📄 grouptree_group.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Core;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class grouptree_group : tree_widget.item_type
{
private bool _membersLoaded;
private PersonalGroup m_group;
private int m_inner_space = 2;
private area_type m_last_leftdown_area;
private area_type m_mouse_location_area = area_type.outside;
public event group_click_portrait_handler on_group_click_portrait;
public grouptree_group(PersonalGroup group)
{
if (group == null)
{
throw new ArgumentNullException("group");
}
this.m_group = group;
base.expand = false;
}
internal override void dispose()
{
base.dispose();
this.m_group = null;
}
internal override void draw(Graphics g, Rectangle rcItem, tree_widget.item_state state)
{
if (this.m_group != null)
{
if (this.draw_detail)
{
this.draw_complete(g, rcItem, state);
}
else
{
this.draw_simple(g, rcItem, state);
}
}
}
private void draw_complete(Graphics g, Rectangle rc, tree_widget.item_state state)
{
int num = this.m_inner_space * 2;
int x = 0;
int y = 0;
Rectangle rect = new Rectangle(rc.Left + num, rc.Top + ((rc.Height - 40) / 2), 40, 40);
if ((rect.Left < rect.Right) && (rect.Top < rect.Bottom))
{
using (Pen pen = new Pen(Color.FromArgb(0xff, 180, 0xc6, 0xd6)))
{
if (this.m_group.GroupInfo.Portrait.Value != null)
{
g.DrawImage(this.m_group.GroupInfo.Portrait.Value, rect);
}
g.DrawRectangle(pen, rect);
}
}
using (StringFormat format = new StringFormat())
{
Rectangle layoutRectangle;
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.FormatFlags |= StringFormatFlags.NoWrap;
format.Trimming = StringTrimming.EllipsisCharacter;
Image image = base.expand ? base.host.expand_image : base.host.collapse_image;
int width = image.Width;
int height = image.Height;
using (Font font = new Font(base.host.Font, FontStyle.Bold))
{
int num6 = font.Height + this.m_inner_space;
using (Brush brush = new SolidBrush(Color.Black))
{
layoutRectangle = Rectangle.FromLTRB((rect.Right + num) + ((image != null) ? (num + width) : 0), rc.Top + this.m_inner_space, (rc.Right - this.m_inner_space) - ((this.m_group.UserInfo.ApproveStateImage != null) ? (this.m_group.UserInfo.ApproveStateImage.Width + this.m_inner_space) : 0), (rc.Top + this.m_inner_space) + num6);
g.DrawString((string) this.m_group.GroupInfo.Name, font, brush, layoutRectangle, format);
}
}
if (image != null)
{
x = rect.Right + num;
y = ((layoutRectangle.Top + layoutRectangle.Bottom) - height) / 2;
g.DrawImage(image, x, y, width, height);
}
if (this.m_group.UserInfo.ApproveStateImage != null)
{
width = this.m_group.UserInfo.ApproveStateImage.Width;
height = this.m_group.UserInfo.ApproveStateImage.Height;
x = (rc.Right - this.m_inner_space) - width;
y = ((layoutRectangle.Top + layoutRectangle.Bottom) - height) / 2;
g.DrawImage(this.m_group.UserInfo.ApproveStateImage, x, y, width, height);
}
x = rect.Right + num;
int num7 = (rc.Right - this.m_inner_space) - x;
int num8 = 2 * (base.host.Font.Height + 1);
int num9 = (rc.Bottom - layoutRectangle.Bottom) - this.m_inner_space;
if (num8 > num9)
{
num8 = base.host.Font.Height + 1;
}
y = layoutRectangle.Bottom + (((rc.Bottom - layoutRectangle.Bottom) - num8) / 2);
Rectangle rectangle3 = new Rectangle(x, y, num7, num8);
using (Brush brush2 = new SolidBrush(Color.Gray))
{
string introduce = (string) this.m_group.GroupInfo.Introduce;
g.MeasureString(introduce, base.host.Font);
string[] textArray = new string[] { "\r\n" };
string[] textArray2 = introduce.Split(textArray, 0);
for (int i = 0; i < textArray2.Length; i++)
{
SizeF ef = g.MeasureString(textArray2[i], base.host.Font);
if (((((i + 2) * ef.Height) <= rectangle3.Height) || (ef.Width > rectangle3.Width)) || (textArray2.Length == 1))
{
g.DrawString(textArray2[i], base.host.Font, brush2, rectangle3, format);
rectangle3.Y += ((int) ef.Width) + 1;
}
else
{
format.Trimming = StringTrimming.None;
if (g.MeasureString(textArray2[i] + "...", base.host.Font).Width < rectangle3.Width)
{
g.DrawString(textArray2[i] + "...", base.host.Font, brush2, rectangle3, format);
}
else
{
for (int j = textArray2[i].Length - 1; j >= 0; j--)
{
string text2 = textArray2[i].Substring(0, j);
if (g.MeasureString(text2 + "...", base.host.Font, 0x7fffffff, format).Width <= rectangle3.Width)
{
g.DrawString(text2 + "...", base.host.Font, brush2, rectangle3, format);
break;
}
}
}
return;
}
}
}
}
}
private void draw_simple(Graphics g, Rectangle rc, tree_widget.item_state state)
{
Image image = base.expand ? base.host.expand_image : base.host.collapse_image;
if (image != null)
{
int left = rc.Left + ((base.host.indent - image.Width) / 2);
int top = rc.Top + ((rc.Height - image.Height) / 2);
Rectangle rect = Rectangle.FromLTRB(left, top, left + image.Width, top + 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;
Rectangle layoutRectangle = Rectangle.FromLTRB(rc.Left + base.host.indent, rc.Top, (rc.Right - this.m_inner_space) - ((this.m_group.UserInfo.ApproveStateImage != null) ? (this.m_group.UserInfo.ApproveStateImage.Width + this.m_inner_space) : 0), rc.Bottom);
using (Brush brush = new SolidBrush(Color.Black))
{
using (Font font = new Font(base.host.Font, FontStyle.Bold))
{
g.DrawString((string) this.m_group.GroupInfo.Name, font, brush, layoutRectangle, format);
}
}
if (this.m_group.UserInfo.ApproveStateImage != null)
{
int num3 = (rc.Right - this.m_inner_space) - this.m_group.UserInfo.ApproveStateImage.Width;
int num4 = rc.Top + ((rc.Height - this.m_group.UserInfo.ApproveStateImage.Height) / 2);
Rectangle rectangle3 = Rectangle.FromLTRB(num3, num4, num3 + this.m_group.UserInfo.ApproveStateImage.Width, num4 + this.m_group.UserInfo.ApproveStateImage.Height);
g.DrawImage(this.m_group.UserInfo.ApproveStateImage, rectangle3);
}
}
}
internal override void on_before_edit(object initParam, ref Rectangle rcEdit, ref string strInitText, ref object context, ref bool fCancel)
{
fCancel = true;
}
internal override void on_mousedown(MouseEventArgs args, Rectangle rcItem)
{
base.on_mousedown(args, rcItem);
if (MouseButtons.Left == args.Button)
{
this.last_leftdown_area = this.test_area(args.get_Location(), rcItem);
}
else
{
this.last_leftdown_area = area_type.outside;
}
if ((area_type.portrait != this.last_leftdown_area) && (args.Button == MouseButtons.Left))
{
base.expand = !base.expand;
base.host.paint();
}
}
internal override void on_mousemove(MouseEventArgs args, Rectangle rcItem)
{
base.on_mousemove(args, rcItem);
this.mouse_location_area = this.test_area(args.get_Location(), rcItem);
}
internal override bool on_mouseup(MouseEventArgs args, Rectangle rcItem)
{
base.on_mouseup(args, rcItem);
if (((MouseButtons.Left == args.Button) && (this.test_area(args.get_Location(), rcItem) == this.last_leftdown_area)) && ((area_type.portrait == this.last_leftdown_area) && (this.on_group_click_portrait != null)))
{
this.on_group_click_portrait(this);
return true;
}
return false;
}
private area_type test_area(Point location, Rectangle rcItem)
{
if (!rcItem.Contains(location))
{
return area_type.outside;
}
area_type normal = area_type.normal;
if (this.draw_detail)
{
Rectangle rectangle = Rectangle.FromLTRB(rcItem.Left + (this.m_inner_space * 2), rcItem.Top + ((rcItem.Height - 40) / 2), (rcItem.Left + (this.m_inner_space * 2)) + 40, (rcItem.Top + ((rcItem.Height - 40) / 2)) + 40);
if (rectangle.Contains(location))
{
return area_type.portrait;
}
Image image = base.expand ? base.host.expand_image : base.host.collapse_image;
if (image != null)
{
int left = rectangle.Right + (this.m_inner_space * 2);
int top = rcItem.Top + this.m_inner_space;
if (Rectangle.FromLTRB(left, top, (left + image.Width) + (this.m_inner_space * 2), (top + (rcItem.Height / 2)) - (this.m_inner_space * 2)).Contains(location))
{
normal = area_type.arrow;
}
}
return normal;
}
Image image2 = base.expand ? base.host.expand_image : base.host.collapse_image;
if ((image2 != null) && (location.X <= (((rcItem.Left + ((base.host.indent - image2.Width) / 2)) + image2.Width) + (this.m_inner_space * 2))))
{
normal = area_type.arrow;
}
return normal;
}
public bool draw_detail
{
get
{
return ((base.host == null) || (!(base.host is grouptree_widget) || (base.host as grouptree_widget).show_detail));
}
}
public PersonalGroup group
{
get
{
return this.m_group;
}
}
public override int height
{
get
{
if (!this.draw_detail)
{
return 0x19;
}
return 0x30;
}
}
private area_type last_leftdown_area
{
get
{
return this.m_last_leftdown_area;
}
set
{
this.m_last_leftdown_area = value;
}
}
public bool MembersLoaded
{
get
{
return this._membersLoaded;
}
set
{
this._membersLoaded = value;
}
}
private area_type mouse_location_area
{
get
{
return this.m_mouse_location_area;
}
set
{
if ((value == area_type.portrait) || (value == area_type.arrow))
{
base.host.Cursor = Cursors.Hand;
}
else
{
base.host.Cursor = base.host.NormalCursor;
}
this.m_mouse_location_area = value;
}
}
public enum area_type
{
arrow = 2,
normal = 0,
outside = -1,
portrait = 1
}
public delegate void group_click_portrait_handler(object sender);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -