diff --git a/src/events.h b/src/events.h index b65e548..4db8559 100644 --- a/src/events.h +++ b/src/events.h @@ -1,14 +1,29 @@ -// LightGUI event table — the natural GTK signal(s) for every widget type. +// LightGUI event table — the natural signal(s) for every widget type. // // Every palette type is listed here exactly once: either with the signals // a user can connect (each gets a generated stub handler, connected via -// g_signal_connect in the generated widget class) or with an explicit -// "no events" note saying why it has none. NONE is left unexamined. +// the widget's std::function callback in the generated code) or with an +// explicit "no events" note saying why it has none. NONE is left unexamined. // The table drives three things: the designer's Events pane (main.cpp), // the code generator (generator.cpp), and the event tests. // +// Phase 2, Flag 10 (Lazarus event names): the Inspector shows the Lazarus +// Object Inspector name for each event (OnClick, OnChange, OnKeyPress, +// OnMouseDown, ...) — the `lazarus` field — while the stored key stays the +// GTK-era signal name, so saved projects and generated stub names are +// unchanged. The five raw events (button-press / button-release / motion / +// key-press / double-click) are the same for every widget type: they are +// wired through the Holder (registry.h IWidget callbacks), not through a +// per-class member, so they work for all 547 classes. The generated X +// event loop dispatches ButtonPress to the topmost widget only, and +// ButtonRelease / MotionNotify / KeyPress to every widget; the Holder +// gates the callbacks accordingly (release only after a press on the same +// widget, motion only inside the widget, key only when the widget handled +// it), and double-click is two presses within 450 ms on the same widget +// (the same rule as the designer canvas). +// // Signal kinds (how the generator wires each one): -// Simple — void on_x(); trampoline (GtkWidget*, gpointer) +// Simple — void on_x(); widget std::function callback // SwitchPage — void on_x(guint page); notebook "switch-page" // RowActivated — void on_x(GtkTreePath* path); tree "row-activated" // RowSelected — void on_x(); trampoline (GtkListBox*, GtkListBoxRow*, gpointer) @@ -44,140 +59,231 @@ enum class EventKind { }; struct EventDef { - const char* signal; // GTK signal name, e.g. "clicked" + const char* signal; // GTK signal name, e.g. "clicked" (stored key) const char* handler; // member handler name, e.g. "on_clicked" const char* label; // short human label for the Events pane EventKind kind; bool builtin = false; // already wired; document only, do not reconnect + // Lazarus Object Inspector name, e.g. "OnClick" (Flag 10). Shown in + // the Events pane; the stored key stays the GTK signal name. + const char* lazarus = nullptr; }; +// Map an XFrame class name ("GtkButton", "TButton", "GtkTextView") to the +// palette key props_for()/events_for() understand ("Button", "Text"). +// Case-insensitive match over the palette keys, plus aliases where the +// names differ. "" when nothing matches (common props + no events only). +// Moved here from main.cpp (Fix 6) so the generator — which sees snapshot +// projects whose w.type IS the class name — normalises the same way the +// Inspector does. Palette keys map to themselves. +inline std::string xframe_type_key(const std::string& cls) { + std::string s = cls; + if (s.rfind("xframe::", 0) == 0) s = s.substr(8); + if (s.rfind("Gtk", 0) == 0) + s = s.substr(3); + else if (s.rfind("T", 0) == 0 && s.size() > 1 && s[1] >= 'A' && + s[1] <= 'Z') + s = s.substr(1); + std::string l; + for (char c : s) + l += (c >= 'A' && c <= 'Z') ? (char)(c - 'A' + 'a') : c; + if (l == "textview") return "Text"; + if (l == "spinbutton") return "SpinEdit"; + if (l == "comboboxtext") return "Combobox"; + if (l == "passwordentry" || l == "searchentry") return "Entry"; + if (l == "togglebutton") return "Checkbutton"; + for (const TypeInfo& t : kTypes) { + std::string k; + for (const char* p = t.key; *p; ++p) + k += (*p >= 'A' && *p <= 'Z') ? (char)(*p - 'A' + 'a') : *p; + if (k == l) return t.key; + } + return ""; +} + inline const std::vector& events_for(const std::string& type) { using K = EventKind; + // Normalise XFrame class names to palette keys (Fix 6): the + // generator and the Inspector both see class names from snapshot + // projects, while this table is keyed by palette kind. + std::string key = xframe_type_key(type); + const std::string& t = key.empty() ? type : key; static const std::vector none; static const std::vector button = { - {"clicked", "on_clicked", "Clicked", K::Simple}, + {"clicked", "on_clicked", "Clicked", K::Simple, false, "OnClick"}, }; static const std::vector entry = { - {"changed", "on_changed", "Text changed", K::Simple}, - {"activate", "on_activate", "Enter pressed (activate)", K::Simple}, + {"changed", "on_changed", "Text changed", K::Simple, false, + "OnChange"}, + {"activate", "on_activate", "Enter pressed (activate)", K::Simple, + false, "OnKeyPress"}, }; static const std::vector checkbutton = { - {"toggled", "on_toggled", "Toggled", K::Simple}, + {"toggled", "on_toggled", "Toggled", K::Simple, false, "OnClick"}, }; static const std::vector radiobutton = { - {"toggled", "on_toggled", "Toggled", K::Simple}, + {"toggled", "on_toggled", "Toggled", K::Simple, false, "OnClick"}, }; static const std::vector combobox = { - {"changed", "on_changed", "Selection changed", K::Simple}, + {"changed", "on_changed", "Selection changed", K::Simple, false, + "OnChange"}, }; static const std::vector listbox = { - {"row-selected", "on_row_selected", "Row selected", K::RowSelected}, + {"row-selected", "on_row_selected", "Row selected", K::RowSelected, + false, "OnClick"}, }; static const std::vector menubutton = { - {"clicked", "on_clicked", "Clicked", K::Simple}, + {"clicked", "on_clicked", "Clicked", K::Simple, false, "OnClick"}, }; static const std::vector canvas = { - {"draw", "on_draw", "Draw (redraw)", K::Draw}, + {"draw", "on_draw", "Draw (redraw)", K::Draw, false, "OnPaint"}, }; static const std::vector scale = { - {"value-changed", "on_value_changed", "Value changed", K::Simple}, + {"value-changed", "on_value_changed", "Value changed", K::Simple, + false, "OnChange"}, }; static const std::vector scrollbar = { - {"value-changed", "on_value_changed", "Value changed", K::Simple}, + {"value-changed", "on_value_changed", "Value changed", K::Simple, + false, "OnChange"}, }; static const std::vector text = { - {"changed", "on_changed", "Text changed", K::BufferChanged}, + {"changed", "on_changed", "Text changed", K::BufferChanged, false, + "OnChange"}, }; static const std::vector toplevel = { {"delete-event", "on_delete_event", "Window close (delete-event)", - K::DeleteEvent}, + K::DeleteEvent, false, "OnClose"}, }; static const std::vector spreadsheet = { - {"changed", "on_cell_changed", "Cell text changed", K::CellChanged}, + {"changed", "on_cell_changed", "Cell text changed", K::CellChanged, + false, "OnChange"}, }; static const std::vector stockchart = { // Draw, wheel zoom, drag pan and the drawing tools are already // wired by the generator (on_draw, on_chart_scroll, on_chart_press, // on_chart_motion, on_chart_release, on_chart_key). - {"draw", "on_draw", "Draw (redraw)", K::Draw, true}, + {"draw", "on_draw", "Draw (redraw)", K::Draw, true, "OnPaint"}, }; static const std::vector memo = { - {"changed", "on_changed", "Text changed", K::BufferChanged}, + {"changed", "on_changed", "Text changed", K::BufferChanged, false, + "OnChange"}, }; static const std::vector shape = { - {"draw", "on_draw", "Draw (redraw)", K::Draw, true}, + {"draw", "on_draw", "Draw (redraw)", K::Draw, true, "OnPaint"}, }; static const std::vector notebook = { - {"switch-page", "on_switch_page", "Page switched", K::SwitchPage}, + {"switch-page", "on_switch_page", "Page switched", K::SwitchPage, + false, "OnChange"}, }; static const std::vector toolbar = { - {"clicked", "on_clicked", "Tool button clicked", K::ItemClicked}, + {"clicked", "on_clicked", "Tool button clicked", K::ItemClicked, + false, "OnClick"}, }; static const std::vector menubar = { - {"activate", "on_activate", "Menu item activated", K::ItemActivate}, + {"activate", "on_activate", "Menu item activated", K::ItemActivate, + false, "OnClick"}, }; static const std::vector spinedit = { - {"value-changed", "on_value_changed", "Value changed", K::Simple}, + {"value-changed", "on_value_changed", "Value changed", K::Simple, + false, "OnChange"}, }; static const std::vector trackbar = { - {"value-changed", "on_value_changed", "Value changed", K::Simple}, + {"value-changed", "on_value_changed", "Value changed", K::Simple, + false, "OnChange"}, }; static const std::vector datetimepicker = { - {"day-selected", "on_day_selected", "Day selected", K::Simple}, - {"month-changed", "on_month_changed", "Month changed", K::Simple}, + {"day-selected", "on_day_selected", "Day selected", K::Simple, false, + "OnChange"}, + {"month-changed", "on_month_changed", "Month changed", K::Simple, + false, "OnChange"}, }; static const std::vector colorbox = { - {"color-set", "on_color_set", "Colour chosen", K::Simple}, + {"color-set", "on_color_set", "Colour chosen", K::Simple, false, + "OnChange"}, }; static const std::vector listview = { {"row-activated", "on_row_activated", "Row activated (double-click)", - K::RowActivated}, - {"cursor-changed", "on_cursor_changed", "Cursor moved", K::Simple}, + K::RowActivated, false, "OnDblClick"}, + {"cursor-changed", "on_cursor_changed", "Cursor moved", K::Simple, + false, "OnSelectionChange"}, }; static const std::vector treeview = { {"row-activated", "on_row_activated", "Row activated (double-click)", - K::RowActivated}, - {"cursor-changed", "on_cursor_changed", "Cursor moved", K::Simple}, + K::RowActivated, false, "OnDblClick"}, + {"cursor-changed", "on_cursor_changed", "Cursor moved", K::Simple, + false, "OnSelectionChange"}, }; static const std::vector stringgrid = { {"row-activated", "on_row_activated", "Row activated (double-click)", - K::RowActivated}, - {"cursor-changed", "on_cursor_changed", "Cursor moved", K::Simple}, + K::RowActivated, false, "OnDblClick"}, + {"cursor-changed", "on_cursor_changed", "Cursor moved", K::Simple, + false, "OnSelectionChange"}, }; static const std::vector plot = { - {"draw", "on_draw", "Draw (redraw)", K::Draw, true}, + {"draw", "on_draw", "Draw (redraw)", K::Draw, true, "OnPaint"}, }; - if (type == "Button") return button; - if (type == "Entry") return entry; - if (type == "Checkbutton") return checkbutton; - if (type == "Radiobutton") return radiobutton; - if (type == "Combobox") return combobox; - if (type == "Listbox") return listbox; - if (type == "Menubutton") return menubutton; - if (type == "Canvas") return canvas; - if (type == "Scale") return scale; - if (type == "Scrollbar") return scrollbar; - if (type == "Text") return text; - if (type == "Toplevel") return toplevel; - if (type == "Spreadsheet") return spreadsheet; - if (type == "StockChart") return stockchart; - if (type == "Memo") return memo; - if (type == "Shape") return shape; - if (type == "Notebook") return notebook; - if (type == "ToolBar") return toolbar; - if (type == "MenuBar") return menubar; - if (type == "SpinEdit") return spinedit; - if (type == "TrackBar") return trackbar; - if (type == "DateTimePicker") return datetimepicker; - if (type == "ColorBox") return colorbox; - if (type == "ListView") return listview; - if (type == "TreeView") return treeview; - if (type == "StringGrid") return stringgrid; - if (type == "Plot") return plot; + static const std::vector checklistbox = { + {"row-selected", "on_row_selected", "Row selected", K::RowSelected, + false, "OnClick"}, + }; + if (t == "Button") return button; + if (t == "Entry") return entry; + if (t == "Checkbutton") return checkbutton; + if (t == "Radiobutton") return radiobutton; + if (t == "Combobox") return combobox; + if (t == "Listbox") return listbox; + if (t == "Menubutton") return menubutton; + if (t == "Canvas") return canvas; + if (t == "Scale") return scale; + if (t == "Scrollbar") return scrollbar; + if (t == "Text") return text; + if (t == "Toplevel") return toplevel; + if (t == "Spreadsheet") return spreadsheet; + if (t == "StockChart") return stockchart; + if (t == "Memo") return memo; + if (t == "Shape") return shape; + if (t == "Notebook") return notebook; + if (t == "ToolBar") return toolbar; + if (t == "MenuBar") return menubar; + if (t == "SpinEdit") return spinedit; + if (t == "TrackBar") return trackbar; + if (t == "DateTimePicker") return datetimepicker; + if (t == "ColorBox") return colorbox; + if (t == "ListView") return listview; + if (t == "TreeView") return treeview; + if (t == "StringGrid") return stringgrid; + if (t == "Plot") return plot; + if (t == "CheckListBox") return checklistbox; return none; // Label, Frame, GroupBox, Panel, Image, ScrollBox, // Splitter, StatusBar, ProgressBar — see no_events_note() } +// 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. +inline const std::vector& raw_events_for(const std::string& type) { + using K = EventKind; + static const std::vector none; + static const std::vector raw = { + {"button-press", "on_button_press", "Mouse down", K::Simple, false, + "OnMouseDown"}, + {"button-release", "on_button_release", "Mouse up", K::Simple, false, + "OnMouseUp"}, + {"motion", "on_motion", "Mouse moved", K::Simple, false, + "OnMouseMove"}, + {"key-press", "on_key_press", "Key pressed", K::Simple, false, + "OnKeyPress"}, + {"double-click", "on_double_click", "Double-click", K::Simple, false, + "OnDblClick"}, + }; + std::string key = xframe_type_key(type); + const std::string& t = key.empty() ? type : key; + if (t == "Toplevel") return none; + return raw; +} + // Why a type with no events has none (shown in the Events pane so the // absence is explicit, not an omission). inline std::string no_events_note(const std::string& type) { @@ -204,11 +310,15 @@ inline std::string no_events_note(const std::string& type) { return "No widget-specific signal."; } -// Find one event definition for a type by GTK signal name. +// Find one event definition for a type by GTK signal name. Checks the +// per-type table first, then the raw events (Fix 6: the type is +// normalised, so a snapshot project's "GtkButton" finds Button's events). inline const EventDef* find_event(const std::string& type, const std::string& signal) { for (const EventDef& d : events_for(type)) if (signal == d.signal) return &d; + for (const EventDef& d : raw_events_for(type)) + if (signal == d.signal) return &d; return nullptr; } diff --git a/src/generator.cpp b/src/generator.cpp index f5413dc..182a54a 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -316,9 +316,12 @@ static const XFrameMap kXFrameMap[] = { {"Plot", "XGraph", "set_white_color_rgb", "", false, false}, }; +// Fix 6: match the palette key OR the XFrame class name — snapshot +// projects carry the class name ("GtkButton"), design-time projects the +// palette key ("Button"). static const XFrameMap* find_map(const std::string& key) { for (const XFrameMap& m : kXFrameMap) - if (key == m.key) return &m; + if (key == m.key || key == m.cls) return &m; return nullptr; } @@ -489,7 +492,10 @@ static std::string tree_node_expr(const std::vector& segs, static void emit_widget_props(std::ostringstream& o, const Widget& w, const XFrameMap& m, const std::string& var) { - const std::string& t = w.type; + // Fix 6: snapshot projects carry the XFrame class name; the branches + // below are keyed by palette kind. + std::string kind = xframe_type_key(w.type); + const std::string& t = kind.empty() ? w.type : kind; auto has = [&](const std::string& n) { return w.props.count(n) && !w.props.at(n).empty(); }; @@ -891,20 +897,30 @@ static std::string stub_name(const Widget& w, const std::string& signal) { // The XFrame callback member for (type, signal), or "" when the class // has none. `lambda_params` is the callback's parameter list for the // wiring lambda; `pass_args` is what the lambda forwards to the stub. +// True when the signal is wired through a Holder callback (no ".w"). +static bool is_holder_event(const std::string& signal) { + return signal == "button-press" || signal == "button-release" || + signal == "motion" || signal == "key-press" || + signal == "double-click"; +} + static std::string event_callback(const std::string& type, const std::string& signal, std::string& lambda_params, std::string& pass_args) { lambda_params = ""; pass_args = ""; + // Fix 6: snapshot projects carry the class name. + std::string kind = xframe_type_key(type); + const std::string& t = kind.empty() ? type : kind; if (signal == "clicked") return "on_click"; if (signal == "toggled") { lambda_params = "bool"; return "on_toggled"; } if (signal == "changed") { - if (type == "Memo") return "on_change"; - if (type == "Spreadsheet") { + if (t == "Memo") return "on_change"; + if (t == "Spreadsheet") { lambda_params = "int col, int row"; pass_args = "col, row"; return "on_cell_change"; @@ -913,7 +929,7 @@ static std::string event_callback(const std::string& type, } if (signal == "activate") return "on_activate"; if (signal == "value-changed") { - if (type == "SpinEdit") lambda_params = "double"; + if (t == "SpinEdit") lambda_params = "double"; return "on_value_changed"; } if (signal == "row-selected") { @@ -930,13 +946,48 @@ static std::string event_callback(const std::string& type, lambda_params = "Srgb"; return "on_color_set"; } - if (signal == "cursor-changed") return "on_selection_changed"; + if (signal == "cursor-changed") { + // XSpreadsheet has no on_selection_changed; its selection + // callback is on_select_cell(col, row). + if (t == "Spreadsheet" || t == "StringGrid") { + lambda_params = "int col, int row"; + pass_args = "col, row"; + return "on_select_cell"; + } + return "on_selection_changed"; + } if (signal == "delete-event") return "on_close"; + // Raw events (Flag 10): wired through the Holder callbacks + // (registry.h IWidget), not a per-class member. + if (signal == "button-press") { + lambda_params = "int x, int y, unsigned button"; + pass_args = "x, y, button"; + return "on_mouse_down"; + } + if (signal == "button-release") { + lambda_params = "int x, int y, unsigned button"; + pass_args = "x, y, button"; + return "on_mouse_up"; + } + if (signal == "motion") { + lambda_params = "int x, int y"; + pass_args = "x, y"; + return "on_mouse_move"; + } + if (signal == "key-press") { + lambda_params = "unsigned long key, const char* text"; + pass_args = "key, text"; + return "on_key_press"; + } + if (signal == "double-click") return "on_double_click"; return ""; } // Stub function definitions for one widget's connected signals. static void emit_event_stubs(std::ostringstream& o, const Widget& w) { + // Fix 6: snapshot projects carry the class name. + std::string kind = xframe_type_key(w.type); + const std::string& t = kind.empty() ? w.type : kind; for (const std::string& sig : w.signals) { const EventDef* d = find_event(w.type, sig); if (!d || d->builtin) continue; @@ -963,22 +1014,37 @@ static void emit_event_stubs(std::ostringstream& o, const Widget& w) { continue; } std::string stub = stub_name(w, sig); - o << "void " << stub << "("; - if (w.type == "Spreadsheet" && sig == "changed") - o << "int col, int row"; - o << ") {\n" - << " std::printf(\"EVENT " << esc_c(w.name) << " " << esc_c(sig); - if (w.type == "Spreadsheet" && sig == "changed") - o << " col=%d row=%d\\n\", col, row"; - else - o << "\\n\""; - o << ");\n}\n\n"; + // 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. + std::string params; + std::string tail = "\\n\""; + if ((t == "Spreadsheet" || t == "StringGrid") && + (sig == "changed" || sig == "cursor-changed")) { + params = "int col, int row"; + tail = " col=%d row=%d\\n\", col, row"; + } else if (sig == "button-press" || sig == "button-release") { + params = "int x, int y, unsigned button"; + tail = " x=%d y=%d button=%u\\n\", x, y, button"; + } else if (sig == "motion") { + params = "int x, int y"; + tail = " x=%d y=%d\\n\", x, y"; + } else if (sig == "key-press") { + params = "unsigned long key, const char* text"; + tail = " key=%lu text=%s\\n\", key, text ? text : \"\""; + } + o << "void " << stub << "(" << params << ") {\n" + << " std::printf(\"EVENT " << esc_c(w.name) << " " << esc_c(sig) + << tail << ");\n}\n\n"; } } // Wiring lines for one widget's connected signals (after construction). static void emit_event_wiring(std::ostringstream& o, const Widget& w, const std::string& var) { + // Fix 6: snapshot projects carry the class name. + std::string kind = xframe_type_key(w.type); + const std::string& t = kind.empty() ? w.type : kind; for (const std::string& sig : w.signals) { const EventDef* d = find_event(w.type, sig); if (!d || d->builtin) continue; @@ -1012,7 +1078,7 @@ static void emit_event_wiring(std::ostringstream& o, const Widget& w, continue; } std::string params, args; - std::string cb = event_callback(w.type, sig, params, args); + std::string cb = event_callback(t, sig, params, args); if (cb.empty()) { o << " // NOTE: no XFrame callback for \"" << sig << "\" on this widget; " << stub_name(w, sig) @@ -1020,7 +1086,10 @@ static void emit_event_wiring(std::ostringstream& o, const Widget& w, continue; } std::string stub = stub_name(w, sig); - o << " " << var << ".w." << cb << " = ["; + // Holder events live on the Holder itself (var), widget callbacks + // on the wrapped widget (var.w). + o << " " << var << (is_holder_event(sig) ? "." : ".w.") << cb + << " = ["; o << "](" << params << ") { " << stub << "(" << args << "); };\n"; } } diff --git a/src/main.cpp b/src/main.cpp index 6e9d134..df03c19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1873,35 +1873,7 @@ static GtkWidget* make_geo_spin(double value, double lo, double hi, return s; } -// Fix 6: map an XFrame class name ("GtkButton", "TButton", -// "GtkTextView") to the GTK palette key props_for()/events_for() -// understand ("Button", "Text"). Case-insensitive match over the -// palette keys, plus aliases where the names differ. "" when nothing -// matches (common props + no events only). -static std::string xframe_type_key(const std::string& cls) { - std::string s = cls; - if (s.rfind("xframe::", 0) == 0) s = s.substr(8); - if (s.rfind("Gtk", 0) == 0) - s = s.substr(3); - else if (s.rfind("T", 0) == 0 && s.size() > 1 && s[1] >= 'A' && - s[1] <= 'Z') - s = s.substr(1); - std::string l; - for (char c : s) - l += (c >= 'A' && c <= 'Z') ? (char)(c - 'A' + 'a') : c; - if (l == "textview") return "Text"; - if (l == "spinbutton") return "SpinEdit"; - if (l == "comboboxtext") return "Combobox"; - if (l == "passwordentry" || l == "searchentry") return "Entry"; - if (l == "togglebutton") return "Checkbutton"; - for (const TypeInfo& t : kTypes) { - std::string k; - for (const char* p = t.key; *p; ++p) - k += (*p >= 'A' && *p <= 'Z') ? (char)(*p - 'A' + 'a') : *p; - if (k == l) return t.key; - } - return ""; -} +// xframe_type_key() lives in events.h (shared with the generator). static GtkWidget* make_xframe_geo_spin(double value, double lo, double hi, const char* which) { @@ -2121,16 +2093,24 @@ static void refresh_xframe_props() { gtk_widget_set_halign(ev_hdr, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(g_props_grid), ev_hdr, 0, row++, 2, 1); const std::vector& evs = events_for(key); - if (evs.empty()) { + const std::vector& raw_evs = raw_events_for(key); + std::vector all_evs; + for (const EventDef& d : evs) all_evs.push_back(&d); + for (const EventDef& d : raw_evs) all_evs.push_back(&d); + if (all_evs.empty()) { GtkWidget* note = gtk_label_new( no_events_note(key.empty() ? m.type : key).c_str()); gtk_label_set_line_wrap(GTK_LABEL(note), TRUE); gtk_widget_set_halign(note, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(g_props_grid), note, 0, row++, 2, 1); } - for (const EventDef& d : evs) { - std::string text = std::string(d.signal) + " → " + d.handler + - "()"; + for (const EventDef* dp : all_evs) { + const EventDef& d = *dp; + // Flag 10: the Lazarus name leads; the stored GTK signal and + // handler stay visible so the generated stub is identifiable. + std::string text = + std::string(d.lazarus ? d.lazarus : d.signal) + " (" + + d.signal + " → " + d.handler + "())"; if (d.builtin) text += " (always connected)"; GtkWidget* c = gtk_check_button_new_with_label(text.c_str()); bool on = d.builtin || @@ -2277,15 +2257,23 @@ static void refresh_props() { gtk_widget_set_halign(ev_hdr, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(g_props_grid), ev_hdr, 0, row++, 2, 1); const std::vector& evs = events_for(m.type); - if (evs.empty()) { + const std::vector& raw_evs = raw_events_for(m.type); + std::vector all_evs; + for (const EventDef& d : evs) all_evs.push_back(&d); + for (const EventDef& d : raw_evs) all_evs.push_back(&d); + if (all_evs.empty()) { GtkWidget* note = gtk_label_new(no_events_note(m.type).c_str()); gtk_label_set_line_wrap(GTK_LABEL(note), TRUE); gtk_widget_set_halign(note, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(g_props_grid), note, 0, row++, 2, 1); } - for (const EventDef& d : evs) { - std::string text = std::string(d.signal) + " → " + d.handler + - "()"; + for (const EventDef* dp : all_evs) { + const EventDef& d = *dp; + // Flag 10: the Lazarus name leads; the stored GTK signal and + // handler stay visible so the generated stub is identifiable. + std::string text = + std::string(d.lazarus ? d.lazarus : d.signal) + " (" + + d.signal + " → " + d.handler + "())"; if (d.builtin) text += " (always connected)"; GtkWidget* c = gtk_check_button_new_with_label(text.c_str()); bool on = d.builtin || @@ -5104,7 +5092,7 @@ static gboolean selftest_step(gpointer) { }; // Wiring callback per signal (generator.cpp event_callback), // "" when the generator emits a stub with no wiring line. - auto wiring_cb = [](const std::string&, const std::string& sig) + auto wiring_cb = [](const std::string& type, const std::string& sig) -> std::string { if (sig == "clicked") return "on_click"; if (sig == "toggled") return "on_toggled"; @@ -5116,7 +5104,10 @@ static gboolean selftest_step(gpointer) { if (sig == "day-selected") return "on_day_selected"; if (sig == "month-changed") return "on_month_changed"; if (sig == "color-set") return "on_color_set"; - if (sig == "cursor-changed") return "on_selection_changed"; + if (sig == "cursor-changed") + return (type == "Spreadsheet" || type == "StringGrid") + ? "on_select_cell" + : "on_selection_changed"; if (sig == "delete-event") return "on_close"; return ""; }; diff --git a/widgets/common/registry.h b/widgets/common/registry.h index a2b3144..e09c204 100644 --- a/widgets/common/registry.h +++ b/widgets/common/registry.h @@ -3,6 +3,8 @@ // and a type-erased factory over all 547 XFrame widget classes. #pragma once +#include +#include #include #include #include @@ -1246,6 +1248,19 @@ struct IWidget { virtual bool set_cursor_visible(bool) { return false; } virtual bool set_multi_select(bool) { return false; } virtual std::string get_text() { return ""; } + // Phase 2, Flag 10: raw pointer/keyboard callbacks, set by the + // generator on the Holder when the corresponding Lazarus event + // (OnMouseDown, OnMouseUp, OnMouseMove, OnKeyPress, OnDblClick) is + // connected. They live on the Holder (not the wrapped widget) so + // they work for every class with no per-class member. The Holder + // overrides below gate them: release only after a press on the + // same widget, motion only inside the widget, key only when the + // widget handled it, double-click two presses within 450 ms. + std::function on_mouse_down; + std::function on_mouse_up; + std::function on_mouse_move; + std::function on_key_press; + std::function on_double_click; }; namespace detail { @@ -1398,6 +1413,10 @@ struct has_get_text().get_text())>> : s template struct Holder : IWidget { T w; + // Double-click tracking (450 ms, same rule as the designer canvas) + // and press latching for the mouse-up gate (Flag 10). + std::chrono::steady_clock::time_point last_press_; + bool pressed_ = false; Holder(Display* d, int s, Window win, GC gc, SStyle_Manager* st, int x, int y, int ww, int hh) : w(d, s, win, gc, st, x, y, ww, hh) {} @@ -1405,10 +1424,34 @@ struct Holder : IWidget { void set_style_name(const std::string& s) override { w.set_style_name(s); } void set_bounds(int x, int y, int ww, int hh) override { w.set_bounds(x, y, ww, hh); } bool contains(int x, int y) override { return w.contains(x, y); } - bool on_button_press(int x, int y, unsigned int b) override { return w.on_button_press(x, y, b); } - bool on_button_release(int x, int y, unsigned int b) override { return w.on_button_release(x, y, b); } - bool on_motion(int x, int y) override { return w.on_motion(x, y); } - bool on_key(KeySym k, const char* s) override { return w.on_key(k, s); } + bool on_button_press(int x, int y, unsigned int b) override { + bool handled = w.on_button_press(x, y, b); + auto now = std::chrono::steady_clock::now(); + if (on_double_click && + now - last_press_ < std::chrono::milliseconds(450)) + on_double_click(); + last_press_ = now; + pressed_ = true; + if (on_mouse_down) on_mouse_down(x, y, b); + return handled; + } + bool on_button_release(int x, int y, unsigned int b) override { + bool handled = w.on_button_release(x, y, b); + if (pressed_ && on_mouse_up) on_mouse_up(x, y, b); + pressed_ = false; + return handled; + } + bool on_motion(int x, int y) override { + bool handled = w.on_motion(x, y); + if (on_mouse_move && w.contains(x, y)) on_mouse_move(x, y); + return handled; + } + bool on_key(KeySym k, const char* s) override { + bool handled = w.on_key(k, s); + if (handled && on_key_press) + on_key_press((unsigned long)k, s); + return handled; + } int width() override { return w.width(); } int height() override { return w.height(); } bool set_text(const std::string& t) override { diff --git a/widgets/tools/gen_registry.py b/widgets/tools/gen_registry.py index b519eea..0d9fe8a 100644 --- a/widgets/tools/gen_registry.py +++ b/widgets/tools/gen_registry.py @@ -45,6 +45,8 @@ HEADER = """// GENERATED by tools/gen_registry.py — do not edit by hand. // and a type-erased factory over all {count} XFrame widget classes. #pragma once +#include +#include #include #include #include @@ -141,6 +143,19 @@ struct IWidget {{ virtual bool set_cursor_visible(bool) {{ return false; }} virtual bool set_multi_select(bool) {{ return false; }} virtual std::string get_text() {{ return ""; }} + // Phase 2, Flag 10: raw pointer/keyboard callbacks, set by the + // generator on the Holder when the corresponding Lazarus event + // (OnMouseDown, OnMouseUp, OnMouseMove, OnKeyPress, OnDblClick) is + // connected. They live on the Holder (not the wrapped widget) so + // they work for every class with no per-class member. The Holder + // overrides below gate them: release only after a press on the + // same widget, motion only inside the widget, key only when the + // widget handled it, double-click two presses within 450 ms. + std::function on_mouse_down; + std::function on_mouse_up; + std::function on_mouse_move; + std::function on_key_press; + std::function on_double_click; }}; namespace detail {{ @@ -293,6 +308,10 @@ struct has_get_text().get_text())>> : s template struct Holder : IWidget {{ T w; + // Double-click tracking (450 ms, same rule as the designer canvas) + // and press latching for the mouse-up gate (Flag 10). + std::chrono::steady_clock::time_point last_press_; + bool pressed_ = false; Holder(Display* d, int s, Window win, GC gc, SStyle_Manager* st, int x, int y, int ww, int hh) : w(d, s, win, gc, st, x, y, ww, hh) {{}} @@ -300,10 +319,34 @@ struct Holder : IWidget {{ void set_style_name(const std::string& s) override {{ w.set_style_name(s); }} void set_bounds(int x, int y, int ww, int hh) override {{ w.set_bounds(x, y, ww, hh); }} bool contains(int x, int y) override {{ return w.contains(x, y); }} - bool on_button_press(int x, int y, unsigned int b) override {{ return w.on_button_press(x, y, b); }} - bool on_button_release(int x, int y, unsigned int b) override {{ return w.on_button_release(x, y, b); }} - bool on_motion(int x, int y) override {{ return w.on_motion(x, y); }} - bool on_key(KeySym k, const char* s) override {{ return w.on_key(k, s); }} + bool on_button_press(int x, int y, unsigned int b) override {{ + bool handled = w.on_button_press(x, y, b); + auto now = std::chrono::steady_clock::now(); + if (on_double_click && + now - last_press_ < std::chrono::milliseconds(450)) + on_double_click(); + last_press_ = now; + pressed_ = true; + if (on_mouse_down) on_mouse_down(x, y, b); + return handled; + }} + bool on_button_release(int x, int y, unsigned int b) override {{ + bool handled = w.on_button_release(x, y, b); + if (pressed_ && on_mouse_up) on_mouse_up(x, y, b); + pressed_ = false; + return handled; + }} + bool on_motion(int x, int y) override {{ + bool handled = w.on_motion(x, y); + if (on_mouse_move && w.contains(x, y)) on_mouse_move(x, y); + return handled; + }} + bool on_key(KeySym k, const char* s) override {{ + bool handled = w.on_key(k, s); + if (handled && on_key_press) + on_key_press((unsigned long)k, s); + return handled; + }} int width() override {{ return w.width(); }} int height() override {{ return w.height(); }} bool set_text(const std::string& t) override {{