group.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753
  1. #include <precomp.h>
  2. #include <tataki/bitmap/bitmap.h>
  3. #include <api/wnd/popup.h>
  4. #include <api/wndmgr/layout.h>
  5. #include <api/skin/skinparse.h>
  6. //#include <api/skin/widgets/button.h>
  7. //#include <api/core/buttons.h>
  8. #include <api/wnd/wndtrack.h>
  9. #include <api/wac/compon.h>
  10. #include <api/skin/skin.h>
  11. #include <api/wnd/notifmsg.h>
  12. #include <api/config/items/intarray.h>
  13. #include <api/config/items/cfgitem.h>
  14. #include <api/config/items/attribute.h>
  15. #include <api/wndmgr/layout.h>
  16. #include <api/script/script.h>
  17. #include <api/script/scriptmgr.h>
  18. #include <bfc/util/profiler.h>
  19. #include <api/wndmgr/resize.h>
  20. #include <bfc/wasabi_std_wnd.h>
  21. #include <api/wnd/PaintCanvas.h>
  22. #ifndef WM_MOUSEWHEEL
  23. #define WM_MOUSEWHEEL 0x20A
  24. #endif
  25. const wchar_t groupXuiObjectStr[] = L"Group"; // This is the xml tag
  26. char groupXuiSvcName[] = "Group xui object"; // this is the name of the xuiservice
  27. #ifdef WASABI_COMPILE_CONFIG
  28. const wchar_t cfgGroupXuiObjectStr[] = L"CfgGroup"; // This is the xml tag
  29. char cfgGroupXuiSvcName[] = "CfgGroup xui object"; // this is the name of the xuiservice
  30. #endif
  31. XMLParamPair Group::groupParams[] =
  32. {
  33. {XUIGROUP_AUTOHEIGHTSOURCE, L"AUTOHEIGHTSOURCE"},
  34. {XUIGROUP_AUTOWIDTHSOURCE, L"AUTOWIDTHSOURCE"},
  35. {XUIGROUP_BACKGROUND, L"BACKGROUND"},
  36. {XUIGROUP_DRAWBACKGROUND, L"DRAWBACKGROUND"},
  37. {XUIGROUP_DEFAULT_W, L"DEFAULT_W"},
  38. {XUIGROUP_DEFAULT_H, L"DEFAULT_H"},
  39. {XUIGROUP_DESIGN_H, L"DESIGN_H"},
  40. {XUIGROUP_DESIGN_W, L"DESIGN_W"},
  41. {XUIGROUP_EMBED_XUI, L"EMBED_XUI"},
  42. {XUIGROUP_INHERIT_CONTENT, L"INHERIT_CONTENT"},
  43. {XUIGROUP_INHERIT_GROUP, L"INHERIT_GROUP"},
  44. {XUIGROUP_INSTANCEID, L"INSTANCEID"},
  45. {XUIGROUP_LOCKMINMAX, L"LOCKMINMAX"},
  46. {XUIGROUP_MAXIMUM_H, L"MAXIMUM_H"},
  47. {XUIGROUP_MAXIMUM_W, L"MAXIMUM_W"},
  48. {XUIGROUP_MINIMUM_H, L"MINIMUM_H"},
  49. {XUIGROUP_MINIMUM_W, L"MINIMUM_W"},
  50. {XUIGROUP_NAME, L"NAME"},
  51. {XUIGROUP_PROPAGATESIZE, L"PROPAGATESIZE"},
  52. {XUIGROUP_XUITAG, L"XUITAG"},
  53. };
  54. Group::Group()
  55. {
  56. scripts_enabled = 1;
  57. getScriptObject()->vcpu_setInterface(groupGuid, (void *)static_cast<Group *>(this));
  58. getScriptObject()->vcpu_setClassName(L"Group");
  59. getScriptObject()->vcpu_setController(groupController);
  60. background = NULL;
  61. skinpart = 0;
  62. captured = 0; resizing = 0;
  63. x = 0; y = 0;
  64. size_w = 0; size_h = 0;
  65. lockminmax = 0;
  66. propagatesize = 0;
  67. reg = NULL;
  68. default_h = AUTOWH;
  69. default_w = AUTOWH;
  70. // allreg = NULL;
  71. // subregionlayers = new PtrList<api_window>;
  72. // subregiongroups = new PtrList<api_window>;
  73. deleting = 0;
  74. moving = 0;
  75. drawbackground = 0;
  76. groupmaxheight = AUTOWH;
  77. groupmaxwidth = AUTOWH;
  78. groupminheight = AUTOWH;
  79. groupminwidth = AUTOWH;
  80. // regionop = 0;
  81. // allsubreg = NULL;
  82. groups.addItem(this);
  83. scaledreg = NULL;
  84. scaledregionvalid = 0;
  85. autoregionop = 1;
  86. setRectRgn(0);
  87. disable_update_pos = 0;
  88. no_init_on_addchild = 0;
  89. lastheightsource = lastwidthsource = NULL;
  90. lastgetwidthbasedon = lastgetheightbasedon = AUTOWH;
  91. content_item = NULL;
  92. xuihandle = newXuiHandle();
  93. CreateXMLParameters(xuihandle);
  94. design_w = AUTOWH;
  95. design_h = AUTOWH;
  96. }
  97. void Group::CreateXMLParameters(int master_handle)
  98. {
  99. //GROUP_PARENT::CreateXMLParameters(master_handle);
  100. int numParams = sizeof(groupParams) / sizeof(groupParams[0]);
  101. hintNumberOfParams(xuihandle, numParams);
  102. for (int i = 0;i < numParams;i++)
  103. {
  104. addParam(xuihandle, groupParams[i], XUI_ATTRIBUTE_IMPLIED);
  105. }
  106. }
  107. Group::~Group()
  108. {
  109. deleteScripts();
  110. deleting = 1;
  111. WASABI_API_WND->skin_unregisterBaseTextureWindow(this);
  112. while (gui_objects.getNumItems() > 0)
  113. {
  114. SkinParser::destroyGuiObject(gui_objects.enumItem(0));
  115. gui_objects.removeByPos(0);
  116. }
  117. delete background;
  118. delete reg;
  119. delete scaledreg;
  120. xuiparams.deleteAll();
  121. /* subregionlayers->removeAll();
  122. delete subregionlayers;
  123. subregiongroups->removeAll();
  124. delete subregiongroups;*/
  125. groups.removeItem(this);
  126. WASABI_API_SYSCB->syscb_deregisterCallback(static_cast<WndCallbackI*>(this));
  127. }
  128. int Group::isGroup(Group *o)
  129. {
  130. return groups.haveItem(o);
  131. }
  132. int Group::setXmlParam(const wchar_t *paramname, const wchar_t *strvalue)
  133. {
  134. if (!WCSICMP(paramname, L"id") && !instanceid.isempty())
  135. return GROUP_PARENT::setXmlParam(paramname, instanceid);
  136. return GROUP_PARENT::setXmlParam(paramname, strvalue);
  137. }
  138. int Group::setXuiParam(int _xuihandle, int xuiid, const wchar_t *paramname, const wchar_t *strvalue)
  139. {
  140. if (xuihandle == _xuihandle)
  141. {
  142. switch (xuiid)
  143. {
  144. case XUIGROUP_INSTANCEID:
  145. instanceid = strvalue;
  146. getGuiObject()->guiobject_setId(instanceid);
  147. return 1;
  148. case XUIGROUP_BACKGROUND:
  149. setBaseTexture(strvalue);
  150. setDrawBackground(1);
  151. return 1;
  152. case XUIGROUP_DRAWBACKGROUND:
  153. setDrawBackground(WTOI(strvalue));
  154. return 1;
  155. case XUIGROUP_DEFAULT_W:
  156. {
  157. int w = WTOI(strvalue);
  158. //getGuiObject()->guiobject_setGuiPosition(NULL, NULL, &w, NULL, NULL, NULL, NULL, NULL);
  159. default_w = w;
  160. return 1;
  161. }
  162. case XUIGROUP_DEFAULT_H:
  163. {
  164. int h = WTOI(strvalue);
  165. //getGuiObject()->guiobject_setGuiPosition(NULL, NULL, NULL, &h, NULL, NULL, NULL, NULL);
  166. default_h = h;
  167. return 1;
  168. }
  169. case XUIGROUP_MAXIMUM_H:
  170. groupmaxheight = WTOI(strvalue);
  171. return 1;
  172. case XUIGROUP_MAXIMUM_W:
  173. groupmaxwidth = WTOI(strvalue);
  174. return 1;
  175. case XUIGROUP_MINIMUM_H:
  176. groupminheight = WTOI(strvalue);
  177. return 1;
  178. case XUIGROUP_MINIMUM_W:
  179. groupminwidth = WTOI(strvalue);
  180. return 1;
  181. case XUIGROUP_PROPAGATESIZE:
  182. propagatesize = WTOI(strvalue);
  183. return 1;
  184. case XUIGROUP_LOCKMINMAX:
  185. lockminmax = WTOI(strvalue);
  186. return 1;
  187. case XUIGROUP_NAME:
  188. setName(strvalue);
  189. return 1;
  190. case XUIGROUP_AUTOWIDTHSOURCE:
  191. setAutoWidthSource(strvalue);
  192. return 1;
  193. case XUIGROUP_AUTOHEIGHTSOURCE:
  194. setAutoHeightSource(strvalue);
  195. return 1;
  196. case XUIGROUP_EMBED_XUI:
  197. xui_embedded_id = strvalue;
  198. return 1;
  199. case XUIGROUP_XUITAG:
  200. return 1;
  201. case XUIGROUP_INHERIT_GROUP:
  202. return 1;
  203. case XUIGROUP_INHERIT_CONTENT:
  204. return 1;
  205. case XUIGROUP_DESIGN_W:
  206. setDesignWidth(WTOI(strvalue));
  207. return 1;
  208. case XUIGROUP_DESIGN_H:
  209. setDesignHeight(WTOI(strvalue));
  210. return 1;
  211. }
  212. }
  213. return GROUP_PARENT::setXuiParam(_xuihandle, xuiid, paramname, strvalue);
  214. }
  215. void Group::setDesignWidth(int w)
  216. {
  217. design_w = w;
  218. if (isPostOnInit())
  219. onResize();
  220. }
  221. void Group::setDesignHeight(int h)
  222. {
  223. design_h = h;
  224. if (isPostOnInit())
  225. onResize();
  226. }
  227. int Group::getDesignWidth()
  228. {
  229. return design_w;
  230. }
  231. int Group::getDesignHeight()
  232. {
  233. return design_h;
  234. }
  235. int Group::onPostedMove()
  236. {
  237. return GROUP_PARENT::onPostedMove();
  238. }
  239. #ifdef WASABI_COMPILE_WNDMGR
  240. void Group::beginMove()
  241. {
  242. if (getGuiObject()->guiobject_getParentGroup())
  243. getGuiObject()->guiobject_getParentGroup()->beginMove();
  244. }
  245. void Group::beginScale()
  246. {
  247. if (getGuiObject()->guiobject_getParentGroup())
  248. getGuiObject()->guiobject_getParentGroup()->beginScale();
  249. }
  250. void Group::beginResize()
  251. {
  252. if (getGuiObject()->guiobject_getParentGroup())
  253. getGuiObject()->guiobject_getParentGroup()->beginResize();
  254. }
  255. void Group::endMove()
  256. {
  257. if (getGuiObject()->guiobject_getParentGroup())
  258. getGuiObject()->guiobject_getParentGroup()->endMove();
  259. }
  260. void Group::endScale()
  261. {
  262. if (getGuiObject()->guiobject_getParentGroup())
  263. getGuiObject()->guiobject_getParentGroup()->endScale();
  264. }
  265. void Group::endResize()
  266. {
  267. if (getGuiObject()->guiobject_getParentGroup())
  268. getGuiObject()->guiobject_getParentGroup()->endResize();
  269. }
  270. #endif
  271. void Group::onMinMaxEnforcerChanged()
  272. {
  273. if (!isPostOnInit()) return ;
  274. int min_x = getPreferences(MINIMUM_W);
  275. int min_y = getPreferences(MINIMUM_H);
  276. int max_x = getPreferences(MAXIMUM_W);
  277. int max_y = getPreferences(MAXIMUM_H);
  278. int sug_x = getPreferences(SUGGESTED_W);
  279. int sug_y = getPreferences(SUGGESTED_H);
  280. min_x = MAX(RESIZE_MINW, min_x);
  281. min_y = MAX(RESIZE_MINH, min_y);
  282. RECT r;
  283. POINT pt;
  284. getClientRect(&r);
  285. int w = r.right - r.left;
  286. int h = r.bottom - r.top;
  287. getPosition(&pt);
  288. if ((w < min_x || h < min_y || w > max_x || h > max_y) && (w != sug_x || h != sug_y))
  289. {
  290. //DebugString("reapplying minmax constraints\n");
  291. resize(pt.x, pt.y, sug_x, sug_y);
  292. }
  293. }
  294. #ifdef WASABI_COMPILE_WNDMGR
  295. void Group::mouseResize(int x, int y, int resizeway)
  296. { // screen coords!
  297. int min_x = getPreferences(MINIMUM_W);
  298. int min_y = getPreferences(MINIMUM_H);
  299. int max_x = getPreferences(MAXIMUM_W);
  300. int max_y = getPreferences(MAXIMUM_H);
  301. int sug_x = getPreferences(SUGGESTED_W);
  302. int sug_y = getPreferences(SUGGESTED_H);
  303. if (max_x != AUTOWH && min_x != AUTOWH && max_x < min_x) max_x = min_x;
  304. if (max_y != AUTOWH && min_y != AUTOWH && max_y < min_y) max_y = min_y;
  305. if (min_x != AUTOWH && max_x != AUTOWH && min_x > max_x) min_x = max_x;
  306. if (min_y != AUTOWH && max_y != AUTOWH && min_y > max_y) min_y = max_y;
  307. if (sug_x != AUTOWH && min_x != AUTOWH && sug_x < min_x) sug_x = min_x;
  308. if (sug_y != AUTOWH && min_y != AUTOWH && sug_y < min_y) sug_y = min_y;
  309. if (sug_x != AUTOWH && max_x != AUTOWH && sug_x > max_x) sug_x = max_x;
  310. if (sug_y != AUTOWH && max_y != AUTOWH && sug_y > max_y) sug_y = max_y;
  311. beginResize();
  312. int mask = 0;
  313. if (resizeway & RESIZE_BOTTOM)
  314. {
  315. mask |= BOTTOM;
  316. }
  317. if (resizeway & RESIZE_RIGHT)
  318. {
  319. mask |= RIGHT;
  320. }
  321. if (resizeway & RESIZE_TOP)
  322. {
  323. mask |= TOP;
  324. }
  325. if (resizeway & RESIZE_LEFT)
  326. {
  327. mask |= LEFT;
  328. }
  329. min_x = MAX(RESIZE_MINW, min_x);
  330. min_y = MAX(RESIZE_MINH, min_y);
  331. if (renderRatioActive())
  332. {
  333. if (min_x != AUTOWH) multRatio(&min_x);
  334. if (min_y != AUTOWH) multRatio(NULL, &min_y);
  335. if (max_x != AUTOWH) multRatio(&max_x);
  336. if (max_y != AUTOWH) multRatio(NULL, &max_y);
  337. if (sug_x != AUTOWH) multRatio(&sug_x);
  338. if (sug_y != AUTOWH) multRatio(NULL, &sug_y);
  339. }
  340. if (min_x == AUTOWH) min_x = -1;
  341. if (max_x == AUTOWH) max_x = -1;
  342. if (min_y == AUTOWH) min_y = -1;
  343. if (max_y == AUTOWH) max_y = -1;
  344. if (sug_x == AUTOWH) sug_x = -1;
  345. if (sug_y == AUTOWH) sug_y = -1;
  346. resizeClass rsize(this, min_x, min_y, max_x, max_y, sug_x, sug_y);
  347. if (rsize.resizeWindow(this, mask | NOINTERSECT))
  348. {
  349. RECT r = rsize.getRect();
  350. if (renderRatioActive())
  351. {
  352. r.right = (int)(((double)(r.right - r.left) / getRenderRatio()) + r.left + 0.5f);
  353. r.bottom = (int)(((double)(r.bottom - r.top) / getRenderRatio()) + r.top + 0.5f);
  354. }
  355. int _min_x = getPreferences(MINIMUM_W);
  356. int _min_y = getPreferences(MINIMUM_H);
  357. int _max_x = getPreferences(MAXIMUM_W);
  358. int _max_y = getPreferences(MAXIMUM_H);
  359. if (_max_x != AUTOWH && _min_x != AUTOWH && _max_x < _min_x) _max_x = _min_x;
  360. if (_max_y != AUTOWH && _min_y != AUTOWH && _max_y < _min_y) _max_y = _min_y;
  361. if (_min_x != AUTOWH && _max_x != AUTOWH && _min_x > _max_x) _min_x = _max_x;
  362. if (_min_y != AUTOWH && _max_y != AUTOWH && _min_y > _max_y) _min_y = _max_y;
  363. if (r.right - r.left < _min_x) r.right = r.left + _min_x;
  364. if (r.bottom - r.top < _min_y) r.bottom = r.top + _min_y;
  365. if (r.right - r.left > _max_x) r.right = r.left + _max_x;
  366. if (r.bottom - r.top > _max_y) r.bottom = r.top + _max_y;
  367. resizeToRect(&r);
  368. invalidate();
  369. endResize();
  370. }
  371. }
  372. #endif
  373. void Group::setAutoWidthSource(const wchar_t *obj)
  374. {
  375. autowidthsource = obj;
  376. }
  377. void Group::setAutoHeightSource(const wchar_t *obj)
  378. {
  379. autoheightsource = obj;
  380. }
  381. int Group::getAutoWidth()
  382. {
  383. return default_w == AUTOWH ? GROUP_PARENT::getPreferences(SUGGESTED_W) : default_w;
  384. }
  385. int Group::getAutoHeight()
  386. {
  387. return default_h == AUTOWH ? GROUP_PARENT::getPreferences(SUGGESTED_H) : default_h;
  388. }
  389. int Group::getWidthBasedOn(GuiObject *o)
  390. {
  391. if (o == NULL)
  392. {
  393. if (lastwidthsource == NULL)
  394. {
  395. if (!autowidthsource.isempty())
  396. {
  397. lastwidthsource = getObject(autowidthsource);
  398. }
  399. }
  400. o = lastwidthsource;
  401. }
  402. if (o == NULL) return AUTOWH;
  403. if (lastgetwidthbasedon != AUTOWH) return lastgetwidthbasedon;
  404. int x, rx, w, rw;
  405. o->guiobject_getGuiPosition(&x, NULL, &w, NULL, &rx, NULL, &rw, NULL);
  406. int p = o->guiobject_getAutoWidth();
  407. if (w == AUTOWH) { w = p; rw = 0; }
  408. if (rx == 0 && rw == 1)
  409. lastgetwidthbasedon = p - w;
  410. else if (rx == 0 && rw == 0)
  411. lastgetwidthbasedon = p + x;
  412. else
  413. lastgetwidthbasedon = AUTOWH;
  414. return lastgetwidthbasedon;
  415. }
  416. int Group::getHeightBasedOn(GuiObject *o)
  417. {
  418. if (o == NULL)
  419. {
  420. if (lastheightsource == NULL)
  421. {
  422. if (!autoheightsource.isempty())
  423. {
  424. lastheightsource = getObject(autoheightsource);
  425. }
  426. }
  427. o = lastheightsource;
  428. }
  429. if (o == NULL) return AUTOWH;
  430. if (lastgetheightbasedon != AUTOWH) return lastgetheightbasedon;
  431. int y, ry, h, rh;
  432. o->guiobject_getGuiPosition(NULL, &y, NULL, &h, NULL, &ry, NULL, &rh);
  433. int p = o->guiobject_getAutoHeight();
  434. if (h == AUTOWH) { h = p; rh = 0; }
  435. if (ry == 0 && rh == 1)
  436. lastgetheightbasedon = p - h;
  437. else if (ry == 0 && rh == 0)
  438. lastgetheightbasedon = h + y;
  439. else
  440. lastgetheightbasedon = AUTOWH;
  441. return lastgetheightbasedon;
  442. }
  443. int Group::getPreferences(int what)
  444. {
  445. int _what = what;
  446. if (lockminmax)
  447. {
  448. if (_what == MAXIMUM_W || _what == MINIMUM_W)
  449. _what = SUGGESTED_W;
  450. if (_what == MAXIMUM_H || _what == MINIMUM_H)
  451. _what = SUGGESTED_H;
  452. }
  453. switch (_what)
  454. {
  455. case SUGGESTED_W:
  456. {
  457. int w, rw;
  458. getGuiObject()->guiobject_getGuiPosition(NULL, NULL, &w, NULL, NULL, NULL, &rw, NULL);
  459. if (w == AUTOWH)
  460. w = getWidthBasedOn();
  461. if (w == AUTOWH || rw == 1)
  462. w = getAutoWidth();
  463. if (w == AUTOWH && getBaseTexture())
  464. w = getBaseTexture()->getWidth();
  465. if (groupmaxwidth != AUTOWH)
  466. {
  467. if (groupminwidth != AUTOWH)
  468. {
  469. return MIN(groupmaxwidth, MAX(groupminwidth, w));
  470. }
  471. else
  472. {
  473. return MIN(groupmaxwidth, w);
  474. }
  475. }
  476. else if (groupminwidth != AUTOWH)
  477. {
  478. return MAX(groupminwidth, w);
  479. }
  480. return w;
  481. }
  482. case SUGGESTED_H:
  483. {
  484. int h, rh;
  485. getGuiObject()->guiobject_getGuiPosition(NULL, NULL, NULL, &h, NULL, NULL, NULL, &rh);
  486. if (h == AUTOWH)
  487. h = getHeightBasedOn();
  488. if (h == AUTOWH || rh == 1)
  489. h = getAutoHeight();
  490. if (h == AUTOWH && getBaseTexture())
  491. h = getBaseTexture()->getHeight();
  492. if (groupmaxheight != AUTOWH)
  493. {
  494. if (groupminheight != AUTOWH)
  495. {
  496. return MIN(groupmaxheight, MAX(groupminheight, h));
  497. }
  498. else
  499. {
  500. return MIN(groupmaxheight, h);
  501. }
  502. }
  503. else if (groupminheight != AUTOWH)
  504. {
  505. return MAX(groupminheight, h);
  506. }
  507. return h;
  508. }
  509. case MAXIMUM_H:
  510. {
  511. int h = GROUP_PARENT::getPreferences(what);
  512. if (h != AUTOWH)
  513. return MIN(h, groupmaxheight);
  514. return groupmaxheight;
  515. }
  516. case MAXIMUM_W:
  517. {
  518. int w = GROUP_PARENT::getPreferences(what);
  519. if (w != AUTOWH)
  520. return MIN(w, groupmaxwidth);
  521. return groupmaxwidth;
  522. }
  523. case MINIMUM_H:
  524. {
  525. int h = GROUP_PARENT::getPreferences(what);
  526. if (h != AUTOWH)
  527. return MAX(h, groupminheight);
  528. return groupminheight;
  529. }
  530. case MINIMUM_W:
  531. {
  532. int w = GROUP_PARENT::getPreferences(what);
  533. if (w != AUTOWH)
  534. return MAX(w, groupminwidth);
  535. return groupminwidth;
  536. }
  537. }
  538. return GROUP_PARENT::getPreferences(what);
  539. }
  540. void Group::updatePos(GuiObject *o, RECT *r2)
  541. {
  542. if (disable_update_pos) return ;
  543. RECT r;
  544. if (r2 == NULL)
  545. {
  546. getClientRect(&r);
  547. r2 = &r;
  548. }
  549. double d = getRenderRatio();
  550. int w, h;
  551. int ox, oy, ow, oh, orx, ory, orw, orh;
  552. int ox1, ox2, oy1, oy2, oanchor;
  553. if (o->guiobject_getAnchoragePosition(&ox1, &oy1, &ox2, &oy2, &oanchor))
  554. {
  555. // anchorage values have not been translated into native values yet, do it now
  556. int x, y, w, h, rx, ry, rw, rh;
  557. x = y = w = h = rx = ry = rw = rh = AUTOWH;
  558. int lw = ox2 - ox1;
  559. int lh = oy2 - oy1;
  560. int iw = getDesignWidth();
  561. int ih = getDesignHeight();
  562. if (iw == AUTOWH || ih == AUTOWH)
  563. {
  564. Wasabi::Std::messageBox(L"anchor coordinate system used without design size for the parent group.\nYour parent group needs the design_w/design_h parameters if you are using x1/y1/x2/y2/anchor parameters on one of its children\nDefaulting to 320x200", L"XML Error", 0);
  565. iw = 320;
  566. ih = 200;
  567. }
  568. int right_m = iw - ox2;
  569. int bottom_m = ih - oy2;
  570. if ((oanchor & ANCHOR_LEFT) == 0 && (oanchor & ANCHOR_RIGHT) == 0) oanchor |= ANCHOR_LEFT;
  571. if ((oanchor & ANCHOR_TOP) == 0 && (oanchor & ANCHOR_BOTTOM) == 0) oanchor |= ANCHOR_TOP;
  572. if (oanchor & ANCHOR_LEFT)
  573. {
  574. x = ox1;
  575. rx = 0;
  576. if (oanchor & ANCHOR_RIGHT)
  577. {
  578. w = -((iw - ox2) + ox1);
  579. rw = 1;
  580. }
  581. else
  582. {
  583. w = lw;
  584. rw = 0;
  585. }
  586. }
  587. else
  588. {
  589. if (oanchor & ANCHOR_RIGHT)
  590. {
  591. x = -(right_m + lw);
  592. rx = 1;
  593. w = lw;
  594. rw = 0;
  595. }
  596. }
  597. if (oanchor & ANCHOR_TOP)
  598. {
  599. y = oy1;
  600. ry = 0;
  601. if (oanchor & ANCHOR_BOTTOM)
  602. {
  603. h = -((ih - oy2) + oy1);
  604. rh = 1;
  605. }
  606. else
  607. {
  608. h = lh;
  609. rh = 0;
  610. }
  611. }
  612. else
  613. {
  614. if (oanchor & ANCHOR_BOTTOM)
  615. {
  616. y = -(bottom_m + lh);
  617. ry = 1;
  618. h = lh;
  619. rh = 0;
  620. }
  621. }
  622. disable_update_pos = 1;
  623. o->guiobject_setGuiPosition(&x, &y, &w, &h, &rx, &ry, &rw, &rh);
  624. o->guiobject_validateAnchorage();
  625. disable_update_pos = 0;
  626. }
  627. o->guiobject_getGuiPosition(&ox, &oy, &ow, &oh, &orx, &ory, &orw, &orh);
  628. if (ow == AUTOWH) { ow = o->guiobject_getAutoWidth(); orw = 0; }
  629. if (oh == AUTOWH) { oh = o->guiobject_getAutoHeight(); orh = 0; }
  630. TextInfoCanvas fontInfoCanvas(this);
  631. double fontScale = fontInfoCanvas.getSystemFontScale();
  632. if (o->guiobject_getAutoSysMetricsX())
  633. ox = (int)((float)ox * fontScale);
  634. if (o->guiobject_getAutoSysMetricsY())
  635. oy = (int)((float)oy * fontScale);
  636. if (o->guiobject_getAutoSysMetricsW())
  637. ow = (int)((float)ow * fontScale);
  638. if (o->guiobject_getAutoSysMetricsH())
  639. oh = (int)((float)oh * fontScale);
  640. if (!o->guiobject_getRootWnd()->handleRatio())
  641. {
  642. if (orw == 1)
  643. w = (int)((float)(r2->right - r2->left + ow) * d);
  644. else if (orw == 2)
  645. w = (int)(((float)(r2->right - r2->left) * ((float)ow / 100.0f)) * d);
  646. else
  647. w = (int)((float)(ow) * d);
  648. if (orh == 1)
  649. h = (int)((float)(r2->bottom - r2->top + oh) * d);
  650. else if (orh == 2)
  651. h = (int)(((float)(r2->bottom - r2->top) * ((float)oh / 100.0f)) * d);
  652. else
  653. h = (int)((float)(oh) * d);
  654. if (orx == 1)
  655. x = (int)((float)(r2->right - r2->left + ox) * d);
  656. else if (orx == 2)
  657. x = (int)(((float)(r2->right - r2->left) * ((float)ox / 100.0f)) * d);
  658. else
  659. x = (int)((float)(ox) * d);
  660. if (ory == 1)
  661. y = (int)((float)(r2->bottom - r2->top + oy) * d);
  662. else if (ory == 2)
  663. y = (int)(((float)(r2->bottom - r2->top) * ((float)oy / 100.0f)) * d);
  664. else
  665. y = (int)((float)(oy) * d);
  666. x += (int)((float)(r2->left) * d);
  667. y += (int)((float)(r2->top) * d);
  668. }
  669. else
  670. {
  671. if (orw == 1)
  672. w = r2->right - r2->left + ow;
  673. else if (orw == 2)
  674. w = (int)((float)(r2->right - r2->left) * ((float)ow / 100.0f));
  675. else
  676. w = ow;
  677. if (orh == 1)
  678. h = r2->bottom - r2->top + oh;
  679. else if (orh == 2)
  680. h = (int)((float)(r2->bottom - r2->top) * ((float)oh / 100.0f));
  681. else
  682. h = oh;
  683. if (orx == 1)
  684. x = r2->right - r2->left + ox;
  685. else if (orx == 2)
  686. x = (int)((float)(r2->right - r2->left) * ((float)ox / 100.0f));
  687. else
  688. x = ox;
  689. if (ory == 1)
  690. y = r2->bottom - r2->top + oy;
  691. else if (ory == 2)
  692. y = (int)((float)(r2->bottom - r2->top) * ((float)oy / 100.0f));
  693. else
  694. y = oy;
  695. x += r2->left;
  696. y += r2->top;
  697. }
  698. o->guiobject_getRootWnd()->resize(x, y, w, h);
  699. }
  700. int Group::onResize()
  701. {
  702. GROUP_PARENT::onResize();
  703. if (!isInited()) return 1;
  704. RECT wr;
  705. getWindowRect(&wr);
  706. RECT r2;
  707. getClientRect(&r2);
  708. size_w = r2.right - r2.left; size_h = r2.bottom - r2.top;
  709. for (int i = 0;i < gui_objects.getNumItems();i++)
  710. {
  711. GuiObject *o = gui_objects.enumItem(i);
  712. updatePos(o, &r2);
  713. }
  714. invalidateScaledReg();
  715. return 1;
  716. }
  717. void Group::invalidateScaledReg()
  718. {
  719. scaledregionvalid = 0;
  720. invalidateWindowRegion();
  721. }
  722. int Group::onInit()
  723. {
  724. GROUP_PARENT::onInit();
  725. WASABI_API_SYSCB->syscb_registerCallback(static_cast<WndCallbackI*>(this));
  726. disable_update_pos = 1;
  727. no_init_on_addchild = 1;
  728. const wchar_t *id = getGroupContentId();
  729. SkinItem *item = getGroupContentSkinItem();
  730. if ((id && *id) || item != NULL)
  731. {
  732. SkinParser::fillGroup(this, id, item, 0, 1, scripts_enabled);
  733. }
  734. disable_update_pos = 0;
  735. no_init_on_addchild = 0;
  736. onFillGroup();
  737. return 1;
  738. }
  739. void Group::onFillGroup()
  740. {
  741. reloadDefaults();
  742. if (xui_embedded_id.len() > 0)
  743. embeddedxui_onNewEmbeddedContent();
  744. }
  745. int Group::onGroupChange(const wchar_t *id)
  746. {
  747. GROUP_PARENT::onGroupChange(id);
  748. if (!isInited()) return 1;
  749. const wchar_t *cid = getGroupContentId();
  750. SkinItem *item = getGroupContentSkinItem();
  751. if (!(cid && *cid) || item != NULL) return 1;
  752. if (!WCSICMP(id, cid)) return 1;
  753. deleteScripts();
  754. WASABI_API_WND->skin_unregisterBaseTextureWindow(this);
  755. while (gui_objects.getNumItems() > 0)
  756. {
  757. SkinParser::destroyGuiObject(gui_objects.enumItem(0));
  758. }
  759. delete background; background = NULL;
  760. delete reg; reg = NULL;
  761. delete scaledreg; scaledreg = NULL;
  762. disable_update_pos = 1;
  763. no_init_on_addchild = 1;
  764. SkinParser::fillGroup(this, cid, item, 0, 1, scripts_enabled);
  765. disable_update_pos = 0;
  766. no_init_on_addchild = 0;
  767. onFillGroup();
  768. if (isInited())
  769. onResize();
  770. getGuiObject()->guiobject_onStartup();
  771. return 1;
  772. }
  773. void Group::reloadDefaults()
  774. {
  775. getGuiObject()->guiobject_getGuiPosition(NULL, NULL, &size_w, &size_h, NULL, NULL, NULL, NULL);
  776. if (size_w == AUTOWH && size_h == AUTOWH)
  777. {
  778. /* if (!background) {
  779. size_w = 250;
  780. size_h = 100;
  781. } else {
  782. size_w = background->getWidth();
  783. size_h = background->getHeight();
  784. }*/
  785. if (background)
  786. {
  787. setPreferences(SUGGESTED_W, background->getWidth());
  788. setPreferences(SUGGESTED_H, background->getHeight());
  789. }
  790. size_w = GROUP_PARENT::getPreferences(SUGGESTED_W);
  791. size_h = GROUP_PARENT::getPreferences(SUGGESTED_H);
  792. }
  793. //setName(getGuiObject()->guiobject_getId());
  794. if (propagatesize)
  795. {
  796. Layout *l = getGuiObject()->guiobject_getParentLayout();
  797. if (l) l->addMinMaxEnforcer(this);
  798. }
  799. int i;
  800. for (i = 0;i < gui_objects.getNumItems();i++)
  801. {
  802. GuiObject *o = gui_objects.enumItem(i);
  803. if (o->guiobject_getParentGroup())
  804. {
  805. o->guiobject_getRootWnd()->setParent(o->guiobject_getParentGroup());
  806. if (!o->guiobject_getRootWnd()->isInited())
  807. {
  808. o->guiobject_getRootWnd()->init(o->guiobject_getParentGroup());
  809. o->guiobject_getParentGroup()->onCreateObject(getGuiObject());
  810. }
  811. }
  812. }
  813. /* if (getGuiObject()->guiobject_getParentGroup() && regionop)
  814. getGuiObject()->guiobject_getParentGroup()->addSubRegionGroup(this);*/
  815. invalidateWindowRegion();
  816. startScripts();
  817. for (i = 0;i < gui_objects.getNumItems();i++)
  818. {
  819. GuiObject *o = gui_objects.enumItem(i);
  820. o->guiobject_onStartup();
  821. }
  822. autoResize();
  823. const wchar_t *name = getName();
  824. if (name != NULL)
  825. onSetName();
  826. }
  827. void Group::startScripts()
  828. {
  829. for (int i = 0;i < getNumScripts();i++)
  830. {
  831. int vcpuid = enumScript(i);
  832. SystemObject *o = SOM::getSystemObjectByScriptId(vcpuid);
  833. if (o != NULL)
  834. {
  835. o->onLoad();
  836. foreach(xuiparams)
  837. XuiParam *p = xuiparams.getfor();
  838. o->onSetXuiParam(p->param, p->value);
  839. endfor;
  840. }
  841. }
  842. }
  843. int Group::onPaint(Canvas *canvas)
  844. {
  845. PaintCanvas paintcanvas;
  846. if (canvas == NULL)
  847. {
  848. if (!paintcanvas.beginPaint(this)) return 0;
  849. canvas = &paintcanvas;
  850. }
  851. GROUP_PARENT::onPaint(canvas);
  852. RECT r;
  853. if (!canvas->getClipBox(&r))
  854. getClientRect(&r);
  855. if (getDrawBackground()) RenderBaseTexture(canvas, r);
  856. return 1;
  857. }
  858. ifc_window *Group::getBaseTextureWindow()
  859. {
  860. if (reg && !reg->isEmpty()) return this;
  861. if (getParent()) return getParent()->getBaseTextureWindow();
  862. return this;
  863. }
  864. void Group::autoResize()
  865. {
  866. int w = getWidthBasedOn();
  867. int h = getHeightBasedOn();
  868. if (h == AUTOWH && w == AUTOWH) return ;
  869. resize(NOCHANGE, NOCHANGE, w == AUTOWH ? NOCHANGE : w, h == AUTOWH ? NOCHANGE : h);
  870. }
  871. int Group::childNotify(ifc_window *child, int msg, intptr_t p1, intptr_t p2)
  872. {
  873. if (msg == ChildNotify::AUTOWHCHANGED)
  874. {
  875. if (lastwidthsource && child == lastwidthsource->guiobject_getRootWnd() ||
  876. lastheightsource && child == lastheightsource->guiobject_getRootWnd())
  877. {
  878. lastgetwidthbasedon = AUTOWH;
  879. lastgetheightbasedon = AUTOWH;
  880. autoResize();
  881. }
  882. }
  883. if (!getParent())
  884. return 0;
  885. return getParent()->childNotify(child, msg, p1, p2);
  886. }
  887. void Group::sendNotifyToAllChildren(int notifymsg, intptr_t param1, intptr_t param2)
  888. {
  889. for (int i = 0;i < gui_objects.getNumItems();i++)
  890. gui_objects.enumItem(i)->guiobject_getRootWnd()->childNotify(this, notifymsg, param1, param2);
  891. }
  892. void Group::addScript(int scriptid)
  893. {
  894. scripts.addItem(scriptid);
  895. }
  896. int Group::getNumScripts()
  897. {
  898. return scripts.getNumItems();
  899. }
  900. int Group::enumScript(int n)
  901. {
  902. return scripts.enumItem(n);
  903. }
  904. void Group::deleteScripts()
  905. {
  906. for (int i = 0;i < scripts.getNumItems();i++)
  907. Script::unloadScript(scripts.enumItem(i));
  908. scripts.removeAll();
  909. }
  910. SkinBitmap *Group::getBaseTexture()
  911. {
  912. if (!background) return NULL;
  913. return background->getBitmap();
  914. }
  915. void Group::setBaseTexture(const wchar_t *b, int regis)
  916. {
  917. backgroundstr = b;
  918. if (regis) WASABI_API_WND->skin_unregisterBaseTextureWindow(this);
  919. delete background;
  920. background = NULL;
  921. if (b != NULL && *b)
  922. {
  923. background = new AutoSkinBitmap();
  924. background->setBitmap(b);
  925. #ifdef _WIN32
  926. RegionI r(background->getBitmap());
  927. setRegion(&r);
  928. #else
  929. #warning port me!
  930. #endif
  931. if (regis) WASABI_API_WND->skin_registerBaseTextureWindow(this, b);
  932. }
  933. else
  934. {
  935. delete reg;
  936. reg = NULL;
  937. delete scaledreg;
  938. scaledreg = NULL;
  939. invalidateWindowRegion();
  940. }
  941. }
  942. const wchar_t *Group::getBackgroundStr()
  943. {
  944. return backgroundstr;
  945. }
  946. int Group::onUnknownXuiParam(const wchar_t *xmlattributename, const wchar_t *value)
  947. {
  948. int r = GROUP_PARENT::onUnknownXuiParam(xmlattributename, value);
  949. if (r == 0)
  950. {
  951. if (!isInited())
  952. {
  953. xuiparams.addItem(new XuiParam(xmlattributename, value));
  954. }
  955. else
  956. {
  957. for (int i = 0;i < getNumScripts();i++)
  958. {
  959. int vcpuid = enumScript(i);
  960. SystemObject *o = SOM::getSystemObjectByScriptId(vcpuid);
  961. if (o != NULL) o->onSetXuiParam(xmlattributename, value);
  962. }
  963. }
  964. }
  965. return r;
  966. }
  967. api_region *Group::getRegion()
  968. {
  969. ensureScaledRegValid();
  970. return scaledreg;
  971. }
  972. void Group::ensureScaledRegValid()
  973. {
  974. if (!scaledregionvalid)
  975. {
  976. scaledregionvalid = 1;
  977. if (!reg) return ;
  978. if (!scaledreg) scaledreg = new RegionI;
  979. scaledreg->empty();
  980. scaledreg->addRegion(reg);
  981. RECT rr;
  982. getNonClientRect(&rr);
  983. if (background)
  984. {
  985. float w = (float)(rr.right - rr.left) / (float)background->getWidth();
  986. float h = (float)(rr.bottom - rr.top) / (float)background->getHeight();
  987. if (w && h && (ABS(w - 1.0f) > 0.01f || ABS(h - 1.0f) > 0.01f))
  988. scaledreg->scale(w, h, 1);
  989. else if (w == 0 || h == 0)
  990. {
  991. RECT r = {0, 0, 0, 0};
  992. scaledreg->setRect(&r);
  993. }
  994. }
  995. }
  996. }
  997. void Group::setRegion(api_region *r)
  998. {
  999. ASSERT(r != NULL);
  1000. if (!reg) reg = new RegionI;
  1001. reg->empty();
  1002. reg->addRegion(r); // background
  1003. invalidateWindowRegion();
  1004. invalidateScaledReg();
  1005. }
  1006. Container *Group::getParentContainer()
  1007. {
  1008. if (!getGuiObject()->guiobject_getParentGroup())
  1009. {
  1010. ifc_window *r = getDesktopParent();
  1011. if (r != NULL)
  1012. {
  1013. //ASSERT(r != NULL);
  1014. Layout *l = static_cast<Layout *>(r->getInterface(layoutGuid));
  1015. if (!l) return NULL;
  1016. return l->getParentContainer();
  1017. }
  1018. }
  1019. Group *g = getGuiObject()->guiobject_getParentGroup();
  1020. if (g) return g->getParentContainer();
  1021. return NULL;
  1022. }
  1023. ifc_window *Group::enumObjects(int i)
  1024. {
  1025. if (i >= gui_objects.getNumItems()) return NULL;
  1026. return gui_objects.enumItem(i)->guiobject_getRootWnd();
  1027. }
  1028. int Group::getNumObjects()
  1029. {
  1030. return gui_objects.getNumItems();
  1031. }
  1032. void Group::addChild(GuiObject *g)
  1033. {
  1034. gui_objects.addItem(g);
  1035. script_objects.addItem((ScriptObject *)g);
  1036. g->guiobject_setParentGroup(this);
  1037. g->guiobject_getRootWnd()->setParent(this);
  1038. if (!no_init_on_addchild && isInited()
  1039. && !g->guiobject_getRootWnd()->isInited())
  1040. g->guiobject_getRootWnd()->init(this);
  1041. }
  1042. void Group::removeChild(GuiObject *g)
  1043. {
  1044. if (!deleting)
  1045. gui_objects.removeItem(g);
  1046. script_objects.removeItem((ScriptObject *)g);
  1047. }
  1048. void Group::onCreateObject(GuiObject *o)
  1049. {
  1050. script_vcpu_onCreateObject(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(o->guiobject_getScriptObject()));
  1051. }
  1052. int Group::getDrawBackground()
  1053. {
  1054. return drawbackground;
  1055. }
  1056. void Group::setDrawBackground(int t)
  1057. {
  1058. drawbackground = t;
  1059. }
  1060. int Group::isLayout()
  1061. {
  1062. return 0;
  1063. }
  1064. int Group::isDesktopAlphaSafe()
  1065. {
  1066. if (!Wasabi::Std::Wnd::isDesktopAlphaAvailable()) return 0;
  1067. for (int i = 0;i < getNumObjects();i++)
  1068. {
  1069. ifc_window *w = enumObjects(i);
  1070. Group *cg = static_cast<Group *>(w);
  1071. if (Group::isGroup(cg))
  1072. if (!cg->isDesktopAlphaSafe()) return 0;
  1073. if (!w->handleDesktopAlpha()) return 0;
  1074. }
  1075. return 1;
  1076. }
  1077. int Group::isTransparencySafe(int excludeme)
  1078. {
  1079. if (!Wasabi::Std::Wnd::isTransparencyAvailable()) return 0;
  1080. if (!excludeme && isTransparencyForcedOff()) return 0;
  1081. for (int i = 0;i < getNumObjects();i++)
  1082. {
  1083. ifc_window *w = enumObjects(i);
  1084. Group *cg = static_cast<Group *>(w);
  1085. if (Group::isGroup(cg))
  1086. if (!cg->isTransparencySafe()) return 0;
  1087. if (!w->handleTransparency()) return 0;
  1088. }
  1089. return 1;
  1090. }
  1091. GuiObject *Group::getObject(const wchar_t *id)
  1092. {
  1093. for (int i = 0;i < script_objects.getNumItems();i++)
  1094. {
  1095. if (!WCSICMP(id, gui_objects.enumItem(i)->guiobject_getId()))
  1096. {
  1097. return gui_objects.enumItem(i);
  1098. }
  1099. }
  1100. return NULL;
  1101. }
  1102. void Group::setGroupContent(const wchar_t *id, SkinItem *item, int allowscripts)
  1103. {
  1104. content_id = id;
  1105. content_item = item;
  1106. scripts_enabled = allowscripts;
  1107. }
  1108. const wchar_t *Group::getGroupContentId()
  1109. {
  1110. return content_id;
  1111. }
  1112. SkinItem *Group::getGroupContentSkinItem()
  1113. {
  1114. return content_item;
  1115. }
  1116. ScriptObject *Group::script_cast(GUID g)
  1117. {
  1118. GuiObject *o = embeddedxui_getEmbeddedObject();
  1119. if (o != NULL)
  1120. {
  1121. void *r = o->guiobject_getScriptObject()->vcpu_getInterface(g);
  1122. if (r != NULL)
  1123. {
  1124. return o->guiobject_getScriptObject();
  1125. }
  1126. }
  1127. return NULL;
  1128. }
  1129. // -----------------------------------------------------------------------
  1130. GroupScriptController _groupController;
  1131. GroupScriptController *groupController = &_groupController;
  1132. // -- Functions table -------------------------------------
  1133. function_descriptor_struct GroupScriptController::exportedFunction[] = {
  1134. {L"getObject", 1, (void*)Group::script_vcpu_getObject },
  1135. {L"enumObject", 1, (void*)Group::script_vcpu_enumObject },
  1136. {L"getNumObjects", 0, (void*)Group::script_vcpu_getNumObjects },
  1137. {L"onCreateObject", 1, (void*)Group::script_vcpu_onCreateObject },
  1138. {L"getMousePosX", 0, (void*)Group::script_vcpu_getMousePosX },
  1139. {L"getMousePosY", 0, (void*)Group::script_vcpu_getMousePosY },
  1140. {L"isLayout", 0, (void*)Group::script_vcpu_isLayout },
  1141. {L"autoResize", 0, (void*)Group::script_vcpu_autoResize},
  1142. };
  1143. // --------------------------------------------------------
  1144. ScriptObject *GroupScriptController::cast(ScriptObject *o, GUID g)
  1145. {
  1146. Group *grp = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1147. if (grp != NULL)
  1148. return grp->script_cast(g);
  1149. return NULL;
  1150. }
  1151. const wchar_t *GroupScriptController::getClassName()
  1152. {
  1153. return L"Group";
  1154. }
  1155. const wchar_t *GroupScriptController::getAncestorClassName()
  1156. {
  1157. return L"GuiObject";
  1158. }
  1159. int GroupScriptController::getInstantiable()
  1160. {
  1161. return 1;
  1162. }
  1163. ScriptObject *GroupScriptController::instantiate()
  1164. {
  1165. return NULL;
  1166. }
  1167. void GroupScriptController::destroy(ScriptObject *o)
  1168. {}
  1169. void *GroupScriptController::encapsulate(ScriptObject *o)
  1170. {
  1171. return NULL;
  1172. }
  1173. void GroupScriptController::deencapsulate(void *o)
  1174. {}
  1175. int GroupScriptController::getNumFunctions()
  1176. {
  1177. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  1178. }
  1179. const function_descriptor_struct *GroupScriptController::getExportedFunctions()
  1180. {
  1181. return exportedFunction;
  1182. }
  1183. GUID GroupScriptController::getClassGuid()
  1184. {
  1185. return groupGuid;
  1186. }
  1187. const wchar_t *Group::vcpu_getClassName()
  1188. {
  1189. return L"Group";
  1190. }
  1191. void Group::addObject(GuiObject *o)
  1192. {
  1193. addChild(o);
  1194. }
  1195. void Group::removeObject(GuiObject *o)
  1196. {
  1197. removeChild(o);
  1198. }
  1199. void Group::setRegionOp(int o)
  1200. {
  1201. GROUP_PARENT::setRegionOp(o);
  1202. autoregionop = 0;
  1203. }
  1204. void Group::invalidateWindowRegion()
  1205. {
  1206. GROUP_PARENT::invalidateWindowRegion();
  1207. if (!isInited() || isLayout()) return ;
  1208. if (autoregionop)
  1209. {
  1210. int yes = 0;
  1211. for (int i = 0;i < gui_objects.getNumItems();i++)
  1212. {
  1213. if (gui_objects.enumItem(i)->guiobject_getRegionOp() != REGIONOP_NONE)
  1214. {
  1215. yes = 1;
  1216. break;
  1217. }
  1218. }
  1219. if (yes)
  1220. GROUP_PARENT::setRegionOp(REGIONOP_OR);
  1221. else
  1222. GROUP_PARENT::setRegionOp(REGIONOP_NONE);
  1223. }
  1224. }
  1225. // VCPU
  1226. scriptVar Group::script_vcpu_onCreateObject(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar ob)
  1227. {
  1228. SCRIPT_FUNCTION_INIT;
  1229. PROCESS_HOOKS1(o, groupController, ob);
  1230. SCRIPT_FUNCTION_CHECKABORTEVENT;
  1231. SCRIPT_EXEC_EVENT1(o, ob);
  1232. }
  1233. // Get an object from its ID
  1234. scriptVar Group::script_vcpu_getObject(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar obj)
  1235. {
  1236. SCRIPT_FUNCTION_INIT
  1237. ASSERT(obj.type == SCRIPT_STRING); // compiler discarded
  1238. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1239. GuiObject *ob = NULL;
  1240. if (g)
  1241. ob = g->getObject(GET_SCRIPT_STRING(obj));
  1242. return MAKE_SCRIPT_OBJECT(ob ? ob->guiobject_getScriptObject() : NULL);
  1243. }
  1244. scriptVar Group::script_vcpu_getMousePosX(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1245. {
  1246. SCRIPT_FUNCTION_INIT
  1247. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1248. if (g)
  1249. {
  1250. POINT pt;
  1251. Wasabi::Std::getMousePos(&pt);
  1252. g->screenToClient(&pt);
  1253. return MAKE_SCRIPT_INT(pt.x);
  1254. }
  1255. RETURN_SCRIPT_ZERO;
  1256. }
  1257. scriptVar Group::script_vcpu_getMousePosY(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1258. {
  1259. SCRIPT_FUNCTION_INIT
  1260. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1261. if (g)
  1262. {
  1263. POINT pt;
  1264. Wasabi::Std::getMousePos(&pt);
  1265. g->screenToClient(&pt);
  1266. return MAKE_SCRIPT_INT(pt.y);
  1267. }
  1268. RETURN_SCRIPT_ZERO;
  1269. }
  1270. scriptVar Group::script_vcpu_getNumObjects(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1271. {
  1272. SCRIPT_FUNCTION_INIT
  1273. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1274. if (g) return MAKE_SCRIPT_INT(g->getNumObjects());
  1275. RETURN_SCRIPT_ZERO;
  1276. }
  1277. scriptVar Group::script_vcpu_enumObject(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar i)
  1278. {
  1279. SCRIPT_FUNCTION_INIT
  1280. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1281. GuiObject *obj = NULL;
  1282. if (g)
  1283. obj = g->gui_objects.enumItem(GET_SCRIPT_INT(i));
  1284. return MAKE_SCRIPT_OBJECT(obj ? obj->guiobject_getScriptObject() : NULL);
  1285. }
  1286. scriptVar Group::script_vcpu_isLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1287. {
  1288. SCRIPT_FUNCTION_INIT
  1289. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1290. return MAKE_SCRIPT_BOOLEAN(g ? g->isLayout() : NULL);
  1291. }
  1292. scriptVar Group::script_vcpu_autoResize(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1293. {
  1294. SCRIPT_FUNCTION_INIT
  1295. Group *g = static_cast<Group *>(o->vcpu_getInterface(groupGuid));
  1296. if (g != NULL) g->autoResize();
  1297. RETURN_SCRIPT_VOID
  1298. }
  1299. #ifdef WASABI_COMPILE_CONFIG
  1300. int Group::isCfgGroup(Group *ptr)
  1301. {
  1302. CfgGroup *g = static_cast<CfgGroup *>(ptr);
  1303. return cfggrouplist.haveItem(g);
  1304. }
  1305. #endif
  1306. PtrList<CfgGroup> Group::cfggrouplist;
  1307. PtrList<Group> Group::groups;
  1308. // ---------------------------------------------------------------
  1309. // Config Groups
  1310. #ifdef WASABI_COMPILE_CONFIG
  1311. CfgGroup::CfgGroup()
  1312. {
  1313. getScriptObject()->vcpu_setInterface(cfgGroupGuid, (void *)static_cast<CfgGroup *>(this));
  1314. getScriptObject()->vcpu_setClassName(L"CfgGroup");
  1315. getScriptObject()->vcpu_setController(cfgGroupController);
  1316. cfgitem = NULL;
  1317. cfggrouplist.addItem(this);
  1318. }
  1319. CfgGroup::~CfgGroup()
  1320. {
  1321. if (cfgitem) viewer_delViewItem(cfgitem);
  1322. cfggrouplist.removeItem(this);
  1323. }
  1324. const wchar_t *CfgGroup::vcpu_getClassName()
  1325. {
  1326. return L"CfgGroup";
  1327. }
  1328. void CfgGroup::setAttr(CfgItem *item, const wchar_t *name)
  1329. {
  1330. if (cfgitem) viewer_delViewItem(cfgitem);
  1331. cfgitem = item;
  1332. attrname = name;
  1333. if (cfgitem != NULL)
  1334. {
  1335. wchar_t t[256] = L"";
  1336. nsGUID::toCharW(cfgitem->getGuid(), t);
  1337. cfgguid = t;
  1338. }
  1339. if (cfgitem) viewer_addViewItem(cfgitem);
  1340. dataChanged();
  1341. }
  1342. int CfgGroup::viewer_onEvent(CfgItem *item, int event, intptr_t param, void *ptr, size_t ptrlen)
  1343. {
  1344. dataChanged();
  1345. return 1;
  1346. }
  1347. int CfgGroup::onInit()
  1348. {
  1349. int r = Group::onInit();
  1350. dataChanged();
  1351. return r;
  1352. }
  1353. void CfgGroup::dataChanged()
  1354. {
  1355. script_vcpu_onCfgChanged(SCRIPT_CALL, getScriptObject());
  1356. }
  1357. CfgItem *CfgGroup::getCfgItem()
  1358. {
  1359. return cfgitem;
  1360. }
  1361. const wchar_t *CfgGroup::getAttributeName()
  1362. {
  1363. return attrname;
  1364. }
  1365. scriptVar CfgGroup::script_vcpu_cfgGetInt(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1366. {
  1367. SCRIPT_FUNCTION_INIT
  1368. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1369. if (cg)
  1370. {
  1371. CfgItem *i = cg->getCfgItem();
  1372. const wchar_t *attrname = cg->getAttributeName();
  1373. if (o != NULL && attrname != NULL)
  1374. return MAKE_SCRIPT_INT(i->getDataAsInt(attrname, 0));
  1375. }
  1376. return MAKE_SCRIPT_INT(0);
  1377. }
  1378. scriptVar CfgGroup::script_vcpu_cfgSetInt(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar v)
  1379. {
  1380. SCRIPT_FUNCTION_INIT
  1381. ASSERT(SOM::isNumeric(&v));
  1382. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1383. if (cg)
  1384. {
  1385. CfgItem *i = cg->getCfgItem();
  1386. const wchar_t *attrname = cg->getAttributeName();
  1387. if (o != NULL && attrname != NULL)
  1388. {
  1389. i->setDataAsInt(attrname, GET_SCRIPT_INT(v));
  1390. }
  1391. }
  1392. RETURN_SCRIPT_VOID;
  1393. }
  1394. scriptVar CfgGroup::script_vcpu_cfgGetString(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1395. {
  1396. SCRIPT_FUNCTION_INIT
  1397. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1398. if (cg)
  1399. {
  1400. CfgItem *i = cg->getCfgItem();
  1401. const wchar_t *a = cg->getAttributeName();
  1402. *txt = 0;
  1403. if (!i || !a)
  1404. return MAKE_SCRIPT_STRING(txt);
  1405. if (o != NULL && a != NULL)
  1406. {
  1407. i->getData(a, txt, 512);
  1408. }
  1409. return MAKE_SCRIPT_STRING(txt);
  1410. }
  1411. return MAKE_SCRIPT_STRING(L"");
  1412. }
  1413. scriptVar CfgGroup::script_vcpu_cfgSetString(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar v)
  1414. {
  1415. SCRIPT_FUNCTION_INIT
  1416. ASSERT(!SOM::isNumeric(&v));
  1417. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1418. if (cg)
  1419. {
  1420. CfgItem *i = cg->getCfgItem();
  1421. const wchar_t *a = cg->getAttributeName();
  1422. if (!i || !a) RETURN_SCRIPT_VOID;
  1423. if (o != NULL && a != NULL)
  1424. {
  1425. i->setData(a, GET_SCRIPT_STRING(v));
  1426. }
  1427. }
  1428. RETURN_SCRIPT_VOID;
  1429. }
  1430. scriptVar CfgGroup::script_vcpu_cfgGetFloat(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1431. {
  1432. SCRIPT_FUNCTION_INIT
  1433. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1434. if (cg)
  1435. {
  1436. CfgItem *i = cg->getCfgItem();
  1437. const wchar_t *attrname = cg->getAttributeName();
  1438. if (o != NULL && attrname != NULL)
  1439. return MAKE_SCRIPT_FLOAT((float)i->getDataAsFloat(attrname, 0));
  1440. }
  1441. return MAKE_SCRIPT_FLOAT(0);
  1442. }
  1443. scriptVar CfgGroup::script_vcpu_cfgSetFloat(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar v)
  1444. {
  1445. SCRIPT_FUNCTION_INIT
  1446. ASSERT(SOM::isNumeric(&v));
  1447. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1448. if (cg)
  1449. {
  1450. CfgItem *i = cg->getCfgItem();
  1451. const wchar_t *attrname = cg->getAttributeName();
  1452. if (o != NULL && attrname != NULL)
  1453. {
  1454. i->setDataAsFloat(attrname, GET_SCRIPT_FLOAT(v));
  1455. }
  1456. }
  1457. RETURN_SCRIPT_VOID;
  1458. }
  1459. scriptVar CfgGroup::script_vcpu_cfgGetName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1460. {
  1461. SCRIPT_FUNCTION_INIT
  1462. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1463. if (cg)
  1464. {
  1465. return MAKE_SCRIPT_STRING(cg->getAttributeName());
  1466. }
  1467. return MAKE_SCRIPT_STRING(L"");
  1468. }
  1469. scriptVar CfgGroup::script_vcpu_cfgGetGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1470. {
  1471. SCRIPT_FUNCTION_INIT
  1472. CfgGroup *cg = static_cast<CfgGroup *>(o->vcpu_getInterface(cfgGroupGuid));
  1473. if (cg)
  1474. return MAKE_SCRIPT_STRING(cg->getCfgGuid());
  1475. return MAKE_SCRIPT_STRING(L"");
  1476. }
  1477. scriptVar CfgGroup::script_vcpu_onCfgChanged(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  1478. {
  1479. SCRIPT_FUNCTION_INIT;
  1480. PROCESS_HOOKS0(o, cfgGroupController);
  1481. SCRIPT_FUNCTION_CHECKABORTEVENT;
  1482. SCRIPT_EXEC_EVENT0(o);
  1483. }
  1484. CfgGroupScriptController _cfgGroupController;
  1485. CfgGroupScriptController *cfgGroupController = &_cfgGroupController;
  1486. // -- Functions table -------------------------------------
  1487. function_descriptor_struct CfgGroupScriptController::exportedFunction[] = {
  1488. {L"cfgGetInt", 0, (void*)CfgGroup::script_vcpu_cfgGetInt },
  1489. {L"cfgSetInt", 1, (void*)CfgGroup::script_vcpu_cfgSetInt },
  1490. {L"cfgGetFloat", 0, (void*)CfgGroup::script_vcpu_cfgGetFloat },
  1491. {L"cfgSetFloat", 1, (void*)CfgGroup::script_vcpu_cfgSetFloat },
  1492. {L"cfgGetString", 0, (void*)CfgGroup::script_vcpu_cfgGetString },
  1493. {L"cfgSetString", 1, (void*)CfgGroup::script_vcpu_cfgSetString },
  1494. {L"onCfgChanged", 0, (void*)CfgGroup::script_vcpu_onCfgChanged },
  1495. {L"cfgGetName", 0, (void*)CfgGroup::script_vcpu_cfgGetName },
  1496. {L"cfgGetGuid", 0, (void*)CfgGroup::script_vcpu_cfgGetGuid},
  1497. };
  1498. /*SET_HIERARCHY(Group, SCRIPT_LAYOUT);
  1499. SET_HIERARCHY2(Group, SCRIPT_LAYOUT, LAYOUT_SCRIPTPARENT);*/
  1500. const wchar_t *CfgGroupScriptController::getClassName()
  1501. {
  1502. return L"CfgGroup";
  1503. }
  1504. const wchar_t *CfgGroupScriptController::getAncestorClassName()
  1505. {
  1506. return L"Group";
  1507. }
  1508. int CfgGroupScriptController::getInstantiable()
  1509. {
  1510. return 1;
  1511. }
  1512. ScriptObject *CfgGroupScriptController::instantiate()
  1513. {
  1514. return NULL;
  1515. }
  1516. int CfgGroupScriptController::getNumFunctions()
  1517. {
  1518. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  1519. }
  1520. const function_descriptor_struct *CfgGroupScriptController::getExportedFunctions()
  1521. {
  1522. return exportedFunction;
  1523. }
  1524. GUID CfgGroupScriptController::getClassGuid()
  1525. {
  1526. return cfgGroupGuid;
  1527. }
  1528. wchar_t CfgGroup::txt[512] = L"";
  1529. #endif // config