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