📄 notifywindowaddbuddyresult.cs
字号:
namespace Imps.Client.Pc.BizControls.NotifyWindows.Templates
{
using Imps.Client;
using Imps.Client.Core;
using Imps.Client.Pc;
using Imps.Client.Pc.BizControls.NotifyWindows;
using Imps.Client.Resource;
using Imps.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.CompilerServices;
public class NotifyWindowAddBuddyResult : NotifyWindowTemplateBase
{
private Imps.Client.Core.Contact _contact;
protected NotifyWindowLabel _contentLabel;
protected string _contentText = "";
private bool _isAgree;
private bool _isByMobileNo;
protected Image _portraitImage;
private const int MAXLENGTH = 5;
public event NotifyWindowEventHandler ContentClick;
public NotifyWindowAddBuddyResult(Imps.Client.Core.Contact contact, bool isByMobileNo, Image backgroundImage)
{
if (contact != null)
{
this._contact = contact;
this._isByMobileNo = isByMobileNo;
int? relationStatus = contact.RelationStatus;
this._isAgree = (relationStatus.GetValueOrDefault() == 1) && relationStatus.get_HasValue();
this._contentText = this.GenerateMessage();
base.BackgroundImageNotify = backgroundImage;
try
{
this._portraitImage = contact.PersonalInfo.Portrait;
}
catch
{
if (contact.PersonalInfo.Gender == Gender.Female)
{
this._portraitImage = ImpsPortrait.GetGirlPortrait(0x60, 0x60);
}
else
{
this._portraitImage = ImpsPortrait.GetBoyPortrait(0x60, 0x60);
}
}
base.InitContent();
}
}
private void contentLabel_Click(object sender, NotifyWindowEventArgs e)
{
this.OnContentClick(e);
}
protected override void CreateContent(NotifyWindowContent content)
{
Rectangle textRectangle = new Rectangle(content.Rectangle.X + 0x49, content.Rectangle.Y + ((content.Rectangle.Height - 60) / 2), 0x88, 60);
this._contentLabel = new NotifyWindowLabel(this._contentText, textRectangle);
int? relationStatus = this._contact.RelationStatus;
this._contentLabel.Clickable = (relationStatus.GetValueOrDefault() == 1) && relationStatus.get_HasValue();
this._contentLabel.Click += new NotifyWindowEventHandler(this.contentLabel_Click);
content.Elements.Add(this._contentLabel);
Rectangle rectangle = new Rectangle(content.Rectangle.X + 8, content.Rectangle.Y + ((content.Rectangle.Height - 60) / 2), 60, 60);
Bitmap bitmap = (Bitmap) ImpsResources.GetImage("Images.48.png");
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImage(this._portraitImage, 8, 8, 0x30, 0x30);
}
NotifyWindowImage image = new NotifyWindowImage(rectangle, bitmap);
content.Elements.Add(image);
}
protected string GenerateMessage()
{
string text = string.Empty;
if (this._isAgree)
{
text = StringTable.NotifyWindow.AddBuddyResult_Agree;
}
else
{
text = StringTable.NotifyWindow.AddBuddyResult_Reject;
}
if (!this._isByMobileNo)
{
return string.Format(StringTable.NotifyWindow.AddBuddyResult_Main_SID, this.shrinkDesc(this._contact.DisplayName), this._contact.Uri.Sid.ToString(), text);
}
if (string.IsNullOrEmpty(this._contact.PersonalInfo.MobileNo))
{
return string.Format("{0}\r\n{1}", this.shrinkDesc(this._contact.DisplayName), text);
}
string text2 = this.shrinkDesc(this._contact.DisplayName);
if (text2.Length > 2)
{
return string.Format("{0}\r\n({1}{2})\r\n{3}", new object[] { text2, StringTable.NotifyWindow.AddBuddyResult_Main_MobileNo, this._contact.PersonalInfo.MobileNo.ToString(), text });
}
return string.Format("{0}{1}{2})\r\n{3}", new object[] { text2, StringTable.NotifyWindow.AddBuddyResult_Main_MobileNo, this._contact.PersonalInfo.MobileNo.ToString(), text });
}
protected string GenerateTitle()
{
return StringTable.NotifyWindow.AddBuddyResult_Title;
}
public void OnContentClick(NotifyWindowEventArgs e)
{
if (this.ContentClick != null)
{
this.ContentClick(this, e);
}
}
private string shrinkDesc(string desc)
{
string text = "";
float num = 100f;
float num2 = 0f;
List<object> list = EmoticonParser.ParseString(null, desc);
rich_string _string = new rich_string(desc);
Graphics g = Graphics.FromHdc(InnerWin32.GetWindowDC(base.Handle));
if (_string.MeasureText(g, this.Font).Width > num)
{
num -= g.MeasureString("...", this.Font).Width - 10f;
}
List<object>.Enumerator enumerator = list.GetEnumerator();
try
{
Label_0133:
while (enumerator.MoveNext())
{
object obj2 = enumerator.get_Current();
if (obj2 is Emoticon)
{
if ((num2 + 16f) >= num)
{
goto Label_014F;
}
text = text + ((Emoticon) obj2).Key;
num2 += 17f;
}
else if (obj2 is string)
{
string text2 = (string) obj2;
SizeF empty = SizeF.Empty;
for (int i = text2.Length; i > 0; i--)
{
string text3 = text2.Substring(0, i);
empty = g.MeasureString(text3, this.Font);
if ((num2 + empty.Width) <= num)
{
text = text + text3;
num2 += empty.Width + 1f;
goto Label_0133;
}
}
}
}
}
finally
{
enumerator.Dispose();
}
Label_014F:
if (num < 100f)
{
text = text + "...";
}
return text;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -