-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyButtonEditViewInfo.cs
112 lines (93 loc) · 3.62 KB
/
MyButtonEditViewInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Drawing;
using DevExpress.Utils.Drawing;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Drawing;
namespace DevExpress.MyControl
{
public class MyButtonEditViewInfo : ButtonEditViewInfo
{
public MyButtonEditViewInfo(RepositoryItem item) : base(item) { }
protected override Rectangle CalcButtons(GraphicsCache cache)
{
Rectangle rect = base.CalcButtons(cache);
if (OwnerEdit == null)
CalculateButtonsRect(cache.Graphics);
return rect;
}
protected override void OnEditValueChanged()
{
base.OnEditValueChanged();
if (OwnerEdit == null)
{
GInfo.AddGraphics(null);
try
{
CalculateButtonsRect(GInfo.Graphics);
}
finally
{
GInfo.ReleaseGraphics();
}
}
}
private void CalculateButtonsRect(Graphics graph)
{
int currentRightBorder = ClientRect.Right;
int baseXPos = 0, buttonWidth = 0;
Rectangle cRect = Rectangle.Empty;
int totalWidthOfButtonRects = 0;
for (int n = RightButtons.Count - 1; n >= 0; n--)
{
cRect = Rectangle.Empty;
EditorButtonObjectInfoArgs objectInfo = RightButtons[n];
buttonWidth = objectInfo.Bounds.Width;
if (objectInfo.Button.Index == 1)
{
string str_val = EditValue as string;
if (str_val == null || str_val.Length == 0)
buttonWidth = CalcMinButtonBounds(objectInfo).Width;
else
buttonWidth = CalcObjectMinBounds(graph, objectInfo, str_val).Width;
}
baseXPos = currentRightBorder - buttonWidth;
if (baseXPos > ClientRect.X)
cRect = new Rectangle(baseXPos, objectInfo.Bounds.Y, buttonWidth, objectInfo.Bounds.Height);
objectInfo.Bounds = cRect;
totalWidthOfButtonRects += buttonWidth;
currentRightBorder -= buttonWidth;
}
}
private Size CalcCaptionSize(Graphics graph, EditorButtonObjectInfoArgs e, string caption)
{
Size res = Size.Empty;
using (GraphicsCache cache = new GraphicsCache(graph)) {
res = e.Appearance.CalcTextSize(cache, caption, 0).ToSize();
}
res.Width += 1;
res.Height += 1;
return res;
}
private Rectangle CalcObjectMinBounds(Graphics graph, EditorButtonObjectInfoArgs e, string caption)
{
EditorButtonPainter eb_painter = GetButtonPainter(e) as EditorButtonPainter;
Size kSize = eb_painter.CalcKindMinSize(e);
Size tSize = CalcCaptionSize(graph, e, caption);
Size res = kSize;
if (!tSize.IsEmpty)
{
res.Width += tSize.Width + (kSize.Width > 0 ? TextGlyphIndent : 0);
int height = res.Height;
res.Height = Math.Max(tSize.Height, height);
}
if (e.Button.Width > 0) res.Width = e.Button.Width;
res.Width += 2;
Rectangle rect, saveBounds = e.Bounds;
e.Bounds = new Rectangle(Point.Empty, res);
rect = eb_painter.CalcBoundsByClientRectangle(e);
e.Bounds = saveBounds;
return rect;
}
}
}