home *** CD-ROM | disk | FTP | other *** search
/ The Complete Idiot's Guide to Microsoft Excel 2010 / CIGExcel.iso / Videos / Flash / controller.swf / scripts / __Packages / mx / containers / ScrollPane.as next >
Encoding:
Text File  |  2010-09-09  |  8.6 KB  |  288 lines

  1. class mx.containers.ScrollPane extends mx.core.ScrollView
  2. {
  3.    var _total;
  4.    var _loaded;
  5.    var __scrollContent;
  6.    var spContentHolder;
  7.    var hScroller;
  8.    var vScroller;
  9.    var onMouseMove;
  10.    var keyDown;
  11.    var mask_mc;
  12.    var hPosition;
  13.    var vPosition;
  14.    var lastX;
  15.    var lastY;
  16.    var hLineScrollSize;
  17.    var vPageScrollSize;
  18.    var vLineScrollSize;
  19.    static var symbolName = "ScrollPane";
  20.    static var symbolOwner = mx.containers.ScrollPane;
  21.    var className = "ScrollPane";
  22.    static var version = "2.0.2.126";
  23.    var __hScrollPolicy = "auto";
  24.    var __scrollDrag = false;
  25.    var __vLineScrollSize = 5;
  26.    var __hLineScrollSize = 5;
  27.    var __vPageScrollSize = 20;
  28.    var __hPageScrollSize = 20;
  29.    var clipParameters = {contentPath:1,scrollDrag:1,hScrollPolicy:1,vScrollPolicy:1,vLineScrollSize:1,hLineScrollSize:1,vPageScrollSize:1,hPageScrollSize:1};
  30.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.containers.ScrollPane.prototype.clipParameters,mx.core.ScrollView.prototype.clipParameters);
  31.    var initializing = true;
  32.    function ScrollPane()
  33.    {
  34.       super();
  35.    }
  36.    function getBytesTotal()
  37.    {
  38.       return this._total;
  39.    }
  40.    function getBytesLoaded()
  41.    {
  42.       return this._loaded;
  43.    }
  44.    function set contentPath(scrollableContent)
  45.    {
  46.       if(!this.initializing)
  47.       {
  48.          if(scrollableContent == undefined)
  49.          {
  50.             this.destroyChildAt(0);
  51.          }
  52.          else
  53.          {
  54.             if(this[mx.core.View.childNameBase + 0] != undefined)
  55.             {
  56.                this.destroyChildAt(0);
  57.             }
  58.             this.createChild(scrollableContent,"spContentHolder");
  59.          }
  60.       }
  61.       this.__scrollContent = scrollableContent;
  62.    }
  63.    function get contentPath()
  64.    {
  65.       return this.__scrollContent;
  66.    }
  67.    function get content()
  68.    {
  69.       return this.spContentHolder;
  70.    }
  71.    function setHPosition(position)
  72.    {
  73.       if(position <= this.hScroller.maxPos && position >= this.hScroller.minPos)
  74.       {
  75.          super.setHPosition(position);
  76.          this.spContentHolder._x = - position;
  77.       }
  78.    }
  79.    function setVPosition(position)
  80.    {
  81.       if(position <= this.vScroller.maxPos && position >= this.vScroller.minPos)
  82.       {
  83.          super.setVPosition(position);
  84.          this.spContentHolder._y = - position;
  85.       }
  86.    }
  87.    function get vLineScrollSize()
  88.    {
  89.       return this.__vLineScrollSize;
  90.    }
  91.    function set vLineScrollSize(vLineSize)
  92.    {
  93.       this.__vLineScrollSize = vLineSize;
  94.       this.vScroller.lineScrollSize = vLineSize;
  95.    }
  96.    function get hLineScrollSize()
  97.    {
  98.       return this.__hLineScrollSize;
  99.    }
  100.    function set hLineScrollSize(hLineSize)
  101.    {
  102.       this.__hLineScrollSize = hLineSize;
  103.       this.hScroller.lineScrollSize = hLineSize;
  104.    }
  105.    function get vPageScrollSize()
  106.    {
  107.       return this.__vPageScrollSize;
  108.    }
  109.    function set vPageScrollSize(vPageSize)
  110.    {
  111.       this.__vPageScrollSize = vPageSize;
  112.       this.vScroller.pageScrollSize = vPageSize;
  113.    }
  114.    function get hPageScrollSize()
  115.    {
  116.       return this.__hPageScrollSize;
  117.    }
  118.    function set hPageScrollSize(hPageSize)
  119.    {
  120.       this.__hPageScrollSize = hPageSize;
  121.       this.hScroller.pageScrollSize = hPageSize;
  122.    }
  123.    function set hScrollPolicy(policy)
  124.    {
  125.       this.__hScrollPolicy = policy.toLowerCase();
  126.       this.setScrollProperties(this.spContentHolder._width,1,this.spContentHolder._height,1);
  127.    }
  128.    function set vScrollPolicy(policy)
  129.    {
  130.       this.__vScrollPolicy = policy.toLowerCase();
  131.       this.setScrollProperties(this.spContentHolder._width,1,this.spContentHolder._height,1);
  132.    }
  133.    function get scrollDrag()
  134.    {
  135.       return this.__scrollDrag;
  136.    }
  137.    function set scrollDrag(s)
  138.    {
  139.       this.__scrollDrag = s;
  140.       if(this.__scrollDrag)
  141.       {
  142.          this.spContentHolder.useHandCursor = true;
  143.          this.spContentHolder.onPress = function()
  144.          {
  145.             this._parent.startDragLoop();
  146.          };
  147.          this.spContentHolder.tabEnabled = false;
  148.          this.spContentHolder.onRelease = this.spContentHolder.onReleaseOutside = function()
  149.          {
  150.             delete this.onMouseMove;
  151.          };
  152.          this.__scrollDrag = true;
  153.       }
  154.       else
  155.       {
  156.          delete this.spContentHolder.onPress;
  157.          this.spContentHolder.tabEnabled = false;
  158.          this.spContentHolder.tabChildren = true;
  159.          this.spContentHolder.useHandCursor = false;
  160.          this.__scrollDrag = false;
  161.       }
  162.    }
  163.    function init(Void)
  164.    {
  165.       super.init();
  166.       this.tabEnabled = true;
  167.       this.keyDown = this._onKeyDown;
  168.    }
  169.    function createChildren(Void)
  170.    {
  171.       super.createChildren();
  172.       this.mask_mc._visible = false;
  173.       this.initializing = false;
  174.       if(this.__scrollContent != undefined && this.__scrollContent != "")
  175.       {
  176.          this.contentPath = this.__scrollContent;
  177.       }
  178.    }
  179.    function size(Void)
  180.    {
  181.       super.size();
  182.       this.setScrollProperties(this.spContentHolder._width,1,this.spContentHolder._height + 20,1);
  183.       this.hPosition = Math.min(this.hPosition,this.maxHPosition);
  184.       this.vPosition = Math.min(this.vPosition,this.maxVPosition);
  185.    }
  186.    function setScrollProperties(columnCount, columnWidth, rowCount, rowHeight)
  187.    {
  188.       super.setScrollProperties(columnCount,columnWidth,rowCount,rowHeight);
  189.       this.hScroller.lineScrollSize = this.__hLineScrollSize;
  190.       this.hScroller.pageScrollSize = this.__hPageScrollSize;
  191.       this.vScroller.lineScrollSize = this.__vLineScrollSize;
  192.       this.vScroller.pageScrollSize = this.__vPageScrollSize;
  193.    }
  194.    function onScroll(scrollEvent)
  195.    {
  196.       this.spContentHolder._x = - this.__hPosition;
  197.       this.spContentHolder._y = - this.__vPosition;
  198.       super.onScroll(scrollEvent);
  199.    }
  200.    function childLoaded(obj)
  201.    {
  202.       super.childLoaded(obj);
  203.       this.onComplete();
  204.    }
  205.    function onComplete(Void)
  206.    {
  207.       this.setScrollProperties(this.spContentHolder._width,1,this.spContentHolder._height,1);
  208.       this.hPosition = 0;
  209.       this.vPosition = 0;
  210.       this.scrollDrag = this.__scrollDrag;
  211.       this.invalidate();
  212.    }
  213.    function startDragLoop(Void)
  214.    {
  215.       this.spContentHolder.lastX = this.spContentHolder._xmouse;
  216.       this.spContentHolder.lastY = this.spContentHolder._ymouse;
  217.       this.spContentHolder.onMouseMove = function()
  218.       {
  219.          var _loc5_ = this.lastX - this._xmouse;
  220.          var _loc4_ = this.lastY - this._ymouse;
  221.          _loc5_ += this._parent.hPosition;
  222.          _loc4_ += this._parent.vPosition;
  223.          var _loc3_ = this._parent.getViewMetrics();
  224.          var _loc7_ = this._parent.__height - _loc3_.top - _loc3_.bottom;
  225.          var _loc6_ = this._parent.__width - _loc3_.left - _loc3_.right;
  226.          this._parent.__hPosition = Math.max(0,Math.min(_loc5_,this._width - _loc6_));
  227.          this._parent.__vPosition = Math.max(0,Math.min(_loc4_,this._height - _loc7_));
  228.          this._parent.hScroller.scrollPosition = this._parent.__hPosition;
  229.          this._x = - this._parent.hPosition;
  230.          this._parent.vScroller.scrollPosition = this._parent.__vPosition;
  231.          this._y = - this._parent.vPosition;
  232.          super.dispatchEvent({type:"scroll"});
  233.       };
  234.    }
  235.    function dispatchEvent(o)
  236.    {
  237.       o.target = this;
  238.       this._total = o.total;
  239.       this._loaded = o.current;
  240.       super.dispatchEvent(o);
  241.    }
  242.    function refreshPane(Void)
  243.    {
  244.       this.contentPath = this.__scrollContent;
  245.    }
  246.    function _onKeyDown(e)
  247.    {
  248.       if(this.hScroller != undefined && this.__hPosition <= this.hScroller.maxPos && this.__hPosition >= this.hScroller.minPos)
  249.       {
  250.          if(e.code == 37)
  251.          {
  252.             this.hPosition -= this.hLineScrollSize;
  253.          }
  254.          else if(e.code == 39)
  255.          {
  256.             this.hPosition += this.hLineScrollSize;
  257.          }
  258.       }
  259.       if(this.vScroller != undefined && this.__vPosition <= this.vScroller.maxPos && this.__vPosition >= this.vScroller.minPos)
  260.       {
  261.          if(e.code == 33)
  262.          {
  263.             this.vPosition -= this.vPageScrollSize;
  264.          }
  265.          else if(e.code == 34)
  266.          {
  267.             this.vPosition += this.vPageScrollSize;
  268.          }
  269.          if(e.code == 40)
  270.          {
  271.             this.vPosition += this.vLineScrollSize;
  272.          }
  273.          else if(e.code == 38)
  274.          {
  275.             this.vPosition -= this.vLineScrollSize;
  276.          }
  277.       }
  278.       if(e.code == 36)
  279.       {
  280.          this.vPosition = this.vScroller.minPos;
  281.       }
  282.       else if(e.code == 35)
  283.       {
  284.          this.vPosition = this.vScroller.maxPos;
  285.       }
  286.    }
  287. }
  288.