home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / filler.swf / scripts / mx / managers / FocusManager.as next >
Encoding:
Text File  |  2008-09-02  |  31.2 KB  |  977 lines

  1. package mx.managers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.display.InteractiveObject;
  6.    import flash.display.Sprite;
  7.    import flash.events.Event;
  8.    import flash.events.FocusEvent;
  9.    import flash.events.KeyboardEvent;
  10.    import flash.events.MouseEvent;
  11.    import flash.system.Capabilities;
  12.    import flash.text.TextField;
  13.    import flash.ui.Keyboard;
  14.    import mx.controls.Button;
  15.    import mx.core.FlexSprite;
  16.    import mx.core.IChildList;
  17.    import mx.core.IRawChildrenContainer;
  18.    import mx.core.IUIComponent;
  19.    import mx.core.mx_internal;
  20.    import mx.events.FlexEvent;
  21.    
  22.    use namespace mx_internal;
  23.    
  24.    public class FocusManager implements IFocusManager
  25.    {
  26.       
  27.       mx_internal static const VERSION:String = "2.0.1.0";
  28.        
  29.       
  30.       private var _showFocusIndicator:Boolean = false;
  31.       
  32.       private var focusableCandidates:Array;
  33.       
  34.       private var LARGE_TAB_INDEX:int = 99999;
  35.       
  36.       private var browserFocusComponent:InteractiveObject;
  37.       
  38.       private var calculateCandidates:Boolean = true;
  39.       
  40.       private var lastAction:String;
  41.       
  42.       private var focusableObjects:Array;
  43.       
  44.       private var defButton:Button;
  45.       
  46.       private var _form:IFocusManagerContainer;
  47.       
  48.       private var _defaultButtonEnabled:Boolean = true;
  49.       
  50.       private var activated:Boolean = false;
  51.       
  52.       private var _defaultButton:Button;
  53.       
  54.       private var _focusPane:Sprite;
  55.       
  56.       private var lastFocus:IFocusManagerComponent;
  57.       
  58.       private var browserMode:Boolean;
  59.       
  60.       public function FocusManager(param1:IFocusManagerContainer, param2:Boolean = false)
  61.       {
  62.          LARGE_TAB_INDEX = 99999;
  63.          calculateCandidates = true;
  64.          activated = false;
  65.          _showFocusIndicator = false;
  66.          _defaultButtonEnabled = true;
  67.          super();
  68.          browserMode = Capabilities.playerType == "ActiveX" && !param2;
  69.          param1.focusManager = this;
  70.          _form = param1;
  71.          focusableObjects = [];
  72.          focusPane = new FlexSprite();
  73.          focusPane.name = "focusPane";
  74.          addFocusables(DisplayObject(param1));
  75.          param1.addEventListener(Event.ADDED,addedHandler);
  76.          param1.addEventListener(Event.REMOVED,removedHandler);
  77.          param1.addEventListener(FlexEvent.SHOW,showHandler);
  78.          param1.addEventListener(FlexEvent.HIDE,hideHandler);
  79.          if(param1 != SystemManager(param1.systemManager).application)
  80.          {
  81.             param1.addEventListener(FlexEvent.CREATION_COMPLETE,creationCompleteHandler);
  82.          }
  83.          param1.systemManager.addFocusManager(param1);
  84.       }
  85.       
  86.       private function addFocusables(param1:DisplayObject, param2:Boolean = false) : void
  87.       {
  88.          var focusable:IFocusManagerComponent = null;
  89.          var doc:DisplayObjectContainer = null;
  90.          var i:int = 0;
  91.          var rawChildren:IChildList = null;
  92.          var o:DisplayObject = param1;
  93.          var skipTopLevel:Boolean = param2;
  94.          if(o is IFocusManagerComponent && !skipTopLevel)
  95.          {
  96.             focusable = IFocusManagerComponent(o);
  97.             if(focusable.focusEnabled)
  98.             {
  99.                if(focusable.tabEnabled && isTabVisible(o))
  100.                {
  101.                   focusableObjects.push(o);
  102.                   calculateCandidates = true;
  103.                }
  104.                o.addEventListener("tabEnabledChange",tabEnabledChangeHandler);
  105.                o.addEventListener("tabIndexChange",tabIndexChangeHandler);
  106.             }
  107.          }
  108.          if(o is DisplayObjectContainer)
  109.          {
  110.             doc = DisplayObjectContainer(o);
  111.             o.addEventListener("tabChildrenChange",tabChildrenChangeHandler);
  112.             if(doc.tabChildren)
  113.             {
  114.                if(o is IRawChildrenContainer)
  115.                {
  116.                   rawChildren = IRawChildrenContainer(o).rawChildren;
  117.                   i = 0;
  118.                   while(i < rawChildren.numChildren)
  119.                   {
  120.                      try
  121.                      {
  122.                         addFocusables(rawChildren.getChildAt(i));
  123.                      }
  124.                      catch(error:SecurityError)
  125.                      {
  126.                      }
  127.                      i++;
  128.                   }
  129.                }
  130.                else
  131.                {
  132.                   i = 0;
  133.                   while(i < doc.numChildren)
  134.                   {
  135.                      try
  136.                      {
  137.                         addFocusables(doc.getChildAt(i));
  138.                      }
  139.                      catch(error:SecurityError)
  140.                      {
  141.                      }
  142.                      i++;
  143.                   }
  144.                }
  145.             }
  146.          }
  147.       }
  148.       
  149.       private function getChildIndex(param1:DisplayObjectContainer, param2:DisplayObject) : int
  150.       {
  151.          var parent:DisplayObjectContainer = param1;
  152.          var child:DisplayObject = param2;
  153.          try
  154.          {
  155.             return parent.getChildIndex(child);
  156.          }
  157.          catch(e:Error)
  158.          {
  159.             if(parent is IRawChildrenContainer)
  160.             {
  161.                return IRawChildrenContainer(parent).rawChildren.getChildIndex(child);
  162.             }
  163.             throw e;
  164.          }
  165.       }
  166.       
  167.       private function mouseFocusChangeHandler(param1:FocusEvent) : void
  168.       {
  169.          var _loc2_:TextField = null;
  170.          if(param1.relatedObject is TextField)
  171.          {
  172.             _loc2_ = param1.relatedObject as TextField;
  173.             if(_loc2_.type == "input" || _loc2_.selectable)
  174.             {
  175.                return;
  176.             }
  177.          }
  178.          param1.preventDefault();
  179.       }
  180.       
  181.       private function focusOutHandler(param1:FocusEvent) : void
  182.       {
  183.          var _loc2_:InteractiveObject = null;
  184.          _loc2_ = InteractiveObject(param1.target);
  185.       }
  186.       
  187.       private function isValidFocusCandidate(param1:DisplayObject, param2:String) : Boolean
  188.       {
  189.          var _loc3_:IFocusManagerGroup = null;
  190.          if(!isEnabledAndVisible(param1))
  191.          {
  192.             return false;
  193.          }
  194.          if(param1 is IFocusManagerGroup)
  195.          {
  196.             _loc3_ = IFocusManagerGroup(param1);
  197.             if(param2 == _loc3_.groupName)
  198.             {
  199.                return false;
  200.             }
  201.          }
  202.          return true;
  203.       }
  204.       
  205.       private function removeFocusables(param1:DisplayObject, param2:Boolean) : void
  206.       {
  207.          var _loc3_:int = 0;
  208.          if(param1 is DisplayObjectContainer)
  209.          {
  210.             if(!param2)
  211.             {
  212.                param1.removeEventListener("tabChildrenChange",tabChildrenChangeHandler);
  213.             }
  214.             _loc3_ = 0;
  215.             while(_loc3_ < focusableObjects.length)
  216.             {
  217.                if(isParent(DisplayObjectContainer(param1),focusableObjects[_loc3_]))
  218.                {
  219.                   if(focusableObjects[_loc3_] == lastFocus)
  220.                   {
  221.                      lastFocus.drawFocus(false);
  222.                      lastFocus = null;
  223.                   }
  224.                   focusableObjects[_loc3_].removeEventListener("tabEnabledChange",tabEnabledChangeHandler);
  225.                   focusableObjects[_loc3_].removeEventListener("tabIndexChange",tabIndexChangeHandler);
  226.                   focusableObjects.splice(_loc3_,1);
  227.                   _loc3_--;
  228.                   calculateCandidates = true;
  229.                }
  230.                _loc3_++;
  231.             }
  232.          }
  233.       }
  234.       
  235.       public function getFocus() : IFocusManagerComponent
  236.       {
  237.          var _loc1_:InteractiveObject = null;
  238.          _loc1_ = mx_internal::form.systemManager.stage.focus;
  239.          return findFocusManagerComponent(_loc1_);
  240.       }
  241.       
  242.       private function addedHandler(param1:Event) : void
  243.       {
  244.          var _loc2_:DisplayObject = null;
  245.          _loc2_ = DisplayObject(param1.target);
  246.          if(_loc2_.stage)
  247.          {
  248.             addFocusables(DisplayObject(param1.target));
  249.          }
  250.       }
  251.       
  252.       private function tabChildrenChangeHandler(param1:Event) : void
  253.       {
  254.          var _loc2_:DisplayObjectContainer = null;
  255.          if(param1.target != param1.currentTarget)
  256.          {
  257.             return;
  258.          }
  259.          calculateCandidates = true;
  260.          _loc2_ = DisplayObjectContainer(param1.target);
  261.          if(_loc2_.tabChildren)
  262.          {
  263.             addFocusables(_loc2_,true);
  264.          }
  265.          else
  266.          {
  267.             removeFocusables(_loc2_,true);
  268.          }
  269.       }
  270.       
  271.       private function sortByDepth(param1:IFocusManagerComponent, param2:IFocusManagerComponent) : Number
  272.       {
  273.          var _loc3_:String = null;
  274.          var _loc4_:String = null;
  275.          var _loc5_:int = 0;
  276.          var _loc6_:String = null;
  277.          var _loc7_:String = null;
  278.          var _loc8_:String = null;
  279.          var _loc9_:DisplayObject = null;
  280.          var _loc10_:DisplayObject = null;
  281.          _loc3_ = "";
  282.          _loc4_ = "";
  283.          _loc8_ = "0000";
  284.          _loc9_ = DisplayObject(param1);
  285.          _loc10_ = DisplayObject(param2);
  286.          while(_loc9_ != DisplayObject(mx_internal::form) && Boolean(_loc9_.parent))
  287.          {
  288.             if((_loc6_ = (_loc5_ = getChildIndex(_loc9_.parent,_loc9_)).toString(16)).length < 4)
  289.             {
  290.                _loc7_ = _loc8_.substring(0,4 - _loc6_.length) + _loc6_;
  291.             }
  292.             _loc3_ = _loc7_ + _loc3_;
  293.             _loc9_ = _loc9_.parent;
  294.          }
  295.          while(_loc10_ != DisplayObject(mx_internal::form) && Boolean(_loc10_.parent))
  296.          {
  297.             if((_loc6_ = (_loc5_ = getChildIndex(_loc10_.parent,_loc10_)).toString(16)).length < 4)
  298.             {
  299.                _loc7_ = _loc8_.substring(0,4 - _loc6_.length) + _loc6_;
  300.             }
  301.             _loc4_ = _loc7_ + _loc4_;
  302.             _loc10_ = _loc10_.parent;
  303.          }
  304.          return _loc3_ > _loc4_ ? 1 : (_loc3_ < _loc4_ ? -1 : 0);
  305.       }
  306.       
  307.       mx_internal function sendDefaultButtonEvent() : void
  308.       {
  309.          defButton.dispatchEvent(new MouseEvent("click"));
  310.       }
  311.       
  312.       private function deactivateHandler(param1:Event) : void
  313.       {
  314.          var _loc2_:InteractiveObject = null;
  315.          _loc2_ = InteractiveObject(param1.target);
  316.       }
  317.       
  318.       private function tabIndexChangeHandler(param1:Event) : void
  319.       {
  320.          calculateCandidates = true;
  321.       }
  322.       
  323.       private function sortFocusableObjects() : void
  324.       {
  325.          var _loc1_:int = 0;
  326.          var _loc2_:int = 0;
  327.          var _loc3_:InteractiveObject = null;
  328.          focusableCandidates = [];
  329.          _loc1_ = int(focusableObjects.length);
  330.          _loc2_ = 0;
  331.          while(_loc2_ < _loc1_)
  332.          {
  333.             _loc3_ = focusableObjects[_loc2_];
  334.             if(_loc3_.tabIndex && !isNaN(Number(_loc3_.tabIndex)) && _loc3_.tabIndex > 0)
  335.             {
  336.                sortFocusableObjectsTabIndex();
  337.                return;
  338.             }
  339.             focusableCandidates.push(_loc3_);
  340.             _loc2_++;
  341.          }
  342.          focusableCandidates.sort(sortByDepth);
  343.       }
  344.       
  345.       private function keyFocusChangeHandler(param1:FocusEvent) : void
  346.       {
  347.          showFocusIndicator = true;
  348.          if(param1.keyCode == Keyboard.TAB && !param1.isDefaultPrevented())
  349.          {
  350.             if(browserFocusComponent)
  351.             {
  352.                if(browserFocusComponent.tabIndex == LARGE_TAB_INDEX)
  353.                {
  354.                   browserFocusComponent.tabIndex = -1;
  355.                }
  356.                browserFocusComponent = null;
  357.                return;
  358.             }
  359.             setFocusToNextObject(param1);
  360.             param1.preventDefault();
  361.          }
  362.       }
  363.       
  364.       private function getIndexOfFocusedObject(param1:DisplayObject) : int
  365.       {
  366.          var _loc2_:int = 0;
  367.          var _loc3_:int = 0;
  368.          _loc2_ = int(focusableCandidates.length);
  369.          _loc3_ = 0;
  370.          _loc3_ = 0;
  371.          while(_loc3_ < _loc2_)
  372.          {
  373.             if(focusableCandidates[_loc3_] == param1)
  374.             {
  375.                return _loc3_;
  376.             }
  377.             _loc3_++;
  378.          }
  379.          return -1;
  380.       }
  381.       
  382.       public function get nextTabIndex() : int
  383.       {
  384.          return getMaxTabIndex() + 1;
  385.       }
  386.       
  387.       public function get focusPane() : Sprite
  388.       {
  389.          return _focusPane;
  390.       }
  391.       
  392.       private function mouseDownHandler(param1:MouseEvent) : void
  393.       {
  394.          var _loc2_:DisplayObject = null;
  395.          if(param1.isDefaultPrevented())
  396.          {
  397.             return;
  398.          }
  399.          _loc2_ = getTopLevelFocusTarget(InteractiveObject(param1.target));
  400.          if(!_loc2_)
  401.          {
  402.             return;
  403.          }
  404.          showFocusIndicator = false;
  405.          if((_loc2_ != lastFocus || lastAction == "ACTIVATE") && !(_loc2_ is TextField))
  406.          {
  407.             setFocus(IFocusManagerComponent(_loc2_));
  408.          }
  409.          lastAction = "MOUSEDOWN";
  410.       }
  411.       
  412.       private function keyDownHandler(param1:KeyboardEvent) : void
  413.       {
  414.          var _loc2_:SystemManager = null;
  415.          var _loc3_:DisplayObject = null;
  416.          var _loc4_:String = null;
  417.          var _loc5_:int = 0;
  418.          var _loc6_:int = 0;
  419.          var _loc7_:IFocusManagerGroup = null;
  420.          _loc2_ = SystemManager(mx_internal::form.systemManager);
  421.          _loc2_.mx_internal::idleCounter = 0;
  422.          if(param1.keyCode == Keyboard.TAB)
  423.          {
  424.             lastAction = "KEY";
  425.             if(calculateCandidates)
  426.             {
  427.                sortFocusableObjects();
  428.                calculateCandidates = false;
  429.             }
  430.          }
  431.          if(browserMode)
  432.          {
  433.             if(param1.keyCode == Keyboard.TAB && focusableCandidates.length > 0)
  434.             {
  435.                _loc3_ = mx_internal::form.systemManager.stage.focus;
  436.                _loc3_ = DisplayObject(findFocusManagerComponent(InteractiveObject(_loc3_)));
  437.                _loc4_ = "";
  438.                if(_loc3_ is IFocusManagerGroup)
  439.                {
  440.                   _loc4_ = (_loc7_ = IFocusManagerGroup(_loc3_)).groupName;
  441.                }
  442.                _loc5_ = getIndexOfFocusedObject(_loc3_);
  443.                _loc6_ = getIndexOfNextObject(_loc5_,param1.shiftKey,false,_loc4_);
  444.                if(param1.shiftKey)
  445.                {
  446.                   if(_loc6_ >= _loc5_)
  447.                   {
  448.                      browserFocusComponent = mx_internal::form.systemManager.stage.focus;
  449.                      if(browserFocusComponent.tabIndex == -1)
  450.                      {
  451.                         browserFocusComponent.tabIndex = LARGE_TAB_INDEX;
  452.                      }
  453.                   }
  454.                }
  455.                else if(_loc6_ <= _loc5_)
  456.                {
  457.                   browserFocusComponent = mx_internal::form.systemManager.stage.focus;
  458.                   if(browserFocusComponent.tabIndex == -1)
  459.                   {
  460.                      browserFocusComponent.tabIndex = LARGE_TAB_INDEX;
  461.                   }
  462.                }
  463.             }
  464.          }
  465.          if(defaultButtonEnabled && param1.keyCode == Keyboard.ENTER && defaultButton && defButton.enabled)
  466.          {
  467.             defButton.callLater(mx_internal::sendDefaultButtonEvent);
  468.          }
  469.       }
  470.       
  471.       public function toString() : String
  472.       {
  473.          return Object(mx_internal::form).toString() + ".focusManager";
  474.       }
  475.       
  476.       private function focusInHandler(param1:FocusEvent) : void
  477.       {
  478.          var _loc2_:InteractiveObject = null;
  479.          var _loc3_:Button = null;
  480.          _loc2_ = InteractiveObject(param1.target);
  481.          if(isParent(DisplayObjectContainer(mx_internal::form),_loc2_))
  482.          {
  483.             lastFocus = findFocusManagerComponent(InteractiveObject(_loc2_));
  484.             if(lastFocus is Button)
  485.             {
  486.                _loc3_ = Button(lastFocus);
  487.                if(defButton)
  488.                {
  489.                   defButton.emphasized = false;
  490.                   defButton = _loc3_;
  491.                   _loc3_.emphasized = true;
  492.                }
  493.             }
  494.             else if(Boolean(defButton) && defButton != _defaultButton)
  495.             {
  496.                defButton.emphasized = false;
  497.                defButton = _defaultButton;
  498.                _defaultButton.emphasized = true;
  499.             }
  500.          }
  501.       }
  502.       
  503.       public function deactivate() : void
  504.       {
  505.          mx_internal::form.systemManager.stage.removeEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler);
  506.          mx_internal::form.systemManager.stage.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler);
  507.          mx_internal::form.removeEventListener(FocusEvent.FOCUS_IN,focusInHandler,true);
  508.          mx_internal::form.removeEventListener(FocusEvent.FOCUS_OUT,focusOutHandler,true);
  509.          mx_internal::form.systemManager.stage.removeEventListener(Event.ACTIVATE,activateHandler);
  510.          mx_internal::form.systemManager.stage.removeEventListener(Event.DEACTIVATE,deactivateHandler);
  511.          mx_internal::form.removeEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  512.          mx_internal::form.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,true);
  513.          activated = false;
  514.       }
  515.       
  516.       private function isParent(param1:DisplayObjectContainer, param2:DisplayObject) : Boolean
  517.       {
  518.          if(param1 is IRawChildrenContainer)
  519.          {
  520.             return IRawChildrenContainer(param1).rawChildren.contains(param2);
  521.          }
  522.          return param1.contains(param2);
  523.       }
  524.       
  525.       private function getIndexOfNextObject(param1:int, param2:Boolean, param3:Boolean, param4:String) : int
  526.       {
  527.          var _loc5_:int = 0;
  528.          var _loc6_:int = 0;
  529.          var _loc7_:DisplayObject = null;
  530.          var _loc8_:IFocusManagerGroup = null;
  531.          var _loc9_:int = 0;
  532.          var _loc10_:DisplayObject = null;
  533.          var _loc11_:IFocusManagerGroup = null;
  534.          _loc5_ = int(focusableCandidates.length);
  535.          _loc6_ = param1;
  536.          while(true)
  537.          {
  538.             if(param2)
  539.             {
  540.                param1--;
  541.             }
  542.             else
  543.             {
  544.                param1++;
  545.             }
  546.             if(param3)
  547.             {
  548.                if(param2 && param1 < 0)
  549.                {
  550.                   break;
  551.                }
  552.                if(!param2 && param1 == _loc5_)
  553.                {
  554.                   break;
  555.                }
  556.             }
  557.             else
  558.             {
  559.                param1 = (param1 + _loc5_) % _loc5_;
  560.                if(_loc6_ == param1)
  561.                {
  562.                   break;
  563.                }
  564.             }
  565.             if(isValidFocusCandidate(focusableCandidates[param1],param4))
  566.             {
  567.                if((_loc7_ = DisplayObject(findFocusManagerComponent(focusableCandidates[param1]))) is IFocusManagerGroup)
  568.                {
  569.                   _loc8_ = IFocusManagerGroup(_loc7_);
  570.                   _loc9_ = 0;
  571.                   while(_loc9_ < focusableCandidates.length)
  572.                   {
  573.                      if((_loc10_ = focusableCandidates[_loc9_]) is IFocusManagerGroup)
  574.                      {
  575.                         if((_loc11_ = IFocusManagerGroup(_loc10_)).groupName == _loc8_.groupName && _loc11_.selected)
  576.                         {
  577.                            param1 = _loc9_;
  578.                            break;
  579.                         }
  580.                      }
  581.                      _loc9_++;
  582.                   }
  583.                }
  584.                return param1;
  585.             }
  586.          }
  587.          return param1;
  588.       }
  589.       
  590.       private function getMaxTabIndex() : int
  591.       {
  592.          var _loc1_:Number = NaN;
  593.          var _loc2_:int = 0;
  594.          var _loc3_:int = 0;
  595.          var _loc4_:Number = NaN;
  596.          _loc1_ = 0;
  597.          _loc2_ = int(focusableObjects.length);
  598.          _loc3_ = 0;
  599.          while(_loc3_ < _loc2_)
  600.          {
  601.             _loc4_ = Number(focusableObjects[_loc3_].tabIndex);
  602.             if(!isNaN(_loc4_))
  603.             {
  604.                _loc1_ = Math.max(_loc1_,_loc4_);
  605.             }
  606.             _loc3_++;
  607.          }
  608.          return _loc1_;
  609.       }
  610.       
  611.       private function showHandler(param1:Event) : void
  612.       {
  613.          mx_internal::form.systemManager.activate(mx_internal::form);
  614.       }
  615.       
  616.       public function findFocusManagerComponent(param1:InteractiveObject) : IFocusManagerComponent
  617.       {
  618.          while(param1)
  619.          {
  620.             if(param1 is IFocusManagerComponent && IFocusManagerComponent(param1).focusEnabled)
  621.             {
  622.                return IFocusManagerComponent(param1);
  623.             }
  624.             param1 = param1.parent;
  625.          }
  626.          return null;
  627.       }
  628.       
  629.       public function setFocus(param1:IFocusManagerComponent) : void
  630.       {
  631.          param1.setFocus();
  632.       }
  633.       
  634.       mx_internal function set form(param1:IFocusManagerContainer) : void
  635.       {
  636.          _form = param1;
  637.       }
  638.       
  639.       private function sortFocusableObjectsTabIndex() : void
  640.       {
  641.          var _loc1_:int = 0;
  642.          var _loc2_:int = 0;
  643.          var _loc3_:IFocusManagerComponent = null;
  644.          focusableCandidates = [];
  645.          _loc1_ = int(focusableObjects.length);
  646.          _loc2_ = 0;
  647.          while(_loc2_ < _loc1_)
  648.          {
  649.             _loc3_ = focusableObjects[_loc2_];
  650.             if(Boolean(_loc3_.tabIndex) && !isNaN(Number(_loc3_.tabIndex)))
  651.             {
  652.                focusableCandidates.push(_loc3_);
  653.             }
  654.             _loc2_++;
  655.          }
  656.          focusableCandidates.sort(sortByTabIndex);
  657.       }
  658.       
  659.       public function set defaultButton(param1:IUIComponent) : void
  660.       {
  661.          var _loc2_:Button = null;
  662.          _loc2_ = !!param1 ? Button(param1) : null;
  663.          if(_loc2_ != _defaultButton)
  664.          {
  665.             if(_defaultButton)
  666.             {
  667.                _defaultButton.emphasized = false;
  668.             }
  669.             if(defButton)
  670.             {
  671.                defButton.emphasized = false;
  672.             }
  673.             _defaultButton = _loc2_;
  674.             defButton = _loc2_;
  675.             if(_loc2_)
  676.             {
  677.                _loc2_.emphasized = true;
  678.             }
  679.          }
  680.       }
  681.       
  682.       private function setFocusToNextObject(param1:FocusEvent) : void
  683.       {
  684.          var _loc2_:IFocusManagerComponent = null;
  685.          if(focusableObjects.length == 0)
  686.          {
  687.             return;
  688.          }
  689.          _loc2_ = getNextFocusManagerComponent(param1.shiftKey);
  690.          if(_loc2_)
  691.          {
  692.             setFocus(_loc2_);
  693.          }
  694.       }
  695.       
  696.       private function getTopLevelFocusTarget(param1:InteractiveObject) : InteractiveObject
  697.       {
  698.          while(param1 != InteractiveObject(mx_internal::form))
  699.          {
  700.             if(param1 is IFocusManagerComponent && IFocusManagerComponent(param1).focusEnabled && IFocusManagerComponent(param1).mouseFocusEnabled && IUIComponent(param1).enabled)
  701.             {
  702.                return param1;
  703.             }
  704.             param1 = param1.parent;
  705.             if(param1 == null)
  706.             {
  707.                break;
  708.             }
  709.          }
  710.          return null;
  711.       }
  712.       
  713.       private function hideHandler(param1:Event) : void
  714.       {
  715.          mx_internal::form.systemManager.deactivate(mx_internal::form);
  716.       }
  717.       
  718.       private function isEnabledAndVisible(param1:DisplayObject) : Boolean
  719.       {
  720.          var _loc2_:DisplayObjectContainer = null;
  721.          _loc2_ = DisplayObject(mx_internal::form).parent;
  722.          while(param1 != _loc2_)
  723.          {
  724.             if(param1 is IUIComponent)
  725.             {
  726.                if(!IUIComponent(param1).enabled)
  727.                {
  728.                   return false;
  729.                }
  730.             }
  731.             if(!param1.visible)
  732.             {
  733.                return false;
  734.             }
  735.             param1 = param1.parent;
  736.          }
  737.          return true;
  738.       }
  739.       
  740.       public function hideFocus() : void
  741.       {
  742.          if(showFocusIndicator)
  743.          {
  744.             showFocusIndicator = false;
  745.             if(lastFocus)
  746.             {
  747.                lastFocus.drawFocus(false);
  748.             }
  749.          }
  750.       }
  751.       
  752.       public function get showFocusIndicator() : Boolean
  753.       {
  754.          return _showFocusIndicator;
  755.       }
  756.       
  757.       mx_internal function get form() : IFocusManagerContainer
  758.       {
  759.          return _form;
  760.       }
  761.       
  762.       public function set focusPane(param1:Sprite) : void
  763.       {
  764.          _focusPane = param1;
  765.       }
  766.       
  767.       private function removedHandler(param1:Event) : void
  768.       {
  769.          var _loc2_:int = 0;
  770.          var _loc3_:DisplayObject = null;
  771.          _loc3_ = DisplayObject(param1.target);
  772.          if(_loc3_ is IFocusManagerComponent)
  773.          {
  774.             _loc2_ = 0;
  775.             while(_loc2_ < focusableObjects.length)
  776.             {
  777.                if(_loc3_ == focusableObjects[_loc2_])
  778.                {
  779.                   if(_loc3_ == lastFocus)
  780.                   {
  781.                      lastFocus.drawFocus(false);
  782.                      lastFocus = null;
  783.                   }
  784.                   _loc3_.removeEventListener("tabEnabledChange",tabEnabledChangeHandler);
  785.                   _loc3_.removeEventListener("tabIndexChange",tabIndexChangeHandler);
  786.                   focusableObjects.splice(_loc2_,1);
  787.                   calculateCandidates = true;
  788.                   break;
  789.                }
  790.                _loc2_++;
  791.             }
  792.          }
  793.          removeFocusables(_loc3_,false);
  794.       }
  795.       
  796.       private function activateHandler(param1:Event) : void
  797.       {
  798.          var _loc2_:InteractiveObject = null;
  799.          _loc2_ = InteractiveObject(param1.target);
  800.          if(Boolean(lastFocus) && !browserMode)
  801.          {
  802.             lastFocus.setFocus();
  803.          }
  804.          lastAction = "ACTIVATE";
  805.       }
  806.       
  807.       public function get defaultButton() : IUIComponent
  808.       {
  809.          return _defaultButton;
  810.       }
  811.       
  812.       public function showFocus() : void
  813.       {
  814.          if(!showFocusIndicator)
  815.          {
  816.             showFocusIndicator = true;
  817.             if(lastFocus)
  818.             {
  819.                lastFocus.drawFocus(true);
  820.             }
  821.          }
  822.       }
  823.       
  824.       public function getNextFocusManagerComponent(param1:Boolean = false) : IFocusManagerComponent
  825.       {
  826.          var _loc2_:DisplayObject = null;
  827.          var _loc3_:String = null;
  828.          var _loc4_:int = 0;
  829.          var _loc5_:Boolean = false;
  830.          var _loc6_:int = 0;
  831.          var _loc7_:int = 0;
  832.          var _loc8_:IFocusManagerGroup = null;
  833.          if(focusableObjects.length == 0)
  834.          {
  835.             return null;
  836.          }
  837.          if(calculateCandidates)
  838.          {
  839.             sortFocusableObjects();
  840.             calculateCandidates = false;
  841.          }
  842.          _loc2_ = mx_internal::form.systemManager.stage.focus;
  843.          _loc2_ = DisplayObject(findFocusManagerComponent(InteractiveObject(_loc2_)));
  844.          _loc3_ = "";
  845.          if(_loc2_ is IFocusManagerGroup)
  846.          {
  847.             _loc3_ = (_loc8_ = IFocusManagerGroup(_loc2_)).groupName;
  848.          }
  849.          _loc4_ = getIndexOfFocusedObject(_loc2_);
  850.          _loc5_ = false;
  851.          _loc6_ = _loc4_;
  852.          if(_loc4_ == -1)
  853.          {
  854.             if(param1)
  855.             {
  856.                _loc4_ = int(focusableCandidates.length);
  857.             }
  858.             _loc5_ = true;
  859.          }
  860.          _loc7_ = getIndexOfNextObject(_loc4_,param1,_loc5_,_loc3_);
  861.          return findFocusManagerComponent(focusableCandidates[_loc7_]);
  862.       }
  863.       
  864.       public function set defaultButtonEnabled(param1:Boolean) : void
  865.       {
  866.          _defaultButtonEnabled = param1;
  867.       }
  868.       
  869.       private function isTabVisible(param1:DisplayObject) : Boolean
  870.       {
  871.          var _loc2_:DisplayObject = null;
  872.          var _loc3_:DisplayObjectContainer = null;
  873.          _loc2_ = DisplayObject(mx_internal::form.systemManager);
  874.          if(!_loc2_)
  875.          {
  876.             return false;
  877.          }
  878.          _loc3_ = param1.parent;
  879.          while(Boolean(_loc3_) && _loc3_ != _loc2_)
  880.          {
  881.             if(!_loc3_.tabChildren)
  882.             {
  883.                return false;
  884.             }
  885.             _loc3_ = _loc3_.parent;
  886.          }
  887.          return true;
  888.       }
  889.       
  890.       public function set showFocusIndicator(param1:Boolean) : void
  891.       {
  892.          _showFocusIndicator = param1;
  893.       }
  894.       
  895.       private function sortByTabIndex(param1:IFocusManagerComponent, param2:IFocusManagerComponent) : int
  896.       {
  897.          var _loc3_:int = 0;
  898.          var _loc4_:int = 0;
  899.          _loc3_ = param1.tabIndex;
  900.          _loc4_ = param2.tabIndex;
  901.          if(_loc3_ == -1)
  902.          {
  903.             _loc3_ = int.MAX_VALUE;
  904.          }
  905.          if(_loc4_ == -1)
  906.          {
  907.             _loc4_ = int.MAX_VALUE;
  908.          }
  909.          return _loc3_ > _loc4_ ? 1 : (_loc3_ < _loc4_ ? -1 : int(sortByDepth(param1,param2)));
  910.       }
  911.       
  912.       public function activate() : void
  913.       {
  914.          if(activated)
  915.          {
  916.             return;
  917.          }
  918.          mx_internal::form.systemManager.stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler,false,0,true);
  919.          mx_internal::form.systemManager.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler,false,0,true);
  920.          mx_internal::form.addEventListener(FocusEvent.FOCUS_IN,focusInHandler,true);
  921.          mx_internal::form.addEventListener(FocusEvent.FOCUS_OUT,focusOutHandler,true);
  922.          mx_internal::form.systemManager.stage.addEventListener(Event.ACTIVATE,activateHandler,false,0,true);
  923.          mx_internal::form.systemManager.stage.addEventListener(Event.DEACTIVATE,deactivateHandler,false,0,true);
  924.          mx_internal::form.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  925.          mx_internal::form.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,true);
  926.          activated = true;
  927.          if(lastFocus)
  928.          {
  929.             setFocus(lastFocus);
  930.          }
  931.       }
  932.       
  933.       public function get defaultButtonEnabled() : Boolean
  934.       {
  935.          return _defaultButtonEnabled;
  936.       }
  937.       
  938.       private function creationCompleteHandler(param1:FlexEvent) : void
  939.       {
  940.          if(DisplayObject(mx_internal::form).visible && !activated)
  941.          {
  942.             mx_internal::form.systemManager.activate(mx_internal::form);
  943.          }
  944.       }
  945.       
  946.       private function tabEnabledChangeHandler(param1:Event) : void
  947.       {
  948.          var _loc2_:InteractiveObject = null;
  949.          var _loc3_:int = 0;
  950.          var _loc4_:int = 0;
  951.          calculateCandidates = true;
  952.          _loc2_ = InteractiveObject(param1.target);
  953.          _loc3_ = int(focusableObjects.length);
  954.          _loc4_ = 0;
  955.          while(_loc4_ < _loc3_)
  956.          {
  957.             if(focusableObjects[_loc4_] == _loc2_)
  958.             {
  959.                break;
  960.             }
  961.             _loc4_++;
  962.          }
  963.          if(_loc2_.tabEnabled)
  964.          {
  965.             if(_loc4_ == _loc3_ && isTabVisible(_loc2_))
  966.             {
  967.                focusableObjects.push(_loc2_);
  968.             }
  969.          }
  970.          else if(_loc4_ < _loc3_)
  971.          {
  972.             focusableObjects.splice(_loc4_,1);
  973.          }
  974.       }
  975.    }
  976. }
  977.