Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.1/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockContentCollection.cs @ 4537

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

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

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Collections.ObjectModel;
4
5namespace WeifenLuo.WinFormsUI.Docking {
6  public class DockContentCollection : ReadOnlyCollection<IDockContent> {
7    private static List<IDockContent> _emptyList = new List<IDockContent>(0);
8
9    internal DockContentCollection()
10      : base(new List<IDockContent>()) {
11    }
12
13    internal DockContentCollection(DockPane pane)
14      : base(_emptyList) {
15      m_dockPane = pane;
16    }
17
18    private DockPane m_dockPane = null;
19    private DockPane DockPane {
20      get { return m_dockPane; }
21    }
22
23    public new IDockContent this[int index] {
24      get {
25        if (DockPane == null)
26          return Items[index] as IDockContent;
27        else
28          return GetVisibleContent(index);
29      }
30    }
31
32    internal int Add(IDockContent content) {
33#if DEBUG
34      if (DockPane != null)
35        throw new InvalidOperationException();
36#endif
37
38      if (Contains(content))
39        return IndexOf(content);
40
41      Items.Add(content);
42      return Count - 1;
43    }
44
45    internal void AddAt(IDockContent content, int index) {
46#if DEBUG
47      if (DockPane != null)
48        throw new InvalidOperationException();
49#endif
50
51      if (index < 0 || index > Items.Count - 1)
52        return;
53
54      if (Contains(content))
55        return;
56
57      Items.Insert(index, content);
58    }
59
60    public new bool Contains(IDockContent content) {
61      if (DockPane == null)
62        return Items.Contains(content);
63      else
64        return (GetIndexOfVisibleContents(content) != -1);
65    }
66
67    public new int Count {
68      get {
69        if (DockPane == null)
70          return base.Count;
71        else
72          return CountOfVisibleContents;
73      }
74    }
75
76    public new int IndexOf(IDockContent content) {
77      if (DockPane == null) {
78        if (!Contains(content))
79          return -1;
80        else
81          return Items.IndexOf(content);
82      } else
83        return GetIndexOfVisibleContents(content);
84    }
85
86    internal void Remove(IDockContent content) {
87      if (DockPane != null)
88        throw new InvalidOperationException();
89
90      if (!Contains(content))
91        return;
92
93      Items.Remove(content);
94    }
95
96    private int CountOfVisibleContents {
97      get {
98#if DEBUG
99        if (DockPane == null)
100          throw new InvalidOperationException();
101#endif
102
103        int count = 0;
104        foreach (IDockContent content in DockPane.Contents) {
105          if (content.DockHandler.DockState == DockPane.DockState)
106            count++;
107        }
108        return count;
109      }
110    }
111
112    private IDockContent GetVisibleContent(int index) {
113#if DEBUG
114      if (DockPane == null)
115        throw new InvalidOperationException();
116#endif
117
118      int currentIndex = -1;
119      foreach (IDockContent content in DockPane.Contents) {
120        if (content.DockHandler.DockState == DockPane.DockState)
121          currentIndex++;
122
123        if (currentIndex == index)
124          return content;
125      }
126      throw (new ArgumentOutOfRangeException());
127    }
128
129    private int GetIndexOfVisibleContents(IDockContent content) {
130#if DEBUG
131      if (DockPane == null)
132        throw new InvalidOperationException();
133#endif
134
135      if (content == null)
136        return -1;
137
138      int index = -1;
139      foreach (IDockContent c in DockPane.Contents) {
140        if (c.DockHandler.DockState == DockPane.DockState) {
141          index++;
142
143          if (c == content)
144            return index;
145        }
146      }
147      return -1;
148    }
149  }
150}
Note: See TracBrowser for help on using the repository browser.