1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.ListView;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.ListBase;
31 private import gtk.ListItemFactory;
32 private import gtk.SelectionModelIF;
33 private import gtk.Widget;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 private import std.algorithm;
37 
38 
39 /**
40  * `GtkListView` presents a large dynamic list of items.
41  * 
42  * `GtkListView` uses its factory to generate one row widget for each visible
43  * item and shows them in a linear display, either vertically or horizontally.
44  * 
45  * The [property@Gtk.ListView:show-separators] property offers a simple way to
46  * display separators between the rows.
47  * 
48  * `GtkListView` allows the user to select items according to the selection
49  * characteristics of the model. For models that allow multiple selected items,
50  * it is possible to turn on _rubberband selection_, using
51  * [property@Gtk.ListView:enable-rubberband].
52  * 
53  * If you need multiple columns with headers, see [class@Gtk.ColumnView].
54  * 
55  * To learn more about the list widget framework, see the
56  * [overview](section-list-widget.html).
57  * 
58  * An example of using `GtkListView`:
59  * ```c
60  * static void
61  * setup_listitem_cb (GtkListItemFactory *factory,
62  * GtkListItem        *list_item)
63  * {
64  * GtkWidget *image;
65  * 
66  * image = gtk_image_new ();
67  * gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
68  * gtk_list_item_set_child (list_item, image);
69  * }
70  * 
71  * static void
72  * bind_listitem_cb (GtkListItemFactory *factory,
73  * GtkListItem        *list_item)
74  * {
75  * GtkWidget *image;
76  * GAppInfo *app_info;
77  * 
78  * image = gtk_list_item_get_child (list_item);
79  * app_info = gtk_list_item_get_item (list_item);
80  * gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
81  * }
82  * 
83  * static void
84  * activate_cb (GtkListView  *list,
85  * guint         position,
86  * gpointer      unused)
87  * {
88  * GAppInfo *app_info;
89  * 
90  * app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
91  * g_app_info_launch (app_info, NULL, NULL, NULL);
92  * g_object_unref (app_info);
93  * }
94  * 
95  * ...
96  * 
97  * model = create_application_list ();
98  * 
99  * factory = gtk_signal_list_item_factory_new ();
100  * g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
101  * g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
102  * 
103  * list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
104  * 
105  * g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
106  * 
107  * gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
108  * ```
109  * 
110  * # CSS nodes
111  * 
112  * ```
113  * listview[.separators][.rich-list][.navigation-sidebar][.data-table]
114  * ├── row
115  * │
116  * ├── row
117  * │
118  * ┊
119  * ╰── [rubberband]
120  * ```
121  * 
122  * `GtkListView` uses a single CSS node named listview. It may carry the
123  * .separators style class, when `GtkListView`:show-separators property
124  * is set. Each child widget uses a single CSS node named row. For
125  * rubberband selection, a node with name rubberband is used.
126  * 
127  * The main listview node may also carry style classes to select
128  * the style of [list presentation](ListContainers.html#list-styles):
129  * .rich-list, .navigation-sidebar or .data-table.
130  * 
131  * # Accessibility
132  * 
133  * `GtkListView` uses the %GTK_ACCESSIBLE_ROLE_LIST role, and the list
134  * items use the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
135  */
136 public class ListView : ListBase
137 {
138 	/** the main Gtk struct */
139 	protected GtkListView* gtkListView;
140 
141 	/** Get the main Gtk struct */
142 	public GtkListView* getListViewStruct(bool transferOwnership = false)
143 	{
144 		if (transferOwnership)
145 			ownedRef = false;
146 		return gtkListView;
147 	}
148 
149 	/** the main Gtk struct as a void* */
150 	protected override void* getStruct()
151 	{
152 		return cast(void*)gtkListView;
153 	}
154 
155 	/**
156 	 * Sets our main struct and passes it to the parent class.
157 	 */
158 	public this (GtkListView* gtkListView, bool ownedRef = false)
159 	{
160 		this.gtkListView = gtkListView;
161 		super(cast(GtkListBase*)gtkListView, ownedRef);
162 	}
163 
164 
165 	/** */
166 	public static GType getType()
167 	{
168 		return gtk_list_view_get_type();
169 	}
170 
171 	/**
172 	 * Creates a new `GtkListView` that uses the given @factory for
173 	 * mapping items to widgets.
174 	 *
175 	 * The function takes ownership of the
176 	 * arguments, so you can write code like
177 	 * ```c
178 	 * list_view = gtk_list_view_new (create_model (),
179 	 * gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
180 	 * ```
181 	 *
182 	 * Params:
183 	 *     model = the model to use, or %NULL
184 	 *     factory = The factory to populate items with, or %NULL
185 	 *
186 	 * Returns: a new `GtkListView` using the given @model and @factory
187 	 *
188 	 * Throws: ConstructionException GTK+ fails to create the object.
189 	 */
190 	public this(SelectionModelIF model, ListItemFactory factory)
191 	{
192 		auto __p = gtk_list_view_new((model is null) ? null : model.getSelectionModelStruct(), (factory is null) ? null : factory.getListItemFactoryStruct());
193 
194 		if(__p is null)
195 		{
196 			throw new ConstructionException("null returned by new");
197 		}
198 
199 		this(cast(GtkListView*) __p);
200 	}
201 
202 	/**
203 	 * Returns whether rows can be selected by dragging with the mouse.
204 	 *
205 	 * Returns: %TRUE if rubberband selection is enabled
206 	 */
207 	public bool getEnableRubberband()
208 	{
209 		return gtk_list_view_get_enable_rubberband(gtkListView) != 0;
210 	}
211 
212 	/**
213 	 * Gets the factory that's currently used to populate list items.
214 	 *
215 	 * Returns: The factory in use
216 	 */
217 	public ListItemFactory getFactory()
218 	{
219 		auto __p = gtk_list_view_get_factory(gtkListView);
220 
221 		if(__p is null)
222 		{
223 			return null;
224 		}
225 
226 		return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p);
227 	}
228 
229 	/**
230 	 * Gets the model that's currently used to read the items displayed.
231 	 *
232 	 * Returns: The model in use
233 	 */
234 	public SelectionModelIF getModel()
235 	{
236 		auto __p = gtk_list_view_get_model(gtkListView);
237 
238 		if(__p is null)
239 		{
240 			return null;
241 		}
242 
243 		return ObjectG.getDObject!(SelectionModelIF)(cast(GtkSelectionModel*) __p);
244 	}
245 
246 	/**
247 	 * Returns whether the list box should show separators
248 	 * between rows.
249 	 *
250 	 * Returns: %TRUE if the list box shows separators
251 	 */
252 	public bool getShowSeparators()
253 	{
254 		return gtk_list_view_get_show_separators(gtkListView) != 0;
255 	}
256 
257 	/**
258 	 * Returns whether rows will be activated on single click and
259 	 * selected on hover.
260 	 *
261 	 * Returns: %TRUE if rows are activated on single click
262 	 */
263 	public bool getSingleClickActivate()
264 	{
265 		return gtk_list_view_get_single_click_activate(gtkListView) != 0;
266 	}
267 
268 	/**
269 	 * Sets whether selections can be changed by dragging with the mouse.
270 	 *
271 	 * Params:
272 	 *     enableRubberband = %TRUE to enable rubberband selection
273 	 */
274 	public void setEnableRubberband(bool enableRubberband)
275 	{
276 		gtk_list_view_set_enable_rubberband(gtkListView, enableRubberband);
277 	}
278 
279 	/**
280 	 * Sets the `GtkListItemFactory` to use for populating list items.
281 	 *
282 	 * Params:
283 	 *     factory = the factory to use or %NULL for none
284 	 */
285 	public void setFactory(ListItemFactory factory)
286 	{
287 		gtk_list_view_set_factory(gtkListView, (factory is null) ? null : factory.getListItemFactoryStruct());
288 	}
289 
290 	/**
291 	 * Sets the model to use.
292 	 *
293 	 * This must be a [iface@Gtk.SelectionModel] to use.
294 	 *
295 	 * Params:
296 	 *     model = the model to use or %NULL for none
297 	 */
298 	public void setModel(SelectionModelIF model)
299 	{
300 		gtk_list_view_set_model(gtkListView, (model is null) ? null : model.getSelectionModelStruct());
301 	}
302 
303 	/**
304 	 * Sets whether the list box should show separators
305 	 * between rows.
306 	 *
307 	 * Params:
308 	 *     showSeparators = %TRUE to show separators
309 	 */
310 	public void setShowSeparators(bool showSeparators)
311 	{
312 		gtk_list_view_set_show_separators(gtkListView, showSeparators);
313 	}
314 
315 	/**
316 	 * Sets whether rows should be activated on single click and
317 	 * selected on hover.
318 	 *
319 	 * Params:
320 	 *     singleClickActivate = %TRUE to activate items on single click
321 	 */
322 	public void setSingleClickActivate(bool singleClickActivate)
323 	{
324 		gtk_list_view_set_single_click_activate(gtkListView, singleClickActivate);
325 	}
326 
327 	/**
328 	 * Emitted when a row has been activated by the user,
329 	 * usually via activating the GtkListView|list.activate-item action.
330 	 *
331 	 * This allows for a convenient way to handle activation in a listview.
332 	 * See [method@Gtk.ListItem.set_activatable] for details on how to use
333 	 * this signal.
334 	 *
335 	 * Params:
336 	 *     position = position of item to activate
337 	 */
338 	gulong addOnActivate(void delegate(uint, ListView) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
339 	{
340 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
341 	}
342 }