r20514: implement idl for DsGetNT4ChangeLog() which transferres the meta data
[ira/wip.git] / webapps / qooxdoo-0.6.3-sdk / frontend / framework / source / class / qx / renderer / layout / DockLayoutImpl.js
1 /* ************************************************************************
2
3    qooxdoo - the new era of web development
4
5    http://qooxdoo.org
6
7    Copyright:
8      2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
9
10    License:
11      LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
12
13    Authors:
14      * Sebastian Werner (wpbasti)
15      * Andreas Ecker (ecker)
16
17 ************************************************************************ */
18
19 /* ************************************************************************
20
21 #module(ui_layout)
22
23 ************************************************************************ */
24
25 qx.OO.defineClass("qx.renderer.layout.DockLayoutImpl", qx.renderer.layout.LayoutImpl,
26 function(vWidget) {
27   qx.renderer.layout.LayoutImpl.call(this, vWidget);
28 });
29
30
31 /*!
32   Global Structure:
33   [01] COMPUTE BOX DIMENSIONS FOR AN INDIVIDUAL CHILD
34   [02] COMPUTE NEEDED DIMENSIONS FOR AN INDIVIDUAL CHILD
35   [03] COMPUTE NEEDED DIMENSIONS FOR ALL CHILDREN
36   [04] UPDATE LAYOUT WHEN A CHILD CHANGES ITS OUTER DIMENSIONS
37   [05] UPDATE CHILD ON INNER DIMENSION CHANGES OF LAYOUT
38   [06] UPDATE LAYOUT ON JOB QUEUE FLUSH
39   [07] UPDATE CHILDREN ON JOB QUEUE FLUSH
40   [08] CHILDREN ADD/REMOVE/MOVE HANDLING
41   [09] FLUSH LAYOUT QUEUES OF CHILDREN
42   [10] LAYOUT CHILD
43   [11] DISPOSER
44
45
46   Inherits from qx.renderer.layout.LayoutImpl:
47   [02] COMPUTE NEEDED DIMENSIONS FOR AN INDIVIDUAL CHILD
48   [03] COMPUTE NEEDED DIMENSIONS FOR ALL CHILDREN
49   [04] UPDATE LAYOUT WHEN A CHILD CHANGES ITS OUTER DIMENSIONS
50   [08] CHILDREN ADD/REMOVE/MOVE HANDLING
51   [11] DISPOSER
52 */
53
54
55
56
57 /*
58 ---------------------------------------------------------------------------
59   [00] ADDITIONAL GLOBAL DATA AND METHODS
60 ---------------------------------------------------------------------------
61 */
62
63 qx.renderer.layout.DockLayoutImpl.METHOD_LOCATION = "layoutChild_location_";
64
65 qx.renderer.layout.DockLayoutImpl._childRanking = {
66   vertical : function(c) { return c.getVerticalAlign() ? 1e6 : c.getHorizontalAlign() ? 2e6 : 3e6; },
67   horizontal : function(c) { return c.getHorizontalAlign() ? 1e6 : c.getVerticalAlign() ? 2e6 : 3e6; },
68   ordered : function(c) { return c.getHorizontalAlign() || c.getVerticalAlign() ? 1e6 : 2e6; }
69 }
70
71 qx.renderer.layout.DockLayoutImpl._childCheck =
72 {
73   common : function(vChild) {
74     if (!(vChild._computedLeftTypeNull && vChild._computedRightTypeNull && vChild._computedTopTypeNull && vChild._computedBottomTypeNull)) {
75       throw new Error("qx.renderer.layout.DockLayoutImpl: It is not allowed to define any location values for children: " + vChild + "!");
76     }
77   },
78
79   horizontal : function(vChild)
80   {
81     if (!(vChild._computedMinHeightTypeNull && vChild._computedHeightTypeNull && vChild._computedMaxHeightTypeNull)) {
82       throw new Error("qx.renderer.layout.DockLayoutImpl: It is not allowed to define any vertical dimension for 'horizontal' placed children: " + vChild + "!");
83     }
84   },
85
86   vertical : function(vChild)
87   {
88     if (!(vChild._computedMinWidthTypeNull && vChild._computedWidthTypeNull && vChild._computedMaxWidthTypeNull)) {
89       throw new Error("qx.renderer.layout.DockLayoutImpl: It is not allowed to define any horizontal dimension for 'vertical' placed children: " + vChild + "!");
90     }
91   },
92
93   "default" : function(vChild)
94   {
95     qx.renderer.layout.DockLayoutImpl._childCheck.horizontal(vChild);
96     qx.renderer.layout.DockLayoutImpl._childCheck.vertical(vChild);
97   }
98 }
99
100
101
102
103
104
105
106 /*
107 ---------------------------------------------------------------------------
108   [01] COMPUTE BOX DIMENSIONS FOR AN INDIVIDUAL CHILD
109 ---------------------------------------------------------------------------
110 */
111
112 /*!
113   Compute and return the box width of the given child
114 */
115 qx.Proto.computeChildBoxWidth = function(vChild)
116 {
117   if (this.getChildAlignMode(vChild) == "horizontal") {
118     return vChild.getWidthValue() || vChild._computeBoxWidthFallback();
119   }
120
121   return this.getWidget().getInnerWidth() - this._lastLeft - this._lastRight;
122 }
123
124 /*!
125   Compute and return the box height of the given child
126 */
127 qx.Proto.computeChildBoxHeight = function(vChild)
128 {
129   if (this.getChildAlignMode(vChild) == "vertical") {
130     return vChild.getHeightValue() || vChild._computeBoxHeightFallback();
131   }
132
133   return this.getWidget().getInnerHeight() - this._lastTop - this._lastBottom;
134 }
135
136
137
138
139
140
141
142 /*
143 ---------------------------------------------------------------------------
144   [05] UPDATE CHILD ON INNER DIMENSION CHANGES OF LAYOUT
145 ---------------------------------------------------------------------------
146 */
147
148 /*!
149   Actions that should be done if the inner width of the widget was changed.
150   Normally this includes update to percent values and ranges.
151 */
152 qx.Proto.updateChildOnInnerWidthChange = function(vChild)
153 {
154   vChild._recomputePercentX();
155   vChild.addToLayoutChanges("location");
156
157   // inform the caller if there were any notable changes occured
158   return true;
159 }
160
161 /*!
162   Actions that should be done if the inner height of the widget was changed.
163   Normally this includes update to percent values and ranges.
164 */
165 qx.Proto.updateChildOnInnerHeightChange = function(vChild)
166 {
167   vChild._recomputePercentY();
168   vChild.addToLayoutChanges("location");
169
170   // inform the caller if there were any notable changes occured
171   return true;
172 }
173
174
175
176
177
178 /*
179 ---------------------------------------------------------------------------
180   [06] UPDATE LAYOUT ON JOB QUEUE FLUSH
181 ---------------------------------------------------------------------------
182 */
183
184 /*!
185   Invalidate and recompute things because of job in queue (before the rest of job handling will be executed).
186 */
187 qx.Proto.updateSelfOnJobQueueFlush = qx.util.Return.returnFalse;
188
189
190
191
192
193
194
195 /*
196 ---------------------------------------------------------------------------
197   [07] UPDATE CHILDREN ON JOB QUEUE FLUSH
198 ---------------------------------------------------------------------------
199 */
200
201 /*!
202   Updates children on special jobs
203 */
204 qx.Proto.updateChildrenOnJobQueueFlush = function(vQueue)
205 {
206   if (vQueue.mode || vQueue.addChild || vQueue.removeChild) {
207     this.getWidget()._addChildrenToLayoutQueue("location");
208   }
209 }
210
211
212
213
214
215
216
217
218
219 /*
220 ---------------------------------------------------------------------------
221   [09] FLUSH LAYOUT QUEUES OF CHILDREN
222 ---------------------------------------------------------------------------
223 */
224
225 /*!
226   This method have full control of the order in which the
227   registered (or also non-registered) children should be
228   layouted on the horizontal axis.
229 */
230 qx.Proto.flushChildrenQueue = function(vChildrenQueue)
231 {
232   var vWidget=this.getWidget(), vChildren=vWidget.getVisibleChildren(), vChildrenLength=vChildren.length, vMode=vWidget.getMode();
233
234   // reset layout
235   this._lastLeft = this._lastRight = this._lastTop = this._lastBottom = 0;
236
237   // sorting children
238   var vRankImpl = qx.renderer.layout.DockLayoutImpl._childRanking[vMode];
239   var vOrderedChildren = qx.lang.Array.copy(vChildren).sort(function(c1, c2) {
240     return (vRankImpl(c1) + vChildren.indexOf(c1)) - (vRankImpl(c2) + vChildren.indexOf(c2));
241   });
242
243   // flushing children
244   for (var i=0; i<vChildrenLength; i++) {
245     vWidget._layoutChild(vOrderedChildren[i]);
246   }
247 }
248
249 qx.Proto.getChildAlign = function(vChild) {
250   return vChild.getVerticalAlign() || vChild.getHorizontalAlign() || "default";
251 }
252
253 qx.Proto.getChildAlignMode = function(vChild) {
254   return vChild.getVerticalAlign() ? "vertical" : vChild.getHorizontalAlign() ? "horizontal" : "default";
255 }
256
257
258
259
260
261
262
263 /*
264 ---------------------------------------------------------------------------
265   [10] LAYOUT CHILD
266 ---------------------------------------------------------------------------
267 */
268
269 /*!
270   This is called from qx.ui.core.Widget and  it's task is to apply the layout
271   (excluding border and padding) to the child.
272 */
273 qx.Proto.layoutChild = function(vChild, vJobs)
274 {
275   qx.renderer.layout.DockLayoutImpl._childCheck.common(vChild);
276   qx.renderer.layout.DockLayoutImpl._childCheck[this.getChildAlignMode(vChild)](vChild);
277
278   this.layoutChild_sizeX_essentialWrapper(vChild, vJobs);
279   this.layoutChild_sizeY_essentialWrapper(vChild, vJobs);
280
281   this.layoutChild_sizeLimitX(vChild, vJobs);
282   this.layoutChild_sizeLimitY(vChild, vJobs);
283
284   this[qx.renderer.layout.DockLayoutImpl.METHOD_LOCATION + this.getChildAlign(vChild)](vChild, vJobs);
285 }
286
287 qx.Proto.layoutChild_location_top = function(vChild, vJobs)
288 {
289   vChild._applyRuntimeTop(this._lastTop);
290   vChild._applyRuntimeLeft(this._lastLeft);
291
292   this.layoutChild_location_horizontal(vChild);
293
294   this._lastTop += vChild.getBoxHeight();
295 }
296
297 qx.Proto.layoutChild_location_left = function(vChild, vJobs)
298 {
299   vChild._applyRuntimeLeft(this._lastLeft);
300   vChild._applyRuntimeTop(this._lastTop);
301
302   this.layoutChild_location_vertical(vChild);
303
304   this._lastLeft += vChild.getBoxWidth();
305 }
306
307
308
309
310
311
312
313 if (qx.sys.Client.getInstance().isMshtml() || qx.sys.Client.getInstance().isOpera())
314 {
315   qx.Proto._applyComputedWidth = function(vChild)
316   {
317     // direct recompute (need to be done, while layouting as the
318     // _last* variable changes during layout process)
319     vChild._recomputeBoxWidth();
320
321     // wrong: simple invalidates are enough here
322     // correct: needs recompute to inform children (to update centering for example)
323     vChild._recomputeOuterWidth();
324     vChild._recomputeInnerWidth();
325
326     // apply calculated width
327     vChild._applyRuntimeWidth(vChild.getBoxWidth());
328   }
329
330   qx.Proto._applyComputedHeight = function(vChild)
331   {
332     // direct recompute (need to be done, while layouting as the
333     // _last* variable changes during layout process)
334     vChild._recomputeBoxHeight();
335
336     // wrong: simple invalidates are enough here
337     // correct: needs recompute to inform children (to update centering for example)
338     vChild._recomputeOuterHeight();
339     vChild._recomputeInnerHeight();
340
341     // apply calculated height
342     vChild._applyRuntimeHeight(vChild.getBoxHeight());
343   }
344
345   qx.Proto.layoutChild_sizeX = function(vChild, vJobs)
346   {
347     // We need to respect all dimension properties on the horizontal axis in internet explorer to set the 'width' style
348     if (vJobs.initial || vJobs.width || vJobs.minWidth || vJobs.maxWidth) {
349       vChild._computedWidthTypeNull && vChild._computedMinWidthTypeNull && vChild._computedMaxWidthTypeNull ? vChild._resetRuntimeWidth() : vChild._applyRuntimeWidth(vChild.getBoxWidth());
350     }
351   }
352
353   qx.Proto.layoutChild_sizeY = function(vChild, vJobs)
354   {
355     // We need to respect all dimension properties on the vertical axis in internet explorer to set the 'height' style
356     if (vJobs.initial || vJobs.height || vJobs.minHeight || vJobs.maxHeight) {
357       vChild._computedHeightTypeNull && vChild._computedMinHeightTypeNull && vChild._computedMaxHeightTypeNull ? vChild._resetRuntimeHeight() : vChild._applyRuntimeHeight(vChild.getBoxHeight());
358     }
359   }
360
361   qx.Proto.layoutChild_location_horizontal = function(vChild) {
362     this._applyComputedWidth(vChild);
363   }
364
365   qx.Proto.layoutChild_location_vertical = function(vChild) {
366     this._applyComputedHeight(vChild);
367   }
368
369   qx.Proto.layoutChild_location_right = function(vChild, vJobs)
370   {
371     vChild._applyRuntimeLeft(this.getWidget().getInnerWidth() - this._lastRight - vChild.getBoxWidth());
372     vChild._applyRuntimeTop(this._lastTop);
373
374     this.layoutChild_location_vertical(vChild);
375
376     this._lastRight += vChild.getBoxWidth();
377   }
378
379   qx.Proto.layoutChild_location_bottom = function(vChild, vJobs)
380   {
381     vChild._applyRuntimeTop(this.getWidget().getInnerHeight() - this._lastBottom - vChild.getBoxHeight());
382     vChild._applyRuntimeLeft(this._lastLeft);
383
384     this.layoutChild_location_horizontal(vChild);
385
386     this._lastBottom += vChild.getBoxHeight();
387   }
388
389   qx.Proto.layoutChild_location_default = function(vChild, vJobs)
390   {
391     var vWidget = this.getWidget();
392
393     vChild._resetRuntimeRight();
394     vChild._resetRuntimeBottom();
395
396     vChild._applyRuntimeTop(this._lastTop);
397     vChild._applyRuntimeLeft(this._lastLeft);
398
399     this._applyComputedWidth(vChild);
400     this._applyComputedHeight(vChild);
401   }
402 }
403 else
404 {
405   qx.Proto._applyComputedWidth = function(vChild)
406   {
407     // direct recompute (need to be done, while layouting as the
408     // _last* variable changes during layout process)
409     vChild._recomputeBoxWidth();
410
411     // wrong: simple invalidates are enough here
412     // correct: needs recompute to inform children (to update centering for example)
413     vChild._recomputeOuterWidth();
414     vChild._recomputeInnerWidth();
415   }
416
417   qx.Proto._applyComputedHeight = function(vChild)
418   {
419     // direct recompute (need to be done, while layouting as the
420     // _last* variable changes during layout process)
421     vChild._recomputeBoxHeight();
422
423     // wrong: simple invalidates are enough here
424     // correct: needs recompute to inform children (to update centering for example)
425     vChild._recomputeOuterHeight();
426     vChild._recomputeInnerHeight();
427   }
428
429   qx.Proto.layoutChild_sizeX = function(vChild, vJobs)
430   {
431     if (vJobs.initial || vJobs.width) {
432       vChild._computedWidthTypeNull ? vChild._resetRuntimeWidth() : vChild._applyRuntimeWidth(vChild.getWidthValue());
433     }
434   }
435
436   qx.Proto.layoutChild_sizeY = function(vChild, vJobs)
437   {
438     if (vJobs.initial || vJobs.height) {
439       vChild._computedHeightTypeNull ? vChild._resetRuntimeHeight() : vChild._applyRuntimeHeight(vChild.getHeightValue());
440     }
441   }
442
443   qx.Proto.layoutChild_location_horizontal = function(vChild)
444   {
445     this._applyComputedWidth(vChild);
446     vChild._applyRuntimeRight(this._lastRight);
447   }
448
449   qx.Proto.layoutChild_location_vertical = function(vChild)
450   {
451     this._applyComputedHeight(vChild);
452     vChild._applyRuntimeBottom(this._lastBottom);
453   }
454
455   qx.Proto.layoutChild_location_right = function(vChild, vJobs)
456   {
457     vChild._applyRuntimeRight(this._lastRight);
458     vChild._applyRuntimeTop(this._lastTop);
459
460     this.layoutChild_location_vertical(vChild);
461
462     this._lastRight += vChild.getBoxWidth();
463   }
464
465   qx.Proto.layoutChild_location_bottom = function(vChild, vJobs)
466   {
467     vChild._applyRuntimeBottom(this._lastBottom);
468     vChild._applyRuntimeLeft(this._lastLeft);
469
470     this.layoutChild_location_horizontal(vChild);
471
472     this._lastBottom += vChild.getBoxHeight();
473   }
474
475   qx.Proto.layoutChild_location_default = function(vChild, vJobs)
476   {
477     vChild._resetRuntimeWidth();
478     vChild._resetRuntimeHeight();
479
480     vChild._applyRuntimeTop(this._lastTop);
481     vChild._applyRuntimeRight(this._lastRight);
482     vChild._applyRuntimeBottom(this._lastBottom);
483     vChild._applyRuntimeLeft(this._lastLeft);
484
485     this._applyComputedWidth(vChild);
486     this._applyComputedHeight(vChild);
487   }
488 }