27#include "MatrixBlock.h"
117 return m_cells.at(
static_cast<size_t>(x) * m_matWidth + y).get(); }
123 void Draw(wxDC *dc, wxDC *antialiassingDC)
override;
145 return (block < m_paperCaptions.size()) ? m_paperCaptions.at(block)->ToString()
150 const wxString
GetToolTip(wxPoint point)
const override;
167 std::optional<MatrixBlock>
BlockInRect(
const wxRect &rect)
const;
205 {
return m_rowElision.Hides(row) || m_colElision.Hides(col); }
215 bool EntryAt(wxPoint point,
size_t &row,
size_t &col)
const;
263 void AddNewCell(std::unique_ptr<Cell> &&cell);
265 void NewRow() { m_matHeight++; m_dropCenters.emplace_back(-1, -1);}
266 void NewColumn() { m_matWidth++; m_widths.emplace_back(-1);}
280 wxString
ToCSV(
const wxString &delimiter)
const;
281 wxString
ToOMML()
const override;
299 wxString
ToTeX()
const override;
300 wxString
ToXML()
const override;
302 void SetSpecialFlag(
bool special) { m_specialMatrix = special; }
304 void SetInferenceFlag(
bool inference) { m_inferenceMatrix = inference; }
306 void RowNames(
bool rn) { m_rowNames = rn; }
308 void ColNames(
bool cn) { m_colNames = cn; }
310 void RoundedParens() { m_parenType = paren_rounded;}
311 void BracketParens() { m_parenType = paren_brackets;}
312 void StraightParens() { m_parenType = paren_straight;}
313 void AngledParens() { m_parenType = paren_angled;}
314 void NoParens() { m_parenType = paren_none;}
325 m_oversizedMode = mode ?
static_cast<uint8_t
>(*mode) : oversizedFollowConfig;
329 if (m_oversizedMode == oversizedFollowConfig)
336 static std::optional<Configuration::OversizedMatrices>
342 int drop = {}, center = {};
343 constexpr int Sum()
const {
return drop + center; }
344 constexpr DropCenter() =
default;
345 constexpr DropCenter(
int drop,
int center) : drop(drop), center(center) {}
355 constexpr bool Active()
const {
return count > 0; }
356 constexpr bool Hides(
size_t index)
const
357 {
return (index >= first) && (index < first +
count); }
371 static Elision ChooseElision(
const std::vector<wxCoord> &sizes,
372 wxCoord gapSize, wxCoord budget);
375 wxCoord ElementSkip()
const {
return Scale_Px(5);}
377 wxCoord DotsSkip()
const {
return Scale_Px(20);}
379 wxCoord DotPitch()
const;
381 wxCoord DotRadius()
const;
383 wxCoord DotsExtent()
const {
return 2 * DotPitch() + 2 * DotRadius(); }
385 wxCoord DotsGap()
const {
return DotsExtent() + DotsSkip() * 2;}
391 void DrawBrackets(wxDC *dc, wxDC *antialiassingDC, wxRect
box)
const;
397 void DrawOnPaper(wxDC *dc, wxDC *antialiassingDC);
399 wxCoord PaperBlockGap()
const {
return 2 * ElementSkip(); }
401 void DrawDots(wxDC *dc, wxPoint start, wxPoint step)
const;
403 void DrawElisionMarks(wxDC *dc)
const;
418 void DrawBands(wxDC *dc)
const;
426 {
return m_colElision.Active() || m_rowElision.Active() || IsScrolling(); }
444 m_banding = !banding ? bandingAuto : (*banding ? bandingOn : bandingOff);
448 if (m_banding == bandingAuto)
450 return m_banding == bandingOn;
460 bool IsScrolling()
const
461 {
return m_hasHorizontalScrollbar || m_hasVerticalScrollbar; }
463 bool IsEntryShown(
size_t row,
size_t col)
const;
465 wxRect EntrySlotRect(
size_t row,
size_t col)
const;
467 void ClampScrollPosition()
const;
469 static void MarkNestedMatrices(
Cell *list);
472 std::vector<std::unique_ptr<Cell>> m_cells;
474 mutable std::vector<wxCoord> m_widths;
475 mutable std::vector<DropCenter> m_dropCenters;
483 mutable wxSize m_contentSize;
485 mutable wxSize m_scrollableSize;
487 mutable wxPoint m_scroll;
489 mutable wxCoord m_scrollbarThickness = 0;
505 wxCoord captionHeight = 0;
514 mutable std::vector<PaperBlock> m_paperBlocks;
516 mutable std::vector<std::unique_ptr<Cell>> m_paperCaptions;
518 mutable double m_paperScale = 1;
521 mutable Elision m_colElision;
523 mutable Elision m_rowElision;
525 size_t m_matWidth = 0;
526 size_t m_matHeight = 0;
528 enum parenType : int8_t
538 uint8_t m_parenType : 3 = paren_rounded;
540 static constexpr uint8_t oversizedFollowConfig = 3;
542 oversizedFollowConfig,
543 "m_oversizedMode is too narrow for OversizedMatrices");
545 uint8_t m_oversizedMode : 2 = oversizedFollowConfig;
546 bool m_specialMatrix : 1 =
false;
547 bool m_inferenceMatrix : 1 =
false;
548 bool m_rowNames : 1 =
false;
549 bool m_colNames : 1 =
false;
551 bool m_nestedInMatrix : 1 =
false;
553 bool m_alwaysBanded : 1 =
false;
555 static constexpr uint8_t bandingAuto = 0, bandingOn = 1, bandingOff = 2;
557 uint8_t m_banding : 2 = bandingAuto;
558 mutable bool m_hasHorizontalScrollbar : 1 =
false;
559 mutable bool m_hasVerticalScrollbar : 1 =
false;
The definition of the base class of all cells the worksheet consists of.
@ count
Not a check: the number of checks.
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:99
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
wxCoord Scale_Px(double px) const
Scale font sizes and line widths according to the zoom factor.
Definition: Cell.h:181
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:532
The configuration storage for the current worksheet.
Definition: Configuration.h:102
OversizedMatrices
How to show a matrix too large for the window.
Definition: Configuration.h:524
@ scroll
Show a window-sized part of it, with native scrollbars.
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
A Cell that displays a matrix.
Definition: MatrCell.h:107
size_t ElidedColumns() const
How many columns are left out of the display (0 = none)
Definition: MatrCell.h:217
double GetPaperScale() const
How much the matrix was shrunk to fit the width of the page.
Definition: MatrCell.h:136
std::optional< Configuration::OversizedMatrices > GetOversizedMode() const
The mode SetOversizedMode() asked for, if any.
Definition: MatrCell.h:328
wxString ToString() const override
Returns the cell's representation as a string.
Definition: MatrCell.cpp:1204
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
wxString GetPaperBlockCaption(size_t block) const
The heading of a block of columns, e.g. "Columns 1 to 8"; empty if there is none.
Definition: MatrCell.h:144
size_t GetMatrixRows() const
How many rows the matrix has.
Definition: MatrCell.h:199
wxRect BlockRect(const MatrixBlock &block) const
Where the shown part of a block is drawn, e.g.
Definition: MatrCell.cpp:856
size_t GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: MatrCell.h:114
static wxString OversizedModeName(Configuration::OversizedMatrices mode)
The name wx_matrix() and the XML use for an oversized-matrix mode.
Definition: MatrCell.cpp:1161
wxPoint ScrollPosition() const
How far the matrix is scrolled.
Definition: MatrCell.h:244
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:1476
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: MatrCell.cpp:1428
bool IsWholeMatrix(const MatrixBlock &block) const
Is this block every entry of the matrix?
Definition: MatrCell.cpp:851
bool IsBanded() const
Does this matrix get alternating row/column bands? See DrawBands().
Definition: MatrCell.h:432
wxSize ScrollableSize() const
The size of the whole matrix, as it would be drawn without scrolling.
Definition: MatrCell.h:240
wxString ToCSV(const wxString &delimiter) const
The matrix as comma- (or tab-, ...) separated values (GH #2364)
Definition: MatrCell.cpp:1242
static constexpr double MinPaperScale
The smallest a matrix is shrunk to on paper before its columns are split instead.
Definition: MatrCell.h:131
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:1373
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: MatrCell.h:115
void SetCurrentPoint(wxPoint point) const override
Pass 2: Arrangement.
Definition: MatrCell.cpp:611
wxString ToRTFTable() const
The entries of the matrix as an RTF table (GH #959)
Definition: MatrCell.cpp:1264
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: MatrCell.cpp:71
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: MatrCell.cpp:1325
bool ScrollEntryIntoView(size_t row, size_t col)
Scrolls just far enough that an entry is inside the viewport (GH #2380)
Definition: MatrCell.cpp:401
size_t ElidedRows() const
How many rows are left out of the display (0 = none)
Definition: MatrCell.h:219
bool IsShownPartially() const
Does the worksheet show only part of this matrix right now?
Definition: MatrCell.h:425
bool EntryAt(wxPoint point, size_t &row, size_t &col) const
Which entry's slot is at this point?
Definition: MatrCell.cpp:692
std::vector< wxCoord > PageBreakCandidates() const override
Where a printed page may cut through this cell, if anywhere.
Definition: MatrCell.cpp:670
static std::optional< Configuration::OversizedMatrices > OversizedModeFromName(const wxString &name)
Parses OversizedModeName()'s output; std::nullopt if it isn't one.
Definition: MatrCell.cpp:1176
Range GetInnerCellsInRect(const wxRect &rect) const override
Select the cells inside this cell described by the rectangle rect.
Definition: MatrCell.cpp:803
std::unique_ptr< MatrCell > CopyBlock(const MatrixBlock &block, GroupCell *group) const
A new matrix holding only this block of entries.
Definition: MatrCell.cpp:888
size_t GetMatrixColumns() const
How many columns the matrix has.
Definition: MatrCell.h:201
bool IsNestedInMatrix() const
Does this matrix sit inside another matrix? Only the outermost one scrolls.
Definition: MatrCell.h:260
bool IsElided(size_t row, size_t col) const
Is the entry in this row and column left out of the display?
Definition: MatrCell.h:204
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void AlwaysBanded(bool banded)
Band this matrix even if it is shown in full.
Definition: MatrCell.h:457
const wxString GetToolTip(wxPoint point) const override
Returns the ToolTip this cell provides at a given point.
Definition: MatrCell.cpp:736
bool HasHorizontalScrollbar() const
Does this matrix show a horizontal scrollbar?
Definition: MatrCell.h:230
wxRect ViewportRect() const
The part of the worksheet the matrix's entries are shown in.
Definition: MatrCell.cpp:419
bool ScrollTo(wxPoint position)
Scrolls the matrix, clamped to its scrollable range.
Definition: MatrCell.cpp:377
size_t GetPaperColumnBlocks() const
How many blocks of columns the matrix was split into to fit the page.
Definition: MatrCell.h:142
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: MatrCell.cpp:917
wxSize ViewportSize() const
The size of the viewport onto it, brackets' margins included.
Definition: MatrCell.h:242
MatrixEntry StepEntry(const MatrixEntry &entry, int rowStep, int colStep) const
The entry one step away from this one, for Shift+arrow keys (GH #2370)
Definition: MatrCell.cpp:868
std::optional< bool > GetBanding() const
What SetBanding() asked for, if anything.
Definition: MatrCell.h:447
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: MatrCell.cpp:1222
wxRect VerticalScrollbarRect() const
Where the vertical scrollbar belongs; empty if there is none.
Definition: MatrCell.cpp:435
wxRect HorizontalScrollbarRect() const
Where the horizontal scrollbar belongs; empty if there is none.
Definition: MatrCell.cpp:428
std::optional< MatrixBlock > BlockInRect(const wxRect &rect) const
The block of shown entries a rectangle touches.
Definition: MatrCell.cpp:833
bool HasVerticalScrollbar() const
Does this matrix show a vertical scrollbar?
Definition: MatrCell.h:232
void SetBanding(std::optional< bool > banding)
Force alternating bands on (true) or off (false), or std::nullopt to decide by size.
Definition: MatrCell.h:443
void SetOversizedMode(std::optional< Configuration::OversizedMatrices > mode)
How this matrix wants to be shown if it is too large for the window.
Definition: MatrCell.h:324
Definition: showfont.cpp:47
A rectangular block of a matrix's entries: a sub-matrix (GH #2345)
Definition: MatrixBlock.h:47
One entry of a matrix, by its zero-based row and column.
Definition: MatrixBlock.h:30