Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPanel.cs

Last change on this file was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 29.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Diagnostics.CodeAnalysis;
5using System.Drawing;
6using System.Windows.Forms;
7
8// To simplify the process of finding the toolbox bitmap resource:
9// #1 Create an internal class called "resfinder" outside of the root namespace.
10// #2 Use "resfinder" in the toolbox bitmap attribute instead of the control name.
11// #3 use the "<default namespace>.<resourcename>" string to locate the resource.
12// See: http://www.bobpowell.net/toolboxbitmap.htm
13internal class resfinder {
14}
15
16namespace WeifenLuo.WinFormsUI.Docking {
17  [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters", MessageId = "0#")]
18  public delegate IDockContent DeserializeDockContent(string persistString);
19
20  [LocalizedDescription("DockPanel_Description")]
21  [Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
22  [ToolboxBitmap(typeof(resfinder), "WeifenLuo.WinFormsUI.Docking.DockPanel.bmp")]
23  [DefaultProperty("DocumentStyle")]
24  [DefaultEvent("ActiveContentChanged")]
25  public partial class DockPanel : Panel {
26    private FocusManagerImpl m_focusManager;
27    private DockPanelExtender m_extender;
28    private DockPaneCollection m_panes;
29    private FloatWindowCollection m_floatWindows;
30    private AutoHideWindowControl m_autoHideWindow;
31    private DockWindowCollection m_dockWindows;
32    private DockContent m_dummyContent;
33    private Control m_dummyControl;
34
35    public DockPanel() {
36      m_focusManager = new FocusManagerImpl(this);
37      m_extender = new DockPanelExtender(this);
38      m_panes = new DockPaneCollection();
39      m_floatWindows = new FloatWindowCollection();
40
41      SuspendLayout();
42
43      m_autoHideWindow = new AutoHideWindowControl(this);
44      m_autoHideWindow.Visible = false;
45      SetAutoHideWindowParent();
46
47      m_dummyControl = new DummyControl();
48      m_dummyControl.Bounds = new Rectangle(0, 0, 1, 1);
49      Controls.Add(m_dummyControl);
50
51      m_dockWindows = new DockWindowCollection(this);
52      Controls.AddRange(new Control[] {
53        DockWindows[DockState.Document],
54        DockWindows[DockState.DockLeft],
55        DockWindows[DockState.DockRight],
56        DockWindows[DockState.DockTop],
57        DockWindows[DockState.DockBottom]
58        });
59
60      m_dummyContent = new DockContent();
61      ResumeLayout();
62    }
63
64    private Color m_BackColor;
65    /// <summary>
66    /// Determines the color with which the client rectangle will be drawn.
67    /// If you take this property instead of the BackColor it will not have any influence on the borders to the surrounding controls (DockPane).
68    /// If you use BackColor the borders to the surrounding controls (DockPane) will also change there colors.
69    /// Alternatively you can use both of them (BackColor to draw the define the color of the borders and DockBackColor to define the color of the client rectangle).
70    /// For Backgroundimages: Set your prefered Image, then set the DockBackColor and the BackColor to the same Color (Control)
71    /// </summary>
72    public Color DockBackColor {
73      get {
74        return !m_BackColor.IsEmpty ? m_BackColor : base.BackColor;
75      }
76      set {
77        m_BackColor = value;
78      }
79    }
80
81    private AutoHideStripBase m_autoHideStripControl = null;
82    internal AutoHideStripBase AutoHideStripControl {
83      get {
84        if (m_autoHideStripControl == null) {
85          m_autoHideStripControl = AutoHideStripFactory.CreateAutoHideStrip(this);
86          Controls.Add(m_autoHideStripControl);
87        }
88        return m_autoHideStripControl;
89      }
90    }
91    internal void ResetAutoHideStripControl() {
92      if (m_autoHideStripControl != null)
93        m_autoHideStripControl.Dispose();
94
95      m_autoHideStripControl = null;
96    }
97
98    private void MdiClientHandleAssigned(object sender, EventArgs e) {
99      SetMdiClient();
100      PerformLayout();
101    }
102
103    private void MdiClient_Layout(object sender, LayoutEventArgs e) {
104      if (DocumentStyle != DocumentStyle.DockingMdi)
105        return;
106
107      foreach (DockPane pane in Panes)
108        if (pane.DockState == DockState.Document)
109          pane.SetContentBounds();
110
111      InvalidateWindowRegion();
112    }
113
114    private bool m_disposed = false;
115    protected override void Dispose(bool disposing) {
116      lock (this) {
117        if (!m_disposed && disposing) {
118          m_focusManager.Dispose();
119          if (m_mdiClientController != null) {
120            m_mdiClientController.HandleAssigned -= new EventHandler(MdiClientHandleAssigned);
121            m_mdiClientController.MdiChildActivate -= new EventHandler(ParentFormMdiChildActivate);
122            m_mdiClientController.Layout -= new LayoutEventHandler(MdiClient_Layout);
123            m_mdiClientController.Dispose();
124          }
125          FloatWindows.Dispose();
126          Panes.Dispose();
127          DummyContent.Dispose();
128
129          m_disposed = true;
130        }
131
132        base.Dispose(disposing);
133      }
134    }
135
136    [Browsable(false)]
137    public IDockContent ActiveAutoHideContent {
138      get { return AutoHideWindow.ActiveContent; }
139      set { AutoHideWindow.ActiveContent = value; }
140    }
141
142    private bool m_allowEndUserDocking = true;
143    [LocalizedCategory("Category_Docking")]
144    [LocalizedDescription("DockPanel_AllowEndUserDocking_Description")]
145    [DefaultValue(true)]
146    public bool AllowEndUserDocking {
147      get { return m_allowEndUserDocking; }
148      set { m_allowEndUserDocking = value; }
149    }
150
151    private bool m_allowEndUserNestedDocking = true;
152    [LocalizedCategory("Category_Docking")]
153    [LocalizedDescription("DockPanel_AllowEndUserNestedDocking_Description")]
154    [DefaultValue(true)]
155    public bool AllowEndUserNestedDocking {
156      get { return m_allowEndUserNestedDocking; }
157      set { m_allowEndUserNestedDocking = value; }
158    }
159
160    private DockContentCollection m_contents = new DockContentCollection();
161    [Browsable(false)]
162    public DockContentCollection Contents {
163      get { return m_contents; }
164    }
165
166    internal DockContent DummyContent {
167      get { return m_dummyContent; }
168    }
169
170    private bool m_rightToLeftLayout = false;
171    [DefaultValue(false)]
172    [LocalizedCategory("Appearance")]
173    [LocalizedDescription("DockPanel_RightToLeftLayout_Description")]
174    public bool RightToLeftLayout {
175      get { return m_rightToLeftLayout; }
176      set {
177        if (m_rightToLeftLayout == value)
178          return;
179
180        m_rightToLeftLayout = value;
181        foreach (FloatWindow floatWindow in FloatWindows)
182          floatWindow.RightToLeftLayout = value;
183      }
184    }
185
186    protected override void OnRightToLeftChanged(EventArgs e) {
187      base.OnRightToLeftChanged(e);
188      foreach (FloatWindow floatWindow in FloatWindows) {
189        if (floatWindow.RightToLeft != RightToLeft)
190          floatWindow.RightToLeft = RightToLeft;
191      }
192    }
193
194    private bool m_showDocumentIcon = false;
195    [DefaultValue(false)]
196    [LocalizedCategory("Category_Docking")]
197    [LocalizedDescription("DockPanel_ShowDocumentIcon_Description")]
198    public bool ShowDocumentIcon {
199      get { return m_showDocumentIcon; }
200      set {
201        if (m_showDocumentIcon == value)
202          return;
203
204        m_showDocumentIcon = value;
205        Refresh();
206      }
207    }
208
209    private DockPanelSkin m_dockPanelSkin = new DockPanelSkin();
210    [LocalizedCategory("Category_Docking")]
211    [LocalizedDescription("DockPanel_DockPanelSkin")]
212    public DockPanelSkin Skin {
213      get { return m_dockPanelSkin; }
214      set { m_dockPanelSkin = value; }
215    }
216
217    private DocumentTabStripLocation m_documentTabStripLocation = DocumentTabStripLocation.Top;
218    [DefaultValue(DocumentTabStripLocation.Top)]
219    [LocalizedCategory("Category_Docking")]
220    [LocalizedDescription("DockPanel_DocumentTabStripLocation")]
221    public DocumentTabStripLocation DocumentTabStripLocation {
222      get { return m_documentTabStripLocation; }
223      set { m_documentTabStripLocation = value; }
224    }
225
226    [Browsable(false)]
227    public DockPanelExtender Extender {
228      get { return m_extender; }
229    }
230
231    public DockPanelExtender.IDockPaneFactory DockPaneFactory {
232      get { return Extender.DockPaneFactory; }
233    }
234
235    public DockPanelExtender.IFloatWindowFactory FloatWindowFactory {
236      get { return Extender.FloatWindowFactory; }
237    }
238
239    internal DockPanelExtender.IDockPaneCaptionFactory DockPaneCaptionFactory {
240      get { return Extender.DockPaneCaptionFactory; }
241    }
242
243    internal DockPanelExtender.IDockPaneStripFactory DockPaneStripFactory {
244      get { return Extender.DockPaneStripFactory; }
245    }
246
247    internal DockPanelExtender.IAutoHideStripFactory AutoHideStripFactory {
248      get { return Extender.AutoHideStripFactory; }
249    }
250
251    [Browsable(false)]
252    public DockPaneCollection Panes {
253      get { return m_panes; }
254    }
255
256    internal Rectangle DockArea {
257      get {
258        return new Rectangle(DockPadding.Left, DockPadding.Top,
259          ClientRectangle.Width - DockPadding.Left - DockPadding.Right,
260          ClientRectangle.Height - DockPadding.Top - DockPadding.Bottom);
261      }
262    }
263
264    private double m_dockBottomPortion = 0.25;
265    [LocalizedCategory("Category_Docking")]
266    [LocalizedDescription("DockPanel_DockBottomPortion_Description")]
267    [DefaultValue(0.25)]
268    public double DockBottomPortion {
269      get { return m_dockBottomPortion; }
270      set {
271        if (value <= 0)
272          throw new ArgumentOutOfRangeException("value");
273
274        if (value == m_dockBottomPortion)
275          return;
276
277        m_dockBottomPortion = value;
278
279        if (m_dockBottomPortion < 1 && m_dockTopPortion < 1) {
280          if (m_dockTopPortion + m_dockBottomPortion > 1)
281            m_dockTopPortion = 1 - m_dockBottomPortion;
282        }
283
284        PerformLayout();
285      }
286    }
287
288    private double m_dockLeftPortion = 0.25;
289    [LocalizedCategory("Category_Docking")]
290    [LocalizedDescription("DockPanel_DockLeftPortion_Description")]
291    [DefaultValue(0.25)]
292    public double DockLeftPortion {
293      get { return m_dockLeftPortion; }
294      set {
295        if (value <= 0)
296          throw new ArgumentOutOfRangeException("value");
297
298        if (value == m_dockLeftPortion)
299          return;
300
301        m_dockLeftPortion = value;
302
303        if (m_dockLeftPortion < 1 && m_dockRightPortion < 1) {
304          if (m_dockLeftPortion + m_dockRightPortion > 1)
305            m_dockRightPortion = 1 - m_dockLeftPortion;
306        }
307        PerformLayout();
308      }
309    }
310
311    private double m_dockRightPortion = 0.25;
312    [LocalizedCategory("Category_Docking")]
313    [LocalizedDescription("DockPanel_DockRightPortion_Description")]
314    [DefaultValue(0.25)]
315    public double DockRightPortion {
316      get { return m_dockRightPortion; }
317      set {
318        if (value <= 0)
319          throw new ArgumentOutOfRangeException("value");
320
321        if (value == m_dockRightPortion)
322          return;
323
324        m_dockRightPortion = value;
325
326        if (m_dockLeftPortion < 1 && m_dockRightPortion < 1) {
327          if (m_dockLeftPortion + m_dockRightPortion > 1)
328            m_dockLeftPortion = 1 - m_dockRightPortion;
329        }
330        PerformLayout();
331      }
332    }
333
334    private double m_dockTopPortion = 0.25;
335    [LocalizedCategory("Category_Docking")]
336    [LocalizedDescription("DockPanel_DockTopPortion_Description")]
337    [DefaultValue(0.25)]
338    public double DockTopPortion {
339      get { return m_dockTopPortion; }
340      set {
341        if (value <= 0)
342          throw new ArgumentOutOfRangeException("value");
343
344        if (value == m_dockTopPortion)
345          return;
346
347        m_dockTopPortion = value;
348
349        if (m_dockTopPortion < 1 && m_dockBottomPortion < 1) {
350          if (m_dockTopPortion + m_dockBottomPortion > 1)
351            m_dockBottomPortion = 1 - m_dockTopPortion;
352        }
353        PerformLayout();
354      }
355    }
356
357    [Browsable(false)]
358    public DockWindowCollection DockWindows {
359      get { return m_dockWindows; }
360    }
361
362    public void UpdateDockWindowZOrder(DockStyle dockStyle, bool fullPanelEdge) {
363      if (dockStyle == DockStyle.Left) {
364        if (fullPanelEdge)
365          DockWindows[DockState.DockLeft].SendToBack();
366        else
367          DockWindows[DockState.DockLeft].BringToFront();
368      } else if (dockStyle == DockStyle.Right) {
369        if (fullPanelEdge)
370          DockWindows[DockState.DockRight].SendToBack();
371        else
372          DockWindows[DockState.DockRight].BringToFront();
373      } else if (dockStyle == DockStyle.Top) {
374        if (fullPanelEdge)
375          DockWindows[DockState.DockTop].SendToBack();
376        else
377          DockWindows[DockState.DockTop].BringToFront();
378      } else if (dockStyle == DockStyle.Bottom) {
379        if (fullPanelEdge)
380          DockWindows[DockState.DockBottom].SendToBack();
381        else
382          DockWindows[DockState.DockBottom].BringToFront();
383      }
384    }
385
386    public int DocumentsCount {
387      get {
388        int count = 0;
389        foreach (IDockContent content in Documents)
390          count++;
391
392        return count;
393      }
394    }
395
396    public IDockContent[] DocumentsToArray() {
397      int count = DocumentsCount;
398      IDockContent[] documents = new IDockContent[count];
399      int i = 0;
400      foreach (IDockContent content in Documents) {
401        documents[i] = content;
402        i++;
403      }
404
405      return documents;
406    }
407
408    public IEnumerable<IDockContent> Documents {
409      get {
410        foreach (IDockContent content in Contents) {
411          if (content.DockHandler.DockState == DockState.Document)
412            yield return content;
413        }
414      }
415    }
416
417    private Rectangle DocumentRectangle {
418      get {
419        Rectangle rect = DockArea;
420        if (DockWindows[DockState.DockLeft].VisibleNestedPanes.Count != 0) {
421          rect.X += (int)(DockArea.Width * DockLeftPortion);
422          rect.Width -= (int)(DockArea.Width * DockLeftPortion);
423        }
424        if (DockWindows[DockState.DockRight].VisibleNestedPanes.Count != 0)
425          rect.Width -= (int)(DockArea.Width * DockRightPortion);
426        if (DockWindows[DockState.DockTop].VisibleNestedPanes.Count != 0) {
427          rect.Y += (int)(DockArea.Height * DockTopPortion);
428          rect.Height -= (int)(DockArea.Height * DockTopPortion);
429        }
430        if (DockWindows[DockState.DockBottom].VisibleNestedPanes.Count != 0)
431          rect.Height -= (int)(DockArea.Height * DockBottomPortion);
432
433        return rect;
434      }
435    }
436
437    private Control DummyControl {
438      get { return m_dummyControl; }
439    }
440
441    [Browsable(false)]
442    public FloatWindowCollection FloatWindows {
443      get { return m_floatWindows; }
444    }
445
446    private Size m_defaultFloatWindowSize = new Size(300, 300);
447    [Category("Layout")]
448    [LocalizedDescription("DockPanel_DefaultFloatWindowSize_Description")]
449    public Size DefaultFloatWindowSize {
450      get { return m_defaultFloatWindowSize; }
451      set { m_defaultFloatWindowSize = value; }
452    }
453    private bool ShouldSerializeDefaultFloatWindowSize() {
454      return DefaultFloatWindowSize != new Size(300, 300);
455    }
456
457    private DocumentStyle m_documentStyle = DocumentStyle.DockingMdi;
458    [LocalizedCategory("Category_Docking")]
459    [LocalizedDescription("DockPanel_DocumentStyle_Description")]
460    [DefaultValue(DocumentStyle.DockingMdi)]
461    public DocumentStyle DocumentStyle {
462      get { return m_documentStyle; }
463      set {
464        if (value == m_documentStyle)
465          return;
466
467        if (!Enum.IsDefined(typeof(DocumentStyle), value))
468          throw new InvalidEnumArgumentException();
469
470        if (value == DocumentStyle.SystemMdi && DockWindows[DockState.Document].VisibleNestedPanes.Count > 0)
471          throw new InvalidEnumArgumentException();
472
473        m_documentStyle = value;
474
475        SuspendLayout(true);
476
477        SetAutoHideWindowParent();
478        SetMdiClient();
479        InvalidateWindowRegion();
480
481        foreach (IDockContent content in Contents) {
482          if (content.DockHandler.DockState == DockState.Document)
483            content.DockHandler.SetPaneAndVisible(content.DockHandler.Pane);
484        }
485
486        PerformMdiClientLayout();
487
488        ResumeLayout(true, true);
489      }
490    }
491
492    private int GetDockWindowSize(DockState dockState) {
493      if (dockState == DockState.DockLeft || dockState == DockState.DockRight) {
494        int width = ClientRectangle.Width - DockPadding.Left - DockPadding.Right;
495        int dockLeftSize = m_dockLeftPortion >= 1 ? (int)m_dockLeftPortion : (int)(width * m_dockLeftPortion);
496        int dockRightSize = m_dockRightPortion >= 1 ? (int)m_dockRightPortion : (int)(width * m_dockRightPortion);
497
498        if (dockLeftSize < MeasurePane.MinSize)
499          dockLeftSize = MeasurePane.MinSize;
500        if (dockRightSize < MeasurePane.MinSize)
501          dockRightSize = MeasurePane.MinSize;
502
503        if (dockLeftSize + dockRightSize > width - MeasurePane.MinSize) {
504          int adjust = (dockLeftSize + dockRightSize) - (width - MeasurePane.MinSize);
505          dockLeftSize -= adjust / 2;
506          dockRightSize -= adjust / 2;
507        }
508
509        return dockState == DockState.DockLeft ? dockLeftSize : dockRightSize;
510      } else if (dockState == DockState.DockTop || dockState == DockState.DockBottom) {
511        int height = ClientRectangle.Height - DockPadding.Top - DockPadding.Bottom;
512        int dockTopSize = m_dockTopPortion >= 1 ? (int)m_dockTopPortion : (int)(height * m_dockTopPortion);
513        int dockBottomSize = m_dockBottomPortion >= 1 ? (int)m_dockBottomPortion : (int)(height * m_dockBottomPortion);
514
515        if (dockTopSize < MeasurePane.MinSize)
516          dockTopSize = MeasurePane.MinSize;
517        if (dockBottomSize < MeasurePane.MinSize)
518          dockBottomSize = MeasurePane.MinSize;
519
520        if (dockTopSize + dockBottomSize > height - MeasurePane.MinSize) {
521          int adjust = (dockTopSize + dockBottomSize) - (height - MeasurePane.MinSize);
522          dockTopSize -= adjust / 2;
523          dockBottomSize -= adjust / 2;
524        }
525
526        return dockState == DockState.DockTop ? dockTopSize : dockBottomSize;
527      } else
528        return 0;
529    }
530
531    protected override void OnLayout(LayoutEventArgs levent) {
532      SuspendLayout(true);
533
534      AutoHideStripControl.Bounds = ClientRectangle;
535
536      CalculateDockPadding();
537
538      DockWindows[DockState.DockLeft].Width = GetDockWindowSize(DockState.DockLeft);
539      DockWindows[DockState.DockRight].Width = GetDockWindowSize(DockState.DockRight);
540      DockWindows[DockState.DockTop].Height = GetDockWindowSize(DockState.DockTop);
541      DockWindows[DockState.DockBottom].Height = GetDockWindowSize(DockState.DockBottom);
542
543      AutoHideWindow.Bounds = GetAutoHideWindowBounds(AutoHideWindowRectangle);
544
545      DockWindows[DockState.Document].BringToFront();
546      AutoHideWindow.BringToFront();
547
548      base.OnLayout(levent);
549
550      if (DocumentStyle == DocumentStyle.SystemMdi && MdiClientExists) {
551        SetMdiClientBounds(SystemMdiClientBounds);
552        InvalidateWindowRegion();
553      } else if (DocumentStyle == DocumentStyle.DockingMdi)
554        InvalidateWindowRegion();
555
556      ResumeLayout(true, true);
557    }
558
559    internal Rectangle GetTabStripRectangle(DockState dockState) {
560      return AutoHideStripControl.GetTabStripRectangle(dockState);
561    }
562
563    protected override void OnPaint(PaintEventArgs e) {
564      base.OnPaint(e);
565
566      if (DockBackColor == BackColor) return;
567
568      Graphics g = e.Graphics;
569      SolidBrush bgBrush = new SolidBrush(DockBackColor);
570      g.FillRectangle(bgBrush, ClientRectangle);
571    }
572
573    internal void AddContent(IDockContent content) {
574      if (content == null)
575        throw (new ArgumentNullException());
576
577      if (!Contents.Contains(content)) {
578        Contents.Add(content);
579        OnContentAdded(new DockContentEventArgs(content));
580      }
581    }
582
583    internal void AddPane(DockPane pane) {
584      if (Panes.Contains(pane))
585        return;
586
587      Panes.Add(pane);
588    }
589
590    internal void AddFloatWindow(FloatWindow floatWindow) {
591      if (FloatWindows.Contains(floatWindow))
592        return;
593
594      FloatWindows.Add(floatWindow);
595    }
596
597    private void CalculateDockPadding() {
598      DockPadding.All = 0;
599
600      int height = AutoHideStripControl.MeasureHeight();
601
602      if (AutoHideStripControl.GetNumberOfPanes(DockState.DockLeftAutoHide) > 0)
603        DockPadding.Left = height;
604      if (AutoHideStripControl.GetNumberOfPanes(DockState.DockRightAutoHide) > 0)
605        DockPadding.Right = height;
606      if (AutoHideStripControl.GetNumberOfPanes(DockState.DockTopAutoHide) > 0)
607        DockPadding.Top = height;
608      if (AutoHideStripControl.GetNumberOfPanes(DockState.DockBottomAutoHide) > 0)
609        DockPadding.Bottom = height;
610    }
611
612    internal void RemoveContent(IDockContent content) {
613      if (content == null)
614        throw (new ArgumentNullException());
615
616      if (Contents.Contains(content)) {
617        Contents.Remove(content);
618        OnContentRemoved(new DockContentEventArgs(content));
619      }
620    }
621
622    internal void RemovePane(DockPane pane) {
623      if (!Panes.Contains(pane))
624        return;
625
626      Panes.Remove(pane);
627    }
628
629    internal void RemoveFloatWindow(FloatWindow floatWindow) {
630      if (!FloatWindows.Contains(floatWindow))
631        return;
632
633      FloatWindows.Remove(floatWindow);
634    }
635
636    public void SetPaneIndex(DockPane pane, int index) {
637      int oldIndex = Panes.IndexOf(pane);
638      if (oldIndex == -1)
639        throw (new ArgumentException(Strings.DockPanel_SetPaneIndex_InvalidPane));
640
641      if (index < 0 || index > Panes.Count - 1)
642        if (index != -1)
643          throw (new ArgumentOutOfRangeException(Strings.DockPanel_SetPaneIndex_InvalidIndex));
644
645      if (oldIndex == index)
646        return;
647      if (oldIndex == Panes.Count - 1 && index == -1)
648        return;
649
650      Panes.Remove(pane);
651      if (index == -1)
652        Panes.Add(pane);
653      else if (oldIndex < index)
654        Panes.AddAt(pane, index - 1);
655      else
656        Panes.AddAt(pane, index);
657    }
658
659    public void SuspendLayout(bool allWindows) {
660      FocusManager.SuspendFocusTracking();
661      SuspendLayout();
662      if (allWindows)
663        SuspendMdiClientLayout();
664    }
665
666    public void ResumeLayout(bool performLayout, bool allWindows) {
667      FocusManager.ResumeFocusTracking();
668      ResumeLayout(performLayout);
669      if (allWindows)
670        ResumeMdiClientLayout(performLayout);
671    }
672
673    internal Form ParentForm {
674      get {
675        if (!IsParentFormValid())
676          throw new InvalidOperationException(Strings.DockPanel_ParentForm_Invalid);
677
678        return GetMdiClientController().ParentForm;
679      }
680    }
681
682    private bool IsParentFormValid() {
683      if (DocumentStyle == DocumentStyle.DockingSdi || DocumentStyle == DocumentStyle.DockingWindow)
684        return true;
685
686      if (!MdiClientExists)
687        GetMdiClientController().RenewMdiClient();
688
689      return (MdiClientExists);
690    }
691
692    protected override void OnParentChanged(EventArgs e) {
693      SetAutoHideWindowParent();
694      GetMdiClientController().ParentForm = (this.Parent as Form);
695      base.OnParentChanged(e);
696    }
697
698    private void SetAutoHideWindowParent() {
699      Control parent;
700      if (DocumentStyle == DocumentStyle.DockingMdi ||
701          DocumentStyle == DocumentStyle.SystemMdi)
702        parent = this.Parent;
703      else
704        parent = this;
705      if (AutoHideWindow.Parent != parent) {
706        AutoHideWindow.Parent = parent;
707        AutoHideWindow.BringToFront();
708      }
709    }
710
711    protected override void OnVisibleChanged(EventArgs e) {
712      base.OnVisibleChanged(e);
713
714      if (Visible)
715        SetMdiClient();
716    }
717
718    private Rectangle SystemMdiClientBounds {
719      get {
720        if (!IsParentFormValid() || !Visible)
721          return Rectangle.Empty;
722
723        Rectangle rect = ParentForm.RectangleToClient(RectangleToScreen(DocumentWindowBounds));
724        return rect;
725      }
726    }
727
728    internal Rectangle DocumentWindowBounds {
729      get {
730        Rectangle rectDocumentBounds = DisplayRectangle;
731        if (DockWindows[DockState.DockLeft].Visible) {
732          rectDocumentBounds.X += DockWindows[DockState.DockLeft].Width;
733          rectDocumentBounds.Width -= DockWindows[DockState.DockLeft].Width;
734        }
735        if (DockWindows[DockState.DockRight].Visible)
736          rectDocumentBounds.Width -= DockWindows[DockState.DockRight].Width;
737        if (DockWindows[DockState.DockTop].Visible) {
738          rectDocumentBounds.Y += DockWindows[DockState.DockTop].Height;
739          rectDocumentBounds.Height -= DockWindows[DockState.DockTop].Height;
740        }
741        if (DockWindows[DockState.DockBottom].Visible)
742          rectDocumentBounds.Height -= DockWindows[DockState.DockBottom].Height;
743
744        return rectDocumentBounds;
745
746      }
747    }
748
749    private PaintEventHandler m_dummyControlPaintEventHandler = null;
750    private void InvalidateWindowRegion() {
751      if (DesignMode)
752        return;
753
754      if (m_dummyControlPaintEventHandler == null)
755        m_dummyControlPaintEventHandler = new PaintEventHandler(DummyControl_Paint);
756
757      DummyControl.Paint += m_dummyControlPaintEventHandler;
758      DummyControl.Invalidate();
759    }
760
761    void DummyControl_Paint(object sender, PaintEventArgs e) {
762      DummyControl.Paint -= m_dummyControlPaintEventHandler;
763      UpdateWindowRegion();
764    }
765
766    private void UpdateWindowRegion() {
767      if (this.DocumentStyle == DocumentStyle.DockingMdi)
768        UpdateWindowRegion_ClipContent();
769      else if (this.DocumentStyle == DocumentStyle.DockingSdi ||
770        this.DocumentStyle == DocumentStyle.DockingWindow)
771        UpdateWindowRegion_FullDocumentArea();
772      else if (this.DocumentStyle == DocumentStyle.SystemMdi)
773        UpdateWindowRegion_EmptyDocumentArea();
774    }
775
776    private void UpdateWindowRegion_FullDocumentArea() {
777      SetRegion(null);
778    }
779
780    private void UpdateWindowRegion_EmptyDocumentArea() {
781      Rectangle rect = DocumentWindowBounds;
782      SetRegion(new Rectangle[] { rect });
783    }
784
785    private void UpdateWindowRegion_ClipContent() {
786      int count = 0;
787      foreach (DockPane pane in this.Panes) {
788        if (!pane.Visible || pane.DockState != DockState.Document)
789          continue;
790
791        count++;
792      }
793
794      if (count == 0) {
795        SetRegion(null);
796        return;
797      }
798
799      Rectangle[] rects = new Rectangle[count];
800      int i = 0;
801      foreach (DockPane pane in this.Panes) {
802        if (!pane.Visible || pane.DockState != DockState.Document)
803          continue;
804
805        rects[i] = RectangleToClient(pane.RectangleToScreen(pane.ContentRectangle));
806        i++;
807      }
808
809      SetRegion(rects);
810    }
811
812    private Rectangle[] m_clipRects = null;
813    private void SetRegion(Rectangle[] clipRects) {
814      if (!IsClipRectsChanged(clipRects))
815        return;
816
817      m_clipRects = clipRects;
818
819      if (m_clipRects == null || m_clipRects.GetLength(0) == 0)
820        Region = null;
821      else {
822        Region region = new Region(new Rectangle(0, 0, this.Width, this.Height));
823        foreach (Rectangle rect in m_clipRects)
824          region.Exclude(rect);
825        Region = region;
826      }
827    }
828
829    private bool IsClipRectsChanged(Rectangle[] clipRects) {
830      if (clipRects == null && m_clipRects == null)
831        return false;
832      else if ((clipRects == null) != (m_clipRects == null))
833        return true;
834
835      foreach (Rectangle rect in clipRects) {
836        bool matched = false;
837        foreach (Rectangle rect2 in m_clipRects) {
838          if (rect == rect2) {
839            matched = true;
840            break;
841          }
842        }
843        if (!matched)
844          return true;
845      }
846
847      foreach (Rectangle rect2 in m_clipRects) {
848        bool matched = false;
849        foreach (Rectangle rect in clipRects) {
850          if (rect == rect2) {
851            matched = true;
852            break;
853          }
854        }
855        if (!matched)
856          return true;
857      }
858      return false;
859    }
860
861    private static readonly object ContentAddedEvent = new object();
862    [LocalizedCategory("Category_DockingNotification")]
863    [LocalizedDescription("DockPanel_ContentAdded_Description")]
864    public event EventHandler<DockContentEventArgs> ContentAdded {
865      add { Events.AddHandler(ContentAddedEvent, value); }
866      remove { Events.RemoveHandler(ContentAddedEvent, value); }
867    }
868    protected virtual void OnContentAdded(DockContentEventArgs e) {
869      EventHandler<DockContentEventArgs> handler = (EventHandler<DockContentEventArgs>)Events[ContentAddedEvent];
870      if (handler != null)
871        handler(this, e);
872    }
873
874    private static readonly object ContentRemovedEvent = new object();
875    [LocalizedCategory("Category_DockingNotification")]
876    [LocalizedDescription("DockPanel_ContentRemoved_Description")]
877    public event EventHandler<DockContentEventArgs> ContentRemoved {
878      add { Events.AddHandler(ContentRemovedEvent, value); }
879      remove { Events.RemoveHandler(ContentRemovedEvent, value); }
880    }
881    protected virtual void OnContentRemoved(DockContentEventArgs e) {
882      EventHandler<DockContentEventArgs> handler = (EventHandler<DockContentEventArgs>)Events[ContentRemovedEvent];
883      if (handler != null)
884        handler(this, e);
885    }
886  }
887}
Note: See TracBrowser for help on using the repository browser.