OpenCPN Partial API docs
Loading...
Searching...
No Matches
s57_query_dlg.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2013 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include <wx/wxprec.h>
25#include <wx/arrstr.h>
26#include <wx/gdicmn.h>
27#include <wx/textwrapper.h>
28#include <wx/wxhtml.h>
29
30#include "model/config_vars.h"
31#include "s57_query_dlg.h"
32#include "navutil.h"
33#include "gui_lib.h"
34#include "color_types.h"
35#include "viewport.h"
36
38// Private class implementations
39class MessageHardBreakWrapper : public wxTextWrapper {
40public:
41 MessageHardBreakWrapper(wxWindow* win, const wxString& text, int widthMax) {
42 m_lineCount = 0;
43 Wrap(win, text, widthMax);
44 }
45 wxString const& GetWrapped() const { return m_wrapped; }
46 int const GetLineCount() const { return m_lineCount; }
47 wxArrayString GetLineArray() { return m_array; }
48
49protected:
50 virtual void OnOutputLine(const wxString& line) {
51 m_wrapped += line;
52 m_array.Add(line);
53 }
54 virtual void OnNewLine() {
55 m_wrapped += '\n';
56 m_lineCount++;
57 }
58
59private:
60 wxString m_wrapped;
61 int m_lineCount;
62 wxArrayString m_array;
63};
64
65IMPLEMENT_CLASS(S57QueryDialog, wxFrame)
66// S57QueryDialog event table definition
67BEGIN_EVENT_TABLE(S57QueryDialog, wxFrame) // ws wxDialog
68EVT_SIZE(S57QueryDialog::OnSize)
69EVT_CLOSE(S57QueryDialog::OnClose)
70EVT_HTML_LINK_CLICKED(wxID_ANY, S57QueryDialog::OnHtmlLinkClicked)
71EVT_CHAR_HOOK(S57QueryDialog::OnKey)
72END_EVENT_TABLE()
73
75
76S57QueryDialog::S57QueryDialog(wxWindow* parent, wxWindowID id,
77 const wxString& caption, const wxPoint& pos,
78 const wxSize& size, long style) {
79 Init();
80 Create(parent, id, caption, pos, size, style);
81}
82
83S57QueryDialog::~S57QueryDialog() {
84 g_S57_dialog_sx = GetSize().x;
85 g_S57_dialog_sy = GetSize().y;
86 m_btnOK->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED,
87 wxCommandEventHandler(S57QueryDialog::OnOKClick), NULL,
88 this);
89}
90
91void S57QueryDialog::Init() {}
92
93bool S57QueryDialog::Create(wxWindow* parent, wxWindowID id,
94 const wxString& caption, const wxPoint& pos,
95 const wxSize& size, long style) {
96 long wstyle = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT;
97
98 if (!wxFrame::Create(parent, id, caption, pos, size, wstyle)) return false;
99
100 wxFont* dFont = GetOCPNScaledFont(_("ObjectQuery"));
101
102 SetFont(*dFont);
103 CreateControls();
104
105 m_createsize = size;
106 /*
107 // This ensures that the dialog cannot be sized smaller
108 // than the minimum size
109 GetSizer()->SetSizeHints( this );
110
111 // Explicitely set the size
112 SetSize( size );
113
114 // Centre the dialog on the parent or (if none) screen
115 Centre();
116 */
117 RecalculateSize();
118
119 DimeControl(this);
120 return true;
121}
122
123void S57QueryDialog::RecalculateSize() {
124 // Make an estimate of the dialog size, without scrollbars showing
125
126 wxSize esize = m_createsize;
127 if (g_bresponsive) {
128 esize = GetParent()->GetClientSize();
129 }
130
131 wxSize dsize = GetParent()->GetClientSize();
132 esize.y = wxMin(esize.y, dsize.y - (1 * GetCharHeight()));
133 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
134 SetSize(esize);
135
136 wxSize fsize = GetSize();
137 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
138 fsize.x = wxMin(fsize.x, dsize.x - (2 * GetCharHeight()));
139 SetSize(fsize);
140
141 Centre();
142}
143
144void S57QueryDialog::CreateControls() {
145 wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
146 SetSizer(topSizer);
147
148 long style = wxHW_SCROLLBAR_AUTO;
149 if (g_btouch) style |= wxHW_NO_SELECTION;
150
151 m_phtml =
152 new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
153
154 m_phtml->SetBorders(5);
155
156 m_phtml->SetMinSize(wxSize(100, 100)); // this will constrain the dialog, too
157 topSizer->Add(m_phtml, 1, wxBOTTOM | wxEXPAND, 10);
158
159 topSizer->FitInside(this);
160
161 m_btnOK = new wxButton(this, wxID_OK);
162 m_btnOK->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
163 wxCommandEventHandler(S57QueryDialog::OnOKClick), NULL,
164 this);
165 topSizer->Add(m_btnOK, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
166}
167
168void S57QueryDialog::SetColorScheme() {
169 DimeControl(this);
170 wxColor bg = GetBackgroundColour();
171 m_phtml->SetBackgroundColour(bg);
172 SetBackgroundColour(
173 bg); // This looks like non-sense, but is needed for __WXGTK__
174 // to get colours to propagate down the control's family tree.
175
176#ifdef __WXQT__
177 // wxQT has some trouble clearing the background of HTML window...
178 wxBitmap tbm(GetSize().x, GetSize().y, -1);
179 wxMemoryDC tdc(tbm);
180 // wxColour cback = GetGlobalColor( "YELO1" );
181 tdc.SetBackground(bg);
182 tdc.Clear();
183 m_phtml->SetBackgroundImage(tbm);
184#endif
185}
186
187void S57QueryDialog::OnKey(wxKeyEvent& ke) {
188 if (ke.GetKeyCode() == WXK_ESCAPE)
189 Close(true);
190 else
191 ke.Skip();
192}
193
194void S57QueryDialog::SetHTMLPage(wxString& page) {
195 m_phtml->SetPage(page);
196 SetColorScheme();
197}
198
199void S57QueryDialog::OnSize(wxSizeEvent& event) {
200 g_S57_dialog_sx = GetSize().x;
201 g_S57_dialog_sy = GetSize().y;
202 wxFrame::OnSize(event);
203}
204
205void S57QueryDialog::OnClose(wxCloseEvent& event) {
206 g_S57_dialog_sx = GetSize().x;
207 g_S57_dialog_sy = GetSize().y;
208 Destroy();
210}
211
212void S57QueryDialog::OnHtmlLinkClicked(wxHtmlLinkEvent& event) {
213 S57ExtraQueryInfoDlg* ExtraObjInfoDlg = new S57ExtraQueryInfoDlg(
214 GetParent(), wxID_ANY, _("Extra Object Info"),
215 wxPoint(GetPosition().x + 20, GetPosition().y + 20),
216 wxSize(g_S57_extradialog_sx, g_S57_extradialog_sy));
217
218 // Check te kind of file, load text files serial and pictures direct
219 wxFileName filen(event.GetLinkInfo().GetHref());
220 wxString Extensions = wxString("txt,html,rtf");
221
222 if (Extensions.Find(filen.GetExt().Lower()) == wxNOT_FOUND)
223 ExtraObjInfoDlg->m_phtml->LoadPage(event.GetLinkInfo().GetHref());
224 else {
225 wxTextFile txf(filen.GetFullPath());
226 if (txf.Open()) {
227 wxString contents;
228 if (filen.GetExt().Lower() == "txt") {
229 contents +=
230 "<font color="
231 "" +
232 GetForegroundColour().GetAsString(wxC2S_HTML_SYNTAX) +
233 ""
234 ">";
235 }
236 wxString str;
237 str = txf.GetFirstLine();
238 do {
239 MessageHardBreakWrapper wrapper(ExtraObjInfoDlg->m_phtml, str,
240 m_phtml->GetSize().x * 9 / 10);
241 contents += wrapper.GetWrapped();
242 contents += "<br>";
243
244 str = txf.GetNextLine();
245 } while (!txf.Eof());
246 if (filen.GetExt().Lower() == "txt") {
247 contents += "</font>";
248 }
249
250 ExtraObjInfoDlg->m_phtml->SetPage(contents);
251 }
252 }
253
254 ExtraObjInfoDlg->SetColorScheme();
255
256#ifdef __ANDROID__
257 ExtraObjInfoDlg->SetSize(GetSize().x - 40, GetSize().y - 40);
258#endif
259
260 ExtraObjInfoDlg->Show(true);
261}
262
264
265IMPLEMENT_CLASS(S57ExtraQueryInfoDlg, wxFrame)
266// S57QueryDialog event table definition
267BEGIN_EVENT_TABLE(S57ExtraQueryInfoDlg, wxFrame) // ws wxDialog
268EVT_SIZE(S57ExtraQueryInfoDlg::OnSize)
269EVT_CLOSE(S57ExtraQueryInfoDlg::OnClose)
270END_EVENT_TABLE()
271
273
274S57ExtraQueryInfoDlg::S57ExtraQueryInfoDlg(wxWindow* parent, wxWindowID id,
275 const wxString& caption,
276 const wxPoint& pos,
277 const wxSize& size, long style) {
278 Init();
279 Create(parent, id, caption, pos, size, style);
280}
281bool S57ExtraQueryInfoDlg::Create(wxWindow* parent, wxWindowID id,
282 const wxString& caption, const wxPoint& pos,
283 const wxSize& size, long style) {
284 long wstyle = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT;
285
286 if (!wxFrame::Create(parent, id, caption, pos, size, wstyle)) return false;
287
288 wxFont* dFont = GetOCPNScaledFont(_("ObjectQuery"));
289
290 SetFont(*dFont);
291 CreateControls();
292
293 DimeControl(this);
294 return true;
295}
296S57ExtraQueryInfoDlg::~S57ExtraQueryInfoDlg() {
297 g_S57_extradialog_sx = GetSize().x;
298 g_S57_extradialog_sy = GetSize().y;
299}
300
301void S57ExtraQueryInfoDlg::OnSize(wxSizeEvent& event) {
302 g_S57_extradialog_sx = GetSize().x;
303 g_S57_extradialog_sy = GetSize().y;
304 wxFrame::OnSize(event);
305}
306
307void S57ExtraQueryInfoDlg::OnClose(wxCloseEvent& event) {
308 g_S57_extradialog_sx = GetSize().x;
309 g_S57_extradialog_sy = GetSize().y;
310 Destroy();
311}
Dialog for displaying extra query information for S57 objects.
S57ExtraQueryInfoDlg()
Constructors.
Dialog for displaying query results of S57 objects.
S57QueryDialog()
Constructors.
Global variables stored in configuration file.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:59
General purpose GUI support.
Utility functions.
S57QueryDialog * g_pObjectQueryDialog
Global instance.
S57 object query result window.
S57QueryDialog * g_pObjectQueryDialog
Global instance.
Geographic projection and coordinate transformations.