1
0

container.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. #include <precomp.h>
  2. #include "wasabicfg.h"
  3. #include <api/wndmgr/container.h>
  4. #include <api/script/script.h>
  5. #include <api/script/scriptmgr.h>
  6. #include <api/config/items/attrbool.h>
  7. #include <api/config/items/cfgitem.h>
  8. #include <api/skin/skinparse.h>
  9. #include <api/wac/compon.h>
  10. #include <api/wnd/wndtrack.h>
  11. #include <api/skin/skin.h>
  12. #include <api/wndmgr/skinembed.h>
  13. #include <api/syscb/callbacks/wndcb.h>
  14. #include <bfc/string/stringdict.h>
  15. #include <api/skin/widgets/xuiwndholder.h> // TODO: cut, but we need XuiWindowHolder::parseGUID for now
  16. #include <bfc/platform/guid.h>
  17. #ifdef WIN32
  18. #include "resource.h"
  19. #include "../Agave/Language/api_language.h"
  20. #endif
  21. BEGIN_STRINGDICTIONARY(_containerparams)
  22. SDI(L"name", CONTAINERPARAM_NAME);
  23. SDI(L"id", CONTAINERPARAM_ID);
  24. SDI(L"dynamic", CONTAINERPARAM_DYNAMIC);
  25. SDI(L"default_x", CONTAINERPARAM_DEFAULTX);
  26. SDI(L"default_y", CONTAINERPARAM_DEFAULTY);
  27. SDI(L"default_visible", CONTAINERPARAM_DEFAULTVISIBLE);
  28. SDI(L"canclose", CONTAINERPARAM_CANCLOSE);
  29. SDI(L"nomenu", CONTAINERPARAM_NOMENU);
  30. SDI(L"nofocusapponclose", CONTAINERPARAM_NOFOCUSAPPONCLOSE);
  31. SDI(L"primarycomponent", CONTAINERPARAM_CONTENT);
  32. END_STRINGDICTIONARY(_containerparams, containerparams);
  33. Container::Container(int script_id)
  34. {
  35. getScriptObject()->vcpu_setInterface(containerGuid, (void *)static_cast<Container *>(this));
  36. getScriptObject()->vcpu_setClassName(L"Container");
  37. getScriptObject()->vcpu_setController(containerController);
  38. scriptid = script_id;
  39. currentLayout = -1;
  40. default_visible = TRUE;
  41. loaded_default_visible = TRUE;
  42. dynamic = 0;
  43. MEMCPY(&myGUID, &INVALID_GUID, sizeof(GUID));
  44. lastLayout = -1;
  45. refocusapponclose = 1;
  46. canclose = 1;
  47. inited = 0;
  48. deleting = 0;
  49. transcient = 0;
  50. switching_layout = 0;
  51. nomenu = 0;
  52. prevent_save_visibility = 0;
  53. contentGuid = INVALID_GUID;
  54. hasContentGuid=false;
  55. }
  56. void Container::setName(const wchar_t *name)
  57. {
  58. #ifdef ON_TWEAK_CONTAINER_NAMEW
  59. ON_TWEAK_CONTAINER_NAMEW(name);
  60. #endif
  61. containerName = name ? name : CONTAINER_UNDEFINED_NAME;
  62. foreach(layouts)
  63. Layout *l = layouts.getfor();
  64. if (l->getRootWndName() == NULL)
  65. {
  66. l->setOSWndName(name);
  67. }
  68. endfor;
  69. updateDefaultVisible();
  70. dependent_sendEvent(Container::depend_getClassGuid(), Event_NAMECHANGE, 0, this);
  71. }
  72. void Container::resetLayouts()
  73. {
  74. updateDefaultVisible();
  75. foreach(layouts)
  76. layouts.getfor()->loadSavedState();
  77. endfor;
  78. }
  79. void Container::setId(const wchar_t *id)
  80. {
  81. containerId = id ? id : L"undefined";
  82. ismain = !WCSICMP(id, L"main");
  83. }
  84. int Container::setXmlParam(const wchar_t *paramname, const wchar_t *strvalue)
  85. {
  86. switch (containerparams.getId(paramname))
  87. {
  88. case CONTAINERPARAM_NAME:
  89. setName(strvalue);
  90. return 1;
  91. case CONTAINERPARAM_ID:
  92. setId(strvalue);
  93. return 1;
  94. case CONTAINERPARAM_DYNAMIC:
  95. setDynamic(WTOI(strvalue));
  96. return 1;
  97. case CONTAINERPARAM_DEFAULTX:
  98. default_x = WTOI(strvalue);
  99. return 1;
  100. case CONTAINERPARAM_DEFAULTY:
  101. default_y = WTOI(strvalue);
  102. return 1;
  103. case CONTAINERPARAM_DEFAULTVISIBLE:
  104. default_visible = WTOI(strvalue);
  105. updateDefaultVisible();
  106. return 1;
  107. case CONTAINERPARAM_CANCLOSE:
  108. canclose = WTOI(strvalue);
  109. return 1;
  110. case CONTAINERPARAM_NOMENU:
  111. nomenu = WTOI(strvalue);
  112. return 1;
  113. case CONTAINERPARAM_NOFOCUSAPPONCLOSE:
  114. refocusapponclose = !WTOI(strvalue);
  115. break;
  116. case CONTAINERPARAM_CONTENT:
  117. {
  118. // TODO: move this out of XuiWindowHolder
  119. GUID *g = XuiWindowHolder::parseGUID(strvalue);
  120. contentGuid = *g;
  121. hasContentGuid=true;
  122. break;
  123. }
  124. }
  125. return 0;
  126. }
  127. Container::~Container()
  128. {
  129. containerCallback(CONT_CB_HIDDEN);
  130. layouts.deleteAll();
  131. contents.deleteAll();
  132. SkinParser::containers.removeItem(this);
  133. }
  134. void Container::getWindowRect(RECT *r)
  135. {
  136. Layout *l = getCurrentLayout();
  137. if (l)
  138. l->getWindowRect(r);
  139. }
  140. void Container::addLayout(Layout *layout)
  141. {
  142. layouts.addItem(layout);
  143. }
  144. const wchar_t *Container::getName()
  145. {
  146. return containerName;
  147. }
  148. const wchar_t *Container::getId()
  149. {
  150. return containerId;
  151. }
  152. int Container::getDefaultPositionX(void)
  153. {
  154. return default_x;
  155. }
  156. int Container::getDefaultPositionY(void)
  157. {
  158. return default_y;
  159. }
  160. void Container::onInit(int noshow)
  161. {
  162. if (inited) return ;
  163. inited++;
  164. loadFromDefaults(noshow);
  165. }
  166. void Container::loadFromDefaults(int noshow)
  167. {
  168. #ifdef WASABI_COMPILE_CONFIG
  169. if (last_layout.isempty())
  170. {
  171. StringPrintfW tmp(L"container_%s|active", getName());
  172. wchar_t c[512] = {0};
  173. WASABI_API_CONFIG->getStringPrivate(tmp, c, 511, L"");
  174. c[510] = 0;
  175. last_layout = c;
  176. }
  177. #endif
  178. if (loaded_default_visible)
  179. {
  180. showDefaultLayout(noshow);
  181. }
  182. }
  183. void Container::setDefaultLayout(const wchar_t *name)
  184. {
  185. last_layout = name;
  186. }
  187. void Container::showDefaultLayout(int noshow)
  188. {
  189. Layout *l = getLayout(last_layout);
  190. if (!l)
  191. l = layouts.enumItem(0);
  192. if (l)
  193. {
  194. currentLayout = layouts.searchItem(l);
  195. if (!noshow)
  196. l->setVisible(1);
  197. containerCallback(CONT_CB_VISIBLE); // since we set currentLayout prior to showing the layout, the callback will not be processed in onChildSetLayoutVisible
  198. }
  199. }
  200. void Container::setVisible(int sh)
  201. {
  202. if (!sh && !canclose)
  203. return ;
  204. int is = isVisible();
  205. if (!!sh == !!is)
  206. return ;
  207. Layout *l = getCurrentLayout();
  208. if (!l && lastLayout != -1)
  209. l = layouts[lastLayout];
  210. if (sh)
  211. {
  212. if (!l)
  213. showDefaultLayout();
  214. else
  215. {
  216. l->setVisible(1);
  217. }
  218. }
  219. else
  220. {
  221. if (l)
  222. l->setVisible(0);
  223. }
  224. }
  225. int Container::isVisible()
  226. {
  227. if (switching_layout) return 1;
  228. Layout *l = getCurrentLayout();
  229. if (!l) return 0;
  230. return l->isVisible();
  231. }
  232. void Container::onChildSetLayoutVisible(Layout *l, int v)
  233. {
  234. for (int i = 0;i < layouts.getNumItems();i++)
  235. {
  236. if (layouts[i] == l)
  237. {
  238. if (v)
  239. {
  240. if (currentLayout != i)
  241. {
  242. Layout *l = NULL;
  243. if (currentLayout >= 0)
  244. l = layouts[currentLayout];
  245. if (l) l->setVisible(0);
  246. containerCallback(CONT_CB_VISIBLE);
  247. currentLayout = i;
  248. l = layouts[currentLayout];
  249. #ifdef WASABI_COMPILE_CONFIG
  250. if (!isTranscient() && !prevent_save_visibility)
  251. WASABI_API_CONFIG->setStringPrivate(StringPrintfW(L"container_%s|active", getName()), l->getGuiObject()->guiobject_getId());
  252. #endif
  253. #ifdef WA3COMPATIBILITY
  254. l->setForwardMsgWnd(WASABI_API_WND->main_getRootWnd()->gethWnd());
  255. #endif
  256. if (l->wantActivation())
  257. {
  258. l->bringToFront();
  259. l->setFocus();
  260. }
  261. l->invalidate();
  262. }
  263. #ifdef WASABI_COMPILE_CONFIG
  264. if (!isTranscient() && !isDynamic() && !prevent_save_visibility)
  265. WASABI_API_CONFIG->setIntPrivate(StringPrintfW(L"activated/%s", getName()), v);
  266. WASABI_API_CONFIG->setIntPrivate(StringPrintfW(L"everloaded/%s", getName()), 1);
  267. #endif
  268. }
  269. else
  270. {
  271. if (i == currentLayout)
  272. {
  273. if (!isDeleting() && !isTranscient() && !isDynamic())
  274. {
  275. #ifdef WASABI_COMPILE_CONFIG
  276. WASABI_API_CONFIG->setIntPrivate(StringPrintfW(L"activated/%s", getName()), v);
  277. #endif
  278. lastLayout = currentLayout;
  279. currentLayout = -1;
  280. }
  281. containerCallback(CONT_CB_HIDDEN);
  282. }
  283. }
  284. return ;
  285. }
  286. }
  287. }
  288. void Container::containerCallback(int msg)
  289. {
  290. switch (msg)
  291. {
  292. case CONT_CB_VISIBLE:
  293. {
  294. foreach(contents)
  295. ContentEntry *e = contents.getfor();
  296. WndInfo i;
  297. i.groupid = e->groupid;
  298. i.guid = e->guid;
  299. i.c = this;
  300. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::WINDOW, WndCallback::SHOWWINDOW, reinterpret_cast<intptr_t>(&i));
  301. endfor
  302. WndInfo i;
  303. i.groupid = getId();
  304. i.guid = INVALID_GUID;
  305. i.c = this;
  306. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::WINDOW, WndCallback::SHOWWINDOW, reinterpret_cast<intptr_t>(&i));
  307. }
  308. break;
  309. case CONT_CB_HIDDEN:
  310. {
  311. foreach(contents)
  312. ContentEntry *e = contents.getfor();
  313. WndInfo i;
  314. i.groupid = e->groupid;
  315. i.guid = e->guid;
  316. i.c = this;
  317. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::WINDOW, WndCallback::HIDEWINDOW, reinterpret_cast<intptr_t>(&i));
  318. endfor
  319. WndInfo i;
  320. i.groupid = getId();
  321. i.guid = INVALID_GUID;
  322. i.c = this;
  323. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::WINDOW, WndCallback::HIDEWINDOW, reinterpret_cast<intptr_t>(&i));
  324. }
  325. break;
  326. }
  327. }
  328. void Container::close()
  329. {
  330. int norefocs = !wantRefocusApp();
  331. if (norefocs) WASABI_API_WND->appdeactivation_push_disallow(NULL);
  332. if (!canclose) return ;
  333. if (isDynamic())
  334. {
  335. setVisible(0);
  336. skinEmbedder->destroyContainer(this); // deferred
  337. }
  338. else
  339. setVisible(0);
  340. if (norefocs) WASABI_API_WND->appdeactivation_pop_disallow(NULL);
  341. }
  342. void Container::toggle()
  343. {
  344. if (isVisible()) close(); else setVisible(1); // close has special function hide/destroy depending on dynamic status
  345. }
  346. void Container::switchToLayout(const wchar_t *name, int moveit)
  347. {
  348. int l = -1;
  349. getLayout(name, &l);
  350. if (l == -1)
  351. {
  352. // Layout not found, reverting to first in the list
  353. if (layouts.getNumItems() > 0) l = 0;
  354. else
  355. return ; // none found, abort
  356. }
  357. switching_layout = 1;
  358. if (l != currentLayout)
  359. {
  360. int old = currentLayout;
  361. RECT r = {0};
  362. Layout *oldlayout = old >= 0 ? layouts[old] : NULL;
  363. Layout *newlayout = layouts[l];
  364. onBeforeSwitchToLayout(oldlayout, newlayout);
  365. if (oldlayout)
  366. {
  367. oldlayout->getWindowRect(&r);
  368. oldlayout->endCapture();
  369. }
  370. int unlinked = layouts[l]->isUnlinked();
  371. unlinked |= oldlayout ? oldlayout->isUnlinked() : 0;
  372. if (moveit && !unlinked && oldlayout)
  373. layouts[l]->move(r.left, r.top);
  374. #ifdef WASABI_COMPILE_CONFIG
  375. // {9149C445-3C30-4e04-8433-5A518ED0FDDE}
  376. const GUID uioptions_guid =
  377. { 0x9149c445, 0x3c30, 0x4e04, { 0x84, 0x33, 0x5a, 0x51, 0x8e, 0xd0, 0xfd, 0xde } };
  378. if (_intVal(WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid), L"Link layouts scale"))
  379. {
  380. #else
  381. if (WASABI_WNDMGR_LINKLAYOUTSCALES)
  382. {
  383. #endif
  384. if (oldlayout)
  385. {
  386. double _r = oldlayout->getRenderRatio();
  387. newlayout->setRenderRatio(_r);
  388. }
  389. }
  390. #ifdef WASABI_COMPILE_CONFIG
  391. if (_intVal(WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid), L"Link layouts alpha"))
  392. {
  393. #else
  394. if (WASABI_WNDMGR_LINKLAYOUTSALPHA)
  395. {
  396. #endif
  397. if (oldlayout)
  398. {
  399. int a = layouts[old]->getAlpha();
  400. newlayout->setAlpha(a);
  401. int autoopacify = layouts[old]->getAutoOpacify();
  402. newlayout->setAutoOpacify(autoopacify);
  403. }
  404. }
  405. WindowTracker::layoutChanged(oldlayout, newlayout);
  406. #ifdef ON_LAYOUT_CHANGED
  407. ON_LAYOUT_CHANGED;
  408. #endif
  409. layouts[l]->setVisible(1);
  410. foreach(SkinParser::containers)
  411. SkinParser::containers.getfor()->savePositions();
  412. endfor
  413. onSwitchToLayout(newlayout);
  414. }
  415. switching_layout = 0;
  416. }
  417. void Container::savePositions()
  418. {
  419. foreach (layouts)
  420. layouts.getfor()->savePosition();
  421. endfor
  422. }
  423. Layout *Container::getLayout(const wchar_t *name, int *pos)
  424. {
  425. for ( int i = 0; i < getNumLayouts(); i++ )
  426. {
  427. if ( WCSCASEEQLSAFE( enumLayout( i )->getGuiObject()->guiobject_getId(), name ) )
  428. {
  429. if (pos)
  430. {
  431. *pos = i;
  432. }
  433. return enumLayout( i );
  434. }
  435. }
  436. return NULL;
  437. }
  438. Layout *Container::getCurrentLayout()
  439. {
  440. if (currentLayout < 0)
  441. return NULL;
  442. return layouts.enumItem(currentLayout);
  443. }
  444. void Container::otherContainerToggled(const wchar_t *id, int visible)
  445. {
  446. for (int i = 0;i < layouts.getNumItems();i++)
  447. layouts[i]->containerToggled(id, visible);
  448. }
  449. void Container::componentToggled(GUID *g, int visible)
  450. {
  451. for (int i = 0;i < layouts.getNumItems();i++)
  452. layouts[i]->componentToggled(g, visible);
  453. }
  454. void Container::sendNotifyToAllLayouts(int notifymsg, int param1, int param2)
  455. {
  456. for (int i = 0;i < layouts.getNumItems();i++)
  457. layouts[i]->sendNotifyToAllChildren(notifymsg, param1, param2);
  458. }
  459. int Container::isMainContainer()
  460. {
  461. return ismain;
  462. }
  463. void Container::sysMenu()
  464. {
  465. POINT p;
  466. Wasabi::Std::getMousePos(&p);
  467. layouts.enumItem(currentLayout)->onRightButtonDown(p.x, p.y);
  468. }
  469. void Container::setDynamic(int i)
  470. {
  471. dynamic = i;
  472. if (!containerId.isempty())
  473. setId(containerId);
  474. }
  475. int Container::isDynamic()
  476. {
  477. return dynamic;
  478. }
  479. void Container::onSwitchToLayout(Layout *l)
  480. {
  481. ScriptObject *ls = l ? l->getGuiObject()->guiobject_getScriptObject() : NULL;
  482. script_onSwitchToLayout(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(ls));
  483. }
  484. void Container::onBeforeSwitchToLayout(Layout *oldl, Layout *newl)
  485. {
  486. ScriptObject *olds = oldl ? oldl->getGuiObject()->guiobject_getScriptObject() : NULL;
  487. ScriptObject *news = newl ? newl->getGuiObject()->guiobject_getScriptObject() : NULL;
  488. script_onBeforeSwitchToLayout(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(olds), MAKE_SCRIPT_OBJECT(news));
  489. }
  490. void Container::onHideLayout(Layout *l)
  491. {
  492. script_onHideLayout(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(l->getGuiObject()->guiobject_getScriptObject()));
  493. }
  494. void Container::onShowLayout(Layout *l)
  495. {
  496. script_onShowLayout(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(l->getGuiObject()->guiobject_getScriptObject()));
  497. }
  498. int Container::getNumLayouts()
  499. {
  500. return layouts.getNumItems();
  501. }
  502. Layout *Container::enumLayout(int n)
  503. {
  504. return layouts.enumItem(n);
  505. }
  506. const wchar_t *Container::getDescriptor()
  507. {
  508. static wchar_t d[256];
  509. // if we've tweaked the container names then when saving out we can see and attempt to 'untweak'
  510. // so that things like Winamp Modern's ML will be correctly positioned irrespective of language
  511. int untweak = 0;
  512. wchar_t tweaked[96] = {0};
  513. // Martin> We need to check the containerName against null - dunno why some skins cause this string to be null
  514. if(containerName.v() != NULL && !_wcsicmp(containerName.v(), WASABI_API_LNGSTRINGW_BUF(IDS_MEDIA_LIBRARY,tweaked,96))){
  515. untweak = 1;
  516. }
  517. WCSNPRINTF(d, 256,L"%s/%s", getId(), (!untweak ? containerName.v() : L"Media Library"));
  518. return d;
  519. }
  520. void Container::updateDefaultVisible()
  521. {
  522. if (!canclose)
  523. {
  524. loaded_default_visible = 1;
  525. return ;
  526. }
  527. #ifdef WASABI_COMPILE_CONFIG
  528. loaded_default_visible = WASABI_API_CONFIG->getIntPrivate(StringPrintfW(L"activated/%s", getName()), default_visible);
  529. #else
  530. loaded_default_visible = default_visible;
  531. #endif
  532. }
  533. int Container::getScriptId()
  534. {
  535. return scriptid;
  536. }
  537. void Container::notifyAddContent(ifc_window *w, const wchar_t *id, GUID g)
  538. {
  539. contents.addItem(new ContentEntry(id, g, w));
  540. ScriptObject *_w = w ? w->getGuiObject()->guiobject_getScriptObject() : NULL;
  541. wchar_t guidstr[256] = {0};
  542. nsGUID::toCharW(g, guidstr);
  543. script_onAddContent(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_OBJECT(_w), MAKE_SCRIPT_STRING(id), MAKE_SCRIPT_STRING(guidstr));
  544. }
  545. void Container::notifyRemoveContent(ifc_window *w)
  546. {
  547. foreach(contents)
  548. ContentEntry *e = contents.getfor();
  549. if (e->wnd == w)
  550. {
  551. contents.removeItem(e);
  552. delete e;
  553. return ;
  554. }
  555. endfor;
  556. }
  557. int Container::hasContent(GUID g)
  558. {
  559. foreach(contents)
  560. ContentEntry *e = contents.getfor();
  561. if (e->guid == g)
  562. {
  563. return 1;
  564. }
  565. endfor;
  566. return 0;
  567. }
  568. GUID Container::getDefaultContent()
  569. {
  570. if (hasContentGuid)
  571. return contentGuid;
  572. if (contents.getNumItems() > 0) return contents.enumItem(0)->guid;
  573. return INVALID_GUID;
  574. }
  575. ContainerScriptController _containerController;
  576. ContainerScriptController *containerController = &_containerController;
  577. // -- Functions table -------------------------------------
  578. function_descriptor_struct ContainerScriptController::exportedFunction[] = {
  579. {L"onSwitchToLayout", 1, (void*)Container::script_onSwitchToLayout },
  580. {L"onBeforeSwitchToLayout", 2, (void*)Container::script_onBeforeSwitchToLayout },
  581. {L"onHideLayout", 1, (void*)Container::script_onHideLayout },
  582. {L"onShowLayout", 1, (void*)Container::script_onShowLayout },
  583. {L"getLayout", 1, (void*)Container::script_getLayout },
  584. {L"getNumLayouts", 0, (void*)Container::script_getNumLayouts },
  585. {L"enumLayout", 1, (void*)Container::script_enumLayout },
  586. {L"getCurLayout", 0, (void*)Container::script_getCurrentLayout},
  587. {L"switchToLayout", 1, (void*)Container::script_switchToLayout },
  588. {L"isDynamic", 0, (void*)Container::script_isDynamic },
  589. {L"show", 0, (void*)Container::script_show },
  590. {L"hide", 0, (void*)Container::script_hide },
  591. {L"close", 0, (void*)Container::script_close},
  592. {L"toggle", 0, (void*)Container::script_toggle },
  593. {L"setName", 1, (void*)Container::script_setName },
  594. {L"getName", 0, (void*)Container::script_getName },
  595. {L"getGuid", 0, (void*)Container::script_getGuid },
  596. {L"setXmlParam", 2, (void*)Container::script_setXmlParam},
  597. {L"onAddContent", 3, (void*)Container::script_onAddContent},
  598. };
  599. // --------------------------------------------------------
  600. /*SET_HIERARCHY(Container, SCRIPT_CONTAINER);
  601. SET_HIERARCHY2(Container, SCRIPT_CONTAINER, CONTAINER_SCRIPTPARENT);*/
  602. const wchar_t *ContainerScriptController::getClassName()
  603. {
  604. return L"Container";
  605. }
  606. const wchar_t *ContainerScriptController::getAncestorClassName()
  607. {
  608. return L"Object";
  609. }
  610. ScriptObjectController *ContainerScriptController::getAncestorController()
  611. {
  612. return rootScriptObjectController;
  613. }
  614. int ContainerScriptController::getInstantiable()
  615. {
  616. return 1;
  617. }
  618. ScriptObject *ContainerScriptController::instantiate()
  619. {
  620. Container *c = new Container;
  621. return c->getScriptObject();
  622. }
  623. void ContainerScriptController::destroy(ScriptObject *o)
  624. {
  625. //ASSERTALWAYS("be nice, don't do that");
  626. Container *c = (Container *)o->vcpu_getInterface(containerGuid);
  627. delete c;
  628. }
  629. void *ContainerScriptController::encapsulate(ScriptObject *o)
  630. {
  631. return NULL;
  632. }
  633. void ContainerScriptController::deencapsulate(void *o)
  634. {}
  635. int ContainerScriptController::getNumFunctions()
  636. {
  637. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  638. }
  639. const function_descriptor_struct *ContainerScriptController::getExportedFunctions()
  640. {
  641. return exportedFunction;
  642. }
  643. GUID ContainerScriptController::getClassGuid()
  644. {
  645. return containerGuid;
  646. }
  647. //-----------------------------------------------------------------------
  648. scriptVar Container::script_onSwitchToLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar l)
  649. {
  650. SCRIPT_FUNCTION_INIT;
  651. PROCESS_HOOKS1(o, containerController, l);
  652. SCRIPT_FUNCTION_CHECKABORTEVENT;
  653. SCRIPT_EXEC_EVENT1(o, l);
  654. }
  655. scriptVar Container::script_onBeforeSwitchToLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar oldl, scriptVar newl)
  656. {
  657. SCRIPT_FUNCTION_INIT;
  658. PROCESS_HOOKS2(o, containerController, oldl, newl);
  659. SCRIPT_FUNCTION_CHECKABORTEVENT;
  660. SCRIPT_EXEC_EVENT2(o, oldl, newl);
  661. }
  662. scriptVar Container::script_onHideLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar l)
  663. {
  664. SCRIPT_FUNCTION_INIT;
  665. PROCESS_HOOKS1(o, containerController, l);
  666. SCRIPT_FUNCTION_CHECKABORTEVENT;
  667. SCRIPT_EXEC_EVENT1(o, l);
  668. }
  669. scriptVar Container::script_onShowLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar l)
  670. {
  671. SCRIPT_FUNCTION_INIT;
  672. PROCESS_HOOKS1(o, containerController, l);
  673. SCRIPT_FUNCTION_CHECKABORTEVENT;
  674. SCRIPT_EXEC_EVENT1(o, l);
  675. }
  676. // Get an layout from its ID
  677. scriptVar Container::script_getLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar obj)
  678. {
  679. SCRIPT_FUNCTION_INIT
  680. ASSERT(obj.type == SCRIPT_STRING); // compiler discarded
  681. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  682. if (c)
  683. {
  684. for (int i = 0;i < c->layouts.getNumItems();i++)
  685. if (!WCSICMP(obj.data.sdata, c->layouts.enumItem(i)->getGuiObject()->guiobject_getId()))
  686. {
  687. return MAKE_SCRIPT_OBJECT(c->layouts.enumItem(i)->getGuiObject()->guiobject_getScriptObject());
  688. }
  689. }
  690. RETURN_SCRIPT_ZERO;
  691. }
  692. scriptVar Container::script_show(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  693. {
  694. SCRIPT_FUNCTION_INIT
  695. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  696. if (c) c->setVisible(1);
  697. RETURN_SCRIPT_VOID;
  698. }
  699. scriptVar Container::script_hide(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  700. {
  701. SCRIPT_FUNCTION_INIT
  702. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  703. if (c) c->setVisible(0);
  704. RETURN_SCRIPT_VOID;
  705. }
  706. scriptVar Container::script_close(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  707. {
  708. SCRIPT_FUNCTION_INIT
  709. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  710. if (c) c->close();
  711. RETURN_SCRIPT_VOID;
  712. }
  713. scriptVar Container::script_toggle(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  714. {
  715. SCRIPT_FUNCTION_INIT
  716. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  717. if (c) c->toggle();
  718. RETURN_SCRIPT_VOID;
  719. }
  720. // Switch to another layout
  721. scriptVar Container::script_switchToLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar l)
  722. {
  723. SCRIPT_FUNCTION_INIT
  724. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  725. if (c)
  726. c->switchToLayout(GET_SCRIPT_STRING(l));
  727. RETURN_SCRIPT_VOID;
  728. }
  729. scriptVar Container::script_getNumLayouts(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  730. {
  731. SCRIPT_FUNCTION_INIT
  732. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  733. if (c) return MAKE_SCRIPT_INT(c->getNumLayouts());
  734. RETURN_SCRIPT_ZERO;
  735. }
  736. scriptVar Container::script_enumLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar n)
  737. {
  738. SCRIPT_FUNCTION_INIT
  739. ASSERT(SOM::isNumeric(&n)); // compiler discarded
  740. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  741. Layout *l = NULL;
  742. if (c) l = c->enumLayout(SOM::makeInt(&n));
  743. return MAKE_SCRIPT_OBJECT(l ? l->getScriptObject() : NULL);
  744. }
  745. scriptVar Container::script_getCurrentLayout(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  746. {
  747. SCRIPT_FUNCTION_INIT
  748. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  749. Layout *l = c->getCurrentLayout();
  750. return MAKE_SCRIPT_OBJECT(l ? l->getScriptObject() : NULL);
  751. }
  752. // Switch to another layout
  753. scriptVar Container::script_vcpu_getId(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  754. {
  755. SCRIPT_FUNCTION_INIT
  756. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  757. if (c)
  758. return MAKE_SCRIPT_STRING(c->getId());
  759. return MAKE_SCRIPT_STRING(L"");
  760. }
  761. scriptVar Container::script_isDynamic(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  762. {
  763. SCRIPT_FUNCTION_INIT
  764. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  765. if (c) return MAKE_SCRIPT_INT(c->isDynamic());
  766. RETURN_SCRIPT_ZERO;
  767. }
  768. scriptVar Container::script_setName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar name)
  769. {
  770. SCRIPT_FUNCTION_INIT
  771. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  772. if (c) c->setName(GET_SCRIPT_STRING(name));
  773. RETURN_SCRIPT_VOID;
  774. }
  775. scriptVar Container::script_getName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  776. {
  777. SCRIPT_FUNCTION_INIT
  778. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  779. if (c) return MAKE_SCRIPT_STRING(c->getName());
  780. return MAKE_SCRIPT_STRING(L"");
  781. }
  782. scriptVar Container::script_getGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  783. {
  784. SCRIPT_FUNCTION_INIT
  785. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  786. if (c)
  787. {
  788. static wchar_t guidstr[256];
  789. nsGUID::toCharW(c->getGUID(), guidstr);
  790. return MAKE_SCRIPT_STRING(guidstr);
  791. }
  792. return MAKE_SCRIPT_STRING(L"");
  793. }
  794. scriptVar Container::script_setXmlParam(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar p, scriptVar v)
  795. {
  796. SCRIPT_FUNCTION_INIT
  797. Container *c = static_cast<Container *>(o->vcpu_getInterface(containerGuid));
  798. if (c) c->setXmlParam(GET_SCRIPT_STRING(p), GET_SCRIPT_STRING(v));
  799. RETURN_SCRIPT_VOID;
  800. }
  801. //void Container::notifyAddContent(ifc_window *w, const wchar_t *id, GUID g)
  802. scriptVar Container::script_onAddContent(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar window, scriptVar id, scriptVar g)
  803. {
  804. SCRIPT_FUNCTION_INIT;
  805. PROCESS_HOOKS3(o, containerController, window, id, g);
  806. SCRIPT_FUNCTION_CHECKABORTEVENT;
  807. SCRIPT_EXEC_EVENT3(o, window, id, g);
  808. }