[gtk+] shortcuts: Complete the container implementations
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] shortcuts: Complete the container implementations
- Date: Mon, 23 Nov 2015 03:42:20 +0000 (UTC)
commit a661ce4d067f70245ed56049e4ef1be306f8387b
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Nov 20 22:58:06 2015 -0500
shortcuts: Complete the container implementations
Various problems with the container implementations in
GtkShortcutsWindow, Section and Group were showing up
in glade.
gtk/gtkcontainer.c | 2 +
gtk/gtkshortcutsgroup.c | 33 ++++++++++++++
gtk/gtkshortcutssection.c | 103 +++++++++++++++++++++++++++++++++++++--------
gtk/gtkshortcutswindow.c | 36 +++++++++++++---
4 files changed, 149 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 48d1644..3122bd6 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -1896,6 +1896,8 @@ gtk_container_remove (GtkContainer *container,
GTK_IS_ASSISTANT (container) ||
GTK_IS_ACTION_BAR (container) ||
GTK_IS_POPOVER_MENU (container) ||
+ GTK_IS_SHORTCUTS_GROUP (container) ||
+ GTK_IS_SHORTCUTS_SECTION (container) ||
GTK_IS_SHORTCUTS_WINDOW (container));
g_object_ref (container);
diff --git a/gtk/gtkshortcutsgroup.c b/gtk/gtkshortcutsgroup.c
index a90b30f..2f6cc10 100644
--- a/gtk/gtkshortcutsgroup.c
+++ b/gtk/gtkshortcutsgroup.c
@@ -141,6 +141,38 @@ gtk_shortcuts_group_add (GtkContainer *container,
G_OBJECT_TYPE_NAME (container));
}
+typedef struct {
+ GtkCallback callback;
+ gpointer data;
+ gboolean include_internal;
+} CallbackData;
+
+static void
+forall_cb (GtkWidget *widget, gpointer data)
+{
+ GtkShortcutsGroup *self;
+ CallbackData *cbdata = data;
+
+ self = GTK_SHORTCUTS_GROUP (gtk_widget_get_parent (widget));
+ if (cbdata->include_internal || widget != (GtkWidget*)self->title)
+ cbdata->callback (widget, cbdata->data);
+}
+
+static void
+gtk_shortcuts_group_forall (GtkContainer *container,
+ gboolean include_internal,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ CallbackData cbdata;
+
+ cbdata.include_internal = include_internal;
+ cbdata.callback = callback;
+ cbdata.data = callback_data;
+
+ GTK_CONTAINER_CLASS (gtk_shortcuts_group_parent_class)->forall (container, include_internal, forall_cb,
&cbdata);
+}
+
static void
gtk_shortcuts_group_get_property (GObject *object,
guint prop_id,
@@ -231,6 +263,7 @@ gtk_shortcuts_group_class_init (GtkShortcutsGroupClass *klass)
widget_class->direction_changed = gtk_shortcuts_group_direction_changed;
container_class->add = gtk_shortcuts_group_add;
+ container_class->forall = gtk_shortcuts_group_forall;
/**
* GtkShortcutsGroup:title:
diff --git a/gtk/gtkshortcutssection.c b/gtk/gtkshortcutssection.c
index eb32ccb..3bdf096 100644
--- a/gtk/gtkshortcutssection.c
+++ b/gtk/gtkshortcutssection.c
@@ -33,6 +33,7 @@
#include "gtkprivate.h"
#include "gtkmarshalers.h"
#include "gtkgesturepan.h"
+#include "gtkwidgetprivate.h"
#include "gtkintl.h"
/**
@@ -64,6 +65,8 @@ struct _GtkShortcutsSection
GtkStack *stack;
GtkStackSwitcher *switcher;
GtkWidget *show_all;
+ GtkWidget *footer;
+ GList *groups;
gboolean has_filtered_group;
gboolean need_reflow;
@@ -120,6 +123,67 @@ static void gtk_shortcuts_section_pan_gesture_pan (GtkGesturePan *gesture,
GtkShortcutsSection *self);
static void
+gtk_shortcuts_section_add (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkShortcutsSection *self = GTK_SHORTCUTS_SECTION (container);
+
+ if (GTK_IS_SHORTCUTS_GROUP (child))
+ gtk_shortcuts_section_add_group (self, GTK_SHORTCUTS_GROUP (child));
+ else
+ g_warning ("Can't add children of type %s to %s",
+ G_OBJECT_TYPE_NAME (child),
+ G_OBJECT_TYPE_NAME (container));
+}
+
+static void
+gtk_shortcuts_section_remove (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkShortcutsSection *self = (GtkShortcutsSection *)container;
+
+ if (GTK_IS_SHORTCUTS_GROUP (child) &&
+ gtk_widget_is_ancestor (child, GTK_WIDGET (container)))
+ {
+ self->groups = g_list_remove (self->groups, child);
+ gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (child)), child);
+ }
+ else
+ GTK_CONTAINER_CLASS (gtk_shortcuts_section_parent_class)->remove (container, child);
+}
+
+static void
+gtk_shortcuts_section_forall (GtkContainer *container,
+ gboolean include_internal,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ GtkShortcutsSection *self = (GtkShortcutsSection *)container;
+ GList *l;
+
+ if (include_internal)
+ {
+ callback (GTK_WIDGET (self->stack), callback_data);
+ callback (GTK_WIDGET (self->footer), callback_data);
+ }
+
+ for (l = self->groups; l; l = l->next)
+ {
+ GtkWidget *group = l->data;
+ callback (group, callback_data);
+ }
+}
+
+static void
+map_child (GtkWidget *child)
+{
+ if (_gtk_widget_get_visible (child) &&
+ _gtk_widget_get_child_visible (child) &&
+ !_gtk_widget_get_mapped (child))
+ gtk_widget_map (child);
+}
+
+static void
gtk_shortcuts_section_map (GtkWidget *widget)
{
GtkShortcutsSection *self = GTK_SHORTCUTS_SECTION (widget);
@@ -127,21 +191,21 @@ gtk_shortcuts_section_map (GtkWidget *widget)
if (self->need_reflow)
gtk_shortcuts_section_reflow_groups (self);
- GTK_WIDGET_CLASS (gtk_shortcuts_section_parent_class)->map (widget);
+ gtk_widget_set_mapped (widget, TRUE);
+
+ map_child (GTK_WIDGET (self->stack));
+ map_child (GTK_WIDGET (self->footer));
}
static void
-gtk_shortcuts_section_add (GtkContainer *container,
- GtkWidget *child)
+gtk_shortcuts_section_unmap (GtkWidget *widget)
{
- GtkShortcutsSection *self = GTK_SHORTCUTS_SECTION (container);
+ GtkShortcutsSection *self = GTK_SHORTCUTS_SECTION (widget);
- if (GTK_IS_SHORTCUTS_GROUP (child))
- gtk_shortcuts_section_add_group (self, GTK_SHORTCUTS_GROUP (child));
- else
- g_warning ("Can't add children of type %s to %s",
- G_OBJECT_TYPE_NAME (child),
- G_OBJECT_TYPE_NAME (container));
+ gtk_widget_set_mapped (widget, FALSE);
+
+ gtk_widget_unmap (GTK_WIDGET (self->footer));
+ gtk_widget_unmap (GTK_WIDGET (self->stack));
}
static void
@@ -239,8 +303,11 @@ gtk_shortcuts_section_class_init (GtkShortcutsSectionClass *klass)
object_class->set_property = gtk_shortcuts_section_set_property;
widget_class->map = gtk_shortcuts_section_map;
+ widget_class->unmap = gtk_shortcuts_section_unmap;
container_class->add = gtk_shortcuts_section_add;
+ container_class->remove = gtk_shortcuts_section_remove;
+ container_class->forall = gtk_shortcuts_section_forall;
container_class->child_type = gtk_shortcuts_section_child_type;
klass->change_current_page = gtk_shortcuts_section_change_current_page;
@@ -331,8 +398,6 @@ gtk_shortcuts_section_class_init (GtkShortcutsSectionClass *klass)
static void
gtk_shortcuts_section_init (GtkShortcutsSection *self)
{
- GtkWidget *box;
-
self->max_height = 15;
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
@@ -362,11 +427,11 @@ gtk_shortcuts_section_init (GtkShortcutsSection *self)
g_signal_connect_swapped (self->show_all, "clicked",
G_CALLBACK (gtk_shortcuts_section_show_all), self);
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
- GTK_CONTAINER_CLASS (gtk_shortcuts_section_parent_class)->add (GTK_CONTAINER (self), box);
+ self->footer = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
+ GTK_CONTAINER_CLASS (gtk_shortcuts_section_parent_class)->add (GTK_CONTAINER (self), self->footer);
- gtk_box_set_center_widget (GTK_BOX (box), GTK_WIDGET (self->switcher));
- gtk_box_pack_end (GTK_BOX (box), self->show_all, TRUE, TRUE, 0);
+ gtk_box_set_center_widget (GTK_BOX (self->footer), GTK_WIDGET (self->switcher));
+ gtk_box_pack_end (GTK_BOX (self->footer), self->show_all, TRUE, TRUE, 0);
gtk_widget_set_halign (self->show_all, GTK_ALIGN_END);
self->pan_gesture = gtk_gesture_pan_new (GTK_WIDGET (self->stack), GTK_ORIENTATION_HORIZONTAL);
@@ -413,16 +478,17 @@ gtk_shortcuts_section_add_group (GtkShortcutsSection *self,
children = gtk_container_get_children (GTK_CONTAINER (self->stack));
if (children)
- page = children->data;
+ page = g_list_last (children)->data;
else
{
page = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 22);
gtk_stack_add_named (self->stack, page, "1");
}
g_list_free (children);
+
children = gtk_container_get_children (GTK_CONTAINER (page));
if (children)
- column = children->data;
+ column = g_list_last (children)->data;
else
{
column = gtk_box_new (GTK_ORIENTATION_VERTICAL, 22);
@@ -431,6 +497,7 @@ gtk_shortcuts_section_add_group (GtkShortcutsSection *self,
g_list_free (children);
gtk_container_add (GTK_CONTAINER (column), GTK_WIDGET (group));
+ self->groups = g_list_append (self->groups, group);
gtk_shortcuts_section_maybe_reflow (self);
}
diff --git a/gtk/gtkshortcutswindow.c b/gtk/gtkshortcutswindow.c
index 606dbf2..2d3e5c3 100644
--- a/gtk/gtkshortcutswindow.c
+++ b/gtk/gtkshortcutswindow.c
@@ -386,8 +386,12 @@ gtk_shortcuts_window_forall (GtkContainer *container,
if (include_internal)
{
- callback (GTK_WIDGET (priv->header_bar), callback_data);
- callback (GTK_WIDGET (priv->main_box), callback_data);
+ if (priv->header_bar)
+ callback (GTK_WIDGET (priv->header_bar), callback_data);
+ if (priv->main_box)
+ callback (GTK_WIDGET (priv->main_box), callback_data);
+ if (priv->popover)
+ callback (GTK_WIDGET (priv->popover), callback_data);
}
if (priv->stack)
@@ -437,12 +441,13 @@ gtk_shortcuts_window_set_section_name (GtkShortcutsWindow *self,
const gchar *section_name)
{
GtkShortcutsWindowPrivate *priv = gtk_shortcuts_window_get_instance_private (self);
- GtkWidget *section;
+ GtkWidget *section = NULL;
g_free (priv->initial_section);
priv->initial_section = g_strdup (section_name);
- section = gtk_stack_get_child_by_name (priv->stack, section_name);
+ if (!section_name)
+ section = gtk_stack_get_child_by_name (priv->stack, section_name);
if (section)
gtk_stack_set_visible_child (priv->stack, section);
}
@@ -595,6 +600,21 @@ gtk_shortcuts_window_finalize (GObject *object)
}
static void
+gtk_shortcuts_window_dispose (GObject *object)
+{
+ GtkShortcutsWindow *self = (GtkShortcutsWindow *)object;
+ GtkShortcutsWindowPrivate *priv = gtk_shortcuts_window_get_instance_private (self);
+
+ g_signal_handlers_disconnect_by_func (priv->stack, G_CALLBACK (update_title_stack), self);
+
+ priv->header_bar = NULL;
+ priv->popover = NULL;
+ priv->main_box = NULL;
+
+ G_OBJECT_CLASS (gtk_shortcuts_window_parent_class)->dispose (object);
+}
+
+static void
gtk_shortcuts_window_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -682,6 +702,7 @@ gtk_shortcuts_window_class_init (GtkShortcutsWindowClass *klass)
object_class->finalize = gtk_shortcuts_window_finalize;
object_class->get_property = gtk_shortcuts_window_get_property;
object_class->set_property = gtk_shortcuts_window_set_property;
+ object_class->dispose = gtk_shortcuts_window_dispose;
widget_class->unmap = gtk_shortcuts_window_unmap;
container_class->add = gtk_shortcuts_window_add;
@@ -917,9 +938,6 @@ gtk_shortcuts_window_init (GtkShortcutsWindow *self)
self,
G_CONNECT_SWAPPED);
- g_signal_connect_object (priv->stack, "notify::visible-child",
- G_CALLBACK (update_title_stack), self, G_CONNECT_SWAPPED);
-
scroller = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
"visible", TRUE,
NULL);
@@ -983,4 +1001,8 @@ gtk_shortcuts_window_init (GtkShortcutsWindow *self)
gtk_grid_attach (GTK_GRID (empty), label, 0, 2, 1, 1);
gtk_stack_add_named (priv->stack, empty, "no-search-results");
+
+ g_signal_connect_object (priv->stack, "notify::visible-child",
+ G_CALLBACK (update_title_stack), self, G_CONNECT_SWAPPED);
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]