[Developers] {Spam?} Mouse event handling in OpendTect

Kristofer Tingdahl kristofer.tingdahl at dgb-group.com
Fri May 4 00:00:18 CEST 2007


Dear co-developers,

the new OpendTect 3.0 has a generalized way of handling mouse events 
that is more generalized compared to Opendtect 2.4. Objects that can 
detect mouse events (e.g. user interface classes) can give you a 
reference to a MouseEventHandler, which is the focal point for mouse events.

The MouseEventHandler is defined in include/General/mouseevent.h

If you write code that would want to be notified about mouse events, you 
have to get the MouseEventHandler from one of the ui-objects, and notify 
the MouseEventHandler that you want to know about the events:


class MyClass : public CallBacker
{
public:
            MyClass()
            {
               meh_ = getFromSomeUiClass();
               meh_->notify( mCB(this,MyClass,handleMouseEvent) );
            }
    void    handleMouseEvent(CallBacker*)
            {
                if ( eventhandler_->isHandled() )
                    return;

                const MouseEvent& event = meh_->event();
                if ( event.rightButton() && !event.leftButton() &&
                     !event.middleButton() && !event.ctrlStatus() &&
                     !event.altStatus() && !event.shiftStatus() )
                {
                    meh_->setHandled( true );
                    //show and handle dialog
                }
            }
protected:
    MouseEventHandler meh_;
};

Once the event callback is received, it MUST check if someone else have 
handled the event and taken necessary actions (the isHandled call). If 
it is not already handled, and your class handles it, it should set the 
isHandled flag to prevent other objects in the callback chain to handle 
the event. It is often a good idea to be very specific what events your 
function should handle to avoid interference with other objects that are 
in the callback chain. In the example, above: The if-statement will only 
let right-clicks when no other mouse or keyboard button are pressed through.

Finally, the mouse-handling in the visualization is slightly different, 
and that is defined in include/visBase/visevent.h

Happy programming,

Kristofer

-- 
Dr. Kristofer Tingdahl
dGB Earth Sciences
1 Sugar Creek Center BLVD #935; Sugar Land, TX 77478; USA
+1 281 652 5318





More information about the Developers mailing list