Commit 8d79a32c authored by Matthias Clasen's avatar Matthias Clasen
Browse files

list widgets: Use selection models in the api

Change the apis in GtkListView, GtkColumnView and
GtkGridView to be explicitly about GtkSelectionModel,
to make it obvious that the widgets handle selection.

Update all users.
parent d2d8b748
Pipeline #209481 passed with stages
in 21 minutes and 33 seconds
......@@ -164,7 +164,7 @@ populate_grid (void)
list = create_color_grid ();
selection = gtk_no_selection_new (gtk_color_list_new (2097152));
gtk_grid_view_set_model (GTK_GRID_VIEW (list), G_LIST_MODEL (selection));
gtk_grid_view_set_model (GTK_GRID_VIEW (list), GTK_SELECTION_MODEL (selection));
g_object_unref (selection);
hincrement = 0;
......
......@@ -104,7 +104,7 @@ activate_cb (GtkListView *list,
GdkAppLaunchContext *context;
GError *error = NULL;
app_info = g_list_model_get_item (gtk_list_view_get_model (list), position);
app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
/* Prepare the context for launching the application and launch it. This
* code is explained in detail in the documentation for #GdkAppLaunchContext
......@@ -176,7 +176,7 @@ do_listview_applauncher (GtkWidget *do_widget)
/* Create the list widget here.
*/
list = gtk_list_view_new_with_factory (model, factory);
list = gtk_list_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
/* We connect the activate signal here. It's the function we defined
* above for launching the selected application.
......
......@@ -462,7 +462,7 @@ do_listview_clocks (GtkWidget *do_widget)
{
GtkWidget *gridview, *sw;
GtkListItemFactory *factory;
GListModel *model;
GtkSelectionModel *model;
/* This is the normal window setup code every demo does */
window = gtk_window_new ();
......@@ -484,7 +484,7 @@ do_listview_clocks (GtkWidget *do_widget)
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
model = G_LIST_MODEL (gtk_no_selection_new (create_clocks_model ()));
model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_clocks_model ()));
gridview = gtk_grid_view_new_with_factory (model, factory);
gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
......
......@@ -866,7 +866,7 @@ do_listview_colors (GtkWidget *do_widget)
guint len;
GtkWidget *selection_view;
GListModel *selection_filter;
GListModel *no_selection;
GtkSelectionModel *no_selection;
GtkWidget *grid;
GtkWidget *selection_size_label;
GtkWidget *selection_average_picture;
......@@ -959,7 +959,7 @@ do_listview_colors (GtkWidget *do_widget)
gtk_box_append (GTK_BOX (box), sw);
gridview = create_color_grid ();
gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection));
gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), GTK_SELECTION_MODEL (selection));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
gtk_widget_set_hexpand (sw, TRUE);
gtk_widget_set_vexpand (sw, TRUE);
......@@ -968,7 +968,7 @@ do_listview_colors (GtkWidget *do_widget)
g_signal_connect (selection_filter, "items-changed", G_CALLBACK (update_selection_count), selection_size_label);
g_signal_connect (selection_filter, "items-changed", G_CALLBACK (update_selection_average), selection_average_picture);
no_selection = G_LIST_MODEL (gtk_no_selection_new (selection_filter));
no_selection = GTK_SELECTION_MODEL (gtk_no_selection_new (selection_filter));
gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection);
g_object_unref (no_selection);
......
......@@ -225,7 +225,7 @@ filebrowser_view_activated_cb (GtkGridView *view,
{
GFileInfo *info;
info = g_list_model_get_item (gtk_grid_view_get_model (view), pos);
info = g_list_model_get_item (G_LIST_MODEL (gtk_grid_view_get_model (view)), pos);
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
gtk_directory_list_set_file (list, G_FILE (g_file_info_get_attribute_object (info, "standard::file")));
......
......@@ -165,8 +165,12 @@
</object>
</child>
</object>
<object class="GtkDirectoryList" id="dirlist">
<property name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property>
<object class="GtkSingleSelection" id="selection_model">
<property name="model">
<object class="GtkDirectoryList" id="dirlist">
<property name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property>
</object>
</property>
</object>
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">File browser</property>
......@@ -227,7 +231,7 @@
<property name="can-focus">1</property>
<child>
<object class="GtkGridView" id="view">
<property name="model">dirlist</property>
<property name="model">selection_model</property>
<property name="max-columns">15</property>
<binding name="factory">
<lookup name="factory" type="FileBrowserView">
......
......@@ -413,7 +413,7 @@ do_listview_settings (GtkWidget *do_widget)
transform_settings_to_keys,
NULL,
columnview, NULL);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), GTK_SELECTION_MODEL (selection));
g_object_unref (selection);
name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column"));
......
......@@ -281,13 +281,13 @@ GtkWidget *
create_weather_view (void)
{
GtkWidget *listview;
GListModel *model;
GtkSelectionModel *model;
GtkListItemFactory *factory;
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_widget), NULL);
model = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ()));
model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_weather_model ()));
listview = gtk_list_view_new_with_factory (model, factory);
gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
......
......@@ -218,7 +218,7 @@ do_listview_words (GtkWidget *do_widget)
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
listview = gtk_list_view_new_with_factory (
G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))),
GTK_SELECTION_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))),
gtk_builder_list_item_factory_new_from_bytes (NULL,
g_bytes_new_static (factory_text, strlen (factory_text))));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
......
......@@ -640,7 +640,8 @@ activate_cb (GtkWidget *widget,
guint position,
gpointer window)
{
GtkTreeListRow *row = g_list_model_get_item (gtk_list_view_get_model (GTK_LIST_VIEW (widget)), position);
GListModel *model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (widget)));
GtkTreeListRow *row = g_list_model_get_item (model, position);
GtkDemo *demo = gtk_tree_list_row_get_item (row);
gtk_demo_run (demo, window);
......@@ -872,9 +873,10 @@ activate (GApplication *app)
selection = gtk_single_selection_new (G_LIST_MODEL (filter_model));
g_signal_connect (selection, "notify::selected-item", G_CALLBACK (selection_cb), NULL);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), GTK_SELECTION_MODEL (selection));
selection_cb (selection, NULL, NULL);
g_object_unref (selection);
g_object_unref (builder);
}
......
......@@ -172,7 +172,7 @@ item_activated (GtkGridView *view,
guint position,
IconBrowserWindow *win)
{
GListModel *model = gtk_grid_view_get_model (view);
GListModel *model = G_LIST_MODEL (gtk_grid_view_get_model (view));
IbIcon *icon = g_list_model_get_item (model, position);
const char *name;
const char *description;
......
......@@ -632,7 +632,7 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
g_param_spec_object ("model",
P_("Model"),
P_("Model for the items displayed"),
G_TYPE_LIST_MODEL,
GTK_TYPE_SELECTION_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
......@@ -1193,11 +1193,11 @@ gtk_column_view_init (GtkColumnView *self)
* Returns: a new #GtkColumnView
**/
GtkWidget *
gtk_column_view_new (GListModel *model)
gtk_column_view_new (GtkSelectionModel *model)
{
GtkWidget *result;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_COLUMN_VIEW,
"model", model,
......@@ -1217,7 +1217,7 @@ gtk_column_view_new (GListModel *model)
*
* Returns: (nullable) (transfer none): The model in use
**/
GListModel *
GtkSelectionModel *
gtk_column_view_get_model (GtkColumnView *self)
{
g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), NULL);
......@@ -1230,17 +1230,14 @@ gtk_column_view_get_model (GtkColumnView *self)
* @self: a #GtkColumnView
* @model: (allow-none) (transfer none): the model to use or %NULL for none
*
* Sets the #GListModel to use.
*
* If the @model is a #GtkSelectionModel, it is used for managing the selection.
* Otherwise, @self creates a #GtkSingleSelection for the selection.
* Sets the #GtkSelectionModel to use.
**/
void
gtk_column_view_set_model (GtkColumnView *self,
GListModel *model)
gtk_column_view_set_model (GtkColumnView *self,
GtkSelectionModel *model)
{
g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
if (gtk_list_view_get_model (self->listview) == model)
return;
......
......@@ -26,6 +26,7 @@
#include <gtk/gtktypes.h>
#include <gtk/gtksortlistmodel.h>
#include <gtk/gtkselectionmodel.h>
#include <gtk/gtksorter.h>
G_BEGIN_DECLS
......@@ -51,7 +52,7 @@ GDK_AVAILABLE_IN_ALL
GType gtk_column_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_column_view_new (GListModel *model);
GtkWidget * gtk_column_view_new (GtkSelectionModel *model);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_column_view_get_columns (GtkColumnView *self);
......@@ -67,10 +68,11 @@ void gtk_column_view_insert_column (GtkColumnView
GtkColumnViewColumn *column);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_column_view_get_model (GtkColumnView *self);
GtkSelectionModel *
gtk_column_view_get_model (GtkColumnView *self);
GDK_AVAILABLE_IN_ALL
void gtk_column_view_set_model (GtkColumnView *self,
GListModel *model);
GtkSelectionModel *model);
GDK_AVAILABLE_IN_ALL
gboolean gtk_column_view_get_show_row_separators (GtkColumnView *self);
......
......@@ -513,7 +513,7 @@ update_custom_widgets_from_list (GtkCustomPaperUnixDialog *dialog)
GListModel *model;
GtkPageSetup *page_setup;
model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview));
model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)));
page_setup = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model));
dialog->non_user_change = TRUE;
......@@ -563,7 +563,7 @@ unit_widget_changed (GtkCustomPaperUnixDialog *dialog)
if (dialog->non_user_change)
return;
model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview));
model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)));
page_setup = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (model));
if (page_setup != NULL)
......@@ -648,7 +648,7 @@ remove_custom_paper (GtkCustomPaperUnixDialog *dialog)
GListModel *model;
guint selected;
model = gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview));
model = G_LIST_MODEL (gtk_list_view_get_model (GTK_LIST_VIEW (dialog->listview)));
selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (model));
if (selected != GTK_INVALID_LIST_POSITION)
g_list_store_remove (dialog->custom_paper_list, selected);
......@@ -867,7 +867,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
GtkWidget *grid, *label, *widget, *frame, *combo;
GtkWidget *hbox, *vbox, *listview, *scrolled, *toolbar, *button;
GtkUnit user_units;
GListModel *model;
GtkSelectionModel *model;
GtkListItemFactory *factory;
content_area = gtk_dialog_get_content_area (cpu_dialog);
......@@ -893,7 +893,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
gtk_box_append (GTK_BOX (vbox), scrolled);
gtk_widget_show (scrolled);
model = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list))));
model = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list))));
g_signal_connect (model, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog);
factory = gtk_signal_list_item_factory_new ();
......
......@@ -81,9 +81,9 @@ struct _GtkDropDown
GtkListItemFactory *factory;
GtkListItemFactory *list_factory;
GListModel *model;
GListModel *selection;
GtkSelectionModel *selection;
GListModel *filter_model;
GListModel *popup_selection;
GtkSelectionModel *popup_selection;
GtkWidget *popup;
GtkWidget *button;
......@@ -690,19 +690,19 @@ gtk_drop_down_set_model (GtkDropDown *self,
else
{
GListModel *filter_model;
GListModel *selection;
GtkSelectionModel *selection;
filter_model = G_LIST_MODEL (gtk_filter_list_model_new (g_object_ref (model), NULL));
g_set_object (&self->filter_model, filter_model);
update_filter (self);
selection = G_LIST_MODEL (gtk_single_selection_new (filter_model));
selection = GTK_SELECTION_MODEL (gtk_single_selection_new (filter_model));
g_set_object (&self->popup_selection, selection);
gtk_list_view_set_model (GTK_LIST_VIEW (self->popup_list), selection);
g_object_unref (selection);
selection = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (model)));
selection = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (model)));
g_set_object (&self->selection, selection);
g_object_unref (selection);
......
......@@ -46,7 +46,7 @@
* SECTION:gtkgridview
* @title: GtkGridView
* @short_description: A widget for displaying grids
* @see_also: #GListModel, #GtkListView, #GtkColumnView
* @see_also: #GtkSelectionModel, #GtkListView, #GtkColumnView
*
* GtkGridView is a widget to present a view into a large dynamic grid of items.
*
......@@ -1092,7 +1092,7 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
g_param_spec_object ("model",
P_("Model"),
P_("Model for the items displayed"),
G_TYPE_LIST_MODEL,
GTK_TYPE_SELECTION_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
......@@ -1188,11 +1188,11 @@ gtk_grid_view_init (GtkGridView *self)
* Returns: a new #GtkGridView
**/
GtkWidget *
gtk_grid_view_new (GListModel *model)
gtk_grid_view_new (GtkSelectionModel *model)
{
GtkWidget *result;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_GRID_VIEW,
"model", model,
......@@ -1222,11 +1222,12 @@ gtk_grid_view_new (GListModel *model)
* Returns: a new #GtkGridView using the given @factory
**/
GtkWidget *
gtk_grid_view_new_with_factory (GListModel *model,
gtk_grid_view_new_with_factory (GtkSelectionModel *model,
GtkListItemFactory *factory)
{
GtkWidget *result;
g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
result = g_object_new (GTK_TYPE_GRID_VIEW,
......@@ -1249,7 +1250,7 @@ gtk_grid_view_new_with_factory (GListModel *model,
*
* Returns: (nullable) (transfer none): The model in use
**/
GListModel *
GtkSelectionModel *
gtk_grid_view_get_model (GtkGridView *self)
{
g_return_val_if_fail (GTK_IS_GRID_VIEW (self), NULL);
......@@ -1262,14 +1263,14 @@ gtk_grid_view_get_model (GtkGridView *self)
* @self: a #GtkGridView
* @model: (allow-none) (transfer none): the model to use or %NULL for none
*
* Sets the #GListModel to use for
* Sets the #GtkSelectionModel to use for
**/
void
gtk_grid_view_set_model (GtkGridView *self,
GListModel *model)
gtk_grid_view_set_model (GtkGridView *self,
GtkSelectionModel *model)
{
g_return_if_fail (GTK_IS_GRID_VIEW (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
if (!gtk_list_base_set_model (GTK_LIST_BASE (self), model))
return;
......
......@@ -48,16 +48,17 @@ GDK_AVAILABLE_IN_ALL
GType gtk_grid_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_grid_view_new (GListModel *model);
GtkWidget * gtk_grid_view_new (GtkSelectionModel *model);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_grid_view_new_with_factory (GListModel *model,
GtkWidget * gtk_grid_view_new_with_factory (GtkSelectionModel *model,
GtkListItemFactory *factory);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_grid_view_get_model (GtkGridView *self);
GtkSelectionModel *
gtk_grid_view_get_model (GtkGridView *self);
GDK_AVAILABLE_IN_ALL
void gtk_grid_view_set_model (GtkGridView *self,
GListModel *model);
GtkSelectionModel *model);
GDK_AVAILABLE_IN_ALL
void gtk_grid_view_set_factory (GtkGridView *self,
GtkListItemFactory *factory);
......
......@@ -56,7 +56,7 @@ typedef struct _GtkListBasePrivate GtkListBasePrivate;
struct _GtkListBasePrivate
{
GtkListItemManager *item_manager;
GListModel *model;
GtkSelectionModel *model;
GtkOrientation orientation;
GtkAdjustment *adjustment[2];
GtkScrollablePolicy scroll_policy[2];
......@@ -469,7 +469,7 @@ gtk_list_base_get_n_items (GtkListBase *self)
if (priv->model == NULL)
return 0;
return g_list_model_get_n_items (priv->model);
return g_list_model_get_n_items (G_LIST_MODEL (priv->model));
}
guint
......@@ -2102,7 +2102,7 @@ gtk_list_base_grab_focus_on_item (GtkListBase *self,
return TRUE;
}
GListModel *
GtkSelectionModel *
gtk_list_base_get_model (GtkListBase *self)
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
......@@ -2111,8 +2111,8 @@ gtk_list_base_get_model (GtkListBase *self)
}
gboolean
gtk_list_base_set_model (GtkListBase *self,
GListModel *model)
gtk_list_base_set_model (GtkListBase *self,
GtkSelectionModel *model)
{
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
......@@ -2123,19 +2123,9 @@ gtk_list_base_set_model (GtkListBase *self,
if (model)
{
GtkSelectionModel *selection_model;
priv->model = g_object_ref (model);
if (GTK_IS_SELECTION_MODEL (model))
selection_model = GTK_SELECTION_MODEL (g_object_ref (model));
else
selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (model)));
gtk_list_item_manager_set_model (priv->item_manager, selection_model);
gtk_list_item_manager_set_model (priv->item_manager, model);
gtk_list_base_set_anchor (self, 0, 0.0, GTK_PACK_START, 0.0, GTK_PACK_START);
g_object_unref (selection_model);
}
else
{
......
......@@ -25,6 +25,7 @@
#endif
#include <gtk/gtkwidget.h>
#include <gtk/gtkselectionmodel.h>
G_BEGIN_DECLS
......
......@@ -71,9 +71,9 @@ GtkListItemManager * gtk_list_base_get_manager (GtkListBase
GtkScrollablePolicy gtk_list_base_get_scroll_policy (GtkListBase *self,
GtkOrientation orientation);
guint gtk_list_base_get_n_items (GtkListBase *self);
GListModel * gtk_list_base_get_model (GtkListBase *self);
GtkSelectionModel * gtk_list_base_get_model (GtkListBase *self);
gboolean gtk_list_base_set_model (GtkListBase *self,
GListModel *model);
GtkSelectionModel *model);
void gtk_list_base_update_adjustments (GtkListBase *self,
int total_across,
int total_along,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment