maximize.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*---------------------------------------------------
  2. -----------------------------------------------------
  3. Filename: maximize.m
  4. Version: 3.4
  5. Type: maki
  6. Date: 13. Sep. 2007 - 15:05
  7. Author: Martin Poehlmann aka Deimos
  8. E-Mail: [email protected]
  9. Internet: www.skinconsortium.com
  10. www.martin.deimos.de.vu
  11. -----------------------------------------------------
  12. ---------------------------------------------------*/
  13. #include <lib/std.mi>
  14. #include attribs/init_Autoresize.m
  15. Function setImages(boolean isMaximized);
  16. Function maximizeShade(boolean save);
  17. Function restoreShade();
  18. Function maximizePlayer(boolean save);
  19. Function restorePlayer();
  20. Function setWndToScreen();
  21. #define SAVEPOS_SHADE 2
  22. #define SAVEPOS_NORMAL 1
  23. #define SAVEPOS_ALL 0
  24. Function savePos(int code);
  25. Class GuiObject Mousetrap;
  26. Global Button Maximize, MaximizeShade, Restore, RestoreShade;
  27. Global Mousetrap noResizerTB, MousetrapTB, MousetrapShade, MousetrapMenu;
  28. Global Layout normal, shade;
  29. Global Boolean tgst;
  30. Global Layer resizer, noResizer, resizerShade, resizerShade2, topResizer;
  31. Global Container player;
  32. Global GuiObject shadeticker, slamclose;
  33. Global Group regions, regionsShade;
  34. Global Layer regionBlack, regionBlackShade;
  35. Global Int DEFAULT_PLAYER_H, DEFAULT_SHADE_H;
  36. Global Int old_x, old_y, old_h, old_w;
  37. System.onScriptLoaded ()
  38. {
  39. initAttribs_Autoresize();
  40. player = System.getContainer("main");
  41. normal = player.getLayout("normal");
  42. Maximize = normal.findObject("player.titlebar.button.maximize");
  43. Restore = normal.findObject("player.titlebar.button.restore");
  44. MousetrapTB = normal.findObject("player.mousetrap.maximize");
  45. resizer = normal.findObject("player.resizer.bottomright");
  46. noResizer = normal.findObject("player.resizer.disable");
  47. noResizerTB = normal.findObject("titlebar.resizer.disable");
  48. regions = normal.findObject("window.background.regions");
  49. regionBlack = normal.findObject("window.background.maximize");
  50. topResizer = normal.findObject("titlebar.resizer.top");
  51. slamclose = normal.findObject("maximize.slam.close");
  52. MousetrapMenu = normal.findObject("menu.hidden.mousetrap");
  53. shade = player.getLayout("shade");
  54. shadeticker = shade.findObject("Songticker");
  55. MaximizeShade = shade.findObject("shade.button.maximize");
  56. RestoreShade = shade.findObject("shade.button.restore");
  57. resizerShade = shade.findObject("shade.resizer.right");
  58. resizerShade2 = shade.findObject("shade.resizer.right2");
  59. MousetrapShade = shade.findObject("shade.mousetrap");
  60. regionsShade = Shade.findObject("window.background.regions");
  61. regionBlackShade = Shade.findObject("window.background.maximize");
  62. DEFAULT_PLAYER_H = stringToInteger(getToken(getParam(), "," , 0));
  63. DEFAULT_SHADE_H = stringToInteger(getToken(getParam(), "," , 1));
  64. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  65. {
  66. maximizePlayer (FALSE);
  67. maximizeShade (FALSE);
  68. setImages (1);
  69. }
  70. else
  71. {
  72. if (getPrivateInt(getSkinName(), "First Start", 1)) setWndToScreen();
  73. else
  74. {
  75. restorePlayer ();
  76. restoreShade ();
  77. }
  78. }
  79. }
  80. // ------------------------------------------------------------------------------
  81. // Cope with viewport changes so we're happy with Windows 8.x snapping mode, etc
  82. // ------------------------------------------------------------------------------
  83. System.onViewPortChanged(int width, int height)
  84. {
  85. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  86. {
  87. if (normal == player.getCurLayout()) maximizePlayer (FALSE);
  88. else if (shade == player.getCurLayout()) maximizeShade (FALSE);
  89. }
  90. }
  91. // ------------------------------------------------------------------------------
  92. // Save all our window positions on skin unloading
  93. // ------------------------------------------------------------------------------
  94. System.onScriptUnloading ()
  95. {
  96. // if (player.getCurLayout() == normal) savePos(SAVEPOS_NORMAL);
  97. // else if (player.getCurLayout() == shade) savePos(SAVEPOS_SHADE);
  98. }
  99. // ------------------------------------------------------------------------------
  100. // Prohibit autoresizing by Video if we're in maximized player (layout_normal)
  101. // ------------------------------------------------------------------------------
  102. sui_autorsize_attrib.onDataChanged ()
  103. {
  104. if (getData() == "1")
  105. {
  106. normal.setXMLParam("lockminmax", "0");
  107. }
  108. else
  109. {
  110. double d = normal.getScale();
  111. if (normal.getLeft() == getViewportLeft() && normal.getTop() == getViewportTop() && normal.getWidth() == getViewPortWidthfromGuiObject(normal)/d && normal.getHeight() == getViewPortHeightfromGuiObject(normal)/d)
  112. {
  113. normal.setXMLParam("lockminmax", "1");
  114. }
  115. }
  116. }
  117. System.onKeyDown (String key)
  118. {
  119. if (key == "ctrl+w" && (shade.isActive() || normal.isActive()))
  120. {
  121. if (shade != player.getCurLayout())
  122. {
  123. player.switchToLayout("shade");
  124. }
  125. else
  126. {
  127. player.switchToLayout("normal");
  128. }
  129. complete;
  130. }
  131. }
  132. // ------------------------------------------------------------------------------
  133. // Button clicks
  134. // ------------------------------------------------------------------------------
  135. Maximize.onLeftClick ()
  136. {
  137. if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  138. {
  139. maximizePlayer (TRUE);
  140. }
  141. }
  142. Restore.onLeftClick ()
  143. {
  144. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  145. {
  146. restorePlayer ();
  147. }
  148. }
  149. MaximizeShade.onLeftClick ()
  150. {
  151. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  152. {
  153. restoreShade ();
  154. }
  155. else
  156. {
  157. maximizeShade (TRUE);
  158. }
  159. }
  160. RestoreShade.onLeftClick ()
  161. {
  162. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  163. {
  164. restoreShade ();
  165. }
  166. else
  167. {
  168. maximizeShade (TRUE);
  169. }
  170. }
  171. /** This will detect the second down click */
  172. Mousetrap.onLeftButtonDblClk (int x, int y)
  173. {
  174. tgst = true;
  175. }
  176. /** Once the button gets up, we'll toggle the maximized state */
  177. mousetrap.onLeftButtonUp (int x, int y)
  178. {
  179. if (tgst)
  180. {
  181. if (shade == player.getCurLayout())
  182. {
  183. if (titlebar_dblclk_max_attib.getData() == "1")
  184. {
  185. if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  186. {
  187. maximizeShade (TRUE);
  188. }
  189. else
  190. {
  191. restoreShade();
  192. }
  193. }
  194. else
  195. {
  196. player.switchToLayout("normal");
  197. }
  198. }
  199. else
  200. {
  201. if (titlebar_dblclk_max_attib.getData() == "1")
  202. {
  203. if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  204. {
  205. maximizePlayer (TRUE);
  206. }
  207. else
  208. {
  209. restorePlayer();
  210. }
  211. }
  212. else
  213. {
  214. player.switchToLayout("shade");
  215. }
  216. }
  217. }
  218. tgst = false;
  219. }
  220. topResizer.onLeftButtonDblClk (int x, int y)
  221. {
  222. if (titlebar_dblclk_max_attib.getData() == "1")
  223. {
  224. if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  225. {
  226. maximizePlayer (TRUE);
  227. }
  228. else
  229. {
  230. restorePlayer();
  231. }
  232. }
  233. else
  234. {
  235. player.switchToLayout("shade");
  236. }
  237. }
  238. // ------------------------------------------------------------------------------
  239. // Detect maximized states on window resize
  240. // ------------------------------------------------------------------------------
  241. normal.onEndMove ()
  242. {
  243. savePos(SAVEPOS_NORMAL);
  244. }
  245. normal.onResize (int x, int y, int w, int nh)
  246. {
  247. //debugString("onResize("+integertoString(x)+","+integertoString(y)+","+integertoString(w)+","+integertoString(nh)+");", 9);
  248. y = normal.getTop();
  249. // prohibit to set nh = 0
  250. if (nh == 0 || w == 0)
  251. {
  252. //debug("error setting player_normal w=" + integerToString(w) + " , h=" + integerToString(nh));
  253. normal.resize(getLeft(), getTop(), getWidth(), DEFAULT_PLAYER_H);
  254. return;
  255. }
  256. if (normal != player.getCurLayout()) return;
  257. if (old_x == x && old_y == y && old_h = nh && old_w == w) return;
  258. old_x = x; old_y = y; old_h = nh; old_w = w;
  259. if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
  260. {
  261. double d = normal.getScale();
  262. if (w == getViewPortWidthfromGuiObject(normal)/d && x == getViewportLeft() && y == getViewportTop())
  263. {
  264. //setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
  265. //setImages (1);
  266. }
  267. else
  268. {
  269. setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
  270. setImages (0);
  271. }
  272. }
  273. else
  274. {
  275. double d = normal.getScale();
  276. if (w == getViewPortWidthfromGuiObject(normal)/d && nh == getViewPortHeightfromGuiObject(normal)/d)
  277. {
  278. //setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
  279. //setImages (1);
  280. }
  281. else
  282. {
  283. setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
  284. setImages (0);
  285. }
  286. }
  287. savePos(SAVEPOS_NORMAL);
  288. }
  289. shade.onEndMove ()
  290. {
  291. savePos(SAVEPOS_SHADE);
  292. }
  293. shade.onResize (int x, int y, int w, int nh)
  294. {
  295. y = shade.getTop();
  296. // prohibit to set nh = 0
  297. if (nh == 0 || w == 0)
  298. {
  299. debug("error setting player_shade w=" + integerToString(w) + " , h=" + integerToString(nh));
  300. shade.resize(getLeft(), getTop(), getWidth(), DEFAULT_SHADE_H);
  301. return;
  302. }
  303. if (shade != player.getCurLayout()) return;
  304. if (old_x == x && old_y == y && old_h = nh && old_w == w) return;
  305. old_x = x; old_y = y; old_h = nh; old_w = w;
  306. double d = shade.getScale();
  307. if (w == getViewPortWidthfromGuiObject(shade)/d && y == getViewportTop() && x == getViewportLeft())
  308. {
  309. //setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
  310. //setImages (1);
  311. }
  312. else
  313. {
  314. setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
  315. setImages (0);
  316. }
  317. savePos(SAVEPOS_SHADE);
  318. }
  319. // ------------------------------------------------------------------------------
  320. // Resize our window on scale if we are maximized
  321. // ------------------------------------------------------------------------------
  322. normal.onScale (Double newscalevalue)
  323. {
  324. if (normal != player.getCurLayout()) return;
  325. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  326. {
  327. maximizePlayer(FALSE);
  328. }
  329. savePos(SAVEPOS_NORMAL);
  330. }
  331. shade.onScale (Double newscalevalue)
  332. {
  333. if (shade != player.getCurLayout()) return;
  334. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  335. {
  336. maximizeShade(FALSE);
  337. }
  338. savePos(SAVEPOS_SHADE);
  339. }
  340. // ------------------------------------------------------------------------------
  341. // Before we switch between layouts, check all images and window sizes
  342. // ------------------------------------------------------------------------------
  343. player.onBeforeSwitchToLayout (Layout _layoutnow, Layout _layouttobe)
  344. {
  345. if (_layoutnow == normal) savePos(SAVEPOS_NORMAL);
  346. else if (_layoutnow == shade) savePos(SAVEPOS_SHADE);
  347. if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  348. {
  349. if (_layouttobe == normal) maximizePlayer (FALSE);
  350. else if (_layouttobe == shade) maximizeShade (FALSE);
  351. setImages (1);
  352. }
  353. else
  354. {
  355. if (_layouttobe == normal) restorePlayer ();
  356. else if (_layouttobe == shade) restoreShade ();
  357. }
  358. }
  359. // ------------------------------------------------------------------------------
  360. // Save wnd position before we go to collapsed state
  361. // ------------------------------------------------------------------------------
  362. normal.onAction (String action, String param, Int x, int y, int p1, int p2, GuiObject source)
  363. {
  364. if (action == "sui" && param == "tonocomp" && x == 0)
  365. {
  366. savePos (SAVEPOS_NORMAL);
  367. }
  368. }
  369. // ******************************************************************************
  370. // Our Function Handles
  371. // ******************************************************************************
  372. setImages (boolean isMaximized)
  373. {
  374. if (isMaximized)
  375. {
  376. // Normal
  377. Maximize.hide();
  378. Restore.show();
  379. if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
  380. {
  381. MousetrapTB.setXMLparam("move", "0");
  382. MousetrapMenu.setXMLparam("move", "0");
  383. noResizerTB.setXMLparam("ghost", "0");
  384. }
  385. else
  386. {
  387. MousetrapTB.setXMLparam("move", "0");
  388. MousetrapMenu.setXMLparam("move", "0");
  389. noResizerTB.setXMLparam("ghost", "0");
  390. }
  391. if (sui_autorsize_attrib.getData() == "0") normal.setXMLParam("lockminmax", "1");
  392. else normal.setXMLParam("lockminmax", "0");
  393. resizer.hide();
  394. noResizer.show();
  395. regions.hide();
  396. regionBlack.show();
  397. // Shade
  398. MousetrapShade.setXMLparam("move", "0");
  399. shadeticker.setXmlParam("move", "0");
  400. MaximizeShade.hide();
  401. RestoreShade.show();
  402. resizerShade.hide();
  403. regionsShade.hide();
  404. resizerShade2.hide();
  405. regionBlackShade.show();
  406. slamclose.show();
  407. }
  408. else
  409. {
  410. // Normal
  411. resizer.show();
  412. noResizer.hide();
  413. MousetrapTB.setXMLparam("move", "1");
  414. noResizerTB.setXMLparam("ghost", "1");
  415. MousetrapMenu.setXMLparam("move", "1");
  416. normal.setXMLParam("lockminmax", "0");
  417. Maximize.show();
  418. Restore.hide();
  419. regions.show();
  420. regionBlack.hide();
  421. // Shade
  422. MousetrapShade.setXMLparam("move", "1");
  423. shadeticker.setXmlParam("move", "1");
  424. resizerShade.show();
  425. resizerShade2.show();
  426. MaximizeShade.show();
  427. RestoreShade.hide();
  428. regionsShade.show();
  429. regionBlackShade.hide();
  430. slamclose.hide();
  431. }
  432. }
  433. maximizeShade (boolean save)
  434. {
  435. if (save)
  436. {
  437. savePos(SAVEPOS_SHADE);
  438. setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
  439. setImages (1);
  440. }
  441. double newscalevalue = shade.getScale();
  442. int sh = shade.getHeight();
  443. if (sh < 1) sh = DEFAULT_SHADE_H;
  444. shade.resize(getViewPortLeftfromGuiObject(shade),getViewPortTopfromGuiObject(shade),getViewportWidthfromGuiObject(shade)/newscalevalue, sh);
  445. }
  446. restoreShade ()
  447. {
  448. if (link_w_attrib.getData() == "0")
  449. {
  450. shade.resize(
  451. getPrivateInt(getSkinName(), "shade_nomax_x", shade.getLeft()),
  452. getPrivateInt(getSkinName(), "shade_nomax_y", shade.getTop()),
  453. getPrivateInt(getSkinName(), "shade_nomax_w", 500),
  454. DEFAULT_SHADE_H
  455. );
  456. }
  457. else
  458. {
  459. shade.resize(
  460. getPrivateInt(getSkinName(), "nomax_x", shade.getLeft()),
  461. getPrivateInt(getSkinName(), "nomax_y", shade.getTop()),
  462. getPrivateInt(getSkinName(), "nomax_w", 700),
  463. DEFAULT_SHADE_H
  464. );
  465. }
  466. setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
  467. setImages (0);
  468. }
  469. maximizePlayer (boolean save)
  470. {
  471. if (save)
  472. {
  473. savePos(SAVEPOS_NORMAL);
  474. setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
  475. setImages (1);
  476. }
  477. double newscalevalue = normal.getScale();
  478. int nh;
  479. if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
  480. {
  481. nh = DEFAULT_PLAYER_H;
  482. }
  483. else
  484. {
  485. nh = getViewPortHeightfromGuiObject(normal)/newscalevalue;
  486. }
  487. if (nh < 1) nh = DEFAULT_PLAYER_H;
  488. normal.resize(getViewPortLeftfromGuiObject(normal), getViewPortTopfromGuiObject(normal), getViewPortWidthfromGuiObject(normal)/newscalevalue, nh);
  489. }
  490. restorePlayer ()
  491. {
  492. //messagebox("restorePlayer", "", 0, "");
  493. int x, y, w, h;
  494. x = getPrivateInt(getSkinName(), "nomax_x", normal.getLeft());
  495. y = getPrivateInt(getSkinName(), "nomax_y", normal.getTop());
  496. w = getPrivateInt(getSkinName(), "nomax_w", normal.getWidth());
  497. if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
  498. {
  499. h = DEFAULT_PLAYER_H;
  500. }
  501. else
  502. {
  503. h = getPrivateInt(getSkinName(), "nomax_h", normal.getHeight());
  504. }
  505. // check if player_w is too small
  506. if (w < stringToInteger(normal.getXmlParam("minimum_w"))) w = stringToInteger(normal.getXmlParam("minimum_w"));
  507. normal.resize(x, y, w, h);
  508. normal.sendAction("pledit_posupdate", "", 0,0,0,0);
  509. setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
  510. setImages (0);
  511. }
  512. savePos (int code)
  513. {
  514. if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
  515. {
  516. if (code == SAVEPOS_NORMAL || code == SAVEPOS_ALL)
  517. {
  518. if (getPrivateString(getSkinName(), "Component", "Media Library") != "Hidden")
  519. {
  520. int nnh = normal.getHeight();
  521. //martin> i really dunno why i've added this code:
  522. //if (nnh > 0 && nnh < 200) setPrivateInt(getSkinName(), "nomax_h", normal.getHeight());
  523. //So lets try it again w/o switch in order to fix resizing - goto shade - goback - size not remembered bug
  524. if (nnh > 200) setPrivateInt(getSkinName(), "nomax_h", normal.getHeight());
  525. // ^ otherwise we save in collapsed mode
  526. }
  527. setPrivateInt(getSkinName(), "nomax_x", normal.getLeft());
  528. setPrivateInt(getSkinName(), "nomax_y", normal.getTop());
  529. if (normal.getWidth() > 0) setPrivateInt(getSkinName(), "nomax_w", normal.getWidth());
  530. //debugInt(getPrivateInt(getSkinName(), "nomax_w", normal.getWidth()));
  531. }
  532. if (code == SAVEPOS_SHADE || code == SAVEPOS_ALL)
  533. {
  534. if (link_w_attrib.getData() == "0")
  535. {
  536. setPrivateInt(getSkinName(), "shade_nomax_x", shade.getLeft());
  537. setPrivateInt(getSkinName(), "shade_nomax_y", shade.getTop());
  538. if (shade.getWidth() > 0) setPrivateInt(getSkinName(), "shade_nomax_w", shade.getWidth());
  539. }
  540. else
  541. {
  542. if (shade.getWidth() > 0) setPrivateInt(getSkinName(), "nomax_w", shade.getWidth());
  543. setPrivateInt(getSkinName(), "nomax_x", shade.getLeft());
  544. setPrivateInt(getSkinName(), "nomax_y", shade.getTop());
  545. }
  546. //debugInt(getPrivateInt(getSkinName(), "nomax_w", shade.getWidth()));
  547. //debugInt(getPrivateInt(getSkinName(), "shade_nomax_w", shade.getWidth()));
  548. }
  549. }
  550. if (code == SAVEPOS_NORMAL || code == SAVEPOS_ALL)
  551. {
  552. if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden") setPrivateInt(getSkinName(), "nomax_y_h", normal.getTop());
  553. }
  554. //debugInt(getPrivateInt(getSkinName(), "nomax_w", shade.getWidth()));
  555. }
  556. setWndToScreen ()
  557. {
  558. int y = getViewPortTop();
  559. int x = getViewPortLeft();
  560. int h = getViewPortHeight();
  561. int w = getViewPortWidth();
  562. int sw = 0.8 * w;
  563. int sh = 0.85 * h;
  564. int mh = stringToInteger(normal.getXmlParam("minimum_h"));
  565. int mw = stringToInteger(normal.getXmlParam("minimum_w"));
  566. if (sh < mh) sh = mh;
  567. if (sw < mw) sw = mw;
  568. /* int sx = x + (w-sw)/2;
  569. int sy = y + (h-sh)/2;*/
  570. normal.resize(normal.getLeft(), normal.getTop(), sw, sh);
  571. setPrivateInt(getSkinName(), "First Start", 0);
  572. setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
  573. setImages (0);
  574. }