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*/
44class FracCell final : public Cell
45{
46public:
47 FracCell(GroupCell *group, Configuration *config,
48 std::unique_ptr<Cell> &&num, std::unique_ptr<Cell> &&denom);
49 FracCell(GroupCell *group, const FracCell &cell);
50 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
51 const CellTypeInfo &GetInfo() override;
52
53 size_t GetInnerCellCount() const override { return 3; }
54 Cell *GetInnerCell(size_t index) const override {
55 switch (index) {
56 case 0:
57 return m_displayedNum;
58 case 1:
59 return m_divide;
60 case 2:
61 return m_displayedDenom;
62 default:
63 return nullptr;
64 }
65 }
66
68 enum FracType : int8_t
69 {
70 FC_NORMAL,
71 FC_CHOOSE,
72 FC_DIFF
73 };
74
75 void Recalculate(const AFontSize fontsize) const override;
76
77 void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override;
78
79 void SetFracStyle(FracType style);
80
82 bool IsOperator() const override { return true; }
83
84 wxString ToMathML() const override;
85 wxString ToMatlab() const override;
86 wxString ToOMML() const override;
87 wxString ToString() const override;
88 wxString ToTeX() const override;
89 wxString ToXML() const override;
90
92 void SetIsExponent() override;
93
94 bool BreakUp() const override;
95
96 void SetupBreakUps() const;
97
98 void SetNextToDraw(Cell *next) const override;
99private:
102 void MakeDivideCell();
103
105 Cell *Num() const { return m_numParenthesis->GetInner(); }
107 Cell *Denom() const { return m_denomParenthesis->GetInner(); }
108
110 std::unique_ptr<ParenCell> const m_numParenthesis;
112 std::unique_ptr<ParenCell> const m_denomParenthesis;
114 std::unique_ptr<TextCell> m_divideOwner;
115
116 // The pointers below point to inner cells and must be kept contiguous.
117 // ** This is the draw list order. All pointers must be the same:
118 // ** either Cell * or std::unique_ptr<Cell>. NO OTHER TYPES are allowed.
120 mutable Cell* m_displayedNum = {};
122 Cell* m_divide = {};
124 mutable Cell* m_displayedDenom = {};
125 // The pointers above point to inner cells and must be kept contiguous.
126
128 mutable int m_protrusion = 0;
135 mutable int m_horizontalGapLeft = 0;
142 mutable int m_horizontalGapRight = 0;
143
145 FracType m_fracStyle = FC_NORMAL;
146
147//** Bitfield objects (1 bytes)
148//**
149 void InitBitFields_FracCell()
150 { // Keep the initialization order below same as the order
151 // of bit fields in this class!
152 m_inExponent = false;
153 }
155 bool m_inExponent : 1 /* InitBitFields_FracCell */;
156};
157
158#endif // FRACCELL_H
The definition of the base class of all cells the worksheet consists of.
This file declares the class ParenCell.
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:98
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:142
The configuration storage for the current worksheet.
Definition: Configuration.h:85
Definition: FracCell.h:45
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: FracCell.cpp:254
bool IsOperator() const override
Answers the question if this is an operator by returning "true".
Definition: FracCell.h:82
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: FracCell.cpp:273
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: FracCell.h:54
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: FracCell.cpp:221
void SetIsExponent() override
Fractions in exponents are shown in their linear form.
Definition: FracCell.cpp:292
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:268
FracType
All types of fractions we support.
Definition: FracCell.h:69
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: FracCell.cpp:278
wxString ToString() const override
Returns the cell's representation as a string.
Definition: FracCell.cpp:186
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: FracCell.cpp:88
bool BreakUp() const override
Try to split this command into lines to make it fit on the screen.
Definition: FracCell.cpp:315
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override
Draw this cell.
Definition: FracCell.cpp:139
size_t GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: FracCell.h:53
void SetNextToDraw(Cell *next) const override
Tells this cell which one should be the next cell to be drawn.
Definition: FracCell.cpp:332
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:74