DockContent.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:DockContent.cs
  5. * 2.功能描述:类文件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/01 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Diagnostics.CodeAnalysis;
  13. using System.Drawing;
  14. using System.Windows.Forms;
  15. namespace Dongke.IBOSS.PRD.Basics.DockPanel
  16. {
  17. public class DockContent : Form, IDockContent
  18. {
  19. public DockContent()
  20. {
  21. m_dockHandler = new DockContentHandler(this, new GetPersistStringCallback(GetPersistString));
  22. m_dockHandler.DockStateChanged += new EventHandler(DockHandler_DockStateChanged);
  23. //Suggested as a fix by bensty regarding form resize
  24. this.ParentChanged += new EventHandler(DockContent_ParentChanged);
  25. }
  26. //Suggested as a fix by bensty regarding form resize
  27. private void DockContent_ParentChanged(object Sender, EventArgs e)
  28. {
  29. if (this.Parent != null)
  30. this.Font = this.Parent.Font;
  31. }
  32. private DockContentHandler m_dockHandler = null;
  33. [Browsable(false)]
  34. public DockContentHandler DockHandler
  35. {
  36. get
  37. {
  38. return m_dockHandler;
  39. }
  40. }
  41. [LocalizedCategory("Category_Docking")]
  42. [LocalizedDescription("DockContent_AllowEndUserDocking_Description")]
  43. [DefaultValue(true)]
  44. public bool AllowEndUserDocking
  45. {
  46. get
  47. {
  48. return DockHandler.AllowEndUserDocking;
  49. }
  50. set
  51. {
  52. DockHandler.AllowEndUserDocking = value;
  53. }
  54. }
  55. [LocalizedCategory("Category_Docking")]
  56. [LocalizedDescription("DockContent_DockAreas_Description")]
  57. [DefaultValue(DockAreas.DockLeft | DockAreas.DockRight | DockAreas.DockTop | DockAreas.DockBottom | DockAreas.Document | DockAreas.Float)]
  58. public DockAreas DockAreas
  59. {
  60. get
  61. {
  62. return DockHandler.DockAreas;
  63. }
  64. set
  65. {
  66. DockHandler.DockAreas = value;
  67. }
  68. }
  69. [LocalizedCategory("Category_Docking")]
  70. [LocalizedDescription("DockContent_AutoHidePortion_Description")]
  71. [DefaultValue(0.25)]
  72. public double AutoHidePortion
  73. {
  74. get
  75. {
  76. return DockHandler.AutoHidePortion;
  77. }
  78. set
  79. {
  80. DockHandler.AutoHidePortion = value;
  81. }
  82. }
  83. private string m_tabText = null;
  84. [Localizable(true)]
  85. [LocalizedCategory("Category_Docking")]
  86. [LocalizedDescription("DockContent_TabText_Description")]
  87. [DefaultValue(null)]
  88. public string TabText
  89. {
  90. get
  91. {
  92. return m_tabText;
  93. }
  94. set
  95. {
  96. DockHandler.TabText = m_tabText = value;
  97. }
  98. }
  99. private bool ShouldSerializeTabText()
  100. {
  101. return (m_tabText != null);
  102. }
  103. [LocalizedCategory("Category_Docking")]
  104. [LocalizedDescription("DockContent_CloseButton_Description")]
  105. [DefaultValue(true)]
  106. public bool CloseButton
  107. {
  108. get
  109. {
  110. return DockHandler.CloseButton;
  111. }
  112. set
  113. {
  114. DockHandler.CloseButton = value;
  115. }
  116. }
  117. [LocalizedCategory("Category_Docking")]
  118. [LocalizedDescription("DockContent_CloseButtonVisible_Description")]
  119. [DefaultValue(true)]
  120. public bool CloseButtonVisible
  121. {
  122. get
  123. {
  124. return DockHandler.CloseButtonVisible;
  125. }
  126. set
  127. {
  128. DockHandler.CloseButtonVisible = value;
  129. }
  130. }
  131. [Browsable(false)]
  132. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  133. public DockPanel DockPanel
  134. {
  135. get
  136. {
  137. return DockHandler.DockPanel;
  138. }
  139. set
  140. {
  141. DockHandler.DockPanel = value;
  142. }
  143. }
  144. [Browsable(false)]
  145. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  146. public DockState DockState
  147. {
  148. get
  149. {
  150. return DockHandler.DockState;
  151. }
  152. set
  153. {
  154. DockHandler.DockState = value;
  155. }
  156. }
  157. [Browsable(false)]
  158. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  159. public DockPane Pane
  160. {
  161. get
  162. {
  163. return DockHandler.Pane;
  164. }
  165. set
  166. {
  167. DockHandler.Pane = value;
  168. }
  169. }
  170. [Browsable(false)]
  171. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  172. public bool IsHidden
  173. {
  174. get
  175. {
  176. return DockHandler.IsHidden;
  177. }
  178. set
  179. {
  180. DockHandler.IsHidden = value;
  181. }
  182. }
  183. [Browsable(false)]
  184. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  185. public DockState VisibleState
  186. {
  187. get
  188. {
  189. return DockHandler.VisibleState;
  190. }
  191. set
  192. {
  193. DockHandler.VisibleState = value;
  194. }
  195. }
  196. [Browsable(false)]
  197. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  198. public bool IsFloat
  199. {
  200. get
  201. {
  202. return DockHandler.IsFloat;
  203. }
  204. set
  205. {
  206. DockHandler.IsFloat = value;
  207. }
  208. }
  209. [Browsable(false)]
  210. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  211. public DockPane PanelPane
  212. {
  213. get
  214. {
  215. return DockHandler.PanelPane;
  216. }
  217. set
  218. {
  219. DockHandler.PanelPane = value;
  220. }
  221. }
  222. [Browsable(false)]
  223. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  224. public DockPane FloatPane
  225. {
  226. get
  227. {
  228. return DockHandler.FloatPane;
  229. }
  230. set
  231. {
  232. DockHandler.FloatPane = value;
  233. }
  234. }
  235. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
  236. protected virtual string GetPersistString()
  237. {
  238. return GetType().ToString();
  239. }
  240. [LocalizedCategory("Category_Docking")]
  241. [LocalizedDescription("DockContent_HideOnClose_Description")]
  242. [DefaultValue(false)]
  243. public bool HideOnClose
  244. {
  245. get
  246. {
  247. return DockHandler.HideOnClose;
  248. }
  249. set
  250. {
  251. DockHandler.HideOnClose = value;
  252. }
  253. }
  254. [LocalizedCategory("Category_Docking")]
  255. [LocalizedDescription("DockContent_ShowHint_Description")]
  256. [DefaultValue(DockState.Unknown)]
  257. public DockState ShowHint
  258. {
  259. get
  260. {
  261. return DockHandler.ShowHint;
  262. }
  263. set
  264. {
  265. DockHandler.ShowHint = value;
  266. }
  267. }
  268. [Browsable(false)]
  269. public bool IsActivated
  270. {
  271. get
  272. {
  273. return DockHandler.IsActivated;
  274. }
  275. }
  276. public bool IsDockStateValid(DockState dockState)
  277. {
  278. return DockHandler.IsDockStateValid(dockState);
  279. }
  280. [LocalizedCategory("Category_Docking")]
  281. [LocalizedDescription("DockContent_TabPageContextMenu_Description")]
  282. [DefaultValue(null)]
  283. public ContextMenu TabPageContextMenu
  284. {
  285. get
  286. {
  287. return DockHandler.TabPageContextMenu;
  288. }
  289. set
  290. {
  291. DockHandler.TabPageContextMenu = value;
  292. }
  293. }
  294. [LocalizedCategory("Category_Docking")]
  295. [LocalizedDescription("DockContent_TabPageContextMenuStrip_Description")]
  296. [DefaultValue(null)]
  297. public ContextMenuStrip TabPageContextMenuStrip
  298. {
  299. get
  300. {
  301. return DockHandler.TabPageContextMenuStrip;
  302. }
  303. set
  304. {
  305. DockHandler.TabPageContextMenuStrip = value;
  306. }
  307. }
  308. [Localizable(true)]
  309. [Category("Appearance")]
  310. [LocalizedDescription("DockContent_ToolTipText_Description")]
  311. [DefaultValue(null)]
  312. public string ToolTipText
  313. {
  314. get
  315. {
  316. return DockHandler.ToolTipText;
  317. }
  318. set
  319. {
  320. DockHandler.ToolTipText = value;
  321. }
  322. }
  323. public new void Activate()
  324. {
  325. DockHandler.Activate();
  326. }
  327. public new void Hide()
  328. {
  329. DockHandler.Hide();
  330. }
  331. public new void Show()
  332. {
  333. DockHandler.Show();
  334. }
  335. public void Show(DockPanel dockPanel)
  336. {
  337. DockHandler.Show(dockPanel);
  338. }
  339. public void Show(DockPanel dockPanel, DockState dockState)
  340. {
  341. DockHandler.Show(dockPanel, dockState);
  342. }
  343. [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
  344. public void Show(DockPanel dockPanel, Rectangle floatWindowBounds)
  345. {
  346. DockHandler.Show(dockPanel, floatWindowBounds);
  347. }
  348. public void Show(DockPane pane, IDockContent beforeContent)
  349. {
  350. DockHandler.Show(pane, beforeContent);
  351. }
  352. public void Show(DockPane previousPane, DockAlignment alignment, double proportion)
  353. {
  354. DockHandler.Show(previousPane, alignment, proportion);
  355. }
  356. [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
  357. public void FloatAt(Rectangle floatWindowBounds)
  358. {
  359. DockHandler.FloatAt(floatWindowBounds);
  360. }
  361. public void DockTo(DockPane paneTo, DockStyle dockStyle, int contentIndex)
  362. {
  363. DockHandler.DockTo(paneTo, dockStyle, contentIndex);
  364. }
  365. public void DockTo(DockPanel panel, DockStyle dockStyle)
  366. {
  367. DockHandler.DockTo(panel, dockStyle);
  368. }
  369. #region IDockContent Members
  370. void IDockContent.OnActivated(EventArgs e)
  371. {
  372. this.OnActivated(e);
  373. }
  374. void IDockContent.OnDeactivate(EventArgs e)
  375. {
  376. this.OnDeactivate(e);
  377. }
  378. #endregion
  379. #region Events
  380. private void DockHandler_DockStateChanged(object sender, EventArgs e)
  381. {
  382. OnDockStateChanged(e);
  383. }
  384. private static readonly object DockStateChangedEvent = new object();
  385. [LocalizedCategory("Category_PropertyChanged")]
  386. [LocalizedDescription("Pane_DockStateChanged_Description")]
  387. public event EventHandler DockStateChanged
  388. {
  389. add
  390. {
  391. Events.AddHandler(DockStateChangedEvent, value);
  392. }
  393. remove
  394. {
  395. Events.RemoveHandler(DockStateChangedEvent, value);
  396. }
  397. }
  398. protected virtual void OnDockStateChanged(EventArgs e)
  399. {
  400. EventHandler handler = (EventHandler)Events[DockStateChangedEvent];
  401. if (handler != null)
  402. handler(this, e);
  403. }
  404. #endregion
  405. /// <summary>
  406. /// Overridden to avoid resize issues with nested controls
  407. /// </summary>
  408. /// <remarks>
  409. /// http://blogs.msdn.com/b/alejacma/archive/2008/11/20/controls-won-t-get-resized-once-the-nesting-hierarchy-of-windows-exceeds-a-certain-depth-x64.aspx
  410. /// http://support.microsoft.com/kb/953934
  411. /// </remarks>
  412. protected override void OnSizeChanged(EventArgs e)
  413. {
  414. if (DockPanel != null && DockPanel.SupportDeeplyNestedContent && IsHandleCreated)
  415. {
  416. BeginInvoke((MethodInvoker)delegate
  417. {
  418. base.OnSizeChanged(e);
  419. });
  420. }
  421. else
  422. {
  423. base.OnSizeChanged(e);
  424. }
  425. }
  426. }
  427. }