Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Mainform refactoring/WinFormsUI/Docking/DockPanel.cs @ 2426

Last change on this file since 2426 was 2134, checked in by gkronber, 15 years ago

Added up to date source of Weifen Luo dock panel suit in a separate project (and added strong name key). Removed binary versions of Weifen Luo dock panel suite and references to it. #687 (Update AdvancedOptimizationFrontend to use more recent version of Weifen Luo Docking library)

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