Kaydet (Commit) 925e2edb authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Drop NSApplicationMain usage

Allows to drop all the special SVMain handling introduced for
MacOSX. This way LO can also be build via SSH, because gengal
won't abort / fail because of the missing window system.

Currently this just implements the global menu. I don't know
what else is missing. Eventually we want to reimplement the
Cocoa debug option forwarding (NSAccessibilityDebugLogLevel).

Change-Id: I359c46fd03e2436a8a37fd211e59e4e305f8aba0
Reviewed-on: https://gerrit.libreoffice.org/60571
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst 0c27134f
...@@ -373,7 +373,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ ...@@ -373,7 +373,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/app/svapp \ vcl/source/app/svapp \
vcl/source/app/svdata \ vcl/source/app/svdata \
vcl/source/app/svmain \ vcl/source/app/svmain \
vcl/source/app/svmainhook \
vcl/source/app/timer \ vcl/source/app/timer \
vcl/source/app/unohelp2 \ vcl/source/app/unohelp2 \
vcl/source/app/unohelp \ vcl/source/app/unohelp \
......
...@@ -90,6 +90,8 @@ public: ...@@ -90,6 +90,8 @@ public:
AquaSalInstance(); AquaSalInstance();
virtual ~AquaSalInstance() override; virtual ~AquaSalInstance() override;
virtual void AfterAppInit() override;
virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override; virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override; virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
virtual void DestroyFrame( SalFrame* pFrame ) override; virtual void DestroyFrame( SalFrame* pFrame ) override;
...@@ -144,7 +146,6 @@ public: ...@@ -144,7 +146,6 @@ public:
void endedPrintJob() { mnActivePrintJobs--; } void endedPrintJob() { mnActivePrintJobs--; }
// event subtypes for NSApplicationDefined events // event subtypes for NSApplicationDefined events
static const short AppExecuteSVMain = 0x7fff;
static const short AppEndLoopEvent = 1; static const short AppEndLoopEvent = 1;
static const short AppStartTimerEvent = 10; static const short AppStartTimerEvent = 10;
static const short YieldWakeupEvent = 20; static const short YieldWakeupEvent = 20;
......
...@@ -54,6 +54,7 @@ SalData::SalData() ...@@ -54,6 +54,7 @@ SalData::SalData()
mnDPIX( 0 ), mnDPIX( 0 ),
mnDPIY( 0 ) mnDPIY( 0 )
{ {
SetSalData(this);
maCursors.fill( INVALID_CURSOR_PTR ); maCursors.fill( INVALID_CURSOR_PTR );
if( s_aAutoReleaseKey == nullptr ) if( s_aAutoReleaseKey == nullptr )
s_aAutoReleaseKey = osl_createThreadKey( releasePool ); s_aAutoReleaseKey = osl_createThreadKey( releasePool );
...@@ -85,6 +86,13 @@ SalData::~SalData() ...@@ -85,6 +86,13 @@ SalData::~SalData()
if ( mpAppleRemoteMainController ) if ( mpAppleRemoteMainController )
[mpAppleRemoteMainController release]; [mpAppleRemoteMainController release];
#endif #endif
if( mpStatusItem )
{
[mpStatusItem release];
mpStatusItem = nil;
}
SetSalData( nullptr );
} }
void SalData::ensureThreadAutoreleasePool() void SalData::ensureThreadAutoreleasePool()
......
...@@ -77,9 +77,7 @@ extern "C" { ...@@ -77,9 +77,7 @@ extern "C" {
using namespace std; using namespace std;
using namespace ::com::sun::star; using namespace ::com::sun::star;
static int* gpnInit = nullptr;
static NSMenu* pDockMenu = nil; static NSMenu* pDockMenu = nil;
static bool bNoSVMain = true;
static bool bLeftMain = false; static bool bLeftMain = false;
class AquaDelayedSettingsChanged : public Idle class AquaDelayedSettingsChanged : public Idle
...@@ -143,23 +141,7 @@ bool AquaSalInstance::isOnCommandLine( const OUString& rArg ) ...@@ -143,23 +141,7 @@ bool AquaSalInstance::isOnCommandLine( const OUString& rArg )
return false; return false;
} }
// initialize the cocoa VCL_NSApplication object void AquaSalInstance::AfterAppInit()
// returns an NSAutoreleasePool that must be released when the event loop begins
static void initNSApp()
{
// create our cocoa NSApplication
[VCL_NSApplication sharedApplication];
SalData::ensureThreadAutoreleasePool();
// put cocoa into multithreaded mode
[NSThread detachNewThreadSelector:@selector(enableCocoaThreads:) toTarget:[[CocoaThreadEnabler alloc] init] withObject:nil];
// activate our delegate methods
[NSApp setDelegate: NSApp];
}
void postInitVCLinitNSApp()
{ {
[[NSNotificationCenter defaultCenter] addObserver: NSApp [[NSNotificationCenter defaultCenter] addObserver: NSApp
selector: @selector(systemColorsChanged:) selector: @selector(systemColorsChanged:)
...@@ -196,38 +178,6 @@ void postInitVCLinitNSApp() ...@@ -196,38 +178,6 @@ void postInitVCLinitNSApp()
#endif #endif
} }
bool ImplSVMainHook( int * pnInit )
{
if (comphelper::LibreOfficeKit::isActive())
return false;
NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
unlink([[NSString stringWithFormat:@"%@/Library/Saved Application State/%s.savedState/restorecount.plist", NSHomeDirectory(), MACOSX_BUNDLE_IDENTIFIER] UTF8String]);
unlink([[NSString stringWithFormat:@"%@/Library/Saved Application State/%s.savedState/restorecount.txt", NSHomeDirectory(), MACOSX_BUNDLE_IDENTIFIER] UTF8String]);
[ pool drain ];
gpnInit = pnInit;
bNoSVMain = false;
initNSApp();
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
}
void SalAbort( const OUString& rErrorText, bool bDumpCore ) void SalAbort( const OUString& rErrorText, bool bDumpCore )
{ {
if( rErrorText.isEmpty() ) if( rErrorText.isEmpty() )
...@@ -243,8 +193,6 @@ void SalAbort( const OUString& rErrorText, bool bDumpCore ) ...@@ -243,8 +193,6 @@ void SalAbort( const OUString& rErrorText, bool bDumpCore )
void InitSalData() void InitSalData()
{ {
SalData *pSalData = new SalData;
SetSalData( pSalData );
} }
const OUString& SalGetDesktopEnvironment() const OUString& SalGetDesktopEnvironment()
...@@ -255,14 +203,6 @@ const OUString& SalGetDesktopEnvironment() ...@@ -255,14 +203,6 @@ const OUString& SalGetDesktopEnvironment()
void DeInitSalData() void DeInitSalData()
{ {
SalData *pSalData = GetSalData();
if( pSalData->mpStatusItem )
{
[pSalData->mpStatusItem release];
pSalData->mpStatusItem = nil;
}
delete pSalData;
SetSalData( nullptr );
} }
void InitSalMain() void InitSalMain()
...@@ -369,12 +309,24 @@ void ImplSalYieldMutexRelease() ...@@ -369,12 +309,24 @@ void ImplSalYieldMutexRelease()
SalInstance* CreateSalInstance() SalInstance* CreateSalInstance()
{ {
// this is the case for not using SVMain SalData* pSalData = new SalData;
// not so good
if( bNoSVMain ) NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
initNSApp(); unlink([[NSString stringWithFormat:@"%@/Library/Saved Application State/%s.savedState/restorecount.plist", NSHomeDirectory(), MACOSX_BUNDLE_IDENTIFIER] UTF8String]);
unlink([[NSString stringWithFormat:@"%@/Library/Saved Application State/%s.savedState/restorecount.txt", NSHomeDirectory(), MACOSX_BUNDLE_IDENTIFIER] UTF8String]);
[ pool drain ];
// create our cocoa NSApplication
[VCL_NSApplication sharedApplication];
SalData::ensureThreadAutoreleasePool();
// put cocoa into multithreaded mode
[NSThread detachNewThreadSelector:@selector(enableCocoaThreads:) toTarget:[[CocoaThreadEnabler alloc] init] withObject:nil];
// activate our delegate methods
[NSApp setDelegate: NSApp];
SalData* pSalData = GetSalData();
SAL_WARN_IF( pSalData->mpInstance != nullptr, "vcl", "more than one instance created" ); SAL_WARN_IF( pSalData->mpInstance != nullptr, "vcl", "more than one instance created" );
AquaSalInstance* pInst = new AquaSalInstance; AquaSalInstance* pInst = new AquaSalInstance;
...@@ -389,6 +341,8 @@ SalInstance* CreateSalInstance() ...@@ -389,6 +341,8 @@ SalInstance* CreateSalInstance()
ImplGetSVData()->maNWFData.mbProgressNeedsErase = true; ImplGetSVData()->maNWFData.mbProgressNeedsErase = true;
ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset = 10; ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset = 10;
[NSApp finishLaunching];
return pInst; return pInst;
} }
...@@ -410,6 +364,13 @@ AquaSalInstance::AquaSalInstance() ...@@ -410,6 +364,13 @@ AquaSalInstance::AquaSalInstance()
AquaSalInstance::~AquaSalInstance() AquaSalInstance::~AquaSalInstance()
{ {
[NSApp stop: NSApp];
bLeftMain = true;
if( pDockMenu )
{
[pDockMenu release];
pDockMenu = nil;
}
GetYieldMutex()->release(); GetYieldMutex()->release();
} }
...@@ -444,20 +405,6 @@ void AquaSalInstance::handleAppDefinedEvent( NSEvent* pEvent ) ...@@ -444,20 +405,6 @@ void AquaSalInstance::handleAppDefinedEvent( NSEvent* pEvent )
case AppEndLoopEvent: case AppEndLoopEvent:
[NSApp stop: NSApp]; [NSApp stop: NSApp];
break; break;
case AppExecuteSVMain:
{
int nResult = ImplSVMain();
if( gpnInit )
*gpnInit = nResult;
[NSApp stop: NSApp];
bLeftMain = true;
if( pDockMenu )
{
[pDockMenu release];
pDockMenu = nil;
}
break;
}
case DispatchTimerEvent: case DispatchTimerEvent:
{ {
AquaSalInstance *pInst = GetSalData()->mpInstance; AquaSalInstance *pInst = GetSalData()->mpInstance;
......
...@@ -112,111 +112,99 @@ static MainMenuSelector* pMainMenuSelector = nil; ...@@ -112,111 +112,99 @@ static MainMenuSelector* pMainMenuSelector = nil;
static void initAppMenu() static void initAppMenu()
{ {
static bool bOnce = true; static bool bInitialized = false;
if( bOnce ) if (bInitialized)
{ return;
bOnce = false;
// get the main menu // get the main menu
NSMenu* pMainMenu = [NSApp mainMenu]; NSMenu* pMainMenu = [NSApp mainMenu];
if( pMainMenu != nil ) assert(pMainMenu == nil);
{ if (pMainMenu != nil)
// create the action selector return;
pMainMenuSelector = [[MainMenuSelector alloc] init];
// get the proper submenu bInitialized = true;
NSMenu* pAppMenu = [[pMainMenu itemAtIndex: 0] submenu];
if( pAppMenu ) NSMenu* pAppMenu = nil;
{ NSMenuItem* pNewItem = nil;
// insert about entry
OUString aAbout(VclResId(SV_STDTEXT_ABOUT)); pMainMenu = [[[NSMenu alloc] initWithTitle: @"Main Menu"] autorelease];
NSString* pString = CreateNSString( aAbout ); pNewItem = [pMainMenu addItemWithTitle: @"Application"
NSMenuItem* pNewItem = [pAppMenu insertItemWithTitle: pString action: nil
action: @selector(showAbout:) keyEquivalent: @""];
keyEquivalent: @"" pAppMenu = [[[NSMenu alloc] initWithTitle: @"Application"] autorelease];
atIndex: 0]; [pNewItem setSubmenu: pAppMenu];
if (pString) [NSApp setMainMenu: pMainMenu];
[pString release];
if( pNewItem ) pMainMenuSelector = [[MainMenuSelector alloc] init];
{
[pNewItem setTarget: pMainMenuSelector]; // about
[pAppMenu insertItem: [NSMenuItem separatorItem] atIndex: 1]; NSString* pString = CreateNSString(VclResId(SV_STDTEXT_ABOUT));
} pNewItem = [pAppMenu addItemWithTitle: pString
action: @selector(showAbout:)
// insert preferences entry keyEquivalent: @""];
OUString aPref(VclResId(SV_STDTEXT_PREFERENCES)); [pString release];
pString = CreateNSString( aPref ); [pNewItem setTarget: pMainMenuSelector];
pNewItem = [pAppMenu insertItemWithTitle: pString
action: @selector(showPreferences:) [pAppMenu addItem:[NSMenuItem separatorItem]];
keyEquivalent: @","
atIndex: 2]; // preferences
if (pString) pString = CreateNSString(VclResId(SV_STDTEXT_PREFERENCES));
[pString release]; pNewItem = [pAppMenu addItemWithTitle: pString
if( pNewItem ) action: @selector(showPreferences:)
{ keyEquivalent: @","];
[pString release];
SAL_WNODEPRECATED_DECLARATIONS_PUSH SAL_WNODEPRECATED_DECLARATIONS_PUSH
// 'NSCommandKeyMask' is deprecated: first deprecated in macOS 10.12 // 'NSCommandKeyMask' is deprecated: first deprecated in macOS 10.12
[pNewItem setKeyEquivalentModifierMask: NSCommandKeyMask]; [pNewItem setKeyEquivalentModifierMask: NSCommandKeyMask];
SAL_WNODEPRECATED_DECLARATIONS_POP SAL_WNODEPRECATED_DECLARATIONS_POP
[pNewItem setTarget: pMainMenuSelector]; [pNewItem setTarget: pMainMenuSelector];
[pAppMenu insertItem: [NSMenuItem separatorItem] atIndex: 3];
} [pAppMenu addItem:[NSMenuItem separatorItem]];
// WARNING: ultra ugly code ahead // Services item and menu
pString = CreateNSString(VclResId(SV_MENU_MAC_SERVICES));
// rename standard entries pNewItem = [pAppMenu addItemWithTitle: pString
// rename "Services" action: nil
pNewItem = [pAppMenu itemAtIndex: 4]; keyEquivalent: @""];
if( pNewItem ) NSMenu *servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease];
{ [pNewItem setSubmenu: servicesMenu];
pString = CreateNSString(VclResId(SV_MENU_MAC_SERVICES)); [NSApp setServicesMenu: servicesMenu];
[pNewItem setTitle: pString];
if( pString ) [pAppMenu addItem:[NSMenuItem separatorItem]];
[pString release];
} // Hide Application
pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEAPP));
// rename "Hide NewApplication" [pAppMenu addItemWithTitle: pString
pNewItem = [pAppMenu itemAtIndex: 6]; action:@selector(hide:)
if( pNewItem ) keyEquivalent:@"h"];
{ [pString release];
pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEAPP));
[pNewItem setTitle: pString]; // Hide Others
if( pString ) pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEALL));
[pString release]; [pAppMenu addItemWithTitle: pString
} action:@selector(hideOtherApplications:)
keyEquivalent:@"h"];
// rename "Hide Others" [pString release];
pNewItem = [pAppMenu itemAtIndex: 7]; SAL_WNODEPRECATED_DECLARATIONS_PUSH
if( pNewItem ) // 'NSCommandKeyMask' is deprecated: first deprecated in macOS 10.12
{ [pNewItem setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEALL)); SAL_WNODEPRECATED_DECLARATIONS_POP
[pNewItem setTitle: pString];
if( pString ) // Show All
[pString release]; pString = CreateNSString(VclResId(SV_MENU_MAC_SHOWALL));
} [pAppMenu addItemWithTitle: pString
action:@selector(unhideAllApplications:)
// rename "Show all" keyEquivalent:@""];
pNewItem = [pAppMenu itemAtIndex: 8]; [pString release];
if( pNewItem )
{ [pAppMenu addItem:[NSMenuItem separatorItem]];
pString = CreateNSString(VclResId(SV_MENU_MAC_SHOWALL));
[pNewItem setTitle: pString]; // Quit
if( pString ) pString = CreateNSString(VclResId(SV_MENU_MAC_QUITAPP));
[pString release]; [pAppMenu addItemWithTitle: pString
} action:@selector(terminate:)
keyEquivalent:@"q"];
// rename "Quit NewApplication" [pString release];
pNewItem = [pAppMenu itemAtIndex: 10];
if( pNewItem )
{
pString = CreateNSString(VclResId(SV_MENU_MAC_QUITAPP));
[pNewItem setTitle: pString];
if( pString )
[pString release];
}
}
}
}
} }
std::unique_ptr<SalMenu> AquaSalInstance::CreateMenu( bool bMenuBar, Menu* pVCLMenu ) std::unique_ptr<SalMenu> AquaSalInstance::CreateMenu( bool bMenuBar, Menu* pVCLMenu )
......
...@@ -62,22 +62,6 @@ ...@@ -62,22 +62,6 @@
-(void)applicationDidFinishLaunching:(NSNotification*)pNotification -(void)applicationDidFinishLaunching:(NSNotification*)pNotification
{ {
(void)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)] ) if( [NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)] )
{ {
NSWindow.allowsAutomaticWindowTabbing = NO; NSWindow.allowsAutomaticWindowTabbing = NO;
......
...@@ -271,10 +271,6 @@ int ImplSVMain() ...@@ -271,10 +271,6 @@ int ImplSVMain()
bool bInit = isInitVCL() || InitVCL(); bool bInit = isInitVCL() || InitVCL();
#ifdef MACOSX
postInitVCLinitNSApp();
#endif
#ifdef IOS #ifdef IOS
testExceptions(); testExceptions();
#endif #endif
...@@ -317,11 +313,7 @@ int ImplSVMain() ...@@ -317,11 +313,7 @@ int ImplSVMain()
int SVMain() int SVMain()
{ {
int nRet; return ImplSVMain();
if( !Application::IsConsoleOnly() && ImplSVMainHook( &nRet ) )
return nRet;
else
return ImplSVMain();
} }
// This variable is set when no Application object has been instantiated // This variable is set when no Application object has been instantiated
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <vcl/svmain.hxx>
#ifndef MACOSX
// MacOSX implementation of ImplSVMainHook is in osx/salinst.cxx
bool ImplSVMainHook( int * )
{
return false; // indicate that ImplSVMainHook is not implemented
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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