Dillo v3.1.1-11-g8f0909b7
Loading...
Searching...
No Matches
tools.cc
Go to the documentation of this file.
1#include "core.hh"
2
3namespace dw {
4namespace core {
5
6using namespace lout::misc;
7
9{
10 DBG_OBJ_CREATE ("dw::core::SizeParams");
11 init ();
12 debugPrint ();
13}
14
15SizeParams::SizeParams (int numPos, Widget **references, int *x, int *y)
16{
17 DBG_OBJ_CREATE ("dw::core::SizeParams");
18 init ();
20 debugPrint ();
21}
22
24{
25 DBG_OBJ_CREATE ("dw::core::SizeParams");
26 init ();
27 fill (other.numPos, other.references, other.x, other.y);
28 debugPrint ();
29}
30
36
38{
39 cleanup ();
40 init ();
41 fill (other.numPos, other.references, other.x, other.y);
42 debugPrint ();
43 return *this;
44}
45
47{
48 numPos = 0;
49 references = NULL;
50 x = y = NULL;
51}
52
54{
55 if (references)
56 delete[] references;
57 if (x)
58 delete[] x;
59 if (y)
60 delete[] y;
61
62 init ();
63}
64
65void SizeParams::fill (int numPos, Widget **references, int *x, int *y)
66{
67 DBG_OBJ_ENTER ("resize", 0, "fill", "%d, ...", numPos);
68
69 cleanup ();
70
71 this->numPos = numPos;
72
73 this->references = new Widget*[numPos];
74 this->x = new int[numPos];
75 this->y = new int[numPos];
76
77 for (int i = 0; i < numPos; i++) {
78 this->references[i] = references[i];
79 this->x[i] = x[i];
80 this->y[i] = y[i];
81 }
82
83 debugPrint ();
84
86}
87
88void SizeParams::forChild (Widget *parent, Widget *child, int xRel, int yRel,
89 SizeParams *childParams)
90{
91 DBG_OBJ_ENTER ("resize", 0, "forChild", "%p, %p, %d, %d, %p",
92 parent, child, xRel, yRel, childParams);
93
94 childParams->cleanup ();
95
96 int numChildReferences = child->numSizeRequestReferences ();
97
98 childParams->numPos = 0;
99 childParams->references = new Widget*[numChildReferences];
100 childParams->x = new int[numChildReferences];
101 childParams->y = new int[numChildReferences];
102
103 for (int i = 0; i < numChildReferences; i++) {
104 Widget *childReference = child->sizeRequestReference (i);
105
106 if (childReference == parent) {
107 childParams->references[childParams->numPos] = childReference;
108 childParams->x[childParams->numPos] = xRel;
109 childParams->y[childParams->numPos] = yRel;
110 childParams->numPos++;
111 } else {
112 bool found = false;
113 for (int j = 0; !found && j < numPos; j++) {
114 if (childReference == references[j]) {
115 found = true;
116 childParams->references[childParams->numPos] = childReference;
117 childParams->x[childParams->numPos] = x[j] + xRel;
118 childParams->y[childParams->numPos] = y[j] + yRel;
119 childParams->numPos++;
120 }
121 }
122 }
123 }
124
125 childParams->debugPrint ();
126
127 DBG_OBJ_LEAVE ();
128}
129
130bool SizeParams::findReference (Widget *reference, int *x, int *y)
131{
132 DBG_OBJ_ENTER ("resize", 0, "findReference", "%p", reference);
133
134 bool found = false;
135 for (int i = 0; i < numPos && !found; i++) {
136 if (reference == references[i]) {
137 if (x)
138 *x = this->x[i];
139 if (y)
140 *y = this->y[i];
141 found = true;
142 }
143 }
144
145 if (found) {
146 if (x && y)
147 DBG_OBJ_LEAVE_VAL ("true, x = %d, y = %d", *x, *y);
148 else if (x)
149 DBG_OBJ_LEAVE_VAL ("true, x = %d", *x);
150 else if (y)
151 DBG_OBJ_LEAVE_VAL ("true, y = %d", *y);
152 else
153 DBG_OBJ_LEAVE_VAL ("%s", "true");
154 } else
155 DBG_OBJ_LEAVE_VAL ("%s", "false");
156
157 return found;
158}
159
165{
166 DBG_OBJ_ENTER ("resize", 0, "isEquivalent", "%p", other);
167 bool result;
168
169 if (numPos != other->numPos)
170 result = false;
171 else {
172 result = true;
173
174 for (int i = 0; result && i < numPos; i++) {
175 bool otherFound = false;
176 for (int j = 0; !otherFound && j < numPos; j++) {
177 DBG_OBJ_MSGF ("resize", 1,
178 "#%d = (%p, %d, %d) vs. #%d = (%p, %d, %d)",
179 i, references[i], x[i], y[i], j, other->references[j],
180 other->x[j], other->y[j]);
181
182 if (references[i] == other->references[j]) {
183 otherFound = true;
184 if (!(x[i] == other->x[j] && y[i] == other->y[j]))
185 result = false;
186 }
187 }
188
189 if (!otherFound)
190 result = false;
191 }
192 }
193
194 DBG_OBJ_LEAVE_VAL ("%s", boolToStr (result));
195 return result;
196}
197
198} // namespace core
199} // namespace dw
Hold arguments passed to dw::core::Widget::sizeRequest and dw::core::Widget::getExtremes,...
Definition tools.hh:19
bool isEquivalent(SizeParams *other)
Compares two instances, but considers a change in the order of the reference widgets as equivalent.
Definition tools.cc:164
Widget ** references
Definition tools.hh:22
SizeParams & operator=(const SizeParams &other)
Definition tools.cc:37
void fill(int numPos, Widget **references, int *x, int *y)
Definition tools.cc:65
void forChild(Widget *parent, Widget *child, int xRel, int yRel, SizeParams *childParams)
Definition tools.cc:88
bool findReference(Widget *reference, int *x, int *y)
Definition tools.cc:130
The base class of all dillo widgets.
Definition widget.hh:24
virtual Widget * sizeRequestReference(int index)
See Sizes of Dillo Widgets (or Size requisitions depending on positions).
Definition widget.cc:1105
virtual int numSizeRequestReferences()
See Sizes of Dillo Widgets (or Size requisitions depending on positions).
Definition widget.cc:1100
#define DBG_OBJ_DELETE()
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_LEAVE()
#define DBG_OBJ_LEAVE_VAL(fmt,...)
Dw is in this namespace, or sub namespaces of this one.
Miscellaneous stuff, which does not fit anywhere else.
Definition misc.cc:31
const char * boolToStr(bool b)
Definition misc.hh:87