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