diff --git a/doc/index.html b/doc/index.html index afc0f8d..b9517ea 100644 --- a/doc/index.html +++ b/doc/index.html @@ -20,6 +20,9 @@
#define MwDispatch2(x, y)
+
+x
+y
+0 for success, otherwise failed.
+MWDECL MwWidget MwCreateWidget (
MwClass widget_class,
const char* name,
diff --git a/include/Mw/Core.h b/include/Mw/Core.h
index 14d2a9e..0cc7130 100644
--- a/include/Mw/Core.h
+++ b/include/Mw/Core.h
@@ -18,6 +18,16 @@
#define MwDispatch(x, y) \
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
+/*!
+ * %warning Used internally
+ * %brief Dispatches the handler of widget class
+ * %param x Widget
+ * %param y Handler name
+ * %return `0` for success, otherwise failed
+ */
+#define MwDispatch2(x, y) \
+ ((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
+
#define MwWaitMS 5
#ifdef __cplusplus
diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h
index 7700a5b..8fd695b 100644
--- a/include/Mw/TypeDefs.h
+++ b/include/Mw/TypeDefs.h
@@ -24,6 +24,7 @@ typedef void* MwWidget;
typedef void* MwMenu;
#endif
typedef void (*MwHandler)(MwWidget handle);
+typedef int (*MwHandler2)(MwWidget handle);
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
@@ -96,11 +97,11 @@ struct _MwMenu {
#endif
struct _MwClass {
- MwHandler create;
- MwHandler destroy;
- MwHandler draw;
- MwHandler click;
- MwHandler parent_resize;
+ MwHandler2 create;
+ MwHandler destroy;
+ MwHandler draw;
+ MwHandler click;
+ MwHandler parent_resize;
};
struct _MwFont {
diff --git a/src/core.c b/src/core.c
index 81cf7db..fdea2ff 100644
--- a/src/core.c
+++ b/src/core.c
@@ -96,7 +96,11 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
shdefault(h->handler, NULL);
shdefault(h->data, NULL);
- MwDispatch(h, create);
+ if(MwDispatch2(h, create)) {
+ h->widget_class = NULL;
+ MwDestroyWidget(h);
+ return NULL;
+ }
return h;
}
diff --git a/src/widget/button.c b/src/widget/button.c
index eb182c7..f76ba73 100644
--- a/src/widget/button.c
+++ b/src/widget/button.c
@@ -1,8 +1,10 @@
/* $Id$ */
#include
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
MwSetDefault(handle);
+
+ return 0;
}
static void draw(MwWidget handle) {
diff --git a/src/widget/frame.c b/src/widget/frame.c
index 4458f04..c371ef1 100644
--- a/src/widget/frame.c
+++ b/src/widget/frame.c
@@ -1,8 +1,10 @@
/* $Id$ */
#include
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
MwSetDefault(handle);
+
+ return 0;
}
static void draw(MwWidget handle) {
diff --git a/src/widget/image.c b/src/widget/image.c
index 0aa0df1..e08e433 100644
--- a/src/widget/image.c
+++ b/src/widget/image.c
@@ -1,8 +1,10 @@
/* $Id$ */
#include
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
MwSetDefault(handle);
+
+ return 0;
}
static void draw(MwWidget handle) {
diff --git a/src/widget/menu.c b/src/widget/menu.c
index 06b3fb3..490cbda 100644
--- a/src/widget/menu.c
+++ b/src/widget/menu.c
@@ -25,7 +25,7 @@ static void set_xywh(MwWidget handle) {
NULL);
}
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
MwMenu m = malloc(sizeof(*m));
m->name = NULL;
@@ -37,6 +37,8 @@ static void create(MwWidget handle) {
MwSetDefault(handle);
set_xywh(handle);
+
+ return 0;
}
static void recursive_free(MwMenu m) {
diff --git a/src/widget/opengl.c b/src/widget/opengl.c
index 60c073e..f589b1c 100644
--- a/src/widget/opengl.c
+++ b/src/widget/opengl.c
@@ -49,7 +49,7 @@ typedef struct opengl {
} opengl_t;
#endif
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
opengl_t* o = malloc(sizeof(*o));
#ifdef _WIN32
PIXELFORMATDESCRIPTOR pfd;
@@ -107,6 +107,8 @@ static void create(MwWidget handle) {
handle->lowlevel->copy_buffer = 0;
MwSetDefault(handle);
+
+ return 0;
}
static void destroy(MwWidget handle) {
diff --git a/src/widget/submenu.c b/src/widget/submenu.c
index b18eeaa..c8459b0 100644
--- a/src/widget/submenu.c
+++ b/src/widget/submenu.c
@@ -3,13 +3,15 @@
#include "../external/stb_ds.h"
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
#ifdef _WIN32
#else
XUnmapWindow(handle->lowlevel->display, handle->lowlevel->window);
#endif
MwSetDefault(handle);
+
+ return 0;
}
static void null_all(MwMenu menu) {
diff --git a/src/widget/vulkan.c b/src/widget/vulkan.c
index 05510e8..44858ff 100644
--- a/src/widget/vulkan.c
+++ b/src/widget/vulkan.c
@@ -117,30 +117,32 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o);
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
vulkan_t* o = malloc(sizeof(*o));
MwErrorEnum err;
err = vulkan_instance_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
- return;
+ return 1;
}
err = vulkan_surface_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
- return;
+ return 1;
}
err = vulkan_devices_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
- return;
+ return 1;
}
handle->lowlevel->copy_buffer = 0;
handle->internal = o;
MwSetDefault(handle);
+
+ return 0;
}
static MwErrorEnum _destroy(MwWidget handle) {
diff --git a/src/widget/window.c b/src/widget/window.c
index 30ece11..ea172f6 100644
--- a/src/widget/window.c
+++ b/src/widget/window.c
@@ -1,8 +1,10 @@
/* $Id$ */
#include
-static void create(MwWidget handle) {
+static int create(MwWidget handle) {
MwSetDefault(handle);
+
+ return 0;
}
static void draw(MwWidget handle) {