]> Pileus Git - ~andy/gtk/commitdiff
Avoid resizing GtkStatusbar if the text of the label changes (#90955, He
authorMatthias Clasen <mclasen@redhat.com>
Tue, 9 Nov 2004 05:04:41 +0000 (05:04 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 9 Nov 2004 05:04:41 +0000 (05:04 +0000)
2004-11-09  Matthias Clasen  <mclasen@redhat.com>

Avoid resizing GtkStatusbar if the text of the label
changes  (#90955, He Qiangqiang, fix proposed by
Owen Taylor, patch by Christian Persch)

* gtk/gtklabel.[hc]: Add a boolean single-line-mode property
which causes the label height not to depend on the actual
text, but only on the font.

* gtk/gtkstatusbar.c (gtk_statusbar_init): Turn on
single-line-mode for the label.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtklabel.c
gtk/gtklabel.h
gtk/gtkstatusbar.c

index be7317ba7a55cf5184138ead992944953b98779c..dc8b3771a877e00fdaa2cde027bd3ff359b0fa96 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-11-09  Matthias Clasen  <mclasen@redhat.com>
+
+       Avoid resizing GtkStatusbar if the text of the label 
+       changes  (#90955, He Qiangqiang, fix proposed by 
+       Owen Taylor, patch by Christian Persch)
+       
+       * gtk/gtklabel.[hc]: Add a boolean single-line-mode property 
+       which causes the label height not to depend on the actual
+       text, but only on the font.
+
+       * gtk/gtkstatusbar.c (gtk_statusbar_init): Turn on
+       single-line-mode for the label.
+
 2004-11-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkfilefilter.c (gtk_file_filter_filter): Use 
index be7317ba7a55cf5184138ead992944953b98779c..dc8b3771a877e00fdaa2cde027bd3ff359b0fa96 100644 (file)
@@ -1,3 +1,16 @@
+2004-11-09  Matthias Clasen  <mclasen@redhat.com>
+
+       Avoid resizing GtkStatusbar if the text of the label 
+       changes  (#90955, He Qiangqiang, fix proposed by 
+       Owen Taylor, patch by Christian Persch)
+       
+       * gtk/gtklabel.[hc]: Add a boolean single-line-mode property 
+       which causes the label height not to depend on the actual
+       text, but only on the font.
+
+       * gtk/gtkstatusbar.c (gtk_statusbar_init): Turn on
+       single-line-mode for the label.
+
 2004-11-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkfilefilter.c (gtk_file_filter_filter): Use 
index be7317ba7a55cf5184138ead992944953b98779c..dc8b3771a877e00fdaa2cde027bd3ff359b0fa96 100644 (file)
@@ -1,3 +1,16 @@
+2004-11-09  Matthias Clasen  <mclasen@redhat.com>
+
+       Avoid resizing GtkStatusbar if the text of the label 
+       changes  (#90955, He Qiangqiang, fix proposed by 
+       Owen Taylor, patch by Christian Persch)
+       
+       * gtk/gtklabel.[hc]: Add a boolean single-line-mode property 
+       which causes the label height not to depend on the actual
+       text, but only on the font.
+
+       * gtk/gtkstatusbar.c (gtk_statusbar_init): Turn on
+       single-line-mode for the label.
+
 2004-11-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkfilefilter.c (gtk_file_filter_filter): Use 
index be7317ba7a55cf5184138ead992944953b98779c..dc8b3771a877e00fdaa2cde027bd3ff359b0fa96 100644 (file)
@@ -1,3 +1,16 @@
+2004-11-09  Matthias Clasen  <mclasen@redhat.com>
+
+       Avoid resizing GtkStatusbar if the text of the label 
+       changes  (#90955, He Qiangqiang, fix proposed by 
+       Owen Taylor, patch by Christian Persch)
+       
+       * gtk/gtklabel.[hc]: Add a boolean single-line-mode property 
+       which causes the label height not to depend on the actual
+       text, but only on the font.
+
+       * gtk/gtkstatusbar.c (gtk_statusbar_init): Turn on
+       single-line-mode for the label.
+
 2004-11-08  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkfilefilter.c (gtk_file_filter_filter): Use 
index e3458eaaed645d7d40e480cf55e68c4892aba393..b0353d066801c681282cf404ab1eb6fbebc362b8 100644 (file)
@@ -1,3 +1,7 @@
+2004-11-09  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk-sections.txt: Add gtk_label_[gs]et_single_line_mode.
+
 2004-11-07  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtk-sections.txt: Add gtk_file_filter_add_pixbuf_formats.
index 27dfa12c678f2a460b82aa8b26978ae6077575ad..74d524dce881c7dbff84bf3627d125f0ef2f8347 100644 (file)
@@ -1932,9 +1932,11 @@ gtk_label_get_mnemonic_widget
 gtk_label_get_selection_bounds
 gtk_label_get_use_markup
 gtk_label_get_use_underline
+gtk_label_get_single_line_mode
 gtk_label_set_label
 gtk_label_set_use_markup
 gtk_label_set_use_underline
+gtk_label_set_single_line_mode
 <SUBSECTION Standard>
 GTK_LABEL
 GTK_IS_LABEL
index 066e29f2e1f2a3ef8e8da3d1350ce53247bef760..b02b3166f440cab8e1051f8efc8fa8767b7c1b15 100644 (file)
@@ -47,6 +47,7 @@
 typedef struct
 {
   gint width_chars;
+  guint single_line_mode : 1;
 }
 GtkLabelPrivate;
 
@@ -80,7 +81,8 @@ enum {
   PROP_CURSOR_POSITION,
   PROP_SELECTION_BOUND,
   PROP_ELLIPSIZE,
-  PROP_WIDTH_CHARS
+  PROP_WIDTH_CHARS,
+  PROP_SINGLE_LINE_MODE
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -420,7 +422,7 @@ gtk_label_class_init (GtkLabelClass *class)
    * GtkLabel:width-chars:
    * 
    * The desired width of the label, in characters. If this property is set to
-   * %-1, the width will be calculated automatically, otherwise the label will
+   * -1, the width will be calculated automatically, otherwise the label will
    * request either 3 characters or the property value, whichever is greater.
    * 
    * Since: 2.6
@@ -435,6 +437,24 @@ gtk_label_class_init (GtkLabelClass *class)
                                                      -1,
                                                      G_PARAM_READWRITE));
   
+  /**
+   * GtkLabel:single-line-mode:
+   * 
+   * Whether the label is in single line mode. In single line mode,
+   * the height of the label does not depend on the actual text, it
+   * is always set to ascent + descent of the font. This can be an
+   * advantage in situations where resizing the label because of text 
+   * changes would be distracting, e.g. in a statusbar.
+   *
+   * Since: 2.6
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_SINGLE_LINE_MODE,
+                                   g_param_spec_boolean ("single-line-mode",
+                                                        P_("Single Line Mode"),
+                                                        P_("Whether the label is in single line mode"),
+                                                        FALSE,
+                                                        G_PARAM_READWRITE));
   /*
    * Key bindings
    */
@@ -560,6 +580,9 @@ gtk_label_set_property (GObject      *object,
     case PROP_WIDTH_CHARS:
       gtk_label_set_width_chars (label, g_value_get_int (value));
       break;
+    case PROP_SINGLE_LINE_MODE:
+      gtk_label_set_single_line_mode (label, g_value_get_boolean (value));
+      break;     
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -631,6 +654,9 @@ gtk_label_get_property (GObject     *object,
     case PROP_WIDTH_CHARS:
       g_value_set_enum (value, gtk_label_get_width_chars (label));
       break;
+    case PROP_SINGLE_LINE_MODE:
+      g_value_set_boolean (value, gtk_label_get_single_line_mode (label));
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1605,6 +1631,7 @@ gtk_label_ensure_layout (GtkLabel *label)
   if (!label->layout)
     {
       PangoAlignment align = PANGO_ALIGN_LEFT; /* Quiet gcc */
+      GtkLabelPrivate *priv = GTK_LABEL_GET_PRIVATE (label);
 
       label->layout = gtk_widget_create_pango_layout (widget, label->text);
 
@@ -1633,6 +1660,7 @@ gtk_label_ensure_layout (GtkLabel *label)
 
       pango_layout_set_alignment (label->layout, align);
       pango_layout_set_ellipsize (label->layout, label->ellipsize);
+      pango_layout_set_single_paragraph_mode (label->layout, priv->single_line_mode);
 
       if (label->ellipsize)
        pango_layout_set_width (label->layout, 
@@ -1772,7 +1800,24 @@ gtk_label_size_request (GtkWidget      *widget,
        width += PANGO_PIXELS (logical_rect.width);
     }
 
-  height += PANGO_PIXELS (logical_rect.height);
+  if (priv->single_line_mode)
+    {
+      PangoContext *context;
+      PangoFontMetrics *metrics;
+      gint ascent, descent;
+
+      context = pango_layout_get_context (label->layout);
+      metrics = pango_context_get_metrics (context, widget->style->font_desc,
+                                           pango_context_get_language (context));
+
+      ascent = pango_font_metrics_get_ascent (metrics);
+      descent = pango_font_metrics_get_descent (metrics);
+      pango_font_metrics_unref (metrics);
+    
+      height += PANGO_PIXELS (ascent + descent);
+    }
+  else
+    height += PANGO_PIXELS (logical_rect.height);
 
   requisition->width = width;
   requisition->height = height;
@@ -3034,6 +3079,59 @@ gtk_label_get_use_underline (GtkLabel *label)
   return label->use_underline;
 }
 
+/**
+ * gtk_label_set_single_line_mode:
+ * @label: a #GtkLabel
+ * @single_line_mode: %TRUE if the label should be in single line mode
+ *
+ * Sets whether the label is in single line mode.
+ *
+ * Since: 2.6
+ */
+void
+gtk_label_set_single_line_mode (GtkLabel *label,
+                                gboolean single_line_mode)
+{
+  GtkLabelPrivate *priv;
+
+  g_return_if_fail (GTK_IS_LABEL (label));
+
+  single_line_mode = single_line_mode != FALSE;
+
+  priv = GTK_LABEL_GET_PRIVATE (label);
+  if (priv->single_line_mode != single_line_mode)
+    {
+      priv->single_line_mode = single_line_mode;
+
+      gtk_label_clear_layout (label);
+      gtk_widget_queue_resize (GTK_WIDGET (label));
+
+      g_object_notify (G_OBJECT (label), "single-line-mode");
+    }
+}
+
+/**
+ * gtk_label_get_single_line_mode:
+ * @label: a #GtkLabel
+ *
+ * Returns whether the label is in single line mode.
+ *
+ * Return value: %TRUE when the label is in single line mode.
+ *
+ * Since: 2.6
+ **/
+gboolean
+gtk_label_get_single_line_mode  (GtkLabel *label)
+{
+  GtkLabelPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_LABEL (label), FALSE);
+
+  priv = GTK_LABEL_GET_PRIVATE (label);
+
+  return priv->single_line_mode;
+}
+
 /* Compute the X position for an offset that corresponds to the "more important
  * cursor position for that offset. We use this when trying to guess to which
  * end of the selection we should go to when the user hits the left or
index 9d71cd0b0a30d1f572b25edb681814ebc2d63a6b..5da9c47ef5ad15482e56bd8ac135bc796d5c0f59 100644 (file)
@@ -155,6 +155,9 @@ void         gtk_label_get_layout_offsets (GtkLabel *label,
                                            gint     *x,
                                            gint     *y);
 
+void         gtk_label_set_single_line_mode  (GtkLabel *label,
+                                              gboolean single_line_mode);
+gboolean     gtk_label_get_single_line_mode  (GtkLabel *label);
 
 #ifndef GTK_DISABLE_DEPRECATED
 
index 00d5a6b4b63d45e4b0bb2c5b57a6ddc0da650a4e..4f3ffc355703527689639c26fd37f52877f29f25 100644 (file)
@@ -226,6 +226,7 @@ gtk_statusbar_init (GtkStatusbar *statusbar)
   gtk_widget_show (statusbar->frame);
 
   statusbar->label = gtk_label_new ("");
+  gtk_label_set_single_line_mode (GTK_LABEL (statusbar->label), TRUE);
   gtk_misc_set_alignment (GTK_MISC (statusbar->label), 0.0, 0.5);
   /* don't expand the size request for the label; if we
    * do that then toplevels weirdly resize