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