DockPanel.DockDragHandler.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:DockPanel.cs
  5. * 2.功能描述:类文件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/01 1.00 新建
  9. *******************************************************************************/
  10. using System.ComponentModel;
  11. using System.Drawing;
  12. using System.Drawing.Drawing2D;
  13. using System.Windows.Forms;
  14. namespace Dongke.IBOSS.PRD.Basics.DockPanel
  15. {
  16. /// <summary>
  17. /// 类文件
  18. /// </summary>
  19. partial class DockPanel
  20. {
  21. private sealed class DockDragHandler : DragHandler
  22. {
  23. private class DockIndicator : DragForm
  24. {
  25. #region IHitTest
  26. private interface IHitTest
  27. {
  28. DockStyle HitTest(Point pt);
  29. DockStyle Status
  30. {
  31. get;
  32. set;
  33. }
  34. }
  35. #endregion
  36. #region PanelIndicator
  37. private class PanelIndicator : PictureBox, IHitTest
  38. {
  39. private static Image _imagePanelLeft = Resources.DockIndicator_PanelLeft;
  40. private static Image _imagePanelRight = Resources.DockIndicator_PanelRight;
  41. private static Image _imagePanelTop = Resources.DockIndicator_PanelTop;
  42. private static Image _imagePanelBottom = Resources.DockIndicator_PanelBottom;
  43. private static Image _imagePanelFill = Resources.DockIndicator_PanelFill;
  44. private static Image _imagePanelLeftActive = Resources.DockIndicator_PanelLeft_Active;
  45. private static Image _imagePanelRightActive = Resources.DockIndicator_PanelRight_Active;
  46. private static Image _imagePanelTopActive = Resources.DockIndicator_PanelTop_Active;
  47. private static Image _imagePanelBottomActive = Resources.DockIndicator_PanelBottom_Active;
  48. private static Image _imagePanelFillActive = Resources.DockIndicator_PanelFill_Active;
  49. public PanelIndicator(DockStyle dockStyle)
  50. {
  51. m_dockStyle = dockStyle;
  52. SizeMode = PictureBoxSizeMode.AutoSize;
  53. Image = ImageInactive;
  54. }
  55. private DockStyle m_dockStyle;
  56. private DockStyle DockStyle
  57. {
  58. get
  59. {
  60. return m_dockStyle;
  61. }
  62. }
  63. private DockStyle m_status;
  64. public DockStyle Status
  65. {
  66. get
  67. {
  68. return m_status;
  69. }
  70. set
  71. {
  72. if (value != DockStyle && value != DockStyle.None)
  73. throw new InvalidEnumArgumentException();
  74. if (m_status == value)
  75. return;
  76. m_status = value;
  77. IsActivated = (m_status != DockStyle.None);
  78. }
  79. }
  80. private Image ImageInactive
  81. {
  82. get
  83. {
  84. if (DockStyle == DockStyle.Left)
  85. return _imagePanelLeft;
  86. else if (DockStyle == DockStyle.Right)
  87. return _imagePanelRight;
  88. else if (DockStyle == DockStyle.Top)
  89. return _imagePanelTop;
  90. else if (DockStyle == DockStyle.Bottom)
  91. return _imagePanelBottom;
  92. else if (DockStyle == DockStyle.Fill)
  93. return _imagePanelFill;
  94. else
  95. return null;
  96. }
  97. }
  98. private Image ImageActive
  99. {
  100. get
  101. {
  102. if (DockStyle == DockStyle.Left)
  103. return _imagePanelLeftActive;
  104. else if (DockStyle == DockStyle.Right)
  105. return _imagePanelRightActive;
  106. else if (DockStyle == DockStyle.Top)
  107. return _imagePanelTopActive;
  108. else if (DockStyle == DockStyle.Bottom)
  109. return _imagePanelBottomActive;
  110. else if (DockStyle == DockStyle.Fill)
  111. return _imagePanelFillActive;
  112. else
  113. return null;
  114. }
  115. }
  116. private bool m_isActivated = false;
  117. private bool IsActivated
  118. {
  119. get
  120. {
  121. return m_isActivated;
  122. }
  123. set
  124. {
  125. m_isActivated = value;
  126. Image = IsActivated ? ImageActive : ImageInactive;
  127. }
  128. }
  129. public DockStyle HitTest(Point pt)
  130. {
  131. return this.Visible && ClientRectangle.Contains(PointToClient(pt)) ? DockStyle : DockStyle.None;
  132. }
  133. }
  134. #endregion PanelIndicator
  135. #region PaneIndicator
  136. private class PaneIndicator : PictureBox, IHitTest
  137. {
  138. private struct HotSpotIndex
  139. {
  140. public HotSpotIndex(int x, int y, DockStyle dockStyle)
  141. {
  142. m_x = x;
  143. m_y = y;
  144. m_dockStyle = dockStyle;
  145. }
  146. private int m_x;
  147. public int X
  148. {
  149. get
  150. {
  151. return m_x;
  152. }
  153. }
  154. private int m_y;
  155. public int Y
  156. {
  157. get
  158. {
  159. return m_y;
  160. }
  161. }
  162. private DockStyle m_dockStyle;
  163. public DockStyle DockStyle
  164. {
  165. get
  166. {
  167. return m_dockStyle;
  168. }
  169. }
  170. }
  171. private static Bitmap _bitmapPaneDiamond = Resources.DockIndicator_PaneDiamond;
  172. private static Bitmap _bitmapPaneDiamondLeft = Resources.DockIndicator_PaneDiamond_Left;
  173. private static Bitmap _bitmapPaneDiamondRight = Resources.DockIndicator_PaneDiamond_Right;
  174. private static Bitmap _bitmapPaneDiamondTop = Resources.DockIndicator_PaneDiamond_Top;
  175. private static Bitmap _bitmapPaneDiamondBottom = Resources.DockIndicator_PaneDiamond_Bottom;
  176. private static Bitmap _bitmapPaneDiamondFill = Resources.DockIndicator_PaneDiamond_Fill;
  177. private static Bitmap _bitmapPaneDiamondHotSpot = Resources.DockIndicator_PaneDiamond_HotSpot;
  178. private static Bitmap _bitmapPaneDiamondHotSpotIndex = Resources.DockIndicator_PaneDiamond_HotSpotIndex;
  179. private static HotSpotIndex[] _hotSpots = new HotSpotIndex[]
  180. {
  181. new HotSpotIndex(1, 0, DockStyle.Top),
  182. new HotSpotIndex(0, 1, DockStyle.Left),
  183. new HotSpotIndex(1, 1, DockStyle.Fill),
  184. new HotSpotIndex(2, 1, DockStyle.Right),
  185. new HotSpotIndex(1, 2, DockStyle.Bottom)
  186. };
  187. private static GraphicsPath _displayingGraphicsPath = DrawHelper.CalculateGraphicsPathFromBitmap(_bitmapPaneDiamond);
  188. public PaneIndicator()
  189. {
  190. SizeMode = PictureBoxSizeMode.AutoSize;
  191. Image = _bitmapPaneDiamond;
  192. Region = new Region(DisplayingGraphicsPath);
  193. }
  194. public static GraphicsPath DisplayingGraphicsPath
  195. {
  196. get
  197. {
  198. return _displayingGraphicsPath;
  199. }
  200. }
  201. public DockStyle HitTest(Point pt)
  202. {
  203. if (!Visible)
  204. return DockStyle.None;
  205. pt = PointToClient(pt);
  206. if (!ClientRectangle.Contains(pt))
  207. return DockStyle.None;
  208. for (int i = _hotSpots.GetLowerBound(0); i <= _hotSpots.GetUpperBound(0); i++)
  209. {
  210. if (_bitmapPaneDiamondHotSpot.GetPixel(pt.X, pt.Y) == _bitmapPaneDiamondHotSpotIndex.GetPixel(_hotSpots[i].X, _hotSpots[i].Y))
  211. return _hotSpots[i].DockStyle;
  212. }
  213. return DockStyle.None;
  214. }
  215. private DockStyle m_status = DockStyle.None;
  216. public DockStyle Status
  217. {
  218. get
  219. {
  220. return m_status;
  221. }
  222. set
  223. {
  224. m_status = value;
  225. if (m_status == DockStyle.None)
  226. Image = _bitmapPaneDiamond;
  227. else if (m_status == DockStyle.Left)
  228. Image = _bitmapPaneDiamondLeft;
  229. else if (m_status == DockStyle.Right)
  230. Image = _bitmapPaneDiamondRight;
  231. else if (m_status == DockStyle.Top)
  232. Image = _bitmapPaneDiamondTop;
  233. else if (m_status == DockStyle.Bottom)
  234. Image = _bitmapPaneDiamondBottom;
  235. else if (m_status == DockStyle.Fill)
  236. Image = _bitmapPaneDiamondFill;
  237. }
  238. }
  239. }
  240. #endregion PaneIndicator
  241. #region consts
  242. private int _PanelIndicatorMargin = 10;
  243. #endregion
  244. private DockDragHandler m_dragHandler;
  245. public DockIndicator(DockDragHandler dragHandler)
  246. {
  247. m_dragHandler = dragHandler;
  248. Controls.AddRange(new Control[] {
  249. PaneDiamond,
  250. PanelLeft,
  251. PanelRight,
  252. PanelTop,
  253. PanelBottom,
  254. PanelFill
  255. });
  256. Region = new Region(Rectangle.Empty);
  257. }
  258. private PaneIndicator m_paneDiamond = null;
  259. private PaneIndicator PaneDiamond
  260. {
  261. get
  262. {
  263. if (m_paneDiamond == null)
  264. m_paneDiamond = new PaneIndicator();
  265. return m_paneDiamond;
  266. }
  267. }
  268. private PanelIndicator m_panelLeft = null;
  269. private PanelIndicator PanelLeft
  270. {
  271. get
  272. {
  273. if (m_panelLeft == null)
  274. m_panelLeft = new PanelIndicator(DockStyle.Left);
  275. return m_panelLeft;
  276. }
  277. }
  278. private PanelIndicator m_panelRight = null;
  279. private PanelIndicator PanelRight
  280. {
  281. get
  282. {
  283. if (m_panelRight == null)
  284. m_panelRight = new PanelIndicator(DockStyle.Right);
  285. return m_panelRight;
  286. }
  287. }
  288. private PanelIndicator m_panelTop = null;
  289. private PanelIndicator PanelTop
  290. {
  291. get
  292. {
  293. if (m_panelTop == null)
  294. m_panelTop = new PanelIndicator(DockStyle.Top);
  295. return m_panelTop;
  296. }
  297. }
  298. private PanelIndicator m_panelBottom = null;
  299. private PanelIndicator PanelBottom
  300. {
  301. get
  302. {
  303. if (m_panelBottom == null)
  304. m_panelBottom = new PanelIndicator(DockStyle.Bottom);
  305. return m_panelBottom;
  306. }
  307. }
  308. private PanelIndicator m_panelFill = null;
  309. private PanelIndicator PanelFill
  310. {
  311. get
  312. {
  313. if (m_panelFill == null)
  314. m_panelFill = new PanelIndicator(DockStyle.Fill);
  315. return m_panelFill;
  316. }
  317. }
  318. private bool m_fullPanelEdge = false;
  319. public bool FullPanelEdge
  320. {
  321. get
  322. {
  323. return m_fullPanelEdge;
  324. }
  325. set
  326. {
  327. if (m_fullPanelEdge == value)
  328. return;
  329. m_fullPanelEdge = value;
  330. RefreshChanges();
  331. }
  332. }
  333. public DockDragHandler DragHandler
  334. {
  335. get
  336. {
  337. return m_dragHandler;
  338. }
  339. }
  340. public DockPanel DockPanel
  341. {
  342. get
  343. {
  344. return DragHandler.DockPanel;
  345. }
  346. }
  347. private DockPane m_dockPane = null;
  348. public DockPane DockPane
  349. {
  350. get
  351. {
  352. return m_dockPane;
  353. }
  354. internal set
  355. {
  356. if (m_dockPane == value)
  357. return;
  358. DockPane oldDisplayingPane = DisplayingPane;
  359. m_dockPane = value;
  360. if (oldDisplayingPane != DisplayingPane)
  361. RefreshChanges();
  362. }
  363. }
  364. private IHitTest m_hitTest = null;
  365. private IHitTest HitTestResult
  366. {
  367. get
  368. {
  369. return m_hitTest;
  370. }
  371. set
  372. {
  373. if (m_hitTest == value)
  374. return;
  375. if (m_hitTest != null)
  376. m_hitTest.Status = DockStyle.None;
  377. m_hitTest = value;
  378. }
  379. }
  380. private DockPane DisplayingPane
  381. {
  382. get
  383. {
  384. return ShouldPaneDiamondVisible() ? DockPane : null;
  385. }
  386. }
  387. private void RefreshChanges()
  388. {
  389. Region region = new Region(Rectangle.Empty);
  390. Rectangle rectDockArea = FullPanelEdge ? DockPanel.DockArea : DockPanel.DocumentWindowBounds;
  391. rectDockArea = RectangleToClient(DockPanel.RectangleToScreen(rectDockArea));
  392. if (ShouldPanelIndicatorVisible(DockState.DockLeft))
  393. {
  394. PanelLeft.Location = new Point(rectDockArea.X + _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
  395. PanelLeft.Visible = true;
  396. region.Union(PanelLeft.Bounds);
  397. }
  398. else
  399. PanelLeft.Visible = false;
  400. if (ShouldPanelIndicatorVisible(DockState.DockRight))
  401. {
  402. PanelRight.Location = new Point(rectDockArea.X + rectDockArea.Width - PanelRight.Width - _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
  403. PanelRight.Visible = true;
  404. region.Union(PanelRight.Bounds);
  405. }
  406. else
  407. PanelRight.Visible = false;
  408. if (ShouldPanelIndicatorVisible(DockState.DockTop))
  409. {
  410. PanelTop.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelTop.Width) / 2, rectDockArea.Y + _PanelIndicatorMargin);
  411. PanelTop.Visible = true;
  412. region.Union(PanelTop.Bounds);
  413. }
  414. else
  415. PanelTop.Visible = false;
  416. if (ShouldPanelIndicatorVisible(DockState.DockBottom))
  417. {
  418. PanelBottom.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelBottom.Width) / 2, rectDockArea.Y + rectDockArea.Height - PanelBottom.Height - _PanelIndicatorMargin);
  419. PanelBottom.Visible = true;
  420. region.Union(PanelBottom.Bounds);
  421. }
  422. else
  423. PanelBottom.Visible = false;
  424. if (ShouldPanelIndicatorVisible(DockState.Document))
  425. {
  426. Rectangle rectDocumentWindow = RectangleToClient(DockPanel.RectangleToScreen(DockPanel.DocumentWindowBounds));
  427. PanelFill.Location = new Point(rectDocumentWindow.X + (rectDocumentWindow.Width - PanelFill.Width) / 2, rectDocumentWindow.Y + (rectDocumentWindow.Height - PanelFill.Height) / 2);
  428. PanelFill.Visible = true;
  429. region.Union(PanelFill.Bounds);
  430. }
  431. else
  432. PanelFill.Visible = false;
  433. if (ShouldPaneDiamondVisible())
  434. {
  435. Rectangle rect = RectangleToClient(DockPane.RectangleToScreen(DockPane.ClientRectangle));
  436. PaneDiamond.Location = new Point(rect.Left + (rect.Width - PaneDiamond.Width) / 2, rect.Top + (rect.Height - PaneDiamond.Height) / 2);
  437. PaneDiamond.Visible = true;
  438. using (GraphicsPath graphicsPath = PaneIndicator.DisplayingGraphicsPath.Clone() as GraphicsPath)
  439. {
  440. Point[] pts = new Point[]
  441. {
  442. new Point(PaneDiamond.Left, PaneDiamond.Top),
  443. new Point(PaneDiamond.Right, PaneDiamond.Top),
  444. new Point(PaneDiamond.Left, PaneDiamond.Bottom)
  445. };
  446. using (Matrix matrix = new Matrix(PaneDiamond.ClientRectangle, pts))
  447. {
  448. graphicsPath.Transform(matrix);
  449. }
  450. region.Union(graphicsPath);
  451. }
  452. }
  453. else
  454. PaneDiamond.Visible = false;
  455. Region = region;
  456. }
  457. private bool ShouldPanelIndicatorVisible(DockState dockState)
  458. {
  459. if (!Visible)
  460. return false;
  461. if (DockPanel.DockWindows[dockState].Visible)
  462. return false;
  463. return DragHandler.DragSource.IsDockStateValid(dockState);
  464. }
  465. private bool ShouldPaneDiamondVisible()
  466. {
  467. if (DockPane == null)
  468. return false;
  469. if (!DockPanel.AllowEndUserNestedDocking)
  470. return false;
  471. return DragHandler.DragSource.CanDockTo(DockPane);
  472. }
  473. public override void Show(bool bActivate)
  474. {
  475. base.Show(bActivate);
  476. Bounds = SystemInformation.VirtualScreen;
  477. RefreshChanges();
  478. }
  479. public void TestDrop()
  480. {
  481. Point pt = Control.MousePosition;
  482. DockPane = DockHelper.PaneAtPoint(pt, DockPanel);
  483. if (TestDrop(PanelLeft, pt) != DockStyle.None)
  484. HitTestResult = PanelLeft;
  485. else if (TestDrop(PanelRight, pt) != DockStyle.None)
  486. HitTestResult = PanelRight;
  487. else if (TestDrop(PanelTop, pt) != DockStyle.None)
  488. HitTestResult = PanelTop;
  489. else if (TestDrop(PanelBottom, pt) != DockStyle.None)
  490. HitTestResult = PanelBottom;
  491. else if (TestDrop(PanelFill, pt) != DockStyle.None)
  492. HitTestResult = PanelFill;
  493. else if (TestDrop(PaneDiamond, pt) != DockStyle.None)
  494. HitTestResult = PaneDiamond;
  495. else
  496. HitTestResult = null;
  497. if (HitTestResult != null)
  498. {
  499. if (HitTestResult is PaneIndicator)
  500. DragHandler.Outline.Show(DockPane, HitTestResult.Status);
  501. else
  502. DragHandler.Outline.Show(DockPanel, HitTestResult.Status, FullPanelEdge);
  503. }
  504. }
  505. private static DockStyle TestDrop(IHitTest hitTest, Point pt)
  506. {
  507. return hitTest.Status = hitTest.HitTest(pt);
  508. }
  509. }
  510. private class DockOutline : DockOutlineBase
  511. {
  512. public DockOutline()
  513. {
  514. m_dragForm = new DragForm();
  515. SetDragForm(Rectangle.Empty);
  516. DragForm.BackColor = SystemColors.ActiveCaption;
  517. DragForm.Opacity = 0.5;
  518. DragForm.Show(false);
  519. }
  520. DragForm m_dragForm;
  521. private DragForm DragForm
  522. {
  523. get
  524. {
  525. return m_dragForm;
  526. }
  527. }
  528. protected override void OnShow()
  529. {
  530. CalculateRegion();
  531. }
  532. protected override void OnClose()
  533. {
  534. DragForm.Close();
  535. }
  536. private void CalculateRegion()
  537. {
  538. if (SameAsOldValue)
  539. return;
  540. if (!FloatWindowBounds.IsEmpty)
  541. SetOutline(FloatWindowBounds);
  542. else if (DockTo is DockPanel)
  543. SetOutline(DockTo as DockPanel, Dock, (ContentIndex != 0));
  544. else if (DockTo is DockPane)
  545. SetOutline(DockTo as DockPane, Dock, ContentIndex);
  546. else
  547. SetOutline();
  548. }
  549. private void SetOutline()
  550. {
  551. SetDragForm(Rectangle.Empty);
  552. }
  553. private void SetOutline(Rectangle floatWindowBounds)
  554. {
  555. SetDragForm(floatWindowBounds);
  556. }
  557. private void SetOutline(DockPanel dockPanel, DockStyle dock, bool fullPanelEdge)
  558. {
  559. Rectangle rect = fullPanelEdge ? dockPanel.DockArea : dockPanel.DocumentWindowBounds;
  560. rect.Location = dockPanel.PointToScreen(rect.Location);
  561. if (dock == DockStyle.Top)
  562. {
  563. int height = dockPanel.GetDockWindowSize(DockState.DockTop);
  564. rect = new Rectangle(rect.X, rect.Y, rect.Width, height);
  565. }
  566. else if (dock == DockStyle.Bottom)
  567. {
  568. int height = dockPanel.GetDockWindowSize(DockState.DockBottom);
  569. rect = new Rectangle(rect.X, rect.Bottom - height, rect.Width, height);
  570. }
  571. else if (dock == DockStyle.Left)
  572. {
  573. int width = dockPanel.GetDockWindowSize(DockState.DockLeft);
  574. rect = new Rectangle(rect.X, rect.Y, width, rect.Height);
  575. }
  576. else if (dock == DockStyle.Right)
  577. {
  578. int width = dockPanel.GetDockWindowSize(DockState.DockRight);
  579. rect = new Rectangle(rect.Right - width, rect.Y, width, rect.Height);
  580. }
  581. else if (dock == DockStyle.Fill)
  582. {
  583. rect = dockPanel.DocumentWindowBounds;
  584. rect.Location = dockPanel.PointToScreen(rect.Location);
  585. }
  586. SetDragForm(rect);
  587. }
  588. private void SetOutline(DockPane pane, DockStyle dock, int contentIndex)
  589. {
  590. if (dock != DockStyle.Fill)
  591. {
  592. Rectangle rect = pane.DisplayingRectangle;
  593. if (dock == DockStyle.Right)
  594. rect.X += rect.Width / 2;
  595. if (dock == DockStyle.Bottom)
  596. rect.Y += rect.Height / 2;
  597. if (dock == DockStyle.Left || dock == DockStyle.Right)
  598. rect.Width -= rect.Width / 2;
  599. if (dock == DockStyle.Top || dock == DockStyle.Bottom)
  600. rect.Height -= rect.Height / 2;
  601. rect.Location = pane.PointToScreen(rect.Location);
  602. SetDragForm(rect);
  603. }
  604. else if (contentIndex == -1)
  605. {
  606. Rectangle rect = pane.DisplayingRectangle;
  607. rect.Location = pane.PointToScreen(rect.Location);
  608. SetDragForm(rect);
  609. }
  610. else
  611. {
  612. using (GraphicsPath path = pane.TabStripControl.GetOutline(contentIndex))
  613. {
  614. RectangleF rectF = path.GetBounds();
  615. Rectangle rect = new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height);
  616. using (Matrix matrix = new Matrix(rect, new Point[] { new Point(0, 0), new Point(rect.Width, 0), new Point(0, rect.Height) }))
  617. {
  618. path.Transform(matrix);
  619. }
  620. Region region = new Region(path);
  621. SetDragForm(rect, region);
  622. }
  623. }
  624. }
  625. private void SetDragForm(Rectangle rect)
  626. {
  627. DragForm.Bounds = rect;
  628. if (rect == Rectangle.Empty)
  629. DragForm.Region = new Region(Rectangle.Empty);
  630. else if (DragForm.Region != null)
  631. DragForm.Region = null;
  632. }
  633. private void SetDragForm(Rectangle rect, Region region)
  634. {
  635. DragForm.Bounds = rect;
  636. DragForm.Region = region;
  637. }
  638. }
  639. public DockDragHandler(DockPanel panel)
  640. : base(panel)
  641. {
  642. }
  643. public new IDockDragSource DragSource
  644. {
  645. get
  646. {
  647. return base.DragSource as IDockDragSource;
  648. }
  649. set
  650. {
  651. base.DragSource = value;
  652. }
  653. }
  654. private DockOutlineBase m_outline;
  655. public DockOutlineBase Outline
  656. {
  657. get
  658. {
  659. return m_outline;
  660. }
  661. private set
  662. {
  663. m_outline = value;
  664. }
  665. }
  666. private DockIndicator m_indicator;
  667. private DockIndicator Indicator
  668. {
  669. get
  670. {
  671. return m_indicator;
  672. }
  673. set
  674. {
  675. m_indicator = value;
  676. }
  677. }
  678. private Rectangle m_floatOutlineBounds;
  679. private Rectangle FloatOutlineBounds
  680. {
  681. get
  682. {
  683. return m_floatOutlineBounds;
  684. }
  685. set
  686. {
  687. m_floatOutlineBounds = value;
  688. }
  689. }
  690. public void BeginDrag(IDockDragSource dragSource)
  691. {
  692. DragSource = dragSource;
  693. if (!BeginDrag())
  694. {
  695. DragSource = null;
  696. return;
  697. }
  698. Outline = new DockOutline();
  699. Indicator = new DockIndicator(this);
  700. Indicator.Show(false);
  701. FloatOutlineBounds = DragSource.BeginDrag(StartMousePosition);
  702. }
  703. protected override void OnDragging()
  704. {
  705. TestDrop();
  706. }
  707. protected override void OnEndDrag(bool abort)
  708. {
  709. DockPanel.SuspendLayout(true);
  710. Outline.Close();
  711. Indicator.Close();
  712. EndDrag(abort);
  713. // Queue a request to layout all children controls
  714. DockPanel.PerformMdiClientLayout();
  715. DockPanel.ResumeLayout(true, true);
  716. DragSource.EndDrag();
  717. DragSource = null;
  718. }
  719. private void TestDrop()
  720. {
  721. Outline.FlagTestDrop = false;
  722. Indicator.FullPanelEdge = ((Control.ModifierKeys & Keys.Shift) != 0);
  723. if ((Control.ModifierKeys & Keys.Control) == 0)
  724. {
  725. Indicator.TestDrop();
  726. if (!Outline.FlagTestDrop)
  727. {
  728. DockPane pane = DockHelper.PaneAtPoint(Control.MousePosition, DockPanel);
  729. if (pane != null && DragSource.IsDockStateValid(pane.DockState))
  730. pane.TestDrop(DragSource, Outline);
  731. }
  732. if (!Outline.FlagTestDrop && DragSource.IsDockStateValid(DockState.Float))
  733. {
  734. FloatWindow floatWindow = DockHelper.FloatWindowAtPoint(Control.MousePosition, DockPanel);
  735. if (floatWindow != null)
  736. floatWindow.TestDrop(DragSource, Outline);
  737. }
  738. }
  739. else
  740. Indicator.DockPane = DockHelper.PaneAtPoint(Control.MousePosition, DockPanel);
  741. if (!Outline.FlagTestDrop)
  742. {
  743. if (DragSource.IsDockStateValid(DockState.Float))
  744. {
  745. Rectangle rect = FloatOutlineBounds;
  746. rect.Offset(Control.MousePosition.X - StartMousePosition.X, Control.MousePosition.Y - StartMousePosition.Y);
  747. Outline.Show(rect);
  748. }
  749. }
  750. if (!Outline.FlagTestDrop)
  751. {
  752. Cursor.Current = Cursors.No;
  753. Outline.Show();
  754. }
  755. else
  756. Cursor.Current = DragControl.Cursor;
  757. }
  758. private void EndDrag(bool abort)
  759. {
  760. if (abort)
  761. return;
  762. if (!Outline.FloatWindowBounds.IsEmpty)
  763. DragSource.FloatAt(Outline.FloatWindowBounds);
  764. else if (Outline.DockTo is DockPane)
  765. {
  766. DockPane pane = Outline.DockTo as DockPane;
  767. DragSource.DockTo(pane, Outline.Dock, Outline.ContentIndex);
  768. }
  769. else if (Outline.DockTo is DockPanel)
  770. {
  771. DockPanel panel = Outline.DockTo as DockPanel;
  772. panel.UpdateDockWindowZOrder(Outline.Dock, Outline.FlagFullEdge);
  773. DragSource.DockTo(panel, Outline.Dock);
  774. }
  775. }
  776. }
  777. private DockDragHandler m_dockDragHandler = null;
  778. private DockDragHandler GetDockDragHandler()
  779. {
  780. if (m_dockDragHandler == null)
  781. m_dockDragHandler = new DockDragHandler(this);
  782. return m_dockDragHandler;
  783. }
  784. internal void BeginDrag(IDockDragSource dragSource)
  785. {
  786. GetDockDragHandler().BeginDrag(dragSource);
  787. }
  788. }
  789. }