52#include "user_colors.h"
55#include "androidUTIL.h"
63extern GLenum g_texture_rectangle_format;
71 const wxBitmap &bmpNormal,
const wxBitmap &bmpRollover,
72 wxItemKind kind, wxObject *clientData,
73 const wxString &shortHelp,
const wxString &longHelp)
74 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, label, bmpNormal,
75 bmpRollover, kind, clientData, shortHelp, longHelp) {
80 m_btooltip_hiviz =
false;
90 pluginNormalIcon = bmpNormal;
91 pluginRolloverIcon = bmpRollover;
96 const wxBitmap &bmpRollover, wxItemKind kind,
97 wxObject *clientData,
const wxString &shortHelp,
98 const wxString &longHelp)
99 : wxToolBarToolBase((wxToolBarBase *)tbar,
id,
"", bmpNormal, bmpRollover,
100 kind, clientData, shortHelp, longHelp) {
104 m_btooltip_hiviz =
false;
105 isPluginTool =
false;
107 m_bmpNormal = bmpNormal;
111 void SetSize(
const wxSize &size) {
116 wxCoord GetWidth()
const {
return m_width; }
118 wxCoord GetHeight()
const {
return m_height; }
120 wxString GetToolname() {
return toolname; }
122 void SetIconName(wxString name) { iconName = name; }
123 wxString GetIconName() {
return iconName; }
125 void SetTooltipHiviz(
bool enable) { m_btooltip_hiviz = enable; }
134 wxBitmap pluginNormalIcon;
135 wxBitmap pluginRolloverIcon;
136 const wxBitmap *pluginToggledIcon;
143 bool m_btooltip_hiviz;
145 wxString pluginNormalIconSVG;
146 wxString pluginRolloverIconSVG;
147 wxString pluginToggledIconSVG;
148 wxBitmap m_activeBitmap;
155ocpnFloatingToolbarDialog::ocpnFloatingToolbarDialog(wxWindow *parent,
165 m_position = position;
167 m_sizefactor = size_factor;
170 m_bAutoHideToolbar =
false;
171 m_nAutoHideToolbar = 5;
172 m_toolbar_scale_tools_shown =
false;
173 m_backcolorString =
"GREY3";
174 m_toolShowMask =
"XXXXXXXXXXXXXXXX";
175 n_toolbarHideMethod = TOOLBAR_HIDE_TO_GRABBER;
176 b_canToggleOrientation =
true;
177 m_enableRolloverBitmaps =
true;
180 m_ptoolbar = CreateNewToolbar();
181 if (m_ptoolbar) m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"GREY3"));
182 m_cs = (ColorScheme)-1;
184 m_style = g_StyleManager->GetCurrentStyle();
185 SetULDockPosition(wxPoint(4, g_maintoolbar_y));
187 SetGeometry(
false, wxRect());
196 m_marginsInvisible = m_style->marginsInvisible;
198 m_FloatingToolbarConfigMenu = NULL;
200 m_fade_timer.SetOwner(
this);
201 this->Connect(wxEVT_TIMER,
202 wxTimerEventHandler(ocpnFloatingToolbarDialog::FadeTimerEvent),
205 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
206 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
208 m_bsubmerged =
false;
209 m_benableSubmerge =
true;
212ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
213 delete m_FloatingToolbarConfigMenu;
218void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
219 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
220 if (g_bmasterToolbarFull) {
221 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) ) {
224 top_frame::Get()->GetAbstractPrimaryCanvas()->ScreenToClient(
225 ::wxGetMousePosition());
227 wxRect r = GetToolbarRect();
228 if (r.Contains(mp))
return;
230 wxCommandEvent event;
231 event.SetId(ID_MASTERTOGGLE);
232 top_frame::Get()->OnToolLeftClick(event);
239 m_Items.push_back(item);
242int ocpnFloatingToolbarDialog::RebuildToolbar() {
249 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
253 bool bEnabled = _toolbarConfigMenuUtil(tic);
256 wxToolBarToolBase *tool =
257 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
258 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
263 if (!tic->m_NormalIconSVG.IsEmpty()) {
264 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
265 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
275void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
276 if (position.x >= 0) m_dock_min_x = position.x;
277 if (position.y >= 0) m_dock_min_y = position.y;
280size_t ocpnFloatingToolbarDialog::GetToolCount() {
282 return m_ptoolbar->GetToolsCount();
287void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
289void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
291 m_ptoolbar->SetToolShowCount(count);
292 m_ptoolbar->SetDirty(
true);
296int ocpnFloatingToolbarDialog::GetToolShowCount() {
298 return m_ptoolbar->GetToolShowCount();
303void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
304 m_backcolorString = colorRef;
305 SetColorScheme(m_cs);
308void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
310void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
312void ocpnFloatingToolbarDialog::CreateConfigMenu() {
313 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
314 m_FloatingToolbarConfigMenu =
new wxMenu();
317bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
319 if (m_FloatingToolbarConfigMenu) {
320 wxMenuItem *menuitem;
322 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
324 if (tic->m_bRequired)
return true;
325 if (tic->m_bPlugin)
return true;
332 int menuItemId = tic->m_ID + idOffset;
334 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
337 return menuitem->IsChecked();
340 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
342 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
343 menuitem->Check(m_configString.Len() >= n
344 ? m_configString.GetChar(n - 1) ==
'X'
346 return menuitem->IsChecked();
351void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
352 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
355void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
357 wxColour back_color = GetGlobalColor(m_backcolorString);
360 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
361 m_ptoolbar->SetColorScheme(cs);
365wxSize ocpnFloatingToolbarDialog::GetToolSize() {
366 wxSize style_tool_size;
368 style_tool_size = m_style->GetToolSize();
370 style_tool_size.x *= m_sizefactor;
371 style_tool_size.y *= m_sizefactor;
373 style_tool_size.x = 32;
374 style_tool_size.y = 32;
377 return style_tool_size;
380void ocpnFloatingToolbarDialog::SetGeometry(
bool bAvoid, wxRect rectAvoid) {
382 wxSize style_tool_size = m_style->GetToolSize();
384 style_tool_size.x *= m_sizefactor;
385 style_tool_size.y *= m_sizefactor;
387 m_ptoolbar->SetToolBitmapSize(style_tool_size);
389 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
390 int grabber_width = m_style->GetIcon(
"grabber").GetWidth();
397 m_pparent->GetClientSize().x -
398 (tool_size.x + m_style->GetToolSeparation()) * 2;
399 if (bAvoid && !rectAvoid.IsEmpty()) {
400 avoid_start = m_pparent->GetClientSize().x - rectAvoid.width -
404 max_rows = (m_pparent->GetClientSize().y /
405 (tool_size.y + m_style->GetToolSeparation())) -
408 max_cols = (avoid_start - grabber_width) /
409 (tool_size.x + m_style->GetToolSeparation());
412 if (m_orient == wxTB_VERTICAL)
413 max_rows = wxMax(max_rows, 2);
415 max_cols = wxMax(max_cols, 2);
418 if (m_orient == wxTB_VERTICAL)
419 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
421 m_ptoolbar->SetMaxRowsCols(100, max_cols);
422 m_ptoolbar->SetSizeFactor(m_sizefactor);
426void ocpnFloatingToolbarDialog::SetDefaultPosition() {
429 if (m_pparent && m_ptoolbar) {
430 wxSize cs = m_pparent->GetClientSize();
432 m_position.x = m_dock_min_x;
433 else if (1 == m_dock_x)
434 m_position.x = cs.x - m_ptoolbar->m_maxWidth;
437 m_position.y = m_dock_min_y;
438 else if (1 == m_dock_y)
439 m_position.y = cs.y - m_ptoolbar->m_maxHeight;
441 m_position.x = wxMin(cs.x - m_ptoolbar->m_maxWidth, m_position.x);
442 m_position.y = wxMin(cs.y - m_ptoolbar->m_maxHeight, m_position.y);
444 m_position.x = wxMax(m_dock_min_x, m_position.x);
445 m_position.y = wxMax(m_dock_min_y, m_position.y);
447 m_position.y += m_auxOffsetY;
449 g_maintoolbar_x = m_position.x;
450 g_maintoolbar_y = m_position.y;
471void ocpnFloatingToolbarDialog::Submerge() {
474 if (m_ptoolbar) m_ptoolbar->KillTooltip();
477void ocpnFloatingToolbarDialog::HideTooltip() {
479 if (m_ptoolbar) m_ptoolbar->HideTooltip();
483void ocpnFloatingToolbarDialog::ShowTooltips() {
485 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
489void ocpnFloatingToolbarDialog::ToggleOrientation() {}
491wxRect ocpnFloatingToolbarDialog::GetToolbarRect() {
492 return wxRect(m_position.x, m_position.y, m_ptoolbar->m_maxWidth,
493 m_ptoolbar->m_maxHeight);
496wxSize ocpnFloatingToolbarDialog::GetToolbarSize() {
497 return wxSize(m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
500wxPoint ocpnFloatingToolbarDialog::GetToolbarPosition() {
501 return wxPoint(m_position.x, m_position.y);
504bool ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
505 if (g_disable_main_toolbar)
return false;
507 bool bproc = m_ptoolbar->OnMouseEvent(event, m_position);
508 if (bproc) m_ptoolbar->CreateBitmap();
514void ocpnFloatingToolbarDialog::RefreshToolbar() {
516 if (m_ptoolbar->IsDirty()) {
518 top_frame::Get()->GetAbstractPrimaryCanvas()->Refresh();
523void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
524 m_nAutoHideToolbar = time;
525 if (m_bAutoHideToolbar) {
527 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
531void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
532 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
533 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
537void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
538 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
541void ocpnFloatingToolbarDialog::Realize() {
543 m_ptoolbar->Realize();
544 m_ptoolbar->CreateBitmap();
545 m_toolbar_image.Destroy();
549void ocpnFloatingToolbarDialog::DrawDC(
ocpnDC &dc,
double displayScale) {
551 m_ptoolbar->CreateBitmap();
552 if (m_ptoolbar->GetBitmap().IsOk()) {
553 dc.DrawBitmap(m_ptoolbar->GetBitmap(), m_position.x, m_position.y,
false);
554 m_ptoolbar->SetDirty(
false);
559void ocpnFloatingToolbarDialog::DrawGL(
ocpnDC &gldc,
double displayScale) {
560 if (g_disable_main_toolbar)
return;
563 if (!m_ptoolbar)
return;
565 wxColour backColor = GetGlobalColor(
"GREY3");
566 gldc.SetBrush(wxBrush(backColor));
567 gldc.SetPen(wxPen(backColor));
569 wxRect r = GetToolbarRect();
570 int m_end_margin = wxMin(GetToolSize().x, GetToolSize().y) / 8;
572 if (m_orient == wxHORIZONTAL)
573 gldc.DrawRoundedRectangle(
574 (r.x - m_end_margin / 2) * displayScale, (r.y - 1) * displayScale,
575 (r.width + m_end_margin) * displayScale, (r.height + 2) * displayScale,
576 (m_end_margin * 1) * displayScale);
578 gldc.DrawRoundedRectangle(
579 (r.x - 1) * displayScale, (r.y - m_end_margin / 2) * displayScale,
580 (r.width + 2) * displayScale, (r.height + m_end_margin) * displayScale,
581 (m_end_margin * 1.5) * displayScale);
583 int width = GetToolbarSize().x;
584 int height = GetToolbarSize().y;
586 m_ptoolbar->CreateBitmap(displayScale);
590 glGenTextures(1, &m_texture);
592 glBindTexture(g_texture_rectangle_format, m_texture);
593 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
595 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
597 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
599 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
602 glBindTexture(g_texture_rectangle_format, m_texture);
605 if (!m_toolbar_image.IsOk()) {
607 m_toolbar_image = m_ptoolbar->GetBitmap().ConvertToImage();
609 unsigned char *d = m_toolbar_image.GetData();
610 unsigned char *e =
new unsigned char[4 * width * height];
611 for (
int y = 0; y < height; y++)
612 for (
int x = 0; x < width; x++) {
613 int i = y * width + x;
614 memcpy(e + 4 * i, d + 3 * i, 3);
617 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, width, height, 0,
618 GL_RGBA, GL_UNSIGNED_BYTE, e);
620 glDisable(g_texture_rectangle_format);
626 glEnable(g_texture_rectangle_format);
627 glBindTexture(g_texture_rectangle_format, m_texture);
630 int x0 = GetToolbarPosition().x, x1 = x0 + width;
631 int y0 = GetToolbarPosition().y - 0, y1 = y0 + height;
638 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
639 tx = width, ty = height;
666 m_callbacks.render_gl_textures(gldc, coords, uv);
667 glDisable(g_texture_rectangle_format);
668 glBindTexture(g_texture_rectangle_format, 0);
676void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
680 m_pparent->GetEventHandler()->AddPendingEvent(event);
682 wxTheApp->GetTopWindow()->Raise();
688 m_ptoolbar = CreateNewToolbar();
695 long winstyle = wxNO_BORDER | wxTB_FLAT;
696 winstyle |= m_orient;
703 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
704 m_ptoolbar->SetColorScheme(m_cs);
705 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
710void ocpnFloatingToolbarDialog::DestroyToolBar() {
711 g_toolbarConfig = GetToolConfigString();
714 m_ptoolbar->ClearTools();
719 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
729 int n_tools = tb->GetToolsCount();
733 ArrayOfPlugInToolbarTools tool_array =
736 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
738 if (pttc->position == n_tools) {
742 case GLOBAL_COLOR_SCHEME_DAY:
743 ptool_bmp = pttc->bitmap_day;
746 case GLOBAL_COLOR_SCHEME_DUSK:
747 ptool_bmp = pttc->bitmap_dusk;
749 case GLOBAL_COLOR_SCHEME_NIGHT:
750 ptool_bmp = pttc->bitmap_night;
753 ptool_bmp = pttc->bitmap_day;
758 wxToolBarToolBase *tool =
759 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
760 wxString(pttc->shortHelp), pttc->kind);
762 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
763 pttc->pluginRolloverIconSVG,
764 pttc->pluginToggledIconSVG);
773 while (CheckAndAddPlugInTool(tb)) {
779void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
780 m_enableRolloverBitmaps = bEnable;
781 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
791EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
792EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
800 int id, const wxString &label, const wxBitmap &bmpNormal,
801 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
802 const wxString &shortHelp, const wxString &longHelp) {
803 if (m_style->NativeToolIconExists(label)) {
804 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
805 clientData, shortHelp, longHelp);
807 wxString testToolname =
g_pi_manager->GetToolOwnerCommonName(
id);
809 if (testToolname ==
"") {
811 clientData, shortHelp, longHelp);
813 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
814 clientData, shortHelp, longHelp);
823void ocpnToolBarSimple::Init() {
824 m_currentRowsOrColumns = 0;
826 m_lastX = m_lastY = 0;
828 m_maxWidth = m_maxHeight = 0;
830 m_pressedTool = m_currentTool = -1;
832 m_xPos = m_yPos = wxDefaultCoord;
834 m_style = g_StyleManager->GetCurrentStyle();
837 m_defaultHeight = 15;
839 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
840 m_toolOutlineColour.Set(
"BLACK");
841 m_last_ro_tool = NULL;
843 m_btoolbar_is_zooming =
false;
846 m_last_plugin_down_id = -1;
849 m_btooltip_show =
false;
853 m_tbenableRolloverBitmaps =
false;
856wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
857 int id,
const wxString &label,
const wxBitmap &bitmap,
858 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
859 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
866 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
867 shortHelp, longHelp, clientData);
872wxToolBarToolBase *ocpnToolBarSimple::AddTool(
873 int toolid,
const wxString &label,
const wxBitmap &bitmap,
874 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
875 const wxString &longHelp, wxObject *data) {
878 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
883wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
884 size_t pos,
int id,
const wxString &label,
const wxBitmap &bitmap,
885 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
886 const wxString &longHelp, wxObject *clientData) {
887 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
888 "invalid position in wxToolBar::InsertTool()");
890 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
891 clientData, shortHelp, longHelp);
893 if (!InsertTool(pos, tool)) {
902wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
903 wxToolBarToolBase *tool) {
904 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
905 "invalid position in wxToolBar::InsertTool()");
907 if (!tool || !DoInsertTool(pos, tool)) {
911 m_tools.Insert(pos, tool);
917bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
918 wxToolBarToolBase *toolBase) {
924 if (tool->isPluginTool) {
925 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
926 if (tool->GetToolname() ==
928 tool->toolname <<
"1";
934 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
937 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
939 if (tool->IsButton()) {
940 tool->SetSize(GetToolSize());
943 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
944 m_style->GetLeftMargin()) > m_maxWidth)
946 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
948 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
949 m_style->GetTopMargin()) > m_maxHeight)
951 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
954 else if (tool->IsControl()) {
955 tool->SetSize(tool->GetControl()->GetSize());
958 tool->b_hilite =
false;
963bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
964 wxToolBarToolBase *tool) {
968 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
976 const wxPoint &pos,
const wxSize &size,
977 long style,
int orient) {
978 m_parentContainer = parent;
997 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
998 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
999 m_tooltip_off = 3000;
1001 m_tbenableRolloverBitmaps =
false;
1006ocpnToolBarSimple::~ocpnToolBarSimple() {}
1008void ocpnToolBarSimple::EnableTooltips() {
1010 m_btooltip_show =
true;
1014void ocpnToolBarSimple::DisableTooltips() {
1016 ocpnToolBarSimple::m_btooltip_show =
false;
1020void ocpnToolBarSimple::KillTooltip() {
1021 m_btooltip_show =
false;
1024 m_tooltip_timer.Stop();
1026 wxTheApp->GetTopWindow()->Raise();
1027 top_frame::Get()->GetAbstractFocusCanvas()->TriggerDeferredFocus();
1030void ocpnToolBarSimple::HideTooltip() {
1036void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1040 m_toolOutlineColour = GetGlobalColor(
"UIBDR");
1042 m_currentColorScheme = cs;
1045bool ocpnToolBarSimple::Realize() {
1047 m_style->SetOrientation(wxTB_VERTICAL);
1049 m_style->SetOrientation(wxTB_HORIZONTAL);
1051 wxSize toolSize = wxSize(-1, -1);
1052 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1053 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1054 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1056 m_currentRowsOrColumns = 0;
1058 m_lastX = leftMargin;
1059 m_lastY = topMargin;
1064 bool firstNode =
true;
1065 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1070 if (iNode >= m_nShowTools)
break;
1076 if (toolSize.x == -1) {
1077 if (!tool->IsSeparator()) {
1078 toolSize.x = tool->m_width;
1079 toolSize.y = tool->m_height;
1083 tool->firstInLine = firstNode;
1084 tool->lastInLine =
false;
1087 tool->last_rect.width = 0;
1089 if (tool->IsSeparator()) {
1098 if (m_currentRowsOrColumns >= m_maxRows)
1099 m_lastX += separatorSize;
1101 m_lastY += separatorSize;
1103 }
else if (tool->IsButton()) {
1104 if (!IsVertical()) {
1105 if (m_currentRowsOrColumns >= m_maxCols) {
1106 tool->firstInLine =
true;
1107 if (lastTool && m_LineCount > 1) lastTool->lastInLine =
true;
1109 m_currentRowsOrColumns = 0;
1110 m_lastX = leftMargin;
1111 m_lastY += toolSize.y + topMargin;
1113 tool->m_x = (wxCoord)m_lastX;
1114 tool->m_y = (wxCoord)m_lastY;
1116 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1117 tool->trect.Inflate(separatorSize / 2, topMargin);
1119 m_lastX += toolSize.x + separatorSize;
1121 if (m_currentRowsOrColumns >= m_maxRows) {
1122 tool->firstInLine =
true;
1123 if (lastTool) lastTool->lastInLine =
true;
1125 m_currentRowsOrColumns = 0;
1126 m_lastX += toolSize.x + leftMargin;
1127 m_lastY = topMargin;
1129 tool->m_x = (wxCoord)m_lastX;
1130 tool->m_y = (wxCoord)m_lastY;
1132 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1133 tool->trect.Inflate((separatorSize / 2), topMargin);
1135 m_lastY += toolSize.y + separatorSize;
1137 m_currentRowsOrColumns++;
1152 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
1153 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
1156 node = node->GetNext();
1159 if (lastTool && (m_LineCount > 1 || IsVertical()))
1160 lastTool->lastInLine =
true;
1162 if (!IsVertical()) {
1163 m_maxHeight += toolSize.y;
1164 m_maxHeight += m_style->GetBottomMargin();
1166 m_maxWidth += toolSize.x;
1167 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
1170 m_bitmap = wxNullBitmap;
1175wxBitmap &ocpnToolBarSimple::CreateBitmap(
double display_scale) {
1176 if (m_bitmap.IsOk())
return m_bitmap;
1179 int width = m_maxWidth;
1180 int height = m_maxHeight;
1183 wxBitmap bm(width, height);
1184 mdc.SelectObject(bm);
1185 mdc.SetBackground(wxBrush(GetBackgroundColour()));
1189 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1190 node; node = node->GetNext()) {
1191 wxToolBarToolBase *tool = node->GetData();
1193 wxRect toolRect = tools->trect;
1194 CreateToolBitmap(tool);
1196 if (tools->m_activeBitmap.IsOk()) {
1197 mdc.DrawBitmap(tools->m_activeBitmap, tools->m_x, tools->m_y,
false);
1202 mdc.SelectObject(wxNullBitmap);
1208void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
1209 if (!top_frame::Get())
1214 if (m_btooltip_show ) {
1215 if (m_last_ro_tool) {
1216 wxString s = m_last_ro_tool->GetShortHelp();
1220 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
1221 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
1223 wxPoint screenPosition =
1224 top_frame::Get()->GetAbstractPrimaryCanvas()->ClientToScreen(
1229 top_frame::Get()->GetAbstractPrimaryCanvas()->GetWindow(), s,
1230 screenPosition, m_last_ro_tool->m_btooltip_hiviz);
1233 wxTheApp->GetTopWindow()->Raise();
1237 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1244void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
1248bool ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event, wxPoint &position) {
1250 event.GetPosition(&x, &y);
1253 wxRect r = wxRect(position, wxSize(m_maxWidth, m_maxHeight));
1254 if (!r.Contains(x, y)) {
1259 m_parentContainer->RefreshFadeTimer();
1262 (
ocpnToolBarTool *)FindToolForPosition(x - position.x, y - position.y);
1264 m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1267 m_tooltipoff_timer.Stop();
1270 if (tool && tool->IsButton() ) {
1271 if (m_btooltip_show) {
1272 if (tool != m_last_ro_tool) {
1278 if (!m_tooltip_timer.IsRunning()) {
1279 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
1286 m_last_ro_tool = tool;
1289 if (event.LeftIsDown()) m_leftDown =
true;
1291 if (event.LeftDown() && tool->IsEnabled()) {
1292 if (tool->CanBeToggled()) {
1294 tool->bitmapOK =
false;
1296 m_bitmap = wxNullBitmap;
1302 ArrayOfPlugInToolbarTools tool_array =
1304 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1306 if (tool->GetId() == pttc->id) {
1311 m_last_plugin_down_id = pttc->id;
1316 }
else if (event.RightDown()) {
1317 OnRightClick(tool->GetId(), x, y);
1330 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
1332 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
1333 tool->CanBeToggled()) {
1337 tool->bitmapOK =
false;
1352void ocpnToolBarSimple::CreateToolBitmap(wxToolBarToolBase *toolBase) {
1355 wxBitmap bmp = wxNullBitmap;
1357 bool bNeedClear = !tool->bitmapOK;
1359 if (tool->bitmapOK) {
1360 if (tool->IsEnabled()) {
1361 bmp = tool->GetNormalBitmap();
1364 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1365 tool->rollover, tool->m_width, tool->m_height);
1366 tool->SetNormalBitmap(bmp);
1367 tool->bitmapOK =
true;
1370 bmp = tool->GetDisabledBitmap();
1372 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1373 false, tool->m_width, tool->m_height);
1374 tool->SetDisabledBitmap(bmp);
1375 tool->bitmapOK =
true;
1379 if (tool->isPluginTool) {
1380 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1387 wxString svgFile = tool->pluginNormalIconSVG;
1389 if (tool->pluginToggledIconSVG.Length())
1390 svgFile = tool->pluginToggledIconSVG;
1392 if (tool->rollover) {
1393 if (tool->pluginRolloverIconSVG.Length())
1394 svgFile = tool->pluginRolloverIconSVG;
1397 if (!svgFile.IsEmpty()) {
1399 bmp =
LoadSVG(svgFile, tool->m_width, tool->m_height);
1401 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1404 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1408 if (!bmp.IsOk() || bmp.IsNull()) {
1409 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1410 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1411 tool->rollover, tool->m_width,
1419 bmp = tool->pluginNormalIcon;
1420 if (fabs(m_sizefactor - 1.0) > 0.01) {
1421 if (tool->m_width && tool->m_height) {
1422 wxImage scaled_image = bmp.ConvertToImage();
1423 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1424 wxIMAGE_QUALITY_HIGH));
1429 tool->SetNormalBitmap(bmp);
1430 tool->bitmapOK =
true;
1432 bmp = tool->GetNormalBitmap();
1433 if (tool->IsEnabled()) {
1434 if (tool->IsToggled()) {
1435 if (!tool->bitmapOK) {
1436 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1437 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1438 tool->rollover, tool->m_width,
1440 tool->SetNormalBitmap(bmp);
1446 if (!tool->bitmapOK) {
1447 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1448 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1449 tool->rollover, tool->m_width,
1451 tool->SetNormalBitmap(bmp);
1456 tool->bitmapOK =
true;
1458 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1459 false, tool->m_width, tool->m_height);
1460 tool->SetDisabledBitmap(bmp);
1461 tool->bitmapOK =
true;
1465 tool->m_activeBitmap = bmp;
1471void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
1475 wxPoint drawAt(tool->m_x, tool->m_y);
1476 wxBitmap bmp = wxNullBitmap;
1478 bool bNeedClear = !tool->bitmapOK;
1480 if (tool->bitmapOK) {
1481 if (tool->IsEnabled()) {
1482 bmp = tool->GetNormalBitmap();
1485 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1486 tool->rollover, tool->m_width, tool->m_height);
1487 tool->SetNormalBitmap(bmp);
1488 tool->bitmapOK =
true;
1491 bmp = tool->GetDisabledBitmap();
1493 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1494 false, tool->m_width, tool->m_height);
1495 tool->SetDisabledBitmap(bmp);
1496 tool->bitmapOK =
true;
1500 if (tool->isPluginTool) {
1501 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1508 wxString svgFile = tool->pluginNormalIconSVG;
1510 if (tool->pluginToggledIconSVG.Length())
1511 svgFile = tool->pluginToggledIconSVG;
1513 if (tool->rollover) {
1514 if (tool->pluginRolloverIconSVG.Length())
1515 svgFile = tool->pluginRolloverIconSVG;
1518 if (!svgFile.IsEmpty()) {
1520 bmp =
LoadSVG(svgFile, tool->m_width, tool->m_height);
1522 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1525 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1529 if (!bmp.IsOk() || bmp.IsNull()) {
1530 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1531 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1532 tool->rollover, tool->m_width,
1539 if (tool->rollover) {
1541 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
1544 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1547 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1549 if (fabs(m_sizefactor - 1.0) > 0.01) {
1550 if (tool->m_width && tool->m_height) {
1551 wxImage scaled_image = bmp.ConvertToImage();
1552 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1553 wxIMAGE_QUALITY_HIGH));
1558 tool->SetNormalBitmap(bmp);
1559 tool->bitmapOK =
true;
1561 bmp = tool->GetNormalBitmap();
1562 if (tool->IsEnabled()) {
1563 if (tool->IsToggled()) {
1564 if (!tool->bitmapOK) {
1565 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1566 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1567 tool->rollover, tool->m_width,
1569 tool->SetNormalBitmap(bmp);
1575 if (!tool->bitmapOK) {
1576 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1577 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1578 tool->rollover, tool->m_width,
1580 tool->SetNormalBitmap(bmp);
1585 tool->bitmapOK =
true;
1587 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1588 false, tool->m_width, tool->m_height);
1589 tool->SetDisabledBitmap(bmp);
1590 tool->bitmapOK =
true;
1595 if (tool->firstInLine) {
1596 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
1598 if (tool->lastInLine) {
1599 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
1602 if (bmp.GetWidth() != m_style->GetToolSize().x ||
1603 bmp.GetHeight() != m_style->GetToolSize().y) {
1609 if ((tool->last_rect.width &&
1610 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
1612 wxBrush bb(GetGlobalColor(
"GREY3"));
1614 dc.SetPen(*wxTRANSPARENT_PEN);
1615 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
1616 tool->last_rect.width, tool->last_rect.height);
1623 wxImage scaled_image = bmp.ConvertToImage();
1624 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1625 wxIMAGE_QUALITY_HIGH));
1626 dc.DrawBitmap(sbmp, drawAt);
1628 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
1631 dc.DrawBitmap(bmp, drawAt);
1633 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
1641wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
1643 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1646 if ((x >= tool->m_x) && (y >= tool->m_y) &&
1647 (x < (tool->m_x + tool->GetWidth())) &&
1648 (y < (tool->m_y + tool->GetHeight()))) {
1652 node = node->GetNext();
1655 return (wxToolBarToolBase *)NULL;
1658void ocpnToolBarSimple::InvalidateBitmaps() {
1659 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1662 tool->bitmapOK =
false;
1663 node = node->GetNext();
1665 m_bitmap = wxNullBitmap;
1668wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
1670 wxToolBarToolBase *tool = FindById(tool_id);
1673 if (otool) rect = otool->trect;
1683void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
1684 bool WXUNUSED(enable)) {
1686 t->bitmapOK =
false;
1689void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
1690 bool WXUNUSED(toggle)) {
1692 t->bitmapOK =
false;
1700wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
1701 wxToolBarToolBase *tool = FindById(
id);
1702 wxCHECK_MSG(tool,
"",
"no such tool");
1704 return tool->GetShortHelp();
1707wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
1708 wxToolBarToolBase *tool = FindById(
id);
1709 wxCHECK_MSG(tool,
"",
"no such tool");
1711 return tool->GetLongHelp();
1714void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
1715 wxToolBarToolBase *tool = FindById(
id);
1717 (void)tool->SetShortHelp(help);
1721void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
1722 wxToolBarToolBase *tool = FindById(
id);
1724 (void)tool->SetLongHelp(help);
1728int ocpnToolBarSimple::GetToolPos(
int id)
const {
1730 wxToolBarToolsList::compatibility_iterator node;
1732 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1733 if (node->GetData()->GetId() == id)
return pos;
1740bool ocpnToolBarSimple::GetToolState(
int id)
const {
1741 wxToolBarToolBase *tool = FindById(
id);
1742 wxCHECK_MSG(tool,
false,
"no such tool");
1744 return tool->IsToggled();
1747bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
1748 wxToolBarToolBase *tool = FindById(
id);
1749 wxCHECK_MSG(tool,
false,
"no such tool");
1751 return tool->IsEnabled();
1754void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
1755 wxToolBarToolBase *tool = FindById(
id);
1757 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
1758 DoToggleTool(tool, toggle);
1759 InvalidateBitmaps();
1760 top_frame::Get()->GetAbstractPrimaryCanvas()->Refresh(
true);
1764wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
1765 wxToolBarToolBase *tool = FindById(
id);
1766 return tool ? tool->GetClientData() : (wxObject *)NULL;
1769void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
1770 wxToolBarToolBase *tool = FindById(
id);
1772 wxCHECK_RET(tool,
"no such tool in wxToolBar::SetToolClientData");
1774 tool->SetClientData(clientData);
1777void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
1778 wxToolBarToolBase *tool = FindById(
id);
1780 if (tool->Enable(enable)) {
1781 DoEnableTool(tool, enable);
1786 if (parent && parent->m_FloatingToolbarConfigMenu) {
1787 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
1788 if (configItem) configItem->Check(
true);
1792void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
1795 tool->SetTooltipHiviz(b_hiviz);
1799void ocpnToolBarSimple::ClearTools() {
1800 while (GetToolsCount()) {
1805int ocpnToolBarSimple::GetVisibleToolCount() {
1807 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1811 node = node->GetNext();
1816bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
1817 wxCHECK_MSG(pos < GetToolsCount(),
false,
1818 "invalid position in wxToolBar::DeleteToolByPos()");
1820 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
1822 if (!DoDeleteTool(pos, node->GetData())) {
1826 delete node->GetData();
1827 m_tools.Erase(node);
1832bool ocpnToolBarSimple::DeleteTool(
int id) {
1834 wxToolBarToolsList::compatibility_iterator node;
1835 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1836 if (node->GetData()->GetId() == id)
break;
1841 if (!node || !DoDeleteTool(pos, node->GetData())) {
1845 delete node->GetData();
1846 m_tools.Erase(node);
1851wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
1852 return InsertSeparator(GetToolsCount());
1855wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
1856 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1857 "invalid position in wxToolBar::InsertSeparator()");
1859 wxToolBarToolBase *tool =
1860 CreateTool(wxID_SEPARATOR,
"", wxNullBitmap, wxNullBitmap,
1861 wxITEM_SEPARATOR, (wxObject *)NULL,
"",
"");
1863 if (!tool || !DoInsertTool(pos, tool)) {
1869 m_tools.Insert(pos, tool);
1875wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
1877 wxToolBarToolsList::compatibility_iterator node;
1878 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1879 if (node->GetData()->GetId() == id)
break;
1887 return (wxToolBarToolBase *)NULL;
1890 wxToolBarToolBase *tool = node->GetData();
1891 if (!DoDeleteTool(pos, tool)) {
1892 return (wxToolBarToolBase *)NULL;
1895 m_tools.Erase(node);
1900wxControl *ocpnToolBarSimple::FindControl(
int id) {
1901 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1902 node; node = node->GetNext()) {
1903 const wxToolBarToolBase *
const tool = node->GetData();
1904 if (tool->IsControl()) {
1905 wxControl *
const control = tool->GetControl();
1908 wxFAIL_MSG(
"NULL control in toolbar?");
1909 }
else if (control->GetId() ==
id) {
1919wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
1920 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
1922 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1923 node; node = node->GetNext()) {
1924 tool = node->GetData();
1925 if (tool->GetId() == id) {
1942bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
1943 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
1947 event.SetInt((
int)toggleDown);
1950 event.SetExtraLong((
long)toggleDown);
1952 top_frame::Get()->GetEventHandler()->AddPendingEvent(event);
1958void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
1962 if (m_parentContainer) {
1963 if (m_parentContainer->m_FloatingToolbarConfigMenu) {
1966 wxDefaultPosition, wxSize(100, 100));
1967 int rc = dlg->ShowModal();
1970 if (rc == wxID_OK) {
1971 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
1972 event.SetEventObject(
this);
1975 top_frame::Get()->GetEventHandler()->AddPendingEvent(event);
1981void ocpnToolBarSimple::DoPluginToolUp() {
1986 ArrayOfPlugInToolbarTools tool_array =
1988 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1990 if (m_last_plugin_down_id == pttc->id) {
1997 m_last_plugin_down_id = -1;
2000void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2001 const wxString &iconName) {
2007 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
2008 otool->m_width, otool->m_height);
2009 tool->SetNormalBitmap(bmp);
2010 otool->SetIconName(iconName);
2015void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
2020 otool->pluginNormalIconSVG = fileSVG;
2025void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
2026 wxBitmap *bmpRollover) {
2029 if (tool->isPluginTool) {
2030 if (bmp->GetWidth() != tool->GetWidth()) {
2032 wxImage ibmp = bmp->ConvertToImage();
2033 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2034 wxIMAGE_QUALITY_HIGH);
2035 wxBitmap sbmp = wxBitmap(ibmp);
2036 tool->pluginNormalIcon = sbmp;
2039 tool->pluginNormalIcon = *bmp;
2042 if (bmpRollover->GetWidth() != tool->GetWidth()) {
2043 if (bmpRollover->IsOk()) {
2044 wxImage ibmp = bmpRollover->ConvertToImage();
2045 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2046 wxIMAGE_QUALITY_HIGH);
2047 wxBitmap sbmp = wxBitmap(ibmp);
2048 tool->pluginRolloverIcon = sbmp;
2051 tool->pluginRolloverIcon = *bmpRollover;
2053 tool->bitmapOK =
false;
2056 tool->SetNormalBitmap(*bmp);
2057 tool->bitmapOK =
true;
2059 InvalidateBitmaps();
2063void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
2064 wxString fileSVGRollover,
2065 wxString fileSVGToggled) {
2068 tool->pluginNormalIconSVG = fileSVGNormal;
2069 tool->pluginRolloverIconSVG = fileSVGRollover;
2070 tool->pluginToggledIconSVG = fileSVGToggled;
2071 tool->bitmapOK =
false;
2072 InvalidateBitmaps();
2078ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
2079 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
2081 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
2083 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
2084 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2087 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
2088 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
2090 choices.push_back(
new wxRadioButton(
2091 this, 1, _(
"No, and permanently remove the option to hide it."),
2092 wxDefaultPosition));
2095 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
2097 wxStdDialogButtonSizer *buttonSizer =
2098 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2100 wxStaticText *textCtrl =
2101 new wxStaticText(
this, wxID_ANY,
2102 _(
"The Man Over Board button could be an important "
2103 "safety feature.\nAre you sure you want to hide it?"));
2105 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
2106 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
2107 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
2108 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
2109 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
2111 topSizer->SetSizeHints(
this);
2115int ToolbarMOBDialog::GetSelection() {
2116 for (
unsigned int i = 0; i < choices.size(); i++) {
2117 if (choices[i]->GetValue())
return choices[i]->GetId();
2137 const wxString &caption,
2139 const wxSize &size,
long style) {
2140 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
2141 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
2143 m_configMenu = NULL;
2144 m_ToolbarDialogAncestor = sponsor;
2146 if (m_ToolbarDialogAncestor)
2147 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
2150 GetSizer()->Fit(
this);
2155ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
2162 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
2163 SetSizer(itemBoxSizer1);
2165 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
2166 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
2167 itemDialog1->SetScrollRate(2, 2);
2174 wxString wqs = getFontQtStylesheet(qFont);
2175 wxCharBuffer sbuf = wqs.ToUTF8();
2176 QString qsb = QString(sbuf.data());
2178 QString qsbq = getQtStyleSheet();
2180 this->GetHandle()->setStyleSheet(qsb + qsbq);
2183 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
2185 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
2186 itemDialog1->SetSizer(itemBoxSizer2);
2188 wxStaticBox *itemStaticBoxSizer3Static =
2189 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Choose Toolbar Icons"));
2190 wxStaticBoxSizer *itemStaticBoxSizer3 =
2191 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
2192 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
2197 nitems = m_configMenu->GetMenuItemCount();
2200 for (
int i = 0; i < nitems; i++) {
2201 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon)
continue;
2202 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2204 wxString label = item->GetItemLabel();
2205 int l = label.Len();
2206 max_width = wxMax(max_width, l);
2208 wxString windowName =
"";
2209 if (item->GetId() == ID_MOB + 100) windowName =
"MOBCheck";
2212 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
2213 wxDefaultSize, 0, wxDefaultValidator, windowName);
2215 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
2216 cb->SetValue(item->IsChecked());
2218 cboxes.push_back(cb);
2222 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
2223 (nitems + 4) * GetCharHeight() * 2);
2225 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
2226 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
2228 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
2229 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
2231 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
2232 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
2235 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
2236 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2239 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
2240 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2241 m_OKButton->SetDefault();
2243 m_CancelButton->Connect(
2244 wxEVT_COMMAND_BUTTON_CLICKED,
2245 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL,
this);
2246 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2247 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
2250 SetColorScheme((ColorScheme)0);
2253void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
2255void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
2256 EndModal(wxID_CANCEL);
2259void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
2260 unsigned int ncheck = 0;
2262 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
2263 wxString new_toolbarConfig = toolbarConfigSave;
2265 for (
unsigned int i = 0; i < cboxes.size(); i++) {
2266 wxCheckBox *cb = cboxes[i];
2267 wxString cbName = cb->GetName();
2269 if (cbName.IsSameAs(
"MOBCheck") && !cb->IsChecked()) {
2272 int dialog_ret = mdlg.ShowModal();
2273 int answer = mdlg.GetSelection();
2274 if (dialog_ret == wxID_OK) {
2276 g_bPermanentMOBIcon =
true;
2278 }
else if (answer == 0) {
2282 new_toolbarConfig = toolbarConfigSave;
2287 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2288 if (new_toolbarConfig.Len() > i) {
2289 new_toolbarConfig.SetChar(i, cb->IsChecked() ?
'X' :
'.');
2291 new_toolbarConfig.Append(cb->IsChecked() ?
'X' :
'.');
2293 item->Check(cb->IsChecked());
2294 if (cb->IsChecked()) ncheck++;
2301 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN ,
'X' );
2303 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
2306 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
2308 item->Check(
true );
2312 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
2317void ToolbarChoicesDialog::RecalculateSize() {
2318 wxSize esize = GetSize();
2321 wxSize dsize = GetParent()->GetClientSize();
2322 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
2323 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
2329 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
2330 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
2334 Move(GetPosition().x, 10);
Global state for AIS decoder.
Charts database management
Generic Chart canvas base.
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.
Global variables stored in configuration file.
OpenGL chart rendering canvas.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
GUI constant definitions.
PlugInManager * g_pi_manager
Global instance.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.
wxBitmap LoadSVG(const wxString filename, const unsigned int width, const unsigned int height, wxBitmap *default_bitmap, bool use_cache)
Load SVG file and return it's bitmap representation of requested size In case file can't be loaded an...
Abstract gFrame/MyFrame interface.