blob: a36cd7b194dde1438cf36b0cddd4959f8e6d6bcf (
plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
namespace go
{
public class GenericStack : Group
{
#region CTOR
public GenericStack()
: base()
{
}
#endregion
#region Private fields
bool childrenArePositionned = false;
int _spacing;
Orientation _orientation;
#endregion
#region Public Properties
[XmlAttributeAttribute()][DefaultValue(2)]
public int Spacing
{
get { return _spacing; }
set { _spacing = value; }
}
[XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
public virtual Orientation Orientation
{
get { return _orientation; }
set { _orientation = value; }
}
#endregion
#region GraphicObject Overrides
[XmlAttributeAttribute()][DefaultValue(-1)]
public override int Width {
get { return base.Width; }
set { base.Width = value; }
}
[XmlAttributeAttribute()][DefaultValue(-1)]
public override int Height {
get { return base.Height; }
set { base.Height = value; }
}
[XmlIgnore]public override bool LayoutIsValid {
get { return childrenArePositionned && base.LayoutIsValid; }
set { base.LayoutIsValid = value; }
}
public override void InvalidateLayout ()
{
childrenArePositionned = false;
base.InvalidateLayout ();
}
protected override Size measureRawSize ()
{
Size raw = Bounds.Size;
Size tmp = new Size ();
if (raw.Width >= 0 && raw.Height >= 0)
return raw;
foreach (GraphicObject c in Children) {
if (raw.Width < 0) {
if (c.WIsValid) {
if (Orientation == Orientation.Horizontal && c.Bounds.Width != 0)
tmp.Width += c.Slot.Width + Spacing;
else
tmp.Width = Math.Max (tmp.Width, c.Slot.Right);
}else
return raw;
}
if (raw.Height < 0) {
if (c.HIsValid) {
if (Orientation == Orientation.Vertical && c.Bounds.Height != 0)
tmp.Height += c.Slot.Height + Spacing;
else
tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);
}else
return raw;
}
}
if (raw.Width < 0)
tmp.Width += 2*Margin;
if (raw.Height < 0)
tmp.Height += 2*Margin;
return tmp;
}
public virtual void ComputeChildrenPositions()
{
int d = 0;
if (Orientation == Orientation.Horizontal) {
foreach (GraphicObject c in Children) {
if (c.Bounds.Width == 0)
continue;
c.Slot.X = d;
c.XIsValid = true;
d += c.Slot.Width + Spacing;
}
} else {
foreach (GraphicObject c in Children) {
if (c.Bounds.Height == 0)
continue;
c.Slot.Y = d;
c.YIsValid = true;
d += c.Slot.Height + Spacing;
}
}
childrenArePositionned = true;
}
public override void UpdateLayout()
{
base.UpdateLayout();
ComputeChildrenPositions ();
if (LayoutIsValid)
registerForRedraw();
}
#endregion
//
// bool enoughtSpaceForWidget(GraphicObject w)
// {
// if (!SizeToContent)
// {
// int nextXForWidget = 0;
// int nextYForWidget = 0;
//
// if (Orientation == Orientation.Horizontal)
// nextXForWidget = currentXForWidget + w.Slot.Width;
// else
// nextYForWidget = nextYForWidget + w.Slot.Height;
//
//
// if (nextXForWidget > ClientRectangle.Right )
// return false;
// if (currentYForWidget > ClientRectangle.Bottom )
// return false;
// }
// return true;
// }
// void advance(GraphicObject w)
// {
// if (Orientation == Orientation.Horizontal)
// currentXForWidget = currentXForWidget + WidgetSpacing + w.Slot.Width;
// else
// currentYForWidget = currentYForWidget + WidgetSpacing + w.Slot.Height;
//
// }
}
}
|