1
0

xuiwndholder.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #include <precomp.h>
  2. #include "xuiwndholder.h"
  3. #include <tataki/canvas/ifc_canvas.h>
  4. #include <bfc/parse/paramparser.h>
  5. #include <api/script/objects/sregion.h>
  6. // -----------------------------------------------------------------------
  7. const wchar_t WindowHolderXuiObjectStr[] = L"WindowHolder"; // This is the xml tag
  8. const wchar_t WindowHolderXuiObjectStrCompat[] = L"Component"; // This is the old xml tag
  9. char WindowHolderXuiSvcName[] = "WindowHolder xui object";
  10. char WindowHolderXuiSvcNameCompat[] = "Component xui object";
  11. // {7DB51C8C-36C0-4585-9240-A2DB22B1B8F7}
  12. static const GUID pvt_xuiWindowHolder =
  13. { 0x7db51c8c, 0x36c0, 0x4585, { 0x92, 0x40, 0xa2, 0xdb, 0x22, 0xb1, 0xb8, 0xf7 } };
  14. XMLParamPair XuiWindowHolder::params[] = {
  15. {XUIWNDHOLDER_ADDHOLD, L"PARAM"},
  16. {XUIWNDHOLDER_ADDHOLD, L"COMPONENT"},
  17. {XUIWNDHOLDER_ADDHOLD, L"HOLD"},
  18. {XUIWNDHOLDER_SETNOSHOWCMDBAR, L"NOSHOWCMDBAR"},
  19. {XUIWNDHOLDER_SETNOANIMRECTS, L"NOANIMATEDRECTS"},
  20. {XUIWNDHOLDER_SETNOANIMRECTS, L"DISABLEANIMATEDRECTS"},
  21. {XUIWNDHOLDER_SETAUTOOPEN, L"AUTOOPEN"},
  22. {XUIWNDHOLDER_SETAUTOCLOSE, L"AUTOCLOSE"},
  23. {XUIWNDHOLDER_SETAUTOFOCUS, L"AUTOFOCUS"},
  24. {XUIWNDHOLDER_SETAUTOAVAILABLE, L"AUTOAVAILABLE"},
  25. };
  26. // -----------------------------------------------------------------------
  27. XuiWindowHolder::XuiWindowHolder() {
  28. getScriptObject()->vcpu_setInterface(windowHolderGuid, (void *)static_cast<WindowHolder *>(this));
  29. getScriptObject()->vcpu_setInterface(pvt_xuiWindowHolder, (void *)static_cast<XuiWindowHolder *>(this));
  30. getScriptObject()->vcpu_setClassName(L"WindowHolder"); // this is the script class name
  31. getScriptObject()->vcpu_setController(windowHolderController);
  32. myxuihandle = newXuiHandle();
  33. CreateXMLParameters(myxuihandle);
  34. setXmlParam(L"autofocus", L"1");
  35. }
  36. void XuiWindowHolder::CreateXMLParameters(int master_handle)
  37. {
  38. //XUIWNDHOLDER_PARENT::CreateXMLParameters(master_handle);
  39. int numParams = sizeof(params) / sizeof(params[0]);
  40. hintNumberOfParams(myxuihandle, numParams);
  41. for (int i = 0;i < numParams;i++)
  42. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  43. }
  44. XuiWindowHolder::~XuiWindowHolder() {
  45. }
  46. void XuiWindowHolder::setRegionFromMap(ScriptObject *map, int byte, int inverse) {
  47. }
  48. void XuiWindowHolder::setRegion(ScriptObject *_region) {
  49. //#pragma CHAT("bas", "lone", "I implemented setRegion for ya once SRegion is safe")
  50. #if 1// if SRegion were cross-dll safe this would work
  51. const GUID regionGuid =
  52. { 0x3a370c02, 0x3cbf, 0x439f, { 0x84, 0xf1, 0x86, 0x88, 0x5b, 0xcf, 0x1e, 0x36 } };
  53. void *reg = _region->vcpu_getInterface(regionGuid);
  54. ASSERT(reg != NULL);
  55. SRegion *sr = static_cast<SRegion*>(reg);
  56. ASSERT(sr != NULL);
  57. api_region *region = sr->getRegion();
  58. ASSERT(region != NULL);
  59. api_region *clone = region->clone();
  60. clone->scale(getRenderRatio(), getRenderRatio());
  61. ifc_window *curRootWnd = getCurRootWnd();
  62. if (curRootWnd)
  63. {
  64. #ifdef _WIN32
  65. OSWINDOWHANDLE osWnd = curRootWnd->gethWnd();
  66. if (osWnd)
  67. SetWindowRgn(osWnd, clone->makeWindowRegion(), TRUE);
  68. #else
  69. #warning port me
  70. // can probably use a mask here
  71. #endif
  72. }
  73. region->disposeClone(clone);
  74. #endif
  75. }
  76. // -----------------------------------------------------------------------
  77. int XuiWindowHolder::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  78. if (xuihandle != myxuihandle)
  79. return XUIWNDHOLDER_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  80. switch (xmlattributeid)
  81. {
  82. case XUIWNDHOLDER_ADDHOLD:
  83. if (!WCSICMP(value, L"@ALL@") || !WCSICMP(value, L"guid:default"))
  84. {
  85. setAcceptAllGuids(1);
  86. setAcceptAllGroups(1);
  87. } else {
  88. setAcceptAllGuids(0);
  89. setAcceptAllGroups(0);
  90. ParamParser pp(value);
  91. for (int i=0;i<pp.getNumItems();i++) {
  92. const wchar_t *e = pp.enumItem(i);
  93. if (*e == '{' || !WCSNICMP(e, L"guid:", 5)) {
  94. GUID *g = parseGUID(e);
  95. if (g)
  96. addAcceptGuid(*g);
  97. }
  98. else
  99. addAcceptGroup(e);
  100. }
  101. }
  102. break;
  103. case XUIWNDHOLDER_SETNOSHOWCMDBAR:
  104. setNoCmdBar(WTOI(value));
  105. break;
  106. case XUIWNDHOLDER_SETNOANIMRECTS:
  107. setNoAnim(WTOI(value));
  108. break;
  109. case XUIWNDHOLDER_SETAUTOOPEN:
  110. setAutoOpen(WTOI(value));
  111. break;
  112. case XUIWNDHOLDER_SETAUTOCLOSE:
  113. setAutoClose(WTOI(value));
  114. break;
  115. case XUIWNDHOLDER_SETAUTOFOCUS:
  116. setAutoFocus(WTOI(value));
  117. break;
  118. case XUIWNDHOLDER_SETAUTOAVAILABLE:
  119. setAutoAvailable(WTOI(value));
  120. break;
  121. default:
  122. return 0;
  123. }
  124. return 1;
  125. }
  126. GUID *XuiWindowHolder::parseGUID(const wchar_t *id) {
  127. if (WCSNICMP(id, L"guid:{",6)==0) {
  128. static GUID g;
  129. id+=5;
  130. g = nsGUID::fromCharW(id);
  131. return &g;
  132. }
  133. if (id && *id == '{') {
  134. static GUID g;
  135. g = nsGUID::fromCharW(id);
  136. return &g;
  137. }
  138. if(WCSICMP(id,L"guid:avs")==0) {
  139. static GUID g={ 10, 12, 16, { 255, 123, 1, 1, 66, 99, 69, 12 } };
  140. return &g;
  141. }
  142. if (WCSICMP(id,L"guid:pl")==0 || WCSICMP(id,L"guid:playlist")==0) {
  143. static GUID g={ 0x45f3f7c1, 0xa6f3, 0x4ee6, { 0xa1, 0x5e, 0x12, 0x5e, 0x92, 0xfc, 0x3f, 0x8d } };
  144. return &g;
  145. }
  146. if (WCSICMP(id,L"guid:ml")==0 || WCSICMP(id,L"guid:musiclibrary")==0 || WCSICMP(id,L"guid:library")==0) {
  147. static GUID g={ 0x6b0edf80, 0xc9a5, 0x11d3, { 0x9f, 0x26, 0x00, 0xc0, 0x4f, 0x39, 0xff, 0xc6 } };
  148. return &g;
  149. }
  150. if(WCSICMP(id,L"guid:null")==0) {
  151. static GUID g=INVALID_GUID;
  152. return &g;
  153. }
  154. if(WCSICMP(id,L"guid:player")==0) {
  155. static GUID g = { 0xe6323f86, 0x1724, 0x4cd3, { 0x9d, 0x87, 0x70, 0x59, 0x1f, 0xc1, 0x6e, 0x5e } };
  156. return &g;
  157. }
  158. return NULL;
  159. }
  160. // -----------------------------------------------------------------------
  161. // Script Object
  162. WindowHolderScriptController _windowHolderController;
  163. WindowHolderScriptController *windowHolderController = &_windowHolderController;
  164. // -- Functions table -------------------------------------
  165. function_descriptor_struct WindowHolderScriptController::exportedFunction[] = {
  166. {L"getGUID", 1, (void*)WindowHolderScriptController::script_getGUID },
  167. {L"setRegionFromMap", 3, (void*)WindowHolderScriptController::script_setRegionFromMap },
  168. {L"setRegion", 1, (void*)WindowHolderScriptController::script_setRegion },
  169. {L"getContent", 0, (void*)WindowHolderScriptController::script_getContent},
  170. {L"getComponentName", 0, (void*)WindowHolderScriptController::script_getComponentName},
  171. };
  172. ScriptObject *WindowHolderScriptController::instantiate() {
  173. XuiWindowHolder *wh = new XuiWindowHolder;
  174. ASSERT(wh != NULL);
  175. return wh->getScriptObject();
  176. }
  177. void WindowHolderScriptController::destroy(ScriptObject *o) {
  178. XuiWindowHolder *wh = static_cast<XuiWindowHolder *>(o->vcpu_getInterface(pvt_xuiWindowHolder));
  179. ASSERT(wh != NULL);
  180. delete wh;
  181. }
  182. void *WindowHolderScriptController::encapsulate(ScriptObject *o) {
  183. return NULL; // no encapsulation for windowholder yet
  184. }
  185. void WindowHolderScriptController::deencapsulate(void *o) {
  186. }
  187. int WindowHolderScriptController::getNumFunctions() {
  188. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  189. }
  190. const function_descriptor_struct *WindowHolderScriptController::getExportedFunctions() {
  191. return exportedFunction;
  192. }
  193. scriptVar WindowHolderScriptController::script_getComponentName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  194. {
  195. SCRIPT_FUNCTION_INIT
  196. XuiWindowHolder *wh = static_cast<XuiWindowHolder*>(o->vcpu_getInterface(pvt_xuiWindowHolder));
  197. if (wh)
  198. {
  199. ifc_window *ro = wh->getCurRootWnd();
  200. if (ro)
  201. {
  202. return MAKE_SCRIPT_STRING(ro->getRootWndName());
  203. }
  204. }
  205. return MAKE_SCRIPT_STRING(L"");
  206. }
  207. scriptVar WindowHolderScriptController::script_getGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  208. {
  209. SCRIPT_FUNCTION_INIT
  210. XuiWindowHolder *wh = static_cast<XuiWindowHolder*>(o->vcpu_getInterface(pvt_xuiWindowHolder));
  211. if (wh)
  212. {
  213. static wchar_t guidstr[256];
  214. nsGUID::toCharW(wh->getCurGuid(), guidstr);
  215. return MAKE_SCRIPT_STRING(guidstr);
  216. }
  217. return MAKE_SCRIPT_STRING(L"");
  218. }
  219. scriptVar WindowHolderScriptController::script_setRegionFromMap(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar map, scriptVar byte, scriptVar inv) {
  220. SCRIPT_FUNCTION_INIT
  221. XuiWindowHolder *xu = static_cast<XuiWindowHolder*>(o->vcpu_getInterface(pvt_xuiWindowHolder));
  222. if (xu) xu->setRegionFromMap(GET_SCRIPT_OBJECT(map), GET_SCRIPT_INT(byte), GET_SCRIPT_INT(inv));
  223. RETURN_SCRIPT_VOID;
  224. }
  225. scriptVar WindowHolderScriptController::script_setRegion(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar reg) {
  226. SCRIPT_FUNCTION_INIT
  227. XuiWindowHolder *xu= static_cast<XuiWindowHolder*>(o->vcpu_getInterface(pvt_xuiWindowHolder));
  228. if (xu) xu->setRegion(GET_SCRIPT_OBJECT(reg));
  229. RETURN_SCRIPT_VOID;
  230. }
  231. scriptVar WindowHolderScriptController::script_getContent(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  232. SCRIPT_FUNCTION_INIT
  233. XuiWindowHolder *xu= static_cast<XuiWindowHolder*>(o->vcpu_getInterface(pvt_xuiWindowHolder));
  234. if (xu) {
  235. ifc_window *w = xu->getRootWndPtr();
  236. if (w) {
  237. GuiObject *o = w->getGuiObject();
  238. if (o)
  239. return MAKE_SCRIPT_OBJECT(o->guiobject_getScriptObject());
  240. }
  241. }
  242. RETURN_SCRIPT_NULL;
  243. }