/**
 * Generated by Apache Royale Compiler from org\apache\royale\html\beads\ComboBoxView.as
 * org.apache.royale.html.beads.ComboBoxView
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.html.beads.ComboBoxView');

goog.require('org.apache.royale.core.BeadViewBase');
goog.require('org.apache.royale.core.IComboBoxModel');
goog.require('org.apache.royale.core.IPopUpHost');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.IUIBase');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.ValuesManager');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.geom.Point');
goog.require('org.apache.royale.html.TextButton');
goog.require('org.apache.royale.html.TextInput');
goog.require('org.apache.royale.html.util.getLabelFromData');
goog.require('org.apache.royale.utils.PointUtils');
goog.require('org.apache.royale.utils.UIUtils');
goog.require('org.apache.royale.html.beads.IComboBoxView');
goog.require('org.apache.royale.utils.Language');



/**
 * @constructor
 * @extends {org.apache.royale.core.BeadViewBase}
 * @implements {org.apache.royale.html.beads.IComboBoxView}
 */
org.apache.royale.html.beads.ComboBoxView = function() {
  org.apache.royale.html.beads.ComboBoxView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.beads.ComboBoxView, org.apache.royale.core.BeadViewBase);


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.html.beads.ComboBoxView', org.apache.royale.html.beads.ComboBoxView);


/**
 * @private
 * @type {org.apache.royale.html.TextInput}
 */
org.apache.royale.html.beads.ComboBoxView.prototype.org_apache_royale_html_beads_ComboBoxView_input;


/**
 * @private
 * @type {org.apache.royale.html.TextButton}
 */
org.apache.royale.html.beads.ComboBoxView.prototype.org_apache_royale_html_beads_ComboBoxView_button;


/**
 * @private
 * @type {org.apache.royale.core.UIBase}
 */
org.apache.royale.html.beads.ComboBoxView.prototype.org_apache_royale_html_beads_ComboBoxView_list;


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.ComboBoxView.prototype.handleSizeChange = function(event) {
  this.sizeChangeAction();
};


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.ComboBoxView.prototype.handleItemChange = function(event) {
  this.itemChangeAction();
};


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.IComboBoxModel
 * @protected
 */
org.apache.royale.html.beads.ComboBoxView.prototype.itemChangeAction = function() {
  var /** @type {Object} */ model = this._strand.getBeadByType(org.apache.royale.core.IComboBoxModel);
  this.org_apache_royale_html_beads_ComboBoxView_input.text = org.apache.royale.html.util.getLabelFromData(model, model.selectedItem);
};


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.UIBase
 * @protected
 */
org.apache.royale.html.beads.ComboBoxView.prototype.sizeChangeAction = function() {
  var /** @type {Object} */ host = this._strand;
  this.org_apache_royale_html_beads_ComboBoxView_input.x = 0;
  this.org_apache_royale_html_beads_ComboBoxView_input.y = 0;
  if (host.isWidthSizedToContent()) {
    this.org_apache_royale_html_beads_ComboBoxView_input.width = 100;
  } else {
    this.org_apache_royale_html_beads_ComboBoxView_input.width = host.width - 20;
  }
  this.org_apache_royale_html_beads_ComboBoxView_button.x = this.org_apache_royale_html_beads_ComboBoxView_input.width;
  this.org_apache_royale_html_beads_ComboBoxView_button.y = 0;
  this.org_apache_royale_html_beads_ComboBoxView_button.width = 20;
  this.org_apache_royale_html_beads_ComboBoxView_button.height = this.org_apache_royale_html_beads_ComboBoxView_input.height;
  this.org_apache_royale_html_beads_ComboBoxView_input.element.style.position = "absolute";
  this.org_apache_royale_html_beads_ComboBoxView_button.element.style.position = "absolute";
  if (host.isHeightSizedToContent()) {
    host.height = this.org_apache_royale_html_beads_ComboBoxView_input.height;
  }
  if (host.isWidthSizedToContent()) {
    host.width = this.org_apache_royale_html_beads_ComboBoxView_input.width + this.org_apache_royale_html_beads_ComboBoxView_button.width;
  }
};


org.apache.royale.html.beads.ComboBoxView.prototype.get__textInputField = function() {
  return this.org_apache_royale_html_beads_ComboBoxView_input;
};


org.apache.royale.html.beads.ComboBoxView.prototype.get__popupButton = function() {
  return this.org_apache_royale_html_beads_ComboBoxView_button;
};


org.apache.royale.html.beads.ComboBoxView.prototype.get__popUp = function() {
  return this.org_apache_royale_html_beads_ComboBoxView_list;
};


org.apache.royale.html.beads.ComboBoxView.prototype.set__strand = function(value) {
  org.apache.royale.html.beads.ComboBoxView.superClass_.set__strand.apply(this, [ value] );
  var /** @type {Object} */ host = value;
  this.org_apache_royale_html_beads_ComboBoxView_input = new org.apache.royale.html.TextInput();
  this.org_apache_royale_html_beads_ComboBoxView_input.className = "ComboBoxTextInput";
  this.org_apache_royale_html_beads_ComboBoxView_button = new org.apache.royale.html.TextButton();
  this.org_apache_royale_html_beads_ComboBoxView_button.style = {"padding":0, "margin":0};
  this.org_apache_royale_html_beads_ComboBoxView_button.text = '▼';
  if (isNaN(host.width))
    this.org_apache_royale_html_beads_ComboBoxView_input.width = 100;
  if (!host.element.style.position) {
    host.element.style.position = "relative";
  }
  host.addElement(this.org_apache_royale_html_beads_ComboBoxView_input);
  host.addElement(this.org_apache_royale_html_beads_ComboBoxView_button);
  var /** @type {Object} */ popUpClass = org.apache.royale.utils.Language.as(org.apache.royale.core.ValuesManager["valuesImpl"].getValue(this._strand, "iPopUp"), Object);
  this.org_apache_royale_html_beads_ComboBoxView_list = new popUpClass();
  this.org_apache_royale_html_beads_ComboBoxView_list.visible = false;
  var /** @type {org.apache.royale.core.IComboBoxModel} */ model = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IComboBoxModel), org.apache.royale.core.IComboBoxModel);
  model.addEventListener("selectedIndexChanged", org.apache.royale.utils.Language.closure(this.handleItemChange, this, 'handleItemChange'));
  model.addEventListener("selectedItemChanged", org.apache.royale.utils.Language.closure(this.handleItemChange, this, 'handleItemChange'));
  this._strand.addEventListener("sizeChanged", org.apache.royale.utils.Language.closure(this.handleSizeChange, this, 'handleSizeChange'));
  this.itemChangeAction();
  this.sizeChangeAction();
};


org.apache.royale.html.beads.ComboBoxView.prototype.get__popUpVisible = function() {
  if (this.org_apache_royale_html_beads_ComboBoxView_list)
    return this.org_apache_royale_html_beads_ComboBoxView_list.visible;
  else
    return false;
};


org.apache.royale.html.beads.ComboBoxView.prototype.set__popUpVisible = function(value) {
  if (value && !this.org_apache_royale_html_beads_ComboBoxView_list.visible) {
    var /** @type {org.apache.royale.core.IComboBoxModel} */ model = this._strand.getBeadByType(org.apache.royale.core.IComboBoxModel);
    this.org_apache_royale_html_beads_ComboBoxView_list.model = model;
    this.org_apache_royale_html_beads_ComboBoxView_list.width = this.org_apache_royale_html_beads_ComboBoxView_input.width;
    this.org_apache_royale_html_beads_ComboBoxView_list.height = 200;
    this.org_apache_royale_html_beads_ComboBoxView_list.visible = true;
    var /** @type {org.apache.royale.geom.Point} */ origin = new org.apache.royale.geom.Point(0, this.org_apache_royale_html_beads_ComboBoxView_button.y + this.org_apache_royale_html_beads_ComboBoxView_button.height);
    var /** @type {org.apache.royale.geom.Point} */ relocated = org.apache.royale.utils.PointUtils.localToGlobal(origin, this._strand);
    this.org_apache_royale_html_beads_ComboBoxView_list.x = relocated.x;
    this.org_apache_royale_html_beads_ComboBoxView_list.y = relocated.y;
    this.org_apache_royale_html_beads_ComboBoxView_list.element.style.position = "absolute";
    var /** @type {org.apache.royale.core.IPopUpHost} */ popupHost = org.apache.royale.utils.UIUtils.findPopUpHost(this._strand);
    popupHost.popUpParent.addElement(this.org_apache_royale_html_beads_ComboBoxView_list);
  } else if (this.org_apache_royale_html_beads_ComboBoxView_list.visible) {
    org.apache.royale.utils.UIUtils.removePopUp(this.org_apache_royale_html_beads_ComboBoxView_list);
    this.org_apache_royale_html_beads_ComboBoxView_list.visible = false;
  }
};


Object.defineProperties(org.apache.royale.html.beads.ComboBoxView.prototype, /** @lends {org.apache.royale.html.beads.ComboBoxView.prototype} */ {
/**
  * @export
  * @type {Object} */
textInputField: {
get: org.apache.royale.html.beads.ComboBoxView.prototype.get__textInputField},
/**
  * @export
  * @type {Object} */
popupButton: {
get: org.apache.royale.html.beads.ComboBoxView.prototype.get__popupButton},
/**
  * @export
  * @type {Object} */
popUp: {
get: org.apache.royale.html.beads.ComboBoxView.prototype.get__popUp},
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.beads.ComboBoxView.prototype.set__strand},
/**
  * @export
  * @type {boolean} */
popUpVisible: {
get: org.apache.royale.html.beads.ComboBoxView.prototype.get__popUpVisible,
set: org.apache.royale.html.beads.ComboBoxView.prototype.set__popUpVisible}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.html.beads.ComboBoxView.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'ComboBoxView', qName: 'org.apache.royale.html.beads.ComboBoxView', kind: 'class' }], interfaces: [org.apache.royale.html.beads.IComboBoxView] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.ComboBoxView.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'textInputField': { type: 'Object', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.ComboBoxView'},
        'popupButton': { type: 'Object', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.ComboBoxView'},
        'popUp': { type: 'Object', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.ComboBoxView'},
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.html.beads.ComboBoxView'},
        'popUpVisible': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.ComboBoxView'}
      };
    },
    methods: function () {
      return {
        'ComboBoxView': { type: '', declaredBy: 'org.apache.royale.html.beads.ComboBoxView'}
      };
    }
  };
};