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 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
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  * # CSS nodes
104  * 
105  * |[<!-- language="plain" -->
106  * expander
107  * ├── title
108  * │   ├── arrow
109  * │   ╰── <label widget>
110  * ╰── <child>
111  * ]|
112  * 
113  * GtkExpander has three CSS nodes, the main node with the name expander,
114  * a subnode with name title and node below it with name arrow. Neither of
115  * them is using any style classes.
116  */
117 public class Expander : Bin
118 {
119 	/** the main Gtk struct */
120 	protected GtkExpander* gtkExpander;
121 
122 	/** Get the main Gtk struct */
123 	public GtkExpander* getExpanderStruct()
124 	{
125 		return gtkExpander;
126 	}
127 
128 	/** the main Gtk struct as a void* */
129 	protected override void* getStruct()
130 	{
131 		return cast(void*)gtkExpander;
132 	}
133 
134 	protected override void setStruct(GObject* obj)
135 	{
136 		gtkExpander = cast(GtkExpander*)obj;
137 		super.setStruct(obj);
138 	}
139 
140 	/**
141 	 * Sets our main struct and passes it to the parent class.
142 	 */
143 	public this (GtkExpander* gtkExpander, bool ownedRef = false)
144 	{
145 		this.gtkExpander = gtkExpander;
146 		super(cast(GtkBin*)gtkExpander, ownedRef);
147 	}
148 
149 	/**
150 	 * Creates a new expander using label as the text of the label.
151 	 * Since 2.4
152 	 * Params:
153 	 *  label = the text of the label
154 	 *  mnemonic = if true characters in label that are preceded by an underscore,
155 	 *  are underlined.
156 	 *  If you need a literal underscore character in a label, use '__' (two
157 	 *  underscores). The first underlined character represents a keyboard
158 	 *  accelerator called a mnemonic.
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this (string label, bool mnemonic=true)
162 	{
163 		GtkExpander* p;
164 		
165 		if ( mnemonic )
166 		{
167 			p = cast(GtkExpander*)gtk_expander_new_with_mnemonic(Str.toStringz(label));
168 		}
169 		else
170 		{
171 			p = cast(GtkExpander*)gtk_expander_new(Str.toStringz(label));
172 		}
173 		
174 		if(p is null)
175 		{
176 			throw new ConstructionException("null returned by gtk_expander_new");
177 		}
178 		
179 		this(p);
180 	}
181 
182 	/**
183 	 */
184 
185 	/** */
186 	public static GType getType()
187 	{
188 		return gtk_expander_get_type();
189 	}
190 
191 	/**
192 	 * Queries a #GtkExpander and returns its current state. Returns %TRUE
193 	 * if the child widget is revealed.
194 	 *
195 	 * See gtk_expander_set_expanded().
196 	 *
197 	 * Returns: the current state of the expander
198 	 *
199 	 * Since: 2.4
200 	 */
201 	public bool getExpanded()
202 	{
203 		return gtk_expander_get_expanded(gtkExpander) != 0;
204 	}
205 
206 	/**
207 	 * Fetches the text from a label widget including any embedded
208 	 * underlines indicating mnemonics and Pango markup, as set by
209 	 * gtk_expander_set_label(). If the label text has not been set the
210 	 * return value will be %NULL. This will be the case if you create an
211 	 * empty button with gtk_button_new() to use as a container.
212 	 *
213 	 * Note that this function behaved differently in versions prior to
214 	 * 2.14 and used to return the label text stripped of embedded
215 	 * underlines indicating mnemonics and Pango markup. This problem can
216 	 * be avoided by fetching the label text directly from the label
217 	 * widget.
218 	 *
219 	 * Returns: The text of the label widget. This string is owned
220 	 *     by the widget and must not be modified or freed.
221 	 *
222 	 * Since: 2.4
223 	 */
224 	public string getLabel()
225 	{
226 		return Str.toString(gtk_expander_get_label(gtkExpander));
227 	}
228 
229 	/**
230 	 * Returns whether the label widget will fill all available
231 	 * horizontal space allocated to @expander.
232 	 *
233 	 * Returns: %TRUE if the label widget will fill all
234 	 *     available horizontal space
235 	 *
236 	 * Since: 2.22
237 	 */
238 	public bool getLabelFill()
239 	{
240 		return gtk_expander_get_label_fill(gtkExpander) != 0;
241 	}
242 
243 	/**
244 	 * Retrieves the label widget for the frame. See
245 	 * gtk_expander_set_label_widget().
246 	 *
247 	 * Returns: the label widget,
248 	 *     or %NULL if there is none
249 	 *
250 	 * Since: 2.4
251 	 */
252 	public Widget getLabelWidget()
253 	{
254 		auto p = gtk_expander_get_label_widget(gtkExpander);
255 		
256 		if(p is null)
257 		{
258 			return null;
259 		}
260 		
261 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
262 	}
263 
264 	/**
265 	 * Returns whether the expander will resize the toplevel widget
266 	 * containing the expander upon resizing and collpasing.
267 	 *
268 	 * Returns: the “resize toplevel” setting.
269 	 *
270 	 * Since: 3.2
271 	 */
272 	public bool getResizeToplevel()
273 	{
274 		return gtk_expander_get_resize_toplevel(gtkExpander) != 0;
275 	}
276 
277 	/**
278 	 * Gets the value set by gtk_expander_set_spacing().
279 	 *
280 	 * Deprecated: Use margins on the child instead.
281 	 *
282 	 * Returns: spacing between the expander and child
283 	 *
284 	 * Since: 2.4
285 	 */
286 	public int getSpacing()
287 	{
288 		return gtk_expander_get_spacing(gtkExpander);
289 	}
290 
291 	/**
292 	 * Returns whether the label’s text is interpreted as marked up with
293 	 * the [Pango text markup language][PangoMarkupFormat].
294 	 * See gtk_expander_set_use_markup().
295 	 *
296 	 * Returns: %TRUE if the label’s text will be parsed for markup
297 	 *
298 	 * Since: 2.4
299 	 */
300 	public bool getUseMarkup()
301 	{
302 		return gtk_expander_get_use_markup(gtkExpander) != 0;
303 	}
304 
305 	/**
306 	 * Returns whether an embedded underline in the expander label
307 	 * indicates a mnemonic. See gtk_expander_set_use_underline().
308 	 *
309 	 * Returns: %TRUE if an embedded underline in the expander
310 	 *     label indicates the mnemonic accelerator keys
311 	 *
312 	 * Since: 2.4
313 	 */
314 	public bool getUseUnderline()
315 	{
316 		return gtk_expander_get_use_underline(gtkExpander) != 0;
317 	}
318 
319 	/**
320 	 * Sets the state of the expander. Set to %TRUE, if you want
321 	 * the child widget to be revealed, and %FALSE if you want the
322 	 * child widget to be hidden.
323 	 *
324 	 * Params:
325 	 *     expanded = whether the child widget is revealed
326 	 *
327 	 * Since: 2.4
328 	 */
329 	public void setExpanded(bool expanded)
330 	{
331 		gtk_expander_set_expanded(gtkExpander, expanded);
332 	}
333 
334 	/**
335 	 * Sets the text of the label of the expander to @label.
336 	 *
337 	 * This will also clear any previously set labels.
338 	 *
339 	 * Params:
340 	 *     label = a string
341 	 *
342 	 * Since: 2.4
343 	 */
344 	public void setLabel(string label)
345 	{
346 		gtk_expander_set_label(gtkExpander, Str.toStringz(label));
347 	}
348 
349 	/**
350 	 * Sets whether the label widget should fill all available
351 	 * horizontal space allocated to @expander.
352 	 *
353 	 * Params:
354 	 *     labelFill = %TRUE if the label should should fill
355 	 *         all available horizontal space
356 	 *
357 	 * Since: 2.22
358 	 */
359 	public void setLabelFill(bool labelFill)
360 	{
361 		gtk_expander_set_label_fill(gtkExpander, labelFill);
362 	}
363 
364 	/**
365 	 * Set the label widget for the expander. This is the widget
366 	 * that will appear embedded alongside the expander arrow.
367 	 *
368 	 * Params:
369 	 *     labelWidget = the new label widget
370 	 *
371 	 * Since: 2.4
372 	 */
373 	public void setLabelWidget(Widget labelWidget)
374 	{
375 		gtk_expander_set_label_widget(gtkExpander, (labelWidget is null) ? null : labelWidget.getWidgetStruct());
376 	}
377 
378 	/**
379 	 * Sets whether the expander will resize the toplevel widget
380 	 * containing the expander upon resizing and collpasing.
381 	 *
382 	 * Params:
383 	 *     resizeToplevel = whether to resize the toplevel
384 	 *
385 	 * Since: 3.2
386 	 */
387 	public void setResizeToplevel(bool resizeToplevel)
388 	{
389 		gtk_expander_set_resize_toplevel(gtkExpander, resizeToplevel);
390 	}
391 
392 	/**
393 	 * Sets the spacing field of @expander, which is the number of
394 	 * pixels to place between expander and the child.
395 	 *
396 	 * Deprecated: Use margins on the child instead.
397 	 *
398 	 * Params:
399 	 *     spacing = distance between the expander and child in pixels
400 	 *
401 	 * Since: 2.4
402 	 */
403 	public void setSpacing(int spacing)
404 	{
405 		gtk_expander_set_spacing(gtkExpander, spacing);
406 	}
407 
408 	/**
409 	 * Sets whether the text of the label contains markup in
410 	 * [Pango’s text markup language][PangoMarkupFormat].
411 	 * See gtk_label_set_markup().
412 	 *
413 	 * Params:
414 	 *     useMarkup = %TRUE if the label’s text should be parsed for markup
415 	 *
416 	 * Since: 2.4
417 	 */
418 	public void setUseMarkup(bool useMarkup)
419 	{
420 		gtk_expander_set_use_markup(gtkExpander, useMarkup);
421 	}
422 
423 	/**
424 	 * If true, an underline in the text of the expander label indicates
425 	 * the next character should be used for the mnemonic accelerator key.
426 	 *
427 	 * Params:
428 	 *     useUnderline = %TRUE if underlines in the text indicate mnemonics
429 	 *
430 	 * Since: 2.4
431 	 */
432 	public void setUseUnderline(bool useUnderline)
433 	{
434 		gtk_expander_set_use_underline(gtkExpander, useUnderline);
435 	}
436 
437 	protected class OnActivateDelegateWrapper
438 	{
439 		static OnActivateDelegateWrapper[] listeners;
440 		void delegate(Expander) dlg;
441 		gulong handlerId;
442 		
443 		this(void delegate(Expander) dlg)
444 		{
445 			this.dlg = dlg;
446 			this.listeners ~= this;
447 		}
448 		
449 		void remove(OnActivateDelegateWrapper source)
450 		{
451 			foreach(index, wrapper; listeners)
452 			{
453 				if (wrapper.handlerId == source.handlerId)
454 				{
455 					listeners[index] = null;
456 					listeners = std.algorithm.remove(listeners, index);
457 					break;
458 				}
459 			}
460 		}
461 	}
462 
463 	/** */
464 	gulong addOnActivate(void delegate(Expander) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
465 	{
466 		auto wrapper = new OnActivateDelegateWrapper(dlg);
467 		wrapper.handlerId = Signals.connectData(
468 			this,
469 			"activate",
470 			cast(GCallback)&callBackActivate,
471 			cast(void*)wrapper,
472 			cast(GClosureNotify)&callBackActivateDestroy,
473 			connectFlags);
474 		return wrapper.handlerId;
475 	}
476 	
477 	extern(C) static void callBackActivate(GtkExpander* expanderStruct, OnActivateDelegateWrapper wrapper)
478 	{
479 		wrapper.dlg(wrapper.outer);
480 	}
481 	
482 	extern(C) static void callBackActivateDestroy(OnActivateDelegateWrapper wrapper, GClosure* closure)
483 	{
484 		wrapper.remove(wrapper);
485 	}
486 }