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