mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-03 08:00:50 +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>
|
||||
|
||||
void handler(MilskoWidget handle){
|
||||
void handler(MilskoWidget handle, void* user_data, void* call_data){
|
||||
printf("hello world!\n");
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ int main(){
|
||||
MilskoWidget window = MilskoVaCreateWidget(MilskoWindowClass, "main", NULL, 0, 0, 400, 400,
|
||||
MilskoNtitle, "hello world",
|
||||
NULL);
|
||||
MilskoWidget button = MilskoVaCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300,
|
||||
MilskoNactivateHandler, handler,
|
||||
NULL);
|
||||
MilskoWidget button = MilskoVaCreateWidget(MilskoButtonClass, "button", window, 50, 50, 300, 300, NULL);
|
||||
|
||||
MilskoAddUserHandler(button, MilskoNactivateHandler, handler, NULL);
|
||||
|
||||
MilskoLoop(window);
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ MILSKODECL void MilskoLoop(MilskoWidget handle);
|
||||
MILSKODECL void MilskoStep(MilskoWidget handle);
|
||||
MILSKODECL int MilskoPending(MilskoWidget handle);
|
||||
|
||||
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
|
||||
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 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 MilskoVaApply(MilskoWidget handle, ...);
|
||||
MILSKODECL void MilskoVaListApply(MilskoWidget handle, va_list va);
|
||||
MILSKODECL void MilskoSetInteger(MilskoWidget handle, const char* key, int n);
|
||||
MILSKODECL void MilskoSetText(MilskoWidget handle, const char* key, const char* value);
|
||||
MILSKODECL int MilskoGetInteger(MilskoWidget handle, const char* key);
|
||||
MILSKODECL const char* MilskoGetText(MilskoWidget handle, const char* key);
|
||||
MILSKODECL void MilskoSetDefault(MilskoWidget handle);
|
||||
MILSKODECL void MilskoVaApply(MilskoWidget handle, ...);
|
||||
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
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
|
||||
#include <Milsko/MachDep.h>
|
||||
|
||||
typedef struct _MilskoClass * MilskoClass, MilskoClassRec;
|
||||
typedef struct _MilskoPoint MilskoPoint;
|
||||
typedef struct _MilskoRect MilskoRect;
|
||||
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
|
||||
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
|
||||
typedef struct _MilskoHandlerKeyValue MilskoHandlerKeyValue;
|
||||
typedef struct _MilskoClass * MilskoClass, MilskoClassRec;
|
||||
typedef struct _MilskoPoint MilskoPoint;
|
||||
typedef struct _MilskoRect MilskoRect;
|
||||
typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue;
|
||||
typedef struct _MilskoTextKeyValue MilskoTextKeyValue;
|
||||
typedef struct _MilskoUserHandlerKeyValue MilskoUserHandlerKeyValue;
|
||||
#ifdef _MILSKO
|
||||
typedef struct _MilskoWidget *MilskoWidget, MilskoWidgetRec;
|
||||
#else
|
||||
typedef void* MilskoWidget;
|
||||
#endif
|
||||
typedef void (*MilskoHandler)(MilskoWidget handle);
|
||||
typedef void (*MilskoUserHandler)(MilskoWidget handle, void* user_data, void* call_data);
|
||||
|
||||
#ifdef _MILSKO
|
||||
#include <Milsko/LowLevel.h>
|
||||
@@ -43,9 +44,10 @@ struct _MilskoIntegerKeyValue {
|
||||
int value;
|
||||
};
|
||||
|
||||
struct _MilskoHandlerKeyValue {
|
||||
char* key;
|
||||
MilskoHandler value;
|
||||
struct _MilskoUserHandlerKeyValue {
|
||||
char* key;
|
||||
void* user_data;
|
||||
MilskoUserHandler value;
|
||||
};
|
||||
|
||||
#ifdef _MILSKO
|
||||
@@ -59,9 +61,9 @@ struct _MilskoWidget {
|
||||
|
||||
int pressed;
|
||||
|
||||
MilskoIntegerKeyValue* integer;
|
||||
MilskoTextKeyValue* text;
|
||||
MilskoHandlerKeyValue* handler;
|
||||
MilskoIntegerKeyValue* integer;
|
||||
MilskoTextKeyValue* text;
|
||||
MilskoUserHandlerKeyValue* handler;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ static void draw(MilskoWidget handle) {
|
||||
}
|
||||
|
||||
static void click(MilskoWidget handle) {
|
||||
MilskoDispatchHandler(handle, MilskoNactivateHandler);
|
||||
MilskoDispatchUserHandler(handle, MilskoNactivateHandler, NULL);
|
||||
}
|
||||
|
||||
MilskoClassRec MilskoButtonClassRec = {
|
||||
|
||||
33
src/core.c
33
src/core.c
@@ -105,6 +105,7 @@ void MilskoDestroyWidget(MilskoWidget handle) {
|
||||
handle->text[i].value = NULL;
|
||||
}
|
||||
shfree(handle->text);
|
||||
shfree(handle->handler);
|
||||
|
||||
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) {
|
||||
if(strcmp(key, MilskoNx) == 0 || strcmp(key, MilskoNy) == 0 || strcmp(key, MilskoNwidth) == 0 || strcmp(key, MilskoNheight) == 0) {
|
||||
int x, y;
|
||||
@@ -187,10 +184,6 @@ const char* MilskoGetText(MilskoWidget handle, const char* key) {
|
||||
return shget(handle->text, key);
|
||||
}
|
||||
|
||||
MilskoHandler MilskoGetHandler(MilskoWidget handle, const char* key) {
|
||||
return shget(handle->handler, key);
|
||||
}
|
||||
|
||||
void MilskoVaApply(MilskoWidget handle, ...) {
|
||||
va_list va;
|
||||
|
||||
@@ -210,8 +203,12 @@ void MilskoVaListApply(MilskoWidget handle, va_list va) {
|
||||
char* t = va_arg(va, char*);
|
||||
MilskoSetText(handle, key, t);
|
||||
} else if(key[0] == 'C') {
|
||||
MilskoHandler h = va_arg(va, MilskoHandler);
|
||||
MilskoSetHandler(handle, key, h);
|
||||
MilskoUserHandler h = va_arg(va, MilskoUserHandler);
|
||||
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);
|
||||
}
|
||||
|
||||
void MilskoDispatchHandler(MilskoWidget handle, const char* key) {
|
||||
MilskoHandler handler = MilskoGetHandler(handle, key);
|
||||
if(handler != NULL) handler(handle);
|
||||
void MilskoDispatchUserHandler(MilskoWidget handle, const char* key, void* handler_data) {
|
||||
int ind = shgeti(handle->handler, key);
|
||||
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