2009-03-16 Claudio Saavedra <csaavedra@igalia.com>
[hildon] / src / hildon-controlbar.c
index 60d808b..15b8e00 100644 (file)
@@ -1,14 +1,14 @@
 /*
- * This file is part of hildon-libs
+ * This file is a part of hildon
  *
  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
  *
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
  * as published by the Free Software Foundation; version 2.1 of
- * the License.
+ * the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 /**
  * SECTION:hildon-controlbar
  * @short_description: A widget that allows increasing or decreasing
- * a value within a pre-defined range
+ * a value within a pre-defined range.
  *
  * #HildonControlbar is a horizontally positioned range widget that is
  * visually divided into blocks and supports setting a minimum and
  * maximum value for the range.
+ * 
+ * <example>
+ * <title>HildonControlbar example</title>
+ * <programlisting>
+ * GtkWidget *cbar = hildon_controlbar_new();
+ * hildon_controlbar_set_max (HILDON_CONTROLBAR (cbar), 12);
+ * hildon_controlbar_set_value (HILDON_CONTROLBAR (cbar), 6);
+ * </programlisting>
+ * </example>
+ * 
  */
 
+#undef                                          HILDON_DISABLE_DEPRECATED
+
 #ifdef                                          HAVE_CONFIG_H
 #include                                        <config.h>
 #endif
 
-#include                                        "hildon-controlbar.h"
 #include                                        <math.h>
+#include                                        <libintl.h>
 #include                                        <gdk/gdk.h>
 #include                                        <gdk/gdkkeysyms.h>
-#include                                        <gtk/gtk.h>
-#include                                        <libintl.h>
+
+#include                                        "hildon-controlbar.h"
 #include                                        "hildon-controlbar-private.h"
 
 #define                                         _(string)\
-                                                dgettext(PACKAGE, string)
+                                                dgettext("hildon-libs", string)
 
 #define                                         DEFAULT_WIDTH 234
 
-#define                                         DEFAULT_HEIGHT 30
+#define                                         DEFAULT_HEIGHT 60
 
-#define                                         DEFAULT_BORDER_WIDTH 2
+#define                                         DEFAULT_BORDER_WIDTH 0
 
 #define                                         HILDON_CONTROLBAR_STEP_INCREMENT 1
 
@@ -139,6 +151,13 @@ hildon_controlbar_change_value                  (GtkRange *range,
                                                  gdouble new_value, 
                                                  gpointer data);
 
+/**
+ * hildon_controlbar_get_type:
+ *
+ * Initializes and returns the type of a hildon control bar.
+ *
+ * Returns: GType of #HildonControlbar
+ */
 GType G_GNUC_CONST
 hildon_controlbar_get_type                      (void)
 {
@@ -213,7 +232,7 @@ hildon_controlbar_class_init                    (HildonControlbarClass *controlb
     /**
      * HildonControlbar:value:
      *
-     * Controlbar value.
+     * Controlbar current value.
      */
     g_object_class_install_property (gobject_class, PROP_VALUE,
             g_param_spec_int ("value",
@@ -256,8 +275,6 @@ hildon_controlbar_init                          (HildonControlbar *controlbar)
     priv->old_value = 0;
     range = GTK_RANGE (controlbar);
 
-    range->has_stepper_a = TRUE;
-    range->has_stepper_d = TRUE;
     range->round_digits = -1;
 
     gtk_widget_set_size_request (GTK_WIDGET (controlbar), 
@@ -265,7 +282,7 @@ hildon_controlbar_init                          (HildonControlbar *controlbar)
             DEFAULT_HEIGHT);
 
     g_signal_connect (range, "change-value",
-            G_CALLBACK (hildon_controlbar_change_value), NULL );
+            G_CALLBACK (hildon_controlbar_change_value), NULL);
 }
 
 static GObject*
@@ -413,7 +430,7 @@ hildon_controlbar_size_request                  (GtkWidget *self,
  * @self: pointer to #HildonControlbar
  * @value: value in range of >= 0 && < G_MAX_INT
  *
- * Change the current value of the control bar to the specified value.
+ * Set the current value of the control bar to the specified value.
  */
 void 
 hildon_controlbar_set_value                     (HildonControlbar * self, 
@@ -576,7 +593,7 @@ hildon_controlbar_get_min                       (HildonControlbar *self)
  * Event handler for button press
  * Need to change button1 to button2 before passing this event to
  * parent handler. (see specs)
- * Also updates button_press variable so that we can draw hilites
+ * Also updates button_press variable so that we can draw highlights
  * correctly
  */
 static gint 
@@ -631,6 +648,8 @@ hildon_controlbar_change_value                  (GtkRange *range,
 {
     HildonControlbarPrivate *priv;
     GtkAdjustment *adj = range->adjustment;
+    gdouble vv = adj->upper - adj->lower;
+    gint calc = ((new_value - adj->lower) / vv) * (vv + 1.0) + adj->lower;
 
     priv = HILDON_CONTROLBAR_GET_PRIVATE(range);
     g_assert (priv);
@@ -655,7 +674,10 @@ hildon_controlbar_change_value                  (GtkRange *range,
         default:
             break;
     }
-    return FALSE;
+
+    GTK_RANGE_CLASS (parent_class)->change_value (range, scroll, calc);
+
+    return TRUE;
 }
 
 /*
@@ -779,13 +801,12 @@ hildon_controlbar_paint                         (HildonControlbar *self,
             "stepper-spacing", &stepper_spacing,
             "inner_border_width", &inner_border_width, NULL);
 
-    g_object_get (G_OBJECT (self), "minimum_visible_bars", &block_min, NULL);
-
     block_area = (w - 2 * stepper_size - 2 * stepper_spacing - 2 * inner_border_width);
 
     if (block_area <= 0)
         return;
 
+    block_min = 1;
     block_max = ctrlbar->upper - ctrlbar->lower + block_min; 
     block_act = priv->old_value - GTK_RANGE (self)->adjustment->lower + block_min;
 
@@ -827,6 +848,8 @@ hildon_controlbar_paint                         (HildonControlbar *self,
 
     block_count = ctrlbar->value - ctrlbar->lower +  block_min;
 
+    if (block_count == 0)
+            block_count = 1;
     /* Without this there is vertical block corruption when block_height = 
        1. This should work from 0 up to whatever */