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