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