35#include "ocpn_types.h"
39#include "pluginmanager.h"
41#include "OCPNPlatform.h"
46#include "ocpn_frame.h"
48#ifdef __OCPN__ANDROID__
49#include "androidUTIL.h"
52extern bool g_bTransparentToolbar;
53extern bool g_bTransparentToolbarInOpenGLOK;
58extern bool g_bPermanentMOBIcon;
60extern bool g_bsmoothpanzoom;
62extern bool g_bmasterToolbarFull;
64extern wxString g_toolbarConfig;
65extern double g_plus_minus_zoom_factor;
66extern int g_maintoolbar_x;
67extern int g_maintoolbar_y;
73EVT_MOUSE_EVENTS(GrabberWin::MouseEvent)
74EVT_PAINT(GrabberWin::OnPaint)
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();
88 scaled_image.Scale(new_width, new_height, wxIMAGE_QUALITY_HIGH));
92 SetSize(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
93 SetMinSize(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
97 m_scale_factor = scale_factor;
103void GrabberWin::OnPaint(wxPaintEvent &event) {
106 wxColour back_color = GetGlobalColor(_T(
"GREY2"));
107 SetBackgroundColour(back_color);
110 dc.DrawBitmap(m_bitmap, 0, 0,
true);
113void GrabberWin::SetColorScheme(ColorScheme cs) {
114 wxColour back_color = GetGlobalColor(_T(
"GREY2"));
116 SetBackgroundColour(back_color);
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();
125 scaled_image.Scale(new_width, new_height, wxIMAGE_QUALITY_HIGH));
130void GrabberWin::MouseEvent(wxMouseEvent &event) {}
132 static wxPoint s_gspt;
135 event.GetPosition( &x, &y );
137 wxPoint spt = ClientToScreen( wxPoint( x, y ) );
138 if( event.LeftDown() ) {
144 if( event.LeftDown() ) {
148 if( event.LeftUp() ) {
149 if( HasCapture() ) ReleaseMouse();
155 if( event.RightDown() && m_ptoolbar->GetCanToggleOrientation()){
157 if(!m_ptoolbar->isSubmergedToGrabber()){
160 if( !m_ptoolbar->m_bnavgrabber ){
161 m_ptoolbar->m_bnavgrabber =
true;
162 m_ptoolbar->SetGrabber(_T(
"4WayMove") );
165 m_ptoolbar->m_bnavgrabber =
false;
166 m_ptoolbar->SetGrabber(_T(
"grabber_hi") );
174 if( event.Dragging() ) {
175 if(m_ptoolbar && m_ptoolbar->IsShown() ){
176 wxPoint par_pos_old = m_ptoolbar->GetPosition();
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;
182 m_ptoolbar->MoveDialogInScreenCoords( par_pos, par_pos_old );
190 if( event.LeftUp() ) {
192 if(m_ptoolbar->m_bnavgrabber){
194 m_ptoolbar->ToggleOrientation();
196 else if(!m_dragging){
197 if(m_ptoolbar->isSubmergedToGrabber()){
198 m_ptoolbar->SurfaceFromGrabber();
201 m_ptoolbar->SubmergeToGrabber();
208#ifndef __OCPN__ANDROID__
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) {
227 m_btooltip_hiviz =
false;
229 toolname = g_pi_manager->GetToolOwnerCommonName(
id);
230 if (toolname == _T(
"")) {
231 isPluginTool =
false;
237 pluginNormalIcon = bmpNormal;
238 pluginRolloverIcon = bmpRollover;
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) {
251 m_btooltip_hiviz =
false;
252 isPluginTool =
false;
254 m_bmpNormal = bmpNormal;
258 void SetSize(
const wxSize &size) {
263 wxCoord GetWidth()
const {
return m_width; }
265 wxCoord GetHeight()
const {
return m_height; }
267 wxString GetToolname() {
return toolname; }
269 void SetIconName(wxString name) { iconName = name; }
270 wxString GetIconName() {
return iconName; }
272 void SetTooltipHiviz(
bool enable) { m_btooltip_hiviz = enable; }
281 wxBitmap pluginNormalIcon;
282 wxBitmap pluginRolloverIcon;
283 const wxBitmap *pluginToggledIcon;
290 bool m_btooltip_hiviz;
292 wxString pluginNormalIconSVG;
293 wxString pluginRolloverIconSVG;
294 wxString pluginToggledIconSVG;
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)
315 long wstyle = wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_SHAPED |
316 wxFRAME_FLOAT_ON_PARENT | wxFRAME_TOOL_WINDOW;
320 wxFrame::Create(parent, -1, _T(
""), wxPoint(-1, -1), wxSize(-1, -1), wstyle);
326 m_bGrabberEnable =
true;
328 m_pRecoverwin = NULL;
329 m_position = position;
331 m_sizefactor = size_factor;
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;
344 m_ptoolbar = CreateNewToolbar();
346 m_cs = (ColorScheme)-1;
348 m_style = g_StyleManager->GetCurrentStyle();
349 SetULDockPosition(wxPoint(4, 4));
351 SetGeometry(
false, wxRect());
354 m_topSizer =
new wxBoxSizer(wxHORIZONTAL);
355 SetSizer(m_topSizer);
362 m_marginsInvisible = m_style->marginsInvisible;
367 m_bnavgrabber =
false;
369 m_FloatingToolbarConfigMenu = NULL;
373 m_bsubmerged =
false;
374 m_bsubmergedToGrabber =
false;
376 m_fade_timer.SetOwner(
this, FADE_TIMER);
377 if (g_bTransparentToolbar) m_fade_timer.Start(5000);
379 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
380 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
382 m_destroyTimer.SetOwner(
this, DESTROY_TIMER);
384 m_benableSubmerge =
true;
387ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
388 delete m_FloatingToolbarConfigMenu;
394 m_Items.push_back(item);
397int ocpnFloatingToolbarDialog::RebuildToolbar() {
404 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
408 bool bEnabled = _toolbarConfigMenuUtil(tic);
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);
418 if (!tic->m_NormalIconSVG.IsEmpty()) {
419 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
420 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
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;
435size_t ocpnFloatingToolbarDialog::GetToolCount() {
437 return m_ptoolbar->GetToolsCount();
442void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
444void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
445 if (m_ptoolbar) m_ptoolbar->SetToolShowCount(count);
448int ocpnFloatingToolbarDialog::GetToolShowCount(
void) {
450 return m_ptoolbar->GetToolShowCount();
455void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
456 m_backcolorString = colorRef;
457 SetColorScheme(m_cs);
460void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
462void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
464void ocpnFloatingToolbarDialog::CreateConfigMenu() {
465 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
466 m_FloatingToolbarConfigMenu =
new wxMenu();
469bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
471 if (m_FloatingToolbarConfigMenu) {
472 wxMenuItem *menuitem;
474 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
476 if (tic->m_bRequired)
return true;
477 if (tic->m_bPlugin)
return true;
484 int menuItemId = tic->m_ID + idOffset;
486 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
489 return menuitem->IsChecked();
492 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
494 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
495 menuitem->Check(m_configString.Len() >= n
496 ? m_configString.GetChar(n - 1) == _T(
'X')
498 return menuitem->IsChecked();
503void ocpnFloatingToolbarDialog::OnWindowCreate(wxWindowCreateEvent &event) {
509void ocpnFloatingToolbarDialog::SetGrabber(wxString icon_name) {
511 m_pGrabberwin =
new GrabberWin(
this,
this, m_sizefactor, icon_name);
512 m_pGrabberwin->Hide();
517 m_pGrabberwin->Refresh();
521void ocpnFloatingToolbarDialog::UpdateRecoveryWindow(
bool b_toolbarEnable) {
523 if (b_toolbarEnable) {
524 m_pRecoverwin->Raise();
525 m_pRecoverwin->Refresh(
false);
527 m_pRecoverwin->Hide();
531void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
532 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
535void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
538 wxColour back_color = GetGlobalColor(m_backcolorString);
541 SetBackgroundColour(back_color);
546 m_ptoolbar->SetBackgroundColour(back_color);
547 m_ptoolbar->ClearBackground();
549 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T(
"GREY1")));
551 m_ptoolbar->SetColorScheme(cs);
552 m_ptoolbar->Refresh(
true);
556 m_pGrabberwin->SetColorScheme(cs);
557 m_pGrabberwin->Refresh();
563wxSize ocpnFloatingToolbarDialog::GetToolSize() {
564 wxSize style_tool_size;
566 style_tool_size = m_style->GetToolSize();
568 style_tool_size.x *= m_sizefactor;
569 style_tool_size.y *= m_sizefactor;
571 style_tool_size.x = 32;
572 style_tool_size.y = 32;
575 return style_tool_size;
578void ocpnFloatingToolbarDialog::SetGeometry(
bool bAvoid, wxRect rectAvoid) {
580 wxSize style_tool_size = m_style->GetToolSize();
582 style_tool_size.x *= m_sizefactor;
583 style_tool_size.y *= m_sizefactor;
585 m_ptoolbar->SetToolBitmapSize(style_tool_size);
587 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
588 int grabber_width = m_style->GetIcon(_T(
"grabber")).GetWidth();
595 GetParent()->GetClientSize().x -
596 (tool_size.x + m_style->GetToolSeparation()) * 2;
597 if (bAvoid && !rectAvoid.IsEmpty()) {
598 avoid_start = GetParent()->GetClientSize().x - rectAvoid.width -
602 max_rows = (GetParent()->GetClientSize().y /
603 (tool_size.y + m_style->GetToolSeparation())) -
606 max_cols = (avoid_start - grabber_width) /
607 (tool_size.x + m_style->GetToolSeparation());
610 if (m_orient == wxTB_VERTICAL)
611 max_rows = wxMax(max_rows, 2);
613 max_cols = wxMax(max_cols, 2);
616 if (m_orient == wxTB_VERTICAL)
617 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
619 m_ptoolbar->SetMaxRowsCols(100, max_cols);
620 m_ptoolbar->SetSizeFactor(m_sizefactor);
624void ocpnFloatingToolbarDialog::GetFrameRelativePosition(
int *x,
int *y) {
625 wxPoint myPos = GetPosition();
627 wxPoint relPos = gFrame->GetPrimaryCanvas()->ScreenToClient(myPos);
628 if (x) *x = relPos.x;
629 if (y) *y = relPos.y;
632void ocpnFloatingToolbarDialog::RestoreRelativePosition(
int x,
int y) {
633 if ((x < 0) || (y < 0)) {
634 SetDefaultPosition();
638 wxPoint screenPos = gFrame->GetPrimaryCanvas()->ClientToScreen(wxPoint(x, y));
639 Move(wxPoint(screenPos));
642void ocpnFloatingToolbarDialog::SetDefaultPosition() {
645 if (m_pparent && m_ptoolbar) {
646 wxSize cs = m_pparent->GetClientSize();
648 m_position.x = m_dock_min_x;
649 else if (1 == m_dock_x)
650 m_position.x = cs.x - GetSize().x;
653 m_position.y = m_dock_min_y;
654 else if (1 == m_dock_y)
655 m_position.y = cs.y - GetSize().y;
657 m_position.x = wxMin(cs.x - GetSize().x, m_position.x);
658 m_position.y = wxMin(cs.y - GetSize().y, m_position.y);
660 m_position.x = wxMax(m_dock_min_x, m_position.x);
661 m_position.y = wxMax(m_dock_min_y, m_position.y);
663 m_position.y += m_auxOffsetY;
665 g_maintoolbar_x = m_position.x;
666 g_maintoolbar_y = m_position.y;
672 wxPoint screen_pos = gFrame->GetPrimaryCanvas()->ClientToScreen(m_position);
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;
700void ocpnFloatingToolbarDialog::Submerge() {
703 if (m_ptoolbar) m_ptoolbar->KillTooltip();
706void ocpnFloatingToolbarDialog::SubmergeToGrabber() {
707 if (!m_benableSubmerge)
return;
711 m_bsubmergedToGrabber =
true;
713 if (m_ptoolbar) m_ptoolbar->KillTooltip();
715 if (!m_pRecoverwin) {
716 wxPoint tbPoint = GetPosition();
717 wxPoint tbPosInCanvas = m_pparent->ScreenToClient(tbPoint);
719 m_pRecoverwin =
new GrabberWin(m_pparent,
this, m_sizefactor,
720 _T(
"grabber_ext" ), tbPosInCanvas);
723 m_pRecoverwin->Show();
724 m_pRecoverwin->Raise();
726 wxSize s = gFrame->GetSize();
736void ocpnFloatingToolbarDialog::Surface() {
739 m_pRecoverwin->Show();
740 m_pRecoverwin->Raise();
742 m_bsubmerged =
false;
748 RestoreRelativePosition(g_maintoolbar_x, g_maintoolbar_y);
750 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
757 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
758 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
762bool ocpnFloatingToolbarDialog::CheckSurfaceRequest(wxMouseEvent &event) {
766void ocpnFloatingToolbarDialog::SurfaceFromGrabber() {}
768void ocpnFloatingToolbarDialog::DestroyTimerEvent(wxTimerEvent &event) {
769 delete m_destroyGrabber;
770 m_destroyGrabber = NULL;
773bool ocpnFloatingToolbarDialog::isSubmergedToGrabber() {
774 return (m_bsubmergedToGrabber);
777void ocpnFloatingToolbarDialog::HideTooltip() {
778#ifndef __OCPN__ANDROID__
779 if (m_ptoolbar) m_ptoolbar->HideTooltip();
783void ocpnFloatingToolbarDialog::ShowTooltips() {
784#ifndef __OCPN__ANDROID__
785 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
789void ocpnFloatingToolbarDialog::ToggleOrientation() {}
791void ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
792 if (g_bTransparentToolbar) {
793 if (event.Entering() && (m_opacity < 255)) {
798 m_fade_timer.Start(5000);
801 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
802 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
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);
819 m_fade_timer.Start(5000);
821 if (g_bTransparentToolbar &&
822 (!g_bopengl || g_bTransparentToolbarInOpenGLOK)) {
824 m_fade_timer.Start(5000);
827 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) && !m_bsubmerged) {
834void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
835 m_nAutoHideToolbar = time;
836 if (m_bAutoHideToolbar) {
838 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
842void ocpnFloatingToolbarDialog::DoFade(
int value) {
843 if (value != m_opacity) SetTransparent(value);
847void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
850 m_fade_timer.Start(500);
852 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
853 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
857void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
858 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
861void ocpnFloatingToolbarDialog::MoveDialogInScreenCoords(wxPoint posn,
863 wxPoint pos_in_parent = m_pparent->ScreenToClient(posn);
864 wxPoint pos_in_parent_old = m_pparent->ScreenToClient(posn_old);
867#define DOCK_MARGIN 40
871 if (pos_in_parent.x < pos_in_parent_old.x)
873 if (pos_in_parent.x < DOCK_MARGIN) {
874 pos_in_parent.x = m_dock_min_x;
877 }
else if (pos_in_parent.x > pos_in_parent_old.x)
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;
888 if (pos_in_parent.y < pos_in_parent_old.y)
890 if (pos_in_parent.y < DOCK_MARGIN) {
894 }
else if (pos_in_parent.y > pos_in_parent_old.y)
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;
903 m_position = pos_in_parent;
905 wxPoint final_pos = m_pparent->ClientToScreen(pos_in_parent);
910void ocpnFloatingToolbarDialog::Realize() {
912 m_ptoolbar->Realize();
915 m_topSizer->Add(m_ptoolbar);
917 if (m_bGrabberEnable) {
918 if (!m_pGrabberwin) {
920 new GrabberWin(
this,
this, m_sizefactor, _T(
"grabber_hi"));
921 m_pGrabberwin->Hide();
924 m_pGrabberwin->Show();
925 m_topSizer->Add(m_pGrabberwin, 0, wxTOP, m_style->GetTopMargin());
928 m_topSizer->Layout();
932 if (m_position.x == 0)
934 else if (m_position.x == m_pparent->GetClientSize().x - GetSize().x)
937 if (m_position.y == 0)
939 else if (m_position.y == m_pparent->GetClientSize().y - GetSize().y)
944 if (m_marginsInvisible) {
945 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
949 bool b_overlap =
false;
951 wxToolBarToolsList::compatibility_iterator node1 =
952 m_ptoolbar->m_tools.GetFirst();
954 wxToolBarToolsList::compatibility_iterator node2 = node1->GetNext();
956 wxToolBarToolBase *tool1 = node1->GetData();
959 wxToolBarToolBase *tool2 = node2->GetData();
962 if ((tools1->m_x + tools1->m_width) >= tools2->m_x) b_overlap =
true;
966 int toolCount = m_ptoolbar->GetVisibleToolCount();
968 wxPoint upperLeft(m_style->GetLeftMargin(), m_style->GetTopMargin());
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();
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();
988 wxBitmap shape(visibleSize.x + tool_size.x,
989 visibleSize.y + tool_size.y);
990 wxMemoryDC sdc(shape);
991 sdc.SetBackground(*wxWHITE_BRUSH);
992 sdc.SetBrush(*wxBLACK_BRUSH);
993 sdc.SetPen(*wxBLACK_PEN);
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);
1007 emptySpace * (tool_size.y + m_style->GetToolSeparation());
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());
1018 sdc.DrawRoundedRectangle(upperLeft, barsize,
1019 m_style->GetToolbarCornerRadius());
1020 upperLeft.x += m_style->GetTopMargin() + tool_size.x;
1022 wxSize barsize(visibleSize.x, tool_size.y);
1025 barsize.x += m_style->GetIcon(_T(
"grabber")).GetWidth();
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);
1033 emptySpace * (tool_size.x + m_style->GetToolSeparation());
1036 sdc.DrawRoundedRectangle(upperLeft, barsize,
1037 m_style->GetToolbarCornerRadius());
1038 upperLeft.y += m_style->GetTopMargin() + tool_size.y;
1043 for (wxToolBarToolsList::compatibility_iterator node =
1044 m_ptoolbar->m_tools.GetFirst();
1045 node; node = node->GetNext()) {
1046 wxToolBarToolBase *tool = node->GetData();
1049 sdc.DrawRoundedRectangle(tools->m_x, tools->m_y, tool_size.x,
1051 m_style->GetToolbarCornerRadius());
1056 if (shape.GetWidth() && shape.GetHeight())
1057 SetShape(wxRegion(shape, *wxWHITE, 10));
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);
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));
1078void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
1082 m_pparent->GetEventHandler()->AddPendingEvent(event);
1090 m_ptoolbar = CreateNewToolbar();
1097 long winstyle = wxNO_BORDER | wxTB_FLAT;
1098 winstyle |= m_orient;
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());
1112void ocpnFloatingToolbarDialog::DestroyToolBar() {
1113 g_toolbarConfig = GetToolConfigString();
1116 m_ptoolbar->ClearTools();
1121 if (!m_destroyTimer.IsRunning()) {
1122 m_destroyGrabber = m_pRecoverwin;
1123 m_pRecoverwin = NULL;
1124 m_destroyTimer.Start(
1125 5, wxTIMER_ONE_SHOT);
1135extern bool g_bAllowShowScaled;
1136extern bool g_bTrackActive;
1137extern s52plib *ps52plib;
1150 pCompass = parentCanvas->GetCompass();
1153 SetGeometry(pCompass->IsShown(), pCompass->GetRect());
1155 SetGeometry(
false, wxRect(0,0,1,1));
1160 wxToolBarToolBase* newtool;
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 );
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 );
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 );
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 );
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 );
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 );
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 );
1210 CheckAndAddPlugInTool( tb );
1213 gs = ps52plib->GetShowS57Text();
1216 tipString = wxString( _(
"Hide ENC text") ) << _T(
" (T)");
1218 tipString = wxString( _(
"Show ENC text") ) << _T(
" (T)");
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 );
1225 m_pTBAISTool = NULL;
1226 CheckAndAddPlugInTool( tb );
1227 tipString = _(
"Hide AIS Targets");
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
1282 AddDefaultPositionPlugInTools( tb );
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 );
1297 if( parentCanvas ) {
1299 tb->ToggleTool( ID_CURRENT, parentCanvas->GetbShowCurrent() );
1300 tb->ToggleTool( ID_TIDE, parentCanvas->GetbShowTide() );
1301 tb->ToggleTool( ID_FOLLOW, parentCanvas->m_bFollow );
1305 if( ps52plib->m_bOK )
1306 tb->ToggleTool( ID_ENC_TEXT, ps52plib->GetShowS57Text() );
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") );
1315 tb->SetToolShortHelp( ID_AIS, _(
"Hide AIS Targets") );
1318 tb->SetToolShortHelp( ID_AIS, _(
"Hide AIS Targets") );
1319 initiconName = _T(
"AIS");
1322 tb->SetToolShortHelp( ID_AIS, _(
"Show AIS Targets") );
1323 initiconName = _T(
"AIS_Disabled");
1325 tb->SetToolNormalBitmapEx( m_pTBAISTool, initiconName );
1326 m_tblastAISiconName = initiconName;
1328 tb->ToggleTool( ID_TRACK, g_bTrackActive );
1331 ArrayOfPlugInToolbarTools tool_array = g_pi_manager->GetPluginToolbarToolArray();
1332 for(
unsigned int i = 0; i < tool_array.GetCount(); i++ ) {
1337 if( pttc->kind == wxITEM_CHECK )
1338 tb->ToggleTool( pttc->id, pttc->b_toggle );
1349 if (!g_pi_manager)
return false;
1358 }
else if (!parentCanvas->IsPrimaryCanvas())
1363 int n_tools = tb->GetToolsCount();
1367 ArrayOfPlugInToolbarTools tool_array =
1368 g_pi_manager->GetPluginToolbarToolArray();
1370 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1372 if (pttc->position == n_tools) {
1373 wxBitmap *ptool_bmp;
1376 case GLOBAL_COLOR_SCHEME_DAY:
1377 ptool_bmp = pttc->bitmap_day;
1380 case GLOBAL_COLOR_SCHEME_DUSK:
1381 ptool_bmp = pttc->bitmap_dusk;
1383 case GLOBAL_COLOR_SCHEME_NIGHT:
1384 ptool_bmp = pttc->bitmap_night;
1387 ptool_bmp = pttc->bitmap_day;
1392 wxToolBarToolBase *tool =
1393 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
1394 wxString(pttc->shortHelp), pttc->kind);
1396 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
1397 pttc->pluginRolloverIconSVG,
1398 pttc->pluginToggledIconSVG);
1407 while (CheckAndAddPlugInTool(tb)) {
1413bool ocpnFloatingToolbarDialog::AddDefaultPositionPlugInTools(
1422 if (!parentCanvas->IsPrimaryCanvas())
return false;
1425 if (!g_pi_manager)
return false;
1431 ArrayOfPlugInToolbarTools tool_array =
1432 g_pi_manager->GetPluginToolbarToolArray();
1434 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1438 if (!pttc->b_viz)
continue;
1440 if (pttc->position == -1)
1442 wxBitmap *ptool_bmp;
1445 case GLOBAL_COLOR_SCHEME_DAY:
1446 ptool_bmp = pttc->bitmap_day;
1448 case GLOBAL_COLOR_SCHEME_DUSK:
1449 ptool_bmp = pttc->bitmap_dusk;
1451 case GLOBAL_COLOR_SCHEME_NIGHT:
1452 ptool_bmp = pttc->bitmap_night;
1455 ptool_bmp = pttc->bitmap_day;
1459 wxToolBarToolBase *tool =
1460 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
1461 wxString(pttc->shortHelp), pttc->kind);
1463 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
1464 pttc->pluginRolloverIconSVG,
1465 pttc->pluginToggledIconSVG);
1473void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
1474 m_enableRolloverBitmaps = bEnable;
1475 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
1486 void OnPaint(wxPaintEvent &event);
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);
1493 void SetHiviz(
bool hiviz) { m_hiviz = hiviz; }
1495 wxSize GetRenderedSize(
void);
1502 wxColour m_back_color;
1503 wxColour m_text_color;
1507 DECLARE_EVENT_TABLE()
1515EVT_PAINT(ToolTipWin::OnPaint)
1521 : wxFrame(parent, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(1, 1),
1522 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR) {
1525 m_back_color = GetGlobalColor(_T (
"UIBCK" ));
1526 m_text_color = GetGlobalColor(_T (
"UITX1" ));
1528 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1529 SetBackgroundColour(m_back_color);
1530 m_cs = GLOBAL_COLOR_SCHEME_RGB;
1535ToolTipWin::~ToolTipWin() {
delete m_pbm; }
1537void ToolTipWin::SetColorScheme(ColorScheme cs) {
1538 m_back_color = GetGlobalColor(_T (
"UIBCK" ));
1539 m_text_color = GetGlobalColor(_T (
"UITX1" ));
1542 m_text_color = FontMgr::Get().GetFontColor(_(
"ToolTips"));
1544 if (m_text_color == *wxBLACK) m_text_color = GetGlobalColor(_T (
"UITX1" ));
1550wxSize ToolTipWin::GetRenderedSize(
void) {
1556 wxFont *plabelFont = FontMgr::Get().GetFont(_(
"ToolTips"));
1557 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, plabelFont);
1565void ToolTipWin::SetBitmap() {
1569 double scaler = g_Platform->GetDisplayDIPMult(
this);
1571 wxFont *plabelFont = FontMgr::Get().GetFont(_(
"ToolTips"));
1572 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
1574 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, &sFont);
1576 m_size.x = w + GetCharWidth() * 2;
1577 m_size.y = h + GetCharHeight() / 2;
1585 m_pbm =
new wxBitmap(m_size.x, m_size.y, -1);
1586 mdc.SelectObject(*m_pbm);
1588 wxPen pborder(m_text_color);
1589 wxBrush bback(m_back_color);
1590 mdc.SetPen(pborder);
1591 mdc.SetBrush(bback);
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);
1600 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
1604 mdc.SetTextForeground(m_text_color);
1605 mdc.SetTextBackground(m_back_color);
1607 int offx = GetCharWidth();
1608 int offy = GetCharHeight()/4;
1611 mdc.DrawText(m_string, offx, offy);
1613 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
1616void ToolTipWin::OnPaint(wxPaintEvent &event) {
1618 GetClientSize(&width, &height);
1621 if (m_string.Len()) {
1623 mdc.SelectObject(*m_pbm);
1624 dc.Blit(0, 0, width, height, &mdc, 0, 0);
1630EVT_SIZE(ocpnToolBarSimple::OnSize)
1631EVT_PAINT(ocpnToolBarSimple::OnPaint)
1632EVT_KILL_FOCUS(ocpnToolBarSimple::OnKillFocus)
1634EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
1635EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
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);
1655 wxString testToolname = g_pi_manager->GetToolOwnerCommonName(
id);
1657 if (testToolname == _T(
"")) {
1659 clientData, shortHelp, longHelp);
1661 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
1662 clientData, shortHelp, longHelp);
1671void ocpnToolBarSimple::Init() {
1672 m_currentRowsOrColumns = 0;
1674 m_lastX = m_lastY = 0;
1676 m_maxWidth = m_maxHeight = 0;
1678 m_pressedTool = m_currentTool = -1;
1680 m_xPos = m_yPos = wxDefaultCoord;
1682 m_style = g_StyleManager->GetCurrentStyle();
1684 m_defaultWidth = 16;
1685 m_defaultHeight = 15;
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;
1692 m_btoolbar_is_zooming =
false;
1693 m_sizefactor = 1.0f;
1695 m_last_plugin_down_id = -1;
1698 m_btooltip_show =
false;
1699#ifndef __OCPN__ANDROID__
1702 m_tbenableRolloverBitmaps =
false;
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,
1714 InvalidateBestSize();
1715 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
1716 shortHelp, longHelp, clientData);
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();
1727 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
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()"));
1739 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
1740 clientData, shortHelp, longHelp);
1742 if (!InsertTool(pos, tool)) {
1751wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
1752 wxToolBarToolBase *tool) {
1753 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1754 _T(
"invalid position in wxToolBar::InsertTool()"));
1756 if (!tool || !DoInsertTool(pos, tool)) {
1760 m_tools.Insert(pos, tool);
1766bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
1767 wxToolBarToolBase *toolBase) {
1773 if (tool->isPluginTool) {
1774 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
1775 if (tool->GetToolname() ==
1777 tool->toolname << _T(
"1");
1783 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
1786 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
1788 if (tool->IsButton()) {
1789 tool->SetSize(GetToolSize());
1792 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
1793 m_style->GetLeftMargin()) > m_maxWidth)
1795 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
1797 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
1798 m_style->GetTopMargin()) > m_maxHeight)
1800 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
1803 else if (tool->IsControl()) {
1804 tool->SetSize(tool->GetControl()->GetSize());
1807 tool->b_hilite =
false;
1812bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
1813 wxToolBarToolBase *tool) {
1817 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
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;
1830 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
1832 if (GetWindowStyleFlag() & wxTB_VERTICAL) {
1846 SetCursor(*wxSTANDARD_CURSOR);
1848 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
1849 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
1850 m_tooltip_off = 3000;
1852 m_tbenableRolloverBitmaps =
false;
1857ocpnToolBarSimple::~ocpnToolBarSimple() {
1858 if (m_pToolTipWin) {
1859 m_pToolTipWin->Destroy();
1860 m_pToolTipWin = NULL;
1864void ocpnToolBarSimple::EnableTooltips() {
1865#ifndef __OCPN__ANDROID__
1866 m_btooltip_show =
true;
1870void ocpnToolBarSimple::DisableTooltips() {
1871#ifndef __OCPN__ANDROID__
1872 ocpnToolBarSimple::m_btooltip_show =
false;
1876void ocpnToolBarSimple::KillTooltip() {
1877 m_btooltip_show =
false;
1879 if (m_pToolTipWin) {
1880 m_pToolTipWin->Hide();
1881 m_pToolTipWin->Destroy();
1882 m_pToolTipWin = NULL;
1884 m_tooltip_timer.Stop();
1916 gFrame->GetFocusCanvas()->TriggerDeferredFocus();
1919void ocpnToolBarSimple::HideTooltip() {
1920#ifndef __OCPN__ANDROID__
1921 if (m_pToolTipWin) {
1922 m_pToolTipWin->Hide();
1927void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1928#ifndef __OCPN__ANDROID__
1929 if (m_pToolTipWin) {
1930 m_pToolTipWin->Destroy();
1931 m_pToolTipWin = NULL;
1934 m_toolOutlineColour = GetGlobalColor(_T(
"UIBDR"));
1936 m_currentColorScheme = cs;
1939bool ocpnToolBarSimple::Realize() {
1941 m_style->SetOrientation(wxTB_VERTICAL);
1943 m_style->SetOrientation(wxTB_HORIZONTAL);
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;
1950 m_currentRowsOrColumns = 0;
1952 m_lastX = leftMargin;
1953 m_lastY = topMargin;
1958 bool firstNode =
true;
1959 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1964 if (iNode >= m_nShowTools)
break;
1970 if (toolSize.x == -1) {
1971 if (!tool->IsSeparator()) {
1972 toolSize.x = tool->m_width;
1973 toolSize.y = tool->m_height;
1977 tool->firstInLine = firstNode;
1978 tool->lastInLine =
false;
1981 tool->last_rect.width = 0;
1983 if (tool->IsSeparator()) {
1984 if (GetWindowStyleFlag() & wxTB_HORIZONTAL) {
1985 if (m_currentRowsOrColumns >= m_maxCols)
1986 m_lastY += separatorSize;
1988 m_lastX += separatorSize;
1990 if (m_currentRowsOrColumns >= m_maxRows)
1991 m_lastX += separatorSize;
1993 m_lastY += separatorSize;
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;
2001 m_currentRowsOrColumns = 0;
2002 m_lastX = leftMargin;
2003 m_lastY += toolSize.y + topMargin;
2005 tool->m_x = (wxCoord)m_lastX;
2006 tool->m_y = (wxCoord)m_lastY;
2008 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
2009 tool->trect.Inflate(separatorSize / 2, topMargin);
2011 m_lastX += toolSize.x + separatorSize;
2013 if (m_currentRowsOrColumns >= m_maxRows) {
2014 tool->firstInLine =
true;
2015 if (lastTool) lastTool->lastInLine =
true;
2017 m_currentRowsOrColumns = 0;
2018 m_lastX += toolSize.x + leftMargin;
2019 m_lastY = topMargin;
2021 tool->m_x = (wxCoord)m_lastX;
2022 tool->m_y = (wxCoord)m_lastY;
2024 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
2025 tool->trect.Inflate((separatorSize / 2), topMargin);
2027 m_lastY += toolSize.y + separatorSize;
2029 m_currentRowsOrColumns++;
2030 }
else if (tool->IsControl()) {
2031 tool->m_x = (wxCoord)(m_lastX);
2032 tool->m_y = (wxCoord)(m_lastY - (topMargin / 2));
2035 wxRect(tool->m_x, tool->m_y, tool->GetWidth(), tool->GetHeight());
2036 tool->trect.Inflate(separatorSize / 2, topMargin);
2038 wxSize s = tool->GetControl()->GetSize();
2039 m_lastX += s.x + separatorSize;
2042 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
2043 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
2046 node = node->GetNext();
2049 if (lastTool && (m_LineCount > 1 || IsVertical()))
2050 lastTool->lastInLine =
true;
2052 if (GetWindowStyleFlag() & wxTB_HORIZONTAL) {
2053 m_maxHeight += toolSize.y;
2054 m_maxHeight += m_style->GetBottomMargin();
2056 m_maxWidth += toolSize.x;
2057 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
2060 SetSize(m_maxWidth, m_maxHeight);
2061 SetMinSize(wxSize(m_maxWidth, m_maxHeight));
2070void ocpnToolBarSimple::OnPaint(wxPaintEvent &WXUNUSED(event)) {
2074 wxRegion ru = GetUpdateRegion();
2075 wxRect upRect = ru.GetBox();
2077 static int count = 0;
2079 if (count > 0)
return;
2082 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2083 node; node = node->GetNext()) {
2084 wxToolBarToolBase *tool = node->GetData();
2086 wxRect toolRect = tools->trect;
2088 if (toolRect.Intersects(upRect)) {
2089 if (tool->IsButton()) {
2091 }
else if (tool->IsControl()) {
2092 if (tool->GetControl()->IsKindOf(CLASSINFO(wxStaticBitmap))) {
2093 wxStaticBitmap *psbm = (wxStaticBitmap *)tool->GetControl();
2095 dc.DrawBitmap(psbm->GetBitmap(), toolsimp->m_x, toolsimp->m_y,
false);
2104void ocpnToolBarSimple::OnSize(wxSizeEvent &WXUNUSED(event)) {
2108void ocpnToolBarSimple::OnKillFocus(wxFocusEvent &WXUNUSED(event)) {
2109 OnMouseEnter(m_pressedTool = m_currentTool = -1);
2112void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
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();
2126 m_pToolTipWin->SetString(s);
2127 m_pToolTipWin->SetHiviz(m_last_ro_tool->m_btooltip_hiviz);
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;
2132 m_pToolTipWin->Move(
2135 wxPoint screenPosition = ClientToScreen(pos_in_toolbar);
2136 wxPoint framePosition = gFrame->ScreenToClient(screenPosition);
2137 wxSize tipSize = m_pToolTipWin->GetRenderedSize();
2139 if ((framePosition.x + tipSize.x) > gFrame->GetSize().x)
2140 screenPosition.x -= (tipSize.x + m_last_ro_tool->m_width + 4);
2142 m_pToolTipWin->SetPosition(screenPosition);
2143 m_pToolTipWin->SetBitmap();
2144 m_pToolTipWin->Show();
2149#ifndef __OCPN__ANDROID__
2150 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
2157void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
2161int s_dragx, s_dragy;
2165#ifdef __OCPN__ANDROID__
2166 if (!event.IsButton())
return;
2170 event.GetPosition(&x, &y);
2173#ifndef __OCPN__ANDROID__
2174 if (event.LeftDown()) {
2179 if (event.LeftUp()) {
2184 static wxPoint s_pos_m_old;
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;
2193 if (!g_btouch && event.Dragging()) {
2195 wxPoint pos_old = GetScreenPosition();
2196 wxPoint pos_new = pos_old;
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)) {
2205 pos_new.x += pos_m.x - s_pos_m_old.x;
2206 pos_new.y += pos_m.y - s_pos_m_old.y;
2211 parentFloatingToolBar->MoveDialogInScreenCoords(pos_new, pos_old);
2215 parent->GetFrameRelativePosition(&g_maintoolbar_x, &g_maintoolbar_y);
2216 s_pos_m_old = pos_m;
2220 if (event.LeftUp() && s_drag) {
2226 if (tool && tool->IsButton() && IsShown()) {
2227 if (m_btooltip_show) {
2229 if (NULL == m_pToolTipWin) {
2231 m_pToolTipWin->SetColorScheme(m_currentColorScheme);
2232 m_pToolTipWin->Hide();
2235 if (tool != m_last_ro_tool) {
2236 m_pToolTipWin->Hide();
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);
2248 if (!g_btouch && m_tbenableRolloverBitmaps) {
2249 if (tool != m_last_ro_tool) {
2250 if (tool->IsEnabled()) {
2251 tool->rollover =
true;
2253 if (m_last_ro_tool) {
2254 if (m_last_ro_tool->IsEnabled()) {
2255 m_last_ro_tool->rollover =
false;
2258 tool->bitmapOK =
false;
2259 m_last_ro_tool = tool;
2266 if (m_pToolTipWin && m_pToolTipWin->IsShown()) {
2267 m_pToolTipWin->Hide();
2269 m_btooltip_show =
true;
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;
2282 m_last_ro_tool = tool;
2285 if (g_bsmoothpanzoom && !g_btouch) {
2289 if (parent) pcc = wxDynamicCast(parent->GetParent(),
ChartCanvas);
2291 if (event.LeftUp() && m_btoolbar_is_zooming) {
2293 pcc->StopMovement();
2294 m_btoolbar_is_zooming =
false;
2299 if (event.LeftDown() && tool &&
2300 (tool->GetId() == ID_ZOOMIN || tool->GetId() == ID_ZOOMOUT)) {
2302 pcc->ZoomCanvas(tool->GetId() == ID_ZOOMIN
2303 ? g_plus_minus_zoom_factor
2304 : 1.0 / g_plus_minus_zoom_factor,
2306 m_btoolbar_is_zooming =
true;
2313 if (m_currentTool > -1) {
2314 if (event.LeftIsDown()) SpringUpButton(m_currentTool);
2319 wxMouseEvent *pev = (wxMouseEvent *)event.Clone();
2320 GetParent()->GetEventHandler()->AddPendingEvent(*pev);
2326 if (!event.IsButton()) {
2327 if (tool->GetId() != m_currentTool) {
2330 if (event.LeftIsDown() && tool->IsEnabled()) {
2331 SpringUpButton(m_currentTool);
2333 if (tool->CanBeToggled()) {
2340 m_currentTool = tool->GetId();
2341 OnMouseEnter(m_currentTool);
2344 wxMouseEvent *pev = (wxMouseEvent *)event.Clone();
2345 GetParent()->GetEventHandler()->AddPendingEvent(*pev);
2352 if (event.LeftIsDown()) m_leftDown =
true;
2354 if (event.LeftDown() && tool->IsEnabled()) {
2355 if (tool->CanBeToggled()) {
2357 tool->bitmapOK =
false;
2365 ArrayOfPlugInToolbarTools tool_array =
2366 g_pi_manager->GetPluginToolbarToolArray();
2367 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
2369 if (tool->GetId() == pttc->id) {
2373 ppi->OnToolbarToolDownCallback(pttc->id);
2374 m_last_plugin_down_id = pttc->id;
2379 }
else if (event.RightDown()) {
2380 OnRightClick(tool->GetId(), x, y);
2393 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
2395 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
2396 tool->CanBeToggled()) {
2400 tool->bitmapOK =
false;
2407 wxMouseEvent *pev = (wxMouseEvent *)event.Clone();
2408 GetParent()->GetEventHandler()->AddPendingEvent(*pev);
2417void ocpnToolBarSimple::DrawTool(wxToolBarToolBase *tool) {
2418 wxClientDC dc(
this);
2425void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
2429 wxPoint drawAt(tool->m_x, tool->m_y);
2430 wxBitmap bmp = wxNullBitmap;
2432 bool bNeedClear = !tool->bitmapOK;
2434 if (tool->bitmapOK) {
2435 if (tool->IsEnabled()) {
2436 bmp = tool->GetNormalBitmap();
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;
2445 bmp = tool->GetDisabledBitmap();
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;
2454 if (tool->isPluginTool) {
2455 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
2462 wxString svgFile = tool->pluginNormalIconSVG;
2464 if (tool->pluginToggledIconSVG.Length())
2465 svgFile = tool->pluginToggledIconSVG;
2467 if (tool->rollover) {
2468 if (tool->pluginRolloverIconSVG.Length())
2469 svgFile = tool->pluginRolloverIconSVG;
2472 if (!svgFile.IsEmpty()) {
2474 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
2476 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
2479 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
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,
2493 if (tool->rollover) {
2495 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
2498 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
2501 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
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));
2512 tool->SetNormalBitmap(bmp);
2513 tool->bitmapOK =
true;
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,
2523 tool->SetNormalBitmap(bmp);
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,
2534 tool->SetNormalBitmap(bmp);
2539 tool->bitmapOK =
true;
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;
2549 if (tool->firstInLine) {
2550 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
2552 if (tool->lastInLine) {
2553 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
2556 if (bmp.GetWidth() != m_style->GetToolSize().x ||
2557 bmp.GetHeight() != m_style->GetToolSize().y) {
2563 if ((tool->last_rect.width &&
2564 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
2566 wxBrush bb(GetGlobalColor(_T(
"GREY3")));
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);
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);
2582 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
2585 dc.DrawBitmap(bmp, drawAt);
2587 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
2595wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
2597 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2600 if ((x >= tool->m_x) && (y >= tool->m_y) &&
2601 (x < (tool->m_x + tool->GetWidth())) &&
2602 (y < (tool->m_y + tool->GetHeight()))) {
2606 node = node->GetNext();
2609 return (wxToolBarToolBase *)NULL;
2612void ocpnToolBarSimple::InvalidateBitmaps() {
2613 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2616 tool->bitmapOK =
false;
2617 node = node->GetNext();
2621wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
2623 wxToolBarToolBase *tool = FindById(tool_id);
2626 if (otool) rect = otool->trect;
2636void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
2637 bool WXUNUSED(enable)) {
2639 t->bitmapOK =
false;
2643void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
2644 bool WXUNUSED(toggle)) {
2646 t->bitmapOK =
false;
2653void ocpnToolBarSimple::SpringUpButton(
int id) {
2654 wxToolBarToolBase *tool = FindById(
id);
2656 if (tool && tool->CanBeToggled()) {
2657 if (tool->IsToggled()) tool->Toggle();
2667wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
2668 wxToolBarToolBase *tool = FindById(
id);
2669 wxCHECK_MSG(tool, wxEmptyString, _T(
"no such tool"));
2671 return tool->GetShortHelp();
2674wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
2675 wxToolBarToolBase *tool = FindById(
id);
2676 wxCHECK_MSG(tool, wxEmptyString, _T(
"no such tool"));
2678 return tool->GetLongHelp();
2681void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
2682 wxToolBarToolBase *tool = FindById(
id);
2684 (void)tool->SetShortHelp(help);
2688void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
2689 wxToolBarToolBase *tool = FindById(
id);
2691 (void)tool->SetLongHelp(help);
2695int ocpnToolBarSimple::GetToolPos(
int id)
const {
2697 wxToolBarToolsList::compatibility_iterator node;
2699 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2700 if (node->GetData()->GetId() ==
id)
return pos;
2707bool ocpnToolBarSimple::GetToolState(
int id)
const {
2708 wxToolBarToolBase *tool = FindById(
id);
2709 wxCHECK_MSG(tool,
false, _T(
"no such tool"));
2711 return tool->IsToggled();
2714bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
2715 wxToolBarToolBase *tool = FindById(
id);
2716 wxCHECK_MSG(tool,
false, _T(
"no such tool"));
2718 return tool->IsEnabled();
2721void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
2722 wxToolBarToolBase *tool = FindById(
id);
2724 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
2725 DoToggleTool(tool, toggle);
2730wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
2731 wxToolBarToolBase *tool = FindById(
id);
2732 return tool ? tool->GetClientData() : (wxObject *)NULL;
2735void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
2736 wxToolBarToolBase *tool = FindById(
id);
2738 wxCHECK_RET(tool, _T(
"no such tool in wxToolBar::SetToolClientData"));
2740 tool->SetClientData(clientData);
2743void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
2744 wxToolBarToolBase *tool = FindById(
id);
2746 if (tool->Enable(enable)) {
2747 DoEnableTool(tool, enable);
2753 if (parent && parent->m_FloatingToolbarConfigMenu) {
2754 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
2755 if (configItem) configItem->Check(
true);
2759void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
2762 tool->SetTooltipHiviz(b_hiviz);
2766void ocpnToolBarSimple::ClearTools() {
2767 while (GetToolsCount()) {
2772int ocpnToolBarSimple::GetVisibleToolCount() {
2774 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2778 node = node->GetNext();
2783bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
2784 wxCHECK_MSG(pos < GetToolsCount(),
false,
2785 _T(
"invalid position in wxToolBar::DeleteToolByPos()"));
2787 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
2789 if (!DoDeleteTool(pos, node->GetData())) {
2793 delete node->GetData();
2794 m_tools.Erase(node);
2799bool ocpnToolBarSimple::DeleteTool(
int id) {
2801 wxToolBarToolsList::compatibility_iterator node;
2802 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2803 if (node->GetData()->GetId() ==
id)
break;
2808 if (!node || !DoDeleteTool(pos, node->GetData())) {
2812 delete node->GetData();
2813 m_tools.Erase(node);
2818wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
2819 return InsertSeparator(GetToolsCount());
2822wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
2823 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
2824 _T(
"invalid position in wxToolBar::InsertSeparator()"));
2826 wxToolBarToolBase *tool = CreateTool(
2827 wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap,
2828 wxITEM_SEPARATOR, (wxObject *)NULL, wxEmptyString, wxEmptyString);
2830 if (!tool || !DoInsertTool(pos, tool)) {
2836 m_tools.Insert(pos, tool);
2842wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
2844 wxToolBarToolsList::compatibility_iterator node;
2845 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2846 if (node->GetData()->GetId() ==
id)
break;
2854 return (wxToolBarToolBase *)NULL;
2857 wxToolBarToolBase *tool = node->GetData();
2858 if (!DoDeleteTool(pos, tool)) {
2859 return (wxToolBarToolBase *)NULL;
2862 m_tools.Erase(node);
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();
2875 wxFAIL_MSG(_T(
"NULL control in toolbar?"));
2876 }
else if (control->GetId() ==
id) {
2886wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
2887 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
2889 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2890 node; node = node->GetNext()) {
2891 tool = node->GetData();
2892 if (tool->GetId() == id) {
2908bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
2909 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
2910 event.SetEventObject(
this);
2913 event.SetInt((
int)toggleDown);
2916 event.SetExtraLong((
long)toggleDown);
2919 GetEventHandler()->ProcessEvent(event);
2925void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
2932 if (parent->m_FloatingToolbarConfigMenu) {
2935 wxDefaultPosition, wxSize(100, 100));
2936 int rc = dlg->ShowModal();
2939 if (rc == wxID_OK) {
2940 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
2941 event.SetEventObject(
this);
2944 gFrame->GetEventHandler()->AddPendingEvent(event);
2955void ocpnToolBarSimple::OnMouseEnter(
int id) {
2956 wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId());
2957 event.SetEventObject(
this);
2960 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
2963 wxToolBarToolBase *tool =
2964 id == wxID_ANY ? (wxToolBarToolBase *)NULL : FindById(
id);
2965 if (tool) help = tool->GetLongHelp();
2966 frame->DoGiveHelp(help,
id != wxID_ANY);
2969 (void)GetEventHandler()->ProcessEvent(event);
2974void ocpnToolBarSimple::DoPluginToolUp() {
2977 if (!g_pi_manager)
return;
2979 ArrayOfPlugInToolbarTools tool_array =
2980 g_pi_manager->GetPluginToolbarToolArray();
2981 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
2983 if (m_last_plugin_down_id == pttc->id) {
2986 if (ppi) ppi->OnToolbarToolUpCallback(pttc->id);
2990 m_last_plugin_down_id = -1;
2993void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2994 const wxString &iconName) {
3000 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
3001 otool->m_width, otool->m_height);
3002 tool->SetNormalBitmap(bmp);
3003 otool->SetIconName(iconName);
3008void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
3013 otool->pluginNormalIconSVG = fileSVG;
3018void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
3019 wxBitmap *bmpRollover) {
3022 if (tool->isPluginTool) {
3023 tool->pluginNormalIcon = *bmp;
3024 tool->pluginRolloverIcon = *bmpRollover;
3025 tool->bitmapOK =
false;
3027 tool->SetNormalBitmap(*bmp);
3028 tool->bitmapOK =
true;
3033void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
3034 wxString fileSVGRollover,
3035 wxString fileSVGToggled) {
3038 tool->pluginNormalIconSVG = fileSVGNormal;
3039 tool->pluginRolloverIconSVG = fileSVGRollover;
3040 tool->pluginToggledIconSVG = fileSVGToggled;
3041 tool->bitmapOK =
false;
3047ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
3048 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
3050 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
3052 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
3053 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
3056 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
3057 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
3059 choices.push_back(
new wxRadioButton(
3060 this, 1, _(
"No, and permanently remove the option to hide it."),
3061 wxDefaultPosition));
3064 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
3066 wxStdDialogButtonSizer *buttonSizer =
3067 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
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?"));
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);
3080 topSizer->SetSizeHints(
this);
3084int ToolbarMOBDialog::GetSelection() {
3085 for (
unsigned int i = 0; i < choices.size(); i++) {
3086 if (choices[i]->GetValue())
return choices[i]->GetId();
3106 const wxString &caption,
3108 const wxSize &size,
long style) {
3109 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
3110 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
3112 m_configMenu = NULL;
3114 if (m_ToolbarDialogAncestor)
3115 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
3118 GetSizer()->Fit(
this);
3123ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
3130 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
3131 SetSizer(itemBoxSizer1);
3133 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
3134 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
3135 itemDialog1->SetScrollRate(2, 2);
3137#ifdef __OCPN__ANDROID__
3140 wxFont *qFont = GetOCPNScaledFont(_(
"Dialog"));
3142 wxString wqs = getFontQtStylesheet(qFont);
3143 wxCharBuffer sbuf = wqs.ToUTF8();
3144 QString qsb = QString(sbuf.data());
3146 QString qsbq = getQtStyleSheet();
3148 this->GetHandle()->setStyleSheet(qsb + qsbq);
3151 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
3153 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
3154 itemDialog1->SetSizer(itemBoxSizer2);
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);
3165 nitems = m_configMenu->GetMenuItemCount();
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);
3172 wxString label = item->GetItemLabel();
3173 int l = label.Len();
3174 max_width = wxMax(max_width, l);
3176 wxString windowName = _T(
"");
3177 if (item->GetId() == ID_MOB + 100) windowName = _T(
"MOBCheck");
3180 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
3181 wxDefaultSize, 0, wxDefaultValidator, windowName);
3183 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
3184 cb->SetValue(item->IsChecked());
3186 cboxes.push_back(cb);
3190 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
3191 (nitems + 4) * GetCharHeight() * 2);
3193 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
3194 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
3196 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
3197 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
3199 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
3200 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
3203 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
3204 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3207 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
3208 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3209 m_OKButton->SetDefault();
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),
3218 SetColorScheme((ColorScheme)0);
3221void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
3223void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
3224 EndModal(wxID_CANCEL);
3227void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
3228 unsigned int ncheck = 0;
3230 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
3231 wxString new_toolbarConfig = toolbarConfigSave;
3233 for (
unsigned int i = 0; i < cboxes.size(); i++) {
3234 wxCheckBox *cb = cboxes[i];
3235 wxString cbName = cb->GetName();
3237 if (cbName.IsSameAs(_T(
"MOBCheck")) && !cb->IsChecked()) {
3240 int dialog_ret = mdlg.ShowModal();
3241 int answer = mdlg.GetSelection();
3242 if (dialog_ret == wxID_OK) {
3244 g_bPermanentMOBIcon =
true;
3246 }
else if (answer == 0) {
3250 new_toolbarConfig = toolbarConfigSave;
3255 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
3256 if (new_toolbarConfig.Len() > i) {
3257 new_toolbarConfig.SetChar(i, cb->IsChecked() ? _T(
'X') : _T(
'.'));
3259 new_toolbarConfig.Append(cb->IsChecked() ? _T(
'X') : _T(
'.'));
3261 item->Check(cb->IsChecked());
3262 if (cb->IsChecked()) ncheck++;
3269 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN , _T(
'X') );
3271 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
3274 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
3276 item->Check(
true );
3280 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
3285void ToolbarChoicesDialog::RecalculateSize(
void) {
3286 wxSize esize = GetSize();
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()));
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()));
3301#ifdef __OCPN__ANDROID__
3302 Move(GetPosition().x, 10);