wxMaxima
Loading...
Searching...
No Matches
TableOfContents.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) 2009-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2014-2018 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
28#include <memory>
29#include <wx/wx.h>
30#include <wx/timer.h>
31#include <wx/listctrl.h>
32#include <wx/dragimag.h>
33#include <vector>
34#include "precomp.h"
35#include "Configuration.h"
36#include "RegexCtrl.h"
37#include "cells/GroupCell.h"
38
39#ifndef TABLEOFCONTENTS_H
40#define TABLEOFCONTENTS_H
41
42enum
43{
44 structure_ctrl_id = 4,
45 structure_regex_id
46};
47
51class TableOfContents : public wxPanel
52{
53public:
54 TableOfContents(wxWindow *parent, int id, Configuration *config, std::unique_ptr<GroupCell> *tree);
55
56 /* The destructor
57 */
59
60 void OnMouseRightDown(wxListEvent &event);
61
63 void OnRegExEvent(wxCommandEvent &ev);
64
73
75 GroupCell *GetCell(std::size_t index);
76
79 { return m_cellRightClickedOn; }
80
81 GroupCell *DNDStart() {return m_dndStartCell;}
82 GroupCell *DNDEnd() {return m_dndEndCell;}
83
96 static long ClampDropIndex(long hitIndex, int itemCount,
97 std::size_t numberOfCaptionsDragged);
98protected:
99 void OnSize(wxSizeEvent &event);
100 void OnDragStart(wxListEvent &evt);
101 void OnMouseUp(wxMouseEvent &evt);
102 void OnMouseCaptureLost(wxMouseCaptureLostEvent &event);
103 void OnMouseMotion(wxMouseEvent &event);
104 void OnTimer(wxTimerEvent &event);
105
106 wxString TocEntryString(GroupCell *cell);
107private:
108 void UpdateStruct();
109 std::unique_ptr<GroupCell> *m_tree;
110 // CellPtrs, not raw pointers: the TOC is rebuilt asynchronously, so a cell
111 // recorded during a drag/right-click can be destroyed before the resulting
112 // menu/drop command reads it back via the getters below. Auto-nulling means a
113 // stale reference reads as nullptr (see "Long-lived cell references" in
114 // CellPtr.h); the consumers in wxMaxima.cpp null-check / GetTree()->Contains().
115 CellPtr<GroupCell> m_dndStartCell;
116 CellPtr<GroupCell> m_dndEndCell;
117 wxTimer m_scrollUpTimer;
118 wxTimer m_scrollDownTimer;
119 wxDragImage *m_dragImage = NULL;
120 // CellPtrs, not raw pointers: these caches can lag the worksheet tree, so an
121 // entry may refer to a cell that has since been deleted. Auto-nulling turns a
122 // stale entry into nullptr rather than a dangling pointer (see "Long-lived
123 // cell references" in CellPtr.h). Callers must therefore null-check entries.
124 std::vector<CellPtr<GroupCell>> m_displayedGroupCells;
126 std::size_t m_numberOfCaptionsDragged = 0;
127 CellPtr<GroupCell> m_cellRightClickedOn;
129 long m_dragStart = -1;
130 long m_dragStop = -1;
131 signed long m_dragCurrentPos = -1;
133 int m_dragFeedback_Last = -1;
135 long m_lastSelection;
136
138 void UpdateDisplay();
139
140 wxListCtrl *m_displayedItems;
141 RegexCtrl *m_regex;
143 wxArrayString m_items_old;
144 Configuration *m_configuration;
145
146 // CellPtrs for the same reason as m_displayedGroupCells above.
147 std::vector<CellPtr<GroupCell>> m_structure;
148};
149
150#endif // TABLEOFCONTENTS_H
This file defines the class GroupCell that bundles input and output in the worksheet.
A weak non-owning pointer that becomes null whenever the observed object is destroyed.
Definition: CellPtr.h:539
The configuration storage for the current worksheet.
Definition: Configuration.h:98
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
A BTextCtrl that allows to input a regex.
Definition: RegexCtrl.h:36
This class generates a pane containing the table of contents.
Definition: TableOfContents.h:52
GroupCell * GetCell(std::size_t index)
Get the nth Cell in the table of contents.
Definition: TableOfContents.cpp:440
void OnRegExEvent(wxCommandEvent &ev)
What happens if someone changes the search box contents.
Definition: TableOfContents.cpp:488
GroupCell * RightClickedOn()
Returns the cell that was last right-clicked on.
Definition: TableOfContents.h:78
void UpdateTableOfContents(GroupCell *pos)
Update the structure information from the tree.
Definition: TableOfContents.cpp:253
static long ClampDropIndex(long hitIndex, int itemCount, std::size_t numberOfCaptionsDragged)
Clamp a hit-tested drop position to a valid target.
Definition: TableOfContents.cpp:94