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