OpendTect-6_4  6.4
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
MenuHandler Class Referenceabstract
Inheritance diagram for MenuHandler:
[legend]

Public Member Functions

 MenuHandler (int id)
 
virtual bool executeMenu ()=0
 
int menuID () const
 
void setMenuID (int newid)
 
bool isHandled () const
 
void setIsHandled (bool)
 
int queueID () const
 
- Public Member Functions inherited from MenuItemHolder
 MenuItemHolder ()
 
virtual ~MenuItemHolder ()
 
virtual void addItem (MenuItem *, bool manage=false)
 
void removeItems ()
 
int nrItems () const
 
const MenuItemgetItem (int idx) const
 
MenuItemgetItem (int idx)
 
int itemIndex (const MenuItem *) const
 
int itemIndex (int id) const
 
MenuItemfindItem (int id)
 
const MenuItemfindItem (int id) const
 
MenuItemfindItem (const char *)
 Seaches for untranslated text. More...
 
const MenuItemfindItem (const char *) const
 Seaches for untranslated text. More...
 
const ObjectSet< MenuItem > & getItems () const
 
- Public Member Functions inherited from CallBacker
 CallBacker ()
 
 CallBacker (const CallBacker &)
 
virtual ~CallBacker ()
 
bool attachCB (NotifierAccess &, const CallBack &, bool onlyifnew=false)
 
bool attachCB (NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false)
 
void detachCB (NotifierAccess &, const CallBack &)
 
void detachCB (NotifierAccess *notif, const CallBack &cb)
 
bool isNotifierAttached (NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 

Public Attributes

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

Protected Member Functions

void assignItemID (MenuItem &)
 
void executeQueue ()
 
- Protected Member Functions inherited from MenuItemHolder
void itemIsDeletedCB (CallBacker *)
 
- Protected Member Functions inherited from CallBacker
void detachAllNotifiers ()
 Call from the destructor of your inherited object. More...
 

Protected Attributes

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

Private Member Functions

 mRefCountImpl (MenuHandler)
 

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:

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

Upon a create notification, your class might do something like this:

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 );
}

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:
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);
}

Constructor & Destructor Documentation

MenuHandler::MenuHandler ( int  id)

Member Function Documentation

void MenuHandler::assignItemID ( MenuItem )
protectedvirtual

Get a unique id for this item.

Reimplemented from MenuItemHolder.

virtual bool MenuHandler::executeMenu ( )
pure virtual

Implemented in uiTreeItemTBHandler, and uiMenuHandler.

void MenuHandler::executeQueue ( )
protected
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.

int MenuHandler::menuID ( ) const
inline
MenuHandler::mRefCountImpl ( MenuHandler  )
private
int MenuHandler::queueID ( ) const
inline

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

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.

void MenuHandler::setMenuID ( int  newid)
inline

Member Data Documentation

Notifier<MenuHandler> MenuHandler::createnotifier
CNotifier<MenuHandler,int> MenuHandler::handlenotifier
int MenuHandler::id_
protected
Notifier<MenuHandler> MenuHandler::initnotifier
bool MenuHandler::ishandled_
protected
int MenuHandler::queueid_
protected

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