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