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 atk.ComponentT;
26 
27 public  import atk.ObjectAtk;
28 public  import gobject.ObjectG;
29 public  import gobject.Signals;
30 public  import gtkc.atk;
31 public  import gtkc.atktypes;
32 public  import gtkc.gdktypes;
33 public  import std.algorithm;
34 
35 
36 /**
37  * #AtkComponent should be implemented by most if not all UI elements
38  * with an actual on-screen presence, i.e. components which can be
39  * said to have a screen-coordinate bounding box.  Virtually all
40  * widgets will need to have #AtkComponent implementations provided
41  * for their corresponding #AtkObject class.  In short, only UI
42  * elements which are *not* GUI elements will omit this ATK interface.
43  * 
44  * A possible exception might be textual information with a
45  * transparent background, in which case text glyph bounding box
46  * information is provided by #AtkText.
47  */
48 public template ComponentT(TStruct)
49 {
50 	/** Get the main Gtk struct */
51 	public AtkComponent* getComponentStruct()
52 	{
53 		return cast(AtkComponent*)getStruct();
54 	}
55 
56 
57 	/**
58 	 * Add the specified handler to the set of functions to be called
59 	 * when this object receives focus events (in or out). If the handler is
60 	 * already added it is not added again
61 	 *
62 	 * Deprecated: If you need to track when an object gains or
63 	 * lose the focus, use the #AtkObject::state-change "focused" notification instead.
64 	 *
65 	 * Params:
66 	 *     handler = The #AtkFocusHandler to be attached to @component
67 	 *
68 	 * Return: a handler id which can be used in atk_component_remove_focus_handler()
69 	 *     or zero if the handler was already added.
70 	 */
71 	public uint addFocusHandler(AtkFocusHandler handler)
72 	{
73 		return atk_component_add_focus_handler(getComponentStruct(), handler);
74 	}
75 
76 	/**
77 	 * Checks whether the specified point is within the extent of the @component.
78 	 *
79 	 * Toolkit implementor note: ATK provides a default implementation for
80 	 * this virtual method. In general there are little reason to
81 	 * re-implement it.
82 	 *
83 	 * Params:
84 	 *     x = x coordinate
85 	 *     y = y coordinate
86 	 *     coordType = specifies whether the coordinates are relative to the screen
87 	 *         or to the components top level window
88 	 *
89 	 * Return: %TRUE or %FALSE indicating whether the specified point is within
90 	 *     the extent of the @component or not
91 	 */
92 	public bool contains(int x, int y, AtkCoordType coordType)
93 	{
94 		return atk_component_contains(getComponentStruct(), x, y, coordType) != 0;
95 	}
96 
97 	/**
98 	 * Returns the alpha value (i.e. the opacity) for this
99 	 * @component, on a scale from 0 (fully transparent) to 1.0
100 	 * (fully opaque).
101 	 *
102 	 * Return: An alpha value from 0 to 1.0, inclusive.
103 	 *
104 	 * Since: 1.12
105 	 */
106 	public double getAlpha()
107 	{
108 		return atk_component_get_alpha(getComponentStruct());
109 	}
110 
111 	/**
112 	 * Gets the rectangle which gives the extent of the @component.
113 	 *
114 	 * Params:
115 	 *     x = address of #gint to put x coordinate
116 	 *     y = address of #gint to put y coordinate
117 	 *     width = address of #gint to put width
118 	 *     height = address of #gint to put height
119 	 *     coordType = specifies whether the coordinates are relative to the screen
120 	 *         or to the components top level window
121 	 */
122 	public void getExtents(out int x, out int y, out int width, out int height, AtkCoordType coordType)
123 	{
124 		atk_component_get_extents(getComponentStruct(), &x, &y, &width, &height, coordType);
125 	}
126 
127 	/**
128 	 * Gets the layer of the component.
129 	 *
130 	 * Return: an #AtkLayer which is the layer of the component
131 	 */
132 	public override AtkLayer getLayer()
133 	{
134 		return atk_component_get_layer(getComponentStruct());
135 	}
136 
137 	/**
138 	 * Gets the zorder of the component. The value G_MININT will be returned
139 	 * if the layer of the component is not ATK_LAYER_MDI or ATK_LAYER_WINDOW.
140 	 *
141 	 * Return: a gint which is the zorder of the component, i.e. the depth at
142 	 *     which the component is shown in relation to other components in the same
143 	 *     container.
144 	 */
145 	public override int getMdiZorder()
146 	{
147 		return atk_component_get_mdi_zorder(getComponentStruct());
148 	}
149 
150 	/**
151 	 * Gets the position of @component in the form of
152 	 * a point specifying @component's top-left corner.
153 	 *
154 	 * Deprecated: Since 2.12. Use atk_component_get_extents() instead.
155 	 *
156 	 * Params:
157 	 *     x = address of #gint to put x coordinate position
158 	 *     y = address of #gint to put y coordinate position
159 	 *     coordType = specifies whether the coordinates are relative to the screen
160 	 *         or to the components top level window
161 	 */
162 	public void getPosition(out int x, out int y, AtkCoordType coordType)
163 	{
164 		atk_component_get_position(getComponentStruct(), &x, &y, coordType);
165 	}
166 
167 	/**
168 	 * Gets the size of the @component in terms of width and height.
169 	 *
170 	 * Deprecated: Since 2.12. Use atk_component_get_extents() instead.
171 	 *
172 	 * Params:
173 	 *     width = address of #gint to put width of @component
174 	 *     height = address of #gint to put height of @component
175 	 */
176 	public void getSize(out int width, out int height)
177 	{
178 		atk_component_get_size(getComponentStruct(), &width, &height);
179 	}
180 
181 	/**
182 	 * Grabs focus for this @component.
183 	 *
184 	 * Return: %TRUE if successful, %FALSE otherwise.
185 	 */
186 	public bool grabFocus()
187 	{
188 		return atk_component_grab_focus(getComponentStruct()) != 0;
189 	}
190 
191 	/**
192 	 * Gets a reference to the accessible child, if one exists, at the
193 	 * coordinate point specified by @x and @y.
194 	 *
195 	 * Params:
196 	 *     x = x coordinate
197 	 *     y = y coordinate
198 	 *     coordType = specifies whether the coordinates are relative to the screen
199 	 *         or to the components top level window
200 	 *
201 	 * Return: a reference to the accessible
202 	 *     child, if one exists
203 	 */
204 	public ObjectAtk refAccessibleAtPoint(int x, int y, AtkCoordType coordType)
205 	{
206 		auto p = atk_component_ref_accessible_at_point(getComponentStruct(), x, y, coordType);
207 		
208 		if(p is null)
209 		{
210 			return null;
211 		}
212 		
213 		return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) p, true);
214 	}
215 
216 	/**
217 	 * Remove the handler specified by @handler_id from the list of
218 	 * functions to be executed when this object receives focus events
219 	 * (in or out).
220 	 *
221 	 * Deprecated: If you need to track when an object gains or
222 	 * lose the focus, use the #AtkObject::state-change "focused" notification instead.
223 	 *
224 	 * Params:
225 	 *     handlerId = the handler id of the focus handler to be removed
226 	 *         from @component
227 	 */
228 	public void removeFocusHandler(uint handlerId)
229 	{
230 		atk_component_remove_focus_handler(getComponentStruct(), handlerId);
231 	}
232 
233 	/**
234 	 * Sets the extents of @component.
235 	 *
236 	 * Params:
237 	 *     x = x coordinate
238 	 *     y = y coordinate
239 	 *     width = width to set for @component
240 	 *     height = height to set for @component
241 	 *     coordType = specifies whether the coordinates are relative to the screen
242 	 *         or to the components top level window
243 	 *
244 	 * Return: %TRUE or %FALSE whether the extents were set or not
245 	 */
246 	public bool setExtents(int x, int y, int width, int height, AtkCoordType coordType)
247 	{
248 		return atk_component_set_extents(getComponentStruct(), x, y, width, height, coordType) != 0;
249 	}
250 
251 	/**
252 	 * Sets the postition of @component.
253 	 *
254 	 * Params:
255 	 *     x = x coordinate
256 	 *     y = y coordinate
257 	 *     coordType = specifies whether the coordinates are relative to the screen
258 	 *         or to the components top level window
259 	 *
260 	 * Return: %TRUE or %FALSE whether or not the position was set or not
261 	 */
262 	public bool setPosition(int x, int y, AtkCoordType coordType)
263 	{
264 		return atk_component_set_position(getComponentStruct(), x, y, coordType) != 0;
265 	}
266 
267 	/**
268 	 * Set the size of the @component in terms of width and height.
269 	 *
270 	 * Params:
271 	 *     width = width to set for @component
272 	 *     height = height to set for @component
273 	 *
274 	 * Return: %TRUE or %FALSE whether the size was set or not
275 	 */
276 	public bool setSize(int width, int height)
277 	{
278 		return atk_component_set_size(getComponentStruct(), width, height) != 0;
279 	}
280 
281 	protected class OnBoundsChangedDelegateWrapper
282 	{
283 		void delegate(AtkRectangle*, ComponentIF) dlg;
284 		gulong handlerId;
285 		ConnectFlags flags;
286 		this(void delegate(AtkRectangle*, ComponentIF) dlg, gulong handlerId, ConnectFlags flags)
287 		{
288 			this.dlg = dlg;
289 			this.handlerId = handlerId;
290 			this.flags = flags;
291 		}
292 	}
293 	protected OnBoundsChangedDelegateWrapper[] onBoundsChangedListeners;
294 
295 	/**
296 	 * The 'bounds-changed" signal is emitted when the bposition or
297 	 * size of the component changes.
298 	 *
299 	 * Params:
300 	 *     arg1 = The AtkRectangle giving the new position and size.
301 	 */
302 	gulong addOnBoundsChanged(void delegate(AtkRectangle*, ComponentIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
303 	{
304 		onBoundsChangedListeners ~= new OnBoundsChangedDelegateWrapper(dlg, 0, connectFlags);
305 		onBoundsChangedListeners[onBoundsChangedListeners.length - 1].handlerId = Signals.connectData(
306 			this,
307 			"bounds-changed",
308 			cast(GCallback)&callBackBoundsChanged,
309 			cast(void*)onBoundsChangedListeners[onBoundsChangedListeners.length - 1],
310 			cast(GClosureNotify)&callBackBoundsChangedDestroy,
311 			connectFlags);
312 		return onBoundsChangedListeners[onBoundsChangedListeners.length - 1].handlerId;
313 	}
314 	
315 	extern(C) static void callBackBoundsChanged(AtkComponent* componentStruct, AtkRectangle* arg1,OnBoundsChangedDelegateWrapper wrapper)
316 	{
317 		wrapper.dlg(arg1, wrapper.outer);
318 	}
319 	
320 	extern(C) static void callBackBoundsChangedDestroy(OnBoundsChangedDelegateWrapper wrapper, GClosure* closure)
321 	{
322 		wrapper.outer.internalRemoveOnBoundsChanged(wrapper);
323 	}
324 
325 	protected void internalRemoveOnBoundsChanged(OnBoundsChangedDelegateWrapper source)
326 	{
327 		foreach(index, wrapper; onBoundsChangedListeners)
328 		{
329 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
330 			{
331 				onBoundsChangedListeners[index] = null;
332 				onBoundsChangedListeners = std.algorithm.remove(onBoundsChangedListeners, index);
333 				break;
334 			}
335 		}
336 	}
337 	
338 }