1
0

xuicheckbox.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include <precomp.h>
  2. #include "xuicheckbox.h"
  3. #include <bfc/parse/paramparser.h>
  4. #include <api/script/objects/c_script/c_text.h>
  5. // -----------------------------------------------------------------------
  6. const wchar_t ScriptCheckBoxXuiObjectStr[] = L"Wasabi:CheckBox"; // This is the xml tag
  7. char ScriptCheckBoxXuiSvcName[] = "Wasabi:CheckBox xui object";
  8. XMLParamPair ScriptCheckBox::params[] = {
  9. {SCRIPTCHECKBOX_ACTION, L"ACTION"},
  10. {SCRIPTCHECKBOX_ACTIONTARGET, L"ACTION_TARGET"},
  11. {SCRIPTCHECKBOX_ACTIONPARAM, L"PARAM"},
  12. {SCRIPTCHECKBOX_RADIOID, L"RADIOID"},
  13. {SCRIPTCHECKBOX_RADIOVAL, L"RADIOVAL"},
  14. {SCRIPTCHECKBOX_TEXT, L"TEXT"},
  15. };
  16. // -----------------------------------------------------------------------
  17. ScriptCheckBox::ScriptCheckBox() : SCRIPTCHECKBOX_PARENT() {
  18. getScriptObject()->vcpu_setInterface(checkBoxGuid, (void *)static_cast<ScriptCheckBox*>(this));
  19. getScriptObject()->vcpu_setClassName(L"CheckBox"); // this is the script class name
  20. getScriptObject()->vcpu_setController(checkBoxController);
  21. myxuihandle = newXuiHandle();
  22. CreateXMLParameters(myxuihandle);
  23. }
  24. void ScriptCheckBox::CreateXMLParameters(int master_handle)
  25. {
  26. //SCRIPTCHECKBOX_PARENT::CreateXMLParameters(master_handle);
  27. int numParams = sizeof(params) / sizeof(params[0]);
  28. hintNumberOfParams(myxuihandle, numParams);
  29. for (int i = 0;i < numParams;i++)
  30. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  31. }
  32. // -----------------------------------------------------------------------
  33. ScriptCheckBox::~ScriptCheckBox() {
  34. }
  35. // -----------------------------------------------------------------------
  36. int ScriptCheckBox::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  37. if (xuihandle != myxuihandle)
  38. return SCRIPTCHECKBOX_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  39. // Parcel the values out to the window object we multiply inherit from
  40. switch (xmlattributeid) {
  41. case SCRIPTCHECKBOX_TEXT:
  42. setText(value);
  43. break;
  44. case SCRIPTCHECKBOX_RADIOID:
  45. setRadioid(value);
  46. break;
  47. case SCRIPTCHECKBOX_RADIOVAL:
  48. setRadioVal(value);
  49. break;
  50. case SCRIPTCHECKBOX_ACTION:
  51. setAction(value);
  52. break;
  53. case SCRIPTCHECKBOX_ACTIONPARAM:
  54. setActionParam(value);
  55. break;
  56. case SCRIPTCHECKBOX_ACTIONTARGET:
  57. setActionTarget(value);
  58. break;
  59. default:
  60. return 0;
  61. }
  62. return 1;
  63. }
  64. void ScriptCheckBox::onToggle() {
  65. SCRIPTCHECKBOX_PARENT::onToggle();
  66. Accessible *a = getAccessibleObject();
  67. if (a != NULL) {
  68. a->onStateChange();
  69. }
  70. CheckBoxController::onToggle(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_INT(isActivated()));
  71. }
  72. // -----------------------------------------------------------------------
  73. // Script Object
  74. CheckBoxController _checkBoxController;
  75. CheckBoxController *checkBoxController = &_checkBoxController;
  76. // -- Functions table -------------------------------------
  77. function_descriptor_struct CheckBoxController::exportedFunction[] = {
  78. {L"onToggle", 1, (void*)CheckBoxController::onToggle},
  79. {L"setChecked", 1, (void*)CheckBoxController::setChecked},
  80. {L"isChecked", 0, (void*)CheckBoxController::isChecked},
  81. {L"setText", 1, (void*)CheckBoxController::setText},
  82. {L"getText", 0, (void*)CheckBoxController::getText},
  83. };
  84. ScriptObject *CheckBoxController::instantiate() {
  85. ScriptCheckBox *sb = new ScriptCheckBox;
  86. ASSERT(sb != NULL);
  87. return sb->getScriptObject();
  88. }
  89. void CheckBoxController::destroy(ScriptObject *o) {
  90. ScriptCheckBox *sb = static_cast<ScriptCheckBox *>(o->vcpu_getInterface(checkBoxGuid));
  91. ASSERT(sb != NULL);
  92. delete sb;
  93. }
  94. void *CheckBoxController::encapsulate(ScriptObject *o) {
  95. return NULL; // no encapsulation for checkboxes yet
  96. }
  97. void CheckBoxController::deencapsulate(void *o) {
  98. }
  99. int CheckBoxController::getNumFunctions() {
  100. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  101. }
  102. const function_descriptor_struct *CheckBoxController::getExportedFunctions() {
  103. return exportedFunction;
  104. }
  105. scriptVar CheckBoxController::onToggle(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar newstate) {
  106. SCRIPT_FUNCTION_INIT
  107. PROCESS_HOOKS1(o, checkBoxController, newstate);
  108. SCRIPT_FUNCTION_CHECKABORTEVENT;
  109. SCRIPT_EXEC_EVENT1(o, newstate);
  110. }
  111. scriptVar CheckBoxController::setChecked(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar state) {
  112. SCRIPT_FUNCTION_INIT
  113. ScriptCheckBox *sb = static_cast<ScriptCheckBox *>(o->vcpu_getInterface(checkBoxGuid));
  114. if (sb) sb->setActivated(GET_SCRIPT_INT(state));
  115. RETURN_SCRIPT_VOID;
  116. }
  117. scriptVar CheckBoxController::isChecked(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  118. SCRIPT_FUNCTION_INIT
  119. int a = 0;
  120. ScriptCheckBox *sb = static_cast<ScriptCheckBox *>(o->vcpu_getInterface(checkBoxGuid));
  121. if (sb) a = sb->isActivated();
  122. return MAKE_SCRIPT_INT(a);
  123. }
  124. scriptVar CheckBoxController::setText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar text) {
  125. SCRIPT_FUNCTION_INIT
  126. ScriptCheckBox *sb = static_cast<ScriptCheckBox *>(o->vcpu_getInterface(checkBoxGuid));
  127. if (sb)
  128. sb->setText(GET_SCRIPT_STRING(text));
  129. RETURN_SCRIPT_VOID;
  130. }
  131. scriptVar CheckBoxController::getText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  132. SCRIPT_FUNCTION_INIT
  133. ScriptCheckBox *sb = static_cast<ScriptCheckBox *>(o->vcpu_getInterface(checkBoxGuid));
  134. if (sb)
  135. {
  136. return MAKE_SCRIPT_STRING(sb->getText());
  137. }
  138. return MAKE_SCRIPT_STRING(L"");
  139. }