diff --git a/include/Mw/Core.h b/include/Mw/Core.h index bd4a7ee..9768951 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -28,6 +28,16 @@ #define MwDispatch2(x, y) \ ((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 #ifdef __cplusplus diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index 32b9b2e..b6b83cc 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -25,7 +25,7 @@ typedef void* MwWidget; #endif typedef void (*MwHandler)(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 (*MwErrorHandler)(int code, const char* message, void* user_data); @@ -79,6 +79,7 @@ struct _MwWidget { MwPoint mouse_point; int close; jmp_buf before_step; + int prop_event; void* internal; diff --git a/src/core.c b/src/core.c index f39458b..b79a8fe 100644 --- a/src/core.c +++ b/src/core.c @@ -83,6 +83,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, h->pressed = 0; h->close = 0; h->destroy_queue = NULL; + h->prop_event = 1; h->lowlevel->user = h; h->lowlevel->handler->draw = lldrawhandler; @@ -171,7 +172,11 @@ void MwStep(MwWidget handle) { int i, j; if(setjmp(handle->before_step)) return; for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]); + + handle->prop_event = 0; MwLLNextEvent(handle->lowlevel); + handle->prop_event = 1; + for(i = 0; i < arrlen(handle->destroy_queue); i++) { MwWidget w = handle->destroy_queue[i]; @@ -222,6 +227,7 @@ void MwSetInteger(MwWidget handle, const char* key, int n) { } else { shput(handle->integer, key, n); } + if(handle->prop_event) MwDispatch3(handle, prop_change, key); } 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); } + 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) { @@ -243,6 +253,7 @@ void MwSetVoid(MwWidget handle, const char* key, void* value) { } else { shput(handle->data, key, value); } + if(handle->prop_event) MwDispatch3(handle, prop_change, key); } int MwGetInteger(MwWidget handle, const char* key) { diff --git a/src/widget/button.c b/src/widget/button.c index 9f4f2dd..4b0d5bd 100644 --- a/src/widget/button.c +++ b/src/widget/button.c @@ -61,13 +61,17 @@ static void click(MwWidget handle) { 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 = { create, /* create */ NULL, /* destroy */ draw, /* draw */ click, /* click */ NULL, /* parent_resize */ - NULL, /* prop_change */ + prop_change, /* prop_change */ NULL, /* mouse_move */ MwForceRender, /* mouse_up */ MwForceRender /* mouse_down */ diff --git a/src/widget/checkbox.c b/src/widget/checkbox.c index 095f56d..570f691 100644 --- a/src/widget/checkbox.c +++ b/src/widget/checkbox.c @@ -33,13 +33,17 @@ static void click(MwWidget handle) { MwDispatchUserHandler(handle, MwNchangedHandler, NULL); } +static void prop_change(MwWidget handle, const char* key) { + if(strcmp(key, MwNchecked) == 0) MwForceRender(handle); +} + MwClassRec MwCheckBoxClassRec = { create, /* create */ NULL, /* destroy */ draw, /* draw */ click, /* click */ NULL, /* parent_resize */ - NULL, /* prop_change */ + prop_change, /* prop_change */ NULL, /* mouse_move */ MwForceRender, /* mouse_up */ MwForceRender /* mouse_down */ diff --git a/src/widget/image.c b/src/widget/image.c index 733b77d..23a942c 100644 --- a/src/widget/image.c +++ b/src/widget/image.c @@ -20,15 +20,19 @@ static void draw(MwWidget handle) { } } +static void prop_change(MwWidget handle, const char* key) { + if(strcmp(key, MwNpixmap) == 0) MwForceRender(handle); +} + MwClassRec MwImageClassRec = { - create, /* create */ - NULL, /* destroy */ - draw, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - NULL, /* mouse_move */ - NULL, /* mouse_up */ - NULL /* mouse_down */ + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL /* mouse_down */ }; MwClass MwImageClass = &MwImageClassRec; diff --git a/src/widget/label.c b/src/widget/label.c index 3c2bb69..40db38d 100644 --- a/src/widget/label.c +++ b/src/widget/label.c @@ -40,15 +40,19 @@ static void draw(MwWidget handle) { MwLLFreeColor(base); } +static void prop_change(MwWidget handle, const char* key) { + if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0) MwForceRender(handle); +} + MwClassRec MwLabelClassRec = { - create, /* create */ - NULL, /* destroy */ - draw, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - NULL, /* mouse_move */ - NULL, /* mouse_up */ - NULL /* mouse_down */ + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL /* mouse_down */ }; MwClass MwLabelClass = &MwLabelClassRec; diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index 4f0daee..f12ced0 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -181,13 +181,17 @@ static void mouse_down(MwWidget 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 = { create, /* create */ destroy, /* destroy */ draw, /* draw */ NULL, /* click */ NULL, /* parent_resize */ - NULL, /* prop_change */ + prop_change, /* prop_change */ mouse_move, /* mouse_move */ MwForceRender, /* mouse_up */ mouse_down /* mouse_down */