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