110 lines
2.5 KiB
C
110 lines
2.5 KiB
C
// ideToolbox.c -- DVX BASIC form designer toolbox window
|
|
//
|
|
// A small floating window with buttons for each control type.
|
|
// Clicking a tool sets the designer's activeTool.
|
|
|
|
#include "ideToolbox.h"
|
|
#include "dvxWm.h"
|
|
#include "widgetBox.h"
|
|
#include "widgetButton.h"
|
|
|
|
#include <string.h>
|
|
|
|
// ============================================================
|
|
// Constants
|
|
// ============================================================
|
|
|
|
#define TBX_WIN_W 72
|
|
#define TBX_WIN_H 320
|
|
#define TBX_BTN_H 20
|
|
|
|
// ============================================================
|
|
// Module state
|
|
// ============================================================
|
|
|
|
static DsgnStateT *sDs = NULL;
|
|
|
|
// ============================================================
|
|
// Tool labels (short names for buttons)
|
|
// ============================================================
|
|
|
|
static const char *sToolLabels[TOOL_COUNT] = {
|
|
"Pointer",
|
|
"Button",
|
|
"Label",
|
|
"TextBox",
|
|
"CheckBox",
|
|
"Option",
|
|
"Frame",
|
|
"ListBox",
|
|
"ComboBox",
|
|
"HScroll",
|
|
"VScroll",
|
|
"Timer",
|
|
"Picture",
|
|
"Image"
|
|
};
|
|
|
|
// ============================================================
|
|
// Callbacks
|
|
// ============================================================
|
|
|
|
static void onToolClick(WidgetT *w) {
|
|
if (!sDs) {
|
|
return;
|
|
}
|
|
|
|
int32_t toolIdx = (int32_t)(intptr_t)w->userData;
|
|
|
|
if (toolIdx >= 0 && toolIdx < TOOL_COUNT) {
|
|
sDs->activeTool = (DsgnToolE)toolIdx;
|
|
sDs->mode = (toolIdx == TOOL_POINTER) ? DSGN_IDLE : DSGN_PLACING;
|
|
}
|
|
}
|
|
|
|
|
|
static void onTbxClose(WindowT *win) {
|
|
// Don't allow closing the toolbox independently
|
|
(void)win;
|
|
}
|
|
|
|
|
|
// ============================================================
|
|
// tbxCreate
|
|
// ============================================================
|
|
|
|
WindowT *tbxCreate(AppContextT *ctx, DsgnStateT *ds) {
|
|
sDs = ds;
|
|
|
|
WindowT *win = dvxCreateWindow(ctx, "Toolbox", 0, 30, TBX_WIN_W, TBX_WIN_H, false);
|
|
|
|
if (!win) {
|
|
return NULL;
|
|
}
|
|
|
|
win->onClose = onTbxClose;
|
|
|
|
WidgetT *root = wgtInitWindow(ctx, win);
|
|
|
|
for (int32_t i = 0; i < TOOL_COUNT; i++) {
|
|
WidgetT *btn = wgtButton(root, sToolLabels[i]);
|
|
btn->onClick = onToolClick;
|
|
btn->userData = (void *)(intptr_t)i;
|
|
}
|
|
|
|
dvxFitWindow(ctx, win);
|
|
return win;
|
|
}
|
|
|
|
|
|
// ============================================================
|
|
// tbxDestroy
|
|
// ============================================================
|
|
|
|
void tbxDestroy(AppContextT *ctx, WindowT *win) {
|
|
if (win) {
|
|
dvxDestroyWindow(ctx, win);
|
|
}
|
|
|
|
sDs = NULL;
|
|
}
|