2
* Copyright (C) 2014 Red Hat, Inc
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, see <http://www.gnu.org/licenses/>.
19
#include "list-box-helper.h"
21
#define MAX_ROWS_VISIBLE 5
24
cc_list_box_update_header_func (GtkListBoxRow *row,
25
GtkListBoxRow *before,
32
gtk_list_box_row_set_header (row, NULL);
36
current = gtk_list_box_row_get_header (row);
39
current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
40
gtk_widget_show (current);
41
gtk_list_box_row_set_header (row, current);
46
cc_list_box_adjust_scrolling (GtkListBox *listbox)
48
GtkWidget *scrolled_window;
50
guint n_rows, num_max_rows;
52
scrolled_window = g_object_get_data (G_OBJECT (listbox), "cc-scrolling-scrolled-window");
56
children = gtk_container_get_children (GTK_CONTAINER (listbox));
57
n_rows = g_list_length (children);
59
num_max_rows = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (listbox), "cc-max-rows-visible"));
61
if (n_rows >= num_max_rows)
63
gint total_row_height = 0;
67
for (l = children, i = 0; l != NULL && i < num_max_rows; l = l->next, i++) {
69
gtk_widget_get_preferred_height (GTK_WIDGET (l->data), &row_height, NULL);
70
total_row_height += row_height;
73
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolled_window), total_row_height);
74
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
75
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
79
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scrolled_window), -1);
80
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
81
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
84
g_list_free (children);
88
cc_list_box_setup_scrolling (GtkListBox *listbox,
92
GtkWidget *scrolled_window;
94
parent = gtk_widget_get_parent (GTK_WIDGET (listbox));
95
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
96
gtk_widget_show (scrolled_window);
98
g_object_ref (listbox);
99
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (listbox));
100
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (listbox));
101
g_object_unref (listbox);
103
gtk_container_add (GTK_CONTAINER (parent), scrolled_window);
105
if (num_max_rows == 0)
106
num_max_rows = MAX_ROWS_VISIBLE;
108
g_object_set_data (G_OBJECT (listbox), "cc-scrolling-scrolled-window", scrolled_window);
109
g_object_set_data (G_OBJECT (listbox), "cc-max-rows-visible", GUINT_TO_POINTER (num_max_rows));