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