]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/app.cpp
Unix compilation fixed
[wxWidgets.git] / src / mac / app.cpp
index e238e4f740ea676d1f7c452416d3d25fcf64df9b..55df1bd41e8670deeb788b72fb471905123f081a 100644 (file)
@@ -21,6 +21,7 @@
 #include "wx/pen.h"
 #include "wx/brush.h"
 #include "wx/cursor.h"
 #include "wx/pen.h"
 #include "wx/brush.h"
 #include "wx/cursor.h"
+#include "wx/intl.h"
 #include "wx/icon.h"
 #include "wx/palette.h"
 #include "wx/dc.h"
 #include "wx/icon.h"
 #include "wx/palette.h"
 #include "wx/dc.h"
@@ -52,7 +53,7 @@
 
 #if wxUSE_SOCKETS
     #ifdef __APPLE__
 
 #if wxUSE_SOCKETS
     #ifdef __APPLE__
-        #include <OT/OpenTransport.h>
+        #include <CoreServices/CoreServices.h>
     #else
         #include <OpenTransport.h>
         #include <OpenTptInternet.h>
     #else
         #include <OpenTransport.h>
         #include <OpenTptInternet.h>
@@ -94,25 +95,41 @@ bool wxApp::s_macSupportPCMenuShortcuts = true ;
 long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
 wxString wxApp::s_macHelpMenuTitleName = "&Help" ;
 
 long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
 wxString wxApp::s_macHelpMenuTitleName = "&Help" ;
 
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
+pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon )
+#else
 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
+#endif
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
 }
 
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
 }
 
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
+pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon )
+#else
 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
+#endif
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
 }
 
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
 }
 
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
+pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon )
+#else
 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
+#endif
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
 }
 
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
 }
 
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
+pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon )
+#else
 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
+#endif
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
 {
        wxApp* app = (wxApp*) refcon ;
        return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
@@ -333,33 +350,36 @@ bool wxApp::Initialize()
   // Mac-specific
 
   UMAInitToolbox( 4 ) ;
   // Mac-specific
 
   UMAInitToolbox( 4 ) ;
+  SetEventMask( everyEvent ) ;
        UMAShowWatchCursor() ;
 
        UMAShowWatchCursor() ;
 
-#ifdef __UNIX__
-    AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,   AEHandleODoc ,
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
+    AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,   NewAEEventHandlerUPP(AEHandleODoc) ,
                            (long) wxTheApp , FALSE ) ;
                            (long) wxTheApp , FALSE ) ;
-    AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , AEHandleOApp ,
+    AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerUPP(AEHandleOApp) ,
                            (long) wxTheApp , FALSE ) ;
                            (long) wxTheApp , FALSE ) ;
-    AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,  AEHandlePDoc ,
+    AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,  NewAEEventHandlerUPP(AEHandlePDoc) ,
                            (long) wxTheApp , FALSE ) ;
                            (long) wxTheApp , FALSE ) ;
-    AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , AEHandleQuit ,
+    AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerUPP(AEHandleQuit) ,
                            (long) wxTheApp , FALSE ) ;
 #else
        AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,   NewAEEventHandlerProc(AEHandleODoc) ,
                            (long) wxTheApp , FALSE ) ;
 #else
        AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,   NewAEEventHandlerProc(AEHandleODoc) ,
-                                                  (long) wxTheApp , FALSE ) ;
+                              (long) wxTheApp , FALSE ) ;
        AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) ,
        AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) ,
-                                                  (long) wxTheApp , FALSE ) ;
+                              (long) wxTheApp , FALSE ) ;
        AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,  NewAEEventHandlerProc(AEHandlePDoc) ,
        AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,  NewAEEventHandlerProc(AEHandlePDoc) ,
-                                                  (long) wxTheApp , FALSE ) ;
+                              (long) wxTheApp , FALSE ) ;
        AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) ,
        AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) ,
-                                                  (long) wxTheApp , FALSE ) ;
+                              (long) wxTheApp , FALSE ) ;
 #endif
 
 
 #endif
 
 
+#ifndef __UNIX__
   // test the minimal configuration necessary
 
   // test the minimal configuration necessary
 
+       #if !TARGET_CARBON
        long theSystem ;
        long theSystem ;
-       long theMachine;
+       long theMachine; 
 
        if (Gestalt(gestaltMachineType, &theMachine) != noErr)
        {
 
        if (Gestalt(gestaltMachineType, &theMachine) != noErr)
        {
@@ -377,7 +397,6 @@ bool wxApp::Initialize()
        {
                error = kMacSTROldSystem  ;
        }
        {
                error = kMacSTROldSystem  ;
        }
-       #if !TARGET_CARBON
        else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
        {
                error = kMacSTRSmallSize;
        else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
        {
                error = kMacSTRSmallSize;
@@ -392,6 +411,7 @@ bool wxApp::Initialize()
                }
        }
        */
                }
        }
        */
+#endif
 
        // if we encountered any problems so far, give the error code and exit immediately
 
 
        // if we encountered any problems so far, give the error code and exit immediately
 
@@ -439,6 +459,17 @@ bool wxApp::Initialize()
   wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
   wxTheColourDatabase->Initialize();
 
   wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
   wxTheColourDatabase->Initialize();
 
+#if wxUSE_LOG
+    // flush the logged messages if any and install a 'safer' log target: the
+    // default one (wxLogGui) can't be used after the resources are freed just
+    // below and the user suppliedo ne might be even more unsafe (using any
+    // wxWindows GUI function is unsafe starting from now)
+    wxLog::DontCreateOnDemand();
+
+    // this will flush the old messages if any
+    delete wxLog::SetActiveTarget(new wxLogStderr);
+#endif // wxUSE_LOG
+
   wxInitializeStockLists();
   wxInitializeStockObjects();
 
   wxInitializeStockLists();
   wxInitializeStockObjects();
 
@@ -852,12 +883,22 @@ void wxCYield()
 }
 
 // Yield to other processes
 }
 
 // Yield to other processes
+
+static bool gs_inYield = FALSE;
+
 bool wxYield()
 {
 bool wxYield()
 {
+#ifdef __WXDEBUG__    
+    if (gs_inYield)
+        wxFAIL_MSG( wxT("wxYield called recursively" ) );
+#endif
+
+    gs_inYield = TRUE;
+    
 #if wxUSE_THREADS
 #if wxUSE_THREADS
-  YieldToAnyThread() ;
+    YieldToAnyThread() ;
 #endif
 #endif
-  EventRecord event ;
+    EventRecord event ;
 
        long sleepTime = 0 ; //::GetCaretTime();
 
 
        long sleepTime = 0 ; //::GetCaretTime();
 
@@ -867,7 +908,19 @@ bool wxYield()
        }
 
        wxMacProcessNotifierAndPendingEvents() ;
        }
 
        wxMacProcessNotifierAndPendingEvents() ;
-  return TRUE;
+
+    gs_inYield = FALSE;
+    
+    return TRUE;
+}
+
+// Yield to incoming messages; but fail silently if recursion is detected.
+bool wxYieldIfNeeded()
+{
+    if (gs_inYield)
+        return FALSE;
+        
+    return wxYield();
 }
 
 // platform specifics
 }
 
 // platform specifics
@@ -912,7 +965,7 @@ void wxApp::MacDoOneEvent()
 {
   EventRecord event ;
 
 {
   EventRecord event ;
 
-       long sleepTime = ::GetCaretTime();
+       long sleepTime = 1 ; // GetCaretTime() / 4 ;
 
        if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn))
        {
 
        if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn))
        {
@@ -928,10 +981,11 @@ void wxApp::MacDoOneEvent()
                wxTheApp->ProcessIdle() ;
        }
        if ( event.what != kHighLevelEvent )
                wxTheApp->ProcessIdle() ;
        }
        if ( event.what != kHighLevelEvent )
-               SetRectRgn( s_macCursorRgn , event.where.h - 1 , event.where.v - 1,  event.where.h + 1 , event.where.v + 1 ) ;
+               SetRectRgn( s_macCursorRgn , event.where.h , event.where.v ,  event.where.h + 1 , event.where.v + 1 ) ;
 
        // repeaters
 
 
        // repeaters
 
+  DeletePendingObjects() ;
        wxMacProcessNotifierAndPendingEvents() ;
 }
 
        wxMacProcessNotifierAndPendingEvents() ;
 }
 
@@ -1009,6 +1063,8 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
 
        short windowPart = ::FindWindow(ev->where, &window);
        wxWindow* win = wxFindWinFromMacWindow( window ) ;
 
        short windowPart = ::FindWindow(ev->where, &window);
        wxWindow* win = wxFindWinFromMacWindow( window ) ;
+    if ( wxPendingDelete.Member(win) )
+        return ;
 
        BitMap screenBits;
        GetQDGlobalsScreenBits( &screenBits );
 
        BitMap screenBits;
        GetQDGlobalsScreenBits( &screenBits );
@@ -1125,7 +1181,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                                        SetOrigin( 0 , 0 ) ;
                                        SetPort( port ) ;
                                }
                                        SetOrigin( 0 , 0 ) ;
                                        SetPort( port ) ;
                                }
-                               if ( window != frontWindow )
+                               if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
                                {
                                        if ( s_macIsInModalLoop )
                                        {
                                {
                                        if ( s_macIsInModalLoop )
                                        {
@@ -1138,6 +1194,8 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                                        }
                                        else
                                        {
                                        }
                                        else
                                        {
+                                               if ( win )
+                                                       win->MacMouseDown( ev , windowPart ) ;
                                                UMASelectWindow( window ) ;
                                        }
                                }
                                                UMASelectWindow( window ) ;
                                        }
                                }
@@ -1382,7 +1440,37 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
 
 void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
 {
 
 void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
 {
-       // nothing to do
+       wxToolTip::RemoveToolTips() ;
+       
+       UInt32 menuresult = UMAMenuEvent(ev) ;
+       if ( HiWord( menuresult ) )
+       {
+       }
+       else
+       {
+               short keycode ;
+               short keychar ;
+               keychar = short(ev->message & charCodeMask);
+               keycode = short(ev->message & keyCodeMask) >> 8 ;
+
+               wxWindow* focus = wxWindow::FindFocus() ;
+               if ( focus )
+               {
+                       long keyval = wxMacTranslateKey(keychar, keycode) ;
+                       
+                       wxKeyEvent event(wxEVT_KEY_UP);
+                       event.m_shiftDown = ev->modifiers & shiftKey;
+                       event.m_controlDown = ev->modifiers & controlKey;
+                       event.m_altDown = ev->modifiers & optionKey;
+                       event.m_metaDown = ev->modifiers & cmdKey;
+                       event.m_keyCode = keyval;
+                       event.m_x = ev->where.h;
+                       event.m_y = ev->where.v;
+                       event.m_timeStamp = ev->when;
+                       event.SetEventObject(focus);
+                       bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+               }
+       }
 }
 
 void wxApp::MacHandleActivateEvent( EventRecord *ev )
 }
 
 void wxApp::MacHandleActivateEvent( EventRecord *ev )
@@ -1410,7 +1498,8 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev )
        wxWindow * win = wxFindWinFromMacWindow( window ) ;
        if ( win )
        {
        wxWindow * win = wxFindWinFromMacWindow( window ) ;
        if ( win )
        {
-               win->MacUpdate( ev ) ;
+        if ( !wxPendingDelete.Member(win) )
+                       win->MacUpdate( ev ) ;
        }
        else
        {
        }
        else
        {
@@ -1444,7 +1533,11 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                case suspendResumeMessage :
                        {
                                bool isResuming = ev->message & resumeFlag ;
                case suspendResumeMessage :
                        {
                                bool isResuming = ev->message & resumeFlag ;
+#if !TARGET_CARBON
                                bool convertClipboard = ev->message & convertClipboardFlag ;
                                bool convertClipboard = ev->message & convertClipboardFlag ;
+#else
+                               bool convertClipboard = false;
+#endif
                                bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
                                if ( isResuming )
                                {
                                bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
                                if ( isResuming )
                                {