mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-06 17:39:45 +00:00
a
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@35 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <Milsko/Milsko.h>
|
#include <Milsko/Milsko.h>
|
||||||
|
|
||||||
void handler(MilskoWidget handle){
|
void handler(MilskoWidget handle, void* user_data, void* call_data){
|
||||||
printf("hello world!\n");
|
printf("hello world!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,9 +10,9 @@ int main(){
|
|||||||
MilskoWidget window = MilskoVaCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 400, 400,
|
MilskoWidget window = MilskoVaCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||||
MilskoNtitle, "hello world",
|
MilskoNtitle, "hello world",
|
||||||
NULL);
|
NULL);
|
||||||
MilskoWidget button = MilskoVaCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300,
|
MilskoWidget button = MilskoVaCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300, NULL);
|
||||||
MilskoNactivateHandler, handler,
|
|
||||||
NULL);
|
MilskoAddUserHandler(button, MilskoNactivateHandler, handler, NULL);
|
||||||
|
|
||||||
MilskoLoop(window);
|
MilskoLoop(window);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ MILSKODECL int MilskoPending(MilskoWidget handle);
|
|||||||
|
|
||||||
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
|
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
|
||||||
MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
|
MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
|
||||||
MILSKODECL void MilskoSetHandler(MilskoWidget handle, const char* key, MilskoHandler value);
|
|
||||||
MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);
|
MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);
|
||||||
MILSKODECL const char* MilskoGetText(MilskoWidget handle, const char* key);
|
MILSKODECL const char* MilskoGetText(MilskoWidget handle, const char* key);
|
||||||
MILSKODECL MilskoHandler MilskoGetHandler(MilskoWidget handle, const char* key);
|
|
||||||
MILSKODECL void MilskoDispatchHandler(MilskoWidget handle, const char* key);
|
|
||||||
MILSKODECL void MilskoSetDefault(MilskoWidget handle);
|
MILSKODECL void MilskoSetDefault(MilskoWidget handle);
|
||||||
MILSKODECL void MilskoVaApply(MilskoWidget handle, ...);
|
MILSKODECL void MilskoVaApply(MilskoWidget handle, ...);
|
||||||
MILSKODECL void MilskoVaListApply(MilskoWidget handle, va_list va);
|
MILSKODECL void MilskoVaListApply(MilskoWidget handle, va_list va);
|
||||||
|
|
||||||
|
MILSKODECL void MilskoAddUserHandler(MilskoWidget handle, const char* key, MilskoUserHandler handler, void* user_data);
|
||||||
|
MILSKODECL void MilskoDispatchUserHandler(MilskoWidget handle, const char* key, void* handler_data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ typedef struct _MilskoPoint MilskoPoint;
|
|||||||
typedef struct _MilskoRect MilskoRect;
|
typedef struct _MilskoRect MilskoRect;
|
||||||
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
|
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
|
||||||
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
|
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
|
||||||
typedef struct _MilskoHandlerKeyValue MilskoHandlerKeyValue;
|
typedef struct _MilskoUserHandlerKeyValue MilskoUserHandlerKeyValue;
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
typedef struct _MilskoWidget *MilskoWidget, MilskoWidgetRec;
|
typedef struct _MilskoWidget *MilskoWidget, MilskoWidgetRec;
|
||||||
#else
|
#else
|
||||||
typedef void* MilskoWidget;
|
typedef void* MilskoWidget;
|
||||||
#endif
|
#endif
|
||||||
typedef void (*MilskoHandler)(MilskoWidget handle);
|
typedef void (*MilskoHandler)(MilskoWidget handle);
|
||||||
|
typedef void (*MilskoUserHandler)(MilskoWidget handle, void* user_data, void* call_data);
|
||||||
|
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
#include <Milsko/LowLevel.h>
|
#include <Milsko/LowLevel.h>
|
||||||
@@ -43,9 +44,10 @@ struct _MilskoIntegerKeyValue {
|
|||||||
int value;
|
int value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MilskoHandlerKeyValue {
|
struct _MilskoUserHandlerKeyValue {
|
||||||
char* key;
|
char* key;
|
||||||
MilskoHandler value;
|
void* user_data;
|
||||||
|
MilskoUserHandler value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
@@ -61,7 +63,7 @@ struct _MilskoWidget {
|
|||||||
|
|
||||||
MilskoIntegerKeyValue* integer;
|
MilskoIntegerKeyValue* integer;
|
||||||
MilskoTextKeyValue* text;
|
MilskoTextKeyValue* text;
|
||||||
MilskoHandlerKeyValue* handler;
|
MilskoUserHandlerKeyValue* handler;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ static void draw(MilskoWidget handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void click(MilskoWidget handle) {
|
static void click(MilskoWidget handle) {
|
||||||
MilskoDispatchHandler(handle, MilskoNactivateHandler);
|
MilskoDispatchUserHandler(handle, MilskoNactivateHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
MilskoClassRec MilskoButtonClassRec = {
|
MilskoClassRec MilskoButtonClassRec = {
|
||||||
|
|||||||
33
src/core.c
33
src/core.c
@@ -105,6 +105,7 @@ void MilskoDestroyWidget(MilskoWidget handle) {
|
|||||||
handle->text[i].value = NULL;
|
handle->text[i].value = NULL;
|
||||||
}
|
}
|
||||||
shfree(handle->text);
|
shfree(handle->text);
|
||||||
|
shfree(handle->handler);
|
||||||
|
|
||||||
free(handle);
|
free(handle);
|
||||||
}
|
}
|
||||||
@@ -162,10 +163,6 @@ void MilskoSetText(MilskoWidget handle, const char* key, const char* value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilskoSetHandler(MilskoWidget handle, const char* key, MilskoHandler value) {
|
|
||||||
shput(handle->handler, key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
int MilskoGetInteger(MilskoWidget handle, const char* key) {
|
int MilskoGetInteger(MilskoWidget handle, const char* key) {
|
||||||
if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) {
|
if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) {
|
||||||
int x, y;
|
int x, y;
|
||||||
@@ -187,10 +184,6 @@ const char* MilskoGetText(MilskoWidget handle, const char* key) {
|
|||||||
return shget(handle->text, key);
|
return shget(handle->text, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
MilskoHandler MilskoGetHandler(MilskoWidget handle, const char* key) {
|
|
||||||
return shget(handle->handler, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MilskoVaApply(MilskoWidget handle, ...) {
|
void MilskoVaApply(MilskoWidget handle, ...) {
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
@@ -210,8 +203,12 @@ void MilskoVaListApply(MilskoWidget handle, va_list va) {
|
|||||||
char* t = va_arg(va, char*);
|
char* t = va_arg(va, char*);
|
||||||
MilskoSetText(handle, key, t);
|
MilskoSetText(handle, key, t);
|
||||||
} else if(key[0] == 'C') {
|
} else if(key[0] == 'C') {
|
||||||
MilskoHandler h = va_arg(va, MilskoHandler);
|
MilskoUserHandler h = va_arg(va, MilskoUserHandler);
|
||||||
MilskoSetHandler(handle, key, h);
|
int ind;
|
||||||
|
|
||||||
|
shput(handle->handler, key, h);
|
||||||
|
ind = shgeti(handle->handler, key);
|
||||||
|
handle->handler[ind].user_data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +217,17 @@ void MilskoSetDefault(MilskoWidget handle) {
|
|||||||
MilskoSetText(handle, MilskoNbackground, MilskoDefaultBackground);
|
MilskoSetText(handle, MilskoNbackground, MilskoDefaultBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilskoDispatchHandler(MilskoWidget handle, const char* key) {
|
void MilskoDispatchUserHandler(MilskoWidget handle, const char* key, void* handler_data) {
|
||||||
MilskoHandler handler = MilskoGetHandler(handle, key);
|
int ind = shgeti(handle->handler, key);
|
||||||
if(handler != NULL) handler(handle);
|
if(ind == -1) return;
|
||||||
|
|
||||||
|
handle->handler[ind].value(handle, handle->handler[ind].user_data, handler_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MilskoAddUserHandler(MilskoWidget handle, const char* key, MilskoUserHandler handler, void* user_data) {
|
||||||
|
int ind;
|
||||||
|
|
||||||
|
shput(handle->handler, key, handler);
|
||||||
|
ind = shgeti(handle->handler, key);
|
||||||
|
handle->handler[ind].user_data = user_data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user