[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / View / ExtensionWindowResizeGrip.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.View
5 {
6     using System.ComponentModel;
7     using System.Diagnostics.CodeAnalysis;
8     using System.Runtime;
9     using System.Windows;
10     using System.Windows.Controls;
11     using System.Windows.Input;
12     using System.Windows.Media;
13
14     //This class is visual representation of ResizeGrip like control, which is used with ExtenstionWindows to allow
15     //resizing. Actual resize logic is handled by ExtensionSurface class
16     [TemplatePart(Name = "PART_ResizeGrip")]
17     class ExtensionWindowResizeGrip : Control
18     {
19         public static readonly DependencyProperty IconProperty =
20             DependencyProperty.Register("Icon", typeof(DrawingBrush), typeof(ExtensionWindowResizeGrip));
21
22         ExtensionWindow parent;
23         ExtensionSurface surface;
24         Point offset;
25
26         [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline,
27             Justification = "Overriding metadata for dependency properties in static constructor is the way suggested by WPF")]
28         static ExtensionWindowResizeGrip()
29         {
30             DefaultStyleKeyProperty.OverrideMetadata(
31                 typeof(ExtensionWindowResizeGrip),
32                 new FrameworkPropertyMetadata(typeof(ExtensionWindowResizeGrip)));            
33         }
34
35         public DrawingBrush Icon
36         {
37             get { return (DrawingBrush)GetValue(IconProperty); }
38             set { SetValue(IconProperty, value); }
39         }
40
41         protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
42         {
43             base.OnMouseLeftButtonDown(e);
44             if (this.parent.IsResizable)
45             {
46                 this.Cursor = Cursors.SizeNWSE;
47                 this.offset = e.GetPosition(this);
48                 CaptureMouse();
49             }
50         }
51
52         protected override void OnMouseMove(MouseEventArgs args)
53         {
54             base.OnMouseMove(args);
55             if (args.LeftButton == MouseButtonState.Pressed && this.IsMouseCaptured)
56             {
57                 Point currentPosition = Mouse.GetPosition(this.parent);
58                 currentPosition.Offset(this.offset.X, this.offset.Y);
59                 Size newSize = new Size();
60                 newSize.Width = Math.Min(Math.Max(this.parent.MinWidth, currentPosition.X), this.parent.MaxWidth);
61                 newSize.Height = Math.Min(Math.Max(this.parent.MinHeight, currentPosition.Y), this.parent.MaxHeight);
62                 System.Diagnostics.Debug.WriteLine("NewSize = (" + newSize.Width + "," + newSize.Height + ")");
63                 this.surface.SetSize(this.parent, newSize);
64             }
65         }
66
67         protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
68         {
69             base.OnMouseLeftButtonUp(e);
70             Mouse.OverrideCursor = null;
71             Mouse.Capture(null);
72         }
73
74         protected override void OnVisualParentChanged(DependencyObject oldParent)
75         {
76             base.OnVisualParentChanged(oldParent);
77             if (!DesignerProperties.GetIsInDesignMode(this) && 
78                 !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface))
79             {
80                 Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow");
81             }
82         }
83
84     }
85 }