30#include <wx/fileconf.h>
31#include <wx/json_defs.h>
32#include <wx/jsonreader.h>
33#include <wx/tokenzr.h>
37#include "model/peer_client.h"
38#include "model/rest_server.h"
39#include "model/semantic_vers.h"
40#include "model/config_vars.h"
42#include "peer_client_dlg.h"
43#include "ocpn_frame.h"
52PinConfirmDlg::PinConfirmDlg() {
58PinConfirmDlg::PinConfirmDlg(wxWindow* parent, wxWindowID
id,
59 const wxString& caption,
const wxString& hint,
60 const wxPoint& pos,
const wxSize& size,
62 wxFont* pif = FontMgr::Get().
GetFont(_(
"Dialog"));
64 Create(parent,
id, caption, hint, pos, size, style);
67PinConfirmDlg::~PinConfirmDlg() {
73void PinConfirmDlg::OnTextChange(wxCommandEvent&) {
74 auto txt = m_pin_textctrl->GetValue().ToStdString();
76 if (txt.size() >= 4) {
78 value = std::stoi(txt);
79 }
catch (std::exception&) {
83 m_ok_btn->Enable(value >= 0 && txt.size() >= 4);
86bool PinConfirmDlg::Create(wxWindow* parent, wxWindowID
id,
87 const wxString& caption,
const wxString& hint,
88 const wxPoint& pos,
const wxSize& size,
long style) {
89 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
90 wxDialog::Create(parent,
id, caption, pos, size, style);
93 GetSizer()->Fit(
this);
94 GetSizer()->SetSizeHints(
this);
99void PinConfirmDlg::CreateControls(
const wxString&) {
100 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
101 SetSizer(itemBoxSizer2);
104 itemBoxSizer2->AddSpacer(20);
106 premtext =
new wxStaticText(
107 this, -1,
"A loooooooooooooooooooooooooooooooooooooooooooooong line\n");
108 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
110 m_pin_textctrl =
new wxTextCtrl(
this, wxID_ANY,
" ", wxDefaultPosition,
111 wxDefaultSize, wxTE_CENTRE);
112 itemBoxSizer2->Add(m_pin_textctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
115 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
116 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
118 m_cancel_btn =
new wxButton(
this, wxID_CANCEL);
120 m_cancel_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
121 [&](wxCommandEvent e) { OnCancelClick(e); });
122 itemBoxSizer16->Add(m_cancel_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
124 m_ok_btn =
new wxButton(
this, wxID_OK);
125 itemBoxSizer16->Add(m_ok_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
126 m_ok_btn->SetDefault();
127 m_ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
128 [&](wxCommandEvent e) { OnOKClick(e); });
129 m_ok_btn->Enable(
false);
130 m_pin_textctrl->Bind(wxEVT_TEXT,
131 [&](wxCommandEvent& ev) { OnTextChange(ev); });
134void PinConfirmDlg::SetMessage(
const wxString& msg) {
136 premtext->SetLabel(msg);
137 premtext->Refresh(
true);
141void PinConfirmDlg::SetPincodeText(
const wxString& message) {
142 m_pin_textctrl->ChangeValue(message);
143 m_pin_textctrl->Show();
144 GetSizer()->Fit(
this);
147void PinConfirmDlg::OnOKClick(wxCommandEvent&) { EndModal(wxID_OK); }
149void PinConfirmDlg::OnCancelClick(wxCommandEvent&) { EndModal(wxID_CANCEL); }
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
General purpose GUI support.