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.IconSet; 26 27 private import cairo.Surface; 28 private import gdk.Window; 29 private import gdkpixbuf.Pixbuf; 30 private import glib.ConstructionException; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gtk.IconSource; 34 private import gtk.Style; 35 private import gtk.StyleContext; 36 private import gtk.Widget; 37 private import gtkc.Loader; 38 private import gtkc.gtk; 39 public import gtkc.gtktypes; 40 private import gtkc.paths; 41 42 43 public class IconSet 44 { 45 /** the main Gtk struct */ 46 protected GtkIconSet* gtkIconSet; 47 48 /** Get the main Gtk struct */ 49 public GtkIconSet* getIconSetStruct() 50 { 51 return gtkIconSet; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected void* getStruct() 56 { 57 return cast(void*)gtkIconSet; 58 } 59 60 /** 61 * Sets our main struct and passes it to the parent class. 62 */ 63 public this (GtkIconSet* gtkIconSet) 64 { 65 this.gtkIconSet = gtkIconSet; 66 } 67 68 ~this () 69 { 70 if ( Linker.isLoaded(LIBRARY.GTK) && gtkIconSet !is null ) 71 { 72 gtk_icon_set_unref(gtkIconSet); 73 } 74 } 75 76 /** 77 */ 78 79 public static GType getType() 80 { 81 return gtk_icon_set_get_type(); 82 } 83 84 /** 85 * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon 86 * in various sizes and widget states. It can provide a #GdkPixbuf 87 * for a given size and state on request, and automatically caches 88 * some of the rendered #GdkPixbuf objects. 89 * 90 * Normally you would use gtk_widget_render_icon_pixbuf() instead of 91 * using #GtkIconSet directly. The one case where you’d use 92 * #GtkIconSet is to create application-specific icon sets to place in 93 * a #GtkIconFactory. 94 * 95 * Deprecated: Use #GtkIconTheme instead. 96 * 97 * Return: a new #GtkIconSet 98 * 99 * Throws: ConstructionException GTK+ fails to create the object. 100 */ 101 public this() 102 { 103 auto p = gtk_icon_set_new(); 104 105 if(p is null) 106 { 107 throw new ConstructionException("null returned by new"); 108 } 109 110 this(cast(GtkIconSet*) p); 111 } 112 113 /** 114 * Creates a new #GtkIconSet with @pixbuf as the default/fallback 115 * source image. If you don’t add any additional #GtkIconSource to the 116 * icon set, all variants of the icon will be created from @pixbuf, 117 * using scaling, pixelation, etc. as required to adjust the icon size 118 * or make the icon look insensitive/prelighted. 119 * 120 * Deprecated: Use #GtkIconTheme instead. 121 * 122 * Params: 123 * pixbuf = a #GdkPixbuf 124 * 125 * Return: a new #GtkIconSet 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this(Pixbuf pixbuf) 130 { 131 auto p = gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct()); 132 133 if(p is null) 134 { 135 throw new ConstructionException("null returned by new_from_pixbuf"); 136 } 137 138 this(cast(GtkIconSet*) p); 139 } 140 141 /** 142 * Icon sets have a list of #GtkIconSource, which they use as base 143 * icons for rendering icons in different states and sizes. Icons are 144 * scaled, made to look insensitive, etc. in 145 * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to 146 * work with. The base images and when to use them are described by 147 * a #GtkIconSource. 148 * 149 * This function copies @source, so you can reuse the same source immediately 150 * without affecting the icon set. 151 * 152 * An example of when you’d use this function: a web browser’s "Back 153 * to Previous Page" icon might point in a different direction in 154 * Hebrew and in English; it might look different when insensitive; 155 * and it might change size depending on toolbar mode (small/large 156 * icons). So a single icon set would contain all those variants of 157 * the icon, and you might add a separate source for each one. 158 * 159 * You should nearly always add a “default” icon source with all 160 * fields wildcarded, which will be used as a fallback if no more 161 * specific source matches. #GtkIconSet always prefers more specific 162 * icon sources to more generic icon sources. The order in which you 163 * add the sources to the icon set does not matter. 164 * 165 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a 166 * default icon source based on the given pixbuf. 167 * 168 * Deprecated: Use #GtkIconTheme instead. 169 * 170 * Params: 171 * source = a #GtkIconSource 172 */ 173 public void addSource(IconSource source) 174 { 175 gtk_icon_set_add_source(gtkIconSet, (source is null) ? null : source.getIconSourceStruct()); 176 } 177 178 /** 179 * Copies @icon_set by value. 180 * 181 * Deprecated: Use #GtkIconTheme instead. 182 * 183 * Return: a new #GtkIconSet identical to the first. 184 */ 185 public IconSet copy() 186 { 187 auto p = gtk_icon_set_copy(gtkIconSet); 188 189 if(p is null) 190 { 191 return null; 192 } 193 194 return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p); 195 } 196 197 /** 198 * Obtains a list of icon sizes this icon set can render. The returned 199 * array must be freed with g_free(). 200 * 201 * Deprecated: Use #GtkIconTheme instead. 202 * 203 * Params: 204 * sizes = return location 205 * for array of sizes 206 * nSizes = location to store number of elements in returned array 207 */ 208 public void getSizes(out GtkIconSize[] sizes) 209 { 210 GtkIconSize* outsizes = null; 211 int nSizes; 212 213 gtk_icon_set_get_sizes(gtkIconSet, &outsizes, &nSizes); 214 215 sizes = outsizes[0 .. nSizes]; 216 } 217 218 /** 219 * Increments the reference count on @icon_set. 220 * 221 * Deprecated: Use #GtkIconTheme instead. 222 * 223 * Return: @icon_set. 224 */ 225 public IconSet doref() 226 { 227 auto p = gtk_icon_set_ref(gtkIconSet); 228 229 if(p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p); 235 } 236 237 /** 238 * Renders an icon using gtk_style_render_icon(). In most cases, 239 * gtk_widget_render_icon() is better, since it automatically provides 240 * most of the arguments from the current widget settings. This 241 * function never returns %NULL; if the icon can’t be rendered 242 * (perhaps because an image file fails to load), a default "missing 243 * image" icon will be returned instead. 244 * 245 * Deprecated: Use gtk_icon_set_render_icon_pixbuf() instead 246 * 247 * Params: 248 * style = a #GtkStyle associated with @widget, or %NULL 249 * direction = text direction 250 * state = widget state 251 * size = icon size. A size of (GtkIconSize)-1 252 * means render at the size of the source and don’t scale. 253 * widget = widget that will display the icon, or %NULL. 254 * The only use that is typically made of this 255 * is to determine the appropriate #GdkScreen. 256 * detail = detail to pass to the theme engine, or %NULL. 257 * Note that passing a detail of anything but %NULL 258 * will disable caching. 259 * 260 * Return: a #GdkPixbuf to be displayed 261 */ 262 public Pixbuf renderIcon(Style style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, Widget widget, string detail) 263 { 264 auto p = gtk_icon_set_render_icon(gtkIconSet, (style is null) ? null : style.getStyleStruct(), direction, state, size, (widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(detail)); 265 266 if(p is null) 267 { 268 return null; 269 } 270 271 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true); 272 } 273 274 /** 275 * Renders an icon using gtk_render_icon_pixbuf(). In most cases, 276 * gtk_widget_render_icon_pixbuf() is better, since it automatically provides 277 * most of the arguments from the current widget settings. This 278 * function never returns %NULL; if the icon can’t be rendered 279 * (perhaps because an image file fails to load), a default "missing 280 * image" icon will be returned instead. 281 * 282 * Deprecated: Use #GtkIconTheme instead. 283 * 284 * Params: 285 * context = a #GtkStyleContext 286 * size = icon size. A size of (GtkIconSize)-1 287 * means render at the size of the source and don’t scale. 288 * 289 * Return: a #GdkPixbuf to be displayed 290 * 291 * Since: 3.0 292 */ 293 public Pixbuf renderIconPixbuf(StyleContext context, GtkIconSize size) 294 { 295 auto p = gtk_icon_set_render_icon_pixbuf(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size); 296 297 if(p is null) 298 { 299 return null; 300 } 301 302 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true); 303 } 304 305 /** 306 * Renders an icon using gtk_render_icon_pixbuf() and converts it to a 307 * cairo surface. 308 * 309 * This function never returns %NULL; if the icon can’t be rendered 310 * (perhaps because an image file fails to load), a default "missing 311 * image" icon will be returned instead. 312 * 313 * Deprecated: Use #GtkIconTheme instead. 314 * 315 * Params: 316 * context = a #GtkStyleContext 317 * size = icon size. A size of (GtkIconSize)-1 318 * means render at the size of the source and don’t scale. 319 * scale = the window scale to render for 320 * forWindow = #GdkWindow to optimize drawing for, or %NULL 321 * 322 * Return: a #cairo_surface_t to be displayed 323 * 324 * Since: 3.10 325 */ 326 public Surface renderIconSurface(StyleContext context, GtkIconSize size, int scale, Window forWindow) 327 { 328 auto p = gtk_icon_set_render_icon_surface(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size, scale, (forWindow is null) ? null : forWindow.getWindowStruct()); 329 330 if(p is null) 331 { 332 return null; 333 } 334 335 return new Surface(cast(cairo_surface_t*) p); 336 } 337 338 /** 339 * Decrements the reference count on @icon_set, and frees memory 340 * if the reference count reaches 0. 341 * 342 * Deprecated: Use #GtkIconTheme instead. 343 */ 344 public void unref() 345 { 346 gtk_icon_set_unref(gtkIconSet); 347 } 348 }