OpenCPN Partial API docs
Loading...
Searching...
No Matches
toolbar.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef TOOLBAR_H_
25#define TOOLBAR_H_
26
27#include <vector>
28
29#include <wx/bitmap.h>
30#include <wx/dynarray.h>
31#include <wx/string.h>
32#include <wx/tbarbase.h>
33#include <wx/menuitem.h>
34
35#include "ocpndc.h"
36#include "tooltip.h"
37#include "styles.h"
38
39class ocpnFloatingToolbarDialog; // forward
41
46public:
49
50 ToolbarItemContainer(int toolid, wxBitmap bmpNormal, wxBitmap bmpDisabled,
51 wxItemKind kind, wxString tooltip, wxString label) {
52 m_ID = toolid;
53 m_tipString = tooltip;
54 m_label = label;
55 m_toolKind = kind;
56 m_bmpNormal = bmpNormal;
57 m_bmpDisabled = bmpDisabled;
58 m_bRequired = false;
59 m_bPlugin = false;
60 }
61
62 ToolbarItemContainer(int toolid, wxBitmap bmpNormal, wxItemKind kind,
63 wxString tooltip, wxString label) {
64 m_ID = toolid;
65 m_tipString = tooltip;
66 m_label = label;
67 m_toolKind = kind;
68 m_bmpNormal = bmpNormal;
69 m_bmpDisabled = wxNullBitmap;
70 m_bRequired = false;
71 m_bPlugin = false;
72 }
73
74 int m_ID;
75 wxString m_tipString;
76 wxString m_label;
77 wxItemKind m_toolKind;
78 bool m_bRequired;
79 bool m_bPlugin;
80
81 wxBitmap m_bmpNormal;
82 wxBitmap m_bmpDisabled;
83 wxToolBarToolBase *m_tool;
84
85 // Supplemental SVG icons for plugin tools
86 wxString m_NormalIconSVG;
87 wxString m_RolloverIconSVG;
88 wxString m_ToggledIconSVG;
89};
90
91typedef std::vector<ToolbarItemContainer *> ArrayOfToolbarItemContainer;
92
93#define TOOLTIPON_TIMER 10000
94#define TOOLTIPOFF_TIMER 10001
95
96enum {
97 TOOLBAR_HIDE_TO_GRABBER = 0,
98 TOOLBAR_HIDE_TO_FIRST_TOOL,
99};
100
101class ToolTipWin;
102class ocpnToolBarTool;
103
108class ocpnToolBarSimple : public wxEvtHandler {
109public:
110 // ctors and dtor
111 ocpnToolBarSimple() { Init(); }
112
113 ocpnToolBarSimple(ocpnFloatingToolbarDialog *parent, wxWindowID winid,
114 const wxPoint &pos = wxDefaultPosition,
115 const wxSize &size = wxDefaultSize,
116 long style = wxNO_BORDER, int orient = wxTB_HORIZONTAL)
117 : m_one_shot(500) {
118 Init();
119
120 Create(parent, winid, pos, size, style, orient);
121 }
122
123 bool Create(ocpnFloatingToolbarDialog *parent, wxWindowID winid,
124 const wxPoint &pos = wxDefaultPosition,
125 const wxSize &size = wxDefaultSize, long style = wxNO_BORDER,
126 int orient = wxTB_HORIZONTAL);
127
128 virtual ~ocpnToolBarSimple();
129
130 virtual void SetToggledBackgroundColour(wxColour c) {
131 m_toggle_bg_color = c;
132 };
133 virtual void SetBackgroundColour(wxColour c) { m_background_color = c; }
134 virtual wxColour GetBackgroundColour() { return m_background_color; }
135 virtual void SetColorScheme(ColorScheme cs);
136
137 // event handlers
138 bool OnMouseEvent(wxMouseEvent &event, wxPoint &position);
139 void OnToolTipTimerEvent(wxTimerEvent &event);
140 void OnToolTipOffTimerEvent(wxTimerEvent &event);
141
142 wxToolBarToolBase *AddTool(int toolid, const wxString &label,
143 const wxBitmap &bitmap,
144 const wxBitmap &bmpDisabled,
145 wxItemKind kind = wxITEM_NORMAL,
146 const wxString &shortHelp = "",
147 const wxString &longHelp = "",
148 wxObject *data = NULL);
149
150 wxToolBarToolBase *AddTool(int toolid, const wxString &label,
151 const wxBitmap &bitmap,
152 const wxString &shortHelp = "",
153 wxItemKind kind = wxITEM_NORMAL) {
154 return AddTool(toolid, label, bitmap, wxNullBitmap, kind, shortHelp);
155 }
156
157 wxToolBarToolBase *InsertTool(size_t pos, int id, const wxString &label,
158 const wxBitmap &bitmap,
159 const wxBitmap &bmpDisabled, wxItemKind kind,
160 const wxString &shortHelp,
161 const wxString &longHelp, wxObject *clientData);
162
163 wxToolBarToolBase *InsertTool(size_t pos, wxToolBarToolBase *tool);
164
165 // Only allow toggle if returns true. Call when left button up.
166 virtual bool OnLeftClick(int toolid, bool toggleDown);
167
168 // Call when right button down.
169 virtual void OnRightClick(int toolid, long x, long y);
170
171 virtual void DoPluginToolUp();
172
173 bool IsDirty() { return m_dirty; }
174 void SetDirty(bool value) { m_dirty = value; }
175
176 size_t GetToolsCount() const { return m_tools.GetCount(); }
177 void SetToolShowCount(int count) { m_nShowTools = count; }
178 int GetToolShowCount() { return m_nShowTools; }
179
180 int GetNoRowsOrColumns() { return m_currentRowsOrColumns; };
181 int GetLineCount() { return m_LineCount; };
182 int GetVisibleToolCount();
183
184 void SetToolNormalBitmapEx(wxToolBarToolBase *tool, const wxString &iconname);
185 void SetToolNormalBitmapSVG(wxToolBarToolBase *tool, wxString fileSVG);
186
187 void EnableRolloverBitmaps(bool enable) {
188 m_tbenableRolloverBitmaps = enable;
189 }
190
191 wxBitmap &GetBitmap() { return m_bitmap; }
192
193 // get the control with the given id or return NULL
194 virtual wxControl *FindControl(int toolid);
195
196 // add a separator to the toolbar
197 virtual wxToolBarToolBase *AddSeparator();
198 virtual wxToolBarToolBase *InsertSeparator(size_t pos);
199
200 // remove the tool from the toolbar: the caller is responsible for actually
201 // deleting the pointer
202 virtual wxToolBarToolBase *RemoveTool(int toolid);
203
204 // delete tool either by index or by position
205 virtual bool DeleteToolByPos(size_t pos);
206 virtual bool DeleteTool(int toolid);
207
208 // delete all tools
209 virtual void ClearTools();
210
211 // must be called after all buttons have been created to finish toolbar
212 // initialisation
213 virtual bool Realize();
214
215 // tools state
216 // -----------
217
218 virtual void EnableTool(int toolid, bool enable);
219 virtual void ToggleTool(int toolid, bool toggle);
220
221 virtual void SetToolBitmaps(int toolid, wxBitmap *bmp, wxBitmap *bmpRollover);
222 virtual void SetToolBitmapsSVG(int id, wxString fileSVGNormal,
223 wxString fileSVGRollover,
224 wxString fileSVGToggled);
225
226 void InvalidateBitmaps();
227 wxBitmap &CreateBitmap(double display_scale = 1.0);
228
229 // set/get tools client data (not for controls)
230 virtual wxObject *GetToolClientData(int toolid) const;
231 virtual void SetToolClientData(int toolid, wxObject *clientData);
232
233 // returns tool pos, or wxNOT_FOUND if tool isn't found
234 virtual int GetToolPos(int id) const;
235
236 // return true if the tool is toggled
237 virtual bool GetToolState(int toolid) const;
238
239 virtual bool GetToolEnabled(int toolid) const;
240
241 virtual void SetToolShortHelp(int toolid, const wxString &helpString);
242 virtual wxString GetToolShortHelp(int toolid) const;
243 virtual void SetToolLongHelp(int toolid, const wxString &helpString);
244 virtual wxString GetToolLongHelp(int toolid) const;
245
246 virtual void SetToolTooltipHiViz(int id, bool b_hiviz);
247
248 virtual void SetSizeFactor(float factor) {
249 m_sizefactor = factor;
250 InvalidateBitmaps();
251 }
252 // toolbar geometry
253 // ----------------
254
255 // the toolbar can wrap - limit the number of columns or rows it may take
256 void SetMaxRowsCols(int rows, int cols) {
257 m_maxRows = rows;
258 m_maxCols = cols;
259 }
260 int GetMaxRows() const { return m_maxRows; }
261 int GetMaxCols() const { return m_maxCols; }
262
263 // get/set the size of the bitmaps used by the toolbar: should be called
264 // before adding any tools to the toolbar
265 virtual void SetToolBitmapSize(const wxSize &size) {
266 m_defaultWidth = size.x;
267 m_defaultHeight = size.y;
268 }
269 virtual wxSize GetToolBitmapSize() const {
270 return wxSize(m_defaultWidth, m_defaultHeight);
271 }
272
273 // the button size in some implementations is bigger than the bitmap size:
274 // get the total button size (by default the same as bitmap size)
275 virtual wxSize GetToolSize() const { return GetToolBitmapSize(); }
276
277 virtual wxRect GetToolRect(int tool_id);
278
279 // returns a (non separator) tool containing the point (x, y) or NULL if
280 // there is no tool at this point (corrdinates are client)
281 wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y);
282
283 // find the tool by id
284 wxToolBarToolBase *FindById(int toolid) const;
285
286 // return true if this is a vertical toolbar, otherwise false
287 bool IsVertical() const { return m_orient == wxTB_VERTICAL; }
288
289 // the list of all our tools
290 wxToolBarToolsList m_tools;
291
292 ocpnFloatingToolbarDialog *m_parentContainer;
293
294 // the maximum number of toolbar rows/columns
295 int m_maxRows;
296 int m_maxCols;
297
298 // the size of the toolbar bitmaps
299 wxCoord m_defaultWidth, m_defaultHeight;
300
301 // The size of the Realizeed toolbar
302 wxCoord m_maxWidth, m_maxHeight;
303
304 void HideTooltip();
305 void KillTooltip();
306 void EnableTooltips();
307 void DisableTooltips();
308
309protected:
310 // common part of all ctors
311 void Init();
312
313 // implement base class pure virtuals
314 virtual wxToolBarToolBase *DoAddTool(
315 int toolid, const wxString &label, const wxBitmap &bitmap,
316 const wxBitmap &bmpDisabled, wxItemKind kind,
317 const wxString &shortHelp = "", const wxString &longHelp = "",
318 wxObject *clientData = NULL, wxCoord xPos = wxDefaultCoord,
319 wxCoord yPos = wxDefaultCoord);
320
321 virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
322 virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
323
324 virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
325 virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
326
327 virtual wxToolBarToolBase *CreateTool(int winid, const wxString &label,
328 const wxBitmap &bmpNormal,
329 const wxBitmap &bmpDisabled,
330 wxItemKind kind, wxObject *clientData,
331 const wxString &shortHelp,
332 const wxString &longHelp);
333
334 // helpers
335 void DrawTool(wxToolBarToolBase *tool);
336 virtual void DrawTool(wxDC &dc, wxToolBarToolBase *tool);
337 void CreateToolBitmap(wxToolBarToolBase *toolBase);
338
339 bool m_dirty;
340 int m_currentRowsOrColumns;
341 int m_LineCount;
342
343 int m_pressedTool, m_currentTool;
344
345 wxCoord m_lastX, m_lastY;
346 wxCoord m_xPos, m_yPos;
347
348 wxColour m_toggle_bg_color;
349 wxColour m_toolOutlineColour;
350 wxColour m_background_color;
351
352 ocpnToolBarTool *m_last_ro_tool;
353
354 ColorScheme m_currentColorScheme;
355
356 wxTimer m_tooltip_timer;
357 int m_one_shot;
358 wxTimer m_tooltipoff_timer;
359 int m_tooltip_off;
360 bool m_btooltip_show;
361
362 bool m_btoolbar_is_zooming;
363
364 ocpnStyle::Style *m_style;
365 int m_orient;
366
367 float m_sizefactor;
368
369 int m_last_plugin_down_id;
370 bool m_leftDown;
371 int m_nShowTools;
372 bool m_tbenableRolloverBitmaps;
373
374 wxBitmap m_bitmap;
375
376private:
377 DECLARE_EVENT_TABLE()
378};
379
380//----------------------------------------------------------------------------------------------------------
381// ocpnFloatingToolbarDialog Specification
382//----------------------------------------------------------------------------------------------------------
383
384#define FADE_TIMER 2
385#define DESTROY_TIMER 3
386
390class ocpnFloatingToolbarDialog : public wxEvtHandler {
391public:
392 ocpnFloatingToolbarDialog(wxWindow *parent, wxPoint position, long orient,
393 float size_factor);
395
396 void OnClose(wxCloseEvent &event);
397 void OnWindowCreate(wxWindowCreateEvent &event);
398 void OnToolLeftClick(wxCommandEvent &event);
399 virtual void OnKeyDown(wxKeyEvent &event);
400 virtual void OnKeyUp(wxKeyEvent &event);
401 void OldMouseEvent(wxMouseEvent &event);
402 bool MouseEvent(wxMouseEvent &event);
403 void FadeTimerEvent(wxTimerEvent &event);
404 bool IsToolbarShown() { return (m_ptoolbar != 0); }
405 float GetScaleFactor() { return m_sizefactor; }
406 void DestroyTimerEvent(wxTimerEvent &event);
407 void DrawDC(ocpnDC &dc, double displayScale);
408 void DrawGL(ocpnDC &gldc, double displayScale);
409
410 void RefreshFadeTimer();
411
412 void EnableSubmerge(bool enable) { m_benableSubmerge = enable; }
413 void Realize();
414 ocpnToolBarSimple *GetToolbar();
415 ocpnToolBarSimple *CreateNewToolbar();
416 void SetToolbarHideMethod(int n_method) { n_toolbarHideMethod = n_method; }
417
418 void SetToolConfigString(wxString string) { m_configString = string; }
419 wxString GetToolConfigString() { return m_configString; }
420
421 float GetSizeFactor() { return m_sizefactor; }
422
423 void CreateConfigMenu();
424 bool _toolbarConfigMenuUtil(ToolbarItemContainer *tic);
425
426 void RefreshToolbar();
427
428 void Submerge();
429 void Surface();
430 void HideTooltip();
431 void ShowTooltips();
432 void EnableTooltips() {
433 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
434 }
435 void DisableTooltips() {
436 if (m_ptoolbar) m_ptoolbar->DisableTooltips();
437 }
438 void UpdateRecoveryWindow(bool b_toolbarEnable);
439 void EnableTool(int toolid, bool enable);
440 void SetToolShortHelp(int toolid, const wxString &helpString);
441
442 void DestroyToolBar();
443 void ToggleOrientation();
444 void MoveDialogInScreenCoords(wxPoint posn, wxPoint posn_old);
445 void SetDefaultPosition();
446 void LockPosition(bool lock) { m_block = lock; }
447 virtual void SetColorScheme(ColorScheme cs);
448 ColorScheme GetColorScheme() { return m_cs; }
449 bool CheckSurfaceRequest(wxMouseEvent &event);
450 void GetFrameRelativePosition(int *x, int *y);
451 void RestoreRelativePosition(int x, int y);
452
453 void SetGeometry(bool bAvoid, wxRect rectAvoid);
454 void SetMinX(int offset) { m_dock_min_x = offset; }
455 void SetMinY(int offset) { m_dock_min_y = offset; }
456 long GetOrient() { return m_orient; }
457 wxSize GetToolSize();
458 wxRect GetToolbarRect();
459 wxSize GetToolbarSize();
460 wxPoint GetToolbarPosition();
461
462 void SetAutoHideTimer(int time);
463 void SetAutoHide(bool hide) { m_bAutoHideToolbar = hide; }
464
465 size_t GetToolCount();
466 void SetToolShowMask(wxString mask);
467 wxString GetToolShowMask() { return m_toolShowMask; }
468
469 void SetToolShowCount(int count);
470 int GetToolShowCount();
471
472 bool CheckAndAddPlugInTool(ocpnToolBarSimple *tb);
473 bool AddDefaultPositionPlugInTools(ocpnToolBarSimple *tb);
474
475 int GetDockX() { return m_dock_x; }
476 int GetDockY() { return m_dock_y; }
477 void SetDockX(int x) { m_dock_x = x; }
478 void SetDockY(int y) { m_dock_y = y; }
479
480 void SetYAuxOffset(int offset) { m_auxOffsetY = offset; }
481
482 void SetCanToggleOrientation(bool enable) { b_canToggleOrientation = enable; }
483 bool GetCanToggleOrientation() { return b_canToggleOrientation; }
484
485 bool toolbarConfigChanged;
486
487 wxMenu *m_FloatingToolbarConfigMenu;
488
489 wxString m_tblastAISiconName;
490 wxToolBarToolBase *m_pTBAISTool;
491 bool m_toolbar_scale_tools_shown;
492 void SetBackGroundColorString(wxString colorRef);
493 void SetULDockPosition(wxPoint position);
494
495 ArrayOfToolbarItemContainer m_Items;
496
497 void AddToolItem(ToolbarItemContainer *item);
498 int RebuildToolbar();
499 void EnableRolloverBitmaps(bool bEnable);
500 bool GetEnableRolloverBitmaps() { return m_enableRolloverBitmaps; }
501
502protected:
503 ocpnToolBarSimple *m_ptoolbar;
504
505private:
506 void DoFade(int value);
507
508 bool m_bsubmerged;
509
510 wxWindow *m_pparent;
511 wxBoxSizer *m_topSizer;
512
513 long m_orient;
514 wxTimer m_fade_timer;
515 int m_opacity;
516 ColorScheme m_cs;
517
518 wxPoint m_position;
519 int m_dock_x;
520 int m_dock_y;
521 int m_dock_min_x;
522 int m_dock_min_y;
523
524 ocpnStyle::Style *m_style;
525 bool m_block;
526
527 bool m_marginsInvisible;
528 float m_sizefactor;
529 wxTimer m_destroyTimer;
530 wxSize m_recoversize;
531
532 bool m_bAutoHideToolbar;
533 int m_nAutoHideToolbar;
534 bool m_benableSubmerge;
535
536 wxString m_backcolorString;
537 int m_cornerRadius;
538 wxString m_toolShowMask;
539 int n_toolbarHideMethod;
540 bool b_canToggleOrientation;
541 wxString m_configString;
542 bool m_enableRolloverBitmaps;
543 int m_auxOffsetY;
544
545 unsigned int m_texture;
546 wxImage m_toolbar_image;
547};
548
549//---------------------------------------------------------------------------
550
551class ToolbarMOBDialog : public wxDialog {
552private:
553 std::vector<wxRadioButton *> choices;
554
555public:
556 ToolbarMOBDialog(wxWindow *parent);
557 int GetSelection();
558};
559
560#define SYMBOL_ToolbarChoices_STYLE \
561 wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCLOSE_BOX
562
563class ToolbarChoicesDialog : public wxDialog {
564 DECLARE_EVENT_TABLE()
565
566public:
569 ToolbarChoicesDialog(wxWindow *parent, ocpnFloatingToolbarDialog *sponsor,
570 wxWindowID id = -1, const wxString &caption = "",
571 const wxPoint &pos = wxDefaultPosition,
572 const wxSize &size = wxDefaultSize,
573 long style = SYMBOL_ToolbarChoices_STYLE);
574
576
577 void SetColorScheme(ColorScheme cs);
578 void RecalculateSize();
579 void CreateControls();
580
581 void OnCancelClick(wxCommandEvent &event);
582 void OnOkClick(wxCommandEvent &event);
583
584 wxButton *m_CancelButton;
585 wxButton *m_OKButton;
586
587 std::vector<wxCheckBox *> cboxes;
588 wxMenu *m_configMenu;
589 ocpnFloatingToolbarDialog *m_ToolbarDialogAncestor;
590};
591
592#endif
ToolbarChoicesDialog()
Constructors.
Definition toolbar.cpp:2129
Container for toolbar item properties.
Definition toolbar.h:45
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
Floating toolbar dialog for OpenCPN.
Definition toolbar.h:390
Generic toolbar implementation in pure wxWidgets adapted from wxToolBarSimple (deprecated).
Definition toolbar.h:108
Layer to use wxDC or opengl.
Chart Symbols.
ocpnFloatingToolbarDialog * g_MainToolbar
Global instance.
Definition toolbar.cpp:65