5. Overview Menus

  Overview Menus
MenuCreatePopup MenuCreatePopup creates a popup menu.
MenuDisplayContextMenu MenuDisplayContextMenu
MenuGetMap MenuGetMap
MenuGetPopup MenuGetPopup returns the function names of a pop-up menu.
MenuInsertCommands MenuInsertCommands inserts a new menu item to a pop-up menu.
MnAppend MnAppend appends an empty menu to the main menu, or appends a new menu item to a pop-up menu.
MnDrawMenuBar MnDrawMenuBar redraws the menu bar.
MnGetNewCommandID MnGetNewCommandID returns a new identification number for a menu item.
MnGetStrings MnGetStrings returns the menu item strings of the specified menu.
MnInsert MnInsert inserts a new item into a menu.
MnInsertPopup MnInsertPopup inserts a new popup menu into a menu.
MnRemove MnRemove removes a menu item or a complete menu.
MnSetChecked MnSetChecked checks or unchecks a menu item.
MnSetCommand MnSetCommand assigns a UniScript command to a menu item.
OnCommand OnCommand is used here as a placeholder for a function that is called when a user clicks a button on the user toolbar or selects the function from a menu.
OnCommandUI OnCommandUI is used here as a placeholder for a function that is called when a user clicks a button on the user toolbar or selects a function from a menu.
RegisterCommand RegisterCommand adds a new command to the command table for the User Toolbar. The registered commands can be added to the ToolBar using the command Tools=>Customize User Toolbar.

5.1. The Main Menus

UniPlot has menus for each window type. The menus have the following names:

Value Meaning
“Editor” This menu is displayed when the text editor is active.
“Document” This menu is displayed when a document page is active .ipw.
“DocumentServer” This menu is displayed when a document page is active in a different application (OLE 1) .ipw.
“Command” This menu is displayed when the command window is active.
“Main” This menu is displayed when UniPlot does not show an active window.

New menu items can be inserted with the help of the functions MnInsert, MnAppend and MnSetCommand. These functions are normally invoked during startup. Most of the standard menu items are added in the file do_cmds.ic.

Example

A simple example:

nID = MnGetNewCommandID();
MnInsert("Document", 1, 7, nID, "My Import");
MnDrawMenuBar();
MnSetCommand(nID, "DoMyImport()");

MnInsert inserts a new item into a menu. In the example the string "My Import" will be added to the “Document” menu. The three numbers have the following meaning: The first number is the index of the main menu element. The index 1 means the first menu, in this case it is the File menu. The 7 means the item is added after the 7th element. The number nID is the index in the UniPlot/UniScript command table. To create a unique index you should use the MnGetNewCommandID function.

MnDrawMenuBar will replot the active menu.

MnSetCommand assigns a UniScript command to a menu item.

5.3. OnCommandUI

Menu items can be removed or disabled by specifying a function to update the menu item. See OnCommandUI.

5.4. Context Menus (shortcut menu)

Beginning with UniPlot 3.05 objects can have menus. To open a context menu, right click on an object. Context menus can contain popup menus.

Example

Example: Add Menu item to the text object context menu:

MenuInsertCommands("OBJ_TB", [""; "MyLegendFunc"], 32000);
MnSetCommand("MyLegendFunc", "Legende...");

Example: Add pop-up menu to the text object context menu.

MenuCreatePopup("OBJ_TB-Legend", [..
    "_Test1";
    "_Test2"]);
MenuInsertCommands("OBJ_TB", [""; "OBJ_TB-Legend@Legende"], 32000);
MnSetCommand("_Test1", "Legende1...");
MnSetCommand("_Test2", "Legende2...");

Example: Adds a pop-up menu “Translate” to the layer object context menu. Save the following script in an ic file in the UniPlot autoload folder:

def _popup_InitTranslateMenu()
{
    global g_bTranslateMenuInit;
    if (g_bTranslateMenuInit) {
        return;
    }
    g_bTranslateMenuInit = 1;
    MenuCreatePopup("OBJ_LAYER-Translate", [..
        "OnTranslateEnglish";
        "OnTranslateGerman";
        "OnTranslateSpanish"]);
    MenuInsertCommands("OBJ_LAYER", [""; "OBJ_LAYER-Translate@Translate"], 32000);
    MnSetCommand("OnTranslateEnglish", "English...");
    MnSetCommand("OnTranslateGerman", "German...");
    MnSetCommand("OnTranslateSpanish", "Spanish...");
}
_popup_InitTranslateMenu()
def OnTranslateEnglish()
{
    hPage = AppGetActivePage();
    if (hPage == 0) {
        return 0;
    }
    hvLayer = PageGetAllLayers(hPage)
    if (hvLayer[1] == 0) {
        return 0;
    }
    // etc..
    MessageBox("english");
}
def OnTranslateGerman()
{
    MessageBox("german");
}
def OnTranslateSpanish()
{
    MessageBox("spanish");
}

id-1362113