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.ScrolledWindow;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Adjustment;
31 private import gtk.Bin;
32 private import gtk.Widget;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * #GtkScrolledWindow is a #GtkBin subclass: it’s a container
40  * the accepts a single child widget. #GtkScrolledWindow adds scrollbars
41  * to the child widget and optionally draws a beveled frame around the
42  * child widget.
43  * 
44  * The scrolled window can work in two ways. Some widgets have native
45  * scrolling support; these widgets implement the #GtkScrollable interface.
46  * Widgets with native scroll support include #GtkTreeView, #GtkTextView,
47  * and #GtkLayout.
48  * 
49  * For widgets that lack native scrolling support, the #GtkViewport
50  * widget acts as an adaptor class, implementing scrollability for child
51  * widgets that lack their own scrolling capabilities. Use #GtkViewport
52  * to scroll child widgets such as #GtkGrid, #GtkBox, and so on.
53  * 
54  * If a widget has native scrolling abilities, it can be added to the
55  * #GtkScrolledWindow with gtk_container_add(). If a widget does not, you
56  * must first add the widget to a #GtkViewport, then add the #GtkViewport
57  * to the scrolled window. gtk_container_add() will do this for you for
58  * widgets that don’t implement #GtkScrollable natively, so you can
59  * ignore the presence of the viewport.
60  * 
61  * The position of the scrollbars is controlled by the scroll
62  * adjustments. See #GtkAdjustment for the fields in an adjustment - for
63  * #GtkScrollbar, used by #GtkScrolledWindow, the “value” field
64  * represents the position of the scrollbar, which must be between the
65  * “lower” field and “upper - page_size.” The “page_size” field
66  * represents the size of the visible scrollable area. The
67  * “step_increment” and “page_increment” fields are used when the user
68  * asks to step down (using the small stepper arrows) or page down (using
69  * for example the PageDown key).
70  * 
71  * If a #GtkScrolledWindow doesn’t behave quite as you would like, or
72  * doesn’t have exactly the right layout, it’s very possible to set up
73  * your own scrolling with #GtkScrollbar and for example a #GtkGrid.
74  */
75 public class ScrolledWindow : Bin
76 {
77 	/** the main Gtk struct */
78 	protected GtkScrolledWindow* gtkScrolledWindow;
79 
80 	/** Get the main Gtk struct */
81 	public GtkScrolledWindow* getScrolledWindowStruct()
82 	{
83 		return gtkScrolledWindow;
84 	}
85 
86 	/** the main Gtk struct as a void* */
87 	protected override void* getStruct()
88 	{
89 		return cast(void*)gtkScrolledWindow;
90 	}
91 
92 	protected override void setStruct(GObject* obj)
93 	{
94 		gtkScrolledWindow = cast(GtkScrolledWindow*)obj;
95 		super.setStruct(obj);
96 	}
97 
98 	/**
99 	 * Sets our main struct and passes it to the parent class.
100 	 */
101 	public this (GtkScrolledWindow* gtkScrolledWindow, bool ownedRef = false)
102 	{
103 		this.gtkScrolledWindow = gtkScrolledWindow;
104 		super(cast(GtkBin*)gtkScrolledWindow, ownedRef);
105 	}
106 
107 	/** */
108 	public this()
109 	{
110 		this(null, null);
111 	}
112 	
113 	/** */
114 	public this(Widget widget)
115 	{
116 		this();
117 		add(widget);
118 	}
119 	
120 	/**
121 	 * Creates a new Scrolled window and set the policy type
122 	 * Params:
123 	 *  hPolicy = the horizontal policy
124 	 *  vPolicy = the vertical policy
125 	 */
126 	this(PolicyType hPolicy, PolicyType vPolicy)
127 	{
128 		this();
129 		setPolicy(hPolicy, vPolicy);
130 	}
131 
132 	/**
133 	 */
134 
135 	public static GType getType()
136 	{
137 		return gtk_scrolled_window_get_type();
138 	}
139 
140 	/**
141 	 * Creates a new scrolled window.
142 	 *
143 	 * The two arguments are the scrolled window’s adjustments; these will be
144 	 * shared with the scrollbars and the child widget to keep the bars in sync
145 	 * with the child. Usually you want to pass %NULL for the adjustments, which
146 	 * will cause the scrolled window to create them for you.
147 	 *
148 	 * Params:
149 	 *     hadjustment = horizontal adjustment
150 	 *     vadjustment = vertical adjustment
151 	 *
152 	 * Return: a new scrolled window
153 	 *
154 	 * Throws: ConstructionException GTK+ fails to create the object.
155 	 */
156 	public this(Adjustment hadjustment, Adjustment vadjustment)
157 	{
158 		auto p = gtk_scrolled_window_new((hadjustment is null) ? null : hadjustment.getAdjustmentStruct(), (vadjustment is null) ? null : vadjustment.getAdjustmentStruct());
159 		
160 		if(p is null)
161 		{
162 			throw new ConstructionException("null returned by new");
163 		}
164 		
165 		this(cast(GtkScrolledWindow*) p);
166 	}
167 
168 	/**
169 	 * Used to add children without native scrolling capabilities. This
170 	 * is simply a convenience function; it is equivalent to adding the
171 	 * unscrollable child to a viewport, then adding the viewport to the
172 	 * scrolled window. If a child has native scrolling, use
173 	 * gtk_container_add() instead of this function.
174 	 *
175 	 * The viewport scrolls the child by moving its #GdkWindow, and takes
176 	 * the size of the child to be the size of its toplevel #GdkWindow.
177 	 * This will be very wrong for most widgets that support native scrolling;
178 	 * for example, if you add a widget such as #GtkTreeView with a viewport,
179 	 * the whole widget will scroll, including the column headings. Thus,
180 	 * widgets with native scrolling support should not be used with the
181 	 * #GtkViewport proxy.
182 	 *
183 	 * A widget supports scrolling natively if it implements the
184 	 * #GtkScrollable interface.
185 	 *
186 	 * Deprecated: gtk_container_add() will now automatically add
187 	 * a #GtkViewport if the child doesn’t implement #GtkScrollable.
188 	 *
189 	 * Params:
190 	 *     child = the widget you want to scroll
191 	 */
192 	public void addWithViewport(Widget child)
193 	{
194 		gtk_scrolled_window_add_with_viewport(gtkScrolledWindow, (child is null) ? null : child.getWidgetStruct());
195 	}
196 
197 	/**
198 	 * Return whether button presses are captured during kinetic
199 	 * scrolling. See gtk_scrolled_window_set_capture_button_press().
200 	 *
201 	 * Return: %TRUE if button presses are captured during kinetic scrolling
202 	 *
203 	 * Since: 3.4
204 	 */
205 	public bool getCaptureButtonPress()
206 	{
207 		return gtk_scrolled_window_get_capture_button_press(gtkScrolledWindow) != 0;
208 	}
209 
210 	/**
211 	 * Returns the horizontal scrollbar’s adjustment, used to connect the
212 	 * horizontal scrollbar to the child widget’s horizontal scroll
213 	 * functionality.
214 	 *
215 	 * Return: the horizontal #GtkAdjustment
216 	 */
217 	public Adjustment getHadjustment()
218 	{
219 		auto p = gtk_scrolled_window_get_hadjustment(gtkScrolledWindow);
220 		
221 		if(p is null)
222 		{
223 			return null;
224 		}
225 		
226 		return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p);
227 	}
228 
229 	/**
230 	 * Returns the horizontal scrollbar of @scrolled_window.
231 	 *
232 	 * Return: the horizontal scrollbar of the scrolled window.
233 	 *
234 	 * Since: 2.8
235 	 */
236 	public Widget getHscrollbar()
237 	{
238 		auto p = gtk_scrolled_window_get_hscrollbar(gtkScrolledWindow);
239 		
240 		if(p is null)
241 		{
242 			return null;
243 		}
244 		
245 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
246 	}
247 
248 	/**
249 	 * Returns the specified kinetic scrolling behavior.
250 	 *
251 	 * Return: the scrolling behavior flags.
252 	 *
253 	 * Since: 3.4
254 	 */
255 	public bool getKineticScrolling()
256 	{
257 		return gtk_scrolled_window_get_kinetic_scrolling(gtkScrolledWindow) != 0;
258 	}
259 
260 	/**
261 	 * Gets the minimal content height of @scrolled_window, or -1 if not set.
262 	 *
263 	 * Return: the minimal content height
264 	 *
265 	 * Since: 3.0
266 	 */
267 	public int getMinContentHeight()
268 	{
269 		return gtk_scrolled_window_get_min_content_height(gtkScrolledWindow);
270 	}
271 
272 	/**
273 	 * Gets the minimum content width of @scrolled_window, or -1 if not set.
274 	 *
275 	 * Return: the minimum content width
276 	 *
277 	 * Since: 3.0
278 	 */
279 	public int getMinContentWidth()
280 	{
281 		return gtk_scrolled_window_get_min_content_width(gtkScrolledWindow);
282 	}
283 
284 	/**
285 	 * Gets the placement of the contents with respect to the scrollbars
286 	 * for the scrolled window. See gtk_scrolled_window_set_placement().
287 	 *
288 	 * Return: the current placement value.
289 	 *
290 	 *     See also gtk_scrolled_window_set_placement() and
291 	 *     gtk_scrolled_window_unset_placement().
292 	 */
293 	public GtkCornerType getPlacement()
294 	{
295 		return gtk_scrolled_window_get_placement(gtkScrolledWindow);
296 	}
297 
298 	/**
299 	 * Retrieves the current policy values for the horizontal and vertical
300 	 * scrollbars. See gtk_scrolled_window_set_policy().
301 	 *
302 	 * Params:
303 	 *     hscrollbarPolicy = location to store the policy
304 	 *         for the horizontal scrollbar, or %NULL.
305 	 *     vscrollbarPolicy = location to store the policy
306 	 *         for the vertical scrollbar, or %NULL.
307 	 */
308 	public void getPolicy(out GtkPolicyType hscrollbarPolicy, out GtkPolicyType vscrollbarPolicy)
309 	{
310 		gtk_scrolled_window_get_policy(gtkScrolledWindow, &hscrollbarPolicy, &vscrollbarPolicy);
311 	}
312 
313 	/**
314 	 * Gets the shadow type of the scrolled window. See
315 	 * gtk_scrolled_window_set_shadow_type().
316 	 *
317 	 * Return: the current shadow type
318 	 */
319 	public GtkShadowType getShadowType()
320 	{
321 		return gtk_scrolled_window_get_shadow_type(gtkScrolledWindow);
322 	}
323 
324 	/**
325 	 * Returns the vertical scrollbar’s adjustment, used to connect the
326 	 * vertical scrollbar to the child widget’s vertical scroll functionality.
327 	 *
328 	 * Return: the vertical #GtkAdjustment
329 	 */
330 	public Adjustment getVadjustment()
331 	{
332 		auto p = gtk_scrolled_window_get_vadjustment(gtkScrolledWindow);
333 		
334 		if(p is null)
335 		{
336 			return null;
337 		}
338 		
339 		return ObjectG.getDObject!(Adjustment)(cast(GtkAdjustment*) p);
340 	}
341 
342 	/**
343 	 * Returns the vertical scrollbar of @scrolled_window.
344 	 *
345 	 * Return: the vertical scrollbar of the scrolled window.
346 	 *
347 	 * Since: 2.8
348 	 */
349 	public Widget getVscrollbar()
350 	{
351 		auto p = gtk_scrolled_window_get_vscrollbar(gtkScrolledWindow);
352 		
353 		if(p is null)
354 		{
355 			return null;
356 		}
357 		
358 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
359 	}
360 
361 	/**
362 	 * Changes the behaviour of @scrolled_window wrt. to the initial
363 	 * event that possibly starts kinetic scrolling. When @capture_button_press
364 	 * is set to %TRUE, the event is captured by the scrolled window, and
365 	 * then later replayed if it is meant to go to the child widget.
366 	 *
367 	 * This should be enabled if any child widgets perform non-reversible
368 	 * actions on #GtkWidget::button-press-event. If they don't, and handle
369 	 * additionally handle #GtkWidget::grab-broken-event, it might be better
370 	 * to set @capture_button_press to %FALSE.
371 	 *
372 	 * This setting only has an effect if kinetic scrolling is enabled.
373 	 *
374 	 * Params:
375 	 *     captureButtonPress = %TRUE to capture button presses
376 	 *
377 	 * Since: 3.4
378 	 */
379 	public void setCaptureButtonPress(bool captureButtonPress)
380 	{
381 		gtk_scrolled_window_set_capture_button_press(gtkScrolledWindow, captureButtonPress);
382 	}
383 
384 	/**
385 	 * Sets the #GtkAdjustment for the horizontal scrollbar.
386 	 *
387 	 * Params:
388 	 *     hadjustment = horizontal scroll adjustment
389 	 */
390 	public void setHadjustment(Adjustment hadjustment)
391 	{
392 		gtk_scrolled_window_set_hadjustment(gtkScrolledWindow, (hadjustment is null) ? null : hadjustment.getAdjustmentStruct());
393 	}
394 
395 	/**
396 	 * Turns kinetic scrolling on or off.
397 	 * Kinetic scrolling only applies to devices with source
398 	 * %GDK_SOURCE_TOUCHSCREEN.
399 	 *
400 	 * Params:
401 	 *     kineticScrolling = %TRUE to enable kinetic scrolling
402 	 *
403 	 * Since: 3.4
404 	 */
405 	public void setKineticScrolling(bool kineticScrolling)
406 	{
407 		gtk_scrolled_window_set_kinetic_scrolling(gtkScrolledWindow, kineticScrolling);
408 	}
409 
410 	/**
411 	 * Sets the minimum height that @scrolled_window should keep visible.
412 	 * Note that this can and (usually will) be smaller than the minimum
413 	 * size of the content.
414 	 *
415 	 * Params:
416 	 *     height = the minimal content height
417 	 *
418 	 * Since: 3.0
419 	 */
420 	public void setMinContentHeight(int height)
421 	{
422 		gtk_scrolled_window_set_min_content_height(gtkScrolledWindow, height);
423 	}
424 
425 	/**
426 	 * Sets the minimum width that @scrolled_window should keep visible.
427 	 * Note that this can and (usually will) be smaller than the minimum
428 	 * size of the content.
429 	 *
430 	 * Params:
431 	 *     width = the minimal content width
432 	 *
433 	 * Since: 3.0
434 	 */
435 	public void setMinContentWidth(int width)
436 	{
437 		gtk_scrolled_window_set_min_content_width(gtkScrolledWindow, width);
438 	}
439 
440 	/**
441 	 * Sets the placement of the contents with respect to the scrollbars
442 	 * for the scrolled window.
443 	 *
444 	 * The default is %GTK_CORNER_TOP_LEFT, meaning the child is
445 	 * in the top left, with the scrollbars underneath and to the right.
446 	 * Other values in #GtkCornerType are %GTK_CORNER_TOP_RIGHT,
447 	 * %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.
448 	 *
449 	 * See also gtk_scrolled_window_get_placement() and
450 	 * gtk_scrolled_window_unset_placement().
451 	 *
452 	 * Params:
453 	 *     windowPlacement = position of the child window
454 	 */
455 	public void setPlacement(GtkCornerType windowPlacement)
456 	{
457 		gtk_scrolled_window_set_placement(gtkScrolledWindow, windowPlacement);
458 	}
459 
460 	/**
461 	 * Sets the scrollbar policy for the horizontal and vertical scrollbars.
462 	 *
463 	 * The policy determines when the scrollbar should appear; it is a value
464 	 * from the #GtkPolicyType enumeration. If %GTK_POLICY_ALWAYS, the
465 	 * scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
466 	 * never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
467 	 * if needed (that is, if the slider part of the bar would be smaller
468 	 * than the trough - the display is larger than the page size).
469 	 *
470 	 * Params:
471 	 *     hscrollbarPolicy = policy for horizontal bar
472 	 *     vscrollbarPolicy = policy for vertical bar
473 	 */
474 	public void setPolicy(GtkPolicyType hscrollbarPolicy, GtkPolicyType vscrollbarPolicy)
475 	{
476 		gtk_scrolled_window_set_policy(gtkScrolledWindow, hscrollbarPolicy, vscrollbarPolicy);
477 	}
478 
479 	/**
480 	 * Changes the type of shadow drawn around the contents of
481 	 * @scrolled_window.
482 	 *
483 	 * Params:
484 	 *     type = kind of shadow to draw around scrolled window contents
485 	 */
486 	public void setShadowType(GtkShadowType type)
487 	{
488 		gtk_scrolled_window_set_shadow_type(gtkScrolledWindow, type);
489 	}
490 
491 	/**
492 	 * Sets the #GtkAdjustment for the vertical scrollbar.
493 	 *
494 	 * Params:
495 	 *     vadjustment = vertical scroll adjustment
496 	 */
497 	public void setVadjustment(Adjustment vadjustment)
498 	{
499 		gtk_scrolled_window_set_vadjustment(gtkScrolledWindow, (vadjustment is null) ? null : vadjustment.getAdjustmentStruct());
500 	}
501 
502 	/**
503 	 * Unsets the placement of the contents with respect to the scrollbars
504 	 * for the scrolled window. If no window placement is set for a scrolled
505 	 * window, it defaults to GTK_CORNER_TOP_LEFT.
506 	 *
507 	 * See also gtk_scrolled_window_set_placement() and
508 	 * gtk_scrolled_window_get_placement().
509 	 *
510 	 * Since: 2.10
511 	 */
512 	public void unsetPlacement()
513 	{
514 		gtk_scrolled_window_unset_placement(gtkScrolledWindow);
515 	}
516 
517 	int[string] connectedSignals;
518 
519 	void delegate(GtkDirectionType, ScrolledWindow)[] onMoveFocusOutListeners;
520 	/**
521 	 * The ::move-focus-out signal is a
522 	 * [keybinding signal][GtkBindingSignal] which gets
523 	 * emitted when focus is moved away from the scrolled window by a
524 	 * keybinding.  The #GtkWidget::move-focus signal is emitted with
525 	 * @direction_type on this scrolled windows toplevel parent in the
526 	 * container hierarchy.  The default bindings for this signal are
527 	 * `Tab + Ctrl` and `Tab + Ctrl + Shift`.
528 	 *
529 	 * Params:
530 	 *     directionType = either %GTK_DIR_TAB_FORWARD or
531 	 *         %GTK_DIR_TAB_BACKWARD
532 	 */
533 	void addOnMoveFocusOut(void delegate(GtkDirectionType, ScrolledWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
534 	{
535 		if ( "move-focus-out" !in connectedSignals )
536 		{
537 			Signals.connectData(
538 				this,
539 				"move-focus-out",
540 				cast(GCallback)&callBackMoveFocusOut,
541 				cast(void*)this,
542 				null,
543 				connectFlags);
544 			connectedSignals["move-focus-out"] = 1;
545 		}
546 		onMoveFocusOutListeners ~= dlg;
547 	}
548 	extern(C) static void callBackMoveFocusOut(GtkScrolledWindow* scrolledwindowStruct, GtkDirectionType directionType, ScrolledWindow _scrolledwindow)
549 	{
550 		foreach ( void delegate(GtkDirectionType, ScrolledWindow) dlg; _scrolledwindow.onMoveFocusOutListeners )
551 		{
552 			dlg(directionType, _scrolledwindow);
553 		}
554 	}
555 
556 	bool delegate(GtkScrollType, bool, ScrolledWindow)[] onScrollChildListeners;
557 	/**
558 	 * The ::scroll-child signal is a
559 	 * [keybinding signal][GtkBindingSignal]
560 	 * which gets emitted when a keybinding that scrolls is pressed.
561 	 * The horizontal or vertical adjustment is updated which triggers a
562 	 * signal that the scrolled windows child may listen to and scroll itself.
563 	 *
564 	 * Params:
565 	 *     scroll = a #GtkScrollType describing how much to scroll
566 	 *     horizontal = whether the keybinding scrolls the child
567 	 *         horizontally or not
568 	 */
569 	void addOnScrollChild(bool delegate(GtkScrollType, bool, ScrolledWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
570 	{
571 		if ( "scroll-child" !in connectedSignals )
572 		{
573 			Signals.connectData(
574 				this,
575 				"scroll-child",
576 				cast(GCallback)&callBackScrollChild,
577 				cast(void*)this,
578 				null,
579 				connectFlags);
580 			connectedSignals["scroll-child"] = 1;
581 		}
582 		onScrollChildListeners ~= dlg;
583 	}
584 	extern(C) static int callBackScrollChild(GtkScrolledWindow* scrolledwindowStruct, GtkScrollType scroll, bool horizontal, ScrolledWindow _scrolledwindow)
585 	{
586 		foreach ( bool delegate(GtkScrollType, bool, ScrolledWindow) dlg; _scrolledwindow.onScrollChildListeners )
587 		{
588 			if ( dlg(scroll, horizontal, _scrolledwindow) )
589 			{
590 				return 1;
591 			}
592 		}
593 		
594 		return 0;
595 	}
596 }