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.
This commit is contained in:
Matthias Clasen 2020-08-31 17:06:48 -04:00
parent d2d8b748e9
commit 8d79a32c50
34 changed files with 114 additions and 112 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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);

View File

@ -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);

View File

@ -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")));

View 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">

View File

@ -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"));

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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 ();

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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
{

View File

@ -25,6 +25,7 @@
#endif
#include <gtk/gtkwidget.h>
#include <gtk/gtkselectionmodel.h>
G_BEGIN_DECLS

View File

@ -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,

View File

@ -44,7 +44,7 @@
* SECTION:gtklistview
* @title: GtkListView
* @short_description: A widget for displaying lists
* @see_also: #GListModel, #GtkColumnView, #GtkGridView
* @see_also: #GtkSelectionModel, #GtkColumnView, #GtkGridView
*
* GtkListView is a widget to present a view into a large dynamic list of items.
*
@ -839,7 +839,7 @@ gtk_list_view_class_init (GtkListViewClass *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);
/**
@ -943,11 +943,11 @@ gtk_list_view_init (GtkListView *self)
* Returns: a new #GtkListView
**/
GtkWidget *
gtk_list_view_new (GListModel *model)
gtk_list_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_LIST_VIEW,
"model", model,
@ -977,12 +977,12 @@ gtk_list_view_new (GListModel *model)
* Returns: a new #GtkListView using the given @factory
**/
GtkWidget *
gtk_list_view_new_with_factory (GListModel *model,
gtk_list_view_new_with_factory (GtkSelectionModel *model,
GtkListItemFactory *factory)
{
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);
g_return_val_if_fail (factory == NULL || GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
result = g_object_new (GTK_TYPE_LIST_VIEW,
@ -1005,7 +1005,7 @@ gtk_list_view_new_with_factory (GListModel *model,
*
* Returns: (nullable) (transfer none): The model in use
**/
GListModel *
GtkSelectionModel *
gtk_list_view_get_model (GtkListView *self)
{
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), NULL);
@ -1018,17 +1018,14 @@ gtk_list_view_get_model (GtkListView *self)
* @self: a #GtkListView
* @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_list_view_set_model (GtkListView *self,
GListModel *model)
gtk_list_view_set_model (GtkListView *self,
GtkSelectionModel *model)
{
g_return_if_fail (GTK_IS_LIST_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;

View File

@ -47,16 +47,17 @@ GDK_AVAILABLE_IN_ALL
GType gtk_list_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_list_view_new (GListModel *model);
GtkWidget * gtk_list_view_new (GtkSelectionModel *model);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_list_view_new_with_factory (GListModel *model,
GtkWidget * gtk_list_view_new_with_factory (GtkSelectionModel *model,
GtkListItemFactory *factory);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_list_view_get_model (GtkListView *self);
GtkSelectionModel *
gtk_list_view_get_model (GtkListView *self);
GDK_AVAILABLE_IN_ALL
void gtk_list_view_set_model (GtkListView *self,
GListModel *model);
GtkSelectionModel *model);
GDK_AVAILABLE_IN_ALL
void gtk_list_view_set_factory (GtkListView *self,
GtkListItemFactory *factory);

View File

@ -832,7 +832,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
selection = G_LIST_MODEL (gtk_single_selection_new (filtered));
gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (selection), GTK_INVALID_LIST_POSITION);
gtk_column_view_set_model (GTK_COLUMN_VIEW (dialog->printer_list), selection);
gtk_column_view_set_model (GTK_COLUMN_VIEW (dialog->printer_list), GTK_SELECTION_MODEL (selection));
g_signal_connect (selection, "items-changed", G_CALLBACK (printer_added_cb), dialog);
g_signal_connect_swapped (selection, "notify::selected", G_CALLBACK (selected_printer_changed), dialog);
g_object_unref (selection);
@ -984,7 +984,7 @@ printer_status_cb (GtkPrintBackend *backend,
*/
selected_printer_changed (dialog);
model = gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list));
model = G_LIST_MODEL (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list)));
if (gtk_print_backend_printer_list_is_done (backend) &&
gtk_printer_is_default (printer) &&
@ -1807,7 +1807,7 @@ printer_details_acquired (GtkPrinter *printer,
static void
selected_printer_changed (GtkPrintUnixDialog *dialog)
{
GListModel *model = gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list));
GListModel *model = G_LIST_MODEL (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list)));
GtkPrinter *printer;
/* Whenever the user selects a printer we stop looking for
@ -3152,7 +3152,7 @@ set_active_printer (GtkPrintUnixDialog *dialog,
GtkPrinter *printer;
guint i;
model = gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list));
model = G_LIST_MODEL (gtk_column_view_get_model (GTK_COLUMN_VIEW (dialog->printer_list)));
for (i = 0; i < g_list_model_get_n_items (model); i++)
{

View File

@ -315,7 +315,7 @@ update_attributes (GtkInspectorA11y *sl)
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (store), filter);
selection = gtk_no_selection_new (G_LIST_MODEL (filter_model));
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->attributes), G_LIST_MODEL (selection));
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->attributes), GTK_SELECTION_MODEL (selection));
g_object_unref (selection);
if (g_list_model_get_n_items (G_LIST_MODEL (filter_model)) > 0)

View File

@ -401,7 +401,7 @@ constructed (GObject *object)
sorted = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (sl->actions)),
g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list)))));
model = G_LIST_MODEL (gtk_no_selection_new (sorted));
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model);
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), GTK_SELECTION_MODEL (model));
g_object_unref (model);
}

View File

@ -86,7 +86,7 @@ gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
sl->object = G_LIST_MODEL (object);
selection = gtk_no_selection_new (g_object_ref (sl->object));
gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
gtk_column_view_set_model (sl->view, GTK_SELECTION_MODEL (selection));
g_object_unref (selection);
}

View File

@ -1306,5 +1306,5 @@ gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
NULL);
wt->priv->selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (wt->priv->tree_model)));
gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list),
G_LIST_MODEL (wt->priv->selection));
GTK_SELECTION_MODEL (wt->priv->selection));
}

View File

@ -626,7 +626,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
sorted = gtk_sort_list_model_new (filtered, NULL);
list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list), list);
gtk_column_view_set_model (GTK_COLUMN_VIEW (pl->priv->list), GTK_SELECTION_MODEL (list));
gtk_sort_list_model_set_sorter (sorted, gtk_column_view_get_sorter (GTK_COLUMN_VIEW (pl->priv->list)));
gtk_column_view_sort_by_column (GTK_COLUMN_VIEW (pl->priv->list), pl->priv->name, GTK_SORT_ASCENDING);

View File

@ -1269,7 +1269,7 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
gtk_list_view_set_factory (GTK_LIST_VIEW (recorder->render_node_list), factory);
g_object_unref (factory);
gtk_list_view_set_model (GTK_LIST_VIEW (recorder->render_node_list),
G_LIST_MODEL (recorder->render_node_selection));
GTK_SELECTION_MODEL (recorder->render_node_selection));
recorder->render_node_properties = GTK_TREE_MODEL (gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, GDK_TYPE_TEXTURE));
gtk_tree_view_set_model (GTK_TREE_VIEW (recorder->node_property_tree), recorder->render_node_properties);

View File

@ -713,7 +713,7 @@ constructed (GObject *object)
sort_model = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (rl->tree_model)), sorter));
rl->selection = gtk_single_selection_new (sort_model);
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), GTK_SELECTION_MODEL (rl->selection));
g_signal_connect (rl->selection, "selection-changed", G_CALLBACK (on_selection_changed), rl);
}

View File

@ -694,6 +694,7 @@ main (int argc, char *argv[])
GtkBuilderScope *scope;
GtkBuilder *builder;
GError *error = NULL;
GtkSelectionModel *selection;
gtk_init ();
@ -759,7 +760,9 @@ main (int argc, char *argv[])
filter = gtk_filter_list_model_new (G_LIST_MODEL (sort), custom_filter);
g_signal_connect (search_entry, "search-changed", G_CALLBACK (search_changed_cb), custom_filter);
gtk_column_view_set_model (GTK_COLUMN_VIEW (view), G_LIST_MODEL (filter));
selection = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (filter)));
gtk_column_view_set_model (GTK_COLUMN_VIEW (view), selection);
g_object_unref (selection);
statusbar = gtk_statusbar_new ();
gtk_widget_add_tick_callback (statusbar, (GtkTickCallback) update_statusbar, NULL, NULL);
@ -771,7 +774,7 @@ main (int argc, char *argv[])
g_object_unref (filter);
list = gtk_list_view_new_with_factory (
g_object_ref (gtk_column_view_get_columns (GTK_COLUMN_VIEW (view))),
GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (gtk_column_view_get_columns (GTK_COLUMN_VIEW (view))))),
gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen (factory_ui))));
gtk_box_append (GTK_BOX (hbox), list);

View File

@ -348,7 +348,7 @@ main (int argc, char *argv[])
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
grid = gtk_grid_view_new_with_factory (model, factory);
grid = gtk_grid_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
gtk_grid_view_set_min_columns (GTK_GRID_VIEW (grid), 20);
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (grid), 20);
@ -359,7 +359,7 @@ main (int argc, char *argv[])
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "list", "GtkListView");
list = gtk_list_view_new (create_model (0, 400, 1, FALSE));
list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, FALSE))));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
factory = gtk_signal_list_item_factory_new ();
@ -375,7 +375,7 @@ main (int argc, char *argv[])
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "column", "GtkColumnView");
cv = gtk_column_view_new (create_model (0, 400, 1, FALSE));
cv = gtk_column_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, FALSE))));
for (guint i = 0; i < 20; i++)
{
@ -401,7 +401,7 @@ main (int argc, char *argv[])
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "tree", "Tree");
list = gtk_list_view_new (create_tree_model (20, 20));
list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_tree_model (20, 20))));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
factory = gtk_signal_list_item_factory_new ();

View File

@ -119,6 +119,7 @@ main (int argc,
GtkSorter *sorter;
guint i;
GtkListItemFactory *factory;
GtkSelectionModel *selection;
gtk_init ();
@ -166,7 +167,9 @@ main (int argc,
listbox = gtk_list_box_new ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listbox);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (sort));
selection = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (sort)));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
g_object_unref (selection);
gtk_list_box_bind_model (GTK_LIST_BOX (listbox),
G_LIST_MODEL (sort),
create_widget_for_listbox,

View File

@ -636,7 +636,7 @@ main (int argc, char *argv[])
selectionmodel = file_info_selection_new (G_LIST_MODEL (filter));
g_object_unref (filter);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selectionmodel));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), GTK_SELECTION_MODEL (selectionmodel));
statusbar = gtk_statusbar_new ();
gtk_widget_add_tick_callback (statusbar, (GtkTickCallback) update_statusbar, NULL, NULL);