wxMaxima
Loading...
Searching...
No Matches
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 <memory>
33#include "Cell.h"
34#include "TextCell.h"
35#include "ParenCell.h"
36
37/* This class represents fractions.
38
39 Fractions can be drawn in 2 ways:
40 - As a 2D fraction (\f$ \frac{a}{b} \f$) if the fraction is narrow enough to fit
41 on the screen, or
42 - as a linear division (\f$ a/b \f$) if it doesn't.
43
44 \image html FracCellGeometry.svg
45 \image html FracCellLinearGeometry.svg
46*/
47class FracCell final : public Cell
48{
49public:
51 std::unique_ptr<Cell> &&num, std::unique_ptr<Cell> &&denom);
52 FracCell(GroupCell *group, const FracCell &cell);
53 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
54 const CellTypeInfo &GetInfo() override;
55
64 size_t GetInnerCellCount() const override { return 3; }
65 Cell *GetInnerCell(size_t index) const override {
66 switch (index) {
67 case 0:
68 return m_displayedNum;
69 case 1:
70 return m_divide;
71 case 2:
72 return m_displayedDenom;
73 default:
74 return nullptr;
75 }
76 }
77
79 enum FracType : int8_t
80 {
81 FC_NORMAL,
82 FC_CHOOSE,
83 FC_DIFF
84 };
85
86 void Recalculate(const AFontSize fontsize) const override;
87
88 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
89
91 void SetCurrentPoint(wxPoint point) const override;
92
93 void SetFracStyle(FracType style);
94
96 bool IsOperator() const override { return true; }
97
98 wxString ToMathML() const override;
99 wxString ToMatlab() const override;
100 wxString ToOMML() const override;
101 wxString ToString() const override;
102 wxString ToTeX() const override;
103 wxString ToXML() const override;
104
106 void SetIsExponent() override;
107
108 bool BreakUp() const override;
109
112 void Unbreak() const override;
113
114 void SetupBreakUps() const;
115
116private:
119 void MakeDivideCell();
120
122 Cell *Num() const { return m_numParenthesis->GetInner(); }
124 Cell *Denom() const { return m_denomParenthesis->GetInner(); }
125
127 std::unique_ptr<ParenCell> const m_numParenthesis;
129 std::unique_ptr<ParenCell> const m_denomParenthesis;
131 std::unique_ptr<TextCell> m_divideOwner;
132
133 // The pointers below point to inner cells and must be kept contiguous.
134 // ** This is the draw list order. All pointers must be the same:
135 // ** either Cell * or std::unique_ptr<Cell>. NO OTHER TYPES are allowed.
137 mutable Cell* m_displayedNum = {};
139 Cell* m_divide = {};
141 mutable Cell* m_displayedDenom = {};
142 // The pointers above point to inner cells and must be kept contiguous.
143
145 mutable int m_protrusion = 0;
152 mutable int m_horizontalGapLeft = 0;
159 mutable int m_horizontalGapRight = 0;
160
162 FracType m_fracStyle = FC_NORMAL;
163
164//** Bitfield objects (1 bytes)
165//**
167 bool m_inExponent : 1 = false;
168};
169
170#endif // FRACCELL_H
The definition of the base class of all cells the worksheet consists of.
This file declares the class ParenCell.
int group
Neighbouring sections of the same group aren't separated.
Definition: ToolBarSections.cpp:45
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:99
A class that carries information about the type of a cell.
Definition: Cell.h:93
The base class all cell types the worksheet can consist of are derived from.
Definition: Cell.h:148
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:526
The configuration storage for the current worksheet.
Definition: Configuration.h:100
Definition: FracCell.h:48
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: FracCell.cpp:291
bool IsOperator() const override
Answers the question if this is an operator by returning "true".
Definition: FracCell.h:96
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: FracCell.cpp:315
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: FracCell.h:65
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: FracCell.cpp:258
void SetIsExponent() override
Fractions in exponents are shown in their linear form.
Definition: FracCell.cpp:332
void Unbreak() const override
Restores the 2D numerator/denominator display that BreakUp() switched to the parenthesized linear for...
Definition: FracCell.cpp:355
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: FracCell.cpp:305
FracType
All types of fractions we support.
Definition: FracCell.h:80
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: FracCell.cpp:320
wxString ToString() const override
Returns the cell's representation as a string.
Definition: FracCell.cpp:223
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: FracCell.cpp:87
bool BreakUp() const override
Try to split this command into lines to make it fit on the screen.
Definition: FracCell.cpp:364
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: FracCell.cpp:195
void SetCurrentPoint(wxPoint point) const override
Pass 2 (Arrange): Positions numerator, denominator, and division sign.
Definition: FracCell.cpp:154
size_t GetInnerCellCount() const override
ORDER MATTERS: also used, via the default GetBrokenCellCount()/ GetBrokenCell(), as this cell's broke...
Definition: FracCell.h:64
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88