Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DockContentCollection.cs @ 8616

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

#1939: Added DockPanelSuite 2.7.0 to ExtLibs.

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