OpenCPN Partial API docs
Loading...
Searching...
No Matches
toolbar.cpp
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#include <wx/wxprec.h>
27
28#ifndef WX_PRECOMP
29#include <wx/wx.h>
30#endif
31
32#include <vector>
33
34#include "config.h"
35#include "ocpn_types.h"
36#include "navutil.h"
37#include "styles.h"
38#include "toolbar.h"
39#include "pluginmanager.h"
40#include "FontMgr.h"
41#include "OCPNPlatform.h"
42#include "chcanv.h"
43#include "gui_lib.h"
44#include "svg_utils.h"
45#include "idents.h"
46#include "ocpn_frame.h"
47
48#ifdef __OCPN__ANDROID__
49#include "androidUTIL.h"
50#endif
51
52extern bool g_bTransparentToolbar;
53extern bool g_bTransparentToolbarInOpenGLOK;
54extern bool g_bopengl;
55extern ocpnStyle::StyleManager *g_StyleManager;
56extern MyFrame *gFrame;
57extern PlugInManager *g_pi_manager;
58extern bool g_bPermanentMOBIcon;
59extern bool g_btouch;
60extern bool g_bsmoothpanzoom;
61extern OCPNPlatform *g_Platform;
62extern bool g_bmasterToolbarFull;
63extern bool g_useMUI;
64extern wxString g_toolbarConfig;
65extern double g_plus_minus_zoom_factor;
66extern int g_maintoolbar_x;
67extern int g_maintoolbar_y;
68
69//----------------------------------------------------------------------------
70// GrabberWindow Implementation
71//----------------------------------------------------------------------------
72BEGIN_EVENT_TABLE(GrabberWin, wxPanel)
73EVT_MOUSE_EVENTS(GrabberWin::MouseEvent)
74EVT_PAINT(GrabberWin::OnPaint)
75END_EVENT_TABLE()
76
77GrabberWin::GrabberWin(wxWindow *parent, ocpnFloatingToolbarDialog *toolbar,
78 float scale_factor, wxString icon_name, wxPoint position)
79 : wxPanel(parent, wxID_ANY, position, wxDefaultSize, wxNO_BORDER) {
80 m_icon_name = icon_name;
81 m_style = g_StyleManager->GetCurrentStyle();
82 wxBitmap bitmap = m_style->GetIcon(icon_name);
83 if (scale_factor > 1.0f) {
84 int new_width = bitmap.GetWidth() * scale_factor;
85 int new_height = bitmap.GetHeight() * scale_factor;
86 wxImage scaled_image = bitmap.ConvertToImage();
87 m_bitmap = wxBitmap(
88 scaled_image.Scale(new_width, new_height, wxIMAGE_QUALITY_HIGH));
89 } else
90 m_bitmap = bitmap;
91
92 SetSize(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
93 SetMinSize(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
94
95 m_bLeftDown = false;
96 m_bRightDown = false;
97 m_scale_factor = scale_factor;
98 m_ptoolbar = toolbar;
99 m_dragging = false;
100 Hide();
101}
102
103void GrabberWin::OnPaint(wxPaintEvent &event) {
104 wxPaintDC dc(this);
105
106 wxColour back_color = GetGlobalColor(_T("GREY2"));
107 SetBackgroundColour(back_color);
108 ClearBackground();
109
110 dc.DrawBitmap(m_bitmap, 0, 0, true);
111}
112
113void GrabberWin::SetColorScheme(ColorScheme cs) {
114 wxColour back_color = GetGlobalColor(_T("GREY2"));
115
116 SetBackgroundColour(back_color);
117 ClearBackground();
118
119 wxBitmap bitmap = m_style->GetIcon(m_icon_name);
120 if (m_scale_factor > 1.0f) {
121 int new_width = bitmap.GetWidth() * m_scale_factor;
122 int new_height = bitmap.GetHeight() * m_scale_factor;
123 wxImage scaled_image = bitmap.ConvertToImage();
124 m_bitmap = wxBitmap(
125 scaled_image.Scale(new_width, new_height, wxIMAGE_QUALITY_HIGH));
126 } else
127 m_bitmap = bitmap;
128}
129
130void GrabberWin::MouseEvent(wxMouseEvent &event) {}
131#if 0
132 static wxPoint s_gspt;
133 int x, y;
134
135 event.GetPosition( &x, &y );
136
137 wxPoint spt = ClientToScreen( wxPoint( x, y ) );
138 if( event.LeftDown() ) {
139 s_gspt = spt;
140 }
141
142#ifndef __WXQT__
143
144 if( event.LeftDown() ) {
145 CaptureMouse();
146 }
147
148 if( event.LeftUp() ) {
149 if( HasCapture() ) ReleaseMouse();
150 }
151
152#endif
153
154
155 if( event.RightDown() && m_ptoolbar->GetCanToggleOrientation()){
156 if(m_ptoolbar){
157 if(!m_ptoolbar->isSubmergedToGrabber()){
158 m_dragging = true;
159
160 if( !m_ptoolbar->m_bnavgrabber ){
161 m_ptoolbar->m_bnavgrabber = true;
162 m_ptoolbar->SetGrabber(_T("4WayMove") );
163 }
164 else{
165 m_ptoolbar->m_bnavgrabber = false;
166 m_ptoolbar->SetGrabber(_T("grabber_hi") );
167 }
168 }
169 }
170 }
171
172
173
174 if( event.Dragging() ) {
175 if(m_ptoolbar && m_ptoolbar->IsShown() /*&& m_ptoolbar->m_bnavgrabber*/){
176 wxPoint par_pos_old = m_ptoolbar->GetPosition();
177
178 wxPoint par_pos = par_pos_old;
179 par_pos.x += spt.x - s_gspt.x;
180 par_pos.y += spt.y - s_gspt.y;
181
182 m_ptoolbar->MoveDialogInScreenCoords( par_pos, par_pos_old );
183
184 s_gspt = spt;
185 m_dragging = true;
186 }
187
188 }
189
190 if( event.LeftUp() ) {
191 if(m_ptoolbar){
192 if(m_ptoolbar->m_bnavgrabber){
193 if(!m_dragging)
194 m_ptoolbar->ToggleOrientation();
195 }
196 else if(!m_dragging){
197 if(m_ptoolbar->isSubmergedToGrabber()){
198 m_ptoolbar->SurfaceFromGrabber();
199 }
200 else{
201 m_ptoolbar->SubmergeToGrabber();
202 }
203 }
204 }
205 m_dragging = false;
206 }
207
208#ifndef __OCPN__ANDROID__
209 gFrame->Raise();
210#endif
211
212}
213#endif
214
215class ocpnToolBarTool : public wxToolBarToolBase {
216public:
217 ocpnToolBarTool(ocpnToolBarSimple *tbar, int id, const wxString &label,
218 const wxBitmap &bmpNormal, const wxBitmap &bmpRollover,
219 wxItemKind kind, wxObject *clientData,
220 const wxString &shortHelp, const wxString &longHelp)
221 : wxToolBarToolBase((wxToolBarBase *)tbar, id, label, bmpNormal,
222 bmpRollover, kind, clientData, shortHelp, longHelp) {
223 m_enabled = true;
224 m_toggled = false;
225 rollover = false;
226 bitmapOK = false;
227 m_btooltip_hiviz = false;
228
229 toolname = g_pi_manager->GetToolOwnerCommonName(id);
230 if (toolname == _T("")) {
231 isPluginTool = false;
232 toolname = label;
233 iconName = label;
234
235 } else {
236 isPluginTool = true;
237 pluginNormalIcon = bmpNormal;
238 pluginRolloverIcon = bmpRollover;
239 }
240 }
241
242 ocpnToolBarTool(ocpnToolBarSimple *tbar, int id, const wxBitmap &bmpNormal,
243 const wxBitmap &bmpRollover, wxItemKind kind,
244 wxObject *clientData, const wxString &shortHelp,
245 const wxString &longHelp)
246 : wxToolBarToolBase((wxToolBarBase *)tbar, id, _T(""), bmpNormal,
247 bmpRollover, kind, clientData, shortHelp, longHelp) {
248 m_enabled = true;
249 m_toggled = false;
250 rollover = false;
251 m_btooltip_hiviz = false;
252 isPluginTool = false;
253
254 m_bmpNormal = bmpNormal;
255 bitmapOK = true;
256 }
257
258 void SetSize(const wxSize &size) {
259 m_width = size.x;
260 m_height = size.y;
261 }
262
263 wxCoord GetWidth() const { return m_width; }
264
265 wxCoord GetHeight() const { return m_height; }
266
267 wxString GetToolname() { return toolname; }
268
269 void SetIconName(wxString name) { iconName = name; }
270 wxString GetIconName() { return iconName; }
271
272 void SetTooltipHiviz(bool enable) { m_btooltip_hiviz = enable; }
273
274 wxCoord m_x;
275 wxCoord m_y;
276 wxCoord m_width;
277 wxCoord m_height;
278 wxRect trect;
279 wxString toolname;
280 wxString iconName;
281 wxBitmap pluginNormalIcon;
282 wxBitmap pluginRolloverIcon;
283 const wxBitmap *pluginToggledIcon;
284 bool firstInLine;
285 bool lastInLine;
286 bool rollover;
287 bool bitmapOK;
288 bool isPluginTool;
289 bool b_hilite;
290 bool m_btooltip_hiviz;
291 wxRect last_rect;
292 wxString pluginNormalIconSVG;
293 wxString pluginRolloverIconSVG;
294 wxString pluginToggledIconSVG;
295};
296
297//---------------------------------------------------------------------------------------
298// ocpnFloatingToolbarDialog Implementation
299//---------------------------------------------------------------------------------------
300BEGIN_EVENT_TABLE(ocpnFloatingToolbarDialog, wxFrame)
301EVT_MOUSE_EVENTS(ocpnFloatingToolbarDialog::MouseEvent)
302EVT_MENU(wxID_ANY, ocpnFloatingToolbarDialog::OnToolLeftClick)
303EVT_TIMER(FADE_TIMER, ocpnFloatingToolbarDialog::FadeTimerEvent)
304EVT_TIMER(DESTROY_TIMER, ocpnFloatingToolbarDialog::DestroyTimerEvent)
305EVT_KEY_DOWN(ocpnFloatingToolbarDialog::OnKeyDown)
306EVT_KEY_UP(ocpnFloatingToolbarDialog::OnKeyUp)
307EVT_WINDOW_CREATE(ocpnFloatingToolbarDialog::OnWindowCreate)
308END_EVENT_TABLE()
309
311 wxPoint position,
312 long orient,
313 float size_factor) {
314 m_pparent = parent;
315 long wstyle = wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_SHAPED |
316 wxFRAME_FLOAT_ON_PARENT | wxFRAME_TOOL_WINDOW;
317
318 m_ptoolbar = NULL;
319
320 wxFrame::Create(parent, -1, _T(""), wxPoint(-1, -1), wxSize(-1, -1), wstyle);
321
322 m_opacity = 255;
323
324 m_pGrabberwin =
325 NULL; // new GrabberWin( this, this, size_factor, _T("grabber_hi") );
326 m_bGrabberEnable = true; // default
327
328 m_pRecoverwin = NULL;
329 m_position = position;
330 m_orient = orient;
331 m_sizefactor = size_factor;
332 m_cornerRadius = 0;
333
334 m_bAutoHideToolbar = false;
335 m_nAutoHideToolbar = 5;
336 m_toolbar_scale_tools_shown = false;
337 m_backcolorString = _T("GREY2");
338 m_toolShowMask = _T("XXXXXXXXXXXXXXXX");
339 n_toolbarHideMethod = TOOLBAR_HIDE_TO_GRABBER;
340 b_canToggleOrientation = true;
341 m_enableRolloverBitmaps = true;
342 m_auxOffsetY = 0;
343
344 m_ptoolbar = CreateNewToolbar();
345
346 m_cs = (ColorScheme)-1;
347
348 m_style = g_StyleManager->GetCurrentStyle();
349 SetULDockPosition(wxPoint(4, 4));
350
351 SetGeometry(false, wxRect());
352
353 // A top-level sizer
354 m_topSizer = new wxBoxSizer(wxHORIZONTAL);
355 SetSizer(m_topSizer);
356
357 // Set initial "Dock" parameters
358 m_dock_x = 0;
359 m_dock_y = 0;
360 m_block = false;
361
362 m_marginsInvisible = m_style->marginsInvisible;
363
364 // if(m_sizefactor > 1.0 )
365 // m_marginsInvisible = true;
366
367 m_bnavgrabber = false;
368
369 m_FloatingToolbarConfigMenu = NULL;
370
371 Hide();
372
373 m_bsubmerged = false;
374 m_bsubmergedToGrabber = false;
375
376 m_fade_timer.SetOwner(this, FADE_TIMER);
377 if (g_bTransparentToolbar) m_fade_timer.Start(5000);
378
379 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
380 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
381
382 m_destroyTimer.SetOwner(this, DESTROY_TIMER);
383
384 m_benableSubmerge = true;
385}
386
387ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
388 delete m_FloatingToolbarConfigMenu;
389
390 DestroyToolBar();
391}
392
393void ocpnFloatingToolbarDialog::AddToolItem(ToolbarItemContainer *item) {
394 m_Items.push_back(item);
395}
396
397int ocpnFloatingToolbarDialog::RebuildToolbar() {
398 ocpnToolBarSimple *tb = GetToolbar();
399 if (!tb) return 0;
400
401 // Iterate over the array of items added,
402 // Creating the toolbar from enabled items.
403 int i_count = 0;
404 for (auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
405 ToolbarItemContainer *tic = *it;
406 if (!tic) continue;
407
408 bool bEnabled = _toolbarConfigMenuUtil(tic);
409
410 if (bEnabled) {
411 wxToolBarToolBase *tool =
412 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
413 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
414 tic->m_tool = tool;
415
416 // Plugin tools may have prescribed their own SVG toolbars as file
417 // locations.
418 if (!tic->m_NormalIconSVG.IsEmpty()) {
419 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
420 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
421 }
422 }
423
424 i_count++;
425 }
426
427 return i_count;
428}
429
430void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
431 if (position.x >= 0) m_dock_min_x = position.x;
432 if (position.y >= 0) m_dock_min_y = position.y;
433}
434
435size_t ocpnFloatingToolbarDialog::GetToolCount() {
436 if (m_ptoolbar)
437 return m_ptoolbar->GetToolsCount();
438 else
439 return 0;
440}
441
442void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
443
444void ocpnFloatingToolbarDialog::SetToolShowCount(int count) {
445 if (m_ptoolbar) m_ptoolbar->SetToolShowCount(count);
446}
447
448int ocpnFloatingToolbarDialog::GetToolShowCount(void) {
449 if (m_ptoolbar)
450 return m_ptoolbar->GetToolShowCount();
451 else
452 return 0;
453}
454
455void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
456 m_backcolorString = colorRef;
457 SetColorScheme(m_cs); // Causes a reload of background color
458}
459
460void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) { event.Skip(); }
461
462void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) { event.Skip(); }
463
464void ocpnFloatingToolbarDialog::CreateConfigMenu() {
465 if (m_FloatingToolbarConfigMenu) delete m_FloatingToolbarConfigMenu;
466 m_FloatingToolbarConfigMenu = new wxMenu();
467}
468
469bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
471 if (m_FloatingToolbarConfigMenu) {
472 wxMenuItem *menuitem;
473
474 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon) return true;
475
476 if (tic->m_bRequired) return true;
477 if (tic->m_bPlugin) return true;
478
479 // Item ID trickery is needed because the wxCommandEvents for menu item
480 // clicked and toolbar button clicked are 100% identical, so if we use same
481 // id's we can't tell the events apart.
482
483 int idOffset = 100; // Hopefully no more than 100 total icons...
484 int menuItemId = tic->m_ID + idOffset;
485
486 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
487
488 if (menuitem) {
489 return menuitem->IsChecked();
490 }
491
492 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
493 tic->m_tipString);
494 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
495 menuitem->Check(m_configString.Len() >= n
496 ? m_configString.GetChar(n - 1) == _T('X')
497 : true);
498 return menuitem->IsChecked();
499 } else
500 return true;
501}
502
503void ocpnFloatingToolbarDialog::OnWindowCreate(wxWindowCreateEvent &event) {
504 // At least on MSW, this call leads to recursion and stack overflow.
505 // Probably not needed any longer
506 // Realize();
507}
508
509void ocpnFloatingToolbarDialog::SetGrabber(wxString icon_name) {
510 // m_pGrabberwin->Destroy();
511 m_pGrabberwin = new GrabberWin(this, this, m_sizefactor, icon_name);
512 m_pGrabberwin->Hide();
513
514 Realize();
515
516#ifdef __WXOSX__
517 m_pGrabberwin->Refresh();
518#endif
519}
520
521void ocpnFloatingToolbarDialog::UpdateRecoveryWindow(bool b_toolbarEnable) {
522 if (m_pRecoverwin) {
523 if (b_toolbarEnable) {
524 m_pRecoverwin->Raise();
525 m_pRecoverwin->Refresh(false);
526 } else
527 m_pRecoverwin->Hide();
528 }
529}
530
531void ocpnFloatingToolbarDialog::EnableTool(int toolid, bool enable) {
532 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
533}
534
535void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
536 m_cs = cs;
537
538 wxColour back_color = GetGlobalColor(m_backcolorString);
539
540 // Set background
541 SetBackgroundColour(back_color);
542 ClearBackground();
543
544 if (m_ptoolbar) {
545 // Set background
546 m_ptoolbar->SetBackgroundColour(back_color);
547 m_ptoolbar->ClearBackground();
548
549 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T("GREY1")));
550
551 m_ptoolbar->SetColorScheme(cs);
552 m_ptoolbar->Refresh(true);
553 }
554
555 if (m_pGrabberwin) {
556 m_pGrabberwin->SetColorScheme(cs);
557 m_pGrabberwin->Refresh();
558 }
559
560 Refresh(true);
561}
562
563wxSize ocpnFloatingToolbarDialog::GetToolSize() {
564 wxSize style_tool_size;
565 if (m_ptoolbar) {
566 style_tool_size = m_style->GetToolSize();
567
568 style_tool_size.x *= m_sizefactor;
569 style_tool_size.y *= m_sizefactor;
570 } else {
571 style_tool_size.x = 32;
572 style_tool_size.y = 32;
573 }
574
575 return style_tool_size;
576}
577
578void ocpnFloatingToolbarDialog::SetGeometry(bool bAvoid, wxRect rectAvoid) {
579 if (m_ptoolbar) {
580 wxSize style_tool_size = m_style->GetToolSize();
581
582 style_tool_size.x *= m_sizefactor;
583 style_tool_size.y *= m_sizefactor;
584
585 m_ptoolbar->SetToolBitmapSize(style_tool_size);
586
587 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
588 int grabber_width = m_style->GetIcon(_T("grabber")).GetWidth();
589
590 int max_rows = 10;
591 int max_cols = 100;
592
593 if (GetParent()) {
594 int avoid_start =
595 GetParent()->GetClientSize().x -
596 (tool_size.x + m_style->GetToolSeparation()) * 2; // default
597 if (bAvoid && !rectAvoid.IsEmpty()) {
598 avoid_start = GetParent()->GetClientSize().x - rectAvoid.width -
599 10; // this is compass window, if shown
600 }
601
602 max_rows = (GetParent()->GetClientSize().y /
603 (tool_size.y + m_style->GetToolSeparation())) -
604 2;
605
606 max_cols = (avoid_start - grabber_width) /
607 (tool_size.x + m_style->GetToolSeparation());
608 max_cols -= 1;
609
610 if (m_orient == wxTB_VERTICAL)
611 max_rows = wxMax(max_rows, 2); // at least two rows
612 else
613 max_cols = wxMax(max_cols, 2); // at least two columns
614 }
615
616 if (m_orient == wxTB_VERTICAL)
617 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
618 else
619 m_ptoolbar->SetMaxRowsCols(100, max_cols);
620 m_ptoolbar->SetSizeFactor(m_sizefactor);
621 }
622}
623
624void ocpnFloatingToolbarDialog::GetFrameRelativePosition(int *x, int *y) {
625 wxPoint myPos = GetPosition();
626
627 wxPoint relPos = gFrame->GetPrimaryCanvas()->ScreenToClient(myPos);
628 if (x) *x = relPos.x;
629 if (y) *y = relPos.y;
630}
631
632void ocpnFloatingToolbarDialog::RestoreRelativePosition(int x, int y) {
633 if ((x < 0) || (y < 0)) {
634 SetDefaultPosition();
635 return;
636 }
637
638 wxPoint screenPos = gFrame->GetPrimaryCanvas()->ClientToScreen(wxPoint(x, y));
639 Move(wxPoint(screenPos));
640}
641
642void ocpnFloatingToolbarDialog::SetDefaultPosition() {
643 if (m_block) return;
644
645 if (m_pparent && m_ptoolbar) {
646 wxSize cs = m_pparent->GetClientSize();
647 if (-1 == m_dock_x)
648 m_position.x = m_dock_min_x;
649 else if (1 == m_dock_x)
650 m_position.x = cs.x - GetSize().x;
651
652 if (-1 == m_dock_y)
653 m_position.y = m_dock_min_y;
654 else if (1 == m_dock_y)
655 m_position.y = cs.y - GetSize().y;
656
657 m_position.x = wxMin(cs.x - GetSize().x, m_position.x);
658 m_position.y = wxMin(cs.y - GetSize().y, m_position.y);
659
660 m_position.x = wxMax(m_dock_min_x, m_position.x);
661 m_position.y = wxMax(m_dock_min_y, m_position.y);
662
663 m_position.y += m_auxOffsetY;
664
665 g_maintoolbar_x = m_position.x;
666 g_maintoolbar_y = m_position.y;
667
668 // take care of left docked instrument windows and don't blast the main
669 // toolbar on top of them, hinding instruments this positions the main
670 // toolbar directly right of the left docked instruments onto the chart
671 // wxPoint screen_pos = m_pparent->ClientToScreen( m_position );
672 wxPoint screen_pos = gFrame->GetPrimaryCanvas()->ClientToScreen(m_position);
673
674 // GTK sometimes has trouble with ClientToScreen() if executed in the
675 // context of an event handler The position of the window is calculated
676 // incorrectly if a deferred Move() has not been processed yet. So work
677 // around this here... Discovered with a Dashboard window left-docked,
678 // toggled on and off by toolbar tool.
679
680 // But this causes another problem. If a toolbar is NOT left docked, it
681 // will walk left by two pixels on each call to Reposition().
682 // TODO
683#ifdef __WXGTK__
684 if (m_pparent->GetParent()) {
685 wxPoint pp = m_pparent->GetPosition();
686 wxPoint ppg = m_pparent->GetParent()->GetScreenPosition();
687 wxPoint screen_pos_fix = ppg + pp + m_position;
688 screen_pos.x = screen_pos_fix.x;
689 }
690#endif
691
692 Move(screen_pos);
693
694#ifdef __WXQT__
695 Raise();
696#endif
697 }
698}
699
700void ocpnFloatingToolbarDialog::Submerge() {
701 m_bsubmerged = true;
702 Hide();
703 if (m_ptoolbar) m_ptoolbar->KillTooltip();
704}
705
706void ocpnFloatingToolbarDialog::SubmergeToGrabber() {
707 if (!m_benableSubmerge) return;
708
709 // Submerge();
710 m_bsubmerged = true;
711 m_bsubmergedToGrabber = true;
712 Hide();
713 if (m_ptoolbar) m_ptoolbar->KillTooltip();
714
715 if (!m_pRecoverwin) {
716 wxPoint tbPoint = GetPosition();
717 wxPoint tbPosInCanvas = m_pparent->ScreenToClient(tbPoint);
718 // tbPosInCanvas.y += 2; // prettify
719 m_pRecoverwin = new GrabberWin(m_pparent, this, m_sizefactor,
720 _T("grabber_ext" ), tbPosInCanvas);
721 }
722
723 m_pRecoverwin->Show();
724 m_pRecoverwin->Raise();
725#ifdef __WXQT__
726 wxSize s = gFrame->GetSize();
727 m_recoversize = s;
728 s.y--;
729 // gFrame->TriggerResize(s);
730 Raise();
731#endif
732
733 gFrame->Refresh(); // Needed for MSW OpenGL
734}
735
736void ocpnFloatingToolbarDialog::Surface() {
737 if (m_pRecoverwin) {
738 // SurfaceFromGrabber();
739 m_pRecoverwin->Show();
740 m_pRecoverwin->Raise();
741 } else {
742 m_bsubmerged = false;
743#ifdef __WXMSW__
744 Hide();
745 Move(0, 0);
746#endif
747
748 RestoreRelativePosition(g_maintoolbar_x, g_maintoolbar_y);
749 Show();
750 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
751
752#ifdef __WXQT__
753 Raise();
754#endif
755 }
756
757 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
758 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
759 }
760}
761
762bool ocpnFloatingToolbarDialog::CheckSurfaceRequest(wxMouseEvent &event) {
763 return false;
764}
765
766void ocpnFloatingToolbarDialog::SurfaceFromGrabber() {}
767
768void ocpnFloatingToolbarDialog::DestroyTimerEvent(wxTimerEvent &event) {
769 delete m_destroyGrabber;
770 m_destroyGrabber = NULL;
771}
772
773bool ocpnFloatingToolbarDialog::isSubmergedToGrabber() {
774 return (m_bsubmergedToGrabber);
775}
776
777void ocpnFloatingToolbarDialog::HideTooltip() {
778#ifndef __OCPN__ANDROID__
779 if (m_ptoolbar) m_ptoolbar->HideTooltip();
780#endif
781}
782
783void ocpnFloatingToolbarDialog::ShowTooltips() {
784#ifndef __OCPN__ANDROID__
785 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
786#endif
787}
788
789void ocpnFloatingToolbarDialog::ToggleOrientation() {}
790
791void ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
792 if (g_bTransparentToolbar) {
793 if (event.Entering() && (m_opacity < 255)) {
794 SetTransparent(255);
795 m_opacity = 255;
796 }
797
798 m_fade_timer.Start(5000); // retrigger the continuous timer
799 }
800
801 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
802 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
803 }
804
805 event.Skip();
806}
807
808void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
809 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
810 if (g_bmasterToolbarFull) {
811 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) && !m_bsubmerged) {
812 wxCommandEvent event;
813 event.SetId(ID_MASTERTOGGLE);
814 gFrame->OnToolLeftClick(event);
815 }
816 }
817 } else {
818 if (m_bnavgrabber) {
819 m_fade_timer.Start(5000); // do nothing if nav grabber is shown
820 } else {
821 if (g_bTransparentToolbar &&
822 (!g_bopengl || g_bTransparentToolbarInOpenGLOK)) {
823 DoFade(128);
824 m_fade_timer.Start(5000); // retrigger the continuous timer
825 }
826
827 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) && !m_bsubmerged) {
828 SubmergeToGrabber();
829 }
830 }
831 }
832}
833
834void ocpnFloatingToolbarDialog::SetAutoHideTimer(int time) {
835 m_nAutoHideToolbar = time;
836 if (m_bAutoHideToolbar) {
837 m_fade_timer.Stop();
838 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
839 }
840}
841
842void ocpnFloatingToolbarDialog::DoFade(int value) {
843 if (value != m_opacity) SetTransparent(value);
844 m_opacity = value;
845}
846
847void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
848 SetTransparent(255);
849 m_opacity = 255;
850 m_fade_timer.Start(500); // retrigger the continuous timer
851
852 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
853 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
854 }
855}
856
857void ocpnFloatingToolbarDialog::SetToolShortHelp(int id, const wxString &help) {
858 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(id, help);
859}
860
861void ocpnFloatingToolbarDialog::MoveDialogInScreenCoords(wxPoint posn,
862 wxPoint posn_old) {
863 wxPoint pos_in_parent = m_pparent->ScreenToClient(posn);
864 wxPoint pos_in_parent_old = m_pparent->ScreenToClient(posn_old);
865
866 // "Docking" support
867#define DOCK_MARGIN 40
868
869 // X
870 m_dock_x = 0;
871 if (pos_in_parent.x < pos_in_parent_old.x) // moving left
872 {
873 if (pos_in_parent.x < DOCK_MARGIN) {
874 pos_in_parent.x = m_dock_min_x; // but dock position may be offset
875 m_dock_x = -1;
876 }
877 } else if (pos_in_parent.x > pos_in_parent_old.x) // moving right
878 {
879 int max_right = m_pparent->GetClientSize().x - GetSize().x;
880 if (pos_in_parent.x > (max_right - DOCK_MARGIN)) {
881 pos_in_parent.x = max_right;
882 m_dock_x = 1;
883 }
884 }
885
886 // Y
887 m_dock_y = 0;
888 if (pos_in_parent.y < pos_in_parent_old.y) // moving up
889 {
890 if (pos_in_parent.y < DOCK_MARGIN) {
891 pos_in_parent.y = 0;
892 m_dock_y = -1;
893 }
894 } else if (pos_in_parent.y > pos_in_parent_old.y) // moving down
895 {
896 int max_down = m_pparent->GetClientSize().y - GetSize().y;
897 if (pos_in_parent.y > (max_down - DOCK_MARGIN)) {
898 pos_in_parent.y = max_down;
899 m_dock_y = 1;
900 }
901 }
902
903 m_position = pos_in_parent;
904
905 wxPoint final_pos = m_pparent->ClientToScreen(pos_in_parent);
906
907 Move(final_pos);
908}
909
910void ocpnFloatingToolbarDialog::Realize() {
911 if (m_ptoolbar) {
912 m_ptoolbar->Realize();
913
914 m_topSizer->Clear();
915 m_topSizer->Add(m_ptoolbar);
916
917 if (m_bGrabberEnable) {
918 if (!m_pGrabberwin) {
919 m_pGrabberwin =
920 new GrabberWin(this, this, m_sizefactor, _T("grabber_hi"));
921 m_pGrabberwin->Hide();
922 }
923
924 m_pGrabberwin->Show();
925 m_topSizer->Add(m_pGrabberwin, 0, wxTOP, m_style->GetTopMargin());
926 }
927
928 m_topSizer->Layout();
929 Fit();
930
931 // Update "Dock" parameters
932 if (m_position.x == 0)
933 m_dock_x = -1;
934 else if (m_position.x == m_pparent->GetClientSize().x - GetSize().x)
935 m_dock_x = 1;
936
937 if (m_position.y == 0)
938 m_dock_y = -1;
939 else if (m_position.y == m_pparent->GetClientSize().y - GetSize().y)
940 m_dock_y = 1;
941
942 // Now create a bitmap mask forthe frame shape.
943
944 if (m_marginsInvisible) {
945 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
946
947 // Determine whether the tool icons are meant (by style) to join without
948 // speces between This will determine what type of region to draw.
949 bool b_overlap = false;
950
951 wxToolBarToolsList::compatibility_iterator node1 =
952 m_ptoolbar->m_tools.GetFirst();
953 if (node1) {
954 wxToolBarToolsList::compatibility_iterator node2 = node1->GetNext();
955 if (node2) {
956 wxToolBarToolBase *tool1 = node1->GetData();
957 ocpnToolBarTool *tools1 = (ocpnToolBarTool *)tool1;
958
959 wxToolBarToolBase *tool2 = node2->GetData();
960 ocpnToolBarTool *tools2 = (ocpnToolBarTool *)tool2;
961
962 if ((tools1->m_x + tools1->m_width) >= tools2->m_x) b_overlap = true;
963 }
964 }
965
966 int toolCount = m_ptoolbar->GetVisibleToolCount();
967
968 wxPoint upperLeft(m_style->GetLeftMargin(), m_style->GetTopMargin());
969 wxSize visibleSize;
970 if (m_ptoolbar->IsVertical()) {
971 int noTools = m_ptoolbar->GetMaxRows();
972 if (noTools > toolCount) noTools = toolCount;
973 visibleSize.x = m_ptoolbar->GetLineCount() *
974 (tool_size.x + m_style->GetTopMargin());
975 visibleSize.y = noTools * (tool_size.y + m_style->GetToolSeparation());
976 visibleSize.x -= m_style->GetTopMargin();
977 visibleSize.y -= m_style->GetToolSeparation();
978 } else {
979 int noTools = m_ptoolbar->GetMaxCols();
980 if (noTools > toolCount) noTools = toolCount;
981 visibleSize.x = noTools * (tool_size.x + m_style->GetToolSeparation());
982 visibleSize.y = m_ptoolbar->GetLineCount() *
983 (tool_size.y + m_style->GetTopMargin());
984 visibleSize.x -= m_style->GetToolSeparation();
985 visibleSize.y -= m_style->GetTopMargin();
986 }
987
988 wxBitmap shape(visibleSize.x + tool_size.x,
989 visibleSize.y + tool_size.y); // + fluff
990 wxMemoryDC sdc(shape);
991 sdc.SetBackground(*wxWHITE_BRUSH);
992 sdc.SetBrush(*wxBLACK_BRUSH);
993 sdc.SetPen(*wxBLACK_PEN);
994 sdc.Clear();
995
996 if (b_overlap) {
997 int lines = m_ptoolbar->GetLineCount();
998 for (int i = 1; i <= lines; i++) {
999 if (m_ptoolbar->IsVertical()) {
1000 wxSize barsize(tool_size.x, visibleSize.y);
1001 if (i == lines && i > 1) {
1002 int toolsInLastLine = toolCount % m_ptoolbar->GetMaxRows();
1003 if (toolsInLastLine == 0)
1004 toolsInLastLine = m_ptoolbar->GetMaxRows();
1005 int emptySpace = (m_ptoolbar->GetMaxRows() - toolsInLastLine);
1006 barsize.y -=
1007 emptySpace * (tool_size.y + m_style->GetToolSeparation());
1008 }
1009 if (i == lines) {
1010 // Also do grabber here, since it is to the right of the last
1011 // line.
1012 wxRect grabMask(upperLeft, barsize);
1013 grabMask.width += m_style->GetIcon(_T("grabber")).GetWidth();
1014 grabMask.height = m_style->GetIcon(_T("grabber")).GetHeight();
1015 sdc.DrawRoundedRectangle(grabMask,
1016 m_style->GetToolbarCornerRadius());
1017 }
1018 sdc.DrawRoundedRectangle(upperLeft, barsize,
1019 m_style->GetToolbarCornerRadius());
1020 upperLeft.x += m_style->GetTopMargin() + tool_size.x;
1021 } else {
1022 wxSize barsize(visibleSize.x, tool_size.y);
1023
1024 if (i == 1) {
1025 barsize.x += m_style->GetIcon(_T("grabber")).GetWidth();
1026 }
1027 if (i == lines && i > 1) {
1028 int toolsInLastLine = toolCount % m_ptoolbar->GetMaxCols();
1029 if (toolsInLastLine == 0)
1030 toolsInLastLine = m_ptoolbar->GetMaxCols();
1031 int emptySpace = (m_ptoolbar->GetMaxCols() - toolsInLastLine);
1032 barsize.x -=
1033 emptySpace * (tool_size.x + m_style->GetToolSeparation());
1034 }
1035
1036 sdc.DrawRoundedRectangle(upperLeft, barsize,
1037 m_style->GetToolbarCornerRadius());
1038 upperLeft.y += m_style->GetTopMargin() + tool_size.y;
1039 }
1040 }
1041 } // b_overlap
1042 else {
1043 for (wxToolBarToolsList::compatibility_iterator node =
1044 m_ptoolbar->m_tools.GetFirst();
1045 node; node = node->GetNext()) {
1046 wxToolBarToolBase *tool = node->GetData();
1047 ocpnToolBarTool *tools = (ocpnToolBarTool *)tool;
1048
1049 sdc.DrawRoundedRectangle(tools->m_x, tools->m_y, tool_size.x,
1050 tool_size.y,
1051 m_style->GetToolbarCornerRadius());
1052 }
1053 }
1054
1055#ifndef __WXQT__
1056 if (shape.GetWidth() && shape.GetHeight())
1057 SetShape(wxRegion(shape, *wxWHITE, 10));
1058#endif
1059 } else {
1060#if !defined(__WXMAC__) && !defined(__OCPN__ANDROID__)
1061 if (m_cornerRadius) {
1062 wxBitmap m_MaskBmp = wxBitmap(GetSize().x, GetSize().y);
1063 wxMemoryDC sdc(m_MaskBmp);
1064 sdc.SetBackground(*wxWHITE_BRUSH);
1065 sdc.Clear();
1066 sdc.SetBrush(*wxBLACK_BRUSH);
1067 sdc.SetPen(*wxBLACK_PEN);
1068 sdc.DrawRoundedRectangle(0, 0, m_MaskBmp.GetWidth(),
1069 m_MaskBmp.GetHeight(), m_cornerRadius);
1070 sdc.SelectObject(wxNullBitmap);
1071 SetShape(wxRegion(m_MaskBmp, *wxWHITE, 0));
1072 }
1073#endif
1074 }
1075 }
1076}
1077
1078void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
1079 // Since Dialog events don't propagate automatically, we send it explicitly
1080 // (instead of relying on event.Skip()). Send events up the window hierarchy
1081
1082 m_pparent->GetEventHandler()->AddPendingEvent(event);
1083#ifndef __WXQT__
1084 gFrame->Raise();
1085#endif
1086}
1087
1088ocpnToolBarSimple *ocpnFloatingToolbarDialog::GetToolbar() {
1089 if (!m_ptoolbar) {
1090 m_ptoolbar = CreateNewToolbar();
1091 }
1092
1093 return m_ptoolbar;
1094}
1095
1096ocpnToolBarSimple *ocpnFloatingToolbarDialog::CreateNewToolbar() {
1097 long winstyle = wxNO_BORDER | wxTB_FLAT;
1098 winstyle |= m_orient;
1099
1100 m_ptoolbar = new ocpnToolBarSimple(this, -1, wxPoint(-1, -1), wxSize(-1, -1),
1101 winstyle);
1102
1103 m_ptoolbar->SetBackgroundColour(GetGlobalColor(_T("GREY2")));
1104 m_ptoolbar->ClearBackground();
1105 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T("GREY1")));
1106 m_ptoolbar->SetColorScheme(m_cs);
1107 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
1108
1109 return m_ptoolbar;
1110}
1111
1112void ocpnFloatingToolbarDialog::DestroyToolBar() {
1113 g_toolbarConfig = GetToolConfigString();
1114
1115 if (m_ptoolbar) {
1116 m_ptoolbar->ClearTools();
1117 delete m_ptoolbar; //->Destroy();
1118 m_ptoolbar = NULL;
1119 }
1120
1121 if (!m_destroyTimer.IsRunning()) {
1122 m_destroyGrabber = m_pRecoverwin;
1123 m_pRecoverwin = NULL;
1124 m_destroyTimer.Start(
1125 5, wxTIMER_ONE_SHOT); // Destor the unneeded recovery grabber
1126 }
1127
1128 m_Items.clear();
1129}
1130
1131#include "s52plib.h"
1132#include "compass.h"
1133#include "chartdb.h"
1134
1135extern bool g_bAllowShowScaled;
1136extern bool g_bTrackActive;
1137extern s52plib *ps52plib;
1138
1139ocpnToolBarSimple *ocpnFloatingToolbarDialog::CreateMyToolbar() {
1140 return NULL;
1141#if 0
1142
1143 ocpnToolBarSimple *tb = GetToolbar();
1144 if( !tb )
1145 return 0;
1146
1147 ocpnCompass *pCompass = NULL;
1148 ChartCanvas *parentCanvas = dynamic_cast<ChartCanvas *>( GetParent() );
1149 if(parentCanvas)
1150 pCompass = parentCanvas->GetCompass();
1151
1152 if(pCompass)
1153 SetGeometry(pCompass->IsShown(), pCompass->GetRect());
1154 else
1155 SetGeometry(false, wxRect(0,0,1,1));
1156
1157 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
1158
1159 wxString tipString;
1160 wxToolBarToolBase* newtool;
1161
1162 CheckAndAddPlugInTool( tb );
1163 tipString = wxString( _("Zoom In") ) << _T(" (+)");
1164 if( _toolbarConfigMenuUtil( ID_ZOOMIN, tipString ) )
1165 tb->AddTool( ID_ZOOMIN, _T("zoomin"),
1166 style->GetToolIcon( _T("zoomin"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1167
1168 CheckAndAddPlugInTool( tb );
1169 tipString = wxString( _("Zoom Out") ) << _T(" (-)");
1170 if( _toolbarConfigMenuUtil( ID_ZOOMOUT, tipString ) )
1171 tb->AddTool( ID_ZOOMOUT, _T("zoomout"),
1172 style->GetToolIcon( _T("zoomout"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1173
1174 CheckAndAddPlugInTool( tb );
1175 tipString = wxString( _("Shift to Larger Scale Chart") ) << _T(" (F7)");
1176 if( _toolbarConfigMenuUtil( ID_STKDN, tipString ) ) {
1177 newtool = tb->AddTool( ID_STKDN, _T("scin"),
1178 style->GetToolIcon( _T("scin"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1179 newtool->Enable( m_toolbar_scale_tools_shown );
1180 }
1181
1182 CheckAndAddPlugInTool( tb );
1183 tipString = wxString( _("Shift to Smaller Scale Chart") ) << _T(" (F8)");
1184 if( _toolbarConfigMenuUtil( ID_STKUP, tipString ) ) {
1185 newtool = tb->AddTool( ID_STKUP, _T("scout"),
1186 style->GetToolIcon( _T("scout"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1187 newtool->Enable( m_toolbar_scale_tools_shown );
1188 }
1189
1190 CheckAndAddPlugInTool( tb );
1191 tipString = wxString( _("Create Route") ) << _T(" (Ctrl-R)");
1192 if( _toolbarConfigMenuUtil( ID_ROUTE, tipString ) )
1193 tb->AddTool( ID_ROUTE, _T("route"),
1194 style->GetToolIcon( _T("route"), TOOLICON_NORMAL ),
1195 style->GetToolIcon( _T("route"), TOOLICON_TOGGLED ), wxITEM_CHECK, tipString );
1196
1197 CheckAndAddPlugInTool( tb );
1198 tipString = wxString( _("Auto Follow") ) << _T(" (F2)");
1199 if( _toolbarConfigMenuUtil( ID_FOLLOW, tipString ) )
1200 tb->AddTool( ID_FOLLOW, _T("follow"),
1201 style->GetToolIcon( _T("follow"), TOOLICON_NORMAL ),
1202 style->GetToolIcon( _T("follow"), TOOLICON_TOGGLED ), wxITEM_CHECK, tipString );
1203
1204 CheckAndAddPlugInTool( tb );
1205 tipString = _("Options");
1206 if( _toolbarConfigMenuUtil( ID_SETTINGS, tipString ) )
1207 tb->AddTool( ID_SETTINGS, _T("settings"),
1208 style->GetToolIcon( _T("settings"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1209
1210 CheckAndAddPlugInTool( tb );
1211 bool gs = false;
1212 if (ps52plib)
1213 gs = ps52plib->GetShowS57Text();
1214
1215 if (gs)
1216 tipString = wxString( _("Hide ENC text") ) << _T(" (T)");
1217 else
1218 tipString = wxString( _("Show ENC text") ) << _T(" (T)");
1219
1220 if( _toolbarConfigMenuUtil( ID_ENC_TEXT, tipString ) )
1221 tb->AddTool( ID_ENC_TEXT, _T("text"),
1222 style->GetToolIcon( _T("text"), TOOLICON_NORMAL ),
1223 style->GetToolIcon( _T("text"), TOOLICON_TOGGLED ), wxITEM_CHECK, tipString );
1224
1225 m_pTBAISTool = NULL;
1226 CheckAndAddPlugInTool( tb );
1227 tipString = _("Hide AIS Targets"); // inital state is on
1228 if( _toolbarConfigMenuUtil( ID_AIS, tipString ) )
1229 m_pTBAISTool = tb->AddTool( ID_AIS, _T("AIS"), style->GetToolIcon( _T("AIS"), TOOLICON_NORMAL ),
1230 style->GetToolIcon( _T("AIS"), TOOLICON_DISABLED ),
1231 wxITEM_NORMAL, tipString );
1232
1233 CheckAndAddPlugInTool( tb );
1234 tipString = _("Show Currents");
1235 if( _toolbarConfigMenuUtil( ID_CURRENT, tipString ) )
1236 tb->AddTool( ID_CURRENT, _T("current"),
1237 style->GetToolIcon( _T("current"), TOOLICON_NORMAL ), tipString, wxITEM_CHECK );
1238
1239 CheckAndAddPlugInTool( tb );
1240 tipString = _("Show Tides");
1241 if( _toolbarConfigMenuUtil( ID_TIDE, tipString ) )
1242 tb->AddTool( ID_TIDE, _T("tide"),
1243 style->GetToolIcon( _T("tide"), TOOLICON_NORMAL ), tipString, wxITEM_CHECK );
1244
1245 CheckAndAddPlugInTool( tb );
1246 tipString = _("Print Chart");
1247 if( _toolbarConfigMenuUtil( ID_PRINT, tipString ) )
1248 tb->AddTool( ID_PRINT, _T("print"),
1249 style->GetToolIcon( _T("print"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1250
1251 CheckAndAddPlugInTool( tb );
1252 tipString = _("Route & Mark Manager");
1253 if( _toolbarConfigMenuUtil( ID_ROUTEMANAGER, tipString ) )
1254 tb->AddTool( ID_ROUTEMANAGER,
1255 _T("route_manager"), style->GetToolIcon( _T("route_manager"), TOOLICON_NORMAL ),
1256 tipString, wxITEM_NORMAL );
1257
1258 CheckAndAddPlugInTool( tb );
1259 tipString = _("Enable Tracking");
1260 if( _toolbarConfigMenuUtil( ID_TRACK, tipString ) )
1261 tb->AddTool( ID_TRACK, _T("track"),
1262 style->GetToolIcon( _T("track"), TOOLICON_NORMAL ),
1263 style->GetToolIcon( _T("track"), TOOLICON_TOGGLED ), wxITEM_CHECK, tipString );
1264
1265 CheckAndAddPlugInTool( tb );
1266 tipString = wxString( _("Change Color Scheme") ) << _T(" (F5)");
1267 if( _toolbarConfigMenuUtil( ID_COLSCHEME, tipString ) ){
1268 tb->AddTool( ID_COLSCHEME,
1269 _T("colorscheme"), style->GetToolIcon( _T("colorscheme"), TOOLICON_NORMAL ),
1270 tipString, wxITEM_NORMAL );
1271 tb->SetToolTooltipHiViz( ID_COLSCHEME, true ); // cause the Tooltip to always be visible, whatever
1272 // the colorscheme
1273 }
1274
1275 CheckAndAddPlugInTool( tb );
1276 tipString = _("About OpenCPN");
1277 if( _toolbarConfigMenuUtil( ID_ABOUT, tipString ) )
1278 tb->AddTool( ID_ABOUT, _T("help"),
1279 style->GetToolIcon( _T("help"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1280
1281 // Add any PlugIn toolbar tools that request default positioning
1282 AddDefaultPositionPlugInTools( tb );
1283
1284 // And finally add the MOB tool
1285 tipString = wxString( _("Drop MOB Marker") ) << _(" (Ctrl-Space)");
1286 if( _toolbarConfigMenuUtil( ID_MOB, tipString ) )
1287 tb->AddTool( ID_MOB, _T("mob_btn"),
1288 style->GetToolIcon( _T("mob_btn"), TOOLICON_NORMAL ), tipString, wxITEM_NORMAL );
1289
1290
1291// Realize() the toolbar
1292 style->Unload();
1293 Realize();
1294
1295// Set up the toggle states
1296
1297 if( parentCanvas ) {
1298 // Re-establish toggle states
1299 tb->ToggleTool( ID_CURRENT, parentCanvas->GetbShowCurrent() );
1300 tb->ToggleTool( ID_TIDE, parentCanvas->GetbShowTide() );
1301 tb->ToggleTool( ID_FOLLOW, parentCanvas->m_bFollow );
1302 }
1303
1304 if( ( ps52plib ) ){
1305 if( ps52plib->m_bOK )
1306 tb->ToggleTool( ID_ENC_TEXT, ps52plib->GetShowS57Text() );
1307 }
1308
1309 wxString initiconName;
1310 if( parentCanvas->GetShowAIS() ) {
1311 if (g_bAllowShowScaled){
1312 if(!parentCanvas->GetAttenAIS())
1313 tb->SetToolShortHelp( ID_AIS, _("Attenuate less critical AIS targets") );
1314 else
1315 tb->SetToolShortHelp( ID_AIS, _("Hide AIS Targets") );
1316 }
1317 else
1318 tb->SetToolShortHelp( ID_AIS, _("Hide AIS Targets") );
1319 initiconName = _T("AIS");
1320 }
1321 else {
1322 tb->SetToolShortHelp( ID_AIS, _("Show AIS Targets") );
1323 initiconName = _T("AIS_Disabled");
1324 }
1325 tb->SetToolNormalBitmapEx( m_pTBAISTool, initiconName );
1326 m_tblastAISiconName = initiconName;
1327
1328 tb->ToggleTool( ID_TRACK, g_bTrackActive );
1329
1330 // Set PlugIn tool toggle states
1331 ArrayOfPlugInToolbarTools tool_array = g_pi_manager->GetPluginToolbarToolArray();
1332 for( unsigned int i = 0; i < tool_array.GetCount(); i++ ) {
1333 PlugInToolbarToolContainer *pttc = tool_array.Item( i );
1334 if( !pttc->b_viz )
1335 continue;
1336
1337 if( pttc->kind == wxITEM_CHECK )
1338 tb->ToggleTool( pttc->id, pttc->b_toggle );
1339 }
1340
1341
1342 // TODO SetStatusBarPane( -1 ); // don't show help on status bar
1343
1344 return tb;
1345#endif
1346}
1347
1348bool ocpnFloatingToolbarDialog::CheckAndAddPlugInTool(ocpnToolBarSimple *tb) {
1349 if (!g_pi_manager) return false;
1350
1351 // We only add plugin tools on toolbar associated with canvas #0, the primary.
1352 // Except, if in gMUI mode, we allow no plugins ever on per-canvas toolbars.
1353
1354 ChartCanvas *parentCanvas = dynamic_cast<ChartCanvas *>(GetParent());
1355 if (parentCanvas) {
1356 if (g_useMUI) {
1357 return false;
1358 } else if (!parentCanvas->IsPrimaryCanvas())
1359 return false;
1360 }
1361
1362 bool bret = false;
1363 int n_tools = tb->GetToolsCount();
1364
1365 // Walk the PlugIn tool spec array, checking the requested position
1366 // If a tool has been requested by a plugin at this position, add it
1367 ArrayOfPlugInToolbarTools tool_array =
1368 g_pi_manager->GetPluginToolbarToolArray();
1369
1370 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
1371 PlugInToolbarToolContainer *pttc = tool_array.Item(i);
1372 if (pttc->position == n_tools) {
1373 wxBitmap *ptool_bmp;
1374
1375 switch (m_cs) {
1376 case GLOBAL_COLOR_SCHEME_DAY:
1377 ptool_bmp = pttc->bitmap_day;
1378 ;
1379 break;
1380 case GLOBAL_COLOR_SCHEME_DUSK:
1381 ptool_bmp = pttc->bitmap_dusk;
1382 break;
1383 case GLOBAL_COLOR_SCHEME_NIGHT:
1384 ptool_bmp = pttc->bitmap_night;
1385 break;
1386 default:
1387 ptool_bmp = pttc->bitmap_day;
1388 ;
1389 break;
1390 }
1391
1392 wxToolBarToolBase *tool =
1393 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
1394 wxString(pttc->shortHelp), pttc->kind);
1395
1396 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
1397 pttc->pluginRolloverIconSVG,
1398 pttc->pluginToggledIconSVG);
1399
1400 bret = true;
1401 }
1402 }
1403
1404 // If we added a tool, call again (recursively) to allow for adding
1405 // adjacent tools
1406 if (bret)
1407 while (CheckAndAddPlugInTool(tb)) { /* nothing to do */
1408 }
1409
1410 return bret;
1411}
1412
1413bool ocpnFloatingToolbarDialog::AddDefaultPositionPlugInTools(
1414 ocpnToolBarSimple *tb) {
1415 // We only add plugin tools on toolbar associated with canvas #0, the primary.
1416 // Except, if in gMUI mode, we allow no plugins ever on per-canvas toolbars.
1417 ChartCanvas *parentCanvas = dynamic_cast<ChartCanvas *>(GetParent());
1418 if (parentCanvas) {
1419 if (g_useMUI) {
1420 return false;
1421 }
1422 if (!parentCanvas->IsPrimaryCanvas()) return false;
1423 }
1424
1425 if (!g_pi_manager) return false;
1426
1427 bool bret = false;
1428
1429 // Walk the PlugIn tool spec array, checking the requested position
1430 // If a tool has been requested by a plugin at this position, add it
1431 ArrayOfPlugInToolbarTools tool_array =
1432 g_pi_manager->GetPluginToolbarToolArray();
1433
1434 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
1435 PlugInToolbarToolContainer *pttc = tool_array.Item(i);
1436
1437 // Tool is currently tagged as invisible
1438 if (!pttc->b_viz) continue;
1439
1440 if (pttc->position == -1) // PlugIn has requested default positioning
1441 {
1442 wxBitmap *ptool_bmp;
1443
1444 switch (m_cs) {
1445 case GLOBAL_COLOR_SCHEME_DAY:
1446 ptool_bmp = pttc->bitmap_day;
1447 break;
1448 case GLOBAL_COLOR_SCHEME_DUSK:
1449 ptool_bmp = pttc->bitmap_dusk;
1450 break;
1451 case GLOBAL_COLOR_SCHEME_NIGHT:
1452 ptool_bmp = pttc->bitmap_night;
1453 break;
1454 default:
1455 ptool_bmp = pttc->bitmap_day;
1456 break;
1457 }
1458
1459 wxToolBarToolBase *tool =
1460 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
1461 wxString(pttc->shortHelp), pttc->kind);
1462
1463 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
1464 pttc->pluginRolloverIconSVG,
1465 pttc->pluginToggledIconSVG);
1466
1467 bret = true;
1468 }
1469 }
1470 return bret;
1471}
1472
1473void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(bool bEnable) {
1474 m_enableRolloverBitmaps = bEnable;
1475 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
1476}
1477
1478//----------------------------------------------------------------------------
1479// Toolbar Tooltip Popup Window Definition
1480//----------------------------------------------------------------------------
1481class ToolTipWin : public wxFrame {
1482public:
1483 ToolTipWin(wxWindow *parent);
1484 ~ToolTipWin();
1485
1486 void OnPaint(wxPaintEvent &event);
1487
1488 void SetColorScheme(ColorScheme cs);
1489 void SetString(wxString &s) { m_string = s; }
1490 void SetPosition(wxPoint pt) { m_position = pt; }
1491 void SetBitmap(void);
1492
1493 void SetHiviz(bool hiviz) { m_hiviz = hiviz; }
1494
1495 wxSize GetRenderedSize(void);
1496
1497private:
1498 wxString m_string;
1499 wxSize m_size;
1500 wxPoint m_position;
1501 wxBitmap *m_pbm;
1502 wxColour m_back_color;
1503 wxColour m_text_color;
1504 ColorScheme m_cs;
1505 bool m_hiviz;
1506
1507 DECLARE_EVENT_TABLE()
1508};
1509//-----------------------------------------------------------------------
1510//
1511// Toolbar Tooltip window implementation
1512//
1513//-----------------------------------------------------------------------
1514BEGIN_EVENT_TABLE(ToolTipWin, wxFrame)
1515EVT_PAINT(ToolTipWin::OnPaint)
1516
1517END_EVENT_TABLE()
1518
1519// Define a constructor
1520ToolTipWin::ToolTipWin(wxWindow *parent)
1521 : wxFrame(parent, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(1, 1),
1522 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR) {
1523 m_pbm = NULL;
1524
1525 m_back_color = GetGlobalColor(_T ( "UIBCK" ));
1526 m_text_color = GetGlobalColor(_T ( "UITX1" ));
1527
1528 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1529 SetBackgroundColour(m_back_color);
1530 m_cs = GLOBAL_COLOR_SCHEME_RGB;
1531
1532 Hide();
1533}
1534
1535ToolTipWin::~ToolTipWin() { delete m_pbm; }
1536
1537void ToolTipWin::SetColorScheme(ColorScheme cs) {
1538 m_back_color = GetGlobalColor(_T ( "UIBCK" ));
1539 m_text_color = GetGlobalColor(_T ( "UITX1" ));
1540
1541#ifndef __WXOSX__
1542 m_text_color = FontMgr::Get().GetFontColor(_("ToolTips"));
1543 // assume black is the default
1544 if (m_text_color == *wxBLACK) m_text_color = GetGlobalColor(_T ( "UITX1" ));
1545#endif
1546
1547 m_cs = cs;
1548}
1549
1550wxSize ToolTipWin::GetRenderedSize(void) {
1551 int h, w;
1552 wxSize sz;
1553
1554 wxScreenDC cdc;
1555
1556 wxFont *plabelFont = FontMgr::Get().GetFont(_("ToolTips"));
1557 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, plabelFont);
1558
1559 sz.x = w + 8;
1560 sz.y = h + 4;
1561
1562 return sz;
1563}
1564
1565void ToolTipWin::SetBitmap() {
1566 int h, w;
1567
1568 wxScreenDC cdc;
1569 double scaler = g_Platform->GetDisplayDIPMult(this);
1570
1571 wxFont *plabelFont = FontMgr::Get().GetFont(_("ToolTips"));
1572 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
1573
1574 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, &sFont);
1575
1576 m_size.x = w + GetCharWidth() * 2;
1577 m_size.y = h + GetCharHeight() / 2;
1578
1579 m_size.x *= scaler;
1580 m_size.y *= scaler;
1581
1582 wxMemoryDC mdc;
1583
1584 delete m_pbm;
1585 m_pbm = new wxBitmap(m_size.x, m_size.y, -1);
1586 mdc.SelectObject(*m_pbm);
1587
1588 wxPen pborder(m_text_color);
1589 wxBrush bback(m_back_color);
1590 mdc.SetPen(pborder);
1591 mdc.SetBrush(bback);
1592
1593 if (m_hiviz) {
1594 if ((m_cs == GLOBAL_COLOR_SCHEME_DUSK) ||
1595 (m_cs == GLOBAL_COLOR_SCHEME_NIGHT)) {
1596 wxBrush hv_back(wxColour(200, 200, 200));
1597 mdc.SetBrush(hv_back);
1598 }
1599 }
1600 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
1601
1602 // Draw the text
1603 mdc.SetFont(sFont);
1604 mdc.SetTextForeground(m_text_color);
1605 mdc.SetTextBackground(m_back_color);
1606
1607 int offx = GetCharWidth();
1608 int offy = GetCharHeight()/4;
1609 offx *= scaler;
1610 offy *= scaler;
1611 mdc.DrawText(m_string, offx, offy);
1612
1613 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
1614}
1615
1616void ToolTipWin::OnPaint(wxPaintEvent &event) {
1617 int width, height;
1618 GetClientSize(&width, &height);
1619 wxPaintDC dc(this);
1620
1621 if (m_string.Len()) {
1622 wxMemoryDC mdc;
1623 mdc.SelectObject(*m_pbm);
1624 dc.Blit(0, 0, width, height, &mdc, 0, 0);
1625 }
1626}
1627
1628// ----------------------------------------------------------------------------
1629BEGIN_EVENT_TABLE(ocpnToolBarSimple, wxControl)
1630EVT_SIZE(ocpnToolBarSimple::OnSize)
1631EVT_PAINT(ocpnToolBarSimple::OnPaint)
1632EVT_KILL_FOCUS(ocpnToolBarSimple::OnKillFocus)
1633EVT_MOUSE_EVENTS(ocpnToolBarSimple::OnMouseEvent)
1634EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
1635EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
1636
1637END_EVENT_TABLE()
1638
1639// ============================================================================
1640// implementation
1641// ============================================================================
1642
1643// ----------------------------------------------------------------------------
1644// tool bar tools creation
1645// ----------------------------------------------------------------------------
1646
1647wxToolBarToolBase *ocpnToolBarSimple::CreateTool(
1648 int id, const wxString &label, const wxBitmap &bmpNormal,
1649 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
1650 const wxString &shortHelp, const wxString &longHelp) {
1651 if (m_style->NativeToolIconExists(label)) {
1652 return new ocpnToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
1653 clientData, shortHelp, longHelp);
1654 } else {
1655 wxString testToolname = g_pi_manager->GetToolOwnerCommonName(id);
1656
1657 if (testToolname == _T("")) { // Not a PlugIn tool...
1658 return new ocpnToolBarTool(this, id, bmpNormal, bmpDisabled, kind,
1659 clientData, shortHelp, longHelp);
1660 } else {
1661 return new ocpnToolBarTool(this, id, label, bmpNormal, bmpDisabled, kind,
1662 clientData, shortHelp, longHelp);
1663 }
1664 }
1665}
1666
1667// ----------------------------------------------------------------------------
1668// ocpnToolBarSimple creation
1669// ----------------------------------------------------------------------------
1670
1671void ocpnToolBarSimple::Init() {
1672 m_currentRowsOrColumns = 0;
1673
1674 m_lastX = m_lastY = 0;
1675
1676 m_maxWidth = m_maxHeight = 0;
1677
1678 m_pressedTool = m_currentTool = -1;
1679
1680 m_xPos = m_yPos = wxDefaultCoord;
1681
1682 m_style = g_StyleManager->GetCurrentStyle();
1683
1684 m_defaultWidth = 16;
1685 m_defaultHeight = 15;
1686
1687 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
1688 m_toolOutlineColour.Set(_T("BLACK"));
1689 m_pToolTipWin = NULL;
1690 m_last_ro_tool = NULL;
1691
1692 m_btoolbar_is_zooming = false;
1693 m_sizefactor = 1.0f;
1694
1695 m_last_plugin_down_id = -1;
1696 m_leftDown = false;
1697 m_nShowTools = 0;
1698 m_btooltip_show = false;
1699#ifndef __OCPN__ANDROID__
1700 EnableTooltips();
1701#endif
1702 m_tbenableRolloverBitmaps = false;
1703}
1704
1705wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
1706 int id, const wxString &label, const wxBitmap &bitmap,
1707 const wxBitmap &bmpDisabled, wxItemKind kind, const wxString &shortHelp,
1708 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
1709 wxCoord yPos) {
1710 // rememeber the position for DoInsertTool()
1711 m_xPos = xPos;
1712 m_yPos = yPos;
1713
1714 InvalidateBestSize();
1715 return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled, kind,
1716 shortHelp, longHelp, clientData);
1717}
1718
1720
1721wxToolBarToolBase *ocpnToolBarSimple::AddTool(
1722 int toolid, const wxString &label, const wxBitmap &bitmap,
1723 const wxBitmap &bmpDisabled, wxItemKind kind, const wxString &shortHelp,
1724 const wxString &longHelp, wxObject *data) {
1725 InvalidateBestSize();
1726 ocpnToolBarTool *tool = (ocpnToolBarTool *)InsertTool(
1727 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
1728 longHelp, data);
1729 return tool;
1730}
1731
1732wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
1733 size_t pos, int id, const wxString &label, const wxBitmap &bitmap,
1734 const wxBitmap &bmpDisabled, wxItemKind kind, const wxString &shortHelp,
1735 const wxString &longHelp, wxObject *clientData) {
1736 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1737 _T("invalid position in wxToolBar::InsertTool()"));
1738
1739 wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind,
1740 clientData, shortHelp, longHelp);
1741
1742 if (!InsertTool(pos, tool)) {
1743 delete tool;
1744
1745 return NULL;
1746 }
1747
1748 return tool;
1749}
1750
1751wxToolBarToolBase *ocpnToolBarSimple::InsertTool(size_t pos,
1752 wxToolBarToolBase *tool) {
1753 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1754 _T("invalid position in wxToolBar::InsertTool()"));
1755
1756 if (!tool || !DoInsertTool(pos, tool)) {
1757 return NULL;
1758 }
1759
1760 m_tools.Insert(pos, tool);
1761 m_nShowTools++;
1762
1763 return tool;
1764}
1765
1766bool ocpnToolBarSimple::DoInsertTool(size_t WXUNUSED(pos),
1767 wxToolBarToolBase *toolBase) {
1768 ocpnToolBarTool *tool = (ocpnToolBarTool *)toolBase;
1769
1770 // Check if the plugin is inserting same-named tools. Make sure they have
1771 // different names, otherwise the style manager cannot differentiate between
1772 // them.
1773 if (tool->isPluginTool) {
1774 for (unsigned int i = 0; i < GetToolsCount(); i++) {
1775 if (tool->GetToolname() ==
1776 ((ocpnToolBarTool *)m_tools.Item(i)->GetData())->GetToolname()) {
1777 tool->toolname << _T("1");
1778 }
1779 }
1780 }
1781
1782 tool->m_x = m_xPos;
1783 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
1784
1785 tool->m_y = m_yPos;
1786 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
1787
1788 if (tool->IsButton()) {
1789 tool->SetSize(GetToolSize());
1790
1791 // Calculate reasonable max size in case Layout() not called
1792 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
1793 m_style->GetLeftMargin()) > m_maxWidth)
1794 m_maxWidth =
1795 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
1796
1797 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
1798 m_style->GetTopMargin()) > m_maxHeight)
1799 m_maxHeight =
1800 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
1801 }
1802
1803 else if (tool->IsControl()) {
1804 tool->SetSize(tool->GetControl()->GetSize());
1805 }
1806
1807 tool->b_hilite = false;
1808
1809 return true;
1810}
1811
1812bool ocpnToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos),
1813 wxToolBarToolBase *tool) {
1814 // VZ: didn't test whether it works, but why not...
1815 tool->Detach();
1816
1817 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
1818
1819 Refresh(false);
1820
1821 return true;
1822}
1823
1824bool ocpnToolBarSimple::Create(wxWindow *parent, wxWindowID id,
1825 const wxPoint &pos, const wxSize &size,
1826 long style, const wxString &name) {
1827 if (!wxWindow::Create(parent, id, pos, size, style, name)) return false;
1828
1829 // Set it to grey (or other 3D face colour)
1830 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
1831
1832 if (GetWindowStyleFlag() & wxTB_VERTICAL) {
1833 m_lastX = 7;
1834 m_lastY = 3;
1835
1836 m_maxRows = 32000; // a lot
1837 m_maxCols = 1;
1838 } else {
1839 m_lastX = 3;
1840 m_lastY = 7;
1841
1842 m_maxRows = 1;
1843 m_maxCols = 32000; // a lot
1844 }
1845
1846 SetCursor(*wxSTANDARD_CURSOR);
1847
1848 m_tooltip_timer.SetOwner(this, TOOLTIPON_TIMER);
1849 m_tooltipoff_timer.SetOwner(this, TOOLTIPOFF_TIMER);
1850 m_tooltip_off = 3000;
1851
1852 m_tbenableRolloverBitmaps = false;
1853
1854 return true;
1855}
1856
1857ocpnToolBarSimple::~ocpnToolBarSimple() {
1858 if (m_pToolTipWin) {
1859 m_pToolTipWin->Destroy();
1860 m_pToolTipWin = NULL;
1861 }
1862}
1863
1864void ocpnToolBarSimple::EnableTooltips() {
1865#ifndef __OCPN__ANDROID__
1866 m_btooltip_show = true;
1867#endif
1868}
1869
1870void ocpnToolBarSimple::DisableTooltips() {
1871#ifndef __OCPN__ANDROID__
1872 ocpnToolBarSimple::m_btooltip_show = false;
1873#endif
1874}
1875
1876void ocpnToolBarSimple::KillTooltip() {
1877 m_btooltip_show = false;
1878
1879 if (m_pToolTipWin) {
1880 m_pToolTipWin->Hide();
1881 m_pToolTipWin->Destroy();
1882 m_pToolTipWin = NULL;
1883 }
1884 m_tooltip_timer.Stop();
1885
1886 /*
1887 if( m_last_ro_tool ) {
1888 if( m_last_ro_tool->IsEnabled() ) {
1889 if( m_last_ro_tool->IsToggled() ) {
1890 if(
1891 m_style->NativeToolIconExists(m_last_ro_tool->GetToolname()) ) {
1892 m_last_ro_tool->SetNormalBitmap( m_style->GetToolIcon(
1893 m_last_ro_tool->GetToolname(), TOOLICON_TOGGLED ) );
1894 }
1895 else{
1896 m_last_ro_tool->SetNormalBitmap(m_style->BuildPluginIcon(
1897 m_last_ro_tool->pluginNormalIcon, TOOLICON_TOGGLED ));
1898 }
1899
1900 }
1901 else {
1902 if(
1903 m_style->NativeToolIconExists(m_last_ro_tool->GetToolname()) ) {
1904 m_last_ro_tool->SetNormalBitmap( m_style->GetToolIcon(
1905 m_last_ro_tool->GetToolname(), TOOLICON_NORMAL ) );
1906 }
1907 else{
1908 m_last_ro_tool->SetNormalBitmap(m_style->BuildPluginIcon(
1909 m_last_ro_tool->pluginNormalIcon, TOOLICON_NORMAL ));
1910 }
1911 }
1912 }
1913 }
1914 */
1915 gFrame->Raise();
1916 gFrame->GetFocusCanvas()->TriggerDeferredFocus();
1917}
1918
1919void ocpnToolBarSimple::HideTooltip() {
1920#ifndef __OCPN__ANDROID__
1921 if (m_pToolTipWin) {
1922 m_pToolTipWin->Hide();
1923 }
1924#endif
1925}
1926
1927void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1928#ifndef __OCPN__ANDROID__
1929 if (m_pToolTipWin) {
1930 m_pToolTipWin->Destroy();
1931 m_pToolTipWin = NULL;
1932 }
1933#endif
1934 m_toolOutlineColour = GetGlobalColor(_T("UIBDR"));
1935
1936 m_currentColorScheme = cs;
1937}
1938
1939bool ocpnToolBarSimple::Realize() {
1940 if (IsVertical())
1941 m_style->SetOrientation(wxTB_VERTICAL);
1942 else
1943 m_style->SetOrientation(wxTB_HORIZONTAL);
1944
1945 wxSize toolSize = wxSize(-1, -1);
1946 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1947 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1948 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1949
1950 m_currentRowsOrColumns = 0;
1951 m_LineCount = 1;
1952 m_lastX = leftMargin;
1953 m_lastY = topMargin;
1954 m_maxWidth = 0;
1955 m_maxHeight = 0;
1956
1957 ocpnToolBarTool *lastTool = NULL;
1958 bool firstNode = true;
1959 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1960
1961 int iNode = 0;
1962
1963 while (node) {
1964 if (iNode >= m_nShowTools) break;
1965
1966 ocpnToolBarTool *tool = (ocpnToolBarTool *)node->GetData();
1967
1968 // Set the tool size to be the size of the first non-separator tool, usually
1969 // the first one
1970 if (toolSize.x == -1) {
1971 if (!tool->IsSeparator()) {
1972 toolSize.x = tool->m_width;
1973 toolSize.y = tool->m_height;
1974 }
1975 }
1976
1977 tool->firstInLine = firstNode;
1978 tool->lastInLine = false;
1979 firstNode = false;
1980
1981 tool->last_rect.width = 0; // mark it invalid
1982
1983 if (tool->IsSeparator()) {
1984 if (GetWindowStyleFlag() & wxTB_HORIZONTAL) {
1985 if (m_currentRowsOrColumns >= m_maxCols)
1986 m_lastY += separatorSize;
1987 else
1988 m_lastX += separatorSize;
1989 } else {
1990 if (m_currentRowsOrColumns >= m_maxRows)
1991 m_lastX += separatorSize;
1992 else
1993 m_lastY += separatorSize;
1994 }
1995 } else if (tool->IsButton()) {
1996 if (!IsVertical()) {
1997 if (m_currentRowsOrColumns >= m_maxCols) {
1998 tool->firstInLine = true;
1999 if (lastTool && m_LineCount > 1) lastTool->lastInLine = true;
2000 m_LineCount++;
2001 m_currentRowsOrColumns = 0;
2002 m_lastX = leftMargin;
2003 m_lastY += toolSize.y + topMargin;
2004 }
2005 tool->m_x = (wxCoord)m_lastX;
2006 tool->m_y = (wxCoord)m_lastY;
2007
2008 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
2009 tool->trect.Inflate(separatorSize / 2, topMargin);
2010
2011 m_lastX += toolSize.x + separatorSize;
2012 } else {
2013 if (m_currentRowsOrColumns >= m_maxRows) {
2014 tool->firstInLine = true;
2015 if (lastTool) lastTool->lastInLine = true;
2016 m_LineCount++;
2017 m_currentRowsOrColumns = 0;
2018 m_lastX += toolSize.x + leftMargin;
2019 m_lastY = topMargin;
2020 }
2021 tool->m_x = (wxCoord)m_lastX;
2022 tool->m_y = (wxCoord)m_lastY;
2023
2024 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
2025 tool->trect.Inflate((separatorSize / 2), topMargin);
2026
2027 m_lastY += toolSize.y + separatorSize;
2028 }
2029 m_currentRowsOrColumns++;
2030 } else if (tool->IsControl()) {
2031 tool->m_x = (wxCoord)(m_lastX);
2032 tool->m_y = (wxCoord)(m_lastY - (topMargin / 2));
2033
2034 tool->trect =
2035 wxRect(tool->m_x, tool->m_y, tool->GetWidth(), tool->GetHeight());
2036 tool->trect.Inflate(separatorSize / 2, topMargin);
2037
2038 wxSize s = tool->GetControl()->GetSize();
2039 m_lastX += s.x + separatorSize;
2040 }
2041
2042 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
2043 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
2044
2045 lastTool = tool;
2046 node = node->GetNext();
2047 iNode++;
2048 }
2049 if (lastTool && (m_LineCount > 1 || IsVertical()))
2050 lastTool->lastInLine = true;
2051
2052 if (GetWindowStyleFlag() & wxTB_HORIZONTAL) {
2053 m_maxHeight += toolSize.y;
2054 m_maxHeight += m_style->GetBottomMargin();
2055 } else {
2056 m_maxWidth += toolSize.x;
2057 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
2058 }
2059
2060 SetSize(m_maxWidth, m_maxHeight);
2061 SetMinSize(wxSize(m_maxWidth, m_maxHeight));
2062
2063 return true;
2064}
2065
2066// ----------------------------------------------------------------------------
2067// event handlers
2068// ----------------------------------------------------------------------------
2069
2070void ocpnToolBarSimple::OnPaint(wxPaintEvent &WXUNUSED(event)) {
2071 wxPaintDC dc(this);
2072 PrepareDC(dc);
2073
2074 wxRegion ru = GetUpdateRegion();
2075 wxRect upRect = ru.GetBox();
2076
2077 static int count = 0;
2078 // Prevent reentry of OnPaint which would cause wxMemoryDC errors.
2079 if (count > 0) return;
2080 count++;
2081
2082 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2083 node; node = node->GetNext()) {
2084 wxToolBarToolBase *tool = node->GetData();
2085 ocpnToolBarTool *tools = (ocpnToolBarTool *)tool;
2086 wxRect toolRect = tools->trect;
2087
2088 if (toolRect.Intersects(upRect)) {
2089 if (tool->IsButton()) {
2090 DrawTool(dc, tool);
2091 } else if (tool->IsControl()) {
2092 if (tool->GetControl()->IsKindOf(CLASSINFO(wxStaticBitmap))) {
2093 wxStaticBitmap *psbm = (wxStaticBitmap *)tool->GetControl();
2094 ocpnToolBarTool *toolsimp = (ocpnToolBarTool *)tool;
2095 dc.DrawBitmap(psbm->GetBitmap(), toolsimp->m_x, toolsimp->m_y, false);
2096 }
2097 }
2098 }
2099 }
2100
2101 count--;
2102}
2103
2104void ocpnToolBarSimple::OnSize(wxSizeEvent &WXUNUSED(event)) {
2105 /*if( GetAutoLayout() )*/ Layout();
2106}
2107
2108void ocpnToolBarSimple::OnKillFocus(wxFocusEvent &WXUNUSED(event)) {
2109 OnMouseEnter(m_pressedTool = m_currentTool = -1);
2110}
2111
2112void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
2113 if (!gFrame) // In case gFrame was already destroyed, but the toolbar still
2114 // exists (Which should not happen, ever.)
2115 return;
2116
2117 // if( !gFrame->IsActive() )
2118 // return;
2119
2120 if (m_btooltip_show && IsShown() && m_pToolTipWin &&
2121 (!m_pToolTipWin->IsShown())) {
2122 if (m_last_ro_tool) {
2123 wxString s = m_last_ro_tool->GetShortHelp();
2124
2125 if (s.Len()) {
2126 m_pToolTipWin->SetString(s);
2127 m_pToolTipWin->SetHiviz(m_last_ro_tool->m_btooltip_hiviz);
2128
2129 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
2130 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
2131
2132 m_pToolTipWin->Move(
2133 0, 0); // workaround for gtk autocentre dialog behavior
2134
2135 wxPoint screenPosition = ClientToScreen(pos_in_toolbar);
2136 wxPoint framePosition = gFrame->ScreenToClient(screenPosition);
2137 wxSize tipSize = m_pToolTipWin->GetRenderedSize();
2138
2139 if ((framePosition.x + tipSize.x) > gFrame->GetSize().x)
2140 screenPosition.x -= (tipSize.x + m_last_ro_tool->m_width + 4);
2141
2142 m_pToolTipWin->SetPosition(screenPosition);
2143 m_pToolTipWin->SetBitmap();
2144 m_pToolTipWin->Show();
2145#ifndef __WXOSX__
2146 gFrame->Raise();
2147#endif
2148
2149#ifndef __OCPN__ANDROID__
2150 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
2151#endif
2152 }
2153 }
2154 }
2155}
2156
2157void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
2158 HideTooltip();
2159}
2160
2161int s_dragx, s_dragy;
2162bool leftDown;
2163
2164void ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event) {
2165#ifdef __OCPN__ANDROID__
2166 if (!event.IsButton()) return;
2167#endif
2168
2169 wxCoord x, y;
2170 event.GetPosition(&x, &y);
2171 ocpnToolBarTool *tool = (ocpnToolBarTool *)FindToolForPosition(x, y);
2172
2173#ifndef __OCPN__ANDROID__
2174 if (event.LeftDown()) {
2176 s_dragx = x;
2177 s_dragy = y;
2178 }
2179 if (event.LeftUp()) {
2181 }
2182#endif
2183
2184 static wxPoint s_pos_m_old;
2185 static bool s_drag;
2186
2187 if (tool && (s_drag || tool->GetId() == ID_MASTERTOGGLE)) {
2188 wxPoint pos_m = ClientToScreen(wxPoint(x, y));
2189 if (event.LeftDown()) {
2190 s_pos_m_old = pos_m;
2191 }
2192
2193 if (!g_btouch && event.Dragging()) {
2194 s_drag = true;
2195 wxPoint pos_old = GetScreenPosition();
2196 wxPoint pos_new = pos_old;
2197
2198 int dx = abs(pos_m.x - s_pos_m_old.x);
2199 int dy = abs(pos_m.y - s_pos_m_old.y);
2200 if ((dx < 10) && (dy < 10)) {
2201 // s_pos_m_old = pos_m;
2202 // return;
2203 }
2204
2205 pos_new.x += pos_m.x - s_pos_m_old.x;
2206 pos_new.y += pos_m.y - s_pos_m_old.y;
2207
2208 ocpnFloatingToolbarDialog *parentFloatingToolBar =
2209 dynamic_cast<ocpnFloatingToolbarDialog *>(GetParent());
2210 // if( (dx > 4) || (dy > 4))
2211 parentFloatingToolBar->MoveDialogInScreenCoords(pos_new, pos_old);
2213 wxDynamicCast(GetParent(), ocpnFloatingToolbarDialog);
2214 if (parent)
2215 parent->GetFrameRelativePosition(&g_maintoolbar_x, &g_maintoolbar_y);
2216 s_pos_m_old = pos_m;
2217 return;
2218 }
2219
2220 if (event.LeftUp() && s_drag) {
2221 s_drag = false;
2222 return;
2223 }
2224 }
2225
2226 if (tool && tool->IsButton() && IsShown()) {
2227 if (m_btooltip_show) {
2228 // ToolTips
2229 if (NULL == m_pToolTipWin) {
2230 m_pToolTipWin = new ToolTipWin(gFrame /*GetParent()*/);
2231 m_pToolTipWin->SetColorScheme(m_currentColorScheme);
2232 m_pToolTipWin->Hide();
2233 }
2234
2235 if (tool != m_last_ro_tool) {
2236 m_pToolTipWin->Hide();
2237 }
2238
2239#ifndef __OCPN__ANDROID__
2240 if (!m_pToolTipWin->IsShown()) {
2241 if (!m_tooltip_timer.IsRunning()) {
2242 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
2243 }
2244 }
2245#endif
2246 }
2247 // Tool Rollover highlighting
2248 if (!g_btouch && m_tbenableRolloverBitmaps) {
2249 if (tool != m_last_ro_tool) {
2250 if (tool->IsEnabled()) {
2251 tool->rollover = true;
2252 }
2253 if (m_last_ro_tool) {
2254 if (m_last_ro_tool->IsEnabled()) {
2255 m_last_ro_tool->rollover = false;
2256 }
2257 }
2258 tool->bitmapOK = false;
2259 m_last_ro_tool = tool;
2260
2261 Refresh(false);
2262 }
2263 }
2264 } else {
2265 // Tooltips
2266 if (m_pToolTipWin && m_pToolTipWin->IsShown()) {
2267 m_pToolTipWin->Hide();
2268 KillTooltip();
2269 m_btooltip_show = true;
2270 }
2271
2272 // Remove Highlighting
2273 if (m_last_ro_tool && m_tbenableRolloverBitmaps) {
2274 if (m_last_ro_tool->IsEnabled()) {
2275 m_last_ro_tool->rollover = false;
2276 m_last_ro_tool->bitmapOK = false;
2277 }
2278 Refresh(false);
2279 }
2280 }
2281
2282 m_last_ro_tool = tool;
2283
2284 // allow smooth zooming while toolbutton is held down
2285 if (g_bsmoothpanzoom && !g_btouch) {
2286 ChartCanvas *pcc = NULL;
2288 wxDynamicCast(GetParent(), ocpnFloatingToolbarDialog);
2289 if (parent) pcc = wxDynamicCast(parent->GetParent(), ChartCanvas);
2290
2291 if (event.LeftUp() && m_btoolbar_is_zooming) {
2292 if (pcc) {
2293 pcc->StopMovement();
2294 m_btoolbar_is_zooming = false;
2295 }
2296 return;
2297 }
2298
2299 if (event.LeftDown() && tool &&
2300 (tool->GetId() == ID_ZOOMIN || tool->GetId() == ID_ZOOMOUT)) {
2301 if (pcc) {
2302 pcc->ZoomCanvas(tool->GetId() == ID_ZOOMIN
2303 ? g_plus_minus_zoom_factor
2304 : 1.0 / g_plus_minus_zoom_factor,
2305 false, false);
2306 m_btoolbar_is_zooming = true;
2307 }
2308 return;
2309 }
2310 }
2311
2312 if (!tool) {
2313 if (m_currentTool > -1) {
2314 if (event.LeftIsDown()) SpringUpButton(m_currentTool);
2315 m_currentTool = -1;
2316 OnMouseEnter(-1);
2317 }
2318
2319 wxMouseEvent *pev = (wxMouseEvent *)event.Clone();
2320 GetParent()->GetEventHandler()->AddPendingEvent(*pev);
2321 wxDELETE(pev);
2322
2323 return;
2324 }
2325
2326 if (!event.IsButton()) {
2327 if (tool->GetId() != m_currentTool) {
2328 // If the left button is kept down and moved over buttons,
2329 // press those buttons.
2330 if (event.LeftIsDown() && tool->IsEnabled()) {
2331 SpringUpButton(m_currentTool);
2332
2333 if (tool->CanBeToggled()) {
2334 tool->Toggle();
2335 }
2336
2337 DrawTool(tool);
2338 }
2339
2340 m_currentTool = tool->GetId();
2341 OnMouseEnter(m_currentTool);
2342 }
2343
2344 wxMouseEvent *pev = (wxMouseEvent *)event.Clone();
2345 GetParent()->GetEventHandler()->AddPendingEvent(*pev);
2346 wxDELETE(pev);
2347
2348 return;
2349 }
2350
2351 // Left button pressed.
2352 if (event.LeftIsDown()) m_leftDown = true; // trigger on
2353
2354 if (event.LeftDown() && tool->IsEnabled()) {
2355 if (tool->CanBeToggled()) {
2356 tool->Toggle();
2357 tool->bitmapOK = false;
2358 }
2359
2360 DrawTool(tool);
2361
2362 // Look for PlugIn tools
2363 // If found, make the callback.
2364 if (g_pi_manager) {
2365 ArrayOfPlugInToolbarTools tool_array =
2366 g_pi_manager->GetPluginToolbarToolArray();
2367 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
2368 PlugInToolbarToolContainer *pttc = tool_array[i];
2369 if (tool->GetId() == pttc->id) {
2370 opencpn_plugin_113 *ppi =
2371 dynamic_cast<opencpn_plugin_113 *>(pttc->m_pplugin);
2372 if (ppi) {
2373 ppi->OnToolbarToolDownCallback(pttc->id);
2374 m_last_plugin_down_id = pttc->id;
2375 }
2376 }
2377 }
2378 }
2379 } else if (event.RightDown()) {
2380 OnRightClick(tool->GetId(), x, y);
2381 }
2382
2383 // Left Button Released. Only this action confirms selection.
2384 // If the button is enabled and it is not a toggle tool and it is
2385 // in the pressed state, then raise the button and call OnLeftClick.
2386 //
2387 // Unfortunately, some touch screen drivers do not send "LeftIsDown" events.
2388 // Nor do they report "LeftIsDown" in any state.
2389 // c.f rPI "official" 7" panel.
2390
2391 // So, for this logic, assume in touch mode that the m_leftDown flag may not
2392 // be set, and process the left-up event anyway.
2393 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
2394 // Pass the OnLeftClick event to tool
2395 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
2396 tool->CanBeToggled()) {
2397 // If it was a toggle, and OnLeftClick says No Toggle allowed,
2398 // then change it back
2399 tool->Toggle();
2400 tool->bitmapOK = false;
2401 }
2402
2403 DoPluginToolUp();
2404 m_leftDown = false;
2405 }
2406
2407 wxMouseEvent *pev = (wxMouseEvent *)event.Clone();
2408 GetParent()->GetEventHandler()->AddPendingEvent(*pev);
2409 wxDELETE(pev);
2410 event.Skip();
2411}
2412
2413// ----------------------------------------------------------------------------
2414// drawing
2415// ----------------------------------------------------------------------------
2416
2417void ocpnToolBarSimple::DrawTool(wxToolBarToolBase *tool) {
2418 wxClientDC dc(this);
2419 DrawTool(dc, tool);
2420}
2421
2422// NB! The current DrawTool code assumes that plugin tools are never disabled
2423// when they are present on the toolbar, since disabled plugins are removed.
2424
2425void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
2426 ocpnToolBarTool *tool = (ocpnToolBarTool *)toolBase;
2427 PrepareDC(dc);
2428
2429 wxPoint drawAt(tool->m_x, tool->m_y);
2430 wxBitmap bmp = wxNullBitmap;
2431
2432 bool bNeedClear = !tool->bitmapOK;
2433
2434 if (tool->bitmapOK) {
2435 if (tool->IsEnabled()) {
2436 bmp = tool->GetNormalBitmap();
2437 if (!bmp.IsOk()) {
2438 bmp =
2439 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
2440 tool->rollover, tool->m_width, tool->m_height);
2441 tool->SetNormalBitmap(bmp);
2442 tool->bitmapOK = true;
2443 }
2444 } else {
2445 bmp = tool->GetDisabledBitmap();
2446 if (!bmp.IsOk()) {
2447 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
2448 false, tool->m_width, tool->m_height);
2449 tool->SetDisabledBitmap(bmp);
2450 tool->bitmapOK = true;
2451 }
2452 }
2453 } else {
2454 if (tool->isPluginTool) {
2455 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
2456
2457 // First try getting the icon from an SVG definition.
2458 // If it is not found, try to see if it is available in the style
2459 // If not there, we build a new icon from the style BG and the (default)
2460 // plugin icon.
2461
2462 wxString svgFile = tool->pluginNormalIconSVG;
2463 if (toggleFlag) {
2464 if (tool->pluginToggledIconSVG.Length())
2465 svgFile = tool->pluginToggledIconSVG;
2466 }
2467 if (tool->rollover) {
2468 if (tool->pluginRolloverIconSVG.Length())
2469 svgFile = tool->pluginRolloverIconSVG;
2470 }
2471
2472 if (!svgFile.IsEmpty()) { // try SVG
2473#ifdef ocpnUSE_SVG
2474 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
2475 if (bmp.IsOk()) {
2476 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
2477 } else
2478 bmp =
2479 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
2480#endif
2481 }
2482
2483 if (!bmp.IsOk() || bmp.IsNull()) {
2484 if (m_style->NativeToolIconExists(tool->GetToolname())) {
2485 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
2486 tool->rollover, tool->m_width,
2487 tool->m_height);
2488 } else {
2489 bmp = wxNullBitmap;
2490 }
2491
2492 if (bmp.IsNull()) { // Tool icon not found
2493 if (tool->rollover) {
2494 bmp =
2495 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
2496 if (!bmp.IsOk()) {
2497 bmp =
2498 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
2499 }
2500 } else {
2501 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
2502 }
2503 if (fabs(m_sizefactor - 1.0) > 0.01) {
2504 if (tool->m_width && tool->m_height) {
2505 wxImage scaled_image = bmp.ConvertToImage();
2506 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
2507 wxIMAGE_QUALITY_HIGH));
2508 }
2509 }
2510 }
2511 }
2512 tool->SetNormalBitmap(bmp);
2513 tool->bitmapOK = true;
2514 } else { // Not a plugin tool
2515 bmp = tool->GetNormalBitmap();
2516 if (tool->IsEnabled()) {
2517 if (tool->IsToggled()) {
2518 if (!tool->bitmapOK) {
2519 if (m_style->NativeToolIconExists(tool->GetToolname())) {
2520 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
2521 tool->rollover, tool->m_width,
2522 tool->m_height);
2523 tool->SetNormalBitmap(bmp);
2524 }
2525 }
2526 }
2527
2528 else {
2529 if (!tool->bitmapOK) {
2530 if (m_style->NativeToolIconExists(tool->GetToolname())) {
2531 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
2532 tool->rollover, tool->m_width,
2533 tool->m_height);
2534 tool->SetNormalBitmap(bmp);
2535 }
2536 }
2537 }
2538
2539 tool->bitmapOK = true;
2540 } else {
2541 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
2542 false, tool->m_width, tool->m_height);
2543 tool->SetDisabledBitmap(bmp);
2544 tool->bitmapOK = true;
2545 }
2546 }
2547 }
2548
2549 if (tool->firstInLine) {
2550 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
2551 }
2552 if (tool->lastInLine) {
2553 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
2554 }
2555
2556 if (bmp.GetWidth() != m_style->GetToolSize().x ||
2557 bmp.GetHeight() != m_style->GetToolSize().y) {
2558 // drawAt.x -= ( bmp.GetWidth() - m_style->GetToolSize().x ) / 2;
2559 // drawAt.y -= ( bmp.GetHeight() - m_style->GetToolSize().y ) / 2;
2560 }
2561
2562 // Clear the last drawn tool if necessary
2563 if ((tool->last_rect.width &&
2564 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
2565 bNeedClear) {
2566 wxBrush bb(GetGlobalColor(_T("GREY3")));
2567 dc.SetBrush(bb);
2568 dc.SetPen(*wxTRANSPARENT_PEN);
2569 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
2570 tool->last_rect.width, tool->last_rect.height);
2571 }
2572
2573 // could cache this in the tool...
2574 // A bit of a hack here. We only scale tools if they are to be magnified
2575 // globally
2576 if (0 /*m_sizefactor > 1.0*/) {
2577 wxImage scaled_image = bmp.ConvertToImage();
2578 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
2579 wxIMAGE_QUALITY_HIGH));
2580 dc.DrawBitmap(sbmp, drawAt);
2581 tool->last_rect =
2582 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
2583
2584 } else {
2585 dc.DrawBitmap(bmp, drawAt);
2586 tool->last_rect =
2587 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
2588 }
2589}
2590
2591// ----------------------------------------------------------------------------
2592// toolbar geometry
2593// ----------------------------------------------------------------------------
2594
2595wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
2596 wxCoord y) {
2597 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2598 while (node) {
2599 ocpnToolBarTool *tool = (ocpnToolBarTool *)node->GetData();
2600 if ((x >= tool->m_x) && (y >= tool->m_y) &&
2601 (x < (tool->m_x + tool->GetWidth())) &&
2602 (y < (tool->m_y + tool->GetHeight()))) {
2603 return tool;
2604 }
2605
2606 node = node->GetNext();
2607 }
2608
2609 return (wxToolBarToolBase *)NULL;
2610}
2611
2612void ocpnToolBarSimple::InvalidateBitmaps() {
2613 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2614 while (node) {
2615 ocpnToolBarTool *tool = (ocpnToolBarTool *)node->GetData();
2616 tool->bitmapOK = false;
2617 node = node->GetNext();
2618 }
2619}
2620
2621wxRect ocpnToolBarSimple::GetToolRect(int tool_id) {
2622 wxRect rect;
2623 wxToolBarToolBase *tool = FindById(tool_id);
2624 if (tool) {
2625 ocpnToolBarTool *otool = (ocpnToolBarTool *)tool;
2626 if (otool) rect = otool->trect;
2627 }
2628
2629 return rect;
2630}
2631
2632// ----------------------------------------------------------------------------
2633// tool state change handlers
2634// ----------------------------------------------------------------------------
2635
2636void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
2637 bool WXUNUSED(enable)) {
2638 ocpnToolBarTool *t = (ocpnToolBarTool *)tool;
2639 t->bitmapOK = false;
2640 DrawTool(tool);
2641}
2642
2643void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
2644 bool WXUNUSED(toggle)) {
2645 ocpnToolBarTool *t = (ocpnToolBarTool *)tool;
2646 t->bitmapOK = false;
2647 DrawTool(tool);
2648}
2649
2650// Okay, so we've left the tool we're in ... we must check if the tool we're
2651// leaving was a 'sprung push button' and if so, spring it back to the up
2652// state.
2653void ocpnToolBarSimple::SpringUpButton(int id) {
2654 wxToolBarToolBase *tool = FindById(id);
2655
2656 if (tool && tool->CanBeToggled()) {
2657 if (tool->IsToggled()) tool->Toggle();
2658
2659 DrawTool(tool);
2660 }
2661}
2662
2663// ----------------------------------------------------------------------------
2664// scrolling implementation
2665// ----------------------------------------------------------------------------
2666
2667wxString ocpnToolBarSimple::GetToolShortHelp(int id) const {
2668 wxToolBarToolBase *tool = FindById(id);
2669 wxCHECK_MSG(tool, wxEmptyString, _T("no such tool"));
2670
2671 return tool->GetShortHelp();
2672}
2673
2674wxString ocpnToolBarSimple::GetToolLongHelp(int id) const {
2675 wxToolBarToolBase *tool = FindById(id);
2676 wxCHECK_MSG(tool, wxEmptyString, _T("no such tool"));
2677
2678 return tool->GetLongHelp();
2679}
2680
2681void ocpnToolBarSimple::SetToolShortHelp(int id, const wxString &help) {
2682 wxToolBarToolBase *tool = FindById(id);
2683 if (tool) {
2684 (void)tool->SetShortHelp(help);
2685 }
2686}
2687
2688void ocpnToolBarSimple::SetToolLongHelp(int id, const wxString &help) {
2689 wxToolBarToolBase *tool = FindById(id);
2690 if (tool) {
2691 (void)tool->SetLongHelp(help);
2692 }
2693}
2694
2695int ocpnToolBarSimple::GetToolPos(int id) const {
2696 size_t pos = 0;
2697 wxToolBarToolsList::compatibility_iterator node;
2698
2699 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2700 if (node->GetData()->GetId() == id) return pos;
2701
2702 pos++;
2703 }
2704
2705 return wxNOT_FOUND;
2706}
2707bool ocpnToolBarSimple::GetToolState(int id) const {
2708 wxToolBarToolBase *tool = FindById(id);
2709 wxCHECK_MSG(tool, false, _T("no such tool"));
2710
2711 return tool->IsToggled();
2712}
2713
2714bool ocpnToolBarSimple::GetToolEnabled(int id) const {
2715 wxToolBarToolBase *tool = FindById(id);
2716 wxCHECK_MSG(tool, false, _T("no such tool"));
2717
2718 return tool->IsEnabled();
2719}
2720
2721void ocpnToolBarSimple::ToggleTool(int id, bool toggle) {
2722 wxToolBarToolBase *tool = FindById(id);
2723
2724 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
2725 DoToggleTool(tool, toggle);
2726 Refresh();
2727 }
2728}
2729
2730wxObject *ocpnToolBarSimple::GetToolClientData(int id) const {
2731 wxToolBarToolBase *tool = FindById(id);
2732 return tool ? tool->GetClientData() : (wxObject *)NULL;
2733}
2734
2735void ocpnToolBarSimple::SetToolClientData(int id, wxObject *clientData) {
2736 wxToolBarToolBase *tool = FindById(id);
2737
2738 wxCHECK_RET(tool, _T("no such tool in wxToolBar::SetToolClientData"));
2739
2740 tool->SetClientData(clientData);
2741}
2742
2743void ocpnToolBarSimple::EnableTool(int id, bool enable) {
2744 wxToolBarToolBase *tool = FindById(id);
2745 if (tool) {
2746 if (tool->Enable(enable)) {
2747 DoEnableTool(tool, enable);
2748 }
2749 }
2750
2752 wxDynamicCast(GetParent(), ocpnFloatingToolbarDialog);
2753 if (parent && parent->m_FloatingToolbarConfigMenu) {
2754 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(id);
2755 if (configItem) configItem->Check(true);
2756 }
2757}
2758
2759void ocpnToolBarSimple::SetToolTooltipHiViz(int id, bool b_hiviz) {
2760 ocpnToolBarTool *tool = (ocpnToolBarTool *)FindById(id);
2761 if (tool) {
2762 tool->SetTooltipHiviz(b_hiviz);
2763 }
2764}
2765
2766void ocpnToolBarSimple::ClearTools() {
2767 while (GetToolsCount()) {
2768 DeleteToolByPos(0);
2769 }
2770}
2771
2772int ocpnToolBarSimple::GetVisibleToolCount() {
2773 int counter = 0;
2774 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2775 while (node) {
2776 ocpnToolBarTool *tool = (ocpnToolBarTool *)node->GetData();
2777 counter++;
2778 node = node->GetNext();
2779 }
2780 return counter;
2781}
2782
2783bool ocpnToolBarSimple::DeleteToolByPos(size_t pos) {
2784 wxCHECK_MSG(pos < GetToolsCount(), false,
2785 _T("invalid position in wxToolBar::DeleteToolByPos()"));
2786
2787 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
2788
2789 if (!DoDeleteTool(pos, node->GetData())) {
2790 return false;
2791 }
2792
2793 delete node->GetData();
2794 m_tools.Erase(node);
2795
2796 return true;
2797}
2798
2799bool ocpnToolBarSimple::DeleteTool(int id) {
2800 size_t pos = 0;
2801 wxToolBarToolsList::compatibility_iterator node;
2802 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2803 if (node->GetData()->GetId() == id) break;
2804
2805 pos++;
2806 }
2807
2808 if (!node || !DoDeleteTool(pos, node->GetData())) {
2809 return false;
2810 }
2811
2812 delete node->GetData();
2813 m_tools.Erase(node);
2814
2815 return true;
2816}
2817
2818wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
2819 return InsertSeparator(GetToolsCount());
2820}
2821
2822wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(size_t pos) {
2823 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
2824 _T("invalid position in wxToolBar::InsertSeparator()"));
2825
2826 wxToolBarToolBase *tool = CreateTool(
2827 wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap,
2828 wxITEM_SEPARATOR, (wxObject *)NULL, wxEmptyString, wxEmptyString);
2829
2830 if (!tool || !DoInsertTool(pos, tool)) {
2831 delete tool;
2832
2833 return NULL;
2834 }
2835
2836 m_tools.Insert(pos, tool);
2837 m_nShowTools++;
2838
2839 return tool;
2840}
2841
2842wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(int id) {
2843 size_t pos = 0;
2844 wxToolBarToolsList::compatibility_iterator node;
2845 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2846 if (node->GetData()->GetId() == id) break;
2847
2848 pos++;
2849 }
2850
2851 if (!node) {
2852 // don't give any error messages - sometimes we might call RemoveTool()
2853 // without knowing whether the tool is or not in the toolbar
2854 return (wxToolBarToolBase *)NULL;
2855 }
2856
2857 wxToolBarToolBase *tool = node->GetData();
2858 if (!DoDeleteTool(pos, tool)) {
2859 return (wxToolBarToolBase *)NULL;
2860 }
2861
2862 m_tools.Erase(node);
2863
2864 return tool;
2865}
2866
2867wxControl *ocpnToolBarSimple::FindControl(int id) {
2868 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2869 node; node = node->GetNext()) {
2870 const wxToolBarToolBase *const tool = node->GetData();
2871 if (tool->IsControl()) {
2872 wxControl *const control = tool->GetControl();
2873
2874 if (!control) {
2875 wxFAIL_MSG(_T("NULL control in toolbar?"));
2876 } else if (control->GetId() == id) {
2877 // found
2878 return control;
2879 }
2880 }
2881 }
2882
2883 return NULL;
2884}
2885
2886wxToolBarToolBase *ocpnToolBarSimple::FindById(int id) const {
2887 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
2888
2889 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2890 node; node = node->GetNext()) {
2891 tool = node->GetData();
2892 if (tool->GetId() == id) {
2893 // found
2894 break;
2895 }
2896
2897 tool = NULL;
2898 }
2899
2900 return tool;
2901}
2902
2903// ----------------------------------------------------------------------------
2904// event processing
2905// ----------------------------------------------------------------------------
2906
2907// Only allow toggle if returns true
2908bool ocpnToolBarSimple::OnLeftClick(int id, bool toggleDown) {
2909 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id);
2910 event.SetEventObject(this);
2911
2912 // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown
2913 event.SetInt((int)toggleDown);
2914
2915 // and SetExtraLong() for backwards compatibility
2916 event.SetExtraLong((long)toggleDown);
2917
2918 // Send events to this toolbar instead (and thence up the window hierarchy)
2919 GetEventHandler()->ProcessEvent(event);
2920
2921 return true;
2922}
2923
2924// Call when right button down.
2925void ocpnToolBarSimple::OnRightClick(int id, long WXUNUSED(x),
2926 long WXUNUSED(y)) {
2927 HideTooltip();
2928
2930 wxDynamicCast(GetParent(), ocpnFloatingToolbarDialog);
2931 if (parent) {
2932 if (parent->m_FloatingToolbarConfigMenu) {
2934 new ToolbarChoicesDialog(NULL, GetParent(), -1, _T("OpenCPN"),
2935 wxDefaultPosition, wxSize(100, 100));
2936 int rc = dlg->ShowModal();
2937 delete dlg;
2938
2939 if (rc == wxID_OK) {
2940 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id);
2941 event.SetEventObject(this);
2942 event.SetInt(id);
2943
2944 gFrame->GetEventHandler()->AddPendingEvent(event);
2945 }
2946 }
2947 }
2948}
2949
2950// Called when the mouse cursor enters a tool bitmap (no button pressed).
2951// Argument is wxID_ANY if mouse is exiting the toolbar.
2952// Note that for this event, the id of the window is used,
2953// and the integer parameter of wxCommandEvent is used to retrieve
2954// the tool id.
2955void ocpnToolBarSimple::OnMouseEnter(int id) {
2956 wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId());
2957 event.SetEventObject(this);
2958 event.SetInt(id);
2959
2960 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
2961 if (frame) {
2962 wxString help;
2963 wxToolBarToolBase *tool =
2964 id == wxID_ANY ? (wxToolBarToolBase *)NULL : FindById(id);
2965 if (tool) help = tool->GetLongHelp();
2966 frame->DoGiveHelp(help, id != wxID_ANY);
2967 }
2968
2969 (void)GetEventHandler()->ProcessEvent(event);
2970
2971 DoPluginToolUp();
2972}
2973
2974void ocpnToolBarSimple::DoPluginToolUp() {
2975 // Look for PlugIn tools
2976 // If found, make the callback.
2977 if (!g_pi_manager) return;
2978
2979 ArrayOfPlugInToolbarTools tool_array =
2980 g_pi_manager->GetPluginToolbarToolArray();
2981 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
2982 PlugInToolbarToolContainer *pttc = tool_array[i];
2983 if (m_last_plugin_down_id == pttc->id) {
2984 opencpn_plugin_113 *ppi =
2985 dynamic_cast<opencpn_plugin_113 *>(pttc->m_pplugin);
2986 if (ppi) ppi->OnToolbarToolUpCallback(pttc->id);
2987 }
2988 }
2989
2990 m_last_plugin_down_id = -1;
2991}
2992
2993void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2994 const wxString &iconName) {
2995 if (tool) {
2996 ocpnToolBarTool *otool = (ocpnToolBarTool *)tool;
2997 if (otool) {
2998 ocpnStyle::Style *style = g_StyleManager->GetCurrentStyle();
2999
3000 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL, false,
3001 otool->m_width, otool->m_height);
3002 tool->SetNormalBitmap(bmp);
3003 otool->SetIconName(iconName);
3004 }
3005 }
3006}
3007
3008void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
3009 wxString fileSVG) {
3010 if (tool) {
3011 ocpnToolBarTool *otool = (ocpnToolBarTool *)tool;
3012 if (otool) {
3013 otool->pluginNormalIconSVG = fileSVG;
3014 }
3015 }
3016}
3017
3018void ocpnToolBarSimple::SetToolBitmaps(int id, wxBitmap *bmp,
3019 wxBitmap *bmpRollover) {
3020 ocpnToolBarTool *tool = (ocpnToolBarTool *)FindById(id);
3021 if (tool) {
3022 if (tool->isPluginTool) {
3023 tool->pluginNormalIcon = *bmp;
3024 tool->pluginRolloverIcon = *bmpRollover;
3025 tool->bitmapOK = false;
3026 } else {
3027 tool->SetNormalBitmap(*bmp);
3028 tool->bitmapOK = true;
3029 }
3030 }
3031}
3032
3033void ocpnToolBarSimple::SetToolBitmapsSVG(int id, wxString fileSVGNormal,
3034 wxString fileSVGRollover,
3035 wxString fileSVGToggled) {
3036 ocpnToolBarTool *tool = (ocpnToolBarTool *)FindById(id);
3037 if (tool) {
3038 tool->pluginNormalIconSVG = fileSVGNormal;
3039 tool->pluginRolloverIconSVG = fileSVGRollover;
3040 tool->pluginToggledIconSVG = fileSVGToggled;
3041 tool->bitmapOK = false;
3042 }
3043}
3044
3045//-------------------------------------------------------------------------------------
3046
3047ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
3048 : wxDialog(parent, wxID_ANY, _("OpenCPN Alert"), wxDefaultPosition,
3049 wxSize(250, 230)) {
3050 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3051
3052 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
3053 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3054
3055 choices.push_back(
3056 new wxRadioButton(this, 0, _("No, I don't want to hide it."),
3057 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
3058
3059 choices.push_back(new wxRadioButton(
3060 this, 1, _("No, and permanently remove the option to hide it."),
3061 wxDefaultPosition));
3062
3063 choices.push_back(
3064 new wxRadioButton(this, 2, _("Yes, hide it."), wxDefaultPosition));
3065
3066 wxStdDialogButtonSizer *buttonSizer =
3067 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
3068
3069 wxStaticText *textCtrl =
3070 new wxStaticText(this, wxID_ANY,
3071 _("The Man Over Board button could be an important "
3072 "safety feature.\nAre you sure you want to hide it?"));
3073
3074 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
3075 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
3076 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
3077 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
3078 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
3079
3080 topSizer->SetSizeHints(this);
3081 SetSizer(topSizer);
3082}
3083
3084int ToolbarMOBDialog::GetSelection() {
3085 for (unsigned int i = 0; i < choices.size(); i++) {
3086 if (choices[i]->GetValue()) return choices[i]->GetId();
3087 }
3088 return 0;
3089}
3090
3091IMPLEMENT_DYNAMIC_CLASS(ToolbarChoicesDialog, wxDialog)
3095BEGIN_EVENT_TABLE(ToolbarChoicesDialog, wxDialog)
3096END_EVENT_TABLE()
3097
3098
3103
3104ToolbarChoicesDialog::ToolbarChoicesDialog(wxWindow *parent, wxWindow *sponsor,
3105 wxWindowID id,
3106 const wxString &caption,
3107 const wxPoint &pos,
3108 const wxSize &size, long style) {
3109 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
3110 wxDialog::Create(parent, id, caption, pos, size, wstyle);
3111
3112 m_configMenu = NULL;
3113 m_ToolbarDialogAncestor = wxDynamicCast(sponsor, ocpnFloatingToolbarDialog);
3114 if (m_ToolbarDialogAncestor)
3115 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
3116
3118 GetSizer()->Fit(this);
3119
3120 RecalculateSize();
3121}
3122
3123ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
3124
3130 wxBoxSizer *itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
3131 SetSizer(itemBoxSizer1);
3132
3133 wxScrolledWindow *itemDialog1 = new wxScrolledWindow(
3134 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
3135 itemDialog1->SetScrollRate(2, 2);
3136
3137#ifdef __OCPN__ANDROID__
3138
3139 // Set Dialog Font by custom crafted Qt Stylesheet.
3140 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
3141
3142 wxString wqs = getFontQtStylesheet(qFont);
3143 wxCharBuffer sbuf = wqs.ToUTF8();
3144 QString qsb = QString(sbuf.data());
3145
3146 QString qsbq = getQtStyleSheet(); // basic scrollbars, etc
3147
3148 this->GetHandle()->setStyleSheet(qsb + qsbq); // Concatenated style sheets
3149
3150#endif
3151 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
3152
3153 wxBoxSizer *itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
3154 itemDialog1->SetSizer(itemBoxSizer2);
3155
3156 wxStaticBox *itemStaticBoxSizer3Static =
3157 new wxStaticBox(itemDialog1, wxID_ANY, _("Choose Toolbar Icons"));
3158 wxStaticBoxSizer *itemStaticBoxSizer3 =
3159 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
3160 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
3161
3162 int nitems = 0;
3163 int max_width = -1;
3164 if (m_configMenu) {
3165 nitems = m_configMenu->GetMenuItemCount();
3166
3167 cboxes.clear();
3168 for (int i = 0; i < nitems; i++) {
3169 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon) continue;
3170 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
3171
3172 wxString label = item->GetItemLabel();
3173 int l = label.Len();
3174 max_width = wxMax(max_width, l);
3175
3176 wxString windowName = _T("");
3177 if (item->GetId() == ID_MOB + 100) windowName = _T("MOBCheck");
3178
3179 wxCheckBox *cb =
3180 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
3181 wxDefaultSize, 0, wxDefaultValidator, windowName);
3182 // wxCheckBox *cb = new wxCheckBox(itemDialog1, -1, label);
3183 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
3184 cb->SetValue(item->IsChecked());
3185
3186 cboxes.push_back(cb);
3187 }
3188 }
3189
3190 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
3191 (nitems + 4) * GetCharHeight() * 2);
3192
3193 wxBoxSizer *itemBoxSizerBottom = new wxBoxSizer(wxHORIZONTAL);
3194 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
3195
3196 wxBoxSizer *itemBoxSizerAux = new wxBoxSizer(wxHORIZONTAL);
3197 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
3198
3199 wxBoxSizer *itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
3200 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
3201
3202 m_CancelButton =
3203 new wxButton(this, -1, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0);
3204 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3205
3206 m_OKButton =
3207 new wxButton(this, -1, _("OK"), wxDefaultPosition, wxDefaultSize, 0);
3208 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3209 m_OKButton->SetDefault();
3210
3211 m_CancelButton->Connect(
3212 wxEVT_COMMAND_BUTTON_CLICKED,
3213 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL, this);
3214 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
3215 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
3216 NULL, this);
3217
3218 SetColorScheme((ColorScheme)0);
3219}
3220
3221void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(this); }
3222
3223void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
3224 EndModal(wxID_CANCEL);
3225}
3226
3227void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
3228 unsigned int ncheck = 0;
3229
3230 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
3231 wxString new_toolbarConfig = toolbarConfigSave;
3232
3233 for (unsigned int i = 0; i < cboxes.size(); i++) {
3234 wxCheckBox *cb = cboxes[i];
3235 wxString cbName = cb->GetName(); // Special flag passed into checkbox ctor
3236 // to find the "MOB" item
3237 if (cbName.IsSameAs(_T("MOBCheck")) && !cb->IsChecked()) {
3238 // Ask if really want to disable MOB button
3239 ToolbarMOBDialog mdlg(this);
3240 int dialog_ret = mdlg.ShowModal();
3241 int answer = mdlg.GetSelection();
3242 if (dialog_ret == wxID_OK) {
3243 if (answer == 1) {
3244 g_bPermanentMOBIcon = true;
3245 cb->SetValue(true);
3246 } else if (answer == 0) {
3247 cb->SetValue(true);
3248 }
3249 } else { // wxID_CANCEL
3250 new_toolbarConfig = toolbarConfigSave;
3251 return;
3252 }
3253 }
3254 if (m_configMenu) {
3255 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
3256 if (new_toolbarConfig.Len() > i) {
3257 new_toolbarConfig.SetChar(i, cb->IsChecked() ? _T('X') : _T('.'));
3258 } else {
3259 new_toolbarConfig.Append(cb->IsChecked() ? _T('X') : _T('.'));
3260 }
3261 item->Check(cb->IsChecked());
3262 if (cb->IsChecked()) ncheck++;
3263 }
3264 }
3265
3266#if 0
3267 // We always must have one Tool enabled. Make it the Options tool....
3268 if( 0 == ncheck){
3269 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN , _T('X') );
3270
3271 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
3272
3273 if(m_configMenu){
3274 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
3275 if(item)
3276 item->Check( true );
3277 }
3278 }
3279#endif
3280 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
3281
3282 EndModal(wxID_OK);
3283}
3284
3285void ToolbarChoicesDialog::RecalculateSize(void) {
3286 wxSize esize = GetSize();
3287
3288 if (GetParent()) {
3289 wxSize dsize = GetParent()->GetClientSize();
3290 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
3291 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
3292 SetSize(esize);
3293 Centre();
3294
3295 } else {
3296 wxSize fsize = g_Platform->getDisplaySize();
3297 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
3298 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
3299 SetSize(fsize);
3300 CentreOnScreen();
3301#ifdef __OCPN__ANDROID__
3302 Move(GetPosition().x, 10);
3303#endif
3304 }
3305}
ToolbarChoicesDialog()
Constructors.
Definition: toolbar.cpp:3102
void OnMouseEvent(wxMouseEvent &event)
Definition: toolbar.cpp:2164