Ejemplo n.º 1
0
        /// <summary>
        /// This method is called when the user changes tab option in the Options dialog.
        /// All the chat tabs and windows that are currently in the closed state are
        /// switched to the new mode. This is the behaviour a user would expect.
        /// </summary>
        private void SwitchWindowMode(bool value)
        {
            //  This is a rather expensive operation, no need to do it if value
            //  is the same as bChatWindowed.
            if (bChatWindowed == value)
            {
                return;
            }

            bChatWindowed = value;
            if (bChatWindowed)
            {
                List <TabPageEx> remList = new List <TabPageEx>();
                foreach (TabPageEx tabPage in tabList)
                {
                    if (!tabControlChat.TabPages.ContainsKey(tabPage.Name))
                    {
                        ChatControl chatControl = (ChatControl)tabPage.Controls["ChatControl"];
                        chatControl.Parent = null;
                        string   key         = chatControl.Key;
                        string   text        = tabPage.Text;
                        ChatForm newChatForm = CreateChatForm(key, text, false, false);
                        newChatForm.Enabled = chatControl.Enabled;
                        newChatForm.Controls.Add(chatControl);
                        chatControl.Windowed = true;
                        remList.Add(tabPage);
                    }
                }
                //  Remove all tabpages that were added to rem list from tab list.
                tabList.RemoveAll(new Predicate <TabPageEx>(delegate(TabPageEx item) {
                    return(remList.Contains(item));
                }));
                //  Dispose all the tab pages that were removed.
                foreach (TabPageEx tabPage in remList)
                {
                    tabPage.Dispose();
                }
            }
            else
            {
                List <ChatForm> remList = new List <ChatForm>();
                foreach (ChatForm chatForm in windowList)
                {
                    if (!chatForm.Visible)
                    {
                        ChatControl chatControl = (ChatControl)chatForm.Controls["ChatControl"];
                        chatControl.Parent = null;
                        string    key        = chatControl.Key;
                        string    text       = chatForm.Text;
                        TabPageEx newTabPage = CreateChatTab(key, text, false);
                        newTabPage.Enabled = chatControl.Enabled;
                        newTabPage.Controls.Add(chatControl);
                        chatControl.Windowed = false;
                        remList.Add(chatForm);
                    }
                }
                //  Remove all chat forms that were added to rem list from window list.
                windowList.RemoveAll(new Predicate <ChatForm>(delegate(ChatForm item) {
                    return(remList.Contains(item));
                }));
                //  Dispose all the chat windows that were removed.
                foreach (ChatForm chatForm in remList)
                {
                    chatForm.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new tab page to the Tab Control and specifies the text and
        /// key for the tab. If tab already exists, bring it to top.
        /// </summary>
        /// <param name="text"></param>
        private void StartConversation(string key, string text, bool activated)
        {
            bool tabSelected = false;

            //  Check if tab with given key exists.
            if (tabControlChat.TabPages.ContainsKey(key))
            {
                //  Tab found, make it selected.
                TabPageEx selectedTabPage = (TabPageEx)tabControlChat.TabPages[key];
                tabControlChat.SelectedTab = selectedTabPage;
                tabSelected = true;
            }
            else if (tabList.ContainsKey(key))
            {
                TabPageEx tabPage = tabList[key];
                tabControlChat.TabPages.Add(tabPage);
                tabControlChat.SelectedTab = tabPage;
                tabSelected = true;
            }
            else if (windowList.ContainsKey(key))
            {
                if (activated)
                {
                    ChatForm chatForm = windowList[key];
                    chatForm.ShowWindow(true, true);
                }
            }
            else
            {
                TabPageEx   newTabPage     = null;
                ChatForm    newChatForm    = null;
                ChatControl newChatControl = null;
                try {
                    //  Create a Chat control and set its properties.
                    newChatControl               = new ChatControl();
                    newChatControl.Name          = "ChatControl";
                    newChatControl.Dock          = DockStyle.Fill;
                    newChatControl.LocalUserName = localUserName;
                    newChatControl.LocalAddress  = localAddress.ToString();

                    User remoteUser = GetUser(key);
                    newChatControl.Key                 = key;
                    newChatControl.RemoteUserName      = remoteUser.Name;
                    newChatControl.RemoteAddress       = remoteUser.Address;
                    newChatControl.MessageFont         = defaultFont;
                    newChatControl.MessageFontColor    = defaultFontColor;
                    newChatControl.HotKeyMod           = Properties.Settings.Default.MessageHotKeyMod;
                    newChatControl.MessageToForeground = bMessageToForeground;
                    newChatControl.SilentMode          = bSilentMode;
                    newChatControl.ShowEmoticons       = Properties.Settings.Default.ShowEmoticons;
                    newChatControl.EmotTextToImage     = Properties.Settings.Default.EmotTextToImage;
                    newChatControl.ShowTimeStamp       = Properties.Settings.Default.ShowTimeStamp;
                    newChatControl.AddDateToTimeStamp  = Properties.Settings.Default.AddDateToTimeStamp;
                    newChatControl.Windowed            = bChatWindowed;
                    newChatControl.Sending            += new ChatControl.SendEventHandler(ChatControl_Sending);
                    newChatControl.WindowModeChange   += new ChatControl.WindowModeChangeEventHandler(ChatControl_WindowModeChange);

                    if (Properties.Settings.Default.ChatWindowed == true)
                    {
                        newChatForm = CreateChatForm(key, text, activated);
                        newChatForm.Controls.Add(newChatControl);
                    }
                    else
                    {
                        //  Create a new tab page and add the chat control to it.
                        newTabPage = CreateChatTab(key, text);
                        newTabPage.Controls.Add(newChatControl);
                        tabSelected = true;
                    }
                    //  Display status message.
                    newChatControl.ReceiveMessage(MessageTypes.Status, string.Empty, remoteUser.Name, remoteUser.Status);
                    //  Display a message if remote user's version is older.
                    if (IsVersionOlder(remoteUser.Version, localClientVersion))
                    {
                        newChatControl.ReceiveMessage(MessageTypes.OldVersion, string.Empty, remoteUser.Name, string.Empty);
                    }
                }
                catch {
                    if (newChatControl != null)
                    {
                        newChatControl.Dispose();
                    }
                    if (newTabPage != null)
                    {
                        newTabPage.Dispose();
                    }
                    if (newChatForm != null)
                    {
                        newChatForm.Dispose();
                    }
                    return;
                }
            }
            tabControlChat.Visible = (tabControlChat.TabCount > 0);
            //  Set keyboard focus to the message box inside the chat control.
            //  This is to be done after tab control becomes visible, else focus will not work.
            if (tabSelected && tabControlChat.SelectedIndex >= 0)
            {
                TabPageEx   tabPage     = (TabPageEx)tabControlChat.SelectedTab;
                ChatControl chatControl = (ChatControl)tabPage.Controls["ChatControl"];
                chatControl.SetFocus();
            }
        }