// Copyright 2007. Adobe Systems Incorporated. All Rights Reserved.
package fl.containers {
import fl.core.UIComponent;
import fl.controls.BaseButton;
import fl.controls.ScrollBar;
import fl.events.ScrollEvent;
import fl.controls.ScrollPolicy;
import fl.controls.ScrollBarDirection;
import fl.core.InvalidationType;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.Graphics;
import flash.geom.Rectangle;
//--------------------------------------
// Events
//--------------------------------------
/**
* Dispatched when the user scrolls content by using the scroll bars on the
* component or the wheel on a mouse device.
*
* @eventType fl.events.ScrollEvent.SCROLL
*
* @includeExample examples/ScrollPane.scroll.1.as -noswf
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Event(name="scroll", type="fl.events.ScrollEvent")]
//--------------------------------------
// Styles
//--------------------------------------
/**
* @copy fl.controls.ScrollBar#style:downArrowDisabledSkin
*
* @default ScrollArrowDown_disabledSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="downArrowDisabledSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:downArrowDownSkin
*
* @default ScrollArrowDown_downSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="downArrowDownSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:downArrowOverSkin
*
* @default ScrollArrowDown_overSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="downArrowOverSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:downArrowUpSkin
*
* @default ScrollArrowDown_upSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="downArrowUpSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:thumbDisabledSkin
*
* @default ScrollThumb_upSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="thumbDisabledSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:thumbDownSkin
*
* @default ScrollThumb_downSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="thumbDownSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:thumbOverSkin
*
* @default ScrollThumb_overSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="thumbOverSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:thumbUpSkin
*
* @default ScrollThumb_upSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="thumbUpSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:trackDisabledSkin
*
* @default ScrollTrack_Skin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="trackDisabledSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:trackDownSkin
*
* @default ScrollTrack_Skin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="trackDownSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:trackOverSkin
*
* @default ScrollTrack_Skin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="trackOverSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:trackUpSkin
*
* @default ScrollTrack_Skin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="trackUpSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:upArrowDisabledSkin
*
* @default ScrollArrowUp_disabledSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="upArrowDisabledSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:upArrowDownSkin
*
* @default ScrollArrowUp_downSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="upArrowDownSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:upArrowOverSkin
*
* @default ScrollArrowUp_overSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="upArrowOverSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:upArrowUpSkin
*
* @default ScrollArrowUp_upSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="upArrowUpSkin", type="Class")]
/**
* @copy fl.controls.ScrollBar#style:thumbIcon
*
* @default ScrollBar_thumbIcon
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="thumbIcon", type="Class")]
/**
* @copy fl.controls.BaseButton#style:repeatDelay
*
* @default 500
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="repeatDelay", type="Number", format="Time")]
/**
* @copy fl.controls.BaseButton#style:repeatInterval
*
* @default 35
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="repeatInterval", type="Number", format="Time")]
/**
* The skin to be used as the background of the scroll pane.
*
* @default ScrollPane_upSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="skin", type="Class")]
/**
* Padding between the content (the component and scroll bar), and the outside edge of the background, in pixels.
*
* @default 0
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
* @internal [kenos] What does "control and scrollbar" mean here -- what is the relationship between these
* elements and the content? I'd like to make this more understandable
* but don't know how it should be written based on the current description.
*/
[Style(name="contentPadding", type="Number", format="Length")]
/**
* When the enabled
property is set to false
,
* interaction with the component is prevented and a white overlay is
* displayed over the component, dimming the component contents. The
* disabledAlpha
style specifies the level of transparency
* that is applied to this overlay. Valid values range from 0, for an
* overlay that is completely transparent, to 1 for an overlay that is opaque.
*
* @default 0.5
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="disabledAlpha", type="Number", format="Length")]
//--------------------------------------
// Class description
//--------------------------------------
/**
* The student_ar_fl_containers_BaseScrollPane class handles basic scroll pane functionality including events, styling,
* drawing the mask and background, the layout of scroll bars, and the handling of scroll positions.
*
*
By default, the student_ar_fl_containers_BaseScrollPane class is extended by the ScrollPane and SelectableList classes, * for all list-based components. This means that any component that uses horizontal or vertical * scrolling does not need to implement any scrolling, masking or layout logic, except for behavior * that is specific to the component.
* * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public class student_ar_fl_containers_BaseScrollPane extends UIComponent { /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _verticalScrollBar:ScrollBar; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _horizontalScrollBar:ScrollBar; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var contentScrollRect:Rectangle; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var disabledOverlay:Shape; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var background:DisplayObject; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var contentWidth:Number=0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var contentHeight:Number=0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _horizontalScrollPolicy:String; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _verticalScrollPolicy:String; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var contentPadding:Number=0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var availableWidth:Number; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var availableHeight:Number; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var vOffset:Number = 0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var vScrollBar:Boolean; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var hScrollBar:Boolean; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _maxHorizontalScrollPosition:Number = 0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _horizontalPageScrollSize:Number = 0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _verticalPageScrollSize:Number = 0; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var defaultLineScrollSize:Number = 4; /** * @private (protected) * * Iffalse
, uses contentWidth
to determine hscroll, otherwise uses fixed _maxHorizontalScroll
value.
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected var useFixedHorizontalScrolling:Boolean = false; // if false, uses contentWidth to determine hscroll, otherwise uses fixed _maxHorizontalScroll value
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected var _useBitmpScrolling:Boolean = false;
/**
* @private
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
private static var defaultStyles:Object = {
repeatDelay:500,repeatInterval:35,
skin:"ScrollPane_upSkin",
contentPadding:0,
disabledAlpha:0.5
};
/**
* @copy fl.core.UIComponent#getStyleDefinition()
*
* @includeExample ../core/examples/UIComponent.getStyleDefinition.1.as -noswf
*
* @see fl.core.UIComponent#getStyle() UIComponent.getStyle()
* @see fl.core.UIComponent#setStyle() UIComponent.setStyle()
* @see fl.managers.StyleManager StyleManager
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public static function getStyleDefinition():Object {
return mergeStyles(defaultStyles, ScrollBar.getStyleDefinition());
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected static const SCROLL_BAR_STYLES:Object = {
upArrowDisabledSkin: "upArrowDisabledSkin",
upArrowDownSkin:"upArrowDownSkin",
upArrowOverSkin:"upArrowOverSkin",
upArrowUpSkin:"upArrowUpSkin",
downArrowDisabledSkin:"downArrowDisabledSkin",
downArrowDownSkin:"downArrowDownSkin",
downArrowOverSkin:"downArrowOverSkin",
downArrowUpSkin:"downArrowUpSkin",
thumbDisabledSkin:"thumbDisabledSkin",
thumbDownSkin:"thumbDownSkin",
thumbOverSkin:"thumbOverSkin",
thumbUpSkin:"thumbUpSkin",
thumbIcon:"thumbIcon",
trackDisabledSkin:"trackDisabledSkin",
trackDownSkin:"trackDownSkin",
trackOverSkin:"trackOverSkin",
trackUpSkin:"trackUpSkin",
repeatDelay:"repeatDelay",
repeatInterval:"repeatInterval"
};
/**
* Creates a new student_ar_fl_containers_BaseScrollPane component instance.
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function student_ar_fl_containers_BaseScrollPane() {
super();
}
[Inspectable(defaultValue=true, verbose=1)]
/**
* @private
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function set enabled(value:Boolean):void {
if (enabled == value) {
return;
}
_verticalScrollBar.enabled = value;
_horizontalScrollBar.enabled = value;
super.enabled = value;
}
[Inspectable(defaultValue="auto",enumeration="on,off,auto")]
/**
* Gets or sets a value that indicates the state of the horizontal scroll
* bar. A value of ScrollPolicy.ON
indicates that the horizontal
* scroll bar is always on; a value of ScrollPolicy.OFF
indicates
* that the horizontal scroll bar is always off; and a value of ScrollPolicy.AUTO
* indicates that its state automatically changes. This property is used with
* other scrolling properties to set the setScrollProperties()
method
* of the scroll bar.
*
* @default ScrollPolicy.AUTO
*
* @see #verticalScrollPolicy
* @see fl.controls.ScrollPolicy ScrollPolicy
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get horizontalScrollPolicy():String {
return _horizontalScrollPolicy;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set horizontalScrollPolicy(value:String):void {
_horizontalScrollPolicy = value;
invalidate(InvalidationType.SIZE);
}
[Inspectable(defaultValue="auto",enumeration="on,off,auto")]
/**
* Gets or sets a value that indicates the state of the vertical scroll
* bar. A value of ScrollPolicy.ON
indicates that the vertical
* scroll bar is always on; a value of ScrollPolicy.OFF
indicates
* that the vertical scroll bar is always off; and a value of ScrollPolicy.AUTO
* indicates that its state automatically changes. This property is used with
* other scrolling properties to set the setScrollProperties()
method
* of the scroll bar.
*
* @default ScrollPolicy.AUTO
*
* @see #horizontalScrollPolicy
* @see fl.controls.ScrollPolicy ScrollPolicy
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get verticalScrollPolicy():String {
return _verticalScrollPolicy;
}
/**
* @private
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set verticalScrollPolicy(value:String):void {
_verticalScrollPolicy = value;
invalidate(InvalidationType.SIZE);
}
[Inspectable(defaultValue=4)]
/**
* Gets or sets a value that describes the amount of content to be scrolled,
* horizontally, when a scroll arrow is clicked. This value is measured in pixels.
*
* @default 4
*
* @see #horizontalPageScrollSize
* @see #verticalLineScrollSize
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get horizontalLineScrollSize():Number {
return _horizontalScrollBar.lineScrollSize;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set horizontalLineScrollSize(value:Number):void {
_horizontalScrollBar.lineScrollSize = value;
}
[Inspectable(defaultValue=4)]
/**
* Gets or sets a value that describes how many pixels to scroll vertically when a scroll arrow is clicked.
*
* @default 4
*
* @see #horizontalLineScrollSize
* @see #verticalPageScrollSize
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get verticalLineScrollSize():Number {
return _verticalScrollBar.lineScrollSize;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set verticalLineScrollSize(value:Number):void {
_verticalScrollBar.lineScrollSize = value;
}
/**
* Gets or sets a value that describes the horizontal position of the
* horizontal scroll bar in the scroll pane, in pixels.
*
* @default 0
*
* @includeExample examples/student_ar_fl_containers_BaseScrollPane.horizontalScrollPosition.1.as -noswf
*
* @see #maxHorizontalScrollPosition
* @see #verticalScrollPosition
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get horizontalScrollPosition():Number {
return _horizontalScrollBar.scrollPosition;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set horizontalScrollPosition(value:Number):void {
// We must force a redraw to ensure that the size is up to date.
drawNow();
_horizontalScrollBar.scrollPosition = value;
setHorizontalScrollPosition(_horizontalScrollBar.scrollPosition,false);
}
/**
* Gets or sets a value that describes the vertical position of the
* vertical scroll bar in the scroll pane, in pixels.
*
* @default 0
*
* @includeExample examples/student_ar_fl_containers_BaseScrollPane.horizontalScrollPosition.1.as -noswf
*
* @see #horizontalScrollPosition
* @see #maxVerticalScrollPosition
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get verticalScrollPosition():Number {
return _verticalScrollBar.scrollPosition;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set verticalScrollPosition(value:Number):void {
// We must force a redraw to ensure that the size is up to date.
drawNow();
_verticalScrollBar.scrollPosition = value;
setVerticalScrollPosition(_verticalScrollBar.scrollPosition,false);
}
/**
* Gets the maximum horizontal scroll position for the current content, in pixels.
*
* @see #horizontalScrollPosition
* @see #maxVerticalScrollPosition
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get maxHorizontalScrollPosition():Number {
drawNow();
return Math.max(0,contentWidth-availableWidth);
}
/**
* Gets the maximum vertical scroll position for the current content, in pixels.
*
* @see #maxHorizontalScrollPosition
* @see #verticalScrollPosition
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get maxVerticalScrollPosition():Number {
drawNow();
return Math.max(0,contentHeight-availableHeight);
}
/**
* When set to true
, the cacheAsBitmap
property for the scrolling content is set
* to true
; when set to false
this value is turned off.
*
* Note: Setting this property to true
increases scrolling performance.