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.ListBoxRow;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Bin;
31 private import gtk.Widget;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
36 
37 
38 /** */
39 public class ListBoxRow : Bin
40 {
41 	/** the main Gtk struct */
42 	protected GtkListBoxRow* gtkListBoxRow;
43 
44 	/** Get the main Gtk struct */
45 	public GtkListBoxRow* getListBoxRowStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return gtkListBoxRow;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected override void* getStruct()
54 	{
55 		return cast(void*)gtkListBoxRow;
56 	}
57 
58 	protected override void setStruct(GObject* obj)
59 	{
60 		gtkListBoxRow = cast(GtkListBoxRow*)obj;
61 		super.setStruct(obj);
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GtkListBoxRow* gtkListBoxRow, bool ownedRef = false)
68 	{
69 		this.gtkListBoxRow = gtkListBoxRow;
70 		super(cast(GtkBin*)gtkListBoxRow, ownedRef);
71 	}
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return gtk_list_box_row_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new #GtkListBoxRow, to be used as a child of a #GtkListBox.
82 	 *
83 	 * Returns: a new #GtkListBoxRow
84 	 *
85 	 * Since: 3.10
86 	 *
87 	 * Throws: ConstructionException GTK+ fails to create the object.
88 	 */
89 	public this()
90 	{
91 		auto p = gtk_list_box_row_new();
92 
93 		if(p is null)
94 		{
95 			throw new ConstructionException("null returned by new");
96 		}
97 
98 		this(cast(GtkListBoxRow*) p);
99 	}
100 
101 	/**
102 	 * Marks @row as changed, causing any state that depends on this
103 	 * to be updated. This affects sorting, filtering and headers.
104 	 *
105 	 * Note that calls to this method must be in sync with the data
106 	 * used for the row functions. For instance, if the list is
107 	 * mirroring some external data set, and *two* rows changed in the
108 	 * external data set then when you call gtk_list_box_row_changed()
109 	 * on the first row the sort function must only read the new data
110 	 * for the first of the two changed rows, otherwise the resorting
111 	 * of the rows will be wrong.
112 	 *
113 	 * This generally means that if you don’t fully control the data
114 	 * model you have to duplicate the data that affects the listbox
115 	 * row functions into the row widgets themselves. Another alternative
116 	 * is to call gtk_list_box_invalidate_sort() on any model change,
117 	 * but that is more expensive.
118 	 *
119 	 * Since: 3.10
120 	 */
121 	public void changed()
122 	{
123 		gtk_list_box_row_changed(gtkListBoxRow);
124 	}
125 
126 	/**
127 	 * Gets the value of the #GtkListBoxRow:activatable property
128 	 * for this row.
129 	 *
130 	 * Returns: %TRUE if the row is activatable
131 	 *
132 	 * Since: 3.14
133 	 */
134 	public bool getActivatable()
135 	{
136 		return gtk_list_box_row_get_activatable(gtkListBoxRow) != 0;
137 	}
138 
139 	/**
140 	 * Returns the current header of the @row. This can be used
141 	 * in a #GtkListBoxUpdateHeaderFunc to see if there is a header
142 	 * set already, and if so to update the state of it.
143 	 *
144 	 * Returns: the current header, or %NULL if none
145 	 *
146 	 * Since: 3.10
147 	 */
148 	public Widget getHeader()
149 	{
150 		auto p = gtk_list_box_row_get_header(gtkListBoxRow);
151 
152 		if(p is null)
153 		{
154 			return null;
155 		}
156 
157 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
158 	}
159 
160 	/**
161 	 * Gets the current index of the @row in its #GtkListBox container.
162 	 *
163 	 * Returns: the index of the @row, or -1 if the @row is not in a listbox
164 	 *
165 	 * Since: 3.10
166 	 */
167 	public int getIndex()
168 	{
169 		return gtk_list_box_row_get_index(gtkListBoxRow);
170 	}
171 
172 	/**
173 	 * Gets the value of the #GtkListBoxRow:selectable property
174 	 * for this row.
175 	 *
176 	 * Returns: %TRUE if the row is selectable
177 	 *
178 	 * Since: 3.14
179 	 */
180 	public bool getSelectable()
181 	{
182 		return gtk_list_box_row_get_selectable(gtkListBoxRow) != 0;
183 	}
184 
185 	/**
186 	 * Returns whether the child is currently selected in its
187 	 * #GtkListBox container.
188 	 *
189 	 * Returns: %TRUE if @row is selected
190 	 *
191 	 * Since: 3.14
192 	 */
193 	public bool isSelected()
194 	{
195 		return gtk_list_box_row_is_selected(gtkListBoxRow) != 0;
196 	}
197 
198 	/**
199 	 * Set the #GtkListBoxRow:activatable property for this row.
200 	 *
201 	 * Params:
202 	 *     activatable = %TRUE to mark the row as activatable
203 	 *
204 	 * Since: 3.14
205 	 */
206 	public void setActivatable(bool activatable)
207 	{
208 		gtk_list_box_row_set_activatable(gtkListBoxRow, activatable);
209 	}
210 
211 	/**
212 	 * Sets the current header of the @row. This is only allowed to be called
213 	 * from a #GtkListBoxUpdateHeaderFunc. It will replace any existing
214 	 * header in the row, and be shown in front of the row in the listbox.
215 	 *
216 	 * Params:
217 	 *     header = the header, or %NULL
218 	 *
219 	 * Since: 3.10
220 	 */
221 	public void setHeader(Widget header)
222 	{
223 		gtk_list_box_row_set_header(gtkListBoxRow, (header is null) ? null : header.getWidgetStruct());
224 	}
225 
226 	/**
227 	 * Set the #GtkListBoxRow:selectable property for this row.
228 	 *
229 	 * Params:
230 	 *     selectable = %TRUE to mark the row as selectable
231 	 *
232 	 * Since: 3.14
233 	 */
234 	public void setSelectable(bool selectable)
235 	{
236 		gtk_list_box_row_set_selectable(gtkListBoxRow, selectable);
237 	}
238 
239 	protected class OnActivateDelegateWrapper
240 	{
241 		void delegate(ListBoxRow) dlg;
242 		gulong handlerId;
243 
244 		this(void delegate(ListBoxRow) dlg)
245 		{
246 			this.dlg = dlg;
247 			onActivateListeners ~= this;
248 		}
249 
250 		void remove(OnActivateDelegateWrapper source)
251 		{
252 			foreach(index, wrapper; onActivateListeners)
253 			{
254 				if (wrapper.handlerId == source.handlerId)
255 				{
256 					onActivateListeners[index] = null;
257 					onActivateListeners = std.algorithm.remove(onActivateListeners, index);
258 					break;
259 				}
260 			}
261 		}
262 	}
263 	OnActivateDelegateWrapper[] onActivateListeners;
264 
265 	/** */
266 	gulong addOnActivate(void delegate(ListBoxRow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 	{
268 		auto wrapper = new OnActivateDelegateWrapper(dlg);
269 		wrapper.handlerId = Signals.connectData(
270 			this,
271 			"activate",
272 			cast(GCallback)&callBackActivate,
273 			cast(void*)wrapper,
274 			cast(GClosureNotify)&callBackActivateDestroy,
275 			connectFlags);
276 		return wrapper.handlerId;
277 	}
278 
279 	extern(C) static void callBackActivate(GtkListBoxRow* listboxrowStruct, OnActivateDelegateWrapper wrapper)
280 	{
281 		wrapper.dlg(wrapper.outer);
282 	}
283 
284 	extern(C) static void callBackActivateDestroy(OnActivateDelegateWrapper wrapper, GClosure* closure)
285 	{
286 		wrapper.remove(wrapper);
287 	}
288 }