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
This commit is contained in:
+14
-2
@@ -1,6 +1,5 @@
|
||||
--- a/build.rs
|
||||
+++ b/build.rs
|
||||
+++ wx-rs-0.2.0-patched/build.rs 2026-09-15 12:56:37.552254500 -0600
|
||||
@@ -24,8 +24,14 @@
|
||||
cfg!(target_os = "macos")
|
||||
}
|
||||
@@ -52,7 +51,7 @@
|
||||
if is_windows() {
|
||||
build_msvc(wx_path)?;
|
||||
} else {
|
||||
@@ -217,6 +232,46 @@
|
||||
@@ -217,6 +232,59 @@
|
||||
)?)
|
||||
}
|
||||
|
||||
@@ -65,6 +64,16 @@
|
||||
+ Command::new(&wxconfig).arg("--cxxflags").output()?.stdout,
|
||||
+ )?;
|
||||
+ let libs = String::from_utf8(Command::new(&wxconfig).arg("--libs").output()?.stdout)?;
|
||||
+ // The widget bridge uses GTK directly (zebra-striping CSS), so add GTK's own
|
||||
+ // include paths. Best-effort: if pkg-config or gtk3-dev is missing the flags
|
||||
+ // are simply empty and the GTK-only code stays disabled.
|
||||
+ let gtk_cflags = Command::new("pkg-config")
|
||||
+ .args(["--cflags", "gtk+-3.0"])
|
||||
+ .output()
|
||||
+ .ok()
|
||||
+ .filter(|o| o.status.success())
|
||||
+ .and_then(|o| String::from_utf8(o.stdout).ok())
|
||||
+ .unwrap_or_default();
|
||||
+
|
||||
+ let mut build = cc::Build::new();
|
||||
+ build.cpp(true)
|
||||
@@ -73,6 +82,9 @@
|
||||
+ for f in cxxflags.split_whitespace() {
|
||||
+ build.flag(f);
|
||||
+ }
|
||||
+ for f in gtk_cflags.split_whitespace() {
|
||||
+ build.flag(f);
|
||||
+ }
|
||||
+ build.compile("wxbridge");
|
||||
+
|
||||
+ for flag in libs.split_whitespace() {
|
||||
|
||||
+89
-1
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,473 @@
|
||||
@@ -0,0 +1,561 @@
|
||||
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
||||
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
||||
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
||||
@@ -69,10 +69,21 @@
|
||||
+ pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
||||
+ pub fn wxbr_dvlc_get_cell(win: *mut c_void, row: usize, col: usize, buf: *mut c_char, cap: c_int) -> c_int;
|
||||
+ pub fn wxbr_dvlc_col_count(win: *mut c_void) -> c_int;
|
||||
+ pub fn wxbr_dvlc_set_col_title(win: *mut c_void, col: c_int, title: *const c_char);
|
||||
+ pub fn wxbr_dvlc_set_sort_indicator(win: *mut c_void, col: c_int, active: c_int, ascending: c_int);
|
||||
+ pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
||||
+ pub fn wxbr_dvlc_selected_row(win: *mut c_void) -> c_long;
|
||||
+ pub fn wxbr_dvlc_select_row(win: *mut c_void, row: c_long);
|
||||
+ pub fn wxbr_dvlc_get_selections(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
+ pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
||||
+ pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
+ pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
+ pub fn wxbr_menu_new() -> *mut c_void;
|
||||
+ pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
+ pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
+ pub fn wxbr_popup_menu(win: *mut c_void, menu: *mut c_void);
|
||||
+ pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_gauge_set_range(win: *mut c_void, range: c_int);
|
||||
@@ -115,6 +126,9 @@
|
||||
+ DvlcReordered,
|
||||
+ TimerTick,
|
||||
+ DvlcActivated,
|
||||
+ DvlcSelectionChanged,
|
||||
+ DvlcContextMenu,
|
||||
+ MenuItem,
|
||||
+}
|
||||
+
|
||||
+impl WxEventKind {
|
||||
@@ -127,11 +141,19 @@
|
||||
+ 6 => WxEventKind::DvlcReordered,
|
||||
+ 7 => WxEventKind::TimerTick,
|
||||
+ 8 => WxEventKind::DvlcActivated,
|
||||
+ 9 => WxEventKind::DvlcSelectionChanged,
|
||||
+ 10 => WxEventKind::DvlcContextMenu,
|
||||
+ 11 => WxEventKind::MenuItem,
|
||||
+ _ => return None,
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/// Apply app-wide zebra striping to tree/list views (GTK CSS; no-op elsewhere).
|
||||
+pub fn apply_zebra_css(r: u8, g: u8, b: u8) {
|
||||
+ unsafe { notsafe::wxbr_apply_zebra_css(r as c_int, g as c_int, b as c_int) }
|
||||
+}
|
||||
+
|
||||
+/// Open a URL in the system default browser. Returns true on success.
|
||||
+pub fn launch_browser(url: &str) -> bool {
|
||||
+ let c = CString::new(url).unwrap_or_default();
|
||||
@@ -431,6 +453,72 @@
|
||||
+ unsafe { notsafe::wxbr_dvlc_select_row(self.0, row as c_long) }
|
||||
+ }
|
||||
+
|
||||
+ /// The selected row indices (multi-select).
|
||||
+ pub fn dvlc_get_selections(&self) -> Vec<usize> {
|
||||
+ let mut buf = vec![0i32; 8192];
|
||||
+ let n = unsafe {
|
||||
+ notsafe::wxbr_dvlc_get_selections(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
+ };
|
||||
+ buf.into_iter().take(n.max(0) as usize).map(|v| v as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ /// Replace the selection with the given row indices.
|
||||
+ pub fn dvlc_select_rows(&self, rows: &[usize]) {
|
||||
+ let v: Vec<c_int> = rows.iter().map(|&r| r as c_int).collect();
|
||||
+ unsafe { notsafe::wxbr_dvlc_select_rows(self.0, v.as_ptr(), v.len() as c_int) }
|
||||
+ }
|
||||
+
|
||||
+ pub fn dvlc_set_alt_row_color(&self, r: u8, g: u8, b: u8) {
|
||||
+ unsafe { notsafe::wxbr_dvlc_set_alt_row_color(self.0, r as c_int, g as c_int, b as c_int) }
|
||||
+ }
|
||||
+
|
||||
+ // ---- rearrangeable check-list ----
|
||||
+
|
||||
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||
+ /// >= 0 is item `v` (checked); `!v` (negative) is item `v` unchecked.
|
||||
+ pub fn rearrange_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
|
||||
+ let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
|
||||
+ let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
|
||||
+ Widget(unsafe {
|
||||
+ notsafe::wxbr_rearrange_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
+ })
|
||||
+ }
|
||||
+
|
||||
+ /// Read back the current order (same wx encoding as `rearrange_list`).
|
||||
+ pub fn rearrange_get_order(&self) -> Vec<i32> {
|
||||
+ let mut buf = vec![0i32; 4096];
|
||||
+ let n = unsafe {
|
||||
+ notsafe::wxbr_rearrange_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
+ };
|
||||
+ buf.into_iter().take(n.max(0) as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ // ---- popup menu ----
|
||||
+
|
||||
+ pub fn menu_new() -> Widget {
|
||||
+ Widget(unsafe { notsafe::wxbr_menu_new() })
|
||||
+ }
|
||||
+
|
||||
+ pub fn menu_append(&self, id: i32, label: &str) {
|
||||
+ let c = CString::new(label).unwrap_or_default();
|
||||
+ unsafe { notsafe::wxbr_menu_append(self.0, id, c.as_ptr()) }
|
||||
+ }
|
||||
+
|
||||
+ pub fn menu_append_separator(&self) {
|
||||
+ unsafe { notsafe::wxbr_menu_append_separator(self.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Show `menu` as a popup on this window; blocks until dismissed.
|
||||
+ pub fn popup_menu(&self, menu: Widget) {
|
||||
+ unsafe { notsafe::wxbr_popup_menu(self.0, menu.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Update a column's header text in place (creation index).
|
||||
+ pub fn dvlc_set_col_title(&self, col: usize, title: &str) {
|
||||
+ let c = CString::new(title).unwrap_or_default();
|
||||
+ unsafe { notsafe::wxbr_dvlc_set_col_title(self.0, col as c_int, c.as_ptr()) }
|
||||
+ }
|
||||
+
|
||||
+ /// Show or clear the native sort arrow on a column (creation index).
|
||||
+ pub fn dvlc_set_sort_indicator(&self, col: usize, active: bool, ascending: bool) {
|
||||
+ unsafe {
|
||||
|
||||
+126
-10
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,482 @@
|
||||
@@ -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).
|
||||
@@ -21,6 +21,12 @@
|
||||
+#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;
|
||||
@@ -34,6 +40,9 @@
|
||||
+ 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" {
|
||||
@@ -261,9 +270,17 @@
|
||||
+// ---- 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);
|
||||
+ 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 =
|
||||
@@ -312,16 +329,10 @@
|
||||
+}
|
||||
+
|
||||
+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++) {
|
||||
+ if (i == 0)
|
||||
+ // toggle column (checkbox): vals[0] carries the checked state as "1"/"0"
|
||||
+ // so a refresh preserves the row selection instead of clearing it.
|
||||
+ values.push_back(wxVariant(vals[0] && vals[0][0] == '1'));
|
||||
+ else if (vals[i])
|
||||
+ values.push_back(wxVariant(wxString::FromUTF8(vals[i])));
|
||||
+ else
|
||||
+ values.push_back(wxVariant(wxT("")));
|
||||
+ values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
|
||||
+ }
|
||||
+ ((wxDataViewListCtrl*)win)->AppendItem(values);
|
||||
+}
|
||||
@@ -361,6 +372,15 @@
|
||||
+ 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.
|
||||
@@ -392,6 +412,52 @@
|
||||
+ 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);
|
||||
@@ -478,6 +544,56 @@
|
||||
+ ((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(); }
|
||||
|
||||
+13
@@ -241,6 +241,16 @@ fn build_linux() -> Result<(), Box<dyn Error>> {
|
||||
Command::new(&wxconfig).arg("--cxxflags").output()?.stdout,
|
||||
)?;
|
||||
let libs = String::from_utf8(Command::new(&wxconfig).arg("--libs").output()?.stdout)?;
|
||||
// The widget bridge uses GTK directly (zebra-striping CSS), so add GTK's own
|
||||
// include paths. Best-effort: if pkg-config or gtk3-dev is missing the flags
|
||||
// are simply empty and the GTK-only code stays disabled.
|
||||
let gtk_cflags = Command::new("pkg-config")
|
||||
.args(["--cflags", "gtk+-3.0"])
|
||||
.output()
|
||||
.ok()
|
||||
.filter(|o| o.status.success())
|
||||
.and_then(|o| String::from_utf8(o.stdout).ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut build = cc::Build::new();
|
||||
build.cpp(true)
|
||||
@@ -249,6 +259,9 @@ fn build_linux() -> Result<(), Box<dyn Error>> {
|
||||
for f in cxxflags.split_whitespace() {
|
||||
build.flag(f);
|
||||
}
|
||||
for f in gtk_cflags.split_whitespace() {
|
||||
build.flag(f);
|
||||
}
|
||||
build.compile("wxbridge");
|
||||
|
||||
for flag in libs.split_whitespace() {
|
||||
|
||||
+116
-9
@@ -18,6 +18,12 @@
|
||||
#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;
|
||||
@@ -31,6 +37,9 @@ enum WxWidgetEventKind {
|
||||
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" {
|
||||
@@ -258,9 +267,17 @@ void wxbr_dialog_close(void* win, int 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);
|
||||
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 =
|
||||
@@ -309,16 +326,10 @@ void wxbr_dvlc_append_toggle_col(void* win, int width) {
|
||||
}
|
||||
|
||||
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++) {
|
||||
if (i == 0)
|
||||
// toggle column (checkbox): vals[0] carries the checked state as "1"/"0"
|
||||
// so a refresh preserves the row selection instead of clearing it.
|
||||
values.push_back(wxVariant(vals[0] && vals[0][0] == '1'));
|
||||
else if (vals[i])
|
||||
values.push_back(wxVariant(wxString::FromUTF8(vals[i])));
|
||||
else
|
||||
values.push_back(wxVariant(wxT("")));
|
||||
values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
|
||||
}
|
||||
((wxDataViewListCtrl*)win)->AppendItem(values);
|
||||
}
|
||||
@@ -398,6 +409,52 @@ 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);
|
||||
@@ -484,6 +541,56 @@ 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(); }
|
||||
|
||||
@@ -61,6 +61,16 @@ mod notsafe {
|
||||
pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
||||
pub fn wxbr_dvlc_selected_row(win: *mut c_void) -> c_long;
|
||||
pub fn wxbr_dvlc_select_row(win: *mut c_void, row: c_long);
|
||||
pub fn wxbr_dvlc_get_selections(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
||||
pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
pub fn wxbr_menu_new() -> *mut c_void;
|
||||
pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
pub fn wxbr_popup_menu(win: *mut c_void, menu: *mut c_void);
|
||||
pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
|
||||
pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
|
||||
pub fn wxbr_gauge_set_range(win: *mut c_void, range: c_int);
|
||||
@@ -103,6 +113,9 @@ pub enum WxEventKind {
|
||||
DvlcReordered,
|
||||
TimerTick,
|
||||
DvlcActivated,
|
||||
DvlcSelectionChanged,
|
||||
DvlcContextMenu,
|
||||
MenuItem,
|
||||
}
|
||||
|
||||
impl WxEventKind {
|
||||
@@ -115,11 +128,19 @@ impl WxEventKind {
|
||||
6 => WxEventKind::DvlcReordered,
|
||||
7 => WxEventKind::TimerTick,
|
||||
8 => WxEventKind::DvlcActivated,
|
||||
9 => WxEventKind::DvlcSelectionChanged,
|
||||
10 => WxEventKind::DvlcContextMenu,
|
||||
11 => WxEventKind::MenuItem,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply app-wide zebra striping to tree/list views (GTK CSS; no-op elsewhere).
|
||||
pub fn apply_zebra_css(r: u8, g: u8, b: u8) {
|
||||
unsafe { notsafe::wxbr_apply_zebra_css(r as c_int, g as c_int, b as c_int) }
|
||||
}
|
||||
|
||||
/// Open a URL in the system default browser. Returns true on success.
|
||||
pub fn launch_browser(url: &str) -> bool {
|
||||
let c = CString::new(url).unwrap_or_default();
|
||||
@@ -419,6 +440,66 @@ impl Widget {
|
||||
unsafe { notsafe::wxbr_dvlc_select_row(self.0, row as c_long) }
|
||||
}
|
||||
|
||||
/// The selected row indices (multi-select).
|
||||
pub fn dvlc_get_selections(&self) -> Vec<usize> {
|
||||
let mut buf = vec![0i32; 8192];
|
||||
let n = unsafe {
|
||||
notsafe::wxbr_dvlc_get_selections(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
};
|
||||
buf.into_iter().take(n.max(0) as usize).map(|v| v as usize).collect()
|
||||
}
|
||||
|
||||
/// Replace the selection with the given row indices.
|
||||
pub fn dvlc_select_rows(&self, rows: &[usize]) {
|
||||
let v: Vec<c_int> = rows.iter().map(|&r| r as c_int).collect();
|
||||
unsafe { notsafe::wxbr_dvlc_select_rows(self.0, v.as_ptr(), v.len() as c_int) }
|
||||
}
|
||||
|
||||
pub fn dvlc_set_alt_row_color(&self, r: u8, g: u8, b: u8) {
|
||||
unsafe { notsafe::wxbr_dvlc_set_alt_row_color(self.0, r as c_int, g as c_int, b as c_int) }
|
||||
}
|
||||
|
||||
// ---- rearrangeable check-list ----
|
||||
|
||||
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||
/// >= 0 is item `v` (checked); `!v` (negative) is item `v` unchecked.
|
||||
pub fn rearrange_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
|
||||
let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
|
||||
let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
|
||||
Widget(unsafe {
|
||||
notsafe::wxbr_rearrange_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
})
|
||||
}
|
||||
|
||||
/// Read back the current order (same wx encoding as `rearrange_list`).
|
||||
pub fn rearrange_get_order(&self) -> Vec<i32> {
|
||||
let mut buf = vec![0i32; 4096];
|
||||
let n = unsafe {
|
||||
notsafe::wxbr_rearrange_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
};
|
||||
buf.into_iter().take(n.max(0) as usize).collect()
|
||||
}
|
||||
|
||||
// ---- popup menu ----
|
||||
|
||||
pub fn menu_new() -> Widget {
|
||||
Widget(unsafe { notsafe::wxbr_menu_new() })
|
||||
}
|
||||
|
||||
pub fn menu_append(&self, id: i32, label: &str) {
|
||||
let c = CString::new(label).unwrap_or_default();
|
||||
unsafe { notsafe::wxbr_menu_append(self.0, id, c.as_ptr()) }
|
||||
}
|
||||
|
||||
pub fn menu_append_separator(&self) {
|
||||
unsafe { notsafe::wxbr_menu_append_separator(self.0) }
|
||||
}
|
||||
|
||||
/// Show `menu` as a popup on this window; blocks until dismissed.
|
||||
pub fn popup_menu(&self, menu: Widget) {
|
||||
unsafe { notsafe::wxbr_popup_menu(self.0, menu.0) }
|
||||
}
|
||||
|
||||
/// Update a column's header text in place (creation index).
|
||||
pub fn dvlc_set_col_title(&self, col: usize, title: &str) {
|
||||
let c = CString::new(title).unwrap_or_default();
|
||||
|
||||
Reference in New Issue
Block a user