Panel.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef HEADER_Panel
  2. #define HEADER_Panel
  3. /*
  4. htop - Panel.h
  5. (C) 2004-2011 Hisham H. Muhammad
  6. Released under the GNU GPLv2+, see the COPYING file
  7. in the source distribution for its full text.
  8. */
  9. #include <assert.h>
  10. #include <stdbool.h>
  11. #include "CRT.h"
  12. #include "FunctionBar.h"
  13. #include "Object.h"
  14. #include "RichString.h"
  15. #include "Vector.h"
  16. struct Panel_;
  17. typedef struct Panel_ Panel;
  18. typedef enum HandlerResult_ {
  19. HANDLED = 0x01,
  20. IGNORED = 0x02,
  21. BREAK_LOOP = 0x04,
  22. REFRESH = 0x08,
  23. REDRAW = 0x10,
  24. RESCAN = 0x20,
  25. RESIZE = 0x40,
  26. SYNTH_KEY = 0x80,
  27. } HandlerResult;
  28. #define EVENT_SET_SELECTED (-1)
  29. #define EVENT_HEADER_CLICK(x_) (-10000 + (x_))
  30. #define EVENT_IS_HEADER_CLICK(ev_) ((ev_) >= -10000 && (ev_) <= -9000)
  31. #define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000)
  32. #define EVENT_SCREEN_TAB_CLICK(x_) (-20000 + (x_))
  33. #define EVENT_IS_SCREEN_TAB_CLICK(ev_) ((ev_) >= -20000 && (ev_) < -10000)
  34. #define EVENT_SCREEN_TAB_GET_X(ev_) ((ev_) + 20000)
  35. typedef HandlerResult (*Panel_EventHandler)(Panel*, int);
  36. typedef void (*Panel_DrawFunctionBar)(Panel*, bool);
  37. typedef void (*Panel_PrintHeader)(Panel*);
  38. typedef struct PanelClass_ {
  39. const ObjectClass super;
  40. const Panel_EventHandler eventHandler;
  41. const Panel_DrawFunctionBar drawFunctionBar;
  42. const Panel_PrintHeader printHeader;
  43. } PanelClass;
  44. #define As_Panel(this_) ((const PanelClass*)((this_)->super.klass))
  45. #define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
  46. #define Panel_eventHandler(this_, ev_) (assert(As_Panel(this_)->eventHandler), As_Panel(this_)->eventHandler((Panel*)(this_), ev_))
  47. #define Panel_drawFunctionBarFn(this_) As_Panel(this_)->drawFunctionBar
  48. #define Panel_drawFunctionBar(this_, hideFB_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_), hideFB_))
  49. #define Panel_printHeaderFn(this_) As_Panel(this_)->printHeader
  50. #define Panel_printHeader(this_) (assert(As_Panel(this_)->printHeader), As_Panel(this_)->printHeader((Panel*)(this_)))
  51. struct Panel_ {
  52. Object super;
  53. int x, y, w, h;
  54. int cursorX, cursorY;
  55. Vector* items;
  56. int selected;
  57. int oldSelected;
  58. int selectedLen;
  59. void* eventHandlerState;
  60. int scrollV;
  61. int scrollH;
  62. bool needsRedraw;
  63. bool cursorOn;
  64. bool wasFocus;
  65. FunctionBar* currentBar;
  66. FunctionBar* defaultBar;
  67. RichString header;
  68. ColorElements selectionColorId;
  69. };
  70. #define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while (0)
  71. #define KEY_CTRL(l) ((l)-'A'+1)
  72. extern const PanelClass Panel_class;
  73. Panel* Panel_new(int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar);
  74. void Panel_delete(Object* cast);
  75. void Panel_init(Panel* this, int x, int y, int w, int h, const ObjectClass* type, bool owner, FunctionBar* fuBar);
  76. void Panel_done(Panel* this);
  77. void Panel_setCursorToSelection(Panel* this);
  78. void Panel_setSelectionColor(Panel* this, ColorElements colorId);
  79. void Panel_setHeader(Panel* this, const char* header);
  80. void Panel_move(Panel* this, int x, int y);
  81. void Panel_resize(Panel* this, int w, int h);
  82. void Panel_prune(Panel* this);
  83. void Panel_add(Panel* this, Object* o);
  84. void Panel_insert(Panel* this, int i, Object* o);
  85. void Panel_set(Panel* this, int i, Object* o);
  86. Object* Panel_get(Panel* this, int i);
  87. Object* Panel_remove(Panel* this, int i);
  88. Object* Panel_getSelected(Panel* this);
  89. void Panel_moveSelectedUp(Panel* this);
  90. void Panel_moveSelectedDown(Panel* this);
  91. int Panel_getSelectedIndex(const Panel* this);
  92. int Panel_size(const Panel* this);
  93. void Panel_setSelected(Panel* this, int selected);
  94. void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected, bool hideFunctionBar);
  95. void Panel_splice(Panel* this, Vector* from);
  96. bool Panel_onKey(Panel* this, int key);
  97. HandlerResult Panel_selectByTyping(Panel* this, int ch);
  98. int Panel_getCh(Panel* this);
  99. #endif