42 const GdkRectangle *cell_area,
44 PangoEllipsizeMode ellipsize)
47 gint wrap_width, xpad;
48 PangoWrapMode wrap_mode;
49 PangoAlignment alignment;
52 "wrap-width", &wrap_width,
53 "wrap-mode", &wrap_mode,
54 "alignment", &alignment,
58 layout = pango_layout_new (gtk_widget_get_pango_context (widget));
60 pango_layout_set_ellipsize (layout, ellipsize);
61 pango_layout_set_alignment (layout, alignment);
65 pango_layout_set_width (layout, wrap_width * PANGO_SCALE);
66 pango_layout_set_wrap (layout, wrap_mode);
70 if (cell_area != NULL)
71 pango_layout_set_width (layout, (cell_area->width - 2 * xpad) * PANGO_SCALE);
73 pango_layout_set_width (layout, -1);
75 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
83 const GdkRectangle *cell_area,
85 PangoLayout **layout_one,
86 PangoLayout **layout_two)
88 PangoLayout *line_one;
89 PangoLayout *line_two = NULL;
97 self, PANGO_ELLIPSIZE_MIDDLE);
99 if (self->priv->line_two == NULL ||
100 g_strcmp0 (self->priv->line_two,
"") == 0)
102 pango_layout_set_height (line_one, - (self->priv->text_lines));
105 pango_layout_set_text (line_one, text, -1);
110 self, PANGO_ELLIPSIZE_END);
112 pango_layout_set_height (line_one, - (self->priv->text_lines - 1));
113 pango_layout_set_height (line_two, -1);
114 pango_layout_set_text (line_two, self->priv->line_two, -1);
117 pango_layout_set_text (line_one, text, -1);
121 *layout_one = line_one;
123 *layout_two = line_two;
131 PangoLayout *layout_1,
132 PangoLayout *layout_2,
135 const GdkRectangle *cell_area,
142 PangoLayout *layout_one, *layout_two;
143 GdkRectangle layout_one_rect, layout_two_rect, layout_union;
145 if (layout_1 == NULL)
151 layout_one = g_object_ref (layout_1);
153 if (layout_2 != NULL)
154 layout_two = g_object_ref (layout_2);
159 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
160 pango_layout_get_pixel_extents (layout_one, NULL, (PangoRectangle *) &layout_one_rect);
162 if (layout_two != NULL)
164 pango_layout_get_pixel_extents (layout_two, NULL, (PangoRectangle *) &layout_two_rect);
166 layout_union.width = MAX (layout_one_rect.width, layout_two_rect.width);
167 layout_union.height = layout_one_rect.height + layout_two_rect.height;
171 layout_union = layout_one_rect;
176 gfloat xalign, yalign;
178 gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
180 layout_union.width = MIN (layout_union.width, cell_area->width - 2 * xpad);
181 layout_union.height = MIN (layout_union.height, cell_area->height - 2 * ypad);
185 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
186 *x_offset_1 = (1.0 - xalign) * (cell_area->width - (layout_one_rect.width + (2 * xpad)));
188 *x_offset_1 = xalign * (cell_area->width - (layout_one_rect.width + (2 * xpad)));
190 *x_offset_1 = MAX (*x_offset_1, 0);
194 if (layout_two != NULL)
196 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
197 *x_offset_2 = (1.0 - xalign) * (cell_area->width - (layout_two_rect.width + (2 * xpad)));
199 *x_offset_2 = xalign * (cell_area->width - (layout_two_rect.width + (2 * xpad)));
201 *x_offset_2 = MAX (*x_offset_2, 0);
211 *y_offset = yalign * (cell_area->height - (layout_union.height + (2 * ypad)));
212 *y_offset = MAX (*y_offset, 0);
217 if (x_offset_1) *x_offset_1 = 0;
218 if (x_offset_2) *x_offset_2 = 0;
219 if (y_offset) *y_offset = 0;
222 g_clear_object (&layout_one);
223 g_clear_object (&layout_two);
226 *height = ypad * 2 + layout_union.height;
229 *width = xpad * 2 + layout_union.width;
236 const GdkRectangle *background_area,
237 const GdkRectangle *cell_area,
238 GtkCellRendererState flags)
241 GtkStyleContext *context;
242 gint line_one_height;
244 GdkRectangle area, render_area = *cell_area;
245 gint xpad, ypad, x_offset_1, x_offset_2, y_offset;
246 PangoLayout *layout_one, *layout_two;
247 PangoRectangle layout_rect;
250 context = gtk_widget_get_style_context (widget);
253 layout_one, layout_two,
256 &x_offset_1, &x_offset_2, &y_offset);
257 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
264 pango_layout_get_pixel_extents (layout_one, NULL, &layout_rect);
267 render_area.x += x_offset_1 - layout_rect.x;
269 gtk_render_layout (context, cr,
275 if (layout_two != NULL)
277 pango_layout_get_pixel_size (layout_one,
278 NULL, &line_one_height);
280 gtk_style_context_save (context);
281 gtk_style_context_add_class (context,
"dim-label");
283 state = gtk_cell_renderer_get_state (cell, widget, flags);
284 gtk_style_context_set_state (context, state);
286 pango_layout_get_pixel_extents (layout_two, NULL, &layout_rect);
289 render_area.x += x_offset_2 - layout_rect.x;
290 render_area.y += line_one_height;
292 gtk_render_layout (context, cr,
297 gtk_style_context_restore (context);
300 g_clear_object (&layout_one);
301 g_clear_object (&layout_two);
310 PangoContext *context;
311 PangoFontMetrics *metrics;
312 PangoFontDescription *font_desc;
313 GtkStyleContext *style_context;
314 gint nat_width, min_width;
315 gint xpad, char_width, wrap_width, text_width;
316 gint width_chars, ellipsize_chars;
320 "width-chars", &width_chars,
321 "wrap-width", &wrap_width,
323 style_context = gtk_widget_get_style_context (widget);
324 gtk_cell_renderer_get_padding (cell, &xpad, NULL);
333 context = gtk_widget_get_pango_context (widget);
334 gtk_style_context_save (style_context);
335 gtk_style_context_set_state (style_context, 0);
336 gtk_style_context_get (style_context, 0,
"font", &font_desc, NULL);
337 gtk_style_context_restore (style_context);
338 metrics = pango_context_get_metrics (context, font_desc,
339 pango_context_get_language (context));
341 char_width = pango_font_metrics_get_approximate_char_width (metrics);
343 pango_font_metrics_unref (metrics);
344 pango_font_description_free (font_desc);
351 min_width = xpad * 2 + MIN (text_width, wrap_width);
353 min_width = xpad * 2 +
355 (PANGO_PIXELS (char_width) * MAX (width_chars, ellipsize_chars)));
358 nat_width = xpad * 2 +
359 MAX ((PANGO_PIXELS (char_width) * width_chars), text_width);
361 nat_width = xpad * 2 + text_width;
363 nat_width = MAX (nat_width, min_width);
366 *minimum_size = min_width;
369 *natural_size = nat_width;
380 PangoLayout *layout_one, *layout_two;
381 gint text_height, wrap_width;
384 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
385 g_object_get (cell,
"wrap-width", &wrap_width, NULL);
388 if (wrap_width != -1)
389 wrap_width = MIN (width - 2 * xpad, wrap_width);
391 wrap_width = width - 2 * xpad;
393 pango_layout_set_width (layout_one, wrap_width);
394 if (layout_two != NULL)
395 pango_layout_set_width (layout_two, wrap_width);
398 layout_one, layout_two,
403 text_height += 2 * ypad;
405 if (minimum_size != NULL)
406 *minimum_size = text_height;
408 if (natural_size != NULL)
409 *natural_size = text_height;
411 g_clear_object (&layout_one);
412 g_clear_object (&layout_two);
423 gtk_cell_renderer_get_preferred_width (cell, widget, &min_width, NULL);
425 minimum_size, natural_size);
431 GtkCellRendererState flags,
432 const GdkRectangle *cell_area,
433 GdkRectangle *aligned_area)
436 gint x_offset, x_offset_1, x_offset_2, y_offset;
437 PangoLayout *layout_one, *layout_two;
442 layout_one, layout_two,
443 &aligned_area->width, &aligned_area->height,
445 &x_offset_1, &x_offset_2, &y_offset);
447 x_offset = MIN (x_offset_1, x_offset_2);
449 aligned_area->x = cell_area->x + x_offset;
450 aligned_area->y = cell_area->y;
452 g_clear_object (&layout_one);
453 g_clear_object (&layout_two);
458 const gchar *line_two)
460 if (g_strcmp0 (self->priv->line_two, line_two) == 0)
463 g_free (self->priv->line_two);
464 self->priv->line_two = g_strdup (line_two);
473 if (self->priv->text_lines == text_lines)
476 self->priv->text_lines = text_lines;
497 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
513 g_value_set_int (value, self->priv->text_lines);
516 g_value_set_string (value, self->priv->line_two);
519 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
529 g_free (self->priv->line_two);
531 G_OBJECT_CLASS (gd_two_lines_renderer_parent_class)->finalize (
object);
537 GtkCellRendererClass *cclass = GTK_CELL_RENDERER_CLASS (klass);
538 GObjectClass *oclass = G_OBJECT_CLASS (klass);
551 g_param_spec_int (
"text-lines",
553 "The total number of lines to be displayed",
555 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
558 g_param_spec_string (
"line-two",
562 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);