wxMaxima
Loading...
Searching...
No Matches
MatrixScrollbars.h
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
22#ifndef MATRIXSCROLLBARS_H
23#define MATRIXSCROLLBARS_H
24
25#include "cells/CellPtr.h"
26#include "cells/MatrCell.h"
27#include "cells/MatrixScrollHost.h"
28
29#include <wx/region.h>
30#include <wx/scrolbar.h>
31#include <wx/scrolwin.h>
32
33#include <memory>
34#include <vector>
35
62{
63public:
64 explicit MatrixScrollbars(wxScrolled<wxWindow> *worksheet);
65 ~MatrixScrollbars() override;
66 MatrixScrollbars(const MatrixScrollbars &) = delete;
67 MatrixScrollbars &operator=(const MatrixScrollbars &) = delete;
68
69 wxCoord ScrollbarThickness() const override;
70 void MatrixDrawn(MatrCell *matrix) override;
71
73 void BeginPaint();
78 void EndPaint(const wxRegion &updateRegion);
80 void Sync();
81
83 size_t VisibleScrollbars() const;
84
85private:
87 struct Entry
88 {
89 CellPtr<MatrCell> matrix;
90 wxScrollBar *horizontal = nullptr;
91 wxScrollBar *vertical = nullptr;
93 bool drawnThisPaint = false;
95 bool shown = false;
97 wxRect lastDrawnAt;
98 };
99
101 void SyncScrollbar(wxScrollBar *&scrollbar, int orientation, bool wanted,
102 const wxRect &where, int position, int thumbSize,
103 int range);
105 void OnScroll(wxScrollEvent &event);
107 static void DestroyScrollbars(Entry &entry);
108
109 wxScrolled<wxWindow> *const m_worksheet;
110 std::vector<std::unique_ptr<Entry>> m_entries;
112 bool m_syncPending = false;
113};
114
115#endif // MATRIXSCROLLBARS_H
Implementation of an observing weak Cell pointer.
A weak non-owning pointer that becomes null whenever the observed object is destroyed.
Definition: CellPtr.h:539
A Cell that displays a matrix.
Definition: MatrCell.h:92
Whatever can give a matrix real scrollbars.
Definition: MatrixScrollHost.h:46
The native scrollbars of the matrices a worksheet shows in a viewport.
Definition: MatrixScrollbars.h:62
size_t VisibleScrollbars() const
How many scrollbars are visible right now (for tests)
Definition: MatrixScrollbars.cpp:213
void EndPaint(const wxRegion &updateRegion)
To be called once a paint has drawn all it is going to.
Definition: MatrixScrollbars.cpp:98
void MatrixDrawn(MatrCell *matrix) override
A matrix that needs scrollbars has just been drawn.
Definition: MatrixScrollbars.cpp:75
void BeginPaint()
To be called before a paint draws any cell.
Definition: MatrixScrollbars.cpp:93
void Sync()
Creates, moves, shows and hides scrollbars as the last paint found.
Definition: MatrixScrollbars.cpp:128
wxCoord ScrollbarThickness() const override
How thick a native scrollbar is, in worksheet pixels.
Definition: MatrixScrollbars.cpp:66
Definition: CellPointers.h:34