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