<!-- **************************************************************************

  Copyright (c) 2010 CubeSoft, Inc.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published
  by the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*************************************************************************** -->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:r="urn:fluent-ribbon"
    xmlns:fs="clr-namespace:Cube.FileSystem;assembly=Cube.FileSystem"
    xmlns:xc="clr-namespace:Cube.Xui.Converters;assembly=Cube.Xui"
    xmlns:my="clr-namespace:Cube.Pdf.Editor">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/ScrollStyle.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!-- **********************************************************************
      ScrollViewer for RibbonTabControl
    *********************************************************************** -->
    <ControlTemplate x:Key="RibbonTabScrollTemplate" TargetType="{x:Type ScrollViewer}">
        <Grid Background="{TemplateBinding Background}" IsHitTestVisible="True">
            <ScrollContentPresenter
                x:Name="PART_ScrollContentPresenter"
                Margin="{TemplateBinding Padding}"
                Content="{TemplateBinding Content}"
                ContentTemplate="{TemplateBinding ContentTemplate}"
                CanContentScroll="{TemplateBinding CanContentScroll}"
                IsHitTestVisible="True" />

            <!-- **************************************************************
              Left side Scroll button
            *************************************************************** -->
            <RepeatButton
                Command="{x:Static ScrollBar.LineLeftCommand}"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Width="16"
                Height="Auto"
                Focusable="false"
                HorizontalAlignment="Left"
                VerticalAlignment="Stretch"
                Style="{DynamicResource ScrollButtonStyle}">
                <RepeatButton.Visibility>
                    <MultiBinding
                        FallbackValue="Visibility.Collapsed"
                        Converter="{StaticResource MenuScrollingVisibilityConverter}"
                        ConverterParameter="0">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ComputedHorizontalScrollBarVisibility" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="HorizontalOffset" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ExtentWidth" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ViewportWidth" />
                    </MultiBinding>
                </RepeatButton.Visibility>
                <Path
                    Fill="{StaticResource TabForegroundBrush}"
                    Stretch="Fill"
                    Stroke="{x:Null}"
                    StrokeThickness="0"
                    HorizontalAlignment="Center"
                    Margin="0"
                    VerticalAlignment="Center"
                    Width="4"
                    Height="6"
                    Data="M0,0L1,1 1,-1z" />
            </RepeatButton>

            <!-- **************************************************************
              Right side Scroll button
            *************************************************************** -->
            <RepeatButton
                Command="{x:Static ScrollBar.LineRightCommand}"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Width="16"
                Height="Auto"
                Focusable="false"
                HorizontalAlignment="Right"
                VerticalAlignment="Stretch"
                Style="{DynamicResource ScrollButtonStyle}">
                <RepeatButton.Visibility>
                    <MultiBinding
                        FallbackValue="Visibility.Collapsed"
                        Converter="{StaticResource MenuScrollingVisibilityConverter}"
                        ConverterParameter="100">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ComputedHorizontalScrollBarVisibility" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="HorizontalOffset" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ExtentWidth" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ViewportWidth" />
                    </MultiBinding>
                </RepeatButton.Visibility>
                <Path
                    Fill="{StaticResource TabForegroundBrush}"
                    Stretch="Fill"
                    Stroke="{x:Null}"
                    StrokeThickness="0"
                    HorizontalAlignment="Center"
                    Margin="0"
                    VerticalAlignment="Center"
                    Width="4"
                    Height="6"
                    Data="M1,0L0,1 0,-1z" />
            </RepeatButton>
        </Grid>
    </ControlTemplate>

    <!-- **********************************************************************
      RibbonTabControl
    *********************************************************************** -->
    <ControlTemplate x:Key="RibbonTabControlControlTemplate" TargetType="{x:Type r:RibbonTabControl}">
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type ScrollViewer}">
                <Setter Property="Template" Value="{StaticResource RibbonTabScrollTemplate}" />
                <Setter Property="CanContentScroll" Value="True" />
                <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
                <Setter Property="VerticalScrollBarVisibility" Value="Disabled" />
                <Setter Property="PanningMode" Value="HorizontalOnly" />
            </Style>
        </ControlTemplate.Resources>

        <Grid
            Background="{TemplateBinding Background}"
            Height="100"
            VerticalAlignment="Top"
            KeyboardNavigation.TabNavigation="Local">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <!-- **************************************************************
              TabHeader
            *************************************************************** -->
            <Border
                HorizontalAlignment="Stretch"
                Margin="0,-1,0,0"
                Width="Auto"
                BorderThickness="0,1"
                Grid.Row="1"
                BorderBrush="{Binding Path=SelectedItem.BorderBrush, RelativeSource={RelativeSource TemplatedParent}}" />

            <!-- **************************************************************
              TabItem
            *************************************************************** -->
            <Border
                HorizontalAlignment="Stretch"
                Background="{StaticResource TabBackgroundBrush}"
                TextElement.Foreground="{StaticResource TabForegroundBrush}"
                BorderBrush="{StaticResource TabBorderBrush}"
                BorderThickness="0,0,0,1"
                Margin="1,0,1,0"
                KeyboardNavigation.TabNavigation="Local"
                KeyboardNavigation.DirectionalNavigation="Contained"
                KeyboardNavigation.TabIndex="2"
                Grid.Row="1">
                <ContentControl Focusable="False">
                    <ContentPresenter
                        x:Name="PART_SelectedContentPresenter"
                        ContentSource="SelectedContent"
                        HorizontalAlignment="Stretch" />
                </ContentControl>
            </Border>

            <!-- **************************************************************
              TabsContainer
            *************************************************************** -->
            <Grid
                Background="{DynamicResource Fluent.Ribbon.Brushes.RibbonTabControl.TabsGrid.Background}"
                TextElement.Foreground="{DynamicResource Fluent.Ribbon.Brushes.RibbonTabControl.TabsGrid.Foreground}"
                Width="Auto"
                HorizontalAlignment="Stretch"
                KeyboardNavigation.TabIndex="1"
                Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <r:WindowSteeringHelperControl Grid.ColumnSpan="4" />
                <ContentPresenter ContentSource="Menu" VerticalAlignment="Stretch" />
                <r:RibbonScrollViewer
                    Style="{DynamicResource RibbonTabScrollViewer}"
                    Width="Auto"
                    HorizontalAlignment="Left"
                    HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Disabled"
                    IsHitTestVisible="True"
                    IsTabStop="False"
                    Visibility="{Binding AreTabHeadersVisible,
                    RelativeSource={RelativeSource TemplatedParent},
                    Converter={xc:BooleanToVisibility}}"
                    Grid.Column="1">
                    <r:RibbonTabsContainer
                        x:Name="PART_TabsContainer"
                        Height="Auto"
                        HorizontalAlignment="Stretch"
                        IsItemsHost="True"
                        KeyboardNavigation.TabIndex="1" />
                </r:RibbonScrollViewer>
            </Grid>
        </Grid>
    </ControlTemplate>

    <!-- **********************************************************************
      RibbonRecentCollection
    *********************************************************************** -->
    <ControlTemplate x:Key="RibbonRecentCollectionTemplate" TargetType="{x:Type ListBox}">
        <ScrollViewer
            Background="{StaticResource WindowBackgroundBrush}"
            Foreground="{StaticResource WindowForegroundBrush}"
            Template="{StaticResource ScrollViewerTemplate}"
            BorderThickness="0"
            HorizontalScrollBarVisibility="Disabled">
            <StackPanel
                Orientation="Vertical"
                IsItemsHost="True" />
        </ScrollViewer>
    </ControlTemplate>

    <!-- **********************************************************************
      RibbonRecentItem
    *********************************************************************** -->
    <DataTemplate x:Key="RibbonRecentItemTemplate" DataType="{x:Type fs:Entity}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="16" />
                <ColumnDefinition Width="6"  />
                <ColumnDefinition Width="*"  />
            </Grid.ColumnDefinitions>

            <Image
                Source="{Binding Converter={my:IconConverter}}"
                Stretch="Uniform" />

            <TextBlock
                Text="{Binding BaseName}"
                TextWrapping="NoWrap"
                TextTrimming="CharacterEllipsis"
                Grid.Column="2" />
        </Grid>
    </DataTemplate>
</ResourceDictionary>