~ci-train-bot/unity-control-center/unity-control-center-ubuntu-disco-3448.1

« back to all changes in this revision

Viewing changes to shell/list-box-helper.c

  • Committer: Bileto Bot
  • Author(s): Khurshid Alam
  • Date: 2018-02-16 13:07:36 UTC
  • mfrom: (12909.2.5 unity-control-center)
  • Revision ID: ci-train-bot@canonical.com-20180216130736-a6ukmihhrrn9nf5k
Import gnome online-accounts panel into unity-control-center
Reference: https://bugzilla.gnome.org/show_bug.cgi?id=774222
Reference: https://github.com/linuxmint/cinnamon-control-center/pull/181 (LP: #1747897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Red Hat, Inc
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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/>.
 
16
 *
 
17
 */
 
18
 
 
19
#include "list-box-helper.h"
 
20
 
 
21
#define MAX_ROWS_VISIBLE 5
 
22
 
 
23
void
 
24
cc_list_box_update_header_func (GtkListBoxRow *row,
 
25
                                GtkListBoxRow *before,
 
26
                                gpointer user_data)
 
27
{
 
28
  GtkWidget *current;
 
29
 
 
30
  if (before == NULL)
 
31
    {
 
32
      gtk_list_box_row_set_header (row, NULL);
 
33
      return;
 
34
    }
 
35
 
 
36
  current = gtk_list_box_row_get_header (row);
 
37
  if (current == NULL)
 
38
    {
 
39
      current = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
 
40
      gtk_widget_show (current);
 
41
      gtk_list_box_row_set_header (row, current);
 
42
    }
 
43
}
 
44
 
 
45
void
 
46
cc_list_box_adjust_scrolling (GtkListBox *listbox)
 
47
{
 
48
  GtkWidget *scrolled_window;
 
49
  GList *children;
 
50
  guint n_rows, num_max_rows;
 
51
 
 
52
  scrolled_window = g_object_get_data (G_OBJECT (listbox), "cc-scrolling-scrolled-window");
 
53
  if (!scrolled_window)
 
54
    return;
 
55
 
 
56
  children = gtk_container_get_children (GTK_CONTAINER (listbox));
 
57
  n_rows = g_list_length (children);
 
58
 
 
59
  num_max_rows = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (listbox), "cc-max-rows-visible"));
 
60
 
 
61
  if (n_rows >= num_max_rows)
 
62
    {
 
63
      gint total_row_height = 0;
 
64
      GList *l;
 
65
      guint i;
 
66
 
 
67
      for (l = children, i = 0; l != NULL && i < num_max_rows; l = l->next, i++) {
 
68
        gint row_height;
 
69
        gtk_widget_get_preferred_height (GTK_WIDGET (l->data), &row_height, NULL);
 
70
        total_row_height += row_height;
 
71
      }
 
72
 
 
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);
 
76
    }
 
77
  else
 
78
    {
 
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);
 
82
    }
 
83
 
 
84
  g_list_free (children);
 
85
}
 
86
 
 
87
void
 
88
cc_list_box_setup_scrolling (GtkListBox *listbox,
 
89
                             guint       num_max_rows)
 
90
{
 
91
  GtkWidget *parent;
 
92
  GtkWidget *scrolled_window;
 
93
 
 
94
  parent = gtk_widget_get_parent (GTK_WIDGET (listbox));
 
95
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
 
96
  gtk_widget_show (scrolled_window);
 
97
 
 
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);
 
102
 
 
103
  gtk_container_add (GTK_CONTAINER (parent), scrolled_window);
 
104
 
 
105
  if (num_max_rows == 0)
 
106
    num_max_rows = MAX_ROWS_VISIBLE;
 
107
 
 
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));
 
110
}