提交 | 用户 | age
|
4b03ae
|
1 |
#include "StdAfx.h"
|
Q |
2 |
#include "Layout.h"
|
|
3 |
|
|
4 |
Layout::Layout(
|
|
5 |
LayoutType type ,
|
|
6 |
CWnd* pWndParent ,
|
|
7 |
|
|
8 |
bool expandToFill,
|
|
9 |
int fillSpaceOrRealSize,
|
|
10 |
|
|
11 |
int wndID,
|
|
12 |
|
|
13 |
int outerPaddingLeft,
|
|
14 |
int outerPaddingRight,
|
|
15 |
|
|
16 |
int outerPaddingUp,
|
|
17 |
int outerPaddingDown,
|
|
18 |
|
|
19 |
int innerPaddingLeft,
|
|
20 |
int innerPaddingRight,
|
|
21 |
|
|
22 |
int innerPaddingUp,
|
|
23 |
int innerPaddingDown)
|
|
24 |
{
|
|
25 |
m_type = type;
|
|
26 |
|
|
27 |
m_pWndParent = pWndParent;
|
|
28 |
|
|
29 |
m_bExpandToFill = expandToFill;
|
|
30 |
m_FillSpaceOrRealSize = fillSpaceOrRealSize;
|
|
31 |
|
|
32 |
m_wndID = wndID;
|
|
33 |
|
|
34 |
m_x = 0;
|
|
35 |
m_y = 0;
|
|
36 |
m_width = 0;
|
|
37 |
m_height = 0;
|
|
38 |
|
|
39 |
m_innerPaddingLeft = innerPaddingLeft;
|
|
40 |
m_innerPaddingRight = innerPaddingRight;
|
|
41 |
m_innerPaddingUp = innerPaddingUp;
|
|
42 |
m_innerPaddingDown = innerPaddingDown;
|
|
43 |
|
|
44 |
m_outerPaddingLeft = outerPaddingLeft;
|
|
45 |
m_outerPaddingRight = outerPaddingRight;
|
|
46 |
m_outerPaddingUp = outerPaddingUp;
|
|
47 |
m_outerPaddingDown = outerPaddingDown;
|
|
48 |
|
|
49 |
}
|
|
50 |
Layout::~Layout(void)
|
|
51 |
{
|
|
52 |
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
|
53 |
{
|
|
54 |
delete *iter;
|
|
55 |
}
|
|
56 |
}
|
|
57 |
Layout* Layout::AddChild(
|
|
58 |
LayoutType type ,
|
|
59 |
|
|
60 |
bool expandToFill,
|
|
61 |
int fillSpaceOrRealSize,
|
|
62 |
|
|
63 |
int wndID,
|
|
64 |
|
|
65 |
int outerPaddingLeft,
|
|
66 |
int outerPaddingRight,
|
|
67 |
|
|
68 |
int outerPaddingUp,
|
|
69 |
int outerPaddingDown,
|
|
70 |
|
|
71 |
int innerPaddingLeft,
|
|
72 |
int innerPaddingRight,
|
|
73 |
|
|
74 |
int innerPaddingUp,
|
|
75 |
int innerPaddingDown)
|
|
76 |
{
|
|
77 |
ASSERT(m_type != LT_Window);
|
|
78 |
Layout* child = new Layout(
|
|
79 |
type , m_pWndParent , expandToFill , fillSpaceOrRealSize , wndID ,
|
|
80 |
outerPaddingLeft , outerPaddingRight , outerPaddingUp , outerPaddingDown,
|
|
81 |
innerPaddingLeft , innerPaddingRight , innerPaddingUp , innerPaddingDown);
|
|
82 |
|
|
83 |
m_children.push_back(child);
|
|
84 |
return child;
|
|
85 |
}
|
|
86 |
|
|
87 |
void Layout::UpdateSize(int w , int h)
|
|
88 |
{
|
|
89 |
m_width = w;
|
|
90 |
m_height = h;
|
|
91 |
UpdateLayout();
|
|
92 |
}
|
|
93 |
void Layout::UpdateLayout()
|
|
94 |
{
|
|
95 |
if (m_type & LT_Window)
|
|
96 |
{
|
|
97 |
UpdateWindow();
|
|
98 |
}
|
|
99 |
if (m_type & LT_LayoutH)
|
|
100 |
{
|
|
101 |
UpdateLayoutH();
|
|
102 |
}
|
|
103 |
if (m_type & LT_LayoutV)
|
|
104 |
{
|
|
105 |
UpdateLayoutV();
|
|
106 |
}
|
|
107 |
}
|
|
108 |
void Layout::UpdateLayoutH()
|
|
109 |
{
|
|
110 |
int totalExpandCount = 0;
|
|
111 |
|
|
112 |
int totalExpandSize = m_width
|
|
113 |
- m_outerPaddingLeft
|
|
114 |
- m_outerPaddingRight
|
|
115 |
- m_innerPaddingLeft
|
|
116 |
- m_innerPaddingRight;
|
|
117 |
|
|
118 |
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
|
119 |
{
|
|
120 |
Layout* child = *iter;
|
|
121 |
|
|
122 |
child->m_height = m_height
|
|
123 |
- m_outerPaddingUp
|
|
124 |
- m_outerPaddingDown
|
|
125 |
- m_innerPaddingUp
|
|
126 |
- m_innerPaddingDown;
|
|
127 |
|
|
128 |
child->m_y = m_y
|
|
129 |
+ m_outerPaddingUp
|
|
130 |
+ m_innerPaddingUp;
|
|
131 |
|
|
132 |
if (child->m_bExpandToFill)
|
|
133 |
{
|
|
134 |
totalExpandCount += child->m_FillSpaceOrRealSize;
|
|
135 |
}else{
|
|
136 |
child->m_width = child->m_FillSpaceOrRealSize;
|
|
137 |
totalExpandSize -= child->m_FillSpaceOrRealSize;
|
|
138 |
}
|
|
139 |
}
|
|
140 |
float unitExpandSize = 0;
|
|
141 |
if (totalExpandCount > 0)
|
|
142 |
{
|
|
143 |
unitExpandSize = float(totalExpandSize) / float(totalExpandCount);
|
|
144 |
}
|
|
145 |
|
|
146 |
int x = m_x
|
|
147 |
+ m_outerPaddingLeft
|
|
148 |
+ m_innerPaddingLeft;
|
|
149 |
|
|
150 |
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
|
151 |
{
|
|
152 |
Layout* child = *iter;
|
|
153 |
|
|
154 |
child->m_x = x;
|
|
155 |
if (child->m_bExpandToFill)
|
|
156 |
{
|
|
157 |
child->m_width = int(unitExpandSize * child->m_FillSpaceOrRealSize);
|
|
158 |
}
|
|
159 |
|
|
160 |
child->UpdateLayout();
|
|
161 |
|
|
162 |
x += child->m_width;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
void Layout::UpdateLayoutV()
|
|
166 |
{
|
|
167 |
int totalExpandCount = 0;
|
|
168 |
|
|
169 |
int totalExpandSize = m_height
|
|
170 |
- m_outerPaddingUp
|
|
171 |
- m_outerPaddingDown
|
|
172 |
- m_innerPaddingUp
|
|
173 |
- m_innerPaddingDown;
|
|
174 |
|
|
175 |
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
|
176 |
{
|
|
177 |
Layout* child = *iter;
|
|
178 |
|
|
179 |
child->m_width = m_width
|
|
180 |
- m_outerPaddingLeft
|
|
181 |
- m_outerPaddingRight
|
|
182 |
- m_innerPaddingLeft
|
|
183 |
- m_innerPaddingRight;
|
|
184 |
|
|
185 |
child->m_x = m_x
|
|
186 |
+ m_outerPaddingLeft
|
|
187 |
+ m_innerPaddingLeft;
|
|
188 |
|
|
189 |
if (child->m_bExpandToFill)
|
|
190 |
{
|
|
191 |
totalExpandCount += child->m_FillSpaceOrRealSize;
|
|
192 |
}else{
|
|
193 |
child->m_height = child->m_FillSpaceOrRealSize;
|
|
194 |
totalExpandSize -= child->m_FillSpaceOrRealSize;
|
|
195 |
}
|
|
196 |
}
|
|
197 |
float unitExpandSize = 0;
|
|
198 |
if (totalExpandCount > 0)
|
|
199 |
{
|
|
200 |
unitExpandSize = float(totalExpandSize) / float(totalExpandCount);
|
|
201 |
}
|
|
202 |
|
|
203 |
int y = m_y
|
|
204 |
+ m_outerPaddingUp
|
|
205 |
+ m_innerPaddingUp;
|
|
206 |
|
|
207 |
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
|
208 |
{
|
|
209 |
Layout* child = *iter;
|
|
210 |
|
|
211 |
child->m_y = y;
|
|
212 |
if (child->m_bExpandToFill)
|
|
213 |
{
|
|
214 |
child->m_height = int(unitExpandSize * child->m_FillSpaceOrRealSize);
|
|
215 |
}
|
|
216 |
|
|
217 |
child->UpdateLayout();
|
|
218 |
|
|
219 |
y += child->m_height;
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
void Layout::UpdateWindow()
|
|
224 |
{
|
|
225 |
m_pWndParent->GetDlgItem(m_wndID)->MoveWindow(
|
|
226 |
m_x + m_outerPaddingLeft,
|
|
227 |
m_y + m_outerPaddingUp,
|
|
228 |
m_width - m_outerPaddingLeft - m_outerPaddingRight,
|
|
229 |
m_height - m_outerPaddingUp - m_outerPaddingDown);
|
|
230 |
} |