<Window x:Class="Hiyoko.Forms.MainForm" x:Name="this"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:c="clr-namespace:Hiyoko"
	xmlns:HiyokoForms="clr-namespace:Hiyoko.Forms"
	xmlns:NetCache="clr-namespace:System.Net.Cache"
	Title="Hiyoko - A Twitter Client" Height="640" Width="640"
	ResizeMode="CanResizeWithGrip"
	Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
	FontSize="12">
	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
			</ResourceDictionary.MergedDictionaries>
			
			<HiyokoForms:Int32ToSolidColorBrushConverter x:Key="Int32ToSolidColorBrushConverter" />
			<HiyokoForms:DateTimeToStringConverter x:Key="DateTimeToStringConverter" />
			<HiyokoForms:RemoveHtmlTagsConverter x:Key="RemoveHtmlTagsConverter" />
			<HiyokoForms:OutputItemToImageSourceConverter x:Key="OutputItemToImageSourceConverter" />
			<HiyokoForms:UrlToImageSourceConverter x:Key="UrlToImageSourceConverter" />
			<HiyokoForms:TextToMarkupTextConverter x:Key="TextToMarkupTextConverter" />
			
			<SolidColorBrush x:Key="statusEditCountNormalColor" Color="Gray" />
			<SolidColorBrush x:Key="statusEditCountWarningColor" Color="DarkRed" />
			<SolidColorBrush x:Key="statusEditCountHighWarningColor" Color="Red" />
			<SolidColorBrush x:Key="transparentBrush" Color="#00000000" />
			
			<BitmapImage x:Key="PostIcon" UriSource="/Resources/Post.png" />
			
			<DataTemplate x:Key="outputItemTemplate">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="auto" />
						<ColumnDefinition Width="*" />
						<ColumnDefinition Width="auto" />
					</Grid.ColumnDefinitions>
					<Image Grid.Column="0" Source="{Binding Converter={StaticResource OutputItemToImageSourceConverter}}" Width="15" Height="15" />
					<TextBlock Grid.Column="1" Text="{Binding Text}" />
					<TextBlock Grid.Column="2" Text="{Binding Path=DateTime, Converter={StaticResource DateTimeToStringConverter}}" />
				</Grid>
			</DataTemplate>  
			<Style x:Key="outputListBoxStyle" TargetType="{x:Type ListBox}">  
				<Setter Property="HorizontalContentAlignment" Value="Stretch" />
				<Setter Property="ItemTemplate" Value="{StaticResource outputItemTemplate}" />  
				<Setter Property="ItemsPanel">
					<Setter.Value>
						<ItemsPanelTemplate>
							<VirtualizingStackPanel Orientation="Vertical" />
						</ItemsPanelTemplate>
					</Setter.Value>
				</Setter>
			</Style>
			
			<DataTemplate x:Key="statusTemplate">
				<StackPanel Name="RootPanel" MouseDown="TimelineItem_MouseDown">
					<Border Margin="4" Padding="4" BorderThickness="1" CornerRadius="4"
						BorderBrush="{Binding Path=User.ProfileSidebarBorderColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}"
						Background="{Binding Path=User.ProfileBackgroundColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}">
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="auto" />
								<ColumnDefinition Width="*" />
							</Grid.ColumnDefinitions>
							<Image Width="47" Height="47" Margin="0,0,4,0" Source="{Binding Path=User.ProfileImageUrl, Converter={StaticResource UrlToImageSourceConverter}}"></Image>
							<Grid Grid.Column="1" Background="#eeffffff">
								<Grid.RowDefinitions>
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
								</Grid.RowDefinitions>
								<Grid Grid.Row="0">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="auto" />
										<ColumnDefinition Width="auto" />
										<ColumnDefinition Width="*" />
										<ColumnDefinition Width="auto" />
										<ColumnDefinition Width="auto" />
									</Grid.ColumnDefinitions>
									<TextBlock Grid.Column="0" Margin="2" FontWeight="UltraBold" Text="{Binding Path=User.Name, Mode=OneWay}"
										Foreground="{Binding Path=User.ProfileLinkColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}"
										Background="{StaticResource transparentBrush}" />
									<TextBlock Grid.Column="1" Margin="4,2,4,2" Text="/"
										Foreground="{Binding Path=User.ProfileTextColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}" />
									<TextBlock Grid.Column="2" Margin="2" Text="{Binding Path=User.ScreenName, Mode=OneWay}"
										Foreground="{Binding Path=User.ProfileTextColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}"
										Background="{StaticResource transparentBrush}" />
									<TextBlock Grid.Column="3" Margin="2" Text="{Binding Path=User.Location, Mode=OneWay}"
										Foreground="{Binding Path=User.ProfileTextColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}"
										Background="{StaticResource transparentBrush}" />
									<TextBlock Grid.Column="4" Margin="2" Text="{Binding Path=CreatedAt, Mode=OneWay, Converter={StaticResource DateTimeToStringConverter}}"
										Foreground="{Binding Path=User.ProfileTextColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}"
										Background="{StaticResource transparentBrush}" />
								</Grid>
								<TextBox Grid.Row="1" Margin="2" Text="{Binding Path=Text, Mode=OneWay}"
									TextWrapping="Wrap" IsReadOnly="true" BorderThickness="0"
									Foreground="{Binding Path=User.ProfileTextColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}"
									Background="{StaticResource transparentBrush}" />
								<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
									<TextBlock Text="{Binding Path=Source, Converter={StaticResource RemoveHtmlTagsConverter}}" 
									Foreground="{Binding Path=User.ProfileTextColor, Converter={StaticResource Int32ToSolidColorBrushConverter}}" />
									<TextBlock Text=" で" />
								</StackPanel>
							</Grid>
						</Grid>
					</Border>
				</StackPanel>
				<DataTemplate.Triggers>
					<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}}" Value="true">
						<Setter TargetName="RootPanel" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
					</DataTrigger>
				</DataTemplate.Triggers>
			</DataTemplate>  
			<Style x:Key="timelineListBoxStyle" TargetType="{x:Type ListBox}">  
				<Setter Property="HorizontalContentAlignment" Value="Stretch" />
				<Setter Property="ItemTemplate" Value="{StaticResource statusTemplate}" />  
				<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
				<Setter Property="ScrollViewer.Margin" Value="0" />
				<Setter Property="ScrollViewer.Padding" Value="0" />
				<Setter Property="SelectionMode" Value="Extended" />
				<Setter Property="ItemsPanel">
					<Setter.Value>
						<ItemsPanelTemplate>
							<VirtualizingStackPanel Orientation="Vertical" />
						</ItemsPanelTemplate>
					</Setter.Value>
				</Setter>
			</Style> 

		</ResourceDictionary>
	</Window.Resources>
	<Window.CommandBindings>
		<CommandBinding Command="ApplicationCommands.Close" Executed="Close_Executed" CanExecute="Close_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.Refresh" Executed="Refresh_Executed" CanExecute="Refresh_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.UpdateStatus" Executed="UpdateStatus_Executed" CanExecute="UpdateStatus_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.NextPage" Executed="NextPage_Executed" CanExecute="NextPage_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.PreviousPage" Executed="PreviousPage_Executed" CanExecute="PreviousPage_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.FirstPage" Executed="FirstPage_Executed" CanExecute="FirstPage_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.About" Executed="About_Executed" CanExecute="About_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.Settings" Executed="Settings_Executed" CanExecute="Settings_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.SaveTimeline" Executed="SaveTimeline_Executed" CanExecute="SaveTimeline_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.DestroyStatus" Executed="DestroyStatus_Executed" CanExecute="DestroyStatus_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.OpenTwitterCom" Executed="OpenTwitterCom_Executed" CanExecute="OpenTwitterCom_CanExecute"/>
		<CommandBinding Command="c:HiyokoCommands.OpenHome" Executed="OpenMyHome_Executed" CanExecute="OpenMyHome_CanExecute"/>
	</Window.CommandBindings>
	<Window.InputBindings>
		<KeyBinding Command="c:HiyokoCommands.Refresh" Key="F5"/>
	</Window.InputBindings>
	
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="auto" />
			<RowDefinition Height="*" />
			<RowDefinition Height="auto" />
		</Grid.RowDefinitions>
		<Menu Grid.Row="0">
			<MenuItem Header="ファイル(_F)">
				<MenuItem Header="twitter.comを開く(_T)" Command="c:HiyokoCommands.OpenTwitterCom" />
				<MenuItem Header="自分のホームを開く(_H)" Command="c:HiyokoCommands.OpenHome" />
				<Separator />
				<MenuItem Header="タイムラインを保存(_A)" Command="c:HiyokoCommands.SaveTimeline" />
				<Separator/>
				<MenuItem Header="設定(_S)" Command="c:HiyokoCommands.Settings" />
				<Separator/>
				<MenuItem Header="終了(_X)" Command="ApplicationCommands.Close"  />
			</MenuItem>
			<MenuItem Header="表示(_V)">
				<MenuItem Header="更新(_R)" Command="c:HiyokoCommands.Refresh" InputGestureText="F5" />
				<Separator/>
				<MenuItem Header="最初のページ(_F)" Command="c:HiyokoCommands.FirstPage" InputGestureText="Alt+\" />
				<MenuItem Header="前のページ(_P)" Command="c:HiyokoCommands.PreviousPage" InputGestureText="Alt+B" />
				<MenuItem Header="次のページ(_N)" Command="c:HiyokoCommands.NextPage" InputGestureText="Alt+N" />
			</MenuItem>
			<MenuItem Header="ヘルプ(_H)">
				<MenuItem Header="Hiyokoについて(_A)" Command="c:HiyokoCommands.About" />
			</MenuItem>
		</Menu>
		<Grid Grid.Row="1">
			<Grid.RowDefinitions>
				<RowDefinition Height="*" />
				<RowDefinition Name="outputListRow" Height="64" />
			</Grid.RowDefinitions>
			
			<TabControl Grid.Row="0">
				<TabItem Header="タイムライン(_1)" Name="timelineTabItem">
					<TabItem.CommandBindings>
						<CommandBinding Command="c:HiyokoCommands.OpenUrls" Executed="OpenUrlsTimeline_Executed" CanExecute="OpenUrlsTimeline_CanExecute"/>	
						<CommandBinding Command="c:HiyokoCommands.OpenSite" Executed="OpenSiteTimeline_Executed" CanExecute="OpenSiteTimeline_CanExecute"/>	
						<CommandBinding Command="c:HiyokoCommands.OpenHome" Executed="OpenHomeTimeline_Executed" CanExecute="OpenHomeTimeline_CanExecute"/>	
						<CommandBinding Command="c:HiyokoCommands.CreateFavorite" Executed="CreateFavoriteTimeline_Executed" CanExecute="CreateFavoriteTimeline_CanExecute"/>	
						<CommandBinding Command="c:HiyokoCommands.CreateBlock" Executed="CreateBlockTimeline_Executed" CanExecute="CreateBlockTimeline_CanExecute"/>	
						<CommandBinding Command="c:HiyokoCommands.DestroyFriendship" Executed="DestroyFriendshipTimeline_Executed" CanExecute="DestroyFriendshipTimeline_CanExecute"/>	
					</TabItem.CommandBindings>
					<Grid>
						<Grid.RowDefinitions>
							<RowDefinition Height="auto" />
							<RowDefinition Height="*" />
							<RowDefinition Height="auto" />
						</Grid.RowDefinitions>
						<Grid Grid.Row="0" Margin="4">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="auto" />
								<ColumnDefinition Width="*" />
								<ColumnDefinition Width="auto" />
								<ColumnDefinition Width="auto" />
							</Grid.ColumnDefinitions>
							<Label Grid.Column="0" Target="{Binding ElementName=statusEdit}">ステータス(_S):</Label>
							<TextBox
								Grid.Column="1"
								Name="statusEdit" Height="32"
								TextWrapping="Wrap" BorderThickness="0"
								TextChanged="StatusEdit_TextChanged">
								<TextBox.InputBindings>
									<KeyBinding Command="c:HiyokoCommands.UpdateStatus" Key="Enter" Modifiers="Control"/>
									<KeyBinding Command="ComponentCommands.ScrollPageUp" Key="PageUp" />
									<KeyBinding Command="ComponentCommands.ScrollPageDown" Key="PageDown" />
								</TextBox.InputBindings>
								<TextBox.CommandBindings>
									<CommandBinding Command="ComponentCommands.ScrollPageUp" Executed="ScrollPageUpTimeline_Executed" CanExecute="ScrollPageUpTimeline_CanExecute" />
									<CommandBinding Command="ComponentCommands.ScrollPageDown" Executed="ScrollPageDownTimeline_Executed" CanExecute="ScrollPageDownTimeline_CanExecute" />
								</TextBox.CommandBindings>
								<TextBox.Style>
									<Style TargetType="TextBox">
										<Setter Property="Template">
											<Setter.Value>
												<ControlTemplate TargetType="{x:Type TextBoxBase}">
													<Border Name="Border" BorderBrush="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" BorderThickness="1" CornerRadius="4"
														Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
														<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
													</Border>
													<ControlTemplate.Triggers>
														<Trigger Property="IsReadOnly" Value="true">
															<Setter TargetName="Border" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
															<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
														</Trigger>
														<MultiTrigger>
															<MultiTrigger.Conditions>
																<Condition Property="IsFocused" Value="true" />
																<Condition Property="IsReadOnly" Value="false" />
															</MultiTrigger.Conditions>
															<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
														</MultiTrigger>
													</ControlTemplate.Triggers>
												</ControlTemplate>
											</Setter.Value>
										</Setter>
									</Style>
								</TextBox.Style>
							</TextBox>
							<Label Grid.Column="2" Name="statusEditCount" FontWeight="UltraBold" FontSize="24"></Label>
							<Button Grid.Column="3" Name="statusSubmitButton" IsTabStop="false" ToolTip="Ctrl+Enterで投稿" Command="c:HiyokoCommands.UpdateStatus">
								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="auto" />
										<ColumnDefinition Width="auto" />
									</Grid.ColumnDefinitions>
									<Image Grid.Column="0" Source="{StaticResource PostIcon}" Width="15" Height="15" />
									<TextBlock Grid.Column="1">投稿</TextBlock>
								</Grid>
							</Button>
						</Grid>
						
						<ListBox Grid.Row="1" ItemsSource="{Binding}" Name="timelineList"
							Style="{StaticResource timelineListBoxStyle}">
							<ListBox.CommandBindings>
								<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyStatus_Executed" CanExecute="CopyStatus_CanExecute" />
							</ListBox.CommandBindings>
							<ListBox.InputBindings>
								<KeyBinding Command="ApplicationCommands.Copy" Key="C" Modifiers="Control" />
								<KeyBinding Command="ApplicationCommands.Copy" Key="Insert" Modifiers="Control" />
							</ListBox.InputBindings>
							<ListBox.ContextMenu>
								<ContextMenu>
									<MenuItem Header="含まれるUrlを開く(_U)" Command="c:HiyokoCommands.OpenUrls" FontWeight="Bold" />
									<MenuItem Header="ユーザーのホームを開く(_H)" Command="c:HiyokoCommands.OpenHome" />
									<MenuItem Header="ユーザーのサイトを開く(_S)" Command="c:HiyokoCommands.OpenSite" />
									<Separator />
									<MenuItem Header="お気に入りに追加(_F)" Command="c:HiyokoCommands.CreateFavorite" />
									<MenuItem Header="ブロックに追加(_B)"  Command="c:HiyokoCommands.CreateBlock" />
									<MenuItem Header="フォローを削除(_R)"  Command="c:HiyokoCommands.DestroyFriendship" />
									<Separator />
									<MenuItem Header="コピー(_C)"  Command="ApplicationCommands.Copy" />
									<Separator />
									<MenuItem Header="削除(_D)"  Command="c:HiyokoCommands.DestroyStatus"/>
								</ContextMenu>
							</ListBox.ContextMenu>
						</ListBox>
						
						<HiyokoForms:Pager Grid.Row="2" CurrentPage="{Binding Path=CurrentTimelinePage, ElementName=this}"/>
					</Grid>
				</TabItem>
				
				<TabItem Header="フレンド(_2)" IsEnabled="false">
					<ListView ItemsSource="{Binding}" Name="friendList"> 
					</ListView>
				</TabItem>
				
				<TabItem Header="フォロワー(_3)" IsEnabled="false">
					<ListView ItemsSource="{Binding}" Name="followerList"> 
					</ListView>
				</TabItem>
				
				<TabItem Header="お気に入り(_4)" IsEnabled="false">
					<ListView ItemsSource="{Binding}" Name="favoriteList"> 
					</ListView>
				</TabItem>
				
				<TabItem Header="ブロック(_5)" IsEnabled="false">
					<ListView ItemsSource="{Binding}" Name="blockList"> 
					</ListView>
				</TabItem>
				
				<TabItem Header="ユーザー検索(_6)">
					<Grid>
						<Grid.RowDefinitions>
							<RowDefinition Height="auto" />
							<RowDefinition Height="*" />
							<RowDefinition Height="auto" />
						</Grid.RowDefinitions>
						
						<ListView Grid.Row="1" ItemsSource="{Binding}" Name="searchList"> 
						</ListView>
						
						<HiyokoForms:Pager Grid.Row="2" />
					</Grid>
				</TabItem>
			</TabControl>
			
			<Grid Grid.Row="1">
				<Grid.RowDefinitions>
					<RowDefinition Height="auto" />
					<RowDefinition Height="*" />
				</Grid.RowDefinitions>
				
				<Label Grid.Row="0" Target="{Binding ElementName=outputList}">アウトプット(_O):</Label>
				<ListBox Grid.Row="1" ItemsSource="{Binding}" Name="outputList"
					Style="{StaticResource outputListBoxStyle}"> 
				</ListBox>
			</Grid>
			
			<GridSplitter 
				Grid.Row="1" Height="2" Margin="2"
				HorizontalAlignment="Stretch" VerticalAlignment="Top"
				Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" />
		</Grid>
		<StatusBar Grid.Row="2">
			<StatusBarItem>
				<TextBlock Name="statusBarMessageBlock" />
			</StatusBarItem>
		</StatusBar>
	</Grid>
</Window>
