1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2001 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkvscale.h"
35 #define VALUE_SPACING 2
37 static gboolean gtk_vscale_expose (GtkWidget *widget,
38 GdkEventExpose *event);
40 static void gtk_vscale_get_layout_offsets (GtkScale *scale,
44 G_DEFINE_TYPE (GtkVScale, gtk_vscale, GTK_TYPE_SCALE)
47 gtk_vscale_class_init (GtkVScaleClass *class)
49 GtkWidgetClass *widget_class;
50 GtkRangeClass *range_class;
51 GtkScaleClass *scale_class;
53 widget_class = GTK_WIDGET_CLASS (class);
54 range_class = GTK_RANGE_CLASS (class);
55 scale_class = GTK_SCALE_CLASS (class);
57 range_class->slider_detail = "vscale";
59 scale_class->get_layout_offsets = gtk_vscale_get_layout_offsets;
61 widget_class->expose_event = gtk_vscale_expose;
65 gtk_vscale_init (GtkVScale *vscale)
69 range = GTK_RANGE (vscale);
71 range->orientation = GTK_ORIENTATION_VERTICAL;
75 gtk_vscale_new (GtkAdjustment *adjustment)
77 return g_object_new (GTK_TYPE_VSCALE, "adjustment", adjustment, NULL);
82 * gtk_vscale_new_with_range:
85 * @step: step increment (tick size) used with keyboard shortcuts
87 * Creates a new vertical scale widget that lets the user input a
88 * number between @min and @max (including @min and @max) with the
89 * increment @step. @step must be nonzero; it's the distance the
90 * slider moves when using the arrow keys to adjust the scale value.
92 * Note that the way in which the precision is derived works best if @step
93 * is a power of ten. If the resulting precision is not suitable for your
94 * needs, use gtk_scale_set_digits() to correct it.
96 * Return value: a new #GtkVScale
99 gtk_vscale_new_with_range (gdouble min,
107 g_return_val_if_fail (min < max, NULL);
108 g_return_val_if_fail (step != 0.0, NULL);
110 adj = gtk_adjustment_new (min, min, max, step, 10 * step, 0);
112 if (fabs (step) >= 1.0 || step == 0.0)
115 digits = abs ((gint) floor (log10 (fabs (step))));
120 scale = g_object_new (GTK_TYPE_VSCALE,
125 return GTK_WIDGET (scale);
129 gtk_vscale_expose (GtkWidget *widget,
130 GdkEventExpose *event)
134 scale = GTK_SCALE (widget);
136 /* We need to chain up _first_ so the various geometry members of
137 * GtkRange struct are updated.
139 if (GTK_WIDGET_CLASS (gtk_vscale_parent_class)->expose_event)
140 GTK_WIDGET_CLASS (gtk_vscale_parent_class)->expose_event (widget, event);
142 if (scale->draw_value)
146 GtkStateType state_type;
148 layout = gtk_scale_get_layout (scale);
149 gtk_scale_get_layout_offsets (scale, &x, &y);
151 state_type = GTK_STATE_NORMAL;
152 if (!GTK_WIDGET_IS_SENSITIVE (scale))
153 state_type = GTK_STATE_INSENSITIVE;
155 gtk_paint_layout (widget->style,
171 gtk_vscale_get_layout_offsets (GtkScale *scale,
178 PangoRectangle logical_rect;
181 widget = GTK_WIDGET (scale);
182 layout = gtk_scale_get_layout (scale);
192 range = GTK_RANGE (widget);
193 scale = GTK_SCALE (widget);
195 gtk_widget_style_get (widget, "value-spacing", &value_spacing, NULL);
197 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
199 switch (scale->value_pos)
202 *x = range->range_rect.x - logical_rect.width - value_spacing;
203 *y = range->slider_start + (range->slider_end - range->slider_start - logical_rect.height) / 2;
204 *y = CLAMP (*y, 0, widget->allocation.height - logical_rect.height);
208 *x = range->range_rect.x + range->range_rect.width + value_spacing;
209 *y = range->slider_start + (range->slider_end - range->slider_start - logical_rect.height) / 2;
210 *y = CLAMP (*y, 0, widget->allocation.height - logical_rect.height);
214 *x = range->range_rect.x + (range->range_rect.width - logical_rect.width) / 2;
215 *y = range->range_rect.y - logical_rect.height - value_spacing;
219 *x = range->range_rect.x + (range->range_rect.width - logical_rect.width) / 2;
220 *y = range->range_rect.y + range->range_rect.height + value_spacing;
224 g_return_if_reached ();
227 *x += widget->allocation.x;
228 *y += widget->allocation.y;
231 #define __GTK_VSCALE_C__
232 #include "gtkaliasdef.c"