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