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"
54PinConfirmDlg::PinConfirmDlg() {
60PinConfirmDlg::PinConfirmDlg(wxWindow* parent, wxWindowID
id,
61 const wxString& caption,
const wxString& hint,
62 const wxPoint& pos,
const wxSize& size,
64 wxFont* pif = FontMgr::Get().
GetFont(_(
"Dialog"));
66 Create(parent,
id, caption, hint, pos, size, style);
69PinConfirmDlg::~PinConfirmDlg() {
75void PinConfirmDlg::OnTextChange(wxCommandEvent&) {
76 auto txt = m_pin_textctrl->GetValue().ToStdString();
78 if (txt.size() >= 4) {
80 value = std::stoi(txt);
81 }
catch (std::exception&) {
85 m_ok_btn->Enable(value >= 0 && txt.size() >= 4);
88bool PinConfirmDlg::Create(wxWindow* parent, wxWindowID
id,
89 const wxString& caption,
const wxString& hint,
90 const wxPoint& pos,
const wxSize& size,
long style) {
91 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
92 wxDialog::Create(parent,
id, caption, pos, size, style);
95 GetSizer()->Fit(
this);
96 GetSizer()->SetSizeHints(
this);
101void PinConfirmDlg::CreateControls(
const wxString&) {
102 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
103 SetSizer(itemBoxSizer2);
106 itemBoxSizer2->AddSpacer(20);
108 premtext =
new wxStaticText(
109 this, -1,
"A loooooooooooooooooooooooooooooooooooooooooooooong line\n");
110 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
112 m_pin_textctrl =
new wxTextCtrl(
this, wxID_ANY,
" ", wxDefaultPosition,
113 wxDefaultSize, wxTE_CENTRE);
114 itemBoxSizer2->Add(m_pin_textctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
117 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
118 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
120 m_cancel_btn =
new wxButton(
this, wxID_CANCEL);
122 m_cancel_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
123 [&](wxCommandEvent e) { OnCancelClick(e); });
124 itemBoxSizer16->Add(m_cancel_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
126 m_ok_btn =
new wxButton(
this, wxID_OK);
127 itemBoxSizer16->Add(m_ok_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
128 m_ok_btn->SetDefault();
129 m_ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
130 [&](wxCommandEvent e) { OnOKClick(e); });
131 m_ok_btn->Enable(
false);
132 m_pin_textctrl->Bind(wxEVT_TEXT,
133 [&](wxCommandEvent& ev) { OnTextChange(ev); });
136void PinConfirmDlg::SetMessage(
const wxString& msg) {
138 premtext->SetLabel(msg);
139 premtext->Refresh(
true);
143void PinConfirmDlg::SetPincodeText(
const wxString& message) {
144 m_pin_textctrl->ChangeValue(message);
145 m_pin_textctrl->Show();
146 GetSizer()->Fit(
this);
149void PinConfirmDlg::OnOKClick(wxCommandEvent&) { EndModal(wxID_OK); }
151void 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.