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.FontButton;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Button;
32 private import gtk.FontChooserIF;
33 private import gtk.FontChooserT;
34 private import gtk.Widget;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 public  import gtkc.gtktypes;
38 private import std.algorithm;
39 
40 
41 /**
42  * The #GtkFontButton is a button which displays the currently selected
43  * font an allows to open a font chooser dialog to change the font.
44  * It is suitable widget for selecting a font in a preference dialog.
45  * 
46  * # CSS nodes
47  * 
48  * GtkFontButton has a single CSS node with name button and style class .font.
49  */
50 public class FontButton : Button, FontChooserIF
51 {
52 	/** the main Gtk struct */
53 	protected GtkFontButton* gtkFontButton;
54 
55 	/** Get the main Gtk struct */
56 	public GtkFontButton* getFontButtonStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gtkFontButton;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gtkFontButton;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GtkFontButton* gtkFontButton, bool ownedRef = false)
73 	{
74 		this.gtkFontButton = gtkFontButton;
75 		super(cast(GtkButton*)gtkFontButton, ownedRef);
76 	}
77 
78 	// add the FontChooser capabilities
79 	mixin FontChooserT!(GtkFontButton);
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gtk_font_button_get_type();
86 	}
87 
88 	/**
89 	 * Creates a new font picker widget.
90 	 *
91 	 * Returns: a new font picker widget.
92 	 *
93 	 * Since: 2.4
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this()
98 	{
99 		auto p = gtk_font_button_new();
100 
101 		if(p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 
106 		this(cast(GtkFontButton*) p);
107 	}
108 
109 	/**
110 	 * Creates a new font picker widget.
111 	 *
112 	 * Params:
113 	 *     fontname = Name of font to display in font chooser dialog
114 	 *
115 	 * Returns: a new font picker widget.
116 	 *
117 	 * Since: 2.4
118 	 *
119 	 * Throws: ConstructionException GTK+ fails to create the object.
120 	 */
121 	public this(string fontname)
122 	{
123 		auto p = gtk_font_button_new_with_font(Str.toStringz(fontname));
124 
125 		if(p is null)
126 		{
127 			throw new ConstructionException("null returned by new_with_font");
128 		}
129 
130 		this(cast(GtkFontButton*) p);
131 	}
132 
133 	/**
134 	 * Retrieves the name of the currently selected font. This name includes
135 	 * style and size information as well. If you want to render something
136 	 * with the font, use this string with pango_font_description_from_string() .
137 	 * If you’re interested in peeking certain values (family name,
138 	 * style, size, weight) just query these properties from the
139 	 * #PangoFontDescription object.
140 	 *
141 	 * Returns: an internal copy of the font name which must not be freed.
142 	 *
143 	 * Since: 2.4
144 	 */
145 	public string getFontName()
146 	{
147 		return Str.toString(gtk_font_button_get_font_name(gtkFontButton));
148 	}
149 
150 	/**
151 	 * Returns whether the font size will be shown in the label.
152 	 *
153 	 * Returns: whether the font size will be shown in the label.
154 	 *
155 	 * Since: 2.4
156 	 */
157 	public bool getShowSize()
158 	{
159 		return gtk_font_button_get_show_size(gtkFontButton) != 0;
160 	}
161 
162 	/**
163 	 * Returns whether the name of the font style will be shown in the label.
164 	 *
165 	 * Returns: whether the font style will be shown in the label.
166 	 *
167 	 * Since: 2.4
168 	 */
169 	public bool getShowStyle()
170 	{
171 		return gtk_font_button_get_show_style(gtkFontButton) != 0;
172 	}
173 
174 	/**
175 	 * Retrieves the title of the font chooser dialog.
176 	 *
177 	 * Returns: an internal copy of the title string which must not be freed.
178 	 *
179 	 * Since: 2.4
180 	 */
181 	public string getTitle()
182 	{
183 		return Str.toString(gtk_font_button_get_title(gtkFontButton));
184 	}
185 
186 	/**
187 	 * Returns whether the selected font is used in the label.
188 	 *
189 	 * Returns: whether the selected font is used in the label.
190 	 *
191 	 * Since: 2.4
192 	 */
193 	public bool getUseFont()
194 	{
195 		return gtk_font_button_get_use_font(gtkFontButton) != 0;
196 	}
197 
198 	/**
199 	 * Returns whether the selected size is used in the label.
200 	 *
201 	 * Returns: whether the selected size is used in the label.
202 	 *
203 	 * Since: 2.4
204 	 */
205 	public bool getUseSize()
206 	{
207 		return gtk_font_button_get_use_size(gtkFontButton) != 0;
208 	}
209 
210 	/**
211 	 * Sets or updates the currently-displayed font in font picker dialog.
212 	 *
213 	 * Params:
214 	 *     fontname = Name of font to display in font chooser dialog
215 	 *
216 	 * Returns: %TRUE
217 	 *
218 	 * Since: 2.4
219 	 */
220 	public bool setFontName(string fontname)
221 	{
222 		return gtk_font_button_set_font_name(gtkFontButton, Str.toStringz(fontname)) != 0;
223 	}
224 
225 	/**
226 	 * If @show_size is %TRUE, the font size will be displayed along with the name of the selected font.
227 	 *
228 	 * Params:
229 	 *     showSize = %TRUE if font size should be displayed in dialog.
230 	 *
231 	 * Since: 2.4
232 	 */
233 	public void setShowSize(bool showSize)
234 	{
235 		gtk_font_button_set_show_size(gtkFontButton, showSize);
236 	}
237 
238 	/**
239 	 * If @show_style is %TRUE, the font style will be displayed along with name of the selected font.
240 	 *
241 	 * Params:
242 	 *     showStyle = %TRUE if font style should be displayed in label.
243 	 *
244 	 * Since: 2.4
245 	 */
246 	public void setShowStyle(bool showStyle)
247 	{
248 		gtk_font_button_set_show_style(gtkFontButton, showStyle);
249 	}
250 
251 	/**
252 	 * Sets the title for the font chooser dialog.
253 	 *
254 	 * Params:
255 	 *     title = a string containing the font chooser dialog title
256 	 *
257 	 * Since: 2.4
258 	 */
259 	public void setTitle(string title)
260 	{
261 		gtk_font_button_set_title(gtkFontButton, Str.toStringz(title));
262 	}
263 
264 	/**
265 	 * If @use_font is %TRUE, the font name will be written using the selected font.
266 	 *
267 	 * Params:
268 	 *     useFont = If %TRUE, font name will be written using font chosen.
269 	 *
270 	 * Since: 2.4
271 	 */
272 	public void setUseFont(bool useFont)
273 	{
274 		gtk_font_button_set_use_font(gtkFontButton, useFont);
275 	}
276 
277 	/**
278 	 * If @use_size is %TRUE, the font name will be written using the selected size.
279 	 *
280 	 * Params:
281 	 *     useSize = If %TRUE, font name will be written using the selected size.
282 	 *
283 	 * Since: 2.4
284 	 */
285 	public void setUseSize(bool useSize)
286 	{
287 		gtk_font_button_set_use_size(gtkFontButton, useSize);
288 	}
289 
290 	protected class OnFontSetDelegateWrapper
291 	{
292 		void delegate(FontButton) dlg;
293 		gulong handlerId;
294 
295 		this(void delegate(FontButton) dlg)
296 		{
297 			this.dlg = dlg;
298 			onFontSetListeners ~= this;
299 		}
300 
301 		void remove(OnFontSetDelegateWrapper source)
302 		{
303 			foreach(index, wrapper; onFontSetListeners)
304 			{
305 				if (wrapper.handlerId == source.handlerId)
306 				{
307 					onFontSetListeners[index] = null;
308 					onFontSetListeners = std.algorithm.remove(onFontSetListeners, index);
309 					break;
310 				}
311 			}
312 		}
313 	}
314 	OnFontSetDelegateWrapper[] onFontSetListeners;
315 
316 	/**
317 	 * The ::font-set signal is emitted when the user selects a font.
318 	 * When handling this signal, use gtk_font_button_get_font_name()
319 	 * to find out which font was just selected.
320 	 *
321 	 * Note that this signal is only emitted when the user
322 	 * changes the font. If you need to react to programmatic font changes
323 	 * as well, use the notify::font-name signal.
324 	 *
325 	 * Since: 2.4
326 	 */
327 	gulong addOnFontSet(void delegate(FontButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
328 	{
329 		auto wrapper = new OnFontSetDelegateWrapper(dlg);
330 		wrapper.handlerId = Signals.connectData(
331 			this,
332 			"font-set",
333 			cast(GCallback)&callBackFontSet,
334 			cast(void*)wrapper,
335 			cast(GClosureNotify)&callBackFontSetDestroy,
336 			connectFlags);
337 		return wrapper.handlerId;
338 	}
339 
340 	extern(C) static void callBackFontSet(GtkFontButton* fontbuttonStruct, OnFontSetDelegateWrapper wrapper)
341 	{
342 		wrapper.dlg(wrapper.outer);
343 	}
344 
345 	extern(C) static void callBackFontSetDestroy(OnFontSetDelegateWrapper wrapper, GClosure* closure)
346 	{
347 		wrapper.remove(wrapper);
348 	}
349 }