GtkListBox doesn't implement GtkScrollable so it needs to be added to a GtkViewport. Instead of having to do this in all .ui files, add a new helper function to setup the widget tree correctly. https://bugzilla.gnome.org/show_bug.cgi?id=732175
96 lines
2.9 KiB
C
96 lines
2.9 KiB
C
/*
|
|
* 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 (GtkListBox *listbox)
|
|
{
|
|
GtkWidget *parent;
|
|
GtkWidget *scrolled_window;
|
|
GList *children;
|
|
guint n_rows;
|
|
|
|
parent = g_object_get_data (G_OBJECT (listbox), "cc-scrolling-parent");
|
|
scrolled_window = g_object_get_data (G_OBJECT (listbox), "cc-scrolling-scrolled-window");
|
|
if (!parent || !scrolled_window)
|
|
return;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
void
|
|
cc_list_box_setup_scrolling (GtkListBox *listbox)
|
|
{
|
|
GtkWidget *parent;
|
|
GtkWidget *scrolled_window;
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (listbox));
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
g_object_ref (listbox);
|
|
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (listbox));
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (listbox));
|
|
g_object_unref (listbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (parent), scrolled_window);
|
|
|
|
g_object_set_data (G_OBJECT (listbox), "cc-scrolling-parent", parent);
|
|
g_object_set_data (G_OBJECT (listbox), "cc-scrolling-scrolled-window", scrolled_window);
|
|
}
|