Esempio n. 1
0
        /// <summary>
        /// Creates a chat tab and adds it to the tab control based on the parameter value.
        /// </summary>
        /// <param name="key">Unique key of user.</param>
        /// <param name="text">Title of tab.</param>
        /// <param name="show">Whether to show tab or not.</param>
        /// <param name="retries">Number of retry.</param>
        /// <returns></returns>
        private TabPageEx CreateChatTab(string key, string text, bool show, int retries)
        {
            TabPageEx newTabPage = null;

            try {
                newTabPage             = new TabPageEx(text);
                newTabPage.Name        = key;
                newTabPage.ImageKey    = "Blank";
                newTabPage.ToolTipText = text;
                SetTabLook(newTabPage);

                //  Add tab page to the tab list.
                tabList.Add(newTabPage);
                //  Set correct status images.
                UpdateUserStatusImages(key);
                //  Set correct tab look.
                UpdateTabWindowStatusLook(key);

                if (show)
                {
                    //  Add tab page to tab control.
                    tabControlChat.TabPages.Add(newTabPage);
                    // Make the new tab the selected tab.
                    tabControlChat.SelectedTab = newTabPage;
                }

                return(newTabPage);
            }
            catch {
                if (newTabPage != null)
                {
                    if (tabList.Contains(newTabPage))
                    {
                        tabList.Remove(newTabPage);
                    }
                    newTabPage.Dispose();
                }
                //  If this is first attempt to create tab, try again.
                //  Else give up and return null.
                if (retries == 0)
                {
                    return(CreateChatTab(key, text, show, ++retries));
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio 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();
            }
        }