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