|
|
@@ -325,3 +325,114 @@ m2_list_model_items_changed (GListModel *model, guint position,
|
|
|
{
|
|
|
g_list_model_items_changed (model, position, removed, added);
|
|
|
}
|
|
|
+
|
|
|
+/* ------------------------------------------------------------------ */
|
|
|
+/* M2LayoutManager (subclass of GtkLayoutManager) */
|
|
|
+/* ------------------------------------------------------------------ */
|
|
|
+
|
|
|
+typedef void (*M2LayoutMeasureFunc) (GtkWidget *widget, int orientation,
|
|
|
+ int for_size, int *minimum, int *natural,
|
|
|
+ gpointer user_data);
|
|
|
+typedef void (*M2LayoutAllocateFunc) (GtkWidget *widget, int width, int height,
|
|
|
+ int baseline, gpointer user_data);
|
|
|
+
|
|
|
+typedef struct _M2LayoutManager M2LayoutManager;
|
|
|
+typedef struct _M2LayoutManagerClass M2LayoutManagerClass;
|
|
|
+
|
|
|
+struct _M2LayoutManager
|
|
|
+{
|
|
|
+ GtkLayoutManager parent_instance;
|
|
|
+ M2LayoutMeasureFunc measure;
|
|
|
+ M2LayoutAllocateFunc allocate;
|
|
|
+ gpointer user_data;
|
|
|
+ GDestroyNotify destroy;
|
|
|
+};
|
|
|
+
|
|
|
+struct _M2LayoutManagerClass
|
|
|
+{
|
|
|
+ GtkLayoutManagerClass parent_class;
|
|
|
+};
|
|
|
+
|
|
|
+static void
|
|
|
+m2_layout_manager_measure (GtkLayoutManager *manager, GtkWidget *widget,
|
|
|
+ GtkOrientation orientation, int for_size,
|
|
|
+ int *minimum, int *natural, int *minimum_baseline,
|
|
|
+ int *natural_baseline)
|
|
|
+{
|
|
|
+ M2LayoutManager *self = (M2LayoutManager *) manager;
|
|
|
+
|
|
|
+ *minimum = 0;
|
|
|
+ *natural = 0;
|
|
|
+ if (self->measure != NULL)
|
|
|
+ self->measure (widget, (int) orientation, for_size, minimum, natural,
|
|
|
+ self->user_data);
|
|
|
+ *minimum_baseline = -1;
|
|
|
+ *natural_baseline = -1;
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+m2_layout_manager_allocate (GtkLayoutManager *manager, GtkWidget *widget,
|
|
|
+ int width, int height, int baseline)
|
|
|
+{
|
|
|
+ M2LayoutManager *self = (M2LayoutManager *) manager;
|
|
|
+
|
|
|
+ if (self->allocate != NULL)
|
|
|
+ self->allocate (widget, width, height, baseline, self->user_data);
|
|
|
+}
|
|
|
+
|
|
|
+G_DEFINE_TYPE (M2LayoutManager, m2_layout_manager, GTK_TYPE_LAYOUT_MANAGER)
|
|
|
+
|
|
|
+static void
|
|
|
+m2_layout_manager_finalize (GObject *object)
|
|
|
+{
|
|
|
+ M2LayoutManager *self = (M2LayoutManager *) object;
|
|
|
+
|
|
|
+ if (self->destroy != NULL)
|
|
|
+ self->destroy (self->user_data);
|
|
|
+
|
|
|
+ G_OBJECT_CLASS (m2_layout_manager_parent_class)->finalize (object);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+m2_layout_manager_class_init (M2LayoutManagerClass *klass)
|
|
|
+{
|
|
|
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
+ GtkLayoutManagerClass *manager_class = GTK_LAYOUT_MANAGER_CLASS (klass);
|
|
|
+
|
|
|
+ object_class->finalize = m2_layout_manager_finalize;
|
|
|
+ manager_class->measure = m2_layout_manager_measure;
|
|
|
+ manager_class->allocate = m2_layout_manager_allocate;
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+m2_layout_manager_init (M2LayoutManager *self)
|
|
|
+{
|
|
|
+ self->measure = NULL;
|
|
|
+ self->allocate = NULL;
|
|
|
+ self->user_data = NULL;
|
|
|
+ self->destroy = NULL;
|
|
|
+}
|
|
|
+
|
|
|
+GtkLayoutManager *
|
|
|
+m2_layout_manager_new (M2LayoutMeasureFunc measure, M2LayoutAllocateFunc allocate,
|
|
|
+ gpointer user_data, GDestroyNotify destroy)
|
|
|
+{
|
|
|
+ M2LayoutManager *self = g_object_new (m2_layout_manager_get_type (), NULL);
|
|
|
+
|
|
|
+ self->measure = measure;
|
|
|
+ self->allocate = allocate;
|
|
|
+ self->user_data = user_data;
|
|
|
+ self->destroy = destroy;
|
|
|
+ return GTK_LAYOUT_MANAGER (self);
|
|
|
+}
|
|
|
+
|
|
|
+/* Position a child at (x, y) with the given size (helper for allocate). */
|
|
|
+void
|
|
|
+m2_layout_allocate_child (GtkWidget *child, int x, int y, int width, int height)
|
|
|
+{
|
|
|
+ graphene_point_t point = GRAPHENE_POINT_INIT (x, y);
|
|
|
+ GskTransform *transform = gsk_transform_translate (NULL, &point);
|
|
|
+
|
|
|
+ gtk_widget_allocate (child, width, height, -1, transform);
|
|
|
+ gsk_transform_unref (transform);
|
|
|
+}
|