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
73class GroupCell final : public Cell
74{
75public:
76 GroupCell(Configuration *config, GroupType groupType, const wxString &initString = {});
77 GroupCell(GroupCell const &cell);
78 GroupCell(GroupCell *group, const GroupCell &cell);
79 std::unique_ptr<Cell> Copy() const;
80 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
81 const CellTypeInfo &GetInfo() override;
82 std::unique_ptr<GroupCell> CopyList() const;
83 virtual ~GroupCell();
84
85 // cppcheck-suppress duplInheritedMember
86 GroupCell *first() const { return dynamic_cast<GroupCell*>(Cell::first()); }
87 // cppcheck-suppress duplInheritedMember
88 GroupCell *last() const { return dynamic_cast<GroupCell*>(Cell::last()); }
89
90 const wxString &GetAnswer(size_t answer) const;
91 const wxString &GetAnswer(const wxString &question) const;
93 bool ContainsSavedAnswers() const { return !m_knownAnswers.empty(); }
95 bool AutoAnswer() const { return m_autoAnswer; }
96 void SetAutoAnswer(bool autoAnswer);
97 void MarkNeedsRecalculate(){m_cellsAppended = true;}
99 void SetAnswer(const wxString &question, const wxString &answer);
100
101 size_t GetInnerCellCount() const override { return (m_groupType == GC_TYPE_PAGEBREAK) ? 0 : 2; }
102 // cppcheck-suppress objectIndex
103 Cell *GetInnerCell(size_t index) const override { return (&m_inputLabel)[index].get(); }
104
111
117 void CellUnderPointer(GroupCell *cell);
118
123 const wxString GetToolTip(wxPoint point) const override;
124
125 // general methods
126 GroupType GetGroupType() const { return m_groupType; }
127
128 void SetGroupType(GroupType groupType);
129
130 // selection methods
131 Range GetInnerCellsInRect(const wxRect &rect) const override;
132
133 Range GetCellsInOutput() const;
134
135 Range GetCellsInOutputRect(const wxRect &rect, wxPoint one, wxPoint two) const;
136
137 // methods for manipulating GroupCell
138 // cppcheck-suppress functionConst
139 bool SetEditableContent(const wxString &text);
140
141 void AppendOutput(std::unique_ptr<Cell> &&cell);
142
149 void RemoveOutput();
150
151 AFontSize EditorFontSize() const;
152
155
165 wxString ToTeX(const wxString &imgDir, const wxString &filename, std::size_t *imgCounter) const;
166
167 wxString ToRTF() const override;
168
169 wxString ToTeXCodeCell(const wxString &imgDir, const wxString &filename, std::size_t *imgCounter) const;
170
171 static wxString ToTeXImage(const Cell *tmp, const wxString &imgDir, const wxString &filename, std::size_t *imgCounter);
172
173 wxString ToTeX() const override;
174
175 wxString ToXML() const override;
176
177 void Hide(bool hide) override;
178 virtual bool FirstLineOnlyEditor() override;
179 void SwitchHide();
180
181 wxRect HideRect() const;
182
183 // raw manipulation of GC (should be protected)
184 void SetInput(std::unique_ptr<Cell> &&input);
185
186 void SetOutput(std::unique_ptr<Cell> &&output);
187
188 void AppendInput(std::unique_ptr<Cell> &&cell);
189
191 // cppcheck-suppress duplInheritedMember
192 GroupCell *GetPrevious() const { return dynamic_cast<GroupCell *>(Cell::GetPrevious()); }
193
195 // cppcheck-suppress duplInheritedMember
196 GroupCell *GetNext() const { return dynamic_cast<GroupCell *>(Cell::GetNext()); }
197
198 static wxString TexEscapeOutputCell(wxString Input);
199
200 Cell *GetPrompt() const { return m_inputLabel.get(); }
201
202 EditorCell *GetEditable() const
203 { return m_inputLabel ? dynamic_cast<EditorCell *>(m_inputLabel->GetNext()) : nullptr; }
204
209 Cell *GetLabel() const { return m_output.get(); }
210
216 { return m_output ? m_output->GetNext() : nullptr; }
217
219 wxRect GetOutputRect() const { return m_outputRect; }
220
227 void Recalculate(AFontSize WXUNUSED(fontsize)) override {Recalculate();}
228 bool Recalculate();
229 wxPoint CalculateInputPosition();
230
232 void RecalculateInput();
233 wxRect GetRect(bool all = false) const override;
239 void RecalculateOutput();
240
242 void BreakLines();
243
249 void ResetInputLabel();
250
252 void ResetInputLabelList();
254
256 bool IsFoldable() const;
257
259 GroupCell *GetHiddenTree() const { return m_hiddenTree.get(); }
260
267 bool HideTree(std::unique_ptr<GroupCell> &&tree);
268
270 std::unique_ptr<GroupCell> UnhideTree();
271
278 bool RevealHidden();
279
281 void SetHiddenTreeParent(GroupCell *parent);
282
287 GroupCell *Fold(); // returns pointer to this or NULL if not successful
292 GroupCell *Unfold();
293
299
305
311 bool IsLesserGCType(GroupType comparedTo) const;
312
314 bool IsMainInput(const Cell *active) const;
315
316 bool IsHeading() const;
318 bool SectioningCanMoveIn() const {return IsHeading() && (GetGroupType() != GC_TYPE_HEADING6);};
320 bool SectioningCanMoveOut() const {return IsHeading() && (GetGroupType() != GC_TYPE_TITLE);}
323
325 void Number(int &section, int &subsection, int &subsubsection, int &heading5, int &heading6, int &image) const;
326
338 void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override;
339
340 bool AddEnding() override;
341
343 void DrawBracket(wxDC *dc, wxDC *antialiassingDC);
344
346 bool Empty() const;
347
349 bool Contains(GroupCell *cell) const;
350
352 wxString ToString() const override;
353
355 void InEvaluationQueue(bool inQueue) { m_inEvaluationQueue = inQueue; }
356
358 void LastInEvaluationQueue(bool last) { m_lastInEvaluationQueue = last; }
359
361 void OnSize();
362
364 void InputHeightChanged();
365
366 typedef std::unordered_map <wxString, wxString, wxStringHash> StringHash;
367 typedef std::unordered_map <wxString, int, wxStringHash> CmdsAndVariables;
368
370 StringHash m_knownAnswers;
371
372#if wxUSE_ACCESSIBILITY
373 wxAccStatus GetDescription(int childId, wxString *description) const override;
374 wxAccStatus GetLocation (wxRect &rect, int elementId) override;
375#endif
376
378 void UpdateYPosition();
379
380 void UpdateOutputPositions();
381
382 void UpdateYPositionList();
383
384 bool GetSuppressTooltipMarker() const { return m_suppressTooltipMarker; }
385 void SetSuppressTooltipMarker(bool suppress) { m_suppressTooltipMarker = suppress; }
386
387protected:
388 wxCoord GetInputIndent();
389 bool NeedsRecalculation(AFontSize fontSize) const override;
390 void UpdateCellsInGroup();
391
392//** 16-byte objects (16 bytes)
393//**
394 wxRect m_outputRect{-1, -1, 0, 0};
395
396//** 8/4 byte objects (40 bytes)
397//**
398 CellPointers *const m_cellPointers = GetCellPointers();
399
400 std::unique_ptr<GroupCell> m_hiddenTree;
402
403 // The pointers below point to inner cells and must be kept contiguous.
404 // ** All pointers must be the same: either Cell * or std::unique_ptr<Cell>.
405 // ** NO OTHER TYPES are allowed.
407 std::unique_ptr<Cell> m_inputLabel;
409 std::unique_ptr<Cell> m_output;
410 // The pointers above point to inner cells and must be kept contiguous.
411
412//** 4-byte objects (16 bytes)
413//**
414 int m_labelWidth_cached = 0;
415 int m_inputWidth, m_inputHeight;
416protected:
417//** 2-byte objects (6 bytes)
418//**
420 int16_t m_cellsInGroup = 1;
421 mutable int16_t m_numberedAnswersCount = 0;
422
423 AFontSize m_mathFontSize;
424
425//** 1-byte objects (1 byte)
426//**
429
430//** Bitfield objects (1 bytes)
431//**
432 void InitBitFields_GroupCell()
433 { // Keep the initialization order below same as the order
434 // of bit fields in this class!
435 m_autoAnswer = false;
436 m_inEvaluationQueue = false;
437 m_lastInEvaluationQueue = false;
438 m_updateConfusableCharWarnings = true;
440 m_cellsAppended = false;
441 }
442
444 bool m_autoAnswer : 1 /* InitBitFields_GroupCell */;
445 bool m_inEvaluationQueue : 1 /* InitBitFields_GroupCell */;
446 bool m_lastInEvaluationQueue : 1 /* InitBitFields_GroupCell */;
447 bool m_updateConfusableCharWarnings : 1 /* InitBitFields_GroupCell */;
449 bool m_suppressTooltipMarker : 1 /* InitBitFields_GroupCell */;
450 bool m_cellsAppended : 1; /* InitBitFields_GroupCell */
451
452 static wxString m_lookalikeChars;
453};
454
455#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:1877
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:694
Cell * GetPrevious() const
Returns a pointer to the previous cell in the current cell list.
Definition: Cell.h:691
Cell * last() const
Get the last cell in this list of cells.
Definition: Cell.cpp:1058
Cell * first() const
Get the first cell in this list of cells.
Definition: Cell.cpp:1049
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:74
bool ContainsSavedAnswers() const
Does this GroupCell know the answer to any of maxima's questions?
Definition: GroupCell.h:93
bool Contains(GroupCell *cell) const
Does this tree contain the cell "cell"?
Definition: GroupCell.cpp:1748
void Hide(bool hide) override
Hide this cell. See IsHidden() for details.
Definition: GroupCell.cpp:1467
GroupCell * m_hiddenTreeParent
store linkage to the parent of the fold
Definition: GroupCell.h:401
bool IsFoldable() const
folding and unfolding
Definition: GroupCell.cpp:244
StringHash m_knownAnswers
A list of answers provided by the user.
Definition: GroupCell.h:370
bool RevealHidden()
Unfold all that is needed to make the current cell seen.
Definition: GroupCell.cpp:1528
void CellUnderPointer(GroupCell *cell)
Marks the cell that is under the mouse pointer.
Definition: GroupCell.cpp:760
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:1668
void Recalculate(AFontSize WXUNUSED(fontsize)) override
Recalculates the size of this GroupCell and all cells inside it if needed.
Definition: GroupCell.h:227
GroupType m_groupType
Which type this cell is of?
Definition: GroupCell.h:428
bool NeedsRecalculation(AFontSize fontSize) const override
True, if something that affects the cell size has changed.
Definition: GroupCell.cpp:590
void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override
Draw this GroupCell.
Definition: GroupCell.cpp:667
GroupCell * GetHiddenTree() const
Get the tree of cells that got hidden by folding this cell.
Definition: GroupCell.h:259
std::unique_ptr< GroupCell > UnhideTree()
Unfold the current cell.
Definition: GroupCell.cpp:1514
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: GroupCell.cpp:957
bool m_autoAnswer
Does this GroupCell automatically fill in the answer to questions?
Definition: GroupCell.h:444
size_t GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: GroupCell.h:101
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: GroupCell.cpp:961
void DrawBracket(wxDC *dc, wxDC *antialiassingDC)
Draw the bracket of this cell.
Definition: GroupCell.cpp:764
void RemoveOutput()
Remove all output cells attached to this one.
Definition: GroupCell.cpp:332
Cell * GetLabel() const
Returns the list of cells the output consists of, starting with the label.
Definition: GroupCell.h:209
void RecalculateOutput()
Recalculate the height of the output part of the cell.
Definition: GroupCell.cpp:536
void RecalculateInput()
Recalculate the height of the input part of the cell.
Definition: GroupCell.cpp:491
Range GetInnerCellsInRect(const wxRect &rect) const override
Select the cells inside this cell described by the rectangle rect.
Definition: GroupCell.cpp:1326
std::unique_ptr< Cell > m_inputLabel
The input label of this cell. Is followed by the input of the cell.
Definition: GroupCell.h:407
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:748
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:380
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
void InputHeightChanged()
Reset the data when the input size changes.
Definition: GroupCell.cpp:463
void ResetInputLabel()
Reset the input label of the current cell.
Definition: GroupCell.cpp:228
const wxString GetToolTip(wxPoint point) const override
Returns the tooltip for the element at the position point.
Definition: GroupCell.cpp:1384
virtual bool FirstLineOnlyEditor() override
True, if this GroupCell is folded and its editor shows only its first line.
Definition: GroupCell.cpp:1461
bool Empty() const
Is this list of cells empty?
Definition: GroupCell.cpp:220
wxRect GetOutputRect() const
Determine which rectangle is occupied by this GroupCell.
Definition: GroupCell.h:219
bool SectioningCanMoveIn() const
Can this chapter/section/... converted to a 'smaller' cell, e.g. section->subsection,...
Definition: GroupCell.h:318
void OnSize()
Called on MathCtrl resize.
Definition: GroupCell.cpp:479
GroupCell * Fold()
Fold this cell.
Definition: GroupCell.cpp:1546
void SetAnswer(const wxString &question, const wxString &answer)
Add a new answer to the cell.
Definition: GroupCell.cpp:278
void InEvaluationQueue(bool inQueue)
Is this cell part of the evaluation Queue?
Definition: GroupCell.h:355
int16_t m_cellsInGroup
The number of cells the current group contains (-1, if no GroupCell)
Definition: GroupCell.h:420
bool SectioningCanMoveOut() const
Can this chapter/section/... converted to a 'larger' cell, e.g. subsection->section,...
Definition: GroupCell.h:320
GroupCell * UnfoldAll()
Unfold all cells.
Definition: GroupCell.cpp:1608
Cell * GetOutput() const
Returns the list of cells the output consists of, starting after the label.
Definition: GroupCell.h:215
bool HideTree(std::unique_ptr< GroupCell > &&tree)
Fold the current cell.
Definition: GroupCell.cpp:1494
std::unique_ptr< GroupCell > m_hiddenTree
here hidden (folded) tree of GCs is stored
Definition: GroupCell.h:400
void LastInEvaluationQueue(bool last)
Is this cell the last cell in the evaluation Queue?
Definition: GroupCell.h:358
wxString ToString() const override
A textual representation of this cell.
Definition: GroupCell.cpp:929
bool AutoAnswer() const
Does this GroupCell save the answer to a question?
Definition: GroupCell.h:95
GroupCell * GetLastWorkingGroup() const
Which GroupCell was the last maxima was working on?
Definition: GroupCell.cpp:283
void UpdateYPosition()
Recalculate the cell's y position using the position and height of the last one.
Definition: GroupCell.cpp:599
GroupCell * GetPrevious() const
Get the previous GroupCell in the list.
Definition: GroupCell.h:192
void BreakLines()
Break this cell into lines.
Definition: GroupCell.cpp:1431
bool AddEnding() override
Add a semicolon to a code cell, if needed.
Definition: GroupCell.cpp:744
GroupCell * GetNext() const
Get the next GroupCell in the list.
Definition: GroupCell.h:196
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: GroupCell.h:103
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: GroupCell.cpp:1202
void ResetInputLabelList()
Call ResetInputLabel() on all cells in the list of cells this GroupCell starts with.
Definition: GroupCell.cpp:235
GroupCell * Unfold()
Unfold this cell.
Definition: GroupCell.cpp:1583
std::unique_ptr< Cell > m_output
The maxima output this cell contains.
Definition: GroupCell.h:409
bool IsLesserGCType(GroupType comparedTo) const
Document structure: Can this cell type be part of the contents of comparedTo?
Definition: GroupCell.cpp:1621
bool m_suppressTooltipMarker
Suppress the yellow ToolTip marker?
Definition: GroupCell.h:449
void SetHiddenTreeParent(GroupCell *parent)
Set the parent cell of hidden cells.
Definition: GroupCell.cpp:1541
GroupCell * FoldAll()
Fold all cells.
Definition: GroupCell.cpp:1593