10.7 local menu

Source: Internet
Author: User

Local menu

Native menu API provides related classes for creating programs, windows, context menus, and pop-up menus.

Air menu Overview

The native menu class program accesses the local menu features of the operating system. The nativemenu object is used to create Application menus (available in The OSX system), window menus (available in the Windows system), context menus, and pop-up menus.

Menu type

 

Air supports the following menu types:

Application menu

The Application menu must be accessed through the shell class. on Mac OS X, the application menu is automatically provided by the operating system. The application uses these air menu APIs to add menu items and sub-menus to the standard menu and register the processing functions. Of course, you can also completely replace the standard menu.

Form menu

Create an nativemenu object and assign it to the nativewindow. Menu attribute to add a form menu. Windows supports the form menu, but Mac OS X is not.

Context Menu

The context menu is added to the interaction object and document element of the htmlcontrol component. The most typical example is to use WebKit APIs on HTML elements. Of course, you can also directly use context menus on htmlcontrol.

System Tray menu

Create a system tray menu by creating an nativemenu object and assigning it to shell. Shell. Icon. menu.

Flex menu

The flex framework provides a set of flex menu classes. These flex menu classes can be used without the need for the form to inherit the system form style and can also be declared in the mxml format. If you use the flex framework, you can use the flex menu class to replace the local menu class.

Custom menu

The local menu is drawn by the operating system outside the flash and HTML rendering models. Of course, you can also draw your own non-local menu, unfortunately, currently, the air menu class does not support "self-drawn" menus.

Menu structure

 

A menu contains one or more menu items. A menu item can be a command, a sub menu, or a separator. Generally, a menu item is a command, if the submenu attribute of a menu item is assigned a nativemenu object, it becomes a sub menu. If the isseparator parameter of the menu item constructor is true, it becomes a separator.

The top menu items are displayed on the menu bar, and other sub-menus are added to the top menu of the application and form menu (although some operating systems can directly place menu items on the menu bar, this seems to be out of the regular format ).

The following icons demonstrate the typical menu structure. The root menu contains the sub-Menus "file" and "edit ". The "file" menu contains two commands and a sub-menu (used to display the most recently opened document. It is also a sub-menu and contains three menu items ). The "edit" menu contains three commands and a separator.

 

Menu events

 

Both menus and menu items can issue displaying and select events:

Displaying:

Before the menu is displayed, the menu and its sub-menus will send a displaying event to notify them of the registered listener. The displaying event gives you a chance to update the menu content or menu item status. For example, the displaying processing function of the "open recent" menu item can change the menu item of the document that has been read.

The target attribute of the event object points to the displayed menu. currenttarget is the object listened to by the registered listener. It can be either the menu or its menu item.

Select:

When a user clicks a command item, the command item sends a select event to the registered listener. However, the sub-menu and separator cannot be selected or the select event is not sent.

The Select event of a menu item is always passed up to the top menu, so you can directly listen on the menu item or the top menu structure. When listening to select events, you must use the target attribute of the event to determine which menu item triggers the event, and the currenttarget attribute can determine the current menu object.

Shortcut Key

 

Shortcut Keys are part of the operating system keyboard function on the menu. Both Mac OS X and Windows allow users to open or select a menu command item on the keyboard.

Use the index of the string to specify the shortcut character. The index value of the first letter of the string is "0 ". In this way, if the "r" letter of the "format" string is used as a shortcut character, set its index value mnemonicindex to 2.

VaR item: nativemenuitem = new nativemenuitem ("format ");

Item. mnemonicindex = 2;

Menu item status

 

The menu item has two State attributes: checked and enabled:

Checked

If it is set to true, a flag is added before the character of the menu item.

VaR item: nativemenuitem = new nativemenuitem ("format ");

Item. Checked = true;

 

Enabled

Set whether menu items are available

VaR item: nativemenuitem = new nativemenuitem ("format ");

Item. Enabled = false;

 

Associate objects with menu items

 

The data attribute of the nativemenuitem class can be associated with any type of objects. For example, in the "open recent" menu, you can assign a file object to the menu item:

Var file: file = new file ("app-storage:/greatgatsby.pdf ");

VaR menuitem: nativemenuitem = docmenu. additem (New nativemenuitem (file. Name ));

Menuitem. Data = file;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.