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.Expander;
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.Bin;
32 private import gtk.Widget;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * A #GtkExpander allows the user to hide or show its child by clicking
40  * on an expander triangle similar to the triangles used in a #GtkTreeView.
41  * 
42  * Normally you use an expander as you would use any other descendant
43  * of #GtkBin; you create the child widget and use gtk_container_add()
44  * to add it to the expander. When the expander is toggled, it will take
45  * care of showing and hiding the child automatically.
46  * 
47  * # Special Usage
48  * 
49  * There are situations in which you may prefer to show and hide the
50  * expanded widget yourself, such as when you want to actually create
51  * the widget at expansion time. In this case, create a #GtkExpander
52  * but do not add a child to it. The expander widget has an
53  * #GtkExpander:expanded property which can be used to monitor
54  * its expansion state. You should watch this property with a signal
55  * connection as follows:
56  * 
57  * |[<!-- language="C" -->
58  * expander = gtk_expander_new_with_mnemonic ("_More Options");
59  * g_signal_connect (expander, "notify::expanded",
60  * G_CALLBACK (expander_callback), NULL);
61  * 
62  * ...
63  * 
64  * static void
65  * expander_callback (GObject    *object,
66  * GParamSpec *param_spec,
67  * gpointer    user_data)
68  * {
69  * GtkExpander *expander;
70  * 
71  * expander = GTK_EXPANDER (object);
72  * 
73  * if (gtk_expander_get_expanded (expander))
74  * {
75  * // Show or create widgets
76  * }
77  * else
78  * {
79  * // Hide or destroy widgets
80  * }
81  * }
82  * ]|
83  * 
84  * # GtkExpander as GtkBuildable
85  * 
86  * The GtkExpander implementation of the GtkBuildable interface supports
87  * placing a child in the label position by specifying “label” as the
88  * “type” attribute of a <child> element. A normal content child can be
89  * specified without specifying a <child> type attribute.
90  * 
91  * An example of a UI definition fragment with GtkExpander:
92  * |[
93  * <object class="GtkExpander">
94  * <child type="label">
95  * <object class="GtkLabel" id="expander-label"/>
96  * </child>
97  * <child>
98  * <object class="GtkEntry" id="expander-content"/>
99  * </child>
100  * </object>
101  * ]|
102  */
103 public class Expander : Bin
104 {
105 	/** the main Gtk struct */
106 	protected GtkExpander* gtkExpander;
107 
108 	/** Get the main Gtk struct */
109 	public GtkExpander* getExpanderStruct()
110 	{
111 		return gtkExpander;
112 	}
113 
114 	/** the main Gtk struct as a void* */
115 	protected override void* getStruct()
116 	{
117 		return cast(void*)gtkExpander;
118 	}
119 
120 	protected override void setStruct(GObject* obj)
121 	{
122 		gtkExpander = cast(GtkExpander*)obj;
123 		super.setStruct(obj);
124 	}
125 
126 	/**
127 	 * Sets our main struct and passes it to the parent class.
128 	 */
129 	public this (GtkExpander* gtkExpander, bool ownedRef = false)
130 	{
131 		this.gtkExpander = gtkExpander;
132 		super(cast(GtkBin*)gtkExpander, ownedRef);
133 	}
134 
135 	/**
136 	 * Creates a new expander using label as the text of the label.
137 	 * Since 2.4
138 	 * Params:
139 	 *  label = the text of the label
140 	 *  mnemonic = if true characters in label that are preceded by an underscore,
141 	 *  are underlined.
142 	 *  If you need a literal underscore character in a label, use '__' (two
143 	 *  underscores). The first underlined character represents a keyboard
144 	 *  accelerator called a mnemonic.
145 	 * Throws: ConstructionException GTK+ fails to create the object.
146 	 */
147 	public this (string label, bool mnemonic=true)
148 	{
149 		GtkExpander* p;
150 		
151 		if ( mnemonic )
152 		{
153 			p = cast(GtkExpander*)gtk_expander_new_with_mnemonic(Str.toStringz(label));
154 		}
155 		else
156 		{
157 			p = cast(GtkExpander*)gtk_expander_new(Str.toStringz(label));
158 		}
159 		
160 		if(p is null)
161 		{
162 			throw new ConstructionException("null returned by gtk_expander_new");
163 		}
164 		
165 		this(p);
166 	}
167 
168 	/**
169 	 */
170 
171 	public static GType getType()
172 	{
173 		return gtk_expander_get_type();
174 	}
175 
176 	/**
177 	 * Queries a #GtkExpander and returns its current state. Returns %TRUE
178 	 * if the child widget is revealed.
179 	 *
180 	 * See gtk_expander_set_expanded().
181 	 *
182 	 * Return: the current state of the expander
183 	 *
184 	 * Since: 2.4
185 	 */
186 	public bool getExpanded()
187 	{
188 		return gtk_expander_get_expanded(gtkExpander) != 0;
189 	}
190 
191 	/**
192 	 * Fetches the text from a label widget including any embedded
193 	 * underlines indicating mnemonics and Pango markup, as set by
194 	 * gtk_expander_set_label(). If the label text has not been set the
195 	 * return value will be %NULL. This will be the case if you create an
196 	 * empty button with gtk_button_new() to use as a container.
197 	 *
198 	 * Note that this function behaved differently in versions prior to
199 	 * 2.14 and used to return the label text stripped of embedded
200 	 * underlines indicating mnemonics and Pango markup. This problem can
201 	 * be avoided by fetching the label text directly from the label
202 	 * widget.
203 	 *
204 	 * Return: The text of the label widget. This string is owned
205 	 *     by the widget and must not be modified or freed.
206 	 *
207 	 * Since: 2.4
208 	 */
209 	public string getLabel()
210 	{
211 		return Str.toString(gtk_expander_get_label(gtkExpander));
212 	}
213 
214 	/**
215 	 * Returns whether the label widget will fill all available
216 	 * horizontal space allocated to @expander.
217 	 *
218 	 * Return: %TRUE if the label widget will fill all
219 	 *     available horizontal space
220 	 *
221 	 * Since: 2.22
222 	 */
223 	public bool getLabelFill()
224 	{
225 		return gtk_expander_get_label_fill(gtkExpander) != 0;
226 	}
227 
228 	/**
229 	 * Retrieves the label widget for the frame. See
230 	 * gtk_expander_set_label_widget().
231 	 *
232 	 * Return: the label widget,
233 	 *     or %NULL if there is none
234 	 *
235 	 * Since: 2.4
236 	 */
237 	public Widget getLabelWidget()
238 	{
239 		auto p = gtk_expander_get_label_widget(gtkExpander);
240 		
241 		if(p is null)
242 		{
243 			return null;
244 		}
245 		
246 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
247 	}
248 
249 	/**
250 	 * Returns whether the expander will resize the toplevel widget
251 	 * containing the expander upon resizing and collpasing.
252 	 *
253 	 * Return: the “resize toplevel” setting.
254 	 *
255 	 * Since: 3.2
256 	 */
257 	public bool getResizeToplevel()
258 	{
259 		return gtk_expander_get_resize_toplevel(gtkExpander) != 0;
260 	}
261 
262 	/**
263 	 * Gets the value set by gtk_expander_set_spacing().
264 	 *
265 	 * Return: spacing between the expander and child
266 	 *
267 	 * Since: 2.4
268 	 */
269 	public int getSpacing()
270 	{
271 		return gtk_expander_get_spacing(gtkExpander);
272 	}
273 
274 	/**
275 	 * Returns whether the label’s text is interpreted as marked up with
276 	 * the [Pango text markup language][PangoMarkupFormat].
277 	 * See gtk_expander_set_use_markup().
278 	 *
279 	 * Return: %TRUE if the label’s text will be parsed for markup
280 	 *
281 	 * Since: 2.4
282 	 */
283 	public bool getUseMarkup()
284 	{
285 		return gtk_expander_get_use_markup(gtkExpander) != 0;
286 	}
287 
288 	/**
289 	 * Returns whether an embedded underline in the expander label
290 	 * indicates a mnemonic. See gtk_expander_set_use_underline().
291 	 *
292 	 * Return: %TRUE if an embedded underline in the expander
293 	 *     label indicates the mnemonic accelerator keys
294 	 *
295 	 * Since: 2.4
296 	 */
297 	public bool getUseUnderline()
298 	{
299 		return gtk_expander_get_use_underline(gtkExpander) != 0;
300 	}
301 
302 	/**
303 	 * Sets the state of the expander. Set to %TRUE, if you want
304 	 * the child widget to be revealed, and %FALSE if you want the
305 	 * child widget to be hidden.
306 	 *
307 	 * Params:
308 	 *     expanded = whether the child widget is revealed
309 	 *
310 	 * Since: 2.4
311 	 */
312 	public void setExpanded(bool expanded)
313 	{
314 		gtk_expander_set_expanded(gtkExpander, expanded);
315 	}
316 
317 	/**
318 	 * Sets the text of the label of the expander to @label.
319 	 *
320 	 * This will also clear any previously set labels.
321 	 *
322 	 * Params:
323 	 *     label = a string
324 	 *
325 	 * Since: 2.4
326 	 */
327 	public void setLabel(string label)
328 	{
329 		gtk_expander_set_label(gtkExpander, Str.toStringz(label));
330 	}
331 
332 	/**
333 	 * Sets whether the label widget should fill all available
334 	 * horizontal space allocated to @expander.
335 	 *
336 	 * Params:
337 	 *     labelFill = %TRUE if the label should should fill
338 	 *         all available horizontal space
339 	 *
340 	 * Since: 2.22
341 	 */
342 	public void setLabelFill(bool labelFill)
343 	{
344 		gtk_expander_set_label_fill(gtkExpander, labelFill);
345 	}
346 
347 	/**
348 	 * Set the label widget for the expander. This is the widget
349 	 * that will appear embedded alongside the expander arrow.
350 	 *
351 	 * Params:
352 	 *     labelWidget = the new label widget
353 	 *
354 	 * Since: 2.4
355 	 */
356 	public void setLabelWidget(Widget labelWidget)
357 	{
358 		gtk_expander_set_label_widget(gtkExpander, (labelWidget is null) ? null : labelWidget.getWidgetStruct());
359 	}
360 
361 	/**
362 	 * Sets whether the expander will resize the toplevel widget
363 	 * containing the expander upon resizing and collpasing.
364 	 *
365 	 * Params:
366 	 *     resizeToplevel = whether to resize the toplevel
367 	 *
368 	 * Since: 3.2
369 	 */
370 	public void setResizeToplevel(bool resizeToplevel)
371 	{
372 		gtk_expander_set_resize_toplevel(gtkExpander, resizeToplevel);
373 	}
374 
375 	/**
376 	 * Sets the spacing field of @expander, which is the number of
377 	 * pixels to place between expander and the child.
378 	 *
379 	 * Params:
380 	 *     spacing = distance between the expander and child in pixels
381 	 *
382 	 * Since: 2.4
383 	 */
384 	public void setSpacing(int spacing)
385 	{
386 		gtk_expander_set_spacing(gtkExpander, spacing);
387 	}
388 
389 	/**
390 	 * Sets whether the text of the label contains markup in
391 	 * [Pango’s text markup language][PangoMarkupFormat].
392 	 * See gtk_label_set_markup().
393 	 *
394 	 * Params:
395 	 *     useMarkup = %TRUE if the label’s text should be parsed for markup
396 	 *
397 	 * Since: 2.4
398 	 */
399 	public void setUseMarkup(bool useMarkup)
400 	{
401 		gtk_expander_set_use_markup(gtkExpander, useMarkup);
402 	}
403 
404 	/**
405 	 * If true, an underline in the text of the expander label indicates
406 	 * the next character should be used for the mnemonic accelerator key.
407 	 *
408 	 * Params:
409 	 *     useUnderline = %TRUE if underlines in the text indicate mnemonics
410 	 *
411 	 * Since: 2.4
412 	 */
413 	public void setUseUnderline(bool useUnderline)
414 	{
415 		gtk_expander_set_use_underline(gtkExpander, useUnderline);
416 	}
417 
418 	int[string] connectedSignals;
419 
420 	void delegate(Expander)[] onActivateListeners;
421 	void addOnActivate(void delegate(Expander) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
422 	{
423 		if ( "activate" !in connectedSignals )
424 		{
425 			Signals.connectData(
426 				this,
427 				"activate",
428 				cast(GCallback)&callBackActivate,
429 				cast(void*)this,
430 				null,
431 				connectFlags);
432 			connectedSignals["activate"] = 1;
433 		}
434 		onActivateListeners ~= dlg;
435 	}
436 	extern(C) static void callBackActivate(GtkExpander* expanderStruct, Expander _expander)
437 	{
438 		foreach ( void delegate(Expander) dlg; _expander.onActivateListeners )
439 		{
440 			dlg(_expander);
441 		}
442 	}
443 }