Compare commits

...
1 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 365732b5d4 GUI round 8b.2 fix: rubber-band drag-select uses native GtkTreeView on GTK
The wx-mouse-event rubber-band approach (LEFT_DOWN/MOTION/LEFT_UP) does not work
on the native GTK wxDataViewCtrl: the underlying GtkTreeView grabs the pointer
during a button drag, so wx never delivers the MOTION events, and only the
initial click row was selected (verified against the shipped binary).

Fix: on GTK, enable the GtkTreeView's own native rubber-band selection via
dv->GtkGetTreeView() + gtk_tree_view_set_rubber_banding(TRUE), guarded by
__WXGTK__ (gtk/gtk.h included only there). The wx-mouse-event approach is kept
as the non-GTK fallback for the future Windows/macOS builds, where it will be
verified in the platform round. The column-header right-click menu (native wx
dataview event) already worked and is unchanged.

Local wx-rs bridge compile clean; patch 0003 regenerated + validated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-17 17:27:16 -06:00
2 changed files with 51 additions and 11 deletions
+26 -6
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,989 @@
@@ -0,0 +1,1009 @@
+// 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).
@@ -36,12 +36,21 @@
+#include <cstdio>
+#include <map>
+#include <vector>
+#ifdef __WXGTK__
+// For native GtkTreeView rubber-band (click-drag) selection, which wx does not
+// enable and which cannot be done via wx mouse events on GTK (the native widget
+// grabs the pointer during a drag). Guarded so non-GTK builds are unaffected.
+#include <gtk/gtk.h>
+#endif
+
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
+static WxWidgetEventFn g_widget_event = nullptr;
+
+// Anchor row per data-view control for rubber-band (click-drag) range select.
+#ifndef __WXGTK__
+// Anchor row per data-view control for the wx-mouse-event rubber-band fallback
+// (non-GTK platforms; GTK uses native GtkTreeView rubber-banding instead).
+static std::map<wxDataViewCtrl*, int> g_drag_anchor;
+#endif
+
+// Event kinds (must match Rust WxEventKind in src/widgets.rs)
+enum WxWidgetEventKind {
@@ -490,10 +499,20 @@
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
+ });
+ // Rubber-band (click-drag) range selection: wxDataViewCtrl has none natively
+ // (only ctrl/shift-click), so track it here. LEFT_DOWN records the anchor row
+ // (and lets the native handler select it); dragging with the button down
+ // extends the selection to the row under the cursor.
+ // Rubber-band (click-drag) range selection. wxDataViewCtrl has none natively.
+#ifdef __WXGTK__
+ // On GTK the control wraps a GtkTreeView, which supports native rubber-band
+ // selection -- just not enabled by wx. Enable it directly. (wx delivers no
+ // MOTION events during the native drag, so the mouse-event fallback below is
+ // inapplicable on GTK.)
+ {
+ GtkWidget* tv = dv->GtkGetTreeView();
+ if (tv) gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
+ }
+#else
+ // Non-GTK fallback: track a drag anchor and extend the selection to the row
+ // under the cursor. LEFT_DOWN records the anchor (and lets the native handler
+ // select it); dragging with the button down selects the inclusive range.
+ dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
+ if (!dv) { e.Skip(); return; }
@@ -534,6 +553,7 @@
+ if (dv) g_drag_anchor.erase(dv);
+ e.Skip();
+ });
+#endif
+ // Row activation (double-click / Enter): report the row + column so the app
+ // can, e.g., open the miner's IP in a browser.
+ dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
@@ -33,12 +33,21 @@
#include <cstdio>
#include <map>
#include <vector>
#ifdef __WXGTK__
// For native GtkTreeView rubber-band (click-drag) selection, which wx does not
// enable and which cannot be done via wx mouse events on GTK (the native widget
// grabs the pointer during a drag). Guarded so non-GTK builds are unaffected.
#include <gtk/gtk.h>
#endif
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
static WxWidgetEventFn g_widget_event = nullptr;
// Anchor row per data-view control for rubber-band (click-drag) range select.
#ifndef __WXGTK__
// Anchor row per data-view control for the wx-mouse-event rubber-band fallback
// (non-GTK platforms; GTK uses native GtkTreeView rubber-banding instead).
static std::map<wxDataViewCtrl*, int> g_drag_anchor;
#endif
// Event kinds (must match Rust WxEventKind in src/widgets.rs)
enum WxWidgetEventKind {
@@ -487,10 +496,20 @@ void* wxbr_dvlc(void* parent) {
dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
});
// Rubber-band (click-drag) range selection: wxDataViewCtrl has none natively
// (only ctrl/shift-click), so track it here. LEFT_DOWN records the anchor row
// (and lets the native handler select it); dragging with the button down
// extends the selection to the row under the cursor.
// Rubber-band (click-drag) range selection. wxDataViewCtrl has none natively.
#ifdef __WXGTK__
// On GTK the control wraps a GtkTreeView, which supports native rubber-band
// selection -- just not enabled by wx. Enable it directly. (wx delivers no
// MOTION events during the native drag, so the mouse-event fallback below is
// inapplicable on GTK.)
{
GtkWidget* tv = dv->GtkGetTreeView();
if (tv) gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
}
#else
// Non-GTK fallback: track a drag anchor and extend the selection to the row
// under the cursor. LEFT_DOWN records the anchor (and lets the native handler
// select it); dragging with the button down selects the inclusive range.
dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
if (!dv) { e.Skip(); return; }
@@ -531,6 +550,7 @@ void* wxbr_dvlc(void* parent) {
if (dv) g_drag_anchor.erase(dv);
e.Skip();
});
#endif
// Row activation (double-click / Enter): report the row + column so the app
// can, e.g., open the miner's IP in a browser.
dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {