25#include <wx/artprov.h>
28#include <wx/statbmp.h>
33#include "OCPNPlatform.h"
38#include "androidUTIL.h"
44extern int g_GUIScaleFactor;
46CopyableText::CopyableText(wxWindow* parent,
const char* text)
47 : wxTextCtrl(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize,
50 wxStaticText tmp(parent, wxID_ANY, text);
51 SetBackgroundColour(tmp.GetBackgroundColour());
55 wxFont* dFont = FontMgr::Get().
GetFont(item, default_size);
56 int req_size = dFont->GetPointSize();
60 double scaled_font_size = dFont->GetPointSize();
63 double points_per_mm =
64 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
65 double min_scaled_font_size =
67 int nscaled_font_size =
68 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
70 if (req_size >= nscaled_font_size)
74 nscaled_font_size, dFont->GetFamily(), dFont->GetStyle(),
84 wxFont* dFont = FontMgr::Get().
GetFont(item, 0);
85 int req_size = dFont->GetPointSize();
86 wxFont qFont = *dFont;
89 double postmult = exp(g_GUIScaleFactor * (0.693 / 5.0));
90 double scaled_font_size = dFont->GetPointSize() * postmult;
92 double points_per_mm =
93 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
94 double min_scaled_font_size =
96 int nscaled_font_size =
97 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
104 qFont.SetPointSize(nscaled_font_size);
110int OCPNMessageBox(wxWindow* parent,
const wxString& message,
111 const wxString& caption,
int style,
int timeout_sec,
int x,
113#ifdef __OCPN__ANDROID__
114 androidDisableRotation();
115 int style_mod = style;
117 auto dlg =
new wxMessageDialog(parent, message, caption, style_mod);
118 int ret = dlg->ShowModal();
119 qDebug() <<
"OCPNMB-1 ret" << ret;
124 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
128 androidEnableRotation();
129 qDebug() <<
"OCPNMB-2 ret" << ret;
137 ret = tbox.GetRetVal();
144EVT_BUTTON(wxID_YES, OCPNMessageDialog::OnYes)
145EVT_BUTTON(wxID_NO, OCPNMessageDialog::OnNo)
146EVT_BUTTON(wxID_CANCEL, OCPNMessageDialog::OnCancel)
147EVT_CLOSE(OCPNMessageDialog::OnClose)
151 const wxString& caption,
long style,
153 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
154 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
159 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
161 wxBoxSizer* icon_text =
new wxBoxSizer(wxHORIZONTAL);
165 if (style & wxICON_MASK) {
167 switch (style & wxICON_MASK) {
169 wxFAIL_MSG(_T(
"incorrect log style"));
173 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
176 case wxICON_INFORMATION:
177 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
181 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
184 case wxICON_QUESTION:
185 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
188 wxStaticBitmap* icon =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
189 icon_text->Add(icon, 0, wxCENTER);
195 icon_text->Add(CreateTextSizer(message), 0, wxALIGN_CENTER | wxLEFT, 10);
197 topsizer->Add(icon_text, 1, wxCENTER | wxLEFT | wxRIGHT | wxTOP, 10);
201 int AllButtonSizerFlags =
202 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
203 int center_flag = wxEXPAND;
204 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
205 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
206 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
211 topsizer->SetSizeHints(
this);
213 wxSize size(GetSize());
214 if (size.x < size.y * 3 / 2) {
215 size.x = size.y * 3 / 2;
219 Centre(wxBOTH | wxCENTER_FRAME);
222void OCPNMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
223 SetReturnCode(wxID_YES);
227void OCPNMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
228 SetReturnCode(wxID_NO);
232void OCPNMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
235 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
236 SetReturnCode(wxID_CANCEL);
237 EndModal(wxID_CANCEL);
241void OCPNMessageDialog::OnClose(wxCloseEvent& event) {
242 SetReturnCode(wxID_CANCEL);
243 EndModal(wxID_CANCEL);
247EVT_TIMER(-1, TimedMessageBox::OnTimer)
251 const wxString& caption,
long style,
252 int timeout_sec, const wxPoint& pos) {
254 m_timer.SetOwner(
this, -1);
256 if (timeout_sec > 0) m_timer.Start(timeout_sec * 1000, wxTIMER_ONE_SHOT);
261 int ret = dlg->GetReturnCode();
264 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
272TimedMessageBox::~TimedMessageBox() {}
274void TimedMessageBox::OnTimer(wxTimerEvent& evt) {
275 if (dlg) dlg->EndModal(wxID_CANCEL);
279EVT_BUTTON(wxID_YES, OCPN_TimedHTMLMessageDialog::OnYes)
280EVT_BUTTON(wxID_NO, OCPN_TimedHTMLMessageDialog::OnNo)
281EVT_BUTTON(wxID_CANCEL, OCPN_TimedHTMLMessageDialog::OnCancel)
282EVT_CLOSE(OCPN_TimedHTMLMessageDialog::OnClose)
283EVT_TIMER(-1, OCPN_TimedHTMLMessageDialog::OnTimer)
284EVT_HTML_LINK_CLICKED(wxID_ANY, OCPN_TimedHTMLMessageDialog::OnHtmlLinkClicked)
288 wxWindow* parent, const wxString& message, const wxString& caption,
289 int tSeconds,
long style,
bool bFixedFont, const wxPoint& pos)
290 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
291 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
294 wxFont* dFont = GetOCPNScaledFont_PlugIn(_(
"Dialog"));
295 double font_size = dFont->GetPointSize();
297 wxTheFontList->FindOrCreateFont(font_size, wxFONTFAMILY_TELETYPE,
298 dFont->GetStyle(), dFont->GetWeight());
302 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
304 msgWindow =
new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
305 wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION);
306 msgWindow->SetBorders(30);
308 topsizer->Add(msgWindow, 1, wxEXPAND, 5);
313 wxCharBuffer buf = html.ToUTF8();
315 msgWindow->SetPage(html);
318 int AllButtonSizerFlags =
319 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
320 int center_flag = wxEXPAND;
321 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
322 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
323 if (sizerBtn) topsizer->Add(sizerBtn, wxSizerFlags().Border().Expand());
337 msgWindow->SetBackgroundColour(GetBackgroundColour());
339 m_timer.SetOwner(
this, -1);
341 if (tSeconds > 0) m_timer.Start(tSeconds * 1000, wxTIMER_ONE_SHOT);
344void OCPN_TimedHTMLMessageDialog::RecalculateSize(
void) {
346 esize.x = GetCharWidth() * 60;
348 sx = g_monitor_info[g_current_monitor].width;
349 esize.x = wxMin(esize.x, sx * 6 / 10);
351 SetClientSize(esize);
353 int height1 = msgWindow->GetInternalRepresentation()->GetHeight();
356 wxMin(::wxGetDisplaySize().y - 100, height1 + 70);
358 SetClientSize(wxSize(
359 esize.x, client_size_y));
362void OCPN_TimedHTMLMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
363 SetReturnCode(wxID_YES);
370void OCPN_TimedHTMLMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
371 SetReturnCode(wxID_NO);
378void OCPN_TimedHTMLMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
381 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
382 SetReturnCode(wxID_CANCEL);
383 EndModal(wxID_CANCEL);
387void OCPN_TimedHTMLMessageDialog::OnClose(wxCloseEvent& event) {
388 SetReturnCode(wxID_CANCEL);
390 EndModal(wxID_CANCEL);
395void OCPN_TimedHTMLMessageDialog::OnTimer(wxTimerEvent& evt) {
397 EndModal(m_style & wxNO_DEFAULT ? wxID_NO : wxID_YES);
405EVT_PAINT(TimedPopupWin::OnPaint)
406EVT_TIMER(POPUP_TIMER, TimedPopupWin::OnTimer)
412 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER) {
415 m_timer_timeout.SetOwner(
this, POPUP_TIMER);
416 m_timeout_sec = timeout;
421TimedPopupWin::~TimedPopupWin() {
delete m_pbm; }
422void TimedPopupWin::OnTimer(wxTimerEvent& event) {
423 if (IsShown()) Hide();
426void TimedPopupWin::SetBitmap(wxBitmap& bmp) {
428 m_pbm =
new wxBitmap(bmp);
431 if (m_timeout_sec > 0)
432 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
435void TimedPopupWin::OnPaint(wxPaintEvent& event) {
437 GetClientSize(&width, &height);
441 mdc.SelectObject(*m_pbm);
442 dc.Blit(0, 0, width, height, &mdc, 0, 0);
wxFont * FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
Creates or finds a matching font in the font cache.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
bool g_bresponsive
Flag to control adaptive UI scaling.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
General purpose GUI support.
PlugIn Object Definition/API.