]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/app.cpp
use specific linker flags under Mac OS X when linking executables against the
[wxWidgets.git] / src / mac / carbon / app.cpp
index dcd512fa879335634cad43cbebabab8303096708..ac9d45b2c808b3094b6d904a9c1c831aaa74e497 100644 (file)
@@ -13,6 +13,8 @@
 #pragma implementation "app.h"
 #endif
 
 #pragma implementation "app.h"
 #endif
 
+#include "wx/defs.h"
+
 #include "wx/window.h"
 #include "wx/frame.h"
 #include "wx/button.h"
 #include "wx/window.h"
 #include "wx/frame.h"
 #include "wx/button.h"
@@ -35,7 +37,7 @@
 #include "wx/textctrl.h"
 #include "wx/menu.h"
 #if wxUSE_WX_RESOURCES
 #include "wx/textctrl.h"
 #include "wx/menu.h"
 #if wxUSE_WX_RESOURCES
-#include "wx/resource.h"
+#  include "wx/resource.h"
 #endif
 
 #include <string.h>
 #endif
 
 #include <string.h>
 #include "wx/mac/uma.h"
 #include "wx/mac/macnotfy.h"
 
 #include "wx/mac/uma.h"
 #include "wx/mac/macnotfy.h"
 
-#if wxUSE_SOCKETS
-    #ifdef __DARWIN__
-        #include <CoreServices/CoreServices.h>
-    #else
-        #include <Sound.h>
-        #include <Threads.h>
-        #include <ToolUtils.h>
-        #include <DiskInit.h>
-        #include <Devices.h>
-    #endif
+#ifdef __DARWIN__
+#  include <CoreServices/CoreServices.h>
+#else
+#  include <Sound.h>
+#  include <Threads.h>
+#  include <ToolUtils.h>
+#  include <DiskInit.h>
+#  include <Devices.h>
 #endif
 
 extern char *wxBuffer;
 #endif
 
 extern char *wxBuffer;
@@ -106,25 +106,25 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long re
 
 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
 
 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
-    wxApp* app = (wxApp*) refcon ;
+    // GD: UNUSED wxApp* app = (wxApp*) refcon ;
     return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
 }
 
 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
     return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
 }
 
 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
-    wxApp* app = (wxApp*) refcon ;
+    // GD: UNUSED wxApp* app = (wxApp*) refcon ;
     return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
 }
 
 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
     return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
 }
 
 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
-    wxApp* app = (wxApp*) refcon ;
+    // GD: UNUSED wxApp* app = (wxApp*) refcon ;
     return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
 }
 
 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
     return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
 }
 
 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon )
 {
-    wxApp* app = (wxApp*) refcon ;
+    // GD: UNUSED wxApp* app = (wxApp*) refcon ;
     return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
 }
 
     return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
 }
 
@@ -162,7 +162,7 @@ short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply)
     return noErr ;
 }
 
     return noErr ;
 }
 
-char StringMac[] =     "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
+char StringMac[] =  "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
                     "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
                     "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
                     "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
                     "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
                     "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
                     "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
@@ -260,7 +260,7 @@ void wxMacConvertFromPCForControls( char * p )
     int len = strlen ( p ) ;
 
     wxMacConvertFromPC( ptr , ptr , len ) ;
     int len = strlen ( p ) ;
 
     wxMacConvertFromPC( ptr , ptr , len ) ;
-    for ( int i = 0 ; i < strlen ( ptr ) ; i++ )
+    for ( unsigned int i = 0 ; i < strlen ( ptr ) ; i++ )
     {
         if ( ptr[i] == '&' && ptr[i]+1 != ' ' )
         {
     {
         if ( ptr[i] == '&' && ptr[i]+1 != ' ' )
         {
@@ -373,6 +373,12 @@ void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding
       CopyCStringToPascal( from , to ) ;
     }
 }
       CopyCStringToPascal( from , to ) ;
     }
 }
+#ifdef WXMAKINGDLL
+#ifndef __DARWIN__
+// we know it's there ;-)
+WXIMPORT char std::__throws_bad_alloc ;
+#endif
+#endif
 
 bool wxApp::Initialize()
 {
 
 bool wxApp::Initialize()
 {
@@ -448,6 +454,7 @@ bool wxApp::Initialize()
 
   if ( error )
   {
 
   if ( error )
   {
+        wxStAppResource resload ;
         short itemHit;
         Str255 message;
 
         short itemHit;
         Str255 message;
 
@@ -503,6 +510,9 @@ bool wxApp::Initialize()
 #endif // wxUSE_LOG
 #endif
 
 #endif // wxUSE_LOG
 #endif
 
+  wxWinMacWindowList = new wxList(wxKEY_INTEGER);
+  wxWinMacControlList = new wxList(wxKEY_INTEGER);
+
   wxInitializeStockLists();
   wxInitializeStockObjects();
 
   wxInitializeStockLists();
   wxInitializeStockObjects();
 
@@ -517,9 +527,6 @@ bool wxApp::Initialize()
      return FALSE;
   }
 
      return FALSE;
   }
 
-  wxWinMacWindowList = new wxList(wxKEY_INTEGER);
-  wxWinMacControlList = new wxList(wxKEY_INTEGER);
-
   wxMacCreateNotifierTable() ;
 
   UMAShowArrowCursor() ;
   wxMacCreateNotifierTable() ;
 
   UMAShowArrowCursor() ;
@@ -621,19 +628,76 @@ void wxApp::CleanUp()
 // wxEntry
 //----------------------------------------------------------------------
 
 // wxEntry
 //----------------------------------------------------------------------
 
-int wxEntryStart( int argc, char *argv[] )
+short gCurrentResource = -1 ;
+
+wxStAppResource::wxStAppResource()
+{
+    m_currentRefNum = CurResFile() ;
+    if ( gCurrentResource != -1 )
+    {
+        UseResFile( gCurrentResource ) ;
+    }
+}
+
+wxStAppResource::~wxStAppResource()
+{
+    if ( m_currentRefNum != -1 )
+    {
+        UseResFile( m_currentRefNum ) ;
+    }
+}
+
+#ifdef WXMAKINGDLL
+
+// for shared libraries we have to manually get the correct resource ref num upon
+// initializing and releasing when terminating, therefore the __wxinitialize and __wxterminate
+// must be used
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __sinit(void);    /*      (generated by linker)   */
+pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
+pascal void __terminate(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
+{
+   gCurrentResource = -1;
+   
+   if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
+      gCurrentResource = 
+         FSpOpenResFile(theInitBlock->fragLocator.u.onDisk.fileSpec, 
+                              fsRdPerm);
+   }
+   return __initialize( theInitBlock ) ;
+}
+
+pascal void __wxterminate(void)
+{
+    if (gCurrentResource != -1)
+      CloseResFile(gCurrentResource);
+    __terminate() ;
+}
+#endif
+
+int WXDLLEXPORT wxEntryStart( int argc, char *argv[] )
 {
     return wxApp::Initialize();
 }
 
 
 {
     return wxApp::Initialize();
 }
 
 
-int wxEntryInitGui()
+int WXDLLEXPORT wxEntryInitGui()
 {
     return wxTheApp->OnInitGui();
 }
 
 
 {
     return wxTheApp->OnInitGui();
 }
 
 
-void wxEntryCleanup()
+void WXDLLEXPORT wxEntryCleanup()
 {
     wxApp::CleanUp();
 }
 {
     wxApp::CleanUp();
 }
@@ -641,6 +705,7 @@ void wxEntryCleanup()
 
 int wxEntry( int argc, char *argv[] , bool enterLoop )
 {
 
 int wxEntry( int argc, char *argv[] , bool enterLoop )
 {
+    gCurrentResource = CurResFile() ;
 #ifdef __MWERKS__
 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
     // This seems to be necessary since there are 'rogue'
 #ifdef __MWERKS__
 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
     // This seems to be necessary since there are 'rogue'
@@ -731,7 +796,9 @@ wxApp::wxApp()
   m_topWindow = NULL;
   wxTheApp = this;
 
   m_topWindow = NULL;
   wxTheApp = this;
 
-  m_wantDebugOutput = TRUE ;
+#if WXWIN_COMPATIBILITY_2_2
+  m_wantDebugOutput = TRUE;
+#endif
 
   argc = 0;
   argv = NULL;
 
   argc = 0;
   argv = NULL;
@@ -886,29 +953,6 @@ void wxApp::DeletePendingObjects()
   }
 }
 
   }
 }
 
-wxIcon
-wxApp::GetStdIcon(int which) const
-{
-    switch(which)
-    {
-        case wxICON_INFORMATION:
-            return wxIcon("wxICON_INFO");
-
-        case wxICON_QUESTION:
-            return wxIcon("wxICON_QUESTION");
-
-        case wxICON_EXCLAMATION:
-            return wxIcon("wxICON_WARNING");
-
-        default:
-            wxFAIL_MSG(wxT("requested non existent standard icon"));
-            // still fall through
-
-        case wxICON_HAND:
-            return wxIcon("wxICON_ERROR");
-    }
-}
-
 void wxExit()
 {
     wxLogError(_("Fatal error: exiting"));
 void wxExit()
 {
     wxLogError(_("Fatal error: exiting"));
@@ -1270,7 +1314,16 @@ void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
     EventRecord* ev = (EventRecord*) evr ;
     WindowRef window;
 
     EventRecord* ev = (EventRecord*) evr ;
     WindowRef window;
 
-    short windowPart = ::FindWindow(ev->where, &window);
+    short windowPart = inNoWindow ;
+       if ( wxTheApp->s_captureWindow )
+       {
+               window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
+               windowPart = inContent ;
+       } 
+       else
+       {
+               windowPart = ::FindWindow(ev->where, &window) ;
+       }
 
     switch (windowPart)
     {
 
     switch (windowPart)
     {
@@ -1433,11 +1486,11 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
             handled = focus->GetEventHandler()->ProcessEvent( event ) ;
             if ( !handled )
             {
             handled = focus->GetEventHandler()->ProcessEvent( event ) ;
             if ( !handled )
             {
-                #if wxUSE_ACCEL
+#if wxUSE_ACCEL
                 if (!handled)
                 {
                 if (!handled)
                 {
-                    wxWindow *ancestor = focus;
                     /*
                     /*
+                    wxWindow *ancestor = focus;
                     while (ancestor)
                     {
                         int command = ancestor->GetAcceleratorTable()->GetCommand( event );
                     while (ancestor)
                     {
                         int command = ancestor->GetAcceleratorTable()->GetCommand( event );
@@ -1453,7 +1506,7 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
                     }
                     */
                 }
                     }
                     */
                 }
-                #endif // wxUSE_ACCEL
+#endif // wxUSE_ACCEL
             }
             if (!handled)
             {
             }
             if (!handled)
             {
@@ -1676,7 +1729,6 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr )
 
                 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
                                                  &currentMouseWindow ) ;
 
                 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
                                                  &currentMouseWindow ) ;
-
                 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
                 {
                     wxMouseEvent event ;
                 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
                 {
                     wxMouseEvent event ;
@@ -1695,17 +1747,21 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr )
                     event.m_y = ev->where.v;
                     event.m_timeStamp = ev->when;
                     event.SetEventObject(this);
                     event.m_y = ev->where.v;
                     event.m_timeStamp = ev->when;
                     event.SetEventObject(this);
-
+                    
                     if ( wxWindow::s_lastMouseWindow )
                     {
                     if ( wxWindow::s_lastMouseWindow )
                     {
-                        wxMouseEvent eventleave(event ) ;
-                        eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ;
+                        wxMouseEvent eventleave(event);
+                        eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
+                        wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
+                        
                         wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
                     }
                     if ( currentMouseWindow )
                     {
                         wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
                     }
                     if ( currentMouseWindow )
                     {
-                        wxMouseEvent evententer(event ) ;
-                        evententer.SetEventType( wxEVT_ENTER_WINDOW ) ;
+                        wxMouseEvent evententer(event);
+                        evententer.SetEventType( wxEVT_ENTER_WINDOW );
+                        currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
+                        
                         currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
                     }
                     wxWindow::s_lastMouseWindow = currentMouseWindow ;
                         currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
                     }
                     wxWindow::s_lastMouseWindow = currentMouseWindow ;