wxMaxima
Loading...
Searching...
No Matches
EditorCell.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) 2006-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
24#ifndef EDITORCELL_H
25#define EDITORCELL_H
26
27#include "Cell.h"
28#include "FontAttribs.h"
29#include "MaximaTokenizer.h"
30#include "TextFormat.h"
31#include <wx/dataobj.h>
32#include <array>
33#include <optional>
34#include <vector>
35#include <algorithm>
36#include <list>
37#include <unordered_map>
38#include <utility>
39
40struct BidiRun;
41
66class EditorCell : public Cell
67{
68private:
69#if wxUSE_ACCESSIBILITY
70 wxAccStatus GetName (int childId, wxString *name) const override;
71 wxAccStatus GetDescription(int childId, wxString *description) const override;
72 wxAccStatus GetFocus (int *childId, Cell **child) const override;
73 wxAccStatus GetDefaultAction(int childId, wxString *actionName) const override;
74 wxAccStatus GetValue (int childId, wxString *strValue) const override;
75 wxAccStatus GetRole (int childId, wxAccRole *role) const override;
76 wxAccStatus GetState (int childId, long *state) const override;
77#endif
78
79public:
81 EditorCell(GroupCell *group, Configuration *config, wxString text = {});
82 EditorCell(GroupCell *group, const EditorCell &cell);
83
92 static std::unique_ptr<EditorCell> Create(GroupCell *group,
93 Configuration *config, CellType type,
94 wxString text = {});
95
97 static bool IsCodeType(CellType type);
98
106 virtual bool IsCodeEditor() const { return false; }
107 void UpdateSelectionString();
108 // The selection/cursor setters clamp their argument to a valid index into the
109 // current text via ClampToText(), so m_selectionStart / m_selectionEnd are
110 // always in [0, m_text.Length()] (e.g. CursorMove(-n) past the start clamps to
111 // 0 instead of wrapping a size_t to a huge value). The getters below keep a
112 // defensive std::min as well, because the text can still shrink *after* a
113 // selection was set without the selection being updated.
114 void SetSelection(size_t start, size_t end){m_selectionStart = ClampToText(start); m_selectionEnd = ClampToText(end); UpdateSelectionString();}
115 bool SelectionActive() const {return m_selectionStart != m_selectionEnd;}
116 void ClearSelection() {SelectionEnd(SelectionEnd());}
117 void SelectionStart(size_t start) {m_selectionStart = ClampToText(start); UpdateSelectionString();}
118 void SelectionEnd(size_t end) {m_selectionEnd = ClampToText(end); UpdateSelectionString();}
119 size_t SelectionStart() const {return std::min(m_selectionStart, m_text.Length());}
120 size_t SelectionEnd() const {return std::min(m_selectionEnd, m_text.Length());}
121 size_t SelectionLeft() const {return std::min(SelectionStart(), SelectionEnd());}
122 size_t SelectionRight() const {return std::max(SelectionStart(), SelectionEnd());}
123 size_t SelectionLength() const {return(SelectionEnd()-SelectionStart());}
124 void SelectionLength(size_t length) {SelectionEnd(SelectionStart() + length); UpdateSelectionString();}
125 void CursorMove(long long increment) {m_selectionEnd = ClampToText(static_cast<long long>(m_selectionEnd) + increment);
126 m_selectionStart = m_selectionEnd; UpdateSelectionString();}
127 size_t CursorPosition() const {return std::min(m_selectionEnd, m_text.Length());}
128 void CursorPosition(size_t pos) {m_selectionStart = ClampToText(pos);
129 m_selectionEnd = m_selectionStart; UpdateSelectionString();}
130 const CellTypeInfo &GetInfo() override;
131 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
132
134 // cppcheck-suppress duplInheritedMember
135 EditorCell *GetPrevious() const { return dynamic_cast<EditorCell*>(Cell::GetPrevious()); }
137 // cppcheck-suppress duplInheritedMember
138 EditorCell *GetNext() const { return dynamic_cast<EditorCell*>(Cell::GetNext()); }
139
141 void InsertEscCommand(const wxString &txt) {
142 InsertText(InterpretEscapeString(txt));
143 }
144
146 wxString GetFullCommandUnderCursor();
147
149 void AddDrawParameter(wxString param);
150
152 void AutoAnswer(bool autoAnswer){m_autoAnswer = autoAnswer;}
153
158 void SearchStartedHere(size_t index) const;
160 void SearchStartedHere() const;
162 void MouseSelectionStartedHere() const;
164 void KeyboardSelectionStartedHere() const;
165
167 const auto &GetWordList() const { return m_wordList; }
168
176 static wxString NormalizeLineEndings(const wxString &input_);
177
179 static wxString EscapeHTMLChars(wxString input);
180
182 static wxString PrependNBSP(wxString input);
183
184 void Recalculate(const AFontSize fontsize) const override;
185
187 void SetCurrentPoint(wxPoint point) const override;
188 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
189
191 wxString ToHTML() const;
192 wxString ToMatlab() const override;
200 wxString ToMatlab(bool dontLimitToSelection) const;
202 wxString ToRTF() const override;
203 wxString ToString() const override;
204 wxString ToString(bool dontLimitToSelection) const;
206 wxString ToTeX() const override;
208 wxString ToXML() const override;
209
211 const wxFont &GetFont() const {
213 }
220 const wxFont &GetFont(TextFormat::Format format) const;
222 void SetFont(wxDC *dc) const;
223
225 void SetForeground(wxDC *dc);
226
231 void SetValue(const wxString &text) override;
232
237 const wxString &GetValue() const override { return m_text; }
238
252 bool CanFormat() const { return !IsCodeEditor(); }
254 const TextFormat::Formats &GetFormats() const;
260 void SetFormats(TextFormat::Formats formats);
266 bool HasFormat(TextFormat::Format flag) const;
282 void SetUnknownLineAttributes(std::vector<std::pair<wxString, wxString>> attributes);
289 void CopyFormatsFrom(const EditorCell &source);
300 wxString SelectionToXML() const;
307 wxString FormattedRTF(size_t start, size_t end, bool markDown) const;
313 wxString FormattedHTML(size_t start, size_t end) const;
315 wxString SelectionToRTF() const;
317 wxString SelectionToHTML() const;
327 bool InsertXML(const wxString &xml);
335 bool InsertHTML(const wxString &html, wxString plainText = wxEmptyString);
341 static wxDataFormat FormattedTextDataFormat();
343
351 const std::vector<std::size_t> &GetSoftBreaks() const { return m_softBreaks; }
352
363 void SetDiffHighlights(std::vector<std::pair<std::size_t, std::size_t>> ranges) {
364 m_diffHighlights = std::move(ranges);
365 m_diffHighlightsTextLength = m_text.Length();
366 }
368 const std::vector<std::pair<std::size_t, std::size_t>> &GetDiffHighlights() const {
369 return m_diffHighlights;
370 }
371
382 void AddErrorStatement(std::size_t start, std::size_t end);
388 void AddErrorSpot(std::size_t start, std::size_t end);
390 void ClearErrorMarks();
392 const std::vector<std::pair<std::size_t, std::size_t>> &GetErrorStatements() const;
394 const std::vector<std::pair<std::size_t, std::size_t>> &GetErrorSpots() const;
396 bool ErrorMarksValid() const {
397 return m_errorMarks && (m_text == m_errorMarks->text);
398 }
399
408 void StyleText() const;
410 void StyleTextCode() const;
411 void StyleTextTexts() const;
412
413protected:
420 virtual void StyleTypedText() const;
421
428 virtual wxString PreprocessNewValue(const wxString &text,
429 std::size_t &cursorPos) const;
430
437 virtual wxString XMLTypeAttribute() const;
438
439public:
440 void Reset();
441
443 void ProcessEvent(wxKeyEvent &event) override;
444
452 bool ActivateCursor();
453
455 void DeactivateCursor();
456
458 size_t BeginningOfLine(size_t pos) const;
459
461 size_t EndOfLine(size_t pos);
462
464 bool AddEnding() override;
465
467 void PositionToXY(size_t position, size_t *x, size_t *y);
468
470 size_t XYToPosition(size_t x, size_t y);
471
473 wxPoint PositionToPoint(size_t pos) override;
478 wxPoint LineColumnToPoint(size_t line, size_t column, size_t pos);
479 wxPoint PositionToPoint() override {return PositionToPoint(CursorPosition());}
480
482 void SelectPointText(wxPoint point) override;
483
490 wxString GetLinkAt(wxPoint point) override;
491
493 void SelectRectText(wxPoint one, wxPoint two) override;
494
496 wxString SelectWordUnderCaret(bool selectParens = true, bool toRight = true,
497 bool includeDoubleQuotes = false);
498
500 bool IsPointInSelection(wxPoint point);
501
502 bool CopyToClipboard() const override;
503
504 bool CutToClipboard() override;
505
506 void PasteFromClipboard(bool primary = false) override;
507
509 size_t GetSelectionStart() const
510 { return SelectionStart(); }
511
513 long GetSelectionEnd() const
514 { return SelectionEnd(); }
515
517 void SelectAll() override
518 {
519 SetSelection(0, m_text.Length());
520 }
521
523 bool AllSelected() const
524 {
525 return (SelectionStart() == 0) && (SelectionEnd() == m_text.Length());
526 }
527
530 {
531 ClearSelection();
532 }
533
534
535 bool CanCopy() const override
536 {
537 return SelectionActive();
538 }
539
540 bool FindMatchingQuotes();
541
542 void FindMatchingParens();
543
549 std::pair<long, long> GetMatchingParens() const { return {m_paren1, m_paren2}; }
550
551 wxCoord GetLineWidth(size_t line, size_t pos);
552
558 wxCoord DigitGroupGapWidth() const;
560 wxSize GetTextSize(const wxString &text) const;
561
566 wxCoord NextTabStop(wxCoord startX) const;
567
576 wxCoord MeasureTextWidth(wxCoord startX, const wxString &text) const;
577
584 static bool IsStrongRightToLeft(wxUniChar c);
585
587 static bool IsStrongLeftToRight(wxUniChar c);
588
603 bool LineIsRightToLeft(size_t line);
604
606 bool LineIsMixedDirection(size_t line);
607
609 size_t LineLength(size_t line);
610
624 wxPoint SelectionLineSpan(size_t lineStart, size_t lineEnd, wxCoord *width);
625
634 bool GetLineBidiRuns(size_t line, std::vector<BidiRun> *runs);
635
642 bool MixedDirectionOffset(size_t line, size_t position, wxCoord *offset);
643
650 std::vector<wxCoord> RightToLeftLineOffsets();
651
653 wxCoord RightToLeftLineOffset(size_t line);
654
657 bool IsDirty() const override
658 {
659 return m_isDirty;
660 }
661
663 void SwitchCaretDisplay() override
664 {
665 m_displayCaret = !m_displayCaret;
666 }
667
668 void SetFocus(bool focus) override
669 {
670 m_hasFocus = focus;
671 }
672
673 bool IsActive() const override;
674
676 bool CaretAtStart() const
677 { return CursorPosition() == 0; }
678
680 void CaretToStart();
681
683 bool CaretAtEnd() const
684 { return CursorPosition() == m_text.Length(); }
685
687 void CaretToEnd();
688
690 void CaretToPosition(size_t pos);
691
702 bool CanUndo() const;
703
705 void Undo();
706
708 bool CanRedo() const {return m_history.CanRedo();}
709
711 void Redo();
712
715 {
716 public:
717 enum Action : uintptr_t {
718 any = 0,
719 removeChar = 1,
720 addChar = 2
721 };
722
724 class HistoryEntry // 64 bytes
725 {
726 public:
727 HistoryEntry() = default;
728 HistoryEntry(const wxString &text, long long selStart, long long selEnd,
729 TextFormat::Formats formats = {}) :
730 m_text(text), m_formats(std::move(formats)), m_selStart(selStart), m_selEnd(selEnd) {}
731 long long SelectionStart() const {return m_selStart;}
732 long long SelectionEnd() const {return m_selEnd;}
733 wxString GetText() const {return m_text;}
734 const TextFormat::Formats &GetFormats() const {return m_formats;}
736 bool SameContent(const HistoryEntry &other) const
737 {return (m_text == other.m_text) && (m_formats == other.m_formats);}
738 private:
739 wxString m_text;
741 TextFormat::Formats m_formats;
742 long long m_selStart = -1;
743 long long m_selEnd = -1;
744 };
745 bool AddState(const HistoryEntry& entry, Action action = any);
746 bool AddState(const wxString &text, long long selStart, long long selEnd, Action action = any,
747 TextFormat::Formats formats = {});
748 bool Undo();
749 bool Redo();
750 bool CanUndo() const;
752 bool CanUndoTo(const HistoryEntry &current) const;
753 bool CanRedo() const;
754 void ClearUndoBuffer();
755 HistoryEntry GetState() const;
756 private:
757 std::vector<HistoryEntry> m_history;
759 size_t m_historyPosition = 0;
760 Action m_lastAction = any;
761 };
762
764 void SaveValue(History::Action action = History::Action::any);
765
772 wxString DivideAtCaret();
773
774 void CommentSelection();
775
777 bool ContainsChanges() const
778 { return m_containsChanges; }
779
781 void ContainsChanges(bool changes)
782 { m_containsChanges = m_containsChangesCheck = changes; }
783
784 bool CheckChanges();
785
788 size_t ReplaceAll(wxString oldString, const wxString &newString, bool ignoreCase);
789 size_t ReplaceAll_RegEx(const wxString &oldString, const wxString &newString);
790
801 bool FindNext(wxString str, const bool &down, const bool &ignoreCase);
802 bool FindNext_RegEx(const wxString& str, const bool &down);
803
804 bool IsSelectionChanged() const { return m_selectionChanged; }
805
806 void GetSelection(size_t *start, size_t *end) const
807 {
808 *start = SelectionStart();
809 *end = SelectionEnd();
810 }
811
824 bool ReplaceSelection(const wxString &oldStr, const wxString &newString,
825 bool keepSelected = false, bool ignoreCase = false,
826 bool replaceMaximaString = false);
827 bool ReplaceSelection_RegEx(const wxString &oldStr, const wxString &newString);
828
830 wxString GetSelectionString() const;
831
834
836 wxString GetWordUnderCaret();
837
839 wxString GetCurrentCommand() const;
840
842 void SetErrorIndex(size_t index){m_errorIndex = index; m_errorIndexSet = true;}
844 void ClearErrorIndex(){m_errorIndexSet = false;}
845
846 bool ErrorIndexSet() const {return m_errorIndexSet;}
847
848 void GotoError(){SetCaretPosition(m_errorIndex); ActivateCursor(); ClearErrorIndex();}
849
851 void ProcessNewline(bool keepCursorAtStartOfLine = true);
852
854 size_t GetCaretPosition() const
855 { return CursorPosition(); }
856
859
861 void SetCaretPosition(size_t pos){CursorPosition(pos);}
862
863 bool FindNextTemplate(bool left = false);
864
865 void InsertText(wxString text);
866
867 wxString TextInFrontOfSelection() const
868 {
869 return GetValue().Left(SelectionLeft());
870 }
871
874 {
875 SetSelection(m_lastSelectionStart, 0);
876 }
877
878 void SetType(CellType type) override;
879 void SetStyle(TextStyle style) override;
880
881 bool NeedsRecalculation(AFontSize fontSize) const override;
882
885 {
886 SetSelection(m_lastSelectionStart, m_text.Length());
887 }
888
890// const MaximaTokenizer::TokenList &GetDisplayedTokens() const;
892 const MaximaTokenizer::TokenList &GetAllTokens() const;
893
894private:
900 void InsertFormatted(const wxString &text, const TextFormat::Formats &pasted);
908 void PushTextLine(const wxString &line, const wxString &indentChar,
909 std::size_t startPos) const;
917 wxCoord PushCodeLine(TextStyle style, const wxString &line) const;
925 void PushTextRun(const wxString &run, const wxString &indentChar,
926 std::size_t startPos) const;
931 void PushFormattedPiece(const wxString &piece, const wxString &indentChar,
932 std::size_t startPos, bool isLink) const;
933
942 template <typename SnippetFunc>
943 void WalkDrawnSnippets(wxDC *dc, SnippetFunc &&onSnippet);
944
948 size_t ClampToText(long long pos) const {
949 if (pos < 0)
950 return 0;
951 return std::min(static_cast<size_t>(pos), m_text.Length());
952 }
953 size_t m_selectionStart = 0;
954 size_t m_selectionEnd = 0;
955 size_t m_lastSelectionStart = 0;
956protected:
971 {
972 private:
975 wxString m_text;
977 TextStyle m_style = TS_CODE_DEFAULT;
979 wxString m_indentChar;
981 mutable CachedInteger<wxCoord> m_width;
983 wxCoord m_indentPixels = 0;
985 bool m_styleThisText = false;
987 bool m_isLink = false;
989 TextFormat::Format m_format = TextFormat::None;
997 wxCoord m_yOffset = 0;
998 public:
1000 StyledText(TextStyle style, const wxString &text)
1001 : m_text(text), m_style(style), m_styleThisText(true) {}
1002
1004 explicit StyledText(const wxString &text, TextStyle style, wxCoord indentPixels = 0,
1005 const wxString &indentChar = {})
1006 : m_text(text), m_style(style), m_indentChar(indentChar), m_indentPixels(indentPixels) {}
1007
1008 void SetWidth(wxCoord width){m_width = width;}
1009 void ResetSize(){m_width.Invalidate();}
1010 wxCoord GetWidth() const {return m_width;}
1011 bool SizeKnown() const {return m_width.IsValid();}
1013 const wxString &GetText() const { return m_text; }
1015 void SetText(const wxString &text) { m_text = text; }
1017 void SetIndentation(wxCoord indentPixels, const wxString &indentString = {})
1018 {
1019 m_indentPixels = indentPixels;
1020 m_indentChar = indentString;
1021 }
1023 wxCoord GetIndentPixels() const { return m_indentPixels; }
1024 const wxString &GetIndentChar() const { return m_indentChar; }
1027 TextStyle GetTextStyle() const { return m_style; }
1028 // Has an individual text style been set for this text portion?
1029 bool IsStyleSet() const { return m_styleThisText; }
1031 bool IsLink() const { return m_isLink; }
1033 void SetLink() { m_isLink = true; }
1035 TextFormat::Format GetFormat() const { return m_format; }
1037 void SetFormat(TextFormat::Format format) { m_format = format; }
1039 wxCoord GetYOffset() const { return m_yOffset; }
1041 void SetYOffset(wxCoord yOffset) { m_yOffset = yOffset; }
1050 const std::vector<size_t> &GetDigitGaps() const { return m_digitGaps; }
1052 void SetDigitGaps(std::vector<size_t> gaps) { m_digitGaps = std::move(gaps); }
1053 private:
1055 std::vector<size_t> m_digitGaps;
1056 };
1057
1058private:
1059#if defined __WXOSX__
1060 bool HandleCtrlCommand(wxKeyEvent &ev);
1061#endif
1062 bool HandleSpecialKey(wxKeyEvent &event);
1063 bool HandleOrdinaryKey(wxKeyEvent &event);
1064
1065 void FontsChanged() const override
1066 {
1067 m_widths.clear();
1068 }
1069
1085 struct SoftBreakCandidate {
1086 std::size_t snippetIdx = 0;
1087 std::size_t textPos = 0;
1088 bool insert = false;
1089 bool valid = false;
1090 };
1091
1096 void HandleSoftLineBreaks_Code(SoftBreakCandidate &candidate, wxCoord &lineWidth,
1097 wxCoord tokenWidth, wxCoord &indentationPixels) const;
1098
1106 wxCoord SnippetWidth(const StyledText &snippet, size_t length) const;
1108 wxCoord SnippetWidth(const StyledText &snippet) const {
1109 return SnippetWidth(snippet, snippet.GetText().Length());
1110 }
1112 void DrawSnippetText(wxDC *dc, const StyledText &snippet, wxCoord x,
1113 wxCoord y) const;
1120 wxCoord DigitGapsWidthIn(size_t from, size_t to) const;
1121
1129 static bool BreakAfterOperator(const wxString &token, const wxString &prevToken,
1130 const wxString &nextToken);
1131
1138 bool IsSoftBreakBefore(std::size_t pos) const {
1139 return std::ranges::binary_search(m_softBreaks, pos);
1140 }
1141
1147 size_t GetIndentDepth(wxString text, size_t positionOfCaret) const;
1148
1155 static wxString InterpretEscapeString(const wxString &txt);
1156
1158 void MarkSelection(wxDC *dc, size_t start, size_t end, TextStyle style);
1159
1161 wxSize GetTextSize(const wxString &text, TextFormat::Format format) const;
1165 wxCoord MeasureTextWidth(wxCoord startX, const wxString &text,
1166 std::size_t startPos) const;
1168 void SyncFormats() const;
1169
1182 struct LineSlot {
1185 wxCoord top = 0;
1187 wxCoord above = 0;
1189 wxCoord below = 0;
1190 };
1192 static constexpr double g_superSubscriptScale = 0.65;
1198 static wxCoord BaselineShift(TextFormat::Format format, wxCoord plainAscent);
1201 wxCoord LineTop(size_t line) const;
1203 void LineSlotExtent(size_t line, wxCoord *top, wxCoord *height) const;
1205 size_t LineAt(wxCoord y) const;
1207
1209 History m_history;
1211 void SetState(const History::HistoryEntry &state);
1213 std::vector<StyledText> &GetStyledText();
1214
1215//** Large fields
1216//**
1217 using StringHash = std::unordered_map<wxString, wxSize, wxStringHash>;
1219 mutable StringHash m_widths;
1220
1222 mutable std::vector<wxString> m_wordList;
1223
1225 mutable MaximaTokenizer::TokenList m_tokens;
1227 mutable MaximaTokenizer::TokenList m_tokens_including_hidden;
1228
1231 mutable wxString m_text;
1232protected:
1234 mutable std::vector<StyledText> m_styledText;
1235private:
1236
1252 mutable std::vector<std::size_t> m_softBreaks;
1259 mutable std::vector<std::size_t> m_digitGapPositions;
1260
1267 struct FormatState {
1269 TextFormat::Formats formats;
1271 wxString formatsText;
1275 TextFormat::Format pendingFormat = TextFormat::None;
1276 std::size_t pendingPos = 0;
1277 bool hasPending = false;
1279 std::vector<std::pair<wxString, wxString>> unknownLineAttributes;
1282 std::array<std::optional<wxFont>, TextFormat::FontVariants> fonts;
1284 std::optional<wxFont> fontsBase;
1285 };
1287 mutable std::unique_ptr<FormatState> m_formatState;
1294 mutable std::vector<LineSlot> m_lineSlots;
1296 FormatState &GetFormatState() const;
1297
1299 std::vector<std::pair<std::size_t, std::size_t>> m_diffHighlights;
1303 std::size_t m_diffHighlightsTextLength = 0;
1305 struct ErrorMarks {
1306 std::vector<std::pair<std::size_t, std::size_t>> statements;
1307 std::vector<std::pair<std::size_t, std::size_t>> spots;
1313 wxString text;
1314 };
1316 std::unique_ptr<ErrorMarks> m_errorMarks;
1317
1318//** 8/4 bytes
1319//**
1320 DocumentCellPointers *const m_documentCellPointers = GetDocumentCellPointers();
1321 ViewCellPointers *const m_viewCellPointers = GetViewCellPointers();
1322
1323//** 4 bytes
1324//**
1325 size_t m_errorIndex = 1;
1326 mutable size_t m_numberOfLines = 1;
1327 mutable wxCoord m_charHeight = 12;
1328 long m_paren1 = -1, m_paren2 = -1;
1329
1330//** 2 bytes
1331//**
1332 AFontStyle m_fontStyle;
1333 AFontWeight m_fontWeight;
1334
1335//** Bitfield objects (2 bytes)
1336//**
1338 bool m_autoAnswer : 1 = false;
1340 mutable bool m_containsChanges : 1 = false;
1341 bool m_containsChangesCheck : 1 = false;
1342 bool m_displayCaret : 1 = false;
1343 bool m_hasFocus : 1 = false;
1344 bool m_errorIndexSet : 1 = false;
1346 bool m_selectionChanged : 1 = false;
1348 bool m_underlined : 1 = false;
1350 mutable bool m_tokens_including_hidden_valid : 1 = false;
1352 mutable bool m_tokens_valid : 1 = false;
1354 mutable bool m_containsLinks : 1 = false;
1355 mutable bool m_isDirty : 1 = true;
1356};
1357
1358#endif // EDITORCELL_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
This file declares the class Maximatokenizer.
Character formatting (bold, italic, superscript, ...) of the text in a text cell (GH #492).
std::vector< Format > Formats
One Format per character, indexed like the text it belongs to; empty = plain.
Definition: TextFormat.h:111
std::uint8_t Format
The formatting of one character: a combination of the flags below.
Definition: TextFormat.h:68
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
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:99
A cached integer value.
Definition: CachedValue.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:148
Cell * GetNext() const
Get the next cell in the list.
Definition: Cell.h:930
Cell * GetPrevious() const
Returns a pointer to the previous cell in the current cell list.
Definition: Cell.h:927
Configuration * m_configuration
A pointer to the configuration responsible for this worksheet.
Definition: Cell.h:1265
DocumentCellPointers * GetDocumentCellPointers() const
The document-model half of the cell-pointer registry this cell uses.
Definition: Cell.cpp:70
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:532
AFontSize m_fontSize_Scaled
The font size is smaller in super- and subscripts.
Definition: Cell.h:1305
ViewCellPointers * GetViewCellPointers() const
The transient view-state half of the cell-pointer registry this cell uses.
Definition: Cell.cpp:74
bool NeedsRecalculation() const
True, if something that affects the cell size has changed.
Definition: Cell.h:647
const TextStyle & GetTextStyle() const
Get the text style.
Definition: Cell.h:729
The configuration storage for the current worksheet.
Definition: Configuration.h:102
const Style * GetStyle(TextStyle textStyle) const
Get the text Style for a given text style identifier.
Definition: Configuration.h:1325
The document-model half of the cell-pointer registry.
Definition: CellPointers.h:54
How an entry to the undo history looks like.
Definition: EditorCell.h:725
bool SameContent(const HistoryEntry &other) const
Do both entries hold the same text with the same formatting?
Definition: EditorCell.h:736
The undo history of this cell.
Definition: EditorCell.h:715
bool CanUndoTo(const HistoryEntry &current) const
Is there an entry before the current position that differs from current?
Definition: EditorCell.cpp:4311
A piece of styled text for syntax highlighting.
Definition: EditorCell.h:971
void SetDigitGaps(std::vector< size_t > gaps)
See GetDigitGaps()
Definition: EditorCell.h:1052
const wxString & GetText() const
Returns the piece of text.
Definition: EditorCell.h:1013
void SetFormat(TextFormat::Format format)
Sets the character formatting of this text portion.
Definition: EditorCell.h:1037
TextFormat::Format GetFormat() const
The character formatting all of this text portion has.
Definition: EditorCell.h:1035
void SetIndentation(wxCoord indentPixels, const wxString &indentString={})
Changes the indentation level of this token.
Definition: EditorCell.h:1017
void SetLink()
Marks this text portion as a link.
Definition: EditorCell.h:1033
void SetYOffset(wxCoord yOffset)
See m_yOffset.
Definition: EditorCell.h:1041
StyledText(const wxString &text, TextStyle style, wxCoord indentPixels=0, const wxString &indentChar={})
Defines a piece of text with the default style that possibly is indented.
Definition: EditorCell.h:1004
const std::vector< size_t > & GetDigitGaps() const
Where this text portion, a number in a code cell, gets the small gaps that separate its digit groups ...
Definition: EditorCell.h:1050
bool IsLink() const
Is this text portion a link? Its text is then the link's address.
Definition: EditorCell.h:1031
TextStyle GetTextStyle() const
If IsStyleSet() is true this function returns the style of this text portion.
Definition: EditorCell.h:1027
StyledText(TextStyle style, const wxString &text)
Defines a piece of styled text.
Definition: EditorCell.h:1000
wxCoord GetIndentPixels() const
By how many pixels do we need to indent this line due to a bullet list or similar?
Definition: EditorCell.h:1023
wxCoord GetYOffset() const
See m_yOffset.
Definition: EditorCell.h:1039
void SetText(const wxString &text)
Changes the piece of text kept in this token.
Definition: EditorCell.h:1015
This class defines what the user sees as input cell.
Definition: EditorCell.h:67
const MaximaTokenizer::TokenList & GetAllTokens() const
Get the list of commands, parenthesis, strings and whitespaces in a code cell.
Definition: EditorCell.cpp:5042
void SetValue(const wxString &text) override
Sets the text that is to be displayed.
Definition: EditorCell.cpp:5138
virtual wxString XMLTypeAttribute() const
The type="..." attribute ToXML() writes for this cell.
Definition: EditorCell.cpp:695
wxPoint LineColumnToPoint(size_t line, size_t column, size_t pos)
PositionToPoint() for a position whose display line and column are already known - or have to be forc...
Definition: EditorCell.cpp:3422
void SetCurrentPoint(wxPoint point) const override
Pass 2: Arrangement.
Definition: EditorCell.cpp:1078
size_t ReplaceAll(wxString oldString, const wxString &newString, bool ignoreCase)
Replaces all occurrences of a given string.
Definition: EditorCell.cpp:5179
const wxFont & GetFont() const
Get the font that matches this cell's formatting.
Definition: EditorCell.h:211
virtual wxString PreprocessNewValue(const wxString &text, std::size_t &cursorPos) const
Transform text on its way into SetValue(); returns what to store and sets cursorPos.
Definition: EditorCell.cpp:5095
wxCoord NextTabStop(wxCoord startX) const
Pixel x of the next 4-column tab stop at or after startX, where one column is the width of a space gl...
Definition: EditorCell.cpp:1920
void CaretToStart()
Move the cursor to the start of this cell.
Definition: EditorCell.cpp:5608
wxString GetLinkAt(wxPoint point) override
The address of the link drawn at the screen coordinate point, if any.
Definition: EditorCell.cpp:1369
bool InsertHTML(const wxString &html, wxString plainText=wxEmptyString)
Insert HTML another program put on the clipboard, formatting included.
Definition: EditorCell.cpp:1626
bool IsActive() const override
Is this editor cell focused?
Definition: EditorCell.cpp:4357
size_t XYToPosition(size_t x, size_t y)
Determines which index the char at the position "x chars left, y chars down" is at.
Definition: EditorCell.cpp:3377
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
size_t GetSelectionStart() const
Get the character position the selection has been started with.
Definition: EditorCell.h:509
void ContainsChanges(bool changes)
Set the information if this cell needs to be re-evaluated by maxima.
Definition: EditorCell.h:781
wxString ToXML() const override
Convert the current cell to XML code for inclusion in a .wxmx file.
Definition: EditorCell.cpp:669
void DeactivateCursor()
Deactivate the blinking cursor in the EditorCell it is in.
Definition: EditorCell.cpp:3247
void StyleTextCode() const
Is Called by StyleText() if this is a code cell.
Definition: EditorCell.cpp:4472
void SetDiffHighlights(std::vector< std::pair< std::size_t, std::size_t > > ranges)
Sets the character ranges of this cell's text the diff viewer wants painted with the TS_DIFF_CHANGED ...
Definition: EditorCell.h:363
void CaretToEnd()
Move the cursor to the end of this cell.
Definition: EditorCell.cpp:5602
const TextFormat::Formats & GetFormats() const
The formats of GetValue(), one per character; empty if it is plain.
Definition: EditorCell.cpp:1543
wxString SelectionToHTML() const
The selected text as a whole HTML document, for other programs.
Definition: EditorCell.cpp:1767
size_t GetCaretPosition() const
Get the cursor's current position inside the cell.
Definition: EditorCell.h:854
wxPoint SelectionLineSpan(size_t lineStart, size_t lineEnd, wxCoord *width)
Where the selection rectangle for [lineStart, lineEnd) goes.
Definition: EditorCell.cpp:970
bool ToggleFormat(TextFormat::Format flag)
Switch a format on or off, as the toolbar's buttons do.
Definition: EditorCell.cpp:1802
bool CopyToClipboard() const override
Copy this cell's editable contents to the clipboard.
Definition: EditorCell.cpp:3800
wxString ToRTF() const override
Convert the current cell to RTF code.
Definition: EditorCell.cpp:494
void ClearErrorIndex()
Clears the index the error is at.
Definition: EditorCell.h:844
wxCoord DigitGroupGapWidth() const
The width of one digit-group gap in a number (GH #192)
Definition: EditorCell.cpp:1980
wxString DivideAtCaret()
DivideAtCaret Returns the string from caret to end and modifies the m_text so it contains only the st...
Definition: EditorCell.cpp:3666
wxString ToString() const override
Returns the cell's representation as a string.
Definition: EditorCell.cpp:415
size_t BeginningOfLine(size_t pos) const
Return the index of the 1st char of the line containing the letter pos.
Definition: EditorCell.cpp:2038
static wxDataFormat FormattedTextDataFormat()
The private clipboard format SelectionToXML()'s result travels in.
Definition: EditorCell.cpp:1779
std::vector< StyledText > m_styledText
The styled-run rendering representation of m_text; see StyledText.
Definition: EditorCell.h:1234
std::vector< wxCoord > RightToLeftLineOffsets()
How far each line has to move right to sit flush with the widest one.
Definition: EditorCell.cpp:3980
wxString GetCurrentCommand() const
Get the command the cursor is in the arguments for.
Definition: EditorCell.cpp:1849
void SetUnknownLineAttributes(std::vector< std::pair< wxString, wxString > > attributes)
The attributes of the <line> elements of a loaded file this version doesn't understand,...
Definition: EditorCell.cpp:1568
bool IsDirty() const override
true, if this cell's width has to be recalculated.
Definition: EditorCell.h:657
void ProcessEvent(wxKeyEvent &event) override
Decide what to do if the user pressed a key when this cell was selected.
Definition: EditorCell.cpp:2130
wxCoord MeasureTextWidth(wxCoord startX, const wxString &text) const
Width, in pixels, of text when it starts at horizontal position startX on its line – like GetTextSize...
Definition: EditorCell.cpp:1927
virtual bool IsCodeEditor() const
Does this concrete cell edit code (Maxima input) rather than prose?
Definition: EditorCell.h:106
const std::vector< std::pair< std::size_t, std::size_t > > & GetErrorSpots() const
The spots AddErrorSpot() has marked (for tests and inspection).
Definition: EditorCell.cpp:5134
bool CanRedo() const
True, if a redo can be done for this cell.
Definition: EditorCell.h:708
wxString GetSelectionString() const
Convert the current selection to a string.
Definition: EditorCell.cpp:5511
long GetSelectionEnd() const
Get the character position the selection has been ended with.
Definition: EditorCell.h:513
void Redo()
Issu a redo command.
Definition: EditorCell.cpp:4376
void SetCaretPosition(size_t pos)
Set the cursor's current position inside the cell.
Definition: EditorCell.h:861
size_t EndOfLine(size_t pos)
Return the index of the last char of the line containing the letter #pos,.
Definition: EditorCell.cpp:2060
void SearchStartedHere() const
Remember that this is the cell the search was started in.
Definition: EditorCell.cpp:336
bool CaretAtStart() const
Is the cursor at the start of this cell?
Definition: EditorCell.h:676
virtual void StyleTypedText() const
The code-vs-prose-specific half of StyleText(), chosen by the subclass.
Definition: EditorCell.cpp:5093
wxSize GetTextSize(const wxString &text) const
Determines the size of a text snippet.
Definition: EditorCell.cpp:1409
void KeyboardSelectionStartedHere() const
Remember that this is the cell the keyboard selection was started in.
Definition: EditorCell.cpp:345
static wxString NormalizeLineEndings(const wxString &input_)
Normalize line endings.
Definition: EditorCell.cpp:1914
bool ReplaceSelection(const wxString &oldStr, const wxString &newString, bool keepSelected=false, bool ignoreCase=false, bool replaceMaximaString=false)
Replace the current selection with a string.
Definition: EditorCell.cpp:5419
void SwitchCaretDisplay() override
Toggles the visibility of the cursor which is used to make it blink.
Definition: EditorCell.h:663
wxString SelectWordUnderCaret(bool selectParens=true, bool toRight=true, bool includeDoubleQuotes=false)
Selects the word the cursor is currently at.
Definition: EditorCell.cpp:3766
wxString ToTeX() const override
Convert the current cell to LaTeX code.
Definition: EditorCell.cpp:528
wxString FormattedHTML(size_t start, size_t end) const
[start, end) of the text as HTML, with its formatting.
Definition: EditorCell.cpp:1753
wxString SelectionToRTF() const
The selected text as a whole RTF document, for other programs.
Definition: EditorCell.cpp:1757
bool CanFormat() const
Can this cell's text be formatted at all? (Not if it is code.)
Definition: EditorCell.h:252
const wxString & GetValue() const override
Returns the text contained in this cell.
Definition: EditorCell.h:237
static bool IsStrongLeftToRight(wxUniChar c)
Is this character a strong left-to-right one?
Definition: EditorCell.cpp:4055
void CopyFormatsFrom(const EditorCell &source)
Take over another cell's formatting, for a cell that took over its text.
Definition: EditorCell.cpp:1575
const std::vector< std::pair< std::size_t, std::size_t > > & GetDiffHighlights() const
The ranges set by SetDiffHighlights() (empty outside the diff viewer).
Definition: EditorCell.h:368
void SelectAll() override
Select the whole text contained in this Cell.
Definition: EditorCell.h:517
void ClearErrorMarks()
Drops all marks AddErrorStatement() and AddErrorSpot() have set.
Definition: EditorCell.cpp:5126
void ReturnToSelectionFromBot()
Return to the selection after the cell has been left downwards.
Definition: EditorCell.h:884
bool CanCopy() const override
Select Can we copy the editable text of this cell?
Definition: EditorCell.h:535
void SelectNone()
Unselect everything.
Definition: EditorCell.h:529
bool FindMatchingQuotes()
For a given quotation mark ("), find a matching quote.
Definition: EditorCell.cpp:3141
void AddDrawParameter(wxString param)
Add a new parameter to a draw- or similar command including the comma, if needed.
Definition: EditorCell.cpp:254
void AutoAnswer(bool autoAnswer)
May this Editor Cell contain the answer to a question?
Definition: EditorCell.h:152
void StyleText() const
Converts m_text to a list of styled text snippets that will later be displayed by draw().
Definition: EditorCell.cpp:5061
bool MixedDirectionOffset(size_t line, size_t position, wxCoord *offset)
Where position sits, in pixels from the line's own left edge, found via the real bidi algorithm (GetL...
Definition: EditorCell.cpp:4129
wxString GetWordUnderCaret()
The word the cursor currently is at.
Definition: EditorCell.cpp:3727
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
std::pair< long, long > GetMatchingParens() const
The pair of brackets or quotes FindMatchingParens() found to highlight.
Definition: EditorCell.h:549
wxString GetFullCommandUnderCursor()
Get the whole maxima command that is currently under the cursor (including all arguments)
Definition: EditorCell.cpp:349
wxPoint PositionToPoint() override
Locates the cursor in the editable text of this cell.
Definition: EditorCell.h:479
wxString SelectionToXML() const
The selected text with its formatting, for the clipboard.
Definition: EditorCell.cpp:1587
bool GetLineBidiRuns(size_t line, std::vector< BidiRun > *runs)
Bidi::GetRuns() for a display line, as absolute positions into m_text (Bidi::GetRuns() itself only kn...
Definition: EditorCell.cpp:4108
void SelectRectText(wxPoint one, wxPoint two) override
Selects the text between the screen coordinates one and two.
Definition: EditorCell.cpp:3601
void SetErrorIndex(size_t index)
Sets the index the error is at.
Definition: EditorCell.h:842
size_t LineLength(size_t line)
How many characters the given display line holds, excluding its newline.
Definition: EditorCell.cpp:4078
bool AllSelected() const
Does the selection currently span the whole cell?
Definition: EditorCell.h:523
bool InsertXML(const wxString &xml)
Insert what SelectionToXML() made, formatting included.
Definition: EditorCell.cpp:1601
wxCoord RightToLeftLineOffset(size_t line)
RightToLeftLineOffsets() for a single line, 0 when there is none.
Definition: EditorCell.cpp:4032
TextStyle GetSelectionStyle() const
Try to determine the selection's text style.
Definition: EditorCell.cpp:5516
void SaveValue(History::Action action=History::Action::any)
Save the current contents of this cell in the undo buffer.
Definition: EditorCell.cpp:4387
bool ErrorMarksValid() const
True if there are error marks that still match the text.
Definition: EditorCell.h:396
void PositionToXY(size_t position, size_t *x, size_t *y)
Determines which line and column the pos'th char is at.
Definition: EditorCell.cpp:3348
bool IsPointInSelection(wxPoint point)
Is the point point inside the currently selected text?
Definition: EditorCell.cpp:3612
void PasteFromClipboard(bool primary=false) override
Paste from the clipboard into this cell.
Definition: EditorCell.cpp:3916
void Undo()
Issue an undo command.
Definition: EditorCell.cpp:4361
void AddErrorSpot(std::size_t start, std::size_t end)
Marks the place in a failing statement Maxima's syntax error points at.
Definition: EditorCell.cpp:5116
void SetFont(wxDC *dc) const
Set the currently used font to the one that matches this cell's formatting.
Definition: EditorCell.cpp:1401
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: EditorCell.cpp:441
bool LineIsRightToLeft(size_t line)
Is the given display line written right to left?
Definition: EditorCell.cpp:4062
bool CutToClipboard() override
Cut this cell's editable contents to the clipboard.
Definition: EditorCell.cpp:3869
EditorCell * GetPrevious() const
Get the previous EditorCell in the list.
Definition: EditorCell.h:135
static bool IsCodeType(CellType type)
Is type a code (Maxima-input) cell type, as opposed to text/sectioning?
Definition: EditorCell.cpp:242
bool CanUndo() const
True, if an undo would change this cell's contents.
Definition: EditorCell.cpp:4319
bool ActivateCursor()
Activate the blinking cursor in this cell.
Definition: EditorCell.cpp:3257
void SetStyle(TextStyle style) override
Sets the TextStyle of this cell.
Definition: EditorCell.cpp:1396
void InsertEscCommand(const wxString &txt)
Insert the symbol that corresponds to the ESC command txt.
Definition: EditorCell.h:141
bool FindNext(wxString str, const bool &down, const bool &ignoreCase)
Finds the next occurrences of a string.
Definition: EditorCell.cpp:5250
void CaretToPosition(size_t pos)
Move the cursor to a certain position in the cell.
Definition: EditorCell.cpp:5614
bool ContainsChanges() const
Query if this cell needs to be re-evaluated by maxima.
Definition: EditorCell.h:777
EditorCell * GetNext() const
Get the next EditorCell in the list.
Definition: EditorCell.h:138
const std::vector< std::pair< std::size_t, std::size_t > > & GetErrorStatements() const
The statements AddErrorStatement() has marked (for tests and inspection).
Definition: EditorCell.cpp:5129
bool AddEnding() override
Adds a ";" to the end of the last command in this cell in case that it doesn't end in $ or ;.
Definition: EditorCell.cpp:3289
void SetForeground(wxDC *dc)
Sets the current color to this cell's foreground color.
Definition: EditorCell.cpp:1845
bool CaretAtEnd() const
Is the cursor at the end of this cell?
Definition: EditorCell.h:683
void SelectPointText(wxPoint point) override
Sets the cursor to the screen coordinate point.
Definition: EditorCell.cpp:3459
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: EditorCell.cpp:1141
const std::vector< std::size_t > & GetSoftBreaks() const
The soft (word-wrap) line-break offsets of the last styling pass.
Definition: EditorCell.h:351
const auto & GetWordList() const
A list of words that might be applicable to the autocomplete function.
Definition: EditorCell.h:167
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: EditorCell.cpp:764
void SetFormats(TextFormat::Formats formats)
Replace the formats; one per character of GetValue(), or empty.
Definition: EditorCell.cpp:1551
void MouseSelectionStartedHere() const
Remember that this is the cell the mouse selection was started in.
Definition: EditorCell.cpp:341
void AddErrorStatement(std::size_t start, std::size_t end)
Marks a statement Maxima reported an error for (GH #289)
Definition: EditorCell.cpp:5105
wxString ToHTML() const
Convert the current cell to HTML code.
Definition: EditorCell.cpp:923
bool LineIsMixedDirection(size_t line)
Does this line mix strong characters of both directions?
Definition: EditorCell.cpp:4093
static std::unique_ptr< EditorCell > Create(GroupCell *group, Configuration *config, CellType type, wxString text={})
Construct the EditorCell subtype (code vs.
Definition: EditorCell.cpp:246
static bool IsStrongRightToLeft(wxUniChar c)
Is this character a strong right-to-left one (Hebrew, Arabic, Farsi, ...)?
Definition: EditorCell.cpp:4039
void ProcessNewline(bool keepCursorAtStartOfLine=true)
Start a new line and optionally auto-indent it.
Definition: EditorCell.cpp:2301
void ConvertNumToUNicodeChar()
Convert a number to unicode chars.
Definition: EditorCell.cpp:720
static wxString PrependNBSP(wxString input)
Convert all but the first of a row of multiple spaces to non-breakable.
Definition: EditorCell.cpp:383
wxString FormattedRTF(size_t start, size_t end, bool markDown) const
[start, end) of the text as RTF, with its formatting.
Definition: EditorCell.cpp:1749
static wxString EscapeHTMLChars(wxString input)
Escape all chars that cannot be used in HTML otherwise.
Definition: EditorCell.cpp:93
void ReturnToSelectionFromTop()
Return to the selection after the cell has been left upwards.
Definition: EditorCell.h:873
void SetType(CellType type) override
Sets the text style according to the type.
Definition: EditorCell.cpp:1391
bool HasFormat(TextFormat::Format flag) const
Is this format on where the user is?
Definition: EditorCell.cpp:1786
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
This class generates a pane containing the last commands that were issued.
Definition: History.h:56
const wxFont & GetFont(AFontSize fontSize) const
Returns the font associated with this style, but with the size fontSize.
Definition: TextStyle.cpp:348
The view/interaction half of the cell-pointer registry.
Definition: CellPointers.h:341
One maximal run of same-direction text within a display line, in visual (left-to-right on screen) ord...
Definition: Bidi.h:47