checkbox.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #ifndef __CHECKBOX_H
  2. #define __CHECKBOX_H
  3. #include <api/wnd/wndclass/guiobjwnd.h>
  4. #include <api/script/objects/c_script/h_guiobject.h>
  5. #include <api/script/objects/c_script/h_button.h>
  6. #define CHECKBOX_PARENT GuiObjectWnd
  7. class TextClicks;
  8. class ToggleClicks;
  9. /**
  10. Class
  11. @short
  12. @author Nullsoft
  13. @ver 1.0
  14. @see
  15. */
  16. class CheckBox : public CHECKBOX_PARENT {
  17. public:
  18. CheckBox(const wchar_t *_text = L"ERROR", const wchar_t *_radioid = NULL);
  19. virtual ~CheckBox();
  20. /**
  21. Method
  22. @see
  23. @ret
  24. @param
  25. */
  26. virtual int onInit();
  27. /**
  28. Method
  29. @see
  30. @ret
  31. @param
  32. */
  33. virtual int getPreferences(int what);
  34. /**
  35. Method
  36. @see
  37. @ret
  38. @param
  39. */
  40. void toggle(int self_switch); // this is called by the click catchers.
  41. /**
  42. Method
  43. @see
  44. @ret
  45. @param
  46. */
  47. void setActivated(int activated, int writetocfg=1);
  48. /**
  49. Method
  50. @see
  51. @ret
  52. @param
  53. */
  54. int isActivated();
  55. /**
  56. Method
  57. @see
  58. @ret
  59. @param
  60. */
  61. void setText(const wchar_t *_text);
  62. const wchar_t *getText();
  63. void setRadioid(const wchar_t *_radioid);
  64. const wchar_t *getRadioid() { return radioid; }
  65. void setRadioVal(const wchar_t *val, int use_radioval=TRUE);
  66. const wchar_t *getRadioVal() { return radioval; }
  67. #ifdef WASABI_COMPILE_CONFIG
  68. /**
  69. Method
  70. @see
  71. @ret
  72. @param
  73. */
  74. virtual int onReloadConfig();
  75. #endif
  76. /**
  77. Method
  78. @see
  79. @ret
  80. @param
  81. */
  82. virtual void onNewContent();
  83. virtual int wantFocus() { return 1; }
  84. virtual int onChar(unsigned int c);
  85. virtual void setAction(const wchar_t *str);
  86. virtual void setActionTarget(const wchar_t *target);
  87. virtual void setActionParam(const wchar_t *param);
  88. virtual const wchar_t *getActionParam();
  89. protected:
  90. virtual void onToggle(); //override to catch toggles
  91. private:
  92. void doAction();
  93. /**
  94. Method
  95. @see
  96. @ret
  97. @param
  98. */
  99. void updateText();
  100. TextClicks *textclicks;
  101. ToggleClicks *toggleclicks;
  102. StringW text;
  103. StringW radioid;
  104. GuiObject *buttonGuiObj;
  105. StringW radioval;
  106. int use_radioval;
  107. StringW action, action_target, action_param;
  108. };
  109. /**
  110. Class
  111. @short
  112. @author Nullsoft
  113. @ver 1.0
  114. @see
  115. */
  116. class TextClicks : public H_GuiObject {
  117. public:
  118. /**
  119. Method
  120. @see
  121. @ret
  122. @param
  123. */
  124. TextClicks(ScriptObject *textobj, CheckBox *_callback) :
  125. /**
  126. Method
  127. @see
  128. @ret
  129. @param
  130. */
  131. callback(_callback), H_GuiObject(textobj) {
  132. }
  133. /**
  134. Method
  135. @see
  136. @ret
  137. @param
  138. */
  139. virtual void hook_onLeftButtonDown(int x, int y) {
  140. callback->toggle(0);
  141. }
  142. private:
  143. CheckBox *callback;
  144. };
  145. /**
  146. Class
  147. @short
  148. @author Nullsoft
  149. @ver 1.0
  150. @see
  151. */
  152. class ToggleClicks : public H_Button {
  153. public:
  154. /**
  155. Method
  156. @see
  157. @ret
  158. @param
  159. */
  160. ToggleClicks(ScriptObject *button, CheckBox *_callback) :
  161. /**
  162. Method
  163. @see
  164. @ret
  165. @param
  166. */
  167. callback(_callback), H_Button(button) {
  168. inhere=0;
  169. }
  170. /**
  171. Method
  172. @see
  173. @ret
  174. @param
  175. */
  176. virtual void hook_onActivate(int activate) {
  177. if (inhere) return;
  178. inhere=1;
  179. callback->toggle(1);
  180. inhere=0;
  181. }
  182. private:
  183. CheckBox *callback;
  184. int inhere;
  185. };
  186. #endif