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