// ideDesigner.h -- DVX BASIC form designer // // Design-time data model and design surface for visual form editing. // Controls are stored as pure data (not live widgets) and rendered // onto a Canvas widget. The designer reads and writes .frm files. #ifndef IDE_DESIGNER_H #define IDE_DESIGNER_H #include "dvxApp.h" #include "dvxWidget.h" #include "widgetCanvas.h" #include "stb_ds_wrap.h" #include #include // ============================================================ // Limits // ============================================================ #define DSGN_MAX_NAME 32 #define DSGN_MAX_TEXT 256 #define DSGN_MAX_PROPS 32 #define DSGN_GRID_SIZE 8 #define DSGN_HANDLE_SIZE 6 // ============================================================ // Design-time property (stored as key=value strings) // ============================================================ typedef struct { char name[DSGN_MAX_NAME]; char value[DSGN_MAX_TEXT]; } DsgnPropT; // ============================================================ // Design-time control // ============================================================ typedef struct { char name[DSGN_MAX_NAME]; char typeName[DSGN_MAX_NAME]; int32_t left; int32_t top; int32_t width; int32_t height; int32_t tabIndex; DsgnPropT props[DSGN_MAX_PROPS]; int32_t propCount; } DsgnControlT; // ============================================================ // Design-time form // ============================================================ typedef struct { char name[DSGN_MAX_NAME]; char caption[DSGN_MAX_TEXT]; int32_t width; int32_t height; DsgnControlT *controls; // stb_ds dynamic array bool dirty; } DsgnFormT; // ============================================================ // Toolbox tool IDs // ============================================================ typedef enum { TOOL_POINTER = 0, TOOL_BUTTON, TOOL_LABEL, TOOL_TEXTBOX, TOOL_CHECKBOX, TOOL_OPTION, TOOL_FRAME, TOOL_LISTBOX, TOOL_COMBOBOX, TOOL_HSCROLL, TOOL_VSCROLL, TOOL_TIMER, TOOL_PICTURE, TOOL_IMAGE, TOOL_COUNT } DsgnToolE; // ============================================================ // Grab handle IDs // ============================================================ typedef enum { HANDLE_NONE = -1, HANDLE_NW = 0, HANDLE_N, HANDLE_NE, HANDLE_E, HANDLE_SE, HANDLE_S, HANDLE_SW, HANDLE_W, HANDLE_COUNT = 8 } DsgnHandleE; // ============================================================ // Interaction mode // ============================================================ typedef enum { DSGN_IDLE, DSGN_PLACING, DSGN_DRAWING, DSGN_MOVING, DSGN_RESIZING } DsgnModeE; // ============================================================ // Designer state // ============================================================ typedef struct { DsgnFormT *form; int32_t selectedIdx; // -1 = form itself selected DsgnToolE activeTool; DsgnModeE mode; DsgnHandleE activeHandle; int32_t dragStartX; int32_t dragStartY; int32_t dragOrigLeft; int32_t dragOrigTop; int32_t dragOrigWidth; int32_t dragOrigHeight; int32_t drawX; // rubber-band start for new control int32_t drawY; bool showGrid; bool snapToGrid; WidgetT *canvas; AppContextT *ctx; } DsgnStateT; // ============================================================ // API // ============================================================ // Initialize designer state. void dsgnInit(DsgnStateT *ds, AppContextT *ctx); // Set the canvas widget for rendering. void dsgnSetCanvas(DsgnStateT *ds, WidgetT *canvas); // Load a .frm file into the designer. bool dsgnLoadFrm(DsgnStateT *ds, const char *source, int32_t sourceLen); // Save the designer form to .frm text format. // Returns the number of bytes written (excluding null), or -1 on error. int32_t dsgnSaveFrm(const DsgnStateT *ds, char *buf, int32_t bufSize); // Create a new blank form. void dsgnNewForm(DsgnStateT *ds, const char *name); // Repaint the design surface. void dsgnPaint(DsgnStateT *ds); // Handle mouse click on the design surface. void dsgnOnMouse(DsgnStateT *ds, int32_t x, int32_t y, bool drag); // Handle key press in design view. void dsgnOnKey(DsgnStateT *ds, int32_t key); // Get the name of the selected control (or form name if nothing selected). const char *dsgnSelectedName(const DsgnStateT *ds); // Get the default event name for a control type. const char *dsgnDefaultEvent(const char *typeName); // Get the VB type name for a tool ID. const char *dsgnToolTypeName(DsgnToolE tool); // Auto-generate a unique control name for the given type. void dsgnAutoName(const DsgnStateT *ds, const char *typeName, char *buf, int32_t bufSize); // Free designer resources. void dsgnFree(DsgnStateT *ds); #endif // IDE_DESIGNER_H