Phase 3: generator emits new props (Shape as TShape, ToggleButton, root window position/state/border-style)

This commit is contained in:
cnmcdee committed 2026-11-30 11:57:56 +00:00
1 parent bf430db324
commit 5135985b93
1 file changed
+306 -8
+306 -8
View File
@@ -282,6 +282,7 @@ static const XFrameMap kXFrameMap[] = {
{"Label", "GtkLabel", "set_fill_color_rgb", "", false, false},
{"Entry", "GtkEntry", "set_fill_color_rgb", "", false, false},
{"Checkbutton", "GtkCheckButton", "", "", false, false},
{"ToggleButton", "GtkToggleButton", "", "", false, false},
{"Radiobutton", "GtkRadioButton", "", "", false, false},
{"Frame", "GtkFrame", "", "", false, false},
{"Combobox", "GtkComboBoxText", "", "", false, false},
@@ -299,7 +300,7 @@ static const XFrameMap kXFrameMap[] = {
{"GroupBox", "GtkFrame", "", "", false, false},
{"Panel", "GtkFrame", "", "", false, false},
{"Image", "GtkImage", "", "", false, false},
{"Shape", "GtkDrawingArea", "", "", false, false},
{"Shape", "TShape", "", "", false, false},
{"Notebook", "GtkNotebook", "", "", false, false},
{"ScrollBox", "GtkScrolledWindow", "set_viewport_background_color_rgb", "", false, false},
{"Splitter", "GtkPaned", "", "", false, false},
@@ -527,10 +528,26 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (has("label"))
o << " " << var << ".w.set_label(\"" << esc_c(prop_or(w, "label", ""))
<< "\");\n";
if (w.props.count("label-xalign"))
o << " " << var << ".w.set_label_xalign("
<< fmt_double(prop_or(w, "label-xalign", "0")) << ");\n";
if (w.props.count("inset"))
o << " " << var << ".w.set_inset("
<< prop_int(w, "inset", 8) << ");\n";
if (w.props.count("top-inset"))
o << " " << var << ".w.set_top_inset("
<< prop_int(w, "top-inset", 14) << ");\n";
} else if (t == "StatusBar") {
if (has("text"))
o << " " << var << ".w.set_text(\"" << esc_c(prop_or(w, "text", ""))
<< "\");\n";
if (has("panels"))
o << " " << var << ".w.set_items(\"" << esc_c(prop_or(w, "panels", ""))
<< "\");\n";
if (w.props.count("size-grip"))
o << " " << var << ".w.set_size_grip("
<< (prop_bool(w, "size-grip", true) ? "true" : "false")
<< ");\n";
} else if (has("label")) {
o << " " << var << ".w.set_text(\"" << esc_c(prop_or(w, "label", ""))
<< "\");\n";
@@ -625,6 +642,20 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (has("value-unchecked"))
o << " " << var << ".w.set_value_unchecked(\""
<< esc_c(prop_or(w, "value-unchecked", "")) << "\");\n";
} else if (t == "ToggleButton") {
if (w.props.count("active"))
o << " " << var << ".w.set_active("
<< (prop_bool(w, "active", false) ? "true" : "false") << ");\n";
if (w.props.count("group-index") && prop_int(w, "group-index", 0) != 0)
o << " " << var << ".w.set_group_index("
<< prop_int(w, "group-index", 0) << ");\n";
if (w.props.count("allow-all-up"))
o << " " << var << ".w.set_allow_all_up("
<< (prop_bool(w, "allow-all-up", false) ? "true" : "false")
<< ");\n";
if (w.props.count("flat"))
o << " " << var << ".w.set_flat("
<< (prop_bool(w, "flat", false) ? "true" : "false") << ");\n";
} else if (t == "Radiobutton") {
int grp = prop_int(w, "group", 0);
if (grp != 0) {
@@ -821,6 +852,15 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (w.props.count("page"))
o << " " << var << ".w.set_current_page("
<< prop_int(w, "page", 0) << ");\n";
if (w.props.count("tab-height"))
o << " " << var << ".w.set_tab_height("
<< prop_int(w, "tab-height", 26) << ");\n";
if (w.props.count("tab-position"))
o << " " << var << ".w.set_tab_position("
<< prop_int(w, "tab-position", 0) << ");\n";
if (w.props.count("tab-width") && prop_int(w, "tab-width", 0) != 0)
o << " " << var << ".w.set_tab_width("
<< prop_int(w, "tab-width", 0) << ");\n";
} else if (t == "Splitter") {
if (w.props.count("position"))
o << " " << var << ".w.set_position("
@@ -828,6 +868,16 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (w.props.count("orientation"))
o << " " << var << ".w.set_orientation("
<< prop_int(w, "orientation", 0) << ");\n";
if (w.props.count("min-size") && prop_int(w, "min-size", 0) != 0)
o << " " << var << ".w.set_min_size("
<< prop_int(w, "min-size", 0) << ");\n";
if (w.props.count("resize-style"))
o << " " << var << ".w.set_resize_style("
<< prop_int(w, "resize-style", 0) << ");\n";
if (w.props.count("auto-snap"))
o << " " << var << ".w.set_auto_snap("
<< (prop_bool(w, "auto-snap", false) ? "true" : "false")
<< ");\n";
} else if (t == "ToolBar") {
if (has("items")) {
o << " " << var << ".w.set_items({";
@@ -839,6 +889,21 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
}
o << "});\n";
}
if (w.props.count("show-captions"))
o << " " << var << ".w.set_show_captions("
<< (prop_bool(w, "show-captions", true) ? "true" : "false")
<< ");\n";
if (w.props.count("flat"))
o << " " << var << ".w.set_flat("
<< (prop_bool(w, "flat", false) ? "true" : "false") << ");\n";
if (w.props.count("button-width") &&
prop_int(w, "button-width", 0) != 0)
o << " " << var << ".w.set_button_width("
<< prop_int(w, "button-width", 0) << ");\n";
if (w.props.count("button-height") &&
prop_int(w, "button-height", 0) != 0)
o << " " << var << ".w.set_button_height("
<< prop_int(w, "button-height", 0) << ");\n";
} else if (t == "MenuBar") {
if (has("menus")) {
o << " " << var << ".w.set_items({";
@@ -868,6 +933,10 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (w.props.count("wrap"))
o << " " << var << ".w.set_wrap("
<< (prop_bool(w, "wrap", false) ? "true" : "false") << ");\n";
if (w.props.count("editor-enabled"))
o << " " << var << ".w.set_editable("
<< (prop_bool(w, "editor-enabled", true) ? "true" : "false")
<< ");\n";
} else if (t == "TrackBar") {
int lo = prop_int(w, "minimum", 0);
int hi = prop_int(w, "maximum", 100);
@@ -905,13 +974,39 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
o << " " << var << ".w.set_sel_end("
<< fmt_double(prop_or(w, "sel-end", "0")) << ");\n";
} else if (t == "ProgressBar") {
if (w.props.count("fraction"))
if (w.props.count("minimum"))
o << " " << var << ".w.set_min("
<< fmt_double(prop_or(w, "minimum", "0")) << ");\n";
if (w.props.count("maximum"))
o << " " << var << ".w.set_max("
<< fmt_double(prop_or(w, "maximum", "100")) << ");\n";
if (w.props.count("position"))
o << " " << var << ".w.set_position("
<< fmt_double(prop_or(w, "position", "45")) << ");\n";
else if (w.props.count("fraction"))
o << " " << var << ".w.set_fraction("
<< fmt_double(prop_or(w, "fraction", "0")) << ");\n";
if (w.props.count("step") &&
std::atof(prop_or(w, "step", "1").c_str()) != 1.0)
o << " " << var << ".w.set_step("
<< fmt_double(prop_or(w, "step", "1")) << ");\n";
if (w.props.count("show-text"))
o << " " << var << ".w.set_show_text("
<< (prop_bool(w, "show-text", false) ? "true" : "false")
<< ");\n";
if (w.props.count("pulsing"))
o << " " << var << ".w.set_pulsing("
<< (prop_bool(w, "pulsing", false) ? "true" : "false")
<< ");\n";
if (w.props.count("inverted"))
o << " " << var << ".w.set_inverted("
<< (prop_bool(w, "inverted", false) ? "true" : "false")
<< ");\n";
std::string bar = prop_rgb_args(w, "bar-color");
if (!bar.empty()) emit_color_call(o, var, "set_bar_color_rgb", false, bar);
std::string trough = prop_rgb_args(w, "trough-color");
if (!trough.empty())
emit_color_call(o, var, "set_trough_color_rgb", false, trough);
} else if (t == "DateTimePicker") {
if (has("date")) {
int y = 0, mo = 0, d = 0;
@@ -928,13 +1023,69 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
o << " " << var << ".w.set_show_day_names("
<< (prop_bool(w, "show-day-names", true) ? "true" : "false")
<< ");\n";
if (w.props.count("show-week-numbers"))
o << " " << var << ".w.set_show_week_numbers("
<< (prop_bool(w, "show-week-numbers", false) ? "true" : "false")
<< ");\n";
std::string gc = prop_rgb_args(w, "grid-color");
if (!gc.empty()) emit_color_call(o, var, "set_grid_color_rgb", false, gc);
std::string sf = prop_rgb_args(w, "selected-fill-color");
if (!sf.empty())
emit_color_call(o, var, "set_selected_fill_color_rgb", false, sf);
std::string st = prop_rgb_args(w, "selected-text-color");
if (!st.empty())
emit_color_call(o, var, "set_selected_text_color_rgb", false, st);
std::string tc = prop_rgb_args(w, "today-color");
if (!tc.empty()) emit_color_call(o, var, "set_today_color_rgb", false, tc);
std::string dc = prop_rgb_args(w, "dim-text-color");
if (!dc.empty())
emit_color_call(o, var, "set_dim_text_color_rgb", false, dc);
std::string wc = prop_rgb_args(w, "weekends-color");
if (!wc.empty())
emit_color_call(o, var, "set_weekends_color_rgb", false, wc);
std::string xc = prop_rgb_args(w, "disabled-color");
if (!xc.empty())
emit_color_call(o, var, "set_disabled_color_rgb", false, xc);
} else if (t == "ColorBox") {
std::string rgb = prop_rgb_args(w, "color");
if (!rgb.empty()) emit_color_call(o, var, "set_color_rgb", false, rgb);
if (w.props.count("style"))
o << " " << var << ".w.set_style("
<< prop_int(w, "style", 0) << ");\n";
std::string dcrgb = prop_rgb_args(w, "default-color");
if (!dcrgb.empty())
emit_color_call(o, var, "set_default_color_rgb", false, dcrgb);
std::string ncrgb = prop_rgb_args(w, "none-color");
if (!ncrgb.empty())
emit_color_call(o, var, "set_none_color_rgb", false, ncrgb);
} else if (t == "ListView") {
if (has("items"))
for (const std::string& row : split_on(';', prop_or(w, "items", "")))
o << " " << var << ".w.add_item(\"" << esc_c(row) << "\");\n";
if (w.props.count("item-index") && prop_int(w, "item-index", -1) >= 0)
o << " " << var << ".w.set_selected_row("
<< prop_int(w, "item-index", -1) << ");\n";
if (w.props.count("item-height") && prop_int(w, "item-height", 0) > 0)
o << " " << var << ".w.set_row_height("
<< prop_int(w, "item-height", 0) << ");\n";
if (w.props.count("view-style"))
o << " " << var << ".w.set_view_style("
<< prop_int(w, "view-style", 0) << ");\n";
if (w.props.count("grid-lines"))
o << " " << var << ".w.set_grid_lines("
<< (prop_bool(w, "grid-lines", false) ? "true" : "false")
<< ");\n";
if (w.props.count("row-select"))
o << " " << var << ".w.set_row_select("
<< (prop_bool(w, "row-select", true) ? "true" : "false")
<< ");\n";
if (w.props.count("multi-select"))
o << " " << var << ".w.set_multi_select("
<< (prop_bool(w, "multi-select", false) ? "true" : "false")
<< ");\n";
if (w.props.count("sort-type"))
o << " " << var << ".w.set_sort_type("
<< prop_int(w, "sort-type", 0) << ");\n";
} else if (t == "TreeView") {
if (has("items")) {
std::vector<std::string> roots;
@@ -951,12 +1102,70 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
}
o << "});\n";
}
if (w.props.count("item-index") && prop_int(w, "item-index", -1) >= 0)
o << " " << var << ".w.set_selected_row("
<< prop_int(w, "item-index", -1) << ");\n";
if (w.props.count("item-height") && prop_int(w, "item-height", 0) > 0)
o << " " << var << ".w.set_row_height("
<< prop_int(w, "item-height", 0) << ");\n";
if (w.props.count("header-height"))
o << " " << var << ".w.set_header_height("
<< prop_int(w, "header-height", 22) << ");\n";
if (w.props.count("headers-visible"))
o << " " << var << ".w.set_headers_visible("
<< (prop_bool(w, "headers-visible", true) ? "true" : "false")
<< ");\n";
if (w.props.count("grid-lines"))
o << " " << var << ".w.set_grid_lines("
<< (prop_bool(w, "grid-lines", false) ? "true" : "false")
<< ");\n";
if (w.props.count("row-select"))
o << " " << var << ".w.set_row_select("
<< (prop_bool(w, "row-select", true) ? "true" : "false")
<< ");\n";
if (w.props.count("multi-select"))
o << " " << var << ".w.set_multi_select("
<< (prop_bool(w, "multi-select", false) ? "true" : "false")
<< ");\n";
if (w.props.count("sort-type"))
o << " " << var << ".w.set_sort_type("
<< prop_int(w, "sort-type", 0) << ");\n";
if (w.props.count("indent"))
o << " " << var << ".w.set_indent("
<< prop_int(w, "indent", 16) << ");\n";
if (w.props.count("show-buttons"))
o << " " << var << ".w.set_show_buttons("
<< (prop_bool(w, "show-buttons", true) ? "true" : "false")
<< ");\n";
if (w.props.count("show-lines"))
o << " " << var << ".w.set_show_lines("
<< (prop_bool(w, "show-lines", true) ? "true" : "false")
<< ");\n";
if (w.props.count("show-root"))
o << " " << var << ".w.set_show_root("
<< (prop_bool(w, "show-root", true) ? "true" : "false")
<< ");\n";
} else if (t == "Spreadsheet" || t == "StringGrid") {
int cols = prop_int(w, "columns", 4);
int rows = prop_int(w, "rows", 5);
if (w.props.count("columns") || w.props.count("rows"))
o << " " << var << ".w.set_size(" << cols << ", " << rows
<< ");\n";
if (w.props.count("fixed-cols") && prop_int(w, "fixed-cols", 0) != 0)
o << " " << var << ".w.set_frozen_cols("
<< prop_int(w, "fixed-cols", 0) << ");\n";
if (w.props.count("fixed-rows") && prop_int(w, "fixed-rows", 0) != 0)
o << " " << var << ".w.set_frozen_rows("
<< prop_int(w, "fixed-rows", 0) << ");\n";
if (w.props.count("default-col-width"))
o << " " << var << ".w.set_default_col_width("
<< prop_int(w, "default-col-width", 84) << ");\n";
if (w.props.count("default-row-height"))
o << " " << var << ".w.set_row_height("
<< prop_int(w, "default-row-height", 20) << ");\n";
if (w.props.count("grid-line-width"))
o << " " << var << ".w.set_grid_line_width("
<< prop_int(w, "grid-line-width", 1) << ");\n";
} else if (t == "Toplevel") {
if (has("title"))
o << " " << var << ".w.set_title(\"" << esc_c(prop_or(w, "title", ""))
@@ -967,6 +1176,18 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
o << " " << var << ".w.set_resizable("
<< (prop_bool(w, "resizable", true) ? "true" : "false")
<< ");\n";
if (w.props.count("border-style"))
o << " " << var << ".w.set_border_style("
<< prop_int(w, "border-style", 0) << ");\n";
if (has("icon"))
o << " // NOTE: icon \"" << esc_c(prop_or(w, "icon", ""))
<< "\" is not loaded by the generated app.\n";
if (w.props.count("position"))
o << " " << var << ".w.set_position("
<< prop_int(w, "position", 0) << ");\n";
if (w.props.count("window-state"))
o << " " << var << ".w.set_window_state("
<< prop_int(w, "window-state", 0) << ");\n";
} else if (t == "Image") {
if (has("file"))
o << " " << var << ".w.set_filename(\""
@@ -974,6 +1195,22 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (w.props.count("pixel-size"))
o << " " << var << ".w.set_pixel_size("
<< prop_int(w, "pixel-size", -1) << ");\n";
if (w.props.count("stretch"))
o << " " << var << ".w.set_stretch("
<< (prop_bool(w, "stretch", false) ? "true" : "false")
<< ");\n";
if (w.props.count("proportional"))
o << " " << var << ".w.set_proportional("
<< (prop_bool(w, "proportional", true) ? "true" : "false")
<< ");\n";
if (w.props.count("center"))
o << " " << var << ".w.set_center("
<< (prop_bool(w, "center", true) ? "true" : "false")
<< ");\n";
if (w.props.count("transparent"))
o << " " << var << ".w.set_transparent("
<< (prop_bool(w, "transparent", false) ? "true" : "false")
<< ");\n";
} else if (t == "StockChart") {
// StockCandlestickChart draws its seeded preview series; the old
// GTK chart's CSV/indicator/drawing engine has no counterpart in
@@ -1005,10 +1242,18 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
<< " (0 = price, 1 = percent)\n";
}
} else if (t == "Shape") {
o << " // NOTE: Shape (\""
<< esc_c(prop_or(w, "shape", "0"))
<< "\", fill \"" << esc_c(prop_or(w, "fill-color", ""))
<< "\") has no XFrame counterpart; drawn as a plain area.\n";
if (w.props.count("shape"))
o << " " << var << ".w.set_shape("
<< prop_int(w, "shape", 0) << ");\n";
std::string sfill = prop_rgb_args(w, "fill-color");
if (!sfill.empty())
emit_color_call(o, var, "set_fill_color", true, sfill);
std::string spen = prop_rgb_args(w, "pen-color");
if (!spen.empty())
emit_color_call(o, var, "set_pen_color", true, spen);
if (w.props.count("pen-width"))
o << " " << var << ".w.set_pen_width("
<< prop_int(w, "pen-width", 2) << ");\n";
} else if (t == "Canvas") {
o << " // NOTE: Canvas has no XFrame counterpart; drawn as a "
"plain area.\n";
@@ -1071,6 +1316,16 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
if (has("glyph"))
notes.push_back("glyph=\"" +
esc_c(prop_or(w, "glyph", "")) + "\"");
if (t == "ListView" && w.props.count("headers-visible") &&
!prop_bool(w, "headers-visible", true))
notes.push_back("headers-visible=false (no ListView header API)");
if (t == "StringGrid" && w.props.count("headers-visible") &&
!prop_bool(w, "headers-visible", true))
notes.push_back("headers-visible=false (grid headers always shown)");
if (t == "ToggleButton" && prop_int(w, "group-index", 0) != 0)
notes.push_back("group-index=" +
std::to_string(prop_int(w, "group-index", 0)) +
" (no cross-widget group yet)");
if (has("focus-control"))
notes.push_back("focus-control=\"" +
esc_c(prop_or(w, "focus-control", "")) + "\"");
@@ -1565,8 +1820,24 @@ static std::string emit_main_cpp(const Project& project,
<< " if (!display) { std::fprintf(stderr, \"cannot open display\\n\"); return 1; }\n"
<< " int screen = DefaultScreen(display);\n"
<< " Window root = RootWindow(display, screen);\n";
o << " Window window = XCreateSimpleWindow(display, root, 100, 100, "
<< win_w << ", " << win_h << ", 1, BlackPixel(display, screen), ";
// Phase 3 (§2.20): window position / border style / state from
// the project. Defaults (0) emit the old fixed behaviour.
if (project.position != 0) {
o << " int win_x = (DisplayWidth(display, screen) - " << win_w
<< ") / 2;\n"
<< " int win_y = (DisplayHeight(display, screen) - " << win_h
<< ") / 2;\n";
}
if (project.window_state == 2) {
o << " int create_w = DisplayWidth(display, screen);\n"
<< " int create_h = DisplayHeight(display, screen);\n";
}
o << " Window window = XCreateSimpleWindow(display, root, "
<< (project.position != 0 ? "win_x, win_y" : "100, 100") << ", "
<< (project.window_state == 2 ? "create_w, create_h"
: std::to_string(win_w) + ", " +
std::to_string(win_h))
<< ", 1, BlackPixel(display, screen), ";
if (has_bg)
o << "alloc_rgb(display, screen, " << bg_r << ", " << bg_g << ", "
<< bg_b << ")";
@@ -1575,6 +1846,33 @@ static std::string emit_main_cpp(const Project& project,
o << ");\n"
<< " XStoreName(display, window, \"" << esc_c(project.title)
<< "\");\n"
<< (project.border_style == 1
? " // Border style None: undecorated window.\n"
" { XSetWindowAttributes attrs{}; attrs.override_redirect "
"= True; XChangeWindowAttributes(display, window, "
"CWOverrideRedirect, &attrs); }\n"
: "")
<< (project.border_style == 2 || project.border_style == 3
? " // NOTE: border style "
+ std::to_string(project.border_style) +
" (single/dialog) has no X11 equivalent here; the window "
"manager draws the frame.\n"
: "")
<< (project.window_state == 1 ? " XIconifyWindow(display, window, "
"screen);\n"
: "")
<< (project.window_state == 3
? " // Fullscreen: ask the window manager.\n"
" { Atom wm_state = XInternAtom(display, "
"\"_NET_WM_STATE\", False); Atom fs = XInternAtom(display, "
"\"_NET_WM_STATE_FULLSCREEN\", False); XEvent ev{}; "
"ev.type = ClientMessage; ev.xclient.window = window; "
"ev.xclient.message_type = wm_state; ev.xclient.format = "
"32; ev.xclient.data.l[0] = 1; ev.xclient.data.l[1] = "
"(long)fs; XSendEvent(display, root, False, "
"SubstructureRedirectMask | SubstructureNotifyMask, "
"&ev); }\n"
: "")
<< " XSelectInput(display, window, ExposureMask | KeyPressMask | "
"StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | "
"PointerMotionMask);\n"