From 3c589c7f47a3552ebff0c89cdb88d136ba519321 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 31 Aug 2003 15:35:32 +0000 Subject: [PATCH] Carbon Event Mouse Moved handler changes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23321 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/app.cpp | 134 +++++++++++++++++++++++++++++++++++- src/mac/carbon/app.cpp | 134 +++++++++++++++++++++++++++++++++++- src/mac/carbon/toplevel.cpp | 2 +- src/mac/toplevel.cpp | 2 +- 4 files changed, 264 insertions(+), 8 deletions(-) diff --git a/src/mac/app.cpp b/src/mac/app.cpp index aa4e3b578b..381dc7fb42 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -298,6 +298,7 @@ void wxApp::MacNewFile() { kEventClassAppleEvent , kEventAppleEvent } , { kEventClassMouse , kEventMouseDown } , + { kEventClassMouse , kEventMouseMoved } , { 'WXMC' , 'WXMC' } } ; @@ -340,15 +341,30 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef { OSStatus result = eventNotHandledErr ; + Point point ; + UInt32 modifiers = 0; + EventMouseButton button = 0 ; + UInt32 click = 0 ; + + GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, + sizeof( Point ), NULL, &point ); + GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, + sizeof( UInt32 ), NULL, &modifiers ); + GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, + sizeof( EventMouseButton ), NULL, &button ); + GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, + sizeof( UInt32 ), NULL, &click ); + + if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) + modifiers += btnState ; + + switch( GetEventKind(event) ) { case kEventMouseDown : { - Point point ; WindowRef window ; - GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, - sizeof( Point ), NULL, &point ); short windowPart = ::FindWindow(point, &window); if ( windowPart == inMenuBar ) @@ -358,6 +374,13 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef } } break ; + case kEventMouseMoved : + { + wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; + result = noErr ; + break ; + } + break ; } return result ; @@ -2099,6 +2122,111 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) } } +#else + +void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp) +{ + WindowRef window; + + wxWindow* currentMouseWindow = NULL ; + + if (s_captureWindow ) + { + currentMouseWindow = s_captureWindow ; + } + else + { + wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , ¤tMouseWindow ) ; + } + + if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) + { + wxMouseEvent event ; + + bool isDown = !(modifiers & btnState) ; // 1 is for up + bool controlDown = modifiers & controlKey ; // for simulating right mouse + + event.m_leftDown = isDown && !controlDown; + + event.m_middleDown = FALSE; + event.m_rightDown = isDown && controlDown; + + event.m_shiftDown = modifiers & shiftKey; + event.m_controlDown = modifiers & controlKey; + event.m_altDown = modifiers & optionKey; + event.m_metaDown = modifiers & cmdKey; + + event.m_x = x; + event.m_y = y; + event.m_timeStamp = timestamp; + + if ( wxWindow::s_lastMouseWindow ) + { + wxMouseEvent eventleave(event); + eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); + wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); + eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; + +#if wxUSE_TOOLTIPS + wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave); +#endif // wxUSE_TOOLTIPS + wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); + } + if ( currentMouseWindow ) + { + wxMouseEvent evententer(event); + evententer.SetEventType( wxEVT_ENTER_WINDOW ); + currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); + evententer.SetEventObject( currentMouseWindow ) ; +#if wxUSE_TOOLTIPS + wxToolTip::RelayEvent( currentMouseWindow , evententer); +#endif // wxUSE_TOOLTIPS + currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); + } + wxWindow::s_lastMouseWindow = currentMouseWindow ; + } + + short windowPart = inNoWindow ; + + if ( s_captureWindow ) + { + window = (WindowRef) s_captureWindow->MacGetRootWindow() ; + windowPart = inContent ; + } + else + { + Point pt= { y , x } ; + windowPart = ::FindWindow(pt , &window); + } + + switch (windowPart) + { + case inContent : + { + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ; + else + { + if ( wxIsBusy() ) + { + } + else + UMAShowArrowCursor(); + } + } + break; + default : + { + if ( wxIsBusy() ) + { + } + else + UMAShowArrowCursor(); + } + break ; + } +} #endif void wxApp::MacHandleMenuCommand( wxUint32 id ) diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index aa4e3b578b..381dc7fb42 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -298,6 +298,7 @@ void wxApp::MacNewFile() { kEventClassAppleEvent , kEventAppleEvent } , { kEventClassMouse , kEventMouseDown } , + { kEventClassMouse , kEventMouseMoved } , { 'WXMC' , 'WXMC' } } ; @@ -340,15 +341,30 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef { OSStatus result = eventNotHandledErr ; + Point point ; + UInt32 modifiers = 0; + EventMouseButton button = 0 ; + UInt32 click = 0 ; + + GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, + sizeof( Point ), NULL, &point ); + GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, + sizeof( UInt32 ), NULL, &modifiers ); + GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, + sizeof( EventMouseButton ), NULL, &button ); + GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, + sizeof( UInt32 ), NULL, &click ); + + if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) + modifiers += btnState ; + + switch( GetEventKind(event) ) { case kEventMouseDown : { - Point point ; WindowRef window ; - GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, - sizeof( Point ), NULL, &point ); short windowPart = ::FindWindow(point, &window); if ( windowPart == inMenuBar ) @@ -358,6 +374,13 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef } } break ; + case kEventMouseMoved : + { + wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; + result = noErr ; + break ; + } + break ; } return result ; @@ -2099,6 +2122,111 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) } } +#else + +void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp) +{ + WindowRef window; + + wxWindow* currentMouseWindow = NULL ; + + if (s_captureWindow ) + { + currentMouseWindow = s_captureWindow ; + } + else + { + wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , ¤tMouseWindow ) ; + } + + if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) + { + wxMouseEvent event ; + + bool isDown = !(modifiers & btnState) ; // 1 is for up + bool controlDown = modifiers & controlKey ; // for simulating right mouse + + event.m_leftDown = isDown && !controlDown; + + event.m_middleDown = FALSE; + event.m_rightDown = isDown && controlDown; + + event.m_shiftDown = modifiers & shiftKey; + event.m_controlDown = modifiers & controlKey; + event.m_altDown = modifiers & optionKey; + event.m_metaDown = modifiers & cmdKey; + + event.m_x = x; + event.m_y = y; + event.m_timeStamp = timestamp; + + if ( wxWindow::s_lastMouseWindow ) + { + wxMouseEvent eventleave(event); + eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); + wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); + eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; + +#if wxUSE_TOOLTIPS + wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave); +#endif // wxUSE_TOOLTIPS + wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); + } + if ( currentMouseWindow ) + { + wxMouseEvent evententer(event); + evententer.SetEventType( wxEVT_ENTER_WINDOW ); + currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); + evententer.SetEventObject( currentMouseWindow ) ; +#if wxUSE_TOOLTIPS + wxToolTip::RelayEvent( currentMouseWindow , evententer); +#endif // wxUSE_TOOLTIPS + currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); + } + wxWindow::s_lastMouseWindow = currentMouseWindow ; + } + + short windowPart = inNoWindow ; + + if ( s_captureWindow ) + { + window = (WindowRef) s_captureWindow->MacGetRootWindow() ; + windowPart = inContent ; + } + else + { + Point pt= { y , x } ; + windowPart = ::FindWindow(pt , &window); + } + + switch (windowPart) + { + case inContent : + { + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ; + else + { + if ( wxIsBusy() ) + { + } + else + UMAShowArrowCursor(); + } + } + break; + default : + { + if ( wxIsBusy() ) + { + } + else + UMAShowArrowCursor(); + } + break ; + } +} #endif void wxApp::MacHandleMenuCommand( wxUint32 id ) diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index a6a9882aea..fce9d1fbf5 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -280,7 +280,7 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef result = noErr ; break ; case kEventMouseMoved : - toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; + wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseDragged : diff --git a/src/mac/toplevel.cpp b/src/mac/toplevel.cpp index a6a9882aea..fce9d1fbf5 100644 --- a/src/mac/toplevel.cpp +++ b/src/mac/toplevel.cpp @@ -280,7 +280,7 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef result = noErr ; break ; case kEventMouseMoved : - toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; + wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseDragged : -- 2.45.2