OpenCPN Partial API docs
Loading...
Searching...
No Matches
conn_edit_commons.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2022 by David S. Register *
3 * Copyright (C) 2062 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * e
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
24
25#ifndef CoNN_eDiT_h
26#define CoNN_eDiT_h
27
28#include <functional>
29#include <string>
30#include <type_traits>
31
32#include <wx/choice.h>
33#include <wx/combobox.h>
34#include <wx/panel.h>
35
36#include "libgui/text_ctrl_w_help.h"
37
38#include "model/conn_params.h"
39
40// Make _() return std::string instead of wxString;
41#undef _
42#if wxCHECK_VERSION(3, 2, 0)
43#define _(s) wxGetTranslation(wxASCII_STR(s)).ToStdString()
44#else
45#define _(s) wxGetTranslation((s)).ToStdString()
46#endif
47
48namespace conn_edit {
49
50static const std::string kPortHelp =
51 _("Port number (1025 - 65535, often 10110)");
52
67
68template <typename T>
70 static_assert(std::is_base_of_v<wxWindow, T>,
71 "Reloadable must inherit from wxWindow");
72
73public:
74 virtual ~Reloadable() = default;
75
77 virtual void Reload() = 0;
78};
79
81class ProtocolChoice : public wxChoice, public Reloadable<wxChoice> {
82public:
83 static ProtocolChoice* Create(
84 wxWindow* parent, ConnectionParams& params,
85 std::function<void()> on_change = [] {});
86
87protected:
88 explicit ProtocolChoice(wxWindow* parent) : wxChoice(parent, wxID_ANY) {}
89};
90
92class PortTextCtrl : public TextCtrlWithHelp,
93 public Reloadable<TextCtrlWithHelp> {
94public:
95 static PortTextCtrl* Create(wxWindow* parent, ConnectionParams& params);
96
97protected:
98 explicit PortTextCtrl(wxWindow* parent)
99 : TextCtrlWithHelp(parent, kPortHelp) {}
100};
101
103class FilterConfigPanel : public wxPanel, public Reloadable<wxPanel> {
104public:
105 static FilterConfigPanel* Create(wxWindow* parent, ConnectionParams& params);
106
107protected:
108 explicit FilterConfigPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) {}
109};
110
112class InputOutputPanel : public wxPanel {
113public:
114 static InputOutputPanel* Create(wxWindow* parent, ConnectionParams& params);
115
116 virtual void EnableOutput(bool enable) = 0;
117
118 virtual void EnableInput(bool enable) = 0;
119
120 virtual void SetOutput(bool value) = 0;
121
122 virtual void SetInput(bool value) = 0;
123
124protected:
125 explicit InputOutputPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) {}
126};
127
129class PortCombo : public wxComboBox, public Reloadable<wxComboBox> {
130public:
131 static PortCombo* Create(wxWindow* parent, wxString& port);
132
133protected:
134 explicit PortCombo(wxWindow* parent) : wxComboBox(parent, wxID_ANY) {}
135};
136
138class NetConfigPanel : public wxPanel {
139public:
140 static NetConfigPanel* Create(wxWindow* parent, ConnectionParams& params);
141
142 ~NetConfigPanel() override = default;
143
144 [[nodiscard]] virtual bool CheckStatus() const = 0;
145
146protected:
147 explicit NetConfigPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) {}
148};
149
150} // namespace conn_edit
151
152#endif // CoNN_eDiT_h
Connection data container close to a POD struct.
Definition conn_params.h:76
Interface implemented by widgets reflecting a ConnectionParams parameter.
virtual void Reload()=0
Synchronize widget value(s) with parameter(s).
Connection parameters.