* 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"
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_scale_buildable_interface_init))
+static gint
+compare_marks (gconstpointer a, gconstpointer b, gpointer data)
+{
+ gboolean inverted = GPOINTER_TO_INT (data);
+ gint val;
+ const GtkScaleMark *ma, *mb;
+
+ val = inverted ? -1 : 1;
+
+ ma = a; mb = b;
+
+ return (ma->value > mb->value) ? val : ((ma->value < mb->value) ? -val : 0);
+}
+
+static void
+gtk_scale_notify (GObject *object,
+ GParamSpec *pspec)
+{
+ if (strcmp (pspec->name, "orientation") == 0)
+ {
+ GtkOrientation orientation;
+
+ orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (object));
+ gtk_range_set_flippable (GTK_RANGE (object),
+ orientation == GTK_ORIENTATION_HORIZONTAL);
+ }
+ 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, \
gobject_class->set_property = gtk_scale_set_property;
gobject_class->get_property = gtk_scale_get_property;
+ gobject_class->notify = gtk_scale_notify;
gobject_class->finalize = gtk_scale_finalize;
widget_class->style_updated = gtk_scale_style_updated;
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SCALE_ACCESSIBLE);
}
-static void
-gtk_scale_orientation_notify (GtkRange *range,
- const GParamSpec *pspec)
-{
- GtkOrientation orientation;
-
- orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (range));
- gtk_range_set_flippable (range,
- orientation == GTK_ORIENTATION_HORIZONTAL);
-}
-
static void
gtk_scale_init (GtkScale *scale)
{
priv->digits = 1;
gtk_range_set_round_digits (range, priv->digits);
- gtk_scale_orientation_notify (range, NULL);
- g_signal_connect (scale, "notify::orientation",
- G_CALLBACK (gtk_scale_orientation_notify),
- NULL);
+ gtk_range_set_flippable (range,
+ gtk_orientable_get_orientation (GTK_ORIENTABLE (range))== GTK_ORIENTATION_HORIZONTAL);
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
gtk_scale_set_has_origin (GtkScale *scale,
gboolean has_origin)
{
- GtkScalePrivate *priv;
-
g_return_if_fail (GTK_IS_SCALE (scale));
- priv = scale->priv;
-
has_origin = has_origin != FALSE;
if (_gtk_range_get_has_origin (GTK_RANGE (scale)) != has_origin)
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);
}
}
static gint
-find_next_pos (GtkWidget *widget,
+find_next_pos (GtkWidget *widget,
GSList *list,
gint *marks,
- GtkPositionType pos,
- gint match)
+ GtkPositionType pos)
{
GtkAllocation allocation;
GSList *m;
{
GtkScaleMark *mark = m->data;
- if (match == (mark->position == pos))
+ if (mark->position == pos)
return marks[i];
}
GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = scale->priv;
GtkRange *range = GTK_RANGE (scale);
- GtkStateFlags state = 0;
GtkStyleContext *context;
gint *marks;
gint focus_padding;
*/
GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr);
- if (!gtk_widget_is_sensitive (widget))
- state |= GTK_STATE_FLAG_INSENSITIVE;
-
if (priv->marks)
{
GtkOrientation orientation;
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (range));
_gtk_range_get_stop_positions (range, &marks);
+
layout = gtk_widget_create_pango_layout (widget, NULL);
gtk_range_get_range_rect (range, &range_rect);
y1 = range_rect.y;
y2 = y1 - slider_width / 2;
min_pos = min_pos_before;
- max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP, 1) - min_sep;
+ max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep;
}
else
{
y1 = range_rect.y + range_rect.height;
y2 = y1 + slider_width / 2;
min_pos = min_pos_after;
- max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM, 1) - min_sep;
+ max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep;
}
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
- gtk_style_context_set_state (context, state);
+ 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)
{
x1 = range_rect.x;
x2 = range_rect.x - slider_width / 2;
min_pos = min_pos_before;
- max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP, 1) - min_sep;
+ max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep;
}
else
{
x1 = range_rect.x + range_rect.width;
x2 = range_rect.x + range_rect.width + slider_width / 2;
min_pos = min_pos_after;
- max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM, 1) - min_sep;
+ max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep;
}
y1 = marks[i];
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_MARK);
- gtk_style_context_set_state (context, state);
+ 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)
{
}
static void
-gtk_scale_mark_free (GtkScaleMark *mark)
+gtk_scale_mark_free (gpointer data)
{
+ GtkScaleMark *mark = data;
+
g_free (mark->markup);
g_free (mark);
}
priv = scale->priv;
- g_slist_foreach (priv->marks, (GFunc)gtk_scale_mark_free, NULL);
- g_slist_free (priv->marks);
+ g_slist_free_full (priv->marks, gtk_scale_mark_free);
priv->marks = NULL;
context = gtk_widget_get_style_context (GTK_WIDGET (scale));
gtk_widget_queue_resize (GTK_WIDGET (scale));
}
-static gint
-compare_marks (gpointer a, gpointer b)
-{
- GtkScaleMark *ma, *mb;
-
- ma = a; mb = b;
-
- return (gint) (ma->value - mb->value);
-}
-
/**
* gtk_scale_add_mark:
* @scale: a #GtkScale
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