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