62 PangoFontDescription *
pfd;
75 if ( tb->
blink < 2 ) {
121 pango_layout_xy_to_index ( tb->
layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL );
141 if ( tbfc == NULL ) {
143 tbfc->
pfd = pango_font_description_from_string ( font );
146 tbfc->
height = pango_font_metrics_get_ascent ( tbfc->
metrics ) + pango_font_metrics_get_descent ( tbfc->
metrics );
149 g_hash_table_insert (
tbfc_cache, (
char *) font, tbfc );
152 pango_font_description_free ( tbfc->
pfd );
159 pango_layout_set_font_description ( tb->
layout, tbfc->
pfd );
180 tb->
emode = PANGO_ELLIPSIZE_END;
194 pango_layout_set_wrap ( tb->
layout, PANGO_WRAP_WORD_CHAR );
224 {
"normal.normal",
"selected.normal",
"alternate.normal" },
226 {
"normal.urgent",
"selected.urgent",
"alternate.urgent" },
228 {
"normal.active",
"selected.active",
"alternate.active" },
267 pango_layout_set_attributes ( tb->
layout, NULL );
269 size_t l = g_utf8_strlen ( tb->
text, -1 );
271 memset (
string,
'*', l );
273 pango_layout_set_text ( tb->
layout,
string, l );
276 pango_layout_set_markup ( tb->
layout, tb->
text, -1 );
279 pango_layout_set_text ( tb->
layout, tb->
text, -1 );
287 return pango_layout_get_text ( tb->
layout );
294 return pango_layout_get_attributes ( tb->
layout );
301 pango_layout_set_attributes ( tb->
layout, list );
311 const gchar *last_pointer = NULL;
313 if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
314 tb->
text = g_strdup ( text );
317 if ( last_pointer != NULL ) {
319 tb->
text = g_strndup ( text, ( last_pointer - text ) );
322 tb->
text = g_strdup (
"Invalid UTF-8 string." );
328 if (
WIDGET ( tb )->parent ) {
333 tb->
cursor = MAX ( 0, MIN ( (
int ) g_utf8_strlen ( tb->
text, -1 ), tb->
cursor ) );
340 if (
icon != NULL ) {
341 cairo_surface_reference (
icon );
345 cairo_surface_destroy ( tb->
icon );
357 pango_layout_set_width ( tb->
layout, -1 );
363 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_MIDDLE );
366 pango_layout_set_ellipsize ( tb->
layout, tb->
emode );
368 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_NONE );
374 int tw = MAX ( 1, w );
406 cairo_surface_destroy ( tb->
icon );
409 if ( tb->
layout != NULL ) {
410 g_object_unref ( tb->
layout );
431 int y = ( pango_font_metrics_get_ascent ( tb->
metrics ) - pango_layout_get_baseline ( tb->
layout ) ) / PANGO_SCALE;
432 int line_width = 0, line_height = 0;
434 pango_layout_get_pixel_size ( tb->
layout, &line_width, &line_height );
436 if ( tb->
yalign > 0.001 ) {
438 top = ( tb->
widget.
h - bottom - line_height - top ) * tb->
yalign + top;
447 int iconh = cairo_image_surface_get_height ( tb->
icon );
448 int iconw = cairo_image_surface_get_width ( tb->
icon );
449 int icons = MAX ( iconh, iconw );
450 double scale = (double) iconheight / icons;
451 cairo_translate ( draw, x + ( iconheight - iconw * scale ) / 2.0, y + ( iconheight - iconh * scale ) / 2.0 );
452 cairo_scale ( draw, scale, scale );
453 cairo_set_source_surface ( draw, tb->
icon, 0, 0 );
454 cairo_paint ( draw );
455 cairo_restore ( draw );
459 if ( tb->
xalign > 0.001 ) {
464 cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
465 cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
470 const char *text = pango_layout_get_text ( tb->
layout );
472 int cursor_offset = MIN ( tb->
cursor, g_utf8_strlen ( text, -1 ) );
475 char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
476 pango_layout_get_cursor_pos ( tb->
layout, offset - text, &pos, NULL );
477 int cursor_x = pos.x / PANGO_SCALE;
478 int cursor_y = pos.y / PANGO_SCALE;
479 int cursor_height = pos.height / PANGO_SCALE;
480 int cursor_width = 2;
481 cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
487 cairo_move_to ( draw, x, top );
488 pango_cairo_show_layout ( draw, tb->
layout );
502 int length = ( tb->
text == NULL ) ? 0 : g_utf8_strlen ( tb->
text, -1 );
503 tb->
cursor = MAX ( 0, MIN ( length, pos ) );
540 if ( tb->
text == NULL ) {
544 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
545 while ( ( c = g_utf8_next_char ( c ) ) ) {
546 gunichar uc = g_utf8_get_char ( c );
547 GUnicodeBreakType bt = g_unichar_break_type ( uc );
548 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
549 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
553 if ( c == NULL || *c ==
'\0' ) {
556 while ( ( c = g_utf8_next_char ( c ) ) ) {
557 gunichar uc = g_utf8_get_char ( c );
558 GUnicodeBreakType bt = g_unichar_break_type ( uc );
559 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
560 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
564 int index = g_utf8_pointer_to_offset ( tb->
text, c );
572 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
573 while ( ( c = g_utf8_prev_char ( c ) ) && c != tb->
text ) {
574 gunichar uc = g_utf8_get_char ( c );
575 GUnicodeBreakType bt = g_unichar_break_type ( uc );
576 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
577 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
581 if ( c != tb->
text ) {
582 while ( ( n = g_utf8_prev_char ( c ) ) ) {
583 gunichar uc = g_utf8_get_char ( n );
584 GUnicodeBreakType bt = g_unichar_break_type ( uc );
585 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
586 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
590 if ( n == tb->
text ) {
595 int index = g_utf8_pointer_to_offset ( tb->
text, c );
602 if ( tb->
text == NULL ) {
607 tb->
cursor = ( int ) g_utf8_strlen ( tb->
text, -1 );
619 char *c = g_utf8_offset_to_pointer ( tb->
text, char_pos );
620 int pos = c - tb->
text;
621 int len = ( int ) strlen ( tb->
text );
622 pos = MAX ( 0, MIN ( len, pos ) );
624 tb->
text = g_realloc ( tb->
text, len + slen + 1 );
626 char *at = tb->
text + pos;
627 memmove ( at + slen, at, len - pos + 1 );
629 memmove ( at, str, slen );
643 int len = g_utf8_strlen ( tb->
text, -1 );
647 pos = MAX ( 0, MIN ( len, pos ) );
648 if ( ( pos + dlen ) > len ) {
652 char *start = g_utf8_offset_to_pointer ( tb->
text, pos );
653 char *end = g_utf8_offset_to_pointer ( tb->
text, pos + dlen );
655 memmove ( start, end, ( tb->
text + strlen ( tb->
text ) ) - end + 1 );
656 if ( tb->
cursor >= pos && tb->
cursor < ( pos + dlen ) ) {
659 else if ( tb->
cursor >= ( pos + dlen ) ) {
675 if ( tb == NULL || tb->
text == NULL ) {
688 if ( tb && tb->
cursor > 0 ) {
695 if ( tb && tb->
cursor > 0 ) {
698 if ( cursor > tb->
cursor ) {
705 if ( tb && tb->
cursor >= 0 ) {
706 int length = g_utf8_strlen ( tb->
text, -1 ) - tb->
cursor;
714 if ( tb && tb->
cursor >= 0 ) {
723 if ( tb && tb->
cursor >= 0 ) {
726 if ( cursor < tb->cursor ) {
797 g_return_val_if_reached ( 0 );
812 gboolean used_something = FALSE;
813 const gchar *w, *n, *e;
814 for ( w = pad, n = g_utf8_next_char ( w ), e = w + pad_len; w < e; w = n, n = g_utf8_next_char ( n ) ) {
815 if ( g_unichar_iscntrl ( g_utf8_get_char ( w ) ) ) {
820 used_something = TRUE;
822 return used_something;
827 pango_font_metrics_unref ( tbfc->
metrics );
829 pango_font_description_free ( tbfc->
pfd );
847 tbfc->
height = pango_font_metrics_get_ascent ( tbfc->
metrics ) + pango_font_metrics_get_descent ( tbfc->
metrics );
886 pango_layout_get_pixel_size ( tb->
layout, NULL, &height );
893 pango_layout_get_pixel_extents ( tb->
layout, NULL, &rect );
894 return rect.width + rect.x;
902 int height = pango_font_metrics_get_ascent (
p_metrics ) + pango_font_metrics_get_descent (
p_metrics );
913 int width = pango_font_metrics_get_approximate_char_width (
p_metrics );
914 char_width = ( width ) / (
double) PANGO_SCALE;
924 int width = pango_font_metrics_get_approximate_digit_width (
p_metrics );
925 ch_width = ( width ) / (
double) PANGO_SCALE;
932 int height = pango_font_metrics_get_ascent ( tb->
metrics ) + pango_font_metrics_get_descent ( tb->
metrics );
949 int old_width = pango_layout_get_width ( tb->
layout );
950 pango_layout_set_width ( tb->
layout, -1 );
953 pango_layout_set_width ( tb->
layout, old_width );
954 return width + padding + offset;
965 pango_layout_set_ellipsize ( tb->
layout, tb->
emode );