36#include "model/ocpn_types.h"
42#include "OCPNPlatform.h"
46#include "model/idents.h"
47#include "ocpn_frame.h"
49#ifdef __OCPN__ANDROID__
50#include "androidUTIL.h"
54#include "glChartCanvas.h"
57extern bool g_bTransparentToolbar;
58extern bool g_bTransparentToolbarInOpenGLOK;
63extern bool g_bPermanentMOBIcon;
66extern bool g_bmasterToolbarFull;
68extern wxString g_toolbarConfig;
69extern double g_plus_minus_zoom_factor;
70extern int g_maintoolbar_x;
71extern int g_maintoolbar_y;
72extern bool g_disable_main_toolbar;
75extern GLenum g_texture_rectangle_format;
83 const wxBitmap &bmpNormal,
const wxBitmap &bmpRollover,
84 wxItemKind kind, wxObject *clientData,
85 const wxString &shortHelp,
const wxString &longHelp)
86 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, label, bmpNormal,
87 bmpRollover, kind, clientData, shortHelp, longHelp) {
92 m_btooltip_hiviz =
false;
94 toolname = g_pi_manager->GetToolOwnerCommonName(
id);
102 pluginNormalIcon = bmpNormal;
103 pluginRolloverIcon = bmpRollover;
108 const wxBitmap &bmpRollover, wxItemKind kind,
109 wxObject *clientData,
const wxString &shortHelp,
110 const wxString &longHelp)
111 : wxToolBarToolBase((wxToolBarBase *)tbar,
id,
"", bmpNormal, bmpRollover,
112 kind, clientData, shortHelp, longHelp) {
116 m_btooltip_hiviz =
false;
117 isPluginTool =
false;
119 m_bmpNormal = bmpNormal;
123 void SetSize(
const wxSize &size) {
128 wxCoord GetWidth()
const {
return m_width; }
130 wxCoord GetHeight()
const {
return m_height; }
132 wxString GetToolname() {
return toolname; }
134 void SetIconName(wxString name) { iconName = name; }
135 wxString GetIconName() {
return iconName; }
137 void SetTooltipHiviz(
bool enable) { m_btooltip_hiviz = enable; }
146 wxBitmap pluginNormalIcon;
147 wxBitmap pluginRolloverIcon;
148 const wxBitmap *pluginToggledIcon;
155 bool m_btooltip_hiviz;
157 wxString pluginNormalIconSVG;
158 wxString pluginRolloverIconSVG;
159 wxString pluginToggledIconSVG;
160 wxBitmap m_activeBitmap;
167ocpnFloatingToolbarDialog::ocpnFloatingToolbarDialog(wxWindow *parent,
175 m_position = position;
177 m_sizefactor = size_factor;
180 m_bAutoHideToolbar =
false;
181 m_nAutoHideToolbar = 5;
182 m_toolbar_scale_tools_shown =
false;
183 m_backcolorString =
"GREY3";
184 m_toolShowMask =
"XXXXXXXXXXXXXXXX";
185 n_toolbarHideMethod = TOOLBAR_HIDE_TO_GRABBER;
186 b_canToggleOrientation =
true;
187 m_enableRolloverBitmaps =
true;
190 m_ptoolbar = CreateNewToolbar();
191 if (m_ptoolbar) m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"GREY3"));
192 m_cs = (ColorScheme)-1;
194 m_style = g_StyleManager->GetCurrentStyle();
195 SetULDockPosition(wxPoint(4, 4));
197 SetGeometry(
false, wxRect());
206 m_marginsInvisible = m_style->marginsInvisible;
208 m_FloatingToolbarConfigMenu = NULL;
210 m_fade_timer.SetOwner(
this);
211 this->Connect(wxEVT_TIMER,
212 wxTimerEventHandler(ocpnFloatingToolbarDialog::FadeTimerEvent),
215 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
216 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
218 m_bsubmerged =
false;
219 m_benableSubmerge =
true;
222ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
223 delete m_FloatingToolbarConfigMenu;
228void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
229 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
230 if (g_bmasterToolbarFull) {
231 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) ) {
234 gFrame->GetPrimaryCanvas()->ScreenToClient(::wxGetMousePosition());
236 wxRect r = GetToolbarRect();
237 if (r.Contains(mp))
return;
239 wxCommandEvent event;
240 event.SetId(ID_MASTERTOGGLE);
241 gFrame->OnToolLeftClick(event);
248 m_Items.push_back(item);
251int ocpnFloatingToolbarDialog::RebuildToolbar() {
258 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
262 bool bEnabled = _toolbarConfigMenuUtil(tic);
265 wxToolBarToolBase *tool =
266 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
267 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
272 if (!tic->m_NormalIconSVG.IsEmpty()) {
273 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
274 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
284void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
285 if (position.x >= 0) m_dock_min_x = position.x;
286 if (position.y >= 0) m_dock_min_y = position.y;
289size_t ocpnFloatingToolbarDialog::GetToolCount() {
291 return m_ptoolbar->GetToolsCount();
296void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
298void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
300 m_ptoolbar->SetToolShowCount(count);
301 m_ptoolbar->SetDirty(
true);
305int ocpnFloatingToolbarDialog::GetToolShowCount(
void) {
307 return m_ptoolbar->GetToolShowCount();
312void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
313 m_backcolorString = colorRef;
314 SetColorScheme(m_cs);
317void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
319void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
321void ocpnFloatingToolbarDialog::CreateConfigMenu() {
322 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
323 m_FloatingToolbarConfigMenu =
new wxMenu();
326bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
328 if (m_FloatingToolbarConfigMenu) {
329 wxMenuItem *menuitem;
331 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
333 if (tic->m_bRequired)
return true;
334 if (tic->m_bPlugin)
return true;
341 int menuItemId = tic->m_ID + idOffset;
343 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
346 return menuitem->IsChecked();
349 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
351 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
352 menuitem->Check(m_configString.Len() >= n
353 ? m_configString.GetChar(n - 1) == _T(
'X')
355 return menuitem->IsChecked();
360void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
361 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
364void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
366 wxColour back_color = GetGlobalColor(m_backcolorString);
369 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
370 m_ptoolbar->SetColorScheme(cs);
374wxSize 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;
389void 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(
"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);
435void ocpnFloatingToolbarDialog::SetDefaultPosition() {
438 if (m_pparent && m_ptoolbar) {
439 wxSize cs = m_pparent->GetClientSize();
441 m_position.x = m_dock_min_x;
442 else if (1 == m_dock_x)
443 m_position.x = cs.x - m_ptoolbar->m_maxWidth;
446 m_position.y = m_dock_min_y;
447 else if (1 == m_dock_y)
448 m_position.y = cs.y - m_ptoolbar->m_maxHeight;
450 m_position.x = wxMin(cs.x - m_ptoolbar->m_maxWidth, m_position.x);
451 m_position.y = wxMin(cs.y - m_ptoolbar->m_maxHeight, m_position.y);
453 m_position.x = wxMax(m_dock_min_x, m_position.x);
454 m_position.y = wxMax(m_dock_min_y, m_position.y);
456 m_position.y += m_auxOffsetY;
458 g_maintoolbar_x = m_position.x;
459 g_maintoolbar_y = m_position.y;
480void ocpnFloatingToolbarDialog::Submerge() {
483 if (m_ptoolbar) m_ptoolbar->KillTooltip();
486void ocpnFloatingToolbarDialog::HideTooltip() {
487#ifndef __OCPN__ANDROID__
488 if (m_ptoolbar) m_ptoolbar->HideTooltip();
492void ocpnFloatingToolbarDialog::ShowTooltips() {
493#ifndef __OCPN__ANDROID__
494 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
498void ocpnFloatingToolbarDialog::ToggleOrientation() {}
500wxRect ocpnFloatingToolbarDialog::GetToolbarRect() {
501 return wxRect(m_position.x, m_position.y, m_ptoolbar->m_maxWidth,
502 m_ptoolbar->m_maxHeight);
505wxSize ocpnFloatingToolbarDialog::GetToolbarSize() {
506 return wxSize(m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
509wxPoint ocpnFloatingToolbarDialog::GetToolbarPosition() {
510 return wxPoint(m_position.x, m_position.y);
513bool ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
514 if (g_disable_main_toolbar)
return false;
516 bool bproc = m_ptoolbar->OnMouseEvent(event, m_position);
517 if (bproc) m_ptoolbar->CreateBitmap();
523void ocpnFloatingToolbarDialog::RefreshToolbar() {
525 if (m_ptoolbar->IsDirty()) {
527 gFrame->GetPrimaryCanvas()->Refresh();
532void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
533 m_nAutoHideToolbar = time;
534 if (m_bAutoHideToolbar) {
536 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
540void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
541 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
542 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
546void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
547 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
550void ocpnFloatingToolbarDialog::Realize() {
552 m_ptoolbar->Realize();
553 m_ptoolbar->CreateBitmap();
554 m_toolbar_image.Destroy();
558void ocpnFloatingToolbarDialog::DrawDC(
ocpnDC &dc,
double displayScale) {
560 m_ptoolbar->CreateBitmap();
561 if (m_ptoolbar->GetBitmap().IsOk()) {
562 dc.DrawBitmap(m_ptoolbar->GetBitmap(), m_position.x, m_position.y,
false);
563 m_ptoolbar->SetDirty(
false);
568void ocpnFloatingToolbarDialog::DrawGL(
ocpnDC &gldc,
double displayScale) {
569 if (g_disable_main_toolbar)
return;
572 if (!m_ptoolbar)
return;
574 wxColour backColor = GetGlobalColor(
"GREY3");
575 gldc.SetBrush(wxBrush(backColor));
576 gldc.SetPen(wxPen(backColor));
578 wxRect r = GetToolbarRect();
579 int m_end_margin = wxMin(GetToolSize().x, GetToolSize().y) / 8;
581 if (m_orient == wxHORIZONTAL)
582 gldc.DrawRoundedRectangle(
583 (r.x - m_end_margin / 2) * displayScale, (r.y - 1) * displayScale,
584 (r.width + m_end_margin) * displayScale, (r.height + 2) * displayScale,
585 (m_end_margin * 1) * displayScale);
587 gldc.DrawRoundedRectangle(
588 (r.x - 1) * displayScale, (r.y - m_end_margin / 2) * displayScale,
589 (r.width + 2) * displayScale, (r.height + m_end_margin) * displayScale,
590 (m_end_margin * 1.5) * displayScale);
592 int width = GetToolbarSize().x;
593 int height = GetToolbarSize().y;
595 m_ptoolbar->CreateBitmap(displayScale);
599 glGenTextures(1, &m_texture);
601 glBindTexture(g_texture_rectangle_format, m_texture);
602 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
604 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
606 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
608 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
611 glBindTexture(g_texture_rectangle_format, m_texture);
614 if (!m_toolbar_image.IsOk()) {
616 m_toolbar_image = m_ptoolbar->GetBitmap().ConvertToImage();
618 unsigned char *d = m_toolbar_image.GetData();
619 unsigned char *e =
new unsigned char[4 * width * height];
620 for (
int y = 0; y < height; y++)
621 for (
int x = 0; x < width; x++) {
622 int i = y * width + x;
623 memcpy(e + 4 * i, d + 3 * i, 3);
626 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, width, height, 0,
627 GL_RGBA, GL_UNSIGNED_BYTE, e);
629 glDisable(g_texture_rectangle_format);
635 glEnable(g_texture_rectangle_format);
636 glBindTexture(g_texture_rectangle_format, m_texture);
639 int x0 = GetToolbarPosition().x, x1 = x0 + width;
640 int y0 = GetToolbarPosition().y - 0, y1 = y0 + height;
647 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
648 tx = width, ty = height;
675 auto canvas = gFrame->GetPrimaryCanvas();
676 canvas->GetglCanvas()->RenderTextures(gldc, coords, uv, 4,
679 glDisable(g_texture_rectangle_format);
680 glBindTexture(g_texture_rectangle_format, 0);
688void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
692 m_pparent->GetEventHandler()->AddPendingEvent(event);
700 m_ptoolbar = CreateNewToolbar();
707 long winstyle = wxNO_BORDER | wxTB_FLAT;
708 winstyle |= m_orient;
715 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
716 m_ptoolbar->SetColorScheme(m_cs);
717 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
722void ocpnFloatingToolbarDialog::DestroyToolBar() {
723 g_toolbarConfig = GetToolConfigString();
726 m_ptoolbar->ClearTools();
731 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
741extern bool g_bTrackActive;
742extern s52plib *ps52plib;
745 if (!g_pi_manager)
return false;
748 int n_tools = tb->GetToolsCount();
752 ArrayOfPlugInToolbarTools tool_array =
753 g_pi_manager->GetPluginToolbarToolArray();
755 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
757 if (pttc->position == n_tools) {
761 case GLOBAL_COLOR_SCHEME_DAY:
762 ptool_bmp = pttc->bitmap_day;
765 case GLOBAL_COLOR_SCHEME_DUSK:
766 ptool_bmp = pttc->bitmap_dusk;
768 case GLOBAL_COLOR_SCHEME_NIGHT:
769 ptool_bmp = pttc->bitmap_night;
772 ptool_bmp = pttc->bitmap_day;
777 wxToolBarToolBase *tool =
778 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
779 wxString(pttc->shortHelp), pttc->kind);
781 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
782 pttc->pluginRolloverIconSVG,
783 pttc->pluginToggledIconSVG);
792 while (CheckAndAddPlugInTool(tb)) {
798void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
799 m_enableRolloverBitmaps = bEnable;
800 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
811 void OnPaint(wxPaintEvent &event);
813 void SetColorScheme(ColorScheme cs);
814 void SetString(wxString &s) { m_string = s; }
815 void SetPosition(wxPoint pt) { m_position = pt; }
816 void SetBitmap(
void);
818 void SetHiviz(
bool hiviz) { m_hiviz = hiviz; }
820 wxSize GetRenderedSize(
void);
827 wxColour m_back_color;
828 wxColour m_text_color;
832 DECLARE_EVENT_TABLE()
840EVT_PAINT(ToolTipWin::OnPaint)
846 : wxFrame(parent, wxID_ANY, "", wxPoint(0, 0), wxSize(1, 1),
847 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR) {
851 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
853 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
855 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
856 SetBackgroundColour(m_back_color);
857 m_cs = GLOBAL_COLOR_SCHEME_RGB;
862ToolTipWin::~ToolTipWin() {
delete m_pbm; }
864void ToolTipWin::SetColorScheme(ColorScheme cs) {
866 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
868 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
871 m_text_color = GetDimedColor(FontMgr::Get().GetFontColor(_(
"ToolTips")));
877wxSize ToolTipWin::GetRenderedSize(
void) {
883 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
884 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, plabelFont);
892void ToolTipWin::SetBitmap() {
898 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
899 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
901 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, &sFont);
903 m_size.x = w + GetCharWidth() * 2;
904 m_size.y = h + GetCharHeight() / 2;
912 m_pbm =
new wxBitmap(m_size.x, m_size.y, -1);
913 mdc.SelectObject(*m_pbm);
915 wxPen pborder(m_text_color);
916 wxBrush bback(m_back_color);
921 if ((m_cs == GLOBAL_COLOR_SCHEME_DUSK) ||
922 (m_cs == GLOBAL_COLOR_SCHEME_NIGHT)) {
923 wxBrush hv_back(wxColour(200, 200, 200));
924 mdc.SetBrush(hv_back);
927 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
931 mdc.SetTextForeground(m_text_color);
932 mdc.SetTextBackground(m_back_color);
934 int offx = GetCharWidth();
935 int offy = GetCharHeight() / 4;
938 mdc.DrawText(m_string, offx, offy);
940 SetClientSize(m_size.x, m_size.y);
941 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
944void ToolTipWin::OnPaint(wxPaintEvent &event) {
946 GetClientSize(&width, &height);
949 if (m_string.Len()) {
951 mdc.SelectObject(*m_pbm);
952 dc.Blit(0, 0, width, height, &mdc, 0, 0);
963EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
964EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
972 int id, const wxString &label, const wxBitmap &bmpNormal,
973 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
974 const wxString &shortHelp, const wxString &longHelp) {
975 if (m_style->NativeToolIconExists(label)) {
976 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
977 clientData, shortHelp, longHelp);
979 wxString testToolname = g_pi_manager->GetToolOwnerCommonName(
id);
981 if (testToolname ==
"") {
983 clientData, shortHelp, longHelp);
985 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
986 clientData, shortHelp, longHelp);
995void ocpnToolBarSimple::Init() {
996 m_currentRowsOrColumns = 0;
998 m_lastX = m_lastY = 0;
1000 m_maxWidth = m_maxHeight = 0;
1002 m_pressedTool = m_currentTool = -1;
1004 m_xPos = m_yPos = wxDefaultCoord;
1006 m_style = g_StyleManager->GetCurrentStyle();
1008 m_defaultWidth = 16;
1009 m_defaultHeight = 15;
1011 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
1012 m_toolOutlineColour.Set(
"BLACK");
1013 m_pToolTipWin = NULL;
1014 m_last_ro_tool = NULL;
1016 m_btoolbar_is_zooming =
false;
1017 m_sizefactor = 1.0f;
1019 m_last_plugin_down_id = -1;
1022 m_btooltip_show =
false;
1023#ifndef __OCPN__ANDROID__
1026 m_tbenableRolloverBitmaps =
false;
1029wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
1030 int id,
const wxString &label,
const wxBitmap &bitmap,
1031 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1032 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
1039 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
1040 shortHelp, longHelp, clientData);
1045wxToolBarToolBase *ocpnToolBarSimple::AddTool(
1046 int toolid,
const wxString &label,
const wxBitmap &bitmap,
1047 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1048 const wxString &longHelp, wxObject *data) {
1051 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
1056wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
1057 size_t pos,
int id,
const wxString &label,
const wxBitmap &bitmap,
1058 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1059 const wxString &longHelp, wxObject *clientData) {
1060 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1061 "invalid position in wxToolBar::InsertTool()");
1063 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
1064 clientData, shortHelp, longHelp);
1066 if (!InsertTool(pos, tool)) {
1075wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
1076 wxToolBarToolBase *tool) {
1077 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1078 "invalid position in wxToolBar::InsertTool()");
1080 if (!tool || !DoInsertTool(pos, tool)) {
1084 m_tools.Insert(pos, tool);
1090bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
1091 wxToolBarToolBase *toolBase) {
1097 if (tool->isPluginTool) {
1098 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
1099 if (tool->GetToolname() ==
1101 tool->toolname <<
"1";
1107 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
1110 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
1112 if (tool->IsButton()) {
1113 tool->SetSize(GetToolSize());
1116 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
1117 m_style->GetLeftMargin()) > m_maxWidth)
1119 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
1121 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
1122 m_style->GetTopMargin()) > m_maxHeight)
1124 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
1127 else if (tool->IsControl()) {
1128 tool->SetSize(tool->GetControl()->GetSize());
1131 tool->b_hilite =
false;
1136bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
1137 wxToolBarToolBase *tool) {
1141 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
1149 const wxPoint &pos,
const wxSize &size,
1150 long style,
int orient) {
1151 m_parentContainer = parent;
1170 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
1171 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
1172 m_tooltip_off = 3000;
1174 m_tbenableRolloverBitmaps =
false;
1179ocpnToolBarSimple::~ocpnToolBarSimple() {
1180 if (m_pToolTipWin) {
1181 m_pToolTipWin->Destroy();
1182 m_pToolTipWin = NULL;
1186void ocpnToolBarSimple::EnableTooltips() {
1187#ifndef __OCPN__ANDROID__
1188 m_btooltip_show =
true;
1192void ocpnToolBarSimple::DisableTooltips() {
1193#ifndef __OCPN__ANDROID__
1194 ocpnToolBarSimple::m_btooltip_show =
false;
1198void ocpnToolBarSimple::KillTooltip() {
1199 m_btooltip_show =
false;
1201 if (m_pToolTipWin) {
1202 m_pToolTipWin->Hide();
1203 m_pToolTipWin->Destroy();
1204 m_pToolTipWin = NULL;
1206 m_tooltip_timer.Stop();
1209 gFrame->GetFocusCanvas()->TriggerDeferredFocus();
1212void ocpnToolBarSimple::HideTooltip() {
1213#ifndef __OCPN__ANDROID__
1214 if (m_pToolTipWin) {
1215 m_pToolTipWin->Hide();
1220void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1221#ifndef __OCPN__ANDROID__
1222 if (m_pToolTipWin) {
1223 m_pToolTipWin->Destroy();
1224 m_pToolTipWin = NULL;
1227 m_toolOutlineColour = GetGlobalColor(
"UIBDR");
1229 m_currentColorScheme = cs;
1232bool ocpnToolBarSimple::Realize() {
1234 m_style->SetOrientation(wxTB_VERTICAL);
1236 m_style->SetOrientation(wxTB_HORIZONTAL);
1238 wxSize toolSize = wxSize(-1, -1);
1239 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1240 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1241 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1243 m_currentRowsOrColumns = 0;
1245 m_lastX = leftMargin;
1246 m_lastY = topMargin;
1251 bool firstNode =
true;
1252 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1257 if (iNode >= m_nShowTools)
break;
1263 if (toolSize.x == -1) {
1264 if (!tool->IsSeparator()) {
1265 toolSize.x = tool->m_width;
1266 toolSize.y = tool->m_height;
1270 tool->firstInLine = firstNode;
1271 tool->lastInLine =
false;
1274 tool->last_rect.width = 0;
1276 if (tool->IsSeparator()) {
1285 if (m_currentRowsOrColumns >= m_maxRows)
1286 m_lastX += separatorSize;
1288 m_lastY += separatorSize;
1290 }
else if (tool->IsButton()) {
1291 if (!IsVertical()) {
1292 if (m_currentRowsOrColumns >= m_maxCols) {
1293 tool->firstInLine =
true;
1294 if (lastTool && m_LineCount > 1) lastTool->lastInLine =
true;
1296 m_currentRowsOrColumns = 0;
1297 m_lastX = leftMargin;
1298 m_lastY += toolSize.y + topMargin;
1300 tool->m_x = (wxCoord)m_lastX;
1301 tool->m_y = (wxCoord)m_lastY;
1303 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1304 tool->trect.Inflate(separatorSize / 2, topMargin);
1306 m_lastX += toolSize.x + separatorSize;
1308 if (m_currentRowsOrColumns >= m_maxRows) {
1309 tool->firstInLine =
true;
1310 if (lastTool) lastTool->lastInLine =
true;
1312 m_currentRowsOrColumns = 0;
1313 m_lastX += toolSize.x + leftMargin;
1314 m_lastY = topMargin;
1316 tool->m_x = (wxCoord)m_lastX;
1317 tool->m_y = (wxCoord)m_lastY;
1319 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1320 tool->trect.Inflate((separatorSize / 2), topMargin);
1322 m_lastY += toolSize.y + separatorSize;
1324 m_currentRowsOrColumns++;
1339 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
1340 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
1343 node = node->GetNext();
1346 if (lastTool && (m_LineCount > 1 || IsVertical()))
1347 lastTool->lastInLine =
true;
1349 if (!IsVertical()) {
1350 m_maxHeight += toolSize.y;
1351 m_maxHeight += m_style->GetBottomMargin();
1353 m_maxWidth += toolSize.x;
1354 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
1357 m_bitmap = wxNullBitmap;
1362wxBitmap &ocpnToolBarSimple::CreateBitmap(
double display_scale) {
1363 if (m_bitmap.IsOk())
return m_bitmap;
1366 int width = m_maxWidth;
1367 int height = m_maxHeight;
1370 wxBitmap bm(width, height);
1371 mdc.SelectObject(bm);
1372 mdc.SetBackground(wxBrush(GetBackgroundColour()));
1376 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1377 node; node = node->GetNext()) {
1378 wxToolBarToolBase *tool = node->GetData();
1380 wxRect toolRect = tools->trect;
1381 CreateToolBitmap(tool);
1383 if (tools->m_activeBitmap.IsOk()) {
1384 mdc.DrawBitmap(tools->m_activeBitmap, tools->m_x, tools->m_y,
false);
1389 mdc.SelectObject(wxNullBitmap);
1395void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
1400 if (m_btooltip_show && m_pToolTipWin &&
1401 (!m_pToolTipWin->IsShown())) {
1402 if (m_last_ro_tool) {
1403 wxString s = m_last_ro_tool->GetShortHelp();
1406 m_pToolTipWin->SetString(s);
1407 m_pToolTipWin->SetHiviz(m_last_ro_tool->m_btooltip_hiviz);
1409 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
1410 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
1412 m_pToolTipWin->Move(
1415 wxPoint screenPosition =
1416 gFrame->GetPrimaryCanvas()->ClientToScreen(pos_in_toolbar);
1417 wxSize tipSize = m_pToolTipWin->GetRenderedSize();
1419 m_pToolTipWin->SetPosition(screenPosition);
1420 m_pToolTipWin->SetBitmap();
1421 m_pToolTipWin->Show();
1426#ifndef __OCPN__ANDROID__
1427 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1434void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
1438bool ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event, wxPoint &position) {
1440 event.GetPosition(&x, &y);
1443 wxRect r = wxRect(position, wxSize(m_maxWidth, m_maxHeight));
1444 if (!r.Contains(x, y)) {
1449 m_parentContainer->RefreshFadeTimer();
1452 (
ocpnToolBarTool *)FindToolForPosition(x - position.x, y - position.y);
1454 m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1457 m_tooltipoff_timer.Stop();
1460 if (tool && tool->IsButton() ) {
1461 if (m_btooltip_show) {
1463 if (NULL == m_pToolTipWin) {
1465 m_pToolTipWin->SetColorScheme(m_currentColorScheme);
1466 m_pToolTipWin->Hide();
1469 if (tool != m_last_ro_tool) {
1470 m_pToolTipWin->Hide();
1473#ifndef __OCPN__ANDROID__
1474 if (!m_pToolTipWin->IsShown()) {
1475 if (!m_tooltip_timer.IsRunning()) {
1476 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
1483 m_last_ro_tool = tool;
1486 if (event.LeftIsDown()) m_leftDown =
true;
1488 if (event.LeftDown() && tool->IsEnabled()) {
1489 if (tool->CanBeToggled()) {
1491 tool->bitmapOK =
false;
1493 m_bitmap = wxNullBitmap;
1499 ArrayOfPlugInToolbarTools tool_array =
1500 g_pi_manager->GetPluginToolbarToolArray();
1501 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1503 if (tool->GetId() == pttc->id) {
1508 m_last_plugin_down_id = pttc->id;
1513 }
else if (event.RightDown()) {
1514 OnRightClick(tool->GetId(), x, y);
1527 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
1529 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
1530 tool->CanBeToggled()) {
1534 tool->bitmapOK =
false;
1549void ocpnToolBarSimple::CreateToolBitmap(wxToolBarToolBase *toolBase) {
1552 wxBitmap bmp = wxNullBitmap;
1554 bool bNeedClear = !tool->bitmapOK;
1556 if (tool->bitmapOK) {
1557 if (tool->IsEnabled()) {
1558 bmp = tool->GetNormalBitmap();
1561 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1562 tool->rollover, tool->m_width, tool->m_height);
1563 tool->SetNormalBitmap(bmp);
1564 tool->bitmapOK =
true;
1567 bmp = tool->GetDisabledBitmap();
1569 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1570 false, tool->m_width, tool->m_height);
1571 tool->SetDisabledBitmap(bmp);
1572 tool->bitmapOK =
true;
1576 if (tool->isPluginTool) {
1577 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1584 wxString svgFile = tool->pluginNormalIconSVG;
1586 if (tool->pluginToggledIconSVG.Length())
1587 svgFile = tool->pluginToggledIconSVG;
1589 if (tool->rollover) {
1590 if (tool->pluginRolloverIconSVG.Length())
1591 svgFile = tool->pluginRolloverIconSVG;
1594 if (!svgFile.IsEmpty()) {
1596 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
1598 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1601 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1605 if (!bmp.IsOk() || bmp.IsNull()) {
1606 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1607 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1608 tool->rollover, tool->m_width,
1616 bmp = tool->pluginNormalIcon;
1617 if (fabs(m_sizefactor - 1.0) > 0.01) {
1618 if (tool->m_width && tool->m_height) {
1619 wxImage scaled_image = bmp.ConvertToImage();
1620 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1621 wxIMAGE_QUALITY_HIGH));
1626 tool->SetNormalBitmap(bmp);
1627 tool->bitmapOK =
true;
1629 bmp = tool->GetNormalBitmap();
1630 if (tool->IsEnabled()) {
1631 if (tool->IsToggled()) {
1632 if (!tool->bitmapOK) {
1633 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1634 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1635 tool->rollover, tool->m_width,
1637 tool->SetNormalBitmap(bmp);
1643 if (!tool->bitmapOK) {
1644 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1645 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1646 tool->rollover, tool->m_width,
1648 tool->SetNormalBitmap(bmp);
1653 tool->bitmapOK =
true;
1655 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1656 false, tool->m_width, tool->m_height);
1657 tool->SetDisabledBitmap(bmp);
1658 tool->bitmapOK =
true;
1662 tool->m_activeBitmap = bmp;
1668void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
1672 wxPoint drawAt(tool->m_x, tool->m_y);
1673 wxBitmap bmp = wxNullBitmap;
1675 bool bNeedClear = !tool->bitmapOK;
1677 if (tool->bitmapOK) {
1678 if (tool->IsEnabled()) {
1679 bmp = tool->GetNormalBitmap();
1682 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1683 tool->rollover, tool->m_width, tool->m_height);
1684 tool->SetNormalBitmap(bmp);
1685 tool->bitmapOK =
true;
1688 bmp = tool->GetDisabledBitmap();
1690 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1691 false, tool->m_width, tool->m_height);
1692 tool->SetDisabledBitmap(bmp);
1693 tool->bitmapOK =
true;
1697 if (tool->isPluginTool) {
1698 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1705 wxString svgFile = tool->pluginNormalIconSVG;
1707 if (tool->pluginToggledIconSVG.Length())
1708 svgFile = tool->pluginToggledIconSVG;
1710 if (tool->rollover) {
1711 if (tool->pluginRolloverIconSVG.Length())
1712 svgFile = tool->pluginRolloverIconSVG;
1715 if (!svgFile.IsEmpty()) {
1717 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
1719 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1722 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1726 if (!bmp.IsOk() || bmp.IsNull()) {
1727 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1728 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1729 tool->rollover, tool->m_width,
1736 if (tool->rollover) {
1738 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
1741 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1744 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1746 if (fabs(m_sizefactor - 1.0) > 0.01) {
1747 if (tool->m_width && tool->m_height) {
1748 wxImage scaled_image = bmp.ConvertToImage();
1749 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1750 wxIMAGE_QUALITY_HIGH));
1755 tool->SetNormalBitmap(bmp);
1756 tool->bitmapOK =
true;
1758 bmp = tool->GetNormalBitmap();
1759 if (tool->IsEnabled()) {
1760 if (tool->IsToggled()) {
1761 if (!tool->bitmapOK) {
1762 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1763 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1764 tool->rollover, tool->m_width,
1766 tool->SetNormalBitmap(bmp);
1772 if (!tool->bitmapOK) {
1773 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1774 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1775 tool->rollover, tool->m_width,
1777 tool->SetNormalBitmap(bmp);
1782 tool->bitmapOK =
true;
1784 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1785 false, tool->m_width, tool->m_height);
1786 tool->SetDisabledBitmap(bmp);
1787 tool->bitmapOK =
true;
1792 if (tool->firstInLine) {
1793 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
1795 if (tool->lastInLine) {
1796 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
1799 if (bmp.GetWidth() != m_style->GetToolSize().x ||
1800 bmp.GetHeight() != m_style->GetToolSize().y) {
1806 if ((tool->last_rect.width &&
1807 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
1809 wxBrush bb(GetGlobalColor(
"GREY3"));
1811 dc.SetPen(*wxTRANSPARENT_PEN);
1812 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
1813 tool->last_rect.width, tool->last_rect.height);
1820 wxImage scaled_image = bmp.ConvertToImage();
1821 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1822 wxIMAGE_QUALITY_HIGH));
1823 dc.DrawBitmap(sbmp, drawAt);
1825 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
1828 dc.DrawBitmap(bmp, drawAt);
1830 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
1838wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
1840 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1843 if ((x >= tool->m_x) && (y >= tool->m_y) &&
1844 (x < (tool->m_x + tool->GetWidth())) &&
1845 (y < (tool->m_y + tool->GetHeight()))) {
1849 node = node->GetNext();
1852 return (wxToolBarToolBase *)NULL;
1855void ocpnToolBarSimple::InvalidateBitmaps() {
1856 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1859 tool->bitmapOK =
false;
1860 node = node->GetNext();
1862 m_bitmap = wxNullBitmap;
1865wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
1867 wxToolBarToolBase *tool = FindById(tool_id);
1870 if (otool) rect = otool->trect;
1880void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
1881 bool WXUNUSED(enable)) {
1883 t->bitmapOK =
false;
1886void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
1887 bool WXUNUSED(toggle)) {
1889 t->bitmapOK =
false;
1897wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
1898 wxToolBarToolBase *tool = FindById(
id);
1899 wxCHECK_MSG(tool, wxEmptyString,
"no such tool");
1901 return tool->GetShortHelp();
1904wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
1905 wxToolBarToolBase *tool = FindById(
id);
1906 wxCHECK_MSG(tool, wxEmptyString,
"no such tool");
1908 return tool->GetLongHelp();
1911void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
1912 wxToolBarToolBase *tool = FindById(
id);
1914 (void)tool->SetShortHelp(help);
1918void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
1919 wxToolBarToolBase *tool = FindById(
id);
1921 (void)tool->SetLongHelp(help);
1925int ocpnToolBarSimple::GetToolPos(
int id)
const {
1927 wxToolBarToolsList::compatibility_iterator node;
1929 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1930 if (node->GetData()->GetId() == id)
return pos;
1937bool ocpnToolBarSimple::GetToolState(
int id)
const {
1938 wxToolBarToolBase *tool = FindById(
id);
1939 wxCHECK_MSG(tool,
false,
"no such tool");
1941 return tool->IsToggled();
1944bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
1945 wxToolBarToolBase *tool = FindById(
id);
1946 wxCHECK_MSG(tool,
false,
"no such tool");
1948 return tool->IsEnabled();
1951void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
1952 wxToolBarToolBase *tool = FindById(
id);
1954 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
1955 DoToggleTool(tool, toggle);
1956 InvalidateBitmaps();
1957 gFrame->GetPrimaryCanvas()->Refresh(
true);
1961wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
1962 wxToolBarToolBase *tool = FindById(
id);
1963 return tool ? tool->GetClientData() : (wxObject *)NULL;
1966void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
1967 wxToolBarToolBase *tool = FindById(
id);
1969 wxCHECK_RET(tool,
"no such tool in wxToolBar::SetToolClientData");
1971 tool->SetClientData(clientData);
1974void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
1975 wxToolBarToolBase *tool = FindById(
id);
1977 if (tool->Enable(enable)) {
1978 DoEnableTool(tool, enable);
1983 if (parent && parent->m_FloatingToolbarConfigMenu) {
1984 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
1985 if (configItem) configItem->Check(
true);
1989void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
1992 tool->SetTooltipHiviz(b_hiviz);
1996void ocpnToolBarSimple::ClearTools() {
1997 while (GetToolsCount()) {
2002int ocpnToolBarSimple::GetVisibleToolCount() {
2004 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2008 node = node->GetNext();
2013bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
2014 wxCHECK_MSG(pos < GetToolsCount(),
false,
2015 "invalid position in wxToolBar::DeleteToolByPos()");
2017 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
2019 if (!DoDeleteTool(pos, node->GetData())) {
2023 delete node->GetData();
2024 m_tools.Erase(node);
2029bool ocpnToolBarSimple::DeleteTool(
int id) {
2031 wxToolBarToolsList::compatibility_iterator node;
2032 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2033 if (node->GetData()->GetId() == id)
break;
2038 if (!node || !DoDeleteTool(pos, node->GetData())) {
2042 delete node->GetData();
2043 m_tools.Erase(node);
2048wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
2049 return InsertSeparator(GetToolsCount());
2052wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
2053 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
2054 "invalid position in wxToolBar::InsertSeparator()");
2056 wxToolBarToolBase *tool = CreateTool(
2057 wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap,
2058 wxITEM_SEPARATOR, (wxObject *)NULL, wxEmptyString, wxEmptyString);
2060 if (!tool || !DoInsertTool(pos, tool)) {
2066 m_tools.Insert(pos, tool);
2072wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
2074 wxToolBarToolsList::compatibility_iterator node;
2075 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2076 if (node->GetData()->GetId() == id)
break;
2084 return (wxToolBarToolBase *)NULL;
2087 wxToolBarToolBase *tool = node->GetData();
2088 if (!DoDeleteTool(pos, tool)) {
2089 return (wxToolBarToolBase *)NULL;
2092 m_tools.Erase(node);
2097wxControl *ocpnToolBarSimple::FindControl(
int id) {
2098 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2099 node; node = node->GetNext()) {
2100 const wxToolBarToolBase *
const tool = node->GetData();
2101 if (tool->IsControl()) {
2102 wxControl *
const control = tool->GetControl();
2105 wxFAIL_MSG(
"NULL control in toolbar?");
2106 }
else if (control->GetId() ==
id) {
2116wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
2117 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
2119 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2120 node; node = node->GetNext()) {
2121 tool = node->GetData();
2122 if (tool->GetId() == id) {
2139bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
2140 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
2144 event.SetInt((
int)toggleDown);
2147 event.SetExtraLong((
long)toggleDown);
2149 gFrame->GetEventHandler()->AddPendingEvent(event);
2155void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
2159 if (m_parentContainer) {
2160 if (m_parentContainer->m_FloatingToolbarConfigMenu) {
2163 wxDefaultPosition, wxSize(100, 100));
2164 int rc = dlg->ShowModal();
2167 if (rc == wxID_OK) {
2168 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
2169 event.SetEventObject(
this);
2172 gFrame->GetEventHandler()->AddPendingEvent(event);
2178void ocpnToolBarSimple::DoPluginToolUp() {
2181 if (!g_pi_manager)
return;
2183 ArrayOfPlugInToolbarTools tool_array =
2184 g_pi_manager->GetPluginToolbarToolArray();
2185 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
2187 if (m_last_plugin_down_id == pttc->id) {
2194 m_last_plugin_down_id = -1;
2197void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2198 const wxString &iconName) {
2204 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
2205 otool->m_width, otool->m_height);
2206 tool->SetNormalBitmap(bmp);
2207 otool->SetIconName(iconName);
2212void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
2217 otool->pluginNormalIconSVG = fileSVG;
2222void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
2223 wxBitmap *bmpRollover) {
2226 if (tool->isPluginTool) {
2227 if (bmp->GetWidth() != tool->GetWidth()) {
2229 wxImage ibmp = bmp->ConvertToImage();
2230 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2231 wxIMAGE_QUALITY_HIGH);
2232 wxBitmap sbmp = wxBitmap(ibmp);
2233 tool->pluginNormalIcon = sbmp;
2236 tool->pluginNormalIcon = *bmp;
2239 if (bmpRollover->GetWidth() != tool->GetWidth()) {
2240 if (bmpRollover->IsOk()) {
2241 wxImage ibmp = bmpRollover->ConvertToImage();
2242 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2243 wxIMAGE_QUALITY_HIGH);
2244 wxBitmap sbmp = wxBitmap(ibmp);
2245 tool->pluginRolloverIcon = sbmp;
2248 tool->pluginRolloverIcon = *bmpRollover;
2250 tool->bitmapOK =
false;
2253 tool->SetNormalBitmap(*bmp);
2254 tool->bitmapOK =
true;
2256 InvalidateBitmaps();
2260void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
2261 wxString fileSVGRollover,
2262 wxString fileSVGToggled) {
2265 tool->pluginNormalIconSVG = fileSVGNormal;
2266 tool->pluginRolloverIconSVG = fileSVGRollover;
2267 tool->pluginToggledIconSVG = fileSVGToggled;
2268 tool->bitmapOK =
false;
2269 InvalidateBitmaps();
2275ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
2276 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
2278 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
2280 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
2281 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2284 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
2285 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
2287 choices.push_back(
new wxRadioButton(
2288 this, 1, _(
"No, and permanently remove the option to hide it."),
2289 wxDefaultPosition));
2292 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
2294 wxStdDialogButtonSizer *buttonSizer =
2295 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2297 wxStaticText *textCtrl =
2298 new wxStaticText(
this, wxID_ANY,
2299 _(
"The Man Over Board button could be an important "
2300 "safety feature.\nAre you sure you want to hide it?"));
2302 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
2303 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
2304 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
2305 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
2306 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
2308 topSizer->SetSizeHints(
this);
2312int ToolbarMOBDialog::GetSelection() {
2313 for (
unsigned int i = 0; i < choices.size(); i++) {
2314 if (choices[i]->GetValue())
return choices[i]->GetId();
2334 const wxString &caption,
2336 const wxSize &size,
long style) {
2337 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
2338 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
2340 m_configMenu = NULL;
2341 m_ToolbarDialogAncestor = sponsor;
2343 if (m_ToolbarDialogAncestor)
2344 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
2347 GetSizer()->Fit(
this);
2352ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
2359 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
2360 SetSizer(itemBoxSizer1);
2362 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
2363 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
2364 itemDialog1->SetScrollRate(2, 2);
2366#ifdef __OCPN__ANDROID__
2371 wxString wqs = getFontQtStylesheet(qFont);
2372 wxCharBuffer sbuf = wqs.ToUTF8();
2373 QString qsb = QString(sbuf.data());
2375 QString qsbq = getQtStyleSheet();
2377 this->GetHandle()->setStyleSheet(qsb + qsbq);
2380 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
2382 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
2383 itemDialog1->SetSizer(itemBoxSizer2);
2385 wxStaticBox *itemStaticBoxSizer3Static =
2386 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Choose Toolbar Icons"));
2387 wxStaticBoxSizer *itemStaticBoxSizer3 =
2388 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
2389 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
2394 nitems = m_configMenu->GetMenuItemCount();
2397 for (
int i = 0; i < nitems; i++) {
2398 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon)
continue;
2399 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2401 wxString label = item->GetItemLabel();
2402 int l = label.Len();
2403 max_width = wxMax(max_width, l);
2405 wxString windowName =
"";
2406 if (item->GetId() == ID_MOB + 100) windowName =
"MOBCheck";
2409 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
2410 wxDefaultSize, 0, wxDefaultValidator, windowName);
2412 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
2413 cb->SetValue(item->IsChecked());
2415 cboxes.push_back(cb);
2419 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
2420 (nitems + 4) * GetCharHeight() * 2);
2422 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
2423 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
2425 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
2426 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
2428 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
2429 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
2432 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
2433 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2436 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
2437 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2438 m_OKButton->SetDefault();
2440 m_CancelButton->Connect(
2441 wxEVT_COMMAND_BUTTON_CLICKED,
2442 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL,
this);
2443 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2444 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
2447 SetColorScheme((ColorScheme)0);
2450void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
2452void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
2453 EndModal(wxID_CANCEL);
2456void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
2457 unsigned int ncheck = 0;
2459 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
2460 wxString new_toolbarConfig = toolbarConfigSave;
2462 for (
unsigned int i = 0; i < cboxes.size(); i++) {
2463 wxCheckBox *cb = cboxes[i];
2464 wxString cbName = cb->GetName();
2466 if (cbName.IsSameAs(
"MOBCheck") && !cb->IsChecked()) {
2469 int dialog_ret = mdlg.ShowModal();
2470 int answer = mdlg.GetSelection();
2471 if (dialog_ret == wxID_OK) {
2473 g_bPermanentMOBIcon =
true;
2475 }
else if (answer == 0) {
2479 new_toolbarConfig = toolbarConfigSave;
2484 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2485 if (new_toolbarConfig.Len() > i) {
2486 new_toolbarConfig.SetChar(i, cb->IsChecked() ? _T(
'X') : _T(
'.'));
2488 new_toolbarConfig.Append(cb->IsChecked() ? _T(
'X') : _T(
'.'));
2490 item->Check(cb->IsChecked());
2491 if (cb->IsChecked()) ncheck++;
2498 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN , _T(
'X') );
2500 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
2503 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
2505 item->Check(
true );
2509 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
2514void ToolbarChoicesDialog::RecalculateSize(
void) {
2515 wxSize esize = GetSize();
2518 wxSize dsize = GetParent()->GetClientSize();
2519 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
2520 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
2526 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
2527 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
2530#ifdef __OCPN__ANDROID__
2531 Move(GetPosition().x, 10);
Global state for AIS decoder.
Charts database management
Generic Chart canvas base.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
Device context class that can use either wxDC or OpenGL for drawing.
virtual void OnToolbarToolDownCallback(int id)
Handles toolbar button press.
virtual void OnToolbarToolUpCallback(int id)
Handles toolbar button release.
bool g_bsmoothpanzoom
Controls how the chart panning and zooming smoothing is done during user interactions.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.