alternative to assert
[gtkD.git] / gtkD / src / gtk / IconTheme.d
blobe56d3e2d0370259848753b504688c4fd20da620f
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkIconTheme.html
26 * outPack = gtk
27 * outFile = IconTheme
28 * strct = GtkIconTheme
29 * realStrct=
30 * ctorStrct=
31 * clss = IconTheme
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_icon_theme_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * - gtk_icon_info_
44 * omit code:
45 * imports:
46 * - glib.Str
47 * - gtk.IconTheme
48 * - gdk.Screen
49 * - gtk.IconInfo
50 * - gdk.Pixbuf
51 * - glib.ListG
52 * structWrap:
53 * - GList* -> ListG
54 * - GdkPixbuf* -> Pixbuf
55 * - GdkScreen* -> Screen
56 * - GtkIconInfo* -> IconInfo
57 * - GtkIconTheme* -> IconTheme
58 * module aliases:
59 * local aliases:
62 module gtk.IconTheme;
64 version(noAssert)
66 version(Tango)
68 import tango.io.Stdout; // use the tango loging?
72 private import gtkc.gtktypes;
74 private import gtkc.gtk;
77 private import glib.Str;
78 private import gtk.IconTheme;
79 private import gdk.Screen;
80 private import gtk.IconInfo;
81 private import gdk.Pixbuf;
82 private import glib.ListG;
87 /**
88 * Description
89 * GtkIconTheme provides a facility for looking up icons by name
90 * and size. The main reason for using a name rather than simply
91 * providing a filename is to allow different icons to be used
92 * depending on what icon theme is selecetd
93 * by the user. The operation of icon themes on Linux and Unix
94 * follows the Icon
95 * Theme Specification. There is a default icon theme,
96 * named hicolor where applications should install
97 * their icons, but more additional application themes can be
98 * installed as operating system vendors and users choose.
99 * Named icons are similar to the Themeable Stock Images(3)
100 * facility, and the distinction between the two may be a bit confusing.
101 * A few things to keep in mind:
102 * Stock images usually are used in conjunction with
103 * Stock Items(3)., such as GTK_STOCK_OK or
104 * GTK_STOCK_OPEN. Named icons are easier to set up and therefore
105 * are more useful for new icons that an application wants to
106 * add, such as application icons or window icons.
107 * Stock images can only be loaded at the symbolic sizes defined
108 * by the GtkIconSize enumeration, or by custom sizes defined
109 * by gtk_icon_size_register(), while named icons are more flexible
110 * and any pixel size can be specified.
111 * Because stock images are closely tied to stock items, and thus
112 * to actions in the user interface, stock images may come in
113 * multiple variants for different widget states or writing
114 * directions.
115 * A good rule of thumb is that if there is a stock image for what
116 * you want to use, use it, otherwise use a named icon. It turns
117 * out that internally stock images are generally defined in
118 * terms of one or more named icons. (An example of the
119 * more than one case is icons that depend on writing direction;
120 * GTK_STOCK_GO_FORWARD uses the two themed icons
121 * "gtk-stock-go-forward-ltr" and "gtk-stock-go-forward-rtl".)
122 * In many cases, named themes are used indirectly, via GtkImage
123 * or stock items, rather than directly, but looking up icons
124 * directly is also simple. The GtkIconTheme object acts
125 * as a database of all the icons in the current theme. You
126 * can create new GtkIconTheme objects, but its much more
127 * efficient to use the standard icon theme for the GdkScreen
128 * so that the icon information is shared with other people
129 * looking up icons. In the case where the default screen is
130 * being used, looking up an icon can be as simple as:
131 * GError *error = NULL;
132 * GtkIconTheme *icon_theme;
133 * GdkPixbuf *pixbuf;
134 * icon_theme = gtk_icon_theme_get_default ();
135 * pixbuf = gtk_icon_theme_load_icon (icon_theme,
136 * "my-icon-name", /+* icon name +/
137 * 48, /+* size +/
138 * 0, /+* flags +/
139 * error);
140 * if (!pixbuf)
142 * g_warning ("Couldn't load icon: %s", error->message);
143 * g_error_free (error);
145 * else
147 * /+* Use the pixbuf +/
148 * g_object_unref (pixbuf);
151 private import gobject.ObjectG;
152 public class IconTheme : ObjectG
155 /** the main Gtk struct */
156 protected GtkIconTheme* gtkIconTheme;
159 public GtkIconTheme* getIconThemeStruct()
161 return gtkIconTheme;
165 /** the main Gtk struct as a void* */
166 protected void* getStruct()
168 return cast(void*)gtkIconTheme;
172 * Sets our main struct and passes it to the parent class
174 public this (GtkIconTheme* gtkIconTheme)
176 version(noAssert)
178 if ( gtkIconTheme is null )
180 int zero = 0;
181 version(Tango)
183 Stdout("struct gtkIconTheme is null on constructor").newline;
185 else
187 printf("struct gtkIconTheme is null on constructor");
189 zero = zero / zero;
192 else
194 assert(gtkIconTheme !is null, "struct gtkIconTheme is null on constructor");
196 super(cast(GObject*)gtkIconTheme);
197 this.gtkIconTheme = gtkIconTheme;
203 // imports for the signal processing
204 private import gobject.Signals;
205 private import gtkc.gdktypes;
206 int[char[]] connectedSignals;
208 void delegate(IconTheme)[] onChangedListeners;
209 void addOnChanged(void delegate(IconTheme) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
211 if ( !("changed" in connectedSignals) )
213 Signals.connectData(
214 getStruct(),
215 "changed",
216 cast(GCallback)&callBackChanged,
217 cast(void*)this,
218 null,
219 connectFlags);
220 connectedSignals["changed"] = 1;
222 onChangedListeners ~= dlg;
224 extern(C) static void callBackChanged(GtkIconTheme* iconThemeStruct, IconTheme iconTheme)
226 bool consumed = false;
228 foreach ( void delegate(IconTheme) dlg ; iconTheme.onChangedListeners )
230 dlg(iconTheme);
233 return consumed;
243 * Creates a new icon theme object. Icon theme objects are used
244 * to lookup up an icon by name in a particular icon theme.
245 * Usually, you'll want to use gtk_icon_theme_get_default()
246 * or gtk_icon_theme_get_for_screen() rather than creating
247 * a new icon theme object for scratch.
248 * Returns:
249 * the newly created GtkIconTheme object.
250 * Since 2.4
252 public this ()
254 // GtkIconTheme* gtk_icon_theme_new (void);
255 this(cast(GtkIconTheme*)gtk_icon_theme_new() );
259 * Gets the icon theme for the default screen. See
260 * gtk_icon_theme_get_for_screen().
261 * Returns:
262 * A unique GtkIconTheme associated with
263 * the default screen. This icon theme is associated with
264 * the screen and can be used as long as the screen
265 * is open. Do not ref or unref it.
266 * Since 2.4
268 public static IconTheme getDefault()
270 // GtkIconTheme* gtk_icon_theme_get_default (void);
271 return new IconTheme( gtk_icon_theme_get_default() );
275 * Gets the icon theme object associated with screen; if this
276 * function has not previously been called for the given
277 * screen, a new icon theme object will be created and
278 * associated with the screen. Icon theme objects are
279 * fairly expensive to create, so using this function
280 * is usually a better choice than calling than gtk_icon_theme_new()
281 * and setting the screen yourself; by using this function
282 * a single icon theme object will be shared between users.
283 * screen:
284 * a GdkScreen
285 * Returns:
286 * A unique GtkIconTheme associated with
287 * the given screen. This icon theme is associated with
288 * the screen and can be used as long as the screen
289 * is open. Do not ref or unref it.
290 * Since 2.4
292 public static IconTheme getForScreen(Screen screen)
294 // GtkIconTheme* gtk_icon_theme_get_for_screen (GdkScreen *screen);
295 return new IconTheme( gtk_icon_theme_get_for_screen((screen is null) ? null : screen.getScreenStruct()) );
299 * Sets the screen for an icon theme; the screen is used
300 * to track the user's currently configured icon theme,
301 * which might be different for different screens.
302 * icon_theme:
303 * a GtkIconTheme
304 * screen:
305 * a GdkScreen
306 * Since 2.4
308 public void setScreen(Screen screen)
310 // void gtk_icon_theme_set_screen (GtkIconTheme *icon_theme, GdkScreen *screen);
311 gtk_icon_theme_set_screen(gtkIconTheme, (screen is null) ? null : screen.getScreenStruct());
315 * Sets the search path for the icon theme object. When looking
316 * for an icon theme, GTK+ will search for a subdirectory of
317 * one or more of the directories in path with the same name
318 * as the icon theme. (Themes from multiple of the path elements
319 * are combined to allow themes to be extended by adding icons
320 * in the user's home directory.)
321 * In addition if an icon found isn't found either in the current
322 * icon theme or the default icon theme, and an image file with
323 * the right name is found directly in one of the elements of
324 * path, then that image will be used for the icon name.
325 * (This is legacy feature, and new icons should be put
326 * into the default icon theme, which is called DEFAULT_THEME_NAME,
327 * rather than directly on the icon path.)
328 * icon_theme:
329 * a GtkIconTheme
330 * path:
331 * array of directories that are searched for icon themes
332 * n_elements:
333 * number of elements in path.
334 * Since 2.4
336 public void setSearchPath(char*[] path, int nElements)
338 // void gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme, const gchar *path[], gint n_elements);
339 gtk_icon_theme_set_search_path(gtkIconTheme, path, nElements);
343 * Gets the current search path. See gtk_icon_theme_set_search_path().
344 * icon_theme:
345 * a GtkIconTheme
346 * path:
347 * location to store a list of icon theme path directories or NULL
348 * The stored value should be freed with g_strfreev().
349 * n_elements:
350 * location to store number of elements
351 * in path, or NULL
352 * Since 2.4
354 public void getSearchPath(char**[] path, int* nElements)
356 // void gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme, gchar **path[], gint *n_elements);
357 gtk_icon_theme_get_search_path(gtkIconTheme, path, nElements);
361 * Appends a directory to the search path.
362 * See gtk_icon_theme_set_search_path().
363 * icon_theme:
364 * a GtkIconTheme
365 * path:
366 * directory name to append to the icon path
367 * Since 2.4
369 public void appendSearchPath(char[] path)
371 // void gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme, const gchar *path);
372 gtk_icon_theme_append_search_path(gtkIconTheme, Str.toStringz(path));
376 * Prepends a directory to the search path.
377 * See gtk_icon_theme_set_search_path().
378 * icon_theme:
379 * a GtkIconTheme
380 * path:
381 * directory name to prepend to the icon path
382 * Since 2.4
384 public void prependSearchPath(char[] path)
386 // void gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme, const gchar *path);
387 gtk_icon_theme_prepend_search_path(gtkIconTheme, Str.toStringz(path));
391 * Sets the name of the icon theme that the GtkIconTheme object uses
392 * overriding system configuration. This function cannot be called
393 * on the icon theme objects returned from gtk_icon_theme_get_default()
394 * and gtk_icon_theme_get_for_screen().
395 * icon_theme:
396 * a GtkIconTheme
397 * theme_name:
398 * name of icon theme to use instead of configured theme,
399 * or NULL to unset a previously set custom theme
400 * Since 2.4
402 public void setCustomTheme(char[] themeName)
404 // void gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme, const gchar *theme_name);
405 gtk_icon_theme_set_custom_theme(gtkIconTheme, Str.toStringz(themeName));
409 * Checks whether an icon theme includes an icon
410 * for a particular name.
411 * icon_theme:
412 * a GtkIconTheme
413 * icon_name:
414 * the name of an icon
415 * Returns:
416 * TRUE if icon_theme includes an
417 * icon for icon_name.
418 * Since 2.4
420 public int hasIcon(char[] iconName)
422 // gboolean gtk_icon_theme_has_icon (GtkIconTheme *icon_theme, const gchar *icon_name);
423 return gtk_icon_theme_has_icon(gtkIconTheme, Str.toStringz(iconName));
427 * Looks up a named icon and returns a structure containing
428 * information such as the filename of the icon. The icon
429 * can then be rendered into a pixbuf using
430 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
431 * combines these two steps if all you need is the pixbuf.)
432 * icon_theme:
433 * a GtkIconTheme
434 * icon_name:
435 * the name of the icon to lookup
436 * size:
437 * desired icon size
438 * flags:
439 * flags modifying the behavior of the icon lookup
440 * Returns:
441 * a GtkIconInfo structure containing information
442 * about the icon, or NULL if the icon wasn't found. Free with
443 * gtk_icon_info_free()
444 * Since 2.4
446 public IconInfo lookupIcon(char[] iconName, int size, GtkIconLookupFlags flags)
448 // GtkIconInfo* gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, GtkIconLookupFlags flags);
449 return new IconInfo( gtk_icon_theme_lookup_icon(gtkIconTheme, Str.toStringz(iconName), size, flags) );
453 * Looks up an icon in an icon theme, scales it to the given size
454 * and renders it into a pixbuf. This is a convenience function;
455 * if more details about the icon are needed, use
456 * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
457 * Note that you probably want to listen for icon theme changes and
458 * update the icon. This is usually done by connecting to the
459 * GtkWidget::style-set signal. If for some reason you do not want to
460 * update the icon when the icon theme changes, you should consider
461 * using gdk_pixbuf_copy() to make a private copy of the pixbuf
462 * returned by this function. Otherwise GTK+ may need to keep the old
463 * icon theme loaded, which would be a waste of memory.
464 * icon_theme:
465 * a GtkIconTheme
466 * icon_name:
467 * the name of the icon to lookup
468 * size:
469 * the desired icon size. The resulting icon may not be
470 * exactly this size; see gtk_icon_info_load_icon().
471 * flags:
472 * flags modifying the behavior of the icon lookup
473 * error:
474 * Location to store error information on failure, or NULL.
475 * Returns:
476 * the rendered icon; this may be a newly created icon
477 * or a new reference to an internal icon, so you must not modify
478 * the icon. Use g_object_unref() to release your reference to the
479 * icon. NULL if the icon isn't found.
480 * Since 2.4
482 public Pixbuf loadIcon(char[] iconName, int size, GtkIconLookupFlags flags, GError** error)
484 // GdkPixbuf* gtk_icon_theme_load_icon (GtkIconTheme *icon_theme, const gchar *icon_name, gint size, GtkIconLookupFlags flags, GError **error);
485 return new Pixbuf( gtk_icon_theme_load_icon(gtkIconTheme, Str.toStringz(iconName), size, flags, error) );
489 * Lists the icons in the current icon theme. Only a subset
490 * of the icons can be listed by providing a context string.
491 * The set of values for the context string is system dependent,
492 * but will typically include such values as "Applications" and
493 * "MimeTypes".
494 * icon_theme:
495 * a GtkIconTheme
496 * context:
497 * a string identifying a particular type of icon,
498 * or NULL to list all icons.
499 * Returns:
500 * a GList list holding the names of all the
501 * icons in the theme. You must first free each element
502 * in the list with g_free(), then free the list itself
503 * with g_list_free().
504 * Since 2.4
506 public ListG listIcons(char[] context)
508 // GList* gtk_icon_theme_list_icons (GtkIconTheme *icon_theme, const gchar *context);
509 return new ListG( gtk_icon_theme_list_icons(gtkIconTheme, Str.toStringz(context)) );
513 * Returns an array of integers describing the sizes at which
514 * the icon is available without scaling. A size of -1 means
515 * that the icon is available in a scalable format. The array
516 * is zero-terminated.
517 * icon_theme:
518 * a GtkIconTheme
519 * icon_name:
520 * the name of an icon
521 * Returns:
522 * An newly allocated array describing the sizes at
523 * which the icon is available. The array should be freed with g_free()
524 * when it is no longer needed.
525 * Since 2.6
527 public int* getIconSizes(char[] iconName)
529 // gint* gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme, const gchar *icon_name);
530 return gtk_icon_theme_get_icon_sizes(gtkIconTheme, Str.toStringz(iconName));
534 * Gets the name of an icon that is representative of the
535 * current theme (for instance, to use when presenting
536 * a list of themes to the user.)
537 * icon_theme:
538 * a GtkIconTheme
539 * Returns:
540 * the name of an example icon or NULL.
541 * Free with g_free().
542 * Since 2.4
544 public char[] getExampleIconName()
546 // char* gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme);
547 return Str.toString(gtk_icon_theme_get_example_icon_name(gtkIconTheme) );
551 * Checks to see if the icon theme has changed; if it has, any
552 * currently cached information is discarded and will be reloaded
553 * next time icon_theme is accessed.
554 * icon_theme:
555 * a GtkIconTheme
556 * Returns:
557 * TRUE if the icon theme has changed and needed
558 * to be reloaded.
559 * Since 2.4
561 public int rescanIfNeeded()
563 // gboolean gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme);
564 return gtk_icon_theme_rescan_if_needed(gtkIconTheme);
568 * Registers a built-in icon for icon theme lookups. The idea
569 * of built-in icons is to allow an application or library
570 * that uses themed icons to function requiring files to
571 * be present in the file system. For instance, the default
572 * images for all of GTK+'s stock icons are registered
573 * as built-icons.
574 * In general, if you use gtk_icon_theme_add_builtin_icon()
575 * you should also install the icon in the icon theme, so
576 * that the icon is generally available.
577 * This function will generally be used with pixbufs loaded
578 * via gdk_pixbuf_new_from_inline().
579 * icon_name:
580 * the name of the icon to register
581 * size:
582 * the size at which to register the icon (different
583 * images can be registered for the same icon name
584 * at different sizes.)
585 * pixbuf:
586 * GdkPixbuf that contains the image to use
587 * for icon_name.
588 * Since 2.4
590 public static void addBuiltinIcon(char[] iconName, int size, Pixbuf pixbuf)
592 // void gtk_icon_theme_add_builtin_icon (const gchar *icon_name, gint size, GdkPixbuf *pixbuf);
593 gtk_icon_theme_add_builtin_icon(Str.toStringz(iconName), size, (pixbuf is null) ? null : pixbuf.getPixbufStruct());