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.Paned;
26 
27 private import gdk.Window;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Container;
32 private import gtk.OrientableIF;
33 private import gtk.OrientableT;
34 private import gtk.Widget;
35 public  import gtkc.gdktypes;
36 private import gtkc.gtk;
37 public  import gtkc.gtktypes;
38 
39 
40 /**
41  * #GtkPaned has two panes, arranged either
42  * horizontally or vertically. The division between
43  * the two panes is adjustable by the user by dragging
44  * a handle.
45  * 
46  * Child widgets are
47  * added to the panes of the widget with gtk_paned_pack1() and
48  * gtk_paned_pack2(). The division between the two children is set by default
49  * from the size requests of the children, but it can be adjusted by the
50  * user.
51  * 
52  * A paned widget draws a separator between the two child widgets and a
53  * small handle that the user can drag to adjust the division. It does not
54  * draw any relief around the children or around the separator. (The space
55  * in which the separator is called the gutter.) Often, it is useful to put
56  * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN
57  * so that the gutter appears as a ridge. No separator is drawn if one of
58  * the children is missing.
59  * 
60  * Each child has two options that can be set, @resize and @shrink. If
61  * @resize is true, then when the #GtkPaned is resized, that child will
62  * expand or shrink along with the paned widget. If @shrink is true, then
63  * that child can be made smaller than its requisition by the user.
64  * Setting @shrink to %FALSE allows the application to set a minimum size.
65  * If @resize is false for both children, then this is treated as if
66  * @resize is true for both children.
67  * 
68  * The application can set the position of the slider as if it were set
69  * by the user, by calling gtk_paned_set_position().
70  * 
71  * # CSS nodes
72  * 
73  * |[<!-- language="plain" -->
74  * paned
75  * ├── <child>
76  * ├── separator[.wide]
77  * ╰── <child>
78  * ]|
79  * 
80  * GtkPaned has a main CSS node with name paned, and a subnode for
81  * the separator with name separator. The subnodes gets a .wide style
82  * class when the paned is supposed to be wide.
83  * 
84  * In horizontal orientation, the nodes of the children are always arranged
85  * from left to right. So :first-child will always select the leftmost child,
86  * regardless of text direction.
87  * 
88  * ## Creating a paned widget with minimum sizes.
89  * 
90  * |[<!-- language="C" -->
91  * GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
92  * GtkWidget *frame1 = gtk_frame_new (NULL);
93  * GtkWidget *frame2 = gtk_frame_new (NULL);
94  * gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
95  * gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
96  * 
97  * gtk_widget_set_size_request (hpaned, 200, -1);
98  * 
99  * gtk_paned_pack1 (GTK_PANED (hpaned), frame1, TRUE, FALSE);
100  * gtk_widget_set_size_request (frame1, 50, -1);
101  * 
102  * gtk_paned_pack2 (GTK_PANED (hpaned), frame2, FALSE, FALSE);
103  * gtk_widget_set_size_request (frame2, 50, -1);
104  * ]|
105  */
106 public class Paned : Container, OrientableIF
107 {
108 	/** the main Gtk struct */
109 	protected GtkPaned* gtkPaned;
110 
111 	/** Get the main Gtk struct */
112 	public GtkPaned* getPanedStruct()
113 	{
114 		return gtkPaned;
115 	}
116 
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gtkPaned;
121 	}
122 
123 	protected override void setStruct(GObject* obj)
124 	{
125 		gtkPaned = cast(GtkPaned*)obj;
126 		super.setStruct(obj);
127 	}
128 
129 	/**
130 	 * Sets our main struct and passes it to the parent class.
131 	 */
132 	public this (GtkPaned* gtkPaned, bool ownedRef = false)
133 	{
134 		this.gtkPaned = gtkPaned;
135 		super(cast(GtkContainer*)gtkPaned, ownedRef);
136 	}
137 
138 	// add the Orientable capabilities
139 	mixin OrientableT!(GtkPaned);
140 
141 	/** */
142 	public void add(Widget child1, Widget child2)
143 	{
144 		add1(child1);
145 		add2(child2);
146 	}
147 
148 	/**
149 	 */
150 
151 	/** */
152 	public static GType getType()
153 	{
154 		return gtk_paned_get_type();
155 	}
156 
157 	/**
158 	 * Creates a new #GtkPaned widget.
159 	 *
160 	 * Params:
161 	 *     orientation = the paned’s orientation.
162 	 *
163 	 * Return: a new #GtkPaned.
164 	 *
165 	 * Since: 3.0
166 	 *
167 	 * Throws: ConstructionException GTK+ fails to create the object.
168 	 */
169 	public this(GtkOrientation orientation)
170 	{
171 		auto p = gtk_paned_new(orientation);
172 		
173 		if(p is null)
174 		{
175 			throw new ConstructionException("null returned by new");
176 		}
177 		
178 		this(cast(GtkPaned*) p);
179 	}
180 
181 	/**
182 	 * Adds a child to the top or left pane with default parameters. This is
183 	 * equivalent to
184 	 * `gtk_paned_pack1 (paned, child, FALSE, TRUE)`.
185 	 *
186 	 * Params:
187 	 *     child = the child to add
188 	 */
189 	public void add1(Widget child)
190 	{
191 		gtk_paned_add1(gtkPaned, (child is null) ? null : child.getWidgetStruct());
192 	}
193 
194 	/**
195 	 * Adds a child to the bottom or right pane with default parameters. This
196 	 * is equivalent to
197 	 * `gtk_paned_pack2 (paned, child, TRUE, TRUE)`.
198 	 *
199 	 * Params:
200 	 *     child = the child to add
201 	 */
202 	public void add2(Widget child)
203 	{
204 		gtk_paned_add2(gtkPaned, (child is null) ? null : child.getWidgetStruct());
205 	}
206 
207 	/**
208 	 * Obtains the first child of the paned widget.
209 	 *
210 	 * Return: first child, or %NULL if it is not set.
211 	 *
212 	 * Since: 2.4
213 	 */
214 	public Widget getChild1()
215 	{
216 		auto p = gtk_paned_get_child1(gtkPaned);
217 		
218 		if(p is null)
219 		{
220 			return null;
221 		}
222 		
223 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
224 	}
225 
226 	/**
227 	 * Obtains the second child of the paned widget.
228 	 *
229 	 * Return: second child, or %NULL if it is not set.
230 	 *
231 	 * Since: 2.4
232 	 */
233 	public Widget getChild2()
234 	{
235 		auto p = gtk_paned_get_child2(gtkPaned);
236 		
237 		if(p is null)
238 		{
239 			return null;
240 		}
241 		
242 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
243 	}
244 
245 	/**
246 	 * Returns the #GdkWindow of the handle. This function is
247 	 * useful when handling button or motion events because it
248 	 * enables the callback to distinguish between the window
249 	 * of the paned, a child and the handle.
250 	 *
251 	 * Return: the paned’s handle window.
252 	 *
253 	 * Since: 2.20
254 	 */
255 	public Window getHandleWindow()
256 	{
257 		auto p = gtk_paned_get_handle_window(gtkPaned);
258 		
259 		if(p is null)
260 		{
261 			return null;
262 		}
263 		
264 		return ObjectG.getDObject!(Window)(cast(GdkWindow*) p);
265 	}
266 
267 	/**
268 	 * Obtains the position of the divider between the two panes.
269 	 *
270 	 * Return: position of the divider
271 	 */
272 	public int getPosition()
273 	{
274 		return gtk_paned_get_position(gtkPaned);
275 	}
276 
277 	/**
278 	 * Gets the #GtkPaned:wide-handle property.
279 	 *
280 	 * Return: %TRUE if the paned should have a wide handle
281 	 *
282 	 * Since: 3.16
283 	 */
284 	public bool getWideHandle()
285 	{
286 		return gtk_paned_get_wide_handle(gtkPaned) != 0;
287 	}
288 
289 	/**
290 	 * Adds a child to the top or left pane.
291 	 *
292 	 * Params:
293 	 *     child = the child to add
294 	 *     resize = should this child expand when the paned widget is resized.
295 	 *     shrink = can this child be made smaller than its requisition.
296 	 */
297 	public void pack1(Widget child, bool resize, bool shrink)
298 	{
299 		gtk_paned_pack1(gtkPaned, (child is null) ? null : child.getWidgetStruct(), resize, shrink);
300 	}
301 
302 	/**
303 	 * Adds a child to the bottom or right pane.
304 	 *
305 	 * Params:
306 	 *     child = the child to add
307 	 *     resize = should this child expand when the paned widget is resized.
308 	 *     shrink = can this child be made smaller than its requisition.
309 	 */
310 	public void pack2(Widget child, bool resize, bool shrink)
311 	{
312 		gtk_paned_pack2(gtkPaned, (child is null) ? null : child.getWidgetStruct(), resize, shrink);
313 	}
314 
315 	/**
316 	 * Sets the position of the divider between the two panes.
317 	 *
318 	 * Params:
319 	 *     position = pixel position of divider, a negative value means that the position
320 	 *         is unset.
321 	 */
322 	public void setPosition(int position)
323 	{
324 		gtk_paned_set_position(gtkPaned, position);
325 	}
326 
327 	/**
328 	 * Sets the #GtkPaned:wide-handle property.
329 	 *
330 	 * Params:
331 	 *     wide = the new value for the #GtkPaned:wide-handle property
332 	 *
333 	 * Since: 3.16
334 	 */
335 	public void setWideHandle(bool wide)
336 	{
337 		gtk_paned_set_wide_handle(gtkPaned, wide);
338 	}
339 
340 	int[string] connectedSignals;
341 
342 	bool delegate(Paned)[] onAcceptPositionListeners;
343 	/**
344 	 * The ::accept-position signal is a
345 	 * [keybinding signal][GtkBindingSignal]
346 	 * which gets emitted to accept the current position of the handle when
347 	 * moving it using key bindings.
348 	 *
349 	 * The default binding for this signal is Return or Space.
350 	 *
351 	 * Since: 2.0
352 	 */
353 	void addOnAcceptPosition(bool delegate(Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
354 	{
355 		if ( "accept-position" !in connectedSignals )
356 		{
357 			Signals.connectData(
358 				this,
359 				"accept-position",
360 				cast(GCallback)&callBackAcceptPosition,
361 				cast(void*)this,
362 				null,
363 				connectFlags);
364 			connectedSignals["accept-position"] = 1;
365 		}
366 		onAcceptPositionListeners ~= dlg;
367 	}
368 	extern(C) static int callBackAcceptPosition(GtkPaned* panedStruct, Paned _paned)
369 	{
370 		foreach ( bool delegate(Paned) dlg; _paned.onAcceptPositionListeners )
371 		{
372 			if ( dlg(_paned) )
373 			{
374 				return 1;
375 			}
376 		}
377 		
378 		return 0;
379 	}
380 
381 	bool delegate(Paned)[] onCancelPositionListeners;
382 	/**
383 	 * The ::cancel-position signal is a
384 	 * [keybinding signal][GtkBindingSignal]
385 	 * which gets emitted to cancel moving the position of the handle using key
386 	 * bindings. The position of the handle will be reset to the value prior to
387 	 * moving it.
388 	 *
389 	 * The default binding for this signal is Escape.
390 	 *
391 	 * Since: 2.0
392 	 */
393 	void addOnCancelPosition(bool delegate(Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
394 	{
395 		if ( "cancel-position" !in connectedSignals )
396 		{
397 			Signals.connectData(
398 				this,
399 				"cancel-position",
400 				cast(GCallback)&callBackCancelPosition,
401 				cast(void*)this,
402 				null,
403 				connectFlags);
404 			connectedSignals["cancel-position"] = 1;
405 		}
406 		onCancelPositionListeners ~= dlg;
407 	}
408 	extern(C) static int callBackCancelPosition(GtkPaned* panedStruct, Paned _paned)
409 	{
410 		foreach ( bool delegate(Paned) dlg; _paned.onCancelPositionListeners )
411 		{
412 			if ( dlg(_paned) )
413 			{
414 				return 1;
415 			}
416 		}
417 		
418 		return 0;
419 	}
420 
421 	bool delegate(bool, Paned)[] onCycleChildFocusListeners;
422 	/**
423 	 * The ::cycle-child-focus signal is a
424 	 * [keybinding signal][GtkBindingSignal]
425 	 * which gets emitted to cycle the focus between the children of the paned.
426 	 *
427 	 * The default binding is f6.
428 	 *
429 	 * Params:
430 	 *     reversed = whether cycling backward or forward
431 	 *
432 	 * Since: 2.0
433 	 */
434 	void addOnCycleChildFocus(bool delegate(bool, Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
435 	{
436 		if ( "cycle-child-focus" !in connectedSignals )
437 		{
438 			Signals.connectData(
439 				this,
440 				"cycle-child-focus",
441 				cast(GCallback)&callBackCycleChildFocus,
442 				cast(void*)this,
443 				null,
444 				connectFlags);
445 			connectedSignals["cycle-child-focus"] = 1;
446 		}
447 		onCycleChildFocusListeners ~= dlg;
448 	}
449 	extern(C) static int callBackCycleChildFocus(GtkPaned* panedStruct, bool reversed, Paned _paned)
450 	{
451 		foreach ( bool delegate(bool, Paned) dlg; _paned.onCycleChildFocusListeners )
452 		{
453 			if ( dlg(reversed, _paned) )
454 			{
455 				return 1;
456 			}
457 		}
458 		
459 		return 0;
460 	}
461 
462 	bool delegate(bool, Paned)[] onCycleHandleFocusListeners;
463 	/**
464 	 * The ::cycle-handle-focus signal is a
465 	 * [keybinding signal][GtkBindingSignal]
466 	 * which gets emitted to cycle whether the paned should grab focus to allow
467 	 * the user to change position of the handle by using key bindings.
468 	 *
469 	 * The default binding for this signal is f8.
470 	 *
471 	 * Params:
472 	 *     reversed = whether cycling backward or forward
473 	 *
474 	 * Since: 2.0
475 	 */
476 	void addOnCycleHandleFocus(bool delegate(bool, Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
477 	{
478 		if ( "cycle-handle-focus" !in connectedSignals )
479 		{
480 			Signals.connectData(
481 				this,
482 				"cycle-handle-focus",
483 				cast(GCallback)&callBackCycleHandleFocus,
484 				cast(void*)this,
485 				null,
486 				connectFlags);
487 			connectedSignals["cycle-handle-focus"] = 1;
488 		}
489 		onCycleHandleFocusListeners ~= dlg;
490 	}
491 	extern(C) static int callBackCycleHandleFocus(GtkPaned* panedStruct, bool reversed, Paned _paned)
492 	{
493 		foreach ( bool delegate(bool, Paned) dlg; _paned.onCycleHandleFocusListeners )
494 		{
495 			if ( dlg(reversed, _paned) )
496 			{
497 				return 1;
498 			}
499 		}
500 		
501 		return 0;
502 	}
503 
504 	bool delegate(GtkScrollType, Paned)[] onMoveHandleListeners;
505 	/**
506 	 * The ::move-handle signal is a
507 	 * [keybinding signal][GtkBindingSignal]
508 	 * which gets emitted to move the handle when the user is using key bindings
509 	 * to move it.
510 	 *
511 	 * Params:
512 	 *     scrollType = a #GtkScrollType
513 	 *
514 	 * Since: 2.0
515 	 */
516 	void addOnMoveHandle(bool delegate(GtkScrollType, Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
517 	{
518 		if ( "move-handle" !in connectedSignals )
519 		{
520 			Signals.connectData(
521 				this,
522 				"move-handle",
523 				cast(GCallback)&callBackMoveHandle,
524 				cast(void*)this,
525 				null,
526 				connectFlags);
527 			connectedSignals["move-handle"] = 1;
528 		}
529 		onMoveHandleListeners ~= dlg;
530 	}
531 	extern(C) static int callBackMoveHandle(GtkPaned* panedStruct, GtkScrollType scrollType, Paned _paned)
532 	{
533 		foreach ( bool delegate(GtkScrollType, Paned) dlg; _paned.onMoveHandleListeners )
534 		{
535 			if ( dlg(scrollType, _paned) )
536 			{
537 				return 1;
538 			}
539 		}
540 		
541 		return 0;
542 	}
543 
544 	bool delegate(Paned)[] onToggleHandleFocusListeners;
545 	/**
546 	 * The ::toggle-handle-focus is a
547 	 * [keybinding signal][GtkBindingSignal]
548 	 * which gets emitted to accept the current position of the handle and then
549 	 * move focus to the next widget in the focus chain.
550 	 *
551 	 * The default binding is Tab.
552 	 *
553 	 * Since: 2.0
554 	 */
555 	void addOnToggleHandleFocus(bool delegate(Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
556 	{
557 		if ( "toggle-handle-focus" !in connectedSignals )
558 		{
559 			Signals.connectData(
560 				this,
561 				"toggle-handle-focus",
562 				cast(GCallback)&callBackToggleHandleFocus,
563 				cast(void*)this,
564 				null,
565 				connectFlags);
566 			connectedSignals["toggle-handle-focus"] = 1;
567 		}
568 		onToggleHandleFocusListeners ~= dlg;
569 	}
570 	extern(C) static int callBackToggleHandleFocus(GtkPaned* panedStruct, Paned _paned)
571 	{
572 		foreach ( bool delegate(Paned) dlg; _paned.onToggleHandleFocusListeners )
573 		{
574 			if ( dlg(_paned) )
575 			{
576 				return 1;
577 			}
578 		}
579 		
580 		return 0;
581 	}
582 }