diff --git a/ChangeLog b/ChangeLog index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 04ba89c1aa..054850cdff 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +Sun Feb 24 14:15:45 2002 Owen Taylor + + * gtk/gtktextview.c (widget_to_buffer): Take border + width into account. + + * gtk/gtklabel.c (get_label_wrap_width): Don't use GdkFont + to compute wrap width ... GdkFont will pull in X11 core + fonts. + Sun Feb 24 00:06:58 2002 Owen Taylor * Released 1.3.15. diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 44e259fd43..5341d749f7 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -1324,6 +1324,51 @@ gtk_label_clear_layout (GtkLabel *label) } } +typedef struct _LabelWrapWidth LabelWrapWidth; +struct _LabelWrapWidth +{ + gint width; + PangoFontDescription *font_desc; +}; + +static void +label_wrap_width_free (gpointer data) +{ + LabelWrapWidth *wrap_width = data; + pango_font_description_free (wrap_width->font_desc); + g_free (wrap_width); +} + +static gint +get_label_wrap_width (GtkLabel *label) +{ + PangoLayout *layout; + GtkStyle *style = GTK_WIDGET (label)->style; + + LabelWrapWidth *wrap_width = g_object_get_data (G_OBJECT (style), "gtk-label-wrap-width"); + if (!wrap_width) + { + wrap_width = g_new0 (LabelWrapWidth, 1); + g_object_set_data_full (G_OBJECT (style), "gtk-label-wrap-width", + wrap_width, label_wrap_width_free); + } + + if (wrap_width->font_desc && pango_font_description_equal (wrap_width->font_desc, style->font_desc)) + return wrap_width->width; + + if (wrap_width->font_desc) + pango_font_description_free (wrap_width->font_desc); + + wrap_width->font_desc = pango_font_description_copy (style->font_desc); + + layout = gtk_widget_create_pango_layout (GTK_WIDGET (label), + "This long string gives a good enough length for any line to have."); + pango_layout_get_size (layout, &wrap_width->width, NULL); + g_object_unref (layout); + + return wrap_width->width; +} + static void gtk_label_ensure_layout (GtkLabel *label) { @@ -1378,6 +1423,8 @@ gtk_label_ensure_layout (GtkLabel *label) pango_layout_set_width (label->layout, aux_info->width * PANGO_SCALE); else { + gint wrap_width; + pango_layout_set_width (label->layout, -1); pango_layout_get_extents (label->layout, NULL, &logical_rect); @@ -1385,10 +1432,9 @@ gtk_label_ensure_layout (GtkLabel *label) /* Try to guess a reasonable maximum width */ longest_paragraph = width; - - width = MIN (width, - PANGO_SCALE * gdk_string_width (gtk_style_get_font (GTK_WIDGET (label)->style), - "This long string gives a good enough length for any line to have.")); + + wrap_width = get_label_wrap_width (label); + width = MIN (width, wrap_width); width = MIN (width, PANGO_SCALE * (gdk_screen_width () + 1) / 2); diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index c466304cef..9e9c164fce 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -6848,6 +6848,7 @@ widget_to_buffer (GtkTextView *text_view, gint focus_edge_width; gboolean interior_focus; gint focus_width; + gint border_width = GTK_CONTAINER (text_view)->border_width; gtk_widget_style_get (GTK_WIDGET (text_view), "interior_focus", &interior_focus, @@ -6861,14 +6862,14 @@ widget_to_buffer (GtkTextView *text_view, if (buffer_x) { - *buffer_x = widget_x - focus_edge_width + text_view->xoffset; + *buffer_x = widget_x - focus_edge_width - border_width + text_view->xoffset; if (text_view->left_window) *buffer_x -= text_view->left_window->allocation.width; } if (buffer_y) { - *buffer_y = widget_y - focus_edge_width + text_view->yoffset; + *buffer_y = widget_y - focus_edge_width - border_width + text_view->yoffset; if (text_view->top_window) *buffer_y -= text_view->top_window->allocation.height; }