mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-08 02:13:29 +00:00
menu widget
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@132 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -39,6 +39,7 @@ struct _MwLLHandler {
|
|||||||
void (*down)(MwLL handle, void* data);
|
void (*down)(MwLL handle, void* data);
|
||||||
void (*resize)(MwLL handle, void* data);
|
void (*resize)(MwLL handle, void* data);
|
||||||
void (*close)(MwLL handle, void* data);
|
void (*close)(MwLL handle, void* data);
|
||||||
|
void (*move)(MwLL handle, void* data);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ struct _MwWidget {
|
|||||||
MwClass widget_class;
|
MwClass widget_class;
|
||||||
|
|
||||||
int pressed;
|
int pressed;
|
||||||
MwPoint pressed_point;
|
MwPoint mouse_point;
|
||||||
int close;
|
int close;
|
||||||
jmp_buf before_step;
|
jmp_buf before_step;
|
||||||
|
|
||||||
@@ -88,6 +88,7 @@ struct _MwWidget {
|
|||||||
|
|
||||||
struct _MwMenu {
|
struct _MwMenu {
|
||||||
char* name;
|
char* name;
|
||||||
|
int keep;
|
||||||
MwWidget wsub;
|
MwWidget wsub;
|
||||||
MwMenu* sub;
|
MwMenu* sub;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask;
|
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask;
|
||||||
|
|
||||||
static void create_pixmap(MwLL handle) {
|
static void create_pixmap(MwLL handle) {
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
@@ -175,6 +175,12 @@ void MwLLNextEvent(MwLL handle) {
|
|||||||
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
|
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
|
||||||
MwLLDispatch(handle, close, NULL);
|
MwLLDispatch(handle, close, NULL);
|
||||||
}
|
}
|
||||||
|
} else if(ev.type == MotionNotify) {
|
||||||
|
MwPoint p;
|
||||||
|
p.x = ev.xmotion.x;
|
||||||
|
p.y = ev.xmotion.y;
|
||||||
|
|
||||||
|
MwLLDispatch(handle, move, &p);
|
||||||
}
|
}
|
||||||
if(render) {
|
if(render) {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|||||||
18
src/core.c
18
src/core.c
@@ -22,11 +22,11 @@ static void lluphandler(MwLL handle, void* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void lldownhandler(MwLL handle, void* data) {
|
static void lldownhandler(MwLL handle, void* data) {
|
||||||
MwWidget h = (MwWidget)handle->user;
|
MwWidget h = (MwWidget)handle->user;
|
||||||
MwPoint* p = data;
|
MwPoint* p = data;
|
||||||
h->pressed = 1;
|
h->pressed = 1;
|
||||||
h->pressed_point.x = p->x;
|
h->mouse_point.x = p->x;
|
||||||
h->pressed_point.y = p->y;
|
h->mouse_point.y = p->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void llresizehandler(MwLL handle, void* data) {
|
static void llresizehandler(MwLL handle, void* data) {
|
||||||
@@ -49,6 +49,13 @@ static void llclosehandler(MwLL handle, void* data) {
|
|||||||
h->close = 1;
|
h->close = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void llmovehandler(MwLL handle, void* data) {
|
||||||
|
MwWidget h = (MwWidget)handle->user;
|
||||||
|
MwPoint* p = data;
|
||||||
|
h->mouse_point.x = p->x;
|
||||||
|
h->mouse_point.y = p->y;
|
||||||
|
}
|
||||||
|
|
||||||
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
|
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
|
||||||
MwWidget h = malloc(sizeof(*h));
|
MwWidget h = malloc(sizeof(*h));
|
||||||
|
|
||||||
@@ -72,6 +79,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
|
|||||||
h->lowlevel->handler->down = lldownhandler;
|
h->lowlevel->handler->down = lldownhandler;
|
||||||
h->lowlevel->handler->resize = llresizehandler;
|
h->lowlevel->handler->resize = llresizehandler;
|
||||||
h->lowlevel->handler->close = llclosehandler;
|
h->lowlevel->handler->close = llclosehandler;
|
||||||
|
h->lowlevel->handler->move = llmovehandler;
|
||||||
|
|
||||||
if(parent != NULL) arrput(parent->children, h);
|
if(parent != NULL) arrput(parent->children, h);
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ static void draw(MwWidget handle) {
|
|||||||
int tw = MwTextWidth(handle, m->sub[i]->name + incr);
|
int tw = MwTextWidth(handle, m->sub[i]->name + incr);
|
||||||
int th = MwTextHeight(handle, m->sub[i]->name + incr);
|
int th = MwTextHeight(handle, m->sub[i]->name + incr);
|
||||||
int oldx = p.x;
|
int oldx = p.x;
|
||||||
|
int in_area;
|
||||||
|
|
||||||
if(incr) {
|
if(incr) {
|
||||||
p.x = MwGetInteger(handle, MwNwidth) - tw - 10;
|
p.x = MwGetInteger(handle, MwNwidth) - tw - 10;
|
||||||
@@ -90,7 +91,8 @@ static void draw(MwWidget handle) {
|
|||||||
r.width = tw + 10;
|
r.width = tw + 10;
|
||||||
r.height = th + 10;
|
r.height = th + 10;
|
||||||
|
|
||||||
if(handle->pressed && r.x <= handle->pressed_point.x && r.y <= handle->pressed_point.y && handle->pressed_point.x <= (int)(r.x + r.width) && handle->pressed_point.y <= (int)(r.y + r.height)) {
|
in_area = (r.x <= handle->mouse_point.x && r.y <= handle->mouse_point.y && handle->mouse_point.x <= (int)(r.x + r.width) && handle->mouse_point.y <= (int)(r.y + r.height)) ? 1 : 0;
|
||||||
|
if(handle->pressed && in_area) {
|
||||||
MwDrawFrame(handle, &r, base, 0);
|
MwDrawFrame(handle, &r, base, 0);
|
||||||
if(m->sub[i]->wsub == NULL && arrlen(m->sub[i]->sub) > 0) {
|
if(m->sub[i]->wsub == NULL && arrlen(m->sub[i]->sub) > 0) {
|
||||||
MwPoint p2;
|
MwPoint p2;
|
||||||
@@ -100,10 +102,24 @@ static void draw(MwWidget handle) {
|
|||||||
|
|
||||||
m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
||||||
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2);
|
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2);
|
||||||
|
} else if(m->sub[i]->keep) {
|
||||||
|
MwDestroyWidget(m->sub[i]->wsub);
|
||||||
|
m->sub[i]->wsub = NULL;
|
||||||
|
m->sub[i]->keep = 0;
|
||||||
}
|
}
|
||||||
} else if(!handle->pressed && m->sub[i]->wsub != NULL) {
|
} else if(!handle->pressed && m->sub[i]->wsub != NULL) {
|
||||||
|
if(in_area) {
|
||||||
|
MwDrawFrame(handle, &r, base, 0);
|
||||||
|
m->sub[i]->keep = 1;
|
||||||
|
} else {
|
||||||
|
MwDestroyWidget(m->sub[i]->wsub);
|
||||||
|
m->sub[i]->wsub = NULL;
|
||||||
|
m->sub[i]->keep = 0;
|
||||||
|
}
|
||||||
|
} else if(m->sub[i]->keep && m->sub[i]->wsub != NULL) {
|
||||||
MwDestroyWidget(m->sub[i]->wsub);
|
MwDestroyWidget(m->sub[i]->wsub);
|
||||||
m->sub[i]->wsub = NULL;
|
m->sub[i]->wsub = NULL;
|
||||||
|
m->sub[i]->keep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MwDrawText(handle, &p, m->sub[i]->name + incr, 1, text);
|
MwDrawText(handle, &p, m->sub[i]->name + incr, 1, text);
|
||||||
@@ -135,6 +151,7 @@ MwMenu MwMenuAdd(MwWidget handle, MwMenu menu, const char* name) {
|
|||||||
new->name = malloc(strlen(name) + 1);
|
new->name = malloc(strlen(name) + 1);
|
||||||
new->sub = NULL;
|
new->sub = NULL;
|
||||||
new->wsub = NULL;
|
new->wsub = NULL;
|
||||||
|
new->keep = 0;
|
||||||
|
|
||||||
strcpy(new->name, name);
|
strcpy(new->name, name);
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
|||||||
XChangeProperty(handle->lowlevel->display, handle->lowlevel->window, wndtype, 4, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
|
XChangeProperty(handle->lowlevel->display, handle->lowlevel->window, wndtype, 4, 32, PropModeReplace, (unsigned char*)&wndmenu, 1);
|
||||||
|
|
||||||
XMapWindow(handle->lowlevel->display, handle->lowlevel->window);
|
XMapWindow(handle->lowlevel->display, handle->lowlevel->window);
|
||||||
|
XSetInputFocus(handle->lowlevel->display, handle->lowlevel->window, RevertToNone, CurrentTime);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
handle->internal = menu;
|
handle->internal = menu;
|
||||||
|
|||||||
Reference in New Issue
Block a user