Skip to content

Commit

Permalink
BugFix Candidate 2 for Issue #6 in LayoutFloatingWindowControl
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirkster99 committed Jul 26, 2018
1 parent edd6de6 commit 4ba3ca8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This program is provided to you under the terms of the Microsoft Public

namespace Xceed.Wpf.AvalonDock.Controls
{
public class LayoutDocumentTabItem : Control
public class LayoutDocumentTabItem : Control
{
#region Members
/// <summary>
Expand Down Expand Up @@ -285,7 +285,21 @@ private void StartDraggingFloatingWindowForContent()
( ( LayoutAnchorable )this.Model ).ResetCanCloseInternal();
}
var manager = this.Model.Root.Manager;
manager.StartDraggingFloatingWindowForContent( this.Model );

// Get psotion of this visual on screen
var pos = this.PointToScreen(new Point(0,0));

// Transform screen point to WPF device independent point
PresentationSource source = PresentationSource.FromVisual(this);
Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(pos);

// Log current delta between mouse and visual for use in drag cycle
var mousePosition = this.PointToScreenDPI(Mouse.GetPosition(this));

Point dragDelta = new Point(mousePosition.X - targetPoints.X,
mousePosition.Y - targetPoints.Y);

manager.StartDraggingFloatingWindowForContent( this.Model, true, dragDelta);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,23 @@ protected LayoutFloatingWindowControl( ILayoutElement model )
this.Loaded += new RoutedEventHandler( OnLoaded );
this.Unloaded += new RoutedEventHandler( OnUnloaded );
_model = model;

DragDelta = default(Point);
}

#endregion

#region Properties
/// <summary>
/// Gets/Sets the X,Y delta between the elemnt being dragged and the
/// mouse position. The value of this property is used during the drag
/// cycle to position the dragged item under the mouse pointer.
///
/// Set this property on intialization to ensure that
/// the delta between mouse and control being dragged
/// remains constant.
/// </summary>
internal Point DragDelta { get; set; }

#region Model

Expand Down Expand Up @@ -443,8 +455,12 @@ private void OnActivated( object sender, EventArgs e )

Logger.InfoFormat("1> Left {0:0.00} TOP {1:0.00}", Left, Top);

Left = (mousePosition.X - (windowArea.Width - clientArea.Width) / 2.0) - 3; // BugFix Issue #6
Top = (mousePosition.Y - ( windowArea.Height - clientArea.Height ) / 2.0) - 3;
// A second chance back up plan if DragDelta is not available
if (DragDelta == default(Point))
DragDelta = new Point(3,3);

Left = mousePosition.X - DragDelta.X; // BugFix Issue #6
Top = mousePosition.Y - DragDelta.Y;
_attachDrag = false;

Logger.InfoFormat("2> Left {0:0.00} TOP {1:0.00}", Left, Top);
Expand Down
12 changes: 8 additions & 4 deletions source/Components/Xceed.Wpf.AvalonDock/DockingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,9 @@ internal FrameworkElement GetAutoHideAreaElement()
return _autohideArea;
}

internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel, bool startDrag = true )
internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel,
bool startDrag = true,
Point dragDelta = default(Point))
{
if( !contentModel.CanFloat )
return;
Expand Down Expand Up @@ -2267,12 +2269,13 @@ internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel,
Layout.FloatingWindows.Add( fw );

fwc = new LayoutAnchorableFloatingWindowControl(
fw as LayoutAnchorableFloatingWindow )
fw as LayoutAnchorableFloatingWindow )
{
Width = fwWidth,
Height = fwHeight,
Left = contentModel.FloatingLeft,
Top = contentModel.FloatingTop
Top = contentModel.FloatingTop,
DragDelta = dragDelta // Setup initial tool window drag delta
};

Logger.InfoFormat("1> contentModel Left {0:0.00} TOP {1:0.00}",
Expand All @@ -2294,7 +2297,8 @@ internal void StartDraggingFloatingWindowForContent( LayoutContent contentModel,
Width = fwWidth,
Height = fwHeight,
Left = contentModel.FloatingLeft,
Top = contentModel.FloatingTop
Top = contentModel.FloatingTop,
DragDelta = dragDelta // Setup initial document window drag delta
};

Logger.InfoFormat("End> contentModel Left {0:0.00} TOP {1:0.00}",
Expand Down

0 comments on commit 4ba3ca8

Please sign in to comment.