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