diff --git a/code/nel/include/nel/gui/ctrl_base.h b/code/nel/include/nel/gui/ctrl_base.h index fe8d5ea60..28eeb2cd0 100644 --- a/code/nel/include/nel/gui/ctrl_base.h +++ b/code/nel/include/nel/gui/ctrl_base.h @@ -68,9 +68,7 @@ namespace NLGUI // special parse virtual bool parse(xmlNodePtr cur, CInterfaceGroup *parentGroup); - - /// Handle all events (implemented by derived classes) (return true to signal event handled) - virtual bool handleEvent (const NLGUI::CEventDescriptor &event); + bool handleEvent (const NLGUI::CEventDescriptor &event); virtual CCtrlBase *getSubCtrl (sint32 /* x */, sint32 /* y */) { return this; } diff --git a/code/nel/include/nel/gui/interface_element.h b/code/nel/include/nel/gui/interface_element.h index 210c24b2e..570dbf689 100644 --- a/code/nel/include/nel/gui/interface_element.h +++ b/code/nel/include/nel/gui/interface_element.h @@ -473,6 +473,7 @@ namespace NLGUI bool isInGroup( CInterfaceGroup *group ); static void setEditorMode( bool b ){ editorMode = b; } + static bool getEditorMode(){ return editorMode; } void setEditorSelected( bool b ){ editorSelected = b; } bool isEditorSelected() const{ return editorSelected; } diff --git a/code/nel/include/nel/gui/view_base.h b/code/nel/include/nel/gui/view_base.h index b7d2aceab..f64803720 100644 --- a/code/nel/include/nel/gui/view_base.h +++ b/code/nel/include/nel/gui/view_base.h @@ -25,6 +25,7 @@ namespace NLGUI { + class CEventDescriptor; class CViewBase : public CInterfaceElement { @@ -76,6 +77,9 @@ namespace NLGUI // special for mouse over : return true and fill the name of the cursor to display virtual bool getMouseOverShape(std::string &/* texName */, uint8 &/* rot */, NLMISC::CRGBA &/* col */) { return false; } + + /// Handle all events (implemented by derived classes) (return true to signal event handled) + virtual bool handleEvent (const NLGUI::CEventDescriptor &evnt); }; diff --git a/code/nel/include/nel/gui/view_text.h b/code/nel/include/nel/gui/view_text.h index df3cf27e3..fa9e184b7 100644 --- a/code/nel/include/nel/gui/view_text.h +++ b/code/nel/include/nel/gui/view_text.h @@ -188,6 +188,8 @@ namespace NLGUI int luaSetLineMaxW(CLuaState &ls); + bool handleEvent( const NLGUI::CEventDescriptor &evnt ); + REFLECT_EXPORT_START(CViewText, CViewBase) REFLECT_STRING("hardtext", getHardText, setHardText); REFLECT_UCSTRING("uc_hardtext", getText, setText); diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 7fedc6240..5700a52e6 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -341,6 +341,7 @@ namespace NLGUI /** * Capture */ + CViewBase *getCapturedView(){ return _CapturedView; } CCtrlBase *getCapturePointerLeft() { return _CapturePointerLeft; } CCtrlBase *getCapturePointerRight() { return _CapturePointerRight; } CCtrlBase *getCaptureKeyboard() { return _CaptureKeyboard; } @@ -510,6 +511,8 @@ namespace NLGUI NLMISC::CRefPtr _CapturePointerLeft; NLMISC::CRefPtr _CapturePointerRight; + NLMISC::CRefPtr< CViewBase > _CapturedView; + // What is under pointer std::vector< CViewBase* > _ViewsUnderPointer; std::vector< CCtrlBase* > _CtrlsUnderPointer; diff --git a/code/nel/src/gui/ctrl_base.cpp b/code/nel/src/gui/ctrl_base.cpp index 8cd51f026..c2f467736 100644 --- a/code/nel/src/gui/ctrl_base.cpp +++ b/code/nel/src/gui/ctrl_base.cpp @@ -37,6 +37,9 @@ namespace NLGUI // *************************************************************************** bool CCtrlBase::handleEvent(const NLGUI::CEventDescriptor &event) { + if( CViewBase::handleEvent( event ) ) + return true; + if (event.getType() == NLGUI::CEventDescriptor::system) { NLGUI::CEventDescriptorSystem &eds = (NLGUI::CEventDescriptorSystem&)event; diff --git a/code/nel/src/gui/ctrl_base_button.cpp b/code/nel/src/gui/ctrl_base_button.cpp index 4c892ecc7..16b2a3ad4 100644 --- a/code/nel/src/gui/ctrl_base_button.cpp +++ b/code/nel/src/gui/ctrl_base_button.cpp @@ -668,12 +668,6 @@ namespace NLGUI if (CWidgetManager::getInstance()->getCapturePointerLeft() != this) return false; - if( editorMode ) - { - CWidgetManager::getInstance()->setCurrentEditorSelection( getId() ); - return true; - } - if (_LeftDblClickHandled) // no effect on mouse up after double click has been handled { _LeftDblClickHandled = false; diff --git a/code/nel/src/gui/view_base.cpp b/code/nel/src/gui/view_base.cpp index cf1e01ede..ebe18b979 100644 --- a/code/nel/src/gui/view_base.cpp +++ b/code/nel/src/gui/view_base.cpp @@ -45,5 +45,23 @@ namespace NLGUI CInterfaceElement::visit(visitor); } + + bool CViewBase::handleEvent( const NLGUI::CEventDescriptor &evnt ) + { + if( evnt.getType() == NLGUI::CEventDescriptor::mouse ) + { + const NLGUI::CEventDescriptorMouse &eventDesc = ( const NLGUI::CEventDescriptorMouse& )evnt; + if( eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown ) + { + if( editorMode ) + { + CWidgetManager::getInstance()->setCurrentEditorSelection( getId() ); + return true; + } + } + } + return false; + } + } diff --git a/code/nel/src/gui/view_text.cpp b/code/nel/src/gui/view_text.cpp index 85e76a09c..b9d58ae45 100644 --- a/code/nel/src/gui/view_text.cpp +++ b/code/nel/src/gui/view_text.cpp @@ -2945,6 +2945,11 @@ namespace NLGUI } } + bool CViewText::handleEvent( const NLGUI::CEventDescriptor &evnt ) + { + return false; + } + // *************************************************************************** void CViewText::serial(NLMISC::IStream &f) { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index b12ddff3c..c923c40fe 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -1031,6 +1031,7 @@ namespace NLGUI _OldCaptureKeyboard = NULL; setCapturePointerLeft(NULL); setCapturePointerRight(NULL); + _CapturedView = NULL; resetColorProps(); @@ -2086,6 +2087,12 @@ namespace NLGUI getCapturePointerRight()->handleEvent( evnt ); setCapturePointerRight( NULL ); } + + if( _CapturedView != NULL ) + { + _CapturedView->handleEvent( evnt ); + _CapturedView = NULL; + } } } @@ -2249,6 +2256,9 @@ namespace NLGUI getCapturePointerLeft() != getCapturePointerRight() ) handled|= getCapturePointerRight()->handleEvent(evnt); + if( _CapturedView != NULL ) + _CapturedView->handleEvent( evnt ); + CInterfaceGroup *ptr = getWindowUnder (eventDesc.getX(), eventDesc.getY()); setCurrentWindowUnder( ptr ); @@ -2326,6 +2336,8 @@ namespace NLGUI } } + bool captured = false; + // must not capture a new element if a sheet is currentlty being dragged. // This may happen when alt-tab has been used => the sheet is dragged but the left button is up if (!CCtrlDraggable::getDraggedSheet()) @@ -2343,9 +2355,25 @@ namespace NLGUI { nMaxDepth = d; setCapturePointerLeft( ctrl ); + captured = true; + } + } + } + + if( CInterfaceElement::getEditorMode() && !captured ) + { + for( sint32 i = _ViewsUnderPointer.size()-1; i >= 0; i-- ) + { + CViewBase *v = _ViewsUnderPointer[i]; + if( ( v != NULL ) && v->isInGroup( pNewCurrentWnd ) ) + { + _CapturedView = v; + captured = true; + break; } } } + notifyElementCaptured( getCapturePointerLeft() ); if (clickedOutModalWindow && !clickedOutModalWindow->OnPostClickOut.empty()) { @@ -2353,13 +2381,16 @@ namespace NLGUI } } //if found - if ( getCapturePointerLeft() != NULL) + if ( captured ) { // consider clicking on a control implies handling of the event. handled= true; // handle the capture - getCapturePointerLeft()->handleEvent(evnt); + if( getCapturePointerLeft() != NULL ) + getCapturePointerLeft()->handleEvent(evnt); + else + _CapturedView->handleEvent( evnt ); } } @@ -2588,6 +2619,8 @@ namespace NLGUI // *************************************************************************** void CWidgetManager::setCapturePointerLeft(CCtrlBase *c) { + _CapturedView = NULL; + // additionally, abort any dragging if( CCtrlDraggable::getDraggedSheet() != NULL ) CCtrlDraggable::getDraggedSheet()->abortDragging();