home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / containers / ViewStack.as < prev   
Encoding:
Text File  |  2010-06-23  |  18.8 KB  |  620 lines

  1. package mx.containers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.Event;
  5.    import mx.automation.IAutomationObject;
  6.    import mx.core.Container;
  7.    import mx.core.ContainerCreationPolicy;
  8.    import mx.core.EdgeMetrics;
  9.    import mx.core.IInvalidating;
  10.    import mx.core.IUIComponent;
  11.    import mx.core.ScrollPolicy;
  12.    import mx.core.UIComponent;
  13.    import mx.core.mx_internal;
  14.    import mx.effects.Effect;
  15.    import mx.effects.EffectManager;
  16.    import mx.events.ChildExistenceChangedEvent;
  17.    import mx.events.EffectEvent;
  18.    import mx.events.FlexEvent;
  19.    import mx.events.IndexChangedEvent;
  20.    import mx.graphics.RoundedRectangle;
  21.    import mx.managers.HistoryManager;
  22.    import mx.managers.IHistoryManagerClient;
  23.    
  24.    use namespace mx_internal;
  25.    
  26.    public class ViewStack extends Container implements IHistoryManagerClient
  27.    {
  28.       mx_internal static const VERSION:String = "3.5.0.12683";
  29.       
  30.       private var dispatchChangeEventPending:Boolean = false;
  31.       
  32.       private var historyManagementEnabledChanged:Boolean = false;
  33.       
  34.       mx_internal var vsPreferredHeight:Number;
  35.       
  36.       private var initialSelectedIndex:int = -1;
  37.       
  38.       private var firstTime:Boolean = true;
  39.       
  40.       mx_internal var _historyManagementEnabled:Boolean = false;
  41.       
  42.       private var overlayChild:Container;
  43.       
  44.       private var overlayTargetArea:RoundedRectangle;
  45.       
  46.       private var proposedSelectedIndex:int = -1;
  47.       
  48.       private var needToInstantiateSelectedChild:Boolean = false;
  49.       
  50.       private var bSaveState:Boolean = false;
  51.       
  52.       mx_internal var vsMinHeight:Number;
  53.       
  54.       private var bInLoadState:Boolean = false;
  55.       
  56.       mx_internal var vsPreferredWidth:Number;
  57.       
  58.       private var _resizeToContent:Boolean = false;
  59.       
  60.       mx_internal var vsMinWidth:Number;
  61.       
  62.       private var lastIndex:int = -1;
  63.       
  64.       private var _selectedIndex:int = -1;
  65.       
  66.       public function ViewStack()
  67.       {
  68.          super();
  69.          addEventListener(ChildExistenceChangedEvent.CHILD_ADD,childAddHandler);
  70.          addEventListener(ChildExistenceChangedEvent.CHILD_REMOVE,childRemoveHandler);
  71.       }
  72.       
  73.       protected function get contentHeight() : Number
  74.       {
  75.          var _loc1_:EdgeMetrics = viewMetricsAndPadding;
  76.          return unscaledHeight - _loc1_.top - _loc1_.bottom;
  77.       }
  78.       
  79.       public function set selectedChild(param1:Container) : void
  80.       {
  81.          var _loc2_:int = getChildIndex(DisplayObject(param1));
  82.          if(_loc2_ >= 0 && _loc2_ < numChildren)
  83.          {
  84.             selectedIndex = _loc2_;
  85.          }
  86.       }
  87.       
  88.       override mx_internal function setActualCreationPolicies(param1:String) : void
  89.       {
  90.          var _loc2_:int = 0;
  91.          var _loc3_:Container = null;
  92.          super.mx_internal::setActualCreationPolicies(param1);
  93.          if(param1 == ContainerCreationPolicy.ALL && numChildren > 0)
  94.          {
  95.             _loc2_ = 0;
  96.             while(_loc2_ < numChildren)
  97.             {
  98.                _loc3_ = getChildAt(_loc2_) as Container;
  99.                if(Boolean(_loc3_) && _loc3_.mx_internal::numChildrenCreated == -1)
  100.                {
  101.                   _loc3_.createComponentsFromDescriptors();
  102.                }
  103.                _loc2_++;
  104.             }
  105.          }
  106.       }
  107.       
  108.       private function dispatchChangeEvent(param1:int, param2:int) : void
  109.       {
  110.          var _loc3_:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
  111.          _loc3_.oldIndex = param1;
  112.          _loc3_.newIndex = param2;
  113.          _loc3_.relatedObject = getChildAt(param2);
  114.          dispatchEvent(_loc3_);
  115.       }
  116.       
  117.       protected function get contentY() : Number
  118.       {
  119.          return getStyle("paddingTop");
  120.       }
  121.       
  122.       protected function commitSelectedIndex(param1:int) : void
  123.       {
  124.          var _loc3_:Container = null;
  125.          var _loc4_:Effect = null;
  126.          if(numChildren == 0)
  127.          {
  128.             _selectedIndex = -1;
  129.             return;
  130.          }
  131.          if(param1 < 0)
  132.          {
  133.             param1 = 0;
  134.          }
  135.          else if(param1 > numChildren - 1)
  136.          {
  137.             param1 = numChildren - 1;
  138.          }
  139.          if(lastIndex != -1 && lastIndex < numChildren)
  140.          {
  141.             Container(getChildAt(lastIndex)).endEffectsStarted();
  142.          }
  143.          if(_selectedIndex != -1)
  144.          {
  145.             selectedChild.endEffectsStarted();
  146.          }
  147.          lastIndex = _selectedIndex;
  148.          if(param1 == lastIndex)
  149.          {
  150.             return;
  151.          }
  152.          _selectedIndex = param1;
  153.          if(initialSelectedIndex == -1)
  154.          {
  155.             initialSelectedIndex = _selectedIndex;
  156.          }
  157.          if(lastIndex != -1 && param1 != -1)
  158.          {
  159.             dispatchChangeEventPending = true;
  160.          }
  161.          var _loc2_:Boolean = false;
  162.          if(lastIndex != -1 && lastIndex < numChildren)
  163.          {
  164.             _loc3_ = Container(getChildAt(lastIndex));
  165.             _loc3_.setVisible(false);
  166.             if(_loc3_.getStyle("hideEffect"))
  167.             {
  168.                _loc4_ = EffectManager.mx_internal::lastEffectCreated;
  169.                if(_loc4_)
  170.                {
  171.                   _loc4_.addEventListener(EffectEvent.EFFECT_END,hideEffectEndHandler);
  172.                   _loc2_ = true;
  173.                }
  174.             }
  175.          }
  176.          if(!_loc2_)
  177.          {
  178.             hideEffectEndHandler(null);
  179.          }
  180.       }
  181.       
  182.       private function instantiateSelectedChild() : void
  183.       {
  184.          if(!selectedChild)
  185.          {
  186.             return;
  187.          }
  188.          if(Boolean(selectedChild) && selectedChild.mx_internal::numChildrenCreated == -1)
  189.          {
  190.             if(initialized)
  191.             {
  192.                selectedChild.addEventListener(FlexEvent.CREATION_COMPLETE,childCreationCompleteHandler);
  193.             }
  194.             selectedChild.createComponentsFromDescriptors(true);
  195.          }
  196.          if(selectedChild is IInvalidating)
  197.          {
  198.             IInvalidating(selectedChild).invalidateSize();
  199.          }
  200.          invalidateSize();
  201.          invalidateDisplayList();
  202.       }
  203.       
  204.       private function initializeHandler(param1:FlexEvent) : void
  205.       {
  206.          overlayChild.removeEventListener(FlexEvent.INITIALIZE,initializeHandler);
  207.          UIComponent(overlayChild).mx_internal::addOverlay(mx_internal::overlayColor,overlayTargetArea);
  208.       }
  209.       
  210.       public function set historyManagementEnabled(param1:Boolean) : void
  211.       {
  212.          if(param1 != mx_internal::_historyManagementEnabled)
  213.          {
  214.             mx_internal::_historyManagementEnabled = param1;
  215.             historyManagementEnabledChanged = true;
  216.             invalidateProperties();
  217.          }
  218.       }
  219.       
  220.       override public function get horizontalScrollPolicy() : String
  221.       {
  222.          return ScrollPolicy.OFF;
  223.       }
  224.       
  225.       private function childAddHandler(param1:ChildExistenceChangedEvent) : void
  226.       {
  227.          var _loc4_:IUIComponent = null;
  228.          var _loc2_:DisplayObject = param1.relatedObject;
  229.          var _loc3_:int = getChildIndex(_loc2_);
  230.          if(_loc2_ is IUIComponent)
  231.          {
  232.             _loc4_ = IUIComponent(_loc2_);
  233.             _loc4_.visible = false;
  234.          }
  235.          if(numChildren == 1 && proposedSelectedIndex == -1)
  236.          {
  237.             proposedSelectedIndex = 0;
  238.             invalidateProperties();
  239.          }
  240.          else if(_loc3_ <= selectedIndex && numChildren > 1 && proposedSelectedIndex == -1)
  241.          {
  242.             ++selectedIndex;
  243.          }
  244.          if(_loc2_ is IAutomationObject)
  245.          {
  246.             IAutomationObject(_loc2_).showInAutomationHierarchy = true;
  247.          }
  248.       }
  249.       
  250.       private function addedToStageHandler(param1:Event) : void
  251.       {
  252.          if(historyManagementEnabled)
  253.          {
  254.             HistoryManager.register(this);
  255.          }
  256.       }
  257.       
  258.       public function get resizeToContent() : Boolean
  259.       {
  260.          return _resizeToContent;
  261.       }
  262.       
  263.       public function saveState() : Object
  264.       {
  265.          var _loc1_:int = _selectedIndex == -1 ? 0 : _selectedIndex;
  266.          return {"selectedIndex":_loc1_};
  267.       }
  268.       
  269.       override public function get autoLayout() : Boolean
  270.       {
  271.          return true;
  272.       }
  273.       
  274.       override mx_internal function removeOverlay() : void
  275.       {
  276.          if(overlayChild)
  277.          {
  278.             UIComponent(overlayChild).mx_internal::removeOverlay();
  279.             overlayChild = null;
  280.          }
  281.       }
  282.       
  283.       private function removedFromStageHandler(param1:Event) : void
  284.       {
  285.          HistoryManager.unregister(this);
  286.       }
  287.       
  288.       [Bindable("creationComplete")]
  289.       [Bindable("valueCommit")]
  290.       public function get selectedChild() : Container
  291.       {
  292.          if(selectedIndex == -1)
  293.          {
  294.             return null;
  295.          }
  296.          return Container(getChildAt(selectedIndex));
  297.       }
  298.       
  299.       private function hideEffectEndHandler(param1:EffectEvent) : void
  300.       {
  301.          if(param1)
  302.          {
  303.             param1.currentTarget.removeEventListener(EffectEvent.EFFECT_END,hideEffectEndHandler);
  304.          }
  305.          needToInstantiateSelectedChild = true;
  306.          invalidateProperties();
  307.          if(bSaveState)
  308.          {
  309.             HistoryManager.save();
  310.             bSaveState = false;
  311.          }
  312.       }
  313.       
  314.       private function childCreationCompleteHandler(param1:FlexEvent) : void
  315.       {
  316.          param1.target.removeEventListener(FlexEvent.CREATION_COMPLETE,childCreationCompleteHandler);
  317.          param1.target.dispatchEvent(new FlexEvent(FlexEvent.SHOW));
  318.       }
  319.       
  320.       override public function set horizontalScrollPolicy(param1:String) : void
  321.       {
  322.       }
  323.       
  324.       public function get historyManagementEnabled() : Boolean
  325.       {
  326.          return mx_internal::_historyManagementEnabled;
  327.       }
  328.       
  329.       public function loadState(param1:Object) : void
  330.       {
  331.          var _loc2_:int = !!param1 ? int(param1.selectedIndex) : 0;
  332.          if(_loc2_ == -1)
  333.          {
  334.             _loc2_ = initialSelectedIndex;
  335.          }
  336.          if(_loc2_ == -1)
  337.          {
  338.             _loc2_ = 0;
  339.          }
  340.          if(_loc2_ != _selectedIndex)
  341.          {
  342.             bInLoadState = true;
  343.             selectedIndex = _loc2_;
  344.             bInLoadState = false;
  345.          }
  346.       }
  347.       
  348.       protected function get contentWidth() : Number
  349.       {
  350.          var _loc1_:EdgeMetrics = viewMetricsAndPadding;
  351.          return unscaledWidth - _loc1_.left - _loc1_.right;
  352.       }
  353.       
  354.       override protected function commitProperties() : void
  355.       {
  356.          super.commitProperties();
  357.          if(historyManagementEnabledChanged)
  358.          {
  359.             if(historyManagementEnabled)
  360.             {
  361.                HistoryManager.register(this);
  362.             }
  363.             else
  364.             {
  365.                HistoryManager.unregister(this);
  366.             }
  367.             historyManagementEnabledChanged = false;
  368.          }
  369.          if(proposedSelectedIndex != -1)
  370.          {
  371.             commitSelectedIndex(proposedSelectedIndex);
  372.             proposedSelectedIndex = -1;
  373.          }
  374.          if(needToInstantiateSelectedChild)
  375.          {
  376.             instantiateSelectedChild();
  377.             needToInstantiateSelectedChild = false;
  378.          }
  379.          if(dispatchChangeEventPending)
  380.          {
  381.             dispatchChangeEvent(lastIndex,selectedIndex);
  382.             dispatchChangeEventPending = false;
  383.          }
  384.          if(firstTime)
  385.          {
  386.             firstTime = false;
  387.             addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler,false,0,true);
  388.             addEventListener(Event.REMOVED_FROM_STAGE,removedFromStageHandler,false,0,true);
  389.          }
  390.       }
  391.       
  392.       public function set resizeToContent(param1:Boolean) : void
  393.       {
  394.          if(param1 != _resizeToContent)
  395.          {
  396.             _resizeToContent = param1;
  397.             if(param1)
  398.             {
  399.                invalidateSize();
  400.             }
  401.          }
  402.       }
  403.       
  404.       override public function createComponentsFromDescriptors(param1:Boolean = true) : void
  405.       {
  406.          if(actualCreationPolicy == ContainerCreationPolicy.ALL)
  407.          {
  408.             super.createComponentsFromDescriptors();
  409.             return;
  410.          }
  411.          var _loc2_:int = numChildren;
  412.          var _loc3_:int = !!childDescriptors ? int(childDescriptors.length) : 0;
  413.          var _loc4_:int = 0;
  414.          while(_loc4_ < _loc3_)
  415.          {
  416.             createComponentFromDescriptor(childDescriptors[_loc4_],false);
  417.             _loc4_++;
  418.          }
  419.          mx_internal::numChildrenCreated = numChildren - _loc2_;
  420.          processedDescriptors = true;
  421.       }
  422.       
  423.       override protected function measure() : void
  424.       {
  425.          var _loc1_:Number = NaN;
  426.          var _loc2_:Number = NaN;
  427.          var _loc3_:Number = NaN;
  428.          var _loc4_:Number = NaN;
  429.          var _loc8_:Container = null;
  430.          super.measure();
  431.          _loc1_ = 0;
  432.          _loc2_ = 0;
  433.          _loc3_ = 0;
  434.          _loc4_ = 0;
  435.          if(Boolean(mx_internal::vsPreferredWidth) && !_resizeToContent)
  436.          {
  437.             measuredMinWidth = mx_internal::vsMinWidth;
  438.             measuredMinHeight = mx_internal::vsMinHeight;
  439.             measuredWidth = mx_internal::vsPreferredWidth;
  440.             measuredHeight = mx_internal::vsPreferredHeight;
  441.             return;
  442.          }
  443.          if(numChildren > 0 && selectedIndex != -1)
  444.          {
  445.             _loc8_ = Container(getChildAt(selectedIndex));
  446.             _loc1_ = _loc8_.minWidth;
  447.             _loc3_ = _loc8_.getExplicitOrMeasuredWidth();
  448.             _loc2_ = _loc8_.minHeight;
  449.             _loc4_ = _loc8_.getExplicitOrMeasuredHeight();
  450.          }
  451.          var _loc5_:EdgeMetrics = viewMetricsAndPadding;
  452.          var _loc6_:Number = _loc5_.left + _loc5_.right;
  453.          _loc1_ += _loc6_;
  454.          _loc3_ += _loc6_;
  455.          var _loc7_:Number = _loc5_.top + _loc5_.bottom;
  456.          _loc2_ += _loc7_;
  457.          _loc4_ += _loc7_;
  458.          measuredMinWidth = _loc1_;
  459.          measuredMinHeight = _loc2_;
  460.          measuredWidth = _loc3_;
  461.          measuredHeight = _loc4_;
  462.          if(Boolean(selectedChild) && Container(selectedChild).mx_internal::numChildrenCreated == -1)
  463.          {
  464.             return;
  465.          }
  466.          if(numChildren == 0)
  467.          {
  468.             return;
  469.          }
  470.          mx_internal::vsMinWidth = _loc1_;
  471.          mx_internal::vsMinHeight = _loc2_;
  472.          mx_internal::vsPreferredWidth = _loc3_;
  473.          mx_internal::vsPreferredHeight = _loc4_;
  474.       }
  475.       
  476.       override public function set verticalScrollPolicy(param1:String) : void
  477.       {
  478.       }
  479.       
  480.       public function set selectedIndex(param1:int) : void
  481.       {
  482.          if(param1 == selectedIndex)
  483.          {
  484.             return;
  485.          }
  486.          proposedSelectedIndex = param1;
  487.          invalidateProperties();
  488.          if(historyManagementEnabled && _selectedIndex != -1 && !bInLoadState)
  489.          {
  490.             bSaveState = true;
  491.          }
  492.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  493.       }
  494.       
  495.       override mx_internal function addOverlay(param1:uint, param2:RoundedRectangle = null) : void
  496.       {
  497.          if(overlayChild)
  498.          {
  499.             mx_internal::removeOverlay();
  500.          }
  501.          overlayChild = selectedChild;
  502.          if(!overlayChild)
  503.          {
  504.             return;
  505.          }
  506.          mx_internal::overlayColor = param1;
  507.          overlayTargetArea = param2;
  508.          if(Boolean(selectedChild) && selectedChild.mx_internal::numChildrenCreated == -1)
  509.          {
  510.             selectedChild.addEventListener(FlexEvent.INITIALIZE,initializeHandler);
  511.          }
  512.          else
  513.          {
  514.             initializeHandler(null);
  515.          }
  516.       }
  517.       
  518.       override public function set autoLayout(param1:Boolean) : void
  519.       {
  520.       }
  521.       
  522.       override public function get verticalScrollPolicy() : String
  523.       {
  524.          return ScrollPolicy.OFF;
  525.       }
  526.       
  527.       [Bindable("creationComplete")]
  528.       [Bindable("valueCommit")]
  529.       [Bindable("change")]
  530.       public function get selectedIndex() : int
  531.       {
  532.          return proposedSelectedIndex == -1 ? _selectedIndex : proposedSelectedIndex;
  533.       }
  534.       
  535.       private function childRemoveHandler(param1:ChildExistenceChangedEvent) : void
  536.       {
  537.          var _loc2_:DisplayObject = param1.relatedObject;
  538.          var _loc3_:int = getChildIndex(_loc2_);
  539.          if(_loc3_ > selectedIndex)
  540.          {
  541.             return;
  542.          }
  543.          var _loc4_:int = selectedIndex;
  544.          if(_loc3_ < _loc4_ || _loc4_ == numChildren - 1)
  545.          {
  546.             if(_loc4_ == 0)
  547.             {
  548.                selectedIndex = -1;
  549.                _selectedIndex = -1;
  550.             }
  551.             else
  552.             {
  553.                --selectedIndex;
  554.             }
  555.          }
  556.          else if(_loc3_ == _loc4_)
  557.          {
  558.             needToInstantiateSelectedChild = true;
  559.             invalidateProperties();
  560.          }
  561.       }
  562.       
  563.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  564.       {
  565.          var _loc8_:Container = null;
  566.          var _loc9_:Number = NaN;
  567.          var _loc10_:Number = NaN;
  568.          super.updateDisplayList(param1,param2);
  569.          var _loc3_:int = numChildren;
  570.          var _loc4_:Number = contentWidth;
  571.          var _loc5_:Number = contentHeight;
  572.          var _loc6_:Number = contentX;
  573.          var _loc7_:Number = contentY;
  574.          if(selectedIndex != -1)
  575.          {
  576.             _loc8_ = Container(getChildAt(selectedIndex));
  577.             _loc9_ = _loc4_;
  578.             _loc10_ = _loc5_;
  579.             if(!isNaN(_loc8_.percentWidth))
  580.             {
  581.                if(_loc9_ > _loc8_.maxWidth)
  582.                {
  583.                   _loc9_ = _loc8_.maxWidth;
  584.                }
  585.             }
  586.             else if(_loc9_ > _loc8_.explicitWidth)
  587.             {
  588.                _loc9_ = _loc8_.explicitWidth;
  589.             }
  590.             if(!isNaN(_loc8_.percentHeight))
  591.             {
  592.                if(_loc10_ > _loc8_.maxHeight)
  593.                {
  594.                   _loc10_ = _loc8_.maxHeight;
  595.                }
  596.             }
  597.             else if(_loc10_ > _loc8_.explicitHeight)
  598.             {
  599.                _loc10_ = _loc8_.explicitHeight;
  600.             }
  601.             if(_loc8_.width != _loc9_ || _loc8_.height != _loc10_)
  602.             {
  603.                _loc8_.setActualSize(_loc9_,_loc10_);
  604.             }
  605.             if(_loc8_.x != _loc6_ || _loc8_.y != _loc7_)
  606.             {
  607.                _loc8_.move(_loc6_,_loc7_);
  608.             }
  609.             _loc8_.visible = true;
  610.          }
  611.       }
  612.       
  613.       protected function get contentX() : Number
  614.       {
  615.          return getStyle("paddingLeft");
  616.       }
  617.    }
  618. }
  619.  
  620.