150 const unsigned m_size;
151 const fs::path m_svg_dir;
155 static unsigned GetSize(
const wxWindow* parent) {
156 double size = parent->GetCharHeight() * (IsWindows() ? 1.3 : 1.0);
157#if wxCHECK_VERSION(3, 1, 2)
160 size *=
static_cast<double>(parent->ToDIP(100)) / 100.;
164 double pixel_per_mm =
166 size = std::max(size, 7.0 * pixel_per_mm);
168 return static_cast<unsigned>(size);
171 [[nodiscard]] wxBitmap LoadIcon(
const std::string& filename)
const {
172 fs::path path = m_svg_dir / filename;
173 return LoadSVG(path.string(), m_size, m_size);
176 [[nodiscard]] wxBitmap IconApplyColorScheme(
const wxBitmap& proto)
const {
177 if (!proto.IsOk())
return wxNullBitmap;
178 if ((m_cs != GLOBAL_COLOR_SCHEME_DAY) &&
179 (m_cs != GLOBAL_COLOR_SCHEME_RGB)) {
181 const wxImage image = proto.ConvertToImage();
182 unsigned char* data = image.GetData();
183 unsigned char* p_idata = data;
184 for (
int i = 0; i < image.GetSize().y; i++) {
185 for (
int j = 0; j < image.GetSize().x; j++) {
186 unsigned char v = *p_idata;
203 explicit StdIcons(
const wxWindow* parent)
204 : m_size(GetSize(parent)),
205 m_svg_dir(fs::path(g_Platform->GetSharedDataDir().ToStdString()) /
206 "uidata" /
"MUI_flat"),
207 m_cs(GLOBAL_COLOR_SCHEME_RGB),
208 trash_bin_proto(LoadIcon(
"trash_bin.svg")),
209 settings_proto(LoadIcon(
"setting_gear.svg")),
210 filled_circle_proto(LoadIcon(
"circle-on.svg")),
211 open_circle_proto(LoadIcon(
"circle-off.svg")),
212 exclaim_mark_proto(LoadIcon(
"exclaim_mark.svg")),
213 x_mult_proto(LoadIcon(
"X_mult.svg")),
214 check_mark_proto(LoadIcon(
"check_mark.svg")) {
215 trash_bin = trash_bin_proto;
216 settings = settings_proto;
217 filled_circle = filled_circle_proto;
218 open_circle = open_circle_proto;
219 exclaim_mark = exclaim_mark_proto;
220 x_mult = x_mult_proto;
221 check_mark = check_mark_proto;
224 void SetColorScheme(
const ColorScheme cs) {
227 trash_bin = IconApplyColorScheme(trash_bin_proto);
228 settings = IconApplyColorScheme(settings_proto);
229 filled_circle = IconApplyColorScheme(filled_circle_proto);
230 open_circle = IconApplyColorScheme(open_circle_proto);
231 exclaim_mark = IconApplyColorScheme(exclaim_mark_proto);
232 x_mult = IconApplyColorScheme(x_mult_proto);
233 check_mark = IconApplyColorScheme(check_mark_proto);
237 const wxBitmap trash_bin_proto;
238 const wxBitmap settings_proto;
239 const wxBitmap filled_circle_proto;
240 const wxBitmap open_circle_proto;
241 const wxBitmap exclaim_mark_proto;
242 const wxBitmap x_mult_proto;
243 const wxBitmap check_mark_proto;
247 wxBitmap filled_circle;
248 wxBitmap open_circle;
249 wxBitmap exclaim_mark;
382 const std::vector<ConnectionParams*>& connections,
386 : wxGrid(parent, wxID_ANY),
387 m_connections(connections),
388 m_header_column_widths({0, 0, 0, 0, 0, 0, 0}),
389 m_last_tooltip_cell(100),
390 m_cs(GLOBAL_COLOR_SCHEME_DAY),
391 m_on_conn_delete(on_conn_update),
393 m_on_edit_conn(on_edit_conn) {
394 ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
395 SetTable(
new wxGridStringTable(),
true);
396 GetTable()->AppendCols(8);
399 SetDefaultRowSize(wxWindow::GetCharHeight() * 2);
400 SetColLabelSize(wxWindow::GetCharHeight() * 2);
402 static const std::array<wxString, 7> headers = {
403 "", _(
"Protocol") +
" ", _(
"In/Out"), _(
"Data port"), _(
"Status"),
"",
406 for (
auto hdr = headers.begin(); hdr != headers.end(); hdr++, ic++) {
407 SetColLabelValue(
static_cast<int>(hdr - headers.begin()), *hdr);
408 unsigned col_width = hdr->Length() * wxWindow::GetCharWidth();
409 col_width = wxMax(col_width, 6 * wxWindow::GetCharWidth());
410 m_header_column_widths[ic] =
static_cast<int>(col_width);
411 SetColSize(ic,
static_cast<int>(col_width));
415 SetLabelBackgroundColour(GetGlobalColor(
"DILG1"));
416 SetLabelTextColour(GetGlobalColor(
"DILG3"));
419 SetColAttributes(parent);
422 DisableDragColSize();
423 DisableDragRowSize();
424 wxWindow::Show(GetNumberRows() > 0);
426 GetGridWindow()->Bind(wxEVT_MOTION, [&](wxMouseEvent& ev) {
430 GetGridWindow()->Bind(wxEVT_MOUSEWHEEL,
431 [&](
const wxMouseEvent& ev) {
OnWheel(ev); });
433 Bind(wxEVT_GRID_LABEL_LEFT_CLICK,
434 [&](wxGridEvent& ev) { HandleSort(ev.GetCol()); });
435 Bind(wxEVT_GRID_CELL_LEFT_CLICK,
436 [&](wxGridEvent& ev) { OnClickCell(ev.GetRow(), ev.GetCol()); });
437 Bind(wxEVT_PAINT, [&](wxPaintEvent& ev) {
438 SetColAttributes(
dynamic_cast<const wxWindow*
>(ev.GetEventObject()));
441 conn_change_lstnr.
Init(
443 [&](
ObservedEvt&) { OnConnectionChange(m_connections); });
445 void SetColorScheme(
const ColorScheme cs) {
447 m_icons.SetColorScheme(cs);
451 wxSize GetEstimatedSize()
const {
453 for (
auto s : m_header_column_widths) rs += s;
454 return {
static_cast<int>(rs), -1};
460 dynamic_cast<wxScrolledWindow*
>(FindWindowByName(TopScrollWindowName));
461 assert(w &&
"No TopScroll window found");
464 w->GetViewStart(&xpos, &ypos);
467 w->GetScrollPixelsPerUnit(&x, &y);
469 const int dir = ev.GetWheelRotation();
470 w->Scroll(-1, ypos - dir / y / 4);
474 void ReloadGrid(
const std::vector<ConnectionParams*>& connections) {
476 m_renderer_status_vector.clear();
478 for (
auto it = connections.begin(); it != connections.end(); ++it) {
479 const auto row =
static_cast<int>(it - connections.begin());
481 SetCellValue(row, 0, (*it)->bEnabled ?
"1" :
"");
483 m_tooltips[row][0] = _(
"Enabled, click to disable");
485 m_tooltips[row][0] = _(
"Disabled, click to enable");
486 std::string protocol = NavAddr::BusToString((*it)->GetCommProtocol());
487 SetCellValue(row, 1, protocol);
488 SetCellValue(row, 2, (*it)->GetIOTypeValueStr());
489 SetCellValue(row, 3, (*it)->GetStrippedDSPort());
490 m_tooltips[row][3] = (*it)->UserComment;
492 m_tooltips[row][5] = _(
"Edit connection");
494 m_tooltips[row][6] = _(
"Delete connection");
495 SetCellValue(row, 7, (*it)->GetKey());
498 stat_renderer->status = ConnState::Disabled;
499 m_renderer_status_vector.push_back(stat_renderer);
500 SetCellRenderer(row, 4, stat_renderer);
502 wxString sp(protocol);
503 unsigned size = sp.Length() * wxWindow::GetCharWidth();
504 m_header_column_widths[1] = std::max(m_header_column_widths[1], size);
505 size = (*it)->GetIOTypeValueStr().Length() * wxWindow::GetCharWidth();
506 m_header_column_widths[2] = std::max(m_header_column_widths[2], size);
507 sp = wxString((*it)->GetStrippedDSPort());
508 size = sp.Length() * wxWindow::GetCharWidth();
509 m_header_column_widths[3] = std::max(m_header_column_widths[3], size);
512 OnConnectionChange(m_connections);
516 for (
auto val : m_header_column_widths) {
517 SetColSize(ic,
static_cast<int>(val));
528 : m_conns(connections) {}
533 if (row1 == -1 && row2 == -1)
return false;
534 if (row1 == -1)
return false;
535 if (row2 == -1)
return true;
536 const int v1 = m_conns->GetCellValue(row1, 4)[0];
537 const int v2 = m_conns->GetCellValue(row2, 4)[0];
550 auto found = find_if(
551 m_connections.begin(), m_connections.end(),
553 if (found == m_connections.end())
return -1;
554 return static_cast<int>(found - m_connections.begin());
563 auto found = find_if(m_connections.begin(), m_connections.end(),
565 return GetCellValue(row, 7) == p->GetKey();
567 return found != m_connections.end() ? *found :
nullptr;
574 void EnsureRows(
size_t rows) {
575 for (
unsigned i = m_tooltips.size(); i <= rows; i++)
576 m_tooltips.emplace_back(std::vector<std::string>(7));
577 for (
unsigned i = GetNumberRows(); i <= rows; i++) AppendRows(1,
false);
581 void SetColAttributes(
const wxWindow* parent) {
584 SetDefaultCellBackgroundColour(GetGlobalColor(
"DILG1"));
586 auto enable_attr =
new wxGridCellAttr();
587 enable_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
590 enable_attr->SetRenderer(
593 enable_attr->SetRenderer(
new wxGridCellBoolRenderer());
595 enable_attr->SetEditor(
new wxGridCellBoolEditor());
596 if (IsWindows()) enable_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
597 SetColAttr(0, enable_attr);
599 auto protocol_attr =
new wxGridCellAttr();
600 protocol_attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
601 protocol_attr->SetReadOnly(
true);
603 protocol_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
604 SetColAttr(1, protocol_attr);
606 auto in_out_attr =
new wxGridCellAttr();
607 in_out_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
608 in_out_attr->SetReadOnly(
true);
609 if (IsWindows()) in_out_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
610 SetColAttr(2, in_out_attr);
612 auto port_attr =
new wxGridCellAttr();
613 port_attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
614 port_attr->SetReadOnly(
true);
615 if (IsWindows()) port_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
616 SetColAttr(3, port_attr);
618 auto status_attr =
new wxGridCellAttr();
619 status_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
620 status_attr->SetReadOnly(
true);
621 status_attr->SetFont(parent->GetFont().Scale(1.3));
622 if (IsWindows()) status_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
623 SetColAttr(4, status_attr);
625 auto edit_attr =
new wxGridCellAttr();
626 edit_attr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
627 edit_attr->SetFont(parent->GetFont().Scale(1.3));
628 edit_attr->SetReadOnly(
true);
629 if (IsWindows()) edit_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
630 SetColAttr(5, edit_attr);
632 auto delete_attr =
new wxGridCellAttr();
633 delete_attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
634 delete_attr->SetFont(parent->GetFont().Scale(1.3));
635 delete_attr->SetTextColour(*wxRED);
636 delete_attr->SetReadOnly(
true);
637 if (IsWindows()) delete_attr->SetBackgroundColour(GetGlobalColor(
"DILG1"));
638 SetColAttr(6, delete_attr);
642 void OnClickCell(
int row,
int col) {
647 }
else if (col == 6) {
653 void OnMouseMove(
const wxMouseEvent& ev) {
654 const wxPoint pt = ev.GetPosition();
655 int row = YToRow(pt.y);
656 int col = XToCol(pt.x);
657 if (col < 0 || col >= 7 || row < 0 || row >= GetNumberRows())
return;
658 if (row * 7 + col == m_last_tooltip_cell)
return;
659 m_last_tooltip_cell = row * 7 + col;
660 GetGridWindow()->SetToolTip(m_tooltips[row][col]);
664 void OnConnectionChange(
const std::vector<ConnectionParams*>& connections) {
665 bool refresh_needed =
false;
666 for (
auto it = connections.begin(); it != connections.end(); ++it) {
667 ConnState state = m_conn_states.GetDriverState(
668 (*it)->GetCommProtocol(), (*it)->GetStrippedDSPort());
669 if (!(*it)->bEnabled) state = ConnState::Disabled;
670 auto row =
static_cast<int>(it - connections.begin());
672 if (
static_cast<int>(m_renderer_status_vector.size()) < row + 1)
continue;
674 case ConnState::Disabled:
675 if (m_renderer_status_vector[row]->status != ConnState::Disabled) {
676 m_renderer_status_vector[row]->SetBitmap(m_icons.filled_circle);
677 m_renderer_status_vector[row]->status = ConnState::Disabled;
678 refresh_needed =
true;
680 m_tooltips[row][4] = _(
"Disabled");
682 case ConnState::NoStats:
683 if (m_renderer_status_vector[row]->status != ConnState::NoStats) {
684 m_renderer_status_vector[row]->SetBitmap(m_icons.open_circle);
685 m_renderer_status_vector[row]->status = ConnState::NoStats;
686 refresh_needed =
true;
688 m_tooltips[row][4] = _(
"No driver statistics available");
690 case ConnState::NoData:
691 if (m_renderer_status_vector[row]->status != ConnState::NoData) {
692 m_renderer_status_vector[row]->SetBitmap(m_icons.exclaim_mark);
693 m_renderer_status_vector[row]->status = ConnState::NoData;
694 refresh_needed =
true;
696 m_tooltips[row][4] = _(
"No data flowing through connection");
698 case ConnState::Unavailable:
699 if (m_renderer_status_vector[row]->status != ConnState::Unavailable) {
700 m_renderer_status_vector[row]->SetBitmap(m_icons.x_mult);
701 m_renderer_status_vector[row]->status = ConnState::Unavailable;
702 refresh_needed =
true;
704 m_tooltips[row][4] = _(
"The device is unavailable");
707 if (m_renderer_status_vector[row]->status != ConnState::Ok) {
708 m_renderer_status_vector[row]->SetBitmap(m_icons.check_mark);
709 m_renderer_status_vector[row]->status = ConnState::Ok;
710 refresh_needed =
true;
712 m_tooltips[row][4] = _(
"Data is flowing");
716 if (refresh_needed) ForceRefresh();
720 void SetSortingColumn(
int col) {
721 if (GetSortingColumn() != wxNOT_FOUND) {
722 int old_col = GetSortingColumn();
723 auto label = GetColLabelValue(old_col);
724 if (label[0] == UtfArrowDown()[0])
725 SetColLabelValue(old_col, label.substr(2));
727 auto label = GetColLabelValue(col);
728 if (label[0] != UtfArrowDown()[0])
729 SetColLabelValue(col, UtfArrowDown() +
" " + label);
730 wxGrid::SetSortingColumn(col);
735 void HandleSort(
int col) {
737 auto& params = TheConnectionParams();
739 std::sort(params.begin(), params.end(),
ConnCompare(col));
741 std::sort(params.begin(), params.end(), ConnStateCompare(
this));
743 SetSortingColumn(col);
747 void HandleEnable(
int row) {
750 cp->bEnabled = !cp->bEnabled;
751 cp->b_IsSetup = FALSE;
752 SetCellValue(row, 0, cp->bEnabled ?
"1" :
"");
754 m_tooltips[row][0] = _(
"Enabled, click to disable");
756 m_tooltips[row][0] = _(
"Disabled, click to enable");
758 stats.driver_iface = cp->GetStrippedDSPort();
759 stats.driver_bus = cp->GetCommProtocol();
760 m_conn_states.HandleDriverStats(stats);
761 StopAndRemoveCommDriver(cp->GetStrippedDSPort(), cp->GetCommProtocol());
763 cp->b_IsSetup =
true;
765 SetCellValue(row, 4, UtfFilledCircle());
772 void HandleEdit(
int row) {
774 Show(GetNumberRows() > 0);
775 m_on_edit_conn(cp,
true);
780 void HandleDelete(
int row) {
782 auto found = std::find(m_connections.begin(), m_connections.end(), cp);
783 if (found != m_connections.end()) {
784 std::stringstream ss;
785 ss << _(
"Ok to delete connection on ") << (*found)->GetStrippedDSPort();
786 int rcode = OCPNMessageBox(
this, ss.str(), _(
"Delete connection?"),
788 if (rcode != wxID_OK && rcode != wxID_YES)
return;
789 delete (*found)->m_optionsPanel;
790 StopAndRemoveCommDriver((*found)->GetStrippedDSPort(),
791 (*found)->GetCommProtocol());
792 TheConnectionParams().erase(found);
793 if (GetNumberRows() >
static_cast<int>(m_connections.size()))
794 DeleteRows(GetNumberRows() - 1);
795 m_on_conn_delete.
Notify();
800 std::vector<std::vector<std::string>> m_tooltips;
802 const std::vector<ConnectionParams*>& m_connections;
803 std::array<unsigned, 7> m_header_column_widths;
804 int m_last_tooltip_cell;
808 std::vector<BitmapCellRenderer*> m_renderer_status_vector;
919 : wxPanel(parent, wxID_ANY) {
920 auto sizer =
new wxStaticBoxSizer(wxVERTICAL,
this,
"");
921 sizer->Add(
new BearingsCheckbox(
this), wxSizerFlags().Expand());
922 sizer->Add(
new ExtraRmbRmcLine(
this), wxSizerFlags().Expand());
923 sizer->Add(
new NmeaFilterRow(
this), wxSizerFlags().Expand());
924 sizer->Add(
new TalkerIdRow(
this), wxSizerFlags().Expand());
925 sizer->Add(
new NetmaskRow(
this), wxSizerFlags().Expand());
927 wxWindow::SetMaxSize(max_size);
932 class BearingsCheckbox :
public wxCheckBox,
public ApplyCancel {
934 explicit BearingsCheckbox(wxWindow* parent)
935 : wxCheckBox(parent, wxID_ANY,
936 _(
"Use magnetic bearing in output sentence APB")) {
937 wxCheckBox::SetValue(g_bMagneticAPB);
940 void Apply()
override { g_bMagneticAPB = GetValue(); }
941 void Cancel()
override { SetValue(g_bMagneticAPB); }
944 class ExtraRmbRmcLine :
public wxPanel {
945 class RmbRmcCheckbox :
public wxCheckBox,
public ApplyCancel {
947 explicit RmbRmcCheckbox(wxWindow* parent)
948 : wxCheckBox(parent, wxID_ANY,
949 _(
"Always send RMB and RMC NMEA0183 data")) {
958 explicit ExtraRmbRmcLine(wxWindow* parent) : wxPanel(parent, wxID_ANY) {
959 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
960 hbox->Add(
new RmbRmcCheckbox(
this), wxSizerFlags().Expand());
961 hbox->Add(1, 1, 1, wxEXPAND);
962 hbox->Add(
new InfoButton(
this, g_btouch, kInfoHeader, kInfo),
963 wxSizerFlags().Border());
969 class ExtraRmbRmcCheckbox final :
public wxCheckBox,
public ApplyCancel {
971 explicit ExtraRmbRmcCheckbox(wxWindow* parent)
972 : wxCheckBox(parent, wxID_ANY,
973 _(
"Always send RMB and RMC NMEA0183 data")) {
982 class NmeaFilterRow :
public wxPanel,
public ApplyCancel {
983 wxCheckBox* checkbox;
984 wxTextCtrl* filter_period;
987 explicit NmeaFilterRow(wxWindow* parent) : wxPanel(parent) {
988 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
989 checkbox =
new wxCheckBox(
991 _(
"Filter NMEA course and speed data. Filter period: "));
992 checkbox->SetValue(g_bfilter_cogsog);
993 hbox->Add(checkbox, wxSizerFlags().Align(wxALIGN_CENTRE));
995 new wxTextCtrl(
this, wxID_ANY,
"", wxDefaultPosition,
996 wxSize(50, 3 * wxWindow::GetCharWidth()), 0);
997 filter_period->SetValue(std::to_string(g_COGFilterSec));
998 hbox->Add(filter_period, wxSizerFlags().Border());
1000 NmeaFilterRow::Cancel();
1003 void Apply()
override {
1004 std::stringstream ss;
1005 ss << filter_period->GetValue();
1006 ss >> g_COGFilterSec;
1007 g_bfilter_cogsog = checkbox->GetValue();
1010 void Cancel()
override {
1011 std::stringstream ss;
1012 ss << g_COGFilterSec;
1013 filter_period->SetValue(ss.str());
1014 checkbox->SetValue(g_bfilter_cogsog);
1019 class TalkerIdRow :
public wxPanel,
public ApplyCancel {
1020 wxTextCtrl* text_ctrl;
1023 explicit TalkerIdRow(wxWindow* parent) : wxPanel(parent) {
1024 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
1025 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"NMEA 0183 Talker Id: ")),
1026 wxSizerFlags().Align(wxALIGN_CENTRE_VERTICAL).Border());
1027 text_ctrl =
new wxTextCtrl(
1028 this, wxID_ANY,
"", wxDefaultPosition,
1029 wxSize(4 * wxWindow::GetCharWidth(), 3 * wxWindow::GetCharWidth()));
1030 text_ctrl->SetToolTip(
1031 _(
"Enter a two-letter talker ID to override the default ID in NMEA "
1032 "sentences generated by OpenCPN (e.g., GP, HC, EC). This affects "
1033 "only sentences created by OpenCPN, not those forwarded from other "
1035 text_ctrl->SetValue(g_TalkerIdText);
1036 hbox->Add(text_ctrl, wxSizerFlags().Border());
1038 TalkerIdRow::Cancel();
1041 void Apply()
override { g_TalkerIdText = text_ctrl->GetValue(); }
1042 void Cancel()
override { text_ctrl->SetValue(g_TalkerIdText); }
1046 class NetmaskRow :
public wxPanel,
public ApplyCancel {
1048 explicit NetmaskRow(wxWindow* parent)
1050 m_spin_ctrl(
new wxSpinCtrl(
this, wxID_ANY)),
1051 m_text(
new wxStaticText(
this, wxID_ANY,
"")) {
1052 m_spin_ctrl->SetRange(8, 32);
1053 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
1054 auto flags = wxSizerFlags().Align(wxALIGN_CENTRE_VERTICAL).Border();
1055 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"Netmask: ")), flags);
1056 hbox->Add(m_text, flags);
1057 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"length (bits): ")), flags);
1058 hbox->Add(m_spin_ctrl, flags);
1060 NetmaskRow::Cancel();
1062 Bind(wxEVT_SPINCTRL, [&](wxSpinEvent&) {
1063 m_text->SetLabel(BitsToDottedMask(m_spin_ctrl->GetValue()));
1068 void Apply()
override { g_netmask_bits = m_spin_ctrl->GetValue(); }
1070 void Cancel()
override {
1071 m_spin_ctrl->SetValue(g_netmask_bits);
1072 m_text->SetLabel(BitsToDottedMask(m_spin_ctrl->GetValue()));
1077 wxSpinCtrl* m_spin_ctrl;
1078 wxStaticText* m_text;
1085 TopPanel(wxWindow* parent,
const std::vector<ConnectionParams*>& connections,
1089 : wxPanel(parent, wxID_ANY),
1090 m_evt_add_connection(evt_add_connection),
1091 m_connections(connections) {
1092 auto vbox =
new wxBoxSizer(wxVERTICAL);
1093 auto conn_grid =
new Connections(
this, m_connections, m_evt_add_connection,
1095 wxSize panel_max_size(conn_grid->GetEstimatedSize());
1096 vbox->AddSpacer(wxWindow::GetCharHeight());
1097 auto conn_flags = wxSizerFlags().Border();
1098 if (IsAndroid()) conn_flags = wxSizerFlags().Border().Expand();
1099 vbox->Add(conn_grid, conn_flags);
1101 wxSizerFlags().Border());
1102 vbox->Add(0, wxWindow::GetCharHeight());
1104 wxSizerFlags().Border(wxLEFT | wxDOWN | wxRIGHT).Expand();
1105 m_general_panel =
new GeneralPanel(
this, panel_max_size);
1106 vbox->Add(m_general_panel, panel_flags);
1108 auto advanced_panel =
new AdvancedPanel(
this, panel_max_size);
1109 m_advanced_panel = advanced_panel;
1110 auto on_toggle = [&, advanced_panel, vbox](
bool show) {
1112 advanced_panel->Show(show);
1113 vbox->SetSizeHints(
this);
1116 vbox->Add(
new ShowAdvanced(
this, on_toggle), panel_flags);
1117 vbox->Add(advanced_panel, panel_flags.ReserveSpaceEvenIfHidden());
1120 vbox->SetSizeHints(
this);
1125 auto on_evt_update_connections = [&, conn_grid](
ObservedEvt&) {
1126 conn_grid->ReloadGrid(TheConnectionParams());
1127 conn_grid->Show(conn_grid->GetNumberRows() > 0);
1130 m_add_connection_lstnr.
Init(m_evt_add_connection,
1131 on_evt_update_connections);
1132 m_conn_grid = conn_grid;
1135 void SetColorScheme(
const ColorScheme cs)
const {
1136 m_conn_grid->SetColorScheme(cs);
1137 m_general_panel->SetColorScheme(cs);
1139 [[nodiscard]]
Connections* GetConnectionsGrid()
const {
return m_conn_grid; }
1144 const std::vector<ConnectionParams*>& m_connections;
1154 TopScroll(wxWindow* parent,
const std::vector<ConnectionParams*>& connections,
1156 : wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
1157 wxVSCROLL | wxHSCROLL, TopScrollWindowName) {
1158 ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS);
1159 auto vbox =
new wxBoxSizer(wxVERTICAL);
1170 new TopPanel(
this, connections, evt_add_connection, on_edit_connection);
1171 vbox->Add(top_panel, wxSizerFlags(1).Expand());
1175 HandleEditFinish(p, new_mode, ok_cancel);
1179 m_edit_panel->SetPropsLabel(_(
"Edit Selected Connection"));
1180 wxWindow*
options = FindWindowByName(
"Options");
1181 assert(
options &&
"Null Options window!");
1186 m_edit_panel->SetSize(
1187 wxSize(
options->GetSize().x,
options->GetSize().y * fraction / 10));
1188 vbox->Add(m_edit_panel, wxSizerFlags(0).Expand());
1189 m_edit_panel->Hide();
1191 SetScrollRate(0, 10);
1192 if (IsAndroid()) SetScrollRate(1, 1);
1194 SetScrollRate(0, 10);
1195 if (IsAndroid()) SetScrollRate(1, 1);
1198 void SetColorScheme(ColorScheme cs)
const {
1199 if (top_panel) top_panel->SetColorScheme(cs);
1203 m_edit_panel->SetPropsLabel(_(
"Edit Selected Connection"));
1204 m_edit_panel->SetNewMode(
false);
1205 m_edit_panel->PreloadControls(p);
1206 m_edit_panel->AddOKCancelButtons();
1211 m_edit_panel->SetPropsLabel(_(
"Configure new connection"));
1212 m_edit_panel->SetDefaultConnectionParams();
1213 m_edit_panel->SetNewMode(
true);
1214 m_edit_panel->AddOKCancelButtons();
1218 void SwitchToEditor() {
1221 DimeControl(m_edit_panel);
1222 m_edit_panel->Show();
1228 void SwitchToGrid() {
1230 m_edit_panel->Hide();
1232 top_panel->GetConnectionsGrid()->
ReloadGrid(TheConnectionParams());
1246 delete cp_orig->m_optionsPanel;
1247 StopAndRemoveCommDriver(cp_orig->GetStrippedDSPort(),
1248 cp_orig->GetCommProtocol());
1250 assert(index != -1 &&
"Cannot look up connection index");
1251 TheConnectionParams()[index] = cp_edited;
1252 cp_edited->b_IsSetup =
false;
1257 if (FindConnectionByIface(cp)) {
1258 wxMessageDialog dialog(
this, kInterfaceExistsMessage,
1259 _(
"Driver creation warning"),
1260 wxOK | wxCENTRE | wxICON_WARNING);
1263 if (cp->GetValidPort()) {
1264 cp->b_IsSetup =
false;
1265 TheConnectionParams().push_back(cp);
1268 _(
"Unable to create a connection as configured. "
1269 "Connected port or address was missing.");
1270 auto& noteman = NotificationManager::GetInstance();
1271 noteman.AddNotification(NotificationSeverity::kWarning,
1272 msg.ToStdString(), 60);
1275 UpdateDatastreams();
1276 top_panel->m_evt_add_connection.
Notify();
1280 UpdateDatastreams();