home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / interfac / it.dig / scripts / __Packages / mx / controls / ComboBox.as < prev    next >
Encoding:
Text File  |  2011-06-09  |  13.8 KB  |  492 lines

  1. class mx.controls.ComboBox extends mx.controls.ComboBase
  2. {
  3.    var editable;
  4.    var __labels;
  5.    var labels;
  6.    var data;
  7.    var __dropdownWidth;
  8.    var __width;
  9.    var selectedIndex;
  10.    var __dropdown;
  11.    var dataProvider;
  12.    var __labelFunction;
  13.    var owner;
  14.    var mask;
  15.    var border_mc;
  16.    var text_mc;
  17.    var getValue;
  18.    var length;
  19.    var selectedItem;
  20.    var labelField;
  21.    var isPressed;
  22.    var height;
  23.    var rowCount;
  24.    var dispatchEvent;
  25.    var dropdown;
  26.    var width;
  27.    var __dataProvider;
  28.    var selected;
  29.    static var symbolName = "ComboBox";
  30.    static var symbolOwner = mx.controls.ComboBox;
  31.    static var version = "2.0.0.377";
  32.    var clipParameters = {labels:1,data:1,editable:1,rowCount:1,dropdownWidth:1};
  33.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.ComboBox.prototype.clipParameters,mx.controls.ComboBase.prototype.clipParameters);
  34.    var className = "ComboBox";
  35.    var _showingDropdown = false;
  36.    var __rowCount = 5;
  37.    var dropdownBorderStyle = undefined;
  38.    var initializing = true;
  39.    var __labelField = "label";
  40.    var bInKeyDown = false;
  41.    function ComboBox()
  42.    {
  43.       super();
  44.    }
  45.    function init()
  46.    {
  47.       super.init();
  48.    }
  49.    function createChildren()
  50.    {
  51.       super.createChildren();
  52.       this.editable = this.editable;
  53.       if(this.__labels.length > 0)
  54.       {
  55.          var _loc6_ = new Array();
  56.          var _loc3_ = 0;
  57.          while(_loc3_ < this.labels.length)
  58.          {
  59.             _loc6_.addItem({label:this.labels[_loc3_],data:this.data[_loc3_]});
  60.             _loc3_ = _loc3_ + 1;
  61.          }
  62.          this.setDataProvider(_loc6_);
  63.       }
  64.       this.dropdownWidth = typeof this.__dropdownWidth != "number" ? this.__width : this.__dropdownWidth;
  65.       if(!this._editable)
  66.       {
  67.          this.selectedIndex = 0;
  68.       }
  69.       this.initializing = false;
  70.    }
  71.    function onKillFocus(n)
  72.    {
  73.       if(this._showingDropdown && n != null)
  74.       {
  75.          this.displayDropdown(false);
  76.       }
  77.       super.onKillFocus();
  78.    }
  79.    function getDropdown()
  80.    {
  81.       if(this.initializing)
  82.       {
  83.          return undefined;
  84.       }
  85.       if(!this.hasDropdown())
  86.       {
  87.          var _loc3_ = new Object();
  88.          _loc3_.styleName = this;
  89.          if(this.dropdownBorderStyle != undefined)
  90.          {
  91.             _loc3_.borderStyle = this.dropdownBorderStyle;
  92.          }
  93.          _loc3_._visible = false;
  94.          this.__dropdown = mx.managers.PopUpManager.createPopUp(this,mx.controls.List,false,_loc3_,true);
  95.          this.__dropdown.scroller.mask.removeMovieClip();
  96.          if(this.dataProvider == undefined)
  97.          {
  98.             this.dataProvider = new Array();
  99.          }
  100.          this.__dropdown.setDataProvider(this.dataProvider);
  101.          this.__dropdown.selectMultiple = false;
  102.          this.__dropdown.rowCount = this.__rowCount;
  103.          this.__dropdown.selectedIndex = this.selectedIndex;
  104.          this.__dropdown.vScrollPolicy = "auto";
  105.          this.__dropdown.labelField = this.__labelField;
  106.          this.__dropdown.labelFunction = this.__labelFunction;
  107.          this.__dropdown.owner = this;
  108.          this.__dropdown.changeHandler = this._changeHandler;
  109.          this.__dropdown.scrollHandler = this._scrollHandler;
  110.          this.__dropdown.itemRollOverHandler = this._itemRollOverHandler;
  111.          this.__dropdown.itemRollOutHandler = this._itemRollOutHandler;
  112.          this.__dropdown.resizeHandler = this._resizeHandler;
  113.          this.__dropdown.mouseDownOutsideHandler = function(eventObj)
  114.          {
  115.             if(!this.owner.hitTest(_root._xmouse,_root._ymouse,false))
  116.             {
  117.                if(!(!this.wrapDownArrowButton && this.owner.downArrow_mc.hitTest(_root._xmouse,_root._ymouse,false)))
  118.                {
  119.                   this.owner.displayDropdown(false);
  120.                }
  121.             }
  122.          };
  123.          this.__dropdown.onTweenUpdate = function(v)
  124.          {
  125.             this._y = v;
  126.          };
  127.          this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  128.          this.createObject("BoundingBox","mask",20);
  129.          this.mask._y = this.border_mc.height;
  130.          this.mask._width = this.__dropdownWidth;
  131.          this.mask._height = this.__dropdown.height;
  132.          this.mask._visible = false;
  133.          this.__dropdown.setMask(this.mask);
  134.       }
  135.       return this.__dropdown;
  136.    }
  137.    function setSize(w, h, noEvent)
  138.    {
  139.       super.setSize(w,h,noEvent);
  140.       this.__dropdownWidth = w;
  141.       this.__dropdown.rowHeight = h;
  142.       this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  143.    }
  144.    function setEditable(e)
  145.    {
  146.       super.setEditable(e);
  147.       if(e)
  148.       {
  149.          this.text_mc.setText("");
  150.       }
  151.       else
  152.       {
  153.          this.text_mc.setText(this.selectedLabel);
  154.       }
  155.    }
  156.    function get labels()
  157.    {
  158.       return this.__labels;
  159.    }
  160.    function set labels(lbls)
  161.    {
  162.       this.__labels = lbls;
  163.       this.setDataProvider(lbls);
  164.    }
  165.    function getLabelField()
  166.    {
  167.       return this.__labelField;
  168.    }
  169.    function get labelField()
  170.    {
  171.       return this.getLabelField();
  172.    }
  173.    function setLabelField(s)
  174.    {
  175.       this.__dropdown.labelField = this.__labelField = s;
  176.       this.text_mc.setText(this.selectedLabel);
  177.    }
  178.    function set labelField(s)
  179.    {
  180.       this.setLabelField(s);
  181.    }
  182.    function getLabelFunction()
  183.    {
  184.       return this.__labelFunction;
  185.    }
  186.    function get labelFunction()
  187.    {
  188.       return this.getLabelFunction();
  189.    }
  190.    function set labelFunction(f)
  191.    {
  192.       this.__dropdown.labelFunction = this.__labelFunction = f;
  193.       this.text_mc.setText(this.selectedLabel);
  194.    }
  195.    function setSelectedItem(v)
  196.    {
  197.       super.setSelectedItem(v);
  198.       this.__dropdown.selectedItem = v;
  199.       this.text_mc.setText(this.selectedLabel);
  200.    }
  201.    function setSelectedIndex(v)
  202.    {
  203.       super.setSelectedIndex(v);
  204.       this.__dropdown.selectedIndex = v;
  205.       this.text_mc.setText(this.selectedLabel);
  206.       this.dispatchValueChangedEvent(this.getValue());
  207.    }
  208.    function setRowCount(count)
  209.    {
  210.       if(isNaN(count))
  211.       {
  212.          return undefined;
  213.       }
  214.       this.__rowCount = count;
  215.       this.__dropdown.setRowCount(count);
  216.    }
  217.    function get rowCount()
  218.    {
  219.       return Math.max(1,Math.min(this.length,this.__rowCount));
  220.    }
  221.    function set rowCount(v)
  222.    {
  223.       this.setRowCount(v);
  224.    }
  225.    function setDropdownWidth(w)
  226.    {
  227.       this.__dropdownWidth = w;
  228.       this.__dropdown.setSize(w,this.__dropdown.height);
  229.    }
  230.    function get dropdownWidth()
  231.    {
  232.       return this.__dropdownWidth;
  233.    }
  234.    function set dropdownWidth(v)
  235.    {
  236.       this.setDropdownWidth(v);
  237.    }
  238.    function get dropdown()
  239.    {
  240.       return this.getDropdown();
  241.    }
  242.    function setDataProvider(dp)
  243.    {
  244.       super.setDataProvider(dp);
  245.       this.__dropdown.setDataProvider(dp);
  246.       if(!this._editable)
  247.       {
  248.          this.selectedIndex = 0;
  249.       }
  250.    }
  251.    function open()
  252.    {
  253.       this.displayDropdown(true);
  254.    }
  255.    function close()
  256.    {
  257.       this.displayDropdown(false);
  258.    }
  259.    function get selectedLabel()
  260.    {
  261.       var _loc2_ = this.selectedItem;
  262.       if(_loc2_ == undefined)
  263.       {
  264.          return "";
  265.       }
  266.       if(this.labelFunction != undefined)
  267.       {
  268.          return this.labelFunction(_loc2_);
  269.       }
  270.       if(typeof _loc2_ != "object")
  271.       {
  272.          return _loc2_;
  273.       }
  274.       if(_loc2_[this.labelField] != undefined)
  275.       {
  276.          return _loc2_[this.labelField];
  277.       }
  278.       if(_loc2_.label != undefined)
  279.       {
  280.          return _loc2_.label;
  281.       }
  282.       var _loc3_ = " ";
  283.       for(var _loc4_ in _loc2_)
  284.       {
  285.          if(_loc4_ != "__ID__")
  286.          {
  287.             _loc3_ = _loc2_[_loc4_] + ", " + _loc3_;
  288.          }
  289.       }
  290.       _loc3_ = _loc3_.substring(0,_loc3_.length - 3);
  291.       return _loc3_;
  292.    }
  293.    function hasDropdown()
  294.    {
  295.       return this.__dropdown != undefined && this.__dropdown.valueOf() != undefined;
  296.    }
  297.    function tweenEndShow(value)
  298.    {
  299.       this._y = value;
  300.       this.isPressed = true;
  301.    }
  302.    function tweenEndHide(value)
  303.    {
  304.       this._y = value;
  305.       this.visible = false;
  306.    }
  307.    function displayDropdown(show)
  308.    {
  309.       if(show == this._showingDropdown)
  310.       {
  311.          return undefined;
  312.       }
  313.       var _loc3_ = new Object();
  314.       _loc3_.x = 0;
  315.       _loc3_.y = this.height;
  316.       this.localToGlobal(_loc3_);
  317.       if(show)
  318.       {
  319.          this.getDropdown();
  320.          var _loc2_ = this.__dropdown;
  321.          _loc2_.isPressed = true;
  322.          _loc2_.rowCount = this.rowCount;
  323.          _loc2_.visible = show;
  324.          _loc2_.onTweenEnd = this.tweenEndShow;
  325.          var _loc5_ = undefined;
  326.          var _loc8_ = undefined;
  327.          if(_loc3_.y + _loc2_.height > Stage.height)
  328.          {
  329.             _loc5_ = _loc3_.y - this.height;
  330.             _loc8_ = _loc5_ - _loc2_.height;
  331.             this.mask._y = - _loc2_.height;
  332.          }
  333.          else
  334.          {
  335.             _loc5_ = _loc3_.y - _loc2_.height;
  336.             _loc8_ = _loc3_.y;
  337.             this.mask._y = this.border_mc.height;
  338.          }
  339.          var _loc7_ = _loc2_.selectedIndex;
  340.          if(_loc7_ == undefined)
  341.          {
  342.             _loc7_ = 0;
  343.          }
  344.          var _loc4_ = _loc2_.vPosition;
  345.          _loc4_ = _loc7_ - 1;
  346.          _loc4_ = Math.min(Math.max(_loc4_,0),_loc2_.length - _loc2_.rowCount);
  347.          _loc2_.vPosition = _loc4_;
  348.          _loc2_.move(_loc3_.x,_loc5_);
  349.          _loc2_.tween = new mx.effects.Tween(this.__dropdown,_loc5_,_loc8_,this.getStyle("openDuration"));
  350.       }
  351.       else
  352.       {
  353.          delete this.__dropdown.dragScrolling;
  354.          this.__dropdown.onTweenEnd = this.tweenEndHide;
  355.          this.__dropdown.tween = new mx.effects.Tween(this.__dropdown,this.__dropdown._y,_loc3_.y - this.__dropdown.height,this.getStyle("openDuration"));
  356.       }
  357.       var _loc9_ = this.getStyle("openEasing");
  358.       if(_loc9_ != undefined)
  359.       {
  360.          this.__dropdown.tween.easingEquation = _loc9_;
  361.       }
  362.       this._showingDropdown = show;
  363.       this.dispatchEvent({type:(!show ? "close" : "open"),target:this});
  364.    }
  365.    function onDownArrow()
  366.    {
  367.       this._parent.displayDropdown(!this._parent._showingDropdown);
  368.    }
  369.    function keyDown(e)
  370.    {
  371.       if(e.ctrlKey && e.code == 40)
  372.       {
  373.          this.displayDropdown(true);
  374.       }
  375.       else if(e.ctrlKey && e.code == 38)
  376.       {
  377.          this.displayDropdown(false);
  378.       }
  379.       else if(e.code == 27)
  380.       {
  381.          this.displayDropdown(false);
  382.       }
  383.       else if(e.code == 13)
  384.       {
  385.          if(this._showingDropdown)
  386.          {
  387.             this.selectedIndex = this.__dropdown.selectedIndex;
  388.             this.displayDropdown(false);
  389.          }
  390.       }
  391.       else if(!this._editable || e.code == 38 || e.code == 40 || e.code == 33 || e.code == 34)
  392.       {
  393.          this.selectedIndex = 0 + this.selectedIndex;
  394.          this.bInKeyDown = true;
  395.          var _loc3_ = this.dropdown;
  396.          _loc3_.keyDown(e);
  397.          this.bInKeyDown = false;
  398.          this.selectedIndex = this.__dropdown.selectedIndex;
  399.       }
  400.    }
  401.    function invalidateStyle(styleProp)
  402.    {
  403.       this.__dropdown.invalidateStyle(styleProp);
  404.       super.invalidateStyle(styleProp);
  405.    }
  406.    function changeTextStyleInChildren(styleProp)
  407.    {
  408.       if(this.dropdown.stylecache != undefined)
  409.       {
  410.          delete this.dropdown.stylecache[styleProp];
  411.          delete this.dropdown.stylecache.tf;
  412.       }
  413.       this.__dropdown.changeTextStyleInChildren(styleProp);
  414.       super.changeTextStyleInChildren(styleProp);
  415.    }
  416.    function changeColorStyleInChildren(sheetName, styleProp, newValue)
  417.    {
  418.       if(this.dropdown.stylecache != undefined)
  419.       {
  420.          delete this.dropdown.stylecache[styleProp];
  421.          delete this.dropdown.stylecache.tf;
  422.       }
  423.       this.__dropdown.changeColorStyleInChildren(sheetName,styleProp,newValue);
  424.       super.changeColorStyleInChildren(sheetName,styleProp,newValue);
  425.    }
  426.    function notifyStyleChangeInChildren(sheetName, styleProp, newValue)
  427.    {
  428.       if(this.dropdown.stylecache != undefined)
  429.       {
  430.          delete this.dropdown.stylecache[styleProp];
  431.          delete this.dropdown.stylecache.tf;
  432.       }
  433.       this.__dropdown.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  434.       super.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  435.    }
  436.    function onUnload()
  437.    {
  438.       this.__dropdown.removeMovieClip();
  439.    }
  440.    function _resizeHandler()
  441.    {
  442.       var _loc2_ = this.owner;
  443.       _loc2_.mask._width = this.width;
  444.       _loc2_.mask._height = this.height;
  445.    }
  446.    function _changeHandler(obj)
  447.    {
  448.       var _loc2_ = this.owner;
  449.       obj.target = _loc2_;
  450.       if(this != this.owner.text_mc)
  451.       {
  452.          _loc2_.selectedIndex = this.selectedIndex;
  453.          if(!_loc2_.bInKeyDown)
  454.          {
  455.             _loc2_.displayDropdown(false);
  456.          }
  457.       }
  458.       _loc2_.dispatchEvent(obj);
  459.    }
  460.    function _scrollHandler(obj)
  461.    {
  462.       var _loc2_ = this.owner;
  463.       obj.target = _loc2_;
  464.       _loc2_.dispatchEvent(obj);
  465.    }
  466.    function _itemRollOverHandler(obj)
  467.    {
  468.       var _loc2_ = this.owner;
  469.       obj.target = _loc2_;
  470.       _loc2_.dispatchEvent(obj);
  471.    }
  472.    function _itemRollOutHandler(obj)
  473.    {
  474.       var _loc2_ = this.owner;
  475.       obj.target = _loc2_;
  476.       _loc2_.dispatchEvent(obj);
  477.    }
  478.    function modelChanged(eventObj)
  479.    {
  480.       super.modelChanged(eventObj);
  481.       if(0 == this.__dataProvider.length)
  482.       {
  483.          this.text_mc.setText("");
  484.          delete this.selected;
  485.       }
  486.       else if(this.__dataProvider.length == eventObj.lastItem - eventObj.firstItem + 1 && eventObj.eventName == "addItems")
  487.       {
  488.          this.selectedIndex = 0;
  489.       }
  490.    }
  491. }
  492.