label.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #include <config.h>
  17. #include "label.h"
  18. #include "themes.h"
  19. Label::Label()
  20. {
  21. create_window();
  22. is_highlighted = false;
  23. dirty = true;
  24. }
  25. Label::Label(const char *aText)
  26. {
  27. create_window();
  28. is_highlighted = false;
  29. set_text(aText);
  30. }
  31. void Label::set_text(const char *aText)
  32. {
  33. text = aText ? aText : "";
  34. // we append one space so that if this widget gets the focus,
  35. // the terminal cursor won't stick to the text. this is for
  36. // aesthetic only.
  37. text += ' ';
  38. dirty = true;
  39. }
  40. void Label::highlight(bool value)
  41. {
  42. is_highlighted = value;
  43. invalidate_view();
  44. }
  45. void Label::update()
  46. {
  47. if (!dirty)
  48. return;
  49. wbkgd(wnd, get_attr(is_highlighted ? STATUSLINE_ATTR : DIALOGLINE_ATTR));
  50. wmove(wnd, 0, 0);
  51. wclrtoeol(wnd);
  52. draw_string(text.c_str(), true);
  53. wnoutrefresh(wnd);
  54. dirty = false;
  55. }
  56. void Label::resize(int lines, int columns, int y, int x)
  57. {
  58. Widget::resize(lines, columns, y, x);
  59. dirty = true;
  60. }