2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2014, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
33 using System.Windows.Forms;
34 using System.Threading;
35 using Radegast.Netcom;
40 public partial class ConferenceIMTabWindow : UserControl
42 private RadegastInstance instance;
43 private RadegastNetcom netcom;
45 private IMTextManager textManager;
46 private GridClient client;
47 private List<UUID> participants = new List<UUID>();
48 ManualResetEvent WaitForSessionStart = new ManualResetEvent(false);
49 private List<string> chatHistory = new List<string>();
50 private int chatPointer;
52 public string SessionName { get; set; }
54 public ConferenceIMTabWindow(RadegastInstance instance, UUID session, string sessionName)
56 InitializeComponent();
57 Disposed += new EventHandler(IMTabWindow_Disposed);
59 this.instance = instance;
60 this.client = instance.Client;
61 this.SessionName = sessionName;
62 netcom = this.instance.Netcom;
64 this.session = session;
66 textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), IMTextManagerType.Conference, this.session, sessionName);
69 netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
70 netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
71 instance.GlobalSettings.OnSettingChanged += new Settings.SettingChangedCallback(GlobalSettings_OnSettingChanged);
73 if (!client.Self.GroupChatSessions.ContainsKey(session))
75 client.Self.ChatterBoxAcceptInvite(session);
81 private void IMTabWindow_Disposed(object sender, EventArgs e)
83 netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
84 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
85 instance.GlobalSettings.OnSettingChanged -= new Settings.SettingChangedCallback(GlobalSettings_OnSettingChanged);
89 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
91 if (e.Status != LoginStatus.Success) return;
98 float size = (float)instance.GlobalSettings["chat_font_size"].AsReal();
99 cbxInput.Font = ChatConsole.ChangeFontSize(cbxInput.Font, size);
100 rtbIMText.Font = ChatConsole.ChangeFontSize(rtbIMText.Font, size);
101 textManager.ReprintAllText();
104 void GlobalSettings_OnSettingChanged(object sender, SettingsEventArgs e)
106 if (e.Key == "chat_font_size")
110 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
115 public void CleanUp()
117 textManager.CleanUp();
121 private void btnSend_Click(object sender, EventArgs e)
123 if (cbxInput.Text.Length == 0) return;
125 SendMessage(cbxInput.Text);
129 private void cbxInput_TextChanged(object sender, EventArgs e)
134 private void RefreshControls()
136 if (!netcom.IsLoggedIn)
138 cbxInput.Enabled = false;
139 btnSend.Enabled = false;
143 cbxInput.Enabled = true;
145 if (cbxInput.Text.Length > 0)
147 btnSend.Enabled = true;
151 btnSend.Enabled = false;
155 void ChatHistoryPrev()
157 if (chatPointer == 0) return;
159 if (chatHistory.Count > chatPointer)
161 cbxInput.Text = chatHistory[chatPointer];
162 cbxInput.SelectionStart = cbxInput.Text.Length;
163 cbxInput.SelectionLength = 0;
167 void ChatHistoryNext()
169 if (chatPointer == chatHistory.Count) return;
171 if (chatPointer == chatHistory.Count)
173 cbxInput.Text = string.Empty;
176 cbxInput.Text = chatHistory[chatPointer];
177 cbxInput.SelectionStart = cbxInput.Text.Length;
178 cbxInput.SelectionLength = 0;
181 private void cbxInput_KeyDown(object sender, KeyEventArgs e)
183 if (e.KeyCode == Keys.Up && e.Modifiers == Keys.Control)
185 e.Handled = e.SuppressKeyPress = true;
190 if (e.KeyCode == Keys.Down && e.Modifiers == Keys.Control)
192 e.Handled = e.SuppressKeyPress = true;
197 if (e.KeyCode != Keys.Enter) return;
198 e.Handled = e.SuppressKeyPress = true;
199 if (cbxInput.Text.Length == 0) return;
201 string message = cbxInput.Text;
203 SendMessage(message);
208 private void SendMessage(string msg)
210 if (msg == string.Empty) return;
212 chatHistory.Add(msg);
213 chatPointer = chatHistory.Count;
215 if (instance.RLV.RestictionActive("sendim")) return;
217 string message = msg.Replace(ChatInputBox.NewlineMarker, "\n");
219 if (instance.GlobalSettings["mu_emotes"].AsBoolean() && message.StartsWith(":"))
221 message = "/me " + message.Substring(1);
224 if (message.Length > 1023)
226 message = message.Remove(1023);
228 if (message.Length > 0)
230 client.Self.InstantMessageGroup(session, message);
234 private void ClearIMInput()
236 cbxInput.Text = string.Empty;
239 public void SelectIMInput()
244 private void rtbIMText_LinkClicked(object sender, LinkClickedEventArgs e)
246 instance.MainForm.ProcessLink(e.LinkText);
249 public UUID SessionId
251 get { return session; }
252 set { session = value; }
255 public IMTextManager TextManager
257 get { return textManager; }
258 set { textManager = value; }
261 private void cbxInput_VisibleChanged(object sender, EventArgs e)
263 if (Visible) cbxInput.Focus();
266 private void cbxInput_SizeChanged(object sender, EventArgs e)
268 pnlChatInput.Height = cbxInput.Height + 7;