wxMaxima
Loading...
Searching...
No Matches
MatrCell.h
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2014-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20//
21// SPDX-License-Identifier: GPL-2.0+
22
23#ifndef MATRCELL_H
24#define MATRCELL_H
25
26#include "Cell.h"
27#include "MatrixBlock.h"
28#include <optional>
29
30#include <vector>
31
106class MatrCell final : public Cell
107{
108public:
110 MatrCell(GroupCell *group, const MatrCell &cell);
111 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
112 const CellTypeInfo &GetInfo() override;
113
114 size_t GetInnerCellCount() const override { return m_cells.size(); }
115 Cell *GetInnerCell(size_t index) const override { return m_cells.at(index).get(); }
116 Cell *GetInnerCell(int x, int y) const {
117 return m_cells.at(static_cast<size_t>(x) * m_matWidth + y).get(); }
118
119 void Recalculate(const AFontSize fontsize) const override;
120
122 void SetCurrentPoint(wxPoint point) const override;
123 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
124
125 std::vector<wxCoord> PageBreakCandidates() const override;
126
131 static constexpr double MinPaperScale = 0.6;
136 double GetPaperScale() const { return m_paperScale; }
142 size_t GetPaperColumnBlocks() const { return m_paperBlocks.size(); }
144 wxString GetPaperBlockCaption(size_t block) const {
145 return (block < m_paperCaptions.size()) ? m_paperCaptions.at(block)->ToString()
146 : wxString();
147 }
149
150 const wxString GetToolTip(wxPoint point) const override;
151 Range GetInnerCellsInRect(const wxRect &rect) const override;
152
167 std::optional<MatrixBlock> BlockInRect(const wxRect &rect) const;
169 bool IsWholeMatrix(const MatrixBlock &block) const;
175 wxRect BlockRect(const MatrixBlock &block) const;
185 MatrixEntry StepEntry(const MatrixEntry &entry, int rowStep,
186 int colStep) const;
194 std::unique_ptr<MatrCell> CopyBlock(const MatrixBlock &block,
195 GroupCell *group) const;
197
199 size_t GetMatrixRows() const { return m_matHeight; }
201 size_t GetMatrixColumns() const { return m_matWidth; }
202
204 bool IsElided(size_t row, size_t col) const
205 { return m_rowElision.Hides(row) || m_colElision.Hides(col); }
215 bool EntryAt(wxPoint point, size_t &row, size_t &col) const;
217 size_t ElidedColumns() const { return m_colElision.count; }
219 size_t ElidedRows() const { return m_rowElision.count; }
220
230 bool HasHorizontalScrollbar() const { return m_hasHorizontalScrollbar; }
232 bool HasVerticalScrollbar() const { return m_hasVerticalScrollbar; }
234 wxRect HorizontalScrollbarRect() const;
236 wxRect VerticalScrollbarRect() const;
238 wxRect ViewportRect() const;
240 wxSize ScrollableSize() const { return m_scrollableSize; }
242 wxSize ViewportSize() const { return m_contentSize; }
244 wxPoint ScrollPosition() const { return m_scroll; }
250 bool ScrollTo(wxPoint position);
258 bool ScrollEntryIntoView(size_t row, size_t col);
260 bool IsNestedInMatrix() const { return m_nestedInMatrix; }
263 void AddNewCell(std::unique_ptr<Cell> &&cell);
264
265 void NewRow() { m_matHeight++; m_dropCenters.emplace_back(-1, -1);}
266 void NewColumn() { m_matWidth++; m_widths.emplace_back(-1);}
267
268 void SetDimension();
269
270 wxString ToMathML() const override;
271 wxString ToMatlab() const override;
280 wxString ToCSV(const wxString &delimiter) const;
281 wxString ToOMML() const override;
297 wxString ToRTFTable() const;
298 wxString ToString() const override;
299 wxString ToTeX() const override;
300 wxString ToXML() const override;
301
302 void SetSpecialFlag(bool special) { m_specialMatrix = special; }
303
304 void SetInferenceFlag(bool inference) { m_inferenceMatrix = inference; }
305
306 void RowNames(bool rn) { m_rowNames = rn; }
307
308 void ColNames(bool cn) { m_colNames = cn; }
309
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;}
315
324 void SetOversizedMode(std::optional<Configuration::OversizedMatrices> mode) {
325 m_oversizedMode = mode ? static_cast<uint8_t>(*mode) : oversizedFollowConfig;
326 }
328 std::optional<Configuration::OversizedMatrices> GetOversizedMode() const {
329 if (m_oversizedMode == oversizedFollowConfig)
330 return std::nullopt;
331 return static_cast<Configuration::OversizedMatrices>(m_oversizedMode);
332 }
336 static std::optional<Configuration::OversizedMatrices>
337 OversizedModeFromName(const wxString &name);
338
339private:
340 struct DropCenter
341 {
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) {}
346 };
347
349 struct Elision
350 {
352 size_t first = 0;
354 size_t count = 0;
355 constexpr bool Active() const { return count > 0; }
356 constexpr bool Hides(size_t index) const
357 { return (index >= first) && (index < first + count); }
358 };
359
371 static Elision ChooseElision(const std::vector<wxCoord> &sizes,
372 wxCoord gapSize, wxCoord budget);
373
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;
419public:
425 bool IsShownPartially() const
426 { return m_colElision.Active() || m_rowElision.Active() || IsScrolling(); }
432 bool IsBanded() const {
433 if (const auto banding = GetBanding())
434 return *banding;
435 return m_alwaysBanded || IsShownPartially();
436 }
443 void SetBanding(std::optional<bool> banding) {
444 m_banding = !banding ? bandingAuto : (*banding ? bandingOn : bandingOff);
445 }
447 std::optional<bool> GetBanding() const {
448 if (m_banding == bandingAuto)
449 return std::nullopt;
450 return m_banding == bandingOn;
451 }
457 void AlwaysBanded(bool banded) { m_alwaysBanded = banded; }
458private:
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);
470
472 std::vector<std::unique_ptr<Cell>> m_cells;
473
474 mutable std::vector<wxCoord> m_widths;
475 mutable std::vector<DropCenter> m_dropCenters;
476
483 mutable wxSize m_contentSize;
485 mutable wxSize m_scrollableSize;
487 mutable wxPoint m_scroll;
489 mutable wxCoord m_scrollbarThickness = 0;
490
496 struct PaperBlock
497 {
499 size_t firstCol = 0;
501 size_t endCol = 0;
503 wxCoord top = 0;
505 wxCoord captionHeight = 0;
507 wxCoord width = 0;
508 };
514 mutable std::vector<PaperBlock> m_paperBlocks;
516 mutable std::vector<std::unique_ptr<Cell>> m_paperCaptions;
518 mutable double m_paperScale = 1;
519
521 mutable Elision m_colElision;
523 mutable Elision m_rowElision;
524
525 size_t m_matWidth = 0;
526 size_t m_matHeight = 0;
527
528 enum parenType : int8_t
529 {
530 paren_rounded = 0,
531 paren_brackets = 1,
532 paren_angled = 2,
533 paren_straight = 3,
534 paren_none = 4
535 };
536//** Bitfield objects (1 bytes)
537//**
538 uint8_t m_parenType : 3 = paren_rounded;
540 static constexpr uint8_t oversizedFollowConfig = 3;
541 static_assert(static_cast<uint8_t>(Configuration::OversizedMatrices::scroll) <
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;
560};
561
562#endif // MATRCELL_H
The definition of the base class of all cells the worksheet consists of.
int group
Neighbouring sections of the same group aren't separated.
Definition: ToolBarSections.cpp:45
@ 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
Definition: emf.h:233