diff --git a/include/Milsko/GDI.h b/include/Milsko/GDI.h index 5d55a86..c093a93 100644 --- a/include/Milsko/GDI.h +++ b/include/Milsko/GDI.h @@ -1,25 +1,27 @@ /* $Id$ */ -#ifndef __MILSKO_X11_H__ -#define __MILSKO_X11_H__ - -typedef struct _MilskoLowLevel* MilskoLL; -typedef struct _MilskoColor* MilskoLLColor; +#ifndef __MILSKO_GDI_H__ +#define __MILSKO_GDI_H__ #include + +typedef struct _MilskoLL * MilskoLL, MilskoLLRec; +typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec; + #include +#include #include -typedef struct _MilskoLowLevel { +struct _MilskoLL { void* user; void (*draw)(MilskoLL handle); -}* MilskoLL; +}; -typedef struct _MilskoColor { - int red; - int green; - int blue; -}* MilskoLLColor; +struct _MilskoColor { + int red; + int green; + int blue; +}; #endif diff --git a/include/Milsko/LowLevel.h b/include/Milsko/LowLevel.h index c21fe07..67c49e8 100644 --- a/include/Milsko/LowLevel.h +++ b/include/Milsko/LowLevel.h @@ -1,6 +1,17 @@ /* $Id$ */ -#ifndef __MILSKO_LL_H__ -#define __MILSKO_LL_H__ +#ifndef __MILSKO_LOWLEVEL_H__ +#define __MILSKO_LOWLEVEL_H__ + +#include + +typedef struct _MilskoLLCallback *MilskoLLCallback, MilskoLLCallbackRec; +#ifdef _MILSKO +typedef struct _MilskoLL * MilskoLL, MilskoLLRec; +typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec; +#else +typedef void* MilskoLL; +typedef void* MilskoLLColor; +#endif #ifdef _MILSKO #ifdef USE_X11 @@ -9,14 +20,18 @@ #ifdef USE_GDI #include #endif -#else -typedef void* MilskoLL; -typedef void* MilskoLLColor; #endif - -#include #include +#define MilskoLLDispatch(x, y) \ + if(x->callback != NULL && x->callback->y != NULL) x->callback->y(x) + +struct _MilskoLLCallback { + void (*draw)(MilskoLL handle); + void (*down)(MilskoLL handle); + void (*up)(MilskoLL handle); +}; + MILSKODECL MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height); MILSKODECL void MilskoLLDestroy(MilskoLL handle); diff --git a/include/Milsko/MachDep.h b/include/Milsko/MachDep.h index 2b88ea9..c084398 100644 --- a/include/Milsko/MachDep.h +++ b/include/Milsko/MachDep.h @@ -7,6 +7,7 @@ #include #include #ifdef _WIN32 +#include #else #include #endif diff --git a/include/Milsko/TypeDefs.h b/include/Milsko/TypeDefs.h index afb0ecb..a958323 100644 --- a/include/Milsko/TypeDefs.h +++ b/include/Milsko/TypeDefs.h @@ -4,36 +4,49 @@ #include -typedef struct _MilskoPoint { +typedef struct _MilskoClass * MilskoClass, MilskoClassRec; +typedef struct _MilskoPoint MilskoPoint; +typedef struct _MilskoRect MilskoRect; +typedef struct _MilskoTextKeyValue MilskoTextKeyValue; +typedef struct _MilskoIntegerKeyValue MilskoIntegerKeyValue; +#ifdef _MILSKO +typedef struct _Milsko *MilskoWidget, MilskoWidgetRec; +#else +typedef void* MilskoWidget; +#endif +typedef void (*MilskoHandler)(MilskoWidget handle); + +#ifdef _MILSKO +#include +#endif + +#define MilskoDispatch(x, y) \ + if(x->class != NULL && x->class->y != NULL) x->class->y(x) + +struct _MilskoPoint { int x; int y; -} MilskoPoint; +}; -typedef struct _MilskoRect { +struct _MilskoRect { int x; int y; unsigned int width; unsigned int height; -} MilskoRect; +}; -typedef struct _MilskoTextKeyValue { +struct _MilskoTextKeyValue { char* key; char* value; -} MilskoTextKeyValue; +}; -typedef struct _MilskoIntegerKeyValue { +struct _MilskoIntegerKeyValue { char* key; int value; -} MilskoIntegerKeyValue; - -typedef struct _MilskoClass* MilskoClass; +}; #ifdef _MILSKO -#include - -typedef struct _Milsko* MilskoWidget; - -typedef struct _Milsko { +struct _Milsko { char* name; MilskoLL lowlevel; @@ -43,19 +56,15 @@ typedef struct _Milsko { MilskoTextKeyValue* text; MilskoIntegerKeyValue* integer; -}* MilskoWidget; -#else -typedef void* MilskoWidget; +}; #endif -typedef void (*MilskoHandler)(MilskoWidget handle); - -typedef struct _MilskoClass { +struct _MilskoClass { void* opaque; MilskoHandler create; MilskoHandler destroy; MilskoHandler draw; MilskoHandler click; -} *MilskoClass, MilskoClassRec; +}; #endif diff --git a/include/Milsko/X11.h b/include/Milsko/X11.h index 2fc7688..02a88e2 100644 --- a/include/Milsko/X11.h +++ b/include/Milsko/X11.h @@ -2,16 +2,18 @@ #ifndef __MILSKO_X11_H__ #define __MILSKO_X11_H__ -typedef struct _MilskoLowLevel* MilskoLL; -typedef struct _MilskoColor* MilskoLLColor; - #include + +typedef struct _MilskoLL * MilskoLL, MilskoLLRec; +typedef struct _MilskoLLColor *MilskoLLColor, MilskoLLColorRec; + #include +#include #include #include -typedef struct _MilskoLowLevel { +struct _MilskoLL { Display* display; Window window; GC gc; @@ -22,14 +24,14 @@ typedef struct _MilskoLowLevel { unsigned int height; void* user; - void (*draw)(MilskoLL handle); -}* MilskoLL; + MilskoLLCallback callback; +}; -typedef struct _MilskoColor { +struct _MilskoLLColor { unsigned long pixel; int red; int green; int blue; -}* MilskoLLColor; +}; #endif diff --git a/src/core.c b/src/core.c index b03d3a4..669b4dd 100644 --- a/src/core.c +++ b/src/core.c @@ -3,12 +3,9 @@ #include "stb_ds.h" -#define Dispatch(x, y) \ - if(x->class != NULL && x->class->y != NULL) x->class->y(x) - static void llhandler(MilskoLL handle) { MilskoWidget h = (MilskoWidget)handle->user; - Dispatch(h, draw); + MilskoDispatch(h, draw); } MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidget parent, int x, int y, unsigned int width, unsigned int height) { @@ -22,8 +19,8 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge h->lowlevel = MilskoLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height); h->class = class; - h->lowlevel->user = h; - h->lowlevel->draw = llhandler; + h->lowlevel->user = h; + h->lowlevel->callback->draw = llhandler; if(parent != NULL) arrput(parent->children, h); @@ -33,7 +30,7 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge shdefault(h->text, NULL); shdefault(h->integer, -1); - Dispatch(h, create); + MilskoDispatch(h, create); return h; } @@ -41,7 +38,7 @@ MilskoWidget MilskoCreateWidget(MilskoClass class, const char* name, MilskoWidge void MilskoDestroyWidget(MilskoWidget handle) { int i; - Dispatch(handle, destroy); + MilskoDispatch(handle, destroy); free(handle->name); diff --git a/src/x11.c b/src/x11.c index fc529b1..47b17f1 100644 --- a/src/x11.c +++ b/src/x11.c @@ -9,11 +9,14 @@ MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height) { Window root; unsigned int border, depth; - r = malloc(sizeof(*r)); - r->x = x; - r->y = y; - r->width = width; - r->height = height; + r = malloc(sizeof(*r)); + r->x = x; + r->y = y; + r->width = width; + r->height = height; + r->callback = malloc(sizeof(*r->callback)); + + memset(r->callback, 0, sizeof(*r->callback)); if(parent == NULL) { r->display = XOpenDisplay(NULL); @@ -114,7 +117,7 @@ void MilskoLLNextEvent(MilskoLL handle) { XEvent ev; if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { if(ev.type == Expose) { - if(handle->draw != NULL) handle->draw(handle); + MilskoLLDispatch(handle, draw); } } }