Kaydet (Commit) 284a7f60 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

OSX Re-Introduce NSApplicationMain usage

This restores the nested NSApplicationMain and default run loop
usage. Without it the Java AWT integration will start its own
event loop, effectively blocking any non-system event processing.

Reproducible via "Tools - Macros - Organize Macros - BeanShell...
- LibreOffice Macros - HelloWorld - helloworld.bsh - Edit".

The blocking can be prevented by overriding NSApplication::run and
running our own event loop using Application::Execute. But this
still doesn't show the Java AWT editor window and I couldn't find
any information how to fix this.

Since OSX now is a VCL plugin, this can't restore the old hook
mechanism, but instead adds a new function to SalInstance.
SalInstance initialization happens at InitVCL() start just a
little bit later in the call stack.

Somehow NSApplicationMain manages to run the Java VM in an extra
thread, so it doesn't block the main loop. Probably this could
also be handled by LO starting the JVM as a thread.
Further information for an implementation eventually can be found
in the "Technical Note TN2147" "JNI Development on Mac OS X."

Change-Id: I04a0c2bf7949571f1b678ada9ab3592e0fe30c1f
Regression-from: 925e2edb
Reviewed-on: https://gerrit.libreoffice.org/65836
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst 8d4a7b17
......@@ -91,6 +91,7 @@ public:
virtual ~AquaSalInstance() override;
virtual void AfterAppInit() override;
virtual bool SVMainHook(int *) override;
virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
......@@ -145,7 +146,7 @@ public:
void endedPrintJob() { mnActivePrintJobs--; }
// event subtypes for NSApplicationDefined events
static const short AppEndLoopEvent = 1;
static const short AppExecuteSVMain = 1;
static const short AppStartTimerEvent = 10;
static const short YieldWakeupEvent = 20;
static const short DispatchTimerEvent = 30;
......
......@@ -89,6 +89,7 @@ public:
//called directly after Application::Init
virtual void AfterAppInit() {}
virtual bool SVMainHook(int*) { return false; }
// Frame
// DisplayName for Unix ???
......
......@@ -81,6 +81,7 @@ extern "C" {
using namespace std;
using namespace ::com::sun::star;
static int* gpnInit = nullptr;
static NSMenu* pDockMenu = nil;
static bool bLeftMain = false;
......@@ -328,8 +329,6 @@ VCLPLUG_OSX_PUBLIC SalInstance* create_SalInstance()
ImplGetSVData()->maNWFData.mbProgressNeedsErase = true;
ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset = 10;
[NSApp finishLaunching];
return pInst;
}
}
......@@ -386,9 +385,14 @@ void AquaSalInstance::handleAppDefinedEvent( NSEvent* pEvent )
if ( pTimer )
pTimer->handleStartTimerEvent( pEvent );
break;
case AppEndLoopEvent:
case AppExecuteSVMain:
{
int nRet = ImplSVMain();
if (gpnInit)
*gpnInit = nRet;
[NSApp stop: NSApp];
break;
}
case DispatchTimerEvent:
{
AquaSalInstance *pInst = GetSalData()->mpInstance;
......@@ -958,5 +962,25 @@ NSImage* CreateNSImage( const Image& rImage )
return pImage;
}
bool AquaSalInstance::SVMainHook(int* pnInit)
{
gpnInit = pnInit;
OUString aExeURL, aExe;
osl_getExecutableFile( &aExeURL.pData );
osl_getSystemPathFromFileURL( aExeURL.pData, &aExe.pData );
OString aByteExe( OUStringToOString( aExe, osl_getThreadTextEncoding() ) );
#ifdef DEBUG
aByteExe += OString ( " NSAccessibilityDebugLogLevel 1" );
const char* pArgv[] = { aByteExe.getStr(), NULL };
NSApplicationMain( 3, pArgv );
#else
const char* pArgv[] = { aByteExe.getStr(), nullptr };
NSApplicationMain( 1, pArgv );
#endif
return true; // indicate that ImplSVMainHook is implemented
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -117,19 +117,12 @@ static void initAppMenu()
static bool bInitialized = false;
if (bInitialized)
return;
// get the main menu
NSMenu* pMainMenu = [NSApp mainMenu];
assert(pMainMenu == nil);
if (pMainMenu != nil)
return;
bInitialized = true;
NSMenu* pAppMenu = nil;
NSMenuItem* pNewItem = nil;
pMainMenu = [[[NSMenu alloc] initWithTitle: @"Main Menu"] autorelease];
NSMenu* pMainMenu = [[[NSMenu alloc] initWithTitle: @"Main Menu"] autorelease];
pNewItem = [pMainMenu addItemWithTitle: @"Application"
action: nil
keyEquivalent: @""];
......
......@@ -62,6 +62,22 @@
-(void)applicationDidFinishLaunching:(NSNotification*)pNotification
{
(void)pNotification;
SAL_WNODEPRECATED_DECLARATIONS_PUSH
// 'NSApplicationDefined' is deprecated: first deprecated in macOS 10.12
NSEvent* pEvent = [NSEvent otherEventWithType: NSApplicationDefined
location: NSZeroPoint
modifierFlags: 0
timestamp: [[NSProcessInfo processInfo] systemUptime]
windowNumber: 0
context: nil
subtype: AquaSalInstance::AppExecuteSVMain
data1: 0
data2: 0 ];
SAL_WNODEPRECATED_DECLARATIONS_POP
assert( pEvent );
[NSApp postEvent: pEvent atStart: NO];
if( [NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)] )
{
[NSWindow setAllowsAutomaticWindowTabbing:NO];
......
......@@ -190,7 +190,11 @@ int ImplSVMain()
int nReturn = EXIT_FAILURE;
bool bInit = isInitVCL() || InitVCL();
const bool bWasInitVCL = isInitVCL();
const bool bInit = bWasInitVCL || InitVCL();
int nRet = 0;
if (!bWasInitVCL && bInit && pSVData->mpDefInst->SVMainHook(&nRet))
return nRet;
if( bInit )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment