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