// ideProperties.c -- DVX BASIC form designer properties window // // A floating window with a two-column list showing property names // and values for the currently selected control. Double-clicking // a value opens an input dialog to edit it. #include "ideProperties.h" #include "dvxDialog.h" #include "dvxWm.h" #include "widgetBox.h" #include "widgetLabel.h" #include "widgetTextInput.h" #include #include #include #include // ============================================================ // Constants // ============================================================ #define PRP_WIN_W 200 #define PRP_WIN_H 320 #define PRP_MAX_ROWS 64 // ============================================================ // Module state // ============================================================ static DsgnStateT *sDs = NULL; static WindowT *sPrpWin = NULL; static WidgetT *sListArea = NULL; // TextArea showing properties as text static AppContextT *sPrpCtx = NULL; // ============================================================ // Prototypes // ============================================================ static void onPrpClose(WindowT *win); // ============================================================ // onPrpClose // ============================================================ static void onPrpClose(WindowT *win) { (void)win; } // ============================================================ // prpCreate // ============================================================ WindowT *prpCreate(AppContextT *ctx, DsgnStateT *ds) { sDs = ds; sPrpCtx = ctx; // Position at right edge of screen int32_t winX = ctx->display.width - PRP_WIN_W - 10; WindowT *win = dvxCreateWindow(ctx, "Properties", winX, 30, PRP_WIN_W, PRP_WIN_H, false); if (!win) { return NULL; } win->onClose = onPrpClose; sPrpWin = win; WidgetT *root = wgtInitWindow(ctx, win); // Properties displayed as a read-only text area (simple approach) sListArea = wgtTextArea(root, 4096); sListArea->weight = 100; sListArea->readOnly = true; prpRefresh(ds); return win; } // ============================================================ // prpDestroy // ============================================================ void prpDestroy(AppContextT *ctx, WindowT *win) { if (win) { dvxDestroyWindow(ctx, win); } sPrpWin = NULL; sListArea = NULL; sDs = NULL; } // ============================================================ // prpRefresh // ============================================================ void prpRefresh(DsgnStateT *ds) { if (!sListArea || !ds || !ds->form) { return; } char buf[4096]; int32_t pos = 0; if (ds->selectedIdx >= 0 && ds->selectedIdx < (int32_t)arrlen(ds->form->controls)) { DsgnControlT *ctrl = &ds->form->controls[ds->selectedIdx]; pos += snprintf(buf + pos, sizeof(buf) - pos, "%s (%s)\n", ctrl->name, ctrl->typeName); pos += snprintf(buf + pos, sizeof(buf) - pos, "---\n"); pos += snprintf(buf + pos, sizeof(buf) - pos, "Name = %s\n", ctrl->name); pos += snprintf(buf + pos, sizeof(buf) - pos, "Left = %d\n", (int)ctrl->left); pos += snprintf(buf + pos, sizeof(buf) - pos, "Top = %d\n", (int)ctrl->top); pos += snprintf(buf + pos, sizeof(buf) - pos, "Width = %d\n", (int)ctrl->width); pos += snprintf(buf + pos, sizeof(buf) - pos, "Height = %d\n", (int)ctrl->height); pos += snprintf(buf + pos, sizeof(buf) - pos, "TabIndex = %d\n", (int)ctrl->tabIndex); for (int32_t i = 0; i < ctrl->propCount; i++) { pos += snprintf(buf + pos, sizeof(buf) - pos, "%-8s = %s\n", ctrl->props[i].name, ctrl->props[i].value); } } else { pos += snprintf(buf + pos, sizeof(buf) - pos, "%s (Form)\n", ds->form->name); pos += snprintf(buf + pos, sizeof(buf) - pos, "---\n"); pos += snprintf(buf + pos, sizeof(buf) - pos, "Name = %s\n", ds->form->name); pos += snprintf(buf + pos, sizeof(buf) - pos, "Caption = %s\n", ds->form->caption); pos += snprintf(buf + pos, sizeof(buf) - pos, "Width = %d\n", (int)ds->form->width); pos += snprintf(buf + pos, sizeof(buf) - pos, "Height = %d\n", (int)ds->form->height); } wgtSetText(sListArea, buf); }