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 
75 	public static GType getType()
76 	{
77 		return gdk_cursor_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new cursor from the set of builtin cursors for the default display.
82 	 * See gdk_cursor_new_for_display().
83 	 *
84 	 * To make the cursor invisible, use %GDK_BLANK_CURSOR.
85 	 *
86 	 * Deprecated: Use gdk_cursor_new_for_display() instead.
87 	 *
88 	 * Params:
89 	 *     cursorType = cursor to create
90 	 *
91 	 * Return: a new #GdkCursor
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(GdkCursorType cursorType)
96 	{
97 		auto p = gdk_cursor_new(cursorType);
98 		
99 		if(p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 		
104 		this(cast(GdkCursor*) p, true);
105 	}
106 
107 	/**
108 	 * Creates a new cursor from the set of builtin cursors.
109 	 * Some useful ones are:
110 	 * - ![](right_ptr.png) #GDK_RIGHT_PTR (right-facing arrow)
111 	 * - ![](crosshair.png) #GDK_CROSSHAIR (crosshair)
112 	 * - ![](xterm.png) #GDK_XTERM (I-beam)
113 	 * - ![](watch.png) #GDK_WATCH (busy)
114 	 * - ![](fleur.png) #GDK_FLEUR (for moving objects)
115 	 * - ![](hand1.png) #GDK_HAND1 (a right-pointing hand)
116 	 * - ![](hand2.png) #GDK_HAND2 (a left-pointing hand)
117 	 * - ![](left_side.png) #GDK_LEFT_SIDE (resize left side)
118 	 * - ![](right_side.png) #GDK_RIGHT_SIDE (resize right side)
119 	 * - ![](top_left_corner.png) #GDK_TOP_LEFT_CORNER (resize northwest corner)
120 	 * - ![](top_right_corner.png) #GDK_TOP_RIGHT_CORNER (resize northeast corner)
121 	 * - ![](bottom_left_corner.png) #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
122 	 * - ![](bottom_right_corner.png) #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
123 	 * - ![](top_side.png) #GDK_TOP_SIDE (resize top side)
124 	 * - ![](bottom_side.png) #GDK_BOTTOM_SIDE (resize bottom side)
125 	 * - ![](sb_h_double_arrow.png) #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
126 	 * - ![](sb_v_double_arrow.png) #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
127 	 * - #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
128 	 *
129 	 * Params:
130 	 *     display = the #GdkDisplay for which the cursor will be created
131 	 *     cursorType = cursor to create
132 	 *
133 	 * Return: a new #GdkCursor
134 	 *
135 	 * Since: 2.2
136 	 *
137 	 * Throws: ConstructionException GTK+ fails to create the object.
138 	 */
139 	public this(Display display, GdkCursorType cursorType)
140 	{
141 		auto p = gdk_cursor_new_for_display((display is null) ? null : display.getDisplayStruct(), cursorType);
142 		
143 		if(p is null)
144 		{
145 			throw new ConstructionException("null returned by new_for_display");
146 		}
147 		
148 		this(cast(GdkCursor*) p, true);
149 	}
150 
151 	/**
152 	 * Creates a new cursor by looking up @name in the current cursor
153 	 * theme.
154 	 *
155 	 * Params:
156 	 *     display = the #GdkDisplay for which the cursor will be created
157 	 *     name = the name of the cursor
158 	 *
159 	 * Return: a new #GdkCursor, or %NULL if there is no
160 	 *     cursor with the given name
161 	 *
162 	 * Since: 2.8
163 	 *
164 	 * Throws: ConstructionException GTK+ fails to create the object.
165 	 */
166 	public this(Display display, string name)
167 	{
168 		auto p = gdk_cursor_new_from_name((display is null) ? null : display.getDisplayStruct(), Str.toStringz(name));
169 		
170 		if(p is null)
171 		{
172 			throw new ConstructionException("null returned by new_from_name");
173 		}
174 		
175 		this(cast(GdkCursor*) p, true);
176 	}
177 
178 	/**
179 	 * Creates a new cursor from a pixbuf.
180 	 *
181 	 * Not all GDK backends support RGBA cursors. If they are not
182 	 * supported, a monochrome approximation will be displayed.
183 	 * The functions gdk_display_supports_cursor_alpha() and
184 	 * gdk_display_supports_cursor_color() can be used to determine
185 	 * whether RGBA cursors are supported;
186 	 * gdk_display_get_default_cursor_size() and
187 	 * gdk_display_get_maximal_cursor_size() give information about
188 	 * cursor sizes.
189 	 *
190 	 * If @x or @y are `-1`, the pixbuf must have
191 	 * options named “x_hot” and “y_hot”, resp., containing
192 	 * integer values between `0` and the width resp. height of
193 	 * the pixbuf. (Since: 3.0)
194 	 *
195 	 * On the X backend, support for RGBA cursors requires a
196 	 * sufficently new version of the X Render extension.
197 	 *
198 	 * Params:
199 	 *     display = the #GdkDisplay for which the cursor will be created
200 	 *     pixbuf = the #GdkPixbuf containing the cursor image
201 	 *     x = the horizontal offset of the “hotspot” of the cursor.
202 	 *     y = the vertical offset of the “hotspot” of the cursor.
203 	 *
204 	 * Return: a new #GdkCursor.
205 	 *
206 	 * Since: 2.4
207 	 *
208 	 * Throws: ConstructionException GTK+ fails to create the object.
209 	 */
210 	public this(Display display, Pixbuf pixbuf, int x, int y)
211 	{
212 		auto p = gdk_cursor_new_from_pixbuf((display is null) ? null : display.getDisplayStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), x, y);
213 		
214 		if(p is null)
215 		{
216 			throw new ConstructionException("null returned by new_from_pixbuf");
217 		}
218 		
219 		this(cast(GdkCursor*) p, true);
220 	}
221 
222 	/**
223 	 * Creates a new cursor from a cairo image surface.
224 	 *
225 	 * Not all GDK backends support RGBA cursors. If they are not
226 	 * supported, a monochrome approximation will be displayed.
227 	 * The functions gdk_display_supports_cursor_alpha() and
228 	 * gdk_display_supports_cursor_color() can be used to determine
229 	 * whether RGBA cursors are supported;
230 	 * gdk_display_get_default_cursor_size() and
231 	 * gdk_display_get_maximal_cursor_size() give information about
232 	 * cursor sizes.
233 	 *
234 	 * On the X backend, support for RGBA cursors requires a
235 	 * sufficently new version of the X Render extension.
236 	 *
237 	 * Params:
238 	 *     display = the #GdkDisplay for which the cursor will be created
239 	 *     surface = the cairo image surface containing the cursor pixel data
240 	 *     x = the horizontal offset of the “hotspot” of the cursor
241 	 *     y = the vertical offset of the “hotspot” of the cursor
242 	 *
243 	 * Return: a new #GdkCursor.
244 	 *
245 	 * Since: 3.10
246 	 *
247 	 * Throws: ConstructionException GTK+ fails to create the object.
248 	 */
249 	public this(Display display, Surface surface, double x, double y)
250 	{
251 		auto p = gdk_cursor_new_from_surface((display is null) ? null : display.getDisplayStruct(), (surface is null) ? null : surface.getSurfaceStruct(), x, y);
252 		
253 		if(p is null)
254 		{
255 			throw new ConstructionException("null returned by new_from_surface");
256 		}
257 		
258 		this(cast(GdkCursor*) p, true);
259 	}
260 
261 	/**
262 	 * Returns the cursor type for this cursor.
263 	 *
264 	 * Return: a #GdkCursorType
265 	 *
266 	 * Since: 2.22
267 	 */
268 	public GdkCursorType getCursorType()
269 	{
270 		return gdk_cursor_get_cursor_type(gdkCursor);
271 	}
272 
273 	/**
274 	 * Returns the display on which the #GdkCursor is defined.
275 	 *
276 	 * Return: the #GdkDisplay associated to @cursor
277 	 *
278 	 * Since: 2.2
279 	 */
280 	public Display getDisplay()
281 	{
282 		auto p = gdk_cursor_get_display(gdkCursor);
283 		
284 		if(p is null)
285 		{
286 			return null;
287 		}
288 		
289 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
290 	}
291 
292 	/**
293 	 * Returns a #GdkPixbuf with the image used to display the cursor.
294 	 *
295 	 * Note that depending on the capabilities of the windowing system and
296 	 * on the cursor, GDK may not be able to obtain the image data. In this
297 	 * case, %NULL is returned.
298 	 *
299 	 * Return: a #GdkPixbuf representing
300 	 *     @cursor, or %NULL
301 	 *
302 	 * Since: 2.8
303 	 */
304 	public Pixbuf getImage()
305 	{
306 		auto p = gdk_cursor_get_image(gdkCursor);
307 		
308 		if(p is null)
309 		{
310 			return null;
311 		}
312 		
313 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
314 	}
315 
316 	/**
317 	 * Returns a cairo image surface with the image used to display the cursor.
318 	 *
319 	 * Note that depending on the capabilities of the windowing system and
320 	 * on the cursor, GDK may not be able to obtain the image data. In this
321 	 * case, %NULL is returned.
322 	 *
323 	 * Params:
324 	 *     xHot = Location to store the hotspot x position,
325 	 *         or %NULL
326 	 *     yHot = Location to store the hotspot y position,
327 	 *         or %NULL
328 	 *
329 	 * Return: a #cairo_surface_t
330 	 *     representing @cursor, or %NULL
331 	 *
332 	 * Since: 3.10
333 	 */
334 	public Surface getSurface(out double xHot, out double yHot)
335 	{
336 		auto p = gdk_cursor_get_surface(gdkCursor, &xHot, &yHot);
337 		
338 		if(p is null)
339 		{
340 			return null;
341 		}
342 		
343 		return new Surface(cast(cairo_surface_t*) p);
344 	}
345 
346 	/**
347 	 * Adds a reference to @cursor.
348 	 *
349 	 * Deprecated: Use g_object_ref() instead
350 	 *
351 	 * Return: Same @cursor that was passed in
352 	 */
353 	public override Cursor doref()
354 	{
355 		auto p = gdk_cursor_ref(gdkCursor);
356 		
357 		if(p is null)
358 		{
359 			return null;
360 		}
361 		
362 		return ObjectG.getDObject!(Cursor)(cast(GdkCursor*) p, true);
363 	}
364 
365 	/**
366 	 * Removes a reference from @cursor, deallocating the cursor
367 	 * if no references remain.
368 	 *
369 	 * Deprecated: Use g_object_unref() instead
370 	 */
371 	public override void unref()
372 	{
373 		gdk_cursor_unref(gdkCursor);
374 	}
375 }