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

Add test cases for alignment.

2006-03-14  Matthias Clasen  <mclasen@redhat.com>

	* tests/testcellrenderertext.c: Add test cases for alignment.

	* gtk/gtkcellrenderertext.c: Add an alignment property,
	and fix some cases where ellipsize_set was being used to
	mean "we're ellipsizing" even when ellipsize was set to NONE.
	(#318761, Ross Burton)
parent 98569f6e
2006-03-14 Matthias Clasen <mclasen@redhat.com>
* tests/testcellrenderertext.c: Add test cases for alignment.
* gtk/gtkcellrenderertext.c: Add an alignment property,
and fix some cases where ellipsize_set was being used to
mean "we're ellipsizing" even when ellipsize was set to NONE.
(#318761, Ross Burton)
* gtk/gtkimcontextsimple.c: Make return and release work again
to commit a hex sequence. Additionally, make escape reset the
im context when in a hex sequence. (#334423, Behdad Esfahbod)
......
2006-03-14 Matthias Clasen <mclasen@redhat.com>
* tests/testcellrenderertext.c: Add test cases for alignment.
* gtk/gtkcellrenderertext.c: Add an alignment property,
and fix some cases where ellipsize_set was being used to
mean "we're ellipsizing" even when ellipsize was set to NONE.
(#318761, Ross Burton)
* gtk/gtkimcontextsimple.c: Make return and release work again
to commit a hex sequence. Additionally, make escape reset the
im context when in a hex sequence. (#334423, Behdad Esfahbod)
......
......@@ -77,6 +77,7 @@ enum {
PROP_SINGLE_PARAGRAPH_MODE,
PROP_WIDTH_CHARS,
PROP_WRAP_WIDTH,
PROP_ALIGN,
/* Style args */
PROP_BACKGROUND,
......@@ -138,6 +139,7 @@ struct _GtkCellRendererTextPrivate
PangoLanguage *language;
PangoEllipsizeMode ellipsize;
PangoWrapMode wrap_mode;
PangoAlignment align;
gulong populate_popup_id;
gulong entry_menu_popdown_timeout;
......@@ -194,6 +196,7 @@ gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
priv->width_chars = -1;
priv->wrap_width = -1;
priv->align = PANGO_ALIGN_LEFT;
}
static void
......@@ -498,6 +501,21 @@ gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
-1,
GTK_PARAM_READWRITE));
/**
* GtkCellRendererText:alignment:
*
* Specifies how to align the lines of text.
*
* Since: 2.10
*/
g_object_class_install_property (object_class,
PROP_ALIGN,
g_param_spec_enum ("alignment",
P_("Alignment"),
P_("How to align the lines"),
PANGO_TYPE_ALIGNMENT,
PANGO_ALIGN_LEFT,
GTK_PARAM_READWRITE));
/* Style props are set or not */
......@@ -749,6 +767,10 @@ gtk_cell_renderer_text_get_property (GObject *object,
g_value_set_int (value, priv->wrap_width);
break;
case PROP_ALIGN:
g_value_set_enum (value, priv->align);
break;
case PROP_BACKGROUND_SET:
g_value_set_boolean (value, celltext->background_set);
break;
......@@ -1249,6 +1271,10 @@ gtk_cell_renderer_text_set_property (GObject *object,
priv->width_chars = g_value_get_int (value);
break;
case PROP_ALIGN:
priv->align = g_value_get_enum (value);
break;
case PROP_BACKGROUND_SET:
celltext->background_set = g_value_get_boolean (value);
break;
......@@ -1446,6 +1472,8 @@ get_layout (GtkCellRendererText *celltext,
pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
}
pango_layout_set_alignment (layout, priv->align);
pango_layout_set_attributes (layout, attr_list);
pango_attr_list_unref (attr_list);
......@@ -1550,7 +1578,7 @@ get_size (GtkCellRenderer *cell,
else
*x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
if (priv->ellipsize_set || priv->wrap_width != -1)
if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
*x_offset = MAX(*x_offset, 0);
}
if (y_offset)
......@@ -1644,7 +1672,7 @@ gtk_cell_renderer_text_render (GtkCellRenderer *cell,
cairo_destroy (cr);
}
if (priv->ellipsize_set)
if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
pango_layout_set_width (layout,
(cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
else if (priv->wrap_width == -1)
......
......@@ -23,9 +23,9 @@
#include <gtk/gtk.h>
#define COL_BACKGROUND 14
#define COL_LINE_NUM 15
#define NUM_COLS 16 /* change this when adding columns */
#define COL_BACKGROUND 15
#define COL_LINE_NUM 16
#define NUM_COLS 17 /* change this when adding columns */
struct cell_params {
char *description; /* 0 */
......@@ -42,8 +42,9 @@ struct cell_params {
PangoWrapMode wrap_mode; /* 11 */
gboolean single_paragraph_mode; /* 12 */
PangoEllipsizeMode ellipsize; /* 13 */
/* COL_BACKGROUND */ /* 14 */
/* COL_LINE_NUM */ /* 15 */
PangoAlignment alignment; /* 14 */
/* COL_BACKGROUND */ /* 15 */
/* COL_LINE_NUM */ /* 16 */
};
#define WO PANGO_WRAP_WORD
......@@ -55,6 +56,9 @@ struct cell_params {
#define MI PANGO_ELLIPSIZE_MIDDLE
#define EN PANGO_ELLIPSIZE_END
#define AL PANGO_ALIGN_LEFT
#define AC PANGO_ALIGN_CENTER
#define AR PANGO_ALIGN_RIGHT
#define TESTL "LEFT JUSTIFIED This is really truly verily some very long text\n\330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205 \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205"
......@@ -73,29 +77,32 @@ static const struct cell_params cell_params[] = {
/* Test alignment */
{ "0 0 0 0 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 1 */
{ "0 0 .5 0 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 2 */
{ "0 0 1 0 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 3 */
{ "0 0 0 .5 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 4 */
{ "0 0 .5 .5 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 5 */
{ "0 0 1 .5 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 6 */
{ "0 0 0 1 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 7 */
{ "0 0 .5 1 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 8 */
{ "0 0 1 1 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 9 */
{ "0 0 0 0 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 1 */
{ "0 0 .5 0 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 2 */
{ "0 0 1 0 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 3 */
{ "0 0 0 .5 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 4 */
{ "0 0 .5 .5 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 5 */
{ "0 0 1 .5 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 6 */
{ "0 0 0 1 T -1 -1 -1 -1 CH F NO", TESTL, 0, 0, 0.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 7 */
{ "0 0 .5 1 T -1 -1 -1 -1 CH F NO", TESTC, 0, 0, 0.5, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 8 */
{ "0 0 1 1 T -1 -1 -1 -1 CH F NO", TESTR, 0, 0, 1.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 9 */
/* Test padding */
{ "10 10 0 0 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 10 */
{ "10 10 .5 0 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 11 */
{ "10 10 1 0 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 12 */
{ "10 10 0 .5 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 13 */
{ "10 10 .5 .5 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 14 */
{ "10 10 1 .5 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 15 */
{ "10 10 0 1 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 16 */
{ "10 10 .5 1 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 17 */
{ "10 10 1 1 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO }, /* 18 */
{ "10 10 0 0 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 10 */
{ "10 10 .5 0 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 11 */
{ "10 10 1 0 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 0.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 12 */
{ "10 10 0 .5 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 13 */
{ "10 10 .5 .5 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 14 */
{ "10 10 1 .5 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 0.5, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 15 */
{ "10 10 0 1 T -1 -1 -1 -1 CH F NO", TESTL, 10, 10, 0.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 16 */
{ "10 10 .5 1 T -1 -1 -1 -1 CH F NO", TESTC, 10, 10, 0.5, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 17 */
{ "10 10 1 1 T -1 -1 -1 -1 CH F NO", TESTR, 10, 10, 1.0, 1.0, TRUE, -1, -1, -1, -1, CH, FALSE, NO , AL }, /* 18 */
/* Test Pango alignment (not xalign) */
{ "0 0 0 0 T -1 -1 -1 -1 CH F NO AL", TESTL, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, 20, WO, FALSE, NO , AL }, /* 19 */
{ "0 0 0 0 T -1 -1 -1 -1 CH F NO AC", TESTC, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, 20, WO, FALSE, NO , AC }, /* 20 */
{ "0 0 0 0 T -1 -1 -1 -1 CH F NO AR", TESTR, 0, 0, 0.0, 0.0, TRUE, -1, -1, -1, 20, WO, FALSE, NO , AR }, /* 21 */
};
static GtkListStore *
......@@ -119,8 +126,9 @@ create_list_store (void)
PANGO_TYPE_WRAP_MODE, /* 11 */
G_TYPE_BOOLEAN, /* 12 */
PANGO_TYPE_ELLIPSIZE_MODE, /* 13 */
G_TYPE_STRING, /* 14 */
G_TYPE_STRING); /* 15 */
PANGO_TYPE_ALIGNMENT, /* 14 */
G_TYPE_STRING, /* 15 */
G_TYPE_STRING); /* 16 */
for (i = 0; i < G_N_ELEMENTS (cell_params); i++)
{
......@@ -148,8 +156,9 @@ create_list_store (void)
11, p->wrap_mode,
12, p->single_paragraph_mode,
13, p->ellipsize,
14, (i % 2 == 0) ? "gray50" : "gray80",
15, buf,
14, p->alignment,
15, (i % 2 == 0) ? "gray50" : "gray80",
16, buf,
-1);
}
......@@ -215,7 +224,8 @@ create_tree (gboolean rtl)
"wrap_mode", 11,
"single_paragraph_mode", 12,
"ellipsize", 13,
"cell_background", 14,
"alignment", 14,
"cell_background", 15,
NULL);
gtk_tree_view_column_set_resizable (column, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
......
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