spopup.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include <precomp.h>
  2. #include <api/script/objects/spopup.h>
  3. #include <api/script/scriptmgr.h>
  4. SPopup::SPopup() {
  5. getScriptObject()->vcpu_setInterface(popupGuid, (void *)static_cast<SPopup*>(this));
  6. getScriptObject()->vcpu_setClassName(L"Popup");
  7. getScriptObject()->vcpu_setController(popupController);
  8. }
  9. SPopup::~SPopup() {
  10. }
  11. PopupScriptController _popupController;
  12. PopupScriptController *popupController = &_popupController;
  13. // -- Functions table -------------------------------------
  14. function_descriptor_struct PopupScriptController::exportedFunction[] = {
  15. {L"addSubMenu", 2, (void*)SPopup::script_vcpu_addSubMenu },
  16. {L"addCommand", 4, (void*)SPopup::script_vcpu_addCommand },
  17. {L"addSeparator", 0, (void*)SPopup::script_vcpu_addSeparator },
  18. {L"popAtXY", 2, (void*)SPopup::script_vcpu_popAtXY },
  19. {L"popAtMouse", 0, (void*)SPopup::script_vcpu_popAtMouse },
  20. {L"getNumCommands", 0, (void*)SPopup::script_vcpu_getNumCommands },
  21. {L"checkCommand", 2, (void*)SPopup::script_vcpu_checkCommand },
  22. {L"disableCommand", 2, (void*)SPopup::script_vcpu_disableCommand },
  23. //todo: events
  24. };
  25. // --------------------------------------------------------
  26. const wchar_t *PopupScriptController::getClassName() {
  27. return L"Popup";
  28. }
  29. const wchar_t *PopupScriptController::getAncestorClassName() {
  30. return L"Object";
  31. }
  32. ScriptObject *PopupScriptController::instantiate() {
  33. SPopup *p = new SPopup;
  34. ASSERT(p != NULL);
  35. return p->getScriptObject();
  36. }
  37. void PopupScriptController::destroy(ScriptObject *o) {
  38. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  39. ASSERT(p != NULL);
  40. delete p;
  41. }
  42. void *PopupScriptController::encapsulate(ScriptObject *o) {
  43. return NULL; // no encapsulation for popups yet
  44. }
  45. void PopupScriptController::deencapsulate(void *o) {
  46. }
  47. int PopupScriptController::getNumFunctions() {
  48. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  49. }
  50. const function_descriptor_struct *PopupScriptController::getExportedFunctions() {
  51. return exportedFunction;
  52. }
  53. GUID PopupScriptController::getClassGuid() {
  54. return popupGuid;
  55. }
  56. // -----------------------------------------------------------------------
  57. scriptVar SPopup::script_vcpu_addSubMenu(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar popup, scriptVar str)
  58. {
  59. SCRIPT_FUNCTION_INIT;
  60. ASSERT(str.type == SCRIPT_STRING); // compiler discarded
  61. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  62. SPopup *p2 = static_cast<SPopup *>(GET_SCRIPT_OBJECT_AS(popup, popupGuid));
  63. if (p) p->addSubMenu(p2, GET_SCRIPT_STRING(str));
  64. RETURN_SCRIPT_VOID;
  65. }
  66. scriptVar SPopup::script_vcpu_addCommand(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar str, scriptVar cmd, scriptVar checked, scriptVar disabled) {
  67. SCRIPT_FUNCTION_INIT;
  68. ASSERT(str.type == SCRIPT_STRING); // compiler discarded
  69. ASSERT(SOM::isNumeric(&cmd)); // compiler discarded
  70. ASSERT(SOM::isNumeric(&checked)); // compiler discarded
  71. ASSERT(SOM::isNumeric(&disabled)); // compiler discarded
  72. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  73. if (p)
  74. p->addCommand(str.data.sdata, SOM::makeInt(&cmd), SOM::makeBoolean(&checked), SOM::makeBoolean(&disabled));
  75. RETURN_SCRIPT_VOID;
  76. }
  77. scriptVar SPopup::script_vcpu_addSeparator(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  78. SCRIPT_FUNCTION_INIT;
  79. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  80. if (p) p->addSeparator();
  81. RETURN_SCRIPT_VOID;
  82. }
  83. scriptVar SPopup::script_vcpu_checkCommand(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar i, scriptVar check) {
  84. SCRIPT_FUNCTION_INIT;
  85. ASSERT(SOM::isNumeric(&i));
  86. ASSERT(SOM::isNumeric(&check));
  87. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  88. if (p) p->checkCommand(SOM::makeInt(&i), SOM::makeBoolean(&check));
  89. RETURN_SCRIPT_VOID;
  90. }
  91. scriptVar SPopup::script_vcpu_disableCommand(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar i, scriptVar disable) {
  92. SCRIPT_FUNCTION_INIT;
  93. ASSERT(SOM::isNumeric(&i));
  94. ASSERT(SOM::isNumeric(&disable));
  95. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  96. if (p) p->disableCommand(SOM::makeInt(&i), SOM::makeBoolean(&disable));
  97. RETURN_SCRIPT_VOID;
  98. }
  99. scriptVar SPopup::script_vcpu_popAtXY(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar x, scriptVar y) {
  100. SCRIPT_FUNCTION_INIT;
  101. ASSERT(SOM::isNumeric(&x));
  102. ASSERT(SOM::isNumeric(&y));
  103. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  104. if (p) return MAKE_SCRIPT_INT(p->popAtXY(SOM::makeInt(&x), SOM::makeInt(&y)));
  105. RETURN_SCRIPT_ZERO;
  106. }
  107. scriptVar SPopup::script_vcpu_popAtMouse(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  108. SCRIPT_FUNCTION_INIT;
  109. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  110. if (p) return MAKE_SCRIPT_INT(p->popAtMouse());
  111. RETURN_SCRIPT_ZERO;
  112. }
  113. scriptVar SPopup::script_vcpu_getNumCommands(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  114. SCRIPT_FUNCTION_INIT;
  115. SPopup *p = static_cast<SPopup *>(o->vcpu_getInterface(popupGuid));
  116. if (p) return MAKE_SCRIPT_INT(p->getNumCommands());
  117. RETURN_SCRIPT_ZERO;
  118. }