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,\
vcl/source/app/svapp \
vcl/source/app/svdata \
vcl/source/app/svmain \
vcl/source/app/svmainhook \
vcl/source/app/timer \
vcl/source/app/unohelp2 \
vcl/source/app/unohelp \
......
......@@ -90,6 +90,8 @@ public:
AquaSalInstance();
virtual ~AquaSalInstance() override;
virtual void AfterAppInit() override;
virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
virtual void DestroyFrame( SalFrame* pFrame ) override;
......@@ -144,7 +146,6 @@ public:
void endedPrintJob() { mnActivePrintJobs--; }
// event subtypes for NSApplicationDefined events
static const short AppExecuteSVMain = 0x7fff;
static const short AppEndLoopEvent = 1;
static const short AppStartTimerEvent = 10;
static const short YieldWakeupEvent = 20;
......
......@@ -54,6 +54,7 @@ SalData::SalData()
mnDPIX( 0 ),
mnDPIY( 0 )
{
SetSalData(this);
maCursors.fill( INVALID_CURSOR_PTR );
if( s_aAutoReleaseKey == nullptr )
s_aAutoReleaseKey = osl_createThreadKey( releasePool );
......@@ -85,6 +86,13 @@ SalData::~SalData()
if ( mpAppleRemoteMainController )
[mpAppleRemoteMainController release];
#endif
if( mpStatusItem )
{
[mpStatusItem release];
mpStatusItem = nil;
}
SetSalData( nullptr );
}
void SalData::ensureThreadAutoreleasePool()
......
......@@ -77,9 +77,7 @@ extern "C" {
using namespace std;
using namespace ::com::sun::star;
static int* gpnInit = nullptr;
static NSMenu* pDockMenu = nil;
static bool bNoSVMain = true;
static bool bLeftMain = false;
class AquaDelayedSettingsChanged : public Idle
......@@ -143,23 +141,7 @@ bool AquaSalInstance::isOnCommandLine( const OUString& rArg )
return false;
}
// initialize the cocoa VCL_NSApplication object
// 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()
void AquaSalInstance::AfterAppInit()
{
[[NSNotificationCenter defaultCenter] addObserver: NSApp
selector: @selector(systemColorsChanged:)
......@@ -196,38 +178,6 @@ void postInitVCLinitNSApp()
#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 )
{
if( rErrorText.isEmpty() )
......@@ -243,8 +193,6 @@ void SalAbort( const OUString& rErrorText, bool bDumpCore )
void InitSalData()
{
SalData *pSalData = new SalData;
SetSalData( pSalData );
}
const OUString& SalGetDesktopEnvironment()
......@@ -255,14 +203,6 @@ const OUString& SalGetDesktopEnvironment()
void DeInitSalData()
{
SalData *pSalData = GetSalData();
if( pSalData->mpStatusItem )
{
[pSalData->mpStatusItem release];
pSalData->mpStatusItem = nil;
}
delete pSalData;
SetSalData( nullptr );
}
void InitSalMain()
......@@ -369,12 +309,24 @@ void ImplSalYieldMutexRelease()
SalInstance* CreateSalInstance()
{
// this is the case for not using SVMain
// not so good
if( bNoSVMain )
initNSApp();
SalData* pSalData = new SalData;
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 ];
// 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" );
AquaSalInstance* pInst = new AquaSalInstance;
......@@ -389,6 +341,8 @@ SalInstance* CreateSalInstance()
ImplGetSVData()->maNWFData.mbProgressNeedsErase = true;
ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset = 10;
[NSApp finishLaunching];
return pInst;
}
......@@ -410,6 +364,13 @@ AquaSalInstance::AquaSalInstance()
AquaSalInstance::~AquaSalInstance()
{
[NSApp stop: NSApp];
bLeftMain = true;
if( pDockMenu )
{
[pDockMenu release];
pDockMenu = nil;
}
GetYieldMutex()->release();
}
......@@ -444,20 +405,6 @@ void AquaSalInstance::handleAppDefinedEvent( NSEvent* pEvent )
case AppEndLoopEvent:
[NSApp stop: NSApp];
break;
case AppExecuteSVMain:
{
int nResult = ImplSVMain();
if( gpnInit )
*gpnInit = nResult;
[NSApp stop: NSApp];
bLeftMain = true;
if( pDockMenu )
{
[pDockMenu release];
pDockMenu = nil;
}
break;
}
case DispatchTimerEvent:
{
AquaSalInstance *pInst = GetSalData()->mpInstance;
......
......@@ -112,111 +112,99 @@ static MainMenuSelector* pMainMenuSelector = nil;
static void initAppMenu()
{
static bool bOnce = true;
if( bOnce )
{
bOnce = false;
static bool bInitialized = false;
if (bInitialized)
return;
// get the main menu
NSMenu* pMainMenu = [NSApp mainMenu];
if( pMainMenu != nil )
{
// create the action selector
assert(pMainMenu == nil);
if (pMainMenu != nil)
return;
bInitialized = true;
NSMenu* pAppMenu = nil;
NSMenuItem* pNewItem = nil;
pMainMenu = [[[NSMenu alloc] initWithTitle: @"Main Menu"] autorelease];
pNewItem = [pMainMenu addItemWithTitle: @"Application"
action: nil
keyEquivalent: @""];
pAppMenu = [[[NSMenu alloc] initWithTitle: @"Application"] autorelease];
[pNewItem setSubmenu: pAppMenu];
[NSApp setMainMenu: pMainMenu];
pMainMenuSelector = [[MainMenuSelector alloc] init];
// get the proper submenu
NSMenu* pAppMenu = [[pMainMenu itemAtIndex: 0] submenu];
if( pAppMenu )
{
// insert about entry
OUString aAbout(VclResId(SV_STDTEXT_ABOUT));
NSString* pString = CreateNSString( aAbout );
NSMenuItem* pNewItem = [pAppMenu insertItemWithTitle: pString
// about
NSString* pString = CreateNSString(VclResId(SV_STDTEXT_ABOUT));
pNewItem = [pAppMenu addItemWithTitle: pString
action: @selector(showAbout:)
keyEquivalent: @""
atIndex: 0];
if (pString)
keyEquivalent: @""];
[pString release];
if( pNewItem )
{
[pNewItem setTarget: pMainMenuSelector];
[pAppMenu insertItem: [NSMenuItem separatorItem] atIndex: 1];
}
// insert preferences entry
OUString aPref(VclResId(SV_STDTEXT_PREFERENCES));
pString = CreateNSString( aPref );
pNewItem = [pAppMenu insertItemWithTitle: pString
[pAppMenu addItem:[NSMenuItem separatorItem]];
// preferences
pString = CreateNSString(VclResId(SV_STDTEXT_PREFERENCES));
pNewItem = [pAppMenu addItemWithTitle: pString
action: @selector(showPreferences:)
keyEquivalent: @","
atIndex: 2];
if (pString)
keyEquivalent: @","];
[pString release];
if( pNewItem )
{
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];
SAL_WNODEPRECATED_DECLARATIONS_POP
[pNewItem setTarget: pMainMenuSelector];
[pAppMenu insertItem: [NSMenuItem separatorItem] atIndex: 3];
}
// WARNING: ultra ugly code ahead
[pAppMenu addItem:[NSMenuItem separatorItem]];
// rename standard entries
// rename "Services"
pNewItem = [pAppMenu itemAtIndex: 4];
if( pNewItem )
{
// Services item and menu
pString = CreateNSString(VclResId(SV_MENU_MAC_SERVICES));
[pNewItem setTitle: pString];
if( pString )
[pString release];
}
pNewItem = [pAppMenu addItemWithTitle: pString
action: nil
keyEquivalent: @""];
NSMenu *servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease];
[pNewItem setSubmenu: servicesMenu];
[NSApp setServicesMenu: servicesMenu];
// rename "Hide NewApplication"
pNewItem = [pAppMenu itemAtIndex: 6];
if( pNewItem )
{
[pAppMenu addItem:[NSMenuItem separatorItem]];
// Hide Application
pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEAPP));
[pNewItem setTitle: pString];
if( pString )
[pAppMenu addItemWithTitle: pString
action:@selector(hide:)
keyEquivalent:@"h"];
[pString release];
}
// rename "Hide Others"
pNewItem = [pAppMenu itemAtIndex: 7];
if( pNewItem )
{
// Hide Others
pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEALL));
[pNewItem setTitle: pString];
if( pString )
[pAppMenu addItemWithTitle: pString
action:@selector(hideOtherApplications:)
keyEquivalent:@"h"];
[pString release];
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
// 'NSCommandKeyMask' is deprecated: first deprecated in macOS 10.12
[pNewItem setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
SAL_WNODEPRECATED_DECLARATIONS_POP
// rename "Show all"
pNewItem = [pAppMenu itemAtIndex: 8];
if( pNewItem )
{
// Show All
pString = CreateNSString(VclResId(SV_MENU_MAC_SHOWALL));
[pNewItem setTitle: pString];
if( pString )
[pAppMenu addItemWithTitle: pString
action:@selector(unhideAllApplications:)
keyEquivalent:@""];
[pString release];
}
// rename "Quit NewApplication"
pNewItem = [pAppMenu itemAtIndex: 10];
if( pNewItem )
{
[pAppMenu addItem:[NSMenuItem separatorItem]];
// Quit
pString = CreateNSString(VclResId(SV_MENU_MAC_QUITAPP));
[pNewItem setTitle: pString];
if( pString )
[pAppMenu addItemWithTitle: pString
action:@selector(terminate:)
keyEquivalent:@"q"];
[pString release];
}
}
}
}
}
std::unique_ptr<SalMenu> AquaSalInstance::CreateMenu( bool bMenuBar, Menu* pVCLMenu )
......
......@@ -62,22 +62,6 @@
-(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.allowsAutomaticWindowTabbing = NO;
......
......@@ -271,10 +271,6 @@ int ImplSVMain()
bool bInit = isInitVCL() || InitVCL();
#ifdef MACOSX
postInitVCLinitNSApp();
#endif
#ifdef IOS
testExceptions();
#endif
......@@ -317,10 +313,6 @@ int ImplSVMain()
int SVMain()
{
int nRet;
if( !Application::IsConsoleOnly() && ImplSVMainHook( &nRet ) )
return nRet;
else
return ImplSVMain();
}
......
/* -*- 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