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