home *** CD-ROM | disk | FTP | other *** search
/ ftp.novell.com / 2014.06.ftp.novell.com.tar / ftp.novell.com / forge / camtasia.msi / Cabs.w1.cab / camtasia_player.swf83 / scripts / __Packages / mx / managers / DepthManager.as next >
Text File  |  2009-08-17  |  15KB  |  464 lines

  1. class mx.managers.DepthManager
  2. {
  3.    static var reservedDepth = 1048575;
  4.    static var highestDepth = 1048574;
  5.    static var lowestDepth = -16383;
  6.    static var numberOfAuthortimeLayers = 383;
  7.    static var kCursor = 101;
  8.    static var kTooltip = 102;
  9.    static var kTop = 201;
  10.    static var kBottom = 202;
  11.    static var kTopmost = 203;
  12.    static var kNotopmost = 204;
  13.    static var holder = _root.createEmptyMovieClip("reserved",mx.managers.DepthManager.reservedDepth);
  14.    static var __depthManager = new mx.managers.DepthManager();
  15.    function DepthManager()
  16.    {
  17.       MovieClip.prototype.createClassChildAtDepth = this.createClassChildAtDepth;
  18.       MovieClip.prototype.createChildAtDepth = this.createChildAtDepth;
  19.       MovieClip.prototype.setDepthTo = this.setDepthTo;
  20.       MovieClip.prototype.setDepthAbove = this.setDepthAbove;
  21.       MovieClip.prototype.setDepthBelow = this.setDepthBelow;
  22.       MovieClip.prototype.findNextAvailableDepth = this.findNextAvailableDepth;
  23.       MovieClip.prototype.shuffleDepths = this.shuffleDepths;
  24.       MovieClip.prototype.getDepthByFlag = this.getDepthByFlag;
  25.       MovieClip.prototype.buildDepthTable = this.buildDepthTable;
  26.       _global.ASSetPropFlags(MovieClip.prototype,"createClassChildAtDepth",1);
  27.       _global.ASSetPropFlags(MovieClip.prototype,"createChildAtDepth",1);
  28.       _global.ASSetPropFlags(MovieClip.prototype,"setDepthTo",1);
  29.       _global.ASSetPropFlags(MovieClip.prototype,"setDepthAbove",1);
  30.       _global.ASSetPropFlags(MovieClip.prototype,"setDepthBelow",1);
  31.       _global.ASSetPropFlags(MovieClip.prototype,"findNextAvailableDepth",1);
  32.       _global.ASSetPropFlags(MovieClip.prototype,"shuffleDepths",1);
  33.       _global.ASSetPropFlags(MovieClip.prototype,"getDepthByFlag",1);
  34.       _global.ASSetPropFlags(MovieClip.prototype,"buildDepthTable",1);
  35.    }
  36.    static function sortFunction(a, b)
  37.    {
  38.       if(a.getDepth() > b.getDepth())
  39.       {
  40.          return 1;
  41.       }
  42.       return -1;
  43.    }
  44.    static function test(depth)
  45.    {
  46.       if(depth == mx.managers.DepthManager.reservedDepth)
  47.       {
  48.          return false;
  49.       }
  50.       return true;
  51.    }
  52.    static function createClassObjectAtDepth(className, depthSpace, initObj)
  53.    {
  54.       var _loc1_ = undefined;
  55.       switch(depthSpace)
  56.       {
  57.          case mx.managers.DepthManager.kCursor:
  58.             _loc1_ = mx.managers.DepthManager.holder.createClassChildAtDepth(className,mx.managers.DepthManager.kTopmost,initObj);
  59.             break;
  60.          case mx.managers.DepthManager.kTooltip:
  61.             _loc1_ = mx.managers.DepthManager.holder.createClassChildAtDepth(className,mx.managers.DepthManager.kTop,initObj);
  62.       }
  63.       return _loc1_;
  64.    }
  65.    static function createObjectAtDepth(linkageName, depthSpace, initObj)
  66.    {
  67.       var _loc1_ = undefined;
  68.       switch(depthSpace)
  69.       {
  70.          case mx.managers.DepthManager.kCursor:
  71.             _loc1_ = mx.managers.DepthManager.holder.createChildAtDepth(linkageName,mx.managers.DepthManager.kTopmost,initObj);
  72.             break;
  73.          case mx.managers.DepthManager.kTooltip:
  74.             _loc1_ = mx.managers.DepthManager.holder.createChildAtDepth(linkageName,mx.managers.DepthManager.kTop,initObj);
  75.       }
  76.       return _loc1_;
  77.    }
  78.    function createClassChildAtDepth(className, depthFlag, initObj)
  79.    {
  80.       if(this._childCounter == undefined)
  81.       {
  82.          this._childCounter = 0;
  83.       }
  84.       var _loc3_ = this.buildDepthTable();
  85.       var _loc2_ = this.getDepthByFlag(depthFlag,_loc3_);
  86.       var _loc6_ = "down";
  87.       if(depthFlag == mx.managers.DepthManager.kBottom)
  88.       {
  89.          _loc6_ = "up";
  90.       }
  91.       var _loc5_ = undefined;
  92.       if(_loc3_[_loc2_] != undefined)
  93.       {
  94.          _loc5_ = _loc2_;
  95.          _loc2_ = this.findNextAvailableDepth(_loc2_,_loc3_,_loc6_);
  96.       }
  97.       var _loc4_ = this.createClassObject(className,"depthChild" + this._childCounter++,_loc2_,initObj);
  98.       if(_loc5_ != undefined)
  99.       {
  100.          _loc3_[_loc2_] = _loc4_;
  101.          this.shuffleDepths(_loc4_,_loc5_,_loc3_,_loc6_);
  102.       }
  103.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  104.       {
  105.          _loc4_._topmost = true;
  106.       }
  107.       return _loc4_;
  108.    }
  109.    function createChildAtDepth(linkageName, depthFlag, initObj)
  110.    {
  111.       if(this._childCounter == undefined)
  112.       {
  113.          this._childCounter = 0;
  114.       }
  115.       var _loc3_ = this.buildDepthTable();
  116.       var _loc2_ = this.getDepthByFlag(depthFlag,_loc3_);
  117.       var _loc6_ = "down";
  118.       if(depthFlag == mx.managers.DepthManager.kBottom)
  119.       {
  120.          _loc6_ = "up";
  121.       }
  122.       var _loc5_ = undefined;
  123.       if(_loc3_[_loc2_] != undefined)
  124.       {
  125.          _loc5_ = _loc2_;
  126.          _loc2_ = this.findNextAvailableDepth(_loc2_,_loc3_,_loc6_);
  127.       }
  128.       var _loc4_ = this.createObject(linkageName,"depthChild" + this._childCounter++,_loc2_,initObj);
  129.       if(_loc5_ != undefined)
  130.       {
  131.          _loc3_[_loc2_] = _loc4_;
  132.          this.shuffleDepths(_loc4_,_loc5_,_loc3_,_loc6_);
  133.       }
  134.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  135.       {
  136.          _loc4_._topmost = true;
  137.       }
  138.       return _loc4_;
  139.    }
  140.    function setDepthTo(depthFlag)
  141.    {
  142.       var _loc2_ = this._parent.buildDepthTable();
  143.       var _loc3_ = this._parent.getDepthByFlag(depthFlag,_loc2_);
  144.       if(_loc2_[_loc3_] != undefined)
  145.       {
  146.          this.shuffleDepths(this,_loc3_,_loc2_,undefined);
  147.       }
  148.       else
  149.       {
  150.          this.swapDepths(_loc3_);
  151.       }
  152.       if(depthFlag == mx.managers.DepthManager.kTopmost)
  153.       {
  154.          this._topmost = true;
  155.       }
  156.       else
  157.       {
  158.          delete this._topmost;
  159.       }
  160.    }
  161.    function setDepthAbove(targetInstance)
  162.    {
  163.       if(targetInstance._parent != this._parent)
  164.       {
  165.          return undefined;
  166.       }
  167.       var _loc2_ = targetInstance.getDepth() + 1;
  168.       var _loc3_ = this._parent.buildDepthTable();
  169.       if(_loc3_[_loc2_] != undefined && this.getDepth() < _loc2_)
  170.       {
  171.          _loc2_ -= 1;
  172.       }
  173.       if(_loc2_ > mx.managers.DepthManager.highestDepth)
  174.       {
  175.          _loc2_ = mx.managers.DepthManager.highestDepth;
  176.       }
  177.       if(_loc2_ == mx.managers.DepthManager.highestDepth)
  178.       {
  179.          this._parent.shuffleDepths(this,_loc2_,_loc3_,"down");
  180.       }
  181.       else if(_loc3_[_loc2_] != undefined)
  182.       {
  183.          this._parent.shuffleDepths(this,_loc2_,_loc3_,undefined);
  184.       }
  185.       else
  186.       {
  187.          this.swapDepths(_loc2_);
  188.       }
  189.    }
  190.    function setDepthBelow(targetInstance)
  191.    {
  192.       if(targetInstance._parent != this._parent)
  193.       {
  194.          return undefined;
  195.       }
  196.       var _loc6_ = targetInstance.getDepth() - 1;
  197.       var _loc3_ = this._parent.buildDepthTable();
  198.       if(_loc3_[_loc6_] != undefined && this.getDepth() > _loc6_)
  199.       {
  200.          _loc6_ += 1;
  201.       }
  202.       var _loc4_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  203.       var _loc5_ = undefined;
  204.       for(_loc5_ in _loc3_)
  205.       {
  206.          var _loc2_ = _loc3_[_loc5_];
  207.          if(_loc2_._parent != undefined)
  208.          {
  209.             _loc4_ = Math.min(_loc4_,_loc2_.getDepth());
  210.          }
  211.       }
  212.       if(_loc6_ < _loc4_)
  213.       {
  214.          _loc6_ = _loc4_;
  215.       }
  216.       if(_loc6_ == _loc4_)
  217.       {
  218.          this._parent.shuffleDepths(this,_loc6_,_loc3_,"up");
  219.       }
  220.       else if(_loc3_[_loc6_] != undefined)
  221.       {
  222.          this._parent.shuffleDepths(this,_loc6_,_loc3_,undefined);
  223.       }
  224.       else
  225.       {
  226.          this.swapDepths(_loc6_);
  227.       }
  228.    }
  229.    function findNextAvailableDepth(targetDepth, depthTable, direction)
  230.    {
  231.       var _loc5_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  232.       if(targetDepth < _loc5_)
  233.       {
  234.          targetDepth = _loc5_;
  235.       }
  236.       if(depthTable[targetDepth] == undefined)
  237.       {
  238.          return targetDepth;
  239.       }
  240.       var _loc2_ = targetDepth;
  241.       var _loc1_ = targetDepth;
  242.       if(direction == "down")
  243.       {
  244.          while(depthTable[_loc1_] != undefined)
  245.          {
  246.             _loc1_ = _loc1_ - 1;
  247.          }
  248.          return _loc1_;
  249.       }
  250.       while(depthTable[_loc2_] != undefined)
  251.       {
  252.          _loc2_ = _loc2_ + 1;
  253.       }
  254.       return _loc2_;
  255.    }
  256.    function shuffleDepths(subject, targetDepth, depthTable, direction)
  257.    {
  258.       var _loc9_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  259.       var _loc8_ = _loc9_;
  260.       var _loc5_ = undefined;
  261.       for(_loc5_ in depthTable)
  262.       {
  263.          var _loc7_ = depthTable[_loc5_];
  264.          if(_loc7_._parent != undefined)
  265.          {
  266.             _loc9_ = Math.min(_loc9_,_loc7_.getDepth());
  267.          }
  268.       }
  269.       if(direction == undefined)
  270.       {
  271.          if(subject.getDepth() > targetDepth)
  272.          {
  273.             direction = "up";
  274.          }
  275.          else
  276.          {
  277.             direction = "down";
  278.          }
  279.       }
  280.       var _loc1_ = new Array();
  281.       for(_loc5_ in depthTable)
  282.       {
  283.          _loc7_ = depthTable[_loc5_];
  284.          if(_loc7_._parent != undefined)
  285.          {
  286.             _loc1_.push(_loc7_);
  287.          }
  288.       }
  289.       _loc1_.sort(mx.managers.DepthManager.sortFunction);
  290.       if(direction == "up")
  291.       {
  292.          var _loc3_ = undefined;
  293.          var _loc11_ = undefined;
  294.          while(_loc1_.length > 0)
  295.          {
  296.             _loc3_ = _loc1_.pop();
  297.             if(_loc3_ == subject)
  298.             {
  299.                break;
  300.             }
  301.          }
  302.          while(_loc1_.length > 0)
  303.          {
  304.             _loc11_ = subject.getDepth();
  305.             _loc3_ = _loc1_.pop();
  306.             var _loc4_ = _loc3_.getDepth();
  307.             if(_loc11_ > _loc4_ + 1)
  308.             {
  309.                if(_loc4_ >= 0)
  310.                {
  311.                   subject.swapDepths(_loc4_ + 1);
  312.                }
  313.                else if(_loc11_ > _loc8_ && _loc4_ < _loc8_)
  314.                {
  315.                   subject.swapDepths(_loc8_);
  316.                }
  317.             }
  318.             subject.swapDepths(_loc3_);
  319.             if(_loc4_ == targetDepth)
  320.             {
  321.                break;
  322.             }
  323.          }
  324.       }
  325.       else if(direction == "down")
  326.       {
  327.          _loc3_ = undefined;
  328.          while(_loc1_.length > 0)
  329.          {
  330.             _loc3_ = _loc1_.shift();
  331.             if(_loc3_ == subject)
  332.             {
  333.                break;
  334.             }
  335.          }
  336.          while(_loc1_.length > 0)
  337.          {
  338.             _loc11_ = _loc3_.getDepth();
  339.             _loc3_ = _loc1_.shift();
  340.             _loc4_ = _loc3_.getDepth();
  341.             if(_loc11_ < _loc4_ - 1 && _loc4_ > 0)
  342.             {
  343.                subject.swapDepths(_loc4_ - 1);
  344.             }
  345.             subject.swapDepths(_loc3_);
  346.             if(_loc4_ == targetDepth)
  347.             {
  348.                break;
  349.             }
  350.          }
  351.       }
  352.    }
  353.    function getDepthByFlag(depthFlag, depthTable)
  354.    {
  355.       var _loc2_ = 0;
  356.       if(depthFlag == mx.managers.DepthManager.kTop || depthFlag == mx.managers.DepthManager.kNotopmost)
  357.       {
  358.          var _loc5_ = 0;
  359.          var _loc7_ = false;
  360.          var _loc8_ = undefined;
  361.          for(_loc8_ in depthTable)
  362.          {
  363.             var _loc9_ = depthTable[_loc8_];
  364.             var _loc3_ = typeof _loc9_;
  365.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  366.             {
  367.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  368.                {
  369.                   if(!_loc9_._topmost)
  370.                   {
  371.                      _loc2_ = Math.max(_loc2_,_loc9_.getDepth());
  372.                   }
  373.                   else if(!_loc7_)
  374.                   {
  375.                      _loc5_ = _loc9_.getDepth();
  376.                      _loc7_ = true;
  377.                   }
  378.                   else
  379.                   {
  380.                      _loc5_ = Math.min(_loc5_,_loc9_.getDepth());
  381.                   }
  382.                }
  383.             }
  384.          }
  385.          _loc2_ += 20;
  386.          if(_loc7_)
  387.          {
  388.             if(_loc2_ >= _loc5_)
  389.             {
  390.                _loc2_ = _loc5_ - 1;
  391.             }
  392.          }
  393.       }
  394.       else if(depthFlag == mx.managers.DepthManager.kBottom)
  395.       {
  396.          for(_loc8_ in depthTable)
  397.          {
  398.             _loc9_ = depthTable[_loc8_];
  399.             _loc3_ = typeof _loc9_;
  400.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  401.             {
  402.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  403.                {
  404.                   _loc2_ = Math.min(_loc2_,_loc9_.getDepth());
  405.                }
  406.             }
  407.          }
  408.          _loc2_ -= 20;
  409.       }
  410.       else if(depthFlag == mx.managers.DepthManager.kTopmost)
  411.       {
  412.          for(_loc8_ in depthTable)
  413.          {
  414.             _loc9_ = depthTable[_loc8_];
  415.             _loc3_ = typeof _loc9_;
  416.             if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc9_.__getTextFormat != undefined)
  417.             {
  418.                if(_loc9_.getDepth() <= mx.managers.DepthManager.highestDepth)
  419.                {
  420.                   _loc2_ = Math.max(_loc2_,_loc9_.getDepth());
  421.                }
  422.             }
  423.          }
  424.          _loc2_ += 100;
  425.       }
  426.       if(_loc2_ >= mx.managers.DepthManager.highestDepth)
  427.       {
  428.          _loc2_ = mx.managers.DepthManager.highestDepth;
  429.       }
  430.       var _loc6_ = mx.managers.DepthManager.lowestDepth + mx.managers.DepthManager.numberOfAuthortimeLayers;
  431.       for(_loc9_ in depthTable)
  432.       {
  433.          var _loc4_ = depthTable[_loc9_];
  434.          if(_loc4_._parent != undefined)
  435.          {
  436.             _loc6_ = Math.min(_loc6_,_loc4_.getDepth());
  437.          }
  438.       }
  439.       if(_loc2_ <= _loc6_)
  440.       {
  441.          _loc2_ = _loc6_;
  442.       }
  443.       return _loc2_;
  444.    }
  445.    function buildDepthTable(Void)
  446.    {
  447.       var _loc5_ = new Array();
  448.       var _loc4_ = undefined;
  449.       for(_loc4_ in this)
  450.       {
  451.          var _loc2_ = this[_loc4_];
  452.          var _loc3_ = typeof _loc2_;
  453.          if(_loc3_ == "movieclip" || _loc3_ == "object" && _loc2_.__getTextFormat != undefined)
  454.          {
  455.             if(_loc2_._parent == this)
  456.             {
  457.                _loc5_[_loc2_.getDepth()] = _loc2_;
  458.             }
  459.          }
  460.       }
  461.       return _loc5_;
  462.    }
  463. }
  464.