[gnome-control-center] region: Use new listbox helpers



commit ccec8ad7e1a15f51664442c961a423a7bc028f3c
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Jun 23 15:37:34 2014 +0200

    region: Use new listbox helpers
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732106

 panels/region/cc-format-chooser.c |   22 +-------------
 panels/region/cc-region-panel.c   |   54 ++++--------------------------------
 2 files changed, 8 insertions(+), 68 deletions(-)
---
diff --git a/panels/region/cc-format-chooser.c b/panels/region/cc-format-chooser.c
index 0133307..ea42dee 100644
--- a/panels/region/cc-format-chooser.c
+++ b/panels/region/cc-format-chooser.c
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
+#include "shell/list-box-helper.h"
 #include "cc-common-language.h"
 #include "cc-util.h"
 
@@ -459,25 +460,6 @@ row_activated (GtkListBox  *box,
 }
 
 static void
-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);
-    }
-}
-
-static void
 cc_format_chooser_private_free (gpointer data)
 {
         CcFormatChooserPrivate *priv = data;
@@ -537,7 +519,7 @@ cc_format_chooser_new (GtkWidget *parent)
         gtk_list_box_set_selection_mode (GTK_LIST_BOX (priv->list),
                                          GTK_SELECTION_NONE);
         gtk_list_box_set_header_func (GTK_LIST_BOX (priv->list),
-                                      update_header_func, NULL, NULL);
+                                      cc_list_box_update_header_func, NULL, NULL);
 
         add_all_regions (GTK_DIALOG (chooser));
 
diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c
index 16935df..b13d6ce 100644
--- a/panels/region/cc-region-panel.c
+++ b/panels/region/cc-region-panel.c
@@ -26,6 +26,7 @@
 #include <gtk/gtk.h>
 #include <polkit/polkit.h>
 
+#include "shell/list-box-helper.h"
 #include "cc-region-panel.h"
 #include "cc-region-resources.h"
 #include "cc-language-chooser.h"
@@ -58,8 +59,6 @@
 #define INPUT_SOURCE_TYPE_XKB "xkb"
 #define INPUT_SOURCE_TYPE_IBUS "ibus"
 
-#define MAX_INPUT_ROWS_VISIBLE 5
-
 #define DEFAULT_LOCALE "en_US.utf-8"
 
 CC_PANEL_REGISTER (CcRegionPanel, cc_region_panel)
@@ -257,25 +256,6 @@ show_restart_notification (CcRegionPanel *self,
         }
 }
 
-static void
-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);
-    }
-}
-
 typedef struct {
         CcRegionPanel *self;
         int category;
@@ -666,7 +646,7 @@ setup_language_section (CcRegionPanel *self)
         gtk_list_box_set_selection_mode (GTK_LIST_BOX (widget),
                                          GTK_SELECTION_NONE);
         gtk_list_box_set_header_func (GTK_LIST_BOX (widget),
-                                      update_header_func,
+                                      cc_list_box_update_header_func,
                                       NULL, NULL);
         g_signal_connect_swapped (widget, "row-activated",
                                   G_CALLBACK (activate_language_row), self);
@@ -808,28 +788,6 @@ setup_app_info_for_id (const gchar *id)
 #endif
 
 static void
-adjust_input_list_scrolling (CcRegionPanel *self)
-{
-        CcRegionPanelPrivate *priv = self->priv;
-
-        if (priv->n_input_rows >= MAX_INPUT_ROWS_VISIBLE) {
-                GtkWidget *parent;
-                gint height;
-
-                parent = gtk_widget_get_parent (priv->input_scrolledwindow);
-                gtk_widget_get_preferred_height (parent, NULL, &height);
-                gtk_widget_set_size_request (parent, -1, height);
-
-                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->input_scrolledwindow),
-                                                GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-        } else {
-                gtk_widget_set_size_request (gtk_widget_get_parent (priv->input_scrolledwindow), -1, -1);
-                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->input_scrolledwindow),
-                                                GTK_POLICY_NEVER, GTK_POLICY_NEVER);
-        }
-}
-
-static void
 remove_no_input_row (GtkContainer *list)
 {
         GList *l;
@@ -892,7 +850,7 @@ add_input_row (CcRegionPanel   *self,
         }
 
         priv->n_input_rows += 1;
-        adjust_input_list_scrolling (self);
+        cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (self->priv->input_scrolledwindow));
 
         return row;
 }
@@ -978,7 +936,7 @@ clear_input_sources (CcRegionPanel *self)
         g_list_free (list);
 
         priv->n_input_rows = 0;
-        adjust_input_list_scrolling (self);
+        cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (self->priv->input_scrolledwindow));
 }
 
 static void
@@ -1289,7 +1247,7 @@ do_remove_selected_input (CcRegionPanel *self)
         gtk_list_box_select_row (GTK_LIST_BOX (priv->input_list), GTK_LIST_BOX_ROW (sibling));
 
         priv->n_input_rows -= 1;
-        adjust_input_list_scrolling (self);
+        cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (self->priv->input_scrolledwindow));
 
         update_buttons (self);
         update_input (self);
@@ -1472,7 +1430,7 @@ setup_input_section (CcRegionPanel *self)
         gtk_list_box_set_selection_mode (GTK_LIST_BOX (priv->input_list),
                                          GTK_SELECTION_SINGLE);
         gtk_list_box_set_header_func (GTK_LIST_BOX (priv->input_list),
-                                      update_header_func,
+                                      cc_list_box_update_header_func,
                                       NULL, NULL);
         g_signal_connect_swapped (priv->input_list, "row-selected",
                                   G_CALLBACK (update_buttons), self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]