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
|
/* ************************************************************************
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)
* David Perez (david-perez)
************************************************************************ */
/* ************************************************************************
#module(ui_resizer)
************************************************************************ */
/**
* This class acts as a wrapper for other child, and allows it to be resized (not moved), normally in
* the right and/or bottom directions. Child can be e.g. a qx.ui.form.TextArea,
* qx.ui.table.Table or qx.ui.form.List. It is an alternative to splitters.
*/
qx.OO.defineClass('qx.ui.resizer.Resizer', qx.ui.layout.CanvasLayout,
function(child)
{
qx.ui.layout.CanvasLayout.call(this);
this._frame = new qx.ui.basic.Terminator;
this._frame.setAppearance("resizer-frame");
this._registerResizeEvents();
this.setAppearance('resizer');
this.setResizeableWest(false);
this.setResizeableNorth(false);
this.setMinWidth("auto");
this.setMinHeight("auto");
this.auto();
if (child)
{
// Remove child border, as the resizer has already its own border.
child.setBorder(new qx.renderer.border.Border(0));
this.add(this._child = child);
}
});
/*!
If the window is resizeable in the left direction.
*/
qx.OO.addProperty({ name : "resizeableWest", type : "boolean", defaultValue : true });
/*!
If the window is resizeable in the top direction.
*/
qx.OO.addProperty({ name : "resizeableNorth", type : "boolean", defaultValue : true });
/*!
If the window is resizeable in the right direction.
*/
qx.OO.addProperty({ name : "resizeableEast", type : "boolean", defaultValue : true });
/*!
If the window is resizeable in the bottom direction.
*/
qx.OO.addProperty({ name : "resizeableSouth", type : "boolean", defaultValue : true });
/*!
If the window is resizeable
*/
qx.OO.addPropertyGroup({ name : "resizeable", members : [ "west", "north", "east", "south" ], mode : "shorthand" });
/*!
The resize method to use
*/
qx.OO.addProperty({ name : "resizeMethod", type : "string", defaultValue : "frame", possibleValues : [ "opaque", "lazyopaque", "frame", "translucent" ] });
/*!
The resize method to use
*/
qx.OO.addProperty({ name : "resizeMethod", type : "string", defaultValue : "frame", possibleValues : [ "opaque", "lazyopaque", "frame", "translucent" ] });
/**
* Adjust so that it returns a boolean instead of an array.
* @return {Boolean}
*/
qx.Proto.isResizeable = qx.Proto.getResizeable = function() {
return this.getResizeableWest() || this.getResizeableEast() || this.getResizeableNorth() || this.getResizeableSouth();
}
qx.Proto._registerResizeEvents = function() {
this.addEventListener("mousedown", this._onmousedown);
this.addEventListener("mouseup", this._onmouseup);
this.addEventListener("mousemove", this._onmousemove);
}
qx.Proto._onmousedown = function(e)
{
if (this._resizeNorth || this._resizeSouth || this._resizeWest || this._resizeEast)
{
// enable capturing
this.setCapture(true);
// activate global cursor
this.getTopLevelWidget().setGlobalCursor(this.getCursor());
// caching element
var el = this.getElement();
// measuring and caching of values for resize session
var pa = this.getTopLevelWidget();
var pl = pa.getElement();
var l = qx.html.Location.getPageAreaLeft(pl);
var t = qx.html.Location.getPageAreaTop(pl);
var r = qx.html.Location.getPageAreaRight(pl);
var b = qx.html.Location.getPageAreaBottom(pl);
// handle frame and translucently
switch(this.getResizeMethod())
{
case "translucent":
this.setOpacity(0.5);
break;
case "frame":
var f = this._frame;
if (f.getParent() != pa)
{
f.setParent(pa);
qx.ui.core.Widget.flushGlobalQueues();
}
f._applyRuntimeLeft(qx.html.Location.getPageBoxLeft(el) - l);
f._applyRuntimeTop(qx.html.Location.getPageBoxTop(el) - t);
f._applyRuntimeWidth(qx.html.Dimension.getBoxWidth(el));
f._applyRuntimeHeight(qx.html.Dimension.getBoxHeight(el));
f.setZIndex(this.getZIndex() + 1);
break;
}
// create resize session
var s = this._resizeSession = {};
var minRef = this._child;
if (this._resizeWest)
{
s.boxWidth = qx.html.Dimension.getBoxWidth(el);
s.boxRight = qx.html.Location.getPageBoxRight(el);
}
if (this._resizeWest || this._resizeEast)
{
s.boxLeft = qx.html.Location.getPageBoxLeft(el);
s.parentAreaOffsetLeft = l;
s.parentAreaOffsetRight = r;
s.minWidth = minRef.getMinWidthValue();
s.maxWidth = minRef.getMaxWidthValue();
}
if (this._resizeNorth)
{
s.boxHeight = qx.html.Dimension.getBoxHeight(el);
s.boxBottom = qx.html.Location.getPageBoxBottom(el);
}
if (this._resizeNorth || this._resizeSouth)
{
s.boxTop = qx.html.Location.getPageBoxTop(el);
s.parentAreaOffsetTop = t;
s.parentAreaOffsetBottom = b;
s.minHeight = minRef.getMinHeightValue();
s.maxHeight = minRef.getMaxHeightValue();
}
}
else
{
// cleanup resize session
delete this._resizeSession;
}
// stop event
e.stopPropagation();
}
qx.Proto._onmouseup = function(e)
{
var s = this._resizeSession;
if (s)
{
// disable capturing
this.setCapture(false);
// deactivate global cursor
this.getTopLevelWidget().setGlobalCursor(null);
// sync sizes to frame
switch(this.getResizeMethod())
{
case "frame":
var o = this._frame;
if (!(o && o.getParent())) {
break;
}
// no break here
case "lazyopaque":
if (s.lastLeft != null) {
this.setLeft(s.lastLeft);
}
if (s.lastTop != null) {
this.setTop(s.lastTop);
}
if (s.lastWidth != null) {
var child = this.getChildren()[0];
if (child) {
child.setWidth(s.lastWidth);
}
}
if (s.lastHeight != null) {
var child = this.getChildren()[0];
if (child) {
child.setHeight(s.lastHeight);
}
}
if (this.getResizeMethod() == "frame") {
this._frame.setParent(null);
}
break;
case "translucent":
this.setOpacity(null);
break;
}
// cleanup session
delete this._resizeNorth;
delete this._resizeEast;
delete this._resizeSouth;
delete this._resizeWest;
delete this._resizeSession;
}
// stop event
e.stopPropagation();
}
qx.Proto._near = function(p, e) {
return e > (p - 5) && e < (p + 5);
}
qx.Proto._onmousemove = function(e)
{
var s = this._resizeSession;
if (s)
{
if (this._resizeWest)
{
s.lastWidth = qx.lang.Number.limit(s.boxWidth + s.boxLeft - Math.max(e.getPageX(), s.parentAreaOffsetLeft), s.minWidth, s.maxWidth);
s.lastLeft = s.boxRight - s.lastWidth - s.parentAreaOffsetLeft;
}
else if (this._resizeEast)
{
s.lastWidth = qx.lang.Number.limit(Math.min(e.getPageX(), s.parentAreaOffsetRight) - s.boxLeft, s.minWidth, s.maxWidth);
}
if (this._resizeNorth)
{
s.lastHeight = qx.lang.Number.limit(s.boxHeight + s.boxTop - Math.max(e.getPageY(), s.parentAreaOffsetTop), s.minHeight, s.maxHeight);
s.lastTop = s.boxBottom - s.lastHeight - s.parentAreaOffsetTop;
}
else if (this._resizeSouth)
{
s.lastHeight = qx.lang.Number.limit(Math.min(e.getPageY(), s.parentAreaOffsetBottom) - s.boxTop, s.minHeight, s.maxHeight);
}
switch(this.getResizeMethod())
{
case "opaque":
case "translucent":
if (this._resizeWest || this._resizeEast)
{
this.setWidth(s.lastWidth);
if (this._resizeWest) {
this.setLeft(s.lastLeft);
}
}
if (this._resizeNorth || this._resizeSouth)
{
this.setHeight(s.lastHeight);
if (this._resizeNorth) {
this.setTop(s.lastTop);
}
}
break;
default:
var o = this.getResizeMethod() == "frame" ? this._frame : this;
if (this._resizeWest || this._resizeEast)
{
o._applyRuntimeWidth(s.lastWidth);
if (this._resizeWest) {
o._applyRuntimeLeft(s.lastLeft);
}
}
if (this._resizeNorth || this._resizeSouth)
{
o._applyRuntimeHeight(s.lastHeight);
if (this._resizeNorth) {
o._applyRuntimeTop(s.lastTop);
}
}
}
}
else
{
var resizeMode = "";
var el = this.getElement();
this._resizeNorth = this._resizeSouth = this._resizeWest = this._resizeEast = false;
if (this._near(qx.html.Location.getPageBoxTop(el), e.getPageY()))
{
if (this.getResizeableNorth()) {
resizeMode = "n";
this._resizeNorth = true;
}
}
else if (this._near(qx.html.Location.getPageBoxBottom(el), e.getPageY()))
{
if (this.getResizeableSouth()) {
resizeMode = "s";
this._resizeSouth = true;
}
}
if (this._near(qx.html.Location.getPageBoxLeft(el), e.getPageX()))
{
if (this.getResizeableWest()) {
resizeMode += "w";
this._resizeWest = true;
}
}
else if (this._near(qx.html.Location.getPageBoxRight(el), e.getPageX()))
{
if (this.getResizeableEast()) {
resizeMode += "e";
this._resizeEast = true;
}
}
if (this._resizeNorth || this._resizeSouth || this._resizeWest || this._resizeEast)
{
this.setCursor(resizeMode + "-resize");
}
else
{
this.setCursor(null);
}
}
// stop event
e.stopPropagation();
}
qx.Proto.dispose = function()
{
if (this.getDisposed()) {
return true;
}
if (this._frame)
{
this._frame.dispose();
this._frame = null;
}
return qx.ui.layout.CanvasLayout.prototype.dispose.call(this);
}
|