OpenCPN Partial API docs
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 
45 class ConnBoldLabel: public wxStaticText {
46 public:
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 
65 private:
66  wxScreenDC dc;
67  wxFont font;
68 };
69 
70 
71 extern "C" bool GetGlobalColor(wxString colorName, wxColour *pcolour);
72 
73 BEGIN_EVENT_TABLE(ConnectionParamsPanel, wxPanel)
74 EVT_PAINT(ConnectionParamsPanel::OnPaint)
75 EVT_ERASE_BACKGROUND(ConnectionParamsPanel::OnEraseBackground)
76 END_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 
99 ConnectionParamsPanel::~ConnectionParamsPanel() {
100  if (m_pConnectionParams) m_pConnectionParams->m_optionsPanel = nullptr;
101 }
102 
103 void 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 
113 void 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 
135 void ConnectionParamsPanel::OnEnableCBClick(wxCommandEvent &event) {
136  if (m_pContainer) {
137  m_pContainer->EnableConnection(m_pConnectionParams, event.IsChecked());
138  }
139 }
140 
141 void 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, 6, 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  // line 2
220  t2 = new ConnBoldLabel(this, _("Serial"));
221  serialGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
222 
223  t4 = new ConnBoldLabel(this, "");
224  serialGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
225 
226  t6 = new ConnBoldLabel(this, ioDir);
227  serialGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
228 
229  wxString proto;
230  switch (m_pConnectionParams->Protocol) {
231  case PROTO_NMEA0183:
232  proto = "NMEA 0183";
233  break;
234  case PROTO_NMEA2000:
235  proto = "NMEA 2000";
236  break;
237  default:
238  proto = _("Undefined");
239  break;
240  }
241 
242  t12 = new ConnBoldLabel(this, proto);
243  serialGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
244 
245  t14 = new ConnBoldLabel(this, m_pConnectionParams->Port);
246  serialGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
247 
248  auto baudRate = wxString::Format("%d", m_pConnectionParams->Baudrate);
249  t16 = new ConnBoldLabel(this, baudRate);
250  serialGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
251 
252  wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
253  wxDefaultSize, wxLI_HORIZONTAL);
254  parmSizer->Add(line, 0, wxEXPAND);
255  line->Connect(wxEVT_LEFT_DOWN,
256  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
257  this);
258 
259  t21 = new wxStaticText(this, wxID_ANY,
260  _("Comment: ") + m_pConnectionParams->UserComment);
261  parmSizer->Add(t21, 0);
262  t21->Connect(wxEVT_LEFT_DOWN,
263  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
264  this);
265 
266  }
267 
268  else if (m_pConnectionParams->Type == NETWORK) {
269  wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
270 
271  wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
272  netGrid->SetFlexibleDirection(wxHORIZONTAL);
273  parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
274 
275  wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
276  netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
277  t1->Connect(wxEVT_LEFT_DOWN,
278  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
279  this);
280 
281  wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
282  netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
283  t3->Connect(wxEVT_LEFT_DOWN,
284  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
285  this);
286 
287  wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
288  netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
289  t5->Connect(wxEVT_LEFT_DOWN,
290  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
291  this);
292 
293  wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _("Protocol"));
294  netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
295  t11->Connect(wxEVT_LEFT_DOWN,
296  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
297  this);
298 
299  wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _("Network Address"));
300  netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
301  t13->Connect(wxEVT_LEFT_DOWN,
302  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
303  this);
304 
305  wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _("Network Port"));
306  netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
307  t15->Connect(wxEVT_LEFT_DOWN,
308  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
309  this);
310 
311  // line 2
312  t2 = new wxStaticText(this, wxID_ANY, _("Network"));
313  t2->SetFont(*bFont);
314  netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
315  t2->Connect(wxEVT_LEFT_DOWN,
316  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
317  this);
318 
319  t4 = new wxStaticText(this, wxID_ANY, _T(""));
320  netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
321  t4->Connect(wxEVT_LEFT_DOWN,
322  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
323  this);
324 
325  t6 = new wxStaticText(this, wxID_ANY, ioDir);
326  t6->SetFont(*bFont);
327  netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
328  t6->Connect(wxEVT_LEFT_DOWN,
329  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
330  this);
331 
332  wxString proto;
333  switch (m_pConnectionParams->NetProtocol) {
334  case UDP:
335  proto = _T("UDP");
336  if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
337  proto << " N0183";
338  else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
339  proto << " N2000";
340  break;
341  case TCP:
342  proto = _T("TCP");
343  if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
344  proto << " N0183";
345  else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
346  proto << " N2000";
347  break;
348  case GPSD:
349  proto = _T("GPSD");
350  break;
351  case SIGNALK:
352  proto = _T("Signal K");
353  break;
354  default:
355  proto = _("Undefined");
356  break;
357  }
358 
359  t12 = new wxStaticText(this, wxID_ANY, proto);
360  t12->SetFont(*bFont);
361  netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
362  t12->Connect(wxEVT_LEFT_DOWN,
363  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
364  this);
365 
366  wxString address = m_pConnectionParams->NetworkAddress;
367  t14 = new wxStaticText(this, wxID_ANY, address);
368  t14->SetFont(*bFont);
369  netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
370  t14->Connect(wxEVT_LEFT_DOWN,
371  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
372  this);
373 
374  wxString port;
375  port.Printf(_T("%d"), m_pConnectionParams->NetworkPort);
376  t16 = new wxStaticText(this, wxID_ANY, port);
377  t16->SetFont(*bFont);
378  netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
379  t16->Connect(wxEVT_LEFT_DOWN,
380  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
381  this);
382 
383  wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
384  wxDefaultSize, wxLI_HORIZONTAL);
385  parmSizer->Add(line, 0, wxEXPAND);
386  line->Connect(wxEVT_LEFT_DOWN,
387  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
388  this);
389 
390  t21 = new wxStaticText(this, wxID_ANY,
391  _("Comment: ") + m_pConnectionParams->UserComment);
392  parmSizer->Add(t21, 0);
393  t21->Connect(wxEVT_LEFT_DOWN,
394  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
395  this);
396  }
397 
398  else if (m_pConnectionParams->Type == INTERNAL_GPS) {
399  wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
400 
401  wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
402  netGrid->SetFlexibleDirection(wxHORIZONTAL);
403  parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
404 
405  wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
406  netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
407  t1->Connect(wxEVT_LEFT_DOWN,
408  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
409  this);
410 
411  wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
412  netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
413  t3->Connect(wxEVT_LEFT_DOWN,
414  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
415  this);
416 
417  wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
418  netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
419  t5->Connect(wxEVT_LEFT_DOWN,
420  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
421  this);
422 
423  wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _T(""));
424  netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
425  t11->Connect(wxEVT_LEFT_DOWN,
426  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
427  this);
428 
429  wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _T(""));
430  netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
431  t13->Connect(wxEVT_LEFT_DOWN,
432  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
433  this);
434 
435  wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _T(""));
436  netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
437  t15->Connect(wxEVT_LEFT_DOWN,
438  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
439  this);
440 
441  // line 2
442  t2 = new wxStaticText(this, wxID_ANY, _("Built-in GPS"));
443  t2->SetFont(*bFont);
444  netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
445  t2->Connect(wxEVT_LEFT_DOWN,
446  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
447  this);
448 
449  t4 = new wxStaticText(this, wxID_ANY, _T(""));
450  netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
451  t4->Connect(wxEVT_LEFT_DOWN,
452  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
453  this);
454 
455  t6 = new wxStaticText(this, wxID_ANY, ioDir);
456  t6->SetFont(*bFont);
457  netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
458  t6->Connect(wxEVT_LEFT_DOWN,
459  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
460  this);
461 
462  wxString proto = _T("");
463 
464  t12 = new wxStaticText(this, wxID_ANY, proto);
465  t12->SetFont(*bFont);
466  netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
467  t12->Connect(wxEVT_LEFT_DOWN,
468  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
469  this);
470 
471  wxString address;
472  t14 = new wxStaticText(this, wxID_ANY, address);
473  t14->SetFont(*bFont);
474  netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
475  t14->Connect(wxEVT_LEFT_DOWN,
476  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
477  this);
478 
479  wxString port;
480  t16 = new wxStaticText(this, wxID_ANY, port);
481  t16->SetFont(*bFont);
482  netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
483  t16->Connect(wxEVT_LEFT_DOWN,
484  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
485  this);
486 
487  wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
488  wxDefaultSize, wxLI_HORIZONTAL);
489  parmSizer->Add(line, 0, wxEXPAND);
490  line->Connect(wxEVT_LEFT_DOWN,
491  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
492  this);
493 
494  t21 = new wxStaticText(this, wxID_ANY,
495  _("Comment: ") + m_pConnectionParams->UserComment);
496  parmSizer->Add(t21, 0);
497  t21->Connect(wxEVT_LEFT_DOWN,
498  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
499  this);
500 
501  } else if (m_pConnectionParams->Type == INTERNAL_BT) {
502  wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
503 
504  wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
505  netGrid->SetFlexibleDirection(wxHORIZONTAL);
506  parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
507 
508  wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
509  netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
510  t1->Connect(wxEVT_LEFT_DOWN,
511  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
512  this);
513 
514  wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
515  netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
516  t3->Connect(wxEVT_LEFT_DOWN,
517  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
518  this);
519 
520  wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Direction"));
521  netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
522  t5->Connect(wxEVT_LEFT_DOWN,
523  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
524  this);
525 
526  wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _T(""));
527  netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
528  t11->Connect(wxEVT_LEFT_DOWN,
529  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
530  this);
531 
532  wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _T(""));
533  netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
534  t13->Connect(wxEVT_LEFT_DOWN,
535  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
536  this);
537 
538  wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _T(""));
539  netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
540  t15->Connect(wxEVT_LEFT_DOWN,
541  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
542  this);
543 
544  // line 2
545  t2 = new wxStaticText(this, wxID_ANY, _("Built-in Bluetooth"));
546  t2->SetFont(*bFont);
547  netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
548  t2->Connect(wxEVT_LEFT_DOWN,
549  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
550  this);
551 
552  t4 = new wxStaticText(this, wxID_ANY, _T(""));
553  netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
554  t4->Connect(wxEVT_LEFT_DOWN,
555  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
556  this);
557 
558  t6 = new wxStaticText(this, wxID_ANY, ioDir);
559  t6->SetFont(*bFont);
560  netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
561  t6->Connect(wxEVT_LEFT_DOWN,
562  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
563  this);
564 
565  wxString proto = _T("");
566 
567  t12 = new wxStaticText(this, wxID_ANY, proto);
568  t12->SetFont(*bFont);
569  netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
570  t12->Connect(wxEVT_LEFT_DOWN,
571  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
572  this);
573 
574  wxString address;
575  t14 = new wxStaticText(this, wxID_ANY, address);
576  t14->SetFont(*bFont);
577  netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
578  t14->Connect(wxEVT_LEFT_DOWN,
579  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
580  this);
581 
582  wxString port;
583  t16 = new wxStaticText(this, wxID_ANY, port);
584  t16->SetFont(*bFont);
585  netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
586  t16->Connect(wxEVT_LEFT_DOWN,
587  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
588  this);
589 
590  wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
591  wxDefaultSize, wxLI_HORIZONTAL);
592  parmSizer->Add(line, 0, wxEXPAND);
593  line->Connect(wxEVT_LEFT_DOWN,
594  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
595  this);
596 
597  t21 = new wxStaticText(this, wxID_ANY,
598  _("Comment: ") + m_pConnectionParams->UserComment);
599  parmSizer->Add(t21, 0);
600  t21->Connect(wxEVT_LEFT_DOWN,
601  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
602  this);
603  } else if (m_pConnectionParams->Type == SOCKETCAN) {
604  wxFlexGridSizer *netGrid = new wxFlexGridSizer(2, 6, 0, metric / 2);
605  netGrid->SetFlexibleDirection(wxHORIZONTAL);
606  parmSizer->Add(netGrid, 0, wxALIGN_LEFT);
607 
608  wxStaticText *t1 = new wxStaticText(this, wxID_ANY, _("Type"));
609  netGrid->Add(t1, 0, wxALIGN_CENTER_HORIZONTAL);
610  t1->Connect(wxEVT_LEFT_DOWN,
611  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
612  this);
613 
614  wxStaticText *t3 = new wxStaticText(this, wxID_ANY, _T(""));
615  netGrid->Add(t3, 0, wxALIGN_CENTER_HORIZONTAL);
616  t3->Connect(wxEVT_LEFT_DOWN,
617  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
618  this);
619 
620  wxStaticText *t5 = new wxStaticText(this, wxID_ANY, _("Driver"));
621  netGrid->Add(t5, 0, wxALIGN_CENTER_HORIZONTAL);
622  t5->Connect(wxEVT_LEFT_DOWN,
623  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
624  this);
625 
626  wxStaticText *t11 = new wxStaticText(this, wxID_ANY, _T(""));
627  netGrid->Add(t11, 0, wxALIGN_CENTER_HORIZONTAL);
628  t11->Connect(wxEVT_LEFT_DOWN,
629  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
630  this);
631 
632  wxStaticText *t13 = new wxStaticText(this, wxID_ANY, _T(""));
633  netGrid->Add(t13, 0, wxALIGN_CENTER_HORIZONTAL);
634  t13->Connect(wxEVT_LEFT_DOWN,
635  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
636  this);
637 
638  wxStaticText *t15 = new wxStaticText(this, wxID_ANY, _T(""));
639  netGrid->Add(t15, 0, wxALIGN_CENTER_HORIZONTAL);
640  t15->Connect(wxEVT_LEFT_DOWN,
641  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
642  this);
643 
644  // line 2
645  t2 = new wxStaticText(this, wxID_ANY, "socketCan");
646  t2->SetFont(*bFont);
647  netGrid->Add(t2, 0, wxALIGN_CENTER_HORIZONTAL);
648  t2->Connect(wxEVT_LEFT_DOWN,
649  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
650  this);
651 
652  t4 = new wxStaticText(this, wxID_ANY, _T(""));
653  netGrid->Add(t4, 0, wxALIGN_CENTER_HORIZONTAL);
654  t4->Connect(wxEVT_LEFT_DOWN,
655  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
656  this);
657 
658  t6 = new wxStaticText(this, wxID_ANY, m_pConnectionParams->socketCAN_port);
659  t6->SetFont(*bFont);
660  netGrid->Add(t6, 0, wxALIGN_CENTER_HORIZONTAL);
661  t6->Connect(wxEVT_LEFT_DOWN,
662  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
663  this);
664 
665  wxString proto = _T("");
666 
667  t12 = new wxStaticText(this, wxID_ANY, proto);
668  t12->SetFont(*bFont);
669  netGrid->Add(t12, 0, wxALIGN_CENTER_HORIZONTAL);
670  t12->Connect(wxEVT_LEFT_DOWN,
671  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
672  this);
673 
674  wxString address;
675  t14 = new wxStaticText(this, wxID_ANY, address);
676  t14->SetFont(*bFont);
677  netGrid->Add(t14, 0, wxALIGN_CENTER_HORIZONTAL);
678  t14->Connect(wxEVT_LEFT_DOWN,
679  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
680  this);
681 
682  wxString port;
683  t16 = new wxStaticText(this, wxID_ANY, port);
684  t16->SetFont(*bFont);
685  netGrid->Add(t16, 0, wxALIGN_CENTER_HORIZONTAL);
686  t16->Connect(wxEVT_LEFT_DOWN,
687  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
688  this);
689 
690  wxStaticLine *line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition,
691  wxDefaultSize, wxLI_HORIZONTAL);
692  parmSizer->Add(line, 0, wxEXPAND);
693  line->Connect(wxEVT_LEFT_DOWN,
694  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
695  this);
696 
697  t21 = new wxStaticText(this, wxID_ANY,
698  _("Comment: ") + m_pConnectionParams->UserComment);
699  parmSizer->Add(t21, 0);
700  t21->Connect(wxEVT_LEFT_DOWN,
701  wxMouseEventHandler(ConnectionParamsPanel::OnSelected), NULL,
702  this);
703  }
704 }
705 
706 void ConnectionParamsPanel::Update(ConnectionParams *ConnectionParams) {
707  m_pConnectionParams = ConnectionParams;
708 
709  wxString ioDir = m_pConnectionParams->GetIOTypeValueStr();
710 
711  if (m_pConnectionParams->Type == SERIAL) {
712  wxString baudRate;
713  baudRate.Printf(_T("%d"), m_pConnectionParams->Baudrate);
714 
715  wxString proto;
716  switch (m_pConnectionParams->Protocol) {
717  case PROTO_NMEA0183:
718  proto = _T("NMEA 0183");
719  break;
720  case PROTO_NMEA2000:
721  proto = _T("NMEA 2000");
722  break;
723  default:
724  proto = _("Undefined");
725  break;
726  }
727 
728  t2->SetLabel(_("Serial"));
729  t6->SetLabel(ioDir);
730  t12->SetLabel(proto);
731  t14->SetLabel(m_pConnectionParams->Port);
732  t16->SetLabel(baudRate);
733 
734  t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
735  } else if (m_pConnectionParams->Type == NETWORK) {
736  wxString proto;
737  switch (m_pConnectionParams->NetProtocol) {
738  case UDP:
739  proto = _T("UDP");
740  if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
741  proto << " N0183";
742  else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
743  proto << " N2000";
744  break;
745  case TCP:
746  proto = _T("TCP");
747  if (m_pConnectionParams->Protocol == PROTO_NMEA0183)
748  proto << " N0183";
749  else if (m_pConnectionParams->Protocol == PROTO_NMEA2000)
750  proto << " N2000";
751  break;
752  case GPSD:
753  proto = _T("GPSD");
754  break;
755  case SIGNALK:
756  proto = _T("Signal K");
757  break;
758  default:
759  proto = _("Undefined");
760  break;
761  }
762  wxString port;
763  port.Printf(_T("%d"), m_pConnectionParams->NetworkPort);
764 
765  t2->SetLabel(_("Network"));
766  t6->SetLabel(ioDir);
767  t12->SetLabel(proto);
768  t14->SetLabel(m_pConnectionParams->NetworkAddress);
769  t16->SetLabel(port);
770 
771  t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
772  } else if (m_pConnectionParams->Type == INTERNAL_GPS) {
773  t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
774  }
775 
776  else if (m_pConnectionParams->Type == INTERNAL_BT) {
777  t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
778  }
779 
780  else if (m_pConnectionParams->Type == SOCKETCAN) {
781  t21->SetLabel(_("Comment: ") + m_pConnectionParams->UserComment);
782  t6->SetLabel(m_pConnectionParams->socketCAN_port);
783  }
784 
785  GetSizer()->Layout();
786 }
787 
788 void ConnectionParamsPanel::OnEraseBackground(wxEraseEvent &event) {}
789 
790 void ConnectionParamsPanel::OnPaint(wxPaintEvent &event) {
791  int width, height;
792  GetSize(&width, &height);
793  wxPaintDC dc(this);
794 
795  dc.SetPen(*wxTRANSPARENT_PEN);
796  dc.SetBrush(wxBrush(GetBackgroundColour()));
797  dc.DrawRectangle(GetVirtualSize());
798 
799  wxColour c;
800 
801  wxString nameString = m_pConnectionParams->Serialize();
802 
803  wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
804 
805  if (m_bSelected) {
806  dc.SetBrush(wxBrush(m_boxColour));
807 
808  GetGlobalColor(_T ( "UITX1" ), &c);
809  dc.SetPen(wxPen(wxColor(0xCE, 0xD5, 0xD6), 3));
810 
811  dc.DrawRoundedRectangle(0, 0, width - 1, height - 1, height / 10);
812 
813  // Draw the thumbnail
814 
815  dc.SetTextForeground(wxColour(0, 0, 0));
816  } else {
817  dc.SetBrush(wxBrush(m_boxColour));
818 
819  GetGlobalColor(_T ( "UITX1" ), &c);
820  dc.SetPen(wxPen(c, 1));
821 
822  int offset = height / 10;
823  dc.DrawRectangle(offset, offset, width - (2 * offset),
824  height - (2 * offset));
825 
826  dc.SetTextForeground(wxColour(128, 128, 128));
827  }
828 }
A wxStaticText bold label with correct width, see #2538.