26 #include <wx/wxprec.h>
36 #include "model/ocpn_types.h"
40 #include "pluginmanager.h"
42 #include "OCPNPlatform.h"
45 #include "svg_utils.h"
46 #include "model/idents.h"
47 #include "ocpn_frame.h"
49 #ifdef __OCPN__ANDROID__
50 #include "androidUTIL.h"
54 #include "glChartCanvas.h"
57 extern bool g_bTransparentToolbar;
58 extern bool g_bTransparentToolbarInOpenGLOK;
59 extern bool g_bopengl;
63 extern bool g_bPermanentMOBIcon;
64 extern bool g_bsmoothpanzoom;
66 extern bool g_bmasterToolbarFull;
68 extern wxString g_toolbarConfig;
69 extern double g_plus_minus_zoom_factor;
70 extern int g_maintoolbar_x;
71 extern int g_maintoolbar_y;
74 extern GLenum g_texture_rectangle_format;
81 const wxBitmap &bmpNormal,
const wxBitmap &bmpRollover,
82 wxItemKind kind, wxObject *clientData,
83 const wxString &shortHelp,
const wxString &longHelp)
84 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, label, bmpNormal,
85 bmpRollover, kind, clientData, shortHelp, longHelp) {
90 m_btooltip_hiviz =
false;
92 toolname = g_pi_manager->GetToolOwnerCommonName(
id);
93 if (toolname == _T(
"")) {
100 pluginNormalIcon = bmpNormal;
101 pluginRolloverIcon = bmpRollover;
106 const wxBitmap &bmpRollover, wxItemKind kind,
107 wxObject *clientData,
const wxString &shortHelp,
108 const wxString &longHelp)
109 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, _T(
""), bmpNormal,
110 bmpRollover, kind, clientData, shortHelp, longHelp) {
114 m_btooltip_hiviz =
false;
115 isPluginTool =
false;
117 m_bmpNormal = bmpNormal;
121 void SetSize(
const wxSize &size) {
126 wxCoord GetWidth()
const {
return m_width; }
128 wxCoord GetHeight()
const {
return m_height; }
130 wxString GetToolname() {
return toolname; }
132 void SetIconName(wxString name) { iconName = name; }
133 wxString GetIconName() {
return iconName; }
135 void SetTooltipHiviz(
bool enable) { m_btooltip_hiviz = enable; }
144 wxBitmap pluginNormalIcon;
145 wxBitmap pluginRolloverIcon;
146 const wxBitmap *pluginToggledIcon;
153 bool m_btooltip_hiviz;
155 wxString pluginNormalIconSVG;
156 wxString pluginRolloverIconSVG;
157 wxString pluginToggledIconSVG;
158 wxBitmap m_activeBitmap;
165 ocpnFloatingToolbarDialog::ocpnFloatingToolbarDialog(wxWindow *parent,
173 m_position = position;
175 m_sizefactor = size_factor;
178 m_bAutoHideToolbar =
false;
179 m_nAutoHideToolbar = 5;
180 m_toolbar_scale_tools_shown =
false;
181 m_backcolorString = _T(
"GREY3");
182 m_toolShowMask = _T(
"XXXXXXXXXXXXXXXX");
183 n_toolbarHideMethod = TOOLBAR_HIDE_TO_GRABBER;
184 b_canToggleOrientation =
true;
185 m_enableRolloverBitmaps =
true;
188 m_ptoolbar = CreateNewToolbar();
190 m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"GREY3"));
191 m_cs = (ColorScheme)-1;
193 m_style = g_StyleManager->GetCurrentStyle();
194 SetULDockPosition(wxPoint(4, 4));
196 SetGeometry(
false, wxRect());
205 m_marginsInvisible = m_style->marginsInvisible;
208 m_FloatingToolbarConfigMenu = NULL;
210 m_fade_timer.SetOwner(
this);
211 this->Connect( wxEVT_TIMER, wxTimerEventHandler( ocpnFloatingToolbarDialog::FadeTimerEvent ), NULL,
this );
213 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
214 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
216 m_bsubmerged =
false;
217 m_benableSubmerge =
true;
220 ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
221 delete m_FloatingToolbarConfigMenu;
226 void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
227 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
228 if (g_bmasterToolbarFull) {
229 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) ) {
232 wxPoint mp = gFrame->GetPrimaryCanvas()->ScreenToClient(::wxGetMousePosition());
234 wxRect r = GetToolbarRect();
238 wxCommandEvent event;
239 event.SetId(ID_MASTERTOGGLE);
240 gFrame->OnToolLeftClick(event);
247 m_Items.push_back(item);
250 int ocpnFloatingToolbarDialog::RebuildToolbar() {
257 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
261 bool bEnabled = _toolbarConfigMenuUtil(tic);
264 wxToolBarToolBase *tool =
265 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
266 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
271 if (!tic->m_NormalIconSVG.IsEmpty()) {
272 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
273 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
283 void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
284 if (position.x >= 0) m_dock_min_x = position.x;
285 if (position.y >= 0) m_dock_min_y = position.y;
288 size_t ocpnFloatingToolbarDialog::GetToolCount() {
290 return m_ptoolbar->GetToolsCount();
295 void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
297 void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
299 m_ptoolbar->SetToolShowCount(count);
300 m_ptoolbar->SetDirty(
true);
304 int ocpnFloatingToolbarDialog::GetToolShowCount(
void) {
306 return m_ptoolbar->GetToolShowCount();
311 void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
312 m_backcolorString = colorRef;
313 SetColorScheme(m_cs);
316 void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
318 void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
320 void ocpnFloatingToolbarDialog::CreateConfigMenu() {
321 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
322 m_FloatingToolbarConfigMenu =
new wxMenu();
325 bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
327 if (m_FloatingToolbarConfigMenu) {
328 wxMenuItem *menuitem;
330 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
332 if (tic->m_bRequired)
return true;
333 if (tic->m_bPlugin)
return true;
340 int menuItemId = tic->m_ID + idOffset;
342 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
345 return menuitem->IsChecked();
348 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
350 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
351 menuitem->Check(m_configString.Len() >= n
352 ? m_configString.GetChar(n - 1) == _T(
'X')
354 return menuitem->IsChecked();
360 void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
361 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
364 void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
366 wxColour back_color = GetGlobalColor(m_backcolorString);
369 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T(
"GREY1")));
370 m_ptoolbar->SetColorScheme(cs);
374 wxSize ocpnFloatingToolbarDialog::GetToolSize() {
375 wxSize style_tool_size;
377 style_tool_size = m_style->GetToolSize();
379 style_tool_size.x *= m_sizefactor;
380 style_tool_size.y *= m_sizefactor;
382 style_tool_size.x = 32;
383 style_tool_size.y = 32;
386 return style_tool_size;
389 void ocpnFloatingToolbarDialog::SetGeometry(
bool bAvoid, wxRect rectAvoid) {
391 wxSize style_tool_size = m_style->GetToolSize();
393 style_tool_size.x *= m_sizefactor;
394 style_tool_size.y *= m_sizefactor;
396 m_ptoolbar->SetToolBitmapSize(style_tool_size);
398 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
399 int grabber_width = m_style->GetIcon(_T(
"grabber")).GetWidth();
406 m_pparent->GetClientSize().x -
407 (tool_size.x + m_style->GetToolSeparation()) * 2;
408 if (bAvoid && !rectAvoid.IsEmpty()) {
409 avoid_start = m_pparent->GetClientSize().x - rectAvoid.width -
413 max_rows = (m_pparent->GetClientSize().y /
414 (tool_size.y + m_style->GetToolSeparation())) -
417 max_cols = (avoid_start - grabber_width) /
418 (tool_size.x + m_style->GetToolSeparation());
421 if (m_orient == wxTB_VERTICAL)
422 max_rows = wxMax(max_rows, 2);
424 max_cols = wxMax(max_cols, 2);
427 if (m_orient == wxTB_VERTICAL)
428 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
430 m_ptoolbar->SetMaxRowsCols(100, max_cols);
431 m_ptoolbar->SetSizeFactor(m_sizefactor);
436 void ocpnFloatingToolbarDialog::SetDefaultPosition() {
439 if (m_pparent && m_ptoolbar) {
440 wxSize cs = m_pparent->GetClientSize();
442 m_position.x = m_dock_min_x;
443 else if (1 == m_dock_x)
444 m_position.x = cs.x - m_ptoolbar->m_maxWidth;
447 m_position.y = m_dock_min_y;
448 else if (1 == m_dock_y)
449 m_position.y = cs.y - m_ptoolbar->m_maxHeight;
451 m_position.x = wxMin(cs.x - m_ptoolbar->m_maxWidth, m_position.x);
452 m_position.y = wxMin(cs.y - m_ptoolbar->m_maxHeight, m_position.y);
454 m_position.x = wxMax(m_dock_min_x, m_position.x);
455 m_position.y = wxMax(m_dock_min_y, m_position.y);
457 m_position.y += m_auxOffsetY;
459 g_maintoolbar_x = m_position.x;
460 g_maintoolbar_y = m_position.y;
481 void ocpnFloatingToolbarDialog::Submerge() {
484 if (m_ptoolbar) m_ptoolbar->KillTooltip();
489 void ocpnFloatingToolbarDialog::HideTooltip() {
490 #ifndef __OCPN__ANDROID__
491 if (m_ptoolbar) m_ptoolbar->HideTooltip();
495 void ocpnFloatingToolbarDialog::ShowTooltips() {
496 #ifndef __OCPN__ANDROID__
497 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
501 void ocpnFloatingToolbarDialog::ToggleOrientation() {}
503 wxRect ocpnFloatingToolbarDialog::GetToolbarRect() {
504 return wxRect(m_position.x, m_position.y,
505 m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
508 wxSize ocpnFloatingToolbarDialog::GetToolbarSize() {
509 return wxSize(m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
512 wxPoint ocpnFloatingToolbarDialog::GetToolbarPosition() {
513 return wxPoint(m_position.x, m_position.y);
516 bool ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
518 bool bproc = m_ptoolbar->OnMouseEvent(event, m_position);
520 m_ptoolbar->CreateBitmap();
527 void ocpnFloatingToolbarDialog::RefreshToolbar() {
529 if (m_ptoolbar->IsDirty()) {
531 gFrame->GetPrimaryCanvas()->Refresh();
537 void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
538 m_nAutoHideToolbar = time;
539 if (m_bAutoHideToolbar) {
541 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
545 void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
546 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
547 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
551 void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
552 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
556 void ocpnFloatingToolbarDialog::Realize() {
558 m_ptoolbar->Realize();
559 m_ptoolbar->CreateBitmap();
560 m_toolbar_image.Destroy();
564 void ocpnFloatingToolbarDialog::DrawDC(
ocpnDC &dc,
double displayScale) {
566 m_ptoolbar->CreateBitmap();
567 if (m_ptoolbar->GetBitmap().IsOk()) {
568 dc.DrawBitmap(m_ptoolbar->GetBitmap(), m_position.x, m_position.y,
false);
569 m_ptoolbar->SetDirty(
false);
574 void ocpnFloatingToolbarDialog::DrawGL(
ocpnDC &gldc,
double displayScale) {
579 wxColour backColor = GetGlobalColor(
"GREY3");
580 gldc.SetBrush(wxBrush(backColor));
581 gldc.SetPen(wxPen(backColor));
583 wxRect r = GetToolbarRect();
584 int m_end_margin = wxMin(GetToolSize().x, GetToolSize().y) / 8;
586 if (m_orient == wxHORIZONTAL)
587 gldc.DrawRoundedRectangle((r.x - m_end_margin/2)*displayScale,
588 (r.y-1)*displayScale,
589 (r.width + m_end_margin)*displayScale,
590 (r.height+2)*displayScale,
591 (m_end_margin * 1)*displayScale);
593 gldc.DrawRoundedRectangle((r.x-1)*displayScale,
594 (r.y- m_end_margin/2)*displayScale,
595 (r.width + 2)*displayScale,
596 (r.height + m_end_margin)*displayScale,
597 (m_end_margin * 1.5)*displayScale);
600 int width = GetToolbarSize().x;
601 int height = GetToolbarSize().y;
603 m_ptoolbar->CreateBitmap(displayScale);
607 glGenTextures(1, &m_texture);
609 glBindTexture(g_texture_rectangle_format, m_texture);
610 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
612 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
614 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
616 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
619 glBindTexture(g_texture_rectangle_format, m_texture);
622 if (!m_toolbar_image.IsOk()) {
624 m_toolbar_image = m_ptoolbar->GetBitmap().ConvertToImage();
626 unsigned char *d = m_toolbar_image.GetData();
627 unsigned char *e =
new unsigned char[4 * width * height];
628 for (
int y = 0; y < height; y++)
629 for (
int x = 0; x < width; x++) {
630 int i = y * width + x;
631 memcpy(e + 4 * i, d + 3 * i, 3);
634 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, width, height, 0,
635 GL_RGBA, GL_UNSIGNED_BYTE, e);
637 glDisable(g_texture_rectangle_format);
643 glEnable(g_texture_rectangle_format);
644 glBindTexture(g_texture_rectangle_format, m_texture);
647 int x0 = GetToolbarPosition().x, x1 = x0 + width;
648 int y0 = GetToolbarPosition().y - 0, y1 = y0 + height;
649 x0 *= displayScale; x1 *= displayScale;
650 y0 *= displayScale; y1 *= displayScale;
653 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
654 tx = width, ty = height;
681 auto canvas = gFrame->GetPrimaryCanvas();
682 canvas->GetglCanvas()->RenderTextures(gldc, coords, uv, 4,
685 glDisable(g_texture_rectangle_format);
686 glBindTexture(g_texture_rectangle_format, 0);
694 void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
698 m_pparent->GetEventHandler()->AddPendingEvent(event);
706 m_ptoolbar = CreateNewToolbar();
713 long winstyle = wxNO_BORDER | wxTB_FLAT;
714 winstyle |= m_orient;
721 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T(
"GREY1")));
722 m_ptoolbar->SetColorScheme(m_cs);
723 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
728 void ocpnFloatingToolbarDialog::DestroyToolBar() {
729 g_toolbarConfig = GetToolConfigString();
732 m_ptoolbar->ClearTools();
737 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
747 extern bool g_bTrackActive;
748 extern s52plib *ps52plib;
752 if (!g_pi_manager)
return false;
755 int n_tools = tb->GetToolsCount();
759 ArrayOfPlugInToolbarTools tool_array =
760 g_pi_manager->GetPluginToolbarToolArray();
762 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
764 if (pttc->position == n_tools) {
768 case GLOBAL_COLOR_SCHEME_DAY:
769 ptool_bmp = pttc->bitmap_day;
772 case GLOBAL_COLOR_SCHEME_DUSK:
773 ptool_bmp = pttc->bitmap_dusk;
775 case GLOBAL_COLOR_SCHEME_NIGHT:
776 ptool_bmp = pttc->bitmap_night;
779 ptool_bmp = pttc->bitmap_day;
784 wxToolBarToolBase *tool =
785 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
786 wxString(pttc->shortHelp), pttc->kind);
788 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
789 pttc->pluginRolloverIconSVG,
790 pttc->pluginToggledIconSVG);
799 while (CheckAndAddPlugInTool(tb)) {
806 void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
807 m_enableRolloverBitmaps = bEnable;
808 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
819 void OnPaint(wxPaintEvent &event);
821 void SetColorScheme(ColorScheme cs);
822 void SetString(wxString &s) { m_string = s; }
823 void SetPosition(wxPoint pt) { m_position = pt; }
824 void SetBitmap(
void);
826 void SetHiviz(
bool hiviz) { m_hiviz = hiviz; }
828 wxSize GetRenderedSize(
void);
835 wxColour m_back_color;
836 wxColour m_text_color;
840 DECLARE_EVENT_TABLE()
848 EVT_PAINT(ToolTipWin::OnPaint)
854 : wxFrame(parent, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(1, 1),
855 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR) {
858 m_back_color = GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
859 m_text_color = GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
861 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
862 SetBackgroundColour(m_back_color);
863 m_cs = GLOBAL_COLOR_SCHEME_RGB;
868 ToolTipWin::~ToolTipWin() {
delete m_pbm; }
870 void ToolTipWin::SetColorScheme(ColorScheme cs) {
871 m_back_color = GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
872 m_text_color = GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
875 m_text_color = GetDimedColor(FontMgr::Get().GetFontColor(_(
"ToolTips")));
881 wxSize ToolTipWin::GetRenderedSize(
void) {
887 wxFont *plabelFont = FontMgr::Get().GetFont(_(
"ToolTips"));
888 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, plabelFont);
896 void ToolTipWin::SetBitmap() {
900 double scaler = g_Platform->GetDisplayDIPMult(
this);
902 wxFont *plabelFont = FontMgr::Get().GetFont(_(
"ToolTips"));
903 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
905 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, &sFont);
907 m_size.x = w + GetCharWidth() * 2;
908 m_size.y = h + GetCharHeight() / 2;
916 m_pbm =
new wxBitmap(m_size.x, m_size.y, -1);
917 mdc.SelectObject(*m_pbm);
919 wxPen pborder(m_text_color);
920 wxBrush bback(m_back_color);
925 if ((m_cs == GLOBAL_COLOR_SCHEME_DUSK) ||
926 (m_cs == GLOBAL_COLOR_SCHEME_NIGHT)) {
927 wxBrush hv_back(wxColour(200, 200, 200));
928 mdc.SetBrush(hv_back);
931 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
935 mdc.SetTextForeground(m_text_color);
936 mdc.SetTextBackground(m_back_color);
938 int offx = GetCharWidth();
939 int offy = GetCharHeight()/4;
942 mdc.DrawText(m_string, offx, offy);
944 SetClientSize(m_size.x, m_size.y);
945 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
948 void ToolTipWin::OnPaint(wxPaintEvent &event) {
950 GetClientSize(&width, &height);
953 if (m_string.Len()) {
955 mdc.SelectObject(*m_pbm);
956 dc.Blit(0, 0, width, height, &mdc, 0, 0);
967 EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
968 EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
976 int id, const wxString &label, const wxBitmap &bmpNormal,
977 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
978 const wxString &shortHelp, const wxString &longHelp) {
979 if (m_style->NativeToolIconExists(label)) {
980 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
981 clientData, shortHelp, longHelp);
983 wxString testToolname = g_pi_manager->GetToolOwnerCommonName(
id);
985 if (testToolname == _T(
"")) {
987 clientData, shortHelp, longHelp);
989 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
990 clientData, shortHelp, longHelp);
999 void ocpnToolBarSimple::Init() {
1000 m_currentRowsOrColumns = 0;
1002 m_lastX = m_lastY = 0;
1004 m_maxWidth = m_maxHeight = 0;
1006 m_pressedTool = m_currentTool = -1;
1008 m_xPos = m_yPos = wxDefaultCoord;
1010 m_style = g_StyleManager->GetCurrentStyle();
1012 m_defaultWidth = 16;
1013 m_defaultHeight = 15;
1015 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
1016 m_toolOutlineColour.Set(_T(
"BLACK"));
1017 m_pToolTipWin = NULL;
1018 m_last_ro_tool = NULL;
1020 m_btoolbar_is_zooming =
false;
1021 m_sizefactor = 1.0f;
1023 m_last_plugin_down_id = -1;
1026 m_btooltip_show =
false;
1027 #ifndef __OCPN__ANDROID__
1030 m_tbenableRolloverBitmaps =
false;
1033 wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
1034 int id,
const wxString &label,
const wxBitmap &bitmap,
1035 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1036 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
1043 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
1044 shortHelp, longHelp, clientData);
1049 wxToolBarToolBase *ocpnToolBarSimple::AddTool(
1050 int toolid,
const wxString &label,
const wxBitmap &bitmap,
1051 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1052 const wxString &longHelp, wxObject *data) {
1055 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
1060 wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
1061 size_t pos,
int id,
const wxString &label,
const wxBitmap &bitmap,
1062 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1063 const wxString &longHelp, wxObject *clientData) {
1064 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1065 _T(
"invalid position in wxToolBar::InsertTool()"));
1067 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
1068 clientData, shortHelp, longHelp);
1070 if (!InsertTool(pos, tool)) {
1079 wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
1080 wxToolBarToolBase *tool) {
1081 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1082 _T(
"invalid position in wxToolBar::InsertTool()"));
1084 if (!tool || !DoInsertTool(pos, tool)) {
1088 m_tools.Insert(pos, tool);
1094 bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
1095 wxToolBarToolBase *toolBase) {
1101 if (tool->isPluginTool) {
1102 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
1103 if (tool->GetToolname() ==
1105 tool->toolname << _T(
"1");
1111 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
1114 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
1116 if (tool->IsButton()) {
1117 tool->SetSize(GetToolSize());
1120 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
1121 m_style->GetLeftMargin()) > m_maxWidth)
1123 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
1125 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
1126 m_style->GetTopMargin()) > m_maxHeight)
1128 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
1131 else if (tool->IsControl()) {
1132 tool->SetSize(tool->GetControl()->GetSize());
1135 tool->b_hilite =
false;
1140 bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
1141 wxToolBarToolBase *tool) {
1145 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
1153 const wxPoint &pos,
const wxSize &size,
1154 long style,
int orient) {
1156 m_parentContainer = parent;
1175 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
1176 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
1177 m_tooltip_off = 3000;
1179 m_tbenableRolloverBitmaps =
false;
1184 ocpnToolBarSimple::~ocpnToolBarSimple() {
1185 if (m_pToolTipWin) {
1186 m_pToolTipWin->Destroy();
1187 m_pToolTipWin = NULL;
1191 void ocpnToolBarSimple::EnableTooltips() {
1192 #ifndef __OCPN__ANDROID__
1193 m_btooltip_show =
true;
1197 void ocpnToolBarSimple::DisableTooltips() {
1198 #ifndef __OCPN__ANDROID__
1199 ocpnToolBarSimple::m_btooltip_show =
false;
1203 void ocpnToolBarSimple::KillTooltip() {
1204 m_btooltip_show =
false;
1206 if (m_pToolTipWin) {
1207 m_pToolTipWin->Hide();
1208 m_pToolTipWin->Destroy();
1209 m_pToolTipWin = NULL;
1211 m_tooltip_timer.Stop();
1214 gFrame->GetFocusCanvas()->TriggerDeferredFocus();
1217 void ocpnToolBarSimple::HideTooltip() {
1218 #ifndef __OCPN__ANDROID__
1219 if (m_pToolTipWin) {
1220 m_pToolTipWin->Hide();
1225 void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1226 #ifndef __OCPN__ANDROID__
1227 if (m_pToolTipWin) {
1228 m_pToolTipWin->Destroy();
1229 m_pToolTipWin = NULL;
1232 m_toolOutlineColour = GetGlobalColor(_T(
"UIBDR"));
1234 m_currentColorScheme = cs;
1237 bool ocpnToolBarSimple::Realize() {
1239 m_style->SetOrientation(wxTB_VERTICAL);
1241 m_style->SetOrientation(wxTB_HORIZONTAL);
1243 wxSize toolSize = wxSize(-1, -1);
1244 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1245 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1246 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1248 m_currentRowsOrColumns = 0;
1250 m_lastX = leftMargin;
1251 m_lastY = topMargin;
1256 bool firstNode =
true;
1257 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1262 if (iNode >= m_nShowTools)
break;
1268 if (toolSize.x == -1) {
1269 if (!tool->IsSeparator()) {
1270 toolSize.x = tool->m_width;
1271 toolSize.y = tool->m_height;
1275 tool->firstInLine = firstNode;
1276 tool->lastInLine =
false;
1279 tool->last_rect.width = 0;
1281 if (tool->IsSeparator()) {
1290 if (m_currentRowsOrColumns >= m_maxRows)
1291 m_lastX += separatorSize;
1293 m_lastY += separatorSize;
1295 }
else if (tool->IsButton()) {
1296 if (!IsVertical()) {
1297 if (m_currentRowsOrColumns >= m_maxCols) {
1298 tool->firstInLine =
true;
1299 if (lastTool && m_LineCount > 1) lastTool->lastInLine =
true;
1301 m_currentRowsOrColumns = 0;
1302 m_lastX = leftMargin;
1303 m_lastY += toolSize.y + topMargin;
1305 tool->m_x = (wxCoord)m_lastX;
1306 tool->m_y = (wxCoord)m_lastY;
1308 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1309 tool->trect.Inflate(separatorSize / 2, topMargin);
1311 m_lastX += toolSize.x + separatorSize;
1313 if (m_currentRowsOrColumns >= m_maxRows) {
1314 tool->firstInLine =
true;
1315 if (lastTool) lastTool->lastInLine =
true;
1317 m_currentRowsOrColumns = 0;
1318 m_lastX += toolSize.x + leftMargin;
1319 m_lastY = topMargin;
1321 tool->m_x = (wxCoord)m_lastX;
1322 tool->m_y = (wxCoord)m_lastY;
1324 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1325 tool->trect.Inflate((separatorSize / 2), topMargin);
1327 m_lastY += toolSize.y + separatorSize;
1329 m_currentRowsOrColumns++;
1344 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
1345 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
1348 node = node->GetNext();
1351 if (lastTool && (m_LineCount > 1 || IsVertical()))
1352 lastTool->lastInLine =
true;
1354 if (!IsVertical()) {
1355 m_maxHeight += toolSize.y;
1356 m_maxHeight += m_style->GetBottomMargin();
1358 m_maxWidth += toolSize.x;
1359 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
1362 m_bitmap = wxNullBitmap;
1367 wxBitmap &ocpnToolBarSimple::CreateBitmap(
double display_scale) {
1368 if (m_bitmap.IsOk())
1372 int width = m_maxWidth;
1373 int height = m_maxHeight;
1376 wxBitmap bm(width, height);
1377 mdc.SelectObject(bm);
1378 mdc.SetBackground(wxBrush( GetBackgroundColour()));
1382 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1383 node; node = node->GetNext()) {
1384 wxToolBarToolBase *tool = node->GetData();
1386 wxRect toolRect = tools->trect;
1387 CreateToolBitmap(tool);
1389 if (tools->m_activeBitmap.IsOk()) {
1390 mdc.DrawBitmap(tools->m_activeBitmap, tools->m_x, tools->m_y,
false);
1395 mdc.SelectObject(wxNullBitmap);
1403 void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
1408 if (m_btooltip_show && m_pToolTipWin &&
1409 (!m_pToolTipWin->IsShown())) {
1410 if (m_last_ro_tool) {
1411 wxString s = m_last_ro_tool->GetShortHelp();
1414 m_pToolTipWin->SetString(s);
1415 m_pToolTipWin->SetHiviz(m_last_ro_tool->m_btooltip_hiviz);
1417 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
1418 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
1420 m_pToolTipWin->Move(
1423 wxPoint screenPosition = gFrame->GetPrimaryCanvas()->ClientToScreen(pos_in_toolbar);
1424 wxSize tipSize = m_pToolTipWin->GetRenderedSize();
1426 m_pToolTipWin->SetPosition(screenPosition);
1427 m_pToolTipWin->SetBitmap();
1428 m_pToolTipWin->Show();
1433 #ifndef __OCPN__ANDROID__
1434 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1441 void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
1446 bool ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event, wxPoint &position) {
1447 #ifdef __OCPN__ANDROID__
1448 if (!event.IsButton())
return false;
1452 event.GetPosition(&x, &y);
1455 wxRect r = wxRect(position, wxSize( m_maxWidth, m_maxHeight));
1456 if (!r.Contains(x,y)) {
1461 m_parentContainer->RefreshFadeTimer();
1466 m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1470 m_tooltipoff_timer.Stop();
1474 if (tool && tool->IsButton() ) {
1475 if (m_btooltip_show) {
1477 if (NULL == m_pToolTipWin) {
1479 m_pToolTipWin->SetColorScheme(m_currentColorScheme);
1480 m_pToolTipWin->Hide();
1483 if (tool != m_last_ro_tool) {
1484 m_pToolTipWin->Hide();
1487 #ifndef __OCPN__ANDROID__
1488 if (!m_pToolTipWin->IsShown()) {
1489 if (!m_tooltip_timer.IsRunning()) {
1490 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
1497 m_last_ro_tool = tool;
1500 if (event.LeftIsDown()) m_leftDown =
true;
1502 if (event.LeftDown() && tool->IsEnabled()) {
1503 if (tool->CanBeToggled()) {
1505 tool->bitmapOK =
false;
1507 m_bitmap = wxNullBitmap;
1513 ArrayOfPlugInToolbarTools tool_array =
1514 g_pi_manager->GetPluginToolbarToolArray();
1515 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1517 if (tool->GetId() == pttc->id) {
1521 ppi->OnToolbarToolDownCallback(pttc->id);
1522 m_last_plugin_down_id = pttc->id;
1527 }
else if (event.RightDown()) {
1528 OnRightClick(tool->GetId(), x, y);
1541 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
1543 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
1544 tool->CanBeToggled()) {
1548 tool->bitmapOK =
false;
1563 void ocpnToolBarSimple::CreateToolBitmap(wxToolBarToolBase *toolBase) {
1566 wxBitmap bmp = wxNullBitmap;
1568 bool bNeedClear = !tool->bitmapOK;
1570 if (tool->bitmapOK) {
1571 if (tool->IsEnabled()) {
1572 bmp = tool->GetNormalBitmap();
1575 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1576 tool->rollover, tool->m_width, tool->m_height);
1577 tool->SetNormalBitmap(bmp);
1578 tool->bitmapOK =
true;
1581 bmp = tool->GetDisabledBitmap();
1583 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1584 false, tool->m_width, tool->m_height);
1585 tool->SetDisabledBitmap(bmp);
1586 tool->bitmapOK =
true;
1590 if (tool->isPluginTool) {
1591 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1598 wxString svgFile = tool->pluginNormalIconSVG;
1600 if (tool->pluginToggledIconSVG.Length())
1601 svgFile = tool->pluginToggledIconSVG;
1603 if (tool->rollover) {
1604 if (tool->pluginRolloverIconSVG.Length())
1605 svgFile = tool->pluginRolloverIconSVG;
1608 if (!svgFile.IsEmpty()) {
1610 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
1612 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1615 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1619 if (!bmp.IsOk() || bmp.IsNull()) {
1620 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1621 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1622 tool->rollover, tool->m_width,
1630 bmp = tool->pluginNormalIcon;
1631 if (fabs(m_sizefactor - 1.0) > 0.01) {
1632 if (tool->m_width && tool->m_height) {
1633 wxImage scaled_image = bmp.ConvertToImage();
1634 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1635 wxIMAGE_QUALITY_HIGH));
1640 tool->SetNormalBitmap(bmp);
1641 tool->bitmapOK =
true;
1643 bmp = tool->GetNormalBitmap();
1644 if (tool->IsEnabled()) {
1645 if (tool->IsToggled()) {
1646 if (!tool->bitmapOK) {
1647 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1648 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1649 tool->rollover, tool->m_width,
1651 tool->SetNormalBitmap(bmp);
1657 if (!tool->bitmapOK) {
1658 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1659 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1660 tool->rollover, tool->m_width,
1662 tool->SetNormalBitmap(bmp);
1667 tool->bitmapOK =
true;
1669 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1670 false, tool->m_width, tool->m_height);
1671 tool->SetDisabledBitmap(bmp);
1672 tool->bitmapOK =
true;
1676 tool->m_activeBitmap = bmp;
1687 void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
1691 wxPoint drawAt(tool->m_x, tool->m_y);
1692 wxBitmap bmp = wxNullBitmap;
1694 bool bNeedClear = !tool->bitmapOK;
1696 if (tool->bitmapOK) {
1697 if (tool->IsEnabled()) {
1698 bmp = tool->GetNormalBitmap();
1701 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1702 tool->rollover, tool->m_width, tool->m_height);
1703 tool->SetNormalBitmap(bmp);
1704 tool->bitmapOK =
true;
1707 bmp = tool->GetDisabledBitmap();
1709 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1710 false, tool->m_width, tool->m_height);
1711 tool->SetDisabledBitmap(bmp);
1712 tool->bitmapOK =
true;
1716 if (tool->isPluginTool) {
1717 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1724 wxString svgFile = tool->pluginNormalIconSVG;
1726 if (tool->pluginToggledIconSVG.Length())
1727 svgFile = tool->pluginToggledIconSVG;
1729 if (tool->rollover) {
1730 if (tool->pluginRolloverIconSVG.Length())
1731 svgFile = tool->pluginRolloverIconSVG;
1734 if (!svgFile.IsEmpty()) {
1736 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
1738 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1741 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1745 if (!bmp.IsOk() || bmp.IsNull()) {
1746 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1747 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1748 tool->rollover, tool->m_width,
1755 if (tool->rollover) {
1757 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
1760 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1763 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1765 if (fabs(m_sizefactor - 1.0) > 0.01) {
1766 if (tool->m_width && tool->m_height) {
1767 wxImage scaled_image = bmp.ConvertToImage();
1768 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1769 wxIMAGE_QUALITY_HIGH));
1774 tool->SetNormalBitmap(bmp);
1775 tool->bitmapOK =
true;
1777 bmp = tool->GetNormalBitmap();
1778 if (tool->IsEnabled()) {
1779 if (tool->IsToggled()) {
1780 if (!tool->bitmapOK) {
1781 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1782 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1783 tool->rollover, tool->m_width,
1785 tool->SetNormalBitmap(bmp);
1791 if (!tool->bitmapOK) {
1792 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1793 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1794 tool->rollover, tool->m_width,
1796 tool->SetNormalBitmap(bmp);
1801 tool->bitmapOK =
true;
1803 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1804 false, tool->m_width, tool->m_height);
1805 tool->SetDisabledBitmap(bmp);
1806 tool->bitmapOK =
true;
1811 if (tool->firstInLine) {
1812 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
1814 if (tool->lastInLine) {
1815 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
1818 if (bmp.GetWidth() != m_style->GetToolSize().x ||
1819 bmp.GetHeight() != m_style->GetToolSize().y) {
1825 if ((tool->last_rect.width &&
1826 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
1828 wxBrush bb(GetGlobalColor(_T(
"GREY3")));
1830 dc.SetPen(*wxTRANSPARENT_PEN);
1831 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
1832 tool->last_rect.width, tool->last_rect.height);
1839 wxImage scaled_image = bmp.ConvertToImage();
1840 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1841 wxIMAGE_QUALITY_HIGH));
1842 dc.DrawBitmap(sbmp, drawAt);
1844 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
1847 dc.DrawBitmap(bmp, drawAt);
1849 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
1857 wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
1859 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1862 if ((x >= tool->m_x) && (y >= tool->m_y) &&
1863 (x < (tool->m_x + tool->GetWidth())) &&
1864 (y < (tool->m_y + tool->GetHeight()))) {
1868 node = node->GetNext();
1871 return (wxToolBarToolBase *)NULL;
1874 void ocpnToolBarSimple::InvalidateBitmaps() {
1875 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1878 tool->bitmapOK =
false;
1879 node = node->GetNext();
1881 m_bitmap = wxNullBitmap;
1884 wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
1886 wxToolBarToolBase *tool = FindById(tool_id);
1889 if (otool) rect = otool->trect;
1899 void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
1900 bool WXUNUSED(enable)) {
1902 t->bitmapOK =
false;
1905 void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
1906 bool WXUNUSED(toggle)) {
1908 t->bitmapOK =
false;
1917 wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
1918 wxToolBarToolBase *tool = FindById(
id);
1919 wxCHECK_MSG(tool, wxEmptyString, _T(
"no such tool"));
1921 return tool->GetShortHelp();
1924 wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
1925 wxToolBarToolBase *tool = FindById(
id);
1926 wxCHECK_MSG(tool, wxEmptyString, _T(
"no such tool"));
1928 return tool->GetLongHelp();
1931 void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
1932 wxToolBarToolBase *tool = FindById(
id);
1934 (void)tool->SetShortHelp(help);
1938 void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
1939 wxToolBarToolBase *tool = FindById(
id);
1941 (void)tool->SetLongHelp(help);
1945 int ocpnToolBarSimple::GetToolPos(
int id)
const {
1947 wxToolBarToolsList::compatibility_iterator node;
1949 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1950 if (node->GetData()->GetId() ==
id)
return pos;
1957 bool ocpnToolBarSimple::GetToolState(
int id)
const {
1958 wxToolBarToolBase *tool = FindById(
id);
1959 wxCHECK_MSG(tool,
false, _T(
"no such tool"));
1961 return tool->IsToggled();
1964 bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
1965 wxToolBarToolBase *tool = FindById(
id);
1966 wxCHECK_MSG(tool,
false, _T(
"no such tool"));
1968 return tool->IsEnabled();
1971 void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
1972 wxToolBarToolBase *tool = FindById(
id);
1974 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
1975 DoToggleTool(tool, toggle);
1976 InvalidateBitmaps();
1977 gFrame->GetPrimaryCanvas()->Refresh(
true);
1981 wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
1982 wxToolBarToolBase *tool = FindById(
id);
1983 return tool ? tool->GetClientData() : (wxObject *)NULL;
1986 void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
1987 wxToolBarToolBase *tool = FindById(
id);
1989 wxCHECK_RET(tool, _T(
"no such tool in wxToolBar::SetToolClientData"));
1991 tool->SetClientData(clientData);
1994 void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
1995 wxToolBarToolBase *tool = FindById(
id);
1997 if (tool->Enable(enable)) {
1998 DoEnableTool(tool, enable);
2003 if (parent && parent->m_FloatingToolbarConfigMenu) {
2004 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
2005 if (configItem) configItem->Check(
true);
2009 void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
2012 tool->SetTooltipHiviz(b_hiviz);
2016 void ocpnToolBarSimple::ClearTools() {
2017 while (GetToolsCount()) {
2022 int ocpnToolBarSimple::GetVisibleToolCount() {
2024 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2028 node = node->GetNext();
2033 bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
2034 wxCHECK_MSG(pos < GetToolsCount(),
false,
2035 _T(
"invalid position in wxToolBar::DeleteToolByPos()"));
2037 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
2039 if (!DoDeleteTool(pos, node->GetData())) {
2043 delete node->GetData();
2044 m_tools.Erase(node);
2049 bool ocpnToolBarSimple::DeleteTool(
int id) {
2051 wxToolBarToolsList::compatibility_iterator node;
2052 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2053 if (node->GetData()->GetId() ==
id)
break;
2058 if (!node || !DoDeleteTool(pos, node->GetData())) {
2062 delete node->GetData();
2063 m_tools.Erase(node);
2068 wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
2069 return InsertSeparator(GetToolsCount());
2072 wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
2073 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
2074 _T(
"invalid position in wxToolBar::InsertSeparator()"));
2076 wxToolBarToolBase *tool = CreateTool(
2077 wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap,
2078 wxITEM_SEPARATOR, (wxObject *)NULL, wxEmptyString, wxEmptyString);
2080 if (!tool || !DoInsertTool(pos, tool)) {
2086 m_tools.Insert(pos, tool);
2092 wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
2094 wxToolBarToolsList::compatibility_iterator node;
2095 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2096 if (node->GetData()->GetId() ==
id)
break;
2104 return (wxToolBarToolBase *)NULL;
2107 wxToolBarToolBase *tool = node->GetData();
2108 if (!DoDeleteTool(pos, tool)) {
2109 return (wxToolBarToolBase *)NULL;
2112 m_tools.Erase(node);
2117 wxControl *ocpnToolBarSimple::FindControl(
int id) {
2118 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2119 node; node = node->GetNext()) {
2120 const wxToolBarToolBase *
const tool = node->GetData();
2121 if (tool->IsControl()) {
2122 wxControl *
const control = tool->GetControl();
2125 wxFAIL_MSG(_T(
"NULL control in toolbar?"));
2126 }
else if (control->GetId() ==
id) {
2136 wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
2137 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
2139 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2140 node; node = node->GetNext()) {
2141 tool = node->GetData();
2142 if (tool->GetId() == id) {
2159 bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
2160 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
2164 event.SetInt((
int)toggleDown);
2167 event.SetExtraLong((
long)toggleDown);
2169 gFrame->GetEventHandler()->AddPendingEvent(event);
2175 void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
2179 if (m_parentContainer) {
2180 if (m_parentContainer->m_FloatingToolbarConfigMenu) {
2183 wxDefaultPosition, wxSize(100, 100));
2184 int rc = dlg->ShowModal();
2187 if (rc == wxID_OK) {
2188 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
2189 event.SetEventObject(
this);
2192 gFrame->GetEventHandler()->AddPendingEvent(event);
2199 void ocpnToolBarSimple::DoPluginToolUp() {
2202 if (!g_pi_manager)
return;
2204 ArrayOfPlugInToolbarTools tool_array =
2205 g_pi_manager->GetPluginToolbarToolArray();
2206 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
2208 if (m_last_plugin_down_id == pttc->id) {
2211 if (ppi) ppi->OnToolbarToolUpCallback(pttc->id);
2215 m_last_plugin_down_id = -1;
2218 void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2219 const wxString &iconName) {
2225 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
2226 otool->m_width, otool->m_height);
2227 tool->SetNormalBitmap(bmp);
2228 otool->SetIconName(iconName);
2233 void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
2238 otool->pluginNormalIconSVG = fileSVG;
2243 void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
2244 wxBitmap *bmpRollover) {
2247 if (tool->isPluginTool) {
2248 if (bmp->GetWidth() != tool->GetWidth()) {
2250 wxImage ibmp = bmp->ConvertToImage();
2251 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2252 wxIMAGE_QUALITY_HIGH);
2253 wxBitmap sbmp = wxBitmap(ibmp);
2254 tool->pluginNormalIcon = sbmp;
2257 tool->pluginNormalIcon = *bmp;
2260 if (bmpRollover->GetWidth() != tool->GetWidth()) {
2261 if (bmpRollover->IsOk()) {
2262 wxImage ibmp = bmpRollover->ConvertToImage();
2263 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2264 wxIMAGE_QUALITY_HIGH);
2265 wxBitmap sbmp = wxBitmap(ibmp);
2266 tool->pluginRolloverIcon = sbmp;
2269 tool->pluginRolloverIcon = *bmpRollover;
2271 tool->bitmapOK =
false;
2274 tool->SetNormalBitmap(*bmp);
2275 tool->bitmapOK =
true;
2277 InvalidateBitmaps();
2281 void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
2282 wxString fileSVGRollover,
2283 wxString fileSVGToggled) {
2286 tool->pluginNormalIconSVG = fileSVGNormal;
2287 tool->pluginRolloverIconSVG = fileSVGRollover;
2288 tool->pluginToggledIconSVG = fileSVGToggled;
2289 tool->bitmapOK =
false;
2290 InvalidateBitmaps();
2296 ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
2297 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
2299 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
2301 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
2302 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2305 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
2306 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
2308 choices.push_back(
new wxRadioButton(
2309 this, 1, _(
"No, and permanently remove the option to hide it."),
2310 wxDefaultPosition));
2313 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
2315 wxStdDialogButtonSizer *buttonSizer =
2316 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2318 wxStaticText *textCtrl =
2319 new wxStaticText(
this, wxID_ANY,
2320 _(
"The Man Over Board button could be an important "
2321 "safety feature.\nAre you sure you want to hide it?"));
2323 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
2324 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
2325 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
2326 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
2327 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
2329 topSizer->SetSizeHints(
this);
2333 int ToolbarMOBDialog::GetSelection() {
2334 for (
unsigned int i = 0; i < choices.size(); i++) {
2335 if (choices[i]->GetValue())
return choices[i]->GetId();
2355 const wxString &caption,
2357 const wxSize &size,
long style) {
2358 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
2359 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
2361 m_configMenu = NULL;
2362 m_ToolbarDialogAncestor = sponsor;
2364 if (m_ToolbarDialogAncestor)
2365 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
2368 GetSizer()->Fit(
this);
2373 ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
2380 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
2381 SetSizer(itemBoxSizer1);
2383 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
2384 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
2385 itemDialog1->SetScrollRate(2, 2);
2387 #ifdef __OCPN__ANDROID__
2390 wxFont *qFont = GetOCPNScaledFont(_(
"Dialog"));
2392 wxString wqs = getFontQtStylesheet(qFont);
2393 wxCharBuffer sbuf = wqs.ToUTF8();
2394 QString qsb = QString(sbuf.data());
2396 QString qsbq = getQtStyleSheet();
2398 this->GetHandle()->setStyleSheet(qsb + qsbq);
2401 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
2403 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
2404 itemDialog1->SetSizer(itemBoxSizer2);
2406 wxStaticBox *itemStaticBoxSizer3Static =
2407 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Choose Toolbar Icons"));
2408 wxStaticBoxSizer *itemStaticBoxSizer3 =
2409 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
2410 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
2415 nitems = m_configMenu->GetMenuItemCount();
2418 for (
int i = 0; i < nitems; i++) {
2419 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon)
continue;
2420 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2422 wxString label = item->GetItemLabel();
2423 int l = label.Len();
2424 max_width = wxMax(max_width, l);
2426 wxString windowName = _T(
"");
2427 if (item->GetId() == ID_MOB + 100) windowName = _T(
"MOBCheck");
2430 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
2431 wxDefaultSize, 0, wxDefaultValidator, windowName);
2433 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
2434 cb->SetValue(item->IsChecked());
2436 cboxes.push_back(cb);
2440 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
2441 (nitems + 4) * GetCharHeight() * 2);
2443 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
2444 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
2446 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
2447 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
2449 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
2450 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
2453 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
2454 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2457 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
2458 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2459 m_OKButton->SetDefault();
2461 m_CancelButton->Connect(
2462 wxEVT_COMMAND_BUTTON_CLICKED,
2463 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL,
this);
2464 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2465 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
2468 SetColorScheme((ColorScheme)0);
2471 void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
2473 void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
2474 EndModal(wxID_CANCEL);
2477 void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
2478 unsigned int ncheck = 0;
2480 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
2481 wxString new_toolbarConfig = toolbarConfigSave;
2483 for (
unsigned int i = 0; i < cboxes.size(); i++) {
2484 wxCheckBox *cb = cboxes[i];
2485 wxString cbName = cb->GetName();
2487 if (cbName.IsSameAs(_T(
"MOBCheck")) && !cb->IsChecked()) {
2490 int dialog_ret = mdlg.ShowModal();
2491 int answer = mdlg.GetSelection();
2492 if (dialog_ret == wxID_OK) {
2494 g_bPermanentMOBIcon =
true;
2496 }
else if (answer == 0) {
2500 new_toolbarConfig = toolbarConfigSave;
2505 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2506 if (new_toolbarConfig.Len() > i) {
2507 new_toolbarConfig.SetChar(i, cb->IsChecked() ? _T(
'X') : _T(
'.'));
2509 new_toolbarConfig.Append(cb->IsChecked() ? _T(
'X') : _T(
'.'));
2511 item->Check(cb->IsChecked());
2512 if (cb->IsChecked()) ncheck++;
2519 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN , _T(
'X') );
2521 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
2524 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
2526 item->Check(
true );
2530 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
2535 void ToolbarChoicesDialog::RecalculateSize(
void) {
2536 wxSize esize = GetSize();
2539 wxSize dsize = GetParent()->GetClientSize();
2540 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
2541 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
2546 wxSize fsize = g_Platform->getDisplaySize();
2547 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
2548 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
2551 #ifdef __OCPN__ANDROID__
2552 Move(GetPosition().x, 10);
Global state for AIS decoder.
General purpose GUI support.