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