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.ColumnView;
26 
27 private import gio.ListModelIF;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.ColumnViewColumn;
32 private import gtk.ScrollableIF;
33 private import gtk.ScrollableT;
34 private import gtk.SelectionModelIF;
35 private import gtk.Sorter;
36 private import gtk.Widget;
37 private import gtk.c.functions;
38 public  import gtk.c.types;
39 private import std.algorithm;
40 
41 
42 /**
43  * `GtkColumnView` presents a large dynamic list of items using multiple columns
44  * with headers.
45  * 
46  * `GtkColumnView` uses the factories of its columns to generate a cell widget for
47  * each column, for each visible item and displays them together as the row for
48  * this item.
49  * 
50  * The [property@Gtk.ColumnView:show-row-separators] and
51  * [propertyGtk.ColumnView:show-column-separators] properties offer a simple way
52  * to display separators between the rows or columns.
53  * 
54  * `GtkColumnView` allows the user to select items according to the selection
55  * characteristics of the model. For models that allow multiple selected items,
56  * it is possible to turn on *rubberband selection*, using
57  * [property@Gtk.ColumnView:enable-rubberband].
58  * 
59  * The column view supports sorting that can be customized by the user by
60  * clicking on column headers. To set this up, the `GtkSorter` returned by
61  * [method@Gtk.ColumnView.get_sorter] must be attached to a sort model for the
62  * data that the view is showing, and the columns must have sorters attached to
63  * them by calling [method@Gtk.ColumnViewColumn.set_sorter]. The initial sort
64  * order can be set with [method@Gtk.ColumnView.sort_by_column].
65  * 
66  * The column view also supports interactive resizing and reordering of
67  * columns, via Drag-and-Drop of the column headers. This can be enabled or
68  * disabled with the [property@Gtk.ColumnView:reorderable] and
69  * [property@Gtk.ColumnViewColumn:resizable] properties.
70  * 
71  * To learn more about the list widget framework, see the
72  * [overview](section-list-widget.html).
73  * 
74  * # CSS nodes
75  * 
76  * ```
77  * columnview[.column-separators][.rich-list][.navigation-sidebar][.data-table]
78  * ├── header
79  * │   ├── <column header>
80  * ┊   ┊
81  * │   ╰── <column header>
82  * │
83  * ├── listview
84  * │
85  * ┊
86  * ╰── [rubberband]
87  * ```
88  * 
89  * `GtkColumnView` uses a single CSS node named columnview. It may carry the
90  * .column-separators style class, when [property@Gtk.ColumnView:show-column-separators]
91  * property is set. Header widgets appear below a node with name header.
92  * The rows are contained in a `GtkListView` widget, so there is a listview
93  * node with the same structure as for a standalone `GtkListView` widget.
94  * If [property@Gtk.ColumnView:show-row-separators] is set, it will be passed
95  * on to the list view, causing its CSS node to carry the .separators style class.
96  * For rubberband selection, a node with name rubberband is used.
97  * 
98  * The main columnview node may also carry style classes to select
99  * the style of [list presentation](section-list-widget.html#list-styles):
100  * .rich-list, .navigation-sidebar or .data-table.
101  * 
102  * # Accessibility
103  * 
104  * `GtkColumnView` uses the %GTK_ACCESSIBLE_ROLE_TREE_GRID role, header title
105  * widgets are using the %GTK_ACCESSIBLE_ROLE_COLUMN_HEADER role. The row widgets
106  * are using the %GTK_ACCESSIBLE_ROLE_ROW role, and individual cells are using
107  * the %GTK_ACCESSIBLE_ROLE_GRID_CELL role
108  */
109 public class ColumnView : Widget, ScrollableIF
110 {
111 	/** the main Gtk struct */
112 	protected GtkColumnView* gtkColumnView;
113 
114 	/** Get the main Gtk struct */
115 	public GtkColumnView* getColumnViewStruct(bool transferOwnership = false)
116 	{
117 		if (transferOwnership)
118 			ownedRef = false;
119 		return gtkColumnView;
120 	}
121 
122 	/** the main Gtk struct as a void* */
123 	protected override void* getStruct()
124 	{
125 		return cast(void*)gtkColumnView;
126 	}
127 
128 	/**
129 	 * Sets our main struct and passes it to the parent class.
130 	 */
131 	public this (GtkColumnView* gtkColumnView, bool ownedRef = false)
132 	{
133 		this.gtkColumnView = gtkColumnView;
134 		super(cast(GtkWidget*)gtkColumnView, ownedRef);
135 	}
136 
137 	// add the Scrollable capabilities
138 	mixin ScrollableT!(GtkColumnView);
139 
140 
141 	/** */
142 	public static GType getType()
143 	{
144 		return gtk_column_view_get_type();
145 	}
146 
147 	/**
148 	 * Creates a new `GtkColumnView`.
149 	 *
150 	 * You most likely want to call [method@Gtk.ColumnView.append_column]
151 	 * to add columns next.
152 	 *
153 	 * Params:
154 	 *     model = the list model to use, or %NULL
155 	 *
156 	 * Returns: a new `GtkColumnView`
157 	 *
158 	 * Throws: ConstructionException GTK+ fails to create the object.
159 	 */
160 	public this(SelectionModelIF model)
161 	{
162 		auto __p = gtk_column_view_new((model is null) ? null : model.getSelectionModelStruct());
163 
164 		if(__p is null)
165 		{
166 			throw new ConstructionException("null returned by new");
167 		}
168 
169 		this(cast(GtkColumnView*) __p);
170 	}
171 
172 	/**
173 	 * Appends the @column to the end of the columns in @self.
174 	 *
175 	 * Params:
176 	 *     column = a `GtkColumnViewColumn` that hasn't been added to a
177 	 *         `GtkColumnView` yet
178 	 */
179 	public void appendColumn(ColumnViewColumn column)
180 	{
181 		gtk_column_view_append_column(gtkColumnView, (column is null) ? null : column.getColumnViewColumnStruct());
182 	}
183 
184 	/**
185 	 * Gets the list of columns in this column view.
186 	 *
187 	 * This list is constant over the lifetime of @self and can be used to
188 	 * monitor changes to the columns of @self by connecting to the
189 	 * ::items-changed signal.
190 	 *
191 	 * Returns: The list managing the columns
192 	 */
193 	public ListModelIF getColumns()
194 	{
195 		auto __p = gtk_column_view_get_columns(gtkColumnView);
196 
197 		if(__p is null)
198 		{
199 			return null;
200 		}
201 
202 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
203 	}
204 
205 	/**
206 	 * Returns whether rows can be selected by dragging with the mouse.
207 	 *
208 	 * Returns: %TRUE if rubberband selection is enabled
209 	 */
210 	public bool getEnableRubberband()
211 	{
212 		return gtk_column_view_get_enable_rubberband(gtkColumnView) != 0;
213 	}
214 
215 	/**
216 	 * Gets the model that's currently used to read the items displayed.
217 	 *
218 	 * Returns: The model in use
219 	 */
220 	public SelectionModelIF getModel()
221 	{
222 		auto __p = gtk_column_view_get_model(gtkColumnView);
223 
224 		if(__p is null)
225 		{
226 			return null;
227 		}
228 
229 		return ObjectG.getDObject!(SelectionModelIF)(cast(GtkSelectionModel*) __p);
230 	}
231 
232 	/**
233 	 * Returns whether columns are reorderable.
234 	 *
235 	 * Returns: %TRUE if columns are reorderable
236 	 */
237 	public bool getReorderable()
238 	{
239 		return gtk_column_view_get_reorderable(gtkColumnView) != 0;
240 	}
241 
242 	/**
243 	 * Returns whether the list should show separators
244 	 * between columns.
245 	 *
246 	 * Returns: %TRUE if the list shows column separators
247 	 */
248 	public bool getShowColumnSeparators()
249 	{
250 		return gtk_column_view_get_show_column_separators(gtkColumnView) != 0;
251 	}
252 
253 	/**
254 	 * Returns whether the list should show separators
255 	 * between rows.
256 	 *
257 	 * Returns: %TRUE if the list shows separators
258 	 */
259 	public bool getShowRowSeparators()
260 	{
261 		return gtk_column_view_get_show_row_separators(gtkColumnView) != 0;
262 	}
263 
264 	/**
265 	 * Returns whether rows will be activated on single click and
266 	 * selected on hover.
267 	 *
268 	 * Returns: %TRUE if rows are activated on single click
269 	 */
270 	public bool getSingleClickActivate()
271 	{
272 		return gtk_column_view_get_single_click_activate(gtkColumnView) != 0;
273 	}
274 
275 	/**
276 	 * Returns a special sorter that reflects the users sorting
277 	 * choices in the column view.
278 	 *
279 	 * To allow users to customizable sorting by clicking on column
280 	 * headers, this sorter needs to be set on the sort model underneath
281 	 * the model that is displayed by the view.
282 	 *
283 	 * See [method@Gtk.ColumnViewColumn.set_sorter] for setting up
284 	 * per-column sorting.
285 	 *
286 	 * Here is an example:
287 	 * ```c
288 	 * gtk_column_view_column_set_sorter (column, sorter);
289 	 * gtk_column_view_append_column (view, column);
290 	 * sorter = g_object_ref (gtk_column_view_get_sorter (view)));
291 	 * model = gtk_sort_list_model_new (store, sorter);
292 	 * selection = gtk_no_selection_new (model);
293 	 * gtk_column_view_set_model (view, selection);
294 	 * ```
295 	 *
296 	 * Returns: the `GtkSorter` of @self
297 	 */
298 	public Sorter getSorter()
299 	{
300 		auto __p = gtk_column_view_get_sorter(gtkColumnView);
301 
302 		if(__p is null)
303 		{
304 			return null;
305 		}
306 
307 		return ObjectG.getDObject!(Sorter)(cast(GtkSorter*) __p);
308 	}
309 
310 	/**
311 	 * Inserts a column at the given position in the columns of @self.
312 	 *
313 	 * If @column is already a column of @self, it will be repositioned.
314 	 *
315 	 * Params:
316 	 *     position = the position to insert @column at
317 	 *     column = the `GtkColumnViewColumn` to insert
318 	 */
319 	public void insertColumn(uint position, ColumnViewColumn column)
320 	{
321 		gtk_column_view_insert_column(gtkColumnView, position, (column is null) ? null : column.getColumnViewColumnStruct());
322 	}
323 
324 	/**
325 	 * Removes the @column from the list of columns of @self.
326 	 *
327 	 * Params:
328 	 *     column = a `GtkColumnViewColumn` that's part of @self
329 	 */
330 	public void removeColumn(ColumnViewColumn column)
331 	{
332 		gtk_column_view_remove_column(gtkColumnView, (column is null) ? null : column.getColumnViewColumnStruct());
333 	}
334 
335 	/**
336 	 * Sets whether selections can be changed by dragging with the mouse.
337 	 *
338 	 * Params:
339 	 *     enableRubberband = %TRUE to enable rubberband selection
340 	 */
341 	public void setEnableRubberband(bool enableRubberband)
342 	{
343 		gtk_column_view_set_enable_rubberband(gtkColumnView, enableRubberband);
344 	}
345 
346 	/**
347 	 * Sets the model to use.
348 	 *
349 	 * This must be a [iface@Gtk.SelectionModel].
350 	 *
351 	 * Params:
352 	 *     model = the model to use or %NULL for none
353 	 */
354 	public void setModel(SelectionModelIF model)
355 	{
356 		gtk_column_view_set_model(gtkColumnView, (model is null) ? null : model.getSelectionModelStruct());
357 	}
358 
359 	/**
360 	 * Sets whether columns should be reorderable by dragging.
361 	 *
362 	 * Params:
363 	 *     reorderable = whether columns should be reorderable
364 	 */
365 	public void setReorderable(bool reorderable)
366 	{
367 		gtk_column_view_set_reorderable(gtkColumnView, reorderable);
368 	}
369 
370 	/**
371 	 * Sets whether the list should show separators
372 	 * between columns.
373 	 *
374 	 * Params:
375 	 *     showColumnSeparators = %TRUE to show column separators
376 	 */
377 	public void setShowColumnSeparators(bool showColumnSeparators)
378 	{
379 		gtk_column_view_set_show_column_separators(gtkColumnView, showColumnSeparators);
380 	}
381 
382 	/**
383 	 * Sets whether the list should show separators
384 	 * between rows.
385 	 *
386 	 * Params:
387 	 *     showRowSeparators = %TRUE to show row separators
388 	 */
389 	public void setShowRowSeparators(bool showRowSeparators)
390 	{
391 		gtk_column_view_set_show_row_separators(gtkColumnView, showRowSeparators);
392 	}
393 
394 	/**
395 	 * Sets whether rows should be activated on single click and
396 	 * selected on hover.
397 	 *
398 	 * Params:
399 	 *     singleClickActivate = %TRUE to activate items on single click
400 	 */
401 	public void setSingleClickActivate(bool singleClickActivate)
402 	{
403 		gtk_column_view_set_single_click_activate(gtkColumnView, singleClickActivate);
404 	}
405 
406 	/**
407 	 * Sets the sorting of the view.
408 	 *
409 	 * This function should be used to set up the initial sorting.
410 	 * At runtime, users can change the sorting of a column view
411 	 * by clicking on the list headers.
412 	 *
413 	 * This call only has an effect if the sorter returned by
414 	 * [method@Gtk.ColumnView.get_sorter] is set on a sort model,
415 	 * and [method@Gtk.ColumnViewColumn.set_sorter] has been called
416 	 * on @column to associate a sorter with the column.
417 	 *
418 	 * If @column is %NULL, the view will be unsorted.
419 	 *
420 	 * Params:
421 	 *     column = the `GtkColumnViewColumn` to sort by, or %NULL
422 	 *     direction = the direction to sort in
423 	 */
424 	public void sortByColumn(ColumnViewColumn column, GtkSortType direction)
425 	{
426 		gtk_column_view_sort_by_column(gtkColumnView, (column is null) ? null : column.getColumnViewColumnStruct(), direction);
427 	}
428 
429 	/**
430 	 * Emitted when a row has been activated by the user, usually via activating
431 	 * the GtkListBase|list.activate-item action.
432 	 *
433 	 * This allows for a convenient way to handle activation in a columnview.
434 	 * See [method@Gtk.ListItem.set_activatable] for details on how to use this
435 	 * signal.
436 	 *
437 	 * Params:
438 	 *     position = position of item to activate
439 	 */
440 	gulong addOnActivate(void delegate(uint, ColumnView) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
441 	{
442 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
443 	}
444 }