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#include "UrlDetection.h"
30#include <vector>
31
37// 304 bytes <- 744 bytes
38// cppcheck-suppress ctuOneDefinitionRuleViolation
39class TextCell : public Cell
40{
41public:
42 TextCell(GroupCell *group, Configuration *config, const wxString &text = {}, TextStyle style = TS_FUNCTION);
43 TextCell(GroupCell *group, const TextCell &cell);
44 virtual ~TextCell(){}
45 virtual const CellTypeInfo &GetInfo() override;
46 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
47
48 AFontSize GetScaledTextSize() const;
49
50 void SetStyle(TextStyle style) override;
51
53 void SetValue(const wxString &text) override;
54
55 virtual void Recalculate(const AFontSize fontsize) const override;
56
58 void SetCurrentPoint(wxPoint point) const override;
59 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
60 const wxFont &GetFont(AFontSize fontsize) const {
61 return m_configuration->GetStyle(GetTextStyle())->GetFont(fontsize);
62 }
63 //cppcheck-suppress functionConst
64 void SetFont(wxDC *dc, AFontSize fontsize) const;
65
66 wxCoord GetWidthAtLineBreak() const override;
67
73
74 wxString ToMatlab() const override;
75 wxString ToMathML() const override;
76 wxString ToOMML() const override;
77 wxString ToRTF() const override;
78 virtual wxString ToString() const override;
79 virtual const wxString GetDisplayedString() const override {return m_displayedText;}
80 wxString ToTeX() const override;
81 wxString ToXML() const override;
82
83 bool IsOperator() const override;
84
85 const wxString &GetValue() const override { return m_text; }
86
87 wxString GetGreekStringTeX() const;
88
89 wxString GetSymbolTeX() const;
90
91 wxString GetGreekStringUnicode() const;
92
93 wxString GetSymbolUnicode(bool keepPercent) const;
94
95 bool IsShortNum() const override;
96
97 void SetType(CellType type) override;
98
99 void SetAltCopyText(const wxString &text) override {m_altCopyText = text;}
100
101 void SetPromptTooltip(bool use) { m_promptTooltip = use; }
102
110 wxString GetLinkAt(wxPoint point) override;
111
112protected:
113 mutable wxString m_altCopyText;
115 wxString GetXMLFlags() const override;
117 virtual void UpdateDisplayedText() const;
124 std::vector<wxm::UrlSpan> LinkSpans() const;
125
131 void UpdateDigitGroupGaps() const;
133 wxCoord DigitGroupGapWidth() const;
142 wxCoord DrawGroupedDigits(wxDC *dc, const wxString &text, wxCoord x,
143 wxCoord y, bool draw) const;
150 mutable std::vector<size_t> m_digitGroupGaps;
158 template <typename RunFunc> void WalkTextRuns(wxDC *dc, wxCoord x, RunFunc &&func) const;
160 void UpdateToolTip();
161 const wxString &GetAltCopyText() const override { return m_altCopyText; }
162
163 void FontsChanged() const override
164 {
165 m_sizeCache.clear();
166 }
167
168 enum TextIndex : int8_t
169 {
170 noText,
171 cellText,
172 userLabelText,
173 numberStart,
174 ellipsis,
175 numberEnd
176 };
177
178 struct SizeEntry {
179 wxSize textSize;
180 AFontSize fontSize;
181 TextIndex index = cellText;
182 SizeEntry(wxSize textSize, AFontSize fontSize, TextIndex index) :
183 textSize(textSize), fontSize(fontSize), index(index) {}
184 SizeEntry() = default;
185 };
186
187 wxSize CalculateTextSize(wxDC *dc, const wxString &text, TextCell::TextIndex const index) const;
188
189 static wxRegEx m_unescapeRegEx;
190 static wxRegEx m_roundingErrorRegEx1;
191 static wxRegEx m_roundingErrorRegEx2;
192 static wxRegEx m_roundingErrorRegEx3;
193 static wxRegEx m_roundingErrorRegEx4;
194
195//** Large objects (120 bytes)
196//**
198 wxString m_text;
200 mutable wxString m_displayedText;
201 mutable std::vector<SizeEntry> m_sizeCache;
203 mutable wxCoord m_widthAtLineBreak = 0;
204
205//** Bitfield objects (1 bytes)
206//**
210 bool m_promptTooltip : 1 = false;
212 mutable bool m_hasLinks : 1 = false;
213};
214
215#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:230
int group
Neighbouring sections of the same group aren't separated.
Definition: ToolBarSections.cpp:45
Finds the web links in a piece of plain text (GH #2396).
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
Configuration * m_configuration
A pointer to the configuration responsible for this worksheet.
Definition: Cell.h:1199
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:526
const TextStyle & GetTextStyle() const
Get the text style.
Definition: Cell.h:692
The configuration storage for the current worksheet.
Definition: Configuration.h:101
const Style * GetStyle(TextStyle textStyle) const
Get the text Style for a given text style identifier.
Definition: Configuration.h:1270
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
const wxFont & GetFont(AFontSize fontSize) const
Returns the font associated with this style, but with the size fontSize.
Definition: TextStyle.cpp:348
A Text cell.
Definition: TextCell.h:40
wxCoord DigitGroupGapWidth() const
The width of one digit-group gap at this cell's font size.
Definition: TextCell.cpp:568
void SetCurrentPoint(wxPoint point) const override
Pass 2: Arrangement.
Definition: TextCell.cpp:133
void SetStyle(TextStyle style) override
Sets the TextStyle of this cell.
Definition: TextCell.cpp:137
std::vector< wxm::UrlSpan > LinkSpans() const
The links in m_displayedText.
Definition: TextCell.cpp:430
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: TextCell.cpp:752
wxString m_text
The text we keep inside this cell.
Definition: TextCell.h:198
bool m_dontEscapeOpeningParenthesis
Is an ending "(" of a function name the opening parenthesis of the function?
Definition: TextCell.h:208
void UpdateToolTip()
Update the tooltip for this cell.
Definition: TextCell.cpp:154
wxString GetLinkAt(wxPoint point) override
The link drawn at point, if any (GH #2396).
Definition: TextCell.cpp:457
bool IsOperator() const override
Is this cell an operator?
Definition: TextCell.cpp:616
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: TextCell.cpp:1185
const wxString & GetAltCopyText() const override
Get the text set using SetAltCopyText - may be empty.
Definition: TextCell.h:161
virtual void UpdateDisplayedText() const
The text we actually display depends on many factors, unfortunately.
Definition: TextCell.cpp:385
const wxString & GetValue() const override
Gets the text this text cell contains.
Definition: TextCell.h:85
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:685
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:517
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: TextCell.cpp:1279
wxString m_displayedText
The text we display: We might want to convert some characters or do similar things.
Definition: TextCell.h:200
bool IsShortNum() const override
True if this cell represents a short number.
Definition: TextCell.cpp:1455
void DontEscapeOpeningParenthesis()
Calling this function signals that the "(" this cell ends in isn't part of the function name.
Definition: TextCell.h:72
wxCoord GetWidthAtLineBreak() const override
The width this cell would have if it were at a line break.
Definition: TextCell.cpp:598
wxCoord DrawGroupedDigits(wxDC *dc, const wxString &text, wxCoord x, wxCoord y, bool draw) const
Draws text, the first text.Length() characters of m_displayedText, with the digit-group gaps that fal...
Definition: TextCell.cpp:574
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: TextCell.cpp:1408
virtual void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: TextCell.cpp:478
wxString GetXMLFlags() const override
Returns the XML flags this cell needs in wxMathML.
Definition: TextCell.cpp:1387
bool m_promptTooltip
Default to a special tooltip for prompts?
Definition: TextCell.h:210
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void UpdateDigitGroupGaps() const
Recomputes m_digitGroupGaps for m_displayedText (GH #192).
Definition: TextCell.cpp:558
std::vector< size_t > m_digitGroupGaps
Where in m_displayedText Draw() leaves a gap between two digit groups.
Definition: TextCell.h:150
wxCoord m_widthAtLineBreak
The width this cell has if it is at a line break, see GetWidthAtLineBreak()
Definition: TextCell.h:203
void FontsChanged() const override
To be called if the font has changed.
Definition: TextCell.h:163
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: TextCell.cpp:1356
void WalkTextRuns(wxDC *dc, wxCoord x, RunFunc &&func) const
Walks m_displayedText as Draw() paints it: plain runs and links.
Definition: TextCell.cpp:439
virtual wxString ToString() const override
Returns the cell's representation as a string.
Definition: TextCell.cpp:626
void SetValue(const wxString &text) override
Set the text contained in this cell.
Definition: TextCell.cpp:364
void SetAltCopyText(const wxString &text) override
What should end up if placing this cell on the clipboard?
Definition: TextCell.h:99
bool m_hasLinks
Does m_displayedText contain a link? Keeps Draw() a single DrawText() if not.
Definition: TextCell.h:212
void func()
function in group 1
Definition: group.cpp:13
Definition: TextCell.h:178