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