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.FontButton; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Button; 32 private import gtk.FontChooserIF; 33 private import gtk.FontChooserT; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 39 40 41 /** 42 * The #GtkFontButton is a button which displays the currently selected 43 * font an allows to open a font chooser dialog to change the font. 44 * It is suitable widget for selecting a font in a preference dialog. 45 * 46 * # CSS nodes 47 * 48 * GtkFontButton has a single CSS node with name button and style class .font. 49 */ 50 public class FontButton : Button, FontChooserIF 51 { 52 /** the main Gtk struct */ 53 protected GtkFontButton* gtkFontButton; 54 55 /** Get the main Gtk struct */ 56 public GtkFontButton* getFontButtonStruct(bool transferOwnership = false) 57 { 58 if (transferOwnership) 59 ownedRef = false; 60 return gtkFontButton; 61 } 62 63 /** the main Gtk struct as a void* */ 64 protected override void* getStruct() 65 { 66 return cast(void*)gtkFontButton; 67 } 68 69 protected override void setStruct(GObject* obj) 70 { 71 gtkFontButton = cast(GtkFontButton*)obj; 72 super.setStruct(obj); 73 } 74 75 /** 76 * Sets our main struct and passes it to the parent class. 77 */ 78 public this (GtkFontButton* gtkFontButton, bool ownedRef = false) 79 { 80 this.gtkFontButton = gtkFontButton; 81 super(cast(GtkButton*)gtkFontButton, ownedRef); 82 } 83 84 // add the FontChooser capabilities 85 mixin FontChooserT!(GtkFontButton); 86 87 88 /** */ 89 public static GType getType() 90 { 91 return gtk_font_button_get_type(); 92 } 93 94 /** 95 * Creates a new font picker widget. 96 * 97 * Returns: a new font picker widget. 98 * 99 * Since: 2.4 100 * 101 * Throws: ConstructionException GTK+ fails to create the object. 102 */ 103 public this() 104 { 105 auto p = gtk_font_button_new(); 106 107 if(p is null) 108 { 109 throw new ConstructionException("null returned by new"); 110 } 111 112 this(cast(GtkFontButton*) p); 113 } 114 115 /** 116 * Creates a new font picker widget. 117 * 118 * Params: 119 * fontname = Name of font to display in font chooser dialog 120 * 121 * Returns: a new font picker widget. 122 * 123 * Since: 2.4 124 * 125 * Throws: ConstructionException GTK+ fails to create the object. 126 */ 127 public this(string fontname) 128 { 129 auto p = gtk_font_button_new_with_font(Str.toStringz(fontname)); 130 131 if(p is null) 132 { 133 throw new ConstructionException("null returned by new_with_font"); 134 } 135 136 this(cast(GtkFontButton*) p); 137 } 138 139 /** 140 * Retrieves the name of the currently selected font. This name includes 141 * style and size information as well. If you want to render something 142 * with the font, use this string with pango_font_description_from_string() . 143 * If you’re interested in peeking certain values (family name, 144 * style, size, weight) just query these properties from the 145 * #PangoFontDescription object. 146 * 147 * Returns: an internal copy of the font name which must not be freed. 148 * 149 * Since: 2.4 150 */ 151 public string getFontName() 152 { 153 return Str.toString(gtk_font_button_get_font_name(gtkFontButton)); 154 } 155 156 /** 157 * Returns whether the font size will be shown in the label. 158 * 159 * Returns: whether the font size will be shown in the label. 160 * 161 * Since: 2.4 162 */ 163 public bool getShowSize() 164 { 165 return gtk_font_button_get_show_size(gtkFontButton) != 0; 166 } 167 168 /** 169 * Returns whether the name of the font style will be shown in the label. 170 * 171 * Returns: whether the font style will be shown in the label. 172 * 173 * Since: 2.4 174 */ 175 public bool getShowStyle() 176 { 177 return gtk_font_button_get_show_style(gtkFontButton) != 0; 178 } 179 180 /** 181 * Retrieves the title of the font chooser dialog. 182 * 183 * Returns: an internal copy of the title string which must not be freed. 184 * 185 * Since: 2.4 186 */ 187 public string getTitle() 188 { 189 return Str.toString(gtk_font_button_get_title(gtkFontButton)); 190 } 191 192 /** 193 * Returns whether the selected font is used in the label. 194 * 195 * Returns: whether the selected font is used in the label. 196 * 197 * Since: 2.4 198 */ 199 public bool getUseFont() 200 { 201 return gtk_font_button_get_use_font(gtkFontButton) != 0; 202 } 203 204 /** 205 * Returns whether the selected size is used in the label. 206 * 207 * Returns: whether the selected size is used in the label. 208 * 209 * Since: 2.4 210 */ 211 public bool getUseSize() 212 { 213 return gtk_font_button_get_use_size(gtkFontButton) != 0; 214 } 215 216 /** 217 * Sets or updates the currently-displayed font in font picker dialog. 218 * 219 * Params: 220 * fontname = Name of font to display in font chooser dialog 221 * 222 * Returns: %TRUE 223 * 224 * Since: 2.4 225 */ 226 public bool setFontName(string fontname) 227 { 228 return gtk_font_button_set_font_name(gtkFontButton, Str.toStringz(fontname)) != 0; 229 } 230 231 /** 232 * If @show_size is %TRUE, the font size will be displayed along with the name of the selected font. 233 * 234 * Params: 235 * showSize = %TRUE if font size should be displayed in dialog. 236 * 237 * Since: 2.4 238 */ 239 public void setShowSize(bool showSize) 240 { 241 gtk_font_button_set_show_size(gtkFontButton, showSize); 242 } 243 244 /** 245 * If @show_style is %TRUE, the font style will be displayed along with name of the selected font. 246 * 247 * Params: 248 * showStyle = %TRUE if font style should be displayed in label. 249 * 250 * Since: 2.4 251 */ 252 public void setShowStyle(bool showStyle) 253 { 254 gtk_font_button_set_show_style(gtkFontButton, showStyle); 255 } 256 257 /** 258 * Sets the title for the font chooser dialog. 259 * 260 * Params: 261 * title = a string containing the font chooser dialog title 262 * 263 * Since: 2.4 264 */ 265 public void setTitle(string title) 266 { 267 gtk_font_button_set_title(gtkFontButton, Str.toStringz(title)); 268 } 269 270 /** 271 * If @use_font is %TRUE, the font name will be written using the selected font. 272 * 273 * Params: 274 * useFont = If %TRUE, font name will be written using font chosen. 275 * 276 * Since: 2.4 277 */ 278 public void setUseFont(bool useFont) 279 { 280 gtk_font_button_set_use_font(gtkFontButton, useFont); 281 } 282 283 /** 284 * If @use_size is %TRUE, the font name will be written using the selected size. 285 * 286 * Params: 287 * useSize = If %TRUE, font name will be written using the selected size. 288 * 289 * Since: 2.4 290 */ 291 public void setUseSize(bool useSize) 292 { 293 gtk_font_button_set_use_size(gtkFontButton, useSize); 294 } 295 296 protected class OnFontSetDelegateWrapper 297 { 298 void delegate(FontButton) dlg; 299 gulong handlerId; 300 301 this(void delegate(FontButton) dlg) 302 { 303 this.dlg = dlg; 304 onFontSetListeners ~= this; 305 } 306 307 void remove(OnFontSetDelegateWrapper source) 308 { 309 foreach(index, wrapper; onFontSetListeners) 310 { 311 if (wrapper.handlerId == source.handlerId) 312 { 313 onFontSetListeners[index] = null; 314 onFontSetListeners = std.algorithm.remove(onFontSetListeners, index); 315 break; 316 } 317 } 318 } 319 } 320 OnFontSetDelegateWrapper[] onFontSetListeners; 321 322 /** 323 * The ::font-set signal is emitted when the user selects a font. 324 * When handling this signal, use gtk_font_button_get_font_name() 325 * to find out which font was just selected. 326 * 327 * Note that this signal is only emitted when the user 328 * changes the font. If you need to react to programmatic font changes 329 * as well, use the notify::font-name signal. 330 * 331 * Since: 2.4 332 */ 333 gulong addOnFontSet(void delegate(FontButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 334 { 335 auto wrapper = new OnFontSetDelegateWrapper(dlg); 336 wrapper.handlerId = Signals.connectData( 337 this, 338 "font-set", 339 cast(GCallback)&callBackFontSet, 340 cast(void*)wrapper, 341 cast(GClosureNotify)&callBackFontSetDestroy, 342 connectFlags); 343 return wrapper.handlerId; 344 } 345 346 extern(C) static void callBackFontSet(GtkFontButton* fontbuttonStruct, OnFontSetDelegateWrapper wrapper) 347 { 348 wrapper.dlg(wrapper.outer); 349 } 350 351 extern(C) static void callBackFontSetDestroy(OnFontSetDelegateWrapper wrapper, GClosure* closure) 352 { 353 wrapper.remove(wrapper); 354 } 355 }