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