1
0

compoobj.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #include "precomp.h"
  2. #ifndef _NOSTUDIO
  3. #include "../../common/std.h"
  4. #include "script.h"
  5. #include "scriptmgr.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 "sregion.h"
  12. #include "../skinparse.h"
  13. #include "../compon.h"
  14. #include "../compwnd.h"
  15. #include "../cbmgr.h"
  16. #include "../smap.h"
  17. #include "../../common/wndcb.h"
  18. #else
  19. #include "compoobj.h"
  20. #endif
  21. CompoObjScriptController _compoController;
  22. CompoObjScriptController *compoController=&_compoController;
  23. // -- Functions table -------------------------------------
  24. function_descriptor_struct CompoObjScriptController::exportedFunction[] = {
  25. {"getGUID", 1, (void*)ComponentObject::script_vcpu_getGUID },
  26. {"getWac", 0, (void*)ComponentObject::script_vcpu_getWac },
  27. {"setRegionFromMap", 3, (void*)ComponentObject::script_vcpu_setRegionFromMap },
  28. {"setRegion", 1, (void*)ComponentObject::script_vcpu_setRegion },
  29. {"onGetWac", 1, (void*)ComponentObject::script_vcpu_onGetWac },
  30. {"onGiveUpWac", 1, (void*)ComponentObject::script_vcpu_onGiveUpWac },
  31. {"setAcceptWac", 1, (void*)ComponentObject::script_vcpu_setAcceptWac },
  32. };
  33. // --------------------------------------------------------
  34. const char *CompoObjScriptController::getClassName() {
  35. return "Component";
  36. }
  37. const wchar_t *CompoObjScriptController::getAncestorClassName() {
  38. return "GuiObject";
  39. }
  40. int CompoObjScriptController::getNumFunctions() {
  41. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  42. }
  43. const function_descriptor_struct *CompoObjScriptController::getExportedFunctions() {
  44. return exportedFunction;
  45. }
  46. GUID CompoObjScriptController::getClassGuid() {
  47. return componentObjectGuid;
  48. }
  49. ScriptObject *CompoObjScriptController::instantiate() {
  50. ComponentObject *obj = new ComponentObject();
  51. return obj->getScriptObject();
  52. }
  53. void CompoObjScriptController::destroy(ScriptObject *o) {
  54. ComponentObject *obj = static_cast<ComponentObject *>(o->vcpu_getInterface(componentObjectGuid));
  55. ASSERT(obj != NULL);
  56. delete obj;
  57. }
  58. void *CompoObjScriptController::encapsulate(ScriptObject *o) {
  59. return NULL; // no encapsulation for componentobject yet
  60. }
  61. void CompoObjScriptController::deencapsulate(void *) {
  62. }
  63. ComponentObject::ComponentObject() {
  64. getScriptObject()->vcpu_setInterface(componentObjectGuid, (void *)static_cast<ComponentObject *>(this));
  65. getScriptObject()->vcpu_setClassName("Component");
  66. getScriptObject()->vcpu_setController(compoController);
  67. deleting = 0;
  68. compwnd = NULL;
  69. noshowcmdbar = 0;
  70. noshowbtnbar = 0;
  71. MEMCPY(&myGUID, &INVALID_GUID, sizeof(GUID));
  72. MEMCPY(&myCompGuid, &INVALID_GUID, sizeof(GUID));
  73. my_region_clone = NULL;
  74. ComponentManager::registerComponentObject(this);
  75. autoopen = 0;
  76. autoclose = 0;
  77. accept = 1;
  78. denyDesktopAlpha = 0;
  79. denyTransparency = 0;
  80. noanimrects = 0;
  81. }
  82. int ComponentObject::setXmlParam(const char *name, const char *value) {
  83. if (COMPONENTOBJECT_PARENT::setXmlParam(name, value)) return 1;
  84. else if (STRCASEEQL(name, "param")) {
  85. GUID *g;
  86. g = SkinParser::getComponentGuid(value);
  87. if (g)
  88. setGUID(*g);
  89. } else if (STRCASEEQL(name, "noshowcmdbar")) {
  90. noshowcmdbar = WTOI(value);
  91. } else if (STRCASEEQL(name, "autoopen")) {
  92. autoopen = WTOI(value);
  93. } else if (STRCASEEQL(name, "autoclose")) {
  94. autoclose = WTOI(value);
  95. } else if (STRCASEEQL(name, "disableanimatedrects")) {
  96. noanimrects = WTOI(value);
  97. } else return 0;
  98. return 1;
  99. }
  100. ComponentObject::~ComponentObject() {
  101. deleting = 1;
  102. ComponentManager::unregisterComponentObject(this, 1);
  103. delete my_region_clone;
  104. }
  105. int ComponentObject::onResize() {
  106. COMPONENTOBJECT_PARENT::onResize();
  107. RECT r = clientRect();
  108. if (compwnd) {
  109. compwnd->resize(&r);
  110. }
  111. return 1;
  112. }
  113. int ComponentObject::handleRatio() {
  114. return compwnd ? compwnd->handleRatio() : 0;
  115. }
  116. void ComponentObject::setGUID(GUID g) {
  117. myGUID = g;
  118. }
  119. void ComponentObject::setCompGUID(GUID g) {
  120. myCompGuid = g;
  121. }
  122. GUID ComponentObject::getGUID(void) {
  123. if (!MEMCMP(&myCompGuid, &INVALID_GUID, sizeof(GUID)))
  124. return myGUID;
  125. else
  126. return myCompGuid;
  127. }
  128. void ComponentObject::script_resetRegion() {
  129. HWND h = ComponentManager::getComponentHWnd(myGUID);
  130. if (h) SetWindowRgn(h, NULL, TRUE);
  131. delete my_region_clone;
  132. my_region_clone = NULL;
  133. }
  134. void ComponentObject::script_setRegionFromMap(SMap *map, int byte, int inv) {
  135. RECT r={map->getBitmap()->getX(), map->getBitmap()->getY(), map->getBitmap()->getWidth(), map->getBitmap()->getHeight()};
  136. api_region *reg = new api_region(map->getBitmap(), &r, 0, 0, FALSE, 1, (unsigned char)byte, inv);
  137. if (!reg) { script_resetRegion(); return; }
  138. delete my_region_clone;
  139. my_region_clone = new api_region();
  140. my_region_clone->add(reg);
  141. delete reg;
  142. HWND h = ComponentManager::getComponentHWnd(myGUID);
  143. if (h) {
  144. api_region *clone = my_region_clone->clone();
  145. clone->scale(getRenderRatio());
  146. SetWindowRgn(h, clone->makeWindowRegion(), TRUE);
  147. my_region_clone->disposeClone(clone);
  148. }
  149. }
  150. void ComponentObject::script_setRegion(SRegion *r) {
  151. api_region *reg = r->getRegion();
  152. if (!reg) { script_resetRegion(); return; }
  153. delete my_region_clone;
  154. my_region_clone = new api_region();
  155. my_region_clone->add(reg);
  156. HWND h = ComponentManager::getComponentHWnd(myGUID);
  157. if (h) {
  158. api_region *clone = my_region_clone->clone();
  159. clone->scale(getRenderRatio());
  160. SetWindowRgn(h, clone->makeWindowRegion(), TRUE);
  161. my_region_clone->disposeClone(clone);
  162. }
  163. }
  164. void ComponentObject::onSetVisible(int s) {
  165. COMPONENTOBJECT_PARENT::onSetVisible(s);
  166. if (compwnd) {
  167. compwnd->setVisible(s);
  168. onResize();
  169. } else {
  170. if (s && autoopen && myGUID != INVALID_GUID && myGUID != GENERIC_GUID)
  171. api->setComponentVisible(myGUID, 1);
  172. }
  173. }
  174. void ComponentObject::deniedComponentCompWnd(CompWnd *c, GUID g) {
  175. if (!deleting) {
  176. Container *_c = getGuiObject()->guiobject_getParentGroup()->getParentContainer();
  177. if (_c) _c->resetGUID();
  178. }
  179. compwnd = c;
  180. compwnd->suppressStatusBar(noshowcmdbar);
  181. CallbackManager::issueCallback(SysCallback::WINDOW, WndCallback::HIDEWINDOW, reinterpret_cast<int>((int *)&g));
  182. onReleaseComponent();
  183. compwnd = NULL;
  184. denyDesktopAlpha = 0;
  185. denyTransparency = 0;
  186. if (!deleting) getGuiObject()->guiobject_getParentLayout()->onGuiObjectSetVisible(getGuiObject(), 0);
  187. }
  188. void ComponentObject::grantedComponentCompWnd(CompWnd *c, GUID g) {
  189. Container *_c = getGuiObject()->guiobject_getParentGroup()->getParentContainer();
  190. if (_c) _c->setGUID(g); // tells the container to change its script_id to id:{guid}
  191. compwnd = c;
  192. compwnd->suppressStatusBar(noshowcmdbar);
  193. onResize();
  194. if (isVisible())
  195. c->setVisible(1);
  196. CallbackManager::issueCallback(SysCallback::WINDOW, WndCallback::SHOWWINDOW, reinterpret_cast<int>((int *)&g));
  197. onGetComponent(g);
  198. }
  199. void ComponentObject::onReleaseComponent() {
  200. HWND h = ComponentManager::getComponentHWnd(myGUID);
  201. SetWindowRgn(h, NULL, FALSE);
  202. }
  203. void ComponentObject::onGetComponent(GUID g) {
  204. HWND h = ComponentManager::getComponentHWnd(myGUID);
  205. if (h) {
  206. if (my_region_clone) {
  207. api_region *clone = my_region_clone->clone();
  208. clone->scale(getRenderRatio());
  209. SetWindowRgn(h, clone->makeWindowRegion(), TRUE);
  210. my_region_clone->disposeClone(clone);
  211. } else
  212. SetWindowRgn(h, NULL, FALSE);
  213. }
  214. }
  215. int ComponentObject::wantGUID(GUID *g) {
  216. if (!accept || !getGuiObject()->guiobject_getParentGroup()) return 0;
  217. Container *_c = getGuiObject()->guiobject_getParentGroup()->getParentContainer();
  218. if (_c && _c->isDynamic() && compwnd) return 0;
  219. if (!MEMCMP(&myGUID, &GENERIC_GUID, sizeof(GUID))) return 1;
  220. return !MEMCMP(&myGUID, g, sizeof(GUID));
  221. }
  222. void ComponentObject::onBeforeGetWac(GUID g, CompWnd *c) {
  223. // if (!Std::isXPOrGreater())
  224. if (!c->handleDesktopAlpha())
  225. denyDesktopAlpha = 1;
  226. if (!c->handleTransparency())
  227. denyTransparency = 1;
  228. getGuiObject()->guiobject_getParentLayout()->onGuiObjectSetVisible(getGuiObject(), 1);
  229. WACObject *wo = SOM::getWACObject(g);
  230. script_vcpu_onGetWac(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(wo ? wo->getScriptObject() : NULL));
  231. }
  232. void ComponentObject::onBeforeGiveUpWac(GUID g, CompWnd *c) {
  233. WACObject *wo = SOM::getWACObject(g);
  234. script_vcpu_onGiveUpWac(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(wo ? wo->getScriptObject() : NULL));
  235. }
  236. int ComponentObject::getAutoClose() {
  237. return autoclose;
  238. }
  239. void ComponentObject::setAcceptWac(int a) {
  240. accept = a;
  241. }
  242. int ComponentObject::handleDesktopAlpha() {
  243. if (denyDesktopAlpha) return 0;
  244. if (!compwnd) return 1;
  245. return 0;
  246. }
  247. int ComponentObject::handleTransparency() {
  248. if (denyTransparency) return 0;
  249. if (!compwnd) return 1;
  250. return compwnd->handleTransparency();
  251. }
  252. int ComponentObject::getPreferences(int what) {
  253. if (compwnd) return compwnd->getPreferences(what);
  254. return COMPONENTOBJECT_PARENT::getPreferences(what);
  255. }
  256. scriptVar ComponentObject::script_vcpu_getGUID(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  257. SCRIPT_FUNCTION_INIT;
  258. OLECHAR oguid[256] = {0}; // NONPORTABLE
  259. ComponentObject *co = static_cast<ComponentObject *>(o->vcpu_getInterface(componentObjectGuid));
  260. if (co) {
  261. static char guid[256];
  262. StringFromGUID2(((ComponentObject *)o)->myGUID, oguid, 256);
  263. wsprintf(guid, "%$", oguid);
  264. return MAKE_SCRIPT_STRING(guid);
  265. }
  266. return MAKE_SCRIPT_STRING("");
  267. }
  268. scriptVar ComponentObject::script_vcpu_getWac(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  269. SCRIPT_FUNCTION_INIT; ;
  270. ComponentObject *co = static_cast<ComponentObject *>(o->vcpu_getInterface(componentObjectGuid));
  271. return MAKE_SCRIPT_OBJECT(co ? SOM::getWACObject(co->getGUID())->getScriptObject() : NULL);
  272. }
  273. scriptVar ComponentObject::script_vcpu_setRegionFromMap(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar map, scriptVar byte, scriptVar inv) {
  274. SCRIPT_FUNCTION_INIT; ;
  275. ASSERT(SOM::isNumeric(&byte));
  276. ASSERT(SOM::isNumeric(&inv));
  277. ComponentObject *co = static_cast<ComponentObject *>(o->vcpu_getInterface(componentObjectGuid));
  278. SMap *sm = static_cast<SMap *>(GET_SCRIPT_OBJECT_AS(map, mapGuid));
  279. co->script_setRegionFromMap(sm, SOM::makeInt(&byte), SOM::makeBoolean(&inv));
  280. RETURN_SCRIPT_VOID;
  281. }
  282. scriptVar ComponentObject::script_vcpu_setRegion(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar r) {
  283. SCRIPT_FUNCTION_INIT; ;
  284. ComponentObject *co = static_cast<ComponentObject *>(o->vcpu_getInterface(componentObjectGuid));
  285. SRegion *reg = static_cast<SRegion *>(GET_SCRIPT_OBJECT_AS(r, regionGuid));
  286. if (co) co->script_setRegion(reg);
  287. RETURN_SCRIPT_VOID;
  288. }
  289. scriptVar ComponentObject::script_vcpu_onGetWac(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar wac) {
  290. SCRIPT_FUNCTION_INIT;
  291. PROCESS_HOOKS1(o, compoController, wac);
  292. SCRIPT_FUNCTION_CHECKABORTEVENT;
  293. SCRIPT_EXEC_EVENT1(o, wac);
  294. }
  295. scriptVar ComponentObject::script_vcpu_onGiveUpWac(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar wac) {
  296. SCRIPT_FUNCTION_INIT;
  297. PROCESS_HOOKS1(o, compoController, wac);
  298. SCRIPT_FUNCTION_CHECKABORTEVENT;
  299. SCRIPT_EXEC_EVENT1(o, wac);
  300. }
  301. scriptVar ComponentObject::script_vcpu_setAcceptWac(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar on) {
  302. SCRIPT_FUNCTION_INIT;
  303. ASSERT(SOM::isNumeric(&on));
  304. ComponentObject *co = static_cast<ComponentObject *>(o->vcpu_getInterface(componentObjectGuid));
  305. if (co) co->setAcceptWac(GET_SCRIPT_BOOLEAN(on));
  306. RETURN_SCRIPT_VOID;
  307. }