From a27737b04e61af4ca0fc75fa027da84fdc5a71e5 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 12 Apr 2019 17:08:21 +0100 Subject: [PATCH] Add default GtkLayoutManagerClass.get_request_mode() Just like GtkContainer provides a default implementation of GtkWidgetClass.get_request_mode(), we can do the same inside GtkLayoutManager. A default implementation preserves the behavior of existing widgets that moved, or will move, to a GtkLayoutManager. --- gtk/gtkboxlayout.c | 37 ------------------------------------- gtk/gtkcustomlayout.c | 2 +- gtk/gtkfixedlayout.c | 8 ++++++++ gtk/gtklayoutmanager.c | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/gtk/gtkboxlayout.c b/gtk/gtkboxlayout.c index 259a4822c9..88215192a0 100644 --- a/gtk/gtkboxlayout.c +++ b/gtk/gtkboxlayout.c @@ -199,42 +199,6 @@ get_spacing (GtkBoxLayout *self, return css_spacing + self->spacing; } -static GtkSizeRequestMode -gtk_box_layout_get_request_mode (GtkLayoutManager *layout_manager, - GtkWidget *widget) -{ - GtkWidget *child; - int wfh = 0, hfw = 0; - - for (child = _gtk_widget_get_first_child (widget); - child != NULL; - child = _gtk_widget_get_next_sibling (child)) - { - GtkSizeRequestMode mode = gtk_widget_get_request_mode (child); - - switch (mode) - { - case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: - hfw += 1; - break; - - case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: - wfh += 1; - break; - - case GTK_SIZE_REQUEST_CONSTANT_SIZE: - default: - break; - } - } - - if (hfw == 0 && wfh == 0) - return GTK_SIZE_REQUEST_CONSTANT_SIZE; - else - return wfh > hfw ? GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT - : GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; -} - static void gtk_box_layout_compute_size (GtkBoxLayout *self, GtkWidget *widget, @@ -738,7 +702,6 @@ gtk_box_layout_class_init (GtkBoxLayoutClass *klass) gobject_class->set_property = gtk_box_layout_set_property; gobject_class->get_property = gtk_box_layout_get_property; - layout_manager_class->get_request_mode = gtk_box_layout_get_request_mode; layout_manager_class->measure = gtk_box_layout_measure; layout_manager_class->allocate = gtk_box_layout_allocate; diff --git a/gtk/gtkcustomlayout.c b/gtk/gtkcustomlayout.c index a1bfe95fff..2616a21df4 100644 --- a/gtk/gtkcustomlayout.c +++ b/gtk/gtkcustomlayout.c @@ -36,7 +36,7 @@ gtk_custom_layout_get_request_mode (GtkLayoutManager *manager, if (self->request_mode_func != NULL) return self->request_mode_func (widget); - return GTK_SIZE_REQUEST_CONSTANT_SIZE; + return GTK_LAYOUT_MANAGER_CLASS (gtk_custom_layout_parent_class)->get_request_mode (manager, widget); } static void diff --git a/gtk/gtkfixedlayout.c b/gtk/gtkfixedlayout.c index 94e4c687b2..cd37590100 100644 --- a/gtk/gtkfixedlayout.c +++ b/gtk/gtkfixedlayout.c @@ -208,6 +208,13 @@ gtk_fixed_layout_child_get_position (GtkFixedLayoutChild *child) G_DEFINE_TYPE (GtkFixedLayout, gtk_fixed_layout, GTK_TYPE_LAYOUT_MANAGER) +static GtkSizeRequestMode +gtk_fixed_layout_get_request_mode (GtkLayoutManager *layout_manager, + GtkWidget *widget) +{ + return GTK_SIZE_REQUEST_CONSTANT_SIZE; +} + static void gtk_fixed_layout_measure (GtkLayoutManager *layout_manager, GtkWidget *widget, @@ -316,6 +323,7 @@ gtk_fixed_layout_class_init (GtkFixedLayoutClass *klass) layout_class->layout_child_type = GTK_TYPE_FIXED_LAYOUT_CHILD; + layout_class->get_request_mode = gtk_fixed_layout_get_request_mode; layout_class->measure = gtk_fixed_layout_measure; layout_class->allocate = gtk_fixed_layout_allocate; layout_class->create_layout_child = gtk_fixed_layout_create_layout_child; diff --git a/gtk/gtklayoutmanager.c b/gtk/gtklayoutmanager.c index cd7d1406b1..c82d8f88d8 100644 --- a/gtk/gtklayoutmanager.c +++ b/gtk/gtklayoutmanager.c @@ -75,7 +75,7 @@ #include "gtklayoutmanagerprivate.h" #include "gtklayoutchild.h" -#include "gtkwidget.h" +#include "gtkwidgetprivate.h" #ifdef G_ENABLE_DEBUG #define LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED(m,method) G_STMT_START { \ @@ -101,7 +101,36 @@ static GtkSizeRequestMode gtk_layout_manager_real_get_request_mode (GtkLayoutManager *manager, GtkWidget *widget) { - return GTK_SIZE_REQUEST_CONSTANT_SIZE; + int hfw = 0, wfh = 0; + GtkWidget *child; + + for (child = _gtk_widget_get_first_child (widget); + child != NULL; + child = _gtk_widget_get_next_sibling (child)) + { + GtkSizeRequestMode res = gtk_widget_get_request_mode (child); + + switch (res) + { + case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: + hfw += 1; + break; + + case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: + wfh += 1; + break; + + case GTK_SIZE_REQUEST_CONSTANT_SIZE: + default: + break; + } + } + + if (hfw == 0 && wfh == 0) + return GTK_SIZE_REQUEST_CONSTANT_SIZE; + + return hfw > wfh ? GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH + : GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT; } static void