[gtk/wip/layout-manager] Add GtkLegacyLayout
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/layout-manager] Add GtkLegacyLayout
- Date: Mon, 28 Jan 2019 14:05:39 +0000 (UTC)
commit 423d5e166eb6dade38382cb3ecd84c6ad1979106
Author: Emmanuele Bassi <ebassi gnome org>
Date: Mon Jan 28 14:03:25 2019 +0000
Add GtkLegacyLayout
GtkLegacyLayout is a layout manager for the transitional period between
the introduction of layout managers and the removal of GtkWidget virtual
functions for the size negotiation.
gtk/gtklegacylayout.c | 129 +++++++++++++++++++++++++++++++++++++++++++
gtk/gtklegacylayoutprivate.h | 33 +++++++++++
gtk/meson.build | 1 +
3 files changed, 163 insertions(+)
---
diff --git a/gtk/gtklegacylayout.c b/gtk/gtklegacylayout.c
new file mode 100644
index 0000000000..17596a7f6e
--- /dev/null
+++ b/gtk/gtklegacylayout.c
@@ -0,0 +1,129 @@
+/*< private >
+ * SECTION:gtklegacylayout
+ * @Title: GtkLegacyLayout
+ * @Short_description: A legacy layout manager
+ *
+ * #GtkLegacyLayout is a convenience type meant to be used as a transition
+ * mechanism between #GtkContainers implementing a layout policy, and
+ * #GtkLayoutManager classes.
+ *
+ * A #GtkLegacyLayout uses closures matching to the old #GtkWidget virtual
+ * functions for size negotiation, to ease the porting towards the
+ * corresponding #GtkLayoutManager virtual functions.
+ */
+
+#include "config.h"
+
+#include "gtklegacylayoutprivate.h"
+
+struct _GtkLegacyLayout
+{
+ GtkLayoutManager parent_instance;
+
+ GtkLegacyRequestModeFunc request_mode_func;
+ GtkLegacyMeasureFunc measure_func;
+ GtkLegacyAllocateFunc allocate_func;
+};
+
+G_DEFINE_TYPE (GtkLegacyLayout, gtk_legacy_layout, GTK_TYPE_LAYOUT_MANAGER)
+
+static GtkSizeRequestMode
+gtk_legacy_layout_get_request_mode (GtkLayoutManager *manager,
+ GtkWidget *widget)
+{
+ GtkLegacyLayout *self = GTK_LEGACY_LAYOUT (manager);
+
+ if (self->request_mode_func != NULL)
+ return self->request_mode_func (widget);
+
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+}
+
+static void
+gtk_legacy_layout_measure (GtkLayoutManager *manager,
+ GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum_p,
+ int *natural_p,
+ int *minimum_baseline_p,
+ int *natural_baseline_p)
+{
+ GtkLegacyLayout *self = GTK_LEGACY_LAYOUT (manager);
+ int minimum = 0, natural = 0;
+ int minimum_baseline = 0, natural_baseline = 0;
+
+ if (self->measure_func != NULL)
+ self->measure_func (widget, orientation, for_size,
+ &minimum, &natural,
+ &minimum_baseline, &natural_baseline);
+
+ if (minimum_p != NULL)
+ *minimum_p = minimum;
+ if (natural_p != NULL)
+ *natural_p = natural;
+
+ if (minimum_baseline_p != NULL)
+ *minimum_baseline_p = minimum_baseline;
+ if (natural_baseline_p != NULL)
+ *natural_baseline_p = natural_baseline;
+}
+
+static void
+gtk_legacy_layout_allocate (GtkLayoutManager *manager,
+ GtkWidget *widget,
+ int width,
+ int height,
+ int baseline)
+{
+ GtkLegacyLayout *self = GTK_LEGACY_LAYOUT (manager);
+
+ if (self->allocate_func != NULL)
+ self->allocate_func (widget, width, height, baseline);
+}
+
+static void
+gtk_legacy_layout_class_init (GtkLegacyLayoutClass *klass)
+{
+ GtkLayoutManagerClass *layout_class = GTK_LAYOUT_MANAGER_CLASS (klass);
+
+ layout_class->get_request_mode = gtk_legacy_layout_get_request_mode;
+ layout_class->measure = gtk_legacy_layout_measure;
+ layout_class->allocate = gtk_legacy_layout_allocate;
+}
+
+static void
+gtk_legacy_layout_init (GtkLegacyLayout *self)
+{
+}
+
+/*< private >
+ * gtk_legacy_layout_new:
+ * @request_mode: (nullable): a function to retrieve
+ * the #GtkSizeRequestMode of the widget using the layout
+ * @measure: (nullable): a fucntion to measure the widget
+ * using the layout
+ * @allocate: (nullable): a function to allocate the children
+ * of the widget using the layout
+ *
+ * Creates a new legacy layout manager.
+ *
+ * Legacy layout managers map to the old #GtkWidget size negotiation
+ * virtual functions, and are meant to be used during the transition
+ * from layout containers to layout manager delegates.
+ *
+ * Returns: (transfer full): the newly created #GtkLegacyLayout
+ */
+GtkLayoutManager *
+gtk_legacy_layout_new (GtkLegacyRequestModeFunc request_mode,
+ GtkLegacyMeasureFunc measure,
+ GtkLegacyAllocateFunc allocate)
+{
+ GtkLegacyLayout *self = g_object_new (GTK_TYPE_LEGACY_LAYOUT, NULL);
+
+ self->request_mode_func = request_mode;
+ self->measure_func = measure;
+ self->allocate_func = allocate;
+
+ return GTK_LAYOUT_MANAGER (self);
+}
diff --git a/gtk/gtklegacylayoutprivate.h b/gtk/gtklegacylayoutprivate.h
new file mode 100644
index 0000000000..47fe5d6998
--- /dev/null
+++ b/gtk/gtklegacylayoutprivate.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <gtk/gtklayoutmanager.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_LEGACY_LAYOUT (gtk_legacy_layout_get_type ())
+
+typedef GtkSizeRequestMode (* GtkLegacyRequestModeFunc) (GtkWidget *widget);
+
+typedef void (* GtkLegacyMeasureFunc) (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline);
+
+typedef void (* GtkLegacyAllocateFunc) (GtkWidget *widget,
+ int width,
+ int height,
+ int baseline);
+
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkLegacyLayout, gtk_legacy_layout, GTK, LEGACY_LAYOUT, GtkLayoutManager)
+
+GDK_AVAILABLE_IN_ALL
+GtkLayoutManager *
+gtk_legacy_layout_new (GtkLegacyRequestModeFunc request_mode,
+ GtkLegacyMeasureFunc measure,
+ GtkLegacyAllocateFunc allocate);
+
+G_END_DECLS
diff --git a/gtk/meson.build b/gtk/meson.build
index f580f205f7..80a3b8c3c4 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -116,6 +116,7 @@ gtk_private_sources = files([
'gtkiconhelper.c',
'gtkkineticscrolling.c',
'gtkkeyhash.c',
+ 'gtklegacylayout.c',
'gtkmagnifier.c',
'gtkmenusectionbox.c',
'gtkmenutracker.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]