summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-06-23 15:34:02 +0200
committerBastien Nocera <hadess@hadess.net>2014-06-24 11:35:30 +0200
commitb3a61bc6f545f460ac0cb374de9b7de18986a8e6 (patch)
tree0561d8146ded0df78eabafd93623310debe12f97
parentcbeba7c6bf1dffa0735a90952bc8779efcb3b975 (diff)
downloadgnome-control-center-b3a61bc6f545f460ac0cb374de9b7de18986a8e6.tar.gz
shell: Add GtkListBox helpers
Add helpers for GtkListBox sizing, and setting separators. https://bugzilla.gnome.org/show_bug.cgi?id=732106
-rw-r--r--shell/Makefile.am2
-rw-r--r--shell/list-box-helper.c72
-rw-r--r--shell/list-box-helper.h27
3 files changed, 101 insertions, 0 deletions
diff --git a/shell/Makefile.am b/shell/Makefile.am
index ad7a68faf..3b15cbb64 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -41,6 +41,8 @@ gnome_control_center_SOURCES = \
hostname-helper.h \
cc-hostname-entry.c \
cc-hostname-entry.h \
+ list-box-helper.h \
+ list-box-helper.c \
$(MARSHAL_FILES)
gnome_control_center_LDFLAGS = -export-dynamic
diff --git a/shell/list-box-helper.c b/shell/list-box-helper.c
new file mode 100644
index 000000000..ba3f44d6e
--- /dev/null
+++ b/shell/list-box-helper.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "list-box-helper.h"
+
+#define MAX_ROWS_VISIBLE 5
+
+void
+cc_list_box_update_header_func (GtkListBoxRow *row,
+ GtkListBoxRow *before,
+ gpointer user_data)
+{
+ GtkWidget *current;
+
+ if (before == NULL)
+ return;
+
+ current = gtk_list_box_row_get_header (row);
+ if (current == NULL)
+ {
+ current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_show (current);
+ gtk_list_box_row_set_header (row, current);
+ }
+}
+
+void
+cc_list_box_adjust_scrolling (GtkScrolledWindow *scrolled_window)
+{
+ GtkWidget *listbox;
+ GtkWidget *parent;
+ GList *children;
+ guint n_rows;
+
+ listbox = gtk_bin_get_child (GTK_BIN (scrolled_window));
+ parent = gtk_widget_get_parent (GTK_WIDGET (scrolled_window));
+ children = gtk_container_get_children (GTK_CONTAINER (listbox));
+ n_rows = g_list_length (children);
+ g_list_free (children);
+
+ if (n_rows >= MAX_ROWS_VISIBLE)
+ {
+ gint height;
+
+ gtk_widget_get_preferred_height (parent, NULL, &height);
+ gtk_widget_set_size_request (parent, -1, height);
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ }
+ else
+ {
+ gtk_widget_set_size_request (parent, -1, -1);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+ GTK_POLICY_NEVER, GTK_POLICY_NEVER);
+ }
+}
diff --git a/shell/list-box-helper.h b/shell/list-box-helper.h
new file mode 100644
index 000000000..327a85d81
--- /dev/null
+++ b/shell/list-box-helper.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <gtk/gtk.h>
+
+void
+cc_list_box_update_header_func (GtkListBoxRow *row,
+ GtkListBoxRow *before,
+ gpointer user_data);
+
+void
+cc_list_box_adjust_scrolling (GtkScrolledWindow *scrolled_window);