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  * Conversion parameters:
26  * inFile  = gdk-Cursors.html
27  * outPack = gdk
28  * outFile = Cursor
29  * strct   = GdkCursor
30  * realStrct=
31  * ctorStrct=
32  * clss    = Cursor
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_cursor_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gdk.Pixmap
48  * 	- gdk.Color
49  * 	- gdk.Display
50  * 	- gdk.Pixbuf
51  * structWrap:
52  * 	- GdkColor* -> Color
53  * 	- GdkCursor* -> Cursor
54  * 	- GdkDisplay* -> Display
55  * 	- GdkPixbuf* -> Pixbuf
56  * 	- GdkPixmap* -> Pixmap
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gdk.Cursor;
63 
64 public  import gtkc.gdktypes;
65 
66 private import gtkc.gdk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 
71 private import glib.Str;
72 private import gdk.Pixmap;
73 private import gdk.Color;
74 private import gdk.Display;
75 private import gdk.Pixbuf;
76 
77 
78 
79 
80 /**
81  * Description
82  * These functions are used to create and destroy cursors.
83  * There is a number of standard cursors, but it is also
84  * possible to construct new cursors from pixmaps and
85  * pixbufs. There may be limitations as to what kinds of
86  * cursors can be constructed on a given display, see
87  * gdk_display_supports_cursor_alpha(),
88  * gdk_display_supports_cursor_color(),
89  * gdk_display_get_default_cursor_size() and
90  * gdk_display_get_maximal_cursor_size().
91  * Cursors by themselves are not very interesting, they must be be
92  * bound to a window for users to see them. This is done with
93  * gdk_window_set_cursor() or by setting the cursor member of the
94  * GdkWindowAttr struct passed to gdk_window_new().
95  */
96 public class Cursor
97 {
98 	
99 	/** the main Gtk struct */
100 	protected GdkCursor* gdkCursor;
101 	
102 	
103 	public GdkCursor* getCursorStruct()
104 	{
105 		return gdkCursor;
106 	}
107 	
108 	
109 	/** the main Gtk struct as a void* */
110 	protected void* getStruct()
111 	{
112 		return cast(void*)gdkCursor;
113 	}
114 	
115 	/**
116 	 * Sets our main struct and passes it to the parent class
117 	 */
118 	public this (GdkCursor* gdkCursor)
119 	{
120 		this.gdkCursor = gdkCursor;
121 	}
122 	
123 	/**
124 	 */
125 	
126 	/**
127 	 * Creates a new cursor from the set of builtin cursors for the default display.
128 	 * See gdk_cursor_new_for_display().
129 	 * To make the cursor invisible, use GDK_BLANK_CURSOR.
130 	 * Params:
131 	 * cursorType = cursor to create
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this (GdkCursorType cursorType)
135 	{
136 		// GdkCursor * gdk_cursor_new (GdkCursorType cursor_type);
137 		auto p = gdk_cursor_new(cursorType);
138 		if(p is null)
139 		{
140 			throw new ConstructionException("null returned by gdk_cursor_new(cursorType)");
141 		}
142 		this(cast(GdkCursor*) p);
143 	}
144 	
145 	/**
146 	 * Creates a new cursor from a given pixmap and mask. Both the pixmap and mask
147 	 * must have a depth of 1 (i.e. each pixel has only 2 values - on or off).
148 	 * The standard cursor size is 16 by 16 pixels. You can create a bitmap
149 	 * from inline data as in the below example.
150 	 * $(DDOC_COMMENT example)
151 	 * Params:
152 	 * source = the pixmap specifying the cursor.
153 	 * mask = the pixmap specifying the mask, which must be the same size as
154 	 * source.
155 	 * fg = the foreground color, used for the bits in the source which are 1.
156 	 * The color does not have to be allocated first.
157 	 * bg = the background color, used for the bits in the source which are 0.
158 	 * The color does not have to be allocated first.
159 	 * x = the horizontal offset of the 'hotspot' of the cursor.
160 	 * y = the vertical offset of the 'hotspot' of the cursor.
161 	 * Throws: ConstructionException GTK+ fails to create the object.
162 	 */
163 	public this (Pixmap source, Pixmap mask, Color fg, Color bg, int x, int y)
164 	{
165 		// GdkCursor * gdk_cursor_new_from_pixmap (GdkPixmap *source,  GdkPixmap *mask,  const GdkColor *fg,  const GdkColor *bg,  gint x,  gint y);
166 		auto p = gdk_cursor_new_from_pixmap((source is null) ? null : source.getPixmapStruct(), (mask is null) ? null : mask.getPixmapStruct(), (fg is null) ? null : fg.getColorStruct(), (bg is null) ? null : bg.getColorStruct(), x, y);
167 		if(p is null)
168 		{
169 			throw new ConstructionException("null returned by gdk_cursor_new_from_pixmap((source is null) ? null : source.getPixmapStruct(), (mask is null) ? null : mask.getPixmapStruct(), (fg is null) ? null : fg.getColorStruct(), (bg is null) ? null : bg.getColorStruct(), x, y)");
170 		}
171 		this(cast(GdkCursor*) p);
172 	}
173 	
174 	/**
175 	 * Creates a new cursor from a pixbuf.
176 	 * Not all GDK backends support RGBA cursors. If they are not
177 	 * supported, a monochrome approximation will be displayed.
178 	 * The functions gdk_display_supports_cursor_alpha() and
179 	 * gdk_display_supports_cursor_color() can be used to determine
180 	 * whether RGBA cursors are supported;
181 	 * gdk_display_get_default_cursor_size() and
182 	 * gdk_display_get_maximal_cursor_size() give information about
183 	 * cursor sizes.
184 	 * If x or y are -1, the pixbuf must have
185 	 * options named "x_hot" and "y_hot", resp., containing
186 	 * integer values between 0 and the width resp. height of
187 	 * the pixbuf. (Since: 3.0)
188 	 * On the X backend, support for RGBA cursors requires a
189 	 * sufficently new version of the X Render extension.
190 	 * Since 2.4
191 	 * Params:
192 	 * display = the GdkDisplay for which the cursor will be created
193 	 * pixbuf = the GdkPixbuf containing the cursor image
194 	 * x = the horizontal offset of the 'hotspot' of the cursor.
195 	 * y = the vertical offset of the 'hotspot' of the cursor.
196 	 * Throws: ConstructionException GTK+ fails to create the object.
197 	 */
198 	public this (Display display, Pixbuf pixbuf, int x, int y)
199 	{
200 		// GdkCursor * gdk_cursor_new_from_pixbuf (GdkDisplay *display,  GdkPixbuf *pixbuf,  gint x,  gint y);
201 		auto p = gdk_cursor_new_from_pixbuf((display is null) ? null : display.getDisplayStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), x, y);
202 		if(p is null)
203 		{
204 			throw new ConstructionException("null returned by gdk_cursor_new_from_pixbuf((display is null) ? null : display.getDisplayStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), x, y)");
205 		}
206 		this(cast(GdkCursor*) p);
207 	}
208 	
209 	/**
210 	 * Creates a new cursor by looking up name in the current cursor
211 	 * theme.
212 	 * Since 2.8
213 	 * Params:
214 	 * display = the GdkDisplay for which the cursor will be created
215 	 * name = the name of the cursor
216 	 * Throws: ConstructionException GTK+ fails to create the object.
217 	 */
218 	public this (Display display, string name)
219 	{
220 		// GdkCursor * gdk_cursor_new_from_name (GdkDisplay *display,  const gchar *name);
221 		auto p = gdk_cursor_new_from_name((display is null) ? null : display.getDisplayStruct(), Str.toStringz(name));
222 		if(p is null)
223 		{
224 			throw new ConstructionException("null returned by gdk_cursor_new_from_name((display is null) ? null : display.getDisplayStruct(), Str.toStringz(name))");
225 		}
226 		this(cast(GdkCursor*) p);
227 	}
228 	
229 	/**
230 	 * Creates a new cursor from the set of builtin cursors.
231 	 * Since 2.2
232 	 * Params:
233 	 * display = the GdkDisplay for which the cursor will be created
234 	 * cursorType = cursor to create
235 	 * Throws: ConstructionException GTK+ fails to create the object.
236 	 */
237 	public this (Display display, GdkCursorType cursorType)
238 	{
239 		// GdkCursor * gdk_cursor_new_for_display (GdkDisplay *display,  GdkCursorType cursor_type);
240 		auto p = gdk_cursor_new_for_display((display is null) ? null : display.getDisplayStruct(), cursorType);
241 		if(p is null)
242 		{
243 			throw new ConstructionException("null returned by gdk_cursor_new_for_display((display is null) ? null : display.getDisplayStruct(), cursorType)");
244 		}
245 		this(cast(GdkCursor*) p);
246 	}
247 	
248 	/**
249 	 * Returns the display on which the GdkCursor is defined.
250 	 * Since 2.2
251 	 * Returns: the GdkDisplay associated to cursor
252 	 */
253 	public Display getDisplay()
254 	{
255 		// GdkDisplay * gdk_cursor_get_display (GdkCursor *cursor);
256 		auto p = gdk_cursor_get_display(gdkCursor);
257 		
258 		if(p is null)
259 		{
260 			return null;
261 		}
262 		
263 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
264 	}
265 	
266 	/**
267 	 * Returns a GdkPixbuf with the image used to display the cursor.
268 	 * Note that depending on the capabilities of the windowing system and
269 	 * on the cursor, GDK may not be able to obtain the image data. In this
270 	 * case, NULL is returned.
271 	 * Since 2.8
272 	 * Returns: a GdkPixbuf representing cursor, or NULL
273 	 */
274 	public Pixbuf getImage()
275 	{
276 		// GdkPixbuf * gdk_cursor_get_image (GdkCursor *cursor);
277 		auto p = gdk_cursor_get_image(gdkCursor);
278 		
279 		if(p is null)
280 		{
281 			return null;
282 		}
283 		
284 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
285 	}
286 	
287 	/**
288 	 * Returns the cursor type for this cursor.
289 	 * Since 2.22
290 	 * Returns: a GdkCursorType
291 	 */
292 	public GdkCursorType getCursorType()
293 	{
294 		// GdkCursorType gdk_cursor_get_cursor_type (GdkCursor *cursor);
295 		return gdk_cursor_get_cursor_type(gdkCursor);
296 	}
297 	
298 	/**
299 	 * Adds a reference to cursor.
300 	 * Returns: Same cursor that was passed in. [transfer full]
301 	 */
302 	public Cursor doref()
303 	{
304 		// GdkCursor * gdk_cursor_ref (GdkCursor *cursor);
305 		auto p = gdk_cursor_ref(gdkCursor);
306 		
307 		if(p is null)
308 		{
309 			return null;
310 		}
311 		
312 		return ObjectG.getDObject!(Cursor)(cast(GdkCursor*) p);
313 	}
314 	
315 	/**
316 	 * Removes a reference from cursor, deallocating the cursor
317 	 * if no references remain.
318 	 */
319 	public void unref()
320 	{
321 		// void gdk_cursor_unref (GdkCursor *cursor);
322 		gdk_cursor_unref(gdkCursor);
323 	}
324 }