forked from AuroraMiddleware/gtk
listview: Expose GtkListItemFactory APIs
Due to the many different ways to set factories, it makes sense to expose them as custom objects. This makes the actual APIs for the list widgets simpler, because they can just have a regular "factory" property. As a convenience function, gtk_list_view_new_with_factory() was added to make this whole approach easy to use from C.
This commit is contained in:
parent
2ef2148fb5
commit
626c525706
@ -291,13 +291,12 @@ do_listview_weather (GtkWidget *do_widget)
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_window_set_child (GTK_WINDOW (window), sw);
|
||||
|
||||
listview = gtk_list_view_new ();
|
||||
listview = gtk_list_view_new_with_factory (
|
||||
gtk_functions_list_item_factory_new (setup_widget,
|
||||
bind_widget,
|
||||
NULL, NULL));
|
||||
gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
|
||||
gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
|
||||
gtk_list_view_set_functions (GTK_LIST_VIEW (listview),
|
||||
setup_widget,
|
||||
bind_widget,
|
||||
NULL, NULL);
|
||||
model = create_weather_model ();
|
||||
selection = G_LIST_MODEL (gtk_no_selection_new (model));
|
||||
gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
|
||||
|
@ -429,11 +429,34 @@ GTK_TYPE_LIST_ITEM_FACTORY
|
||||
gtk_list_item_factory_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkbuilderlistitemfactory</FILE>
|
||||
<TITLE>GtkBuilderListItemFactory</TITLE>
|
||||
GtkBuilderListItemFactory
|
||||
gtk_builder_list_item_factory_new_from_bytes
|
||||
gtk_builder_list_item_factory_new_from_resource
|
||||
gtk_builder_list_item_factory_get_bytes
|
||||
gtk_builder_list_item_factory_get_resource
|
||||
gtk_builder_list_item_factory_get_scope
|
||||
<SUBSECTION Standard>
|
||||
GTK_BUILDER_LIST_ITEM_FACTORY
|
||||
GTK_BUILDER_LIST_ITEM_FACTORY_CLASS
|
||||
GTK_BUILDER_LIST_ITEM_FACTORY_GET_CLASS
|
||||
GTK_IS_BUILDER_LIST_ITEM_FACTORY
|
||||
GTK_IS_BUILDER_LIST_ITEM_FACTORY_CLASS
|
||||
GTK_TYPE_BUILDER_LIST_ITEM_FACTORY
|
||||
<SUBSECTION Private>
|
||||
gtk_builder_list_item_factory_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtklistview</FILE>
|
||||
<TITLE>GtkListView</TITLE>
|
||||
GtkListView
|
||||
gtk_list_view_new
|
||||
gtk_list_view_new_with_factory
|
||||
gtk_list_view_set_factory
|
||||
gtk_list_view_get_factory
|
||||
gtk_list_view_set_model
|
||||
gtk_list_view_get_model
|
||||
gtk_list_view_set_show_separators
|
||||
|
@ -20,10 +20,11 @@ gtk_assistant_page_get_type
|
||||
gtk_bin_layout_get_type
|
||||
gtk_box_get_type
|
||||
gtk_box_layout_get_type
|
||||
gtk_buildable_get_type
|
||||
gtk_builder_cscope_get_type
|
||||
gtk_builder_get_type
|
||||
gtk_builder_list_item_factory_get_type
|
||||
gtk_builder_scope_get_type
|
||||
gtk_buildable_get_type
|
||||
gtk_button_get_type
|
||||
gtk_calendar_get_type
|
||||
gtk_cell_area_get_type
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <gtk/gtkbox.h>
|
||||
#include <gtk/gtkbuildable.h>
|
||||
#include <gtk/gtkbuilder.h>
|
||||
#include <gtk/gtkbuilderlistitemfactory.h>
|
||||
#include <gtk/gtkbuilderscope.h>
|
||||
#include <gtk/gtkbutton.h>
|
||||
#include <gtk/gtkcalendar.h>
|
||||
@ -126,6 +127,7 @@
|
||||
#include <gtk/gtkfontchooserdialog.h>
|
||||
#include <gtk/gtkfontchooserwidget.h>
|
||||
#include <gtk/gtkframe.h>
|
||||
#include <gtk/gtkfunctionslistitemfactory.h>
|
||||
#include <gtk/gtkgesture.h>
|
||||
#include <gtk/gtkgestureclick.h>
|
||||
#include <gtk/gtkgesturedrag.h>
|
||||
@ -155,6 +157,7 @@
|
||||
#include <gtk/gtklinkbutton.h>
|
||||
#include <gtk/gtklistbox.h>
|
||||
#include <gtk/gtklistitem.h>
|
||||
#include <gtk/gtklistitemfactory.h>
|
||||
#include <gtk/gtkliststore.h>
|
||||
#include <gtk/gtklistview.h>
|
||||
#include <gtk/gtklockbutton.h>
|
||||
|
@ -19,11 +19,41 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkbuilderlistitemfactoryprivate.h"
|
||||
#include "gtkbuilderlistitemfactory.h"
|
||||
|
||||
#include "gtkbuilder.h"
|
||||
#include "gtklistitemfactoryprivate.h"
|
||||
#include "gtklistitemprivate.h"
|
||||
|
||||
/**
|
||||
* SECTION:gtkbuilderlistitemfactory
|
||||
* @Tiitle: GtkBuilderListItemFactory
|
||||
* @Short_description: A listitem factory using ui files
|
||||
*
|
||||
* #GtkBuilderListItemFactory is a #GtkListItemFactory that creates
|
||||
* widgets by instantiating #GtkBuilder UI templates. The templates
|
||||
* must be extending #GtkListItem, and typically use #GtkExpressions
|
||||
* to obtain data from the items in the model.
|
||||
*
|
||||
* Example:
|
||||
* |[
|
||||
* <interface>
|
||||
* <template class="GtkListItem">
|
||||
* <property name="child">
|
||||
* <object class="GtkLabel">
|
||||
* <property name="xalign">0</property>
|
||||
* <binding name="label">
|
||||
* <lookup name="name" type="SettingsKey">
|
||||
* <lookup name="item">GtkListItem</lookup>
|
||||
* </lookup>
|
||||
* </binding>
|
||||
* </object>
|
||||
* </property>
|
||||
* </template>
|
||||
* </interface>
|
||||
* ]|
|
||||
*/
|
||||
|
||||
struct _GtkBuilderListItemFactory
|
||||
{
|
||||
GtkListItemFactory parent_instance;
|
||||
@ -96,6 +126,15 @@ gtk_builder_list_item_factory_init (GtkBuilderListItemFactory *self)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_builder_list_item_factory_new_from_bytes:
|
||||
* @bytes: the bytes containing the ui file to instantiate
|
||||
*
|
||||
* Creates s new #GtkBuilderListItemFactory that instantiates widgets
|
||||
* using @bytes as the data to pass to #GtkBuilder.
|
||||
*
|
||||
* Returns: a new #GtkBuilderListItemFactory
|
||||
**/
|
||||
GtkListItemFactory *
|
||||
gtk_builder_list_item_factory_new_from_bytes (GBytes *bytes)
|
||||
{
|
||||
@ -110,6 +149,15 @@ gtk_builder_list_item_factory_new_from_bytes (GBytes *bytes)
|
||||
return GTK_LIST_ITEM_FACTORY (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_builder_list_item_factory_new_from_resource:
|
||||
* @resource_path: valid path to a resource that contains the data
|
||||
*
|
||||
* Creates s new #GtkBuilderListItemFactory that instantiates widgets
|
||||
* using data read from the given @resource_path to pass to #GtkBuilder.
|
||||
*
|
||||
* Returns: a new #GtkBuilderListItemFactory
|
||||
**/
|
||||
GtkListItemFactory *
|
||||
gtk_builder_list_item_factory_new_from_resource (const char *resource_path)
|
||||
{
|
||||
|
@ -17,11 +17,14 @@
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GTK_BUILDER_LIST_ITEM_FACTORY_H__
|
||||
#define __GTK_BUILDER_LIST_ITEM_FACTORY_H__
|
||||
|
||||
#include "gtklistitemfactoryprivate.h"
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtklistitemfactory.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -35,9 +38,12 @@ G_BEGIN_DECLS
|
||||
typedef struct _GtkBuilderListItemFactory GtkBuilderListItemFactory;
|
||||
typedef struct _GtkBuilderListItemFactoryClass GtkBuilderListItemFactoryClass;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_builder_list_item_factory_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkListItemFactory * gtk_builder_list_item_factory_new_from_bytes (GBytes *bytes);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkListItemFactory * gtk_builder_list_item_factory_new_from_resource (const char *resource_path);
|
||||
|
||||
|
@ -19,8 +19,9 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkfunctionslistitemfactoryprivate.h"
|
||||
#include "gtkfunctionslistitemfactory.h"
|
||||
|
||||
#include "gtklistitemfactoryprivate.h"
|
||||
#include "gtklistitemprivate.h"
|
||||
|
||||
struct _GtkFunctionsListItemFactory
|
||||
|
@ -17,11 +17,15 @@
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GTK_FUNCTIONS_LIST_ITEM_FACTORY_H__
|
||||
#define __GTK_FUNCTIONS_LIST_ITEM_FACTORY_H__
|
||||
|
||||
#include "gtklistitemfactoryprivate.h"
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtklistitemfactory.h>
|
||||
#include <gtk/gtklistitem.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -35,8 +39,38 @@ G_BEGIN_DECLS
|
||||
typedef struct _GtkFunctionsListItemFactory GtkFunctionsListItemFactory;
|
||||
typedef struct _GtkFunctionsListItemFactoryClass GtkFunctionsListItemFactoryClass;
|
||||
|
||||
/**
|
||||
* GtkListItemSetupFunc:
|
||||
* @item: the #GtkListItem to set up
|
||||
* @user_data: (closure): user data
|
||||
*
|
||||
* Called whenever a new list item needs to be setup for managing a row in
|
||||
* the list.
|
||||
*
|
||||
* At this point, the list item is not bound yet, so gtk_list_item_get_item()
|
||||
* will return %NULL.
|
||||
* The list item will later be bound to an item via the #GtkListItemBindFunc.
|
||||
*/
|
||||
typedef void (* GtkListItemSetupFunc) (GtkListItem *item, gpointer user_data);
|
||||
|
||||
/**
|
||||
* GtkListItemBindFunc:
|
||||
* @item: the #GtkListItem to bind
|
||||
* @user_data: (closure): user data
|
||||
*
|
||||
* Binds a#GtkListItem previously set up via a #GtkListItemSetupFunc to
|
||||
* an @item.
|
||||
*
|
||||
* Rebinding a @item to different @items is supported as well as
|
||||
* unbinding it by setting @item to %NULL.
|
||||
*/
|
||||
typedef void (* GtkListItemBindFunc) (GtkListItem *item,
|
||||
gpointer user_data);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_functions_list_item_factory_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkListItemFactory * gtk_functions_list_item_factory_new (GtkListItemSetupFunc setup_func,
|
||||
GtkListItemBindFunc bind_func,
|
||||
gpointer user_data,
|
@ -41,34 +41,6 @@ typedef struct _GtkListItemClass GtkListItemClass;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_list_item_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/**
|
||||
* GtkListItemSetupFunc:
|
||||
* @item: the #GtkListItem to set up
|
||||
* @user_data: (closure): user data
|
||||
*
|
||||
* Called whenever a new list item needs to be setup for managing a row in
|
||||
* the list.
|
||||
*
|
||||
* At this point, the list item is not bound yet, so gtk_list_item_get_item()
|
||||
* will return %NULL.
|
||||
* The list item will later be bound to an item via the #GtkListItemBindFunc.
|
||||
*/
|
||||
typedef void (* GtkListItemSetupFunc) (GtkListItem *item, gpointer user_data);
|
||||
|
||||
/**
|
||||
* GtkListItemBindFunc:
|
||||
* @item: the #GtkListItem to bind
|
||||
* @user_data: (closure): user data
|
||||
*
|
||||
* Binds a#GtkListItem previously set up via a #GtkListItemSetupFunc to
|
||||
* an @item.
|
||||
*
|
||||
* Rebinding a @item to different @items is supported as well as
|
||||
* unbinding it by setting @item to %NULL.
|
||||
*/
|
||||
typedef void (* GtkListItemBindFunc) (GtkListItem *item,
|
||||
gpointer user_data);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gpointer gtk_list_item_get_item (GtkListItem *self);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
48
gtk/gtklistitemfactory.h
Normal file
48
gtk/gtklistitemfactory.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright © 2019 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_LIST_ITEM_FACTORY_H__
|
||||
#define __GTK_LIST_ITEM_FACTORY_H__
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
typedef struct _GtkListItemFactoryClass GtkListItemFactoryClass;
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_LIST_ITEM_FACTORY (gtk_list_item_factory_get_type ())
|
||||
#define GTK_LIST_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LIST_ITEM_FACTORY, GtkListItemFactory))
|
||||
#define GTK_LIST_ITEM_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_LIST_ITEM_FACTORY, GtkListItemFactoryClass))
|
||||
#define GTK_IS_LIST_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LIST_ITEM_FACTORY))
|
||||
#define GTK_IS_LIST_ITEM_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_LIST_ITEM_FACTORY))
|
||||
#define GTK_LIST_ITEM_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_LIST_ITEM_FACTORY, GtkListItemFactoryClass))
|
||||
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_list_item_factory_get_type (void) G_GNUC_CONST;
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_LIST_ITEM_FACTORY_H__ */
|
@ -18,24 +18,15 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GTK_LIST_ITEM_FACTORY_H__
|
||||
#define __GTK_LIST_ITEM_FACTORY_H__
|
||||
#ifndef __GTK_LIST_ITEM_FACTORY_PRIVATE_H__
|
||||
#define __GTK_LIST_ITEM_FACTORY_PRIVATE_H__
|
||||
|
||||
#include <gtk/gtklistitem.h>
|
||||
#include <gtk/gtklistitemfactory.h>
|
||||
#include <gtk/gtklistview.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_LIST_ITEM_FACTORY (gtk_list_item_factory_get_type ())
|
||||
#define GTK_LIST_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LIST_ITEM_FACTORY, GtkListItemFactory))
|
||||
#define GTK_LIST_ITEM_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_LIST_ITEM_FACTORY, GtkListItemFactoryClass))
|
||||
#define GTK_IS_LIST_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LIST_ITEM_FACTORY))
|
||||
#define GTK_IS_LIST_ITEM_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_LIST_ITEM_FACTORY))
|
||||
#define GTK_LIST_ITEM_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_LIST_ITEM_FACTORY, GtkListItemFactoryClass))
|
||||
|
||||
typedef struct _GtkListItemFactory GtkListItemFactory;
|
||||
typedef struct _GtkListItemFactoryClass GtkListItemFactoryClass;
|
||||
|
||||
struct _GtkListItemFactory
|
||||
{
|
||||
GObject parent_instance;
|
||||
@ -74,8 +65,6 @@ struct _GtkListItemFactoryClass
|
||||
GtkListItem *list_item);
|
||||
};
|
||||
|
||||
GType gtk_list_item_factory_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gtk_list_item_factory_setup (GtkListItemFactory *self,
|
||||
GtkListItem *list_item);
|
||||
void gtk_list_item_factory_teardown (GtkListItemFactory *self,
|
||||
@ -101,4 +90,4 @@ void gtk_list_item_factory_unbind (GtkListItemFact
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_LIST_ITEM_FACTORY_H__ */
|
||||
#endif /* __GTK_LIST_ITEM_FACTORY_PRIVATE_H__ */
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include "gtklistview.h"
|
||||
|
||||
#include "gtkadjustment.h"
|
||||
#include "gtkbuilderlistitemfactoryprivate.h"
|
||||
#include "gtkfunctionslistitemfactoryprivate.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtklistitemmanagerprivate.h"
|
||||
#include "gtkorientableprivate.h"
|
||||
@ -91,6 +89,7 @@ struct _ListRowAugment
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_FACTORY,
|
||||
PROP_HADJUSTMENT,
|
||||
PROP_HSCROLL_POLICY,
|
||||
PROP_MODEL,
|
||||
@ -636,6 +635,10 @@ gtk_list_view_get_property (GObject *object,
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_FACTORY:
|
||||
g_value_set_object (value, gtk_list_item_manager_get_factory (self->item_manager));
|
||||
break;
|
||||
|
||||
case PROP_HADJUSTMENT:
|
||||
g_value_set_object (value, self->adjustment[GTK_ORIENTATION_HORIZONTAL]);
|
||||
break;
|
||||
@ -721,6 +724,10 @@ gtk_list_view_set_property (GObject *object,
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_FACTORY:
|
||||
gtk_list_view_set_factory (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_HADJUSTMENT:
|
||||
gtk_list_view_set_adjustment (self, GTK_ORIENTATION_HORIZONTAL, g_value_get_object (value));
|
||||
break;
|
||||
@ -912,6 +919,18 @@ gtk_list_view_class_init (GtkListViewClass *klass)
|
||||
g_param_spec_override ("vscroll-policy",
|
||||
g_object_interface_find_property (iface, "vscroll-policy"));
|
||||
|
||||
/**
|
||||
* GtkListView:factory:
|
||||
*
|
||||
* Factory for populating list items
|
||||
*/
|
||||
properties[PROP_FACTORY] =
|
||||
g_param_spec_object ("factory",
|
||||
P_("Factory"),
|
||||
P_("Factory for populating list items"),
|
||||
GTK_TYPE_LIST_ITEM_FACTORY,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* GtkListView:model:
|
||||
*
|
||||
@ -1009,8 +1028,9 @@ gtk_list_view_init (GtkListView *self)
|
||||
*
|
||||
* Creates a new empty #GtkListView.
|
||||
*
|
||||
* You most likely want to call gtk_list_view_set_model() to set
|
||||
* a model and then set up a way to map its items to widgets next.
|
||||
* 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.
|
||||
*
|
||||
* Returns: a new #GtkListView
|
||||
**/
|
||||
@ -1020,6 +1040,41 @@ gtk_list_view_new (void)
|
||||
return g_object_new (GTK_TYPE_LIST_VIEW, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_list_view_new_with_factory:
|
||||
* @factory: (transfer full): The factory to populate items with
|
||||
*
|
||||
* 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"));
|
||||
* ```
|
||||
*
|
||||
* Returns: a new #GtkListView using the given @factory
|
||||
**/
|
||||
GtkWidget *
|
||||
gtk_list_view_new_with_factory (GtkListItemFactory *factory)
|
||||
{
|
||||
GtkWidget *result;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
|
||||
|
||||
result = g_object_new (GTK_TYPE_LIST_VIEW,
|
||||
"factory", factory,
|
||||
NULL);
|
||||
|
||||
g_object_unref (factory);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_list_view_get_model:
|
||||
* @self: a #GtkListView
|
||||
@ -1082,50 +1137,42 @@ gtk_list_view_set_model (GtkListView *self,
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_view_set_functions (GtkListView *self,
|
||||
GtkListItemSetupFunc setup_func,
|
||||
GtkListItemBindFunc bind_func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify user_destroy)
|
||||
/**
|
||||
* gtk_list_view_get_factory:
|
||||
* @self: a #GtkListView
|
||||
*
|
||||
* Gets the factory that's currently used to populate list items.
|
||||
*
|
||||
* Returns: (nullable) (transfer none): The factory in use
|
||||
**/
|
||||
GtkListItemFactory *
|
||||
gtk_list_view_get_factory (GtkListView *self)
|
||||
{
|
||||
GtkListItemFactory *factory;
|
||||
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), NULL);
|
||||
|
||||
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
||||
g_return_if_fail (setup_func || bind_func);
|
||||
g_return_if_fail (user_data != NULL || user_destroy == NULL);
|
||||
|
||||
factory = gtk_functions_list_item_factory_new (setup_func, bind_func, user_data, user_destroy);
|
||||
gtk_list_item_manager_set_factory (self->item_manager, factory);
|
||||
g_object_unref (factory);
|
||||
return gtk_list_item_manager_get_factory (self->item_manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_list_view_set_factory:
|
||||
* @self: a #GtkListView
|
||||
* @factory: (allow-none) (transfer none): the factory to use or %NULL for none
|
||||
*
|
||||
* Sets the #GtkListItemFactory to use for populating list items.
|
||||
**/
|
||||
void
|
||||
gtk_list_view_set_factory_from_bytes (GtkListView *self,
|
||||
GBytes *bytes)
|
||||
gtk_list_view_set_factory (GtkListView *self,
|
||||
GtkListItemFactory *factory)
|
||||
{
|
||||
GtkListItemFactory *factory;
|
||||
|
||||
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
||||
g_return_if_fail (bytes != NULL);
|
||||
g_return_if_fail (factory == NULL || GTK_LIST_ITEM_FACTORY (factory));
|
||||
|
||||
if (factory == gtk_list_item_manager_get_factory (self->item_manager))
|
||||
return;
|
||||
|
||||
factory = gtk_builder_list_item_factory_new_from_bytes (bytes);
|
||||
gtk_list_item_manager_set_factory (self->item_manager, factory);
|
||||
g_object_unref (factory);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_list_view_set_factory_from_resource (GtkListView *self,
|
||||
const char *resource_path)
|
||||
{
|
||||
GtkListItemFactory *factory;
|
||||
|
||||
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
||||
g_return_if_fail (resource_path != NULL);
|
||||
|
||||
factory = gtk_builder_list_item_factory_new_from_resource (resource_path);
|
||||
gtk_list_item_manager_set_factory (self->item_manager, factory);
|
||||
g_object_unref (factory);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FACTORY]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,8 @@ G_DECLARE_FINAL_TYPE (GtkListView, gtk_list_view, GTK, LIST_VIEW, GtkWidget)
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_list_view_new (void);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_list_view_new_with_factory (GtkListItemFactory *factory);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GListModel * gtk_list_view_get_model (GtkListView *self);
|
||||
@ -43,17 +45,11 @@ GDK_AVAILABLE_IN_ALL
|
||||
void gtk_list_view_set_model (GtkListView *self,
|
||||
GListModel *model);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_list_view_set_functions (GtkListView *self,
|
||||
GtkListItemSetupFunc setup_func,
|
||||
GtkListItemBindFunc bind_func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify user_destroy);
|
||||
void gtk_list_view_set_factory (GtkListView *self,
|
||||
GtkListItemFactory *factory);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_list_view_set_factory_from_bytes (GtkListView *self,
|
||||
GBytes *bytes);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_list_view_set_factory_from_resource (GtkListView *self,
|
||||
const char *resource_path);
|
||||
GtkListItemFactory *
|
||||
gtk_list_view_get_factory (GtkListView *self);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_list_view_set_show_separators (GtkListView *self,
|
||||
|
@ -41,6 +41,7 @@ typedef struct _GtkCssStyleChange GtkCssStyleChange;
|
||||
typedef struct _GtkEventController GtkEventController;
|
||||
typedef struct _GtkGesture GtkGesture;
|
||||
typedef struct _GtkLayoutManager GtkLayoutManager;
|
||||
typedef struct _GtkListItemFactory GtkListItemFactory;
|
||||
typedef struct _GtkNative GtkNative;
|
||||
typedef struct _GtkRequisition GtkRequisition;
|
||||
typedef struct _GtkRoot GtkRoot;
|
||||
|
@ -438,6 +438,7 @@ gtk_public_headers = files([
|
||||
'gtkboxlayout.h',
|
||||
'gtkbuildable.h',
|
||||
'gtkbuilder.h',
|
||||
'gtkbuilderlistitemfactory.h',
|
||||
'gtkbuilderscope.h',
|
||||
'gtkbutton.h',
|
||||
'gtkcalendar.h',
|
||||
@ -513,6 +514,7 @@ gtk_public_headers = files([
|
||||
'gtkfontchooserdialog.h',
|
||||
'gtkfontchooserwidget.h',
|
||||
'gtkframe.h',
|
||||
'gtkfunctionslistitemfactory.h',
|
||||
'gtkgesture.h',
|
||||
'gtkgesturedrag.h',
|
||||
'gtkgesturelongpress.h',
|
||||
@ -543,6 +545,7 @@ gtk_public_headers = files([
|
||||
'gtklinkbutton.h',
|
||||
'gtklistbox.h',
|
||||
'gtklistitem.h',
|
||||
'gtklistitemfactory.h',
|
||||
'gtkliststore.h',
|
||||
'gtklistview.h',
|
||||
'gtklockbutton.h',
|
||||
|
@ -145,11 +145,10 @@ main (int argc,
|
||||
gtk_widget_set_vexpand (sw, TRUE);
|
||||
gtk_box_append (GTK_BOX (vbox), sw);
|
||||
|
||||
listview = gtk_list_view_new ();
|
||||
gtk_list_view_set_functions (GTK_LIST_VIEW (listview),
|
||||
setup_list_item,
|
||||
bind_list_item,
|
||||
NULL, NULL);
|
||||
listview = gtk_list_view_new_with_factory (
|
||||
gtk_functions_list_item_factory_new (setup_list_item,
|
||||
bind_list_item,
|
||||
NULL, NULL));
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
|
||||
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
||||
|
@ -566,6 +566,7 @@ update_statusbar (GtkStatusbar *statusbar)
|
||||
g_string_append_printf (string, " (%u directories remaining)", active + g_slist_length (pending));
|
||||
result = G_SOURCE_CONTINUE;
|
||||
}
|
||||
result = G_SOURCE_CONTINUE;
|
||||
|
||||
gtk_statusbar_push (statusbar, 0, string->str);
|
||||
g_free (string->str);
|
||||
@ -627,11 +628,10 @@ main (int argc, char *argv[])
|
||||
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (search_entry), sw);
|
||||
gtk_box_append (GTK_BOX (vbox), sw);
|
||||
|
||||
listview = gtk_list_view_new ();
|
||||
gtk_list_view_set_functions (GTK_LIST_VIEW (listview),
|
||||
setup_widget,
|
||||
NULL,
|
||||
NULL, NULL);
|
||||
listview = gtk_list_view_new_with_factory (
|
||||
gtk_functions_list_item_factory_new (setup_widget,
|
||||
NULL,
|
||||
NULL, NULL));
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
|
||||
|
||||
if (argc > 1)
|
||||
|
Loading…
Reference in New Issue
Block a user