widget.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifndef BDE_WIDGET_H
  17. #define BDE_WIDGET_H
  18. #include "dispatcher.h"
  19. #include "terminal.h"
  20. typedef int attribute_t;
  21. class Widget : public Dispatcher {
  22. bool modal;
  23. public:
  24. WINDOW *wnd; // public
  25. Widget();
  26. virtual ~Widget();
  27. bool create_window(int lines = 1, int cols = 5);
  28. void destroy_window() {
  29. if (wnd) {
  30. delwin(wnd);
  31. wnd = NULL;
  32. }
  33. }
  34. bool is_valid_window() const {
  35. return wnd != NULL;
  36. }
  37. void enable_keypad() {
  38. if (is_valid_window())
  39. keypad(wnd, TRUE);
  40. }
  41. int window_width() const {
  42. int x, y;
  43. getmaxyx(wnd, y, x);
  44. return x;
  45. }
  46. int window_height() const {
  47. int x, y;
  48. getmaxyx(wnd, y, x);
  49. return y;
  50. }
  51. int window_begx() const {
  52. int x, y;
  53. getbegyx(wnd, y, x);
  54. return x;
  55. }
  56. int window_begy() const {
  57. int x, y;
  58. getbegyx(wnd, y, x);
  59. return y;
  60. }
  61. void put_unichar(unichar ch, unichar bad_repr);
  62. void draw_string(const char *u8, bool align_right = false);
  63. virtual void resize(int lines, int columns, int y, int x);
  64. virtual void update() = 0;
  65. virtual bool is_dirty() const = 0;
  66. virtual void invalidate_view() = 0;
  67. virtual void end_modal() { modal = false; }
  68. virtual void set_modal() { modal = true; }
  69. virtual bool is_modal() const { return modal; }
  70. static void signal_error();
  71. };
  72. #endif