]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/app.cpp
only work on the focus if the control is shown
[wxWidgets.git] / src / mac / carbon / app.cpp
index 8529b9e59ba7f985f4c5e7a27d456639646504e3..381dc7fb4281c8599448e5549be93fbcc3d54ae3 100644 (file)
@@ -55,7 +55,7 @@
 
 #ifdef __DARWIN__
 #  include <CoreServices/CoreServices.h>
-#  if defined(WXMAKINGDLL)
+#  if defined(WXMAKINGDLL_CORE)
 #    include <mach-o/dyld.h>
 #  endif
 #else
@@ -73,7 +73,6 @@ extern wxList *wxWinMacControlList;
 // statics for implementation
 
 static bool s_inYield = FALSE;
-static bool s_inOnIdle = FALSE;
 
 #if TARGET_CARBON
 static bool s_inReceiveEvent = FALSE ;
@@ -299,6 +298,7 @@ void wxApp::MacNewFile()
         { kEventClassAppleEvent , kEventAppleEvent } ,
 
         { kEventClassMouse , kEventMouseDown } ,
+        { kEventClassMouse , kEventMouseMoved } ,
         { 'WXMC' , 'WXMC' }
     } ;
 
@@ -341,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 )
@@ -359,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 ;
@@ -471,7 +493,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )
 
 #endif
 
-#if defined(WXMAKINGDLL) && !defined(__DARWIN__)
+#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
 // we know it's there ;-)
 WXIMPORT char std::__throws_bad_alloc ;
 #endif
@@ -486,7 +508,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
     SetEventMask( everyEvent ) ;
     UMAShowWatchCursor() ;
 
-#if defined(WXMAKINGDLL) && defined(__DARWIN__)
+#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
     // open shared library resources from here since we don't have
     //   __wxinitialize in Mach-O shared libraries
     wxStAppResource::OpenSharedLibraryResource(NULL);
@@ -657,7 +679,7 @@ void wxApp::CleanUp()
 #  endif
 #endif
 
-#if defined(WXMAKINGDLL) && defined(__DARWIN__)
+#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
     // close shared library resources from here since we don't have
     //   __wxterminate in Mach-O shared libraries
     wxStAppResource::CloseSharedLibraryResource();
@@ -684,9 +706,9 @@ void wxApp::CleanUp()
 // need to be able to find it with NSLookupAndBindSymbol
 short gSharedLibraryResource = kResFileNotOpened ;
 
-#if defined(WXMAKINGDLL) && defined(__DARWIN__)
+#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
 CFBundleRef gSharedLibraryBundle = NULL;
-#endif /* WXMAKINGDLL && __DARWIN__ */
+#endif /* WXMAKINGDLL_CORE && __DARWIN__ */
 
 wxStAppResource::wxStAppResource()
 {
@@ -709,7 +731,7 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
 {
     gSharedLibraryResource = kResFileNotOpened;
 
-#ifdef WXMAKINGDLL
+#ifdef WXMAKINGDLL_CORE
     if ( initBlock != NULL ) {
         const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
         FSSpec *fileSpec = NULL;
@@ -742,9 +764,8 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
         else {
             // wxWindows is a simple dynamic shared library
             //   load the resources from the data fork of a separate resource file
-            char  *theResPath;
-            char  *theName;
-            char  *theExt;
+            wxString theResPath;
+            wxString theName;
             FSRef  theResRef;
             OSErr  theErr = noErr;
 
@@ -764,27 +785,24 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
 #endif
 
             // allocate copy to replace .dylib.* extension with .rsrc
-            theResPath = strdup(theLibPath);
-            if (theResPath != NULL) {
-                theName = strrchr(theResPath, '/');
-                if (theName == NULL) {
-                    // no directory elements in path
-                    theName = theResPath;
-                }
-                // find ".dylib" shared library extension
-                theExt = strstr(theName, ".dylib");
-                // overwrite extension with ".rsrc"
-                strcpy(theExt, ".rsrc");
+            if (theLibPath != NULL) {
+                theResPath = theLibPath;
+                // replace '_core' with '' in case of multi-lib build
+                theResPath.Replace(wxT("_core"), wxEmptyString);
+                // replace ".dylib" shared library extension with ".rsrc"
+                theResPath.Replace(wxT(".dylib"), wxT(".rsrc"));
+                // Find the begining of the filename
+                theName = theResPath.AfterLast('/');
 
 #if 0
                 wxLogDebug( wxT("wxMac resources file name is '%s'"),
-                            theResPath );
+                            theResPath.mb_str() );
 #endif
 
-                theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false);
+                theErr = FSPathMakeRef((UInt8 *) theResPath.mb_str(), &theResRef, false);
                 if (theErr != noErr) {
                     // try in current directory (using name only)
-                    theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false);
+                    theErr = FSPathMakeRef((UInt8 *) theName.mb_str(), &theResRef, false);
                 }
 
                 // open the resource file
@@ -796,22 +814,20 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
 #ifdef __WXDEBUG__
                     fprintf(stderr,
                             wxT("unable to open wxMac resource file '%s'\n"),
-                            theResPath );
+                            theResPath.mb_str() );
 #endif // __WXDEBUG__
                 }
 
-                // free duplicated resource file path
-                free(theResPath);
             }
         }
 #endif /* __DARWIN__ */
     }
-#endif /* WXMAKINGDLL */
+#endif /* WXMAKINGDLL_CORE */
 }
 
 void wxStAppResource::CloseSharedLibraryResource()
 {
-#ifdef WXMAKINGDLL
+#ifdef WXMAKINGDLL_CORE
     // Close the shared library resource file
     if (gSharedLibraryResource != kResFileNotOpened) {
 #ifdef __DARWIN__
@@ -827,10 +843,10 @@ void wxStAppResource::CloseSharedLibraryResource()
         }
         gSharedLibraryResource = kResFileNotOpened;
     }
-#endif /* WXMAKINGDLL */
+#endif /* WXMAKINGDLL_CORE */
 }
 
-#if defined(WXMAKINGDLL) && !defined(__DARWIN__)
+#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
 
 // for shared libraries we have to manually get the correct resource
 // ref num upon initializing and releasing when terminating, therefore
@@ -854,7 +870,7 @@ pascal void __wxterminate(void)
     __terminate() ;
 }
 
-#endif /* WXMAKINGDLL && !__DARWIN__ */
+#endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
 
 #if TARGET_CARBON
 
@@ -1023,7 +1039,7 @@ void wxApp::Dispatch()
 void wxApp::OnIdle(wxIdleEvent& event)
 {
     wxAppBase::OnIdle(event);
-    
+
     // If they are pending events, we must process them: pending events are
     // either events to the threads other than main or events posted with
     // wxPostEvent() functions
@@ -1151,7 +1167,7 @@ void wxApp::MacSuspend( bool convertClipboard )
 #if TARGET_CARBON
 #if 0 //  having problems right now with that
         if (!win->HasFlag(wxSTAY_ON_TOP))
-#endif  
+#endif
 #endif
             win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
 
@@ -2106,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 ) , &currentMouseWindow ) ;
+    }
+
+    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 )