Commit e742718c authored by Cedric Roux's avatar Cedric Roux

handle button press/release

first version, to be finished
parent 2df85ee8
......@@ -164,6 +164,42 @@ printf("HINTS container horizontal %p\n", _w);
*height = this->hint_height;
}
static void horizontal_button(gui *_g, widget *_this, int x, int y,
int button, int up)
{
printf("BUTTON container horizontal %p xy %d %d button %d up %d\n", _this, x, y, button, up);
struct gui *g = _g;
struct container_widget *this = _this;
struct widget_list *l;
l = this->common.children;
while (l) {
if (l->item->x <= x && x < l->item->x + l->item->width) {
l->item->button(g, l->item, x - l->item->x, y, button, up);
break;
}
l = l->next;
}
}
static void vertical_button(gui *_g, widget *_this, int x, int y,
int button, int up)
{
printf("BUTTON container vertical %p xy %d %d button %d up %d\n", _this, x, y, button, up);
struct gui *g = _g;
struct container_widget *this = _this;
struct widget_list *l;
l = this->common.children;
while (l) {
if (l->item->y <= y && y < l->item->y + l->item->height) {
l->item->button(g, l->item, x, y - l->item->y, button, up);
break;
}
l = l->next;
}
}
static void paint(gui *_gui, widget *_this)
{
printf("PAINT container\n");
......@@ -197,9 +233,11 @@ widget *new_container(gui *_gui, int vertical)
if (vertical) {
w->common.allocate = vertical_allocate;
w->common.hints = vertical_hints;
w->common.button = vertical_button;
} else {
w->common.allocate = horizontal_allocate;
w->common.hints = horizontal_hints;
w->common.button = horizontal_button;
}
gunlock(g);
......
......@@ -47,6 +47,8 @@ struct widget {
void (*hints)(gui *g, widget *this, int *width, int *height);
void (*paint)(gui *g, widget *this);
void (*clear)(gui *g, widget *this);
/* user input */
void (*button)(gui *g, widget *this, int x, int y, int button, int up);
};
struct widget_list {
......
......@@ -44,6 +44,12 @@ static void allocate(
printf("ALLOCATE text_list %p xywh %d %d %d %d nlines %d\n", this, x, y, width, height, this->allocated_nlines);
}
static void button(gui *g, widget *_this, int x, int y, int button, int up)
{
struct text_list_widget *this = _this;
printf("BUTTON test_list %p xy %d %d button %d up %d\n", this, x, y, button, up);
}
widget *new_text_list(gui *_gui, int width, int nlines, int bgcol)
{
struct gui *g = _gui;
......@@ -63,6 +69,8 @@ widget *new_text_list(gui *_gui, int width, int nlines, int bgcol)
w->common.hints = hints;
w->common.allocate = allocate;
w->common.button = button;
gunlock(g);
return w;
......
......@@ -55,6 +55,16 @@ printf("PAINT toplevel_window (%d %d)\n", this->common.width, this->common.heigh
g->xwin = NULL; /* TODO: remove? it's just in case */
}
static void button(gui *_g, widget *_this, int x, int y, int button, int up)
{
struct gui *g = _g;
struct toplevel_window_widget *this = _this;
g->xwin = this->x;
this->common.children->item->button(_g, this->common.children->item,
x, y, button, up);
g->xwin = NULL; /* TODO: remove? it's just in case */
}
/**********************************************************************/
/* creation */
/**********************************************************************/
......@@ -78,6 +88,8 @@ widget *new_toplevel_window(gui *_gui, int width, int height, char *title)
w->common.allocate = allocate;
w->common.paint = paint;
w->common.button = button;
gunlock(g);
return w;
......
......@@ -13,6 +13,8 @@ static void default_allocate(
static void default_add_child(
gui *_gui, widget *_this, widget *child, int position);
static void default_hints(gui *g, widget *this, int *width, int *height);
static void default_button(gui *gui, widget *_this, int x, int y, int button,
int up);
static void toplevel_list_append(struct gui *g, struct widget *e)
{
......@@ -47,6 +49,7 @@ widget *new_widget(struct gui *g, enum widget_type type, int size)
ret->add_child = default_add_child;
ret->allocate = default_allocate;
ret->hints = default_hints;
ret->button = default_button;
/* there is no default paint, on purpose */
ret->type = type;
......@@ -159,6 +162,12 @@ static void default_hints(gui *g, widget *this, int *width, int *height)
*height = 1;
}
static void default_button(gui *gui, widget *_this, int x, int y, int button,
int up)
{
/* nothing */
}
/*************************************************************************/
/* utils functions */
/*************************************************************************/
......
......@@ -158,7 +158,7 @@ printf("XEV %d\n", ev.type);
}
break;
case ConfigureNotify:
if ((w = find_x_window(g, ev.xexpose.window)) != NULL) {
if ((w = find_x_window(g, ev.xconfigure.window)) != NULL) {
struct x_window *xw = w->x;
xw->resize = 1;
xw->new_width = ev.xconfigure.width;
......@@ -168,9 +168,21 @@ printf("XEV %d\n", ev.type);
printf("ConfigureNotify %d %d\n", ev.xconfigure.width, ev.xconfigure.height);
}
break;
case ButtonPress:
if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
w->common.button(g, w, ev.xbutton.x, ev.xbutton.y,
ev.xbutton.button, 0);
}
break;
case ButtonRelease:
if ((w = find_x_window(g, ev.xbutton.window)) != NULL) {
w->common.button(g, w, ev.xbutton.x, ev.xbutton.y,
ev.xbutton.button, 1);
}
break;
#if 0
case MapNotify:
if ((w = find_x_window(g, ev.xexpose.window)) != NULL) {
if ((w = find_x_window(g, ev.xmap.window)) != NULL) {
struct x_window *xw = w->x;
xw->repaint = 1;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment