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