wxMaxima
Loading...
Searching...
No Matches
ToolBar.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) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2008-2009 Ziga Lenarcic <zigalenarcic@users.sourceforge.net>
5// (C) 2012-2013 Doug Ilijev <doug.ilijev@gmail.com>
6// (C) 2015-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
7//
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 2 of the License, or
11// (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18//
19// You should have received a copy of the GNU General Public License
20// along with this program; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// SPDX-License-Identifier: GPL-2.0+
24
29#include <memory>
30#include <wx/wx.h>
31#include <wx/aui/aui.h>
32#include <wx/choice.h>
33#include "precomp.h"
34#include "cells/AnimationCell.h"
35#include "cells/GroupCell.h"
36#include "cells/TextFormat.h"
37#include "ToolBarSections.h"
38#include <vector>
39
40#ifndef _WXMAXIMA_TOOLBAR_H
41#define _WXMAXIMA_TOOLBAR_H
42
43class ToolBar : public wxAuiToolBar
44{
45public:
46 explicit ToolBar(wxWindow *parent);
50 {
54 };
55
62 { return section_menu_first + static_cast<int>(section); }
63
64 virtual ~ToolBar();
65
78 void EnableTool(int toolId, bool state)
79 {
80 if (GetToolEnabled(toolId) == state)
81 return;
82 wxAuiToolBar::EnableTool(toolId, state);
83 Refresh();
84 }
85
88 void SetToolBitmap(int toolId, const wxBitmapBundle &bitmap)
89 {
90 wxAuiToolBar::SetToolBitmap(toolId, bitmap);
91 Refresh();
92 }
93
96 {
97 if (!m_needsInformation)
98 {
99 SetToolBitmap(tb_follow, m_needsInformationIcon);
100 m_needsInformation = true;
101 }
102 }
103
106 {
107 if (m_needsInformation)
108 {
109 SetToolBitmap(tb_follow, m_followIcon);
110 m_needsInformation = false;
111 }
112 }
113
114 void AnimationButtonState(AnimationStartStopState state);
115
118 enum Event
119 {
120 plot_slider_id = 5500,
121 tb_interrupt,
122 tb_follow,
123 tb_eval,
124 tb_eval_all,
125 tb_evaltillhere,
126 tb_evaluate_rest,
127 tb_animation_startStop,
128 tb_animation_start,
129 tb_animation_stop,
130 tb_hideCode,
131 tb_changeStyle,
132 menu_restart_id,
135 tb_italic,
136 tb_underline,
137 tb_strikethrough,
138 tb_superscript,
139 tb_subscript
140 };
141
143 wxSlider *m_plotSlider = nullptr;
144
145 wxBitmap m_undoIcon;
146 wxBitmap m_redoIcon;
147 wxBitmap m_followIcon;
148 wxBitmap m_needsInformationIcon;
149 wxBitmap m_PlayButton;
150 wxBitmap m_StopButton;
151
152 void CanUndo(bool value)
153 {
154 if (value != m_canUndo_old)
155 {
156 EnableTool(wxID_UNDO, value);
157 m_canUndo_old = value;
158 }
159 }
160
161 void CanRedo(bool value)
162 {
163 if (value != m_canRedo_old)
164 {
165 EnableTool(wxID_REDO, value);
166 m_canRedo_old = value;
167 }
168 }
169
170 void CanCopy(bool value)
171 {
172 if (value != m_canCopy_old)
173 {
174 EnableTool(wxID_COPY, value);
175 m_canCopy_old = value;
176 }
177 }
178
179 void CanCut(bool value)
180 {
181 if (value != m_canCut_old)
182 {
183 EnableTool(wxID_CUT, value);
184 m_canCut_old = value;
185 }
186 }
187
188 void CanSave(bool value)
189 {
190 if (value != m_canSave_old)
191 {
192 EnableTool(wxID_SAVE, value);
193 m_canSave_old = value;
194 }
195 }
196
197 void CanPrint(bool value)
198 {
199 if (value != m_canPrint_old)
200 {
201 EnableTool(wxID_PRINT, value);
202 m_canPrint_old = value;
203 }
204 }
205
206 void CanEvalTillHere(bool value)
207 {
208 if (value != m_canEvalTillHere_old)
209 {
210 EnableTool(tb_evaltillhere, value);
211 EnableTool(tb_evaluate_rest, value);
212 m_canEvalTillHere_old = value;
213 }
214 }
215
216 void CanEvalThisCell(bool value)
217 {
218 if (value != m_canEvalThisCell_old)
219 {
220 EnableTool(tb_eval, value);
221 m_canEvalThisCell_old = value;
222 }
223 }
224
232 void TextFormatState(bool value, TextFormat::Format active);
233
234 void WorksheetEmpty(bool value)
235 {
236 if (value != m_worksheetEmpty_old)
237 {
238 EnableTool(tb_eval_all, !value);
239 m_worksheetEmpty_old = value;
240 }
241 }
242
244 void UpdateSlider(AnimationCell *cell);
245
246 int GetIdealHeight(){
247 return m_needsInformationIcon.GetSize().y;
248 }
249
251 void AddTools();
252
256 void SetCellStyle(GroupType style);
258 void UnsetCellStyle(){SetCellStyle(GC_TYPE_INVALID);}
260 void SetDefaultCellStyle(GroupType style) { m_defaultCellStyle = style; }
262 void SetDefaultCellStyle();
264 void UpdateBitmaps();
265
266 wxBitmap GetEvalAllBitmap(wxSize siz);
267 wxBitmap GetEvalBitmap(wxSize siz);
268 wxBitmap GetPreferencesBitmap(wxSize siz);
269 wxBitmap GetSelectAllBitmap(wxSize siz);
270 wxBitmap GetRestartBitmap(wxSize siz);
271 wxBitmap GetInterruptBitmap(wxSize siz);
272 wxBitmap GetEvalTillHereBitmap(wxSize siz);
273 wxBitmap GetEvalRestBitmap(wxSize siz);
274
275 wxSize GetOptimalBitmapSize();
276 wxSize GetPPI();
278 static bool ShowSection(ToolBarSections::Section section);
280 static void ShowSection(ToolBarSections::Section section, bool show);
282 static std::vector<ToolBarSections::Section> SectionOrder();
284 static void SectionOrder(const std::vector<ToolBarSections::Section> &order);
286 static wxString SectionName(ToolBarSections::Section section);
287
288protected:
290 static constexpr int section_menu_first = 6000;
293 void OnSize(wxSizeEvent &event);
294 void OnMouseRightDown(wxMouseEvent &event);
295 void OnMenu(wxCommandEvent &event);
296private:
298 wxSize m_ppi;
300 GroupType m_defaultCellStyle = GC_TYPE_CODE;
302 wxChoice *m_textStyle = nullptr;
304 std::size_t m_animationDisplayedIndex = 0;
306 std::size_t m_animationMaxIndex;
307 bool m_canRedo_old = true;
308 bool m_canUndo_old = true;
309 bool m_canCopy_old = true;
310 bool m_canCut_old = true;
311 bool m_canSave_old = true;
312 bool m_canPrint_old = true;
313 bool m_canEvalTillHere_old = true;
314 bool m_canEvalThisCell_old = true;
316 bool m_canFormatText_old = true;
317 bool m_worksheetEmpty_old = false;
318 AnimationStartStopState m_AnimationStartStopState = Inactive;
320 bool m_needsInformation = false;
321};
322
323#endif
This file declares the class AnimationCell.
This file defines the class GroupCell that bundles input and output in the worksheet.
GroupType
All types a GroupCell can be of.
Definition: GroupCell.h:43
Character formatting (bold, italic, superscript, ...) of the text in a text cell (GH #492).
std::uint8_t Format
The formatting of one character: a combination of the flags below.
Definition: TextFormat.h:68
The sections the main toolbar is made of, and the order they are shown in.
Section
A section of the main toolbar.
Definition: ToolBarSections.h:48
Definition: AnimationCell.h:46
Definition: ToolBar.h:44
void AddTools()
Remove all ools and then add all tools that are requested/fit in the toolbar/...
Definition: ToolBar.cpp:291
void ShowUserInputBitmap()
Show that user input is needed for maxima to continue.
Definition: ToolBar.h:95
void SetCellStyle(GroupType style)
Set the cell style to show for the current cell.
Definition: ToolBar.cpp:637
wxSlider * m_plotSlider
The slider for animations.
Definition: ToolBar.h:143
void UpdateBitmaps()
Update the bitmaps on ppi changes.
Definition: ToolBar.cpp:542
void UpdateSlider(AnimationCell *cell)
Updates the slider to match the Slide Show cell.
Definition: ToolBar.cpp:90
AnimationStartStopState
All states the "start/stop animation" toolbar button can be in.
Definition: ToolBar.h:50
@ Stopped
The animation is stopped.
Definition: ToolBar.h:52
@ Inactive
No animation is currently running.
Definition: ToolBar.h:53
@ Running
The animation is running.
Definition: ToolBar.h:51
static constexpr int section_menu_first
The first id of the sections' entries in the context menu.
Definition: ToolBar.h:290
void SetDefaultCellStyle(GroupType style)
Set the default cell style for new cells.
Definition: ToolBar.h:260
void TextFormatState(bool value, TextFormat::Format active)
Enable the character formatting buttons (only in a text cell)
Definition: ToolBar.cpp:682
void ShowFollowBitmap()
Stop showing that user input is needed for maxima to continue.
Definition: ToolBar.h:105
void UnsetCellStyle()
Called if there is no cell to show the style for.
Definition: ToolBar.h:258
void SetToolBitmap(int toolId, const wxBitmapBundle &bitmap)
Change a tool's icon, and repaint the toolbar so the change shows at once (wxAuiToolBar::SetToolBitma...
Definition: ToolBar.h:88
static wxString SectionName(ToolBarSections::Section section)
The (translated) name of a toolbar section, as the user sees it.
Definition: ToolBar.cpp:490
Event
A list of all events the Toolbar can receive.
Definition: ToolBar.h:119
@ tb_bold
The character formatting buttons for text cells (GH #492)
Definition: ToolBar.h:134
void AddSection(ToolBarSections::Section section)
Add the tools of one section of the toolbar.
Definition: ToolBar.cpp:373
static int SectionMenuId(ToolBarSections::Section section)
The id of a section's entry in the toolbar's context menu.
Definition: ToolBar.h:61
void EnableTool(int toolId, bool state)
Enable or disable a tool, and repaint the toolbar if that changed anything.
Definition: ToolBar.h:78
GroupType GetCellType()
Get the cell style for new cells.
Definition: ToolBar.cpp:612
static bool ShowSection(ToolBarSections::Section section)
Is a toolbar section shown? See ToolBarSections.
Definition: ToolBar.cpp:469
static std::vector< ToolBarSections::Section > SectionOrder()
The order the toolbar sections are shown in, from the config.
Definition: ToolBar.cpp:479
void SetDefaultCellStyle()
The current style is the new style for new cells.
Definition: ToolBar.cpp:581