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.FontChooserT; 26 27 public import glib.Str; 28 public import gobject.ObjectG; 29 public import gobject.Signals; 30 public import gtkc.gdktypes; 31 public import gtkc.gtk; 32 public import gtkc.gtktypes; 33 public import pango.PgFontDescription; 34 public import pango.PgFontFace; 35 public import pango.PgFontFamily; 36 public import pango.PgFontMap; 37 38 39 /** 40 * #GtkFontChooser is an interface that can be implemented by widgets 41 * displaying the list of fonts. In GTK+, the main objects 42 * that implement this interface are #GtkFontChooserWidget, 43 * #GtkFontChooserDialog and #GtkFontButton. The GtkFontChooser interface 44 * has been introducted in GTK+ 3.2. 45 */ 46 public template FontChooserT(TStruct) 47 { 48 /** Get the main Gtk struct */ 49 public GtkFontChooser* getFontChooserStruct() 50 { 51 return cast(GtkFontChooser*)getStruct(); 52 } 53 54 /** 55 */ 56 57 /** 58 * Gets the currently-selected font name. 59 * 60 * Note that this can be a different string than what you set with 61 * gtk_font_chooser_set_font(), as the font chooser widget may 62 * normalize font names and thus return a string with a different 63 * structure. For example, “Helvetica Italic Bold 12” could be 64 * normalized to “Helvetica Bold Italic 12”. 65 * 66 * Use pango_font_description_equal() if you want to compare two 67 * font descriptions. 68 * 69 * Return: A string with the name 70 * of the current font, or %NULL if no font is selected. You must 71 * free this string with g_free(). 72 * 73 * Since: 3.2 74 */ 75 public string getFont() 76 { 77 return Str.toString(gtk_font_chooser_get_font(getFontChooserStruct())); 78 } 79 80 /** 81 * Gets the currently-selected font. 82 * 83 * Note that this can be a different string than what you set with 84 * gtk_font_chooser_set_font(), as the font chooser widget may 85 * normalize font names and thus return a string with a different 86 * structure. For example, “Helvetica Italic Bold 12” could be 87 * normalized to “Helvetica Bold Italic 12”. 88 * 89 * Use pango_font_description_equal() if you want to compare two 90 * font descriptions. 91 * 92 * Return: A #PangoFontDescription for the 93 * current font, or %NULL if no font is selected. 94 * 95 * Since: 3.2 96 */ 97 public PgFontDescription getFontDesc() 98 { 99 auto p = gtk_font_chooser_get_font_desc(getFontChooserStruct()); 100 101 if(p is null) 102 { 103 return null; 104 } 105 106 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p); 107 } 108 109 /** 110 * Gets the #PangoFontFace representing the selected font group 111 * details (i.e. family, slant, weight, width, etc). 112 * 113 * If the selected font is not installed, returns %NULL. 114 * 115 * Return: A #PangoFontFace representing the 116 * selected font group details, or %NULL. The returned object is owned by 117 * @fontchooser and must not be modified or freed. 118 * 119 * Since: 3.2 120 */ 121 public PgFontFace getFontFace() 122 { 123 auto p = gtk_font_chooser_get_font_face(getFontChooserStruct()); 124 125 if(p is null) 126 { 127 return null; 128 } 129 130 return ObjectG.getDObject!(PgFontFace)(cast(PangoFontFace*) p); 131 } 132 133 /** 134 * Gets the #PangoFontFamily representing the selected font family. 135 * Font families are a collection of font faces. 136 * 137 * If the selected font is not installed, returns %NULL. 138 * 139 * Return: A #PangoFontFamily representing the 140 * selected font family, or %NULL. The returned object is owned by @fontchooser 141 * and must not be modified or freed. 142 * 143 * Since: 3.2 144 */ 145 public PgFontFamily getFontFamily() 146 { 147 auto p = gtk_font_chooser_get_font_family(getFontChooserStruct()); 148 149 if(p is null) 150 { 151 return null; 152 } 153 154 return ObjectG.getDObject!(PgFontFamily)(cast(PangoFontFamily*) p); 155 } 156 157 /** 158 * Gets the custom font map of this font chooser widget, 159 * or %NULL if it does not have one. 160 * 161 * Return: a #PangoFontMap, or %NULL 162 * 163 * Since: 3.18 164 */ 165 public override PgFontMap getFontMap() 166 { 167 auto p = gtk_font_chooser_get_font_map(getFontChooserStruct()); 168 169 if(p is null) 170 { 171 return null; 172 } 173 174 return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) p, true); 175 } 176 177 /** 178 * The selected font size. 179 * 180 * Return: A n integer representing the selected font size, 181 * or -1 if no font size is selected. 182 * 183 * Since: 3.2 184 */ 185 public int getFontSize() 186 { 187 return gtk_font_chooser_get_font_size(getFontChooserStruct()); 188 } 189 190 /** 191 * Gets the text displayed in the preview area. 192 * 193 * Return: the text displayed in the 194 * preview area 195 * 196 * Since: 3.2 197 */ 198 public string getPreviewText() 199 { 200 return Str.toString(gtk_font_chooser_get_preview_text(getFontChooserStruct())); 201 } 202 203 /** 204 * Returns whether the preview entry is shown or not. 205 * 206 * Return: %TRUE if the preview entry is shown 207 * or %FALSE if it is hidden. 208 * 209 * Since: 3.2 210 */ 211 public bool getShowPreviewEntry() 212 { 213 return gtk_font_chooser_get_show_preview_entry(getFontChooserStruct()) != 0; 214 } 215 216 /** 217 * Adds a filter function that decides which fonts to display 218 * in the font chooser. 219 * 220 * Params: 221 * filter = a #GtkFontFilterFunc, or %NULL 222 * userData = data to pass to @filter 223 * destroy = function to call to free @data when it is no longer needed 224 * 225 * Since: 3.2 226 */ 227 public void setFilterFunc(GtkFontFilterFunc filter, void* userData, GDestroyNotify destroy) 228 { 229 gtk_font_chooser_set_filter_func(getFontChooserStruct(), filter, userData, destroy); 230 } 231 232 /** 233 * Sets the currently-selected font. 234 * 235 * Params: 236 * fontname = a font name like “Helvetica 12” or “Times Bold 18” 237 * 238 * Since: 3.2 239 */ 240 public void setFont(string fontname) 241 { 242 gtk_font_chooser_set_font(getFontChooserStruct(), Str.toStringz(fontname)); 243 } 244 245 /** 246 * Sets the currently-selected font from @font_desc. 247 * 248 * Params: 249 * fontDesc = a #PangoFontDescription 250 * 251 * Since: 3.2 252 */ 253 public void setFontDesc(PgFontDescription fontDesc) 254 { 255 gtk_font_chooser_set_font_desc(getFontChooserStruct(), (fontDesc is null) ? null : fontDesc.getPgFontDescriptionStruct()); 256 } 257 258 /** 259 * Sets a custom font map to use for this font chooser widget. 260 * A custom font map can be used to present application-specific 261 * fonts instead of or in addition to the normal system fonts. 262 * 263 * |[<!-- language="C" --> 264 * FcConfig *config; 265 * PangoFontMap *fontmap; 266 * 267 * config = FcInitLoadConfigAndFonts (); 268 * FcConfigAppFontAddFile (config, my_app_font_file); 269 * 270 * fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT); 271 * pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config); 272 * 273 * gtk_font_chooser_set_font_map (font_chooser, fontmap); 274 * ]| 275 * 276 * Note that other GTK+ widgets will only be able to use the application-specific 277 * font if it is present in the font map they use: 278 * 279 * |[ 280 * context = gtk_widget_get_pango_context (label); 281 * pango_context_set_font_map (context, fontmap); 282 * ]| 283 * 284 * Params: 285 * fontmap = a #PangoFontMap 286 * 287 * Since: 3.18 288 */ 289 public override void setFontMap(PgFontMap fontmap) 290 { 291 gtk_font_chooser_set_font_map(getFontChooserStruct(), (fontmap is null) ? null : fontmap.getPgFontMapStruct()); 292 } 293 294 /** 295 * Sets the text displayed in the preview area. 296 * The @text is used to show how the selected font looks. 297 * 298 * Params: 299 * text = the text to display in the preview area 300 * 301 * Since: 3.2 302 */ 303 public void setPreviewText(string text) 304 { 305 gtk_font_chooser_set_preview_text(getFontChooserStruct(), Str.toStringz(text)); 306 } 307 308 /** 309 * Shows or hides the editable preview entry. 310 * 311 * Params: 312 * showPreviewEntry = whether to show the editable preview entry or not 313 * 314 * Since: 3.2 315 */ 316 public void setShowPreviewEntry(bool showPreviewEntry) 317 { 318 gtk_font_chooser_set_show_preview_entry(getFontChooserStruct(), showPreviewEntry); 319 } 320 321 int[string] connectedSignals; 322 323 void delegate(string, FontChooserIF)[] _onFontActivatedListeners; 324 @property void delegate(string, FontChooserIF)[] onFontActivatedListeners() 325 { 326 return _onFontActivatedListeners; 327 } 328 /** 329 * Emitted when a font is activated. 330 * This usually happens when the user double clicks an item, 331 * or an item is selected and the user presses one of the keys 332 * Space, Shift+Space, Return or Enter. 333 * 334 * Params: 335 * fontname = the font name 336 */ 337 void addOnFontActivated(void delegate(string, FontChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 338 { 339 if ( "font-activated" !in connectedSignals ) 340 { 341 Signals.connectData( 342 this, 343 "font-activated", 344 cast(GCallback)&callBackFontActivated, 345 cast(void*)cast(FontChooserIF)this, 346 null, 347 connectFlags); 348 connectedSignals["font-activated"] = 1; 349 } 350 _onFontActivatedListeners ~= dlg; 351 } 352 extern(C) static void callBackFontActivated(GtkFontChooser* fontchooserStruct, char* fontname, FontChooserIF _fontchooser) 353 { 354 foreach ( void delegate(string, FontChooserIF) dlg; _fontchooser.onFontActivatedListeners ) 355 { 356 dlg(Str.toString(fontname), _fontchooser); 357 } 358 } 359 }