X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e8566d35384f83d88ac5f14b6209136377535c14..cd5e9298159e58f57e05f3b76c9d4a45e1eefe12:/src/mac/app.cpp?ds=inline diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 864e760185..ac9d45b2c8 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -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 @@ -53,13 +55,14 @@ #include "wx/mac/uma.h" #include "wx/mac/macnotfy.h" -#if wxUSE_SOCKETS - #ifdef __DARWIN__ - #include - #else - #include - #include - #endif +#ifdef __DARWIN__ +# include +#else +# include +# include +# include +# include +# include #endif extern char *wxBuffer; @@ -85,7 +88,7 @@ const short kMacMinHeap = (29 * 1024) ; const short kwxMacMenuBarResource = 1 ; const short kwxMacAppleMenuId = 1 ; -RgnHandle wxApp::s_macCursorRgn = NULL; +WXHRGN wxApp::s_macCursorRgn = NULL; wxWindow* wxApp::s_captureWindow = NULL ; int wxApp::s_lastMouseDown = 0 ; long wxApp::sm_lastMessageTime = 0; @@ -103,29 +106,29 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long re 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 ) { - 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 ) { - 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 ) { - wxApp* app = (wxApp*) refcon ; + // GD: UNUSED wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; } -OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEODoc(const WXEVENTREF event , WXEVENTREF reply) { SysBeep(40) ; ProcessSerialNumber PSN ; @@ -135,17 +138,17 @@ OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply) return noErr ; } -OSErr wxApp::MacHandleAEPDoc(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF reply) { return noErr ; } -OSErr wxApp::MacHandleAEOApp(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEOApp(const WXEVENTREF event , WXEVENTREF reply) { return noErr ; } -OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply) { wxWindow* win = GetTopWindow() ; if ( win ) @@ -159,7 +162,7 @@ OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *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" @@ -257,7 +260,7 @@ void wxMacConvertFromPCForControls( char * p ) 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 != ' ' ) { @@ -370,6 +373,12 @@ void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding CopyCStringToPascal( from , to ) ; } } +#ifdef WXMAKINGDLL +#ifndef __DARWIN__ +// we know it's there ;-) +WXIMPORT char std::__throws_bad_alloc ; +#endif +#endif bool wxApp::Initialize() { @@ -445,6 +454,7 @@ bool wxApp::Initialize() if ( error ) { + wxStAppResource resload ; short itemHit; Str255 message; @@ -500,6 +510,9 @@ bool wxApp::Initialize() #endif // wxUSE_LOG #endif + wxWinMacWindowList = new wxList(wxKEY_INTEGER); + wxWinMacControlList = new wxList(wxKEY_INTEGER); + wxInitializeStockLists(); wxInitializeStockObjects(); @@ -514,9 +527,6 @@ bool wxApp::Initialize() return FALSE; } - wxWinMacWindowList = new wxList(wxKEY_INTEGER); - wxWinMacControlList = new wxList(wxKEY_INTEGER); - wxMacCreateNotifierTable() ; UMAShowArrowCursor() ; @@ -526,6 +536,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 +574,9 @@ void wxApp::CleanUp() if (wxWinMacWindowList) delete wxWinMacWindowList ; + if (wxWinMacControlList) + delete wxWinMacControlList ; + delete wxPendingEvents; #if wxUSE_THREADS delete wxPendingEventsLocker; @@ -603,7 +617,7 @@ void wxApp::CleanUp() UMACleanupToolbox() ; if (s_macCursorRgn) - ::DisposeRgn(s_macCursorRgn); + ::DisposeRgn((RgnHandle)s_macCursorRgn); #if 0 TerminateAE() ; @@ -614,19 +628,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 +705,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' @@ -724,7 +796,9 @@ wxApp::wxApp() m_topWindow = NULL; wxTheApp = this; - m_wantDebugOutput = TRUE ; +#if WXWIN_COMPATIBILITY_2_2 + m_wantDebugOutput = TRUE; +#endif argc = 0; argv = NULL; @@ -879,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")); @@ -958,11 +1009,11 @@ bool wxApp::Yield(bool onlyIfNeeded) long sleepTime = 1 ; //::GetCaretTime(); - while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn)) + while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) { wxTheApp->MacHandleOneEvent( &event ); if ( event.what != kHighLevelEvent ) - SetRectRgn( wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; + SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; } wxMacProcessNotifierAndPendingEvents() ; @@ -976,19 +1027,24 @@ bool wxApp::Yield(bool onlyIfNeeded) void wxApp::MacSuspend( bool convertClipboard ) { - // we have to deactive the window manually + // we have to deactive the top level windows manually - wxWindow* window = GetTopWindow() ; - if ( window ) - window->MacActivate( MacGetCurrentEvent() , false ) ; + wxNode* node = wxTopLevelWindows.First(); + while (node) + { + wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data(); + win->MacActivate( MacGetCurrentEvent() , false ) ; - s_lastMouseDown = 0 ; - if( convertClipboard ) - { - MacConvertPrivateToPublicScrap() ; - } + node = node->Next(); + } - ::HideFloatingWindows() ; + s_lastMouseDown = 0 ; + if( convertClipboard ) + { + MacConvertPrivateToPublicScrap() ; + } + + ::HideFloatingWindows() ; } void wxApp::MacResume( bool convertClipboard ) @@ -1016,7 +1072,7 @@ void wxApp::MacDoOneEvent() long sleepTime = 1; // GetCaretTime() / 4 ; - if (WaitNextEvent(everyEvent, &event, sleepTime, s_macCursorRgn)) + if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) { MacHandleOneEvent( &event ); } @@ -1030,7 +1086,7 @@ void wxApp::MacDoOneEvent() wxTheApp->ProcessIdle() ; } if ( event.what != kHighLevelEvent ) - SetRectRgn( s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; + SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; // repeaters @@ -1038,8 +1094,9 @@ void wxApp::MacDoOneEvent() wxMacProcessNotifierAndPendingEvents() ; } -void wxApp::MacHandleOneEvent( EventRecord *ev ) +void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; m_macCurrentEvent = ev ; wxApp::sm_lastMessageTime = ev->when ; @@ -1093,15 +1150,17 @@ void wxApp::MacHandleOneEvent( EventRecord *ev ) wxMacProcessNotifierAndPendingEvents() ; } -void wxApp::MacHandleHighLevelEvent( EventRecord *ev ) +void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; ::AEProcessAppleEvent( ev ) ; } bool s_macIsInModalLoop = false ; -void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) +void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; wxToolTip::RemoveToolTips() ; WindowRef window; @@ -1111,7 +1170,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; short windowPart = ::FindWindow(ev->where, &window); - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( wxPendingDelete.Member(win) ) return ; @@ -1151,12 +1210,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) GrafPtr port ; GetPort( &port ) ; Point pt = { 0, 0 } ; - #if TARGET_CARBON - SetPort( GetWindowPort(window) ) ; - #else - SetPort( (window) ) ; - #endif - SetOrigin( 0 , 0 ) ; + SetPortWindowPort(window) ; LocalToGlobal( &pt ) ; SetPort( port ) ; win->SetSize( pt.h , pt.v , -1 , @@ -1222,12 +1276,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) { GrafPtr port ; GetPort( &port ) ; - #if TARGET_CARBON - SetPort( GetWindowPort(window) ) ; - #else - SetPort( (window) ) ; - #endif - SetOrigin( 0 , 0 ) ; + SetPortWindowPort(window) ; SetPort( port ) ; } if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) @@ -1260,11 +1309,21 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) } } -void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) +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) { @@ -1274,7 +1333,7 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) break ; default: { - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacMouseUp( ev , windowPart ) ; } @@ -1391,8 +1450,9 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) return retval; } -void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) +void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; wxToolTip::RemoveToolTips() ; UInt32 menuresult = UMAMenuEvent(ev) ; @@ -1426,11 +1486,11 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) handled = focus->GetEventHandler()->ProcessEvent( event ) ; if ( !handled ) { - #if wxUSE_ACCEL +#if wxUSE_ACCEL if (!handled) { - wxWindow *ancestor = focus; /* + wxWindow *ancestor = focus; while (ancestor) { int command = ancestor->GetAcceleratorTable()->GetCommand( event ); @@ -1446,7 +1506,7 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) } */ } - #endif // wxUSE_ACCEL +#endif // wxUSE_ACCEL } if (!handled) { @@ -1508,8 +1568,9 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) } } -void wxApp::MacHandleKeyUpEvent( EventRecord *ev ) +void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; wxToolTip::RemoveToolTips() ; UInt32 menuresult = UMAMenuEvent(ev) ; @@ -1543,8 +1604,9 @@ void wxApp::MacHandleKeyUpEvent( EventRecord *ev ) } } -void wxApp::MacHandleActivateEvent( EventRecord *ev ) +void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; WindowRef window = (WindowRef) ev->message ; if ( window ) { @@ -1556,20 +1618,21 @@ void wxApp::MacHandleActivateEvent( EventRecord *ev ) // if it is a floater we activate/deactivate the front non-floating window instead window = ::FrontNonFloatingWindow() ; } - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacActivate( ev , activate ) ; } } -void wxApp::MacHandleUpdateEvent( EventRecord *ev ) +void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; WindowRef window = (WindowRef) ev->message ; - wxWindow * win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; if ( win ) { if ( !wxPendingDelete.Member(win) ) - win->MacUpdate( ev ) ; + win->MacUpdate( ev->when ) ; } else { @@ -1581,8 +1644,9 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev ) } } -void wxApp::MacHandleDiskEvent( EventRecord *ev ) +void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; if ( HiWord( ev->message ) != noErr ) { #if !TARGET_CARBON @@ -1596,8 +1660,9 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev ) } } -void wxApp::MacHandleOSEvent( EventRecord *ev ) +void wxApp::MacHandleOSEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; switch( ( ev->message & osEvtMessageMask ) >> 24 ) { case suspendResumeMessage : @@ -1626,13 +1691,13 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) if ( oldFrontWindow ) { - wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; if ( win ) win->MacActivate( ev , false ) ; } if ( newFrontWindow ) { - wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; if ( win ) win->MacActivate( ev , true ) ; } @@ -1664,7 +1729,6 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , ¤tMouseWindow ) ; - if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) { wxMouseEvent event ; @@ -1683,17 +1747,21 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) 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 ; @@ -1726,7 +1794,7 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) ::GetNextEvent(0, &tmp); ev->modifiers = tmp.modifiers; - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacMouseMoved( ev , windowPart ) ; else