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 gdk.Cursor;
26 
27 private import cairo.Surface;
28 private import gdk.Display;
29 private import gdkpixbuf.Pixbuf;
30 private import glib.ConstructionException;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gtkc.gdk;
34 public  import gtkc.gdktypes;
35 
36 
37 /**
38  * A #GdkCursor represents a cursor. Its contents are private.
39  */
40 public class Cursor : ObjectG
41 {
42 	/** the main Gtk struct */
43 	protected GdkCursor* gdkCursor;
44 
45 	/** Get the main Gtk struct */
46 	public GdkCursor* getCursorStruct()
47 	{
48 		return gdkCursor;
49 	}
50 
51 	/** the main Gtk struct as a void* */
52 	protected override void* getStruct()
53 	{
54 		return cast(void*)gdkCursor;
55 	}
56 
57 	protected override void setStruct(GObject* obj)
58 	{
59 		gdkCursor = cast(GdkCursor*)obj;
60 		super.setStruct(obj);
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (GdkCursor* gdkCursor, bool ownedRef = false)
67 	{
68 		this.gdkCursor = gdkCursor;
69 		super(cast(GObject*)gdkCursor, ownedRef);
70 	}
71 
72 
73 	/** */
74 	public static GType getType()
75 	{
76 		return gdk_cursor_get_type();
77 	}
78 
79 	/**
80 	 * Creates a new cursor from the set of builtin cursors for the default display.
81 	 * See gdk_cursor_new_for_display().
82 	 *
83 	 * To make the cursor invisible, use %GDK_BLANK_CURSOR.
84 	 *
85 	 * Deprecated: Use gdk_cursor_new_for_display() instead.
86 	 *
87 	 * Params:
88 	 *     cursorType = cursor to create
89 	 *
90 	 * Return: a new #GdkCursor
91 	 *
92 	 * Throws: ConstructionException GTK+ fails to create the object.
93 	 */
94 	public this(GdkCursorType cursorType)
95 	{
96 		auto p = gdk_cursor_new(cursorType);
97 		
98 		if(p is null)
99 		{
100 			throw new ConstructionException("null returned by new");
101 		}
102 		
103 		this(cast(GdkCursor*) p, true);
104 	}
105 
106 	/**
107 	 * Creates a new cursor from the set of builtin cursors.
108 	 *
109 	 * Params:
110 	 *     display = the #GdkDisplay for which the cursor will be created
111 	 *     cursorType = cursor to create
112 	 *
113 	 * Return: a new #GdkCursor
114 	 *
115 	 * Since: 2.2
116 	 *
117 	 * Throws: ConstructionException GTK+ fails to create the object.
118 	 */
119 	public this(Display display, GdkCursorType cursorType)
120 	{
121 		auto p = gdk_cursor_new_for_display((display is null) ? null : display.getDisplayStruct(), cursorType);
122 		
123 		if(p is null)
124 		{
125 			throw new ConstructionException("null returned by new_for_display");
126 		}
127 		
128 		this(cast(GdkCursor*) p, true);
129 	}
130 
131 	/**
132 	 * Creates a new cursor by looking up @name in the current cursor
133 	 * theme.
134 	 *
135 	 * A recommended set of cursor names that will work across different
136 	 * platforms can be found in the CSS specification:
137 	 * - "none"
138 	 * - ![](default_cursor.png) "default"
139 	 * - ![](help_cursor.png) "help"
140 	 * - ![](pointer_cursor.png) "pointer"
141 	 * - ![](progress_cursor.png) "progress"
142 	 * - ![](wait_cursor.png) "wait"
143 	 * - ![](cell_cursor.png) "cell"
144 	 * - ![](crosshair_cursor.png) "crosshair"
145 	 * - ![](text_cursor.png) "text"
146 	 * - ![](vertical_text_cursor.png) "vertical-text"
147 	 * - ![](alias_cursor.png) "alias"
148 	 * - ![](copy_cursor.png) "copy"
149 	 * - ![](move_cursor.png) "move"
150 	 * - ![](no_drop_cursor.png) "no-drop"
151 	 * - ![](not_allowed_cursor.png) "not-allowed"
152 	 * - ![](grab_cursor.png) "grab"
153 	 * - ![](grabbing_cursor.png) "grabbing"
154 	 * - ![](all_scroll_cursor.png) "all-scroll"
155 	 * - ![](col_resize_cursor.png) "col-resize"
156 	 * - ![](row_resize_cursor.png) "row-resize"
157 	 * - ![](n_resize_cursor.png) "n-resize"
158 	 * - ![](e_resize_cursor.png) "e-resize"
159 	 * - ![](s_resize_cursor.png) "s-resize"
160 	 * - ![](w_resize_cursor.png) "w-resize"
161 	 * - ![](ne_resize_cursor.png) "ne-resize"
162 	 * - ![](nw_resize_cursor.png) "nw-resize"
163 	 * - ![](sw_resize_cursor.png) "sw-resize"
164 	 * - ![](se_resize_cursor.png) "se-resize"
165 	 * - ![](ew_resize_cursor.png) "ew-resize"
166 	 * - ![](ns_resize_cursor.png) "ns-resize"
167 	 * - ![](nesw_resize_cursor.png) "nesw-resize"
168 	 * - ![](nwse_resize_cursor.png) "nwse-resize"
169 	 * - ![](zoom_in_cursor.png) "zoom-in"
170 	 * - ![](zoom_out_cursor.png) "zoom-out"
171 	 *
172 	 * Params:
173 	 *     display = the #GdkDisplay for which the cursor will be created
174 	 *     name = the name of the cursor
175 	 *
176 	 * Return: a new #GdkCursor, or %NULL if there is no
177 	 *     cursor with the given name
178 	 *
179 	 * Since: 2.8
180 	 *
181 	 * Throws: ConstructionException GTK+ fails to create the object.
182 	 */
183 	public this(Display display, string name)
184 	{
185 		auto p = gdk_cursor_new_from_name((display is null) ? null : display.getDisplayStruct(), Str.toStringz(name));
186 		
187 		if(p is null)
188 		{
189 			throw new ConstructionException("null returned by new_from_name");
190 		}
191 		
192 		this(cast(GdkCursor*) p, true);
193 	}
194 
195 	/**
196 	 * Creates a new cursor from a pixbuf.
197 	 *
198 	 * Not all GDK backends support RGBA cursors. If they are not
199 	 * supported, a monochrome approximation will be displayed.
200 	 * The functions gdk_display_supports_cursor_alpha() and
201 	 * gdk_display_supports_cursor_color() can be used to determine
202 	 * whether RGBA cursors are supported;
203 	 * gdk_display_get_default_cursor_size() and
204 	 * gdk_display_get_maximal_cursor_size() give information about
205 	 * cursor sizes.
206 	 *
207 	 * If @x or @y are `-1`, the pixbuf must have
208 	 * options named “x_hot” and “y_hot”, resp., containing
209 	 * integer values between `0` and the width resp. height of
210 	 * the pixbuf. (Since: 3.0)
211 	 *
212 	 * On the X backend, support for RGBA cursors requires a
213 	 * sufficently new version of the X Render extension.
214 	 *
215 	 * Params:
216 	 *     display = the #GdkDisplay for which the cursor will be created
217 	 *     pixbuf = the #GdkPixbuf containing the cursor image
218 	 *     x = the horizontal offset of the “hotspot” of the cursor.
219 	 *     y = the vertical offset of the “hotspot” of the cursor.
220 	 *
221 	 * Return: a new #GdkCursor.
222 	 *
223 	 * Since: 2.4
224 	 *
225 	 * Throws: ConstructionException GTK+ fails to create the object.
226 	 */
227 	public this(Display display, Pixbuf pixbuf, int x, int y)
228 	{
229 		auto p = gdk_cursor_new_from_pixbuf((display is null) ? null : display.getDisplayStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), x, y);
230 		
231 		if(p is null)
232 		{
233 			throw new ConstructionException("null returned by new_from_pixbuf");
234 		}
235 		
236 		this(cast(GdkCursor*) p, true);
237 	}
238 
239 	/**
240 	 * Creates a new cursor from a cairo image surface.
241 	 *
242 	 * Not all GDK backends support RGBA cursors. If they are not
243 	 * supported, a monochrome approximation will be displayed.
244 	 * The functions gdk_display_supports_cursor_alpha() and
245 	 * gdk_display_supports_cursor_color() can be used to determine
246 	 * whether RGBA cursors are supported;
247 	 * gdk_display_get_default_cursor_size() and
248 	 * gdk_display_get_maximal_cursor_size() give information about
249 	 * cursor sizes.
250 	 *
251 	 * On the X backend, support for RGBA cursors requires a
252 	 * sufficently new version of the X Render extension.
253 	 *
254 	 * Params:
255 	 *     display = the #GdkDisplay for which the cursor will be created
256 	 *     surface = the cairo image surface containing the cursor pixel data
257 	 *     x = the horizontal offset of the “hotspot” of the cursor
258 	 *     y = the vertical offset of the “hotspot” of the cursor
259 	 *
260 	 * Return: a new #GdkCursor.
261 	 *
262 	 * Since: 3.10
263 	 *
264 	 * Throws: ConstructionException GTK+ fails to create the object.
265 	 */
266 	public this(Display display, Surface surface, double x, double y)
267 	{
268 		auto p = gdk_cursor_new_from_surface((display is null) ? null : display.getDisplayStruct(), (surface is null) ? null : surface.getSurfaceStruct(), x, y);
269 		
270 		if(p is null)
271 		{
272 			throw new ConstructionException("null returned by new_from_surface");
273 		}
274 		
275 		this(cast(GdkCursor*) p, true);
276 	}
277 
278 	/**
279 	 * Returns the cursor type for this cursor.
280 	 *
281 	 * Return: a #GdkCursorType
282 	 *
283 	 * Since: 2.22
284 	 */
285 	public GdkCursorType getCursorType()
286 	{
287 		return gdk_cursor_get_cursor_type(gdkCursor);
288 	}
289 
290 	/**
291 	 * Returns the display on which the #GdkCursor is defined.
292 	 *
293 	 * Return: the #GdkDisplay associated to @cursor
294 	 *
295 	 * Since: 2.2
296 	 */
297 	public Display getDisplay()
298 	{
299 		auto p = gdk_cursor_get_display(gdkCursor);
300 		
301 		if(p is null)
302 		{
303 			return null;
304 		}
305 		
306 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
307 	}
308 
309 	/**
310 	 * Returns a #GdkPixbuf with the image used to display the cursor.
311 	 *
312 	 * Note that depending on the capabilities of the windowing system and
313 	 * on the cursor, GDK may not be able to obtain the image data. In this
314 	 * case, %NULL is returned.
315 	 *
316 	 * Return: a #GdkPixbuf representing
317 	 *     @cursor, or %NULL
318 	 *
319 	 * Since: 2.8
320 	 */
321 	public Pixbuf getImage()
322 	{
323 		auto p = gdk_cursor_get_image(gdkCursor);
324 		
325 		if(p is null)
326 		{
327 			return null;
328 		}
329 		
330 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
331 	}
332 
333 	/**
334 	 * Returns a cairo image surface with the image used to display the cursor.
335 	 *
336 	 * Note that depending on the capabilities of the windowing system and
337 	 * on the cursor, GDK may not be able to obtain the image data. In this
338 	 * case, %NULL is returned.
339 	 *
340 	 * Params:
341 	 *     xHot = Location to store the hotspot x position,
342 	 *         or %NULL
343 	 *     yHot = Location to store the hotspot y position,
344 	 *         or %NULL
345 	 *
346 	 * Return: a #cairo_surface_t
347 	 *     representing @cursor, or %NULL
348 	 *
349 	 * Since: 3.10
350 	 */
351 	public Surface getSurface(out double xHot, out double yHot)
352 	{
353 		auto p = gdk_cursor_get_surface(gdkCursor, &xHot, &yHot);
354 		
355 		if(p is null)
356 		{
357 			return null;
358 		}
359 		
360 		return new Surface(cast(cairo_surface_t*) p);
361 	}
362 
363 	/**
364 	 * Adds a reference to @cursor.
365 	 *
366 	 * Deprecated: Use g_object_ref() instead
367 	 *
368 	 * Return: Same @cursor that was passed in
369 	 */
370 	public override Cursor doref()
371 	{
372 		auto p = gdk_cursor_ref(gdkCursor);
373 		
374 		if(p is null)
375 		{
376 			return null;
377 		}
378 		
379 		return ObjectG.getDObject!(Cursor)(cast(GdkCursor*) p, true);
380 	}
381 
382 	/**
383 	 * Removes a reference from @cursor, deallocating the cursor
384 	 * if no references remain.
385 	 *
386 	 * Deprecated: Use g_object_unref() instead
387 	 */
388 	public override void unref()
389 	{
390 		gdk_cursor_unref(gdkCursor);
391 	}
392 }