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.
30 #include <glib/gi18n.h>
31 #include "modest-scrolled-window-scrollable.h"
33 static void modest_scrolled_window_scrollable_class_init (ModestScrolledWindowScrollableClass *klass);
34 static void modest_scrolled_window_scrollable_init (ModestScrolledWindowScrollable *self);
35 static void modest_scrollable_iface_init (gpointer g, gpointer iface_data);
37 /* GObject interface */
38 static void modest_scrolled_window_scrollable_finalize (GObject *obj);
39 static void modest_scrolled_window_scrollable_get_property (GObject *obj,
43 static void modest_scrolled_window_scrollable_set_property (GObject *obj,
48 /* Modest scrollable interface */
49 static void modest_scrolled_window_scrollable_add_with_viewport (ModestScrollable *self, GtkWidget *widget);
50 static void modest_scrolled_window_scrollable_add_with_viewport_default (ModestScrollable *self, GtkWidget *widget);
51 static GtkAdjustment *modest_scrolled_window_scrollable_get_vadjustment (ModestScrollable *self);
52 static GtkAdjustment *modest_scrolled_window_scrollable_get_vadjustment_default (ModestScrollable *self);
53 static GtkAdjustment *modest_scrolled_window_scrollable_get_hadjustment (ModestScrollable *self);
54 static GtkAdjustment *modest_scrolled_window_scrollable_get_hadjustment_default (ModestScrollable *self);
55 static void modest_scrolled_window_scrollable_scroll_to (ModestScrollable *self, const gint x, const gint y);
56 static void modest_scrolled_window_scrollable_scroll_to_default (ModestScrollable *self, const gint x, const gint y);
57 static void modest_scrolled_window_scrollable_jump_to (ModestScrollable *self, const gint x, const gint y);
58 static void modest_scrolled_window_scrollable_jump_to_default (ModestScrollable *self, const gint x, const gint y);
59 static GtkPolicyType modest_scrolled_window_scrollable_get_vertical_policy (ModestScrollable *self);
60 static GtkPolicyType modest_scrolled_window_scrollable_get_vertical_policy_default (ModestScrollable *self);
61 static GtkPolicyType modest_scrolled_window_scrollable_get_horizontal_policy (ModestScrollable *self);
62 static GtkPolicyType modest_scrolled_window_scrollable_get_horizontal_policy_default (ModestScrollable *self);
63 static void modest_scrolled_window_scrollable_set_horizontal_policy (ModestScrollable *self, GtkPolicyType policy);
64 static void modest_scrolled_window_scrollable_set_horizontal_policy_default (ModestScrollable *self, GtkPolicyType policy);
65 static void modest_scrolled_window_scrollable_set_vertical_policy (ModestScrollable *self, GtkPolicyType policy);
66 static void modest_scrolled_window_scrollable_set_vertical_policy_default (ModestScrollable *self, GtkPolicyType policy);
71 PROP_HORIZONTAL_POLICY,
74 PROP_HORIZONTAL_MAX_OVERSHOOT,
75 PROP_VERTICAL_MAX_OVERSHOOT,
79 static GtkScrolledWindowClass *parent_class = NULL;
81 G_DEFINE_TYPE_EXTENDED (ModestScrolledWindowScrollable,
82 modest_scrolled_window_scrollable,
83 GTK_TYPE_SCROLLED_WINDOW,
86 G_IMPLEMENT_INTERFACE (MODEST_TYPE_SCROLLABLE, modest_scrollable_iface_init);
91 modest_scrolled_window_scrollable_new (void)
93 GtkWidget *scrollable = g_object_new (MODEST_TYPE_SCROLLED_WINDOW_SCROLLABLE,
94 "hscrollbar-policy", GTK_POLICY_NEVER,
95 "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
102 modest_scrolled_window_scrollable_class_init (ModestScrolledWindowScrollableClass *klass)
104 GObjectClass *gobject_class;
106 parent_class = g_type_class_peek_parent (klass);
107 gobject_class = (GObjectClass *) klass;
108 gobject_class->finalize = modest_scrolled_window_scrollable_finalize;
109 gobject_class->set_property = modest_scrolled_window_scrollable_set_property;
110 gobject_class->get_property = modest_scrolled_window_scrollable_get_property;
112 klass->add_with_viewport_func = modest_scrolled_window_scrollable_add_with_viewport_default;
113 klass->get_vadjustment_func = modest_scrolled_window_scrollable_get_vadjustment_default;
114 klass->get_hadjustment_func = modest_scrolled_window_scrollable_get_hadjustment_default;
115 klass->scroll_to_func = modest_scrolled_window_scrollable_scroll_to_default;
116 klass->jump_to_func = modest_scrolled_window_scrollable_jump_to_default;
117 klass->get_vertical_policy_func = modest_scrolled_window_scrollable_get_vertical_policy_default;
118 klass->get_horizontal_policy_func = modest_scrolled_window_scrollable_get_horizontal_policy_default;
119 klass->set_vertical_policy_func = modest_scrolled_window_scrollable_set_vertical_policy_default;
120 klass->set_horizontal_policy_func = modest_scrolled_window_scrollable_set_horizontal_policy_default;
122 g_object_class_install_property (gobject_class,
123 PROP_HORIZONTAL_POLICY,
124 g_param_spec_enum ("horizontal_policy",
125 _("Horizontal scrollbar policy"),
126 _("Visual policy of the horizontal scrollbar"),
127 GTK_TYPE_POLICY_TYPE,
128 GTK_POLICY_AUTOMATIC,
129 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
131 g_object_class_install_property (gobject_class,
132 PROP_VERTICAL_POLICY,
133 g_param_spec_enum ("vertical_policy",
134 _("Vertical scrollbar policy"),
135 _("Visual policy of the vertical scrollbar"),
136 GTK_TYPE_POLICY_TYPE,
137 GTK_POLICY_AUTOMATIC,
138 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
140 g_object_class_install_property (gobject_class,
142 g_param_spec_flags ("movement_mode",
143 "Directions scroll is allowed",
144 "Movements allowed in the scrollable",
145 MODEST_TYPE_MOVEMENT_MODE,
146 MODEST_MOVEMENT_MODE_VERTICAL,
150 g_object_class_install_property (gobject_class,
151 PROP_HORIZONTAL_MAX_OVERSHOOT,
152 g_param_spec_int ("horizontal-max-overshoot",
153 "Horizontal max overshoot",
154 "Horizontal maximum overshoot (0 disables)",
156 G_PARAM_READWRITE |G_PARAM_CONSTRUCT));
158 g_object_class_install_property (gobject_class,
159 PROP_VERTICAL_MAX_OVERSHOOT,
160 g_param_spec_int ("vertical-max-overshoot",
161 "Vertical max overshoot",
162 "Vertical maximum overshoot (0 disables)",
164 G_PARAM_READWRITE |G_PARAM_CONSTRUCT));
168 modest_scrolled_window_scrollable_init (ModestScrolledWindowScrollable *self)
173 modest_scrollable_iface_init (gpointer g, gpointer iface_data)
175 ModestScrollableIface *iface = (ModestScrollableIface *) g;
177 iface->jump_to = modest_scrolled_window_scrollable_jump_to;
178 iface->scroll_to = modest_scrolled_window_scrollable_scroll_to;
179 iface->add_with_viewport = modest_scrolled_window_scrollable_add_with_viewport;
180 iface->get_vadjustment = modest_scrolled_window_scrollable_get_vadjustment;
181 iface->get_hadjustment = modest_scrolled_window_scrollable_get_hadjustment;
182 iface->get_vertical_policy = modest_scrolled_window_scrollable_get_vertical_policy;
183 iface->set_vertical_policy = modest_scrolled_window_scrollable_set_vertical_policy;
184 iface->get_horizontal_policy = modest_scrolled_window_scrollable_get_horizontal_policy;
185 iface->set_horizontal_policy = modest_scrolled_window_scrollable_set_horizontal_policy;
189 modest_scrolled_window_scrollable_finalize (GObject *obj)
191 G_OBJECT_CLASS(parent_class)->finalize (obj);
195 modest_scrolled_window_scrollable_get_property (GObject *obj,
200 GtkPolicyType policy;
203 case PROP_VERTICAL_POLICY:
204 gtk_scrolled_window_get_policy (GTK_SCROLLED_WINDOW (obj), NULL, &policy);
205 g_value_set_enum (value, policy);
207 case PROP_HORIZONTAL_POLICY:
208 gtk_scrolled_window_get_policy (GTK_SCROLLED_WINDOW (obj), &policy, NULL);
209 g_value_set_enum (value, policy);
211 case PROP_MOVEMENT_MODE:
212 g_value_set_enum (value, MODEST_MOVEMENT_MODE_BOTH);
214 case PROP_HORIZONTAL_MAX_OVERSHOOT:
215 g_value_set_int (value, 0);
217 case PROP_VERTICAL_MAX_OVERSHOOT:
218 g_value_set_int (value, 0);
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
227 modest_scrolled_window_scrollable_set_property (GObject *obj,
232 GtkPolicyType hpolicy, vpolicy;
234 gtk_scrolled_window_get_policy (GTK_SCROLLED_WINDOW (obj), &hpolicy, &vpolicy);
236 case PROP_VERTICAL_POLICY:
237 vpolicy = g_value_get_enum (value);
238 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (obj), hpolicy, vpolicy);
240 case PROP_HORIZONTAL_POLICY:
241 hpolicy = g_value_get_enum (value);
242 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (obj), hpolicy, vpolicy);
244 case PROP_MOVEMENT_MODE:
245 case PROP_HORIZONTAL_MAX_OVERSHOOT:
246 case PROP_VERTICAL_MAX_OVERSHOOT:
247 /* these three parameters are not supported in scrolled window */
250 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
256 modest_scrolled_window_scrollable_add_with_viewport (ModestScrollable *self,
259 MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->add_with_viewport_func (self, widget);
263 modest_scrolled_window_scrollable_add_with_viewport_default (ModestScrollable *self,
266 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (self), widget);
269 static GtkAdjustment *
270 modest_scrolled_window_scrollable_get_vadjustment (ModestScrollable *self)
272 return MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->get_vadjustment_func (self);
275 static GtkAdjustment *
276 modest_scrolled_window_scrollable_get_vadjustment_default (ModestScrollable *self)
278 return gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self));
281 static GtkAdjustment *
282 modest_scrolled_window_scrollable_get_hadjustment (ModestScrollable *self)
284 return MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->get_hadjustment_func (self);
287 static GtkAdjustment *
288 modest_scrolled_window_scrollable_get_hadjustment_default (ModestScrollable *self)
290 return gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (self));
294 modest_scrolled_window_scrollable_scroll_to (ModestScrollable *self,
295 const gint x, const gint y)
297 MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->scroll_to_func (self, x, y);
301 modest_scrolled_window_scrollable_scroll_to_default (ModestScrollable *self,
302 const gint x, const gint y)
304 GtkAdjustment *vadj, *hadj;
305 hadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self));
306 gtk_adjustment_set_value (hadj, (gdouble) y);
307 vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self));
311 modest_scrolled_window_scrollable_jump_to (ModestScrollable *self,
312 const gint x, const gint y)
314 MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->jump_to_func (self, x, y);
318 modest_scrolled_window_scrollable_jump_to_default (ModestScrollable *self,
319 const gint x, const gint y)
321 modest_scrollable_scroll_to (MODEST_SCROLLABLE (self), x, y);
325 modest_scrolled_window_scrollable_get_vertical_policy (ModestScrollable *self)
327 return MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->get_vertical_policy_func (self);
331 modest_scrolled_window_scrollable_get_vertical_policy_default (ModestScrollable *self)
333 GtkPolicyType policy;
335 g_object_get (G_OBJECT (self), "vertical-policy", &policy, NULL);
340 modest_scrolled_window_scrollable_get_horizontal_policy (ModestScrollable *self)
342 return MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->get_horizontal_policy_func (self);
346 modest_scrolled_window_scrollable_get_horizontal_policy_default (ModestScrollable *self)
348 GtkPolicyType policy;
350 g_object_get (G_OBJECT (self), "horizontal-policy", &policy, NULL);
355 modest_scrolled_window_scrollable_set_horizontal_policy (ModestScrollable *self,
356 GtkPolicyType policy)
358 MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->set_horizontal_policy_func (self, policy);
362 modest_scrolled_window_scrollable_set_horizontal_policy_default (ModestScrollable *self,
363 GtkPolicyType policy)
365 g_object_set (G_OBJECT (self), "horizontal-policy", policy, NULL);
369 modest_scrolled_window_scrollable_set_vertical_policy (ModestScrollable *self,
370 GtkPolicyType policy)
372 MODEST_SCROLLED_WINDOW_SCROLLABLE_GET_CLASS (self)->set_vertical_policy_func (self, policy);
376 modest_scrolled_window_scrollable_set_vertical_policy_default (ModestScrollable *self,
377 GtkPolicyType policy)
379 g_object_set (G_OBJECT (self), "vertical-policy", policy, NULL);