Build: the wx-rs build script chose the platform with cfg!(), which in a build script describes the build host, so a Linux-to-Windows build took the GTK path. It now reads CARGO_CFG_TARGET_*, and Windows/GNU builds through wx-config exactly like GTK, against a static wxMSW from scripts/build-wx-windows.sh. The C++ runtime is linked statically, so the .exe imports only Windows system DLLs. crates/alkane-gui/build.rs embeds an application manifest (Common Controls v6, per-monitor DPI v2, UTF-8 code page, Windows 10/11), the icon and version info. Bridge on wxMSW (patches 0007/0008): - the upstream frame's invisible "OSX key events" child sat above the UI on MSW and swallowed every click and key; it is no longer created there - light/dark is chosen before the first window (wxMSW ignores it later) and follows the Windows app mode, with dark grid rules for the data view - the generic wxDataViewCtrl gets mouse input in its inner main window, so drag-select and the per-cell / per-icon tooltips bind there (GTK keeps its native GtkTreeView paths; the icon hit-test is shared) - sizes cross the Rust/C++ boundary in DIPs (identity on GTK), so columns, icons, KPI cards and the status bar scale at 125-200 % - vector shapes go through GDI+ (anti-aliased like Cairo on GTK); selected rows use the themed list-view text colour like the native renderer - the frame never opens larger than the monitor work area; title-bar icon from the executable; upstream menu insert no longer reads UTF-8 as UTF-16 App: OS differences live in alkane_core::platform (settings in %APPDATA%\alkane-toolkit, owner-only secret files, NUL, console-less helper processes). SSH password logins use SSH_ASKPASS with the toolkit itself as the helper on every platform, replacing sshpass, which Windows lacks. Release builds are GUI-subsystem; headless modes attach to the parent console. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
692 lines
29 KiB
Diff
692 lines
29 KiB
Diff
Subject: [PATCH 0008] widget bridge: wxMSW support (generic data-view input and tooltips, DIP size boundary, anti-aliased shapes, themed selection colours)
|
|
|
|
--- a/cpp_src/widgets_bridge.cpp
|
|
+++ b/cpp_src/widgets_bridge.cpp
|
|
@@ -36,7 +36,13 @@
|
|
#include <cstdio>
|
|
#include <cmath>
|
|
#include <map>
|
|
+#include <memory>
|
|
#include <vector>
|
|
+#ifdef __WXMSW__
|
|
+// Themed list-view colours, to draw selected rows the way the native renderer does.
|
|
+#include <wx/msw/uxtheme.h>
|
|
+#include <vssym32.h>
|
|
+#endif
|
|
#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
|
|
@@ -48,8 +54,9 @@
|
|
static WxWidgetEventFn g_widget_event = nullptr;
|
|
|
|
#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).
|
|
+// Anchor row per data-view control for the wx-mouse-event rubber-band selection
|
|
+// used with the generic wxDataViewCtrl (wxMSW and any other non-GTK port; GTK
|
|
+// uses native GtkTreeView rubber-banding instead).
|
|
static std::map<wxDataViewCtrl*, int> g_drag_anchor;
|
|
#endif
|
|
|
|
@@ -72,6 +79,26 @@
|
|
WxEV_SIZE = 16, // p1 = new client width, p2 = new client height
|
|
};
|
|
|
|
+// Sizes cross the Rust <-> C++ boundary in DIPs (device-independent pixels,
|
|
+// 1/96 inch: the size at 100 % display scale). The bridge converts them for the
|
|
+// window they apply to. wxGTK and wxOSX lay out in logical pixels already, so
|
|
+// FromDIP/ToDIP are the identity there and nothing changes; per-monitor-DPI-
|
|
+// aware wxMSW works in physical pixels, where a 180 px column must become
|
|
+// 270 px at 150 % or text clips. Non-positive values (wxDefaultCoord and the
|
|
+// like) pass through untouched.
|
|
+static wxWindow* DipWindow(wxWindow* win) {
|
|
+ if (win) return win;
|
|
+ return wxTheApp ? wxTheApp->GetTopWindow() : nullptr;
|
|
+}
|
|
+static int PxFromDip(wxWindow* win, int dip) {
|
|
+ wxWindow* w = DipWindow(win);
|
|
+ return (w && dip > 0) ? w->FromDIP(dip) : dip;
|
|
+}
|
|
+static int DipFromPx(wxWindow* win, int px) {
|
|
+ wxWindow* w = DipWindow(win);
|
|
+ return (w && px > 0) ? w->ToDIP(px) : px;
|
|
+}
|
|
+
|
|
// A list store that carries an optional per-row foreground colour plus an
|
|
// alternating-row (zebra) background, surfaced to the native control via
|
|
// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
|
@@ -196,6 +223,20 @@
|
|
static wxSlider* g_zoom_slider = nullptr; // the status-bar zoom slider
|
|
static wxTextCtrl* g_zoom_entry = nullptr; // the editable "100%" field next to it
|
|
|
|
+// Display density for the custom-drawn shapes and icons. wxGTK and wxOSX draw
|
|
+// in DPI-independent logical pixels, so FromDIP() is the identity there and
|
|
+// these change nothing. Per-monitor-DPI-aware wxMSW draws in physical pixels,
|
|
+// so a 15 px shape slot has to become 23 px at 150 % to keep the same physical
|
|
+// size as the (already scaled) text beside it.
|
|
+static double DipFactor() {
|
|
+ return g_zoom_table ? g_zoom_table->FromDIP(1000) / 1000.0 : 1.0;
|
|
+}
|
|
+static int Dip(int px) { return (int)(px * DipFactor() + 0.5); }
|
|
+// Space one vector shape occupies, at the current display density.
|
|
+static int ShapeAdvance() { return Dip(SHAPE_ADVANCE); }
|
|
+// Icon size factor: the table zoom (round 14 #3) times the display density.
|
|
+static double ShapeScale() { return g_table_zoom * DipFactor(); }
|
|
+
|
|
// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a
|
|
// wxTimer while any such dot is on screen; the treeview it repaints is tracked so
|
|
// the timer can invalidate exactly it.
|
|
@@ -313,7 +354,7 @@
|
|
// health icons are square, so the advance is (h - 3) just like a real one.
|
|
if (shape == SHAPE_GAP) {
|
|
int h = cell.height - 1;
|
|
- int cap = (int)(28 * g_table_zoom + 0.5);
|
|
+ int cap = (int)(28 * ShapeScale() + 0.5);
|
|
if (cap < 8) cap = 8;
|
|
if (h > cap) h = cap;
|
|
if (h < 8) h = 8;
|
|
@@ -329,7 +370,7 @@
|
|
bool health = (shape == SHAPE_BOLT || shape == SHAPE_BRAIN ||
|
|
shape == SHAPE_FAN || shape == SHAPE_CHIP);
|
|
int h = cell.height - (health ? 1 : 4);
|
|
- int cap = (int)((health ? 28 : 15) * g_table_zoom + 0.5);
|
|
+ int cap = (int)((health ? 28 : 15) * ShapeScale() + 0.5);
|
|
if (cap < 8) cap = 8;
|
|
if (h > cap) h = cap;
|
|
if (h < 8) h = 8;
|
|
@@ -362,25 +403,37 @@
|
|
dc->DrawBitmap(bmp, x + (adv - dw) / 2, cy - dh / 2, true);
|
|
return adv;
|
|
}
|
|
- int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE;
|
|
+ int slot = (w > ShapeAdvance()) ? w : ShapeAdvance();
|
|
dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true);
|
|
return slot;
|
|
}
|
|
}
|
|
- int cx = x + SHAPE_ADVANCE / 2;
|
|
+#ifdef __WXMSW__
|
|
+ // GDI does not anti-alias, so the dots and the padlock came out jagged next
|
|
+ // to the smooth SVG icons. Draw the vector shapes through GDI+ instead, as
|
|
+ // Cairo already does on GTK; the context inherits the DC's origin, scale and
|
|
+ // clip (the same approach wx's own generic markup renderer takes).
|
|
+ std::unique_ptr<wxGCDC> smooth;
|
|
+ if (wxGraphicsContext* gc = wxGraphicsContext::CreateFromUnknownDC(*dc)) {
|
|
+ smooth.reset(new wxGCDC(gc));
|
|
+ dc = smooth.get();
|
|
+ }
|
|
+#endif
|
|
+ const int adv = ShapeAdvance();
|
|
+ int cx = x + adv / 2;
|
|
if (shape == SHAPE_LIGHT_BEACON) {
|
|
// A green dot above a red dot, both flashing quickly (round 15 #6). The blink
|
|
// is a fast on/off (~0.5 s) driven by the shared pulse phase.
|
|
double a = (std::sin(g_pulse_phase * 3.0) > 0.0) ? 1.0 : 0.18;
|
|
wxColour green = BlendColour(bg, wxColour(30, 175, 70), a);
|
|
wxColour red = BlendColour(bg, wxColour(215, 45, 40), a);
|
|
- int r = 3;
|
|
+ int r = Dip(3);
|
|
dc->SetPen(*wxTRANSPARENT_PEN);
|
|
dc->SetBrush(wxBrush(green));
|
|
dc->DrawCircle(cx, cy - (r + 1), r);
|
|
dc->SetBrush(wxBrush(red));
|
|
dc->DrawCircle(cx, cy + (r + 1), r);
|
|
- return SHAPE_ADVANCE;
|
|
+ return adv;
|
|
}
|
|
if (shape == SHAPE_DOT || shape == SHAPE_PULSE_DOT) {
|
|
wxColour fill = colour;
|
|
@@ -391,21 +444,21 @@
|
|
}
|
|
dc->SetPen(*wxTRANSPARENT_PEN);
|
|
dc->SetBrush(wxBrush(fill));
|
|
- dc->DrawCircle(cx, cy, 4);
|
|
- return SHAPE_ADVANCE;
|
|
+ dc->DrawCircle(cx, cy, Dip(4));
|
|
+ return adv;
|
|
}
|
|
// Padlock: a filled body with a staple shackle above. The colour carries the
|
|
// state (green = unlocked, red = locked); the shackle is drawn ajar when open.
|
|
bool open = (shape == SHAPE_UNLOCK);
|
|
- int bw = 9, bh = 7;
|
|
+ int bw = Dip(9), bh = Dip(7);
|
|
int bx = cx - bw / 2;
|
|
int by = cy - bh / 2 + 1;
|
|
dc->SetPen(*wxTRANSPARENT_PEN);
|
|
dc->SetBrush(wxBrush(colour));
|
|
- dc->DrawRoundedRectangle(bx, by, bw, bh, 1.5);
|
|
+ dc->DrawRoundedRectangle(bx, by, bw, bh, 1.5 * DipFactor());
|
|
dc->SetBrush(*wxTRANSPARENT_BRUSH);
|
|
- dc->SetPen(wxPen(colour, 2));
|
|
- int sr = 3;
|
|
+ dc->SetPen(wxPen(colour, Dip(2)));
|
|
+ int sr = Dip(3);
|
|
int legTop = by - sr - 1;
|
|
int lx = cx - sr, rx = cx + sr;
|
|
dc->DrawLine(lx, by, lx, legTop); // left leg
|
|
@@ -414,11 +467,45 @@
|
|
dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted
|
|
else
|
|
dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body
|
|
- return SHAPE_ADVANCE;
|
|
+ return adv;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
+// True when selected rows keep their own background under a light, translucent
|
|
+// highlight (the Explorer list-view style of Windows 10/11 with visual styles)
|
|
+// rather than a solid highlight colour.
|
|
+static bool SelectionIsTranslucent(wxWindow* win) {
|
|
+#ifdef __WXMSW__
|
|
+ if (win && wxUxThemeIsActive()) {
|
|
+ wxUxThemeHandle theme(win, L"EXPLORER::LISTVIEW;LISTVIEW", L"DarkMode_ItemsView::LISTVIEW");
|
|
+ return ::IsThemePartDefined(theme, LVP_LISTITEM, 0) != 0;
|
|
+ }
|
|
+#else
|
|
+ (void)win;
|
|
+#endif
|
|
+ return false;
|
|
+}
|
|
+
|
|
+// Text colour for a selected row, matching the platform's native data-view text
|
|
+// renderer. Windows 10/11 (visual styles on) draw the Explorer list-view
|
|
+// selection: a light translucent highlight under the normal dark text, taken
|
|
+// from the theme (dark-mode aware). Elsewhere -- GTK, or Windows with visual
|
|
+// styles off / high contrast -- the selection is a solid highlight, so the text
|
|
+// switches to the system highlight-text colour.
|
|
+static wxColour SelectedTextColour(wxWindow* win) {
|
|
+#ifdef __WXMSW__
|
|
+ if (SelectionIsTranslucent(win)) {
|
|
+ wxUxThemeHandle theme(win, L"EXPLORER::LISTVIEW;LISTVIEW", L"DarkMode_ItemsView::LISTVIEW");
|
|
+ wxColour c = theme.GetColour(LVP_LISTITEM, TMT_TEXTCOLOR, LISS_SELECTED);
|
|
+ if (c.IsOk()) return c;
|
|
+ }
|
|
+#else
|
|
+ (void)win;
|
|
+#endif
|
|
+ return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
|
|
+}
|
|
+
|
|
class SegmentRenderer : public wxDataViewCustomRenderer {
|
|
public:
|
|
SegmentRenderer()
|
|
@@ -467,7 +554,9 @@
|
|
bg.height += 80;
|
|
dc->DrawRectangle(bg);
|
|
}
|
|
- wxColour highlight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
|
|
+ wxDataViewColumn* owner_col = const_cast<SegmentRenderer*>(this)->GetOwner();
|
|
+ wxColour highlight =
|
|
+ SelectedTextColour(owner_col ? owner_col->GetOwner() : nullptr);
|
|
// An uncoloured (default) segment -- the "/" in a combined cell, a "Stock"
|
|
// firmware family, etc. -- must dim exactly like the native columns when the
|
|
// top-level window is backdropped. wxGTK dims a native cell's text via the
|
|
@@ -503,7 +592,7 @@
|
|
if (IsShapeSentinel(seg.text, shape)) {
|
|
// Background the shape sits on, so the pulsing locate dot fades toward it.
|
|
wxColour cellbg;
|
|
- if (selected) {
|
|
+ if (selected && !SelectionIsTranslucent(owner_col ? owner_col->GetOwner() : nullptr)) {
|
|
cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
|
|
} else if (GetAttr().HasBackgroundColour()) {
|
|
cellbg = GetAttr().GetBackgroundColour();
|
|
@@ -530,11 +619,11 @@
|
|
if (IsShapeSentinel(seg.text, shape)) {
|
|
bool health = (shape == SHAPE_BOLT || shape == SHAPE_BRAIN ||
|
|
shape == SHAPE_FAN || shape == SHAPE_CHIP);
|
|
- int adv = SHAPE_ADVANCE;
|
|
+ int adv = ShapeAdvance();
|
|
// Health icons measure bigger and pack tighter, and report a taller
|
|
// content height so the row grows to fit them (round 14 #1). Sizes scale
|
|
// with the table zoom (round 14 #3).
|
|
- int hh = (int)((health ? 22 : 15) * g_table_zoom + 0.5);
|
|
+ int hh = (int)((health ? 22 : 15) * ShapeScale() + 0.5);
|
|
if (hh < 8) hh = 8;
|
|
// The alignment gap is one health-icon-width slot that draws nothing
|
|
// (round 15 #5); health icons are square, so its advance is hh - 3.
|
|
@@ -646,7 +735,7 @@
|
|
if (flags & 16) f |= wxBOTTOM;
|
|
if (flags & 32) f |= wxLEFT;
|
|
if (flags & 64) f |= wxRIGHT;
|
|
- ((wxSizer*)sizer)->Add((wxWindow*)win, proportion, f, border);
|
|
+ ((wxSizer*)sizer)->Add((wxWindow*)win, proportion, f, PxFromDip((wxWindow*)win, border));
|
|
}
|
|
|
|
void wxbr_sizer_add_sizer(void* sizer, void* subsizer, int proportion, int flags, int border) {
|
|
@@ -658,11 +747,12 @@
|
|
if (flags & 16) f |= wxBOTTOM;
|
|
if (flags & 32) f |= wxLEFT;
|
|
if (flags & 64) f |= wxRIGHT;
|
|
- ((wxSizer*)sizer)->Add((wxSizer*)subsizer, proportion, f, border);
|
|
+ ((wxSizer*)sizer)->Add((wxSizer*)subsizer, proportion, f,
|
|
+ PxFromDip(((wxSizer*)sizer)->GetContainingWindow(), border));
|
|
}
|
|
|
|
void wxbr_sizer_add_spacer(void* sizer, int px) {
|
|
- ((wxSizer*)sizer)->AddSpacer(px);
|
|
+ ((wxSizer*)sizer)->AddSpacer(PxFromDip(((wxSizer*)sizer)->GetContainingWindow(), px));
|
|
}
|
|
|
|
void wxbr_sizer_add_stretch(void* sizer, int proportion) {
|
|
@@ -694,9 +784,11 @@
|
|
// Emit WxEV_SIZE (p1 = new client width, p2 = height) whenever this window is
|
|
// resized. e.Skip() keeps the normal sizer layout running (round 11 #2).
|
|
void wxbr_bind_size(void* win) {
|
|
- ((wxWindow*)win)->Bind(wxEVT_SIZE, [](wxSizeEvent& e) {
|
|
- if (g_widget_event) g_widget_event(WxEV_SIZE, (long)e.GetSize().GetWidth(),
|
|
- (long)e.GetSize().GetHeight());
|
|
+ wxWindow* w = (wxWindow*)win;
|
|
+ w->Bind(wxEVT_SIZE, [w](wxSizeEvent& e) {
|
|
+ if (g_widget_event)
|
|
+ g_widget_event(WxEV_SIZE, (long)DipFromPx(w, e.GetSize().GetWidth()),
|
|
+ (long)DipFromPx(w, e.GetSize().GetHeight()));
|
|
e.Skip();
|
|
});
|
|
}
|
|
@@ -704,7 +796,8 @@
|
|
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));
|
|
+ wxWindow* window = (wxWindow*)win;
|
|
+ window->SetMinSize(wxSize(PxFromDip(window, w), PxFromDip(window, h)));
|
|
}
|
|
|
|
// Attach a hover tooltip to any widget (round 15 #10). An empty string clears it.
|
|
@@ -902,7 +995,8 @@
|
|
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);
|
|
+ DipWindow((wxWindow*)parent)->FromDIP(wxSize(360, 480)),
|
|
+ wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
|
|
}
|
|
|
|
int wxbr_dialog_show_modal(void* win) {
|
|
@@ -957,6 +1051,96 @@
|
|
return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
|
|
}
|
|
|
|
+// Per-icon tooltip hit-testing for a Health-style cell (round 15 #15), shared by
|
|
+// the GTK and generic tooltip paths so both pick the same icon. The slot advance
|
|
+// must match DrawShape's UNIFORM health-icon slot: (row height - 1, capped at
|
|
+// 28*zoom) - 3 for every glyph and gap alike (round 19 #2). A right-aligned
|
|
+// column (round 19 #21) draws the icon block flush to the cell's right edge, so
|
|
+// slots are measured from the block's left, not the cell's left.
|
|
+struct IconSlots {
|
|
+ int left; // x of the first slot, in the same coordinates as the cell
|
|
+ int adv; // width of one slot
|
|
+};
|
|
+
|
|
+static IconSlots HealthIconSlots(int cell_x, int cell_w, int cell_h, int n,
|
|
+ bool right_aligned) {
|
|
+ int h = cell_h - 1;
|
|
+ int cap = (int)(28 * ShapeScale() + 0.5);
|
|
+ if (cap < 8) cap = 8;
|
|
+ if (h > cap) h = cap;
|
|
+ if (h < 8) h = 8;
|
|
+ int adv = h - 3;
|
|
+ if (adv < 1) adv = 1;
|
|
+ int left = cell_x;
|
|
+ if (right_aligned) {
|
|
+ int content_w = n * adv;
|
|
+ if (content_w < cell_w) left = cell_x + (cell_w - content_w);
|
|
+ }
|
|
+ return IconSlots{left, adv};
|
|
+}
|
|
+
|
|
+static int HealthIconSlotAt(const IconSlots& slots, int x, int n) {
|
|
+ int off = x - slots.left;
|
|
+ if (off < 0) off = 0;
|
|
+ int slot = off / slots.adv;
|
|
+ if (slot >= n) slot = n - 1;
|
|
+ return slot < 0 ? 0 : slot;
|
|
+}
|
|
+
|
|
+#ifndef __WXGTK__
|
|
+// Generic wxDataViewCtrl (wxMSW): per-cell and per-icon hover tooltips.
|
|
+// The control draws its rows in an inner main window, which is where mouse
|
|
+// events arrive, so the tooltip lives on that window. Windows only re-shows a
|
|
+// tooltip when its text is re-set, so the handler tracks the (row, column,
|
|
+// icon slot) under the pointer and replaces the tooltip only when it changes;
|
|
+// moving from one Health icon to the next therefore pops the right text.
|
|
+struct DvTipKey {
|
|
+ int row = -1;
|
|
+ unsigned col = (unsigned)-1;
|
|
+ int slot = -1;
|
|
+ bool operator==(const DvTipKey& o) const {
|
|
+ return row == o.row && col == o.col && slot == o.slot;
|
|
+ }
|
|
+};
|
|
+static std::map<wxDataViewCtrl*, DvTipKey> g_tip_key;
|
|
+
|
|
+// Padding the generic renderer leaves on each side of a cell (PADDING_RIGHTLEFT
|
|
+// in src/generic/datavgen.cpp); custom renderers draw inside it.
|
|
+static const int GENERIC_CELL_PADDING = 3;
|
|
+
|
|
+static void dvlc_update_tooltip(wxDataViewCtrl* dv, wxWindow* area, wxPoint area_pos) {
|
|
+ const wxPoint p = dv->ScreenToClient(area->ClientToScreen(area_pos));
|
|
+ wxDataViewItem item;
|
|
+ wxDataViewColumn* col = nullptr;
|
|
+ dv->HitTest(p, item, col);
|
|
+ DvTipKey key;
|
|
+ wxString tip;
|
|
+ if (item.IsOk() && col) {
|
|
+ AttrListStore* store = static_cast<AttrListStore*>(dv->GetModel());
|
|
+ key.row = (int)store->GetRow(item);
|
|
+ key.col = col->GetModelColumn();
|
|
+ auto iit = store->icon_tip.find({(unsigned)key.row, key.col});
|
|
+ if (iit != store->icon_tip.end() && !iit->second.empty()) {
|
|
+ wxRect r = dv->GetItemRect(item, col);
|
|
+ int pad = dv->FromDIP(GENERIC_CELL_PADDING);
|
|
+ int n = (int)iit->second.size();
|
|
+ IconSlots slots = HealthIconSlots(r.x + pad, r.width - 2 * pad, r.height, n,
|
|
+ col->GetAlignment() == wxALIGN_RIGHT);
|
|
+ key.slot = HealthIconSlotAt(slots, p.x, n);
|
|
+ tip = iit->second[(size_t)key.slot];
|
|
+ } else {
|
|
+ auto it = store->cell_tip.find({(unsigned)key.row, key.col});
|
|
+ if (it != store->cell_tip.end()) tip = it->second;
|
|
+ }
|
|
+ }
|
|
+ DvTipKey& last = g_tip_key[dv];
|
|
+ if (last == key) return;
|
|
+ last = key;
|
|
+ area->UnsetToolTip();
|
|
+ if (!tip.IsEmpty()) area->SetToolTip(tip);
|
|
+}
|
|
+#endif
|
|
+
|
|
#ifdef __WXGTK__
|
|
// GtkTreeView "query-tooltip" handler: show the per-cell tooltip stored for the
|
|
// (row, model column) under the pointer (used by the Errors column). wx does
|
|
@@ -987,31 +1171,12 @@
|
|
GdkRectangle crect;
|
|
gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, gcol, &crect);
|
|
gtk_tree_path_free(path);
|
|
- // Icon advance must match DrawShape's now-UNIFORM health-icon slot, which is
|
|
- // (row height - 1, capped at 28*zoom) - 3 for every glyph and gap alike. The
|
|
- // earlier per-glyph advance (w-3) shifted the hit slots so tooltips landed on
|
|
- // the wrong icon (round 19 #2); with the uniform slot the hit-test lines up.
|
|
- int h = crect.height - 1;
|
|
- int cap = (int)(28 * g_table_zoom + 0.5);
|
|
- if (cap < 8) cap = 8;
|
|
- if (h > cap) h = cap;
|
|
- if (h < 8) h = 8;
|
|
- int adv = h - 3;
|
|
- if (adv < 1) adv = 1;
|
|
int n = (int)iit->second.size();
|
|
- // A right-aligned column (round 19 #21) draws the icon block flush to the
|
|
- // cell's right edge, so measure the pointer from the block's left, not the
|
|
- // cell's left.
|
|
- int block_left = crect.x;
|
|
- if (wxcol->GetAlignment() == wxALIGN_RIGHT) {
|
|
- int content_w = n * adv;
|
|
- if (content_w < crect.width) block_left = crect.x + (crect.width - content_w);
|
|
- }
|
|
- int off = bx - block_left;
|
|
- if (off < 0) off = 0;
|
|
- int slot = off / adv;
|
|
- if (slot < 0) slot = 0;
|
|
- if (slot >= n) slot = n - 1;
|
|
+ IconSlots slots = HealthIconSlots(crect.x, crect.width, crect.height, n,
|
|
+ wxcol->GetAlignment() == wxALIGN_RIGHT);
|
|
+ int slot = HealthIconSlotAt(slots, bx, n);
|
|
+ int adv = slots.adv;
|
|
+ int block_left = slots.left;
|
|
const wxString& tip = iit->second[(size_t)slot];
|
|
if (tip.IsEmpty()) return FALSE;
|
|
// Scope the tooltip's "tip area" to just this icon's slot (round 18 #4a).
|
|
@@ -1103,49 +1268,61 @@
|
|
}
|
|
}
|
|
#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; }
|
|
- // Leave modifier-clicks to the native ctrl/shift multi-select behaviour.
|
|
- if (e.ControlDown() || e.ShiftDown()) { g_drag_anchor.erase(dv); e.Skip(); return; }
|
|
- wxDataViewItem item;
|
|
- wxDataViewColumn* col = nullptr;
|
|
- dv->HitTest(e.GetPosition(), item, col);
|
|
- if (item.IsOk()) {
|
|
- g_drag_anchor[dv] =
|
|
- (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
|
- } else {
|
|
+ // Generic wxDataViewCtrl (wxMSW): no native rubber-banding, so track a drag
|
|
+ // anchor and extend the selection to the row under the cursor. The generic
|
|
+ // control draws and receives mouse input in an inner "main window", not in
|
|
+ // the wxDataViewCtrl itself (mouse events do not propagate to parents), so
|
|
+ // the handlers bind there; HitTest wants control coordinates.
|
|
+ {
|
|
+ wxWindow* area = dv->GetMainWindow();
|
|
+ auto row_at = [dv, area](const wxPoint& area_pos, int& row) {
|
|
+ wxDataViewItem item;
|
|
+ wxDataViewColumn* col = nullptr;
|
|
+ dv->HitTest(dv->ScreenToClient(area->ClientToScreen(area_pos)), item, col);
|
|
+ if (!item.IsOk()) return false;
|
|
+ row = (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
|
+ return true;
|
|
+ };
|
|
+ area->Bind(wxEVT_LEFT_DOWN, [dv, row_at](wxMouseEvent& e) {
|
|
+ // Leave modifier-clicks to the native ctrl/shift multi-select behaviour.
|
|
+ int row = -1;
|
|
+ if (!e.ControlDown() && !e.ShiftDown() && row_at(e.GetPosition(), row)) {
|
|
+ g_drag_anchor[dv] = row;
|
|
+ } else {
|
|
+ g_drag_anchor.erase(dv);
|
|
+ }
|
|
+ e.Skip(); // let the control select the anchor row
|
|
+ });
|
|
+ area->Bind(wxEVT_MOTION, [dv, area, row_at](wxMouseEvent& e) {
|
|
+ e.Skip();
|
|
+ dvlc_update_tooltip(dv, area, e.GetPosition());
|
|
+ auto it = g_drag_anchor.find(dv);
|
|
+ int cur = -1;
|
|
+ if (!e.LeftIsDown() || it == g_drag_anchor.end() || !row_at(e.GetPosition(), cur))
|
|
+ return;
|
|
+ int lo = it->second < cur ? it->second : cur;
|
|
+ int hi = it->second < cur ? cur : it->second;
|
|
+ wxDataViewIndexListModel* model = (wxDataViewIndexListModel*)dv->GetModel();
|
|
+ wxDataViewItemArray sel;
|
|
+ for (int r = lo; r <= hi; ++r) sel.push_back(model->GetItem((unsigned)r));
|
|
+ dv->SetSelections(sel);
|
|
+ // Selecting programmatically does not emit SELECTION_CHANGED, so notify.
|
|
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
|
+ });
|
|
+ area->Bind(wxEVT_LEFT_UP, [dv](wxMouseEvent& e) {
|
|
g_drag_anchor.erase(dv);
|
|
- }
|
|
- e.Skip(); // let the native handler select the anchor row
|
|
- });
|
|
- dv->Bind(wxEVT_MOTION, [](wxMouseEvent& e) {
|
|
- wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
|
- if (!dv || !e.LeftIsDown()) { e.Skip(); return; }
|
|
- auto it = g_drag_anchor.find(dv);
|
|
- if (it == g_drag_anchor.end()) { e.Skip(); return; }
|
|
- wxDataViewItem item;
|
|
- wxDataViewColumn* col = nullptr;
|
|
- dv->HitTest(e.GetPosition(), item, col);
|
|
- if (!item.IsOk()) { e.Skip(); return; }
|
|
- wxDataViewIndexListModel* model = (wxDataViewIndexListModel*)dv->GetModel();
|
|
- int cur = (int)model->GetRow(item);
|
|
- int lo = it->second < cur ? it->second : cur;
|
|
- int hi = it->second < cur ? cur : it->second;
|
|
- dv->UnselectAll();
|
|
- for (int r = lo; r <= hi; ++r) dv->Select(model->GetItem((unsigned)r));
|
|
- // Selecting programmatically does not emit SELECTION_CHANGED, so notify.
|
|
- if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
|
- e.Skip();
|
|
- });
|
|
- dv->Bind(wxEVT_LEFT_UP, [](wxMouseEvent& e) {
|
|
- wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
|
- if (dv) g_drag_anchor.erase(dv);
|
|
- e.Skip();
|
|
- });
|
|
+ e.Skip();
|
|
+ });
|
|
+ area->Bind(wxEVT_LEAVE_WINDOW, [dv](wxMouseEvent& e) {
|
|
+ g_tip_key.erase(dv);
|
|
+ e.Skip();
|
|
+ });
|
|
+ dv->Bind(wxEVT_DESTROY, [dv](wxWindowDestroyEvent& e) {
|
|
+ g_drag_anchor.erase(dv);
|
|
+ g_tip_key.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.
|
|
@@ -1177,6 +1354,7 @@
|
|
if (reorderable) flags |= wxDATAVIEW_COL_REORDERABLE;
|
|
unsigned col = dv->GetColumnCount(); // next model column index
|
|
dvlc_store(win)->AppendColumn("string");
|
|
+ width = PxFromDip(dv, width);
|
|
dv->AppendTextColumn(wxString::FromUTF8(title), col, wxDATAVIEW_CELL_INERT,
|
|
width, dvlc_wx_align(align), flags);
|
|
// Record the 100% column width for the zoom (round 14 #3); the first column of
|
|
@@ -1196,6 +1374,7 @@
|
|
unsigned col = dv->GetColumnCount(); // next model column index
|
|
dvlc_store(win)->AppendColumn("string");
|
|
SegmentRenderer* renderer = new SegmentRenderer();
|
|
+ width = PxFromDip(dv, width);
|
|
wxAlignment al = dvlc_wx_align(align);
|
|
renderer->SetAlignment(al);
|
|
wxDataViewColumn* c = new wxDataViewColumn(wxString::FromUTF8(title), renderer, col,
|
|
@@ -1211,7 +1390,7 @@
|
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
|
unsigned col = dv->GetColumnCount();
|
|
dvlc_store(win)->AppendColumn("bool");
|
|
- dv->AppendToggleColumn(wxT(""), col, wxDATAVIEW_CELL_ACTIVATABLE, width,
|
|
+ dv->AppendToggleColumn(wxT(""), col, wxDATAVIEW_CELL_ACTIVATABLE, PxFromDip(dv, width),
|
|
wxALIGN_CENTRE, 0);
|
|
}
|
|
|
|
@@ -1356,7 +1535,8 @@
|
|
if (!c) return;
|
|
c->SetWidth(wxCOL_WIDTH_AUTOSIZE);
|
|
int w = c->GetWidth();
|
|
- const int floor_px = 24;
|
|
+ cap_px = PxFromDip(dv, cap_px);
|
|
+ const int floor_px = PxFromDip(dv, 24);
|
|
if (w < floor_px) w = floor_px;
|
|
if (cap_px > 0 && w > cap_px) w = cap_px;
|
|
c->SetWidth(w);
|
|
@@ -1483,7 +1663,7 @@
|
|
|
|
void* wxbr_gauge(void* parent, int range) {
|
|
wxGauge* g = new wxGauge((wxWindow*)parent, wxID_ANY, range < 1 ? 1 : range,
|
|
- wxDefaultPosition, wxSize(-1, 6),
|
|
+ wxDefaultPosition, wxSize(-1, PxFromDip((wxWindow*)parent, 6)),
|
|
wxGA_HORIZONTAL | wxGA_SMOOTH);
|
|
return (void*)g;
|
|
}
|
|
@@ -1510,11 +1690,10 @@
|
|
|
|
// ---- appearance / dark mode -------------------------------------------------
|
|
|
|
-void wxbr_set_appearance_system() {
|
|
-#if wxCHECK_VERSION(3, 3, 0)
|
|
- if (wxTheApp) wxTheApp->SetAppearance(wxApp::Appearance::System);
|
|
-#endif
|
|
-}
|
|
+// init_app() now sets the appearance before the frame exists (the only point
|
|
+// at which wxMSW honours it, and where ALKANE_APPEARANCE is applied); this is
|
|
+// kept for API compatibility and does nothing further.
|
|
+void wxbr_set_appearance_system() {}
|
|
|
|
int wxbr_is_dark() {
|
|
return wxSystemSettings::GetAppearance().IsDark() ? 1 : 0;
|
|
@@ -1658,7 +1837,8 @@
|
|
|
|
void* wxbr_reorder_list(void* parent, int n, const int* order, const char** items) {
|
|
wxListCtrl* lc = new wxListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
|
- wxSize(-1, 240), wxLC_REPORT | wxLC_NO_HEADER);
|
|
+ wxSize(-1, PxFromDip((wxWindow*)parent, 240)),
|
|
+ wxLC_REPORT | wxLC_NO_HEADER);
|
|
lc->EnableCheckBoxes(true);
|
|
// Narrower than before so the picker dialog is not over-wide (round 13 #1).
|
|
lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 190);
|
|
@@ -1874,7 +2054,9 @@
|
|
// given colour on a transparent bitmap so it reads as a coloured glyph on the
|
|
// native button. Emits WxEV_BUTTON_CLICKED with `id`, like a normal button.
|
|
void* wxbr_media_button(void* parent, int id, int kind, int r, int g, int b) {
|
|
- const int sz = 20;
|
|
+ // The glyph is designed on a 20x20 DIP grid and drawn at the display scale.
|
|
+ const int sz = PxFromDip((wxWindow*)parent, 20);
|
|
+ const double scale = sz / 20.0;
|
|
wxImage img(sz, sz);
|
|
img.InitAlpha();
|
|
unsigned char* a = img.GetAlpha();
|
|
@@ -1885,6 +2067,7 @@
|
|
wxGraphicsContext* gc = wxGraphicsContext::Create(mdc);
|
|
if (gc) {
|
|
gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
|
|
+ gc->Scale(scale, scale);
|
|
wxColour col(r, g, b);
|
|
gc->SetBrush(wxBrush(col));
|
|
gc->SetPen(wxPen(col, 1.0));
|
|
@@ -1915,9 +2098,10 @@
|
|
// #RRGGBB) into a wxStaticBitmap for the KPI cards (round 11 #15). The caller
|
|
// passes the target pixel size (w chosen from the SVG aspect ratio, h fixed).
|
|
void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) {
|
|
+ // A bitmap bundle (w x h DIPs) rather than a fixed bitmap, so the icon is
|
|
+ // rasterised for the window's actual display scale.
|
|
wxBitmapBundle bundle = wxBitmapBundle::FromSVG(svg, wxSize(w, h));
|
|
- wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
|
|
- return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
|
|
+ return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bundle);
|
|
}
|
|
|
|
// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell
|
|
@@ -1990,7 +2174,7 @@
|
|
int fld = (sb->GetFieldsCount() >= 3) ? 2 : 1;
|
|
wxRect r;
|
|
if (sb->GetFieldRect(fld, r)) {
|
|
- int ew = 52;
|
|
+ int ew = PxFromDip(sb, 52);
|
|
int eh = g_zoom_entry->GetBestSize().GetHeight();
|
|
if (eh > r.height - 2) eh = r.height - 2;
|
|
g_zoom_entry->SetSize(r.x + r.width - ew - 2, r.y + (r.height - eh) / 2, ew, eh);
|
|
@@ -2039,7 +2223,7 @@
|
|
wxFrame* frame = (wxFrame*)frame_ptr;
|
|
wxStatusBar* sb = frame->GetStatusBar();
|
|
if (!sb) sb = frame->CreateStatusBar();
|
|
- int widths[2] = { -1, 340 };
|
|
+ int widths[2] = { -1, PxFromDip(frame, 340) };
|
|
sb->SetFieldsCount(2);
|
|
sb->SetStatusWidths(2, widths);
|
|
if (!g_status_indicator) {
|
|
@@ -2072,12 +2256,12 @@
|
|
wxFrame* frame = (wxFrame*)frame_ptr;
|
|
wxStatusBar* sb = frame->GetStatusBar();
|
|
if (!sb) sb = frame->CreateStatusBar();
|
|
- int widths[3] = { -1, 240, 190 };
|
|
+ int widths[3] = { -1, PxFromDip(frame, 240), PxFromDip(frame, 190) };
|
|
sb->SetFieldsCount(3);
|
|
sb->SetStatusWidths(3, widths);
|
|
// A native slider needs more vertical room than a default status bar gives, so
|
|
// grow the bar to fit it (round 14 #3).
|
|
- sb->SetMinHeight(30);
|
|
+ sb->SetMinHeight(PxFromDip(frame, 30));
|
|
if (!g_zoom_slider) {
|
|
g_zoom_slider = new wxSlider(sb, wxID_ANY, 100, 50, 250);
|
|
g_zoom_slider->SetToolTip(wxT("Table zoom"));
|
|
--- a/src/widgets.rs
|
|
+++ b/src/widgets.rs
|
|
@@ -260,7 +260,8 @@
|
|
unsafe { notsafe::wxbr_launch_browser(c.as_ptr()) != 0 }
|
|
}
|
|
|
|
-/// Ask wx to follow the system light/dark appearance (no-op before 3.3).
|
|
+/// Kept for API compatibility: `init_app` already follows the system light/dark
|
|
+/// appearance (or `ALKANE_APPEARANCE=light|dark`), before any window exists.
|
|
pub fn set_appearance_system() {
|
|
unsafe { notsafe::wxbr_set_appearance_system() }
|
|
}
|