Skip to content

Class: cCJContextMenu

Properties | Events | Methods | Index of Classes

Used to create context menu for a commandbar system

Hierarchy

cObject > DfComAutomationObject > cComAutomationObject > cCJCommandBar > cCJContextMenu

Show full hierarchy and direct subclasses

Library: Windows Application Class Library

Package: cCJCommandBarSystem.pkg

Description

The cCJContextMenu class is used to create context menus. Context menus are the menus made available by right clicking on a visual control.

Context menus are normally not placed inside the cCJCommandBarSystem object. They are usually located insides or near the object that uses it or at the desktop level so all objects can use it. However, it is required to have at least one cCJCommandBarSystem object in a program that uses a cCJContextMenu.

Object oEditContextMenu is a cCJContextMenu

    Object oUndoMenuItem is a cCJUndoMenuItem
    End_Object

    Object oCutMenuItem is a cCJCutMenuItem
        Set pbControlBeginGroup to True
    End_Object

    Object oCopyMenuItem is a cCJCopyMenuItem
    End_Object

    Object oPasteMenuItem is a cCJPasteMenuItem
    End_Object

    Object oDeleteItem is a cCJDeleteEditMenuItem
    End_Object

    Object oSelectAllMenuItem is a cCJSelectAllMenuItem
        Set pbControlBeginGroup to True
    End_Object
End_Object
Col 1 Col 2
Note: For an overview on the commandbar system, refer to Using Menus, Toolbars and Statusbars

Context menus must be able to figure out what commandbar system they belong to. By default, a context menu will assume it belongs to the main MDI commandbar system. This can be overridden by setting the phoCommandBars property.

A context menu is invoked by sending it the Popup message. There is a standard interface built into most of the classes for invoking context menus. If the Floating_Menu_object property is non-zero, the right mouse event Mouse_Down2 is augmented to send the popup message to the object handle stored in that property. Therefore setting Floating_Menu_object to your context menu is all that is needed to bind a context menu to a control.

Object oSpecialContextMenu is a cCJContextMenu

    Object oCutMenuItem is a cCJCutMenuItem
    End_Object

    Object oCopyMenuItem is a cCJCopyMenuItem
    End_Object

    Object oPasteMenuItem is a cCJPasteMenuItem
        Set pbControlBeginGroup to True
    End_Object

    Object oDeleteItem is a cCJDeleteEditMenuItem
        Set pbControlBeginGroup to True
    End_Object

End_Object

Object oForm is a Form
    Set Floating_Menu_Object to oSpecialContextMenu
    :
End_Object

The Default Context Menus

Two global context menus should be included at the desktop in most projects by including the packages oEditContextMenu.pkg and oDEOEditContextMenu.pkg. These create two context menus, a standard-control context menu and a data entry (DEO) control context menu. The standard-control menu is assigned to the Default_Form_Floating_Menu_ID global variable, which makes it default context menu for non-data aware forms (Form, Grid, etc.). The DEO-control context menu is assigned to the Default_dbFloating_Menu_ID global variable, which makes it the default context menu for data aware forms (dbForm, dbGrid, etc.). These standard context menus are made available as follows:

Object oApplication is a cApplication
    Set peHelpType to htHtmlHelp
End_Object  // oApplication

Use oEditContextMenu.pkg
Use oDEOEditContextMenu.pkg

Object oMain is a Panel
    :
End_Object

The Context Menu Creation Process

When a context menu is invoked, the message Popup is sent to the context menu. This sends the message CreatePopupComInstance, which is the message that creates the all of the COM popup menu objects. CreatePopupComInstance does the following:

  1. Creates the COM context menu.
  2. Sets the appropriate COM messages.
  3. Sends the OnCreate event. This can be used by developers to customize the creation process.
  4. Creates all child menu objects by sending CreateComInstance to all child objects.
  5. Makes sure that all child menu items are properly enabled, checked and visible.
  6. Sends the OnPopupInit event allowing for further developer customization.

When complete, the COM objects are all created. The Popup method will now display the menu. When the menu is closed, the COM objects will all be destroyed.

See Also

cCJCommandBarSystem | cCJMenuItem