OpenCPN Partial API docs
Loading...
Searching...
No Matches
conn_params_panel.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2013 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifdef __MINGW32__
25#undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
26#include <windows.h>
27#endif
28
29#include "conn_params_panel.h"
30
31#include <wx/tokenzr.h>
32#include <wx/intl.h>
33#include <wx/statline.h>
34
35#include "ocpn_plugin.h"
36#include "options.h"
37#include "color_handler.h"
38
39#if !wxUSE_XLOCALE && wxCHECK_VERSION(3, 0, 0)
40#define wxAtoi(arg) atoi(arg)
41#endif
42
44class ConnBoldLabel : public wxStaticText {
45public:
46 ConnBoldLabel(wxWindow *parent, const wxString &label)
47 : wxStaticText(parent, wxID_ANY, "") {
48 font = parent->GetFont();
49 font.MakeBold();
50 SetFont(font);
51 SetLabel(label);
52 Connect(wxEVT_LEFT_DOWN,
53 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
54 parent);
55 }
56
57 void SetLabel(const wxString &label) {
58 wxStaticText::SetLabel(label);
59 dc.SetFont(font);
60 auto size = dc.GetTextExtent(label).Scale(1.1, 1.1);
61 SetMinSize(size);
62 }
63
64private:
65 wxScreenDC dc;
66 wxFont font;
67};
68
69BEGIN_EVENT_TABLE(ConnectionParamsPanel, wxPanel)
70EVT_PAINT(ConnectionParamsPanel::OnPaint)
71EVT_ERASE_BACKGROUND(ConnectionParamsPanel::OnEraseBackground)
72END_EVENT_TABLE()
73
75 wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size,
76 ConnectionParams *p_itemConnectionParams, ConnectionsDialog *pContainer)
77 : wxPanel(parent, id, pos, size, wxBORDER_NONE) {
78 m_pContainer = pContainer;
79 m_pConnectionParams = p_itemConnectionParams;
80 m_bSelected = false;
81
82 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
83 SetFont(*dFont);
84
85 int refHeight = GetCharHeight();
86
87 // This controls the basic heght when later added to a vertical sizer
88 // SetMinSize(wxSize(-1, 6 * refHeight));
89
90 Connect(wxEVT_LEFT_DOWN,
91 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL, this);
92 CreateControls();
93}
94
95ConnectionParamsPanel::~ConnectionParamsPanel() {
96 if (m_pConnectionParams) m_pConnectionParams->m_optionsPanel = nullptr;
97}
98
99void ConnectionParamsPanel::OnSelected(wxMouseEvent &event) {}
100
101void ConnectionParamsPanel::SetSelected(bool selected) {
102 m_bSelected = selected;
103 wxColour colour;
104 int refHeight = GetCharHeight();
105
106 if (selected) {
107 m_boxColour = GetDialogColor(DLG_HIGHLIGHT);
108 } else {
109 m_boxColour = GetDialogColor(DLG_BACKGROUND);
110 }
111
112 wxWindowList kids = GetChildren();
113 for (unsigned int i = 0; i < kids.GetCount(); i++) {
114 wxWindowListNode *node = kids.Item(i);
115 wxWindow *win = node->GetData();
116 win->SetBackgroundColour(m_boxColour);
117 }
118
119 GetSizer()->Layout();
120 Refresh(true);
121}
122
123void ConnectionParamsPanel::OnEnableCBClick(wxCommandEvent &event) {}
124
125void ConnectionParamsPanel::CreateControls(void) {
126 int metric = GetCharHeight();
127
128 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
129 double font_size = dFont->GetPointSize() * 17 / 16;
130 wxFont *bFont = wxTheFontList->FindOrCreateFont(
131 font_size, dFont->GetFamily(), dFont->GetStyle(), wxFONTWEIGHT_BOLD);
132
133 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
134 SetSizer(mainSizer);
135
136 mainSizer->AddSpacer(metric);
137
138 wxBoxSizer *panelSizer = new wxBoxSizer(wxHORIZONTAL);
139 mainSizer->Add(panelSizer, 0, wxLEFT, 5);
140
141 mainSizer->AddSpacer(metric);
142
143 // Enable cbox
144 wxBoxSizer *enableSizer = new wxBoxSizer(wxVERTICAL);
145 panelSizer->Add(enableSizer, 1);
146
147 m_cbEnable = new wxCheckBox(this, wxID_ANY, _("Enable"));
148 m_cbEnable->Connect(
149 wxEVT_COMMAND_CHECKBOX_CLICKED,
150 wxCommandEventHandler(ConnectionParamsPanel::OnEnableCBClick), NULL,
151 this);
152 m_cbEnable->SetValue(m_pConnectionParams->bEnabled);
153
154 enableSizer->Add(m_cbEnable, 1, wxLEFT | wxEXPAND, metric);
155
156 // Parms
157 wxBoxSizer *parmSizer = new wxBoxSizer(wxVERTICAL);
158 panelSizer->Add(parmSizer, 5);
159
160 if (m_pConnectionParams->Type == SERIAL) {
161 wxFlexGridSizer *serialGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
162 serialGrid->SetFlexibleDirection(wxHORIZONTAL);
163 parmSizer->Add(serialGrid, 0, wxALIGN_LEFT);
164
165 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
166
167 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
168 serialGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
169 t1->Connect(wxEVT_LEFT_DOWN,
170 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
171 this);
172
173 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, "");
174 serialGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
175 t3->Connect(wxEVT_LEFT_DOWN,
176 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
177 this);
178
179 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
180 serialGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
181 t5->Connect(wxEVT_LEFT_DOWN,
182 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
183 this);
184
185 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _("Protocol"));
186 serialGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
187 t11->Connect(wxEVT_LEFT_DOWN,
188 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
189 this);
190
191 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _("Serial Port"));
192 serialGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
193 t13->Connect(wxEVT_LEFT_DOWN,
194 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
195 this);
196
197 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _("Baudrate"));
198 serialGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
199 t15->Connect(wxEVT_LEFT_DOWN,
200 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
201 this);
202
203 // line 2
204 t2 = new ConnBoldLabel(this, _("Serial"));
205 serialGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
206
207 t4 = new ConnBoldLabel(this, "");
208 serialGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
209
210 t6 = new ConnBoldLabel(this, ioDir);
211 serialGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
212
213 wxString proto;
214 switch (m_pConnectionParams->Protocol) {
215 case PROTO_NMEA0183:
216 proto = "NMEA 0183";
217 break;
218 case PROTO_NMEA2000:
219 proto = "NMEA 2000";
220 break;
221 default:
222 proto = _("Undefined");
223 break;
224 }
225
226 t12 = new ConnBoldLabel(this, proto);
227 serialGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
228
229 t14 = new ConnBoldLabel(this, m_pConnectionParams->Port);
230 serialGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
231
232 auto baudRate = wxString::Format("%d", m_pConnectionParams->Baudrate);
233 t16 = new ConnBoldLabel(this, baudRate);
234 serialGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
235
236 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
237 wxDefaultSize, wxLI_HORIZONTAL);
238 parmSizer->Add(line, 0, wxEXPAND);
239 line->Connect(wxEVT_LEFT_DOWN,
240 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
241 this);
242
243 t21 = new wxStaticText(this, wxID_ANY,
244 _("Comment: ") + m_pConnectionParams->UserComment);
245 parmSizer->Add(t21, 0);
246 t21->Connect(wxEVT_LEFT_DOWN,
247 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
248 this);
249
250 }
251
252 else if (m_pConnectionParams->Type == NETWORK) {
253 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
254
255 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
256 netGrid->SetFlexibleDirection(wxHORIZONTAL);
257 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
258
259 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
260 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
261 t1->Connect(wxEVT_LEFT_DOWN,
262 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
263 this);
264
265 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, "");
266 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
267 t3->Connect(wxEVT_LEFT_DOWN,
268 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
269 this);
270
271 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
272 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
273 t5->Connect(wxEVT_LEFT_DOWN,
274 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
275 this);
276
277 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _("Protocol"));
278 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
279 t11->Connect(wxEVT_LEFT_DOWN,
280 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
281 this);
282
283 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _("Network Address"));
284 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
285 t13->Connect(wxEVT_LEFT_DOWN,
286 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
287 this);
288
289 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _("Network Port"));
290 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
291 t15->Connect(wxEVT_LEFT_DOWN,
292 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
293 this);
294
295 // line 2
296 t2 = new wxStaticText(this, wxID_ANY, _("Network"));
297 t2->SetFont(*bFont);
298 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
299 t2->Connect(wxEVT_LEFT_DOWN,
300 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
301 this);
302
303 t4 = new wxStaticText(this, wxID_ANY, "");
304 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
305 t4->Connect(wxEVT_LEFT_DOWN,
306 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
307 this);
308
309 t6 = new wxStaticText(this, wxID_ANY, ioDir);
310 t6->SetFont(*bFont);
311 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
312 t6->Connect(wxEVT_LEFT_DOWN,
313 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
314 this);
315
316 wxString proto;
317 switch (m_pConnectionParams->NetProtocol) {
318 case UDP:
319 proto = "UDP";
320 if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
321 proto << " N0183";
322 else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
323 proto << " N2000";
324 break;
325 case TCP:
326 proto = "TCP";
327 if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
328 proto << " N0183";
329 else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
330 proto << " N2000";
331 break;
332 case GPSD:
333 proto = "GPSD";
334 break;
335 case SIGNALK:
336 proto = "Signal K";
337 break;
338 default:
339 proto = _("Undefined");
340 break;
341 }
342
343 t12 = new wxStaticText(this, wxID_ANY, proto);
344 t12->SetFont(*bFont);
345 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
346 t12->Connect(wxEVT_LEFT_DOWN,
347 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
348 this);
349
350 wxString address = m_pConnectionParams->NetworkAddress;
351 t14 = new wxStaticText(this, wxID_ANY, address);
352 t14->SetFont(*bFont);
353 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
354 t14->Connect(wxEVT_LEFT_DOWN,
355 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
356 this);
357
358 wxString port;
359 port.Printf("%d", m_pConnectionParams->NetworkPort);
360 t16 = new wxStaticText(this, wxID_ANY, port);
361 t16->SetFont(*bFont);
362 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
363 t16->Connect(wxEVT_LEFT_DOWN,
364 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
365 this);
366
367 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
368 wxDefaultSize, wxLI_HORIZONTAL);
369 parmSizer->Add(line, 0, wxEXPAND);
370 line->Connect(wxEVT_LEFT_DOWN,
371 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
372 this);
373
374 t21 = new wxStaticText(this, wxID_ANY,
375 _("Comment: ") + m_pConnectionParams->UserComment);
376 parmSizer->Add(t21, 0);
377 t21->Connect(wxEVT_LEFT_DOWN,
378 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
379 this);
380 }
381
382 else if (m_pConnectionParams->Type == INTERNAL_GPS) {
383 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
384
385 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
386 netGrid->SetFlexibleDirection(wxHORIZONTAL);
387 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
388
389 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
390 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
391 t1->Connect(wxEVT_LEFT_DOWN,
392 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
393 this);
394
395 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, "");
396 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
397 t3->Connect(wxEVT_LEFT_DOWN,
398 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
399 this);
400
401 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
402 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
403 t5->Connect(wxEVT_LEFT_DOWN,
404 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
405 this);
406
407 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, "");
408 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
409 t11->Connect(wxEVT_LEFT_DOWN,
410 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
411 this);
412
413 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, "");
414 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
415 t13->Connect(wxEVT_LEFT_DOWN,
416 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
417 this);
418
419 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, "");
420 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
421 t15->Connect(wxEVT_LEFT_DOWN,
422 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
423 this);
424
425 // line 2
426 t2 = new wxStaticText(this, wxID_ANY, _("Built-in GPS"));
427 t2->SetFont(*bFont);
428 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
429 t2->Connect(wxEVT_LEFT_DOWN,
430 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
431 this);
432
433 t4 = new wxStaticText(this, wxID_ANY, "");
434 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
435 t4->Connect(wxEVT_LEFT_DOWN,
436 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
437 this);
438
439 t6 = new wxStaticText(this, wxID_ANY, ioDir);
440 t6->SetFont(*bFont);
441 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
442 t6->Connect(wxEVT_LEFT_DOWN,
443 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
444 this);
445
446 wxString proto = "";
447
448 t12 = new wxStaticText(this, wxID_ANY, proto);
449 t12->SetFont(*bFont);
450 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
451 t12->Connect(wxEVT_LEFT_DOWN,
452 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
453 this);
454
455 wxString address;
456 t14 = new wxStaticText(this, wxID_ANY, address);
457 t14->SetFont(*bFont);
458 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
459 t14->Connect(wxEVT_LEFT_DOWN,
460 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
461 this);
462
463 wxString port;
464 t16 = new wxStaticText(this, wxID_ANY, port);
465 t16->SetFont(*bFont);
466 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
467 t16->Connect(wxEVT_LEFT_DOWN,
468 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
469 this);
470
471 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
472 wxDefaultSize, wxLI_HORIZONTAL);
473 parmSizer->Add(line, 0, wxEXPAND);
474 line->Connect(wxEVT_LEFT_DOWN,
475 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
476 this);
477
478 t21 = new wxStaticText(this, wxID_ANY,
479 _("Comment: ") + m_pConnectionParams->UserComment);
480 parmSizer->Add(t21, 0);
481 t21->Connect(wxEVT_LEFT_DOWN,
482 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
483 this);
484
485 } else if (m_pConnectionParams->Type == INTERNAL_BT) {
486 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
487
488 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
489 netGrid->SetFlexibleDirection(wxHORIZONTAL);
490 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
491
492 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
493 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
494 t1->Connect(wxEVT_LEFT_DOWN,
495 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
496 this);
497
498 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, "");
499 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
500 t3->Connect(wxEVT_LEFT_DOWN,
501 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
502 this);
503
504 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
505 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
506 t5->Connect(wxEVT_LEFT_DOWN,
507 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
508 this);
509
510 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, "");
511 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
512 t11->Connect(wxEVT_LEFT_DOWN,
513 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
514 this);
515
516 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, "");
517 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
518 t13->Connect(wxEVT_LEFT_DOWN,
519 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
520 this);
521
522 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, "");
523 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
524 t15->Connect(wxEVT_LEFT_DOWN,
525 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
526 this);
527
528 // line 2
529 t2 = new wxStaticText(this, wxID_ANY, _("Built-in Bluetooth"));
530 t2->SetFont(*bFont);
531 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
532 t2->Connect(wxEVT_LEFT_DOWN,
533 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
534 this);
535
536 t4 = new wxStaticText(this, wxID_ANY, "");
537 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
538 t4->Connect(wxEVT_LEFT_DOWN,
539 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
540 this);
541
542 t6 = new wxStaticText(this, wxID_ANY, ioDir);
543 t6->SetFont(*bFont);
544 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
545 t6->Connect(wxEVT_LEFT_DOWN,
546 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
547 this);
548
549 wxString proto = "";
550
551 t12 = new wxStaticText(this, wxID_ANY, proto);
552 t12->SetFont(*bFont);
553 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
554 t12->Connect(wxEVT_LEFT_DOWN,
555 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
556 this);
557
558 wxString address;
559 t14 = new wxStaticText(this, wxID_ANY, address);
560 t14->SetFont(*bFont);
561 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
562 t14->Connect(wxEVT_LEFT_DOWN,
563 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
564 this);
565
566 wxString port;
567 t16 = new wxStaticText(this, wxID_ANY, port);
568 t16->SetFont(*bFont);
569 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
570 t16->Connect(wxEVT_LEFT_DOWN,
571 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
572 this);
573
574 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
575 wxDefaultSize, wxLI_HORIZONTAL);
576 parmSizer->Add(line, 0, wxEXPAND);
577 line->Connect(wxEVT_LEFT_DOWN,
578 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
579 this);
580
581 t21 = new wxStaticText(this, wxID_ANY,
582 _("Comment: ") + m_pConnectionParams->UserComment);
583 parmSizer->Add(t21, 0);
584 t21->Connect(wxEVT_LEFT_DOWN,
585 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
586 this);
587 } else if (m_pConnectionParams->Type == SOCKETCAN) {
588 wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
589 netGrid->SetFlexibleDirection(wxHORIZONTAL);
590 parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
591
592 wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
593 netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
594 t1->Connect(wxEVT_LEFT_DOWN,
595 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
596 this);
597
598 wxStaticText *t3 = new wxStaticText(this, wxID_ANY, "");
599 netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
600 t3->Connect(wxEVT_LEFT_DOWN,
601 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
602 this);
603
604 wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Driver"));
605 netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
606 t5->Connect(wxEVT_LEFT_DOWN,
607 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
608 this);
609
610 wxStaticText *t11 = new wxStaticText(this, wxID_ANY, "");
611 netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
612 t11->Connect(wxEVT_LEFT_DOWN,
613 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
614 this);
615
616 wxStaticText *t13 = new wxStaticText(this, wxID_ANY, "");
617 netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
618 t13->Connect(wxEVT_LEFT_DOWN,
619 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
620 this);
621
622 wxStaticText *t15 = new wxStaticText(this, wxID_ANY, "");
623 netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
624 t15->Connect(wxEVT_LEFT_DOWN,
625 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
626 this);
627
628 // line 2
629 t2 = new wxStaticText(this, wxID_ANY, "socketCan");
630 t2->SetFont(*bFont);
631 netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
632 t2->Connect(wxEVT_LEFT_DOWN,
633 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
634 this);
635
636 t4 = new wxStaticText(this, wxID_ANY, "");
637 netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
638 t4->Connect(wxEVT_LEFT_DOWN,
639 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
640 this);
641
642 t6 = new wxStaticText(this, wxID_ANY, m_pConnectionParams->socketCAN_port);
643 t6->SetFont(*bFont);
644 netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
645 t6->Connect(wxEVT_LEFT_DOWN,
646 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
647 this);
648
649 wxString proto = "";
650
651 t12 = new wxStaticText(this, wxID_ANY, proto);
652 t12->SetFont(*bFont);
653 netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
654 t12->Connect(wxEVT_LEFT_DOWN,
655 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
656 this);
657
658 wxString address;
659 t14 = new wxStaticText(this, wxID_ANY, address);
660 t14->SetFont(*bFont);
661 netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
662 t14->Connect(wxEVT_LEFT_DOWN,
663 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
664 this);
665
666 wxString port;
667 t16 = new wxStaticText(this, wxID_ANY, port);
668 t16->SetFont(*bFont);
669 netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
670 t16->Connect(wxEVT_LEFT_DOWN,
671 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
672 this);
673
674 wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
675 wxDefaultSize, wxLI_HORIZONTAL);
676 parmSizer->Add(line, 0, wxEXPAND);
677 line->Connect(wxEVT_LEFT_DOWN,
678 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
679 this);
680
681 t21 = new wxStaticText(this, wxID_ANY,
682 _("Comment: ") + m_pConnectionParams->UserComment);
683 parmSizer->Add(t21, 0);
684 t21->Connect(wxEVT_LEFT_DOWN,
685 wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
686 this);
687 }
688}
689
690void ConnectionParamsPanel::Update(ConnectionParams *ConnectionParams) {
691 m_pConnectionParams = ConnectionParams;
692
693 wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
694
695 if (m_pConnectionParams->Type == SERIAL) {
696 wxString baudRate;
697 baudRate.Printf("%d", m_pConnectionParams->Baudrate);
698
699 wxString proto;
700 switch (m_pConnectionParams->Protocol) {
701 case PROTO_NMEA0183:
702 proto = "NMEA 0183";
703 break;
704 case PROTO_NMEA2000:
705 proto = "NMEA 2000";
706 break;
707 default:
708 proto = _("Undefined");
709 break;
710 }
711
712 t2->SetLabel(_("Serial"));
713 t6->SetLabel(ioDir);
714 t12->SetLabel(proto);
715 t14->SetLabel(m_pConnectionParams->Port);
716 t16->SetLabel(baudRate);
717
718 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
719 } else if (m_pConnectionParams->Type == NETWORK) {
720 wxString proto;
721 switch (m_pConnectionParams->NetProtocol) {
722 case UDP:
723 proto = "UDP";
724 if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
725 proto << " N0183";
726 else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
727 proto << " N2000";
728 break;
729 case TCP:
730 proto = "TCP";
731 if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
732 proto << " N0183";
733 else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
734 proto << " N2000";
735 break;
736 case GPSD:
737 proto = "GPSD";
738 break;
739 case SIGNALK:
740 proto = "Signal K";
741 break;
742 default:
743 proto = _("Undefined");
744 break;
745 }
746 wxString port;
747 port.Printf("%d", m_pConnectionParams->NetworkPort);
748
749 t2->SetLabel(_("Network"));
750 t6->SetLabel(ioDir);
751 t12->SetLabel(proto);
752 t14->SetLabel(m_pConnectionParams->NetworkAddress);
753 t16->SetLabel(port);
754
755 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
756 } else if (m_pConnectionParams->Type == INTERNAL_GPS) {
757 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
758 }
759
760 else if (m_pConnectionParams->Type == INTERNAL_BT) {
761 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
762 }
763
764 else if (m_pConnectionParams->Type == SOCKETCAN) {
765 t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
766 t6->SetLabel(m_pConnectionParams->socketCAN_port);
767 }
768
769 GetSizer()->Layout();
770}
771
772void ConnectionParamsPanel::OnEraseBackground(wxEraseEvent &event) {}
773
774void ConnectionParamsPanel::OnPaint(wxPaintEvent &event) {
775 int width, height;
776 GetSize(&width, &height);
777 wxPaintDC dc(this);
778
779 dc.SetPen(*wxTRANSPARENT_PEN);
780 dc.SetBrush(wxBrush(GetBackgroundColour()));
781 dc.DrawRectangle(GetVirtualSize());
782
783 wxColour c;
784
785 wxString nameString = m_pConnectionParams->Serialize();
786
787 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
788
789 if (m_bSelected) {
790 dc.SetBrush(wxBrush(m_boxColour));
791
792 GetGlobalColor(_T ( "UITX1" ), &c);
793 dc.SetPen(wxPen(wxColor(0xCE, 0xD5, 0xD6), 3));
794
795 dc.DrawRoundedRectangle(0, 0, width - 1, height - 1, height / 10);
796
797 // Draw the thumbnail
798
799 dc.SetTextForeground(wxColour(0, 0, 0));
800 } else {
801 dc.SetBrush(wxBrush(m_boxColour));
802
803 GetGlobalColor(_T ( "UITX1" ), &c);
804 dc.SetPen(wxPen(c, 1));
805
806 int offset = height / 10;
807 dc.DrawRectangle(offset, offset, width - (2 * offset),
808 height - (2 * offset));
809
810 dc.SetTextForeground(wxColour(128, 128, 128));
811 }
812}
A wxStaticText bold label with correct width, see #2538.
Panel for displaying and editing connection parameters.
wxColour GetDialogColor(DialogColor color)
Retrieves a dialog color based on its role in the application's dialogs.
Global color handling by name.
@ DLG_BACKGROUND
Background color of the dialog.
@ DLG_HIGHLIGHT
Highlight color.
Panel for editing a connection.
PlugIn Object Definition/API.