📄 tree_widget_group.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Core;
using System;
using System.Drawing;
using System.Windows.Forms;
public class tree_widget_group : tree_widget.item_type
{
private int m_buddy_count;
private bool m_fNeedReCalcNameTextWidth = true;
private bool m_focused;
private object m_group;
private int m_inner_space = 2;
private int m_nNameTextWidth;
private int m_online_count;
public tree_widget_group(object contact_group)
{
if (contact_group == null)
{
throw new ArgumentNullException("contact_group");
}
this.update_group_info(contact_group, ContactGroupEventType.NameChanged, false);
}
internal override void dispose()
{
this.m_group = null;
}
internal override void draw(Graphics g, Rectangle rc, tree_widget.item_state state)
{
if (this.group != null)
{
Image image;
this.m_focused = tree_widget.item_state.focused == (state & tree_widget.item_state.focused);
Rectangle rect = Rectangle.Empty;
if (base.expand)
{
image = base.host.expand_image;
}
else
{
image = base.host.collapse_image;
}
if (image != null)
{
int num = (base.host.indent - image.Width) / 2;
int num2 = (rc.Height - image.Height) / 2;
rect = Rectangle.FromLTRB(rc.Left + num, rc.Top + num2, (rc.Left + num) + image.Width, (rc.Top + num2) + image.Height);
g.DrawImage(image, rect);
}
using (StringFormat format = new StringFormat())
{
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.FormatFlags |= StringFormatFlags.NoWrap;
format.Trimming = StringTrimming.EllipsisCharacter;
int left = rc.Left + base.host.indent;
int top = rc.Top + this.m_inner_space;
int right = rc.Right - this.m_inner_space;
int bottom = rc.Bottom - this.m_inner_space;
if (right > left)
{
SizeF ef = new SizeF(0f, 0f);
SizeF ef2 = new SizeF(0f, 0f);
string text = null;
if (0 < this.m_buddy_count)
{
if (this.group is ContactGroupBase)
{
if (-1 == (this.group as ContactGroupBase).Id)
{
text = string.Format("({0})", this.m_buddy_count);
}
else
{
text = string.Format("({0}/{1})", this.m_online_count, this.m_buddy_count);
}
}
else
{
if (!(this.group is SystemFixedContactGroup))
{
throw new Exception("Unsupport group type");
}
text = string.Format("({0})", this.m_buddy_count);
}
ef2 = g.MeasureString(text, base.host.Font);
}
using (Font font = new Font(base.host.Font, FontStyle.Bold))
{
if (this.m_fNeedReCalcNameTextWidth)
{
ef = g.MeasureString(this.name, font);
this.m_nNameTextWidth = ((int) ef.Width) + 2;
this.m_fNeedReCalcNameTextWidth = false;
}
}
if ((right - left) < ((this.m_nNameTextWidth + ef2.Width) + this.m_inner_space))
{
left = right - ((int) Math.Ceiling((double) ef2.Width));
g.DrawString(text, base.host.Font, Brushes.DimGray, Rectangle.FromLTRB(left, top, right, bottom), format);
right = left - this.m_inner_space;
left = rc.Left + base.host.indent;
using (Font font2 = new Font(base.host.Font, FontStyle.Bold))
{
g.DrawString(this.name, font2, Brushes.Black, Rectangle.FromLTRB(left, top, right, bottom), format);
return;
}
}
left = rc.Left + base.host.indent;
using (Font font3 = new Font(base.host.Font, FontStyle.Bold))
{
g.DrawString(this.name, font3, Brushes.Black, Rectangle.FromLTRB(left, top, right, bottom), format);
}
left += this.m_nNameTextWidth + this.m_inner_space;
g.DrawString(text, base.host.Font, Brushes.DimGray, Rectangle.FromLTRB(left, top, right, bottom), format);
}
}
}
}
internal override void on_after_edit(string strNewText, object context)
{
if (0 < strNewText.Length)
{
if (!(this.m_group is ContactGroup))
{
throw new Exception("This group type can not been renamed.");
}
if (this.m_group == null)
{
throw new Exception("m_group is null");
}
AsyncBizOperation op = new AsyncBizOperation();
(this.m_group as ContactGroup).AsyncUpdate(strNewText, op);
}
}
internal override void on_before_edit(object initParam, ref Rectangle rcEdit, ref string strInitText, ref object context, ref bool fCancel)
{
if (this.m_group == null)
{
fCancel = true;
}
else if (this.m_group is SystemFixedContactGroup)
{
fCancel = true;
}
else if ((this.m_group is ContactGroupBase) && (-1 == (this.m_group as ContactGroupBase).Id))
{
fCancel = true;
}
else
{
Rectangle rectangle = Rectangle.FromLTRB(rcEdit.Left + base.host.indent, rcEdit.Top + this.m_inner_space, ((rcEdit.Left + this.m_nNameTextWidth) + base.host.indent) + 6, rcEdit.Bottom - this.m_inner_space);
rcEdit = Rectangle.FromLTRB(rectangle.Left, rcEdit.Top, rectangle.Right, rcEdit.Bottom);
strInitText = this.name;
}
}
internal override void on_before_edit(Rectangle rcItem, Point ptClick, ref Rectangle rcEdit, ref string strInitText, ref object context, ref bool fCancel)
{
fCancel = true;
}
internal override void on_mousedown(MouseEventArgs args, Rectangle rc)
{
base.on_mousedown(args, rc);
if (MouseButtons.Left == args.Button)
{
base.expand = !base.expand;
base.host.paint();
}
}
internal override void on_mousemove(MouseEventArgs args, Rectangle rc)
{
base.on_mousemove(args, rc);
base.host.Cursor = Cursors.Hand;
}
public void update_group_info(ContactGroupEventType event_type, bool fRepaint)
{
this.update_group_info(this.m_group, event_type, fRepaint);
}
public void update_group_info(object contact_group, ContactGroupEventType event_type, bool fRepaint)
{
if (contact_group == null)
{
throw new ArgumentNullException("contact_group");
}
this.m_group = contact_group;
if (this.m_group is ContactGroup)
{
ContactGroup group = this.m_group as ContactGroup;
if (ContactGroupEventType.NameChanged == event_type)
{
this.name = group.DisplayName;
}
else if (ContactGroupEventType.ContactCountChanged == event_type)
{
this.buddy_count = group.Contacts.Count;
}
}
else
{
if (!(this.m_group is SystemFixedContactGroup))
{
throw new ArgumentException("Unsupported group type", "contact_group");
}
SystemFixedContactGroup group2 = this.m_group as SystemFixedContactGroup;
if (ContactGroupEventType.NameChanged == event_type)
{
this.name = group2.Name;
}
else if (ContactGroupEventType.ContactCountChanged == event_type)
{
this.buddy_count = group2.Contacts.Count;
this.online_count = 0;
}
}
if (fRepaint && (((base.host != null) && base.host.IsHandleCreated) && !base.host.IsDisposed))
{
base.host.Invalidate(base.bounds);
}
}
public int buddy_count
{
get
{
return this.m_buddy_count;
}
set
{
this.m_buddy_count = value;
}
}
public object group
{
get
{
return this.m_group;
}
}
public override int height
{
get
{
return 20;
}
}
public string name
{
get
{
return base.text;
}
set
{
base.text = value;
this.m_fNeedReCalcNameTextWidth = true;
}
}
public int online_count
{
get
{
return this.m_online_count;
}
set
{
this.m_online_count = value;
}
}
public override int width
{
get
{
return 0;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -