blob: 9676decafcd9f634d8e6edf554dcda9439aa8c9c (
plain)
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
|
/*************************************************************************************
Extended WPF Toolkit
Copyright (C) 2007-2013 Xceed Software Inc.
This program is provided to you under the terms of the Microsoft Public
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
For more features, controls, and fast professional support,
pick up the Plus Edition at http://xceed.com/wpf_toolkit
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
***********************************************************************************/
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Xceed.Wpf.AvalonDock.Layout;
namespace Xceed.Wpf.AvalonDock.Controls
{
internal class DragService
{
#region Members
private DockingManager _manager;
private LayoutFloatingWindowControl _floatingWindow;
private List<IOverlayWindowHost> _overlayWindowHosts = new List<IOverlayWindowHost>();
private IOverlayWindowHost _currentHost;
private IOverlayWindow _currentWindow;
private List<IDropArea> _currentWindowAreas = new List<IDropArea>();
private IDropTarget _currentDropTarget;
#endregion
#region Public Methods
public DragService( LayoutFloatingWindowControl floatingWindow )
{
_floatingWindow = floatingWindow;
_manager = floatingWindow.Model.Root.Manager;
GetOverlayWindowHosts();
}
public void UpdateMouseLocation( Point dragPosition )
{
var floatingWindowModel = _floatingWindow.Model as LayoutFloatingWindow;
var newHost = _overlayWindowHosts.FirstOrDefault( oh => oh.HitTest( dragPosition ) );
if( _currentHost != null || _currentHost != newHost )
{
//is mouse still inside current overlay window host?
if( ( _currentHost != null && !_currentHost.HitTest( dragPosition ) ) ||
_currentHost != newHost )
{
//esit drop target
if( _currentDropTarget != null )
_currentWindow.DragLeave( _currentDropTarget );
_currentDropTarget = null;
//exit area
_currentWindowAreas.ForEach( a =>
_currentWindow.DragLeave( a ) );
_currentWindowAreas.Clear();
//hide current overlay window
if( _currentWindow != null )
_currentWindow.DragLeave( _floatingWindow );
if( _currentHost != null )
_currentHost.HideOverlayWindow();
_currentHost = null;
}
if( _currentHost != newHost )
{
_currentHost = newHost;
_currentWindow = _currentHost.ShowOverlayWindow( _floatingWindow );
_currentWindow.DragEnter( _floatingWindow );
}
}
if( _currentHost == null )
return;
if( _currentDropTarget != null &&
!_currentDropTarget.HitTest( dragPosition ) )
{
_currentWindow.DragLeave( _currentDropTarget );
_currentDropTarget = null;
}
List<IDropArea> areasToRemove = new List<IDropArea>();
_currentWindowAreas.ForEach( a =>
{
//is mouse still inside this area?
if( !a.DetectionRect.Contains( dragPosition ) )
{
_currentWindow.DragLeave( a );
areasToRemove.Add( a );
}
} );
areasToRemove.ForEach( a =>
_currentWindowAreas.Remove( a ) );
var areasToAdd =
_currentHost.GetDropAreas( _floatingWindow ).Where( cw => !_currentWindowAreas.Contains( cw ) && cw.DetectionRect.Contains( dragPosition ) ).ToList();
_currentWindowAreas.AddRange( areasToAdd );
areasToAdd.ForEach( a =>
_currentWindow.DragEnter( a ) );
if( _currentDropTarget == null )
{
_currentWindowAreas.ForEach( wa =>
{
if( _currentDropTarget != null )
return;
_currentDropTarget = _currentWindow.GetTargets().FirstOrDefault( dt => dt.HitTest( dragPosition ) );
if( _currentDropTarget != null )
{
_currentWindow.DragEnter( _currentDropTarget );
return;
}
} );
}
}
public void Drop( Point dropLocation, out bool dropHandled )
{
dropHandled = false;
UpdateMouseLocation( dropLocation );
var floatingWindowModel = _floatingWindow.Model as LayoutFloatingWindow;
var root = floatingWindowModel.Root;
if( _currentHost != null )
_currentHost.HideOverlayWindow();
if( _currentDropTarget != null )
{
_currentWindow.DragDrop( _currentDropTarget );
root.CollectGarbage();
dropHandled = true;
}
_currentWindowAreas.ForEach( a => _currentWindow.DragLeave( a ) );
if( _currentDropTarget != null )
_currentWindow.DragLeave( _currentDropTarget );
if( _currentWindow != null )
_currentWindow.DragLeave( _floatingWindow );
_currentWindow = null;
_currentHost = null;
}
#endregion
#region Internal Methods
internal void Abort()
{
var floatingWindowModel = _floatingWindow.Model as LayoutFloatingWindow;
_currentWindowAreas.ForEach( a => _currentWindow.DragLeave( a ) );
if( _currentDropTarget != null )
_currentWindow.DragLeave( _currentDropTarget );
if( _currentWindow != null )
_currentWindow.DragLeave( _floatingWindow );
_currentWindow = null;
if( _currentHost != null )
_currentHost.HideOverlayWindow();
_currentHost = null;
}
#endregion
#region Private Methods
private void GetOverlayWindowHosts()
{
_overlayWindowHosts.AddRange( _manager.GetFloatingWindowsByZOrder().OfType<LayoutAnchorableFloatingWindowControl>().Where( fw => fw != _floatingWindow && fw.IsVisible ) );
_overlayWindowHosts.Add( _manager );
}
#endregion
}
}
|