[gtk/kill-containers: 34/49] headerbar: Derive from GtkWidget
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/kill-containers: 34/49] headerbar: Derive from GtkWidget
- Date: Tue, 12 May 2020 01:59:49 +0000 (UTC)
commit 9ac5251fe6257887f530b12bd9bc074f1ecf283b
Author: Matthias Clasen <mclasen redhat com>
Date: Fri May 8 09:37:52 2020 -0400
headerbar: Derive from GtkWidget
gtk/gtkheaderbar.c | 84 +++++++++++++++++++-----------------------------------
gtk/gtkheaderbar.h | 2 +-
2 files changed, 31 insertions(+), 55 deletions(-)
---
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 208415c701..40d4e1ae2f 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -36,8 +36,6 @@
#include "gtkwindowcontrols.h"
#include "gtkwindowhandle.h"
-#include "a11y/gtkcontaineraccessible.h"
-
#include <string.h>
/**
@@ -115,12 +113,12 @@ typedef struct _GtkHeaderBarClass GtkHeaderBarClass;
struct _GtkHeaderBar
{
- GtkContainer container;
+ GtkWidget container;
};
struct _GtkHeaderBarClass
{
- GtkContainerClass parent_class;
+ GtkWidgetClass parent_class;
};
struct _GtkHeaderBarPrivate
@@ -155,7 +153,7 @@ static GParamSpec *header_bar_props[LAST_PROP] = { NULL, };
static void gtk_header_bar_buildable_init (GtkBuildableIface *iface);
-G_DEFINE_TYPE_WITH_CODE (GtkHeaderBar, gtk_header_bar, GTK_TYPE_CONTAINER,
+G_DEFINE_TYPE_WITH_CODE (GtkHeaderBar, gtk_header_bar, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkHeaderBar)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_header_bar_buildable_init));
@@ -488,13 +486,6 @@ gtk_header_bar_pack (GtkHeaderBar *bar,
update_default_decoration (bar);
}
-static void
-gtk_header_bar_add (GtkContainer *container,
- GtkWidget *child)
-{
- gtk_header_bar_pack (GTK_HEADER_BAR (container), child, GTK_PACK_START);
-}
-
/**
* gtk_header_bar_remove:
* @bar: a #GtkHeaderBar
@@ -534,51 +525,38 @@ gtk_header_bar_remove (GtkHeaderBar *bar,
update_default_decoration (bar);
}
-static void
-gtk_header_bar_forall (GtkContainer *container,
- GtkCallback callback,
- gpointer callback_data)
+static GtkSizeRequestMode
+gtk_header_bar_get_request_mode (GtkWidget *widget)
{
- GtkHeaderBar *bar = GTK_HEADER_BAR (container);
- GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
GtkWidget *w;
+ int wfh = 0, hfw = 0;
- if (priv->start_box)
+ for (w = gtk_widget_get_first_child (widget);
+ w != NULL;
+ w = gtk_widget_get_next_sibling (w))
{
- w = _gtk_widget_get_first_child (priv->start_box);
- while (w != NULL)
- {
- GtkWidget *next = _gtk_widget_get_next_sibling (w);
-
- if (w != priv->start_window_controls)
- (* callback) (w, callback_data);
-
- w = next;
- }
- }
-
- if (priv->title_widget != NULL)
- (* callback) (priv->title_widget, callback_data);
+ GtkSizeRequestMode mode = gtk_widget_get_request_mode (w);
- if (priv->end_box)
- {
- w = _gtk_widget_get_first_child (priv->end_box);
- while (w != NULL)
+ switch (mode)
{
- GtkWidget *next = _gtk_widget_get_next_sibling (w);
-
- if (w != priv->end_window_controls)
- (* callback) (w, callback_data);
-
- w = next;
+ 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;
}
}
-}
-static GType
-gtk_header_bar_child_type (GtkContainer *container)
-{
- return GTK_TYPE_WIDGET;
+ 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
@@ -586,7 +564,6 @@ gtk_header_bar_class_init (GtkHeaderBarClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
object_class->dispose = gtk_header_bar_dispose;
object_class->finalize = gtk_header_bar_finalize;
@@ -595,11 +572,8 @@ gtk_header_bar_class_init (GtkHeaderBarClass *class)
widget_class->root = gtk_header_bar_root;
widget_class->unroot = gtk_header_bar_unroot;
-
- container_class->add = gtk_header_bar_add;
- container_class->remove = gtk_header_bar_remove;
- container_class->forall = gtk_header_bar_forall;
- container_class->child_type = gtk_header_bar_child_type;
+ widget_class->focus = gtk_widget_focus_child;
+ widget_class->get_request_mode = gtk_header_bar_get_request_mode;
header_bar_props[PROP_TITLE_WIDGET] =
g_param_spec_object ("title-widget",
@@ -689,6 +663,8 @@ gtk_header_bar_buildable_add_child (GtkBuildable *buildable,
gtk_header_bar_pack_start (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
else if (g_strcmp0 (type, "end") == 0)
gtk_header_bar_pack_end (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
+ else if (GTK_IS_WIDGET (child))
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
else
parent_buildable_iface->add_child (buildable, builder, child, type);
}
diff --git a/gtk/gtkheaderbar.h b/gtk/gtkheaderbar.h
index 0bbd591759..d993b6304c 100644
--- a/gtk/gtkheaderbar.h
+++ b/gtk/gtkheaderbar.h
@@ -24,7 +24,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
-#include <gtk/gtkcontainer.h>
+#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]