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/gtkhscale.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/gtkhscale.c')
-rw-r--r-- | gtk/gtkhscale.c | 132 |
1 files changed, 78 insertions, 54 deletions
diff --git a/gtk/gtkhscale.c b/gtk/gtkhscale.c index 13c6fd2a55..4ca302e4e6 100644 --- a/gtk/gtkhscale.c +++ b/gtk/gtkhscale.c @@ -37,6 +37,10 @@ static void gtk_hscale_init (GtkHScale *hscale); static gboolean gtk_hscale_expose (GtkWidget *widget, GdkEventExpose *event); +static void gtk_hscale_get_layout_offsets (GtkScale *scale, + gint *x, + gint *y); + GType gtk_hscale_get_type (void) { @@ -69,13 +73,17 @@ gtk_hscale_class_init (GtkHScaleClass *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 = "hscale"; + + scale_class->get_layout_offsets = gtk_hscale_get_layout_offsets; widget_class->expose_event = gtk_hscale_expose; } @@ -145,13 +153,9 @@ static gboolean gtk_hscale_expose (GtkWidget *widget, GdkEventExpose *event) { - GtkRange *range; - GtkHScale *hscale; GtkScale *scale; - range = GTK_RANGE (widget); scale = GTK_SCALE (widget); - hscale = GTK_HSCALE (widget); /* We need to chain up _first_ so the various geometry members of * GtkRange struct are updated. @@ -162,58 +166,12 @@ gtk_hscale_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 - value_spacing - logical_rect.width; - y = range->range_rect.y + (range->range_rect.height - logical_rect.height) / 2; - break; - - case GTK_POS_RIGHT: - x = range->range_rect.x + range->range_rect.width + value_spacing; - y = range->range_rect.y + (range->range_rect.height - logical_rect.height) / 2; - break; - - case GTK_POS_TOP: - x = range->slider_start + - (range->slider_end - range->slider_start - logical_rect.width) / 2; - x = CLAMP (x, 0, widget->allocation.width - logical_rect.width); - y = range->range_rect.y - logical_rect.height - value_spacing; - break; - - case GTK_POS_BOTTOM: - x = range->slider_start + - (range->slider_end - range->slider_start - logical_rect.width) / 2; - x = CLAMP (x, 0, widget->allocation.width - logical_rect.width); - 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 (scale); + gtk_scale_get_layout_offsets (scale, &x, &y); + state_type = GTK_STATE_NORMAL; if (!GTK_WIDGET_IS_SENSITIVE (scale)) state_type = GTK_STATE_INSENSITIVE; @@ -228,8 +186,74 @@ gtk_hscale_expose (GtkWidget *widget, x, y, layout); - g_object_unref (layout); } return FALSE; } + +static void +gtk_hscale_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; + } + + gtk_widget_style_get (widget, "value_spacing", &value_spacing, NULL); + + range = GTK_RANGE (widget); + scale = GTK_SCALE (widget); + + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); + + switch (scale->value_pos) + { + case GTK_POS_LEFT: + *x = range->range_rect.x - value_spacing - logical_rect.width; + *y = range->range_rect.y + (range->range_rect.height - logical_rect.height) / 2; + break; + + case GTK_POS_RIGHT: + *x = range->range_rect.x + range->range_rect.width + value_spacing; + *y = range->range_rect.y + (range->range_rect.height - logical_rect.height) / 2; + break; + + case GTK_POS_TOP: + *x = range->slider_start + + (range->slider_end - range->slider_start - logical_rect.width) / 2; + *x = CLAMP (*x, 0, widget->allocation.width - logical_rect.width); + *y = range->range_rect.y - logical_rect.height - value_spacing; + break; + + case GTK_POS_BOTTOM: + *x = range->slider_start + + (range->slider_end - range->slider_start - logical_rect.width) / 2; + *x = CLAMP (*x, 0, widget->allocation.width - logical_rect.width); + *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; +} |