Phase 2 GTK apply_prop fix + SELFTEST 7b + gen_matrix enum fix (C): legacy GTK apply_prop maps Entry password/show-password/alignment and Scale/TrackBar range, remaining Phase 2 props model-only (kills all 78 GLib warnings incl. 2 pre-existing password ones); SELFTEST Phase 7b places one widget of each Phase 2 type, live-applies props, checks stored values and generated setters/stubs; gen_matrix case 03 enum loop now takes the last value (values arrays are not 0-terminated) and case 04 covers every Phase 2 enum value
This commit is contained in:
1 parent
d3c93d8564
commit
751786618b
2 files changed
+334
-4
No files matched your search
+290
-1
@@ -933,7 +933,7 @@ static void apply_prop(Item* it, const PropDef& def, const std::string& value) {
|
||||
step * 10);
|
||||
return;
|
||||
}
|
||||
if (ty == "TrackBar" &&
|
||||
if ((ty == "TrackBar" || ty == "Scale") &&
|
||||
(std::strcmp(name, "minimum") == 0 ||
|
||||
std::strcmp(name, "maximum") == 0 ||
|
||||
std::strcmp(name, "step") == 0)) {
|
||||
@@ -979,6 +979,79 @@ static void apply_prop(Item* it, const PropDef& def, const std::string& value) {
|
||||
rebuild_stringgrid(it);
|
||||
return;
|
||||
}
|
||||
if (ty == "Entry" && std::strcmp(name, "password") == 0) {
|
||||
gtk_entry_set_visibility(GTK_ENTRY(it->target),
|
||||
value == "true" ? FALSE : TRUE);
|
||||
return;
|
||||
}
|
||||
if (ty == "Entry" && std::strcmp(name, "show-password") == 0) {
|
||||
gtk_entry_set_visibility(GTK_ENTRY(it->target),
|
||||
value == "true" ? TRUE : FALSE);
|
||||
return;
|
||||
}
|
||||
if (ty == "Entry" && std::strcmp(name, "alignment") == 0) {
|
||||
int v = std::atoi(value.c_str());
|
||||
g_object_set(G_OBJECT(it->target), "xalign",
|
||||
v == 0 ? 0.0 : (v == 1 ? 0.5 : 1.0), nullptr);
|
||||
return;
|
||||
}
|
||||
// Phase 2 (§2.1–§2.10): Lazarus props with no GTK equivalent —
|
||||
// stored in the model, emitted by the generator; never passed
|
||||
// to g_object_set (unknown names warn on every placement).
|
||||
if ((ty == "Button" &&
|
||||
(std::strcmp(name, "default") == 0 ||
|
||||
std::strcmp(name, "cancel") == 0 ||
|
||||
std::strcmp(name, "kind") == 0 ||
|
||||
std::strcmp(name, "modal-result") == 0 ||
|
||||
std::strcmp(name, "layout") == 0 ||
|
||||
std::strcmp(name, "glyph") == 0)) ||
|
||||
(ty == "Label" &&
|
||||
(std::strcmp(name, "transparent") == 0 ||
|
||||
std::strcmp(name, "show-accel-char") == 0 ||
|
||||
std::strcmp(name, "focus-control") == 0)) ||
|
||||
(ty == "Entry" &&
|
||||
(std::strcmp(name, "char-case") == 0 ||
|
||||
std::strcmp(name, "numbers-only") == 0 ||
|
||||
std::strcmp(name, "hide-selection") == 0 ||
|
||||
std::strcmp(name, "auto-select") == 0)) ||
|
||||
(ty == "Checkbutton" &&
|
||||
(std::strcmp(name, "allow-grayed") == 0 ||
|
||||
std::strcmp(name, "alignment") == 0 ||
|
||||
std::strcmp(name, "value-checked") == 0 ||
|
||||
std::strcmp(name, "value-unchecked") == 0)) ||
|
||||
(ty == "Radiobutton" && std::strcmp(name, "group") == 0) ||
|
||||
(ty == "Combobox" &&
|
||||
(std::strcmp(name, "style") == 0 ||
|
||||
std::strcmp(name, "drop-down-count") == 0 ||
|
||||
std::strcmp(name, "drop-down-width") == 0 ||
|
||||
std::strcmp(name, "sorted") == 0 ||
|
||||
std::strcmp(name, "read-only") == 0 ||
|
||||
std::strcmp(name, "max-length") == 0 ||
|
||||
std::strcmp(name, "auto-complete") == 0 ||
|
||||
std::strcmp(name, "char-case") == 0)) ||
|
||||
(ty == "Listbox" &&
|
||||
(std::strcmp(name, "item-index") == 0 ||
|
||||
std::strcmp(name, "sorted") == 0 ||
|
||||
std::strcmp(name, "columns") == 0 ||
|
||||
std::strcmp(name, "item-height") == 0 ||
|
||||
std::strcmp(name, "integral-height") == 0)) ||
|
||||
(ty == "Scrollbar" && std::strcmp(name, "large-change") == 0) ||
|
||||
((ty == "Scale" || ty == "TrackBar") &&
|
||||
(std::strcmp(name, "page-step") == 0 ||
|
||||
std::strcmp(name, "tick-marks") == 0 ||
|
||||
std::strcmp(name, "frequency") == 0 ||
|
||||
std::strcmp(name, "show-sel-range") == 0 ||
|
||||
std::strcmp(name, "sel-start") == 0 ||
|
||||
std::strcmp(name, "sel-end") == 0)) ||
|
||||
((ty == "Text" || ty == "Memo") &&
|
||||
(std::strcmp(name, "max-length") == 0 ||
|
||||
std::strcmp(name, "scroll-bars") == 0 ||
|
||||
std::strcmp(name, "want-tabs") == 0 ||
|
||||
std::strcmp(name, "want-returns") == 0 ||
|
||||
std::strcmp(name, "hide-selection") == 0 ||
|
||||
std::strcmp(name, "alignment") == 0))) {
|
||||
return; // model-only in the GTK designer
|
||||
}
|
||||
}
|
||||
GObject* o = G_OBJECT(it->target);
|
||||
switch (def.kind) {
|
||||
@@ -4326,6 +4399,7 @@ static gboolean selftest_step(gpointer) {
|
||||
int sysrc_scratch = std::system("rm -rf /tmp/lightgui_gen_test "
|
||||
"/tmp/lightgui_gen_test5 /tmp/lightgui_gen_test6 "
|
||||
"/tmp/lightgui_gen_test7 /tmp/lightgui_gen_test8 "
|
||||
"/tmp/lightgui_gen_test_p2 "
|
||||
"/tmp/lightgui_gen_test_gtk /tmp/lightgui_codeview");
|
||||
(void)sysrc_scratch;
|
||||
|
||||
@@ -4997,6 +5071,221 @@ static gboolean selftest_step(gpointer) {
|
||||
std::printf("GENERATED7 /tmp/lightgui_gen_test7\n");
|
||||
}
|
||||
|
||||
// Phase 7b: Proposal Phase 2 — per-widget custom props (§2.1–§2.10
|
||||
// + CheckListBox) on the XFrame canvas: place one widget of each
|
||||
// type, live-apply props through the Inspector path
|
||||
// (xframe_canvas_apply_prop), check the stored model, set Lazarus
|
||||
// events, and verify the generated code carries the setters + stubs.
|
||||
{
|
||||
auto place_p2 = [](const char* cls, int x, int y) {
|
||||
int idx = -1;
|
||||
for (int i = 0; i < kXFramePaletteCount; ++i)
|
||||
if (std::strcmp(kXFramePalette[i].name, cls) == 0) {
|
||||
idx = kXFramePalette[i].index;
|
||||
break;
|
||||
}
|
||||
if (idx < 0) return -1;
|
||||
return xframe_canvas_place(idx, x, y, 0, 0);
|
||||
};
|
||||
auto stored = [](int id, const char* name) {
|
||||
for (const XFramePlacedInfo& info : xframe_canvas_placed())
|
||||
if (info.id == id) {
|
||||
auto it = info.props.find(name);
|
||||
return it == info.props.end() ? std::string()
|
||||
: it->second;
|
||||
}
|
||||
return std::string("\x01missing");
|
||||
};
|
||||
int gx = 10, gy = 10;
|
||||
auto next_xy = [&]() {
|
||||
int x = gx, y = gy;
|
||||
gx += 190;
|
||||
if (gx > 600) { gx = 10; gy += 130; }
|
||||
return std::pair<int, int>(x, y);
|
||||
};
|
||||
// Button (§2.1): kind applies caption + modal result.
|
||||
int pbtn = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pbtn = place_p2("GtkButton", xy.first, xy.second);
|
||||
}
|
||||
check(pbtn > 0);
|
||||
check(xframe_canvas_apply_prop(pbtn, "kind", "1"));
|
||||
check(stored(pbtn, "label") == "OK");
|
||||
check(stored(pbtn, "modal-result") == "1");
|
||||
check(xframe_canvas_apply_prop(pbtn, "default", "true"));
|
||||
check(stored(pbtn, "default") == "true");
|
||||
// Entry (§2.2).
|
||||
int pent = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pent = place_p2("GtkEntry", xy.first, xy.second);
|
||||
}
|
||||
check(pent > 0);
|
||||
check(xframe_canvas_apply_prop(pent, "text", "hello"));
|
||||
check(stored(pent, "text") == "hello");
|
||||
check(xframe_canvas_apply_prop(pent, "alignment", "1"));
|
||||
check(stored(pent, "alignment") == "1");
|
||||
check(xframe_canvas_apply_prop(pent, "numbers-only", "true"));
|
||||
// Label (§2.3).
|
||||
int plbl = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
plbl = place_p2("GtkLabel", xy.first, xy.second);
|
||||
}
|
||||
check(plbl > 0);
|
||||
check(xframe_canvas_apply_prop(plbl, "yalign", "0.25"));
|
||||
check(stored(plbl, "yalign") == "0.25");
|
||||
check(xframe_canvas_apply_prop(plbl, "transparent", "true"));
|
||||
check(xframe_canvas_apply_prop(plbl, "show-accel-char", "false"));
|
||||
// CheckBox (§2.4).
|
||||
int pcb = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pcb = place_p2("GtkCheckButton", xy.first, xy.second);
|
||||
}
|
||||
check(pcb > 0);
|
||||
check(xframe_canvas_apply_prop(pcb, "allow-grayed", "true"));
|
||||
check(xframe_canvas_apply_prop(pcb, "active", "true"));
|
||||
check(xframe_canvas_apply_prop(pcb, "value-checked", "yes"));
|
||||
check(stored(pcb, "value-checked") == "yes");
|
||||
// RadioButton (§2.5): two buttons, same group id.
|
||||
int prb1 = -1, prb2 = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
prb1 = place_p2("GtkRadioButton", xy.first, xy.second);
|
||||
xy = next_xy();
|
||||
prb2 = place_p2("GtkRadioButton", xy.first, xy.second);
|
||||
}
|
||||
check(prb1 > 0 && prb2 > 0);
|
||||
check(xframe_canvas_apply_prop(prb1, "group", "3"));
|
||||
check(xframe_canvas_apply_prop(prb2, "group", "3"));
|
||||
check(stored(prb1, "group") == "3");
|
||||
check(xframe_canvas_apply_prop(prb1, "active", "true"));
|
||||
// ComboBox (§2.6).
|
||||
int pcombo = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pcombo = place_p2("GtkComboBoxText", xy.first, xy.second);
|
||||
}
|
||||
check(pcombo > 0);
|
||||
check(xframe_canvas_apply_prop(pcombo, "items", "C|A|B"));
|
||||
check(xframe_canvas_apply_prop(pcombo, "sorted", "true"));
|
||||
check(xframe_canvas_apply_prop(pcombo, "active", "1"));
|
||||
check(stored(pcombo, "text") == "B");
|
||||
check(xframe_canvas_apply_prop(pcombo, "drop-down-count", "5"));
|
||||
// ListBox (§2.7).
|
||||
int plist = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
plist = place_p2("GtkListBox", xy.first, xy.second);
|
||||
}
|
||||
check(plist > 0);
|
||||
check(xframe_canvas_apply_prop(plist, "items", "One|Two|Three"));
|
||||
check(xframe_canvas_apply_prop(plist, "item-index", "2"));
|
||||
check(xframe_canvas_apply_prop(plist, "item-height", "30"));
|
||||
// ScrollBar (§2.8).
|
||||
int pscroll = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pscroll = place_p2("GtkScrollbar", xy.first, xy.second);
|
||||
}
|
||||
check(pscroll > 0);
|
||||
check(xframe_canvas_apply_prop(pscroll, "lower", "10"));
|
||||
check(xframe_canvas_apply_prop(pscroll, "upper", "90"));
|
||||
check(xframe_canvas_apply_prop(pscroll, "value", "50"));
|
||||
check(xframe_canvas_apply_prop(pscroll, "orientation", "1"));
|
||||
check(xframe_canvas_apply_prop(pscroll, "large-change", "20"));
|
||||
// Scale / TrackBar (§2.9).
|
||||
int pscale = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pscale = place_p2("GtkScale", xy.first, xy.second);
|
||||
}
|
||||
check(pscale > 0);
|
||||
check(xframe_canvas_apply_prop(pscale, "minimum", "10"));
|
||||
check(xframe_canvas_apply_prop(pscale, "maximum", "90"));
|
||||
check(xframe_canvas_apply_prop(pscale, "value", "42"));
|
||||
check(xframe_canvas_apply_prop(pscale, "tick-marks", "3"));
|
||||
check(xframe_canvas_apply_prop(pscale, "frequency", "20"));
|
||||
check(xframe_canvas_apply_prop(pscale, "page-step", "5"));
|
||||
check(stored(pscale, "page-step") == "5");
|
||||
// Text (§2.10).
|
||||
int ptext = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
ptext = place_p2("GtkTextView", xy.first, xy.second);
|
||||
}
|
||||
check(ptext > 0);
|
||||
check(xframe_canvas_apply_prop(ptext, "text", "Hello"));
|
||||
check(stored(ptext, "text") == "Hello");
|
||||
check(xframe_canvas_apply_prop(ptext, "max-length", "10"));
|
||||
check(xframe_canvas_apply_prop(ptext, "want-tabs", "false"));
|
||||
// Memo (§2.10).
|
||||
int pmemo = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pmemo = place_p2("TMemo", xy.first, xy.second);
|
||||
}
|
||||
check(pmemo > 0);
|
||||
check(xframe_canvas_apply_prop(pmemo, "text", "Memo text"));
|
||||
check(stored(pmemo, "text") == "Memo text");
|
||||
check(xframe_canvas_apply_prop(pmemo, "cursor-visible", "false"));
|
||||
check(xframe_canvas_apply_prop(pmemo, "scroll-bars", "1"));
|
||||
// CheckListBox (Flag 8): per-item checked state.
|
||||
int pclb = -1;
|
||||
{
|
||||
auto xy = next_xy();
|
||||
pclb = place_p2("TCheckListBox", xy.first, xy.second);
|
||||
}
|
||||
check(pclb > 0);
|
||||
check(xframe_canvas_apply_prop(pclb, "items", "Red|Green|Blue"));
|
||||
check(xframe_canvas_apply_prop(pclb, "checked-items", "0,2"));
|
||||
check(stored(pclb, "checked-items") == "0,2");
|
||||
check(xframe_canvas_apply_prop(pclb, "item-index", "1"));
|
||||
// Events (Flag 10): Lazarus names, stub + connection in output.
|
||||
check(xframe_canvas_set_signal(pbtn, "clicked", true));
|
||||
check(xframe_canvas_set_signal(pbtn, "button-press", true));
|
||||
Project snap2 = snapshot_project();
|
||||
std::string btn_name;
|
||||
for (const Widget& w : snap2.widgets)
|
||||
if (w.type == "GtkButton" && w.props.count("kind"))
|
||||
btn_name = w.name;
|
||||
check(!btn_name.empty());
|
||||
GenResult gr2 = generate_project(snap2, snap2.widgets,
|
||||
"/tmp/lightgui_gen_test_p2");
|
||||
check(gr2.ok && gr2.files.size() == 4);
|
||||
auto read_file_p2 = [](const std::string& path) {
|
||||
gchar* t = nullptr;
|
||||
if (!g_file_get_contents(path.c_str(), &t, nullptr, nullptr) ||
|
||||
!t)
|
||||
return std::string();
|
||||
std::string s2 = t;
|
||||
g_free(t);
|
||||
return s2;
|
||||
};
|
||||
std::string code2 = read_file_p2("/tmp/lightgui_gen_test_p2/main.cpp");
|
||||
check(!code2.empty());
|
||||
check(code2.find("set_kind(1)") != std::string::npos);
|
||||
check(code2.find("set_checked_items(\"0,2\")") !=
|
||||
std::string::npos);
|
||||
check(code2.find("radio_group_3") != std::string::npos);
|
||||
check(code2.find("set_orientation_vertical(true)") !=
|
||||
std::string::npos);
|
||||
check(code2.find("set_marks({10.0, 30.0, 50.0, 70.0, 90.0})") !=
|
||||
std::string::npos);
|
||||
check(code2.find("set_value_checked(\"yes\")") !=
|
||||
std::string::npos);
|
||||
check(code2.find("add_item(\"Red\")") != std::string::npos);
|
||||
check(code2.find("set_drop_down_count(5)") != std::string::npos);
|
||||
check(code2.find("on_" + btn_name + "_clicked") !=
|
||||
std::string::npos);
|
||||
check(code2.find(btn_name + ".w.on_click") != std::string::npos);
|
||||
check(code2.find(btn_name + ".on_mouse_down") != std::string::npos);
|
||||
std::printf("GENERATED_P2 /tmp/lightgui_gen_test_p2\n");
|
||||
}
|
||||
|
||||
|
||||
// Phase 8: event handlers — connect every natural signal on every
|
||||
// widget on the canvas, generate, and check the emitted code carries
|
||||
// a stub handler + a std::function wiring line for each; types with no natural
|
||||
|
||||
+44
-3
@@ -96,10 +96,17 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
}
|
||||
case PropKind::Enum: {
|
||||
// Last value: the values array is NOT
|
||||
// 0-terminated (every table starts at 0), so
|
||||
// count the labels in enum_labels and take
|
||||
// values[count - 1].
|
||||
int last = 0;
|
||||
for (int k = 0; d->enum_values && d->enum_values[k];
|
||||
++k)
|
||||
last = d->enum_values[k];
|
||||
if (d->enum_values && d->enum_labels) {
|
||||
int n = 1;
|
||||
for (const char* q = d->enum_labels; *q; ++q)
|
||||
if (*q == '|') ++n;
|
||||
last = d->enum_values[n - 1];
|
||||
}
|
||||
w.props[d->name] = std::to_string(last);
|
||||
break;
|
||||
}
|
||||
@@ -144,6 +151,40 @@ int main(int argc, char** argv) {
|
||||
for (int v = 0; v <= 3; ++v)
|
||||
add("Text", "Txt_wrap_" + std::to_string(v), "wrap-mode",
|
||||
std::to_string(v));
|
||||
// Phase 2 enums: every value of every new enum prop.
|
||||
for (int v = 0; v <= 9; ++v)
|
||||
add("Button", "Btn_kind_" + std::to_string(v), "kind",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 3; ++v)
|
||||
add("Button", "Btn_layout_" + std::to_string(v), "layout",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 2; ++v)
|
||||
add("Entry", "Ent_align_" + std::to_string(v), "alignment",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 2; ++v)
|
||||
add("Entry", "Ent_case_" + std::to_string(v), "char-case",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 1; ++v)
|
||||
add("Checkbutton", "Chk_align_" + std::to_string(v),
|
||||
"alignment", std::to_string(v));
|
||||
for (int v = 0; v <= 2; ++v)
|
||||
add("Combobox", "Cmb_style_" + std::to_string(v), "style",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 3; ++v)
|
||||
add("Scale", "Scl_ticks_" + std::to_string(v), "tick-marks",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 1; ++v)
|
||||
add("Scrollbar", "Scr_orient_" + std::to_string(v),
|
||||
"orientation", std::to_string(v));
|
||||
for (int v = 0; v <= 3; ++v)
|
||||
add("Text", "Txt_scroll_" + std::to_string(v), "scroll-bars",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 3; ++v)
|
||||
add("Memo", "Mem_scroll_" + std::to_string(v), "scroll-bars",
|
||||
std::to_string(v));
|
||||
for (int v = 0; v <= 3; ++v)
|
||||
add("TrackBar", "Trk_ticks_" + std::to_string(v), "tick-marks",
|
||||
std::to_string(v));
|
||||
emit("04_enum_values", p);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user