/client/src/fl/controls/ScrollBar.as

https://github.com/lilin01/haha · ActionScript · 1085 lines · 296 code · 66 blank · 723 comment · 48 complexity · 4047f5d81de746ba33d51917f9ec128e MD5 · raw file

  1. // Copyright 2007. Adobe Systems Incorporated. All Rights Reserved.
  2. package fl.controls {
  3. import fl.controls.BaseButton;
  4. import fl.controls.LabelButton;
  5. import fl.controls.ScrollBarDirection;
  6. import fl.core.UIComponent;
  7. import fl.core.InvalidationType;
  8. import fl.events.ComponentEvent;
  9. import fl.events.ScrollEvent;
  10. import flash.display.Sprite;
  11. import flash.events.Event;
  12. import flash.events.MouseEvent;
  13. import flash.events.TimerEvent;
  14. import flash.text.TextField;
  15. import flash.text.TextFormat;
  16. import flash.utils.Timer;
  17. import fl.controls.TextInput;
  18. //--------------------------------------
  19. // Events
  20. //--------------------------------------
  21. /**
  22. * Dispatched when the ScrollBar instance's <code>scrollPosition</code> property changes.
  23. *
  24. * @eventType fl.events.ScrollEvent.SCROLL
  25. *
  26. * @see #scrollPosition
  27. *
  28. * @langversion 3.0
  29. * @playerversion Flash 9.0.28.0
  30. *
  31. * @playerversion AIR 1.0
  32. * @productversion Flash CS3
  33. */
  34. [Event(name="scroll", type="fl.events.ScrollEvent") ]
  35. //--------------------------------------
  36. // Styles
  37. //--------------------------------------
  38. /**
  39. * Name of the class to use as the skin for the down arrow button of the scroll bar
  40. * when it is disabled. If you change the skin, either graphically or programmatically,
  41. * you should ensure that the new skin is the same height (for horizontal scroll bars)
  42. * or width (for vertical scroll bars) as the track.
  43. *
  44. * @default ScrollArrowDown_disabledSkin
  45. *
  46. * @langversion 3.0
  47. * @playerversion Flash 9.0.28.0
  48. *
  49. * @playerversion AIR 1.0
  50. * @productversion Flash CS3
  51. */
  52. [Style(name="downArrowDisabledSkin", type="Class")]
  53. /**
  54. * Name of the class to use as the skin for the down arrow button of the scroll bar
  55. * when you click the arrow button. If you change the skin, either graphically or
  56. * programmatically, you should ensure that the new skin is the same height (for
  57. * horizontal scroll bars) or width (for vertical scroll bars) as the track.
  58. *
  59. * @default ScrollArrowDown_downSkin
  60. *
  61. * @langversion 3.0
  62. * @playerversion Flash 9.0.28.0
  63. *
  64. * @playerversion AIR 1.0
  65. * @productversion Flash CS3
  66. */
  67. [Style(name="downArrowDownSkin", type="Class")]
  68. /**
  69. * Name of the class to use as the skin for the down arrow button of the scroll bar
  70. * when the mouse pointer is over the arrow button. If you change the skin, either
  71. * graphically or programmatically, you should ensure that the new skin is the same
  72. * height (for horizontal scroll bars) or width (for vertical scroll bars) as the track.
  73. *
  74. * @default ScrollArrowDown_overSkin
  75. *
  76. * @langversion 3.0
  77. * @playerversion Flash 9.0.28.0
  78. *
  79. * @playerversion AIR 1.0
  80. * @productversion Flash CS3
  81. */
  82. [Style(name="downArrowOverSkin", type="Class")]
  83. /**
  84. * Name of the class to use as the skin for the down arrow button of the scroll bar.
  85. * If you change the skin, either graphically or programmatically, you should ensure
  86. * that the new skin is the same height (for horizontal scroll bars) or width (for
  87. * vertical scroll bars) as the track.
  88. *
  89. * @default ScrollArrowDown_upSkin
  90. *
  91. * @langversion 3.0
  92. * @playerversion Flash 9.0.28.0
  93. *
  94. * @playerversion AIR 1.0
  95. * @productversion Flash CS3
  96. */
  97. [Style(name="downArrowUpSkin", type="Class")]
  98. /**
  99. * The skin that is used to indicate the disabled state of the thumb.
  100. *
  101. * @default ScrollThumb_disabledSkin
  102. *
  103. * @langversion 3.0
  104. * @playerversion Flash 9.0.28.0
  105. *
  106. * @playerversion AIR 1.0
  107. * @productversion Flash CS3
  108. */
  109. [Style(name="thumbDisabledSkin", type="Class")]
  110. /**
  111. * Name of the class to use as the skin for the thumb of the scroll bar when you
  112. * click the thumb.
  113. *
  114. * @default ScrollThumb_downSkin
  115. *
  116. * @langversion 3.0
  117. * @playerversion Flash 9.0.28.0
  118. *
  119. * @playerversion AIR 1.0
  120. * @productversion Flash CS3
  121. */
  122. [Style(name="thumbDownSkin", type="Class")]
  123. /**
  124. * Name of the class to use as the skin for the thumb of the scroll bar when the
  125. * mouse pointer is over the thumb.
  126. *
  127. * @default ScrollThumb_overSkin
  128. *
  129. * @langversion 3.0
  130. * @playerversion Flash 9.0.28.0
  131. *
  132. * @playerversion AIR 1.0
  133. * @productversion Flash CS3
  134. */
  135. [Style(name="thumbOverSkin", type="Class")]
  136. /**
  137. * Name of the class to use as the skin used for the thumb of the scroll
  138. * bar.
  139. *
  140. * @default ScrollThumb_upSkin
  141. *
  142. * @langversion 3.0
  143. * @playerversion Flash 9.0.28.0
  144. *
  145. * @playerversion AIR 1.0
  146. * @productversion Flash CS3
  147. */
  148. [Style(name="thumbUpSkin", type="Class")]
  149. /**
  150. * The skin that is used to indicate a disabled track.
  151. *
  152. * @default ScrollTrack_Skin
  153. *
  154. * @langversion 3.0
  155. * @playerversion Flash 9.0.28.0
  156. *
  157. * @playerversion AIR 1.0
  158. * @productversion Flash CS3
  159. */
  160. [Style(name="trackDisabledSkin", type="Class")]
  161. /**
  162. * The skin that is used to indicate the down state of a disabled skin.
  163. *
  164. * @default ScrollTrack_Skin
  165. *
  166. * @langversion 3.0
  167. * @playerversion Flash 9.0.28.0
  168. *
  169. * @playerversion AIR 1.0
  170. * @productversion Flash CS3
  171. */
  172. [Style(name="trackDownSkin", type="Class")]
  173. /**
  174. * The skin that is used to indicate the mouseover state for the scroll track.
  175. *
  176. * @default ScrollTrack_Skin
  177. *
  178. * @langversion 3.0
  179. * @playerversion Flash 9.0.28.0
  180. *
  181. * @playerversion AIR 1.0
  182. * @productversion Flash CS3
  183. */
  184. [Style(name="trackOverSkin", type="Class")]
  185. /**
  186. * The skin used to indicate the mouse up state for the scroll track.
  187. *
  188. * @default ScrollTrack_Skin
  189. *
  190. * @langversion 3.0
  191. * @playerversion Flash 9.0.28.0
  192. *
  193. * @playerversion AIR 1.0
  194. * @productversion Flash CS3
  195. */
  196. [Style(name="trackUpSkin", type="Class")]
  197. /**
  198. * Name of the class to use as the skin for the up arrow button of the scroll bar
  199. * when it is disabled. If you change the skin, either graphically or programmatically,
  200. * you should ensure that the new skin is the same height (for horizontal scroll bars)
  201. * or width (for vertical scroll bars) as the track.
  202. *
  203. * @default ScrollArrowUp_disabledSkin
  204. *
  205. * @langversion 3.0
  206. * @playerversion Flash 9.0.28.0
  207. *
  208. * @playerversion AIR 1.0
  209. * @productversion Flash CS3
  210. */
  211. [Style(name="upArrowDisabledSkin", type="Class")]
  212. /**
  213. * Name of the class to use as the skin for the up arrow button of the scroll bar when
  214. * you click the arrow button. If you change the skin, either graphically or programmatically,
  215. * you should ensure that the new skin is the same height (for horizontal scroll bars) or width
  216. * (for vertical scroll bars) as the track.
  217. *
  218. * @default ScrollArrowUp_downSkin
  219. *
  220. * @langversion 3.0
  221. * @playerversion Flash 9.0.28.0
  222. *
  223. * @playerversion AIR 1.0
  224. * @productversion Flash CS3
  225. */
  226. [Style(name="upArrowDownSkin", type="Class")]
  227. /**
  228. * Name of the class to use as the skin for the up arrow button of the scroll bar when the
  229. * mouse pointer is over the arrow button. If you change the skin, either graphically or
  230. * programmatically, you should ensure that the new skin is the same height (for horizontal
  231. * scroll bars) or width (for vertical scroll bars) as the track.
  232. *
  233. * @default ScrollArrowUp_overSkin
  234. *
  235. * @langversion 3.0
  236. * @playerversion Flash 9.0.28.0
  237. *
  238. * @playerversion AIR 1.0
  239. * @productversion Flash CS3
  240. */
  241. [Style(name="upArrowOverSkin", type="Class")]
  242. /**
  243. * Name of the class to use as the skin for the up arrow button of the scroll bar. If you
  244. * change the skin, either graphically or programmatically, you should ensure that the new
  245. * skin is the same height (for horizontal scroll bars) or width (for vertical scroll bars)
  246. * as the track.
  247. *
  248. * @default ScrollArrowUp_upSkin
  249. *
  250. * @langversion 3.0
  251. * @playerversion Flash 9.0.28.0
  252. *
  253. * @playerversion AIR 1.0
  254. * @productversion Flash CS3
  255. */
  256. [Style(name="upArrowUpSkin", type="Class")]
  257. /**
  258. * Name of the class to use as the icon for the thumb of the scroll bar.
  259. *
  260. * @default ScrollBar_thumbIcon
  261. *
  262. * @langversion 3.0
  263. * @playerversion Flash 9.0.28.0
  264. *
  265. * @playerversion AIR 1.0
  266. * @productversion Flash CS3
  267. */
  268. [Style(name="thumbIcon", type="Class")]
  269. /**
  270. * @copy fl.controls.BaseButton#style:repeatDelay
  271. *
  272. * @default 500
  273. *
  274. * @langversion 3.0
  275. * @playerversion Flash 9.0.28.0
  276. *
  277. * @playerversion AIR 1.0
  278. * @productversion Flash CS3
  279. */
  280. [Style(name="repeatDelay", type="Number", format="Time")]
  281. /**
  282. * @copy fl.controls.BaseButton#style:repeatInterval
  283. *
  284. * @default 35
  285. *
  286. * @langversion 3.0
  287. * @playerversion Flash 9.0.28.0
  288. *
  289. * @playerversion AIR 1.0
  290. * @productversion Flash CS3
  291. */
  292. [Style(name="repeatInterval", type="Number", format="Time")]
  293. //--------------------------------------
  294. // Class description
  295. //--------------------------------------
  296. /**
  297. * The ScrollBar component provides the end user with a way to control the
  298. * portion of data that is displayed when there is too much data to
  299. * fit in the display area. The scroll bar consists of four parts:
  300. * two arrow buttons, a track, and a thumb. The position of the
  301. * thumb and display of the buttons depends on the current state of
  302. * the scroll bar. The scroll bar uses four parameters to calculate
  303. * its display state: a minimum range value; a maximum range value;
  304. * a current position that must be within the range values; and a
  305. * viewport size that must be equal to or less than the range and
  306. * represents the number of items in the range that can be
  307. * displayed at the same time.
  308. *
  309. * @langversion 3.0
  310. * @playerversion Flash 9.0.28.0
  311. *
  312. * @playerversion AIR 1.0
  313. * @productversion Flash CS3
  314. */
  315. public class ScrollBar extends UIComponent {
  316. /**
  317. * @private (internal)
  318. *
  319. * @langversion 3.0
  320. * @playerversion Flash 9.0.28.0
  321. */
  322. public static const WIDTH:Number = 15;
  323. /**
  324. * @private
  325. *
  326. * @langversion 3.0
  327. * @playerversion Flash 9.0.28.0
  328. */
  329. private var _pageSize:Number = 10;
  330. /**
  331. * @private
  332. *
  333. * @langversion 3.0
  334. * @playerversion Flash 9.0.28.0
  335. */
  336. private var _pageScrollSize:Number = 0;
  337. /**
  338. * @private
  339. *
  340. * @langversion 3.0
  341. * @playerversion Flash 9.0.28.0
  342. */
  343. private var _lineScrollSize:Number = 1;
  344. /**
  345. * @private
  346. *
  347. * @langversion 3.0
  348. * @playerversion Flash 9.0.28.0
  349. */
  350. private var _minScrollPosition:Number = 0;
  351. /**
  352. * @private
  353. *
  354. * @langversion 3.0
  355. * @playerversion Flash 9.0.28.0
  356. */
  357. private var _maxScrollPosition:Number = 0;
  358. /**
  359. * @private
  360. *
  361. * @langversion 3.0
  362. * @playerversion Flash 9.0.28.0
  363. */
  364. private var _scrollPosition:Number = 0;
  365. /**
  366. * @private
  367. *
  368. * @langversion 3.0
  369. * @playerversion Flash 9.0.28.0
  370. */
  371. private var _direction:String = ScrollBarDirection.VERTICAL;
  372. /**
  373. * @private
  374. *
  375. * @langversion 3.0
  376. * @playerversion Flash 9.0.28.0
  377. */
  378. private var thumbScrollOffset:Number;
  379. /**
  380. * @private
  381. *
  382. * @langversion 3.0
  383. * @playerversion Flash 9.0.28.0
  384. */
  385. protected var inDrag:Boolean = false;
  386. /**
  387. * @private (protected)
  388. *
  389. * @langversion 3.0
  390. * @playerversion Flash 9.0.28.0
  391. */
  392. protected var upArrow:BaseButton;
  393. /**
  394. * @private (protected)
  395. *
  396. * @langversion 3.0
  397. * @playerversion Flash 9.0.28.0
  398. */
  399. protected var downArrow:BaseButton;
  400. /**
  401. * @private (protected)
  402. *
  403. * @langversion 3.0
  404. * @playerversion Flash 9.0.28.0
  405. */
  406. protected var thumb:LabelButton;
  407. /**
  408. * @private (protected)
  409. *
  410. * @langversion 3.0
  411. * @playerversion Flash 9.0.28.0
  412. */
  413. protected var track:BaseButton;
  414. // Note that there is currently no disabled state for thumb,
  415. // and track only has one state.
  416. /**
  417. * @private
  418. *
  419. * @langversion 3.0
  420. * @playerversion Flash 9.0.28.0
  421. */
  422. private static var defaultStyles:Object = {downArrowDisabledSkin:"ScrollArrowDown_disabledSkin",downArrowDownSkin:"ScrollArrowDown_downSkin",downArrowOverSkin:"ScrollArrowDown_overSkin",downArrowUpSkin:"ScrollArrowDown_upSkin",
  423. thumbDisabledSkin:"ScrollThumb_upSkin",thumbDownSkin:"ScrollThumb_downSkin",thumbOverSkin:"ScrollThumb_overSkin",thumbUpSkin:"ScrollThumb_upSkin",
  424. trackDisabledSkin:"ScrollTrack_skin",trackDownSkin:"ScrollTrack_skin",trackOverSkin:"ScrollTrack_skin",trackUpSkin:"ScrollTrack_skin",
  425. upArrowDisabledSkin:"ScrollArrowUp_disabledSkin",upArrowDownSkin:"ScrollArrowUp_downSkin",upArrowOverSkin:"ScrollArrowUp_overSkin",upArrowUpSkin:"ScrollArrowUp_upSkin",
  426. thumbIcon:"ScrollBar_thumbIcon",
  427. repeatDelay:500,repeatInterval:35};
  428. /**
  429. * @copy fl.core.UIComponent#getStyleDefinition()
  430. *
  431. * @see fl.core.UIComponent#getStyle()
  432. * @see fl.core.UIComponent#setStyle()
  433. * @see fl.managers.StyleManager
  434. *
  435. * @langversion 3.0
  436. * @playerversion Flash 9.0.28.0
  437. *
  438. * @playerversion AIR 1.0
  439. * @productversion Flash CS3
  440. */
  441. public static function getStyleDefinition():Object {
  442. return defaultStyles;
  443. }
  444. /**
  445. * @private (protected)
  446. *
  447. * @langversion 3.0
  448. * @playerversion Flash 9.0.28.0
  449. */
  450. protected static const DOWN_ARROW_STYLES:Object = {
  451. disabledSkin:"downArrowDisabledSkin",
  452. downSkin:"downArrowDownSkin",
  453. overSkin:"downArrowOverSkin",
  454. upSkin:"downArrowUpSkin",
  455. repeatDelay:"repeatDelay",
  456. repeatInterval:"repeatInterval"
  457. };
  458. /**
  459. * @private (protected)
  460. *
  461. * @langversion 3.0
  462. * @playerversion Flash 9.0.28.0
  463. */
  464. protected static const THUMB_STYLES:Object = {
  465. disabledSkin:"thumbDisabledSkin",
  466. downSkin:"thumbDownSkin",
  467. overSkin:"thumbOverSkin",
  468. upSkin:"thumbUpSkin",
  469. icon:"thumbIcon",
  470. textPadding: 0
  471. };
  472. /**
  473. * @private (protected)
  474. *
  475. * @langversion 3.0
  476. * @playerversion Flash 9.0.28.0
  477. */
  478. protected static const TRACK_STYLES:Object = {
  479. disabledSkin:"trackDisabledSkin",
  480. downSkin:"trackDownSkin",
  481. overSkin:"trackOverSkin",
  482. upSkin:"trackUpSkin",
  483. repeatDelay:"repeatDelay",
  484. repeatInterval:"repeatInterval"
  485. };
  486. /**
  487. * @private (protected)
  488. *
  489. * @langversion 3.0
  490. * @playerversion Flash 9.0.28.0
  491. */
  492. protected static const UP_ARROW_STYLES:Object = {
  493. disabledSkin:"upArrowDisabledSkin",
  494. downSkin:"upArrowDownSkin",
  495. overSkin:"upArrowOverSkin",
  496. upSkin:"upArrowUpSkin",
  497. repeatDelay:"repeatDelay",
  498. repeatInterval:"repeatInterval"
  499. };
  500. /**
  501. * Creates a new ScrollBar component instance.
  502. *
  503. * @langversion 3.0
  504. * @playerversion Flash 9.0.28.0
  505. *
  506. * @playerversion AIR 1.0
  507. * @productversion Flash CS3
  508. */
  509. public function ScrollBar() {
  510. super();
  511. setStyles();
  512. focusEnabled = false;
  513. }
  514. /**
  515. * @copy fl.core.UIComponent#setSize()
  516. *
  517. * @see #height
  518. * @see #width
  519. *
  520. * @langversion 3.0
  521. * @playerversion Flash 9.0.28.0
  522. *
  523. * @playerversion AIR 1.0
  524. * @productversion Flash CS3
  525. */
  526. override public function setSize(width:Number, height:Number):void {
  527. if (_direction == ScrollBarDirection.HORIZONTAL) {
  528. super.setSize(height,width);
  529. } else {
  530. super.setSize(width,height);
  531. }
  532. }
  533. /**
  534. * @copy fl.core.UIComponent#width
  535. *
  536. * @see #height
  537. * @see #setSize()
  538. *
  539. * @langversion 3.0
  540. * @playerversion Flash 9.0.28.0
  541. *
  542. * @playerversion AIR 1.0
  543. * @productversion Flash CS3
  544. */
  545. override public function get width():Number {
  546. return (_direction == ScrollBarDirection.HORIZONTAL) ? super.height : super.width;
  547. }
  548. /**
  549. * @copy fl.core.UIComponent#height
  550. *
  551. * @see #setSize()
  552. * @see #width
  553. *
  554. * @langversion 3.0
  555. * @playerversion Flash 9.0.28.0
  556. *
  557. * @playerversion AIR 1.0
  558. * @productversion Flash CS3
  559. */
  560. override public function get height():Number {
  561. return (_direction == ScrollBarDirection.HORIZONTAL) ? super.width : super.height;
  562. }
  563. /**
  564. * Gets or sets a Boolean value that indicates whether the scroll bar is enabled.
  565. * A value of <code>true</code> indicates that the scroll bar is enabled; a value of
  566. * <code>false</code> indicates that it is not.
  567. *
  568. * @default true
  569. *
  570. * @langversion 3.0
  571. * @playerversion Flash 9.0.28.0
  572. *
  573. * @playerversion AIR 1.0
  574. * @productversion Flash CS3
  575. */
  576. override public function get enabled():Boolean {
  577. return super.enabled;
  578. }
  579. /**
  580. * @private (setter)
  581. *
  582. * @langversion 3.0
  583. * @playerversion Flash 9.0.28.0
  584. */
  585. override public function set enabled(value:Boolean):void {
  586. super.enabled = value;
  587. downArrow.enabled = track.enabled = thumb.enabled = upArrow.enabled = (enabled && _maxScrollPosition > _minScrollPosition);
  588. updateThumb();
  589. }
  590. /**
  591. * Sets the range and viewport size of the ScrollBar component. The ScrollBar
  592. * component updates the state of the arrow buttons and size of the scroll
  593. * thumb accordingly. All of the scroll properties are relative to the
  594. * scale of the <code>minScrollPosition</code> and the <code>maxScrollPosition</code>.
  595. * Each number between the maximum and minumum values represents one scroll position.
  596. *
  597. * @param pageSize Size of one page. Determines the size of the thumb, and the increment by which the scroll bar moves when the arrows are clicked.
  598. * @param minScrollPosition Bottom of the scrolling range.
  599. * @param maxScrollPosition Top of the scrolling range.
  600. * @param pageScrollSize Increment to move when a track is pressed, in pixels.
  601. *
  602. * @see #maxScrollPosition
  603. * @see #minScrollPosition
  604. * @see #pageScrollSize
  605. * @see #pageSize
  606. *
  607. * @langversion 3.0
  608. * @playerversion Flash 9.0.28.0
  609. *
  610. * @playerversion AIR 1.0
  611. * @productversion Flash CS3
  612. */
  613. public function setScrollProperties(pageSize:Number,minScrollPosition:Number,maxScrollPosition:Number,pageScrollSize:Number=0):void {
  614. this.pageSize = pageSize;
  615. _minScrollPosition = minScrollPosition;
  616. _maxScrollPosition = maxScrollPosition;
  617. if (pageScrollSize >= 0) { _pageScrollSize = pageScrollSize; }
  618. enabled = (_maxScrollPosition > _minScrollPosition);
  619. // ensure our scroll position is still in range:
  620. setScrollPosition(_scrollPosition, false);
  621. updateThumb();
  622. }
  623. /**
  624. * Gets or sets the current scroll position and updates the position
  625. * of the thumb. The <code>scrollPosition</code> value represents a relative position between
  626. * the <code>minScrollPosition</code> and <code>maxScrollPosition</code> values.
  627. *
  628. * @default 0
  629. *
  630. * @see #setScrollProperties()
  631. * @see #minScrollPosition
  632. * @see #maxScrollPosition
  633. *
  634. * @langversion 3.0
  635. * @playerversion Flash 9.0.28.0
  636. *
  637. * @playerversion AIR 1.0
  638. * @productversion Flash CS3
  639. */
  640. public function get scrollPosition():Number { return _scrollPosition; }
  641. /**
  642. * @private (setter)
  643. *
  644. * @langversion 3.0
  645. * @playerversion Flash 9.0.28.0
  646. */
  647. public function set scrollPosition(newScrollPosition:Number):void {
  648. setScrollPosition(newScrollPosition, true);
  649. }
  650. /**
  651. * Gets or sets a number that represents the minimum scroll position. The
  652. * <code>scrollPosition</code> value represents a relative position between the
  653. * <code>minScrollPosition</code> and the <code>maxScrollPosition</code> values.
  654. * This property is set by the component that contains the scroll bar,
  655. * and is usually zero.
  656. *
  657. * @default 0
  658. *
  659. * @see #setScrollProperties()
  660. * @see #maxScrollPosition
  661. * @see #scrollPosition
  662. *
  663. * @langversion 3.0
  664. * @playerversion Flash 9.0.28.0
  665. *
  666. * @playerversion AIR 1.0
  667. * @productversion Flash CS3
  668. */
  669. public function get minScrollPosition():Number {
  670. return _minScrollPosition;
  671. }
  672. /**
  673. * @private (setter)
  674. *
  675. * @langversion 3.0
  676. * @playerversion Flash 9.0.28.0
  677. */
  678. public function set minScrollPosition(value:Number):void {
  679. // This uses setScrollProperties because it needs to update thumb and enabled.
  680. setScrollProperties(_pageSize,value,_maxScrollPosition);
  681. }
  682. /**
  683. * Gets or sets a number that represents the maximum scroll position. The
  684. * <code>scrollPosition</code> value represents a relative position between the
  685. * <code>minScrollPosition</code> and the <code>maxScrollPosition</code> values.
  686. * This property is set by the component that contains the scroll bar,
  687. * and is the maximum value. Usually this property describes the number
  688. * of pixels between the bottom of the component and the bottom of
  689. * the content, but this property is often set to a different value to change the
  690. * behavior of the scrolling. For example, the TextArea component sets this
  691. * property to the <code>maxScrollH</code> value of the text field, so that the
  692. * scroll bar scrolls appropriately by line of text.
  693. *
  694. * @default 0
  695. *
  696. * @see #setScrollProperties()
  697. * @see #minScrollPosition
  698. * @see #scrollPosition
  699. *
  700. * @langversion 3.0
  701. * @playerversion Flash 9.0.28.0
  702. *
  703. * @playerversion AIR 1.0
  704. * @productversion Flash CS3
  705. */
  706. public function get maxScrollPosition():Number {
  707. return _maxScrollPosition;
  708. }
  709. /**
  710. * @private (setter)
  711. *
  712. * @langversion 3.0
  713. * @playerversion Flash 9.0.28.0
  714. */
  715. public function set maxScrollPosition(value:Number):void {
  716. // This uses setScrollProperties because it needs to update thumb and enabled.
  717. setScrollProperties(_pageSize,_minScrollPosition,value);
  718. }
  719. /**
  720. * Gets or sets the number of lines that a page contains. The <code>lineScrollSize</code>
  721. * is measured in increments between the <code>minScrollPosition</code> and
  722. * the <code>maxScrollPosition</code>. If this property is 0, the scroll bar
  723. * will not scroll.
  724. *
  725. * @default 10
  726. *
  727. * @see #maxScrollPosition
  728. * @see #minScrollPosition
  729. * @see #setScrollProperties()
  730. *
  731. * @langversion 3.0
  732. * @playerversion Flash 9.0.28.0
  733. *
  734. * @playerversion AIR 1.0
  735. * @productversion Flash CS3
  736. */
  737. public function get pageSize():Number {
  738. return _pageSize;
  739. }
  740. /**
  741. * @private (setter)
  742. *
  743. * @langversion 3.0
  744. * @playerversion Flash 9.0.28.0
  745. */
  746. public function set pageSize(value:Number):void {
  747. if (value > 0) {
  748. _pageSize = value;
  749. }
  750. }
  751. /**
  752. * Gets or sets a value that represents the increment by which the page is scrolled
  753. * when the scroll bar track is pressed. The <code>pageScrollSize</code> value is
  754. * measured in increments between the <code>minScrollPosition</code> and the
  755. * <code>maxScrollPosition</code> values. If this value is set to 0, the value of the
  756. * <code>pageSize</code> property is used.
  757. *
  758. * @default 0
  759. *
  760. * @see #maxScrollPosition
  761. * @see #minScrollPosition
  762. *
  763. * @langversion 3.0
  764. * @playerversion Flash 9.0.28.0
  765. *
  766. * @playerversion AIR 1.0
  767. * @productversion Flash CS3
  768. */
  769. public function get pageScrollSize():Number {
  770. return (_pageScrollSize == 0) ? _pageSize : _pageScrollSize;
  771. }
  772. /**
  773. * @private (setter)
  774. *
  775. * @langversion 3.0
  776. * @playerversion Flash 9.0.28.0
  777. */
  778. public function set pageScrollSize(value:Number):void {
  779. if (value>=0) { _pageScrollSize = value; }
  780. }
  781. /**
  782. * Gets or sets a value that represents the increment by which to scroll the page
  783. * when the scroll bar track is pressed. The <code>pageScrollSize</code> is measured
  784. * in increments between the <code>minScrollPosition</code> and the <code>maxScrollPosition</code>
  785. * values. If this value is set to 0, the value of the <code>pageSize</code> property is used.
  786. *
  787. * @default 0
  788. *
  789. * @see #maxScrollPosition
  790. * @see #minScrollPosition
  791. *
  792. * @langversion 3.0
  793. * @playerversion Flash 9.0.28.0
  794. *
  795. * @playerversion AIR 1.0
  796. * @productversion Flash CS3
  797. */
  798. public function get lineScrollSize():Number {
  799. return _lineScrollSize;
  800. }
  801. /**
  802. * @private (setter)
  803. *
  804. * @langversion 3.0
  805. * @playerversion Flash 9.0.28.0
  806. */
  807. public function set lineScrollSize(value:Number):void {
  808. if (value>0) {_lineScrollSize = value; }
  809. }
  810. /**
  811. * Gets or sets a value that indicates whether the scroll bar scrolls horizontally or vertically.
  812. * Valid values are <code>ScrollBarDirection.HORIZONTAL</code> and
  813. * <code>ScrollBarDirection.VERTICAL</code>.
  814. *
  815. * @default ScrollBarDirection.VERTICAL
  816. *
  817. * @see fl.controls.ScrollBarDirection ScrollBarDirection
  818. *
  819. * @langversion 3.0
  820. * @playerversion Flash 9.0.28.0
  821. *
  822. * @playerversion AIR 1.0
  823. * @productversion Flash CS3
  824. */
  825. public function get direction():String {
  826. return _direction;
  827. }
  828. /**
  829. * @private (setter)
  830. *
  831. * @langversion 3.0
  832. * @playerversion Flash 9.0.28.0
  833. */
  834. public function set direction(value:String):void {
  835. if (_direction == value) { return; }
  836. _direction = value;
  837. if (isLivePreview) { return; } // Rotation and scaling happens automatically in LivePreview.
  838. //
  839. setScaleY(1);
  840. var horizontal:Boolean = _direction == ScrollBarDirection.HORIZONTAL;
  841. if (horizontal && componentInspectorSetting) {
  842. if (rotation == 90 ) { return; }
  843. setScaleX(-1);
  844. rotation = -90;
  845. }
  846. if (!componentInspectorSetting) {
  847. if (horizontal && rotation == 0) {
  848. rotation = -90;
  849. setScaleX(-1);
  850. } else if (!horizontal && rotation == -90 ) {
  851. rotation = 0;
  852. setScaleX(1);
  853. }
  854. }
  855. invalidate(InvalidationType.SIZE);
  856. }
  857. /**
  858. * @private (protected)
  859. *
  860. * @langversion 3.0
  861. * @playerversion Flash 9.0.28.0
  862. */
  863. override protected function configUI():void {
  864. super.configUI();
  865. track = new BaseButton();
  866. track.move(0,14);
  867. track.useHandCursor = false;
  868. track.autoRepeat = true;
  869. track.focusEnabled = false;
  870. addChild(track);
  871. thumb = new LabelButton();
  872. thumb.label = "";
  873. thumb.setSize(WIDTH,15);
  874. thumb.move(0,15);
  875. thumb.focusEnabled = false;
  876. addChild(thumb);
  877. downArrow = new BaseButton();
  878. downArrow.setSize(WIDTH,14);
  879. downArrow.autoRepeat = true;
  880. downArrow.focusEnabled = false;
  881. addChild(downArrow);
  882. upArrow = new BaseButton();
  883. upArrow.setSize(WIDTH,14);
  884. upArrow.move(0,0);
  885. upArrow.autoRepeat = true;
  886. upArrow.focusEnabled = false;
  887. addChild(upArrow);
  888. upArrow.addEventListener(ComponentEvent.BUTTON_DOWN,scrollPressHandler,false,0,true);
  889. downArrow.addEventListener(ComponentEvent.BUTTON_DOWN,scrollPressHandler,false,0,true);
  890. track.addEventListener(ComponentEvent.BUTTON_DOWN,scrollPressHandler,false,0,true);
  891. thumb.addEventListener(MouseEvent.MOUSE_DOWN,thumbPressHandler,false,0,true);
  892. enabled = false;
  893. }
  894. /**
  895. * @private (protected)
  896. *
  897. * @langversion 3.0
  898. * @playerversion Flash 9.0.28.0
  899. */
  900. override protected function draw():void {
  901. if (isInvalid(InvalidationType.SIZE)) {
  902. var h:Number = super.height;
  903. downArrow.move(0, Math.max(upArrow.height, h-downArrow.height));
  904. track.setSize(WIDTH, Math.max(0, h-(downArrow.height + upArrow.height)));
  905. updateThumb();
  906. }
  907. if (isInvalid(InvalidationType.STYLES,InvalidationType.STATE)) {
  908. setStyles();
  909. }
  910. // Call drawNow on nested components to get around problems with nested render events:
  911. downArrow.drawNow();
  912. upArrow.drawNow();
  913. track.drawNow();
  914. thumb.drawNow();
  915. validate();
  916. }
  917. /**
  918. * @private (protected)
  919. *
  920. * @langversion 3.0
  921. * @playerversion Flash 9.0.28.0
  922. */
  923. protected function scrollPressHandler(event:ComponentEvent):void {
  924. event.stopImmediatePropagation();
  925. if (event.currentTarget == upArrow) {
  926. setScrollPosition(_scrollPosition-_lineScrollSize);
  927. } else if (event.currentTarget == downArrow) {
  928. setScrollPosition(_scrollPosition+_lineScrollSize);
  929. } else {
  930. var mousePosition:Number = (track.mouseY)/track.height * (_maxScrollPosition-_minScrollPosition) + _minScrollPosition;
  931. var pgScroll:Number = (pageScrollSize == 0)?pageSize:pageScrollSize;
  932. if (_scrollPosition < mousePosition) {
  933. setScrollPosition(Math.min(mousePosition,_scrollPosition+pgScroll));
  934. } else if (_scrollPosition > mousePosition) {
  935. setScrollPosition(Math.max(mousePosition,_scrollPosition-pgScroll));
  936. }
  937. }
  938. }
  939. /**
  940. * @private (protected)
  941. *
  942. * @langversion 3.0
  943. * @playerversion Flash 9.0.28.0
  944. */
  945. protected function thumbPressHandler(event:MouseEvent):void {
  946. inDrag = true;
  947. thumbScrollOffset = mouseY-thumb.y;
  948. thumb.mouseStateLocked = true;
  949. mouseChildren = false; // Should be able to do stage.mouseChildren, but doesn't seem to work.
  950. stage.addEventListener(MouseEvent.MOUSE_MOVE,handleThumbDrag,false,0,true);
  951. stage.addEventListener(MouseEvent.MOUSE_UP,thumbReleaseHandler,false,0,true);
  952. }
  953. /**
  954. * @private (protected)
  955. *
  956. * @langversion 3.0
  957. * @playerversion Flash 9.0.28.0
  958. */
  959. protected function handleThumbDrag(event:MouseEvent):void {
  960. var pos:Number = Math.max(0, Math.min(track.height-thumb.height, mouseY-track.y-thumbScrollOffset));
  961. setScrollPosition(pos/(track.height-thumb.height) * (_maxScrollPosition-_minScrollPosition) + _minScrollPosition);
  962. }
  963. /**
  964. * @private (protected)
  965. *
  966. * @langversion 3.0
  967. * @playerversion Flash 9.0.28.0
  968. */
  969. protected function thumbReleaseHandler(event:MouseEvent):void {
  970. inDrag = false;
  971. mouseChildren = true;
  972. thumb.mouseStateLocked = false;
  973. stage.removeEventListener(MouseEvent.MOUSE_MOVE,handleThumbDrag);
  974. stage.removeEventListener(MouseEvent.MOUSE_UP,thumbReleaseHandler);
  975. }
  976. /**
  977. * @private (protected)
  978. *
  979. * @langversion 3.0
  980. * @playerversion Flash 9.0.28.0
  981. */
  982. public function setScrollPosition(newScrollPosition:Number, fireEvent:Boolean=true):void {
  983. var oldPosition:Number = scrollPosition;
  984. _scrollPosition = Math.max(_minScrollPosition,Math.min(_maxScrollPosition, newScrollPosition));
  985. if (oldPosition == _scrollPosition) { return; }
  986. if (fireEvent) { dispatchEvent(new ScrollEvent(_direction, scrollPosition-oldPosition, scrollPosition)); }
  987. updateThumb();
  988. }
  989. /**
  990. * @private (protected)
  991. *
  992. * @langversion 3.0
  993. * @playerversion Flash 9.0.28.0
  994. */
  995. protected function setStyles():void {
  996. copyStylesToChild(downArrow,DOWN_ARROW_STYLES);
  997. copyStylesToChild(thumb,THUMB_STYLES);
  998. copyStylesToChild(track,TRACK_STYLES);
  999. copyStylesToChild(upArrow,UP_ARROW_STYLES);
  1000. }
  1001. /**
  1002. * @private
  1003. *
  1004. * @langversion 3.0
  1005. * @playerversion Flash 9.0.28.0
  1006. */
  1007. protected function updateThumb():void {
  1008. var per:Number = _maxScrollPosition - _minScrollPosition + _pageSize;
  1009. if (track.height <= 12 || _maxScrollPosition <= _minScrollPosition || (per == 0 || isNaN(per))) {
  1010. thumb.height = 12;
  1011. thumb.visible = false;
  1012. } else {
  1013. thumb.height = Math.max(13,_pageSize / per * track.height);
  1014. thumb.y = track.y+(track.height-thumb.height)*((_scrollPosition-_minScrollPosition)/(_maxScrollPosition-_minScrollPosition));
  1015. thumb.visible = enabled;
  1016. }
  1017. }
  1018. }
  1019. }