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 import gtkc.gobject : g_object_ref; 229 g_object_ref(cast(GObject*)p); 230 231 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 232 } 233 234 /** 235 * Warning 236 * 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. 237 * Gets the stock icon name and size being displayed by the GtkImage. 238 * The storage type of the image must be GTK_IMAGE_EMPTY or 239 * GTK_IMAGE_STOCK (see gtk_image_get_storage_type()). 240 * The returned string is owned by the GtkImage and should not 241 * be freed. 242 * Params: 243 * stockId = place to store a 244 * stock icon name, or NULL. [out][transfer none][allow-none] 245 * size = place to store a stock icon 246 * size, or NULL. [out][allow-none][type int] 247 */ 248 public void getStock(out string stockId, out GtkIconSize size) 249 { 250 // void gtk_image_get_stock (GtkImage *image, gchar **stock_id, GtkIconSize *size); 251 char* outstockId = null; 252 253 gtk_image_get_stock(gtkImage, &outstockId, &size); 254 255 stockId = Str.toString(outstockId); 256 } 257 258 /** 259 * Gets the GdkPixbufAnimation being displayed by the GtkImage. 260 * The storage type of the image must be GTK_IMAGE_EMPTY or 261 * GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()). 262 * The caller of this function does not own a reference to the 263 * returned animation. 264 * Returns: the displayed animation, or NULL if the image is empty. [transfer none] 265 */ 266 public PixbufAnimation getAnimation() 267 { 268 // GdkPixbufAnimation * gtk_image_get_animation (GtkImage *image); 269 auto p = gtk_image_get_animation(gtkImage); 270 271 if(p is null) 272 { 273 return null; 274 } 275 276 return ObjectG.getDObject!(PixbufAnimation)(cast(GdkPixbufAnimation*) p); 277 } 278 279 /** 280 * Gets the icon name and size being displayed by the GtkImage. 281 * The storage type of the image must be GTK_IMAGE_EMPTY or 282 * GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()). 283 * The returned string is owned by the GtkImage and should not 284 * be freed. 285 * Since 2.6 286 * Params: 287 * iconName = place to store an 288 * icon name, or NULL. [out][transfer none][allow-none] 289 * size = place to store an icon size, 290 * or NULL. [out][allow-none][type int] 291 */ 292 public void getIconName(out string iconName, out GtkIconSize size) 293 { 294 // void gtk_image_get_icon_name (GtkImage *image, const gchar **icon_name, GtkIconSize *size); 295 char* outiconName = null; 296 297 gtk_image_get_icon_name(gtkImage, &outiconName, &size); 298 299 iconName = Str.toString(outiconName); 300 } 301 302 /** 303 * Gets the GIcon and size being displayed by the GtkImage. 304 * The storage type of the image must be GTK_IMAGE_EMPTY or 305 * GTK_IMAGE_GICON (see gtk_image_get_storage_type()). 306 * The caller of this function does not own a reference to the 307 * returned GIcon. 308 * Since 2.14 309 * Params: 310 * gicon = place to store a 311 * GIcon, or NULL. [out][transfer none][allow-none] 312 * size = place to store an icon size, 313 * or NULL. [out][allow-none][type int] 314 */ 315 public void getGicon(out IconIF gicon, out GtkIconSize size) 316 { 317 // void gtk_image_get_gicon (GtkImage *image, GIcon **gicon, GtkIconSize *size); 318 GIcon* outgicon = null; 319 320 gtk_image_get_gicon(gtkImage, &outgicon, &size); 321 322 gicon = ObjectG.getDObject!(Icon, IconIF)(outgicon); 323 } 324 325 /** 326 * Gets the type of representation being used by the GtkImage 327 * to store image data. If the GtkImage has no image data, 328 * the return value will be GTK_IMAGE_EMPTY. 329 * Returns: image representation being used 330 */ 331 public GtkImageType getStorageType() 332 { 333 // GtkImageType gtk_image_get_storage_type (GtkImage *image); 334 return gtk_image_get_storage_type(gtkImage); 335 } 336 337 /** 338 * Creates a new GtkImage displaying the file filename. If the file 339 * isn't found or can't be loaded, the resulting GtkImage will 340 * display a "broken image" icon. This function never returns NULL, 341 * it always returns a valid GtkImage widget. 342 * If the file contains an animation, the image will contain an 343 * animation. 344 * If you need to detect failures to load the file, use 345 * gdk_pixbuf_new_from_file() to load the file yourself, then create 346 * the GtkImage from the pixbuf. (Or for animations, use 347 * gdk_pixbuf_animation_new_from_file()). 348 * The storage type (gtk_image_get_storage_type()) of the returned 349 * image is not defined, it will be whatever is appropriate for 350 * displaying the file. 351 * Params: 352 * filename = a filename. [type filename] 353 * Throws: ConstructionException GTK+ fails to create the object. 354 */ 355 public this (string filename) 356 { 357 // GtkWidget * gtk_image_new_from_file (const gchar *filename); 358 auto p = gtk_image_new_from_file(Str.toStringz(filename)); 359 if(p is null) 360 { 361 throw new ConstructionException("null returned by gtk_image_new_from_file(Str.toStringz(filename))"); 362 } 363 this(cast(GtkImage*) p); 364 } 365 366 /** 367 * Warning 368 * 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. 369 * Creates a GtkImage displaying an icon set. Sample stock sizes are 370 * GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR. Instead of using 371 * this function, usually it's better to create a GtkIconFactory, put 372 * your icon sets in the icon factory, add the icon factory to the 373 * list of default factories with gtk_icon_factory_add_default(), and 374 * then use gtk_image_new_from_stock(). This will allow themes to 375 * override the icon you ship with your application. 376 * The GtkImage does not assume a reference to the 377 * icon set; you still need to unref it if you own references. 378 * GtkImage will add its own reference rather than adopting yours. 379 * Params: 380 * iconSet = a GtkIconSet 381 * size = a stock icon size. [type int] 382 * Throws: ConstructionException GTK+ fails to create the object. 383 */ 384 public this (IconSet iconSet, GtkIconSize size) 385 { 386 // GtkWidget * gtk_image_new_from_icon_set (GtkIconSet *icon_set, GtkIconSize size); 387 auto p = gtk_image_new_from_icon_set((iconSet is null) ? null : iconSet.getIconSetStruct(), size); 388 if(p is null) 389 { 390 throw new ConstructionException("null returned by gtk_image_new_from_icon_set((iconSet is null) ? null : iconSet.getIconSetStruct(), size)"); 391 } 392 this(cast(GtkImage*) p); 393 } 394 395 /** 396 * Creates a new GtkImage displaying pixbuf. 397 * The GtkImage does not assume a reference to the 398 * pixbuf; you still need to unref it if you own references. 399 * GtkImage will add its own reference rather than adopting yours. 400 * Note that this function just creates an GtkImage from the pixbuf. The 401 * GtkImage created will not react to state changes. Should you want that, 402 * you should use gtk_image_new_from_icon_name(). 403 * Params: 404 * pixbuf = a GdkPixbuf, or NULL. [allow-none] 405 * Throws: ConstructionException GTK+ fails to create the object. 406 */ 407 public this (Pixbuf pixbuf) 408 { 409 // GtkWidget * gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf); 410 auto p = gtk_image_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct()); 411 if(p is null) 412 { 413 throw new ConstructionException("null returned by gtk_image_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct())"); 414 } 415 this(cast(GtkImage*) p); 416 } 417 418 /** 419 * Creates a GtkImage displaying the given animation. 420 * The GtkImage does not assume a reference to the 421 * animation; you still need to unref it if you own references. 422 * GtkImage will add its own reference rather than adopting yours. 423 * Note that the animation frames are shown using a timeout with 424 * G_PRIORITY_DEFAULT. When using animations to indicate busyness, 425 * keep in mind that the animation will only be shown if the main loop 426 * is not busy with something that has a higher priority. 427 * Params: 428 * animation = an animation 429 * Throws: ConstructionException GTK+ fails to create the object. 430 */ 431 public this (PixbufAnimation animation) 432 { 433 // GtkWidget * gtk_image_new_from_animation (GdkPixbufAnimation *animation); 434 auto p = gtk_image_new_from_animation((animation is null) ? null : animation.getPixbufAnimationStruct()); 435 if(p is null) 436 { 437 throw new ConstructionException("null returned by gtk_image_new_from_animation((animation is null) ? null : animation.getPixbufAnimationStruct())"); 438 } 439 this(cast(GtkImage*) p); 440 } 441 442 /** 443 * Creates a GtkImage displaying an icon from the current icon theme. 444 * If the icon name isn't known, a "broken image" icon will be 445 * displayed instead. If the current icon theme is changed, the icon 446 * will be updated appropriately. 447 * Since 2.6 448 * Params: 449 * iconName = an icon name 450 * size = a stock icon size. [type int] 451 * Throws: ConstructionException GTK+ fails to create the object. 452 */ 453 public this (string iconName, GtkIconSize size) 454 { 455 // GtkWidget * gtk_image_new_from_icon_name (const gchar *icon_name, GtkIconSize size); 456 auto p = gtk_image_new_from_icon_name(Str.toStringz(iconName), size); 457 if(p is null) 458 { 459 throw new ConstructionException("null returned by gtk_image_new_from_icon_name(Str.toStringz(iconName), size)"); 460 } 461 this(cast(GtkImage*) p); 462 } 463 464 /** 465 * Creates a GtkImage displaying an icon from the current icon theme. 466 * If the icon name isn't known, a "broken image" icon will be 467 * displayed instead. If the current icon theme is changed, the icon 468 * will be updated appropriately. 469 * Since 2.14 470 * Params: 471 * icon = an icon 472 * size = a stock icon size. [type int] 473 * Throws: ConstructionException GTK+ fails to create the object. 474 */ 475 public this (IconIF icon, GtkIconSize size) 476 { 477 // GtkWidget * gtk_image_new_from_gicon (GIcon *icon, GtkIconSize size); 478 auto p = gtk_image_new_from_gicon((icon is null) ? null : icon.getIconTStruct(), size); 479 if(p is null) 480 { 481 throw new ConstructionException("null returned by gtk_image_new_from_gicon((icon is null) ? null : icon.getIconTStruct(), size)"); 482 } 483 this(cast(GtkImage*) p); 484 } 485 486 /** 487 * See gtk_image_new_from_file() for details. 488 * Params: 489 * filename = a filename or NULL. [type filename][allow-none] 490 */ 491 public void setFromFile(string filename) 492 { 493 // void gtk_image_set_from_file (GtkImage *image, const gchar *filename); 494 gtk_image_set_from_file(gtkImage, Str.toStringz(filename)); 495 } 496 497 /** 498 * Warning 499 * 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. 500 * See gtk_image_new_from_icon_set() for details. 501 * Params: 502 * iconSet = a GtkIconSet 503 * size = a stock icon size. [type int] 504 */ 505 public void setFromIconSet(IconSet iconSet, GtkIconSize size) 506 { 507 // void gtk_image_set_from_icon_set (GtkImage *image, GtkIconSet *icon_set, GtkIconSize size); 508 gtk_image_set_from_icon_set(gtkImage, (iconSet is null) ? null : iconSet.getIconSetStruct(), size); 509 } 510 511 /** 512 * See gtk_image_new_from_pixbuf() for details. 513 * Params: 514 * pixbuf = a GdkPixbuf or NULL. [allow-none] 515 */ 516 public void setFromPixbuf(Pixbuf pixbuf) 517 { 518 // void gtk_image_set_from_pixbuf (GtkImage *image, GdkPixbuf *pixbuf); 519 gtk_image_set_from_pixbuf(gtkImage, (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 520 } 521 522 /** 523 * Warning 524 * 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. 525 * See gtk_image_new_from_stock() for details. 526 * Params: 527 * stockId = a stock icon name 528 * size = a stock icon size. [type int] 529 */ 530 public void setFromStock(string stockId, GtkIconSize size) 531 { 532 // void gtk_image_set_from_stock (GtkImage *image, const gchar *stock_id, GtkIconSize size); 533 gtk_image_set_from_stock(gtkImage, Str.toStringz(stockId), size); 534 } 535 536 /** 537 * Causes the GtkImage to display the given animation (or display 538 * nothing, if you set the animation to NULL). 539 * Params: 540 * animation = the GdkPixbufAnimation 541 */ 542 public void setFromAnimation(PixbufAnimation animation) 543 { 544 // void gtk_image_set_from_animation (GtkImage *image, GdkPixbufAnimation *animation); 545 gtk_image_set_from_animation(gtkImage, (animation is null) ? null : animation.getPixbufAnimationStruct()); 546 } 547 548 /** 549 * See gtk_image_new_from_icon_name() for details. 550 * Since 2.6 551 * Params: 552 * iconName = an icon name 553 * size = an icon size. [type int] 554 */ 555 public void setFromIconName(string iconName, GtkIconSize size) 556 { 557 // void gtk_image_set_from_icon_name (GtkImage *image, const gchar *icon_name, GtkIconSize size); 558 gtk_image_set_from_icon_name(gtkImage, Str.toStringz(iconName), size); 559 } 560 561 /** 562 * See gtk_image_new_from_gicon() for details. 563 * Since 2.14 564 * Params: 565 * icon = an icon 566 * size = an icon size. [type int] 567 */ 568 public void setFromGicon(IconIF icon, GtkIconSize size) 569 { 570 // void gtk_image_set_from_gicon (GtkImage *image, GIcon *icon, GtkIconSize size); 571 gtk_image_set_from_gicon(gtkImage, (icon is null) ? null : icon.getIconTStruct(), size); 572 } 573 574 /** 575 * See gtk_image_new_from_resource() for details. 576 * Params: 577 * resourcePath = a resource path or NULL. [allow-none] 578 */ 579 public void setFromResource(string resourcePath) 580 { 581 // void gtk_image_set_from_resource (GtkImage *image, const gchar *resource_path); 582 gtk_image_set_from_resource(gtkImage, Str.toStringz(resourcePath)); 583 } 584 585 /** 586 * Resets the image to be empty. 587 * Since 2.8 588 */ 589 public void clear() 590 { 591 // void gtk_image_clear (GtkImage *image); 592 gtk_image_clear(gtkImage); 593 } 594 595 /** 596 * Creates a new empty GtkImage widget. 597 * Throws: ConstructionException GTK+ fails to create the object. 598 */ 599 public this () 600 { 601 // GtkWidget * gtk_image_new (void); 602 auto p = gtk_image_new(); 603 if(p is null) 604 { 605 throw new ConstructionException("null returned by gtk_image_new()"); 606 } 607 this(cast(GtkImage*) p); 608 } 609 610 /** 611 * Sets the pixel size to use for named icons. If the pixel size is set 612 * to a value != -1, it is used instead of the icon size set by 613 * gtk_image_set_from_icon_name(). 614 * Since 2.6 615 * Params: 616 * pixelSize = the new pixel size 617 */ 618 public void setPixelSize(int pixelSize) 619 { 620 // void gtk_image_set_pixel_size (GtkImage *image, gint pixel_size); 621 gtk_image_set_pixel_size(gtkImage, pixelSize); 622 } 623 624 /** 625 * Gets the pixel size used for named icons. 626 * Since 2.6 627 * Returns: the pixel size used for named icons. 628 */ 629 public int getPixelSize() 630 { 631 // gint gtk_image_get_pixel_size (GtkImage *image); 632 return gtk_image_get_pixel_size(gtkImage); 633 } 634 }