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