Example #1
0
            /// <summary>
            ///     移除一个子项
            /// </summary>
            /// <param name="subItem">要移除的子项</param>
            public void Remove(ChatListSubItem subItem)
            {
                int index = this.IndexOf(subItem);

                if (-1 != index)
                {
                    this.RemoveAt(index);
                }
            }
Example #2
0
        public override object ConvertTo(
            ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("DestinationType cannot be null");
            }
            //MessageBox.Show("Convertto OK");
            if (destinationType == typeof(InstanceDescriptor) && (value is ChatListItem))
            {
                ConstructorInfo   constructor = null;
                var               item        = (ChatListItem)value;
                ChatListSubItem[] subItems    = null;
                //MessageBox.Show("Convertto Start Item:" + item.Text);
                //MessageBox.Show("Item.SubItems.Count:" + item.SubItems.Count);
                if (item.SubItems.Count > 0)
                {
                    subItems = new ChatListSubItem[item.SubItems.Count];
                    item.SubItems.CopyTo(subItems, 0);
                }
                //MessageBox.Show("Item.SubItems.Count:" + item.SubItems.Count);
                if (item.Text != null && subItems != null)
                {
                    constructor =
                        typeof(ChatListItem).GetConstructor(new[] { typeof(string), typeof(ChatListSubItem[]) });
                }
                //MessageBox.Show("Constructor(Text,item[]):" + (constructor != null));
                if (constructor != null)
                {
                    return(new InstanceDescriptor(constructor, new object[] { item.Text, subItems }, false));
                }

                if (subItems != null)
                {
                    constructor = typeof(ChatListItem).GetConstructor(new[] { typeof(ChatListSubItem[]) });
                }
                if (constructor != null)
                {
                    return(new InstanceDescriptor(constructor, new object[] { subItems }, false));
                }
                if (item.Text != null)
                {
                    //MessageBox.Show("StartGetConstructor(text)");
                    constructor = typeof(ChatListItem).GetConstructor(new[] { typeof(string), typeof(bool) });
                }
                //MessageBox.Show("Constructor(Text):" + (constructor != null));
                if (constructor != null)
                {
                    //System.Windows.Forms.MessageBox.Show("text OK");
                    return(new InstanceDescriptor(constructor, new object[] { item.Text, item.IsOpen }));
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Example #3
0
 private void EnsureSpace(int elements)
 {
     if (this.m_arrSubItems == null)
     {
         this.m_arrSubItems = new ChatListSubItem[Math.Max(elements, 4)];
     }
     else if (elements + this.count > this.m_arrSubItems.Length)
     {
         var arrTemp = new ChatListSubItem[Math.Max(this.m_arrSubItems.Length * 2, elements + this.count)];
         this.m_arrSubItems.CopyTo(arrTemp, 0);
         this.m_arrSubItems = arrTemp;
     }
 }
Example #4
0
 /// <summary>
 ///     根据在线状态添加一个子项
 /// </summary>
 /// <param name="subItem">要添加的子项</param>
 public void AddAccordingToStatus(ChatListSubItem subItem)
 {
     if (subItem.Status == ChatListSubItem.UserStatus.OffLine)
     {
         this.Add(subItem);
         return;
     }
     for (int i = 0, len = this.count; i < len; i++)
     {
         if (subItem.Status <= this.m_arrSubItems[i].Status)
         {
             this.Insert(i, subItem);
             return;
         }
     }
     this.Add(subItem);
 }
Example #5
0
 /// <summary>
 ///     添加一个子项
 /// </summary>
 /// <param name="subItem">要添加的子项</param>
 public void Add(ChatListSubItem subItem)
 {
     if (subItem == null)
     {
         throw new ArgumentNullException("SubItem cannot be null");
     }
     this.EnsureSpace(1);
     if (-1 == this.IndexOf(subItem))
     {
         subItem.OwnerListItem            = this.owner;
         this.m_arrSubItems[this.count++] = subItem;
         if (this.owner.OwnerChatListBox != null)
         {
             this.owner.OwnerChatListBox.Invalidate();
         }
     }
 }
Example #6
0
 /// <summary>
 ///     根据索引插入一个子项
 /// </summary>
 /// <param name="index">索引位置</param>
 /// <param name="subItem">要插入的子项</param>
 public void Insert(int index, ChatListSubItem subItem)
 {
     if (index < 0 || index >= this.count)
     {
         throw new IndexOutOfRangeException("Index was outside the bounds of the array");
     }
     if (subItem == null)
     {
         throw new ArgumentNullException("SubItem cannot be null");
     }
     this.EnsureSpace(1);
     for (int i = this.count; i > index; i--)
     {
         this.m_arrSubItems[i] = this.m_arrSubItems[i - 1];
     }
     subItem.OwnerListItem     = this.owner;
     this.m_arrSubItems[index] = subItem;
     this.count++;
     if (this.owner.OwnerChatListBox != null)
     {
         this.owner.OwnerChatListBox.Invalidate();
     }
 }
Example #7
0
 /// <summary>
 ///     获取索引位置
 /// </summary>
 /// <param name="subItem">要获取索引的子项</param>
 /// <returns>索引</returns>
 public int IndexOf(ChatListSubItem subItem)
 {
     return(Array.IndexOf(this.m_arrSubItems, subItem));
 }
Example #8
0
 /// <summary>
 ///     判断子项是否在集合内
 /// </summary>
 /// <param name="subItem">要判断的子项</param>
 /// <returns>是否在集合内</returns>
 public bool Contains(ChatListSubItem subItem)
 {
     return(this.IndexOf(subItem) != -1);
 }