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

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

goog.require('org.apache.royale.core.IBorderPaddingMarginValuesImpl');
goog.require('org.apache.royale.core.ILayoutView');
goog.require('org.apache.royale.core.IMeasurementBead');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.IUIBase');
goog.require('org.apache.royale.core.LayoutBase');
goog.require('org.apache.royale.core.ValuesManager');
goog.require('org.apache.royale.core.layout.EdgeData');
goog.require('org.apache.royale.core.IBeadLayout');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.0
 * @constructor
 * @extends {org.apache.royale.core.LayoutBase}
 * @implements {org.apache.royale.core.IBeadLayout}
 */
org.apache.royale.html.beads.layouts.VerticalColumnLayout = function() {
  org.apache.royale.html.beads.layouts.VerticalColumnLayout.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.beads.layouts.VerticalColumnLayout, org.apache.royale.core.LayoutBase);


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


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.org_apache_royale_html_beads_layouts_VerticalColumnLayout__numColumns = 0;


/**
 * @copy org.apache.royale.core.IBeadLayout#layout
 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
 * @royaleignorecoercion org.apache.royale.core.IMeasurementBead
 * @royaleignorecoercion org.apache.royale.core.IBorderPaddingMarginValuesImpl
 * @export
 * @override
 */
org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.layout = function() {
  var /** @type {org.apache.royale.core.ILayoutView} */ contentView = this.layoutView;
  if (contentView.element.style.position != "absolute" && contentView.element.style.position != "relative") {
    contentView.element.style.position = "relative";
  }
  contentView.element.style["vertical-align"] = "top";
  var /** @type {org.apache.royale.core.layout.EdgeData} */ padding = org.apache.royale.core.ValuesManager["valuesImpl"].getPaddingMetrics(this.host);
  var /** @type {number} */ sw = this.host.width;
  var /** @type {number} */ sh = this.host.height;
  var /** @type {boolean} */ hasWidth = !this.host.isWidthSizedToContent();
  var /** @type {boolean} */ hasHeight = !this.host.isHeightSizedToContent();
  var /** @type {org.apache.royale.core.IUIBase} */ e;
  var /** @type {number} */ i = 0;
  var /** @type {number} */ col = 0;
  var /** @type {Array} */ columns = [];
  var /** @type {Array} */ rows = [];
  var /** @type {Array} */ data = [];
  for (i = 0; i < this.numColumns; i++)
    columns[i] = 0;
  var /** @type {number} */ n = contentView.numElements;
  var /** @type {Object} */ rowData = {rowHeight:0};
  var /** @type {Array} */ views = [];
  var /** @type {Array} */ heights = [];
  var /** @type {Array} */ widths = [];
  for (i = 0; i < n; i++) {
    views[i] = contentView.getElementAt(i);
    heights[i] = views[i].height;
    widths[i] = views[i].width;
    e = views[i];
    if (e == null || !e.visible)
      continue;
    var /** @type {Object} */ margins = this.childMargins(e, sw, sh);
    data.push({mt:margins.top, mb:margins.bottom, mr:margins.right, ml:margins.left});
    var /** @type {number} */ thisPrefWidth = 0;
    if (org.apache.royale.utils.Language.is(e, org.apache.royale.core.IStrand)) {
      var /** @type {Object} */ measure = e.getBeadByType(org.apache.royale.core.IMeasurementBead);
      if (measure)
        thisPrefWidth = Number(measure.measuredWidth + margins.left + margins.right);
      else
        thisPrefWidth = Number(widths[i] + margins.left + margins.right);
    }
    else
      thisPrefWidth = Number(widths[i] + margins.left + margins.right);
    rowData.rowHeight = Math.max(rowData.rowHeight, heights[i] + margins.top + margins.bottom);
    columns[col] = Math.max(columns[col], thisPrefWidth);
    col = col + 1;
    if (col == this.numColumns) {
      rows.push(rowData);
      rowData = {rowHeight:0};
      col = 0;
    }
  }
  var /** @type {number} */ lastmb = 0;
  var /** @type {number} */ curx = padding.left;
  var /** @type {number} */ cury = padding.top;
  var /** @type {number} */ maxHeight = 0;
  var /** @type {number} */ maxWidth = 0;
  col = 0;
  for (i = 0; i < n; i++) {
    e = views[i];
    if (e == null || !e.visible)
      continue;
    e.x = Number(curx + data[i].ml);
    e.y = Number(cury + data[i].mt);
    curx += Number(columns[col++]);
    maxHeight = Math.max(maxHeight, e.y + heights[i] + data[i].mb);
    maxWidth = Math.max(maxWidth, e.x + widths[i] + data[i].mr);
    if (col == this.numColumns) {
      cury += Number(rows[0].rowHeight);
      rows.shift();
      col = 0;
      curx = padding.left;
    }
    e.element.style.position = "absolute";
  }
  return true;
};


org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.get__numColumns = function() {
  return this.org_apache_royale_html_beads_layouts_VerticalColumnLayout__numColumns;
};


org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.set__numColumns = function(value) {
  this.org_apache_royale_html_beads_layouts_VerticalColumnLayout__numColumns = value;
};


Object.defineProperties(org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype, /** @lends {org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype} */ {
/**
  * @export
  * @type {number} */
numColumns: {
get: org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.get__numColumns,
set: org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.set__numColumns}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.layouts.VerticalColumnLayout.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'numColumns': { type: 'int', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.layouts.VerticalColumnLayout'}
      };
    },
    methods: function () {
      return {
        'VerticalColumnLayout': { type: '', declaredBy: 'org.apache.royale.html.beads.layouts.VerticalColumnLayout'},
        'layout': { type: 'Boolean', declaredBy: 'org.apache.royale.html.beads.layouts.VerticalColumnLayout'}
      };
    }
  };
};