www.pudn.com > Fetion.rar > InviteControl.cs


namespace Imps.Client.Pc 
{ 
    using Imps.Client; 
    using Imps.Client.Core; 
    using Imps.Client.Pc.BizControls; 
    using Imps.Client.Pc.Controls; 
    using Imps.Client.Resource; 
    using Imps.Client.Utils; 
    using Imps.Client.Utils.Win32; 
    using Imps.Common; 
    using Imps.Utils; 
    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Runtime.CompilerServices; 
    using System.Windows.Forms; 
 
    public class InviteControl : UserControl 
    { 
        private List _excludeContacts; 
        private IFrameworkWindow _framework; 
        private ContactMatchHelper _matchHelper; 
        private int _maxSelectedCount; 
        private bool _onlyShowOnline; 
        private bool _searchTextboxAtTop; 
        private List _selectedContacts; 
        private SelectContactsType _selectType; 
        private bool _showGroup; 
        private bool _showJ2MER1; 
        private bool _showMobileBuddy; 
        private bool _showSelf; 
        private bool _showSMSOffline; 
        private bool _showSMSOnline; 
        private bool _showSymbianR1; 
        private IContainer components; 
        public string emptyText; 
        private bool fireByFunction; 
        private FlowLayoutPanel flowPanlContacts; 
        private int lastCheckIndex; 
        private Label lblMessage; 
        private Label lblNoneContacts; 
        private Label lblSelectInfo; 
        private Label lbSpace; 
        private Imps.Client.Core.Contact me; 
        private ToolStripMenuItem menuDelete; 
        private menu_widget menuOperation; 
        private Panel panel1; 
        private Panel panel2; 
        private Panel pnlOnlyForBorderShit; 
        private BListControlToolbar toolbarSearch; 
        private BuddySelectionTree treeContacts; 
        private XTextBox txtSearch; 
        private XSplitContainer xSplitContainer; 
 
        public event EventHandler SelectedContactsChanged; 
 
        public event EventHandler SplitterMoved; 
 
        public InviteControl(IFrameworkWindow framework) : this(framework, null) 
        { 
        } 
 
        public InviteControl(IFrameworkWindow framework, List selectedContacts) : this(framework, selectedContacts, null) 
        { 
        } 
 
        public InviteControl(IFrameworkWindow framework, List selectedContacts, List excludeContacts) : this(framework, selectedContacts, excludeContacts, SelectContactsType.None) 
        { 
        } 
 
        public InviteControl(IFrameworkWindow framework, List selectedContacts, List excludeContacts, SelectContactsType selectType) 
        { 
            this._showGroup = true; 
            this._maxSelectedCount = 0x7fffffff; 
            this._showJ2MER1 = true; 
            this._showSymbianR1 = true; 
            this._showSMSOffline = true; 
            this.emptyText = StringTable.Contact.ContactSearchEmptyText; 
            this.lastCheckIndex = -1; 
            this.InitializeComponent(); 
            this.txtSearch = this.toolbarSearch.SearchTextBox; 
            this._selectType = selectType; 
            this._framework = framework; 
            this._selectedContacts = selectedContacts; 
            this._excludeContacts = excludeContacts; 
            this.xSplitContainer.SplitterMoved += new SplitterEventHandler(this.xSplitContainer_SplitterMoved); 
            base.GotFocus += new EventHandler(this.InviteControl_GotFocus); 
            this.flowPanlContacts.ControlAdded += new ControlEventHandler(this.flowPanlContacts_ControlsChanged); 
            this.flowPanlContacts.ControlRemoved += new ControlEventHandler(this.flowPanlContacts_ControlsChanged); 
        } 
 
        private void AddBuddyNode(BuddySelectionGroupNode parent, Imps.Client.Core.Contact contact) 
        { 
            BuddySelectionBuddyNode buddy = new BuddySelectionBuddyNode(); 
            buddy.NickName = contact.DisplayName; 
            buddy.MoodPhrase = contact.Presence.MoodPhrase; 
            buddy.Tag = contact; 
            buddy.StatusImage = contact.PresenceIcon; 
            this.treeContacts.AddBuddyNode(parent, buddy); 
        } 
 
        private bool AddLabel(string name, object tag) 
        { 
            try 
            { 
                if (tag is Imps.Client.Core.Contact) 
                { 
                    Imps.Client.Core.Contact contact = tag as Imps.Client.Core.Contact; 
                    if (this.GetLabelByContact(contact) != null) 
                    { 
                        return false; 
                    } 
                    if (contact.Uri.Raw == this.CurrentUser.Uri.Raw) 
                    { 
                        name = "我自己"; 
                    } 
                } 
                Label label = new Label(); 
                label.UseMnemonic = false; 
                label.Tag = tag; 
                label.Text = name; 
                label.Font = new Font("SimSun", 9f, FontStyle.Underline, GraphicsUnit.Point, 0x86); 
                label.Size = new Size(0x29, 12); 
                label.AutoSize = true; 
                label.Padding = new Padding(1, 2, 1, 2); 
                this.flowPanlContacts.Controls.Add(label); 
                label.MouseClick += new MouseEventHandler(this.lblContact_MouseClick); 
                label.DoubleClick += new EventHandler(this.lblContact_DoubleClick); 
                this.FormatSelectInfo(); 
            } 
            catch 
            { 
                return false; 
            } 
            return true; 
        } 
 
        private void AddMySelfNode() 
        { 
            BuddySelectionBuddyNode buddy = new BuddySelectionBuddyNode(); 
            buddy.Name = "我自己"; 
            buddy.NickName = "我自己"; 
            buddy.MoodPhrase = ""; 
            buddy.StatusImage = new AmigoImage(ImageHelper.GetThumbnailImage(this.CurrentUser.PersonalInfo.Portrait, 0x10, 0x10)); 
            buddy.Tag = this.me; 
            this.treeContacts.AddBuddyNode(null, buddy); 
            if (this._selectedContacts.Contains(this.me)) 
            { 
                buddy.CheckState = CheckState.Checked; 
                this.CheckNode(buddy); 
            } 
        } 
 
        private void BindContacts(BuddySelectionGroupNode parent, List lstContacts) 
        { 
            lstContacts.Sort(); 
            foreach (Imps.Client.Core.Contact contact in lstContacts) 
            { 
                this.AddBuddyNode(parent, contact); 
            } 
        } 
 
        private void BindGroups() 
        { 
            try 
            { 
                lock (this.CurrentUser.ContactList.Groups) 
                { 
                    foreach (Imps.Client.Core.ContactGroup group in this.CurrentUser.ContactList.Groups) 
                    { 
                        List allowContacts = this.GetAllowContacts(group.Contacts.ListContacts); 
                        if (allowContacts.Count > 0) 
                        { 
                            BuddySelectionGroupNode gNode = new BuddySelectionGroupNode(group.Name + string.Format(" ({0})", allowContacts.Count), CheckState.Unchecked); 
                            gNode.Tag = group; 
                            this.treeContacts.AddBuddyGroup(gNode); 
                            this.BindContacts(gNode, allowContacts); 
                        } 
                    } 
                } 
                this.BindNoneGroupContacts(); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void bindList() 
        { 
            try 
            { 
                if (this.ShowSelf) 
                { 
                    this.me = this.CurrentUser.ContactList.FindOrCreateContact(this.CurrentUser.Uri.Raw, new AsyncBizOperation()); 
                    this.AddMySelfNode(); 
                } 
                if (this.ShowGroup) 
                { 
                    this.BindGroups(); 
                } 
                else 
                { 
                    List allowContacts = this.GetAllowContacts(this.CurrentUser.ContactList.Contacts.ListContacts); 
                    this.BindContacts(null, allowContacts); 
                } 
                if (this.treeContacts.Nodes.Count > 0) 
                { 
                    this.treeContacts.SelectedNode = this.treeContacts.Nodes[0] as PaintTreeNode; 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
            finally 
            { 
                this.lblNoneContacts.Visible = this.treeContacts.Nodes.Count == 0; 
            } 
        } 
 
        private void BindNoneGroupContacts() 
        { 
            lock (this.CurrentUser.ContactList.Contacts.SyncRoot) 
            { 
                List lstContacts = new List(); 
                foreach (Imps.Client.Core.Contact contact in this.CurrentUser.ContactList.Contacts) 
                { 
                    if ((contact.BelongToGroups.Count == 0) && this.IsContactCanShow(contact)) 
                    { 
                        lstContacts.Add(contact); 
                    } 
                } 
                if (lstContacts.Count > 0) 
                { 
                    this.BindContacts(null, lstContacts); 
                } 
            } 
        } 
 
        private void CheckContactNode(Imps.Client.Core.Contact contact) 
        { 
            for (int i = 0; i < this.treeContacts.Nodes.Count; i++) 
            { 
                PaintTreeNode node = this.treeContacts.Nodes[i] as PaintTreeNode; 
                if ((node.Tag is Imps.Client.Core.Contact) && ((node.Tag as Imps.Client.Core.Contact).Uri.Raw == contact.Uri.Raw)) 
                { 
                    (node as BuddySelectionBuddyNode).CheckState = CheckState.Checked; 
                    this.CheckContactNode(node); 
                    return; 
                } 
                foreach (TreeNode node2 in this.treeContacts.Nodes[i].Nodes) 
                { 
                    if ((node2.Tag as Imps.Client.Core.Contact) == contact) 
                    { 
                        if (!this.treeContacts.Nodes[i].IsExpanded) 
                        { 
                            this.treeContacts.Nodes[i].Expand(); 
                        } 
                        (node2 as BuddySelectionBuddyNode).CheckState = CheckState.Checked; 
                        this.CheckContactNode(node2 as PaintTreeNode); 
                        return; 
                    } 
                } 
            } 
        } 
 
        private void CheckContactNode(PaintTreeNode node) 
        { 
            Imps.Client.Core.Contact tag = node.Tag as Imps.Client.Core.Contact; 
            if ((node as BuddySelectionBuddyNode).CheckState == CheckState.Checked) 
            { 
                if (!this._selectedContacts.Contains(tag)) 
                { 
                    if (this._selectedContacts.Count >= this._maxSelectedCount) 
                    { 
                        (node as BuddySelectionBuddyNode).CheckState = CheckState.Unchecked; 
                        FormatGroupCheckState(node); 
                        this._framework.UnifiedMessageBox.ShowWarning(this, string.Format(StringTable.Conversation.MsgSelectLimit, this._maxSelectedCount)); 
                        return; 
                    } 
                    this._selectedContacts.Add(tag); 
                } 
                this.AddLabel(tag.DisplayName, tag); 
                FormatGroupCheckState(node); 
                this.FormatOtherGroupBuddyNode(node.Parent, tag, true); 
            } 
            else 
            { 
                if (this._selectedContacts.Contains(tag)) 
                { 
                    this._selectedContacts.Remove(tag); 
                } 
                this.RemoveLable(tag); 
                FormatGroupCheckState(node); 
                this.FormatOtherGroupBuddyNode(node.Parent, tag, false); 
            } 
        } 
 
        private void CheckGroupNode(PaintTreeNode node) 
        { 
            bool flag = (node as BuddySelectionGroupNode).CheckState == CheckState.Checked; 
            foreach (TreeNode node2 in node.Nodes) 
            { 
                Imps.Client.Core.Contact tag = node2.Tag as Imps.Client.Core.Contact; 
                if (flag) 
                { 
                    if (this._selectedContacts.Count < this._maxSelectedCount) 
                    { 
                        (node2 as BuddySelectionBuddyNode).CheckState = CheckState.Checked; 
                        if (!this._selectedContacts.Contains(tag)) 
                        { 
                            this._selectedContacts.Add(tag); 
                            if (!this.AddLabel(tag.DisplayName, tag)) 
                            { 
                                break; 
                            } 
                            this.FormatOtherGroupBuddyNode(node, tag, true); 
                        } 
                    } 
                    else if (!this._selectedContacts.Contains(tag)) 
                    { 
                        (node2 as BuddySelectionBuddyNode).CheckState = CheckState.Unchecked; 
                        if ((node as BuddySelectionGroupNode).CheckState == CheckState.Checked) 
                        { 
                            FormatGroupCheckState(node2 as BuddySelectionBuddyNode); 
                            this._framework.UnifiedMessageBox.ShowWarning(this, string.Format(StringTable.Conversation.MsgSelectLimit, this._maxSelectedCount)); 
                        } 
                        this.FormatOtherGroupBuddyNode(node2, tag, false); 
                    } 
                    continue; 
                } 
                if (this._selectedContacts.Contains(tag)) 
                { 
                    this._selectedContacts.Remove(tag); 
                } 
                this.RemoveLable(tag); 
                this.RemoveTreeNodeSelect(tag); 
            } 
        } 
 
        private void CheckLabel(Label label) 
        { 
            label.ForeColor = Color.White; 
            label.BackColor = Color.Black; 
        } 
 
        private void CheckNode(PaintTreeNode node) 
        { 
            try 
            { 
                if (node.Tag is Imps.Client.Core.ContactGroup) 
                { 
                    this.CheckGroupNode(node); 
                } 
                else if (node.Tag is Imps.Client.Core.Contact) 
                { 
                    this.CheckContactNode(node); 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        protected override void Dispose(bool disposing) 
        { 
            if (disposing && (this.components != null)) 
            { 
                this.components.Dispose(); 
            } 
            base.Dispose(disposing); 
        } 
 
        private void flowPanlContacts_ControlsChanged(object sender, ControlEventArgs e) 
        { 
            if (this.SelectedContactsChanged != null) 
            { 
                this.SelectedContactsChanged(this, EventArgs.Empty); 
            } 
        } 
 
        private void flowPanlContacts_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
        { 
            if (e.KeyValue == 0x2e) 
            { 
                this.RemoveCheckedLabels(); 
            } 
        } 
 
        private static void FormatGroupCheckState(PaintTreeNode node) 
        { 
            if (node.Parent != null) 
            { 
                bool flag = false; 
                bool flag2 = true; 
                foreach (TreeNode node2 in node.Parent.Nodes) 
                { 
                    if ((node2 as BuddySelectionBuddyNode).CheckState != CheckState.Checked) 
                    { 
                        flag2 = false; 
                    } 
                    else 
                    { 
                        flag = true; 
                    } 
                } 
                if (flag2) 
                { 
                    (node.Parent as BuddySelectionGroupNode).CheckState = CheckState.Checked; 
                } 
                else if (flag) 
                { 
                    (node.Parent as BuddySelectionGroupNode).CheckState = CheckState.Indeterminate; 
                } 
                else 
                { 
                    (node.Parent as BuddySelectionGroupNode).CheckState = CheckState.Unchecked; 
                } 
            } 
        } 
 
        private void FormatOtherGroupBuddyNode(TreeNode node, Imps.Client.Core.Contact contact, bool check) 
        { 
            if (contact.BelongToGroups.Count > 1) 
            { 
                for (int i = 0; i < this.treeContacts.Nodes.Count; i++) 
                { 
                    if (this.treeContacts.Nodes[i] != node) 
                    { 
                        if (this.treeContacts.Nodes[i] is BuddySelectionBuddyNode) 
                        { 
                            if (((this.treeContacts.Nodes[i] as BuddySelectionBuddyNode).Tag as Imps.Client.Core.Contact) == contact) 
                            { 
                                if (check) 
                                { 
                                    (this.treeContacts.Nodes[i] as BuddySelectionBuddyNode).CheckState = CheckState.Checked; 
                                } 
                                else 
                                { 
                                    (this.treeContacts.Nodes[i] as BuddySelectionBuddyNode).CheckState = CheckState.Unchecked; 
                                } 
                            } 
                        } 
                        else if (contact.BelongToGroups.Contains(((this.treeContacts.Nodes[i] as BuddySelectionGroupNode).Tag as Imps.Client.Core.ContactGroup).Id)) 
                        { 
                            foreach (TreeNode node2 in this.treeContacts.Nodes[i].Nodes) 
                            { 
                                if (((node2 as BuddySelectionBuddyNode).Tag as Imps.Client.Core.Contact) != contact) 
                                { 
                                    continue; 
                                } 
                                if (check) 
                                { 
                                    (node2 as BuddySelectionBuddyNode).CheckState = CheckState.Checked; 
                                } 
                                else 
                                { 
                                    (node2 as BuddySelectionBuddyNode).CheckState = CheckState.Unchecked; 
                                } 
                                FormatGroupCheckState(node2 as PaintTreeNode); 
                            } 
                        } 
                    } 
                } 
            } 
        } 
 
        private void FormatSelectInfo() 
        { 
            int count = this._selectedContacts.Count; 
            this.lblSelectInfo.Text = string.Format(StringTable.Conversation.MsgInviteSelectedInfo, count, this._maxSelectedCount - count); 
        } 
 
        private List GetAllowContacts(List sourceList) 
        { 
            List list = new List(); 
            foreach (Imps.Client.Core.Contact contact in sourceList) 
            { 
                if (this.IsContactCanShow(contact)) 
                { 
                    list.Add(contact); 
                } 
            } 
            return list; 
        } 
 
        private Label GetLabelByContact(Imps.Client.Core.Contact contact) 
        { 
            for (int i = 0; i < this.flowPanlContacts.Controls.Count; i++) 
            { 
                if ((this.flowPanlContacts.Controls[i].Tag as Imps.Client.Core.Contact) == contact) 
                { 
                    return (this.flowPanlContacts.Controls[i] as Label); 
                } 
            } 
            return null; 
        } 
 
        private int GetLabelIndex(Label label) 
        { 
            for (int i = 0; i < this.flowPanlContacts.Controls.Count; i++) 
            { 
                if (this.flowPanlContacts.Controls[i] == label) 
                { 
                    return i; 
                } 
            } 
            return -1; 
        } 
 
        private void InitializeComponent() 
        { 
            this.components = new Container(); 
            this.menuDelete = new ToolStripMenuItem(); 
            this.menuOperation = new menu_widget(this.components); 
            this.xSplitContainer = new XSplitContainer(); 
            this.pnlOnlyForBorderShit = new Panel(); 
            this.lblNoneContacts = new Label(); 
            this.treeContacts = new BuddySelectionTree(); 
            this.toolbarSearch = new BListControlToolbar(); 
            this.lblMessage = new Label(); 
            this.panel1 = new Panel(); 
            this.panel2 = new Panel(); 
            this.flowPanlContacts = new FlowLayoutPanel(); 
            this.lbSpace = new Label(); 
            this.lblSelectInfo = new Label(); 
            this.menuOperation.SuspendLayout(); 
            this.xSplitContainer.Panel1.SuspendLayout(); 
            this.xSplitContainer.Panel2.SuspendLayout(); 
            this.xSplitContainer.SuspendLayout(); 
            this.pnlOnlyForBorderShit.SuspendLayout(); 
            this.panel1.SuspendLayout(); 
            this.panel2.SuspendLayout(); 
            base.SuspendLayout(); 
            this.menuDelete.Name = "menuDelete"; 
            this.menuDelete.Size = new Size(0x62, 0x16); 
            this.menuDelete.Text = "删除"; 
            this.menuDelete.Click += new EventHandler(this.menuDelete_Click); 
            this.menuOperation.Items.AddRange(new ToolStripItem[] { this.menuDelete }); 
            this.menuOperation.Name = "menuOperation"; 
            this.menuOperation.Size = new Size(0x63, 0x1a); 
            this.menuOperation.UseMnemonic = true; 
            this.xSplitContainer.BackColor = Color.Transparent; 
            this.xSplitContainer.Dock = DockStyle.Fill; 
            this.xSplitContainer.Location = new System.Drawing.Point(0, 0); 
            this.xSplitContainer.Name = "xSplitContainer"; 
            this.xSplitContainer.Orientation = Orientation.Horizontal; 
            this.xSplitContainer.Panel1.BackColor = Color.Transparent; 
            this.xSplitContainer.Panel1.Controls.Add(this.pnlOnlyForBorderShit); 
            this.xSplitContainer.Panel1.Controls.Add(this.toolbarSearch); 
            this.xSplitContainer.Panel1.Controls.Add(this.lblMessage); 
            this.xSplitContainer.Panel1.RightToLeft = RightToLeft.No; 
            this.xSplitContainer.Panel1MinSize = 0x7d; 
            this.xSplitContainer.Panel2.BackColor = Color.Transparent; 
            this.xSplitContainer.Panel2.Controls.Add(this.panel1); 
            this.xSplitContainer.Panel2.Controls.Add(this.lbSpace); 
            this.xSplitContainer.Panel2.Controls.Add(this.lblSelectInfo); 
            this.xSplitContainer.Panel2.RightToLeft = RightToLeft.No; 
            this.xSplitContainer.Panel2MinSize = 0x51; 
            this.xSplitContainer.Size = new Size(0x10d, 0x17e); 
            this.xSplitContainer.SplitterDistance = 0x110; 
            this.xSplitContainer.TabIndex = 5; 
            this.pnlOnlyForBorderShit.BackColor = Color.FromArgb(0xca, 0xd4, 0xde); 
            this.pnlOnlyForBorderShit.Controls.Add(this.lblNoneContacts); 
            this.pnlOnlyForBorderShit.Controls.Add(this.treeContacts); 
            this.pnlOnlyForBorderShit.Dock = DockStyle.Fill; 
            this.pnlOnlyForBorderShit.Location = new System.Drawing.Point(0, 0x3f); 
            this.pnlOnlyForBorderShit.Name = "pnlOnlyForBorderShit"; 
            this.pnlOnlyForBorderShit.Padding = new Padding(1, 0, 1, 1); 
            this.pnlOnlyForBorderShit.Size = new Size(0x10d, 0xd1); 
            this.pnlOnlyForBorderShit.TabIndex = 5; 
            this.lblNoneContacts.AutoSize = true; 
            this.lblNoneContacts.BackColor = Color.White; 
            this.lblNoneContacts.Location = new System.Drawing.Point(4, 6); 
            this.lblNoneContacts.Name = "lblNoneContacts"; 
            this.lblNoneContacts.Size = new Size(0x7d, 12); 
            this.lblNoneContacts.TabIndex = 2; 
            this.lblNoneContacts.Text = "没有符合您条件的好友"; 
            this.lblNoneContacts.Visible = false; 
            this.treeContacts.BorderStyle = BorderStyle.None; 
            this.treeContacts.ContactShowMode = ShowMode.SingleRow; 
            this.treeContacts.Dock = DockStyle.Fill; 
            this.treeContacts.FullRowSelect = true; 
            this.treeContacts.HideSelection = false; 
            this.treeContacts.Indent = 20; 
            this.treeContacts.ItemHeight = 20; 
            this.treeContacts.Location = new System.Drawing.Point(1, 0); 
            this.treeContacts.Name = "treeContacts"; 
            this.treeContacts.PaintSelected = true; 
            this.treeContacts.SelectBorderColor = Color.FromArgb(0x83, 150, 0xc3); 
            this.treeContacts.SelectedNode = null; 
            this.treeContacts.SelectionColor = Color.BlueViolet; 
            this.treeContacts.ShowPlusMinus = false; 
            this.treeContacts.Size = new Size(0x10b, 0xd0); 
            this.treeContacts.Sorted = true; 
            this.treeContacts.TabIndex = 1; 
            this.toolbarSearch.BackColor = Color.FromArgb(0xca, 0xd4, 0xde); 
            this.toolbarSearch.Dock = DockStyle.Top; 
            this.toolbarSearch.DropDownMenu = null; 
            this.toolbarSearch.Location = new System.Drawing.Point(0, 0x2a); 
            this.toolbarSearch.Name = "toolbarSearch"; 
            this.toolbarSearch.ShowDisplayModeBar = false; 
            this.toolbarSearch.SimpleMode = true; 
            this.toolbarSearch.Size = new Size(0x10d, 0x15); 
            this.toolbarSearch.TabIndex = 0; 
            this.toolbarSearch.TipText = "请输入昵称、姓名、手机号、飞信号等查找好友"; 
            this.toolbarSearch.TipTextClear = "清除输入内容"; 
            this.toolbarSearch.TipTextMagnifier = "请输入昵称、姓名、手机号、飞信号等查找好友"; 
            this.toolbarSearch.TipTextMenu = "请输入昵称、姓名、手机号、飞信号等查找好友"; 
            this.lblMessage.Dock = DockStyle.Top; 
            this.lblMessage.Location = new System.Drawing.Point(0, 0); 
            this.lblMessage.Name = "lblMessage"; 
            this.lblMessage.Padding = new Padding(1); 
            this.lblMessage.Size = new Size(0x10d, 0x2a); 
            this.lblMessage.TabIndex = 4; 
            this.lblMessage.Text = "Message"; 
            this.panel1.BackColor = Color.FromArgb(0xca, 0xd4, 0xde); 
            this.panel1.Controls.Add(this.panel2); 
            this.panel1.Dock = DockStyle.Fill; 
            this.panel1.Location = new System.Drawing.Point(0, 0x15); 
            this.panel1.Name = "panel1"; 
            this.panel1.Padding = new Padding(1); 
            this.panel1.Size = new Size(0x10d, 0x55); 
            this.panel1.TabIndex = 3; 
            this.panel2.BackColor = Color.White; 
            this.panel2.Controls.Add(this.flowPanlContacts); 
            this.panel2.Dock = DockStyle.Fill; 
            this.panel2.Location = new System.Drawing.Point(1, 1); 
            this.panel2.Name = "panel2"; 
            this.panel2.Padding = new Padding(3, 3, 0, 0); 
            this.panel2.Size = new Size(0x10b, 0x53); 
            this.panel2.TabIndex = 0; 
            this.flowPanlContacts.AutoScroll = true; 
            this.flowPanlContacts.BackColor = Color.White; 
            this.flowPanlContacts.Dock = DockStyle.Fill; 
            this.flowPanlContacts.Location = new System.Drawing.Point(3, 3); 
            this.flowPanlContacts.Name = "flowPanlContacts"; 
            this.flowPanlContacts.Size = new Size(0x108, 80); 
            this.flowPanlContacts.TabIndex = 2; 
            this.flowPanlContacts.TabStop = true; 
            this.flowPanlContacts.PreviewKeyDown += new PreviewKeyDownEventHandler(this.flowPanlContacts_PreviewKeyDown); 
            this.lbSpace.Dock = DockStyle.Top; 
            this.lbSpace.Location = new System.Drawing.Point(0, 0x10); 
            this.lbSpace.Name = "lbSpace"; 
            this.lbSpace.Size = new Size(0x10d, 5); 
            this.lbSpace.TabIndex = 5; 
            this.lbSpace.TextAlign = ContentAlignment.MiddleLeft; 
            this.lblSelectInfo.Dock = DockStyle.Top; 
            this.lblSelectInfo.Location = new System.Drawing.Point(0, 0); 
            this.lblSelectInfo.Name = "lblSelectInfo"; 
            this.lblSelectInfo.Size = new Size(0x10d, 0x10); 
            this.lblSelectInfo.TabIndex = 2; 
            this.lblSelectInfo.Text = "已选中[{0}]人,还能再邀请{0}人"; 
            this.lblSelectInfo.TextAlign = ContentAlignment.MiddleLeft; 
            base.AutoScaleDimensions = new SizeF(6f, 12f); 
            base.AutoScaleMode = AutoScaleMode.Font; 
            this.BackColor = Color.Transparent; 
            base.Controls.Add(this.xSplitContainer); 
            base.Name = "InviteControl"; 
            base.Size = new Size(0x10d, 0x17e); 
            this.menuOperation.ResumeLayout(false); 
            this.xSplitContainer.Panel1.ResumeLayout(false); 
            this.xSplitContainer.Panel2.ResumeLayout(false); 
            this.xSplitContainer.ResumeLayout(false); 
            this.pnlOnlyForBorderShit.ResumeLayout(false); 
            this.pnlOnlyForBorderShit.PerformLayout(); 
            this.panel1.ResumeLayout(false); 
            this.panel2.ResumeLayout(false); 
            base.ResumeLayout(false); 
        } 
 
        private void InviteControl_GotFocus(object sender, EventArgs e) 
        { 
            this.txtSearch.Focus(); 
        } 
 
        private void InviteControl_Shown(object sender, EventArgs e) 
        { 
            this.bindList(); 
            for (int i = this._selectedContacts.Count - 1; i >= 0; i--) 
            { 
                if (!this.IsContactCanShow(this._selectedContacts[i])) 
                { 
                    this._selectedContacts.Remove(this._selectedContacts[i]); 
                } 
            } 
            this._selectedContacts.Sort(); 
            this.ReSelectNodes(); 
            bool flag = false; 
            if (this._selectedContacts.Count > this._maxSelectedCount) 
            { 
                for (int j = this._selectedContacts.Count - 1; j >= this._maxSelectedCount; j--) 
                { 
                    this._selectedContacts.Remove(this._selectedContacts[j]); 
                } 
                flag = true; 
            } 
            this.FormatSelectInfo(); 
            if (flag) 
            { 
                this._framework.UnifiedMessageBox.ShowWarning(this, string.Format(StringTable.Conversation.MsgSelectLimit, this._maxSelectedCount)); 
            } 
        } 
 
        private bool IsCheckedLabel(Label lbl) 
        { 
            return (lbl.ForeColor == Color.White); 
        } 
 
        private bool IsContactCanShow(Imps.Client.Core.Contact contact) 
        { 
            if (contact.Uri.Raw != this.CurrentUser.Uri.Raw) 
            { 
                if ((this._excludeContacts != null) && this._excludeContacts.Contains(contact)) 
                { 
                    return false; 
                } 
                switch (this.SelectType) 
                { 
                    case SelectContactsType.MultiConversation: 
                        return contact.EnableMultiIM; 
 
                    case SelectContactsType.GroupSms: 
                        return contact.EnableSMS; 
 
                    case SelectContactsType.Ivr: 
                        return contact.EnableIvr; 
 
                    case SelectContactsType.InviteJoinGroup: 
                        return contact.EnableInviteJoinGroup; 
                } 
                if (contact.RelationStatus != 1) 
                { 
                    return false; 
                } 
                if (contact.Type == ContactType.Vodafone) 
                { 
                    return false; 
                } 
                if (contact.IsBlocked) 
                { 
                    return false; 
                } 
                if (!this.ShowSMSOffline) 
                { 
                    if (contact.Presence.IsSmsOffline) 
                    { 
                        return false; 
                    } 
                } 
                else if (contact.PersonalInfo.Provision != 1) 
                { 
                    return false; 
                } 
                if (!this.ShowSymbianR1 && (contact.Presence.ClientTypeType == ClientType.SymbianR1)) 
                { 
                    return false; 
                } 
                if (!this.ShowJ2MER1 && (contact.Presence.ClientTypeType == ClientType.J2MER1)) 
                { 
                    return false; 
                } 
                if (this.OnlyShowOnline && (contact.Presence.MainPresence == MainPresence.Offline)) 
                { 
                    return false; 
                } 
                if (!this.ShowSMSOnline && (contact.Presence.MainPresence == MainPresence.SmsOnline)) 
                { 
                    return false; 
                } 
                if ((contact is Imps.Client.Core.MobileBuddy) && !this.ShowMobileBuddy) 
                { 
                    return false; 
                } 
            } 
            return true; 
        } 
 
        private void lblContact_DoubleClick(object sender, EventArgs e) 
        { 
            this.RemoveCheckedLabels(); 
        } 
 
        private void lblContact_MouseClick(object sender, MouseEventArgs e) 
        { 
            bool flag = (Imps.Client.Utils.Win32.NativeMethods.GetKeyState(0x11) & 0x8000) != 0; 
            bool flag2 = (Imps.Client.Utils.Win32.NativeMethods.GetKeyState(0x10) & 0x8000) != 0; 
            if (!flag && !flag2) 
            { 
                this.UnCheckAllLable(); 
            } 
            this.flowPanlContacts.Focus(); 
            Label lbl = sender as Label; 
            Console.WriteLine(lbl.ForeColor); 
            if (this.IsCheckedLabel(lbl)) 
            { 
                this.UnCheckLabel(lbl); 
            } 
            else 
            { 
                this.CheckLabel(lbl); 
                if ((!flag && !flag2) || (this.lastCheckIndex == -1)) 
                { 
                    this.lastCheckIndex = this.GetLabelIndex(lbl); 
                } 
                if (e.Button == MouseButtons.Right) 
                { 
                    this.menuOperation.Show(Control.MousePosition); 
                } 
            } 
            if (flag2 && (this.lastCheckIndex != -1)) 
            { 
                int labelIndex = this.GetLabelIndex(lbl); 
                int num2 = (labelIndex > this.lastCheckIndex) ? this.lastCheckIndex : labelIndex; 
                int num3 = (labelIndex > this.lastCheckIndex) ? labelIndex : this.lastCheckIndex; 
                for (int i = num2; i <= num3; i++) 
                { 
                    this.CheckLabel(this.flowPanlContacts.Controls[i] as Label); 
                } 
                for (int j = 0; j < num2; j++) 
                { 
                    this.UnCheckLabel(this.flowPanlContacts.Controls[j] as Label); 
                } 
                if (num3 < this.flowPanlContacts.Controls.Count) 
                { 
                    for (int k = num3 + 1; k < this.flowPanlContacts.Controls.Count; k++) 
                    { 
                        this.UnCheckLabel(this.flowPanlContacts.Controls[k] as Label); 
                    } 
                } 
            } 
        } 
 
        private void menuDelete_Click(object sender, EventArgs e) 
        { 
            this.RemoveCheckedLabels(); 
        } 
 
        protected override void OnLoad(EventArgs e) 
        { 
            base.OnLoad(e); 
            if (this._selectedContacts == null) 
            { 
                this._selectedContacts = new List(); 
            } 
            this.lblNoneContacts.Text = StringTable.ContactTree.FoundNone; 
            this.txtSearch.MaxLength = 0x40; 
            this.txtSearch.EmptyTextTip = this.emptyText; 
            this.txtSearch.TextChanged += new EventHandler(this.txtSearch_TextChanged); 
            this.txtSearch.KeyDown += new KeyEventHandler(this.txtSearch_KeyDown); 
            this.flowPanlContacts.LostFocus += delegate { 
                this.UnCheckAllLable(); 
            }; 
            vscroll_widget _widget = scroll_maker.instance.vscroll(); 
            _widget.host = this.treeContacts; 
            this.treeContacts.Parent.Controls.Add(_widget); 
            vscroll_widget _widget2 = scroll_maker.instance.vscroll(); 
            _widget2.sensitive = true; 
            _widget2.for_pane = true; 
            _widget2.stylized_mode = true; 
            _widget2.host = this.flowPanlContacts; 
            this.flowPanlContacts.Parent.Controls.Add(_widget2); 
            hscroll_widget _widget3 = scroll_maker.instance.hscroll(); 
            _widget3.sensitive = true; 
            _widget3.for_pane = true; 
            _widget3.stylized_mode = true; 
            _widget3.host = this.flowPanlContacts; 
            this.flowPanlContacts.Parent.Controls.Add(_widget3); 
            this.treeContacts.NodeAferCheck += new NodeAfterCheck(this.treeContacts_NodeAferCheck); 
            base.FindForm().Shown += new EventHandler(this.InviteControl_Shown); 
        } 
 
        private void PersonalInfo_PropertiesChanged(object sender, PropertiesChangedEventArgs e) 
        { 
            if ((e.ContainsProperty("Portrait") && (this.treeContacts.Nodes[0] is BuddySelectionBuddyNode)) && (((this.treeContacts.Nodes[0] as BuddySelectionBuddyNode).Tag as Imps.Client.Core.Contact).Uri.Raw == this.CurrentUser.Uri.Raw)) 
            { 
                (this.treeContacts.Nodes[0] as BuddySelectionBuddyNode).StatusImage = new AmigoImage(ImageHelper.GetThumbnailImage(this.CurrentUser.PersonalInfo.Portrait, 0x10, 0x10)); 
            } 
        } 
 
        private void RemoveCheckedLabels() 
        { 
            try 
            { 
                for (int i = this.flowPanlContacts.Controls.Count - 1; i >= 0; i--) 
                { 
                    if (this.flowPanlContacts.Controls[i].ForeColor == Color.White) 
                    { 
                        Imps.Client.Core.Contact tag = this.flowPanlContacts.Controls[i].Tag as Imps.Client.Core.Contact; 
                        this._selectedContacts.Remove(tag); 
                        this.flowPanlContacts.Controls.Remove(this.flowPanlContacts.Controls[i]); 
                        this.RemoveTreeNodeSelect(tag); 
                    } 
                } 
                this.FormatSelectInfo(); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void RemoveLable(object tag) 
        { 
            try 
            { 
                for (int i = 0; i < this.flowPanlContacts.Controls.Count; i++) 
                { 
                    if ((this.flowPanlContacts.Controls[i] as Label).Tag == tag) 
                    { 
                        this.flowPanlContacts.Controls.Remove(this.flowPanlContacts.Controls[i]); 
                        break; 
                    } 
                } 
                this.FormatSelectInfo(); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void RemoveTreeNodeSelect(Imps.Client.Core.Contact contact) 
        { 
            try 
            { 
                for (int i = 0; i < this.treeContacts.Nodes.Count; i++) 
                { 
                    PaintTreeNode node = this.treeContacts.Nodes[i] as PaintTreeNode; 
                    if ((node.Tag is Imps.Client.Core.Contact) && ((node.Tag as Imps.Client.Core.Contact) == contact)) 
                    { 
                        (node as BuddySelectionBuddyNode).CheckState = CheckState.Unchecked; 
                    } 
                    foreach (TreeNode node2 in this.treeContacts.Nodes[i].Nodes) 
                    { 
                        if ((node2.Tag as Imps.Client.Core.Contact) == contact) 
                        { 
                            (node2 as BuddySelectionBuddyNode).CheckState = CheckState.Unchecked; 
                            FormatGroupCheckState(node2 as BuddySelectionBuddyNode); 
                        } 
                    } 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void ReSelectNodes() 
        { 
            for (int i = 0; i < this._selectedContacts.Count; i++) 
            { 
                if (i < this._maxSelectedCount) 
                { 
                    this.CheckContactNode(this._selectedContacts[i]); 
                } 
                if (i >= this._maxSelectedCount) 
                { 
                    return; 
                } 
            } 
        } 
 
        public void SetTreeFocus() 
        { 
            this.treeContacts.Focus(); 
        } 
 
        private void treeContacts_NodeAferCheck(object sender, BuddySelectionTreeCheckEventArgs e) 
        { 
            this.CheckNode(e.Node); 
        } 
 
        private void txtSearch_KeyDown(object sender, KeyEventArgs e) 
        { 
            if (e.KeyCode == Keys.Escape) 
            { 
                this.txtSearch.Text = string.Empty; 
            } 
        } 
 
        private void txtSearch_TextChanged(object sender, EventArgs e) 
        { 
            if (!this.fireByFunction) 
            { 
                try 
                { 
                    string keyWord = this.txtSearch.Text.Trim(); 
                    this.treeContacts.Nodes.Clear(); 
                    if (keyWord.Length <= 0) 
                    { 
                        this.bindList(); 
                        this.MatchHelper.Clear(); 
                    } 
                    else 
                    { 
                        ContactCollection matchContacts = this.MatchHelper.GetMatchContacts(keyWord); 
                        List allowContacts = this.GetAllowContacts(matchContacts.ListContacts); 
                        if (this.ShowSelf && (this.me != null)) 
                        { 
                            try 
                            { 
                                if (("woziji".Contains(keyWord) || "我自己".Contains(keyWord)) || (this.CurrentUser.MobileNo.Contains(keyWord) || this.CurrentUser.Sid.ToString().Contains(keyWord))) 
                                { 
                                    this.AddMySelfNode(); 
                                } 
                            } 
                            catch 
                            { 
                            } 
                        } 
                        this.BindContacts(null, allowContacts); 
                    } 
                    if (this._selectedContacts.Count > 0) 
                    { 
                        this.ReSelectNodes(); 
                    } 
                } 
                catch (Exception exception) 
                { 
                    ClientLogger.WriteException(exception); 
                } 
                finally 
                { 
                    this.lblNoneContacts.Visible = this.treeContacts.Nodes.Count == 0; 
                } 
            } 
        } 
 
        private void UnCheckAllLable() 
        { 
            foreach (Label label in this.flowPanlContacts.Controls) 
            { 
                if (this.IsCheckedLabel(label)) 
                { 
                    this.UnCheckLabel(label); 
                } 
            } 
        } 
 
        private void UnCheckLabel(Label label) 
        { 
            label.ForeColor = Color.Black; 
            label.BackColor = Color.Transparent; 
        } 
 
        private void xSplitContainer_SplitterMoved(object sender, SplitterEventArgs e) 
        { 
            if (this.SplitterMoved != null) 
            { 
                this.SplitterMoved(sender, e); 
            } 
        } 
 
        private Imps.Client.Core.User CurrentUser 
        { 
            get 
            { 
                return this._framework.AccountManager.CurrentUser; 
            } 
        } 
 
        private ContactMatchHelper MatchHelper 
        { 
            get 
            { 
                if (this._matchHelper == null) 
                { 
                    this._matchHelper = new ContactMatchHelper(this.CurrentUser); 
                } 
                return this._matchHelper; 
            } 
        } 
 
        public int MaxSelectedCount 
        { 
            get 
            { 
                return this._maxSelectedCount; 
            } 
            set 
            { 
                this._maxSelectedCount = value; 
            } 
        } 
 
        public string Message 
        { 
            get 
            { 
                return this.lblMessage.Text; 
            } 
            set 
            { 
                this.lblMessage.Text = value; 
            } 
        } 
 
        public int MessageLabelHeight 
        { 
            get 
            { 
                return this.lblMessage.Height; 
            } 
            set 
            { 
                this.lblMessage.Height = value; 
            } 
        } 
 
        public bool OnlyShowOnline 
        { 
            get 
            { 
                return this._onlyShowOnline; 
            } 
            set 
            { 
                this._onlyShowOnline = value; 
            } 
        } 
 
        public bool SearchTextboxAtTop 
        { 
            get 
            { 
                return this._searchTextboxAtTop; 
            } 
            set 
            { 
                if (this._searchTextboxAtTop != value) 
                { 
                    this._searchTextboxAtTop = value; 
                    if (value) 
                    { 
                        this.toolbarSearch.SendToBack(); 
                        this.lblMessage.BackColor = Color.FromArgb(0xca, 0xd4, 0xde); 
                    } 
                    else 
                    { 
                        this.lblMessage.SendToBack(); 
                        this.lblMessage.BackColor = Color.Transparent; 
                    } 
                } 
            } 
        } 
 
        public bool SearchTextBoxVisible 
        { 
            get 
            { 
                return this.toolbarSearch.Visible; 
            } 
            set 
            { 
                this.toolbarSearch.Visible = true; 
            } 
        } 
 
        public Imps.Client.Core.Contact SelectedContact 
        { 
            get 
            { 
                if ((this.treeContacts.SelectedNode != null) && (this.treeContacts.SelectedNode.Tag is Imps.Client.Core.Contact)) 
                { 
                    return (this.treeContacts.SelectedNode.Tag as Imps.Client.Core.Contact); 
                } 
                return null; 
            } 
        } 
 
        public List SelectedContacts 
        { 
            get 
            { 
                if (this._selectedContacts == null) 
                { 
                    this._selectedContacts = new List(); 
                } 
                return this._selectedContacts; 
            } 
        } 
 
        public SelectContactsType SelectType 
        { 
            get 
            { 
                return this._selectType; 
            } 
            internal set 
            { 
                this._selectType = value; 
            } 
        } 
 
        public bool ShowGroup 
        { 
            get 
            { 
                return this._showGroup; 
            } 
            set 
            { 
                this._showGroup = value; 
            } 
        } 
 
        public bool ShowJ2MER1 
        { 
            get 
            { 
                return this._showJ2MER1; 
            } 
            set 
            { 
                this._showJ2MER1 = value; 
            } 
        } 
 
        public bool ShowMobileBuddy 
        { 
            get 
            { 
                return this._showMobileBuddy; 
            } 
            set 
            { 
                this._showMobileBuddy = value; 
            } 
        } 
 
        public bool ShowSelf 
        { 
            get 
            { 
                return this._showSelf; 
            } 
            set 
            { 
                this._showSelf = value; 
            } 
        } 
 
        public bool ShowSMSOffline 
        { 
            get 
            { 
                return this._showSMSOffline; 
            } 
            set 
            { 
                this._showSMSOffline = value; 
            } 
        } 
 
        public bool ShowSMSOnline 
        { 
            get 
            { 
                return this._showSMSOnline; 
            } 
            set 
            { 
                this._showSMSOnline = value; 
            } 
        } 
 
        public bool ShowSymbianR1 
        { 
            get 
            { 
                return this._showSymbianR1; 
            } 
            set 
            { 
                this._showSymbianR1 = value; 
            } 
        } 
 
        public int SplitterDistance 
        { 
            get 
            { 
                return this.xSplitContainer.SplitterDistance; 
            } 
            set 
            { 
                this.xSplitContainer.SplitterDistance = value; 
            } 
        } 
    } 
}