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