home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Interface / it.dig / scripts / __Packages / mx / controls / TextArea.as < prev    next >
Encoding:
Text File  |  2006-07-04  |  14.1 KB  |  539 lines

  1. class mx.controls.TextArea extends mx.core.ScrollView
  2. {
  3.    var label;
  4.    var initText;
  5.    var _color;
  6.    var focusTextField;
  7.    var owner;
  8.    var hscroll;
  9.    var scroll;
  10.    var tfx;
  11.    var tfy;
  12.    var tfw;
  13.    var tfh;
  14.    var _vpos;
  15.    var _hpos;
  16.    var hookedV;
  17.    var vScroller;
  18.    var hookedH;
  19.    var hScroller;
  20.    var addEventListener;
  21.    var removeEventListener;
  22.    static var symbolName = "TextArea";
  23.    static var symbolOwner = mx.controls.TextArea;
  24.    static var version = "2.0.2.126";
  25.    var className = "TextArea";
  26.    var initializing = true;
  27.    var clipParameters = {text:1,wordWrap:1,editable:1,maxChars:1,restrict:1,html:1,password:1};
  28.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.TextArea.prototype.clipParameters,mx.core.ScrollView.prototype.clipParameters);
  29.    var __vScrollPolicy = "auto";
  30.    var __hScrollPolicy = "auto";
  31.    var __editable = true;
  32.    function TextArea()
  33.    {
  34.       super();
  35.    }
  36.    function get maxChars()
  37.    {
  38.       return this.label.maxChars;
  39.    }
  40.    function set maxChars(x)
  41.    {
  42.       this.label.maxChars = x;
  43.    }
  44.    function get length()
  45.    {
  46.       return this.label.length;
  47.    }
  48.    function get restrict()
  49.    {
  50.       return this.label.restrict;
  51.    }
  52.    function set restrict(s)
  53.    {
  54.       this.label.restrict = s != "" ? s : null;
  55.    }
  56.    function get wordWrap()
  57.    {
  58.       return this.label.wordWrap;
  59.    }
  60.    function set wordWrap(s)
  61.    {
  62.       this.label.wordWrap = s;
  63.       this.invalidate();
  64.    }
  65.    function get editable()
  66.    {
  67.       return this.__editable;
  68.    }
  69.    function set editable(x)
  70.    {
  71.       this.__editable = x;
  72.       this.label.type = !x ? "dynamic" : "input";
  73.    }
  74.    function get password()
  75.    {
  76.       return this.label.password;
  77.    }
  78.    function set password(s)
  79.    {
  80.       this.label.password = s;
  81.    }
  82.    function get html()
  83.    {
  84.       return this.getHtml();
  85.    }
  86.    function set html(value)
  87.    {
  88.       this.setHtml(value);
  89.    }
  90.    function getHtml()
  91.    {
  92.       return this.label.html;
  93.    }
  94.    function setHtml(value)
  95.    {
  96.       if(value != this.label.html)
  97.       {
  98.          this.label.html = value;
  99.       }
  100.    }
  101.    function get text()
  102.    {
  103.       return this.getText();
  104.    }
  105.    function set text(t)
  106.    {
  107.       this.setText(t);
  108.    }
  109.    function getText()
  110.    {
  111.       if(this.initializing)
  112.       {
  113.          return this.initText;
  114.       }
  115.       var _loc2_ = this.label;
  116.       if(_loc2_.html == true)
  117.       {
  118.          return _loc2_.htmlText;
  119.       }
  120.       return _loc2_.text;
  121.    }
  122.    function setText(t)
  123.    {
  124.       if(this.initializing)
  125.       {
  126.          this.initText = t;
  127.       }
  128.       else
  129.       {
  130.          var _loc2_ = this.label;
  131.          if(_loc2_.html == true)
  132.          {
  133.             _loc2_.htmlText = t;
  134.          }
  135.          else
  136.          {
  137.             _loc2_.text = t;
  138.          }
  139.          this.invalidate();
  140.       }
  141.       this.dispatchValueChangedEvent(t);
  142.    }
  143.    function get hPosition()
  144.    {
  145.       return this.getHPosition();
  146.    }
  147.    function set hPosition(pos)
  148.    {
  149.       this.setHPosition(pos);
  150.       this.label.hscroll = pos;
  151.       this.label.background = false;
  152.    }
  153.    function get vPosition()
  154.    {
  155.       return this.getVPosition();
  156.    }
  157.    function set vPosition(pos)
  158.    {
  159.       this.setVPosition(pos);
  160.       this.label.scroll = pos + 1;
  161.       this.label.background = false;
  162.    }
  163.    function get maxVPosition()
  164.    {
  165.       var _loc2_ = this.label.maxscroll - 1;
  166.       return _loc2_ != undefined ? _loc2_ : 0;
  167.    }
  168.    function get maxHPosition()
  169.    {
  170.       var _loc2_ = this.label.maxhscroll;
  171.       return _loc2_ != undefined ? _loc2_ : 0;
  172.    }
  173.    function init(Void)
  174.    {
  175.       super.init();
  176.       this.label.styleName = this;
  177.       this._color = mx.core.UIObject.textColorList;
  178.       this.focusTextField = this.label;
  179.       this.label.owner = this;
  180.       this.label.onSetFocus = function(x)
  181.       {
  182.          this._parent.onSetFocus(x);
  183.       };
  184.       this.label.onKillFocus = function(x)
  185.       {
  186.          this._parent.onKillFocus(x);
  187.       };
  188.       this.label.drawFocus = function(b)
  189.       {
  190.          this._parent.drawFocus(b);
  191.       };
  192.       this.label.onChanged = function()
  193.       {
  194.          this.owner.adjustScrollBars();
  195.          this.owner.dispatchEvent({type:"change"});
  196.          this.owner.dispatchValueChangedEvent(this.owner.text);
  197.       };
  198.       this.label.onScroller = function()
  199.       {
  200.          this.owner.hPosition = this.hscroll;
  201.          this.owner.vPosition = this.scroll - 1;
  202.       };
  203.       if(this.text == undefined)
  204.       {
  205.          this.text = "";
  206.       }
  207.    }
  208.    function createChildren(Void)
  209.    {
  210.       super.createChildren();
  211.       this.label.autoSize = "none";
  212.    }
  213.    function layoutContent(x, y, totalW, totalH, displayW, displayH)
  214.    {
  215.       var _loc2_ = this.label;
  216.       if(this.tfx != x || this.tfy != y || this.tfw != displayW || this.tfh != displayH)
  217.       {
  218.          this.tfx = x;
  219.          this.tfy = y;
  220.          this.tfw = displayW;
  221.          this.tfh = displayH;
  222.          _loc2_.move(this.tfx,this.tfy);
  223.          _loc2_.setSize(this.tfw,this.tfh);
  224.          this.doLater(this,"adjustScrollBars");
  225.       }
  226.    }
  227.    function scrollChanged(Void)
  228.    {
  229.       var _loc2_ = Selection;
  230.       if(_loc2_.lastBeginIndex != undefined)
  231.       {
  232.          this.restoreSelection();
  233.       }
  234.       this.label.background = false;
  235.    }
  236.    function onScroll(docObj)
  237.    {
  238.       var _loc3_ = this.label;
  239.       super.onScroll(docObj);
  240.       _loc3_.hscroll = this.hPosition + 0;
  241.       _loc3_.scroll = this.vPosition + 1;
  242.       this._vpos = _loc3_.scroll;
  243.       this._hpos = _loc3_.hscroll;
  244.       _loc3_.background = false;
  245.       if(this.hookedV != true)
  246.       {
  247.          this.vScroller.addEventListener("scrollChanged",this);
  248.          this.hookedV = true;
  249.       }
  250.       if(this.hookedH != true)
  251.       {
  252.          this.hScroller.addEventListener("scrollChanged",this);
  253.          this.hookedH = true;
  254.       }
  255.    }
  256.    function size(Void)
  257.    {
  258.       var _loc3_ = this.getViewMetrics();
  259.       var _loc7_ = _loc3_.left + _loc3_.right;
  260.       var _loc4_ = _loc3_.top + _loc3_.bottom;
  261.       var _loc6_ = _loc3_.left;
  262.       var _loc5_ = _loc3_.top;
  263.       this.tfx = _loc6_;
  264.       this.tfy = _loc5_;
  265.       this.tfw = this.width - _loc7_;
  266.       this.tfh = this.height - _loc4_;
  267.       super.size();
  268.       this.label.move(this.tfx,this.tfy);
  269.       this.label.setSize(this.tfw,this.tfh);
  270.       if(this.height <= 40)
  271.       {
  272.          this.hScrollPolicy = "off";
  273.          this.vScrollPolicy = "off";
  274.       }
  275.       this.doLater(this,"adjustScrollBars");
  276.    }
  277.    function setEnabled(enable)
  278.    {
  279.       this.vScroller.enabled = enable;
  280.       this.hScroller.enabled = enable;
  281.       this.label.type = !(this.editable == false || enable == false) ? "input" : "dynamic";
  282.       this.label.selectable = enable;
  283.       var _loc3_ = this.getStyle(!enable ? "disabledColor" : "color");
  284.       if(_loc3_ == undefined)
  285.       {
  286.          _loc3_ = !enable ? 8947848 : 0;
  287.       }
  288.       this.setColor(_loc3_);
  289.    }
  290.    function setColor(col)
  291.    {
  292.       this.label.textColor = col;
  293.    }
  294.    function setFocus(Void)
  295.    {
  296.       Selection.setFocus(this.label);
  297.    }
  298.    function onSetFocus(x)
  299.    {
  300.       var f = Selection.getFocus();
  301.       var o = eval(f);
  302.       if(o != this.label)
  303.       {
  304.          Selection.setFocus(this.label);
  305.          return undefined;
  306.       }
  307.       this.getFocusManager().defaultPushButtonEnabled = false;
  308.       this.addEventListener("keyDown",this);
  309.       super.onSetFocus(x);
  310.    }
  311.    function onKillFocus(x)
  312.    {
  313.       this.getFocusManager().defaultPushButtonEnabled = true;
  314.       this.removeEventListener("keyDown",this);
  315.       super.onKillFocus(x);
  316.    }
  317.    function restoreSelection(x)
  318.    {
  319.       var _loc2_ = Selection;
  320.       Selection.setSelection(_loc2_.lastBeginIndex,_loc2_.lastEndIndex);
  321.       this.label.scroll = this._vpos;
  322.       this.label.hscroll = this._hpos;
  323.    }
  324.    function getLineOffsets(Void)
  325.    {
  326.       var _loc16_ = this._getTextFormat();
  327.       var _loc18_ = _loc16_.getTextExtent2(this.label.text);
  328.       var _loc5_ = _root._getTextExtent;
  329.       _loc5_.setNewTextFormat(_loc16_);
  330.       var _loc14_ = this.label.wordWrap;
  331.       var _loc9_ = 0;
  332.       var _loc7_ = this.label._width - 2 - 2;
  333.       var _loc12_ = new Array();
  334.       var _loc17_ = new String(this.label.text);
  335.       var _loc15_ = _loc17_.split("\r");
  336.       var _loc11_ = 0;
  337.       while(_loc11_ < _loc15_.length)
  338.       {
  339.          _loc12_.push(_loc9_);
  340.          var _loc4_ = _loc15_[_loc11_];
  341.          _loc5_.text = _loc4_;
  342.          var _loc13_ = Math.ceil(_loc5_.textWidth / _loc7_);
  343.          var _loc10_ = Math.floor(_loc4_.length / _loc13_);
  344.          var _loc3_ = undefined;
  345.          while(_loc14_ && _loc5_.textWidth > _loc7_)
  346.          {
  347.             _loc3_ = _loc4_.indexOf(" ",_loc10_);
  348.             var _loc6_ = undefined;
  349.             if(_loc3_ == -1)
  350.             {
  351.                _loc3_ = _loc4_.lastIndexOf(" ");
  352.                if(_loc3_ == -1)
  353.                {
  354.                   _loc3_ = _loc10_;
  355.                }
  356.             }
  357.             _loc6_ = _loc4_.substr(0,_loc3_);
  358.             _loc5_.text = _loc6_;
  359.             if(_loc5_.textWidth > _loc7_)
  360.             {
  361.                while(_loc5_.textWidth > _loc7_)
  362.                {
  363.                   var _loc8_ = _loc3_;
  364.                   _loc3_ = _loc4_.lastIndexOf(" ",_loc3_ - 1);
  365.                   if(_loc3_ == -1)
  366.                   {
  367.                      _loc3_ = _loc8_ - 1;
  368.                   }
  369.                   _loc6_ = _loc4_.substr(0,_loc3_);
  370.                   _loc5_.text = _loc6_;
  371.                }
  372.             }
  373.             else if(_loc5_.textWidth < _loc7_)
  374.             {
  375.                _loc8_ = _loc3_;
  376.                while(_loc5_.textWidth < _loc7_)
  377.                {
  378.                   _loc8_ = _loc3_;
  379.                   _loc3_ = _loc4_.indexOf(" ",_loc3_ + 1);
  380.                   if(_loc3_ == -1)
  381.                   {
  382.                      if(_loc4_.indexOf(" ",0) != -1)
  383.                      {
  384.                         break;
  385.                      }
  386.                      _loc3_ = _loc8_ + 1;
  387.                   }
  388.                   _loc6_ = _loc4_.substr(0,_loc3_);
  389.                   _loc5_.text = _loc6_;
  390.                }
  391.                _loc3_ = _loc8_;
  392.             }
  393.             _loc9_ += _loc3_;
  394.             _loc12_.push(_loc9_ + 1);
  395.             _loc4_ = _loc4_.substr(_loc3_);
  396.             if(_loc4_.charAt(0) == " ")
  397.             {
  398.                _loc4_ = _loc4_.substr(1,_loc4_.length - 1);
  399.                _loc9_ += 1;
  400.             }
  401.             _loc5_.text = _loc4_;
  402.          }
  403.          _loc9_ += _loc4_.length + 1;
  404.          _loc11_ = _loc11_ + 1;
  405.       }
  406.       return _loc12_;
  407.    }
  408.    function keyDown(e)
  409.    {
  410.       var _loc5_ = e.code;
  411.       if(_loc5_ == 34)
  412.       {
  413.          var _loc6_ = this.label.bottomScroll - this.label.scroll + 1;
  414.          var _loc3_ = this.getLineOffsets();
  415.          var _loc2_ = Math.min(this.label.bottomScroll + 1,this.label.maxscroll);
  416.          if(_loc2_ == this.label.maxscroll)
  417.          {
  418.             var _loc4_ = this.label.length;
  419.             Selection.setSelection(_loc4_,_loc4_);
  420.          }
  421.          else
  422.          {
  423.             this.label.scroll = _loc2_;
  424.             Selection.setSelection(_loc3_[_loc2_ - 1],_loc3_[_loc2_ - 1]);
  425.          }
  426.       }
  427.       else if(_loc5_ == 33)
  428.       {
  429.          _loc6_ = this.label.bottomScroll - this.label.scroll + 1;
  430.          _loc3_ = this.getLineOffsets();
  431.          _loc2_ = this.label.scroll - 1;
  432.          if(_loc2_ < 1)
  433.          {
  434.             Selection.setSelection(0,0);
  435.          }
  436.          else
  437.          {
  438.             Selection.setSelection(_loc3_[_loc2_ - 1],_loc3_[_loc2_ - 1]);
  439.             this.label.scroll = Math.max(_loc2_ - _loc6_,1);
  440.          }
  441.       }
  442.    }
  443.    function draw(Void)
  444.    {
  445.       var _loc2_ = this.label;
  446.       var _loc4_ = this.getText();
  447.       if(this.initializing)
  448.       {
  449.          this.initializing = false;
  450.          delete this.initText;
  451.       }
  452.       var _loc3_ = this._getTextFormat();
  453.       _loc2_.embedFonts = _loc3_.embedFonts == true;
  454.       if(_loc3_ != undefined)
  455.       {
  456.          _loc2_.setTextFormat(_loc3_);
  457.          _loc2_.setNewTextFormat(_loc3_);
  458.       }
  459.       _loc2_.multiline = true;
  460.       _loc2_.wordWrap = this.wordWrap == true;
  461.       if(_loc2_.html == true)
  462.       {
  463.          _loc2_.setTextFormat(_loc3_);
  464.          _loc2_.htmlText = _loc4_;
  465.       }
  466.       else
  467.       {
  468.          _loc2_.text = _loc4_;
  469.       }
  470.       _loc2_.type = this.editable != true ? "dynamic" : "input";
  471.       this.size();
  472.       _loc2_.background = false;
  473.    }
  474.    function adjustScrollBars()
  475.    {
  476.       var _loc2_ = this.label;
  477.       var _loc4_ = _loc2_.bottomScroll - _loc2_.scroll + 1;
  478.       var _loc3_ = _loc4_ + _loc2_.maxscroll - 1;
  479.       if(_loc3_ < 1)
  480.       {
  481.          _loc3_ = 1;
  482.       }
  483.       var _loc5_ = 0;
  484.       if(_loc2_.textWidth + 5 > _loc2_._width)
  485.       {
  486.          if(!_loc2_.wordWrap)
  487.          {
  488.             _loc5_ = _loc2_._width + _loc2_.maxhscroll;
  489.          }
  490.       }
  491.       else
  492.       {
  493.          _loc2_.hscroll = 0;
  494.          _loc2_.background = false;
  495.       }
  496.       if(_loc2_.height / _loc4_ != Math.round(_loc2_.height / _loc4_))
  497.       {
  498.          _loc3_ = _loc3_ - 1;
  499.       }
  500.       this.setScrollProperties(_loc5_,1,_loc3_,_loc2_.height / _loc4_);
  501.    }
  502.    function setScrollProperties(colCount, colWidth, rwCount, rwHeight, hPadding, wPadding)
  503.    {
  504.       super.setScrollProperties(colCount,colWidth,rwCount,rwHeight,hPadding,wPadding);
  505.       if(this.vScroller == undefined)
  506.       {
  507.          this.hookedV = false;
  508.       }
  509.       if(this.hScroller == undefined)
  510.       {
  511.          this.hookedH = false;
  512.       }
  513.    }
  514.    function get tabIndex()
  515.    {
  516.       return this.label.tabIndex;
  517.    }
  518.    function set tabIndex(w)
  519.    {
  520.       this.label.tabIndex = w;
  521.    }
  522.    function set _accProps(val)
  523.    {
  524.       this.label._accProps = val;
  525.    }
  526.    function get _accProps()
  527.    {
  528.       return this.label._accProps;
  529.    }
  530.    function get styleSheet()
  531.    {
  532.       return this.label.styleSheet;
  533.    }
  534.    function set styleSheet(v)
  535.    {
  536.       this.label.styleSheet = v;
  537.    }
  538. }
  539.