1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  Mark Properties 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 
26 #ifndef _MARKINFO_H_
27 #define _MARKINFO_H_
28 
29 /*!
30  * Includes
31  */
32 #include "wx/listctrl.h"
33 #include "chart1.h"                 // for ColorScheme
34 #include "wx/hyperlink.h"           // toh, 2009.02.08
35 #include <wx/choice.h>
36 #include <wx/tglbtn.h>
37 #include <wx/bmpcbox.h>
38 #include <wx/notebook.h>
39 #include <wx/filesys.h>
40 #include <wx/clrpicker.h>
41 #include <wx/odcombo.h>
42 #include <wx/gbsizer.h>
43 #include <wx/spinctrl.h>
44 #include "LinkPropDlg.h"
45 #include "Hyperlink.h"
46 #include <wx/htmllbox.h>
47 #include <wx/datectrl.h>
48 #include <wx/timectrl.h>
49 #include <wx/dateevt.h>
50 #include <wx/list.h>
51 #include <wx/combobox.h>
52 
53 #include <wx/dialog.h>
54 
55 #ifdef __WXGTK__
56 //wxTimePickerCtrl is completely broken in Gnome based desktop environments as of wxGTK 3.0
57 #include "time_textbox.h"
58 #endif
59 
60 #define ID_WPT_RANGERINGS_NO     7507
61 #define ID_RCLK_MENU_COPY_TEXT   7013
62 #define ID_RCLK_MENU_DELETE      7015
63 #define ID_RCLK_MENU_COPY        7016
64 #define ID_RCLK_MENU_COPY_LL     7017
65 #define ID_RCLK_MENU_PASTE       7018
66 #define ID_RCLK_MENU_PASTE_LL    7019
67 #define ID_RCLK_MENU_DELETE_LINK 7023
68 #define ID_RCLK_MENU_EDIT_LINK   7024
69 #define ID_RCLK_MENU_ADD_LINK    7025
70 
71 #include "tcmgr.h"
72 #include "OCPNPlatform.h"
73 
74 /*!
75  * Forward declarations
76  */
77 
78 class   wxListCtrl;
79 class   Route;
80 class   RoutePoint;
81 class   HyperlinkList;
82 class   OCPNIconCombo;
83 
84 /*!
85  * Control identifiers
86  */
87 
88 ////@begin control identifiers
89 
90 #define ID_MARKPROP 8000
91 #define SYMBOL_MARKPROP_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
92 #define SYMBOL_MARKPROP_TITLE _("Waypoint Properties")
93 #define SYMBOL_MARKPROP_IDNAME ID_MARKPROP
94 #define SYMBOL_MARKPROP_SIZE wxSize(200, 300)
95 #define SYMBOL_MARKPROP_POSITION wxDefaultPosition
96 #define ID_MARKPROP_CANCEL 8001
97 #define ID_MARKPROP_OK 8002
98 #define ID_ICONCTRL 8003
99 #define ID_LATCTRL 8004
100 #define ID_LONCTRL 8005
101 #define ID_SHOWNAMECHECKBOXBASIC 8006
102 #define ID_BITMAPCOMBOCTRL 8007
103 #define ID_NAMECTRL 8008
104 #define wxID_HTMLLIST 8009
105 #define ID_DESCR_CTR_DESC 8010
106 #define ID_DESCR_CTR_BASIC 8011
107 #define ID_BTN_DESC_BASIC 8012
108 #define ID_ETA_DATEPICKERCTRL 8013
109 #define ID_ETA_TIMEPICKERCTRL 8014
110 #define ID_SHOWNAMECHECKBOX_EXT 8015
111 #define ID_CHECKBOX_VIS_EXT 8016
112 #define ID_CHECKBOX_SCAMIN_VIS 8017
113 #define ID_SET_DEFAULT_ICON 8018
114 #define ID_SET_DEFAULT_RANGERINGS 8019
115 #define ID_SET_DEFAULT_ARRIVALRADIUS 8020
116 #define ID_SET_DEFAULT_SCAMIN 8021
117 #define ID_SET_DEFAULT_NAMEVIS 8022
118 #define ID_SET_DEFAULT_ALL 8023
119 #define ID_BTN_LINK_MENU 8024
120 #define ID_DEFAULT 8025
121 #define ID_BTN_SHOW_TIDES 8026
122 
123 ////@end control identifiers
124 
125 /*!
126  * Compatibility
127  */
128 
129 #ifndef wxCLOSE_BOX
130 #define wxCLOSE_BOX 0x1000
131 #endif
132 #ifndef wxFIXED_MINSIZE
133 #define wxFIXED_MINSIZE 0
134 #endif
135 
136 WX_DECLARE_OBJARRAY(wxBitmap,      ArrayOfBitmaps);
137 
138 class SaveDefaultsDialog;
139 
140 /*!
141  * OCPNIconCombo class declaration
142  */
143 
144 class  OCPNIconCombo : public wxOwnerDrawnComboBox
145 {
146 public:
147 
148     OCPNIconCombo(wxWindow* parent, wxWindowID id, const wxString& value = _T(""),
149                   const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
150                   int n = 0, const wxString choices[] = NULL,
151                   long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = _T("OCPNIconCombo") );
152 
153 
154 
155     ~OCPNIconCombo ();
156 
157     void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const;
158     wxCoord OnMeasureItem(size_t item) const;
159     wxCoord OnMeasureItemWidth(size_t item) const;
160 
161     int Append(const wxString& item, wxBitmap bmp);
162     void Clear( void );
163 
164 private:
165     int         itemHeight;
166     ArrayOfBitmaps  bmpArray;
167 
168 };
169 
170 
171 //    LatLonTextCtrl Specification
172 //    We need a derived wxText control for lat/lon input in the MarkProp dialog
173 //    Specifically, we need to catch loss-of-focus events and signal the parent dialog
174 //    to update the mark's lat/lon dynamically.
175 
176 //DECLARE_EVENT_TYPE(EVT_LLCHANGE, -1)
177 extern /*expdecl*/ const wxEventType EVT_LLCHANGE;
178 
179 class LatLonTextCtrl: public wxTextCtrl
180 {
181 //    DECLARE_DYNAMIC_CLASS( LatLonTextCtrl )
182     DECLARE_EVENT_TABLE()
183 
184 public:
185       LatLonTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""),
186             const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
187             long style = 0, const wxValidator& validator = wxDefaultValidator,
188             const wxString& name = wxTextCtrlNameStr);
189 
190       void OnKillFocus(wxFocusEvent &event);
191 
192 
193       wxEvtHandler *m_pParentEventHandler;
194 
195 };
196 
197 ///////////////////////////////////////////////////////////////////////////////
198 /// Class MarkInfoDef
199 ///////////////////////////////////////////////////////////////////////////////
200 class MarkInfoDlg : public wxFrame
201 {
202     DECLARE_EVENT_TABLE()
203     friend class SaveDefaultsDialog;
204 
205 	private:
206         RoutePoint*     m_pRoutePoint;
207         static bool     instanceFlag;
208         int             i_htmlList_item;
209 
210         bool            m_bShowName_save;
211         wxString        m_Name_save;
212         wxString        m_IconName_save;
213         int             m_current_icon_Index;
214         double          m_lat_save;
215         double          m_lon_save;
216         wxString        m_Description_save;
217         HyperlinkList*  m_pMyLinkList;
218         bool            m_bIsVisible_save;
219         bool            m_bUseScaMin_save;
220         int             m_iScaminVal_save;
221         bool            m_bShowWaypointRangeRings_save;
222         int             m_iWaypointRangeRingsNumber_save;
223         float           m_fWaypointRangeRingsStep_save;
224         wxColour        m_wxcWaypointRangeRingsColour_save;
225         double          m_WaypointArrivalRadius_save;
226         float           m_PlannedSpeed_save;
227         wxDateTime      m_ArrETA_save;
228         std::map<double, const IDX_entry*> m_tss;
229         wxString        m_lasttspos;
230 
231 	protected:
232         OCPNIconCombo*          m_bcomboBoxIcon;
233         wxBoxSizer*             bSizerBasicProperties;
234         wxBoxSizer*             bSizerLinks;
235         wxButton*               m_buttonExtDescription;
236         wxButton*               m_buttonLinksMenu;
237         wxBitmapButton*         m_buttonShowTides;
238         wxButton*               DefaultsBtn;
239         wxCheckBox*             m_checkBoxScaMin;
240         wxCheckBox*             m_checkBoxShowName;
241         wxCheckBox*             m_checkBoxShowNameExt;
242         wxCheckBox*             m_checkBoxVisible;
243         wxChoice*               m_choiceWaypointRangeRingsUnits;
244         wxColourPickerCtrl*     m_PickColor;
245         wxCheckBox*             m_cbEtaPresent;
246         wxBoxSizer*             bMainSizer;
247         wxFlexGridSizer*        fSizerBasicProperties;
248         wxFlexGridSizer*        waypointradarGrid;
249         wxFlexGridSizer*        waypointrrSelect;
250         wxGridBagSizer*         bGB_SizerProperties;
251         wxFlexGridSizer*        gbSizerInnerProperties;
252         wxNotebook*             m_notebookProperties;
253         wxObject*               m_contextObject;
254         wxScrolledWindow*       m_panelBasicProperties;
255         wxPanel*                m_panelDescription;
256         wxScrolledWindow*       m_panelExtendedProperties;
257         wxSimpleHtmlListBox*    m_htmlList;
258         wxSize                  m_defaultClientSize;
259         wxChoice*               m_ChoiceWaypointRangeRingsNumber;
260         wxStaticBitmap*         m_bitmapIcon;
261         wxStaticBoxSizer*       sbS_Description;
262         wxStaticBoxSizer*       sbSizerExtProperties;
263         wxStaticBoxSizer*       sbSizerLinks;
264         wxStaticBoxSizer*       sbSizerBasicProperties;
265         wxStaticBoxSizer*       sbRangeRingsExtProperties;
266         wxStaticBoxSizer*       sbSizerDescription;
267         wxStaticText*           m_staticTextArrivalRadius;
268         wxStaticText*           m_staticTextDescription;
269         wxStaticText*           m_staticTextEditEnabled;
270         wxStaticText*           m_staticTextGpx;
271         wxStaticText*           m_staticTextGuid;
272         wxStaticText*           m_staticTextTideStation;
273         wxStaticText*           m_staticTextIcon;
274         wxStaticText*           m_staticTextLatitude;
275         wxStaticText*           m_staticTextLayer;
276         wxStaticText*           m_staticTextLongitude;
277         wxStaticText*           m_staticTextName;
278         wxStaticText*           m_staticTextScaMin;
279         wxStaticText*           m_staticTextShowNameExt;
280         wxStaticText*           m_staticTextRR1;
281         wxStaticText*           m_staticTextRR2;
282         wxStaticText*           m_staticTextRR3;
283         wxStaticText*           m_staticTextRR4;
284         wxStaticText*           m_staticTextArrivalUnits;
285         wxStaticText*           m_staticTextPlSpeed;
286         wxStaticText*           m_staticTextEta;
287         wxStaticText*           m_staticTextPlSpeedUnits;
288         wxStdDialogButtonSizer* m_sdbSizerButtons;
289         wxTextCtrl*             m_textArrivalRadius;
290         wxTextCtrl*             m_textCtrlExtDescription;
291         wxTextCtrl*             m_textCtrlGpx;
292         wxTextCtrl*             m_textCtrlGuid;
293         wxScrolledWindow        *m_scrolledWindowLinks;
294         wxHyperlinkCtrl         *m_hyperlink17;
295         wxMenu                  *m_menuLink;
296         wxToggleButton          *m_toggleBtnEdit;
297         wxButton                *m_buttonAddLink;
298 
299 #ifdef __OCPN__ANDROID__
300         wxChoice*               m_comboBoxTideStation;
301 #else
302         wxComboBox*             m_comboBoxTideStation;
303 #endif
304         wxTextCtrl*             m_textDescription;
305         wxTextCtrl*             m_textLatitude;
306         wxTextCtrl*             m_textLongitude;
307         wxTextCtrl*             m_textName;
308         wxTextCtrl*             m_textScaMin;
309         wxTextCtrl*             m_textWaypointRangeRingsStep;
310         wxTextCtrl*             m_textCtrlPlSpeed;
311         wxBitmap               _img_MUI_settings_svg;
312         wxButton*               m_sdbSizerButtonsCancel;
313         wxButton*               m_sdbSizerButtonsOK;
314 
315 #ifndef __OCPN__ANDROID__
316         wxDatePickerCtrl*       m_EtaDatePickerCtrl;
317 #ifdef __WXGTK__
318         TimeCtrl*               m_EtaTimePickerCtrl;
319 #else
320         wxTimePickerCtrl*       m_EtaTimePickerCtrl;
321 #endif
322 #endif
323         wxArrayString           m_choiceTideChoices;
324         wxBitmap                m_bmTide;
325         int                     m_sizeMetric;
326         wxHyperlinkCtrl         *m_pEditedLink;
327 
328         void initialize_images(void);
329         void OnBitmapCombClick(wxCommandEvent& event);
330         void OnPositionCtlUpdated( wxCommandEvent& event );
331         void OnExtDescriptionClick( wxCommandEvent& event );
332         void OnDescChangedExt( wxCommandEvent& event );
333         void OnDescChangedBasic( wxCommandEvent& event );
334         void OnMarkInfoCancelClick( wxCommandEvent& event );
335         void OnMarkInfoOKClick( wxCommandEvent& event );
336         void OnShowWaypointNameSelectBasic( wxCommandEvent& event );
337         void OnShowWaypointNameSelectExt( wxCommandEvent& event );
338         void OnSelectScaMinExt( wxCommandEvent& event );
339         void OnWptRangeRingsNoChange( wxCommandEvent& event );
340         void OnCopyPasteLatLon( wxCommandEvent& event );
341         void OnWaypointRangeRingSelect( wxCommandEvent& event );
342         void m_htmlListContextMenuBtn( wxCommandEvent &event );
343         void m_htmlListContextMenu( wxMouseEvent &event );
344         void OnRightClickLatLon( wxCommandEvent& event );
345         void OnHtmlLinkClicked(wxHtmlLinkEvent &event);
346         void OnHyperLinkClick( wxHyperlinkEvent &event );
347 
348         void On_html_link_popupmenu_Click( wxCommandEvent& event );
349         void DefautlBtnClicked( wxCommandEvent& event );
350         void OnNotebookPageChanged( wxNotebookEvent& event );
OnTimeChanged(wxDateEvent & event)351         void OnTimeChanged( wxDateEvent& event ) { m_cbEtaPresent->SetValue(true); }
352         void OnTideStationCombobox( wxCommandEvent& event);
353         void OnClose( wxCloseEvent& event );
354         void ShowTidesBtnClicked( wxCommandEvent& event );
355         void OnAddLink( wxCommandEvent& event );
356 
357     public:
358         MarkInfoDlg( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Waypoint Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1, -1 ), long style = wxDEFAULT_FRAME_STYLE|wxFRAME_FLOAT_ON_PARENT|wxMAXIMIZE_BOX|wxRESIZE_BORDER );
359         ~MarkInfoDlg();
360         void Create();
361         void InitialFocus(void);
362         void RecalculateSize( void );
GetRoutePoint(void)363         RoutePoint *GetRoutePoint(void) { return m_pRoutePoint; }
364         void SetColorScheme( ColorScheme cs );
365         void SetRoutePoint( RoutePoint *pRP );
366         void UpdateHtmlList();
SetDialogTitle(const wxString & title)367         void SetDialogTitle(const wxString & title) { SetTitle(title); }
368         bool UpdateProperties( bool positionOnly = false );
369         void ValidateMark(void);
370         bool SaveChanges();
GetSimpleBox()371         wxSimpleHtmlListBox *GetSimpleBox()
372             { return wxDynamicCast(m_htmlList, wxSimpleHtmlListBox); }
373         void OnHtmlCellClicked(wxHtmlCellEvent &event);
374 
375         SaveDefaultsDialog* m_SaveDefaultDlg;
376 
377 };
378 
379 ///////////////////////////////////////////////////////////////////////////////
380 /// Class SaveDefaultsDialog
381 ///////////////////////////////////////////////////////////////////////////////
382 
383 class SaveDefaultsDialog: public wxDialog
384 {
385     friend class MarkInfoDlg;
386 
387 protected:
388     //(*Declarations(SaveDefaultsDialog)
389     wxCheckBox* RangRingsCB;
390     wxCheckBox* ArrivalRCB;
391     wxCheckBox* IconCB;
392     wxCheckBox* NameCB;
393     wxCheckBox* ScaleCB;
394     wxStaticText* stRR;
395     wxStaticText* stArrivalR;
396     wxStaticText* stIcon;
397     wxStaticText* stName;
398     wxStaticText* stScale;
399     wxStaticText* StaticText1;
400     //*)
401 
402 public:
403     SaveDefaultsDialog(MarkInfoDlg* parent);
404 };
405 
406 
407 #endif // _MARKINFO_H_
408