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// MARKER(update_precomp.py): autogen include statement, do not remove
24cdf0e10cSrcweir#include "precompiled_vcl.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir#include <sal/alloca.h>
27cdf0e10cSrcweir
28cdf0e10cSrcweir#include "vcl/window.hxx"
29cdf0e10cSrcweir#include "vcl/svapp.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir#include "aqua/salinst.h"
32cdf0e10cSrcweir#include "aqua/salgdi.h"
33cdf0e10cSrcweir#include "aqua/salframe.h"
34cdf0e10cSrcweir#include "aqua/salframeview.h"
35cdf0e10cSrcweir#include "aqua/aqua11yfactory.h"
36cdf0e10cSrcweir
37cdf0e10cSrcweir#define WHEEL_EVENT_FACTOR 1.5
38cdf0e10cSrcweir
39b9aaf9d4SHerbert Dürr
40cdf0e10cSrcweirstatic sal_uInt16 ImplGetModifierMask( unsigned int nMask )
41cdf0e10cSrcweir{
42cdf0e10cSrcweir    sal_uInt16 nRet = 0;
43cdf0e10cSrcweir    if( (nMask & NSShiftKeyMask) != 0 )
44cdf0e10cSrcweir        nRet |= KEY_SHIFT;
45cdf0e10cSrcweir    if( (nMask & NSControlKeyMask) != 0 )
46cdf0e10cSrcweir        nRet |= KEY_MOD3;
47cdf0e10cSrcweir    if( (nMask & NSAlternateKeyMask) != 0 )
48cdf0e10cSrcweir        nRet |= KEY_MOD2;
49cdf0e10cSrcweir    if( (nMask & NSCommandKeyMask) != 0 )
50cdf0e10cSrcweir        nRet |= KEY_MOD1;
51cdf0e10cSrcweir    return nRet;
52cdf0e10cSrcweir}
53cdf0e10cSrcweir
54cdf0e10cSrcweirstatic sal_uInt16 ImplMapCharCode( sal_Unicode aCode )
55cdf0e10cSrcweir{
56cdf0e10cSrcweir    static sal_uInt16 aKeyCodeMap[ 128 ] =
57cdf0e10cSrcweir    {
58cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
59cdf0e10cSrcweir        KEY_BACKSPACE, KEY_TAB, KEY_RETURN, 0, 0, KEY_RETURN, 0, 0,
60cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
61cdf0e10cSrcweir        0, KEY_TAB, 0, KEY_ESCAPE, 0, 0, 0, 0,
62cdf0e10cSrcweir        KEY_SPACE, 0, 0, 0, 0, 0, 0, 0,
63cdf0e10cSrcweir        0, 0, KEY_MULTIPLY, KEY_ADD, KEY_COMMA, KEY_SUBTRACT, KEY_POINT, KEY_DIVIDE,
64cdf0e10cSrcweir        KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7,
65cdf0e10cSrcweir        KEY_8, KEY_9, 0, 0, KEY_LESS, KEY_EQUAL, KEY_GREATER, 0,
66cdf0e10cSrcweir        0, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
67cdf0e10cSrcweir        KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
68cdf0e10cSrcweir        KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W,
69cdf0e10cSrcweir        KEY_X, KEY_Y, KEY_Z, 0, 0, 0, 0, 0,
70cdf0e10cSrcweir        KEY_QUOTELEFT, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
71cdf0e10cSrcweir        KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
72cdf0e10cSrcweir        KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W,
73cdf0e10cSrcweir        KEY_X, KEY_Y, KEY_Z, 0, 0, 0, KEY_TILDE, KEY_BACKSPACE
74cdf0e10cSrcweir    };
75*d9d2cc80SHerbert Dürr
76cdf0e10cSrcweir    // Note: the mapping 0x7f should by rights be KEY_DELETE
77cdf0e10cSrcweir    // however if you press "backspace" 0x7f is reported
78cdf0e10cSrcweir    // whereas for "delete" 0xf728 gets reported
79*d9d2cc80SHerbert Dürr
80cdf0e10cSrcweir    // Note: the mapping of 0x19 to KEY_TAB is because for unknown reasons
81cdf0e10cSrcweir    // tab alone is reported as 0x09 (as expected) but shift-tab is
82cdf0e10cSrcweir    // reported as 0x19 (end of medium)
83*d9d2cc80SHerbert Dürr
84cdf0e10cSrcweir    static sal_uInt16 aFunctionKeyCodeMap[ 128 ] =
85cdf0e10cSrcweir    {
86cdf0e10cSrcweir        KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_F1, KEY_F2, KEY_F3, KEY_F4,
87cdf0e10cSrcweir        KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12,
88cdf0e10cSrcweir        KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20,
89cdf0e10cSrcweir        KEY_F21, KEY_F22, KEY_F23, KEY_F24, KEY_F25, KEY_F26, 0, 0,
90cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, KEY_INSERT,
91cdf0e10cSrcweir        KEY_DELETE, KEY_HOME, 0, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN, 0, 0,
92cdf0e10cSrcweir        0, 0, 0, 0, 0, KEY_MENU, 0, 0,
93cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
94cdf0e10cSrcweir        0, 0, 0, KEY_UNDO, KEY_REPEAT, KEY_FIND, KEY_HELP, 0,
95cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
96cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
97cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
98cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
99cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
100cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0,
101cdf0e10cSrcweir        0, 0, 0, 0, 0, 0, 0, 0
102cdf0e10cSrcweir    };
103*d9d2cc80SHerbert Dürr
104cdf0e10cSrcweir    sal_uInt16 nKeyCode = 0;
105cdf0e10cSrcweir    if( aCode < sizeof( aKeyCodeMap) / sizeof( aKeyCodeMap[0] ) )
106cdf0e10cSrcweir        nKeyCode = aKeyCodeMap[ aCode ];
107cdf0e10cSrcweir    else if( aCode >= 0xf700 && aCode < 0xf780 )
108cdf0e10cSrcweir        nKeyCode = aFunctionKeyCodeMap[ aCode - 0xf700 ];
109cdf0e10cSrcweir    return nKeyCode;
110cdf0e10cSrcweir}
111cdf0e10cSrcweir
112cdf0e10cSrcweir// store the frame the mouse last entered
113cdf0e10cSrcweirstatic AquaSalFrame* s_pMouseFrame = NULL;
114cdf0e10cSrcweir// store the last pressed button for enter/exit events
115cdf0e10cSrcweir// which lack that information
116cdf0e10cSrcweirstatic sal_uInt16 s_nLastButton = 0;
117cdf0e10cSrcweir
118cdf0e10cSrcweir// combinations of keys we need to handle ourselves
119cdf0e10cSrcweirstatic const struct ExceptionalKey
120cdf0e10cSrcweir{
121cdf0e10cSrcweir    const sal_uInt16        nKeyCode;
122cdf0e10cSrcweir    const unsigned int  nModifierMask;
123cdf0e10cSrcweir} aExceptionalKeys[] =
124cdf0e10cSrcweir{
125cdf0e10cSrcweir    { KEY_D, NSControlKeyMask | NSShiftKeyMask | NSAlternateKeyMask },
126cdf0e10cSrcweir    { KEY_D, NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask }
127cdf0e10cSrcweir};
128cdf0e10cSrcweir
129cdf0e10cSrcweirstatic AquaSalFrame* getMouseContainerFrame()
130cdf0e10cSrcweir{
1312dae3561SHerbert Dürr    NSInteger nWindows = 0;
132cdf0e10cSrcweir    NSCountWindows( &nWindows );
1332dae3561SHerbert Dürr    NSInteger* pWindows = (NSInteger*)alloca( nWindows * sizeof(NSInteger) );
134cdf0e10cSrcweir    // note: NSWindowList is supposed to be in z-order front to back
135cdf0e10cSrcweir    NSWindowList( nWindows, pWindows );
136cdf0e10cSrcweir    AquaSalFrame* pDispatchFrame = NULL;
137cdf0e10cSrcweir    for(int i = 0; i < nWindows && ! pDispatchFrame; i++ )
138cdf0e10cSrcweir    {
139cdf0e10cSrcweir        NSWindow* pWin = [NSApp windowWithWindowNumber: pWindows[i]];
140cdf0e10cSrcweir        if( pWin && [pWin isMemberOfClass: [SalFrameWindow class]] && [(SalFrameWindow*)pWin containsMouse] )
141cdf0e10cSrcweir            pDispatchFrame = [(SalFrameWindow*)pWin getSalFrame];
142cdf0e10cSrcweir    }
143cdf0e10cSrcweir    return pDispatchFrame;
144cdf0e10cSrcweir}
145cdf0e10cSrcweir
146cdf0e10cSrcweir@implementation SalFrameWindow
147cdf0e10cSrcweir-(id)initWithSalFrame: (AquaSalFrame*)pFrame
148cdf0e10cSrcweir{
149cdf0e10cSrcweir	mDraggingDestinationHandler = nil;
150cdf0e10cSrcweir    mpFrame = pFrame;
151cd426cceSHerbert Dürr    NSRect aRect = NSMakeRect( pFrame->maGeometry.nX, pFrame->maGeometry.nY,
152cd426cceSHerbert Dürr                     pFrame->maGeometry.nWidth, pFrame->maGeometry.nHeight);
153cdf0e10cSrcweir    pFrame->VCLToCocoa( aRect );
154cdf0e10cSrcweir    NSWindow* pNSWindow = [super initWithContentRect: aRect styleMask: mpFrame->getStyleMask() backing: NSBackingStoreBuffered defer: NO ];
155cdf0e10cSrcweir    [pNSWindow useOptimizedDrawing: YES]; // OSX recommendation when there are no overlapping subviews within the receiver
156b9aaf9d4SHerbert Dürr
1576669cefeSHerbert Dürr    // enable OSX>=10.7 fullscreen options if available and useful
158b9aaf9d4SHerbert Dürr    bool bAllowFullScreen = (0 == (mpFrame->mnStyle & (SAL_FRAME_STYLE_DIALOG | SAL_FRAME_STYLE_TOOLTIP | SAL_FRAME_STYLE_SYSTEMCHILD | SAL_FRAME_STYLE_FLOAT | SAL_FRAME_STYLE_TOOLWINDOW | SAL_FRAME_STYLE_INTRO)));
159b9aaf9d4SHerbert Dürr    bAllowFullScreen &= (0 == (~mpFrame->mnStyle & (SAL_FRAME_STYLE_SIZEABLE)));
160b9aaf9d4SHerbert Dürr    bAllowFullScreen &= (mpFrame->mpParent == NULL);
161b9aaf9d4SHerbert Dürr    const SEL setCollectionBehavior = @selector(setCollectionBehavior:);
162b9aaf9d4SHerbert Dürr    if( bAllowFullScreen && [pNSWindow respondsToSelector: setCollectionBehavior])
163b9aaf9d4SHerbert Dürr    {
164c1f635d7SHerbert Dürr        const int bMode= (bAllowFullScreen ? NSWindowCollectionBehaviorFullScreenPrimary : NSWindowCollectionBehaviorFullScreenAuxiliary);
165c1f635d7SHerbert Dürr        [pNSWindow performSelector:setCollectionBehavior withObject:(id)bMode];
166b9aaf9d4SHerbert Dürr    }
167b9aaf9d4SHerbert Dürr
1686669cefeSHerbert Dürr    // disable OSX>=10.7 window restoration until we support it directly
1696669cefeSHerbert Dürr    const SEL setRestorable = @selector(setRestorable:);
1700376cbd9SHerbert Dürr    if( [pNSWindow respondsToSelector: setRestorable]) {
171c1f635d7SHerbert Dürr        [pNSWindow performSelector:setRestorable withObject:(id)NO];
1720376cbd9SHerbert Dürr    }
1736669cefeSHerbert Dürr
174*d9d2cc80SHerbert Dürr    return (SalFrameWindow*)pNSWindow;
175cdf0e10cSrcweir}
176cdf0e10cSrcweir
177cdf0e10cSrcweir-(AquaSalFrame*)getSalFrame
178cdf0e10cSrcweir{
179cdf0e10cSrcweir    return mpFrame;
180cdf0e10cSrcweir}
181cdf0e10cSrcweir
182cdf0e10cSrcweir-(void)displayIfNeeded
183cdf0e10cSrcweir{
184cdf0e10cSrcweir    if( GetSalData() && GetSalData()->mpFirstInstance )
185cdf0e10cSrcweir    {
186cdf0e10cSrcweir        vos::IMutex* pMutex = GetSalData()->mpFirstInstance->GetYieldMutex();
187cdf0e10cSrcweir        if( pMutex )
188cdf0e10cSrcweir        {
189cdf0e10cSrcweir            pMutex->acquire();
190cdf0e10cSrcweir            [super displayIfNeeded];
191cdf0e10cSrcweir            pMutex->release();
192cdf0e10cSrcweir        }
193cdf0e10cSrcweir    }
194cdf0e10cSrcweir}
195cdf0e10cSrcweir
196cdf0e10cSrcweir-(BOOL)containsMouse
197cdf0e10cSrcweir{
198cdf0e10cSrcweir    // is this event actually inside that NSWindow ?
199cdf0e10cSrcweir    NSPoint aPt = [NSEvent mouseLocation];
200cdf0e10cSrcweir    NSRect aFrameRect = [self frame];
201cdf0e10cSrcweir    BOOL bInRect = NSPointInRect( aPt, aFrameRect );
202cdf0e10cSrcweir    return bInRect;
203cdf0e10cSrcweir}
204cdf0e10cSrcweir
205cdf0e10cSrcweir-(BOOL)canBecomeKeyWindow
206cdf0e10cSrcweir{
207cdf0e10cSrcweir    if( (mpFrame->mnStyle &
208cdf0e10cSrcweir            ( SAL_FRAME_STYLE_FLOAT                 |
209cdf0e10cSrcweir              SAL_FRAME_STYLE_TOOLTIP               |
210cdf0e10cSrcweir              SAL_FRAME_STYLE_INTRO
211cdf0e10cSrcweir            )) == 0 )
212cdf0e10cSrcweir        return YES;
213cdf0e10cSrcweir    if( (mpFrame->mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) != 0 )
214cdf0e10cSrcweir        return YES;
215cdf0e10cSrcweir    if( mpFrame->mbFullScreen )
216cdf0e10cSrcweir        return YES;
217cdf0e10cSrcweir    if( (mpFrame->mnStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE) )
218cdf0e10cSrcweir        return YES;
219cdf0e10cSrcweir    return [super canBecomeKeyWindow];
220cdf0e10cSrcweir}
221cdf0e10cSrcweir
222cdf0e10cSrcweir-(void)windowDidBecomeKey: (NSNotification*)pNotification
223cdf0e10cSrcweir{
224cdf0e10cSrcweir    (void)pNotification;
225cdf0e10cSrcweir    YIELD_GUARD;
226cdf0e10cSrcweir
227cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
228cdf0e10cSrcweir    {
229cdf0e10cSrcweir        static const sal_uLong nGuessDocument = SAL_FRAME_STYLE_MOVEABLE|
230cdf0e10cSrcweir                                            SAL_FRAME_STYLE_SIZEABLE|
231cdf0e10cSrcweir                                            SAL_FRAME_STYLE_CLOSEABLE;
232*d9d2cc80SHerbert Dürr
233cdf0e10cSrcweir        if( mpFrame->mpMenu )
234cdf0e10cSrcweir            mpFrame->mpMenu->setMainMenu();
235cdf0e10cSrcweir        else if( ! mpFrame->mpParent &&
236cdf0e10cSrcweir                 ( (mpFrame->mnStyle & nGuessDocument) == nGuessDocument || // set default menu for e.g. help
237cdf0e10cSrcweir                    mpFrame->mbFullScreen ) )                               // ser default menu for e.g. presentation
238cdf0e10cSrcweir        {
239cdf0e10cSrcweir            AquaSalMenu::setDefaultMenu();
240cdf0e10cSrcweir        }
241cdf0e10cSrcweir        #if 0
242cdf0e10cSrcweir        // FIXME: we should disable menus while in modal mode
243cdf0e10cSrcweir        // however from down here there is currently no reliable way to
244cdf0e10cSrcweir        // find out when to do this
245cdf0e10cSrcweir        if( (mpFrame->mpParent && mpFrame->mpParent->GetWindow()->IsInModalMode()) )
246cdf0e10cSrcweir            AquaSalMenu::enableMainMenu( false );
247cdf0e10cSrcweir        #endif
248cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_GETFOCUS, 0 );
249cdf0e10cSrcweir        mpFrame->SendPaintEvent(); // repaint controls as active
250cdf0e10cSrcweir    }
251cdf0e10cSrcweir}
252cdf0e10cSrcweir
253cdf0e10cSrcweir-(void)windowDidResignKey: (NSNotification*)pNotification
254cdf0e10cSrcweir{
255cdf0e10cSrcweir    (void)pNotification;
256cdf0e10cSrcweir    YIELD_GUARD;
257cdf0e10cSrcweir
258cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
259cdf0e10cSrcweir    {
260cdf0e10cSrcweir        mpFrame->CallCallback(SALEVENT_LOSEFOCUS, 0);
261cdf0e10cSrcweir        mpFrame->SendPaintEvent(); // repaint controls as inactive
262cdf0e10cSrcweir    }
263cdf0e10cSrcweir}
264cdf0e10cSrcweir
265cdf0e10cSrcweir-(void)windowDidChangeScreen: (NSNotification*)pNotification
266cdf0e10cSrcweir{
267cdf0e10cSrcweir    (void)pNotification;
268cdf0e10cSrcweir    YIELD_GUARD;
269cdf0e10cSrcweir
270cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
271cdf0e10cSrcweir        mpFrame->screenParametersChanged();
272cdf0e10cSrcweir}
273cdf0e10cSrcweir
274cdf0e10cSrcweir-(void)windowDidMove: (NSNotification*)pNotification
275cdf0e10cSrcweir{
276cdf0e10cSrcweir    (void)pNotification;
277cdf0e10cSrcweir    YIELD_GUARD;
278cdf0e10cSrcweir
279cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
280cdf0e10cSrcweir    {
281cdf0e10cSrcweir        mpFrame->UpdateFrameGeometry();
282cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_MOVE, 0 );
283cdf0e10cSrcweir    }
284cdf0e10cSrcweir}
285cdf0e10cSrcweir
286cdf0e10cSrcweir-(void)windowDidResize: (NSNotification*)pNotification
287cdf0e10cSrcweir{
288cdf0e10cSrcweir    (void)pNotification;
289cdf0e10cSrcweir    YIELD_GUARD;
290cdf0e10cSrcweir
291cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
292cdf0e10cSrcweir    {
293cdf0e10cSrcweir        mpFrame->UpdateFrameGeometry();
294cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_RESIZE, 0 );
295cdf0e10cSrcweir        mpFrame->SendPaintEvent();
296cdf0e10cSrcweir    }
297cdf0e10cSrcweir}
298cdf0e10cSrcweir
299cdf0e10cSrcweir-(void)windowDidMiniaturize: (NSNotification*)pNotification
300cdf0e10cSrcweir{
301cdf0e10cSrcweir    (void)pNotification;
302cdf0e10cSrcweir    YIELD_GUARD;
303cdf0e10cSrcweir
304cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
305cdf0e10cSrcweir    {
306cdf0e10cSrcweir        mpFrame->mbShown = false;
307cdf0e10cSrcweir        mpFrame->UpdateFrameGeometry();
308cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_RESIZE, 0 );
309cdf0e10cSrcweir    }
310cdf0e10cSrcweir}
311cdf0e10cSrcweir
312cdf0e10cSrcweir-(void)windowDidDeminiaturize: (NSNotification*)pNotification
313cdf0e10cSrcweir{
314cdf0e10cSrcweir    (void)pNotification;
315cdf0e10cSrcweir    YIELD_GUARD;
316cdf0e10cSrcweir
317cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
318cdf0e10cSrcweir    {
319cdf0e10cSrcweir        mpFrame->mbShown = true;
320cdf0e10cSrcweir        mpFrame->UpdateFrameGeometry();
321cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_RESIZE, 0 );
322cdf0e10cSrcweir    }
323cdf0e10cSrcweir}
324cdf0e10cSrcweir
325cdf0e10cSrcweir-(BOOL)windowShouldClose: (NSNotification*)pNotification
326cdf0e10cSrcweir{
327cdf0e10cSrcweir    (void)pNotification;
328cdf0e10cSrcweir    YIELD_GUARD;
329cdf0e10cSrcweir
330cdf0e10cSrcweir    BOOL bRet = YES;
331cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
332cdf0e10cSrcweir    {
333cdf0e10cSrcweir        // #i84461# end possible input
334cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 );
335cdf0e10cSrcweir        if( AquaSalFrame::isAlive( mpFrame ) )
336cdf0e10cSrcweir        {
337cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_CLOSE, 0 );
338cdf0e10cSrcweir            bRet = NO; // application will close the window or not, AppKit shouldn't
339cdf0e10cSrcweir        }
340cdf0e10cSrcweir    }
341cdf0e10cSrcweir
342cdf0e10cSrcweir    return bRet;
343cdf0e10cSrcweir}
344cdf0e10cSrcweir
345b9aaf9d4SHerbert Dürr-(void)windowDidEnterFullScreen: (NSNotification*)pNotification
346b9aaf9d4SHerbert Dürr{
347b9aaf9d4SHerbert Dürr    YIELD_GUARD;
348b9aaf9d4SHerbert Dürr
349b9aaf9d4SHerbert Dürr    if( !mpFrame || !AquaSalFrame::isAlive( mpFrame))
350b9aaf9d4SHerbert Dürr        return;
351b9aaf9d4SHerbert Dürr    mpFrame->mbFullScreen = true;
352b9aaf9d4SHerbert Dürr    (void)pNotification;
353b9aaf9d4SHerbert Dürr}
354b9aaf9d4SHerbert Dürr
355b9aaf9d4SHerbert Dürr-(void)windowDidExitFullScreen: (NSNotification*)pNotification
356b9aaf9d4SHerbert Dürr{
357b9aaf9d4SHerbert Dürr    YIELD_GUARD;
358b9aaf9d4SHerbert Dürr
359b9aaf9d4SHerbert Dürr    if( !mpFrame || !AquaSalFrame::isAlive( mpFrame))
360b9aaf9d4SHerbert Dürr        return;
361b9aaf9d4SHerbert Dürr    mpFrame->mbFullScreen = false;
362b9aaf9d4SHerbert Dürr    (void)pNotification;
363b9aaf9d4SHerbert Dürr}
364b9aaf9d4SHerbert Dürr
365cdf0e10cSrcweir-(void)dockMenuItemTriggered: (id)sender
366cdf0e10cSrcweir{
367cdf0e10cSrcweir    (void)sender;
368cdf0e10cSrcweir    YIELD_GUARD;
369cdf0e10cSrcweir
370cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
371cdf0e10cSrcweir        mpFrame->ToTop( SAL_FRAME_TOTOP_RESTOREWHENMIN | SAL_FRAME_TOTOP_GRABFOCUS );
372cdf0e10cSrcweir}
373cdf0e10cSrcweir
374cdf0e10cSrcweir-(::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessibleContext >)accessibleContext
375cdf0e10cSrcweir{
376cdf0e10cSrcweir    return mpFrame -> GetWindow() -> GetAccessible() -> getAccessibleContext();
377cdf0e10cSrcweir}
378cdf0e10cSrcweir
379cdf0e10cSrcweir-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
380cdf0e10cSrcweir{
381cdf0e10cSrcweir  return [mDraggingDestinationHandler draggingEntered: sender];
382cdf0e10cSrcweir}
383cdf0e10cSrcweir
384cdf0e10cSrcweir-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
385cdf0e10cSrcweir{
386cdf0e10cSrcweir  return [mDraggingDestinationHandler draggingUpdated: sender];
387cdf0e10cSrcweir}
388cdf0e10cSrcweir
389cdf0e10cSrcweir-(void)draggingExited:(id <NSDraggingInfo>)sender
390cdf0e10cSrcweir{
391cdf0e10cSrcweir  [mDraggingDestinationHandler draggingExited: sender];
392cdf0e10cSrcweir}
393cdf0e10cSrcweir
394cdf0e10cSrcweir-(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
395cdf0e10cSrcweir{
396cdf0e10cSrcweir  return [mDraggingDestinationHandler prepareForDragOperation: sender];
397cdf0e10cSrcweir}
398cdf0e10cSrcweir
399cdf0e10cSrcweir-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
400cdf0e10cSrcweir{
401cdf0e10cSrcweir  return [mDraggingDestinationHandler performDragOperation: sender];
402cdf0e10cSrcweir}
403cdf0e10cSrcweir
404cdf0e10cSrcweir-(void)concludeDragOperation:(id <NSDraggingInfo>)sender
405cdf0e10cSrcweir{
406cdf0e10cSrcweir  [mDraggingDestinationHandler concludeDragOperation: sender];
407cdf0e10cSrcweir}
408cdf0e10cSrcweir
409cdf0e10cSrcweir-(void)registerDraggingDestinationHandler:(id)theHandler
410cdf0e10cSrcweir{
411cdf0e10cSrcweir  mDraggingDestinationHandler = theHandler;
412cdf0e10cSrcweir}
413cdf0e10cSrcweir
414cdf0e10cSrcweir-(void)unregisterDraggingDestinationHandler:(id)theHandler
415cdf0e10cSrcweir{
416cdf0e10cSrcweir    (void)theHandler;
417cdf0e10cSrcweir    mDraggingDestinationHandler = nil;
418cdf0e10cSrcweir}
419cdf0e10cSrcweir
420cdf0e10cSrcweir@end
421cdf0e10cSrcweir
422cdf0e10cSrcweir@implementation SalFrameView
423cdf0e10cSrcweir+(void)unsetMouseFrame: (AquaSalFrame*)pFrame
424cdf0e10cSrcweir{
425cdf0e10cSrcweir    if( pFrame == s_pMouseFrame )
426cdf0e10cSrcweir        s_pMouseFrame = NULL;
427cdf0e10cSrcweir}
428cdf0e10cSrcweir
429cdf0e10cSrcweir-(id)initWithSalFrame: (AquaSalFrame*)pFrame
430cdf0e10cSrcweir{
431bde8a4bdSHerbert Dürr    if ((self = [super initWithFrame: [NSWindow contentRectForFrameRect: [pFrame->getNSWindow() frame] styleMask: pFrame->mnStyleMask]]) != nil)
432cdf0e10cSrcweir    {
433cdf0e10cSrcweir        mDraggingDestinationHandler = nil;
434cdf0e10cSrcweir        mpFrame = pFrame;
435cdf0e10cSrcweir        mMarkedRange = NSMakeRange(NSNotFound, 0);
436cdf0e10cSrcweir        mSelectedRange = NSMakeRange(NSNotFound, 0);
437cdf0e10cSrcweir        mpReferenceWrapper = nil;
438cdf0e10cSrcweir		mpMouseEventListener = nil;
439cdf0e10cSrcweir        mpLastSuperEvent = nil;
440cdf0e10cSrcweir    }
441cdf0e10cSrcweir
442cdf0e10cSrcweir    mfLastMagnifyTime = 0.0;
443cdf0e10cSrcweir    return self;
444cdf0e10cSrcweir}
445cdf0e10cSrcweir
446cdf0e10cSrcweir-(AquaSalFrame*)getSalFrame
447cdf0e10cSrcweir{
448cdf0e10cSrcweir    return mpFrame;
449cdf0e10cSrcweir}
450cdf0e10cSrcweir
451cdf0e10cSrcweir-(void)resetCursorRects
452cdf0e10cSrcweir{
453cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
454cdf0e10cSrcweir    {
455cdf0e10cSrcweir        // FIXME: does this leak the returned NSCursor of getCurrentCursor ?
45601367266SHerbert Dürr        const NSRect aRect = { NSZeroPoint, NSMakeSize( mpFrame->maGeometry.nWidth, mpFrame->maGeometry.nHeight) };
457cdf0e10cSrcweir        [self addCursorRect: aRect cursor: mpFrame->getCurrentCursor()];
458cdf0e10cSrcweir    }
459cdf0e10cSrcweir}
460cdf0e10cSrcweir
461cdf0e10cSrcweir-(BOOL)acceptsFirstResponder
462cdf0e10cSrcweir{
463cdf0e10cSrcweir    return YES;
464cdf0e10cSrcweir}
465cdf0e10cSrcweir
466cdf0e10cSrcweir-(BOOL)acceptsFirstMouse: (NSEvent*)pEvent
467cdf0e10cSrcweir{
468cdf0e10cSrcweir    (void)pEvent;
469cdf0e10cSrcweir    return YES;
470cdf0e10cSrcweir}
471cdf0e10cSrcweir
472cdf0e10cSrcweir-(BOOL)isOpaque
473cdf0e10cSrcweir{
474457e662bSHerbert Dürr	if( !mpFrame)
475457e662bSHerbert Dürr		return YES;
476457e662bSHerbert Dürr	if( !AquaSalFrame::isAlive( mpFrame))
477457e662bSHerbert Dürr		return YES;
478457e662bSHerbert Dürr	if( !mpFrame->getClipPath())
479457e662bSHerbert Dürr		return YES;
480457e662bSHerbert Dürr	return NO;
481cdf0e10cSrcweir}
482cdf0e10cSrcweir
483cdf0e10cSrcweir// helper class similar to a vos::OGuard for the SalYieldMutex
48486e1cf34SPedro Giffuni// the difference is that it only does tryToAcquire instead of acquire
485cdf0e10cSrcweir// so dreaded deadlocks like #i93512# are prevented
486cdf0e10cSrcweirclass TryGuard
487cdf0e10cSrcweir{
488cdf0e10cSrcweirpublic:
489cdf0e10cSrcweir			TryGuard()  { mbGuarded = ImplSalYieldMutexTryToAcquire(); }
490cdf0e10cSrcweir			~TryGuard() { if( mbGuarded ) ImplSalYieldMutexRelease(); }
491cdf0e10cSrcweir	bool	IsGuarded() { return mbGuarded; }
492cdf0e10cSrcweirprivate:
493cdf0e10cSrcweir	bool	mbGuarded;
494cdf0e10cSrcweir};
495cdf0e10cSrcweir
496cdf0e10cSrcweir-(void)drawRect: (NSRect)aRect
497cdf0e10cSrcweir{
498cdf0e10cSrcweir	// HOTFIX: #i93512# prevent deadlocks if any other thread already has the SalYieldMutex
499cdf0e10cSrcweir	TryGuard aTryGuard;
500cdf0e10cSrcweir	if( !aTryGuard.IsGuarded() )
501cdf0e10cSrcweir	{
502cdf0e10cSrcweir		// NOTE: the mpFrame access below is not guarded yet!
503cdf0e10cSrcweir		// TODO: mpFrame et al need to be guarded by an independent mutex
504cdf0e10cSrcweir		AquaSalGraphics* pGraphics = (mpFrame && AquaSalFrame::isAlive(mpFrame)) ? mpFrame->mpGraphics : NULL;
505cdf0e10cSrcweir		if( pGraphics )
506cdf0e10cSrcweir		{
507cdf0e10cSrcweir			// we did not get the mutex so we cannot draw now => request to redraw later
508cdf0e10cSrcweir			// convert the NSRect to a CGRect for Refreshrect()
509cdf0e10cSrcweir			const CGRect aCGRect = {{aRect.origin.x,aRect.origin.y},{aRect.size.width,aRect.size.height}};
510cdf0e10cSrcweir			pGraphics->RefreshRect( aCGRect );
511cdf0e10cSrcweir		}
512cdf0e10cSrcweir		return;
513cdf0e10cSrcweir	}
514cdf0e10cSrcweir
515cdf0e10cSrcweir    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
516cdf0e10cSrcweir    {
517cdf0e10cSrcweir        if( mpFrame->mpGraphics )
518cdf0e10cSrcweir        {
519cdf0e10cSrcweir            mpFrame->mpGraphics->UpdateWindow( aRect );
520cdf0e10cSrcweir            if( mpFrame->getClipPath() )
521bde8a4bdSHerbert Dürr                [mpFrame->getNSWindow() invalidateShadow];
522cdf0e10cSrcweir        }
523cdf0e10cSrcweir    }
524cdf0e10cSrcweir}
525cdf0e10cSrcweir
526cdf0e10cSrcweir-(void)sendMouseEventToFrame: (NSEvent*)pEvent button:(sal_uInt16)nButton eventtype:(sal_uInt16)nEvent
527cdf0e10cSrcweir{
528cdf0e10cSrcweir    YIELD_GUARD;
529cdf0e10cSrcweir
530cdf0e10cSrcweir    AquaSalFrame* pDispatchFrame = AquaSalFrame::GetCaptureFrame();
531cdf0e10cSrcweir    bool bIsCaptured = false;
532cdf0e10cSrcweir    if( pDispatchFrame )
533cdf0e10cSrcweir    {
534cdf0e10cSrcweir        bIsCaptured = true;
535cdf0e10cSrcweir        if( nEvent == SALEVENT_MOUSELEAVE ) // no leave events if mouse is captured
536cdf0e10cSrcweir            nEvent = SALEVENT_MOUSEMOVE;
537cdf0e10cSrcweir    }
538cdf0e10cSrcweir    else if( s_pMouseFrame )
539cdf0e10cSrcweir        pDispatchFrame = s_pMouseFrame;
540cdf0e10cSrcweir    else
541cdf0e10cSrcweir        pDispatchFrame = mpFrame;
542*d9d2cc80SHerbert Dürr
543cdf0e10cSrcweir    /* #i81645# Cocoa reports mouse events while a button is pressed
544cdf0e10cSrcweir       to the window in which it was first pressed. This is reasonable and fine and
545cdf0e10cSrcweir       gets one around most cases where on other platforms one uses CaptureMouse or XGrabPointer,
546cdf0e10cSrcweir       however vcl expects mouse events to occur in the window the mouse is over, unless the
547cdf0e10cSrcweir       mouse is explicitly captured. So we need to find the window the mouse is actually
548cdf0e10cSrcweir       over for conformance with other platforms.
549cdf0e10cSrcweir    */
550cdf0e10cSrcweir    if( ! bIsCaptured && nButton && pDispatchFrame && AquaSalFrame::isAlive( pDispatchFrame ) )
551cdf0e10cSrcweir    {
552cdf0e10cSrcweir        // is this event actually inside that NSWindow ?
553cdf0e10cSrcweir        NSPoint aPt = [NSEvent mouseLocation];
554bde8a4bdSHerbert Dürr        NSRect aFrameRect = [pDispatchFrame->getNSWindow() frame];
555*d9d2cc80SHerbert Dürr
556cdf0e10cSrcweir	if ( ! NSPointInRect( aPt, aFrameRect ) )
557cdf0e10cSrcweir        {
558cdf0e10cSrcweir            // no, it is not
559cdf0e10cSrcweir            // now we need to find the one it may be in
560cdf0e10cSrcweir            /* #i93756# we ant to get enumerate the application windows in z-order
561cdf0e10cSrcweir               to check if any contains the mouse. This could be elegantly done with this
562cdf0e10cSrcweir               code:
563cdf0e10cSrcweir
564cdf0e10cSrcweir               // use NSApp to check windows in ZOrder whether they contain the mouse pointer
565cdf0e10cSrcweir               NSWindow* pWindow = [NSApp makeWindowsPerform: @selector(containsMouse) inOrder: YES];
566cdf0e10cSrcweir               if( pWindow && [pWindow isMemberOfClass: [SalFrameWindow class]] )
567cdf0e10cSrcweir                   pDispatchFrame = [(SalFrameWindow*)pWindow getSalFrame];
568*d9d2cc80SHerbert Dürr
569cdf0e10cSrcweir               However if a non SalFrameWindow is on screen (like e.g. the file dialog)
570cdf0e10cSrcweir               it can be hit with the containsMouse selector, which it doesn't support.
571cdf0e10cSrcweir               Sadly NSApplication:makeWindowsPerform does not check (for performance reasons
572cdf0e10cSrcweir               I assume) whether a window supports a selector before sending it.
573cdf0e10cSrcweir            */
574cdf0e10cSrcweir            AquaSalFrame* pMouseFrame = getMouseContainerFrame();
575cdf0e10cSrcweir            if( pMouseFrame )
576cdf0e10cSrcweir                pDispatchFrame = pMouseFrame;
577cdf0e10cSrcweir        }
578cdf0e10cSrcweir    }
579*d9d2cc80SHerbert Dürr
580cdf0e10cSrcweir    if( pDispatchFrame && AquaSalFrame::isAlive( pDispatchFrame ) )
581cdf0e10cSrcweir    {
582cdf0e10cSrcweir        pDispatchFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 );
583cdf0e10cSrcweir        pDispatchFrame->mnLastModifierFlags = [pEvent modifierFlags];
584cdf0e10cSrcweir
585cdf0e10cSrcweir        NSPoint aPt = [NSEvent mouseLocation];
586cdf0e10cSrcweir        pDispatchFrame->CocoaToVCL( aPt );
587*d9d2cc80SHerbert Dürr
588cdf0e10cSrcweir        sal_uInt16 nModMask = ImplGetModifierMask( [pEvent modifierFlags] );
589cdf0e10cSrcweir        // #i82284# emulate ctrl left
590cdf0e10cSrcweir        if( nModMask == KEY_MOD3 && nButton == MOUSE_LEFT )
591cdf0e10cSrcweir        {
592cdf0e10cSrcweir            nModMask    = 0;
593cdf0e10cSrcweir            nButton     = MOUSE_RIGHT;
594cdf0e10cSrcweir        }
595cdf0e10cSrcweir
596cdf0e10cSrcweir        SalMouseEvent aEvent;
597cdf0e10cSrcweir        aEvent.mnTime   = pDispatchFrame->mnLastEventTime;
598cdf0e10cSrcweir        aEvent.mnX      = static_cast<long>(aPt.x) - pDispatchFrame->maGeometry.nX;
599cdf0e10cSrcweir        aEvent.mnY      = static_cast<long>(aPt.y) - pDispatchFrame->maGeometry.nY;
600cdf0e10cSrcweir        aEvent.mnButton = nButton;
601cdf0e10cSrcweir        aEvent.mnCode   =  aEvent.mnButton | nModMask;
602cdf0e10cSrcweir
603cdf0e10cSrcweir        // --- RTL --- (mirror mouse pos)
604cdf0e10cSrcweir        if( Application::GetSettings().GetLayoutRTL() )
605cdf0e10cSrcweir            aEvent.mnX = pDispatchFrame->maGeometry.nWidth-1-aEvent.mnX;
606*d9d2cc80SHerbert Dürr
607cdf0e10cSrcweir        pDispatchFrame->CallCallback( nEvent, &aEvent );
608cdf0e10cSrcweir    }
609cdf0e10cSrcweir}
610cdf0e10cSrcweir
611cdf0e10cSrcweir-(void)mouseDown: (NSEvent*)pEvent
612cdf0e10cSrcweir{
613cdf0e10cSrcweir    if ( mpMouseEventListener != nil &&
614cdf0e10cSrcweir	    [mpMouseEventListener respondsToSelector: @selector(mouseDown:)])
615cdf0e10cSrcweir	{
616cdf0e10cSrcweir	    [mpMouseEventListener mouseDown: [pEvent copyWithZone: NULL]];
617cdf0e10cSrcweir	}
618cdf0e10cSrcweir
619cdf0e10cSrcweir    s_nLastButton = MOUSE_LEFT;
620cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:MOUSE_LEFT eventtype:SALEVENT_MOUSEBUTTONDOWN];
621cdf0e10cSrcweir}
622cdf0e10cSrcweir
623cdf0e10cSrcweir-(void)mouseDragged: (NSEvent*)pEvent
624cdf0e10cSrcweir{
625cdf0e10cSrcweir    if ( mpMouseEventListener != nil &&
626cdf0e10cSrcweir	     [mpMouseEventListener respondsToSelector: @selector(mouseDragged:)])
627cdf0e10cSrcweir	{
628cdf0e10cSrcweir	    [mpMouseEventListener mouseDragged: [pEvent copyWithZone: NULL]];
629cdf0e10cSrcweir	}
630cdf0e10cSrcweir    s_nLastButton = MOUSE_LEFT;
631cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:MOUSE_LEFT eventtype:SALEVENT_MOUSEMOVE];
632cdf0e10cSrcweir}
633cdf0e10cSrcweir
634cdf0e10cSrcweir-(void)mouseUp: (NSEvent*)pEvent
635cdf0e10cSrcweir{
636cdf0e10cSrcweir    s_nLastButton = 0;
637cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:MOUSE_LEFT eventtype:SALEVENT_MOUSEBUTTONUP];
638cdf0e10cSrcweir}
639cdf0e10cSrcweir
640cdf0e10cSrcweir-(void)mouseMoved: (NSEvent*)pEvent
641cdf0e10cSrcweir{
642cdf0e10cSrcweir    s_nLastButton = 0;
643cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:0 eventtype:SALEVENT_MOUSEMOVE];
644cdf0e10cSrcweir}
645cdf0e10cSrcweir
646cdf0e10cSrcweir-(void)mouseEntered: (NSEvent*)pEvent
647cdf0e10cSrcweir{
648cdf0e10cSrcweir    s_pMouseFrame = mpFrame;
649*d9d2cc80SHerbert Dürr
650cdf0e10cSrcweir    // #i107215# the only mouse events we get when inactive are enter/exit
651cdf0e10cSrcweir    // actually we would like to have all of them, but better none than some
652cdf0e10cSrcweir    if( [NSApp isActive] )
653cdf0e10cSrcweir        [self sendMouseEventToFrame:pEvent button:s_nLastButton eventtype:SALEVENT_MOUSEMOVE];
654cdf0e10cSrcweir}
655cdf0e10cSrcweir
656cdf0e10cSrcweir-(void)mouseExited: (NSEvent*)pEvent
657cdf0e10cSrcweir{
658cdf0e10cSrcweir    if( s_pMouseFrame == mpFrame )
659cdf0e10cSrcweir        s_pMouseFrame = NULL;
660cdf0e10cSrcweir
661cdf0e10cSrcweir    // #i107215# the only mouse events we get when inactive are enter/exit
662cdf0e10cSrcweir    // actually we would like to have all of them, but better none than some
663cdf0e10cSrcweir    if( [NSApp isActive] )
664cdf0e10cSrcweir        [self sendMouseEventToFrame:pEvent button:s_nLastButton eventtype:SALEVENT_MOUSELEAVE];
665cdf0e10cSrcweir}
666cdf0e10cSrcweir
667cdf0e10cSrcweir-(void)rightMouseDown: (NSEvent*)pEvent
668cdf0e10cSrcweir{
669cdf0e10cSrcweir    s_nLastButton = MOUSE_RIGHT;
670cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:MOUSE_RIGHT eventtype:SALEVENT_MOUSEBUTTONDOWN];
671cdf0e10cSrcweir}
672cdf0e10cSrcweir
673cdf0e10cSrcweir-(void)rightMouseDragged: (NSEvent*)pEvent
674cdf0e10cSrcweir{
675cdf0e10cSrcweir    s_nLastButton = MOUSE_RIGHT;
676cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:MOUSE_RIGHT eventtype:SALEVENT_MOUSEMOVE];
677cdf0e10cSrcweir}
678cdf0e10cSrcweir
679cdf0e10cSrcweir-(void)rightMouseUp: (NSEvent*)pEvent
680cdf0e10cSrcweir{
681cdf0e10cSrcweir    s_nLastButton = 0;
682cdf0e10cSrcweir    [self sendMouseEventToFrame:pEvent button:MOUSE_RIGHT eventtype:SALEVENT_MOUSEBUTTONUP];
683cdf0e10cSrcweir}
684cdf0e10cSrcweir
685cdf0e10cSrcweir-(void)otherMouseDown: (NSEvent*)pEvent
686cdf0e10cSrcweir{
687cdf0e10cSrcweir    if( [pEvent buttonNumber] == 2 )
688cdf0e10cSrcweir    {
689cdf0e10cSrcweir        s_nLastButton = MOUSE_MIDDLE;
690cdf0e10cSrcweir        [self sendMouseEventToFrame:pEvent button:MOUSE_MIDDLE eventtype:SALEVENT_MOUSEBUTTONDOWN];
691cdf0e10cSrcweir    }
692cdf0e10cSrcweir    else
693cdf0e10cSrcweir        s_nLastButton = 0;
694cdf0e10cSrcweir}
695cdf0e10cSrcweir
696cdf0e10cSrcweir-(void)otherMouseDragged: (NSEvent*)pEvent
697cdf0e10cSrcweir{
698cdf0e10cSrcweir    if( [pEvent buttonNumber] == 2 )
699cdf0e10cSrcweir    {
700cdf0e10cSrcweir        s_nLastButton = MOUSE_MIDDLE;
701cdf0e10cSrcweir        [self sendMouseEventToFrame:pEvent button:MOUSE_MIDDLE eventtype:SALEVENT_MOUSEMOVE];
702cdf0e10cSrcweir    }
703cdf0e10cSrcweir    else
704cdf0e10cSrcweir        s_nLastButton = 0;
705cdf0e10cSrcweir}
706cdf0e10cSrcweir
707cdf0e10cSrcweir-(void)otherMouseUp: (NSEvent*)pEvent
708cdf0e10cSrcweir{
709cdf0e10cSrcweir    s_nLastButton = 0;
710cdf0e10cSrcweir    if( [pEvent buttonNumber] == 2 )
711cdf0e10cSrcweir        [self sendMouseEventToFrame:pEvent button:MOUSE_MIDDLE eventtype:SALEVENT_MOUSEBUTTONUP];
712cdf0e10cSrcweir}
713cdf0e10cSrcweir
714cdf0e10cSrcweir- (void)magnifyWithEvent: (NSEvent*)pEvent
715cdf0e10cSrcweir{
716cdf0e10cSrcweir    YIELD_GUARD;
717*d9d2cc80SHerbert Dürr
718cdf0e10cSrcweir    // TODO: ??  -(float)magnification;
719cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
720cdf0e10cSrcweir	{
721cdf0e10cSrcweir		const NSTimeInterval fMagnifyTime = [pEvent timestamp];
722cdf0e10cSrcweir        mpFrame->mnLastEventTime = static_cast<sal_uLong>( fMagnifyTime * 1000.0 );
723cdf0e10cSrcweir        mpFrame->mnLastModifierFlags = [pEvent modifierFlags];
724cdf0e10cSrcweir
725cdf0e10cSrcweir        // check if this is a new series of magnify events
726cdf0e10cSrcweir        static const NSTimeInterval fMaxDiffTime = 0.3;
727cdf0e10cSrcweir        const bool bNewSeries = (fMagnifyTime - mfLastMagnifyTime > fMaxDiffTime);
728cdf0e10cSrcweir
729cdf0e10cSrcweir        if( bNewSeries )
730cdf0e10cSrcweir            mfMagnifyDeltaSum = 0.0;
731cdf0e10cSrcweir        mfMagnifyDeltaSum += [pEvent deltaZ];
732cdf0e10cSrcweir
733cdf0e10cSrcweir		mfLastMagnifyTime = [pEvent timestamp];
734cdf0e10cSrcweir		// TODO: change to 0.1 when COMMAND_WHEEL_ZOOM handlers allow finer zooming control
735cdf0e10cSrcweir		static const float fMagnifyFactor = 0.25;
736cdf0e10cSrcweir        static const float fMinMagnifyStep = 15.0 / fMagnifyFactor;
737cdf0e10cSrcweir        if( fabs(mfMagnifyDeltaSum) <= fMinMagnifyStep )
738cdf0e10cSrcweir            return;
739cdf0e10cSrcweir
740cdf0e10cSrcweir        // adapt NSEvent-sensitivity to application expectations
741cdf0e10cSrcweir        // TODO: rather make COMMAND_WHEEL_ZOOM handlers smarter
742cdf0e10cSrcweir        const float fDeltaZ = mfMagnifyDeltaSum * fMagnifyFactor;
743cdf0e10cSrcweir        int nDeltaZ = FRound( fDeltaZ );
744cdf0e10cSrcweir        if( !nDeltaZ )
745cdf0e10cSrcweir        {
746cdf0e10cSrcweir            // handle new series immediately
747cdf0e10cSrcweir            if( !bNewSeries )
748cdf0e10cSrcweir                return;
749cdf0e10cSrcweir            nDeltaZ = (fDeltaZ >= 0.0) ? +1 : -1;
750cdf0e10cSrcweir        }
751cdf0e10cSrcweir        // eventually give credit for delta sum
752cdf0e10cSrcweir        mfMagnifyDeltaSum -= nDeltaZ / fMagnifyFactor;
753cdf0e10cSrcweir
754cdf0e10cSrcweir        NSPoint aPt = [NSEvent mouseLocation];
755cdf0e10cSrcweir        mpFrame->CocoaToVCL( aPt );
756*d9d2cc80SHerbert Dürr
757cdf0e10cSrcweir        SalWheelMouseEvent aEvent;
758cdf0e10cSrcweir        aEvent.mnTime           = mpFrame->mnLastEventTime;
759cdf0e10cSrcweir        aEvent.mnX              = static_cast<long>(aPt.x) - mpFrame->maGeometry.nX;
760cdf0e10cSrcweir        aEvent.mnY              = static_cast<long>(aPt.y) - mpFrame->maGeometry.nY;
761cdf0e10cSrcweir        aEvent.mnCode           = ImplGetModifierMask( mpFrame->mnLastModifierFlags );
762cdf0e10cSrcweir        aEvent.mnCode           |= KEY_MOD1; // we want zooming, no scrolling
763cdf0e10cSrcweir        aEvent.mbDeltaIsPixel   = TRUE;
764*d9d2cc80SHerbert Dürr
765cdf0e10cSrcweir        // --- RTL --- (mirror mouse pos)
766cdf0e10cSrcweir        if( Application::GetSettings().GetLayoutRTL() )
767cdf0e10cSrcweir            aEvent.mnX = mpFrame->maGeometry.nWidth-1-aEvent.mnX;
768*d9d2cc80SHerbert Dürr
769cdf0e10cSrcweir        aEvent.mnDelta = nDeltaZ;
770cdf0e10cSrcweir        aEvent.mnNotchDelta = (nDeltaZ >= 0) ? +1 : -1;
771cdf0e10cSrcweir        if( aEvent.mnDelta == 0 )
772cdf0e10cSrcweir            aEvent.mnDelta = aEvent.mnNotchDelta;
773cdf0e10cSrcweir        aEvent.mbHorz = FALSE;
774cdf0e10cSrcweir        aEvent.mnScrollLines = nDeltaZ;
775cdf0e10cSrcweir        if( aEvent.mnScrollLines == 0 )
776cdf0e10cSrcweir            aEvent.mnScrollLines = 1;
777cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent );
778cdf0e10cSrcweir    }
779cdf0e10cSrcweir}
780cdf0e10cSrcweir
781cdf0e10cSrcweir- (void)rotateWithEvent: (NSEvent*)pEvent
782cdf0e10cSrcweir{
783cdf0e10cSrcweir    //Rotation : -(float)rotation;
784cdf0e10cSrcweir    // TODO: create new CommandType so rotation is available to the applications
785cdf0e10cSrcweir    (void)pEvent;
786cdf0e10cSrcweir}
787cdf0e10cSrcweir
788cdf0e10cSrcweir- (void)swipeWithEvent: (NSEvent*)pEvent
789cdf0e10cSrcweir{
790cdf0e10cSrcweir    YIELD_GUARD;
791*d9d2cc80SHerbert Dürr
792cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
793cdf0e10cSrcweir    {
794cdf0e10cSrcweir        mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 );
795cdf0e10cSrcweir        mpFrame->mnLastModifierFlags = [pEvent modifierFlags];
796*d9d2cc80SHerbert Dürr
797cdf0e10cSrcweir        // merge pending scroll wheel events
79809c47e18SHerbert Dürr        CGFloat dX = 0.0;
79909c47e18SHerbert Dürr        CGFloat dY = 0.0;
800cdf0e10cSrcweir        for(;;)
801cdf0e10cSrcweir        {
802cdf0e10cSrcweir            dX += [pEvent deltaX];
803cdf0e10cSrcweir            dY += [pEvent deltaY];
804cdf0e10cSrcweir            NSEvent* pNextEvent = [NSApp nextEventMatchingMask: NSScrollWheelMask
805cdf0e10cSrcweir            untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ];
806cdf0e10cSrcweir            if( !pNextEvent )
807cdf0e10cSrcweir                break;
808cdf0e10cSrcweir            pEvent = pNextEvent;
809cdf0e10cSrcweir        }
810*d9d2cc80SHerbert Dürr
811cdf0e10cSrcweir        NSPoint aPt = [NSEvent mouseLocation];
812cdf0e10cSrcweir        mpFrame->CocoaToVCL( aPt );
813*d9d2cc80SHerbert Dürr
814cdf0e10cSrcweir        SalWheelMouseEvent aEvent;
815cdf0e10cSrcweir        aEvent.mnTime           = mpFrame->mnLastEventTime;
816cdf0e10cSrcweir        aEvent.mnX              = static_cast<long>(aPt.x) - mpFrame->maGeometry.nX;
817cdf0e10cSrcweir        aEvent.mnY              = static_cast<long>(aPt.y) - mpFrame->maGeometry.nY;
818cdf0e10cSrcweir        aEvent.mnCode           = ImplGetModifierMask( mpFrame->mnLastModifierFlags );
819cdf0e10cSrcweir        aEvent.mbDeltaIsPixel   = TRUE;
820*d9d2cc80SHerbert Dürr
821cdf0e10cSrcweir        // --- RTL --- (mirror mouse pos)
822cdf0e10cSrcweir        if( Application::GetSettings().GetLayoutRTL() )
823cdf0e10cSrcweir            aEvent.mnX = mpFrame->maGeometry.nWidth-1-aEvent.mnX;
824*d9d2cc80SHerbert Dürr
825cdf0e10cSrcweir        if( dX != 0.0 )
826cdf0e10cSrcweir        {
827cdf0e10cSrcweir            aEvent.mnDelta = static_cast<long>(floor(dX));
82809c47e18SHerbert Dürr            aEvent.mnNotchDelta = (dX < 0) ? -1 : +1;
829cdf0e10cSrcweir            if( aEvent.mnDelta == 0 )
830cdf0e10cSrcweir                aEvent.mnDelta = aEvent.mnNotchDelta;
831cdf0e10cSrcweir            aEvent.mbHorz = TRUE;
832cdf0e10cSrcweir            aEvent.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
833cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent );
834cdf0e10cSrcweir        }
835cdf0e10cSrcweir        if( dY != 0.0 && AquaSalFrame::isAlive( mpFrame ))
836cdf0e10cSrcweir        {
837cdf0e10cSrcweir            aEvent.mnDelta = static_cast<long>(floor(dY));
83809c47e18SHerbert Dürr            aEvent.mnNotchDelta = (dY < 0) ? -1 : +1;
839cdf0e10cSrcweir            if( aEvent.mnDelta == 0 )
840cdf0e10cSrcweir                aEvent.mnDelta = aEvent.mnNotchDelta;
841cdf0e10cSrcweir            aEvent.mbHorz = FALSE;
842cdf0e10cSrcweir            aEvent.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
843cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent );
844cdf0e10cSrcweir        }
845cdf0e10cSrcweir    }
846cdf0e10cSrcweir}
847cdf0e10cSrcweir
848cdf0e10cSrcweir-(void)scrollWheel: (NSEvent*)pEvent
849cdf0e10cSrcweir{
850cdf0e10cSrcweir    YIELD_GUARD;
851*d9d2cc80SHerbert Dürr
852cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
853cdf0e10cSrcweir    {
854cdf0e10cSrcweir        mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 );
855cdf0e10cSrcweir        mpFrame->mnLastModifierFlags = [pEvent modifierFlags];
856cdf0e10cSrcweir
857cdf0e10cSrcweir        // merge pending scroll wheel events
85809c47e18SHerbert Dürr        CGFloat dX = 0.0;
85909c47e18SHerbert Dürr        CGFloat dY = 0.0;
860cdf0e10cSrcweir        for(;;)
861cdf0e10cSrcweir        {
862cdf0e10cSrcweir            dX += [pEvent deltaX];
863cdf0e10cSrcweir    	    dY += [pEvent deltaY];
864cdf0e10cSrcweir            NSEvent* pNextEvent = [NSApp nextEventMatchingMask: NSScrollWheelMask
865cdf0e10cSrcweir                untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ];
866cdf0e10cSrcweir            if( !pNextEvent )
867cdf0e10cSrcweir                break;
868cdf0e10cSrcweir            pEvent = pNextEvent;
869cdf0e10cSrcweir        }
870cdf0e10cSrcweir
871cdf0e10cSrcweir        NSPoint aPt = [NSEvent mouseLocation];
872cdf0e10cSrcweir        mpFrame->CocoaToVCL( aPt );
873cdf0e10cSrcweir
874cdf0e10cSrcweir        SalWheelMouseEvent aEvent;
875cdf0e10cSrcweir        aEvent.mnTime         = mpFrame->mnLastEventTime;
876cdf0e10cSrcweir        aEvent.mnX            = static_cast<long>(aPt.x) - mpFrame->maGeometry.nX;
877cdf0e10cSrcweir        aEvent.mnY            = static_cast<long>(aPt.y) - mpFrame->maGeometry.nY;
878cdf0e10cSrcweir        aEvent.mnCode         = ImplGetModifierMask( mpFrame->mnLastModifierFlags );
879cdf0e10cSrcweir        aEvent.mbDeltaIsPixel = TRUE;
880cdf0e10cSrcweir
881cdf0e10cSrcweir        // --- RTL --- (mirror mouse pos)
882cdf0e10cSrcweir        if( Application::GetSettings().GetLayoutRTL() )
883cdf0e10cSrcweir            aEvent.mnX = mpFrame->maGeometry.nWidth-1-aEvent.mnX;
884cdf0e10cSrcweir
885cdf0e10cSrcweir        if( dX != 0.0 )
886cdf0e10cSrcweir        {
887cdf0e10cSrcweir            aEvent.mnDelta = static_cast<long>(floor(dX));
88809c47e18SHerbert Dürr            aEvent.mnNotchDelta = (dX < 0) ? -1 : +1;
889cdf0e10cSrcweir            if( aEvent.mnDelta == 0 )
890cdf0e10cSrcweir                aEvent.mnDelta = aEvent.mnNotchDelta;
891cdf0e10cSrcweir            aEvent.mbHorz = TRUE;
892*d9d2cc80SHerbert Dürr            aEvent.mnScrollLines = fabs(dX) / WHEEL_EVENT_FACTOR;
893cdf0e10cSrcweir            if( aEvent.mnScrollLines == 0 )
894cdf0e10cSrcweir                aEvent.mnScrollLines = 1;
895cdf0e10cSrcweir
896cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent );
897cdf0e10cSrcweir        }
898cdf0e10cSrcweir        if( dY != 0.0 && AquaSalFrame::isAlive( mpFrame ) )
899cdf0e10cSrcweir        {
900cdf0e10cSrcweir            aEvent.mnDelta = static_cast<long>(floor(dY));
90109c47e18SHerbert Dürr            aEvent.mnNotchDelta = (dY < 0) ? -1 : +1;
902cdf0e10cSrcweir            if( aEvent.mnDelta == 0 )
903cdf0e10cSrcweir                aEvent.mnDelta = aEvent.mnNotchDelta;
904cdf0e10cSrcweir            aEvent.mbHorz = FALSE;
905*d9d2cc80SHerbert Dürr            aEvent.mnScrollLines = fabs(dY) / WHEEL_EVENT_FACTOR;
906*d9d2cc80SHerbert Dürr            if( aEvent.mnScrollLines == 0 )
907cdf0e10cSrcweir                aEvent.mnScrollLines = 1;
908cdf0e10cSrcweir
909cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent );
910cdf0e10cSrcweir        }
911cdf0e10cSrcweir    }
912cdf0e10cSrcweir}
913cdf0e10cSrcweir
914cdf0e10cSrcweir
915cdf0e10cSrcweir-(void)keyDown: (NSEvent*)pEvent
916cdf0e10cSrcweir{
917cdf0e10cSrcweir    YIELD_GUARD;
918*d9d2cc80SHerbert Dürr
919cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
920cdf0e10cSrcweir    {
921cdf0e10cSrcweir        mpLastEvent = pEvent;
922cdf0e10cSrcweir        mbInKeyInput = true;
923cdf0e10cSrcweir        mbNeedSpecialKeyHandle = false;
924cdf0e10cSrcweir        mbKeyHandled = false;
925cdf0e10cSrcweir
926cdf0e10cSrcweir        mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 );
927cdf0e10cSrcweir        mpFrame->mnLastModifierFlags = [pEvent modifierFlags];
928*d9d2cc80SHerbert Dürr
929cdf0e10cSrcweir        if( ! [self handleKeyDownException: pEvent] )
930cdf0e10cSrcweir        {
931cdf0e10cSrcweir            NSArray* pArray = [NSArray arrayWithObject: pEvent];
932cdf0e10cSrcweir            [self interpretKeyEvents: pArray];
933cdf0e10cSrcweir        }
934cdf0e10cSrcweir
935cdf0e10cSrcweir        mbInKeyInput = false;
936cdf0e10cSrcweir    }
937cdf0e10cSrcweir}
938cdf0e10cSrcweir
939cdf0e10cSrcweir-(BOOL)handleKeyDownException:(NSEvent*)pEvent
940cdf0e10cSrcweir{
941cdf0e10cSrcweir    // check for a very special set of modified characters
942cdf0e10cSrcweir    NSString* pUnmodifiedString = [pEvent charactersIgnoringModifiers];
943cdf0e10cSrcweir
944cdf0e10cSrcweir    if( pUnmodifiedString && [pUnmodifiedString length] == 1 )
945cdf0e10cSrcweir    {
946cdf0e10cSrcweir        /* #i103102# key events with command and alternate don't make it through
947cdf0e10cSrcweir           interpretKeyEvents (why ?). Try to dispatch them here first,
948cdf0e10cSrcweir           if not successful continue normally
949cdf0e10cSrcweir        */
950cdf0e10cSrcweir        if( (mpFrame->mnLastModifierFlags & (NSAlternateKeyMask | NSCommandKeyMask))
951cdf0e10cSrcweir                    == (NSAlternateKeyMask | NSCommandKeyMask) )
952cdf0e10cSrcweir        {
953cdf0e10cSrcweir            if( [self sendSingleCharacter: mpLastEvent] )
954cdf0e10cSrcweir                return YES;
955cdf0e10cSrcweir        }
956cdf0e10cSrcweir        unichar keyChar = [pUnmodifiedString characterAtIndex: 0];
957cdf0e10cSrcweir        sal_uInt16 nKeyCode = ImplMapCharCode( keyChar );
958*d9d2cc80SHerbert Dürr
959cdf0e10cSrcweir        // Caution: should the table grow to more than 5 or 6 entries,
960cdf0e10cSrcweir        // we must consider moving it to a kind of hash map
961cdf0e10cSrcweir        const unsigned int nExceptions = sizeof( aExceptionalKeys ) / sizeof( aExceptionalKeys[0] );
962cdf0e10cSrcweir        for( unsigned int i = 0; i < nExceptions; i++ )
963cdf0e10cSrcweir        {
964cdf0e10cSrcweir            if( nKeyCode == aExceptionalKeys[i].nKeyCode &&
965cdf0e10cSrcweir                (mpFrame->mnLastModifierFlags & aExceptionalKeys[i].nModifierMask)
966cdf0e10cSrcweir                == aExceptionalKeys[i].nModifierMask )
967cdf0e10cSrcweir            {
968cdf0e10cSrcweir                [self sendKeyInputAndReleaseToFrame: nKeyCode character: 0];
969cdf0e10cSrcweir
970cdf0e10cSrcweir                return YES;
971cdf0e10cSrcweir            }
972cdf0e10cSrcweir        }
973cdf0e10cSrcweir    }
974cdf0e10cSrcweir    return NO;
975cdf0e10cSrcweir}
976cdf0e10cSrcweir
977cdf0e10cSrcweir-(void)flagsChanged: (NSEvent*)pEvent
978cdf0e10cSrcweir{
979cdf0e10cSrcweir    YIELD_GUARD;
980*d9d2cc80SHerbert Dürr
981cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
982cdf0e10cSrcweir    {
983cdf0e10cSrcweir        mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 );
984cdf0e10cSrcweir        mpFrame->mnLastModifierFlags = [pEvent modifierFlags];
985cdf0e10cSrcweir    }
986cdf0e10cSrcweir}
987cdf0e10cSrcweir
988cdf0e10cSrcweir-(void)insertText:(id)aString
989cdf0e10cSrcweir{
990cdf0e10cSrcweir    YIELD_GUARD;
991*d9d2cc80SHerbert Dürr
992cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
993cdf0e10cSrcweir    {
994cdf0e10cSrcweir        NSString* pInsert = nil;
995cdf0e10cSrcweir        if( [aString isMemberOfClass: [NSAttributedString class]] )
996cdf0e10cSrcweir            pInsert = [aString string];
997cdf0e10cSrcweir        else
998cdf0e10cSrcweir            pInsert = aString;
999*d9d2cc80SHerbert Dürr
1000cdf0e10cSrcweir        int nLen = 0;
1001cdf0e10cSrcweir        if( pInsert && ( nLen = [pInsert length] ) > 0 )
1002cdf0e10cSrcweir        {
1003cdf0e10cSrcweir            OUString aInsertString( GetOUString( pInsert ) );
1004cdf0e10cSrcweir             // aCharCode initializer is safe since aInsertString will at least contain '\0'
1005cdf0e10cSrcweir            sal_Unicode aCharCode = *aInsertString.getStr();
1006*d9d2cc80SHerbert Dürr
1007cdf0e10cSrcweir            if( nLen == 1 &&
1008cdf0e10cSrcweir                aCharCode < 0x80 &&
1009cdf0e10cSrcweir                aCharCode > 0x1f &&
1010cdf0e10cSrcweir				! [self hasMarkedText ]
1011cdf0e10cSrcweir                )
1012cdf0e10cSrcweir            {
1013cdf0e10cSrcweir                sal_uInt16 nKeyCode = ImplMapCharCode( aCharCode );
1014cdf0e10cSrcweir                unsigned int nLastModifiers = mpFrame->mnLastModifierFlags;
1015cdf0e10cSrcweir
1016cdf0e10cSrcweir                // #i99567#
1017cdf0e10cSrcweir                // find out the unmodified key code
1018*d9d2cc80SHerbert Dürr
1019cdf0e10cSrcweir                // sanity check
1020cdf0e10cSrcweir                if( mpLastEvent && ( [mpLastEvent type] == NSKeyDown || [mpLastEvent type] == NSKeyUp ) )
1021cdf0e10cSrcweir                {
1022cdf0e10cSrcweir                    // get unmodified string
1023cdf0e10cSrcweir                    NSString* pUnmodifiedString = [mpLastEvent charactersIgnoringModifiers];
1024cdf0e10cSrcweir                    if( pUnmodifiedString && [pUnmodifiedString length] == 1 )
1025cdf0e10cSrcweir                    {
1026cdf0e10cSrcweir                        // map the unmodified key code
1027cdf0e10cSrcweir                        unichar keyChar = [pUnmodifiedString characterAtIndex: 0];
1028cdf0e10cSrcweir                        nKeyCode = ImplMapCharCode( keyChar );
1029cdf0e10cSrcweir                    }
1030cdf0e10cSrcweir                    nLastModifiers = [mpLastEvent modifierFlags];
1031cdf0e10cSrcweir
1032cdf0e10cSrcweir                }
1033cdf0e10cSrcweir                // #i99567#
1034cdf0e10cSrcweir                // applications and vcl's edit fields ignore key events with ALT
1035cdf0e10cSrcweir                // however we're at a place where we know text should be inserted
1036cdf0e10cSrcweir                // so it seems we need to strip the Alt modifier here
1037cdf0e10cSrcweir                if( (nLastModifiers & (NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask))
1038cdf0e10cSrcweir                    == NSAlternateKeyMask )
1039cdf0e10cSrcweir                {
1040cdf0e10cSrcweir                    nLastModifiers = 0;
1041cdf0e10cSrcweir                }
1042cdf0e10cSrcweir                [self sendKeyInputAndReleaseToFrame: nKeyCode character: aCharCode modifiers: nLastModifiers];
1043cdf0e10cSrcweir            }
1044cdf0e10cSrcweir            else
1045cdf0e10cSrcweir            {
1046cdf0e10cSrcweir                SalExtTextInputEvent aEvent;
1047cdf0e10cSrcweir                aEvent.mnTime           = mpFrame->mnLastEventTime;
1048cdf0e10cSrcweir                aEvent.maText           = aInsertString;
1049cdf0e10cSrcweir                aEvent.mpTextAttr       = NULL;
1050cdf0e10cSrcweir                aEvent.mnCursorPos      = aInsertString.getLength();
1051cdf0e10cSrcweir                aEvent.mnDeltaStart     = 0;
1052cdf0e10cSrcweir                aEvent.mnCursorFlags    = 0;
1053cdf0e10cSrcweir                aEvent.mbOnlyCursor     = FALSE;
1054cdf0e10cSrcweir                mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, &aEvent );
1055cdf0e10cSrcweir                if( AquaSalFrame::isAlive( mpFrame ) )
1056cdf0e10cSrcweir                    mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 );
1057cdf0e10cSrcweir            }
1058cdf0e10cSrcweir        }
1059cdf0e10cSrcweir        else
1060cdf0e10cSrcweir        {
1061cdf0e10cSrcweir            SalExtTextInputEvent aEvent;
1062cdf0e10cSrcweir            aEvent.mnTime           = mpFrame->mnLastEventTime;
1063cdf0e10cSrcweir            aEvent.maText           = String();
1064cdf0e10cSrcweir            aEvent.mpTextAttr       = NULL;
1065cdf0e10cSrcweir            aEvent.mnCursorPos      = 0;
1066cdf0e10cSrcweir            aEvent.mnDeltaStart     = 0;
1067cdf0e10cSrcweir            aEvent.mnCursorFlags    = 0;
1068cdf0e10cSrcweir            aEvent.mbOnlyCursor     = FALSE;
1069cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, &aEvent );
1070cdf0e10cSrcweir            if( AquaSalFrame::isAlive( mpFrame ) )
1071cdf0e10cSrcweir                mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 );
1072cdf0e10cSrcweir
1073cdf0e10cSrcweir        }
1074cdf0e10cSrcweir        mbKeyHandled = true;
1075cdf0e10cSrcweir        [self unmarkText];
1076cdf0e10cSrcweir    }
1077cdf0e10cSrcweir}
1078cdf0e10cSrcweir
1079cdf0e10cSrcweir-(void)insertTab: (id)aSender
1080cdf0e10cSrcweir{
1081cdf0e10cSrcweir    (void)aSender;
1082cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_TAB character: '\t' modifiers: 0];
1083cdf0e10cSrcweir}
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir-(void)insertBacktab: (id)aSender
1086cdf0e10cSrcweir{
1087cdf0e10cSrcweir    (void)aSender;
1088cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: (KEY_TAB | KEY_SHIFT) character: '\t' modifiers: 0];
1089cdf0e10cSrcweir}
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir-(void)moveLeft: (id)aSender
1092cdf0e10cSrcweir{
1093cdf0e10cSrcweir    (void)aSender;
1094cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_LEFT character: 0 modifiers: 0];
1095cdf0e10cSrcweir}
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir-(void)moveLeftAndModifySelection: (id)aSender
1098cdf0e10cSrcweir{
1099cdf0e10cSrcweir    (void)aSender;
1100cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_LEFT character: 0 modifiers: NSShiftKeyMask];
1101cdf0e10cSrcweir}
1102cdf0e10cSrcweir
1103cdf0e10cSrcweir-(void)moveBackwardAndModifySelection: (id)aSender
1104cdf0e10cSrcweir{
1105cdf0e10cSrcweir    (void)aSender;
1106cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_BACKWARD character: 0  modifiers: 0];
1107cdf0e10cSrcweir}
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir-(void)moveRight: (id)aSender
1110cdf0e10cSrcweir{
1111cdf0e10cSrcweir    (void)aSender;
1112cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_RIGHT character: 0 modifiers: 0];
1113cdf0e10cSrcweir}
1114cdf0e10cSrcweir
1115cdf0e10cSrcweir-(void)moveRightAndModifySelection: (id)aSender
1116cdf0e10cSrcweir{
1117cdf0e10cSrcweir    (void)aSender;
1118cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_RIGHT character: 0 modifiers: NSShiftKeyMask];
1119cdf0e10cSrcweir}
1120cdf0e10cSrcweir
1121cdf0e10cSrcweir-(void)moveForwardAndModifySelection: (id)aSender
1122cdf0e10cSrcweir{
1123cdf0e10cSrcweir    (void)aSender;
1124cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_FORWARD character: 0  modifiers: 0];
1125cdf0e10cSrcweir}
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir-(void)moveWordLeft: (id)aSender
1128cdf0e10cSrcweir{
1129cdf0e10cSrcweir    (void)aSender;
1130cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_BACKWARD character: 0  modifiers: 0];
1131cdf0e10cSrcweir}
1132cdf0e10cSrcweir
1133cdf0e10cSrcweir-(void)moveWordBackward: (id)aSender
1134cdf0e10cSrcweir{
1135cdf0e10cSrcweir    (void)aSender;
1136cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_BACKWARD character: 0  modifiers: 0];
1137cdf0e10cSrcweir}
1138cdf0e10cSrcweir
1139cdf0e10cSrcweir-(void)moveWordBackwardAndModifySelection: (id)aSender
1140cdf0e10cSrcweir{
1141cdf0e10cSrcweir    (void)aSender;
1142cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_BACKWARD character: 0  modifiers: 0];
1143cdf0e10cSrcweir}
1144cdf0e10cSrcweir
1145cdf0e10cSrcweir-(void)moveWordLeftAndModifySelection: (id)aSender
1146cdf0e10cSrcweir{
1147cdf0e10cSrcweir    (void)aSender;
1148cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_BACKWARD character: 0  modifiers: 0];
1149cdf0e10cSrcweir}
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir-(void)moveWordRight: (id)aSender
1152cdf0e10cSrcweir{
1153cdf0e10cSrcweir    (void)aSender;
1154cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_FORWARD character: 0  modifiers: 0];
1155cdf0e10cSrcweir}
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir-(void)moveWordForward: (id)aSender
1158cdf0e10cSrcweir{
1159cdf0e10cSrcweir    (void)aSender;
1160cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_FORWARD character: 0  modifiers: 0];
1161cdf0e10cSrcweir}
1162cdf0e10cSrcweir
1163cdf0e10cSrcweir-(void)moveWordForwardAndModifySelection: (id)aSender
1164cdf0e10cSrcweir{
1165cdf0e10cSrcweir    (void)aSender;
1166cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_FORWARD character: 0  modifiers: 0];
1167cdf0e10cSrcweir}
1168cdf0e10cSrcweir
1169cdf0e10cSrcweir-(void)moveWordRightAndModifySelection: (id)aSender
1170cdf0e10cSrcweir{
1171cdf0e10cSrcweir    (void)aSender;
1172cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_FORWARD character: 0  modifiers: 0];
1173cdf0e10cSrcweir}
1174cdf0e10cSrcweir
1175cdf0e10cSrcweir-(void)moveToEndOfLine: (id)aSender
1176cdf0e10cSrcweir{
1177cdf0e10cSrcweir    (void)aSender;
1178cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_LINE character: 0  modifiers: 0];
1179cdf0e10cSrcweir}
1180cdf0e10cSrcweir
1181cdf0e10cSrcweir-(void)moveToRightEndOfLine: (id)aSender
1182cdf0e10cSrcweir{
1183cdf0e10cSrcweir    (void)aSender;
1184cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_LINE character: 0  modifiers: 0];
1185cdf0e10cSrcweir}
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir-(void)moveToEndOfLineAndModifySelection: (id)aSender
1188cdf0e10cSrcweir{
1189cdf0e10cSrcweir    (void)aSender;
1190cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_LINE character: 0  modifiers: 0];
1191cdf0e10cSrcweir}
1192cdf0e10cSrcweir
1193cdf0e10cSrcweir-(void)moveToRightEndOfLineAndModifySelection: (id)aSender
1194cdf0e10cSrcweir{
1195cdf0e10cSrcweir    (void)aSender;
1196cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_LINE character: 0  modifiers: 0];
1197cdf0e10cSrcweir}
1198cdf0e10cSrcweir
1199cdf0e10cSrcweir-(void)moveToBeginningOfLine: (id)aSender
1200cdf0e10cSrcweir{
1201cdf0e10cSrcweir    (void)aSender;
1202cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE character: 0  modifiers: 0];
1203cdf0e10cSrcweir}
1204cdf0e10cSrcweir
1205cdf0e10cSrcweir-(void)moveToLeftEndOfLine: (id)aSender
1206cdf0e10cSrcweir{
1207cdf0e10cSrcweir    (void)aSender;
1208cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE character: 0  modifiers: 0];
1209cdf0e10cSrcweir}
1210cdf0e10cSrcweir
1211cdf0e10cSrcweir-(void)moveToBeginningOfLineAndModifySelection: (id)aSender
1212cdf0e10cSrcweir{
1213cdf0e10cSrcweir    (void)aSender;
1214cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE character: 0  modifiers: 0];
1215cdf0e10cSrcweir}
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir-(void)moveToLeftEndOfLineAndModifySelection: (id)aSender
1218cdf0e10cSrcweir{
1219cdf0e10cSrcweir    (void)aSender;
1220cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE character: 0  modifiers: 0];
1221cdf0e10cSrcweir}
1222cdf0e10cSrcweir
1223cdf0e10cSrcweir-(void)moveToEndOfParagraph: (id)aSender
1224cdf0e10cSrcweir{
1225cdf0e10cSrcweir    (void)aSender;
1226cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH character: 0  modifiers: 0];
1227cdf0e10cSrcweir}
1228cdf0e10cSrcweir
1229cdf0e10cSrcweir-(void)moveToEndOfParagraphAndModifySelection: (id)aSender
1230cdf0e10cSrcweir{
1231cdf0e10cSrcweir    (void)aSender;
1232cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH character: 0  modifiers: 0];
1233cdf0e10cSrcweir}
1234cdf0e10cSrcweir
1235cdf0e10cSrcweir-(void)moveParagraphForward: (id)aSender
1236cdf0e10cSrcweir{
1237cdf0e10cSrcweir    (void)aSender;
1238cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH character: 0  modifiers: 0];
1239cdf0e10cSrcweir}
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir-(void)moveParagraphForwardAndModifySelection: (id)aSender
1242cdf0e10cSrcweir{
1243cdf0e10cSrcweir    (void)aSender;
1244cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH character: 0  modifiers: 0];
1245cdf0e10cSrcweir}
1246cdf0e10cSrcweir
1247cdf0e10cSrcweir-(void)moveToBeginningOfParagraph: (id)aSender
1248cdf0e10cSrcweir{
1249cdf0e10cSrcweir    (void)aSender;
1250cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH character: 0  modifiers: 0];
1251cdf0e10cSrcweir}
1252cdf0e10cSrcweir
1253cdf0e10cSrcweir-(void)moveParagraphBackward: (id)aSender
1254cdf0e10cSrcweir{
1255cdf0e10cSrcweir    (void)aSender;
1256cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH character: 0  modifiers: 0];
1257cdf0e10cSrcweir}
1258cdf0e10cSrcweir
1259cdf0e10cSrcweir-(void)moveToBeginningOfParagraphAndModifySelection: (id)aSender
1260cdf0e10cSrcweir{
1261cdf0e10cSrcweir    (void)aSender;
1262cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH character: 0  modifiers: 0];
1263cdf0e10cSrcweir}
1264cdf0e10cSrcweir
1265cdf0e10cSrcweir-(void)moveParagraphBackwardAndModifySelection: (id)aSender
1266cdf0e10cSrcweir{
1267cdf0e10cSrcweir    (void)aSender;
1268cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH character: 0  modifiers: 0];
1269cdf0e10cSrcweir}
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir-(void)moveToEndOfDocument: (id)aSender
1272cdf0e10cSrcweir{
1273cdf0e10cSrcweir    (void)aSender;
1274cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT character: 0  modifiers: 0];
1275cdf0e10cSrcweir}
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir-(void)scrollToEndOfDocument: (id)aSender
1278cdf0e10cSrcweir{
1279cdf0e10cSrcweir    (void)aSender;
1280cdf0e10cSrcweir    // this is not exactly what we should do, but it makes "End" and "Shift-End" behave consistent
1281cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT character: 0  modifiers: 0];
1282cdf0e10cSrcweir}
1283cdf0e10cSrcweir
1284cdf0e10cSrcweir-(void)moveToEndOfDocumentAndModifySelection: (id)aSender
1285cdf0e10cSrcweir{
1286cdf0e10cSrcweir    (void)aSender;
1287cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT character: 0  modifiers: 0];
1288cdf0e10cSrcweir}
1289cdf0e10cSrcweir
1290cdf0e10cSrcweir-(void)moveToBeginningOfDocument: (id)aSender
1291cdf0e10cSrcweir{
1292cdf0e10cSrcweir    (void)aSender;
1293cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT character: 0  modifiers: 0];
1294cdf0e10cSrcweir}
1295cdf0e10cSrcweir
1296cdf0e10cSrcweir-(void)scrollToBeginningOfDocument: (id)aSender
1297cdf0e10cSrcweir{
1298cdf0e10cSrcweir    (void)aSender;
1299cdf0e10cSrcweir    // this is not exactly what we should do, but it makes "Home" and "Shift-Home" behave consistent
1300cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT character: 0  modifiers: 0];
1301cdf0e10cSrcweir}
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir-(void)moveToBeginningOfDocumentAndModifySelection: (id)aSender
1304cdf0e10cSrcweir{
1305cdf0e10cSrcweir    (void)aSender;
1306cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT character: 0  modifiers: 0];
1307cdf0e10cSrcweir}
1308cdf0e10cSrcweir
1309cdf0e10cSrcweir-(void)moveUp: (id)aSender
1310cdf0e10cSrcweir{
1311cdf0e10cSrcweir    (void)aSender;
1312cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_UP character: 0 modifiers: 0];
1313cdf0e10cSrcweir}
1314cdf0e10cSrcweir
1315cdf0e10cSrcweir-(void)moveDown: (id)aSender
1316cdf0e10cSrcweir{
1317cdf0e10cSrcweir    (void)aSender;
1318cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_DOWN character: 0 modifiers: 0];
1319cdf0e10cSrcweir}
1320cdf0e10cSrcweir
1321cdf0e10cSrcweir-(void)insertNewline: (id)aSender
1322cdf0e10cSrcweir{
1323cdf0e10cSrcweir    (void)aSender;
1324cdf0e10cSrcweir    // #i91267# make enter and shift-enter work by evaluating the modifiers
1325cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_RETURN character: '\n' modifiers: mpFrame->mnLastModifierFlags];
1326cdf0e10cSrcweir}
1327cdf0e10cSrcweir
1328cdf0e10cSrcweir-(void)deleteBackward: (id)aSender
1329cdf0e10cSrcweir{
1330cdf0e10cSrcweir    (void)aSender;
1331cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_BACKSPACE character: '\b' modifiers: 0];
1332cdf0e10cSrcweir}
1333cdf0e10cSrcweir
1334cdf0e10cSrcweir-(void)deleteForward: (id)aSender
1335cdf0e10cSrcweir{
1336cdf0e10cSrcweir    (void)aSender;
1337cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_DELETE character: 0x7f modifiers: 0];
1338cdf0e10cSrcweir}
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir-(void)deleteBackwardByDecomposingPreviousCharacter: (id)aSender
1341cdf0e10cSrcweir{
1342cdf0e10cSrcweir    (void)aSender;
1343cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_BACKSPACE character: '\b' modifiers: 0];
1344cdf0e10cSrcweir}
1345cdf0e10cSrcweir
1346cdf0e10cSrcweir-(void)deleteWordBackward: (id)aSender
1347cdf0e10cSrcweir{
1348cdf0e10cSrcweir    (void)aSender;
1349cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_WORD_BACKWARD character: 0  modifiers: 0];
1350cdf0e10cSrcweir}
1351cdf0e10cSrcweir
1352cdf0e10cSrcweir-(void)deleteWordForward: (id)aSender
1353cdf0e10cSrcweir{
1354cdf0e10cSrcweir    (void)aSender;
1355cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_WORD_FORWARD character: 0  modifiers: 0];
1356cdf0e10cSrcweir}
1357cdf0e10cSrcweir
1358cdf0e10cSrcweir-(void)deleteToBeginningOfLine: (id)aSender
1359cdf0e10cSrcweir{
1360cdf0e10cSrcweir    (void)aSender;
1361cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE character: 0  modifiers: 0];
1362cdf0e10cSrcweir}
1363cdf0e10cSrcweir
1364cdf0e10cSrcweir-(void)deleteToEndOfLine: (id)aSender
1365cdf0e10cSrcweir{
1366cdf0e10cSrcweir    (void)aSender;
1367cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_END_OF_LINE character: 0  modifiers: 0];
1368cdf0e10cSrcweir}
1369cdf0e10cSrcweir
1370cdf0e10cSrcweir-(void)deleteToBeginningOfParagraph: (id)aSender
1371cdf0e10cSrcweir{
1372cdf0e10cSrcweir    (void)aSender;
1373cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_PARAGRAPH character: 0  modifiers: 0];
1374cdf0e10cSrcweir}
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir-(void)deleteToEndOfParagraph: (id)aSender
1377cdf0e10cSrcweir{
1378cdf0e10cSrcweir    (void)aSender;
1379cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_END_OF_PARAGRAPH character: 0  modifiers: 0];
1380cdf0e10cSrcweir}
1381cdf0e10cSrcweir
1382cdf0e10cSrcweir-(void)insertLineBreak: (id)aSender
1383cdf0e10cSrcweir{
1384cdf0e10cSrcweir    (void)aSender;
1385cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::INSERT_LINEBREAK character: 0  modifiers: 0];
1386cdf0e10cSrcweir}
1387cdf0e10cSrcweir
1388cdf0e10cSrcweir-(void)insertParagraphSeparator: (id)aSender
1389cdf0e10cSrcweir{
1390cdf0e10cSrcweir    (void)aSender;
1391cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::INSERT_PARAGRAPH character: 0  modifiers: 0];
1392cdf0e10cSrcweir}
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir-(void)selectWord: (id)aSender
1395cdf0e10cSrcweir{
1396cdf0e10cSrcweir    (void)aSender;
1397cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD character: 0  modifiers: 0];
1398cdf0e10cSrcweir}
1399cdf0e10cSrcweir
1400cdf0e10cSrcweir-(void)selectLine: (id)aSender
1401cdf0e10cSrcweir{
1402cdf0e10cSrcweir    (void)aSender;
1403cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_LINE character: 0  modifiers: 0];
1404cdf0e10cSrcweir}
1405cdf0e10cSrcweir
1406cdf0e10cSrcweir-(void)selectParagraph: (id)aSender
1407cdf0e10cSrcweir{
1408cdf0e10cSrcweir    (void)aSender;
1409cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_PARAGRAPH character: 0  modifiers: 0];
1410cdf0e10cSrcweir}
1411cdf0e10cSrcweir
1412cdf0e10cSrcweir-(void)selectAll: (id)aSender
1413cdf0e10cSrcweir{
1414cdf0e10cSrcweir    (void)aSender;
1415cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_ALL character: 0  modifiers: 0];
1416cdf0e10cSrcweir}
1417cdf0e10cSrcweir
1418cdf0e10cSrcweir-(void)cancelOperation: (id)aSender
1419cdf0e10cSrcweir{
1420cdf0e10cSrcweir    (void)aSender;
1421cdf0e10cSrcweir    [self sendKeyInputAndReleaseToFrame: KEY_ESCAPE character: 0x1b modifiers: 0];
1422cdf0e10cSrcweir}
1423cdf0e10cSrcweir
1424cdf0e10cSrcweir-(void)noop: (id)aSender
1425cdf0e10cSrcweir{
1426cdf0e10cSrcweir    (void)aSender;
1427cdf0e10cSrcweir    if( ! mbKeyHandled )
1428cdf0e10cSrcweir    {
1429cdf0e10cSrcweir        if( ! [self sendSingleCharacter:mpLastEvent] )
1430cdf0e10cSrcweir        {
1431cdf0e10cSrcweir            /* prevent recursion */
1432cdf0e10cSrcweir            if( mpLastEvent != mpLastSuperEvent && [NSApp respondsToSelector: @selector(sendSuperEvent:)] )
1433cdf0e10cSrcweir            {
1434cdf0e10cSrcweir                id pLastSuperEvent = mpLastSuperEvent;
1435cdf0e10cSrcweir                mpLastSuperEvent = mpLastEvent;
1436cdf0e10cSrcweir                [NSApp performSelector:@selector(sendSuperEvent:) withObject: mpLastEvent];
1437cdf0e10cSrcweir                mpLastSuperEvent = pLastSuperEvent;
1438*d9d2cc80SHerbert Dürr
1439cdf0e10cSrcweir                std::map< NSEvent*, bool >::iterator it = GetSalData()->maKeyEventAnswer.find( mpLastEvent );
1440cdf0e10cSrcweir                if( it != GetSalData()->maKeyEventAnswer.end() )
1441cdf0e10cSrcweir                    it->second = true;
1442cdf0e10cSrcweir            }
1443cdf0e10cSrcweir        }
1444cdf0e10cSrcweir    }
1445cdf0e10cSrcweir}
1446cdf0e10cSrcweir
1447cdf0e10cSrcweir-(BOOL)sendKeyInputAndReleaseToFrame: (sal_uInt16)nKeyCode character: (sal_Unicode)aChar
1448cdf0e10cSrcweir{
1449cdf0e10cSrcweir    return [self sendKeyInputAndReleaseToFrame: nKeyCode character: aChar modifiers: mpFrame->mnLastModifierFlags];
1450cdf0e10cSrcweir}
1451cdf0e10cSrcweir
1452cdf0e10cSrcweir-(BOOL)sendKeyInputAndReleaseToFrame: (sal_uInt16)nKeyCode character: (sal_Unicode)aChar modifiers: (unsigned int)nMod
1453cdf0e10cSrcweir{
1454cdf0e10cSrcweir    return [self sendKeyToFrameDirect: nKeyCode character: aChar modifiers: nMod] ||
1455cdf0e10cSrcweir           [self sendSingleCharacter: mpLastEvent];
1456cdf0e10cSrcweir}
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir-(BOOL)sendKeyToFrameDirect: (sal_uInt16)nKeyCode  character: (sal_Unicode)aChar modifiers: (unsigned int)nMod
1459cdf0e10cSrcweir{
1460cdf0e10cSrcweir    YIELD_GUARD;
1461*d9d2cc80SHerbert Dürr
1462cdf0e10cSrcweir    long nRet = 0;
1463cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
1464cdf0e10cSrcweir    {
1465cdf0e10cSrcweir        SalKeyEvent aEvent;
1466cdf0e10cSrcweir        aEvent.mnTime           = mpFrame->mnLastEventTime;
1467cdf0e10cSrcweir        aEvent.mnCode           = nKeyCode | ImplGetModifierMask( nMod );
1468cdf0e10cSrcweir        aEvent.mnCharCode       = aChar;
1469cdf0e10cSrcweir        aEvent.mnRepeat         = FALSE;
1470cdf0e10cSrcweir        nRet = mpFrame->CallCallback( SALEVENT_KEYINPUT, &aEvent );
1471cdf0e10cSrcweir        std::map< NSEvent*, bool >::iterator it = GetSalData()->maKeyEventAnswer.find( mpLastEvent );
1472cdf0e10cSrcweir        if( it != GetSalData()->maKeyEventAnswer.end() )
1473cdf0e10cSrcweir            it->second = nRet ? true : false;
1474cdf0e10cSrcweir        if( AquaSalFrame::isAlive( mpFrame ) )
1475cdf0e10cSrcweir            mpFrame->CallCallback( SALEVENT_KEYUP, &aEvent );
1476cdf0e10cSrcweir    }
1477cdf0e10cSrcweir    return nRet ? YES : NO;
1478cdf0e10cSrcweir}
1479cdf0e10cSrcweir
1480cdf0e10cSrcweir
1481cdf0e10cSrcweir-(BOOL)sendSingleCharacter: (NSEvent *)pEvent
1482cdf0e10cSrcweir{
1483cdf0e10cSrcweir    NSString* pUnmodifiedString = [pEvent charactersIgnoringModifiers];
1484cdf0e10cSrcweir
1485cdf0e10cSrcweir    if( pUnmodifiedString && [pUnmodifiedString length] == 1 )
1486cdf0e10cSrcweir    {
1487cdf0e10cSrcweir        unichar keyChar = [pUnmodifiedString characterAtIndex: 0];
1488cdf0e10cSrcweir        sal_uInt16 nKeyCode = ImplMapCharCode( keyChar );
1489cdf0e10cSrcweir        if( nKeyCode != 0 )
1490cdf0e10cSrcweir        {
1491cdf0e10cSrcweir            // don't send unicodes in the private use area
1492cdf0e10cSrcweir            if( keyChar >= 0xf700 && keyChar < 0xf780 )
1493cdf0e10cSrcweir                keyChar = 0;
1494cdf0e10cSrcweir            BOOL bRet = [self sendKeyToFrameDirect: nKeyCode character: keyChar modifiers: mpFrame->mnLastModifierFlags];
1495cdf0e10cSrcweir            mbInKeyInput = false;
1496cdf0e10cSrcweir
1497cdf0e10cSrcweir            return bRet;
1498cdf0e10cSrcweir        }
1499cdf0e10cSrcweir    }
1500cdf0e10cSrcweir    return NO;
1501cdf0e10cSrcweir}
1502cdf0e10cSrcweir
1503cdf0e10cSrcweir
1504cdf0e10cSrcweir// NSTextInput protocol
1505cdf0e10cSrcweir- (NSArray *)validAttributesForMarkedText
1506cdf0e10cSrcweir{
1507cdf0e10cSrcweir    return [NSArray arrayWithObjects:NSUnderlineStyleAttributeName, nil];
1508cdf0e10cSrcweir}
1509cdf0e10cSrcweir
1510cdf0e10cSrcweir- (BOOL)hasMarkedText
1511cdf0e10cSrcweir{
1512cdf0e10cSrcweir    BOOL bHasMarkedText;
1513cdf0e10cSrcweir
1514cdf0e10cSrcweir    bHasMarkedText = ( mMarkedRange.location != NSNotFound ) &&
1515cdf0e10cSrcweir                     ( mMarkedRange.length != 0 );
1516cdf0e10cSrcweir    // hack to check keys like "Control-j"
1517cdf0e10cSrcweir    if( mbInKeyInput )
1518cdf0e10cSrcweir    {
1519cdf0e10cSrcweir        mbNeedSpecialKeyHandle = true;
1520cdf0e10cSrcweir    }
1521cdf0e10cSrcweir
1522cdf0e10cSrcweir    // FIXME:
1523cdf0e10cSrcweir    // #i106901#
1524cdf0e10cSrcweir    // if we come here outside of mbInKeyInput, this is likely to be because
1525cdf0e10cSrcweir    // of the keyboard viewer. For unknown reasons having no marked range
1526cdf0e10cSrcweir    // in this case causes a crash. So we say we have a marked range anyway
1527cdf0e10cSrcweir    // This is a hack, since it is not understood what a) causes that crash
1528cdf0e10cSrcweir    // and b) why we should have a marked range at this point.
1529cdf0e10cSrcweir    if( ! mbInKeyInput )
1530cdf0e10cSrcweir        bHasMarkedText = YES;
1531cdf0e10cSrcweir
1532cdf0e10cSrcweir    return bHasMarkedText;
1533cdf0e10cSrcweir}
1534cdf0e10cSrcweir
1535cdf0e10cSrcweir- (NSRange)markedRange
1536cdf0e10cSrcweir{
1537cdf0e10cSrcweir    // FIXME:
1538cdf0e10cSrcweir    // #i106901#
1539cdf0e10cSrcweir    // if we come here outside of mbInKeyInput, this is likely to be because
1540cdf0e10cSrcweir    // of the keyboard viewer. For unknown reasons having no marked range
1541cdf0e10cSrcweir    // in this case causes a crash. So we say we have a marked range anyway
1542cdf0e10cSrcweir    // This is a hack, since it is not understood what a) causes that crash
1543cdf0e10cSrcweir    // and b) why we should have a marked range at this point.
1544cdf0e10cSrcweir    if( ! mbInKeyInput )
1545cdf0e10cSrcweir        return NSMakeRange( 0, 0 );
1546*d9d2cc80SHerbert Dürr
1547cdf0e10cSrcweir    return [self hasMarkedText] ? mMarkedRange : NSMakeRange( NSNotFound, 0 );
1548cdf0e10cSrcweir}
1549cdf0e10cSrcweir
1550cdf0e10cSrcweir- (NSRange)selectedRange
1551cdf0e10cSrcweir{
1552cdf0e10cSrcweir    return mSelectedRange;
1553cdf0e10cSrcweir}
1554cdf0e10cSrcweir
1555cdf0e10cSrcweir- (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange
1556cdf0e10cSrcweir{
1557cdf0e10cSrcweir    if( ![aString isKindOfClass:[NSAttributedString class]] )
1558cdf0e10cSrcweir        aString = [[[NSAttributedString alloc] initWithString:aString] autorelease];
1559cdf0e10cSrcweir    NSRange rangeToReplace = [self hasMarkedText] ? [self markedRange] : [self selectedRange];
1560cdf0e10cSrcweir    if( rangeToReplace.location == NSNotFound )
1561cdf0e10cSrcweir    {
1562cdf0e10cSrcweir        mMarkedRange = NSMakeRange( selRange.location, [aString length] );
1563cdf0e10cSrcweir        mSelectedRange = NSMakeRange( selRange.location, selRange.length );
1564cdf0e10cSrcweir    }
1565cdf0e10cSrcweir    else
1566cdf0e10cSrcweir    {
1567cdf0e10cSrcweir        mMarkedRange = NSMakeRange( rangeToReplace.location, [aString length] );
1568cdf0e10cSrcweir        mSelectedRange = NSMakeRange( rangeToReplace.location + selRange.location, selRange.length );
1569cdf0e10cSrcweir    }
1570cdf0e10cSrcweir
1571cdf0e10cSrcweir    int len = [aString length];
1572cdf0e10cSrcweir    SalExtTextInputEvent aInputEvent;
1573cdf0e10cSrcweir    aInputEvent.mnTime = mpFrame->mnLastEventTime;
1574cdf0e10cSrcweir    aInputEvent.mnDeltaStart = 0;
1575cdf0e10cSrcweir    aInputEvent.mbOnlyCursor = FALSE;
1576cdf0e10cSrcweir    if( len > 0 ) {
1577cdf0e10cSrcweir        NSString *pString = [aString string];
1578cdf0e10cSrcweir        OUString aInsertString( GetOUString( pString ) );
1579cdf0e10cSrcweir        std::vector<sal_uInt16> aInputFlags = std::vector<sal_uInt16>( std::max( 1, len ), 0 );
1580cdf0e10cSrcweir        for ( int i = 0; i < len; i++ )
1581cdf0e10cSrcweir        {
1582cdf0e10cSrcweir            unsigned int nUnderlineValue;
1583cdf0e10cSrcweir            NSRange effectiveRange;
1584*d9d2cc80SHerbert Dürr
1585cdf0e10cSrcweir            effectiveRange = NSMakeRange(i, 1);
1586cdf0e10cSrcweir            nUnderlineValue = [[aString attribute:NSUnderlineStyleAttributeName atIndex:i effectiveRange:&effectiveRange] unsignedIntValue];
1587cdf0e10cSrcweir
1588cdf0e10cSrcweir            switch (nUnderlineValue & 0xff) {
1589cdf0e10cSrcweir            case NSUnderlineStyleSingle:
1590cdf0e10cSrcweir                aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_UNDERLINE;
1591cdf0e10cSrcweir                break;
1592cdf0e10cSrcweir            case NSUnderlineStyleThick:
1593cdf0e10cSrcweir                aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_UNDERLINE | SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT;
1594cdf0e10cSrcweir                break;
1595cdf0e10cSrcweir            case NSUnderlineStyleDouble:
1596cdf0e10cSrcweir                aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_BOLDUNDERLINE;
1597cdf0e10cSrcweir                break;
1598cdf0e10cSrcweir            default:
1599cdf0e10cSrcweir                aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT;
1600cdf0e10cSrcweir                break;
1601cdf0e10cSrcweir            }
1602cdf0e10cSrcweir        }
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir        aInputEvent.maText = aInsertString;
1605cdf0e10cSrcweir        aInputEvent.mnCursorPos = selRange.location;
1606cdf0e10cSrcweir        aInputEvent.mpTextAttr = &aInputFlags[0];
1607cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void *)&aInputEvent );
1608cdf0e10cSrcweir    } else {
1609cdf0e10cSrcweir        aInputEvent.maText = String();
1610cdf0e10cSrcweir        aInputEvent.mnCursorPos = 0;
1611cdf0e10cSrcweir        aInputEvent.mnCursorFlags = 0;
1612cdf0e10cSrcweir        aInputEvent.mpTextAttr = 0;
1613cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void *)&aInputEvent );
1614cdf0e10cSrcweir        mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 );
1615cdf0e10cSrcweir    }
1616cdf0e10cSrcweir    mbKeyHandled= true;
1617cdf0e10cSrcweir}
1618cdf0e10cSrcweir
1619cdf0e10cSrcweir- (void)unmarkText
1620cdf0e10cSrcweir{
1621cdf0e10cSrcweir    mSelectedRange = mMarkedRange = NSMakeRange(NSNotFound, 0);
1622cdf0e10cSrcweir}
1623cdf0e10cSrcweir
1624cdf0e10cSrcweir- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange
1625cdf0e10cSrcweir{
1626cdf0e10cSrcweir    (void)theRange;
1627cdf0e10cSrcweir    // FIXME
1628cdf0e10cSrcweir    return nil;
1629cdf0e10cSrcweir}
1630cdf0e10cSrcweir
16312dae3561SHerbert Dürr- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
1632cdf0e10cSrcweir{
1633cdf0e10cSrcweir    (void)thePoint;
1634cdf0e10cSrcweir    // FIXME
1635cdf0e10cSrcweir    return 0;
1636cdf0e10cSrcweir}
1637cdf0e10cSrcweir
1638cdf0e10cSrcweir#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
1639cdf0e10cSrcweir/* build target 10.5 or greater */
1640cdf0e10cSrcweir- (NSInteger)conversationIdentifier
1641cdf0e10cSrcweir#else
1642cdf0e10cSrcweir/* build target 10.4 */
1643cdf0e10cSrcweir- (long)conversationIdentifier
1644cdf0e10cSrcweir#endif
1645cdf0e10cSrcweir{
1646cdf0e10cSrcweir    return (long)self;
1647cdf0e10cSrcweir}
1648cdf0e10cSrcweir
1649cdf0e10cSrcweir- (void)doCommandBySelector:(SEL)aSelector
1650cdf0e10cSrcweir{
1651cdf0e10cSrcweir    if( AquaSalFrame::isAlive( mpFrame ) )
1652cdf0e10cSrcweir    {
1653cdf0e10cSrcweir        #if OSL_DEBUG_LEVEL > 1
1654cdf0e10cSrcweir        // fprintf( stderr, "SalFrameView: doCommandBySelector %s\n", (char*)aSelector );
1655cdf0e10cSrcweir        #endif
1656cdf0e10cSrcweir        if( (mpFrame->mnICOptions & SAL_INPUTCONTEXT_TEXT) != 0 &&
1657cdf0e10cSrcweir            aSelector != NULL && [self respondsToSelector: aSelector] )
1658cdf0e10cSrcweir        {
1659cdf0e10cSrcweir            [self performSelector: aSelector];
1660cdf0e10cSrcweir        }
1661cdf0e10cSrcweir        else
1662cdf0e10cSrcweir        {
1663cdf0e10cSrcweir            [self sendSingleCharacter:mpLastEvent];
1664cdf0e10cSrcweir        }
1665cdf0e10cSrcweir    }
1666cdf0e10cSrcweir
1667cdf0e10cSrcweir    mbKeyHandled = true;
1668cdf0e10cSrcweir}
1669cdf0e10cSrcweir
1670cdf0e10cSrcweir-(void)clearLastEvent
1671cdf0e10cSrcweir{
1672cdf0e10cSrcweir    mpLastEvent = nil;
1673cdf0e10cSrcweir}
1674cdf0e10cSrcweir
1675cdf0e10cSrcweir- (NSRect)firstRectForCharacterRange:(NSRange)theRange
1676cdf0e10cSrcweir{
1677cdf0e10cSrcweir    (void)theRange;
1678cdf0e10cSrcweir    SalExtTextInputPosEvent aPosEvent;
1679cdf0e10cSrcweir    mpFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void *)&aPosEvent );
1680cdf0e10cSrcweir
1681cdf0e10cSrcweir    NSRect rect;
1682cdf0e10cSrcweir
1683cdf0e10cSrcweir    rect.origin.x = aPosEvent.mnX + mpFrame->maGeometry.nX;
1684cdf0e10cSrcweir    rect.origin.y =   aPosEvent.mnY + mpFrame->maGeometry.nY + 4; // add some space for underlines
1685cdf0e10cSrcweir    rect.size.width = aPosEvent.mnWidth;
1686cdf0e10cSrcweir    rect.size.height = aPosEvent.mnHeight;
1687cdf0e10cSrcweir
1688cdf0e10cSrcweir    mpFrame->VCLToCocoa( rect );
1689cdf0e10cSrcweir    return rect;
1690cdf0e10cSrcweir}
1691cdf0e10cSrcweir
1692cdf0e10cSrcweir-(id)parentAttribute {
1693bde8a4bdSHerbert Dürr    return mpFrame->getNSWindow();
1694cdf0e10cSrcweir}
1695cdf0e10cSrcweir
1696cdf0e10cSrcweir-(::com::sun::star::accessibility::XAccessibleContext *)accessibleContext
1697cdf0e10cSrcweir{
1698cdf0e10cSrcweir    if ( mpReferenceWrapper == nil ) {
1699cdf0e10cSrcweir        // some frames never become visible ..
1700cdf0e10cSrcweir        Window *pWindow = mpFrame -> GetWindow();
1701cdf0e10cSrcweir        if ( ! pWindow )
1702cdf0e10cSrcweir            return nil;
1703cdf0e10cSrcweir
1704cdf0e10cSrcweir        mpReferenceWrapper = new ReferenceWrapper;
1705cdf0e10cSrcweir        mpReferenceWrapper -> rAccessibleContext =  pWindow -> /*GetAccessibleChildWindow( 0 ) ->*/ GetAccessible() -> getAccessibleContext();
1706cdf0e10cSrcweir        [ AquaA11yFactory insertIntoWrapperRepository: self forAccessibleContext: mpReferenceWrapper -> rAccessibleContext ];
1707cdf0e10cSrcweir    }
1708cdf0e10cSrcweir    return [ super accessibleContext ];
1709cdf0e10cSrcweir}
1710cdf0e10cSrcweir
171197dacec1SHerbert Dürr-(NSWindow*)windowForParent
17122fb76c82SHerbert Dürr{
171397dacec1SHerbert Dürr    return mpFrame->getNSWindow();
1714cdf0e10cSrcweir}
1715cdf0e10cSrcweir
1716cdf0e10cSrcweir-(void)registerMouseEventListener: (id)theListener
1717cdf0e10cSrcweir{
1718cdf0e10cSrcweir  mpMouseEventListener = theListener;
1719cdf0e10cSrcweir}
1720cdf0e10cSrcweir
1721cdf0e10cSrcweir-(void)unregisterMouseEventListener: (id)theListener
1722cdf0e10cSrcweir{
1723cdf0e10cSrcweir    (void)theListener;
1724cdf0e10cSrcweir    mpMouseEventListener = nil;
1725cdf0e10cSrcweir}
1726cdf0e10cSrcweir
1727cdf0e10cSrcweir-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
1728cdf0e10cSrcweir{
1729cdf0e10cSrcweir  return [mDraggingDestinationHandler draggingEntered: sender];
1730cdf0e10cSrcweir}
1731cdf0e10cSrcweir
1732cdf0e10cSrcweir-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
1733cdf0e10cSrcweir{
1734cdf0e10cSrcweir  return [mDraggingDestinationHandler draggingUpdated: sender];
1735cdf0e10cSrcweir}
1736cdf0e10cSrcweir
1737cdf0e10cSrcweir-(void)draggingExited:(id <NSDraggingInfo>)sender
1738cdf0e10cSrcweir{
1739cdf0e10cSrcweir  [mDraggingDestinationHandler draggingExited: sender];
1740cdf0e10cSrcweir}
1741cdf0e10cSrcweir
1742cdf0e10cSrcweir-(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
1743cdf0e10cSrcweir{
1744cdf0e10cSrcweir  return [mDraggingDestinationHandler prepareForDragOperation: sender];
1745cdf0e10cSrcweir}
1746cdf0e10cSrcweir
1747cdf0e10cSrcweir-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender
1748cdf0e10cSrcweir{
1749cdf0e10cSrcweir  return [mDraggingDestinationHandler performDragOperation: sender];
1750cdf0e10cSrcweir}
1751cdf0e10cSrcweir
1752cdf0e10cSrcweir-(void)concludeDragOperation:(id <NSDraggingInfo>)sender
1753cdf0e10cSrcweir{
1754cdf0e10cSrcweir  [mDraggingDestinationHandler concludeDragOperation: sender];
1755cdf0e10cSrcweir}
1756cdf0e10cSrcweir
1757cdf0e10cSrcweir-(void)registerDraggingDestinationHandler:(id)theHandler
1758cdf0e10cSrcweir{
1759cdf0e10cSrcweir  mDraggingDestinationHandler = theHandler;
1760cdf0e10cSrcweir}
1761cdf0e10cSrcweir
1762cdf0e10cSrcweir-(void)unregisterDraggingDestinationHandler:(id)theHandler
1763cdf0e10cSrcweir{
1764cdf0e10cSrcweir    (void)theHandler;
1765cdf0e10cSrcweir    mDraggingDestinationHandler = nil;
1766cdf0e10cSrcweir}
1767cdf0e10cSrcweir
1768cdf0e10cSrcweir@end
1769cdf0e10cSrcweir
1770