wxMaxima
Loading...
Searching...
No Matches
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 <utility>
34#include <memory>
35#include "Cell.h"
36#include "EditorCell.h"
37#include <unordered_map>
38
40// This enum's elements must be synchronized with (WXMFormat.h) WXMHeaderId.
41enum GroupType : int8_t
42{
43 GC_TYPE_INVALID = -1,
44 GC_TYPE_CODE = 0,
45 GC_TYPE_TITLE,
46 GC_TYPE_SECTION,
47 GC_TYPE_SUBSECTION,
48 GC_TYPE_SUBSUBSECTION,
49 GC_TYPE_HEADING5,
50 GC_TYPE_HEADING6,
51 GC_TYPE_TEXT,
52 GC_TYPE_IMAGE,
53 GC_TYPE_PAGEBREAK
54};
56std::ostream& operator<<(std::ostream& out, const GroupType grouptype);
57
86class GroupCell : public Cell
87{
88public:
91 GroupCell(Configuration *config, GroupType groupType,
92 const wxString &initString = {});
93 GroupCell(GroupCell const &cell);
94 GroupCell(GroupCell *group, const GroupCell &cell);
95 std::unique_ptr<Cell> Copy() const;
96 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
97 const CellTypeInfo &GetInfo() override;
98 std::unique_ptr<GroupCell> CopyList() const;
99 virtual ~GroupCell();
100
101 int GetMaxDrop() const;
102 int GetCenterList() const;
103
104 // cppcheck-suppress duplInheritedMember
105 GroupCell *first() const { return dynamic_cast<GroupCell*>(Cell::first()); }
106 // cppcheck-suppress duplInheritedMember
107 GroupCell *last() const { return dynamic_cast<GroupCell*>(Cell::last()); }
108
109 const wxString &GetAnswer(size_t answer) const;
110 const wxString &GetAnswer(const wxString &question) const;
112 bool ContainsSavedAnswers() const { return !m_knownAnswers.empty(); }
114 bool AutoAnswer() const { return m_autoAnswer; }
115 void SetAutoAnswer(bool autoAnswer);
116 void MarkNeedsRecalculate(){m_cellsAppended = true;}
118 void SetAnswer(const wxString &question, const wxString &answer);
119
120 size_t GetInnerCellCount() const override { return (m_groupType == GC_TYPE_PAGEBREAK) ? 0 : 2; }
121 Cell *GetInnerCell(size_t index) const override {
122 switch (index) {
123 case 0:
124 return m_inputLabel.get();
125 case 1:
126 return m_output.get();
127 default:
128 return nullptr;
129 }
130 }
131
138
144 void CellUnderPointer(GroupCell *cell);
145
150 const wxString GetToolTip(wxPoint point) const override;
151
152 // general methods
153 GroupType GetGroupType() const { return m_groupType; }
154
155 void SetGroupType(GroupType groupType);
156
157 // selection methods
158 Range GetInnerCellsInRect(const wxRect &rect) const override;
159
160 Range GetCellsInOutput() const;
161
162 Range GetCellsInOutputRect(const wxRect &rect, wxPoint one, wxPoint two) const;
163
164 // methods for manipulating GroupCell
165 // cppcheck-suppress functionConst
166 bool SetEditableContent(const wxString &text);
167
168 void AppendOutput(std::unique_ptr<Cell> &&cell);
169
176 void RemoveOutput();
177
178 AFontSize EditorFontSize() const;
179
182
192 wxString ToTeX(const wxString &imgDir, const wxString &filename, std::size_t *imgCounter) const;
193
194 wxString ToRTF() const override;
195
196 wxString ToTeXCodeCell(const wxString &imgDir, const wxString &filename, std::size_t *imgCounter) const;
197
198 static wxString ToTeXImage(const Cell *tmp, const wxString &imgDir, const wxString &filename, std::size_t *imgCounter);
199
200 wxString ToTeX() const override;
201
202 wxString ToXML() const override;
203
204 void Hide(bool hide) override;
205 virtual bool FirstLineOnlyEditor() const override;
206 void SwitchHide();
207
208 wxRect HideRect() const;
209
210 // raw manipulation of GC (should be protected)
211 void SetInput(std::unique_ptr<Cell> &&input);
212
213 void SetOutput(std::unique_ptr<Cell> &&output);
214
215 void AppendInput(std::unique_ptr<Cell> &&cell);
216
218 // cppcheck-suppress duplInheritedMember
219 GroupCell *GetPrevious() const { return dynamic_cast<GroupCell *>(Cell::GetPrevious()); }
220
222 // cppcheck-suppress duplInheritedMember
223 GroupCell *GetNext() const { return dynamic_cast<GroupCell *>(Cell::GetNext()); }
224
225 static wxString TexEscapeOutputCell(wxString Input);
226
227 Cell *GetPrompt() const { return m_inputLabel.get(); }
228
229 EditorCell *GetEditable() const
230 { return m_inputLabel ? dynamic_cast<EditorCell *>(m_inputLabel->GetNext()) : nullptr; }
231
236 Cell *GetLabel() const { return m_output.get(); }
237
243 { return m_output ? m_output->GetNext() : nullptr; }
244
246 wxRect GetOutputRect() const { return m_outputRect; }
247
254 void Recalculate(const AFontSize fontsize) const override {
255 if (fontsize.IsValid())
256 m_mathFontSize = fontsize;
257 else
258 m_mathFontSize = m_configuration->GetMathFontSize();
259 m_fontSize = m_mathFontSize;
260 Recalculate();
261 }
262 bool Recalculate() const;
264 void SetCurrentPoint(wxPoint point) override;
265 wxPoint CalculateInputPosition() const;
266
268 void RecalculateInput() const;
269 wxRect GetRect(bool all = false) const override;
275 void RecalculateOutput() const;
276
278 void BreakLines() const;
279
285 void ResetInputLabel();
286
288 void ResetInputLabelList();
290
292 bool IsFoldable() const;
293
295 GroupCell *GetHiddenTree() const { return m_hiddenTree.get(); }
296
303 bool HideTree(std::unique_ptr<GroupCell> &&tree);
304
306 std::unique_ptr<GroupCell> UnhideTree();
307
314 bool RevealHidden();
315
317 void SetHiddenTreeParent(GroupCell *parent, GroupCell *last = nullptr);
318
323 GroupCell *Fold(); // returns pointer to this or NULL if not successful
328 GroupCell *Unfold();
329
335
341
347 bool IsLesserGCType(GroupType comparedTo) const;
348
350 bool IsMainInput(const Cell *active) const;
351
352 bool IsHeading() const;
354 bool SectioningCanMoveIn() const {return IsHeading() && (GetGroupType() != GC_TYPE_HEADING6);};
356 bool SectioningCanMoveOut() const {return IsHeading() && (GetGroupType() != GC_TYPE_TITLE);}
359
361 void Number(int &section, int &subsection, int &subsubsection, int &heading5, int &heading6, int &image) const;
362
374 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
375
376 bool AddEnding() override;
377
379 void DrawBracket(wxDC *dc, wxDC *antialiassingDC);
380
382 bool Empty() const;
383
385 bool Contains(GroupCell *cell) const;
386
388 wxString ToString() const override;
389
391 void InEvaluationQueue(bool inQueue) { m_inEvaluationQueue = inQueue; }
392
394 void LastInEvaluationQueue(bool last) { m_lastInEvaluationQueue = last; }
395
397 void OnSize();
398
400 void InputHeightChanged();
401
402 typedef std::unordered_map <wxString, int, wxStringHash> CmdsAndVariables;
403
405 std::vector<std::pair<wxString, wxString>> m_knownAnswers;
406
407#if wxUSE_ACCESSIBILITY
408 wxAccStatus GetDescription(int childId, wxString *description) const override;
409 wxAccStatus GetLocation (wxRect &rect, int elementId) override;
410 wxAccStatus GetRole (int childId, wxAccRole *role) const override;
411#endif
412
414 void UpdateYPosition() const;
415
416 void UpdateOutputPositions() const;
417
418 void UpdateYPositionList() const;
419
420 bool GetSuppressTooltipMarker() const { return m_suppressTooltipMarker; }
421 void SetSuppressTooltipMarker(bool suppress) { m_suppressTooltipMarker = suppress; }
422
423protected:
424 wxCoord GetInputIndent() const;
425 bool NeedsRecalculation(AFontSize fontSize) const override;
426 void UpdateCellsInGroup();
427
428//** 16-byte objects (16 bytes)
429//**
430 mutable wxRect m_outputRect{-1, -1, 0, 0};
431
432//** 8/4 byte objects (40 bytes)
433//**
434 CellPointers *const m_cellPointers = GetCellPointers();
435
436 std::unique_ptr<GroupCell> m_hiddenTree;
438
439 // The pointers below point to inner cells and must be kept contiguous.
440 // ** All pointers must be the same: either Cell * or std::unique_ptr<Cell>.
441 // ** NO OTHER TYPES are allowed.
443 std::unique_ptr<Cell> m_inputLabel;
445 std::unique_ptr<Cell> m_output;
446 // The pointers above point to inner cells and must be kept contiguous.
447
448//** 4-byte objects (16 bytes)
449//**
450 mutable int m_labelWidth_cached = 0;
451 mutable int m_inputWidth, m_inputHeight;
452protected:
453//** 2-byte objects (6 bytes)
454//**
456 int16_t m_cellsInGroup = 1;
457 mutable int16_t m_numberedAnswersCount = 0;
458
459 mutable AFontSize m_mathFontSize;
460
461//** 1-byte objects (1 byte)
462//**
465
466//** Bitfield objects (1 bytes)
467//**
468 void InitBitFields_GroupCell()
469 { // Keep the initialization order below same as the order
470 // of bit fields in this class!
471 m_autoAnswer = false;
472 m_inEvaluationQueue = false;
473 m_lastInEvaluationQueue = false;
474 m_updateConfusableCharWarnings = true;
476 m_cellsAppended = false;
477 m_layoutSuppressed = false;
478 }
479
481 bool m_autoAnswer : 1 /* InitBitFields_GroupCell */;
482 bool m_inEvaluationQueue : 1 /* InitBitFields_GroupCell */;
483 bool m_lastInEvaluationQueue : 1 /* InitBitFields_GroupCell */;
484 bool m_updateConfusableCharWarnings : 1 /* InitBitFields_GroupCell */;
486 bool m_suppressTooltipMarker : 1 /* InitBitFields_GroupCell */;
487 mutable bool m_cellsAppended : 1 /* InitBitFields_GroupCell */;
488 mutable bool m_layoutSuppressed : 1 /* InitBitFields_GroupCell */;
489
490 static wxString m_lookalikeChars;
491};
492
493#endif /* GROUPCELL_H */
The definition of the base class of all cells the worksheet consists of.
This file contains the definition of the class EditorCell.
std::ostream & operator<<(std::ostream &out, const GroupType grouptype)
Allow Standard c++ streams to print out our enum values as text.
Definition: GroupCell.cpp:1925
GroupType
All types a GroupCell can be of.
Definition: GroupCell.h:42
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:98
The storage for pointers to cells.
Definition: CellPointers.h:45
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
Cell * GetNext() const
Get the next cell in the list.
Definition: Cell.h:726
Cell * GetPrevious() const
Returns a pointer to the previous cell in the current cell list.
Definition: Cell.h:723
Cell * last() const
Get the last cell in this list of cells.
Definition: Cell.cpp:1182
AFontSize m_fontSize
The unscaled font size.
Definition: Cell.h:1087
virtual void SetCurrentPoint(wxPoint point)
Pass 2: Arrangement.
Definition: Cell.cpp:463
Configuration * m_configuration
A pointer to the configuration responsible for this worksheet.
Definition: Cell.h:1054
bool NeedsRecalculation() const
True, if something that affects the cell size has changed.
Definition: Cell.h:501
Cell * first() const
Get the first cell in this list of cells.
Definition: Cell.cpp:1173
The configuration storage for the current worksheet.
Definition: Configuration.h:85
This class defines what the user sees as input cell.
Definition: EditorCell.h:59
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87
bool ContainsSavedAnswers() const
Does this GroupCell know the answer to any of maxima's questions?
Definition: GroupCell.h:112
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Draw this GroupCell.
Definition: GroupCell.cpp:689
bool Contains(GroupCell *cell) const
Does this tree contain the cell "cell"?
Definition: GroupCell.cpp:1771
void Hide(bool hide) override
Hide this cell. See IsHidden() for details.
Definition: GroupCell.cpp:1486
GroupCell * m_hiddenTreeParent
store linkage to the parent of the fold
Definition: GroupCell.h:437
std::vector< std::pair< wxString, wxString > > m_knownAnswers
A list of answers provided by the user.
Definition: GroupCell.h:405
bool IsFoldable() const
folding and unfolding
Definition: GroupCell.cpp:197
void BreakLines() const
Break this cell into lines.
Definition: GroupCell.cpp:1450
virtual bool FirstLineOnlyEditor() const override
True, if this GroupCell is folded and its editor shows only its first line.
Definition: GroupCell.cpp:1480
bool RevealHidden()
Unfold all that is needed to make the current cell seen.
Definition: GroupCell.cpp:1547
void CellUnderPointer(GroupCell *cell)
Marks the cell that is under the mouse pointer.
Definition: GroupCell.cpp:763
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:1691
GroupType m_groupType
Which type this cell is of?
Definition: GroupCell.h:464
void UpdateOutputPositions() const
Pass 2 (Arrange): Calculates positions for all cells in the output.
Definition: GroupCell.cpp:632
GroupCell * GetHiddenTree() const
Get the tree of cells that got hidden by folding this cell.
Definition: GroupCell.h:295
std::unique_ptr< GroupCell > UnhideTree()
Unfold the current cell.
Definition: GroupCell.cpp:1533
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: GroupCell.cpp:975
bool m_autoAnswer
Does this GroupCell automatically fill in the answer to questions?
Definition: GroupCell.h:481
size_t GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: GroupCell.h:120
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: GroupCell.cpp:979
void DrawBracket(wxDC *dc, wxDC *antialiassingDC)
Draw the bracket of this cell.
Definition: GroupCell.cpp:775
void RemoveOutput()
Remove all output cells attached to this one.
Definition: GroupCell.cpp:295
Cell * GetLabel() const
Returns the list of cells the output consists of, starting with the label.
Definition: GroupCell.h:236
void SetCurrentPoint(wxPoint point) override
Pass 2 (Arrange): Sets the GroupCell position and triggers child layout.
Definition: GroupCell.cpp:673
const wxString GetToolTip(wxPoint point) const override
Returns the tooltip for the element at the position point.
Definition: GroupCell.cpp:1403
Range GetInnerCellsInRect(const wxRect &rect) const override
Select the cells inside this cell described by the rectangle rect.
Definition: GroupCell.cpp:1345
std::unique_ptr< Cell > m_inputLabel
The input label of this cell. Is followed by the input of the cell.
Definition: GroupCell.h:443
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
wxRect GetRect(bool all=false) const override
Get the smallest rectangle this cell fits in.
Definition: GroupCell.cpp:751
GroupCell * SectioningUnitGetEndOf() const
Get the end of this section/subsection/...
void UpdateConfusableCharWarnings()
GroupCells warn if they contain both greek and latin lookalike chars.
Definition: GroupCell.cpp:343
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
void RecalculateInput() const
Recalculate the height of the input part of the cell.
Definition: GroupCell.cpp:457
void SetHiddenTreeParent(GroupCell *parent, GroupCell *last=nullptr)
Set the parent cell of hidden cells.
Definition: GroupCell.cpp:1560
void InputHeightChanged()
Reset the data when the input size changes.
Definition: GroupCell.cpp:424
void ResetInputLabel()
Reset the input label of the current cell.
Definition: GroupCell.cpp:181
void Recalculate(const AFontSize fontsize) const override
Recalculates the size of this GroupCell and all cells inside it if needed.
Definition: GroupCell.h:254
bool Empty() const
Is this list of cells empty?
Definition: GroupCell.cpp:173
wxRect GetOutputRect() const
Determine which rectangle is occupied by this GroupCell.
Definition: GroupCell.h:246
bool SectioningCanMoveIn() const
Can this chapter/section/... converted to a 'smaller' cell, e.g. section->subsection,...
Definition: GroupCell.h:354
void OnSize()
Called on MathCtrl resize.
Definition: GroupCell.cpp:445
GroupCell * Fold()
Fold this cell.
Definition: GroupCell.cpp:1568
void SetAnswer(const wxString &question, const wxString &answer)
Add a new answer to the cell.
Definition: GroupCell.cpp:234
void InEvaluationQueue(bool inQueue)
Is this cell part of the evaluation Queue?
Definition: GroupCell.h:391
int16_t m_cellsInGroup
The number of cells the current group contains (-1, if no GroupCell)
Definition: GroupCell.h:456
bool SectioningCanMoveOut() const
Can this chapter/section/... converted to a 'larger' cell, e.g. subsection->section,...
Definition: GroupCell.h:356
void UpdateYPosition() const
Recalculate the cell's y position using the position and height of the last one.
Definition: GroupCell.cpp:586
GroupCell * UnfoldAll()
Unfold all cells.
Definition: GroupCell.cpp:1631
Cell * GetOutput() const
Returns the list of cells the output consists of, starting after the label.
Definition: GroupCell.h:242
bool HideTree(std::unique_ptr< GroupCell > &&tree)
Fold the current cell.
Definition: GroupCell.cpp:1513
std::unique_ptr< GroupCell > m_hiddenTree
here hidden (folded) tree of GCs is stored
Definition: GroupCell.h:436
void LastInEvaluationQueue(bool last)
Is this cell the last cell in the evaluation Queue?
Definition: GroupCell.h:394
wxString ToString() const override
A textual representation of this cell.
Definition: GroupCell.cpp:947
bool AutoAnswer() const
Does this GroupCell save the answer to a question?
Definition: GroupCell.h:114
GroupCell * GetLastWorkingGroup() const
Which GroupCell was the last maxima was working on?
Definition: GroupCell.cpp:246
GroupCell * GetPrevious() const
Get the previous GroupCell in the list.
Definition: GroupCell.h:219
bool AddEnding() override
Add a semicolon to a code cell, if needed.
Definition: GroupCell.cpp:747
GroupCell * GetNext() const
Get the next GroupCell in the list.
Definition: GroupCell.h:223
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: GroupCell.h:121
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: GroupCell.cpp:1220
void RecalculateOutput() const
Recalculate the height of the output part of the cell.
Definition: GroupCell.cpp:514
void ResetInputLabelList()
Call ResetInputLabel() on all cells in the list of cells this GroupCell starts with.
Definition: GroupCell.cpp:188
GroupCell * Unfold()
Unfold this cell.
Definition: GroupCell.cpp:1605
std::unique_ptr< Cell > m_output
The maxima output this cell contains.
Definition: GroupCell.h:445
bool IsLesserGCType(GroupType comparedTo) const
Document structure: Can this cell type be part of the contents of comparedTo?
Definition: GroupCell.cpp:1644
bool m_suppressTooltipMarker
Suppress the yellow ToolTip marker?
Definition: GroupCell.h:486
GroupCell * FoldAll()
Fold all cells.
Definition: GroupCell.cpp:1616