OptionItem.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef HEADER_OptionItem
  2. #define HEADER_OptionItem
  3. /*
  4. htop - OptionItem.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 <stdbool.h>
  10. #include "Object.h"
  11. enum OptionItemType {
  12. OPTION_ITEM_TEXT,
  13. OPTION_ITEM_CHECK,
  14. OPTION_ITEM_NUMBER,
  15. };
  16. typedef struct OptionItemClass_ {
  17. const ObjectClass super;
  18. enum OptionItemType kind;
  19. } OptionItemClass;
  20. #define As_OptionItem(this_) ((const OptionItemClass*)((this_)->super.klass))
  21. #define OptionItem_kind(this_) As_OptionItem(this_)->kind
  22. typedef struct OptionItem_ {
  23. Object super;
  24. char* text;
  25. } OptionItem;
  26. typedef struct TextItem_ {
  27. OptionItem super;
  28. char* text;
  29. } TextItem;
  30. typedef struct CheckItem_ {
  31. OptionItem super;
  32. bool* ref;
  33. bool value;
  34. } CheckItem;
  35. typedef struct NumberItem_ {
  36. OptionItem super;
  37. char* text;
  38. int* ref;
  39. int value;
  40. int scale;
  41. int min;
  42. int max;
  43. } NumberItem;
  44. extern const OptionItemClass OptionItem_class;
  45. extern const OptionItemClass TextItem_class;
  46. extern const OptionItemClass CheckItem_class;
  47. extern const OptionItemClass NumberItem_class;
  48. TextItem* TextItem_new(const char* text);
  49. CheckItem* CheckItem_newByRef(const char* text, bool* ref);
  50. CheckItem* CheckItem_newByVal(const char* text, bool value);
  51. bool CheckItem_get(const CheckItem* this);
  52. void CheckItem_set(CheckItem* this, bool value);
  53. void CheckItem_toggle(CheckItem* this);
  54. NumberItem* NumberItem_newByRef(const char* text, int* ref, int scale, int min, int max);
  55. NumberItem* NumberItem_newByVal(const char* text, int value, int scale, int min, int max);
  56. int NumberItem_get(const NumberItem* this);
  57. void NumberItem_decrease(NumberItem* this);
  58. void NumberItem_increase(NumberItem* this);
  59. void NumberItem_toggle(NumberItem* this);
  60. #endif