blob: 1db833065a17b1c888580404608d1fcd30a007c0 (
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
|
#include "tools.hh"
namespace dw {
namespace core {
SizeParams::SizeParams ()
{
init ();
}
SizeParams::~SizeParams ()
{
cleanup ();
}
void SizeParams::init ()
{
numPos = 0;
references = NULL;
x = y = NULL;
}
void SizeParams::cleanup ()
{
if (references)
delete[] references;
if (x)
delete[] x;
if (y)
delete[] y;
init ();
}
void SizeParams::fill (int numPos, Widget **references, int *x, int *y)
{
cleanup ();
this->numPos = numPos;
this->references = new Widget*[numPos];
this->x = new int[numPos];
this->y = new int[numPos];
for (int i = 0; i < numPos; i++) {
this->references[i] = references[i];
this->x[i] = x[i];
this->y[i] = y[i];
}
}
void SizeParams::forChild (Widget *parent, Widget *child, int xRel, int yRel,
SizeParams *childParams)
{
int numChildReferences = child->numSizeRequestReferences ();
childParams->numPos = 0;
childParams->references = new Widget*[numChildReferences];
childParams->x = new int[numChildReferences];
childParams->y = new int[numChildReferences];
for (int i = 0; i < numChildReferences; i++) {
Widget *childReference = child->sizeRequestReference (i);
if (childReference == parent) {
references[numPos] = childReference;
childParams->x[numPos] = xRel;
childParams->y[numPos] = yRel;
numPos++;
} else {
bool found = false;
for (int j = 0; !found && j < numPos; j++) {
if (childReference == references[j]) {
found = true;
references[numPos] = childReference;
childParams->x[numPos] = x[j] + xRel;
childParams->y[numPos] = y[j] + yRel;
numPos++;
}
}
}
}
}
bool SizeParams::findReference (Widget *reference, int *x, int *y)
{
for (int i = 0; i < numPos; i++) {
if (reference == references[i]) {
if (x)
*x = this->x[i];
if (y)
*y = this->y[i];
return true;
}
}
return false;
}
} // namespace core
} // namespace dw
|