Merge branch 'list-constructors' into 'master'

List constructors

See merge request GNOME/gtk!2296
This commit is contained in:
Matthias Clasen 2020-07-26 23:56:21 +00:00
commit e57d6ec359
61 changed files with 302 additions and 430 deletions

View File

@ -174,28 +174,25 @@ constraint_view_init (ConstraintView *self)
manager = gtk_constraint_layout_new ();
gtk_widget_set_layout_manager (GTK_WIDGET (self), manager);
all_children = gtk_widget_observe_children (GTK_WIDGET (self));
all_constraints = gtk_constraint_layout_observe_constraints (GTK_CONSTRAINT_LAYOUT (manager));
guides = gtk_constraint_layout_observe_guides (GTK_CONSTRAINT_LAYOUT (manager));
all_constraints = gtk_constraint_layout_observe_constraints (GTK_CONSTRAINT_LAYOUT (manager));
filter = gtk_custom_filter_new (omit_internal, NULL, NULL);
constraints = (GListModel *)gtk_filter_list_model_new (all_constraints, filter);
g_object_unref (filter);
all_children = gtk_widget_observe_children (GTK_WIDGET (self));
filter = gtk_custom_filter_new (omit_internal, NULL, NULL);
children = (GListModel *)gtk_filter_list_model_new (all_children, filter);
g_object_unref (filter);
list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (list, children);
g_list_store_append (list, guides);
g_list_store_append (list, constraints);
self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
g_object_unref (children);
g_object_unref (guides);
g_object_unref (constraints);
g_object_unref (all_children);
g_object_unref (all_constraints);
g_object_unref (list);
self->model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
controller = (GtkEventController *)gtk_gesture_drag_new ();
g_signal_connect (controller, "drag-begin", G_CALLBACK (drag_begin), self);

View File

@ -166,14 +166,6 @@ do_listview_applauncher (GtkWidget *do_widget)
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
/* Create the list widget here.
*/
list = gtk_list_view_new_with_factory (factory);
/* We connect the activate signal here. It's the function we defined
* above for launching the selected application.
*/
g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
/* And of course we need to set the data model. Here we call the function
* we wrote above that gives us the list of applications. Then we set
* it on the list widget.
@ -181,8 +173,15 @@ do_listview_applauncher (GtkWidget *do_widget)
* to create as many listitems as it needs to show itself to the user.
*/
model = create_application_list ();
gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
g_object_unref (model);
/* Create the list widget here.
*/
list = gtk_list_view_new_with_factory (model, factory);
/* We connect the activate signal here. It's the function we defined
* above for launching the selected application.
*/
g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
/* List widgets should always be contained in a #GtkScrolledWindow,
* because otherwise they might get too large or they might not

View File

@ -463,7 +463,6 @@ do_listview_clocks (GtkWidget *do_widget)
GtkWidget *gridview, *sw;
GtkListItemFactory *factory;
GListModel *model;
GtkNoSelection *selection;
/* This is the normal window setup code every demo does */
window = gtk_window_new ();
@ -485,16 +484,12 @@ do_listview_clocks (GtkWidget *do_widget)
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
gridview = gtk_grid_view_new_with_factory (factory);
model = G_LIST_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);
model = create_clocks_model ();
selection = gtk_no_selection_new (model);
gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
g_object_unref (selection);
g_object_unref (model);
}
if (!gtk_widget_get_visible (window))

View File

@ -663,7 +663,7 @@ create_color_grid (void)
GtkWidget *gridview;
GtkListItemFactory *factory;
gridview = gtk_grid_view_new ();
gridview = gtk_grid_view_new (NULL);
gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
@ -884,7 +884,7 @@ do_listview_colors (GtkWidget *do_widget)
sort_model = gtk_sort_list_model_new (gtk_color_list_new (0), NULL);
gtk_sort_list_model_set_incremental (sort_model, TRUE);
selection = GTK_MULTI_SELECTION (gtk_multi_selection_new (G_LIST_MODEL (sort_model)));
selection = gtk_multi_selection_new (G_LIST_MODEL (sort_model));
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Colors");
@ -950,7 +950,7 @@ do_listview_colors (GtkWidget *do_widget)
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_selection_listitem_cb), NULL);
selection_view = gtk_grid_view_new_with_factory (factory);
selection_view = gtk_grid_view_new_with_factory (NULL, factory);
gtk_widget_add_css_class (selection_view, "compact");
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (selection_view), 200);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), selection_view);
@ -970,7 +970,6 @@ do_listview_colors (GtkWidget *do_widget)
no_selection = G_LIST_MODEL (gtk_no_selection_new (selection_filter));
gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection);
g_object_unref (selection_filter);
g_object_unref (no_selection);
selection_info_toggle = gtk_toggle_button_new ();

View File

@ -214,7 +214,6 @@ transform_settings_to_keys (GBinding *binding,
GtkSortListModel *sort_model;
GtkFilterListModel *filter_model;
GtkFilter *filter;
GtkNoSelection *selection_model;
char **keys;
guint i;
@ -242,21 +241,13 @@ transform_settings_to_keys (GBinding *binding,
g_object_unref (settings);
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (store),
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data)));
g_object_unref (store);
g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data))));
filter = gtk_string_filter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
g_object_unref (sort_model);
g_set_object (&current_filter, filter);
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
g_object_unref (filter);
selection_model = gtk_no_selection_new (G_LIST_MODEL (filter_model));
g_object_unref (filter_model);
g_value_take_object (to_value, selection_model);
g_value_take_object (to_value, gtk_no_selection_new (G_LIST_MODEL (filter_model)));
return TRUE;
}
@ -403,8 +394,8 @@ do_listview_settings (GtkWidget *do_widget)
g_object_unref (actions);
model = create_settings_model (NULL, NULL);
treemodel = gtk_tree_list_model_new (FALSE,
model,
treemodel = gtk_tree_list_model_new (model,
FALSE,
TRUE,
create_settings_model,
NULL,
@ -418,8 +409,6 @@ do_listview_settings (GtkWidget *do_widget)
columnview, NULL);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
g_object_unref (selection);
g_object_unref (treemodel);
g_object_unref (model);
name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column"));
sorter = gtk_string_sorter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));

View File

@ -281,20 +281,16 @@ GtkWidget *
create_weather_view (void)
{
GtkWidget *listview;
GListModel *model, *selection;
GListModel *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);
listview = gtk_list_view_new_with_factory (factory);
model = G_LIST_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);
model = create_weather_model ();
selection = G_LIST_MODEL (gtk_no_selection_new (model));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
g_object_unref (selection);
g_object_unref (model);
return listview;
}

View File

@ -157,7 +157,6 @@ do_listview_words (GtkWidget *do_widget)
{
GtkWidget *header, *listview, *sw, *vbox, *search_entry, *open_button, *overlay;
GtkFilterListModel *filter_model;
GtkNoSelection *selection;
GtkStringList *stringlist;
GtkFilter *filter;
GFile *file;
@ -215,18 +214,15 @@ 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_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);
selection = gtk_no_selection_new (G_LIST_MODEL (filter_model));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
g_object_unref (selection);
g_signal_connect (filter_model, "items-changed", G_CALLBACK (update_title_cb), progress);
g_signal_connect (filter_model, "notify::pending", G_CALLBACK (update_title_cb), progress);
update_title_cb (filter_model);
g_object_unref (filter_model);
}
if (!gtk_widget_get_visible (window))

View File

@ -1136,8 +1136,8 @@ activate (GApplication *app)
g_signal_connect (search_bar, "notify::search-mode-enabled", G_CALLBACK (clear_search), NULL);
listmodel = create_demo_model ();
treemodel = gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (listmodel),
treemodel = gtk_tree_list_model_new (G_LIST_MODEL (listmodel),
FALSE,
TRUE,
get_child_model,
NULL,
@ -1145,6 +1145,7 @@ activate (GApplication *app)
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (treemodel), NULL);
filter = gtk_custom_filter_new ((GtkCustomFilterFunc)demo_filter_by_name, filter_model, NULL);
gtk_filter_list_model_set_filter (filter_model, filter);
g_object_unref (filter);
search_entry = GTK_WIDGET (gtk_builder_get_object (builder, "search-entry"));
g_signal_connect (search_entry, "search-changed", G_CALLBACK (demo_search_changed_cb), filter);

View File

@ -1161,7 +1161,7 @@ gtk_column_view_init (GtkColumnView *self)
self->sorter = gtk_column_view_sorter_new ();
self->factory = gtk_column_list_item_factory_new (self);
self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (
self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (NULL,
GTK_LIST_ITEM_FACTORY (g_object_ref (self->factory))));
gtk_widget_set_hexpand (GTK_WIDGET (self->listview), TRUE);
gtk_widget_set_vexpand (GTK_WIDGET (self->listview), TRUE);
@ -1179,19 +1179,30 @@ gtk_column_view_init (GtkColumnView *self)
/**
* gtk_column_view_new:
* @model: (allow-none) (transfer full): the list model to use, or %NULL
*
* Creates a new empty #GtkColumnView.
* Creates a new #GtkColumnView.
*
* You most likely want to call gtk_column_view_set_factory() to
* set up a way to map its items to widgets and gtk_column_view_set_model()
* to set a model to provide items next.
* You most likely want to call gtk_column_view_append_column() to
* add columns next.
*
* Returns: a new #GtkColumnView
**/
GtkWidget *
gtk_column_view_new (void)
gtk_column_view_new (GListModel *model)
{
return g_object_new (GTK_TYPE_COLUMN_VIEW, NULL);
GtkWidget *result;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_COLUMN_VIEW,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return result;
}
/**
@ -1500,8 +1511,8 @@ gtk_column_view_get_list_view (GtkColumnView *self)
* |[
* gtk_column_view_column_set_sorter (column, sorter);
* gtk_column_view_append_column (view, column);
* model = gtk_sort_list_model_new (store,
* gtk_column_view_get_sorter (view));
* sorter = g_object_ref (gtk_column_view_get_sorter (view)));
* model = gtk_sort_list_model_new (store, sorter);
* selection = gtk_no_selection_new (model);
* gtk_column_view_set_model (view, selection);
* ]|

View File

@ -51,7 +51,7 @@ GDK_AVAILABLE_IN_ALL
GType gtk_column_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_column_view_new (void);
GtkWidget * gtk_column_view_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_column_view_get_columns (GtkColumnView *self);

View File

@ -322,12 +322,9 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
g_object_unref (printer_list);
full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list)));
g_object_unref (printer_list_list);
filter = gtk_custom_filter_new (match_func, NULL, NULL);
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
g_object_unref (full_list);
g_object_unref (filter);
dialog->custom_paper_list = g_list_store_new (GTK_TYPE_PAGE_SETUP);
gtk_print_load_custom_papers (dialog->custom_paper_list);
@ -896,20 +893,16 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
gtk_box_append (GTK_BOX (vbox), scrolled);
gtk_widget_show (scrolled);
listview = gtk_list_view_new ();
gtk_widget_set_size_request (listview, 140, -1);
model = G_LIST_MODEL (gtk_single_selection_new (G_LIST_MODEL (dialog->custom_paper_list)));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), model);
model = G_LIST_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);
g_object_unref (model);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
gtk_list_view_set_factory (GTK_LIST_VIEW (listview), factory);
g_object_unref (factory);
listview = gtk_list_view_new_with_factory (model, factory);
gtk_widget_set_size_request (listview, 140, -1);
dialog->listview = listview;

View File

@ -666,9 +666,8 @@ gtk_drop_down_set_model (GtkDropDown *self,
GListModel *filter_model;
GListModel *selection;
filter_model = G_LIST_MODEL (gtk_filter_list_model_new (model, NULL));
filter_model = G_LIST_MODEL (gtk_filter_list_model_new (g_object_ref (model), NULL));
g_set_object (&self->filter_model, filter_model);
g_object_unref (filter_model);
update_filter (self);
@ -677,7 +676,7 @@ gtk_drop_down_set_model (GtkDropDown *self,
gtk_list_view_set_model (GTK_LIST_VIEW (self->popup_list), selection);
g_object_unref (selection);
selection = G_LIST_MODEL (gtk_single_selection_new (model));
selection = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (model)));
g_set_object (&self->selection, selection);
g_object_unref (selection);

View File

@ -614,8 +614,8 @@ gtk_filter_list_model_init (GtkFilterListModel *self)
/**
* gtk_filter_list_model_new:
* @model: (allow-none): the model to sort
* @filter: (allow-none): filter or %NULL to not filter items
* @model: (allow-none) (transfer full): the model to sort, or %NULL
* @filter: (allow-none) (transfer full): filter or %NULL to not filter items
*
* Creates a new #GtkFilterListModel that will filter @model using the given
* @filter.
@ -636,6 +636,10 @@ gtk_filter_list_model_new (GListModel *model,
"filter", filter,
NULL);
/* consume the references */
g_clear_object (&model);
g_clear_object (&filter);
return result;
}

View File

@ -425,7 +425,7 @@ gtk_flatten_list_model_init (GtkFlattenListModel *self)
/**
* gtk_flatten_list_model_new:
* @model: (nullable) (transfer none): the model to be flattened
* @model: (nullable) (transfer full): the model to be flattened
*
* Creates a new #GtkFlattenListModel that flattens @list.
*
@ -442,6 +442,9 @@ gtk_flatten_list_model_new (GListModel *model)
"model", model,
NULL);
/* we consume the reference */
g_clear_object (&model);
return result;
}

View File

@ -784,7 +784,7 @@ update_fontlist (GtkFontChooserWidget *self)
if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0)
model = g_object_ref (G_LIST_MODEL (fontmap));
else
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (fontmap)));
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (g_object_ref (fontmap))));
gtk_filter_list_model_set_model (self->filter_model, model);
g_object_unref (model);
}

View File

@ -1177,52 +1177,65 @@ gtk_grid_view_init (GtkGridView *self)
/**
* gtk_grid_view_new:
* @model: (allow-none) (transfer full): the model to use, or %NULL
*
* Creates a new empty #GtkGridView.
* Creates a new #GtkGridView.
*
* You most likely want to call gtk_grid_view_set_factory() to
* set up a way to map its items to widgets and gtk_grid_view_set_model()
* to set a model to provide items next.
* set up a way to map its items to widgets next.
*
* Returns: a new #GtkGridView
**/
GtkWidget *
gtk_grid_view_new (void)
gtk_grid_view_new (GListModel *model)
{
return g_object_new (GTK_TYPE_GRID_VIEW, NULL);
GtkWidget *result;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_GRID_VIEW,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return result;
}
/**
* gtk_grid_view_new_with_factory:
* @factory: (transfer full): The factory to populate items with
* @model: (allow-none) (transfer full): the model to use, or %NULL
* @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
*
* Creates a new #GtkGridView that uses the given @factory for
* mapping items to widgets.
*
* You most likely want to call gtk_grid_view_set_model() to set
* a model next.
*
* The function takes ownership of the
* argument, so you can write code like
* ```
* grid_view = gtk_grid_view_new_with_factory (
* gtk_builder_list_item_factory_newfrom_resource ("/resource.ui"));
* grid_view = gtk_grid_view_new_with_factory (create_model (),
* gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
* ```
*
* Returns: a new #GtkGridView using the given @factory
**/
GtkWidget *
gtk_grid_view_new_with_factory (GtkListItemFactory *factory)
gtk_grid_view_new_with_factory (GListModel *model,
GtkListItemFactory *factory)
{
GtkWidget *result;
g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
result = g_object_new (GTK_TYPE_GRID_VIEW,
"model", model,
"factory", factory,
NULL);
g_object_unref (factory);
/* consume the references */
g_clear_object (&model);
g_clear_object (&factory);
return result;
}

View File

@ -48,9 +48,10 @@ GDK_AVAILABLE_IN_ALL
GType gtk_grid_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_grid_view_new (void);
GtkWidget * gtk_grid_view_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_grid_view_new_with_factory (GtkListItemFactory *factory);
GtkWidget * gtk_grid_view_new_with_factory (GListModel *model,
GtkListItemFactory *factory);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_grid_view_get_model (GtkGridView *self);

View File

@ -2130,7 +2130,7 @@ gtk_list_base_set_model (GtkListBase *self,
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 (model));
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_base_set_anchor (self, 0, 0.0, GTK_PACK_START, 0.0, GTK_PACK_START);

View File

@ -36,7 +36,6 @@ struct _GtkListListModel
{
GObject parent_instance;
GType item_type;
guint n_items;
gpointer (* get_first) (gpointer);
gpointer (* get_next) (gpointer, gpointer);
@ -55,9 +54,7 @@ struct _GtkListListModelClass
static GType
gtk_list_list_model_get_item_type (GListModel *list)
{
GtkListListModel *self = GTK_LIST_LIST_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -143,8 +140,7 @@ gtk_list_list_model_init (GtkListListModel *self)
}
GtkListListModel *
gtk_list_list_model_new (GType item_type,
gpointer (* get_first) (gpointer),
gtk_list_list_model_new (gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),
gpointer (* get_last) (gpointer),
@ -161,8 +157,7 @@ gtk_list_list_model_new (GType item_type,
item = get_next (item, data))
n_items++;
return gtk_list_list_model_new_with_size (item_type,
n_items,
return gtk_list_list_model_new_with_size (n_items,
get_first,
get_next,
get_previous,
@ -173,8 +168,7 @@ gtk_list_list_model_new (GType item_type,
}
GtkListListModel *
gtk_list_list_model_new_with_size (GType item_type,
guint n_items,
gtk_list_list_model_new_with_size (guint n_items,
gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),
@ -185,7 +179,6 @@ gtk_list_list_model_new_with_size (GType item_type,
{
GtkListListModel *result;
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (get_first != NULL, NULL);
g_return_val_if_fail (get_next != NULL, NULL);
g_return_val_if_fail (get_previous != NULL, NULL);
@ -193,7 +186,6 @@ gtk_list_list_model_new_with_size (GType item_type,
result = g_object_new (GTK_TYPE_LIST_LIST_MODEL, NULL);
result->item_type = item_type;
result->n_items = n_items;
result->get_first = get_first;
result->get_next = get_next;

View File

@ -37,8 +37,7 @@ typedef struct _GtkListListModelClass GtkListListModelClass;
GType gtk_list_list_model_get_type (void) G_GNUC_CONST;
GtkListListModel * gtk_list_list_model_new (GType item_type,
gpointer (* get_first) (gpointer),
GtkListListModel * gtk_list_list_model_new (gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),
gpointer (* get_last) (gpointer),
@ -46,8 +45,7 @@ GtkListListModel * gtk_list_list_model_new (GType
gpointer data,
GDestroyNotify notify);
GtkListListModel * gtk_list_list_model_new_with_size (GType item_type,
guint n_items,
GtkListListModel * gtk_list_list_model_new_with_size (guint n_items,
gpointer (* get_first) (gpointer),
gpointer (* get_next) (gpointer, gpointer),
gpointer (* get_previous) (gpointer, gpointer),

View File

@ -102,18 +102,16 @@
*
* ...
*
* model = create_application_list ();
*
* factory = gtk_signal_list_item_factory_new ();
* g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
* g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
*
* list = gtk_list_view_new_with_factory (factory);
* list = gtk_list_view_new_with_factory (model, factory);
*
* g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
*
* model = create_application_list ();
* gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
* g_object_unref (model);
*
* gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
* ]|
*
@ -931,52 +929,66 @@ gtk_list_view_init (GtkListView *self)
/**
* gtk_list_view_new:
* @model: (allow-none) (transfer full): the model to use, or %NULL
*
* Creates a new empty #GtkListView.
* Creates a new #GtkListView.
*
* You most likely want to call gtk_list_view_set_factory() to
* set up a way to map its items to widgets and gtk_list_view_set_model()
* to set a model to provide items next.
* You most likely want to call gtk_list_view_set_factory()
* to set up a way to map its items to widgets.
*
* Returns: a new #GtkListView
**/
GtkWidget *
gtk_list_view_new (void)
gtk_list_view_new (GListModel *model)
{
return g_object_new (GTK_TYPE_LIST_VIEW, NULL);
GtkWidget *result;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_LIST_VIEW,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return result;
}
/**
* gtk_list_view_new_with_factory:
* @factory: (transfer full): The factory to populate items with
* @model: (allow-none) (transfer full): the model to use, or %NULL
* @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
*
* Creates a new #GtkListView that uses the given @factory for
* mapping items to widgets.
*
* You most likely want to call gtk_list_view_set_model() to set
* a model next.
*
* The function takes ownership of the
* argument, so you can write code like
* ```
* list_view = gtk_list_view_new_with_factory (
* gtk_builder_list_item_factory_newfrom_resource ("/resource.ui"));
* list_view = gtk_list_view_new_with_factory (create_model (),
* gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
* ```
*
* Returns: a new #GtkListView using the given @factory
**/
GtkWidget *
gtk_list_view_new_with_factory (GtkListItemFactory *factory)
gtk_list_view_new_with_factory (GListModel *model,
GtkListItemFactory *factory)
{
GtkWidget *result;
g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
g_return_val_if_fail (model == NULL || G_IS_LIST_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,
"model", model,
"factory", factory,
NULL);
g_object_unref (factory);
/* consume the references */
g_clear_object (&model);
g_clear_object (&factory);
return result;
}

View File

@ -47,9 +47,10 @@ GDK_AVAILABLE_IN_ALL
GType gtk_list_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_list_view_new (void);
GtkWidget * gtk_list_view_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_list_view_new_with_factory (GtkListItemFactory *factory);
GtkWidget * gtk_list_view_new_with_factory (GListModel *model,
GtkListItemFactory *factory);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_list_view_get_model (GtkListView *self);

View File

@ -412,7 +412,7 @@ gtk_map_list_model_augment (GtkRbTree *map,
/**
* gtk_map_list_model_new:
* @model: (allow-none): The model to map or %NULL for none
* @model: (transfer full) (allow-none): The model to map or %NULL for none
* @map_func: (allow-none): map function or %NULL to not map items
* @user_data: (closure): user data passed to @map_func
* @user_destroy: destroy notifier for @user_data
@ -435,6 +435,9 @@ gtk_map_list_model_new (GListModel *model,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
if (map_func)
gtk_map_list_model_set_map_func (result, map_func, user_data, user_destroy);

View File

@ -370,20 +370,27 @@ gtk_multi_selection_init (GtkMultiSelection *self)
/**
* gtk_multi_selection_new:
* @model: (transfer none): the #GListModel to manage
* @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
*
* Creates a new selection to handle @model.
*
* Returns: (transfer full) (type GtkMultiSelection): a new #GtkMultiSelection
* Returns: (transfer full): a new #GtkMultiSelection
**/
GListModel *
GtkMultiSelection *
gtk_multi_selection_new (GListModel *model)
{
GtkMultiSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_MULTI_SELECTION,
self = g_object_new (GTK_TYPE_MULTI_SELECTION,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**

View File

@ -31,13 +31,13 @@ GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkMultiSelection, gtk_multi_selection, GTK, MULTI_SELECTION, GObject)
GDK_AVAILABLE_IN_ALL
GListModel * gtk_multi_selection_new (GListModel *model);
GtkMultiSelection * gtk_multi_selection_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self);
GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self);
GDK_AVAILABLE_IN_ALL
void gtk_multi_selection_set_model (GtkMultiSelection *self,
GListModel *model);
void gtk_multi_selection_set_model (GtkMultiSelection *self,
GListModel *model);
G_END_DECLS

View File

@ -216,7 +216,7 @@ gtk_no_selection_init (GtkNoSelection *self)
/**
* gtk_no_selection_new:
* @model: (transfer none): the #GListModel to manage
* @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
*
* Creates a new selection to handle @model.
*
@ -225,11 +225,18 @@ gtk_no_selection_init (GtkNoSelection *self)
GtkNoSelection *
gtk_no_selection_new (GListModel *model)
{
GtkNoSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_NO_SELECTION,
self = g_object_new (GTK_TYPE_NO_SELECTION,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**
@ -253,8 +260,8 @@ gtk_no_selection_get_model (GtkNoSelection *self)
* @self: a #GtkNoSelection
* @model: (allow-none): A #GListModel to wrap
*
* Sets the model that @self should wrap. If @model is %NULL, this
* model will be empty.
* Sets the model that @self should wrap.
* If @model is %NULL, this model will be empty.
**/
void
gtk_no_selection_set_model (GtkNoSelection *self,

View File

@ -308,7 +308,6 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
g_list_store_append (store, dialog->manage_papers_list);
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
g_object_unref (store);
g_object_unref (paper_size_list);
/* Do this in code, we want the translatable strings without the markup */
@ -325,8 +324,6 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog)
filter = gtk_custom_filter_new (match_func, NULL, NULL);
dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter));
g_object_unref (full_list);
g_object_unref (filter);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_printer_item), dialog);

View File

@ -807,14 +807,12 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
g_list_store_append (store, dialog->manage_papers_list);
paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store)));
gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list);
g_object_unref (store);
g_object_unref (paper_size_list);
/* Load backends */
model = load_print_backends (dialog);
sorter = gtk_custom_sorter_new (default_printer_list_sort_func, NULL, NULL);
sorted = G_LIST_MODEL (gtk_sort_list_model_new (model, sorter));
g_object_unref (sorter);
filter = gtk_every_filter_new ();
@ -831,7 +829,6 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
gtk_multi_filter_append (GTK_MULTI_FILTER (filter), filter1);
filtered = G_LIST_MODEL (gtk_filter_list_model_new (sorted, filter));
g_object_unref (filter);
selection = G_LIST_MODEL (gtk_single_selection_new (filtered));
gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
@ -840,8 +837,6 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
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);
g_object_unref (filtered);
g_object_unref (model);
gtk_print_load_custom_papers (dialog->custom_paper_list);
@ -1037,7 +1032,6 @@ load_print_backends (GtkPrintUnixDialog *dialog)
{
GList *node;
GListStore *lists;
GListModel *model;
lists = g_list_store_new (G_TYPE_LIST_MODEL);
@ -1053,11 +1047,7 @@ load_print_backends (GtkPrintUnixDialog *dialog)
g_list_store_append (lists, gtk_print_backend_get_printers (backend));
}
model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists)));
g_object_unref (lists);
return model;
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists)));
}
static void

View File

@ -37,7 +37,6 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
NUM_PROPERTIES
};
@ -46,7 +45,6 @@ struct _GtkSelectionFilterModel
{
GObject parent_instance;
GType item_type;
GtkSelectionModel *model;
GtkBitset *selection;
};
@ -61,9 +59,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
static GType
gtk_selection_filter_model_get_item_type (GListModel *list)
{
GtkSelectionFilterModel *self = GTK_SELECTION_FILTER_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@ -159,10 +155,6 @@ gtk_selection_filter_model_set_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_selection_filter_model_set_model (self, g_value_get_object (value));
break;
@ -183,10 +175,6 @@ gtk_selection_filter_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@ -229,18 +217,6 @@ gtk_selection_filter_model_class_init (GtkSelectionFilterModelClass *class)
gobject_class->get_property = gtk_selection_filter_model_get_property;
gobject_class->dispose = gtk_selection_filter_model_dispose;
/**
* GtkSelectionFilterModel:item-type:
*
* The #GType for elements of this object
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of elements of this object"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSelectionFilterModel:model:
*
@ -263,7 +239,7 @@ gtk_selection_filter_model_init (GtkSelectionFilterModel *self)
/**
* gtk_selection_filter_model_new:
* @model: the selection model to filter
* @model: (allow-none) (transfer none): the selection model to filter, or %NULL
*
* Creates a new #GtkSelectionFilterModel that will include the
* selected items from the underlying selection model.
@ -273,35 +249,8 @@ gtk_selection_filter_model_init (GtkSelectionFilterModel *self)
GtkSelectionFilterModel *
gtk_selection_filter_model_new (GtkSelectionModel *model)
{
GtkSelectionFilterModel *result;
g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_SELECTION_FILTER_MODEL,
"item-type", g_list_model_get_item_type (G_LIST_MODEL (model)),
"model", model,
NULL);
return result;
}
/**
* gtk_selection_filter_model_new_for_type:
* @item_type: the type of the items that will be returned
*
* Creates a new empty selection filter model set up to return items
* of type @item_type. It is up to the application to set a proper
* selection model to ensure the item type is matched.
*
* Returns: a new #GtkSelectionFilterModel
**/
GtkSelectionFilterModel *
gtk_selection_filter_model_new_for_type (GType item_type)
{
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
return g_object_new (GTK_TYPE_SELECTION_FILTER_MODEL,
"item-type", item_type,
"model", model,
NULL);
}
@ -325,8 +274,6 @@ gtk_selection_filter_model_set_model (GtkSelectionFilterModel *self,
g_return_if_fail (GTK_IS_SELECTION_FILTER_MODEL (self));
g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
g_return_if_fail (model == NULL || g_type_is_a (g_list_model_get_item_type (G_LIST_MODEL (model)),
self->item_type));
if (self->model == model)
return;

View File

@ -44,21 +44,16 @@ G_DEFINE_INTERFACE (GtkShortcutManager, gtk_shortcut_manager, G_TYPE_OBJECT)
void
gtk_shortcut_manager_create_controllers (GtkWidget *widget)
{
GListStore *store;
GtkFlattenListModel *model;
GtkEventController *controller;
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
g_object_unref (store);
model = gtk_flatten_list_model_new (G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER)));
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-bubble");
gtk_widget_add_controller (widget, controller);
store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER);
model = gtk_flatten_list_model_new (G_LIST_MODEL (store));
g_object_unref (store);
model = gtk_flatten_list_model_new (G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER)));
g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref);
controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model));
gtk_event_controller_set_name (controller, "gtk-shortcut-manager-capture");

View File

@ -453,7 +453,7 @@ gtk_single_selection_init (GtkSingleSelection *self)
/**
* gtk_single_selection_new:
* @model: (transfer none): the #GListModel to manage
* @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
*
* Creates a new selection to handle @model.
*
@ -462,11 +462,18 @@ gtk_single_selection_init (GtkSingleSelection *self)
GtkSingleSelection *
gtk_single_selection_new (GListModel *model)
{
GtkSingleSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_SINGLE_SELECTION,
self = g_object_new (GTK_TYPE_SINGLE_SELECTION,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**

View File

@ -30,11 +30,12 @@
* @short_description: A list model that presents a slice out of a larger list
* @see_also: #GListModel
*
* #GtkSliceListModel is a list model that takes a list model and presents a slice of
* that model.
* #GtkSliceListModel is a list model that takes a list model and presents a
* slice of that model.
*
* This is useful when implementing paging by setting the size to the number of elements
* per page and updating the offset whenever a different page is opened.
* This is useful when implementing paging by setting the size to the number
* of elements per page and updating the offset whenever a different page is
* opened.
*/
#define DEFAULT_SIZE 10
@ -300,7 +301,7 @@ gtk_slice_list_model_init (GtkSliceListModel *self)
/**
* gtk_slice_list_model_new:
* @model: (transfer none) (allow-none): The model to use
* @model: (transfer full) (allow-none): The model to use, or %NULL
* @offset: the offset of the slice
* @size: maximum size of the slice
*
@ -314,13 +315,20 @@ gtk_slice_list_model_new (GListModel *model,
guint offset,
guint size)
{
GtkSliceListModel *self;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
self = g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
"model", model,
"offset", offset,
"size", size,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**

View File

@ -828,8 +828,8 @@ gtk_sort_list_model_init (GtkSortListModel *self)
/**
* gtk_sort_list_model_new:
* @model: (allow-none): the model to sort
* @sorter: (allow-none): the #GtkSorter to sort @model with
* @model: (allow-none) (transfer full): the model to sort, or %NULL
* @sorter: (allow-none) (transfer full): the #GtkSorter to sort @model with, or %NULL
*
* Creates a new sort list model that uses the @sorter to sort @model.
*
@ -849,6 +849,10 @@ gtk_sort_list_model_new (GListModel *model,
"sorter", sorter,
NULL);
/* consume the references */
g_clear_object (&model);
g_clear_object (&sorter);
return result;
}

View File

@ -734,8 +734,8 @@ gtk_tree_list_model_init (GtkTreeListModel *self)
/**
* gtk_tree_list_model_new:
* @root: (transfer full): The #GListModel to use as root
* @passthrough: %TRUE to pass through items from the models
* @root: The #GListModel to use as root
* @autoexpand: %TRUE to set the autoexpand property and expand the @root model
* @create_func: Function to call to create the #GListModel for the children
* of an item
@ -743,12 +743,12 @@ gtk_tree_list_model_init (GtkTreeListModel *self)
* @user_destroy: Function to call to free @user_data
*
* Creates a new empty #GtkTreeListModel displaying @root with all rows collapsed.
*
* Returns: a newly created #GtkTreeListModel.
*
* Returns: a newly created #GtkTreeListModel.
**/
GtkTreeListModel *
gtk_tree_list_model_new (gboolean passthrough,
GListModel *root,
gtk_tree_list_model_new (GListModel *root,
gboolean passthrough,
gboolean autoexpand,
GtkTreeListModelCreateModelFunc create_func,
gpointer user_data,
@ -768,7 +768,7 @@ gtk_tree_list_model_new (gboolean passthrough,
self->user_data = user_data;
self->user_destroy = user_destroy;
gtk_tree_list_model_init_node (self, &self->root_node, g_object_ref (root));
gtk_tree_list_model_init_node (self, &self->root_node, root);
return self;
}

View File

@ -58,8 +58,8 @@ G_DECLARE_FINAL_TYPE (GtkTreeListRow, gtk_tree_list_row, GTK, TREE_LIST_ROW, GOb
typedef GListModel * (* GtkTreeListModelCreateModelFunc) (gpointer item, gpointer user_data);
GDK_AVAILABLE_IN_ALL
GtkTreeListModel * gtk_tree_list_model_new (gboolean passthrough,
GListModel *root,
GtkTreeListModel * gtk_tree_list_model_new (GListModel *root,
gboolean passthrough,
gboolean autoexpand,
GtkTreeListModelCreateModelFunc create_func,
gpointer user_data,

View File

@ -11535,8 +11535,7 @@ gtk_widget_observe_children (GtkWidget *widget)
if (priv->children_observer)
return g_object_ref (G_LIST_MODEL (priv->children_observer));
priv->children_observer = gtk_list_list_model_new (GTK_TYPE_WIDGET,
(gpointer) gtk_widget_get_first_child,
priv->children_observer = gtk_list_list_model_new ((gpointer) gtk_widget_get_first_child,
(gpointer) gtk_widget_get_next_sibling,
(gpointer) gtk_widget_get_prev_sibling,
(gpointer) gtk_widget_get_last_child,
@ -11622,14 +11621,13 @@ gtk_widget_observe_controllers (GtkWidget *widget)
if (priv->controller_observer)
return g_object_ref (G_LIST_MODEL (priv->controller_observer));
priv->controller_observer = gtk_list_list_model_new (GTK_TYPE_EVENT_CONTROLLER,
gtk_widget_controller_list_get_first,
gtk_widget_controller_list_get_next,
gtk_widget_controller_list_get_prev,
NULL,
(gpointer) g_object_ref,
widget,
gtk_widget_controller_observer_destroyed);
priv->controller_observer = gtk_list_list_model_new (gtk_widget_controller_list_get_first,
gtk_widget_controller_list_get_next,
gtk_widget_controller_list_get_prev,
NULL,
(gpointer) g_object_ref,
widget,
gtk_widget_controller_observer_destroyed);
return G_LIST_MODEL (priv->controller_observer);
}

View File

@ -46,7 +46,7 @@ struct _GtkInspectorActions
GObject *object;
GListModel *actions;
GListStore *actions;
GtkColumnViewColumn *name;
};
@ -79,7 +79,7 @@ action_added (GObject *owner,
GtkInspectorActions *sl)
{
ActionHolder *holder = action_holder_new (owner, action_name);
g_list_store_append (G_LIST_STORE (sl->actions), holder);
g_list_store_append (sl->actions, holder);
g_object_unref (holder);
}
@ -283,7 +283,7 @@ add_muxer (GtkInspectorActions *sl,
static gboolean
reload (GtkInspectorActions *sl)
{
g_list_store_remove_all (G_LIST_STORE (sl->actions));
g_list_store_remove_all (sl->actions);
if (GTK_IS_APPLICATION (sl->object))
{
@ -395,12 +395,11 @@ constructed (GObject *object)
gtk_column_view_column_set_sorter (sl->name, sorter);
g_object_unref (sorter);
sl->actions = G_LIST_MODEL (g_list_store_new (ACTION_TYPE_HOLDER));
sorted = G_LIST_MODEL (gtk_sort_list_model_new (sl->actions,
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list))));
sl->actions = g_list_store_new (ACTION_TYPE_HOLDER);
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);
g_object_unref (sorted);
g_object_unref (model);
}

View File

@ -244,13 +244,11 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
gtk_property_lookup_list_model_set_object (self->model, object);
map_model = gtk_map_list_model_new (G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL);
g_object_unref (self->model);
flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (map_model));
sorter = gtk_custom_sorter_new (compare_controllers, NULL, NULL);
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model), sorter);
g_object_unref (sorter);
gtk_list_box_bind_model (GTK_LIST_BOX (self->listbox),
G_LIST_MODEL (sort_model),
@ -259,8 +257,6 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
NULL);
g_object_unref (sort_model);
g_object_unref (flatten_model);
g_object_unref (map_model);
}
static void

View File

@ -85,7 +85,7 @@ gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
g_object_set (page, "visible", TRUE, NULL);
sl->object = G_LIST_MODEL (object);
selection = gtk_no_selection_new (sl->object);
selection = gtk_no_selection_new (g_object_ref (sl->object));
gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
g_object_unref (selection);
}

View File

@ -116,7 +116,6 @@ static GListModel *
object_tree_widget_get_children (GObject *object)
{
GtkWidget *widget = GTK_WIDGET (object);
GtkFlattenListModel *flatten;
GListStore *list;
GListModel *sublist;
@ -130,10 +129,7 @@ object_tree_widget_get_children (GObject *object)
g_list_store_append (list, sublist);
g_object_unref (sublist);
flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
g_object_unref (list);
return G_LIST_MODEL (flatten);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
}
static GListModel *
@ -211,7 +207,6 @@ list_model_for_properties (GObject *object,
const char **props)
{
GListStore *concat;
GListModel *result;
guint i;
if (props[1] == NULL)
@ -225,9 +220,7 @@ list_model_for_properties (GObject *object,
g_object_unref (tmp);
}
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
g_object_unref (concat);
return result;
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat)));
}
static GListModel *
@ -310,7 +303,6 @@ object_tree_tree_view_get_children (GObject *object)
GtkTreeView *treeview = GTK_TREE_VIEW (object);
GListStore *columns, *selection, *result_list;
GListModel *props;
GtkFlattenListModel *result;
guint i;
props = list_model_for_properties (object, (const char *[2]) { "model", NULL });
@ -330,10 +322,8 @@ object_tree_tree_view_get_children (GObject *object)
g_object_unref (selection);
g_list_store_append (result_list, columns);
g_object_unref (columns);
result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (result);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
}
static GListModel *
@ -341,7 +331,6 @@ object_tree_column_view_get_children (GObject *object)
{
GtkColumnView *view = GTK_COLUMN_VIEW (object);
GListStore *result_list;
GtkFlattenListModel *result;
GListModel *columns, *sublist;
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
@ -353,10 +342,7 @@ object_tree_column_view_get_children (GObject *object)
g_list_store_append (result_list, sublist);
g_object_unref (sublist);
result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list));
g_object_unref (result_list);
return G_LIST_MODEL (result);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
}
static GListModel *
@ -602,12 +588,11 @@ static GListModel *
object_get_children (GObject *object)
{
GType object_type;
GListModel *result, *children;
GListModel *children;
GListStore *result_list;
guint i;
object_type = G_OBJECT_TYPE (object);
result = NULL;
result_list = NULL;
for (i = 0; i < G_N_ELEMENTS (object_tree_class_funcs); i++)
@ -619,32 +604,17 @@ object_get_children (GObject *object)
if (children == NULL)
continue;
if (result_list)
{
g_list_store_append (result_list, children);
g_object_unref (children);
}
else if (result == NULL)
{
result = children;
}
else
{
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (result_list, result);
g_object_unref (result);
g_list_store_append (result_list, children);
g_object_unref (children);
}
if (!result_list)
result_list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (result_list, children);
g_object_unref (children);
}
if (result_list)
{
result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
g_object_unref (result_list);
}
return result;
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list)));
else
return NULL;
}
static const char *
@ -1167,7 +1137,6 @@ create_root_model (GdkDisplay *display)
{
GtkFilter *custom_filter;
GtkFilterListModel *filter;
GtkFlattenListModel *flatten;
GListStore *list, *special;
gpointer item;
@ -1182,16 +1151,13 @@ create_root_model (GdkDisplay *display)
g_object_unref (special);
filter = gtk_filter_list_model_new (NULL, NULL);
custom_filter = gtk_custom_filter_new (toplevel_filter_func,
display, NULL);
custom_filter = gtk_custom_filter_new (toplevel_filter_func, display, NULL);
gtk_filter_list_model_set_filter (filter, custom_filter);
gtk_filter_list_model_set_model (filter, gtk_window_get_toplevels ());
g_list_store_append (list, filter);
g_object_unref (filter);
flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list));
g_object_unref (list);
return G_LIST_MODEL (flatten);
return G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (list)));
}
static void
@ -1332,18 +1298,13 @@ void
gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
GdkDisplay *display)
{
GListModel *root_model;
root_model = create_root_model (display);
wt->priv->tree_model = gtk_tree_list_model_new (FALSE,
root_model,
wt->priv->tree_model = gtk_tree_list_model_new (create_root_model (display),
FALSE,
FALSE,
create_model_for_object,
NULL,
NULL);
wt->priv->selection = gtk_single_selection_new (G_LIST_MODEL (wt->priv->tree_model));
g_object_unref (root_model);
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));
}

View File

@ -622,7 +622,7 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
if (GTK_IS_WIDGET (object))
g_signal_connect_object (object, "destroy", G_CALLBACK (cleanup_object), pl, G_CONNECT_SWAPPED);
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), pl->priv->filter));
filtered = G_LIST_MODEL (gtk_filter_list_model_new (G_LIST_MODEL (store), g_object_ref (pl->priv->filter)));
sorted = gtk_sort_list_model_new (filtered, NULL);
list = G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (sorted)));
@ -633,9 +633,6 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
gtk_widget_show (GTK_WIDGET (pl));
g_object_unref (list);
g_object_unref (sorted);
g_object_unref (filtered);
g_object_unref (store);
return TRUE;
}

View File

@ -1234,12 +1234,12 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
NULL);
recorder->render_node_root_model = g_list_store_new (GDK_TYPE_PAINTABLE);
recorder->render_node_model = gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (recorder->render_node_root_model),
recorder->render_node_model = gtk_tree_list_model_new (g_object_ref (G_LIST_MODEL (recorder->render_node_root_model)),
FALSE,
TRUE,
create_list_model_for_render_node_paintable,
NULL, NULL);
recorder->render_node_selection = gtk_single_selection_new (G_LIST_MODEL (recorder->render_node_model));
recorder->render_node_selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (recorder->render_node_model)));
g_signal_connect (recorder->render_node_selection, "notify::selected-item", G_CALLBACK (render_node_list_selection_changed), recorder);
factory = gtk_signal_list_item_factory_new ();

View File

@ -692,7 +692,6 @@ static void
constructed (GObject *object)
{
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
GListModel *root_model;
GListModel *sort_model;
GtkSorter *column_sorter;
GtkSorter *sorter;
@ -702,9 +701,8 @@ constructed (GObject *object)
g_signal_connect (rl->close_details_button, "clicked",
G_CALLBACK (close_details), rl);
root_model = load_resources ();
rl->tree_model = gtk_tree_list_model_new (FALSE,
root_model,
rl->tree_model = gtk_tree_list_model_new (load_resources (),
FALSE,
FALSE,
create_model_for_object,
NULL,
@ -712,11 +710,8 @@ constructed (GObject *object)
column_sorter = gtk_column_view_get_sorter (GTK_COLUMN_VIEW (rl->list));
sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter));
sort_model = G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (rl->tree_model), sorter));
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);
g_object_unref (root_model);
g_object_unref (sort_model);
g_object_unref (sorter);
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));

View File

@ -746,12 +746,11 @@ main (int argc, char *argv[])
dirmodel = create_list_model_for_directory (root);
g_object_unref (root);
}
tree = gtk_tree_list_model_new (FALSE,
dirmodel,
tree = gtk_tree_list_model_new (dirmodel,
FALSE,
TRUE,
create_list_model_for_file_info,
NULL, NULL);
g_object_unref (dirmodel);
sorter = gtk_tree_list_row_sorter_new (g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (view))));
sort = gtk_sort_list_model_new (G_LIST_MODEL (tree), sorter);
@ -759,7 +758,6 @@ main (int argc, char *argv[])
custom_filter = gtk_custom_filter_new (match_file, g_object_ref (search_entry), g_object_unref);
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);
g_object_unref (custom_filter);
gtk_column_view_set_model (GTK_COLUMN_VIEW (view), G_LIST_MODEL (filter));
@ -771,12 +769,10 @@ main (int argc, char *argv[])
gtk_box_append (GTK_BOX (vbox), statusbar);
g_object_unref (filter);
g_object_unref (sort);
g_object_unref (tree);
list = gtk_list_view_new_with_factory (
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_list_view_set_model (GTK_LIST_VIEW (list), gtk_column_view_get_columns (GTK_COLUMN_VIEW (view)));
gtk_box_append (GTK_BOX (hbox), list);
g_object_unref (scope);
@ -787,6 +783,5 @@ main (int argc, char *argv[])
while (g_list_model_get_n_items (toplevels))
g_main_context_iteration (NULL, TRUE);
return 0;
}

View File

@ -191,8 +191,8 @@ create_child_model (gpointer item,
static GListModel *
create_tree_model (guint n, guint m)
{
return G_LIST_MODEL (gtk_tree_list_model_new (FALSE,
create_model (0, n, m, TRUE),
return G_LIST_MODEL (gtk_tree_list_model_new (create_model (0, n, m, TRUE),
FALSE,
FALSE,
create_child_model,
GUINT_TO_POINTER (m), NULL));
@ -342,36 +342,26 @@ main (int argc, char *argv[])
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "grid", "GtkGridView");
grid = gtk_grid_view_new ();
gtk_grid_view_set_min_columns (GTK_GRID_VIEW (grid), 20);
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (grid), 20);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), grid);
model = create_model (0, 400, 1, FALSE);
gtk_grid_view_set_model (GTK_GRID_VIEW (grid), model);
g_object_unref (model);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
gtk_grid_view_set_factory (GTK_GRID_VIEW (grid), factory);
g_object_unref (factory);
grid = gtk_grid_view_new_with_factory (model, factory);
gtk_grid_view_set_min_columns (GTK_GRID_VIEW (grid), 20);
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (grid), 20);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), grid);
/* list */
sw = gtk_scrolled_window_new ();
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 ();
list = gtk_list_view_new (create_model (0, 400, 1, FALSE));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
model = create_model (0, 400, 1, FALSE);
gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
g_object_unref (model);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
@ -385,11 +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 ();
model = create_model (0, 400, 1, FALSE);
gtk_column_view_set_model (GTK_COLUMN_VIEW (cv), model);
g_object_unref (model);
cv = gtk_column_view_new (create_model (0, 400, 1, FALSE));
for (guint i = 0; i < 20; i++)
{
@ -415,13 +401,9 @@ 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 ();
list = gtk_list_view_new (create_tree_model (20, 20));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
model = create_tree_model (20, 20);
gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
g_object_unref (model);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_tree_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_tree_item), NULL);

View File

@ -127,7 +127,6 @@ main (int argc,
add (store);
sorter = gtk_numeric_sorter_new (gtk_cclosure_expression_new (G_TYPE_UINT, NULL, 0, NULL, (GCallback)get_number, NULL, NULL));
sort = gtk_sort_list_model_new (G_LIST_MODEL (store), sorter);
g_object_unref (sorter);
win = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (win), 400, 600);
@ -149,7 +148,7 @@ main (int argc,
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_list_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_list_item), NULL);
listview = gtk_list_view_new_with_factory (factory);
listview = gtk_list_view_new_with_factory (NULL, factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
@ -182,7 +181,5 @@ main (int argc,
while (g_list_model_get_n_items (toplevels))
g_main_context_iteration (NULL, TRUE);
g_object_unref (store);
return 0;
}

View File

@ -318,7 +318,6 @@ get_file_path (GFileInfo *info)
static GListModel *
create_list_model_for_directory (gpointer file)
{
GtkSortListModel *sort;
GtkDirectoryList *dir;
GtkSorter *sorter;
@ -327,12 +326,8 @@ create_list_model_for_directory (gpointer file)
dir = create_directory_list (file);
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL, (GCallback) get_file_path, NULL, NULL));
sort = gtk_sort_list_model_new (G_LIST_MODEL (dir), sorter);
g_object_unref (sorter);
g_object_unref (dir);
return G_LIST_MODEL (sort);
return G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (dir), sorter));
}
typedef struct _RowData RowData;
@ -594,7 +589,6 @@ int
main (int argc, char *argv[])
{
GtkWidget *win, *vbox, *sw, *listview, *search_entry, *statusbar;
GListModel *dirmodel;
GtkTreeListModel *tree;
GtkFilterListModel *filter;
GtkFilter *custom_filter;
@ -621,26 +615,23 @@ main (int argc, char *argv[])
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
listview = gtk_list_view_new_with_factory (factory);
listview = gtk_list_view_new_with_factory (NULL, factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
if (argc > 1)
root = g_file_new_for_commandline_arg (argv[1]);
else
root = g_file_new_for_path (g_get_current_dir ());
dirmodel = create_list_model_for_directory (root);
tree = gtk_tree_list_model_new (FALSE,
dirmodel,
tree = gtk_tree_list_model_new (create_list_model_for_directory (root),
FALSE,
TRUE,
create_list_model_for_file_info,
NULL, NULL);
g_object_unref (dirmodel);
g_object_unref (root);
custom_filter = gtk_custom_filter_new (match_file, search_entry, NULL);
filter = gtk_filter_list_model_new (G_LIST_MODEL (tree), custom_filter);
g_signal_connect (search_entry, "search-changed", G_CALLBACK (search_changed_cb), custom_filter);
g_object_unref (custom_filter);
selectionmodel = file_info_selection_new (G_LIST_MODEL (filter));
g_object_unref (filter);
@ -654,7 +645,6 @@ main (int argc, char *argv[])
update_statusbar (GTK_STATUSBAR (statusbar));
gtk_box_append (GTK_BOX (vbox), statusbar);
g_object_unref (tree);
g_object_unref (selectionmodel);
gtk_widget_show (win);

View File

@ -203,7 +203,7 @@ test_nested (void)
filter = gtk_string_filter_new (NULL);
gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "word");
list = G_LIST_MODEL (g_list_store_new (G_TYPE_OBJECT));
filtered = gtk_filter_list_model_new (list, filter);
filtered = gtk_filter_list_model_new (list, g_object_ref (filter));
list_expr = gtk_object_expression_new (G_OBJECT (filtered));
filter_expr = gtk_property_expression_new (GTK_TYPE_FILTER_LIST_MODEL, list_expr, "filter");
@ -262,8 +262,6 @@ test_nested (void)
g_assert_cmpint (counter, ==, 0);
g_object_unref (filtered);
g_object_unref (list);
g_object_unref (filter);
gtk_expression_unref (expr);
}
@ -292,7 +290,7 @@ test_nested_this_destroyed (void)
filter = gtk_string_filter_new (NULL);
gtk_string_filter_set_search (GTK_STRING_FILTER (filter), "word");
list = G_LIST_MODEL (g_list_store_new (G_TYPE_OBJECT));
filtered = gtk_filter_list_model_new (list, filter);
filtered = gtk_filter_list_model_new (list, g_object_ref (filter));
list_expr = gtk_object_expression_new (G_OBJECT (filtered));
filter_expr = gtk_property_expression_new (GTK_TYPE_FILTER_LIST_MODEL, list_expr, "filter");
@ -333,7 +331,6 @@ test_nested_this_destroyed (void)
g_assert_cmpint (counter, ==, 0);
g_object_unref (filtered);
g_object_unref (list);
g_object_unref (filter);
gtk_expression_unref (expr);
}
@ -492,11 +489,8 @@ test_bind_child (void)
"filter");
filter = gtk_string_filter_new (NULL);
child = gtk_filter_list_model_new (NULL, NULL);
gtk_filter_list_model_set_filter (child, filter);
child = gtk_filter_list_model_new (NULL, filter);
target = gtk_filter_list_model_new (G_LIST_MODEL (child), NULL);
g_object_unref (child);
g_object_unref (filter);
gtk_expression_bind (expr, target, "filter", child);
g_assert_true (gtk_filter_list_model_get_filter (child) == gtk_filter_list_model_get_filter (target));
@ -528,7 +522,7 @@ test_nested_bind (void)
gtk_string_filter_set_search (GTK_STRING_FILTER (filter2), "sausage");
list = G_LIST_MODEL (g_list_store_new (G_TYPE_OBJECT));
filtered = gtk_filter_list_model_new (list, filter2);
filtered = gtk_filter_list_model_new (list, g_object_ref (filter2));
filter_expr = gtk_property_expression_new (GTK_TYPE_FILTER_LIST_MODEL,
gtk_object_expression_new (G_OBJECT (filtered)),
@ -566,7 +560,6 @@ test_nested_bind (void)
g_object_unref (filter2);
g_object_unref (filter3);
g_object_unref (filtered);
g_object_unref (list);
gtk_expression_unref (expr);
gtk_expression_unref (filter_expr);
@ -709,7 +702,6 @@ test_bind_object (void)
gtk_expression_unref (expr);
g_object_unref (model);
g_object_unref (store);
}
int

View File

@ -189,7 +189,7 @@ new_model (guint size,
{
GtkFilterListModel *result;
result = gtk_filter_list_model_new (G_LIST_MODEL (new_store (1, size, 1)), filter);
result = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (new_store (1, size, 1))), g_object_ref (filter));
return result;
}

View File

@ -135,6 +135,10 @@ filter_list_model_new (GListModel *source,
GListStore *check;
guint i;
if (source)
g_object_ref (source);
if (filter)
g_object_ref (filter);
model = gtk_filter_list_model_new (source, filter);
check = g_list_store_new (G_TYPE_OBJECT);
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (model)); i++)
@ -443,8 +447,6 @@ test_model_changes (gconstpointer model_id)
g_object_unref (model2);
g_object_unref (flatten2);
g_object_unref (flatten1);
g_object_unref (store2);
g_object_unref (store1);
g_object_unref (multi);
}

View File

@ -167,8 +167,7 @@ new_model (guint size,
filter = gtk_custom_filter_new (filter_func, data, NULL);
else
filter = NULL;
result = gtk_filter_list_model_new (G_LIST_MODEL (new_store (1, size, 1)), filter);
g_clear_object (&filter);
result = gtk_filter_list_model_new (g_object_ref (G_LIST_MODEL (new_store (1, size, 1))), filter);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);

View File

@ -210,6 +210,8 @@ new_model (GListStore *store)
GtkFlattenListModel *result;
GString *changes;
if (store)
g_object_ref (store);
result = gtk_flatten_list_model_new (G_LIST_MODEL (store));
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);

View File

@ -196,6 +196,8 @@ new_model (GListStore *store)
GtkMapListModel *result;
GString *changes;
if (store)
g_object_ref (store);
result = gtk_map_list_model_new (G_LIST_MODEL (store), map_multiply, GUINT_TO_POINTER (2), NULL);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);

View File

@ -253,7 +253,7 @@ new_model (GListStore *store)
GtkSelectionModel *result;
GString *changes;
result = GTK_SELECTION_MODEL (gtk_multi_selection_new (G_LIST_MODEL (store)));
result = GTK_SELECTION_MODEL (gtk_multi_selection_new (g_object_ref (G_LIST_MODEL (store))));
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
@ -615,6 +615,7 @@ test_selection_filter (void)
g_object_unref (store);
g_object_unref (selection);
g_object_unref (filter);
}
static void
@ -627,7 +628,7 @@ test_set_model (void)
store = new_store (1, 5, 1);
m1 = G_LIST_MODEL (store);
m2 = G_LIST_MODEL (gtk_slice_list_model_new (m1, 0, 3));
m2 = G_LIST_MODEL (gtk_slice_list_model_new (g_object_ref (m1), 0, 3));
selection = new_model (store);
assert_selection (selection, "");
assert_selection_changes (selection, "");

View File

@ -249,7 +249,7 @@ new_model (GListStore *store, gboolean autoselect, gboolean can_unselect)
GtkSelectionModel *result;
GString *changes;
result = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (store)));
result = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (store))));
/* We want to return an empty selection unless autoselect is true,
* so undo the initial selection due to autoselect defaulting to TRUE.
@ -653,7 +653,7 @@ test_set_model (void)
store = new_store (1, 5, 1);
m1 = G_LIST_MODEL (store);
m2 = G_LIST_MODEL (gtk_slice_list_model_new (m1, 0, 3));
m2 = G_LIST_MODEL (gtk_slice_list_model_new (g_object_ref (m1), 0, 3));
selection = new_model (store, TRUE, TRUE);
assert_selection (selection, "1");
assert_selection_changes (selection, "");

View File

@ -191,6 +191,8 @@ new_model (GListStore *store, guint offset, guint size)
GtkSliceListModel *result;
GString *changes;
if (store)
g_object_ref (store);
result = gtk_slice_list_model_new (G_LIST_MODEL (store), offset, size);
changes = g_string_new ("");

View File

@ -247,6 +247,8 @@ new_model (guint size,
{
GtkSortListModel *result;
if (sorter)
g_object_ref (sorter);
result = gtk_sort_list_model_new (G_LIST_MODEL (fisher_yates_shuffle (new_store (1, size, 1))), sorter);
return result;
@ -630,8 +632,8 @@ test_stable (void)
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi), b);
model1 = new_model (20, multi);
g_object_unref (multi);
model2b = gtk_sort_list_model_new (gtk_sort_list_model_get_model (model1), b);
model2 = gtk_sort_list_model_new (G_LIST_MODEL (model2b), a);
model2b = gtk_sort_list_model_new (g_object_ref (gtk_sort_list_model_get_model (model1)), g_object_ref (b));
model2 = gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (model2b)), g_object_ref (a));
assert_model_equal (model1, model2);
modify_sorter (a);

View File

@ -200,9 +200,9 @@ create_sort_list_model (gconstpointer model_id,
guint id = GPOINTER_TO_UINT (model_id);
if (track_changes)
model = sort_list_model_new (id & 1 ? NULL : source, id & 2 ? NULL : sorter);
model = sort_list_model_new (((id & 1) || !source) ? NULL : g_object_ref (source), ((id & 2) || !sorter) ? NULL : g_object_ref (sorter));
else
model = gtk_sort_list_model_new (id & 1 ? NULL : source, id & 2 ? NULL : sorter);
model = gtk_sort_list_model_new (((id & 1) || !source) ? NULL : g_object_ref (source), ((id & 2) || !sorter) ? NULL : g_object_ref (sorter));
switch (id >> 2)
{
@ -433,7 +433,6 @@ test_stability (gconstpointer model_id)
g_object_unref (sort2);
g_object_unref (sort1);
g_object_unref (flatten);
g_object_unref (store);
}
static void

View File

@ -220,8 +220,7 @@ new_model (gpointer model)
GtkSorter *sorter;
sorter = gtk_custom_sorter_new (compare, NULL, NULL);
result = gtk_sort_list_model_new (model, sorter);
g_object_unref (sorter);
result = gtk_sort_list_model_new (g_object_ref (model), sorter);
}
else
result = gtk_sort_list_model_new (NULL, NULL);

View File

@ -170,7 +170,7 @@ new_model (guint size,
GtkTreeListModel *tree;
GString *changes;
tree = gtk_tree_list_model_new (TRUE, G_LIST_MODEL (new_store (size, size, size)), expanded, create_sub_model_cb, NULL, NULL);
tree = gtk_tree_list_model_new (G_LIST_MODEL (new_store (size, size, size)), TRUE, expanded, create_sub_model_cb, NULL, NULL);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(tree), changes_quark, changes, free_changes);
g_signal_connect (tree, "items-changed", G_CALLBACK (items_changed), changes);

View File

@ -158,8 +158,8 @@ new_child_model (gpointer item,
static GListModel *
new_model (guint size)
{
return G_LIST_MODEL (gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (new_store (1, size, 1)),
return G_LIST_MODEL (gtk_tree_list_model_new (G_LIST_MODEL (new_store (1, size, 1)),
FALSE,
TRUE,
new_child_model,
NULL, NULL));
@ -179,9 +179,7 @@ test_simple (void)
sort = gtk_sort_list_model_new (model, sorter);
assert_model (sort, "1 2 21 3 31 32 321");
g_object_unref (sorter);
g_object_unref (sort);
g_object_unref (model);
}
static GtkSorter *