OpendTect  7.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
MenuHandler Class Referenceabstract
Inheritance diagram for MenuHandler:
[legend]

Public Member Functions

virtual bool executeMenu ()=0
 
bool isHandled () const
 
int menuID () const
 
int queueID () const
 
void setIsHandled (bool)
 
void setMenuID (int newid)
 
- Public Member Functions inherited from MenuItemHolder
 MenuItemHolder ()
 
virtual ~MenuItemHolder ()
 
virtual void addItem (MenuItem *, bool manage=false)
 
MenuItemfindItem (const char *)
 Seaches for untranslated text. More...
 
const MenuItemfindItem (const char *) const
 Seaches for untranslated text. More...
 
MenuItemfindItem (int id)
 
const MenuItemfindItem (int id) const
 
MenuItemgetItem (int idx)
 
const MenuItemgetItem (int idx) const
 
const ObjectSet< MenuItem > & getItems () const
 
int itemIndex (const MenuItem *) const
 
int itemIndex (int id) const
 
int nrItems () const
 
void removeItems ()
 
- Public Member Functions inherited from CallBacker
 CallBacker ()
 
 CallBacker (const CallBacker &)
 
virtual ~CallBacker ()
 
bool attachCB (const NotifierAccess &, const CallBack &, bool onlyifnew=false) const
 
bool attachCB (const NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false) const
 
void detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
virtual bool isCapsule () const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
void stopReceivingNotifications () const
 
virtual CallBackertrueCaller ()
 
- Public Member Functions inherited from RefCount::Referenced
void addObserver (WeakPtrBase *obs)
 Not for normal use. May become private. More...
 
int nrRefs () const
 Only for expert use. More...
 
void ref () const
 
bool refIfReffed () const
 Don't use in production, for debugging. More...
 
void removeObserver (WeakPtrBase *obs)
 Not for normal use. May become private. More...
 
bool tryRef () const
 Not for normal use. May become private. More...
 
void unRef () const
 
void unRefNoDelete () const
 

Public Attributes

Notifier< MenuHandlercreatenotifier
 
CNotifier< MenuHandler, int > handlenotifier
 
Notifier< MenuHandlerinitnotifier
 
- Public Attributes inherited from MenuItemHolder
Notifier< MenuItemHolderremoval
 

Protected Member Functions

 MenuHandler (int id)
 
virtual ~MenuHandler ()
 
void assignItemID (MenuItem &) override
 
void executeQueue ()
 
- Protected Member Functions inherited from MenuItemHolder
void itemIsDeletedCB (CallBacker *)
 
- Protected Member Functions inherited from RefCount::Referenced
 Referenced ()
 
 Referenced (const Referenced &)
 
virtual ~Referenced ()
 
Referencedoperator= (const Referenced &)
 

Protected Attributes

int id_
 
bool ishandled_
 
int queueid_
 
- Protected Attributes inherited from MenuItemHolder
MenuItemHolderparent_
 

Additional Inherited Members

- Static Public Member Functions inherited from CallBacker
static void createReceiverForCurrentThread ()
 
static void removeReceiverForCurrentThread ()
 
- Static Public Member Functions inherited from RefCount::Referenced
static bool isSane (const Referenced *)
 

Detailed Description

A generic representation of a menu. It allows anyone to add their own custom menuitems to it. The principle is that the menu triggers it's createnotifier just before the menu should be displayed, and the application adds the items it wants into the menu. When the user has clicked on something in the menu, the handlenotifier is triggered and the application checks what should be done.

Usage:

\code
menu->createnotifier.notify( mCB(this,myclass,createMenuCB) );
menu->handlenotifier.notify( mCB(this,myclass,handleMenuCB) );
\endcode

Upon a create notification, your class might do something like this:
\code
void myclass::createMenuCB( CallBacker* callback )
{
    mDynamicCastGet( MenuHandler*, menu, callback );

    mAddMenuItem( menu, &mymenuitem, true, false );
    mAddMenuItem( menu, &mysubmenu, true, false );
    mAddMenuItem( &mysubmenu, &mysubmenuitem1, true, false );
    mAddMenuItem( &mysubmenu, &mysubmenuitem2, true, false );
}
\endcode

The code will make a menu with two items, and the second item will have a submenu with two items. The first boolean says whether the item should be enabled, the second one says where there should be a check before it.

The menuitems are instantiations of MenuItem and should be stored in your class. They hold information about the item itself (like text, enabled or not enabled, checked or not checked, information on where in the menu it should be placed. In addition, it has an unique id that is set when the item is inserted into the menu.

Upon a handle notification, your class might do something like this:
\code
void myclass::handleMenuCB(CallBacker* callback )
{
    mCBCapsuleUnpackWithCaller( int, mnuid, caller, callback );
    mDynamicCastGet( MenuHandler*, menu, caller );
    if ( mnuid==-1 || menu->isHandled() )
        return;

    bool ishandled = true;
    if ( mnuid==mymenuitem.id )
        do_something();
    else if ( mnuid==mysubmenuitem1.id )
        do_something_else();
    else if ( mnuid==mymenusubitem2.id )
        do_something_else();
    else
        ishandled = false;

    menu->setIsHandled(ishandled);
}
\endcode

<>

Constructor & Destructor Documentation

◆ MenuHandler()

MenuHandler::MenuHandler ( int  id)
protected

◆ ~MenuHandler()

virtual MenuHandler::~MenuHandler ( )
protectedvirtual

Member Function Documentation

◆ assignItemID()

void MenuHandler::assignItemID ( MenuItem )
overrideprotectedvirtual

Get a unique id for this item.

Reimplemented from MenuItemHolder.

◆ executeMenu()

virtual bool MenuHandler::executeMenu ( )
pure virtual

Implemented in uiTreeItemTBHandler, and uiMenuHandler.

◆ executeQueue()

void MenuHandler::executeQueue ( )
protected

◆ isHandled()

bool MenuHandler::isHandled ( ) const

Should be called as the first thing from callbacks that is triggered from uiMenuHandler::handlenotifier. If isHandled() returns true, the callback should return immediately.

◆ menuID()

int MenuHandler::menuID ( ) const
inline

◆ queueID()

int MenuHandler::queueID ( ) const
inline

After a menu is executed, it will execute a queue, identified by this id.

◆ setIsHandled()

void MenuHandler::setIsHandled ( bool  )

Should be called from callbacks that are triggered from uiMenuHandler::handlenotifier if they have found the menu id they are looking for.

◆ setMenuID()

void MenuHandler::setMenuID ( int  newid)
inline

Member Data Documentation

◆ createnotifier

Notifier<MenuHandler> MenuHandler::createnotifier

◆ handlenotifier

CNotifier<MenuHandler,int> MenuHandler::handlenotifier

◆ id_

int MenuHandler::id_
protected

◆ initnotifier

Notifier<MenuHandler> MenuHandler::initnotifier

◆ ishandled_

bool MenuHandler::ishandled_
protected

◆ queueid_

int MenuHandler::queueid_
protected

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2024