1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/* A gzw border. */
#include <gtk/gtk.h>
#include "gzw.h"
#include "gzwborder.h"
static void
gzw_border_size_nego_x (Gzw *gzw, gint width)
{
gint border;
border = ((GzwBorder *)gzw)->border;
gzw_size_nego_x (((GzwBorder *)gzw)->child, width - border * 2);
gzw->req_height = ((GzwBorder *)gzw)->child->req_height + border * 2;
gzw->req_ascent = ((GzwBorder *)gzw)->child->req_ascent + border * 2;
}
static void
gzw_border_size_nego_y (Gzw *gzw, GzwRect *allocation)
{
GzwRect child_allocation;
gint border;
GzwRect repaint;
border = ((GzwBorder *)gzw)->border;
/* Request incremental repaints. */
if (allocation->x0 == gzw->allocation.x0 &&
allocation->y0 == gzw->allocation.y0)
{
if (allocation->x1 != gzw->allocation.x1)
{
repaint.x0 = MIN (allocation->x1, gzw->allocation.x1) - border;
repaint.y0 = allocation->y0;
repaint.x1 = allocation->x1;
repaint.y1 = allocation->y1;
gzw_request_paint (gzw, &repaint);
}
if (allocation->y1 != gzw->allocation.y1)
{
repaint.x0 = allocation->x0;
repaint.y0 = MIN (allocation->y1, gzw->allocation.y1) - border;
repaint.x1 = allocation->x1;
repaint.y1 = allocation->y1;
#ifdef VERBOSE
g_print ("gzw_border_size_nego_y: request (%d, %d) - (%d, %d)\n",
repaint.x0,
repaint.y0,
repaint.x1,
repaint.y1);
#endif
gzw_request_paint (gzw, &repaint);
}
}
gzw->allocation = *allocation;
child_allocation.x0 = allocation->x0 + border;
child_allocation.x1 = allocation->x1 - border;
child_allocation.y0 = allocation->y0 + border;
child_allocation.y1 = allocation->y1 - border;
gzw_size_nego_y (((GzwBorder *)gzw)->child, &child_allocation);
}
static void
gzw_border_paint (Gzw *gzw, GzwRect *rect, GzwPaint *paint)
{
GtkWidget *widget;
GzwContainer *container;
GzwRect child_rect;
#ifdef VERBOSE
g_print ("gzw_border_paint (%d, %d) - (%d, %d)",
rect->x0, rect->y0, rect->x1, rect->y1);
#endif
container = gzw_find_container (gzw);
if (container != NULL)
{
#ifdef VERBOSE
g_print (", visible = (%d, %d) - (%d, %d)\n",
container->visible.x0, container->visible.y0,
container->visible.x1, container->visible.y1);
#endif
widget = container->widget;
gzw_paint_to_screen (widget, container, rect, paint);
gzw_rect_intersect (&child_rect, rect,
&((GzwBorder *)gzw)->child->allocation);
if (!gzw_rect_empty (&child_rect))
{
gzw_paint (((GzwBorder *)gzw)->child, &child_rect, paint);
gzw_paint_to_screen (widget, container, &child_rect, paint);
}
gzw_paint_finish_screen (paint);
}
#ifdef VERBOSE
else
g_print ("\n");
#endif
}
static void
gzw_border_handle_event (Gzw *gzw, GdkEvent *event)
{
gzw_handle_event (((GzwBorder *)gzw)->child, event);
}
static void
gzw_border_gtk_foreach (Gzw *gzw, GzwCallback callback, gpointer callback_data,
GzwRect *plus, GzwRect *minus)
{
gzw_gtk_foreach (((GzwBorder *)gzw)->child, callback, callback_data,
plus, minus);
}
static void
gzw_border_destroy (Gzw *gzw)
{
gzw_destroy (((GzwBorder *)gzw)->child);
g_free (gzw);
}
static void
gzw_border_request_resize (Gzw *gzw, Gzw *child)
{
gint border;
border = ((GzwBorder *)gzw)->border;
gzw->req_width_min = ((GzwBorder *)gzw)->child->req_width_min + border * 2;
gzw->req_width_max = ((GzwBorder *)gzw)->child->req_width_max + border * 2;
gzw_request_parent_resize (gzw);
}
static const GzwClass gzw_border_class =
{
gzw_border_size_nego_x,
gzw_border_size_nego_y,
gzw_border_paint,
gzw_border_handle_event,
gzw_border_gtk_foreach,
gzw_border_destroy,
gzw_border_request_resize
};
Gzw *
gzw_border_new (Gzw *child, gint border)
{
GzwBorder *gzw_border;
GzwRect null_rect = {0, 0, 0, 0};
gzw_border = g_new (GzwBorder, 1);
gzw_border->gzw.klass = &gzw_border_class;
gzw_border->gzw.allocation = null_rect;
gzw_border->gzw.req_width_min = child->req_width_min + border * 2;
gzw_border->gzw.req_width_max = child->req_width_max + border * 2;
gzw_border->gzw.flags = child->flags &
(GZW_FLAG_BASELINE | GZW_FLAG_GTK_EMBED);
gzw_border->gzw.parent = NULL;
gzw_border->gzw.container = NULL;
gzw_border->child = child;
gzw_border->border = border;
child->parent = (Gzw *)gzw_border;
return (Gzw *)gzw_border;
}
|