<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<UIX xmlns="http://schemas.microsoft.com/2007/uix"
  xmlns:sys="assembly://mscorlib/System"
  xmlns:zune="assembly://ZuneShell/ZuneUI"
  xmlns:iris="assembly://UIX/Microsoft.Iris"
  xmlns:styles="res://ZuneShellResources!Styles.uix"
  xmlns:page="res://ZuneShellResources!PageStack.uix"
  xmlns:toptoolbar="res://ZuneShellResources!TopToolbar.uix"
  xmlns:popuplayer="res://ZuneShellResources!PopupLayer.uix"
  xmlns:jil="res://ZuneShellResources!JumpInList.uix"
  xmlns:bottomtoolbar="res://ZuneShellResources!BottomToolbar.uix"
  xmlns:mnav="res://ZuneMarketplaceResources!Navigation.uix"
  xmlns:cnav="res://ZuneShellResources!CollectionNavigation.uix"
  xmlns:snav="res://ZuneShellResources!SocialNavigation.uix"
  xmlns:animations="res://ZuneShellResources!Animations.uix"
  xmlns:nonclient="res://ZuneShellResources!NonClientControls.uix"
  xmlns:focus="res://ZuneShellResources!FocusRect.uix">

  
  <UI Name="Frame" Base="page:PageStack">
    <Properties>
      <zune:Shell Name="Shell" Shell="{(zune:Shell)zune:Shell.DefaultInstance}"/>
    </Properties>

    <Locals>
      <zune:DictionaryCommandHandler Name="ShellCommandHandlers">
        <Handlers>

          <zune:CurrentPageCommandHandler Name="Page"/>

          <zune:DictionaryCommandHandler Name="Marketplace"
            DictionaryCommandHandler="{mnav:Navigation.Root}"/>

          <zune:DictionaryCommandHandler Name="Collection"
            DictionaryCommandHandler="{cnav:Navigation.Root}"/>

          <zune:DictionaryCommandHandler Name="Device"
            DictionaryCommandHandler="{cnav:DeviceNavigation.Root}"/>

          <zune:DictionaryCommandHandler Name="Social"
            DictionaryCommandHandler="{snav:Navigation.Root}"/>

          <zune:WebUrlCommandHandler Name="Web"/>

          <zune:HelpCommandHandler Name="Help"/>

        </Handlers>
      </zune:DictionaryCommandHandler>
      <jil:JumpInList Name="JumpInList"/>

      
      
      <AnchorLayoutInput Name="EnergyBarLayoutMax" Bottom="Parent,1" Left="Parent,0" Right="Parent,1,-1"/>
      <AnchorLayoutInput Name="EnergyBarLayoutNorm" Bottom="Parent,1" Left="Parent,0,1" Right="Grabber,0"/>

      <Int32 Name="MouseActivityTimeout" Int32="5000"/>

      <sys:Boolean Name="AutoHideToolbars"/>
      <Timer Name="KeyIdleTimer" Interval="{MouseActivityTimeout}" AutoRepeat="false" Enabled="false"/>
      <styles:WindowState Name="WindowState"/>
    </Locals>

    <Input>
      
      <ClickHandler Name="MouseDown" ClickType="Mouse" HandlerTransition="Down" HandlerStage="Routed" Handle="false"/>

      
      <KeyHandler Name="CancelSettings" Key="Escape" DisallowedModifiers="Alt,Shift,Windows,Ctrl" HandlerStage="Bubbled" />

      <ShortcutHandler Name="ShortcutPlay" Shortcut="Play" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Play}"/>
      <ShortcutHandler Name="ShortcutPause" Shortcut="Pause" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Pause}"/>
      <ShortcutHandler Name="ShortcutPlayPause" Shortcut="PlayPause" HandlerStage="Bubbled"/>
      <ShortcutHandler Name="ShortcutStop" Shortcut="Stop" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Stop}"/>
      <ShortcutHandler Name="ShortcutSkipBack" Shortcut="SkipBack" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Back}"/>
      <ShortcutHandler Name="ShortcutSkipForward" Shortcut="SkipForward" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Forward}"/>

      <KeyHandler Name="KeyHandlerForward"       Key="F"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Forward}"/>
      <KeyHandler Name="KeyHandlerBack"          Key="B"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Back}"/>
      <KeyHandler Name="KeyHandlerStop"          Key="S"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.Stop}"/>
      <KeyHandler Name="KeyHandlerPlayPause"     Key="P"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerToggleShuffle" Key="H"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerToggleRepeat"  Key="T"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerHelp"          Key="F1" DisallowedModifiers="Alt,Shift,Ctrl,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerToggleMute"    Key="F7" DisallowedModifiers="Alt,Shift,Ctrl,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerVolumeDown"    Key="F8" DisallowedModifiers="Alt,Shift,Ctrl,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerVolumeUp"      Key="F9" DisallowedModifiers="Alt,Shift,Ctrl,Windows" HandlerStage="Bubbled"/>
      <KeyHandler Name="KeyHandlerFastForward"   Key="F"  RequiredModifiers="Ctrl,Shift" DisallowedModifiers="Alt,Windows" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.FastforwardHotkey}"/>
      <KeyHandler Name="KeyHandlerRewind"        Key="B"  RequiredModifiers="Ctrl,Shift" DisallowedModifiers="Alt,Windows" HandlerStage="Bubbled" Command="{zune:TransportControls.Instance.RewindHotkey}"/>
      <KeyHandler Name="KeyHandlerSearchFocus"   Key="E"  RequiredModifiers="Ctrl" DisallowedModifiers="Alt,Shift,Windows" HandlerStage="Bubbled" Command="{zune:Search.Instance.SearchFocusHotkey}"/>

      <FocusHandler Name="FocusChangedUsingKeyboard" Reason="Key" HandlerStage="Bubbled"/>
      <KeyHandler Name="ShowFocusRectF10" Key="F10" Handle="false" HandlerStage="Routed"/>
      <KeyHandler Name="ShowFocusRectApps" Key="Apps" Handle="false" HandlerStage="Routed"/>

      <KeyHandler Name="SpaceKeyHandler" Key="Space" RequiredModifiers="Alt" DisallowedModifiers="Ctrl,Shift,Windows" HandlerStage="Routed,Direct" Repeat="false" />

      <KeyHandler Name="AnyKeys" Key="Any" HandlerStage="Routed" Handle="false"/>
    </Input>


    <Scripts>
      
      <Script>zune:Shell.DefaultInstance.CommandHandler = ShellCommandHandlers;</Script>

      
      <Script>
        MouseDown.Command = PopupLayer.MouseDownCommand;
      </Script>

      
      <Script>
        zune:ZunePage page = [Shell.CurrentPage];
        if (page is zune:CategoryPage)
        {
          CancelSettings.Command = ((zune:CategoryPage) page).CancelButton;
        }
        else
        {
          CancelSettings.Command = null;
        }
      </Script>

      
      <Script>
        bool modalPopup = [PopupLayer.IsModal];
        bool backArrow = [Shell.CurrentPage.ShowBackArrow];
        bool computerIcon = ([Shell.CurrentPage.ShowComputerIcon] != zune:ComputerIconState.Hide);
        bool nowPlayingX = [Shell.CurrentPage.ShowNowPlayingX];

        
        CanGoBack = !modalPopup &amp;&amp; (computerIcon || backArrow || nowPlayingX);
      </Script>

      
      
      <Script>
        ResizeBorders.Visible = (!iris:Application.Window.ShowWindowFrame) &amp;&amp;
                                ([iris:Application.Window.WindowState] != iris:WindowState.Maximized);
      </Script>

      <Script>
        if ([iris:Application.Window.WindowState] == iris:WindowState.Maximized)
        {
          EnergyBar.LayoutInput = EnergyBarLayoutMax;
          Grabber.Visible = false;
        }
        else
        {
          Grabber.Visible = true;
          EnergyBar.LayoutInput = EnergyBarLayoutNorm;
        }
      </Script>

      
      <Script>
        AutoHideToolbars = [Shell.CurrentPage.AutoHideToolbars] &amp;&amp; [WindowState.CanHideMouse];

        iris:Application.Window.HideMouseOnIdle = AutoHideToolbars;
      </Script>

      
      <Script>
        iris:Application.Window.MouseIdleTimeout = MouseActivityTimeout;
      </Script>
      
      
      <Script>
        [DeclareTrigger(Shell.CurrentPage)]
        WindowState.PageInputActivity = false;
      </Script>

      
      <Script>
        bool hideNow = [AutoHideToolbars] &amp;&amp; 
                      ![iris:Application.Window.MouseActive] &amp;&amp; 
                      ![WindowState.KeysActive];
        
        

        TopToolbar.InvisibleMode    = hideNow;
        BottomToolbar.InvisibleMode = hideNow;

        
        

        FocusRect.Alpha = (float)!hideNow;
        AnyKeys.StopRoute = hideNow;
        
        styles:WindowState.InputActive = !hideNow;
      </Script>

      <Script>
        [DeclareTrigger(AnyKeys.Pressing)]
        WindowState.KeysActive = true;
        KeyIdleTimer.Stop();
        KeyIdleTimer.Start();
      </Script>

      <Script>
        [DeclareTrigger(KeyIdleTimer.Tick)]
        WindowState.KeysActive = false;
      </Script>

      

      
      <Script>
        [DeclareTrigger(ShortcutPlayPause.Invoked)]
        [DeclareTrigger(KeyHandlerPlayPause.Invoked)]
        if (zune:TransportControls.Instance.Playing)
        {
          zune:TransportControls.Instance.Pause.Invoke();
        }
        else
        {
          zune:TransportControls.Instance.Play.Invoke();
        }
      </Script>

      
      <Script>
        bool shouldBeVisible = [zune:JumpInListManager.Instance.IsActive];

        if (shouldBeVisible &amp;&amp; !JumpInList.Helper.IsVisible)
        {
            JumpInList.Helper.Show(JumpInList);
        }
        else if (!shouldBeVisible &amp;&amp; JumpInList.Helper.IsVisible)
        {
            JumpInList.Helper.Hide();
        }
      </Script>

      
      <Script>
        if (![JumpInList.Helper.IsVisible])
        {
          zune:JumpInListManager.Instance.Clear();
        }
      </Script>

      <Script>
        SpaceKeyHandler.Command = TopToolbar.MenuCommand;
      </Script>
      
      <Script>
        [DeclareTrigger(KeyHandlerToggleShuffle.Invoked)]
        zune:TransportControls.Instance.Shuffling.NextValue(true);
      </Script>

      <Script>
        [DeclareTrigger(KeyHandlerToggleRepeat.Invoked)]
        zune:TransportControls.Instance.Repeating.NextValue(true);
      </Script>

      <Script>
        [DeclareTrigger(KeyHandlerToggleMute.Invoked)]
        zune:TransportControls.Instance.Muted.NextValue(true);
      </Script>

      <Script>
        [DeclareTrigger(KeyHandlerVolumeDown.Invoked)]
        zune:TransportControls.Instance.Volume.Value = zune:TransportControls.Instance.Volume.Value - 10.0;
      </Script>

      <Script>
        [DeclareTrigger(KeyHandlerVolumeUp.Invoked)]
        zune:TransportControls.Instance.Volume.Value = zune:TransportControls.Instance.Volume.Value + 10.0;
      </Script>

      
      <Script>
        [DeclareTrigger(KeyHandlerHelp.Invoked)]
        
        string helpPath = "Help\" + zune:Shell.LoadString(zune:StringId.IDS_ZUNECLIENT_LOCALE) + "\LandingPage.htm";
        zune:Shell.DefaultInstance.Execute(helpPath, null);
      </Script>

      
      <Script>
        [DeclareTrigger(FocusChangedUsingKeyboard.GainedFocus)]
        [DeclareTrigger(ShowFocusRectF10.Invoked)]
        [DeclareTrigger(ShowFocusRectApps.Invoked)]
        FocusRect.Visible = true;
      </Script>

      
      <Script>
        if (![iris:Application.Window.Active] || ![zune:PopupManager.Instance.AnyDialogs])
        {
          FocusRect.Visible = false;
        }
      </Script>

      <Script>
        MainBackground.Visible = [Shell.CurrentPage.ShowAppBackground];
      </Script>

      <Script>
        MainBackground.Content = new Image([Shell.BackgroundImage], styles:Styles.BackgroundMargins);
      </Script>

    </Scripts>

    <Content>
      <Panel Layout="Anchor">
        <Children>
          
          <focus:FocusRect Name="FocusRect" Visible="false">
            <LayoutInput>
              <AnchorLayoutInput Left="Focus,0,-1" Right="Focus,1,1" Top="Focus,0,-1" Bottom="Focus,1,1" ContributesToHeight="false" ContributesToWidth="false"/>
            </LayoutInput>
          </focus:FocusRect>

          <nonclient:WindowResizeBorderLayer Name="ResizeBorders" Layout="Fill"/>

          <popuplayer:PopupLayer Name="PopupLayer" Layout="Fill"/>


          <Graphic Name="Grabber" Content="{styles:Styles.Grabber}" MaximumSize="9,6" Layout="Fill">
            <LayoutInput>
              <AnchorLayoutInput Name="GrabberLayout" Bottom="Parent,1" Right="Parent,1,-1"/>
            </LayoutInput>
          </Graphic>

          <Graphic Name="EnergyBar" Content="{styles:Styles.EnergyBar}" MaximumSize="0,6" Layout="Fill" Visible="true" Margins="1,0,0,0"/>


          <Panel Layout="Anchor" Navigation="RememberFocus,ContainAll,WrapTabOrder" FocusOrder="0">
            <Children>
              <Panel Layout="Dock">
                <Children>

                  
                  <toptoolbar:TopToolbar Name="TopToolbar" Shell="{Shell}" FocusOrder="1">
                    <LayoutInput>
                      <DockLayoutInput Position="Top"/>
                    </LayoutInput>
                  </toptoolbar:TopToolbar>

                  
                  <bottomtoolbar:BottomToolbar Name="BottomToolbar" Shell="{Shell}" FocusOrder="4">
                    <LayoutInput>
                      <DockLayoutInput Position="Bottom"/>
                    </LayoutInput>
                  </bottomtoolbar:BottomToolbar>

                  
                  
                  <page:PageBase Name="ForegroundUI" Shell="{Shell}" Page="{Shell.CurrentPage}" FocusOrder="2" Margins="{styles:Styles.FrameMargins}">
                    <LayoutInput>
                      <DockLayoutInput Position="Client"/>
                    </LayoutInput>
                  </page:PageBase>

                </Children>
              </Panel>

              
              <page:PageBase Name="BackgroundUI" Shell="{Shell}" Page="{Shell.CurrentPage}" FocusOrder="3" Layout="Fill"/>

            </Children>
          </Panel>

          <Graphic 
            Name="MainBackground" 
            Layout="Fill"
            ErrorImage="{styles:Styles.DefaultBackgroundImage}"
            >
            
            
            <Animations>
              <Animation Animation="{animations:Animations.MainBackgroundPageTransitionHide}"/>
            </Animations>
          </Graphic>

        </Children>
      </Panel>
    </Content>
  </UI>

</UIX>
