feature is currently implemented in the runtime by having the users
basically directly the calling of the Flash ContextMenu API. It would
be better to have a slightly more modular API which could also be
portable other runtimes. This proposal calls for a new API which adds
two new runtime classes, LzContextMenu, and LzContextMenuItem.
The major design issue is how to get callbacks; this design proposes
two mechanisms: the menu-item class and the menu class itself will get
"onselect" events when they are selected, and the API also supports,
as a convenience, passing an LzDelegate object to a menu or menu item
which will get installed, and is executed when the menu or menu-item
is selected.
An example usage looks like this:
<view width="100" height="100" bgcolor="#cccccc" name="v1">
<method event="oninit">
var cm = new LzContextMenu();
// Set up a LzDelegate as a callback
var item1 = cm.makeMenuItem('Item1', new LzDelegate(this, "handlerightclick"));
cm.addItem(item1);
var item3 = cm.makeMenuItem('Item3', new LzDelegate(this, "handlerightclick"));
item3.setEnabled(false);
cm.addItem(item3);
var item4 = cm.makeMenuItem('Item4', new LzDelegate(this, "handlerightclick"));
item4.setSeparatorBefore(true);
cm.addItem(item4);
var item5 = cm.makeMenuItem('Show Dialog', new LzDelegate(this, "handlerightclick"));
cm.addItem(item5);
// Menu items generate a "onselect" when they are selected
new LzDelegate(this, "showdialog", item5, "onselect");
this.setContextMenu(cm);
// "onselect" event is to a LzContextMenu soon as the menu gets a mousedown on the right button.
// This gives you a chance to (quickly) rearrange the menu on the fly.
new LzDelegate(this, "menuselected", cm, "onselect");
// "onselect" event is sent to an LzContextMenuItem when it is selected from the menu
new LzDelegate(this, "menuitemselected", item1, "onselect");
Debug.write(cm);
</method>
<method name="menuselected" args="val">
Debug.write("A right click on the menu was detected, val= ", val);
</method>
<method name="menuitemselected" args="val">
Debug.write("A right click on an item was detected, val= ", val);
</method>
<method name="handlerightclick" args="val">
Debug.write("handle item handlerightclick, val=", val);
</method>
<method name="showdialog">
md.open();
</method>
</view>
The API looks like this:
//-----------------------------------------------------------------------------
// LzContextMenu.setCaption
//
// Sets the text string which is displayed for the menu item
// @param String caption: text string to display
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenuItem.setCaption = function (caption) {
//-----------------------------------------------------------------------------
// LzContextMenu.setEnabled
//
// @param boolean val: if false, menu item is grayed out and will not respond to clicks
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenuItem.setEnabled = function (val) {
//-----------------------------------------------------------------------------
// LzContextMenu.setVisible
//
// Sets the function which will be called when the menu item is selected
// @param boolean val: sets visibility
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenuItem.setSeparatorBefore = function (val) {
//-----------------------------------------------------------------------------
// LzContextMenu.setVisible
//
// Sets the function which will be called when the menu item is selected
// @param boolean val: sets visibility
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenuItem.setVisible = function (val) {
//-----------------------------------------------------------------------------
// LzContextMenu.setDelegate
//
// Sets the delegate which will be called when the menu item is selected
// @param LzDelegate delegate: delegate which is executed when item is selected. An
// onselect event is also sent.
//
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenuItem.setDelegate = function (delegate) {
//-----------------------------------------------------------------------------
// LzContextMenu.makeMenuItem
//
// create a new menu item for a LzContextMenu
// @param String title: menu item name
// @param LzDelegate callback: delegate to execute when item is selected
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenu.makeMenuItem = function (title, callback) {
//-----------------------------------------------------------------------------
// LzContextMenu.addItem
//
// Adds a menu items into a menu
// @param LzContextMenuItem item: LzContextMenuItem to install on this menu
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenu.addItem = function (item) {
//-----------------------------------------------------------------------------
// LzContextMenu.hideBuiltInItems
//
// Removes Flash-installed default menu items
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenu.hideBuiltInItems = function () {
//-----------------------------------------------------------------------------
// LzContextMenu.clearItems
//
// Remove all custom items from a menu
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenu.clearItems = function () {
//-----------------------------------------------------------------------------
// LzContextMenu.getItems
//
// Return list of custom items
// @keywords public
//-----------------------------------------------------------------------------
LzContextMenu.getItems = function () {
--
Henry Minsky
Software Architect
[EMAIL PROTECTED]
_______________________________________________ Laszlo-user mailing list [email protected] http://www.openlaszlo.org/mailman/listinfo/laszlo-user
