wxMaxima
GroupCell.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) 2008-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4 // (C) 2012 Doug Ilijev <doug.ilijev@gmail.com>
5 // (C) 2014-2015 Gunter Königsmann <wxMaxima@physikbuch.de>
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 
30 #ifndef GROUPCELL_H
31 #define GROUPCELL_H
32 
33 #include "Cell.h"
34 #include "EditorCell.h"
35 
37 // This enum's elements must be synchronized with (WXMFormat.h) WXMHeaderId.
38 enum GroupType : int8_t
39 {
40  GC_TYPE_INVALID = -1,
41  GC_TYPE_CODE = 0,
42  GC_TYPE_TITLE,
43  GC_TYPE_SECTION,
44  GC_TYPE_SUBSECTION,
45  GC_TYPE_SUBSUBSECTION,
46  GC_TYPE_HEADING5,
47  GC_TYPE_HEADING6,
48  GC_TYPE_TEXT,
49  GC_TYPE_IMAGE,
50  GC_TYPE_PAGEBREAK
51 };
52 
68 class GroupCell final : public Cell
69 {
70 public:
71  GroupCell(Configuration **config, GroupType groupType, const wxString &initString = {});
72  GroupCell(GroupCell const &cell);
73  GroupCell(GroupCell *group, const GroupCell &cell);
74  std::unique_ptr<Cell> Copy() const;
75  std::unique_ptr<Cell> Copy(GroupCell *group) const override;
76  const CellTypeInfo &GetInfo() override;
77  std::unique_ptr<GroupCell> CopyList() const;
78  ~GroupCell();
79 
80  GroupCell *first() const { return dynamic_cast<GroupCell*>(Cell::first()); }
81  GroupCell *last() const { return dynamic_cast<GroupCell*>(Cell::last()); }
82 
83  const wxString &GetAnswer(int answer) const;
84  const wxString &GetAnswer(const wxString &question) const;
86  bool ContainsSavedAnswers() { return !m_knownAnswers.empty(); }
88  bool AutoAnswer() const { return m_autoAnswer; }
89  void SetAutoAnswer(bool autoAnswer);
90  void MarkNeedsRecalculate(){m_cellsAppended = true;}
92  void SetAnswer(const wxString &question, const wxString &answer);
93 
94  int GetInnerCellCount() const override { return (m_groupType == GC_TYPE_PAGEBREAK) ? 0 : 2; }
95  // cppcheck-suppress objectIndex
96  Cell *GetInnerCell(int index) const override { return (&m_inputLabel)[index].get(); }
97 
104 
110  void CellUnderPointer(GroupCell *cell);
111 
116  const wxString &GetToolTip(wxPoint point) const override;
117 
118  // general methods
119  GroupType GetGroupType() const { return m_groupType; }
120 
121  void SetGroupType(GroupType type);
122 
123  // selection methods
124  Range GetInnerCellsInRect(const wxRect &rect) const override;
125 
126  Range GetCellsInOutput() const;
127 
128  Range GetCellsInOutputRect(const wxRect &rect, wxPoint one, wxPoint two) const;
129 
130  // methods for manipulating GroupCell
131  // cppcheck-suppress functionConst
132  bool SetEditableContent(const wxString &text);
133 
134  void AppendOutput(std::unique_ptr<Cell> &&cell);
135 
142  void RemoveOutput();
143 
144  AFontSize EditorFontSize() const;
145 
148 
158  wxString ToTeX(wxString imgDir, wxString filename, int *imgCounter) const;
159 
160  wxString ToRTF() const override;
161 
162  wxString ToTeXCodeCell(wxString imgDir, wxString filename, int *imgCounter) const;
163 
164  static wxString ToTeXImage(Cell *tmp, wxString imgDir, wxString filename, int *imgCounter);
165 
166  wxString ToTeX() const override;
167 
168  wxString ToXML() const override;
169 
170  void Hide(bool hide) override;
171 
172  void SwitchHide();
173 
174  wxRect HideRect();
175 
176  // raw manipulation of GC (should be protected)
177  void SetInput(std::unique_ptr<Cell> &&input);
178 
179  void SetOutput(std::unique_ptr<Cell> &&output);
180 
181  void AppendInput(std::unique_ptr<Cell> &&cell);
182 
184  GroupCell *GetPrevious() const { return dynamic_cast<GroupCell *>(Cell::GetPrevious()); }
186  GroupCell *GetNext() const { return dynamic_cast<GroupCell *>(Cell::GetNext()); }
187 
188  static wxString TexEscapeOutputCell(wxString Input);
189 
190  Cell *GetPrompt() const { return m_inputLabel.get(); }
191 
192  EditorCell *GetEditable() const
193  { return m_inputLabel ? dynamic_cast<EditorCell *>(m_inputLabel->GetNext()) : nullptr; }
194 
199  Cell *GetLabel() const { return m_output.get(); }
200 
205  Cell *GetOutput() const
206  { return m_output ? m_output->GetNext() : nullptr; }
207 
209  wxRect GetOutputRect() const { return m_outputRect; }
210 
217  void Recalculate(AFontSize WXUNUSED(fontsize)) override {Recalculate();}
218  void Recalculate();
219  wxPoint CalculateInputPosition();
220 
222  void RecalculateInput();
223  wxRect GetRect(bool all = false) const override;
229  void RecalculateOutput();
230 
235  bool BreakUpCells(Cell *cell);
236 
238  bool UnBreakUpCells(Cell *cell);
239 
241  void BreakLines();
242 
248  void ResetInputLabel();
249 
251  void ResetInputLabelList();
253 
255  bool IsFoldable() const;
256 
258  GroupCell *GetHiddenTree() const { return m_hiddenTree.get(); }
259 
266  bool HideTree(std::unique_ptr<GroupCell> &&tree);
267 
269  std::unique_ptr<GroupCell> UnhideTree();
270 
277  bool RevealHidden();
278 
280  void SetHiddenTreeParent(GroupCell *parent);
281 
286  GroupCell *Fold(); // returns pointer to this or NULL if not successful
291  GroupCell *Unfold();
292 
297  GroupCell *FoldAll();
298 
303  GroupCell *UnfoldAll();
304 
310  bool IsLesserGCType(GroupType comparedTo) const;
311 
313  bool IsMainInput(Cell *active) const;
314 
315  bool IsHeading() const;
317  bool SectioningCanMoveIn() const {return IsHeading() && (GetGroupType() != GC_TYPE_HEADING6);};
319  bool SectioningCanMoveOut() const {return IsHeading() && (GetGroupType() != GC_TYPE_TITLE);}
322 
324  void Number(int &section, int &subsection, int &subsubsection, int &heading5, int &heading6, int &image) const;
325 
337  void Draw(wxPoint point) override;
338 
339  bool AddEnding() override;
340 
342  void DrawBracket();
343 
345  bool Empty() const;
346 
348  bool Contains(GroupCell *cell) const;
349 
351  wxString ToString() const override;
352 
354  void InEvaluationQueue(bool inQueue) { m_inEvaluationQueue = inQueue; }
355 
357  void LastInEvaluationQueue(bool last) { m_lastInEvaluationQueue = last; }
358 
360  void OnSize();
361 
363  void InputHeightChanged();
364 
365  WX_DECLARE_STRING_HASH_MAP(wxString, StringHash);
367  StringHash m_knownAnswers;
368 
369 #if wxUSE_ACCESSIBILITY
370  wxAccStatus GetDescription(int childId, wxString *description) const override;
371  wxAccStatus GetLocation (wxRect &rect, int elementId) override;
372 #endif
373 
375  void UpdateYPosition();
376 
377  void UpdateOutputPositions();
378 
379  void UpdateYPositionList();
380 
381  bool GetSuppressTooltipMarker() const { return m_suppressTooltipMarker; }
382  void SetSuppressTooltipMarker(bool suppress) { m_suppressTooltipMarker = suppress; }
383 
384 protected:
385  bool NeedsRecalculation(AFontSize fontSize) const override;
386  int GetInputIndent();
387  int GetLineIndent(Cell *cell);
388  void UpdateCellsInGroup();
389 
390 //** 16-byte objects (16 bytes)
391 //**
392  wxRect m_outputRect{-1, -1, 0, 0};
393 
394 //** 8/4 byte objects (40 bytes)
395 //**
396  CellPointers *const m_cellPointers = GetCellPointers();
397 
398  std::unique_ptr<GroupCell> m_hiddenTree;
400 
401  // The pointers below point to inner cells and must be kept contiguous.
402  // ** All pointers must be the same: either Cell * or std::unique_ptr<Cell>.
403  // ** NO OTHER TYPES are allowed.
405  std::unique_ptr<Cell> m_inputLabel;
407  std::unique_ptr<Cell> m_output;
408  // The pointers above point to inner cells and must be kept contiguous.
409 
410 //** 4-byte objects (16 bytes)
411 //**
412  int m_labelWidth_cached = 0;
413  int m_inputWidth, m_inputHeight;
414 private:
416  int m_clientWidth_old = -1;
417 
418 protected:
419 //** 2-byte objects (6 bytes)
420 //**
422  int16_t m_cellsInGroup = 1;
423  mutable int16_t m_numberedAnswersCount = 0;
424 
425  AFontSize m_mathFontSize;
426 
427 //** 1-byte objects (1 byte)
428 //**
431 
432 //** Bitfield objects (1 bytes)
433 //**
434  void InitBitFields()
435  { // Keep the initialization order below same as the order
436  // of bit fields in this class!
437  m_autoAnswer = false;
438  m_inEvaluationQueue = false;
439  m_lastInEvaluationQueue = false;
440  m_updateConfusableCharWarnings = true;
441  m_suppressTooltipMarker = false;
442  m_cellsAppended = false;
443  }
444 
446  bool m_autoAnswer : 1 /* InitBitFields */;
447  bool m_inEvaluationQueue : 1 /* InitBitFields */;
448  bool m_lastInEvaluationQueue : 1 /* InitBitFields */;
449  bool m_updateConfusableCharWarnings : 1 /* InitBitFields */;
451  bool m_suppressTooltipMarker : 1 /* InitBitFields */;
452  bool m_cellsAppended : 1; /* InitBitFields */
453 
454  static wxString m_lookalikeChars;
455 };
456 
457 #endif /* GROUPCELL_H */
GroupCell::m_suppressTooltipMarker
bool m_suppressTooltipMarker
Suppress the yellow ToolTip marker?
Definition: GroupCell.h:451
GroupCell::IsLesserGCType
bool IsLesserGCType(GroupType comparedTo) const
Definition: GroupCell.cpp:1929
GroupCell::GetInfo
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
GroupCell::m_inputLabel
std::unique_ptr< Cell > m_inputLabel
The input label of this cell. Is followed by the input of the cell.
Definition: GroupCell.h:405
Cell.h
GroupCell::GetInnerCellsInRect
Range GetInnerCellsInRect(const wxRect &rect) const override
Select the cells inside this cell described by the rectangle rect.
Definition: GroupCell.cpp:1488
GroupCell::CellUnderPointer
void CellUnderPointer(GroupCell *cell)
Definition: GroupCell.cpp:876
GroupCell::Recalculate
void Recalculate(AFontSize WXUNUSED(fontsize)) override
Definition: GroupCell.h:217
GroupCell::ResetInputLabelList
void ResetInputLabelList()
Call ResetInputLabel() on all cells in the list of cells this GroupCell starts with.
Definition: GroupCell.cpp:243
GroupCell::GetOutputRect
wxRect GetOutputRect() const
Determine which rectangle is occupied by this GroupCell.
Definition: GroupCell.h:209
GroupCell::ToRTF
wxString ToRTF() const override
Definition: GroupCell.cpp:1097
GroupCell::ContainsSavedAnswers
bool ContainsSavedAnswers()
Does this GroupCell know the answer to any of maxima's questions?
Definition: GroupCell.h:86
GroupCell::RemoveOutput
void RemoveOutput()
Definition: GroupCell.cpp:357
GroupCell::NeedsRecalculation
bool NeedsRecalculation(AFontSize fontSize) const override
True, if something that affects the cell size has changed.
Definition: GroupCell.cpp:665
GroupCell::InputHeightChanged
void InputHeightChanged()
Reset the data when the input size changes.
Definition: GroupCell.cpp:512
GroupCell::IsFoldable
bool IsFoldable() const
folding and unfolding
Definition: GroupCell.cpp:254
GroupCell::UpdateYPosition
void UpdateYPosition()
Recalculate the cell's y position using the position and height of the last one.
Definition: GroupCell.cpp:678
GroupCell::AutoAnswer
bool AutoAnswer() const
Does this GroupCell save the answer to a question?
Definition: GroupCell.h:88
GroupCell::SectioningUnitGetEndOf
GroupCell * SectioningUnitGetEndOf() const
Get the end of this section/subsection/...
GroupCell::GetLabel
Cell * GetLabel() const
Definition: GroupCell.h:199
GroupCell::UnhideTree
std::unique_ptr< GroupCell > UnhideTree()
Unfold the current cell.
Definition: GroupCell.cpp:1814
GroupCell::Contains
bool Contains(GroupCell *cell) const
Does this tree contain the cell "cell"?
Definition: GroupCell.cpp:2058
GroupCell::UpdateConfusableCharWarnings
void UpdateConfusableCharWarnings()
GroupCells warn if they contain both greek and latin lookalike chars.
Definition: GroupCell.cpp:413
GroupCell::Unfold
GroupCell * Unfold()
Definition: GroupCell.cpp:1884
GroupCell::ToXML
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: GroupCell.cpp:1352
GroupCell::ToString
wxString ToString() const override
A textual representation of this cell.
Definition: GroupCell.cpp:1059
GroupCell::m_hiddenTree
std::unique_ptr< GroupCell > m_hiddenTree
here hidden (folded) tree of GCs is stored
Definition: GroupCell.h:398
GroupCell::SetHiddenTreeParent
void SetHiddenTreeParent(GroupCell *parent)
Set the parent cell of hidden cells.
Definition: GroupCell.cpp:1841
GroupCell::ResetInputLabel
void ResetInputLabel()
Definition: GroupCell.cpp:234
GroupCell::m_groupType
GroupType m_groupType
Which type this cell is of?
Definition: GroupCell.h:430
GroupCell::RecalculateInput
void RecalculateInput()
Recalculate the height of the input part of the cell.
Definition: GroupCell.cpp:551
GroupType
GroupType
All types a GroupCell can be of.
Definition: GroupCell.h:38
GroupCell::RevealHidden
bool RevealHidden()
Definition: GroupCell.cpp:1827
GroupCell::GetInnerCellCount
int GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: GroupCell.h:94
GroupCell::m_cellsInGroup
int16_t m_cellsInGroup
The number of cells the current group contains (-1, if no GroupCell)
Definition: GroupCell.h:422
GroupCell::RecalculateOutput
void RecalculateOutput()
Definition: GroupCell.cpp:600
GroupCell::m_knownAnswers
StringHash m_knownAnswers
A list of answers provided by the user.
Definition: GroupCell.h:367
Cell
Definition: Cell.h:139
GroupCell::BreakUpCells
bool BreakUpCells(Cell *cell)
Definition: GroupCell.cpp:1675
Cell::first
Cell * first() const
Get the first cell in this list of cells.
Definition: Cell.cpp:1058
EditorCell
Definition: EditorCell.h:57
GroupCell::InEvaluationQueue
void InEvaluationQueue(bool inQueue)
Is this cell part of the evaluation Queue?
Definition: GroupCell.h:354
GroupCell::GetOutput
Cell * GetOutput() const
Definition: GroupCell.h:205
Cell::GetNext
Cell * GetNext() const
Get the next cell in the list.
Definition: Cell.h:624
GroupCell::m_autoAnswer
bool m_autoAnswer
Does this GroupCell automatically fill in the answer to questions?
Definition: GroupCell.h:446
CellPointers
Definition: CellPointers.h:44
GroupCell::GetHiddenTree
GroupCell * GetHiddenTree() const
Get the tree of cells that got hidden by folding this cell.
Definition: GroupCell.h:258
AFontSize
Definition: FontAttribs.h:97
GroupCell::BreakLines
void BreakLines()
Break this cell into lines.
Definition: GroupCell.cpp:1592
GroupCell::OnSize
void OnSize()
Called on MathCtrl resize.
Definition: GroupCell.cpp:533
GroupCell::LastInEvaluationQueue
void LastInEvaluationQueue(bool last)
Is this cell the last cell in the evaluation Queue?
Definition: GroupCell.h:357
GroupCell::HideTree
bool HideTree(std::unique_ptr< GroupCell > &&tree)
Definition: GroupCell.cpp:1796
GroupCell::Empty
bool Empty() const
Is this list of cells empty?
Definition: GroupCell.cpp:224
GroupCell::ToTeX
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: GroupCell.cpp:1092
GroupCell::GetRect
wxRect GetRect(bool all=false) const override
Definition: GroupCell.cpp:849
Configuration
Definition: Configuration.h:83
GroupCell::UnBreakUpCells
bool UnBreakUpCells(Cell *cell)
Undo a BreakUpCells.
Definition: GroupCell.cpp:1724
GroupCell::GetToolTip
const wxString & GetToolTip(wxPoint point) const override
Definition: GroupCell.cpp:1548
Cell::last
Cell * last() const
Get the last cell in this list of cells.
Definition: Cell.cpp:1068
GroupCell::m_output
std::unique_ptr< Cell > m_output
The maxima output this cell contains.
Definition: GroupCell.h:407
GroupCell::GetPrevious
GroupCell * GetPrevious() const
Get the previous GroupCell in the list.
Definition: GroupCell.h:184
GroupCell::GetLastWorkingGroup
GroupCell * GetLastWorkingGroup() const
Definition: GroupCell.cpp:299
GroupCell::m_hiddenTreeParent
GroupCell * m_hiddenTreeParent
store linkage to the parent of the fold
Definition: GroupCell.h:399
GroupCell::SetAnswer
void SetAnswer(const wxString &question, const wxString &answer)
Add a new answer to the cell.
Definition: GroupCell.cpp:293
GroupCell::GetNext
GroupCell * GetNext() const
Get the next GroupCell in the list.
Definition: GroupCell.h:186
GroupCell::Number
void Number(int &section, int &subsection, int &subsubsection, int &heading5, int &heading6, int &image) const
Return this cell's section- or image number.
Definition: GroupCell.cpp:1977
GroupCell::AddEnding
bool AddEnding() override
Definition: GroupCell.cpp:844
EditorCell.h
GroupCell
Definition: GroupCell.h:68
GroupCell::SectioningCanMoveOut
bool SectioningCanMoveOut() const
Can this chapter/section/... converted to a 'larger' cell, e.g. subsection->section,...
Definition: GroupCell.h:319
GroupCell::Fold
GroupCell * Fold()
Definition: GroupCell.cpp:1847
GroupCell::UnfoldAll
GroupCell * UnfoldAll()
Definition: GroupCell.cpp:1913
CellTypeInfo
A class that carries information about the type of a cell.
Definition: Cell.h:90
GroupCell::GetInnerCell
Cell * GetInnerCell(int index) const override
Definition: GroupCell.h:96
GroupCell::SectioningCanMoveIn
bool SectioningCanMoveIn() const
Can this chapter/section/... converted to a 'smaller' cell, e.g. section->subsection,...
Definition: GroupCell.h:317
GroupCell::DrawBracket
void DrawBracket()
Draw the bracket of this cell.
Definition: GroupCell.cpp:881
GroupCell::FoldAll
GroupCell * FoldAll()
Definition: GroupCell.cpp:1895