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 / TextInput.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  10.9 KB  |  400 lines

  1. package fl.controls
  2. {
  3.    import fl.core.InvalidationType;
  4.    import fl.core.UIComponent;
  5.    import fl.events.ComponentEvent;
  6.    import fl.managers.IFocusManager;
  7.    import fl.managers.IFocusManagerComponent;
  8.    import flash.display.DisplayObject;
  9.    import flash.events.Event;
  10.    import flash.events.FocusEvent;
  11.    import flash.events.KeyboardEvent;
  12.    import flash.events.TextEvent;
  13.    import flash.text.TextField;
  14.    import flash.text.TextFieldType;
  15.    import flash.text.TextFormat;
  16.    import flash.text.TextLineMetrics;
  17.    import flash.ui.Keyboard;
  18.    
  19.    [Embed(source="/_assets/assets.swf", symbol="symbol144")]
  20.    public class TextInput extends UIComponent implements IFocusManagerComponent
  21.    {
  22.       public static var createAccessibilityImplementation:Function;
  23.       
  24.       private static var defaultStyles:Object = {
  25.          "upSkin":"TextInput_upSkin",
  26.          "disabledSkin":"TextInput_disabledSkin",
  27.          "focusRectSkin":null,
  28.          "focusRectPadding":null,
  29.          "textFormat":null,
  30.          "disabledTextFormat":null,
  31.          "textPadding":0,
  32.          "embedFonts":false
  33.       };
  34.       
  35.       protected var _html:Boolean = false;
  36.       
  37.       protected var background:DisplayObject;
  38.       
  39.       protected var _savedHTML:String;
  40.       
  41.       protected var _editable:Boolean = true;
  42.       
  43.       public var textField:TextField;
  44.       
  45.       public function TextInput()
  46.       {
  47.          super();
  48.       }
  49.       
  50.       public static function getStyleDefinition() : Object
  51.       {
  52.          return defaultStyles;
  53.       }
  54.       
  55.       public function set alwaysShowSelection(param1:Boolean) : void
  56.       {
  57.          textField.alwaysShowSelection = param1;
  58.       }
  59.       
  60.       override public function set enabled(param1:Boolean) : void
  61.       {
  62.          super.enabled = param1;
  63.          updateTextFieldType();
  64.       }
  65.       
  66.       public function get imeMode() : String
  67.       {
  68.          return _imeMode;
  69.       }
  70.       
  71.       protected function handleChange(param1:Event) : void
  72.       {
  73.          param1.stopPropagation();
  74.          dispatchEvent(new Event(Event.CHANGE,true));
  75.       }
  76.       
  77.       public function set imeMode(param1:String) : void
  78.       {
  79.          _imeMode = param1;
  80.       }
  81.       
  82.       protected function setEmbedFont() : *
  83.       {
  84.          var _loc1_:Object = getStyleValue("embedFonts");
  85.          if(_loc1_ != null)
  86.          {
  87.             textField.embedFonts = _loc1_;
  88.          }
  89.       }
  90.       
  91.       protected function drawLayout() : void
  92.       {
  93.          var _loc1_:Number = Number(getStyleValue("textPadding"));
  94.          if(background != null)
  95.          {
  96.             background.width = width;
  97.             background.height = height;
  98.          }
  99.          textField.width = width - 2 * _loc1_;
  100.          textField.height = height - 2 * _loc1_;
  101.          textField.x = textField.y = _loc1_;
  102.       }
  103.       
  104.       public function set condenseWhite(param1:Boolean) : void
  105.       {
  106.          textField.condenseWhite = param1;
  107.       }
  108.       
  109.       public function get textWidth() : Number
  110.       {
  111.          return textField.textWidth;
  112.       }
  113.       
  114.       override protected function focusOutHandler(param1:FocusEvent) : void
  115.       {
  116.          super.focusOutHandler(param1);
  117.          if(editable)
  118.          {
  119.             setIMEMode(false);
  120.          }
  121.       }
  122.       
  123.       override public function setFocus() : void
  124.       {
  125.          stage.focus = textField;
  126.       }
  127.       
  128.       public function set displayAsPassword(param1:Boolean) : void
  129.       {
  130.          textField.displayAsPassword = param1;
  131.       }
  132.       
  133.       protected function drawBackground() : void
  134.       {
  135.          var _loc1_:DisplayObject = background;
  136.          var _loc2_:String = enabled ? "upSkin" : "disabledSkin";
  137.          background = getDisplayObjectInstance(getStyleValue(_loc2_));
  138.          if(background == null)
  139.          {
  140.             return;
  141.          }
  142.          addChildAt(background,0);
  143.          if(_loc1_ != null && _loc1_ != background && contains(_loc1_))
  144.          {
  145.             removeChild(_loc1_);
  146.          }
  147.       }
  148.       
  149.       public function get text() : String
  150.       {
  151.          return textField.text;
  152.       }
  153.       
  154.       public function set maxChars(param1:int) : void
  155.       {
  156.          textField.maxChars = param1;
  157.       }
  158.       
  159.       public function set horizontalScrollPosition(param1:int) : void
  160.       {
  161.          textField.scrollH = param1;
  162.       }
  163.       
  164.       override protected function isOurFocus(param1:DisplayObject) : Boolean
  165.       {
  166.          return param1 == textField || super.isOurFocus(param1);
  167.       }
  168.       
  169.       public function get textHeight() : Number
  170.       {
  171.          return textField.textHeight;
  172.       }
  173.       
  174.       public function get restrict() : String
  175.       {
  176.          return textField.restrict;
  177.       }
  178.       
  179.       public function get alwaysShowSelection() : Boolean
  180.       {
  181.          return textField.alwaysShowSelection;
  182.       }
  183.       
  184.       override public function get enabled() : Boolean
  185.       {
  186.          return super.enabled;
  187.       }
  188.       
  189.       override protected function draw() : void
  190.       {
  191.          var _loc1_:Object = null;
  192.          if(isInvalid(InvalidationType.STYLES,InvalidationType.STATE))
  193.          {
  194.             drawTextFormat();
  195.             drawBackground();
  196.             _loc1_ = getStyleValue("embedFonts");
  197.             if(_loc1_ != null)
  198.             {
  199.                textField.embedFonts = _loc1_;
  200.             }
  201.             invalidate(InvalidationType.SIZE,false);
  202.          }
  203.          if(isInvalid(InvalidationType.SIZE))
  204.          {
  205.             drawLayout();
  206.          }
  207.          super.draw();
  208.       }
  209.       
  210.       public function set editable(param1:Boolean) : void
  211.       {
  212.          _editable = param1;
  213.          updateTextFieldType();
  214.       }
  215.       
  216.       public function setSelection(param1:int, param2:int) : void
  217.       {
  218.          textField.setSelection(param1,param2);
  219.       }
  220.       
  221.       public function get condenseWhite() : Boolean
  222.       {
  223.          return textField.condenseWhite;
  224.       }
  225.       
  226.       public function get displayAsPassword() : Boolean
  227.       {
  228.          return textField.displayAsPassword;
  229.       }
  230.       
  231.       public function get selectionBeginIndex() : int
  232.       {
  233.          return textField.selectionBeginIndex;
  234.       }
  235.       
  236.       override protected function configUI() : void
  237.       {
  238.          super.configUI();
  239.          tabChildren = true;
  240.          textField = new TextField();
  241.          addChild(textField);
  242.          updateTextFieldType();
  243.          textField.addEventListener(TextEvent.TEXT_INPUT,handleTextInput,false,0,true);
  244.          textField.addEventListener(Event.CHANGE,handleChange,false,0,true);
  245.          textField.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown,false,0,true);
  246.       }
  247.       
  248.       public function get maxChars() : int
  249.       {
  250.          return textField.maxChars;
  251.       }
  252.       
  253.       public function set text(param1:String) : void
  254.       {
  255.          textField.text = param1;
  256.          _html = false;
  257.          invalidate(InvalidationType.DATA);
  258.          invalidate(InvalidationType.STYLES);
  259.       }
  260.       
  261.       protected function updateTextFieldType() : void
  262.       {
  263.          textField.type = enabled && editable ? TextFieldType.INPUT : TextFieldType.DYNAMIC;
  264.          textField.selectable = enabled;
  265.       }
  266.       
  267.       protected function handleKeyDown(param1:KeyboardEvent) : void
  268.       {
  269.          if(param1.keyCode == Keyboard.ENTER)
  270.          {
  271.             dispatchEvent(new ComponentEvent(ComponentEvent.ENTER,true));
  272.          }
  273.       }
  274.       
  275.       public function get horizontalScrollPosition() : int
  276.       {
  277.          return textField.scrollH;
  278.       }
  279.       
  280.       public function get selectionEndIndex() : int
  281.       {
  282.          return textField.selectionEndIndex;
  283.       }
  284.       
  285.       public function get editable() : Boolean
  286.       {
  287.          return _editable;
  288.       }
  289.       
  290.       public function get maxHorizontalScrollPosition() : int
  291.       {
  292.          return textField.maxScrollH;
  293.       }
  294.       
  295.       public function appendText(param1:String) : void
  296.       {
  297.          textField.appendText(param1);
  298.       }
  299.       
  300.       protected function drawTextFormat() : void
  301.       {
  302.          var _loc1_:Object = UIComponent.getStyleDefinition();
  303.          var _loc2_:TextFormat = enabled ? _loc1_.defaultTextFormat as TextFormat : _loc1_.defaultDisabledTextFormat as TextFormat;
  304.          textField.setTextFormat(_loc2_);
  305.          var _loc3_:TextFormat = getStyleValue(enabled ? "textFormat" : "disabledTextFormat") as TextFormat;
  306.          if(_loc3_ != null)
  307.          {
  308.             textField.setTextFormat(_loc3_);
  309.          }
  310.          else
  311.          {
  312.             _loc3_ = _loc2_;
  313.          }
  314.          textField.defaultTextFormat = _loc3_;
  315.          setEmbedFont();
  316.          if(_html)
  317.          {
  318.             textField.htmlText = _savedHTML;
  319.          }
  320.       }
  321.       
  322.       public function get length() : int
  323.       {
  324.          return textField.length;
  325.       }
  326.       
  327.       public function set htmlText(param1:String) : void
  328.       {
  329.          if(param1 == "")
  330.          {
  331.             text = "";
  332.             return;
  333.          }
  334.          _html = true;
  335.          _savedHTML = param1;
  336.          textField.htmlText = param1;
  337.          invalidate(InvalidationType.DATA);
  338.          invalidate(InvalidationType.STYLES);
  339.       }
  340.       
  341.       protected function handleTextInput(param1:TextEvent) : void
  342.       {
  343.          param1.stopPropagation();
  344.          dispatchEvent(new TextEvent(TextEvent.TEXT_INPUT,true,false,param1.text));
  345.       }
  346.       
  347.       public function set restrict(param1:String) : void
  348.       {
  349.          if(componentInspectorSetting && param1 == "")
  350.          {
  351.             param1 = null;
  352.          }
  353.          textField.restrict = param1;
  354.       }
  355.       
  356.       public function getLineMetrics(param1:int) : TextLineMetrics
  357.       {
  358.          return textField.getLineMetrics(param1);
  359.       }
  360.       
  361.       override public function drawFocus(param1:Boolean) : void
  362.       {
  363.          if(focusTarget != null)
  364.          {
  365.             focusTarget.drawFocus(param1);
  366.             return;
  367.          }
  368.          super.drawFocus(param1);
  369.       }
  370.       
  371.       override protected function focusInHandler(param1:FocusEvent) : void
  372.       {
  373.          if(param1.target == this)
  374.          {
  375.             stage.focus = textField;
  376.          }
  377.          var _loc2_:IFocusManager = focusManager;
  378.          if(editable && Boolean(_loc2_))
  379.          {
  380.             _loc2_.showFocusIndicator = true;
  381.             if(textField.selectable && textField.selectionBeginIndex == textField.selectionBeginIndex)
  382.             {
  383.                setSelection(0,textField.length);
  384.             }
  385.          }
  386.          super.focusInHandler(param1);
  387.          if(editable)
  388.          {
  389.             setIMEMode(true);
  390.          }
  391.       }
  392.       
  393.       public function get htmlText() : String
  394.       {
  395.          return textField.htmlText;
  396.       }
  397.    }
  398. }
  399.  
  400.