24#include <wx/artprov.h>
30#include <wx/statbmp.h>
31#include <wx/statline.h>
33#include <wx/textctrl.h>
47#include "androidUTIL.h"
51CopyableText::CopyableText(wxWindow* parent,
const char* text)
52 : wxTextCtrl(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize,
55 wxStaticText tmp(parent, wxID_ANY, text);
56 SetBackgroundColour(tmp.GetBackgroundColour());
60 wxFont* dFont = FontMgr::Get().
GetFont(item, default_size);
61 int req_size = dFont->GetPointSize();
65 double scaled_font_size = dFont->GetPointSize();
68 double points_per_mm =
69 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
70 double min_scaled_font_size =
72 int nscaled_font_size =
73 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
75 if (req_size >= nscaled_font_size)
79 nscaled_font_size, dFont->GetFamily(), dFont->GetStyle(),
89 wxFont* dFont = FontMgr::Get().
GetFont(item, 0);
90 int req_size = dFont->GetPointSize();
91 wxFont qFont = *dFont;
94 double postmult = exp(g_GUIScaleFactor * (0.693 / 5.0));
95 double scaled_font_size = dFont->GetPointSize() * postmult;
97 double points_per_mm =
98 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
99 double min_scaled_font_size =
101 int nscaled_font_size =
102 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
109 qFont.SetPointSize(nscaled_font_size);
115int OCPNMessageBox(wxWindow* parent,
const wxString& message,
116 const wxString& caption,
int style,
int timeout_sec,
int x,
119 androidDisableRotation();
120 int style_mod = style;
122 auto dlg =
new wxMessageDialog(parent, message, caption, style_mod);
123 int ret = dlg->ShowModal();
124 qDebug() <<
"OCPNMB-1 ret" << ret;
129 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
133 androidEnableRotation();
134 qDebug() <<
"OCPNMB-2 ret" << ret;
142 ret = tbox.GetRetVal();
149EVT_BUTTON(wxID_YES, OCPNMessageDialog::OnYes)
150EVT_BUTTON(wxID_NO, OCPNMessageDialog::OnNo)
151EVT_BUTTON(wxID_CANCEL, OCPNMessageDialog::OnCancel)
152EVT_CLOSE(OCPNMessageDialog::OnClose)
156 const wxString& caption,
long style,
158 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
159 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
164 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
166 wxBoxSizer* icon_text =
new wxBoxSizer(wxHORIZONTAL);
170 if (style & wxICON_MASK) {
172 switch (style & wxICON_MASK) {
174 wxFAIL_MSG(
"incorrect log style");
178 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
181 case wxICON_INFORMATION:
182 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
186 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
189 case wxICON_QUESTION:
190 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
193 wxStaticBitmap* icon =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
194 icon_text->Add(icon, 0, wxCENTER);
200 icon_text->Add(CreateTextSizer(message), 0, wxALIGN_CENTER | wxLEFT, 10);
202 topsizer->Add(icon_text, 1, wxCENTER | wxLEFT | wxRIGHT | wxTOP, 10);
206 int AllButtonSizerFlags =
207 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
208 int center_flag = wxEXPAND;
209 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
210 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
211 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
216 topsizer->SetSizeHints(
this);
218 wxSize size(GetSize());
219 if (size.x < size.y * 3 / 2) {
220 size.x = size.y * 3 / 2;
224 Centre(wxBOTH | wxCENTER_FRAME);
227void OCPNMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
228 SetReturnCode(wxID_YES);
232void OCPNMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
233 SetReturnCode(wxID_NO);
237void OCPNMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
240 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
241 SetReturnCode(wxID_CANCEL);
242 EndModal(wxID_CANCEL);
246void OCPNMessageDialog::OnClose(wxCloseEvent& event) {
247 SetReturnCode(wxID_CANCEL);
248 EndModal(wxID_CANCEL);
252EVT_TIMER(-1, TimedMessageBox::OnTimer)
256 const wxString& caption,
long style,
257 int timeout_sec, const wxPoint& pos) {
259 m_timer.SetOwner(
this, -1);
261 if (timeout_sec > 0) m_timer.Start(timeout_sec * 1000, wxTIMER_ONE_SHOT);
266 int ret = dlg->GetReturnCode();
269 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
277TimedMessageBox::~TimedMessageBox() {}
279void TimedMessageBox::OnTimer(wxTimerEvent& evt) {
280 if (dlg) dlg->EndModal(wxID_CANCEL);
285EVT_PAINT(TimedPopupWin::OnPaint)
286EVT_TIMER(POPUP_TIMER, TimedPopupWin::OnTimer)
292 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER) {
295 m_timer_timeout.SetOwner(
this, POPUP_TIMER);
296 m_timeout_sec = timeout;
301TimedPopupWin::~TimedPopupWin() {
delete m_pbm; }
302void TimedPopupWin::OnTimer(wxTimerEvent& event) {
303 if (IsShown()) Hide();
306void TimedPopupWin::SetBitmap(wxBitmap& bmp) {
308 m_pbm =
new wxBitmap(bmp);
311 if (m_timeout_sec > 0)
312 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
315void TimedPopupWin::OnPaint(wxPaintEvent& event) {
317 GetClientSize(&width, &height);
321 mdc.SelectObject(*m_pbm);
322 dc.Blit(0, 0, width, height, &mdc, 0, 0);
327 explicit InfoFrame(wxWindow* parent,
const char* header,
const char* info)
328 : wxFrame(parent, wxID_ANY, info) {
329 auto flags = wxSizerFlags().Expand();
330 auto vbox =
new wxBoxSizer(wxVERTICAL);
331 vbox->Add(
new wxStaticText(
this, wxID_ANY, info), flags.Border());
332 vbox->Add(
new wxStaticLine(
this, wxID_ANY), flags);
333 auto button_sizer =
new wxStdDialogButtonSizer();
334 auto ok_btn =
new wxButton(
this, wxID_OK);
335 ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
336 [&](wxCommandEvent&) { Hide(); });
337 button_sizer->SetAffirmativeButton(ok_btn);
338 vbox->Add(button_sizer, flags.Border());
339 button_sizer->Realize();
346InfoButton::InfoButton(wxWindow* parent,
bool touch,
const char* header,
348 : wxButton(parent, wxID_ANY,
"", wxDefaultPosition, wxDefaultSize,
349 wxBU_EXACTFIT | wxBORDER_NONE),
350 m_icon(parent,
"help-info.svg",
351 GuiEvents::GetInstance().color_scheme_change, touch),
352 m_info_frame(new
InfoFrame(parent, header, info)) {
353 SetBitmap(m_icon.GetBitmap());
354 Bind(wxEVT_COMMAND_BUTTON_CLICKED, [&](wxCommandEvent&) {
356 m_info_frame->Show();
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)
Get a font object for a UI element.
EventVar exchange point, a singleton.
Global variables stored in configuration file.
Misc GUI event vars, a singleton.
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.
Timer identification constants.