summaryrefslogtreecommitdiff
path: root/gtk/gtkfixed.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2019-03-26 16:50:30 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2019-03-26 18:15:13 +0000
commitdd5c981b63166149ed3bd909fda7e2ee21eac676 (patch)
treeb32e2a7139758e0346cd2eec91f05d64838371b1 /gtk/gtkfixed.c
parent9a4c19349e19b73237f55ac2d2a02bce784ebd4c (diff)
downloadgtk+-dd5c981b63166149ed3bd909fda7e2ee21eac676.tar.gz
Use GtkFixedLayout in GtkFixed
Drop the child properties and the sizing code.
Diffstat (limited to 'gtk/gtkfixed.c')
-rw-r--r--gtk/gtkfixed.c287
1 files changed, 55 insertions, 232 deletions
diff --git a/gtk/gtkfixed.c b/gtk/gtkfixed.c
index aaac22cc49..a0d1b41829 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,50 @@ 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)
+/**
+ * gtk_fixed_get_child_position:
+ * @fixed: a #GtkFixed
+ * @widget: a child of @fixed
+ * @x: (out): the horizontal position of the @widget
+ * @y: (out): the vertical position of the @widget
+ *
+ * Retrieves the position of the given child #GtkWidget in the given
+ * #GtkFixed container.
+ */
+void
+gtk_fixed_get_child_position (GtkFixed *fixed,
+ GtkWidget *widget,
+ gint *x,
+ gint *y)
{
- g_return_if_fail (GTK_IS_FIXED (fixed));
-
- gtk_widget_freeze_child_notify (widget);
+ GtkFixedPrivate *priv = gtk_fixed_get_instance_private (fixed);
+ GtkFixedLayoutChild *child_info;
+ graphene_point_t pos;
- 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 +213,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);
-
- 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;
+ GtkFixedPrivate *priv = gtk_fixed_get_instance_private (fixed);
+ GtkFixedLayoutChild *child_info;
- 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