36#include "model/ocpn_types.h"
40#include "pluginmanager.h"
42#include "OCPNPlatform.h"
46#include "model/idents.h"
47#include "ocpn_frame.h"
49#ifdef __OCPN__ANDROID__
50#include "androidUTIL.h"
54#include "glChartCanvas.h"
57extern bool g_bTransparentToolbar;
58extern bool g_bTransparentToolbarInOpenGLOK;
63extern bool g_bPermanentMOBIcon;
64extern bool g_bsmoothpanzoom;
66extern bool g_bmasterToolbarFull;
68extern wxString g_toolbarConfig;
69extern double g_plus_minus_zoom_factor;
70extern int g_maintoolbar_x;
71extern int g_maintoolbar_y;
72extern bool g_disable_main_toolbar;
75extern GLenum g_texture_rectangle_format;
81 const wxBitmap &bmpNormal,
const wxBitmap &bmpRollover,
82 wxItemKind kind, wxObject *clientData,
83 const wxString &shortHelp,
const wxString &longHelp)
84 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, label, bmpNormal,
85 bmpRollover, kind, clientData, shortHelp, longHelp) {
90 m_btooltip_hiviz =
false;
92 toolname = g_pi_manager->GetToolOwnerCommonName(
id);
93 if (toolname == _T(
"")) {
100 pluginNormalIcon = bmpNormal;
101 pluginRolloverIcon = bmpRollover;
106 const wxBitmap &bmpRollover, wxItemKind kind,
107 wxObject *clientData,
const wxString &shortHelp,
108 const wxString &longHelp)
109 : wxToolBarToolBase((wxToolBarBase *)tbar,
id, _T(
""), bmpNormal,
110 bmpRollover, kind, clientData, shortHelp, longHelp) {
114 m_btooltip_hiviz =
false;
115 isPluginTool =
false;
117 m_bmpNormal = bmpNormal;
121 void SetSize(
const wxSize &size) {
126 wxCoord GetWidth()
const {
return m_width; }
128 wxCoord GetHeight()
const {
return m_height; }
130 wxString GetToolname() {
return toolname; }
132 void SetIconName(wxString name) { iconName = name; }
133 wxString GetIconName() {
return iconName; }
135 void SetTooltipHiviz(
bool enable) { m_btooltip_hiviz = enable; }
144 wxBitmap pluginNormalIcon;
145 wxBitmap pluginRolloverIcon;
146 const wxBitmap *pluginToggledIcon;
153 bool m_btooltip_hiviz;
155 wxString pluginNormalIconSVG;
156 wxString pluginRolloverIconSVG;
157 wxString pluginToggledIconSVG;
158 wxBitmap m_activeBitmap;
165ocpnFloatingToolbarDialog::ocpnFloatingToolbarDialog(wxWindow *parent,
173 m_position = position;
175 m_sizefactor = size_factor;
178 m_bAutoHideToolbar =
false;
179 m_nAutoHideToolbar = 5;
180 m_toolbar_scale_tools_shown =
false;
181 m_backcolorString = _T(
"GREY3");
182 m_toolShowMask = _T(
"XXXXXXXXXXXXXXXX");
183 n_toolbarHideMethod = TOOLBAR_HIDE_TO_GRABBER;
184 b_canToggleOrientation =
true;
185 m_enableRolloverBitmaps =
true;
188 m_ptoolbar = CreateNewToolbar();
189 if (m_ptoolbar) m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"GREY3"));
190 m_cs = (ColorScheme)-1;
192 m_style = g_StyleManager->GetCurrentStyle();
193 SetULDockPosition(wxPoint(4, 4));
195 SetGeometry(
false, wxRect());
204 m_marginsInvisible = m_style->marginsInvisible;
206 m_FloatingToolbarConfigMenu = NULL;
208 m_fade_timer.SetOwner(
this);
209 this->Connect(wxEVT_TIMER,
210 wxTimerEventHandler(ocpnFloatingToolbarDialog::FadeTimerEvent),
213 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0))
214 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
216 m_bsubmerged =
false;
217 m_benableSubmerge =
true;
220ocpnFloatingToolbarDialog::~ocpnFloatingToolbarDialog() {
221 delete m_FloatingToolbarConfigMenu;
226void ocpnFloatingToolbarDialog::FadeTimerEvent(wxTimerEvent &event) {
227 if (n_toolbarHideMethod == TOOLBAR_HIDE_TO_FIRST_TOOL) {
228 if (g_bmasterToolbarFull) {
229 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0) ) {
232 gFrame->GetPrimaryCanvas()->ScreenToClient(::wxGetMousePosition());
234 wxRect r = GetToolbarRect();
235 if (r.Contains(mp))
return;
237 wxCommandEvent event;
238 event.SetId(ID_MASTERTOGGLE);
239 gFrame->OnToolLeftClick(event);
246 m_Items.push_back(item);
249int ocpnFloatingToolbarDialog::RebuildToolbar() {
256 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
260 bool bEnabled = _toolbarConfigMenuUtil(tic);
263 wxToolBarToolBase *tool =
264 tb->AddTool(tic->m_ID, tic->m_label, tic->m_bmpNormal,
265 tic->m_bmpDisabled, tic->m_toolKind, tic->m_tipString);
270 if (!tic->m_NormalIconSVG.IsEmpty()) {
271 tb->SetToolBitmapsSVG(tic->m_ID, tic->m_NormalIconSVG,
272 tic->m_RolloverIconSVG, tic->m_ToggledIconSVG);
282void ocpnFloatingToolbarDialog::SetULDockPosition(wxPoint position) {
283 if (position.x >= 0) m_dock_min_x = position.x;
284 if (position.y >= 0) m_dock_min_y = position.y;
287size_t ocpnFloatingToolbarDialog::GetToolCount() {
289 return m_ptoolbar->GetToolsCount();
294void ocpnFloatingToolbarDialog::SetToolShowMask(wxString mask) {}
296void ocpnFloatingToolbarDialog::SetToolShowCount(
int count) {
298 m_ptoolbar->SetToolShowCount(count);
299 m_ptoolbar->SetDirty(
true);
303int ocpnFloatingToolbarDialog::GetToolShowCount(
void) {
305 return m_ptoolbar->GetToolShowCount();
310void ocpnFloatingToolbarDialog::SetBackGroundColorString(wxString colorRef) {
311 m_backcolorString = colorRef;
312 SetColorScheme(m_cs);
315void ocpnFloatingToolbarDialog::OnKeyDown(wxKeyEvent &event) {
event.Skip(); }
317void ocpnFloatingToolbarDialog::OnKeyUp(wxKeyEvent &event) {
event.Skip(); }
319void ocpnFloatingToolbarDialog::CreateConfigMenu() {
320 if (m_FloatingToolbarConfigMenu)
delete m_FloatingToolbarConfigMenu;
321 m_FloatingToolbarConfigMenu =
new wxMenu();
324bool ocpnFloatingToolbarDialog::_toolbarConfigMenuUtil(
326 if (m_FloatingToolbarConfigMenu) {
327 wxMenuItem *menuitem;
329 if (tic->m_ID == ID_MOB && g_bPermanentMOBIcon)
return true;
331 if (tic->m_bRequired)
return true;
332 if (tic->m_bPlugin)
return true;
339 int menuItemId = tic->m_ID + idOffset;
341 menuitem = m_FloatingToolbarConfigMenu->FindItem(menuItemId);
344 return menuitem->IsChecked();
347 menuitem = m_FloatingToolbarConfigMenu->AppendCheckItem(menuItemId,
349 size_t n = m_FloatingToolbarConfigMenu->GetMenuItemCount();
350 menuitem->Check(m_configString.Len() >= n
351 ? m_configString.GetChar(n - 1) == _T(
'X')
353 return menuitem->IsChecked();
358void ocpnFloatingToolbarDialog::EnableTool(
int toolid,
bool enable) {
359 if (m_ptoolbar) m_ptoolbar->EnableTool(toolid, enable);
362void ocpnFloatingToolbarDialog::SetColorScheme(ColorScheme cs) {
364 wxColour back_color = GetGlobalColor(m_backcolorString);
367 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T(
"GREY1")));
368 m_ptoolbar->SetColorScheme(cs);
372wxSize ocpnFloatingToolbarDialog::GetToolSize() {
373 wxSize style_tool_size;
375 style_tool_size = m_style->GetToolSize();
377 style_tool_size.x *= m_sizefactor;
378 style_tool_size.y *= m_sizefactor;
380 style_tool_size.x = 32;
381 style_tool_size.y = 32;
384 return style_tool_size;
387void ocpnFloatingToolbarDialog::SetGeometry(
bool bAvoid, wxRect rectAvoid) {
389 wxSize style_tool_size = m_style->GetToolSize();
391 style_tool_size.x *= m_sizefactor;
392 style_tool_size.y *= m_sizefactor;
394 m_ptoolbar->SetToolBitmapSize(style_tool_size);
396 wxSize tool_size = m_ptoolbar->GetToolBitmapSize();
397 int grabber_width = m_style->GetIcon(_T(
"grabber")).GetWidth();
404 m_pparent->GetClientSize().x -
405 (tool_size.x + m_style->GetToolSeparation()) * 2;
406 if (bAvoid && !rectAvoid.IsEmpty()) {
407 avoid_start = m_pparent->GetClientSize().x - rectAvoid.width -
411 max_rows = (m_pparent->GetClientSize().y /
412 (tool_size.y + m_style->GetToolSeparation())) -
415 max_cols = (avoid_start - grabber_width) /
416 (tool_size.x + m_style->GetToolSeparation());
419 if (m_orient == wxTB_VERTICAL)
420 max_rows = wxMax(max_rows, 2);
422 max_cols = wxMax(max_cols, 2);
425 if (m_orient == wxTB_VERTICAL)
426 m_ptoolbar->SetMaxRowsCols(max_rows, 100);
428 m_ptoolbar->SetMaxRowsCols(100, max_cols);
429 m_ptoolbar->SetSizeFactor(m_sizefactor);
433void ocpnFloatingToolbarDialog::SetDefaultPosition() {
436 if (m_pparent && m_ptoolbar) {
437 wxSize cs = m_pparent->GetClientSize();
439 m_position.x = m_dock_min_x;
440 else if (1 == m_dock_x)
441 m_position.x = cs.x - m_ptoolbar->m_maxWidth;
444 m_position.y = m_dock_min_y;
445 else if (1 == m_dock_y)
446 m_position.y = cs.y - m_ptoolbar->m_maxHeight;
448 m_position.x = wxMin(cs.x - m_ptoolbar->m_maxWidth, m_position.x);
449 m_position.y = wxMin(cs.y - m_ptoolbar->m_maxHeight, m_position.y);
451 m_position.x = wxMax(m_dock_min_x, m_position.x);
452 m_position.y = wxMax(m_dock_min_y, m_position.y);
454 m_position.y += m_auxOffsetY;
456 g_maintoolbar_x = m_position.x;
457 g_maintoolbar_y = m_position.y;
478void ocpnFloatingToolbarDialog::Submerge() {
481 if (m_ptoolbar) m_ptoolbar->KillTooltip();
484void ocpnFloatingToolbarDialog::HideTooltip() {
485#ifndef __OCPN__ANDROID__
486 if (m_ptoolbar) m_ptoolbar->HideTooltip();
490void ocpnFloatingToolbarDialog::ShowTooltips() {
491#ifndef __OCPN__ANDROID__
492 if (m_ptoolbar) m_ptoolbar->EnableTooltips();
496void ocpnFloatingToolbarDialog::ToggleOrientation() {}
498wxRect ocpnFloatingToolbarDialog::GetToolbarRect() {
499 return wxRect(m_position.x, m_position.y, m_ptoolbar->m_maxWidth,
500 m_ptoolbar->m_maxHeight);
503wxSize ocpnFloatingToolbarDialog::GetToolbarSize() {
504 return wxSize(m_ptoolbar->m_maxWidth, m_ptoolbar->m_maxHeight);
507wxPoint ocpnFloatingToolbarDialog::GetToolbarPosition() {
508 return wxPoint(m_position.x, m_position.y);
511bool ocpnFloatingToolbarDialog::MouseEvent(wxMouseEvent &event) {
512 if (g_disable_main_toolbar)
return false;
514 bool bproc = m_ptoolbar->OnMouseEvent(event, m_position);
515 if (bproc) m_ptoolbar->CreateBitmap();
521void ocpnFloatingToolbarDialog::RefreshToolbar() {
523 if (m_ptoolbar->IsDirty()) {
525 gFrame->GetPrimaryCanvas()->Refresh();
530void ocpnFloatingToolbarDialog::SetAutoHideTimer(
int time) {
531 m_nAutoHideToolbar = time;
532 if (m_bAutoHideToolbar) {
534 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
538void ocpnFloatingToolbarDialog::RefreshFadeTimer() {
539 if (m_bAutoHideToolbar && (m_nAutoHideToolbar > 0)) {
540 m_fade_timer.Start(m_nAutoHideToolbar * 1000);
544void ocpnFloatingToolbarDialog::SetToolShortHelp(
int id,
const wxString &help) {
545 if (m_ptoolbar) m_ptoolbar->SetToolShortHelp(
id, help);
548void ocpnFloatingToolbarDialog::Realize() {
550 m_ptoolbar->Realize();
551 m_ptoolbar->CreateBitmap();
552 m_toolbar_image.Destroy();
556void ocpnFloatingToolbarDialog::DrawDC(
ocpnDC &dc,
double displayScale) {
558 m_ptoolbar->CreateBitmap();
559 if (m_ptoolbar->GetBitmap().IsOk()) {
560 dc.DrawBitmap(m_ptoolbar->GetBitmap(), m_position.x, m_position.y,
false);
561 m_ptoolbar->SetDirty(
false);
566void ocpnFloatingToolbarDialog::DrawGL(
ocpnDC &gldc,
double displayScale) {
567 if (g_disable_main_toolbar)
return;
570 if (!m_ptoolbar)
return;
572 wxColour backColor = GetGlobalColor(
"GREY3");
573 gldc.SetBrush(wxBrush(backColor));
574 gldc.SetPen(wxPen(backColor));
576 wxRect r = GetToolbarRect();
577 int m_end_margin = wxMin(GetToolSize().x, GetToolSize().y) / 8;
579 if (m_orient == wxHORIZONTAL)
580 gldc.DrawRoundedRectangle(
581 (r.x - m_end_margin / 2) * displayScale, (r.y - 1) * displayScale,
582 (r.width + m_end_margin) * displayScale, (r.height + 2) * displayScale,
583 (m_end_margin * 1) * displayScale);
585 gldc.DrawRoundedRectangle(
586 (r.x - 1) * displayScale, (r.y - m_end_margin / 2) * displayScale,
587 (r.width + 2) * displayScale, (r.height + m_end_margin) * displayScale,
588 (m_end_margin * 1.5) * displayScale);
590 int width = GetToolbarSize().x;
591 int height = GetToolbarSize().y;
593 m_ptoolbar->CreateBitmap(displayScale);
597 glGenTextures(1, &m_texture);
599 glBindTexture(g_texture_rectangle_format, m_texture);
600 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
602 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
604 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
606 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
609 glBindTexture(g_texture_rectangle_format, m_texture);
612 if (!m_toolbar_image.IsOk()) {
614 m_toolbar_image = m_ptoolbar->GetBitmap().ConvertToImage();
616 unsigned char *d = m_toolbar_image.GetData();
617 unsigned char *e =
new unsigned char[4 * width * height];
618 for (
int y = 0; y < height; y++)
619 for (
int x = 0; x < width; x++) {
620 int i = y * width + x;
621 memcpy(e + 4 * i, d + 3 * i, 3);
624 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, width, height, 0,
625 GL_RGBA, GL_UNSIGNED_BYTE, e);
627 glDisable(g_texture_rectangle_format);
633 glEnable(g_texture_rectangle_format);
634 glBindTexture(g_texture_rectangle_format, m_texture);
637 int x0 = GetToolbarPosition().x, x1 = x0 + width;
638 int y0 = GetToolbarPosition().y - 0, y1 = y0 + height;
645 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
646 tx = width, ty = height;
673 auto canvas = gFrame->GetPrimaryCanvas();
674 canvas->GetglCanvas()->RenderTextures(gldc, coords, uv, 4,
677 glDisable(g_texture_rectangle_format);
678 glBindTexture(g_texture_rectangle_format, 0);
686void ocpnFloatingToolbarDialog::OnToolLeftClick(wxCommandEvent &event) {
690 m_pparent->GetEventHandler()->AddPendingEvent(event);
698 m_ptoolbar = CreateNewToolbar();
705 long winstyle = wxNO_BORDER | wxTB_FLAT;
706 winstyle |= m_orient;
713 m_ptoolbar->SetToggledBackgroundColour(GetGlobalColor(_T(
"GREY1")));
714 m_ptoolbar->SetColorScheme(m_cs);
715 m_ptoolbar->EnableRolloverBitmaps(GetEnableRolloverBitmaps());
720void ocpnFloatingToolbarDialog::DestroyToolBar() {
721 g_toolbarConfig = GetToolConfigString();
724 m_ptoolbar->ClearTools();
729 for (
auto it = m_Items.cbegin(); it != m_Items.cend(); it++) {
739extern bool g_bTrackActive;
740extern s52plib *ps52plib;
743 if (!g_pi_manager)
return false;
746 int n_tools = tb->GetToolsCount();
750 ArrayOfPlugInToolbarTools tool_array =
751 g_pi_manager->GetPluginToolbarToolArray();
753 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
755 if (pttc->position == n_tools) {
759 case GLOBAL_COLOR_SCHEME_DAY:
760 ptool_bmp = pttc->bitmap_day;
763 case GLOBAL_COLOR_SCHEME_DUSK:
764 ptool_bmp = pttc->bitmap_dusk;
766 case GLOBAL_COLOR_SCHEME_NIGHT:
767 ptool_bmp = pttc->bitmap_night;
770 ptool_bmp = pttc->bitmap_day;
775 wxToolBarToolBase *tool =
776 tb->AddTool(pttc->id, wxString(pttc->label), *(ptool_bmp),
777 wxString(pttc->shortHelp), pttc->kind);
779 tb->SetToolBitmapsSVG(pttc->id, pttc->pluginNormalIconSVG,
780 pttc->pluginRolloverIconSVG,
781 pttc->pluginToggledIconSVG);
790 while (CheckAndAddPlugInTool(tb)) {
796void ocpnFloatingToolbarDialog::EnableRolloverBitmaps(
bool bEnable) {
797 m_enableRolloverBitmaps = bEnable;
798 if (m_ptoolbar) m_ptoolbar->EnableRolloverBitmaps(bEnable);
809 void OnPaint(wxPaintEvent &event);
811 void SetColorScheme(ColorScheme cs);
812 void SetString(wxString &s) { m_string = s; }
813 void SetPosition(wxPoint pt) { m_position = pt; }
814 void SetBitmap(
void);
816 void SetHiviz(
bool hiviz) { m_hiviz = hiviz; }
818 wxSize GetRenderedSize(
void);
825 wxColour m_back_color;
826 wxColour m_text_color;
830 DECLARE_EVENT_TABLE()
838EVT_PAINT(ToolTipWin::OnPaint)
844 : wxFrame(parent, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(1, 1),
845 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR) {
849 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
851 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
853 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
854 SetBackgroundColour(m_back_color);
855 m_cs = GLOBAL_COLOR_SCHEME_RGB;
860ToolTipWin::~ToolTipWin() {
delete m_pbm; }
862void ToolTipWin::SetColorScheme(ColorScheme cs) {
864 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
866 GetDimedColor(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
869 m_text_color = GetDimedColor(FontMgr::Get().GetFontColor(_(
"ToolTips")));
875wxSize ToolTipWin::GetRenderedSize(
void) {
881 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
882 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, plabelFont);
890void ToolTipWin::SetBitmap() {
896 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
897 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
899 cdc.GetTextExtent(m_string, &w, &h, NULL, NULL, &sFont);
901 m_size.x = w + GetCharWidth() * 2;
902 m_size.y = h + GetCharHeight() / 2;
910 m_pbm =
new wxBitmap(m_size.x, m_size.y, -1);
911 mdc.SelectObject(*m_pbm);
913 wxPen pborder(m_text_color);
914 wxBrush bback(m_back_color);
919 if ((m_cs == GLOBAL_COLOR_SCHEME_DUSK) ||
920 (m_cs == GLOBAL_COLOR_SCHEME_NIGHT)) {
921 wxBrush hv_back(wxColour(200, 200, 200));
922 mdc.SetBrush(hv_back);
925 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
929 mdc.SetTextForeground(m_text_color);
930 mdc.SetTextBackground(m_back_color);
932 int offx = GetCharWidth();
933 int offy = GetCharHeight() / 4;
936 mdc.DrawText(m_string, offx, offy);
938 SetClientSize(m_size.x, m_size.y);
939 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
942void ToolTipWin::OnPaint(wxPaintEvent &event) {
944 GetClientSize(&width, &height);
947 if (m_string.Len()) {
949 mdc.SelectObject(*m_pbm);
950 dc.Blit(0, 0, width, height, &mdc, 0, 0);
961EVT_TIMER(TOOLTIPON_TIMER, ocpnToolBarSimple::OnToolTipTimerEvent)
962EVT_TIMER(TOOLTIPOFF_TIMER, ocpnToolBarSimple::OnToolTipOffTimerEvent)
970 int id, const wxString &label, const wxBitmap &bmpNormal,
971 const wxBitmap &bmpDisabled, wxItemKind kind, wxObject *clientData,
972 const wxString &shortHelp, const wxString &longHelp) {
973 if (m_style->NativeToolIconExists(label)) {
974 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
975 clientData, shortHelp, longHelp);
977 wxString testToolname = g_pi_manager->GetToolOwnerCommonName(
id);
979 if (testToolname == _T(
"")) {
981 clientData, shortHelp, longHelp);
983 return new ocpnToolBarTool(
this,
id, label, bmpNormal, bmpDisabled, kind,
984 clientData, shortHelp, longHelp);
993void ocpnToolBarSimple::Init() {
994 m_currentRowsOrColumns = 0;
996 m_lastX = m_lastY = 0;
998 m_maxWidth = m_maxHeight = 0;
1000 m_pressedTool = m_currentTool = -1;
1002 m_xPos = m_yPos = wxDefaultCoord;
1004 m_style = g_StyleManager->GetCurrentStyle();
1006 m_defaultWidth = 16;
1007 m_defaultHeight = 15;
1009 m_toggle_bg_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
1010 m_toolOutlineColour.Set(_T(
"BLACK"));
1011 m_pToolTipWin = NULL;
1012 m_last_ro_tool = NULL;
1014 m_btoolbar_is_zooming =
false;
1015 m_sizefactor = 1.0f;
1017 m_last_plugin_down_id = -1;
1020 m_btooltip_show =
false;
1021#ifndef __OCPN__ANDROID__
1024 m_tbenableRolloverBitmaps =
false;
1027wxToolBarToolBase *ocpnToolBarSimple::DoAddTool(
1028 int id,
const wxString &label,
const wxBitmap &bitmap,
1029 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1030 const wxString &longHelp, wxObject *clientData, wxCoord xPos,
1037 return InsertTool(GetToolsCount(),
id, label, bitmap, bmpDisabled, kind,
1038 shortHelp, longHelp, clientData);
1043wxToolBarToolBase *ocpnToolBarSimple::AddTool(
1044 int toolid,
const wxString &label,
const wxBitmap &bitmap,
1045 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1046 const wxString &longHelp, wxObject *data) {
1049 GetToolsCount(), toolid, label, bitmap, bmpDisabled, kind, shortHelp,
1054wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
1055 size_t pos,
int id,
const wxString &label,
const wxBitmap &bitmap,
1056 const wxBitmap &bmpDisabled, wxItemKind kind,
const wxString &shortHelp,
1057 const wxString &longHelp, wxObject *clientData) {
1058 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1059 _T(
"invalid position in wxToolBar::InsertTool()"));
1061 wxToolBarToolBase *tool = CreateTool(
id, label, bitmap, bmpDisabled, kind,
1062 clientData, shortHelp, longHelp);
1064 if (!InsertTool(pos, tool)) {
1073wxToolBarToolBase *ocpnToolBarSimple::InsertTool(
size_t pos,
1074 wxToolBarToolBase *tool) {
1075 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
1076 _T(
"invalid position in wxToolBar::InsertTool()"));
1078 if (!tool || !DoInsertTool(pos, tool)) {
1082 m_tools.Insert(pos, tool);
1088bool ocpnToolBarSimple::DoInsertTool(
size_t WXUNUSED(pos),
1089 wxToolBarToolBase *toolBase) {
1095 if (tool->isPluginTool) {
1096 for (
unsigned int i = 0; i < GetToolsCount(); i++) {
1097 if (tool->GetToolname() ==
1099 tool->toolname << _T(
"1");
1105 if (tool->m_x == wxDefaultCoord) tool->m_x = m_style->GetLeftMargin();
1108 if (tool->m_y == wxDefaultCoord) tool->m_y = m_style->GetTopMargin();
1110 if (tool->IsButton()) {
1111 tool->SetSize(GetToolSize());
1114 if ((tool->m_x + tool->GetNormalBitmap().GetWidth() +
1115 m_style->GetLeftMargin()) > m_maxWidth)
1117 (wxCoord)((tool->m_x + tool->GetWidth() + m_style->GetLeftMargin()));
1119 if ((tool->m_y + tool->GetNormalBitmap().GetHeight() +
1120 m_style->GetTopMargin()) > m_maxHeight)
1122 (wxCoord)((tool->m_y + tool->GetHeight() + m_style->GetTopMargin()));
1125 else if (tool->IsControl()) {
1126 tool->SetSize(tool->GetControl()->GetSize());
1129 tool->b_hilite =
false;
1134bool ocpnToolBarSimple::DoDeleteTool(
size_t WXUNUSED(pos),
1135 wxToolBarToolBase *tool) {
1139 if (m_last_ro_tool == tool) m_last_ro_tool = NULL;
1147 const wxPoint &pos,
const wxSize &size,
1148 long style,
int orient) {
1149 m_parentContainer = parent;
1168 m_tooltip_timer.SetOwner(
this, TOOLTIPON_TIMER);
1169 m_tooltipoff_timer.SetOwner(
this, TOOLTIPOFF_TIMER);
1170 m_tooltip_off = 3000;
1172 m_tbenableRolloverBitmaps =
false;
1177ocpnToolBarSimple::~ocpnToolBarSimple() {
1178 if (m_pToolTipWin) {
1179 m_pToolTipWin->Destroy();
1180 m_pToolTipWin = NULL;
1184void ocpnToolBarSimple::EnableTooltips() {
1185#ifndef __OCPN__ANDROID__
1186 m_btooltip_show =
true;
1190void ocpnToolBarSimple::DisableTooltips() {
1191#ifndef __OCPN__ANDROID__
1192 ocpnToolBarSimple::m_btooltip_show =
false;
1196void ocpnToolBarSimple::KillTooltip() {
1197 m_btooltip_show =
false;
1199 if (m_pToolTipWin) {
1200 m_pToolTipWin->Hide();
1201 m_pToolTipWin->Destroy();
1202 m_pToolTipWin = NULL;
1204 m_tooltip_timer.Stop();
1207 gFrame->GetFocusCanvas()->TriggerDeferredFocus();
1210void ocpnToolBarSimple::HideTooltip() {
1211#ifndef __OCPN__ANDROID__
1212 if (m_pToolTipWin) {
1213 m_pToolTipWin->Hide();
1218void ocpnToolBarSimple::SetColorScheme(ColorScheme cs) {
1219#ifndef __OCPN__ANDROID__
1220 if (m_pToolTipWin) {
1221 m_pToolTipWin->Destroy();
1222 m_pToolTipWin = NULL;
1225 m_toolOutlineColour = GetGlobalColor(_T(
"UIBDR"));
1227 m_currentColorScheme = cs;
1230bool ocpnToolBarSimple::Realize() {
1232 m_style->SetOrientation(wxTB_VERTICAL);
1234 m_style->SetOrientation(wxTB_HORIZONTAL);
1236 wxSize toolSize = wxSize(-1, -1);
1237 int separatorSize = m_style->GetToolSeparation() * m_sizefactor;
1238 int topMargin = m_style->GetTopMargin() * m_sizefactor;
1239 int leftMargin = m_style->GetLeftMargin() * m_sizefactor;
1241 m_currentRowsOrColumns = 0;
1243 m_lastX = leftMargin;
1244 m_lastY = topMargin;
1249 bool firstNode =
true;
1250 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1255 if (iNode >= m_nShowTools)
break;
1261 if (toolSize.x == -1) {
1262 if (!tool->IsSeparator()) {
1263 toolSize.x = tool->m_width;
1264 toolSize.y = tool->m_height;
1268 tool->firstInLine = firstNode;
1269 tool->lastInLine =
false;
1272 tool->last_rect.width = 0;
1274 if (tool->IsSeparator()) {
1283 if (m_currentRowsOrColumns >= m_maxRows)
1284 m_lastX += separatorSize;
1286 m_lastY += separatorSize;
1288 }
else if (tool->IsButton()) {
1289 if (!IsVertical()) {
1290 if (m_currentRowsOrColumns >= m_maxCols) {
1291 tool->firstInLine =
true;
1292 if (lastTool && m_LineCount > 1) lastTool->lastInLine =
true;
1294 m_currentRowsOrColumns = 0;
1295 m_lastX = leftMargin;
1296 m_lastY += toolSize.y + topMargin;
1298 tool->m_x = (wxCoord)m_lastX;
1299 tool->m_y = (wxCoord)m_lastY;
1301 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1302 tool->trect.Inflate(separatorSize / 2, topMargin);
1304 m_lastX += toolSize.x + separatorSize;
1306 if (m_currentRowsOrColumns >= m_maxRows) {
1307 tool->firstInLine =
true;
1308 if (lastTool) lastTool->lastInLine =
true;
1310 m_currentRowsOrColumns = 0;
1311 m_lastX += toolSize.x + leftMargin;
1312 m_lastY = topMargin;
1314 tool->m_x = (wxCoord)m_lastX;
1315 tool->m_y = (wxCoord)m_lastY;
1317 tool->trect = wxRect(tool->m_x, tool->m_y, toolSize.x, toolSize.y);
1318 tool->trect.Inflate((separatorSize / 2), topMargin);
1320 m_lastY += toolSize.y + separatorSize;
1322 m_currentRowsOrColumns++;
1337 if (m_lastX > m_maxWidth) m_maxWidth = m_lastX;
1338 if (m_lastY > m_maxHeight) m_maxHeight = m_lastY;
1341 node = node->GetNext();
1344 if (lastTool && (m_LineCount > 1 || IsVertical()))
1345 lastTool->lastInLine =
true;
1347 if (!IsVertical()) {
1348 m_maxHeight += toolSize.y;
1349 m_maxHeight += m_style->GetBottomMargin();
1351 m_maxWidth += toolSize.x;
1352 m_maxWidth += m_style->GetRightMargin() * m_sizefactor;
1355 m_bitmap = wxNullBitmap;
1360wxBitmap &ocpnToolBarSimple::CreateBitmap(
double display_scale) {
1361 if (m_bitmap.IsOk())
return m_bitmap;
1364 int width = m_maxWidth;
1365 int height = m_maxHeight;
1368 wxBitmap bm(width, height);
1369 mdc.SelectObject(bm);
1370 mdc.SetBackground(wxBrush(GetBackgroundColour()));
1374 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1375 node; node = node->GetNext()) {
1376 wxToolBarToolBase *tool = node->GetData();
1378 wxRect toolRect = tools->trect;
1379 CreateToolBitmap(tool);
1381 if (tools->m_activeBitmap.IsOk()) {
1382 mdc.DrawBitmap(tools->m_activeBitmap, tools->m_x, tools->m_y,
false);
1387 mdc.SelectObject(wxNullBitmap);
1393void ocpnToolBarSimple::OnToolTipTimerEvent(wxTimerEvent &event) {
1398 if (m_btooltip_show && m_pToolTipWin &&
1399 (!m_pToolTipWin->IsShown())) {
1400 if (m_last_ro_tool) {
1401 wxString s = m_last_ro_tool->GetShortHelp();
1404 m_pToolTipWin->SetString(s);
1405 m_pToolTipWin->SetHiviz(m_last_ro_tool->m_btooltip_hiviz);
1407 wxPoint pos_in_toolbar(m_last_ro_tool->m_x, m_last_ro_tool->m_y);
1408 pos_in_toolbar.x += m_last_ro_tool->m_width + 2;
1410 m_pToolTipWin->Move(
1413 wxPoint screenPosition =
1414 gFrame->GetPrimaryCanvas()->ClientToScreen(pos_in_toolbar);
1415 wxSize tipSize = m_pToolTipWin->GetRenderedSize();
1417 m_pToolTipWin->SetPosition(screenPosition);
1418 m_pToolTipWin->SetBitmap();
1419 m_pToolTipWin->Show();
1424#ifndef __OCPN__ANDROID__
1425 if (g_btouch) m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1432void ocpnToolBarSimple::OnToolTipOffTimerEvent(wxTimerEvent &event) {
1436bool ocpnToolBarSimple::OnMouseEvent(wxMouseEvent &event, wxPoint &position) {
1438 event.GetPosition(&x, &y);
1441 wxRect r = wxRect(position, wxSize(m_maxWidth, m_maxHeight));
1442 if (!r.Contains(x, y)) {
1447 m_parentContainer->RefreshFadeTimer();
1450 (
ocpnToolBarTool *)FindToolForPosition(x - position.x, y - position.y);
1452 m_tooltipoff_timer.Start(m_tooltip_off, wxTIMER_ONE_SHOT);
1455 m_tooltipoff_timer.Stop();
1458 if (tool && tool->IsButton() ) {
1459 if (m_btooltip_show) {
1461 if (NULL == m_pToolTipWin) {
1463 m_pToolTipWin->SetColorScheme(m_currentColorScheme);
1464 m_pToolTipWin->Hide();
1467 if (tool != m_last_ro_tool) {
1468 m_pToolTipWin->Hide();
1471#ifndef __OCPN__ANDROID__
1472 if (!m_pToolTipWin->IsShown()) {
1473 if (!m_tooltip_timer.IsRunning()) {
1474 m_tooltip_timer.Start(m_one_shot, wxTIMER_ONE_SHOT);
1481 m_last_ro_tool = tool;
1484 if (event.LeftIsDown()) m_leftDown =
true;
1486 if (event.LeftDown() && tool->IsEnabled()) {
1487 if (tool->CanBeToggled()) {
1489 tool->bitmapOK =
false;
1491 m_bitmap = wxNullBitmap;
1497 ArrayOfPlugInToolbarTools tool_array =
1498 g_pi_manager->GetPluginToolbarToolArray();
1499 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
1501 if (tool->GetId() == pttc->id) {
1505 ppi->OnToolbarToolDownCallback(pttc->id);
1506 m_last_plugin_down_id = pttc->id;
1511 }
else if (event.RightDown()) {
1512 OnRightClick(tool->GetId(), x, y);
1525 if (event.LeftUp() && tool->IsEnabled() && (m_leftDown || g_btouch)) {
1527 if (!OnLeftClick(tool->GetId(), tool->IsToggled()) &&
1528 tool->CanBeToggled()) {
1532 tool->bitmapOK =
false;
1547void ocpnToolBarSimple::CreateToolBitmap(wxToolBarToolBase *toolBase) {
1550 wxBitmap bmp = wxNullBitmap;
1552 bool bNeedClear = !tool->bitmapOK;
1554 if (tool->bitmapOK) {
1555 if (tool->IsEnabled()) {
1556 bmp = tool->GetNormalBitmap();
1559 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1560 tool->rollover, tool->m_width, tool->m_height);
1561 tool->SetNormalBitmap(bmp);
1562 tool->bitmapOK =
true;
1565 bmp = tool->GetDisabledBitmap();
1567 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1568 false, tool->m_width, tool->m_height);
1569 tool->SetDisabledBitmap(bmp);
1570 tool->bitmapOK =
true;
1574 if (tool->isPluginTool) {
1575 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1582 wxString svgFile = tool->pluginNormalIconSVG;
1584 if (tool->pluginToggledIconSVG.Length())
1585 svgFile = tool->pluginToggledIconSVG;
1587 if (tool->rollover) {
1588 if (tool->pluginRolloverIconSVG.Length())
1589 svgFile = tool->pluginRolloverIconSVG;
1592 if (!svgFile.IsEmpty()) {
1594 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
1596 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1599 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1603 if (!bmp.IsOk() || bmp.IsNull()) {
1604 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1605 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1606 tool->rollover, tool->m_width,
1614 bmp = tool->pluginNormalIcon;
1615 if (fabs(m_sizefactor - 1.0) > 0.01) {
1616 if (tool->m_width && tool->m_height) {
1617 wxImage scaled_image = bmp.ConvertToImage();
1618 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1619 wxIMAGE_QUALITY_HIGH));
1624 tool->SetNormalBitmap(bmp);
1625 tool->bitmapOK =
true;
1627 bmp = tool->GetNormalBitmap();
1628 if (tool->IsEnabled()) {
1629 if (tool->IsToggled()) {
1630 if (!tool->bitmapOK) {
1631 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1632 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1633 tool->rollover, tool->m_width,
1635 tool->SetNormalBitmap(bmp);
1641 if (!tool->bitmapOK) {
1642 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1643 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1644 tool->rollover, tool->m_width,
1646 tool->SetNormalBitmap(bmp);
1651 tool->bitmapOK =
true;
1653 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1654 false, tool->m_width, tool->m_height);
1655 tool->SetDisabledBitmap(bmp);
1656 tool->bitmapOK =
true;
1660 tool->m_activeBitmap = bmp;
1666void ocpnToolBarSimple::DrawTool(wxDC &dc, wxToolBarToolBase *toolBase) {
1670 wxPoint drawAt(tool->m_x, tool->m_y);
1671 wxBitmap bmp = wxNullBitmap;
1673 bool bNeedClear = !tool->bitmapOK;
1675 if (tool->bitmapOK) {
1676 if (tool->IsEnabled()) {
1677 bmp = tool->GetNormalBitmap();
1680 m_style->GetToolIcon(tool->GetToolname(), TOOLICON_NORMAL,
1681 tool->rollover, tool->m_width, tool->m_height);
1682 tool->SetNormalBitmap(bmp);
1683 tool->bitmapOK =
true;
1686 bmp = tool->GetDisabledBitmap();
1688 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1689 false, tool->m_width, tool->m_height);
1690 tool->SetDisabledBitmap(bmp);
1691 tool->bitmapOK =
true;
1695 if (tool->isPluginTool) {
1696 int toggleFlag = tool->IsToggled() ? TOOLICON_TOGGLED : TOOLICON_NORMAL;
1703 wxString svgFile = tool->pluginNormalIconSVG;
1705 if (tool->pluginToggledIconSVG.Length())
1706 svgFile = tool->pluginToggledIconSVG;
1708 if (tool->rollover) {
1709 if (tool->pluginRolloverIconSVG.Length())
1710 svgFile = tool->pluginRolloverIconSVG;
1713 if (!svgFile.IsEmpty()) {
1715 bmp = LoadSVG(svgFile, tool->m_width, tool->m_height);
1717 bmp = m_style->BuildPluginIcon(bmp, toggleFlag, m_sizefactor);
1720 m_style->BuildPluginIcon(tool->pluginNormalIcon, TOOLICON_NORMAL);
1724 if (!bmp.IsOk() || bmp.IsNull()) {
1725 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1726 bmp = m_style->GetToolIcon(tool->GetToolname(), toggleFlag,
1727 tool->rollover, tool->m_width,
1734 if (tool->rollover) {
1736 m_style->BuildPluginIcon(tool->pluginRolloverIcon, toggleFlag);
1739 m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1742 bmp = m_style->BuildPluginIcon(tool->pluginNormalIcon, toggleFlag);
1744 if (fabs(m_sizefactor - 1.0) > 0.01) {
1745 if (tool->m_width && tool->m_height) {
1746 wxImage scaled_image = bmp.ConvertToImage();
1747 bmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1748 wxIMAGE_QUALITY_HIGH));
1753 tool->SetNormalBitmap(bmp);
1754 tool->bitmapOK =
true;
1756 bmp = tool->GetNormalBitmap();
1757 if (tool->IsEnabled()) {
1758 if (tool->IsToggled()) {
1759 if (!tool->bitmapOK) {
1760 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1761 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_TOGGLED,
1762 tool->rollover, tool->m_width,
1764 tool->SetNormalBitmap(bmp);
1770 if (!tool->bitmapOK) {
1771 if (m_style->NativeToolIconExists(tool->GetToolname())) {
1772 bmp = m_style->GetToolIcon(tool->GetIconName(), TOOLICON_NORMAL,
1773 tool->rollover, tool->m_width,
1775 tool->SetNormalBitmap(bmp);
1780 tool->bitmapOK =
true;
1782 bmp = m_style->GetToolIcon(tool->GetToolname(), TOOLICON_DISABLED,
1783 false, tool->m_width, tool->m_height);
1784 tool->SetDisabledBitmap(bmp);
1785 tool->bitmapOK =
true;
1790 if (tool->firstInLine) {
1791 m_style->DrawToolbarLineStart(bmp, m_sizefactor);
1793 if (tool->lastInLine) {
1794 m_style->DrawToolbarLineEnd(bmp, m_sizefactor);
1797 if (bmp.GetWidth() != m_style->GetToolSize().x ||
1798 bmp.GetHeight() != m_style->GetToolSize().y) {
1804 if ((tool->last_rect.width &&
1805 (tool->last_rect.x != drawAt.x || tool->last_rect.y != drawAt.y)) ||
1807 wxBrush bb(GetGlobalColor(_T(
"GREY3")));
1809 dc.SetPen(*wxTRANSPARENT_PEN);
1810 dc.DrawRectangle(tool->last_rect.x, tool->last_rect.y,
1811 tool->last_rect.width, tool->last_rect.height);
1818 wxImage scaled_image = bmp.ConvertToImage();
1819 wxBitmap sbmp = wxBitmap(scaled_image.Scale(tool->m_width, tool->m_height,
1820 wxIMAGE_QUALITY_HIGH));
1821 dc.DrawBitmap(sbmp, drawAt);
1823 wxRect(drawAt.x, drawAt.y, sbmp.GetWidth(), sbmp.GetHeight());
1826 dc.DrawBitmap(bmp, drawAt);
1828 wxRect(drawAt.x, drawAt.y, bmp.GetWidth(), bmp.GetHeight());
1836wxToolBarToolBase *ocpnToolBarSimple::FindToolForPosition(wxCoord x,
1838 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1841 if ((x >= tool->m_x) && (y >= tool->m_y) &&
1842 (x < (tool->m_x + tool->GetWidth())) &&
1843 (y < (tool->m_y + tool->GetHeight()))) {
1847 node = node->GetNext();
1850 return (wxToolBarToolBase *)NULL;
1853void ocpnToolBarSimple::InvalidateBitmaps() {
1854 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
1857 tool->bitmapOK =
false;
1858 node = node->GetNext();
1860 m_bitmap = wxNullBitmap;
1863wxRect ocpnToolBarSimple::GetToolRect(
int tool_id) {
1865 wxToolBarToolBase *tool = FindById(tool_id);
1868 if (otool) rect = otool->trect;
1878void ocpnToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
1879 bool WXUNUSED(enable)) {
1881 t->bitmapOK =
false;
1884void ocpnToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
1885 bool WXUNUSED(toggle)) {
1887 t->bitmapOK =
false;
1895wxString ocpnToolBarSimple::GetToolShortHelp(
int id)
const {
1896 wxToolBarToolBase *tool = FindById(
id);
1897 wxCHECK_MSG(tool, wxEmptyString, _T(
"no such tool"));
1899 return tool->GetShortHelp();
1902wxString ocpnToolBarSimple::GetToolLongHelp(
int id)
const {
1903 wxToolBarToolBase *tool = FindById(
id);
1904 wxCHECK_MSG(tool, wxEmptyString, _T(
"no such tool"));
1906 return tool->GetLongHelp();
1909void ocpnToolBarSimple::SetToolShortHelp(
int id,
const wxString &help) {
1910 wxToolBarToolBase *tool = FindById(
id);
1912 (void)tool->SetShortHelp(help);
1916void ocpnToolBarSimple::SetToolLongHelp(
int id,
const wxString &help) {
1917 wxToolBarToolBase *tool = FindById(
id);
1919 (void)tool->SetLongHelp(help);
1923int ocpnToolBarSimple::GetToolPos(
int id)
const {
1925 wxToolBarToolsList::compatibility_iterator node;
1927 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
1928 if (node->GetData()->GetId() == id)
return pos;
1935bool ocpnToolBarSimple::GetToolState(
int id)
const {
1936 wxToolBarToolBase *tool = FindById(
id);
1937 wxCHECK_MSG(tool,
false, _T(
"no such tool"));
1939 return tool->IsToggled();
1942bool ocpnToolBarSimple::GetToolEnabled(
int id)
const {
1943 wxToolBarToolBase *tool = FindById(
id);
1944 wxCHECK_MSG(tool,
false, _T(
"no such tool"));
1946 return tool->IsEnabled();
1949void ocpnToolBarSimple::ToggleTool(
int id,
bool toggle) {
1950 wxToolBarToolBase *tool = FindById(
id);
1952 if (tool && tool->CanBeToggled() && tool->Toggle(toggle)) {
1953 DoToggleTool(tool, toggle);
1954 InvalidateBitmaps();
1955 gFrame->GetPrimaryCanvas()->Refresh(
true);
1959wxObject *ocpnToolBarSimple::GetToolClientData(
int id)
const {
1960 wxToolBarToolBase *tool = FindById(
id);
1961 return tool ? tool->GetClientData() : (wxObject *)NULL;
1964void ocpnToolBarSimple::SetToolClientData(
int id, wxObject *clientData) {
1965 wxToolBarToolBase *tool = FindById(
id);
1967 wxCHECK_RET(tool, _T(
"no such tool in wxToolBar::SetToolClientData"));
1969 tool->SetClientData(clientData);
1972void ocpnToolBarSimple::EnableTool(
int id,
bool enable) {
1973 wxToolBarToolBase *tool = FindById(
id);
1975 if (tool->Enable(enable)) {
1976 DoEnableTool(tool, enable);
1981 if (parent && parent->m_FloatingToolbarConfigMenu) {
1982 wxMenuItem *configItem = parent->m_FloatingToolbarConfigMenu->FindItem(
id);
1983 if (configItem) configItem->Check(
true);
1987void ocpnToolBarSimple::SetToolTooltipHiViz(
int id,
bool b_hiviz) {
1990 tool->SetTooltipHiviz(b_hiviz);
1994void ocpnToolBarSimple::ClearTools() {
1995 while (GetToolsCount()) {
2000int ocpnToolBarSimple::GetVisibleToolCount() {
2002 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2006 node = node->GetNext();
2011bool ocpnToolBarSimple::DeleteToolByPos(
size_t pos) {
2012 wxCHECK_MSG(pos < GetToolsCount(),
false,
2013 _T(
"invalid position in wxToolBar::DeleteToolByPos()"));
2015 wxToolBarToolsList::compatibility_iterator node = m_tools.Item(pos);
2017 if (!DoDeleteTool(pos, node->GetData())) {
2021 delete node->GetData();
2022 m_tools.Erase(node);
2027bool ocpnToolBarSimple::DeleteTool(
int id) {
2029 wxToolBarToolsList::compatibility_iterator node;
2030 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2031 if (node->GetData()->GetId() == id)
break;
2036 if (!node || !DoDeleteTool(pos, node->GetData())) {
2040 delete node->GetData();
2041 m_tools.Erase(node);
2046wxToolBarToolBase *ocpnToolBarSimple::AddSeparator() {
2047 return InsertSeparator(GetToolsCount());
2050wxToolBarToolBase *ocpnToolBarSimple::InsertSeparator(
size_t pos) {
2051 wxCHECK_MSG(pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
2052 _T(
"invalid position in wxToolBar::InsertSeparator()"));
2054 wxToolBarToolBase *tool = CreateTool(
2055 wxID_SEPARATOR, wxEmptyString, wxNullBitmap, wxNullBitmap,
2056 wxITEM_SEPARATOR, (wxObject *)NULL, wxEmptyString, wxEmptyString);
2058 if (!tool || !DoInsertTool(pos, tool)) {
2064 m_tools.Insert(pos, tool);
2070wxToolBarToolBase *ocpnToolBarSimple::RemoveTool(
int id) {
2072 wxToolBarToolsList::compatibility_iterator node;
2073 for (node = m_tools.GetFirst(); node; node = node->GetNext()) {
2074 if (node->GetData()->GetId() == id)
break;
2082 return (wxToolBarToolBase *)NULL;
2085 wxToolBarToolBase *tool = node->GetData();
2086 if (!DoDeleteTool(pos, tool)) {
2087 return (wxToolBarToolBase *)NULL;
2090 m_tools.Erase(node);
2095wxControl *ocpnToolBarSimple::FindControl(
int id) {
2096 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2097 node; node = node->GetNext()) {
2098 const wxToolBarToolBase *
const tool = node->GetData();
2099 if (tool->IsControl()) {
2100 wxControl *
const control = tool->GetControl();
2103 wxFAIL_MSG(_T(
"NULL control in toolbar?"));
2104 }
else if (control->GetId() ==
id) {
2114wxToolBarToolBase *ocpnToolBarSimple::FindById(
int id)
const {
2115 wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL;
2117 for (wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
2118 node; node = node->GetNext()) {
2119 tool = node->GetData();
2120 if (tool->GetId() == id) {
2137bool ocpnToolBarSimple::OnLeftClick(
int id,
bool toggleDown) {
2138 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED,
id);
2142 event.SetInt((
int)toggleDown);
2145 event.SetExtraLong((
long)toggleDown);
2147 gFrame->GetEventHandler()->AddPendingEvent(event);
2153void ocpnToolBarSimple::OnRightClick(
int id,
long WXUNUSED(x),
2157 if (m_parentContainer) {
2158 if (m_parentContainer->m_FloatingToolbarConfigMenu) {
2161 wxDefaultPosition, wxSize(100, 100));
2162 int rc = dlg->ShowModal();
2165 if (rc == wxID_OK) {
2166 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED,
id);
2167 event.SetEventObject(
this);
2170 gFrame->GetEventHandler()->AddPendingEvent(event);
2176void ocpnToolBarSimple::DoPluginToolUp() {
2179 if (!g_pi_manager)
return;
2181 ArrayOfPlugInToolbarTools tool_array =
2182 g_pi_manager->GetPluginToolbarToolArray();
2183 for (
unsigned int i = 0; i < tool_array.GetCount(); i++) {
2185 if (m_last_plugin_down_id == pttc->id) {
2188 if (ppi) ppi->OnToolbarToolUpCallback(pttc->id);
2192 m_last_plugin_down_id = -1;
2195void ocpnToolBarSimple::SetToolNormalBitmapEx(wxToolBarToolBase *tool,
2196 const wxString &iconName) {
2202 wxBitmap bmp = style->GetToolIcon(iconName, TOOLICON_NORMAL,
false,
2203 otool->m_width, otool->m_height);
2204 tool->SetNormalBitmap(bmp);
2205 otool->SetIconName(iconName);
2210void ocpnToolBarSimple::SetToolNormalBitmapSVG(wxToolBarToolBase *tool,
2215 otool->pluginNormalIconSVG = fileSVG;
2220void ocpnToolBarSimple::SetToolBitmaps(
int id, wxBitmap *bmp,
2221 wxBitmap *bmpRollover) {
2224 if (tool->isPluginTool) {
2225 if (bmp->GetWidth() != tool->GetWidth()) {
2227 wxImage ibmp = bmp->ConvertToImage();
2228 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2229 wxIMAGE_QUALITY_HIGH);
2230 wxBitmap sbmp = wxBitmap(ibmp);
2231 tool->pluginNormalIcon = sbmp;
2234 tool->pluginNormalIcon = *bmp;
2237 if (bmpRollover->GetWidth() != tool->GetWidth()) {
2238 if (bmpRollover->IsOk()) {
2239 wxImage ibmp = bmpRollover->ConvertToImage();
2240 ibmp.Rescale(tool->GetWidth(), tool->GetHeight(),
2241 wxIMAGE_QUALITY_HIGH);
2242 wxBitmap sbmp = wxBitmap(ibmp);
2243 tool->pluginRolloverIcon = sbmp;
2246 tool->pluginRolloverIcon = *bmpRollover;
2248 tool->bitmapOK =
false;
2251 tool->SetNormalBitmap(*bmp);
2252 tool->bitmapOK =
true;
2254 InvalidateBitmaps();
2258void ocpnToolBarSimple::SetToolBitmapsSVG(
int id, wxString fileSVGNormal,
2259 wxString fileSVGRollover,
2260 wxString fileSVGToggled) {
2263 tool->pluginNormalIconSVG = fileSVGNormal;
2264 tool->pluginRolloverIconSVG = fileSVGRollover;
2265 tool->pluginToggledIconSVG = fileSVGToggled;
2266 tool->bitmapOK =
false;
2267 InvalidateBitmaps();
2273ToolbarMOBDialog::ToolbarMOBDialog(wxWindow *parent)
2274 : wxDialog(parent, wxID_ANY, _(
"OpenCPN Alert"), wxDefaultPosition,
2276 wxBoxSizer *topSizer =
new wxBoxSizer(wxVERTICAL);
2278 wxBoxSizer *sizer =
new wxBoxSizer(wxVERTICAL);
2279 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
2282 new wxRadioButton(
this, 0, _(
"No, I don't want to hide it."),
2283 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
2285 choices.push_back(
new wxRadioButton(
2286 this, 1, _(
"No, and permanently remove the option to hide it."),
2287 wxDefaultPosition));
2290 new wxRadioButton(
this, 2, _(
"Yes, hide it."), wxDefaultPosition));
2292 wxStdDialogButtonSizer *buttonSizer =
2293 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
2295 wxStaticText *textCtrl =
2296 new wxStaticText(
this, wxID_ANY,
2297 _(
"The Man Over Board button could be an important "
2298 "safety feature.\nAre you sure you want to hide it?"));
2300 sizer->Add(textCtrl, 0, wxEXPAND | wxALL, 5);
2301 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
2302 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
2303 sizer->Add(choices[2], 0, wxEXPAND | wxALL, 5);
2304 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
2306 topSizer->SetSizeHints(
this);
2310int ToolbarMOBDialog::GetSelection() {
2311 for (
unsigned int i = 0; i < choices.size(); i++) {
2312 if (choices[i]->GetValue())
return choices[i]->GetId();
2332 const wxString &caption,
2334 const wxSize &size,
long style) {
2335 long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
2336 wxDialog::Create(parent,
id, caption, pos, size, wstyle);
2338 m_configMenu = NULL;
2339 m_ToolbarDialogAncestor = sponsor;
2341 if (m_ToolbarDialogAncestor)
2342 m_configMenu = m_ToolbarDialogAncestor->m_FloatingToolbarConfigMenu;
2345 GetSizer()->Fit(
this);
2350ToolbarChoicesDialog::~ToolbarChoicesDialog() {}
2357 wxBoxSizer *itemBoxSizer1 =
new wxBoxSizer(wxVERTICAL);
2358 SetSizer(itemBoxSizer1);
2360 wxScrolledWindow *itemDialog1 =
new wxScrolledWindow(
2361 this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxHSCROLL | wxVSCROLL);
2362 itemDialog1->SetScrollRate(2, 2);
2364#ifdef __OCPN__ANDROID__
2369 wxString wqs = getFontQtStylesheet(qFont);
2370 wxCharBuffer sbuf = wqs.ToUTF8();
2371 QString qsb = QString(sbuf.data());
2373 QString qsbq = getQtStyleSheet();
2375 this->GetHandle()->setStyleSheet(qsb + qsbq);
2378 itemBoxSizer1->Add(itemDialog1, 2, wxEXPAND | wxALL, 0);
2380 wxBoxSizer *itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
2381 itemDialog1->SetSizer(itemBoxSizer2);
2383 wxStaticBox *itemStaticBoxSizer3Static =
2384 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Choose Toolbar Icons"));
2385 wxStaticBoxSizer *itemStaticBoxSizer3 =
2386 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
2387 itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxEXPAND | wxALL, 5);
2392 nitems = m_configMenu->GetMenuItemCount();
2395 for (
int i = 0; i < nitems; i++) {
2396 if (i + ID_ZOOMIN == ID_MOB && g_bPermanentMOBIcon)
continue;
2397 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2399 wxString label = item->GetItemLabel();
2400 int l = label.Len();
2401 max_width = wxMax(max_width, l);
2403 wxString windowName = _T(
"");
2404 if (item->GetId() == ID_MOB + 100) windowName = _T(
"MOBCheck");
2407 new wxCheckBox(itemDialog1, -1, label, wxDefaultPosition,
2408 wxDefaultSize, 0, wxDefaultValidator, windowName);
2410 itemStaticBoxSizer3->Add(cb, 0, wxALL | wxEXPAND, 2);
2411 cb->SetValue(item->IsChecked());
2413 cboxes.push_back(cb);
2417 itemBoxSizer1->SetMinSize((max_width + 20) * GetCharWidth(),
2418 (nitems + 4) * GetCharHeight() * 2);
2420 wxBoxSizer *itemBoxSizerBottom =
new wxBoxSizer(wxHORIZONTAL);
2421 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALL | wxEXPAND, 5);
2423 wxBoxSizer *itemBoxSizerAux =
new wxBoxSizer(wxHORIZONTAL);
2424 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALL, 3);
2426 wxBoxSizer *itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
2427 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALL, 3);
2430 new wxButton(
this, -1, _(
"Cancel"), wxDefaultPosition, wxDefaultSize, 0);
2431 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2434 new wxButton(
this, -1, _(
"OK"), wxDefaultPosition, wxDefaultSize, 0);
2435 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
2436 m_OKButton->SetDefault();
2438 m_CancelButton->Connect(
2439 wxEVT_COMMAND_BUTTON_CLICKED,
2440 wxCommandEventHandler(ToolbarChoicesDialog::OnCancelClick), NULL,
this);
2441 m_OKButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
2442 wxCommandEventHandler(ToolbarChoicesDialog::OnOkClick),
2445 SetColorScheme((ColorScheme)0);
2448void ToolbarChoicesDialog::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
2450void ToolbarChoicesDialog::OnCancelClick(wxCommandEvent &event) {
2451 EndModal(wxID_CANCEL);
2454void ToolbarChoicesDialog::OnOkClick(wxCommandEvent &event) {
2455 unsigned int ncheck = 0;
2457 wxString toolbarConfigSave = m_ToolbarDialogAncestor->GetToolConfigString();
2458 wxString new_toolbarConfig = toolbarConfigSave;
2460 for (
unsigned int i = 0; i < cboxes.size(); i++) {
2461 wxCheckBox *cb = cboxes[i];
2462 wxString cbName = cb->GetName();
2464 if (cbName.IsSameAs(_T(
"MOBCheck")) && !cb->IsChecked()) {
2467 int dialog_ret = mdlg.ShowModal();
2468 int answer = mdlg.GetSelection();
2469 if (dialog_ret == wxID_OK) {
2471 g_bPermanentMOBIcon =
true;
2473 }
else if (answer == 0) {
2477 new_toolbarConfig = toolbarConfigSave;
2482 wxMenuItem *item = m_configMenu->FindItemByPosition(i);
2483 if (new_toolbarConfig.Len() > i) {
2484 new_toolbarConfig.SetChar(i, cb->IsChecked() ? _T(
'X') : _T(
'.'));
2486 new_toolbarConfig.Append(cb->IsChecked() ? _T(
'X') : _T(
'.'));
2488 item->Check(cb->IsChecked());
2489 if (cb->IsChecked()) ncheck++;
2496 new_toolbarConfig.SetChar( ID_SETTINGS -ID_ZOOMIN , _T(
'X') );
2498 int idOffset = ID_PLUGIN_BASE - ID_ZOOMIN + 100;
2501 wxMenuItem *item = m_configMenu->FindItem(ID_SETTINGS + idOffset);
2503 item->Check(
true );
2507 m_ToolbarDialogAncestor->SetToolConfigString(new_toolbarConfig);
2512void ToolbarChoicesDialog::RecalculateSize(
void) {
2513 wxSize esize = GetSize();
2516 wxSize dsize = GetParent()->GetClientSize();
2517 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
2518 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
2524 fsize.y = wxMin(esize.y, fsize.y - (4 * GetCharHeight()));
2525 fsize.x = wxMin(esize.x, fsize.x - (2 * GetCharHeight()));
2528#ifdef __OCPN__ANDROID__
2529 Move(GetPosition().x, 10);
Global state for AIS decoder.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
Device context class that can use either wxDC or OpenGL for drawing.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.