1
0

embeddedxui.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "precomp.h"
  2. #include "embeddedxui.h"
  3. EmbeddedXuiObject::EmbeddedXuiObject() {
  4. embedded = NULL;
  5. myxuihandle = newXuiHandle();
  6. getScriptObject()->vcpu_setInterface(embeddedXuiGuid, (void *)static_cast<EmbeddedXuiObject *>(this));
  7. getScriptObject()->vcpu_setClassName(L"ObjectEmbedded"); // this is the script class name
  8. getScriptObject()->vcpu_setController(embeddedXuiController);
  9. }
  10. EmbeddedXuiObject::~EmbeddedXuiObject() {
  11. paramlist.deleteAll();
  12. }
  13. void EmbeddedXuiObject::onNewContent() {
  14. embeddedxui_onNewEmbeddedContent();
  15. }
  16. void EmbeddedXuiObject::embeddedxui_onNewEmbeddedContent() {
  17. embedded = NULL;
  18. const wchar_t *id = embeddedxui_getEmbeddedObjectId();
  19. if (id != NULL && *id) {
  20. GuiObject *myself = getGuiObject();
  21. embedded = myself->guiobject_findObject(id);
  22. if (embedded != NULL && embedded != myself) {
  23. foreach(paramlist)
  24. EmbeddedXuiObjectParam *p = paramlist.getfor();
  25. embedded->guiobject_setXmlParam(p->param, p->value);
  26. endfor;
  27. #ifdef WASABI_COMPILE_CONFIG
  28. syncCfgAttrib();
  29. #endif
  30. }
  31. }
  32. }
  33. int EmbeddedXuiObject::onUnknownXuiParam(const wchar_t *xmlattributename, const wchar_t *value) {
  34. int r = EMBEDDEDXUIOBJECT_PARENT::onUnknownXuiParam(xmlattributename, value);
  35. paramlist.addItem(new EmbeddedXuiObjectParam(xmlattributename, value));
  36. if (embedded)
  37. r = embedded->guiobject_setXmlParam(xmlattributename, value);
  38. return r;
  39. }
  40. int EmbeddedXuiObject::onInit()
  41. {
  42. int r = EMBEDDEDXUIOBJECT_PARENT::onInit();
  43. const wchar_t *id = embeddedxui_getContentId();
  44. if (id != NULL && *id)
  45. setContent(id);
  46. return r;
  47. }
  48. #ifdef WASABI_COMPILE_CONFIG
  49. int EmbeddedXuiObject::onReloadConfig() {
  50. int r = EMBEDDEDXUIOBJECT_PARENT::onReloadConfig();
  51. syncCfgAttrib();
  52. return r;
  53. }
  54. #endif
  55. #ifdef WASABI_COMPILE_CONFIG
  56. void EmbeddedXuiObject::syncCfgAttrib()
  57. {
  58. if (embedded == NULL) return;
  59. CfgItem *item = getGuiObject()->guiobject_getCfgItem();
  60. const wchar_t *attrib = getGuiObject()->guiobject_getCfgAttrib();
  61. if (item != embedded->guiobject_getCfgItem() ||
  62. attrib != embedded->guiobject_getCfgAttrib()) {
  63. embedded->guiobject_setCfgAttrib(item, attrib);
  64. }
  65. }
  66. #endif
  67. // -----------------------------------------------------------------------
  68. // Script Object
  69. EmbeddedXuiScriptController _embeddedXuiController;
  70. EmbeddedXuiScriptController *embeddedXuiController = &_embeddedXuiController;
  71. // -- Functions table -------------------------------------
  72. function_descriptor_struct EmbeddedXuiScriptController::exportedFunction[] = {
  73. {L"getEmbeddedObject", 0, (void*)EmbeddedXuiScriptController::EmbeddedXui_getEmbeddedObject},
  74. };
  75. ScriptObject *EmbeddedXuiScriptController::instantiate() {
  76. EmbeddedXuiObject *ex = new EmbeddedXuiObject;
  77. ASSERT(ex != NULL);
  78. return ex->getScriptObject();
  79. }
  80. void EmbeddedXuiScriptController::destroy(ScriptObject *o) {
  81. EmbeddedXuiObject *ex= static_cast<EmbeddedXuiObject *>(o->vcpu_getInterface(embeddedXuiGuid));
  82. ASSERT(ex != NULL);
  83. delete ex;
  84. }
  85. void *EmbeddedXuiScriptController::encapsulate(ScriptObject *o) {
  86. return NULL; // no encapsulation for DropDownlist yet
  87. }
  88. void EmbeddedXuiScriptController::deencapsulate(void *o) {
  89. }
  90. int EmbeddedXuiScriptController::getNumFunctions() {
  91. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  92. }
  93. const function_descriptor_struct *EmbeddedXuiScriptController::getExportedFunctions() {
  94. return exportedFunction;
  95. }
  96. scriptVar EmbeddedXuiScriptController::EmbeddedXui_getEmbeddedObject(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  97. SCRIPT_FUNCTION_INIT
  98. EmbeddedXuiObject *ex = static_cast<EmbeddedXuiObject*>(o->vcpu_getInterface(embeddedXuiGuid));
  99. ScriptObject *_o = NULL;
  100. if (ex) {
  101. GuiObject *go = ex->embeddedxui_getEmbeddedObject();
  102. if (go != NULL)
  103. _o = go->guiobject_getScriptObject();
  104. }
  105. return MAKE_SCRIPT_OBJECT(_o);
  106. }
  107. ScriptObject *EmbeddedXuiScriptController::cast(ScriptObject *o, GUID g) {
  108. EmbeddedXuiObject *exo = static_cast<EmbeddedXuiObject *>(o->vcpu_getInterface(embeddedXuiGuid));
  109. if (!exo) return NULL;
  110. GuiObject *go = exo->embeddedxui_getEmbeddedObject();
  111. if (go != NULL) {
  112. ScriptObject *eo = go->guiobject_getScriptObject();
  113. if (eo != NULL) {
  114. void *i = eo->vcpu_getInterface(g);
  115. if (i != NULL)
  116. return eo;
  117. }
  118. }
  119. return NULL;
  120. }
  121. ScriptObjectController *EmbeddedXuiScriptController::getAncestorController() { return WASABI_API_MAKI->maki_getController(guiObjectGuid); }