From 5f9c8f653daac7c7aa22fa6160771f7f899216bc Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 20 Feb 2012 11:28:36 +0100 Subject: [PATCH] entry: trim the progress bar area if the text area is resized When a subclass of GtkEntry (e.g. GtkSpinButton) resizes the available text area (by overriding the get_text_area_size vfunc), we need to ensure we don't draw a possible progressbar over the part that got removed from the text area. This fixes drawing a progressbar in GtkSpinButton and in its subclasses, such as GimpSpinScale, and makes Mitch happy too! --- gtk/gtkentry.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 801dd96da5..0694a75850 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3523,21 +3523,47 @@ get_progress_area (GtkWidget *widget, GtkEntry *entry = GTK_ENTRY (widget); GtkEntryPrivate *private = entry->priv; GtkStyleContext *context; - GtkBorder margin; + GtkBorder margin, border, entry_borders; + gint frame_width, text_area_width, text_area_height; + + context = gtk_widget_get_style_context (widget); + _gtk_entry_get_borders (entry, &entry_borders); + get_text_area_size (entry, + NULL, NULL, + &text_area_width, &text_area_height); + get_frame_size (entry, FALSE, + NULL, NULL, + &frame_width, NULL); - get_frame_size (GTK_ENTRY (widget), FALSE, NULL, NULL, width, height); *x = 0; *y = 0; + *width = text_area_width + entry_borders.left + entry_borders.right; + *height = text_area_height + entry_borders.top + entry_borders.bottom; if (!private->interior_focus) { *x -= private->focus_width; *y -= private->focus_width; - *width += 2 * private->focus_width; - *height += 2 * private->focus_width; } - context = gtk_widget_get_style_context (widget); + /* if the text area got resized by a subclass, subtract the left/right + * border width, so that the progress bar won't extend over the resized + * text area. + */ + if (frame_width > *width) + { + gtk_style_context_get_border (context, 0, &border); + if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL) + { + *x = (frame_width - *width) + border.left; + *width -= border.left; + } + else + { + *width -= border.right; + } + } + gtk_entry_prepare_context_for_progress (entry, context); gtk_style_context_get_margin (context, 0, &margin);