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