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.EventControllerScroll;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.EventController;
31 private import gtk.c.functions;
32 public  import gtk.c.types;
33 private import std.algorithm;
34 
35 
36 /**
37  * `GtkEventControllerScroll` is an event controller that handles scroll
38  * events.
39  * 
40  * It is capable of handling both discrete and continuous scroll
41  * events from mice or touchpads, abstracting them both with the
42  * [signal@Gtk.EventControllerScroll::scroll] signal. Deltas in
43  * the discrete case are multiples of 1.
44  * 
45  * In the case of continuous scroll events, `GtkEventControllerScroll`
46  * encloses all [signal@Gtk.EventControllerScroll::scroll] emissions
47  * between two [signal@Gtk.EventControllerScroll::scroll-begin] and
48  * [signal@Gtk.EventControllerScroll::scroll-end] signals.
49  * 
50  * The behavior of the event controller can be modified by the flags
51  * given at creation time, or modified at a later point through
52  * [method@Gtk.EventControllerScroll.set_flags] (e.g. because the scrolling
53  * conditions of the widget changed).
54  * 
55  * The controller can be set up to emit motion for either/both vertical
56  * and horizontal scroll events through %GTK_EVENT_CONTROLLER_SCROLL_VERTICAL,
57  * %GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL and %GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES.
58  * If any axis is disabled, the respective [signal@Gtk.EventControllerScroll::scroll]
59  * delta will be 0. Vertical scroll events will be translated to horizontal
60  * motion for the devices incapable of horizontal scrolling.
61  * 
62  * The event controller can also be forced to emit discrete events on all
63  * devices through %GTK_EVENT_CONTROLLER_SCROLL_DISCRETE. This can be used
64  * to implement discrete actions triggered through scroll events (e.g.
65  * switching across combobox options).
66  * 
67  * The %GTK_EVENT_CONTROLLER_SCROLL_KINETIC flag toggles the emission of the
68  * [signal@Gtk.EventControllerScroll::decelerate] signal, emitted at the end
69  * of scrolling with two X/Y velocity arguments that are consistent with the
70  * motion that was received.
71  */
72 public class EventControllerScroll : EventController
73 {
74 	/** the main Gtk struct */
75 	protected GtkEventControllerScroll* gtkEventControllerScroll;
76 
77 	/** Get the main Gtk struct */
78 	public GtkEventControllerScroll* getEventControllerScrollStruct(bool transferOwnership = false)
79 	{
80 		if (transferOwnership)
81 			ownedRef = false;
82 		return gtkEventControllerScroll;
83 	}
84 
85 	/** the main Gtk struct as a void* */
86 	protected override void* getStruct()
87 	{
88 		return cast(void*)gtkEventControllerScroll;
89 	}
90 
91 	/**
92 	 * Sets our main struct and passes it to the parent class.
93 	 */
94 	public this (GtkEventControllerScroll* gtkEventControllerScroll, bool ownedRef = false)
95 	{
96 		this.gtkEventControllerScroll = gtkEventControllerScroll;
97 		super(cast(GtkEventController*)gtkEventControllerScroll, ownedRef);
98 	}
99 
100 
101 	/** */
102 	public static GType getType()
103 	{
104 		return gtk_event_controller_scroll_get_type();
105 	}
106 
107 	/**
108 	 * Creates a new event controller that will handle scroll events.
109 	 *
110 	 * Params:
111 	 *     flags = flags affecting the controller behavior
112 	 *
113 	 * Returns: a new `GtkEventControllerScroll`
114 	 *
115 	 * Throws: ConstructionException GTK+ fails to create the object.
116 	 */
117 	public this(GtkEventControllerScrollFlags flags)
118 	{
119 		auto __p = gtk_event_controller_scroll_new(flags);
120 
121 		if(__p is null)
122 		{
123 			throw new ConstructionException("null returned by new");
124 		}
125 
126 		this(cast(GtkEventControllerScroll*) __p, true);
127 	}
128 
129 	/**
130 	 * Gets the flags conditioning the scroll controller behavior.
131 	 *
132 	 * Returns: the controller flags.
133 	 */
134 	public GtkEventControllerScrollFlags getFlags()
135 	{
136 		return gtk_event_controller_scroll_get_flags(gtkEventControllerScroll);
137 	}
138 
139 	/**
140 	 * Sets the flags conditioning scroll controller behavior.
141 	 *
142 	 * Params:
143 	 *     flags = flags affecting the controller behavior
144 	 */
145 	public void setFlags(GtkEventControllerScrollFlags flags)
146 	{
147 		gtk_event_controller_scroll_set_flags(gtkEventControllerScroll, flags);
148 	}
149 
150 	/**
151 	 * Emitted after scroll is finished if the
152 	 * %GTK_EVENT_CONTROLLER_SCROLL_KINETIC flag is set.
153 	 *
154 	 * @vel_x and @vel_y express the initial velocity that was
155 	 * imprinted by the scroll events. @vel_x and @vel_y are expressed in
156 	 * pixels/ms.
157 	 *
158 	 * Params:
159 	 *     velX = X velocity
160 	 *     velY = Y velocity
161 	 */
162 	gulong addOnDecelerate(void delegate(double, double, EventControllerScroll) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
163 	{
164 		return Signals.connect(this, "decelerate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
165 	}
166 
167 	/**
168 	 * Signals that the widget should scroll by the
169 	 * amount specified by @dx and @dy.
170 	 *
171 	 * Params:
172 	 *     dx = X delta
173 	 *     dy = Y delta
174 	 *
175 	 * Returns: %TRUE if the scroll event was handled,
176 	 *     %FALSE otherwise.
177 	 */
178 	gulong addOnScroll(bool delegate(double, double, EventControllerScroll) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
179 	{
180 		return Signals.connect(this, "scroll", dlg, connectFlags ^ ConnectFlags.SWAPPED);
181 	}
182 
183 	/**
184 	 * Signals that a new scrolling operation has begun.
185 	 *
186 	 * It will only be emitted on devices capable of it.
187 	 */
188 	gulong addOnScrollBegin(void delegate(EventControllerScroll) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
189 	{
190 		return Signals.connect(this, "scroll-begin", dlg, connectFlags ^ ConnectFlags.SWAPPED);
191 	}
192 
193 	/**
194 	 * Signals that a scrolling operation has finished.
195 	 *
196 	 * It will only be emitted on devices capable of it.
197 	 */
198 	gulong addOnScrollEnd(void delegate(EventControllerScroll) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
199 	{
200 		return Signals.connect(this, "scroll-end", dlg, connectFlags ^ ConnectFlags.SWAPPED);
201 	}
202 }