PageRenderTime 1108ms CodeModel.GetById 43ms RepoModel.GetById 11ms 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

Large files files are truncated, but you can click here to view the full 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; …

Large files files are truncated, but you can click here to view the full file