From e128397f931f7a97316057588c6dfd70b1b9fd97 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Mon, 24 Nov 2003 14:25:05 +0000 Subject: [PATCH] Applied patch #809019 (Adds embedded/plugin capabilities to wxMac). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24651 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/app.h | 5 +++ include/wx/mac/uma.h | 2 +- src/mac/app.cpp | 81 ++++++++++++++++++++++++++---------------- src/mac/carbon/app.cpp | 81 ++++++++++++++++++++++++++---------------- src/mac/carbon/uma.cpp | 52 ++++++++++++++++++--------- src/mac/uma.cpp | 52 ++++++++++++++++++--------- 6 files changed, 178 insertions(+), 95 deletions(-) diff --git a/include/wx/mac/app.h b/include/wx/mac/app.h index 94e28ec345..7b2c3462b1 100644 --- a/include/wx/mac/app.h +++ b/include/wx/mac/app.h @@ -80,6 +80,7 @@ protected: // where overriden public: + static bool sm_isEmbedded; // Implementation virtual bool Initialize(int& argc, wxChar **argv); virtual void CleanUp(); @@ -142,6 +143,10 @@ public: void MacDoOneEvent() ; WXEVENTREF MacGetCurrentEvent() { return m_macCurrentEvent ; } void MacHandleOneEvent( WXEVENTREF ev ) ; + + // For embedded use. By default does nothing. + virtual void MacHandleUnhandledEvent( WXEVENTREF ev ); + #if !TARGET_CARBON virtual void MacHandleMenuSelect( int menuid , int menuitem ) ; virtual void MacHandleMouseUpEvent( WXEVENTREF ev ) ; diff --git a/include/wx/mac/uma.h b/include/wx/mac/uma.h index 0b665d5d4c..0d4399a04f 100644 --- a/include/wx/mac/uma.h +++ b/include/wx/mac/uma.h @@ -14,7 +14,7 @@ #include "wx/mac/private.h" -void UMAInitToolbox( UInt16 inMoreMastersCalls) ; +void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded) ; void UMACleanupToolbox() ; long UMAGetSystemVersion() ; bool UMAHasAppearance() ; diff --git a/src/mac/app.cpp b/src/mac/app.cpp index baa2127bbf..2ff6ed261d 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -110,6 +110,8 @@ long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ; long wxApp::s_macExitMenuItemId = wxID_EXIT ; wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ; +// Normally we're not a plugin +bool wxApp::sm_isEmbedded = false; //---------------------------------------------------------------------- // Core Apple Event Support //---------------------------------------------------------------------- @@ -521,7 +523,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) // Mac-specific - UMAInitToolbox( 4 ) ; + UMAInitToolbox( 4, sm_isEmbedded ) ; SetEventMask( everyEvent ) ; UMAShowWatchCursor() ; @@ -638,38 +640,44 @@ bool wxApp::OnInitGui() #if TARGET_CARBON InstallStandardEventHandler( GetApplicationEventTarget() ) ; - InstallApplicationEventHandler( - GetwxAppEventHandlerUPP(), - GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); + if (!sm_isEmbedded) + { + InstallApplicationEventHandler( + GetwxAppEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); + } #endif + if (!sm_isEmbedded) + { #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , - NewAEEventHandlerUPP(AEHandleODoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , - NewAEEventHandlerUPP(AEHandleOApp) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , - NewAEEventHandlerUPP(AEHandlePDoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , - NewAEEventHandlerUPP(AEHandleQuit) , - 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , + NewAEEventHandlerUPP(AEHandleODoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , + NewAEEventHandlerUPP(AEHandleOApp) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , + NewAEEventHandlerUPP(AEHandlePDoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , + NewAEEventHandlerUPP(AEHandleQuit) , + 0 , FALSE ) ; #else - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , - NewAEEventHandlerProc(AEHandleODoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , - NewAEEventHandlerProc(AEHandleOApp) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , - NewAEEventHandlerProc(AEHandlePDoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , - NewAEEventHandlerProc(AEHandleQuit) , - 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , + NewAEEventHandlerProc(AEHandleODoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , + NewAEEventHandlerProc(AEHandleOApp) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , + NewAEEventHandlerProc(AEHandlePDoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , + NewAEEventHandlerProc(AEHandleQuit) , + 0 , FALSE ) ; #endif + } return TRUE ; } @@ -1274,7 +1282,7 @@ void wxApp::MacDoOneEvent() ::IdleControls( window ) ; if ( wxTheApp->ProcessIdle() ) - sleepTime = 0 ; + sleepTime = kEventDurationNoWait; else sleepTime = GetCaretTime() / 2 ; } @@ -1287,13 +1295,22 @@ void wxApp::MacDoOneEvent() wxMacProcessNotifierAndPendingEvents() ; } +/*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr ) +{ + // Override to process unhandled events as you please +} + void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { #if TARGET_CARBON EventTargetRef theTarget; theTarget = GetEventDispatcherTarget(); m_macCurrentEvent = evr ; - SendEventToEventTarget ((EventRef) evr , theTarget); + OSStatus status = SendEventToEventTarget ((EventRef) evr , theTarget); + if(status == eventNotHandledErr) + { + MacHandleUnhandledEvent(evr); + } #else EventRecord* ev = (EventRecord*) evr ; m_macCurrentEvent = ev ; @@ -1325,6 +1342,10 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr ) MacHandleActivateEvent( ev ) ; break; case updateEvt: + // In embedded mode we first let the UnhandledEvent function + // try to handle the update event. If we handle it ourselves + // first and then pass it on, the host's windows won't update. + MacHandleUnhandledEvent(ev); MacHandleUpdateEvent( ev ) ; break; case keyDown: diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index baa2127bbf..2ff6ed261d 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -110,6 +110,8 @@ long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ; long wxApp::s_macExitMenuItemId = wxID_EXIT ; wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ; +// Normally we're not a plugin +bool wxApp::sm_isEmbedded = false; //---------------------------------------------------------------------- // Core Apple Event Support //---------------------------------------------------------------------- @@ -521,7 +523,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) // Mac-specific - UMAInitToolbox( 4 ) ; + UMAInitToolbox( 4, sm_isEmbedded ) ; SetEventMask( everyEvent ) ; UMAShowWatchCursor() ; @@ -638,38 +640,44 @@ bool wxApp::OnInitGui() #if TARGET_CARBON InstallStandardEventHandler( GetApplicationEventTarget() ) ; - InstallApplicationEventHandler( - GetwxAppEventHandlerUPP(), - GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); + if (!sm_isEmbedded) + { + InstallApplicationEventHandler( + GetwxAppEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); + } #endif + if (!sm_isEmbedded) + { #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , - NewAEEventHandlerUPP(AEHandleODoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , - NewAEEventHandlerUPP(AEHandleOApp) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , - NewAEEventHandlerUPP(AEHandlePDoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , - NewAEEventHandlerUPP(AEHandleQuit) , - 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , + NewAEEventHandlerUPP(AEHandleODoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , + NewAEEventHandlerUPP(AEHandleOApp) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , + NewAEEventHandlerUPP(AEHandlePDoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , + NewAEEventHandlerUPP(AEHandleQuit) , + 0 , FALSE ) ; #else - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , - NewAEEventHandlerProc(AEHandleODoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , - NewAEEventHandlerProc(AEHandleOApp) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , - NewAEEventHandlerProc(AEHandlePDoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , - NewAEEventHandlerProc(AEHandleQuit) , - 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , + NewAEEventHandlerProc(AEHandleODoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , + NewAEEventHandlerProc(AEHandleOApp) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , + NewAEEventHandlerProc(AEHandlePDoc) , + 0 , FALSE ) ; + AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , + NewAEEventHandlerProc(AEHandleQuit) , + 0 , FALSE ) ; #endif + } return TRUE ; } @@ -1274,7 +1282,7 @@ void wxApp::MacDoOneEvent() ::IdleControls( window ) ; if ( wxTheApp->ProcessIdle() ) - sleepTime = 0 ; + sleepTime = kEventDurationNoWait; else sleepTime = GetCaretTime() / 2 ; } @@ -1287,13 +1295,22 @@ void wxApp::MacDoOneEvent() wxMacProcessNotifierAndPendingEvents() ; } +/*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr ) +{ + // Override to process unhandled events as you please +} + void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { #if TARGET_CARBON EventTargetRef theTarget; theTarget = GetEventDispatcherTarget(); m_macCurrentEvent = evr ; - SendEventToEventTarget ((EventRef) evr , theTarget); + OSStatus status = SendEventToEventTarget ((EventRef) evr , theTarget); + if(status == eventNotHandledErr) + { + MacHandleUnhandledEvent(evr); + } #else EventRecord* ev = (EventRecord*) evr ; m_macCurrentEvent = ev ; @@ -1325,6 +1342,10 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr ) MacHandleActivateEvent( ev ) ; break; case updateEvt: + // In embedded mode we first let the UnhandledEvent function + // try to handle the update event. If we handle it ourselves + // first and then pass it on, the host's windows won't update. + MacHandleUnhandledEvent(ev); MacHandleUpdateEvent( ev ) ; break; case keyDown: diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index f7356b7c59..68a62c217c 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -45,6 +45,8 @@ static long sUMAAppearanceVersion = 0 ; static long sUMASystemVersion = 0 ; static bool sUMAHasAquaLayout = false ; +static bool sUMAHasInittedAppearance = false; + extern int gAGABackgroundColor ; bool UMAHasAppearance() { return sUMAHasAppearance ; } long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; } @@ -60,7 +62,7 @@ bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; } void UMACleanupToolbox() { - if ( sUMAHasAppearance ) + if (sUMAHasInittedAppearance) { UnregisterAppearanceClient() ; } @@ -71,26 +73,29 @@ void UMACleanupToolbox() if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) TXNTerminateTextension( ) ; } -void UMAInitToolbox( UInt16 inMoreMastersCalls ) +void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded ) { #if !TARGET_CARBON ::MaxApplZone(); for (long i = 1; i <= inMoreMastersCalls; i++) ::MoreMasters(); - ::InitGraf(&qd.thePort); - ::InitFonts(); - ::InitMenus(); - ::TEInit(); - ::InitDialogs(0L); - ::FlushEvents(everyEvent, 0); - ::InitCursor(); + if (!isEmbedded) + { + ::InitGraf(&qd.thePort); + ::InitFonts(); + ::InitMenus(); + ::TEInit(); + ::InitDialogs(0L); + ::FlushEvents(everyEvent, 0); + } + long total,contig; PurgeSpace(&total, &contig); -#else - InitCursor(); #endif + ::InitCursor(); + if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) sUMASystemVersion = 0x0000 ; @@ -98,7 +103,17 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr ) { sUMAHasAppearance = true ; - RegisterAppearanceClient(); + OSStatus status = RegisterAppearanceClient(); + // If status equals appearanceProcessRegisteredErr it means the + // appearance client already was registered (For example if we run + // embedded, the host might have registered it). In such a case + // we don't unregister it later on. + if (status != appearanceProcessRegisteredErr) + { + // Appearance client wasn't registered yet. + sUMAHasInittedAppearance = true; + } + if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr ) { sUMAAppearanceVersion = theAppearance ; @@ -116,10 +131,13 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) #if TARGET_CARBON // Call currently implicitely done : InitFloatingWindows() ; #else - if ( sUMAHasWindowManager ) - InitFloatingWindows() ; - else - InitWindows(); + if (!isEmbedded) + { + if ( sUMAHasWindowManager ) + InitFloatingWindows() ; + else + InitWindows(); + } #endif if ( NavServicesAvailable() ) @@ -143,7 +161,7 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) TXNMacOSPreferredFontDescription fontDescriptions[] = { - { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } , + { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } } ; int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; #if 0 // TARGET_CARBON diff --git a/src/mac/uma.cpp b/src/mac/uma.cpp index f7356b7c59..68a62c217c 100644 --- a/src/mac/uma.cpp +++ b/src/mac/uma.cpp @@ -45,6 +45,8 @@ static long sUMAAppearanceVersion = 0 ; static long sUMASystemVersion = 0 ; static bool sUMAHasAquaLayout = false ; +static bool sUMAHasInittedAppearance = false; + extern int gAGABackgroundColor ; bool UMAHasAppearance() { return sUMAHasAppearance ; } long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; } @@ -60,7 +62,7 @@ bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; } void UMACleanupToolbox() { - if ( sUMAHasAppearance ) + if (sUMAHasInittedAppearance) { UnregisterAppearanceClient() ; } @@ -71,26 +73,29 @@ void UMACleanupToolbox() if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) TXNTerminateTextension( ) ; } -void UMAInitToolbox( UInt16 inMoreMastersCalls ) +void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded ) { #if !TARGET_CARBON ::MaxApplZone(); for (long i = 1; i <= inMoreMastersCalls; i++) ::MoreMasters(); - ::InitGraf(&qd.thePort); - ::InitFonts(); - ::InitMenus(); - ::TEInit(); - ::InitDialogs(0L); - ::FlushEvents(everyEvent, 0); - ::InitCursor(); + if (!isEmbedded) + { + ::InitGraf(&qd.thePort); + ::InitFonts(); + ::InitMenus(); + ::TEInit(); + ::InitDialogs(0L); + ::FlushEvents(everyEvent, 0); + } + long total,contig; PurgeSpace(&total, &contig); -#else - InitCursor(); #endif + ::InitCursor(); + if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) sUMASystemVersion = 0x0000 ; @@ -98,7 +103,17 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr ) { sUMAHasAppearance = true ; - RegisterAppearanceClient(); + OSStatus status = RegisterAppearanceClient(); + // If status equals appearanceProcessRegisteredErr it means the + // appearance client already was registered (For example if we run + // embedded, the host might have registered it). In such a case + // we don't unregister it later on. + if (status != appearanceProcessRegisteredErr) + { + // Appearance client wasn't registered yet. + sUMAHasInittedAppearance = true; + } + if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr ) { sUMAAppearanceVersion = theAppearance ; @@ -116,10 +131,13 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) #if TARGET_CARBON // Call currently implicitely done : InitFloatingWindows() ; #else - if ( sUMAHasWindowManager ) - InitFloatingWindows() ; - else - InitWindows(); + if (!isEmbedded) + { + if ( sUMAHasWindowManager ) + InitFloatingWindows() ; + else + InitWindows(); + } #endif if ( NavServicesAvailable() ) @@ -143,7 +161,7 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) TXNMacOSPreferredFontDescription fontDescriptions[] = { - { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } , + { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } } ; int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; #if 0 // TARGET_CARBON -- 2.45.2