home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Swf / Produtividade.swf / scripts / __Packages / mx / controls / TextArea.as < prev    next >
Encoding:
Text File  |  2010-02-24  |  13.9 KB  |  532 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.0.377";
  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.enabled = enable;
  280.       this.vScroller.enabled = enable;
  281.       this.hScroller.enabled = enable;
  282.       this.label.type = !(this.editable == false || this.enabled == false) ? "input" : "dynamic";
  283.       this.label.selectable = this.enabled;
  284.       var _loc2_ = this.getStyle(!enable ? "disabledColor" : "color");
  285.       if(_loc2_ == undefined)
  286.       {
  287.          _loc2_ = !enable ? 8947848 : 0;
  288.       }
  289.       this.setColor(_loc2_);
  290.    }
  291.    function setColor(col)
  292.    {
  293.       this.label.textColor = col;
  294.    }
  295.    function setFocus(Void)
  296.    {
  297.       Selection.setFocus(this.label);
  298.    }
  299.    function onSetFocus(x)
  300.    {
  301.       var f = Selection.getFocus();
  302.       var o = eval(f);
  303.       if(o != this.label)
  304.       {
  305.          Selection.setFocus(this.label);
  306.          return undefined;
  307.       }
  308.       this.getFocusManager().defaultPushButtonEnabled = false;
  309.       this.addEventListener("keyDown",this);
  310.       super.onSetFocus(x);
  311.    }
  312.    function onKillFocus(x)
  313.    {
  314.       this.getFocusManager().defaultPushButtonEnabled = true;
  315.       this.removeEventListener("keyDown",this);
  316.       super.onKillFocus(x);
  317.    }
  318.    function restoreSelection(x)
  319.    {
  320.       var _loc2_ = Selection;
  321.       Selection.setSelection(_loc2_.lastBeginIndex,_loc2_.lastEndIndex);
  322.       this.label.scroll = this._vpos;
  323.       this.label.hscroll = this._hpos;
  324.    }
  325.    function getLineOffsets(Void)
  326.    {
  327.       var _loc16_ = this._getTextFormat();
  328.       var _loc18_ = _loc16_.getTextExtent2(this.label.text);
  329.       var _loc5_ = _root._getTextExtent;
  330.       _loc5_.setNewTextFormat(TextFormat(_loc16_));
  331.       var _loc14_ = this.label.wordWrap;
  332.       var _loc9_ = 0;
  333.       var _loc7_ = this.label._width - 2 - 2;
  334.       var _loc12_ = new Array();
  335.       var _loc17_ = new String(this.label.text);
  336.       var _loc15_ = _loc17_.split("\r");
  337.       var _loc11_ = 0;
  338.       while(_loc11_ < _loc15_.length)
  339.       {
  340.          _loc12_.push(_loc9_);
  341.          var _loc4_ = _loc15_[_loc11_];
  342.          _loc5_.text = _loc4_;
  343.          var _loc13_ = Math.ceil(_loc5_.textWidth / _loc7_);
  344.          var _loc10_ = Math.floor(_loc4_.length / _loc13_);
  345.          var _loc3_ = undefined;
  346.          while(_loc14_ && _loc5_.textWidth > _loc7_)
  347.          {
  348.             _loc3_ = _loc4_.indexOf(" ",_loc10_);
  349.             var _loc6_ = undefined;
  350.             if(_loc3_ == -1)
  351.             {
  352.                _loc3_ = _loc4_.lastIndexOf(" ");
  353.                if(_loc3_ == -1)
  354.                {
  355.                   _loc3_ = _loc10_;
  356.                }
  357.             }
  358.             _loc6_ = _loc4_.substr(0,_loc3_);
  359.             _loc5_.text = _loc6_;
  360.             if(_loc5_.textWidth > _loc7_)
  361.             {
  362.                while(_loc5_.textWidth > _loc7_)
  363.                {
  364.                   var _loc8_ = _loc3_;
  365.                   _loc3_ = _loc4_.lastIndexOf(" ",_loc3_ - 1);
  366.                   if(_loc3_ == -1)
  367.                   {
  368.                      _loc3_ = _loc8_ - 1;
  369.                   }
  370.                   _loc6_ = _loc4_.substr(0,_loc3_);
  371.                   _loc5_.text = _loc6_;
  372.                }
  373.             }
  374.             else if(_loc5_.textWidth < _loc7_)
  375.             {
  376.                _loc8_ = _loc3_;
  377.                while(_loc5_.textWidth < _loc7_)
  378.                {
  379.                   _loc8_ = _loc3_;
  380.                   _loc3_ = _loc4_.indexOf(" ",_loc3_ + 1);
  381.                   if(_loc3_ == -1)
  382.                   {
  383.                      if(_loc4_.indexOf(" ",0) != -1)
  384.                      {
  385.                         break;
  386.                      }
  387.                      _loc3_ = _loc8_ + 1;
  388.                   }
  389.                   _loc6_ = _loc4_.substr(0,_loc3_);
  390.                   _loc5_.text = _loc6_;
  391.                }
  392.                _loc3_ = _loc8_;
  393.             }
  394.             _loc9_ += _loc3_;
  395.             _loc12_.push(_loc9_ + 1);
  396.             _loc4_ = _loc4_.substr(_loc3_);
  397.             if(_loc4_.charAt(0) == " ")
  398.             {
  399.                _loc4_ = _loc4_.substr(1,_loc4_.length - 1);
  400.                _loc9_ += 1;
  401.             }
  402.             _loc5_.text = _loc4_;
  403.          }
  404.          _loc9_ += _loc4_.length + 1;
  405.          _loc11_ = _loc11_ + 1;
  406.       }
  407.       return _loc12_;
  408.    }
  409.    function keyDown(e)
  410.    {
  411.       var _loc5_ = e.code;
  412.       if(_loc5_ == 34)
  413.       {
  414.          var _loc6_ = this.label.bottomScroll - this.label.scroll + 1;
  415.          var _loc3_ = this.getLineOffsets();
  416.          var _loc2_ = Math.min(this.label.bottomScroll + 1,this.label.maxscroll);
  417.          if(_loc2_ == this.label.maxscroll)
  418.          {
  419.             var _loc4_ = this.label.length;
  420.             Selection.setSelection(_loc4_,_loc4_);
  421.          }
  422.          else
  423.          {
  424.             this.label.scroll = _loc2_;
  425.             Selection.setSelection(_loc3_[_loc2_ - 1],_loc3_[_loc2_ - 1]);
  426.          }
  427.       }
  428.       else if(_loc5_ == 33)
  429.       {
  430.          _loc6_ = this.label.bottomScroll - this.label.scroll + 1;
  431.          _loc3_ = this.getLineOffsets();
  432.          _loc2_ = this.label.scroll - 1;
  433.          if(_loc2_ < 1)
  434.          {
  435.             Selection.setSelection(0,0);
  436.          }
  437.          else
  438.          {
  439.             Selection.setSelection(_loc3_[_loc2_ - 1],_loc3_[_loc2_ - 1]);
  440.             this.label.scroll = Math.max(_loc2_ - _loc6_,1);
  441.          }
  442.       }
  443.    }
  444.    function draw(Void)
  445.    {
  446.       var _loc2_ = this.label;
  447.       var _loc4_ = this.getText();
  448.       if(this.initializing)
  449.       {
  450.          this.initializing = false;
  451.          delete this.initText;
  452.       }
  453.       var _loc3_ = this._getTextFormat();
  454.       _loc2_.embedFonts = _loc3_.embedFonts == true;
  455.       if(_loc3_ != undefined)
  456.       {
  457.          _loc2_.setTextFormat(_loc3_);
  458.          _loc2_.setNewTextFormat(_loc3_);
  459.       }
  460.       _loc2_.multiline = true;
  461.       _loc2_.wordWrap = this.wordWrap == true;
  462.       if(_loc2_.wordWrap)
  463.       {
  464.          this.__hScrollPolicy = "off";
  465.       }
  466.       if(_loc2_.html == true)
  467.       {
  468.          _loc2_.setTextFormat(_loc3_);
  469.          _loc2_.htmlText = _loc4_;
  470.       }
  471.       else
  472.       {
  473.          _loc2_.text = _loc4_;
  474.       }
  475.       _loc2_.type = this.editable != true ? "dynamic" : "input";
  476.       this.size();
  477.       _loc2_.background = false;
  478.    }
  479.    function adjustScrollBars()
  480.    {
  481.       var _loc2_ = this.label;
  482.       var _loc4_ = _loc2_.bottomScroll - _loc2_.scroll + 1;
  483.       var _loc3_ = _loc4_ + _loc2_.maxscroll - 1;
  484.       if(_loc3_ < 1)
  485.       {
  486.          _loc3_ = 1;
  487.       }
  488.       var _loc5_ = 0;
  489.       if(_loc2_.textWidth + 5 > _loc2_._width)
  490.       {
  491.          if(!_loc2_.wordWrap)
  492.          {
  493.             _loc5_ = _loc2_._width + _loc2_.maxhscroll;
  494.          }
  495.       }
  496.       else
  497.       {
  498.          _loc2_.hscroll = 0;
  499.          _loc2_.background = false;
  500.       }
  501.       if(_loc2_.height / _loc4_ != Math.round(_loc2_.height / _loc4_))
  502.       {
  503.          _loc3_ = _loc3_ - 1;
  504.       }
  505.       this.setScrollProperties(_loc5_,1,_loc3_,_loc2_.height / _loc4_);
  506.    }
  507.    function get tabIndex()
  508.    {
  509.       return this.label.tabIndex;
  510.    }
  511.    function set tabIndex(w)
  512.    {
  513.       this.label.tabIndex = w;
  514.    }
  515.    function set _accProps(val)
  516.    {
  517.       this.label._accProps = val;
  518.    }
  519.    function get _accProps()
  520.    {
  521.       return this.label._accProps;
  522.    }
  523.    function get styleSheet()
  524.    {
  525.       return this.label.styleSheet;
  526.    }
  527.    function set styleSheet(v)
  528.    {
  529.       this.label.styleSheet = v;
  530.    }
  531. }
  532.