summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/framework/source/class/qx/renderer/layout/GridLayoutImpl.js
blob: ecb8c899a7c73d62e6c7cd1fd250409924ad7c78 (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
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
/* ************************************************************************

   qooxdoo - the new era of web development

   http://qooxdoo.org

   Copyright:
     2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org

   License:
     LGPL 2.1: http://www.gnu.org/licenses/lgpl.html

   Authors:
     * Sebastian Werner (wpbasti)
     * Andreas Ecker (ecker)

************************************************************************ */

/* ************************************************************************

#module(ui_layout)

************************************************************************ */

qx.OO.defineClass("qx.renderer.layout.GridLayoutImpl", qx.renderer.layout.LayoutImpl,
function(vWidget) {
  qx.renderer.layout.LayoutImpl.call(this, vWidget);
});




/*!
  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:

  [04] UPDATE LAYOUT WHEN A CHILD CHANGES ITS OUTER DIMENSIONS
  [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
  [11] DISPOSER
*/



/*
---------------------------------------------------------------------------
  [01] COMPUTE BOX DIMENSIONS FOR AN INDIVIDUAL CHILD
---------------------------------------------------------------------------
*/

/*!
  Compute and return the box width of the given child.
*/
qx.Proto.computeChildBoxWidth = function(vChild)
{
  var vWidget = this.getWidget();
  var vColWidth = vWidget.getColumnInnerWidth(vChild._col, vChild._row);

  // extend colwidth to spanned area
  if (vWidget.isSpanStart(vChild._col, vChild._row))
  {
    var vEntry = vWidget.getSpanEntry(vChild._col, vChild._row);
    for (var i=1; i<vEntry.colLength; i++)
    {
      // right padding from the previous cell
      vColWidth += vWidget.getComputedCellPaddingRight(vChild._col + i - 1, vChild._row);

      // left padding from the current cell
      vColWidth += vWidget.getComputedCellPaddingLeft(vChild._col + i, vChild._row);

      // spacing between previous and current cell
      vColWidth += vWidget.getHorizontalSpacing();

      // inner width of the current cell plus
      vColWidth += vWidget.getColumnInnerWidth(vChild._col + i, vChild._row);
    }
  }

  return vChild.getAllowStretchX() ? vColWidth : Math.min(vChild.getWidthValue(), vColWidth);
}

/*!
  Compute and return the box height of the given child.
*/
qx.Proto.computeChildBoxHeight = function(vChild)
{
  var vWidget = this.getWidget();
  var vRowHeight = vWidget.getRowInnerHeight(vChild._col, vChild._row);

  // extend colwidth to spanned area
  if (vWidget.isSpanStart(vChild._col, vChild._row))
  {
    var vEntry = vWidget.getSpanEntry(vChild._col, vChild._row);
    for (var i=1; i<vEntry.rowLength; i++)
    {
      // right padding from the previous cell
      vRowHeight += vWidget.getComputedCellPaddingBottom(vChild._col, vChild._row + i - 1);

      // left padding from the current cell
      vRowHeight += vWidget.getComputedCellPaddingTop(vChild._col, vChild._row + i);

      // spacing between previous and current cell
      vRowHeight += vWidget.getVerticalSpacing();

      // inner width of the current cell plus
      vRowHeight += vWidget.getRowInnerHeight(vChild._col, vChild._row + i);
    }
  }

  return vChild.getAllowStretchY() ? vRowHeight : Math.min(vChild.getHeightValue(), vRowHeight);
}







/*
---------------------------------------------------------------------------
  [03] COMPUTE NEEDED DIMENSIONS FOR ALL CHILDREN
---------------------------------------------------------------------------
*/

/*!
  Compute and return the width needed by all children of this widget
  which is in a grid layout the width used by all columns.
*/
qx.Proto.computeChildrenNeededWidth = function()
{
  var vWidget = this.getWidget();
  var vSpacingX = vWidget.getHorizontalSpacing();
  var vSum = -vSpacingX;

  for (var i=0, l=vWidget.getColumnCount(); i<l; i++) {
    vSum += vWidget.getColumnBoxWidth(i) + vSpacingX;
  }

  return vSum;
}

/*!
  Compute and return the height needed by all children of this widget
  which is in a grid layout the height used by all rows.
*/
qx.Proto.computeChildrenNeededHeight = function()
{
  var vWidget = this.getWidget();
  var vSpacingY = vWidget.getVerticalSpacing();
  var vSum = -vSpacingY;

  for (var i=0, l=vWidget.getRowCount(); i<l; i++) {
    vSum += vWidget.getRowBoxHeight(i) + vSpacingY;
  }

  return vSum;
}







/*
---------------------------------------------------------------------------
  [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("locationX");

  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("locationY");

  return true;
}








/*
---------------------------------------------------------------------------
  [10] LAYOUT CHILD
---------------------------------------------------------------------------
*/

/*!
  This is called from qx.ui.core.Widget and  it's task is to apply the layout
  (excluding border and padding) to the child.
*/

qx.Proto.layoutChild = function(vChild, vJobs)
{
  var vWidget = this.getWidget();

  this.layoutChild_sizeX(vChild, vJobs);
  this.layoutChild_sizeY(vChild, vJobs);

  this.layoutChild_sizeLimitX(vChild, vJobs);
  this.layoutChild_sizeLimitY(vChild, vJobs);

  this.layoutChild_marginX(vChild, vJobs);
  this.layoutChild_marginY(vChild, vJobs);

  this.layoutChild_locationX(vChild, vJobs);
  this.layoutChild_locationY(vChild, vJobs);
}

qx.Proto.layoutChild_sizeX = function(vChild, vJobs)
{
  vChild._applyRuntimeWidth(vChild.getBoxWidth());
}

qx.Proto.layoutChild_sizeY = function(vChild, vJobs)
{
  vChild._applyRuntimeHeight(vChild.getBoxHeight());
}

qx.Proto.layoutChild_locationX = function(vChild, vJobs)
{
  var vWidget = this.getWidget();
  var vSpacingX = vWidget.getHorizontalSpacing();
  var vLocSumX = vWidget.getPaddingLeft() + vWidget.getComputedCellPaddingLeft(vChild._col, vChild._row);

  for (var i=0; i<vChild._col; i++) {
    vLocSumX += vWidget.getColumnBoxWidth(i) + vSpacingX;
  }

  switch(vChild.getHorizontalAlign() || vWidget.getColumnHorizontalAlignment(vChild._col) || vWidget.getRowHorizontalAlignment(vChild._row) || vWidget.getHorizontalChildrenAlign())
  {
    case "center":
      vLocSumX += Math.round((vWidget.getColumnInnerWidth(vChild._col, vChild._row) - vChild.getBoxWidth()) / 2);
      break;

    case "right":
      vLocSumX += vWidget.getColumnInnerWidth(vChild._col, vChild._row) - vChild.getBoxWidth();
      break;
  }

  vChild._applyRuntimeLeft(vLocSumX);
}

qx.Proto.layoutChild_locationY = function(vChild, vJobs)
{
  var vWidget = this.getWidget();
  var vSpacingY = vWidget.getVerticalSpacing();
  var vLocSumY = vWidget.getPaddingTop() + vWidget.getComputedCellPaddingTop(vChild._col, vChild._row);

  for (var i=0; i<vChild._row; i++) {
    vLocSumY += vWidget.getRowBoxHeight(i) + vSpacingY;
  }

  switch(vChild.getVerticalAlign() || vWidget.getRowVerticalAlignment(vChild._row) || vWidget.getColumnVerticalAlignment(vChild._col) || vWidget.getVerticalChildrenAlign())
  {
    case "middle":
      vLocSumY += Math.round((vWidget.getRowInnerHeight(vChild._col, vChild._row) - vChild.getBoxHeight()) / 2);
      break;

    case "bottom":
      vLocSumY += vWidget.getRowInnerHeight(vChild._col, vChild._row) - vChild.getBoxHeight();
      break;
  }

  vChild._applyRuntimeTop(vLocSumY);
}