Phase 2 Flag 10: Lazarus event names (OnClick, OnChange, OnMouseDown, ...) in the Inspector Events pane; raw pointer/keyboard/double-click events wired through Holder callbacks; find_event checks raw events; class_kind aliases for ToggleButton/PasswordEntry/SearchEntry + TCheckListBox
This commit is contained in:
1 parent
7f3c430e4b
commit
156ed68046
5 files changed
+194
-20
No files matched your search
@@ -48,6 +48,9 @@ pub struct EventDef {
|
||||
pub handler: &'static str,
|
||||
/// Short human label for the Events pane.
|
||||
pub label: &'static str,
|
||||
/// Lazarus Object Inspector name, e.g. `"OnClick"` (Flag 10). Shown
|
||||
/// in the Events pane; the stored key stays the GTK signal name.
|
||||
pub lazarus: &'static str,
|
||||
pub kind: EventKind,
|
||||
/// Already wired; document only, do not reconnect.
|
||||
pub builtin: bool,
|
||||
@@ -64,6 +67,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "clicked",
|
||||
handler: "on_clicked",
|
||||
label: "Clicked",
|
||||
lazarus: "OnClick",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -72,6 +76,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "changed",
|
||||
handler: "on_changed",
|
||||
label: "Text changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -79,6 +84,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "activate",
|
||||
handler: "on_activate",
|
||||
label: "Enter pressed (activate)",
|
||||
lazarus: "OnKeyPress",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -87,6 +93,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "toggled",
|
||||
handler: "on_toggled",
|
||||
label: "Toggled",
|
||||
lazarus: "OnClick",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -94,6 +101,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "toggled",
|
||||
handler: "on_toggled",
|
||||
label: "Toggled",
|
||||
lazarus: "OnClick",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -101,6 +109,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "changed",
|
||||
handler: "on_changed",
|
||||
label: "Selection changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -108,6 +117,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "row-selected",
|
||||
handler: "on_row_selected",
|
||||
label: "Row selected",
|
||||
lazarus: "OnClick",
|
||||
kind: K::RowSelected,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -115,6 +125,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "clicked",
|
||||
handler: "on_clicked",
|
||||
label: "Clicked",
|
||||
lazarus: "OnClick",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -122,6 +133,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "draw",
|
||||
handler: "on_draw",
|
||||
label: "Draw (redraw)",
|
||||
lazarus: "OnPaint",
|
||||
kind: K::Draw,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -129,6 +141,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "value-changed",
|
||||
handler: "on_value_changed",
|
||||
label: "Value changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -136,6 +149,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "value-changed",
|
||||
handler: "on_value_changed",
|
||||
label: "Value changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -143,6 +157,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "changed",
|
||||
handler: "on_changed",
|
||||
label: "Text changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::BufferChanged,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -150,6 +165,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "delete-event",
|
||||
handler: "on_delete_event",
|
||||
label: "Window close (delete-event)",
|
||||
lazarus: "OnClose",
|
||||
kind: K::DeleteEvent,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -157,6 +173,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "changed",
|
||||
handler: "on_cell_changed",
|
||||
label: "Cell text changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::CellChanged,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -167,6 +184,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "draw",
|
||||
handler: "on_draw",
|
||||
label: "Draw (redraw)",
|
||||
lazarus: "OnPaint",
|
||||
kind: K::Draw,
|
||||
builtin: true,
|
||||
}],
|
||||
@@ -174,6 +192,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "changed",
|
||||
handler: "on_changed",
|
||||
label: "Text changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::BufferChanged,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -181,6 +200,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "draw",
|
||||
handler: "on_draw",
|
||||
label: "Draw (redraw)",
|
||||
lazarus: "OnPaint",
|
||||
kind: K::Draw,
|
||||
builtin: true,
|
||||
}],
|
||||
@@ -188,6 +208,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "switch-page",
|
||||
handler: "on_switch_page",
|
||||
label: "Page switched",
|
||||
lazarus: "OnChange",
|
||||
kind: K::SwitchPage,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -195,6 +216,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "clicked",
|
||||
handler: "on_clicked",
|
||||
label: "Tool button clicked",
|
||||
lazarus: "OnClick",
|
||||
kind: K::ItemClicked,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -202,6 +224,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "activate",
|
||||
handler: "on_activate",
|
||||
label: "Menu item activated",
|
||||
lazarus: "OnKeyPress",
|
||||
kind: K::ItemActivate,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -209,6 +232,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "value-changed",
|
||||
handler: "on_value_changed",
|
||||
label: "Value changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -216,6 +240,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "value-changed",
|
||||
handler: "on_value_changed",
|
||||
label: "Value changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -224,6 +249,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "day-selected",
|
||||
handler: "on_day_selected",
|
||||
label: "Day selected",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -231,6 +257,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "month-changed",
|
||||
handler: "on_month_changed",
|
||||
label: "Month changed",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -239,6 +266,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "color-set",
|
||||
handler: "on_color_set",
|
||||
label: "Colour chosen",
|
||||
lazarus: "OnChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
}],
|
||||
@@ -247,6 +275,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "row-activated",
|
||||
handler: "on_row_activated",
|
||||
label: "Row activated (double-click)",
|
||||
lazarus: "OnDblClick",
|
||||
kind: K::RowActivated,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -254,6 +283,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "cursor-changed",
|
||||
handler: "on_cursor_changed",
|
||||
label: "Cursor moved",
|
||||
lazarus: "OnSelectionChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -263,6 +293,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "row-activated",
|
||||
handler: "on_row_activated",
|
||||
label: "Row activated (double-click)",
|
||||
lazarus: "OnDblClick",
|
||||
kind: K::RowActivated,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -270,6 +301,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "cursor-changed",
|
||||
handler: "on_cursor_changed",
|
||||
label: "Cursor moved",
|
||||
lazarus: "OnSelectionChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -279,6 +311,7 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "row-activated",
|
||||
handler: "on_row_activated",
|
||||
label: "Row activated (double-click)",
|
||||
lazarus: "OnDblClick",
|
||||
kind: K::RowActivated,
|
||||
builtin: false,
|
||||
},
|
||||
@@ -286,14 +319,24 @@ pub fn events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
signal: "cursor-changed",
|
||||
handler: "on_cursor_changed",
|
||||
label: "Cursor moved",
|
||||
lazarus: "OnSelectionChange",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
],
|
||||
"CheckListBox" => &[EventDef {
|
||||
signal: "row-selected",
|
||||
handler: "on_row_selected",
|
||||
label: "Row selected",
|
||||
lazarus: "OnClick",
|
||||
kind: K::RowSelected,
|
||||
builtin: false,
|
||||
}],
|
||||
"Plot" => &[EventDef {
|
||||
signal: "draw",
|
||||
handler: "on_draw",
|
||||
label: "Draw (redraw)",
|
||||
lazarus: "OnPaint",
|
||||
kind: K::Draw,
|
||||
builtin: true,
|
||||
}],
|
||||
@@ -325,9 +368,71 @@ pub fn no_events_note(widget_type: &str) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// Find one event definition for a type by GTK signal name.
|
||||
/// Raw pointer/keyboard events (Flag 10): the same five for every
|
||||
/// widget type except the Toplevel window, which is not a widget in
|
||||
/// generated code. Wired through the Holder callbacks (registry.h), so
|
||||
/// they need no per-class member. Listed separately from `events_for`
|
||||
/// so the existing per-type tables — and the tests that enumerate them
|
||||
/// — are untouched.
|
||||
pub fn raw_events_for(widget_type: &str) -> &'static [EventDef] {
|
||||
use EventKind as K;
|
||||
static RAW: &[EventDef] = &[
|
||||
EventDef {
|
||||
signal: "button-press",
|
||||
handler: "on_button_press",
|
||||
label: "Mouse down",
|
||||
lazarus: "OnMouseDown",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
EventDef {
|
||||
signal: "button-release",
|
||||
handler: "on_button_release",
|
||||
label: "Mouse up",
|
||||
lazarus: "OnMouseUp",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
EventDef {
|
||||
signal: "motion",
|
||||
handler: "on_motion",
|
||||
label: "Mouse moved",
|
||||
lazarus: "OnMouseMove",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
EventDef {
|
||||
signal: "key-press",
|
||||
handler: "on_key_press",
|
||||
label: "Key pressed",
|
||||
lazarus: "OnKeyPress",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
EventDef {
|
||||
signal: "double-click",
|
||||
handler: "on_double_click",
|
||||
label: "Double-click",
|
||||
lazarus: "OnDblClick",
|
||||
kind: K::Simple,
|
||||
builtin: false,
|
||||
},
|
||||
];
|
||||
let widget_type = crate::model::class_kind(widget_type).unwrap_or(widget_type);
|
||||
if widget_type == "Toplevel" {
|
||||
&[]
|
||||
} else {
|
||||
RAW
|
||||
}
|
||||
}
|
||||
|
||||
/// Find one event definition for a type by GTK signal name. Checks the
|
||||
/// per-type table first, then the raw events.
|
||||
pub fn find_event(widget_type: &str, signal: &str) -> Option<&'static EventDef> {
|
||||
events_for(widget_type).iter().find(|d| d.signal == signal)
|
||||
events_for(widget_type)
|
||||
.iter()
|
||||
.find(|d| d.signal == signal)
|
||||
.or_else(|| raw_events_for(widget_type).iter().find(|d| d.signal == signal))
|
||||
}
|
||||
|
||||
/// Connect/disconnect one signal on a widget model; `false` if the signal
|
||||
|
||||
@@ -17,7 +17,10 @@ pub mod project_io;
|
||||
pub mod props;
|
||||
|
||||
pub use canonicalize::canonicalize;
|
||||
pub use events::{events_for, find_event, no_events_note, set_widget_signal, EventDef, EventKind};
|
||||
pub use events::{
|
||||
events_for, find_event, no_events_note, raw_events_for, set_widget_signal, EventDef,
|
||||
EventKind,
|
||||
};
|
||||
pub use model::{class_kind, find_type, looks_like_class, Project, TypeInfo, Widget, KTYPES};
|
||||
pub use project_io::{load_from_str, load_project_file, save_project_file, save_to_string};
|
||||
pub use props::{common_props, find_prop, props_for, PropDef, PropKind};
|
||||
@@ -403,6 +403,10 @@ pub fn class_kind(class: &str) -> Option<&'static str> {
|
||||
"GtkTreeView" => "TreeView",
|
||||
"XGraph" => "Plot",
|
||||
"GtkImage" => "Image",
|
||||
"GtkToggleButton" => "Checkbutton",
|
||||
"GtkPasswordEntry" => "Entry",
|
||||
"GtkSearchEntry" => "Entry",
|
||||
"TCheckListBox" => "CheckListBox",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ use crate::canvas::{delete_item, move_item, resize_item, set_prop};
|
||||
use crate::state::Shared;
|
||||
use gtk::prelude::*;
|
||||
use lightgui_core::props::{PropDef, PropKind};
|
||||
use lightgui_core::{common_props, events_for, no_events_note, props_for, set_widget_signal};
|
||||
use lightgui_core::{
|
||||
common_props, events_for, no_events_note, props_for, raw_events_for, set_widget_signal,
|
||||
};
|
||||
|
||||
fn add_row(grid: >k::Grid, row: i32, label: &str, control: >k::Widget) {
|
||||
let lab = gtk::Label::new(Some(label));
|
||||
@@ -452,21 +454,27 @@ pub fn refresh_props(app: &Shared) {
|
||||
}
|
||||
}
|
||||
// Events: one checkbutton per connectable signal.
|
||||
// Flag 10: the Lazarus name leads; the stored GTK signal and
|
||||
// handler stay visible so the generated stub is identifiable.
|
||||
let events = events_for(&wtype);
|
||||
let raw_events = raw_events_for(&wtype);
|
||||
let eh = gtk::Label::new(Some("<b>Events</b>"));
|
||||
eh.set_use_markup(true);
|
||||
eh.set_halign(gtk::Align::Start);
|
||||
grid.attach(&eh, 0, row, 2, 1);
|
||||
row += 1;
|
||||
if events.is_empty() {
|
||||
if events.is_empty() && raw_events.is_empty() {
|
||||
let note = gtk::Label::new(Some(no_events_note(&wtype)));
|
||||
note.set_halign(gtk::Align::Start);
|
||||
note.set_line_wrap(true);
|
||||
grid.attach(¬e, 0, row, 2, 1);
|
||||
row += 1;
|
||||
} else {
|
||||
for ev in events {
|
||||
let mut text = format!("{} \u{2192} {}()", ev.signal, ev.handler);
|
||||
for ev in events.iter().chain(raw_events.iter()) {
|
||||
let mut text = format!(
|
||||
"{} ({} \u{2192} {}())",
|
||||
ev.lazarus, ev.signal, ev.handler
|
||||
);
|
||||
if ev.builtin {
|
||||
text.push_str(" (always connected)");
|
||||
}
|
||||
|
||||
@@ -1482,12 +1482,47 @@ fn event_callback(kind: &str, signal: &str) -> (&'static str, &'static str, &'st
|
||||
"day-selected" => ("on_day_selected", "", ""),
|
||||
"month-changed" => ("on_month_changed", "", ""),
|
||||
"color-set" => ("on_color_set", "Srgb", ""),
|
||||
"cursor-changed" => ("on_selection_changed", "", ""),
|
||||
"cursor-changed" => {
|
||||
// XSpreadsheet has no on_selection_changed; its selection
|
||||
// callback is on_select_cell(col, row).
|
||||
if kind == "Spreadsheet" || kind == "StringGrid" {
|
||||
("on_select_cell", "int col, int row", "col, row")
|
||||
} else {
|
||||
("on_selection_changed", "", "")
|
||||
}
|
||||
}
|
||||
"delete-event" => ("on_close", "", ""),
|
||||
// Raw events (Flag 10): wired through the Holder callbacks
|
||||
// (registry.h IWidget), not a per-class member.
|
||||
"button-press" => (
|
||||
"on_mouse_down",
|
||||
"int x, int y, unsigned button",
|
||||
"x, y, button",
|
||||
),
|
||||
"button-release" => (
|
||||
"on_mouse_up",
|
||||
"int x, int y, unsigned button",
|
||||
"x, y, button",
|
||||
),
|
||||
"motion" => ("on_mouse_move", "int x, int y", "x, y"),
|
||||
"key-press" => (
|
||||
"on_key_press",
|
||||
"unsigned long key, const char* text",
|
||||
"key, text",
|
||||
),
|
||||
"double-click" => ("on_double_click", "", ""),
|
||||
_ => ("", "", ""),
|
||||
}
|
||||
}
|
||||
|
||||
/// True when the signal is wired through a Holder callback (no ".w").
|
||||
fn is_holder_event(signal: &str) -> bool {
|
||||
matches!(
|
||||
signal,
|
||||
"button-press" | "button-release" | "motion" | "key-press" | "double-click"
|
||||
)
|
||||
}
|
||||
|
||||
/// Stub function definitions for one widget's connected signals.
|
||||
fn emit_event_stubs(o: &mut String, w: &Widget) {
|
||||
for sig in &w.signals {
|
||||
@@ -1520,22 +1555,34 @@ fn emit_event_stubs(o: &mut String, w: &Widget) {
|
||||
continue;
|
||||
}
|
||||
let stub = stub_name(w, sig);
|
||||
o.push_str(&format!("void {stub}("));
|
||||
// Stub parameters and trace tail per (kind, signal). The
|
||||
// Spreadsheet/StringGrid cell events carry (col, row); the raw
|
||||
// pointer/key events carry their coordinates or key.
|
||||
let kind = class_kind(&w.widget_type).unwrap_or(&w.widget_type);
|
||||
if kind == "Spreadsheet" && sig == "changed" {
|
||||
o.push_str("int col, int row");
|
||||
}
|
||||
let (params, tail) = if (kind == "Spreadsheet" || kind == "StringGrid")
|
||||
&& (sig == "changed" || sig == "cursor-changed")
|
||||
{
|
||||
("int col, int row", " col=%d row=%d\\n\", col, row")
|
||||
} else if sig == "button-press" || sig == "button-release" {
|
||||
(
|
||||
"int x, int y, unsigned button",
|
||||
" x=%d y=%d button=%u\\n\", x, y, button",
|
||||
)
|
||||
} else if sig == "motion" {
|
||||
("int x, int y", " x=%d y=%d\\n\", x, y")
|
||||
} else if sig == "key-press" {
|
||||
(
|
||||
"unsigned long key, const char* text",
|
||||
" key=%lu text=%s\\n\", key, text ? text : \"\"",
|
||||
)
|
||||
} else {
|
||||
("", "\\n\"")
|
||||
};
|
||||
o.push_str(&format!(
|
||||
") {{\n std::printf(\"EVENT {} {}",
|
||||
"void {stub}({params}) {{\n std::printf(\"EVENT {} {}{tail});\n}}\n\n",
|
||||
esc_c(&w.name),
|
||||
esc_c(sig)
|
||||
));
|
||||
if kind == "Spreadsheet" && sig == "changed" {
|
||||
o.push_str(" col=%d row=%d\\n\", col, row");
|
||||
} else {
|
||||
o.push_str("\\n\"");
|
||||
}
|
||||
o.push_str(");\n}\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1587,8 +1634,15 @@ fn emit_event_wiring(o: &mut String, w: &Widget, var: &str, kind: &str) {
|
||||
continue;
|
||||
}
|
||||
let stub = stub_name(w, sig);
|
||||
// Holder events live on the Holder itself (var), widget callbacks
|
||||
// on the wrapped widget (var.w).
|
||||
let target = if is_holder_event(sig) {
|
||||
format!("{var}.{cb}")
|
||||
} else {
|
||||
format!("{var}.w.{cb}")
|
||||
};
|
||||
o.push_str(&format!(
|
||||
" {var}.w.{cb} = []({params}) {{ {stub}({args}); }};\n"
|
||||
" {target} = []({params}) {{ {stub}({args}); }};\n"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user