1
0

skin.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. #include <precomp.h>
  2. #include <api.h>
  3. #include "skin.h"
  4. #include <api/skin/skinbmps.h>
  5. #include <tataki/canvas/bltcanvas.h>
  6. #include <api/wnd/basewnd.h>
  7. #include <tataki/bitmap/bitmap.h>
  8. #include <bfc/parse/pathparse.h>
  9. #include <bfc/file/readdir.h>
  10. //#include <api/wac/main.h> // CUT!!
  11. #include <api/skin/skinparse.h>
  12. #include <api/wac/compon.h>
  13. #ifdef WASABI_COMPILE_WNDMGR
  14. #include <api/wndmgr/skinembed.h>
  15. #endif
  16. #include <api/script/vcpu.h>
  17. #include <api/skin/skinelem.h>
  18. #include <api/application/wkc.h>
  19. #include <api/skin/gammamgr.h>
  20. #include <api/wnd/wndtrack.h>
  21. #ifdef WASABI_COMPILE_PAINTSETS
  22. #include <api/wnd/paintset.h>
  23. #endif
  24. #include <bfc/string/StringW.h>
  25. #ifdef WIN32
  26. #include "resource.h"
  27. #include "../Agave/Language/api_language.h"
  28. #endif
  29. // Version number has now a style of x.yz (same as gen_ff version)
  30. #define SKIN_LEGACY_VERSION 80.f // oldest supported is 0.8
  31. #define SKIN_VERSION 136.f // current version is 1.36
  32. Skin *tha = NULL;
  33. static wchar_t *loadSkinList = NULL, skName[64];
  34. Skin::Skin()
  35. {
  36. if (deferedskinset == NULL)
  37. {
  38. deferedskinset = new SkinTimer();
  39. }
  40. base = NULL;
  41. scaled = NULL;
  42. scale_x = 0;
  43. scale_y = 0;
  44. validRgn = NULL;
  45. resizing = FALSE;
  46. }
  47. Skin::~Skin()
  48. {
  49. if (this == tha)
  50. {
  51. delete deferedskinset;
  52. deferedskinset = NULL;
  53. }
  54. delete validRgn;
  55. validRgn = NULL;
  56. delete base;
  57. delete scaled;
  58. if (this == tha)
  59. {
  60. if (loadSkinList)
  61. {
  62. FREE(loadSkinList);
  63. loadSkinList = NULL;
  64. }
  65. }
  66. }
  67. Skin *Skin::getCurSkin()
  68. {
  69. return tha;
  70. }
  71. void Skin::setSkinName(const wchar_t *newskinname, const wchar_t *skinpath)
  72. {
  73. if (newskinname)
  74. skinName = newskinname;
  75. else
  76. skinName = WASABI_API_LNGSTRINGW_BUF(IDS_NO_SKIN_LOADED_,skName,64);
  77. if (skinpath == NULL)
  78. {
  79. skinPath = WASABI_API_SKIN->getSkinsPath();
  80. skinPath.AppendFolder(newskinname);
  81. }
  82. else
  83. {
  84. skinPath = skinpath;
  85. skinPath.AddBackslash();
  86. }
  87. }
  88. const wchar_t *Skin::getSkinName()
  89. {
  90. return skinName.getValue();
  91. }
  92. const wchar_t *Skin::getSkinPath()
  93. {
  94. return skinPath.getValue();
  95. }
  96. const wchar_t *Skin::getDefaultSkinPath()
  97. {
  98. defSkinPath = WASABI_API_SKIN->getSkinsPath();
  99. defSkinPath.AppendFolder(L"Default");
  100. return defSkinPath;
  101. }
  102. void Skin::setBaseTexture(const wchar_t *b)
  103. {
  104. if (b == NULL)
  105. {
  106. delete base;
  107. base = NULL;
  108. return ;
  109. }
  110. base = new AutoSkinBitmap();
  111. base->setBitmap(b);
  112. }
  113. void Skin::rescaleBaseTexture(int w, int h)
  114. {
  115. /* if (scaled != NULL && scale_x == w && scale_y == h)
  116. return;
  117. if ((resizing && (w > m_x || h > m_y)) || (!resizing && (w != m_x || h != m_y)))
  118. {
  119. delete scaled;
  120. int lw = resizing ? maxw : w;
  121. int lh = resizing ? maxh : h;
  122. scaled = new BltCanvas(lw , lh);
  123. m_x = lw; m_y = lh;
  124. api_region *reg = new api_region(0,0,lw,lh);
  125. scaled->selectClipRgn(reg);
  126. delete reg;
  127. lastw = w;
  128. lasth = h;
  129. }
  130. // Empty valid region
  131. if (validRgn)
  132. validRgn->empty();
  133. else
  134. validRgn = new api_region();
  135. scale_x = w;
  136. scale_y = h;*/
  137. }
  138. void Skin::invalidateBaseTexture(Skin *s)
  139. { //FG
  140. if (!s) s = tha;
  141. if (s) s->_invalidateBaseTexture();
  142. }
  143. void Skin::invalidateAllBaseTextures()
  144. { //FG
  145. tha->_invalidateBaseTexture();
  146. for (int i = 0;i < skinList.getNumItems();i++)
  147. {
  148. Skin *s = skinList.enumItem(i);
  149. s->_invalidateBaseTexture();
  150. }
  151. }
  152. void Skin::unloadAllBaseTextures()
  153. {
  154. if (tha) tha->_unloadBaseTexture();
  155. for (int i = 0;i < skinList.getNumItems();i++)
  156. {
  157. Skin *s = skinList.enumItem(i);
  158. s->_unloadBaseTexture();
  159. }
  160. }
  161. void Skin::reloadAllBaseTextures()
  162. {
  163. if (tha) tha->_reloadBaseTexture();
  164. for (int i = 0;i < skinList.getNumItems();i++)
  165. {
  166. Skin *s = skinList.enumItem(i);
  167. s->_reloadBaseTexture();
  168. }
  169. invalidateAllBaseTextures();
  170. }
  171. void Skin::_unloadBaseTexture()
  172. {
  173. if (base)
  174. base->reset();
  175. }
  176. void Skin::_reloadBaseTexture()
  177. {
  178. if (!tha) return ;
  179. if (base)
  180. base->reload();
  181. }
  182. void Skin::_invalidateBaseTexture(void)
  183. { //FG
  184. if (validRgn)
  185. validRgn->empty();
  186. }
  187. void Skin::registerBaseSkin(Skin *s, ifc_window *b)
  188. {
  189. skinList.addItem(s);
  190. baseList.addItem(b);
  191. }
  192. Skin *Skin::unregisterBaseSkin(ifc_window *b)
  193. {
  194. for (int i = 0;i < baseList.getNumItems();i++)
  195. {
  196. if (baseList.enumItem(i) == b)
  197. {
  198. Skin *s = skinList.enumItem(i);
  199. baseList.delByPos(i);
  200. skinList.delByPos(i);
  201. if (baseList.getNumItems() == 0)
  202. baseList.removeAll();
  203. if (skinList.getNumItems() == 0)
  204. skinList.removeAll();
  205. return s;
  206. }
  207. }
  208. return NULL;
  209. }
  210. Skin *Skin::baseToSkin(ifc_window *b)
  211. {
  212. if (b == NULL) return NULL;
  213. for (int i = 0;i < baseList.getNumItems();i++)
  214. if (baseList.enumItem(i) == b)
  215. return skinList.enumItem(i);
  216. return NULL;
  217. }
  218. void Skin::renderBaseTexture(ifc_window *base, ifc_canvas *c, const RECT &r, ifc_window *dest, int alpha)
  219. {
  220. renderBaseTexture(base, baseToSkin(base), c, r, dest, alpha);
  221. }
  222. void Skin::renderBaseTexture(ifc_window *base, Skin *s, ifc_canvas *c, const RECT &r, ifc_window *dest, int alpha)
  223. {
  224. ASSERT(tha != NULL);
  225. if (!s)
  226. {
  227. DebugStringW(L"Warning, base texture from main wnd?!\n");
  228. s = tha;
  229. }
  230. s->_renderBaseTexture(base, c, r, dest, alpha);
  231. }
  232. void Skin::validateBaseTextureRect(RECT *r)
  233. {
  234. /* if (!base) {
  235. ASSERT(!(tha && this == tha));
  236. if (origbase)
  237. base = new SkinBitmap(origbase, origbase->getWidth(), origbase->getHeight());
  238. else
  239. base = new SkinBitmap(tha->base, tha->base->getWidth(), tha->base->getHeight());
  240. if (!base) return;
  241. }
  242. // make a region with the rect we have to draw
  243. api_region *newregion = new api_region(r);
  244. // check if newregion is enclosed in validRgn, put whatever is outside back into newregion
  245. if (newregion->enclosed(validRgn, newregion)) {
  246. delete newregion;
  247. return;
  248. }
  249. // compute projected coordinates
  250. RECT destRect, srcRect;
  251. newregion->getRgnBox(&destRect);
  252. srcRect.left = (int)(((float)destRect.left / scale_x) * base->getWidth());
  253. srcRect.right = (int)(((float)destRect.right / scale_x) * base->getWidth());
  254. srcRect.top = (int)(((float)destRect.top / scale_y) * base->getHeight());
  255. srcRect.bottom = (int)(((float)destRect.bottom / scale_y) * base->getHeight());
  256. // stretch the relevant portion of the image
  257. base->stretchRectToRect(scaled, &srcRect, &destRect);
  258. #if 0 //FG> debug purpose
  259. HDC dc = GetDC(NULL);
  260. BitBlt(dc, 0, 0, scale_x, scale_y, scaled->getHDC(), 0, 0, SRCCOPY);
  261. ReleaseDC(NULL, dc);
  262. #endif
  263. // add this region to the valid region
  264. validRgn->add(newregion);
  265. delete newregion;*/
  266. }
  267. #define SAFEROUND(d) ((float)(int)d == d) ? (int)d : (d - (float)(int)d > 0) ? ((int)d)+1 : ((int)d)-1
  268. // FG> Please change this only if you REALLY know what you are doing. this needs to account for basewnd
  269. // coordinates (start from 0,0), as well as virtualwnd (relative to parent), at any depth (group holding
  270. // texture as 2nd group of the tree, and rendering the base texture in a basewnd in a virtual in the group),
  271. // and should handle resized textures and scaled windows. ooch
  272. void Skin::_renderBaseTexture(ifc_window *wndbase, ifc_canvas *c, const RECT &r, ifc_window *dest, int alpha)
  273. {
  274. // pick our basetexture
  275. AutoSkinBitmap *b = base ? base : tha->base;
  276. if (!b) return ;
  277. // srcRect is the source rectangle in the basetexture
  278. RECT srcRect;
  279. // destProjectedRect is the basetexture rectangle projected to dest coordinates
  280. RECT destProjectedRect;
  281. ifc_window *p = dest;
  282. POINT pt;
  283. int sx = 0, sy = 0;
  284. while (p && p != wndbase)
  285. {
  286. if (!p->isVirtual())
  287. {
  288. p->getPosition(&pt);
  289. sx += pt.x;
  290. sy += pt.y;
  291. }
  292. p = p->getParent();
  293. }
  294. ASSERT(p);
  295. wndbase->getNonClientRect(&destProjectedRect);
  296. destProjectedRect.left -= sx;
  297. destProjectedRect.top -= sy;
  298. destProjectedRect.right -= sx;
  299. destProjectedRect.bottom -= sy;
  300. srcRect.left = 0;
  301. srcRect.top = 0;
  302. srcRect.right = b->getBitmap()->getWidth();
  303. srcRect.bottom = b->getBitmap()->getHeight();
  304. #if 0//CUT
  305. // NONPORTABLE
  306. HDC hdc = c->getHDC();
  307. HRGN oldRgn = CreateRectRgn(0, 0, 0, 0);
  308. HRGN newRgn = CreateRectRgnIndirect(&r);
  309. int cs = GetClipRgn(hdc, oldRgn);
  310. ExtSelectClipRgn(hdc, newRgn, (cs != 1) ? RGN_COPY : RGN_AND);
  311. b->getBitmap()->stretchToRectAlpha(c, &srcRect, &destProjectedRect, alpha);
  312. SelectClipRgn(hdc, cs ? oldRgn : NULL);
  313. DeleteObject(oldRgn);
  314. DeleteObject(newRgn);
  315. #endif
  316. BaseCloneCanvas clone(c);
  317. RegionI oldRgn, newRgn(&r);
  318. #ifdef _WIN32
  319. int cs = clone.getClipRgn(&oldRgn);
  320. if (cs) newRgn.andRegion(&oldRgn);
  321. clone.selectClipRgn(&newRgn);
  322. b->getBitmap()->stretchToRectAlpha(&clone, &srcRect, &destProjectedRect, alpha);
  323. clone.selectClipRgn(cs ? &oldRgn : NULL);
  324. #else
  325. #warning port me
  326. b->getBitmap()->stretchToRectAlpha(&clone, &srcRect, &destProjectedRect, alpha);
  327. #endif
  328. }
  329. wchar_t *Skin::enumLoadableSkins(int refresh)
  330. {
  331. static size_t loadSkinListSize = 1024;
  332. if (loadSkinList)
  333. {
  334. if (!refresh)
  335. return loadSkinList;
  336. FREE(loadSkinList);
  337. }
  338. loadSkinList = WMALLOC(loadSkinListSize);
  339. loadSkinList[0] = 0;
  340. int first = 1;
  341. ReadDir skins(L"skins");
  342. while (skins.next())
  343. {
  344. const wchar_t *filename = skins.getFilename();
  345. wchar_t *ext = const_cast<wchar_t *>(Wasabi::Std::extension(filename));
  346. if (skins.isDir() || !WCSICMP(ext, L"wal") ||
  347. !WCSICMP(ext, L"wsz") || !WCSICMP(ext, L"zip"))
  348. {
  349. if (!skins.isDotDir() && !skins.isDotDotDir())
  350. {
  351. if (!skins.isDir() )
  352. {
  353. if (ext && *ext) *(ext - 1) = 0;
  354. }
  355. // check loadSkinList size
  356. if ((wcslen(loadSkinList) + wcslen(filename) + 2) > loadSkinListSize)
  357. {
  358. loadSkinListSize *= 2;
  359. loadSkinList = (wchar_t *)REALLOC(loadSkinList, sizeof(wchar_t) * loadSkinListSize);
  360. }
  361. if (!first)
  362. wcscat(loadSkinList, L"/");
  363. wcscat(loadSkinList, filename);
  364. first = 0;
  365. }
  366. }
  367. }
  368. return loadSkinList;
  369. }
  370. int Skin::loadSkinPart(const wchar_t *xmlfile)
  371. {
  372. #ifdef WASABI_COMPILE_COMPONENTS
  373. WasabiKernelController *wkc = Main::getKernelController();
  374. if (wkc && !wkc->testSkinFile(xmlfile)) return -1;
  375. #endif
  376. int id = WASABI_API_PALETTE->newSkinPart();
  377. SkinElementsMgr::onBeforeLoadingScriptElements(xmlfile, id);
  378. SkinParser::loadScriptXml(xmlfile, id);
  379. SkinElementsMgr::onAfterLoadingScriptElements();
  380. #ifdef WASABI_COMPILE_WNDMGR
  381. SkinParser::startupContainers(id);
  382. #endif
  383. return id;
  384. }
  385. void Skin::unloadSkinPart(int skinpartid)
  386. {
  387. SkinElementsMgr::unloadScriptElements(skinpartid);
  388. SkinParser::cleanupScript(skinpartid);
  389. }
  390. int Skin::checkSkin(const wchar_t *skinname)
  391. {
  392. OSFILETYPE fh = WFOPEN(StringPathCombine(WASABI_API_SKIN->getSkinPath(), L"skin.xml"), WF_READONLY_BINARY);
  393. if (fh != OPEN_FAILED)
  394. {
  395. FCLOSE(fh);
  396. // ok it's a wa3 skin, now check the skin version number in the xml file
  397. SkinVersionXmlReader r(skinname);
  398. if (!r.getWalVersion()) return CHKSKIN_ISWA3OLD;
  399. #ifndef LC_NUMERIC
  400. #define LC_NUMERIC 4
  401. #endif
  402. float v = (float)(WTOF(r.getWalVersion()) * 100); // Since wa5.51 we will do a check for x.yz style
  403. if (v < (SKIN_LEGACY_VERSION-0.5f)) return CHKSKIN_ISWA3OLD;
  404. if (v > (SKIN_VERSION+0.5f)) return CHKSKIN_ISWA3FUTURE;
  405. return CHKSKIN_ISWA3;
  406. }
  407. fh = WFOPEN(StringPathCombine(WASABI_API_SKIN->getSkinPath(), L"Main.bmp"), WF_READONLY_BINARY);
  408. if (fh != OPEN_FAILED)
  409. {
  410. FCLOSE(fh);
  411. return CHKSKIN_ISWA2;
  412. }
  413. return CHKSKIN_UNKNOWN;
  414. }
  415. void Skin::toggleSkin(const wchar_t *skin_name, const wchar_t *skin_path, int deferred)
  416. {
  417. StringW skinName = skin_name;
  418. if (sendAbortCallback(skinName)) return ;
  419. enable_group_reload = 0;
  420. StringW oldSkinPath = skinPath;
  421. char title[32] = {0};
  422. setSkinName(skinName, skin_path);
  423. int skinType = checkSkin(skinName);
  424. skinPath = oldSkinPath;
  425. #ifdef WASABI_COMPILE_COMPONENTS
  426. WasabiKernelController *wkc = Main::getKernelController();
  427. if (wkc && !wkc->testSkin(skinName)) skinType = CHKSKIN_DISALLOWED;
  428. #endif
  429. switch (skinType)
  430. {
  431. case CHKSKIN_ISWA3OLD:
  432. {
  433. #ifdef WIN32
  434. WASABI_API_WND->appdeactivation_setbypass(1);
  435. int ret = MessageBoxA(GetActiveWindow(), WASABI_API_LNGSTRING(IDS_SKIN_LOAD_FORMAT_OLD),
  436. WASABI_API_LNGSTRING_BUF(IDS_SKIN_LOAD_WARNING,title,32),
  437. MB_ICONWARNING | MB_YESNO);
  438. WASABI_API_WND->appdeactivation_setbypass(0);
  439. if (ret == IDNO) return ;
  440. #else
  441. DebugString( "The skin you are trying to load is meant for an older Winamp3 version.\n" );
  442. #endif
  443. break;
  444. }
  445. case CHKSKIN_ISWA3FUTURE:
  446. {
  447. #ifdef WIN32
  448. WASABI_API_WND->appdeactivation_setbypass(1);
  449. int ret = MessageBoxA(GetActiveWindow(), WASABI_API_LNGSTRING(IDS_SKIN_LOAD_FORMAT_TOO_RECENT),
  450. WASABI_API_LNGSTRING_BUF(IDS_SKIN_LOAD_WARNING,title,32),
  451. MB_ICONWARNING | MB_YESNO);
  452. WASABI_API_WND->appdeactivation_setbypass(0);
  453. if (ret == IDNO) return ;
  454. #else
  455. DebugString( "The skin you are trying to load is meant for an older Winamp3 version.\n" );
  456. #endif
  457. break;
  458. }
  459. case CHKSKIN_UNKNOWN:
  460. #ifdef WIN32
  461. WASABI_API_WND->appdeactivation_setbypass(1);
  462. MessageBoxA(GetActiveWindow(), WASABI_API_LNGSTRING(IDS_SKIN_LOAD_NOT_SUPPORTED),
  463. WASABI_API_LNGSTRING_BUF(IDS_ERROR,title,32), MB_ICONERROR);
  464. WASABI_API_WND->appdeactivation_setbypass(0);
  465. #else
  466. DebugString( "The skin you are trying to load is meant for an older Winamp3 version.\n" );
  467. #endif
  468. return ;
  469. case CHKSKIN_DISALLOWED:
  470. // kernel controller should output its own error message
  471. return ;
  472. case CHKSKIN_ISWA2: break;
  473. }
  474. WASABI_API_COLORTHEMES->StartTransaction();
  475. if (skin_loaded)
  476. {
  477. sendUnloadingCallback();
  478. }
  479. loading = 1;
  480. if (skin_loaded)
  481. {
  482. //ComponentManager::detachAllTemporary();
  483. //ComponentManager::destroyAllCompContainer();
  484. #ifdef WASABI_COMPILE_WNDMGR
  485. #ifdef WASABI_COMPILE_CONFIG
  486. #ifndef WASABI_WNDMGR_NORESPAWN
  487. skinEmbedder->saveState();
  488. #endif
  489. #endif
  490. #endif
  491. // unload current skin
  492. SkinParser::cleanUp();
  493. delete(tha);
  494. tha = NULL;
  495. //delete(VCPU::scriptManager);
  496. unloadResources();
  497. // TODO: benski> unload WAC files inside skin.
  498. // we should have saved a list of WacComponent * when loading
  499. // add a new method ComponentManager::unload(WacComponent *);
  500. Skin::sendResetCallback();
  501. // VCPU::scriptManager = new ScriptObjectManager();
  502. Skin *n = new Skin;
  503. tha = n;
  504. }
  505. setSkinName(skinName, skin_path);
  506. if (skin_loaded)
  507. {
  508. SkinElementsMgr::resetSkinElements();
  509. //SkinElementsMgr::loadSkinElements(skinName); // only loads element definitions, not actual bitmaps
  510. sendReloadCallback();
  511. reloadResources();
  512. }
  513. // TODO: benski> load WAC files inside skin. save list of WacComponent * to a list to unload later
  514. // make ComponentManager::load() return the WacComponent to allow this
  515. #ifdef WASABI_COMPILE_WNDMGR
  516. int ncont = SkinParser::loadContainers(skinName); //sends guiloaded cb
  517. #endif
  518. GammaMgr::loadDefault();
  519. #ifdef WASABI_COMPILE_WNDMGR
  520. SkinParser::startupContainers();
  521. #ifdef WASABI_COMPILE_CONFIG
  522. #ifndef WASABI_WNDMGR_NORESPAWN
  523. skinEmbedder->restoreSavedState();
  524. #endif
  525. #endif
  526. #endif
  527. enable_group_reload = 1;
  528. sendLoadedCallback();
  529. #ifdef WASABI_COMPILE_WNDMGR
  530. SkinParser::centerSkin();
  531. #endif
  532. loading = 0;
  533. #ifdef WASABI_COMPILE_WNDMGR
  534. #ifdef WA3COMPATIBILITY
  535. if (ncont == 0)
  536. SkinParser::emmergencyReloadDefaultSkin();
  537. #endif
  538. #endif
  539. skin_loaded = 1;
  540. WASABI_API_COLORTHEMES->EndTransaction();
  541. }
  542. void Skin::unloadSkin()
  543. {
  544. if (!skin_loaded) return ;
  545. sendUnloadingCallback();
  546. loading = -1;
  547. #ifdef WASABI_COMPILE_WNDMGR
  548. #ifdef WASABI_COMPILE_CONFIG
  549. #ifndef WASABI_WNDMGR_NORESPAWN
  550. skinEmbedder->saveState();
  551. #endif
  552. #endif
  553. #endif
  554. // unload current skin
  555. SkinParser::cleanUp();
  556. delete(tha);
  557. tha = NULL;
  558. //delete(VCPU::scriptManager);
  559. unloadResources();
  560. Skin::sendResetCallback();
  561. // VCPU::scriptManager = new ScriptObjectManager();
  562. Skin *n = new Skin;
  563. tha = n;
  564. setSkinName(WASABI_API_LNGSTRINGW_BUF(IDS_NO_SKIN_LOADED_,skName,64));
  565. SkinElementsMgr::resetSkinElements();
  566. //SkinElementsMgr::loadSkinElements(skinName); // only loads element definitions, not actual bitmaps
  567. sendReloadCallback();
  568. reloadResources();
  569. loading = 0;
  570. skin_loaded = 0;
  571. }
  572. void Skin::sendUnloadingCallback()
  573. {
  574. #if defined(WASABI_COMPILE_COMPONENTS) | defined(GEN_FF) // MULTIAPI-FIXME!!
  575. ComponentManager::broadcastNotify(WAC_NOTIFY_SKINUNLOADING, WASABI_API_PALETTE->getSkinPartIterator());
  576. #endif
  577. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::UNLOADING);
  578. }
  579. int Skin::sendAbortCallback(const wchar_t *skinname)
  580. {
  581. int a = 0;
  582. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::CHECKPREVENTSWITCH, (intptr_t)skinname, (intptr_t)&a);
  583. return a;
  584. }
  585. void Skin::sendResetCallback()
  586. {
  587. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::RESET);
  588. }
  589. void Skin::sendReloadCallback()
  590. {
  591. #if defined(WASABI_COMPILE_COMPONENTS) | defined(GEN_FF) // MULTIAPI-FIXME!!
  592. ComponentManager::broadcastNotify(WAC_NOTIFY_SWITCHINGSKIN, WASABI_API_PALETTE->getSkinPartIterator()); // this msg primilarily here to insert stuff between unloading of the old skin and reloading of the new one
  593. #endif
  594. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::RELOAD);
  595. }
  596. void Skin::sendBeforeLoadingElementsCallback()
  597. {
  598. #if defined(WASABI_COMPILE_COMPONENTS) | defined(GEN_FF) // MULTIAPI-FIXME!!
  599. ComponentManager::broadcastNotify(WAC_NOTIFY_BEFORELOADINGSKINELEMENTS, WASABI_API_PALETTE->getSkinPartIterator()); // this msg primilarily here to insert stuff between unloading of the old skin and reloading of the new one
  600. #endif
  601. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::BEFORELOADINGELEMENTS);
  602. }
  603. void Skin::sendGuiLoadedCallback()
  604. {
  605. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::GUILOADED);
  606. }
  607. void Skin::sendLoadedCallback()
  608. {
  609. #if defined(WASABI_COMPILE_COMPONENTS) | defined(GEN_FF) // MULTIAPI-FIXME!!
  610. ComponentManager::broadcastNotify(WAC_NOTIFY_SKINLOADED, WASABI_API_PALETTE->getSkinPartIterator());
  611. #endif
  612. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::SKINCB, SkinCallback::LOADED);
  613. }
  614. void Skin::setSkinReady(int i)
  615. {
  616. loading = !i;
  617. }
  618. void Skin::main_notifySkinLoaded()
  619. {
  620. skin_loaded = 1;
  621. }
  622. int Skin::isSkinReady()
  623. {
  624. return !loading;
  625. }
  626. int Skin::unloadResources()
  627. {
  628. if (windowTracker)
  629. {
  630. for (int i = 0;i < windowTracker->getNumAllWindows();i++)
  631. {
  632. ifc_window *w = windowTracker->enumAllWindows(i);
  633. #ifdef _WIN32
  634. if (w) w->wndProc(w->gethWnd(), WM_WA_RELOAD, 0, 0);
  635. #else
  636. #warning port me
  637. #endif
  638. }
  639. Skin::unloadAllBaseTextures();
  640. #ifdef WASABI_COMPILE_PAINTSETS
  641. paintset_reset();
  642. #endif
  643. }
  644. sendResetCallback();
  645. return 1;
  646. }
  647. int Skin::reloadResources()
  648. {
  649. if (windowTracker)
  650. {
  651. for (int i = 0;i < windowTracker->getNumAllWindows();i++)
  652. {
  653. ifc_window *w = windowTracker->enumAllWindows(i);
  654. #ifdef _WIN32
  655. if (w) w->wndProc(w->gethWnd(), WM_WA_RELOAD, 1, 0);
  656. #else
  657. #warning port me
  658. #endif
  659. }
  660. Skin::reloadAllBaseTextures();
  661. }
  662. sendReloadCallback();
  663. return 1;
  664. }
  665. bool Skin::isLoaded()
  666. {
  667. return !!skin_loaded;
  668. }
  669. PtrList<Skin> Skin::skinList;
  670. PtrList<ifc_window> Skin::baseList;
  671. StringW Skin::skinName;
  672. StringW Skin::skinPath;
  673. int Skin::isDefaultSkin = 0;
  674. int Skin::loading = 0;
  675. int Skin::highest_id = 0;
  676. int Skin::reloadingskin = 0;
  677. int Skin::enable_group_reload = 0;
  678. StringW Skin::defSkinPath;
  679. SkinTimer *Skin::deferedskinset = NULL;
  680. int Skin::skin_loaded = 0;