22 #include <wx/artprov.h>
23 #include <wx/dialog.h>
25 #include <wx/statbmp.h>
30 #include "OCPNPlatform.h"
35 #include "androidUTIL.h"
39 extern bool g_bresponsive;
41 extern int g_GUIScaleFactor;
43 CopyableText::CopyableText(wxWindow* parent,
const char* text)
44 : wxTextCtrl(parent, wxID_ANY, text, wxDefaultPosition,
45 wxDefaultSize, wxBORDER_NONE) {
47 wxStaticText tmp(parent, wxID_ANY, text);
48 SetBackgroundColour(tmp.GetBackgroundColour());
52 wxFont* GetOCPNScaledFont(wxString item,
int default_size) {
53 wxFont* dFont = FontMgr::Get().GetFont(item, default_size);
54 int req_size = dFont->GetPointSize();
58 double scaled_font_size = dFont->GetPointSize();
61 double points_per_mm =
62 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
63 double min_scaled_font_size =
65 int nscaled_font_size =
66 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
68 if (req_size >= nscaled_font_size)
71 wxFont* qFont = FontMgr::Get().FindOrCreateFont(
72 nscaled_font_size, dFont->GetFamily(), dFont->GetStyle(),
81 wxFont GetOCPNGUIScaledFont(wxString item) {
82 wxFont* dFont = FontMgr::Get().GetFont(item, 0);
83 int req_size = dFont->GetPointSize();
84 wxFont qFont = *dFont;
87 double postmult = exp(g_GUIScaleFactor * (0.693 / 5.0));
88 double scaled_font_size = dFont->GetPointSize() * postmult;
90 double points_per_mm =
91 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
92 double min_scaled_font_size =
94 int nscaled_font_size =
95 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
102 qFont.SetPointSize(nscaled_font_size);
108 int OCPNMessageBox( wxWindow *parent,
const wxString& message,
const wxString& caption,
int style,
109 int timeout_sec,
int x,
int y )
111 #ifdef __OCPN__ANDROID__
112 androidDisableRotation();
113 int style_mod = style;
115 auto dlg =
new wxMessageDialog(parent, message, caption, style_mod);
116 int ret = dlg->ShowModal();
117 qDebug() <<
"OCPNMB-1 ret" << ret;
122 if( ((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK))
127 androidEnableRotation();
128 qDebug() <<
"OCPNMB-2 ret" << ret;
134 TimedMessageBox tbox(parent, message, caption, style, timeout_sec, wxPoint( x, y ) );
135 ret = tbox.GetRetVal() ;
143 EVT_BUTTON(wxID_YES, OCPNMessageDialog::OnYes)
144 EVT_BUTTON(wxID_NO, OCPNMessageDialog::OnNo)
145 EVT_BUTTON(wxID_CANCEL, OCPNMessageDialog::OnCancel)
146 EVT_CLOSE(OCPNMessageDialog::OnClose)
150 const wxString& caption,
long style,
152 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
153 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
155 wxFont* qFont = GetOCPNScaledFont(_(
"Dialog"));
158 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
160 wxBoxSizer* icon_text =
new wxBoxSizer(wxHORIZONTAL);
164 if (style & wxICON_MASK) {
166 switch (style & wxICON_MASK) {
168 wxFAIL_MSG(_T(
"incorrect log style"));
172 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
175 case wxICON_INFORMATION:
176 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
180 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
183 case wxICON_QUESTION:
184 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
187 wxStaticBitmap* icon =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
188 icon_text->Add(icon, 0, wxCENTER);
194 icon_text->Add(CreateTextSizer(message), 0, wxALIGN_CENTER | wxLEFT, 10);
196 topsizer->Add(icon_text, 1, wxCENTER | wxLEFT | wxRIGHT | wxTOP, 10);
200 int AllButtonSizerFlags =
201 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
202 int center_flag = wxEXPAND;
203 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
204 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
205 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
210 topsizer->SetSizeHints(
this);
212 wxSize size(GetSize());
213 if (size.x < size.y * 3 / 2) {
214 size.x = size.y * 3 / 2;
218 Centre(wxBOTH | wxCENTER_FRAME);
221 void OCPNMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
222 SetReturnCode(wxID_YES);
226 void OCPNMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
227 SetReturnCode(wxID_NO);
231 void OCPNMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
234 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
235 SetReturnCode(wxID_CANCEL);
236 EndModal(wxID_CANCEL);
240 void OCPNMessageDialog::OnClose(wxCloseEvent& event) {
241 SetReturnCode(wxID_CANCEL);
242 EndModal(wxID_CANCEL);
246 EVT_TIMER(-1, TimedMessageBox::OnTimer)
250 const wxString& caption,
long style,
251 int timeout_sec, const wxPoint& pos) {
253 m_timer.SetOwner(
this, -1);
255 if (timeout_sec > 0) m_timer.Start(timeout_sec * 1000, wxTIMER_ONE_SHOT);
260 int ret = dlg->GetReturnCode();
263 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
271 TimedMessageBox::~TimedMessageBox() {}
273 void TimedMessageBox::OnTimer(wxTimerEvent& evt) {
274 if (dlg) dlg->EndModal(wxID_CANCEL);
278 EVT_BUTTON(wxID_YES, OCPN_TimedHTMLMessageDialog::OnYes)
279 EVT_BUTTON(wxID_NO, OCPN_TimedHTMLMessageDialog::OnNo)
280 EVT_BUTTON(wxID_CANCEL, OCPN_TimedHTMLMessageDialog::OnCancel)
281 EVT_CLOSE(OCPN_TimedHTMLMessageDialog::OnClose)
282 EVT_TIMER(-1, OCPN_TimedHTMLMessageDialog::OnTimer)
283 EVT_HTML_LINK_CLICKED( wxID_ANY, OCPN_TimedHTMLMessageDialog::OnHtmlLinkClicked )
287 wxWindow* parent, const wxString& message, const wxString& caption,
288 int tSeconds,
long style,
bool bFixedFont, const wxPoint& pos)
289 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
290 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
293 wxFont* dFont = GetOCPNScaledFont_PlugIn(_(
"Dialog"));
294 double font_size = dFont->GetPointSize();
296 wxTheFontList->FindOrCreateFont(font_size, wxFONTFAMILY_TELETYPE,
297 dFont->GetStyle(), dFont->GetWeight());
301 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
303 msgWindow =
new wxHtmlWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
304 wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION);
305 msgWindow->SetBorders(30);
307 topsizer->Add(msgWindow, 1, wxEXPAND, 5);
312 wxCharBuffer buf = html.ToUTF8();
314 msgWindow->SetPage(html);
317 int AllButtonSizerFlags =
318 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
319 int center_flag = wxEXPAND;
320 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
321 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
322 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
336 msgWindow->SetBackgroundColour(GetBackgroundColour());
338 m_timer.SetOwner(
this, -1);
340 if (tSeconds > 0) m_timer.Start(tSeconds * 1000, wxTIMER_ONE_SHOT);
343 void OCPN_TimedHTMLMessageDialog::RecalculateSize(
void) {
345 esize.x = GetCharWidth() * 60;
347 sx = g_monitor_info[g_current_monitor].width;
348 esize.x = wxMin(esize.x, sx * 6 / 10);
350 SetClientSize(esize);
352 int height1 = msgWindow->GetInternalRepresentation()->GetHeight();
355 wxMin(::wxGetDisplaySize().y - 100, height1 + 70);
357 SetClientSize(wxSize(
358 esize.x, client_size_y));
361 void OCPN_TimedHTMLMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
362 SetReturnCode(wxID_YES);
369 void OCPN_TimedHTMLMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
370 SetReturnCode(wxID_NO);
377 void OCPN_TimedHTMLMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
380 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
381 SetReturnCode(wxID_CANCEL);
382 EndModal(wxID_CANCEL);
386 void OCPN_TimedHTMLMessageDialog::OnClose(wxCloseEvent& event) {
387 SetReturnCode(wxID_CANCEL);
389 EndModal(wxID_CANCEL);
394 void OCPN_TimedHTMLMessageDialog::OnTimer(wxTimerEvent& evt) {
396 EndModal(m_style & wxNO_DEFAULT ? wxID_NO : wxID_YES);
405 EVT_PAINT(TimedPopupWin::OnPaint)
406 EVT_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;
421 TimedPopupWin::~TimedPopupWin() {
delete m_pbm; }
422 void TimedPopupWin::OnTimer(wxTimerEvent &event) {
423 if (IsShown()) Hide();
426 void 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);
435 void TimedPopupWin::OnPaint(wxPaintEvent &event) {
437 GetClientSize(&width, &height);
441 mdc.SelectObject(*m_pbm);
442 dc.Blit(0, 0, width, height, &mdc, 0, 0);
General purpose GUI support.