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 gdk.Texture;
28 private import gdk.c.functions;
29 public  import gdk.c.types;
30 private import glib.ConstructionException;
31 private import glib.Str;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 
35 
36 /**
37  * `GdkCursor` is used to create and destroy cursors.
38  * 
39  * Cursors are immutable objects, so once you created them, there is no way
40  * to modify them later. You should create a new cursor when you want to change
41  * something about it.
42  * 
43  * Cursors by themselves are not very interesting: they must be bound to a
44  * window for users to see them. This is done with [method@Gdk.Surface.set_cursor]
45  * or [method@Gdk.Surface.set_device_cursor]. Applications will typically
46  * use higher-level GTK functions such as [method@Gtk.Widget.set_cursor]`
47  * instead.
48  * 
49  * Cursors are not bound to a given [class@Gdk.Display], so they can be shared.
50  * However, the appearance of cursors may vary when used on different
51  * platforms.
52  * 
53  * ## Named and texture cursors
54  * 
55  * There are multiple ways to create cursors. The platform's own cursors
56  * can be created with [ctor@Gdk.Cursor.new_from_name]. That function lists
57  * the commonly available names that are shared with the CSS specification.
58  * Other names may be available, depending on the platform in use. On some
59  * platforms, what images are used for named cursors may be influenced by
60  * the cursor theme.
61  * 
62  * Another option to create a cursor is to use [ctor@Gdk.Cursor.new_from_texture]
63  * and provide an image to use for the cursor.
64  * 
65  * To ease work with unsupported cursors, a fallback cursor can be provided.
66  * If a [class@Gdk.Surface] cannot use a cursor because of the reasons mentioned
67  * above, it will try the fallback cursor. Fallback cursors can themselves have
68  * fallback cursors again, so it is possible to provide a chain of progressively
69  * easier to support cursors. If none of the provided cursors can be supported,
70  * the default cursor will be the ultimate fallback.
71  */
72 public class Cursor : ObjectG
73 {
74 	/** the main Gtk struct */
75 	protected GdkCursor* gdkCursor;
76 
77 	/** Get the main Gtk struct */
78 	public GdkCursor* getCursorStruct(bool transferOwnership = false)
79 	{
80 		if (transferOwnership)
81 			ownedRef = false;
82 		return gdkCursor;
83 	}
84 
85 	/** the main Gtk struct as a void* */
86 	protected override void* getStruct()
87 	{
88 		return cast(void*)gdkCursor;
89 	}
90 
91 	/**
92 	 * Sets our main struct and passes it to the parent class.
93 	 */
94 	public this (GdkCursor* gdkCursor, bool ownedRef = false)
95 	{
96 		this.gdkCursor = gdkCursor;
97 		super(cast(GObject*)gdkCursor, ownedRef);
98 	}
99 
100 
101 	/** */
102 	public static GType getType()
103 	{
104 		return gdk_cursor_get_type();
105 	}
106 
107 	/**
108 	 * Creates a new cursor by looking up @name in the current cursor
109 	 * theme.
110 	 *
111 	 * A recommended set of cursor names that will work across different
112 	 * platforms can be found in the CSS specification:
113 	 *
114 	 * | | | | |
115 	 * | --- | --- | ---- | --- |
116 	 * | "none" | ![](default_cursor.png) "default" | ![](help_cursor.png) "help" | ![](pointer_cursor.png) "pointer" |
117 	 * | ![](context_menu_cursor.png) "context-menu" | ![](progress_cursor.png) "progress" | ![](wait_cursor.png) "wait" | ![](cell_cursor.png) "cell" |
118 	 * | ![](crosshair_cursor.png) "crosshair" | ![](text_cursor.png) "text" | ![](vertical_text_cursor.png) "vertical-text" | ![](alias_cursor.png) "alias" |
119 	 * | ![](copy_cursor.png) "copy" | ![](no_drop_cursor.png) "no-drop" | ![](move_cursor.png) "move" | ![](not_allowed_cursor.png) "not-allowed" |
120 	 * | ![](grab_cursor.png) "grab" | ![](grabbing_cursor.png) "grabbing" | ![](all_scroll_cursor.png) "all-scroll" | ![](col_resize_cursor.png) "col-resize" |
121 	 * | ![](row_resize_cursor.png) "row-resize" | ![](n_resize_cursor.png) "n-resize" | ![](e_resize_cursor.png) "e-resize" | ![](s_resize_cursor.png) "s-resize" |
122 	 * | ![](w_resize_cursor.png) "w-resize" | ![](ne_resize_cursor.png) "ne-resize" | ![](nw_resize_cursor.png) "nw-resize" | ![](sw_resize_cursor.png) "sw-resize" |
123 	 * | ![](se_resize_cursor.png) "se-resize" | ![](ew_resize_cursor.png) "ew-resize" | ![](ns_resize_cursor.png) "ns-resize" | ![](nesw_resize_cursor.png) "nesw-resize" |
124 	 * | ![](nwse_resize_cursor.png) "nwse-resize" | ![](zoom_in_cursor.png) "zoom-in" | ![](zoom_out_cursor.png) "zoom-out" | |
125 	 *
126 	 * Params:
127 	 *     name = the name of the cursor
128 	 *     fallback = %NULL or the `GdkCursor` to fall back to when
129 	 *         this one cannot be supported
130 	 *
131 	 * Returns: a new `GdkCursor`, or %NULL if there is no
132 	 *     cursor with the given name
133 	 *
134 	 * Throws: ConstructionException GTK+ fails to create the object.
135 	 */
136 	public this(string name, Cursor fallback)
137 	{
138 		auto __p = gdk_cursor_new_from_name(Str.toStringz(name), (fallback is null) ? null : fallback.getCursorStruct());
139 
140 		if(__p is null)
141 		{
142 			throw new ConstructionException("null returned by new_from_name");
143 		}
144 
145 		this(cast(GdkCursor*) __p, true);
146 	}
147 
148 	/**
149 	 * Creates a new cursor from a `GdkTexture`.
150 	 *
151 	 * Params:
152 	 *     texture = the texture providing the pixel data
153 	 *     hotspotX = the horizontal offset of the “hotspot” of the cursor
154 	 *     hotspotY = the vertical offset of the “hotspot” of the cursor
155 	 *     fallback = %NULL or the `GdkCursor` to fall back to when
156 	 *         this one cannot be supported
157 	 *
158 	 * Returns: a new `GdkCursor`
159 	 *
160 	 * Throws: ConstructionException GTK+ fails to create the object.
161 	 */
162 	public this(Texture texture, int hotspotX, int hotspotY, Cursor fallback)
163 	{
164 		auto __p = gdk_cursor_new_from_texture((texture is null) ? null : texture.getTextureStruct(), hotspotX, hotspotY, (fallback is null) ? null : fallback.getCursorStruct());
165 
166 		if(__p is null)
167 		{
168 			throw new ConstructionException("null returned by new_from_texture");
169 		}
170 
171 		this(cast(GdkCursor*) __p, true);
172 	}
173 
174 	/**
175 	 * Returns the fallback for this @cursor.
176 	 *
177 	 * The fallback will be used if this cursor is not available on a given
178 	 * `GdkDisplay`. For named cursors, this can happen when using nonstandard
179 	 * names or when using an incomplete cursor theme. For textured cursors,
180 	 * this can happen when the texture is too large or when the `GdkDisplay`
181 	 * it is used on does not support textured cursors.
182 	 *
183 	 * Returns: the fallback of the cursor or %NULL
184 	 *     to use the default cursor as fallback.
185 	 */
186 	public Cursor getFallback()
187 	{
188 		auto __p = gdk_cursor_get_fallback(gdkCursor);
189 
190 		if(__p is null)
191 		{
192 			return null;
193 		}
194 
195 		return ObjectG.getDObject!(Cursor)(cast(GdkCursor*) __p);
196 	}
197 
198 	/**
199 	 * Returns the horizontal offset of the hotspot.
200 	 *
201 	 * The hotspot indicates the pixel that will be directly above the cursor.
202 	 *
203 	 * Note that named cursors may have a nonzero hotspot, but this function
204 	 * will only return the hotspot position for cursors created with
205 	 * [ctor@Gdk.Cursor.new_from_texture].
206 	 *
207 	 * Returns: the horizontal offset of the hotspot or 0 for named cursors
208 	 */
209 	public int getHotspotX()
210 	{
211 		return gdk_cursor_get_hotspot_x(gdkCursor);
212 	}
213 
214 	/**
215 	 * Returns the vertical offset of the hotspot.
216 	 *
217 	 * The hotspot indicates the pixel that will be directly above the cursor.
218 	 *
219 	 * Note that named cursors may have a nonzero hotspot, but this function
220 	 * will only return the hotspot position for cursors created with
221 	 * [ctor@Gdk.Cursor.new_from_texture].
222 	 *
223 	 * Returns: the vertical offset of the hotspot or 0 for named cursors
224 	 */
225 	public int getHotspotY()
226 	{
227 		return gdk_cursor_get_hotspot_y(gdkCursor);
228 	}
229 
230 	/**
231 	 * Returns the name of the cursor.
232 	 *
233 	 * If the cursor is not a named cursor, %NULL will be returned.
234 	 *
235 	 * Returns: the name of the cursor or %NULL
236 	 *     if it is not a named cursor
237 	 */
238 	public string getName()
239 	{
240 		return Str.toString(gdk_cursor_get_name(gdkCursor));
241 	}
242 
243 	/**
244 	 * Returns the texture for the cursor.
245 	 *
246 	 * If the cursor is a named cursor, %NULL will be returned.
247 	 *
248 	 * Returns: the texture for cursor or %NULL
249 	 *     if it is a named cursor
250 	 */
251 	public Texture getTexture()
252 	{
253 		auto __p = gdk_cursor_get_texture(gdkCursor);
254 
255 		if(__p is null)
256 		{
257 			return null;
258 		}
259 
260 		return ObjectG.getDObject!(Texture)(cast(GdkTexture*) __p);
261 	}
262 }