diff options
author | Matthias Clasen <maclas@gmx.de> | 2004-02-12 23:58:46 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-02-12 23:58:46 +0000 |
commit | f6a32cf0d13e4f7c2bb238cbf79e69243dafb93b (patch) | |
tree | c6b4a7e5fb387f5bc11bac0a7c838d3d37a53716 /gtk/gtkvscale.c | |
parent | 0c4c9f0d1c482740670368466a3aedabec833169 (diff) | |
download | gtk+-f6a32cf0d13e4f7c2bb238cbf79e69243dafb93b.tar.gz |
Fix for #104811, Padraig O'Briain:
Fri Feb 13 00:54:59 2004 Matthias Clasen <maclas@gmx.de>
Fix for #104811, Padraig O'Briain:
* gtk/gtkscale.h:
* gtk/gtkscale.c (_gtk_scale_clear_layout):
* gtk/gtkscale.c (gtk_scale_get_layout_offsets):
* gtk/gtkscale.c (gtk_scale_get_layout): New functions to determine the
text and its position from a GtkScale, to make it more accessible.
* gtk/gtkhscale.c (gtk_hscale_get_layout_offsets):
* gtk/gtkvscale.c (gtk_vscale_get_layout_offsets): Implementations of the
new GtkScale vfunc.
Diffstat (limited to 'gtk/gtkvscale.c')
-rw-r--r-- | gtk/gtkvscale.c | 131 |
1 files changed, 78 insertions, 53 deletions
diff --git a/gtk/gtkvscale.c b/gtk/gtkvscale.c index ae28fddfdc..86a4d93d41 100644 --- a/gtk/gtkvscale.c +++ b/gtk/gtkvscale.c @@ -39,6 +39,10 @@ static void gtk_vscale_init (GtkVScale *vscale); static gboolean gtk_vscale_expose (GtkWidget *widget, GdkEventExpose *event); +static void gtk_vscale_get_layout_offsets (GtkScale *scale, + gint *x, + gint *y); + GType gtk_vscale_get_type (void) { @@ -71,14 +75,18 @@ gtk_vscale_class_init (GtkVScaleClass *class) { GtkWidgetClass *widget_class; GtkRangeClass *range_class; + GtkScaleClass *scale_class; widget_class = GTK_WIDGET_CLASS (class); range_class = GTK_RANGE_CLASS (class); + scale_class = GTK_SCALE_CLASS (class); parent_class = g_type_class_peek_parent (class); range_class->slider_detail = "vscale"; + scale_class->get_layout_offsets = gtk_vscale_get_layout_offsets; + widget_class->expose_event = gtk_vscale_expose; } @@ -147,13 +155,9 @@ static gboolean gtk_vscale_expose (GtkWidget *widget, GdkEventExpose *event) { - GtkRange *range; - GtkVScale *vscale; GtkScale *scale; - range = GTK_RANGE (widget); scale = GTK_SCALE (widget); - vscale = GTK_VSCALE (widget); /* We need to chain up _first_ so the various geometry members of * GtkRange struct are updated. @@ -164,56 +168,12 @@ gtk_vscale_expose (GtkWidget *widget, if (scale->draw_value) { PangoLayout *layout; - PangoRectangle logical_rect; - gchar *txt; gint x, y; GtkStateType state_type; - gint value_spacing; - gtk_widget_style_get (widget, "value_spacing", &value_spacing, NULL); - - txt = _gtk_scale_format_value (scale, - GTK_RANGE (scale)->adjustment->value); - - layout = gtk_widget_create_pango_layout (widget, txt); - g_free (txt); - - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - switch (scale->value_pos) - { - case GTK_POS_LEFT: - x = range->range_rect.x - logical_rect.width - value_spacing; - y = range->slider_start + (range->slider_end - range->slider_start - logical_rect.height) / 2; - y = CLAMP (y, 0, widget->allocation.height - logical_rect.height); - break; - - case GTK_POS_RIGHT: - x = range->range_rect.x + range->range_rect.width + value_spacing; - y = range->slider_start + (range->slider_end - range->slider_start - logical_rect.height) / 2; - y = CLAMP (y, 0, widget->allocation.height - logical_rect.height); - break; - - case GTK_POS_TOP: - x = range->range_rect.x + (range->range_rect.width - logical_rect.width) / 2; - y = range->range_rect.y - logical_rect.height - value_spacing; - break; - - case GTK_POS_BOTTOM: - x = range->range_rect.x + (range->range_rect.width - logical_rect.width) / 2; - y = range->range_rect.y + range->range_rect.height + value_spacing; - break; - - default: - g_return_val_if_reached (FALSE); - x = 0; - y = 0; - break; - } - - x += widget->allocation.x; - y += widget->allocation.y; - + layout = gtk_scale_get_layout (widget); + gtk_scale_get_layout_offsets (widget, &x, &y); + state_type = GTK_STATE_NORMAL; if (!GTK_WIDGET_IS_SENSITIVE (scale)) state_type = GTK_STATE_INSENSITIVE; @@ -227,9 +187,74 @@ gtk_vscale_expose (GtkWidget *widget, "vscale", x, y, layout); - - g_object_unref (layout); } return FALSE; + +} + +static void +gtk_vscale_get_layout_offsets (GtkScale *scale, + gint *x, + gint *y) +{ + GtkWidget *widget; + GtkRange *range; + GtkScale *scale; + PangoLayout *layout; + PangoRectangle logical_rect; + gint value_spacing; + + widget = GTK_WIDGET (scale); + layout = gtk_scale_get_layout (scale); + + if (!layout) + { + *x = 0; + *y = 0; + + return; + } + + range = GTK_RANGE (widget); + scale = GTK_SCALE (widget); + + gtk_widget_style_get (widget, "value_spacing", &value_spacing, NULL); + + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); + + switch (scale->value_pos) + { + case GTK_POS_LEFT: + *x = range->range_rect.x - logical_rect.width - value_spacing; + *y = range->slider_start + (range->slider_end - range->slider_start - logical_rect.height) / 2; + *y = CLAMP (*y, 0, widget->allocation.height - logical_rect.height); + break; + + case GTK_POS_RIGHT: + *x = range->range_rect.x + range->range_rect.width + value_spacing; + *y = range->slider_start + (range->slider_end - range->slider_start - logical_rect.height) / 2; + *y = CLAMP (*y, 0, widget->allocation.height - logical_rect.height); + break; + + case GTK_POS_TOP: + *x = range->range_rect.x + (range->range_rect.width - logical_rect.width) / 2; + *y = range->range_rect.y - logical_rect.height - value_spacing; + break; + + case GTK_POS_BOTTOM: + *x = range->range_rect.x + (range->range_rect.width - logical_rect.width) / 2; + *y = range->range_rect.y + range->range_rect.height + value_spacing; + break; + + default: + g_return_val_if_reached (FALSE); + *x = 0; + *y = 0; + break; + } + + *x += widget->allocation.x; + *y += widget->allocation.y; } + |