25 #include <wx/wxprec.h>
26 #include <wx/wxhtml.h>
28 #include "S57QueryDialog.h"
31 #include <wx/textwrapper.h>
32 #include "color_types.h"
34 extern ColorScheme global_color_scheme;
36 extern int g_S57_dialog_sx;
37 extern int g_S57_dialog_sy;
38 extern int g_S57_extradialog_sx;
39 extern int g_S57_extradialog_sy;
40 extern bool g_bresponsive;
47 Wrap(win, text, widthMax);
49 wxString
const& GetWrapped()
const {
return m_wrapped; }
50 int const GetLineCount()
const {
return m_lineCount; }
51 wxArrayString GetLineArray() {
return m_array; }
54 virtual void OnOutputLine(
const wxString& line) {
58 virtual void OnNewLine() {
66 wxArrayString m_array;
72 EVT_SIZE(S57QueryDialog::OnSize)
73 EVT_CLOSE(S57QueryDialog::OnClose)
74 EVT_HTML_LINK_CLICKED(wxID_ANY, S57QueryDialog::OnHtmlLinkClicked)
75 EVT_CHAR_HOOK(S57QueryDialog::OnKey)
81 const wxString& caption,
const wxPoint& pos,
82 const wxSize& size,
long style) {
84 Create(parent,
id, caption, pos, size, style);
87 S57QueryDialog::~S57QueryDialog() {
88 g_S57_dialog_sx = GetSize().x;
89 g_S57_dialog_sy = GetSize().y;
90 m_btnOK->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED,
91 wxCommandEventHandler(S57QueryDialog::OnOKClick), NULL,
95 void S57QueryDialog::Init() {}
97 bool S57QueryDialog::Create(wxWindow* parent, wxWindowID
id,
98 const wxString& caption,
const wxPoint& pos,
99 const wxSize& size,
long style) {
100 long wstyle = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT;
102 if (!wxFrame::Create(parent,
id, caption, pos, size, wstyle))
return false;
104 wxFont* dFont = GetOCPNScaledFont(_(
"ObjectQuery"));
127 void S57QueryDialog::RecalculateSize(
void) {
130 wxSize esize = m_createsize;
132 esize = GetParent()->GetClientSize();
135 wxSize dsize = GetParent()->GetClientSize();
136 esize.y = wxMin(esize.y, dsize.y - (1 * GetCharHeight()));
137 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
140 wxSize fsize = GetSize();
141 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
142 fsize.x = wxMin(fsize.x, dsize.x - (2 * GetCharHeight()));
148 void S57QueryDialog::CreateControls() {
149 wxBoxSizer* topSizer =
new wxBoxSizer(wxVERTICAL);
152 long style = wxHW_SCROLLBAR_AUTO;
153 if (g_btouch) style |= wxHW_NO_SELECTION;
156 new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
158 m_phtml->SetBorders(5);
160 m_phtml->SetMinSize(wxSize(100, 100));
161 topSizer->Add(m_phtml, 1, wxBOTTOM | wxEXPAND, 10);
163 topSizer->FitInside(
this);
165 m_btnOK =
new wxButton(
this, wxID_OK);
166 m_btnOK->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
167 wxCommandEventHandler(S57QueryDialog::OnOKClick), NULL,
169 topSizer->Add(m_btnOK, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 5);
172 void S57QueryDialog::SetColorScheme(
void) {
174 wxColor bg = GetBackgroundColour();
175 m_phtml->SetBackgroundColour(bg);
182 wxBitmap tbm(GetSize().x, GetSize().y, -1);
185 tdc.SetBackground(bg);
187 m_phtml->SetBackgroundImage(tbm);
191 void S57QueryDialog::OnKey(wxKeyEvent& ke) {
192 if (ke.GetKeyCode() == WXK_ESCAPE)
198 void S57QueryDialog::SetHTMLPage(wxString& page) {
199 m_phtml->SetPage(page);
203 void S57QueryDialog::OnSize(wxSizeEvent& event) {
204 g_S57_dialog_sx = GetSize().x;
205 g_S57_dialog_sy = GetSize().y;
206 wxFrame::OnSize(event);
209 void S57QueryDialog::OnClose(wxCloseEvent& event) {
210 g_S57_dialog_sx = GetSize().x;
211 g_S57_dialog_sy = GetSize().y;
213 g_pObjectQueryDialog = NULL;
216 void S57QueryDialog::OnHtmlLinkClicked(wxHtmlLinkEvent& event) {
218 GetParent(), wxID_ANY, _(
"Extra Object Info"),
219 wxPoint(GetPosition().x + 20, GetPosition().y + 20),
220 wxSize(g_S57_extradialog_sx, g_S57_extradialog_sy));
223 wxFileName filen(event.GetLinkInfo().GetHref());
224 wxString Extensions = wxString(
"txt,html,rtf");
226 if (Extensions.Find(filen.GetExt().Lower()) == wxNOT_FOUND)
227 ExtraObjInfoDlg->m_phtml->LoadPage(event.GetLinkInfo().GetHref());
229 wxTextFile txf(filen.GetFullPath());
233 str = txf.GetFirstLine();
236 m_phtml->GetSize().x * 9 / 10);
237 contents += wrapper.GetWrapped();
240 str = txf.GetNextLine();
241 }
while (!txf.Eof());
243 ExtraObjInfoDlg->m_phtml->SetPage(contents);
247 ExtraObjInfoDlg->SetColorScheme();
249 #ifdef __OCPN__ANDROID__
250 ExtraObjInfoDlg->SetSize(GetSize().x - 40, GetSize().y - 40);
253 ExtraObjInfoDlg->Show(
true);
261 EVT_SIZE(S57ExtraQueryInfoDlg::OnSize)
262 EVT_CLOSE(S57ExtraQueryInfoDlg::OnClose)
268 const wxString& caption,
270 const wxSize& size,
long style) {
272 Create(parent,
id, caption, pos, size, style);
274 bool S57ExtraQueryInfoDlg::Create(wxWindow* parent, wxWindowID
id,
275 const wxString& caption,
const wxPoint& pos,
276 const wxSize& size,
long style) {
277 long wstyle = wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT;
279 if (!wxFrame::Create(parent,
id, caption, pos, size, wstyle))
return false;
281 wxFont* dFont = GetOCPNScaledFont(_(
"ObjectQuery"));
289 S57ExtraQueryInfoDlg::~S57ExtraQueryInfoDlg() {
290 g_S57_extradialog_sx = GetSize().x;
291 g_S57_extradialog_sy = GetSize().y;
294 void S57ExtraQueryInfoDlg::OnSize(wxSizeEvent& event) {
295 g_S57_extradialog_sx = GetSize().x;
296 g_S57_extradialog_sy = GetSize().y;
297 wxFrame::OnSize(event);
300 void S57ExtraQueryInfoDlg::OnClose(wxCloseEvent& event) {
301 g_S57_extradialog_sx = GetSize().x;
302 g_S57_extradialog_sy = GetSize().y;
S57QueryDialog()
Constructors.
General purpose GUI support.