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