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 		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 	 * Gets the custom font map of this font chooser widget,
157 	 * or %NULL if it does not have one.
158 	 *
159 	 * Return: a #PangoFontMap, or %NULL
160 	 *
161 	 * Since: 3.18
162 	 */
163 	public override PgFontMap getFontMap()
164 	{
165 		auto p = gtk_font_chooser_get_font_map(getFontChooserStruct());
166 		
167 		if(p is null)
168 		{
169 			return null;
170 		}
171 		
172 		return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) p, true);
173 	}
174 
175 	/**
176 	 * The selected font size.
177 	 *
178 	 * Return: A n integer representing the selected font size,
179 	 *     or -1 if no font size is selected.
180 	 *
181 	 * Since: 3.2
182 	 */
183 	public int getFontSize()
184 	{
185 		return gtk_font_chooser_get_font_size(getFontChooserStruct());
186 	}
187 
188 	/**
189 	 * Gets the text displayed in the preview area.
190 	 *
191 	 * Return: the text displayed in the
192 	 *     preview area
193 	 *
194 	 * Since: 3.2
195 	 */
196 	public string getPreviewText()
197 	{
198 		return Str.toString(gtk_font_chooser_get_preview_text(getFontChooserStruct()));
199 	}
200 
201 	/**
202 	 * Returns whether the preview entry is shown or not.
203 	 *
204 	 * Return: %TRUE if the preview entry is shown
205 	 *     or %FALSE if it is hidden.
206 	 *
207 	 * Since: 3.2
208 	 */
209 	public bool getShowPreviewEntry()
210 	{
211 		return gtk_font_chooser_get_show_preview_entry(getFontChooserStruct()) != 0;
212 	}
213 
214 	/**
215 	 * Adds a filter function that decides which fonts to display
216 	 * in the font chooser.
217 	 *
218 	 * Params:
219 	 *     filter = a #GtkFontFilterFunc, or %NULL
220 	 *     userData = data to pass to @filter
221 	 *     destroy = function to call to free @data when it is no longer needed
222 	 *
223 	 * Since: 3.2
224 	 */
225 	public void setFilterFunc(GtkFontFilterFunc filter, void* userData, GDestroyNotify destroy)
226 	{
227 		gtk_font_chooser_set_filter_func(getFontChooserStruct(), filter, userData, destroy);
228 	}
229 
230 	/**
231 	 * Sets the currently-selected font.
232 	 *
233 	 * Params:
234 	 *     fontname = a font name like “Helvetica 12” or “Times Bold 18”
235 	 *
236 	 * Since: 3.2
237 	 */
238 	public void setFont(string fontname)
239 	{
240 		gtk_font_chooser_set_font(getFontChooserStruct(), Str.toStringz(fontname));
241 	}
242 
243 	/**
244 	 * Sets the currently-selected font from @font_desc.
245 	 *
246 	 * Params:
247 	 *     fontDesc = a #PangoFontDescription
248 	 *
249 	 * Since: 3.2
250 	 */
251 	public void setFontDesc(PgFontDescription fontDesc)
252 	{
253 		gtk_font_chooser_set_font_desc(getFontChooserStruct(), (fontDesc is null) ? null : fontDesc.getPgFontDescriptionStruct());
254 	}
255 
256 	/**
257 	 * Sets a custom font map to use for this font chooser widget.
258 	 * A custom font map can be used to present application-specific
259 	 * fonts instead of or in addition to the normal system fonts.
260 	 *
261 	 * |[<!-- language="C" -->
262 	 * FcConfig *config;
263 	 * PangoFontMap *fontmap;
264 	 *
265 	 * config = FcInitLoadConfigAndFonts ();
266 	 * FcConfigAppFontAddFile (config, my_app_font_file);
267 	 *
268 	 * fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
269 	 * pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (fontmap), config);
270 	 *
271 	 * gtk_font_chooser_set_font_map (font_chooser, fontmap);
272 	 * ]|
273 	 *
274 	 * Note that other GTK+ widgets will only be able to use the application-specific
275 	 * font if it is present in the font map they use:
276 	 *
277 	 * |[
278 	 * context = gtk_widget_get_pango_context (label);
279 	 * pango_context_set_font_map (context, fontmap);
280 	 * ]|
281 	 *
282 	 * Params:
283 	 *     fontmap = a #PangoFontMap
284 	 *
285 	 * Since: 3.18
286 	 */
287 	public override void setFontMap(PgFontMap fontmap)
288 	{
289 		gtk_font_chooser_set_font_map(getFontChooserStruct(), (fontmap is null) ? null : fontmap.getPgFontMapStruct());
290 	}
291 
292 	/**
293 	 * Sets the text displayed in the preview area.
294 	 * The @text is used to show how the selected font looks.
295 	 *
296 	 * Params:
297 	 *     text = the text to display in the preview area
298 	 *
299 	 * Since: 3.2
300 	 */
301 	public void setPreviewText(string text)
302 	{
303 		gtk_font_chooser_set_preview_text(getFontChooserStruct(), Str.toStringz(text));
304 	}
305 
306 	/**
307 	 * Shows or hides the editable preview entry.
308 	 *
309 	 * Params:
310 	 *     showPreviewEntry = whether to show the editable preview entry or not
311 	 *
312 	 * Since: 3.2
313 	 */
314 	public void setShowPreviewEntry(bool showPreviewEntry)
315 	{
316 		gtk_font_chooser_set_show_preview_entry(getFontChooserStruct(), showPreviewEntry);
317 	}
318 
319 	int[string] connectedSignals;
320 
321 	void delegate(string, FontChooserIF)[] _onFontActivatedListeners;
322 	@property void delegate(string, FontChooserIF)[] onFontActivatedListeners()
323 	{
324 		return _onFontActivatedListeners;
325 	}
326 	/**
327 	 * Emitted when a font is activated.
328 	 * This usually happens when the user double clicks an item,
329 	 * or an item is selected and the user presses one of the keys
330 	 * Space, Shift+Space, Return or Enter.
331 	 *
332 	 * Params:
333 	 *     fontname = the font name
334 	 */
335 	void addOnFontActivated(void delegate(string, FontChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
336 	{
337 		if ( "font-activated" !in connectedSignals )
338 		{
339 			Signals.connectData(
340 				this,
341 				"font-activated",
342 				cast(GCallback)&callBackFontActivated,
343 				cast(void*)cast(FontChooserIF)this,
344 				null,
345 				connectFlags);
346 			connectedSignals["font-activated"] = 1;
347 		}
348 		_onFontActivatedListeners ~= dlg;
349 	}
350 	extern(C) static void callBackFontActivated(GtkFontChooser* fontchooserStruct, char* fontname, FontChooserIF _fontchooser)
351 	{
352 		foreach ( void delegate(string, FontChooserIF) dlg; _fontchooser.onFontActivatedListeners )
353 		{
354 			dlg(Str.toString(fontname), _fontchooser);
355 		}
356 	}
357 }