[gtk/fixed-layout: 21/21] Use GtkFixedLayout in GtkFixed
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/fixed-layout: 21/21] Use GtkFixedLayout in GtkFixed
- Date: Tue, 26 Mar 2019 17:41:16 +0000 (UTC)
commit 32d3eb4be913143dd26286fe171703f30f69eab3
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Mar 26 16:50:30 2019 +0000
Use GtkFixedLayout in GtkFixed
Drop the child properties and the sizing code.
demos/gtk-demo/dnd.c | 4 +-
gtk/gtkfixed.c | 277 +++++++++------------------------------------------
gtk/gtkfixed.h | 6 +-
3 files changed, 52 insertions(+), 235 deletions(-)
---
diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c
index 4c28e17676..665768abba 100644
--- a/demos/gtk-demo/dnd.c
+++ b/demos/gtk-demo/dnd.c
@@ -196,7 +196,7 @@ edit_label_done (GtkWidget *entry, gpointer data)
GtkWidget *label;
int x, y;
- gtk_container_child_get (GTK_CONTAINER (fixed), entry, "x", &x, "y", &y, NULL);
+ gtk_fixed_get_position (GTK_FIXED (fixed), entry, &x, &y);
label = GTK_WIDGET (g_object_get_data (G_OBJECT (entry), "label"));
gtk_label_set_text (GTK_LABEL (label), gtk_editable_get_text (GTK_EDITABLE (entry)));
@@ -210,7 +210,7 @@ edit_cb (GtkWidget *child)
GtkWidget *fixed = gtk_widget_get_parent (child);
int x, y;
- gtk_container_child_get (GTK_CONTAINER (fixed), child, "x", &x, "y", &y, NULL);
+ gtk_fixed_get_position (GTK_FIXED (fixed), child, &x, &y);
if (GTK_IS_LABEL (child))
{
diff --git a/gtk/gtkfixed.c b/gtk/gtkfixed.c
index aaac22cc49..0810135cb6 100644
--- a/gtk/gtkfixed.c
+++ b/gtk/gtkfixed.c
@@ -76,37 +76,11 @@
#include "gtkfixed.h"
#include "gtkcontainerprivate.h"
-#include "gtkwidgetprivate.h"
-#include "gtkprivate.h"
+#include "gtkfixedlayout.h"
#include "gtkintl.h"
+#include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
-typedef struct
-{
- gint x;
- gint y;
-} GtkFixedChild;
-
-enum {
- CHILD_PROP_0,
- CHILD_PROP_X,
- CHILD_PROP_Y
-};
-
-static GQuark child_data_quark = 0;
-
-static void gtk_fixed_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline);
-
-
-static void gtk_fixed_size_allocate (GtkWidget *widget,
- int width,
- int height,
- int baseline);
static void gtk_fixed_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_fixed_remove (GtkContainer *container,
@@ -116,63 +90,21 @@ static void gtk_fixed_forall (GtkContainer *container,
gpointer callback_data);
static GType gtk_fixed_child_type (GtkContainer *container);
-static void gtk_fixed_set_child_property (GtkContainer *container,
- GtkWidget *child,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_fixed_get_child_property (GtkContainer *container,
- GtkWidget *child,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE (GtkFixed, gtk_fixed, GTK_TYPE_CONTAINER)
-
-static GtkFixedChild *
-get_fixed_child (GtkWidget *widget)
-{
- g_assert (GTK_IS_FIXED (gtk_widget_get_parent (widget)));
+typedef struct {
+ GtkLayoutManager *layout;
+} GtkFixedPrivate;
- return (GtkFixedChild *) g_object_get_qdata (G_OBJECT (widget), child_data_quark);
-}
+G_DEFINE_TYPE_WITH_PRIVATE (GtkFixed, gtk_fixed, GTK_TYPE_CONTAINER)
static void
-gtk_fixed_class_init (GtkFixedClass *class)
+gtk_fixed_class_init (GtkFixedClass *klass)
{
- GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
-
- widget_class = (GtkWidgetClass*) class;
- container_class = (GtkContainerClass*) class;
-
- widget_class->measure = gtk_fixed_measure;
- widget_class->size_allocate = gtk_fixed_size_allocate;
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
container_class->add = gtk_fixed_add;
container_class->remove = gtk_fixed_remove;
container_class->forall = gtk_fixed_forall;
container_class->child_type = gtk_fixed_child_type;
- container_class->set_child_property = gtk_fixed_set_child_property;
- container_class->get_child_property = gtk_fixed_get_child_property;
-
- gtk_container_class_install_child_property (container_class,
- CHILD_PROP_X,
- g_param_spec_int ("x",
- P_("X position"),
- P_("X position of child widget"),
- G_MININT, G_MAXINT, 0,
- GTK_PARAM_READWRITE));
-
- gtk_container_class_install_child_property (container_class,
- CHILD_PROP_Y,
- g_param_spec_int ("y",
- P_("Y position"),
- P_("Y position of child widget"),
- G_MININT, G_MAXINT, 0,
- GTK_PARAM_READWRITE));
-
- child_data_quark = g_quark_from_static_string ("gtk-fixed-child-data");
}
static GType
@@ -182,9 +114,14 @@ gtk_fixed_child_type (GtkContainer *container)
}
static void
-gtk_fixed_init (GtkFixed *fixed)
+gtk_fixed_init (GtkFixed *self)
{
- gtk_widget_set_has_surface (GTK_WIDGET (fixed), FALSE);
+ GtkFixedPrivate *priv = gtk_fixed_get_instance_private (self);
+
+ gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
+
+ priv->layout = gtk_fixed_layout_new ();
+ gtk_widget_set_layout_manager (GTK_WIDGET (self), priv->layout);
}
/**
@@ -215,48 +152,40 @@ gtk_fixed_put (GtkFixed *fixed,
gint x,
gint y)
{
- GtkFixedChild *child_info;
+ GtkFixedPrivate *priv = gtk_fixed_get_instance_private (fixed);
+ GtkFixedLayoutChild *child_info;
g_return_if_fail (GTK_IS_FIXED (fixed));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (_gtk_widget_get_parent (widget) == NULL);
- child_info = g_new (GtkFixedChild, 1);
- child_info->x = x;
- child_info->y = y;
-
- g_object_set_qdata_full (G_OBJECT (widget), child_data_quark, child_info, g_free);
gtk_widget_set_parent (widget, GTK_WIDGET (fixed));
+
+ child_info = GTK_FIXED_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (priv->layout, widget));
+ gtk_fixed_layout_child_set_position (child_info, &GRAPHENE_POINT_INIT (x, y));
}
-static void
-gtk_fixed_move_internal (GtkFixed *fixed,
- GtkWidget *widget,
- GtkFixedChild *child,
- gint x,
- gint y)
+void
+gtk_fixed_get_position (GtkFixed *fixed,
+ GtkWidget *widget,
+ gint *x,
+ gint *y)
{
- g_return_if_fail (GTK_IS_FIXED (fixed));
+ GtkFixedPrivate *priv = gtk_fixed_get_instance_private (fixed);
+ GtkFixedLayoutChild *child_info;
+ graphene_point_t pos;
- gtk_widget_freeze_child_notify (widget);
-
- if (child->x != x)
- {
- child->x = x;
- gtk_widget_child_notify (widget, "x");
- }
-
- if (child->y != y)
- {
- child->y = y;
- gtk_widget_child_notify (widget, "y");
- }
+ g_return_if_fail (GTK_IS_FIXED (fixed));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (fixed));
- gtk_widget_thaw_child_notify (widget);
+ child_info = GTK_FIXED_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (priv->layout, widget));
+ gtk_fixed_layout_child_get_position (child_info, &pos);
- if (gtk_widget_get_visible (widget) &&
- gtk_widget_get_visible (GTK_WIDGET (fixed)))
- gtk_widget_queue_resize (GTK_WIDGET (fixed));
+ if (x != NULL)
+ *x = floorf (pos.x);
+ if (y != NULL)
+ *y = floorf (pos.y);
}
/**
@@ -274,131 +203,15 @@ gtk_fixed_move (GtkFixed *fixed,
gint x,
gint y)
{
- g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (fixed));
-
- gtk_fixed_move_internal (fixed, widget, get_fixed_child (widget), x, y);
-}
-
-static void
-gtk_fixed_set_child_property (GtkContainer *container,
- GtkWidget *child,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkFixed *fixed = GTK_FIXED (container);
- GtkFixedChild *fixed_child = get_fixed_child (child);
+ GtkFixedPrivate *priv = gtk_fixed_get_instance_private (fixed);
+ GtkFixedLayoutChild *child_info;
- switch (property_id)
- {
- case CHILD_PROP_X:
- gtk_fixed_move_internal (fixed,
- child,
- fixed_child,
- g_value_get_int (value),
- fixed_child->y);
- break;
- case CHILD_PROP_Y:
- gtk_fixed_move_internal (fixed,
- child,
- fixed_child,
- fixed_child->x,
- g_value_get_int (value));
- break;
- default:
- GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
- break;
- }
-}
-
-static void
-gtk_fixed_get_child_property (GtkContainer *container,
- GtkWidget *child,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkFixedChild *fixed_child = get_fixed_child (child);
-
- switch (property_id)
- {
- case CHILD_PROP_X:
- g_value_set_int (value, fixed_child->x);
- break;
- case CHILD_PROP_Y:
- g_value_set_int (value, fixed_child->y);
- break;
- default:
- GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
- break;
- }
-}
-
-static void
-gtk_fixed_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline)
-{
- int child_min, child_nat;
- GtkWidget *child;
- GtkFixedChild *child_info;
-
- for (child = gtk_widget_get_first_child (widget);
- child != NULL;
- child = gtk_widget_get_next_sibling (child))
- {
- child_info = get_fixed_child (child);
-
- if (!gtk_widget_get_visible (child))
- continue;
-
- gtk_widget_measure (child, orientation, -1, &child_min, &child_nat, NULL, NULL);
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- *minimum = MAX (*minimum, child_info->x + child_min);
- *natural = MAX (*natural, child_info->x + child_nat);
- }
- else /* VERTICAL */
- {
- *minimum = MAX (*minimum, child_info->y + child_min);
- *natural = MAX (*natural, child_info->y + child_nat);
- }
- }
-}
-
-static void
-gtk_fixed_size_allocate (GtkWidget *widget,
- int width,
- int height,
- int baseline)
-{
- GtkWidget *child;
- GtkFixedChild *child_info;
- GtkAllocation child_allocation;
- GtkRequisition child_requisition;
-
- for (child = gtk_widget_get_first_child (widget);
- child != NULL;
- child = gtk_widget_get_next_sibling (child))
- {
- child_info = get_fixed_child (child);
-
- if (!gtk_widget_get_visible (child))
- continue;
-
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
- child_allocation.x = child_info->x;
- child_allocation.y = child_info->y;
+ g_return_if_fail (GTK_IS_FIXED (fixed));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (fixed));
- child_allocation.width = child_requisition.width;
- child_allocation.height = child_requisition.height;
- gtk_widget_size_allocate (child, &child_allocation, -1);
- }
+ child_info = GTK_FIXED_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (priv->layout, widget));
+ gtk_fixed_layout_child_set_position (child_info, &GRAPHENE_POINT_INIT (x, y));
}
static void
diff --git a/gtk/gtkfixed.h b/gtk/gtkfixed.h
index 74e88d9d3b..819fdafbf9 100644
--- a/gtk/gtkfixed.h
+++ b/gtk/gtkfixed.h
@@ -75,7 +75,11 @@ void gtk_fixed_move (GtkFixed *fixed,
GtkWidget *widget,
gint x,
gint y);
-
+GDK_AVAILABLE_IN_ALL
+void gtk_fixed_get_position (GtkFixed *fixed,
+ GtkWidget *widget,
+ gint *x,
+ gint *y);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]