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 = GtkImage.html 27 * outPack = gtk 28 * outFile = Image 29 * strct = GtkImage 30 * realStrct= 31 * ctorStrct= 32 * clss = Image 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_image_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * - gtk_image_new_from_stock 45 * omit signals: 46 * imports: 47 * - glib.Str 48 * - gio.Icon 49 * - gio.IconIF 50 * - gdk.Pixbuf 51 * - gdkpixbuf.PixbufAnimation 52 * - gtk.IconSet 53 * structWrap: 54 * - GIcon* -> IconIF 55 * - GdkPixbuf* -> Pixbuf 56 * - GdkPixbufAnimation* -> PixbufAnimation 57 * - GtkIconSet* -> IconSet 58 * module aliases: 59 * local aliases: 60 * overrides: 61 */ 62 63 module gtk.Image; 64 65 public import gtkc.gtktypes; 66 67 private import gtkc.gtk; 68 private import glib.ConstructionException; 69 private import gobject.ObjectG; 70 71 72 private import glib.Str; 73 private import gio.Icon; 74 private import gio.IconIF; 75 private import gdk.Pixbuf; 76 private import gdkpixbuf.PixbufAnimation; 77 private import gtk.IconSet; 78 79 80 81 private import gtk.Misc; 82 83 /** 84 * The GtkImage widget displays an image. Various kinds of object 85 * can be displayed as an image; most typically, you would load a 86 * GdkPixbuf ("pixel buffer") from a file, and then display that. 87 * There's a convenience function to do this, gtk_image_new_from_file(), 88 * used as follows: 89 * 90 * $(DDOC_COMMENT example) 91 * 92 * If the file isn't loaded successfully, the image will contain a 93 * "broken image" icon similar to that used in many web browsers. 94 * If you want to handle errors in loading the file yourself, 95 * for example by displaying an error message, then load the image with 96 * gdk_pixbuf_new_from_file(), then create the GtkImage with 97 * gtk_image_new_from_pixbuf(). 98 * 99 * The image file may contain an animation, if so the GtkImage will 100 * display an animation (GdkPixbufAnimation) instead of a static image. 101 * 102 * GtkImage is a subclass of GtkMisc, which implies that you can 103 * align it (center, left, right) and add padding to it, using 104 * GtkMisc methods. 105 * 106 * GtkImage is a "no window" widget (has no GdkWindow of its own), 107 * so by default does not receive events. If you want to receive events 108 * on the image, such as button clicks, place the image inside a 109 * GtkEventBox, then connect to the event signals on the event box. 110 * 111 * $(DDOC_COMMENT example) 112 * 113 * When handling events on the event box, keep in mind that coordinates 114 * in the image may be different from event box coordinates due to 115 * the alignment and padding settings on the image (see GtkMisc). 116 * The simplest way to solve this is to set the alignment to 0.0 117 * (left/top), and set the padding to zero. Then the origin of 118 * the image will be the same as the origin of the event box. 119 * 120 * Sometimes an application will want to avoid depending on external data 121 * files, such as image files. GTK+ comes with a program to avoid this, 122 * called gdk-pixbuf-csource. This library 123 * allows you to convert an image into a C variable declaration, which 124 * can then be loaded into a GdkPixbuf using 125 * gdk_pixbuf_new_from_inline(). 126 */ 127 public class Image : Misc 128 { 129 130 /** the main Gtk struct */ 131 protected GtkImage* gtkImage; 132 133 134 public GtkImage* getImageStruct() 135 { 136 return gtkImage; 137 } 138 139 140 /** the main Gtk struct as a void* */ 141 protected override void* getStruct() 142 { 143 return cast(void*)gtkImage; 144 } 145 146 /** 147 * Sets our main struct and passes it to the parent class 148 */ 149 public this (GtkImage* gtkImage) 150 { 151 super(cast(GtkMisc*)gtkImage); 152 this.gtkImage = gtkImage; 153 } 154 155 protected override void setStruct(GObject* obj) 156 { 157 super.setStruct(obj); 158 gtkImage = cast(GtkImage*)obj; 159 } 160 161 /** 162 * Creates a GtkImage displaying a stock icon. Sample stock icon 163 * names are GTK_STOCK_OPEN, GTK_STOCK_EXIT. Sample stock sizes 164 * are GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock 165 * icon name isn't known, the image will be empty. 166 * You can register your own stock icon names, see 167 * gtk_icon_factory_add_default() and gtk_icon_factory_add(). 168 * Params: 169 * StockID = a stock icon name 170 * size = a stock icon size 171 * Returns: 172 * a new GtkImage displaying the stock icon 173 * Throws: ConstructionException GTK+ fails to create the object. 174 */ 175 public this (StockID stockID, GtkIconSize size) 176 { 177 // GtkWidget* gtk_image_new_from_stock (const gchar *stock_id, GtkIconSize size); 178 auto p = gtk_image_new_from_stock(Str.toStringz(StockDesc[stockID]), size); 179 if(p is null) 180 { 181 throw new ConstructionException("null returned by gtk_image_new_from_stock(Str.toStringz(StockDesc[stockID]), size)"); 182 } 183 this(cast(GtkImage*)p); 184 } 185 186 /** 187 */ 188 189 /** 190 * Warning 191 * gtk_image_get_icon_set has been deprecated since version 3.10 and should not be used in newly-written code. Use gtk_image_get_icon_name() instead. 192 * Gets the icon set and size being displayed by the GtkImage. 193 * The storage type of the image must be GTK_IMAGE_EMPTY or 194 * GTK_IMAGE_ICON_SET (see gtk_image_get_storage_type()). 195 * Params: 196 * iconSet = location to store a 197 * GtkIconSet, or NULL. [out][transfer none][allow-none] 198 * size = location to store a stock 199 * icon size, or NULL. [out][allow-none][type int] 200 */ 201 public void getIconSet(out IconSet iconSet, out GtkIconSize size) 202 { 203 // void gtk_image_get_icon_set (GtkImage *image, GtkIconSet **icon_set, GtkIconSize *size); 204 GtkIconSet* outiconSet = null; 205 206 gtk_image_get_icon_set(gtkImage, &outiconSet, &size); 207 208 iconSet = ObjectG.getDObject!(IconSet)(outiconSet); 209 } 210 211 /** 212 * Gets the GdkPixbuf being displayed by the GtkImage. 213 * The storage type of the image must be GTK_IMAGE_EMPTY or 214 * GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()). 215 * The caller of this function does not own a reference to the 216 * returned pixbuf. 217 * Returns: the displayed pixbuf, or NULL if the image is empty. [transfer none] 218 */ 219 public Pixbuf getPixbuf() 220 { 221 // GdkPixbuf * gtk_image_get_pixbuf (GtkImage *image); 222 auto p = gtk_image_get_pixbuf(gtkImage); 223 224 if(p is null) 225 { 226 return null; 227 } 228 229 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 230 } 231 232 /** 233 * Warning 234 * gtk_image_get_stock has been deprecated since version 3.10 and should not be used in newly-written code. Use gtk_image_get_icon_name() instead. 235 * Gets the stock icon name and size being displayed by the GtkImage. 236 * The storage type of the image must be GTK_IMAGE_EMPTY or 237 * GTK_IMAGE_STOCK (see gtk_image_get_storage_type()). 238 * The returned string is owned by the GtkImage and should not 239 * be freed. 240 * Params: 241 * stockId = place to store a 242 * stock icon name, or NULL. [out][transfer none][allow-none] 243 * size = place to store a stock icon 244 * size, or NULL. [out][allow-none][type int] 245 */ 246 public void getStock(out string stockId, out GtkIconSize size) 247 { 248 // void gtk_image_get_stock (GtkImage *image, gchar **stock_id, GtkIconSize *size); 249 char* outstockId = null; 250 251 gtk_image_get_stock(gtkImage, &outstockId, &size); 252 253 stockId = Str.toString(outstockId); 254 } 255 256 /** 257 * Gets the GdkPixbufAnimation being displayed by the GtkImage. 258 * The storage type of the image must be GTK_IMAGE_EMPTY or 259 * GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()). 260 * The caller of this function does not own a reference to the 261 * returned animation. 262 * Returns: the displayed animation, or NULL if the image is empty. [transfer none] 263 */ 264 public PixbufAnimation getAnimation() 265 { 266 // GdkPixbufAnimation * gtk_image_get_animation (GtkImage *image); 267 auto p = gtk_image_get_animation(gtkImage); 268 269 if(p is null) 270 { 271 return null; 272 } 273 274 return ObjectG.getDObject!(PixbufAnimation)(cast(GdkPixbufAnimation*) p); 275 } 276 277 /** 278 * Gets the icon name and size being displayed by the GtkImage. 279 * The storage type of the image must be GTK_IMAGE_EMPTY or 280 * GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()). 281 * The returned string is owned by the GtkImage and should not 282 * be freed. 283 * Since 2.6 284 * Params: 285 * iconName = place to store an 286 * icon name, or NULL. [out][transfer none][allow-none] 287 * size = place to store an icon size, 288 * or NULL. [out][allow-none][type int] 289 */ 290 public void getIconName(out string iconName, out GtkIconSize size) 291 { 292 // void gtk_image_get_icon_name (GtkImage *image, const gchar **icon_name, GtkIconSize *size); 293 char* outiconName = null; 294 295 gtk_image_get_icon_name(gtkImage, &outiconName, &size); 296 297 iconName = Str.toString(outiconName); 298 } 299 300 /** 301 * Gets the GIcon and size being displayed by the GtkImage. 302 * The storage type of the image must be GTK_IMAGE_EMPTY or 303 * GTK_IMAGE_GICON (see gtk_image_get_storage_type()). 304 * The caller of this function does not own a reference to the 305 * returned GIcon. 306 * Since 2.14 307 * Params: 308 * gicon = place to store a 309 * GIcon, or NULL. [out][transfer none][allow-none] 310 * size = place to store an icon size, 311 * or NULL. [out][allow-none][type int] 312 */ 313 public void getGicon(out IconIF gicon, out GtkIconSize size) 314 { 315 // void gtk_image_get_gicon (GtkImage *image, GIcon **gicon, GtkIconSize *size); 316 GIcon* outgicon = null; 317 318 gtk_image_get_gicon(gtkImage, &outgicon, &size); 319 320 gicon = ObjectG.getDObject!(Icon, IconIF)(outgicon); 321 } 322 323 /** 324 * Gets the type of representation being used by the GtkImage 325 * to store image data. If the GtkImage has no image data, 326 * the return value will be GTK_IMAGE_EMPTY. 327 * Returns: image representation being used 328 */ 329 public GtkImageType getStorageType() 330 { 331 // GtkImageType gtk_image_get_storage_type (GtkImage *image); 332 return gtk_image_get_storage_type(gtkImage); 333 } 334 335 /** 336 * Creates a new GtkImage displaying the file filename. If the file 337 * isn't found or can't be loaded, the resulting GtkImage will 338 * display a "broken image" icon. This function never returns NULL, 339 * it always returns a valid GtkImage widget. 340 * If the file contains an animation, the image will contain an 341 * animation. 342 * If you need to detect failures to load the file, use 343 * gdk_pixbuf_new_from_file() to load the file yourself, then create 344 * the GtkImage from the pixbuf. (Or for animations, use 345 * gdk_pixbuf_animation_new_from_file()). 346 * The storage type (gtk_image_get_storage_type()) of the returned 347 * image is not defined, it will be whatever is appropriate for 348 * displaying the file. 349 * Params: 350 * filename = a filename. [type filename] 351 * Throws: ConstructionException GTK+ fails to create the object. 352 */ 353 public this (string filename) 354 { 355 // GtkWidget * gtk_image_new_from_file (const gchar *filename); 356 auto p = gtk_image_new_from_file(Str.toStringz(filename)); 357 if(p is null) 358 { 359 throw new ConstructionException("null returned by gtk_image_new_from_file(Str.toStringz(filename))"); 360 } 361 this(cast(GtkImage*) p); 362 } 363 364 /** 365 * Warning 366 * gtk_image_new_from_icon_set has been deprecated since version 3.10 and should not be used in newly-written code. Use gtk_image_new_from_icon_name() instead. 367 * Creates a GtkImage displaying an icon set. Sample stock sizes are 368 * GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using 369 * this function, usually it's better to create a GtkIconFactory, put 370 * your icon sets in the icon factory, add the icon factory to the 371 * list of default factories with gtk_icon_factory_add_default(), and 372 * then use gtk_image_new_from_stock(). This will allow themes to 373 * override the icon you ship with your application. 374 * The GtkImage does not assume a reference to the 375 * icon set; you still need to unref it if you own references. 376 * GtkImage will add its own reference rather than adopting yours. 377 * Params: 378 * iconSet = a GtkIconSet 379 * size = a stock icon size. [type int] 380 * Throws: ConstructionException GTK+ fails to create the object. 381 */ 382 public this (IconSet iconSet, GtkIconSize size) 383 { 384 // GtkWidget * gtk_image_new_from_icon_set (GtkIconSet *icon_set, GtkIconSize size); 385 auto p = gtk_image_new_from_icon_set((iconSet is null) ? null : iconSet.getIconSetStruct(), size); 386 if(p is null) 387 { 388 throw new ConstructionException("null returned by gtk_image_new_from_icon_set((iconSet is null) ? null : iconSet.getIconSetStruct(), size)"); 389 } 390 this(cast(GtkImage*) p); 391 } 392 393 /** 394 * Creates a new GtkImage displaying pixbuf. 395 * The GtkImage does not assume a reference to the 396 * pixbuf; you still need to unref it if you own references. 397 * GtkImage will add its own reference rather than adopting yours. 398 * Note that this function just creates an GtkImage from the pixbuf. The 399 * GtkImage created will not react to state changes. Should you want that, 400 * you should use gtk_image_new_from_icon_name(). 401 * Params: 402 * pixbuf = a GdkPixbuf, or NULL. [allow-none] 403 * Throws: ConstructionException GTK+ fails to create the object. 404 */ 405 public this (Pixbuf pixbuf) 406 { 407 // GtkWidget * gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf); 408 auto p = gtk_image_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct()); 409 if(p is null) 410 { 411 throw new ConstructionException("null returned by gtk_image_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct())"); 412 } 413 this(cast(GtkImage*) p); 414 } 415 416 /** 417 * Creates a GtkImage displaying the given animation. 418 * The GtkImage does not assume a reference to the 419 * animation; you still need to unref it if you own references. 420 * GtkImage will add its own reference rather than adopting yours. 421 * Note that the animation frames are shown using a timeout with 422 * G_PRIORITY_DEFAULT. When using animations to indicate busyness, 423 * keep in mind that the animation will only be shown if the main loop 424 * is not busy with something that has a higher priority. 425 * Params: 426 * animation = an animation 427 * Throws: ConstructionException GTK+ fails to create the object. 428 */ 429 public this (PixbufAnimation animation) 430 { 431 // GtkWidget * gtk_image_new_from_animation (GdkPixbufAnimation *animation); 432 auto p = gtk_image_new_from_animation((animation is null) ? null : animation.getPixbufAnimationStruct()); 433 if(p is null) 434 { 435 throw new ConstructionException("null returned by gtk_image_new_from_animation((animation is null) ? null : animation.getPixbufAnimationStruct())"); 436 } 437 this(cast(GtkImage*) p); 438 } 439 440 /** 441 * Creates a GtkImage displaying an icon from the current icon theme. 442 * If the icon name isn't known, a "broken image" icon will be 443 * displayed instead. If the current icon theme is changed, the icon 444 * will be updated appropriately. 445 * Since 2.6 446 * Params: 447 * iconName = an icon name 448 * size = a stock icon size. [type int] 449 * Throws: ConstructionException GTK+ fails to create the object. 450 */ 451 public this (string iconName, GtkIconSize size) 452 { 453 // GtkWidget * gtk_image_new_from_icon_name (const gchar *icon_name, GtkIconSize size); 454 auto p = gtk_image_new_from_icon_name(Str.toStringz(iconName), size); 455 if(p is null) 456 { 457 throw new ConstructionException("null returned by gtk_image_new_from_icon_name(Str.toStringz(iconName), size)"); 458 } 459 this(cast(GtkImage*) p); 460 } 461 462 /** 463 * Creates a GtkImage displaying an icon from the current icon theme. 464 * If the icon name isn't known, a "broken image" icon will be 465 * displayed instead. If the current icon theme is changed, the icon 466 * will be updated appropriately. 467 * Since 2.14 468 * Params: 469 * icon = an icon 470 * size = a stock icon size. [type int] 471 * Throws: ConstructionException GTK+ fails to create the object. 472 */ 473 public this (IconIF icon, GtkIconSize size) 474 { 475 // GtkWidget * gtk_image_new_from_gicon (GIcon *icon, GtkIconSize size); 476 auto p = gtk_image_new_from_gicon((icon is null) ? null : icon.getIconTStruct(), size); 477 if(p is null) 478 { 479 throw new ConstructionException("null returned by gtk_image_new_from_gicon((icon is null) ? null : icon.getIconTStruct(), size)"); 480 } 481 this(cast(GtkImage*) p); 482 } 483 484 /** 485 * See gtk_image_new_from_file() for details. 486 * Params: 487 * filename = a filename or NULL. [type filename][allow-none] 488 */ 489 public void setFromFile(string filename) 490 { 491 // void gtk_image_set_from_file (GtkImage *image, const gchar *filename); 492 gtk_image_set_from_file(gtkImage, Str.toStringz(filename)); 493 } 494 495 /** 496 * Warning 497 * gtk_image_set_from_icon_set has been deprecated since version 3.10 and should not be used in newly-written code. Use gtk_image_set_from_icon_name() instead. 498 * See gtk_image_new_from_icon_set() for details. 499 * Params: 500 * iconSet = a GtkIconSet 501 * size = a stock icon size. [type int] 502 */ 503 public void setFromIconSet(IconSet iconSet, GtkIconSize size) 504 { 505 // void gtk_image_set_from_icon_set (GtkImage *image, GtkIconSet *icon_set, GtkIconSize size); 506 gtk_image_set_from_icon_set(gtkImage, (iconSet is null) ? null : iconSet.getIconSetStruct(), size); 507 } 508 509 /** 510 * See gtk_image_new_from_pixbuf() for details. 511 * Params: 512 * pixbuf = a GdkPixbuf or NULL. [allow-none] 513 */ 514 public void setFromPixbuf(Pixbuf pixbuf) 515 { 516 // void gtk_image_set_from_pixbuf (GtkImage *image, GdkPixbuf *pixbuf); 517 gtk_image_set_from_pixbuf(gtkImage, (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 518 } 519 520 /** 521 * Warning 522 * gtk_image_set_from_stock has been deprecated since version 3.10 and should not be used in newly-written code. Use gtk_image_set_from_icon_name() instead. 523 * See gtk_image_new_from_stock() for details. 524 * Params: 525 * stockId = a stock icon name 526 * size = a stock icon size. [type int] 527 */ 528 public void setFromStock(string stockId, GtkIconSize size) 529 { 530 // void gtk_image_set_from_stock (GtkImage *image, const gchar *stock_id, GtkIconSize size); 531 gtk_image_set_from_stock(gtkImage, Str.toStringz(stockId), size); 532 } 533 534 /** 535 * Causes the GtkImage to display the given animation (or display 536 * nothing, if you set the animation to NULL). 537 * Params: 538 * animation = the GdkPixbufAnimation 539 */ 540 public void setFromAnimation(PixbufAnimation animation) 541 { 542 // void gtk_image_set_from_animation (GtkImage *image, GdkPixbufAnimation *animation); 543 gtk_image_set_from_animation(gtkImage, (animation is null) ? null : animation.getPixbufAnimationStruct()); 544 } 545 546 /** 547 * See gtk_image_new_from_icon_name() for details. 548 * Since 2.6 549 * Params: 550 * iconName = an icon name 551 * size = an icon size. [type int] 552 */ 553 public void setFromIconName(string iconName, GtkIconSize size) 554 { 555 // void gtk_image_set_from_icon_name (GtkImage *image, const gchar *icon_name, GtkIconSize size); 556 gtk_image_set_from_icon_name(gtkImage, Str.toStringz(iconName), size); 557 } 558 559 /** 560 * See gtk_image_new_from_gicon() for details. 561 * Since 2.14 562 * Params: 563 * icon = an icon 564 * size = an icon size. [type int] 565 */ 566 public void setFromGicon(IconIF icon, GtkIconSize size) 567 { 568 // void gtk_image_set_from_gicon (GtkImage *image, GIcon *icon, GtkIconSize size); 569 gtk_image_set_from_gicon(gtkImage, (icon is null) ? null : icon.getIconTStruct(), size); 570 } 571 572 /** 573 * See gtk_image_new_from_resource() for details. 574 * Params: 575 * resourcePath = a resource path or NULL. [allow-none] 576 */ 577 public void setFromResource(string resourcePath) 578 { 579 // void gtk_image_set_from_resource (GtkImage *image, const gchar *resource_path); 580 gtk_image_set_from_resource(gtkImage, Str.toStringz(resourcePath)); 581 } 582 583 /** 584 * Resets the image to be empty. 585 * Since 2.8 586 */ 587 public void clear() 588 { 589 // void gtk_image_clear (GtkImage *image); 590 gtk_image_clear(gtkImage); 591 } 592 593 /** 594 * Creates a new empty GtkImage widget. 595 * Throws: ConstructionException GTK+ fails to create the object. 596 */ 597 public this () 598 { 599 // GtkWidget * gtk_image_new (void); 600 auto p = gtk_image_new(); 601 if(p is null) 602 { 603 throw new ConstructionException("null returned by gtk_image_new()"); 604 } 605 this(cast(GtkImage*) p); 606 } 607 608 /** 609 * Sets the pixel size to use for named icons. If the pixel size is set 610 * to a value != -1, it is used instead of the icon size set by 611 * gtk_image_set_from_icon_name(). 612 * Since 2.6 613 * Params: 614 * pixelSize = the new pixel size 615 */ 616 public void setPixelSize(int pixelSize) 617 { 618 // void gtk_image_set_pixel_size (GtkImage *image, gint pixel_size); 619 gtk_image_set_pixel_size(gtkImage, pixelSize); 620 } 621 622 /** 623 * Gets the pixel size used for named icons. 624 * Since 2.6 625 * Returns: the pixel size used for named icons. 626 */ 627 public int getPixelSize() 628 { 629 // gint gtk_image_get_pixel_size (GtkImage *image); 630 return gtk_image_get_pixel_size(gtkImage); 631 } 632 }