<UserControl
    x:Class="Microsoft.Terminal.TerminalControl.TermControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:Microsoft.Terminal.TerminalControl"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    d:DesignHeight="768"
    d:DesignWidth="1024"
    TabNavigation="Cycle"
    IsTabStop="True"
    AllowFocusOnInteraction="True"
    AllowDrop="True"
    Drop="_DragDropHandler"
    DragOver="_DragOverHandler"
    Tapped="_TappedHandler"
    PointerWheelChanged="_MouseWheelHandler"
    PreviewKeyDown="_KeyDownHandler"
    KeyUp="_KeyUpHandler"
    CharacterReceived="_CharacterHandler"
    GotFocus="_GotFocusHandler"
    LostFocus="_LostFocusHandler">
    <!--
        TODO GH#4031: We've investigated whether we should be using KeyDown or PreviewKeyDown
        but not necessarily come to a consensus. It's possible that moving input to the SwapChainPanel
        will solve a bunch of the search input issues we found last time we switched.
    -->

    <Grid x:Name="RootGrid">
        <Image x:Name="BackgroundImage"
               AutomationProperties.AccessibilityView="Raw" />
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0"
                  Visibility="Visible"
                  Background="Transparent"
                  PointerPressed="_PointerPressedHandler"
                  PointerMoved="_PointerMovedHandler"
                  PointerReleased="_PointerReleasedHandler">

                <SwapChainPanel x:Name="SwapChainPanel"
                                SizeChanged="_SwapChainSizeChanged"
                                CompositionScaleChanged="_SwapChainScaleChanged" />

                <!-- Putting this in a grid w/ the SwapChainPanel
                ensures that it's always aligned w/ the scrollbar -->
                <local:SearchBoxControl x:Name="SearchBox"
                                        x:Load="False"
                                        Visibility="Collapsed"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Top"
                                        Search="_Search"
                                        Closed="_CloseSearchBoxControl" />
            </Grid>

            <ScrollBar Grid.Column="1"
                       x:Name="ScrollBar"
                       Orientation="Vertical"
                       IndicatorMode="MouseIndicator"
                       HorizontalAlignment="Right"
                       VerticalAlignment="Stretch"
                       Maximum="1"
                       ViewportSize="10"
                       IsTabStop="False"
                       SmallChange="1"
                       LargeChange="4"
                       ValueChanged="_ScrollbarChangeHandler"
                       PointerPressed="_CapturePointer"
                       PointerReleased="_ReleasePointerCapture" />
        </Grid>

        <local:TSFInputControl x:Name="TSFInputControl"
                               CompositionCompleted="_CompositionCompleted"
                               CurrentCursorPosition="_CurrentCursorPositionHandler"
                               CurrentFontInfo="_FontInfoHandler" />

        <Grid x:Name="RendererFailedNotice"
              x:Load="False"
              HorizontalAlignment="Center"
              VerticalAlignment="Center">
            <Border Background="{ThemeResource SystemControlBackgroundAltHighBrush}"
                    BorderBrush="{ThemeResource SystemAccentColor}"
                    Margin="8,8,8,8"
                    Padding="8,8,8,8"
                    BorderThickness="2,2,2,2"
                    CornerRadius="{ThemeResource OverlayCornerRadius}">
                <StackPanel>
                    <TextBlock HorizontalAlignment="Center" x:Uid="TermControl_RendererFailedTextBlock" TextWrapping="WrapWholeWords"/>
                    <Button Click="_RenderRetryButton_Click" x:Uid="TermControl_RendererRetryButton" HorizontalAlignment="Right" />
                </StackPanel>
            </Border>
        </Grid>

    </Grid>

</UserControl>
