wxMaxima
FracCell.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4 // (C) 2014-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // SPDX-License-Identifier: GPL-2.0+
22 
29 #ifndef FRACCELL_H
30 #define FRACCELL_H
31 
32 #include "Cell.h"
33 #include "TextCell.h"
34 #include "ParenCell.h"
35 
36 /* This class represents fractions.
37 
38  Fractions can be drawn in 2 ways:
39  - As a 2D fraction (\f$ \frac{a}{b} \f$) if the fraction is narrow enough to fit
40  on the screen, or
41  - as a linear division (\f$ a/b \f$) if it doesn't.
42  */
43 class FracCell final : public Cell
44 {
45 public:
46  FracCell(GroupCell *group, Configuration **config,
47  std::unique_ptr<Cell> &&num, std::unique_ptr<Cell> &&denom);
48  FracCell(GroupCell *group, const FracCell &cell);
49  std::unique_ptr<Cell> Copy(GroupCell *group) const override;
50  const CellTypeInfo &GetInfo() override;
51 
52  int GetInnerCellCount() const override { return 3; }
53  // cppcheck-suppress objectIndex
54  Cell *GetInnerCell(int index) const override { return (&m_displayedNum)[index]; }
55 
57  enum FracType : int8_t
58  {
59  FC_NORMAL,
60  FC_CHOOSE,
61  FC_DIFF
62  };
63 
64  void Recalculate(AFontSize fontsize) override;
65 
66  void Draw(wxPoint point) override;
67 
68  void SetFracStyle(FracType style) { m_fracStyle = style; }
69 
71  bool IsOperator() const override { return true; }
72 
73  wxString ToMathML() const override;
74  wxString ToMatlab() const override;
75  wxString ToOMML() const override;
76  wxString ToString() const override;
77  wxString ToTeX() const override;
78  wxString ToXML() const override;
79 
81  void SetExponentFlag() override;
82 
83  bool BreakUp() override;
84 
85  void SetupBreakUps();
86 
87  void SetNextToDraw(Cell *next) override;
88 
89 private:
92  void MakeDivideCell();
93 
95  Cell *Num() const { return m_numParenthesis->GetInner(); }
97  Cell *Denom() const { return m_denomParenthesis->GetInner(); }
98 
100  std::unique_ptr<ParenCell> const m_numParenthesis;
102  std::unique_ptr<ParenCell> const m_denomParenthesis;
104  std::unique_ptr<TextCell> m_divideOwner;
105 
106  // The pointers below point to inner cells and must be kept contiguous.
107  // ** This is the draw list order. All pointers must be the same:
108  // ** either Cell * or std::unique_ptr<Cell>. NO OTHER TYPES are allowed.
110  Cell* m_displayedNum = {};
112  Cell* m_divide = {};
114  Cell* m_displayedDenom = {};
115  // The pointers above point to inner cells and must be kept contiguous.
116 
118  int m_protrusion = 0;
125  int m_horizontalGapLeft = 0;
132  int m_horizontalGapRight = 0;
133 
135  FracType m_fracStyle = FC_NORMAL;
136 
137 //** Bitfield objects (1 bytes)
138 //**
139  void InitBitFields()
140  { // Keep the initialization order below same as the order
141  // of bit fields in this class!
142  m_inExponent = false;
143  }
145  bool m_inExponent : 1 /* InitBitFields */;
146 };
147 
148 #endif // FRACCELL_H
FracCell::GetInnerCell
Cell * GetInnerCell(int index) const override
Definition: FracCell.h:54
FracCell::BreakUp
bool BreakUp() override
Definition: FracCell.cpp:330
Cell.h
FracCell::ToMathML
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: FracCell.cpp:273
FracCell::ToTeX
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: FracCell.cpp:254
FracCell::ToXML
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: FracCell.cpp:288
FracCell
Definition: FracCell.h:43
FracCell::ToOMML
wxString ToOMML() const override
Definition: FracCell.cpp:281
FracCell::GetInnerCellCount
int GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: FracCell.h:52
FracCell::GetInfo
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
FracCell::FracType
FracType
All types of fractions we support.
Definition: FracCell.h:57
Cell
Definition: Cell.h:139
ParenCell.h
FracCell::SetNextToDraw
void SetNextToDraw(Cell *next) override
Definition: FracCell.cpp:352
AFontSize
Definition: FontAttribs.h:97
FracCell::Copy
std::unique_ptr< Cell > Copy(GroupCell *group) const override
FracCell::ToMatlab
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: FracCell.cpp:213
FracCell::SetExponentFlag
void SetExponentFlag() override
Fractions in exponents are shown in their linear form.
Definition: FracCell.cpp:303
Configuration
Definition: Configuration.h:83
GroupCell
Definition: GroupCell.h:68
CellTypeInfo
A class that carries information about the type of a cell.
Definition: Cell.h:90
FracCell::ToString
wxString ToString() const override
Returns the cell's representation as a string.
Definition: FracCell.cpp:170
FracCell::IsOperator
bool IsOperator() const override
Answers the question if this is an operator by returning "true".
Definition: FracCell.h:71
FracCell::Recalculate
void Recalculate(AFontSize fontsize) override
Definition: FracCell.cpp:66