shell: Fix list box scrolling helper
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
This commit is contained in:
parent
ea62444388
commit
61a6c6f0cb
6 changed files with 47 additions and 49 deletions
|
@ -112,8 +112,6 @@ struct _CcRegionPanelPrivate {
|
|||
GtkWidget *remove_input;
|
||||
GtkWidget *show_config;
|
||||
GtkWidget *show_layout;
|
||||
GtkWidget *input_scrolledwindow;
|
||||
guint n_input_rows;
|
||||
|
||||
GSettings *input_settings;
|
||||
GnomeXkbInfo *xkb_info;
|
||||
|
@ -849,8 +847,7 @@ 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;
|
||||
cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (self->priv->input_scrolledwindow));
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (priv->input_list));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
@ -935,8 +932,7 @@ clear_input_sources (CcRegionPanel *self)
|
|||
}
|
||||
g_list_free (list);
|
||||
|
||||
priv->n_input_rows = 0;
|
||||
cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (self->priv->input_scrolledwindow));
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (priv->input_list));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1246,8 +1242,7 @@ do_remove_selected_input (CcRegionPanel *self)
|
|||
gtk_container_remove (GTK_CONTAINER (priv->input_list), GTK_WIDGET (selected));
|
||||
gtk_list_box_select_row (GTK_LIST_BOX (priv->input_list), GTK_LIST_BOX_ROW (sibling));
|
||||
|
||||
priv->n_input_rows -= 1;
|
||||
cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (self->priv->input_scrolledwindow));
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (priv->input_list));
|
||||
|
||||
update_buttons (self);
|
||||
update_input (self);
|
||||
|
@ -1414,7 +1409,6 @@ 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);
|
||||
|
@ -1427,6 +1421,8 @@ setup_input_section (CcRegionPanel *self)
|
|||
g_signal_connect_swapped (priv->show_layout, "clicked",
|
||||
G_CALLBACK (show_selected_layout), self);
|
||||
|
||||
cc_list_box_setup_scrolling (GTK_LIST_BOX (priv->input_list));
|
||||
|
||||
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),
|
||||
|
|
|
@ -181,21 +181,9 @@
|
|||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="input_scrolledwindow">
|
||||
<object class="GtkListBox" id="input_list">
|
||||
<property name="visible">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="GtkListBox" id="input_list">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -527,7 +527,7 @@ cc_sharing_panel_add_folder (GtkListBox *box,
|
|||
i = g_list_length (rows);
|
||||
gtk_list_box_insert (GTK_LIST_BOX (box), row, i - 1);
|
||||
}
|
||||
cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (WID ("shared-folders-scrolledwindow")));
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (box));
|
||||
|
||||
bail:
|
||||
g_free (folder);
|
||||
|
@ -543,7 +543,7 @@ cc_sharing_panel_remove_folder (GtkButton *button,
|
|||
|
||||
row = g_object_get_data (G_OBJECT (button), "row");
|
||||
gtk_widget_destroy (row);
|
||||
cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (WID ("shared-folders-scrolledwindow")));
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (WID ("shared-folders-listbox")));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -724,6 +724,7 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
|
|||
gtk_list_box_set_header_func (GTK_LIST_BOX (box),
|
||||
cc_list_box_update_header_func, NULL,
|
||||
NULL);
|
||||
cc_list_box_setup_scrolling (GTK_LIST_BOX (box));
|
||||
|
||||
list = folders;
|
||||
while (list && *list)
|
||||
|
@ -738,7 +739,7 @@ cc_sharing_panel_setup_media_sharing_dialog (CcSharingPanel *self)
|
|||
gtk_list_box_insert (GTK_LIST_BOX (box),
|
||||
cc_sharing_panel_new_add_media_sharing_row (self), -1);
|
||||
|
||||
cc_list_box_adjust_scrolling (GTK_SCROLLED_WINDOW (WID ("shared-folders-scrolledwindow")));
|
||||
cc_list_box_adjust_scrolling (GTK_LIST_BOX (box));
|
||||
|
||||
g_signal_connect (G_OBJECT (box), "row-activated",
|
||||
G_CALLBACK (cc_sharing_panel_add_folder), self);
|
||||
|
|
|
@ -911,7 +911,7 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Folders</property>
|
||||
<property name="mnemonic_widget">shared-folders-scrolledwindow</property>
|
||||
<property name="mnemonic_widget">shared-folders-listbox</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
|
@ -923,29 +923,15 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="shared-folders-box">
|
||||
<object class="GtkFrame" id="shared-folders-frame">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="shared-folders-scrolledwindow">
|
||||
<object class="GtkListBox" id="shared-folders-listbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<property name="vscrollbar-policy">never</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="shared-folders-listbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
|
@ -40,15 +40,18 @@ cc_list_box_update_header_func (GtkListBoxRow *row,
|
|||
}
|
||||
|
||||
void
|
||||
cc_list_box_adjust_scrolling (GtkScrolledWindow *scrolled_window)
|
||||
cc_list_box_adjust_scrolling (GtkListBox *listbox)
|
||||
{
|
||||
GtkWidget *listbox;
|
||||
GtkWidget *parent;
|
||||
GtkWidget *scrolled_window;
|
||||
GList *children;
|
||||
guint n_rows;
|
||||
|
||||
listbox = gtk_bin_get_child (GTK_BIN (scrolled_window));
|
||||
parent = gtk_widget_get_parent (GTK_WIDGET (scrolled_window));
|
||||
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);
|
||||
|
@ -70,3 +73,24 @@ cc_list_box_adjust_scrolling (GtkScrolledWindow *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);
|
||||
}
|
||||
|
|
|
@ -24,4 +24,7 @@ cc_list_box_update_header_func (GtkListBoxRow *row,
|
|||
gpointer user_data);
|
||||
|
||||
void
|
||||
cc_list_box_adjust_scrolling (GtkScrolledWindow *scrolled_window);
|
||||
cc_list_box_adjust_scrolling (GtkListBox *listbox);
|
||||
|
||||
void
|
||||
cc_list_box_setup_scrolling (GtkListBox *listbox);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue