DockPanelExtender.cs
上传用户:szlfmled
上传日期:2020-11-22
资源大小:978k
文件大小:6k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Diagnostics.CodeAnalysis;
  4. namespace WeifenLuo.WinFormsUI.Docking
  5. {
  6. public sealed class DockPanelExtender
  7. {
  8.         [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
  9.         public interface IDockPaneFactory
  10. {
  11. DockPane CreateDockPane(IDockContent content, DockState visibleState, bool show);
  12.             [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "1#")]            
  13. DockPane CreateDockPane(IDockContent content, FloatWindow floatWindow, bool show);
  14. DockPane CreateDockPane(IDockContent content, DockPane previousPane, DockAlignment alignment, double proportion, bool show);
  15.             [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "1#")]            
  16. DockPane CreateDockPane(IDockContent content, Rectangle floatWindowBounds, bool show);
  17. }
  18.         [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
  19.         public interface IFloatWindowFactory
  20. {
  21. FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane);
  22. FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds);
  23. }
  24.         [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
  25.         public interface IDockPaneCaptionFactory
  26. {
  27. DockPaneCaptionBase CreateDockPaneCaption(DockPane pane);
  28. }
  29.         [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
  30.         public interface IDockPaneStripFactory
  31. {
  32. DockPaneStripBase CreateDockPaneStrip(DockPane pane);
  33. }
  34.         [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
  35.         public interface IAutoHideStripFactory
  36. {
  37. AutoHideStripBase CreateAutoHideStrip(DockPanel panel);
  38. }
  39. #region DefaultDockPaneFactory
  40. private class DefaultDockPaneFactory : IDockPaneFactory
  41. {
  42. public DockPane CreateDockPane(IDockContent content, DockState visibleState, bool show)
  43. {
  44. return new DockPane(content, visibleState, show);
  45. }
  46. public DockPane CreateDockPane(IDockContent content, FloatWindow floatWindow, bool show)
  47. {
  48. return new DockPane(content, floatWindow, show);
  49. }
  50. public DockPane CreateDockPane(IDockContent content, DockPane prevPane, DockAlignment alignment, double proportion, bool show)
  51. {
  52. return new DockPane(content, prevPane, alignment, proportion, show);
  53. }
  54. public DockPane CreateDockPane(IDockContent content, Rectangle floatWindowBounds, bool show)
  55. {
  56. return new DockPane(content, floatWindowBounds, show);
  57. }
  58. }
  59. #endregion
  60. #region DefaultFloatWindowFactory
  61. private class DefaultFloatWindowFactory : IFloatWindowFactory
  62. {
  63. public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane)
  64. {
  65. return new FloatWindow(dockPanel, pane);
  66. }
  67. public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds)
  68. {
  69. return new FloatWindow(dockPanel, pane, bounds);
  70. }
  71. }
  72. #endregion
  73. #region DefaultDockPaneCaptionFactory
  74. private class DefaultDockPaneCaptionFactory : IDockPaneCaptionFactory
  75. {
  76. public DockPaneCaptionBase CreateDockPaneCaption(DockPane pane)
  77. {
  78. return new VS2005DockPaneCaption(pane);
  79. }
  80. }
  81. #endregion
  82. #region DefaultDockPaneTabStripFactory
  83. private class DefaultDockPaneStripFactory : IDockPaneStripFactory
  84. {
  85. public DockPaneStripBase CreateDockPaneStrip(DockPane pane)
  86. {
  87. return new VS2005DockPaneStrip(pane);
  88. }
  89. }
  90. #endregion
  91. #region DefaultAutoHideStripFactory
  92. private class DefaultAutoHideStripFactory : IAutoHideStripFactory
  93. {
  94. public AutoHideStripBase CreateAutoHideStrip(DockPanel panel)
  95. {
  96. return new VS2005AutoHideStrip(panel);
  97. }
  98. }
  99. #endregion
  100. internal DockPanelExtender(DockPanel dockPanel)
  101. {
  102. m_dockPanel = dockPanel;
  103. }
  104. private DockPanel m_dockPanel;
  105. private DockPanel DockPanel
  106. {
  107. get { return m_dockPanel; }
  108. }
  109. private IDockPaneFactory m_dockPaneFactory = null;
  110. public IDockPaneFactory DockPaneFactory
  111. {
  112. get
  113. {
  114. if (m_dockPaneFactory == null)
  115. m_dockPaneFactory = new DefaultDockPaneFactory();
  116. return m_dockPaneFactory;
  117. }
  118. set
  119. {
  120. if (DockPanel.Panes.Count > 0)
  121. throw new InvalidOperationException();
  122. m_dockPaneFactory = value;
  123. }
  124. }
  125. private IFloatWindowFactory m_floatWindowFactory = null;
  126. public IFloatWindowFactory FloatWindowFactory
  127. {
  128. get
  129. {
  130. if (m_floatWindowFactory == null)
  131. m_floatWindowFactory = new DefaultFloatWindowFactory();
  132. return m_floatWindowFactory;
  133. }
  134. set
  135. {
  136. if (DockPanel.FloatWindows.Count > 0)
  137. throw new InvalidOperationException();
  138. m_floatWindowFactory = value;
  139. }
  140. }
  141. private IDockPaneCaptionFactory m_dockPaneCaptionFactory = null;
  142. public IDockPaneCaptionFactory DockPaneCaptionFactory
  143. {
  144. get
  145. {
  146. if (m_dockPaneCaptionFactory == null)
  147. m_dockPaneCaptionFactory = new DefaultDockPaneCaptionFactory();
  148. return m_dockPaneCaptionFactory;
  149. }
  150. set
  151. {
  152. if (DockPanel.Panes.Count > 0)
  153. throw new InvalidOperationException();
  154. m_dockPaneCaptionFactory = value;
  155. }
  156. }
  157. private IDockPaneStripFactory m_dockPaneStripFactory = null;
  158. public IDockPaneStripFactory DockPaneStripFactory
  159. {
  160. get
  161. {
  162. if (m_dockPaneStripFactory == null)
  163. m_dockPaneStripFactory = new DefaultDockPaneStripFactory();
  164. return m_dockPaneStripFactory;
  165. }
  166. set
  167. {
  168. if (DockPanel.Contents.Count > 0)
  169. throw new InvalidOperationException();
  170. m_dockPaneStripFactory = value;
  171. }
  172. }
  173. private IAutoHideStripFactory m_autoHideStripFactory = null;
  174. public IAutoHideStripFactory AutoHideStripFactory
  175. {
  176. get
  177. {
  178. if (m_autoHideStripFactory == null)
  179. m_autoHideStripFactory = new DefaultAutoHideStripFactory();
  180. return m_autoHideStripFactory;
  181. }
  182. set
  183. {
  184. if (DockPanel.Contents.Count > 0)
  185. throw new InvalidOperationException();
  186. if (m_autoHideStripFactory == value)
  187. return;
  188. m_autoHideStripFactory = value;
  189.                 DockPanel.ResetAutoHideStripControl();
  190. }
  191. }
  192. }
  193. }