wxMaxima
Loading...
Searching...
No Matches
TextCell.h
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-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
5// (C) 2020 Kuba Ober <kuba@bertec.com>
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// SPDX-License-Identifier: GPL-2.0+
23
24#ifndef TEXTCELL_H
25#define TEXTCELL_H
26
27#include <wx/regex.h>
28#include "Cell.h"
29
35// 304 bytes <- 744 bytes
36// cppcheck-suppress ctuOneDefinitionRuleViolation
37class TextCell : public Cell
38{
39public:
40 TextCell(GroupCell *group, Configuration *config, const wxString &text = {}, TextStyle style = TS_FUNCTION);
41 TextCell(GroupCell *group, const TextCell &cell);
42 virtual ~TextCell(){}
43 virtual const CellTypeInfo &GetInfo() override;
44 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
45
46 AFontSize GetScaledTextSize() const;
47
48 void SetStyle(TextStyle style) override;
49
51 void SetValue(const wxString &text) override;
52
53 virtual void Recalculate(const AFontSize fontsize) const override;
54
56 void SetCurrentPoint(wxPoint point) override;
57 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
58 const wxFont &GetFont(AFontSize fontsize) const {
59 return m_configuration->GetStyle(GetTextStyle())->GetFont(fontsize);
60 }
61 //cppcheck-suppress functionConst
62 void SetFont(wxDC *dc, AFontSize fontsize) const;
63
69
70 wxString ToMatlab() const override;
71 wxString ToMathML() const override;
72 wxString ToOMML() const override;
73 wxString ToRTF() const override;
74 virtual wxString ToString() const override;
75 virtual const wxString GetDisplayedString() const override {return m_displayedText;}
76 wxString ToTeX() const override;
77 wxString ToXML() const override;
78
79 bool IsOperator() const override;
80
81 const wxString &GetValue() const override { return m_text; }
82
83 wxString GetGreekStringTeX() const;
84
85 wxString GetSymbolTeX() const;
86
87 wxString GetGreekStringUnicode() const;
88
89 wxString GetSymbolUnicode(bool keepPercent) const;
90
91 bool IsShortNum() const override;
92
93 void SetType(CellType type) override;
94
95 void SetAltCopyText(const wxString &text) override {m_altCopyText = text;}
96
97 void SetPromptTooltip(bool use) { m_promptTooltip = use; }
98
99protected:
100 mutable wxString m_altCopyText;
102 wxString GetXMLFlags() const override;
104 virtual void UpdateDisplayedText() const;
106 void UpdateToolTip();
107 const wxString &GetAltCopyText() const override { return m_altCopyText; }
108
109 void FontsChanged() const override
110 {
111 m_sizeCache.clear();
112 }
113
114 enum TextIndex : int8_t
115 {
116 noText,
117 cellText,
118 userLabelText,
119 numberStart,
120 ellipsis,
121 numberEnd
122 };
123
124 struct SizeEntry {
125 wxSize textSize;
126 AFontSize fontSize;
127 TextIndex index = cellText;
128 SizeEntry(wxSize textSize, AFontSize fontSize, TextIndex index) :
129 textSize(textSize), fontSize(fontSize), index(index) {}
130 SizeEntry() = default;
131 };
132
133 wxSize CalculateTextSize(wxDC *dc, const wxString &text, TextCell::TextIndex const index) const;
134
135 static wxRegEx m_unescapeRegEx;
136 static wxRegEx m_roundingErrorRegEx1;
137 static wxRegEx m_roundingErrorRegEx2;
138 static wxRegEx m_roundingErrorRegEx3;
139 static wxRegEx m_roundingErrorRegEx4;
140
141//** Large objects (120 bytes)
142//**
144 wxString m_text;
146 mutable wxString m_displayedText;
147 mutable std::vector<SizeEntry> m_sizeCache;
148
149//** Bitfield objects (1 bytes)
150//**
151 void InitBitFields_TextCell()
152 { // Keep the initialization order below same as the order
153 // of bit fields in this class!
155 m_promptTooltip = false;
156 }
157
159 bool m_dontEscapeOpeningParenthesis : 1 /* InitBitFields_TextCell */;
161 bool m_promptTooltip : 1 /* InitBitFields_TextCell */;
162};
163
164#endif // TEXTCELL_H
The definition of the base class of all cells the worksheet consists of.
CellType
The supported types of math cells.
Definition: Cell.h:64
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:231
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:97
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
virtual void SetCurrentPoint(wxPoint point)
Pass 2: Arrangement.
Definition: Cell.cpp:466
Configuration * m_configuration
A pointer to the configuration responsible for this worksheet.
Definition: Cell.h:1062
const TextStyle & GetTextStyle() const
Get the text style.
Definition: Cell.h:562
The configuration storage for the current worksheet.
Definition: Configuration.h:86
const Style * GetStyle(TextStyle textStyle) const
Get the text Style for a given text style identifier.
Definition: Configuration.h:884
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87
const wxFont & GetFont(AFontSize fontSize) const
Returns the font associated with this style, but with the size fontSize.
Definition: TextStyle.cpp:355
A Text cell.
Definition: TextCell.h:38
void SetStyle(TextStyle style) override
Sets the TextStyle of this cell.
Definition: TextCell.cpp:137
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: TextCell.cpp:619
wxString m_text
The text we keep inside this cell.
Definition: TextCell.h:144
bool m_dontEscapeOpeningParenthesis
Is an ending "(" of a function name the opening parenthesis of the function?
Definition: TextCell.h:159
void UpdateToolTip()
Update the tooltip for this cell.
Definition: TextCell.cpp:154
bool IsOperator() const override
Is this cell an operator?
Definition: TextCell.cpp:483
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: TextCell.cpp:1026
const wxString & GetAltCopyText() const override
Get the text set using SetAltCopyText - may be empty.
Definition: TextCell.h:107
virtual void UpdateDisplayedText() const
The text we actually display depends on many factors, unfortunately.
Definition: TextCell.cpp:382
const wxString & GetValue() const override
Gets the text this text cell contains.
Definition: TextCell.h:81
void SetType(CellType type) override
Sets the text style according to the type.
Definition: TextCell.cpp:149
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: TextCell.cpp:552
virtual const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: TextCell.cpp:453
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: TextCell.cpp:1110
wxString m_displayedText
The text we display: We might want to convert some characters or do similar things.
Definition: TextCell.h:146
bool IsShortNum() const override
True if this cell represents a short number.
Definition: TextCell.cpp:1264
void DontEscapeOpeningParenthesis()
Calling this function signals that the "(" this cell ends in isn't part of the function name.
Definition: TextCell.h:68
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: TextCell.cpp:1217
void SetCurrentPoint(wxPoint point) override
Pass 2: Arrangement.
Definition: TextCell.cpp:133
virtual void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: TextCell.cpp:424
wxString GetXMLFlags() const override
Returns the XML flags this cell needs in wxMathML.
Definition: TextCell.cpp:1196
bool m_promptTooltip
Default to a special tooltip for prompts?
Definition: TextCell.h:161
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void FontsChanged() const override
To be called if the font has changed.
Definition: TextCell.h:109
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: TextCell.cpp:1178
virtual wxString ToString() const override
Returns the cell's representation as a string.
Definition: TextCell.cpp:493
void SetValue(const wxString &text) override
Set the text contained in this cell.
Definition: TextCell.cpp:361
void SetAltCopyText(const wxString &text) override
What should end up if placing this cell on the clipboard?
Definition: TextCell.h:95
Definition: TextCell.h:124