[libadwaita/wip/exalm/fixes: 5/5] Implement get_request_mode() where appropriate
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/fixes: 5/5] Implement get_request_mode() where appropriate
- Date: Mon, 9 Aug 2021 15:47:52 +0000 (UTC)
commit 7cfc783e563f4c1ed521cd5b046e6e6016e4eecf
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Aug 9 20:31:43 2021 +0500
Implement get_request_mode() where appropriate
When using a layout manager, get_request_mode() comes for free, but
otherwise it has to be implemented manually for every widget.
Coincidentally, we've had a copy of GtkLayoutManager's get_request_mode()
in AdwHeaderBar and AdwViewStack. Extract it into widget utils and use it
everywhere.
Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/70
src/adw-carousel.c | 1 +
src/adw-flap.c | 1 +
src/adw-header-bar.c | 34 ----------------------------------
src/adw-indicator-bin.c | 1 +
src/adw-leaflet.c | 1 +
src/adw-squeezer.c | 1 +
src/adw-view-stack.c | 35 +----------------------------------
src/adw-widget-utils-private.h | 2 ++
src/adw-widget-utils.c | 32 ++++++++++++++++++++++++++++++++
9 files changed, 40 insertions(+), 68 deletions(-)
---
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 2d2c708c..183bf22b 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -873,6 +873,7 @@ adw_carousel_class_init (AdwCarouselClass *klass)
widget_class->measure = adw_carousel_measure;
widget_class->size_allocate = adw_carousel_size_allocate;
widget_class->direction_changed = adw_carousel_direction_changed;
+ widget_class->get_request_mode = adw_widget_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand;
/**
diff --git a/src/adw-flap.c b/src/adw-flap.c
index 5a482087..b59f5d3c 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -1262,6 +1262,7 @@ adw_flap_class_init (AdwFlapClass *klass)
widget_class->size_allocate = adw_flap_size_allocate;
widget_class->snapshot = adw_flap_snapshot;
widget_class->direction_changed = adw_flap_direction_changed;
+ widget_class->get_request_mode = adw_widget_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand;
/**
diff --git a/src/adw-header-bar.c b/src/adw-header-bar.c
index c42a6d35..1d0dc6b0 100644
--- a/src/adw-header-bar.c
+++ b/src/adw-header-bar.c
@@ -354,39 +354,6 @@ adw_header_bar_set_property (GObject *object,
}
}
-static GtkSizeRequestMode
-adw_header_bar_get_request_mode (GtkWidget *widget)
-{
- GtkWidget *w;
- int wfh = 0, hfw = 0;
-
- for (w = gtk_widget_get_first_child (widget);
- w != NULL;
- w = gtk_widget_get_next_sibling (w)) {
- GtkSizeRequestMode mode = gtk_widget_get_request_mode (w);
-
- switch (mode) {
- case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
- hfw ++;
- break;
- case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
- wfh ++;
- 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
adw_header_bar_class_init (AdwHeaderBarClass *class)
{
@@ -400,7 +367,6 @@ adw_header_bar_class_init (AdwHeaderBarClass *class)
widget_class->root = adw_header_bar_root;
widget_class->unroot = adw_header_bar_unroot;
- widget_class->get_request_mode = adw_header_bar_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand_horizontal_only;
/**
diff --git a/src/adw-indicator-bin.c b/src/adw-indicator-bin.c
index f4993d7f..3e60d67e 100644
--- a/src/adw-indicator-bin.c
+++ b/src/adw-indicator-bin.c
@@ -281,6 +281,7 @@ adw_indicator_bin_class_init (AdwIndicatorBinClass *klass)
widget_class->size_allocate = adw_indicator_bin_size_allocate;
widget_class->snapshot = adw_indicator_bin_snapshot;
widget_class->unrealize = adw_indicator_bin_unrealize;
+ widget_class->get_request_mode = adw_widget_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand;
/**
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index 07c1d792..9b21a54d 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -2307,6 +2307,7 @@ adw_leaflet_class_init (AdwLeafletClass *klass)
widget_class->size_allocate = adw_leaflet_size_allocate;
widget_class->snapshot = adw_leaflet_snapshot;
widget_class->direction_changed = adw_leaflet_direction_changed;
+ widget_class->get_request_mode = adw_widget_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand;
g_object_class_override_property (object_class,
diff --git a/src/adw-squeezer.c b/src/adw-squeezer.c
index c0c245e6..7fade0be 100644
--- a/src/adw-squeezer.c
+++ b/src/adw-squeezer.c
@@ -1066,6 +1066,7 @@ adw_squeezer_class_init (AdwSqueezerClass *klass)
widget_class->size_allocate = adw_squeezer_size_allocate;
widget_class->snapshot = adw_squeezer_snapshot;
widget_class->measure = adw_squeezer_measure;
+ widget_class->get_request_mode = adw_widget_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand;
g_object_class_override_property (object_class,
diff --git a/src/adw-view-stack.c b/src/adw-view-stack.c
index ceff2165..9c651733 100644
--- a/src/adw-view-stack.c
+++ b/src/adw-view-stack.c
@@ -882,39 +882,6 @@ stack_remove (AdwViewStack *self,
gtk_widget_queue_resize (GTK_WIDGET (self));
}
-static GtkSizeRequestMode
-adw_view_stack_get_request_mode (GtkWidget *widget)
-{
- GtkWidget *child;
- int wfh = 0, hfw = 0;
-
- for (child = gtk_widget_get_first_child (widget);
- child;
- 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++;
- break;
- case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
- wfh++;
- 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
adw_view_stack_size_allocate (GtkWidget *widget,
int width,
@@ -1180,8 +1147,8 @@ adw_view_stack_class_init (AdwViewStackClass *klass)
widget_class->size_allocate = adw_view_stack_size_allocate;
widget_class->snapshot = adw_view_stack_snapshot;
widget_class->measure = adw_view_stack_measure;
+ widget_class->get_request_mode = adw_widget_get_request_mode;
widget_class->compute_expand = adw_widget_compute_expand;
- widget_class->get_request_mode = adw_view_stack_get_request_mode;
/**
* AdwViewStack:hhomogeneous: (attributes org.gtk.Property.get=adw_view_stack_get_hhomogeneous
org.gtk.Property.set=adw_view_stack_set_hhomogeneous)
diff --git a/src/adw-widget-utils-private.h b/src/adw-widget-utils-private.h
index d9db1103..3f6f027d 100644
--- a/src/adw-widget-utils-private.h
+++ b/src/adw-widget-utils-private.h
@@ -39,4 +39,6 @@ void adw_widget_compute_expand_horizontal_only (GtkWidget *widget,
gboolean *hexpand_p,
gboolean *vexpand_p);
+GtkSizeRequestMode adw_widget_get_request_mode (GtkWidget *widget);
+
G_END_DECLS
diff --git a/src/adw-widget-utils.c b/src/adw-widget-utils.c
index c234ceb6..9541fb89 100644
--- a/src/adw-widget-utils.c
+++ b/src/adw-widget-utils.c
@@ -511,3 +511,35 @@ adw_widget_compute_expand_horizontal_only (GtkWidget *widget,
*hexpand_p = hexpand;
*vexpand_p = FALSE;
}
+
+GtkSizeRequestMode
+adw_widget_get_request_mode (GtkWidget *widget)
+{
+ GtkWidget *child;
+ int wfh = 0, hfw = 0;
+
+ for (child = gtk_widget_get_first_child (widget);
+ child;
+ 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++;
+ break;
+ case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
+ wfh++;
+ 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;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]