home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 April / ME_04_2012.iso / Video-Tutorial / iPhoto / media / player.swf / scripts / mx / managers / DragManagerImpl.as < prev    next >
Encoding:
Text File  |  2011-11-11  |  9.4 KB  |  284 lines

  1. package mx.managers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import flash.events.IEventDispatcher;
  7.    import flash.events.MouseEvent;
  8.    import flash.geom.Matrix;
  9.    import flash.geom.Point;
  10.    import mx.core.DragSource;
  11.    import mx.core.IFlexDisplayObject;
  12.    import mx.core.IFlexModule;
  13.    import mx.core.IFlexModuleFactory;
  14.    import mx.core.ILayoutDirectionElement;
  15.    import mx.core.IUIComponent;
  16.    import mx.core.LayoutDirection;
  17.    import mx.core.UIComponentGlobals;
  18.    import mx.core.mx_internal;
  19.    import mx.events.DragEvent;
  20.    import mx.events.Request;
  21.    import mx.managers.dragClasses.DragProxy;
  22.    import mx.styles.CSSStyleDeclaration;
  23.    import mx.styles.IStyleManager2;
  24.    import mx.styles.StyleManager;
  25.    import mx.utils.MatrixUtil;
  26.    
  27.    use namespace mx_internal;
  28.    
  29.    public class DragManagerImpl extends EventDispatcher implements IDragManager
  30.    {
  31.       private static var sm:ISystemManager;
  32.       
  33.       private static var instance:IDragManager;
  34.       
  35.       public static var mixins:Array;
  36.       
  37.       mx_internal static const VERSION:String = "4.5.0.20967";
  38.       
  39.       private var sandboxRoot:IEventDispatcher;
  40.       
  41.       private var dragInitiator:IUIComponent;
  42.       
  43.       public var dragProxy:DragProxy;
  44.       
  45.       public var bDoingDrag:Boolean = false;
  46.       
  47.       private var mouseIsDown:Boolean = false;
  48.       
  49.       public function DragManagerImpl()
  50.       {
  51.          var _loc1_:int = 0;
  52.          var _loc2_:int = 0;
  53.          super();
  54.          if(instance)
  55.          {
  56.             throw new Error("Instance already exists.");
  57.          }
  58.          if(mixins)
  59.          {
  60.             _loc1_ = int(mixins.length);
  61.             _loc2_ = 0;
  62.             while(_loc2_ < _loc1_)
  63.             {
  64.                new mixins[_loc2_](this);
  65.                _loc2_++;
  66.             }
  67.          }
  68.          this.sandboxRoot = sm.getSandboxRoot();
  69.          if(sm.isTopLevelRoot())
  70.          {
  71.             sm.addEventListener(MouseEvent.MOUSE_DOWN,this.sm_mouseDownHandler,false,0,true);
  72.             sm.addEventListener(MouseEvent.MOUSE_UP,this.sm_mouseUpHandler,false,0,true);
  73.          }
  74.          if(hasEventListener("initialize"))
  75.          {
  76.             dispatchEvent(new Event("initialize"));
  77.          }
  78.       }
  79.       
  80.       public static function getInstance() : IDragManager
  81.       {
  82.          if(!instance)
  83.          {
  84.             sm = SystemManagerGlobals.topLevelSystemManagers[0];
  85.             instance = new DragManagerImpl();
  86.          }
  87.          return instance;
  88.       }
  89.       
  90.       private static function getStyleManager(param1:IUIComponent) : IStyleManager2
  91.       {
  92.          if(param1 is IFlexModule)
  93.          {
  94.             return StyleManager.getStyleManager(IFlexModule(param1).moduleFactory);
  95.          }
  96.          return StyleManager.getStyleManager(sm as IFlexModuleFactory);
  97.       }
  98.       
  99.       public function get isDragging() : Boolean
  100.       {
  101.          return this.bDoingDrag;
  102.       }
  103.       
  104.       public function doDrag(param1:IUIComponent, param2:DragSource, param3:MouseEvent, param4:IFlexDisplayObject = null, param5:Number = 0, param6:Number = 0, param7:Number = 0.5, param8:Boolean = true) : void
  105.       {
  106.          var _loc9_:Number = NaN;
  107.          var _loc10_:Number = NaN;
  108.          var _loc11_:Event = null;
  109.          var _loc20_:CSSStyleDeclaration = null;
  110.          var _loc21_:Class = null;
  111.          if(this.bDoingDrag)
  112.          {
  113.             return;
  114.          }
  115.          if(!(param3.type == MouseEvent.MOUSE_DOWN || param3.type == MouseEvent.CLICK || this.mouseIsDown || param3.buttonDown))
  116.          {
  117.             return;
  118.          }
  119.          this.bDoingDrag = true;
  120.          if(hasEventListener("doDrag"))
  121.          {
  122.             dispatchEvent(new Event("doDrag"));
  123.          }
  124.          this.dragInitiator = param1;
  125.          this.dragProxy = new DragProxy(param1,param2);
  126.          if(hasEventListener("popUpChildren"))
  127.          {
  128.             _loc11_ = new DragEvent("popUpChildren",false,true,this.dragProxy);
  129.          }
  130.          if(!_loc11_ || dispatchEvent(_loc11_))
  131.          {
  132.             sm.popUpChildren.addChild(this.dragProxy);
  133.          }
  134.          if(!param4)
  135.          {
  136.             _loc20_ = getStyleManager(param1).getMergedStyleDeclaration("mx.managers.DragManager");
  137.             _loc21_ = _loc20_.getStyle("defaultDragImageSkin");
  138.             param4 = new _loc21_();
  139.             this.dragProxy.addChild(DisplayObject(param4));
  140.             _loc9_ = Number(param1.width);
  141.             _loc10_ = Number(param1.height);
  142.          }
  143.          else
  144.          {
  145.             this.dragProxy.addChild(DisplayObject(param4));
  146.             if(param4 is ILayoutManagerClient)
  147.             {
  148.                UIComponentGlobals.mx_internal::layoutManager.validateClient(ILayoutManagerClient(param4),true);
  149.             }
  150.             if(param4 is IUIComponent)
  151.             {
  152.                _loc9_ = Number((param4 as IUIComponent).getExplicitOrMeasuredWidth());
  153.                _loc10_ = Number((param4 as IUIComponent).getExplicitOrMeasuredHeight());
  154.             }
  155.             else
  156.             {
  157.                _loc9_ = Number(param4.measuredWidth);
  158.                _loc10_ = Number(param4.measuredHeight);
  159.             }
  160.          }
  161.          if(param1 is ILayoutDirectionElement && ILayoutDirectionElement(param1).layoutDirection == LayoutDirection.RTL)
  162.          {
  163.             this.dragProxy.layoutDirection = LayoutDirection.RTL;
  164.          }
  165.          param4.setActualSize(_loc9_,_loc10_);
  166.          this.dragProxy.setActualSize(_loc9_,_loc10_);
  167.          this.dragProxy.alpha = param7;
  168.          this.dragProxy.allowMove = param8;
  169.          var _loc12_:Matrix = MatrixUtil.getConcatenatedMatrix(DisplayObject(param1),DisplayObject(this.sandboxRoot));
  170.          _loc12_.tx = 0;
  171.          _loc12_.ty = 0;
  172.          var _loc13_:Matrix = param4.transform.matrix;
  173.          if(_loc13_)
  174.          {
  175.             _loc12_.concat(param4.transform.matrix);
  176.             param4.transform.matrix = _loc12_;
  177.          }
  178.          var _loc14_:Object = param3.target;
  179.          if(_loc14_ == null)
  180.          {
  181.             _loc14_ = param1;
  182.          }
  183.          var _loc15_:Point = new Point(param3.localX,param3.localY);
  184.          _loc15_ = DisplayObject(_loc14_).localToGlobal(_loc15_);
  185.          _loc15_ = DisplayObject(this.sandboxRoot).globalToLocal(_loc15_);
  186.          var _loc16_:Number = _loc15_.x;
  187.          var _loc17_:Number = _loc15_.y;
  188.          var _loc18_:Point = DisplayObject(param1).localToGlobal(new Point(-param5,-param6));
  189.          _loc18_ = DisplayObject(this.sandboxRoot).globalToLocal(_loc18_);
  190.          this.dragProxy.xOffset = _loc16_ - _loc18_.x;
  191.          this.dragProxy.yOffset = _loc17_ - _loc18_.y;
  192.          this.dragProxy.x = _loc18_.x;
  193.          this.dragProxy.y = _loc18_.y;
  194.          this.dragProxy.startX = this.dragProxy.x;
  195.          this.dragProxy.startY = this.dragProxy.y;
  196.          if(param4 is DisplayObject)
  197.          {
  198.             DisplayObject(param4).cacheAsBitmap = true;
  199.          }
  200.          var _loc19_:Object = this.dragProxy.automationDelegate;
  201.          if(_loc19_)
  202.          {
  203.             _loc19_.recordAutomatableDragStart(param1,param3);
  204.          }
  205.       }
  206.       
  207.       public function acceptDragDrop(param1:IUIComponent) : void
  208.       {
  209.          if(this.dragProxy)
  210.          {
  211.             this.dragProxy.target = param1 as DisplayObject;
  212.          }
  213.          if(hasEventListener("acceptDragDrop"))
  214.          {
  215.             dispatchEvent(new Request("acceptDragDrop",false,false,param1));
  216.          }
  217.       }
  218.       
  219.       public function showFeedback(param1:String) : void
  220.       {
  221.          if(this.dragProxy)
  222.          {
  223.             if(param1 == DragManager.MOVE && !this.dragProxy.allowMove)
  224.             {
  225.                param1 = DragManager.COPY;
  226.             }
  227.             this.dragProxy.action = param1;
  228.          }
  229.          if(hasEventListener("showFeedback"))
  230.          {
  231.             dispatchEvent(new Request("showFeedback",false,false,param1));
  232.          }
  233.       }
  234.       
  235.       public function getFeedback() : String
  236.       {
  237.          var _loc1_:Request = null;
  238.          if(hasEventListener("getFeedback"))
  239.          {
  240.             _loc1_ = new Request("getFeedback",false,true);
  241.             if(!dispatchEvent(_loc1_))
  242.             {
  243.                return _loc1_.value as String;
  244.             }
  245.          }
  246.          return !!this.dragProxy ? this.dragProxy.action : DragManager.NONE;
  247.       }
  248.       
  249.       public function endDrag() : void
  250.       {
  251.          var _loc1_:Event = null;
  252.          if(hasEventListener("endDrag"))
  253.          {
  254.             _loc1_ = new Event("endDrag",false,true);
  255.          }
  256.          if(!_loc1_ || dispatchEvent(_loc1_))
  257.          {
  258.             if(this.dragProxy)
  259.             {
  260.                sm.popUpChildren.removeChild(this.dragProxy);
  261.                if(this.dragProxy.numChildren > 0)
  262.                {
  263.                   this.dragProxy.removeChildAt(0);
  264.                }
  265.                this.dragProxy = null;
  266.             }
  267.          }
  268.          this.dragInitiator = null;
  269.          this.bDoingDrag = false;
  270.       }
  271.       
  272.       private function sm_mouseDownHandler(param1:MouseEvent) : void
  273.       {
  274.          this.mouseIsDown = true;
  275.       }
  276.       
  277.       private function sm_mouseUpHandler(param1:MouseEvent) : void
  278.       {
  279.          this.mouseIsDown = false;
  280.       }
  281.    }
  282. }
  283.  
  284.