1
0

grouptgbutton.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <precomp.h>
  2. #include "grouptgbutton.h"
  3. #include <api/script/objects/guiobject.h>
  4. #include <api/wnd/notifmsg.h>
  5. GroupToggleButton::GroupToggleButton() {
  6. status = STATUS_OFF;
  7. }
  8. GroupToggleButton::~GroupToggleButton() {
  9. }
  10. void GroupToggleButton::setGroups(const wchar_t *_on, const wchar_t *_off) {
  11. on_id = _on;
  12. on.setContent(on_id);
  13. off_id = _off;
  14. off.setContent(off_id);
  15. }
  16. int GroupToggleButton::onInit() {
  17. int rt = GROUPTOGGLEBUTTON_PARENT::onInit();
  18. initGroups();
  19. return rt;
  20. }
  21. void GroupToggleButton::initGroups() {
  22. on.setStartHidden(status == STATUS_ON ? 0 : 1); off.setStartHidden(status == STATUS_ON ? 1 : 0);
  23. on.setContent(on_id);
  24. off.setContent(off_id);
  25. on.setParent(this); off.setParent(this);
  26. on.init(this); off.init(this);
  27. rootwndholder_setRootWnd(status == STATUS_ON ? &on : &off);
  28. }
  29. int GroupToggleButton::childNotify(ifc_window *child, int msg, intptr_t param1, intptr_t param2) {
  30. if (child == &on || child == &off) {
  31. switch (msg) {
  32. case ChildNotify::BUTTON_LEFTPUSH: {
  33. if (wantFullClick()) grouptoggle_onLeftPush();
  34. return 1;
  35. }
  36. case ChildNotify::BUTTON_RIGHTPUSH: {
  37. if (wantFullClick()) grouptoggle_onRightPush();
  38. return 1;
  39. }
  40. case ChildNotify::CLICKWND_LEFTDOWN: {
  41. if (!wantFullClick()) grouptoggle_onLeftPush();
  42. return 1;
  43. }
  44. case ChildNotify::CLICKWND_RIGHTDOWN: {
  45. if (!wantFullClick()) grouptoggle_onRightPush();
  46. return 1;
  47. }
  48. }
  49. }
  50. return GROUPTOGGLEBUTTON_PARENT::childNotify(child, msg, param1, param2);
  51. }
  52. void GroupToggleButton::toggle() {
  53. if (status == STATUS_OFF) {
  54. if (isInited()) {
  55. off.setVisible(0);
  56. on.setVisible(1);
  57. rootwndholder_setRootWnd(&on);
  58. }
  59. status = STATUS_ON;
  60. } else {
  61. if (isInited()) {
  62. on.setVisible(0);
  63. off.setVisible(1);
  64. rootwndholder_setRootWnd(&off);
  65. }
  66. status = STATUS_OFF;
  67. }
  68. notifyParent(ChildNotify::GROUPCLICKTGBUTTON_TOGGLE, status);
  69. }
  70. void GroupToggleButton::setStatus(int s) {
  71. if (s != status)
  72. toggle();
  73. }
  74. int GroupToggleButton::wantFullClick() {
  75. return 0;
  76. }
  77. void GroupToggleButton::grouptoggle_onLeftPush() {
  78. notifyParent(ChildNotify::GROUPCLICKTGBUTTON_CLICKED);
  79. if (!wantAutoToggle()) return;
  80. if (status == STATUS_ON && !off_id.isempty() || status == STATUS_OFF && !on_id.isempty())
  81. toggle();
  82. }
  83. void GroupToggleButton::grouptoggle_onRightPush() {
  84. }
  85. GroupClickWnd *GroupToggleButton::enumGroups(int n) {
  86. if (n == 0) return &on;
  87. if (n == 1) return &off;
  88. return NULL;
  89. }
  90. int GroupToggleButton::getNumGroups() {
  91. int i=0;
  92. i++;
  93. i++;
  94. return i;
  95. }