-Yosh
This commit is contained in:
Manish Singh
1999-09-04 06:29:10 +00:00
parent cd70fa440e
commit adfadca186
9 changed files with 351 additions and 178 deletions

View File

@ -1,3 +1,8 @@
Fri Sep 3 23:26:38 PDT 1999 Manish Singh <yosh@gimp.org>
* app/gtkwrapbox.[ch]
* app/gtk[hv]wrapbox.c: gle sync
Fri Sep 3 23:17:44 PDT 1999 Manish Singh <yosh@gimp.org> Fri Sep 3 23:17:44 PDT 1999 Manish Singh <yosh@gimp.org>
* plug-ins/common/mkgen.pl: autogen .cvsignore too * plug-ins/common/mkgen.pl: autogen .cvsignore too

View File

@ -24,12 +24,17 @@
/* --- prototypes --- */ /* --- prototypes --- */
static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass); static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass);
static void gtk_hwrap_box_init (GtkHWrapBox *hwbox); static void gtk_hwrap_box_init (GtkHWrapBox *hwbox);
static void gtk_hwrap_box_size_request (GtkWidget *widget, static void gtk_hwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_hwrap_box_size_allocate (GtkWidget *widget, static void gtk_hwrap_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static GSList* reverse_list_row_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
GtkAllocation *area,
guint *max_height,
gboolean *can_vexpand);
/* --- variables --- */ /* --- variables --- */
@ -79,6 +84,8 @@ gtk_hwrap_box_class_init (GtkHWrapBoxClass *class)
widget_class->size_request = gtk_hwrap_box_size_request; widget_class->size_request = gtk_hwrap_box_size_request;
widget_class->size_allocate = gtk_hwrap_box_size_allocate; widget_class->size_allocate = gtk_hwrap_box_size_allocate;
wrap_box_class->rlist_line_children = reverse_list_row_children;
} }
static void static void
@ -88,12 +95,12 @@ gtk_hwrap_box_init (GtkHWrapBox *hwbox)
hwbox->max_child_height = 0; hwbox->max_child_height = 0;
} }
GtkWidget * GtkWidget*
gtk_hwrap_box_new (gboolean homogeneous) gtk_hwrap_box_new (gboolean homogeneous)
{ {
GtkHWrapBox *hwbox; GtkHWrapBox *hwbox;
hwbox = GTK_HWRAP_BOX (gtk_widget_new (gtk_hwrap_box_get_type (), NULL)); hwbox = GTK_HWRAP_BOX (gtk_widget_new (GTK_TYPE_HWRAP_BOX, NULL));
GTK_WRAP_BOX (hwbox)->homogeneous = homogeneous ? TRUE : FALSE; GTK_WRAP_BOX (hwbox)->homogeneous = homogeneous ? TRUE : FALSE;
@ -262,38 +269,36 @@ gtk_hwrap_box_size_request (GtkWidget *widget,
requisition->width = layout_width; requisition->width = layout_width;
requisition->height = layout_height; requisition->height = layout_height;
} }
/*<h2v-off>*/
/* g_print ("ratio for width %d height %d = %f\n", /* g_print ("ratio for width %d height %d = %f\n",
(gint) layout_width, (gint) layout_width,
(gint) layout_height, (gint) layout_height,
ratio); */ ratio);
/*<h2v-on>*/ */
} }
while (row_inc); while (row_inc);
/*<h2v-off>*/ requisition->width += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->width += GTK_CONTAINER (wbox)->border_width * 2; requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->height += GTK_CONTAINER (wbox)->border_width * 2;
/* g_print ("choosen: width %d, height %d\n", /* g_print ("choosen: width %d, height %d\n",
requisition->width, requisition->width,
requisition->height); */ requisition->height);
/*<h2v-on>*/ */
} }
static GSList* static GSList*
list_row_children (GtkWrapBox *wbox, reverse_list_row_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p, GtkWrapBoxChild **child_p,
guint row_width, GtkAllocation *area,
guint *max_height, guint *max_child_size,
gboolean *can_vexpand) gboolean *expand_line)
{ {
GSList *slist = NULL; GSList *slist = NULL;
guint width = 0; guint width = 0, row_width = area->width;
GtkWrapBoxChild *child = *child_p; GtkWrapBoxChild *child = *child_p;
*max_height = 0; *max_child_size = 0;
*can_vexpand = FALSE; *expand_line = FALSE;
while (child && !GTK_WIDGET_VISIBLE (child->widget)) while (child && !GTK_WIDGET_VISIBLE (child->widget))
{ {
@ -308,8 +313,8 @@ list_row_children (GtkWrapBox *wbox,
get_child_requisition (wbox, child->widget, &child_requisition); get_child_requisition (wbox, child->widget, &child_requisition);
width += child_requisition.width; width += child_requisition.width;
*max_height = MAX (*max_height, child_requisition.height); *max_child_size = MAX (*max_child_size, child_requisition.height);
*can_vexpand |= child->vexpand; *expand_line |= child->vexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
*child_p = child->next; *child_p = child->next;
child = *child_p; child = *child_p;
@ -322,8 +327,8 @@ list_row_children (GtkWrapBox *wbox,
if (width + wbox->hspacing + child_requisition.width > row_width) if (width + wbox->hspacing + child_requisition.width > row_width)
break; break;
width += wbox->hspacing + child_requisition.width; width += wbox->hspacing + child_requisition.width;
*max_height = MAX (*max_height, child_requisition.height); *max_child_size = MAX (*max_child_size, child_requisition.height);
*can_vexpand |= child->vexpand; *expand_line |= child->vexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
n++; n++;
} }
@ -332,7 +337,7 @@ list_row_children (GtkWrapBox *wbox,
} }
} }
return g_slist_reverse (slist); return slist;
} }
static void static void
@ -500,7 +505,13 @@ layout_rows (GtkWrapBox *wbox,
guint children_per_line; guint children_per_line;
next_child = wbox->children; next_child = wbox->children;
slist = list_row_children (wbox, &next_child, area->width, &min_height, &vexpand); slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
area,
&min_height,
&vexpand);
slist = g_slist_reverse (slist);
children_per_line = g_slist_length (slist); children_per_line = g_slist_length (slist);
while (slist) while (slist)
{ {
@ -516,19 +527,20 @@ layout_rows (GtkWrapBox *wbox,
line_list = line; line_list = line;
n_lines++; n_lines++;
slist = list_row_children (wbox, slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child, &next_child,
area->width, area,
&min_height, &min_height,
&vexpand); &vexpand);
slist = g_slist_reverse (slist);
} }
if (total_height > area->height) if (total_height > area->height)
shrink_height = total_height - area->height; shrink_height = total_height - area->height;
else else
shrink_height = 0; shrink_height = 0;
if (1) /* reverse and shrink */ if (1) /* reverse lines and shrink */
{ {
Line *prev = NULL, *last = NULL; Line *prev = NULL, *last = NULL;
gfloat n_shrink_lines = n_lines; gfloat n_shrink_lines = n_lines;
@ -632,8 +644,9 @@ gtk_hwrap_box_size_allocate (GtkWidget *widget,
/*<h2v-off>*/ /*<h2v-off>*/
/* g_print ("got: width %d, height %d\n", /* g_print ("got: width %d, height %d\n",
allocation->width, allocation->width,
allocation->height); */ allocation->height);
*/
/*<h2v-on>*/ /*<h2v-on>*/
layout_rows (wbox, &area); layout_rows (wbox, &area);

View File

@ -24,12 +24,17 @@
/* --- prototypes --- */ /* --- prototypes --- */
static void gtk_vwrap_box_class_init (GtkVWrapBoxClass *klass); static void gtk_vwrap_box_class_init (GtkVWrapBoxClass *klass);
static void gtk_vwrap_box_init (GtkVWrapBox *vwbox); static void gtk_vwrap_box_init (GtkVWrapBox *vwbox);
static void gtk_vwrap_box_size_request (GtkWidget *widget, static void gtk_vwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_vwrap_box_size_allocate (GtkWidget *widget, static void gtk_vwrap_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static GSList* reverse_list_col_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
GtkAllocation *area,
guint *max_width,
gboolean *can_hexpand);
/* --- variables --- */ /* --- variables --- */
@ -79,6 +84,8 @@ gtk_vwrap_box_class_init (GtkVWrapBoxClass *class)
widget_class->size_request = gtk_vwrap_box_size_request; widget_class->size_request = gtk_vwrap_box_size_request;
widget_class->size_allocate = gtk_vwrap_box_size_allocate; widget_class->size_allocate = gtk_vwrap_box_size_allocate;
wrap_box_class->rlist_line_children = reverse_list_col_children;
} }
static void static void
@ -88,12 +95,12 @@ gtk_vwrap_box_init (GtkVWrapBox *vwbox)
vwbox->max_child_width = 0; vwbox->max_child_width = 0;
} }
GtkWidget * GtkWidget*
gtk_vwrap_box_new (gboolean homogeneous) gtk_vwrap_box_new (gboolean homogeneous)
{ {
GtkVWrapBox *vwbox; GtkVWrapBox *vwbox;
vwbox = GTK_VWRAP_BOX (gtk_widget_new (gtk_vwrap_box_get_type (), NULL)); vwbox = GTK_VWRAP_BOX (gtk_widget_new (GTK_TYPE_VWRAP_BOX, NULL));
GTK_WRAP_BOX (vwbox)->homogeneous = homogeneous ? TRUE : FALSE; GTK_WRAP_BOX (vwbox)->homogeneous = homogeneous ? TRUE : FALSE;
@ -262,38 +269,36 @@ gtk_vwrap_box_size_request (GtkWidget *widget,
requisition->height = layout_height; requisition->height = layout_height;
requisition->width = layout_width; requisition->width = layout_width;
} }
/*<h2v-off>*/ /* g_print ("ratio for height %d width %d = %f\n",
/* g_print ("ratio for width %d height %d = %f\n", (gint) layout_height,
(gint) layout_width, (gint) layout_width,
(gint) layout_height, ratio);
ratio); */ */
/*<h2v-on>*/
} }
while (col_inc); while (col_inc);
/*<h2v-off>*/ requisition->width += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->width += GTK_CONTAINER (wbox)->border_width * 2; requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /* g_print ("choosen: height %d, width %d\n",
/* g_print ("choosen: width %d, height %d\n", requisition->height,
requisition->width, requisition->width);
requisition->height); */ */
/*<h2v-on>*/
} }
static GSList* static GSList*
list_col_children (GtkWrapBox *wbox, reverse_list_col_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p, GtkWrapBoxChild **child_p,
guint col_height, GtkAllocation *area,
guint *max_width, guint *max_child_size,
gboolean *can_hexpand) gboolean *expand_line)
{ {
GSList *slist = NULL; GSList *slist = NULL;
guint height = 0; guint height = 0, col_height = area->height;
GtkWrapBoxChild *child = *child_p; GtkWrapBoxChild *child = *child_p;
*max_width = 0; *max_child_size = 0;
*can_hexpand = FALSE; *expand_line = FALSE;
while (child && !GTK_WIDGET_VISIBLE (child->widget)) while (child && !GTK_WIDGET_VISIBLE (child->widget))
{ {
@ -308,8 +313,8 @@ list_col_children (GtkWrapBox *wbox,
get_child_requisition (wbox, child->widget, &child_requisition); get_child_requisition (wbox, child->widget, &child_requisition);
height += child_requisition.height; height += child_requisition.height;
*max_width = MAX (*max_width, child_requisition.width); *max_child_size = MAX (*max_child_size, child_requisition.width);
*can_hexpand |= child->hexpand; *expand_line |= child->hexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
*child_p = child->next; *child_p = child->next;
child = *child_p; child = *child_p;
@ -322,8 +327,8 @@ list_col_children (GtkWrapBox *wbox,
if (height + wbox->vspacing + child_requisition.height > col_height) if (height + wbox->vspacing + child_requisition.height > col_height)
break; break;
height += wbox->vspacing + child_requisition.height; height += wbox->vspacing + child_requisition.height;
*max_width = MAX (*max_width, child_requisition.width); *max_child_size = MAX (*max_child_size, child_requisition.width);
*can_hexpand |= child->hexpand; *expand_line |= child->hexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
n++; n++;
} }
@ -332,7 +337,7 @@ list_col_children (GtkWrapBox *wbox,
} }
} }
return g_slist_reverse (slist); return slist;
} }
static void static void
@ -500,7 +505,13 @@ layout_cols (GtkWrapBox *wbox,
guint children_per_line; guint children_per_line;
next_child = wbox->children; next_child = wbox->children;
slist = list_col_children (wbox, &next_child, area->height, &min_width, &hexpand); slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
area,
&min_width,
&hexpand);
slist = g_slist_reverse (slist);
children_per_line = g_slist_length (slist); children_per_line = g_slist_length (slist);
while (slist) while (slist)
{ {
@ -516,19 +527,20 @@ layout_cols (GtkWrapBox *wbox,
line_list = line; line_list = line;
n_lines++; n_lines++;
slist = list_col_children (wbox, slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child, &next_child,
area->height, area,
&min_width, &min_width,
&hexpand); &hexpand);
slist = g_slist_reverse (slist);
} }
if (total_width > area->width) if (total_width > area->width)
shrink_width = total_width - area->width; shrink_width = total_width - area->width;
else else
shrink_width = 0; shrink_width = 0;
if (1) /* reverse and shrink */ if (1) /* reverse lines and shrink */
{ {
Line *prev = NULL, *last = NULL; Line *prev = NULL, *last = NULL;
gfloat n_shrink_lines = n_lines; gfloat n_shrink_lines = n_lines;
@ -632,8 +644,9 @@ gtk_vwrap_box_size_allocate (GtkWidget *widget,
/*<h2v-off>*/ /*<h2v-off>*/
/* g_print ("got: width %d, height %d\n", /* g_print ("got: width %d, height %d\n",
allocation->width, allocation->width,
allocation->height); */ allocation->height);
*/
/*<h2v-on>*/ /*<h2v-on>*/
layout_cols (wbox, &area); layout_cols (wbox, &area);

View File

@ -137,6 +137,8 @@ gtk_wrap_box_class_init (GtkWrapBoxClass *class)
container_class->child_type = gtk_wrap_box_child_type; container_class->child_type = gtk_wrap_box_child_type;
container_class->set_child_arg = gtk_wrap_box_set_child_arg; container_class->set_child_arg = gtk_wrap_box_set_child_arg;
container_class->get_child_arg = gtk_wrap_box_get_child_arg; container_class->get_child_arg = gtk_wrap_box_get_child_arg;
class->rlist_line_children = NULL;
gtk_object_add_arg_type ("GtkWrapBox::homogeneous", gtk_object_add_arg_type ("GtkWrapBox::homogeneous",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS); GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);
@ -599,6 +601,54 @@ gtk_wrap_box_set_child_packing (GtkWrapBox *wbox,
} }
} }
guint*
gtk_wrap_box_query_line_lengths (GtkWrapBox *wbox,
guint *_n_lines)
{
GtkWrapBoxChild *next_child = NULL;
GtkAllocation area, *allocation;
gboolean expand_line;
GSList *slist;
guint max_child_size, border, n_lines = 0, *lines = NULL;
if (_n_lines)
*_n_lines = 0;
g_return_val_if_fail (GTK_IS_WRAP_BOX (wbox), NULL);
allocation = &GTK_WIDGET (wbox)->allocation;
border = GTK_CONTAINER (wbox)->border_width;
area.x = allocation->x + border;
area.y = allocation->y + border;
area.width = MAX (1, (gint) allocation->width - border * 2);
area.height = MAX (1, (gint) allocation->height - border * 2);
next_child = wbox->children;
slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
&area,
&max_child_size,
&expand_line);
while (slist)
{
guint l = n_lines++;
lines = g_renew (guint, lines, n_lines);
lines[l] = g_slist_length (slist);
g_slist_free (slist);
slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
&area,
&max_child_size,
&expand_line);
}
if (_n_lines)
*_n_lines = n_lines;
return lines;
}
static void static void
gtk_wrap_box_map (GtkWidget *widget) gtk_wrap_box_map (GtkWidget *widget)
{ {
@ -659,7 +709,7 @@ gtk_wrap_box_expose (GtkWidget *widget,
gtk_widget_intersect (child->widget, &event->area, &child_event.area)) gtk_widget_intersect (child->widget, &event->area, &child_event.area))
gtk_widget_event (child->widget, (GdkEvent*) &child_event); gtk_widget_event (child->widget, (GdkEvent*) &child_event);
return FALSE; return TRUE;
} }
static void static void

View File

@ -64,6 +64,12 @@ struct _GtkWrapBox
struct _GtkWrapBoxClass struct _GtkWrapBoxClass
{ {
GtkContainerClass parent_class; GtkContainerClass parent_class;
GSList* (*rlist_line_children) (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
GtkAllocation *area,
guint *max_child_size,
gboolean *expand_line);
}; };
struct _GtkWrapBoxChild struct _GtkWrapBoxChild
{ {
@ -114,6 +120,8 @@ void gtk_wrap_box_set_child_packing (GtkWrapBox *wbox,
gboolean hfill, gboolean hfill,
gboolean vexpand, gboolean vexpand,
gboolean vfill); gboolean vfill);
guint* gtk_wrap_box_query_line_lengths (GtkWrapBox *wbox,
guint *n_lines);

View File

@ -24,12 +24,17 @@
/* --- prototypes --- */ /* --- prototypes --- */
static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass); static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass);
static void gtk_hwrap_box_init (GtkHWrapBox *hwbox); static void gtk_hwrap_box_init (GtkHWrapBox *hwbox);
static void gtk_hwrap_box_size_request (GtkWidget *widget, static void gtk_hwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_hwrap_box_size_allocate (GtkWidget *widget, static void gtk_hwrap_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static GSList* reverse_list_row_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
GtkAllocation *area,
guint *max_height,
gboolean *can_vexpand);
/* --- variables --- */ /* --- variables --- */
@ -79,6 +84,8 @@ gtk_hwrap_box_class_init (GtkHWrapBoxClass *class)
widget_class->size_request = gtk_hwrap_box_size_request; widget_class->size_request = gtk_hwrap_box_size_request;
widget_class->size_allocate = gtk_hwrap_box_size_allocate; widget_class->size_allocate = gtk_hwrap_box_size_allocate;
wrap_box_class->rlist_line_children = reverse_list_row_children;
} }
static void static void
@ -88,12 +95,12 @@ gtk_hwrap_box_init (GtkHWrapBox *hwbox)
hwbox->max_child_height = 0; hwbox->max_child_height = 0;
} }
GtkWidget * GtkWidget*
gtk_hwrap_box_new (gboolean homogeneous) gtk_hwrap_box_new (gboolean homogeneous)
{ {
GtkHWrapBox *hwbox; GtkHWrapBox *hwbox;
hwbox = GTK_HWRAP_BOX (gtk_widget_new (gtk_hwrap_box_get_type (), NULL)); hwbox = GTK_HWRAP_BOX (gtk_widget_new (GTK_TYPE_HWRAP_BOX, NULL));
GTK_WRAP_BOX (hwbox)->homogeneous = homogeneous ? TRUE : FALSE; GTK_WRAP_BOX (hwbox)->homogeneous = homogeneous ? TRUE : FALSE;
@ -262,38 +269,36 @@ gtk_hwrap_box_size_request (GtkWidget *widget,
requisition->width = layout_width; requisition->width = layout_width;
requisition->height = layout_height; requisition->height = layout_height;
} }
/*<h2v-off>*/
/* g_print ("ratio for width %d height %d = %f\n", /* g_print ("ratio for width %d height %d = %f\n",
(gint) layout_width, (gint) layout_width,
(gint) layout_height, (gint) layout_height,
ratio); */ ratio);
/*<h2v-on>*/ */
} }
while (row_inc); while (row_inc);
/*<h2v-off>*/ requisition->width += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->width += GTK_CONTAINER (wbox)->border_width * 2; requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->height += GTK_CONTAINER (wbox)->border_width * 2;
/* g_print ("choosen: width %d, height %d\n", /* g_print ("choosen: width %d, height %d\n",
requisition->width, requisition->width,
requisition->height); */ requisition->height);
/*<h2v-on>*/ */
} }
static GSList* static GSList*
list_row_children (GtkWrapBox *wbox, reverse_list_row_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p, GtkWrapBoxChild **child_p,
guint row_width, GtkAllocation *area,
guint *max_height, guint *max_child_size,
gboolean *can_vexpand) gboolean *expand_line)
{ {
GSList *slist = NULL; GSList *slist = NULL;
guint width = 0; guint width = 0, row_width = area->width;
GtkWrapBoxChild *child = *child_p; GtkWrapBoxChild *child = *child_p;
*max_height = 0; *max_child_size = 0;
*can_vexpand = FALSE; *expand_line = FALSE;
while (child && !GTK_WIDGET_VISIBLE (child->widget)) while (child && !GTK_WIDGET_VISIBLE (child->widget))
{ {
@ -308,8 +313,8 @@ list_row_children (GtkWrapBox *wbox,
get_child_requisition (wbox, child->widget, &child_requisition); get_child_requisition (wbox, child->widget, &child_requisition);
width += child_requisition.width; width += child_requisition.width;
*max_height = MAX (*max_height, child_requisition.height); *max_child_size = MAX (*max_child_size, child_requisition.height);
*can_vexpand |= child->vexpand; *expand_line |= child->vexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
*child_p = child->next; *child_p = child->next;
child = *child_p; child = *child_p;
@ -322,8 +327,8 @@ list_row_children (GtkWrapBox *wbox,
if (width + wbox->hspacing + child_requisition.width > row_width) if (width + wbox->hspacing + child_requisition.width > row_width)
break; break;
width += wbox->hspacing + child_requisition.width; width += wbox->hspacing + child_requisition.width;
*max_height = MAX (*max_height, child_requisition.height); *max_child_size = MAX (*max_child_size, child_requisition.height);
*can_vexpand |= child->vexpand; *expand_line |= child->vexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
n++; n++;
} }
@ -332,7 +337,7 @@ list_row_children (GtkWrapBox *wbox,
} }
} }
return g_slist_reverse (slist); return slist;
} }
static void static void
@ -500,7 +505,13 @@ layout_rows (GtkWrapBox *wbox,
guint children_per_line; guint children_per_line;
next_child = wbox->children; next_child = wbox->children;
slist = list_row_children (wbox, &next_child, area->width, &min_height, &vexpand); slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
area,
&min_height,
&vexpand);
slist = g_slist_reverse (slist);
children_per_line = g_slist_length (slist); children_per_line = g_slist_length (slist);
while (slist) while (slist)
{ {
@ -516,19 +527,20 @@ layout_rows (GtkWrapBox *wbox,
line_list = line; line_list = line;
n_lines++; n_lines++;
slist = list_row_children (wbox, slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child, &next_child,
area->width, area,
&min_height, &min_height,
&vexpand); &vexpand);
slist = g_slist_reverse (slist);
} }
if (total_height > area->height) if (total_height > area->height)
shrink_height = total_height - area->height; shrink_height = total_height - area->height;
else else
shrink_height = 0; shrink_height = 0;
if (1) /* reverse and shrink */ if (1) /* reverse lines and shrink */
{ {
Line *prev = NULL, *last = NULL; Line *prev = NULL, *last = NULL;
gfloat n_shrink_lines = n_lines; gfloat n_shrink_lines = n_lines;
@ -632,8 +644,9 @@ gtk_hwrap_box_size_allocate (GtkWidget *widget,
/*<h2v-off>*/ /*<h2v-off>*/
/* g_print ("got: width %d, height %d\n", /* g_print ("got: width %d, height %d\n",
allocation->width, allocation->width,
allocation->height); */ allocation->height);
*/
/*<h2v-on>*/ /*<h2v-on>*/
layout_rows (wbox, &area); layout_rows (wbox, &area);

View File

@ -24,12 +24,17 @@
/* --- prototypes --- */ /* --- prototypes --- */
static void gtk_vwrap_box_class_init (GtkVWrapBoxClass *klass); static void gtk_vwrap_box_class_init (GtkVWrapBoxClass *klass);
static void gtk_vwrap_box_init (GtkVWrapBox *vwbox); static void gtk_vwrap_box_init (GtkVWrapBox *vwbox);
static void gtk_vwrap_box_size_request (GtkWidget *widget, static void gtk_vwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition); GtkRequisition *requisition);
static void gtk_vwrap_box_size_allocate (GtkWidget *widget, static void gtk_vwrap_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static GSList* reverse_list_col_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
GtkAllocation *area,
guint *max_width,
gboolean *can_hexpand);
/* --- variables --- */ /* --- variables --- */
@ -79,6 +84,8 @@ gtk_vwrap_box_class_init (GtkVWrapBoxClass *class)
widget_class->size_request = gtk_vwrap_box_size_request; widget_class->size_request = gtk_vwrap_box_size_request;
widget_class->size_allocate = gtk_vwrap_box_size_allocate; widget_class->size_allocate = gtk_vwrap_box_size_allocate;
wrap_box_class->rlist_line_children = reverse_list_col_children;
} }
static void static void
@ -88,12 +95,12 @@ gtk_vwrap_box_init (GtkVWrapBox *vwbox)
vwbox->max_child_width = 0; vwbox->max_child_width = 0;
} }
GtkWidget * GtkWidget*
gtk_vwrap_box_new (gboolean homogeneous) gtk_vwrap_box_new (gboolean homogeneous)
{ {
GtkVWrapBox *vwbox; GtkVWrapBox *vwbox;
vwbox = GTK_VWRAP_BOX (gtk_widget_new (gtk_vwrap_box_get_type (), NULL)); vwbox = GTK_VWRAP_BOX (gtk_widget_new (GTK_TYPE_VWRAP_BOX, NULL));
GTK_WRAP_BOX (vwbox)->homogeneous = homogeneous ? TRUE : FALSE; GTK_WRAP_BOX (vwbox)->homogeneous = homogeneous ? TRUE : FALSE;
@ -262,38 +269,36 @@ gtk_vwrap_box_size_request (GtkWidget *widget,
requisition->height = layout_height; requisition->height = layout_height;
requisition->width = layout_width; requisition->width = layout_width;
} }
/*<h2v-off>*/ /* g_print ("ratio for height %d width %d = %f\n",
/* g_print ("ratio for width %d height %d = %f\n", (gint) layout_height,
(gint) layout_width, (gint) layout_width,
(gint) layout_height, ratio);
ratio); */ */
/*<h2v-on>*/
} }
while (col_inc); while (col_inc);
/*<h2v-off>*/ requisition->width += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->width += GTK_CONTAINER (wbox)->border_width * 2; requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /* g_print ("choosen: height %d, width %d\n",
/* g_print ("choosen: width %d, height %d\n", requisition->height,
requisition->width, requisition->width);
requisition->height); */ */
/*<h2v-on>*/
} }
static GSList* static GSList*
list_col_children (GtkWrapBox *wbox, reverse_list_col_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p, GtkWrapBoxChild **child_p,
guint col_height, GtkAllocation *area,
guint *max_width, guint *max_child_size,
gboolean *can_hexpand) gboolean *expand_line)
{ {
GSList *slist = NULL; GSList *slist = NULL;
guint height = 0; guint height = 0, col_height = area->height;
GtkWrapBoxChild *child = *child_p; GtkWrapBoxChild *child = *child_p;
*max_width = 0; *max_child_size = 0;
*can_hexpand = FALSE; *expand_line = FALSE;
while (child && !GTK_WIDGET_VISIBLE (child->widget)) while (child && !GTK_WIDGET_VISIBLE (child->widget))
{ {
@ -308,8 +313,8 @@ list_col_children (GtkWrapBox *wbox,
get_child_requisition (wbox, child->widget, &child_requisition); get_child_requisition (wbox, child->widget, &child_requisition);
height += child_requisition.height; height += child_requisition.height;
*max_width = MAX (*max_width, child_requisition.width); *max_child_size = MAX (*max_child_size, child_requisition.width);
*can_hexpand |= child->hexpand; *expand_line |= child->hexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
*child_p = child->next; *child_p = child->next;
child = *child_p; child = *child_p;
@ -322,8 +327,8 @@ list_col_children (GtkWrapBox *wbox,
if (height + wbox->vspacing + child_requisition.height > col_height) if (height + wbox->vspacing + child_requisition.height > col_height)
break; break;
height += wbox->vspacing + child_requisition.height; height += wbox->vspacing + child_requisition.height;
*max_width = MAX (*max_width, child_requisition.width); *max_child_size = MAX (*max_child_size, child_requisition.width);
*can_hexpand |= child->hexpand; *expand_line |= child->hexpand;
slist = g_slist_prepend (slist, child); slist = g_slist_prepend (slist, child);
n++; n++;
} }
@ -332,7 +337,7 @@ list_col_children (GtkWrapBox *wbox,
} }
} }
return g_slist_reverse (slist); return slist;
} }
static void static void
@ -500,7 +505,13 @@ layout_cols (GtkWrapBox *wbox,
guint children_per_line; guint children_per_line;
next_child = wbox->children; next_child = wbox->children;
slist = list_col_children (wbox, &next_child, area->height, &min_width, &hexpand); slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
area,
&min_width,
&hexpand);
slist = g_slist_reverse (slist);
children_per_line = g_slist_length (slist); children_per_line = g_slist_length (slist);
while (slist) while (slist)
{ {
@ -516,19 +527,20 @@ layout_cols (GtkWrapBox *wbox,
line_list = line; line_list = line;
n_lines++; n_lines++;
slist = list_col_children (wbox, slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child, &next_child,
area->height, area,
&min_width, &min_width,
&hexpand); &hexpand);
slist = g_slist_reverse (slist);
} }
if (total_width > area->width) if (total_width > area->width)
shrink_width = total_width - area->width; shrink_width = total_width - area->width;
else else
shrink_width = 0; shrink_width = 0;
if (1) /* reverse and shrink */ if (1) /* reverse lines and shrink */
{ {
Line *prev = NULL, *last = NULL; Line *prev = NULL, *last = NULL;
gfloat n_shrink_lines = n_lines; gfloat n_shrink_lines = n_lines;
@ -632,8 +644,9 @@ gtk_vwrap_box_size_allocate (GtkWidget *widget,
/*<h2v-off>*/ /*<h2v-off>*/
/* g_print ("got: width %d, height %d\n", /* g_print ("got: width %d, height %d\n",
allocation->width, allocation->width,
allocation->height); */ allocation->height);
*/
/*<h2v-on>*/ /*<h2v-on>*/
layout_cols (wbox, &area); layout_cols (wbox, &area);

View File

@ -137,6 +137,8 @@ gtk_wrap_box_class_init (GtkWrapBoxClass *class)
container_class->child_type = gtk_wrap_box_child_type; container_class->child_type = gtk_wrap_box_child_type;
container_class->set_child_arg = gtk_wrap_box_set_child_arg; container_class->set_child_arg = gtk_wrap_box_set_child_arg;
container_class->get_child_arg = gtk_wrap_box_get_child_arg; container_class->get_child_arg = gtk_wrap_box_get_child_arg;
class->rlist_line_children = NULL;
gtk_object_add_arg_type ("GtkWrapBox::homogeneous", gtk_object_add_arg_type ("GtkWrapBox::homogeneous",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS); GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);
@ -599,6 +601,54 @@ gtk_wrap_box_set_child_packing (GtkWrapBox *wbox,
} }
} }
guint*
gtk_wrap_box_query_line_lengths (GtkWrapBox *wbox,
guint *_n_lines)
{
GtkWrapBoxChild *next_child = NULL;
GtkAllocation area, *allocation;
gboolean expand_line;
GSList *slist;
guint max_child_size, border, n_lines = 0, *lines = NULL;
if (_n_lines)
*_n_lines = 0;
g_return_val_if_fail (GTK_IS_WRAP_BOX (wbox), NULL);
allocation = &GTK_WIDGET (wbox)->allocation;
border = GTK_CONTAINER (wbox)->border_width;
area.x = allocation->x + border;
area.y = allocation->y + border;
area.width = MAX (1, (gint) allocation->width - border * 2);
area.height = MAX (1, (gint) allocation->height - border * 2);
next_child = wbox->children;
slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
&area,
&max_child_size,
&expand_line);
while (slist)
{
guint l = n_lines++;
lines = g_renew (guint, lines, n_lines);
lines[l] = g_slist_length (slist);
g_slist_free (slist);
slist = GTK_WRAP_BOX_GET_CLASS (wbox)->rlist_line_children (wbox,
&next_child,
&area,
&max_child_size,
&expand_line);
}
if (_n_lines)
*_n_lines = n_lines;
return lines;
}
static void static void
gtk_wrap_box_map (GtkWidget *widget) gtk_wrap_box_map (GtkWidget *widget)
{ {
@ -659,7 +709,7 @@ gtk_wrap_box_expose (GtkWidget *widget,
gtk_widget_intersect (child->widget, &event->area, &child_event.area)) gtk_widget_intersect (child->widget, &event->area, &child_event.area))
gtk_widget_event (child->widget, (GdkEvent*) &child_event); gtk_widget_event (child->widget, (GdkEvent*) &child_event);
return FALSE; return TRUE;
} }
static void static void

View File

@ -64,6 +64,12 @@ struct _GtkWrapBox
struct _GtkWrapBoxClass struct _GtkWrapBoxClass
{ {
GtkContainerClass parent_class; GtkContainerClass parent_class;
GSList* (*rlist_line_children) (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
GtkAllocation *area,
guint *max_child_size,
gboolean *expand_line);
}; };
struct _GtkWrapBoxChild struct _GtkWrapBoxChild
{ {
@ -114,6 +120,8 @@ void gtk_wrap_box_set_child_packing (GtkWrapBox *wbox,
gboolean hfill, gboolean hfill,
gboolean vexpand, gboolean vexpand,
gboolean vfill); gboolean vfill);
guint* gtk_wrap_box_query_line_lengths (GtkWrapBox *wbox,
guint *n_lines);