home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / fl / controls / TextArea.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  19.3 KB  |  655 lines

  1. package fl.controls
  2. {
  3.    import fl.core.InvalidationType;
  4.    import fl.core.UIComponent;
  5.    import fl.events.ComponentEvent;
  6.    import fl.events.ScrollEvent;
  7.    import fl.managers.IFocusManager;
  8.    import fl.managers.IFocusManagerComponent;
  9.    import flash.display.DisplayObject;
  10.    import flash.events.Event;
  11.    import flash.events.FocusEvent;
  12.    import flash.events.KeyboardEvent;
  13.    import flash.events.MouseEvent;
  14.    import flash.events.TextEvent;
  15.    import flash.system.IME;
  16.    import flash.text.TextField;
  17.    import flash.text.TextFieldType;
  18.    import flash.text.TextFormat;
  19.    import flash.text.TextLineMetrics;
  20.    import flash.ui.Keyboard;
  21.    
  22.    [Embed(source="/_assets/assets.swf", symbol="symbol231")]
  23.    public class TextArea extends UIComponent implements IFocusManagerComponent
  24.    {
  25.       public static var createAccessibilityImplementation:Function;
  26.       
  27.       private static var defaultStyles:Object = {
  28.          "upSkin":"TextArea_upSkin",
  29.          "disabledSkin":"TextArea_disabledSkin",
  30.          "focusRectSkin":null,
  31.          "focusRectPadding":null,
  32.          "textFormat":null,
  33.          "disabledTextFormat":null,
  34.          "textPadding":3,
  35.          "embedFonts":false
  36.       };
  37.       
  38.       protected static const SCROLL_BAR_STYLES:Object = {
  39.          "downArrowDisabledSkin":"downArrowDisabledSkin",
  40.          "downArrowDownSkin":"downArrowDownSkin",
  41.          "downArrowOverSkin":"downArrowOverSkin",
  42.          "downArrowUpSkin":"downArrowUpSkin",
  43.          "upArrowDisabledSkin":"upArrowDisabledSkin",
  44.          "upArrowDownSkin":"upArrowDownSkin",
  45.          "upArrowOverSkin":"upArrowOverSkin",
  46.          "upArrowUpSkin":"upArrowUpSkin",
  47.          "thumbDisabledSkin":"thumbDisabledSkin",
  48.          "thumbDownSkin":"thumbDownSkin",
  49.          "thumbOverSkin":"thumbOverSkin",
  50.          "thumbUpSkin":"thumbUpSkin",
  51.          "thumbIcon":"thumbIcon",
  52.          "trackDisabledSkin":"trackDisabledSkin",
  53.          "trackDownSkin":"trackDownSkin",
  54.          "trackOverSkin":"trackOverSkin",
  55.          "trackUpSkin":"trackUpSkin",
  56.          "repeatDelay":"repeatDelay",
  57.          "repeatInterval":"repeatInterval"
  58.       };
  59.       
  60.       protected var _horizontalScrollBar:UIScrollBar;
  61.       
  62.       protected var _html:Boolean = false;
  63.       
  64.       protected var background:DisplayObject;
  65.       
  66.       protected var _verticalScrollBar:UIScrollBar;
  67.       
  68.       protected var _savedHTML:String;
  69.       
  70.       protected var _horizontalScrollPolicy:String = "auto";
  71.       
  72.       protected var _editable:Boolean = true;
  73.       
  74.       protected var textHasChanged:Boolean = false;
  75.       
  76.       public var textField:TextField;
  77.       
  78.       protected var _wordWrap:Boolean = true;
  79.       
  80.       protected var _verticalScrollPolicy:String = "auto";
  81.       
  82.       public function TextArea()
  83.       {
  84.          super();
  85.       }
  86.       
  87.       public static function getStyleDefinition() : Object
  88.       {
  89.          return UIComponent.mergeStyles(defaultStyles,ScrollBar.getStyleDefinition());
  90.       }
  91.       
  92.       public function set alwaysShowSelection(param1:Boolean) : void
  93.       {
  94.          textField.alwaysShowSelection = param1;
  95.       }
  96.       
  97.       override public function set enabled(param1:Boolean) : void
  98.       {
  99.          super.enabled = param1;
  100.          mouseChildren = enabled;
  101.          invalidate(InvalidationType.STATE);
  102.       }
  103.       
  104.       override protected function focusInHandler(param1:FocusEvent) : void
  105.       {
  106.          setIMEMode(true);
  107.          if(param1.target == this)
  108.          {
  109.             stage.focus = textField;
  110.          }
  111.          var _loc2_:IFocusManager = focusManager;
  112.          if(_loc2_)
  113.          {
  114.             if(editable)
  115.             {
  116.                _loc2_.showFocusIndicator = true;
  117.             }
  118.             _loc2_.defaultButtonEnabled = false;
  119.          }
  120.          super.focusInHandler(param1);
  121.          if(editable)
  122.          {
  123.             setIMEMode(true);
  124.          }
  125.       }
  126.       
  127.       protected function handleChange(param1:Event) : void
  128.       {
  129.          param1.stopPropagation();
  130.          dispatchEvent(new Event(Event.CHANGE,true));
  131.          invalidate(InvalidationType.DATA);
  132.       }
  133.       
  134.       public function set imeMode(param1:String) : void
  135.       {
  136.          _imeMode = param1;
  137.       }
  138.       
  139.       public function get imeMode() : String
  140.       {
  141.          return IME.conversionMode;
  142.       }
  143.       
  144.       override public function drawFocus(param1:Boolean) : void
  145.       {
  146.          if(focusTarget != null)
  147.          {
  148.             focusTarget.drawFocus(param1);
  149.             return;
  150.          }
  151.          super.drawFocus(param1);
  152.       }
  153.       
  154.       protected function handleWheel(param1:MouseEvent) : void
  155.       {
  156.          if(!enabled || !_verticalScrollBar.visible)
  157.          {
  158.             return;
  159.          }
  160.          _verticalScrollBar.scrollPosition -= param1.delta * _verticalScrollBar.lineScrollSize;
  161.          dispatchEvent(new ScrollEvent(ScrollBarDirection.VERTICAL,param1.delta * _verticalScrollBar.lineScrollSize,_verticalScrollBar.scrollPosition));
  162.       }
  163.       
  164.       public function set condenseWhite(param1:Boolean) : void
  165.       {
  166.          textField.condenseWhite = param1;
  167.          invalidate(InvalidationType.DATA);
  168.       }
  169.       
  170.       public function get textWidth() : Number
  171.       {
  172.          drawNow();
  173.          return textField.textWidth;
  174.       }
  175.       
  176.       override protected function focusOutHandler(param1:FocusEvent) : void
  177.       {
  178.          var _loc2_:IFocusManager = focusManager;
  179.          if(_loc2_)
  180.          {
  181.             _loc2_.defaultButtonEnabled = true;
  182.          }
  183.          setSelection(0,0);
  184.          super.focusOutHandler(param1);
  185.          if(editable)
  186.          {
  187.             setIMEMode(false);
  188.          }
  189.       }
  190.       
  191.       protected function handleScroll(param1:ScrollEvent) : void
  192.       {
  193.          dispatchEvent(param1);
  194.       }
  195.       
  196.       protected function drawLayout() : void
  197.       {
  198.          var _loc1_:Number = Number(getStyleValue("textPadding"));
  199.          textField.x = textField.y = _loc1_;
  200.          background.width = width;
  201.          background.height = height;
  202.          var _loc2_:Number = height;
  203.          var _loc3_:Boolean = needVScroll();
  204.          var _loc4_:Number = width - (_loc3_ ? _verticalScrollBar.width : 0);
  205.          var _loc5_:Boolean = needHScroll();
  206.          if(_loc5_)
  207.          {
  208.             _loc2_ -= _horizontalScrollBar.height;
  209.          }
  210.          setTextSize(_loc4_,_loc2_,_loc1_);
  211.          if(_loc5_ && !_loc3_ && needVScroll())
  212.          {
  213.             _loc3_ = true;
  214.             _loc4_ -= _verticalScrollBar.width;
  215.             setTextSize(_loc4_,_loc2_,_loc1_);
  216.          }
  217.          if(_loc3_)
  218.          {
  219.             _verticalScrollBar.visible = true;
  220.             _verticalScrollBar.x = width - _verticalScrollBar.width;
  221.             _verticalScrollBar.height = _loc2_;
  222.             _verticalScrollBar.visible = true;
  223.             _verticalScrollBar.enabled = enabled;
  224.          }
  225.          else
  226.          {
  227.             _verticalScrollBar.visible = false;
  228.          }
  229.          if(_loc5_)
  230.          {
  231.             _horizontalScrollBar.visible = true;
  232.             _horizontalScrollBar.y = height - _horizontalScrollBar.height;
  233.             _horizontalScrollBar.width = _loc4_;
  234.             _horizontalScrollBar.visible = true;
  235.             _horizontalScrollBar.enabled = enabled;
  236.          }
  237.          else
  238.          {
  239.             _horizontalScrollBar.visible = false;
  240.          }
  241.          updateScrollBars();
  242.          addEventListener(Event.ENTER_FRAME,delayedLayoutUpdate,false,0,true);
  243.       }
  244.       
  245.       public function set displayAsPassword(param1:Boolean) : void
  246.       {
  247.          textField.displayAsPassword = param1;
  248.       }
  249.       
  250.       protected function drawBackground() : void
  251.       {
  252.          var _loc1_:DisplayObject = background;
  253.          var _loc2_:String = enabled ? "upSkin" : "disabledSkin";
  254.          background = getDisplayObjectInstance(getStyleValue(_loc2_));
  255.          if(background != null)
  256.          {
  257.             addChildAt(background,0);
  258.          }
  259.          if(_loc1_ != null && _loc1_ != background && contains(_loc1_))
  260.          {
  261.             removeChild(_loc1_);
  262.          }
  263.       }
  264.       
  265.       public function get horizontalScrollPolicy() : String
  266.       {
  267.          return _horizontalScrollPolicy;
  268.       }
  269.       
  270.       protected function delayedLayoutUpdate(param1:Event) : void
  271.       {
  272.          if(textHasChanged)
  273.          {
  274.             textHasChanged = false;
  275.             drawLayout();
  276.             return;
  277.          }
  278.          removeEventListener(Event.ENTER_FRAME,delayedLayoutUpdate);
  279.       }
  280.       
  281.       public function get verticalScrollPosition() : Number
  282.       {
  283.          return textField.scrollV;
  284.       }
  285.       
  286.       public function get text() : String
  287.       {
  288.          return textField.text;
  289.       }
  290.       
  291.       public function get verticalScrollBar() : UIScrollBar
  292.       {
  293.          return _verticalScrollBar;
  294.       }
  295.       
  296.       public function set maxChars(param1:int) : void
  297.       {
  298.          textField.maxChars = param1;
  299.       }
  300.       
  301.       public function get textHeight() : Number
  302.       {
  303.          drawNow();
  304.          return textField.textHeight;
  305.       }
  306.       
  307.       override protected function isOurFocus(param1:DisplayObject) : Boolean
  308.       {
  309.          return param1 == textField || super.isOurFocus(param1);
  310.       }
  311.       
  312.       public function get maxVerticalScrollPosition() : int
  313.       {
  314.          return textField.maxScrollV;
  315.       }
  316.       
  317.       public function set horizontalScrollPosition(param1:Number) : void
  318.       {
  319.          drawNow();
  320.          textField.scrollH = param1;
  321.       }
  322.       
  323.       public function get restrict() : String
  324.       {
  325.          return textField.restrict;
  326.       }
  327.       
  328.       protected function setEmbedFont() : *
  329.       {
  330.          var _loc1_:Object = getStyleValue("embedFonts");
  331.          if(_loc1_ != null)
  332.          {
  333.             textField.embedFonts = _loc1_;
  334.          }
  335.       }
  336.       
  337.       public function get alwaysShowSelection() : Boolean
  338.       {
  339.          return textField.alwaysShowSelection;
  340.       }
  341.       
  342.       override public function get enabled() : Boolean
  343.       {
  344.          return super.enabled;
  345.       }
  346.       
  347.       override protected function draw() : void
  348.       {
  349.          if(isInvalid(InvalidationType.STATE))
  350.          {
  351.             updateTextFieldType();
  352.          }
  353.          if(isInvalid(InvalidationType.STYLES))
  354.          {
  355.             setStyles();
  356.             setEmbedFont();
  357.          }
  358.          if(isInvalid(InvalidationType.STYLES,InvalidationType.STATE))
  359.          {
  360.             drawTextFormat();
  361.             drawBackground();
  362.             invalidate(InvalidationType.SIZE,false);
  363.          }
  364.          if(isInvalid(InvalidationType.SIZE,InvalidationType.DATA))
  365.          {
  366.             drawLayout();
  367.          }
  368.          super.draw();
  369.       }
  370.       
  371.       public function set horizontalScrollPolicy(param1:String) : void
  372.       {
  373.          _horizontalScrollPolicy = param1;
  374.          invalidate(InvalidationType.SIZE);
  375.       }
  376.       
  377.       public function set editable(param1:Boolean) : void
  378.       {
  379.          _editable = param1;
  380.          invalidate(InvalidationType.STATE);
  381.       }
  382.       
  383.       public function setSelection(param1:int, param2:int) : void
  384.       {
  385.          textField.setSelection(param1,param2);
  386.       }
  387.       
  388.       public function get condenseWhite() : Boolean
  389.       {
  390.          return textField.condenseWhite;
  391.       }
  392.       
  393.       public function get displayAsPassword() : Boolean
  394.       {
  395.          return textField.displayAsPassword;
  396.       }
  397.       
  398.       protected function setTextSize(param1:Number, param2:Number, param3:Number) : void
  399.       {
  400.          var _loc4_:Number = param1 - param3 * 2;
  401.          var _loc5_:Number = param2 - param3 * 2;
  402.          if(_loc4_ != textField.width)
  403.          {
  404.             textField.width = _loc4_;
  405.          }
  406.          if(_loc5_ != textField.height)
  407.          {
  408.             textField.height = _loc5_;
  409.          }
  410.       }
  411.       
  412.       public function get horizontalScrollBar() : UIScrollBar
  413.       {
  414.          return _horizontalScrollBar;
  415.       }
  416.       
  417.       public function get selectionBeginIndex() : int
  418.       {
  419.          return textField.selectionBeginIndex;
  420.       }
  421.       
  422.       override protected function configUI() : void
  423.       {
  424.          super.configUI();
  425.          tabChildren = true;
  426.          textField = new TextField();
  427.          addChild(textField);
  428.          updateTextFieldType();
  429.          _verticalScrollBar = new UIScrollBar();
  430.          _verticalScrollBar.name = "V";
  431.          _verticalScrollBar.visible = false;
  432.          _verticalScrollBar.focusEnabled = false;
  433.          copyStylesToChild(_verticalScrollBar,SCROLL_BAR_STYLES);
  434.          _verticalScrollBar.addEventListener(ScrollEvent.SCROLL,handleScroll,false,0,true);
  435.          addChild(_verticalScrollBar);
  436.          _horizontalScrollBar = new UIScrollBar();
  437.          _horizontalScrollBar.name = "H";
  438.          _horizontalScrollBar.visible = false;
  439.          _horizontalScrollBar.focusEnabled = false;
  440.          _horizontalScrollBar.direction = ScrollBarDirection.HORIZONTAL;
  441.          copyStylesToChild(_horizontalScrollBar,SCROLL_BAR_STYLES);
  442.          _horizontalScrollBar.addEventListener(ScrollEvent.SCROLL,handleScroll,false,0,true);
  443.          addChild(_horizontalScrollBar);
  444.          textField.addEventListener(TextEvent.TEXT_INPUT,handleTextInput,false,0,true);
  445.          textField.addEventListener(Event.CHANGE,handleChange,false,0,true);
  446.          textField.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown,false,0,true);
  447.          _horizontalScrollBar.scrollTarget = textField;
  448.          _verticalScrollBar.scrollTarget = textField;
  449.          addEventListener(MouseEvent.MOUSE_WHEEL,handleWheel,false,0,true);
  450.       }
  451.       
  452.       public function set verticalScrollPosition(param1:Number) : void
  453.       {
  454.          drawNow();
  455.          textField.scrollV = param1;
  456.       }
  457.       
  458.       public function get maxChars() : int
  459.       {
  460.          return textField.maxChars;
  461.       }
  462.       
  463.       public function set text(param1:String) : void
  464.       {
  465.          if(componentInspectorSetting && param1 == "")
  466.          {
  467.             return;
  468.          }
  469.          textField.text = param1;
  470.          _html = false;
  471.          invalidate(InvalidationType.DATA);
  472.          invalidate(InvalidationType.STYLES);
  473.          textHasChanged = true;
  474.       }
  475.       
  476.       protected function updateScrollBars() : *
  477.       {
  478.          _horizontalScrollBar.update();
  479.          _verticalScrollBar.update();
  480.          _verticalScrollBar.enabled = enabled;
  481.          _horizontalScrollBar.enabled = enabled;
  482.          _horizontalScrollBar.drawNow();
  483.          _verticalScrollBar.drawNow();
  484.       }
  485.       
  486.       public function get maxHorizontalScrollPosition() : int
  487.       {
  488.          return textField.maxScrollH;
  489.       }
  490.       
  491.       protected function needHScroll() : Boolean
  492.       {
  493.          if(_horizontalScrollPolicy == ScrollPolicy.OFF)
  494.          {
  495.             return false;
  496.          }
  497.          if(_horizontalScrollPolicy == ScrollPolicy.ON)
  498.          {
  499.             return true;
  500.          }
  501.          return textField.maxScrollH > 0;
  502.       }
  503.       
  504.       protected function handleKeyDown(param1:KeyboardEvent) : void
  505.       {
  506.          if(param1.keyCode == Keyboard.ENTER)
  507.          {
  508.             dispatchEvent(new ComponentEvent(ComponentEvent.ENTER,true));
  509.          }
  510.       }
  511.       
  512.       public function get horizontalScrollPosition() : Number
  513.       {
  514.          return textField.scrollH;
  515.       }
  516.       
  517.       public function get selectionEndIndex() : int
  518.       {
  519.          return textField.selectionEndIndex;
  520.       }
  521.       
  522.       public function get editable() : Boolean
  523.       {
  524.          return _editable;
  525.       }
  526.       
  527.       protected function updateTextFieldType() : void
  528.       {
  529.          textField.type = enabled && _editable ? TextFieldType.INPUT : TextFieldType.DYNAMIC;
  530.          textField.selectable = enabled;
  531.          textField.wordWrap = _wordWrap;
  532.          textField.multiline = true;
  533.       }
  534.       
  535.       public function appendText(param1:String) : void
  536.       {
  537.          textField.appendText(param1);
  538.          invalidate(InvalidationType.DATA);
  539.       }
  540.       
  541.       public function set wordWrap(param1:Boolean) : void
  542.       {
  543.          _wordWrap = param1;
  544.          invalidate(InvalidationType.STATE);
  545.       }
  546.       
  547.       public function set verticalScrollPolicy(param1:String) : void
  548.       {
  549.          _verticalScrollPolicy = param1;
  550.          invalidate(InvalidationType.SIZE);
  551.       }
  552.       
  553.       protected function setStyles() : void
  554.       {
  555.          copyStylesToChild(_verticalScrollBar,SCROLL_BAR_STYLES);
  556.          copyStylesToChild(_horizontalScrollBar,SCROLL_BAR_STYLES);
  557.       }
  558.       
  559.       public function get length() : Number
  560.       {
  561.          return textField.text.length;
  562.       }
  563.       
  564.       protected function drawTextFormat() : void
  565.       {
  566.          var _loc1_:Object = UIComponent.getStyleDefinition();
  567.          var _loc2_:TextFormat = enabled ? _loc1_.defaultTextFormat as TextFormat : _loc1_.defaultDisabledTextFormat as TextFormat;
  568.          textField.setTextFormat(_loc2_);
  569.          var _loc3_:TextFormat = getStyleValue(enabled ? "textFormat" : "disabledTextFormat") as TextFormat;
  570.          if(_loc3_ != null)
  571.          {
  572.             textField.setTextFormat(_loc3_);
  573.          }
  574.          else
  575.          {
  576.             _loc3_ = _loc2_;
  577.          }
  578.          textField.defaultTextFormat = _loc3_;
  579.          setEmbedFont();
  580.          if(_html)
  581.          {
  582.             textField.htmlText = _savedHTML;
  583.          }
  584.       }
  585.       
  586.       public function set htmlText(param1:String) : void
  587.       {
  588.          if(componentInspectorSetting && param1 == "")
  589.          {
  590.             return;
  591.          }
  592.          if(param1 == "")
  593.          {
  594.             text = "";
  595.             return;
  596.          }
  597.          _html = true;
  598.          _savedHTML = param1;
  599.          textField.htmlText = param1;
  600.          invalidate(InvalidationType.DATA);
  601.          invalidate(InvalidationType.STYLES);
  602.          textHasChanged = true;
  603.       }
  604.       
  605.       public function get verticalScrollPolicy() : String
  606.       {
  607.          return _verticalScrollPolicy;
  608.       }
  609.       
  610.       protected function handleTextInput(param1:TextEvent) : void
  611.       {
  612.          param1.stopPropagation();
  613.          dispatchEvent(new TextEvent(TextEvent.TEXT_INPUT,true,false,param1.text));
  614.       }
  615.       
  616.       public function get htmlText() : String
  617.       {
  618.          return textField.htmlText;
  619.       }
  620.       
  621.       public function getLineMetrics(param1:int) : TextLineMetrics
  622.       {
  623.          return textField.getLineMetrics(param1);
  624.       }
  625.       
  626.       public function get wordWrap() : Boolean
  627.       {
  628.          return _wordWrap;
  629.       }
  630.       
  631.       protected function needVScroll() : Boolean
  632.       {
  633.          if(_verticalScrollPolicy == ScrollPolicy.OFF)
  634.          {
  635.             return false;
  636.          }
  637.          if(_verticalScrollPolicy == ScrollPolicy.ON)
  638.          {
  639.             return true;
  640.          }
  641.          return textField.maxScrollV > 1;
  642.       }
  643.       
  644.       public function set restrict(param1:String) : void
  645.       {
  646.          if(componentInspectorSetting && param1 == "")
  647.          {
  648.             param1 = null;
  649.          }
  650.          textField.restrict = param1;
  651.       }
  652.    }
  653. }
  654.  
  655.