OpenCPN Partial API docs
Loading...
Searching...
No Matches
MarkInfo.cpp
1/**************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: MarkProperties Support
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25#include "config.h"
26
27// For compilers that support precompilation, includes "wx/wx.h".
28#include <wx/wxprec.h>
29
30#ifndef WX_PRECOMP
31#include <wx/wx.h>
32#endif
33
34#include <wx/datetime.h>
35#include <wx/clipbrd.h>
36#include <wx/print.h>
37#include <wx/printdlg.h>
38#include <wx/stattext.h>
39#include <wx/clrpicker.h>
40#include <wx/bmpbuttn.h>
41
42#include "chcanv.h"
43#include "gui_lib.h"
44#include "MarkInfo.h"
45#include "model/georef.h"
46#include "model/navutil_base.h"
47#include "model/own_ship.h"
48#include "model/position_parser.h"
49#include "model/route.h"
50#include "model/routeman.h"
51#include "model/select.h"
52#include "navutil.h" // for Route
53#include "ocpn_frame.h"
54#include "OCPNPlatform.h"
55#include "pluginmanager.h"
56#include "routemanagerdialog.h"
57#include "routeprintout.h"
58#include "RoutePropDlgImpl.h"
59#include "styles.h"
60#include "svg_utils.h"
61#include "TCWin.h"
62#include "ui_utils.h"
63
64#ifdef __ANDROID__
65#include "androidUTIL.h"
66#include <QtWidgets/QScroller>
67#endif
68
69extern TCMgr* ptcmgr;
70extern MyConfig* pConfig;
71extern Routeman* g_pRouteMan;
72extern RouteManagerDialog* pRouteManagerDialog;
73extern RoutePropDlgImpl* pRoutePropDialog;
74extern ocpnStyle::StyleManager* g_StyleManager;
75
76extern MyFrame* gFrame;
77extern OCPNPlatform* g_Platform;
78extern wxString g_default_wp_icon;
79
80// Global print data, to remember settings during the session
81
82// Global page setup data
83
84extern float g_MarkScaleFactorExp;
85
86extern MarkInfoDlg* g_pMarkInfoDialog;
87
88WX_DECLARE_LIST(wxBitmap, BitmapList);
89#include <wx/listimpl.cpp>
90WX_DEFINE_LIST(BitmapList);
91
92#include <wx/arrimpl.cpp>
93WX_DEFINE_OBJARRAY(ArrayOfBitmaps);
94
95#define EXTENDED_PROP_PAGE 2 // Index of the extended properties page
96
97OCPNIconCombo::OCPNIconCombo(wxWindow* parent, wxWindowID id,
98 const wxString& value, const wxPoint& pos,
99 const wxSize& size, int n,
100 const wxString choices[], long style,
101 const wxValidator& validator, const wxString& name)
102 : wxOwnerDrawnComboBox(parent, id, value, pos, size, n, choices, style,
103 validator, name) {
104 double fontHeight =
105 GetFont().GetPointSize() / g_Platform->getFontPointsperPixel();
106 itemHeight = (int)wxRound(fontHeight);
107}
108
109OCPNIconCombo::~OCPNIconCombo() {}
110
111void OCPNIconCombo::OnDrawItem(wxDC& dc, const wxRect& rect, int item,
112 int flags) const {
113 int offset_x = bmpArray[item].GetWidth();
114 int bmpHeight = bmpArray[item].GetHeight();
115 dc.DrawBitmap(bmpArray[item], rect.x, rect.y + (rect.height - bmpHeight) / 2,
116 true);
117
118 if (flags & wxODCB_PAINTING_CONTROL) {
119 wxString text = GetValue();
120 int margin_x = 2;
121
122#if wxCHECK_VERSION(2, 9, 0)
123 if (ShouldUseHintText()) {
124 text = GetHint();
125 wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
126 dc.SetTextForeground(col);
127 }
128
129 margin_x = GetMargins().x;
130#endif
131
132 dc.DrawText(text, rect.x + margin_x + offset_x,
133 (rect.height - dc.GetCharHeight()) / 2 + rect.y);
134 } else {
135 dc.DrawText(GetVListBoxComboPopup()->GetString(item), rect.x + 2 + offset_x,
136 (rect.height - dc.GetCharHeight()) / 2 + rect.y);
137 }
138}
139
140wxCoord OCPNIconCombo::OnMeasureItem(size_t item) const {
141 int bmpHeight = bmpArray[item].GetHeight();
142
143 return wxMax(itemHeight, bmpHeight);
144}
145
146wxCoord OCPNIconCombo::OnMeasureItemWidth(size_t item) const { return -1; }
147
148int OCPNIconCombo::Append(const wxString& item, wxBitmap bmp) {
149 bmpArray.Add(bmp);
150 int idx = wxOwnerDrawnComboBox::Append(item);
151
152 return idx;
153}
154
155void OCPNIconCombo::Clear(void) {
156 wxOwnerDrawnComboBox::Clear();
157 bmpArray.Clear();
158}
159
160//-------------------------------------------------------------------------------
161//
162// Mark Properties Dialog Implementation
163//
164//-------------------------------------------------------------------------------
169// DEFINE_EVENT_TYPE(EVT_LLCHANGE) // events from LatLonTextCtrl
170const wxEventType EVT_LLCHANGE = wxNewEventType();
171//------------------------------------------------------------------------------
172// LatLonTextCtrl Window Implementation
173//------------------------------------------------------------------------------
174BEGIN_EVENT_TABLE(LatLonTextCtrl, wxWindow)
175END_EVENT_TABLE()
176
177// constructor
178LatLonTextCtrl::LatLonTextCtrl(wxWindow* parent, wxWindowID id,
179 const wxString& value, const wxPoint& pos,
180 const wxSize& size, long style,
181 const wxValidator& validator,
182 const wxString& name)
183 : wxTextCtrl(parent, id, value, pos, size, style, validator, name) {
184 m_pParentEventHandler = parent->GetEventHandler();
185}
186
187void LatLonTextCtrl::OnKillFocus(wxFocusEvent& event) {
188 // Send an event to the Parent Dialog
189 wxCommandEvent up_event(EVT_LLCHANGE, GetId());
190 up_event.SetEventObject((wxObject*)this);
191 m_pParentEventHandler->AddPendingEvent(up_event);
192}
193
194//-------------------------------------------------------------------------------
195//
196// Mark Information Dialog Implementation
197//
198//-------------------------------------------------------------------------------
199BEGIN_EVENT_TABLE(MarkInfoDlg, DIALOG_PARENT)
200EVT_BUTTON(wxID_OK, MarkInfoDlg::OnMarkInfoOKClick)
201EVT_BUTTON(wxID_CANCEL, MarkInfoDlg::OnMarkInfoCancelClick)
202EVT_BUTTON(ID_BTN_DESC_BASIC, MarkInfoDlg::OnExtDescriptionClick)
203EVT_BUTTON(ID_DEFAULT, MarkInfoDlg::DefautlBtnClicked)
204EVT_BUTTON(ID_BTN_SHOW_TIDES, MarkInfoDlg::ShowTidesBtnClicked)
205EVT_COMBOBOX(ID_BITMAPCOMBOCTRL, MarkInfoDlg::OnBitmapCombClick)
206EVT_CHECKBOX(ID_CHECKBOX_SCAMIN_VIS, MarkInfoDlg::OnSelectScaMinExt)
207EVT_TEXT(ID_DESCR_CTR_DESC, MarkInfoDlg::OnDescChangedExt)
208EVT_TEXT(ID_DESCR_CTR_BASIC, MarkInfoDlg::OnDescChangedBasic)
209EVT_TEXT(ID_LATCTRL, MarkInfoDlg::OnPositionCtlUpdated)
210EVT_TEXT(ID_LONCTRL, MarkInfoDlg::OnPositionCtlUpdated)
211EVT_CHOICE(ID_WPT_RANGERINGS_NO, MarkInfoDlg::OnWptRangeRingsNoChange)
212// the HTML listbox's events
213EVT_HTML_LINK_CLICKED(wxID_ANY, MarkInfoDlg::OnHtmlLinkClicked)
214EVT_COMMAND(wxID_ANY, EVT_LAYOUT_RESIZE, MarkInfoDlg::OnLayoutResize)
215EVT_CLOSE(MarkInfoDlg::OnClose)
216
217// EVT_CHOICE( ID_WAYPOINTRANGERINGS, MarkInfoDef::OnWaypointRangeRingSelect )
218END_EVENT_TABLE()
219
220MarkInfoDlg::MarkInfoDlg(wxWindow* parent, wxWindowID id, const wxString& title,
221 const wxPoint& pos, const wxSize& size, long style) {
222 DIALOG_PARENT::Create(parent, id, title, pos, size, style);
223
224 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
225 SetFont(*qFont);
226 int metric = GetCharHeight();
227
228#ifdef __ANDROID__
229 // Set Dialog Font by custom crafted Qt Stylesheet.
230 wxString wqs = getFontQtStylesheet(qFont);
231 wxCharBuffer sbuf = wqs.ToUTF8();
232 QString qsb = QString(sbuf.data());
233 QString qsbq = getQtStyleSheet(); // basic scrollbars, etc
234 this->GetHandle()->setStyleSheet(qsb + qsbq); // Concatenated style sheets
235 wxScreenDC sdc;
236 if (sdc.IsOk()) sdc.GetTextExtent(_T("W"), NULL, &metric, NULL, NULL, qFont);
237#endif
238 Create();
239 m_pMyLinkList = NULL;
240 SetColorScheme((ColorScheme)0);
241 m_pRoutePoint = NULL;
242 m_SaveDefaultDlg = NULL;
243 CenterOnScreen();
244
245#ifdef __WXOSX__
246 Connect(wxEVT_ACTIVATE, wxActivateEventHandler(MarkInfoDlg::OnActivate), NULL,
247 this);
248#endif
249}
250
251void MarkInfoDlg::OnActivate(wxActivateEvent& event) {
252 auto pWin = dynamic_cast<DIALOG_PARENT*>(event.GetEventObject());
253 long int style = pWin->GetWindowStyle();
254 if (event.GetActive())
255 pWin->SetWindowStyle(style | wxSTAY_ON_TOP);
256 else
257 pWin->SetWindowStyle(style ^ wxSTAY_ON_TOP);
258}
259
260void MarkInfoDlg::initialize_images(void) {
261 wxString iconDir = g_Platform->GetSharedDataDir() + _T("uidata/MUI_flat/");
262 _img_MUI_settings_svg = LoadSVG(iconDir + _T("MUI_settings.svg"),
263 2 * GetCharHeight(), 2 * GetCharHeight());
264
265 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
266 wxBitmap tide = style->GetIcon(_T("tidesml"));
267 wxImage tide1 = tide.ConvertToImage();
268 wxImage tide1s = tide1.Scale(m_sizeMetric * 3 / 2, m_sizeMetric * 3 / 2,
269 wxIMAGE_QUALITY_HIGH);
270 m_bmTide = wxBitmap(tide1s);
271
272 return;
273}
274
275void MarkInfoDlg::Create() {
276 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
277 SetFont(*qFont);
278 m_sizeMetric = GetCharHeight();
279
280#ifdef __ANDROID__
281 // Set Dialog Font by custom crafted Qt Stylesheet.
282
283 wxString wqs = getFontQtStylesheet(qFont);
284 wxCharBuffer sbuf = wqs.ToUTF8();
285 QString qsb = QString(sbuf.data());
286
287 QString qsbq = getAdjustedDialogStyleSheet(); // basic scrollbars, etc
288
289 this->GetHandle()->setStyleSheet(qsb + qsbq); // Concatenated style sheets
290
291 wxScreenDC sdc;
292 if (sdc.IsOk())
293 sdc.GetTextExtent(_T("W"), NULL, &m_sizeMetric, NULL, NULL, qFont);
294
295#endif
296
297 initialize_images();
298
299 wxBoxSizer* bSizer1;
300 bSizer1 = new wxBoxSizer(wxVERTICAL);
301 SetSizer(bSizer1);
302 bSizer1->SetSizeHints(this); // set size hints to honour minimum size
303
304 // Notebook with fixed width tabs
305 m_notebookProperties = new wxNotebook(this, wxID_ANY, wxDefaultPosition,
306 wxDefaultSize, wxNB_FIXEDWIDTH);
307
308 m_panelBasicProperties = new wxScrolledWindow(
309 m_notebookProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize,
310 wxHSCROLL | wxVSCROLL | wxTAB_TRAVERSAL);
311#ifdef __ANDROID__
312 m_panelBasicProperties->GetHandle()->setStyleSheet(
313 getAdjustedDialogStyleSheet());
314#endif
315
316 // Basic panel
317 m_panelBasicProperties->SetScrollRate(0, 2);
318 m_notebookProperties->AddPage(m_panelBasicProperties, _("Basic"), true);
319 bSizerBasicProperties = new wxBoxSizer(wxVERTICAL);
320 m_panelBasicProperties->SetSizer(bSizerBasicProperties);
321
322 // Layer notification
323 m_staticTextLayer = new wxStaticText(
324 m_panelBasicProperties, wxID_ANY,
325 _("This waypoint is part of a layer and can't be edited"),
326 wxDefaultPosition, wxDefaultSize, 0);
327 m_staticTextLayer->Enable(false);
328 bSizerBasicProperties->Add(m_staticTextLayer, 0, wxALL, 5);
329
330 // Basic properties grid layout
331 wxPanel* props_panel = new wxPanel(m_panelBasicProperties);
332 FormGrid* props_sizer = new FormGrid(this);
333 props_panel->SetSizer(props_sizer);
334 bSizerBasicProperties->Add(props_panel, 0, wxALL | wxEXPAND, 16);
335 int label_size = m_sizeMetric * 4;
336
337 // Name property
338 m_textName = new TextField(props_panel, _("Name"));
339
340 // Show name checkbox
341 wxStaticText* name_cb_label =
342 new wxStaticText(props_panel, wxID_ANY, _("Show waypoint name"));
343 m_checkBoxShowName =
344 new wxCheckBox(props_panel, wxID_ANY, wxEmptyString, wxDefaultPosition,
345 wxDefaultSize, wxALIGN_CENTER_VERTICAL);
346 m_checkBoxShowName->Bind(wxEVT_CHECKBOX,
347 &MarkInfoDlg::OnShowWaypointNameSelectBasic, this);
348 props_sizer->Add(name_cb_label, 0, wxALIGN_TOP);
349 props_sizer->Add(m_checkBoxShowName, 0, wxEXPAND);
350
351 // Icon property (with icon scaling)
352 int icon_size = m_sizeMetric * 2;
353 icon_size = wxMax(icon_size, (32 * g_MarkScaleFactorExp) + 4);
354 m_bcomboBoxIcon =
355 new OCPNIconCombo(props_panel, wxID_ANY, _("Combo!"), wxDefaultPosition,
356 wxDefaultSize, 0, NULL, wxCB_READONLY);
357 m_bcomboBoxIcon->SetPopupMaxHeight(::wxGetDisplaySize().y / 2);
358 m_bcomboBoxIcon->SetMinSize(wxSize(-1, icon_size));
359
360 wxStaticText* icon_label = new wxStaticText(props_panel, wxID_ANY, _("Icon"));
361 icon_label->SetMinSize(wxSize(label_size, -1));
362 props_sizer->Add(icon_label, 0, wxALIGN_CENTER_VERTICAL);
363 props_sizer->Add(m_bcomboBoxIcon, 0, wxEXPAND);
364
365 // Lat/lon properties
366 m_textLatitude = new TextField(props_panel, _("Latitude"));
367 m_textLongitude = new TextField(props_panel, _("Longitude"));
368 props_sizer->Fit(props_panel);
369
370 // Description box
371 wxStaticBox* desc_box =
372 new wxStaticBox(m_panelBasicProperties, wxID_ANY, _("Description"));
373 wxStaticBoxSizer* desc_sizer = new wxStaticBoxSizer(desc_box, wxHORIZONTAL);
374 bSizerBasicProperties->Add(desc_sizer, 1, wxALL | wxEXPAND, 8);
375 m_textDescription = new wxTextCtrl(
376 m_panelBasicProperties, ID_DESCR_CTR_BASIC, wxEmptyString,
377 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
378 m_textDescription->SetMinSize(wxSize(-1, 80));
379 desc_sizer->Add(m_textDescription, 1, wxEXPAND);
380
381 // Description expand button
382 m_buttonExtDescription =
383 new wxButton(m_panelBasicProperties, ID_BTN_DESC_BASIC, _T("..."),
384 wxDefaultPosition, wxSize(GetCharHeight() * 15 / 10, -1), 0);
385 desc_sizer->Add(m_buttonExtDescription, 0, wxEXPAND);
386
387 // Links box
388 wxStaticBox* links_box =
389 new wxStaticBox(m_panelBasicProperties, wxID_ANY, _("Links"));
390 wxStaticBoxSizer* links_sizer = new wxStaticBoxSizer(links_box, wxHORIZONTAL);
391 bSizerBasicProperties->Add(links_sizer, 1, wxALL | wxEXPAND, 8);
392
393#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
394 m_htmlList = new wxSimpleHtmlListBox(m_panelBasicProperties, wxID_ANY,
395 wxDefaultPosition, wxDefaultSize, 0);
396 links_sizer->Add(m_htmlList, 1, wxEXPAND);
397#else
398
399 m_scrolledWindowLinks =
400 new wxScrolledWindow(m_panelBasicProperties, wxID_ANY, wxDefaultPosition,
401 wxSize(-1, 100), wxHSCROLL | wxVSCROLL);
402 m_scrolledWindowLinks->SetMinSize(wxSize(-1, 80));
403 m_scrolledWindowLinks->SetScrollRate(2, 2);
404 links_sizer->Add(m_scrolledWindowLinks, 1, wxEXPAND);
405
406 bSizerLinks = new wxBoxSizer(wxVERTICAL);
407 m_scrolledWindowLinks->SetSizer(bSizerLinks);
408
409 m_menuLink = new wxMenu();
410 wxMenuItem* m_menuItemDelete;
411 m_menuItemDelete = new wxMenuItem(m_menuLink, wxID_ANY, wxString(_("Delete")),
412 wxEmptyString, wxITEM_NORMAL);
413 m_menuLink->Append(m_menuItemDelete);
414
415 wxMenuItem* m_menuItemEdit;
416 m_menuItemEdit = new wxMenuItem(m_menuLink, wxID_ANY, wxString(_("Edit")),
417 wxEmptyString, wxITEM_NORMAL);
418 m_menuLink->Append(m_menuItemEdit);
419
420 wxMenuItem* m_menuItemAdd;
421 m_menuItemAdd = new wxMenuItem(m_menuLink, wxID_ANY, wxString(_("Add new")),
422 wxEmptyString, wxITEM_NORMAL);
423 m_menuLink->Append(m_menuItemAdd);
424
425 wxBoxSizer* bSizer9 = new wxBoxSizer(wxHORIZONTAL);
426
427 m_buttonAddLink =
428 new wxButton(m_panelBasicProperties, wxID_ANY, _("Add new"),
429 wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
430 bSizer9->Add(m_buttonAddLink, 0, wxALL, 5);
431
432 m_buttonAddLink->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
433 wxCommandEventHandler(MarkInfoDlg::OnAddLink), NULL,
434 this);
435
436 links_sizer->Add(bSizer9, 0, wxEXPAND, 5);
437
438#endif
439
440 m_panelDescription =
441 new wxPanel(m_notebookProperties, wxID_ANY, wxDefaultPosition,
442 wxDefaultSize, wxTAB_TRAVERSAL);
443 wxBoxSizer* bSizer15;
444 bSizer15 = new wxBoxSizer(wxVERTICAL);
445
446 m_textCtrlExtDescription =
447 new wxTextCtrl(m_panelDescription, ID_DESCR_CTR_DESC, wxEmptyString,
448 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
449 bSizer15->Add(m_textCtrlExtDescription, 1, wxALL | wxEXPAND, 5);
450
451 m_panelDescription->SetSizer(bSizer15);
452 m_notebookProperties->AddPage(m_panelDescription, _("Description"), false);
453
456
457 m_panelExtendedProperties = new wxScrolledWindow(
458 m_notebookProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize,
459 wxHSCROLL | wxVSCROLL | wxTAB_TRAVERSAL);
460#ifdef __ANDROID__
461 m_panelExtendedProperties->GetHandle()->setStyleSheet(
462 getAdjustedDialogStyleSheet());
463#endif
464
465 m_panelExtendedProperties->SetScrollRate(0, 2);
466
467 wxBoxSizer* fSizerExtProperties = new wxBoxSizer(wxVERTICAL);
468 m_panelExtendedProperties->SetSizer(fSizerExtProperties);
469 m_notebookProperties->AddPage(m_panelExtendedProperties, _("Extended"),
470 false);
471
472 sbSizerExtProperties = new wxStaticBoxSizer(
473 wxVERTICAL, m_panelExtendedProperties, _("Extended Properties"));
474 wxFlexGridSizer* gbSizerInnerExtProperties = new wxFlexGridSizer(3, 0, 0);
475 gbSizerInnerExtProperties->AddGrowableCol(2);
476 gbSizerInnerExtProperties->SetFlexibleDirection(wxBOTH);
477 gbSizerInnerExtProperties->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
478
479 m_checkBoxVisible = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
480 ID_CHECKBOX_VIS_EXT, wxEmptyString);
481 gbSizerInnerExtProperties->Add(m_checkBoxVisible);
482 wxStaticText* m_staticTextVisible = new wxStaticText(
483 sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("Show on chart"));
484 gbSizerInnerExtProperties->Add(m_staticTextVisible);
485 gbSizerInnerExtProperties->Add(0, 0, 1, wxEXPAND, 0);
486
487 m_checkBoxScaMin = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
488 ID_CHECKBOX_SCAMIN_VIS, wxEmptyString);
489 gbSizerInnerExtProperties->Add(m_checkBoxScaMin, 0, wxALIGN_CENTRE_VERTICAL,
490 0);
491 m_staticTextScaMin = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
492 wxID_ANY, _("Show at scale > 1 :"));
493 gbSizerInnerExtProperties->Add(m_staticTextScaMin, 0, wxALIGN_CENTRE_VERTICAL,
494 0);
495 m_textScaMin = new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY);
496 gbSizerInnerExtProperties->Add(m_textScaMin, 0, wxALL | wxEXPAND, 5);
497
498 m_checkBoxShowNameExt = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
499 wxID_ANY, wxEmptyString);
500 m_checkBoxShowNameExt->Bind(wxEVT_CHECKBOX,
501 &MarkInfoDlg::OnShowWaypointNameSelectExt, this);
502 gbSizerInnerExtProperties->Add(m_checkBoxShowNameExt);
503 m_staticTextShowNameExt = new wxStaticText(
504 sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("Show waypoint name"));
505
506 gbSizerInnerExtProperties->Add(m_staticTextShowNameExt);
507 gbSizerInnerExtProperties->Add(0, 0, 1, wxEXPAND, 0);
508
509 sbRangeRingsExtProperties = new wxStaticBoxSizer(
510 wxVERTICAL, sbSizerExtProperties->GetStaticBox(), _("Range rings"));
511 wxFlexGridSizer* gbRRExtProperties = new wxFlexGridSizer(4, 0, 0);
512 gbRRExtProperties->AddGrowableCol(0);
513 gbRRExtProperties->AddGrowableCol(1);
514 gbRRExtProperties->AddGrowableCol(3);
515 m_staticTextRR1 = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
516 wxID_ANY, _("Number"));
517 gbRRExtProperties->Add(m_staticTextRR1, 0, wxLEFT, 5);
518 m_staticTextRR2 = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
519 wxID_ANY, _("Distance"));
520 gbRRExtProperties->Add(m_staticTextRR2, 0, wxLEFT, 5);
521 gbRRExtProperties->Add(0, 0, 1, wxEXPAND, 5); // a spacer
522 m_staticTextRR4 = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
523 wxID_ANY, _("Color"));
524 gbRRExtProperties->Add(m_staticTextRR4, 0, wxLEFT, 5);
525
526 wxString rrAlt[] = {_("None"), _T( "1" ), _T( "2" ), _T( "3" ),
527 _T( "4" ), _T( "5" ), _T( "6" ), _T( "7" ),
528 _T( "8" ), _T( "9" ), _T( "10" )};
529 m_ChoiceWaypointRangeRingsNumber =
530 new wxChoice(sbSizerExtProperties->GetStaticBox(), ID_WPT_RANGERINGS_NO,
531 wxDefaultPosition, wxDefaultSize, 11, rrAlt);
532
533 gbRRExtProperties->Add(m_ChoiceWaypointRangeRingsNumber, 0, wxALL | wxEXPAND,
534 5);
535 m_textWaypointRangeRingsStep =
536 new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("0.05"),
537 wxDefaultPosition, wxDefaultSize, 0);
538 gbRRExtProperties->Add(m_textWaypointRangeRingsStep, 0, wxALL | wxEXPAND, 5);
539
540 wxString pDistUnitsStrings[] = {_("NMi"), _("km")};
541 m_RangeRingUnits =
542 new wxChoice(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
543 wxDefaultPosition, wxDefaultSize, 2, pDistUnitsStrings);
544 gbRRExtProperties->Add(m_RangeRingUnits, 0, wxALIGN_CENTRE_VERTICAL, 0);
545
546 m_PickColor = new wxColourPickerCtrl(sbSizerExtProperties->GetStaticBox(),
547 wxID_ANY, wxColour(0, 0, 0),
548 wxDefaultPosition, wxDefaultSize, 0);
549 gbRRExtProperties->Add(m_PickColor, 0, wxALL | wxEXPAND, 5);
550 sbRangeRingsExtProperties->Add(
551 gbRRExtProperties, 1,
552 wxLEFT | wxTOP | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
553
554 sbSizerExtProperties->GetStaticBox()->Layout();
555
556 wxFlexGridSizer* gbSizerInnerExtProperties2 = new wxFlexGridSizer(2, 0, 0);
557 gbSizerInnerExtProperties2->AddGrowableCol(1);
558
559 m_staticTextGuid =
560 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
561 _("GUID"), wxDefaultPosition, wxDefaultSize, 0);
562 gbSizerInnerExtProperties2->Add(m_staticTextGuid, 0, wxALIGN_CENTRE_VERTICAL,
563 0);
564 m_textCtrlGuid = new wxTextCtrl(sbSizerExtProperties->GetStaticBox(),
565 wxID_ANY, wxEmptyString, wxDefaultPosition,
566 wxDefaultSize, wxTE_READONLY);
567 m_textCtrlGuid->SetEditable(false);
568 gbSizerInnerExtProperties2->Add(m_textCtrlGuid, 0, wxALL | wxEXPAND, 5);
569
570 wxFlexGridSizer* gbSizerInnerExtProperties1 = new wxFlexGridSizer(3, 0, 0);
571 gbSizerInnerExtProperties1->AddGrowableCol(1);
572
573 m_staticTextTideStation =
574 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
575 _("Tide Station"), wxDefaultPosition, wxDefaultSize, 0);
576 gbSizerInnerExtProperties1->Add(m_staticTextTideStation, 0,
577 wxALIGN_CENTRE_VERTICAL, 5);
578
579#ifdef __ANDROID__
580 m_choiceTideChoices.Add(_T(" "));
581 m_comboBoxTideStation =
582 new wxChoice(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
583 wxDefaultPosition, wxDefaultSize, m_choiceTideChoices);
584
585 gbSizerInnerExtProperties1->Add(
586 m_comboBoxTideStation, 0, wxALL | wxEXPAND | wxALIGN_CENTRE_VERTICAL, 5);
587
588#else
589 m_comboBoxTideStation = new wxComboBox(
590 sbSizerExtProperties->GetStaticBox(), wxID_ANY, wxEmptyString,
591 wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY);
592 gbSizerInnerExtProperties1->Add(
593 m_comboBoxTideStation, 0, wxALL | wxEXPAND | wxALIGN_CENTRE_VERTICAL, 5);
594#endif
595
596 m_buttonShowTides = new wxBitmapButton(
597 sbSizerExtProperties->GetStaticBox(), ID_BTN_SHOW_TIDES, m_bmTide,
598 wxDefaultPosition, m_bmTide.GetSize(), 0);
599 gbSizerInnerExtProperties1->Add(m_buttonShowTides, 0,
600 wxALL | wxALIGN_CENTRE_VERTICAL, 5);
601
602 m_staticTextArrivalRadius = new wxStaticText(
603 sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("Arrival Radius"));
604 gbSizerInnerExtProperties1->Add(m_staticTextArrivalRadius, 0,
605 wxALIGN_CENTRE_VERTICAL, 0);
606 m_textArrivalRadius =
607 new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
608 wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
609 gbSizerInnerExtProperties1->Add(m_textArrivalRadius, 0, wxALL | wxEXPAND, 5);
610 m_staticTextArrivalUnits =
611 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
612 wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
613 gbSizerInnerExtProperties1->Add(m_staticTextArrivalUnits, 0,
614 wxALIGN_CENTRE_VERTICAL, 0);
615
616 m_staticTextPlSpeed =
617 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
618 _("Planned Speed"), wxDefaultPosition, wxDefaultSize, 0);
619 gbSizerInnerExtProperties1->Add(m_staticTextPlSpeed, 0,
620 wxALIGN_CENTRE_VERTICAL, 0);
621 m_textCtrlPlSpeed =
622 new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
623 wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
624 gbSizerInnerExtProperties1->Add(m_textCtrlPlSpeed, 0, wxALL | wxEXPAND, 5);
625 m_staticTextPlSpeedUnits =
626 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
627 getUsrSpeedUnit(), wxDefaultPosition, wxDefaultSize, 0);
628 gbSizerInnerExtProperties1->Add(m_staticTextPlSpeedUnits, 0,
629 wxALIGN_CENTRE_VERTICAL, 0);
630
631 m_staticTextEta = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
632 wxID_ANY, _("ETD (UTC)"));
633 gbSizerInnerExtProperties1->Add(m_staticTextEta, 0, wxALIGN_CENTRE_VERTICAL,
634 0);
635 wxBoxSizer* bsTimestamp = new wxBoxSizer(wxHORIZONTAL);
636 m_cbEtaPresent = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
637 wxID_ANY, wxEmptyString);
638 bsTimestamp->Add(m_cbEtaPresent, 0, wxALL | wxEXPAND, 5);
639 m_EtaDatePickerCtrl = new wxDatePickerCtrl(
640 sbSizerExtProperties->GetStaticBox(), ID_ETA_DATEPICKERCTRL,
641 wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT,
642 wxDefaultValidator);
643 bsTimestamp->Add(m_EtaDatePickerCtrl, 0, wxALL | wxEXPAND, 5);
644
645#ifdef __WXGTK__
646 m_EtaTimePickerCtrl =
647 new TimeCtrl(sbSizerExtProperties->GetStaticBox(), ID_ETA_TIMEPICKERCTRL,
648 wxDefaultDateTime, wxDefaultPosition, wxDefaultSize);
649#else
650 m_EtaTimePickerCtrl = new wxTimePickerCtrl(
651 sbSizerExtProperties->GetStaticBox(), ID_ETA_TIMEPICKERCTRL,
652 wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT,
653 wxDefaultValidator);
654#endif
655
656 bsTimestamp->Add(m_EtaTimePickerCtrl, 0, wxALL | wxEXPAND, 5);
657 gbSizerInnerExtProperties1->Add(bsTimestamp, 0, wxEXPAND, 0);
658 sbSizerExtProperties->Add(gbSizerInnerExtProperties, 0, wxALL | wxEXPAND, 5);
659 sbSizerExtProperties->Add(sbRangeRingsExtProperties, 0, wxALL | wxEXPAND, 5);
660 sbSizerExtProperties->Add(gbSizerInnerExtProperties2, 0, wxALL | wxEXPAND, 5);
661 sbSizerExtProperties->Add(gbSizerInnerExtProperties1, 0, wxALL | wxEXPAND, 5);
662
663 fSizerExtProperties->Add(sbSizerExtProperties, 1, wxALL | wxEXPAND);
664
665 //-----------------
666 bSizer1->Add(m_notebookProperties, 1, wxEXPAND);
667
668 wxBoxSizer* btnSizer = new wxBoxSizer(wxHORIZONTAL);
669 bSizer1->Add(btnSizer, 0, wxEXPAND, 0);
670
671 DefaultsBtn =
672 new wxBitmapButton(this, ID_DEFAULT, _img_MUI_settings_svg,
673 wxDefaultPosition, _img_MUI_settings_svg.GetSize(), 0);
674 btnSizer->Add(DefaultsBtn, 0, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
675 btnSizer->Add(0, 0, 1, wxEXPAND); // spacer
676
677 m_sdbSizerButtons = new wxStdDialogButtonSizer();
678 m_buttonOkay = new wxButton(this, wxID_OK);
679 m_sdbSizerButtons->AddButton(m_buttonOkay);
680 m_sdbSizerButtons->AddButton(new wxButton(this, wxID_CANCEL, _("Cancel")));
681 m_sdbSizerButtons->Realize();
682 btnSizer->Add(m_sdbSizerButtons, 0, wxALL, 5);
683
684 // SetMinSize(wxSize(-1, 600));
685
686 // Connect Events
687 m_textLatitude->Connect(
688 wxEVT_CONTEXT_MENU,
689 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
690 m_textLongitude->Connect(
691 wxEVT_CONTEXT_MENU,
692 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
693#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
694 m_htmlList->Connect(wxEVT_RIGHT_DOWN,
695 wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu),
696 NULL, this);
697#else
698#endif
699 m_notebookProperties->Connect(
700 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
701 wxNotebookEventHandler(MarkInfoDlg::OnNotebookPageChanged), NULL, this);
702 // m_EtaTimePickerCtrl->Connect( wxEVT_TIME_CHANGED, wxDateEventHandler(
703 // MarkInfoDlg::OnTimeChanged ), NULL, this ); m_EtaDatePickerCtrl->Connect(
704 // wxEVT_DATE_CHANGED, wxDateEventHandler( MarkInfoDlg::OnTimeChanged ), NULL,
705 // this );
706 m_comboBoxTideStation->Connect(
707 wxEVT_COMMAND_COMBOBOX_SELECTED,
708 wxCommandEventHandler(MarkInfoDlg::OnTideStationCombobox), NULL, this);
709}
710
711void MarkInfoDlg::OnClose(wxCloseEvent& event) {
712 Hide();
713 event.Veto();
714 if (m_pRoutePoint) m_pRoutePoint->m_bRPIsBeingEdited = false;
715}
716
717#define TIDESTATION_BATCH_SIZE 10
718
719void MarkInfoDlg::OnTideStationCombobox(wxCommandEvent& event) {
720 int count = m_comboBoxTideStation->GetCount();
721 int sel = m_comboBoxTideStation->GetSelection();
722 if (sel == count - 1) {
723 wxString n;
724 int i = 0;
725 for (auto ts : m_tss) {
726 if (i == count + TIDESTATION_BATCH_SIZE) {
727 break;
728 }
729 if (i > count) {
730 n = wxString::FromUTF8(ts.second->IDX_station_name);
731 m_comboBoxTideStation->Append(n);
732 }
733 i++;
734 }
735 }
736}
737
738void MarkInfoDlg::OnNotebookPageChanged(wxNotebookEvent& event) {
739 if (event.GetSelection() == EXTENDED_PROP_PAGE) {
740 if (m_lasttspos.IsSameAs(m_textLatitude->GetValue() +
741 m_textLongitude->GetValue())) {
742 return;
743 }
744 m_lasttspos = m_textLatitude->GetValue() + m_textLongitude->GetValue();
745 double lat = fromDMM(m_textLatitude->GetValue());
746 double lon = fromDMM(m_textLongitude->GetValue());
747 m_tss = ptcmgr->GetStationsForLL(lat, lon);
748 wxString s = m_comboBoxTideStation->GetStringSelection();
749 wxString n;
750 int i = 0;
751 m_comboBoxTideStation->Clear();
752 m_comboBoxTideStation->Append(wxEmptyString);
753 for (auto ts : m_tss) {
754 if (i == TIDESTATION_BATCH_SIZE) {
755 break;
756 }
757 i++;
758 n = wxString::FromUTF8(ts.second->IDX_station_name);
759 m_comboBoxTideStation->Append(n);
760 if (s == n) {
761 m_comboBoxTideStation->SetSelection(i);
762 }
763 }
764 if (m_comboBoxTideStation->GetStringSelection() != s) {
765 m_comboBoxTideStation->Insert(s, 1);
766 m_comboBoxTideStation->SetSelection(1);
767 }
768 }
769}
770
771void MarkInfoDlg::RecalculateSize(void) {
772#ifdef __ANDROID__
773
774 Layout();
775
776 wxSize dsize = GetParent()->GetClientSize();
777
778 wxSize esize;
779
780 esize.x = GetCharHeight() * 20;
781 esize.y = GetCharHeight() * 40;
782 // qDebug() << "esizeA" << esize.x << esize.y;
783
784 esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
785 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
786 SetSize(wxSize(esize.x, esize.y));
787 // qDebug() << "esize" << esize.x << esize.y;
788
789 wxSize fsize = GetSize();
790 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
791 fsize.x = wxMin(fsize.x, dsize.x - (1 * GetCharHeight()));
792 // qDebug() << "fsize" << fsize.x << fsize.y;
793
794 // And finally, not too tall...
795 fsize.y = wxMin(fsize.y, (25 * GetCharHeight()));
796
797 SetSize(wxSize(-1, fsize.y));
798
799 m_defaultClientSize = GetClientSize();
800 Center();
801#else
802 wxSize dsize = GetParent()->GetClientSize();
803 SetSize(-1, wxMax(GetSize().y, dsize.y / 1.5));
804#endif
805}
806
807MarkInfoDlg::~MarkInfoDlg() {
808 // Disconnect Events
809 m_textLatitude->Disconnect(
810 wxEVT_CONTEXT_MENU,
811 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
812 m_textLongitude->Disconnect(
813 wxEVT_CONTEXT_MENU,
814 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
815#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
816 m_htmlList->Disconnect(
817 wxEVT_RIGHT_DOWN, wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu),
818 NULL, this);
819#else
820#endif
821
822 m_notebookProperties->Disconnect(
823 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
824 wxNotebookEventHandler(MarkInfoDlg::OnNotebookPageChanged), NULL, this);
825 m_EtaTimePickerCtrl->Disconnect(
826 wxEVT_TIME_CHANGED, wxDateEventHandler(MarkInfoDlg::OnTimeChanged), NULL,
827 this);
828 m_EtaDatePickerCtrl->Disconnect(
829 wxEVT_DATE_CHANGED, wxDateEventHandler(MarkInfoDlg::OnTimeChanged), NULL,
830 this);
831
832#ifdef __ANDROID__
833 androidEnableBackButton(true);
834#endif
835}
836
837void MarkInfoDlg::InitialFocus(void) {
838 m_textName->SetFocus();
839 m_textName->SetInsertionPointEnd();
840}
841
842void MarkInfoDlg::SetColorScheme(ColorScheme cs) { DimeControl(this); }
843
844void MarkInfoDlg::ClearData() {
845 m_pRoutePoint = NULL;
846 UpdateProperties();
847}
848
849void MarkInfoDlg::SetRoutePoint(RoutePoint* pRP) {
850 m_pRoutePoint = pRP;
851 if (m_pRoutePoint) {
852 m_lat_save = m_pRoutePoint->m_lat;
853 m_lon_save = m_pRoutePoint->m_lon;
854 m_IconName_save = m_pRoutePoint->GetIconName();
855 m_bShowName_save = m_pRoutePoint->m_bShowName;
856 m_bIsVisible_save = m_pRoutePoint->m_bIsVisible;
857 m_Name_save = m_pRoutePoint->GetName();
858 m_Description_save = m_pRoutePoint->m_MarkDescription;
859 m_bUseScaMin_save = m_pRoutePoint->GetUseSca();
860 m_iScaminVal_save = m_pRoutePoint->GetScaMin();
861
862 if (m_pMyLinkList) delete m_pMyLinkList;
863 m_pMyLinkList = new HyperlinkList();
864 int NbrOfLinks = m_pRoutePoint->m_HyperlinkList->GetCount();
865 if (NbrOfLinks > 0) {
866 wxHyperlinkListNode* linknode =
867 m_pRoutePoint->m_HyperlinkList->GetFirst();
868 while (linknode) {
869 Hyperlink* link = linknode->GetData();
870
871 Hyperlink* h = new Hyperlink();
872 h->DescrText = link->DescrText;
873 h->Link = link->Link;
874 h->LType = link->LType;
875
876 m_pMyLinkList->Append(h);
877
878 linknode = linknode->GetNext();
879 }
880 }
881 }
882}
883
884void MarkInfoDlg::UpdateHtmlList() {
885#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
886 GetSimpleBox()->Clear();
887 int NbrOfLinks = m_pRoutePoint->m_HyperlinkList->GetCount();
888
889 if (NbrOfLinks > 0) {
890 wxHyperlinkListNode* linknode = m_pRoutePoint->m_HyperlinkList->GetFirst();
891 while (linknode) {
892 Hyperlink* link = linknode->GetData();
893 wxString s = wxString::Format(wxT("<a href='%s'>%s</a>"), link->Link,
894 link->DescrText);
895 GetSimpleBox()->AppendString(s);
896 linknode = linknode->GetNext();
897 }
898 }
899#else
900 // Clear the list
901 wxWindowList kids = m_scrolledWindowLinks->GetChildren();
902 for (unsigned int i = 0; i < kids.GetCount(); i++) {
903 wxWindowListNode* node = kids.Item(i);
904 wxWindow* win = node->GetData();
905
906 auto link_win = dynamic_cast<wxHyperlinkCtrl*>(win);
907 if (link_win) {
908 link_win->Disconnect(
909 wxEVT_COMMAND_HYPERLINK,
910 wxHyperlinkEventHandler(MarkInfoDlg::OnHyperLinkClick));
911 link_win->Disconnect(
912 wxEVT_RIGHT_DOWN,
913 wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu));
914 win->Destroy();
915 }
916 }
917
918 int NbrOfLinks = m_pRoutePoint->m_HyperlinkList->GetCount();
919 HyperlinkList* hyperlinklist = m_pRoutePoint->m_HyperlinkList;
920 if (NbrOfLinks > 0) {
921 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
922 while (linknode) {
923 Hyperlink* link = linknode->GetData();
924 wxString Link = link->Link;
925 wxString Descr = link->DescrText;
926
927 wxHyperlinkCtrl* ctrl = new wxHyperlinkCtrl(
928 m_scrolledWindowLinks, wxID_ANY, Descr, Link, wxDefaultPosition,
929 wxDefaultSize, wxNO_BORDER | wxHL_CONTEXTMENU | wxHL_ALIGN_LEFT);
930 ctrl->Connect(wxEVT_COMMAND_HYPERLINK,
931 wxHyperlinkEventHandler(MarkInfoDlg::OnHyperLinkClick),
932 NULL, this);
933 if (!m_pRoutePoint->m_bIsInLayer)
934 ctrl->Connect(wxEVT_RIGHT_DOWN,
935 wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu),
936 NULL, this);
937
938 bSizerLinks->Add(ctrl, 1, wxALL | wxEXPAND, 5);
939
940 linknode = linknode->GetNext();
941 }
942 }
943
944 // Integrate all of the rebuilt hyperlink controls
945 m_scrolledWindowLinks->Layout();
946#endif
947}
948
949void MarkInfoDlg::OnHyperLinkClick(wxHyperlinkEvent& event) {
950 wxString url = event.GetURL();
951 url.Replace(_T(" "), _T("%20"));
952 if (g_Platform) g_Platform->platformLaunchDefaultBrowser(url);
953}
954
955void MarkInfoDlg::OnHtmlLinkClicked(wxHtmlLinkEvent& event) {
956 // Windows has trouble handling local file URLs with embedded anchor
957 // points, e.g file://testfile.html#point1 The trouble is with the
958 // wxLaunchDefaultBrowser with verb "open" Workaround is to probe the
959 // registry to get the default browser, and open directly
960 //
961 // But, we will do this only if the URL contains the anchor point
962 // character '#' What a hack......
963
964#ifdef __WXMSW__
965 wxString cc = event.GetLinkInfo().GetHref().c_str();
966 if (cc.Find(_T("#")) != wxNOT_FOUND) {
967 wxRegKey RegKey(
968 wxString(_T("HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command")));
969 if (RegKey.Exists()) {
970 wxString command_line;
971 RegKey.QueryValue(wxString(_T("")), command_line);
972
973 // Remove "
974 command_line.Replace(wxString(_T("\"")), wxString(_T("")));
975
976 // Strip arguments
977 int l = command_line.Find(_T(".exe"));
978 if (wxNOT_FOUND == l) l = command_line.Find(_T(".EXE"));
979
980 if (wxNOT_FOUND != l) {
981 wxString cl = command_line.Mid(0, l + 4);
982 cl += _T(" ");
983 cc.Prepend(_T("\""));
984 cc.Append(_T("\""));
985 cl += cc;
986 wxExecute(cl); // Async, so Fire and Forget...
987 }
988 }
989 } else {
990 wxString url = event.GetLinkInfo().GetHref().c_str();
991 url.Replace(_T(" "), _T("%20"));
992 ::wxLaunchDefaultBrowser(url);
993 event.Skip();
994 }
995#else
996 wxString url = event.GetLinkInfo().GetHref().c_str();
997 url.Replace(_T(" "), _T("%20"));
998 if (g_Platform) g_Platform->platformLaunchDefaultBrowser(url);
999
1000 event.Skip();
1001#endif
1002}
1003
1004void MarkInfoDlg::OnLayoutResize(wxCommandEvent& event) {
1005 m_panelBasicProperties->Layout();
1006 this->Layout();
1007}
1008
1009void MarkInfoDlg::OnDescChangedExt(wxCommandEvent& event) {
1010 if (m_panelDescription->IsShownOnScreen()) {
1011 m_textDescription->ChangeValue(m_textCtrlExtDescription->GetValue());
1012 }
1013 event.Skip();
1014}
1015void MarkInfoDlg::OnDescChangedBasic(wxCommandEvent& event) {
1016 if (m_panelBasicProperties->IsShownOnScreen()) {
1017 m_textCtrlExtDescription->ChangeValue(m_textDescription->GetValue());
1018 }
1019 event.Skip();
1020}
1021
1022void MarkInfoDlg::OnExtDescriptionClick(wxCommandEvent& event) {
1023 long pos = m_textDescription->GetInsertionPoint();
1024 m_notebookProperties->SetSelection(1);
1025 m_textCtrlExtDescription->SetInsertionPoint(pos);
1026 event.Skip();
1027}
1028
1029void MarkInfoDlg::OnShowWaypointNameSelectBasic(wxCommandEvent& event) {
1030 m_checkBoxShowNameExt->SetValue(m_checkBoxShowName->GetValue());
1031 event.Skip();
1032}
1033void MarkInfoDlg::OnShowWaypointNameSelectExt(wxCommandEvent& event) {
1034 m_checkBoxShowName->SetValue(m_checkBoxShowNameExt->GetValue());
1035 event.Skip();
1036}
1037
1038void MarkInfoDlg::OnWptRangeRingsNoChange(wxCommandEvent& event) {
1039 if (!m_pRoutePoint->m_bIsInLayer) {
1040 m_textWaypointRangeRingsStep->Enable(
1041 (bool)(m_ChoiceWaypointRangeRingsNumber->GetSelection() != 0));
1042 m_PickColor->Enable(
1043 (bool)(m_ChoiceWaypointRangeRingsNumber->GetSelection() != 0));
1044 }
1045}
1046
1047void MarkInfoDlg::OnSelectScaMinExt(wxCommandEvent& event) {
1048 if (!m_pRoutePoint->m_bIsInLayer) {
1049 m_textScaMin->Enable(m_checkBoxScaMin->GetValue());
1050 }
1051}
1052
1053void MarkInfoDlg::OnPositionCtlUpdated(wxCommandEvent& event) {
1054 // Fetch the control values, convert to degrees
1055 double lat = fromDMM(m_textLatitude->GetValue());
1056 double lon = fromDMM(m_textLongitude->GetValue());
1057 if (!m_pRoutePoint->m_bIsInLayer) {
1058 m_pRoutePoint->SetPosition(lat, lon);
1059 pSelect->ModifySelectablePoint(lat, lon, (void*)m_pRoutePoint,
1060 SELTYPE_ROUTEPOINT);
1061 }
1062 // Update the mark position dynamically
1063 gFrame->RefreshAllCanvas();
1064}
1065
1066void MarkInfoDlg::m_htmlListContextMenu(wxMouseEvent& event) {
1067#ifndef __ANDROID__
1068 // SimpleHtmlList->HitTest doesn't seem to work under msWin, so we use a
1069 // custom made version
1070 wxPoint pos = event.GetPosition();
1071 i_htmlList_item = -1;
1072 for (int i = 0; i < (int)GetSimpleBox()->GetCount(); i++) {
1073 wxRect rect = GetSimpleBox()->GetItemRect(i);
1074 if (rect.Contains(pos)) {
1075 i_htmlList_item = i;
1076 break;
1077 }
1078 }
1079
1080 wxMenu* popup = new wxMenu();
1081 if ((GetSimpleBox()->GetCount()) > 0 && (i_htmlList_item > -1) &&
1082 (i_htmlList_item < (int)GetSimpleBox()->GetCount())) {
1083 popup->Append(ID_RCLK_MENU_DELETE_LINK, _("Delete"));
1084 popup->Append(ID_RCLK_MENU_EDIT_LINK, _("Edit"));
1085 }
1086 popup->Append(ID_RCLK_MENU_ADD_LINK, _("Add New"));
1087
1088 m_contextObject = event.GetEventObject();
1089 popup->Connect(
1090 wxEVT_COMMAND_MENU_SELECTED,
1091 wxCommandEventHandler(MarkInfoDlg::On_html_link_popupmenu_Click), NULL,
1092 this);
1093 PopupMenu(popup);
1094 delete popup;
1095#else
1096
1097 m_pEditedLink = dynamic_cast<wxHyperlinkCtrl*>(event.GetEventObject());
1098
1099 if (m_pEditedLink) {
1100 wxString url = m_pEditedLink->GetURL();
1101 wxString label = m_pEditedLink->GetLabel();
1102 i_htmlList_item = -1;
1103 HyperlinkList* hyperlinklist = m_pRoutePoint->m_HyperlinkList;
1104 if (hyperlinklist->GetCount() > 0) {
1105 int i = 0;
1106 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
1107 while (linknode) {
1108 Hyperlink* link = linknode->GetData();
1109 if (link->DescrText == label) {
1110 i_htmlList_item = i;
1111 break;
1112 }
1113
1114 linknode = linknode->GetNext();
1115 i++;
1116 }
1117 }
1118
1119 wxFont sFont = GetOCPNGUIScaledFont(_("Menu"));
1120
1121 wxMenu* popup = new wxMenu();
1122 {
1123 wxMenuItem* menuItemDelete =
1124 new wxMenuItem(popup, ID_RCLK_MENU_DELETE_LINK, wxString(_("Delete")),
1125 wxEmptyString, wxITEM_NORMAL);
1126#ifdef __WXQT__
1127 menuItemDelete->SetFont(sFont);
1128#endif
1129 popup->Append(menuItemDelete);
1130
1131 wxMenuItem* menuItemEdit =
1132 new wxMenuItem(popup, ID_RCLK_MENU_EDIT_LINK, wxString(_("Edit")),
1133 wxEmptyString, wxITEM_NORMAL);
1134#ifdef __WXQT__
1135 menuItemEdit->SetFont(sFont);
1136#endif
1137 popup->Append(menuItemEdit);
1138 }
1139
1140 wxMenuItem* menuItemAdd =
1141 new wxMenuItem(popup, ID_RCLK_MENU_ADD_LINK, wxString(_("Add New")),
1142 wxEmptyString, wxITEM_NORMAL);
1143#ifdef __WXQT__
1144 menuItemAdd->SetFont(sFont);
1145#endif
1146 popup->Append(menuItemAdd);
1147
1148 m_contextObject = event.GetEventObject();
1149 popup->Connect(
1150 wxEVT_COMMAND_MENU_SELECTED,
1151 wxCommandEventHandler(MarkInfoDlg::On_html_link_popupmenu_Click), NULL,
1152 this);
1153 wxPoint p = m_scrolledWindowLinks->GetPosition();
1154 p.x += m_scrolledWindowLinks->GetSize().x / 2;
1155 PopupMenu(popup, p);
1156 delete popup;
1157
1158 // m_scrolledWindowLinks->PopupMenu( m_menuLink,
1159 // m_pEditedLink->GetPosition().x /*+ event.GetPosition().x*/,
1160 // m_pEditedLink->GetPosition().y /*+ event.GetPosition().y*/ );
1161 }
1162/*
1163 wxPoint pos = event.GetPosition();
1164 i_htmlList_item = -1;
1165 for( int i=0; i < (int)GetSimpleBox()->GetCount(); i++ )
1166 {
1167 wxRect rect = GetSimpleBox()->GetItemRect( i );
1168 if( rect.Contains( pos) ){
1169 i_htmlList_item = i;
1170 break;
1171 }
1172 }
1173
1174 */
1175#endif
1176}
1177
1178void MarkInfoDlg::OnAddLink(wxCommandEvent& event) {
1179 wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED);
1180 evt.SetId(ID_RCLK_MENU_ADD_LINK);
1181
1182 On_html_link_popupmenu_Click(evt);
1183}
1184
1185void MarkInfoDlg::On_html_link_popupmenu_Click(wxCommandEvent& event) {
1186 switch (event.GetId()) {
1187 case ID_RCLK_MENU_DELETE_LINK: {
1188 wxHyperlinkListNode* node =
1189 m_pRoutePoint->m_HyperlinkList->Item(i_htmlList_item);
1190 m_pRoutePoint->m_HyperlinkList->DeleteNode(node);
1191 UpdateHtmlList();
1192 break;
1193 }
1194 case ID_RCLK_MENU_EDIT_LINK: {
1195 Hyperlink* link =
1196 m_pRoutePoint->m_HyperlinkList->Item(i_htmlList_item)->GetData();
1197 LinkPropImpl* LinkPropDlg = new LinkPropImpl(this);
1198 LinkPropDlg->m_textCtrlLinkDescription->SetValue(link->DescrText);
1199 LinkPropDlg->m_textCtrlLinkUrl->SetValue(link->Link);
1200 DimeControl(LinkPropDlg);
1201 LinkPropDlg->ShowWindowModalThenDo([this, LinkPropDlg,
1202 link](int retcode) {
1203 if (retcode == wxID_OK) {
1204 link->DescrText = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1205 link->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1206 m_pRoutePoint->m_HyperlinkList->Item(i_htmlList_item)->SetData(link);
1207 UpdateHtmlList();
1208 }
1209 });
1210 break;
1211 }
1212 case ID_RCLK_MENU_ADD_LINK: {
1213 LinkPropImpl* LinkPropDlg = new LinkPropImpl(this);
1214 LinkPropDlg->m_textCtrlLinkDescription->SetValue(wxEmptyString);
1215 LinkPropDlg->m_textCtrlLinkUrl->SetValue(wxEmptyString);
1216 DimeControl(LinkPropDlg);
1217 LinkPropDlg->ShowWindowModalThenDo([this, LinkPropDlg](int retcode) {
1218 if (retcode == wxID_OK) {
1219 Hyperlink* link = new Hyperlink;
1220 link->DescrText = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1221 link->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1222 // Check if decent
1223 if (link->DescrText == wxEmptyString) {
1224 link->DescrText = link->Link;
1225 }
1226 if (link->Link == wxEmptyString) {
1227 delete link;
1228 } else {
1229 m_pRoutePoint->m_HyperlinkList->Append(link);
1230 }
1231 UpdateHtmlList();
1232 }
1233 });
1234 break;
1235 }
1236 }
1237 event.Skip();
1238}
1239
1240void MarkInfoDlg::OnRightClickLatLon(wxCommandEvent& event) {
1241 wxMenu* popup = new wxMenu();
1242 popup->Append(ID_RCLK_MENU_COPY, _("Copy"));
1243 popup->Append(ID_RCLK_MENU_COPY_LL, _("Copy lat/long"));
1244 popup->Append(ID_RCLK_MENU_PASTE, _("Paste"));
1245 popup->Append(ID_RCLK_MENU_PASTE_LL, _("Paste lat/long"));
1246 m_contextObject = event.GetEventObject();
1247 popup->Connect(wxEVT_COMMAND_MENU_SELECTED,
1248 wxCommandEventHandler(MarkInfoDlg::OnCopyPasteLatLon), NULL,
1249 this);
1250
1251 PopupMenu(popup);
1252 delete popup;
1253}
1254
1255void MarkInfoDlg::OnCopyPasteLatLon(wxCommandEvent& event) {
1256 // Fetch the control values, convert to degrees
1257 double lat = fromDMM(m_textLatitude->GetValue());
1258 double lon = fromDMM(m_textLongitude->GetValue());
1259
1260 wxString result;
1261
1262 switch (event.GetId()) {
1263 case ID_RCLK_MENU_PASTE: {
1264 if (wxTheClipboard->Open()) {
1265 wxTextDataObject data;
1266 wxTheClipboard->GetData(data);
1267 result = data.GetText();
1268 ((wxTextCtrl*)m_contextObject)->SetValue(result);
1269 wxTheClipboard->Close();
1270 }
1271 return;
1272 }
1273 case ID_RCLK_MENU_PASTE_LL: {
1274 if (wxTheClipboard->Open()) {
1275 wxTextDataObject data;
1276 wxTheClipboard->GetData(data);
1277 result = data.GetText();
1278
1279 PositionParser pparse(result);
1280
1281 if (pparse.IsOk()) {
1282 m_textLatitude->SetValue(pparse.GetLatitudeString());
1283 m_textLongitude->SetValue(pparse.GetLongitudeString());
1284 }
1285 wxTheClipboard->Close();
1286 }
1287 return;
1288 }
1289 case ID_RCLK_MENU_COPY: {
1290 result = ((wxTextCtrl*)m_contextObject)->GetValue();
1291 break;
1292 }
1293 case ID_RCLK_MENU_COPY_LL: {
1294 result << toSDMM(1, lat, true) << _T('\t');
1295 result << toSDMM(2, lon, true);
1296 break;
1297 }
1298 }
1299
1300 if (wxTheClipboard->Open()) {
1301 wxTextDataObject* data = new wxTextDataObject;
1302 data->SetText(result);
1303 wxTheClipboard->SetData(data);
1304 wxTheClipboard->Close();
1305 }
1306}
1307
1308void MarkInfoDlg::DefautlBtnClicked(wxCommandEvent& event) {
1309 m_SaveDefaultDlg = new SaveDefaultsDialog(this);
1310 m_SaveDefaultDlg->Center();
1311 DimeControl(m_SaveDefaultDlg);
1312 int retcode = m_SaveDefaultDlg->ShowModal();
1313
1314 {
1315 if (retcode == wxID_OK) {
1316 double value;
1317 if (m_SaveDefaultDlg->IconCB->GetValue()) {
1318 g_default_wp_icon =
1319 *pWayPointMan->GetIconKey(m_bcomboBoxIcon->GetSelection());
1320 }
1321 if (m_SaveDefaultDlg->RangRingsCB->GetValue()) {
1322 g_iWaypointRangeRingsNumber =
1323 m_ChoiceWaypointRangeRingsNumber->GetSelection();
1324 if (m_textWaypointRangeRingsStep->GetValue().ToDouble(&value))
1325 g_fWaypointRangeRingsStep = fromUsrDistance(value, -1);
1326 g_colourWaypointRangeRingsColour = m_PickColor->GetColour();
1327 }
1328 if (m_SaveDefaultDlg->ArrivalRCB->GetValue())
1329 if (m_textArrivalRadius->GetValue().ToDouble(&value))
1330 g_n_arrival_circle_radius = fromUsrDistance(value, -1);
1331 if (m_SaveDefaultDlg->ScaleCB->GetValue()) {
1332 g_iWpt_ScaMin = wxAtoi(m_textScaMin->GetValue());
1333 g_bUseWptScaMin = m_checkBoxScaMin->GetValue();
1334 }
1335 if (m_SaveDefaultDlg->NameCB->GetValue()) {
1336 g_bShowWptName = m_checkBoxShowName->GetValue();
1337 }
1338 }
1339 m_SaveDefaultDlg = NULL;
1340 }
1341}
1342
1343void MarkInfoDlg::OnMarkInfoCancelClick(wxCommandEvent& event) {
1344 if (m_pRoutePoint) {
1345 m_pRoutePoint->SetVisible(m_bIsVisible_save);
1346 m_pRoutePoint->SetNameShown(m_bShowName_save);
1347 m_pRoutePoint->SetPosition(m_lat_save, m_lon_save);
1348 m_pRoutePoint->SetIconName(m_IconName_save);
1349 m_pRoutePoint->ReLoadIcon();
1350 m_pRoutePoint->SetName(m_Name_save);
1351 m_pRoutePoint->m_MarkDescription = m_Description_save;
1352 m_pRoutePoint->SetUseSca(m_bUseScaMin_save);
1353 m_pRoutePoint->SetScaMin(m_iScaminVal_save);
1354
1355 m_pRoutePoint->m_HyperlinkList->Clear();
1356
1357 int NbrOfLinks = m_pMyLinkList->GetCount();
1358 if (NbrOfLinks > 0) {
1359 wxHyperlinkListNode* linknode = m_pMyLinkList->GetFirst();
1360 while (linknode) {
1361 Hyperlink* link = linknode->GetData();
1362 Hyperlink* h = new Hyperlink();
1363 h->DescrText = link->DescrText;
1364 h->Link = link->Link;
1365 h->LType = link->LType;
1366
1367 m_pRoutePoint->m_HyperlinkList->Append(h);
1368
1369 linknode = linknode->GetNext();
1370 }
1371 }
1372 }
1373
1374 m_lasttspos.Clear();
1375
1376#ifdef __WXGTK__
1377 gFrame->Raise();
1378#endif
1379
1380 Show(false);
1381 delete m_pMyLinkList;
1382 m_pMyLinkList = NULL;
1383 SetClientSize(m_defaultClientSize);
1384
1385#ifdef __ANDROID__
1386 androidEnableBackButton(true);
1387#endif
1388
1389 event.Skip();
1390}
1391
1392void MarkInfoDlg::OnMarkInfoOKClick(wxCommandEvent& event) {
1393 if (m_pRoutePoint) {
1394 m_pRoutePoint->m_wxcWaypointRangeRingsColour = m_PickColor->GetColour();
1395
1396 OnPositionCtlUpdated(event);
1397 SaveChanges(); // write changes to globals and update config
1398 }
1399
1400#ifdef __WXGTK__
1401 gFrame->Raise();
1402#endif
1403
1404 Show(false);
1405
1406 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1407 pRouteManagerDialog->UpdateWptListCtrl();
1408
1409 if (pRoutePropDialog && pRoutePropDialog->IsShown())
1410 pRoutePropDialog->UpdatePoints();
1411
1412 SetClientSize(m_defaultClientSize);
1413
1414#ifdef __ANDROID__
1415 androidEnableBackButton(true);
1416#endif
1417
1418 event.Skip();
1419}
1420
1421bool MarkInfoDlg::UpdateProperties(bool positionOnly) {
1422 if (m_pRoutePoint) {
1423 m_textLatitude->SetValue(::toSDMM(1, m_pRoutePoint->m_lat));
1424 m_textLongitude->SetValue(::toSDMM(2, m_pRoutePoint->m_lon));
1425 m_lat_save = m_pRoutePoint->m_lat;
1426 m_lon_save = m_pRoutePoint->m_lon;
1427 m_textName->SetValue(m_pRoutePoint->GetName());
1428 m_textDescription->ChangeValue(m_pRoutePoint->m_MarkDescription);
1429 m_textCtrlExtDescription->ChangeValue(m_pRoutePoint->m_MarkDescription);
1430 m_checkBoxShowName->SetValue(m_pRoutePoint->m_bShowName);
1431 m_checkBoxShowNameExt->SetValue(m_pRoutePoint->m_bShowName);
1432 m_checkBoxVisible->SetValue(m_pRoutePoint->m_bIsVisible);
1433 m_checkBoxScaMin->SetValue(m_pRoutePoint->GetUseSca());
1434 m_textScaMin->SetValue(
1435 wxString::Format(wxT("%i"), (int)m_pRoutePoint->GetScaMin()));
1436 m_textCtrlGuid->SetValue(m_pRoutePoint->m_GUID);
1437 m_ChoiceWaypointRangeRingsNumber->SetSelection(
1438 m_pRoutePoint->GetWaypointRangeRingsNumber());
1439 wxString buf;
1440 buf.Printf(_T("%.3f"),
1441 toUsrDistance(m_pRoutePoint->GetWaypointRangeRingsStep(), -1));
1442 m_textWaypointRangeRingsStep->SetValue(buf);
1443 m_staticTextArrivalUnits->SetLabel(getUsrDistanceUnit());
1444 buf.Printf(_T("%.3f"),
1445 toUsrDistance(m_pRoutePoint->GetWaypointArrivalRadius(), -1));
1446 m_textArrivalRadius->SetValue(buf);
1447
1448 int nUnits = m_pRoutePoint->GetWaypointRangeRingsStepUnits();
1449 m_RangeRingUnits->SetSelection(nUnits);
1450
1451 wxColour col = m_pRoutePoint->m_wxcWaypointRangeRingsColour;
1452 m_PickColor->SetColour(col);
1453
1454 if (m_pRoutePoint->m_bIsInRoute) {
1455 if (m_name_validator) m_name_validator.reset();
1456 m_name_validator =
1457 std::make_unique<RoutePointNameValidator>(m_pRoutePoint);
1458 m_textName->SetValidator(*m_name_validator);
1459 m_textName->Bind(wxEVT_TEXT, &TextField::OnTextChanged, m_textName);
1460 m_textName->Bind(wxEVT_KILL_FOCUS, &MarkInfoDlg::OnFocusEvent, this);
1461 } else {
1462 m_textName->SetValidator();
1463 m_textName->Unbind(wxEVT_TEXT, &TextField::OnTextChanged, m_textName);
1464 m_textName->Unbind(wxEVT_KILL_FOCUS, &MarkInfoDlg::OnFocusEvent, this);
1465 }
1466
1467 if (m_comboBoxTideStation->GetStringSelection() !=
1468 m_pRoutePoint->m_TideStation) {
1469 m_comboBoxTideStation->Clear();
1470 m_comboBoxTideStation->Append(wxEmptyString);
1471 if (!m_pRoutePoint->m_TideStation.IsEmpty()) {
1472 m_comboBoxTideStation->Append(m_pRoutePoint->m_TideStation);
1473 m_comboBoxTideStation->SetSelection(1);
1474 }
1475 }
1476
1477 if (m_pRoutePoint->GetPlannedSpeed() > .01) {
1478 m_textCtrlPlSpeed->SetValue(wxString::Format(
1479 "%.1f", toUsrSpeed(m_pRoutePoint->GetPlannedSpeed())));
1480 } else {
1481 m_textCtrlPlSpeed->SetValue(wxEmptyString);
1482 }
1483
1484 wxDateTime etd;
1485 etd = m_pRoutePoint->GetManualETD();
1486 if (etd.IsValid()) {
1487 m_cbEtaPresent->SetValue(true);
1488 m_EtaDatePickerCtrl->SetValue(etd.GetDateOnly());
1489 m_EtaTimePickerCtrl->SetValue(etd);
1490 } else {
1491 m_cbEtaPresent->SetValue(false);
1492 }
1493
1494 m_staticTextPlSpeed->Show(m_pRoutePoint->m_bIsInRoute);
1495 m_textCtrlPlSpeed->Show(m_pRoutePoint->m_bIsInRoute);
1496 m_staticTextEta->Show(m_pRoutePoint->m_bIsInRoute);
1497 m_EtaDatePickerCtrl->Show(m_pRoutePoint->m_bIsInRoute);
1498 m_EtaTimePickerCtrl->Show(m_pRoutePoint->m_bIsInRoute);
1499 m_cbEtaPresent->Show(m_pRoutePoint->m_bIsInRoute);
1500 m_staticTextPlSpeedUnits->Show(m_pRoutePoint->m_bIsInRoute);
1501 m_staticTextArrivalRadius->Show(m_pRoutePoint->m_bIsInRoute);
1502 m_staticTextArrivalUnits->Show(m_pRoutePoint->m_bIsInRoute);
1503 m_textArrivalRadius->Show(m_pRoutePoint->m_bIsInRoute);
1504
1505 if (positionOnly) return true;
1506
1507 // Layer or not?
1508 if (m_pRoutePoint->m_bIsInLayer) {
1509 m_staticTextLayer->Enable();
1510 m_staticTextLayer->Show(true);
1511 m_textName->SetEditable(false);
1512 m_textDescription->SetEditable(false);
1513 m_textCtrlExtDescription->SetEditable(false);
1514 m_textLatitude->SetEditable(false);
1515 m_textLongitude->SetEditable(false);
1516 m_bcomboBoxIcon->Enable(false);
1517 m_checkBoxShowName->Enable(false);
1518 m_checkBoxVisible->Enable(false);
1519 m_textArrivalRadius->SetEditable(false);
1520 m_checkBoxScaMin->Enable(false);
1521 m_textScaMin->SetEditable(false);
1522 m_checkBoxShowNameExt->Enable(false);
1523 m_ChoiceWaypointRangeRingsNumber->Enable(false);
1524 m_textWaypointRangeRingsStep->SetEditable(false);
1525 m_PickColor->Enable(false);
1526 DefaultsBtn->Enable(false);
1527 m_EtaDatePickerCtrl->Enable(false);
1528 m_EtaTimePickerCtrl->Enable(false);
1529 m_cbEtaPresent->Enable(false);
1530 m_notebookProperties->SetSelection(0); // Show Basic page
1531 m_comboBoxTideStation->Enable(false);
1532 } else {
1533 m_staticTextLayer->Enable(false);
1534 m_staticTextLayer->Show(false);
1535 m_textName->SetEditable(true);
1536 m_textDescription->SetEditable(true);
1537 m_textCtrlExtDescription->SetEditable(true);
1538 m_textLatitude->SetEditable(true);
1539 m_textLongitude->SetEditable(true);
1540 m_bcomboBoxIcon->Enable(true);
1541 m_checkBoxShowName->Enable(true);
1542 m_checkBoxVisible->Enable(true);
1543 m_textArrivalRadius->SetEditable(true);
1544 m_checkBoxScaMin->Enable(true);
1545 m_textScaMin->SetEditable(true);
1546 m_checkBoxShowNameExt->Enable(true);
1547 m_ChoiceWaypointRangeRingsNumber->Enable(true);
1548 m_textWaypointRangeRingsStep->SetEditable(true);
1549 m_PickColor->Enable(true);
1550 DefaultsBtn->Enable(true);
1551 m_EtaDatePickerCtrl->Enable(true);
1552 m_EtaTimePickerCtrl->Enable(true);
1553 m_cbEtaPresent->Enable(true);
1554 m_notebookProperties->SetSelection(0);
1555 m_comboBoxTideStation->Enable(true);
1556 }
1557
1558 // Fill the icon selector combo box
1559 m_bcomboBoxIcon->Clear();
1560 // Iterate on the Icon Descriptions, filling in the combo control
1561 bool fillCombo = m_bcomboBoxIcon->GetCount() == 0;
1562
1563 if (fillCombo) {
1564 for (int i = 0; i < pWayPointMan->GetNumIcons(); i++) {
1565 wxString* ps = pWayPointMan->GetIconDescription(i);
1566 wxBitmap bmp =
1567 pWayPointMan->GetIconBitmapForList(i, 2 * GetCharHeight());
1568
1569 m_bcomboBoxIcon->Append(*ps, bmp);
1570 }
1571 }
1572 // find the correct item in the combo box
1573 int iconToSelect = -1;
1574 for (int i = 0; i < pWayPointMan->GetNumIcons(); i++) {
1575 if (*pWayPointMan->GetIconKey(i) == m_pRoutePoint->GetIconName()) {
1576 iconToSelect = i;
1577 m_bcomboBoxIcon->Select(iconToSelect);
1578 break;
1579 }
1580 }
1581 wxCommandEvent ev;
1582 OnShowWaypointNameSelectBasic(ev);
1583 OnWptRangeRingsNoChange(ev);
1584 OnSelectScaMinExt(ev);
1585 UpdateHtmlList();
1586 }
1587
1588#ifdef __ANDROID__
1589 androidEnableBackButton(false);
1590#endif
1591
1592 Fit();
1593 // SetMinSize(wxSize(-1, 600));
1594 RecalculateSize();
1595
1596 return true;
1597}
1598
1599// Focus event handler to validate the dialog.
1600void MarkInfoDlg::OnFocusEvent(wxFocusEvent& event) {
1601 bool is_valid = Validate();
1602 m_buttonOkay->Enable(is_valid);
1603 event.Skip();
1604}
1605
1606void MarkInfoDlg::OnBitmapCombClick(wxCommandEvent& event) {
1607 wxString* icon_name =
1608 pWayPointMan->GetIconKey(m_bcomboBoxIcon->GetSelection());
1609 if (icon_name && icon_name->Length()) m_pRoutePoint->SetIconName(*icon_name);
1610 m_pRoutePoint->ReLoadIcon();
1611 SaveChanges();
1612 // pConfig->UpdateWayPoint( m_pRoutePoint );
1613}
1614
1615void MarkInfoDlg::ValidateMark(void) {
1616 // Look in the master list of Waypoints to see if the currently selected
1617 // waypoint is still valid It may have been deleted as part of a route
1618 wxRoutePointListNode* node = pWayPointMan->GetWaypointList()->GetFirst();
1619
1620 bool b_found = false;
1621 while (node) {
1622 RoutePoint* rp = node->GetData();
1623 if (m_pRoutePoint == rp) {
1624 b_found = true;
1625 break;
1626 }
1627 node = node->GetNext();
1628 }
1629 if (!b_found) m_pRoutePoint = NULL;
1630}
1631
1632bool MarkInfoDlg::SaveChanges() {
1633 if (m_pRoutePoint) {
1634 if (m_pRoutePoint->m_bIsInLayer) return true;
1635 if (!this->Validate()) return false; // prevent invalid save
1636
1637 // Get User input Text Fields
1638 m_pRoutePoint->SetName(m_textName->GetValue());
1639 m_pRoutePoint->SetWaypointArrivalRadius(m_textArrivalRadius->GetValue());
1640 m_pRoutePoint->SetScaMin(m_textScaMin->GetValue());
1641 m_pRoutePoint->SetUseSca(m_checkBoxScaMin->GetValue());
1642 m_pRoutePoint->m_MarkDescription = m_textDescription->GetValue();
1643 m_pRoutePoint->SetVisible(m_checkBoxVisible->GetValue());
1644 m_pRoutePoint->m_bShowName = m_checkBoxShowName->GetValue();
1645 m_pRoutePoint->SetPosition(fromDMM(m_textLatitude->GetValue()),
1646 fromDMM(m_textLongitude->GetValue()));
1647 wxString* icon_name =
1648 pWayPointMan->GetIconKey(m_bcomboBoxIcon->GetSelection());
1649 if (icon_name && icon_name->Length())
1650 m_pRoutePoint->SetIconName(*icon_name);
1651 m_pRoutePoint->ReLoadIcon();
1652 m_pRoutePoint->SetShowWaypointRangeRings(
1653 (bool)(m_ChoiceWaypointRangeRingsNumber->GetSelection() != 0));
1654 m_pRoutePoint->SetWaypointRangeRingsNumber(
1655 m_ChoiceWaypointRangeRingsNumber->GetSelection());
1656 double value;
1657 if (m_textWaypointRangeRingsStep->GetValue().ToDouble(&value))
1658 m_pRoutePoint->SetWaypointRangeRingsStep(fromUsrDistance(value, -1));
1659 if (m_textArrivalRadius->GetValue().ToDouble(&value))
1660 m_pRoutePoint->SetWaypointArrivalRadius(fromUsrDistance(value, -1));
1661
1662 if (m_RangeRingUnits->GetSelection() != wxNOT_FOUND)
1663 m_pRoutePoint->SetWaypointRangeRingsStepUnits(
1664 m_RangeRingUnits->GetSelection());
1665
1666 m_pRoutePoint->m_TideStation = m_comboBoxTideStation->GetStringSelection();
1667 if (m_textCtrlPlSpeed->GetValue() == wxEmptyString) {
1668 m_pRoutePoint->SetPlannedSpeed(0.0);
1669 } else {
1670 double spd;
1671 if (m_textCtrlPlSpeed->GetValue().ToDouble(&spd)) {
1672 m_pRoutePoint->SetPlannedSpeed(fromUsrSpeed(spd));
1673 }
1674 }
1675
1676 if (m_cbEtaPresent->GetValue()) {
1677 wxDateTime dt = m_EtaDatePickerCtrl->GetValue();
1678 dt.SetHour(m_EtaTimePickerCtrl->GetValue().GetHour());
1679 dt.SetMinute(m_EtaTimePickerCtrl->GetValue().GetMinute());
1680 dt.SetSecond(m_EtaTimePickerCtrl->GetValue().GetSecond());
1681 if (dt.IsValid()) {
1682 m_pRoutePoint->SetETD(dt.FormatISOCombined());
1683 }
1684 } else {
1685 m_pRoutePoint->SetETD(wxEmptyString);
1686 }
1687
1688 if (m_pRoutePoint->m_bIsInRoute) {
1689 // Update the route segment selectables
1690 pSelect->UpdateSelectableRouteSegments(m_pRoutePoint);
1691
1692 // Get an array of all routes using this point
1693 wxArrayPtrVoid* pEditRouteArray =
1694 g_pRouteMan->GetRouteArrayContaining(m_pRoutePoint);
1695
1696 if (pEditRouteArray) {
1697 for (unsigned int ir = 0; ir < pEditRouteArray->GetCount(); ir++) {
1698 Route* pr = (Route*)pEditRouteArray->Item(ir);
1699 pr->FinalizeForRendering();
1700 pr->UpdateSegmentDistances();
1701
1702 pConfig->UpdateRoute(pr);
1703 }
1704 delete pEditRouteArray;
1705 }
1706 } else
1707 pConfig->UpdateWayPoint(m_pRoutePoint);
1708 // No general settings need be saved pConfig->UpdateSettings();
1709 }
1710 return true;
1711}
1712
1713SaveDefaultsDialog::SaveDefaultsDialog(MarkInfoDlg* parent)
1714 : wxDialog(parent, wxID_ANY, _("Save some defaults")) {
1715 //(*Initialize(SaveDefaultsDialog)
1716 this->SetSizeHints(wxDefaultSize, wxDefaultSize);
1717
1718 wxBoxSizer* bSizer1 = new wxBoxSizer(wxVERTICAL);
1719 wxStdDialogButtonSizer* StdDialogButtonSizer1;
1720
1721 StaticText1 =
1722 new wxStaticText(this, wxID_ANY,
1723 _("Check which properties of current waypoint\n should "
1724 "be set as default for NEW waypoints."));
1725 bSizer1->Add(StaticText1, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
1726
1727 wxFlexGridSizer* fgSizer1 = new wxFlexGridSizer(2);
1728
1729 wxString s =
1730 (g_pMarkInfoDialog->m_checkBoxShowName->GetValue() ? _("Do use")
1731 : _("Don't use"));
1732 NameCB =
1733 new wxCheckBox(this, wxID_ANY, _("Show Waypoint Name"), wxDefaultPosition,
1734 wxDefaultSize, 0, wxDefaultValidator);
1735 fgSizer1->Add(NameCB, 0, wxALL, 5);
1736 stName = new wxStaticText(this, wxID_ANY, _T("[") + s + _T("]"),
1737 wxDefaultPosition, wxDefaultSize, 0);
1738 stName->Wrap(-1);
1739 fgSizer1->Add(stName, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1740
1741 s = g_pMarkInfoDialog->m_pRoutePoint->GetIconName();
1742 IconCB = new wxCheckBox(this, wxID_ANY, _("Icon"));
1743 fgSizer1->Add(IconCB, 0, wxALL, 5);
1744 stIcon = new wxStaticText(this, wxID_ANY, _T("[") + s + _T("]"),
1745 wxDefaultPosition, wxDefaultSize, 0);
1746 stIcon->Wrap(-1);
1747 fgSizer1->Add(stIcon, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1748
1749 s = (g_pMarkInfoDialog->m_ChoiceWaypointRangeRingsNumber->GetSelection()
1750 ? _("Do use") +
1751 wxString::Format(
1752 _T(" (%i) "),
1753 g_pMarkInfoDialog->m_ChoiceWaypointRangeRingsNumber
1754 ->GetSelection())
1755 : _("Don't use"));
1756 RangRingsCB = new wxCheckBox(this, wxID_ANY, _("Range rings"));
1757 fgSizer1->Add(RangRingsCB, 0, wxALL, 5);
1758 stRR = new wxStaticText(this, wxID_ANY, _T("[") + s + _T("]"),
1759 wxDefaultPosition, wxDefaultSize, 0);
1760 stRR->Wrap(-1);
1761 fgSizer1->Add(stRR, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1762
1763 s = (g_pMarkInfoDialog->m_textArrivalRadius->GetValue());
1764 ArrivalRCB = new wxCheckBox(this, wxID_ANY, _("Arrival radius"));
1765 fgSizer1->Add(ArrivalRCB, 0, wxALL, 5);
1766 stArrivalR = new wxStaticText(
1767 this, wxID_ANY,
1768 wxString::Format(_T("[%s %s]"), s.c_str(), getUsrDistanceUnit().c_str()),
1769 wxDefaultPosition, wxDefaultSize, 0);
1770 stArrivalR->Wrap(-1);
1771 fgSizer1->Add(stArrivalR, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL,
1772 5);
1773
1774 s = (g_pMarkInfoDialog->m_checkBoxScaMin->GetValue()
1775 ? _("Show only if") + _T(" < ") +
1776 g_pMarkInfoDialog->m_textScaMin->GetValue()
1777 : _("Show always"));
1778 ScaleCB = new wxCheckBox(this, wxID_ANY, _("Show only at scale"));
1779 fgSizer1->Add(ScaleCB, 0, wxALL, 5);
1780 stScale = new wxStaticText(this, wxID_ANY, _T("[") + s + _T("]"),
1781 wxDefaultPosition, wxDefaultSize, 0);
1782 stScale->Wrap(-1);
1783 fgSizer1->Add(stScale, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1784
1785 bSizer1->Add(fgSizer1, 0, wxALL | wxEXPAND, 5);
1786
1787 StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
1788 StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK));
1789 StdDialogButtonSizer1->AddButton(
1790 new wxButton(this, wxID_CANCEL, _("Cancel")));
1791 StdDialogButtonSizer1->Realize();
1792 bSizer1->Add(StdDialogButtonSizer1, 0, wxALL | wxEXPAND, 5);
1793
1794 SetSizer(bSizer1);
1795 Fit();
1796 Layout();
1797
1798#ifdef __ANDROID__
1799 SetSize(parent->GetSize());
1800#endif
1801
1802 Center();
1803}
1804
1805void MarkInfoDlg::ShowTidesBtnClicked(wxCommandEvent& event) {
1806 if (m_comboBoxTideStation->GetSelection() < 1) {
1807 return;
1808 }
1809 IDX_entry* pIDX = (IDX_entry*)ptcmgr->GetIDX_entry(
1810 ptcmgr->GetStationIDXbyName(m_comboBoxTideStation->GetStringSelection(),
1811 fromDMM(m_textLatitude->GetValue()),
1812 fromDMM(m_textLongitude->GetValue())));
1813 if (pIDX) {
1814 TCWin* pCwin = new TCWin(gFrame->GetPrimaryCanvas(), 0, 0, pIDX);
1815 pCwin->Show();
1816 } else {
1817 wxString msg(_("Tide Station not found"));
1818 msg += _T(":\n");
1819 msg += m_comboBoxTideStation->GetStringSelection();
1820 OCPNMessageBox(NULL, msg, _("OpenCPN Info"), wxOK | wxCENTER, 10);
1821 }
1822}
Grid layout with 2 columns for form labels and fields.
Definition form_grid.h:28
Represents an index entry for tidal and current data.
Definition IDX_entry.h:49
Class LinkPropImpl.
Definition LinkPropDlg.h:89
Dialog for displaying and editing waypoint properties.
Definition MarkInfo.h:212
Main application frame.
Definition ocpn_frame.h:136
Custom combobox for selecting waypoint icons.
Definition MarkInfo.h:159
Provides platform-specific support utilities for OpenCPN.
Definition route.h:75
Dialog for saving default waypoint properties.
Definition MarkInfo.h:405
Definition tcmgr.h:86
Definition TCWin.h:46
Text field with validator and error handler.
Definition field_text.h:38
void OnTextChanged(wxCommandEvent &event)
Text changed event handler.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:54
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
Definition gui_lib.cpp:83
General purpose GUI support.
GUI library utils and events.