forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResizer.cs
More file actions
231 lines (194 loc) · 7.77 KB
/
Copy pathResizer.cs
File metadata and controls
231 lines (194 loc) · 7.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//-----------------------------------------------------------------------
// <copyright file="Resizer.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Microsoft.Management.UI.Internal
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
/// <summary>
/// The resize grip possibilities.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
public enum ResizeGripLocation
{
/// <summary>
/// One grip is shown, on the right side.
/// </summary>
Right,
/// <summary>
/// One grip is shown, on the left side.
/// </summary>
Left,
}
/// <content>
/// Partial class implementation for Resizer control.
/// </content>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
public partial class Resizer : ContentControl
{
private AdornerLayer adornerLayer;
private UIElementAdorner adorner;
private ContentControl adornerContent;
/// <summary>
/// Creates an instance of Resizer.
/// </summary>
public Resizer()
{
// nothing
}
internal static Thickness CreateGripThickness(double visibleGripWidth, ResizeGripLocation gripLocation)
{
Thickness thickness;
if (visibleGripWidth < 0.0 || Double.IsNaN(visibleGripWidth))
{
throw new ArgumentOutOfRangeException("visibleGripWidth", "The value must be greater than or equal to 0." );
}
if (Double.IsInfinity(visibleGripWidth))
{
throw new ArgumentOutOfRangeException("visibleGripWidth", "The value must be less than infinity.");
}
switch (gripLocation)
{
case ResizeGripLocation.Right:
thickness = new Thickness(0, 0, visibleGripWidth, 0);
break;
case ResizeGripLocation.Left:
thickness = new Thickness(visibleGripWidth, 0, 0, 0);
break;
default:
throw new InvalidEnumArgumentException("gripLocation", (int) gripLocation, typeof(ResizeGripLocation));
}
return thickness;
}
partial void PreOnApplyTemplate()
{
if (this.rightGrip != null)
{
this.rightGrip.DragDelta -= this.OnRightGripDragDelta;
this.rightGrip.DragStarted -= this.OnRightGripDragStarted;
this.rightGrip.DragCompleted -= this.OnRightGripDragCompleted;
}
if (this.leftGrip != null)
{
this.leftGrip.DragDelta -= this.OnLeftGripDragDelta;
this.leftGrip.DragStarted -= this.OnLeftGripDragStarted;
this.leftGrip.DragCompleted -= this.OnLeftGripDragCompleted;
}
}
partial void PostOnApplyTemplate()
{
this.rightGrip.DragDelta += this.OnRightGripDragDelta;
this.rightGrip.DragStarted += this.OnRightGripDragStarted;
this.rightGrip.DragCompleted += this.OnRightGripDragCompleted;
this.leftGrip.DragDelta += this.OnLeftGripDragDelta;
this.leftGrip.DragStarted += this.OnLeftGripDragStarted;
this.leftGrip.DragCompleted += this.OnLeftGripDragCompleted;
}
private void CreateAdorner()
{
this.adornerLayer = AdornerLayer.GetAdornerLayer(this);
this.adorner = new UIElementAdorner(this);
this.adornerContent = new ContentControl();
this.adornerContent.Name = "ResizerAdornerContent";
this.adornerContent.HorizontalContentAlignment = HorizontalAlignment.Stretch;
this.adornerContent.VerticalContentAlignment = VerticalAlignment.Stretch;
this.adornerContent.ContentTemplate = this.DraggingTemplate;
this.adorner.Child = this.adornerContent;
}
private void RemoveAdorner()
{
this.adornerLayer.Remove(this.adorner);
}
private void OnLeftGripDragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
this.StopDragging(ResizeGripLocation.Left, e);
}
private void OnLeftGripDragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
{
this.StartDragging(ResizeGripLocation.Left);
}
private void OnLeftGripDragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
this.PerformDrag(ResizeGripLocation.Left, e);
}
private void OnRightGripDragCompleted(object sender, DragCompletedEventArgs e)
{
this.StopDragging(ResizeGripLocation.Right, e);
}
private void OnRightGripDragStarted(object sender, DragStartedEventArgs e)
{
this.StartDragging(ResizeGripLocation.Right);
}
private void OnRightGripDragDelta(object sender, DragDeltaEventArgs e)
{
this.PerformDrag(ResizeGripLocation.Right, e);
}
private void PerformDrag(ResizeGripLocation location, DragDeltaEventArgs e)
{
double newWidth = this.GetNewWidth(location, e.HorizontalChange);
if (this.ResizeWhileDragging)
{
this.Width = newWidth;
}
else
{
this.adorner.Width = newWidth;
}
}
private void StartDragging(ResizeGripLocation location)
{
if (false == this.ResizeWhileDragging)
{
if (this.adornerLayer == null)
{
this.CreateAdorner();
}
this.adornerContent.Content = location;
this.adornerLayer.Add(this.adorner);
this.adorner.Height = this.ActualHeight;
this.adorner.Width = this.ActualWidth;
}
}
private void StopDragging(ResizeGripLocation location, DragCompletedEventArgs e)
{
if (false == this.ResizeWhileDragging)
{
this.RemoveAdorner();
double newWidth = this.GetNewWidth(location, e.HorizontalChange);
this.Width = newWidth;
}
}
private double GetNewWidth(ResizeGripLocation location, double horzDelta)
{
var realDelta = this.GetHorizontalDelta(location, horzDelta);
double newWidth = this.ActualWidth + realDelta;
return this.GetConstrainedValue(newWidth, this.MaxWidth, this.MinWidth);
}
private double GetHorizontalDelta(ResizeGripLocation location, double horzDelta)
{
double realDelta;
if (location == ResizeGripLocation.Right)
{
realDelta = horzDelta;
}
else
{
Debug.Assert(location == ResizeGripLocation.Left);
realDelta = -horzDelta;
}
return realDelta;
}
private double GetConstrainedValue(double value, double max, double min)
{
return Math.Min(max, Math.Max(value, min));
}
}
}