Modified webpage: now tinymail repository is in gitorious.
[modest] / src / widgets / modest-scrollable.c
index 693b17b..268f304 100644 (file)
@@ -121,7 +121,73 @@ modest_scrollable_jump_to (ModestScrollable *scrollable,
        }
 }
 
+/**
+ * modest_scrollable_get_vertical_policy:
+ * @scrollable: a #ModestScrollable instance
+ *
+ * returns the vertical scroll policy
+ *
+ * Returns: a #GtkPolicyType
+ */
+GtkPolicyType            
+modest_scrollable_get_vertical_policy (ModestScrollable *scrollable)
+{
+       if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_vertical_policy) {
+               return MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_vertical_policy (scrollable);
+       } else {
+               return GTK_POLICY_NEVER;
+       }
+}
 
+/**
+ * modest_scrollable_get_horizontal_policy:
+ * @scrollable: a #ModestScrollable instance
+ *
+ * returns the horizontal scroll policy
+ *
+ * Returns: a #GtkPolicyType
+ */
+GtkPolicyType            
+modest_scrollable_get_horizontal_policy (ModestScrollable *scrollable)
+{
+       if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_horizontal_policy) {
+               return MODEST_SCROLLABLE_GET_IFACE (scrollable)->get_horizontal_policy (scrollable);
+       } else {
+               return GTK_POLICY_NEVER;
+       }
+}
+
+/**
+ * modest_scrollable_set_vertical_policy:
+ * @scrollable: a #ModestScrollable instance
+ * @policy: a #GtkPolicyType
+ *
+ * sets the vertical scroll policy
+ */
+void
+modest_scrollable_set_vertical_policy (ModestScrollable *scrollable,
+                                      GtkPolicyType policy)
+{
+       if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_vertical_policy) {
+               MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_vertical_policy (scrollable, policy);
+       }
+}
+
+/**
+ * modest_scrollable_set_horizontal_policy:
+ * @scrollable: a #ModestScrollable instance
+ * @policy: a #GtkPolicyType
+ *
+ * sets the horizontal scroll policy
+ */
+void
+modest_scrollable_set_horizontal_policy (ModestScrollable *scrollable,
+                                        GtkPolicyType policy)
+{
+       if (MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_horizontal_policy) {
+               MODEST_SCROLLABLE_GET_IFACE (scrollable)->set_horizontal_policy (scrollable, policy);
+       }
+}
 
 static void
 modest_scrollable_base_init (gpointer g_iface)
@@ -133,23 +199,46 @@ modest_scrollable_base_init (gpointer g_iface)
                initialized = TRUE;
 
                g_object_interface_install_property (g_iface,
-                                                    g_param_spec_enum ("vscrollbar_policy",
-                                                                       "vscrollbar policy",
-                                                                       "Visual policy of the vertical scrollbar",
+                                                    g_param_spec_enum ("vertical_policy",
+                                                                       "Vertical scroll policy",
+                                                                       "Visual policy of the vertical scroll",
                                                                        GTK_TYPE_POLICY_TYPE,
                                                                        GTK_POLICY_AUTOMATIC,
                                                                        G_PARAM_READWRITE |
                                                                        G_PARAM_CONSTRUCT));
 
                g_object_interface_install_property (g_iface,
-                                                    g_param_spec_enum ("hscrollbar_policy",
-                                                                       "hscrollbar policy",
-                                                                       "Visual policy of the horizontal scrollbar",
+                                                    g_param_spec_enum ("horizontal_policy",
+                                                                       "Horizontal scroll policy",
+                                                                       "Visual policy of the horizontal scroll",
                                                                        GTK_TYPE_POLICY_TYPE,
                                                                        GTK_POLICY_AUTOMATIC,
                                                                        G_PARAM_READWRITE |
                                                                        G_PARAM_CONSTRUCT));
 
+               g_object_interface_install_property (g_iface,
+                                                    g_param_spec_flags ("movement_mode",
+                                                                        "Directions scroll is allowed",
+                                                                        "Movements allowed in the scrollable",
+                                                                        MODEST_TYPE_MOVEMENT_MODE,
+                                                                        MODEST_MOVEMENT_MODE_VERTICAL,
+                                                                        G_PARAM_READWRITE |
+                                                                        G_PARAM_CONSTRUCT));
+
+               g_object_interface_install_property (g_iface,
+                                                    g_param_spec_int ("horizontal-max-overshoot",
+                                                                      "Horizontal max overshoot",
+                                                                      "Horizontal maximum overshoot (0 disables)",
+                                                                      0, G_MAXINT, 150,
+                                                                      G_PARAM_READWRITE |G_PARAM_CONSTRUCT));
+
+               g_object_interface_install_property (g_iface,
+                                                    g_param_spec_int ("vertical-max-overshoot",
+                                                                      "Vertical max overshoot",
+                                                                      "Vertical maximum overshoot (0 disables)",
+                                                                      0, G_MAXINT, 150,
+                                                                      G_PARAM_READWRITE |G_PARAM_CONSTRUCT));
+
 
        }
 }
@@ -182,3 +271,68 @@ modest_scrollable_get_type (void)
 
        return type;
 }
+
+void
+modest_scrollable_scroll (ModestScrollable *scrollable, 
+                         gint horizontal, gint vertical)
+{
+       g_return_if_fail (MODEST_IS_SCROLLABLE (scrollable));
+       gint h_pos = -1;
+       gint v_pos = -1;
+
+       g_assert (scrollable);
+       /* at atleast one of values have to be valid */
+       g_return_if_fail (h_pos == -1 && v_pos == -1);
+
+       if (horizontal != 0) {
+               GtkAdjustment *h_adj;
+
+               h_adj = modest_scrollable_get_hadjustment (scrollable);
+               g_return_if_fail (h_adj);
+
+               h_pos = h_adj->value + h_adj->step_increment * horizontal;
+               if (horizontal > 0) {
+                       h_pos += h_adj->page_size;
+                       if (h_pos > h_adj->upper - h_adj->page_size) {
+                               h_pos = h_adj->upper - h_adj->page_size;
+                       } else if (h_pos < 0) {
+                               h_pos = 0;
+                       }
+               }
+       }
+
+       if (vertical != 0) {
+               GtkAdjustment *v_adj;
+
+               v_adj = modest_scrollable_get_vadjustment (scrollable);
+               g_return_if_fail (v_adj);
+
+               v_pos = v_adj->value + v_adj->step_increment * vertical;
+               if (vertical > 0) {
+                       v_pos += v_adj->page_size;
+                       if (v_pos > v_adj->upper - v_adj->page_size) {
+                               v_pos = v_adj->upper - v_adj->page_size;
+                       } else if (v_pos < 0) {
+                               v_pos = 0;
+                       }
+               }
+       }
+
+       modest_scrollable_scroll_to (scrollable, h_pos, v_pos);
+}
+
+GType
+modest_movement_mode_get_type (void)
+{
+  static GType etype = 0;
+  if (etype == 0) {
+    static const GFlagsValue values[] = {
+           { MODEST_MOVEMENT_MODE_HORIZONTAL, "HILDON_MOVEMENT_MODE_HORIZONTAL", "horizontal" },
+           { MODEST_MOVEMENT_MODE_VERTICAL, "MODEST_MOVEMENT_MODE_VERTICAL", "vertical" },
+           { MODEST_MOVEMENT_MODE_BOTH, "MODEST_MOVEMENT_MODE_BOTH", "both" },
+           { 0, NULL, NULL }
+    };
+    etype = g_flags_register_static ("ModestMovementMode", values);
+  }
+  return etype;
+}