forked from AuroraMiddleware/gtk
gridview: Revise constructors
Make both gtk_grid_view_new and gtk_grid_view_new_with_factory take a model as first argument, and make all arguments allow-none and transfer full. Update all callers.
This commit is contained in:
parent
fc22b75a06
commit
eb5c76210e
@ -462,7 +462,7 @@ do_listview_clocks (GtkWidget *do_widget)
|
||||
{
|
||||
GtkWidget *gridview, *sw;
|
||||
GtkListItemFactory *factory;
|
||||
GtkNoSelection *selection;
|
||||
GListModel *model;
|
||||
|
||||
/* This is the normal window setup code every demo does */
|
||||
window = gtk_window_new ();
|
||||
@ -484,14 +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);
|
||||
|
||||
selection = gtk_no_selection_new (create_clocks_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);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
|
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -342,23 +342,17 @@ 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 ();
|
||||
|
Loading…
Reference in New Issue
Block a user