]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkscale.c
a11y: Emit text-changed signals directly
[~andy/gtk] / gtk / gtkscale.c
index 70522a6067178e51f41834a6d8a3e0b38920609c..1af2f538b09dd56a047bb6f1738d476326087c67 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
 #include <stdlib.h>
 
 #include "gtkscaleprivate.h"
+
+#include "gtkadjustment.h"
+#include "gtkbindings.h"
+#include "gtkbuildable.h"
+#include "gtkbuilderprivate.h"
 #include "gtkiconfactory.h"
 #include "gtkicontheme.h"
+#include "gtkintl.h"
 #include "gtkmarshalers.h"
-#include "gtkbindings.h"
 #include "gtkorientable.h"
-#include "gtktypebuiltins.h"
 #include "gtkprivate.h"
-#include "gtkintl.h"
-#include "gtkbuildable.h"
-#include "gtkbuilderprivate.h"
+#include "gtktypebuiltins.h"
 
 #include "a11y/gtkscaleaccessible.h"
 
@@ -195,16 +195,47 @@ gtk_scale_notify (GObject    *object,
   else if (strcmp (pspec->name, "inverted") == 0)
     {
       GtkScale *scale = GTK_SCALE (object);
+      GtkScaleMark *mark;
+      GSList *m;
+      gint i, n;
+      gdouble *values;
 
       scale->priv->marks = g_slist_sort_with_data (scale->priv->marks,
                                                    compare_marks,
                                                    GINT_TO_POINTER (gtk_range_get_inverted (GTK_RANGE (scale))));
+
+      n = g_slist_length (scale->priv->marks);
+      values = g_new (gdouble, n);
+      for (m = scale->priv->marks, i = 0; m; m = m->next, i++)
+        {
+          mark = m->data;
+          values[i] = mark->value;
+        }
+
+      _gtk_range_set_stop_values (GTK_RANGE (scale), values, n);
+
+      g_free (values);
     }
 
   if (G_OBJECT_CLASS (gtk_scale_parent_class)->notify)
     G_OBJECT_CLASS (gtk_scale_parent_class)->notify (object, pspec);
 }
 
+static void
+gtk_scale_update_style (GtkScale *scale)
+{
+  gint slider_length;
+  GtkRange *range;
+
+  range = GTK_RANGE (scale);
+
+  gtk_widget_style_get (GTK_WIDGET (scale),
+                        "slider-length", &slider_length,
+                        NULL);
+
+  gtk_range_set_min_slider_size (range, slider_length);
+  _gtk_scale_clear_layout (scale);
+}
 
 #define add_slider_binding(binding_set, keyval, mask, scroll)              \
   gtk_binding_entry_add_signal (binding_set, keyval, mask,                 \
@@ -476,6 +507,7 @@ gtk_scale_init (GtkScale *scale)
 
   context = gtk_widget_get_style_context (GTK_WIDGET (scale));
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE);
+  gtk_scale_update_style (scale);
 }
 
 static void
@@ -1004,18 +1036,7 @@ gtk_scale_get_mark_label_size (GtkScale        *scale,
 static void
 gtk_scale_style_updated (GtkWidget *widget)
 {
-  gint slider_length;
-  GtkRange *range;
-
-  range = GTK_RANGE (widget);
-  
-  gtk_widget_style_get (widget,
-                        "slider-length", &slider_length,
-                        NULL);
-
-  gtk_range_set_min_slider_size (range, slider_length);
-
-  _gtk_scale_clear_layout (GTK_SCALE (widget));
+  gtk_scale_update_style (GTK_SCALE (widget));
 
   GTK_WIDGET_CLASS (gtk_scale_parent_class)->style_updated (widget);
 }
@@ -1141,23 +1162,9 @@ gtk_scale_draw (GtkWidget *widget,
       GSList *m;
       gint min_pos_before, min_pos_after;
       gint min_pos, max_pos;
-      gint n_marks;
 
       orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (range));
-      n_marks = _gtk_range_get_stop_positions (range, &marks);
-      /* We always draw the marks in increasing direction, so flip
-       * the stop positions to match the marks (which we flip in
-       * gtk_scale_notify)
-       */
-      if (gtk_range_get_inverted (range))
-        {
-          for (i = 0; i < n_marks / 2; i++)
-            {
-              x1 = marks[i];
-              marks[i] = marks[n_marks - 1 - i];
-              marks[n_marks - 1 - i] = x1;
-            }
-        }
+      _gtk_range_get_stop_positions (range, &marks);
 
       layout = gtk_widget_create_pango_layout (widget, NULL);
       gtk_range_get_range_rect (range, &range_rect);
@@ -1189,7 +1196,9 @@ gtk_scale_draw (GtkWidget *widget,
               gtk_style_context_save (context);
               gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
 
+              gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
               gtk_render_line (context, cr, x1, y1, x1, y2);
+              gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SEPARATOR);
 
               if (mark->markup)
                 {
@@ -1240,7 +1249,9 @@ gtk_scale_draw (GtkWidget *widget,
               gtk_style_context_save (context);
               gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
 
+              gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
               gtk_render_line (context, cr, x1, y1, x2, y1);
+              gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SEPARATOR);
 
               if (mark->markup)
                 {
@@ -1615,8 +1626,9 @@ gtk_scale_add_mark (GtkScale        *scale,
   else
     mark->position = GTK_POS_BOTTOM;
 
-  priv->marks = g_slist_insert_sorted (priv->marks, mark,
-                                       (GCompareFunc) compare_marks);
+  priv->marks = g_slist_insert_sorted_with_data (priv->marks, mark,
+                                                 compare_marks,
+                                                 GINT_TO_POINTER (gtk_range_get_inverted (GTK_RANGE (scale))));
 
 #define MARKS_ABOVE 1
 #define MARKS_BELOW 2