26#include <wx/artprov.h>
29#include <wx/statbmp.h>
34#include "OCPNPlatform.h"
35#include "ocpn_plugin.h"
38#include "androidUTIL.h"
42extern bool g_bresponsive;
44extern int g_GUIScaleFactor;
46wxFont* GetOCPNScaledFont(wxString item,
int default_size) {
47 wxFont* dFont = FontMgr::Get().GetFont(item, default_size);
48 int req_size = dFont->GetPointSize();
52 double scaled_font_size = dFont->GetPointSize();
55 double points_per_mm =
56 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
57 double min_scaled_font_size =
59 int nscaled_font_size =
60 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
62 if (req_size >= nscaled_font_size)
65 wxFont* qFont = FontMgr::Get().FindOrCreateFont(
66 nscaled_font_size, dFont->GetFamily(), dFont->GetStyle(),
75wxFont GetOCPNGUIScaledFont(wxString item) {
76 wxFont* dFont = FontMgr::Get().GetFont(item, 0);
77 int req_size = dFont->GetPointSize();
78 wxFont qFont = *dFont;
81 double postmult = exp(g_GUIScaleFactor * (0.693 / 5.0));
82 double scaled_font_size = dFont->GetPointSize() * postmult;
84 double points_per_mm =
85 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
86 double min_scaled_font_size =
88 int nscaled_font_size =
89 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
96 qFont.SetPointSize(nscaled_font_size);
102int OCPNMessageBox( wxWindow *parent,
const wxString& message,
const wxString& caption,
int style,
103 int timeout_sec,
int x,
int y )
105#ifdef __OCPN__ANDROID__
106 androidDisableRotation();
107 int style_mod = style;
109 auto dlg =
new wxMessageDialog(parent, message, caption, style_mod);
110 int ret = dlg->ShowModal();
111 qDebug() <<
"OCPNMB-1 ret" << ret;
116 if( ((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK))
121 androidEnableRotation();
122 qDebug() <<
"OCPNMB-2 ret" << ret;
128 TimedMessageBox tbox(parent, message, caption, style, timeout_sec, wxPoint( x, y ) );
129 ret = tbox.GetRetVal() ;
137EVT_BUTTON(wxID_YES, OCPNMessageDialog::OnYes)
138EVT_BUTTON(wxID_NO, OCPNMessageDialog::OnNo)
139EVT_BUTTON(wxID_CANCEL, OCPNMessageDialog::OnCancel)
140EVT_CLOSE(OCPNMessageDialog::OnClose)
144 const wxString& caption,
long style,
146 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
147 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
149 wxFont* qFont = GetOCPNScaledFont(_(
"Dialog"));
152 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
154 wxBoxSizer* icon_text =
new wxBoxSizer(wxHORIZONTAL);
158 if (style & wxICON_MASK) {
160 switch (style & wxICON_MASK) {
162 wxFAIL_MSG(_T(
"incorrect log style"));
166 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
169 case wxICON_INFORMATION:
170 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
174 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
177 case wxICON_QUESTION:
178 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
181 wxStaticBitmap* icon =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
182 icon_text->Add(icon, 0, wxCENTER);
188 icon_text->Add(CreateTextSizer(message), 0, wxALIGN_CENTER | wxLEFT, 10);
190 topsizer->Add(icon_text, 1, wxCENTER | wxLEFT | wxRIGHT | wxTOP, 10);
194 int AllButtonSizerFlags =
195 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
196 int center_flag = wxEXPAND;
197 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
198 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
199 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
204 topsizer->SetSizeHints(
this);
206 wxSize size(GetSize());
207 if (size.x < size.y * 3 / 2) {
208 size.x = size.y * 3 / 2;
212 Centre(wxBOTH | wxCENTER_FRAME);
215void OCPNMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
216 SetReturnCode(wxID_YES);
220void OCPNMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
221 SetReturnCode(wxID_NO);
225void OCPNMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
228 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
229 SetReturnCode(wxID_CANCEL);
230 EndModal(wxID_CANCEL);
234void OCPNMessageDialog::OnClose(wxCloseEvent& event) {
235 SetReturnCode(wxID_CANCEL);
236 EndModal(wxID_CANCEL);
240EVT_TIMER(-1, TimedMessageBox::OnTimer)
244 const wxString& caption,
long style,
245 int timeout_sec, const wxPoint& pos) {
247 m_timer.SetOwner(
this, -1);
249 if (timeout_sec > 0) m_timer.Start(timeout_sec * 1000, wxTIMER_ONE_SHOT);
254 int ret = dlg->GetReturnCode();
257 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
265TimedMessageBox::~TimedMessageBox() {}
267void TimedMessageBox::OnTimer(wxTimerEvent& evt) {
268 if (dlg) dlg->EndModal(wxID_CANCEL);
272EVT_BUTTON(wxID_YES, OCPN_TimedHTMLMessageDialog::OnYes)
273EVT_BUTTON(wxID_NO, OCPN_TimedHTMLMessageDialog::OnNo)
274EVT_BUTTON(wxID_CANCEL, OCPN_TimedHTMLMessageDialog::OnCancel)
275EVT_CLOSE(OCPN_TimedHTMLMessageDialog::OnClose)
276EVT_TIMER(-1, OCPN_TimedHTMLMessageDialog::OnTimer)
280 wxWindow* parent, const wxString& message, const wxString& caption,
281 int tSeconds,
long style,
bool bFixedFont, const wxPoint& pos)
282 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
283 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
286 wxFont* dFont = GetOCPNScaledFont_PlugIn(_(
"Dialog"));
287 double font_size = dFont->GetPointSize();
289 wxTheFontList->FindOrCreateFont(font_size, wxFONTFAMILY_TELETYPE,
290 dFont->GetStyle(), dFont->GetWeight());
294 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
296 msgWindow =
new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
297 wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION);
298 msgWindow->SetBorders(30);
300 topsizer->Add(msgWindow, 1, wxEXPAND, 5);
305 wxCharBuffer buf = html.ToUTF8();
307 msgWindow->SetPage(html);
310 int AllButtonSizerFlags =
311 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
312 int center_flag = wxEXPAND;
313 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
314 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
315 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
329 msgWindow->SetBackgroundColour(GetBackgroundColour());
331 m_timer.SetOwner(
this, -1);
333 if (tSeconds > 0) m_timer.Start(tSeconds * 1000, wxTIMER_ONE_SHOT);
336void OCPN_TimedHTMLMessageDialog::RecalculateSize(
void) {
338 esize.x = GetCharWidth() * 60;
340 ::wxDisplaySize(&sx, &sy);
341 esize.x = wxMin(esize.x, sx * 6 / 10);
343 SetClientSize(esize);
345 int height1 = msgWindow->GetInternalRepresentation()->GetHeight();
348 wxMin(::wxGetDisplaySize().y - 100, height1 + 70);
350 SetClientSize(wxSize(
351 esize.x, client_size_y));
354void OCPN_TimedHTMLMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
355 SetReturnCode(wxID_YES);
362void OCPN_TimedHTMLMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
363 SetReturnCode(wxID_NO);
370void OCPN_TimedHTMLMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
373 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
374 SetReturnCode(wxID_CANCEL);
375 EndModal(wxID_CANCEL);
379void OCPN_TimedHTMLMessageDialog::OnClose(wxCloseEvent& event) {
380 SetReturnCode(wxID_CANCEL);
382 EndModal(wxID_CANCEL);
387void OCPN_TimedHTMLMessageDialog::OnTimer(wxTimerEvent& evt) {
389 EndModal(m_style & wxNO_DEFAULT ? wxID_NO : wxID_YES);
398EVT_PAINT(TimedPopupWin::OnPaint)
399EVT_TIMER(POPUP_TIMER, TimedPopupWin::OnTimer)
405 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER) {
408 m_timer_timeout.SetOwner(
this, POPUP_TIMER);
409 m_timeout_sec = timeout;
414TimedPopupWin::~TimedPopupWin() {
delete m_pbm; }
415void TimedPopupWin::OnTimer(wxTimerEvent &event) {
416 if (IsShown()) Hide();
419void TimedPopupWin::SetBitmap(wxBitmap &bmp) {
421 m_pbm =
new wxBitmap(bmp);
424 if (m_timeout_sec > 0)
425 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
428void TimedPopupWin::OnPaint(wxPaintEvent &event) {
430 GetClientSize(&width, &height);
434 mdc.SelectObject(*m_pbm);
435 dc.Blit(0, 0, width, height, &mdc, 0, 0);