Mercurial > pidgin.yaz
comparison finch/libgnt/gnttextview.c @ 16011:1f24fd9a6237
word wrapping, fix \r\n newlines
author | Richard Nelson <wabz@pidgin.im> |
---|---|
date | Mon, 09 Apr 2007 10:03:48 +0000 |
parents | f00f2e283ffb |
children | ab3f93232a2d |
comparison
equal
deleted
inserted
replaced
16010:eae8e127e4fb | 16011:1f24fd9a6237 |
---|---|
481 view->list = g_list_first(view->list); | 481 view->list = g_list_first(view->list); |
482 | 482 |
483 start = end = view->string->str + len; | 483 start = end = view->string->str + len; |
484 | 484 |
485 while (*start) { | 485 while (*start) { |
486 GntTextLine *oldl; | |
486 GntTextSegment *seg = NULL; | 487 GntTextSegment *seg = NULL; |
487 | 488 |
488 if (*end == '\n' || *end == '\r') { | 489 if (*end == '\n' || *end == '\r') { |
490 if (!strncmp(end, "\r\n", 2)) | |
491 end++; | |
489 end++; | 492 end++; |
490 start = end; | 493 start = end; |
491 gnt_text_view_next_line(view); | 494 gnt_text_view_next_line(view); |
492 view->list = g_list_first(view->list); | 495 view->list = g_list_first(view->list); |
493 continue; | 496 continue; |
499 line = g_new0(GntTextLine, 1); | 502 line = g_new0(GntTextLine, 1); |
500 line->soft = TRUE; | 503 line->soft = TRUE; |
501 view->list = g_list_prepend(view->list, line); | 504 view->list = g_list_prepend(view->list, line); |
502 } | 505 } |
503 | 506 |
504 if ((end = strchr(start, '\n')) != NULL || | 507 if ((end = strchr(start, '\r')) != NULL || |
505 (end = strchr(start, '\r')) != NULL) { | 508 (end = strchr(start, '\n')) != NULL) { |
506 len = gnt_util_onscreen_width(start, end - 1); | 509 len = gnt_util_onscreen_width(start, end - 1); |
507 if (len >= widget->priv.width - line->length - 1) { | 510 if (len >= widget->priv.width - line->length - 1) { |
508 end = NULL; | 511 end = NULL; |
509 } | 512 } |
510 } | 513 } |
525 seg->start = start - view->string->str; | 528 seg->start = start - view->string->str; |
526 seg->tvflag = flags; | 529 seg->tvflag = flags; |
527 seg->flags = fl; | 530 seg->flags = fl; |
528 line->segments = g_list_append(line->segments, seg); | 531 line->segments = g_list_append(line->segments, seg); |
529 } | 532 } |
530 seg->end = end - view->string->str; | 533 |
531 line->length += len; | 534 oldl = line; |
532 | |
533 start = end; | |
534 if (*end && *end != '\n' && *end != '\r') { | 535 if (*end && *end != '\n' && *end != '\r') { |
536 const char *tmp = end; | |
537 while (end && *end != '\n' && *end != '\r' && !g_ascii_isspace(*end)) { | |
538 end = g_utf8_find_prev_char(seg->start + view->string->str, end); | |
539 } | |
540 if (!end || !g_ascii_isspace(*end)) | |
541 end = tmp; | |
542 else | |
543 end++; /* Remove the space */ | |
544 | |
535 line = g_new0(GntTextLine, 1); | 545 line = g_new0(GntTextLine, 1); |
536 line->soft = TRUE; | 546 line->soft = TRUE; |
537 view->list = g_list_prepend(view->list, line); | 547 view->list = g_list_prepend(view->list, line); |
538 } | 548 } |
549 seg->end = end - view->string->str; | |
550 oldl->length += len; | |
551 start = end; | |
539 } | 552 } |
540 | 553 |
541 view->list = list; | 554 view->list = list; |
542 | 555 |
543 gnt_widget_draw(widget); | 556 gnt_widget_draw(widget); |