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.FlowBoxChild;
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 FlowBoxChild : Bin
40 {
41 	/** the main Gtk struct */
42 	protected GtkFlowBoxChild* gtkFlowBoxChild;
43 
44 	/** Get the main Gtk struct */
45 	public GtkFlowBoxChild* getFlowBoxChildStruct()
46 	{
47 		return gtkFlowBoxChild;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected override void* getStruct()
52 	{
53 		return cast(void*)gtkFlowBoxChild;
54 	}
55 
56 	protected override void setStruct(GObject* obj)
57 	{
58 		gtkFlowBoxChild = cast(GtkFlowBoxChild*)obj;
59 		super.setStruct(obj);
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GtkFlowBoxChild* gtkFlowBoxChild, bool ownedRef = false)
66 	{
67 		this.gtkFlowBoxChild = gtkFlowBoxChild;
68 		super(cast(GtkBin*)gtkFlowBoxChild, ownedRef);
69 	}
70 
71 
72 	/** */
73 	public static GType getType()
74 	{
75 		return gtk_flow_box_child_get_type();
76 	}
77 
78 	/**
79 	 * Creates a new #GtkFlowBoxChild, to be used as a child
80 	 * of a #GtkFlowBox.
81 	 *
82 	 * Return: a new #GtkFlowBoxChild
83 	 *
84 	 * Since: 3.12
85 	 *
86 	 * Throws: ConstructionException GTK+ fails to create the object.
87 	 */
88 	public this()
89 	{
90 		auto p = gtk_flow_box_child_new();
91 		
92 		if(p is null)
93 		{
94 			throw new ConstructionException("null returned by new");
95 		}
96 		
97 		this(cast(GtkFlowBoxChild*) p);
98 	}
99 
100 	/**
101 	 * Marks @child as changed, causing any state that depends on this
102 	 * to be updated. This affects sorting and filtering.
103 	 *
104 	 * Note that calls to this method must be in sync with the data
105 	 * used for the sorting and filtering functions. For instance, if
106 	 * the list is mirroring some external data set, and *two* children
107 	 * changed in the external data set when you call
108 	 * gtk_flow_box_child_changed() on the first child, the sort function
109 	 * must only read the new data for the first of the two changed
110 	 * children, otherwise the resorting of the children will be wrong.
111 	 *
112 	 * This generally means that if you don’t fully control the data
113 	 * model, you have to duplicate the data that affects the sorting
114 	 * and filtering functions into the widgets themselves. Another
115 	 * alternative is to call gtk_flow_box_invalidate_sort() on any
116 	 * model change, but that is more expensive.
117 	 *
118 	 * Since: 3.12
119 	 */
120 	public void changed()
121 	{
122 		gtk_flow_box_child_changed(gtkFlowBoxChild);
123 	}
124 
125 	/**
126 	 * Gets the current index of the @child in its #GtkFlowBox container.
127 	 *
128 	 * Return: the index of the @child, or -1 if the @child is not
129 	 *     in a flow box.
130 	 *
131 	 * Since: 3.12
132 	 */
133 	public int getIndex()
134 	{
135 		return gtk_flow_box_child_get_index(gtkFlowBoxChild);
136 	}
137 
138 	/**
139 	 * Returns whether the @child is currently selected in its
140 	 * #GtkFlowBox container.
141 	 *
142 	 * Return: %TRUE if @child is selected
143 	 *
144 	 * Since: 3.12
145 	 */
146 	public bool isSelected()
147 	{
148 		return gtk_flow_box_child_is_selected(gtkFlowBoxChild) != 0;
149 	}
150 
151 	protected class OnActivateDelegateWrapper
152 	{
153 		void delegate(FlowBoxChild) dlg;
154 		gulong handlerId;
155 		ConnectFlags flags;
156 		this(void delegate(FlowBoxChild) dlg, gulong handlerId, ConnectFlags flags)
157 		{
158 			this.dlg = dlg;
159 			this.handlerId = handlerId;
160 			this.flags = flags;
161 		}
162 	}
163 	protected OnActivateDelegateWrapper[] onActivateListeners;
164 
165 	/**
166 	 * The ::activate signal is emitted when the user activates
167 	 * a child widget in a #GtkFlowBox, either by clicking or
168 	 * double-clicking, or by using the Space or Enter key.
169 	 *
170 	 * While this signal is used as a
171 	 * [keybinding signal][GtkBindingSignal],
172 	 * it can be used by applications for their own purposes.
173 	 */
174 	gulong addOnActivate(void delegate(FlowBoxChild) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
175 	{
176 		onActivateListeners ~= new OnActivateDelegateWrapper(dlg, 0, connectFlags);
177 		onActivateListeners[onActivateListeners.length - 1].handlerId = Signals.connectData(
178 			this,
179 			"activate",
180 			cast(GCallback)&callBackActivate,
181 			cast(void*)onActivateListeners[onActivateListeners.length - 1],
182 			cast(GClosureNotify)&callBackActivateDestroy,
183 			connectFlags);
184 		return onActivateListeners[onActivateListeners.length - 1].handlerId;
185 	}
186 	
187 	extern(C) static void callBackActivate(GtkFlowBoxChild* flowboxchildStruct,OnActivateDelegateWrapper wrapper)
188 	{
189 		wrapper.dlg(wrapper.outer);
190 	}
191 	
192 	extern(C) static void callBackActivateDestroy(OnActivateDelegateWrapper wrapper, GClosure* closure)
193 	{
194 		wrapper.outer.internalRemoveOnActivate(wrapper);
195 	}
196 
197 	protected void internalRemoveOnActivate(OnActivateDelegateWrapper source)
198 	{
199 		foreach(index, wrapper; onActivateListeners)
200 		{
201 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
202 			{
203 				onActivateListeners[index] = null;
204 				onActivateListeners = std.algorithm.remove(onActivateListeners, index);
205 				break;
206 			}
207 		}
208 	}
209 	
210 }