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