summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/framework/source/class/qx/ui/listview/Header.js
blob: 5d11d5bdc007b381b6d7a89b4a69d784d075a0ba (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
/* ************************************************************************

   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_listview)

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

qx.OO.defineClass("qx.ui.listview.Header", qx.ui.layout.HorizontalBoxLayout,
function(vColumns)
{
  qx.ui.layout.HorizontalBoxLayout.call(this);

  // This fixes the innerWidth calculation difference between the grid(pane) and the head.
  this.setPaddingRight(qx.ui.core.Widget.SCROLLBAR_SIZE);


  // ************************************************************************
  //   STORE REFERENCE TO CONFIG ENTRY
  // ************************************************************************
  this._columns = vColumns;


  // ************************************************************************
  //   CREATE HEADER CELLS
  // ************************************************************************
  var vHeadCell, vHeadSeparator;

  for (var vCol in vColumns)
  {
    vHeadCell = new qx.ui.listview.HeaderCell(vColumns[vCol], vCol);
    vHeadSeparator = new qx.ui.listview.HeaderSeparator;

    this.add(vHeadCell, vHeadSeparator);

    if (vColumns[vCol].align) {
      vHeadCell.setHorizontalChildrenAlign(vColumns[vCol].align);

      if (vColumns[vCol].align == "right") {
        vHeadCell.setReverseChildrenOrder(true);
      }
    }

    // store some additional data
    vColumns[vCol].contentClass = qx.OO.classes["qx.ui.listview.ContentCell" + qx.lang.String.toFirstUp(vColumns[vCol].type || "text")];
    vColumns[vCol].headerCell = vHeadCell;
  }


  // ************************************************************************
  //   ADD EVENT LISTENERS
  // ************************************************************************
  this.addEventListener("mousemove", this._onmousemove);
  this.addEventListener("mousedown", this._onmousedown);
  this.addEventListener("mouseup", this._onmouseup);
  this.addEventListener("mouseout", this._onmouseout);
});

qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "list-view-header" });



/*
---------------------------------------------------------------------------
  RESIZE SYNC
---------------------------------------------------------------------------
*/

qx.Proto._syncColumnWidth = function(vWidth)
{
  var vChildren = this.getChildren();
  var vColumn = Math.ceil(vChildren.indexOf(this._resizeCell) / 2);

  this.getParent().getPane().setColumnWidth(vColumn, vWidth);
}

qx.Proto._syncResizeLine = function()
{
  qx.ui.core.Widget.flushGlobalQueues();

  var vParent = this.getParent();
  var vLine = vParent.getResizeLine();
  var vLeft = qx.dom.Location.getPageBoxLeft(this._resizeSeparator.getElement()) - qx.dom.Location.getPageInnerLeft(this.getElement());
  var vTop = qx.dom.Dimension.getBoxHeight(vParent.getHeader().getElement());
  var vHeight = qx.dom.Dimension.getBoxHeight(vParent.getElement()) - vTop;

  vLine._applyRuntimeTop(vTop);
  vLine._applyRuntimeHeight(vHeight);
  vLine._applyRuntimeLeft(vLeft);

  vLine.removeStyleProperty("visibility");
}




/*
---------------------------------------------------------------------------
  EVENT HANDLER
---------------------------------------------------------------------------
*/

qx.Proto._mshtml = qx.sys.Client.getInstance().isMshtml();

qx.Proto._onmousemove = function(e)
{
  if (!this.getParent().getResizable()) {
    return;
  }

  if (this._resizingActive)
  {
    // Slow down mshtml a bit
    if (this._mshtml)
    {
      if ((new Date).valueOf() - this._last < 50) {
        return;
      }

      this._last = (new Date).valueOf();
    }

    var vNewLeft = e.getPageX();
    var vSizeDiff = vNewLeft - this._resizeStart;
    var vCell = this._resizeCell;

    vCell.setWidth(Math.max(4, vCell.getWidth() + vSizeDiff));
    this._resizeStart = vNewLeft;

    if (this.getParent().getLiveResize())
    {
      this._syncColumnWidth(vCell._computeBoxWidth());
    }
    else
    {
      this._syncResizeLine();
    }
  }
  else
  {
    var vTarget = e.getTarget();
    var vEventPos = e.getPageX();
    var vTargetPosLeft = qx.dom.Location.getPageBoxLeft(vTarget.getElement());
    var vTargetPosRight = vTargetPosLeft + qx.dom.Dimension.getBoxWidth(vTarget.getElement());

    var vResizeCursor = false;
    var vResizeSeparator = null;

    if (vTarget instanceof qx.ui.listview.HeaderSeparator)
    {
      vResizeCursor = true;
      vResizeSeparator = vTarget;
    }
    else if ((vEventPos - vTargetPosLeft) <= 10)
    {
      // Ignore first column
      if (!vTarget.isFirstChild())
      {
        vResizeCursor = true;
        vResizeSeparator = vTarget.getPreviousSibling();
      }
    }
    else if ((vTargetPosRight - vEventPos) <= 10)
    {
      vResizeCursor = true;
      vResizeSeparator = vTarget.getNextSibling();
    }

    if (!(vResizeSeparator instanceof qx.ui.listview.HeaderSeparator))
    {
      vResizeSeparator = vTarget = vResizeCursor = null;
    }

    // Check if child is marked as resizable
    else if (vResizeSeparator)
    {
      var vResizeCell = vResizeSeparator.getPreviousSibling();

      if (vResizeCell && (vResizeCell._computedWidthTypePercent || vResizeCell._config.resizable == false)) {
        vResizeSeparator = vTarget = vResizeCursor = null;
      }
    }

    // Apply global cursor
    this.getTopLevelWidget().setGlobalCursor(vResizeCursor ? "e-resize" : null);

    // Store data for mousedown
    this._resizeSeparator = vResizeSeparator;
    this._resizeTarget = vTarget;
  }
}

qx.Proto._onmousedown = function(e)
{
  if (!this._resizeSeparator) {
    return;
  }

  this._resizingActive = true;
  this._resizeStart = e.getPageX();
  this._resizeCell = this._resizeSeparator.getPreviousSibling();

  if (!this.getParent().getLiveResize()) {
    this._syncResizeLine();
  }

  this.setCapture(true);
}

qx.Proto._onmouseup = function(e)
{
  if (!this._resizingActive) {
    return;
  }

  this._syncColumnWidth(this._resizeCell.getBoxWidth());

  this.setCapture(false);
  this.getTopLevelWidget().setGlobalCursor(null);

  // Remove hover effect
  this._resizeTarget.removeState("over");

  // Hide resize line
  this.getParent().getResizeLine().setStyleProperty("visibility", "hidden");

  this._cleanupResizing();
}

qx.Proto._onmouseout = function(e)
{
  if (!this.getCapture()) {
    this.getTopLevelWidget().setGlobalCursor(null);
  }
}

qx.Proto._cleanupResizing = function()
{
  delete this._resizingActive;

  delete this._resizeSeparator;
  delete this._resizeTarget;
  delete this._resizeStart;
  delete this._resizeCell;
}










/*
---------------------------------------------------------------------------
  DISPOSER
---------------------------------------------------------------------------
*/

qx.Proto.dispose = function()
{
  if (this.getDisposed()) {
    return;
  }

  this._cleanupResizing();

  this.removeEventListener("mousemove", this._onmousemove);
  this.removeEventListener("mousedown", this._onmousedown);
  this.removeEventListener("mouseup", this._onmouseup);
  this.removeEventListener("mouseout", this._onmouseout);

  this._columns = null;

  return qx.ui.layout.HorizontalBoxLayout.prototype.dispose.call(this);
}