2 // Radegast Metaverse Client
\r
3 // Copyright (c) 2009, Radegast Development Team
\r
4 // All rights reserved.
\r
6 // Redistribution and use in source and binary forms, with or without
\r
7 // modification, are permitted provided that the following conditions are met:
\r
9 // * Redistributions of source code must retain the above copyright notice,
\r
10 // this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the distribution.
\r
14 // * Neither the name of the application "Radegast", nor the names of its
\r
15 // contributors may be used to endorse or promote products derived from
\r
16 // this software without specific prior written permission.
\r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 using System.Collections.Generic;
\r
33 using System.ComponentModel;
\r
34 using System.Drawing;
\r
37 using System.Windows.Forms;
\r
38 using Radegast.Netcom;
\r
39 using OpenMetaverse;
\r
43 public partial class IMTabWindow : UserControl
\r
45 private RadegastInstance instance;
\r
46 private RadegastNetcom netcom { get { return instance.Netcom; } }
\r
47 private UUID target;
\r
48 private UUID session;
\r
49 private string toName;
\r
50 private IMTextManager textManager;
\r
51 private bool typing = false;
\r
53 public IMTabWindow(RadegastInstance instance, UUID target, UUID session, string toName)
\r
55 InitializeComponent();
\r
56 Disposed += new EventHandler(IMTabWindow_Disposed);
\r
58 this.instance = instance;
\r
60 this.target = target;
\r
61 this.session = session;
\r
62 this.toName = toName;
\r
64 textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session, toName);
\r
65 ApplyConfig(this.instance.Config.CurrentConfig);
\r
66 this.instance.Config.ConfigApplied += new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);
\r
69 private void IMTabWindow_Disposed(object sender, EventArgs e)
\r
71 this.instance.Config.ConfigApplied -= new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);
\r
75 private void Config_ConfigApplied(object sender, ConfigAppliedEventArgs e)
\r
77 ApplyConfig(e.AppliedConfig);
\r
80 private void ApplyConfig(Config config)
\r
82 if (config.InterfaceStyle == 0) //System
\r
83 toolStrip1.RenderMode = ToolStripRenderMode.System;
\r
84 else if (config.InterfaceStyle == 1) //Office 2003
\r
85 toolStrip1.RenderMode = ToolStripRenderMode.ManagerRenderMode;
\r
88 private void AddNetcomEvents()
\r
90 netcom.ClientLoginStatus += new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);
\r
91 netcom.ClientDisconnected += new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);
\r
94 private void RemoveNetcomEvents()
\r
96 netcom.ClientLoginStatus -= new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);
\r
97 netcom.ClientDisconnected -= new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);
\r
100 private void netcom_ClientLoginStatus(object sender, ClientLoginEventArgs e)
\r
102 if (e.Status != LoginStatus.Success) return;
\r
107 private void netcom_ClientDisconnected(object sender, ClientDisconnectEventArgs e)
\r
112 public void CleanUp()
\r
114 instance.TabConsole.RemoveTab(SessionId.ToString());
\r
115 textManager.CleanUp();
\r
116 textManager = null;
\r
119 private void btnSend_Click(object sender, EventArgs e)
\r
121 netcom.SendInstantMessage(cbxInput.Text, target, session);
\r
122 this.ClearIMInput();
\r
125 private void cbxInput_TextChanged(object sender, EventArgs e)
\r
130 private void RefreshControls()
\r
132 if (!netcom.IsLoggedIn)
\r
134 cbxInput.Enabled = false;
\r
135 btnSend.Enabled = false;
\r
139 if (cbxInput.Text.Length > 0)
\r
141 btnSend.Enabled = true;
\r
145 netcom.SendIMStartTyping(target, session);
\r
151 btnSend.Enabled = false;
\r
152 netcom.SendIMStopTyping(target, session);
\r
157 private void cbxInput_KeyUp(object sender, KeyEventArgs e)
\r
159 if (e.KeyCode != Keys.Enter) return;
\r
160 e.SuppressKeyPress = true;
\r
161 if (cbxInput.Text.Length == 0) return;
\r
163 netcom.SendInstantMessage(cbxInput.Text, target, session);
\r
164 this.ClearIMInput();
\r
167 private void ClearIMInput()
\r
169 cbxInput.Items.Add(cbxInput.Text);
\r
170 cbxInput.Text = string.Empty;
\r
173 public void SelectIMInput()
\r
178 private void rtbIMText_LinkClicked(object sender, LinkClickedEventArgs e)
\r
180 instance.MainForm.processLink(e.LinkText);
\r
183 private void tbtnProfile_Click(object sender, EventArgs e)
\r
185 (new frmProfile(instance, toName, target)).Show();
\r
188 private void cbxInput_KeyDown(object sender, KeyEventArgs e)
\r
190 if (e.KeyCode == Keys.Enter) e.SuppressKeyPress = true;
\r
193 public UUID TargetId
\r
195 get { return target; }
\r
196 set { target = value; }
\r
199 public string TargetName
\r
201 get { return toName; }
\r
202 set { toName = value; }
\r
205 public UUID SessionId
\r
207 get { return session; }
\r
208 set { session = value; }
\r
211 public IMTextManager TextManager
\r
213 get { return textManager; }
\r
214 set { textManager = value; }
\r