From edfa67e964399794a6c0aca29f5b3b5f465521db Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Sep 2025 09:14:57 +0000 Subject: [PATCH] prop git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@17 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Milsko/TypeDefs.h | 13 +++++++++++++ src/core.c | 28 +++++++++++++++++++++++++--- src/x11.c | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/Milsko/TypeDefs.h b/include/Milsko/TypeDefs.h index 78b7ad0..043825a 100644 --- a/include/Milsko/TypeDefs.h +++ b/include/Milsko/TypeDefs.h @@ -9,6 +9,16 @@ typedef struct _MilskoPoint { int y; } MilskoPoint; +typedef struct _MilskoTextKeyValue { + char* key; + char* value; +} MilskoTextKeyValue; + +typedef struct _MilskoIntegerKeyValue { + char* key; + int value; +} MilskoIntegerKeyValue; + typedef struct _MilskoClass* MilskoClass; #ifdef _MILSKO @@ -21,6 +31,9 @@ typedef struct _Milsko { HMILSKO parent; HMILSKO* children; MilskoClass class; + + MilskoTextKeyValue* text; + MilskoIntegerKeyValue* integer; }* HMILSKO; #else typedef void* HMILSKO; diff --git a/src/core.c b/src/core.c index eeaabb4..931ddb0 100644 --- a/src/core.c +++ b/src/core.c @@ -13,6 +13,12 @@ HMILSKO MilskoCreateWidget(MilskoClass class, HMILSKO parent, int x, int y, unsi if(parent != NULL) arrput(parent->children, h); + sh_new_strdup(h->text); + sh_new_strdup(h->integer); + + shdefault(h->text, NULL); + shdefault(h->integer, -1); + return h; } @@ -38,14 +44,23 @@ void MilskoDestroyWidget(HMILSKO handle) { } } MilskoLLDestroy(handle->lowlevel); + + shfree(handle->integer); + + for(i = 0; i < shlen(handle->text); i++) { + free(handle->text[i].value); + handle->text[i].value = NULL; + } + shfree(handle->text); + free(handle); } -MILSKODECL void MilskoStep(HMILSKO handle) { +void MilskoStep(HMILSKO handle) { MilskoLLNextEvent(handle->lowlevel); } -MILSKODECL int MilskoPending(HMILSKO handle) { +int MilskoPending(HMILSKO handle) { int i; for(i = 0; i < arrlen(handle->children); i++) { if(MilskoPending(handle->children[i])) return 1; @@ -53,7 +68,7 @@ MILSKODECL int MilskoPending(HMILSKO handle) { return MilskoLLPending(handle->lowlevel); } -MILSKODECL void MilskoLoop(HMILSKO handle) { +void MilskoLoop(HMILSKO handle) { while(1) { MilskoStep(handle); MilskoLLSleep(10); @@ -74,12 +89,19 @@ void MilskoSetInteger(HMILSKO handle, const char* key, int n) { if(strcmp(key, MilskoNheight) == 0) h = n; if(xy) MilskoLLSetXY(handle->lowlevel, x, y); if(wh) MilskoLLSetWH(handle->lowlevel, w, h); + } else { + shput(handle->integer, key, n); } } void MilskoSetText(HMILSKO handle, const char* key, const char* value) { if(strcmp(key, MilskoNtitle) == 0) { MilskoLLSetTitle(handle->lowlevel, value); + } else { + char* v = malloc(strlen(value) + 1); + strcpy(v, value); + + shput(handle->text, key, v); } } diff --git a/src/x11.c b/src/x11.c index 6ce0642..82ba7af 100644 --- a/src/x11.c +++ b/src/x11.c @@ -109,6 +109,6 @@ void MilskoLLSleep(int ms) { usleep(ms * 1000); } -MILSKODECL void MilskoLLSetTitle(HMILSKOLL handle, const char* title) { +void MilskoLLSetTitle(HMILSKOLL handle, const char* title) { XSetStandardProperties(handle->display, handle->window, title, "Milsko Widget Toolkit", None, (char**)NULL, 0, NULL); }