]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/app.cpp
Various fixes for Textctrl and Popup Menus.
[wxWidgets.git] / src / mac / carbon / app.cpp
index b16dcd492a5019dfcf9458ec3a618e4f4d0a62e8..0c87a1037886bd44a8f1a58638ee29ea278a7dd9 100644 (file)
@@ -13,6 +13,8 @@
 #pragma implementation "app.h"
 #endif
 
+#include "wx/defs.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/resource.h"
+#  include "wx/resource.h"
 #endif
 
 #include <string.h>
 #include "wx/mac/uma.h"
 #include "wx/mac/macnotfy.h"
 
-#if wxUSE_SOCKETS
-    #ifdef __DARWIN__
-        #include <CoreServices/CoreServices.h>
-    #else
-        #include <OpenTransport.h>
-        #include <OpenTptInternet.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;
@@ -159,7 +162,7 @@ short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply)
     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"
@@ -371,6 +374,11 @@ void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding
     }
 }
 
+#ifndef __DARWIN__
+// we know it's there ;-)
+WXIMPORT char std::__throws_bad_alloc ;
+#endif
+
 bool wxApp::Initialize()
 {
   int error = 0 ;
@@ -445,6 +453,7 @@ bool wxApp::Initialize()
 
   if ( error )
   {
+        wxStAppResource resload ;
         short itemHit;
         Str255 message;
 
@@ -526,6 +535,7 @@ bool wxApp::Initialize()
 
 void wxApp::CleanUp()
 {
+    wxToolTip::RemoveToolTips() ;
 #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
@@ -563,6 +573,9 @@ void wxApp::CleanUp()
   if (wxWinMacWindowList)
     delete wxWinMacWindowList ;
 
+  if (wxWinMacControlList)
+    delete wxWinMacControlList ;
+
     delete wxPendingEvents;
 #if wxUSE_THREADS
     delete wxPendingEventsLocker;
@@ -614,19 +627,76 @@ void wxApp::CleanUp()
 // 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();
 }
 
 
-int wxEntryInitGui()
+int WXDLLEXPORT wxEntryInitGui()
 {
     return wxTheApp->OnInitGui();
 }
 
 
-void wxEntryCleanup()
+void WXDLLEXPORT wxEntryCleanup()
 {
     wxApp::CleanUp();
 }
@@ -634,6 +704,7 @@ void wxEntryCleanup()
 
 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'
@@ -1159,7 +1230,7 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
                     GrafPtr port ;
                     GetPort( &port ) ;
                     Point pt = { 0, 0 } ;
-                    SetPort( GetWindowPort(window) ) ;
+                    SetPortWindowPort(window) ;
                     LocalToGlobal( &pt ) ;
                     SetPort( port ) ;
                         win->SetSize( pt.h , pt.v , -1 ,
@@ -1225,7 +1296,7 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
                 {
                     GrafPtr port ;
                     GetPort( &port ) ;
-                    SetPort( GetWindowPort(window) ) ;
+                    SetPortWindowPort(window) ;
                     SetPort( port ) ;
                 }
                 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
@@ -1263,7 +1334,16 @@ void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
     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)
     {
@@ -1669,7 +1749,6 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr )
 
                 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
                                                  &currentMouseWindow ) ;
-
                 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
                 {
                     wxMouseEvent event ;
@@ -1688,17 +1767,21 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr )
                     event.m_y = ev->where.v;
                     event.m_timeStamp = ev->when;
                     event.SetEventObject(this);
-
+                    
                     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 )
                     {
-                        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 ;