116 const unsigned m_size;
117 const fs::path m_svg_dir;
121 static unsigned GetSize(
const wxWindow* parent) {
122 double size = parent->GetCharHeight() * (IsWindows() ? 1.3 : 1.0);
123#if wxCHECK_VERSION(3, 1, 2)
126 size *=
static_cast<double>(parent->ToDIP(100)) / 100.;
130 double pixel_per_mm =
132 size = std::max(size, 7.0 * pixel_per_mm);
134 return static_cast<unsigned>(size);
137 [[nodiscard]] wxBitmap LoadIcon(
const std::string& filename)
const {
138 fs::path path = m_svg_dir / filename;
139 return LoadSVG(path.string(), m_size, m_size);
142 [[nodiscard]] wxBitmap IconApplyColorScheme(
const wxBitmap& proto)
const {
143 if (!proto.IsOk())
return wxNullBitmap;
144 if ((m_cs != GLOBAL_COLOR_SCHEME_DAY) &&
145 (m_cs != GLOBAL_COLOR_SCHEME_RGB)) {
147 const wxImage image = proto.ConvertToImage();
148 unsigned char* data = image.GetData();
149 unsigned char* p_idata = data;
150 for (
int i = 0; i < image.GetSize().y; i++) {
151 for (
int j = 0; j < image.GetSize().x; j++) {
152 unsigned char v = *p_idata;
169 explicit StdIcons(
const wxWindow* parent)
170 : m_size(GetSize(parent)),
171 m_svg_dir(fs::path(g_Platform->GetSharedDataDir().ToStdString()) /
172 "uidata" /
"MUI_flat"),
173 m_cs(GLOBAL_COLOR_SCHEME_RGB),
174 trash_bin_proto(LoadIcon(
"trash_bin.svg")),
175 settings_proto(LoadIcon(
"setting_gear.svg")),
176 filled_circle_proto(LoadIcon(
"circle-on.svg")),
177 open_circle_proto(LoadIcon(
"circle-off.svg")),
178 exclaim_mark_proto(LoadIcon(
"exclaim_mark.svg")),
179 x_mult_proto(LoadIcon(
"X_mult.svg")),
180 check_mark_proto(LoadIcon(
"check_mark.svg")) {
181 trash_bin = trash_bin_proto;
182 settings = settings_proto;
183 filled_circle = filled_circle_proto;
184 open_circle = open_circle_proto;
185 exclaim_mark = exclaim_mark_proto;
186 x_mult = x_mult_proto;
187 check_mark = check_mark_proto;
190 void SetColorScheme(
const ColorScheme cs) {
193 trash_bin = IconApplyColorScheme(trash_bin_proto);
194 settings = IconApplyColorScheme(settings_proto);
195 filled_circle = IconApplyColorScheme(filled_circle_proto);
196 open_circle = IconApplyColorScheme(open_circle_proto);
197 exclaim_mark = IconApplyColorScheme(exclaim_mark_proto);
198 x_mult = IconApplyColorScheme(x_mult_proto);
199 check_mark = IconApplyColorScheme(check_mark_proto);
203 const wxBitmap trash_bin_proto;
204 const wxBitmap settings_proto;
205 const wxBitmap filled_circle_proto;
206 const wxBitmap open_circle_proto;
207 const wxBitmap exclaim_mark_proto;
208 const wxBitmap x_mult_proto;
209 const wxBitmap check_mark_proto;
213 wxBitmap filled_circle;
214 wxBitmap open_circle;
215 wxBitmap exclaim_mark;
348 const std::vector<ConnectionParams*>& connections,
352 : wxGrid(parent, wxID_ANY),
353 m_connections(connections),
354 m_header_column_widths({0, 0, 0, 0, 0, 0, 0}),
355 m_last_tooltip_cell(100),
356 m_cs(GLOBAL_COLOR_SCHEME_DAY),
357 m_on_conn_delete(on_conn_update),
359 m_on_edit_conn(on_edit_conn) {
360 ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
361 SetTable(
new wxGridStringTable(),
false);
362 GetTable()->AppendCols(8);
365 SetDefaultRowSize(wxWindow::GetCharHeight() * 2);
366 SetColLabelSize(wxWindow::GetCharHeight() * 2);
368 static const std::array<wxString, 7> headers = {
369 "", _(
"Protocol") +
" ", _(
"In/Out"), _(
"Data port"), _(
"Status"),
"",
372 for (
auto hdr = headers.begin(); hdr != headers.end(); hdr++, ic++) {
373 SetColLabelValue(
static_cast<int>(hdr - headers.begin()), *hdr);
374 unsigned col_width = hdr->Length() * wxWindow::GetCharWidth();
375 col_width = wxMax(col_width, 6 * wxWindow::GetCharWidth());
376 m_header_column_widths[ic] =
static_cast<int>(col_width);
377 SetColSize(ic,
static_cast<int>(col_width));
381 SetLabelBackgroundColour(GetGlobalColor(
"DILG1"));
382 SetLabelTextColour(GetGlobalColor(
"DILG3"));
385 SetColAttributes(parent);
388 DisableDragColSize();
389 DisableDragRowSize();
390 wxWindow::Show(GetNumberRows() > 0);
392 GetGridWindow()->Bind(wxEVT_MOTION, [&](wxMouseEvent& ev) {
396 GetGridWindow()->Bind(wxEVT_MOUSEWHEEL,
397 [&](
const wxMouseEvent& ev) {
OnWheel(ev); });
399 Bind(wxEVT_GRID_LABEL_LEFT_CLICK,
400 [&](wxGridEvent& ev) { HandleSort(ev.GetCol()); });
401 Bind(wxEVT_GRID_CELL_LEFT_CLICK,
402 [&](wxGridEvent& ev) { OnClickCell(ev.GetRow(), ev.GetCol()); });
403 Bind(wxEVT_PAINT, [&](wxPaintEvent& ev) {
404 SetColAttributes(
dynamic_cast<const wxWindow*
>(ev.GetEventObject()));
407 conn_change_lstnr.
Init(
409 [&](
ObservedEvt&) { OnConnectionChange(m_connections); });
411 void SetColorScheme(
const ColorScheme cs) {
413 m_icons.SetColorScheme(cs);
417 wxSize GetEstimatedSize()
const {
419 for (
auto s : m_header_column_widths) rs += s;
420 return {
static_cast<int>(rs), -1};
426 dynamic_cast<wxScrolledWindow*
>(FindWindowByName(TopScrollWindowName));
427 assert(w &&
"No TopScroll window found");
430 w->GetViewStart(&xpos, &ypos);
433 w->GetScrollPixelsPerUnit(&x, &y);
435 const int dir = ev.GetWheelRotation();
436 w->Scroll(-1, ypos - dir / y / 4);
440 void ReloadGrid(
const std::vector<ConnectionParams*>& connections) {
442 m_renderer_status_vector.clear();
444 for (
auto it = connections.begin(); it != connections.end(); ++it) {
445 const auto row =
static_cast<int>(it - connections.begin());
447 SetCellValue(row, 0, (*it)->bEnabled ?
"1" :
"");
449 m_tooltips[row][0] = _(
"Enabled, click to disable");
451 m_tooltips[row][0] = _(
"Disabled, click to enable");
452 std::string protocol = NavAddr::BusToString((*it)->GetCommProtocol());
453 SetCellValue(row, 1, protocol);
454 SetCellValue(row, 2, (*it)->GetIOTypeValueStr());
455 SetCellValue(row, 3, (*it)->GetStrippedDSPort());
456 m_tooltips[row][3] = (*it)->UserComment;
458 m_tooltips[row][5] = _(
"Edit connection");
460 m_tooltips[row][6] = _(
"Delete connection");
461 SetCellValue(row, 7, (*it)->GetKey());
464 stat_renderer->status = ConnState::Disabled;
465 m_renderer_status_vector.push_back(stat_renderer);
466 SetCellRenderer(row, 4, stat_renderer);
468 wxString sp(protocol);
469 unsigned size = sp.Length() * wxWindow::GetCharWidth();
470 m_header_column_widths[1] = std::max(m_header_column_widths[1], size);
471 size = (*it)->GetIOTypeValueStr().Length() * wxWindow::GetCharWidth();
472 m_header_column_widths[2] = std::max(m_header_column_widths[2], size);
473 sp = wxString((*it)->GetStrippedDSPort());
474 size = sp.Length() * wxWindow::GetCharWidth();
475 m_header_column_widths[3] = std::max(m_header_column_widths[3], size);
478 OnConnectionChange(m_connections);
482 for (
auto val : m_header_column_widths) {
483 SetColSize(ic,
static_cast<int>(val));
494 : m_conns(connections) {}
499 if (row1 == -1 && row2 == -1)
return false;
500 if (row1 == -1)
return false;
501 if (row2 == -1)
return true;
502 const int v1 = m_conns->GetCellValue(row1, 4)[0];
503 const int v2 = m_conns->GetCellValue(row2, 4)[0];
516 auto found = find_if(
517 m_connections.begin(), m_connections.end(),
519 if (found == m_connections.end())
return -1;
520 return static_cast<int>(found - m_connections.begin());
529 auto found = find_if(m_connections.begin(), m_connections.end(),
531 return GetCellValue(row, 7) == p->GetKey();
533 return found != m_connections.end() ? *found :
nullptr;
540 void EnsureRows(
size_t rows) {
541 for (
unsigned i = m_tooltips.size(); i <= rows; i++)
542 m_tooltips.emplace_back(std::vector<std::string>(7));
543 for (
unsigned i = GetNumberRows(); i <= rows; i++) AppendRows(1,
false);
547 void SetColAttributes(
const wxWindow* parent) {
550 SetDefaultCellBackgroundColour(GetGlobalColor(
"DILG1"));
552 auto enable_attr =
new wxGridCellAttr();
553 enable_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
556 enable_attr->SetRenderer(
559 enable_attr->SetRenderer(
new wxGridCellBoolRenderer());
561 enable_attr->SetEditor(
new wxGridCellBoolEditor());
562 if (IsWindows()) enable_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
563 SetColAttr(0, enable_attr);
565 auto protocol_attr =
new wxGridCellAttr();
566 protocol_attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
567 protocol_attr->SetReadOnly(
true);
569 protocol_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
570 SetColAttr(1, protocol_attr);
572 auto in_out_attr =
new wxGridCellAttr();
573 in_out_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
574 in_out_attr->SetReadOnly(
true);
575 if (IsWindows()) in_out_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
576 SetColAttr(2, in_out_attr);
578 auto port_attr =
new wxGridCellAttr();
579 port_attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
580 port_attr->SetReadOnly(
true);
581 if (IsWindows()) port_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
582 SetColAttr(3, port_attr);
584 auto status_attr =
new wxGridCellAttr();
585 status_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
586 status_attr->SetReadOnly(
true);
587 status_attr->SetFont(parent->GetFont().Scale(1.3));
588 if (IsWindows()) status_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
589 SetColAttr(4, status_attr);
591 auto edit_attr =
new wxGridCellAttr();
592 edit_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
593 edit_attr->SetFont(parent->GetFont().Scale(1.3));
594 edit_attr->SetReadOnly(
true);
595 if (IsWindows()) edit_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
596 SetColAttr(5, edit_attr);
598 auto delete_attr =
new wxGridCellAttr();
599 delete_attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
600 delete_attr->SetFont(parent->GetFont().Scale(1.3));
601 delete_attr->SetTextColour(*wxRED);
602 delete_attr->SetReadOnly(
true);
603 if (IsWindows()) delete_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
604 SetColAttr(6, delete_attr);
608 void OnClickCell(
int row,
int col) {
613 }
else if (col == 6) {
619 void OnMouseMove(
const wxMouseEvent& ev) {
620 const wxPoint pt = ev.GetPosition();
621 int row = YToRow(pt.y);
622 int col = XToCol(pt.x);
623 if (col < 0 || col >= 7 || row < 0 || row >= GetNumberRows())
return;
624 if (row * 7 + col == m_last_tooltip_cell)
return;
625 m_last_tooltip_cell = row * 7 + col;
626 GetGridWindow()->SetToolTip(m_tooltips[row][col]);
630 void OnConnectionChange(
const std::vector<ConnectionParams*>& connections) {
631 bool refresh_needed =
false;
632 for (
auto it = connections.begin(); it != connections.end(); ++it) {
633 ConnState state = m_conn_states.GetDriverState(
634 (*it)->GetCommProtocol(), (*it)->GetStrippedDSPort());
635 if (!(*it)->bEnabled) state = ConnState::Disabled;
636 auto row =
static_cast<int>(it - connections.begin());
638 if (
static_cast<int>(m_renderer_status_vector.size()) < row + 1)
continue;
640 case ConnState::Disabled:
641 if (m_renderer_status_vector[row]->status != ConnState::Disabled) {
642 m_renderer_status_vector[row]->SetBitmap(m_icons.filled_circle);
643 m_renderer_status_vector[row]->status = ConnState::Disabled;
644 refresh_needed =
true;
646 m_tooltips[row][4] = _(
"Disabled");
648 case ConnState::NoStats:
649 if (m_renderer_status_vector[row]->status != ConnState::NoStats) {
650 m_renderer_status_vector[row]->SetBitmap(m_icons.open_circle);
651 m_renderer_status_vector[row]->status = ConnState::NoStats;
652 refresh_needed =
true;
654 m_tooltips[row][4] = _(
"No driver statistics available");
656 case ConnState::NoData:
657 if (m_renderer_status_vector[row]->status != ConnState::NoData) {
658 m_renderer_status_vector[row]->SetBitmap(m_icons.exclaim_mark);
659 m_renderer_status_vector[row]->status = ConnState::NoData;
660 refresh_needed =
true;
662 m_tooltips[row][4] = _(
"No data flowing through connection");
664 case ConnState::Unavailable:
665 if (m_renderer_status_vector[row]->status != ConnState::Unavailable) {
666 m_renderer_status_vector[row]->SetBitmap(m_icons.x_mult);
667 m_renderer_status_vector[row]->status = ConnState::Unavailable;
668 refresh_needed =
true;
670 m_tooltips[row][4] = _(
"The device is unavailable");
673 if (m_renderer_status_vector[row]->status != ConnState::Ok) {
674 m_renderer_status_vector[row]->SetBitmap(m_icons.check_mark);
675 m_renderer_status_vector[row]->status = ConnState::Ok;
676 refresh_needed =
true;
678 m_tooltips[row][4] = _(
"Data is flowing");
682 if (refresh_needed) ForceRefresh();
686 void SetSortingColumn(
int col) {
687 if (GetSortingColumn() != wxNOT_FOUND) {
688 int old_col = GetSortingColumn();
689 auto label = GetColLabelValue(old_col);
690 if (label[0] == UtfArrowDown()[0])
691 SetColLabelValue(old_col, label.substr(2));
693 auto label = GetColLabelValue(col);
694 if (label[0] != UtfArrowDown()[0])
695 SetColLabelValue(col, UtfArrowDown() +
" " + label);
696 wxGrid::SetSortingColumn(col);
701 void HandleSort(
int col) {
703 auto& params = TheConnectionParams();
705 std::sort(params.begin(), params.end(),
ConnCompare(col));
707 std::sort(params.begin(), params.end(), ConnStateCompare(
this));
709 SetSortingColumn(col);
713 void HandleEnable(
int row) {
716 cp->bEnabled = !cp->bEnabled;
717 cp->b_IsSetup = FALSE;
718 SetCellValue(row, 0, cp->bEnabled ?
"1" :
"");
720 m_tooltips[row][0] = _(
"Enabled, click to disable");
722 m_tooltips[row][0] = _(
"Disabled, click to enable");
724 stats.driver_iface = cp->GetStrippedDSPort();
725 stats.driver_bus = cp->GetCommProtocol();
726 m_conn_states.HandleDriverStats(stats);
727 StopAndRemoveCommDriver(cp->GetStrippedDSPort(), cp->GetCommProtocol());
729 cp->b_IsSetup =
true;
731 SetCellValue(row, 4, UtfFilledCircle());
738 void HandleEdit(
int row) {
740 Show(GetNumberRows() > 0);
741 m_on_edit_conn(cp,
true);
746 void HandleDelete(
int row) {
748 auto found = std::find(m_connections.begin(), m_connections.end(), cp);
749 if (found != m_connections.end()) {
750 std::stringstream ss;
751 ss << _(
"Ok to delete connection on ") << (*found)->GetStrippedDSPort();
752 int rcode = OCPNMessageBox(
this, ss.str(), _(
"Delete connection?"),
754 if (rcode != wxID_OK && rcode != wxID_YES)
return;
755 delete (*found)->m_optionsPanel;
756 StopAndRemoveCommDriver((*found)->GetStrippedDSPort(),
757 (*found)->GetCommProtocol());
758 TheConnectionParams().erase(found);
759 if (GetNumberRows() >
static_cast<int>(m_connections.size()))
760 DeleteRows(GetNumberRows() - 1);
761 m_on_conn_delete.
Notify();
766 std::vector<std::vector<std::string>> m_tooltips;
768 const std::vector<ConnectionParams*>& m_connections;
769 std::array<unsigned, 7> m_header_column_widths;
770 int m_last_tooltip_cell;
774 std::vector<BitmapCellRenderer*> m_renderer_status_vector;
885 : wxPanel(parent, wxID_ANY) {
886 auto sizer =
new wxStaticBoxSizer(wxVERTICAL,
this,
"");
887 sizer->Add(
new BearingsCheckbox(
this), wxSizerFlags().Expand());
888 sizer->Add(
new ExtraRmbRmcLine(
this), wxSizerFlags().Expand());
889 sizer->Add(
new NmeaFilterRow(
this), wxSizerFlags().Expand());
890 sizer->Add(
new TalkerIdRow(
this), wxSizerFlags().Expand());
891 sizer->Add(
new NetmaskRow(
this), wxSizerFlags().Expand());
893 wxWindow::SetMaxSize(max_size);
898 class BearingsCheckbox :
public wxCheckBox,
public ApplyCancel {
900 explicit BearingsCheckbox(wxWindow* parent)
901 : wxCheckBox(parent, wxID_ANY,
902 _(
"Use magnetic bearing in output sentence APB")) {
903 wxCheckBox::SetValue(g_bMagneticAPB);
906 void Apply()
override { g_bMagneticAPB = GetValue(); }
907 void Cancel()
override { SetValue(g_bMagneticAPB); }
910 class ExtraRmbRmcLine :
public wxPanel {
911 class RmbRmcCheckbox :
public wxCheckBox,
public ApplyCancel {
913 explicit RmbRmcCheckbox(wxWindow* parent)
914 : wxCheckBox(parent, wxID_ANY,
915 _(
"Always send RMB and RMC NMEA0183 data")) {
924 explicit ExtraRmbRmcLine(wxWindow* parent) : wxPanel(parent, wxID_ANY) {
925 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
926 hbox->Add(
new RmbRmcCheckbox(
this), wxSizerFlags().Expand());
927 hbox->Add(1, 1, 1, wxEXPAND);
928 hbox->Add(
new InfoButton(
this, g_btouch, kInfoHeader, kInfo),
929 wxSizerFlags().Border());
935 class ExtraRmbRmcCheckbox final :
public wxCheckBox,
public ApplyCancel {
937 explicit ExtraRmbRmcCheckbox(wxWindow* parent)
938 : wxCheckBox(parent, wxID_ANY,
939 _(
"Always send RMB and RMC NMEA0183 data")) {
948 class NmeaFilterRow :
public wxPanel,
public ApplyCancel {
949 wxCheckBox* checkbox;
950 wxTextCtrl* filter_period;
953 explicit NmeaFilterRow(wxWindow* parent) : wxPanel(parent) {
954 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
955 checkbox =
new wxCheckBox(
957 _(
"Filter NMEA course and speed data. Filter period: "));
958 checkbox->SetValue(g_bfilter_cogsog);
959 hbox->Add(checkbox, wxSizerFlags().Align(wxALIGN_CENTRE));
961 new wxTextCtrl(
this, wxID_ANY,
"", wxDefaultPosition,
962 wxSize(50, 3 * wxWindow::GetCharWidth()), 0);
963 filter_period->SetValue(std::to_string(g_COGFilterSec));
964 hbox->Add(filter_period, wxSizerFlags().Border());
966 NmeaFilterRow::Cancel();
969 void Apply()
override {
970 std::stringstream ss;
971 ss << filter_period->GetValue();
972 ss >> g_COGFilterSec;
973 g_bfilter_cogsog = checkbox->GetValue();
976 void Cancel()
override {
977 std::stringstream ss;
978 ss << g_COGFilterSec;
979 filter_period->SetValue(ss.str());
980 checkbox->SetValue(g_bfilter_cogsog);
985 class TalkerIdRow :
public wxPanel,
public ApplyCancel {
986 wxTextCtrl* text_ctrl;
989 explicit TalkerIdRow(wxWindow* parent) : wxPanel(parent) {
990 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
991 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"NMEA 0183 Talker Id: ")),
992 wxSizerFlags().Align(wxALIGN_CENTRE_VERTICAL).Border());
993 text_ctrl =
new wxTextCtrl(
994 this, wxID_ANY,
"", wxDefaultPosition,
995 wxSize(4 * wxWindow::GetCharWidth(), 3 * wxWindow::GetCharWidth()));
996 text_ctrl->SetToolTip(
997 _(
"Enter a two-letter talker ID to override the default ID in NMEA "
998 "sentences generated by OpenCPN (e.g., GP, HC, EC). This affects "
999 "only sentences created by OpenCPN, not those forwarded from other "
1001 text_ctrl->SetValue(g_TalkerIdText);
1002 hbox->Add(text_ctrl, wxSizerFlags().Border());
1004 TalkerIdRow::Cancel();
1007 void Apply()
override { g_TalkerIdText = text_ctrl->GetValue(); }
1008 void Cancel()
override { text_ctrl->SetValue(g_TalkerIdText); }
1012 class NetmaskRow :
public wxPanel,
public ApplyCancel {
1014 explicit NetmaskRow(wxWindow* parent)
1016 m_spin_ctrl(
new wxSpinCtrl(
this, wxID_ANY)),
1017 m_text(
new wxStaticText(
this, wxID_ANY,
"")) {
1018 m_spin_ctrl->SetRange(8, 32);
1019 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
1020 auto flags = wxSizerFlags().Align(wxALIGN_CENTRE_VERTICAL).Border();
1021 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"Netmask: ")), flags);
1022 hbox->Add(m_text, flags);
1023 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"length (bits): ")), flags);
1024 hbox->Add(m_spin_ctrl, flags);
1026 NetmaskRow::Cancel();
1028 Bind(wxEVT_SPINCTRL, [&](wxSpinEvent&) {
1029 m_text->SetLabel(BitsToDottedMask(m_spin_ctrl->GetValue()));
1034 void Apply()
override { g_netmask_bits = m_spin_ctrl->GetValue(); }
1036 void Cancel()
override {
1037 m_spin_ctrl->SetValue(g_netmask_bits);
1038 m_text->SetLabel(BitsToDottedMask(m_spin_ctrl->GetValue()));
1043 wxSpinCtrl* m_spin_ctrl;
1044 wxStaticText* m_text;
1051 TopPanel(wxWindow* parent,
const std::vector<ConnectionParams*>& connections,
1055 : wxPanel(parent, wxID_ANY),
1056 m_evt_add_connection(evt_add_connection),
1057 m_connections(connections) {
1058 auto vbox =
new wxBoxSizer(wxVERTICAL);
1059 auto conn_grid =
new Connections(
this, m_connections, m_evt_add_connection,
1061 wxSize panel_max_size(conn_grid->GetEstimatedSize());
1062 vbox->AddSpacer(wxWindow::GetCharHeight());
1063 auto conn_flags = wxSizerFlags().Border();
1064 if (IsAndroid()) conn_flags = wxSizerFlags().Border().Expand();
1065 vbox->Add(conn_grid, conn_flags);
1067 wxSizerFlags().Border());
1068 vbox->Add(0, wxWindow::GetCharHeight());
1070 wxSizerFlags().Border(wxLEFT | wxDOWN | wxRIGHT).Expand();
1071 m_general_panel =
new GeneralPanel(
this, panel_max_size);
1072 vbox->Add(m_general_panel, panel_flags);
1074 auto advanced_panel =
new AdvancedPanel(
this, panel_max_size);
1075 m_advanced_panel = advanced_panel;
1076 auto on_toggle = [&, advanced_panel, vbox](
bool show) {
1078 advanced_panel->Show(show);
1079 vbox->SetSizeHints(
this);
1082 vbox->Add(
new ShowAdvanced(
this, on_toggle), panel_flags);
1083 vbox->Add(advanced_panel, panel_flags.ReserveSpaceEvenIfHidden());
1086 vbox->SetSizeHints(
this);
1091 auto on_evt_update_connections = [&, conn_grid](
ObservedEvt&) {
1092 conn_grid->ReloadGrid(TheConnectionParams());
1093 conn_grid->Show(conn_grid->GetNumberRows() > 0);
1096 m_add_connection_lstnr.
Init(m_evt_add_connection,
1097 on_evt_update_connections);
1098 m_conn_grid = conn_grid;
1101 void SetColorScheme(
const ColorScheme cs)
const {
1102 m_conn_grid->SetColorScheme(cs);
1103 m_general_panel->SetColorScheme(cs);
1105 [[nodiscard]]
Connections* GetConnectionsGrid()
const {
return m_conn_grid; }
1110 const std::vector<ConnectionParams*>& m_connections;
1120 TopScroll(wxWindow* parent,
const std::vector<ConnectionParams*>& connections,
1122 : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
1123 wxVSCROLL | wxHSCROLL, TopScrollWindowName) {
1124 ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
1125 auto vbox =
new wxBoxSizer(wxVERTICAL);
1136 new TopPanel(
this, connections, evt_add_connection, on_edit_connection);
1137 vbox->Add(top_panel, wxSizerFlags(1).Expand());
1141 HandleEditFinish(p, new_mode, ok_cancel);
1145 m_edit_panel->SetPropsLabel(_(
"Edit Selected Connection"));
1146 wxWindow*
options = FindWindowByName(
"Options");
1147 assert(
options &&
"Null Options window!");
1152 m_edit_panel->SetSize(
1153 wxSize(
options->GetSize().x,
options->GetSize().y * fraction / 10));
1154 vbox->Add(m_edit_panel, wxSizerFlags(0).Expand());
1155 m_edit_panel->Hide();
1157 SetScrollRate(0, 10);
1158 if (IsAndroid()) SetScrollRate(1, 1);
1160 SetScrollRate(0, 10);
1161 if (IsAndroid()) SetScrollRate(1, 1);
1164 void SetColorScheme(ColorScheme cs)
const {
1165 if (top_panel) top_panel->SetColorScheme(cs);
1169 m_edit_panel->SetPropsLabel(_(
"Edit Selected Connection"));
1170 m_edit_panel->SetNewMode(
false);
1171 m_edit_panel->PreloadControls(p);
1172 m_edit_panel->AddOKCancelButtons();
1177 m_edit_panel->SetPropsLabel(_(
"Configure new connection"));
1178 m_edit_panel->SetDefaultConnectionParams();
1179 m_edit_panel->SetNewMode(
true);
1180 m_edit_panel->AddOKCancelButtons();
1184 void SwitchToEditor() {
1187 DimeControl(m_edit_panel);
1188 m_edit_panel->Show();
1194 void SwitchToGrid() {
1196 m_edit_panel->Hide();
1198 top_panel->GetConnectionsGrid()->
ReloadGrid(TheConnectionParams());
1212 delete cp_orig->m_optionsPanel;
1213 StopAndRemoveCommDriver(cp_orig->GetStrippedDSPort(),
1214 cp_orig->GetCommProtocol());
1216 assert(index != -1 &&
"Cannot look up connection index");
1217 TheConnectionParams()[index] = cp_edited;
1218 cp_edited->b_IsSetup =
false;
1223 if (cp->GetValidPort()) {
1224 cp->b_IsSetup =
false;
1225 TheConnectionParams().push_back(cp);
1228 _(
"Unable to create a connection as configured. "
1229 "Connected port or address was missing.");
1230 auto& noteman = NotificationManager::GetInstance();
1231 noteman.AddNotification(NotificationSeverity::kWarning,
1232 msg.ToStdString(), 60);
1235 UpdateDatastreams();
1236 top_panel->m_evt_add_connection.
Notify();
1240 UpdateDatastreams();