Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DockPanel.cs @ 18190

Last change on this file since 18190 was 8616, checked in by mkommend, 12 years ago

#1939: Added DockPanelSuite 2.7.0 to ExtLibs.

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