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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Sebastian Werner (wpbasti)
* Andreas Ecker (ecker)
************************************************************************ */
/* ************************************************************************
#module(ui_layout)
************************************************************************ */
qx.OO.defineClass("qx.renderer.layout.FlowLayoutImpl", qx.renderer.layout.LayoutImpl,
function(vWidget) {
qx.renderer.layout.LayoutImpl.call(this, vWidget);
});
qx.renderer.layout.FlowLayoutImpl.STR_FIRST = "getFirstVisibleChild";
qx.renderer.layout.FlowLayoutImpl.STR_LAST = "getLastVisibleChild";
qx.renderer.layout.FlowLayoutImpl.STR_NEXT = "getNextSibling";
qx.renderer.layout.FlowLayoutImpl.STR_PREVIOUS = "getPreviousSibling";
/*!
Global Structure:
[01] COMPUTE BOX DIMENSIONS FOR AN INDIVIDUAL CHILD
[03] COMPUTE NEEDED DIMENSIONS FOR ALL CHILDREN
[04] UPDATE LAYOUT WHEN A CHILD CHANGES ITS OUTER DIMENSIONS
[05] UPDATE CHILD ON INNER DIMENSION CHANGES OF LAYOUT
[06] UPDATE LAYOUT ON JOB QUEUE FLUSH
[07] UPDATE CHILDREN ON JOB QUEUE FLUSH
[08] CHILDREN ADD/REMOVE/MOVE HANDLING
[09] FLUSH LAYOUT QUEUES OF CHILDREN
[10] LAYOUT CHILD
[11] DISPOSER
Inherits from qx.renderer.layout.LayoutImpl:
[01] COMPUTE BOX DIMENSIONS FOR AN INDIVIDUAL CHILD
[02] COMPUTE NEEDED DIMENSIONS FOR AN INDIVIDUAL CHILD
[06] UPDATE LAYOUT ON JOB QUEUE FLUSH
[11] DISPOSER
*/
/*
---------------------------------------------------------------------------
[03] COMPUTE NEEDED DIMENSIONS FOR ALL CHILDREN
---------------------------------------------------------------------------
*/
/*!
Compute and return the width needed by all children of this widget
*/
qx.Proto.computeChildrenNeededWidth = function()
{
var w = this.getWidget();
return qx.renderer.layout.LayoutImpl.prototype.computeChildrenNeededWidth_sum.call(this) + ((w.getVisibleChildrenLength()-1) * w.getHorizontalSpacing());
}
/*!
Calculate the layout to get the needed height of the children
*/
qx.Proto.computeChildrenNeededHeight = function()
{
var vWidget = this.getWidget();
var vInnerWidth = vWidget.getInnerWidth();
var vHorizontalSpacing = vWidget.getHorizontalSpacing();
var vVerticalSpacing = vWidget.getVerticalSpacing();
var vReversed = vWidget.getReverseChildrenOrder();
var vRowWidth = 0;
var vRowHeight = 0;
var vRowHeightSum = 0;
for (var i=0, ch=vWidget.getVisibleChildren(), chl=ch.length, chc; i<chl; i++)
{
chc = vReversed ? ch[chl-1-i] : ch[i];
vRowWidth += chc.getNeededWidth();
if (vRowWidth > vInnerWidth)
{
vRowHeightSum += vRowHeight + vVerticalSpacing;
vRowWidth = chc.getNeededWidth();
vRowHeight = chc.getNeededHeight();
}
else
{
vRowHeight = Math.max(vRowHeight, chc.getNeededHeight());
}
vRowWidth += vHorizontalSpacing;
}
return vRowHeightSum + vRowHeight;
}
/*
---------------------------------------------------------------------------
[04] UPDATE LAYOUT WHEN A CHILD CHANGES ITS OUTER DIMENSIONS
---------------------------------------------------------------------------
*/
/*!
Things to do and layout when any of the childs changes it's outer width.
Needed by layouts where the children depends on each-other, like flow- or box-layouts.
*/
qx.Proto.updateSelfOnChildOuterWidthChange = function(vChild)
{
// If a child only change it's width also recompute the height
// as the layout flows around here
//this.getWidget()._recomputeNeededHeightHelper();
this.getWidget()._invalidatePreferredInnerHeight();
}
/*
---------------------------------------------------------------------------
[05] UPDATE CHILD ON INNER DIMENSION CHANGES OF LAYOUT
---------------------------------------------------------------------------
*/
/*!
Actions that should be done if the inner width of the widget was changed.
Normally this includes update to percent values and ranges.
*/
qx.Proto.updateChildOnInnerWidthChange = function(vChild)
{
vChild._recomputePercentX();
vChild.addToLayoutChanges("location");
return true;
}
/*!
Actions that should be done if the inner height of the widget was changed.
Normally this includes update to percent values and ranges.
*/
qx.Proto.updateChildOnInnerHeightChange = function(vChild)
{
vChild._recomputePercentY();
vChild.addToLayoutChanges("location");
return true;
}
/*
---------------------------------------------------------------------------
[07] UPDATE CHILDREN ON JOB QUEUE FLUSH
---------------------------------------------------------------------------
*/
/*!
Updates children on special jobs
*/
qx.Proto.updateChildrenOnJobQueueFlush = function(vQueue)
{
if (vQueue.horizontalSpacing || vQueue.verticalSpacing || vQueue.reverseChildrenOrder || vQueue.horizontalChildrenAlign || vQueue.verticalChildrenAlign) {
this.getWidget()._addChildrenToLayoutQueue("location");
}
}
/*
---------------------------------------------------------------------------
[08] CHILDREN ADD/REMOVE/MOVE HANDLING
---------------------------------------------------------------------------
*/
/*!
This method combines calls of methods which should be done if a widget should be removed from the current layout.
Needed by layouts where the children depends on each-other, like flow- or box-layouts.
*/
qx.Proto.updateChildrenOnRemoveChild = function(vChild, vIndex)
{
var w=this.getWidget(), ch=w.getVisibleChildren(), chl=ch.length, chc, i=-1;
if (w.getReverseChildrenOrder())
{
while((chc=ch[++i]) && i<vIndex) {
chc.addToLayoutChanges("location");
}
}
else
{
i+=vIndex;
while(chc=ch[++i]) {
chc.addToLayoutChanges("location");
}
}
}
/*!
This method combines calls of methods which should be done if a child should be moved
inside the same parent to a new positions.
Needed by layouts where the children depends on each-other, like flow- or box-layouts.
*/
qx.Proto.updateChildrenOnMoveChild = function(vChild, vIndex, vOldIndex)
{
for (var i=Math.min(vIndex, vOldIndex), ch=this.getWidget().getVisibleChildren(), l=ch.length; i<l; i++) {
ch[i].addToLayoutChanges("location");
}
}
/*
---------------------------------------------------------------------------
[09] FLUSH LAYOUT QUEUES OF CHILDREN
---------------------------------------------------------------------------
*/
/*!
This method have full control of the order in which the
registered (or also non-registered) children should be
layouted on the horizontal axis.
*/
qx.Proto.flushChildrenQueue = function(vChildrenQueue)
{
var w=this.getWidget(), ch=w.getVisibleChildren(), chl=ch.length, chc, chh;
if (w.getReverseChildrenOrder())
{
// layout all childs from the first child
// with an own layout request to the end
var i=chl, changed=false;
while(chc=ch[--i])
{
chh = chc.toHashCode();
if (changed || vChildrenQueue[chh])
{
w._layoutChild(chc);
changed = true;
}
}
}
else
{
// layout all childs from the first child
// with an own layout request to the end
var i=-1, changed=false;
while(chc=ch[++i])
{
chh = chc.toHashCode();
if (changed || vChildrenQueue[chh])
{
w._layoutChild(chc);
changed = true;
}
}
}
}
/*
---------------------------------------------------------------------------
[10] LAYOUT CHILD
---------------------------------------------------------------------------
*/
qx.Proto.layoutChild = function(vChild, vJobs)
{
this.layoutChild_sizeX_essentialWrapper(vChild, vJobs);
this.layoutChild_sizeY_essentialWrapper(vChild, vJobs);
this.layoutChild_sizeLimitX(vChild, vJobs);
this.layoutChild_sizeLimitY(vChild, vJobs);
this.layoutChild_marginX(vChild, vJobs);
this.layoutChild_marginY(vChild, vJobs);
this.layoutChild_location(vChild, vJobs);
}
if (qx.core.Client.getInstance().isMshtml() || qx.core.Client.getInstance().isOpera())
{
/*!
We need to respect all dimension properties on the horizontal axis in
internet explorer to set the 'width' style
*/
qx.Proto.layoutChild_sizeX = function(vChild, vJobs)
{
if (vJobs.initial || vJobs.width || vJobs.minWidth || vJobs.maxWidth) {
vChild._computedWidthTypeNull && vChild._computedMinWidthTypeNull && vChild._computedMaxWidthTypeNull ? vChild._resetRuntimeWidth() : vChild._applyRuntimeWidth(vChild.getBoxWidth());
}
}
/*!
We need to respect all dimension properties on the vertical axis in
internet explorer to set the 'height' style
*/
qx.Proto.layoutChild_sizeY = function(vChild, vJobs)
{
if (vJobs.initial || vJobs.height || vJobs.minHeight || vJobs.maxHeight) {
vChild._computedHeightTypeNull && vChild._computedMinHeightTypeNull && vChild._computedMaxHeightTypeNull ? vChild._resetRuntimeHeight() : vChild._applyRuntimeHeight(vChild.getBoxHeight());
}
}
}
else
{
qx.Proto.layoutChild_sizeX = function(vChild, vJobs)
{
if (vJobs.initial || vJobs.width) {
vChild._computedWidthTypeNull ? vChild._resetRuntimeWidth() : vChild._applyRuntimeWidth(vChild.getWidthValue());
}
}
qx.Proto.layoutChild_sizeY = function(vChild, vJobs)
{
if (vJobs.initial || vJobs.height) {
vChild._computedHeightTypeNull ? vChild._resetRuntimeHeight() : vChild._applyRuntimeHeight(vChild.getHeightValue());
}
}
}
qx.Proto.layoutChild_location = function(vChild, vJobs)
{
var vWidget = this.getWidget();
var vReverse = vWidget.getReverseChildrenOrder();
var vMethodBegin = vReverse ? qx.renderer.layout.FlowLayoutImpl.STR_LAST : qx.renderer.layout.FlowLayoutImpl.STR_FIRST;
var vMethodContinue = vReverse ? qx.renderer.layout.FlowLayoutImpl.STR_NEXT : qx.renderer.layout.FlowLayoutImpl.STR_PREVIOUS;
if (vChild == vWidget[vMethodBegin]())
{
vChild._cachedLocationHorizontal = vChild._cachedLocationVertical = vChild._cachedRow = 0;
}
else
{
var vTempChild = vChild[vMethodContinue]();
// stupidly update cache value (check them later)
vChild._cachedLocationHorizontal = vTempChild._cachedLocationHorizontal + vTempChild.getOuterWidth() + vWidget.getHorizontalSpacing();
vChild._cachedLocationVertical = vTempChild._cachedLocationVertical;
vChild._cachedRow = vTempChild._cachedRow;
// check now
if ((vChild._cachedLocationHorizontal + vChild.getOuterWidth()) > vWidget.getInnerWidth())
{
// evaluate width of previous row
vRowMax = vTempChild.getOuterHeight();
while((vTempChild = vTempChild[vMethodContinue]()) && vTempChild._cachedRow == vChild._cachedRow) {
vRowMax = Math.max(vRowMax, vTempChild.getOuterHeight());
}
// switch to new row
vChild._cachedLocationHorizontal = 0;
vChild._cachedLocationVertical += vWidget.getVerticalSpacing() + vRowMax;
vChild._cachedRow++;
}
}
// add margins and parent padding
if (vWidget.getHorizontalChildrenAlign() == "right")
{
vChild._resetRuntimeLeft();
vChild._applyRuntimeRight(vWidget.getPaddingRight() + vChild._cachedLocationHorizontal);
}
else
{
vChild._resetRuntimeRight();
vChild._applyRuntimeLeft(vWidget.getPaddingLeft() + vChild._cachedLocationHorizontal);
}
if (vWidget.getVerticalChildrenAlign() == "bottom")
{
vChild._resetRuntimeTop();
vChild._applyRuntimeBottom(vWidget.getPaddingBottom() + vChild._cachedLocationVertical);
}
else
{
vChild._resetRuntimeBottom();
vChild._applyRuntimeTop(vWidget.getPaddingTop() + vChild._cachedLocationVertical);
}
}
|