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