123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648 |
- /*---------------------------------------------------
- -----------------------------------------------------
- Filename: maximize.m
- Version: 3.4
- Type: maki
- Date: 13. Sep. 2007 - 15:05
- Author: Martin Poehlmann aka Deimos
- E-Mail: [email protected]
- Internet: www.skinconsortium.com
- www.martin.deimos.de.vu
- -----------------------------------------------------
- ---------------------------------------------------*/
- #include <lib/std.mi>
- #include attribs/init_Autoresize.m
- Function setImages(boolean isMaximized);
- Function maximizeShade(boolean save);
- Function restoreShade();
- Function maximizePlayer(boolean save);
- Function restorePlayer();
- Function setWndToScreen();
- #define SAVEPOS_SHADE 2
- #define SAVEPOS_NORMAL 1
- #define SAVEPOS_ALL 0
- Function savePos(int code);
- Class GuiObject Mousetrap;
- Global Button Maximize, MaximizeShade, Restore, RestoreShade;
- Global Mousetrap noResizerTB, MousetrapTB, MousetrapShade, MousetrapMenu;
- Global Layout normal, shade;
- Global Boolean tgst;
- Global Layer resizer, noResizer, resizerShade, resizerShade2, topResizer;
- Global Container player;
- Global GuiObject shadeticker, slamclose;
- Global Group regions, regionsShade;
- Global Layer regionBlack, regionBlackShade;
- Global Int DEFAULT_PLAYER_H, DEFAULT_SHADE_H;
- Global Int old_x, old_y, old_h, old_w;
- System.onScriptLoaded ()
- {
- initAttribs_Autoresize();
- player = System.getContainer("main");
- normal = player.getLayout("normal");
- Maximize = normal.findObject("player.titlebar.button.maximize");
- Restore = normal.findObject("player.titlebar.button.restore");
- MousetrapTB = normal.findObject("player.mousetrap.maximize");
- resizer = normal.findObject("player.resizer.bottomright");
- noResizer = normal.findObject("player.resizer.disable");
- noResizerTB = normal.findObject("titlebar.resizer.disable");
- regions = normal.findObject("window.background.regions");
- regionBlack = normal.findObject("window.background.maximize");
- topResizer = normal.findObject("titlebar.resizer.top");
- slamclose = normal.findObject("maximize.slam.close");
- MousetrapMenu = normal.findObject("menu.hidden.mousetrap");
- shade = player.getLayout("shade");
- shadeticker = shade.findObject("Songticker");
- MaximizeShade = shade.findObject("shade.button.maximize");
- RestoreShade = shade.findObject("shade.button.restore");
- resizerShade = shade.findObject("shade.resizer.right");
- resizerShade2 = shade.findObject("shade.resizer.right2");
- MousetrapShade = shade.findObject("shade.mousetrap");
- regionsShade = Shade.findObject("window.background.regions");
- regionBlackShade = Shade.findObject("window.background.maximize");
- DEFAULT_PLAYER_H = stringToInteger(getToken(getParam(), "," , 0));
- DEFAULT_SHADE_H = stringToInteger(getToken(getParam(), "," , 1));
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizePlayer (FALSE);
- maximizeShade (FALSE);
- setImages (1);
- }
- else
- {
- if (getPrivateInt(getSkinName(), "First Start", 1)) setWndToScreen();
- else
- {
- restorePlayer ();
- restoreShade ();
- }
- }
- }
- // ------------------------------------------------------------------------------
- // Cope with viewport changes so we're happy with Windows 8.x snapping mode, etc
- // ------------------------------------------------------------------------------
- System.onViewPortChanged(int width, int height)
- {
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- if (normal == player.getCurLayout()) maximizePlayer (FALSE);
- else if (shade == player.getCurLayout()) maximizeShade (FALSE);
- }
- }
- // ------------------------------------------------------------------------------
- // Save all our window positions on skin unloading
- // ------------------------------------------------------------------------------
- System.onScriptUnloading ()
- {
- // if (player.getCurLayout() == normal) savePos(SAVEPOS_NORMAL);
- // else if (player.getCurLayout() == shade) savePos(SAVEPOS_SHADE);
- }
- // ------------------------------------------------------------------------------
- // Prohibit autoresizing by Video if we're in maximized player (layout_normal)
- // ------------------------------------------------------------------------------
- sui_autorsize_attrib.onDataChanged ()
- {
- if (getData() == "1")
- {
- normal.setXMLParam("lockminmax", "0");
- }
- else
- {
- double d = normal.getScale();
- if (normal.getLeft() == getViewportLeft() && normal.getTop() == getViewportTop() && normal.getWidth() == getViewPortWidthfromGuiObject(normal)/d && normal.getHeight() == getViewPortHeightfromGuiObject(normal)/d)
- {
- normal.setXMLParam("lockminmax", "1");
- }
- }
- }
- System.onKeyDown (String key)
- {
- if (key == "ctrl+w" && (shade.isActive() || normal.isActive()))
- {
- if (shade != player.getCurLayout())
- {
- player.switchToLayout("shade");
- }
- else
- {
- player.switchToLayout("normal");
- }
- complete;
- }
- }
- // ------------------------------------------------------------------------------
- // Button clicks
- // ------------------------------------------------------------------------------
- Maximize.onLeftClick ()
- {
- if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizePlayer (TRUE);
- }
- }
- Restore.onLeftClick ()
- {
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- restorePlayer ();
- }
- }
- MaximizeShade.onLeftClick ()
- {
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- restoreShade ();
- }
- else
- {
- maximizeShade (TRUE);
- }
- }
- RestoreShade.onLeftClick ()
- {
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- restoreShade ();
- }
- else
- {
- maximizeShade (TRUE);
- }
- }
- /** This will detect the second down click */
- Mousetrap.onLeftButtonDblClk (int x, int y)
- {
- tgst = true;
- }
- /** Once the button gets up, we'll toggle the maximized state */
- mousetrap.onLeftButtonUp (int x, int y)
- {
- if (tgst)
- {
- if (shade == player.getCurLayout())
- {
- if (titlebar_dblclk_max_attib.getData() == "1")
- {
- if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizeShade (TRUE);
- }
- else
- {
- restoreShade();
- }
- }
- else
- {
- player.switchToLayout("normal");
- }
- }
- else
- {
- if (titlebar_dblclk_max_attib.getData() == "1")
- {
- if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizePlayer (TRUE);
- }
- else
- {
- restorePlayer();
- }
- }
- else
- {
- player.switchToLayout("shade");
- }
- }
- }
- tgst = false;
- }
- topResizer.onLeftButtonDblClk (int x, int y)
- {
- if (titlebar_dblclk_max_attib.getData() == "1")
- {
- if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizePlayer (TRUE);
- }
- else
- {
- restorePlayer();
- }
- }
- else
- {
- player.switchToLayout("shade");
- }
- }
- // ------------------------------------------------------------------------------
- // Detect maximized states on window resize
- // ------------------------------------------------------------------------------
- normal.onEndMove ()
- {
- savePos(SAVEPOS_NORMAL);
- }
- normal.onResize (int x, int y, int w, int nh)
- {
- //debugString("onResize("+integertoString(x)+","+integertoString(y)+","+integertoString(w)+","+integertoString(nh)+");", 9);
- y = normal.getTop();
- // prohibit to set nh = 0
- if (nh == 0 || w == 0)
- {
- //debug("error setting player_normal w=" + integerToString(w) + " , h=" + integerToString(nh));
- normal.resize(getLeft(), getTop(), getWidth(), DEFAULT_PLAYER_H);
- return;
- }
- if (normal != player.getCurLayout()) return;
- if (old_x == x && old_y == y && old_h = nh && old_w == w) return;
- old_x = x; old_y = y; old_h = nh; old_w = w;
- if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
- {
- double d = normal.getScale();
- if (w == getViewPortWidthfromGuiObject(normal)/d && x == getViewportLeft() && y == getViewportTop())
- {
- //setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
- //setImages (1);
- }
- else
- {
- setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
- setImages (0);
- }
- }
- else
- {
- double d = normal.getScale();
- if (w == getViewPortWidthfromGuiObject(normal)/d && nh == getViewPortHeightfromGuiObject(normal)/d)
- {
- //setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
- //setImages (1);
- }
- else
- {
- setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
- setImages (0);
- }
- }
- savePos(SAVEPOS_NORMAL);
- }
- shade.onEndMove ()
- {
- savePos(SAVEPOS_SHADE);
- }
- shade.onResize (int x, int y, int w, int nh)
- {
- y = shade.getTop();
- // prohibit to set nh = 0
- if (nh == 0 || w == 0)
- {
- debug("error setting player_shade w=" + integerToString(w) + " , h=" + integerToString(nh));
- shade.resize(getLeft(), getTop(), getWidth(), DEFAULT_SHADE_H);
- return;
- }
- if (shade != player.getCurLayout()) return;
- if (old_x == x && old_y == y && old_h = nh && old_w == w) return;
- old_x = x; old_y = y; old_h = nh; old_w = w;
- double d = shade.getScale();
- if (w == getViewPortWidthfromGuiObject(shade)/d && y == getViewportTop() && x == getViewportLeft())
- {
- //setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
- //setImages (1);
- }
- else
- {
- setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
- setImages (0);
- }
- savePos(SAVEPOS_SHADE);
- }
- // ------------------------------------------------------------------------------
- // Resize our window on scale if we are maximized
- // ------------------------------------------------------------------------------
- normal.onScale (Double newscalevalue)
- {
- if (normal != player.getCurLayout()) return;
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizePlayer(FALSE);
- }
- savePos(SAVEPOS_NORMAL);
- }
- shade.onScale (Double newscalevalue)
- {
- if (shade != player.getCurLayout()) return;
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- maximizeShade(FALSE);
- }
- savePos(SAVEPOS_SHADE);
- }
- // ------------------------------------------------------------------------------
- // Before we switch between layouts, check all images and window sizes
- // ------------------------------------------------------------------------------
- player.onBeforeSwitchToLayout (Layout _layoutnow, Layout _layouttobe)
- {
- if (_layoutnow == normal) savePos(SAVEPOS_NORMAL);
- else if (_layoutnow == shade) savePos(SAVEPOS_SHADE);
- if (getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- if (_layouttobe == normal) maximizePlayer (FALSE);
- else if (_layouttobe == shade) maximizeShade (FALSE);
- setImages (1);
- }
- else
- {
- if (_layouttobe == normal) restorePlayer ();
- else if (_layouttobe == shade) restoreShade ();
- }
- }
- // ------------------------------------------------------------------------------
- // Save wnd position before we go to collapsed state
- // ------------------------------------------------------------------------------
- normal.onAction (String action, String param, Int x, int y, int p1, int p2, GuiObject source)
- {
- if (action == "sui" && param == "tonocomp" && x == 0)
- {
- savePos (SAVEPOS_NORMAL);
- }
- }
- // ******************************************************************************
- // Our Function Handles
- // ******************************************************************************
- setImages (boolean isMaximized)
- {
- if (isMaximized)
- {
- // Normal
- Maximize.hide();
- Restore.show();
- if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
- {
- MousetrapTB.setXMLparam("move", "0");
- MousetrapMenu.setXMLparam("move", "0");
- noResizerTB.setXMLparam("ghost", "0");
- }
- else
- {
- MousetrapTB.setXMLparam("move", "0");
- MousetrapMenu.setXMLparam("move", "0");
- noResizerTB.setXMLparam("ghost", "0");
- }
- if (sui_autorsize_attrib.getData() == "0") normal.setXMLParam("lockminmax", "1");
- else normal.setXMLParam("lockminmax", "0");
- resizer.hide();
- noResizer.show();
- regions.hide();
- regionBlack.show();
- // Shade
- MousetrapShade.setXMLparam("move", "0");
- shadeticker.setXmlParam("move", "0");
- MaximizeShade.hide();
- RestoreShade.show();
- resizerShade.hide();
- regionsShade.hide();
- resizerShade2.hide();
- regionBlackShade.show();
- slamclose.show();
- }
- else
- {
- // Normal
- resizer.show();
- noResizer.hide();
- MousetrapTB.setXMLparam("move", "1");
- noResizerTB.setXMLparam("ghost", "1");
- MousetrapMenu.setXMLparam("move", "1");
- normal.setXMLParam("lockminmax", "0");
- Maximize.show();
- Restore.hide();
- regions.show();
- regionBlack.hide();
- // Shade
- MousetrapShade.setXMLparam("move", "1");
- shadeticker.setXmlParam("move", "1");
- resizerShade.show();
- resizerShade2.show();
- MaximizeShade.show();
- RestoreShade.hide();
- regionsShade.show();
- regionBlackShade.hide();
- slamclose.hide();
- }
- }
- maximizeShade (boolean save)
- {
- if (save)
- {
- savePos(SAVEPOS_SHADE);
- setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
- setImages (1);
- }
- double newscalevalue = shade.getScale();
- int sh = shade.getHeight();
- if (sh < 1) sh = DEFAULT_SHADE_H;
- shade.resize(getViewPortLeftfromGuiObject(shade),getViewPortTopfromGuiObject(shade),getViewportWidthfromGuiObject(shade)/newscalevalue, sh);
- }
- restoreShade ()
- {
- if (link_w_attrib.getData() == "0")
- {
- shade.resize(
- getPrivateInt(getSkinName(), "shade_nomax_x", shade.getLeft()),
- getPrivateInt(getSkinName(), "shade_nomax_y", shade.getTop()),
- getPrivateInt(getSkinName(), "shade_nomax_w", 500),
- DEFAULT_SHADE_H
- );
- }
- else
- {
- shade.resize(
- getPrivateInt(getSkinName(), "nomax_x", shade.getLeft()),
- getPrivateInt(getSkinName(), "nomax_y", shade.getTop()),
- getPrivateInt(getSkinName(), "nomax_w", 700),
- DEFAULT_SHADE_H
- );
- }
- setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
- setImages (0);
- }
- maximizePlayer (boolean save)
- {
- if (save)
- {
- savePos(SAVEPOS_NORMAL);
- setPrivateInt(getSkinName(), "isMainWndMaximized", 1);
- setImages (1);
- }
- double newscalevalue = normal.getScale();
- int nh;
- if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
- {
- nh = DEFAULT_PLAYER_H;
- }
- else
- {
- nh = getViewPortHeightfromGuiObject(normal)/newscalevalue;
- }
- if (nh < 1) nh = DEFAULT_PLAYER_H;
- normal.resize(getViewPortLeftfromGuiObject(normal), getViewPortTopfromGuiObject(normal), getViewPortWidthfromGuiObject(normal)/newscalevalue, nh);
- }
- restorePlayer ()
- {
- //messagebox("restorePlayer", "", 0, "");
- int x, y, w, h;
- x = getPrivateInt(getSkinName(), "nomax_x", normal.getLeft());
- y = getPrivateInt(getSkinName(), "nomax_y", normal.getTop());
- w = getPrivateInt(getSkinName(), "nomax_w", normal.getWidth());
- if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden")
- {
- h = DEFAULT_PLAYER_H;
- }
- else
- {
- h = getPrivateInt(getSkinName(), "nomax_h", normal.getHeight());
- }
- // check if player_w is too small
- if (w < stringToInteger(normal.getXmlParam("minimum_w"))) w = stringToInteger(normal.getXmlParam("minimum_w"));
- normal.resize(x, y, w, h);
- normal.sendAction("pledit_posupdate", "", 0,0,0,0);
- setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
- setImages (0);
- }
- savePos (int code)
- {
- if (!getPrivateInt(getSkinName(), "isMainWndMaximized", 0))
- {
- if (code == SAVEPOS_NORMAL || code == SAVEPOS_ALL)
- {
- if (getPrivateString(getSkinName(), "Component", "Media Library") != "Hidden")
- {
- int nnh = normal.getHeight();
- //martin> i really dunno why i've added this code:
- //if (nnh > 0 && nnh < 200) setPrivateInt(getSkinName(), "nomax_h", normal.getHeight());
- //So lets try it again w/o switch in order to fix resizing - goto shade - goback - size not remembered bug
- if (nnh > 200) setPrivateInt(getSkinName(), "nomax_h", normal.getHeight());
- // ^ otherwise we save in collapsed mode
- }
- setPrivateInt(getSkinName(), "nomax_x", normal.getLeft());
- setPrivateInt(getSkinName(), "nomax_y", normal.getTop());
- if (normal.getWidth() > 0) setPrivateInt(getSkinName(), "nomax_w", normal.getWidth());
- //debugInt(getPrivateInt(getSkinName(), "nomax_w", normal.getWidth()));
- }
- if (code == SAVEPOS_SHADE || code == SAVEPOS_ALL)
- {
- if (link_w_attrib.getData() == "0")
- {
- setPrivateInt(getSkinName(), "shade_nomax_x", shade.getLeft());
- setPrivateInt(getSkinName(), "shade_nomax_y", shade.getTop());
- if (shade.getWidth() > 0) setPrivateInt(getSkinName(), "shade_nomax_w", shade.getWidth());
- }
- else
- {
- if (shade.getWidth() > 0) setPrivateInt(getSkinName(), "nomax_w", shade.getWidth());
- setPrivateInt(getSkinName(), "nomax_x", shade.getLeft());
- setPrivateInt(getSkinName(), "nomax_y", shade.getTop());
- }
- //debugInt(getPrivateInt(getSkinName(), "nomax_w", shade.getWidth()));
- //debugInt(getPrivateInt(getSkinName(), "shade_nomax_w", shade.getWidth()));
- }
- }
- if (code == SAVEPOS_NORMAL || code == SAVEPOS_ALL)
- {
- if (getPrivateString(getSkinName(), "Component", "Media Library") == "Hidden") setPrivateInt(getSkinName(), "nomax_y_h", normal.getTop());
- }
- //debugInt(getPrivateInt(getSkinName(), "nomax_w", shade.getWidth()));
- }
- setWndToScreen ()
- {
- int y = getViewPortTop();
- int x = getViewPortLeft();
- int h = getViewPortHeight();
- int w = getViewPortWidth();
- int sw = 0.8 * w;
- int sh = 0.85 * h;
- int mh = stringToInteger(normal.getXmlParam("minimum_h"));
- int mw = stringToInteger(normal.getXmlParam("minimum_w"));
- if (sh < mh) sh = mh;
- if (sw < mw) sw = mw;
-
- /* int sx = x + (w-sw)/2;
- int sy = y + (h-sh)/2;*/
- normal.resize(normal.getLeft(), normal.getTop(), sw, sh);
- setPrivateInt(getSkinName(), "First Start", 0);
- setPrivateInt(getSkinName(), "isMainWndMaximized", 0);
- setImages (0);
- }
|