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