better property handling
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@226 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
parent
84a4efa57e
commit
7450b17bcf
8 changed files with 64 additions and 22 deletions
|
|
@ -28,6 +28,16 @@
|
||||||
#define MwDispatch2(x, y) \
|
#define MwDispatch2(x, y) \
|
||||||
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
|
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* %warning Used internally
|
||||||
|
* %brief Dispatches the handler of widget class
|
||||||
|
* %param x Widget
|
||||||
|
* %param y Handler name
|
||||||
|
* %param name Property name
|
||||||
|
*/
|
||||||
|
#define MwDispatch3(x, y, name) \
|
||||||
|
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x, name) : 0)
|
||||||
|
|
||||||
#define MwWaitMS 5
|
#define MwWaitMS 5
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ typedef void* MwWidget;
|
||||||
#endif
|
#endif
|
||||||
typedef void (*MwHandler)(MwWidget handle);
|
typedef void (*MwHandler)(MwWidget handle);
|
||||||
typedef int (*MwHandler2)(MwWidget handle);
|
typedef int (*MwHandler2)(MwWidget handle);
|
||||||
typedef int (*MwHandler3)(MwWidget handle, const char* key);
|
typedef void (*MwHandler3)(MwWidget handle, const char* key);
|
||||||
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
|
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
|
||||||
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
|
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
|
||||||
|
|
||||||
|
|
@ -79,6 +79,7 @@ struct _MwWidget {
|
||||||
MwPoint mouse_point;
|
MwPoint mouse_point;
|
||||||
int close;
|
int close;
|
||||||
jmp_buf before_step;
|
jmp_buf before_step;
|
||||||
|
int prop_event;
|
||||||
|
|
||||||
void* internal;
|
void* internal;
|
||||||
|
|
||||||
|
|
|
||||||
11
src/core.c
11
src/core.c
|
|
@ -83,6 +83,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
||||||
h->pressed = 0;
|
h->pressed = 0;
|
||||||
h->close = 0;
|
h->close = 0;
|
||||||
h->destroy_queue = NULL;
|
h->destroy_queue = NULL;
|
||||||
|
h->prop_event = 1;
|
||||||
|
|
||||||
h->lowlevel->user = h;
|
h->lowlevel->user = h;
|
||||||
h->lowlevel->handler->draw = lldrawhandler;
|
h->lowlevel->handler->draw = lldrawhandler;
|
||||||
|
|
@ -171,7 +172,11 @@ void MwStep(MwWidget handle) {
|
||||||
int i, j;
|
int i, j;
|
||||||
if(setjmp(handle->before_step)) return;
|
if(setjmp(handle->before_step)) return;
|
||||||
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
|
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
|
||||||
|
|
||||||
|
handle->prop_event = 0;
|
||||||
MwLLNextEvent(handle->lowlevel);
|
MwLLNextEvent(handle->lowlevel);
|
||||||
|
handle->prop_event = 1;
|
||||||
|
|
||||||
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
|
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
|
||||||
MwWidget w = handle->destroy_queue[i];
|
MwWidget w = handle->destroy_queue[i];
|
||||||
|
|
||||||
|
|
@ -222,6 +227,7 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
|
||||||
} else {
|
} else {
|
||||||
shput(handle->integer, key, n);
|
shput(handle->integer, key, n);
|
||||||
}
|
}
|
||||||
|
if(handle->prop_event) MwDispatch3(handle, prop_change, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwSetText(MwWidget handle, const char* key, const char* value) {
|
void MwSetText(MwWidget handle, const char* key, const char* value) {
|
||||||
|
|
@ -235,6 +241,10 @@ void MwSetText(MwWidget handle, const char* key, const char* value) {
|
||||||
|
|
||||||
shput(handle->text, key, v);
|
shput(handle->text, key, v);
|
||||||
}
|
}
|
||||||
|
if(handle->prop_event) MwDispatch3(handle, prop_change, key);
|
||||||
|
if(strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0) {
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwSetVoid(MwWidget handle, const char* key, void* value) {
|
void MwSetVoid(MwWidget handle, const char* key, void* value) {
|
||||||
|
|
@ -243,6 +253,7 @@ void MwSetVoid(MwWidget handle, const char* key, void* value) {
|
||||||
} else {
|
} else {
|
||||||
shput(handle->data, key, value);
|
shput(handle->data, key, value);
|
||||||
}
|
}
|
||||||
|
if(handle->prop_event) MwDispatch3(handle, prop_change, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MwGetInteger(MwWidget handle, const char* key) {
|
int MwGetInteger(MwWidget handle, const char* key) {
|
||||||
|
|
|
||||||
|
|
@ -61,13 +61,17 @@ static void click(MwWidget handle) {
|
||||||
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
|
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
|
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNpixmap) == 0) MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
MwClassRec MwButtonClassRec = {
|
MwClassRec MwButtonClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
click, /* click */
|
click, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
NULL, /* mouse_move */
|
||||||
MwForceRender, /* mouse_up */
|
MwForceRender, /* mouse_up */
|
||||||
MwForceRender /* mouse_down */
|
MwForceRender /* mouse_down */
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,17 @@ static void click(MwWidget handle) {
|
||||||
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
|
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
|
if(strcmp(key, MwNchecked) == 0) MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
MwClassRec MwCheckBoxClassRec = {
|
MwClassRec MwCheckBoxClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
click, /* click */
|
click, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
NULL, /* mouse_move */
|
||||||
MwForceRender, /* mouse_up */
|
MwForceRender, /* mouse_up */
|
||||||
MwForceRender /* mouse_down */
|
MwForceRender /* mouse_down */
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,17 @@ static void draw(MwWidget handle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
|
if(strcmp(key, MwNpixmap) == 0) MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
MwClassRec MwImageClassRec = {
|
MwClassRec MwImageClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
NULL, /* mouse_move */
|
||||||
NULL, /* mouse_up */
|
NULL, /* mouse_up */
|
||||||
NULL /* mouse_down */
|
NULL /* mouse_down */
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,17 @@ static void draw(MwWidget handle) {
|
||||||
MwLLFreeColor(base);
|
MwLLFreeColor(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
|
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0) MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
MwClassRec MwLabelClassRec = {
|
MwClassRec MwLabelClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
NULL, /* mouse_move */
|
||||||
NULL, /* mouse_up */
|
NULL, /* mouse_up */
|
||||||
NULL /* mouse_down */
|
NULL /* mouse_down */
|
||||||
|
|
|
||||||
|
|
@ -181,13 +181,17 @@ static void mouse_down(MwWidget handle) {
|
||||||
MwForceRender(handle);
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
|
if(strcmp(key, MwNminValue) == 0 || strcmp(key, MwNvalue) == 0 || strcmp(key, MwNmaxValue) == 0 || strcmp(key, MwNareaShown) == 0) MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
MwClassRec MwScrollBarClassRec = {
|
MwClassRec MwScrollBarClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
destroy, /* destroy */
|
destroy, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
mouse_move, /* mouse_move */
|
mouse_move, /* mouse_move */
|
||||||
MwForceRender, /* mouse_up */
|
MwForceRender, /* mouse_up */
|
||||||
mouse_down /* mouse_down */
|
mouse_down /* mouse_down */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue