Mercurial > pidgin
comparison finch/libgnt/gnttree.c @ 21250:9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
attributes if the terminal doesn't support color. Fixes #3560.
I have included the output of diffstat of the changeset. Do we like this in
our commit message? If we do, we can use the stuff rekkanoryo has for gf.
----------------------------------------------------------------------
ChangeLog.API | 7 +++++++
finch/libgnt/gntbox.c | 10 +++++-----
finch/libgnt/gntbutton.c | 3 ++-
finch/libgnt/gntcheckbox.c | 4 ++--
finch/libgnt/gntcolors.c | 11 +++++++++++
finch/libgnt/gntcolors.h | 13 +++++++++++++
finch/libgnt/gntcombobox.c | 8 ++++----
finch/libgnt/gntentry.c | 4 ++--
finch/libgnt/gntline.c | 4 ++--
finch/libgnt/gntmain.c | 4 ++--
finch/libgnt/gntmenu.c | 4 ++--
finch/libgnt/gntslider.c | 10 +++++-----
finch/libgnt/gnttextview.c | 14 +++++++-------
finch/libgnt/gnttree.c | 37 ++++++++++++++++++-------------------
finch/libgnt/gntwidget.c | 22 +++++++++++-----------
finch/libgnt/gntwm.c | 4 ++--
finch/libgnt/gntws.c | 10 +++++-----
17 files changed, 100 insertions(+), 69 deletions(-)
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 16 Oct 2007 09:51:12 +0000 |
parents | fe77cc691f78 |
children | f35b480841dc |
comparison
equal
deleted
inserted
replaced
21249:930d0b49ebcf | 21250:9187d331aebe |
---|---|
430 if (tree->current == NULL) { | 430 if (tree->current == NULL) { |
431 tree->current = tree->root; | 431 tree->current = tree->root; |
432 tree_selection_changed(tree, NULL, tree->current); | 432 tree_selection_changed(tree, NULL, tree->current); |
433 } | 433 } |
434 | 434 |
435 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); | 435 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); |
436 | 436 |
437 start = 0; | 437 start = 0; |
438 if (tree->show_title) | 438 if (tree->show_title) |
439 { | 439 { |
440 int i; | 440 int i; |
441 int x = pos; | 441 int x = pos; |
442 | 442 |
443 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), | 443 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), |
444 widget->priv.width - pos - 1); | 444 widget->priv.width - pos - 1); |
445 mvwhline(widget->window, pos, pos, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), | 445 mvwhline(widget->window, pos, pos, ' ' | gnt_color_pair(GNT_COLOR_NORMAL), |
446 widget->priv.width - pos - 1); | 446 widget->priv.width - pos - 1); |
447 | 447 |
448 for (i = 0; i < tree->ncol; i++) | 448 for (i = 0; i < tree->ncol; i++) |
449 { | 449 { |
450 if (COLUMN_INVISIBLE(tree, i)) { | 450 if (COLUMN_INVISIBLE(tree, i)) { |
453 mvwaddnstr(widget->window, pos, x + (x != pos), tree->columns[i].title, tree->columns[i].width); | 453 mvwaddnstr(widget->window, pos, x + (x != pos), tree->columns[i].title, tree->columns[i].width); |
454 NEXT_X; | 454 NEXT_X; |
455 } | 455 } |
456 if (pos) | 456 if (pos) |
457 { | 457 { |
458 tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); | 458 tree_mark_columns(tree, pos, 0, ACS_TTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
459 tree_mark_columns(tree, pos, widget->priv.height - pos, | 459 tree_mark_columns(tree, pos, widget->priv.height - pos, |
460 ACS_BTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); | 460 ACS_BTEE | gnt_color_pair(GNT_COLOR_NORMAL)); |
461 } | 461 } |
462 tree_mark_columns(tree, pos, pos + 1, | 462 tree_mark_columns(tree, pos, pos + 1, |
463 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | COLOR_PAIR(GNT_COLOR_NORMAL)); | 463 (tree->show_separator ? ACS_PLUS : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); |
464 tree_mark_columns(tree, pos, pos, | 464 tree_mark_columns(tree, pos, pos, |
465 (tree->show_separator ? ACS_VLINE : ' ') | COLOR_PAIR(GNT_COLOR_NORMAL)); | 465 (tree->show_separator ? ACS_VLINE : ' ') | gnt_color_pair(GNT_COLOR_NORMAL)); |
466 start = 2; | 466 start = 2; |
467 } | 467 } |
468 | 468 |
469 rows = widget->priv.height - pos * 2 - start - 1; | 469 rows = widget->priv.height - pos * 2 - start - 1; |
470 tree->bottom = get_next_n_opt(tree->top, rows, &down); | 470 tree->bottom = get_next_n_opt(tree->top, rows, &down); |
512 attr |= A_BLINK; | 512 attr |= A_BLINK; |
513 | 513 |
514 if (row == tree->current) | 514 if (row == tree->current) |
515 { | 515 { |
516 if (gnt_widget_has_focus(widget)) | 516 if (gnt_widget_has_focus(widget)) |
517 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT); | 517 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT); |
518 else | 518 else |
519 attr |= COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D); | 519 attr |= gnt_color_pair(GNT_COLOR_HIGHLIGHT_D); |
520 } | 520 } |
521 else | 521 else |
522 { | 522 { |
523 if (flags & GNT_TEXT_FLAG_DIM) | 523 if (flags & GNT_TEXT_FLAG_DIM) |
524 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); | 524 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED)); |
525 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) | 525 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
526 attr |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); | 526 attr |= (A_DIM | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
527 else | 527 else |
528 attr |= COLOR_PAIR(GNT_COLOR_NORMAL); | 528 attr |= gnt_color_pair(GNT_COLOR_NORMAL); |
529 } | 529 } |
530 | 530 |
531 wbkgdset(widget->window, '\0' | attr); | 531 wbkgdset(widget->window, '\0' | attr); |
532 mvwaddstr(widget->window, i, pos, str); | 532 mvwaddstr(widget->window, i, pos, str); |
533 whline(widget->window, ' ', scrcol - wr); | 533 whline(widget->window, ' ', scrcol - wr); |
535 g_free(str); | 535 g_free(str); |
536 tree_mark_columns(tree, pos, i, | 536 tree_mark_columns(tree, pos, i, |
537 (tree->show_separator ? ACS_VLINE : ' ') | attr); | 537 (tree->show_separator ? ACS_VLINE : ' ') | attr); |
538 } | 538 } |
539 | 539 |
540 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | 540 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
541 while (i < widget->priv.height - pos) | 541 while (i < widget->priv.height - pos) |
542 { | 542 { |
543 mvwhline(widget->window, i, pos, ' ', | 543 mvwhline(widget->window, i, pos, ' ', |
544 widget->priv.width - pos * 2 - 1); | 544 widget->priv.width - pos * 2 - 1); |
545 tree_mark_columns(tree, pos, i, | 545 tree_mark_columns(tree, pos, i, |
574 position = rows - showing; | 574 position = rows - showing; |
575 | 575 |
576 position += pos + start + 1; | 576 position += pos + start + 1; |
577 | 577 |
578 mvwvline(widget->window, pos + start + 1, scrcol, | 578 mvwvline(widget->window, pos + start + 1, scrcol, |
579 ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), rows); | 579 ' ' | gnt_color_pair(GNT_COLOR_NORMAL), rows); |
580 mvwvline(widget->window, position, scrcol, | 580 mvwvline(widget->window, position, scrcol, |
581 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing); | 581 ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing); |
582 } | 582 } |
583 | 583 |
584 mvwaddch(widget->window, start + pos, scrcol, | 584 mvwaddch(widget->window, start + pos, scrcol, |
585 ((tree->top != tree->root) ? ACS_UARROW : ' ') | | 585 ((tree->top != tree->root) ? ACS_UARROW : ' ') | |
586 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); | 586 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
587 | 587 |
588 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol, | 588 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol, |
589 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); | 589 (row ? ACS_DARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
590 | 590 |
591 /* If there's a search-text, show it in the bottom of the tree */ | 591 /* If there's a search-text, show it in the bottom of the tree */ |
592 if (tree->priv->search && tree->priv->search->len > 0) { | 592 if (tree->priv->search && tree->priv->search->len > 0) { |
593 const char *str = gnt_util_onscreen_width_to_pointer(tree->priv->search->str, scrcol - 1, NULL); | 593 const char *str = gnt_util_onscreen_width_to_pointer(tree->priv->search->str, scrcol - 1, NULL); |
594 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); | 594 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); |
595 mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos, | 595 mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos, |
596 tree->priv->search->str, str - tree->priv->search->str); | 596 tree->priv->search->str, str - tree->priv->search->str); |
597 } | 597 } |
598 | 598 |
599 gnt_widget_queue_update(widget); | 599 gnt_widget_queue_update(widget); |
1326 else | 1326 else |
1327 { | 1327 { |
1328 tree->list = g_list_insert(tree->list, key, position + 1); | 1328 tree->list = g_list_insert(tree->list, key, position + 1); |
1329 } | 1329 } |
1330 } | 1330 } |
1331 | |
1332 redraw_tree(tree); | 1331 redraw_tree(tree); |
1333 | 1332 |
1334 return row; | 1333 return row; |
1335 } | 1334 } |
1336 | 1335 |