1
0

svcwnd.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #include "precomp.h"
  2. #include "../../bfc/std.h"
  3. #include "script.h"
  4. #include "scriptmgr.h"
  5. #include "../../bfc/notifmsg.h"
  6. #include "../../common/script/scriptobj.h"
  7. #include "compoobj.h"
  8. #include "../api.h"
  9. #include "vcpu.h"
  10. #include "../smap.h"
  11. #include "../skinparse.h"
  12. #include "svcwnd.h"
  13. #include "../services/services.h"
  14. #include "../services/servicei.h"
  15. #include "../svcmgr.h"
  16. #include "../services/svc_wndcreate.h"
  17. char svcWndXuiObjectStr[] = "SvcWnd"; // This is the xml tag
  18. char svcWndXuiSvcName[] = "SvcWnd xui object"; // this is the name of the xuiservice
  19. SvcWndScriptController _svcWndController;
  20. SvcWndScriptController *svcWndController = &_svcWndController;
  21. // -- Functions table -------------------------------------
  22. function_descriptor_struct SvcWndScriptController::exportedFunction[] = {
  23. {"getGUID", 1, (void*)SvcWnd::script_vcpu_getGUID },
  24. {"getWac", 0, (void*)SvcWnd::script_vcpu_getWac },
  25. };
  26. // --------------------------------------------------------
  27. const wchar_t *SvcWndScriptController::getClassName() {
  28. return L"SvcGuiObject";
  29. }
  30. const wchar_t *SvcWndScriptController::getAncestorClassName() {
  31. return "GuiObject";
  32. }
  33. int SvcWndScriptController::getNumFunctions() {
  34. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  35. }
  36. const function_descriptor_struct *SvcWndScriptController::getExportedFunctions() {
  37. return exportedFunction;
  38. }
  39. GUID SvcWndScriptController::getClassGuid() {
  40. return svcWndGuid;
  41. }
  42. ScriptObject *SvcWndScriptController::instantiate() {
  43. SvcWnd *sv = new SvcWnd();
  44. ASSERT(sv != NULL);
  45. return sv->getScriptObject();
  46. }
  47. void SvcWndScriptController::destroy(ScriptObject *o) {
  48. SvcWnd *obj = static_cast<SvcWnd*>(o->vcpu_getInterface(svcWndGuid));
  49. ASSERT(obj != NULL);
  50. delete obj;
  51. }
  52. void *SvcWndScriptController::encapsulate(ScriptObject *o) {
  53. return NULL; // no encapsulation for svcwnd yet
  54. }
  55. void SvcWndScriptController::deencapsulate(void *o) {
  56. }
  57. char SvcWndParams[][] =
  58. {
  59. "DBLCLICKACTION", //SVCWND_DBLCLKACTION
  60. "GUID" // SVCWND_GUID
  61. };
  62. SvcWnd::SvcWnd() {
  63. getScriptObject()->vcpu_setInterface(svcWndGuid, (void *)static_cast<SvcWnd*>(this));
  64. getScriptObject()->vcpu_setClassName("SvcGuiObject");
  65. getScriptObject()->vcpu_setController(svcWndController);
  66. myGUID = INVALID_GUID;
  67. svcwnd = NULL;
  68. svc = NULL;
  69. forwarded = 0;
  70. xuihandle = newXuiHandle();
  71. addParam(xuihandle, SvcWndParams[0], SVCWND_DBLCLKACTION, XUI_ATTRIBUTE_IMPLIED);
  72. addParam(xuihandle, SvcWndParams[1], SVCWND_GUID, XUI_ATTRIBUTE_IMPLIED);
  73. }
  74. // servicewnd to svcwnd
  75. int SvcWnd::childNotify(api_window *child, int msg, intptr_t param1, intptr_t param2) {
  76. if (child == svcwnd) {
  77. switch (msg) {
  78. case ChildNotify::SVCWND_LBUTTONDOWN:
  79. onLeftButtonDown(param1, param2);
  80. break;
  81. case ChildNotify::SVCWND_RBUTTONDOWN:
  82. onRightButtonDown(param1, param2);
  83. break;
  84. case ChildNotify::SVCWND_LBUTTONUP:
  85. onLeftButtonUp(param1, param2);
  86. break;
  87. case ChildNotify::SVCWND_RBUTTONUP:
  88. onRightButtonUp(param1, param2);
  89. break;
  90. case ChildNotify::SVCWND_LBUTTONDBLCLK:
  91. onLeftButtonDblClk(param1, param2);
  92. break;
  93. case ChildNotify::SVCWND_RBUTTONDBLCLK:
  94. onRightButtonDblClk(param1, param2);
  95. break;
  96. case ChildNotify::SVCWND_MOUSEMOVE:
  97. onMouseMove(param1, param2);
  98. break;
  99. }
  100. forwarded = 0;
  101. } else
  102. return SVCWND_PARENT::childNotify(child, msg, param1, param2);
  103. return 1;
  104. }
  105. // virtualwnd to guiobject bridging
  106. int SvcWnd::onLeftButtonDblClk(int x, int y) {
  107. if(!dblClickAction.isempty()) {
  108. const char *toCheck="SWITCH;";
  109. if(!STRNINCMP(dblClickAction,toCheck)) {
  110. onLeftButtonUp(x,y);
  111. getGuiObject()->guiobject_getParentGroup()->getParentContainer()->switchToLayout(dblClickAction.getValue()+STRLEN(toCheck));
  112. }
  113. }
  114. return SVCWND_PARENT::onLeftButtonDblClk(x, y);
  115. }
  116. int SvcWnd::onResize() {
  117. SVCWND_PARENT::onResize();
  118. RECT r = clientRect();
  119. if (svcwnd)
  120. svcwnd->resize(r.left, r.top, r.right-r.left, r.bottom-r.top);
  121. return 1;
  122. }
  123. void SvcWnd::onSetVisible(int v) {
  124. if (svcwnd) svcwnd->setVisible(v);
  125. SVCWND_PARENT::onSetVisible(v);
  126. }
  127. int SvcWnd::setXuiParam(int _xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  128. if (_xuihandle == xuihandle) {
  129. switch (xmlattributeid) {
  130. case SVCWND_GUID: {
  131. GUID *g;
  132. g = SkinParser::getComponentGuid(value);
  133. if (g)
  134. setGUID(*g);
  135. return 1;
  136. }
  137. case SVCWND_DBLCLKACTION:
  138. dblClickAction = value;
  139. return 1;
  140. }
  141. }
  142. return SVCWND_PARENT::setXuiParam(_xuihandle,xmlattributeid,xmlattributename,value);
  143. }
  144. int SvcWnd::onUnknownXuiParam(const wchar_t *param, const wchar_t *value) {
  145. params.addItem(new String(param));
  146. params.addItem(new String(value));
  147. return 0;
  148. }
  149. int SvcWnd::onInit() {
  150. int r = SVCWND_PARENT::onInit();
  151. WindowCreateByGuidEnum wce(getGUID());
  152. for (;;) {
  153. if (!svc)
  154. svc = wce.getNext();
  155. if (!svc) return 0;
  156. svcwnd = svc->createWindowByGuid(getGUID(), this);
  157. if (svcwnd != NULL) break;
  158. SvcEnum::release(svc); svc = NULL;
  159. }
  160. if (svcwnd != NULL)
  161. {
  162. svcwnd->setStartHidden(1);
  163. if (!svcwnd->isInited())
  164. r &= svcwnd->init(this);
  165. if (params.getNumItems() > 0) {
  166. for (int i=0;i<params.getNumItems();i+=2) {
  167. svcwnd->getGuiObject()->guiobject_setXmlParam(params[i]->getValue(), params[i+1]->getValue());
  168. }
  169. }
  170. }
  171. params.deleteAll();
  172. return r;
  173. }
  174. SvcWnd::~SvcWnd() {
  175. if (svc) {
  176. svc->destroyWindow(svcwnd);
  177. ServiceManager::release(svc);
  178. }
  179. }
  180. int SvcWnd::handleRatio() {
  181. return 1; // todo: ask window
  182. }
  183. void SvcWnd::setGUID(GUID g) {
  184. myGUID = g;
  185. }
  186. GUID SvcWnd::getGUID(void) {
  187. return myGUID;
  188. }
  189. int SvcWnd::getPreferences(int what) {
  190. if (svcwnd) return svcwnd->getPreferences(what);
  191. return SVCWND_PARENT::getPreferences(what);
  192. }
  193. scriptVar SvcWnd::script_vcpu_getGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  194. SCRIPT_FUNCTION_INIT;
  195. SvcWnd *s = static_cast<SvcWnd *>(o->vcpu_getInterface(svcWndGuid));
  196. if (s)
  197. return MAKE_SCRIPT_STRING(StringPrintf(s->myGUID));
  198. else
  199. return MAKE_SCRIPT_STRING("");
  200. }
  201. scriptVar SvcWnd::script_vcpu_getWac(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  202. SCRIPT_FUNCTION_INIT;
  203. SvcWnd *s = static_cast<SvcWnd *>(o->vcpu_getInterface(svcWndGuid));
  204. if (s) return MAKE_SCRIPT_OBJECT(SOM::getWACObject(s->getGUID())->getScriptObject());
  205. RETURN_SCRIPT_VOID;
  206. }