NestedPaneCollection.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:NestedPaneCollection.cs
  5. * 2.功能描述:类文件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/01 1.00 新建
  9. *******************************************************************************/
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Drawing;
  13. namespace Dongke.IBOSS.PRD.Basics.DockPanel
  14. {
  15. public sealed class NestedPaneCollection : ReadOnlyCollection<DockPane>
  16. {
  17. private INestedPanesContainer m_container;
  18. private VisibleNestedPaneCollection m_visibleNestedPanes;
  19. internal NestedPaneCollection(INestedPanesContainer container)
  20. : base(new List<DockPane>())
  21. {
  22. m_container = container;
  23. m_visibleNestedPanes = new VisibleNestedPaneCollection(this);
  24. }
  25. public INestedPanesContainer Container
  26. {
  27. get
  28. {
  29. return m_container;
  30. }
  31. }
  32. public VisibleNestedPaneCollection VisibleNestedPanes
  33. {
  34. get
  35. {
  36. return m_visibleNestedPanes;
  37. }
  38. }
  39. public DockState DockState
  40. {
  41. get
  42. {
  43. return Container.DockState;
  44. }
  45. }
  46. public bool IsFloat
  47. {
  48. get
  49. {
  50. return DockState == DockState.Float;
  51. }
  52. }
  53. internal void Add(DockPane pane)
  54. {
  55. if (pane == null)
  56. return;
  57. NestedPaneCollection oldNestedPanes = (pane.NestedPanesContainer == null) ? null : pane.NestedPanesContainer.NestedPanes;
  58. if (oldNestedPanes != null)
  59. oldNestedPanes.InternalRemove(pane);
  60. Items.Add(pane);
  61. if (oldNestedPanes != null)
  62. oldNestedPanes.CheckFloatWindowDispose();
  63. }
  64. private void CheckFloatWindowDispose()
  65. {
  66. if (Count == 0 && Container.DockState == DockState.Float)
  67. {
  68. FloatWindow floatWindow = (FloatWindow)Container;
  69. if (!floatWindow.Disposing && !floatWindow.IsDisposed)
  70. if (!Win32Helper.IsRunningOnMono)
  71. NativeMethods.PostMessage(((FloatWindow)Container).Handle, FloatWindow.WM_CHECKDISPOSE, 0, 0);
  72. }
  73. }
  74. /// <summary>
  75. /// Switches a pane with its first child in the pane hierarchy. (The actual hiding happens elsewhere.)
  76. /// </summary>
  77. /// <param name="pane">Pane to switch</param>
  78. internal void SwitchPaneWithFirstChild(DockPane pane)
  79. {
  80. if (!Contains(pane))
  81. return;
  82. NestedDockingStatus statusPane = pane.NestedDockingStatus;
  83. DockPane lastNestedPane = null;
  84. for (int i = Count - 1; i > IndexOf(pane); i--)
  85. {
  86. if (this[i].NestedDockingStatus.PreviousPane == pane)
  87. {
  88. lastNestedPane = this[i];
  89. break;
  90. }
  91. }
  92. if (lastNestedPane != null)
  93. {
  94. int indexLastNestedPane = IndexOf(lastNestedPane);
  95. Items[IndexOf(pane)] = lastNestedPane;
  96. Items[indexLastNestedPane] = pane;
  97. NestedDockingStatus lastNestedDock = lastNestedPane.NestedDockingStatus;
  98. DockAlignment newAlignment;
  99. if (lastNestedDock.Alignment == DockAlignment.Left)
  100. newAlignment = DockAlignment.Right;
  101. else if (lastNestedDock.Alignment == DockAlignment.Right)
  102. newAlignment = DockAlignment.Left;
  103. else if (lastNestedDock.Alignment == DockAlignment.Top)
  104. newAlignment = DockAlignment.Bottom;
  105. else
  106. newAlignment = DockAlignment.Top;
  107. double newProportion = 1 - lastNestedDock.Proportion;
  108. lastNestedDock.SetStatus(this, statusPane.PreviousPane, statusPane.Alignment, statusPane.Proportion);
  109. for (int i = indexLastNestedPane - 1; i > IndexOf(lastNestedPane); i--)
  110. {
  111. NestedDockingStatus status = this[i].NestedDockingStatus;
  112. if (status.PreviousPane == pane)
  113. status.SetStatus(this, lastNestedPane, status.Alignment, status.Proportion);
  114. }
  115. statusPane.SetStatus(this, lastNestedPane, newAlignment, newProportion);
  116. }
  117. }
  118. internal void Remove(DockPane pane)
  119. {
  120. InternalRemove(pane);
  121. CheckFloatWindowDispose();
  122. }
  123. private void InternalRemove(DockPane pane)
  124. {
  125. if (!Contains(pane))
  126. return;
  127. NestedDockingStatus statusPane = pane.NestedDockingStatus;
  128. DockPane lastNestedPane = null;
  129. for (int i = Count - 1; i > IndexOf(pane); i--)
  130. {
  131. if (this[i].NestedDockingStatus.PreviousPane == pane)
  132. {
  133. lastNestedPane = this[i];
  134. break;
  135. }
  136. }
  137. if (lastNestedPane != null)
  138. {
  139. int indexLastNestedPane = IndexOf(lastNestedPane);
  140. Items.Remove(lastNestedPane);
  141. Items[IndexOf(pane)] = lastNestedPane;
  142. NestedDockingStatus lastNestedDock = lastNestedPane.NestedDockingStatus;
  143. lastNestedDock.SetStatus(this, statusPane.PreviousPane, statusPane.Alignment, statusPane.Proportion);
  144. for (int i = indexLastNestedPane - 1; i > IndexOf(lastNestedPane); i--)
  145. {
  146. NestedDockingStatus status = this[i].NestedDockingStatus;
  147. if (status.PreviousPane == pane)
  148. status.SetStatus(this, lastNestedPane, status.Alignment, status.Proportion);
  149. }
  150. }
  151. else
  152. Items.Remove(pane);
  153. statusPane.SetStatus(null, null, DockAlignment.Left, 0.5);
  154. statusPane.SetDisplayingStatus(false, null, DockAlignment.Left, 0.5);
  155. statusPane.SetDisplayingBounds(Rectangle.Empty, Rectangle.Empty, Rectangle.Empty);
  156. }
  157. public DockPane GetDefaultPreviousPane(DockPane pane)
  158. {
  159. for (int i = Count - 1; i >= 0; i--)
  160. if (this[i] != pane)
  161. return this[i];
  162. return null;
  163. }
  164. }
  165. }