Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Interim version of needed resizer

  • Loading branch information...
commit 1b1da861ea0eb727550fab8f79f535092aa59721 1 parent bea541d
@flq authored
View
23 Thawmadoce/App.xaml
@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Thawmadoce="clr-namespace:Thawmadoce.Bootstrapping"
- xmlns:Converters="clr-namespace:Thawmadoce.Frame.Converters">
+ xmlns:Converters="clr-namespace:Thawmadoce.Frame.Converters" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@@ -13,8 +13,8 @@
<BooleanToVisibilityConverter x:Key="BoolToVis" />
<Converters:PathToImageSourceConverter x:Key="PathToImg" />
-
- <SolidColorBrush x:Key="TransparentBlack" Color="#AA000000" />
+ <sys:Double x:Key="BorderOpacity">1.0</sys:Double>
+ <SolidColorBrush x:Key="TransparentBlack" Color="#FA000000" />
<Thickness x:Key="PositioningOfAppItemButton">0,2,100,0</Thickness>
<Thickness x:Key="PositioningOfEditorToolbar">0,3,110,0</Thickness>
@@ -30,6 +30,23 @@
<GradientStop Color="Black" Offset="0.732"/>
</LinearGradientBrush>
+ <Style x:Key="ResizeHandle" TargetType="{x:Type Control}">
+ <Setter Property="Width" Value="20" />
+ <Setter Property="Height" Value="20" />
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate>
+ <Rectangle Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Fill="Transparent" />
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsMouseOver" Value="True">
+ <Setter Property="Cursor" Value="SizeNWSE" />
+ </Trigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+
<Style x:Key="Button_VisibleCommand" TargetType="{x:Type Button}">
<Setter Property="Background" Value="{StaticResource Blueback}"/>
<Setter Property="Margin" Value="3" />
View
19 Thawmadoce/Frame/Extensions/WpfExtensions.cs
@@ -0,0 +1,19 @@
+using System.Windows;
+using System.Windows.Media;
+
+namespace Thawmadoce.Frame.Extensions
+{
+ public static class WpfExtensions
+ {
+ public static T GetVisualParent<T>(this DependencyObject obj) where T : DependencyObject
+ {
+ while (obj != null)
+ {
+ if (obj is T)
+ return (T)obj;
+ obj = VisualTreeHelper.GetParent(obj);
+ }
+ return null;
+ }
+ }
+}
View
28 Thawmadoce/Frame/Handle.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using Thawmadoce.Frame.Extensions;
+
+namespace Thawmadoce.Frame
+{
+ public class Handle : Control
+ {
+ private WindowResizer wdwR;
+
+ public Handle()
+ {
+ Loaded += HandleLoaded;
+ }
+
+ private void HandleLoaded(object sender, RoutedEventArgs e)
+ {
+ var wdw = this.GetVisualParent<Window>();
+ if (wdw == null)
+ return; //WTF!
+ wdwR = new WindowResizer(wdw, this);
+ }
+
+
+ }
+}
View
74 Thawmadoce/Frame/WindowResizer.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Windows;
+using System.Windows.Input;
+using System.Runtime.InteropServices;
+using System.Windows.Threading;
+
+namespace Thawmadoce.Frame
+{
+ /// <summary>
+ /// Inspired by http://www.codeproject.com/KB/WPF/WPF_Window_Resizing.aspx
+ /// but heavily modified.
+ /// </summary>
+ public class WindowResizer
+ {
+ private readonly Window _target;
+ private bool _resizing;
+ private PointApi _resizePoint;
+ private Size _resizeSize;
+ private readonly DispatcherTimer _timer;
+
+ public WindowResizer(Window target, UIElement gripElement)
+ {
+ _target = target;
+
+ _timer = new DispatcherTimer(DispatcherPriority.Send, _target.Dispatcher)
+ {Interval = TimeSpan.FromMilliseconds(10)};
+ _timer.Tick += HandleMouseCheck;
+ gripElement.MouseLeftButtonDown += HandleElementMouseLeftButtonDown;
+ }
+
+ private void HandleElementMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ GetCursorPos(out _resizePoint);
+ _resizeSize = new Size(_target.Width, _target.Height);
+ _resizing = true;
+ _timer.Start();
+ }
+
+ private void HandleMouseCheck(object sender, EventArgs e)
+ {
+ if (_resizing)
+ {
+ UpdateSize();
+ UpdateMouseDown();
+ }
+ else
+ _timer.Stop();
+ }
+
+ private void UpdateSize()
+ {
+ PointApi p;
+ GetCursorPos(out p);
+ _target.Height = _resizeSize.Height - (_resizePoint.Y - p.Y);
+ _target.Width = _resizeSize.Width - (_resizePoint.X - p.X);
+ }
+
+ private void UpdateMouseDown()
+ {
+ if (Mouse.LeftButton == MouseButtonState.Released)
+ _resizing = false;
+ }
+
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool GetCursorPos(out PointApi lpPoint);
+
+ private struct PointApi
+ {
+ public int X;
+ public int Y;
+ }
+ }
+}
View
7 Thawmadoce/ShellView.xaml
@@ -1,12 +1,12 @@
<Window x:Class="Thawmadoce.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Icon="thawmadoce.ico"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Frame="clr-namespace:Thawmadoce.Frame" Icon="thawmadoce.ico"
WindowStyle="None"
Background="Transparent"
AllowsTransparency="True">
<Grid>
- <ContentControl x:Name="WindowHeader" HorizontalAlignment="Stretch" VerticalAlignment="Top" Opacity="0.6" />
- <Image Source="/Media/upper_left_fill.png" Margin="0,24,0,0" Width="9" Height="9" VerticalAlignment="Top" HorizontalAlignment="Left" Opacity="0.6" />
+ <ContentControl x:Name="WindowHeader" HorizontalAlignment="Stretch" VerticalAlignment="Top" Opacity="{StaticResource BorderOpacity}" />
+ <Image Source="/Media/upper_left_fill.png" Margin="0,24,0,0" Width="9" Height="9" VerticalAlignment="Top" HorizontalAlignment="Left" Opacity="{StaticResource BorderOpacity}" />
<Border BorderThickness="2"
BorderBrush="{StaticResource TransparentBlack}"
Background="{StaticResource TransparentBlack}"
@@ -26,5 +26,6 @@
</Grid>
</DockPanel>
</Border>
+ <Frame:Handle Style="{StaticResource ResizeHandle}" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>
</Window>
View
13 Thawmadoce/ShellViewModel.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Windows;
+using System.Windows;
using System.Windows.Input;
using Caliburn.Micro;
using MemBus;
@@ -19,8 +18,6 @@ public class ShellViewModel : Screen
private readonly IPublisher _publisher;
private readonly GestureService _gestureSvc = new GestureService();
- private const string Title = "The awesome markdown centrifuge";
-
public WindowHeaderViewModel WindowHeader { get; set; }
public MarkdownEditorViewModel Editor { get; set; }
public AppItemsViewModel AppItems { get; set; }
@@ -32,13 +29,6 @@ public ShellViewModel(IKeyboardOnlyActions[] keyboardOnlyActions, IPublisher pub
_publisher = publisher;
}
- public void Handle(NewDisplayNameUiMsg msg)
- {
- if (msg.IsTitleReset)
- DisplayName = "Thawmadoce";
- DisplayName = (msg.Append ? "Thawmadoce - " : "") + msg.NewTitle;
- //NotifyOfPropertyChange(()=>DisplayName);
- }
public IGestureService GestureService
{
@@ -49,7 +39,6 @@ public IGestureService GestureService
protected override void OnActivate()
{
this.ActivateAllChilds();
- DisplayName = Title;
}
protected override void OnViewAttached(object view, object context)
View
3  Thawmadoce/Thawmadoce.csproj
@@ -158,8 +158,10 @@
<Compile Include="Frame\Extensions\ObservableCollection.cs" />
<Compile Include="Frame\Extensions\Useful.cs" />
<Compile Include="Frame\Extensions\ViewModelExtensions.cs" />
+ <Compile Include="Frame\Extensions\WpfExtensions.cs" />
<Compile Include="Frame\FocusBehavior.cs" />
<Compile Include="Frame\GestureService.cs" />
+ <Compile Include="Frame\Handle.cs" />
<Compile Include="Frame\IUserInteraction.cs" />
<Compile Include="Frame\QuickGrid.cs" />
<Compile Include="Frame\IDispatchServices.cs" />
@@ -177,6 +179,7 @@
<Compile Include="Frame\StructuremapBridge.cs" />
<Compile Include="Frame\Messaging\ViewActivationPump.cs" />
<Compile Include="Frame\UserInteraction.cs" />
+ <Compile Include="Frame\WindowResizer.cs" />
<Compile Include="Frame\WpfDispatchService.cs" />
<Compile Include="Frame\XamlStatic.cs" />
<Compile Include="MainApp\ActivateExceptionAppDialog.cs" />
View
11 Thawmadoce/WindowHeaderView.xaml
@@ -3,10 +3,15 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- mc:Ignorable="d">
- <StackPanel Orientation="Horizontal">
+ mc:Ignorable="d" Margin="0,2,0,0">
+ <StackPanel Orientation="Horizontal" MouseLeftButtonDown="OnHeaderMouseDown">
<Image Source="/Media/window_left.png" Width="13" Height="25" />
- <StackPanel Orientation="Horizontal" MinWidth="200" Background="Black"></StackPanel>
+ <StackPanel Orientation="Horizontal" MinWidth="200" Background="Black">
+ <Button Style="{StaticResource NakedButton}" Click="HandleCloseClick">
+ <Image Source="/Media/dialog_close.png" Width="16" Height="16" />
+ </Button>
+ <TextBlock x:Name="Title" Foreground="White" Margin="5,2,0,0" />
+ </StackPanel>
<Image Source="/Media/window_right.png" Width="57" Height="25" />
</StackPanel>
</UserControl>
View
31 Thawmadoce/WindowHeaderView.xaml.cs
@@ -1,16 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
+using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using Thawmadoce.Frame.Extensions;
namespace Thawmadoce
{
@@ -23,5 +13,22 @@ public WindowHeaderView()
{
InitializeComponent();
}
+
+ private void HandleCloseClick(object sender, RoutedEventArgs e)
+ {
+ var b = sender as DependencyObject;
+ var wdw = b.GetVisualParent<Window>();
+
+ if (wdw != null)
+ wdw.Close();
+ }
+
+ private void OnHeaderMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ var b = sender as DependencyObject;
+ var w = b.GetVisualParent<Window>();
+ if (w != null)
+ w.DragMove();
+ }
}
}
View
23 Thawmadoce/WindowHeaderViewModel.cs
@@ -1,6 +1,25 @@
-namespace Thawmadoce
+using Caliburn.Micro;
+using Thawmadoce.MainApp;
+
+namespace Thawmadoce
{
- public class WindowHeaderViewModel
+ public class WindowHeaderViewModel : PropertyChangedBase
{
+ private const string title = "The awesome markdown centrifuge";
+
+ public WindowHeaderViewModel()
+ {
+ Title = title;
+ }
+
+ public void Handle(NewDisplayNameUiMsg msg)
+ {
+ if (msg.IsTitleReset)
+ Title = "Thawmadoce";
+ Title = (msg.Append ? "Thawmadoce - " : "") + msg.NewTitle;
+ NotifyOfPropertyChange(()=>Title);
+ }
+
+ public string Title { get; set; }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.