DVX_GUI/core/widgetClass.c

49 lines
1.8 KiB
C

// widgetClass.c -- Widget class table and dynamic registration
//
// The widgetClassTable[] is the central dispatch table for the widget
// system. All entries start NULL and are filled at runtime by widget
// DXE registration functions (wgtBoxRegister, wgtButtonRegister, etc.).
// The loader loads each widget DXE and calls its register function
// before starting the shell.
//
// This file contains only the table and the dynamic registration API.
// All class definitions live in their respective widget .c files.
#include "widgetInternal.h"
// ============================================================
// Class table -- indexed by WidgetTypeE
// ============================================================
//
// Every entry is NULL until the corresponding widget DXE calls its
// registration function (e.g. wgtBoxRegister sets VBox/HBox/Frame).
// Sized WGT_MAX_TYPES to accommodate both built-in widget types
// (0..WGT_TYPE_BUILTIN_COUNT-1) and dynamically registered types
// (WGT_TYPE_DYNAMIC_BASE..WGT_MAX_TYPES-1).
const WidgetClassT *widgetClassTable[WGT_MAX_TYPES];
// ============================================================
// wgtRegisterClass -- register a dynamic widget type at runtime
// ============================================================
//
// External DXE plugins call this to add new widget types without
// modifying the core library. Returns the assigned type ID
// (>= WGT_TYPE_DYNAMIC_BASE) so the caller can use it with
// widgetAlloc(). Returns -1 if the table is full.
int32_t wgtRegisterClass(const WidgetClassT *wclass) {
if (!wclass) {
return -1;
}
for (int32_t i = WGT_TYPE_DYNAMIC_BASE; i < WGT_MAX_TYPES; i++) {
if (!widgetClassTable[i]) {
widgetClassTable[i] = wclass;
return i;
}
}
return -1;
}