54#include "androidUTIL.h"
62extern GLenum g_texture_rectangle_format;
70 const wxBitmap &bmpNormal,
const wxBitmap &bmpRollover,
71 wxItemKind kind, wxObject *clientData,
72 const wxString &shortHelp,
const wxString &longHelp)
73 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, label, bmpNormal,
74 bmpRollover, kind, clientData, shortHelp, longHelp) {
79 m_btooltip_hiviz =
false;
89 pluginNormalIcon = bmpNormal;
90 pluginRolloverIcon = bmpRollover;
95 const wxBitmap &bmpRollover, wxItemKind kind,
96 wxObject *clientData,
const wxString &shortHelp,
97 const wxString &longHelp)
98 : wxToolBarToolBase((wxToolBarBase *)tbar,
id,
"", bmpNormal, bmpRollover,
99 kind, clientData, shortHelp, longHelp) {
103 m_btooltip_hiviz =
false;
104 isPluginTool =
false;
106 m_bmpNormal = bmpNormal;
110 void SetSize(
const wxSize &size) {
115 wxCoord GetWidth()
const {
return m_width; }
117 wxCoord GetHeight()
const {
return m_height; }
119 wxString GetToolname() {
return toolname; }
121 void SetIconName(wxString name) { iconName = name; }
122 wxString GetIconName() {
return iconName; }
124 void SetTooltipHiviz(
bool enable) { m_btooltip_hiviz = enable; }
133 wxBitmap pluginNormalIcon;
134 wxBitmap pluginRolloverIcon;
135 const wxBitmap *pluginToggledIcon;
142 bool m_btooltip_hiviz;
144 wxString pluginNormalIconSVG;
145 wxString pluginRolloverIconSVG;
146 wxString pluginToggledIconSVG;
147 wxBitmap m_activeBitmap;
154ocpnFloatingToolbarDialog::ocpnFloatingToolbarDialog(wxWindow *parent,
162 m_position = position;
164 m_sizefactor = size_factor;
167 m_bAutoHideToolbar =
false;
168 m_nAutoHideToolbar = 5;
169 m_toolbar_scale_tools_shown =
false;
170 m_backcolorString =
"GREY3";
171 m_toolShowMask =
"XXXXXXXXXXXXXXXX";
172 n_toolbarHideMethod = TOOLBAR_HIDE_TO_GRABBER;
173 b_canToggleOrientation =
true;
174 m_enableRolloverBitmaps =
true;
177 m_ptoolbar = CreateNewToolbar();
178 if (m_ptoolbar) m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"GREY3"));
179 m_cs = (ColorScheme)-1;
181 m_style = g_StyleManager->GetCurrentStyle();
182 SetULDockPosition(wxPoint(4, 4));
184 SetGeometry(
false, wxRect());
193 m_marginsInvisible = m_style->marginsInvisible;
195 m_FloatingToolbarConfigMenu = NULL;
197 m_fade_timer.SetOwner(
this);
198 this->Connect(wxEVT_TIMER,
199 wxTimerEventHandler(ocpnFloatingToolbarDialog::FadeTimerEvent),
202 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
203 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
205 m_bsubmerged =
false;
206 m_benableSubmerge =
true;
209ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
210 delete m_FloatingToolbarConfigMenu;
215void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
216 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
217 if (g_bmasterToolbarFull) {
218 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) ) {
221 gFrame->GetPrimaryCanvas()->ScreenToClient(::wxGetMousePosition());
223 wxRect r = GetToolbarRect();
224 if (r.Contains(mp))
return;
226 wxCommandEvent event;
227 event.SetId(ID_MASTERTOGGLE);
228 gFrame->OnToolLeftClick(event);
235 m_Items.push_back(item);
238int ocpnFloatingToolbarDialog::RebuildToolbar() {
245 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
249 bool bEnabled = _toolbarConfigMenuUtil(tic);
252 wxToolBarToolBase *tool =
253 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
254 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
259 if (!tic->m_NormalIconSVG.IsEmpty()) {
260 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
261 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
271void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
272 if (position.x >= 0) m_dock_min_x = position.x;
273 if (position.y >= 0) m_dock_min_y = position.y;
276size_t ocpnFloatingToolbarDialog::GetToolCount() {
278 return m_ptoolbar->GetToolsCount();
283void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
285void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
287 m_ptoolbar->SetToolShowCount(count);
288 m_ptoolbar->SetDirty(
true);
292int ocpnFloatingToolbarDialog::GetToolShowCount() {
294 return m_ptoolbar->GetToolShowCount();
299void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
300 m_backcolorString = colorRef;
301 SetColorScheme(m_cs);
304void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
306void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
308void ocpnFloatingToolbarDialog::CreateConfigMenu() {
309 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
310 m_FloatingToolbarConfigMenu =
new wxMenu();
313bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
315 if (m_FloatingToolbarConfigMenu) {
316 wxMenuItem *menuitem;
318 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
320 if (tic->m_bRequired)
return true;
321 if (tic->m_bPlugin)
return true;
328 int menuItemId = tic->m_ID + idOffset;
330 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
333 return menuitem->IsChecked();
336 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
338 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
339 menuitem->Check(m_configString.Len() >= n
340 ? m_configString.GetChar(n - 1) ==
'X'
342 return menuitem->IsChecked();
347void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
348 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
351void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
353 wxColour back_color = GetGlobalColor(m_backcolorString);
356 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
357 m_ptoolbar->SetColorScheme(cs);
361wxSize ocpnFloatingToolbarDialog::GetToolSize() {
362 wxSize style_tool_size;
364 style_tool_size = m_style->GetToolSize();
366 style_tool_size.x *= m_sizefactor;
367 style_tool_size.y *= m_sizefactor;
369 style_tool_size.x = 32;
370 style_tool_size.y = 32;
373 return style_tool_size;
376void ocpnFloatingToolbarDialog::SetGeometry(
bool bAvoid, wxRect rectAvoid) {
378 wxSize style_tool_size = m_style->GetToolSize();
380 style_tool_size.x *= m_sizefactor;
381 style_tool_size.y *= m_sizefactor;
383 m_ptoolbar->SetToolBitmapSize(style_tool_size);
385 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
386 int grabber_width = m_style->GetIcon(
"grabber").GetWidth();
393 m_pparent->GetClientSize().x -
394 (tool_size.x + m_style->GetToolSeparation()) * 2;
395 if (bAvoid && !rectAvoid.IsEmpty()) {
396 avoid_start = m_pparent->GetClientSize().x - rectAvoid.width -
400 max_rows = (m_pparent->GetClientSize().y /
401 (tool_size.y + m_style->GetToolSeparation())) -
404 max_cols = (avoid_start - grabber_width) /
405 (tool_size.x + m_style->GetToolSeparation());
408 if (m_orient == wxTB_VERTICAL)
409 max_rows = wxMax(max_rows, 2);
411 max_cols = wxMax(max_cols, 2);
414 if (m_orient == wxTB_VERTICAL)
415 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
417 m_ptoolbar->SetMaxRowsCols(100, max_cols);
418 m_ptoolbar->SetSizeFactor(m_sizefactor);
422void ocpnFloatingToolbarDialog::SetDefaultPosition() {
425 if (m_pparent && m_ptoolbar) {
426 wxSize cs = m_pparent->GetClientSize();
428 m_position.x = m_dock_min_x;
429 else if (1 == m_dock_x)
430 m_position.x = cs.x - m_ptoolbar->m_maxWidth;
433 m_position.y = m_dock_min_y;
434 else if (1 == m_dock_y)
435 m_position.y = cs.y - m_ptoolbar->m_maxHeight;
437 m_position.x = wxMin(cs.x - m_ptoolbar->m_maxWidth, m_position.x);
438 m_position.y = wxMin(cs.y - m_ptoolbar->m_maxHeight, m_position.y);
440 m_position.x = wxMax(m_dock_min_x, m_position.x);
441 m_position.y = wxMax(m_dock_min_y, m_position.y);
443 m_position.y += m_auxOffsetY;
445 g_maintoolbar_x = m_position.x;
446 g_maintoolbar_y = m_position.y;
467void ocpnFloatingToolbarDialog::Submerge() {
470 if (m_ptoolbar) m_ptoolbar->KillTooltip();
473void ocpnFloatingToolbarDialog::HideTooltip() {
475 if (m_ptoolbar) m_ptoolbar->HideTooltip();
479void ocpnFloatingToolbarDialog::ShowTooltips() {
481 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
485void ocpnFloatingToolbarDialog::ToggleOrientation() {}
487wxRect ocpnFloatingToolbarDialog::GetToolbarRect() {
488 return wxRect(m_position.x, m_position.y, m_ptoolbar->m_maxWidth,
489 m_ptoolbar->m_maxHeight);
492wxSize ocpnFloatingToolbarDialog::GetToolbarSize() {
493 return wxSize(m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
496wxPoint ocpnFloatingToolbarDialog::GetToolbarPosition() {
497 return wxPoint(m_position.x, m_position.y);
500bool ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
501 if (g_disable_main_toolbar)
return false;
503 bool bproc = m_ptoolbar->OnMouseEvent(event, m_position);
504 if (bproc) m_ptoolbar->CreateBitmap();
510void ocpnFloatingToolbarDialog::RefreshToolbar() {
512 if (m_ptoolbar->IsDirty()) {
514 gFrame->GetPrimaryCanvas()->Refresh();
519void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
520 m_nAutoHideToolbar = time;
521 if (m_bAutoHideToolbar) {
523 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
527void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
528 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
529 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
533void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
534 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
537void ocpnFloatingToolbarDialog::Realize() {
539 m_ptoolbar->Realize();
540 m_ptoolbar->CreateBitmap();
541 m_toolbar_image.Destroy();
545void ocpnFloatingToolbarDialog::DrawDC(
ocpnDC &dc,
double displayScale) {
547 m_ptoolbar->CreateBitmap();
548 if (m_ptoolbar->GetBitmap().IsOk()) {
549 dc.DrawBitmap(m_ptoolbar->GetBitmap(), m_position.x, m_position.y,
false);
550 m_ptoolbar->SetDirty(
false);
555void ocpnFloatingToolbarDialog::DrawGL(
ocpnDC &gldc,
double displayScale) {
556 if (g_disable_main_toolbar)
return;
559 if (!m_ptoolbar)
return;
561 wxColour backColor = GetGlobalColor(
"GREY3");
562 gldc.SetBrush(wxBrush(backColor));
563 gldc.SetPen(wxPen(backColor));
565 wxRect r = GetToolbarRect();
566 int m_end_margin = wxMin(GetToolSize().x, GetToolSize().y) / 8;
568 if (m_orient == wxHORIZONTAL)
569 gldc.DrawRoundedRectangle(
570 (r.x - m_end_margin / 2) * displayScale, (r.y - 1) * displayScale,
571 (r.width + m_end_margin) * displayScale, (r.height + 2) * displayScale,
572 (m_end_margin * 1) * displayScale);
574 gldc.DrawRoundedRectangle(
575 (r.x - 1) * displayScale, (r.y - m_end_margin / 2) * displayScale,
576 (r.width + 2) * displayScale, (r.height + m_end_margin) * displayScale,
577 (m_end_margin * 1.5) * displayScale);
579 int width = GetToolbarSize().x;
580 int height = GetToolbarSize().y;
582 m_ptoolbar->CreateBitmap(displayScale);
586 glGenTextures(1, &m_texture);
588 glBindTexture(g_texture_rectangle_format, m_texture);
589 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
591 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
593 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
595 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
598 glBindTexture(g_texture_rectangle_format, m_texture);
601 if (!m_toolbar_image.IsOk()) {
603 m_toolbar_image = m_ptoolbar->GetBitmap().ConvertToImage();
605 unsigned char *d = m_toolbar_image.GetData();
606 unsigned char *e =
new unsigned char[4 * width * height];
607 for (
int y = 0; y < height; y++)
608 for (
int x = 0; x < width; x++) {
609 int i = y * width + x;
610 memcpy(e + 4 * i, d + 3 * i, 3);
613 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, width, height, 0,
614 GL_RGBA, GL_UNSIGNED_BYTE, e);
616 glDisable(g_texture_rectangle_format);
622 glEnable(g_texture_rectangle_format);
623 glBindTexture(g_texture_rectangle_format, m_texture);
626 int x0 = GetToolbarPosition().x, x1 = x0 + width;
627 int y0 = GetToolbarPosition().y - 0, y1 = y0 + height;
634 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
635 tx = width, ty = height;
662 auto canvas = gFrame->GetPrimaryCanvas();
663 canvas->GetglCanvas()->RenderTextures(gldc, coords, uv, 4,
666 glDisable(g_texture_rectangle_format);
667 glBindTexture(g_texture_rectangle_format, 0);
675void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
679 m_pparent->GetEventHandler()->AddPendingEvent(event);
687 m_ptoolbar = CreateNewToolbar();
694 long winstyle = wxNO_BORDER | wxTB_FLAT;
695 winstyle |= m_orient;
702 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(
"GREY1"));
703 m_ptoolbar->SetColorScheme(m_cs);
704 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
709void ocpnFloatingToolbarDialog::DestroyToolBar() {
710 g_toolbarConfig = GetToolConfigString();
713 m_ptoolbar->ClearTools();
718 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
728 int n_tools = tb->GetToolsCount();
732 ArrayOfPlugInToolbarTools tool_array =
735 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
737 if (pttc->position == n_tools) {
741 case GLOBAL_COLOR_SCHEME_DAY:
742 ptool_bmp = pttc->bitmap_day;
745 case GLOBAL_COLOR_SCHEME_DUSK:
746 ptool_bmp = pttc->bitmap_dusk;
748 case GLOBAL_COLOR_SCHEME_NIGHT:
749 ptool_bmp = pttc->bitmap_night;
752 ptool_bmp = pttc->bitmap_day;
757 wxToolBarToolBase *tool =
758 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
759 wxString(pttc->shortHelp), pttc->kind);
761 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
762 pttc->pluginRolloverIconSVG,
763 pttc->pluginToggledIconSVG);
772 while (CheckAndAddPlugInTool(tb)) {
778void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
779 m_enableRolloverBitmaps = bEnable;
780 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
790EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
791EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
799 int id, const wxString &label, const wxBitmap &bmpNormal,
800 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
801 const wxString &shortHelp, const wxString &longHelp) {
802 if (m_style->NativeToolIconExists(label)) {
803 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
804 clientData, shortHelp, longHelp);
806 wxString testToolname =
g_pi_manager->GetToolOwnerCommonName(
id);
808 if (testToolname ==
"") {
810 clientData, shortHelp, longHelp);
812 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
813 clientData, shortHelp, longHelp);
822void ocpnToolBarSimple::Init() {
823 m_currentRowsOrColumns = 0;
825 m_lastX = m_lastY = 0;
827 m_maxWidth = m_maxHeight = 0;
829 m_pressedTool = m_currentTool = -1;
831 m_xPos = m_yPos = wxDefaultCoord;
833 m_style = g_StyleManager->GetCurrentStyle();
836 m_defaultHeight = 15;
838 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
839 m_toolOutlineColour.Set(
"BLACK");
840 m_last_ro_tool = NULL;
842 m_btoolbar_is_zooming =
false;
845 m_last_plugin_down_id = -1;
848 m_btooltip_show =
false;
852 m_tbenableRolloverBitmaps =
false;
855wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
856 int id,
const wxString &label,
const wxBitmap &bitmap,
857 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
858 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
865 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
866 shortHelp, longHelp, clientData);
871wxToolBarToolBase *ocpnToolBarSimple::AddTool(
872 int toolid,
const wxString &label,
const wxBitmap &bitmap,
873 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
874 const wxString &longHelp, wxObject *data) {
877 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
882wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
883 size_t pos,
int id,
const wxString &label,
const wxBitmap &bitmap,
884 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
885 const wxString &longHelp, wxObject *clientData) {
886 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
887 "invalid position in wxToolBar::InsertTool()");
889 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
890 clientData, shortHelp, longHelp);
892 if (!InsertTool(pos, tool)) {
901wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
902 wxToolBarToolBase *tool) {
903 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
904 "invalid position in wxToolBar::InsertTool()");
906 if (!tool || !DoInsertTool(pos, tool)) {
910 m_tools.Insert(pos, tool);
916bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
917 wxToolBarToolBase *toolBase) {
923 if (tool->isPluginTool) {
924 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
925 if (tool->GetToolname() ==
927 tool->toolname <<
"1";
933 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
936 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
938 if (tool->IsButton()) {
939 tool->SetSize(GetToolSize());
942 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
943 m_style->GetLeftMargin()) > m_maxWidth)
945 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
947 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
948 m_style->GetTopMargin()) > m_maxHeight)
950 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
953 else if (tool->IsControl()) {
954 tool->SetSize(tool->GetControl()->GetSize());
957 tool->b_hilite =
false;
962bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
963 wxToolBarToolBase *tool) {
967 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
975 const wxPoint &pos,
const wxSize &size,
976 long style,
int orient) {
977 m_parentContainer = parent;
996 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
997 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
998 m_tooltip_off = 3000;
1000 m_tbenableRolloverBitmaps =
false;
1005ocpnToolBarSimple::~ocpnToolBarSimple() {}
1007void ocpnToolBarSimple::EnableTooltips() {
1009 m_btooltip_show =
true;
1013void ocpnToolBarSimple::DisableTooltips() {
1015 ocpnToolBarSimple::m_btooltip_show =
false;
1019void ocpnToolBarSimple::KillTooltip() {
1020 m_btooltip_show =
false;
1023 m_tooltip_timer.Stop();
1026 gFrame->GetFocusCanvas()->TriggerDeferredFocus();
1029void ocpnToolBarSimple::HideTooltip() {
1035void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1039 m_toolOutlineColour = GetGlobalColor(
"UIBDR");
1041 m_currentColorScheme = cs;
1044bool ocpnToolBarSimple::Realize() {
1046 m_style->SetOrientation(wxTB_VERTICAL);
1048 m_style->SetOrientation(wxTB_HORIZONTAL);
1050 wxSize toolSize = wxSize(-1, -1);
1051 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1052 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1053 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1055 m_currentRowsOrColumns = 0;
1057 m_lastX = leftMargin;
1058 m_lastY = topMargin;
1063 bool firstNode =
true;
1064 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1069 if (iNode >= m_nShowTools)
break;
1075 if (toolSize.x == -1) {
1076 if (!tool->IsSeparator()) {
1077 toolSize.x = tool->m_width;
1078 toolSize.y = tool->m_height;
1082 tool->firstInLine = firstNode;
1083 tool->lastInLine =
false;
1086 tool->last_rect.width = 0;
1088 if (tool->IsSeparator()) {
1097 if (m_currentRowsOrColumns >= m_maxRows)
1098 m_lastX += separatorSize;
1100 m_lastY += separatorSize;
1102 }
else if (tool->IsButton()) {
1103 if (!IsVertical()) {
1104 if (m_currentRowsOrColumns >= m_maxCols) {
1105 tool->firstInLine =
true;
1106 if (lastTool && m_LineCount > 1) lastTool->lastInLine =
true;
1108 m_currentRowsOrColumns = 0;
1109 m_lastX = leftMargin;
1110 m_lastY += toolSize.y + topMargin;
1112 tool->m_x = (wxCoord)m_lastX;
1113 tool->m_y = (wxCoord)m_lastY;
1115 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1116 tool->trect.Inflate(separatorSize / 2, topMargin);
1118 m_lastX += toolSize.x + separatorSize;
1120 if (m_currentRowsOrColumns >= m_maxRows) {
1121 tool->firstInLine =
true;
1122 if (lastTool) lastTool->lastInLine =
true;
1124 m_currentRowsOrColumns = 0;
1125 m_lastX += toolSize.x + leftMargin;
1126 m_lastY = topMargin;
1128 tool->m_x = (wxCoord)m_lastX;
1129 tool->m_y = (wxCoord)m_lastY;
1131 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1132 tool->trect.Inflate((separatorSize / 2), topMargin);
1134 m_lastY += toolSize.y + separatorSize;
1136 m_currentRowsOrColumns++;
1151 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
1152 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
1155 node = node->GetNext();
1158 if (lastTool && (m_LineCount > 1 || IsVertical()))
1159 lastTool->lastInLine =
true;
1161 if (!IsVertical()) {
1162 m_maxHeight += toolSize.y;
1163 m_maxHeight += m_style->GetBottomMargin();
1165 m_maxWidth += toolSize.x;
1166 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
1169 m_bitmap = wxNullBitmap;
1174wxBitmap &ocpnToolBarSimple::CreateBitmap(
double display_scale) {
1175 if (m_bitmap.IsOk())
return m_bitmap;
1178 int width = m_maxWidth;
1179 int height = m_maxHeight;
1182 wxBitmap bm(width, height);
1183 mdc.SelectObject(bm);
1184 mdc.SetBackground(wxBrush(GetBackgroundColour()));
1188 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1189 node; node = node->GetNext()) {
1190 wxToolBarToolBase *tool = node->GetData();
1192 wxRect toolRect = tools->trect;
1193 CreateToolBitmap(tool);
1195 if (tools->m_activeBitmap.IsOk()) {
1196 mdc.DrawBitmap(tools->m_activeBitmap, tools->m_x, tools->m_y,
false);
1201 mdc.SelectObject(wxNullBitmap);
1207void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
1212 if (m_btooltip_show ) {
1213 if (m_last_ro_tool) {
1214 wxString s = m_last_ro_tool->GetShortHelp();
1218 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
1219 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
1221 wxPoint screenPosition =
1222 gFrame->GetPrimaryCanvas()->ClientToScreen(pos_in_toolbar);
1226 gFrame->GetPrimaryCanvas(), s, screenPosition,
1227 m_last_ro_tool->m_btooltip_hiviz);
1234 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1241void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
1245bool ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event, wxPoint &position) {
1247 event.GetPosition(&x, &y);
1250 wxRect r = wxRect(position, wxSize(m_maxWidth, m_maxHeight));
1251 if (!r.Contains(x, y)) {
1256 m_parentContainer->RefreshFadeTimer();
1259 (
ocpnToolBarTool *)FindToolForPosition(x - position.x, y - position.y);
1261 m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1264 m_tooltipoff_timer.Stop();
1267 if (tool && tool->IsButton() ) {
1268 if (m_btooltip_show) {
1269 if (tool != m_last_ro_tool) {
1275 if (!m_tooltip_timer.IsRunning()) {
1276 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
1283 m_last_ro_tool = tool;
1286 if (event.LeftIsDown()) m_leftDown =
true;
1288 if (event.LeftDown() && tool->IsEnabled()) {
1289 if (tool->CanBeToggled()) {
1291 tool->bitmapOK =
false;
1293 m_bitmap = wxNullBitmap;
1299 ArrayOfPlugInToolbarTools tool_array =
1301 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1303 if (tool->GetId() == pttc->id) {
1308 m_last_plugin_down_id = pttc->id;
1313 }
else if (event.RightDown()) {
1314 OnRightClick(tool->GetId(), x, y);
1327 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
1329 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
1330 tool->CanBeToggled()) {
1334 tool->bitmapOK =
false;
1349void ocpnToolBarSimple::CreateToolBitmap(wxToolBarToolBase *toolBase) {
1352 wxBitmap bmp = wxNullBitmap;
1354 bool bNeedClear = !tool->bitmapOK;
1356 if (tool->bitmapOK) {
1357 if (tool->IsEnabled()) {
1358 bmp = tool->GetNormalBitmap();
1361 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1362 tool->rollover, tool->m_width, tool->m_height);
1363 tool->SetNormalBitmap(bmp);
1364 tool->bitmapOK =
true;
1367 bmp = tool->GetDisabledBitmap();
1369 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1370 false, tool->m_width, tool->m_height);
1371 tool->SetDisabledBitmap(bmp);
1372 tool->bitmapOK =
true;
1376 if (tool->isPluginTool) {
1377 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1384 wxString svgFile = tool->pluginNormalIconSVG;
1386 if (tool->pluginToggledIconSVG.Length())
1387 svgFile = tool->pluginToggledIconSVG;
1389 if (tool->rollover) {
1390 if (tool->pluginRolloverIconSVG.Length())
1391 svgFile = tool->pluginRolloverIconSVG;
1394 if (!svgFile.IsEmpty()) {
1396 bmp =
LoadSVG(svgFile, tool->m_width, tool->m_height);
1398 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1401 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1405 if (!bmp.IsOk() || bmp.IsNull()) {
1406 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1407 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1408 tool->rollover, tool->m_width,
1416 bmp = tool->pluginNormalIcon;
1417 if (fabs(m_sizefactor - 1.0) > 0.01) {
1418 if (tool->m_width && tool->m_height) {
1419 wxImage scaled_image = bmp.ConvertToImage();
1420 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1421 wxIMAGE_QUALITY_HIGH));
1426 tool->SetNormalBitmap(bmp);
1427 tool->bitmapOK =
true;
1429 bmp = tool->GetNormalBitmap();
1430 if (tool->IsEnabled()) {
1431 if (tool->IsToggled()) {
1432 if (!tool->bitmapOK) {
1433 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1434 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1435 tool->rollover, tool->m_width,
1437 tool->SetNormalBitmap(bmp);
1443 if (!tool->bitmapOK) {
1444 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1445 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1446 tool->rollover, tool->m_width,
1448 tool->SetNormalBitmap(bmp);
1453 tool->bitmapOK =
true;
1455 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1456 false, tool->m_width, tool->m_height);
1457 tool->SetDisabledBitmap(bmp);
1458 tool->bitmapOK =
true;
1462 tool->m_activeBitmap = bmp;
1468void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
1472 wxPoint drawAt(tool->m_x, tool->m_y);
1473 wxBitmap bmp = wxNullBitmap;
1475 bool bNeedClear = !tool->bitmapOK;
1477 if (tool->bitmapOK) {
1478 if (tool->IsEnabled()) {
1479 bmp = tool->GetNormalBitmap();
1482 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1483 tool->rollover, tool->m_width, tool->m_height);
1484 tool->SetNormalBitmap(bmp);
1485 tool->bitmapOK =
true;
1488 bmp = tool->GetDisabledBitmap();
1490 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1491 false, tool->m_width, tool->m_height);
1492 tool->SetDisabledBitmap(bmp);
1493 tool->bitmapOK =
true;
1497 if (tool->isPluginTool) {
1498 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1505 wxString svgFile = tool->pluginNormalIconSVG;
1507 if (tool->pluginToggledIconSVG.Length())
1508 svgFile = tool->pluginToggledIconSVG;
1510 if (tool->rollover) {
1511 if (tool->pluginRolloverIconSVG.Length())
1512 svgFile = tool->pluginRolloverIconSVG;
1515 if (!svgFile.IsEmpty()) {
1517 bmp =
LoadSVG(svgFile, tool->m_width, tool->m_height);
1519 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1522 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1526 if (!bmp.IsOk() || bmp.IsNull()) {
1527 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1528 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1529 tool->rollover, tool->m_width,
1536 if (tool->rollover) {
1538 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
1541 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1544 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1546 if (fabs(m_sizefactor - 1.0) > 0.01) {
1547 if (tool->m_width && tool->m_height) {
1548 wxImage scaled_image = bmp.ConvertToImage();
1549 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1550 wxIMAGE_QUALITY_HIGH));
1555 tool->SetNormalBitmap(bmp);
1556 tool->bitmapOK =
true;
1558 bmp = tool->GetNormalBitmap();
1559 if (tool->IsEnabled()) {
1560 if (tool->IsToggled()) {
1561 if (!tool->bitmapOK) {
1562 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1563 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1564 tool->rollover, tool->m_width,
1566 tool->SetNormalBitmap(bmp);
1572 if (!tool->bitmapOK) {
1573 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1574 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1575 tool->rollover, tool->m_width,
1577 tool->SetNormalBitmap(bmp);
1582 tool->bitmapOK =
true;
1584 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1585 false, tool->m_width, tool->m_height);
1586 tool->SetDisabledBitmap(bmp);
1587 tool->bitmapOK =
true;
1592 if (tool->firstInLine) {
1593 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
1595 if (tool->lastInLine) {
1596 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
1599 if (bmp.GetWidth() != m_style->GetToolSize().x ||
1600 bmp.GetHeight() != m_style->GetToolSize().y) {
1606 if ((tool->last_rect.width &&
1607 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
1609 wxBrush bb(GetGlobalColor(
"GREY3"));
1611 dc.SetPen(*wxTRANSPARENT_PEN);
1612 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
1613 tool->last_rect.width, tool->last_rect.height);
1620 wxImage scaled_image = bmp.ConvertToImage();
1621 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1622 wxIMAGE_QUALITY_HIGH));
1623 dc.DrawBitmap(sbmp, drawAt);
1625 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
1628 dc.DrawBitmap(bmp, drawAt);
1630 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
1638wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
1640 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1643 if ((x >= tool->m_x) && (y >= tool->m_y) &&
1644 (x < (tool->m_x + tool->GetWidth())) &&
1645 (y < (tool->m_y + tool->GetHeight()))) {
1649 node = node->GetNext();
1652 return (wxToolBarToolBase *)NULL;
1655void ocpnToolBarSimple::InvalidateBitmaps() {
1656 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1659 tool->bitmapOK =
false;
1660 node = node->GetNext();
1662 m_bitmap = wxNullBitmap;
1665wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
1667 wxToolBarToolBase *tool = FindById(tool_id);
1670 if (otool) rect = otool->trect;
1680void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
1681 bool WXUNUSED(enable)) {
1683 t->bitmapOK =
false;
1686void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
1687 bool WXUNUSED(toggle)) {
1689 t->bitmapOK =
false;
1697wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
1698 wxToolBarToolBase *tool = FindById(
id);
1699 wxCHECK_MSG(tool,
"",
"no such tool");
1701 return tool->GetShortHelp();
1704wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
1705 wxToolBarToolBase *tool = FindById(
id);
1706 wxCHECK_MSG(tool,
"",
"no such tool");
1708 return tool->GetLongHelp();
1711void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
1712 wxToolBarToolBase *tool = FindById(
id);
1714 (void)tool->SetShortHelp(help);
1718void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
1719 wxToolBarToolBase *tool = FindById(
id);
1721 (void)tool->SetLongHelp(help);
1725int ocpnToolBarSimple::GetToolPos(
int id)
const {
1727 wxToolBarToolsList::compatibility_iterator node;
1729 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1730 if (node->GetData()->GetId() == id)
return pos;
1737bool ocpnToolBarSimple::GetToolState(
int id)
const {
1738 wxToolBarToolBase *tool = FindById(
id);
1739 wxCHECK_MSG(tool,
false,
"no such tool");
1741 return tool->IsToggled();
1744bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
1745 wxToolBarToolBase *tool = FindById(
id);
1746 wxCHECK_MSG(tool,
false,
"no such tool");
1748 return tool->IsEnabled();
1751void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
1752 wxToolBarToolBase *tool = FindById(
id);
1754 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
1755 DoToggleTool(tool, toggle);
1756 InvalidateBitmaps();
1757 gFrame->GetPrimaryCanvas()->Refresh(
true);
1761wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
1762 wxToolBarToolBase *tool = FindById(
id);
1763 return tool ? tool->GetClientData() : (wxObject *)NULL;
1766void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
1767 wxToolBarToolBase *tool = FindById(
id);
1769 wxCHECK_RET(tool,
"no such tool in wxToolBar::SetToolClientData");
1771 tool->SetClientData(clientData);
1774void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
1775 wxToolBarToolBase *tool = FindById(
id);
1777 if (tool->Enable(enable)) {
1778 DoEnableTool(tool, enable);
1783 if (parent && parent->m_FloatingToolbarConfigMenu) {
1784 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
1785 if (configItem) configItem->Check(
true);
1789void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
1792 tool->SetTooltipHiviz(b_hiviz);
1796void ocpnToolBarSimple::ClearTools() {
1797 while (GetToolsCount()) {
1802int ocpnToolBarSimple::GetVisibleToolCount() {
1804 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1808 node = node->GetNext();
1813bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
1814 wxCHECK_MSG(pos < GetToolsCount(),
false,
1815 "invalid position in wxToolBar::DeleteToolByPos()");
1817 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
1819 if (!DoDeleteTool(pos, node->GetData())) {
1823 delete node->GetData();
1824 m_tools.Erase(node);
1829bool ocpnToolBarSimple::DeleteTool(
int id) {
1831 wxToolBarToolsList::compatibility_iterator node;
1832 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1833 if (node->GetData()->GetId() == id)
break;
1838 if (!node || !DoDeleteTool(pos, node->GetData())) {
1842 delete node->GetData();
1843 m_tools.Erase(node);
1848wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
1849 return InsertSeparator(GetToolsCount());
1852wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
1853 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1854 "invalid position in wxToolBar::InsertSeparator()");
1856 wxToolBarToolBase *tool =
1857 CreateTool(wxID_SEPARATOR,
"", wxNullBitmap, wxNullBitmap,
1858 wxITEM_SEPARATOR, (wxObject *)NULL,
"",
"");
1860 if (!tool || !DoInsertTool(pos, tool)) {
1866 m_tools.Insert(pos, tool);
1872wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
1874 wxToolBarToolsList::compatibility_iterator node;
1875 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1876 if (node->GetData()->GetId() == id)
break;
1884 return (wxToolBarToolBase *)NULL;
1887 wxToolBarToolBase *tool = node->GetData();
1888 if (!DoDeleteTool(pos, tool)) {
1889 return (wxToolBarToolBase *)NULL;
1892 m_tools.Erase(node);
1897wxControl *ocpnToolBarSimple::FindControl(
int id) {
1898 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1899 node; node = node->GetNext()) {
1900 const wxToolBarToolBase *
const tool = node->GetData();
1901 if (tool->IsControl()) {
1902 wxControl *
const control = tool->GetControl();
1905 wxFAIL_MSG(
"NULL control in toolbar?");
1906 }
else if (control->GetId() ==
id) {
1916wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
1917 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
1919 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1920 node; node = node->GetNext()) {
1921 tool = node->GetData();
1922 if (tool->GetId() == id) {
1939bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
1940 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
1944 event.SetInt((
int)toggleDown);
1947 event.SetExtraLong((
long)toggleDown);
1949 gFrame->GetEventHandler()->AddPendingEvent(event);
1955void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
1959 if (m_parentContainer) {
1960 if (m_parentContainer->m_FloatingToolbarConfigMenu) {
1963 wxDefaultPosition, wxSize(100, 100));
1964 int rc = dlg->ShowModal();
1967 if (rc == wxID_OK) {
1968 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
1969 event.SetEventObject(
this);
1972 gFrame->GetEventHandler()->AddPendingEvent(event);
1978void ocpnToolBarSimple::DoPluginToolUp() {
1983 ArrayOfPlugInToolbarTools tool_array =
1985 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1987 if (m_last_plugin_down_id == pttc->id) {
1994 m_last_plugin_down_id = -1;
1997void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
1998 const wxString &iconName) {
2004 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
2005 otool->m_width, otool->m_height);
2006 tool->SetNormalBitmap(bmp);
2007 otool->SetIconName(iconName);
2012void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
2017 otool->pluginNormalIconSVG = fileSVG;
2022void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
2023 wxBitmap *bmpRollover) {
2026 if (tool->isPluginTool) {
2027 if (bmp->GetWidth() != tool->GetWidth()) {
2029 wxImage ibmp = bmp->ConvertToImage();
2030 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2031 wxIMAGE_QUALITY_HIGH);
2032 wxBitmap sbmp = wxBitmap(ibmp);
2033 tool->pluginNormalIcon = sbmp;
2036 tool->pluginNormalIcon = *bmp;
2039 if (bmpRollover->GetWidth() != tool->GetWidth()) {
2040 if (bmpRollover->IsOk()) {
2041 wxImage ibmp = bmpRollover->ConvertToImage();
2042 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2043 wxIMAGE_QUALITY_HIGH);
2044 wxBitmap sbmp = wxBitmap(ibmp);
2045 tool->pluginRolloverIcon = sbmp;
2048 tool->pluginRolloverIcon = *bmpRollover;
2050 tool->bitmapOK =
false;
2053 tool->SetNormalBitmap(*bmp);
2054 tool->bitmapOK =
true;
2056 InvalidateBitmaps();
2060void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
2061 wxString fileSVGRollover,
2062 wxString fileSVGToggled) {
2065 tool->pluginNormalIconSVG = fileSVGNormal;
2066 tool->pluginRolloverIconSVG = fileSVGRollover;
2067 tool->pluginToggledIconSVG = fileSVGToggled;
2068 tool->bitmapOK =
false;
2069 InvalidateBitmaps();
2075ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
2076 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
2078 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
2080 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
2081 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2084 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
2085 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
2087 choices.push_back(
new wxRadioButton(
2088 this, 1, _(
"No, and permanently remove the option to hide it."),
2089 wxDefaultPosition));
2092 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
2094 wxStdDialogButtonSizer *buttonSizer =
2095 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2097 wxStaticText *textCtrl =
2098 new wxStaticText(
this, wxID_ANY,
2099 _(
"The Man Over Board button could be an important "
2100 "safety feature.\nAre you sure you want to hide it?"));
2102 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
2103 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
2104 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
2105 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
2106 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
2108 topSizer->SetSizeHints(
this);
2112int ToolbarMOBDialog::GetSelection() {
2113 for (
unsigned int i = 0; i < choices.size(); i++) {
2114 if (choices[i]->GetValue())
return choices[i]->GetId();
2134 const wxString &caption,
2136 const wxSize &size,
long style) {
2137 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
2138 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
2140 m_configMenu = NULL;
2141 m_ToolbarDialogAncestor = sponsor;
2143 if (m_ToolbarDialogAncestor)
2144 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
2147 GetSizer()->Fit(
this);
2152ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
2159 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
2160 SetSizer(itemBoxSizer1);
2162 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
2163 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
2164 itemDialog1->SetScrollRate(2, 2);
2171 wxString wqs = getFontQtStylesheet(qFont);
2172 wxCharBuffer sbuf = wqs.ToUTF8();
2173 QString qsb = QString(sbuf.data());
2175 QString qsbq = getQtStyleSheet();
2177 this->GetHandle()->setStyleSheet(qsb + qsbq);
2180 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
2182 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
2183 itemDialog1->SetSizer(itemBoxSizer2);
2185 wxStaticBox *itemStaticBoxSizer3Static =
2186 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Choose Toolbar Icons"));
2187 wxStaticBoxSizer *itemStaticBoxSizer3 =
2188 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
2189 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
2194 nitems = m_configMenu->GetMenuItemCount();
2197 for (
int i = 0; i < nitems; i++) {
2198 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon)
continue;
2199 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2201 wxString label = item->GetItemLabel();
2202 int l = label.Len();
2203 max_width = wxMax(max_width, l);
2205 wxString windowName =
"";
2206 if (item->GetId() == ID_MOB + 100) windowName =
"MOBCheck";
2209 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
2210 wxDefaultSize, 0, wxDefaultValidator, windowName);
2212 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
2213 cb->SetValue(item->IsChecked());
2215 cboxes.push_back(cb);
2219 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
2220 (nitems + 4) * GetCharHeight() * 2);
2222 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
2223 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
2225 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
2226 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
2228 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
2229 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
2232 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
2233 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2236 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
2237 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2238 m_OKButton->SetDefault();
2240 m_CancelButton->Connect(
2241 wxEVT_COMMAND_BUTTON_CLICKED,
2242 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL,
this);
2243 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2244 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
2247 SetColorScheme((ColorScheme)0);
2250void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
2252void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
2253 EndModal(wxID_CANCEL);
2256void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
2257 unsigned int ncheck = 0;
2259 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
2260 wxString new_toolbarConfig = toolbarConfigSave;
2262 for (
unsigned int i = 0; i < cboxes.size(); i++) {
2263 wxCheckBox *cb = cboxes[i];
2264 wxString cbName = cb->GetName();
2266 if (cbName.IsSameAs(
"MOBCheck") && !cb->IsChecked()) {
2269 int dialog_ret = mdlg.ShowModal();
2270 int answer = mdlg.GetSelection();
2271 if (dialog_ret == wxID_OK) {
2273 g_bPermanentMOBIcon =
true;
2275 }
else if (answer == 0) {
2279 new_toolbarConfig = toolbarConfigSave;
2284 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2285 if (new_toolbarConfig.Len() > i) {
2286 new_toolbarConfig.SetChar(i, cb->IsChecked() ?
'X' :
'.');
2288 new_toolbarConfig.Append(cb->IsChecked() ?
'X' :
'.');
2290 item->Check(cb->IsChecked());
2291 if (cb->IsChecked()) ncheck++;
2298 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN ,
'X' );
2300 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
2303 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
2305 item->Check(
true );
2309 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
2314void ToolbarChoicesDialog::RecalculateSize() {
2315 wxSize esize = GetSize();
2318 wxSize dsize = GetParent()->GetClientSize();
2319 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
2320 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
2326 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
2327 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
2331 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...