Commit ccb1f08e authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Require Pango 1.5.1 (for ellipsisation).

Thu Jul 22 01:05:16 2004  Matthias Clasen  <maclas@gmx.de>

	* configure.in: Require Pango 1.5.1 (for ellipsisation).

	* gtk/gtklabel.h:
	* gtk/gtklabel.c (gtk_label_class_init): Add a new :ellipsise
	property which controls ellipsisation of the label.  (#125250,
	Tim Van Wassenhove, patch by James M. Cape)

	* tests/testellipsise.c: Simple test for ellipsisation.
parent b23415ee
Thu Jul 22 01:05:16 2004 Matthias Clasen <maclas@gmx.de>
* configure.in: Require Pango 1.5.1 (for ellipsisation).
* gtk/gtklabel.h:
* gtk/gtklabel.c (gtk_label_class_init): Add a new :ellipsise
property which controls ellipsisation of the label. (#125250,
Tim Van Wassenhove, patch by James M. Cape)
* tests/testellipsise.c: Simple test for ellipsisation.
Wed Jul 21 22:46:27 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_new_text): Don't leak the
......
Thu Jul 22 01:05:16 2004 Matthias Clasen <maclas@gmx.de>
* configure.in: Require Pango 1.5.1 (for ellipsisation).
* gtk/gtklabel.h:
* gtk/gtklabel.c (gtk_label_class_init): Add a new :ellipsise
property which controls ellipsisation of the label. (#125250,
Tim Van Wassenhove, patch by James M. Cape)
* tests/testellipsise.c: Simple test for ellipsisation.
Wed Jul 21 22:46:27 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_new_text): Don't leak the
......
Thu Jul 22 01:05:16 2004 Matthias Clasen <maclas@gmx.de>
* configure.in: Require Pango 1.5.1 (for ellipsisation).
* gtk/gtklabel.h:
* gtk/gtklabel.c (gtk_label_class_init): Add a new :ellipsise
property which controls ellipsisation of the label. (#125250,
Tim Van Wassenhove, patch by James M. Cape)
* tests/testellipsise.c: Simple test for ellipsisation.
Wed Jul 21 22:46:27 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_new_text): Don't leak the
......
Thu Jul 22 01:05:16 2004 Matthias Clasen <maclas@gmx.de>
* configure.in: Require Pango 1.5.1 (for ellipsisation).
* gtk/gtklabel.h:
* gtk/gtklabel.c (gtk_label_class_init): Add a new :ellipsise
property which controls ellipsisation of the label. (#125250,
Tim Van Wassenhove, patch by James M. Cape)
* tests/testellipsise.c: Simple test for ellipsisation.
Wed Jul 21 22:46:27 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_new_text): Don't leak the
......
......@@ -30,7 +30,7 @@ m4_define([gtk_binary_version], [2.4.0])
# required versions of other packages
m4_define([glib_required_version], [2.4.0])
m4_define([pango_required_version], [1.4.0])
m4_define([pango_required_version], [1.5.1])
m4_define([atk_required_version], [1.0.1])
......
Thu Jul 22 01:04:14 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtk-sections.txt: Add new ellipsistation api.
Sun Jul 18 20:17:41 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* === released 2.5.0 ==
......
......@@ -1857,6 +1857,7 @@ gtk_label_set_markup
gtk_label_set_markup_with_mnemonic
gtk_label_set_pattern
gtk_label_set_justify
gtk_label_set_ellipsize
gtk_label_get
gtk_label_parse_uline
gtk_label_set_line_wrap
......@@ -1872,6 +1873,7 @@ gtk_label_set_selectable
gtk_label_set_text_with_mnemonic
gtk_label_get_attributes
gtk_label_get_justify
gtk_label_get_ellipsize
gtk_label_get_label
gtk_label_get_layout
gtk_label_get_line_wrap
......
......@@ -69,7 +69,8 @@ enum {
PROP_MNEMONIC_KEYVAL,
PROP_MNEMONIC_WIDGET,
PROP_CURSOR_POSITION,
PROP_SELECTION_BOUND
PROP_SELECTION_BOUND,
PROP_ELLIPSIZE
};
static guint signals[LAST_SIGNAL] = { 0 };
......@@ -384,6 +385,15 @@ gtk_label_class_init (GtkLabelClass *class)
0,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class,
PROP_ELLIPSIZE,
g_param_spec_enum ("ellipsize",
P_("Ellipsize"),
P_("The preferred place to ellipsize the string, if the label does not have enough room to display the entire string, if at all"),
PANGO_TYPE_ELLIPSIZE_MODE,
PANGO_ELLIPSIZE_NONE,
G_PARAM_READWRITE));
/*
* Key bindings
*/
......@@ -501,6 +511,9 @@ gtk_label_set_property (GObject *object,
case PROP_MNEMONIC_WIDGET:
gtk_label_set_mnemonic_widget (label, (GtkWidget*) g_value_get_object (value));
break;
case PROP_ELLIPSIZE:
gtk_label_set_ellipsize (label, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -566,6 +579,9 @@ gtk_label_get_property (GObject *object,
else
g_value_set_int (value, 0);
break;
case PROP_ELLIPSIZE:
g_value_set_enum (value, label->ellipsize);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -582,6 +598,7 @@ gtk_label_init (GtkLabel *label)
label->jtype = GTK_JUSTIFY_LEFT;
label->wrap = FALSE;
label->ellipsize = PANGO_ELLIPSIZE_NONE;
label->use_underline = FALSE;
label->use_markup = FALSE;
......@@ -1267,6 +1284,54 @@ gtk_label_get_justify (GtkLabel *label)
return label->jtype;
}
/**
* gtk_label_set_ellipsize:
* @label: a #GtkLabel
* @mode: a #PangoEllipsizeMode
*
* Sets the mode used to ellipsize (add an ellipsis: "...") to the text if there
* is not enough space to render the entire string.
*
* Since: 2.6
**/
void
gtk_label_set_ellipsize (GtkLabel *label,
PangoEllipsizeMode mode)
{
g_return_if_fail (GTK_IS_LABEL (label));
g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE && mode <= PANGO_ELLIPSIZE_END);
if ((PangoEllipsizeMode) label->ellipsize != mode)
{
label->ellipsize = mode;
/* No real need to be this drastic, but easier than duplicating the code */
gtk_label_clear_layout (label);
g_object_notify (G_OBJECT (label), "ellipsize");
gtk_widget_queue_resize (GTK_WIDGET (label));
}
}
/**
* gtk_label_get_ellipsize:
* @label: a #GtkLabel
*
* Returns the ellipsizing position of the label. See gtk_label_set_ellipsize().
*
* Return value: #PangoEllipsizeMode
*
* Since: 2.6
**/
PangoEllipsizeMode
gtk_label_get_ellipsize (GtkLabel *label)
{
g_return_val_if_fail (GTK_IS_LABEL (label), PANGO_ELLIPSIZE_NONE);
return label->ellipsize;
}
/**
* gtk_label_set_line_wrap:
* @label: a #GtkLabel
......@@ -1454,6 +1519,7 @@ gtk_label_ensure_layout (GtkLabel *label)
}
pango_layout_set_alignment (label->layout, align);
pango_layout_set_ellipsize (label->layout, label->ellipsize);
if (label->wrap)
{
......@@ -1563,13 +1629,31 @@ gtk_label_size_request (GtkWidget *widget,
height = label->misc.ypad * 2;
pango_layout_get_extents (label->layout, NULL, &logical_rect);
aux_info = _gtk_widget_get_aux_info (widget, FALSE);
if (label->wrap && aux_info && aux_info->width > 0)
width += aux_info->width;
else
width += PANGO_PIXELS (logical_rect.width);
if (label->ellipsize)
{
PangoContext *context;
PangoFontMetrics *metrics;
gint char_width;
/* The minimum size for ellipsized labels is ~ 3 chars */
context = pango_layout_get_context (label->layout);
metrics = pango_context_get_metrics (context, widget->style->font_desc, NULL);
char_width = pango_font_metrics_get_approximate_char_width (metrics);
pango_font_metrics_unref (metrics);
width += (PANGO_PIXELS (char_width) * 3);
}
else
{
if (label->wrap && aux_info && aux_info->width > 0)
width += aux_info->width;
else
width += PANGO_PIXELS (logical_rect.width);
}
height += PANGO_PIXELS (logical_rect.height);
requisition->width = width;
......@@ -1586,6 +1670,9 @@ gtk_label_size_allocate (GtkWidget *widget,
(* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
if (label->ellipsize)
pango_layout_set_width (label->layout, allocation->width * PANGO_SCALE);
if (label->select_info && label->select_info->window)
{
gdk_window_move_resize (label->select_info->window,
......@@ -1676,7 +1763,7 @@ get_layout_location (GtkLabel *label,
GtkMisc *misc;
GtkWidget *widget;
gfloat xalign;
gint x, y;
gint req_width, x, y;
misc = GTK_MISC (label);
widget = GTK_WIDGET (label);
......@@ -1686,16 +1773,27 @@ get_layout_location (GtkLabel *label,
else
xalign = 1.0 - misc->xalign;
if (label->ellipsize)
{
PangoRectangle ink_rect;
pango_layout_get_extents (label->layout, &ink_rect, NULL);
req_width = PANGO_PIXELS (ink_rect.width);
}
else
req_width = widget->requisition.width;
x = floor (widget->allocation.x + (gint)misc->xpad +
xalign * (widget->allocation.width - widget->requisition.width)
+ 0.5);
xalign * (widget->allocation.width - req_width)
+ 0.5);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
x = MAX (x, widget->allocation.x + misc->xpad);
else
x = MIN (x,
widget->allocation.x + widget->allocation.width -
widget->requisition.width - misc->xpad);
req_width - misc->xpad);
y = floor (widget->allocation.y + (gint)misc->ypad
+ MAX (((widget->allocation.height - widget->requisition.height) * misc->yalign)
......
......@@ -60,6 +60,7 @@ struct _GtkLabel
guint wrap : 1;
guint use_underline : 1;
guint use_markup : 1;
guint ellipsize : 3;
guint mnemonic_keyval;
......@@ -128,6 +129,9 @@ void gtk_label_set_text_with_mnemonic (GtkLabel *label,
void gtk_label_set_justify (GtkLabel *label,
GtkJustification jtype);
GtkJustification gtk_label_get_justify (GtkLabel *label);
void gtk_label_set_ellipsize (GtkLabel *label,
PangoEllipsizeMode mode);
PangoEllipsizeMode gtk_label_get_ellipsize (GtkLabel *label);
void gtk_label_set_pattern (GtkLabel *label,
const gchar *pattern);
void gtk_label_set_line_wrap (GtkLabel *label,
......
......@@ -32,6 +32,7 @@ noinst_PROGRAMS = \
testcombo \
testcombochange \
testdnd \
testellipsise \
testentrycompletion \
testfilechooser \
testgtk \
......@@ -69,6 +70,7 @@ testcalendar_DEPENDENCIES = $(TEST_DEPS)
testcombo_DEPENDENCIES = $(TEST_DEPS)
testcombochange_DEPENDENCIES = $(TEST_DEPS)
testdnd_DEPENDENCIES = $(TEST_DEPS)
testellipsise_DEPENDENCIES = $(TEST_DEPS)
testentrycompletion_DEPENDENCIES = $(TEST_DEPS)
testfilechooser_DEPENDENCIES = $(TEST_DEPS)
testgtk_DEPENDENCIES = $(TEST_DEPS)
......@@ -99,6 +101,7 @@ testcalendar_LDADD = $(LDADDS)
testcombo_LDADD = $(LDADDS)
testcombochange_LDADD = $(LDADDS)
testdnd_LDADD = $(LDADDS)
testellipsise_LDADD = $(LDADDS)
testentrycompletion_LDADD = $(LDADDS)
testfilechooser_LDADD = $(LDADDS)
testgtk_LDADD = $(LDADDS)
......
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include <gtk/gtk.h>
static void
combo_changed_cb (GtkWidget *combo,
gpointer data)
{
GtkWidget *label = GTK_WIDGET (data);
gint active;
active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
gtk_label_set_ellipsize (GTK_LABEL (label), (PangoEllipsizeMode)active);
}
int
main (int argc, char *argv[])
{
GtkWidget *window, *vbox, *hbox, *label, *combo;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
vbox = gtk_vbox_new (0, FALSE);
gtk_container_add (GTK_CONTAINER (window), vbox);
hbox = gtk_hbox_new (0, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
label = gtk_label_new ("This label may be ellipsized\nto make it fit.");
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
combo = gtk_combo_box_new_text ();
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "NONE");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "START");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "MIDDLE");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "END");
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
g_signal_connect (combo, "changed", G_CALLBACK (combo_changed_cb), label);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment