Files
alkane-toolkit/thirdparty/wx-rs/patches/0002-widget-bridge-rs.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

575 lines
23 KiB
Diff

--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,3 +3,7 @@
mod menu;
pub use menu::*;
+
+// alkane-toolkit patch: widget bridge (see cpp_src/widgets_bridge.cpp)
+mod widgets;
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -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).
+// All functions must be called from the main thread while the wx event loop
+// is (or will be) running.
+
+use std::ffi::CString;
+use std::os::raw::{c_char, c_int, c_long, c_void};
+
+mod notsafe {
+ use std::os::raw::{c_char, c_int, c_long, c_void};
+
+ extern "C" {
+ pub fn wxbr_set_widget_event_fn(f: extern "C" fn(c_int, c_long, c_long));
+ pub fn wxbr_main_frame() -> *mut c_void;
+ pub fn wxbr_panel(parent: *mut c_void) -> *mut c_void;
+ pub fn wxbr_box_sizer(vertical: c_int) -> *mut c_void;
+ pub fn wxbr_sizer_add(sizer: *mut c_void, win: *mut c_void, proportion: c_int, flags: c_int, border: c_int);
+ pub fn wxbr_sizer_add_sizer(sizer: *mut c_void, subsizer: *mut c_void, proportion: c_int, flags: c_int, border: c_int);
+ pub fn wxbr_sizer_add_spacer(sizer: *mut c_void, px: c_int);
+ pub fn wxbr_sizer_add_stretch(sizer: *mut c_void, proportion: c_int);
+ pub fn wxbr_set_sizer(win: *mut c_void, sizer: *mut c_void);
+ pub fn wxbr_layout(win: *mut c_void);
+ pub fn wxbr_sizer_detach(sizer: *mut c_void, win: *mut c_void);
+ pub fn wxbr_fit(win: *mut c_void);
+ pub fn wxbr_set_min_size(win: *mut c_void, w: c_int, h: c_int);
+ pub fn wxbr_static_text(parent: *mut c_void, label: *const c_char) -> *mut c_void;
+ pub fn wxbr_set_label(win: *mut c_void, label: *const c_char);
+ pub fn wxbr_get_label(win: *mut c_void, buf: *mut c_char, cap: c_int) -> c_int;
+ pub fn wxbr_set_bold(win: *mut c_void);
+ pub fn wxbr_set_font_size(win: *mut c_void, pts: c_int);
+ pub fn wxbr_button(parent: *mut c_void, label: *const c_char, id: c_int) -> *mut c_void;
+ pub fn wxbr_text_ctrl(parent: *mut c_void, multiline: c_int) -> *mut c_void;
+ pub fn wxbr_text_ctrl_get(win: *mut c_void, buf: *mut c_char, cap: c_int) -> c_int;
+ pub fn wxbr_text_ctrl_set(win: *mut c_void, value: *const c_char);
+ pub fn wxbr_check_box(parent: *mut c_void, label: *const c_char) -> *mut c_void;
+ pub fn wxbr_check_box_get(win: *mut c_void) -> c_int;
+ pub fn wxbr_check_box_set(win: *mut c_void, v: c_int);
+ pub fn wxbr_check_list_box(parent: *mut c_void) -> *mut c_void;
+ pub fn wxbr_clb_append(win: *mut c_void, label: *const c_char);
+ pub fn wxbr_clb_clear(win: *mut c_void);
+ pub fn wxbr_clb_count(win: *mut c_void) -> c_int;
+ pub fn wxbr_clb_checked(win: *mut c_void, i: c_int) -> c_int;
+ pub fn wxbr_clb_set_checked(win: *mut c_void, i: c_int, v: c_int);
+ pub fn wxbr_clb_string(win: *mut c_void, i: c_int, buf: *mut c_char, cap: c_int) -> c_int;
+ pub fn wxbr_dialog(parent: *mut c_void, title: *const c_char) -> *mut c_void;
+ pub fn wxbr_dialog_show_modal(win: *mut c_void) -> c_int;
+ pub fn wxbr_dialog_close(win: *mut c_void, code: c_int);
+ pub fn wxbr_dvlc(parent: *mut c_void) -> *mut c_void;
+ pub fn wxbr_dvlc_append_text_col(win: *mut c_void, title: *const c_char, width: c_int, reorderable: c_int);
+ pub fn wxbr_dvlc_append_toggle_col(win: *mut c_void, width: c_int);
+ pub fn wxbr_dvlc_append_row(win: *mut c_void, nvals: c_int, vals: *const *const c_char);
+ pub fn wxbr_dvlc_delete_row(win: *mut c_void, row: usize);
+ pub fn wxbr_dvlc_clear(win: *mut c_void);
+ pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
+ 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);
+ pub fn wxbr_gauge_set_value(win: *mut c_void, value: c_int);
+ pub fn wxbr_gauge_pulse(win: *mut c_void);
+ pub fn wxbr_show(win: *mut c_void, shown: c_int);
+ pub fn wxbr_launch_browser(url: *const c_char) -> c_int;
+ pub fn wxbr_set_appearance_system();
+ pub fn wxbr_is_dark() -> c_int;
+ pub fn wxbr_system_color(which: c_int, r: *mut u8, g: *mut u8, b: *mut u8);
+ pub fn wxbr_set_bg(win: *mut c_void, r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_set_fg(win: *mut c_void, r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_destroy(win: *mut c_void);
+ }
+}
+
+/// Opaque handle to a wxWidgets window/sizer/control.
+#[derive(Clone, Copy, Debug)]
+pub struct Widget(pub(crate) *mut c_void);
+
+/// Sizer flags understood by the bridge (see widgets_bridge.cpp).
+pub mod sizer_flags {
+ pub const EXPAND: i32 = 1;
+ pub const ALIGN_CENTRE_VERTICAL: i32 = 2;
+ pub const BORDER_ALL: i32 = 4;
+ pub const BORDER_TOP: i32 = 8;
+ pub const BORDER_BOTTOM: i32 = 16;
+ pub const BORDER_LEFT: i32 = 32;
+ pub const BORDER_RIGHT: i32 = 64;
+}
+
+/// Widget event kinds delivered to the handler set by `set_event_handler`.
+/// Values match WxWidgetEventKind in widgets_bridge.cpp.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum WxEventKind {
+ ButtonClicked,
+ ClbToggled,
+ DvlcValueChanged,
+ DvlcHeaderClick,
+ DvlcReordered,
+ TimerTick,
+ DvlcActivated,
+ DvlcSelectionChanged,
+ DvlcContextMenu,
+ MenuItem,
+}
+
+impl WxEventKind {
+ fn from_raw(k: i32) -> Option<Self> {
+ Some(match k {
+ 1 => WxEventKind::ButtonClicked,
+ 3 => WxEventKind::ClbToggled,
+ 4 => WxEventKind::DvlcValueChanged,
+ 5 => WxEventKind::DvlcHeaderClick,
+ 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();
+ unsafe { notsafe::wxbr_launch_browser(c.as_ptr()) != 0 }
+}
+
+/// Ask wx to follow the system light/dark appearance (no-op before 3.3).
+pub fn set_appearance_system() {
+ unsafe { notsafe::wxbr_set_appearance_system() }
+}
+
+/// True if the current system appearance is dark.
+pub fn is_dark() -> bool {
+ unsafe { notsafe::wxbr_is_dark() != 0 }
+}
+
+/// A theme colour. `which`: 0=window bg, 1=window text, 2=highlight,
+/// 3=button face, 4=grey text. Returns (r, g, b).
+pub fn system_color(which: i32) -> (u8, u8, u8) {
+ let (mut r, mut g, mut b) = (0u8, 0u8, 0u8);
+ unsafe { notsafe::wxbr_system_color(which, &mut r, &mut g, &mut b) }
+ (r, g, b)
+}
+
+/// A widget event: kind plus two payload words.
+/// ButtonClicked: p1 = button id.
+/// ClbToggled: p1 = control handle, p2 = item index.
+/// DvlcValueChanged: p1 = row, p2 = column.
+/// DvlcHeaderClick: p1 = column.
+/// DvlcReordered: (re-read the column order afterwards).
+/// TimerTick: p1 = timer id.
+#[derive(Debug, Clone, Copy)]
+pub struct WxEvent {
+ pub kind: WxEventKind,
+ pub p1: i64,
+ pub p2: i64,
+}
+
+type Handler = fn(WxEvent);
+
+thread_local! {
+ static HANDLER: std::cell::RefCell<Option<Handler>> = const { std::cell::RefCell::new(None) };
+}
+
+extern "C" fn event_trampoline(kind: c_int, p1: c_long, p2: c_long) {
+ let Some(kind) = WxEventKind::from_raw(kind) else { return };
+ let ev = WxEvent { kind, p1: p1 as i64, p2: p2 as i64 };
+ HANDLER.with(|h| {
+ if let Some(f) = h.borrow().as_ref() {
+ f(ev);
+ }
+ });
+}
+
+/// Install the single widget-event handler (call once, before run_app).
+pub fn set_event_handler(f: Handler) {
+ HANDLER.with(|h| *h.borrow_mut() = Some(f));
+ unsafe {
+ notsafe::wxbr_set_widget_event_fn(event_trampoline);
+ }
+}
+
+impl Widget {
+ pub fn main_frame() -> Widget {
+ Widget(unsafe { notsafe::wxbr_main_frame() })
+ }
+
+ pub fn panel(parent: Widget) -> Widget {
+ Widget(unsafe { notsafe::wxbr_panel(parent.0) })
+ }
+
+ pub fn box_sizer(vertical: bool) -> Widget {
+ Widget(unsafe { notsafe::wxbr_box_sizer(vertical as c_int) })
+ }
+
+ pub fn add(&self, win: Widget, proportion: i32, flags: i32, border: i32) {
+ unsafe { notsafe::wxbr_sizer_add(self.0, win.0, proportion, flags, border) }
+ }
+
+ /// Add a child SIZER (not a window) to this sizer.
+ pub fn add_sizer(&self, sizer: Widget, proportion: i32, flags: i32, border: i32) {
+ unsafe { notsafe::wxbr_sizer_add_sizer(self.0, sizer.0, proportion, flags, border) }
+ }
+
+ pub fn add_spacer(&self, px: i32) {
+ unsafe { notsafe::wxbr_sizer_add_spacer(self.0, px) }
+ }
+
+ pub fn add_stretch(&self, proportion: i32) {
+ unsafe { notsafe::wxbr_sizer_add_stretch(self.0, proportion) }
+ }
+
+ pub fn set_sizer_on(&self, win: Widget) {
+ unsafe { notsafe::wxbr_set_sizer(win.0, self.0) }
+ }
+
+ /// Re-run this window's sizer (self = a window). Call after adding a child
+ /// window to an already-installed sizer, or after rebuilding the table.
+ pub fn layout(&self) {
+ unsafe { notsafe::wxbr_layout(self.0) }
+ }
+
+ /// Detach a child window from this sizer (self = a sizer) without
+ /// destroying it. Use before destroying a sizer-managed window.
+ pub fn detach(&self, win: Widget) {
+ unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
+ }
+
+ pub fn fit(&self, win: Widget) {
+ unsafe { notsafe::wxbr_fit(win.0) }
+ }
+
+ pub fn set_min_size(&self, w: i32, h: i32) {
+ unsafe { notsafe::wxbr_set_min_size(self.0, w, h) }
+ }
+
+ pub fn static_text(parent: Widget, label: &str) -> Widget {
+ let c = CString::new(label).unwrap_or_default();
+ Widget(unsafe { notsafe::wxbr_static_text(parent.0, c.as_ptr()) })
+ }
+
+ pub fn set_label(&self, label: &str) {
+ let c = CString::new(label).unwrap_or_default();
+ unsafe { notsafe::wxbr_set_label(self.0, c.as_ptr()) }
+ }
+
+ /// Read back a control's current label text (self-test uses this to verify
+ /// what a KPI actually displays).
+ pub fn get_label(&self) -> String {
+ let mut buf = vec![0i8; 4096];
+ let n = unsafe { notsafe::wxbr_get_label(self.0, buf.as_mut_ptr(), buf.len() as c_int) };
+ if n <= 0 {
+ return String::new();
+ }
+ let bytes: Vec<u8> = buf[..(n - 1) as usize].iter().map(|&b| b as u8).collect();
+ String::from_utf8_lossy(&bytes).into_owned()
+ }
+
+ pub fn set_bold(&self) {
+ unsafe { notsafe::wxbr_set_bold(self.0) }
+ }
+
+ pub fn set_font_size(&self, pts: i32) {
+ unsafe { notsafe::wxbr_set_font_size(self.0, pts) }
+ }
+
+ pub fn button(parent: Widget, label: &str, id: i32) -> Widget {
+ let c = CString::new(label).unwrap_or_default();
+ Widget(unsafe { notsafe::wxbr_button(parent.0, c.as_ptr(), id) })
+ }
+
+ pub fn text_ctrl(parent: Widget, multiline: bool) -> Widget {
+ Widget(unsafe { notsafe::wxbr_text_ctrl(parent.0, multiline as c_int) })
+ }
+
+ pub fn get_value(&self) -> String {
+ let mut buf = vec![0i8; 65536];
+ let n = unsafe { notsafe::wxbr_text_ctrl_get(self.0, buf.as_mut_ptr(), buf.len() as c_int) };
+ let n = n.max(1) as usize;
+ let bytes: Vec<u8> = buf[..n - 1].iter().map(|&b| b as u8).collect();
+ String::from_utf8_lossy(&bytes).into_owned()
+ }
+
+ pub fn set_value(&self, value: &str) {
+ let c = CString::new(value).unwrap_or_default();
+ unsafe { notsafe::wxbr_text_ctrl_set(self.0, c.as_ptr()) }
+ }
+
+ pub fn check_box(parent: Widget, label: &str) -> Widget {
+ let c = CString::new(label).unwrap_or_default();
+ Widget(unsafe { notsafe::wxbr_check_box(parent.0, c.as_ptr()) })
+ }
+
+ pub fn is_checked(&self) -> bool {
+ unsafe { notsafe::wxbr_check_box_get(self.0) != 0 }
+ }
+
+ pub fn set_checked(&self, v: bool) {
+ unsafe { notsafe::wxbr_check_box_set(self.0, v as c_int) }
+ }
+
+ pub fn check_list_box(parent: Widget) -> Widget {
+ Widget(unsafe { notsafe::wxbr_check_list_box(parent.0) })
+ }
+
+ pub fn clb_append(&self, label: &str) {
+ let c = CString::new(label).unwrap_or_default();
+ unsafe { notsafe::wxbr_clb_append(self.0, c.as_ptr()) }
+ }
+
+ pub fn clb_clear(&self) {
+ unsafe { notsafe::wxbr_clb_clear(self.0) }
+ }
+
+ pub fn clb_count(&self) -> usize {
+ unsafe { notsafe::wxbr_clb_count(self.0).max(0) as usize }
+ }
+
+ pub fn clb_checked(&self, i: usize) -> bool {
+ unsafe { notsafe::wxbr_clb_checked(self.0, i as c_int) != 0 }
+ }
+
+ pub fn clb_set_checked(&self, i: usize, v: bool) {
+ unsafe { notsafe::wxbr_clb_set_checked(self.0, i as c_int, v as c_int) }
+ }
+
+ pub fn clb_string(&self, i: usize) -> Option<String> {
+ let mut buf = vec![0i8; 4096];
+ let n = unsafe { notsafe::wxbr_clb_string(self.0, i as c_int, buf.as_mut_ptr(), buf.len() as c_int) };
+ if n <= 0 {
+ return None;
+ }
+ let bytes: Vec<u8> = buf[..(n - 1) as usize].iter().map(|&b| b as u8).collect();
+ Some(String::from_utf8_lossy(&bytes).into_owned())
+ }
+
+ pub fn dialog(parent: Widget, title: &str) -> Widget {
+ let c = CString::new(title).unwrap_or_default();
+ Widget(unsafe { notsafe::wxbr_dialog(parent.0, c.as_ptr()) })
+ }
+
+ /// Blocks in a nested event loop until the dialog is dismissed.
+ pub fn show_modal(&self) -> i32 {
+ unsafe { notsafe::wxbr_dialog_show_modal(self.0) }
+ }
+
+ pub fn close(&self, code: i32) {
+ unsafe { notsafe::wxbr_dialog_close(self.0, code) }
+ }
+
+ // ---- data view list ctrl ----
+
+ pub fn dvlc(parent: Widget) -> Widget {
+ Widget(unsafe { notsafe::wxbr_dvlc(parent.0) })
+ }
+
+ pub fn dvlc_append_text_col(&self, title: &str, width: i32, reorderable: bool) {
+ let c = CString::new(title).unwrap_or_default();
+ unsafe { notsafe::wxbr_dvlc_append_text_col(self.0, c.as_ptr(), width, reorderable as c_int) }
+ }
+
+ pub fn dvlc_append_toggle_col(&self, width: i32) {
+ unsafe { notsafe::wxbr_dvlc_append_toggle_col(self.0, width) }
+ }
+
+ pub fn dvlc_append_row(&self, values: &[&str]) {
+ let cvals: Vec<CString> = values.iter().map(|v| CString::new(*v).unwrap_or_default()).collect();
+ let ptrs: Vec<*const c_char> = cvals.iter().map(|c| c.as_ptr()).collect();
+ unsafe { notsafe::wxbr_dvlc_append_row(self.0, ptrs.len() as c_int, ptrs.as_ptr()) }
+ }
+
+ pub fn dvlc_delete_row(&self, row: usize) {
+ unsafe { notsafe::wxbr_dvlc_delete_row(self.0, row) }
+ }
+
+ pub fn dvlc_clear(&self) {
+ unsafe { notsafe::wxbr_dvlc_clear(self.0) }
+ }
+
+ pub fn dvlc_row_count(&self) -> usize {
+ unsafe { notsafe::wxbr_dvlc_row_count(self.0).max(0) as usize }
+ }
+
+ pub fn dvlc_set_cell(&self, row: usize, col: usize, value: &str) {
+ let c = CString::new(value).unwrap_or_default();
+ unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
+ }
+
+ pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
+ let mut buf = vec![0i8; 4096];
+ let n = unsafe {
+ notsafe::wxbr_dvlc_get_cell(self.0, row, col, buf.as_mut_ptr(), buf.len() as c_int)
+ };
+ if n <= 0 {
+ return None;
+ }
+ let bytes: Vec<u8> = buf[..(n - 1) as usize].iter().map(|&b| b as u8).collect();
+ Some(String::from_utf8_lossy(&bytes).into_owned())
+ }
+
+ pub fn dvlc_col_count(&self) -> usize {
+ unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
+ }
+
+ /// Model column index shown at display position `pos` (after drag reorder).
+ pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
+ let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
+ if v < 0 { None } else { Some(v as usize) }
+ }
+
+ pub fn dvlc_selected_row(&self) -> Option<usize> {
+ let v = unsafe { notsafe::wxbr_dvlc_selected_row(self.0) };
+ if v < 0 { None } else { Some(v as usize) }
+ }
+
+ pub fn dvlc_select_row(&self, row: usize) {
+ 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 {
+ notsafe::wxbr_dvlc_set_sort_indicator(
+ self.0,
+ col as c_int,
+ active as c_int,
+ ascending as c_int,
+ )
+ }
+ }
+
+ pub fn timer(id: i32, ms: i32) -> Widget {
+ Widget(unsafe { notsafe::wxbr_timer(id, ms) })
+ }
+
+ // ---- gauge (progress bar) ----
+
+ pub fn gauge(parent: Widget, range: i32) -> Widget {
+ Widget(unsafe { notsafe::wxbr_gauge(parent.0, range) })
+ }
+
+ pub fn gauge_set_range(&self, range: i32) {
+ unsafe { notsafe::wxbr_gauge_set_range(self.0, range) }
+ }
+
+ pub fn gauge_set_value(&self, value: i32) {
+ unsafe { notsafe::wxbr_gauge_set_value(self.0, value) }
+ }
+
+ pub fn gauge_pulse(&self) {
+ unsafe { notsafe::wxbr_gauge_pulse(self.0) }
+ }
+
+ /// Show or hide this window.
+ pub fn show(&self, shown: bool) {
+ unsafe { notsafe::wxbr_show(self.0, shown as c_int) }
+ }
+
+ pub fn set_bg(&self, r: u8, g: u8, b: u8) {
+ unsafe { notsafe::wxbr_set_bg(self.0, r as c_int, g as c_int, b as c_int) }
+ }
+
+ pub fn set_fg(&self, r: u8, g: u8, b: u8) {
+ unsafe { notsafe::wxbr_set_fg(self.0, r as c_int, g as c_int, b as c_int) }
+ }
+
+ /// Deferred destruction (safe from event handlers); used to rebuild
+ /// the table when its column set changes.
+ pub fn destroy(&self) {
+ unsafe { notsafe::wxbr_destroy(self.0) }
+ }
+}