/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.fl.controls
{
import com.yahoo.astra.fl.containers.IRendererContainer;
import com.yahoo.astra.fl.controls.menuBarClasses.MenuButton;
import com.yahoo.astra.fl.controls.menuBarClasses.MenuButtonRow;
import com.yahoo.astra.fl.events.MenuButtonRowEvent;
import com.yahoo.astra.fl.events.MenuEvent;
import com.yahoo.astra.fl.utils.XMLUtil;
import fl.core.InvalidationType;
import fl.core.UIComponent;
import fl.data.DataProvider;
import fl.managers.IFocusManagerComponent;
import flash.events.FocusEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
//--------------------------------------
// Events
//--------------------------------------
/**
* Dispatched when the user clicks an item in the menu.
*
* @eventType com.yahoo.astra.fl.events.MenuEvent.ITEM_CLICK
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Event(name="itemClick", type="com.yahoo.astra.fl.events.MenuEvent")]
/**
* Dispatched when a menu is shown
*
* @eventType com.yahoo.astra.fl.events.MenuEvent.MENU_SHOW
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Event(name="menuShow", type="com.yahoo.astra.fl.events.MenuEvent")]
/**
* Dispatched when a menu is hidden.
*
* @eventType com.yahoo.astra.fl.events.MenuEvent.MENU_HIDE
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Event(name="menuHide", type="com.yahoo.astra.fl.events.MenuEvent")]
//--------------------------------------
// Styles
//--------------------------------------
/**
* The number of pixels the top level menu will appear to the right of MenuBar
* button. A negative value can be used to set the menu to the left of the
* MenuBar button. The default value is 5.
*
* @default 5
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="xOffset", type="Number")]
/**
* The number of pixels the top level menu will appear below the MenuBar button.
* A negative value can be used to have the menu overlap the MenuBar button. The
* default value is 5.
*
* @default 5
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="yOffset", type="Number")]
/**
* The number of pixels between the left edge of the menu and the left edge of
* the stage when the stage is too narrow to fit the menu. If the value were set
* to 0, the left edge of the menu would be flush with the left edge of the stage.
*
* @default 0
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="menuLeftMargin", type="Number")]
/**
* The number of pixels between the bottom of the menuBar and the top of the
* menu when the stage is to short to fit the menu. If the value were set to 0,
* the top of the menu would be flush with bottom edge of the menuBar.
*
* @default 0
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="menuTopMargin", type="Number")]
/**
* The number of pixels for a bottom gutter to a menu when the stage to short to
* fit the menu. If the value were set to 0, the bottom of the menu would be
* flush with the bottom edge of the stage.
*
* @default 0
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="menuBottomMargin", type="Number")]
/**
* The number of pixels between the right edge of the menu and the right edge of
* the stage when the stage is too narrow to fit the menu. If the value were set
* to 0, the right edge of the menu would be flush with the left edge of the
* stage.
*
* @default 0
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="menuRightMargin", type="Number")]
/**
* The number of pixels that each submenu will appear to right of its parent
* menu. A negative value can be used to have the menus overlap.
*
* @default -3
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="subMenuXOffset", type="Number")]
/**
* The number of pixels that each submenu will appear below the top of its parent
* menu. A negative value can be used to have the menu appear above its parent
* menu.
*
* @default 3
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
[Style(name="subMenuYOffset", type="Number")]
/**
* The MenuBar extends the UIComponent and manages a MenuButtonRow and corresponding
* instances of Menu.
*
* @see fl.core.UIComponent
* @see com.yahoo.astra.fl.controls.MenuButtonRow
* @see com.yahoo.astra.fl.controls.Menu
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
* @author Dwight Bridges
*/
public class MenuBar extends UIComponent implements IFocusManagerComponent
{
//--------------------------------------
// Constructor
//--------------------------------------
/**
* Constructor.
*/
public function MenuBar(value:Object = null)
{
super();
if(value != null) value.addChild(this);
tabEnabled = true;
_buttonRow = new MenuButtonRow(this);
_buttonRow.height = height;
_buttonRow.addEventListener(MenuButtonRowEvent.ITEM_DOWN, itemDownHandler, false, 0, true);
_buttonRow.addEventListener(MenuButtonRowEvent.ITEM_ROLL_OVER, itemRollOverHandler, false, 0, true);
_buttonRow.addEventListener(MenuButtonRowEvent.ITEM_UP, itemUpHandler, false, 0, true);
if(this.isLivePreview)
{
_buttonRow.dataProvider = new DataProvider(["No preview data available."]);
}
}
//--------------------------------------
// Properties
//--------------------------------------
/**
* @private
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
private static var defaultStyles:Object = {
xOffset:0,
yOffset:0,
menuLeftMargin:0,
menuTopMargin:0,
menuBottomMargin:0,
menuRightMargin:0,
subMenuXOffset:0,
subMenuYOffset:0,
focusRectSkin:null,
focusRectPadding:null,
menuBarBackground:"MenuBar_background"
}
/**
* @private (protected)
* @inheritDoc
*/
override protected function initializeAccessibility():void {
if (MenuBar.createAccessibilityImplementation != null) {
MenuBar.createAccessibilityImplementation(this);
}
}
/**
* @private
*/
private static const MENU_BUTTON_STYLES:Object =
{
embedFonts: "embedFonts",
disabledTextFormat: "disabledTextFormat",
textFormat: "textFormat",
textPadding: "textPadding"
};
private static var menuRendererStyles:Object = {};
private static var menuBarStyles:Object = {};
private static var menuBarRendererStyles:Object = {};
private var menuStyles:Object = {};
/**
* @private (protected)
*
* Instance of the MenuButtonRow. Contains a row of buttons that control the menu
* instances.
*/
public var _buttonRow:MenuButtonRow;
/**
* Gets the array of buttons
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get buttons():Array
{
return _buttonRow.buttons;
}
[Inspectable(defaultValue="false",type=Boolean)]
/**
* Indicates whether or not to close open menus when the mouse leaves the stage
* of the flash application. The default value is false.
*/
public var closeMenuOnMouseLeave:Boolean = false;
[Inspectable(defaultValue=true,type=Boolean)]
/**
* Indicates whether or not a menu link that spawns a child menu will be
* clickable. The default value is true.
*/
public var parentMenuClickable:Boolean = true;
/**
*
*/
public var selectedIndex:int = _buttonRow ? _buttonRow.selectedIndex : -1;
/**
* Creates the Accessibility class.
* This method is called from UIComponent.
*
*/
public static var createAccessibilityImplementation:Function;
/**
* @private
* Storage for the labelField property
*/
protected var _labelField:String="label";
[Inspectable(category="Data", defaultValue="label")]
/**
* Name of the field in the items in the dataProvider
* Array to display as the label in the Menu.
* By default, the control uses a property named label
* on each Array object and displays it.
*
However, if the dataProvider
items do not contain
* a label
property, you can set the labelField
* property to use a different property.
XMLDataProvider
:
* menubar.dataProvider = new XMLDataProvider(someXML);
*
* You can also use an array of objects in the following format:
*
*
* var dp:Array = [
* {
* label:"File",
* data:
* [
* { label:"File Menu item 1" },
* { label:"File Menu item 2" }
* ]
* },
* {
* label:"Edit",
* data:
* [
* { label:"Edit Menu item 1" },
* { label:"Edit Menu item 2" }
* ]
* }
* ];
*
* menubar.dataProvider = new DataProvider(dp);
*
*