[gtk+/wip/combo: 4/11] First rough support for grouping
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/combo: 4/11] First rough support for grouping
- Date: Fri, 26 Dec 2014 05:20:46 +0000 (UTC)
commit 8737110df66e97b40cbd2d6f6b6539ab3afa5c50
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 25 20:56:19 2014 -0500
First rough support for grouping
gtk/gtkcombo.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
gtk/gtkcombo.h | 7 +++
2 files changed, 144 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcombo.c b/gtk/gtkcombo.c
index cdae5f2..cdd436c 100644
--- a/gtk/gtkcombo.c
+++ b/gtk/gtkcombo.c
@@ -27,6 +27,7 @@
#include "gtkbuilderprivate.h"
#include "gtkbutton.h"
#include "gtkentry.h"
+#include "gtkframe.h"
#include "gtklabel.h"
#include "gtklistbox.h"
#include "gtkimage.h"
@@ -794,6 +795,7 @@ reset_popover (GtkWidget *widget,
typedef struct
{
+ GtkCombo *combo;
const gchar *id;
GtkWidget *row;
} ForeachData;
@@ -815,7 +817,7 @@ find_row (GtkWidget *row,
}
static void
-add_to_list (GtkCombo *combo,
+add_to_list (GtkWidget *list,
const gchar *id,
const gchar *sort,
const gchar *text)
@@ -825,19 +827,19 @@ add_to_list (GtkCombo *combo,
data.id = id;
data.row = NULL;
- gtk_container_foreach (GTK_CONTAINER (combo->list), find_row, &data);
+ gtk_container_foreach (GTK_CONTAINER (list), find_row, &data);
if (data.row)
{
gtk_combo_row_set_sort (GTK_COMBO_ROW (data.row), sort);
gtk_combo_row_set_text (GTK_COMBO_ROW (data.row), text);
- gtk_list_box_invalidate_sort (GTK_LIST_BOX (combo->list));
- gtk_list_box_invalidate_filter (GTK_LIST_BOX (combo->list));
+ gtk_list_box_invalidate_sort (GTK_LIST_BOX (list));
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (list));
}
else
{
row = gtk_combo_row_new (id, sort, text);
- gtk_list_box_insert (GTK_LIST_BOX (combo->list), row, -1);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
}
}
@@ -865,8 +867,33 @@ update_check (GtkWidget *row,
gpointer data)
{
ForeachData *d = data;
+ const gchar *group;
const gchar *id;
+ group = (const gchar *)g_object_get_data (G_OBJECT (row), "group");
+ if (group && g_strcmp0 (group, "list") != 0)
+ {
+ GtkWidget *tab, *list, *check;
+ ForeachData data2;
+
+ data2.combo = d->combo;
+ data2.id = d->id;
+ data2.row = NULL;
+ tab = gtk_stack_get_child_by_name (GTK_STACK (d->combo->stack), group);
+ list = (GtkWidget *)g_object_get_data (G_OBJECT (tab), "list");
+ gtk_container_foreach (GTK_CONTAINER (list), update_check, &data2);
+ check = (GtkWidget *)g_object_get_data (G_OBJECT (row), "check");
+ if (data2.row)
+ {
+ gtk_widget_show (check);
+ d->row = data2.row;
+ }
+ else
+ {
+ gtk_widget_hide (check);
+ }
+ }
+
if (!GTK_IS_COMBO_ROW (row))
return;
@@ -890,6 +917,7 @@ set_active (GtkCombo *combo,
const gchar *text;
ForeachData data;
+ data.combo = combo;
data.id = id;
data.row = NULL;
gtk_container_foreach (GTK_CONTAINER (combo->list), update_check, &data);
@@ -916,6 +944,8 @@ list_row_activated (GtkListBox *list,
GtkListBoxRow *row,
GtkCombo *combo)
{
+ const gchar *group;
+
if ((GtkWidget*)row == combo->show_more)
{
expand_list (combo);
@@ -929,6 +959,13 @@ list_row_activated (GtkListBox *list,
return;
}
+ group = (const gchar *) g_object_get_data (G_OBJECT (row), "group");
+ if (group)
+ {
+ gtk_stack_set_visible_child_name (GTK_STACK (combo->stack), group);
+ return;
+ }
+
if (GTK_IS_COMBO_ROW (row))
set_active (combo, gtk_combo_row_get_id (GTK_COMBO_ROW (row)));
@@ -1029,6 +1066,7 @@ collapse_list (GtkCombo *combo)
}
else
{
+ gtk_widget_show (combo->search_revealer);
gtk_revealer_set_reveal_child (GTK_REVEALER (combo->search_revealer), TRUE);
gtk_widget_show (combo->show_more);
}
@@ -1239,7 +1277,7 @@ gtk_combo_add (GtkCombo *combo,
{
g_return_if_fail (GTK_IS_COMBO (combo));
- add_to_list (combo, id, sort, text);
+ add_to_list (combo->list, id, sort, text);
collapse_list (combo);
}
@@ -1358,3 +1396,96 @@ gtk_combo_get_allow_custom (GtkCombo *combo)
return combo->allow_custom;
}
+
+static GtkWidget *
+ensure_group (GtkCombo *combo,
+ const gchar *group)
+{
+ GtkWidget *tab;
+ GtkWidget *list;
+
+ tab = gtk_stack_get_child_by_name (GTK_STACK (combo->stack), group);
+ if (tab == NULL)
+ {
+ GtkWidget *frame;
+ GtkWidget *header;
+ GtkWidget *box;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *item;
+
+ tab = frame = gtk_frame_new (NULL);
+ gtk_widget_show (frame);
+ g_object_set (frame, "margin", 10, NULL);
+ list = gtk_list_box_new ();
+ gtk_widget_show (list);
+ gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
+ header = gtk_list_box_row_new ();
+ gtk_widget_show (header);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ g_object_set (box, "margin", 6, NULL);
+ gtk_widget_show (box);
+ image = gtk_image_new_from_icon_name ("pan-start-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_widget_set_halign (image, GTK_ALIGN_START);
+ gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
+ gtk_widget_show (image);
+ gtk_container_add (GTK_CONTAINER (box), image);
+ label = gtk_label_new (group);
+ gtk_widget_show (label);
+ gtk_box_set_center_widget (GTK_BOX (box), label);
+ gtk_container_add (GTK_CONTAINER (header), box);
+ gtk_list_box_insert (GTK_LIST_BOX (list), header, -1);
+ gtk_container_add (GTK_CONTAINER (frame), list);
+ gtk_stack_add_named (GTK_STACK (combo->stack), frame, group);
+
+ g_object_set_data (G_OBJECT (header), "group", (gpointer)"list");
+ g_object_set_data (G_OBJECT (tab), "list", list);
+
+ g_signal_connect (list, "row-activated", G_CALLBACK (list_row_activated), combo);
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (list), list_sort_func, combo, NULL);
+ gtk_list_box_set_header_func (GTK_LIST_BOX (list), list_header_func, combo, NULL);
+
+
+ item = gtk_list_box_row_new ();
+ gtk_widget_show (item);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ g_object_set (box, "margin", 6, NULL);
+ gtk_widget_show (box);
+ image = gtk_image_new_from_icon_name ("pan-end-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_widget_set_halign (image, GTK_ALIGN_END);
+ gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
+ gtk_widget_show (image);
+ gtk_box_pack_end (GTK_BOX (box), image, FALSE, FALSE, 0);
+ label = gtk_label_new (group);
+ gtk_widget_show (label);
+ gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+ image = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
+ gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
+
+ gtk_container_add (GTK_CONTAINER (item), box);
+ gtk_list_box_insert (GTK_LIST_BOX (combo->list), item, -1);
+ g_object_set_data (G_OBJECT (item), "group", (gpointer)group);
+ g_object_set_data (G_OBJECT (item), "check", image);
+ }
+
+ list = (GtkWidget*)g_object_get_data (G_OBJECT (tab), "list");
+
+ return list;
+}
+
+void
+gtk_combo_add_with_group (GtkCombo *combo,
+ const gchar *group,
+ const gchar *id,
+ const gchar *sort,
+ const gchar *text)
+{
+ GtkWidget *list;
+
+ g_return_if_fail (GTK_IS_COMBO (combo));
+
+ list = ensure_group (combo, group);
+ add_to_list (list, id, sort, text);
+}
diff --git a/gtk/gtkcombo.h b/gtk/gtkcombo.h
index 8ad95d5..3046734 100644
--- a/gtk/gtkcombo.h
+++ b/gtk/gtkcombo.h
@@ -72,6 +72,13 @@ GDK_AVAILABLE_IN_3_16
void gtk_combo_set_allow_custom (GtkCombo *combo,
gboolean allow);
+GDK_AVAILABLE_IN_3_16
+void gtk_combo_add_with_group (GtkCombo *combo,
+ const gchar *group,
+ const gchar *id,
+ const gchar *sort,
+ const gchar *text);
+
G_END_DECLS
#endif /* __GTK_COMBO_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]