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 private import gtk.c.functions;
36 public  import gtk.c.types;
37 public  import gtkc.gtktypes;
38 private import std.algorithm;
39 
40 
41 /**
42  * #GtkPaned has two panes, arranged either
43  * horizontally or vertically. The division between
44  * the two panes is adjustable by the user by dragging
45  * a handle.
46  * 
47  * Child widgets are
48  * added to the panes of the widget with gtk_paned_pack1() and
49  * gtk_paned_pack2(). The division between the two children is set by default
50  * from the size requests of the children, but it can be adjusted by the
51  * user.
52  * 
53  * A paned widget draws a separator between the two child widgets and a
54  * small handle that the user can drag to adjust the division. It does not
55  * draw any relief around the children or around the separator. (The space
56  * in which the separator is called the gutter.) Often, it is useful to put
57  * each child inside a #GtkFrame with the shadow type set to %GTK_SHADOW_IN
58  * so that the gutter appears as a ridge. No separator is drawn if one of
59  * the children is missing.
60  * 
61  * Each child has two options that can be set, @resize and @shrink. If
62  * @resize is true, then when the #GtkPaned is resized, that child will
63  * expand or shrink along with the paned widget. If @shrink is true, then
64  * that child can be made smaller than its requisition by the user.
65  * Setting @shrink to %FALSE allows the application to set a minimum size.
66  * If @resize is false for both children, then this is treated as if
67  * @resize is true for both children.
68  * 
69  * The application can set the position of the slider as if it were set
70  * by the user, by calling gtk_paned_set_position().
71  * 
72  * # CSS nodes
73  * 
74  * |[<!-- language="plain" -->
75  * paned
76  * ├── <child>
77  * ├── separator[.wide]
78  * ╰── <child>
79  * ]|
80  * 
81  * GtkPaned has a main CSS node with name paned, and a subnode for
82  * the separator with name separator. The subnode gets a .wide style
83  * class when the paned is supposed to be wide.
84  * 
85  * In horizontal orientation, the nodes of the children are always arranged
86  * from left to right. So :first-child will always select the leftmost child,
87  * regardless of text direction.
88  * 
89  * ## Creating a paned widget with minimum sizes.
90  * 
91  * |[<!-- language="C" -->
92  * GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
93  * GtkWidget *frame1 = gtk_frame_new (NULL);
94  * GtkWidget *frame2 = gtk_frame_new (NULL);
95  * gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_IN);
96  * gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
97  * 
98  * gtk_widget_set_size_request (hpaned, 200, -1);
99  * 
100  * gtk_paned_pack1 (GTK_PANED (hpaned), frame1, TRUE, FALSE);
101  * gtk_widget_set_size_request (frame1, 50, -1);
102  * 
103  * gtk_paned_pack2 (GTK_PANED (hpaned), frame2, FALSE, FALSE);
104  * gtk_widget_set_size_request (frame2, 50, -1);
105  * ]|
106  */
107 public class Paned : Container, OrientableIF
108 {
109 	/** the main Gtk struct */
110 	protected GtkPaned* gtkPaned;
111 
112 	/** Get the main Gtk struct */
113 	public GtkPaned* getPanedStruct(bool transferOwnership = false)
114 	{
115 		if (transferOwnership)
116 			ownedRef = false;
117 		return gtkPaned;
118 	}
119 
120 	/** the main Gtk struct as a void* */
121 	protected override void* getStruct()
122 	{
123 		return cast(void*)gtkPaned;
124 	}
125 
126 	/**
127 	 * Sets our main struct and passes it to the parent class.
128 	 */
129 	public this (GtkPaned* gtkPaned, bool ownedRef = false)
130 	{
131 		this.gtkPaned = gtkPaned;
132 		super(cast(GtkContainer*)gtkPaned, ownedRef);
133 	}
134 
135 	// add the Orientable capabilities
136 	mixin OrientableT!(GtkPaned);
137 
138 	/** */
139 	public void add(Widget child1, Widget child2)
140 	{
141 		add1(child1);
142 		add2(child2);
143 	}
144 
145 	/**
146 	 */
147 
148 	/** */
149 	public static GType getType()
150 	{
151 		return gtk_paned_get_type();
152 	}
153 
154 	/**
155 	 * Creates a new #GtkPaned widget.
156 	 *
157 	 * Params:
158 	 *     orientation = the paned’s orientation.
159 	 *
160 	 * Returns: a new #GtkPaned.
161 	 *
162 	 * Since: 3.0
163 	 *
164 	 * Throws: ConstructionException GTK+ fails to create the object.
165 	 */
166 	public this(GtkOrientation orientation)
167 	{
168 		auto p = gtk_paned_new(orientation);
169 
170 		if(p is null)
171 		{
172 			throw new ConstructionException("null returned by new");
173 		}
174 
175 		this(cast(GtkPaned*) p);
176 	}
177 
178 	/**
179 	 * Adds a child to the top or left pane with default parameters. This is
180 	 * equivalent to
181 	 * `gtk_paned_pack1 (paned, child, FALSE, TRUE)`.
182 	 *
183 	 * Params:
184 	 *     child = the child to add
185 	 */
186 	public void add1(Widget child)
187 	{
188 		gtk_paned_add1(gtkPaned, (child is null) ? null : child.getWidgetStruct());
189 	}
190 
191 	/**
192 	 * Adds a child to the bottom or right pane with default parameters. This
193 	 * is equivalent to
194 	 * `gtk_paned_pack2 (paned, child, TRUE, TRUE)`.
195 	 *
196 	 * Params:
197 	 *     child = the child to add
198 	 */
199 	public void add2(Widget child)
200 	{
201 		gtk_paned_add2(gtkPaned, (child is null) ? null : child.getWidgetStruct());
202 	}
203 
204 	/**
205 	 * Obtains the first child of the paned widget.
206 	 *
207 	 * Returns: first child, or %NULL if it is not set.
208 	 *
209 	 * Since: 2.4
210 	 */
211 	public Widget getChild1()
212 	{
213 		auto p = gtk_paned_get_child1(gtkPaned);
214 
215 		if(p is null)
216 		{
217 			return null;
218 		}
219 
220 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
221 	}
222 
223 	/**
224 	 * Obtains the second child of the paned widget.
225 	 *
226 	 * Returns: second child, or %NULL if it is not set.
227 	 *
228 	 * Since: 2.4
229 	 */
230 	public Widget getChild2()
231 	{
232 		auto p = gtk_paned_get_child2(gtkPaned);
233 
234 		if(p is null)
235 		{
236 			return null;
237 		}
238 
239 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
240 	}
241 
242 	/**
243 	 * Returns the #GdkWindow of the handle. This function is
244 	 * useful when handling button or motion events because it
245 	 * enables the callback to distinguish between the window
246 	 * of the paned, a child and the handle.
247 	 *
248 	 * Returns: the paned’s handle window.
249 	 *
250 	 * Since: 2.20
251 	 */
252 	public Window getHandleWindow()
253 	{
254 		auto p = gtk_paned_get_handle_window(gtkPaned);
255 
256 		if(p is null)
257 		{
258 			return null;
259 		}
260 
261 		return ObjectG.getDObject!(Window)(cast(GdkWindow*) p);
262 	}
263 
264 	/**
265 	 * Obtains the position of the divider between the two panes.
266 	 *
267 	 * Returns: position of the divider
268 	 */
269 	public int getPosition()
270 	{
271 		return gtk_paned_get_position(gtkPaned);
272 	}
273 
274 	/**
275 	 * Gets the #GtkPaned:wide-handle property.
276 	 *
277 	 * Returns: %TRUE if the paned should have a wide handle
278 	 *
279 	 * Since: 3.16
280 	 */
281 	public bool getWideHandle()
282 	{
283 		return gtk_paned_get_wide_handle(gtkPaned) != 0;
284 	}
285 
286 	/**
287 	 * Adds a child to the top or left pane.
288 	 *
289 	 * Params:
290 	 *     child = the child to add
291 	 *     resize = should this child expand when the paned widget is resized.
292 	 *     shrink = can this child be made smaller than its requisition.
293 	 */
294 	public void pack1(Widget child, bool resize, bool shrink)
295 	{
296 		gtk_paned_pack1(gtkPaned, (child is null) ? null : child.getWidgetStruct(), resize, shrink);
297 	}
298 
299 	/**
300 	 * Adds a child to the bottom or right pane.
301 	 *
302 	 * Params:
303 	 *     child = the child to add
304 	 *     resize = should this child expand when the paned widget is resized.
305 	 *     shrink = can this child be made smaller than its requisition.
306 	 */
307 	public void pack2(Widget child, bool resize, bool shrink)
308 	{
309 		gtk_paned_pack2(gtkPaned, (child is null) ? null : child.getWidgetStruct(), resize, shrink);
310 	}
311 
312 	/**
313 	 * Sets the position of the divider between the two panes.
314 	 *
315 	 * Params:
316 	 *     position = pixel position of divider, a negative value means that the position
317 	 *         is unset.
318 	 */
319 	public void setPosition(int position)
320 	{
321 		gtk_paned_set_position(gtkPaned, position);
322 	}
323 
324 	/**
325 	 * Sets the #GtkPaned:wide-handle property.
326 	 *
327 	 * Params:
328 	 *     wide = the new value for the #GtkPaned:wide-handle property
329 	 *
330 	 * Since: 3.16
331 	 */
332 	public void setWideHandle(bool wide)
333 	{
334 		gtk_paned_set_wide_handle(gtkPaned, wide);
335 	}
336 
337 	/**
338 	 * The ::accept-position signal is a
339 	 * [keybinding signal][GtkBindingSignal]
340 	 * which gets emitted to accept the current position of the handle when
341 	 * moving it using key bindings.
342 	 *
343 	 * The default binding for this signal is Return or Space.
344 	 *
345 	 * Since: 2.0
346 	 */
347 	gulong addOnAcceptPosition(bool delegate(Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
348 	{
349 		return Signals.connect(this, "accept-position", dlg, connectFlags ^ ConnectFlags.SWAPPED);
350 	}
351 
352 	/**
353 	 * The ::cancel-position signal is a
354 	 * [keybinding signal][GtkBindingSignal]
355 	 * which gets emitted to cancel moving the position of the handle using key
356 	 * bindings. The position of the handle will be reset to the value prior to
357 	 * moving it.
358 	 *
359 	 * The default binding for this signal is Escape.
360 	 *
361 	 * Since: 2.0
362 	 */
363 	gulong addOnCancelPosition(bool delegate(Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
364 	{
365 		return Signals.connect(this, "cancel-position", dlg, connectFlags ^ ConnectFlags.SWAPPED);
366 	}
367 
368 	/**
369 	 * The ::cycle-child-focus signal is a
370 	 * [keybinding signal][GtkBindingSignal]
371 	 * which gets emitted to cycle the focus between the children of the paned.
372 	 *
373 	 * The default binding is f6.
374 	 *
375 	 * Params:
376 	 *     reversed = whether cycling backward or forward
377 	 *
378 	 * Since: 2.0
379 	 */
380 	gulong addOnCycleChildFocus(bool delegate(bool, Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
381 	{
382 		return Signals.connect(this, "cycle-child-focus", dlg, connectFlags ^ ConnectFlags.SWAPPED);
383 	}
384 
385 	/**
386 	 * The ::cycle-handle-focus signal is a
387 	 * [keybinding signal][GtkBindingSignal]
388 	 * which gets emitted to cycle whether the paned should grab focus to allow
389 	 * the user to change position of the handle by using key bindings.
390 	 *
391 	 * The default binding for this signal is f8.
392 	 *
393 	 * Params:
394 	 *     reversed = whether cycling backward or forward
395 	 *
396 	 * Since: 2.0
397 	 */
398 	gulong addOnCycleHandleFocus(bool delegate(bool, Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
399 	{
400 		return Signals.connect(this, "cycle-handle-focus", dlg, connectFlags ^ ConnectFlags.SWAPPED);
401 	}
402 
403 	/**
404 	 * The ::move-handle signal is a
405 	 * [keybinding signal][GtkBindingSignal]
406 	 * which gets emitted to move the handle when the user is using key bindings
407 	 * to move it.
408 	 *
409 	 * Params:
410 	 *     scrollType = a #GtkScrollType
411 	 *
412 	 * Since: 2.0
413 	 */
414 	gulong addOnMoveHandle(bool delegate(GtkScrollType, Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
415 	{
416 		return Signals.connect(this, "move-handle", dlg, connectFlags ^ ConnectFlags.SWAPPED);
417 	}
418 
419 	/**
420 	 * The ::toggle-handle-focus is a
421 	 * [keybinding signal][GtkBindingSignal]
422 	 * which gets emitted to accept the current position of the handle and then
423 	 * move focus to the next widget in the focus chain.
424 	 *
425 	 * The default binding is Tab.
426 	 *
427 	 * Since: 2.0
428 	 */
429 	gulong addOnToggleHandleFocus(bool delegate(Paned) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
430 	{
431 		return Signals.connect(this, "toggle-handle-focus", dlg, connectFlags ^ ConnectFlags.SWAPPED);
432 	}
433 }