wxMaxima
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 class TextCell : public Cell
37 {
38 public:
39  TextCell(GroupCell *group, Configuration **config, const wxString &text = {}, TextStyle style = TS_FUNCTION);
40  TextCell(GroupCell *group, const TextCell &cell);
41  virtual const CellTypeInfo &GetInfo() override;
42  std::unique_ptr<Cell> Copy(GroupCell *group) const override;
43 
44  AFontSize GetScaledTextSize() const;
45 
46  virtual void SetStyle(TextStyle style) override;
47 
49  void SetValue(const wxString &text) override;
50 
51  virtual void Recalculate(AFontSize fontsize) override;
52 
53  void Draw(wxPoint point) override;
54 
55  void SetFont(AFontSize fontsize);
56 
62 
63  wxString ToMatlab() const override;
64  wxString ToMathML() const override;
65  wxString ToOMML() const override;
66  wxString ToRTF() const override;
67  virtual wxString ToString() const override;
68  wxString ToTeX() const override;
69  wxString ToXML() const override;
70 
71  bool IsOperator() const override;
72 
73  const wxString &GetValue() const override { return m_text; }
74 
75  wxString GetGreekStringTeX() const;
76 
77  wxString GetSymbolTeX() const;
78 
79  wxString GetGreekStringUnicode() const;
80 
81  wxString GetSymbolUnicode(bool keepPercent) const;
82 
83  bool IsShortNum() const override;
84 
85  void SetType(CellType type) override;
86 
87  void SetAltCopyText(const wxString &text) override {m_altCopyText = text;}
88 
89  void SetPromptTooltip(bool use) { m_promptTooltip = use; }
90 
91 protected:
92  mutable wxString m_altCopyText;
94  virtual wxString GetXMLFlags() const;
96  virtual void UpdateDisplayedText();
98  void UpdateToolTip();
99  const wxString &GetAltCopyText() const override { return m_altCopyText; }
100 
101  void FontsChanged() override
102  {
103  ResetSize();
104  ResetData();
105  m_sizeCache.clear();
106  }
107 
108  virtual bool NeedsRecalculation(AFontSize fontSize) const override;
109 
110  enum TextIndex : int8_t
111  {
112  noText,
113  cellText,
114  userLabelText,
115  numberStart,
116  ellipsis,
117  numberEnd
118  };
119 
120  struct SizeEntry {
121  wxSize textSize;
122  AFontSize fontSize;
123  TextIndex index;
124  SizeEntry(wxSize textSize, AFontSize fontSize, TextIndex index) :
125  textSize(textSize), fontSize(fontSize), index(index) {}
126  SizeEntry() = default;
127  };
128 
129  wxSize CalculateTextSize(wxDC *dc, const wxString &text, TextCell::TextIndex const index);
130 
131  static wxRegEx m_unescapeRegEx;
132  static wxRegEx m_roundingErrorRegEx1;
133  static wxRegEx m_roundingErrorRegEx2;
134  static wxRegEx m_roundingErrorRegEx3;
135  static wxRegEx m_roundingErrorRegEx4;
136 
137 //** Large objects (120 bytes)
138 //**
140  wxString m_text;
142  wxString m_displayedText;
143  std::vector<SizeEntry> m_sizeCache;
144 
145 //** Bitfield objects (1 bytes)
146 //**
147  void InitBitFields()
148  { // Keep the initialization order below same as the order
149  // of bit fields in this class!
151  m_promptTooltip = false;
152  m_keepPercent_last = (*m_configuration)->CheckKeepPercent();
153  }
154 
156  bool m_dontEscapeOpeningParenthesis : 1 /* InitBitFields */;
158  bool m_promptTooltip : 1 /* InitBitFields */;
161 
162 };
163 
164 #endif // TEXTCELL_H
Cell.h
TextCell::IsOperator
bool IsOperator() const override
Is this cell an operator?
Definition: TextCell.cpp:455
TextCell::GetXMLFlags
virtual wxString GetXMLFlags() const
Returns the XML flags this cell needs in wxMathML.
Definition: TextCell.cpp:1191
TextCell::GetInfo
virtual const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
TextCell
Definition: TextCell.h:36
TextCell::ToString
virtual wxString ToString() const override
Returns the cell's representation as a string.
Definition: TextCell.cpp:466
TextStyle
TextStyle
Definition: TextStyle.h:307
TextCell::NeedsRecalculation
virtual bool NeedsRecalculation(AFontSize fontSize) const override
True, if something that affects the cell size has changed.
Definition: TextCell.cpp:320
TextCell::Draw
void Draw(wxPoint point) override
Definition: TextCell.cpp:414
Cell::ResetData
void ResetData()
Mark all cached size information as "to be calculated".
Definition: Cell.cpp:1010
TextCell::m_displayedText
wxString m_displayedText
The text we display: We might want to convert some characters or do similar things.
Definition: TextCell.h:142
TextCell::m_text
wxString m_text
The text we keep inside this cell.
Definition: TextCell.h:140
TextCell::ToXML
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: TextCell.cpp:1218
TextCell::ToRTF
wxString ToRTF() const override
Definition: TextCell.cpp:1171
TextCell::SetValue
void SetValue(const wxString &text) override
Set the text contained in this cell.
Definition: TextCell.cpp:306
TextCell::ToMathML
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: TextCell.cpp:1020
TextCell::FontsChanged
void FontsChanged() override
To be called if the font has changed.
Definition: TextCell.h:101
TextCell::UpdateToolTip
void UpdateToolTip()
Update the tooltip for this cell.
Definition: TextCell.cpp:115
TextCell::m_keepPercent_last
bool m_keepPercent_last
The last known value of CheckKeepPercent.
Definition: TextCell.h:160
Cell
Definition: Cell.h:139
TextCell::DontEscapeOpeningParenthesis
void DontEscapeOpeningParenthesis()
Definition: TextCell.h:61
TextCell::ToTeX
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: TextCell.cpp:599
TextCell::ToOMML
wxString ToOMML() const override
Definition: TextCell.cpp:1097
TextCell::SizeEntry
Definition: TextCell.h:120
TextCell::GetAltCopyText
const wxString & GetAltCopyText() const override
Get the text set using SetAltCopyText - may be empty.
Definition: TextCell.h:99
AFontSize
Definition: FontAttribs.h:97
CellType
CellType
Definition: Cell.h:63
TextCell::m_promptTooltip
bool m_promptTooltip
Default to a special tooltip for prompts?
Definition: TextCell.h:158
TextCell::Copy
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Configuration
Definition: Configuration.h:83
TextCell::UpdateDisplayedText
virtual void UpdateDisplayedText()
The text we actually display depends on many factors, unfortunately.
Definition: TextCell.cpp:337
Cell::ResetSize
void ResetSize()
Mark the cached height and width information as "to be calculated".
Definition: Cell.cpp:1034
GroupCell
Definition: GroupCell.h:68
TextCell::m_dontEscapeOpeningParenthesis
bool m_dontEscapeOpeningParenthesis
Is an ending "(" of a function name the opening parenthesis of the function?
Definition: TextCell.h:156
CellTypeInfo
A class that carries information about the type of a cell.
Definition: Cell.h:90
TextCell::ToMatlab
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: TextCell.cpp:531
TextCell::Recalculate
virtual void Recalculate(AFontSize fontsize) override
Definition: TextCell.cpp:382
TextCell::SetType
void SetType(CellType type) override
Sets the text style according to the type.
Definition: TextCell.cpp:105
TextCell::SetStyle
virtual void SetStyle(TextStyle style) override
Sets the TextStyle of this cell.
Definition: TextCell.cpp:91
TextCell::SetAltCopyText
void SetAltCopyText(const wxString &text) override
Definition: TextCell.h:87