Files
alkane-toolkit/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch
T
noahandClaude Opus 4.8 bd17a33ea1 GUI round 2: selection, scan loop, column management, dark-mode fix
- Fixed "Scan ranges" button label (no longer grows with the range list).
- Dark-mode KPI cards: derive colours from the live system theme luminance
  instead of is_dark(), which mis-detected some GTK dark themes.
- Removed the checkbox column; the table is multi-select (wxDV_MULTIPLE,
  ctrl/shift-click), with the selection tracked by IP so it survives refreshes.
- Replaced Rescan with Play / Pause / Stop; added an editable auto-rescan
  interval (scan-ranges dialog; ~/.config/alkane-toolkit/auto-rescan-secs.txt)
  with a timer-driven countdown scheduler.
- Status bar shows the last-probed IP during a scan and a countdown to the next
  scan when idle (dropped the "scan complete" text).
- Default sort is IP-ascending with a header chevron; IP is column 0, sortable.
- Choose-columns dialog is a wxRearrangeCtrl (check to show; up/down or drag to
  reorder) exposing every metric, including Pool 1/2/3 URL + worker.
- Column drag-reorder moves the whole column with its data on drop.
- Row separator lines (wxDV_ROW_LINES). GTK3 native has no zebra striping; a
  GTK4-forward zebra-CSS hook and pkg-config gtk cflags are in place.

Scan engine: parse each configured pool's (url, worker); Progress carries the
last-probed IP. Model: Column::Sel removed; Pool1/2/3 columns; default IP sort.

wx-rs bridge: multi-select + selection/context-menu events + get_selections,
alternating-row + zebra-CSS hooks, in-place column title, rearrangeable list,
and popup-menu primitives (for the upcoming right-click config menu). Patches
0001-0003 regenerated and round-trip validated.

Review fixes: scan loop no longer sticks "scanning" if a thread ends without
Done (channel-disconnect handling + Stop force-reset); Play no longer starts a
second scan; stale selections pruned on rescan; column apply order/visibility
applied atomically.

Verified: 22 unit tests, a 14-check headless UI self-test, and interaction
checks (multi-select, column rearrange/drag, play/pause/stop, dark mode).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-16 17:27:20 -06:00

602 lines
20 KiB
Diff

--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,598 @@
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
+// render-callback bridge (which is kept untouched).
+// See thirdparty/wx-rs/patches/ for the patch queue that carries this file.
+
+#include <wx/wx.h>
+#include <wx/dataview.h>
+#include <wx/checklst.h>
+#include <wx/sizer.h>
+#include <wx/stattext.h>
+#include <wx/textctrl.h>
+#include <wx/button.h>
+#include <wx/checkbox.h>
+#include <wx/dialog.h>
+#include <wx/timer.h>
+#include <wx/vector.h>
+#include <wx/gauge.h>
+#include <wx/settings.h>
+#include <wx/utils.h>
+#include <wx/app.h>
+#include <wx/rearrangectrl.h>
+#include <wx/menu.h>
+#ifdef __WXGTK__
+#include <gtk/gtk.h>
+#endif
+#include <cstdio>
+
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
+static WxWidgetEventFn g_widget_event = nullptr;
+
+// Event kinds (must match Rust WxEventKind in src/widgets.rs)
+enum WxWidgetEventKind {
+ WxEV_BUTTON_CLICKED = 1,
+ WxEV_CLB_TOGGLED = 3,
+ WxEV_DVLC_VALUE_CHANGED = 4,
+ WxEV_DVLC_HEADER_CLICK = 5,
+ WxEV_DVLC_REORDERED = 6,
+ WxEV_TIMER_TICK = 7,
+ WxEV_DVLC_ACTIVATED = 8,
+ WxEV_DVLC_SELECTION_CHANGED = 9,
+ WxEV_DVLC_CONTEXT_MENU = 10,
+ WxEV_MENU_ITEM = 11,
+};
+
+extern "C" {
+
+void wxbr_set_widget_event_fn(WxWidgetEventFn f) { g_widget_event = f; }
+
+// ---- window tree / sizers -------------------------------------------------
+
+void* wxbr_main_frame() { return (void*)wxTheApp->GetTopWindow(); }
+
+void* wxbr_panel(void* parent) {
+ return (void*)new wxPanel((wxWindow*)parent, wxID_ANY);
+}
+
+void* wxbr_box_sizer(int vertical) {
+ return (void*)new wxBoxSizer(vertical ? wxVERTICAL : wxHORIZONTAL);
+}
+
+// flag bits (must match Rust sizer_flags):
+// 1 = EXPAND, 2 = ALIGN_CENTRE_VERTICAL, 4 = wxALL, 8 = wxTOP,
+// 16 = wxBOTTOM, 32 = wxLEFT, 64 = wxRIGHT
+void wxbr_sizer_add(void* sizer, void* win, int proportion, int flags, int border) {
+ int f = 0;
+ if (flags & 1) f |= wxEXPAND;
+ if (flags & 2) f |= wxALIGN_CENTRE_VERTICAL;
+ if (flags & 4) f |= wxALL;
+ if (flags & 8) f |= wxTOP;
+ if (flags & 16) f |= wxBOTTOM;
+ if (flags & 32) f |= wxLEFT;
+ if (flags & 64) f |= wxRIGHT;
+ ((wxSizer*)sizer)->Add((wxWindow*)win, proportion, f, border);
+}
+
+void wxbr_sizer_add_sizer(void* sizer, void* subsizer, int proportion, int flags, int border) {
+ int f = 0;
+ if (flags & 1) f |= wxEXPAND;
+ if (flags & 2) f |= wxALIGN_CENTRE_VERTICAL;
+ if (flags & 4) f |= wxALL;
+ if (flags & 8) f |= wxTOP;
+ if (flags & 16) f |= wxBOTTOM;
+ if (flags & 32) f |= wxLEFT;
+ if (flags & 64) f |= wxRIGHT;
+ ((wxSizer*)sizer)->Add((wxSizer*)subsizer, proportion, f, border);
+}
+
+void wxbr_sizer_add_spacer(void* sizer, int px) {
+ ((wxSizer*)sizer)->AddSpacer(px);
+}
+
+void wxbr_sizer_add_stretch(void* sizer, int proportion) {
+ ((wxSizer*)sizer)->AddStretchSpacer(proportion);
+}
+
+void wxbr_set_sizer(void* win, void* sizer) {
+ ((wxWindow*)win)->SetSizer((wxSizer*)sizer);
+}
+
+// Re-run this window's sizer to (re)position its children. Needed after a
+// child window is added to an already-installed sizer (e.g. the table, which
+// is created after the frame's sizer is set and rebuilt on column changes).
+void wxbr_layout(void* win) { ((wxWindow*)win)->Layout(); }
+
+// Remove a child window from a sizer without destroying the window. Call this
+// before destroying a sizer-managed window so the sizer keeps no dangling item.
+void wxbr_sizer_detach(void* sizer, void* win) {
+ ((wxSizer*)sizer)->Detach((wxWindow*)win);
+}
+
+void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
+
+void wxbr_set_min_size(void* win, int w, int h) {
+ ((wxWindow*)win)->SetMinSize(wxSize(w, h));
+}
+
+// ---- static text / fonts --------------------------------------------------
+
+void* wxbr_static_text(void* parent, const char* label) {
+ return (void*)new wxStaticText((wxWindow*)parent, wxID_ANY,
+ wxString::FromUTF8(label));
+}
+
+void wxbr_set_label(void* win, const char* label) {
+ wxStaticText* st = dynamic_cast<wxStaticText*>((wxWindow*)win);
+ if (st) st->SetLabel(wxString::FromUTF8(label));
+ else ((wxWindow*)win)->SetLabel(wxString::FromUTF8(label));
+}
+
+// Read a control's current label text (used by the headless self-test to read
+// back what a KPI static text actually displays).
+int wxbr_get_label(void* win, char* buf, int cap) {
+ wxWindow* w = (wxWindow*)win;
+ wxStaticText* st = dynamic_cast<wxStaticText*>(w);
+ wxString s = st ? st->GetLabel() : w->GetLabel();
+ wxCharBuffer b = s.ToUTF8();
+ int n = (int)strlen(b.data());
+ if (n >= cap) n = cap - 1;
+ memcpy(buf, b.data(), n);
+ buf[n] = 0;
+ return n + 1;
+}
+
+void wxbr_set_bold(void* win) {
+ wxWindow* w = (wxWindow*)win;
+ wxFont f = w->GetFont();
+ wxFontInfo info(f.GetPointSize());
+ info.Bold();
+ w->SetFont(wxFont(info));
+}
+
+void wxbr_set_font_size(void* win, int pts) {
+ wxWindow* w = (wxWindow*)win;
+ wxFontInfo info(pts);
+ if (w->GetFont().GetWeight() == wxFONTWEIGHT_BOLD) info.Bold();
+ w->SetFont(wxFont(info));
+}
+
+// ---- button ---------------------------------------------------------------
+
+void* wxbr_button(void* parent, const char* label, int id) {
+ wxButton* b = new wxButton((wxWindow*)parent, id, wxString::FromUTF8(label));
+ b->Bind(wxEVT_BUTTON, [id](wxCommandEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_BUTTON_CLICKED, id, 0);
+ });
+ return (void*)b;
+}
+
+// ---- text ctrl ------------------------------------------------------------
+
+void* wxbr_text_ctrl(void* parent, int multiline) {
+ long style = multiline ? (wxTE_MULTILINE | wxTE_DONTWRAP) : 0;
+ return (void*)new wxTextCtrl((wxWindow*)parent, wxID_ANY, wxT(""),
+ wxDefaultPosition, wxSize(-1, -1), style);
+}
+
+int wxbr_text_ctrl_get(void* win, char* buf, int cap) {
+ wxTextCtrl* t = (wxTextCtrl*)win;
+ wxString v = t->GetValue();
+ wxCharBuffer b = v.ToUTF8();
+ int n = (int)strlen(b.data());
+ if (n >= cap) n = cap - 1;
+ memcpy(buf, b.data(), n);
+ buf[n] = 0;
+ return n + 1; // total length needed if truncated
+}
+
+void wxbr_text_ctrl_set(void* win, const char* value) {
+ ((wxTextCtrl*)win)->SetValue(wxString::FromUTF8(value));
+}
+
+// ---- checkbox -------------------------------------------------------------
+
+void* wxbr_check_box(void* parent, const char* label) {
+ return (void*)new wxCheckBox((wxWindow*)parent, wxID_ANY,
+ wxString::FromUTF8(label));
+}
+
+int wxbr_check_box_get(void* win) {
+ return ((wxCheckBox*)win)->GetValue() ? 1 : 0;
+}
+
+void wxbr_check_box_set(void* win, int v) {
+ ((wxCheckBox*)win)->SetValue(v != 0);
+}
+
+// ---- check list box ---------------------------------------------------------
+
+void* wxbr_check_list_box(void* parent) {
+ wxCheckListBox* clb = new wxCheckListBox((wxWindow*)parent, wxID_ANY,
+ wxDefaultPosition, wxSize(-1, -1),
+ 0, NULL, wxLB_SINGLE | wxLB_NEEDED_SB);
+ clb->Bind(wxEVT_CHECKLISTBOX, [clb](wxCommandEvent& e) {
+ if (g_widget_event)
+ g_widget_event(WxEV_CLB_TOGGLED, (long)(intptr_t)clb, e.GetInt());
+ });
+ return (void*)clb;
+}
+
+void wxbr_clb_append(void* win, const char* label) {
+ ((wxCheckListBox*)win)->Append(wxString::FromUTF8(label));
+}
+
+void wxbr_clb_clear(void* win) { ((wxCheckListBox*)win)->Clear(); }
+
+int wxbr_clb_count(void* win) { return (int)((wxCheckListBox*)win)->GetCount(); }
+
+int wxbr_clb_checked(void* win, int i) {
+ return ((wxCheckListBox*)win)->IsChecked(i) ? 1 : 0;
+}
+
+void wxbr_clb_set_checked(void* win, int i, int v) {
+ wxCheckListBox* clb = (wxCheckListBox*)win;
+ if (v)
+ clb->Check(i);
+ else
+ clb->Check(i, false);
+}
+
+int wxbr_clb_string(void* win, int i, char* buf, int cap) {
+ wxCheckListBox* clb = (wxCheckListBox*)win;
+ if (i < 0 || i >= (int)clb->GetCount()) return 0;
+ wxCharBuffer b = clb->GetString(i).ToUTF8();
+ int n = (int)strlen(b.data());
+ if (n >= cap) n = cap - 1;
+ memcpy(buf, b.data(), n);
+ buf[n] = 0;
+ return n + 1;
+}
+
+// ---- dialog -----------------------------------------------------------------
+
+void* wxbr_dialog(void* parent, const char* title) {
+ return (void*)new wxDialog((wxWindow*)parent, wxID_ANY,
+ wxString::FromUTF8(title), wxDefaultPosition,
+ wxSize(360, 480), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
+}
+
+int wxbr_dialog_show_modal(void* win) {
+ return ((wxDialog*)win)->ShowModal();
+}
+
+void wxbr_dialog_close(void* win, int code) {
+ ((wxDialog*)win)->EndModal(code);
+}
+
+// ---- data view list ctrl ------------------------------------------------------
+
+void* wxbr_dvlc(void* parent) {
+ // Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
+ // checkbox column.
+ wxDataViewListCtrl* lc =
+ new wxDataViewListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
+ wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
+ lc->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
+ });
+ lc->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_CONTEXT_MENU, 0, 0);
+ });
+ lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
+ if (g_widget_event) {
+ wxDataViewListCtrl* lc =
+ dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
+ if (!lc) return;
+ wxDataViewItem item = e.GetItem();
+ if (!item.IsOk()) return;
+ int row = lc->GetStore()->GetRow(item);
+ g_widget_event(WxEV_DVLC_VALUE_CHANGED, row, (long)e.GetColumn());
+ }
+ });
+ lc->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
+ });
+ lc->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
+ });
+ // Row activation (double-click / Enter): report the row + column so the app
+ // can, e.g., open the miner's IP in a browser.
+ lc->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
+ if (g_widget_event) {
+ wxDataViewListCtrl* lc =
+ dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
+ if (!lc) return;
+ wxDataViewItem item = e.GetItem();
+ if (!item.IsOk()) return;
+ int row = lc->GetStore()->GetRow(item);
+ g_widget_event(WxEV_DVLC_ACTIVATED, row, (long)e.GetColumn());
+ }
+ });
+ return (void*)lc;
+}
+
+void wxbr_dvlc_append_text_col(void* win, const char* title, int width, int reorderable) {
+ int flags = wxDATAVIEW_COL_RESIZABLE;
+ if (reorderable) flags |= wxDATAVIEW_COL_REORDERABLE;
+ ((wxDataViewListCtrl*)win)
+ ->AppendTextColumn(wxString::FromUTF8(title), wxDATAVIEW_CELL_INERT,
+ width, wxALIGN_NOT, flags);
+}
+
+void wxbr_dvlc_append_toggle_col(void* win, int width) {
+ ((wxDataViewListCtrl*)win)
+ ->AppendToggleColumn(wxT(""), wxDATAVIEW_CELL_ACTIVATABLE, width,
+ wxALIGN_CENTRE, 0);
+}
+
+void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
+ // All columns are text now (row selection replaced the checkbox column).
+ wxVector<wxVariant> values;
+ for (int i = 0; i < nvals; i++) {
+ values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
+ }
+ ((wxDataViewListCtrl*)win)->AppendItem(values);
+}
+
+void wxbr_dvlc_delete_row(void* win, unsigned row) {
+ ((wxDataViewListCtrl*)win)->DeleteItem(row);
+}
+
+void wxbr_dvlc_clear(void* win) { ((wxDataViewListCtrl*)win)->DeleteAllItems(); }
+
+int wxbr_dvlc_row_count(void* win) {
+ return (int)((wxDataViewListCtrl*)win)->GetStore()->GetItemCount();
+}
+
+void wxbr_dvlc_set_cell(void* win, unsigned row, unsigned col, const char* value) {
+ ((wxDataViewListCtrl*)win)
+ ->SetValue(wxVariant(wxString::FromUTF8(value)), row, col);
+}
+
+int wxbr_dvlc_get_cell(void* win, unsigned row, unsigned col, char* buf, int cap) {
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
+ wxDataViewListStore* store = lc->GetStore();
+ if (row >= store->GetItemCount() || col >= lc->GetColumnCount())
+ return 0;
+ wxVariant v;
+ store->GetValueByRow(v, row, col);
+ wxString s = v.GetString();
+ wxCharBuffer b = s.ToUTF8();
+ int n = (int)strlen(b.data());
+ if (n >= cap) n = cap - 1;
+ memcpy(buf, b.data(), n);
+ buf[n] = 0;
+ return n + 1;
+}
+
+int wxbr_dvlc_col_count(void* win) {
+ return (int)((wxDataViewListCtrl*)win)->GetColumnCount();
+}
+
+// Update a column's header text in place (creation index) without recreating
+// the control -- used to refresh the ASCII sort marker on a sort click.
+void wxbr_dvlc_set_col_title(void* win, int col, const char* title) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ if (col < 0 || (unsigned)col >= dv->GetColumnCount()) return;
+ wxDataViewColumn* c = dv->GetColumn(col);
+ if (c) c->SetTitle(wxString::FromUTF8(title));
+}
+
+// Show/clear the native sort arrow on a column (creation index). The app does
+// its own sorting; this only draws the indicator so the header shows which
+// column is the sort key and in which direction.
+void wxbr_dvlc_set_sort_indicator(void* win, int col, int active, int ascending) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ if (col < 0 || (unsigned)col >= dv->GetColumnCount()) return;
+ wxDataViewColumn* c = dv->GetColumn(col);
+ if (!c) return;
+ if (active) {
+ c->SetSortOrder(ascending != 0);
+ } else if (c->IsSortKey()) {
+ c->UnsetAsSortKey();
+ }
+}
+
+// model column index (creation order) currently shown at display position pos
+int wxbr_dvlc_col_at_pos(void* win, int pos) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ unsigned n = dv->GetColumnCount();
+ if (pos < 0 || (unsigned)pos >= n) return -1;
+ for (unsigned i = 0; i < n; i++) {
+ wxDataViewColumn* c = dv->GetColumn(i);
+ if (c && dv->GetColumnPosition(c) == (unsigned)pos) return (int)i;
+ }
+ return -1;
+}
+
+long wxbr_dvlc_selected_row(void* win) {
+ return (long)((wxDataViewListCtrl*)win)->GetSelectedRow();
+}
+
+// Fill `buf` with the selected row indices (multi-select); returns the count.
+int wxbr_dvlc_get_selections(void* win, int* buf, int cap) {
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
+ wxDataViewItemArray items;
+ int n = (int)lc->GetSelections(items);
+ int out = 0;
+ for (int i = 0; i < n && out < cap; i++) {
+ int row = lc->GetStore()->GetRow(items[i]);
+ if (row >= 0) buf[out++] = row;
+ }
+ return out;
+}
+
+void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
+ lc->UnselectAll();
+ for (int i = 0; i < n; i++) {
+ if (rows[i] >= 0) lc->SelectRow((unsigned)rows[i]);
+ }
+}
+
+void wxbr_dvlc_set_alt_row_color(void* win, int r, int g, int b) {
+ // No-op on GTK (native dataview lacks it); see wxbr_apply_zebra_css.
+ ((wxDataViewListCtrl*)win)->SetAlternateRowColour(wxColour(r, g, b));
+}
+
+// GTK's native dataview does not implement SetAlternateRowColour, so apply
+// zebra striping app-wide via a CSS provider (GTK 3.20+ supports :nth-child on
+// treeview rows). No-op off GTK.
+void wxbr_apply_zebra_css(int r, int g, int b) {
+#ifdef __WXGTK__
+ GtkCssProvider* p = gtk_css_provider_new();
+ char css[192];
+ std::snprintf(css, sizeof(css),
+ "treeview.view:nth-child(even){background-color:rgb(%d,%d,%d);}",
+ r, g, b);
+ gtk_css_provider_load_from_data(p, css, -1, NULL);
+ gtk_style_context_add_provider_for_screen(
+ gdk_screen_get_default(), GTK_STYLE_PROVIDER(p),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref(p);
+#else
+ (void)r; (void)g; (void)b;
+#endif
+}
+
+void wxbr_dvlc_select_row(void* win, long row) {
+ if (row < 0) return;
+ ((wxDataViewListCtrl*)win)->SelectRow((unsigned)row);
+}
+
+// ---- timer -----------------------------------------------------------------
+
+void* wxbr_timer(int id, int ms) {
+ wxTimer* t = new wxTimer;
+ t->Bind(wxEVT_TIMER, [id](wxTimerEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_TIMER_TICK, id, 0);
+ });
+ t->Start(ms);
+ return (void*)t;
+}
+
+// ---- gauge (progress bar) ---------------------------------------------------
+
+void* wxbr_gauge(void* parent, int range) {
+ wxGauge* g = new wxGauge((wxWindow*)parent, wxID_ANY, range < 1 ? 1 : range,
+ wxDefaultPosition, wxSize(-1, 6),
+ wxGA_HORIZONTAL | wxGA_SMOOTH);
+ return (void*)g;
+}
+
+void wxbr_gauge_set_range(void* win, int range) {
+ ((wxGauge*)win)->SetRange(range < 1 ? 1 : range);
+}
+
+void wxbr_gauge_set_value(void* win, int value) {
+ ((wxGauge*)win)->SetValue(value);
+}
+
+void wxbr_gauge_pulse(void* win) { ((wxGauge*)win)->Pulse(); }
+
+// ---- show / hide any window -------------------------------------------------
+
+void wxbr_show(void* win, int shown) { ((wxWindow*)win)->Show(shown != 0); }
+
+// ---- open a URL in the default browser --------------------------------------
+
+int wxbr_launch_browser(const char* url) {
+ return wxLaunchDefaultBrowser(wxString::FromUTF8(url)) ? 1 : 0;
+}
+
+// ---- appearance / dark mode -------------------------------------------------
+
+void wxbr_set_appearance_system() {
+#if wxCHECK_VERSION(3, 3, 0)
+ if (wxTheApp) wxTheApp->SetAppearance(wxApp::Appearance::System);
+#endif
+}
+
+int wxbr_is_dark() {
+ return wxSystemSettings::GetAppearance().IsDark() ? 1 : 0;
+}
+
+// Fetch a theme colour so custom widgets follow light/dark. which:
+// 0=window bg, 1=window text, 2=highlight, 3=button face, 4=grey text.
+void wxbr_system_color(int which, unsigned char* r, unsigned char* g,
+ unsigned char* b) {
+ wxSystemColour idx = wxSYS_COLOUR_WINDOW;
+ switch (which) {
+ case 0: idx = wxSYS_COLOUR_WINDOW; break;
+ case 1: idx = wxSYS_COLOUR_WINDOWTEXT; break;
+ case 2: idx = wxSYS_COLOUR_HIGHLIGHT; break;
+ case 3: idx = wxSYS_COLOUR_BTNFACE; break;
+ case 4: idx = wxSYS_COLOUR_GRAYTEXT; break;
+ default: idx = wxSYS_COLOUR_WINDOW; break;
+ }
+ wxColour c = wxSystemSettings::GetColour(idx);
+ *r = c.Red();
+ *g = c.Green();
+ *b = c.Blue();
+}
+
+// ---- widget colours (for the KPI cards) -------------------------------------
+
+void wxbr_set_bg(void* win, int r, int g, int b) {
+ ((wxWindow*)win)->SetBackgroundColour(wxColour(r, g, b));
+}
+
+void wxbr_set_fg(void* win, int r, int g, int b) {
+ ((wxWindow*)win)->SetForegroundColour(wxColour(r, g, b));
+}
+
+// ---- rearrangeable check-list (Choose columns, drag/reorder + check) ---------
+
+// order[i] encodes the item at display position i: value v >= 0 means original
+// item v, checked; a negative value ~v means original item v, unchecked.
+void* wxbr_rearrange_list(void* parent, int n, const int* order, const char** items) {
+ wxArrayInt aorder;
+ wxArrayString aitems;
+ for (int i = 0; i < n; i++) {
+ aorder.Add(order[i]);
+ aitems.Add(wxString::FromUTF8(items[i]));
+ }
+ wxRearrangeCtrl* ctrl =
+ new wxRearrangeCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
+ wxSize(-1, -1), aorder, aitems);
+ return (void*)ctrl;
+}
+
+// Read back the current order (same encoding as above) into buf; returns count.
+int wxbr_rearrange_get_order(void* win, int* buf, int cap) {
+ wxRearrangeCtrl* ctrl = (wxRearrangeCtrl*)win;
+ const wxArrayInt& order = ctrl->GetList()->GetCurrentOrder();
+ int n = (int)order.GetCount();
+ for (int i = 0; i < n && i < cap; i++) buf[i] = order[i];
+ return n < cap ? n : cap;
+}
+
+// ---- popup menu (right-click context menu) ----------------------------------
+
+void* wxbr_menu_new() { return (void*)new wxMenu(); }
+
+void wxbr_menu_append(void* menu, int id, const char* label) {
+ ((wxMenu*)menu)->Append(id, wxString::FromUTF8(label));
+}
+
+void wxbr_menu_append_separator(void* menu) {
+ ((wxMenu*)menu)->AppendSeparator();
+}
+
+// Show the menu at the current mouse position on `win`; blocks until dismissed.
+// The chosen item id is delivered via WxEV_MENU_ITEM before this returns.
+void wxbr_popup_menu(void* win, void* menu) {
+ wxWindow* w = (wxWindow*)win;
+ wxMenu* m = (wxMenu*)menu;
+ m->Bind(wxEVT_MENU, [](wxCommandEvent& e) {
+ if (g_widget_event) g_widget_event(WxEV_MENU_ITEM, e.GetId(), 0);
+ });
+ w->PopupMenu(m);
+ delete m;
+}
+
+// ---- deferred destroy (safe from event handlers) ----------------------------
+
+void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
+
+} // extern "C"