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