VisibleNestedPaneCollection.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:VisibleNestedPaneCollection.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 VisibleNestedPaneCollection : ReadOnlyCollection<DockPane>
  16. {
  17. private NestedPaneCollection m_nestedPanes;
  18. internal VisibleNestedPaneCollection(NestedPaneCollection nestedPanes)
  19. : base(new List<DockPane>())
  20. {
  21. m_nestedPanes = nestedPanes;
  22. }
  23. public NestedPaneCollection NestedPanes
  24. {
  25. get
  26. {
  27. return m_nestedPanes;
  28. }
  29. }
  30. public INestedPanesContainer Container
  31. {
  32. get
  33. {
  34. return NestedPanes.Container;
  35. }
  36. }
  37. public DockState DockState
  38. {
  39. get
  40. {
  41. return NestedPanes.DockState;
  42. }
  43. }
  44. public bool IsFloat
  45. {
  46. get
  47. {
  48. return NestedPanes.IsFloat;
  49. }
  50. }
  51. internal void Refresh()
  52. {
  53. Items.Clear();
  54. for (int i = 0; i < NestedPanes.Count; i++)
  55. {
  56. DockPane pane = NestedPanes[i];
  57. NestedDockingStatus status = pane.NestedDockingStatus;
  58. status.SetDisplayingStatus(true, status.PreviousPane, status.Alignment, status.Proportion);
  59. Items.Add(pane);
  60. }
  61. foreach (DockPane pane in NestedPanes)
  62. if (pane.DockState != DockState || pane.IsHidden)
  63. {
  64. pane.Bounds = Rectangle.Empty;
  65. pane.SplitterBounds = Rectangle.Empty;
  66. Remove(pane);
  67. }
  68. CalculateBounds();
  69. foreach (DockPane pane in this)
  70. {
  71. NestedDockingStatus status = pane.NestedDockingStatus;
  72. pane.Bounds = status.PaneBounds;
  73. pane.SplitterBounds = status.SplitterBounds;
  74. pane.SplitterAlignment = status.Alignment;
  75. }
  76. }
  77. private void Remove(DockPane pane)
  78. {
  79. if (!Contains(pane))
  80. return;
  81. NestedDockingStatus statusPane = pane.NestedDockingStatus;
  82. DockPane lastNestedPane = null;
  83. for (int i = Count - 1; i > IndexOf(pane); i--)
  84. {
  85. if (this[i].NestedDockingStatus.PreviousPane == pane)
  86. {
  87. lastNestedPane = this[i];
  88. break;
  89. }
  90. }
  91. if (lastNestedPane != null)
  92. {
  93. int indexLastNestedPane = IndexOf(lastNestedPane);
  94. Items.Remove(lastNestedPane);
  95. Items[IndexOf(pane)] = lastNestedPane;
  96. NestedDockingStatus lastNestedDock = lastNestedPane.NestedDockingStatus;
  97. lastNestedDock.SetDisplayingStatus(true, statusPane.DisplayingPreviousPane, statusPane.DisplayingAlignment, statusPane.DisplayingProportion);
  98. for (int i = indexLastNestedPane - 1; i > IndexOf(lastNestedPane); i--)
  99. {
  100. NestedDockingStatus status = this[i].NestedDockingStatus;
  101. if (status.PreviousPane == pane)
  102. status.SetDisplayingStatus(true, lastNestedPane, status.DisplayingAlignment, status.DisplayingProportion);
  103. }
  104. }
  105. else
  106. Items.Remove(pane);
  107. statusPane.SetDisplayingStatus(false, null, DockAlignment.Left, 0.5);
  108. }
  109. private void CalculateBounds()
  110. {
  111. if (Count == 0)
  112. return;
  113. this[0].NestedDockingStatus.SetDisplayingBounds(Container.DisplayingRectangle, Container.DisplayingRectangle, Rectangle.Empty);
  114. for (int i = 1; i < Count; i++)
  115. {
  116. DockPane pane = this[i];
  117. NestedDockingStatus status = pane.NestedDockingStatus;
  118. DockPane prevPane = status.DisplayingPreviousPane;
  119. NestedDockingStatus statusPrev = prevPane.NestedDockingStatus;
  120. Rectangle rect = statusPrev.PaneBounds;
  121. bool bVerticalSplitter = (status.DisplayingAlignment == DockAlignment.Left || status.DisplayingAlignment == DockAlignment.Right);
  122. Rectangle rectThis = rect;
  123. Rectangle rectPrev = rect;
  124. Rectangle rectSplitter = rect;
  125. if (status.DisplayingAlignment == DockAlignment.Left)
  126. {
  127. rectThis.Width = (int)((double)rect.Width * status.DisplayingProportion) - (Measures.SplitterSize / 2);
  128. rectSplitter.X = rectThis.X + rectThis.Width;
  129. rectSplitter.Width = Measures.SplitterSize;
  130. rectPrev.X = rectSplitter.X + rectSplitter.Width;
  131. rectPrev.Width = rect.Width - rectThis.Width - rectSplitter.Width;
  132. }
  133. else if (status.DisplayingAlignment == DockAlignment.Right)
  134. {
  135. rectPrev.Width = (rect.Width - (int)((double)rect.Width * status.DisplayingProportion)) - (Measures.SplitterSize / 2);
  136. rectSplitter.X = rectPrev.X + rectPrev.Width;
  137. rectSplitter.Width = Measures.SplitterSize;
  138. rectThis.X = rectSplitter.X + rectSplitter.Width;
  139. rectThis.Width = rect.Width - rectPrev.Width - rectSplitter.Width;
  140. }
  141. else if (status.DisplayingAlignment == DockAlignment.Top)
  142. {
  143. rectThis.Height = (int)((double)rect.Height * status.DisplayingProportion) - (Measures.SplitterSize / 2);
  144. rectSplitter.Y = rectThis.Y + rectThis.Height;
  145. rectSplitter.Height = Measures.SplitterSize;
  146. rectPrev.Y = rectSplitter.Y + rectSplitter.Height;
  147. rectPrev.Height = rect.Height - rectThis.Height - rectSplitter.Height;
  148. }
  149. else if (status.DisplayingAlignment == DockAlignment.Bottom)
  150. {
  151. rectPrev.Height = (rect.Height - (int)((double)rect.Height * status.DisplayingProportion)) - (Measures.SplitterSize / 2);
  152. rectSplitter.Y = rectPrev.Y + rectPrev.Height;
  153. rectSplitter.Height = Measures.SplitterSize;
  154. rectThis.Y = rectSplitter.Y + rectSplitter.Height;
  155. rectThis.Height = rect.Height - rectPrev.Height - rectSplitter.Height;
  156. }
  157. else
  158. rectThis = Rectangle.Empty;
  159. rectSplitter.Intersect(rect);
  160. rectThis.Intersect(rect);
  161. rectPrev.Intersect(rect);
  162. status.SetDisplayingBounds(rect, rectThis, rectSplitter);
  163. statusPrev.SetDisplayingBounds(statusPrev.LogicalBounds, rectPrev, statusPrev.SplitterBounds);
  164. }
  165. }
  166. }
  167. }