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