Generated event loop now tracks pressed_widget (set on a handled ButtonPress) and focused_widget (click-to-focus). ButtonRelease goes to the pressed widget even if the pointer moved off it; MotionNotify goes to the pressed widget while a press is held (drag), otherwise to the topmost widget under the pointer; KeyPress goes to the focused widget only. ButtonPress hit-testing, Expose, ConfigureNotify and ClientMessage unchanged. Verified live under Xvfb with a generated 4-widget app (2 buttons + 2 entries) and an instrumented event log: keys go only to the focused entry, hover only to the widget under the pointer, drag motion and release only to the pressed button. The designer canvas does NOT share this loop (it already targets release/motion/keys by selection/hit-test), so it is unchanged.
2517 lines
144 KiB
C++
2517 lines
144 KiB
C++
// LightGUI code generator — see generator.h.
|
|
//
|
|
// Step 4 of the unified XFrame-native canvas (Nov 29, 2026): the output
|
|
// is a self-contained C++ program that uses the XFrame library — NOT
|
|
// GTK. One file, main.cpp, opens the display, creates the top-level
|
|
// window, sets up the SStyle_Manager, constructs one lg::Holder<T> per
|
|
// placed widget (T is the XFrame class for the designer's palette type),
|
|
// applies the widget's properties through the getter/setter API, wires
|
|
// connected signals to stub handlers via the widgets' std::function
|
|
// callbacks, and runs an X event loop dispatching through lg::IWidget.
|
|
// A CMakeLists.txt + Makefile build it against the XFrame widget sources
|
|
// (LIGHTGUI_WIDGETS_DIR, default /usr/local/include/lightgui); a README.md
|
|
// documents the build.
|
|
//
|
|
// Why one file: the widget classes are header-only in widgets/, and the
|
|
// registry (widgets/common/registry.h) already includes all 547 of them,
|
|
// so main.cpp just includes the registry and uses lg::Holder<T> for
|
|
// uniform construction + IWidget dispatch. The generator itself must NOT
|
|
// include the registry: it is compiled into the GTK designer binary and
|
|
// the XFrame class names (GtkButton, GtkLabel, ...) collide with GTK's
|
|
// own typedefs in any TU that includes <gtk/gtk.h>.
|
|
// The generated code gets its widget list from the canvas: the designer
|
|
// snapshots placed widgets into the same Project/Widget model the old
|
|
// GTK generator took, so the generator interface is unchanged.
|
|
|
|
#include "generator.h"
|
|
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <vector>
|
|
|
|
#include "events.h"
|
|
#include "props.h" // Phase 4: find_prop() for the generic loop
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
// ---------------------------------------------------------------- helpers
|
|
|
|
// Escape a string for a C++ string literal.
|
|
static std::string esc_c(const std::string& s) {
|
|
std::string out;
|
|
for (unsigned char c : s) {
|
|
switch (c) {
|
|
case '"': out += "\\\""; break;
|
|
case '\\': out += "\\\\"; break;
|
|
case '\n': out += "\\n"; break;
|
|
case '\r': out += "\\r"; break;
|
|
case '\t': out += "\\t"; break;
|
|
default:
|
|
if (c < 0x20) {
|
|
char buf[8];
|
|
std::snprintf(buf, sizeof buf, "\\%03o", c);
|
|
out += buf;
|
|
} else {
|
|
out += (char)c;
|
|
}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
static std::string trim(const std::string& s) {
|
|
size_t a = s.find_first_not_of(" \t\r\n");
|
|
if (a == std::string::npos) return "";
|
|
size_t b = s.find_last_not_of(" \t\r\n");
|
|
return s.substr(a, b - a + 1);
|
|
}
|
|
|
|
// Split on one separator, trimming each part, dropping empties.
|
|
static std::vector<std::string> split_on(char sep, const std::string& spec) {
|
|
std::vector<std::string> out;
|
|
size_t start = 0;
|
|
for (size_t i = 0; i <= spec.size(); ++i) {
|
|
if (i == spec.size() || spec[i] == sep) {
|
|
std::string one = trim(spec.substr(start, i - start));
|
|
if (!one.empty()) out.push_back(one);
|
|
start = i + 1;
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// Format a stored double for a C++ literal ("0" would pass an int, so
|
|
// make sure a '.' or exponent is present).
|
|
static std::string fmt_double(const std::string& v) {
|
|
char buf[64];
|
|
std::snprintf(buf, sizeof buf, "%g", std::atof(v.c_str()));
|
|
std::string s = buf;
|
|
if (s.find_first_of(".eEnN") == std::string::npos) s += ".0";
|
|
return s;
|
|
}
|
|
|
|
static std::string prop_or(const Widget& w, const std::string& name,
|
|
const std::string& dflt) {
|
|
auto it = w.props.find(name);
|
|
return it == w.props.end() ? dflt : it->second;
|
|
}
|
|
|
|
static bool prop_bool(const Widget& w, const std::string& name, bool dflt) {
|
|
auto it = w.props.find(name);
|
|
if (it == w.props.end()) return dflt;
|
|
return it->second == "true" || it->second == "1";
|
|
}
|
|
|
|
static int prop_int(const Widget& w, const std::string& name, int dflt) {
|
|
auto it = w.props.find(name);
|
|
if (it == w.props.end()) return dflt;
|
|
try {
|
|
return std::stoi(it->second);
|
|
} catch (...) {
|
|
return dflt;
|
|
}
|
|
}
|
|
|
|
// Parse a designer colour: "#rrggbb", "#rgb", "rgb(r,g,b)", or a basic
|
|
// colour name. The designer canonicalises Color props to rgb(...), but
|
|
// loaded .fdj files may carry the other forms.
|
|
static bool parse_color(const std::string& v, int& r, int& g, int& b) {
|
|
std::string s = trim(v);
|
|
if (s.empty()) return false;
|
|
static const std::map<std::string, std::tuple<int, int, int>> kNamed = {
|
|
{"black", {0, 0, 0}}, {"white", {255, 255, 255}},
|
|
{"red", {255, 0, 0}}, {"green", {0, 128, 0}},
|
|
{"blue", {0, 0, 255}}, {"yellow", {255, 255, 0}},
|
|
{"cyan", {0, 255, 255}}, {"magenta", {255, 0, 255}},
|
|
{"gray", {128, 128, 128}}, {"grey", {128, 128, 128}},
|
|
{"orange", {255, 165, 0}}, {"purple", {128, 0, 128}},
|
|
};
|
|
std::string low = s;
|
|
for (char& c : low) c = (char)std::tolower((unsigned char)c);
|
|
auto ni = kNamed.find(low);
|
|
if (ni != kNamed.end()) {
|
|
std::tie(r, g, b) = ni->second;
|
|
return true;
|
|
}
|
|
if (s[0] == '#') {
|
|
std::string h = s.substr(1);
|
|
if (h.size() == 3) h = {h[0], h[0], h[1], h[1], h[2], h[2]};
|
|
if (h.size() != 6) return false;
|
|
try {
|
|
r = std::stoi(h.substr(0, 2), nullptr, 16);
|
|
g = std::stoi(h.substr(2, 2), nullptr, 16);
|
|
b = std::stoi(h.substr(4, 2), nullptr, 16);
|
|
} catch (...) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
if (low.rfind("rgb(", 0) == 0 && s.back() == ')') {
|
|
std::string inner = s.substr(4, s.size() - 5);
|
|
std::vector<std::string> parts = split_on(',', inner);
|
|
if (parts.size() < 3) return false;
|
|
try {
|
|
r = std::stoi(parts[0]);
|
|
g = std::stoi(parts[1]);
|
|
b = std::stoi(parts[2]);
|
|
} catch (...) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// "r, g, b" for a *_rgb(...) call, or "" when the prop is absent/unparsable.
|
|
static std::string prop_rgb_args(const Widget& w, const std::string& name) {
|
|
auto it = w.props.find(name);
|
|
if (it == w.props.end()) return "";
|
|
int r = 0, g = 0, b = 0;
|
|
if (!parse_color(it->second, r, g, b)) return "";
|
|
return std::to_string(r) + ", " + std::to_string(g) + ", " +
|
|
std::to_string(b);
|
|
}
|
|
|
|
static std::string sanitize_class(const std::string& raw) {
|
|
std::string out;
|
|
for (char c : raw)
|
|
if (std::isalnum((unsigned char)c) || c == '_') out += c;
|
|
if (out.empty()) out = "MyWindow";
|
|
if (std::isdigit((unsigned char)out[0])) out = "W" + out;
|
|
return out;
|
|
}
|
|
|
|
// Widget name -> C++ identifier (names are already Button_001-style, but
|
|
// loaded projects could carry anything).
|
|
static std::string sanitize_ident(const std::string& raw) {
|
|
std::string out;
|
|
for (char c : raw)
|
|
if (std::isalnum((unsigned char)c) || c == '_') out += c;
|
|
if (out.empty()) out = "widget";
|
|
if (std::isdigit((unsigned char)out[0])) out = "w_" + out;
|
|
return out;
|
|
}
|
|
|
|
// Identifier fragment from a label ("Save As" -> "save_as").
|
|
static std::string id_part(const std::string& label) {
|
|
std::string out;
|
|
for (unsigned char c : label) {
|
|
if (std::isalnum(c))
|
|
out += (char)std::tolower(c);
|
|
else if (!out.empty() && out.back() != '_')
|
|
out += '_';
|
|
}
|
|
while (!out.empty() && out.back() == '_') out.pop_back();
|
|
return out.empty() ? "item" : out;
|
|
}
|
|
|
|
// Signal name -> identifier fragment ("value-changed" -> "value_changed").
|
|
static std::string sig_part(const std::string& signal) {
|
|
std::string out = signal;
|
|
for (char& c : out)
|
|
if (!std::isalnum((unsigned char)c)) c = '_';
|
|
return out;
|
|
}
|
|
|
|
// ---------------------------------------------------------------- menus
|
|
|
|
struct MenuDef {
|
|
std::string label;
|
|
std::vector<std::string> items;
|
|
};
|
|
|
|
// Parse the designer's menu spec: one "Label: Item | Item | -" per line.
|
|
static std::vector<MenuDef> parse_menus(const std::string& spec) {
|
|
std::vector<MenuDef> out;
|
|
std::istringstream in(spec);
|
|
std::string line;
|
|
while (std::getline(in, line)) {
|
|
size_t colon = line.find(':');
|
|
if (colon == std::string::npos) continue;
|
|
MenuDef m;
|
|
m.label = trim(line.substr(0, colon));
|
|
if (m.label.empty()) continue;
|
|
std::istringstream items(line.substr(colon + 1));
|
|
std::string item;
|
|
while (std::getline(items, item, '|')) {
|
|
item = trim(item);
|
|
if (!item.empty()) m.items.push_back(item);
|
|
}
|
|
out.push_back(m);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// ------------------------------------------------------- type -> XFrame class
|
|
//
|
|
// One row per designer palette type. `fill` names the setter the
|
|
// generated code uses for the common background prop, or "" when the
|
|
// class has no such setter (then a per-widget style clone carries the
|
|
// colour instead — see emit_widget_styles). `srgb` marks setters taking
|
|
// Srgb{r, g, b} rather than (r, g, b) ints. The setter names below were
|
|
// verified against widgets/components/<Cls>/<Cls>.h (getter/setter pass,
|
|
// Nov 29 2026); only setters that exist on that class are named, so the
|
|
// generated code always compiles.
|
|
//
|
|
// Foreground (`text`) is ALWAYS "" — it rides the per-widget style.
|
|
// The widgets' set_text_color_rgb only affects the DISABLED text (every
|
|
// draw() gates it on !enabled_; MenuBar/TreeView/ListView use it for
|
|
// selected/hot rows), while the enabled text colour comes from the
|
|
// style — verified by rendering Nov 30 2026 (a label with
|
|
// set_text_color_rgb(0,0,255) still drew black text). The one exception
|
|
// in the other direction: ComboBox fill is "" too, because
|
|
// set_fill_color_rgb colours only the dropdown list, not the main field.
|
|
|
|
struct XFrameMap {
|
|
const char* key; // designer palette type key (model.h kTypes)
|
|
const char* cls; // XFrame class (widgets/common/registry.h)
|
|
const char* fill; // background setter, "" = none (use a style)
|
|
const char* text; // foreground setter, "" = none (use a style)
|
|
bool fill_srgb; // fill setter takes Srgb, not (r, g, b)
|
|
bool text_srgb;
|
|
};
|
|
|
|
static const XFrameMap kXFrameMap[] = {
|
|
{"Button", "GtkButton", "", "", false, false},
|
|
{"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},
|
|
{"Listbox", "GtkListBox", "set_frame_background_color_rgb", "", false, false},
|
|
{"CheckListBox", "TCheckListBox", "", "", false, false},
|
|
{"Menubutton", "GtkMenuButton", "", "", false, false},
|
|
{"Canvas", "GtkDrawingArea", "", "", false, false},
|
|
{"Scale", "GtkScale", "", "", false, false},
|
|
{"Scrollbar", "GtkScrollbar", "", "", false, false},
|
|
{"Text", "GtkTextView", "set_fill_color_rgb", "", false, false},
|
|
{"Toplevel", "GtkWindow", "", "", false, false},
|
|
{"Spreadsheet", "XSpreadsheet", "set_white_color_rgb", "", false, false},
|
|
{"StockChart", "StockCandlestickChart", "set_bg_color", "", true, false},
|
|
{"Memo", "TMemo", "set_fill_color_rgb", "", false, false},
|
|
{"GroupBox", "GtkFrame", "", "", false, false},
|
|
{"Panel", "GtkFrame", "", "", false, false},
|
|
{"Image", "GtkImage", "", "", false, false},
|
|
{"Shape", "TShape", "", "", false, false},
|
|
{"Notebook", "GtkNotebook", "", "", false, false},
|
|
{"ScrollBox", "GtkScrolledWindow", "set_viewport_background_color_rgb", "", false, false},
|
|
{"Splitter", "GtkPaned", "", "", false, false},
|
|
{"StatusBar", "GtkStatusbar", "", "", false, false},
|
|
{"ToolBar", "GtkToolbar", "", "", false, false},
|
|
{"MenuBar", "GtkMenuBar", "", "", false, false},
|
|
{"SpinEdit", "GtkSpinButton", "set_fill_color_rgb", "", false, false},
|
|
{"TrackBar", "GtkScale", "", "", false, false},
|
|
{"ProgressBar", "GtkProgressBar", "", "", false, false},
|
|
{"DateTimePicker", "GtkCalendar", "", "", false, false},
|
|
{"ColorBox", "GtkColorButton", "", "", false, false},
|
|
{"ListView", "GtkListView", "", "", false, false},
|
|
{"TreeView", "GtkTreeView", "", "", false, false},
|
|
{"StringGrid", "XSpreadsheet", "set_white_color_rgb", "", false, false},
|
|
{"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 || key == m.cls) return &m;
|
|
return nullptr;
|
|
}
|
|
|
|
// A plausible XFrame class name straight from an XFrame-only .fdj
|
|
// (step 5): Capitalised identifier, e.g. GtkButton, StockLineChart,
|
|
// TMemo, XGraph. Anything else is not a widget class.
|
|
// Namespace-qualify a widget class name for use as a C++ type. Most
|
|
// classes are in the global namespace, but 165 of the 547 (all indicator
|
|
// classes whose names start with Ind, e.g. IndADX) live in namespace
|
|
// xframe:: — the exact set below is taken from the registry's own
|
|
// create_widget() (widgets/common/registry.h, Nov 30 2026), which is
|
|
// the same spelling the generated main.cpp's Holder<T> must use. The
|
|
// Ind* prefix alone does NOT decide it: 85 Ind* classes (IndAPO,
|
|
// IndAcceleratorOscillator, ...) are global. Without the qualifier the
|
|
// generated code fails with "IndADX was not declared in this scope".
|
|
static const char* kXFrameNsClasses[] = {
|
|
"IndADX", "IndADXR", "IndALMA", "IndATR", "IndAccumulationDistributionLine", "IndAccumulativeSwingIndex",
|
|
"IndAlligatorJaw", "IndAlligatorLips", "IndAlligatorTeeth", "IndAnchoredVWAP", "IndAroonDown", "IndAroonOscillator",
|
|
"IndAroonUp", "IndAutocorrelation", "IndBollingerBands", "IndBollingerBandwidth", "IndBollingerPercentB", "IndCamarillaPivotPoints",
|
|
"IndChaikinMoneyFlow", "IndChaikinOscillator", "IndChaikinVolatility", "IndChandeKrollStop", "IndChandelierExit", "IndChandelierExitLong",
|
|
"IndChandelierExitShort", "IndChikouSpan", "IndCloseVolatility", "IndCorrelation", "IndCovariance", "IndCumulativeVolumeDelta",
|
|
"IndDEMA", "IndDPO", "IndDX", "IndDemandIndex", "IndDominantCyclePeriod", "IndDonchianChannels",
|
|
"IndDonchianLower", "IndDonchianMiddle", "IndDonchianUpper", "IndEMA", "IndEaseOfMovement", "IndEfficiencyRatio",
|
|
"IndEhlersDecycler", "IndEhlersSuperSmoother", "IndEhlersTrendline", "IndElderRayBear", "IndElderRayBull", "IndElderSafeZone",
|
|
"IndFAMA", "IndFRAMA", "IndFibonacciPivotPoints", "IndFractalDimension", "IndFractalDimensionIndex", "IndFractalDown",
|
|
"IndFractalUp", "IndGarmanKlassVolatility", "IndGatorOscillator", "IndGaussianMA", "IndGopalakrishnanRangeIndex", "IndGuppyMMA",
|
|
"IndHMA", "IndHalfTrend", "IndHighLowRange", "IndHistoricalVolatility", "IndHurstExponent", "IndIntradayIntensityIndex",
|
|
"IndKAMA", "IndKeltnerBandwidth", "IndKeltnerChannels", "IndKijunSen", "IndKlingerVolumeOscillator", "IndKurtosis",
|
|
"IndLSMA", "IndLinReg", "IndLinRegAngle", "IndLinRegIntercept", "IndLinRegSlope", "IndLinearRegressionForecast",
|
|
"IndLinearRegressionIntercept", "IndLinearRegressionSlope", "IndMAEnvelopeLower", "IndMAEnvelopeUpper", "IndMAMA", "IndMassIndex",
|
|
"IndMcGinley", "IndMedianMA", "IndMedianPrice", "IndMinusDI", "IndMoneyFlowIndex", "IndMoneyFlowVolume",
|
|
"IndMovingAverageRibbon", "IndNATR", "IndNegativeVolumeIndex", "IndOBV", "IndPSAR", "IndParkinsonVolatility",
|
|
"IndPercentageVolumeOscillator", "IndPercentileRank", "IndPivotPoint", "IndPlusDI", "IndPositiveVolumeIndex", "IndQStick",
|
|
"IndRMA", "IndRSquared", "IndRWIHigh", "IndRWILow", "IndRegressionChannel", "IndRelativeVolatilityIndex",
|
|
"IndRelativeVolume", "IndRogersSatchellVolatility", "IndSMA", "IndSMMA", "IndSSLChannel", "IndSenkouSpanA",
|
|
"IndSenkouSpanB", "IndShannonEntropy", "IndSineWMA", "IndSkewness", "IndStandardError", "IndStandardPivotPoints",
|
|
"IndStdDev", "IndSupertrend", "IndSwingIndex", "IndT3", "IndTEMA", "IndTRIMA",
|
|
"IndTRIX", "IndTSF", "IndTSMA", "IndTTMSqueeze", "IndTenkanSen", "IndTrendIntensityIndex",
|
|
"IndTrueRange", "IndTwiggsMoneyFlow", "IndTypicalPrice", "IndUTBot", "IndUlcerIndex", "IndUpDownRatio",
|
|
"IndUpDownVolumeRatio", "IndVHF", "IndVIDYA", "IndVWAP", "IndVWAPBands", "IndVWEMA",
|
|
"IndVWMA", "IndVariance", "IndVolatilityRatio", "IndVolatilityStop", "IndVolumeAverage", "IndVolumeDelta",
|
|
"IndVolumeOscillator", "IndVolumePriceTrend", "IndVolumeRateOfChange", "IndVolumeWeightedMovingAverage", "IndVolumeZoneOscillator", "IndVortex",
|
|
"IndWMA", "IndWeightedClose", "IndWilderVolatilitySystem", "IndWildersMA", "IndWoodiePivotPoints", "IndYangZhangVolatility",
|
|
"IndZLEMA", "IndZScore", "IndZigZag",
|
|
};
|
|
static std::string qualified_class(const std::string& cls) {
|
|
if (std::binary_search(std::begin(kXFrameNsClasses),
|
|
std::end(kXFrameNsClasses), cls))
|
|
return "xframe::" + cls;
|
|
return cls;
|
|
}
|
|
|
|
static bool looks_like_class(const std::string& key) {
|
|
if (key.empty() || !std::isupper((unsigned char)key[0])) return false;
|
|
for (char c : key)
|
|
if (!std::isalnum((unsigned char)c) && c != '_') return false;
|
|
return true;
|
|
}
|
|
|
|
// ------------------------------------------------------- per-widget styles
|
|
//
|
|
// Colours the widget class cannot take directly (no fill/text setter)
|
|
// and the Inspector border props ride on a per-widget style cloned from
|
|
// the default: add_style_ex(<var>_style, fill, outline, line, text,
|
|
// radius, linewidth, font) + set_style_name. This is the same mechanism
|
|
// the canvas uses for borders (SStyle_Manager::add_border_style).
|
|
|
|
// Forward declarations: defined with the other Phase 1 helpers
|
|
// before emit_main_cpp; used here by style_for().
|
|
static bool widget_font_custom(const Widget& w);
|
|
static std::string widget_font_expr(const Widget& w);
|
|
|
|
struct StyleSpec {
|
|
bool needed = false;
|
|
int fill_r = 225, fill_g = 225, fill_b = 225;
|
|
int line_r = 60, line_g = 60, line_b = 60;
|
|
int text_r = 20, text_g = 20, text_b = 20;
|
|
int radius = 6;
|
|
int linewidth = 1;
|
|
// Font argument for add_style_ex: the default XLFD literal, or a
|
|
// lightgui_pick_font(...) call when the widget has a custom font.
|
|
std::string font_expr = "\"-misc-fixed-medium-r-normal--13-*\"";
|
|
};
|
|
|
|
static StyleSpec style_for(const Widget& w, const XFrameMap& m) {
|
|
StyleSpec s;
|
|
int r = 0, g = 0, b = 0;
|
|
bool has_bg = w.props.count("background") &&
|
|
parse_color(prop_or(w, "background", ""), r, g, b);
|
|
bool has_fg = w.props.count("foreground") &&
|
|
parse_color(prop_or(w, "foreground", ""), r, g, b);
|
|
int bw = prop_int(w, "border-width", 0);
|
|
int br = prop_int(w, "border-radius", 0);
|
|
bool has_bc = w.props.count("border-color") &&
|
|
parse_color(prop_or(w, "border-color", ""), r, g, b);
|
|
bool font_custom = widget_font_custom(w);
|
|
s.needed = (has_bg && !m.fill[0]) || (has_fg && !m.text[0]) ||
|
|
bw > 0 || br > 0 || has_bc || font_custom;
|
|
if (!s.needed) return s;
|
|
s.font_expr = widget_font_expr(w);
|
|
if (has_bg && !m.fill[0]) {
|
|
parse_color(prop_or(w, "background", ""), s.fill_r, s.fill_g, s.fill_b);
|
|
}
|
|
if (has_fg && !m.text[0]) {
|
|
parse_color(prop_or(w, "foreground", ""), s.text_r, s.text_g, s.text_b);
|
|
}
|
|
if (has_bc) {
|
|
parse_color(prop_or(w, "border-color", ""), s.line_r, s.line_g, s.line_b);
|
|
}
|
|
if (br > 0) s.radius = br;
|
|
if (bw > 0) s.linewidth = bw;
|
|
return s;
|
|
}
|
|
|
|
static void emit_widget_styles(std::ostringstream& o,
|
|
const std::vector<Widget>& widgets) {
|
|
for (const Widget& w : widgets) {
|
|
const XFrameMap* m = find_map(w.type);
|
|
XFrameMap direct;
|
|
if (!m && looks_like_class(w.type)) {
|
|
direct = XFrameMap{w.type.c_str(), w.type.c_str(),
|
|
"", "", false, false};
|
|
m = &direct;
|
|
}
|
|
if (!m) continue;
|
|
StyleSpec s = style_for(w, *m);
|
|
if (!s.needed) continue;
|
|
std::string var = sanitize_ident(w.name);
|
|
o << " styles.add_style_ex(\"" << var << "_style\", Srgb{"
|
|
<< s.fill_r << ", " << s.fill_g << ", " << s.fill_b
|
|
<< "}, Srgb{120, 120, 120}, Srgb{" << s.line_r << ", " << s.line_g
|
|
<< ", " << s.line_b << "}, Srgb{" << s.text_r << ", " << s.text_g
|
|
<< ", " << s.text_b << "}, " << s.radius << ", " << s.linewidth
|
|
<< ", " << s.font_expr << ");\n";
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------- widget properties
|
|
//
|
|
// One setter call per designer prop, but ONLY where the mapped XFrame
|
|
// class has that setter (verified against the widget headers). A prop
|
|
// with no setter on the class is left out — the generated code must
|
|
// compile for every design, and a wrong guess would not. Unmapped
|
|
// design data is noted in a comment where the loss is visible
|
|
// (Shape/Canvas/Plot/StockChart), and in the generated README.
|
|
|
|
static void emit_color_call(std::ostringstream& o, const std::string& var,
|
|
const std::string& setter, bool srgb,
|
|
const std::string& rgb_args) {
|
|
if (srgb) {
|
|
o << " " << var << ".w." << setter << "(Srgb{" << rgb_args
|
|
<< "});\n";
|
|
} else {
|
|
o << " " << var << ".w." << setter << "(" << rgb_args << ");\n";
|
|
}
|
|
}
|
|
|
|
// Recursive GtkTreeView::Node aggregate: "Root/Leaf" ->
|
|
// GtkTreeView::Node{{"Root"}, {GtkTreeView::Node{{"Leaf"}, {}, true}}, true}
|
|
static std::string tree_node_expr(const std::vector<std::string>& segs,
|
|
size_t i) {
|
|
std::ostringstream o;
|
|
o << "GtkTreeView::Node{{\"" << esc_c(segs[i]) << "\"}, {";
|
|
if (i + 1 < segs.size()) o << tree_node_expr(segs, i + 1);
|
|
o << "}, true}";
|
|
return o.str();
|
|
}
|
|
|
|
// Emit set_marks({v, v, ...}) for a Scale/TrackBar from tick-marks +
|
|
// frequency over [mn, mx] (mirrors refresh_scale_marks in the canvas).
|
|
static void emit_scale_marks(std::ostringstream& o, const Widget& w,
|
|
const std::string& var, double mn, double mx) {
|
|
if (prop_int(w, "tick-marks", 0) == 0) return;
|
|
int freq = prop_int(w, "frequency", 10);
|
|
if (freq <= 0 || mx <= mn) return;
|
|
std::vector<double> marks;
|
|
for (double v = mn; v <= mx; v += freq) marks.push_back(v);
|
|
if (marks.empty() || marks.back() != mx) marks.push_back(mx);
|
|
o << " " << var << ".w.set_marks({";
|
|
bool first = true;
|
|
for (double v : marks) {
|
|
if (!first) o << ", ";
|
|
first = false;
|
|
o << fmt_double(std::to_string(v));
|
|
}
|
|
o << "});\n";
|
|
}
|
|
|
|
// ---- Phase 4 (proposal 2.22 / 4.12): Stock + Instrumentation ----
|
|
// Capability table: class -> (prop, setter) rows the generic loop
|
|
// below may emit. A prop is emittable only when it is in the widget's
|
|
// Inspector table (same data, props.h); the arg form comes from that
|
|
// table's kind. Generated by tools/gen_phase4_props.py.
|
|
static const std::map<std::string,
|
|
std::vector<std::pair<std::string, std::string>>>
|
|
kPhase4Caps = {
|
|
// Phase 4 capability table (generated by tools/gen_phase4_props.py).
|
|
// (prop, setter) rows the generator may emit for a class; the arg
|
|
// form comes from the Inspector table's kind for that prop.
|
|
{"InstAnalogGauge", {{"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"needle-line-width", "set_needle_line_width"}, {"value", "set_value"}}},
|
|
{"InstBarMeter", {{"amber-color", "set_amber_color"}, {"face-color", "set_face_color"}, {"green-color", "set_green_color"}, {"ink-color", "set_ink_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"horizontal", "set_horizontal"}, {"marker-line-width", "set_marker_line_width"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstBeacon", {{"beacon-color", "set_beacon_color"}, {"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"flash-rate", "set_flash_rate"}, {"on", "set_on"}, {"phase", "set_phase"}}},
|
|
{"InstBezel", {{"ink-color", "set_ink_color"}, {"panel-color", "set_panel_color"}, {"screw-color", "set_screw_color"}, {"screw-ring-color", "set_screw_ring_color"}, {"white-color", "set_white_color"}}},
|
|
{"InstCircuitBreaker", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"green-color", "set_green_color"}, {"panel-color", "set_panel_color"}, {"plate-color", "set_plate_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"lever-line-width", "set_lever_line_width"}}},
|
|
{"InstControlPanel", {{"amber-color", "set_amber_color"}, {"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"panel-color", "set_panel_color"}, {"screw-color", "set_screw_color"}, {"screw-ring-color", "set_screw_ring_color"}, {"white-color", "set_white_color"}, {"grid-cols", "set_grid_cols"}, {"grid-rows", "set_grid_rows"}}},
|
|
{"InstDigitalReadout", {{"amber-color", "set_amber_color"}, {"dark-color", "set_dark_color"}, {"ink-color", "set_ink_color"}, {"segment-off-color", "set_segment_off_color"}, {"segment-on-color", "set_segment_on_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstEmergencyStop", {{"amber-color", "set_amber_color"}, {"dark-color", "set_dark_color"}, {"red-color", "set_red_color"}, {"redlit-color", "set_redlit_color"}, {"surround-color", "set_surround_color"}, {"white-color", "set_white_color"}, {"on", "set_on"}}},
|
|
{"InstFlowMeter", {{"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstHorizontalTankLevel", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstKeySwitch", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"panel-color", "set_panel_color"}, {"plate-color", "set_plate_color"}, {"white-color", "set_white_color"}, {"key-in", "set_key_in"}, {"pointer-line-width", "set_pointer_line_width"}, {"positions", "set_positions"}}},
|
|
{"InstLampTestButton", {{"bezel-color", "set_bezel_color"}, {"face-color", "set_face_color"}, {"face-down-color", "set_face_down_color"}, {"hover-color", "set_hover_color"}, {"white-color", "set_white_color"}}},
|
|
{"InstLedBlue", {{"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lead-color", "set_lead_color"}, {"lens-color", "set_lens_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstLedDigits1", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"decimal-places", "set_decimal_places"}, {"value", "set_value"}}},
|
|
{"InstLedDigits2", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"decimal-places", "set_decimal_places"}, {"value", "set_value"}}},
|
|
{"InstLedDigits3", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"decimal-places", "set_decimal_places"}, {"value", "set_value"}}},
|
|
{"InstLedDigits4", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"decimal-places", "set_decimal_places"}, {"value", "set_value"}}},
|
|
{"InstLedDigits5", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"decimal-places", "set_decimal_places"}, {"value", "set_value"}}},
|
|
{"InstLedDigits6", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"decimal-places", "set_decimal_places"}, {"value", "set_value"}}},
|
|
{"InstLedGreen", {{"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lead-color", "set_lead_color"}, {"lens-color", "set_lens_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstLedRed", {{"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lead-color", "set_lead_color"}, {"lens-color", "set_lens_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstLevelColumnGauge", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstLevelTransmitter", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstManometer", {{"blue-color", "set_blue_color"}, {"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstNameplate", {{"amber-color", "set_amber_color"}, {"dark-color", "set_dark_color"}, {"engraved-color", "set_engraved_color"}, {"grey-color", "set_grey_color"}, {"screw-color", "set_screw_color"}, {"screw-ring-color", "set_screw_ring_color"}, {"white-color", "set_white_color"}}},
|
|
{"InstNeedleEdgewise", {{"bezel-color", "set_bezel_color"}, {"face-color", "set_face_color"}, {"needle-color", "set_needle_color"}, {"panel-color", "set_panel_color"}, {"red-color", "set_red_color"}, {"tick-color", "set_tick_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstNeedleKnifeEdge", {{"bezel-color", "set_bezel_color"}, {"face-color", "set_face_color"}, {"mirror-color", "set_mirror_color"}, {"needle-color", "set_needle_color"}, {"panel-color", "set_panel_color"}, {"red-color", "set_red_color"}, {"tick-color", "set_tick_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstNeedleTapered", {{"bezel-color", "set_bezel_color"}, {"face-color", "set_face_color"}, {"needle-color", "set_needle_color"}, {"panel-color", "set_panel_color"}, {"red-color", "set_red_color"}, {"tick-color", "set_tick_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstNeedleVu", {{"bezel-color", "set_bezel_color"}, {"face-color", "set_face_color"}, {"needle-color", "set_needle_color"}, {"panel-color", "set_panel_color"}, {"red-color", "set_red_color"}, {"tick-color", "set_tick_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"value", "set_value"}}},
|
|
{"InstOpenChannelLevel", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"surface-color", "set_surface_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstPanelLampAmber", {{"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lens-color", "set_lens_color"}, {"ring-color", "set_ring_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstPanelLampBlue", {{"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lens-color", "set_lens_color"}, {"ring-color", "set_ring_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstPanelLampGreen", {{"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lens-color", "set_lens_color"}, {"ring-color", "set_ring_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstPanelLampRed", {{"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lens-color", "set_lens_color"}, {"ring-color", "set_ring_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstPanelLampWhite", {{"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"hover-color", "set_hover_color"}, {"lens-color", "set_lens_color"}, {"ring-color", "set_ring_color"}, {"white-color", "set_white_color"}, {"brightness", "set_brightness"}, {"on", "set_on"}}},
|
|
{"InstPanelPlate", {{"amber-color", "set_amber_color"}, {"ink-color", "set_ink_color"}, {"panel-color", "set_panel_color"}, {"screw-color", "set_screw_color"}, {"screw-ring-color", "set_screw_ring_color"}, {"white-color", "set_white_color"}}},
|
|
{"InstPressureGauge", {{"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"needle-line-width", "set_needle_line_width"}, {"value", "set_value"}}},
|
|
{"InstPushButton", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"green-color", "set_green_color"}, {"greenlit-color", "set_greenlit_color"}, {"red-color", "set_red_color"}, {"redlit-color", "set_redlit_color"}, {"white-color", "set_white_color"}, {"on", "set_on"}}},
|
|
{"InstPushButtonLatching", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"green-color", "set_green_color"}, {"greenlit-color", "set_greenlit_color"}, {"redlit-color", "set_redlit_color"}, {"white-color", "set_white_color"}, {"on", "set_on"}}},
|
|
{"InstRgbStatusLed", {{"blue-channel-color", "set_blue_channel_color"}, {"dark-color", "set_dark_color"}, {"green-channel-color", "set_green_channel_color"}, {"hover-color", "set_hover_color"}, {"red-channel-color", "set_red_channel_color"}, {"swatch-outline-color", "set_swatch_outline_color"}, {"white-color", "set_white_color"}, {"all-on", "set_all"}, {"blue-on", "set_blue"}, {"brightness", "set_brightness"}, {"green-on", "set_green"}, {"red-on", "set_red"}}},
|
|
{"InstRockerSwitch", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"dimred-color", "set_dimred_color"}, {"green-color", "set_green_color"}, {"panel-color", "set_panel_color"}, {"rocker-color", "set_rocker_color"}, {"white-color", "set_white_color"}, {"on", "set_on"}}},
|
|
{"InstRockerSwitchDouble", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"green-color", "set_green_color"}, {"red-color", "set_red_color"}, {"rocker-color", "set_rocker_color"}, {"white-color", "set_white_color"}, {"position", "set_position"}}},
|
|
{"InstRockerSwitchIlluminated", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"dimred-color", "set_dimred_color"}, {"green-color", "set_green_color"}, {"greenlit-color", "set_greenlit_color"}, {"red-color", "set_red_color"}, {"rocker-color", "set_rocker_color"}, {"white-color", "set_white_color"}, {"on", "set_on"}}},
|
|
{"InstRotarySelector", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"panel-color", "set_panel_color"}, {"plate-color", "set_plate_color"}, {"white-color", "set_white_color"}, {"pointer-line-width", "set_pointer_line_width"}, {"position", "set_position"}, {"positions", "set_positions"}}},
|
|
{"InstSeg14Display1", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg14Display2", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg14Display3", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg14Display4", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg14Display5", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg14Display6", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg16Display1", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg16Display2", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg16Display3", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg16Display4", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg16Display5", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSeg16Display6", {{"bezel-color", "set_bezel_color"}, {"dim-color", "set_dim_color"}, {"label-color", "set_label_color"}, {"lit-color", "set_lit_color"}, {"value", "set_value"}}},
|
|
{"InstSightGlassLevel", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"steel-color", "set_steel_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstSlideSwitch", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"green-color", "set_green_color"}, {"panel-color", "set_panel_color"}, {"rocker-color", "set_rocker_color"}, {"white-color", "set_white_color"}, {"on", "set_on"}}},
|
|
{"InstSphericalTankLevel", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstStackLight", {{"amber-color", "set_amber_color"}, {"dark-color", "set_dark_color"}, {"green-color", "set_green_color"}, {"hover-color", "set_hover_color"}, {"red-color", "set_red_color"}, {"tier-outline-color", "set_tier_outline_color"}, {"white-color", "set_white_color"}, {"all-on", "set_all"}, {"amber-brightness", "set_amber_brightness"}, {"amber-on", "set_amber"}, {"green-brightness", "set_green_brightness"}, {"green-on", "set_green"}, {"red-brightness", "set_red_brightness"}, {"red-on", "set_red"}}},
|
|
{"InstTankLevelAlarms", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstTemperatureGauge", {{"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"needle-line-width", "set_needle_line_width"}, {"value", "set_value"}}},
|
|
{"InstToggleSwitch", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"greenlit-color", "set_greenlit_color"}, {"panel-color", "set_panel_color"}, {"plate-color", "set_plate_color"}, {"redlit-color", "set_redlit_color"}, {"white-color", "set_white_color"}, {"lever-line-width", "set_lever_line_width"}, {"on", "set_on"}}},
|
|
{"InstToggleSwitchIlluminated", {{"amber-color", "set_amber_color"}, {"bezel-color", "set_bezel_color"}, {"dark-color", "set_dark_color"}, {"dimred-color", "set_dimred_color"}, {"greenlit-color", "set_greenlit_color"}, {"panel-color", "set_panel_color"}, {"plate-color", "set_plate_color"}, {"white-color", "set_white_color"}, {"lever-line-width", "set_lever_line_width"}, {"on", "set_on"}}},
|
|
{"InstVerticalTankLevel", {{"amber-color", "set_amber_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"hover-color", "set_hover_color"}, {"ink-color", "set_ink_color"}, {"pale-color", "set_pale_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"alarm-hi", "set_alarm_hi"}, {"alarm-hi-hi", "set_alarm_hi_hi"}, {"alarm-lo", "set_alarm_lo"}, {"alarm-lo-lo", "set_alarm_lo_lo"}, {"level", "set_level"}}},
|
|
{"InstVuMeter", {{"face-color", "set_face_color"}, {"ink-color", "set_ink_color"}, {"red-color", "set_red_color"}, {"white-color", "set_white_color"}, {"maximum", "set_range"}, {"minimum", "set_range"}, {"needle-line-width", "set_needle_line_width"}, {"value", "set_value"}}},
|
|
{"StockAccumulationDistribution", {{"line-color", "set_line_color"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockAreaChart", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"line-color", "set_line_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockArrow", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockBaselineChart", {{"axis-color", "set_axis_color"}, {"baseline-color", "set_baseline_color"}, {"down-color", "set_down_color"}, {"down-fill-color", "set_down_fill_color"}, {"grid-color", "set_grid_color"}, {"line-color", "set_line_color"}, {"up-color", "set_up_color"}, {"up-fill-color", "set_up_fill_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"baseline", "set_baseline"}, {"line-width", "set_line_width"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockBrush", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockCandlestickChart", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockCorrelationView", {{"axis-color", "set_axis_color"}, {"corr-color", "set_corr_color"}, {"grid-color", "set_grid_color"}, {"scatter-color", "set_scatter_color"}, {"zero-line-color", "set_zero_line_color"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"window", "set_window"}}},
|
|
{"StockEllipse", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockFibExtension", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"level-color", "set_level_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}}},
|
|
{"StockFibRetracement", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"level-color", "set_level_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}}},
|
|
{"StockHeikinAshi", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockHollowCandles", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockHorizontalLine", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockIndexedComparison", {{"base-line-color", "set_base_line_color"}, {"base-value", "set_base_value"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockLineChart", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"line-color", "set_line_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockMeasureTool", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockMoneyFlowChart", {{"down-color", "set_down_color"}, {"up-color", "set_up_color"}, {"zero-line-color", "set_zero_line_color"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockMultiSymbolChart", {{"axis-color", "set_axis_color"}, {"grid-color", "set_grid_color"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockOBVChart", {{"line-color", "set_line_color"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockOHLCBarChart", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockOverlayChart", {{"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockParallelChannel", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockPitchfork", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockPriceLabel", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}}},
|
|
{"StockRatioChart", {{"line-color", "set_line_color"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockRectangle", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockRelativePerformance", {{"zero-line-color", "set_zero_line_color"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockRenko", {{"axis-color", "set_axis_color"}, {"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"up-color", "set_up_color"}, {"auto-y", "set_auto_y"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"brick-size", "set_brick_size"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}, {"y-max", "set_y_range"}, {"y-min", "set_y_range"}}},
|
|
{"StockSectorComparison", {{"labels", "set_labels_text"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockSpreadChart", {{"line-color", "set_line_color"}, {"zero-line-color", "set_zero_line_color"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockTextAnnotation", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"fill-color", "set_fill_color"}, {"grid-color", "set_grid_color"}, {"text-color", "set_text_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"annotation-text", "set_annotation_text"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}}},
|
|
{"StockTrendline", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockVWAP", {{"line-color", "set_line_color"}, {"vwap-color", "set_vwap_color"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockVerticalLine", {{"axis-color", "set_axis_color"}, {"candle-down-color", "set_candle_down_color"}, {"candle-up-color", "set_candle_up_color"}, {"color", "set_color"}, {"grid-color", "set_grid_color"}, {"anchor-1-bar", "set_anchors"}, {"anchor-1-price", "set_anchors"}, {"anchor-2-bar", "set_anchors"}, {"anchor-2-price", "set_anchors"}, {"anchor-3-bar", "set_anchors"}, {"anchor-3-price", "set_anchors"}, {"axis-height", "set_axis_h"}, {"axis-width", "set_axis_w"}, {"line-width", "set_line_width"}}},
|
|
{"StockVolumeBars", {{"down-color", "set_down_color"}, {"grid-color", "set_grid_color"}, {"line-color", "set_line_color"}, {"up-color", "set_up_color"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockVolumeCandles", {{"down-color", "set_down_color"}, {"up-color", "set_up_color"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
{"StockVolumeProfile", {{"line-color", "set_line_color"}, {"poc-color", "set_poc_color"}, {"bins", "set_bins"}, {"symbol", "set_symbol"}, {"view-count", "set_view_count"}, {"view-first", "set_view_first"}}},
|
|
};
|
|
|
|
// Phase 4: classes with set_bg_color(Srgb) (generated by
|
|
// tools/gen_phase4_props.py). The common "background"
|
|
// prop is emitted through set_bg_color for these.
|
|
static const std::vector<std::string> kPhase4BgColor = {
|
|
"InstLedDigits1",
|
|
"InstLedDigits2",
|
|
"InstLedDigits3",
|
|
"InstLedDigits4",
|
|
"InstLedDigits5",
|
|
"InstLedDigits6",
|
|
"InstSeg14Display1",
|
|
"InstSeg14Display2",
|
|
"InstSeg14Display3",
|
|
"InstSeg14Display4",
|
|
"InstSeg14Display5",
|
|
"InstSeg14Display6",
|
|
"InstSeg16Display1",
|
|
"InstSeg16Display2",
|
|
"InstSeg16Display3",
|
|
"InstSeg16Display4",
|
|
"InstSeg16Display5",
|
|
"InstSeg16Display6",
|
|
"StockAccumulationDistribution",
|
|
"StockAreaChart",
|
|
"StockArrow",
|
|
"StockBaselineChart",
|
|
"StockBrush",
|
|
"StockCandlestickChart",
|
|
"StockCorrelationView",
|
|
"StockEllipse",
|
|
"StockFibExtension",
|
|
"StockFibRetracement",
|
|
"StockHeikinAshi",
|
|
"StockHollowCandles",
|
|
"StockHorizontalLine",
|
|
"StockIndexedComparison",
|
|
"StockLineChart",
|
|
"StockMeasureTool",
|
|
"StockMoneyFlowChart",
|
|
"StockMultiSymbolChart",
|
|
"StockOBVChart",
|
|
"StockOHLCBarChart",
|
|
"StockOverlayChart",
|
|
"StockParallelChannel",
|
|
"StockPitchfork",
|
|
"StockPriceLabel",
|
|
"StockRatioChart",
|
|
"StockRectangle",
|
|
"StockRelativePerformance",
|
|
"StockRenko",
|
|
"StockSectorComparison",
|
|
"StockSpreadChart",
|
|
"StockTextAnnotation",
|
|
"StockTrendline",
|
|
"StockVWAP",
|
|
"StockVerticalLine",
|
|
"StockVolumeBars",
|
|
"StockVolumeCandles",
|
|
"StockVolumeProfile",
|
|
};
|
|
|
|
// Resolve the XFrame class name for a Phase 4 lookup: snapshot
|
|
// projects carry the class name; the StockChart palette key maps to
|
|
// its class. "" when the widget is not a Stock/Inst class.
|
|
static std::string phase4_class(const Widget& w,
|
|
const std::string& kind,
|
|
const std::string& t) {
|
|
if (t == "StockChart") return "StockCandlestickChart";
|
|
if (!kind.empty()) return "";
|
|
std::string cls = w.type;
|
|
if (cls.rfind("xframe::", 0) == 0) cls = cls.substr(8);
|
|
return cls;
|
|
}
|
|
|
|
static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
|
const XFrameMap& m, const std::string& var) {
|
|
// 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();
|
|
};
|
|
|
|
// Text / label first: the designer seeds label-ish props with the
|
|
// widget name, so set_text(label) reproduces what the designer shows.
|
|
if (t == "Frame" || t == "GroupBox" || t == "Panel") {
|
|
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";
|
|
} else if (has("text")) {
|
|
o << " " << var << ".w.set_text(\"" << esc_c(prop_or(w, "text", ""))
|
|
<< "\");\n";
|
|
}
|
|
|
|
if (t == "Label") {
|
|
if (w.props.count("xalign"))
|
|
o << " " << var << ".w.set_xalign("
|
|
<< fmt_double(prop_or(w, "xalign", "0.5")) << ");\n";
|
|
if (w.props.count("yalign"))
|
|
o << " " << var << ".w.set_yalign("
|
|
<< fmt_double(prop_or(w, "yalign", "0.5")) << ");\n";
|
|
if (w.props.count("wrap"))
|
|
o << " " << var << ".w.set_wrap("
|
|
<< (prop_bool(w, "wrap", false) ? "true" : "false") << ");\n";
|
|
if (w.props.count("selectable"))
|
|
o << " " << var << ".w.set_selectable("
|
|
<< (prop_bool(w, "selectable", false) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("transparent"))
|
|
o << " " << var << ".w.set_transparent("
|
|
<< (prop_bool(w, "transparent", false) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("show-accel-char") &&
|
|
!prop_bool(w, "show-accel-char", true))
|
|
o << " " << var << ".w.set_show_accel_char(false);\n";
|
|
} else if (t == "Button") {
|
|
if (prop_bool(w, "default", false))
|
|
o << " " << var << ".w.set_default(true);\n";
|
|
if (prop_bool(w, "cancel", false))
|
|
o << " " << var << ".w.set_cancel(true);\n";
|
|
if (w.props.count("kind") && prop_int(w, "kind", 0) != 0)
|
|
o << " " << var << ".w.set_kind(" << prop_int(w, "kind", 0)
|
|
<< ");\n";
|
|
if (w.props.count("modal-result") && prop_int(w, "modal-result", 0) != 0)
|
|
o << " " << var << ".w.set_modal_result("
|
|
<< prop_int(w, "modal-result", 0) << ");\n";
|
|
if (w.props.count("layout") && prop_int(w, "layout", 0) != 0)
|
|
o << " " << var << ".w.set_layout(" << prop_int(w, "layout", 0)
|
|
<< ");\n";
|
|
} else if (t == "Entry") {
|
|
if (has("placeholder-text"))
|
|
o << " " << var << ".w.set_placeholder_text(\""
|
|
<< esc_c(prop_or(w, "placeholder-text", "")) << "\");\n";
|
|
if (w.props.count("max-length"))
|
|
o << " " << var << ".w.set_max_length("
|
|
<< prop_int(w, "max-length", 0) << ");\n";
|
|
if (w.props.count("editable"))
|
|
o << " " << var << ".w.set_editable("
|
|
<< (prop_bool(w, "editable", true) ? "true" : "false")
|
|
<< ");\n";
|
|
// Password: the new prop wins when present; a legacy
|
|
// visibility=false means the same thing.
|
|
bool pw = w.props.count("password")
|
|
? prop_bool(w, "password", false)
|
|
: (w.props.count("visibility") &&
|
|
!prop_bool(w, "visibility", true));
|
|
if (pw)
|
|
o << " " << var << ".w.set_password(true);\n";
|
|
if (prop_bool(w, "show-password", false))
|
|
o << " " << var << ".w.set_show_password(true);\n";
|
|
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
|
o << " " << var << ".w.set_alignment("
|
|
<< prop_int(w, "alignment", 0) << ");\n";
|
|
if (w.props.count("char-case") && prop_int(w, "char-case", 0) != 0)
|
|
o << " " << var << ".w.set_char_case("
|
|
<< prop_int(w, "char-case", 0) << ");\n";
|
|
if (prop_bool(w, "numbers-only", false))
|
|
o << " " << var << ".w.set_numbers_only(true);\n";
|
|
if (prop_bool(w, "hide-selection", false))
|
|
o << " " << var << ".w.set_hide_selection(true);\n";
|
|
if (prop_bool(w, "auto-select", false))
|
|
o << " " << var << ".w.set_auto_select(true);\n";
|
|
} else if (t == "Checkbutton") {
|
|
if (prop_bool(w, "allow-grayed", false))
|
|
o << " " << var << ".w.set_allow_grayed(true);\n";
|
|
if (w.props.count("active"))
|
|
o << " " << var << ".w.set_active("
|
|
<< (prop_bool(w, "active", false) ? "true" : "false") << ");\n";
|
|
if (w.props.count("inconsistent"))
|
|
o << " " << var << ".w.set_inconsistent("
|
|
<< (prop_bool(w, "inconsistent", false) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
|
o << " " << var << ".w.set_alignment(1);\n";
|
|
if (has("value-checked"))
|
|
o << " " << var << ".w.set_value_checked(\""
|
|
<< esc_c(prop_or(w, "value-checked", "")) << "\");\n";
|
|
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) {
|
|
o << " " << var << ".w.set_group_id(" << grp << ");\n";
|
|
o << " " << var << ".w.set_group(&radio_group_" << grp
|
|
<< ");\n";
|
|
}
|
|
if (w.props.count("active"))
|
|
o << " " << var << ".w.set_active("
|
|
<< (prop_bool(w, "active", false) ? "true" : "false") << ");\n";
|
|
} else if (t == "Combobox") {
|
|
if (has("items"))
|
|
for (const std::string& item : split_on('|', prop_or(w, "items", "")))
|
|
o << " " << var << ".w.append_text(\"" << esc_c(item)
|
|
<< "\");\n";
|
|
if (w.props.count("active"))
|
|
o << " " << var << ".w.set_active("
|
|
<< prop_int(w, "active", 0) << ");\n";
|
|
if (w.props.count("style") && prop_int(w, "style", 0) != 0)
|
|
o << " " << var << ".w.set_style(" << prop_int(w, "style", 0)
|
|
<< ");\n";
|
|
if (w.props.count("drop-down-count") &&
|
|
prop_int(w, "drop-down-count", 8) != 8)
|
|
o << " " << var << ".w.set_drop_down_count("
|
|
<< prop_int(w, "drop-down-count", 8) << ");\n";
|
|
if (w.props.count("drop-down-width") &&
|
|
prop_int(w, "drop-down-width", 0) != 0)
|
|
o << " " << var << ".w.set_drop_down_width("
|
|
<< prop_int(w, "drop-down-width", 0) << ");\n";
|
|
if (prop_bool(w, "sorted", false))
|
|
o << " " << var << ".w.set_sorted(true);\n";
|
|
if (prop_bool(w, "read-only", false))
|
|
o << " " << var << ".w.set_read_only(true);\n";
|
|
if (w.props.count("max-length") && prop_int(w, "max-length", 0) != 0)
|
|
o << " " << var << ".w.set_max_length("
|
|
<< prop_int(w, "max-length", 0) << ");\n";
|
|
if (prop_bool(w, "auto-complete", false))
|
|
o << " " << var << ".w.set_auto_complete(true);\n";
|
|
if (w.props.count("char-case") && prop_int(w, "char-case", 0) != 0)
|
|
o << " " << var << ".w.set_char_case("
|
|
<< prop_int(w, "char-case", 0) << ");\n";
|
|
} else if (t == "Listbox") {
|
|
if (has("items"))
|
|
for (const std::string& item : split_on('|', prop_or(w, "items", "")))
|
|
o << " " << var << ".w.add_row(\"" << esc_c(item) << "\");\n";
|
|
if (w.props.count("selection-mode") &&
|
|
prop_int(w, "selection-mode", 1) == 3)
|
|
o << " " << var << ".w.set_multi_select(true);\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 (prop_bool(w, "sorted", false))
|
|
o << " " << var << ".w.set_sorted(true);\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";
|
|
} else if (t == "CheckListBox") {
|
|
if (has("items"))
|
|
for (const std::string& item : split_on('|', prop_or(w, "items", "")))
|
|
o << " " << var << ".w.add_item(\"" << esc_c(item)
|
|
<< "\");\n";
|
|
if (prop_bool(w, "sorted", false))
|
|
o << " " << var << ".w.set_sorted(true);\n";
|
|
if (has("checked-items"))
|
|
o << " " << var << ".w.set_checked_items(\""
|
|
<< esc_c(prop_or(w, "checked-items", "")) << "\");\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";
|
|
} else if (t == "Menubutton") {
|
|
if (w.props.count("direction") && prop_int(w, "direction", 1) != 1)
|
|
o << " " << var << ".w.set_direction("
|
|
<< prop_int(w, "direction", 1) << ");\n";
|
|
} else if (t == "Scale") {
|
|
if (w.props.count("minimum") || w.props.count("maximum"))
|
|
o << " " << var << ".w.set_range("
|
|
<< fmt_double(prop_or(w, "minimum", "0")) << ", "
|
|
<< fmt_double(prop_or(w, "maximum", "100")) << ");\n";
|
|
if (w.props.count("value"))
|
|
o << " " << var << ".w.set_value("
|
|
<< fmt_double(prop_or(w, "value", "0")) << ");\n";
|
|
if (w.props.count("draw-value"))
|
|
o << " " << var << ".w.set_draw_value("
|
|
<< (prop_bool(w, "draw-value", true) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("page-step") &&
|
|
std::atof(prop_or(w, "page-step", "10").c_str()) != 10.0)
|
|
o << " " << var << ".w.set_page_step("
|
|
<< fmt_double(prop_or(w, "page-step", "10")) << ");\n";
|
|
emit_scale_marks(o, w, var,
|
|
std::atof(prop_or(w, "minimum", "0").c_str()),
|
|
std::atof(prop_or(w, "maximum", "100").c_str()));
|
|
if (prop_bool(w, "show-sel-range", false))
|
|
o << " " << var << ".w.set_show_sel_range(true);\n";
|
|
if (w.props.count("sel-start") &&
|
|
std::atof(prop_or(w, "sel-start", "0").c_str()) != 0.0)
|
|
o << " " << var << ".w.set_sel_start("
|
|
<< fmt_double(prop_or(w, "sel-start", "0")) << ");\n";
|
|
if (w.props.count("sel-end") &&
|
|
std::atof(prop_or(w, "sel-end", "0").c_str()) != 0.0)
|
|
o << " " << var << ".w.set_sel_end("
|
|
<< fmt_double(prop_or(w, "sel-end", "0")) << ");\n";
|
|
} else if (t == "Scrollbar") {
|
|
if (w.props.count("lower") &&
|
|
std::atof(prop_or(w, "lower", "0").c_str()) != 0.0)
|
|
o << " " << var << ".w.set_lower("
|
|
<< fmt_double(prop_or(w, "lower", "0")) << ");\n";
|
|
if (w.props.count("upper"))
|
|
o << " " << var << ".w.set_upper("
|
|
<< fmt_double(prop_or(w, "upper", "100")) << ");\n";
|
|
if (w.props.count("page-size"))
|
|
o << " " << var << ".w.set_page_size("
|
|
<< fmt_double(prop_or(w, "page-size", "10")) << ");\n";
|
|
if (w.props.count("step-increment"))
|
|
o << " " << var << ".w.set_step("
|
|
<< fmt_double(prop_or(w, "step-increment", "1")) << ");\n";
|
|
if (w.props.count("page-increment") &&
|
|
std::atof(prop_or(w, "page-increment", "10").c_str()) != 10.0)
|
|
o << " " << var << ".w.set_page_increment("
|
|
<< fmt_double(prop_or(w, "page-increment", "10")) << ");\n";
|
|
if (w.props.count("value"))
|
|
o << " " << var << ".w.set_value("
|
|
<< fmt_double(prop_or(w, "value", "0")) << ");\n";
|
|
if (w.props.count("orientation") && prop_int(w, "orientation", 0) != 0)
|
|
o << " " << var << ".w.set_orientation_vertical(true);\n";
|
|
if (w.props.count("large-change") &&
|
|
std::atof(prop_or(w, "large-change", "10").c_str()) != 10.0)
|
|
o << " " << var << ".w.set_page_increment("
|
|
<< fmt_double(prop_or(w, "large-change", "10")) << ");\n";
|
|
} else if (t == "Text") {
|
|
if (w.props.count("editable"))
|
|
o << " " << var << ".w.set_editable("
|
|
<< (prop_bool(w, "editable", true) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("wrap-mode"))
|
|
o << " " << var << ".w.set_wrap_mode("
|
|
<< (prop_int(w, "wrap-mode", 0) != 0 ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("cursor-visible") &&
|
|
!prop_bool(w, "cursor-visible", true))
|
|
o << " " << var << ".w.set_cursor_visible(false);\n";
|
|
if (w.props.count("max-length") && prop_int(w, "max-length", 0) != 0)
|
|
o << " " << var << ".w.set_max_length("
|
|
<< prop_int(w, "max-length", 0) << ");\n";
|
|
if (w.props.count("scroll-bars") && prop_int(w, "scroll-bars", 0) != 0)
|
|
o << " " << var << ".w.set_scroll_bars("
|
|
<< prop_int(w, "scroll-bars", 0) << ");\n";
|
|
if (w.props.count("want-tabs") && !prop_bool(w, "want-tabs", true))
|
|
o << " " << var << ".w.set_want_tabs(false);\n";
|
|
if (w.props.count("want-returns") &&
|
|
!prop_bool(w, "want-returns", true))
|
|
o << " " << var << ".w.set_want_returns(false);\n";
|
|
if (prop_bool(w, "hide-selection", false))
|
|
o << " " << var << ".w.set_hide_selection(true);\n";
|
|
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
|
o << " " << var << ".w.set_alignment("
|
|
<< prop_int(w, "alignment", 0) << ");\n";
|
|
} else if (t == "Memo") {
|
|
if (w.props.count("editable"))
|
|
o << " " << var << ".w.set_editable("
|
|
<< (prop_bool(w, "editable", true) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("cursor-visible") &&
|
|
!prop_bool(w, "cursor-visible", true))
|
|
o << " " << var << ".w.set_cursor_visible(false);\n";
|
|
if (w.props.count("max-length") && prop_int(w, "max-length", 0) != 0)
|
|
o << " " << var << ".w.set_max_length("
|
|
<< prop_int(w, "max-length", 0) << ");\n";
|
|
if (w.props.count("scroll-bars") && prop_int(w, "scroll-bars", 3) != 3)
|
|
o << " " << var << ".w.set_scroll_bars("
|
|
<< prop_int(w, "scroll-bars", 3) << ");\n";
|
|
if (w.props.count("want-tabs") && !prop_bool(w, "want-tabs", true))
|
|
o << " " << var << ".w.set_want_tabs(false);\n";
|
|
if (w.props.count("want-returns") &&
|
|
!prop_bool(w, "want-returns", true))
|
|
o << " " << var << ".w.set_want_returns(false);\n";
|
|
if (prop_bool(w, "hide-selection", false))
|
|
o << " " << var << ".w.set_hide_selection(true);\n";
|
|
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
|
o << " " << var << ".w.set_alignment("
|
|
<< prop_int(w, "alignment", 0) << ");\n";
|
|
if (w.props.count("wrap-mode"))
|
|
o << " " << var << ".w.set_wordwrap("
|
|
<< (prop_int(w, "wrap-mode", 0) != 0 ? "true" : "false")
|
|
<< ");\n";
|
|
} else if (t == "Notebook") {
|
|
if (has("pages"))
|
|
for (const std::string& page : split_on('|', prop_or(w, "pages", "")))
|
|
o << " " << var << ".w.append_page(\"" << esc_c(page)
|
|
<< "\");\n";
|
|
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("
|
|
<< prop_int(w, "position", 100) << ");\n";
|
|
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(\""
|
|
<< esc_c(prop_or(w, "items", "")) << "\");\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(\""
|
|
<< esc_c(prop_or(w, "menus", "")) << "\");\n";
|
|
} else if (t == "SpinEdit") {
|
|
int lo = prop_int(w, "minimum", 0);
|
|
int hi = prop_int(w, "maximum", 100);
|
|
if (w.props.count("minimum") || w.props.count("maximum"))
|
|
o << " " << var << ".w.set_range(" << fmt_double(std::to_string(lo))
|
|
<< ", " << fmt_double(std::to_string(hi)) << ");\n";
|
|
if (w.props.count("step"))
|
|
o << " " << var << ".w.set_increments("
|
|
<< fmt_double(prop_or(w, "step", "1")) << ", 10.0);\n";
|
|
if (w.props.count("value"))
|
|
o << " " << var << ".w.set_value("
|
|
<< fmt_double(prop_or(w, "value", "0")) << ");\n";
|
|
if (w.props.count("digits"))
|
|
o << " " << var << ".w.set_digits("
|
|
<< prop_int(w, "digits", 0) << ");\n";
|
|
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);
|
|
if (w.props.count("minimum") || w.props.count("maximum"))
|
|
o << " " << var << ".w.set_range(" << fmt_double(std::to_string(lo))
|
|
<< ", " << fmt_double(std::to_string(hi)) << ");\n";
|
|
if (w.props.count("step"))
|
|
o << " " << var << ".w.set_step("
|
|
<< fmt_double(prop_or(w, "step", "1")) << ");\n";
|
|
if (w.props.count("value"))
|
|
o << " " << var << ".w.set_value("
|
|
<< fmt_double(prop_or(w, "value", "0")) << ");\n";
|
|
if (w.props.count("draw-value"))
|
|
o << " " << var << ".w.set_draw_value("
|
|
<< (prop_bool(w, "draw-value", true) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("orientation"))
|
|
o << " " << var << ".w.set_orientation_vertical("
|
|
<< (prop_int(w, "orientation", 0) != 0 ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("page-step") &&
|
|
std::atof(prop_or(w, "page-step", "10").c_str()) != 10.0)
|
|
o << " " << var << ".w.set_page_step("
|
|
<< fmt_double(prop_or(w, "page-step", "10")) << ");\n";
|
|
emit_scale_marks(o, w, var, prop_int(w, "minimum", 0),
|
|
prop_int(w, "maximum", 100));
|
|
if (prop_bool(w, "show-sel-range", false))
|
|
o << " " << var << ".w.set_show_sel_range(true);\n";
|
|
if (w.props.count("sel-start") &&
|
|
std::atof(prop_or(w, "sel-start", "0").c_str()) != 0.0)
|
|
o << " " << var << ".w.set_sel_start("
|
|
<< fmt_double(prop_or(w, "sel-start", "0")) << ");\n";
|
|
if (w.props.count("sel-end") &&
|
|
std::atof(prop_or(w, "sel-end", "0").c_str()) != 0.0)
|
|
o << " " << var << ".w.set_sel_end("
|
|
<< fmt_double(prop_or(w, "sel-end", "0")) << ");\n";
|
|
} else if (t == "ProgressBar") {
|
|
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;
|
|
if (std::sscanf(prop_or(w, "date", "").c_str(), "%d-%d-%d",
|
|
&y, &mo, &d) == 3)
|
|
o << " " << var << ".w.set_date(" << y << ", " << mo << ", "
|
|
<< d << ");\n";
|
|
}
|
|
if (w.props.count("show-heading"))
|
|
o << " " << var << ".w.set_show_heading("
|
|
<< (prop_bool(w, "show-heading", true) ? "true" : "false")
|
|
<< ");\n";
|
|
if (w.props.count("show-day-names"))
|
|
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;
|
|
for (const std::string& path : split_on(';', prop_or(w, "items", ""))) {
|
|
std::vector<std::string> segs = split_on('/', path);
|
|
if (!segs.empty()) roots.push_back(tree_node_expr(segs, 0));
|
|
}
|
|
o << " " << var << ".w.set_roots({";
|
|
bool first = true;
|
|
for (const std::string& r : roots) {
|
|
if (!first) o << ", ";
|
|
first = false;
|
|
o << r;
|
|
}
|
|
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", ""))
|
|
<< "\");\n";
|
|
else
|
|
o << " " << var << ".w.set_title(\"" << esc_c(w.name) << "\");\n";
|
|
if (w.props.count("resizable"))
|
|
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(\""
|
|
<< esc_c(prop_or(w, "file", "")) << "\");\n";
|
|
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
|
|
// the XFrame widget API, so the design data is recorded here for
|
|
// hand-wiring instead of silently dropped. (The chart's own
|
|
// colours/params -- up/down colour, grid, view, y-range -- are
|
|
// emitted by the generic Phase 4 loop below.)
|
|
if (has("data-file") || has("indicators") || has("drawings") ||
|
|
has("compare-files") || w.props.count("scale-mode")) {
|
|
o << " // NOTE: StockChart design data not representable "
|
|
"through the StockCandlestickChart API:\n";
|
|
if (has("data-file"))
|
|
o << " // data-file: \"" << esc_c(prop_or(w, "data-file", ""))
|
|
<< "\"\n";
|
|
if (has("indicators"))
|
|
o << " // indicators: \"" << esc_c(prop_or(w, "indicators", ""))
|
|
<< "\"\n";
|
|
if (has("drawings"))
|
|
o << " // drawings: \"" << esc_c(prop_or(w, "drawings", ""))
|
|
<< "\"\n";
|
|
if (has("compare-files"))
|
|
o << " // compare-files: \""
|
|
<< esc_c(prop_or(w, "compare-files", "")) << "\"\n";
|
|
if (w.props.count("scale-mode"))
|
|
o << " // scale-mode: " << prop_or(w, "scale-mode", "0")
|
|
<< " (0 = price, 1 = percent)\n";
|
|
}
|
|
} else if (t == "Shape") {
|
|
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";
|
|
} else if (t == "Plot") {
|
|
o << " // NOTE: Plot line colour \""
|
|
<< esc_c(prop_or(w, "line-color", ""))
|
|
<< "\" is not representable through the XGraph API.\n";
|
|
}
|
|
|
|
// Phase 4: Stock/Instrumentation generic emission. One call per
|
|
// Inspector-table prop the widget actually has, gated by the
|
|
// capability table (so a prop is never emitted for a class whose
|
|
// widget lacks the setter) and by the table kind (so "value" emits
|
|
// set_value(double) for gauges and set_value("...") for Seg displays).
|
|
{
|
|
std::string cls = phase4_class(w, kind, t);
|
|
auto cit = cls.empty() ? kPhase4Caps.end() : kPhase4Caps.find(cls);
|
|
if (cit != kPhase4Caps.end()) {
|
|
// Pairs first: one setter takes two values, so both props
|
|
// are emitted together from the model.
|
|
if (w.props.count("minimum") || w.props.count("maximum"))
|
|
o << " " << var << ".w.set_range("
|
|
<< fmt_double(prop_or(w, "minimum", "0")) << ", "
|
|
<< fmt_double(prop_or(w, "maximum", "100")) << ");\n";
|
|
if (w.props.count("y-min") || w.props.count("y-max"))
|
|
o << " " << var << ".w.set_y_range("
|
|
<< fmt_double(prop_or(w, "y-min", "0")) << ", "
|
|
<< fmt_double(prop_or(w, "y-max", "1")) << ");\n";
|
|
// Anchors: all six components -> set_anchors3; otherwise
|
|
// one set_anchor(i, bar, price) per anchor whose two
|
|
// components are both present (never silently reset a
|
|
// sibling anchor).
|
|
bool all6 = w.props.count("anchor-1-bar") &&
|
|
w.props.count("anchor-1-price") &&
|
|
w.props.count("anchor-2-bar") &&
|
|
w.props.count("anchor-2-price") &&
|
|
w.props.count("anchor-3-bar") &&
|
|
w.props.count("anchor-3-price");
|
|
if (all6) {
|
|
o << " " << var << ".w.set_anchors3("
|
|
<< prop_int(w, "anchor-1-bar", 0) << ", "
|
|
<< fmt_double(prop_or(w, "anchor-1-price", "100")) << ", "
|
|
<< prop_int(w, "anchor-2-bar", 10) << ", "
|
|
<< fmt_double(prop_or(w, "anchor-2-price", "100")) << ", "
|
|
<< prop_int(w, "anchor-3-bar", 20) << ", "
|
|
<< fmt_double(prop_or(w, "anchor-3-price", "100"))
|
|
<< ");\n";
|
|
} else {
|
|
for (int i = 1; i <= 3; ++i) {
|
|
std::string bar_key =
|
|
"anchor-" + std::to_string(i) + "-bar";
|
|
std::string price_key =
|
|
"anchor-" + std::to_string(i) + "-price";
|
|
if (!w.props.count(bar_key) ||
|
|
!w.props.count(price_key))
|
|
continue;
|
|
o << " " << var << ".w.set_anchor(" << (i - 1)
|
|
<< ", " << prop_int(w, bar_key, (i - 1) * 10) << ", "
|
|
<< fmt_double(prop_or(w, price_key, "100"))
|
|
<< ");\n";
|
|
}
|
|
}
|
|
for (const auto& row : cit->second) {
|
|
const std::string& prop = row.first;
|
|
const std::string& setter = row.second;
|
|
if (prop == "text") continue; // shared path above
|
|
if (prop == "minimum" || prop == "maximum" ||
|
|
prop == "y-min" || prop == "y-max" ||
|
|
prop.rfind("anchor-", 0) == 0)
|
|
continue; // pairs, emitted above
|
|
if (!w.props.count(prop)) continue;
|
|
const PropDef* d = find_prop(cls, prop);
|
|
if (!d) continue;
|
|
if (d->kind == PropKind::Color) {
|
|
std::string rgb = prop_rgb_args(w, prop);
|
|
if (!rgb.empty())
|
|
emit_color_call(o, var, setter, true, rgb);
|
|
} else if (d->kind == PropKind::Double) {
|
|
o << " " << var << ".w." << setter << "("
|
|
<< fmt_double(prop_or(w, prop, d->def ? d->def : "0"))
|
|
<< ");\n";
|
|
} else if (d->kind == PropKind::Int) {
|
|
o << " " << var << ".w." << setter << "("
|
|
<< prop_int(w, prop, d->def ? std::atoi(d->def) : 0)
|
|
<< ");\n";
|
|
} else if (d->kind == PropKind::Str) {
|
|
o << " " << var << ".w." << setter << "(\""
|
|
<< esc_c(prop_or(w, prop, d->def ? d->def : ""))
|
|
<< "\");\n";
|
|
} else {
|
|
// Bool (no Enum props in the Phase 4 tables).
|
|
o << " " << var << ".w." << setter << "("
|
|
<< (prop_bool(w, prop,
|
|
d->def && std::string(d->def) == "true")
|
|
? "true" : "false")
|
|
<< ");\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Common background / foreground: direct setter where the class has
|
|
// one, otherwise the per-widget style clone (emitted above).
|
|
if (m.fill[0]) {
|
|
std::string rgb = prop_rgb_args(w, "background");
|
|
if (!rgb.empty()) emit_color_call(o, var, m.fill, m.fill_srgb, rgb);
|
|
} else {
|
|
// Phase 4: the map has no fill setter for Stock/Inst classes;
|
|
// those with set_bg_color take the background through it.
|
|
std::string rgb = prop_rgb_args(w, "background");
|
|
if (!rgb.empty()) {
|
|
std::string cls = phase4_class(w, kind, t);
|
|
if (!cls.empty() &&
|
|
std::find(kPhase4BgColor.begin(), kPhase4BgColor.end(),
|
|
cls) != kPhase4BgColor.end())
|
|
emit_color_call(o, var, "set_bg_color", true, rgb);
|
|
}
|
|
}
|
|
if (m.text[0]) {
|
|
std::string rgb = prop_rgb_args(w, "foreground");
|
|
if (!rgb.empty()) emit_color_call(o, var, m.text, m.text_srgb, rgb);
|
|
}
|
|
if (style_for(w, m).needed)
|
|
o << " " << var << ".w.set_style_name(\"" << var << "_style\");\n";
|
|
// Phase 1 generic props: enabled/visible go through the IWidget
|
|
// virtuals, so they compile for every class (a class without the
|
|
// setter is a no-op). Only emitted when false (the default).
|
|
if (w.props.count("enabled") && !prop_bool(w, "enabled", true))
|
|
o << " " << var << ".set_enabled(false);\n";
|
|
if (w.props.count("visible") && !prop_bool(w, "visible", true))
|
|
o << " " << var << ".set_visible(false);\n";
|
|
// Model-only props (stored in the place file, no XFrame setter):
|
|
// recorded here, not silently dropped.
|
|
{
|
|
std::vector<std::string> notes;
|
|
if (has("hint"))
|
|
notes.push_back("hint=\"" +
|
|
esc_c(prop_or(w, "hint", "")) + "\"");
|
|
if (has("tooltip-text"))
|
|
notes.push_back("tooltip-text=\"" +
|
|
esc_c(prop_or(w, "tooltip-text", "")) + "\"");
|
|
if (prop_int(w, "tag", 0) != 0)
|
|
notes.push_back("tag=" + std::to_string(prop_int(w, "tag", 0)));
|
|
if (has("cursor"))
|
|
notes.push_back("cursor=\"" +
|
|
esc_c(prop_or(w, "cursor", "")) + "\"");
|
|
if (prop_int(w, "tab-order", 0) != 0)
|
|
notes.push_back("tab-order=" +
|
|
std::to_string(prop_int(w, "tab-order", 0)));
|
|
if (w.props.count("tab-stop") && !prop_bool(w, "tab-stop", true))
|
|
notes.push_back("tab-stop=false");
|
|
for (const char* mg : {"margin-left", "margin-top", "margin-right",
|
|
"margin-bottom", "margin-around"})
|
|
if (prop_int(w, mg, 0) != 0)
|
|
notes.push_back(std::string(mg) + "=" +
|
|
std::to_string(prop_int(w, mg, 0)));
|
|
if (prop_bool(w, "show-hint", false))
|
|
notes.push_back("show-hint=true");
|
|
if (prop_bool(w, "font-underline", false))
|
|
notes.push_back("font-underline=true");
|
|
if (prop_bool(w, "font-strikeout", false))
|
|
notes.push_back("font-strikeout=true");
|
|
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", "")) + "\"");
|
|
if (w.props.count("columns") && prop_int(w, "columns", 1) != 1)
|
|
notes.push_back("columns=" +
|
|
std::to_string(prop_int(w, "columns", 1)));
|
|
if (prop_bool(w, "integral-height", false))
|
|
notes.push_back("integral-height=true");
|
|
if (!notes.empty()) {
|
|
o << " // NOTE (model-only, no XFrame setter): ";
|
|
for (size_t i = 0; i < notes.size(); ++i) {
|
|
if (i) o << ", ";
|
|
o << notes[i];
|
|
}
|
|
o << "\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------- event handlers
|
|
//
|
|
// A connected GTK signal becomes a stub handler plus a wiring line that
|
|
// assigns the mapped XFrame widget's std::function callback. The stub
|
|
// prints the same "EVENT <Widget> <signal>" trace the old generator's
|
|
// stubs printed, so behaviour stays observable. Signals with no XFrame
|
|
// callback on the class (e.g. row-activated) still get their stub —
|
|
// kept for hand-wiring — with a NOTE and no wiring line. Builtin draw
|
|
// events are skipped: the widget already draws itself.
|
|
|
|
static std::string stub_name(const Widget& w, const std::string& signal) {
|
|
return "on_" + sanitize_ident(w.name) + "_" + sig_part(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 (t == "Memo") return "on_change";
|
|
if (t == "Spreadsheet") {
|
|
lambda_params = "int col, int row";
|
|
pass_args = "col, row";
|
|
return "on_cell_change";
|
|
}
|
|
return "on_changed";
|
|
}
|
|
if (signal == "activate") return "on_activate";
|
|
if (signal == "value-changed") {
|
|
if (t == "SpinEdit") lambda_params = "double";
|
|
return "on_value_changed";
|
|
}
|
|
if (signal == "row-selected") {
|
|
lambda_params = "int";
|
|
return "on_row_selected";
|
|
}
|
|
if (signal == "switch-page") {
|
|
lambda_params = "int";
|
|
return "on_page_changed";
|
|
}
|
|
if (signal == "day-selected") return "on_day_selected";
|
|
if (signal == "month-changed") return "on_month_changed";
|
|
if (signal == "color-set") {
|
|
lambda_params = "Srgb";
|
|
return "on_color_set";
|
|
}
|
|
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;
|
|
if (d->kind == EventKind::ItemClicked) {
|
|
for (const std::string& item :
|
|
split_on('|', prop_or(w, "items", "New|Open|Save"))) {
|
|
std::string stub = "on_" + sanitize_ident(w.name) +
|
|
"_clicked_" + id_part(item);
|
|
o << "void " << stub << "() {\n"
|
|
<< " std::printf(\"EVENT " << esc_c(w.name) << " clicked "
|
|
<< esc_c(item) << "\\n\");\n}\n\n";
|
|
}
|
|
continue;
|
|
}
|
|
if (d->kind == EventKind::ItemActivate) {
|
|
for (const std::string& menu :
|
|
split_on('|', prop_or(w, "menus", "File|Edit|Help"))) {
|
|
std::string stub = "on_" + sanitize_ident(w.name) +
|
|
"_activate_" + id_part(menu);
|
|
o << "void " << stub << "() {\n"
|
|
<< " std::printf(\"EVENT " << esc_c(w.name) << " activate "
|
|
<< esc_c(menu) << "\\n\");\n}\n\n";
|
|
}
|
|
continue;
|
|
}
|
|
std::string stub = stub_name(w, sig);
|
|
// 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;
|
|
if (d->kind == EventKind::ItemClicked) {
|
|
std::vector<std::string> items =
|
|
split_on('|', prop_or(w, "items", "New|Open|Save"));
|
|
o << " " << var << ".w.on_activate = [](int index) {\n"
|
|
<< " switch (index) {\n";
|
|
for (size_t i = 0; i < items.size(); ++i)
|
|
o << " case " << i << ": on_"
|
|
<< sanitize_ident(w.name) << "_clicked_"
|
|
<< id_part(items[i]) << "(); break;\n";
|
|
o << " default: break;\n"
|
|
<< " }\n"
|
|
<< " };\n";
|
|
continue;
|
|
}
|
|
if (d->kind == EventKind::ItemActivate) {
|
|
std::vector<std::string> menus =
|
|
split_on('|', prop_or(w, "menus", "File|Edit|Help"));
|
|
o << " " << var << ".w.on_activate = [](int menu, int item) {\n"
|
|
<< " (void)item;\n"
|
|
<< " switch (menu) {\n";
|
|
for (size_t i = 0; i < menus.size(); ++i)
|
|
o << " case " << i << ": on_"
|
|
<< sanitize_ident(w.name) << "_activate_"
|
|
<< id_part(menus[i]) << "(); break;\n";
|
|
o << " default: break;\n"
|
|
<< " }\n"
|
|
<< " };\n";
|
|
continue;
|
|
}
|
|
std::string 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)
|
|
<< " is kept for hand-wiring.\n";
|
|
continue;
|
|
}
|
|
std::string stub = stub_name(w, sig);
|
|
// 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";
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------- Phase 1 helpers
|
|
//
|
|
// Effective anchors for a widget (Flag 1): align maps to an anchor
|
|
// set (Top -> top+left+right, Bottom -> bottom+left+right, Left ->
|
|
// left+top+bottom, Right -> right+top+bottom, Client -> all four);
|
|
// align None (0) leaves the four anchor bools in charge. The
|
|
// Lazarus default is [akTop, akLeft].
|
|
struct Anchors {
|
|
bool top = true, left = true, right = false, bottom = false;
|
|
};
|
|
|
|
static Anchors effective_anchors(const Widget& w) {
|
|
int align = prop_int(w, "align", 0);
|
|
if (align == 1) return Anchors{true, true, true, false};
|
|
if (align == 2) return Anchors{false, true, true, true};
|
|
if (align == 3) return Anchors{true, true, false, true};
|
|
if (align == 4) return Anchors{true, false, true, true};
|
|
if (align == 5) return Anchors{true, true, true, true};
|
|
return Anchors{prop_bool(w, "anchor-top", true),
|
|
prop_bool(w, "anchor-left", true),
|
|
prop_bool(w, "anchor-right", false),
|
|
prop_bool(w, "anchor-bottom", false)};
|
|
}
|
|
|
|
static std::string anchor_label(const Anchors& a) {
|
|
std::string out;
|
|
auto add = [&](const char* n) {
|
|
if (!out.empty()) out += ", ";
|
|
out += n;
|
|
};
|
|
if (a.top) add("top");
|
|
if (a.left) add("left");
|
|
if (a.right) add("right");
|
|
if (a.bottom) add("bottom");
|
|
return out.empty() ? "none" : out;
|
|
}
|
|
|
|
// True when the widget has a per-widget font that differs from the
|
|
// default (fixed, 13, regular): the style then needs the font picker.
|
|
static bool widget_font_custom(const Widget& w) {
|
|
if (!prop_or(w, "font-name", "").empty()) return true;
|
|
if (w.props.count("font-size") && prop_int(w, "font-size", 13) != 13)
|
|
return true;
|
|
if (prop_bool(w, "font-bold", false)) return true;
|
|
if (prop_bool(w, "font-italic", false)) return true;
|
|
return false;
|
|
}
|
|
|
|
// The font argument for a per-widget add_style_ex: the default XLFD
|
|
// literal, or a lightgui_pick_font(...) call when the widget has a
|
|
// custom font (Phase 1, Flag 2). Underline / strikeout have no X
|
|
// core-font rendering and do not make the font custom.
|
|
static std::string widget_font_expr(const Widget& w) {
|
|
if (!widget_font_custom(w))
|
|
return "\"-misc-fixed-medium-r-normal--13-*\"";
|
|
std::string expr = "lightgui_pick_font(display, \"" +
|
|
esc_c(prop_or(w, "font-name", "")) + "\", ";
|
|
expr += std::to_string(prop_int(w, "font-size", 13)) + ", ";
|
|
expr += prop_bool(w, "font-bold", false) ? "true" : "false";
|
|
expr += ", ";
|
|
expr += prop_bool(w, "font-italic", false) ? "true" : "false";
|
|
expr += ")";
|
|
return expr;
|
|
}
|
|
|
|
// Per-widget font picker, emitted into generated code when a widget
|
|
// has a custom font (Phase 1, Flag 2). Returns the first loadable
|
|
// XLFD for family/size/bold/italic (the same candidate chain as
|
|
// font_xlfd_for in the canvas core).
|
|
static const char* kLightguiPickFont = R"GEN(// Pick a loadable XLFD for a per-widget font (Phase 1, Flag 2):
|
|
// family/size/bold/italic, then oblique for italic, then plain, then
|
|
// fixed at the requested size, then the fixed 13 default.
|
|
// A wildcard pattern can match a two-byte font first (e.g. a JIS fixed
|
|
// font at size 16, which has no misc twin). XDrawString with 1-byte
|
|
// Latin text draws nothing with such a font, so every match is listed
|
|
// and the first SINGLE-BYTE font (min_byte1 == max_byte1 == 0) wins;
|
|
// its full XLFD name is returned, since the pattern itself would
|
|
// re-resolve to the two-byte font.
|
|
static std::string lightgui_pick_font(Display* display,
|
|
const std::string& family, int size,
|
|
bool bold, bool italic) {
|
|
if (size < 6) size = 6;
|
|
if (size > 72) size = 72;
|
|
std::string fam = family;
|
|
for (char& c : fam) c = (char)std::tolower((unsigned char)c);
|
|
if (fam.empty()) fam = "fixed";
|
|
std::string weight = bold ? "bold" : "medium";
|
|
std::string slant = italic ? "i" : "r";
|
|
std::string sz = std::to_string(size);
|
|
std::vector<std::string> cands;
|
|
if (!fam.empty() && fam[0] == '-') {
|
|
cands.push_back(fam);
|
|
} else {
|
|
cands.push_back("-*-" + fam + "-" + weight + "-" + slant + "-normal--" + sz + "-*");
|
|
if (italic) cands.push_back("-*-" + fam + "-" + weight + "-o-normal--" + sz + "-*");
|
|
cands.push_back("-*-" + fam + "-medium-r-normal--" + sz + "-*");
|
|
}
|
|
cands.push_back("-*-fixed-" + weight + "-" + slant + "-normal--" + sz + "-*");
|
|
if (italic) cands.push_back("-*-fixed-" + weight + "-o-normal--" + sz + "-*");
|
|
cands.push_back("-*-fixed-medium-r-normal--" + sz + "-*");
|
|
cands.push_back("-misc-fixed-medium-r-normal--13-*");
|
|
for (const std::string& pat : cands) {
|
|
int count = 0;
|
|
char** list = XListFonts(display, pat.c_str(), 64, &count);
|
|
if (!list) continue;
|
|
for (int i = 0; i < count; ++i) {
|
|
XFontStruct* f = XLoadQueryFont(display, list[i]);
|
|
if (!f) continue;
|
|
bool single_byte = (f->min_byte1 == 0 && f->max_byte1 == 0);
|
|
XFreeFont(display, f);
|
|
if (single_byte) {
|
|
std::string hit = list[i];
|
|
XFreeFontNames(list);
|
|
return hit;
|
|
}
|
|
}
|
|
XFreeFontNames(list);
|
|
}
|
|
return "-misc-fixed-medium-r-normal--13-*";
|
|
}
|
|
)GEN";
|
|
|
|
// AutoSize helper, emitted into generated code when a widget has
|
|
// autosize=true (Phase 1, Flag 11): resize to fit the caption/text,
|
|
// measured with the widget's resolved style font.
|
|
static const char* kApplyAutosize = R"GEN(// AutoSize (Phase 1, Flag 11): resize a widget to fit its caption/text.
|
|
static void apply_autosize(lg::IWidget* w, SStyle_Manager& styles,
|
|
const std::string& style_name, int x, int y,
|
|
int minw, int minh, int maxw, int maxh) {
|
|
std::string text = w->get_text();
|
|
if (text.empty()) return;
|
|
SStyle st = styles.resolve(style_name);
|
|
XFontStruct* f = st.font_;
|
|
if (!f) return;
|
|
size_t best_start = 0, best_len = 0, cur_start = 0;
|
|
int lines = 1;
|
|
for (size_t i = 0; i <= text.size(); ++i) {
|
|
if (i == text.size() || text[i] == '\n') {
|
|
size_t len = i - cur_start;
|
|
if (len > best_len) { best_len = len; best_start = cur_start; }
|
|
if (i != text.size()) { lines++; cur_start = i + 1; }
|
|
}
|
|
}
|
|
int ww = XTextWidth(f, text.c_str() + best_start, (int)best_len) + 16;
|
|
int hh = (f->ascent + f->descent) * lines + 8;
|
|
if (minw > 0 && ww < minw) ww = minw;
|
|
if (minh > 0 && hh < minh) hh = minh;
|
|
if (maxw > 0 && ww > maxw) ww = maxw;
|
|
if (maxh > 0 && hh > maxh) hh = maxh;
|
|
if (ww < 24) ww = 24;
|
|
if (hh < 16) hh = 16;
|
|
w->set_bounds(x, y, ww, hh);
|
|
}
|
|
)GEN";
|
|
|
|
// ------------------------------------------------------- main.cpp emitter
|
|
|
|
static std::string emit_main_cpp(const Project& project,
|
|
const std::vector<Widget>& widgets) {
|
|
std::string cls = sanitize_class(project.class_name);
|
|
std::vector<MenuDef> menus = parse_menus(project.menubar);
|
|
const int menubar_h = menus.empty() ? 0 : 28;
|
|
int win_w = project.win_width > 0 ? project.win_width : 800;
|
|
int win_h = project.win_height > 0 ? project.win_height : 600;
|
|
|
|
// Resolve every widget to its XFrame class first; unmapped types
|
|
// are skipped with a comment (generation still succeeds).
|
|
struct Resolved {
|
|
const Widget* w;
|
|
XFrameMap m;
|
|
std::string var;
|
|
};
|
|
std::vector<Resolved> resolved;
|
|
std::vector<std::string> skipped;
|
|
for (const Widget& w : widgets) {
|
|
const XFrameMap* m = find_map(w.type);
|
|
if (m) {
|
|
resolved.push_back(Resolved{&w, *m, sanitize_ident(w.name)});
|
|
} else if (looks_like_class(w.type)) {
|
|
XFrameMap direct{w.type.c_str(), w.type.c_str(),
|
|
"", "", false, false};
|
|
resolved.push_back(Resolved{&w, direct, sanitize_ident(w.name)});
|
|
} else {
|
|
skipped.push_back(w.name + " (type \"" + w.type + "\")");
|
|
}
|
|
}
|
|
|
|
// Phase 1: which generated-code helpers are needed. Computed over
|
|
// the resolved widgets only, so an emitted helper is always used
|
|
// (an unused static function would warn under -Wall -Wextra).
|
|
bool need_font_helper = false;
|
|
bool need_autosize_helper = false;
|
|
bool need_anchors = !menus.empty(); // the menubar spans the width
|
|
for (const Resolved& r : resolved) {
|
|
if (widget_font_custom(*r.w)) need_font_helper = true;
|
|
if (prop_bool(*r.w, "autosize", false)) need_autosize_helper = true;
|
|
Anchors a = effective_anchors(*r.w);
|
|
if (a.right || a.bottom) need_anchors = true;
|
|
}
|
|
|
|
std::ostringstream o;
|
|
o << "// Generated by LightGUI (C++/XFrame) — step 4, unified canvas.\n"
|
|
<< "// A plain X11/XFrame program: no GTK. Build with the generated\n"
|
|
<< "// CMakeLists.txt (cmake -S . -B build && cmake --build build)\n"
|
|
<< "// or the generated Makefile (make). Both need the XFrame widget\n"
|
|
<< "// sources; see LIGHTGUI_WIDGETS_DIR in CMakeLists.txt / Makefile.\n"
|
|
<< "//\n"
|
|
<< "// The window is \"" << esc_c(project.title) << "\" (" << win_w
|
|
<< "x" << win_h << ") with " << resolved.size() << " widget(s)";
|
|
if (!skipped.empty()) {
|
|
o << "; skipped (no XFrame class):";
|
|
for (const std::string& s : skipped) o << " " << s << ";";
|
|
}
|
|
o << ".\n\n"
|
|
<< "#include \"common/registry.h\"\n\n"
|
|
<< "#include <X11/Xlib.h>\n"
|
|
<< "#include <X11/Xutil.h>\n\n"
|
|
<< "#include <cstdio>\n"
|
|
<< "#include <cstdlib>\n";
|
|
// lightgui_pick_font uses std::tolower (only when a widget has a
|
|
// custom font; otherwise the include would be unused).
|
|
if (need_font_helper) o << "#include <cctype>\n";
|
|
o << "#include <memory>\n"
|
|
<< "#include <string>\n"
|
|
<< "#include <vector>\n\n";
|
|
// alloc_rgb is only emitted when the window background needs it;
|
|
// otherwise it would warn as unused under -Wall -Wextra.
|
|
int bg_r = 0, bg_g = 0, bg_b = 0;
|
|
bool has_bg = parse_color(project.background, bg_r, bg_g, bg_b);
|
|
if (has_bg) {
|
|
o << "// Allocate an RGB colour on the default colormap.\n"
|
|
<< "static unsigned long alloc_rgb(Display* display, int screen,\n"
|
|
<< " int r, int g, int b) {\n"
|
|
<< " XColor c;\n"
|
|
<< " c.red = (unsigned short)(r << 8);\n"
|
|
<< " c.green = (unsigned short)(g << 8);\n"
|
|
<< " c.blue = (unsigned short)(b << 8);\n"
|
|
<< " if (XAllocColor(display, DefaultColormap(display, screen), &c))\n"
|
|
<< " return c.pixel;\n"
|
|
<< " return WhitePixel(display, screen);\n"
|
|
<< "}\n\n";
|
|
}
|
|
|
|
// Event handler stubs (free functions; wired to the widgets below).
|
|
for (const Resolved& r : resolved) emit_event_stubs(o, *r.w);
|
|
if (!menus.empty()) {
|
|
for (const MenuDef& m : menus) {
|
|
o << "void on_menubar_activate_" << id_part(m.label) << "() {\n"
|
|
<< " std::printf(\"EVENT menubar " << esc_c(m.label)
|
|
<< "\\n\");\n}\n\n";
|
|
}
|
|
}
|
|
|
|
if (need_font_helper) o << kLightguiPickFont << "\n";
|
|
if (need_autosize_helper) o << kApplyAutosize << "\n";
|
|
|
|
o << "int main() {\n"
|
|
<< " Display* display = XOpenDisplay(nullptr);\n"
|
|
<< " if (!display) { std::fprintf(stderr, \"cannot open display\\n\"); return 1; }\n"
|
|
<< " int screen = DefaultScreen(display);\n"
|
|
<< " Window root = RootWindow(display, screen);\n";
|
|
// 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 << ")";
|
|
else
|
|
o << "WhitePixel(display, screen)";
|
|
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"
|
|
<< " Atom delete_window = XInternAtom(display, \"WM_DELETE_WINDOW\", False);\n"
|
|
<< " XSetWMProtocols(display, window, &delete_window, 1);\n"
|
|
<< " XMapWindow(display, window);\n"
|
|
<< " GC gc = DefaultGC(display, screen);\n"
|
|
<< " SStyle_Manager styles(display, window, screen, gc);\n"
|
|
<< " styles.add_style_ex(\"default\", Srgb{225, 225, 225}, "
|
|
"Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "
|
|
"\"-misc-fixed-medium-r-normal--13-*\");\n"
|
|
<< " styles.add_style_ex(\"dark\", Srgb{45, 45, 48}, "
|
|
"Srgb{20, 20, 22}, Srgb{200, 200, 200}, Srgb{240, 240, 240}, 6, 1, "
|
|
"\"-misc-fixed-medium-r-normal--13-*\");\n"
|
|
<< " styles.set_active_style_byName(\"default\");\n";
|
|
emit_widget_styles(o, widgets);
|
|
|
|
// Project menu bar (if any): a GtkMenuBar across the top; placed
|
|
// widgets shift down by its height, as in the old GTK window
|
|
// (menu bar packed above the fixed area).
|
|
if (!menus.empty()) {
|
|
o << " lg::Holder<GtkMenuBar> menubar(display, screen, window, gc, "
|
|
"&styles, 0, 0, " << win_w << ", " << menubar_h << ");\n";
|
|
for (const MenuDef& m : menus) {
|
|
o << " menubar.w.add_item(\"" << esc_c(m.label) << "\", {";
|
|
bool first = true;
|
|
for (const std::string& item : m.items) {
|
|
if (item == "-") continue; // separator: no XFrame equivalent
|
|
if (!first) o << ", ";
|
|
first = false;
|
|
o << "\"" << esc_c(item) << "\"";
|
|
}
|
|
o << "});\n";
|
|
}
|
|
o << " menubar.w.on_activate = [](int menu, int item) {\n"
|
|
<< " (void)item;\n"
|
|
<< " switch (menu) {\n";
|
|
for (size_t i = 0; i < menus.size(); ++i)
|
|
o << " case " << i << ": on_menubar_activate_"
|
|
<< id_part(menus[i].label) << "(); break;\n";
|
|
o << " default: break;\n"
|
|
<< " }\n"
|
|
<< " };\n";
|
|
}
|
|
|
|
// RadioButton groups (Phase 2): one shared vector per group id;
|
|
// each button in the group calls set_group on it, so turning one
|
|
// on turns the others off (GtkRadioButton::set_active).
|
|
{
|
|
std::vector<int> groups;
|
|
for (const Resolved& r : resolved) {
|
|
std::string kind = xframe_type_key(r.w->type);
|
|
if ((kind.empty() ? r.w->type : kind) == "Radiobutton") {
|
|
int g = prop_int(*r.w, "group", 0);
|
|
if (g != 0 &&
|
|
std::find(groups.begin(), groups.end(), g) == groups.end())
|
|
groups.push_back(g);
|
|
}
|
|
}
|
|
for (int g : groups)
|
|
o << " std::vector<GtkRadioButton*> radio_group_" << g
|
|
<< ";\n";
|
|
}
|
|
|
|
// Widgets, in design order (later = on top for event dispatch).
|
|
for (const Resolved& r : resolved) {
|
|
const Widget& w = *r.w;
|
|
o << " lg::Holder<" << qualified_class(r.m.cls) << "> " << r.var
|
|
<< "(display, screen, window, gc, &styles, " << w.x << ", "
|
|
<< (w.y + menubar_h) << ", " << w.width << ", " << w.height
|
|
<< ");\n";
|
|
emit_widget_props(o, w, r.m, r.var);
|
|
emit_event_wiring(o, w, r.var);
|
|
if (prop_bool(w, "autosize", false)) {
|
|
std::string sty =
|
|
style_for(w, r.m).needed ? r.var + "_style" : "";
|
|
o << " apply_autosize(&" << r.var << ", styles, \"" << sty
|
|
<< "\", " << w.x << ", " << (w.y + menubar_h) << ", "
|
|
<< prop_int(w, "min-width", 0) << ", "
|
|
<< prop_int(w, "min-height", 0) << ", "
|
|
<< prop_int(w, "max-width", 0) << ", "
|
|
<< prop_int(w, "max-height", 0) << ");\n";
|
|
}
|
|
}
|
|
|
|
o << " std::vector<lg::IWidget*> widgets = {";
|
|
bool first = true;
|
|
if (!menus.empty()) {
|
|
o << " &menubar";
|
|
first = false;
|
|
}
|
|
for (const Resolved& r : resolved) {
|
|
if (!first) o << ",";
|
|
first = false;
|
|
o << " &" << r.var;
|
|
}
|
|
o << " };\n";
|
|
if (need_anchors) {
|
|
o << " // Anchors (Phase 1, Flag 1): minimal anchor layout. "
|
|
"Each anchored widget is repositioned/resized from its "
|
|
"design geometry when the window resizes; top+left alone "
|
|
"is static and needs no code.\n"
|
|
<< " auto apply_anchors = [&](int new_w, int new_h) {\n";
|
|
// Silence -Wunused-parameter when the lambda body uses only
|
|
// one of the two sizes (menubar-only designs use new_w alone;
|
|
// bottom-only anchor sets use new_h alone).
|
|
{
|
|
bool uses_w = !menus.empty(), uses_h = false;
|
|
for (const Resolved& r : resolved) {
|
|
Anchors a = effective_anchors(*r.w);
|
|
if (a.right) uses_w = true;
|
|
if (a.bottom) uses_h = true;
|
|
}
|
|
if (!uses_w) o << " (void)new_w;\n";
|
|
if (!uses_h) o << " (void)new_h;\n";
|
|
}
|
|
if (!menus.empty()) {
|
|
o << " menubar.set_bounds(0, 0, new_w, " << menubar_h
|
|
<< ");\n";
|
|
}
|
|
for (const Resolved& r : resolved) {
|
|
const Widget& w = *r.w;
|
|
Anchors a = effective_anchors(w);
|
|
if (!a.right && !a.bottom) continue;
|
|
int x = w.x, y = w.y + menubar_h;
|
|
std::string xs = std::to_string(x), ys = std::to_string(y);
|
|
std::string ws = std::to_string(w.width);
|
|
std::string hs = std::to_string(w.height);
|
|
if (a.right && a.left)
|
|
ws += " + (new_w - " + std::to_string(win_w) + ")";
|
|
else if (a.right)
|
|
xs += " + (new_w - " + std::to_string(win_w) + ")";
|
|
if (a.bottom && a.top)
|
|
hs += " + (new_h - " + std::to_string(win_h) + ")";
|
|
else if (a.bottom)
|
|
ys += " + (new_h - " + std::to_string(win_h) + ")";
|
|
o << " { // " << r.var << ": anchors "
|
|
<< anchor_label(a) << "\n"
|
|
<< " int _x = " << xs << ";\n"
|
|
<< " int _y = " << ys << ";\n"
|
|
<< " int _w = " << ws << ";\n"
|
|
<< " int _h = " << hs << ";\n";
|
|
if (prop_int(w, "min-width", 0) > 0)
|
|
o << " if (_w < " << prop_int(w, "min-width", 0)
|
|
<< ") _w = " << prop_int(w, "min-width", 0) << ";\n";
|
|
if (prop_int(w, "max-width", 0) > 0)
|
|
o << " if (_w > " << prop_int(w, "max-width", 0)
|
|
<< ") _w = " << prop_int(w, "max-width", 0) << ";\n";
|
|
if (prop_int(w, "min-height", 0) > 0)
|
|
o << " if (_h < " << prop_int(w, "min-height", 0)
|
|
<< ") _h = " << prop_int(w, "min-height", 0) << ";\n";
|
|
if (prop_int(w, "max-height", 0) > 0)
|
|
o << " if (_h > " << prop_int(w, "max-height", 0)
|
|
<< ") _h = " << prop_int(w, "max-height", 0) << ";\n";
|
|
o << " if (_w < 24) _w = 24;\n"
|
|
<< " if (_h < 16) _h = 16;\n"
|
|
<< " " << r.var << ".set_bounds(_x, _y, _w, _h);\n"
|
|
<< " }\n";
|
|
}
|
|
o << " };\n";
|
|
}
|
|
o << " auto redraw_all = [&]() {\n"
|
|
<< " XClearWindow(display, window);\n"
|
|
<< " for (lg::IWidget* wd : widgets) wd->draw();\n"
|
|
<< " XFlush(display);\n"
|
|
<< " };\n"
|
|
<< " redraw_all();\n"
|
|
<< " bool running = true;\n"
|
|
<< " // Task 4: event routing. pressed_widget is the widget that\n"
|
|
<< " // received the ButtonPress (release + drag motion go there);\n"
|
|
<< " // focused_widget is the last widget clicked (keys go there).\n"
|
|
<< " lg::IWidget* pressed_widget = nullptr;\n"
|
|
<< " lg::IWidget* focused_widget = nullptr;\n"
|
|
<< " while (running) {\n"
|
|
<< " XEvent event;\n"
|
|
<< " XNextEvent(display, &event);\n"
|
|
<< " bool handled = false;\n"
|
|
<< " switch (event.type) {\n"
|
|
<< " case Expose:\n"
|
|
<< " handled = true;\n"
|
|
<< " break;\n"
|
|
<< " case ButtonPress:\n"
|
|
<< " // Topmost widget first (reverse design order).\n"
|
|
<< " for (auto it = widgets.rbegin(); it != widgets.rend(); ++it) {\n"
|
|
<< " if ((*it)->contains(event.xbutton.x, event.xbutton.y)) {\n"
|
|
<< " handled = (*it)->on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);\n"
|
|
<< " if (handled) { pressed_widget = *it; focused_widget = *it; }\n"
|
|
<< " break;\n"
|
|
<< " }\n"
|
|
<< " }\n"
|
|
<< " break;\n"
|
|
<< " case ButtonRelease:\n"
|
|
<< " // Release goes to the widget that got the press,\n"
|
|
<< " // even if the pointer moved off it.\n"
|
|
<< " if (pressed_widget) {\n"
|
|
<< " handled = pressed_widget->on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);\n"
|
|
<< " pressed_widget = nullptr;\n"
|
|
<< " }\n"
|
|
<< " break;\n"
|
|
<< " case MotionNotify:\n"
|
|
<< " if (pressed_widget) {\n"
|
|
<< " // Drag: motion goes to the pressed widget.\n"
|
|
<< " handled = pressed_widget->on_motion(event.xmotion.x, event.xmotion.y);\n"
|
|
<< " } else {\n"
|
|
<< " // Hover: topmost widget under the pointer.\n"
|
|
<< " for (auto it = widgets.rbegin(); it != widgets.rend(); ++it) {\n"
|
|
<< " if ((*it)->contains(event.xmotion.x, event.xmotion.y)) {\n"
|
|
<< " handled = (*it)->on_motion(event.xmotion.x, event.xmotion.y);\n"
|
|
<< " break;\n"
|
|
<< " }\n"
|
|
<< " }\n"
|
|
<< " }\n"
|
|
<< " break;\n"
|
|
<< " case KeyPress: {\n"
|
|
<< " char buffer[32];\n"
|
|
<< " KeySym key = 0;\n"
|
|
<< " int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);\n"
|
|
<< " buffer[n] = 0;\n"
|
|
<< " if (focused_widget)\n"
|
|
<< " handled = focused_widget->on_key(key, buffer);\n"
|
|
<< " break;\n"
|
|
<< " }\n"
|
|
<< " case ConfigureNotify:\n";
|
|
if (need_anchors)
|
|
o << " apply_anchors(event.xconfigure.width, event.xconfigure.height);\n";
|
|
o << " handled = true;\n"
|
|
<< " break;\n"
|
|
<< " case ClientMessage:\n"
|
|
<< " if ((Atom)event.xclient.data.l[0] == delete_window)\n"
|
|
<< " running = false;\n"
|
|
<< " break;\n"
|
|
<< " default:\n"
|
|
<< " break;\n"
|
|
<< " }\n"
|
|
<< " if (handled) redraw_all();\n"
|
|
<< " }\n"
|
|
<< " XCloseDisplay(display);\n"
|
|
<< " return 0;\n"
|
|
<< "}\n";
|
|
return o.str();
|
|
}
|
|
|
|
// ------------------------------------------------------- build files
|
|
|
|
static std::string emit_cmake_lists(const std::string& cls) {
|
|
std::ostringstream o;
|
|
o << "# Generated by LightGUI (C++/XFrame).\n"
|
|
<< "# Build: cmake -S . -B build && cmake --build build\n"
|
|
<< "# The XFrame widget headers live in the installed location; point at\n"
|
|
<< "# them with -DLIGHTGUI_WIDGETS_DIR=<path> if they are not at the\n"
|
|
<< "# default below.\n"
|
|
<< "cmake_minimum_required(VERSION 3.20)\n"
|
|
<< "project(" << cls << " CXX)\n"
|
|
<< "set(CMAKE_CXX_STANDARD 17)\n"
|
|
<< "set(CMAKE_CXX_STANDARD_REQUIRED ON)\n"
|
|
<< "set(LIGHTGUI_WIDGETS_DIR \"/usr/local/include/lightgui\" CACHE PATH "
|
|
"\"LightGUI XFrame widget sources (widgets/common/registry.h)\")\n"
|
|
<< "if(NOT EXISTS \"${LIGHTGUI_WIDGETS_DIR}/common/registry.h\")\n"
|
|
<< " message(FATAL_ERROR \"XFrame widget sources not found at "
|
|
"${LIGHTGUI_WIDGETS_DIR} - pass "
|
|
"-DLIGHTGUI_WIDGETS_DIR=<lightgui-repo>/widgets\")\n"
|
|
<< "endif()\n"
|
|
<< "find_package(X11 REQUIRED)\n"
|
|
<< "add_executable(app main.cpp)\n"
|
|
<< "target_include_directories(app PRIVATE ${LIGHTGUI_WIDGETS_DIR})\n"
|
|
<< "target_link_libraries(app PRIVATE X11::X11)\n";
|
|
return o.str();
|
|
}
|
|
|
|
static std::string emit_makefile() {
|
|
std::ostringstream o;
|
|
o << "# Generated by LightGUI (C++/XFrame).\n"
|
|
<< "# Build: make [WIDGETS_DIR=<installed-headers>]\n"
|
|
<< "CXX ?= g++\n"
|
|
<< "CXXFLAGS ?= -O2 -Wall -std=c++17\n"
|
|
<< "WIDGETS_DIR ?= /usr/local/include/lightgui\n"
|
|
<< "X11FLAGS := $(shell pkg-config --cflags x11)\n"
|
|
<< "X11LIBS := $(shell pkg-config --libs x11)\n\n"
|
|
<< "app: main.cpp\n"
|
|
<< "\t$(CXX) $(CXXFLAGS) -I$(WIDGETS_DIR) $(X11FLAGS) -o $@ main.cpp $(X11LIBS)\n\n"
|
|
<< "clean:\n"
|
|
<< "\trm -f app\n\n"
|
|
<< ".PHONY: clean\n";
|
|
return o.str();
|
|
}
|
|
|
|
static std::string emit_readme(const Project& project,
|
|
const std::vector<Widget>& widgets) {
|
|
std::ostringstream o;
|
|
o << "# " << project.title << "\n\n"
|
|
<< "Generated by LightGUI (C++/XFrame) — a plain X11/XFrame program, no GTK.\n\n"
|
|
<< "## Build\n\n"
|
|
<< "```sh\n"
|
|
<< "cmake -S . -B build && cmake --build build # or: make\n"
|
|
<< "```\n\n"
|
|
<< "Both need the XFrame widget sources from the LightGUI repo\n"
|
|
<< "(`widgets/common/registry.h`). Default location is\n"
|
|
<< "`/usr/local/include/lightgui`; override with\n"
|
|
<< "`-DLIGHTGUI_WIDGETS_DIR=<path>` (CMake) or\n"
|
|
<< "`make WIDGETS_DIR=<path>`.\n\n"
|
|
<< "## Run\n\n"
|
|
<< "```sh\n"
|
|
<< "./build/app # or: ./app\n"
|
|
<< "```\n\n"
|
|
<< "Close the window (or its close button) to quit.\n\n"
|
|
<< "## Contents\n\n"
|
|
<< "- `main.cpp` — the whole app: display/window setup, styles, one\n"
|
|
<< " `lg::Holder<T>` per widget, property setup, event stubs, X event loop.\n"
|
|
<< "- `CMakeLists.txt`, `Makefile` — build it.\n\n"
|
|
<< "## Notes\n\n"
|
|
<< "- Widgets: " << widgets.size() << " placed. Each is constructed\n"
|
|
<< " as its XFrame class (e.g. `GtkButton`) with the geometry and\n"
|
|
<< " properties from the design; colours and state use the widgets'\n"
|
|
<< " getter/setter API where one exists, otherwise a per-widget\n"
|
|
<< " style clone.\n"
|
|
<< "- A few designer props have no setter on the mapped XFrame class\n"
|
|
<< " (e.g. `digits` on a scale, `inverted`, tooltip text) and are\n"
|
|
<< " left out; visible losses (Shape, Canvas, Plot line colour,\n"
|
|
<< " StockChart CSV/indicators) are noted in comments in `main.cpp`.\n"
|
|
<< "- Connected signals are wired to the widgets' `std::function`\n"
|
|
<< " callbacks; each stub prints `EVENT <Widget> <signal>`.\n";
|
|
return o.str();
|
|
}
|
|
|
|
// ---------------------------------------------------------------- driver
|
|
|
|
static bool write_file(const fs::path& path, const std::string& content,
|
|
GenResult& r) {
|
|
std::ofstream f(path);
|
|
if (!f) {
|
|
r.error = "cannot write " + path.string();
|
|
return false;
|
|
}
|
|
f << content;
|
|
if (!f) {
|
|
r.error = "write failed for " + path.string();
|
|
return false;
|
|
}
|
|
r.files.push_back(path.string());
|
|
return true;
|
|
}
|
|
|
|
GenResult generate_project(const Project& project,
|
|
const std::vector<Widget>& widgets,
|
|
const std::string& out_dir) {
|
|
GenResult r;
|
|
std::error_code ec;
|
|
fs::create_directories(out_dir, ec);
|
|
if (ec) {
|
|
r.error = "cannot create " + out_dir + ": " + ec.message();
|
|
return r;
|
|
}
|
|
std::string cls = sanitize_class(project.class_name);
|
|
fs::path dir(out_dir);
|
|
if (!write_file(dir / "main.cpp", emit_main_cpp(project, widgets), r))
|
|
return r;
|
|
if (!write_file(dir / "CMakeLists.txt", emit_cmake_lists(cls), r))
|
|
return r;
|
|
if (!write_file(dir / "Makefile", emit_makefile(), r)) return r;
|
|
if (!write_file(dir / "README.md", emit_readme(project, widgets), r))
|
|
return r;
|
|
r.ok = true;
|
|
return r;
|
|
}
|