<!--
Copyright 2019 faddenSoft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<Window x:Class="SourceGen.WpfGui.EditLvTableLocation"
        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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SourceGen.WpfGui"
        mc:Ignorable="d"
        Title="Edit Local Variable Table Location"
        SizeToContent="WidthAndHeight" ResizeMode="NoResize"
        ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
        ContentRendered="Window_ContentRendered">

    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BoolToVis"/>
    </Window.Resources>

    <DockPanel LastChildFill="False" Margin="8">
        <TextBlock DockPanel.Dock="Top" Text="Select new location for table" Margin="0,0,75,8"/>
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
            <TextBlock Text="File offset (hex): +"/>

            <!-- up/down control, inspired by https://stackoverflow.com/a/5321605/294248 -->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <TextBox Name="offsetTextBox" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Width="50" MaxLength="6"
                         Text="{Binding OffsetStr, UpdateSourceTrigger=PropertyChanged, FallbackValue=012345}"/>
                <RepeatButton Grid.Column="1" Grid.Row="0" Content="5" FontSize="8" FontFamily="Marlett"
                              VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
                              Click="OffsetUp_Click"/>
                <RepeatButton Grid.Column="1" Grid.Row="1" Content="6" FontSize="8" FontFamily="Marlett"
                              VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
                              Click="OffsetDown_Click"/>
            </Grid>

        </StackPanel>
        <DockPanel DockPanel.Dock="Bottom" LastChildFill="False" Margin="0,16,0,0">
            <Button DockPanel.Dock="Right" Content="Cancel" Width="70" Margin="8,0,0,0" IsCancel="True"/>
            <Button DockPanel.Dock="Right" Grid.Column="1" Content="OK" Width="70"
                    IsDefault="True" IsEnabled="{Binding IsValid}" Click="OkButton_Click"/>
        </DockPanel>

        <TextBlock DockPanel.Dock="Bottom" Margin="0,4,0,0"
                   Text="• Offset must not already have a local variable table"
                   Foreground="{Binding TableAlreadyPresentBrush}"/>
        <TextBlock DockPanel.Dock="Bottom" Margin="0,4,0,0"
                   Text="• Offset must be the start of an instruction"
                   Foreground="{Binding NotInstructionBrush}"/>
        <TextBlock DockPanel.Dock="Bottom" Margin="0,4,0,0"
                   Text="• Offset value must be valid"
                   Foreground="{Binding InvalidOffsetBrush}"/>
    </DockPanel>
</Window>
