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.SingleSelection;
26 
27 private import gio.ListModelIF;
28 private import gio.ListModelT;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gtk.SelectionModelIF;
32 private import gtk.SelectionModelT;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 
36 
37 /**
38  * `GtkSingleSelection` is a `GtkSelectionModel` that allows selecting a single
39  * item.
40  * 
41  * Note that the selection is *persistent* -- if the selected item is removed
42  * and re-added in the same ::items-changed emission, it stays selected.
43  * In particular, this means that changing the sort order of an underlying sort
44  * model will preserve the selection.
45  */
46 public class SingleSelection : ObjectG, ListModelIF, SelectionModelIF
47 {
48 	/** the main Gtk struct */
49 	protected GtkSingleSelection* gtkSingleSelection;
50 
51 	/** Get the main Gtk struct */
52 	public GtkSingleSelection* getSingleSelectionStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return gtkSingleSelection;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected override void* getStruct()
61 	{
62 		return cast(void*)gtkSingleSelection;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GtkSingleSelection* gtkSingleSelection, bool ownedRef = false)
69 	{
70 		this.gtkSingleSelection = gtkSingleSelection;
71 		super(cast(GObject*)gtkSingleSelection, ownedRef);
72 	}
73 
74 	// add the ListModel capabilities
75 	mixin ListModelT!(GtkSingleSelection);
76 
77 	// add the SelectionModel capabilities
78 	mixin SelectionModelT!(GtkSingleSelection);
79 
80 
81 	/** */
82 	public static GType getType()
83 	{
84 		return gtk_single_selection_get_type();
85 	}
86 
87 	/**
88 	 * Creates a new selection to handle @model.
89 	 *
90 	 * Params:
91 	 *     model = the `GListModel` to manage, or %NULL
92 	 *
93 	 * Returns: a new `GtkSingleSelection`
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(ListModelIF model)
98 	{
99 		auto __p = gtk_single_selection_new((model is null) ? null : model.getListModelStruct());
100 
101 		if(__p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 
106 		this(cast(GtkSingleSelection*) __p, true);
107 	}
108 
109 	/**
110 	 * Checks if autoselect has been enabled or disabled via
111 	 * gtk_single_selection_set_autoselect().
112 	 *
113 	 * Returns: %TRUE if autoselect is enabled
114 	 */
115 	public bool getAutoselect()
116 	{
117 		return gtk_single_selection_get_autoselect(gtkSingleSelection) != 0;
118 	}
119 
120 	/**
121 	 * If %TRUE, gtk_selection_model_unselect_item() is supported and allows
122 	 * unselecting the selected item.
123 	 *
124 	 * Returns: %TRUE to support unselecting
125 	 */
126 	public bool getCanUnselect()
127 	{
128 		return gtk_single_selection_get_can_unselect(gtkSingleSelection) != 0;
129 	}
130 
131 	/**
132 	 * Gets the model that @self is wrapping.
133 	 *
134 	 * Returns: The model being wrapped
135 	 */
136 	public ListModelIF getModel()
137 	{
138 		auto __p = gtk_single_selection_get_model(gtkSingleSelection);
139 
140 		if(__p is null)
141 		{
142 			return null;
143 		}
144 
145 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
146 	}
147 
148 	/**
149 	 * Gets the position of the selected item.
150 	 *
151 	 * If no item is selected, %GTK_INVALID_LIST_POSITION is returned.
152 	 *
153 	 * Returns: The position of the selected item
154 	 */
155 	public uint getSelected()
156 	{
157 		return gtk_single_selection_get_selected(gtkSingleSelection);
158 	}
159 
160 	/**
161 	 * Gets the selected item.
162 	 *
163 	 * If no item is selected, %NULL is returned.
164 	 *
165 	 * Returns: The selected item
166 	 */
167 	public ObjectG getSelectedItem()
168 	{
169 		auto __p = gtk_single_selection_get_selected_item(gtkSingleSelection);
170 
171 		if(__p is null)
172 		{
173 			return null;
174 		}
175 
176 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p);
177 	}
178 
179 	/**
180 	 * Enables or disables autoselect.
181 	 *
182 	 * If @autoselect is %TRUE, @self will enforce that an item is always
183 	 * selected. It will select a new item when the currently selected
184 	 * item is deleted and it will disallow unselecting the current item.
185 	 *
186 	 * Params:
187 	 *     autoselect = %TRUE to always select an item
188 	 */
189 	public void setAutoselect(bool autoselect)
190 	{
191 		gtk_single_selection_set_autoselect(gtkSingleSelection, autoselect);
192 	}
193 
194 	/**
195 	 * If %TRUE, unselecting the current item via
196 	 * gtk_selection_model_unselect_item() is supported.
197 	 *
198 	 * Note that setting [property@Gtk.SingleSelection:autoselect] will
199 	 * cause unselecting to not work, so it practically makes no sense
200 	 * to set both at the same time the same time.
201 	 *
202 	 * Params:
203 	 *     canUnselect = %TRUE to allow unselecting
204 	 */
205 	public void setCanUnselect(bool canUnselect)
206 	{
207 		gtk_single_selection_set_can_unselect(gtkSingleSelection, canUnselect);
208 	}
209 
210 	/**
211 	 * Sets the model that @self should wrap.
212 	 *
213 	 * If @model is %NULL, @self will be empty.
214 	 *
215 	 * Params:
216 	 *     model = A `GListModel` to wrap
217 	 */
218 	public void setModel(ListModelIF model)
219 	{
220 		gtk_single_selection_set_model(gtkSingleSelection, (model is null) ? null : model.getListModelStruct());
221 	}
222 
223 	/**
224 	 * Selects the item at the given position.
225 	 *
226 	 * If the list does not have an item at @position or
227 	 * %GTK_INVALID_LIST_POSITION is given, the behavior depends on the
228 	 * value of the [property@Gtk.SingleSelection:autoselect] property:
229 	 * If it is set, no change will occur and the old item will stay
230 	 * selected. If it is unset, the selection will be unset and no item
231 	 * will be selected.
232 	 *
233 	 * Params:
234 	 *     position = the item to select or %GTK_INVALID_LIST_POSITION
235 	 */
236 	public void setSelected(uint position)
237 	{
238 		gtk_single_selection_set_selected(gtkSingleSelection, position);
239 	}
240 }