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();
186 SetULDockPosition(wxPoint(4, g_maintoolbar_y));
188 SetULDockPosition(wxPoint(4, 4));
191 SetGeometry(
false, wxRect());
200 m_marginsInvisible = m_style->marginsInvisible;
202 m_FloatingToolbarConfigMenu = NULL;
204 m_fade_timer.SetOwner(
this);
205 this->Connect(wxEVT_TIMER,
206 wxTimerEventHandler(ocpnFloatingToolbarDialog::FadeTimerEvent),
209 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
210 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
212 m_bsubmerged =
false;
213 m_benableSubmerge =
true;
216ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
217 delete m_FloatingToolbarConfigMenu;
222void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
223 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
224 if (g_bmasterToolbarFull) {
225 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) ) {
228 top_frame::Get()->GetAbstractPrimaryCanvas()->ScreenToClient(
229 ::wxGetMousePosition());
231 wxRect r = GetToolbarRect();
232 if (r.Contains(mp))
return;
234 wxCommandEvent event;
235 event.SetId(ID_MASTERTOGGLE);
236 top_frame::Get()->OnToolLeftClick(event);
243 m_Items.push_back(item);
246int ocpnFloatingToolbarDialog::RebuildToolbar() {
253 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
257 bool bEnabled = _toolbarConfigMenuUtil(tic);
260 wxToolBarToolBase *tool =
261 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
262 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
267 if (!tic->m_NormalIconSVG.IsEmpty()) {
268 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
269 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
279void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
280 if (position.x >= 0) m_dock_min_x = position.x;
281 if (position.y >= 0) m_dock_min_y = position.y;
284size_t ocpnFloatingToolbarDialog::GetToolCount() {
286 return m_ptoolbar->GetToolsCount();
291void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
293void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
295 m_ptoolbar->SetToolShowCount(count);
296 m_ptoolbar->SetDirty(
true);
300int ocpnFloatingToolbarDialog::GetToolShowCount() {
302 return m_ptoolbar->GetToolShowCount();
307void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
308 m_backcolorString = colorRef;
309 SetColorScheme(m_cs);
312void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
314void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
316void ocpnFloatingToolbarDialog::CreateConfigMenu() {
317 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
318 m_FloatingToolbarConfigMenu =
new wxMenu();
321bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
323 if (m_FloatingToolbarConfigMenu) {
324 wxMenuItem *menuitem;
326 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
328 if (tic->m_bRequired)
return true;
329 if (tic->m_bPlugin)
return true;
336 int menuItemId = tic->m_ID + idOffset;
338 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
341 return menuitem->IsChecked();
344 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
346 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
347 menuitem->Check(m_configString.Len() >= n
348 ? m_configString.GetChar(n - 1) ==
'X'
350 return menuitem->IsChecked();
355void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
356 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
359void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
361 wxColour back_color = GetGlobalColor(m_backcolorString);
364 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
365 m_ptoolbar->SetColorScheme(cs);
369wxSize ocpnFloatingToolbarDialog::GetToolSize() {
370 wxSize style_tool_size;
372 style_tool_size = m_style->GetToolSize();
374 style_tool_size.x *= m_sizefactor;
375 style_tool_size.y *= m_sizefactor;
377 style_tool_size.x = 32;
378 style_tool_size.y = 32;
381 return style_tool_size;
384void ocpnFloatingToolbarDialog::SetGeometry(
bool bAvoid, wxRect rectAvoid) {
386 wxSize style_tool_size = m_style->GetToolSize();
388 style_tool_size.x *= m_sizefactor;
389 style_tool_size.y *= m_sizefactor;
391 m_ptoolbar->SetToolBitmapSize(style_tool_size);
393 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
394 int grabber_width = m_style->GetIcon(
"grabber").GetWidth();
401 m_pparent->GetClientSize().x -
402 (tool_size.x + m_style->GetToolSeparation()) * 2;
403 if (bAvoid && !rectAvoid.IsEmpty()) {
404 avoid_start = m_pparent->GetClientSize().x - rectAvoid.width -
408 max_rows = (m_pparent->GetClientSize().y /
409 (tool_size.y + m_style->GetToolSeparation())) -
412 max_cols = (avoid_start - grabber_width) /
413 (tool_size.x + m_style->GetToolSeparation());
416 if (m_orient == wxTB_VERTICAL)
417 max_rows = wxMax(max_rows, 2);
419 max_cols = wxMax(max_cols, 2);
422 if (m_orient == wxTB_VERTICAL)
423 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
425 m_ptoolbar->SetMaxRowsCols(100, max_cols);
426 m_ptoolbar->SetSizeFactor(m_sizefactor);
430void ocpnFloatingToolbarDialog::SetDefaultPosition() {
433 if (m_pparent && m_ptoolbar) {
434 wxSize cs = m_pparent->GetClientSize();
436 m_position.x = m_dock_min_x;
437 else if (1 == m_dock_x)
438 m_position.x = cs.x - m_ptoolbar->m_maxWidth;
441 m_position.y = m_dock_min_y;
442 else if (1 == m_dock_y)
443 m_position.y = cs.y - m_ptoolbar->m_maxHeight;
445 m_position.x = wxMin(cs.x - m_ptoolbar->m_maxWidth, m_position.x);
446 m_position.y = wxMin(cs.y - m_ptoolbar->m_maxHeight, m_position.y);
448 m_position.x = wxMax(m_dock_min_x, m_position.x);
449 m_position.y = wxMax(m_dock_min_y, m_position.y);
451 m_position.y += m_auxOffsetY;
453 g_maintoolbar_x = m_position.x;
454 g_maintoolbar_y = m_position.y;
475void ocpnFloatingToolbarDialog::Submerge() {
478 if (m_ptoolbar) m_ptoolbar->KillTooltip();
481void ocpnFloatingToolbarDialog::HideTooltip() {
483 if (m_ptoolbar) m_ptoolbar->HideTooltip();
487void ocpnFloatingToolbarDialog::ShowTooltips() {
489 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
493void ocpnFloatingToolbarDialog::ToggleOrientation() {}
495wxRect ocpnFloatingToolbarDialog::GetToolbarRect() {
496 return wxRect(m_position.x, m_position.y, m_ptoolbar->m_maxWidth,
497 m_ptoolbar->m_maxHeight);
500wxSize ocpnFloatingToolbarDialog::GetToolbarSize() {
501 return wxSize(m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
504wxPoint ocpnFloatingToolbarDialog::GetToolbarPosition() {
505 return wxPoint(m_position.x, m_position.y);
508bool ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
509 if (g_disable_main_toolbar)
return false;
511 bool bproc = m_ptoolbar->OnMouseEvent(event, m_position);
512 if (bproc) m_ptoolbar->CreateBitmap();
518void ocpnFloatingToolbarDialog::RefreshToolbar() {
520 if (m_ptoolbar->IsDirty()) {
522 top_frame::Get()->GetAbstractPrimaryCanvas()->Refresh();
527void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
528 m_nAutoHideToolbar = time;
529 if (m_bAutoHideToolbar) {
531 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
535void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
536 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
537 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
541void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
542 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
545void ocpnFloatingToolbarDialog::Realize() {
547 m_ptoolbar->Realize();
548 m_ptoolbar->CreateBitmap();
549 m_toolbar_image.Destroy();
553void ocpnFloatingToolbarDialog::DrawDC(
ocpnDC &dc,
double displayScale) {
555 m_ptoolbar->CreateBitmap();
556 if (m_ptoolbar->GetBitmap().IsOk()) {
557 dc.DrawBitmap(m_ptoolbar->GetBitmap(), m_position.x, m_position.y,
false);
558 m_ptoolbar->SetDirty(
false);
563void ocpnFloatingToolbarDialog::DrawGL(
ocpnDC &gldc,
double displayScale) {
564 if (g_disable_main_toolbar)
return;
567 if (!m_ptoolbar)
return;
569 wxColour backColor = GetGlobalColor(
"GREY3");
570 gldc.SetBrush(wxBrush(backColor));
571 gldc.SetPen(wxPen(backColor));
573 wxRect r = GetToolbarRect();
574 int m_end_margin = wxMin(GetToolSize().x, GetToolSize().y) / 8;
576 if (m_orient == wxHORIZONTAL)
577 gldc.DrawRoundedRectangle(
578 (r.x - m_end_margin / 2) * displayScale, (r.y - 1) * displayScale,
579 (r.width + m_end_margin) * displayScale, (r.height + 2) * displayScale,
580 (m_end_margin * 1) * displayScale);
582 gldc.DrawRoundedRectangle(
583 (r.x - 1) * displayScale, (r.y - m_end_margin / 2) * displayScale,
584 (r.width + 2) * displayScale, (r.height + m_end_margin) * displayScale,
585 (m_end_margin * 1.5) * displayScale);
587 int width = GetToolbarSize().x;
588 int height = GetToolbarSize().y;
590 m_ptoolbar->CreateBitmap(displayScale);
594 glGenTextures(1, &m_texture);
596 glBindTexture(g_texture_rectangle_format, m_texture);
597 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
599 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
601 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
603 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
606 glBindTexture(g_texture_rectangle_format, m_texture);
609 if (!m_toolbar_image.IsOk()) {
611 m_toolbar_image = m_ptoolbar->GetBitmap().ConvertToImage();
613 unsigned char *d = m_toolbar_image.GetData();
614 unsigned char *e =
new unsigned char[4 * width * height];
615 for (
int y = 0; y < height; y++)
616 for (
int x = 0; x < width; x++) {
617 int i = y * width + x;
618 memcpy(e + 4 * i, d + 3 * i, 3);
621 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, width, height, 0,
622 GL_RGBA, GL_UNSIGNED_BYTE, e);
624 glDisable(g_texture_rectangle_format);
630 glEnable(g_texture_rectangle_format);
631 glBindTexture(g_texture_rectangle_format, m_texture);
634 int x0 = GetToolbarPosition().x, x1 = x0 + width;
635 int y0 = GetToolbarPosition().y - 0, y1 = y0 + height;
642 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
643 tx = width, ty = height;
670 m_callbacks.render_gl_textures(gldc, coords, uv);
671 glDisable(g_texture_rectangle_format);
672 glBindTexture(g_texture_rectangle_format, 0);
680void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
684 m_pparent->GetEventHandler()->AddPendingEvent(event);
686 wxTheApp->GetTopWindow()->Raise();
692 m_ptoolbar = CreateNewToolbar();
699 long winstyle = wxNO_BORDER | wxTB_FLAT;
700 winstyle |= m_orient;
707 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
708 m_ptoolbar->SetColorScheme(m_cs);
709 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
714void ocpnFloatingToolbarDialog::DestroyToolBar() {
715 g_toolbarConfig = GetToolConfigString();
718 m_ptoolbar->ClearTools();
723 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
733 int n_tools = tb->GetToolsCount();
737 ArrayOfPlugInToolbarTools tool_array =
740 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
742 if (pttc->position == n_tools) {
746 case GLOBAL_COLOR_SCHEME_DAY:
747 ptool_bmp = pttc->bitmap_day;
750 case GLOBAL_COLOR_SCHEME_DUSK:
751 ptool_bmp = pttc->bitmap_dusk;
753 case GLOBAL_COLOR_SCHEME_NIGHT:
754 ptool_bmp = pttc->bitmap_night;
757 ptool_bmp = pttc->bitmap_day;
762 wxToolBarToolBase *tool =
763 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
764 wxString(pttc->shortHelp), pttc->kind);
766 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
767 pttc->pluginRolloverIconSVG,
768 pttc->pluginToggledIconSVG);
777 while (CheckAndAddPlugInTool(tb)) {
783void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
784 m_enableRolloverBitmaps = bEnable;
785 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
795EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
796EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
804 int id, const wxString &label, const wxBitmap &bmpNormal,
805 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
806 const wxString &shortHelp, const wxString &longHelp) {
807 if (m_style->NativeToolIconExists(label)) {
808 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
809 clientData, shortHelp, longHelp);
811 wxString testToolname =
g_pi_manager->GetToolOwnerCommonName(
id);
813 if (testToolname ==
"") {
815 clientData, shortHelp, longHelp);
817 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
818 clientData, shortHelp, longHelp);
827void ocpnToolBarSimple::Init() {
828 m_currentRowsOrColumns = 0;
830 m_lastX = m_lastY = 0;
832 m_maxWidth = m_maxHeight = 0;
834 m_pressedTool = m_currentTool = -1;
836 m_xPos = m_yPos = wxDefaultCoord;
838 m_style = g_StyleManager->GetCurrentStyle();
841 m_defaultHeight = 15;
843 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
844 m_toolOutlineColour.Set(
"BLACK");
845 m_last_ro_tool = NULL;
847 m_btoolbar_is_zooming =
false;
850 m_last_plugin_down_id = -1;
853 m_btooltip_show =
false;
857 m_tbenableRolloverBitmaps =
false;
860wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
861 int id,
const wxString &label,
const wxBitmap &bitmap,
862 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
863 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
870 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
871 shortHelp, longHelp, clientData);
876wxToolBarToolBase *ocpnToolBarSimple::AddTool(
877 int toolid,
const wxString &label,
const wxBitmap &bitmap,
878 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
879 const wxString &longHelp, wxObject *data) {
882 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
887wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
888 size_t pos,
int id,
const wxString &label,
const wxBitmap &bitmap,
889 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
890 const wxString &longHelp, wxObject *clientData) {
891 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
892 "invalid position in wxToolBar::InsertTool()");
894 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
895 clientData, shortHelp, longHelp);
897 if (!InsertTool(pos, tool)) {
906wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
907 wxToolBarToolBase *tool) {
908 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
909 "invalid position in wxToolBar::InsertTool()");
911 if (!tool || !DoInsertTool(pos, tool)) {
915 m_tools.Insert(pos, tool);
921bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
922 wxToolBarToolBase *toolBase) {
928 if (tool->isPluginTool) {
929 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
930 if (tool->GetToolname() ==
932 tool->toolname <<
"1";
938 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
941 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
943 if (tool->IsButton()) {
944 tool->SetSize(GetToolSize());
947 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
948 m_style->GetLeftMargin()) > m_maxWidth)
950 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
952 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
953 m_style->GetTopMargin()) > m_maxHeight)
955 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
958 else if (tool->IsControl()) {
959 tool->SetSize(tool->GetControl()->GetSize());
962 tool->b_hilite =
false;
967bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
968 wxToolBarToolBase *tool) {
972 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
980 const wxPoint &pos,
const wxSize &size,
981 long style,
int orient) {
982 m_parentContainer = parent;
1001 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
1002 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
1003 m_tooltip_off = 3000;
1005 m_tbenableRolloverBitmaps =
false;
1010ocpnToolBarSimple::~ocpnToolBarSimple() {}
1012void ocpnToolBarSimple::EnableTooltips() {
1014 m_btooltip_show =
true;
1018void ocpnToolBarSimple::DisableTooltips() {
1020 ocpnToolBarSimple::m_btooltip_show =
false;
1024void ocpnToolBarSimple::KillTooltip() {
1025 m_btooltip_show =
false;
1028 m_tooltip_timer.Stop();
1030 wxTheApp->GetTopWindow()->Raise();
1031 top_frame::Get()->GetAbstractFocusCanvas()->TriggerDeferredFocus();
1034void ocpnToolBarSimple::HideTooltip() {
1040void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1044 m_toolOutlineColour = GetGlobalColor(
"UIBDR");
1046 m_currentColorScheme = cs;
1049bool ocpnToolBarSimple::Realize() {
1051 m_style->SetOrientation(wxTB_VERTICAL);
1053 m_style->SetOrientation(wxTB_HORIZONTAL);
1055 wxSize toolSize = wxSize(-1, -1);
1056 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1057 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1058 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1060 m_currentRowsOrColumns = 0;
1062 m_lastX = leftMargin;
1063 m_lastY = topMargin;
1068 bool firstNode =
true;
1069 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1074 if (iNode >= m_nShowTools)
break;
1080 if (toolSize.x == -1) {
1081 if (!tool->IsSeparator()) {
1082 toolSize.x = tool->m_width;
1083 toolSize.y = tool->m_height;
1087 tool->firstInLine = firstNode;
1088 tool->lastInLine =
false;
1091 tool->last_rect.width = 0;
1093 if (tool->IsSeparator()) {
1102 if (m_currentRowsOrColumns >= m_maxRows)
1103 m_lastX += separatorSize;
1105 m_lastY += separatorSize;
1107 }
else if (tool->IsButton()) {
1108 if (!IsVertical()) {
1109 if (m_currentRowsOrColumns >= m_maxCols) {
1110 tool->firstInLine =
true;
1111 if (lastTool && m_LineCount > 1) lastTool->lastInLine =
true;
1113 m_currentRowsOrColumns = 0;
1114 m_lastX = leftMargin;
1115 m_lastY += toolSize.y + topMargin;
1117 tool->m_x = (wxCoord)m_lastX;
1118 tool->m_y = (wxCoord)m_lastY;
1120 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1121 tool->trect.Inflate(separatorSize / 2, topMargin);
1123 m_lastX += toolSize.x + separatorSize;
1125 if (m_currentRowsOrColumns >= m_maxRows) {
1126 tool->firstInLine =
true;
1127 if (lastTool) lastTool->lastInLine =
true;
1129 m_currentRowsOrColumns = 0;
1130 m_lastX += toolSize.x + leftMargin;
1131 m_lastY = topMargin;
1133 tool->m_x = (wxCoord)m_lastX;
1134 tool->m_y = (wxCoord)m_lastY;
1136 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1137 tool->trect.Inflate((separatorSize / 2), topMargin);
1139 m_lastY += toolSize.y + separatorSize;
1141 m_currentRowsOrColumns++;
1156 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
1157 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
1160 node = node->GetNext();
1163 if (lastTool && (m_LineCount > 1 || IsVertical()))
1164 lastTool->lastInLine =
true;
1166 if (!IsVertical()) {
1167 m_maxHeight += toolSize.y;
1168 m_maxHeight += m_style->GetBottomMargin();
1170 m_maxWidth += toolSize.x;
1171 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
1174 m_bitmap = wxNullBitmap;
1179wxBitmap &ocpnToolBarSimple::CreateBitmap(
double display_scale) {
1180 if (m_bitmap.IsOk())
return m_bitmap;
1183 int width = m_maxWidth;
1184 int height = m_maxHeight;
1187 wxBitmap bm(width, height);
1188 mdc.SelectObject(bm);
1189 mdc.SetBackground(wxBrush(GetBackgroundColour()));
1193 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1194 node; node = node->GetNext()) {
1195 wxToolBarToolBase *tool = node->GetData();
1197 wxRect toolRect = tools->trect;
1198 CreateToolBitmap(tool);
1200 if (tools->m_activeBitmap.IsOk()) {
1201 mdc.DrawBitmap(tools->m_activeBitmap, tools->m_x, tools->m_y,
false);
1206 mdc.SelectObject(wxNullBitmap);
1212void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
1213 if (!top_frame::Get())
1218 if (m_btooltip_show ) {
1219 if (m_last_ro_tool) {
1220 wxString s = m_last_ro_tool->GetShortHelp();
1224 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
1225 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
1227 wxPoint screenPosition =
1228 top_frame::Get()->GetAbstractPrimaryCanvas()->ClientToScreen(
1233 top_frame::Get()->GetAbstractPrimaryCanvas()->GetWindow(), s,
1234 screenPosition, m_last_ro_tool->m_btooltip_hiviz);
1237 wxTheApp->GetTopWindow()->Raise();
1241 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1248void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
1252bool ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event, wxPoint &position) {
1254 event.GetPosition(&x, &y);
1257 wxRect r = wxRect(position, wxSize(m_maxWidth, m_maxHeight));
1258 if (!r.Contains(x, y)) {
1263 m_parentContainer->RefreshFadeTimer();
1266 (
ocpnToolBarTool *)FindToolForPosition(x - position.x, y - position.y);
1268 m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1271 m_tooltipoff_timer.Stop();
1274 if (tool && tool->IsButton() ) {
1275 if (m_btooltip_show) {
1276 if (tool != m_last_ro_tool) {
1282 if (!m_tooltip_timer.IsRunning()) {
1283 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
1290 m_last_ro_tool = tool;
1293 if (event.LeftIsDown()) m_leftDown =
true;
1295 if (event.LeftDown() && tool->IsEnabled()) {
1296 if (tool->CanBeToggled()) {
1298 tool->bitmapOK =
false;
1300 m_bitmap = wxNullBitmap;
1306 ArrayOfPlugInToolbarTools tool_array =
1308 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1310 if (tool->GetId() == pttc->id) {
1315 m_last_plugin_down_id = pttc->id;
1320 }
else if (event.RightDown()) {
1321 OnRightClick(tool->GetId(), x, y);
1334 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
1336 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
1337 tool->CanBeToggled()) {
1341 tool->bitmapOK =
false;
1356void ocpnToolBarSimple::CreateToolBitmap(wxToolBarToolBase *toolBase) {
1359 wxBitmap bmp = wxNullBitmap;
1361 bool bNeedClear = !tool->bitmapOK;
1363 if (tool->bitmapOK) {
1364 if (tool->IsEnabled()) {
1365 bmp = tool->GetNormalBitmap();
1368 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1369 tool->rollover, tool->m_width, tool->m_height);
1370 tool->SetNormalBitmap(bmp);
1371 tool->bitmapOK =
true;
1374 bmp = tool->GetDisabledBitmap();
1376 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1377 false, tool->m_width, tool->m_height);
1378 tool->SetDisabledBitmap(bmp);
1379 tool->bitmapOK =
true;
1383 if (tool->isPluginTool) {
1384 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1391 wxString svgFile = tool->pluginNormalIconSVG;
1393 if (tool->pluginToggledIconSVG.Length())
1394 svgFile = tool->pluginToggledIconSVG;
1396 if (tool->rollover) {
1397 if (tool->pluginRolloverIconSVG.Length())
1398 svgFile = tool->pluginRolloverIconSVG;
1401 if (!svgFile.IsEmpty()) {
1403 bmp =
LoadSVG(svgFile, tool->m_width, tool->m_height);
1405 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1408 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1412 if (!bmp.IsOk() || bmp.IsNull()) {
1413 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1414 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1415 tool->rollover, tool->m_width,
1423 bmp = tool->pluginNormalIcon;
1424 if (fabs(m_sizefactor - 1.0) > 0.01) {
1425 if (tool->m_width && tool->m_height) {
1426 wxImage scaled_image = bmp.ConvertToImage();
1427 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1428 wxIMAGE_QUALITY_HIGH));
1433 tool->SetNormalBitmap(bmp);
1434 tool->bitmapOK =
true;
1436 bmp = tool->GetNormalBitmap();
1437 if (tool->IsEnabled()) {
1438 if (tool->IsToggled()) {
1439 if (!tool->bitmapOK) {
1440 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1441 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1442 tool->rollover, tool->m_width,
1444 tool->SetNormalBitmap(bmp);
1450 if (!tool->bitmapOK) {
1451 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1452 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1453 tool->rollover, tool->m_width,
1455 tool->SetNormalBitmap(bmp);
1460 tool->bitmapOK =
true;
1462 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1463 false, tool->m_width, tool->m_height);
1464 tool->SetDisabledBitmap(bmp);
1465 tool->bitmapOK =
true;
1469 tool->m_activeBitmap = bmp;
1475void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
1479 wxPoint drawAt(tool->m_x, tool->m_y);
1480 wxBitmap bmp = wxNullBitmap;
1482 bool bNeedClear = !tool->bitmapOK;
1484 if (tool->bitmapOK) {
1485 if (tool->IsEnabled()) {
1486 bmp = tool->GetNormalBitmap();
1489 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1490 tool->rollover, tool->m_width, tool->m_height);
1491 tool->SetNormalBitmap(bmp);
1492 tool->bitmapOK =
true;
1495 bmp = tool->GetDisabledBitmap();
1497 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1498 false, tool->m_width, tool->m_height);
1499 tool->SetDisabledBitmap(bmp);
1500 tool->bitmapOK =
true;
1504 if (tool->isPluginTool) {
1505 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1512 wxString svgFile = tool->pluginNormalIconSVG;
1514 if (tool->pluginToggledIconSVG.Length())
1515 svgFile = tool->pluginToggledIconSVG;
1517 if (tool->rollover) {
1518 if (tool->pluginRolloverIconSVG.Length())
1519 svgFile = tool->pluginRolloverIconSVG;
1522 if (!svgFile.IsEmpty()) {
1524 bmp =
LoadSVG(svgFile, tool->m_width, tool->m_height);
1526 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1529 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1533 if (!bmp.IsOk() || bmp.IsNull()) {
1534 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1535 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1536 tool->rollover, tool->m_width,
1543 if (tool->rollover) {
1545 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
1548 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1551 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1553 if (fabs(m_sizefactor - 1.0) > 0.01) {
1554 if (tool->m_width && tool->m_height) {
1555 wxImage scaled_image = bmp.ConvertToImage();
1556 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1557 wxIMAGE_QUALITY_HIGH));
1562 tool->SetNormalBitmap(bmp);
1563 tool->bitmapOK =
true;
1565 bmp = tool->GetNormalBitmap();
1566 if (tool->IsEnabled()) {
1567 if (tool->IsToggled()) {
1568 if (!tool->bitmapOK) {
1569 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1570 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1571 tool->rollover, tool->m_width,
1573 tool->SetNormalBitmap(bmp);
1579 if (!tool->bitmapOK) {
1580 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1581 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1582 tool->rollover, tool->m_width,
1584 tool->SetNormalBitmap(bmp);
1589 tool->bitmapOK =
true;
1591 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1592 false, tool->m_width, tool->m_height);
1593 tool->SetDisabledBitmap(bmp);
1594 tool->bitmapOK =
true;
1599 if (tool->firstInLine) {
1600 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
1602 if (tool->lastInLine) {
1603 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
1606 if (bmp.GetWidth() != m_style->GetToolSize().x ||
1607 bmp.GetHeight() != m_style->GetToolSize().y) {
1613 if ((tool->last_rect.width &&
1614 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
1616 wxBrush bb(GetGlobalColor(
"GREY3"));
1618 dc.SetPen(*wxTRANSPARENT_PEN);
1619 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
1620 tool->last_rect.width, tool->last_rect.height);
1627 wxImage scaled_image = bmp.ConvertToImage();
1628 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1629 wxIMAGE_QUALITY_HIGH));
1630 dc.DrawBitmap(sbmp, drawAt);
1632 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
1635 dc.DrawBitmap(bmp, drawAt);
1637 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
1645wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
1647 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1650 if ((x >= tool->m_x) && (y >= tool->m_y) &&
1651 (x < (tool->m_x + tool->GetWidth())) &&
1652 (y < (tool->m_y + tool->GetHeight()))) {
1656 node = node->GetNext();
1659 return (wxToolBarToolBase *)NULL;
1662void ocpnToolBarSimple::InvalidateBitmaps() {
1663 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1666 tool->bitmapOK =
false;
1667 node = node->GetNext();
1669 m_bitmap = wxNullBitmap;
1672wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
1674 wxToolBarToolBase *tool = FindById(tool_id);
1677 if (otool) rect = otool->trect;
1687void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
1688 bool WXUNUSED(enable)) {
1690 t->bitmapOK =
false;
1693void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
1694 bool WXUNUSED(toggle)) {
1696 t->bitmapOK =
false;
1704wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
1705 wxToolBarToolBase *tool = FindById(
id);
1706 wxCHECK_MSG(tool,
"",
"no such tool");
1708 return tool->GetShortHelp();
1711wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
1712 wxToolBarToolBase *tool = FindById(
id);
1713 wxCHECK_MSG(tool,
"",
"no such tool");
1715 return tool->GetLongHelp();
1718void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
1719 wxToolBarToolBase *tool = FindById(
id);
1721 (void)tool->SetShortHelp(help);
1725void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
1726 wxToolBarToolBase *tool = FindById(
id);
1728 (void)tool->SetLongHelp(help);
1732int ocpnToolBarSimple::GetToolPos(
int id)
const {
1734 wxToolBarToolsList::compatibility_iterator node;
1736 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1737 if (node->GetData()->GetId() == id)
return pos;
1744bool ocpnToolBarSimple::GetToolState(
int id)
const {
1745 wxToolBarToolBase *tool = FindById(
id);
1746 wxCHECK_MSG(tool,
false,
"no such tool");
1748 return tool->IsToggled();
1751bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
1752 wxToolBarToolBase *tool = FindById(
id);
1753 wxCHECK_MSG(tool,
false,
"no such tool");
1755 return tool->IsEnabled();
1758void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
1759 wxToolBarToolBase *tool = FindById(
id);
1761 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
1762 DoToggleTool(tool, toggle);
1763 InvalidateBitmaps();
1764 top_frame::Get()->GetAbstractPrimaryCanvas()->Refresh(
true);
1768wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
1769 wxToolBarToolBase *tool = FindById(
id);
1770 return tool ? tool->GetClientData() : (wxObject *)NULL;
1773void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
1774 wxToolBarToolBase *tool = FindById(
id);
1776 wxCHECK_RET(tool,
"no such tool in wxToolBar::SetToolClientData");
1778 tool->SetClientData(clientData);
1781void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
1782 wxToolBarToolBase *tool = FindById(
id);
1784 if (tool->Enable(enable)) {
1785 DoEnableTool(tool, enable);
1790 if (parent && parent->m_FloatingToolbarConfigMenu) {
1791 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
1792 if (configItem) configItem->Check(
true);
1796void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
1799 tool->SetTooltipHiviz(b_hiviz);
1803void ocpnToolBarSimple::ClearTools() {
1804 while (GetToolsCount()) {
1809int ocpnToolBarSimple::GetVisibleToolCount() {
1811 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1815 node = node->GetNext();
1820bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
1821 wxCHECK_MSG(pos < GetToolsCount(),
false,
1822 "invalid position in wxToolBar::DeleteToolByPos()");
1824 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
1826 if (!DoDeleteTool(pos, node->GetData())) {
1830 delete node->GetData();
1831 m_tools.Erase(node);
1836bool ocpnToolBarSimple::DeleteTool(
int id) {
1838 wxToolBarToolsList::compatibility_iterator node;
1839 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1840 if (node->GetData()->GetId() == id)
break;
1845 if (!node || !DoDeleteTool(pos, node->GetData())) {
1849 delete node->GetData();
1850 m_tools.Erase(node);
1855wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
1856 return InsertSeparator(GetToolsCount());
1859wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
1860 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1861 "invalid position in wxToolBar::InsertSeparator()");
1863 wxToolBarToolBase *tool =
1864 CreateTool(wxID_SEPARATOR,
"", wxNullBitmap, wxNullBitmap,
1865 wxITEM_SEPARATOR, (wxObject *)NULL,
"",
"");
1867 if (!tool || !DoInsertTool(pos, tool)) {
1873 m_tools.Insert(pos, tool);
1879wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
1881 wxToolBarToolsList::compatibility_iterator node;
1882 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1883 if (node->GetData()->GetId() == id)
break;
1891 return (wxToolBarToolBase *)NULL;
1894 wxToolBarToolBase *tool = node->GetData();
1895 if (!DoDeleteTool(pos, tool)) {
1896 return (wxToolBarToolBase *)NULL;
1899 m_tools.Erase(node);
1904wxControl *ocpnToolBarSimple::FindControl(
int id) {
1905 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1906 node; node = node->GetNext()) {
1907 const wxToolBarToolBase *
const tool = node->GetData();
1908 if (tool->IsControl()) {
1909 wxControl *
const control = tool->GetControl();
1912 wxFAIL_MSG(
"NULL control in toolbar?");
1913 }
else if (control->GetId() ==
id) {
1923wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
1924 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
1926 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1927 node; node = node->GetNext()) {
1928 tool = node->GetData();
1929 if (tool->GetId() == id) {
1946bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
1947 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
1951 event.SetInt((
int)toggleDown);
1954 event.SetExtraLong((
long)toggleDown);
1956 top_frame::Get()->GetEventHandler()->AddPendingEvent(event);
1962void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
1966 if (m_parentContainer) {
1967 if (m_parentContainer->m_FloatingToolbarConfigMenu) {
1970 wxDefaultPosition, wxSize(100, 100));
1971 int rc = dlg->ShowModal();
1974 if (rc == wxID_OK) {
1975 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
1976 event.SetEventObject(
this);
1979 top_frame::Get()->GetEventHandler()->AddPendingEvent(event);
1985void ocpnToolBarSimple::DoPluginToolUp() {
1990 ArrayOfPlugInToolbarTools tool_array =
1992 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1994 if (m_last_plugin_down_id == pttc->id) {
2001 m_last_plugin_down_id = -1;
2004void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2005 const wxString &iconName) {
2011 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
2012 otool->m_width, otool->m_height);
2013 tool->SetNormalBitmap(bmp);
2014 otool->SetIconName(iconName);
2019void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
2024 otool->pluginNormalIconSVG = fileSVG;
2029void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
2030 wxBitmap *bmpRollover) {
2033 if (tool->isPluginTool) {
2034 if (bmp->GetWidth() != tool->GetWidth()) {
2036 wxImage ibmp = bmp->ConvertToImage();
2037 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2038 wxIMAGE_QUALITY_HIGH);
2039 wxBitmap sbmp = wxBitmap(ibmp);
2040 tool->pluginNormalIcon = sbmp;
2043 tool->pluginNormalIcon = *bmp;
2046 if (bmpRollover->GetWidth() != tool->GetWidth()) {
2047 if (bmpRollover->IsOk()) {
2048 wxImage ibmp = bmpRollover->ConvertToImage();
2049 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2050 wxIMAGE_QUALITY_HIGH);
2051 wxBitmap sbmp = wxBitmap(ibmp);
2052 tool->pluginRolloverIcon = sbmp;
2055 tool->pluginRolloverIcon = *bmpRollover;
2057 tool->bitmapOK =
false;
2060 tool->SetNormalBitmap(*bmp);
2061 tool->bitmapOK =
true;
2063 InvalidateBitmaps();
2067void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
2068 wxString fileSVGRollover,
2069 wxString fileSVGToggled) {
2072 tool->pluginNormalIconSVG = fileSVGNormal;
2073 tool->pluginRolloverIconSVG = fileSVGRollover;
2074 tool->pluginToggledIconSVG = fileSVGToggled;
2075 tool->bitmapOK =
false;
2076 InvalidateBitmaps();
2082ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
2083 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
2085 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
2087 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
2088 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2091 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
2092 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
2094 choices.push_back(
new wxRadioButton(
2095 this, 1, _(
"No, and permanently remove the option to hide it."),
2096 wxDefaultPosition));
2099 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
2101 wxStdDialogButtonSizer *buttonSizer =
2102 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2104 wxStaticText *textCtrl =
2105 new wxStaticText(
this, wxID_ANY,
2106 _(
"The Man Over Board button could be an important "
2107 "safety feature.\nAre you sure you want to hide it?"));
2109 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
2110 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
2111 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
2112 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
2113 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
2115 topSizer->SetSizeHints(
this);
2119int ToolbarMOBDialog::GetSelection() {
2120 for (
unsigned int i = 0; i < choices.size(); i++) {
2121 if (choices[i]->GetValue())
return choices[i]->GetId();
2141 const wxString &caption,
2143 const wxSize &size,
long style) {
2144 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
2145 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
2147 m_configMenu = NULL;
2148 m_ToolbarDialogAncestor = sponsor;
2150 if (m_ToolbarDialogAncestor)
2151 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
2154 GetSizer()->Fit(
this);
2159ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
2166 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
2167 SetSizer(itemBoxSizer1);
2169 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
2170 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
2171 itemDialog1->SetScrollRate(2, 2);
2178 wxString wqs = getFontQtStylesheet(qFont);
2179 wxCharBuffer sbuf = wqs.ToUTF8();
2180 QString qsb = QString(sbuf.data());
2182 QString qsbq = getQtStyleSheet();
2184 this->GetHandle()->setStyleSheet(qsb + qsbq);
2187 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
2189 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
2190 itemDialog1->SetSizer(itemBoxSizer2);
2192 wxStaticBox *itemStaticBoxSizer3Static =
2193 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Choose Toolbar Icons"));
2194 wxStaticBoxSizer *itemStaticBoxSizer3 =
2195 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
2196 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
2201 nitems = m_configMenu->GetMenuItemCount();
2204 for (
int i = 0; i < nitems; i++) {
2205 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon)
continue;
2206 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2208 wxString label = item->GetItemLabel();
2209 int l = label.Len();
2210 max_width = wxMax(max_width, l);
2212 wxString windowName =
"";
2213 if (item->GetId() == ID_MOB + 100) windowName =
"MOBCheck";
2216 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
2217 wxDefaultSize, 0, wxDefaultValidator, windowName);
2219 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
2220 cb->SetValue(item->IsChecked());
2222 cboxes.push_back(cb);
2226 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
2227 (nitems + 4) * GetCharHeight() * 2);
2229 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
2230 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
2232 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
2233 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
2235 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
2236 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
2239 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
2240 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2243 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
2244 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2245 m_OKButton->SetDefault();
2247 m_CancelButton->Connect(
2248 wxEVT_COMMAND_BUTTON_CLICKED,
2249 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL,
this);
2250 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2251 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
2254 SetColorScheme((ColorScheme)0);
2257void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
2259void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
2260 EndModal(wxID_CANCEL);
2263void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
2264 unsigned int ncheck = 0;
2266 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
2267 wxString new_toolbarConfig = toolbarConfigSave;
2269 for (
unsigned int i = 0; i < cboxes.size(); i++) {
2270 wxCheckBox *cb = cboxes[i];
2271 wxString cbName = cb->GetName();
2273 if (cbName.IsSameAs(
"MOBCheck") && !cb->IsChecked()) {
2276 int dialog_ret = mdlg.ShowModal();
2277 int answer = mdlg.GetSelection();
2278 if (dialog_ret == wxID_OK) {
2280 g_bPermanentMOBIcon =
true;
2282 }
else if (answer == 0) {
2286 new_toolbarConfig = toolbarConfigSave;
2291 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2292 if (new_toolbarConfig.Len() > i) {
2293 new_toolbarConfig.SetChar(i, cb->IsChecked() ?
'X' :
'.');
2295 new_toolbarConfig.Append(cb->IsChecked() ?
'X' :
'.');
2297 item->Check(cb->IsChecked());
2298 if (cb->IsChecked()) ncheck++;
2305 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN ,
'X' );
2307 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
2310 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
2312 item->Check(
true );
2316 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
2321void ToolbarChoicesDialog::RecalculateSize() {
2322 wxSize esize = GetSize();
2325 wxSize dsize = GetParent()->GetClientSize();
2326 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
2327 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
2333 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
2334 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
2338 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.