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