home *** CD-ROM | disk | FTP | other *** search
/ The Complete Idiot's Guide to Microsoft Excel 2010 / CIGExcel.iso / Videos / Flash / controller.swf / scripts / __Packages / mx / controls / alertClasses / AlertForm.as
Encoding:
Text File  |  2010-09-09  |  6.5 KB  |  181 lines

  1. class mx.controls.alertClasses.AlertForm extends mx.core.UIComponent
  2. {
  3.    var text_mc;
  4.    var textMeasure_mc;
  5.    var icon_mc;
  6.    var buttons;
  7.    var createClassChildAtDepth;
  8.    var extent;
  9.    var detail;
  10.    static var symbolOwner = mx.core.UIComponent;
  11.    var idNames = ["text_mc","icon_mc"];
  12.    var defButtonName = undefined;
  13.    function AlertForm()
  14.    {
  15.       super();
  16.    }
  17.    function init(Void)
  18.    {
  19.       super.init();
  20.    }
  21.    function setDefaultButton()
  22.    {
  23.       this._parent.focusManager.defaultPushButton = this[this.defButtonName];
  24.    }
  25.    function createChildren(Void)
  26.    {
  27.       this.tabChildren = true;
  28.       this.tabEnabled = false;
  29.       if(this.text_mc == undefined)
  30.       {
  31.          this.createClassObject(mx.controls.TextArea,"text_mc",0,{styleName:this,borderStyle:"none",readOnly:true});
  32.       }
  33.       this.text_mc.tabEnabled = false;
  34.       this.text_mc.tabChildren = false;
  35.       this.text_mc.hScrollPolicy = "off";
  36.       this.text_mc.vScrollPolicy = "off";
  37.       this.text_mc.label.selectable = false;
  38.       if(this.textMeasure_mc == undefined)
  39.       {
  40.          this.createTextField("textMeasure_mc",-1,0,0,0,0);
  41.       }
  42.       this.textMeasure_mc._visible = false;
  43.       this.textMeasure_mc.multiline = true;
  44.       this.textMeasure_mc.wordWrap = true;
  45.       this.textMeasure_mc.autoSize = "left";
  46.       if(this.icon_mc == undefined && this._parent.icon != undefined)
  47.       {
  48.          this.setSkin(1,this._parent.icon);
  49.       }
  50.       this.buttons = new Array();
  51.       var _loc2_ = this._parent.defButton;
  52.       if(this._parent.okButton)
  53.       {
  54.          this.createButton("okButton",mx.controls.Alert.okLabel,mx.controls.Alert.OK);
  55.          if(_loc2_ == mx.controls.Alert.OK)
  56.          {
  57.             this.defButtonName = "okButton";
  58.          }
  59.       }
  60.       if(this._parent.yesButton)
  61.       {
  62.          this.createButton("yesButton",mx.controls.Alert.yesLabel,mx.controls.Alert.YES);
  63.          if(_loc2_ == mx.controls.Alert.YES)
  64.          {
  65.             this.defButtonName = "yesButton";
  66.          }
  67.       }
  68.       if(this._parent.noButton)
  69.       {
  70.          this.createButton("noButton",mx.controls.Alert.noLabel,mx.controls.Alert.NO);
  71.          if(_loc2_ == mx.controls.Alert.NO)
  72.          {
  73.             this.defButtonName = "noButton";
  74.          }
  75.       }
  76.       if(this._parent.cancelButton)
  77.       {
  78.          this.createButton("cancelButton",mx.controls.Alert.cancelLabel,mx.controls.Alert.CANCEL);
  79.          if(_loc2_ == mx.controls.Alert.CANCEL)
  80.          {
  81.             this.defButtonName = "cancelButton";
  82.          }
  83.       }
  84.       if(this.defButtonName != undefined)
  85.       {
  86.          this[this.defButtonName].emphasized = true;
  87.          this[this.defButtonName].redraw(true);
  88.          this.doLater(this,"setDefaultButton");
  89.       }
  90.    }
  91.    function createButton(name, title, detail)
  92.    {
  93.       var _loc3_ = mx.controls.Alert.buttonStyleDeclaration;
  94.       var _loc2_ = mx.controls.Button(this.createClassChildAtDepth(mx.controls.Button,mx.managers.DepthManager.kTop,{falseUpSkin:mx.controls.Alert.buttonUp,falseDownSkin:mx.controls.Alert.buttonDown,falseOverSkin:mx.controls.Alert.buttonOver,falseOverSkinEmphasized:mx.controls.Alert.buttonOverEmphasized,falseUpSkinEmphasized:mx.controls.Alert.buttonUpEmphasized,falseDownSkinEmphasized:mx.controls.Alert.buttonDownEmphasized,styleName:(_loc3_ != undefined ? mx.controls.Alert.buttonStyleDeclaration : this),validateNow:true}));
  95.       _loc2_.setLabel(title);
  96.       _loc2_.setSize(mx.controls.Alert.buttonWidth,mx.controls.Alert.buttonHeight);
  97.       this.buttons.push(_loc2_);
  98.       _loc2_.clickHandler = this.onClick;
  99.       _loc2_.detail = detail;
  100.       this[name] = _loc2_;
  101.    }
  102.    function getSize(Void)
  103.    {
  104.       var _loc2_ = new Object();
  105.       _loc2_.height = this.buttons[0].height + 24;
  106.       var _loc8_ = this._parent.back_mc.title_mc._getTextFormat();
  107.       this.extent = _loc8_.getTextExtent2(this._parent.title);
  108.       _loc2_.width = Math.max(Math.max(2,this.buttons.length) * (this.buttons[0].width + 8),this.extent.width + 4 + 8);
  109.       var _loc6_ = this.text_mc._getTextFormat();
  110.       this.extent = _loc6_.getTextExtent2(this._parent.text);
  111.       this.textMeasure_mc._width = 2 * _loc2_.width;
  112.       this.textMeasure_mc.setNewTextFormat(this.text_mc._getTextFormat());
  113.       this.textMeasure_mc.text = this._parent.text;
  114.       _loc2_.height += this.textMeasure_mc.textHeight + 8;
  115.       var _loc4_ = Math.ceil(this.textMeasure_mc.textHeight / this.extent.height);
  116.       if(_loc4_ > 1)
  117.       {
  118.          this.extent.width = 2 * _loc2_.width;
  119.          this.text_mc.wordWrap = true;
  120.       }
  121.       var _loc3_ = Math.min(this.extent.width + 4 + 8,2 * _loc2_.width);
  122.       var _loc7_ = _loc2_.width;
  123.       _loc2_.width = Math.max(_loc3_,_loc2_.width) + 8;
  124.       if(this.icon_mc != undefined)
  125.       {
  126.          this.extent.width += this.icon_mc.width + 8;
  127.          _loc3_ = Math.min(this.extent.width + 4 + 8,2 * _loc7_);
  128.          _loc2_.width = Math.max(_loc3_,_loc2_.width) + 8;
  129.          var _loc5_ = this.icon_mc.height - _loc4_ * (this.extent.height + 4);
  130.          if(_loc5_ > 0)
  131.          {
  132.             _loc2_.height += _loc5_;
  133.          }
  134.       }
  135.       return _loc2_;
  136.    }
  137.    function draw(Void)
  138.    {
  139.       this.size();
  140.       this._parent.visible = true;
  141.    }
  142.    function size(Void)
  143.    {
  144.       var _loc4_ = this.height - this.buttons[0].height - 8;
  145.       var _loc3_ = this.buttons.length * (this.buttons[0].width + 8) - 8;
  146.       _loc3_ = (this.width - _loc3_) / 2;
  147.       var _loc2_ = 0;
  148.       while(_loc2_ < this.buttons.length)
  149.       {
  150.          this.buttons[_loc2_].move(_loc3_,_loc4_);
  151.          this.buttons[_loc2_].tabIndex = _loc2_ + 1;
  152.          _loc3_ += this.buttons[_loc2_].width + 8;
  153.          _loc2_ = _loc2_ + 1;
  154.       }
  155.       _loc4_ -= 8;
  156.       _loc3_ = Math.max((this.width - this.extent.width - 4) / 2,8);
  157.       if(this.icon_mc != undefined)
  158.       {
  159.          this.icon_mc.move(_loc3_,(this.height - this.buttons[0].height - this.icon_mc.height) / 2);
  160.          _loc3_ += this.icon_mc.width + 8;
  161.       }
  162.       this.text_mc.move(_loc3_,8);
  163.       this.text_mc.setSize(this.width - _loc3_ - 8,_loc4_ - 8);
  164.       if(this._parent.text == undefined)
  165.       {
  166.          this.text_mc.text = "";
  167.       }
  168.       else
  169.       {
  170.          this.text_mc.text = this._parent.text;
  171.       }
  172.    }
  173.    function onClick(evt)
  174.    {
  175.       var _loc2_ = mx.controls.Alert(this._parent._parent);
  176.       _loc2_.visible = false;
  177.       _loc2_.dispatchEvent({type:"click",detail:this.detail});
  178.       _loc2_.deletePopUp();
  179.    }
  180. }
  181.