guiobjwnd.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. #include <precomp.h>
  2. #include <api/script/api_maki.h>
  3. #include <api/wnd/wndclass/guiobjwnd.h>
  4. #include <api/script/scriptobj.h>
  5. #include <api/script/scriptguid.h>
  6. #include <api/service/svcs/svc_droptarget.h>
  7. #include <api/wnd/notifmsg.h>
  8. #include <api/script/objects/rootobject.h>
  9. #include <api/locales/xlatstr.h>
  10. XMLParamPair GuiObjectWnd::params[] =
  11. {
  12. {GUIOBJECT_ACTIVEALPHA, L"ACTIVEALPHA"},
  13. {GUIOBJECT_ALPHA, L"ALPHA"},
  14. {GUIOBJECT_SETANCHOR, L"ANCHOR"},
  15. #ifdef USEAPPBAR
  16. {GUIOBJECT_APPBAR, L"APPBAR"},
  17. #endif
  18. {GUIOBJECT_CFGATTR, L"CFGATTRIB"},
  19. {GUIOBJECT_SETCURSOR, L"CURSOR"},
  20. {GUIOBJECT_DROPTARGET, L"DROPTARGET"},
  21. {GUIOBJECT_ENABLED, L"ENABLED"},
  22. {GUIOBJECT_FITTOPARENT, L"FITPARENT"},
  23. {GUIOBJECT_FOCUSONCLICK, L"FOCUSONCLICK"},
  24. {GUIOBJECT_GHOST, L"GHOST"},
  25. {GUIOBJECT_H, L"H"},
  26. {GUIOBJECT_ID, L"ID"},
  27. {GUIOBJECT_INACTIVEALPHA, L"INACTIVEALPHA"},
  28. {GUIOBJECT_MOVE, L"MOVE"},
  29. {GUIOBJECT_SETNOCONTEXTMENU, L"NOCONTEXTMENU"},
  30. {GUIOBJECT_SETNODBLCLICK, L"NODBLCLICK"},
  31. {GUIOBJECT_SETNOLEFTCLICK, L"NOLEFTCLICK"},
  32. {GUIOBJECT_SETNOMOUSEMOVE, L"NOMOUSEMOVE"},
  33. {GUIOBJECT_SETNORIGHTCLICK, L"NORIGHTCLICK"},
  34. {GUIOBJECT_NOTIFY, L"NOTIFY"},
  35. {GUIOBJECT_NOTIFY, L"NOTIFY0"},
  36. {GUIOBJECT_NOTIFY, L"NOTIFY1"},
  37. {GUIOBJECT_NOTIFY, L"NOTIFY2"},
  38. {GUIOBJECT_NOTIFY, L"NOTIFY3"},
  39. {GUIOBJECT_NOTIFY, L"NOTIFY4"},
  40. {GUIOBJECT_NOTIFY, L"NOTIFY5"},
  41. {GUIOBJECT_NOTIFY, L"NOTIFY6"},
  42. {GUIOBJECT_NOTIFY, L"NOTIFY7"},
  43. {GUIOBJECT_NOTIFY, L"NOTIFY8"},
  44. {GUIOBJECT_NOTIFY, L"NOTIFY9"},
  45. {GUIOBJECT_RECTRGN, L"RECTRGN"},
  46. {GUIOBJECT_SYSREGION, L"REGIONOP"},
  47. {GUIOBJECT_RELATH, L"RELATH"},
  48. {GUIOBJECT_RELATW, L"RELATW"},
  49. {GUIOBJECT_RELATX, L"RELATX"},
  50. {GUIOBJECT_RELATY, L"RELATY"},
  51. {GUIOBJECT_RENDERBASETEXTURE, L"RENDERBASETEXTURE"},
  52. {GUIOBJECT_SYSMETRICSX, L"SYSMETRICSX"},
  53. {GUIOBJECT_SYSMETRICSY, L"SYSMETRICSY"},
  54. {GUIOBJECT_SYSMETRICSW, L"SYSMETRICSW"},
  55. {GUIOBJECT_SYSMETRICSH, L"SYSMETRICSH"},
  56. {GUIOBJECT_SYSREGION, L"SYSREGION"},
  57. {GUIOBJECT_TABORDER, L"TABORDER"},
  58. {GUIOBJECT_TOOLTIP, L"TOOLTIP"},
  59. {GUIOBJECT_TRANSLATE, L"TRANSLATE"},
  60. {GUIOBJECT_USERDATA, L"USERDATA"},
  61. {GUIOBJECT_VISIBLE, L"VISIBLE"},
  62. {GUIOBJECT_W, L"W"},
  63. {GUIOBJECT_WANTFOCUS, L"WANTFOCUS"},
  64. {GUIOBJECT_X, L"X"},
  65. {GUIOBJECT_SETX1, L"X1"},
  66. {GUIOBJECT_SETX2, L"X2"},
  67. {GUIOBJECT_Y, L"Y"},
  68. {GUIOBJECT_SETY1, L"Y1"},
  69. {GUIOBJECT_SETY2, L"Y2"},
  70. };
  71. GuiObjectWnd::GuiObjectWnd()
  72. {
  73. my_gui_object = static_cast<GuiObject *>(WASABI_API_MAKI->maki_encapsulate(guiObjectGuid, getScriptObject()));
  74. getScriptObject()->vcpu_setInterface(xmlObjectGuid, static_cast<XmlObject *>(this));
  75. getScriptObject()->vcpu_setInterface(guiObjectWndGuid, static_cast<GuiObjectWnd *>(this));
  76. #ifdef USEAPPBAR
  77. getScriptObject()->vcpu_setInterface(appBarGuid, static_cast<AppBar*>(this));
  78. #endif
  79. my_gui_object->guiobject_setRootWnd(this);
  80. getScriptObject()->vcpu_setClassName(L"GuiObject");
  81. getScriptObject()->vcpu_setController(WASABI_API_MAKI->maki_getController(guiObjectGuid));
  82. cfg_reentry = 0;
  83. xuihandle = newXuiHandle();
  84. CreateXMLParameters(xuihandle);
  85. }
  86. void GuiObjectWnd::CreateXMLParameters(int master_handle)
  87. {
  88. int numParams = sizeof(params) / sizeof(params[0]);
  89. hintNumberOfParams(xuihandle, numParams);
  90. for (int i = 0;i < numParams;i++)
  91. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  92. }
  93. GuiObjectWnd::~GuiObjectWnd()
  94. {
  95. WASABI_API_MAKI->maki_deencapsulate(guiObjectGuid, my_gui_object);
  96. my_gui_object = NULL;
  97. }
  98. const wchar_t *GuiObjectWnd::getTip()
  99. {
  100. switch(wantTranslation())
  101. {
  102. case 1:
  103. return _(tip);
  104. case 2:
  105. return __(tip);
  106. default:
  107. return tip;
  108. }
  109. }
  110. int GuiObjectWnd::onRightButtonDown(int x, int y)
  111. {
  112. if (!my_gui_object) return 1;
  113. GUIOBJECTWND_PARENT::onRightButtonDown(x, y);
  114. my_gui_object->guiobject_onRightButtonDown(x, y);
  115. return 1;
  116. }
  117. int GuiObjectWnd::onRightButtonUp(int x, int y)
  118. {
  119. if (!my_gui_object) return 1;
  120. GUIOBJECTWND_PARENT::onRightButtonUp(x, y);
  121. my_gui_object->guiobject_onRightButtonUp(x, y);
  122. return 1;
  123. }
  124. int GuiObjectWnd::onLeftButtonDown(int x, int y)
  125. {
  126. if (!my_gui_object) return 1;
  127. GUIOBJECTWND_PARENT::onLeftButtonDown(x, y);
  128. my_gui_object->guiobject_onLeftButtonDown(x, y);
  129. return 1;
  130. }
  131. int GuiObjectWnd::onLeftButtonUp(int x, int y)
  132. {
  133. if (!my_gui_object) return 1;
  134. GUIOBJECTWND_PARENT::onLeftButtonUp(x, y);
  135. my_gui_object->guiobject_onLeftButtonUp(x, y);
  136. return 1;
  137. }
  138. int GuiObjectWnd::onMouseMove(int x, int y)
  139. {
  140. if (!my_gui_object) return 1;
  141. GUIOBJECTWND_PARENT::onMouseMove(x, y);
  142. my_gui_object->guiobject_onMouseMove(x, y);
  143. return 1;
  144. }
  145. int GuiObjectWnd::wantTranslation()
  146. {
  147. if (!my_gui_object) return 1;
  148. return my_gui_object->guiobject_wantTranslation();
  149. }
  150. int GuiObjectWnd::onLeftButtonDblClk(int x, int y)
  151. {
  152. if (!my_gui_object) return 1;
  153. GUIOBJECTWND_PARENT::onLeftButtonDblClk(x, y);
  154. my_gui_object->guiobject_onLeftButtonDblClk(x, y);
  155. return 1;
  156. }
  157. int GuiObjectWnd::onRightButtonDblClk(int x, int y)
  158. {
  159. if (!my_gui_object) return 1;
  160. GUIOBJECTWND_PARENT::onRightButtonDblClk(x, y);
  161. my_gui_object->guiobject_onRightButtonDblClk(x, y);
  162. return 1;
  163. }
  164. // Martin> For the next two functions, we need to ensure that we don't kill volume change if nothing is done
  165. int GuiObjectWnd::onMouseWheelDown (int click, int line)
  166. {
  167. if (!my_gui_object) return 1;
  168. int ret = GUIOBJECTWND_PARENT::onMouseWheelDown(click, line);
  169. if (!ret) ret = my_gui_object->guiobject_onMouseWheelDown(click, line);
  170. return ret;
  171. }
  172. int GuiObjectWnd::onMouseWheelUp (int click, int line)
  173. {
  174. if (!my_gui_object) return 1;
  175. int ret = GUIOBJECTWND_PARENT::onMouseWheelUp(click, line);
  176. if (!ret) ret = my_gui_object->guiobject_onMouseWheelUp(click, line);
  177. return ret;
  178. }
  179. int GuiObjectWnd::onResize()
  180. {
  181. if (!my_gui_object) return 1;
  182. GUIOBJECTWND_PARENT::onResize();
  183. if (!isInited()) return 1;
  184. ifc_window *w = my_gui_object->guiobject_getRootWnd();
  185. RECT r;
  186. w->getClientRect(&r);
  187. my_gui_object->guiobject_onResize(r.left, r.top, r.right - r.left, r.bottom - r.top);
  188. return 1;
  189. }
  190. void GuiObjectWnd::onEnterArea()
  191. {
  192. if (!my_gui_object) return ;
  193. GUIOBJECTWND_PARENT::onEnterArea();
  194. my_gui_object->guiobject_onEnterArea();
  195. }
  196. void GuiObjectWnd::onLeaveArea()
  197. {
  198. if (!my_gui_object) return ;
  199. GUIOBJECTWND_PARENT::onLeaveArea();
  200. my_gui_object->guiobject_onLeaveArea();
  201. }
  202. void GuiObjectWnd::onSetVisible(int show)
  203. {
  204. if (!my_gui_object)
  205. return ;
  206. GUIOBJECTWND_PARENT::onSetVisible(show);
  207. my_gui_object->guiobject_onSetVisible(show);
  208. }
  209. int GuiObjectWnd::onEnable(int en)
  210. {
  211. if (!my_gui_object) return 1;
  212. GUIOBJECTWND_PARENT::onEnable(en);
  213. my_gui_object->guiobject_onEnable(en);
  214. return 1;
  215. }
  216. GuiObject *GuiObjectWnd::getGuiObject()
  217. {
  218. return my_gui_object;
  219. }
  220. RootObject *GuiObjectWnd::getRootObject()
  221. {
  222. return my_gui_object->guiobject_getRootObject();
  223. }
  224. int GuiObjectWnd::dragDrop(ifc_window *sourceWnd, int x, int y)
  225. {
  226. int r = DropTargetEnum::throwDrop(my_gui_object->guiobject_getDropTarget(), sourceWnd, x, y);
  227. if (r == 0)
  228. {
  229. ifc_window *p = getParent();
  230. if (p != NULL)
  231. {
  232. DragInterface *d = p->getDragInterface();
  233. if (d != NULL)
  234. return d->dragDrop(sourceWnd, x, y);
  235. }
  236. }
  237. return r;
  238. }
  239. int GuiObjectWnd::dragEnter(ifc_window *sourceWnd)
  240. {
  241. my_gui_object->guiobject_dragEnter(sourceWnd);
  242. return 1;
  243. }
  244. int GuiObjectWnd::dragOver(int x, int y, ifc_window *sourceWnd)
  245. {
  246. my_gui_object->guiobject_dragOver(x, y, sourceWnd);
  247. return 1;
  248. }
  249. int GuiObjectWnd::dragLeave(ifc_window *sourceWnd)
  250. {
  251. my_gui_object->guiobject_dragLeave(sourceWnd);
  252. return 1;
  253. }
  254. int GuiObjectWnd::onActivate()
  255. {
  256. if (!my_gui_object) return 1;
  257. GUIOBJECTWND_PARENT::onActivate();
  258. invalidate();
  259. return 1;
  260. }
  261. int GuiObjectWnd::onDeactivate()
  262. {
  263. if (!my_gui_object) return 1;
  264. GUIOBJECTWND_PARENT::onDeactivate();
  265. invalidate();
  266. return 1;
  267. }
  268. void GuiObjectWnd::onCancelCapture()
  269. {
  270. if (!my_gui_object) return ;
  271. GUIOBJECTWND_PARENT::onCancelCapture();
  272. my_gui_object->guiobject_onCancelCapture();
  273. }
  274. int GuiObjectWnd::setXuiParam(int _xuihandle, int attrid, const wchar_t *name, const wchar_t *value)
  275. {
  276. if (_xuihandle == xuihandle)
  277. {
  278. switch (attrid)
  279. {
  280. case GUIOBJECT_FOCUSONCLICK:
  281. setFocusOnClick(WTOI(value));
  282. break;
  283. default:
  284. getGuiObject()->guiobject_setXmlParamById(attrid, value);
  285. break;
  286. }
  287. }
  288. return 0;
  289. }
  290. int GuiObjectWnd::onUnknownXmlParam(const wchar_t *param, const wchar_t *value)
  291. {
  292. return onUnknownXuiParam(param, value);
  293. }
  294. int GuiObjectWnd::setXmlParamById(int xmlhandle, int attrid, const wchar_t *name, const wchar_t *value)
  295. {
  296. return setXuiParam(xmlhandle, attrid, name, value);
  297. }
  298. void *GuiObjectWnd::getInterface(GUID interface_guid)
  299. {
  300. void *r = GUIOBJECTWND_PARENT::getInterface(interface_guid);
  301. if (r) return r;
  302. return getRootObject()->rootobject_getScriptObject()->vcpu_getInterface(interface_guid);
  303. }
  304. int GuiObjectWnd::onAction(const wchar_t *action, const wchar_t *param, int x, int y, intptr_t p1, intptr_t p2, void *data, size_t datalen, ifc_window *source)
  305. {
  306. #ifdef WASABI_COMPILE_CONFIG
  307. if (!_wcsicmp(action, L"reload_config") && isInited())
  308. {
  309. if (cfg_reentry) return 1;
  310. cfg_reentry = 1;
  311. int r = onReloadConfig();
  312. cfg_reentry = 0;
  313. return r;
  314. }
  315. #endif
  316. int rt = GUIOBJECTWND_PARENT::onAction(action, param, x, y, p1, p2, data, datalen, source);
  317. getGuiObject()->guiobject_onAction(action, param, x, y, p1, p2, data, datalen, source);
  318. return rt;
  319. }
  320. void GuiObjectWnd::setContent(const wchar_t *groupid_orguid, int autoresizefromcontent)
  321. {
  322. #ifdef WASABI_COMPILE_SKIN
  323. // abstract_setAllowDeferredContent(0);
  324. abstract_setContent(groupid_orguid, autoresizefromcontent);
  325. #endif
  326. }
  327. void GuiObjectWnd::setContentBySkinItem(SkinItem *item, int autoresizefromcontent)
  328. {
  329. // abstract_setAllowDeferredContent(0);
  330. #ifdef WASABI_COMPILE_SKIN
  331. abstract_setContentBySkinItem(item, autoresizefromcontent);
  332. #endif
  333. }
  334. void GuiObjectWnd::abstract_onNewContent()
  335. {
  336. #ifdef WASABI_COMPILE_SKIN
  337. GUIOBJECTWND_PARENT::abstract_onNewContent();
  338. #endif
  339. onNewContent();
  340. #ifdef WASABI_COMPILE_CONFIG
  341. if (getGuiObject()->guiobject_hasCfgAttrib())
  342. onReloadConfig();
  343. #endif
  344. }
  345. GuiObject *GuiObjectWnd::findObject(const wchar_t *object_id)
  346. {
  347. return getGuiObject()->guiobject_findObject(object_id);
  348. }
  349. #ifdef WASABI_COMPILE_SCRIPT
  350. ScriptObject *GuiObjectWnd::findScriptObject(const wchar_t *object_id)
  351. {
  352. GuiObject *fo = getGuiObject()->guiobject_findObject(object_id);
  353. if (fo != NULL) return fo->guiobject_getScriptObject();
  354. return NULL;
  355. }
  356. #endif
  357. const wchar_t *GuiObjectWnd::getId()
  358. {
  359. if (my_gui_object)
  360. return my_gui_object->guiobject_getId();
  361. return GUIOBJECTWND_PARENT::getId();
  362. }
  363. int GuiObjectWnd::onPostOnInit()
  364. {
  365. int r = GUIOBJECTWND_PARENT::onPostOnInit();
  366. #ifdef WASABI_COMPILE_CONFIG
  367. if (getGuiObject()->guiobject_hasCfgAttrib())
  368. onReloadConfig();
  369. #endif
  370. return r;
  371. }
  372. int GuiObjectWnd::onInit()
  373. {
  374. int r = GUIOBJECTWND_PARENT::onInit();
  375. getGuiObject()->guiobject_onInit();
  376. return r;
  377. }
  378. int GuiObjectWnd::onChar(unsigned int c)
  379. {
  380. if (!my_gui_object) return 1;
  381. int r = GUIOBJECTWND_PARENT::onChar(c);
  382. getGuiObject()->guiobject_onChar(c);
  383. return r;
  384. }
  385. int GuiObjectWnd::onKeyDown(int vkcode)
  386. {
  387. if (!my_gui_object) return 1;
  388. int r = GUIOBJECTWND_PARENT::onKeyDown(vkcode);
  389. getGuiObject()->guiobject_onKeyDown(vkcode);
  390. return r;
  391. }
  392. int GuiObjectWnd::onKeyUp(int vkcode)
  393. {
  394. if (!my_gui_object) return 1;
  395. int r = GUIOBJECTWND_PARENT::onKeyUp(vkcode);
  396. getGuiObject()->guiobject_onKeyUp(vkcode);
  397. return r;
  398. }
  399. int GuiObjectWnd::onGetFocus()
  400. {
  401. if (!my_gui_object) return 1;
  402. int r = GUIOBJECTWND_PARENT::onGetFocus();
  403. getGuiObject()->guiobject_onGetFocus();
  404. return r;
  405. }
  406. int GuiObjectWnd::onKillFocus()
  407. {
  408. if (!my_gui_object) return 1;
  409. int r = GUIOBJECTWND_PARENT::onKillFocus();
  410. getGuiObject()->guiobject_onKillFocus();
  411. return r;
  412. }
  413. int GuiObjectWnd::onAcceleratorEvent(const wchar_t *name)
  414. {
  415. int r = GUIOBJECTWND_PARENT::onAcceleratorEvent(name);
  416. getGuiObject()->guiobject_onAccelerator(name);
  417. return r;
  418. }
  419. int GuiObjectWnd::wantFocus()
  420. {
  421. if (GUIOBJECTWND_PARENT::wantFocus()) return 1;
  422. if (my_gui_object)
  423. return my_gui_object->guiobject_wantFocus();
  424. return 0;
  425. }