| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:DockContentCollection.cs
- * 2.功能描述:类文件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/01 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- namespace Dongke.IBOSS.PRD.Basics.DockPanel
- {
- public class DockContentCollection : ReadOnlyCollection<IDockContent>
- {
- private static List<IDockContent> _emptyList = new List<IDockContent>(0);
- internal DockContentCollection()
- : base(new List<IDockContent>())
- {
- }
- internal DockContentCollection(DockPane pane)
- : base(_emptyList)
- {
- m_dockPane = pane;
- }
- private DockPane m_dockPane = null;
- private DockPane DockPane
- {
- get
- {
- return m_dockPane;
- }
- }
- public new IDockContent this[int index]
- {
- get
- {
- if (DockPane == null)
- return Items[index] as IDockContent;
- else
- return GetVisibleContent(index);
- }
- }
- internal int Add(IDockContent content)
- {
- #if DEBUG
- if (DockPane != null)
- throw new InvalidOperationException();
- #endif
- if (Contains(content))
- return IndexOf(content);
- Items.Add(content);
- return Count - 1;
- }
- internal void AddAt(IDockContent content, int index)
- {
- #if DEBUG
- if (DockPane != null)
- throw new InvalidOperationException();
- #endif
- if (index < 0 || index > Items.Count - 1)
- return;
- if (Contains(content))
- return;
- Items.Insert(index, content);
- }
- public new bool Contains(IDockContent content)
- {
- if (DockPane == null)
- return Items.Contains(content);
- else
- return (GetIndexOfVisibleContents(content) != -1);
- }
- public new int Count
- {
- get
- {
- if (DockPane == null)
- return base.Count;
- else
- return CountOfVisibleContents;
- }
- }
- public new int IndexOf(IDockContent content)
- {
- if (DockPane == null)
- {
- if (!Contains(content))
- return -1;
- else
- return Items.IndexOf(content);
- }
- else
- return GetIndexOfVisibleContents(content);
- }
- internal void Remove(IDockContent content)
- {
- if (DockPane != null)
- throw new InvalidOperationException();
- if (!Contains(content))
- return;
- Items.Remove(content);
- }
- private int CountOfVisibleContents
- {
- get
- {
- #if DEBUG
- if (DockPane == null)
- throw new InvalidOperationException();
- #endif
- int count = 0;
- foreach (IDockContent content in DockPane.Contents)
- {
- if (content.DockHandler.DockState == DockPane.DockState)
- count++;
- }
- return count;
- }
- }
- private IDockContent GetVisibleContent(int index)
- {
- #if DEBUG
- if (DockPane == null)
- throw new InvalidOperationException();
- #endif
- int currentIndex = -1;
- foreach (IDockContent content in DockPane.Contents)
- {
- if (content.DockHandler.DockState == DockPane.DockState)
- currentIndex++;
- if (currentIndex == index)
- return content;
- }
- throw (new ArgumentOutOfRangeException());
- }
- private int GetIndexOfVisibleContents(IDockContent content)
- {
- #if DEBUG
- if (DockPane == null)
- throw new InvalidOperationException();
- #endif
- if (content == null)
- return -1;
- int index = -1;
- foreach (IDockContent c in DockPane.Contents)
- {
- if (c.DockHandler.DockState == DockPane.DockState)
- {
- index++;
- if (c == content)
- return index;
- }
- }
- return -1;
- }
- }
- }
|