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;}
83protected:
84 void OnSize(wxSizeEvent &event);
85 void OnDragStart(wxListEvent &evt);
86 void OnMouseUp(wxMouseEvent &evt);
87 void OnMouseCaptureLost(wxMouseCaptureLostEvent &event);
88 void OnMouseMotion(wxMouseEvent &event);
89 void OnTimer(wxTimerEvent &event);
90
91 wxString TocEntryString(GroupCell *cell);
92private:
93 void UpdateStruct();
94 std::unique_ptr<GroupCell> *m_tree;
95 // CellPtrs, not raw pointers: the TOC is rebuilt asynchronously, so a cell
96 // recorded during a drag/right-click can be destroyed before the resulting
97 // menu/drop command reads it back via the getters below. Auto-nulling means a
98 // stale reference reads as nullptr (see "Long-lived cell references" in
99 // CellPtr.h); the consumers in wxMaxima.cpp null-check / GetTree()->Contains().
100 CellPtr<GroupCell> m_dndStartCell;
101 CellPtr<GroupCell> m_dndEndCell;
102 wxTimer m_scrollUpTimer;
103 wxTimer m_scrollDownTimer;
104 wxDragImage *m_dragImage = NULL;
105 // CellPtrs, not raw pointers: these caches can lag the worksheet tree, so an
106 // entry may refer to a cell that has since been deleted. Auto-nulling turns a
107 // stale entry into nullptr rather than a dangling pointer (see "Long-lived
108 // cell references" in CellPtr.h). Callers must therefore null-check entries.
109 std::vector<CellPtr<GroupCell>> m_displayedGroupCells;
111 std::size_t m_numberOfCaptionsDragged = 0;
112 CellPtr<GroupCell> m_cellRightClickedOn;
114 long m_dragStart = -1;
115 long m_dragStop = -1;
116 signed long m_dragCurrentPos = -1;
118 int m_dragFeedback_Last = -1;
120 long m_lastSelection;
121
123 void UpdateDisplay();
124
125 wxListCtrl *m_displayedItems;
126 RegexCtrl *m_regex;
128 wxArrayString m_items_old;
129 Configuration *m_configuration;
130
131 // CellPtrs for the same reason as m_displayedGroupCells above.
132 std::vector<CellPtr<GroupCell>> m_structure;
133};
134
135#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:489
The configuration storage for the current worksheet.
Definition: Configuration.h:87
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87
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:436
void OnRegExEvent(wxCommandEvent &ev)
What happens if someone changes the search box contents.
Definition: TableOfContents.cpp:484
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:249