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