[dia/dia-next: 12/59] Port Gtk[VH]WrapBox to Gtk3
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/dia-next: 12/59] Port Gtk[VH]WrapBox to Gtk3
- Date: Wed, 9 Jan 2019 18:35:18 +0000 (UTC)
commit 6046930f870b114deca5bc69a88762a58211915c
Author: Zander Brown <zbrown gnome org>
Date: Sun Dec 23 18:54:16 2018 +0000
Port Gtk[VH]WrapBox to Gtk3
Certain level of irony in that
app/gtkhwrapbox.c | 132 +++++++++++++++++++++++++++++++++---------------------
app/gtkvwrapbox.c | 89 ++++++++++++++++++++++++------------
app/gtkwrapbox.c | 52 +++++++--------------
app/gtkwrapbox.h | 2 +-
4 files changed, 158 insertions(+), 117 deletions(-)
---
diff --git a/app/gtkhwrapbox.c b/app/gtkhwrapbox.c
index 30f5a46f..b44f30da 100644
--- a/app/gtkhwrapbox.c
+++ b/app/gtkhwrapbox.c
@@ -23,21 +23,22 @@
#include "config.h"
#include "gtkhwrapbox.h"
-#include <gtk/gtkversion.h>
/* --- prototypes --- */
-static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass);
-static void gtk_hwrap_box_init (GtkHWrapBox *hwbox);
-static void gtk_hwrap_box_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_hwrap_box_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static GSList* reverse_list_row_children (GtkWrapBox *wbox,
- GtkWrapBoxChild **child_p,
- GtkAllocation *area,
- guint *max_height,
- gboolean *can_vexpand);
+static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass);
+static void gtk_hwrap_box_init (GtkHWrapBox *hwbox);
+static void gtk_hwrap_box_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimal_size,
+ gint *natural_size);
+static void gtk_hwrap_box_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static GSList* reverse_list_row_children (GtkWrapBox *wbox,
+ GtkWrapBoxChild **child_p,
+ GtkAllocation *area,
+ guint *max_height,
+ gboolean *can_vexpand);
/* --- variables --- */
@@ -72,6 +73,29 @@ gtk_hwrap_box_get_type (void)
return hwrap_box_type;
}
+
+static void
+gtk_hwrap_box_get_preferred_width (GtkWidget *widget,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ gtk_hwrap_box_get_preferred_size (widget,
+ GTK_ORIENTATION_HORIZONTAL,
+ minimal_width,
+ natural_width);
+}
+
+static void
+gtk_hwrap_box_get_preferred_height (GtkWidget *widget,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ gtk_hwrap_box_get_preferred_size (widget,
+ GTK_ORIENTATION_VERTICAL,
+ minimal_height,
+ natural_height);
+}
+
static void
gtk_hwrap_box_class_init (GtkHWrapBoxClass *class)
{
@@ -87,7 +111,8 @@ gtk_hwrap_box_class_init (GtkHWrapBoxClass *class)
parent_class = g_type_class_peek_parent (class);
- widget_class->size_request = gtk_hwrap_box_size_request;
+ widget_class->get_preferred_width = gtk_hwrap_box_get_preferred_width;
+ widget_class->get_preferred_height = gtk_hwrap_box_get_preferred_height;
widget_class->size_allocate = gtk_hwrap_box_size_allocate;
wrap_box_class->rlist_line_children = reverse_list_row_children;
@@ -183,43 +208,38 @@ get_layout_size (GtkHWrapBox *this,
}
static void
-gtk_hwrap_box_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_hwrap_box_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimal_size,
+ gint *natural_size)
{
GtkHWrapBox *this = GTK_HWRAP_BOX (widget);
GtkWrapBox *wbox = GTK_WRAP_BOX (widget);
GtkWrapBoxChild *child;
gfloat ratio_dist, layout_width = 0;
guint row_inc = 0;
+ gint height;
+ gint width;
- g_return_if_fail (requisition != NULL);
-
- requisition->width = 0;
- requisition->height = 0;
+ width = 0;
+ height = 0;
this->max_child_width = 0;
this->max_child_height = 0;
/* size_request all children */
- for (child = wbox->children; child; child = child->next)
-#if GTK_CHECK_VERSION(2,20,0)
- if (gtk_widget_get_visible (child->widget))
-#else
- if (GTK_WIDGET_VISIBLE (child->widget))
-#endif
- {
- GtkRequisition child_requisition;
-
- gtk_widget_size_request (child->widget, &child_requisition);
-
- this->max_child_width = MAX (this->max_child_width, child_requisition.width);
- this->max_child_height = MAX (this->max_child_height, child_requisition.height);
- }
-
- /* figure all possible layouts */
- ratio_dist = 32768;
- layout_width = this->max_child_width;
- do
- {
+ for (child = wbox->children; child; child = child->next) {
+ if (gtk_widget_get_visible (child->widget)) {
+ GtkRequisition child_requisition;
+
+ gtk_widget_size_request (child->widget, &child_requisition);
+ this->max_child_width = MAX (this->max_child_width, child_requisition.width);
+ this->max_child_height = MAX (this->max_child_height, child_requisition.height);
+ }
+
+ /* figure all possible layouts */
+ ratio_dist = 32768;
+ layout_width = this->max_child_width;
+ do {
gfloat layout_height;
gfloat ratio, dist;
@@ -227,27 +247,34 @@ gtk_hwrap_box_size_request (GtkWidget *widget,
layout_height = get_layout_size (this, layout_width, &row_inc);
ratio = layout_width / layout_height; /*<h2v-skip>*/
dist = MAX (ratio, wbox->aspect_ratio) - MIN (ratio, wbox->aspect_ratio);
- if (dist < ratio_dist)
- {
- ratio_dist = dist;
- requisition->width = layout_width;
- requisition->height = layout_height;
- }
+ if (dist < ratio_dist) {
+ ratio_dist = dist;
+ width = layout_width;
+ height = layout_height;
+ }
/* g_print ("ratio for width %d height %d = %f\n",
(gint) layout_width,
(gint) layout_height,
ratio);
*/
- }
- while (row_inc);
-
- requisition->width += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
- requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
+ } while (row_inc);
+
+ width += gtk_container_get_border_width (GTK_CONTAINER (wbox)) * 2; /*<h2v-skip>*/
+ height += gtk_container_get_border_width (GTK_CONTAINER (wbox)) * 2; /*<h2v-skip>*/
/* g_print ("chosen: width %d, height %d\n",
requisition->width,
requisition->height);
*/
+ }
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ *minimal_size = width;
+ *natural_size = width;
+ } else {
+ *minimal_size = height;
+ *natural_size = height;
+ }
}
static GSList*
@@ -618,9 +645,8 @@ gtk_hwrap_box_size_allocate (GtkWidget *widget,
{
GtkWrapBox *wbox = GTK_WRAP_BOX (widget);
GtkAllocation area;
- gint border = GTK_CONTAINER (wbox)->border_width; /*<h2v-skip>*/
+ gint border = gtk_container_get_border_width (GTK_CONTAINER (wbox)); /*<h2v-skip>*/
- widget->allocation = *allocation;
area.x = allocation->x + border;
area.y = allocation->y + border;
area.width = MAX (1, (gint) allocation->width - border * 2);
@@ -633,5 +659,7 @@ gtk_hwrap_box_size_allocate (GtkWidget *widget,
*/
/*<h2v-on>*/
+ gtk_widget_set_allocation (widget, allocation);
+
layout_rows (wbox, &area);
}
diff --git a/app/gtkvwrapbox.c b/app/gtkvwrapbox.c
index f648e0d7..fe51114c 100644
--- a/app/gtkvwrapbox.c
+++ b/app/gtkvwrapbox.c
@@ -23,21 +23,22 @@
#include "config.h"
#include "gtkvwrapbox.h"
-#include <gtk/gtkversion.h>
/* --- prototypes --- */
-static void gtk_vwrap_box_class_init (GtkVWrapBoxClass *klass);
-static void gtk_vwrap_box_init (GtkVWrapBox *vwbox);
-static void gtk_vwrap_box_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_vwrap_box_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static GSList* reverse_list_col_children (GtkWrapBox *wbox,
- GtkWrapBoxChild **child_p,
- GtkAllocation *area,
- guint *max_width,
- gboolean *can_hexpand);
+static void gtk_vwrap_box_class_init (GtkVWrapBoxClass *klass);
+static void gtk_vwrap_box_init (GtkVWrapBox *vwbox);
+static void gtk_vwrap_box_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimal_size,
+ gint *natural_size);
+static void gtk_vwrap_box_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static GSList* reverse_list_col_children (GtkWrapBox *wbox,
+ GtkWrapBoxChild **child_p,
+ GtkAllocation *area,
+ guint *max_width,
+ gboolean *can_hexpand);
/* --- variables --- */
@@ -72,6 +73,28 @@ gtk_vwrap_box_get_type (void)
return vwrap_box_type;
}
+static void
+gtk_vwrap_box_get_preferred_width (GtkWidget *widget,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ gtk_vwrap_box_get_preferred_size (widget,
+ GTK_ORIENTATION_HORIZONTAL,
+ minimal_width,
+ natural_width);
+}
+
+static void
+gtk_vwrap_box_get_preferred_height (GtkWidget *widget,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ gtk_vwrap_box_get_preferred_size (widget,
+ GTK_ORIENTATION_VERTICAL,
+ minimal_height,
+ natural_height);
+}
+
static void
gtk_vwrap_box_class_init (GtkVWrapBoxClass *class)
{
@@ -87,7 +110,8 @@ gtk_vwrap_box_class_init (GtkVWrapBoxClass *class)
parent_class = g_type_class_peek_parent (class);
- widget_class->size_request = gtk_vwrap_box_size_request;
+ widget_class->get_preferred_width = gtk_vwrap_box_get_preferred_width;
+ widget_class->get_preferred_height = gtk_vwrap_box_get_preferred_height;
widget_class->size_allocate = gtk_vwrap_box_size_allocate;
wrap_box_class->rlist_line_children = reverse_list_col_children;
@@ -183,29 +207,27 @@ get_layout_size (GtkVWrapBox *this,
}
static void
-gtk_vwrap_box_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_vwrap_box_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimal_size,
+ gint *natural_size)
{
GtkVWrapBox *this = GTK_VWRAP_BOX (widget);
GtkWrapBox *wbox = GTK_WRAP_BOX (widget);
GtkWrapBoxChild *child;
gfloat ratio_dist, layout_height = 0;
guint col_inc = 0;
+ gint height;
+ gint width;
- g_return_if_fail (requisition != NULL);
-
- requisition->height = 0;
- requisition->width = 0;
+ height = 0;
+ width = 0;
this->max_child_height = 0;
this->max_child_width = 0;
/* size_request all children */
for (child = wbox->children; child; child = child->next)
-#if GTK_CHECK_VERSION(2,20,0)
if (gtk_widget_get_visible (child->widget))
-#else
- if (GTK_WIDGET_VISIBLE (child->widget))
-#endif
{
GtkRequisition child_requisition;
@@ -230,8 +252,8 @@ gtk_vwrap_box_size_request (GtkWidget *widget,
if (dist < ratio_dist)
{
ratio_dist = dist;
- requisition->height = layout_height;
- requisition->width = layout_width;
+ height = layout_height;
+ width = layout_width;
}
/* g_print ("ratio for height %d width %d = %f\n",
@@ -242,12 +264,20 @@ gtk_vwrap_box_size_request (GtkWidget *widget,
}
while (col_inc);
- requisition->width += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
- requisition->height += GTK_CONTAINER (wbox)->border_width * 2; /*<h2v-skip>*/
+ width += gtk_container_get_border_width (GTK_CONTAINER (wbox)) * 2; /*<h2v-skip>*/
+ height += gtk_container_get_border_width (GTK_CONTAINER (wbox)) * 2; /*<h2v-skip>*/
/* g_print ("chosen: height %d, width %d\n",
requisition->height,
requisition->width);
*/
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+ *minimal_size = width;
+ *natural_size = width;
+ } else {
+ *minimal_size = height;
+ *natural_size = height;
+ }
}
static GSList*
@@ -618,14 +648,15 @@ gtk_vwrap_box_size_allocate (GtkWidget *widget,
{
GtkWrapBox *wbox = GTK_WRAP_BOX (widget);
GtkAllocation area;
- gint border = GTK_CONTAINER (wbox)->border_width; /*<h2v-skip>*/
+ gint border = gtk_container_get_border_width (GTK_CONTAINER (wbox)); /*<h2v-skip>*/
- widget->allocation = *allocation;
area.y = allocation->y + border;
area.x = allocation->x + border;
area.height = MAX (1, (gint) allocation->height - border * 2);
area.width = MAX (1, (gint) allocation->width - border * 2);
+ gtk_widget_set_allocation (widget, allocation);
+
/*<h2v-off>*/
/* g_print ("got: width %d, height %d\n",
allocation->width,
diff --git a/app/gtkwrapbox.c b/app/gtkwrapbox.c
index 6043de02..0614a5c8 100644
--- a/app/gtkwrapbox.c
+++ b/app/gtkwrapbox.c
@@ -23,7 +23,6 @@
#include "config.h"
#include "gtkwrapbox.h"
-#include <gtk/gtkversion.h>
/* --- properties --- */
@@ -73,8 +72,8 @@ static void gtk_wrap_box_get_child_property (GtkContainer *container,
GParamSpec *pspec);
static void gtk_wrap_box_map (GtkWidget *widget);
static void gtk_wrap_box_unmap (GtkWidget *widget);
-static gint gtk_wrap_box_expose (GtkWidget *widget,
- GdkEventExpose *event);
+static gint gtk_wrap_box_draw (GtkWidget *widget,
+ cairo_t *ctx);
static void gtk_wrap_box_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_wrap_box_remove (GtkContainer *container,
@@ -136,7 +135,7 @@ gtk_wrap_box_class_init (GtkWrapBoxClass *class)
widget_class->map = gtk_wrap_box_map;
widget_class->unmap = gtk_wrap_box_unmap;
- widget_class->expose_event = gtk_wrap_box_expose;
+ widget_class->draw = gtk_wrap_box_draw;
container_class->add = gtk_wrap_box_add;
container_class->remove = gtk_wrap_box_remove;
@@ -353,8 +352,8 @@ gtk_wrap_box_get_property (GObject *object,
g_value_set_float (value, wbox->aspect_ratio);
break;
case PROP_CURRENT_RATIO:
- g_value_set_float (value, (((gfloat) widget->allocation.width) /
- ((gfloat) widget->allocation.height)));
+ g_value_set_float (value, (((gfloat) gtk_widget_get_allocated_width (widget)) /
+ ((gfloat) gtk_widget_get_allocated_height (widget))));
break;
case PROP_CHILD_LIMIT:
g_value_set_uint (value, wbox->child_limit);
@@ -576,7 +575,7 @@ gtk_wrap_box_pack (GtkWrapBox *wbox,
{
g_return_if_fail (GTK_IS_WRAP_BOX (wbox));
g_return_if_fail (GTK_IS_WIDGET (child));
- g_return_if_fail (child->parent == NULL);
+ g_return_if_fail (gtk_widget_get_parent (child) == NULL);
gtk_wrap_box_pack_wrapped (wbox, child, hexpand, hfill, vexpand, vfill, FALSE);
}
@@ -594,14 +593,9 @@ gtk_wrap_box_pack_wrapped (GtkWrapBox *wbox,
g_return_if_fail (GTK_IS_WRAP_BOX (wbox));
g_return_if_fail (GTK_IS_WIDGET (child));
- g_return_if_fail (child->parent == NULL);
+ g_return_if_fail (gtk_widget_get_parent (child) == NULL);
-#if GLIB_CHECK_VERSION(2,10,0)
child_info = g_slice_new (GtkWrapBoxChild);
-#else
- child_info = g_new (GtkWrapBoxChild, 1);
-#endif
-
child_info->widget = child;
child_info->hexpand = hexpand ? TRUE : FALSE;
child_info->hfill = hfill ? TRUE : FALSE;
@@ -623,24 +617,12 @@ gtk_wrap_box_pack_wrapped (GtkWrapBox *wbox,
gtk_widget_set_parent (child, GTK_WIDGET (wbox));
-#if GTK_CHECK_VERSION(2,20,0)
if (gtk_widget_get_realized (GTK_WIDGET (wbox)))
-#else
- if (GTK_WIDGET_REALIZED (wbox))
-#endif
gtk_widget_realize (child);
-#if GTK_CHECK_VERSION(2,20,0)
if (gtk_widget_get_visible (GTK_WIDGET (wbox)) && gtk_widget_get_visible (child))
-#else
- if (GTK_WIDGET_VISIBLE (wbox) && GTK_WIDGET_VISIBLE (child))
-#endif
{
-#if GTK_CHECK_VERSION(2,20,0)
if (gtk_widget_get_mapped (GTK_WIDGET (wbox)))
-#else
- if (GTK_WIDGET_MAPPED (wbox))
-#endif
gtk_widget_map (child);
gtk_widget_queue_resize (child);
@@ -784,7 +766,7 @@ gtk_wrap_box_query_line_lengths (GtkWrapBox *wbox,
guint *_n_lines)
{
GtkWrapBoxChild *next_child = NULL;
- GtkAllocation area, *allocation;
+ GtkAllocation area, allocation;
gboolean expand_line;
GSList *slist;
guint max_child_size, border, n_lines = 0, *lines = NULL;
@@ -793,12 +775,12 @@ gtk_wrap_box_query_line_lengths (GtkWrapBox *wbox,
*_n_lines = 0;
g_return_val_if_fail (GTK_IS_WRAP_BOX (wbox), NULL);
- allocation = >K_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);
+ gtk_widget_get_allocation (wbox, &allocation);
+ border = gtk_container_get_border_width (GTK_CONTAINER (wbox));
+ 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,
@@ -880,10 +862,10 @@ gtk_wrap_box_unmap (GtkWidget *widget)
}
static gint
-gtk_wrap_box_expose (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_wrap_box_draw (GtkWidget *widget,
+ cairo_t *ctx)
{
- return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ return GTK_WIDGET_CLASS (parent_class)->draw (widget, ctx);
}
static void
diff --git a/app/gtkwrapbox.h b/app/gtkwrapbox.h
index e557b5da..dc65444e 100644
--- a/app/gtkwrapbox.h
+++ b/app/gtkwrapbox.h
@@ -24,7 +24,7 @@
#define __GTK_WRAP_BOX_H__
-#include <gtk/gtkcontainer.h>
+#include <gtk/gtk.h>
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]