62 PangoFontDescription *
pfd;
75 if ( tb->
blink < 2 ) {
121 pango_layout_xy_to_index ( tb->
layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL );
140 if ( tbfc == NULL ) {
142 tbfc->
pfd = pango_font_description_from_string ( font );
145 tbfc->
height = pango_font_metrics_get_ascent ( tbfc->
metrics ) + pango_font_metrics_get_descent ( tbfc->
metrics );
148 g_hash_table_insert (
tbfc_cache, (
char *) font, tbfc );
151 pango_font_description_free ( tbfc->
pfd );
158 pango_layout_set_font_description ( tb->
layout, tbfc->
pfd );
178 tb->
emode = PANGO_ELLIPSIZE_END;
188 pango_layout_set_wrap ( tb->
layout, PANGO_WRAP_WORD_CHAR );
192 if ( txt == NULL || ( *txt ) ==
'\0' ) {
227 {
"normal.normal",
"selected.normal",
"alternate.normal" },
229 {
"normal.urgent",
"selected.urgent",
"alternate.urgent" },
231 {
"normal.active",
"selected.active",
"alternate.active" },
270 pango_layout_set_attributes ( tb->
layout, NULL );
278 size_t l = g_utf8_strlen ( tb->
text, -1 );
280 memset (
string,
'*', l );
282 pango_layout_set_text ( tb->
layout,
string, l );
285 pango_layout_set_markup ( tb->
layout, tb->
text, -1 );
288 pango_layout_set_text ( tb->
layout, tb->
text, -1 );
296 return pango_layout_get_text ( tb->
layout );
303 return pango_layout_get_attributes ( tb->
layout );
310 pango_layout_set_attributes ( tb->
layout, list );
320 const gchar *last_pointer = NULL;
322 if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
323 tb->
text = g_strdup ( text );
326 if ( last_pointer != NULL ) {
328 tb->
text = g_strndup ( text, ( last_pointer - text ) );
331 tb->
text = g_strdup (
"Invalid UTF-8 string." );
337 if (
WIDGET ( tb )->parent ) {
342 tb->
cursor = MAX ( 0, MIN ( (
int ) g_utf8_strlen ( tb->
text, -1 ), tb->
cursor ) );
351 pango_layout_set_width ( tb->
layout, -1 );
357 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_MIDDLE );
360 pango_layout_set_ellipsize ( tb->
layout, tb->
emode );
363 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_NONE );
369 int tw = MAX ( 1, w );
400 if ( tb->
layout != NULL ) {
401 g_object_unref ( tb->
layout );
422 int y = ( pango_font_metrics_get_ascent ( tb->
metrics ) - pango_layout_get_baseline ( tb->
layout ) ) / PANGO_SCALE;
423 int line_width = 0, line_height = 0;
425 pango_layout_get_pixel_size ( tb->
layout, &line_width, &line_height );
427 if ( tb->
yalign > 0.001 ) {
429 top = ( tb->
widget.
h - bottom - line_height - top ) * tb->
yalign + top;
435 if ( tb->
xalign > 0.001 ) {
440 cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
441 cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
449 cairo_move_to ( draw, x, top );
451 cairo_reset_clip ( draw );
452 pango_cairo_show_layout ( draw, tb->
layout );
453 cairo_restore ( draw );
459 const char *text = pango_layout_get_text ( tb->
layout );
461 int cursor_offset = MIN ( tb->
cursor, g_utf8_strlen ( text, -1 ) );
464 char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
465 pango_layout_get_cursor_pos ( tb->
layout, offset - text, &pos, NULL );
466 int cursor_x = pos.x / PANGO_SCALE;
467 int cursor_y = pos.y / PANGO_SCALE;
468 int cursor_height = pos.height / PANGO_SCALE;
469 int cursor_width = 2;
470 cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
486 int length = ( tb->
text == NULL ) ? 0 : g_utf8_strlen ( tb->
text, -1 );
487 tb->
cursor = MAX ( 0, MIN ( length, pos ) );
524 if ( tb->
text == NULL ) {
528 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
529 while ( ( c = g_utf8_next_char ( c ) ) ) {
530 gunichar uc = g_utf8_get_char ( c );
531 GUnicodeBreakType bt = g_unichar_break_type ( uc );
532 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
533 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
537 if ( c == NULL || *c ==
'\0' ) {
540 while ( ( c = g_utf8_next_char ( c ) ) ) {
541 gunichar uc = g_utf8_get_char ( c );
542 GUnicodeBreakType bt = g_unichar_break_type ( uc );
543 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
544 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
548 int index = g_utf8_pointer_to_offset ( tb->
text, c );
556 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
557 while ( ( c = g_utf8_prev_char ( c ) ) && c != tb->
text ) {
558 gunichar uc = g_utf8_get_char ( c );
559 GUnicodeBreakType bt = g_unichar_break_type ( uc );
560 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
561 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
565 if ( c != tb->
text ) {
566 while ( ( n = g_utf8_prev_char ( c ) ) ) {
567 gunichar uc = g_utf8_get_char ( n );
568 GUnicodeBreakType bt = g_unichar_break_type ( uc );
569 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
570 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
574 if ( n == tb->
text ) {
579 int index = g_utf8_pointer_to_offset ( tb->
text, c );
586 if ( tb->
text == NULL ) {
591 tb->
cursor = ( int ) g_utf8_strlen ( tb->
text, -1 );
603 char *c = g_utf8_offset_to_pointer ( tb->
text, char_pos );
604 int pos = c - tb->
text;
605 int len = ( int ) strlen ( tb->
text );
606 pos = MAX ( 0, MIN ( len, pos ) );
608 tb->
text = g_realloc ( tb->
text, len + slen + 1 );
610 char *at = tb->
text + pos;
611 memmove ( at + slen, at, len - pos + 1 );
613 memmove ( at, str, slen );
627 int len = g_utf8_strlen ( tb->
text, -1 );
631 pos = MAX ( 0, MIN ( len, pos ) );
632 if ( ( pos + dlen ) > len ) {
636 char *start = g_utf8_offset_to_pointer ( tb->
text, pos );
637 char *end = g_utf8_offset_to_pointer ( tb->
text, pos + dlen );
639 memmove ( start, end, ( tb->
text + strlen ( tb->
text ) ) - end + 1 );
640 if ( tb->
cursor >= pos && tb->
cursor < ( pos + dlen ) ) {
643 else if ( tb->
cursor >= ( pos + dlen ) ) {
659 if ( tb == NULL || tb->
text == NULL ) {
672 if ( tb && tb->
cursor > 0 ) {
679 if ( tb && tb->
cursor > 0 ) {
682 if ( cursor > tb->
cursor ) {
689 if ( tb && tb->
cursor >= 0 ) {
690 int length = g_utf8_strlen ( tb->
text, -1 ) - tb->
cursor;
698 if ( tb && tb->
cursor >= 0 ) {
707 if ( tb && tb->
cursor >= 0 ) {
710 if ( cursor < tb->cursor ) {
781 g_return_val_if_reached ( 0 );
796 gboolean used_something = FALSE;
797 const gchar *w, *n, *e;
798 for ( w = pad, n = g_utf8_next_char ( w ), e = w + pad_len; w < e; w = n, n = g_utf8_next_char ( n ) ) {
799 if ( g_unichar_iscntrl ( g_utf8_get_char ( w ) ) ) {
804 used_something = TRUE;
806 return used_something;
811 pango_font_metrics_unref ( tbfc->
metrics );
813 pango_font_description_free ( tbfc->
pfd );
831 tbfc->
height = pango_font_metrics_get_ascent ( tbfc->
metrics ) + pango_font_metrics_get_descent ( tbfc->
metrics );
870 pango_layout_get_pixel_size ( tb->
layout, NULL, &height );
877 pango_layout_get_pixel_extents ( tb->
layout, NULL, &rect );
878 return rect.width + rect.x;
886 int height = pango_font_metrics_get_ascent (
p_metrics ) + pango_font_metrics_get_descent (
p_metrics );
897 int width = pango_font_metrics_get_approximate_char_width (
p_metrics );
898 char_width = ( width ) / (
double) PANGO_SCALE;
908 int width = pango_font_metrics_get_approximate_digit_width (
p_metrics );
909 ch_width = ( width ) / (
double) PANGO_SCALE;
916 int height = pango_font_metrics_get_ascent ( tb->
metrics ) + pango_font_metrics_get_descent ( tb->
metrics );
936 int old_width = pango_layout_get_width ( tb->
layout );
937 pango_layout_set_width ( tb->
layout, -1 );
940 pango_layout_set_width ( tb->
layout, old_width );
941 return width + padding + offset;
950 pango_layout_set_ellipsize ( tb->
layout, tb->
emode );