1 /* Copyright (c) 2009, Igalia
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <modest-scrollable.h>
35 * modest_scrollable_add_with_viewport:
36 * @scrollable: a #ModestScrollable instance
37 * @widget: a #GtkWidget
39 * adds a widget to the @scrollable, wrapping it into a viewport.
40 * This is useful if @widget does not implement scroll_adjustments
44 modest_scrollable_add_with_viewport (ModestScrollable *scrollable,
47 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->add_with_viewport) {
48 MODEST_SCROLLABLE_GET_IFACE (scrollable)->add_with_viewport (scrollable, widget);
53 * modest_scrollable_get_vadjustment:
54 * @self: a #ModestScrollable
56 * obtains the vertical adjustment for @self
58 * Returns: a #GtkAdjustment
61 modest_scrollable_get_vadjustment (ModestScrollable *self)
63 if (MODEST_SCROLLABLE_GET_IFACE (self)->get_vadjustment) {
64 return MODEST_SCROLLABLE_GET_IFACE (self)->get_vadjustment (self);
71 * modest_scrollable_get_hadjustment:
72 * @self: a #ModestScrollable
74 * obtains the horizontal adjustment for @self
76 * Returns: a #GtkAdjustment
79 modest_scrollable_get_hadjustment (ModestScrollable *self)
81 if (MODEST_SCROLLABLE_GET_IFACE (self)->get_hadjustment) {
82 return MODEST_SCROLLABLE_GET_IFACE (self)->get_hadjustment (self);
89 * modest_scrollable_scroll_to:
90 * @scrollable: a #ModestScrollable instance
91 * @x: the X coordinate to scroll to
92 * @y: the Y coordinate to scroll to
94 * scrolls softly visible area of @scrollable, to show the coordinates
98 modest_scrollable_scroll_to (ModestScrollable *scrollable,
99 const gint x, const gint y)
101 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->scroll_to) {
102 MODEST_SCROLLABLE_GET_IFACE (scrollable)->scroll_to (scrollable, x, y);
107 * modest_scrollable_jump_to:
108 * @scrollable: a #ModestScrollable instance
109 * @x: the X coordinate to jump to
110 * @y: the Y coordinate to jump to
112 * scrolls visible area of @scrollable, to show the coordinates
113 * (@x, @y). Movement is immediate.
116 modest_scrollable_jump_to (ModestScrollable *scrollable,
117 const gint x, const gint y)
119 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->jump_to) {
120 MODEST_SCROLLABLE_GET_IFACE (scrollable)->jump_to (scrollable, x, y);
125 * modest_scrollable_get_vertical_policy:
126 * @scrollable: a #ModestScrollable instance
128 * returns the vertical scroll policy
130 * Returns: a #GtkPolicyType
133 modest_scrollable_get_vertical_policy (ModestScrollable *scrollable)
135 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_vertical_policy) {
136 return MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_vertical_policy (scrollable);
138 return GTK_POLICY_NEVER;
143 * modest_scrollable_get_horizontal_policy:
144 * @scrollable: a #ModestScrollable instance
146 * returns the horizontal scroll policy
148 * Returns: a #GtkPolicyType
151 modest_scrollable_get_horizontal_policy (ModestScrollable *scrollable)
153 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_horizontal_policy) {
154 return MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_horizontal_policy (scrollable);
156 return GTK_POLICY_NEVER;
161 * modest_scrollable_set_vertical_policy:
162 * @scrollable: a #ModestScrollable instance
163 * @policy: a #GtkPolicyType
165 * sets the vertical scroll policy
168 modest_scrollable_set_vertical_policy (ModestScrollable *scrollable,
169 GtkPolicyType policy)
171 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_vertical_policy) {
172 MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_vertical_policy (scrollable, policy);
177 * modest_scrollable_set_horizontal_policy:
178 * @scrollable: a #ModestScrollable instance
179 * @policy: a #GtkPolicyType
181 * sets the horizontal scroll policy
184 modest_scrollable_set_horizontal_policy (ModestScrollable *scrollable,
185 GtkPolicyType policy)
187 if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_horizontal_policy) {
188 MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_horizontal_policy (scrollable, policy);
193 modest_scrollable_base_init (gpointer g_iface)
195 static gboolean initialized = FALSE;
198 /* create interface signals here. */
201 g_object_interface_install_property (g_iface,
202 g_param_spec_enum ("vertical_policy",
203 "Vertical scroll policy",
204 "Visual policy of the vertical scroll",
205 GTK_TYPE_POLICY_TYPE,
206 GTK_POLICY_AUTOMATIC,
210 g_object_interface_install_property (g_iface,
211 g_param_spec_enum ("horizontal_policy",
212 "Horizontal scroll policy",
213 "Visual policy of the horizontal scroll",
214 GTK_TYPE_POLICY_TYPE,
215 GTK_POLICY_AUTOMATIC,
219 g_object_interface_install_property (g_iface,
220 g_param_spec_flags ("movement_mode",
221 "Directions scroll is allowed",
222 "Movements allowed in the scrollable",
223 MODEST_TYPE_MOVEMENT_MODE,
224 MODEST_MOVEMENT_MODE_VERTICAL,
228 g_object_interface_install_property (g_iface,
229 g_param_spec_int ("horizontal-max-overshoot",
230 "Horizontal max overshoot",
231 "Horizontal maximum overshoot (0 disables)",
233 G_PARAM_READWRITE |G_PARAM_CONSTRUCT));
235 g_object_interface_install_property (g_iface,
236 g_param_spec_int ("vertical-max-overshoot",
237 "Vertical max overshoot",
238 "Vertical maximum overshoot (0 disables)",
240 G_PARAM_READWRITE |G_PARAM_CONSTRUCT));
247 modest_scrollable_get_type (void)
249 static GType type = 0;
251 if (G_UNLIKELY(type == 0))
253 static const GTypeInfo info =
255 sizeof (ModestScrollableIface),
256 modest_scrollable_base_init, /* base_init */
257 NULL, /* base_finalize */
258 NULL, /* class_init */
259 NULL, /* class_finalize */
260 NULL, /* class_data */
263 NULL, /* instance_init */
267 type = g_type_register_static (G_TYPE_INTERFACE,
268 "ModestScrollable", &info, 0);
276 modest_scrollable_scroll (ModestScrollable *scrollable,
277 gint horizontal, gint vertical)
279 g_return_if_fail (MODEST_IS_SCROLLABLE (scrollable));
283 g_assert (scrollable);
284 /* at atleast one of values have to be valid */
285 g_return_if_fail (h_pos == -1 && v_pos == -1);
287 if (horizontal != 0) {
288 GtkAdjustment *h_adj;
290 h_adj = modest_scrollable_get_hadjustment (scrollable);
291 g_return_if_fail (h_adj);
293 h_pos = h_adj->value + h_adj->step_increment * horizontal;
294 if (horizontal > 0) {
295 h_pos += h_adj->page_size;
296 if (h_pos > h_adj->upper - h_adj->page_size) {
297 h_pos = h_adj->upper - h_adj->page_size;
298 } else if (h_pos < 0) {
305 GtkAdjustment *v_adj;
307 v_adj = modest_scrollable_get_vadjustment (scrollable);
308 g_return_if_fail (v_adj);
310 v_pos = v_adj->value + v_adj->step_increment * vertical;
312 v_pos += v_adj->page_size;
313 if (v_pos > v_adj->upper - v_adj->page_size) {
314 v_pos = v_adj->upper - v_adj->page_size;
315 } else if (v_pos < 0) {
321 modest_scrollable_scroll_to (scrollable, h_pos, v_pos);
325 modest_movement_mode_get_type (void)
327 static GType etype = 0;
329 static const GFlagsValue values[] = {
330 { MODEST_MOVEMENT_MODE_HORIZONTAL, "HILDON_MOVEMENT_MODE_HORIZONTAL", "horizontal" },
331 { MODEST_MOVEMENT_MODE_VERTICAL, "MODEST_MOVEMENT_MODE_VERTICAL", "vertical" },
332 { MODEST_MOVEMENT_MODE_BOTH, "MODEST_MOVEMENT_MODE_BOTH", "both" },
335 etype = g_flags_register_static ("ModestMovementMode", values);