diff options
author | Owen Taylor <otaylor@src.gnome.org> | 1998-11-06 22:05:02 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1998-11-06 22:05:02 +0000 |
commit | e2a521922085c8010028e227f61bba59ea6b8242 (patch) | |
tree | 2500d6aa6f63aab4b58c17546532ecce8fdcca37 /gtk/gtkvscale.c | |
parent | 3c0df19a588bd96f328bda975db8eb9fa7f79e81 (diff) | |
download | gtk+-e2a521922085c8010028e227f61bba59ea6b8242.tar.gz |
Merge from themes-2. See the ChangeLog for a somewhat detailed
history of the evolution of the changes involved. Most of this
is actually minor painting tweaks.
Diffstat (limited to 'gtk/gtkvscale.c')
-rw-r--r-- | gtk/gtkvscale.c | 193 |
1 files changed, 151 insertions, 42 deletions
diff --git a/gtk/gtkvscale.c b/gtk/gtkvscale.c index 5fecac3564..2bdc33c11f 100644 --- a/gtk/gtkvscale.c +++ b/gtk/gtkvscale.c @@ -38,13 +38,20 @@ static void gtk_vscale_pos_trough (GtkVScale *vscale, gint *y, gint *w, gint *h); +static void gtk_vscale_pos_background (GtkVScale *vscale, + gint *x, + gint *y, + gint *w, + gint *h); static void gtk_vscale_draw_slider (GtkRange *range); static void gtk_vscale_draw_value (GtkScale *scale); +static void gtk_vscale_draw (GtkWidget *widget, + GdkRectangle *area); static gint gtk_vscale_trough_keys (GtkRange *range, GdkEventKey *key, GtkScrollType *scroll, GtkTroughType *pos); - +static void gtk_vscale_clear_background (GtkRange *range); guint gtk_vscale_get_type (void) @@ -85,12 +92,14 @@ gtk_vscale_class_init (GtkVScaleClass *class) widget_class->realize = gtk_vscale_realize; widget_class->size_request = gtk_vscale_size_request; widget_class->size_allocate = gtk_vscale_size_allocate; + widget_class->draw = gtk_vscale_draw; range_class->slider_update = gtk_range_default_vslider_update; range_class->trough_click = gtk_range_default_vtrough_click; range_class->motion = gtk_range_default_vmotion; range_class->draw_slider = gtk_vscale_draw_slider; range_class->trough_keys = gtk_vscale_trough_keys; + range_class->clear_background = gtk_vscale_clear_background; scale_class->draw_value = gtk_vscale_draw_value; } @@ -98,6 +107,7 @@ gtk_vscale_class_init (GtkVScaleClass *class) static void gtk_vscale_init (GtkVScale *vscale) { + GTK_WIDGET_SET_FLAGS (vscale, GTK_NO_WINDOW); } GtkWidget* @@ -130,28 +140,26 @@ gtk_vscale_realize (GtkWidget *widget) GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); range = GTK_RANGE (widget); - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); + widget->window = gtk_widget_get_parent_window (widget); + gdk_window_ref (widget->window); gtk_vscale_pos_trough (GTK_VSCALE (widget), &x, &y, &w, &h); + attributes.x = x; attributes.y = y; attributes.width = w; attributes.height = h; - attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.event_mask = gtk_widget_get_events (widget) | + (GDK_EXPOSURE_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; range->trough = gdk_window_new (widget->window, &attributes, attributes_mask); @@ -164,11 +172,9 @@ gtk_vscale_realize (GtkWidget *widget) widget->style = gtk_style_attach (widget->style, widget->window); - gdk_window_set_user_data (widget->window, widget); gdk_window_set_user_data (range->trough, widget); gdk_window_set_user_data (range->slider, widget); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, range->trough, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->slider, GTK_STATE_NORMAL); @@ -179,6 +185,69 @@ gtk_vscale_realize (GtkWidget *widget) } static void +gtk_vscale_draw (GtkWidget *widget, + GdkRectangle *area) +{ + GtkRange *range; + GdkRectangle tmp_area; + GdkRectangle child_area; + gint x, y, width, height; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_RANGE (widget)); + g_return_if_fail (area != NULL); + + if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) + { + range = GTK_RANGE (widget); + + gtk_vscale_pos_background (GTK_VSCALE (widget), &x, &y, &width, &height); + + tmp_area.x = x; + tmp_area.y = y; + tmp_area.width = width; + tmp_area.height = height; + + if (gdk_rectangle_intersect (area, &tmp_area, &child_area)) + gtk_range_draw_background (range); + + gtk_vscale_pos_trough (GTK_VSCALE (widget), &x, &y, &width, &height); + + tmp_area.x = x; + tmp_area.y = y; + tmp_area.width = width; + tmp_area.height = height; + + if (gdk_rectangle_intersect (area, &tmp_area, &child_area)) + { + gtk_range_draw_trough (range); + gtk_range_draw_slider (range); + gtk_range_draw_step_forw (range); + gtk_range_draw_step_back (range); + } + } +} + +static void +gtk_vscale_clear_background (GtkRange *range) +{ + GtkWidget *widget; + GtkScale *scale; + gint x, y, width, height; + + g_return_if_fail (range != NULL); + g_return_if_fail (GTK_IS_SCALE (range)); + + widget = GTK_WIDGET (range); + scale = GTK_SCALE (range); + + gtk_vscale_pos_background (GTK_VSCALE (widget), &x, &y, &width, &height); + + gtk_widget_queue_clear_area (GTK_WIDGET (range), + x, y, width, height); +} + +static void gtk_vscale_size_request (GtkWidget *widget, GtkRequisition *requisition) { @@ -236,10 +305,6 @@ gtk_vscale_size_allocate (GtkWidget *widget, range = GTK_RANGE (widget); scale = GTK_SCALE (widget); - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); - gtk_vscale_pos_trough (GTK_VSCALE (widget), &x, &y, &width, &height); gdk_window_move_resize (range->trough, x, y, width, height); @@ -300,13 +365,60 @@ gtk_vscale_pos_trough (GtkVScale *vscale, } *y += 1; *h -= 2; + + *x += widget->allocation.x; + *y += widget->allocation.y; +} + +static void +gtk_vscale_pos_background (GtkVScale *vscale, + gint *x, + gint *y, + gint *w, + gint *h) +{ + GtkWidget *widget; + GtkScale *scale; + + gint tx, ty, twidth, theight; + + g_return_if_fail (vscale != NULL); + g_return_if_fail (GTK_IS_VSCALE (vscale)); + g_return_if_fail ((x != NULL) && (y != NULL) && (w != NULL) && (h != NULL)); + + gtk_vscale_pos_trough (vscale, &tx, &ty, &twidth, &theight); + + widget = GTK_WIDGET (vscale); + scale = GTK_SCALE (vscale); + + *x = widget->allocation.x; + *y = widget->allocation.y; + *w = widget->allocation.width; + *h = widget->allocation.height; + + switch (scale->value_pos) + { + case GTK_POS_LEFT: + *w -= twidth; + break; + case GTK_POS_RIGHT: + *x = tx; + *w -= twidth; + break; + case GTK_POS_TOP: + *h -= theight; + break; + case GTK_POS_BOTTOM: + *y = ty; + *h -= theight; + break; + } } static void gtk_vscale_draw_slider (GtkRange *range) { GtkStateType state_type; - gint width, height; g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_VSCALE (range)); @@ -319,16 +431,11 @@ gtk_vscale_draw_slider (GtkRange *range) else state_type = GTK_STATE_NORMAL; - gtk_style_set_background (GTK_WIDGET (range)->style, range->slider, state_type); - gdk_window_clear (range->slider); - - gdk_window_get_size (range->slider, &width, &height); - gtk_draw_hline (GTK_WIDGET (range)->style, range->slider, - state_type, 1, width - 2, height / 2); - - gtk_draw_shadow (GTK_WIDGET (range)->style, range->slider, - state_type, GTK_SHADOW_OUT, - 0, 0, -1, -1); + gtk_paint_slider(GTK_WIDGET (range)->style, range->slider, state_type, + GTK_SHADOW_OUT, + NULL, GTK_WIDGET (range), "vscale", + 0, 0, -1, -1, + GTK_ORIENTATION_VERTICAL); } } @@ -336,6 +443,7 @@ static void gtk_vscale_draw_value (GtkScale *scale) { GtkStateType state_type; + GtkWidget *widget; gchar buffer[32]; gint text_width; gint width, height; @@ -344,11 +452,10 @@ gtk_vscale_draw_value (GtkScale *scale) g_return_if_fail (scale != NULL); g_return_if_fail (GTK_IS_VSCALE (scale)); + widget = GTK_WIDGET (scale); + if (scale->draw_value) { - gdk_window_get_size (GTK_WIDGET (scale)->window, &width, &height); - gdk_window_clear_area (GTK_WIDGET (scale)->window, 1, 1, width - 3, height - 3); - sprintf (buffer, "%0.*f", GTK_RANGE (scale)->digits, GTK_RANGE (scale)->adjustment->value); text_width = gdk_string_measure (GTK_WIDGET (scale)->style->font, buffer); @@ -361,7 +468,7 @@ gtk_vscale_draw_value (GtkScale *scale) gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height); x -= SCALE_CLASS (scale)->value_spacing + text_width; - y += ((height - + y += widget->allocation.y + ((height - (GTK_WIDGET (scale)->style->font->ascent + GTK_WIDGET (scale)->style->font->descent)) / 2 + GTK_WIDGET (scale)->style->font->ascent); @@ -373,7 +480,7 @@ gtk_vscale_draw_value (GtkScale *scale) gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height); x += width + SCALE_CLASS (scale)->value_spacing; - y += ((height - + y += widget->allocation.y + ((height - (GTK_WIDGET (scale)->style->font->ascent + GTK_WIDGET (scale)->style->font->descent)) / 2 + GTK_WIDGET (scale)->style->font->ascent); @@ -400,9 +507,11 @@ gtk_vscale_draw_value (GtkScale *scale) if (!GTK_WIDGET_IS_SENSITIVE (scale)) state_type = GTK_STATE_INSENSITIVE; - gtk_draw_string (GTK_WIDGET (scale)->style, - GTK_WIDGET (scale)->window, - state_type, x, y, buffer); + gtk_paint_string (GTK_WIDGET (scale)->style, + GTK_WIDGET (scale)->window, + state_type, + NULL, GTK_WIDGET (scale), "vscale", + x, y, buffer); } } |