File size: 32,215 Bytes
b1b3bae |
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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace WeifenLuo.WinFormsUI.Docking
{
partial class DockPanel
{
#region PaneIndicator
public interface IPaneIndicator : IHitTest
{
Point Location { get; set; }
bool Visible { get; set; }
int Left { get; }
int Top { get; }
int Right { get; }
int Bottom { get; }
Rectangle ClientRectangle { get; }
int Width { get; }
int Height { get; }
GraphicsPath DisplayingGraphicsPath { get; }
}
public struct HotSpotIndex
{
public HotSpotIndex(int x, int y, DockStyle dockStyle)
{
m_x = x;
m_y = y;
m_dockStyle = dockStyle;
}
private int m_x;
public int X
{
get { return m_x; }
}
private int m_y;
public int Y
{
get { return m_y; }
}
private DockStyle m_dockStyle;
public DockStyle DockStyle
{
get { return m_dockStyle; }
}
}
internal class DefaultPaneIndicator : PictureBox, IPaneIndicator
{
private static Bitmap _bitmapPaneDiamond = Resources.DockIndicator_PaneDiamond;
private static Bitmap _bitmapPaneDiamondLeft = Resources.DockIndicator_PaneDiamond_Left;
private static Bitmap _bitmapPaneDiamondRight = Resources.DockIndicator_PaneDiamond_Right;
private static Bitmap _bitmapPaneDiamondTop = Resources.DockIndicator_PaneDiamond_Top;
private static Bitmap _bitmapPaneDiamondBottom = Resources.DockIndicator_PaneDiamond_Bottom;
private static Bitmap _bitmapPaneDiamondFill = Resources.DockIndicator_PaneDiamond_Fill;
private static Bitmap _bitmapPaneDiamondHotSpot = Resources.DockIndicator_PaneDiamond_HotSpot;
private static Bitmap _bitmapPaneDiamondHotSpotIndex = Resources.DockIndicator_PaneDiamond_HotSpotIndex;
private static HotSpotIndex[] _hotSpots = new[]
{
new HotSpotIndex(1, 0, DockStyle.Top),
new HotSpotIndex(0, 1, DockStyle.Left),
new HotSpotIndex(1, 1, DockStyle.Fill),
new HotSpotIndex(2, 1, DockStyle.Right),
new HotSpotIndex(1, 2, DockStyle.Bottom)
};
private GraphicsPath _displayingGraphicsPath = DrawHelper.CalculateGraphicsPathFromBitmap(_bitmapPaneDiamond);
public DefaultPaneIndicator()
{
SizeMode = PictureBoxSizeMode.AutoSize;
Image = _bitmapPaneDiamond;
Region = new Region(DisplayingGraphicsPath);
}
public GraphicsPath DisplayingGraphicsPath
{
get { return _displayingGraphicsPath; }
}
public DockStyle HitTest(Point pt)
{
if (!Visible)
return DockStyle.None;
pt = PointToClient(pt);
if (!ClientRectangle.Contains(pt))
return DockStyle.None;
for (int i = _hotSpots.GetLowerBound(0); i <= _hotSpots.GetUpperBound(0); i++)
{
if (_bitmapPaneDiamondHotSpot.GetPixel(pt.X, pt.Y) == _bitmapPaneDiamondHotSpotIndex.GetPixel(_hotSpots[i].X, _hotSpots[i].Y))
return _hotSpots[i].DockStyle;
}
return DockStyle.None;
}
private DockStyle m_status = DockStyle.None;
public DockStyle Status
{
get { return m_status; }
set
{
m_status = value;
if (m_status == DockStyle.None)
Image = _bitmapPaneDiamond;
else if (m_status == DockStyle.Left)
Image = _bitmapPaneDiamondLeft;
else if (m_status == DockStyle.Right)
Image = _bitmapPaneDiamondRight;
else if (m_status == DockStyle.Top)
Image = _bitmapPaneDiamondTop;
else if (m_status == DockStyle.Bottom)
Image = _bitmapPaneDiamondBottom;
else if (m_status == DockStyle.Fill)
Image = _bitmapPaneDiamondFill;
}
}
}
#endregion PaneIndicator
#region IHitTest
public interface IHitTest
{
DockStyle HitTest(Point pt);
DockStyle Status { get; set; }
}
#endregion
#region PanelIndicator
public interface IPanelIndicator : IHitTest
{
Point Location { get; set; }
bool Visible { get; set; }
Rectangle Bounds { get; }
int Width { get; }
int Height { get; }
}
internal class DefaultPanelIndicator : PictureBox, IPanelIndicator
{
private static Image _imagePanelLeft = Resources.DockIndicator_PanelLeft;
private static Image _imagePanelRight = Resources.DockIndicator_PanelRight;
private static Image _imagePanelTop = Resources.DockIndicator_PanelTop;
private static Image _imagePanelBottom = Resources.DockIndicator_PanelBottom;
private static Image _imagePanelFill = Resources.DockIndicator_PanelFill;
private static Image _imagePanelLeftActive = Resources.DockIndicator_PanelLeft_Active;
private static Image _imagePanelRightActive = Resources.DockIndicator_PanelRight_Active;
private static Image _imagePanelTopActive = Resources.DockIndicator_PanelTop_Active;
private static Image _imagePanelBottomActive = Resources.DockIndicator_PanelBottom_Active;
private static Image _imagePanelFillActive = Resources.DockIndicator_PanelFill_Active;
public DefaultPanelIndicator(DockStyle dockStyle)
{
m_dockStyle = dockStyle;
SizeMode = PictureBoxSizeMode.AutoSize;
Image = ImageInactive;
}
private DockStyle m_dockStyle;
private DockStyle DockStyle
{
get { return m_dockStyle; }
}
private DockStyle m_status;
public DockStyle Status
{
get { return m_status; }
set
{
if (value != DockStyle && value != DockStyle.None)
throw new InvalidEnumArgumentException();
if (m_status == value)
return;
m_status = value;
IsActivated = (m_status != DockStyle.None);
}
}
private Image ImageInactive
{
get
{
if (DockStyle == DockStyle.Left)
return _imagePanelLeft;
else if (DockStyle == DockStyle.Right)
return _imagePanelRight;
else if (DockStyle == DockStyle.Top)
return _imagePanelTop;
else if (DockStyle == DockStyle.Bottom)
return _imagePanelBottom;
else if (DockStyle == DockStyle.Fill)
return _imagePanelFill;
else
return null;
}
}
private Image ImageActive
{
get
{
if (DockStyle == DockStyle.Left)
return _imagePanelLeftActive;
else if (DockStyle == DockStyle.Right)
return _imagePanelRightActive;
else if (DockStyle == DockStyle.Top)
return _imagePanelTopActive;
else if (DockStyle == DockStyle.Bottom)
return _imagePanelBottomActive;
else if (DockStyle == DockStyle.Fill)
return _imagePanelFillActive;
else
return null;
}
}
private bool m_isActivated = false;
private bool IsActivated
{
get { return m_isActivated; }
set
{
m_isActivated = value;
Image = IsActivated ? ImageActive : ImageInactive;
}
}
public DockStyle HitTest(Point pt)
{
return this.Visible && ClientRectangle.Contains(PointToClient(pt)) ? DockStyle : DockStyle.None;
}
}
#endregion PanelIndicator
internal class DefaultDockOutline : DockOutlineBase
{
public DefaultDockOutline()
{
m_dragForm = new DragForm();
SetDragForm(Rectangle.Empty);
DragForm.BackColor = SystemColors.ActiveCaption;
DragForm.Opacity = 0.5;
DragForm.Show(false);
}
DragForm m_dragForm;
private DragForm DragForm
{
get { return m_dragForm; }
}
protected override void OnShow()
{
CalculateRegion();
}
protected override void OnClose()
{
DragForm.Close();
}
private void CalculateRegion()
{
if (SameAsOldValue)
return;
if (!FloatWindowBounds.IsEmpty)
SetOutline(FloatWindowBounds);
else if (DockTo is DockPanel)
SetOutline(DockTo as DockPanel, Dock, (ContentIndex != 0));
else if (DockTo is DockPane)
SetOutline(DockTo as DockPane, Dock, ContentIndex);
else
SetOutline();
}
private void SetOutline()
{
SetDragForm(Rectangle.Empty);
}
private void SetOutline(Rectangle floatWindowBounds)
{
SetDragForm(floatWindowBounds);
}
private void SetOutline(DockPanel dockPanel, DockStyle dock, bool fullPanelEdge)
{
Rectangle rect = fullPanelEdge ? dockPanel.DockArea : dockPanel.DocumentWindowBounds;
rect.Location = dockPanel.PointToScreen(rect.Location);
if (dock == DockStyle.Top)
{
int height = dockPanel.GetDockWindowSize(DockState.DockTop);
rect = new Rectangle(rect.X, rect.Y, rect.Width, height);
}
else if (dock == DockStyle.Bottom)
{
int height = dockPanel.GetDockWindowSize(DockState.DockBottom);
rect = new Rectangle(rect.X, rect.Bottom - height, rect.Width, height);
}
else if (dock == DockStyle.Left)
{
int width = dockPanel.GetDockWindowSize(DockState.DockLeft);
rect = new Rectangle(rect.X, rect.Y, width, rect.Height);
}
else if (dock == DockStyle.Right)
{
int width = dockPanel.GetDockWindowSize(DockState.DockRight);
rect = new Rectangle(rect.Right - width, rect.Y, width, rect.Height);
}
else if (dock == DockStyle.Fill)
{
rect = dockPanel.DocumentWindowBounds;
rect.Location = dockPanel.PointToScreen(rect.Location);
}
SetDragForm(rect);
}
private void SetOutline(DockPane pane, DockStyle dock, int contentIndex)
{
if (dock != DockStyle.Fill)
{
Rectangle rect = pane.DisplayingRectangle;
if (dock == DockStyle.Right)
rect.X += rect.Width / 2;
if (dock == DockStyle.Bottom)
rect.Y += rect.Height / 2;
if (dock == DockStyle.Left || dock == DockStyle.Right)
rect.Width -= rect.Width / 2;
if (dock == DockStyle.Top || dock == DockStyle.Bottom)
rect.Height -= rect.Height / 2;
rect.Location = pane.PointToScreen(rect.Location);
SetDragForm(rect);
}
else if (contentIndex == -1)
{
Rectangle rect = pane.DisplayingRectangle;
rect.Location = pane.PointToScreen(rect.Location);
SetDragForm(rect);
}
else
{
using (GraphicsPath path = pane.TabStripControl.GetOutline(contentIndex))
{
RectangleF rectF = path.GetBounds();
Rectangle rect = new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height);
using (Matrix matrix = new Matrix(rect, new Point[] { new Point(0, 0), new Point(rect.Width, 0), new Point(0, rect.Height) }))
{
path.Transform(matrix);
}
Region region = new Region(path);
SetDragForm(rect, region);
}
}
}
private void SetDragForm(Rectangle rect)
{
DragForm.Bounds = rect;
if (rect == Rectangle.Empty)
{
if (DragForm.Region != null)
{
DragForm.Region.Dispose();
}
DragForm.Region = new Region(Rectangle.Empty);
}
else if (DragForm.Region != null)
{
DragForm.Region.Dispose();
DragForm.Region = null;
}
}
private void SetDragForm(Rectangle rect, Region region)
{
DragForm.Bounds = rect;
DragForm.Region = region;
}
}
private sealed class DockDragHandler : DragHandler
{
public class DockIndicator : DragForm
{
#region consts
private int _PanelIndicatorMargin = 10;
#endregion
private DockDragHandler m_dragHandler;
public DockIndicator(DockDragHandler dragHandler)
{
m_dragHandler = dragHandler;
Controls.AddRange(new[] {
(Control)PaneDiamond,
(Control)PanelLeft,
(Control)PanelRight,
(Control)PanelTop,
(Control)PanelBottom,
(Control)PanelFill
});
Region = new Region(Rectangle.Empty);
}
private IPaneIndicator m_paneDiamond = null;
private IPaneIndicator PaneDiamond
{
get
{
if (m_paneDiamond == null)
m_paneDiamond = m_dragHandler.DockPanel.Extender.PaneIndicatorFactory.CreatePaneIndicator();
return m_paneDiamond;
}
}
private IPanelIndicator m_panelLeft = null;
private IPanelIndicator PanelLeft
{
get
{
if (m_panelLeft == null)
m_panelLeft = m_dragHandler.DockPanel.Extender.PanelIndicatorFactory.CreatePanelIndicator(DockStyle.Left);
return m_panelLeft;
}
}
private IPanelIndicator m_panelRight = null;
private IPanelIndicator PanelRight
{
get
{
if (m_panelRight == null)
m_panelRight = m_dragHandler.DockPanel.Extender.PanelIndicatorFactory.CreatePanelIndicator(DockStyle.Right);
return m_panelRight;
}
}
private IPanelIndicator m_panelTop = null;
private IPanelIndicator PanelTop
{
get
{
if (m_panelTop == null)
m_panelTop = m_dragHandler.DockPanel.Extender.PanelIndicatorFactory.CreatePanelIndicator(DockStyle.Top);
return m_panelTop;
}
}
private IPanelIndicator m_panelBottom = null;
private IPanelIndicator PanelBottom
{
get
{
if (m_panelBottom == null)
m_panelBottom = m_dragHandler.DockPanel.Extender.PanelIndicatorFactory.CreatePanelIndicator(DockStyle.Bottom);
return m_panelBottom;
}
}
private IPanelIndicator m_panelFill = null;
private IPanelIndicator PanelFill
{
get
{
if (m_panelFill == null)
m_panelFill = m_dragHandler.DockPanel.Extender.PanelIndicatorFactory.CreatePanelIndicator(DockStyle.Fill);
return m_panelFill;
}
}
private bool m_fullPanelEdge = false;
public bool FullPanelEdge
{
get { return m_fullPanelEdge; }
set
{
if (m_fullPanelEdge == value)
return;
m_fullPanelEdge = value;
RefreshChanges();
}
}
public DockDragHandler DragHandler
{
get { return m_dragHandler; }
}
public DockPanel DockPanel
{
get { return DragHandler.DockPanel; }
}
private DockPane m_dockPane = null;
public DockPane DockPane
{
get { return m_dockPane; }
internal set
{
if (m_dockPane == value)
return;
DockPane oldDisplayingPane = DisplayingPane;
m_dockPane = value;
if (oldDisplayingPane != DisplayingPane)
RefreshChanges();
}
}
private IHitTest m_hitTest = null;
private IHitTest HitTestResult
{
get { return m_hitTest; }
set
{
if (m_hitTest == value)
return;
if (m_hitTest != null)
m_hitTest.Status = DockStyle.None;
m_hitTest = value;
}
}
private DockPane DisplayingPane
{
get { return ShouldPaneDiamondVisible() ? DockPane : null; }
}
private void RefreshChanges()
{
Region region = new Region(Rectangle.Empty);
Rectangle rectDockArea = FullPanelEdge ? DockPanel.DockArea : DockPanel.DocumentWindowBounds;
rectDockArea = RectangleToClient(DockPanel.RectangleToScreen(rectDockArea));
if (ShouldPanelIndicatorVisible(DockState.DockLeft))
{
PanelLeft.Location = new Point(rectDockArea.X + _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
PanelLeft.Visible = true;
region.Union(PanelLeft.Bounds);
}
else
PanelLeft.Visible = false;
if (ShouldPanelIndicatorVisible(DockState.DockRight))
{
PanelRight.Location = new Point(rectDockArea.X + rectDockArea.Width - PanelRight.Width - _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
PanelRight.Visible = true;
region.Union(PanelRight.Bounds);
}
else
PanelRight.Visible = false;
if (ShouldPanelIndicatorVisible(DockState.DockTop))
{
PanelTop.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelTop.Width) / 2, rectDockArea.Y + _PanelIndicatorMargin);
PanelTop.Visible = true;
region.Union(PanelTop.Bounds);
}
else
PanelTop.Visible = false;
if (ShouldPanelIndicatorVisible(DockState.DockBottom))
{
PanelBottom.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelBottom.Width) / 2, rectDockArea.Y + rectDockArea.Height - PanelBottom.Height - _PanelIndicatorMargin);
PanelBottom.Visible = true;
region.Union(PanelBottom.Bounds);
}
else
PanelBottom.Visible = false;
if (ShouldPanelIndicatorVisible(DockState.Document))
{
Rectangle rectDocumentWindow = RectangleToClient(DockPanel.RectangleToScreen(DockPanel.DocumentWindowBounds));
PanelFill.Location = new Point(rectDocumentWindow.X + (rectDocumentWindow.Width - PanelFill.Width) / 2, rectDocumentWindow.Y + (rectDocumentWindow.Height - PanelFill.Height) / 2);
PanelFill.Visible = true;
region.Union(PanelFill.Bounds);
}
else
PanelFill.Visible = false;
if (ShouldPaneDiamondVisible())
{
Rectangle rect = RectangleToClient(DockPane.RectangleToScreen(DockPane.ClientRectangle));
PaneDiamond.Location = new Point(rect.Left + (rect.Width - PaneDiamond.Width)/2, rect.Top + (rect.Height - PaneDiamond.Height)/2);
PaneDiamond.Visible = true;
using (GraphicsPath graphicsPath = PaneDiamond.DisplayingGraphicsPath.Clone() as GraphicsPath)
{
Point[] pts = new Point[]
{
new Point(PaneDiamond.Left, PaneDiamond.Top),
new Point(PaneDiamond.Right, PaneDiamond.Top),
new Point(PaneDiamond.Left, PaneDiamond.Bottom)
};
using (Matrix matrix = new Matrix(PaneDiamond.ClientRectangle, pts))
{
graphicsPath.Transform(matrix);
}
region.Union(graphicsPath);
}
}
else
PaneDiamond.Visible = false;
Region = region;
}
private bool ShouldPanelIndicatorVisible(DockState dockState)
{
if (!Visible)
return false;
if (DockPanel.DockWindows[dockState].Visible)
return false;
return DragHandler.DragSource.IsDockStateValid(dockState);
}
private bool ShouldPaneDiamondVisible()
{
if (DockPane == null)
return false;
if (!DockPanel.AllowEndUserNestedDocking)
return false;
return DragHandler.DragSource.CanDockTo(DockPane);
}
public override void Show(bool bActivate)
{
base.Show(bActivate);
Bounds = SystemInformation.VirtualScreen;
RefreshChanges();
}
public void TestDrop()
{
Point pt = Control.MousePosition;
DockPane = DockHelper.PaneAtPoint(pt, DockPanel);
if (TestDrop(PanelLeft, pt) != DockStyle.None)
HitTestResult = PanelLeft;
else if (TestDrop(PanelRight, pt) != DockStyle.None)
HitTestResult = PanelRight;
else if (TestDrop(PanelTop, pt) != DockStyle.None)
HitTestResult = PanelTop;
else if (TestDrop(PanelBottom, pt) != DockStyle.None)
HitTestResult = PanelBottom;
else if (TestDrop(PanelFill, pt) != DockStyle.None)
HitTestResult = PanelFill;
else if (TestDrop(PaneDiamond, pt) != DockStyle.None)
HitTestResult = PaneDiamond;
else
HitTestResult = null;
if (HitTestResult != null)
{
if (HitTestResult is IPaneIndicator)
DragHandler.Outline.Show(DockPane, HitTestResult.Status);
else
DragHandler.Outline.Show(DockPanel, HitTestResult.Status, FullPanelEdge);
}
}
private static DockStyle TestDrop(IHitTest hitTest, Point pt)
{
return hitTest.Status = hitTest.HitTest(pt);
}
}
public DockDragHandler(DockPanel panel)
: base(panel)
{
}
public new IDockDragSource DragSource
{
get { return base.DragSource as IDockDragSource; }
set { base.DragSource = value; }
}
private DockOutlineBase m_outline;
public DockOutlineBase Outline
{
get { return m_outline; }
private set { m_outline = value; }
}
private DockIndicator m_indicator;
private DockIndicator Indicator
{
get { return m_indicator; }
set { m_indicator = value; }
}
private Rectangle m_floatOutlineBounds;
private Rectangle FloatOutlineBounds
{
get { return m_floatOutlineBounds; }
set { m_floatOutlineBounds = value; }
}
public void BeginDrag(IDockDragSource dragSource)
{
DragSource = dragSource;
if (!BeginDrag())
{
DragSource = null;
return;
}
Outline = DockPanel.Extender.DockOutlineFactory.CreateDockOutline();
Indicator = new DockIndicator(this);
Indicator.Show(false);
FloatOutlineBounds = DragSource.BeginDrag(StartMousePosition);
}
protected override void OnDragging()
{
TestDrop();
}
protected override void OnEndDrag(bool abort)
{
DockPanel.SuspendLayout(true);
Outline.Close();
Indicator.Close();
EndDrag(abort);
// Queue a request to layout all children controls
DockPanel.PerformMdiClientLayout();
DockPanel.ResumeLayout(true, true);
DragSource.EndDrag();
DragSource = null;
}
private void TestDrop()
{
Outline.FlagTestDrop = false;
Indicator.FullPanelEdge = ((Control.ModifierKeys & Keys.Shift) != 0);
if ((Control.ModifierKeys & Keys.Control) == 0)
{
Indicator.TestDrop();
if (!Outline.FlagTestDrop)
{
DockPane pane = DockHelper.PaneAtPoint(Control.MousePosition, DockPanel);
if (pane != null && DragSource.IsDockStateValid(pane.DockState))
pane.TestDrop(DragSource, Outline);
}
if (!Outline.FlagTestDrop && DragSource.IsDockStateValid(DockState.Float))
{
FloatWindow floatWindow = DockHelper.FloatWindowAtPoint(Control.MousePosition, DockPanel);
if (floatWindow != null)
floatWindow.TestDrop(DragSource, Outline);
}
}
else
Indicator.DockPane = DockHelper.PaneAtPoint(Control.MousePosition, DockPanel);
if (!Outline.FlagTestDrop)
{
if (DragSource.IsDockStateValid(DockState.Float))
{
Rectangle rect = FloatOutlineBounds;
rect.Offset(Control.MousePosition.X - StartMousePosition.X, Control.MousePosition.Y - StartMousePosition.Y);
Outline.Show(rect);
}
}
if (!Outline.FlagTestDrop)
{
Cursor.Current = Cursors.No;
Outline.Show();
}
else
Cursor.Current = DragControl.Cursor;
}
private void EndDrag(bool abort)
{
if (abort)
return;
if (!Outline.FloatWindowBounds.IsEmpty)
DragSource.FloatAt(Outline.FloatWindowBounds);
else if (Outline.DockTo is DockPane)
{
DockPane pane = Outline.DockTo as DockPane;
DragSource.DockTo(pane, Outline.Dock, Outline.ContentIndex);
}
else if (Outline.DockTo is DockPanel)
{
DockPanel panel = Outline.DockTo as DockPanel;
panel.UpdateDockWindowZOrder(Outline.Dock, Outline.FlagFullEdge);
DragSource.DockTo(panel, Outline.Dock);
}
}
}
private DockDragHandler m_dockDragHandler = null;
private DockDragHandler GetDockDragHandler()
{
if (m_dockDragHandler == null)
m_dockDragHandler = new DockDragHandler(this);
return m_dockDragHandler;
}
internal void BeginDrag(IDockDragSource dragSource)
{
GetDockDragHandler().BeginDrag(dragSource);
}
}
}
|