Context menus are not supported within SAPGUI for HTML.
Use
The context menu (right-hand mouse button or
SHIFT+F10 ) allows you to display a context-sensitive menu. The context is defined by the position of the mouse pointer when the user requests the menu.A context menu allows the user to choose functions that are relevant to the current context.
Features
If you want to provide a context menu in a custom control, you must register the event that is triggered when the user clicks the right mouse button (
context_menu ). The event triggered when the user chooses an entry from the context menu ( context_menu_selected ) is either registered directly by the control wrapper (for example, SAP Tree), or must be registered explicitly (SAP Picture).If the user requests a context menu for an object, the application program is called using the normal
event mechanism. In the event handler method for the context_menu event, the program receives a menu reference as an event parameter. The program uses the menu reference to construct the required menu. You can either predefine a context menu using the Menu Painter, or construct one dynamically in your program. The context menu is displayed automatically after the event handler method.The above description does not apply to the SAP Picture. In the SAP Picture, the menu reference is not passed as an event parameter.
When the user chooses an entry from the context menu, a further event is triggered, which is passed to the application program. Accordingly, you must register a further handler method for this event. Use the handler method to analyze the function code. This is passed to the method as an event parameter.
Activities
The SAP Tree is an exception in terms of registering events. In the SAP Tree, you only have to register the event
Constructing a Context Menu
When you implement the handler method for the event
context_menu , you must assign the menu to the control. You may need to check the particular context in which the user requested the context menu.You construct the context menu using class
CL_CTMENU . Almost all control wrappers pass a context menu object reference as an event parameter of the context_menu event. If this is not the case (for example, SAP Picture), you must create an object of the class CL_CTMENU .You can use the following methods with the context menu object:
Method |
Description |
LOAD_GUI_STATUS |
Loads a context menu that you have already defined in the Menu Painter (see below) |
ADD_FUNCTION |
Adds a function |
ADD_MENU |
Adds a menu that you defined in the Menu Painter |
ADD_SUBMENU |
Adds a menu that you defined in the Menu Painter as a submenu |
ADD_SEPARATOR |
Adds a separator |
RESET |
Reset to initial value |
HIDE FUNCTIONS |
Hides a function |
SHOW_FUNCTIONS |
Shows a function |
DISABLE_FUNCTIONS |
Inactivates a function |
ENABLE_FUNCTIONS |
Activates a function |
The context menu is displayed automatically after the event handler method. The SAP Picture Control and SAP Toolbar Control are an exception to this. With these controls, you must display the context menu explicitly using the method
display_context_menu.Evaluating the Function Code
You interpret the user's choice from the context menu in the handler method for the event
context_menu_selected . You can identify and react to this choice using the function code.