[gnome-control-center] region: Prevent window from getting too tall with many input sources



commit 4b09dd843ff73c868a74e16e1fe13fd35f3f293d
Author: Rui Matos <tiagomatos gmail com>
Date:   Fri Mar 8 23:57:33 2013 +0100

    region: Prevent window from getting too tall with many input sources
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695443

 panels/region/cc-region-panel.c |   37 +++++++++++++++++++++++++++++++++++++
 panels/region/region.ui         |   16 ++++++++++++++--
 2 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c
index 490b41a..77aaf18 100644
--- a/panels/region/cc-region-panel.c
+++ b/panels/region/cc-region-panel.c
@@ -59,6 +59,8 @@
 #define INPUT_SOURCE_TYPE_XKB "xkb"
 #define INPUT_SOURCE_TYPE_IBUS "ibus"
 
+#define MAX_INPUT_ROWS_VISIBLE 5
+
 CC_PANEL_REGISTER (CcRegionPanel, cc_region_panel)
 
 #define WID(s) GTK_WIDGET (gtk_builder_get_object (self->priv->builder, s))
@@ -106,6 +108,8 @@ struct _CcRegionPanelPrivate {
         GtkWidget *remove_input;
         GtkWidget *show_config;
         GtkWidget *show_layout;
+        GtkWidget *input_scrolledwindow;
+        guint n_input_rows;
 
         GSettings *input_settings;
         GnomeXkbInfo *xkb_info;
@@ -634,6 +638,28 @@ 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 GtkWidget *
 add_input_row (CcRegionPanel   *self,
                const gchar     *type,
@@ -641,6 +667,7 @@ add_input_row (CcRegionPanel   *self,
                const gchar     *name,
                GDesktopAppInfo *app_info)
 {
+        CcRegionPanelPrivate *priv = self->priv;
         GtkWidget *row;
         GtkWidget *label;
         GtkWidget *image;
@@ -674,6 +701,9 @@ add_input_row (CcRegionPanel   *self,
                 g_object_set_data_full (G_OBJECT (row), "app-info", g_object_ref (app_info), g_object_unref);
         }
 
+        priv->n_input_rows += 1;
+        adjust_input_list_scrolling (self);
+
         return row;
 }
 
@@ -745,6 +775,9 @@ clear_input_sources (CcRegionPanel *self)
                 gtk_container_remove (GTK_CONTAINER (priv->input_list), GTK_WIDGET (l->data));
         }
         g_list_free (list);
+
+        priv->n_input_rows = 0;
+        adjust_input_list_scrolling (self);
 }
 
 static void
@@ -1052,6 +1085,9 @@ do_remove_selected_input (CcRegionPanel *self)
         gtk_container_remove (GTK_CONTAINER (priv->input_list), selected);
         egg_list_box_select_child (EGG_LIST_BOX (priv->input_list), sibling);
 
+        priv->n_input_rows -= 1;
+        adjust_input_list_scrolling (self);
+
         update_buttons (self);
         update_input (self);
 }
@@ -1217,6 +1253,7 @@ setup_input_section (CcRegionPanel *self)
         priv->remove_input = WID ("input_source_remove");
         priv->show_config = WID ("input_source_config");
         priv->show_layout = WID ("input_source_layout");
+        priv->input_scrolledwindow = WID ("input_scrolledwindow");
 
         g_signal_connect_swapped (priv->options_button, "clicked",
                                   G_CALLBACK (show_input_options), self);
diff --git a/panels/region/region.ui b/panels/region/region.ui
index f594ab0..29120b6 100644
--- a/panels/region/region.ui
+++ b/panels/region/region.ui
@@ -175,9 +175,21 @@
                 <property name="label_xalign">0</property>
                 <property name="shadow_type">in</property>
                 <child>
-                  <object class="EggListBox" id="input_list">
+                  <object class="GtkScrolledWindow" id="input_scrolledwindow">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="hscrollbar-policy">never</property>
+                    <property name="vscrollbar-policy">never</property>
+                    <child>
+                      <object class="GtkViewport" id="input_viewport">
+                        <property name="visible">True</property>
+                        <child>
+                          <object class="EggListBox" id="input_list">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>


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