-// \r
-// Radegast Metaverse Client\r
-// Copyright (c) 2009, Radegast Development Team\r
-// All rights reserved.\r
-// \r
-// Redistribution and use in source and binary forms, with or without\r
-// modification, are permitted provided that the following conditions are met:\r
-// \r
-// * Redistributions of source code must retain the above copyright notice,\r
-// this list of conditions and the following disclaimer.\r
-// * Redistributions in binary form must reproduce the above copyright\r
-// notice, this list of conditions and the following disclaimer in the\r
-// documentation and/or other materials provided with the distribution.\r
-// * Neither the name of the application "Radegast", nor the names of its\r
-// contributors may be used to endorse or promote products derived from\r
-// this software without specific prior written permission.\r
-// \r
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-//\r
-// $Id$\r
-//\r
-using System;\r
-using System.Collections.Generic;\r
-using System.ComponentModel;\r
-using System.Drawing;\r
-using System.Data;\r
-using System.Text;\r
-using System.Windows.Forms;\r
-using Radegast.Netcom;\r
-using OpenMetaverse;\r
-\r
-namespace Radegast\r
-{\r
- public partial class IMTabWindow : UserControl\r
- {\r
- private RadegastInstance instance;\r
- private RadegastNetcom netcom { get { return instance.Netcom; } }\r
- private UUID target;\r
- private UUID session;\r
- private string toName;\r
- private IMTextManager textManager;\r
- private bool typing = false;\r
-\r
- public IMTabWindow(RadegastInstance instance, UUID target, UUID session, string toName)\r
- {\r
- InitializeComponent();\r
- Disposed += new EventHandler(IMTabWindow_Disposed);\r
-\r
- this.instance = instance;\r
-\r
- this.target = target;\r
- this.session = session;\r
- this.toName = toName;\r
-\r
- textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session, toName);\r
- ApplyConfig(this.instance.Config.CurrentConfig);\r
- this.instance.Config.ConfigApplied += new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);\r
- }\r
-\r
- private void IMTabWindow_Disposed(object sender, EventArgs e)\r
- {\r
- this.instance.Config.ConfigApplied -= new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);\r
- CleanUp();\r
- }\r
-\r
- private void Config_ConfigApplied(object sender, ConfigAppliedEventArgs e)\r
- {\r
- ApplyConfig(e.AppliedConfig);\r
- }\r
-\r
- private void ApplyConfig(Config config)\r
- {\r
- if (config.InterfaceStyle == 0) //System\r
- toolStrip1.RenderMode = ToolStripRenderMode.System;\r
- else if (config.InterfaceStyle == 1) //Office 2003\r
- toolStrip1.RenderMode = ToolStripRenderMode.ManagerRenderMode;\r
- }\r
-\r
- private void AddNetcomEvents()\r
- {\r
- netcom.ClientLoginStatus += new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);\r
- netcom.ClientDisconnected += new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);\r
- }\r
-\r
- private void RemoveNetcomEvents()\r
- {\r
- netcom.ClientLoginStatus -= new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);\r
- netcom.ClientDisconnected -= new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);\r
- }\r
-\r
- private void netcom_ClientLoginStatus(object sender, ClientLoginEventArgs e)\r
- {\r
- if (e.Status != LoginStatus.Success) return;\r
-\r
- RefreshControls();\r
- }\r
-\r
- private void netcom_ClientDisconnected(object sender, ClientDisconnectEventArgs e)\r
- {\r
- RefreshControls();\r
- }\r
-\r
- public void CleanUp()\r
- {\r
- instance.TabConsole.RemoveTab(SessionId.ToString());\r
- textManager.CleanUp();\r
- textManager = null;\r
- }\r
-\r
- private void btnSend_Click(object sender, EventArgs e)\r
- {\r
- netcom.SendInstantMessage(cbxInput.Text, target, session);\r
- this.ClearIMInput();\r
- }\r
-\r
- private void cbxInput_TextChanged(object sender, EventArgs e)\r
- {\r
- RefreshControls();\r
- }\r
-\r
- private void RefreshControls()\r
- {\r
- if (!netcom.IsLoggedIn)\r
- {\r
- cbxInput.Enabled = false;\r
- btnSend.Enabled = false;\r
- return;\r
- }\r
-\r
- if (cbxInput.Text.Length > 0)\r
- {\r
- btnSend.Enabled = true;\r
-\r
- if (!typing)\r
- {\r
- netcom.SendIMStartTyping(target, session);\r
- typing = true;\r
- }\r
- }\r
- else\r
- {\r
- btnSend.Enabled = false;\r
- netcom.SendIMStopTyping(target, session);\r
- typing = false;\r
- }\r
- }\r
-\r
- private void cbxInput_KeyUp(object sender, KeyEventArgs e)\r
- {\r
- if (e.KeyCode != Keys.Enter) return;\r
- e.SuppressKeyPress = true;\r
- if (cbxInput.Text.Length == 0) return;\r
-\r
- netcom.SendInstantMessage(cbxInput.Text, target, session);\r
- this.ClearIMInput();\r
- }\r
-\r
- private void ClearIMInput()\r
- {\r
- cbxInput.Items.Add(cbxInput.Text);\r
- cbxInput.Text = string.Empty;\r
- }\r
-\r
- public void SelectIMInput()\r
- {\r
- cbxInput.Select();\r
- }\r
-\r
- private void rtbIMText_LinkClicked(object sender, LinkClickedEventArgs e)\r
- {\r
- instance.MainForm.processLink(e.LinkText);\r
- }\r
-\r
- private void tbtnProfile_Click(object sender, EventArgs e)\r
- {\r
- (new frmProfile(instance, toName, target)).Show();\r
- }\r
-\r
- private void cbxInput_KeyDown(object sender, KeyEventArgs e)\r
- {\r
- if (e.KeyCode == Keys.Enter) e.SuppressKeyPress = true;\r
- }\r
-\r
- public UUID TargetId\r
- {\r
- get { return target; }\r
- set { target = value; }\r
- }\r
-\r
- public string TargetName\r
- {\r
- get { return toName; }\r
- set { toName = value; }\r
- }\r
-\r
- public UUID SessionId\r
- {\r
- get { return session; }\r
- set { session = value; }\r
- }\r
-\r
- public IMTextManager TextManager\r
- {\r
- get { return textManager; }\r
- set { textManager = value; }\r
- }\r
- }\r
-}\r
+//
+// Radegast Metaverse Client
+// Copyright (c) 2009-2014, Radegast Development Team
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the application "Radegast", nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// $Id$
+//
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using Radegast.Netcom;
+using OpenMetaverse;
+
+namespace Radegast
+{
+ public partial class IMTabWindow : UserControl
+ {
+ private RadegastInstance instance;
+ private RadegastNetcom netcom { get { return instance.Netcom; } }
+ private UUID target;
+ private UUID session;
+ private string toName;
+ private IMTextManager textManager;
+ private bool typing = false;
+ private List<string> chatHistory = new List<string>();
+ private int chatPointer;
+
+ public IMTabWindow(RadegastInstance instance, UUID target, UUID session, string toName)
+ {
+ InitializeComponent();
+ Disposed += new EventHandler(IMTabWindow_Disposed);
+
+ this.instance = instance;
+
+ this.target = target;
+ this.session = session;
+ this.toName = toName;
+
+ textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), IMTextManagerType.Agent, this.session, toName);
+
+ AddNetcomEvents();
+
+ UpdateFontSize();
+ }
+
+ private void IMTabWindow_Disposed(object sender, EventArgs e)
+ {
+ CleanUp();
+ }
+
+ private void AddNetcomEvents()
+ {
+ netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
+ netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
+ instance.GlobalSettings.OnSettingChanged += new Settings.SettingChangedCallback(GlobalSettings_OnSettingChanged);
+ }
+
+ private void RemoveNetcomEvents()
+ {
+ netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
+ netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
+ instance.GlobalSettings.OnSettingChanged -= new Settings.SettingChangedCallback(GlobalSettings_OnSettingChanged);
+ }
+
+ void UpdateFontSize()
+ {
+ float size = (float)instance.GlobalSettings["chat_font_size"].AsReal();
+ cbxInput.Font = ChatConsole.ChangeFontSize(cbxInput.Font, size);
+ rtbIMText.Font = ChatConsole.ChangeFontSize(rtbIMText.Font, size);
+ textManager.ReprintAllText();
+ }
+
+ void GlobalSettings_OnSettingChanged(object sender, SettingsEventArgs e)
+ {
+ if (e.Key == "chat_font_size")
+ UpdateFontSize();
+ }
+
+ private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
+ {
+ if (e.Status != LoginStatus.Success) return;
+
+ RefreshControls();
+ }
+
+ private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
+ {
+ RefreshControls();
+ }
+
+ public void CleanUp()
+ {
+ instance.TabConsole.RemoveTab(SessionId.ToString());
+ textManager.CleanUp();
+ textManager = null;
+ RemoveNetcomEvents();
+ }
+
+ private void btnSend_Click(object sender, EventArgs e)
+ {
+ ProcessInput();
+ }
+
+ private void cbxInput_TextChanged(object sender, EventArgs e)
+ {
+ RefreshControls();
+ }
+
+ private void RefreshControls()
+ {
+ if (!netcom.IsLoggedIn)
+ {
+ cbxInput.Enabled = false;
+ btnSend.Enabled = false;
+ return;
+ }
+
+ cbxInput.Enabled = true;
+
+ if (cbxInput.Text.Length > 0)
+ {
+ btnSend.Enabled = true;
+
+ if (!typing)
+ {
+ netcom.SendIMStartTyping(target, session);
+ typing = true;
+ }
+ }
+ else
+ {
+ btnSend.Enabled = false;
+ netcom.SendIMStopTyping(target, session);
+ typing = false;
+ }
+ }
+
+ private void ProcessInput()
+ {
+ if (cbxInput.Text.Length == 0) return;
+
+ chatHistory.Add(cbxInput.Text);
+ chatPointer = chatHistory.Count;
+
+ string msg = cbxInput.Text.Replace(ChatInputBox.NewlineMarker, "\n");
+
+ if (instance.GlobalSettings["mu_emotes"].AsBoolean() && msg.StartsWith(":"))
+ {
+ msg = "/me " + msg.Substring(1);
+ }
+
+ if (instance.RLV.RestictionActive("sendim", target.ToString()))
+ msg = "*** IM blocked by sender's viewer";
+
+ netcom.SendInstantMessage(msg, target, session);
+ this.ClearIMInput();
+ }
+
+ void ChatHistoryPrev()
+ {
+ if (chatPointer == 0) return;
+ chatPointer--;
+ if (chatHistory.Count > chatPointer)
+ {
+ cbxInput.Text = chatHistory[chatPointer];
+ cbxInput.SelectionStart = cbxInput.Text.Length;
+ cbxInput.SelectionLength = 0;
+ }
+ }
+
+ void ChatHistoryNext()
+ {
+ if (chatPointer == chatHistory.Count) return;
+ chatPointer++;
+ if (chatPointer == chatHistory.Count)
+ {
+ cbxInput.Text = string.Empty;
+ return;
+ }
+ cbxInput.Text = chatHistory[chatPointer];
+ cbxInput.SelectionStart = cbxInput.Text.Length;
+ cbxInput.SelectionLength = 0;
+ }
+
+ private void cbxInput_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Up && e.Modifiers == Keys.Control)
+ {
+ e.Handled = e.SuppressKeyPress = true;
+ ChatHistoryPrev();
+ return;
+ }
+
+ if (e.KeyCode == Keys.Down && e.Modifiers == Keys.Control)
+ {
+ e.Handled = e.SuppressKeyPress = true;
+ ChatHistoryNext();
+ return;
+ }
+
+ if (e.KeyCode != Keys.Enter) return;
+ e.Handled = e.SuppressKeyPress = true;
+ ProcessInput();
+ }
+
+ private void ClearIMInput()
+ {
+ cbxInput.Text = string.Empty;
+ }
+
+ public void SelectIMInput()
+ {
+ cbxInput.Select();
+ }
+
+ private void rtbIMText_LinkClicked(object sender, LinkClickedEventArgs e)
+ {
+ instance.MainForm.ProcessLink(e.LinkText);
+ }
+
+ private void tbtnProfile_Click(object sender, EventArgs e)
+ {
+ instance.MainForm.ShowAgentProfile(toName, target);
+ }
+
+ private void btnOfferTeleport_Click(object sender, EventArgs e)
+ {
+ instance.Client.Self.SendTeleportLure(target, "Join me in " + instance.Client.Network.CurrentSim.Name + "!");
+ }
+
+ private void btnPay_Click(object sender, EventArgs e)
+ {
+ (new frmPay(instance, target, toName, false)).ShowDialog();
+ }
+
+ public UUID TargetId
+ {
+ get { return target; }
+ set { target = value; }
+ }
+
+ public string TargetName
+ {
+ get { return toName; }
+ set { toName = value; }
+ }
+
+ public UUID SessionId
+ {
+ get { return session; }
+ set { session = value; }
+ }
+
+ public IMTextManager TextManager
+ {
+ get { return textManager; }
+ set { textManager = value; }
+ }
+
+ private void cbxInput_VisibleChanged(object sender, EventArgs e)
+ {
+ if (Visible) cbxInput.Focus();
+ }
+
+ private void cbxInput_SizeChanged(object sender, EventArgs e)
+ {
+ pnlChatInput.Height = cbxInput.Height + 9;
+ }
+
+ private void cbAlwaysDing_CheckedChanged(object sender, EventArgs e)
+ {
+ textManager.DingOnAllIncoming = ((CheckBox)sender).Checked;
+ }
+ }
+}