contextMenu

contextMenu(conwin:  Window input;        (Form)
            mouse:   Boolean;
            x:       Integer;
            y:       Integer): Boolean;

contextMenu(control: control-type input;  (Control)
            conwin:  Window input;
            mouse:   Boolean;
            x:       Integer;
            y:       Integer): Boolean;

The contextMenu event occurs after the right mouseUp event and after the keyUp event.

If the control or form does not implement the event, the default processing continues.

This event returns true if processing is to continue or it returns false to terminate further processing.

For the JadeRichText control, the contextMenu event occurs after the right mouse click or a Shift+F10 key combination if the contextMenuOptions property has a value of MenuOption_Custom. If the control does not implement the event, no action is taken and the context menu is not displayed. This event returns true if the JadeRichText control displays its built-in menu or it returns false if it displays the custom popup menu.

The contextMenu event parameters are listed in the following table.

Parameter Description
control Control for which the event is being called
conwin The window being right-clicked or the control with the focus when the keyboard generates the event
mouse Contains true if the mouse generated the event or false if the keyboard generated it
x Client left position in pixels of the window specified by the conwin parameter for the mouse click, or unused if mouse is false
y Client top position in pixels of the window specified by the conwin parameter for the mouse click, or unused if mouse is false

The contextMenu event is called when the right mouse button is clicked over the window or when a control has focus and the accelerator menu key or the Shift+F10 shortcut keys of the application are pressed. You would most often implement this event to display a popup menu when the user performs that action, or you could implement it to suppress an existing automatically displayed popup menu (for example, that which occurs for a text box control).

For a JadeRichText or JadeTextEdit control, you would most often implement this event to display a popup menu when the user performs that action, or you could implement it to suppress the automatic display of the built-in context menu in a rich text control and display the custom menu instead.

The contextMenu event is also called for each parent of the window unless a previous child window in the parent-child chain terminated that process by returning a value of false from the event method. The contextMenu event has no impact on existing events and occurs in addition to the normal mouse and keyboard events.

Displaying a form, popup menu, or changing focus during mouse or keyboard events results in contextMenu events not being sent.

If you want to suppress the default context menu, you must implement the contextMenu event for the text box, and it should return false. This also means that the event is not called on any of its parents.

The method in the following example shows the use of the contextMenu event, positioning the popup menu on the currently selected list entry when the keyboard is used.

listBox1_contextMenu(control: Control;
                     conwin:  Window;
                     mouse:   Boolean;
                     x, y:    Integer): Boolean updating;
vars
    x1 : Real;
    y1 : Real;
begin
    x1 := x;
    y1 := y;
    if not mouse then  // if keyboard, use current listIndex value
        x1 := 20;
        if listBox1.listIndex < 0 then
            y1 := 5;
        else
            y1 := listBox1.positionTop(listBox1.listIndex);
        endif;
    endif;
    listBox1.windowToScreen(x1, y1);
    self.screenToWindow(x1, y1);   // convert x, y relative to form
    self.popupMenu(menuOptions, x1.Integer, y1.Integer);
    return false;                  // cancel further processing
end;