summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-09-13 12:44:24 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2018-09-18 11:43:30 +0200
commit925e2edb6f3f8fffcff9eddb31ed18bc77e2a690 (patch)
treeb7077dcf99051435d5de54146581b97fa6b6a33b /vcl
parent0c27134fb993b30e1a0ce827364c35f8fbaac359 (diff)
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: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/inc/osx/salinst.h3
-rw-r--r--vcl/osx/saldata.cxx8
-rw-r--r--vcl/osx/salinst.cxx107
-rw-r--r--vcl/osx/salmenu.cxx190
-rw-r--r--vcl/osx/vclnsapp.mm16
-rw-r--r--vcl/source/app/svmain.cxx10
-rw-r--r--vcl/source/app/svmainhook.cxx34
8 files changed, 127 insertions, 242 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 2f69f6550dae..f9df0a3a5f36 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -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 \
diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
index 60a542afcf9d..afb1d2b34aa3 100644
--- a/vcl/inc/osx/salinst.h
+++ b/vcl/inc/osx/salinst.h
@@ -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;
diff --git a/vcl/osx/saldata.cxx b/vcl/osx/saldata.cxx
index 3357adbcd60a..033114dae7e1 100644
--- a/vcl/osx/saldata.cxx
+++ b/vcl/osx/saldata.cxx
@@ -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()
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 0314b85ef1f8..e81278b807fb 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -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;
diff --git a/vcl/osx/salmenu.cxx b/vcl/osx/salmenu.cxx
index ee0e99278892..4ec9e7d70871 100644
--- a/vcl/osx/salmenu.cxx
+++ b/vcl/osx/salmenu.cxx
@@ -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
- pMainMenuSelector = [[MainMenuSelector alloc] init];
+ // get the main menu
+ NSMenu* pMainMenu = [NSApp mainMenu];
+ assert(pMainMenu == nil);
+ if (pMainMenu != nil)
+ return;
- // 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
- action: @selector(showAbout:)
- keyEquivalent: @""
- atIndex: 0];
- if (pString)
- [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
- action: @selector(showPreferences:)
- keyEquivalent: @","
- atIndex: 2];
- if (pString)
- [pString release];
- if( pNewItem )
- {
+ 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];
+
+ // about
+ NSString* pString = CreateNSString(VclResId(SV_STDTEXT_ABOUT));
+ pNewItem = [pAppMenu addItemWithTitle: pString
+ action: @selector(showAbout:)
+ keyEquivalent: @""];
+ [pString release];
+ [pNewItem setTarget: pMainMenuSelector];
+
+ [pAppMenu addItem:[NSMenuItem separatorItem]];
+
+ // preferences
+ pString = CreateNSString(VclResId(SV_STDTEXT_PREFERENCES));
+ pNewItem = [pAppMenu addItemWithTitle: pString
+ action: @selector(showPreferences:)
+ keyEquivalent: @","];
+ [pString release];
SAL_WNODEPRECATED_DECLARATIONS_PUSH
-// 'NSCommandKeyMask' is deprecated: first deprecated in macOS 10.12
- [pNewItem setKeyEquivalentModifierMask: NSCommandKeyMask];
+ // '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
-
- // rename standard entries
- // rename "Services"
- pNewItem = [pAppMenu itemAtIndex: 4];
- if( pNewItem )
- {
- pString = CreateNSString(VclResId(SV_MENU_MAC_SERVICES));
- [pNewItem setTitle: pString];
- if( pString )
- [pString release];
- }
-
- // rename "Hide NewApplication"
- pNewItem = [pAppMenu itemAtIndex: 6];
- if( pNewItem )
- {
- pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEAPP));
- [pNewItem setTitle: pString];
- if( pString )
- [pString release];
- }
-
- // rename "Hide Others"
- pNewItem = [pAppMenu itemAtIndex: 7];
- if( pNewItem )
- {
- pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEALL));
- [pNewItem setTitle: pString];
- if( pString )
- [pString release];
- }
-
- // rename "Show all"
- pNewItem = [pAppMenu itemAtIndex: 8];
- if( pNewItem )
- {
- pString = CreateNSString(VclResId(SV_MENU_MAC_SHOWALL));
- [pNewItem setTitle: pString];
- if( pString )
- [pString release];
- }
-
- // rename "Quit NewApplication"
- pNewItem = [pAppMenu itemAtIndex: 10];
- if( pNewItem )
- {
- pString = CreateNSString(VclResId(SV_MENU_MAC_QUITAPP));
- [pNewItem setTitle: pString];
- if( pString )
- [pString release];
- }
- }
- }
- }
+ [pNewItem setTarget: pMainMenuSelector];
+
+ [pAppMenu addItem:[NSMenuItem separatorItem]];
+
+ // Services item and menu
+ pString = CreateNSString(VclResId(SV_MENU_MAC_SERVICES));
+ pNewItem = [pAppMenu addItemWithTitle: pString
+ action: nil
+ keyEquivalent: @""];
+ NSMenu *servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease];
+ [pNewItem setSubmenu: servicesMenu];
+ [NSApp setServicesMenu: servicesMenu];
+
+ [pAppMenu addItem:[NSMenuItem separatorItem]];
+
+ // Hide Application
+ pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEAPP));
+ [pAppMenu addItemWithTitle: pString
+ action:@selector(hide:)
+ keyEquivalent:@"h"];
+ [pString release];
+
+ // Hide Others
+ pString = CreateNSString(VclResId(SV_MENU_MAC_HIDEALL));
+ [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
+
+ // Show All
+ pString = CreateNSString(VclResId(SV_MENU_MAC_SHOWALL));
+ [pAppMenu addItemWithTitle: pString
+ action:@selector(unhideAllApplications:)
+ keyEquivalent:@""];
+ [pString release];
+
+ [pAppMenu addItem:[NSMenuItem separatorItem]];
+
+ // Quit
+ pString = CreateNSString(VclResId(SV_MENU_MAC_QUITAPP));
+ [pAppMenu addItemWithTitle: pString
+ action:@selector(terminate:)
+ keyEquivalent:@"q"];
+ [pString release];
}
std::unique_ptr<SalMenu> AquaSalInstance::CreateMenu( bool bMenuBar, Menu* pVCLMenu )
diff --git a/vcl/osx/vclnsapp.mm b/vcl/osx/vclnsapp.mm
index f60b478a185f..7bbdc9d8843f 100644
--- a/vcl/osx/vclnsapp.mm
+++ b/vcl/osx/vclnsapp.mm
@@ -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;
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 3ca22053452d..c9f3f056f7e9 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -271,10 +271,6 @@ int ImplSVMain()
bool bInit = isInitVCL() || InitVCL();
-#ifdef MACOSX
- postInitVCLinitNSApp();
-#endif
-
#ifdef IOS
testExceptions();
#endif
@@ -317,11 +313,7 @@ int ImplSVMain()
int SVMain()
{
- int nRet;
- if( !Application::IsConsoleOnly() && ImplSVMainHook( &nRet ) )
- return nRet;
- else
- return ImplSVMain();
+ return ImplSVMain();
}
// This variable is set when no Application object has been instantiated
diff --git a/vcl/source/app/svmainhook.cxx b/vcl/source/app/svmainhook.cxx
deleted file mode 100644
index a66bbc186f92..000000000000
--- a/vcl/source/app/svmainhook.cxx
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- 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: */