|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de, |
| 3 |
* and EclipseSource |
| 4 |
* |
| 5 |
* This program and the accompanying materials are made available under the |
| 6 |
* terms of the Eclipse Public License v1.0 which accompanies this |
| 7 |
* distribution, and is available at http://www.eclipse.org/legal/epl-v10.html |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* 1&1 Internet AG and others - original API and implementation |
| 11 |
* EclipseSource - adaptation for the Eclipse Rich Ajax Platform |
| 12 |
******************************************************************************/ |
| 13 |
|
| 14 |
qx.Class.define( "org.eclipse.swt.widgets.Scrollable", { |
| 15 |
extend : qx.ui.layout.CanvasLayout, |
| 16 |
|
| 17 |
construct : function( clientArea ) { |
| 18 |
this.base( arguments ); |
| 19 |
this._clientArea = clientArea; |
| 20 |
this._horzScrollBar = new qx.ui.basic.ScrollBar( true ); |
| 21 |
this._vertScrollBar = new qx.ui.basic.ScrollBar( false ); |
| 22 |
this._blockScrolling = false; |
| 23 |
this._internalChangeFlag = false; |
| 24 |
this.add( this._clientArea ); |
| 25 |
this.add( this._horzScrollBar ); |
| 26 |
this.add( this._vertScrollBar ); |
| 27 |
this._configureScrollBars(); |
| 28 |
this._configureClientArea(); |
| 29 |
this.__onscroll = qx.lang.Function.bindEvent( this._onscroll, this ); |
| 30 |
}, |
| 31 |
|
| 32 |
destruct : function() { |
| 33 |
var el = this._clientArea._getTargetNode(); |
| 34 |
if( el ) { |
| 35 |
var eventUtil = qx.html.EventRegistration; |
| 36 |
eventUtil.removeEventListener( el, "scroll", this.__onscroll ); |
| 37 |
delete this.__onscroll; |
| 38 |
} |
| 39 |
this._clientArea = null; |
| 40 |
this._horzScrollBar = null; |
| 41 |
this._vertScrollBar = null; |
| 42 |
}, |
| 43 |
|
| 44 |
events : { |
| 45 |
"userScroll" : "qx.event.type.Event" |
| 46 |
}, |
| 47 |
|
| 48 |
members : { |
| 49 |
|
| 50 |
///////// |
| 51 |
// Public |
| 52 |
|
| 53 |
setScrollBarsVisible : function( horizontal, vertical ) { |
| 54 |
this._horzScrollBar.setDisplay( horizontal ); |
| 55 |
this._vertScrollBar.setDisplay( vertical ); |
| 56 |
var overflow = "hidden"; |
| 57 |
if( horizontal && vertical ) { |
| 58 |
overflow = "scroll"; |
| 59 |
} else if( horizontal ) { |
| 60 |
overflow = "scrollX"; |
| 61 |
} else if( vertical ) { |
| 62 |
overflow = "scrollY"; |
| 63 |
} |
| 64 |
this._clientArea.setOverflow( overflow ); |
| 65 |
this._layoutX(); |
| 66 |
this._layoutY(); |
| 67 |
}, |
| 68 |
|
| 69 |
setHBarSelection : function( value ) { |
| 70 |
this._internalChangeFlag = true; |
| 71 |
if( this._horzScrollBar.getMaximum() < value ) { |
| 72 |
// TODO [tb] : The ScrollBar should do that itself |
| 73 |
this._horzScrollBar.setMaximum( value ); |
| 74 |
} |
| 75 |
this._horzScrollBar.setValue( value ); |
| 76 |
this._internalChangeFlag = false; |
| 77 |
}, |
| 78 |
|
| 79 |
setVBarSelection : function( value ) { |
| 80 |
this._internalChangeFlag = true; |
| 81 |
if( this._vertScrollBar.getMaximum() < value ) { |
| 82 |
// TODO [tb] : The ScrollBar should do that itself |
| 83 |
this._vertScrollBar.setMaximum( value ); |
| 84 |
} |
| 85 |
this._vertScrollBar.setValue( value ); |
| 86 |
this._internalChangeFlag = false; |
| 87 |
}, |
| 88 |
|
| 89 |
setBlockScrolling : function( value ) { |
| 90 |
this._blockScrolling = value; |
| 91 |
}, |
| 92 |
|
| 93 |
///////// |
| 94 |
// Layout |
| 95 |
|
| 96 |
_configureClientArea : function() { |
| 97 |
this._clientArea.setOverflow( "scroll" ); |
| 98 |
this._clientArea.setLeft( 0 ); |
| 99 |
this._clientArea.setTop( 0 ); |
| 100 |
this._clientArea.addEventListener( "create", this._onClientCreate, this ); |
| 101 |
this._clientArea.addEventListener( "appear", this._onClientAppear, this ); |
| 102 |
// TOOD [tb] : Do this with an eventlistner after fixing Bug 327023 |
| 103 |
this._clientArea._layoutPost |
| 104 |
= qx.lang.Function.bindEvent( this._onClientLayout, this ); |
| 105 |
}, |
| 106 |
|
| 107 |
_configureScrollBars : function() { |
| 108 |
var dragBlocker = function( event ) { event.stopPropagation(); }; |
| 109 |
var preferredWidth = this._vertScrollBar.getPreferredBoxWidth(); |
| 110 |
var preferredHeight = this._horzScrollBar.getPreferredBoxHeight(); |
| 111 |
this._horzScrollBar.setLeft( 0 ); |
| 112 |
this._horzScrollBar.setHeight( preferredHeight ); |
| 113 |
this._horzScrollBar.addEventListener( "dragstart", dragBlocker ); |
| 114 |
this._vertScrollBar.setTop( 0 ); |
| 115 |
this._vertScrollBar.setWidth( preferredWidth ); |
| 116 |
this._vertScrollBar.addEventListener( "dragstart", dragBlocker ); |
| 117 |
this._horzScrollBar.addEventListener( "changeValue", |
| 118 |
this._onHorzScrollBarChangeValue, |
| 119 |
this ); |
| 120 |
this._vertScrollBar.addEventListener( "changeValue", |
| 121 |
this._onVertScrollBarChangeValue, |
| 122 |
this ); |
| 123 |
}, |
| 124 |
|
| 125 |
_applyWidth : function( newValue, oldValue ) { |
| 126 |
this.base( arguments, newValue, oldValue ); |
| 127 |
this._layoutX(); |
| 128 |
}, |
| 129 |
|
| 130 |
_applyHeight : function( newValue, oldValue ) { |
| 131 |
this.base( arguments, newValue, oldValue ); |
| 132 |
this._layoutY(); |
| 133 |
}, |
| 134 |
|
| 135 |
_applyBorder : function( newValue, oldValue ) { |
| 136 |
this.base( arguments, newValue, oldValue ); |
| 137 |
this._layoutX(); |
| 138 |
this._layoutY(); |
| 139 |
}, |
| 140 |
|
| 141 |
_layoutX : function() { |
| 142 |
var clientWidth = this.getWidth() - this.getFrameWidth(); |
| 143 |
if( this._vertScrollBar.getDisplay() ) { |
| 144 |
clientWidth -= this._vertScrollBar.getWidth(); |
| 145 |
} |
| 146 |
this._clientArea.setWidth( clientWidth ); |
| 147 |
this._vertScrollBar.setLeft( clientWidth ); |
| 148 |
this._horzScrollBar.setWidth( clientWidth ); |
| 149 |
}, |
| 150 |
|
| 151 |
_layoutY : function() { |
| 152 |
var clientHeight = this.getHeight() - this.getFrameHeight(); |
| 153 |
if( this._horzScrollBar.getDisplay() ) { |
| 154 |
clientHeight -= this._horzScrollBar.getHeight(); |
| 155 |
} |
| 156 |
this._clientArea.setHeight( clientHeight ); |
| 157 |
this._vertScrollBar.setHeight( clientHeight ); |
| 158 |
this._horzScrollBar.setTop( clientHeight ); |
| 159 |
}, |
| 160 |
|
| 161 |
_onClientCreate : function( evt ) { |
| 162 |
this._clientArea.prepareEnhancedBorder(); |
| 163 |
var el = this._clientArea._getTargetNode(); |
| 164 |
var eventUtil = qx.html.EventRegistration; |
| 165 |
eventUtil.addEventListener( el, "scroll", this.__onscroll ); |
| 166 |
}, |
| 167 |
|
| 168 |
_onClientLayout : function() { |
| 169 |
// TODO [tb] : _getScrollBarWidth should be a static function, it has |
| 170 |
// nothing to do with the instance, which here is only used to call it |
| 171 |
var barWidth = this._horzScrollBar._getScrollBarWidth(); |
| 172 |
var node = this._clientArea._getTargetNode(); |
| 173 |
var el = this._clientArea.getElement(); |
| 174 |
var overflow = this._clientArea.getOverflow(); |
| 175 |
var width = parseInt( el.style.width ); |
| 176 |
var height = parseInt( el.style.height ); |
| 177 |
if( overflow === "scroll" || overflow === "scrollY" ) { |
| 178 |
width += barWidth; |
| 179 |
} |
| 180 |
if( overflow === "scroll" || overflow === "scrollX" ) { |
| 181 |
height += barWidth; |
| 182 |
} |
| 183 |
node.style.width = width |
| 184 |
node.style.height = height; |
| 185 |
}, |
| 186 |
|
| 187 |
//////////// |
| 188 |
// Scrolling |
| 189 |
|
| 190 |
_onHorzScrollBarChangeValue : function() { |
| 191 |
if( this._isCreated ) { |
| 192 |
this._syncClientArea( true, false ); |
| 193 |
} |
| 194 |
if( !this._internalChangeFlag ) { |
| 195 |
this.createDispatchEvent( "userScroll" ); |
| 196 |
} |
| 197 |
}, |
| 198 |
|
| 199 |
_onVertScrollBarChangeValue : function() { |
| 200 |
if( this._isCreated ) { |
| 201 |
this._syncClientArea( false, true ); |
| 202 |
} |
| 203 |
if( !this._internalChangeFlag ) { |
| 204 |
this.createDispatchEvent( "userScroll" ); |
| 205 |
} |
| 206 |
}, |
| 207 |
|
| 208 |
_onClientAppear : function() { |
| 209 |
this._internalChangeFlag = true; |
| 210 |
this._syncClientArea( true, true ); |
| 211 |
this._internalChangeFlag = false; |
| 212 |
}, |
| 213 |
|
| 214 |
_onscroll : function( evt ) { |
| 215 |
if( !this._internalChangeFlag ) { |
| 216 |
org.eclipse.rwt.EventHandlerUtil.stopDomEvent( evt ); |
| 217 |
var blockH = this._blockScrolling || !this._horzScrollBar.getDisplay(); |
| 218 |
var blockV = this._blockScrolling || !this._vertScrollBar.getDisplay(); |
| 219 |
this._internalChangeFlag = true; |
| 220 |
this._syncClientArea( blockH, blockV ); |
| 221 |
this._internalChangeFlag = false; |
| 222 |
this._syncScrollBars(); |
| 223 |
} |
| 224 |
}, |
| 225 |
|
| 226 |
_syncClientArea : function( horz, vert ) { |
| 227 |
if( horz ) { |
| 228 |
var scrollX = this._horzScrollBar.getValue(); |
| 229 |
this._clientArea.setScrollLeft( scrollX ); |
| 230 |
} |
| 231 |
if( vert ) { |
| 232 |
var scrollY = this._vertScrollBar.getValue(); |
| 233 |
this._clientArea.setScrollTop( scrollY ); |
| 234 |
} |
| 235 |
}, |
| 236 |
|
| 237 |
_syncScrollBars : function() { |
| 238 |
var scrollX = this._clientArea.getScrollLeft(); |
| 239 |
this._horzScrollBar.setValue( scrollX ); |
| 240 |
var scrollY = this._clientArea.getScrollTop(); |
| 241 |
this._vertScrollBar.setValue( scrollY ); |
| 242 |
} |
| 243 |
|
| 244 |
} |
| 245 |
} ); |