PageRenderTime 69ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/Sample/mx/core/Container.as

https://github.com/ingydotnet/yaml-oscon2009-talk
ActionScript | 5089 lines | 2288 code | 660 blank | 2141 comment | 481 complexity | a9c7096f43fa329625516aad147fd2fe MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2003-2007 Adobe Systems Incorporated
  5. // All Rights Reserved.
  6. //
  7. // NOTICE: Adobe permits you to use, modify, and distribute this file
  8. // in accordance with the terms of the license agreement accompanying it.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package mx.core
  12. {
  13. import flash.display.DisplayObject;
  14. import flash.display.DisplayObjectContainer;
  15. import flash.display.Graphics;
  16. import flash.display.InteractiveObject;
  17. import flash.display.Loader;
  18. import flash.display.Shape;
  19. import flash.display.Sprite;
  20. import flash.events.Event;
  21. import flash.events.KeyboardEvent;
  22. import flash.events.MouseEvent;
  23. import flash.geom.Point;
  24. import flash.geom.Rectangle;
  25. import flash.text.TextField;
  26. import flash.text.TextLineMetrics;
  27. import flash.ui.Keyboard;
  28. import flash.utils.getDefinitionByName;
  29. import mx.binding.BindingManager;
  30. import mx.controls.Button;
  31. import mx.controls.HScrollBar;
  32. import mx.controls.VScrollBar;
  33. import mx.controls.listClasses.IListItemRenderer;
  34. import mx.controls.scrollClasses.ScrollBar;
  35. import mx.events.ChildExistenceChangedEvent;
  36. import mx.events.FlexEvent;
  37. import mx.events.IndexChangedEvent;
  38. import mx.events.ScrollEvent;
  39. import mx.events.ScrollEventDetail;
  40. import mx.events.ScrollEventDirection;
  41. import mx.graphics.RoundedRectangle;
  42. import mx.managers.IFocusManager;
  43. import mx.managers.IFocusManagerContainer;
  44. import mx.managers.ILayoutManagerClient;
  45. import mx.managers.ISystemManager;
  46. import mx.styles.CSSStyleDeclaration;
  47. import mx.styles.ISimpleStyleClient;
  48. import mx.styles.IStyleClient;
  49. import mx.styles.StyleManager;
  50. import mx.styles.StyleProtoChain;
  51. use namespace mx_internal;
  52. //--------------------------------------
  53. // Events
  54. //--------------------------------------
  55. /**
  56. * Dispatched after a child has been added to a container.
  57. *
  58. * <p>The childAdd event is dispatched when the <code>addChild()</code>
  59. * or <code>addChildAt()</code> method is called.
  60. * When a container is first created, the <code>addChild()</code>
  61. * method is automatically called for each child component declared
  62. * in the MXML file.
  63. * The <code>addChildAt()</code> method is automatically called
  64. * whenever a Repeater object adds or removes child objects.
  65. * The application developer may also manually call these
  66. * methods to add new children.</p>
  67. *
  68. * <p>At the time when this event is sent, the child object has been
  69. * initialized, but its width and height have not yet been calculated,
  70. * and the child has not been drawn on the screen.
  71. * If you want to be notified when the child has been fully initialized
  72. * and rendered, then register as a listener for the child's
  73. * <code>creationComplete</code> event.</p>
  74. *
  75. * @eventType mx.events.ChildExistenceChangedEvent.CHILD_ADD
  76. */
  77. [Event(name="childAdd", type="mx.events.ChildExistenceChangedEvent")]
  78. /**
  79. * Dispatched after the index (among the container children)
  80. * of a container child changes.
  81. * This event is only dispatched for the child specified as the argument to
  82. * the <code>setChildIndex()</code> method; it is not dispatched
  83. * for any other child whose index changes as a side effect of the call
  84. * to the <code>setChildIndex()</code> method.
  85. *
  86. * <p>The child's index is changed when the
  87. * <code>setChildIndex()</code> method is called.</p>
  88. *
  89. * @eventType mx.events.IndexChangedEvent.CHILD_INDEX_CHANGE
  90. */
  91. [Event(name="childIndexChange", type="mx.events.IndexChangedEvent")]
  92. /**
  93. * Dispatched before a child of a container is removed.
  94. *
  95. * <p>This event is delivered when any of the following methods is called:
  96. * <code>removeChild()</code>, <code>removeChildAt()</code>,
  97. * or <code>removeAllChildren()</code>.</p>
  98. *
  99. * @eventType mx.events.ChildExistenceChangedEvent.CHILD_REMOVE
  100. */
  101. [Event(name="childRemove", type="mx.events.ChildExistenceChangedEvent")]
  102. /**
  103. * Dispatched when the <code>data</code> property changes.
  104. *
  105. * <p>When a container is used as a renderer in a List or other components,
  106. * the <code>data</code> property is used pass to the container
  107. * the data to display.</p>
  108. *
  109. * @eventType mx.events.FlexEvent.DATA_CHANGE
  110. */
  111. [Event(name="dataChange", type="mx.events.FlexEvent")]
  112. /**
  113. * Dispatched when the user manually scrolls the container.
  114. *
  115. * <p>The event is dispatched when the scroll position is changed using
  116. * either the mouse (e.g. clicking on the scrollbar's "down" button)
  117. * or the keyboard (e.g., clicking on the down-arrow key).
  118. * However, this event is not dispatched if the scroll position
  119. * is changed programatically (e.g., setting the value of the
  120. * <code>horizontalScrollPosition</code> property).
  121. * The <code>viewChanged</code> event is delivered whenever the
  122. * scroll position is changed, either manually or programatically.</p>
  123. *
  124. * <p>At the time when this event is dispatched, the scrollbar has
  125. * been updated to the new position, but the container's child objects
  126. * have not been shifted to reflect the new scroll position.</p>
  127. *
  128. * @eventType mx.events.ScrollEvent.SCROLL
  129. */
  130. [Event(name="scroll", type="mx.events.ScrollEvent")]
  131. //--------------------------------------
  132. // Styles
  133. //--------------------------------------
  134. include "../styles/metadata/BarColorStyle.as"
  135. include "../styles/metadata/BorderStyles.as"
  136. include "../styles/metadata/PaddingStyles.as"
  137. include "../styles/metadata/TextStyles.as"
  138. /**
  139. * If a background image is specified, this style specifies
  140. * whether it is fixed with regard to the viewport (<code>"fixed"</code>)
  141. * or scrolls along with the content (<code>"scroll"</code>).
  142. *
  143. * @default "scroll"
  144. */
  145. [Style(name="backgroundAttachment", type="String", inherit="no")]
  146. /**
  147. * The alpha value for the overlay that is placed on top of the
  148. * container when it is disabled.
  149. */
  150. [Style(name="disabledOverlayAlpha", type="Number", inherit="no")]
  151. /**
  152. * The name of the horizontal scrollbar style.
  153. *
  154. * @default undefined
  155. */
  156. [Style(name="horizontalScrollBarStyleName", type="String", inherit="no")]
  157. /**
  158. * The name of the vertical scrollbar style.
  159. *
  160. * @default undefined
  161. */
  162. [Style(name="verticalScrollBarStyleName", type="String", inherit="no")]
  163. /**
  164. * Number of pixels between the container's bottom border
  165. * and the bottom of its content area.
  166. *
  167. * @default 0
  168. */
  169. [Style(name="paddingBottom", type="Number", format="Length", inherit="no")]
  170. /**
  171. * Number of pixels between the container's top border
  172. * and the top of its content area.
  173. *
  174. * @default 0
  175. */
  176. [Style(name="paddingTop", type="Number", format="Length", inherit="no")]
  177. [ResourceBundle("core")]
  178. /**
  179. * The Container class is an abstract base class for components that
  180. * controls the layout characteristics of child components.
  181. * You do not create an instance of Container in an application.
  182. * Instead, you create an instance of one of Container's subclasses,
  183. * such as Canvas or HBox.
  184. *
  185. * <p>The Container class contains the logic for scrolling, clipping,
  186. * and dynamic instantiation.
  187. * It contains methods for adding and removing children.
  188. * It also contains the <code>getChildAt()</code> method, and the logic
  189. * for drawing the background and borders of containers.</p>
  190. *
  191. * @mxml
  192. *
  193. * Flex Framework containers inherit the following attributes from the Container
  194. * class:</p>
  195. *
  196. * <pre>
  197. * &lt;mx:<i>tagname</i>
  198. * <strong>Properties</strong>
  199. * autoLayout="true|false"
  200. * clipContent="true|false"
  201. * creationIndex="undefined"
  202. * creationPolicy="auto|all|queued|none"
  203. * defaultButton="<i>No default</i>"
  204. * horizontalLineScrollSize="5"
  205. * horizontalPageScrollSize="0"
  206. * horizontalScrollBar="null"
  207. * horizontalScrollPolicy="auto|on|off"
  208. * horizontalScrollPosition="0"
  209. * icon="undefined"
  210. * label=""
  211. * verticalLineScrollSize="5"
  212. * verticalPageScrollSize="0"
  213. * verticalScrollBar="null"
  214. * verticalScrollPolicy="auto|on|off"
  215. * verticalScrollPosition="0"
  216. *
  217. * <strong>Styles</strong>
  218. * backgroundAlpha="1.0"
  219. * backgroundAttachment="scroll"
  220. * backgroundColor="undefined"
  221. * backgroundDisabledColor="undefined"
  222. * backgroundImage="undefined"
  223. * backgroundSize="auto"
  224. * <i> For the Application container only,</i> backgroundSize="100%"
  225. * barColor="undefined"
  226. * borderColor="0xAAB3B3"
  227. * borderSides="left top right bottom"
  228. * borderSkin="mx.skins.halo.HaloBorder"
  229. * borderStyle="inset"
  230. * borderThickness="1"
  231. * color="0x0B333C"
  232. * cornerRadius="0"
  233. * disabledColor="0xAAB3B3"
  234. * disbledOverlayAlpha="undefined"
  235. * dropShadowColor="0x000000"
  236. * dropShadowEnabled="false"
  237. * fontAntiAliasType="advanced"
  238. * fontfamily="Verdana"
  239. * fontGridFitType="pixel"
  240. * fontSharpness="0""
  241. * fontSize="10"
  242. * fontStyle="normal"
  243. * fontThickness="0"
  244. * fontWeight="normal"
  245. * horizontalScrollBarStyleName="undefined"
  246. * paddingBottom="0"
  247. * paddingLeft="0"
  248. * paddingRight="0"
  249. * paddingTop="0"
  250. * shadowDirection="center"
  251. * shadowDistance="2"
  252. * textAlign="left"
  253. * textDecoration="none|underline"
  254. * textIndent="0"
  255. * verticalScrollBarStyleName="undefined"
  256. *
  257. * <strong>Events</strong>
  258. * childAdd="<i>No default</i>"
  259. * childIndexChange="<i>No default</i>"
  260. * childRemove="<i>No default</i>"
  261. * dataChange="<i>No default</i>"
  262. * scroll="<i>No default</i>"
  263. * &gt;
  264. * ...
  265. * <i>child tags</i>
  266. * ...
  267. * &lt;/mx:<i>tagname</i>&gt;
  268. * </pre>
  269. */
  270. public class Container extends UIComponent
  271. implements IContainer, IDataRenderer,
  272. IFocusManagerContainer, IListItemRenderer,
  273. IRawChildrenContainer
  274. {
  275. include "../core/Version.as"
  276. //--------------------------------------------------------------------------
  277. //
  278. // Notes: Child management
  279. //
  280. //--------------------------------------------------------------------------
  281. /*
  282. Although at the level of a Flash DisplayObjectContainer, all
  283. children are equal, in a Flex Container some children are "more
  284. equal than others". (George Orwell, "Animal Farm")
  285. In particular, Flex distinguishes between content children and
  286. non-content (or "chrome") children. Content children are the kind
  287. that can be specified in MXML. If you put several controls
  288. into a VBox, those are its content children. Non-content children
  289. are the other ones that you get automatically, such as a
  290. background/border, scrollbars, the titlebar of a Panel,
  291. AccordionHeaders, etc.
  292. Most application developers are uninterested in non-content children,
  293. so Container overrides APIs such as numChildren and getChildAt()
  294. to deal only with content children. For example, Container, keeps
  295. its own _numChildren counter.
  296. Container assumes that content children are contiguous, and that
  297. non-content children come before or after the content children.
  298. In order words, Container partitions DisplayObjectContainer's
  299. index range into three parts:
  300. A B C D E F G H I
  301. 0 1 2 3 4 5 6 7 8 <- index for all children
  302. 0 1 2 3 <- index for content children
  303. The content partition contains the content children D E F G.
  304. The pre-content partition contains the non-content children
  305. A B C that always stay before the content children.
  306. The post-content partition contains the non-content children
  307. H I that always stay after the content children.
  308. Container maintains two state variables, _firstChildIndex
  309. and _numChildren, which keep track of the partitioning.
  310. In this example, _firstChildIndex would be 3 and _numChildren
  311. would be 4.
  312. */
  313. //--------------------------------------------------------------------------
  314. //
  315. // Class constants
  316. //
  317. //--------------------------------------------------------------------------
  318. /**
  319. * @private
  320. * See changedStyles, below
  321. */
  322. private static const MULTIPLE_PROPERTIES:String = "<MULTIPLE>";
  323. //--------------------------------------------------------------------------
  324. //
  325. // Class methods
  326. //
  327. //--------------------------------------------------------------------------
  328. //--------------------------------------------------------------------------
  329. //
  330. // Constructor
  331. //
  332. //--------------------------------------------------------------------------
  333. /**
  334. * Constructor.
  335. */
  336. public function Container()
  337. {
  338. super();
  339. // By default, containers cannot receive focus but their children can.
  340. tabChildren = true;
  341. tabEnabled = false;
  342. showInAutomationHierarchy = false;
  343. }
  344. //--------------------------------------------------------------------------
  345. //
  346. // Variables
  347. //
  348. //--------------------------------------------------------------------------
  349. //----------------------------------
  350. // Child creation vars
  351. //----------------------------------
  352. /**
  353. * The creation policy of this container.
  354. * This property is useful when the container inherits its creation policy
  355. * from its parent container.
  356. */
  357. protected var actualCreationPolicy:String;
  358. /**
  359. * @private
  360. */
  361. private var numChildrenBefore:int;
  362. /**
  363. * @private
  364. */
  365. private var recursionFlag:Boolean = true;
  366. //----------------------------------
  367. // Layout vars
  368. //----------------------------------
  369. /**
  370. * @private
  371. * Remember when a child has been added or removed.
  372. * When that occurs, we want to run the LayoutManager
  373. * (even if autoLayout is false).
  374. */
  375. private var forceLayout:Boolean = false;
  376. /**
  377. * @private
  378. */
  379. mx_internal var doingLayout:Boolean = false;
  380. //----------------------------------
  381. // Style vars
  382. //----------------------------------
  383. /**
  384. * @private
  385. * If this value is non-null, then we need to recursively notify children
  386. * that a style property has changed. If one style property has changed,
  387. * this field holds the name of the style that changed. If multiple style
  388. * properties have changed, then the value of this field is
  389. * Container.MULTIPLE_PROPERTIES.
  390. */
  391. private var changedStyles:String = null;
  392. //----------------------------------
  393. // Scrolling vars
  394. //----------------------------------
  395. /**
  396. * @private
  397. */
  398. private var _creatingContentPane:Boolean = false;
  399. /**
  400. * Containers use an internal content pane to control scrolling.
  401. * The <code>creatingContentPane</code> is <code>true</code> while the container is creating
  402. * the content pane so that some events can be ignored or blocked.
  403. */
  404. public function get creatingContentPane():Boolean
  405. {
  406. return _creatingContentPane;
  407. }
  408. public function set creatingContentPane(value:Boolean):void
  409. {
  410. _creatingContentPane = value;
  411. }
  412. /**
  413. * @private
  414. * A box that takes up space in the lower right corner,
  415. * between the horizontal and vertical scrollbars.
  416. */
  417. protected var whiteBox:Shape;
  418. /**
  419. * @private
  420. */
  421. mx_internal var contentPane:Sprite = null;
  422. /**
  423. * @private
  424. * Flags that remember what work to do during the next updateDisplayList().
  425. */
  426. private var scrollPropertiesChanged:Boolean = false;
  427. private var scrollPositionChanged:Boolean = true;
  428. private var horizontalScrollPositionPending:Number;
  429. private var verticalScrollPositionPending:Number;
  430. /**
  431. * @private
  432. * Cached values describing the total size of the content being scrolled
  433. * and the size of the area in which the scrolled content is displayed.
  434. */
  435. private var scrollableWidth:Number = 0;
  436. private var scrollableHeight:Number = 0;
  437. private var viewableWidth:Number = 0;
  438. private var viewableHeight:Number = 0;
  439. //----------------------------------
  440. // Other vars
  441. //----------------------------------
  442. /**
  443. * @private
  444. * The border/background object.
  445. */
  446. mx_internal var border:IFlexDisplayObject;
  447. /**
  448. * @private
  449. * Sprite used to block user input when the container is disabled.
  450. */
  451. mx_internal var blocker:Sprite;
  452. /**
  453. * @private
  454. * Keeps track of the number of mouse events we are listening for
  455. */
  456. private var mouseEventReferenceCount:int = 0;
  457. //--------------------------------------------------------------------------
  458. //
  459. // Overridden properties
  460. //
  461. //--------------------------------------------------------------------------
  462. //----------------------------------
  463. // baselinePosition
  464. //----------------------------------
  465. /**
  466. * @private
  467. * The baselinePosition of a Container is calculated
  468. * as if there was a UITextField using the Container's styles
  469. * whose top is at viewMetrics.top.
  470. */
  471. override public function get baselinePosition():Number
  472. {
  473. if (FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  474. {
  475. // If we have a verticalAlignment of top,
  476. // then return the baseline of our first child
  477. if (getStyle("verticalAlign") == "top" && numChildren > 0)
  478. {
  479. var child:IUIComponent = getChildAt(0) as IUIComponent;
  480. if (child)
  481. return child.y + child.baselinePosition;
  482. }
  483. return super.baselinePosition;
  484. }
  485. if (!validateBaselinePosition())
  486. return NaN;
  487. // Unless the height is very small, the baselinePosition
  488. // of a generic Container is calculated as if there was
  489. // a UITextField using the Container's styles
  490. // whose top is at viewMetrics.top.
  491. // If the height is small, the baselinePosition is calculated
  492. // as if there were text within whose ascent the Container
  493. // is vertically centered.
  494. // At the crossover height, these two calculations
  495. // produce the same result.
  496. var lineMetrics:TextLineMetrics = measureText("Wj");
  497. if (height < 2 * viewMetrics.top + 4 + lineMetrics.ascent)
  498. return int(height + (lineMetrics.ascent - height) / 2);
  499. return viewMetrics.top + 2 + lineMetrics.ascent;
  500. }
  501. //----------------------------------
  502. // contentMouseX
  503. //----------------------------------
  504. /**
  505. * @copy mx.core.UIComponent#contentMouseX
  506. */
  507. override public function get contentMouseX():Number
  508. {
  509. if (contentPane)
  510. return contentPane.mouseX;
  511. return super.contentMouseX;
  512. }
  513. //----------------------------------
  514. // contentMouseY
  515. //----------------------------------
  516. /**
  517. * @copy mx.core.UIComponent#contentMouseY
  518. */
  519. override public function get contentMouseY():Number
  520. {
  521. if (contentPane)
  522. return contentPane.mouseY;
  523. return super.contentMouseY;
  524. }
  525. //----------------------------------
  526. // doubleClickEnabled
  527. //----------------------------------
  528. /**
  529. * @private
  530. * Propagate to children.
  531. */
  532. override public function set doubleClickEnabled(value:Boolean):void
  533. {
  534. super.doubleClickEnabled = value;
  535. if (contentPane)
  536. {
  537. var n:int = contentPane.numChildren;
  538. for (var i:int = 0; i < n; i++)
  539. {
  540. var child:InteractiveObject =
  541. contentPane.getChildAt(i) as InteractiveObject;
  542. if (child)
  543. child.doubleClickEnabled = value;
  544. }
  545. }
  546. }
  547. //----------------------------------
  548. // enabled
  549. //----------------------------------
  550. [Inspectable(category="General", enumeration="true,false", defaultValue="true")]
  551. /**
  552. * @private
  553. */
  554. override public function set enabled(value:Boolean):void
  555. {
  556. super.enabled = value;
  557. // Scrollbars must be enabled/disabled when this container is.
  558. if (horizontalScrollBar)
  559. horizontalScrollBar.enabled = value;
  560. if (verticalScrollBar)
  561. verticalScrollBar.enabled = value;
  562. invalidateProperties();
  563. }
  564. //----------------------------------
  565. // focusPane
  566. //----------------------------------
  567. /**
  568. * @private
  569. * Storage for the focusPane property.
  570. */
  571. private var _focusPane:Sprite;
  572. /**
  573. * @private
  574. * Focus pane associated with this object.
  575. * An object has a focus pane when one of its children has got focus.
  576. */
  577. override public function get focusPane():Sprite
  578. {
  579. return _focusPane;
  580. }
  581. /**
  582. * @private
  583. */
  584. override public function set focusPane(o:Sprite):void
  585. {
  586. // The addition or removal of the focus sprite should not trigger
  587. // a measurement/layout pass. Temporarily set the invalidation flags,
  588. // so that calls to invalidateSize() and invalidateDisplayList() have
  589. // no effect.
  590. var oldInvalidateSizeFlag:Boolean = invalidateSizeFlag;
  591. var oldInvalidateDisplayListFlag:Boolean = invalidateDisplayListFlag;
  592. invalidateSizeFlag = true;
  593. invalidateDisplayListFlag = true;
  594. if (o)
  595. {
  596. rawChildren.addChild(o);
  597. o.x = 0;
  598. o.y = 0;
  599. o.scrollRect = null;
  600. _focusPane = o;
  601. }
  602. else
  603. {
  604. rawChildren.removeChild(_focusPane);
  605. _focusPane = null;
  606. }
  607. if (o && contentPane)
  608. {
  609. o.x = contentPane.x;
  610. o.y = contentPane.y;
  611. o.scrollRect = contentPane.scrollRect;
  612. }
  613. invalidateSizeFlag = oldInvalidateSizeFlag;
  614. invalidateDisplayListFlag = oldInvalidateDisplayListFlag;
  615. }
  616. //----------------------------------
  617. // $numChildren
  618. //----------------------------------
  619. /**
  620. * @private
  621. * This property allows access to the Player's native implementation
  622. * of the numChildren property, which can be useful since components
  623. * can override numChildren and thereby hide the native implementation.
  624. * Note that this "base property" is final and cannot be overridden,
  625. * so you can count on it to reflect what is happening at the player level.
  626. */
  627. mx_internal final function get $numChildren():int
  628. {
  629. return super.numChildren;
  630. }
  631. //----------------------------------
  632. // numChildren
  633. //----------------------------------
  634. /**
  635. * @private
  636. * Storage for the numChildren property.
  637. */
  638. mx_internal var _numChildren:int = 0;
  639. /**
  640. * Number of child components in this container.
  641. *
  642. * <p>The number of children is initially equal
  643. * to the number of children declared in MXML.
  644. * At runtime, new children may be added by calling
  645. * <code>addChild()</code> or <code>addChildAt()</code>,
  646. * and existing children may be removed by calling
  647. * <code>removeChild()</code>, <code>removeChildAt()</code>,
  648. * or <code>removeAllChildren()</code>.</p>
  649. */
  650. override public function get numChildren():int
  651. {
  652. return contentPane ? contentPane.numChildren : _numChildren;
  653. }
  654. //--------------------------------------------------------------------------
  655. //
  656. // Properties
  657. //
  658. //--------------------------------------------------------------------------
  659. //----------------------------------
  660. // autoLayout
  661. //----------------------------------
  662. /**
  663. * @private
  664. * Storage for the autoLayout property.
  665. */
  666. private var _autoLayout:Boolean = true;
  667. [Inspectable(defaultValue="true")]
  668. /**
  669. * If <code>true</code>, measurement and layout are done
  670. * when the position or size of a child is changed.
  671. * If <code>false</code>, measurement and layout are done only once,
  672. * when children are added to or removed from the container.
  673. *
  674. * <p>When using the Move effect, the layout around the component that
  675. * is moving does not readjust to fit that the Move effect animates.
  676. * Setting a container's <code>autoLayout</code> property to
  677. * <code>true</code> has no effect on this behavior.</p>
  678. *
  679. * <p>The Zoom effect does not work when the <code>autoLayout</code>
  680. * property is <code>false</code>.</p>
  681. *
  682. * <p>The <code>autoLayout</code> property does not apply to
  683. * Accordion or ViewStack containers.</p>
  684. *
  685. * @default true
  686. */
  687. public function get autoLayout():Boolean
  688. {
  689. return _autoLayout;
  690. }
  691. /**
  692. * @private
  693. */
  694. public function set autoLayout(value:Boolean):void
  695. {
  696. _autoLayout = value;
  697. // If layout is being turned back on, trigger a layout to occur now.
  698. if (value)
  699. {
  700. invalidateSize();
  701. invalidateDisplayList();
  702. var p:IInvalidating = parent as IInvalidating;
  703. if (p)
  704. {
  705. p.invalidateSize();
  706. p.invalidateDisplayList();
  707. }
  708. }
  709. }
  710. //----------------------------------
  711. // borderMetrics
  712. //----------------------------------
  713. /**
  714. * Returns an EdgeMetrics object that has four properties:
  715. * <code>left</code>, <code>top</code>, <code>right</code>,
  716. * and <code>bottom</code>.
  717. * The value of each property is equal to the thickness of one side
  718. * of the border, expressed in pixels.
  719. *
  720. * <p>Unlike <code>viewMetrics</code>, this property is not
  721. * overriden by subclasses of Container.</p>
  722. */
  723. public function get borderMetrics():EdgeMetrics
  724. {
  725. return border && border is IRectangularBorder ?
  726. IRectangularBorder(border).borderMetrics :
  727. EdgeMetrics.EMPTY;
  728. }
  729. //----------------------------------
  730. // childDescriptors
  731. //----------------------------------
  732. /**
  733. * @private
  734. * Storage for the childDescriptors property.
  735. * This variable is initialized in the construct() method
  736. * using the childDescriptors in the initObj, which is autogenerated.
  737. * If this Container was not created by createComponentFromDescriptor(),
  738. * its childDescriptors property is null.
  739. */
  740. private var _childDescriptors:Array /* of UIComponentDescriptor */;
  741. /**
  742. * Array of UIComponentDescriptor objects produced by the MXML compiler.
  743. *
  744. * <p>Each UIComponentDescriptor object contains the information
  745. * specified in one child MXML tag of the container's MXML tag.
  746. * The order of the UIComponentDescriptor objects in the Array
  747. * is the same as the order of the child tags.
  748. * During initialization, the child descriptors are used to create
  749. * the container's child UIComponent objects and its Repeater objects,
  750. * and to give them the initial property values, event handlers, effects,
  751. * and so on, that were specified in MXML.</p>
  752. *
  753. * @see mx.core.UIComponentDescriptor
  754. */
  755. public function get childDescriptors():Array /* of UIComponentDescriptor */
  756. {
  757. return _childDescriptors;
  758. }
  759. //----------------------------------
  760. // childRepeaters
  761. //----------------------------------
  762. /**
  763. * @private
  764. * Storage for the childRepeaters property.
  765. */
  766. private var _childRepeaters:Array;
  767. /**
  768. * @private
  769. * An array of the Repeater objects found within this container.
  770. */
  771. mx_internal function get childRepeaters():Array
  772. {
  773. return _childRepeaters;
  774. }
  775. /**
  776. * @private
  777. */
  778. mx_internal function set childRepeaters(value:Array):void
  779. {
  780. _childRepeaters = value;
  781. }
  782. //----------------------------------
  783. // clipContent
  784. //----------------------------------
  785. /**
  786. * @private
  787. * Storage for the clipContent property.
  788. */
  789. private var _clipContent:Boolean = true;
  790. [Inspectable(defaultValue="true")]
  791. /**
  792. * Whether to apply a clip mask if the positions and/or sizes
  793. * of this container's children extend outside the borders of
  794. * this container.
  795. * If <code>false</code>, the children of this container
  796. * remain visible when they are moved or sized outside the
  797. * borders of this container.
  798. * If <code>true</code>, the children of this container are clipped.
  799. *
  800. * <p>If <code>clipContent</code> is <code>false</code>, then scrolling
  801. * is disabled for this container and scrollbars will not appear.
  802. * If <code>clipContent</code> is true, then scrollbars will usually
  803. * appear when the container's children extend outside the border of
  804. * the container.
  805. * For additional control over the appearance of scrollbars,
  806. * see <code>horizontalScrollPolicy</code> and <code>verticalScrollPolicy</code>.</p>
  807. *
  808. * @default true
  809. */
  810. public function get clipContent():Boolean
  811. {
  812. return _clipContent;
  813. }
  814. /**
  815. * @private
  816. */
  817. public function set clipContent(value:Boolean):void
  818. {
  819. if (_clipContent != value)
  820. {
  821. _clipContent = value;
  822. invalidateDisplayList();
  823. }
  824. }
  825. //----------------------------------
  826. // createdComponents
  827. //----------------------------------
  828. /**
  829. * @private
  830. * Internal variable used to keep track of the components created
  831. * by this Container. This is different than the list maintained
  832. * by DisplayObjectContainer, because it includes Repeaters.
  833. */
  834. private var _createdComponents:Array;
  835. /**
  836. * @private
  837. * An array of all components created by this container including
  838. * Repeater components.
  839. */
  840. mx_internal function get createdComponents():Array
  841. {
  842. return _createdComponents;
  843. }
  844. /**
  845. * @private
  846. */
  847. mx_internal function set createdComponents(value:Array):void
  848. {
  849. _createdComponents = value;
  850. }
  851. //----------------------------------
  852. // creationIndex
  853. //----------------------------------
  854. /**
  855. * @private
  856. * Storage for the creationIndex property.
  857. */
  858. private var _creationIndex:int = -1;
  859. [Inspectable(defaultValue="undefined")]
  860. /**
  861. * Specifies the order to instantiate and draw the children
  862. * of the container.
  863. *
  864. * <p>This property can only be used when the <code>creationPolicy</code>
  865. * property is set to <code>ContainerCreationPolicy.QUEUED</code>.
  866. * Otherwise, it is ignored.</p>
  867. *
  868. * @default -1
  869. */
  870. public function get creationIndex():int
  871. {
  872. return _creationIndex;
  873. }
  874. /**
  875. * @private
  876. */
  877. public function set creationIndex(value:int):void
  878. {
  879. _creationIndex = value;
  880. }
  881. //----------------------------------
  882. // creationPolicy
  883. //----------------------------------
  884. /**
  885. * @private
  886. * Storage for the creationPolicy property.
  887. * This variable is initialized in the construct() method
  888. * using the childDescriptors in the initObj, which is autogenerated.
  889. * If this Container was not created by createComponentFromDescriptor(),
  890. * its childDescriptors property is null.
  891. */
  892. private var _creationPolicy:String;
  893. [Inspectable(enumeration="all,auto,queued,none")]
  894. /**
  895. * The child creation policy for this Container.
  896. * ActionScript values can be <code>ContainerCreationPolicy.AUTO</code>,
  897. * <code>ContainerCreationPolicy.ALL</code>,
  898. * <code>ContainerCreationPolicy.NONE</code>,
  899. * or <code>ContainerCreationPolicy.QUEUED</code>.
  900. * MXML values can be <code>"auto"</code>, <code>"all"</code>,
  901. * <code>"none"</code>, or <code>"queued"</code>.
  902. *
  903. * <p>If no <code>creationPolicy</code> is specified for a container,
  904. * that container inherits its parent's <code>creationPolicy</code>.
  905. * If no <code>creationPolicy</code> is specified for the Application,
  906. * it defaults to <code>ContainerCreationPolicy.AUTO</code>.</p>
  907. *
  908. * <p>A <code>creationPolicy</code> of <code>ContainerCreationPolicy.AUTO</code> means
  909. * that the container delays creating some or all descendants
  910. * until they are needed, a process which is known as <i>deferred
  911. * instantiation</i>.
  912. * This policy produces the best startup time because fewer
  913. * UIComponents are created initially.
  914. * However, this introduces navigation delays when a user navigates
  915. * to other parts of the application for the first time.
  916. * Navigator containers such as Accordion, TabNavigator, and ViewStack
  917. * implement the <code>ContainerCreationPolicy.AUTO</code> policy by creating all their
  918. * children immediately, but wait to create the deeper descendants
  919. * of a child until it becomes the selected child of the navigator
  920. * container.</p>
  921. *
  922. * <p>A <code>creationPolicy</code> of <code>ContainerCreationPolicy.ALL</code> means
  923. * that the navigator containers immediately create deeper descendants
  924. * for each child, rather than waiting until that child is
  925. * selected. For single-view containers such as a VBox container,
  926. * there is no difference between the <code>ContainerCreationPolicy.AUTO</code> and
  927. * <code>ContainerCreationPolicy.ALL</code> policies.</p>
  928. *
  929. * <p>A <code>creationPolicy</code> of <code>ContainerCreationPolicy.QUEUED</code> means
  930. * that the container is added to a creation queue rather than being
  931. * immediately instantiated and drawn.
  932. * When the application processes the queued container, it creates
  933. * the children of the container and then waits until the children
  934. * have been created before advancing to the next container in the
  935. * creation queue.</p>
  936. *
  937. * <p>A <code>creationPolicy</code> of <code>ContainerCreationPolicy.NONE</code> means
  938. * that the container creates none of its children.
  939. * In that case, it is the responsibility of the MXML author
  940. * to create the children by calling the
  941. * <code>createComponentsFromDescriptors()</code> method.</p>
  942. */
  943. public function get creationPolicy():String
  944. {
  945. return _creationPolicy;
  946. }
  947. /**
  948. * @private
  949. */
  950. public function set creationPolicy(value:String):void
  951. {
  952. _creationPolicy = value;
  953. setActualCreationPolicies(value);
  954. }
  955. //----------------------------------
  956. // defaultButton
  957. //----------------------------------
  958. /**
  959. * @private
  960. * Storage for the defaultButton property.
  961. */
  962. private var _defaultButton:IFlexDisplayObject;
  963. [Inspectable(category="General")]
  964. /**
  965. * The Button control designated as the default button
  966. * for the container.
  967. * When controls in the container have focus, pressing the
  968. * Enter key is the same as clicking this Button control.
  969. *
  970. * @default null
  971. */
  972. public function get defaultButton():IFlexDisplayObject
  973. {
  974. return _defaultButton;
  975. }
  976. /**
  977. * @private
  978. */
  979. public function set defaultButton(value:IFlexDisplayObject):void
  980. {
  981. _defaultButton = value;
  982. ContainerGlobals.focusedContainer = null;
  983. }
  984. //----------------------------------
  985. // data
  986. //----------------------------------
  987. /**
  988. * @private
  989. * Storage for the data property.
  990. */
  991. private var _data:Object;
  992. [Bindable("dataChange")]
  993. [Inspectable(environment="none")]
  994. /**
  995. * The <code>data</code> property lets you pass a value
  996. * to the component when you use it in an item renderer or item editor.
  997. * You typically use data binding to bind a field of the <code>data</code>
  998. * property to a property of this component.
  999. *
  1000. * <p>You do not set this property in MXML.</p>
  1001. *
  1002. * @default null
  1003. * @see mx.core.IDataRenderer
  1004. */
  1005. public function get data():Object
  1006. {
  1007. return _data;
  1008. }
  1009. /**
  1010. * @private
  1011. */
  1012. public function set data(value:Object):void
  1013. {
  1014. _data = value;
  1015. dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
  1016. invalidateDisplayList();
  1017. }
  1018. //----------------------------------
  1019. // firstChildIndex
  1020. //----------------------------------
  1021. /**
  1022. * @private
  1023. * Storage for the firstChildIndex property.
  1024. */
  1025. private var _firstChildIndex:int = 0;
  1026. /**
  1027. * @private
  1028. * The index of the first content child,
  1029. * when dealing with both content and non-content children.
  1030. */
  1031. mx_internal function get firstChildIndex():int
  1032. {
  1033. return _firstChildIndex;
  1034. }
  1035. //----------------------------------
  1036. // horizontalLineScrollSize
  1037. //----------------------------------
  1038. /**
  1039. * @private
  1040. * Storage for the horizontalLineScrollSize property.
  1041. */
  1042. private var _horizontalLineScrollSize:Number = 5;
  1043. [Bindable("horizontalLineScrollSizeChanged")]
  1044. [Inspectable(defaultValue="5")]
  1045. /**
  1046. * Number of pixels to move when the left- or right-arrow
  1047. * button in the horizontal scroll bar is pressed.
  1048. *
  1049. * @default 5
  1050. */
  1051. public function get horizontalLineScrollSize():Number
  1052. {
  1053. return _horizontalLineScrollSize;
  1054. }
  1055. /**
  1056. * @private
  1057. */
  1058. public function set horizontalLineScrollSize(value:Number):void
  1059. {
  1060. scrollPropertiesChanged = true;
  1061. _horizontalLineScrollSize = value;
  1062. invalidateDisplayList();
  1063. dispatchEvent(new Event("horizontalLineScrollSizeChanged"));
  1064. }
  1065. //----------------------------------
  1066. // horizontalPageScrollSize
  1067. //----------------------------------
  1068. /**
  1069. * @private
  1070. * Storage for the horizontalPageScrollSize property.
  1071. */
  1072. private var _horizontalPageScrollSize:Number = 0;
  1073. [Bindable("horizontalPageScrollSizeChanged")]
  1074. [Inspectable(defaultValue="0")]
  1075. /**
  1076. * Number of pixels to move when the track in the
  1077. * horizontal scroll bar is pressed.
  1078. * A value of 0 means that the page size
  1079. * will be calculated to be a full screen.
  1080. *
  1081. * @default 0
  1082. */
  1083. public function get horizontalPageScrollSize():Number
  1084. {
  1085. return _horizontalPageScrollSize;
  1086. }
  1087. /**
  1088. * @private
  1089. */
  1090. public function set horizontalPageScrollSize(value:Number):void
  1091. {
  1092. scrollPropertiesChanged = true;
  1093. _horizontalPageScrollSize = value;
  1094. invalidateDisplayList();
  1095. dispatchEvent(new Event("horizontalPageScrollSizeChanged"));
  1096. }
  1097. //----------------------------------
  1098. // horizontalScrollBar
  1099. //----------------------------------
  1100. /**
  1101. * @private
  1102. * The horizontal scrollbar (null if not present).
  1103. */
  1104. private var _horizontalScrollBar:ScrollBar;
  1105. /**
  1106. * The horizontal scrollbar used in this container.
  1107. * This property is null if no horizontal scroll bar
  1108. * is currently displayed.
  1109. * In general you do not access this property directly.
  1110. * Manipulation of the <code>horizontalScrollPolicy</code>
  1111. * and <code>horizontalScrollPosition</code>
  1112. * properties should provide sufficient control over the scroll bar.
  1113. */
  1114. public function get horizontalScrollBar():ScrollBar
  1115. {
  1116. return _horizontalScrollBar;
  1117. }
  1118. /**
  1119. * @private
  1120. */
  1121. public function set horizontalScrollBar(value:ScrollBar):void
  1122. {
  1123. _horizontalScrollBar = value;
  1124. }
  1125. //----------------------------------
  1126. // horizontalScrollPosition
  1127. //----------------------------------
  1128. /**
  1129. * @private
  1130. * Storage for the horizontalScrollPosition property.
  1131. */
  1132. private var _horizontalScrollPosition:Number = 0;
  1133. [Bindable("scroll")]
  1134. [Bindable("viewChanged")]
  1135. [Inspectable(defaultValue="0")]
  1136. /**
  1137. * The current position of the horizontal scroll bar.
  1138. * This is equal to the distance in pixels between the left edge
  1139. * of the scrollable surface and the leftmost piece of the surface
  1140. * that is currently visible.
  1141. *
  1142. * @default 0
  1143. */
  1144. public function get horizontalScrollPosition():Number
  1145. {
  1146. if (!isNaN(horizontalScrollPositionPending))
  1147. return horizontalScrollPositionPending;
  1148. return _horizontalScrollPosition;
  1149. }
  1150. /**
  1151. * @private
  1152. */
  1153. public function set horizontalScrollPosition(value:Number):void
  1154. {
  1155. if (_horizontalScrollPosition == value)
  1156. return;
  1157. // Note: We can't use maxHorizontalScrollPosition to clamp the value here.
  1158. // The horizontalScrollBar may not exist yet,
  1159. // or its maxPos might change during layout.
  1160. // (For example, you could set the horizontalScrollPosition of a childless container,
  1161. // then add a child which causes it to have a scrollbar.)
  1162. // The horizontalScrollPosition gets clamped to the range 0 through maxHorizontalScrollPosition
  1163. // late, in the updateDisplayList() method, just before the scrollPosition
  1164. // of the horizontalScrollBar is set.
  1165. _horizontalScrollPosition = value;
  1166. scrollPositionChanged = true;
  1167. if (!initialized)
  1168. horizontalScrollPositionPending = value;
  1169. invalidateDisplayList();
  1170. dispatchEvent(new Event("viewChanged"));
  1171. }
  1172. //----------------------------------
  1173. // horizontalScrollPolicy
  1174. //----------------------------------
  1175. /**
  1176. * @private
  1177. * Storage for the horizontalScrollPolicy property.
  1178. */
  1179. mx_internal var _horizontalScrollPolicy:String = ScrollPolicy.AUTO;
  1180. [Bindable("horizontalScrollPolicyChanged")]
  1181. [Inspectable(category="General", enumeration="off,on,auto", defaultValue="auto")]
  1182. /**
  1183. * Specifies whether the horizontal scroll bar is always present,
  1184. * always absent, or automatically added when needed.
  1185. * ActionScript values can be <code>ScrollPolicy.ON</code>, <code>ScrollPolicy.OFF</code>,
  1186. * and <code>ScrollPolicy.AUTO</code>.
  1187. * MXML values can be <code>"on"</code>, <code>"off"</code>,
  1188. * and <code>"auto"</code>.
  1189. *
  1190. * <p>Setting this property to <code>ScrollPolicy.OFF</code> also prevents the
  1191. * <code>horizontalScrollPosition</code> property from having an effect.</p>
  1192. *
  1193. * <p>Note: This property does not apply to the ControlBar container.</p>
  1194. *
  1195. * <p>If the <code>horizontalScrollPolicy</code> is <code>ScrollPolicy.AUTO</code>,
  1196. * the horizontal scroll bar appears when all of the following
  1197. * are true:</p>
  1198. * <ul>
  1199. * <li>One of the container's children extends beyond the left
  1200. * edge or right edge of the container.</li>
  1201. * <li>The <code>clipContent</code> property is <code>true</code>.</li>
  1202. * <li>The width and height of the container are large enough to
  1203. * reasonably accommodate a scroll bar.</li>
  1204. * </ul>
  1205. *
  1206. * @default ScrollPolicy.AUTO
  1207. */
  1208. public function get horizontalScrollPolicy():String
  1209. {
  1210. return _horizontalScrollPolicy;
  1211. }
  1212. /**
  1213. * @private
  1214. */
  1215. public function set horizontalScrollPolicy(value:String):void
  1216. {
  1217. if (_horizontalScrollPolicy != value)
  1218. {
  1219. _horizontalScrollPolicy = value;
  1220. invalidateDisplayList();
  1221. dispatchEvent(new Event("horizontalScrollPolicyChanged"));
  1222. }
  1223. }
  1224. //----------------------------------
  1225. // icon
  1226. //----------------------------------
  1227. /**
  1228. * @private
  1229. * Storage for the icon property.
  1230. */
  1231. private var _icon:Class = null;
  1232. [Bindable("iconChanged")]
  1233. [Inspectable(category="General", defaultValue="", format="EmbeddedFile")]
  1234. /**
  1235. * The Class of the icon displayed by some navigator
  1236. * containers to represent this Container.
  1237. *
  1238. * <p>For example, if this Container is a child of a TabNavigator,
  1239. * this icon appears in the corresponding tab.
  1240. * If this Container is a child of an Accordion,
  1241. * this icon appears in the corresponding header.</p>
  1242. *
  1243. * <p>To embed the icon in the SWF file, use the &#64;Embed()
  1244. * MXML compiler directive:</p>
  1245. *
  1246. * <pre>
  1247. * icon="&#64;Embed('filepath')"
  1248. * </pre>
  1249. *
  1250. * <p>The image can be a JPEG, GIF, PNG, SVG, or SWF file.</p>
  1251. *
  1252. * @default null
  1253. */
  1254. public function get icon():Class
  1255. {
  1256. return _icon;
  1257. }
  1258. /**
  1259. * @private
  1260. */
  1261. public function set icon(value:Class):void
  1262. {
  1263. _icon = value;
  1264. dispatchEvent(new Event("iconChanged"));
  1265. }
  1266. //----------------------------------
  1267. // label
  1268. //----------------------------------
  1269. /**
  1270. * @private
  1271. * Storage for the label property.
  1272. */
  1273. private var _label:String = "";
  1274. [Bindable("labelChanged")]
  1275. [Inspectable(category="General", defaultValue="")]
  1276. /**
  1277. * The text displayed by some navigator containers to represent
  1278. * this Container.
  1279. *
  1280. * <p>For example, if this Container is a child of a TabNavigator,
  1281. * this string appears in the corresponding tab.
  1282. * If this Container is a child of an Accordion,
  1283. * this string appears in the corresponding header.</p>
  1284. *
  1285. * @default ""
  1286. */
  1287. public function get label():String
  1288. {
  1289. return _label;
  1290. }
  1291. /**
  1292. * @private
  1293. */
  1294. public function set label(value:String):void
  1295. {
  1296. _label = value;
  1297. dispatchEvent(new Event("labelChanged"));
  1298. }
  1299. //----------------------------------
  1300. // maxHorizontalScrollPosition
  1301. //----------------------------------
  1302. /**
  1303. * The largest possible value for the
  1304. * <code>horizontalScrollPosition</code> property.
  1305. * Defaults to 0 if the horizontal scrollbar is not present.
  1306. */
  1307. public function get maxHorizontalScrollPosition():Number
  1308. {
  1309. return horizontalScrollBar ?
  1310. horizontalScrollBar.maxScrollPosition :
  1311. Math.max(scrollableWidth - viewableWidth, 0);
  1312. }
  1313. //----------------------------------
  1314. // maxVerticalScrollPosition
  1315. //----------------------------------
  1316. /**
  1317. * The largest possible value for the
  1318. * <code>verticalScrollPosition</code> property.
  1319. * Defaults to 0 if the vertical scrollbar is not present.
  1320. */
  1321. public function get maxVerticalScrollPosition():Number
  1322. {
  1323. return verticalScrollBar ?
  1324. verticalScrollBar.maxScrollPosition :
  1325. Math.max(scrollableHeight - viewableHeight, 0);
  1326. }
  1327. //----------------------------------
  1328. // numChildrenCreated
  1329. //----------------------------------
  1330. /**
  1331. * @private
  1332. */
  1333. private var _numChildrenCreated:int = -1;
  1334. /**
  1335. * @private
  1336. * The number of children created inside this container.
  1337. * The default value is 0.
  1338. */
  1339. mx_internal function get numChildrenCreated():int
  1340. {
  1341. return _numChildrenCreated;
  1342. }
  1343. /**
  1344. * @private
  1345. */
  1346. mx_internal function set numChildrenCreated(value:int):void
  1347. {
  1348. _numChildrenCreated = value;
  1349. }
  1350. //----------------------------------
  1351. // numRepeaters
  1352. //----------------------------------
  1353. /**
  1354. * @private
  1355. * The number of Repeaters in this Container.
  1356. *
  1357. * <p>This number includes Repeaters that are immediate children of this
  1358. * container and Repeaters that are nested inside other Repeaters.
  1359. * Consider the following example:</p>
  1360. *
  1361. * <pre>
  1362. * &lt;mx:HBox&gt;
  1363. * &lt;mx:Repeater dataProvider="[1, 2]"&gt;
  1364. * &lt;mx:Repeater dataProvider="..."&gt;
  1365. * &lt;mx:Button/&gt;
  1366. * &lt;/mx:Repeater&gt;
  1367. * &lt;/mx:Repeater&gt;
  1368. * &lt;mx:HBox&gt;
  1369. * </pre>
  1370. *
  1371. * <p>In this example, the <code>numRepeaters</code> property
  1372. * for the HBox would be set equal to 3 -- one outer Repeater
  1373. * and two inner repeaters.</p>
  1374. *
  1375. * <p>The <code>numRepeaters</code> property does not include Repeaters
  1376. * that are nested inside other containers.
  1377. * Consider this example:</p>
  1378. *
  1379. * <pre>
  1380. * &lt;mx:HBox&gt;
  1381. * &lt;mx:Repeater dataProvider="[1, 2]"&gt;
  1382. * &lt;mx:VBox&gt;
  1383. * &lt;mx:Repeater dataProvider="..."&gt;
  1384. * &lt;mx:Button/&gt;
  1385. * &lt;/mx:Repeater&gt;
  1386. * &lt;/mx:VBox&gt;
  1387. * &lt;/mx:Repeater&gt;
  1388. * &lt;mx:HBox&gt;
  1389. * </pre>
  1390. *
  1391. * <p>In this example, the <code>numRepeaters</code> property
  1392. * for the outer HBox would be set equal to 1 -- just the outer repeater.
  1393. * The two inner VBox containers would also have a
  1394. * <code>numRepeaters</code> property equal to 1 -- one Repeater
  1395. * per VBox.</p>
  1396. */
  1397. mx_internal function get numRepeaters():int
  1398. {
  1399. return childRepeaters ? childRepeaters.length : 0;
  1400. }
  1401. //----------------------------------
  1402. // rawChildren
  1403. //----------------------------------
  1404. /**
  1405. * @private
  1406. * The single IChildList object that's always returned
  1407. * from the rawChildren property, below.
  1408. */
  1409. private var _rawChildren:ContainerRawChildrenList;
  1410. /**
  1411. * A container typically contains child components, which can be enumerated
  1412. * using the <code>Container.getChildAt()</code> method and
  1413. * <code>Container.numChildren</code> property. In addition, the container
  1414. * may contain style elements and skins, such as the border and background.
  1415. * Flash Player and AIR do not draw any distinction between child components
  1416. * and skins. They are all accessible using the player's
  1417. * <code>getChildAt()</code> method and
  1418. * <code>numChildren</code> property.
  1419. * However, the Container class overrides the <code>getChildAt()</code> method
  1420. * and <code>numChildren</code> property (and several other methods)
  1421. * to create the illusion that
  1422. * the container's children are the only child components.
  1423. *
  1424. * <p>If you need to access all of the children of the container (both the
  1425. * content children and the skins), then use the methods and properties
  1426. * on the <code>rawChildren</code> property instead of the regular Container methods.
  1427. * For example, use the <code>Container.rawChildren.getChildAt())</code> method.
  1428. * However, if a container creates a ContentPane Sprite object for its children,
  1429. * the <code>rawChildren</code> property value only counts the ContentPane, not the
  1430. * container's children.
  1431. * It is not always possible to determine when a container will have a ContentPane.</p>
  1432. *
  1433. * <p><b>Note:</b>If you call the <code>addChild</code> or
  1434. * <code>addChildAt</code>method of the <code>rawChildren</code> object,
  1435. * set <code>tabEnabled = false</code> on the component that you have added.
  1436. * Doing so prevents users from tabbing to the visual-only component
  1437. * that you have added.</p>
  1438. */
  1439. public function get rawChildren():IChildList
  1440. {
  1441. if (!_rawChildren)
  1442. _rawChildren = new ContainerRawChildrenList(this);
  1443. return _rawChildren;
  1444. }
  1445. //----------------------------------
  1446. // usePadding
  1447. //----------------------------------
  1448. /**
  1449. * @private
  1450. */
  1451. mx_internal function get usePadding():Boolean
  1452. {
  1453. // Containers, by default, always use padding.
  1454. return true;
  1455. }
  1456. //----------------------------------
  1457. // verticalLineScrollSize
  1458. //----------------------------------
  1459. /**
  1460. * @private
  1461. * Storage for the verticalLineScrollSize property.
  1462. */
  1463. private var _verticalLineScrollSize:Number = 5;
  1464. [Bindable("verticalLineScrollSizeChanged")]
  1465. [Inspectable(defaultValue="5")]
  1466. /**
  1467. * Number of pixels to scroll when the up- or down-arrow
  1468. * button in the vertical scroll bar is pressed,
  1469. * or when you scroll by using the mouse wheel.
  1470. *
  1471. * @default 5
  1472. */
  1473. public function get verticalLineScrollSize():Number
  1474. {
  1475. return _verticalLineScrollSize;
  1476. }
  1477. /**
  1478. * @private
  1479. */
  1480. public function set verticalLineScrollSize(value:Number):void
  1481. {
  1482. scrollPropertiesChanged = true;
  1483. _verticalLineScrollSize = value;
  1484. invalidateDisplayList();
  1485. dispatchEvent(new Event("verticalLineScrollSizeChanged"));
  1486. }
  1487. //----------------------------------
  1488. // verticalPageScrollSize
  1489. //----------------------------------
  1490. /**
  1491. * @private
  1492. * Storage for the verticalPageScrollSize property.
  1493. */
  1494. private var _verticalPageScrollSize:Number = 0;
  1495. [Bindable("verticalPageScrollSizeChanged")]
  1496. [Inspectable(defaultValue="0")]
  1497. /**
  1498. * Number of pixels to scroll when the track
  1499. * in the vertical scroll bar is pressed.
  1500. * A value of 0 means that the page size
  1501. * will be calculated to be a full screen.
  1502. *
  1503. * @default 0
  1504. */
  1505. public function get verticalPageScrollSize():Number
  1506. {
  1507. return _verticalPageScrollSize;
  1508. }
  1509. /**
  1510. * @private
  1511. */
  1512. public function set verticalPageScrollSize(value:Number):void
  1513. {
  1514. scrollPropertiesChanged = true;
  1515. _verticalPageScrollSize = value;
  1516. invalidateDisplayList();
  1517. dispatchEvent(new Event("verticalPageScrollSizeChanged"));
  1518. }
  1519. //----------------------------------
  1520. // verticalScrollBar
  1521. //----------------------------------
  1522. /**
  1523. * @private
  1524. * The vertical scrollbar (null if not present).
  1525. */
  1526. private var _verticalScrollBar:ScrollBar;
  1527. /**
  1528. * The vertical scrollbar used in this container.
  1529. * This property is null if no vertical scroll bar
  1530. * is currently displayed.
  1531. * In general you do not access this property directly.
  1532. * Manipulation of the <code>verticalScrollPolicy</code>
  1533. * and <code>verticalScrollPosition</code>
  1534. * properties should provide sufficient control over the scroll bar.
  1535. */
  1536. public function get verticalScrollBar():ScrollBar
  1537. {
  1538. return _verticalScrollBar;
  1539. }
  1540. /**
  1541. * @private
  1542. */
  1543. public function set verticalScrollBar(value:ScrollBar):void
  1544. {
  1545. _verticalScrollBar = value;
  1546. }
  1547. //----------------------------------
  1548. // verticalScrollPosition
  1549. //----------------------------------
  1550. /**
  1551. * @private
  1552. * Storage for the verticalScrollPosition property.
  1553. */
  1554. private var _verticalScrollPosition:Number = 0;
  1555. [Bindable("scroll")]
  1556. [Bindable("viewChanged")]
  1557. [Inspectable(defaultValue="0")]
  1558. /**
  1559. * The current position of the vertical scroll bar.
  1560. * This is equal to the distance in pixels between the top edge
  1561. * of the scrollable surface and the topmost piece of the surface
  1562. * that is currently visible.
  1563. *
  1564. * @default 0
  1565. */
  1566. public function get verticalScrollPosition():Number
  1567. {
  1568. if (!isNaN(verticalScrollPositionPending))
  1569. return verticalScrollPositionPending;
  1570. return _verticalScrollPosition;
  1571. }
  1572. /**
  1573. * @private
  1574. */
  1575. public function set verticalScrollPosition(value:Number):void
  1576. {
  1577. if (_verticalScrollPosition == value)
  1578. return;
  1579. // Note: We can't use maxVerticalScrollPosition to clamp the value here.
  1580. // The verticalScrollBar may not exist yet,
  1581. // or its maxPos might change during layout.
  1582. // (For example, you could set the verticalScrollPosition of a childless container,
  1583. // then add a child which causes it to have a scrollbar.)
  1584. // The verticalScrollPosition gets clamped to the range 0 through maxVerticalScrollPosition
  1585. // late, in the updateDisplayList() method, just before the scrollPosition
  1586. // of the verticalScrollBar is set.
  1587. _verticalScrollPosition = value;
  1588. scrollPositionChanged = true;
  1589. if (!initialized)
  1590. verticalScrollPositionPending = value;
  1591. invalidateDisplayList();
  1592. dispatchEvent(new Event("viewChanged"));
  1593. }
  1594. //----------------------------------
  1595. // verticalScrollPolicy
  1596. //----------------------------------
  1597. /**
  1598. * @private
  1599. * Storage for the verticalScrollPolicy property.
  1600. */
  1601. mx_internal var _verticalScrollPolicy:String = ScrollPolicy.AUTO;
  1602. [Bindable("verticalScrollPolicyChanged")]
  1603. [Inspectable(category="General", enumeration="off,on,auto", defaultValue="auto")]
  1604. /**
  1605. * Specifies whether the vertical scroll bar is always present,
  1606. * always absent, or automatically added when needed.
  1607. * Possible values are <code>ScrollPolicy.ON</code>, <code>ScrollPolicy.OFF</code>,
  1608. * and <code>ScrollPolicy.AUTO</code>.
  1609. * MXML values can be <code>"on"</code>, <code>"off"</code>,
  1610. * and <code>"auto"</code>.
  1611. *
  1612. * <p>Setting this property to <code>ScrollPolicy.OFF</code> also prevents the
  1613. * <code>verticalScrollPosition</code> property from having an effect.</p>
  1614. *
  1615. * <p>Note: This property does not apply to the ControlBar container.</p>
  1616. *
  1617. * <p>If the <code>verticalScrollPolicy</code> is <code>ScrollPolicy.AUTO</code>,
  1618. * the vertical scroll bar appears when all of the following
  1619. * are true:</p>
  1620. * <ul>
  1621. * <li>One of the container's children extends beyond the top
  1622. * edge or bottom edge of the container.</li>
  1623. * <li>The <code>clipContent</code> property is <code>true</code>.</li>
  1624. * <li>The width and height of the container are large enough to
  1625. * reasonably accommodate a scroll bar.</li>
  1626. * </ul>
  1627. *
  1628. * @default ScrollPolicy.AUTO
  1629. */
  1630. public function get verticalScrollPolicy():String
  1631. {
  1632. return _verticalScrollPolicy;
  1633. }
  1634. /**
  1635. * @private
  1636. */
  1637. public function set verticalScrollPolicy(value:String):void
  1638. {
  1639. if (_verticalScrollPolicy != value)
  1640. {
  1641. _verticalScrollPolicy = value;
  1642. invalidateDisplayList();
  1643. dispatchEvent(new Event("verticalScrollPolicyChanged"));
  1644. }
  1645. }
  1646. //----------------------------------
  1647. // viewMetrics
  1648. //----------------------------------
  1649. /**
  1650. * @private
  1651. * Offsets including borders and scrollbars
  1652. */
  1653. private var _viewMetrics:EdgeMetrics;
  1654. /**
  1655. * Returns an object that has four properties: <code>left</code>,
  1656. * <code>top</code>, <code>right</code>, and <code>bottom</code>.
  1657. * The value of each property equals the thickness of the chrome
  1658. * (visual elements) around the edge of the container.
  1659. *
  1660. * <p>The chrome includes the border thickness.
  1661. * If the <code>horizontalScrollPolicy</code> or <code>verticalScrollPolicy</code>
  1662. * property value is <code>ScrollPolicy.ON</code>, the
  1663. * chrome also includes the thickness of the corresponding
  1664. * scroll bar. If a scroll policy is <code>ScrollPolicy.AUTO</code>,
  1665. * the chrome measurement does not include the scroll bar thickness,
  1666. * even if a scroll bar is displayed.</p>
  1667. *
  1668. * <p>Subclasses of Container should override this method, so that
  1669. * they include other chrome to be taken into account when positioning
  1670. * the Container's children.
  1671. * For example, the <code>viewMetrics</code> property for the
  1672. * Panel class should return an object whose <code>top</code> property
  1673. * includes the thickness of the Panel container's title bar.</p>
  1674. */
  1675. public function get viewMetrics():EdgeMetrics
  1676. {
  1677. var bm:EdgeMetrics = borderMetrics;
  1678. // If scrollPolicy is ScrollPolicy.ON, then the scrollbars are accounted for
  1679. // during both measurement and layout.
  1680. //
  1681. // If scrollPolicy is ScrollPolicy.AUTO, then scrollbars are ignored during
  1682. // measurement. Otherwise, the entire layout of the app could change
  1683. // everytime that the scrollbars turn on or off.
  1684. //
  1685. // However, we do take the width of scrollbars into account when laying
  1686. // out our children. That way, children that have a percentage width or
  1687. // percentage height will only expand to consume space that's left over
  1688. // after leaving room for the scrollbars.
  1689. var verticalScrollBarIncluded:Boolean =
  1690. verticalScrollBar != null &&
  1691. (doingLayout || verticalScrollPolicy == ScrollPolicy.ON);
  1692. var horizontalScrollBarIncluded:Boolean =
  1693. horizontalScrollBar != null &&
  1694. (doingLayout || horizontalScrollPolicy == ScrollPolicy.ON);
  1695. if (!verticalScrollBarIncluded && !horizontalScrollBarIncluded)
  1696. return bm;
  1697. // The viewMetrics property needs to return its own object.
  1698. // Rather than allocating a new one each time, we'll allocate one once
  1699. // and then hold a reference to it.
  1700. if (!_viewMetrics)
  1701. {
  1702. _viewMetrics = bm.clone();
  1703. }
  1704. else
  1705. {
  1706. _viewMetrics.left = bm.left;
  1707. _viewMetrics.right = bm.right;
  1708. _viewMetrics.top = bm.top;
  1709. _viewMetrics.bottom = bm.bottom;
  1710. }
  1711. if (verticalScrollBarIncluded)
  1712. _viewMetrics.right += verticalScrollBar.minWidth;
  1713. if (horizontalScrollBarIncluded)
  1714. _viewMetrics.bottom += horizontalScrollBar.minHeight;
  1715. return _viewMetrics;
  1716. }
  1717. //----------------------------------
  1718. // viewMetricsAndPadding
  1719. //----------------------------------
  1720. /**
  1721. * @private
  1722. * Cached value containing the view metrics plus the object's margins.
  1723. */
  1724. private var _viewMetricsAndPadding:EdgeMetrics;
  1725. /**
  1726. * Returns an object that has four properties: <code>left</code>,
  1727. * <code>top</code>, <code>right</code>, and <code>bottom</code>.
  1728. * The value of each property is equal to the thickness of the chrome
  1729. * (visual elements)
  1730. * around the edge of the container plus the thickness of the object's margins.
  1731. *
  1732. * <p>The chrome includes the border thickness.
  1733. * If the <code>horizontalScrollPolicy</code> or <code>verticalScrollPolicy</code>
  1734. * property value is <code>ScrollPolicy.ON</code>, the
  1735. * chrome also includes the thickness of the corresponding
  1736. * scroll bar. If a scroll policy is <code>ScrollPolicy.AUTO</code>,
  1737. * the chrome measurement does not include the scroll bar thickness,
  1738. * even if a scroll bar is displayed.</p>
  1739. */
  1740. public function get viewMetricsAndPadding():EdgeMetrics
  1741. {
  1742. // If this object has scrollbars, and if the verticalScrollPolicy
  1743. // is not ScrollPolicy.ON, then the view metrics change
  1744. // depending on whether we're doing layout or not.
  1745. // In that case, we can't use a cached value.
  1746. // In all other cases, use the cached value if it exists.
  1747. if (_viewMetricsAndPadding &&
  1748. (!horizontalScrollBar ||
  1749. horizontalScrollPolicy == ScrollPolicy.ON) &&
  1750. (!verticalScrollBar ||
  1751. verticalScrollPolicy == ScrollPolicy.ON))
  1752. {
  1753. return _viewMetricsAndPadding;
  1754. }
  1755. if (!_viewMetricsAndPadding)
  1756. _viewMetricsAndPadding = new EdgeMetrics();
  1757. var o:EdgeMetrics = _viewMetricsAndPadding;
  1758. var vm:EdgeMetrics = viewMetrics;
  1759. o.left = vm.left + getStyle("paddingLeft");
  1760. o.right = vm.right + getStyle("paddingRight");
  1761. o.top = vm.top + getStyle("paddingTop");
  1762. o.bottom = vm.bottom + getStyle("paddingBottom");
  1763. return o;
  1764. }
  1765. //--------------------------------------------------------------------------
  1766. //
  1767. // Overridden methods: EventDispatcher
  1768. //
  1769. //--------------------------------------------------------------------------
  1770. /**
  1771. * @private
  1772. * If we add a mouse event, then we need to add a mouse shield
  1773. * to us and to all our children
  1774. * The mouseShield style is a non-inheriting style
  1775. * that is used by the view.
  1776. * The mouseShieldChildren style is an inherting style
  1777. * that is used by the children views.
  1778. */
  1779. override public function addEventListener(
  1780. type:String, listener:Function,
  1781. useCapture:Boolean = false,
  1782. priority:int = 0,
  1783. useWeakReference:Boolean = false):void
  1784. {
  1785. super.addEventListener(type, listener, useCapture,
  1786. priority, useWeakReference);
  1787. // If we are a mouse event, then create a mouse shield.
  1788. if (type == MouseEvent.CLICK ||
  1789. type == MouseEvent.DOUBLE_CLICK ||
  1790. type == MouseEvent.MOUSE_DOWN ||
  1791. type == MouseEvent.MOUSE_MOVE ||
  1792. type == MouseEvent.MOUSE_OVER ||
  1793. type == MouseEvent.MOUSE_OUT ||
  1794. type == MouseEvent.MOUSE_UP ||
  1795. type == MouseEvent.MOUSE_WHEEL)
  1796. {
  1797. if (mouseEventReferenceCount < 0x7FFFFFFF /* int_max */ &&
  1798. mouseEventReferenceCount++ == 0)
  1799. {
  1800. setStyle("mouseShield", true);
  1801. setStyle("mouseShieldChildren", true);
  1802. }
  1803. }
  1804. }
  1805. /**
  1806. * @private
  1807. * Remove the mouse shield if we no longer listen to any mouse events
  1808. */
  1809. override public function removeEventListener(
  1810. type:String, listener:Function,
  1811. useCapture:Boolean = false):void
  1812. {
  1813. super.removeEventListener(type, listener, useCapture);
  1814. // If we are a mouse event,
  1815. // then decrement the mouse shield reference count.
  1816. if (type == MouseEvent.CLICK ||
  1817. type == MouseEvent.DOUBLE_CLICK ||
  1818. type == MouseEvent.MOUSE_DOWN ||
  1819. type == MouseEvent.MOUSE_MOVE ||
  1820. type == MouseEvent.MOUSE_OVER ||
  1821. type == MouseEvent.MOUSE_OUT ||
  1822. type == MouseEvent.MOUSE_UP ||
  1823. type == MouseEvent.MOUSE_WHEEL)
  1824. {
  1825. if (mouseEventReferenceCount > 0 &&
  1826. --mouseEventReferenceCount == 0)
  1827. {
  1828. setStyle("mouseShield", false);
  1829. setStyle("mouseShieldChildren", false);
  1830. }
  1831. }
  1832. }
  1833. //--------------------------------------------------------------------------
  1834. //
  1835. // Overridden methods: DisplayObjectContainer
  1836. //
  1837. //--------------------------------------------------------------------------
  1838. /**
  1839. * Adds a child DisplayObject to this Container.
  1840. * The child is added after other existing children,
  1841. * so that the first child added has index 0,
  1842. * the next has index 1, an so on.
  1843. *
  1844. * <p><b>Note: </b>While the <code>child</code> argument to the method
  1845. * is specified as of type DisplayObject, the argument must implement
  1846. * the IUIComponent interface to be added as a child of a container.
  1847. * All Flex components implement this interface.</p>
  1848. *
  1849. * <p>Children are layered from back to front.
  1850. * In other words, if children overlap, the one with index 0
  1851. * is farthest to the back, and the one with index
  1852. * <code>numChildren - 1</code> is frontmost.
  1853. * This means the newly added children are layered
  1854. * in front of existing children.</p>
  1855. *
  1856. * @param child The DisplayObject to add as a child of this Container.
  1857. * It must implement the IUIComponent interface.
  1858. *
  1859. * @return The added child as an object of type DisplayObject.
  1860. * You typically cast the return value to UIComponent,
  1861. * or to the type of the added component.
  1862. *
  1863. * @see mx.core.IUIComponent
  1864. *
  1865. * @tiptext Adds a child object to this container.
  1866. */
  1867. override public function addChild(child:DisplayObject):DisplayObject
  1868. {
  1869. return addChildAt(child, numChildren);
  1870. /*
  1871. addingChild(child);
  1872. if (contentPane)
  1873. contentPane.addChild(child);
  1874. else
  1875. $addChild(child);
  1876. childAdded(child);
  1877. return child;
  1878. */
  1879. }
  1880. /**
  1881. * Adds a child DisplayObject to this Container.
  1882. * The child is added at the index specified.
  1883. *
  1884. * <p><b>Note: </b>While the <code>child</code> argument to the method
  1885. * is specified as of type DisplayObject, the argument must implement
  1886. * the IUIComponent interface to be added as a child of a container.
  1887. * All Flex components implement this interface.</p>
  1888. *
  1889. * <p>Children are layered from back to front.
  1890. * In other words, if children overlap, the one with index 0
  1891. * is farthest to the back, and the one with index
  1892. * <code>numChildren - 1</code> is frontmost.
  1893. * This means the newly added children are layered
  1894. * in front of existing children.</p>
  1895. *
  1896. * <p>When you add a new child at an index that is already occupied
  1897. * by an old child, it doesn't replace the old child; instead the
  1898. * old child and the ones after it "slide over" and have their index
  1899. * incremented by one.
  1900. * For example, suppose a Container contains the children
  1901. * (A, B, C) and you add D at index 1.
  1902. * Then the container will contain (A, D, B, C).
  1903. * If you want to replace an old child, you must first remove it
  1904. * before adding the new one.</p>
  1905. *
  1906. * @param child The DisplayObject to add as a child of this Container.
  1907. * It must implement the IUIComponent interface.
  1908. *
  1909. * @param index The index to add the child at.
  1910. *
  1911. * @return The added child as an object of type DisplayObject.
  1912. * You typically cast the return value to UIComponent,
  1913. * or to the type of the added component.
  1914. *
  1915. * @see mx.core.IUIComponent
  1916. */
  1917. override public function addChildAt(child:DisplayObject,
  1918. index:int):DisplayObject
  1919. {
  1920. var formerParent:DisplayObjectContainer = child.parent;
  1921. if (formerParent && !(formerParent is Loader))
  1922. {
  1923. // Adjust index if necessary when former parent happens
  1924. // to be the same container.
  1925. if (formerParent == this)
  1926. index = (index == numChildren) ? index - 1 : index;
  1927. formerParent.removeChild(child);
  1928. }
  1929. addingChild(child);
  1930. // Add the child to either this container or its contentPane.
  1931. // The player will dispatch an "added" event from the child
  1932. // after it has been added, so all "added" handlers execute here.
  1933. if (contentPane)
  1934. contentPane.addChildAt(child, index);
  1935. else
  1936. $addChildAt(child, _firstChildIndex + index);
  1937. childAdded(child);
  1938. if ((child is UIComponent) && UIComponent(child).isDocument)
  1939. BindingManager.setEnabled(child, true);
  1940. return child;
  1941. }
  1942. /**
  1943. * Removes a child DisplayObject from the child list of this Container.
  1944. * The removed child will have its <code>parent</code>
  1945. * property set to null.
  1946. * The child will still exist unless explicitly destroyed.
  1947. * If you add it to another container,
  1948. * it will retain its last known state.
  1949. *
  1950. * @param child The DisplayObject to remove.
  1951. *
  1952. * @return The removed child as an object of type DisplayObject.
  1953. * You typically cast the return value to UIComponent,
  1954. * or to the type of the removed component.
  1955. */
  1956. override public function removeChild(child:DisplayObject):DisplayObject
  1957. {
  1958. if (child is IDeferredInstantiationUIComponent &&
  1959. IDeferredInstantiationUIComponent(child).descriptor)
  1960. {
  1961. // if child's descriptor is present, it means child was created
  1962. // with MXML. Need to go through and remove component in
  1963. // createdComponents so there is no memory leak by keeping
  1964. // a reference to the removed child (SDK-12506)
  1965. if (createdComponents)
  1966. {
  1967. var n:int = createdComponents.length;
  1968. for(var i:int = 0; i < n; i++)
  1969. {
  1970. if (createdComponents[i] === child)
  1971. {
  1972. // delete this reference
  1973. createdComponents.splice(i, 1);
  1974. }
  1975. }
  1976. }
  1977. }
  1978. removingChild(child);
  1979. if ((child is UIComponent) && UIComponent(child).isDocument)
  1980. BindingManager.setEnabled(child, false);
  1981. // Remove the child from either this container or its contentPane.
  1982. // The player will dispatch a "removed" event from the child
  1983. // before it is removed, so all "removed" handlers execute here.
  1984. if (contentPane)
  1985. contentPane.removeChild(child);
  1986. else
  1987. $removeChild(child);
  1988. childRemoved(child);
  1989. return child;
  1990. }
  1991. /**
  1992. * Removes a child DisplayObject from the child list of this Container
  1993. * at the specified index.
  1994. * The removed child will have its <code>parent</code>
  1995. * property set to null.
  1996. * The child will still exist unless explicitly destroyed.
  1997. * If you add it to another container,
  1998. * it will retain its last known state.
  1999. *
  2000. * @param index The child index of the DisplayObject to remove.
  2001. *
  2002. * @return The removed child as an object of type DisplayObject.
  2003. * You typically cast the return value to UIComponent,
  2004. * or to the type of the removed component.
  2005. */
  2006. override public function removeChildAt(index:int):DisplayObject
  2007. {
  2008. return removeChild(getChildAt(index));
  2009. /*
  2010. Shouldn't implement removeChildAt() in terms of removeChild().
  2011. */
  2012. }
  2013. /**
  2014. * Gets the <i>n</i>th child component object.
  2015. *
  2016. * <p>The children returned from this method include children that are
  2017. * declared in MXML and children that are added using the
  2018. * <code>addChild()</code> or <code>addChildAt()</code> method.</p>
  2019. *
  2020. * @param childIndex Number from 0 to (numChildren - 1).
  2021. *
  2022. * @return Reference to the child as an object of type DisplayObject.
  2023. * You typically cast the return value to UIComponent,
  2024. * or to the type of a specific Flex control, such as ComboBox or TextArea.
  2025. */
  2026. override public function getChildAt(index:int):DisplayObject
  2027. {
  2028. if (contentPane)
  2029. {
  2030. return contentPane.getChildAt(index);
  2031. }
  2032. else
  2033. {
  2034. // The DisplayObjectContainer implementation of getChildAt()
  2035. // in the Player throws this error if the index is bad,
  2036. // so we should too.
  2037. // if (index < 0 || index >= _numChildren)
  2038. // throw new RangeError("The supplied index is out of bounds");
  2039. return super.getChildAt(_firstChildIndex + index);
  2040. }
  2041. }
  2042. /**
  2043. * Returns the child whose <code>name</code> property is the specified String.
  2044. *
  2045. * @param name The identifier of the child.
  2046. *
  2047. * @return The DisplayObject representing the child as an object of type DisplayObject.
  2048. * You typically cast the return value to UIComponent,
  2049. * or to the type of a specific Flex control, such as ComboBox or TextArea.
  2050. */
  2051. override public function getChildByName(name:String):DisplayObject
  2052. {
  2053. if (contentPane)
  2054. {
  2055. return contentPane.getChildByName(name);
  2056. }
  2057. else
  2058. {
  2059. var child:DisplayObject = super.getChildByName(name);
  2060. if (!child)
  2061. return null;
  2062. // Check if the child is in the index range for content children.
  2063. var index:int = super.getChildIndex(child) - _firstChildIndex;
  2064. if (index < 0 || index >= _numChildren)
  2065. return null;
  2066. return child;
  2067. }
  2068. }
  2069. /**
  2070. * Gets the zero-based index of a specific child.
  2071. *
  2072. * <p>The first child of the container (i.e.: the first child tag
  2073. * that appears in the MXML declaration) has an index of 0,
  2074. * the second child has an index of 1, and so on.
  2075. * The indexes of a container's children determine
  2076. * the order in which they get laid out.
  2077. * For example, in a VBox the child with index 0 is at the top,
  2078. * the child with index 1 is below it, etc.</p>
  2079. *
  2080. * <p>If you add a child by calling the <code>addChild()</code> method,
  2081. * the new child's index is equal to the largest index among existing
  2082. * children plus one.
  2083. * You can insert a child at a specified index by using the
  2084. * <code>addChildAt()</code> method; in that case the indices of the
  2085. * child previously at that index, and the children at higher indices,
  2086. * all have their index increased by 1 so that all indices fall in the
  2087. * range from 0 to <code>(numChildren - 1)</code>.</p>
  2088. *
  2089. * <p>If you remove a child by calling <code>removeChild()</code>
  2090. * or <code>removeChildAt()</code> method, then the indices of the
  2091. * remaining children are adjusted so that all indices fall in the
  2092. * range from 0 to <code>(numChildren - 1)</code>.</p>
  2093. *
  2094. * <p>If <code>myView.getChildIndex(myChild)</code> returns 5,
  2095. * then <code>myView.getChildAt(5)</code> returns myChild.</p>
  2096. *
  2097. * <p>The index of a child may be changed by calling the
  2098. * <code>setChildIndex()</code> method.</p>
  2099. *
  2100. * @param child Reference to child whose index to get.
  2101. *
  2102. * @return Number between 0 and (numChildren - 1).
  2103. */
  2104. override public function getChildIndex(child:DisplayObject):int
  2105. {
  2106. if (contentPane)
  2107. {
  2108. return contentPane.getChildIndex(child);
  2109. }
  2110. else
  2111. {
  2112. var index:int = super.getChildIndex(child) - _firstChildIndex;
  2113. // The DisplayObjectContainer implementation of getChildIndex()
  2114. // in the Player throws this error if the child isn't a child,
  2115. // so we should too.
  2116. // if (index < 0 || index >= _numChildren)
  2117. // throw new ArgumentError("The DisplayObject supplied must be a child of the caller.");
  2118. return index;
  2119. }
  2120. }
  2121. /**
  2122. * Sets the index of a particular child.
  2123. * See the <code>getChildIndex()</code> method for a
  2124. * description of the child's index.
  2125. *
  2126. * @param child Reference to child whose index to set.
  2127. *
  2128. * @param newIndex Number that indicates the new index.
  2129. * Must be an integer between 0 and (numChildren - 1).
  2130. */
  2131. override public function setChildIndex(child:DisplayObject, newIndex:int):void
  2132. {
  2133. var oldIndex:int;
  2134. var eventOldIndex:int = oldIndex;
  2135. var eventNewIndex:int = newIndex;
  2136. if (contentPane)
  2137. {
  2138. contentPane.setChildIndex(child, newIndex);
  2139. if (_autoLayout || forceLayout)
  2140. invalidateDisplayList();
  2141. }
  2142. else
  2143. {
  2144. oldIndex = super.getChildIndex(child);
  2145. // Offset the index, to leave room for skins before the list of children
  2146. newIndex += _firstChildIndex;
  2147. if (newIndex == oldIndex)
  2148. return;
  2149. // Change the child's index, shifting around other children to make room
  2150. super.setChildIndex(child, newIndex);
  2151. invalidateDisplayList();
  2152. eventOldIndex = oldIndex - _firstChildIndex;
  2153. eventNewIndex = newIndex - _firstChildIndex;
  2154. }
  2155. // Notify others that the child index has changed
  2156. var event:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHILD_INDEX_CHANGE);
  2157. event.relatedObject = child;
  2158. event.oldIndex = eventOldIndex;
  2159. event.newIndex = eventNewIndex;
  2160. dispatchEvent(event);
  2161. dispatchEvent(new Event("childrenChanged"));
  2162. }
  2163. /**
  2164. * @private
  2165. */
  2166. override public function contains(child:DisplayObject):Boolean
  2167. {
  2168. if (contentPane)
  2169. return contentPane.contains(child);
  2170. else
  2171. return super.contains(child);
  2172. }
  2173. //--------------------------------------------------------------------------
  2174. //
  2175. // Overridden methods: UIComponent
  2176. //
  2177. //--------------------------------------------------------------------------
  2178. /**
  2179. * @private
  2180. */
  2181. override public function initialize():void
  2182. {
  2183. // Until component templating is implemented, the childDescriptors
  2184. // come either from the top-level descriptor in the component itself
  2185. // (i.e., the defined children) or from a descriptor for an instance
  2186. // of that component in some other component or app (i.e., the
  2187. // instance children). At this point _childDescriptors already
  2188. // contains the instance children if there are any; but if the
  2189. // document defines any children, we have to use them instead.
  2190. if (isDocument && documentDescriptor && !processedDescriptors)
  2191. {
  2192. // NOTE: documentDescriptor.properties is a potentially
  2193. // expensive function call, so do it only once.
  2194. var props:* = documentDescriptor.properties;
  2195. if (props && props.childDescriptors)
  2196. {
  2197. if (_childDescriptors)
  2198. {
  2199. var message:String = resourceManager.getString(
  2200. "core", "multipleChildSets_ClassAndInstance");
  2201. throw new Error(message);
  2202. }
  2203. else
  2204. {
  2205. _childDescriptors = props.childDescriptors;
  2206. }
  2207. }
  2208. }
  2209. super.initialize();
  2210. }
  2211. /**
  2212. * @private
  2213. * Create components that are children of this Container.
  2214. */
  2215. override protected function createChildren():void
  2216. {
  2217. super.createChildren();
  2218. // Create the border/background object.
  2219. createBorder();
  2220. // To save ourselves an extra layout pass, check to see
  2221. // if the scrollbars will definitely be needed.
  2222. // If so, create them now.
  2223. createOrDestroyScrollbars(
  2224. horizontalScrollPolicy == ScrollPolicy.ON,
  2225. verticalScrollPolicy == ScrollPolicy.ON,
  2226. horizontalScrollPolicy == ScrollPolicy.ON ||
  2227. verticalScrollPolicy == ScrollPolicy.ON);
  2228. // Determine the child-creation policy (ContainerCreationPolicy.AUTO,
  2229. // ContainerCreationPolicy.ALL, or ContainerCreationPolicy.NONE).
  2230. // If the author has specified a policy, use it.
  2231. // Otherwise, use the parent's policy.
  2232. // This must be set before createChildren() gets called.
  2233. if (creationPolicy != null)
  2234. {
  2235. actualCreationPolicy = creationPolicy;
  2236. }
  2237. else if (parent is Container)
  2238. {
  2239. if (Container(parent).actualCreationPolicy ==
  2240. ContainerCreationPolicy.QUEUED)
  2241. {
  2242. actualCreationPolicy = ContainerCreationPolicy.AUTO;
  2243. }
  2244. else
  2245. {
  2246. actualCreationPolicy = Container(parent).actualCreationPolicy;
  2247. }
  2248. }
  2249. // It is ok for actualCreationPolicy to be null. Popups require it.
  2250. if (actualCreationPolicy == ContainerCreationPolicy.NONE)
  2251. {
  2252. actualCreationPolicy = ContainerCreationPolicy.AUTO;
  2253. }
  2254. else if (actualCreationPolicy == ContainerCreationPolicy.QUEUED)
  2255. {
  2256. var mainApp:Application = parentApplication ?
  2257. Application(parentApplication) :
  2258. Application(Application.application);
  2259. mainApp.addToCreationQueue(this, creationIndex, null, this);
  2260. }
  2261. else if (recursionFlag)
  2262. {
  2263. // Create whatever children are appropriate. If any were
  2264. // previously created, they don't get re-created.
  2265. createComponentsFromDescriptors();
  2266. }
  2267. // If autoLayout is initially false, we still want to do
  2268. // measurement once (even if we don't have any children)
  2269. if (autoLayout == false)
  2270. forceLayout = true;
  2271. // weak references
  2272. UIComponentGlobals.layoutManager.addEventListener(
  2273. FlexEvent.UPDATE_COMPLETE, layoutCompleteHandler, false, 0, true);
  2274. }
  2275. /**
  2276. * @private
  2277. * Override to NOT set precessedDescriptors.
  2278. */
  2279. override protected function initializationComplete():void
  2280. {
  2281. // Don't call super.initializationComplete().
  2282. }
  2283. /**
  2284. * @private
  2285. */
  2286. override protected function commitProperties():void
  2287. {
  2288. super.commitProperties();
  2289. if (changedStyles)
  2290. {
  2291. // If multiple properties have changed, set styleProp to null.
  2292. // Otherwise, set it to the name of the style that has changed.
  2293. var styleProp:String = changedStyles == MULTIPLE_PROPERTIES ?
  2294. null :
  2295. changedStyles;
  2296. super.notifyStyleChangeInChildren(styleProp, true);
  2297. changedStyles = null;
  2298. }
  2299. createOrDestroyBlocker();
  2300. }
  2301. /**
  2302. * @private
  2303. */
  2304. override public function validateSize(recursive:Boolean = false):void
  2305. {
  2306. // If autoLayout is turned off and we haven't recently created
  2307. // or destroyed any children, then we're not doing any
  2308. // measurement or layout.
  2309. // Return false indicating that the measurements haven't changed.
  2310. if (autoLayout == false && forceLayout == false)
  2311. {
  2312. if (recursive)
  2313. {
  2314. var n:int = super.numChildren;
  2315. for (var i:int = 0; i < n; i++)
  2316. {
  2317. var child:DisplayObject = super.getChildAt(i);
  2318. if (child is ILayoutManagerClient )
  2319. ILayoutManagerClient (child).validateSize(true);
  2320. }
  2321. }
  2322. adjustSizesForScaleChanges();
  2323. }
  2324. else
  2325. {
  2326. super.validateSize(recursive);
  2327. }
  2328. }
  2329. /**
  2330. * @private
  2331. */
  2332. override public function validateDisplayList():void
  2333. {
  2334. // trace(">>Container validateLayoutPhase " + this);
  2335. var vm:EdgeMetrics;
  2336. // If autoLayout is turned off and we haven't recently created or
  2337. // destroyed any children, then don't do any layout
  2338. if (_autoLayout || forceLayout)
  2339. {
  2340. doingLayout = true;
  2341. super.validateDisplayList();
  2342. doingLayout = false;
  2343. }
  2344. else
  2345. {
  2346. // Layout borders, Panel headers, and other border chrome.
  2347. layoutChrome(unscaledWidth, unscaledHeight);
  2348. }
  2349. // Set this to block requeuing when sizing children.
  2350. invalidateDisplayListFlag = true;
  2351. // Based on the positions of the children, determine
  2352. // whether a clip mask and scrollbars are needed.
  2353. if (createContentPaneAndScrollbarsIfNeeded())
  2354. {
  2355. // Redo layout if scrollbars just got created or destroyed (because
  2356. // now we may have more or less space).
  2357. if (_autoLayout || forceLayout)
  2358. {
  2359. doingLayout = true;
  2360. super.validateDisplayList();
  2361. doingLayout = false;
  2362. }
  2363. // If a scrollbar was created, that may precipitate the need
  2364. // for a second scrollbar, so run it a second time.
  2365. createContentPaneAndScrollbarsIfNeeded();
  2366. }
  2367. // The relayout performed by the above calls
  2368. // to super.validateDisplayList() may result
  2369. // in new max scroll positions that are less
  2370. // than previously-set scroll positions.
  2371. // For example, when a maximally-scrolled container
  2372. // is resized to be larger, the new max scroll positions
  2373. // are reduced and the current scroll positions
  2374. // will be invalid unless we clamp them.
  2375. if (clampScrollPositions())
  2376. scrollChildren();
  2377. if (contentPane)
  2378. {
  2379. vm = viewMetrics;
  2380. // Set the position and size of the overlay .
  2381. if (overlay)
  2382. {
  2383. overlay.x = 0;
  2384. overlay.y = 0;
  2385. overlay.width = unscaledWidth;
  2386. overlay.height = unscaledHeight;
  2387. }
  2388. // Set the positions and sizes of the scrollbars.
  2389. if (horizontalScrollBar || verticalScrollBar)
  2390. {
  2391. // Get the view metrics and remove the thickness
  2392. // of the scrollbars from the view metrics.
  2393. // We can't simply get the border metrics,
  2394. // because some subclass (e.g.: Window)
  2395. // might add to the metrics.
  2396. if (verticalScrollBar &&
  2397. verticalScrollPolicy == ScrollPolicy.ON)
  2398. {
  2399. vm.right -= verticalScrollBar.minWidth;
  2400. }
  2401. if (horizontalScrollBar &&
  2402. horizontalScrollPolicy == ScrollPolicy.ON)
  2403. {
  2404. vm.bottom -= horizontalScrollBar.minHeight;
  2405. }
  2406. if (horizontalScrollBar)
  2407. {
  2408. var w:Number = unscaledWidth - vm.left - vm.right;
  2409. if (verticalScrollBar)
  2410. w -= verticalScrollBar.minWidth;
  2411. horizontalScrollBar.setActualSize(
  2412. w, horizontalScrollBar.minHeight);
  2413. horizontalScrollBar.move(vm.left,
  2414. unscaledHeight - vm.bottom -
  2415. horizontalScrollBar.minHeight);
  2416. }
  2417. if (verticalScrollBar)
  2418. {
  2419. var h:Number = unscaledHeight - vm.top - vm.bottom;
  2420. if (horizontalScrollBar)
  2421. h -= horizontalScrollBar.minHeight;
  2422. verticalScrollBar.setActualSize(
  2423. verticalScrollBar.minWidth, h);
  2424. verticalScrollBar.move(unscaledWidth - vm.right -
  2425. verticalScrollBar.minWidth,
  2426. vm.top);
  2427. }
  2428. // Set the position of the box
  2429. // that covers the gap between the scroll bars.
  2430. if (whiteBox)
  2431. {
  2432. whiteBox.x = verticalScrollBar.x;
  2433. whiteBox.y = horizontalScrollBar.y;
  2434. }
  2435. }
  2436. contentPane.x = vm.left;
  2437. contentPane.y = vm.top;
  2438. if (focusPane)
  2439. {
  2440. focusPane.x = vm.left
  2441. focusPane.y = vm.top;
  2442. }
  2443. scrollChildren();
  2444. }
  2445. invalidateDisplayListFlag = false;
  2446. // that blocks UI input as well as draws an alpha overlay.
  2447. // Make sure the blocker is correctly positioned and sized here.
  2448. if (blocker)
  2449. {
  2450. vm = viewMetrics;
  2451. var bgColor:Object = enabled ?
  2452. null :
  2453. getStyle("backgroundDisabledColor");
  2454. if (bgColor === null || isNaN(Number(bgColor)))
  2455. bgColor = getStyle("backgroundColor");
  2456. if (bgColor === null || isNaN(Number(bgColor)))
  2457. bgColor = 0xFFFFFF;
  2458. var blockerAlpha:Number = getStyle("disabledOverlayAlpha");
  2459. if (isNaN(blockerAlpha))
  2460. blockerAlpha = 0.6;
  2461. blocker.x = vm.left;
  2462. blocker.y = vm.top;
  2463. var widthToBlock:Number = unscaledWidth - (vm.left + vm.right);
  2464. var heightToBlock:Number = unscaledHeight - (vm.top + vm.bottom);
  2465. blocker.graphics.clear();
  2466. blocker.graphics.beginFill(uint(bgColor), blockerAlpha);
  2467. blocker.graphics.drawRect(0, 0, widthToBlock, heightToBlock);
  2468. blocker.graphics.endFill();
  2469. // Blocker must be in front of everything
  2470. rawChildren.setChildIndex(blocker, rawChildren.numChildren - 1);
  2471. }
  2472. // trace("<<Container internalValidateDisplayList " + this);
  2473. }
  2474. /**
  2475. * Respond to size changes by setting the positions and sizes
  2476. * of this container's children.
  2477. *
  2478. * <p>See the <code>UIComponent.updateDisplayList()</code> method for more information
  2479. * about the <code>updateDisplayList()</code> method.</p>
  2480. *
  2481. * <p>The <code>Container.updateDisplayList()</code> method sets the position
  2482. * and size of the Container container's border.
  2483. * In every subclass of Container, the subclass's <code>updateDisplayList()</code>
  2484. * method should call the <code>super.updateDisplayList()</code> method,
  2485. * so that the border is positioned properly.</p>
  2486. *
  2487. * @param unscaledWidth Specifies the width of the component, in pixels,
  2488. * in the component's coordinates, regardless of the value of the
  2489. * <code>scaleX</code> property of the component.
  2490. *
  2491. * @param unscaledHeight Specifies the height of the component, in pixels,
  2492. * in the component's coordinates, regardless of the value of the
  2493. * <code>scaleY</code> property of the component.
  2494. *
  2495. * @see mx.core.UIComponent
  2496. */
  2497. override protected function updateDisplayList(unscaledWidth:Number,
  2498. unscaledHeight:Number):void
  2499. {
  2500. super.updateDisplayList(unscaledWidth, unscaledHeight);
  2501. layoutChrome(unscaledWidth, unscaledHeight);
  2502. if (scrollPositionChanged)
  2503. {
  2504. clampScrollPositions();
  2505. scrollChildren();
  2506. scrollPositionChanged = false;
  2507. }
  2508. if (scrollPropertiesChanged)
  2509. {
  2510. if (horizontalScrollBar)
  2511. {
  2512. horizontalScrollBar.lineScrollSize = horizontalLineScrollSize;
  2513. horizontalScrollBar.pageScrollSize = horizontalPageScrollSize;
  2514. }
  2515. if (verticalScrollBar)
  2516. {
  2517. verticalScrollBar.lineScrollSize = verticalLineScrollSize;
  2518. verticalScrollBar.pageScrollSize = verticalPageScrollSize;
  2519. }
  2520. scrollPropertiesChanged = false;
  2521. }
  2522. if (contentPane && contentPane.scrollRect)
  2523. {
  2524. // Draw content pane
  2525. var backgroundColor:Object = enabled ?
  2526. null :
  2527. getStyle("backgroundDisabledColor");
  2528. if (backgroundColor === null || isNaN(Number(backgroundColor)))
  2529. backgroundColor = getStyle("backgroundColor");
  2530. var backgroundAlpha:Number = getStyle("backgroundAlpha");
  2531. if (!_clipContent ||
  2532. isNaN(Number(backgroundColor)) ||
  2533. backgroundColor === "" ||
  2534. (!(horizontalScrollBar || verticalScrollBar) && !cacheAsBitmap))
  2535. {
  2536. backgroundColor = null;
  2537. }
  2538. // If there's a backgroundImage or background, unset
  2539. // opaqueBackground.
  2540. else if (getStyle("backgroundImage") ||
  2541. getStyle("background"))
  2542. {
  2543. backgroundColor = null;
  2544. }
  2545. // If the background is not opaque, unset opaqueBackground.
  2546. else if (backgroundAlpha != 1)
  2547. {
  2548. backgroundColor = null;
  2549. }
  2550. contentPane.opaqueBackground = backgroundColor;
  2551. // Set cacheAsBitmap only if opaqueBackground is also set (to avoid
  2552. // text anti-aliasing issue with device text on Windows).
  2553. contentPane.cacheAsBitmap = (backgroundColor != null);
  2554. }
  2555. }
  2556. /**
  2557. * @copy mx.core.UIComponent#contentToGlobal()
  2558. */
  2559. override public function contentToGlobal(point:Point):Point
  2560. {
  2561. if (contentPane)
  2562. return contentPane.localToGlobal(point);
  2563. return localToGlobal(point);
  2564. }
  2565. /**
  2566. * @copy mx.core.UIComponent#globalToContent()
  2567. */
  2568. override public function globalToContent(point:Point):Point
  2569. {
  2570. if (contentPane)
  2571. return contentPane.globalToLocal(point);
  2572. return globalToLocal(point);
  2573. }
  2574. /**
  2575. * @copy mx.core.UIComponent#contentToLocal()
  2576. */
  2577. override public function contentToLocal(point:Point):Point
  2578. {
  2579. if (!contentPane)
  2580. return point;
  2581. point = contentToGlobal(point);
  2582. return globalToLocal(point);
  2583. }
  2584. /**
  2585. * @copy mx.core.UIComponent#localToContent()
  2586. */
  2587. override public function localToContent(point:Point):Point
  2588. {
  2589. if (!contentPane)
  2590. return point;
  2591. point = localToGlobal(point);
  2592. return globalToContent(point);
  2593. }
  2594. /**
  2595. * @private
  2596. */
  2597. override public function styleChanged(styleProp:String):void
  2598. {
  2599. var allStyles:Boolean = styleProp == null || styleProp == "styleName";
  2600. // Check to see if this is one of the style properties that is known
  2601. // to affect page layout.
  2602. if (allStyles || StyleManager.isSizeInvalidatingStyle(styleProp))
  2603. {
  2604. // Some styles, such as horizontalAlign and verticalAlign,
  2605. // affect the layout of this object's children without changing the
  2606. // view's size. This function forces the view to be remeasured
  2607. // and layed out.
  2608. invalidateDisplayList();
  2609. }
  2610. // Replace the borderSkin
  2611. if (allStyles || styleProp == "borderSkin")
  2612. {
  2613. if (border)
  2614. {
  2615. rawChildren.removeChild(DisplayObject(border));
  2616. border = null;
  2617. createBorder();
  2618. }
  2619. }
  2620. // Create a border object, if none previously existed and
  2621. // one is needed now.
  2622. if (allStyles ||
  2623. styleProp == "borderStyle" ||
  2624. styleProp == "backgroundColor" ||
  2625. styleProp == "backgroundImage" ||
  2626. styleProp == "mouseShield" ||
  2627. styleProp == "mouseShieldChildren")
  2628. {
  2629. createBorder();
  2630. }
  2631. super.styleChanged(styleProp);
  2632. // Check to see if this is one of the style properties that is known.
  2633. // to affect page layout.
  2634. if (allStyles ||
  2635. StyleManager.isSizeInvalidatingStyle(styleProp))
  2636. {
  2637. invalidateViewMetricsAndPadding();
  2638. }
  2639. if (allStyles || styleProp == "horizontalScrollBarStyleName")
  2640. {
  2641. if (horizontalScrollBar && horizontalScrollBar is ISimpleStyleClient)
  2642. {
  2643. var horizontalScrollBarStyleName:String =
  2644. getStyle("horizontalScrollBarStyleName");
  2645. ISimpleStyleClient(horizontalScrollBar).styleName =
  2646. horizontalScrollBarStyleName;
  2647. }
  2648. }
  2649. if (allStyles || styleProp == "verticalScrollBarStyleName")
  2650. {
  2651. if (verticalScrollBar && verticalScrollBar is ISimpleStyleClient)
  2652. {
  2653. var verticalScrollBarStyleName:String =
  2654. getStyle("verticalScrollBarStyleName");
  2655. ISimpleStyleClient(verticalScrollBar).styleName =
  2656. verticalScrollBarStyleName;
  2657. }
  2658. }
  2659. }
  2660. /**
  2661. * @private
  2662. * Call the styleChanged method on children of this container
  2663. *
  2664. * Notify chrome children immediately, and recursively call this
  2665. * function for all descendants of the chrome children. We recurse
  2666. * regardless of the recursive flag because one of the descendants
  2667. * might have a styleName property that points to this object.
  2668. *
  2669. * If recursive is true, then also notify content children ... but
  2670. * do it later. Notification is deferred so that multiple calls to
  2671. * setStyle can be batched up into one traversal.
  2672. */
  2673. override public function notifyStyleChangeInChildren(
  2674. styleProp:String, recursive:Boolean):void
  2675. {
  2676. // Notify chrome children immediately, recursively calling this
  2677. // this function
  2678. var n:int = super.numChildren;
  2679. for (var i:int = 0; i < n; i++)
  2680. {
  2681. // Is this a chrome child?
  2682. if (contentPane ||
  2683. i < _firstChildIndex ||
  2684. i >= _firstChildIndex + _numChildren)
  2685. {
  2686. var child:ISimpleStyleClient = super.getChildAt(i) as ISimpleStyleClient;
  2687. if (child)
  2688. {
  2689. child.styleChanged(styleProp);
  2690. if (child is IStyleClient)
  2691. IStyleClient(child).notifyStyleChangeInChildren(styleProp, recursive);
  2692. }
  2693. }
  2694. }
  2695. // If recursive, then remember to notify the content children later
  2696. if (recursive)
  2697. {
  2698. // If multiple styleProps have changed, set changedStyles to
  2699. // MULTIPLE_PROPERTIES. Otherwise, set it to the name of the
  2700. // changed property.
  2701. changedStyles = (changedStyles != null || styleProp == null) ?
  2702. MULTIPLE_PROPERTIES : styleProp;
  2703. invalidateProperties();
  2704. }
  2705. }
  2706. /**
  2707. * @private
  2708. */
  2709. override public function regenerateStyleCache(recursive:Boolean):void
  2710. {
  2711. super.regenerateStyleCache(recursive);
  2712. if (contentPane)
  2713. {
  2714. // Do the same thing as UIComponent, but don't check the child's index to
  2715. // ascertain that it's a content child (we already know that here).
  2716. var n:int = contentPane.numChildren;
  2717. for (var i:int = 0; i < n; i++)
  2718. {
  2719. var child:DisplayObject = getChildAt(i);
  2720. if (recursive && child is UIComponent)
  2721. {
  2722. // Does this object already have a proto chain? If not,
  2723. // there's no need to regenerate a new one.
  2724. if (UIComponent(child).inheritingStyles != UIComponent.STYLE_UNINITIALIZED)
  2725. UIComponent(child).regenerateStyleCache(recursive);
  2726. }
  2727. else if (child is IUITextField && IUITextField(child).inheritingStyles)
  2728. {
  2729. StyleProtoChain.initTextField(IUITextField(child));
  2730. }
  2731. }
  2732. }
  2733. }
  2734. /**
  2735. * Used internally by the Dissolve Effect to add the overlay to the chrome of a container.
  2736. */
  2737. override protected function attachOverlay():void
  2738. {
  2739. rawChildren_addChild(overlay);
  2740. }
  2741. /**
  2742. * Fill an overlay object which is always the topmost child in the container.
  2743. * This method is used
  2744. * by the Dissolve effect; never call it directly. It is called
  2745. * internally by the <code>addOverlay()</code> method.
  2746. *
  2747. * The Container fills the overlay object so it covers the viewable area returned
  2748. * by the <code>viewMetrics</code> property and uses the <code>cornerRadius</code> style.
  2749. */
  2750. override mx_internal function fillOverlay(overlay:UIComponent, color:uint,
  2751. targetArea:RoundedRectangle = null):void
  2752. {
  2753. var vm:EdgeMetrics = viewMetrics;
  2754. var cornerRadius:Number = 0; //getStyle("cornerRadius");
  2755. if (!targetArea)
  2756. {
  2757. targetArea = new RoundedRectangle(
  2758. vm.left, vm.top,
  2759. unscaledWidth - vm.right - vm.left,
  2760. unscaledHeight - vm.bottom - vm.top,cornerRadius);
  2761. }
  2762. if (isNaN(targetArea.x) || isNaN(targetArea.y) ||
  2763. isNaN(targetArea.width) || isNaN(targetArea.height) ||
  2764. isNaN(targetArea.cornerRadius))
  2765. return;
  2766. var g:Graphics = overlay.graphics;
  2767. g.clear();
  2768. g.beginFill(color);
  2769. g.drawRoundRect(targetArea.x, targetArea.y,
  2770. targetArea.width, targetArea.height,
  2771. targetArea.cornerRadius * 2,
  2772. targetArea.cornerRadius * 2);
  2773. g.endFill();
  2774. }
  2775. /**
  2776. * Executes all the data bindings on this Container. Flex calls this method
  2777. * automatically once a Container has been created to cause any data bindings that
  2778. * have destinations inside of it to execute.
  2779. *
  2780. * Workaround for MXML container/bindings problem (177074):
  2781. * override Container.executeBindings() to prefer descriptor.document over parentDocument in the
  2782. * call to BindingManager.executeBindings().
  2783. *
  2784. * This should always provide the correct behavior for instances created by descriptor, and will
  2785. * provide the original behavior for procedurally-created instances. (The bug may or may not appear
  2786. * in the latter case.)
  2787. *
  2788. * A more complete fix, guaranteeing correct behavior in both non-DI and reparented-component
  2789. * scenarios, is anticipated for updater 1.
  2790. *
  2791. * @param recurse If <code>false</code>, then only execute the bindings
  2792. * on this Container.
  2793. * If <code>true</code>, then also execute the bindings on this
  2794. * container's children, grandchildren,
  2795. * great-grandchildren, and so on.
  2796. */
  2797. override public function executeBindings(recurse:Boolean = false):void
  2798. {
  2799. var bindingsHost:Object = descriptor && descriptor.document ? descriptor.document : parentDocument;
  2800. BindingManager.executeBindings(bindingsHost, id, this);
  2801. if (recurse)
  2802. executeChildBindings(recurse);
  2803. }
  2804. /**
  2805. * @private
  2806. * Prepare the Object for printing
  2807. *
  2808. * @see mx.printing.FlexPrintJob
  2809. */
  2810. override public function prepareToPrint(target:IFlexDisplayObject):Object
  2811. {
  2812. var rect:Rectangle = (contentPane && contentPane.scrollRect) ? contentPane.scrollRect : null;
  2813. if (rect)
  2814. contentPane.scrollRect = null;
  2815. super.prepareToPrint(target);
  2816. return rect;
  2817. }
  2818. /**
  2819. * @private
  2820. * After printing is done
  2821. *
  2822. * @see mx.printing.FlexPrintJob
  2823. */
  2824. override public function finishPrint(obj:Object, target:IFlexDisplayObject):void
  2825. {
  2826. if (obj)
  2827. contentPane.scrollRect = Rectangle(obj);
  2828. super.finishPrint(obj,target);
  2829. }
  2830. //--------------------------------------------------------------------------
  2831. //
  2832. // Methods: Child management
  2833. //
  2834. //--------------------------------------------------------------------------
  2835. /**
  2836. * @private
  2837. */
  2838. override mx_internal function addingChild(child:DisplayObject):void
  2839. {
  2840. // Throw an RTE if child is not an IUIComponent.
  2841. var uiChild:IUIComponent = IUIComponent(child);
  2842. // Set the child's virtual parent, nestLevel, document, etc.
  2843. super.addingChild(child);
  2844. invalidateSize();
  2845. invalidateDisplayList();
  2846. if (!contentPane)
  2847. {
  2848. // If this is the first content child, then any chrome
  2849. // that already exists is positioned in front of it.
  2850. // If other content children already existed, then set the
  2851. // depth of this object to be just behind the existing
  2852. // content children.
  2853. if (_numChildren == 0)
  2854. _firstChildIndex = super.numChildren;
  2855. // Increment the number of content children.
  2856. _numChildren++;
  2857. }
  2858. if (contentPane && !autoLayout)
  2859. {
  2860. forceLayout = true;
  2861. // weak reference
  2862. UIComponentGlobals.layoutManager.addEventListener(
  2863. FlexEvent.UPDATE_COMPLETE, layoutCompleteHandler, false, 0, true);
  2864. }
  2865. }
  2866. /**
  2867. * @private
  2868. */
  2869. override mx_internal function childAdded(child:DisplayObject):void
  2870. {
  2871. dispatchEvent(new Event("childrenChanged"));
  2872. var event:ChildExistenceChangedEvent =
  2873. new ChildExistenceChangedEvent(
  2874. ChildExistenceChangedEvent.CHILD_ADD);
  2875. event.relatedObject = child;
  2876. dispatchEvent(event);
  2877. child.dispatchEvent(new FlexEvent(FlexEvent.ADD));
  2878. super.childAdded(child); // calls createChildren()
  2879. }
  2880. /**
  2881. * @private
  2882. */
  2883. override mx_internal function removingChild(child:DisplayObject):void
  2884. {
  2885. super.removingChild(child);
  2886. child.dispatchEvent(new FlexEvent(FlexEvent.REMOVE));
  2887. var event:ChildExistenceChangedEvent =
  2888. new ChildExistenceChangedEvent(
  2889. ChildExistenceChangedEvent.CHILD_REMOVE);
  2890. event.relatedObject = child;
  2891. dispatchEvent(event);
  2892. }
  2893. /**
  2894. * @private
  2895. */
  2896. override mx_internal function childRemoved(child:DisplayObject):void
  2897. {
  2898. super.childRemoved(child);
  2899. invalidateSize();
  2900. invalidateDisplayList();
  2901. if (!contentPane)
  2902. {
  2903. _numChildren--;
  2904. if (_numChildren == 0)
  2905. _firstChildIndex = super.numChildren;
  2906. }
  2907. if (contentPane && !autoLayout)
  2908. {
  2909. forceLayout = true;
  2910. // weak reference
  2911. UIComponentGlobals.layoutManager.addEventListener(
  2912. FlexEvent.UPDATE_COMPLETE, layoutCompleteHandler, false, 0, true);
  2913. }
  2914. dispatchEvent(new Event("childrenChanged"));
  2915. }
  2916. [Bindable("childrenChanged")]
  2917. /**
  2918. * Returns an Array of DisplayObject objects consisting of the content children
  2919. * of the container.
  2920. * This array does <b>not</b> include the DisplayObjects that implement
  2921. * the container's display elements, such as its border and
  2922. * the background image.
  2923. *
  2924. * @return Array of DisplayObject objects consisting of the content children
  2925. * of the container.
  2926. *
  2927. * @see #rawChildren
  2928. */
  2929. public function getChildren():Array
  2930. {
  2931. var results:Array = [];
  2932. var n:int = numChildren;
  2933. for (var i:int = 0; i < n; i++)
  2934. {
  2935. results.push(getChildAt(i));
  2936. }
  2937. return results;
  2938. }
  2939. /**
  2940. * Removes all children from the child list of this container.
  2941. */
  2942. public function removeAllChildren():void
  2943. {
  2944. while (numChildren > 0)
  2945. {
  2946. removeChildAt(0);
  2947. }
  2948. }
  2949. //--------------------------------------------------------------------------
  2950. //
  2951. // Methods: Deferred instantiation
  2952. //
  2953. //--------------------------------------------------------------------------
  2954. /**
  2955. * @private
  2956. * For containers, we need to ensure that at most one set of children
  2957. * has been specified for the component.
  2958. * There are two ways to specify multiple sets of children:
  2959. * a) the component itself, as well as an instance of the component,
  2960. * might specify children;
  2961. * b) both a base and derived component might specify children.
  2962. * Case (a) is handled in initialize(), above.
  2963. * Case (b) is handled here.
  2964. * This method is called in overrides of initialize()
  2965. * that are generated for MXML components.
  2966. */
  2967. mx_internal function setDocumentDescriptor(desc:UIComponentDescriptor):void
  2968. {
  2969. if (processedDescriptors)
  2970. return;
  2971. if (_documentDescriptor && _documentDescriptor.properties.childDescriptors)
  2972. {
  2973. if (desc.properties.childDescriptors)
  2974. {
  2975. var message:String = resourceManager.getString(
  2976. "core", "multipleChildSets_ClassAndSubclass");
  2977. throw new Error(message);
  2978. }
  2979. }
  2980. else
  2981. {
  2982. _documentDescriptor = desc;
  2983. _documentDescriptor.document = this;
  2984. }
  2985. }
  2986. /**
  2987. * @private
  2988. * Used by subclasses, so must be public.
  2989. */
  2990. mx_internal function setActualCreationPolicies(policy:String):void
  2991. {
  2992. actualCreationPolicy = policy;
  2993. // Recursively set the actualCreationPolicy of all descendant
  2994. // containers which have an undefined creationPolicy.
  2995. var childPolicy:String = policy;
  2996. if (policy == ContainerCreationPolicy.QUEUED)
  2997. childPolicy = ContainerCreationPolicy.AUTO;
  2998. //trace("setActualCreationPolicies policy", policy, "childPolicy", childPolicy);
  2999. var n:int = numChildren;
  3000. for (var i:int = 0; i < n; i++)
  3001. {
  3002. var child:IFlexDisplayObject = IFlexDisplayObject(getChildAt(i));
  3003. if (child is Container)
  3004. {
  3005. var childContainer:Container = Container(child);
  3006. if (childContainer.creationPolicy == null)
  3007. childContainer.setActualCreationPolicies(childPolicy);
  3008. }
  3009. }
  3010. }
  3011. /**
  3012. * Iterate through the Array of <code>childDescriptors</code>,
  3013. * and call the <code>createComponentFromDescriptor()</code> method for each one.
  3014. *
  3015. * <p>If the value of the container's <code>creationPolicy</code> property is
  3016. * <code>ContainerCreationPolicy.ALL</code>, then this method is called
  3017. * automatically during the initialization sequence.</p>
  3018. *
  3019. * <p>If the value of the container's <code>creationPolicy</code> is
  3020. * <code>ContainerCreationPolicy.AUTO</code>,
  3021. * then this method is called automatically when the
  3022. * container's children are about to become visible.</p>
  3023. *
  3024. * <p>If the value of the container's <code>creationPolicy</code> property is
  3025. * <code>ContainerCreationPolicy.NONE</code>,
  3026. * then you should call this function
  3027. * when you want to create this container's children.</p>
  3028. *
  3029. * @param recurse If <code>true</code>, recursively
  3030. * create components.
  3031. */
  3032. public function createComponentsFromDescriptors(
  3033. recurse:Boolean = true):void
  3034. {
  3035. numChildrenBefore = numChildren;
  3036. createdComponents = [];
  3037. var n:int = childDescriptors ? childDescriptors.length : 0;
  3038. for (var i:int = 0; i < n; i++)
  3039. {
  3040. var component:IFlexDisplayObject =
  3041. createComponentFromDescriptor(childDescriptors[i], recurse);
  3042. createdComponents.push(component);
  3043. }
  3044. if (creationPolicy == ContainerCreationPolicy.QUEUED ||
  3045. creationPolicy == ContainerCreationPolicy.NONE)
  3046. {
  3047. UIComponentGlobals.layoutManager.usePhasedInstantiation = false;
  3048. }
  3049. numChildrenCreated = numChildren - numChildrenBefore;
  3050. processedDescriptors = true;
  3051. }
  3052. /**
  3053. * Given a single UIComponentDescriptor, create the corresponding
  3054. * component and add the component as a child of this Container.
  3055. *
  3056. * <p>This method instantiates the new object but does not add it to the display list, so the object does not
  3057. * appear on the screen by default. To add the new object to the display list, call the <code>validateNow()</code>
  3058. * method on the container after calling the <code>createComponentFromDescriptor()</code> method,
  3059. * as the following example shows:
  3060. * <pre>
  3061. * myVBox.createComponentFromDescriptor(myVBox.childDescriptors[0],false);
  3062. * myVBox.validateNow();
  3063. * </pre>
  3064. * </p>
  3065. *
  3066. * <p>Alternatively, you can call the <code>createComponentsFromDescriptors()</code> method on the
  3067. * container to create all components at one time. You are not required to call the <code>validateNow()</code>
  3068. * method after calling the <code>createComponentsFromDescriptors()</code> method.</p>
  3069. *
  3070. *
  3071. * @param descriptorOrIndex The UIComponentDescriptor for the
  3072. * component to be created. This argument is either a
  3073. * UIComponentDescriptor object or the index of one of the container's
  3074. * children (an integer between 0 and n-1, where n is the total
  3075. * number of children of this container).
  3076. *
  3077. * @param recurse If <code>false</code>, create this component
  3078. * but none of its children.
  3079. * If <code>true</code>, after creating the component, Flex calls
  3080. * the <code>createComponentsFromDescriptors()</code> method to create all or some
  3081. * of its children, based on the value of the component's <code>creationPolicy</code> property.
  3082. *
  3083. * @see mx.core.UIComponentDescriptor
  3084. */
  3085. public function createComponentFromDescriptor(
  3086. descriptor:ComponentDescriptor,
  3087. recurse:Boolean):IFlexDisplayObject
  3088. {
  3089. // If recurse is 'false', we create this component but none
  3090. // of its children.
  3091. // If recurse is 'true', after creating the component we call
  3092. // createComponentsFromDescriptors() to create all or some
  3093. // of its children, based on the component's
  3094. // actualContainerCreationPolicy.
  3095. var childDescriptor:UIComponentDescriptor =
  3096. UIComponentDescriptor(descriptor);
  3097. var childProperties:Object = childDescriptor.properties;
  3098. // This function could be asked to create the same child component
  3099. // twice. That's fine if the child component is inside a repeater.
  3100. // In other cases, though, we want to avoid creating the same child
  3101. // twice.
  3102. //
  3103. // The hasChildMatchingDescriptor function is a bit expensive, so
  3104. // we try to avoid calling it if we know we're inside the first call
  3105. // to createComponents.
  3106. if ((numChildrenBefore != 0 || numChildrenCreated != -1) &&
  3107. childDescriptor.instanceIndices == null &&
  3108. hasChildMatchingDescriptor(childDescriptor))
  3109. {
  3110. return null;
  3111. }
  3112. // Turn on the three-frame instantiation scheme.
  3113. UIComponentGlobals.layoutManager.usePhasedInstantiation = true;
  3114. // Create the new child object and give it a unique name
  3115. var childType:Class = childDescriptor.type;
  3116. var child:IDeferredInstantiationUIComponent = new childType();
  3117. child.id = childDescriptor.id;
  3118. if (child.id && child.id != "")
  3119. child.name = child.id;
  3120. // Copy property values from the descriptor
  3121. // to the newly created component.
  3122. child.descriptor = childDescriptor;
  3123. if (childProperties.childDescriptors && child is Container)
  3124. {
  3125. Container(child)._childDescriptors =
  3126. childProperties.childDescriptors;
  3127. delete childProperties.childDescriptors;
  3128. }
  3129. for (var p:String in childProperties)
  3130. {
  3131. child[p] = childProperties[p];
  3132. }
  3133. // Set a flag indicating whether we should call
  3134. // this function recursively.
  3135. if (child is Container)
  3136. Container(child).recursionFlag = recurse;
  3137. if (childDescriptor.instanceIndices)
  3138. {
  3139. if (child is IRepeaterClient)
  3140. {
  3141. var rChild:IRepeaterClient = IRepeaterClient(child);
  3142. rChild.instanceIndices = childDescriptor.instanceIndices;
  3143. rChild.repeaters = childDescriptor.repeaters;
  3144. rChild.repeaterIndices = childDescriptor.repeaterIndices;
  3145. }
  3146. }
  3147. if (child is IStyleClient)
  3148. {
  3149. var scChild:IStyleClient = IStyleClient(child);
  3150. // Initialize the CSSStyleDeclaration.
  3151. // It is used by initProtoChain(), which is called by addChild().
  3152. if (childDescriptor.stylesFactory != null)
  3153. {
  3154. if (!scChild.styleDeclaration)
  3155. scChild.styleDeclaration = new CSSStyleDeclaration();
  3156. scChild.styleDeclaration.factory =
  3157. childDescriptor.stylesFactory;
  3158. }
  3159. }
  3160. // For each event, register the handle method, which is specified in
  3161. // the descriptor by name, as one of the child's event listeners.
  3162. var childEvents:Object = childDescriptor.events;
  3163. if (childEvents)
  3164. {
  3165. for (var eventName:String in childEvents)
  3166. {
  3167. var eventHandler:String = childEvents[eventName];
  3168. child.addEventListener(eventName,
  3169. childDescriptor.document[eventHandler]);
  3170. }
  3171. }
  3172. // For each effect, register the EffectManager as an event listener
  3173. var childEffects:Array = childDescriptor.effects;
  3174. if (childEffects)
  3175. child.registerEffects(childEffects);
  3176. if (child is IRepeaterClient)
  3177. IRepeaterClient(child).initializeRepeaterArrays(this);
  3178. // If an MXML id was specified, create a property with this name on
  3179. // the MXML document object whose value references the child.
  3180. // This should be the last step in initializing the child, so that
  3181. // it can't be referenced until initialization is complete.
  3182. // However, it must be done before executing executeBindings().
  3183. child.createReferenceOnParentDocument(
  3184. IFlexDisplayObject(childDescriptor.document));
  3185. if (!child.document)
  3186. child.document = childDescriptor.document;
  3187. // Repeaters don't get added as children of the Container,
  3188. // so they have their own initialization sequence.
  3189. if (child is IRepeater)
  3190. {
  3191. // Add this repeater to the list maintained by the parent
  3192. // container
  3193. if (!childRepeaters)
  3194. childRepeaters = [];
  3195. childRepeaters.push(child);
  3196. // The Binding Manager may have some data that it wants to bind to
  3197. // various properties of the newly created repeater.
  3198. child.executeBindings();
  3199. IRepeater(child).initializeRepeater(this, recurse);
  3200. }
  3201. else
  3202. {
  3203. // This needs to run before child.executeBindings(), because
  3204. // executeBindings() depends on the parent being set.
  3205. addChild(DisplayObject(child));
  3206. child.executeBindings();
  3207. if (creationPolicy == ContainerCreationPolicy.QUEUED ||
  3208. creationPolicy == ContainerCreationPolicy.NONE)
  3209. {
  3210. child.addEventListener(FlexEvent.CREATION_COMPLETE,
  3211. creationCompleteHandler);
  3212. }
  3213. }
  3214. // Return a reference to the child UIComponent that was just created.
  3215. return child;
  3216. }
  3217. /**
  3218. * @private
  3219. */
  3220. private function hasChildMatchingDescriptor(
  3221. descriptor:UIComponentDescriptor):Boolean
  3222. {
  3223. // Optimization: If the descriptor has an id but no such id
  3224. // reference exists on the document, then there are no children
  3225. // in this container with that descriptor.
  3226. // (On the other hand, if there IS an id reference on the document,
  3227. // we can't be sure that it is for a child of this container. It
  3228. // could be an indexed reference in which some instances are
  3229. // in other containers. This happens when you have
  3230. // <Repeater>
  3231. // <VBox>
  3232. // <Button>
  3233. var id:String = descriptor.id;
  3234. if (id != null && document[id] == null)
  3235. return false;
  3236. var n:int = numChildren;
  3237. var i:int;
  3238. // Iterate over this container's children, looking for one
  3239. // that matches this descriptor
  3240. for (i = 0; i < n; i++)
  3241. {
  3242. var child:IUIComponent = IUIComponent(getChildAt(i));
  3243. if (child is IDeferredInstantiationUIComponent &&
  3244. IDeferredInstantiationUIComponent(child)
  3245. .descriptor == descriptor)
  3246. {
  3247. return true;
  3248. }
  3249. }
  3250. // Also check this container's Repeaters, if there are any.
  3251. if (childRepeaters)
  3252. {
  3253. n = childRepeaters.length;
  3254. for (i = 0; i < n; i++)
  3255. {
  3256. if (IDeferredInstantiationUIComponent(childRepeaters[i])
  3257. .descriptor == descriptor)
  3258. {
  3259. return true;
  3260. }
  3261. }
  3262. }
  3263. return false;
  3264. }
  3265. //--------------------------------------------------------------------------
  3266. //
  3267. // Methods: Support for rawChildren access
  3268. //
  3269. //--------------------------------------------------------------------------
  3270. /**
  3271. * @private
  3272. * This class overrides addChild() to deal with only content children,
  3273. * so in order to implement the rawChildren property we need
  3274. * a parallel method that deals with all children.
  3275. */
  3276. mx_internal function rawChildren_addChild(child:DisplayObject):DisplayObject
  3277. {
  3278. // This method is only used to implement rawChildren.addChild(),
  3279. // so the child being added is assumed to be a non-content child.
  3280. // (You would use just addChild() to add a content child.)
  3281. // If there are no content children, the new child is placed
  3282. // in the pre-content partition.
  3283. // If there are content children, the new child is placed
  3284. // in the post-content partition.
  3285. if (_numChildren == 0)
  3286. _firstChildIndex++;
  3287. super.addingChild(child);
  3288. $addChild(child);
  3289. super.childAdded(child);
  3290. dispatchEvent(new Event("childrenChanged"));
  3291. return child;
  3292. }
  3293. /**
  3294. * @private
  3295. * This class overrides addChildAt() to deal with only content children,
  3296. * so in order to implement the rawChildren property we need
  3297. * a parallel method that deals with all children.
  3298. */
  3299. mx_internal function rawChildren_addChildAt(child:DisplayObject,
  3300. index:int):DisplayObject
  3301. {
  3302. if (_firstChildIndex < index &&
  3303. index < _firstChildIndex + _numChildren + 1)
  3304. {
  3305. _numChildren++;
  3306. }
  3307. else if (index <= _firstChildIndex)
  3308. {
  3309. _firstChildIndex++;
  3310. }
  3311. super.addingChild(child);
  3312. $addChildAt(child, index);
  3313. super.childAdded(child);
  3314. dispatchEvent(new Event("childrenChanged"));
  3315. return child;
  3316. }
  3317. /**
  3318. * @private
  3319. * This class overrides removeChild() to deal with only content children,
  3320. * so in order to implement the rawChildren property we need
  3321. * a parallel method that deals with all children.
  3322. */
  3323. mx_internal function rawChildren_removeChild(
  3324. child:DisplayObject):DisplayObject
  3325. {
  3326. var index:int = rawChildren_getChildIndex(child);
  3327. return rawChildren_removeChildAt(index);
  3328. }
  3329. /**
  3330. * @private
  3331. * This class overrides removeChildAt() to deal with only content children,
  3332. * so in order to implement the rawChildren property we need
  3333. * a parallel method that deals with all children.
  3334. */
  3335. mx_internal function rawChildren_removeChildAt(index:int):DisplayObject
  3336. {
  3337. var child:DisplayObject = super.getChildAt(index);
  3338. super.removingChild(child);
  3339. $removeChildAt(index);
  3340. super.childRemoved(child);
  3341. if (_firstChildIndex < index &&
  3342. index < _firstChildIndex + _numChildren)
  3343. {
  3344. _numChildren--;
  3345. }
  3346. else if (_numChildren == 0 || index < _firstChildIndex)
  3347. {
  3348. _firstChildIndex--;
  3349. }
  3350. invalidateSize();
  3351. invalidateDisplayList();
  3352. dispatchEvent(new Event("childrenChanged"));
  3353. return child;
  3354. }
  3355. /**
  3356. * @private
  3357. * This class overrides getChildAt() to deal with only content children,
  3358. * so in order to implement the rawChildren property we need
  3359. * a parallel method that deals with all children.
  3360. */
  3361. mx_internal function rawChildren_getChildAt(index:int):DisplayObject
  3362. {
  3363. return super.getChildAt(index);
  3364. }
  3365. /**
  3366. * @private
  3367. * This class overrides getChildByName() to deal with only content children,
  3368. * so in order to implement the rawChildren property we need
  3369. * a parallel method that deals with all children.
  3370. */
  3371. mx_internal function rawChildren_getChildByName(name:String):DisplayObject
  3372. {
  3373. return super.getChildByName(name);
  3374. }
  3375. /**
  3376. * @private
  3377. * This class overrides getChildIndex() to deal with only content children,
  3378. * so in order to implement the rawChildren property we need
  3379. * a parallel method that deals with all children.
  3380. */
  3381. mx_internal function rawChildren_getChildIndex(child:DisplayObject):int
  3382. {
  3383. return super.getChildIndex(child);
  3384. }
  3385. /**
  3386. * @private
  3387. * This class overrides setChildIndex() to deal with only content children,
  3388. * so in order to implement the rawChildren property we need
  3389. * a parallel method that deals with all children.
  3390. */
  3391. mx_internal function rawChildren_setChildIndex(child:DisplayObject,
  3392. newIndex:int):void
  3393. {
  3394. var oldIndex:int = super.getChildIndex(child);
  3395. super.setChildIndex(child, newIndex);
  3396. // Is this a piece of chrome that was previously before
  3397. // the content children and is now after them in the list?
  3398. if (oldIndex < _firstChildIndex && newIndex >= _firstChildIndex)
  3399. {
  3400. _firstChildIndex--;
  3401. }
  3402. // Is this a piece of chrome that was previously after
  3403. // the content children and is now before them in the list?
  3404. else if (oldIndex >= _firstChildIndex && newIndex <= _firstChildIndex)
  3405. {
  3406. _firstChildIndex++
  3407. }
  3408. dispatchEvent(new Event("childrenChanged"));
  3409. }
  3410. /**
  3411. * @private
  3412. * This class overrides getObjectsUnderPoint() to deal with only content children,
  3413. * so in order to implement the rawChildren property we need
  3414. * a parallel method that deals with all children.
  3415. */
  3416. mx_internal function rawChildren_getObjectsUnderPoint(pt:Point):Array
  3417. {
  3418. return super.getObjectsUnderPoint(pt);
  3419. }
  3420. /**
  3421. * @private
  3422. * This class overrides contains() to deal with only content children,
  3423. * so in order to implement the rawChildren property we need
  3424. * a parallel method that deals with all children.
  3425. */
  3426. mx_internal function rawChildren_contains(child:DisplayObject):Boolean
  3427. {
  3428. return super.contains(child);
  3429. }
  3430. //--------------------------------------------------------------------------
  3431. //
  3432. // Methods: Chrome management
  3433. //
  3434. //--------------------------------------------------------------------------
  3435. /**
  3436. * Respond to size changes by setting the positions and sizes
  3437. * of this container's borders.
  3438. * This is an advanced method that you might override
  3439. * when creating a subclass of Container.
  3440. *
  3441. * <p>Flex calls the <code>layoutChrome()</code> method when the
  3442. * container is added to a parent container using the <code>addChild()</code> method,
  3443. * and when the container's <code>invalidateDisplayList()</code> method is called.</p>
  3444. *
  3445. * <p>The <code>Container.layoutChrome()</code> method is called regardless of the
  3446. * value of the <code>autoLayout</code> property.</p>
  3447. *
  3448. * <p>The <code>Container.layoutChrome()</code> method sets the
  3449. * position and size of the Container container's border.
  3450. * In every subclass of Container, the subclass's <code>layoutChrome()</code>
  3451. * method should call the <code>super.layoutChrome()</code> method,
  3452. * so that the border is positioned properly.</p>
  3453. *
  3454. * @param unscaledWidth Specifies the width of the component, in pixels,
  3455. * in the component's coordinates, regardless of the value of the
  3456. * <code>scaleX</code> property of the component.
  3457. *
  3458. * @param unscaledHeight Specifies the height of the component, in pixels,
  3459. * in the component's coordinates, regardless of the value of the
  3460. * <code>scaleY</code> property of the component.
  3461. */
  3462. protected function layoutChrome(unscaledWidth:Number,
  3463. unscaledHeight:Number):void
  3464. {
  3465. // Border covers the whole thing.
  3466. if (border)
  3467. {
  3468. updateBackgroundImageRect();
  3469. border.move(0, 0);
  3470. border.setActualSize(unscaledWidth, unscaledHeight);
  3471. }
  3472. }
  3473. /**
  3474. * Creates the container's border skin
  3475. * if it is needed and does not already exist.
  3476. */
  3477. protected function createBorder():void
  3478. {
  3479. if (!border && isBorderNeeded())
  3480. {
  3481. var borderClass:Class = getStyle("borderSkin");
  3482. if (borderClass != null)
  3483. {
  3484. border = new borderClass();
  3485. border.name = "border";
  3486. if (border is IUIComponent)
  3487. IUIComponent(border).enabled = enabled;
  3488. if (border is ISimpleStyleClient)
  3489. ISimpleStyleClient(border).styleName = this;
  3490. // Add the border behind all the children.
  3491. rawChildren.addChildAt(DisplayObject(border), 0);
  3492. invalidateDisplayList();
  3493. }
  3494. }
  3495. }
  3496. /**
  3497. * @private
  3498. */
  3499. private function isBorderNeeded():Boolean
  3500. {
  3501. //trace("isBorderNeeded",this,"ms",getStyle("mouseShield"),"borderStyle",getStyle("borderStyle"));
  3502. // If the borderSkin is a custom class, always assume the border is needed.
  3503. var c:Class = getStyle("borderSkin");
  3504. // Lookup the HaloBorder class by name to avoid a linkage dependency.
  3505. // Note: this code assumes HaloBorder is the default border skin. If this is changed
  3506. // in defaults.css, it must also be changed here.
  3507. try
  3508. {
  3509. if (c != getDefinitionByName("mx.skins.halo::HaloBorder"))
  3510. return true;
  3511. }
  3512. catch(e:Error)
  3513. {
  3514. return true;
  3515. }
  3516. var v:Object = getStyle("borderStyle");
  3517. if (v)
  3518. {
  3519. // If borderStyle is "none", then only create a border if the mouseShield style is true
  3520. // (meaning that there is a mouse event listener on this view). We don't create a border
  3521. // if our parent's mouseShieldChildren style is true.
  3522. if ((v != "none") || (v == "none" && getStyle("mouseShield")))
  3523. {
  3524. return true;
  3525. }
  3526. }
  3527. v = getStyle("backgroundColor");
  3528. if (v !== null && v !== "")
  3529. return true;
  3530. v = getStyle("backgroundImage");
  3531. return v != null && v != "";
  3532. }
  3533. /**
  3534. * @private
  3535. */
  3536. mx_internal function invalidateViewMetricsAndPadding():void
  3537. {
  3538. _viewMetricsAndPadding = null;
  3539. }
  3540. /**
  3541. * @private
  3542. */
  3543. private function createOrDestroyBlocker():void
  3544. {
  3545. // If this container is being enabled and a blocker exists,
  3546. // remove it. If this container is being disabled and a
  3547. // blocker doesn't exist, create it.
  3548. if (enabled)
  3549. {
  3550. if (blocker)
  3551. {
  3552. rawChildren.removeChild(blocker);
  3553. blocker = null;
  3554. }
  3555. }
  3556. else
  3557. {
  3558. if (!blocker)
  3559. {
  3560. blocker = new FlexSprite();
  3561. blocker.name = "blocker";
  3562. blocker.mouseEnabled = true;
  3563. rawChildren.addChild(blocker);
  3564. blocker.addEventListener(MouseEvent.CLICK,
  3565. blocker_clickHandler);
  3566. // If the focus is a child of ours, we clear it here.
  3567. var o:DisplayObject =
  3568. focusManager ?
  3569. DisplayObject(focusManager.getFocus()) :
  3570. null;
  3571. while (o)
  3572. {
  3573. if (o == this)
  3574. {
  3575. var sm:ISystemManager = systemManager;
  3576. if (sm && sm.stage)
  3577. sm.stage.focus = null;
  3578. break;
  3579. }
  3580. o = o.parent;
  3581. }
  3582. }
  3583. }
  3584. }
  3585. /**
  3586. * @private
  3587. */
  3588. private function updateBackgroundImageRect():void
  3589. {
  3590. var rectBorder:IRectangularBorder = border as IRectangularBorder;
  3591. if (!rectBorder)
  3592. return;
  3593. // If viewableWidth and viewableHeight are 0, we don't have any
  3594. // scrollbars or clipped content.
  3595. if (viewableWidth == 0 && viewableHeight == 0)
  3596. {
  3597. rectBorder.backgroundImageBounds = null;
  3598. return;
  3599. }
  3600. var vm:EdgeMetrics = viewMetrics;
  3601. var bkWidth:Number = viewableWidth ? viewableWidth :
  3602. unscaledWidth - vm.left - vm.right;
  3603. var bkHeight:Number = viewableHeight ? viewableHeight :
  3604. unscaledHeight - vm.top - vm.bottom;
  3605. if (getStyle("backgroundAttachment") == "fixed")
  3606. {
  3607. rectBorder.backgroundImageBounds = new Rectangle(vm.left, vm.top,
  3608. bkWidth, bkHeight);
  3609. }
  3610. else
  3611. {
  3612. rectBorder.backgroundImageBounds = new Rectangle(vm.left, vm.top,
  3613. Math.max(scrollableWidth, bkWidth),
  3614. Math.max(scrollableHeight, bkHeight));
  3615. }
  3616. }
  3617. //--------------------------------------------------------------------------
  3618. //
  3619. // Methods: Scrolling
  3620. //
  3621. //--------------------------------------------------------------------------
  3622. /**
  3623. * @private
  3624. */
  3625. private function createContentPaneAndScrollbarsIfNeeded():Boolean
  3626. {
  3627. var bounds:Rectangle;
  3628. var changed:Boolean;
  3629. // No mask is needed if clipping isn't active
  3630. if (_clipContent)
  3631. {
  3632. // Get the new scrollable width, which is the equal to the right
  3633. // edge of the rightmost child. Also get the new scrollable height.
  3634. bounds = getScrollableRect();
  3635. // Create or destroy scrollbars if necessary, and update the
  3636. // properties of the scrollbars.
  3637. changed = createScrollbarsIfNeeded(bounds);
  3638. if (border)
  3639. updateBackgroundImageRect();
  3640. return changed;
  3641. }
  3642. else
  3643. {
  3644. changed = createOrDestroyScrollbars(false, false, false);
  3645. // Get scrollableWidth and scrollableHeight for scrollChildren()
  3646. bounds = getScrollableRect();
  3647. scrollableWidth = bounds.right;
  3648. scrollableHeight = bounds.bottom;
  3649. if (changed && border)
  3650. updateBackgroundImageRect();
  3651. return changed;
  3652. }
  3653. }
  3654. /**
  3655. * @private
  3656. */
  3657. mx_internal function getScrollableRect():Rectangle
  3658. {
  3659. var left:Number = 0;
  3660. var top:Number = 0;
  3661. var right:Number = 0;
  3662. var bottom:Number = 0;
  3663. var n:int = numChildren;
  3664. for (var i:int = 0; i < n; i++)
  3665. {
  3666. var child:DisplayObject = getChildAt(i);
  3667. if (child is IUIComponent && !IUIComponent(child).includeInLayout)
  3668. continue;
  3669. left = Math.min(left, child.x);
  3670. top = Math.min(top, child.y);
  3671. // width/height can be NaN if using percentages and
  3672. // hasn't been layed out yet.
  3673. if (!isNaN(child.width))
  3674. right = Math.max(right, child.x + child.width);
  3675. if (!isNaN(child.height))
  3676. bottom = Math.max(bottom, child.y + child.height);
  3677. }
  3678. // Add in the right/bottom margins and view metrics.
  3679. var vm:EdgeMetrics = viewMetrics;
  3680. var bounds:Rectangle = new Rectangle();
  3681. bounds.left = left;
  3682. bounds.top = top;
  3683. bounds.right = right;
  3684. bounds.bottom = bottom;
  3685. if (mx_internal::usePadding)
  3686. {
  3687. bounds.right += getStyle("paddingRight");
  3688. bounds.bottom += getStyle("paddingBottom");
  3689. }
  3690. return bounds;
  3691. }
  3692. /**
  3693. * @private
  3694. */
  3695. private function createScrollbarsIfNeeded(bounds:Rectangle):Boolean
  3696. {
  3697. var newScrollableWidth:Number = bounds.right;
  3698. var newScrollableHeight:Number = bounds.bottom;
  3699. var newViewableWidth:Number = unscaledWidth;
  3700. var newViewableHeight:Number = unscaledHeight;
  3701. var hasNegativeCoords:Boolean = bounds.left < 0 || bounds.top < 0;
  3702. var vm:EdgeMetrics = viewMetrics;
  3703. // Several of the layout managers round floating-point numbers
  3704. // down, using Math.floor().
  3705. // The rounded-down width value is passed to UIComponent.setActualSize,
  3706. // which does the following:
  3707. //
  3708. // unscaledWidth = w / scaleX
  3709. //
  3710. // Suppose "w" was originally 91.9 but the layout manager
  3711. // rounded it down to 91. Suppose scaleX is 0.01.
  3712. // Then unscaledWidth is 91/0.01 = 9100, but it would have been
  3713. // 91.9/0.01 = 9190 if it weren't for the rounding.
  3714. // To undo the effect of the rounding, we'll add a fudge factor to
  3715. // newViewableWidth. That way, we don't display unwanted scrollbars.
  3716. if (scaleX != 1.0)
  3717. newViewableWidth += 1.0 / Math.abs(scaleX);
  3718. if (scaleY != 1.0)
  3719. newViewableHeight += 1.0 / Math.abs(scaleY);
  3720. newViewableWidth = Math.floor(newViewableWidth);
  3721. newViewableHeight = Math.floor(newViewableHeight);
  3722. newScrollableWidth = Math.floor(newScrollableWidth);
  3723. newScrollableHeight = Math.floor(newScrollableHeight);
  3724. if (horizontalScrollBar && horizontalScrollPolicy != ScrollPolicy.ON)
  3725. newViewableHeight -= horizontalScrollBar.minHeight;
  3726. if (verticalScrollBar && verticalScrollPolicy != ScrollPolicy.ON)
  3727. newViewableWidth -= verticalScrollBar.minWidth;
  3728. newViewableWidth -= (vm.left + vm.right);
  3729. newViewableHeight -= (vm.top + vm.bottom);
  3730. var needHorizontal:Boolean =
  3731. horizontalScrollPolicy == ScrollPolicy.ON;
  3732. var needVertical:Boolean =
  3733. verticalScrollPolicy == ScrollPolicy.ON;
  3734. var needContentPane:Boolean =
  3735. needHorizontal ||
  3736. needVertical ||
  3737. hasNegativeCoords ||
  3738. overlay != null ||
  3739. vm.left > 0 ||
  3740. vm.top > 0;
  3741. // These "if" statements are tuned for the most common case,
  3742. // which is that the Container does not need scrollbars.
  3743. if (newViewableWidth < newScrollableWidth)
  3744. {
  3745. needContentPane = true;
  3746. // Don't display scrollbars if the Container is so small
  3747. // that scrollbars would occlude everything else
  3748. // or the scrollbar buttons would overlap.
  3749. if (horizontalScrollPolicy == ScrollPolicy.AUTO &&
  3750. unscaledHeight - vm.top - vm.bottom >= 18 &&
  3751. unscaledWidth - vm.left - vm.right >= 32)
  3752. {
  3753. needHorizontal = true;
  3754. }
  3755. }
  3756. if (newViewableHeight < newScrollableHeight)
  3757. {
  3758. needContentPane = true;
  3759. if (verticalScrollPolicy == ScrollPolicy.AUTO &&
  3760. unscaledWidth - vm.left - vm.right >= 18 &&
  3761. unscaledHeight - vm.top - vm.bottom >= 32)
  3762. {
  3763. needVertical = true;
  3764. }
  3765. }
  3766. // Fix for 106095. The logic here says "if removing the scrollbars
  3767. // would make enough room to display the view's children, then remove
  3768. // the scrollbars".
  3769. if (needHorizontal &&
  3770. needVertical &&
  3771. horizontalScrollPolicy == ScrollPolicy.AUTO &&
  3772. verticalScrollPolicy == ScrollPolicy.AUTO &&
  3773. horizontalScrollBar &&
  3774. verticalScrollBar &&
  3775. newViewableWidth + verticalScrollBar.minWidth >= newScrollableWidth &&
  3776. newViewableHeight + horizontalScrollBar.minHeight >= newScrollableHeight)
  3777. {
  3778. needHorizontal = needVertical = false;
  3779. }
  3780. // If the vertical scrollbar is going to be removed anyway, and
  3781. // removing it would also free up enough space for the contents to fit
  3782. // horizontally, then there's no need for the horizontal scrollbar
  3783. // either.
  3784. else if (needHorizontal &&
  3785. !needVertical &&
  3786. verticalScrollBar &&
  3787. horizontalScrollPolicy == ScrollPolicy.AUTO &&
  3788. newViewableWidth + verticalScrollBar.minWidth >= newScrollableWidth)
  3789. {
  3790. needHorizontal = false;
  3791. }
  3792. var changed:Boolean = createOrDestroyScrollbars(
  3793. needHorizontal, needVertical, needContentPane);
  3794. if ((scrollableWidth != newScrollableWidth ||
  3795. viewableWidth != newViewableWidth) ||
  3796. changed)
  3797. {
  3798. if (horizontalScrollBar)
  3799. {
  3800. horizontalScrollBar.setScrollProperties(
  3801. newViewableWidth, 0,
  3802. newScrollableWidth - newViewableWidth, horizontalPageScrollSize);
  3803. scrollPositionChanged = true;
  3804. }
  3805. viewableWidth = newViewableWidth;
  3806. scrollableWidth = newScrollableWidth;
  3807. }
  3808. if ((scrollableHeight != newScrollableHeight ||
  3809. viewableHeight != newViewableHeight) ||
  3810. changed)
  3811. {
  3812. if (verticalScrollBar)
  3813. {
  3814. verticalScrollBar.setScrollProperties(
  3815. newViewableHeight, 0,
  3816. newScrollableHeight-newViewableHeight, verticalPageScrollSize);
  3817. scrollPositionChanged = true;
  3818. }
  3819. viewableHeight = newViewableHeight;
  3820. scrollableHeight = newScrollableHeight;
  3821. }
  3822. return changed;
  3823. }
  3824. /**
  3825. * @private
  3826. */
  3827. private function createOrDestroyScrollbars(
  3828. needHorizontal:Boolean,
  3829. needVertical:Boolean,
  3830. needContentPane:Boolean):Boolean
  3831. {
  3832. var changed:Boolean = false;
  3833. var fm:IFocusManager;
  3834. if (needHorizontal || needVertical || needContentPane)
  3835. createContentPane();
  3836. // Create or destroy horizontal scrollbar.
  3837. if (needHorizontal)
  3838. {
  3839. if (!horizontalScrollBar)
  3840. {
  3841. horizontalScrollBar = new HScrollBar();
  3842. horizontalScrollBar.name = "horizontalScrollBar";
  3843. var horizontalScrollBarStyleName:String =
  3844. getStyle("horizontalScrollBarStyleName");
  3845. if (horizontalScrollBarStyleName && horizontalScrollBar is ISimpleStyleClient)
  3846. ISimpleStyleClient(horizontalScrollBar).styleName = horizontalScrollBarStyleName;
  3847. rawChildren.addChild(DisplayObject(horizontalScrollBar));
  3848. horizontalScrollBar.lineScrollSize = horizontalLineScrollSize;
  3849. horizontalScrollBar.pageScrollSize = horizontalPageScrollSize;
  3850. horizontalScrollBar.addEventListener(ScrollEvent.SCROLL, horizontalScrollBar_scrollHandler);
  3851. horizontalScrollBar.enabled = enabled;
  3852. if (horizontalScrollBar is IInvalidating)
  3853. IInvalidating(horizontalScrollBar).validateNow();
  3854. invalidateDisplayList();
  3855. invalidateViewMetricsAndPadding();
  3856. changed = true;
  3857. if (!verticalScrollBar)
  3858. addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  3859. }
  3860. }
  3861. else
  3862. {
  3863. if (horizontalScrollBar)
  3864. {
  3865. horizontalScrollBar.removeEventListener(
  3866. ScrollEvent.SCROLL,
  3867. horizontalScrollBar_scrollHandler);
  3868. rawChildren.removeChild(DisplayObject(horizontalScrollBar));
  3869. horizontalScrollBar = null;
  3870. viewableWidth = scrollableWidth = 0;
  3871. if (_horizontalScrollPosition != 0)
  3872. {
  3873. _horizontalScrollPosition = 0;
  3874. scrollPositionChanged = true;
  3875. }
  3876. invalidateDisplayList();
  3877. invalidateViewMetricsAndPadding();
  3878. changed = true;
  3879. fm = focusManager;
  3880. if (!verticalScrollBar && (!fm || fm.getFocus() != this))
  3881. removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  3882. }
  3883. }
  3884. // Create or destroy vertical scrollbar.
  3885. if (needVertical)
  3886. {
  3887. if (!verticalScrollBar)
  3888. {
  3889. verticalScrollBar = new VScrollBar();
  3890. verticalScrollBar.name = "verticalScrollBar";
  3891. var verticalScrollBarStyleName:String =
  3892. getStyle("verticalScrollBarStyleName");
  3893. if (verticalScrollBarStyleName && verticalScrollBar is ISimpleStyleClient)
  3894. ISimpleStyleClient(verticalScrollBar).styleName = verticalScrollBarStyleName;
  3895. rawChildren.addChild(DisplayObject(verticalScrollBar));
  3896. verticalScrollBar.lineScrollSize = verticalLineScrollSize;
  3897. verticalScrollBar.pageScrollSize = verticalPageScrollSize;
  3898. verticalScrollBar.addEventListener(ScrollEvent.SCROLL, verticalScrollBar_scrollHandler);
  3899. verticalScrollBar.enabled = enabled;
  3900. if (verticalScrollBar is IInvalidating)
  3901. IInvalidating(verticalScrollBar).validateNow();
  3902. invalidateDisplayList();
  3903. invalidateViewMetricsAndPadding();
  3904. changed = true;
  3905. if (!horizontalScrollBar)
  3906. addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  3907. // Listen for "mouseWheel" events on myself or any of my children
  3908. addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
  3909. }
  3910. }
  3911. else
  3912. {
  3913. if (verticalScrollBar)
  3914. {
  3915. verticalScrollBar.removeEventListener(ScrollEvent.SCROLL, verticalScrollBar_scrollHandler);
  3916. rawChildren.removeChild(DisplayObject(verticalScrollBar));
  3917. verticalScrollBar = null;
  3918. viewableHeight = scrollableHeight = 0;
  3919. if (_verticalScrollPosition != 0)
  3920. {
  3921. _verticalScrollPosition = 0;
  3922. scrollPositionChanged = true;
  3923. }
  3924. invalidateDisplayList();
  3925. invalidateViewMetricsAndPadding();
  3926. changed = true;
  3927. fm = focusManager;
  3928. if (!horizontalScrollBar && (!fm || fm.getFocus() != this))
  3929. removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  3930. removeEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler);
  3931. }
  3932. }
  3933. // Create or destroy the whiteBox.
  3934. // If both scrollBars are active, there's an empty space
  3935. // between the two scrollBars in the lower right corner.
  3936. // The whiteBox fills that space, so that the container's
  3937. // children aren't visible when they scroll underneath.
  3938. if (horizontalScrollBar && verticalScrollBar)
  3939. {
  3940. if (!whiteBox)
  3941. {
  3942. whiteBox = new FlexShape();
  3943. whiteBox.name = "whiteBox";
  3944. var g:Graphics = whiteBox.graphics;
  3945. g.beginFill(0xFFFFFF);
  3946. g.drawRect(0, 0, verticalScrollBar.minWidth, horizontalScrollBar.minHeight);
  3947. g.endFill()
  3948. rawChildren.addChild(whiteBox);
  3949. }
  3950. }
  3951. else
  3952. {
  3953. if (whiteBox)
  3954. {
  3955. rawChildren.removeChild(whiteBox);
  3956. whiteBox = null;
  3957. }
  3958. }
  3959. return changed;
  3960. }
  3961. /**
  3962. * @private
  3963. * Ensures that horizontalScrollPosition is in the range
  3964. * from 0 through maxHorizontalScrollPosition and that
  3965. * verticalScrollPosition is in the range from 0 through
  3966. * maxVerticalScrollPosition.
  3967. * Returns true if either horizontalScrollPosition or
  3968. * verticalScrollPosition was changed to ensure this.
  3969. */
  3970. private function clampScrollPositions():Boolean
  3971. {
  3972. var changed:Boolean = false;
  3973. // Clamp horizontalScrollPosition to the range
  3974. // 0 through maxHorizontalScrollPosition.
  3975. // If horizontalScrollBar doesn't exist,
  3976. // maxHorizontalScrollPosition will be 0.
  3977. if (_horizontalScrollPosition < 0)
  3978. {
  3979. _horizontalScrollPosition = 0;
  3980. changed = true;
  3981. }
  3982. else if (_horizontalScrollPosition > maxHorizontalScrollPosition)
  3983. {
  3984. _horizontalScrollPosition = maxHorizontalScrollPosition;
  3985. changed = true;
  3986. }
  3987. // Set the position of the horizontal scrollbar's thumb.
  3988. if (horizontalScrollBar &&
  3989. horizontalScrollBar.scrollPosition != _horizontalScrollPosition)
  3990. {
  3991. horizontalScrollBar.scrollPosition = _horizontalScrollPosition;
  3992. }
  3993. // Clamp verticalScrollPosition to the range
  3994. // 0 through maxVerticalScrollPosition.
  3995. // If verticalScrollBar doesn't exist,
  3996. // maxVerticalScrollPosition will be 0.
  3997. if (_verticalScrollPosition < 0)
  3998. {
  3999. _verticalScrollPosition = 0;
  4000. changed = true;
  4001. }
  4002. else if (_verticalScrollPosition > maxVerticalScrollPosition)
  4003. {
  4004. _verticalScrollPosition = maxVerticalScrollPosition;
  4005. changed = true;
  4006. }
  4007. // Set the position of the vertical scrollbar's thumb.
  4008. if (verticalScrollBar &&
  4009. verticalScrollBar.scrollPosition != _verticalScrollPosition)
  4010. {
  4011. verticalScrollBar.scrollPosition = _verticalScrollPosition;
  4012. }
  4013. return changed;
  4014. }
  4015. /**
  4016. * @private
  4017. */
  4018. mx_internal function createContentPane():void
  4019. {
  4020. if (contentPane)
  4021. return;
  4022. creatingContentPane = true;
  4023. // Reparent the children. Get the number before we create contentPane
  4024. // because that changes logic of how many children we have
  4025. var n:int = numChildren;
  4026. var newPane:Sprite = new FlexSprite();
  4027. newPane.name = "contentPane";
  4028. newPane.tabChildren = true;
  4029. // Place content pane above border and background image but below
  4030. // all other chrome.
  4031. var childIndex:int;
  4032. if (border)
  4033. {
  4034. childIndex = rawChildren.getChildIndex(DisplayObject(border)) + 1;
  4035. if (border is IRectangularBorder && IRectangularBorder(border).hasBackgroundImage)
  4036. childIndex++;
  4037. }
  4038. else
  4039. {
  4040. childIndex = 0;
  4041. }
  4042. rawChildren.addChildAt(newPane, childIndex);
  4043. for (var i:int = 0; i < n; i++)
  4044. {
  4045. // use super because contentPane now exists and messes up getChildAt();
  4046. var child:IUIComponent =
  4047. IUIComponent(super.getChildAt(_firstChildIndex));
  4048. newPane.addChild(DisplayObject(child));
  4049. child.parentChanged(newPane);
  4050. _numChildren--; // required
  4051. }
  4052. contentPane = newPane;
  4053. creatingContentPane = false
  4054. // UIComponent sets $visible to false. If we don't make it true here,
  4055. // nothing shows up. Making this true should be harmless, as the
  4056. // container itself should be false, and so should all its children.
  4057. contentPane.visible = true;
  4058. }
  4059. /**
  4060. * Positions the container's content area relative to the viewable area
  4061. * based on the horizontalScrollPosition and verticalScrollPosition properties.
  4062. * Content that doesn't appear in the viewable area gets clipped.
  4063. * This method should be overridden by subclasses that have scrollable
  4064. * chrome in the content area.
  4065. */
  4066. protected function scrollChildren():void
  4067. {
  4068. if (!contentPane)
  4069. return;
  4070. var vm:EdgeMetrics = viewMetrics;
  4071. var x:Number = 0;
  4072. var y:Number = 0;
  4073. var w:Number = unscaledWidth - vm.left - vm.right;
  4074. var h:Number = unscaledHeight - vm.top - vm.bottom;
  4075. if (_clipContent)
  4076. {
  4077. x += _horizontalScrollPosition;
  4078. if (horizontalScrollBar)
  4079. w = viewableWidth;
  4080. y += _verticalScrollPosition;
  4081. if (verticalScrollBar)
  4082. h = viewableHeight;
  4083. }
  4084. else
  4085. {
  4086. w = scrollableWidth;
  4087. h = scrollableHeight;
  4088. }
  4089. // If we have enough space to display everything, don't set
  4090. // scrollRect.
  4091. var sr:Rectangle = getScrollableRect();
  4092. if (x == 0 && y == 0 // Not scrolled
  4093. && w >= sr.right && h >= sr.bottom && // Vertical content visible
  4094. sr.left >= 0 && sr.top >= 0 && _forceClippingCount <= 0) // No negative coordinates
  4095. {
  4096. contentPane.scrollRect = null;
  4097. contentPane.opaqueBackground = null;
  4098. contentPane.cacheAsBitmap = false;
  4099. }
  4100. else
  4101. {
  4102. contentPane.scrollRect = new Rectangle(x, y, w, h);
  4103. }
  4104. if (focusPane)
  4105. focusPane.scrollRect = contentPane.scrollRect;
  4106. if (border && border is IRectangularBorder &&
  4107. IRectangularBorder(border).hasBackgroundImage)
  4108. {
  4109. IRectangularBorder(border).layoutBackgroundImage();
  4110. }
  4111. }
  4112. /**
  4113. * @private
  4114. */
  4115. private function dispatchScrollEvent(direction:String,
  4116. oldPosition:Number,
  4117. newPosition:Number,
  4118. detail:String):void
  4119. {
  4120. var event:ScrollEvent = new ScrollEvent(ScrollEvent.SCROLL);
  4121. event.direction = direction;
  4122. event.position = newPosition;
  4123. event.delta = newPosition - oldPosition;
  4124. event.detail = detail;
  4125. dispatchEvent(event);
  4126. }
  4127. /**
  4128. * @private
  4129. * Used by a child component to force clipping during a Move effect
  4130. */
  4131. private var _forceClippingCount:int;
  4132. mx_internal function set forceClipping(value:Boolean):void
  4133. {
  4134. if (_clipContent) // Can only force clipping if clipContent == true
  4135. {
  4136. if (value)
  4137. _forceClippingCount++
  4138. else
  4139. _forceClippingCount--;
  4140. createContentPane();
  4141. scrollChildren();
  4142. }
  4143. }
  4144. //--------------------------------------------------------------------------
  4145. //
  4146. // Methods: Binding
  4147. //
  4148. //--------------------------------------------------------------------------
  4149. /**
  4150. * Executes the bindings into this Container's child UIComponent objects.
  4151. * Flex calls this method automatically once a Container has been created.
  4152. *
  4153. * @param recurse If <code>false</code>, then only execute the bindings
  4154. * on the immediate children of this Container.
  4155. * If <code>true</code>, then also execute the bindings on this
  4156. * container's grandchildren,
  4157. * great-grandchildren, and so on.
  4158. */
  4159. public function executeChildBindings(recurse:Boolean):void
  4160. {
  4161. var n:int = numChildren;
  4162. for (var i:int = 0; i < n; i++)
  4163. {
  4164. var child:IUIComponent = IUIComponent(getChildAt(i));
  4165. if (child is IDeferredInstantiationUIComponent)
  4166. {
  4167. IDeferredInstantiationUIComponent(child).
  4168. executeBindings(recurse);
  4169. }
  4170. }
  4171. }
  4172. //--------------------------------------------------------------------------
  4173. //
  4174. // Overridden event handlers
  4175. //
  4176. //--------------------------------------------------------------------------
  4177. /**
  4178. * @private
  4179. */
  4180. override protected function keyDownHandler(event:KeyboardEvent):void
  4181. {
  4182. // If a text field currently has focus, it is handling all arrow keys.
  4183. // We shouldn't also scroll this Container.
  4184. var focusObj:Object = getFocus();
  4185. if (focusObj is TextField)
  4186. return;
  4187. var direction:String;
  4188. var oldPos:Number;
  4189. if (verticalScrollBar)
  4190. {
  4191. direction = ScrollEventDirection.VERTICAL;
  4192. oldPos = verticalScrollPosition;
  4193. switch (event.keyCode)
  4194. {
  4195. case Keyboard.DOWN:
  4196. {
  4197. verticalScrollPosition += verticalLineScrollSize;
  4198. dispatchScrollEvent(direction, oldPos,
  4199. verticalScrollPosition,
  4200. ScrollEventDetail.LINE_DOWN);
  4201. event.stopPropagation();
  4202. break;
  4203. }
  4204. case Keyboard.UP:
  4205. {
  4206. verticalScrollPosition -= verticalLineScrollSize;
  4207. dispatchScrollEvent(direction, oldPos,
  4208. verticalScrollPosition,
  4209. ScrollEventDetail.LINE_UP);
  4210. event.stopPropagation();
  4211. break;
  4212. }
  4213. case Keyboard.PAGE_UP:
  4214. {
  4215. verticalScrollPosition -= verticalPageScrollSize;
  4216. dispatchScrollEvent(direction, oldPos,
  4217. verticalScrollPosition,
  4218. ScrollEventDetail.PAGE_UP);
  4219. event.stopPropagation();
  4220. break;
  4221. }
  4222. case Keyboard.PAGE_DOWN:
  4223. {
  4224. verticalScrollPosition += verticalPageScrollSize;
  4225. dispatchScrollEvent(direction, oldPos,
  4226. verticalScrollPosition,
  4227. ScrollEventDetail.PAGE_DOWN);
  4228. event.stopPropagation();
  4229. break;
  4230. }
  4231. case Keyboard.HOME:
  4232. {
  4233. verticalScrollPosition =
  4234. verticalScrollBar.minScrollPosition;
  4235. dispatchScrollEvent(direction, oldPos,
  4236. verticalScrollPosition,
  4237. ScrollEventDetail.AT_TOP);
  4238. event.stopPropagation();
  4239. break;
  4240. }
  4241. case Keyboard.END:
  4242. {
  4243. verticalScrollPosition =
  4244. verticalScrollBar.maxScrollPosition;
  4245. dispatchScrollEvent(direction, oldPos,
  4246. verticalScrollPosition,
  4247. ScrollEventDetail.AT_BOTTOM);
  4248. event.stopPropagation();
  4249. break;
  4250. }
  4251. }
  4252. }
  4253. if (horizontalScrollBar)
  4254. {
  4255. direction = ScrollEventDirection.HORIZONTAL;
  4256. oldPos = horizontalScrollPosition;
  4257. switch (event.keyCode)
  4258. {
  4259. case Keyboard.LEFT:
  4260. {
  4261. horizontalScrollPosition -= horizontalLineScrollSize;
  4262. dispatchScrollEvent(direction, oldPos,
  4263. horizontalScrollPosition,
  4264. ScrollEventDetail.LINE_LEFT);
  4265. event.stopPropagation();
  4266. break;
  4267. }
  4268. case Keyboard.RIGHT:
  4269. {
  4270. horizontalScrollPosition += horizontalLineScrollSize;
  4271. dispatchScrollEvent(direction, oldPos,
  4272. horizontalScrollPosition,
  4273. ScrollEventDetail.LINE_RIGHT);
  4274. event.stopPropagation();
  4275. break;
  4276. }
  4277. }
  4278. }
  4279. }
  4280. //--------------------------------------------------------------------------
  4281. //
  4282. // Event handlers
  4283. //
  4284. //--------------------------------------------------------------------------
  4285. /**
  4286. * @private
  4287. * This method copied verbatim from mx.core.ScrollControlBase.
  4288. */
  4289. private function mouseWheelHandler(event:MouseEvent):void
  4290. {
  4291. // If this Container has a vertical scrollbar, then handle the event
  4292. // and prevent further bubbling
  4293. if (verticalScrollBar)
  4294. {
  4295. event.stopPropagation();
  4296. var scrollDirection:int = event.delta <= 0 ? 1 : -1;
  4297. var lineScrollSize:int = verticalScrollBar ?
  4298. verticalScrollBar.lineScrollSize :
  4299. 1;
  4300. // Make sure we scroll by at least one line
  4301. var scrollAmount:Number =
  4302. Math.max(Math.abs(event.delta), lineScrollSize);
  4303. // Multiply by 3 to make scrolling a little faster
  4304. var oldPosition:Number = verticalScrollPosition;
  4305. verticalScrollPosition += 3 * scrollAmount * scrollDirection;
  4306. dispatchScrollEvent(ScrollEventDirection.VERTICAL,
  4307. oldPosition, verticalScrollPosition,
  4308. event.delta <= 0 ?
  4309. ScrollEventDetail.LINE_UP :
  4310. ScrollEventDetail.LINE_DOWN);
  4311. }
  4312. }
  4313. /**
  4314. * @private
  4315. * This function is called when the LayoutManager finishes running.
  4316. * Clear the forceLayout flag that was set earlier.
  4317. */
  4318. private function layoutCompleteHandler(event:FlexEvent):void
  4319. {
  4320. UIComponentGlobals.layoutManager.removeEventListener(
  4321. FlexEvent.UPDATE_COMPLETE, layoutCompleteHandler);
  4322. forceLayout = false;
  4323. var needToScrollChildren:Boolean = false;
  4324. if (!isNaN(horizontalScrollPositionPending))
  4325. {
  4326. if (horizontalScrollPositionPending < 0)
  4327. horizontalScrollPositionPending = 0;
  4328. else if (horizontalScrollPositionPending > maxHorizontalScrollPosition)
  4329. horizontalScrollPositionPending = maxHorizontalScrollPosition;
  4330. // Set the position of the horizontal scrollbar's thumb.
  4331. if (horizontalScrollBar &&
  4332. horizontalScrollBar.scrollPosition !=
  4333. horizontalScrollPositionPending)
  4334. {
  4335. _horizontalScrollPosition = horizontalScrollPositionPending;
  4336. horizontalScrollBar.scrollPosition =
  4337. horizontalScrollPositionPending;
  4338. needToScrollChildren = true;
  4339. }
  4340. horizontalScrollPositionPending = NaN;
  4341. }
  4342. if (!isNaN(verticalScrollPositionPending))
  4343. {
  4344. // Clamp verticalScrollPosition to the range 0 through maxVerticalScrollPosition.
  4345. // If verticalScrollBar doesn't exist, maxVerticalScrollPosition will be 0.
  4346. if (verticalScrollPositionPending < 0)
  4347. verticalScrollPositionPending = 0;
  4348. else if (verticalScrollPositionPending > maxVerticalScrollPosition)
  4349. verticalScrollPositionPending = maxVerticalScrollPosition;
  4350. // Set the position of the vertical scrollbar's thumb.
  4351. if (verticalScrollBar && verticalScrollBar.scrollPosition != verticalScrollPositionPending)
  4352. {
  4353. _verticalScrollPosition = verticalScrollPositionPending;
  4354. verticalScrollBar.scrollPosition = verticalScrollPositionPending;
  4355. needToScrollChildren = true;
  4356. }
  4357. verticalScrollPositionPending = NaN;
  4358. }
  4359. if (needToScrollChildren)
  4360. scrollChildren();
  4361. }
  4362. /**
  4363. * @private
  4364. */
  4365. private function creationCompleteHandler(event:FlexEvent):void
  4366. {
  4367. numChildrenCreated--;
  4368. if (numChildrenCreated <= 0)
  4369. dispatchEvent(new FlexEvent("childrenCreationComplete"));
  4370. }
  4371. /**
  4372. * @private
  4373. * This method is called if the user interactively moves
  4374. * the horizontal scrollbar thumb.
  4375. */
  4376. private function horizontalScrollBar_scrollHandler(event:Event):void
  4377. {
  4378. // TextField.scroll bubbles so you might see it here
  4379. if (event is ScrollEvent)
  4380. {
  4381. var oldPos:Number = horizontalScrollPosition;
  4382. horizontalScrollPosition = horizontalScrollBar.scrollPosition;
  4383. dispatchScrollEvent(ScrollEventDirection.HORIZONTAL,
  4384. oldPos,
  4385. horizontalScrollPosition,
  4386. ScrollEvent(event).detail);
  4387. }
  4388. }
  4389. /**
  4390. * @private
  4391. * This method is called if the user interactively moves
  4392. * the vertical scrollbar thumb.
  4393. */
  4394. private function verticalScrollBar_scrollHandler(event:Event):void
  4395. {
  4396. // TextField.scroll bubbles so you might see it here
  4397. if (event is ScrollEvent)
  4398. {
  4399. var oldPos:Number = verticalScrollPosition;
  4400. verticalScrollPosition = verticalScrollBar.scrollPosition;
  4401. dispatchScrollEvent(ScrollEventDirection.VERTICAL,
  4402. oldPos,
  4403. verticalScrollPosition,
  4404. ScrollEvent(event).detail);
  4405. }
  4406. }
  4407. /**
  4408. * @private
  4409. */
  4410. private function blocker_clickHandler(event:Event):void
  4411. {
  4412. // Swallow click events from blocker.
  4413. event.stopPropagation();
  4414. }
  4415. }
  4416. }