1cdf0e10cSrcweir/************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir#include "precompiled_vcl.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir#include "rtl/ustrbuf.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir#include "vcl/window.hxx" 34cdf0e10cSrcweir#include "vcl/svapp.hxx" 35cdf0e10cSrcweir#include "vcl/cmdevt.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir#include "aqua/vclnsapp.h" 38cdf0e10cSrcweir#include "aqua/salinst.h" 39cdf0e10cSrcweir#include "aqua/saldata.hxx" 40cdf0e10cSrcweir#include "aqua/salframe.h" 41cdf0e10cSrcweir#include "aqua/salframeview.h" 42cdf0e10cSrcweir 43cdf0e10cSrcweir#include "impimagetree.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir#include "premac.h" 46cdf0e10cSrcweir#import "Carbon/Carbon.h" 47cdf0e10cSrcweir#import "apple_remote/RemoteControl.h" 48cdf0e10cSrcweir#include "postmac.h" 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir@implementation CocoaThreadEnabler 52cdf0e10cSrcweir-(void)enableCocoaThreads:(id)param 53cdf0e10cSrcweir{ 54cdf0e10cSrcweir // do nothing, this is just to start an NSThread and therefore put 55cdf0e10cSrcweir // Cocoa into multithread mode 56cdf0e10cSrcweir (void)param; 57cdf0e10cSrcweir} 58cdf0e10cSrcweir@end 59cdf0e10cSrcweir 60cdf0e10cSrcweir@implementation VCL_NSApplication 61cdf0e10cSrcweir-(void)sendEvent:(NSEvent*)pEvent 62cdf0e10cSrcweir{ 63cdf0e10cSrcweir NSEventType eType = [pEvent type]; 64cdf0e10cSrcweir if( eType == NSApplicationDefined ) 65cdf0e10cSrcweir GetSalData()->mpFirstInstance->handleAppDefinedEvent( pEvent ); 66cdf0e10cSrcweir else if( eType == NSKeyDown && ([pEvent modifierFlags] & NSCommandKeyMask) != 0 ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir NSWindow* pKeyWin = [NSApp keyWindow]; 69cdf0e10cSrcweir if( pKeyWin && [pKeyWin isKindOfClass: [SalFrameWindow class]] ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir AquaSalFrame* pFrame = [(SalFrameWindow*)pKeyWin getSalFrame]; 72cdf0e10cSrcweir // handle Cmd-W 73cdf0e10cSrcweir // FIXME: the correct solution would be to handle this in framework 74cdf0e10cSrcweir // in the menu code 75cdf0e10cSrcweir // however that is currently being revised, so let's use a preliminary solution here 76cdf0e10cSrcweir // this hack is based on assumption 77cdf0e10cSrcweir // a) Cmd-W is the same in all languages in OOo's menu conig 78cdf0e10cSrcweir // b) Cmd-W is the same in all languages in on MacOS 79cdf0e10cSrcweir // for now this seems to be true 80cdf0e10cSrcweir unsigned int nModMask = ([pEvent modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)); 81cdf0e10cSrcweir if( (pFrame->mnStyleMask & NSClosableWindowMask) != 0 ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir if( nModMask == NSCommandKeyMask 84cdf0e10cSrcweir && [[pEvent charactersIgnoringModifiers] isEqualToString: @"w"] ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir [pFrame->getWindow() windowShouldClose: nil]; 87cdf0e10cSrcweir return; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir /* 92cdf0e10cSrcweir * #i98949# - Cmd-M miniaturize window, Cmd-Option-M miniaturize all windows 93cdf0e10cSrcweir */ 94cdf0e10cSrcweir if( [[pEvent charactersIgnoringModifiers] isEqualToString: @"m"] ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir if ( nModMask == NSCommandKeyMask && ([pFrame->getWindow() styleMask] & NSMiniaturizableWindowMask) ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir [pFrame->getWindow() performMiniaturize: nil]; 99cdf0e10cSrcweir return; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir if ( nModMask == ( NSCommandKeyMask | NSAlternateKeyMask ) ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir [NSApp miniaturizeAll: nil]; 105cdf0e10cSrcweir return; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir // #i90083# handle frame switching 110cdf0e10cSrcweir // FIXME: lousy workaround 111cdf0e10cSrcweir if( (nModMask & (NSControlKeyMask|NSAlternateKeyMask)) == 0 ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir if( [[pEvent characters] isEqualToString: @"<"] || 114cdf0e10cSrcweir [[pEvent characters] isEqualToString: @"~"] ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir [self cycleFrameForward: pFrame]; 117cdf0e10cSrcweir return; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir else if( [[pEvent characters] isEqualToString: @">"] || 120cdf0e10cSrcweir [[pEvent characters] isEqualToString: @"`"] ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir [self cycleFrameBackward: pFrame]; 123cdf0e10cSrcweir return; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir // get information whether the event was handled; keyDown returns nothing 128cdf0e10cSrcweir GetSalData()->maKeyEventAnswer[ pEvent ] = false; 129cdf0e10cSrcweir bool bHandled = false; 130cdf0e10cSrcweir 131cdf0e10cSrcweir // dispatch to view directly to avoid the key event being consumed by the menubar 132cdf0e10cSrcweir // popup windows do not get the focus, so they don't get these either 133cdf0e10cSrcweir // simplest would be dispatch this to the key window always if it is without parent 134cdf0e10cSrcweir // however e.g. in document we want the menu shortcut if e.g. the stylist has focus 135cdf0e10cSrcweir if( pFrame->mpParent && (pFrame->mnStyle & SAL_FRAME_STYLE_FLOAT) == 0 ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir [[pKeyWin contentView] keyDown: pEvent]; 138cdf0e10cSrcweir bHandled = GetSalData()->maKeyEventAnswer[ pEvent ]; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir // see whether the main menu consumes this event 142cdf0e10cSrcweir // if not, we want to dispatch it ourselves. Unless we do this "trick" 143cdf0e10cSrcweir // the main menu just beeps for an unknown or disabled key equivalent 144cdf0e10cSrcweir // and swallows the event wholesale 145cdf0e10cSrcweir NSMenu* pMainMenu = [NSApp mainMenu]; 146cdf0e10cSrcweir if( ! bHandled && (pMainMenu == 0 || ! [pMainMenu performKeyEquivalent: pEvent]) ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir [[pKeyWin contentView] keyDown: pEvent]; 149cdf0e10cSrcweir bHandled = GetSalData()->maKeyEventAnswer[ pEvent ]; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir else 152cdf0e10cSrcweir bHandled = true; // event handled already or main menu just handled it 153cdf0e10cSrcweir 154cdf0e10cSrcweir GetSalData()->maKeyEventAnswer.erase( pEvent ); 155cdf0e10cSrcweir if( bHandled ) 156cdf0e10cSrcweir return; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir else if( pKeyWin ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir // #i94601# a window not of vcl's making has the focus. 161cdf0e10cSrcweir // Since our menus do not invoke the usual commands 162cdf0e10cSrcweir // try to play nice with native windows like the file dialog 163cdf0e10cSrcweir // and emulate them 164cdf0e10cSrcweir // precondition: this ONLY works because CMD-V (paste), CMD-C (copy) and CMD-X (cut) are 165cdf0e10cSrcweir // NOT localized, that is the same in all locales. Should this be 166cdf0e10cSrcweir // different in any locale, this hack will fail. 167cdf0e10cSrcweir unsigned int nModMask = ([pEvent modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)); 168cdf0e10cSrcweir if( nModMask == NSCommandKeyMask ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir 171cdf0e10cSrcweir if( [[pEvent charactersIgnoringModifiers] isEqualToString: @"v"] ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir if( [NSApp sendAction: @selector(paste:) to: nil from: nil] ) 174cdf0e10cSrcweir return; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir else if( [[pEvent charactersIgnoringModifiers] isEqualToString: @"c"] ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir if( [NSApp sendAction: @selector(copy:) to: nil from: nil] ) 179cdf0e10cSrcweir return; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir else if( [[pEvent charactersIgnoringModifiers] isEqualToString: @"x"] ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir if( [NSApp sendAction: @selector(cut:) to: nil from: nil] ) 184cdf0e10cSrcweir return; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir else if( eType == NSScrollWheel && ( GetSalData()->mnSystemVersion < VER_LEOPARD /* fixed in Leopard and above */ ) ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir 192cdf0e10cSrcweir NSWindow* pWin = [pEvent window]; 193cdf0e10cSrcweir // on Tiger wheel events do not reach non key windows 194cdf0e10cSrcweir // which probably should be considered a bug 195cdf0e10cSrcweir if( [pWin isKindOfClass: [SalFrameWindow class]] && [pWin canBecomeKeyWindow] == NO ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir [[pWin contentView] scrollWheel: pEvent]; 198cdf0e10cSrcweir return; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir } 201cdf0e10cSrcweir [super sendEvent: pEvent]; 202cdf0e10cSrcweir} 203cdf0e10cSrcweir 204cdf0e10cSrcweir-(void)sendSuperEvent:(NSEvent*)pEvent 205cdf0e10cSrcweir{ 206cdf0e10cSrcweir [super sendEvent: pEvent]; 207cdf0e10cSrcweir} 208cdf0e10cSrcweir 209cdf0e10cSrcweir-(void)cycleFrameForward: (AquaSalFrame*)pCurFrame 210cdf0e10cSrcweir{ 211cdf0e10cSrcweir // find current frame in list 212cdf0e10cSrcweir std::list< AquaSalFrame* >& rFrames( GetSalData()->maFrames ); 213cdf0e10cSrcweir std::list< AquaSalFrame* >::iterator it = rFrames.begin(); 214cdf0e10cSrcweir for( ; it != rFrames.end() && *it != pCurFrame; ++it ) 215cdf0e10cSrcweir ; 216cdf0e10cSrcweir if( it != rFrames.end() ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir // now find the next frame (or end) 219cdf0e10cSrcweir do 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ++it; 222cdf0e10cSrcweir if( it != rFrames.end() ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir if( (*it)->mpDockMenuEntry != NULL && 225cdf0e10cSrcweir (*it)->mbShown ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir [(*it)->getWindow() makeKeyAndOrderFront: NSApp]; 228cdf0e10cSrcweir return; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } while( it != rFrames.end() ); 232cdf0e10cSrcweir // cycle around, find the next up to pCurFrame 233cdf0e10cSrcweir it = rFrames.begin(); 234cdf0e10cSrcweir while( *it != pCurFrame ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir if( (*it)->mpDockMenuEntry != NULL && 237cdf0e10cSrcweir (*it)->mbShown ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir [(*it)->getWindow() makeKeyAndOrderFront: NSApp]; 240cdf0e10cSrcweir return; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir ++it; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir} 246cdf0e10cSrcweir 247cdf0e10cSrcweir-(void)cycleFrameBackward: (AquaSalFrame*)pCurFrame 248cdf0e10cSrcweir{ 249cdf0e10cSrcweir // do the same as cycleFrameForward only with a reverse iterator 250cdf0e10cSrcweir 251cdf0e10cSrcweir // find current frame in list 252cdf0e10cSrcweir std::list< AquaSalFrame* >& rFrames( GetSalData()->maFrames ); 253cdf0e10cSrcweir std::list< AquaSalFrame* >::reverse_iterator it = rFrames.rbegin(); 254cdf0e10cSrcweir for( ; it != rFrames.rend() && *it != pCurFrame; ++it ) 255cdf0e10cSrcweir ; 256cdf0e10cSrcweir if( it != rFrames.rend() ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir // now find the next frame (or end) 259cdf0e10cSrcweir do 260cdf0e10cSrcweir { 261cdf0e10cSrcweir ++it; 262cdf0e10cSrcweir if( it != rFrames.rend() ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir if( (*it)->mpDockMenuEntry != NULL && 265cdf0e10cSrcweir (*it)->mbShown ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir [(*it)->getWindow() makeKeyAndOrderFront: NSApp]; 268cdf0e10cSrcweir return; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir } 271cdf0e10cSrcweir } while( it != rFrames.rend() ); 272cdf0e10cSrcweir // cycle around, find the next up to pCurFrame 273cdf0e10cSrcweir it = rFrames.rbegin(); 274cdf0e10cSrcweir while( *it != pCurFrame ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir if( (*it)->mpDockMenuEntry != NULL && 277cdf0e10cSrcweir (*it)->mbShown ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir [(*it)->getWindow() makeKeyAndOrderFront: NSApp]; 280cdf0e10cSrcweir return; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir ++it; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir } 285cdf0e10cSrcweir} 286cdf0e10cSrcweir 287cdf0e10cSrcweir-(NSMenu*)applicationDockMenu:(NSApplication *)sender 288cdf0e10cSrcweir{ 289cdf0e10cSrcweir (void)sender; 290cdf0e10cSrcweir return AquaSalInstance::GetDynamicDockMenu(); 291cdf0e10cSrcweir} 292cdf0e10cSrcweir 293cdf0e10cSrcweir-(BOOL)application: (NSApplication*)app openFile: (NSString*)pFile 294cdf0e10cSrcweir{ 295cdf0e10cSrcweir (void)app; 296cdf0e10cSrcweir const rtl::OUString aFile( GetOUString( pFile ) ); 297cdf0e10cSrcweir if( ! AquaSalInstance::isOnCommandLine( aFile ) ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir const ApplicationEvent* pAppEvent = new ApplicationEvent( String(), ApplicationAddress(), 300cdf0e10cSrcweir APPEVENT_OPEN_STRING, aFile ); 301cdf0e10cSrcweir AquaSalInstance::aAppEventList.push_back( pAppEvent ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir return YES; 304cdf0e10cSrcweir} 305cdf0e10cSrcweir 306cdf0e10cSrcweir-(void)application: (NSApplication*) app openFiles: (NSArray*)files 307cdf0e10cSrcweir{ 308cdf0e10cSrcweir (void)app; 309cdf0e10cSrcweir rtl::OUStringBuffer aFileList( 256 ); 310cdf0e10cSrcweir 311cdf0e10cSrcweir NSEnumerator* it = [files objectEnumerator]; 312cdf0e10cSrcweir NSString* pFile = nil; 313cdf0e10cSrcweir 314cdf0e10cSrcweir while( (pFile = [it nextObject]) != nil ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir const rtl::OUString aFile( GetOUString( pFile ) ); 317cdf0e10cSrcweir if( ! AquaSalInstance::isOnCommandLine( aFile ) ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir if( aFileList.getLength() > 0 ) 320cdf0e10cSrcweir aFileList.append( sal_Unicode( APPEVENT_PARAM_DELIMITER ) ); 321cdf0e10cSrcweir aFileList.append( aFile ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir if( aFileList.getLength() ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir // we have no back channel here, we have to assume success, in which case 328cdf0e10cSrcweir // replyToOpenOrPrint does not need to be called according to documentation 329cdf0e10cSrcweir // [app replyToOpenOrPrint: NSApplicationDelegateReplySuccess]; 330cdf0e10cSrcweir const ApplicationEvent* pAppEvent = new ApplicationEvent( String(), ApplicationAddress(), 331cdf0e10cSrcweir APPEVENT_OPEN_STRING, aFileList.makeStringAndClear() ); 332cdf0e10cSrcweir AquaSalInstance::aAppEventList.push_back( pAppEvent ); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir} 335cdf0e10cSrcweir 336cdf0e10cSrcweir-(BOOL)application: (NSApplication*)app printFile: (NSString*)pFile 337cdf0e10cSrcweir{ 338cdf0e10cSrcweir (void)app; 339cdf0e10cSrcweir const rtl::OUString aFile( GetOUString( pFile ) ); 340cdf0e10cSrcweir const ApplicationEvent* pAppEvent = new ApplicationEvent( String(), ApplicationAddress(), 341cdf0e10cSrcweir APPEVENT_PRINT_STRING, aFile ); 342cdf0e10cSrcweir AquaSalInstance::aAppEventList.push_back( pAppEvent ); 343cdf0e10cSrcweir return YES; 344cdf0e10cSrcweir} 345cdf0e10cSrcweir-(NSApplicationPrintReply)application: (NSApplication *) app printFiles:(NSArray *)files withSettings: (NSDictionary *)printSettings showPrintPanels:(BOOL)bShowPrintPanels 346cdf0e10cSrcweir{ 347cdf0e10cSrcweir (void)app; 348cdf0e10cSrcweir (void)printSettings; 349cdf0e10cSrcweir (void)bShowPrintPanels; 350cdf0e10cSrcweir // currently ignores print settings an bShowPrintPanels 351cdf0e10cSrcweir rtl::OUStringBuffer aFileList( 256 ); 352cdf0e10cSrcweir 353cdf0e10cSrcweir NSEnumerator* it = [files objectEnumerator]; 354cdf0e10cSrcweir NSString* pFile = nil; 355cdf0e10cSrcweir 356cdf0e10cSrcweir while( (pFile = [it nextObject]) != nil ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir if( aFileList.getLength() > 0 ) 359cdf0e10cSrcweir aFileList.append( sal_Unicode( APPEVENT_PARAM_DELIMITER ) ); 360cdf0e10cSrcweir aFileList.append( GetOUString( pFile ) ); 361cdf0e10cSrcweir } 362cdf0e10cSrcweir const ApplicationEvent* pAppEvent = new ApplicationEvent( String(), ApplicationAddress(), 363cdf0e10cSrcweir APPEVENT_PRINT_STRING, aFileList.makeStringAndClear() ); 364cdf0e10cSrcweir AquaSalInstance::aAppEventList.push_back( pAppEvent ); 365cdf0e10cSrcweir // we have no back channel here, we have to assume success 366cdf0e10cSrcweir // correct handling would be NSPrintingReplyLater and then send [app replyToOpenOrPrint] 367cdf0e10cSrcweir return NSPrintingSuccess; 368cdf0e10cSrcweir} 369cdf0e10cSrcweir 370cdf0e10cSrcweir-(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication *) app 371cdf0e10cSrcweir{ 372cdf0e10cSrcweir (void)app; 373cdf0e10cSrcweir NSApplicationTerminateReply aReply = NSTerminateNow; 374cdf0e10cSrcweir { 375cdf0e10cSrcweir YIELD_GUARD; 376cdf0e10cSrcweir 377cdf0e10cSrcweir SalData* pSalData = GetSalData(); 378cdf0e10cSrcweir if( ! pSalData->maFrames.empty() ) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir // the following QueryExit will likely present a message box, activate application 381cdf0e10cSrcweir [NSApp activateIgnoringOtherApps: YES]; 382cdf0e10cSrcweir aReply = pSalData->maFrames.front()->CallCallback( SALEVENT_SHUTDOWN, NULL ) ? NSTerminateCancel : NSTerminateNow; 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir if( aReply == NSTerminateNow ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir ApplicationEvent aEv( String(), ApplicationAddress(), ByteString( "PRIVATE:DOSHUTDOWN" ), String() ); 388cdf0e10cSrcweir GetpApp()->AppEvent( aEv ); 389cdf0e10cSrcweir ImplImageTreeSingletonRef()->shutDown(); 390cdf0e10cSrcweir // DeInitVCL should be called in ImplSVMain - unless someon _exits first which 391cdf0e10cSrcweir // can occur in Desktop::doShutdown for example 392cdf0e10cSrcweir } 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir return aReply; 396cdf0e10cSrcweir} 397cdf0e10cSrcweir 398cdf0e10cSrcweir-(void)systemColorsChanged: (NSNotification*) pNotification 399cdf0e10cSrcweir{ 400cdf0e10cSrcweir (void)pNotification; 401cdf0e10cSrcweir YIELD_GUARD; 402cdf0e10cSrcweir 403cdf0e10cSrcweir const SalData* pSalData = GetSalData(); 404cdf0e10cSrcweir if( !pSalData->maFrames.empty() ) 405cdf0e10cSrcweir pSalData->maFrames.front()->CallCallback( SALEVENT_SETTINGSCHANGED, NULL ); 406cdf0e10cSrcweir} 407cdf0e10cSrcweir 408cdf0e10cSrcweir-(void)screenParametersChanged: (NSNotification*) pNotification 409cdf0e10cSrcweir{ 410cdf0e10cSrcweir (void)pNotification; 411cdf0e10cSrcweir YIELD_GUARD; 412cdf0e10cSrcweir 413cdf0e10cSrcweir SalData* pSalData = GetSalData(); 414cdf0e10cSrcweir std::list< AquaSalFrame* >::iterator it; 415cdf0e10cSrcweir for( it = pSalData->maFrames.begin(); it != pSalData->maFrames.end(); ++it ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir (*it)->screenParametersChanged(); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir} 420cdf0e10cSrcweir 421cdf0e10cSrcweir-(void)scrollbarVariantChanged: (NSNotification*) pNotification 422cdf0e10cSrcweir{ 423cdf0e10cSrcweir (void)pNotification; 424cdf0e10cSrcweir GetSalData()->mpFirstInstance->delayedSettingsChanged( true ); 425cdf0e10cSrcweir} 426cdf0e10cSrcweir 427cdf0e10cSrcweir-(void)scrollbarSettingsChanged: (NSNotification*) pNotification 428cdf0e10cSrcweir{ 429cdf0e10cSrcweir (void)pNotification; 430cdf0e10cSrcweir GetSalData()->mpFirstInstance->delayedSettingsChanged( false ); 431cdf0e10cSrcweir} 432cdf0e10cSrcweir 433cdf0e10cSrcweir-(void)addFallbackMenuItem: (NSMenuItem*)pNewItem 434cdf0e10cSrcweir{ 435cdf0e10cSrcweir AquaSalMenu::addFallbackMenuItem( pNewItem ); 436cdf0e10cSrcweir} 437cdf0e10cSrcweir 438cdf0e10cSrcweir-(void)removeFallbackMenuItem: (NSMenuItem*)pItem 439cdf0e10cSrcweir{ 440cdf0e10cSrcweir AquaSalMenu::removeFallbackMenuItem( pItem ); 441cdf0e10cSrcweir} 442cdf0e10cSrcweir 443cdf0e10cSrcweir-(void)addDockMenuItem: (NSMenuItem*)pNewItem 444cdf0e10cSrcweir{ 445cdf0e10cSrcweir NSMenu* pDock = AquaSalInstance::GetDynamicDockMenu(); 446cdf0e10cSrcweir [pDock insertItem: pNewItem atIndex: [pDock numberOfItems]]; 447cdf0e10cSrcweir} 448cdf0e10cSrcweir 449cdf0e10cSrcweir// for Apple Remote implementation 450cdf0e10cSrcweir 451cdf0e10cSrcweir#pragma mark - 452cdf0e10cSrcweir#pragma mark NSApplication Delegates 453cdf0e10cSrcweir- (void)applicationWillBecomeActive:(NSNotification *)pNotification 454cdf0e10cSrcweir{ 455cdf0e10cSrcweir (void)pNotification; 456*ff005604SEike Rathke SalData* pSalData = GetSalData(); 457*ff005604SEike Rathke if (pSalData->mpMainController->remoteControl) 458*ff005604SEike Rathke { 459cdf0e10cSrcweir // [remoteControl startListening: self]; 460cdf0e10cSrcweir // does crash because the right thing to do is 461cdf0e10cSrcweir // [GetSalData()->mpMainController->remoteControl startListening: self]; 462cdf0e10cSrcweir // but the instance variable 'remoteControl' is declared protected 463cdf0e10cSrcweir // workaround : declare remoteControl instance variable as public in RemoteMainController.m 464cdf0e10cSrcweir 465*ff005604SEike Rathke [pSalData->mpMainController->remoteControl startListening: self]; 466cdf0e10cSrcweir#ifdef DEBUG 467cdf0e10cSrcweir NSLog(@"Apple Remote will become active - Using remote controls"); 468cdf0e10cSrcweir#endif 469cdf0e10cSrcweir } 470*ff005604SEike Rathke for( std::list< AquaSalFrame* >::const_iterator it = pSalData->maPresentationFrames.begin(); 471*ff005604SEike Rathke it != pSalData->maPresentationFrames.end(); ++it ) 472*ff005604SEike Rathke { 473*ff005604SEike Rathke [(*it)->mpWindow setLevel: NSPopUpMenuWindowLevel]; 474*ff005604SEike Rathke if( [(*it)->mpWindow isVisible] ) 475*ff005604SEike Rathke [(*it)->mpWindow orderFront: NSApp]; 476*ff005604SEike Rathke } 477cdf0e10cSrcweir} 478cdf0e10cSrcweir 479cdf0e10cSrcweir- (void)applicationWillResignActive:(NSNotification *)pNotification 480cdf0e10cSrcweir{ 481cdf0e10cSrcweir (void)pNotification; 482*ff005604SEike Rathke SalData* pSalData = GetSalData(); 483*ff005604SEike Rathke if (pSalData->mpMainController->remoteControl) 484*ff005604SEike Rathke { 485cdf0e10cSrcweir // [remoteControl stopListening: self]; 486cdf0e10cSrcweir // does crash because the right thing to do is 487cdf0e10cSrcweir // [GetSalData()->mpMainController->remoteControl stopListening: self]; 488cdf0e10cSrcweir // but the instance variable 'remoteControl' is declared protected 489cdf0e10cSrcweir // workaround : declare remoteControl instance variable as public in RemoteMainController.m 490cdf0e10cSrcweir 491*ff005604SEike Rathke [pSalData->mpMainController->remoteControl stopListening: self]; 492cdf0e10cSrcweir#ifdef DEBUG 493cdf0e10cSrcweir NSLog(@"Apple Remote will resign active - Releasing remote controls"); 494cdf0e10cSrcweir#endif 495cdf0e10cSrcweir } 496*ff005604SEike Rathke for( std::list< AquaSalFrame* >::const_iterator it = pSalData->maPresentationFrames.begin(); 497*ff005604SEike Rathke it != pSalData->maPresentationFrames.end(); ++it ) 498*ff005604SEike Rathke { 499*ff005604SEike Rathke [(*it)->mpWindow setLevel: NSNormalWindowLevel]; 500*ff005604SEike Rathke } 501cdf0e10cSrcweir} 502cdf0e10cSrcweir 503cdf0e10cSrcweir- (BOOL)applicationShouldHandleReopen: (NSApplication*)pApp hasVisibleWindows: (BOOL) bWinVisible 504cdf0e10cSrcweir{ 505cdf0e10cSrcweir (void)pApp; 506cdf0e10cSrcweir (void)bWinVisible; 507cdf0e10cSrcweir NSObject* pHdl = GetSalData()->mpDockIconClickHandler; 508cdf0e10cSrcweir if( pHdl && [pHdl respondsToSelector: @selector(dockIconClicked:)] ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir [pHdl performSelector:@selector(dockIconClicked:) withObject: self]; 511cdf0e10cSrcweir } 512cdf0e10cSrcweir return YES; 513cdf0e10cSrcweir} 514cdf0e10cSrcweir 515cdf0e10cSrcweir-(void)setDockIconClickHandler: (NSObject*)pHandler 516cdf0e10cSrcweir{ 517cdf0e10cSrcweir GetSalData()->mpDockIconClickHandler = pHandler; 518cdf0e10cSrcweir} 519cdf0e10cSrcweir 520cdf0e10cSrcweir 521cdf0e10cSrcweir@end 522cdf0e10cSrcweir 523