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 = GtkIconTheme.html 27 * outPack = gtk 28 * outFile = IconTheme 29 * strct = GtkIconTheme 30 * realStrct= 31 * ctorStrct= 32 * clss = IconTheme 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_icon_theme_ 41 * omit structs: 42 * omit prefixes: 43 * - gtk_icon_info_ 44 * omit code: 45 * omit signals: 46 * imports: 47 * - glib.Str 48 * - glib.ErrorG 49 * - glib.GException 50 * - cairo.Surface 51 * - glib.ListG 52 * - gio.IconIF 53 * - gdk.Pixbuf 54 * - gdk.RGBA 55 * - gdk.Screen 56 * - gdk.Window 57 * - gtk.IconInfo 58 * - gtk.StyleContext 59 * structWrap: 60 * - GIcon* -> IconIF 61 * - GList* -> ListG 62 * - GdkPixbuf* -> Pixbuf 63 * - GdkRGBA* -> RGBA 64 * - GdkScreen* -> Screen 65 * - GdkWindow* -> Window 66 * - GtkIconInfo* -> IconInfo 67 * - GtkIconTheme* -> IconTheme 68 * - GtkStyleContext* -> StyleContext 69 * - cairo_surface_t* -> Surface 70 * module aliases: 71 * local aliases: 72 * overrides: 73 */ 74 75 module gtk.IconTheme; 76 77 public import gtkc.gtktypes; 78 79 private import gtkc.gtk; 80 private import glib.ConstructionException; 81 private import gobject.ObjectG; 82 83 private import gobject.Signals; 84 public import gtkc.gdktypes; 85 private import glib.Str; 86 private import glib.ErrorG; 87 private import glib.GException; 88 private import cairo.Surface; 89 private import glib.ListG; 90 private import gio.IconIF; 91 private import gdk.Pixbuf; 92 private import gdk.RGBA; 93 private import gdk.Screen; 94 private import gdk.Window; 95 private import gtk.IconInfo; 96 private import gtk.StyleContext; 97 98 99 private import gobject.ObjectG; 100 101 /** 102 * GtkIconTheme provides a facility for looking up icons by name 103 * and size. The main reason for using a name rather than simply 104 * providing a filename is to allow different icons to be used 105 * depending on what icon theme is selected 106 * by the user. The operation of icon themes on Linux and Unix 107 * follows the Icon 108 * Theme Specification. There is a default icon theme, 109 * named hicolor where applications should install 110 * their icons, but more additional application themes can be 111 * installed as operating system vendors and users choose. 112 * 113 * Named icons are similar to the Themeable Stock Images(3) 114 * facility, and the distinction between the two may be a bit confusing. 115 * A few things to keep in mind: 116 * 117 * Stock images usually are used in conjunction with 118 * Stock Items(3), such as GTK_STOCK_OK or 119 * GTK_STOCK_OPEN. Named icons are easier to set up and therefore 120 * are more useful for new icons that an application wants to 121 * add, such as application icons or window icons. 122 * 123 * Stock images can only be loaded at the symbolic sizes defined 124 * by the GtkIconSize enumeration, or by custom sizes defined 125 * by gtk_icon_size_register(), while named icons are more flexible 126 * and any pixel size can be specified. 127 * 128 * Because stock images are closely tied to stock items, and thus 129 * to actions in the user interface, stock images may come in 130 * multiple variants for different widget states or writing 131 * directions. 132 * 133 * A good rule of thumb is that if there is a stock image for what 134 * you want to use, use it, otherwise use a named icon. It turns 135 * out that internally stock images are generally defined in 136 * terms of one or more named icons. (An example of the 137 * more than one case is icons that depend on writing direction; 138 * GTK_STOCK_GO_FORWARD uses the two themed icons 139 * "gtk-stock-go-forward-ltr" and "gtk-stock-go-forward-rtl".) 140 * 141 * In many cases, named themes are used indirectly, via GtkImage 142 * or stock items, rather than directly, but looking up icons 143 * directly is also simple. The GtkIconTheme object acts 144 * as a database of all the icons in the current theme. You 145 * can create new GtkIconTheme objects, but it's much more 146 * efficient to use the standard icon theme for the GdkScreen 147 * so that the icon information is shared with other people 148 * looking up icons. In the case where the default screen is 149 * being used, looking up an icon can be as simple as: 150 * 151 * $(DDOC_COMMENT example) 152 */ 153 public class IconTheme : ObjectG 154 { 155 156 /** the main Gtk struct */ 157 protected GtkIconTheme* gtkIconTheme; 158 159 160 /** Get the main Gtk struct */ 161 public GtkIconTheme* getIconThemeStruct() 162 { 163 return gtkIconTheme; 164 } 165 166 167 /** the main Gtk struct as a void* */ 168 protected override void* getStruct() 169 { 170 return cast(void*)gtkIconTheme; 171 } 172 173 /** 174 * Sets our main struct and passes it to the parent class 175 */ 176 public this (GtkIconTheme* gtkIconTheme) 177 { 178 super(cast(GObject*)gtkIconTheme); 179 this.gtkIconTheme = gtkIconTheme; 180 } 181 182 protected override void setStruct(GObject* obj) 183 { 184 super.setStruct(obj); 185 gtkIconTheme = cast(GtkIconTheme*)obj; 186 } 187 188 /** 189 */ 190 int[string] connectedSignals; 191 192 void delegate(IconTheme)[] onChangedListeners; 193 /** 194 * Emitted when the current icon theme is switched or GTK+ detects 195 * that a change has occurred in the contents of the current 196 * icon theme. 197 */ 198 void addOnChanged(void delegate(IconTheme) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 199 { 200 if ( !("changed" in connectedSignals) ) 201 { 202 Signals.connectData( 203 getStruct(), 204 "changed", 205 cast(GCallback)&callBackChanged, 206 cast(void*)this, 207 null, 208 connectFlags); 209 connectedSignals["changed"] = 1; 210 } 211 onChangedListeners ~= dlg; 212 } 213 extern(C) static void callBackChanged(GtkIconTheme* iconThemeStruct, IconTheme _iconTheme) 214 { 215 foreach ( void delegate(IconTheme) dlg ; _iconTheme.onChangedListeners ) 216 { 217 dlg(_iconTheme); 218 } 219 } 220 221 222 /** 223 * Creates a new icon theme object. Icon theme objects are used 224 * to lookup up an icon by name in a particular icon theme. 225 * Usually, you'll want to use gtk_icon_theme_get_default() 226 * or gtk_icon_theme_get_for_screen() rather than creating 227 * a new icon theme object for scratch. 228 * Since 2.4 229 * Throws: ConstructionException GTK+ fails to create the object. 230 */ 231 public this () 232 { 233 // GtkIconTheme * gtk_icon_theme_new (void); 234 auto p = gtk_icon_theme_new(); 235 if(p is null) 236 { 237 throw new ConstructionException("null returned by gtk_icon_theme_new()"); 238 } 239 this(cast(GtkIconTheme*) p); 240 } 241 242 /** 243 * Gets the icon theme for the default screen. See 244 * gtk_icon_theme_get_for_screen(). 245 * Since 2.4 246 * Returns: A unique GtkIconTheme associated with the default screen. This icon theme is associated with the screen and can be used as long as the screen is open. Do not ref or unref it. [transfer none] 247 */ 248 public static IconTheme getDefault() 249 { 250 // GtkIconTheme * gtk_icon_theme_get_default (void); 251 auto p = gtk_icon_theme_get_default(); 252 253 if(p is null) 254 { 255 return null; 256 } 257 258 return ObjectG.getDObject!(IconTheme)(cast(GtkIconTheme*) p); 259 } 260 261 /** 262 * Gets the icon theme object associated with screen; if this 263 * function has not previously been called for the given 264 * screen, a new icon theme object will be created and 265 * associated with the screen. Icon theme objects are 266 * fairly expensive to create, so using this function 267 * is usually a better choice than calling than gtk_icon_theme_new() 268 * and setting the screen yourself; by using this function 269 * a single icon theme object will be shared between users. 270 * Since 2.4 271 * Params: 272 * screen = a GdkScreen 273 * Returns: A unique GtkIconTheme associated with the given screen. This icon theme is associated with the screen and can be used as long as the screen is open. Do not ref or unref it. [transfer none] 274 */ 275 public static IconTheme getForScreen(Screen screen) 276 { 277 // GtkIconTheme * gtk_icon_theme_get_for_screen (GdkScreen *screen); 278 auto p = gtk_icon_theme_get_for_screen((screen is null) ? null : screen.getScreenStruct()); 279 280 if(p is null) 281 { 282 return null; 283 } 284 285 return ObjectG.getDObject!(IconTheme)(cast(GtkIconTheme*) p); 286 } 287 288 /** 289 * Sets the screen for an icon theme; the screen is used 290 * to track the user's currently configured icon theme, 291 * which might be different for different screens. 292 * Since 2.4 293 * Params: 294 * screen = a GdkScreen 295 */ 296 public void setScreen(Screen screen) 297 { 298 // void gtk_icon_theme_set_screen (GtkIconTheme *icon_theme, GdkScreen *screen); 299 gtk_icon_theme_set_screen(gtkIconTheme, (screen is null) ? null : screen.getScreenStruct()); 300 } 301 302 /** 303 * Sets the search path for the icon theme object. When looking 304 * for an icon theme, GTK+ will search for a subdirectory of 305 * one or more of the directories in path with the same name 306 * as the icon theme. (Themes from multiple of the path elements 307 * are combined to allow themes to be extended by adding icons 308 * in the user's home directory.) 309 * In addition if an icon found isn't found either in the current 310 * icon theme or the default icon theme, and an image file with 311 * the right name is found directly in one of the elements of 312 * path, then that image will be used for the icon name. 313 * (This is legacy feature, and new icons should be put 314 * into the default icon theme, which is called DEFAULT_THEME_NAME, 315 * rather than directly on the icon path.) 316 * Since 2.4 317 * Params: 318 * path = array of 319 * directories that are searched for icon themes. [array length=n_elements][element-type filename] 320 */ 321 public void setSearchPath(string[] path) 322 { 323 // void gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme, const gchar *path[], gint n_elements); 324 gtk_icon_theme_set_search_path(gtkIconTheme, Str.toStringzArray(path), cast(int) path.length); 325 } 326 327 /** 328 * Gets the current search path. See gtk_icon_theme_set_search_path(). 329 * Since 2.4 330 * Params: 331 * path = location to store a list of icon theme path directories or NULL. 332 * The stored value should be freed with g_strfreev(). [allow-none][array length=n_elements][element-type filename][out] 333 */ 334 public void getSearchPath(out string[] path) 335 { 336 // void gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme, gchar **path[], gint *n_elements); 337 char** outpath = null; 338 int nElements; 339 340 gtk_icon_theme_get_search_path(gtkIconTheme, &outpath, &nElements); 341 342 path = null; 343 foreach ( cstr; outpath[0 .. nElements] ) 344 { 345 path ~= Str.toString(cstr); 346 } 347 } 348 349 /** 350 * Appends a directory to the search path. 351 * See gtk_icon_theme_set_search_path(). 352 * Since 2.4 353 * Params: 354 * path = directory name to append to the icon path. [type filename] 355 */ 356 public void appendSearchPath(string path) 357 { 358 // void gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme, const gchar *path); 359 gtk_icon_theme_append_search_path(gtkIconTheme, Str.toStringz(path)); 360 } 361 362 /** 363 * Prepends a directory to the search path. 364 * See gtk_icon_theme_set_search_path(). 365 * Since 2.4 366 * Params: 367 * path = directory name to prepend to the icon path. [type filename] 368 */ 369 public void prependSearchPath(string path) 370 { 371 // void gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme, const gchar *path); 372 gtk_icon_theme_prepend_search_path(gtkIconTheme, Str.toStringz(path)); 373 } 374 375 /** 376 * Sets the name of the icon theme that the GtkIconTheme object uses 377 * overriding system configuration. This function cannot be called 378 * on the icon theme objects returned from gtk_icon_theme_get_default() 379 * and gtk_icon_theme_get_for_screen(). 380 * Since 2.4 381 * Params: 382 * themeName = name of icon theme to use instead of 383 * configured theme, or NULL to unset a previously set custom theme. [allow-none] 384 */ 385 public void setCustomTheme(string themeName) 386 { 387 // void gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme, const gchar *theme_name); 388 gtk_icon_theme_set_custom_theme(gtkIconTheme, Str.toStringz(themeName)); 389 } 390 391 /** 392 * Checks whether an icon theme includes an icon 393 * for a particular name. 394 * Since 2.4 395 * Params: 396 * iconName = the name of an icon 397 * Returns: TRUE if icon_theme includes an icon for icon_name. 398 */ 399 public int hasIcon(string iconName) 400 { 401 // gboolean gtk_icon_theme_has_icon (GtkIconTheme *icon_theme, const gchar *icon_name); 402 return gtk_icon_theme_has_icon(gtkIconTheme, Str.toStringz(iconName)); 403 } 404 405 /** 406 * Looks up a named icon and returns a structure containing 407 * information such as the filename of the icon. The icon 408 * can then be rendered into a pixbuf using 409 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() 410 * combines these two steps if all you need is the pixbuf.) 411 * Since 2.4 412 * Params: 413 * iconName = the name of the icon to lookup 414 * size = desired icon size 415 * flags = flags modifying the behavior of the icon lookup 416 * Returns: a GtkIconInfo object containing information about the icon, or NULL if the icon wasn't found. [transfer full] 417 */ 418 public IconInfo lookupIcon(string iconName, int size, GtkIconLookupFlags flags) 419 { 420 // GtkIconInfo * gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, GtkIconLookupFlags flags); 421 auto p = gtk_icon_theme_lookup_icon(gtkIconTheme, Str.toStringz(iconName), size, flags); 422 423 if(p is null) 424 { 425 return null; 426 } 427 428 return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p); 429 } 430 431 /** 432 * Looks up a named icon for a particular window scale and returns a 433 * structure containing information such as the filename of the 434 * icon. The icon can then be rendered into a pixbuf using 435 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines 436 * these two steps if all you need is the pixbuf.) 437 * Params: 438 * iconName = the name of the icon to lookup 439 * size = desired icon size 440 * scale = the desired scale 441 * flags = flags modifying the behavior of the icon lookup 442 * Returns: a GtkIconInfo object containing information about the icon, or NULL if the icon wasn't found. [transfer full] Since 3.10 443 */ 444 public IconInfo lookupIconForScale(string iconName, int size, int scale, GtkIconLookupFlags flags) 445 { 446 // GtkIconInfo * gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, gint scale, GtkIconLookupFlags flags); 447 auto p = gtk_icon_theme_lookup_icon_for_scale(gtkIconTheme, Str.toStringz(iconName), size, scale, flags); 448 449 if(p is null) 450 { 451 return null; 452 } 453 454 return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p); 455 } 456 457 /** 458 * Looks up a named icon and returns a structure containing 459 * information such as the filename of the icon. The icon 460 * can then be rendered into a pixbuf using 461 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() 462 * combines these two steps if all you need is the pixbuf.) 463 * If icon_names contains more than one name, this function 464 * tries them all in the given order before falling back to 465 * inherited icon themes. 466 * Since 2.12 467 * Params: 468 * iconNames = NULL-terminated array of 469 * icon names to lookup. [array zero-terminated=1] 470 * size = desired icon size 471 * flags = flags modifying the behavior of the icon lookup 472 * Returns: a GtkIconInfo object containing information about the icon, or NULL if the icon wasn't found. [transfer full] 473 */ 474 public IconInfo chooseIcon(string[] iconNames, int size, GtkIconLookupFlags flags) 475 { 476 // GtkIconInfo * gtk_icon_theme_choose_icon (GtkIconTheme *icon_theme, const gchar *icon_names[], gint size, GtkIconLookupFlags flags); 477 auto p = gtk_icon_theme_choose_icon(gtkIconTheme, Str.toStringzArray(iconNames), size, flags); 478 479 if(p is null) 480 { 481 return null; 482 } 483 484 return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p); 485 } 486 487 /** 488 * Looks up a named icon for a particular window scale and returns a 489 * structure containing information such as the filename of the 490 * icon. The icon can then be rendered into a pixbuf using 491 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines 492 * these two steps if all you need is the pixbuf.) 493 * If icon_names contains more than one name, this function 494 * tries them all in the given order before falling back to 495 * inherited icon themes. 496 * Params: 497 * iconNames = NULL-terminated array of 498 * icon names to lookup. [array zero-terminated=1] 499 * size = desired icon size 500 * scale = desired scale 501 * flags = flags modifying the behavior of the icon lookup 502 * Returns: a GtkIconInfo object containing information about the icon, or NULL if the icon wasn't found. [transfer full] Since 3.10 503 */ 504 public IconInfo chooseIconForScale(string[] iconNames, int size, int scale, GtkIconLookupFlags flags) 505 { 506 // GtkIconInfo * gtk_icon_theme_choose_icon_for_scale (GtkIconTheme *icon_theme, const gchar *icon_names[], gint size, gint scale, GtkIconLookupFlags flags); 507 auto p = gtk_icon_theme_choose_icon_for_scale(gtkIconTheme, Str.toStringzArray(iconNames), size, scale, flags); 508 509 if(p is null) 510 { 511 return null; 512 } 513 514 return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p); 515 } 516 517 /** 518 * Looks up an icon and returns a structure containing 519 * information such as the filename of the icon. 520 * The icon can then be rendered into a pixbuf using 521 * gtk_icon_info_load_icon(). 522 * Since 2.14 523 * Params: 524 * icon = the GIcon to look up 525 * size = desired icon size 526 * flags = flags modifying the behavior of the icon lookup 527 * Returns: a GtkIconInfo structure containing information about the icon, or NULL if the icon wasn't found. Unref with g_object_unref(). [transfer full] 528 */ 529 public IconInfo lookupByGicon(IconIF icon, int size, GtkIconLookupFlags flags) 530 { 531 // GtkIconInfo * gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme, GIcon *icon, gint size, GtkIconLookupFlags flags); 532 auto p = gtk_icon_theme_lookup_by_gicon(gtkIconTheme, (icon is null) ? null : icon.getIconTStruct(), size, flags); 533 534 if(p is null) 535 { 536 return null; 537 } 538 539 return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p); 540 } 541 542 /** 543 * Looks up an icon and returns a structure containing 544 * information such as the filename of the icon. 545 * The icon can then be rendered into a pixbuf using 546 * gtk_icon_info_load_icon_for_scale(). 547 * Params: 548 * icon = the GIcon to look up 549 * size = desired icon size 550 * scale = the desired scale 551 * flags = flags modifying the behavior of the icon lookup 552 * Returns: a GtkIconInfo structure containing information about the icon, or NULL if the icon wasn't found. Unref with g_object_unref(). [transfer full] Since 3.10 553 */ 554 public IconInfo lookupByGiconForScale(IconIF icon, int size, int scale, GtkIconLookupFlags flags) 555 { 556 // GtkIconInfo * gtk_icon_theme_lookup_by_gicon_for_scale (GtkIconTheme *icon_theme, GIcon *icon, gint size, gint scale, GtkIconLookupFlags flags); 557 auto p = gtk_icon_theme_lookup_by_gicon_for_scale(gtkIconTheme, (icon is null) ? null : icon.getIconTStruct(), size, scale, flags); 558 559 if(p is null) 560 { 561 return null; 562 } 563 564 return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p); 565 } 566 567 /** 568 * Looks up an icon in an icon theme, scales it to the given size 569 * and renders it into a pixbuf. This is a convenience function; 570 * if more details about the icon are needed, use 571 * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon(). 572 * Note that you probably want to listen for icon theme changes and 573 * update the icon. This is usually done by connecting to the 574 * GtkWidget::style-set signal. If for some reason you do not want to 575 * update the icon when the icon theme changes, you should consider 576 * using gdk_pixbuf_copy() to make a private copy of the pixbuf 577 * returned by this function. Otherwise GTK+ may need to keep the old 578 * icon theme loaded, which would be a waste of memory. 579 * Since 2.4 580 * Params: 581 * iconName = the name of the icon to lookup 582 * size = the desired icon size. The resulting icon may not be 583 * exactly this size; see gtk_icon_info_load_icon(). 584 * flags = flags modifying the behavior of the icon lookup 585 * Returns: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use g_object_unref() to release your reference to the icon. NULL if the icon isn't found. [transfer full] 586 * Throws: GException on failure. 587 */ 588 public Pixbuf loadIcon(string iconName, int size, GtkIconLookupFlags flags) 589 { 590 // GdkPixbuf * gtk_icon_theme_load_icon (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, GtkIconLookupFlags flags, GError **error); 591 GError* err = null; 592 593 auto p = gtk_icon_theme_load_icon(gtkIconTheme, Str.toStringz(iconName), size, flags, &err); 594 595 if (err !is null) 596 { 597 throw new GException( new ErrorG(err) ); 598 } 599 600 601 if(p is null) 602 { 603 return null; 604 } 605 606 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 607 } 608 609 /** 610 * Looks up an icon in an icon theme for a particular window scale, 611 * scales it to the given size and renders it into a pixbuf. This is a 612 * convenience function; if more details about the icon are needed, 613 * use gtk_icon_theme_lookup_icon() followed by 614 * gtk_icon_info_load_icon(). 615 * Note that you probably want to listen for icon theme changes and 616 * update the icon. This is usually done by connecting to the 617 * GtkWidget::style-set signal. If for some reason you do not want to 618 * update the icon when the icon theme changes, you should consider 619 * using gdk_pixbuf_copy() to make a private copy of the pixbuf 620 * returned by this function. Otherwise GTK+ may need to keep the old 621 * icon theme loaded, which would be a waste of memory. 622 * Params: 623 * iconName = the name of the icon to lookup 624 * size = the desired icon size. The resulting icon may not be 625 * exactly this size; see gtk_icon_info_load_icon(). 626 * scale = desired scale 627 * flags = flags modifying the behavior of the icon lookup 628 * Returns: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use g_object_unref() to release your reference to the icon. NULL if the icon isn't found. [transfer full] Since 3.10 629 * Throws: GException on failure. 630 */ 631 public Pixbuf loadIconForScale(string iconName, int size, int scale, GtkIconLookupFlags flags) 632 { 633 // GdkPixbuf * gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, gint scale, GtkIconLookupFlags flags, GError **error); 634 GError* err = null; 635 636 auto p = gtk_icon_theme_load_icon_for_scale(gtkIconTheme, Str.toStringz(iconName), size, scale, flags, &err); 637 638 if (err !is null) 639 { 640 throw new GException( new ErrorG(err) ); 641 } 642 643 644 if(p is null) 645 { 646 return null; 647 } 648 649 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 650 } 651 652 /** 653 * Looks up an icon in an icon theme for a particular window scale, 654 * scales it to the given size and renders it into a cairo surface. This is a 655 * convenience function; if more details about the icon are needed, 656 * use gtk_icon_theme_lookup_icon() followed by 657 * gtk_icon_info_load_surface(). 658 * Note that you probably want to listen for icon theme changes and 659 * update the icon. This is usually done by connecting to the 660 * GtkWidget::style-set signal. 661 * Params: 662 * iconName = the name of the icon to lookup 663 * size = the desired icon size. The resulting icon may not be 664 * exactly this size; see gtk_icon_info_load_icon(). 665 * scale = desired scale 666 * forWindow = GdkWindow to optimize drawing for, or NULL. [allow-none] 667 * flags = flags modifying the behavior of the icon lookup 668 * Returns: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use cairo_surface_destroy() to release your reference to the icon. NULL if the icon isn't found. [transfer full] Since 3.10 669 * Throws: GException on failure. 670 */ 671 public Surface loadSurface(string iconName, int size, int scale, Window forWindow, GtkIconLookupFlags flags) 672 { 673 // cairo_surface_t * gtk_icon_theme_load_surface (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, gint scale, GdkWindow *for_window, GtkIconLookupFlags flags, GError **error); 674 GError* err = null; 675 676 auto p = gtk_icon_theme_load_surface(gtkIconTheme, Str.toStringz(iconName), size, scale, (forWindow is null) ? null : forWindow.getWindowStruct(), flags, &err); 677 678 if (err !is null) 679 { 680 throw new GException( new ErrorG(err) ); 681 } 682 683 684 if(p is null) 685 { 686 return null; 687 } 688 689 return ObjectG.getDObject!(Surface)(cast(cairo_surface_t*) p); 690 } 691 692 /** 693 * Gets the list of contexts available within the current 694 * hierarchy of icon themes 695 * Since 2.12 696 * Returns: a GList list holding the names of all the contexts in the theme. You must first free each element in the list with g_free(), then free the list itself with g_list_free(). [element-type utf8][transfer full] 697 */ 698 public ListG listContexts() 699 { 700 // GList * gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme); 701 auto p = gtk_icon_theme_list_contexts(gtkIconTheme); 702 703 if(p is null) 704 { 705 return null; 706 } 707 708 return ObjectG.getDObject!(ListG)(cast(GList*) p); 709 } 710 711 /** 712 * Lists the icons in the current icon theme. Only a subset 713 * of the icons can be listed by providing a context string. 714 * The set of values for the context string is system dependent, 715 * but will typically include such values as "Applications" and 716 * "MimeTypes". 717 * Since 2.4 718 * Params: 719 * context = a string identifying a particular type of 720 * icon, or NULL to list all icons. [allow-none] 721 * Returns: a GList list holding the names of all the icons in the theme. You must first free each element in the list with g_free(), then free the list itself with g_list_free(). [element-type utf8][transfer full] 722 */ 723 public ListG listIcons(string context) 724 { 725 // GList * gtk_icon_theme_list_icons (GtkIconTheme *icon_theme, const gchar *context); 726 auto p = gtk_icon_theme_list_icons(gtkIconTheme, Str.toStringz(context)); 727 728 if(p is null) 729 { 730 return null; 731 } 732 733 return ObjectG.getDObject!(ListG)(cast(GList*) p); 734 } 735 736 /** 737 * Returns an array of integers describing the sizes at which 738 * the icon is available without scaling. A size of -1 means 739 * that the icon is available in a scalable format. The array 740 * is zero-terminated. 741 * Since 2.6 742 * Params: 743 * iconName = the name of an icon 744 * Returns: An newly allocated array describing the sizes at which the icon is available. The array should be freed with g_free() when it is no longer needed. [array zero-terminated=1] 745 */ 746 public int* getIconSizes(string iconName) 747 { 748 // gint * gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme, const gchar *icon_name); 749 return gtk_icon_theme_get_icon_sizes(gtkIconTheme, Str.toStringz(iconName)); 750 } 751 752 /** 753 * Gets the name of an icon that is representative of the 754 * current theme (for instance, to use when presenting 755 * a list of themes to the user.) 756 * Since 2.4 757 * Returns: the name of an example icon or NULL. Free with g_free(). 758 */ 759 public string getExampleIconName() 760 { 761 // char * gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme); 762 return Str.toString(gtk_icon_theme_get_example_icon_name(gtkIconTheme)); 763 } 764 765 /** 766 * Checks to see if the icon theme has changed; if it has, any 767 * currently cached information is discarded and will be reloaded 768 * next time icon_theme is accessed. 769 * Since 2.4 770 * Returns: TRUE if the icon theme has changed and needed to be reloaded. 771 */ 772 public int rescanIfNeeded() 773 { 774 // gboolean gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme); 775 return gtk_icon_theme_rescan_if_needed(gtkIconTheme); 776 } 777 778 /** 779 * Registers a built-in icon for icon theme lookups. The idea 780 * of built-in icons is to allow an application or library 781 * that uses themed icons to function requiring files to 782 * be present in the file system. For instance, the default 783 * images for all of GTK+'s stock icons are registered 784 * as built-icons. 785 * In general, if you use gtk_icon_theme_add_builtin_icon() 786 * you should also install the icon in the icon theme, so 787 * that the icon is generally available. 788 * This function will generally be used with pixbufs loaded 789 * via gdk_pixbuf_new_from_inline(). 790 * Since 2.4 791 * Params: 792 * iconName = the name of the icon to register 793 * size = the size at which to register the icon (different 794 * images can be registered for the same icon name 795 * at different sizes.) 796 * pixbuf = GdkPixbuf that contains the image to use 797 * for icon_name. 798 */ 799 public static void addBuiltinIcon(string iconName, int size, Pixbuf pixbuf) 800 { 801 // void gtk_icon_theme_add_builtin_icon (const gchar *icon_name, gint size, GdkPixbuf *pixbuf); 802 gtk_icon_theme_add_builtin_icon(Str.toStringz(iconName), size, (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 803 } 804 }