summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@neko.keithp.com>2006-11-24 18:47:19 -0800
committerKeith Packard <keithp@neko.keithp.com>2006-11-24 18:47:19 -0800
commit9cbb077d90651a3e21a168dcdb59515e4c9f9574 (patch)
tree55f158f4b59cbe29830ed598d8fd81a063cdba86
parent30abf238994625669eef90b0aa0b7dd209c7a2d9 (diff)
Huge WM-related change?keithp-changes
-rw-r--r--twin.h154
-rw-r--r--twin_box.c119
-rw-r--r--twin_button.c44
-rw-r--r--twin_calc.c46
-rw-r--r--twin_calc.h2
-rw-r--r--twin_clock.c22
-rw-r--r--twin_clock.h8
-rw-r--r--twin_demo.c17
-rw-r--r--twin_demoline.c53
-rw-r--r--twin_demoline.h8
-rw-r--r--twin_demospline.c75
-rw-r--r--twin_demospline.h8
-rw-r--r--twin_font.c8
-rw-r--r--twin_hello.c32
-rw-r--r--twin_label.c56
-rw-r--r--twin_path.c2
-rw-r--r--twin_pixmap.c4
-rw-r--r--twin_screen.c34
-rw-r--r--twin_text.c3
-rw-r--r--twin_toplevel.c109
-rw-r--r--twin_widget.c83
-rw-r--r--twin_window.c199
-rw-r--r--twinint.h4
-rw-r--r--xtwin.c2
24 files changed, 559 insertions, 533 deletions
diff --git a/twin.h b/twin.h
index c99a1f7..ae2f17f 100644
--- a/twin.h
+++ b/twin.h
@@ -36,7 +36,6 @@ typedef uint32_t twin_argb32_t;
typedef uint32_t twin_ucs4_t;
typedef int twin_bool_t;
typedef int16_t twin_coord_t;
-typedef int16_t twin_style_t;
typedef int16_t twin_count_t;
typedef int16_t twin_keysym_t;
typedef int32_t twin_area_t;
@@ -82,7 +81,8 @@ typedef union _twin_pointer {
twin_argb32_t *argb32;
} twin_pointer_t;
-typedef struct _twin_window twin_window_t;
+typedef struct _twin_window twin_window_t;
+typedef struct _twin_box twin_toplevel_t;
/*
* A rectangular array of pixels
@@ -118,10 +118,9 @@ typedef struct _twin_pixmap {
*/
twin_pointer_t p;
/*
- * When representing a window, this point
- * refers to the window object
+ * The widget tree (if any)
*/
- twin_window_t *window;
+ twin_toplevel_t *toplevel;
} twin_pixmap_t;
/*
@@ -150,11 +149,15 @@ typedef struct _twin_screen {
/*
* One of them receives all key events
*/
- twin_pixmap_t *active;
+ twin_pixmap_t *key_focus;
/*
* pointer down for this window
*/
- twin_pixmap_t *pointer;
+ twin_pixmap_t *pointer_grab;
+ /*
+ * pointer inside this window
+ */
+ twin_pixmap_t *pointer_in;
/*
* Output size
*/
@@ -230,6 +233,14 @@ typedef struct _twin_matrix {
typedef struct _twin_path twin_path_t;
+typedef enum _twin_style {
+ TwinStyleRoman = 0,
+ TwinStyleBold = 1,
+ TwinStyleOblique = 2,
+ TwinStyleBoldOblique = 3,
+ TwinStyleUnhinted = 4,
+} twin_style_t;
+
typedef enum _twin_cap {
TwinCapRound,
TwinCapButt,
@@ -264,6 +275,7 @@ typedef struct _twin_text_metrics {
typedef enum _twin_event_kind {
TwinEventButtonDown, TwinEventButtonUp, TwinEventMotion,
TwinEventKeyDown, TwinEventKeyUp, TwinEventUcs4,
+ TwinEventEnter, TwinEventLeave,
TwinEventActivate, TwinEventDeactivate,
TwinEventPaint,
TwinEventShow,
@@ -316,22 +328,6 @@ typedef twin_bool_t (*twin_event_func_t) (twin_window_t *window,
typedef void (*twin_destroy_func_t) (twin_window_t *window);
-struct _twin_window {
- twin_screen_t *screen;
- twin_pixmap_t *pixmap;
- twin_window_style_t style;
- twin_rect_t client;
- twin_rect_t damage;
- twin_bool_t client_grab;
- twin_bool_t want_focus;
- void *client_data;
- char *name;
-
- twin_draw_func_t draw;
- twin_event_func_t event;
- twin_destroy_func_t destroy;
-};
-
/*
* Icons
*/
@@ -376,11 +372,11 @@ typedef struct _twin_file twin_file_t;
typedef struct _twin_widget twin_widget_t;
typedef struct _twin_box twin_box_t;
-#define _twin_widget_width(w) (((twin_widget_t *)(w))->extents.right - \
- ((twin_widget_t *)(w))->extents.left)
+#define _twin_widget_width(w) ((w)->widget.extents.right - \
+ (w)->widget.extents.left)
-#define _twin_widget_height(w) (((twin_widget_t *)(w))->extents.bottom - \
- ((twin_widget_t *)(w))->extents.top)
+#define _twin_widget_height(w) ((w)->widget.extents.bottom - \
+ (w)->widget.extents.top)
typedef enum _twin_box_dir {
TwinBoxHorz, TwinBoxVert
@@ -409,7 +405,7 @@ typedef enum _twin_shape {
TwinShapeEllipse,
} twin_shape_t;
-struct _twin_widget {
+typedef struct _twin_widget_part {
twin_window_t *window;
twin_widget_t *next;
twin_box_t *parent;
@@ -423,52 +419,53 @@ struct _twin_widget {
twin_widget_layout_t preferred;
twin_shape_t shape;
twin_fixed_t radius;
+ void *closure;
+} twin_widget_part_t;
+
+struct _twin_widget {
+ twin_widget_part_t widget;
};
-struct _twin_box {
- twin_widget_t widget;
+typedef struct _twin_box_part {
twin_box_dir_t dir;
twin_widget_t *children;
- twin_widget_t *button_down;
- twin_widget_t *focus;
-};
+ twin_widget_t *key_focus;
+ twin_widget_t *pointer_grab;
+} twin_box_part_t;
-typedef struct _twin_toplevel {
- twin_box_t box;
-} twin_toplevel_t;
+struct _twin_box {
+ twin_widget_part_t widget;
+ twin_box_part_t box;
+};
typedef enum _twin_align {
TwinAlignLeft, TwinAlignCenter, TwinAlignRight
} twin_align_t;
-typedef struct _twin_label {
- twin_widget_t widget;
+typedef struct _twin_label_part {
char *label;
twin_argb32_t foreground;
twin_fixed_t font_size;
twin_style_t font_style;
twin_point_t offset;
twin_align_t align;
-} twin_label_t;
-
-typedef enum _twin_button_signal {
- TwinButtonSignalDown, /* sent when button pressed */
- TwinButtonSignalUp, /* send when button released inside widget */
-} twin_button_signal_t;
+} twin_label_part_t;
-typedef struct _twin_button twin_button_t;
-
-typedef void (*twin_button_signal_proc_t) (twin_button_t *button,
- twin_button_signal_t signal,
- void *closure);
+typedef struct _twin_label {
+ twin_widget_part_t widget;
+ twin_label_part_t label;
+} twin_label_t;
-struct _twin_button {
- twin_label_t label;
+typedef struct _twin_button_part {
twin_bool_t pressed;
twin_bool_t active;
- twin_button_signal_proc_t signal;
- void *closure;
-};
+} twin_button_part_t;
+
+typedef struct _twin_button {
+ twin_widget_part_t widget;
+ twin_label_part_t label;
+ twin_button_part_t button;
+} twin_button_t;
typedef enum _twin_scroll_signal {
TwinScrollSignalUpArrow,
@@ -484,8 +481,20 @@ typedef void (*twin_scroll_signal_proc_t) (twin_scroll_t *scroll,
twin_scroll_signal_t signal,
void *closure);
-struct _twin_scroll {
- twin_widget_t widget;
+struct _twin_window {
+ twin_screen_t *screen;
+ twin_pixmap_t *pixmap;
+ twin_toplevel_t *toplevel;
+ twin_window_style_t style;
+ twin_rect_t client;
+ twin_bool_t want_focus;
+ void *client_data;
+
+ twin_label_t *label;
+
+ twin_draw_func_t draw;
+ twin_event_func_t event;
+ twin_destroy_func_t destroy;
};
/*
@@ -507,6 +516,18 @@ twin_button_create (twin_box_t *parent,
twin_fixed_t font_size,
twin_style_t font_style);
+twin_dispatch_result_t
+_twin_button_dispatch (twin_widget_t *widget, twin_event_t *event);
+
+void
+_twin_button_init (twin_button_t *button,
+ twin_box_t *parent,
+ const char *value,
+ twin_argb32_t foreground,
+ twin_fixed_t font_size,
+ twin_style_t font_style,
+ twin_dispatch_proc_t dispatch);
+
/*
* twin_convolve.c
*/
@@ -596,10 +617,6 @@ twin_fixed_div (twin_fixed_t a, twin_fixed_t b);
twin_bool_t
twin_has_ucs4 (twin_ucs4_t ucs4);
-#define TWIN_TEXT_ROMAN 0
-#define TWIN_TEXT_BOLD 1
-#define TWIN_TEXT_OBLIQUE 2
-#define TWIN_TEXT_UNHINTED 4
void
twin_path_ucs4_stroke (twin_path_t *path, twin_ucs4_t ucs4);
@@ -962,10 +979,10 @@ void
twin_screen_update (twin_screen_t *screen);
void
-twin_screen_set_active (twin_screen_t *screen, twin_pixmap_t *pixmap);
+twin_screen_set_key_focus (twin_screen_t *screen, twin_pixmap_t *pixmap);
twin_pixmap_t *
-twin_screen_get_active (twin_screen_t *screen);
+twin_screen_get_key_focus (twin_screen_t *screen);
void
twin_screen_set_background (twin_screen_t *screen, twin_pixmap_t *pixmap);
@@ -1016,16 +1033,8 @@ twin_now (void);
*/
twin_toplevel_t *
twin_toplevel_create (twin_screen_t *screen,
- twin_format_t format,
- twin_window_style_t style,
- twin_coord_t x,
- twin_coord_t y,
- twin_coord_t width,
- twin_coord_t height,
- const char *name);
-
-void
-twin_toplevel_show (twin_toplevel_t *toplevel);
+ twin_window_t *window,
+ twin_box_dir_t dir);
/*
* twin_trig.c
@@ -1061,6 +1070,7 @@ twin_widget_set (twin_widget_t *widget, twin_argb32_t background);
twin_window_t *
twin_window_create (twin_screen_t *screen,
+ const char *name,
twin_format_t format,
twin_window_style_t style,
twin_coord_t x,
diff --git a/twin_box.c b/twin_box.c
index 2ebf63b..e172345 100644
--- a/twin_box.c
+++ b/twin_box.c
@@ -32,11 +32,12 @@ _twin_box_init (twin_box_t *box,
twin_dispatch_proc_t dispatch)
{
static twin_widget_layout_t preferred = { 0, 0, 0, 0 };
- _twin_widget_init (&box->widget, parent, window, preferred, dispatch);
- box->dir = dir;
- box->children = NULL;
- box->button_down = NULL;
- box->focus = NULL;
+ _twin_widget_init ((twin_widget_t *) box, parent,
+ window, preferred, dispatch);
+ box->box.dir = dir;
+ box->box.children = NULL;
+ box->box.key_focus = NULL;
+ box->box.pointer_grab = NULL;
}
static twin_dispatch_result_t
@@ -48,7 +49,7 @@ _twin_box_query_geometry (twin_box_t *box)
preferred.width = 0;
preferred.height = 0;
- if (box->dir == TwinBoxHorz)
+ if (box->box.dir == TwinBoxHorz)
{
preferred.stretch_width = 0;
preferred.stretch_height = 10000;
@@ -61,30 +62,30 @@ _twin_box_query_geometry (twin_box_t *box)
/*
* Find preferred geometry
*/
- for (child = box->children; child; child = child->next)
+ for (child = box->box.children; child; child = child->widget.next)
{
- if (child->layout)
+ if (child->widget.layout)
{
ev.kind = TwinEventQueryGeometry;
- (*child->dispatch) (child, &ev);
+ (*child->widget.dispatch) (child, &ev);
}
- if (box->dir == TwinBoxHorz)
+ if (box->box.dir == TwinBoxHorz)
{
- preferred.width += child->preferred.width;
- preferred.stretch_width += child->preferred.stretch_width;
- if (child->preferred.height > preferred.height)
- preferred.height = child->preferred.height;
- if (child->preferred.stretch_height < preferred.stretch_height)
- preferred.stretch_height = child->preferred.stretch_height;
+ preferred.width += child->widget.preferred.width;
+ preferred.stretch_width += child->widget.preferred.stretch_width;
+ if (child->widget.preferred.height > preferred.height)
+ preferred.height = child->widget.preferred.height;
+ if (child->widget.preferred.stretch_height < preferred.stretch_height)
+ preferred.stretch_height = child->widget.preferred.stretch_height;
}
else
{
- preferred.height += child->preferred.height;
- preferred.stretch_height += child->preferred.stretch_height;
- if (child->preferred.width > preferred.width)
- preferred.width = child->preferred.width;
- if (child->preferred.stretch_width < preferred.stretch_width)
- preferred.stretch_width = child->preferred.stretch_width;
+ preferred.height += child->widget.preferred.height;
+ preferred.stretch_height += child->widget.preferred.stretch_height;
+ if (child->widget.preferred.width > preferred.width)
+ preferred.width = child->widget.preferred.width;
+ if (child->widget.preferred.stretch_width < preferred.stretch_width)
+ preferred.stretch_width = child->widget.preferred.stretch_width;
}
}
box->widget.preferred = preferred;
@@ -104,7 +105,7 @@ _twin_box_configure (twin_box_t *box)
twin_coord_t pos = 0;
twin_widget_t *child;
- if (box->dir == TwinBoxHorz)
+ if (box->box.dir == TwinBoxHorz)
{
stretch = box->widget.preferred.stretch_width;
actual = width;
@@ -118,23 +119,21 @@ _twin_box_configure (twin_box_t *box)
}
if (!stretch) stretch = 1;
delta = delta_remain = actual - pref;
- for (child = box->children; child; child = child->next)
+ for (child = box->box.children; child; child = child->widget.next)
{
twin_event_t ev;
twin_coord_t stretch_this;
twin_coord_t delta_this;
twin_rect_t extents;
- if (!child->next)
+ if (box->box.dir == TwinBoxHorz)
+ stretch_this = child->widget.preferred.stretch_width;
+ else
+ stretch_this = child->widget.preferred.stretch_height;
+ if (!child->widget.next && stretch_this)
delta_this = delta_remain;
else
- {
- if (box->dir == TwinBoxHorz)
- stretch_this = child->preferred.stretch_width;
- else
- stretch_this = child->preferred.stretch_height;
delta_this = delta * stretch_this / stretch;
- }
if (delta_remain < 0)
{
if (delta_this < delta_remain)
@@ -146,9 +145,9 @@ _twin_box_configure (twin_box_t *box)
delta_this = delta_remain;
}
delta_remain -= delta_this;
- if (box->dir == TwinBoxHorz)
+ if (box->box.dir == TwinBoxHorz)
{
- twin_coord_t child_w = child->preferred.width;
+ twin_coord_t child_w = child->widget.preferred.width;
extents.top = 0;
extents.bottom = height;
extents.left = pos;
@@ -156,7 +155,7 @@ _twin_box_configure (twin_box_t *box)
}
else
{
- twin_coord_t child_h = child->preferred.height;
+ twin_coord_t child_h = child->widget.preferred.height;
extents.left = 0;
extents.right = width;
extents.top = pos;
@@ -169,7 +168,7 @@ _twin_box_configure (twin_box_t *box)
{
ev.kind = TwinEventConfigure;
ev.u.configure.extents = extents;
- (*child->dispatch) (child, &ev);
+ (*child->widget.dispatch) (child, &ev);
}
}
return TwinDispatchContinue;
@@ -178,13 +177,13 @@ _twin_box_configure (twin_box_t *box)
static twin_widget_t *
_twin_box_xy_to_widget (twin_box_t *box, twin_coord_t x, twin_coord_t y)
{
- twin_widget_t *widget;
+ twin_widget_t *child;
- for (widget = box->children; widget; widget = widget->next)
+ for (child = box->box.children; child; child = child->widget.next)
{
- if (widget->extents.left <= x && x < widget->extents.right &&
- widget->extents.top <= y && y < widget->extents.bottom)
- return widget;
+ if (child->widget.extents.left <= x && x < child->widget.extents.right &&
+ child->widget.extents.top <= y && y < child->widget.extents.bottom)
+ return child;
}
return NULL;
}
@@ -205,45 +204,45 @@ _twin_box_dispatch (twin_widget_t *widget, twin_event_t *event)
case TwinEventConfigure:
return _twin_box_configure (box);
case TwinEventButtonDown:
- box->button_down = _twin_box_xy_to_widget (box,
+ box->box.pointer_grab = _twin_box_xy_to_widget (box,
event->u.pointer.x,
event->u.pointer.y);
- if (box->button_down && box->button_down->want_focus)
- box->focus = box->button_down;
+ if (box->box.pointer_grab && box->box.pointer_grab->widget.want_focus)
+ box->box.key_focus = box->box.pointer_grab;
/* fall through ... */
case TwinEventButtonUp:
case TwinEventMotion:
- if (box->button_down)
+ if (box->box.pointer_grab)
{
- child = box->button_down;
+ child = box->box.pointer_grab;
ev = *event;
- ev.u.pointer.x -= child->extents.left;
- ev.u.pointer.y -= child->extents.top;
- return (*box->button_down->dispatch) (child, &ev);
+ ev.u.pointer.x -= child->widget.extents.left;
+ ev.u.pointer.y -= child->widget.extents.top;
+ return (*box->box.pointer_grab->widget.dispatch) (child, &ev);
}
break;
case TwinEventKeyDown:
case TwinEventKeyUp:
case TwinEventUcs4:
- if (box->focus)
- return (*box->focus->dispatch) (box->focus, event);
+ if (box->box.key_focus)
+ return (*box->box.key_focus->widget.dispatch) (box->box.key_focus, event);
break;
case TwinEventPaint:
box->widget.paint = TWIN_FALSE;
- for (child = box->children; child; child = child->next)
- if (child->paint)
+ for (child = box->box.children; child; child = child->widget.next)
+ if (child->widget.paint)
{
twin_pixmap_t *pixmap = box->widget.window->pixmap;
twin_rect_t clip = twin_pixmap_current_clip (pixmap);
- if (child->shape != TwinShapeRectangle)
- twin_fill (child->window->pixmap,
- widget->background, TWIN_SOURCE,
- child->extents.left, child->extents.top,
- child->extents.right, child->extents.bottom);
- twin_pixmap_set_clip (pixmap, child->extents);
- child->paint = TWIN_FALSE;
- (*child->dispatch) (child, event);
+ if (child->widget.shape != TwinShapeRectangle)
+ twin_fill (child->widget.window->pixmap,
+ widget->widget.background, TWIN_SOURCE,
+ child->widget.extents.left, child->widget.extents.top,
+ child->widget.extents.right, child->widget.extents.bottom);
+ twin_pixmap_set_clip (pixmap, child->widget.extents);
+ child->widget.paint = TWIN_FALSE;
+ (*child->widget.dispatch) (child, event);
twin_pixmap_restore_clip (pixmap, clip);
}
break;
diff --git a/twin_button.c b/twin_button.c
index 347daf1..cdf4d84 100644
--- a/twin_button.c
+++ b/twin_button.c
@@ -29,9 +29,9 @@
static void
_twin_button_paint (twin_button_t *button)
{
- _twin_widget_bevel (&button->label.widget,
+ _twin_widget_bevel ((twin_widget_t *) button,
_twin_button_bw(button),
- button->active);
+ button->button.active);
}
static void
@@ -40,54 +40,56 @@ _twin_button_set_label_offset (twin_button_t *button)
twin_fixed_t bf = _twin_button_bw (button);
twin_fixed_t bh = bf / 2;
- if (button->active)
+ if (button->button.active)
button->label.offset.y = button->label.offset.x = 0;
else
button->label.offset.y = button->label.offset.x = -bh;
- _twin_widget_queue_paint (&button->label.widget);
+ _twin_widget_queue_paint ((twin_widget_t *) button);
}
twin_dispatch_result_t
_twin_button_dispatch (twin_widget_t *widget, twin_event_t *event)
{
twin_button_t *button = (twin_button_t *) widget;
+ twin_event_t ev;
if (_twin_label_dispatch (widget, event) == TwinDispatchDone)
return TwinDispatchDone;
+
switch (event->kind) {
case TwinEventPaint:
_twin_button_paint (button);
break;
case TwinEventButtonDown:
- button->pressed = TWIN_TRUE;
- button->active = TWIN_TRUE;
+ button->button.pressed = TWIN_TRUE;
+ button->button.active = TWIN_TRUE;
_twin_button_set_label_offset (button);
- if (button->signal)
- (*button->signal) (button, TwinButtonSignalDown, button->closure);
+ ev.kind = TwinEventActivate;
+ (*button->widget.dispatch) ((twin_widget_t *) button, &ev);
return TwinDispatchDone;
break;
case TwinEventMotion:
- if (button->pressed)
+ if (button->button.pressed)
{
- twin_bool_t active = _twin_widget_contains (&button->label.widget,
+ twin_bool_t active = _twin_widget_contains ((twin_widget_t *) button,
event->u.pointer.x,
event->u.pointer.y);
- if (active != button->active)
+ if (active != button->button.active)
{
- button->active = active;
+ button->button.active = active;
_twin_button_set_label_offset (button);
}
}
return TwinDispatchDone;
break;
case TwinEventButtonUp:
- button->pressed = TWIN_FALSE;
- if (button->active)
+ button->button.pressed = TWIN_FALSE;
+ if (button->button.active)
{
- button->active = TWIN_FALSE;
+ button->button.active = TWIN_FALSE;
_twin_button_set_label_offset (button);
- if (button->signal)
- (*button->signal) (button, TwinButtonSignalUp, button->closure);
+ ev.kind = TwinEventDeactivate;
+ (*button->widget.dispatch) ((twin_widget_t *) button, &ev);
}
return TwinDispatchDone;
break;
@@ -106,12 +108,10 @@ _twin_button_init (twin_button_t *button,
twin_style_t font_style,
twin_dispatch_proc_t dispatch)
{
- _twin_label_init (&button->label, parent, value,
+ _twin_label_init ((twin_label_t *) button, parent, value,
foreground, font_size, font_style, dispatch);
- button->pressed = TWIN_FALSE;
- button->active = TWIN_FALSE;
- button->signal = NULL;
- button->closure = NULL;
+ button->button.pressed = TWIN_FALSE;
+ button->button.active = TWIN_FALSE;
_twin_button_set_label_offset (button);
}
diff --git a/twin_calc.c b/twin_calc.c
index 36dfda9..71a249a 100644
--- a/twin_calc.c
+++ b/twin_calc.c
@@ -82,11 +82,11 @@ static const char *twin_calc_labels[] = {
};
#define TWIN_CALC_VALUE_SIZE twin_int_to_fixed(29)
-#define TWIN_CALC_VALUE_STYLE TWIN_TEXT_ROMAN
+#define TWIN_CALC_VALUE_STYLE TwinStyleRoman
#define TWIN_CALC_VALUE_FG 0xff000000
#define TWIN_CALC_VALUE_BG 0x80808080
#define TWIN_CALC_BUTTON_SIZE twin_int_to_fixed(15)
-#define TWIN_CALC_BUTTON_STYLE TWIN_TEXT_BOLD
+#define TWIN_CALC_BUTTON_STYLE TwinStyleBold
#define TWIN_CALC_BUTTON_FG 0xff000000
#define TWIN_CALC_BUTTON_BG 0xc0808080
@@ -143,18 +143,19 @@ _twin_calc_digit (twin_calc_t *calc, int digit)
_twin_calc_update_value (calc);
}
-static void
-_twin_calc_button_signal (twin_button_t *button,
- twin_button_signal_t signal,
- void *closure)
+static twin_dispatch_result_t
+_twin_calc_button_dispatch (twin_widget_t *widget,
+ twin_event_t *event)
{
- twin_calc_t *calc = closure;
+ twin_button_t *button = (twin_button_t *) widget;
+ twin_calc_t *calc = button->widget.closure;
int i;
int a, b;
- if (signal != TwinButtonSignalDown) return;
+ if (event->kind != TwinEventActivate)
+ return _twin_button_dispatch (widget, event);
i = _twin_calc_button_to_id (calc, button);
- if (i < 0) return;
+ if (i < 0) return TwinDispatchDone;
switch (i) {
case TWIN_CALC_PLUS:
case TWIN_CALC_MINUS:
@@ -192,6 +193,7 @@ _twin_calc_button_signal (twin_button_t *button,
_twin_calc_digit (calc, i);
break;
}
+ return TwinDispatchDone;
}
void
@@ -200,19 +202,19 @@ twin_calc_start (twin_screen_t *screen, const char *name, int x, int y, int w, i
twin_calc_t *calc = malloc (sizeof (twin_calc_t));
int i, j;
- calc->toplevel = twin_toplevel_create (screen,
- TWIN_ARGB32,
- TwinWindowApplication,
- x, y, w, h, name);
- calc->display = twin_label_create (&calc->toplevel->box,
+ calc->window = twin_window_create (screen, name, TWIN_ARGB32,
+ TwinWindowApplication,
+ x, y, w, h);
+ calc->toplevel = calc->window->toplevel;
+ calc->display = twin_label_create (calc->toplevel,
"0",
TWIN_CALC_VALUE_FG,
TWIN_CALC_VALUE_SIZE,
TWIN_CALC_VALUE_STYLE);
- twin_widget_set (&calc->display->widget, TWIN_CALC_VALUE_BG);
- calc->display->align = TwinAlignRight;
+ twin_widget_set ((twin_widget_t *) calc->display, TWIN_CALC_VALUE_BG);
+ calc->display->label.align = TwinAlignRight;
calc->display->widget.shape = TwinShapeLozenge;
- calc->keys = twin_box_create (&calc->toplevel->box, TwinBoxHorz);
+ calc->keys = twin_box_create (calc->toplevel, TwinBoxHorz);
for (i = 0; i < TWIN_CALC_COLS; i++)
{
calc->cols[i] = twin_box_create (calc->keys, TwinBoxVert);
@@ -224,13 +226,13 @@ twin_calc_start (twin_screen_t *screen, const char *name, int x, int y, int w, i
TWIN_CALC_BUTTON_FG,
TWIN_CALC_BUTTON_SIZE,
TWIN_CALC_BUTTON_STYLE);
- twin_widget_set (&calc->buttons[b]->label.widget,
+ twin_widget_set ((twin_widget_t *) calc->buttons[b],
TWIN_CALC_BUTTON_BG);
- calc->buttons[b]->signal = _twin_calc_button_signal;
- calc->buttons[b]->closure = calc;
+ calc->buttons[b]->widget.dispatch = _twin_calc_button_dispatch;
+ calc->buttons[b]->widget.closure = calc;
/* calc->buttons[b]->label.widget.shape = TwinShapeLozenge; */
if (i || j)
- calc->buttons[b]->label.widget.copy_geom = &calc->buttons[calc_layout[0][0]]->label.widget;
+ calc->buttons[b]->widget.copy_geom = (twin_widget_t *) calc->buttons[calc_layout[0][0]];
}
}
@@ -238,5 +240,5 @@ twin_calc_start (twin_screen_t *screen, const char *name, int x, int y, int w, i
calc->stack[i] = 0;
calc->pending_delete = TWIN_TRUE;
calc->pending_op = 0;
- twin_toplevel_show (calc->toplevel);
+ twin_window_show (calc->window);
}
diff --git a/twin_calc.h b/twin_calc.h
index 0d3df7d..2015685 100644
--- a/twin_calc.h
+++ b/twin_calc.h
@@ -22,8 +22,6 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-#include <twin.h>
-
#ifndef _TWIN_CALC_H_
#define _TWIN_CALC_H_
diff --git a/twin_clock.c b/twin_clock.c
index 7fe5bee..565e280 100644
--- a/twin_clock.c
+++ b/twin_clock.c
@@ -130,7 +130,7 @@ _twin_clock_face (twin_clock_t *clock)
twin_path_empty (path);
twin_path_rotate (path, twin_degrees_to_angle (-11) + TWIN_ANGLE_90);
twin_path_set_font_size (path, D(0.5));
- twin_path_set_font_style (path, TWIN_TEXT_UNHINTED|TWIN_TEXT_OBLIQUE);
+ twin_path_set_font_style (path, TwinStyleUnhinted|TwinStyleOblique);
twin_text_metrics_utf8 (path, label, &metrics);
height = metrics.ascent + metrics.descent;
width = metrics.right_side_bearing - metrics.left_side_bearing;
@@ -147,7 +147,7 @@ _twin_clock_face (twin_clock_t *clock)
}
twin_path_set_font_size (path, D(0.2));
- twin_path_set_font_style (path, TWIN_TEXT_UNHINTED);
+ twin_path_set_font_style (path, TwinStyleUnhinted);
for (m = 1; m <= 60; m++)
{
@@ -219,7 +219,7 @@ static twin_time_t
_twin_clock_timeout (twin_time_t now, void *closure)
{
twin_clock_t *clock = closure;
- _twin_widget_queue_paint (&clock->widget);
+ _twin_widget_queue_paint ((twin_widget_t *) clock);
return _twin_clock_interval ();
}
@@ -246,8 +246,8 @@ _twin_clock_init (twin_clock_t *clock,
twin_dispatch_proc_t dispatch)
{
static const twin_widget_layout_t preferred = { 0, 0, 1, 1 };
- _twin_widget_init (&clock->widget, parent, 0, preferred, dispatch);
- clock->timeout = twin_set_timeout (_twin_clock_timeout,
+ _twin_widget_init ((twin_widget_t *) clock, parent, 0, preferred, dispatch);
+ clock->clock.timeout = twin_set_timeout (_twin_clock_timeout,
_twin_clock_interval(),
clock);
}
@@ -264,10 +264,12 @@ twin_clock_create (twin_box_t *parent)
void
twin_clock_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h)
{
- twin_toplevel_t *toplevel = twin_toplevel_create (screen, TWIN_ARGB32,
- TwinWindowApplication,
- x, y, w, h, name);
- twin_clock_t *clock = twin_clock_create (&toplevel->box);
+ twin_window_t *window = twin_window_create (screen, name,
+ TWIN_ARGB32,
+ TwinWindowApplication,
+ x, y, w, h);
+ twin_toplevel_t *toplevel = window->toplevel;
+ twin_clock_t *clock = twin_clock_create (toplevel);
(void) clock;
- twin_toplevel_show (toplevel);
+ twin_window_show (window);
}
diff --git a/twin_clock.h b/twin_clock.h
index ec0947d..6a96d87 100644
--- a/twin_clock.h
+++ b/twin_clock.h
@@ -27,9 +27,13 @@
#include <twin.h>
-typedef struct _twin_clock {
- twin_widget_t widget;
+typedef struct _twin_clock_part {
twin_timeout_t *timeout;
+} twin_clock_part_t;
+
+typedef struct _twin_clock {
+ twin_widget_part_t widget;
+ twin_clock_part_t clock;
} twin_clock_t;
void
diff --git a/twin_demo.c b/twin_demo.c
index 8e8a37e..80a7fdf 100644
--- a/twin_demo.c
+++ b/twin_demo.c
@@ -75,7 +75,7 @@ twin_example_start (twin_screen_t *screen, int x, int y, int w, int h)
static void
twin_line_start (twin_screen_t *screen, int x, int y, int w, int h)
{
- twin_window_t *window = twin_window_create (screen, TWIN_ARGB32,
+ twin_window_t *window = twin_window_create (screen, "line", TWIN_ARGB32,
TwinWindowApplication,
x, y, w, h);
twin_pixmap_t *pixmap = window->pixmap;
@@ -86,8 +86,6 @@ twin_line_start (twin_screen_t *screen, int x, int y, int w, int h)
twin_fill (pixmap, 0xffffffff, TWIN_SOURCE,
0, 0, w, h);
- twin_window_set_name (window, "line");
-
for (fy = 0; fy < 150; fy += 40)
{
twin_path_move (stroke, D(-150), -D(fy));
@@ -102,7 +100,8 @@ twin_line_start (twin_screen_t *screen, int x, int y, int w, int h)
static void
twin_circletext_start (twin_screen_t *screen, int x, int y, int w, int h)
{
- twin_window_t *window = twin_window_create (screen, TWIN_ARGB32,
+ twin_window_t *window = twin_window_create (screen, "circletext",
+ TWIN_ARGB32,
TwinWindowApplication,
x, y, w, h);
int wid = window->client.right - window->client.left;
@@ -118,7 +117,7 @@ twin_circletext_start (twin_screen_t *screen, int x, int y, int w, int h)
0, 0, wid, hei);
twin_window_set_name (window, "circletext");
- twin_path_set_font_style (path, TWIN_TEXT_UNHINTED);
+ twin_path_set_font_style (path, TwinStyleUnhinted);
twin_path_circle (pen, 0, 0, D (1));
twin_path_translate (path, D(200), D(200));
@@ -147,7 +146,8 @@ twin_circletext_start (twin_screen_t *screen, int x, int y, int w, int h)
static void
twin_quickbrown_start (twin_screen_t *screen, int x, int y, int w, int h)
{
- twin_window_t *window = twin_window_create (screen, TWIN_ARGB32,
+ twin_window_t *window = twin_window_create (screen, "Quick Brown",
+ TWIN_ARGB32,
TwinWindowApplication,
x, y, w, h);
int wid = window->client.right - window->client.left;
@@ -196,7 +196,8 @@ twin_quickbrown_start (twin_screen_t *screen, int x, int y, int w, int h)
static void
twin_ascii_start (twin_screen_t *screen, int x, int y, int w, int h)
{
- twin_window_t *window = twin_window_create (screen, TWIN_ARGB32,
+ twin_window_t *window = twin_window_create (screen, "ASCII",
+ TWIN_ARGB32,
TwinWindowApplication,
x, y, w, h);
int wid = window->client.right - window->client.left;
@@ -250,7 +251,7 @@ twin_ascii_start (twin_screen_t *screen, int x, int y, int w, int h)
static void
twin_jelly_start (twin_screen_t *screen, int x, int y, int w, int h)
{
- twin_window_t *window = twin_window_create (screen, TWIN_ARGB32,
+ twin_window_t *window = twin_window_create (screen, "Jelly", TWIN_ARGB32,
TwinWindowApplication,
x, y, w, h);
int wid = window->client.right - window->client.left;
diff --git a/twin_demoline.c b/twin_demoline.c
index 3e3837f..608f156 100644
--- a/twin_demoline.c
+++ b/twin_demoline.c
@@ -51,11 +51,11 @@ _twin_demoline_paint (twin_demoline_t *demoline)
twin_path_t *path;
path = twin_path_create ();
- twin_path_set_cap_style (path, demoline->cap_style);
- twin_path_move (path, demoline->points[0].x, demoline->points[0].y);
- twin_path_draw (path, demoline->points[1].x, demoline->points[1].y);
+ twin_path_set_cap_style (path, demoline->demoline.cap_style);
+ twin_path_move (path, demoline->demoline.points[0].x, demoline->demoline.points[0].y);
+ twin_path_draw (path, demoline->demoline.points[1].x, demoline->demoline.points[1].y);
twin_paint_stroke (_twin_demoline_pixmap(demoline), 0xff000000, path,
- demoline->line_width);
+ demoline->demoline.line_width);
twin_path_set_cap_style (path, TwinCapButt);
twin_paint_stroke (_twin_demoline_pixmap(demoline), 0xffff0000, path,
twin_int_to_fixed (2));
@@ -65,11 +65,11 @@ _twin_demoline_paint (twin_demoline_t *demoline)
static twin_dispatch_result_t
_twin_demoline_update_pos (twin_demoline_t *demoline, twin_event_t *event)
{
- if (demoline->which < 0)
+ if (demoline->demoline.which < 0)
return TwinDispatchContinue;
- demoline->points[demoline->which].x = twin_int_to_fixed (event->u.pointer.x);
- demoline->points[demoline->which].y = twin_int_to_fixed (event->u.pointer.y);
- _twin_widget_queue_paint (&demoline->widget);
+ demoline->demoline.points[demoline->demoline.which].x = twin_int_to_fixed (event->u.pointer.x);
+ demoline->demoline.points[demoline->demoline.which].y = twin_int_to_fixed (event->u.pointer.y);
+ _twin_widget_queue_paint ((twin_widget_t *) demoline);
return TwinDispatchDone;
}
@@ -81,8 +81,8 @@ _twin_demoline_hit (twin_demoline_t *demoline, twin_fixed_t x, twin_fixed_t y)
int i;
for (i = 0; i < 2; i++)
- if (twin_fixed_abs (x - demoline->points[i].x) < demoline->line_width / 2 &&
- twin_fixed_abs (y - demoline->points[i].y) < demoline->line_width / 2)
+ if (twin_fixed_abs (x - demoline->demoline.points[i].x) < demoline->demoline.line_width / 2 &&
+ twin_fixed_abs (y - demoline->demoline.points[i].y) < demoline->demoline.line_width / 2)
return i;
return -1;
}
@@ -99,7 +99,7 @@ _twin_demoline_dispatch (twin_widget_t *widget, twin_event_t *event)
_twin_demoline_paint (demoline);
break;
case TwinEventButtonDown:
- demoline->which = _twin_demoline_hit (demoline,
+ demoline->demoline.which = _twin_demoline_hit (demoline,
twin_int_to_fixed (event->u.pointer.x),
twin_int_to_fixed (event->u.pointer.y));
return _twin_demoline_update_pos (demoline, event);
@@ -108,10 +108,10 @@ _twin_demoline_dispatch (twin_widget_t *widget, twin_event_t *event)
return _twin_demoline_update_pos (demoline, event);
break;
case TwinEventButtonUp:
- if (demoline->which < 0)
+ if (demoline->demoline.which < 0)
return TwinDispatchContinue;
_twin_demoline_update_pos (demoline, event);
- demoline->which = -1;
+ demoline->demoline.which = -1;
return TwinDispatchDone;
break;
default:
@@ -126,14 +126,14 @@ _twin_demoline_init (twin_demoline_t *demoline,
twin_dispatch_proc_t dispatch)
{
static const twin_widget_layout_t preferred = { 0, 0, 1, 1 };
- _twin_widget_init (&demoline->widget, parent, 0, preferred, dispatch);
- twin_widget_set (&demoline->widget, 0xffffffff);
- demoline->line_width = twin_int_to_fixed (30);
- demoline->cap_style = TwinCapProjecting;
- demoline->points[0].x = twin_int_to_fixed (50);
- demoline->points[0].y = twin_int_to_fixed (50);
- demoline->points[1].x = twin_int_to_fixed (100);
- demoline->points[1].y = twin_int_to_fixed (100);
+ _twin_widget_init ((twin_widget_t *) demoline, parent, 0, preferred, dispatch);
+ twin_widget_set ((twin_widget_t *) demoline, 0xffffffff);
+ demoline->demoline.line_width = twin_int_to_fixed (30);
+ demoline->demoline.cap_style = TwinCapProjecting;
+ demoline->demoline.points[0].x = twin_int_to_fixed (50);
+ demoline->demoline.points[0].y = twin_int_to_fixed (50);
+ demoline->demoline.points[1].x = twin_int_to_fixed (100);
+ demoline->demoline.points[1].y = twin_int_to_fixed (100);
}
twin_demoline_t *
@@ -148,10 +148,11 @@ twin_demoline_create (twin_box_t *parent)
void
twin_demoline_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h)
{
- twin_toplevel_t *toplevel = twin_toplevel_create (screen, TWIN_ARGB32,
- TwinWindowApplication,
- x, y, w, h, name);
- twin_demoline_t *demoline = twin_demoline_create (&toplevel->box);
+ twin_window_t *window = twin_window_create (screen, name, TWIN_ARGB32,
+ TwinWindowApplication,
+ x,y,w,h);
+ twin_toplevel_t *toplevel = window->toplevel;
+ twin_demoline_t *demoline = twin_demoline_create (toplevel);
(void) demoline;
- twin_toplevel_show (toplevel);
+ twin_window_show (window);
}
diff --git a/twin_demoline.h b/twin_demoline.h
index 433c7f0..f5f929b 100644
--- a/twin_demoline.h
+++ b/twin_demoline.h
@@ -27,12 +27,16 @@
#include <twin.h>
-typedef struct _twin_demoline {
- twin_widget_t widget;
+typedef struct _twin_demoline_part {
twin_point_t points[2];
int which;
twin_fixed_t line_width;
twin_cap_t cap_style;
+} twin_demoline_part_t;
+
+typedef struct _twin_demoline {
+ twin_widget_part_t widget;
+ twin_demoline_part_t demoline;
} twin_demoline_t;
void
diff --git a/twin_demospline.c b/twin_demospline.c
index 0ae02be..0cf81dd 100644
--- a/twin_demospline.c
+++ b/twin_demospline.c
@@ -37,33 +37,33 @@ _twin_demospline_paint (twin_demospline_t *demospline)
int i;
path = twin_path_create ();
- twin_path_set_cap_style (path, demospline->cap_style);
- twin_path_move (path, demospline->points[0].x, demospline->points[0].y);
+ twin_path_set_cap_style (path, demospline->demospline.cap_style);
+ twin_path_move (path, demospline->demospline.points[0].x, demospline->demospline.points[0].y);
twin_path_curve (path,
- demospline->points[1].x, demospline->points[1].y,
- demospline->points[2].x, demospline->points[2].y,
- demospline->points[3].x, demospline->points[3].y);
+ demospline->demospline.points[1].x, demospline->demospline.points[1].y,
+ demospline->demospline.points[2].x, demospline->demospline.points[2].y,
+ demospline->demospline.points[3].x, demospline->demospline.points[3].y);
twin_paint_stroke (_twin_demospline_pixmap(demospline), 0xff404040, path,
- demospline->line_width);
+ demospline->demospline.line_width);
twin_path_set_cap_style (path, TwinCapButt);
twin_paint_stroke (_twin_demospline_pixmap(demospline), 0xffffff00, path,
twin_int_to_fixed (2));
twin_path_empty (path);
- twin_path_move (path, demospline->points[0].x, demospline->points[0].y);
- twin_path_draw (path, demospline->points[1].x, demospline->points[1].y);
+ twin_path_move (path, demospline->demospline.points[0].x, demospline->demospline.points[0].y);
+ twin_path_draw (path, demospline->demospline.points[1].x, demospline->demospline.points[1].y);
twin_paint_stroke (_twin_demospline_pixmap(demospline), 0xc08000c0, path,
twin_int_to_fixed (2));
twin_path_empty (path);
- twin_path_move (path, demospline->points[3].x, demospline->points[3].y);
- twin_path_draw (path, demospline->points[2].x, demospline->points[2].y);
+ twin_path_move (path, demospline->demospline.points[3].x, demospline->demospline.points[3].y);
+ twin_path_draw (path, demospline->demospline.points[2].x, demospline->demospline.points[2].y);
twin_paint_stroke (_twin_demospline_pixmap(demospline), 0xc08000c0, path,
twin_int_to_fixed (2));
twin_path_empty (path);
for (i = 0; i < NPT; i++)
{
twin_path_empty (path);
- twin_path_circle (path, demospline->points[i].x, demospline->points[i].y,
+ twin_path_circle (path, demospline->demospline.points[i].x, demospline->demospline.points[i].y,
twin_int_to_fixed (10));
twin_paint_path (_twin_demospline_pixmap(demospline), 0x40004020, path);
}
@@ -73,11 +73,11 @@ _twin_demospline_paint (twin_demospline_t *demospline)
static twin_dispatch_result_t
_twin_demospline_update_pos (twin_demospline_t *demospline, twin_event_t *event)
{
- if (demospline->which < 0)
+ if (demospline->demospline.which < 0)
return TwinDispatchContinue;
- demospline->points[demospline->which].x = twin_int_to_fixed (event->u.pointer.x);
- demospline->points[demospline->which].y = twin_int_to_fixed (event->u.pointer.y);
- _twin_widget_queue_paint (&demospline->widget);
+ demospline->demospline.points[demospline->demospline.which].x = twin_int_to_fixed (event->u.pointer.x);
+ demospline->demospline.points[demospline->demospline.which].y = twin_int_to_fixed (event->u.pointer.y);
+ _twin_widget_queue_paint ((twin_widget_t *) demospline);
return TwinDispatchDone;
}
@@ -89,8 +89,8 @@ _twin_demospline_hit (twin_demospline_t *demospline, twin_fixed_t x, twin_fixed_
int i;
for (i = 0; i < NPT; i++)
- if (twin_fixed_abs (x - demospline->points[i].x) < demospline->line_width / 2 &&
- twin_fixed_abs (y - demospline->points[i].y) < demospline->line_width / 2)
+ if (twin_fixed_abs (x - demospline->demospline.points[i].x) < demospline->demospline.line_width / 2 &&
+ twin_fixed_abs (y - demospline->demospline.points[i].y) < demospline->demospline.line_width / 2)
return i;
return -1;
}
@@ -107,7 +107,7 @@ _twin_demospline_dispatch (twin_widget_t *widget, twin_event_t *event)
_twin_demospline_paint (demospline);
break;
case TwinEventButtonDown:
- demospline->which = _twin_demospline_hit (demospline,
+ demospline->demospline.which = _twin_demospline_hit (demospline,
twin_int_to_fixed (event->u.pointer.x),
twin_int_to_fixed (event->u.pointer.y));
return _twin_demospline_update_pos (demospline, event);
@@ -116,10 +116,10 @@ _twin_demospline_dispatch (twin_widget_t *widget, twin_event_t *event)
return _twin_demospline_update_pos (demospline, event);
break;
case TwinEventButtonUp:
- if (demospline->which < 0)
+ if (demospline->demospline.which < 0)
return TwinDispatchContinue;
_twin_demospline_update_pos (demospline, event);
- demospline->which = -1;
+ demospline->demospline.which = -1;
return TwinDispatchDone;
break;
default:
@@ -134,18 +134,18 @@ _twin_demospline_init (twin_demospline_t *demospline,
twin_dispatch_proc_t dispatch)
{
static const twin_widget_layout_t preferred = { 0, 0, 1, 1 };
- _twin_widget_init (&demospline->widget, parent, 0, preferred, dispatch);
- twin_widget_set (&demospline->widget, 0xffffffff);
- demospline->line_width = twin_int_to_fixed (100);
- demospline->cap_style = TwinCapButt;
- demospline->points[0].x = twin_int_to_fixed (100);
- demospline->points[0].y = twin_int_to_fixed (100);
- demospline->points[1].x = twin_int_to_fixed (300);
- demospline->points[1].y = twin_int_to_fixed (300);
- demospline->points[2].x = twin_int_to_fixed (100);
- demospline->points[2].y = twin_int_to_fixed (300);
- demospline->points[3].x = twin_int_to_fixed (300);
- demospline->points[3].y = twin_int_to_fixed (100);
+ _twin_widget_init ((twin_widget_t *) demospline, parent, 0, preferred, dispatch);
+ twin_widget_set ((twin_widget_t *) demospline, 0xffffffff);
+ demospline->demospline.line_width = twin_int_to_fixed (100);
+ demospline->demospline.cap_style = TwinCapRound;
+ demospline->demospline.points[0].x = twin_int_to_fixed (100);
+ demospline->demospline.points[0].y = twin_int_to_fixed (100);
+ demospline->demospline.points[1].x = twin_int_to_fixed (300);
+ demospline->demospline.points[1].y = twin_int_to_fixed (300);
+ demospline->demospline.points[2].x = twin_int_to_fixed (100);
+ demospline->demospline.points[2].y = twin_int_to_fixed (300);
+ demospline->demospline.points[3].x = twin_int_to_fixed (300);
+ demospline->demospline.points[3].y = twin_int_to_fixed (100);
}
twin_demospline_t *
@@ -160,10 +160,11 @@ twin_demospline_create (twin_box_t *parent)
void
twin_demospline_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h)
{
- twin_toplevel_t *toplevel = twin_toplevel_create (screen, TWIN_ARGB32,
- TwinWindowApplication,
- x, y, w, h, name);
- twin_demospline_t *demospline = twin_demospline_create (&toplevel->box);
+ twin_window_t *window = twin_window_create (screen, name, TWIN_ARGB32,
+ TwinWindowApplication,
+ x, y, w, h);
+ twin_toplevel_t *toplevel = window->toplevel;
+ twin_demospline_t *demospline = twin_demospline_create (toplevel);
(void) demospline;
- twin_toplevel_show (toplevel);
+ twin_window_show (window);
}
diff --git a/twin_demospline.h b/twin_demospline.h
index 87f7ae7..a5af94b 100644
--- a/twin_demospline.h
+++ b/twin_demospline.h
@@ -29,12 +29,16 @@
#define NPT 4
-typedef struct _twin_demospline {
- twin_widget_t widget;
+typedef struct _twin_demospline_part {
twin_point_t points[NPT];
int which;
twin_fixed_t line_width;
twin_cap_t cap_style;
+} twin_demospline_part_t;
+
+typedef struct _twin_demospline {
+ twin_widget_part_t widget;
+ twin_demospline_part_t demospline;
} twin_demospline_t;
void
diff --git a/twin_font.c b/twin_font.c
index aaf22d2..9f99df1 100644
--- a/twin_font.c
+++ b/twin_font.c
@@ -61,7 +61,7 @@ _twin_text_compute_info (twin_path_t *path, twin_text_info_t *info)
/*
* Only hint axis aligned text
*/
- if ((path->state.font_style & TWIN_TEXT_UNHINTED) == 0 &&
+ if ((path->state.font_style & TwinStyleUnhinted) == 0 &&
((path->state.matrix.m[0][1] == 0 &&
path->state.matrix.m[1][0] == 0) ||
(path->state.matrix.m[0][0] == 0 &&
@@ -112,7 +112,7 @@ _twin_text_compute_info (twin_path_t *path, twin_text_info_t *info)
info->pen.y = TWIN_FIXED_HALF;
info->margin.x = info->pen.x;
info->margin.y = info->pen.y;
- if (path->state.font_style & TWIN_TEXT_BOLD)
+ if (path->state.font_style & TwinStyleBold)
{
twin_fixed_t pen_x_add = SNAPH(info->pen.x >> 1);
twin_fixed_t pen_y_add = SNAPH(info->pen.y >> 1);
@@ -140,7 +140,7 @@ _twin_text_compute_info (twin_path_t *path, twin_text_info_t *info)
info->scale.x = path->state.font_size;
info->scale.y = path->state.font_size;
- if (path->state.font_style & TWIN_TEXT_BOLD)
+ if (path->state.font_style & TwinStyleBold)
info->pen.x = path->state.font_size / 16;
else
info->pen.x = path->state.font_size / 24;
@@ -156,7 +156,7 @@ _twin_text_compute_info (twin_path_t *path, twin_text_info_t *info)
info->pen_matrix.m[2][0] = 0; info->pen_matrix.m[2][1] = 0;
twin_matrix_scale (&info->pen_matrix, info->pen.x, info->pen.y);
- if (path->state.font_style & TWIN_TEXT_OBLIQUE)
+ if (path->state.font_style & TwinStyleOblique)
{
twin_matrix_t m;
diff --git a/twin_hello.c b/twin_hello.c
index ad78029..d04f4f8 100644
--- a/twin_hello.c
+++ b/twin_hello.c
@@ -37,39 +37,39 @@ _twin_hello_timeout (twin_time_t now, void *closure)
twin_label_set (labelb, t,
0xff008000,
twin_int_to_fixed (12),
- TWIN_TEXT_OBLIQUE);
+ TwinStyleOblique);
return 1000;
}
void
twin_hello_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h)
{
- twin_toplevel_t *top = twin_toplevel_create (screen,
- TWIN_ARGB32,
- TwinWindowApplication,
- x, y, w, h, name);
- twin_label_t *labela = twin_label_create (&top->box,
+ twin_window_t *window = twin_window_create (screen, name, TWIN_ARGB32,
+ TwinWindowApplication,
+ x, y, w, h);
+ twin_toplevel_t *top = window->toplevel;
+ twin_label_t *labela = twin_label_create (top,
name,
0xff000080,
twin_int_to_fixed (12),
- TWIN_TEXT_ROMAN);
- twin_widget_t *widget = twin_widget_create (&top->box,
+ TwinStyleRoman);
+ twin_widget_t *widget = twin_widget_create (top,
0xff800000,
1, 2, 0, 0);
- twin_label_t *labelb = twin_label_create (&top->box,
+ twin_label_t *labelb = twin_label_create (top,
name,
0xff008000,
twin_int_to_fixed (12),
- TWIN_TEXT_OBLIQUE);
- twin_button_t *button = twin_button_create (&top->box,
+ TwinStyleOblique);
+ twin_button_t *button = twin_button_create (top,
"Button",
0xff800000,
twin_int_to_fixed (18),
- TWIN_TEXT_BOLD|TWIN_TEXT_OBLIQUE);
- twin_widget_set (&labela->widget, 0xc0c0c0c0);
+ TwinStyleBold|TwinStyleOblique);
+ twin_widget_set ((twin_widget_t *) labela, 0xc0c0c0c0);
(void) widget;
- twin_widget_set (&labelb->widget, 0xc0c0c0c0);
- twin_widget_set (&button->label.widget, 0xc0808080);
- twin_toplevel_show (top);
+ twin_widget_set ((twin_widget_t *) labelb, 0xc0c0c0c0);
+ twin_widget_set ((twin_widget_t *) button, 0xc0808080);
+ twin_window_show (window);
twin_set_timeout (_twin_hello_timeout, 1000, labelb);
}
diff --git a/twin_label.c b/twin_label.c
index fb43372..debd609 100644
--- a/twin_label.c
+++ b/twin_label.c
@@ -30,13 +30,13 @@ _twin_label_query_geometry (twin_label_t *label)
twin_path_t *path = twin_path_create ();
twin_text_metrics_t m;
- label->widget.preferred.width = twin_fixed_to_int (label->font_size) * 2;
- label->widget.preferred.height = twin_fixed_to_int (label->font_size) * 2;
+ label->widget.preferred.width = twin_fixed_to_int (label->label.font_size) * 2;
+ label->widget.preferred.height = twin_fixed_to_int (label->label.font_size) * 2;
if (path)
{
- twin_path_set_font_size (path, label->font_size);
- twin_path_set_font_style (path, label->font_style);
- twin_text_metrics_utf8 (path, label->label, &m);
+ twin_path_set_font_size (path, label->label.font_size);
+ twin_path_set_font_style (path, label->label.font_style);
+ twin_text_metrics_utf8 (path, label->label.label, &m);
label->widget.preferred.width += twin_fixed_to_int (m.width);
twin_path_destroy (path);
}
@@ -56,25 +56,25 @@ _twin_label_paint (twin_label_t *label)
twin_fixed_t hf = twin_int_to_fixed (h);
twin_fixed_t x, y;
- twin_path_set_font_size (path, label->font_size);
- twin_path_set_font_style (path, label->font_style);
- twin_text_metrics_utf8 (path, label->label, &m);
- y = (hf - (m.ascent + m.descent)) / 2 + m.ascent + label->offset.y;
- switch (label->align) {
+ twin_path_set_font_size (path, label->label.font_size);
+ twin_path_set_font_style (path, label->label.font_style);
+ twin_text_metrics_utf8 (path, label->label.label, &m);
+ y = (hf - (m.ascent + m.descent)) / 2 + m.ascent + label->label.offset.y;
+ switch (label->label.align) {
case TwinAlignLeft:
- x = label->font_size / 2;
+ x = label->label.font_size / 2;
break;
case TwinAlignCenter:
x = (wf - m.width) / 2;
break;
case TwinAlignRight:
- x = wf - label->font_size / 2 - m.width;
+ x = wf - label->label.font_size / 2 - m.width;
break;
}
- x += label->offset.x;
+ x += label->label.offset.x;
twin_path_move (path, x, y);
- twin_path_utf8 (path, label->label);
- twin_paint_path (label->widget.window->pixmap, label->foreground, path);
+ twin_path_utf8 (path, label->label.label);
+ twin_paint_path (label->widget.window->pixmap, label->label.foreground, path);
twin_path_destroy (path);
}
}
@@ -112,16 +112,16 @@ twin_label_set (twin_label_t *label,
if (new)
{
- if (label->label)
- free (label->label);
- label->label = new;
- strcpy (label->label, value);
+ if (label->label.label)
+ free (label->label.label);
+ label->label.label = new;
+ strcpy (label->label.label, value);
}
}
- label->font_size = font_size;
- label->font_style = font_style;
- label->foreground = foreground;
- _twin_widget_queue_layout (&label->widget);
+ label->label.font_size = font_size;
+ label->label.font_style = font_style;
+ label->label.foreground = foreground;
+ _twin_widget_queue_layout ((twin_widget_t *) label);
}
void
@@ -134,11 +134,11 @@ _twin_label_init (twin_label_t *label,
twin_dispatch_proc_t dispatch)
{
static const twin_widget_layout_t preferred = { 0, 0, 1, 1 };
- _twin_widget_init (&label->widget, parent, 0, preferred, dispatch);
- label->label = NULL;
- label->offset.x = 0;
- label->offset.y = 0;
- label->align = TwinAlignCenter;
+ _twin_widget_init ((twin_widget_t *) label, parent, 0, preferred, dispatch);
+ label->label.label = NULL;
+ label->label.offset.x = 0;
+ label->label.offset.y = 0;
+ label->label.align = TwinAlignCenter;
twin_label_set (label, value, foreground, font_size, font_style);
}
diff --git a/twin_path.c b/twin_path.c
index a226fff..e42a0b5 100644
--- a/twin_path.c
+++ b/twin_path.c
@@ -512,7 +512,7 @@ twin_path_create (void)
path->sublen = 0;
twin_matrix_identity (&path->state.matrix);
path->state.font_size = TWIN_FIXED_ONE * 15;
- path->state.font_style = TWIN_TEXT_ROMAN;
+ path->state.font_style = TwinStyleRoman;
path->state.cap_style = TwinCapRound;
return path;
}
diff --git a/twin_pixmap.c b/twin_pixmap.c
index 5a5adf8..c9bd133 100644
--- a/twin_pixmap.c
+++ b/twin_pixmap.c
@@ -276,8 +276,8 @@ twin_pixmap_move (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y)
twin_bool_t
twin_pixmap_dispatch (twin_pixmap_t *pixmap, twin_event_t *event)
{
- if (pixmap->window)
- return twin_window_dispatch (pixmap->window, event);
+ if (pixmap->toplevel)
+ return _twin_toplevel_dispatch ((twin_widget_t *) pixmap->toplevel, event) == TwinDispatchDone;
return TWIN_FALSE;
}
diff --git a/twin_screen.c b/twin_screen.c
index 0f1a611..d53c4fe 100644
--- a/twin_screen.c
+++ b/twin_screen.c
@@ -218,11 +218,11 @@ twin_screen_update (twin_screen_t *screen)
}
void
-twin_screen_set_active (twin_screen_t *screen, twin_pixmap_t *pixmap)
+twin_screen_set_key_focus (twin_screen_t *screen, twin_pixmap_t *pixmap)
{
twin_event_t ev;
- twin_pixmap_t *old = screen->active;
- screen->active = pixmap;
+ twin_pixmap_t *old = screen->key_focus;
+ screen->key_focus = pixmap;
if (old)
{
ev.kind = TwinEventDeactivate;
@@ -236,9 +236,9 @@ twin_screen_set_active (twin_screen_t *screen, twin_pixmap_t *pixmap)
}
twin_pixmap_t *
-twin_screen_get_active (twin_screen_t *screen)
+twin_screen_get_key_focus (twin_screen_t *screen)
{
- return screen->active;
+ return screen->key_focus;
}
void
@@ -266,7 +266,7 @@ twin_screen_dispatch (twin_screen_t *screen,
case TwinEventMotion:
case TwinEventButtonDown:
case TwinEventButtonUp:
- pixmap = screen->pointer;
+ pixmap = screen->pointer_grab;
if (!pixmap)
{
for (pixmap = screen->top; pixmap; pixmap = pixmap->down)
@@ -277,20 +277,36 @@ twin_screen_dispatch (twin_screen_t *screen,
break;
}
if (event->kind == TwinEventButtonDown)
- screen->pointer = pixmap;
+ screen->pointer_grab = pixmap;
}
if (event->kind == TwinEventButtonUp)
- screen->pointer = NULL;
+ screen->pointer_grab = NULL;
if (pixmap)
{
event->u.pointer.x = event->u.pointer.screen_x - pixmap->x;
event->u.pointer.y = event->u.pointer.screen_y - pixmap->y;
}
+ if (pixmap != screen->pointer_in)
+ {
+ twin_event_t ev;
+
+ if (screen->pointer_in)
+ {
+ ev.kind = TwinEventLeave;
+ twin_pixmap_dispatch (screen->pointer_in, &ev);
+ }
+ if (pixmap)
+ {
+ ev.u.pointer = event->u.pointer;
+ ev.kind = TwinEventEnter;
+ twin_pixmap_dispatch (pixmap, &ev);
+ }
+ }
break;
case TwinEventKeyDown:
case TwinEventKeyUp:
case TwinEventUcs4:
- pixmap = screen->active;
+ pixmap = screen->key_focus;
break;
default:
pixmap = NULL;
diff --git a/twin_text.c b/twin_text.c
index 7cdeed6..9db9fb4 100644
--- a/twin_text.c
+++ b/twin_text.c
@@ -29,7 +29,8 @@
void
twin_text_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h)
{
- twin_window_t *text = twin_window_create (screen, TWIN_ARGB32,
+ twin_window_t *text = twin_window_create (screen, name,
+ TWIN_ARGB32,
TwinWindowApplication,
x,y,w,h);
twin_fixed_t fx, fy;
diff --git a/twin_toplevel.c b/twin_toplevel.c
index 9ce8e7a..072fe4a 100644
--- a/twin_toplevel.c
+++ b/twin_toplevel.c
@@ -24,34 +24,13 @@
#include "twinint.h"
-twin_dispatch_result_t
-_twin_toplevel_dispatch (twin_widget_t *widget, twin_event_t *event)
-{
- twin_toplevel_t *toplevel = (twin_toplevel_t *) widget;
- twin_event_t ev = *event;
-
- switch (ev.kind) {
- case TwinEventConfigure:
- ev.u.configure.extents.left = 0;
- ev.u.configure.extents.top = 0;
- ev.u.configure.extents.right = (event->u.configure.extents.right -
- event->u.configure.extents.left);
- ev.u.configure.extents.bottom = (event->u.configure.extents.bottom -
- event->u.configure.extents.top);
- break;
- default:
- break;
- }
- return _twin_box_dispatch (&toplevel->box.widget, &ev);
-}
-
static twin_bool_t
_twin_toplevel_event (twin_window_t *window,
twin_event_t *event)
{
twin_toplevel_t *toplevel = window->client_data;
- return (*toplevel->box.widget.dispatch) (&toplevel->box.widget, event) == TwinDispatchDone;
+ return (*toplevel->widget.dispatch) ((twin_widget_t *) toplevel, event) == TwinDispatchDone;
}
static void
@@ -61,7 +40,7 @@ _twin_toplevel_draw (twin_window_t *window)
twin_event_t event;
event.kind = TwinEventPaint;
- (*toplevel->box.widget.dispatch) (&toplevel->box.widget, &event);
+ (*toplevel->widget.dispatch) ((twin_widget_t *) toplevel, &event);
}
static void
@@ -71,52 +50,32 @@ _twin_toplevel_destroy (twin_window_t *window)
twin_event_t event;
event.kind = TwinEventDestroy;
- (*toplevel->box.widget.dispatch) (&toplevel->box.widget, &event);
+ (*toplevel->widget.dispatch) ((twin_widget_t *) toplevel, &event);
}
void
_twin_toplevel_init (twin_toplevel_t *toplevel,
- twin_dispatch_proc_t dispatch,
twin_window_t *window,
- const char *name)
+ twin_box_dir_t dir,
+ twin_dispatch_proc_t dispatch)
{
- twin_rect_t extents;
-
- twin_window_set_name (window, name);
- extents.left = 0;
- extents.top = 0;
- extents.right = window->client.right - window->client.left;
- extents.bottom =window->client.bottom - window->client.top;
- window->draw = _twin_toplevel_draw;
- window->destroy = _twin_toplevel_destroy;
- window->event = _twin_toplevel_event;
- window->client_data = toplevel;
- _twin_box_init (&toplevel->box, 0, window, TwinBoxVert, dispatch);
+ _twin_box_init ((twin_box_t *) toplevel, 0, window, dir, dispatch);
}
twin_toplevel_t *
twin_toplevel_create (twin_screen_t *screen,
- twin_format_t format,
- twin_window_style_t style,
- twin_coord_t x,
- twin_coord_t y,
- twin_coord_t width,
- twin_coord_t height,
- const char *name)
+ twin_window_t *window,
+ twin_box_dir_t dir)
{
twin_toplevel_t *toplevel;
- twin_window_t *window = twin_window_create (screen, format, style,
- x, y, width, height);
-
- if (!window)
- return 0;
- toplevel = malloc (sizeof (twin_toplevel_t) + strlen (name) + 1);
+
+ toplevel = malloc (sizeof (twin_toplevel_t));
if (!toplevel)
{
twin_window_destroy (window);
return 0;
}
- _twin_toplevel_init (toplevel, _twin_toplevel_dispatch, window, name);
+ _twin_toplevel_init (toplevel, window, dir, _twin_toplevel_dispatch);
return toplevel;
}
@@ -127,7 +86,7 @@ _twin_toplevel_paint (void *closure)
twin_event_t ev;
ev.kind = TwinEventPaint;
- (*toplevel->box.widget.dispatch) (&toplevel->box.widget, &ev);
+ (*toplevel->widget.dispatch) ((twin_widget_t *) toplevel, &ev);
return TWIN_FALSE;
}
@@ -136,9 +95,9 @@ _twin_toplevel_queue_paint (twin_widget_t *widget)
{
twin_toplevel_t *toplevel = (twin_toplevel_t *) widget;
- if (!toplevel->box.widget.paint)
+ if (!toplevel->widget.paint)
{
- toplevel->box.widget.paint = TWIN_TRUE;
+ toplevel->widget.paint = TWIN_TRUE;
twin_set_work (_twin_toplevel_paint,
TWIN_WORK_PAINT,
toplevel);
@@ -151,16 +110,16 @@ _twin_toplevel_layout (void *closure)
{
twin_toplevel_t *toplevel = closure;
twin_event_t ev;
- twin_window_t *window = toplevel->box.widget.window;
+ twin_window_t *window = toplevel->widget.window;
ev.kind = TwinEventQueryGeometry;
- (*toplevel->box.widget.dispatch) (&toplevel->box.widget, &ev);
+ (*toplevel->widget.dispatch) ((twin_widget_t *) toplevel, &ev);
ev.kind = TwinEventConfigure;
ev.u.configure.extents.left = 0;
ev.u.configure.extents.top = 0;
ev.u.configure. extents.right = window->client.right - window->client.left;
ev.u.configure.extents.bottom =window->client.bottom - window->client.top;
- (*toplevel->box.widget.dispatch) (&toplevel->box.widget, &ev);
+ (*toplevel->widget.dispatch) ((twin_widget_t *) toplevel, &ev);
return TWIN_FALSE;
}
@@ -169,9 +128,9 @@ _twin_toplevel_queue_layout (twin_widget_t *widget)
{
twin_toplevel_t *toplevel = (twin_toplevel_t *) widget;
- if (!toplevel->box.widget.layout)
+ if (!toplevel->widget.layout)
{
- toplevel->box.widget.layout = TWIN_TRUE;
+ toplevel->widget.layout = TWIN_TRUE;
twin_set_work (_twin_toplevel_layout,
TWIN_WORK_LAYOUT,
toplevel);
@@ -179,11 +138,37 @@ _twin_toplevel_queue_layout (twin_widget_t *widget)
}
}
+twin_dispatch_result_t
+_twin_toplevel_dispatch (twin_widget_t *widget, twin_event_t *event)
+{
+ twin_toplevel_t *toplevel = (twin_toplevel_t *) widget;
+ twin_event_t ev = *event;
+
+ switch (ev.kind) {
+ case TwinEventConfigure:
+ ev.u.configure.extents.left = 0;
+ ev.u.configure.extents.top = 0;
+ ev.u.configure.extents.right = (event->u.configure.extents.right -
+ event->u.configure.extents.left);
+ ev.u.configure.extents.bottom = (event->u.configure.extents.bottom -
+ event->u.configure.extents.top);
+ break;
+ case TwinEventShow:
+ _twin_toplevel_layout (toplevel);
+ _twin_toplevel_paint (toplevel);
+ break;
+ default:
+ break;
+ }
+ return _twin_box_dispatch ((twin_widget_t *) toplevel, &ev);
+}
+
+#if 0
void
twin_toplevel_show (twin_toplevel_t *toplevel)
{
_twin_toplevel_layout (toplevel);
_twin_toplevel_paint (toplevel);
- twin_window_show (toplevel->box.widget.window);
+ twin_window_show (toplevel->widget.window);
}
-
+#endif
diff --git a/twin_widget.c b/twin_widget.c
index 34ef0dc..e32847e 100644
--- a/twin_widget.c
+++ b/twin_widget.c
@@ -69,10 +69,10 @@ _twin_widget_paint_shape (twin_widget_t *widget,
twin_coord_t bottom,
twin_fixed_t radius)
{
- twin_pixmap_t *pixmap = widget->window->pixmap;
+ twin_pixmap_t *pixmap = widget->widget.window->pixmap;
if (shape == TwinShapeRectangle)
- twin_fill (pixmap, widget->background, TWIN_SOURCE,
+ twin_fill (pixmap, widget->widget.background, TWIN_SOURCE,
left, top, right, bottom);
else
{
@@ -80,7 +80,7 @@ _twin_widget_paint_shape (twin_widget_t *widget,
right, bottom, radius);
if (path)
{
- twin_paint_path (pixmap, widget->background, path);
+ twin_paint_path (pixmap, widget->widget.background, path);
twin_path_destroy (path);
}
}
@@ -89,9 +89,9 @@ _twin_widget_paint_shape (twin_widget_t *widget,
static void
_twin_widget_paint (twin_widget_t *widget)
{
- _twin_widget_paint_shape (widget, widget->shape, 0, 0,
+ _twin_widget_paint_shape (widget, widget->widget.shape, 0, 0,
_twin_widget_width (widget),
- _twin_widget_height (widget), widget->radius);
+ _twin_widget_height (widget), widget->widget.radius);
}
twin_dispatch_result_t
@@ -99,22 +99,22 @@ _twin_widget_dispatch (twin_widget_t *widget, twin_event_t *event)
{
switch (event->kind) {
case TwinEventQueryGeometry:
- widget->layout = TWIN_FALSE;
- if (widget->copy_geom)
+ widget->widget.layout = TWIN_FALSE;
+ if (widget->widget.copy_geom)
{
- twin_widget_t *copy = widget->copy_geom;
- if (copy->layout)
- (*copy->dispatch) (copy, event);
- widget->preferred = copy->preferred;
+ twin_widget_t *copy = widget->widget.copy_geom;
+ if (copy->widget.layout)
+ (*copy->widget.dispatch) (copy, event);
+ widget->widget.preferred = copy->widget.preferred;
return TwinDispatchDone;
}
break;
case TwinEventConfigure:
- widget->extents = event->u.configure.extents;
+ widget->widget.extents = event->u.configure.extents;
break;
case TwinEventPaint:
_twin_widget_paint (widget);
- widget->paint = TWIN_FALSE;
+ widget->widget.paint = TWIN_FALSE;
break;
default:
break;
@@ -133,37 +133,38 @@ _twin_widget_init (twin_widget_t *widget,
{
twin_widget_t **prev;
- for (prev = &parent->children; *prev; prev = &(*prev)->next);
- widget->next = *prev;
+ for (prev = &parent->box.children; *prev; prev = &(*prev)->widget.next);
+ widget->widget.next = *prev;
*prev = widget;
window = parent->widget.window;
}
else
- widget->next = NULL;
- widget->window = window;
- widget->parent = parent;
- widget->copy_geom = NULL;
- widget->paint = TWIN_TRUE;
- widget->layout = TWIN_TRUE;
- widget->want_focus = TWIN_FALSE;
- widget->background = 0x00000000;
- widget->extents.left = widget->extents.top = 0;
- widget->extents.right = widget->extents.bottom = 0;
- widget->preferred = preferred;
- widget->dispatch = dispatch;
- widget->shape = TwinShapeRectangle;
- widget->radius = twin_int_to_fixed (12);
+ widget->widget.next = NULL;
+ widget->widget.window = window;
+ widget->widget.parent = parent;
+ widget->widget.copy_geom = NULL;
+ widget->widget.paint = TWIN_TRUE;
+ widget->widget.layout = TWIN_TRUE;
+ widget->widget.want_focus = TWIN_FALSE;
+ widget->widget.background = 0x00000000;
+ widget->widget.extents.left = widget->widget.extents.top = 0;
+ widget->widget.extents.right = widget->widget.extents.bottom = 0;
+ widget->widget.preferred = preferred;
+ widget->widget.dispatch = dispatch;
+ widget->widget.shape = TwinShapeRectangle;
+ widget->widget.radius = twin_int_to_fixed (12);
+ widget->widget.closure = NULL;
}
void
_twin_widget_queue_paint (twin_widget_t *widget)
{
- while (widget->parent)
+ while (widget->widget.parent)
{
- if (widget->paint)
+ if (widget->widget.paint)
return;
- widget->paint = TWIN_TRUE;
- widget = &widget->parent->widget;
+ widget->widget.paint = TWIN_TRUE;
+ widget = (twin_widget_t *) widget->widget.parent;
}
_twin_toplevel_queue_paint (widget);
}
@@ -171,13 +172,13 @@ _twin_widget_queue_paint (twin_widget_t *widget)
void
_twin_widget_queue_layout (twin_widget_t *widget)
{
- while (widget->parent)
+ while (widget->widget.parent)
{
- if (widget->layout)
+ if (widget->widget.layout)
return;
- widget->layout = TWIN_TRUE;
- widget->paint = TWIN_TRUE;
- widget = &widget->parent->widget;
+ widget->widget.layout = TWIN_TRUE;
+ widget->widget.paint = TWIN_TRUE;
+ widget = (twin_widget_t *) widget->widget.parent;
}
_twin_toplevel_queue_layout (widget);
}
@@ -213,7 +214,7 @@ _twin_widget_bevel (twin_widget_t *widget,
twin_fixed_t w = twin_int_to_fixed (_twin_widget_width (widget));
twin_fixed_t h = twin_int_to_fixed (_twin_widget_height (widget));
twin_argb32_t top_color, bot_color;
- twin_pixmap_t *pixmap = widget->window->pixmap;
+ twin_pixmap_t *pixmap = widget->widget.window->pixmap;
if (path)
{
@@ -266,13 +267,13 @@ twin_widget_create (twin_box_t *parent,
preferred.stretch_width = stretch_width;
preferred.stretch_height = stretch_height;
_twin_widget_init (widget, parent, 0, preferred, _twin_widget_dispatch);
- widget->background = background;
+ widget->widget.background = background;
return widget;
}
void
twin_widget_set (twin_widget_t *widget, twin_argb32_t background)
{
- widget->background = background;
+ widget->widget.background = background;
_twin_widget_queue_paint (widget);
}
diff --git a/twin_window.c b/twin_window.c
index 086a8ad..996847f 100644
--- a/twin_window.c
+++ b/twin_window.c
@@ -33,8 +33,50 @@
#define TWIN_RESIZE_SIZE ((TWIN_TITLE_HEIGHT + 4) / 5)
#define TWIN_TITLE_BW ((TWIN_TITLE_HEIGHT + 11) / 12)
+static twin_dispatch_result_t
+_twin_window_label_dispatch (twin_widget_t *widget,
+ twin_event_t *event)
+{
+ twin_window_t *window = widget->widget.window;
+
+ if (_twin_label_dispatch (widget, event) == TwinDispatchDone)
+ return TwinDispatchDone;
+
+ /*
+ * simple window management
+ */
+ switch (event->kind) {
+ case TwinEventButtonDown:
+ twin_window_show (window);
+ window->screen->button_x = event->u.pointer.x;
+ window->screen->button_y = event->u.pointer.y;
+ return TwinDispatchDone;
+ case TwinEventButtonUp:
+ window->screen->button_x = -1;
+ window->screen->button_y = -1;
+ case TwinEventMotion:
+ if (window->screen->button_x >= 0)
+ {
+ twin_coord_t x, y;
+
+ x = event->u.pointer.screen_x - window->screen->button_x;
+ y = event->u.pointer.screen_y - window->screen->button_y;
+ twin_window_configure (window,
+ window->style,
+ x, y,
+ window->pixmap->width,
+ window->pixmap->height);
+ }
+ return TwinDispatchDone;
+ default:
+ break;
+ }
+ return TwinDispatchContinue;
+}
+
twin_window_t *
twin_window_create (twin_screen_t *screen,
+ const char *name,
twin_format_t format,
twin_window_style_t style,
twin_coord_t x,
@@ -44,6 +86,8 @@ twin_window_create (twin_screen_t *screen,
{
twin_window_t *window = malloc (sizeof (twin_window_t));
twin_coord_t left, top, right, bottom;
+ twin_box_t *titlebar;
+ twin_button_t *menu, *min, *max;
if (!window) return NULL;
window->screen = screen;
@@ -70,17 +114,47 @@ twin_window_create (twin_screen_t *screen,
window->client.right = width - right;
window->client.bottom = height - bottom;
window->pixmap = twin_pixmap_create (format, width, height);
- twin_pixmap_clip (window->pixmap,
- window->client.left, window->client.top,
- window->client.right, window->client.bottom);
- window->pixmap->window = window;
+ window->toplevel = twin_toplevel_create (screen, window, TwinBoxVert);
+ switch (window->style) {
+ case TwinWindowApplication:
+ titlebar = twin_box_create (window->toplevel,
+ TwinBoxHorz);
+ menu = twin_button_create (titlebar, "Menu",
+ 0xff202020,
+ twin_int_to_fixed (10),
+ TwinStyleRoman);
+ menu->widget.preferred.stretch_width = 0;
+ menu->widget.preferred.stretch_height = 0;
+ twin_widget_set ((twin_widget_t *) menu, TWIN_ACTIVE_BG);
+ window->label = twin_label_create (titlebar, name,
+ 0xffffffff,
+ twin_int_to_fixed (10),
+ TwinStyleOblique);
+ twin_widget_set ((twin_widget_t *) window->label, TWIN_ACTIVE_BG);
+ window->label->widget.dispatch = _twin_window_label_dispatch;
+ min = twin_button_create (titlebar, "Min",
+ 0xff202020,
+ twin_int_to_fixed (10),
+ TwinStyleRoman);
+ twin_widget_set ((twin_widget_t *) min, TWIN_ACTIVE_BG);
+ min->widget.preferred.stretch_width = 0;
+ min->widget.preferred.stretch_height = 0;
+ max = twin_button_create (titlebar, "Max",
+ 0xff202020,
+ twin_int_to_fixed (10),
+ TwinStyleRoman);
+ twin_widget_set ((twin_widget_t *) max, TWIN_ACTIVE_BG);
+ max->widget.preferred.stretch_width = 0;
+ max->widget.preferred.stretch_height = 0;
+ break;
+ default:
+ break;
+ }
+
+ window->pixmap->toplevel = window->toplevel;
twin_pixmap_move (window->pixmap, x, y);
- window->damage.left = window->damage.right = 0;
- window->damage.top = window->damage.bottom = 0;
- window->client_grab = TWIN_FALSE;
window->want_focus = TWIN_FALSE;
window->client_data = 0;
- window->name = 0;
window->draw = 0;
window->event = 0;
@@ -93,7 +167,6 @@ twin_window_destroy (twin_window_t *window)
{
twin_window_hide (window);
twin_pixmap_destroy (window->pixmap);
- if (window->name) free (window->name);
free (window);
}
@@ -102,6 +175,13 @@ twin_window_show (twin_window_t *window)
{
if (window->pixmap != window->screen->top)
twin_pixmap_show (window->pixmap, window->screen, window->screen->top);
+ if (window->toplevel)
+ {
+ twin_event_t ev;
+
+ ev.kind = TwinEventShow;
+ (*window->toplevel->widget.dispatch) ((twin_widget_t *) window->toplevel, &ev);
+ }
}
void
@@ -132,7 +212,7 @@ twin_window_configure (twin_window_t *window,
int i;
window->pixmap = twin_pixmap_create (old->format, width, height);
- window->pixmap->window = window;
+ window->pixmap->toplevel = window->toplevel;
twin_pixmap_move (window->pixmap, x, y);
if (old->screen)
twin_pixmap_show (window->pixmap, window->screen, old);
@@ -145,8 +225,10 @@ twin_window_configure (twin_window_t *window,
}
if (x != window->pixmap->x || y != window->pixmap->y)
twin_pixmap_move (window->pixmap, x, y);
+#if 0
if (need_repaint)
twin_window_draw (window);
+#endif
twin_pixmap_enable_update (window->pixmap);
}
@@ -172,12 +254,13 @@ void
twin_window_set_name (twin_window_t *window,
const char *name)
{
- if (window->name) free (window->name);
- window->name = malloc (strlen (name) + 1);
- if (window->name) strcpy (window->name, name);
- twin_window_draw (window);
+ twin_label_set (window->label, name,
+ 0xffffffff,
+ twin_int_to_fixed (10),
+ TwinStyleOblique);
}
+#if 0
static void
twin_window_frame (twin_window_t *window)
{
@@ -327,90 +410,4 @@ twin_window_draw (twin_window_t *window)
if (window->draw)
(*window->draw) (window);
}
-
-twin_bool_t
-twin_window_dispatch (twin_window_t *window, twin_event_t *event)
-{
- twin_event_t ev = *event;
- twin_bool_t delegate = TWIN_TRUE;
-
- switch (ev.kind) {
- case TwinEventButtonDown:
- if (window->client.left <= ev.u.pointer.x &&
- ev.u.pointer.x < window->client.right &&
- window->client.top <= ev.u.pointer.y &&
- ev.u.pointer.y < window->client.bottom)
- {
- delegate = TWIN_TRUE;
- window->client_grab = TWIN_TRUE;
- ev.u.pointer.x -= window->client.left;
- ev.u.pointer.y -= window->client.top;
- }
- else
- delegate = TWIN_FALSE;
- break;
- case TwinEventButtonUp:
- if (window->client_grab)
- {
- delegate = TWIN_TRUE;
- window->client_grab = TWIN_FALSE;
- ev.u.pointer.x -= window->client.left;
- ev.u.pointer.y -= window->client.top;
- }
- else
- delegate = TWIN_FALSE;
- break;
- case TwinEventMotion:
- if (window->client_grab ||
- (window->client.left <= ev.u.pointer.x &&
- ev.u.pointer.x < window->client.right &&
- window->client.top <= ev.u.pointer.y &&
- ev.u.pointer.y < window->client.bottom))
- {
- delegate = TWIN_TRUE;
- ev.u.pointer.x -= window->client.left;
- ev.u.pointer.y -= window->client.top;
- }
- else
- delegate = TWIN_FALSE;
- break;
- default:
- break;
- }
- if (!window->event)
- delegate = TWIN_FALSE;
-
- if (delegate && (*window->event) (window, &ev))
- return TWIN_TRUE;
-
- /*
- * simple window management
- */
- switch (event->kind) {
- case TwinEventButtonDown:
- twin_window_show (window);
- window->screen->button_x = event->u.pointer.x;
- window->screen->button_y = event->u.pointer.y;
- return TWIN_TRUE;
- case TwinEventButtonUp:
- window->screen->button_x = -1;
- window->screen->button_y = -1;
- case TwinEventMotion:
- if (window->screen->button_x >= 0)
- {
- twin_coord_t x, y;
-
- x = event->u.pointer.screen_x - window->screen->button_x;
- y = event->u.pointer.screen_y - window->screen->button_y;
- twin_window_configure (window,
- window->style,
- x, y,
- window->pixmap->width,
- window->pixmap->height);
- }
- return TWIN_TRUE;
- default:
- break;
- }
- return TWIN_FALSE;
-}
+#endif
diff --git a/twinint.h b/twinint.h
index 42cecf1..f436d1b 100644
--- a/twinint.h
+++ b/twinint.h
@@ -513,9 +513,9 @@ _twin_toplevel_dispatch (twin_widget_t *widget, twin_event_t *event);
void
_twin_toplevel_init (twin_toplevel_t *toplevel,
- twin_dispatch_proc_t dispatch,
twin_window_t *window,
- const char *name);
+ twin_box_dir_t dir,
+ twin_dispatch_proc_t dispatch);
void
_twin_toplevel_queue_paint (twin_widget_t *widget);
diff --git a/xtwin.c b/xtwin.c
index 06f4485..b43fff9 100644
--- a/xtwin.c
+++ b/xtwin.c
@@ -50,7 +50,7 @@ main (int argc, char **argv)
#if 0
twin_demo_start (x11->screen, "Demo", 100, 100, 400, 400);
#endif
-#if 0
+#if 1
twin_text_start (x11->screen, "Gettysburg Address", 0, 0, 300, 300);
#endif
#if 0