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