/* start module: pyjamas.ui.MenuBar */
pyjamas.ui.MenuBar = $pyjs.loaded_modules["pyjamas.ui.MenuBar"] = function (__mod_name__) {
if(pyjamas.ui.MenuBar.__was_initialized__) return pyjamas.ui.MenuBar;
pyjamas.ui.MenuBar.__was_initialized__ = true;
if (__mod_name__ == null) __mod_name__ = 'pyjamas.ui.MenuBar';
var __name__ = pyjamas.ui.MenuBar.__name__ = __mod_name__;
var MenuBar = pyjamas.ui.MenuBar;

 pyjslib.__import__(['pyjamas.ui.pyjamas.DOM', 'pyjamas.ui.pyjamas', 'pyjamas.DOM', 'pyjamas'], 'pyjamas.DOM', 'pyjamas.ui.MenuBar')
 pyjamas.ui.MenuBar.DOM = $pyjs.__modules__.pyjamas.DOM;
 pyjslib.__import__(['pyjamas.ui.pyjamas.DeferredCommand.DeferredCommand', 'pyjamas.ui.pyjamas.DeferredCommand', 'pyjamas.DeferredCommand.DeferredCommand', 'pyjamas.DeferredCommand'], 'pyjamas.DeferredCommand.DeferredCommand', 'pyjamas.ui.MenuBar')
 pyjamas.ui.MenuBar.DeferredCommand = $pyjs.__modules__.pyjamas.DeferredCommand.DeferredCommand;
 pyjslib.__import__(['pyjamas.ui.pyjamas.ui.Widget.Widget', 'pyjamas.ui.pyjamas.ui.Widget', 'pyjamas.ui.Widget.Widget', 'pyjamas.ui.Widget'], 'pyjamas.ui.Widget.Widget', 'pyjamas.ui.MenuBar')
 pyjamas.ui.MenuBar.Widget = $pyjs.__modules__.pyjamas.ui.Widget.Widget;
 pyjslib.__import__(['pyjamas.ui.pyjamas.ui.MenuItem.MenuItem', 'pyjamas.ui.pyjamas.ui.MenuItem', 'pyjamas.ui.MenuItem.MenuItem', 'pyjamas.ui.MenuItem'], 'pyjamas.ui.MenuItem.MenuItem', 'pyjamas.ui.MenuBar')
 pyjamas.ui.MenuBar.MenuItem = $pyjs.__modules__.pyjamas.ui.MenuItem.MenuItem;
 pyjslib.__import__(['pyjamas.ui.pyjamas.ui.MenuBarPopupPanel.MenuBarPopupPanel', 'pyjamas.ui.pyjamas.ui.MenuBarPopupPanel', 'pyjamas.ui.MenuBarPopupPanel.MenuBarPopupPanel', 'pyjamas.ui.MenuBarPopupPanel'], 'pyjamas.ui.MenuBarPopupPanel.MenuBarPopupPanel', 'pyjamas.ui.MenuBar')
 pyjamas.ui.MenuBar.MenuBarPopupPanel = $pyjs.__modules__.pyjamas.ui.MenuBarPopupPanel.MenuBarPopupPanel;
pyjamas.ui.MenuBar.MenuBar = (function(){
	var cls_instance = pyjs__class_instance('MenuBar');
	var cls_definition = new Object();
	cls_definition.__md5__ = 'a5da9c587d5c1a90e20c42f433af4531';
	cls_definition.__init__ = pyjs__bind_method(cls_instance, '__init__', function(vertical) {
		if (this.__is_instance__ === true) {
			var self = this;
			var kwargs = arguments.length >= 2 ? arguments[arguments.length-1] : arguments[arguments.length];
			if (typeof kwargs != 'object' || kwargs.__is_instance__ !== true || kwargs.__name__ != 'Dict') {
				kwargs = arguments[arguments.length+1];
			}
		} else {
			var self = arguments[0];
			vertical = arguments[1];
			var kwargs = arguments.length >= 3 ? arguments[arguments.length-1] : arguments[arguments.length];
			if (typeof kwargs != 'object' || kwargs.__is_instance__ !== true || kwargs.__name__ != 'Dict') {
				kwargs = arguments[arguments.length+1];
			}
		}
		if (typeof kwargs == 'undefined') {
			kwargs = pyjslib.Dict({});
			if (typeof vertical != 'undefined') {
				if (pyjslib.get_pyjs_classtype(vertical) == 'Dict') {
					kwargs = vertical;
					vertical = arguments[2];
				}
			} else 			if (typeof self != 'undefined') {
				if (pyjslib.get_pyjs_classtype(self) == 'Dict') {
					kwargs = self;
					self = arguments[2];
				}
			} else {
			}
		}
		if (typeof vertical == 'undefined') vertical=false;
		var outer,tr,table;
		if (pyjslib.bool(!(kwargs.has_key(String('StyleName'))))) {
			kwargs.__setitem__(String('StyleName'), String('gwt-MenuBar'));
		}
		self.body = null;
		self.items = new pyjslib.List([]);
		self.parentMenu = null;
		self.popup = null;
		self.selectedItem = null;
		self.shownChildMenu = null;
		self.vertical = false;
		self.autoOpen = false;
		table = pyjamas.ui.MenuBar.DOM.createTable();
		self.body = pyjamas.ui.MenuBar.DOM.createTBody();
		pyjamas.ui.MenuBar.DOM.appendChild(table, self.body);
		if (pyjslib.bool(!(vertical))) {
			tr = pyjamas.ui.MenuBar.DOM.createTR();
			pyjamas.ui.MenuBar.DOM.appendChild(self.body, tr);
		}
		self.vertical = vertical;
		outer = pyjamas.ui.MenuBar.DOM.createDiv();
		pyjamas.ui.MenuBar.DOM.appendChild(outer, table);
		self.setElement(outer);
		pyjs_kwargs_call(pyjamas.ui.MenuBar.Widget, '__init__', null, kwargs, [{}, self]);
		return null;
	}
	, 1, [null,'kwargs','self', 'vertical']);
	cls_definition.addItem = pyjs__bind_method(cls_instance, 'addItem', function(item, asHTML, popup) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			item = arguments[1];
			asHTML = arguments[2];
			popup = arguments[3];
		}
		if (typeof asHTML == 'undefined') asHTML=null;
		if (typeof popup == 'undefined') popup=null;
		var tr;
		if (pyjslib.bool(!(pyjslib.hasattr(item, String('setSubMenu'))))) {
			item = pyjamas.ui.MenuBar.MenuItem(item, asHTML, popup);
		}
		if (pyjslib.bool(self.vertical)) {
			tr = pyjamas.ui.MenuBar.DOM.createTR();
			pyjamas.ui.MenuBar.DOM.appendChild(self.body, tr);
		}
		else {
			tr = pyjamas.ui.MenuBar.DOM.getChild(self.body, 0);
		}
		pyjamas.ui.MenuBar.DOM.appendChild(tr, item.getElement());
		item.setParentMenu(self);
		item.setSelectionStyle(false);
		self.items.append(item);
		return item;
	}
	, 1, [null,null,'self', 'item', 'asHTML', 'popup']);
	cls_definition.clearItems = pyjs__bind_method(cls_instance, 'clearItems', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}
		var container;
		container = self.getItemContainerElement();
    while (pyjslib.bool((pyjslib.cmp(pyjamas.ui.MenuBar.DOM.getChildCount(container), 0) == 1))) {
		pyjamas.ui.MenuBar.DOM.removeChild(container, pyjamas.ui.MenuBar.DOM.getChild(container, 0));
    }
		self.items = new pyjslib.List([]);
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.getAutoOpen = pyjs__bind_method(cls_instance, 'getAutoOpen', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		return self.autoOpen;
	}
	, 1, [null,null,'self']);
	cls_definition.onBrowserEvent = pyjs__bind_method(cls_instance, 'onBrowserEvent', function(event) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			event = arguments[1];
		}
		var item,type;
		pyjamas.ui.MenuBar.Widget.onBrowserEvent(self, event);
		item = self.findItem(pyjamas.ui.MenuBar.DOM.eventGetTarget(event));
		if (pyjslib.bool((item === null))) {
			return false;
		}
		type = pyjamas.ui.MenuBar.DOM.eventGetType(event);
		if (pyjslib.bool(pyjslib.eq(type, String('click')))) {
			self.doItemAction(item, true);
			return true;
		}
		else if (pyjslib.bool(pyjslib.eq(type, String('mouseover')))) {
			self.itemOver(item);
		}
		else if (pyjslib.bool(pyjslib.eq(type, String('mouseout')))) {
			self.itemOver(null);
		}
		return false;
	}
	, 1, [null,null,'self', 'event']);
	cls_definition.onPopupClosed = pyjs__bind_method(cls_instance, 'onPopupClosed', function(sender, autoClosed) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			sender = arguments[1];
			autoClosed = arguments[2];
		}

		if (pyjslib.bool(autoClosed)) {
			self.closeAllParents();
		}
		self.onHide();
		self.shownChildMenu = null;
		self.popup = null;
		return null;
	}
	, 1, [null,null,'self', 'sender', 'autoClosed']);
	cls_definition.removeItem = pyjs__bind_method(cls_instance, 'removeItem', function(item) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			item = arguments[1];
		}
		var container,idx,err,pyjs_try_err;
		try {
			idx = self.items.index(item);
		} catch(pyjs_try_err) {
			var pyjs_try_err_name = (typeof pyjs_try_err.__name__ == 'undefined' ? pyjs_try_err.name : pyjs_try_err.__name__ );
			$pyjs.__last_exception__ = {error: pyjs_try_err, module: pyjamas.ui.MenuBar, try_lineno: 108};
			if (pyjs_try_err_name == pyjslib.ValueError.__name__) {
				$pyjs.__last_exception__.except_lineno = 110;
				err = pyjs_try_err;
				return null;
			} else { throw pyjs_try_err }
		}
		container = self.getItemContainerElement();
		pyjamas.ui.MenuBar.DOM.removeChild(container, pyjamas.ui.MenuBar.DOM.getChild(container, idx));
    self.items.__delitem__(idx);
		return null;
	}
	, 1, [null,null,'self', 'item']);
	cls_definition.setAutoOpen = pyjs__bind_method(cls_instance, 'setAutoOpen', function(autoOpen) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			autoOpen = arguments[1];
		}

		self.autoOpen = autoOpen;
		return null;
	}
	, 1, [null,null,'self', 'autoOpen']);
	cls_definition.closeAllParents = pyjs__bind_method(cls_instance, 'closeAllParents', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}
		var curMenu;
		curMenu = self;
    while (pyjslib.bool((curMenu !== null))) {
		curMenu.close();
		if (pyjslib.bool(((curMenu.parentMenu === null)) && ((curMenu.selectedItem !== null)))) {
			curMenu.selectedItem.setSelectionStyle(false);
			curMenu.selectedItem = null;
		}
		curMenu = curMenu.parentMenu;
    }
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.doItemAction = pyjs__bind_method(cls_instance, 'doItemAction', function(item, fireCommand) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			item = arguments[1];
			fireCommand = arguments[2];
		}
		var sub_menu,cmd;
		if (pyjslib.bool(((self.shownChildMenu !== null)) && (pyjslib.eq(item.getSubMenu(), self.shownChildMenu)))) {
			return null;
		}
		if (pyjslib.bool((self.shownChildMenu !== null))) {
			self.shownChildMenu.onHide();
			self.popup.hide();
		}
		if (pyjslib.bool((item.getSubMenu() === null))) {
			if (pyjslib.bool(fireCommand)) {
				self.closeAllParents();
				cmd = item.getCommand();
				if (pyjslib.bool((cmd !== null))) {
					pyjamas.ui.MenuBar.DeferredCommand().add(cmd);
				}
			}
			return null;
		}
		self.selectItem(item);
		self.popup = pyjamas.ui.MenuBar.MenuBarPopupPanel(item);
		self.popup.addPopupListener(self);
		if (pyjslib.bool(self.vertical)) {
			self.popup.setPopupPosition( ( item.getAbsoluteLeft() + item.getOffsetWidth() ) , item.getAbsoluteTop());
		}
		else {
			self.popup.setPopupPosition(item.getAbsoluteLeft(),  ( item.getAbsoluteTop() + item.getOffsetHeight() ) );
		}
		self.shownChildMenu = item.getSubMenu();
		sub_menu = item.getSubMenu();
		sub_menu.parentMenu = self;
		self.popup.show();
		return null;
	}
	, 1, [null,null,'self', 'item', 'fireCommand']);
	cls_definition.onDetach = pyjs__bind_method(cls_instance, 'onDetach', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool((self.popup !== null))) {
			self.popup.hide();
		}
		pyjamas.ui.MenuBar.Widget.onDetach(self);
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.itemOver = pyjs__bind_method(cls_instance, 'itemOver', function(item) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			item = arguments[1];
		}

		if (pyjslib.bool((item === null))) {
			if (pyjslib.bool(((self.selectedItem !== null)) && (pyjslib.eq(self.shownChildMenu, self.selectedItem.getSubMenu())))) {
				return null;
			}
		}
		self.selectItem(item);
		if (pyjslib.bool((item !== null))) {
			if (pyjslib.bool(((self.shownChildMenu !== null)) || ((self.parentMenu !== null)) || (self.autoOpen))) {
				self.doItemAction(item, false);
			}
		}
		return null;
	}
	, 1, [null,null,'self', 'item']);
	cls_definition.close = pyjs__bind_method(cls_instance, 'close', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool((self.parentMenu !== null))) {
			self.parentMenu.popup.hide();
		}
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.findItem = pyjs__bind_method(cls_instance, 'findItem', function(hItem) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			hItem = arguments[1];
		}
		var item;
		var __item = self.items.__iter__();
		try {
			while (true) {
				var item = __item.next();
				
				if (pyjslib.bool(pyjamas.ui.MenuBar.DOM.isOrHasChild(item.getElement(), hItem))) {
					return item;
				}
			}
		} catch (e) {
			if (e.__name__ != 'StopIteration') {
				throw e;
			}
		}
		return null;
	}
	, 1, [null,null,'self', 'hItem']);
	cls_definition.getItemContainerElement = pyjs__bind_method(cls_instance, 'getItemContainerElement', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool(self.vertical)) {
			return self.body;
		}
		else {
			return pyjamas.ui.MenuBar.DOM.getChild(self.body, 0);
		}
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.onHide = pyjs__bind_method(cls_instance, 'onHide', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool((self.shownChildMenu !== null))) {
			self.shownChildMenu.onHide();
			self.popup.hide();
		}
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.onShow = pyjs__bind_method(cls_instance, 'onShow', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool((pyjslib.cmp(pyjslib.len(self.items), 0) == 1))) {
			self.selectItem(self.items.__getitem__(0));
		}
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.selectItem = pyjs__bind_method(cls_instance, 'selectItem', function(item) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			item = arguments[1];
		}

		if (pyjslib.bool(pyjslib.eq(item, self.selectedItem))) {
			return null;
		}
		if (pyjslib.bool((self.selectedItem !== null))) {
			self.selectedItem.setSelectionStyle(false);
		}
		if (pyjslib.bool((item !== null))) {
			item.setSelectionStyle(true);
		}
		self.selectedItem = item;
		return null;
	}
	, 1, [null,null,'self', 'item']);
	return pyjs__class_function(cls_instance, cls_definition, 
	                            new Array(pyjamas.ui.MenuBar.Widget));
})();
return this;
}; /* end pyjamas.ui.MenuBar */
$pyjs.modules_hash['pyjamas.ui.MenuBar'] = $pyjs.loaded_modules['pyjamas.ui.MenuBar'];


 /* end module: pyjamas.ui.MenuBar */


/*
PYJS_DEPS: ['pyjamas.DOM', 'pyjamas', 'pyjamas.DeferredCommand.DeferredCommand', 'pyjamas.DeferredCommand', 'pyjamas.ui.Widget.Widget', 'pyjamas.ui', 'pyjamas.ui.Widget', 'pyjamas.ui.MenuItem.MenuItem', 'pyjamas.ui.MenuItem', 'pyjamas.ui.MenuBarPopupPanel.MenuBarPopupPanel', 'pyjamas.ui.MenuBarPopupPanel']
*/
