diff options
Diffstat (limited to 'vcl/aqua/source/window')
-rw-r--r-- | vcl/aqua/source/window/salframe.cxx | 1807 | ||||
-rw-r--r-- | vcl/aqua/source/window/salframeview.mm | 1732 | ||||
-rw-r--r-- | vcl/aqua/source/window/salmenu.cxx | 969 | ||||
-rw-r--r-- | vcl/aqua/source/window/salnsmenu.mm | 217 | ||||
-rw-r--r-- | vcl/aqua/source/window/salobj.cxx | 247 |
5 files changed, 0 insertions, 4972 deletions
diff --git a/vcl/aqua/source/window/salframe.cxx b/vcl/aqua/source/window/salframe.cxx deleted file mode 100644 index f6bcdc9443..0000000000 --- a/vcl/aqua/source/window/salframe.cxx +++ /dev/null @@ -1,1807 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************ - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_vcl.hxx" - -#include <string> - -#include "rtl/ustrbuf.hxx" - -#include "osl/file.h" - -#include "vcl/svapp.hxx" -#include "vcl/window.hxx" -#include "vcl/timer.hxx" - -#include "aqua/saldata.hxx" -#include "aqua/salgdi.h" -#include "aqua/salframe.h" -#include "aqua/salmenu.h" -#include "aqua/saltimer.h" -#include "aqua/salinst.h" -#include "aqua/salframeview.h" -#include "aqua/aqua11yfactory.h" - -#include "salwtype.hxx" - -#include "premac.h" -// needed for theming -// FIXME: move theming code to salnativewidgets.cxx -#include <Carbon/Carbon.h> -#include "postmac.h" - - -using namespace std; - -// ======================================================================= - -AquaSalFrame* AquaSalFrame::s_pCaptureFrame = NULL; - -// ======================================================================= - -AquaSalFrame::AquaSalFrame( SalFrame* pParent, sal_uLong salFrameStyle ) : - mpWindow(nil), - mpView(nil), - mpDockMenuEntry(nil), - mpGraphics(NULL), - mpParent(NULL), - mnMinWidth(0), - mnMinHeight(0), - mnMaxWidth(0), - mnMaxHeight(0), - mbGraphics(false), - mbFullScreen( false ), - mbShown(false), - mbInitShow(true), - mbPositioned(false), - mbSized(false), - mbPresentation( false ), - mnStyle( salFrameStyle ), - mnStyleMask( 0 ), - mnLastEventTime( 0 ), - mnLastModifierFlags( 0 ), - mpMenu( NULL ), - mnExtStyle( 0 ), - mePointerStyle( POINTER_ARROW ), - mnTrackingRectTag( 0 ), - mrClippingPath( 0 ), - mnICOptions( 0 ) -{ - maSysData.nSize = sizeof( SystemEnvData ); - - mpParent = dynamic_cast<AquaSalFrame*>(pParent); - - initWindowAndView(); - - SalData* pSalData = GetSalData(); - pSalData->maFrames.push_front( this ); - pSalData->maFrameCheck.insert( this ); -} - -// ----------------------------------------------------------------------- - -AquaSalFrame::~AquaSalFrame() -{ - // if the frame is destroyed and has the current menubar - // set the default menubar - if( mpMenu && mpMenu->mbMenuBar && AquaSalMenu::pCurrentMenuBar == mpMenu ) - AquaSalMenu::setDefaultMenu(); - - // cleanup clipping stuff - ResetClipRegion(); - - [SalFrameView unsetMouseFrame: this]; - - SalData* pSalData = GetSalData(); - pSalData->maFrames.remove( this ); - pSalData->maFrameCheck.erase( this ); - pSalData->maPresentationFrames.remove( this ); - - DBG_ASSERT( this != s_pCaptureFrame, "capture frame destroyed" ); - if( this == s_pCaptureFrame ) - s_pCaptureFrame = NULL; - - if ( mpGraphics ) - delete mpGraphics; - - if( mpDockMenuEntry ) - // life cycle comment: the menu has ownership of the item, so no release - [AquaSalInstance::GetDynamicDockMenu() removeItem: mpDockMenuEntry]; - if ( mpView ) { - [AquaA11yFactory revokeView: mpView]; - [mpView release]; - } - if ( mpWindow ) - [mpWindow release]; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::initWindowAndView() -{ - // initialize mirroring parameters - // FIXME: screens changing - NSScreen * pScreen = [mpWindow screen]; - if( pScreen == nil ) - pScreen = [NSScreen mainScreen]; - maScreenRect = [pScreen frame]; - - // calculate some default geometry - NSRect aVisibleRect = [pScreen visibleFrame]; - CocoaToVCL( aVisibleRect ); - - maGeometry.nX = static_cast<int>(aVisibleRect.origin.x + aVisibleRect.size.width / 10); - maGeometry.nY = static_cast<int>(aVisibleRect.origin.y + aVisibleRect.size.height / 10); - maGeometry.nWidth = static_cast<unsigned int>(aVisibleRect.size.width * 0.8); - maGeometry.nHeight = static_cast<unsigned int>(aVisibleRect.size.height * 0.8); - - // calculate style mask - if( (mnStyle & SAL_FRAME_STYLE_FLOAT) || - (mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) - mnStyleMask = NSBorderlessWindowMask; - else if( mnStyle & SAL_FRAME_STYLE_DEFAULT ) - { - mnStyleMask = NSTitledWindowMask | - NSMiniaturizableWindowMask | - NSResizableWindowMask | - NSClosableWindowMask; - // make default window "maximized" - maGeometry.nX = static_cast<int>(aVisibleRect.origin.x); - maGeometry.nY = static_cast<int>(aVisibleRect.origin.y); - maGeometry.nWidth = static_cast<int>(aVisibleRect.size.width); - maGeometry.nHeight = static_cast<int>(aVisibleRect.size.height); - mbPositioned = mbSized = true; - } - else - { - if( (mnStyle & SAL_FRAME_STYLE_MOVEABLE) ) - { - mnStyleMask |= NSTitledWindowMask; - if( mpParent == NULL ) - mnStyleMask |= NSMiniaturizableWindowMask; - } - if( (mnStyle & SAL_FRAME_STYLE_SIZEABLE) ) - mnStyleMask |= NSResizableWindowMask; - if( (mnStyle & SAL_FRAME_STYLE_CLOSEABLE) ) - mnStyleMask |= NSClosableWindowMask; - // documentation says anything other than NSBorderlessWindowMask (=0) - // should also include NSTitledWindowMask; - if( mnStyleMask != 0 ) - mnStyleMask |= NSTitledWindowMask; - } - - // #i91990# support GUI-less (daemon) execution - @try - { - mpWindow = [[SalFrameWindow alloc] initWithSalFrame: this]; - mpView = [[SalFrameView alloc] initWithSalFrame: this]; - } - @catch ( id exception ) - { - return; - } - - if( (mnStyle & SAL_FRAME_STYLE_TOOLTIP) ) - [mpWindow setIgnoresMouseEvents: YES]; - else - [mpWindow setAcceptsMouseMovedEvents: YES]; - [mpWindow setHasShadow: YES]; - [mpWindow setDelegate: mpWindow]; - - NSRect aRect = { { 0,0 }, { maGeometry.nWidth, maGeometry.nHeight } }; - mnTrackingRectTag = [mpView addTrackingRect: aRect owner: mpView userData: nil assumeInside: NO]; - - maSysData.pView = mpView; - - UpdateFrameGeometry(); - - [mpWindow setContentView: mpView]; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::CocoaToVCL( NSRect& io_rRect, bool bRelativeToScreen ) -{ - if( bRelativeToScreen ) - io_rRect.origin.y = maScreenRect.size.height - (io_rRect.origin.y+io_rRect.size.height); - else - io_rRect.origin.y = maGeometry.nHeight - (io_rRect.origin.y+io_rRect.size.height); -} - -void AquaSalFrame::VCLToCocoa( NSRect& io_rRect, bool bRelativeToScreen ) -{ - if( bRelativeToScreen ) - io_rRect.origin.y = maScreenRect.size.height - (io_rRect.origin.y+io_rRect.size.height); - else - io_rRect.origin.y = maGeometry.nHeight - (io_rRect.origin.y+io_rRect.size.height); -} - -void AquaSalFrame::CocoaToVCL( NSPoint& io_rPoint, bool bRelativeToScreen ) -{ - if( bRelativeToScreen ) - io_rPoint.y = maScreenRect.size.height - io_rPoint.y; - else - io_rPoint.y = maGeometry.nHeight - io_rPoint.y; -} - -void AquaSalFrame::VCLToCocoa( NSPoint& io_rPoint, bool bRelativeToScreen ) -{ - if( bRelativeToScreen ) - io_rPoint.y = maScreenRect.size.height - io_rPoint.y; - else - io_rPoint.y = maGeometry.nHeight - io_rPoint.y; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::screenParametersChanged() -{ - UpdateFrameGeometry(); - - if( mpGraphics ) - mpGraphics->updateResolution(); - CallCallback( SALEVENT_DISPLAYCHANGED, 0 ); -} - -// ----------------------------------------------------------------------- - -SalGraphics* AquaSalFrame::GetGraphics() -{ - if ( mbGraphics ) - return NULL; - - if ( !mpGraphics ) - { - mpGraphics = new AquaSalGraphics; - mpGraphics->SetWindowGraphics( this ); - } - - mbGraphics = TRUE; - return mpGraphics; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::ReleaseGraphics( SalGraphics *pGraphics ) -{ - (void)pGraphics; - DBG_ASSERT( pGraphics == mpGraphics, "graphics released on wrong frame" ); - mbGraphics = FALSE; -} - -// ----------------------------------------------------------------------- - -sal_Bool AquaSalFrame::PostEvent( void *pData ) -{ - GetSalData()->mpFirstInstance->PostUserEvent( this, SALEVENT_USEREVENT, pData ); - return TRUE; -} - -// ----------------------------------------------------------------------- -void AquaSalFrame::SetTitle(const XubString& rTitle) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - NSString* pTitle = CreateNSString( rTitle ); - [mpWindow setTitle: pTitle]; - - // create an entry in the dock menu - const sal_uLong nAppWindowStyle = (SAL_FRAME_STYLE_CLOSEABLE | SAL_FRAME_STYLE_MOVEABLE); - if( mpParent == NULL && - (mnStyle & nAppWindowStyle) == nAppWindowStyle ) - { - if( mpDockMenuEntry == NULL ) - { - NSMenu* pDock = AquaSalInstance::GetDynamicDockMenu(); - mpDockMenuEntry = [pDock insertItemWithTitle: pTitle - action: @selector(dockMenuItemTriggered:) - keyEquivalent: @"" - atIndex: 0]; - [mpDockMenuEntry setTarget: mpWindow]; - - // TODO: image (either the generic window image or an icon - // check mark (for "main" window ?) - } - else - [mpDockMenuEntry setTitle: pTitle]; - } - - if (pTitle) - [pTitle release]; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetIcon( sal_uInt16 ) -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetRepresentedURL( const rtl::OUString& i_rDocURL ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( i_rDocURL.indexOfAsciiL( "file:", 5 ) == 0 ) - { - rtl::OUString aSysPath; - osl_getSystemPathFromFileURL( i_rDocURL.pData, &aSysPath.pData ); - NSString* pStr = CreateNSString( aSysPath ); - if( pStr ) - { - [pStr autorelease]; - [mpWindow setRepresentedFilename: pStr]; - } - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::initShow() -{ - mbInitShow = false; - if( ! mbPositioned && ! mbFullScreen ) - { - Rectangle aScreenRect; - GetWorkArea( aScreenRect ); - if( mpParent ) // center relative to parent - { - // center on parent - long nNewX = mpParent->maGeometry.nX + ((long)mpParent->maGeometry.nWidth - (long)maGeometry.nWidth)/2; - if( nNewX < aScreenRect.Left() ) - nNewX = aScreenRect.Left(); - if( long(nNewX + maGeometry.nWidth) > aScreenRect.Right() ) - nNewX = aScreenRect.Right() - maGeometry.nWidth-1; - long nNewY = mpParent->maGeometry.nY + ((long)mpParent->maGeometry.nHeight - (long)maGeometry.nHeight)/2; - if( nNewY < aScreenRect.Top() ) - nNewY = aScreenRect.Top(); - if( nNewY > aScreenRect.Bottom() ) - nNewY = aScreenRect.Bottom() - maGeometry.nHeight-1; - SetPosSize( nNewX - mpParent->maGeometry.nX, - nNewY - mpParent->maGeometry.nY, - 0, 0, SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y ); - } - else if( ! (mnStyle & SAL_FRAME_STYLE_SIZEABLE) ) - { - // center on screen - long nNewX = (aScreenRect.GetWidth() - maGeometry.nWidth)/2; - long nNewY = (aScreenRect.GetHeight() - maGeometry.nHeight)/2; - SetPosSize( nNewX, nNewY, 0, 0, SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y ); - } - } - - // make sure the view is present in the wrapper list before any children receive focus - [AquaA11yFactory registerView: mpView]; -} - -void AquaSalFrame::SendPaintEvent( const Rectangle* pRect ) -{ - SalPaintEvent aPaintEvt( 0, 0, maGeometry.nWidth, maGeometry.nHeight, true ); - if( pRect ) - { - aPaintEvt.mnBoundX = pRect->Left(); - aPaintEvt.mnBoundY = pRect->Top(); - aPaintEvt.mnBoundWidth = pRect->GetWidth(); - aPaintEvt.mnBoundHeight = pRect->GetHeight(); - } - - CallCallback(SALEVENT_PAINT, &aPaintEvt); -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::Show(sal_Bool bVisible, sal_Bool bNoActivate) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - mbShown = bVisible; - if(bVisible) - { - if( mbInitShow ) - initShow(); - - CallCallback(SALEVENT_RESIZE, 0); - // trigger filling our backbuffer - SendPaintEvent(); - - if( bNoActivate || [mpWindow canBecomeKeyWindow] == NO ) - [mpWindow orderFront: NSApp]; - else - [mpWindow makeKeyAndOrderFront: NSApp]; - - if( mpParent ) - { - /* #i92674# #i96433# we do not want an invisible parent to show up (which adding a visible - child implicitly does). However we also do not want a parentless toolbar. - - HACK: try to decide when we should not insert a child to its parent - floaters and ownerdraw windows have not yet shown up in cases where - we don't want the parent to become visible - */ - if( mpParent->mbShown || (mnStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT) ) ) - { - [mpParent->mpWindow addChildWindow: mpWindow ordered: NSWindowAbove]; - } - } - - if( mbPresentation ) - [mpWindow makeMainWindow]; - } - else - { - // if the frame holding the current menubar gets hidden - // show the default menubar - if( mpMenu && mpMenu->mbMenuBar && AquaSalMenu::pCurrentMenuBar == mpMenu ) - AquaSalMenu::setDefaultMenu(); - - // #i90440# #i94443# work around the focus going back to some other window - // if a child gets hidden for a parent window - if( mpParent && mpParent->mbShown && [mpWindow isKeyWindow] ) - [mpParent->mpWindow makeKeyAndOrderFront: NSApp]; - - [SalFrameView unsetMouseFrame: this]; - if( mpParent && [mpWindow parentWindow] == mpParent->mpWindow ) - [mpParent->mpWindow removeChildWindow: mpWindow]; - - [mpWindow orderOut: NSApp]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::Enable( sal_Bool ) -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetMinClientSize( long nWidth, long nHeight ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - mnMinWidth = nWidth; - mnMinHeight = nHeight; - - if( mpWindow ) - { - // Always add the decoration as the dimension concerns only - // the content rectangle - nWidth += maGeometry.nLeftDecoration + maGeometry.nRightDecoration; - nHeight += maGeometry.nTopDecoration + maGeometry.nBottomDecoration; - - NSSize aSize = { nWidth, nHeight }; - - // Size of full window (content+structure) although we only - // have the client size in arguments - [mpWindow setMinSize: aSize]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetMaxClientSize( long nWidth, long nHeight ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - mnMaxWidth = nWidth; - mnMaxHeight = nHeight; - - if( mpWindow ) - { - // Always add the decoration as the dimension concerns only - // the content rectangle - nWidth += maGeometry.nLeftDecoration + maGeometry.nRightDecoration; - nHeight += maGeometry.nTopDecoration + maGeometry.nBottomDecoration; - - // Carbon windows can't have a size greater than 32767x32767 - if (nWidth>32767) nWidth=32767; - if (nHeight>32767) nHeight=32767; - - NSSize aSize = { nWidth, nHeight }; - - // Size of full window (content+structure) although we only - // have the client size in arguments - [mpWindow setMaxSize: aSize]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetClientSize( long nWidth, long nHeight ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( mpWindow ) - { - NSSize aSize = { nWidth, nHeight }; - - [mpWindow setContentSize: aSize]; - UpdateFrameGeometry(); - if( mbShown ) - // trigger filling our backbuffer - SendPaintEvent(); - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::GetClientSize( long& rWidth, long& rHeight ) -{ - if( mbShown || mbInitShow ) - { - rWidth = maGeometry.nWidth; - rHeight = maGeometry.nHeight; - } - else - { - rWidth = 0; - rHeight = 0; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetWindowState( const SalFrameState* pState ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if ( mpWindow ) - { - // set normal state - NSRect aStateRect = [mpWindow frame]; - aStateRect = [NSWindow contentRectForFrameRect: aStateRect styleMask: mnStyleMask]; - CocoaToVCL( aStateRect ); - if( pState->mnMask & SAL_FRAMESTATE_MASK_X ) - aStateRect.origin.x = float(pState->mnX); - if( pState->mnMask & SAL_FRAMESTATE_MASK_Y ) - aStateRect.origin.y = float(pState->mnY); - if( pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH ) - aStateRect.size.width = float(pState->mnWidth); - if( pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT ) - aStateRect.size.height = float(pState->mnHeight); - VCLToCocoa( aStateRect ); - aStateRect = [NSWindow frameRectForContentRect: aStateRect styleMask: mnStyleMask]; - - [mpWindow setFrame: aStateRect display: NO]; - if( pState->mnState == SAL_FRAMESTATE_MINIMIZED ) - [mpWindow miniaturize: NSApp]; - else if( [mpWindow isMiniaturized] ) - [mpWindow deminiaturize: NSApp]; - - - /* ZOOMED is not really maximized (actually it toggles between a user set size and - the program specified one), but comes closest since the default behavior is - "maximized" if the user did not intervene - */ - if( pState->mnState == SAL_FRAMESTATE_MAXIMIZED ) - { - if(! [mpWindow isZoomed]) - [mpWindow zoom: NSApp]; - } - else - { - if( [mpWindow isZoomed] ) - [mpWindow zoom: NSApp]; - } - } - - // get new geometry - UpdateFrameGeometry(); - - sal_uInt16 nEvent = 0; - if( pState->mnMask & (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_X) ) - { - mbPositioned = true; - nEvent = SALEVENT_MOVE; - } - - if( pState->mnMask & (SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT) ) - { - mbSized = true; - nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE; - } - // send event that we were moved/sized - if( nEvent ) - CallCallback( nEvent, NULL ); - - if( mbShown && mpWindow ) - { - // trigger filling our backbuffer - SendPaintEvent(); - - // tell the system the views need to be updated - [mpWindow display]; - } -} - -// ----------------------------------------------------------------------- - -sal_Bool AquaSalFrame::GetWindowState( SalFrameState* pState ) -{ - if ( !mpWindow ) - return FALSE; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - pState->mnMask = SAL_FRAMESTATE_MASK_X | - SAL_FRAMESTATE_MASK_Y | - SAL_FRAMESTATE_MASK_WIDTH | - SAL_FRAMESTATE_MASK_HEIGHT | - SAL_FRAMESTATE_MASK_STATE; - - NSRect aStateRect = [mpWindow frame]; - aStateRect = [NSWindow contentRectForFrameRect: aStateRect styleMask: mnStyleMask]; - CocoaToVCL( aStateRect ); - pState->mnX = long(aStateRect.origin.x); - pState->mnY = long(aStateRect.origin.y); - pState->mnWidth = long(aStateRect.size.width); - pState->mnHeight = long(aStateRect.size.height); - - if( [mpWindow isMiniaturized] ) - pState->mnState = SAL_FRAMESTATE_MINIMIZED; - else if( ! [mpWindow isZoomed] ) - pState->mnState = SAL_FRAMESTATE_NORMAL; - else - pState->mnState = SAL_FRAMESTATE_MAXIMIZED; - - return TRUE; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetScreenNumber(unsigned int nScreen) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - NSArray* pScreens = [NSScreen screens]; - Rectangle aRet; - NSScreen* pScreen = nil; - if( pScreens && nScreen < [pScreens count] ) - { - // get new screen frame - pScreen = [pScreens objectAtIndex: nScreen]; - NSRect aNewScreen = [pScreen frame]; - - // get current screen frame - pScreen = [mpWindow screen]; - if( pScreen ) - { - NSRect aCurScreen = [pScreen frame]; - if( aCurScreen.origin.x != aNewScreen.origin.x || - aCurScreen.origin.y != aNewScreen.origin.y ) - { - NSRect aFrameRect = [mpWindow frame]; - aFrameRect.origin.x += aNewScreen.origin.x - aCurScreen.origin.x; - aFrameRect.origin.y += aNewScreen.origin.y - aCurScreen.origin.y; - [mpWindow setFrame: aFrameRect display: NO]; - UpdateFrameGeometry(); - } - } - } -} - -void AquaSalFrame::SetApplicationID( const rtl::OUString &/*rApplicationID*/ ) -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nDisplay ) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( mbFullScreen == bFullScreen ) - return; - - mbFullScreen = bFullScreen; - if( bFullScreen ) - { - // hide the dock and the menubar if we are on the menu screen - // which is always on index 0 according to documentation - bool bHideMenu = (nDisplay == 0); - - NSRect aNewContentRect = { { 0, 0 }, { 0, 0 } }; - // get correct screen - NSScreen* pScreen = nil; - NSArray* pScreens = [NSScreen screens]; - if( pScreens ) - { - if( nDisplay >= 0 && (unsigned int)nDisplay < [pScreens count] ) - pScreen = [pScreens objectAtIndex: nDisplay]; - else - { - // this means span all screens - bHideMenu = true; - NSEnumerator* pEnum = [pScreens objectEnumerator]; - while( (pScreen = [pEnum nextObject]) != nil ) - { - NSRect aScreenRect = [pScreen frame]; - if( aScreenRect.origin.x < aNewContentRect.origin.x ) - { - aNewContentRect.size.width += aNewContentRect.origin.x - aScreenRect.origin.x; - aNewContentRect.origin.x = aScreenRect.origin.x; - } - if( aScreenRect.origin.y < aNewContentRect.origin.y ) - { - aNewContentRect.size.height += aNewContentRect.origin.y - aScreenRect.origin.y; - aNewContentRect.origin.y = aScreenRect.origin.y; - } - if( aScreenRect.origin.x + aScreenRect.size.width > aNewContentRect.origin.x + aNewContentRect.size.width ) - aNewContentRect.size.width = aScreenRect.origin.x + aScreenRect.size.width - aNewContentRect.origin.x; - if( aScreenRect.origin.y + aScreenRect.size.height > aNewContentRect.origin.y + aNewContentRect.size.height ) - aNewContentRect.size.height = aScreenRect.origin.y + aScreenRect.size.height - aNewContentRect.origin.y; - } - } - } - if( aNewContentRect.size.width == 0 && aNewContentRect.size.height == 0 ) - { - if( pScreen == nil ) - pScreen = [mpWindow screen]; - if( pScreen == nil ) - pScreen = [NSScreen mainScreen]; - - aNewContentRect = [pScreen frame]; - } - - if( bHideMenu ) - [NSMenu setMenuBarVisible:NO]; - - maFullScreenRect = [mpWindow frame]; - { - [mpWindow setFrame: [NSWindow frameRectForContentRect: aNewContentRect styleMask: mnStyleMask] display: mbShown ? YES : NO]; - } - - UpdateFrameGeometry(); - - if( mbShown ) - CallCallback( SALEVENT_MOVERESIZE, NULL ); - } - else - { - { - [mpWindow setFrame: maFullScreenRect display: mbShown ? YES : NO]; - } - UpdateFrameGeometry(); - - if( mbShown ) - CallCallback( SALEVENT_MOVERESIZE, NULL ); - - // show the dock and the menubar - [NSMenu setMenuBarVisible:YES]; - } - if( mbShown ) - // trigger filling our backbuffer - SendPaintEvent(); -} - -// ----------------------------------------------------------------------- - -class PreventSleepTimer : public AutoTimer -{ -public: - PreventSleepTimer() - { - SetTimeout( 30000 ); - Start(); - } - - virtual ~PreventSleepTimer() - { - } - - virtual void Timeout() - { - UpdateSystemActivity(OverallAct); - } -}; - -void AquaSalFrame::StartPresentation( sal_Bool bStart ) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( bStart ) - { - GetSalData()->maPresentationFrames.push_back( this ); - mpActivityTimer.reset( new PreventSleepTimer() ); - [mpWindow setLevel: NSPopUpMenuWindowLevel]; - if( mbShown ) - [mpWindow makeMainWindow]; - } - else - { - GetSalData()->maPresentationFrames.remove( this ); - mpActivityTimer.reset(); - [mpWindow setLevel: NSNormalWindowLevel]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetAlwaysOnTop( sal_Bool ) -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::ToTop(sal_uInt16 nFlags) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( ! (nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN) ) - { - if( ! [mpWindow isVisible] || [mpWindow isMiniaturized] ) - return; - } - if( nFlags & SAL_FRAME_TOTOP_GRABFOCUS ) - [mpWindow makeKeyAndOrderFront: NSApp]; - else - [mpWindow orderFront: NSApp]; -} - -// ----------------------------------------------------------------------- - -NSCursor* AquaSalFrame::getCurrentCursor() const -{ - NSCursor* pCursor = nil; - switch( mePointerStyle ) - { - case POINTER_TEXT: pCursor = [NSCursor IBeamCursor]; break; - case POINTER_CROSS: pCursor = [NSCursor crosshairCursor]; break; - case POINTER_HAND: - case POINTER_MOVE: pCursor = [NSCursor openHandCursor]; break; - case POINTER_NSIZE: pCursor = [NSCursor resizeUpCursor]; break; - case POINTER_SSIZE: pCursor = [NSCursor resizeDownCursor]; break; - case POINTER_ESIZE: pCursor = [NSCursor resizeRightCursor]; break; - case POINTER_WSIZE: pCursor = [NSCursor resizeLeftCursor]; break; - case POINTER_ARROW: pCursor = [NSCursor arrowCursor]; break; - case POINTER_VSPLIT: - case POINTER_VSIZEBAR: - case POINTER_WINDOW_NSIZE: - case POINTER_WINDOW_SSIZE: - pCursor = [NSCursor resizeUpDownCursor]; break; - case POINTER_HSPLIT: - case POINTER_HSIZEBAR: - case POINTER_WINDOW_ESIZE: - case POINTER_WINDOW_WSIZE: - pCursor = [NSCursor resizeLeftRightCursor]; break; - case POINTER_REFHAND: pCursor = [NSCursor pointingHandCursor]; break; - - default: - pCursor = GetSalData()->getCursor( mePointerStyle ); - if( pCursor == nil ) - { - OSL_FAIL( "unmapped cursor" ); - pCursor = [NSCursor arrowCursor]; - } - break; - } - return pCursor; -} - -void AquaSalFrame::SetPointer( PointerStyle ePointerStyle ) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( ePointerStyle >= POINTER_COUNT || ePointerStyle == mePointerStyle ) - return; - mePointerStyle = ePointerStyle; - - [mpWindow invalidateCursorRectsForView: mpView]; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetPointerPos( long nX, long nY ) -{ - // FIXME: use Cocoa functions - - // FIXME: multiscreen support - CGPoint aPoint = { nX + maGeometry.nX, nY + maGeometry.nY }; - CGDirectDisplayID mainDisplayID = CGMainDisplayID(); - CGDisplayMoveCursorToPoint( mainDisplayID, aPoint ); -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::Flush( void ) -{ - if( !(mbGraphics && mpGraphics && mpView && mbShown) ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - - [mpView setNeedsDisplay: YES]; - - // outside of the application's event loop (e.g. IntroWindow) - // nothing would trigger paint event handling - // => fall back to synchronous painting - if( ImplGetSVData()->maAppData.mnDispatchLevel <= 0 ) - { - [mpView display]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::Flush( const Rectangle& rRect ) -{ - if( !(mbGraphics && mpGraphics && mpView && mbShown) ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - NSRect aNSRect = { {rRect.Left(), rRect.Top()}, { rRect.GetWidth(), rRect.GetHeight() } }; - VCLToCocoa( aNSRect, false ); - [mpView setNeedsDisplayInRect: aNSRect]; - - // outside of the application's event loop (e.g. IntroWindow) - // nothing would trigger paint event handling - // => fall back to synchronous painting - if( ImplGetSVData()->maAppData.mnDispatchLevel <= 0 ) - { - [mpView display]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::Sync() -{ - if( mbGraphics && mpGraphics && mpView && mbShown ) - { - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - [mpView setNeedsDisplay: YES]; - [mpView display]; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetInputContext( SalInputContext* pContext ) -{ - if (!pContext) - { - mnICOptions = 0; - return; - } - - mnICOptions = pContext->mnOptions; - - if(!(pContext->mnOptions & SAL_INPUTCONTEXT_TEXT)) - return; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::EndExtTextInput( sal_uInt16 ) -{ -} - -// ----------------------------------------------------------------------- - -XubString AquaSalFrame::GetKeyName( sal_uInt16 nKeyCode ) -{ - static std::map< sal_uInt16, rtl::OUString > aKeyMap; - if( aKeyMap.empty() ) - { - sal_uInt16 i; - for( i = KEY_A; i <= KEY_Z; i++ ) - aKeyMap[ i ] = rtl::OUString( sal_Unicode( 'A' + (i - KEY_A) ) ); - for( i = KEY_0; i <= KEY_9; i++ ) - aKeyMap[ i ] = rtl::OUString( sal_Unicode( '0' + (i - KEY_0) ) ); - for( i = KEY_F1; i <= KEY_F26; i++ ) - { - rtl::OUStringBuffer aKey( 3 ); - aKey.append( sal_Unicode( 'F' ) ); - aKey.append( sal_Int32( i - KEY_F1 + 1 ) ); - aKeyMap[ i ] = aKey.makeStringAndClear(); - } - - aKeyMap[ KEY_DOWN ] = rtl::OUString( sal_Unicode( 0x21e3 ) ); - aKeyMap[ KEY_UP ] = rtl::OUString( sal_Unicode( 0x21e1 ) ); - aKeyMap[ KEY_LEFT ] = rtl::OUString( sal_Unicode( 0x21e0 ) ); - aKeyMap[ KEY_RIGHT ] = rtl::OUString( sal_Unicode( 0x21e2 ) ); - aKeyMap[ KEY_HOME ] = rtl::OUString( sal_Unicode( 0x2196 ) ); - aKeyMap[ KEY_END ] = rtl::OUString( sal_Unicode( 0x2198 ) ); - aKeyMap[ KEY_PAGEUP ] = rtl::OUString( sal_Unicode( 0x21de ) ); - aKeyMap[ KEY_PAGEDOWN ] = rtl::OUString( sal_Unicode( 0x21df ) ); - aKeyMap[ KEY_RETURN ] = rtl::OUString( sal_Unicode( 0x21a9 ) ); - aKeyMap[ KEY_ESCAPE ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "esc" ) ); - aKeyMap[ KEY_TAB ] = rtl::OUString( sal_Unicode( 0x21e5 ) ); - aKeyMap[ KEY_BACKSPACE ]= rtl::OUString( sal_Unicode( 0x232b ) ); - aKeyMap[ KEY_SPACE ] = rtl::OUString( sal_Unicode( 0x2423 ) ); - aKeyMap[ KEY_DELETE ] = rtl::OUString( sal_Unicode( 0x2326 ) ); - aKeyMap[ KEY_ADD ] = rtl::OUString( sal_Unicode( '+' ) ); - aKeyMap[ KEY_SUBTRACT ] = rtl::OUString( sal_Unicode( '-' ) ); - aKeyMap[ KEY_DIVIDE ] = rtl::OUString( sal_Unicode( '/' ) ); - aKeyMap[ KEY_MULTIPLY ] = rtl::OUString( sal_Unicode( '*' ) ); - aKeyMap[ KEY_POINT ] = rtl::OUString( sal_Unicode( '.' ) ); - aKeyMap[ KEY_COMMA ] = rtl::OUString( sal_Unicode( ',' ) ); - aKeyMap[ KEY_LESS ] = rtl::OUString( sal_Unicode( '<' ) ); - aKeyMap[ KEY_GREATER ] = rtl::OUString( sal_Unicode( '>' ) ); - aKeyMap[ KEY_EQUAL ] = rtl::OUString( sal_Unicode( '=' ) ); - aKeyMap[ KEY_OPEN ] = rtl::OUString( sal_Unicode( 0x23cf ) ); - - /* yet unmapped KEYCODES: - aKeyMap[ KEY_INSERT ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_CUT ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_COPY ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_PASTE ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_UNDO ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_REPEAT ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_FIND ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_PROPERTIES ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_FRONT ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_CONTEXTMENU ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_MENU ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_HELP ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_HANGUL_HANJA ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_DECIMAL ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_TILDE ] = rtl::OUString( sal_Unicode( ) ); - aKeyMap[ KEY_QUOTELEFT ]= rtl::OUString( sal_Unicode( ) ); - */ - - } - - rtl::OUStringBuffer aResult( 16 ); - - sal_uInt16 nUnmodifiedCode = (nKeyCode & KEY_CODE); - std::map< sal_uInt16, rtl::OUString >::const_iterator it = aKeyMap.find( nUnmodifiedCode ); - if( it != aKeyMap.end() ) - { - if( (nKeyCode & KEY_SHIFT) != 0 ) - aResult.append( sal_Unicode( 0x21e7 ) ); - if( (nKeyCode & KEY_MOD1) != 0 ) - aResult.append( sal_Unicode( 0x2318 ) ); - // we do not really handle Alt (see below) - // we map it to MOD3, whichis actually Command - if( (nKeyCode & (KEY_MOD2|KEY_MOD3)) != 0 ) - aResult.append( sal_Unicode( 0x2303 ) ); - - aResult.append( it->second ); - } - - return aResult.makeStringAndClear(); -} - -// ----------------------------------------------------------------------- - -XubString AquaSalFrame::GetSymbolKeyName( const XubString&, sal_uInt16 nKeyCode ) -{ - return GetKeyName( nKeyCode ); -} - -// ----------------------------------------------------------------------- - -static void getAppleScrollBarVariant(void) -{ - bool bIsScrollbarDoubleMax = true; // default is DoubleMax - - CFStringRef AppleScrollBarType = CFSTR("AppleScrollBarVariant"); - if( AppleScrollBarType ) - { - CFStringRef ScrollBarVariant = ((CFStringRef)CFPreferencesCopyAppValue( AppleScrollBarType, kCFPreferencesCurrentApplication )); - if( ScrollBarVariant ) - { - if( CFGetTypeID( ScrollBarVariant ) == CFStringGetTypeID() ) - { - // TODO: check for the less important variants "DoubleMin" and "DoubleBoth" too - CFStringRef DoubleMax = CFSTR("DoubleMax"); - if (DoubleMax) - { - if ( !CFStringCompare(ScrollBarVariant, DoubleMax, kCFCompareCaseInsensitive) ) - bIsScrollbarDoubleMax = true; - else - bIsScrollbarDoubleMax = false; - CFRelease(DoubleMax); - } - } - CFRelease( ScrollBarVariant ); - } - CFRelease(AppleScrollBarType); - } - - GetSalData()->mbIsScrollbarDoubleMax = bIsScrollbarDoubleMax; - - CFStringRef jumpScroll = CFSTR("AppleScrollerPagingBehavior"); - if( jumpScroll ) - { - CFBooleanRef jumpStr = ((CFBooleanRef)CFPreferencesCopyAppValue( jumpScroll, kCFPreferencesCurrentApplication )); - if( jumpStr ) - { - if( CFGetTypeID( jumpStr ) == CFBooleanGetTypeID() ) - ImplGetSVData()->maNWFData.mbScrollbarJumpPage = (jumpStr == kCFBooleanTrue); - CFRelease( jumpStr ); - } - CFRelease( jumpScroll ); - } -} - -static Color getColor( NSColor* pSysColor, const Color& rDefault, NSWindow* pWin ) -{ - Color aRet( rDefault ); - if( pSysColor ) - { - // transform to RGB - NSColor* pRBGColor = [pSysColor colorUsingColorSpaceName: NSDeviceRGBColorSpace device: [pWin deviceDescription]]; - if( pRBGColor ) - { - float r = 0, g = 0, b = 0, a = 0; - [pRBGColor getRed: &r green: &g blue: &b alpha: &a]; - aRet = Color( int(r*255.999), int(g*255.999), int(b*255.999) ); - /* - do not release here; leads to duplicate free in yield - it seems the converted color comes out autoreleased, although this - is not documented - [pRBGColor release]; - */ - } - } - return aRet; -} - -static Font getFont( NSFont* pFont, long nDPIY, const Font& rDefault ) -{ - Font aResult( rDefault ); - if( pFont ) - { - aResult.SetName( GetOUString( [pFont familyName] ) ); - aResult.SetHeight( static_cast<int>(([pFont pointSize] * 72.0 / (float)nDPIY)+0.5) ); - aResult.SetItalic( ([pFont italicAngle] != 0.0) ? ITALIC_NORMAL : ITALIC_NONE ); - // FIMXE: bold ? - } - - return aResult; -} - -void AquaSalFrame::getResolution( long& o_rDPIX, long& o_rDPIY ) -{ - if( ! mpGraphics ) - { - GetGraphics(); - ReleaseGraphics( mpGraphics ); - } - mpGraphics->GetResolution( o_rDPIX, o_rDPIY ); -} - -// on OSX-Aqua the style settings are independent of the frame, so it does -// not really belong here. Since the connection to the Appearance_Manager -// is currently done in salnativewidgets.cxx this would be a good place. -// On the other hand VCL's platform independent code currently only asks -// SalFrames for system settings anyway, so moving the code somewhere else -// doesn't make the anything cleaner for now -void AquaSalFrame::UpdateSettings( AllSettings& rSettings ) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - [mpView lockFocus]; - - StyleSettings aStyleSettings = rSettings.GetStyleSettings(); - - // Background Color - Color aBackgroundColor = Color( 0xEC, 0xEC, 0xEC ); - aStyleSettings.Set3DColors( aBackgroundColor ); - aStyleSettings.SetFaceColor( aBackgroundColor ); - Color aInactiveTabColor( aBackgroundColor ); - aInactiveTabColor.DecreaseLuminance( 32 ); - aStyleSettings.SetInactiveTabColor( aInactiveTabColor ); - - aStyleSettings.SetDialogColor( aBackgroundColor ); - aStyleSettings.SetLightBorderColor( aBackgroundColor ); - Color aShadowColor( aStyleSettings.GetShadowColor() ); - aStyleSettings.SetDarkShadowColor( aShadowColor ); - aShadowColor.IncreaseLuminance( 32 ); - aStyleSettings.SetShadowColor( aShadowColor ); - - // get the system font settings - Font aAppFont = aStyleSettings.GetAppFont(); - long nDPIX = 72, nDPIY = 72; - getResolution( nDPIX, nDPIY ); - aAppFont = getFont( [NSFont systemFontOfSize: 0], nDPIY, aAppFont ); - - aStyleSettings.SetToolbarIconSize( nDPIY > 160 ? STYLE_TOOLBAR_ICONSIZE_LARGE : STYLE_TOOLBAR_ICONSIZE_SMALL ); - - // TODO: better mapping of aqua<->ooo font settings - aStyleSettings.SetAppFont( aAppFont ); - aStyleSettings.SetHelpFont( aAppFont ); - aStyleSettings.SetPushButtonFont( aAppFont ); - - Font aTitleFont( getFont( [NSFont titleBarFontOfSize: 0], nDPIY, aAppFont ) ); - aStyleSettings.SetTitleFont( aTitleFont ); - aStyleSettings.SetFloatTitleFont( aTitleFont ); - - Font aMenuFont( getFont( [NSFont menuFontOfSize: 0], nDPIY, aAppFont ) ); - aStyleSettings.SetMenuFont( aMenuFont ); - - aStyleSettings.SetToolFont( aAppFont ); - - Font aLabelFont( getFont( [NSFont labelFontOfSize: 0], nDPIY, aAppFont ) ); - aStyleSettings.SetLabelFont( aLabelFont ); - aStyleSettings.SetInfoFont( aLabelFont ); - aStyleSettings.SetRadioCheckFont( aLabelFont ); - aStyleSettings.SetFieldFont( aLabelFont ); - aStyleSettings.SetGroupFont( aLabelFont ); - aStyleSettings.SetIconFont( aLabelFont ); - - Color aHighlightColor( getColor( [NSColor selectedTextBackgroundColor], - aStyleSettings.GetHighlightColor(), mpWindow ) ); - aStyleSettings.SetHighlightColor( aHighlightColor ); - Color aHighlightTextColor( getColor( [NSColor selectedTextColor], - aStyleSettings.GetHighlightTextColor(), mpWindow ) ); - aStyleSettings.SetHighlightTextColor( aHighlightTextColor ); - - Color aMenuHighlightColor( getColor( [NSColor selectedMenuItemColor], - aStyleSettings.GetMenuHighlightColor(), mpWindow ) ); - aStyleSettings.SetMenuHighlightColor( aMenuHighlightColor ); - Color aMenuHighlightTextColor( getColor( [NSColor selectedMenuItemTextColor], - aStyleSettings.GetMenuHighlightTextColor(), mpWindow ) ); - aStyleSettings.SetMenuHighlightTextColor( aMenuHighlightTextColor ); - - aStyleSettings.SetMenuColor( aBackgroundColor ); - Color aMenuTextColor( getColor( [NSColor textColor], - aStyleSettings.GetMenuTextColor(), mpWindow ) ); - aStyleSettings.SetMenuTextColor( aMenuTextColor ); - aStyleSettings.SetMenuBarTextColor( aMenuTextColor ); - - aStyleSettings.SetCursorBlinkTime( 500 ); - - // no mnemonics on aqua - aStyleSettings.SetOptions( aStyleSettings.GetOptions() | STYLE_OPTION_NOMNEMONICS ); - - getAppleScrollBarVariant(); - - // set scrollbar size - aStyleSettings.SetScrollBarSize( static_cast<long int>([NSScroller scrollerWidth]) ); - - // images in menus false for MacOSX - aStyleSettings.SetPreferredUseImagesInMenus( false ); - aStyleSettings.SetHideDisabledMenuItems( sal_True ); - aStyleSettings.SetAcceleratorsInContextMenus( sal_False ); - - rSettings.SetStyleSettings( aStyleSettings ); - - [mpView unlockFocus]; -} - -// ----------------------------------------------------------------------- - -const SystemEnvData* AquaSalFrame::GetSystemData() const -{ - return &maSysData; -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::Beep( SoundType eSoundType ) -{ - switch( eSoundType ) - { - case SOUND_DISABLE: - // don't beep - break; - default: - NSBeep(); - break; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::SetPosSize(long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - sal_uInt16 nEvent = 0; - - if( [mpWindow isMiniaturized] ) - [mpWindow deminiaturize: NSApp]; // expand the window - - if (nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y)) - { - mbPositioned = true; - nEvent = SALEVENT_MOVE; - } - - if (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) - { - mbSized = true; - nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE; - } - - NSRect aFrameRect = [mpWindow frame]; - NSRect aContentRect = [NSWindow contentRectForFrameRect: aFrameRect styleMask: mnStyleMask]; - - // position is always relative to parent frame - NSRect aParentContentRect; - - if( mpParent ) - { - if( Application::GetSettings().GetLayoutRTL() ) - { - if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 ) - nX = mpParent->maGeometry.nWidth - nWidth-1 - nX; - else - nX = mpParent->maGeometry.nWidth - static_cast<long int>( aContentRect.size.width-1) - nX; - } - NSRect aParentFrameRect = [mpParent->mpWindow frame]; - aParentContentRect = [NSWindow contentRectForFrameRect: aParentFrameRect styleMask: mpParent->mnStyleMask]; - } - else - aParentContentRect = maScreenRect; // use screen if no parent - - CocoaToVCL( aContentRect ); - CocoaToVCL( aParentContentRect ); - - bool bPaint = false; - if( (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) != 0 ) - { - if( nWidth != aContentRect.size.width || nHeight != aContentRect.size.height ) - bPaint = true; - } - - // use old window pos if no new pos requested - if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 ) - aContentRect.origin.x = nX + aParentContentRect.origin.x; - if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0) - aContentRect.origin.y = nY + aParentContentRect.origin.y; - - // use old size if no new size requested - if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 ) - aContentRect.size.width = nWidth; - if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0) - aContentRect.size.height = nHeight; - - VCLToCocoa( aContentRect ); - - // do not display yet, we need to update our backbuffer - { - [mpWindow setFrame: [NSWindow frameRectForContentRect: aContentRect styleMask: mnStyleMask] display: NO]; - } - - UpdateFrameGeometry(); - - if (nEvent) - CallCallback(nEvent, NULL); - - if( mbShown && bPaint ) - { - // trigger filling our backbuffer - SendPaintEvent(); - - // now inform the system that the views need to be drawn - [mpWindow display]; - } -} - -void AquaSalFrame::GetWorkArea( Rectangle& rRect ) -{ - if ( !mpWindow ) - return; - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - NSScreen* pScreen = [mpWindow screen]; - if( pScreen == nil ) - pScreen = [NSScreen mainScreen]; - NSRect aRect = [pScreen visibleFrame]; - CocoaToVCL( aRect ); - rRect.nLeft = static_cast<long>(aRect.origin.x); - rRect.nTop = static_cast<long>(aRect.origin.y); - rRect.nRight = static_cast<long>(aRect.origin.x + aRect.size.width - 1); - rRect.nBottom = static_cast<long>(aRect.origin.y + aRect.size.height - 1); -} - -SalPointerState AquaSalFrame::GetPointerState() -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - SalPointerState state; - state.mnState = 0; - - // get position - NSPoint aPt = [mpWindow mouseLocationOutsideOfEventStream]; - CocoaToVCL( aPt, false ); - state.maPos = Point(static_cast<long>(aPt.x), static_cast<long>(aPt.y)); - - NSEvent* pCur = [NSApp currentEvent]; - bool bMouseEvent = false; - if( pCur ) - { - bMouseEvent = true; - switch( [pCur type] ) - { - case NSLeftMouseDown: state.mnState |= MOUSE_LEFT; break; - case NSLeftMouseUp: break; - case NSRightMouseDown: state.mnState |= MOUSE_RIGHT; break; - case NSRightMouseUp: break; - case NSOtherMouseDown: state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; break; - case NSOtherMouseUp: break; - case NSMouseMoved: break; - case NSLeftMouseDragged: state.mnState |= MOUSE_LEFT; break; - case NSRightMouseDragged: state.mnState |= MOUSE_RIGHT; break; - case NSOtherMouseDragged: state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; break; - break; - default: - bMouseEvent = false; - break; - } - } - if( bMouseEvent ) - { - unsigned int nMask = (unsigned int)[pCur modifierFlags]; - if( (nMask & NSShiftKeyMask) != 0 ) - state.mnState |= KEY_SHIFT; - if( (nMask & NSControlKeyMask) != 0 ) - state.mnState |= KEY_MOD3; - if( (nMask & NSAlternateKeyMask) != 0 ) - state.mnState |= KEY_MOD2; - if( (nMask & NSCommandKeyMask) != 0 ) - state.mnState |= KEY_MOD1; - - } - else - { - // FIXME: replace Carbon by Cocoa - // Cocoa does not have an equivalent for GetCurrentEventButtonState - // and GetCurrentEventKeyModifiers. - // we could try to get away with tracking all events for modifierKeys - // and all mouse events for button state in VCL_NSApllication::sendEvent, - // but it is unclear whether this will get us the same result. - // leave in GetCurrentEventButtonState and GetCurrentEventKeyModifiers for now - - // fill in button state - UInt32 nState = GetCurrentEventButtonState(); - state.mnState = 0; - if( nState & 1 ) - state.mnState |= MOUSE_LEFT; // primary button - if( nState & 2 ) - state.mnState |= MOUSE_RIGHT; // secondary button - if( nState & 4 ) - state.mnState |= MOUSE_MIDDLE; // tertiary button - - // fill in modifier state - nState = GetCurrentEventKeyModifiers(); - if( nState & shiftKey ) - state.mnState |= KEY_SHIFT; - if( nState & controlKey ) - state.mnState |= KEY_MOD3; - if( nState & optionKey ) - state.mnState |= KEY_MOD2; - if( nState & cmdKey ) - state.mnState |= KEY_MOD1; - } - - - return state; -} - -SalFrame::SalIndicatorState AquaSalFrame::GetIndicatorState() -{ - SalIndicatorState aState; - aState.mnState = 0; - return aState; -} - -void AquaSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ ) -{ -} - -bool AquaSalFrame::SetPluginParent( SystemParentData* ) -{ - // plugin parent may be killed unexpectedly by - // plugging process; - - //TODO: implement - return sal_False; -} - -sal_Bool AquaSalFrame::MapUnicodeToKeyCode( sal_Unicode , LanguageType , KeyCode& ) -{ - // not supported yet - return FALSE; -} - -LanguageType AquaSalFrame::GetInputLanguage() -{ - //TODO: implement - return LANGUAGE_DONTKNOW; -} - -void AquaSalFrame::DrawMenuBar() -{ -} - -void AquaSalFrame::SetMenu( SalMenu* pSalMenu ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - AquaSalMenu* pMenu = static_cast<AquaSalMenu*>(pSalMenu); - DBG_ASSERT( ! pMenu || pMenu->mbMenuBar, "setting non menubar on frame" ); - mpMenu = pMenu; - if( mpMenu ) - mpMenu->setMainMenu(); -} - -void AquaSalFrame::SetExtendedFrameStyle( SalExtStyle nStyle ) -{ - if ( mpWindow ) - { - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( (mnExtStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) != (nStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) ) - [mpWindow setDocumentEdited: (nStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) ? YES : NO]; - } - - mnExtStyle = nStyle; -} - -void AquaSalFrame::SetBackgroundBitmap( SalBitmap* ) -{ - //TODO: implement -} - -SalBitmap* AquaSalFrame::SnapShot() -{ - return mpGraphics ? mpGraphics->getBitmap( 0, 0, maGeometry.nWidth, maGeometry.nHeight ) : NULL; -} - -SalFrame* AquaSalFrame::GetParent() const -{ - return mpParent; -} - -void AquaSalFrame::SetParent( SalFrame* pNewParent ) -{ - bool bShown = mbShown; - // remove from child list - Show( FALSE ); - mpParent = (AquaSalFrame*)pNewParent; - // insert to correct parent and paint - Show( bShown ); -} - -void AquaSalFrame::UpdateFrameGeometry() -{ - if ( !mpWindow ) - { - return; - } - - // keep in mind that view and window coordinates are lower left - // whereas vcl's are upper left - - // update screen rect - NSScreen * pScreen = [mpWindow screen]; - if( pScreen ) - { - maScreenRect = [pScreen frame]; - NSArray* pScreens = [NSScreen screens]; - if( pScreens ) - maGeometry.nScreenNumber = [pScreens indexOfObject: pScreen]; - } - - NSRect aFrameRect = [mpWindow frame]; - NSRect aContentRect = [NSWindow contentRectForFrameRect: aFrameRect styleMask: mnStyleMask]; - - // release old track rect - [mpView removeTrackingRect: mnTrackingRectTag]; - // install the new track rect - NSRect aTrackRect = { { 0, 0 }, aContentRect.size }; - mnTrackingRectTag = [mpView addTrackingRect: aTrackRect owner: mpView userData: nil assumeInside: NO]; - - // convert to vcl convention - CocoaToVCL( aFrameRect ); - CocoaToVCL( aContentRect ); - - maGeometry.nX = static_cast<int>(aContentRect.origin.x); - maGeometry.nY = static_cast<int>(aContentRect.origin.y); - - maGeometry.nLeftDecoration = static_cast<unsigned int>(aContentRect.origin.x - aFrameRect.origin.x); - maGeometry.nRightDecoration = static_cast<unsigned int>((aFrameRect.origin.x + aFrameRect.size.width) - - (aContentRect.origin.x + aContentRect.size.width)); - - maGeometry.nTopDecoration = static_cast<unsigned int>(aContentRect.origin.y - aFrameRect.origin.y); - maGeometry.nBottomDecoration = static_cast<unsigned int>((aFrameRect.origin.y + aFrameRect.size.height) - - (aContentRect.origin.y + aContentRect.size.height)); - - maGeometry.nWidth = static_cast<unsigned int>(aContentRect.size.width); - maGeometry.nHeight = static_cast<unsigned int>(aContentRect.size.height); -} - -// ----------------------------------------------------------------------- - -void AquaSalFrame::CaptureMouse( sal_Bool bCapture ) -{ - /* Remark: - we'll try to use a pidgin version of capture mouse - on MacOSX (neither carbon nor cocoa) there is a - CaptureMouse equivalent (in Carbon there is TrackMouseLocation - but this is useless to use since it is blocking) - - However on cocoa the active frame seems to get mouse events - also outside the window, so we'll try to forward mouse events - to the capture frame in the hope that one of our frames - gets a mouse event. - - This will break as soon as the user activates another app, but - a mouse click will normally lead to a release of the mouse anyway. - - Let's see how far we get this way. Alternatively we could use one - large overlay window like we did for the carbon implementation, - however that is resource intensive. - */ - - if( bCapture ) - s_pCaptureFrame = this; - else if( ! bCapture && s_pCaptureFrame == this ) - s_pCaptureFrame = NULL; -} - -void AquaSalFrame::ResetClipRegion() -{ - if ( !mpWindow ) - { - return; - } - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - // release old path and indicate no clipping - CGPathRelease( mrClippingPath ); - mrClippingPath = NULL; - - if( mpView && mbShown ) - [mpView setNeedsDisplay: YES]; - if( mpWindow ) - { - [mpWindow setOpaque: YES]; - [mpWindow invalidateShadow]; - } -} - -void AquaSalFrame::BeginSetClipRegion( sal_uLong nRects ) -{ - if ( !mpWindow ) - { - return; - } - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - // release old path - if( mrClippingPath ) - { - CGPathRelease( mrClippingPath ); - mrClippingPath = NULL; - } - - if( maClippingRects.size() > SAL_CLIPRECT_COUNT && nRects < maClippingRects.size() ) - { - std::vector<CGRect> aEmptyVec; - maClippingRects.swap( aEmptyVec ); - } - maClippingRects.clear(); - maClippingRects.reserve( nRects ); -} - -void AquaSalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight ) -{ - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( nWidth && nHeight ) - { - NSRect aRect = { { nX, nY }, { nWidth, nHeight } }; - VCLToCocoa( aRect, false ); - maClippingRects.push_back( CGRectMake(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height) ); - } -} - -void AquaSalFrame::EndSetClipRegion() -{ - if ( !mpWindow ) - { - return; - } - - // #i113170# may not be the main thread if called from UNO API - SalData::ensureThreadAutoreleasePool(); - - if( ! maClippingRects.empty() ) - { - mrClippingPath = CGPathCreateMutable(); - CGPathAddRects( mrClippingPath, NULL, &maClippingRects[0], maClippingRects.size() ); - } - if( mpView && mbShown ) - [mpView setNeedsDisplay: YES]; - if( mpWindow ) - { - [mpWindow setOpaque: (mrClippingPath != NULL) ? NO : YES]; - [mpWindow setBackgroundColor: [NSColor clearColor]]; - // shadow is invalidated when view gets drawn again - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/aqua/source/window/salframeview.mm b/vcl/aqua/source/window/salframeview.mm deleted file mode 100644 index 54ebe8090f..0000000000 --- a/vcl/aqua/source/window/salframeview.mm +++ /dev/null @@ -1,1732 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/*n*********************************************************************** - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_vcl.hxx" - -#include <sal/alloca.h> -#include <sal/macros.h> - -#include "vcl/window.hxx" -#include "vcl/svapp.hxx" - -#include "aqua/salinst.h" -#include "aqua/salgdi.h" -#include "aqua/salframe.h" -#include "aqua/salframeview.h" -#include "aqua/aqua11yfactory.h" - -#define WHEEL_EVENT_FACTOR 1.5 - -static sal_uInt16 ImplGetModifierMask( unsigned int nMask ) -{ - sal_uInt16 nRet = 0; - if( (nMask & NSShiftKeyMask) != 0 ) - nRet |= KEY_SHIFT; - if( (nMask & NSControlKeyMask) != 0 ) - nRet |= KEY_MOD3; - if( (nMask & NSAlternateKeyMask) != 0 ) - nRet |= KEY_MOD2; - if( (nMask & NSCommandKeyMask) != 0 ) - nRet |= KEY_MOD1; - return nRet; -} - -static sal_uInt16 ImplMapCharCode( sal_Unicode aCode ) -{ - static sal_uInt16 aKeyCodeMap[ 128 ] = - { - 0, 0, 0, 0, 0, 0, 0, 0, - KEY_BACKSPACE, KEY_TAB, KEY_RETURN, 0, 0, KEY_RETURN, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, KEY_TAB, 0, KEY_ESCAPE, 0, 0, 0, 0, - KEY_SPACE, 0, 0, 0, 0, 0, 0, 0, - 0, 0, KEY_MULTIPLY, KEY_ADD, KEY_COMMA, KEY_SUBTRACT, KEY_POINT, KEY_DIVIDE, - KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, - KEY_8, KEY_9, 0, 0, KEY_LESS, KEY_EQUAL, KEY_GREATER, 0, - 0, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, - KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, - KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, - KEY_X, KEY_Y, KEY_Z, 0, 0, 0, 0, 0, - KEY_QUOTELEFT, KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, - KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, - KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, - KEY_X, KEY_Y, KEY_Z, 0, 0, 0, KEY_TILDE, KEY_BACKSPACE - }; - - // Note: the mapping 0x7f should by rights be KEY_DELETE - // however if you press "backspace" 0x7f is reported - // whereas for "delete" 0xf728 gets reported - - // Note: the mapping of 0x19 to KEY_TAB is because for unknown reasons - // tab alone is reported as 0x09 (as expected) but shift-tab is - // reported as 0x19 (end of medium) - - static sal_uInt16 aFunctionKeyCodeMap[ 128 ] = - { - KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_F1, KEY_F2, KEY_F3, KEY_F4, - KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, - KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, - KEY_F21, KEY_F22, KEY_F23, KEY_F24, KEY_F25, KEY_F26, 0, 0, - 0, 0, 0, 0, 0, 0, 0, KEY_INSERT, - KEY_DELETE, KEY_HOME, 0, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN, 0, 0, - 0, 0, 0, 0, 0, KEY_MENU, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, KEY_UNDO, KEY_REPEAT, KEY_FIND, KEY_HELP, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - }; - - sal_uInt16 nKeyCode = 0; - if( aCode < SAL_N_ELEMENTS( aKeyCodeMap) ) - nKeyCode = aKeyCodeMap[ aCode ]; - else if( aCode >= 0xf700 && aCode < 0xf780 ) - nKeyCode = aFunctionKeyCodeMap[ aCode - 0xf700 ]; - return nKeyCode; -} - -// store the frame the mouse last entered -static AquaSalFrame* s_pMouseFrame = NULL; -// store the last pressed button for enter/exit events -// which lack that information -static sal_uInt16 s_nLastButton = 0; - -// combinations of keys we need to handle ourselves -static const struct ExceptionalKey -{ - const sal_uInt16 nKeyCode; - const unsigned int nModifierMask; -} aExceptionalKeys[] = -{ - { KEY_D, NSControlKeyMask | NSShiftKeyMask | NSAlternateKeyMask }, - { KEY_D, NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask } -}; - -static AquaSalFrame* getMouseContainerFrame() -{ - int nWindows = 0; - NSCountWindows( &nWindows ); - int* pWindows = (int*)alloca( nWindows * sizeof(int) ); - // note: NSWindowList is supposed to be in z-order front to back - NSWindowList( nWindows, pWindows ); - AquaSalFrame* pDispatchFrame = NULL; - for(int i = 0; i < nWindows && ! pDispatchFrame; i++ ) - { - NSWindow* pWin = [NSApp windowWithWindowNumber: pWindows[i]]; - if( pWin && [pWin isMemberOfClass: [SalFrameWindow class]] && [(SalFrameWindow*)pWin containsMouse] ) - pDispatchFrame = [(SalFrameWindow*)pWin getSalFrame]; - } - return pDispatchFrame; -} - -@implementation SalFrameWindow --(id)initWithSalFrame: (AquaSalFrame*)pFrame -{ - mDraggingDestinationHandler = nil; - mpFrame = pFrame; - NSRect aRect = { { pFrame->maGeometry.nX, pFrame->maGeometry.nY }, - { pFrame->maGeometry.nWidth, pFrame->maGeometry.nHeight } }; - pFrame->VCLToCocoa( aRect ); - NSWindow* pNSWindow = [super initWithContentRect: aRect styleMask: mpFrame->getStyleMask() backing: NSBackingStoreBuffered defer: NO ]; - [pNSWindow useOptimizedDrawing: YES]; // OSX recommendation when there are no overlapping subviews within the receiver - return pNSWindow; -} - --(AquaSalFrame*)getSalFrame -{ - return mpFrame; -} - --(void)displayIfNeeded -{ - if( GetSalData() && GetSalData()->mpFirstInstance ) - { - osl::SolarMutex* pMutex = GetSalData()->mpFirstInstance->GetYieldMutex(); - if( pMutex ) - { - pMutex->acquire(); - [super displayIfNeeded]; - pMutex->release(); - } - } -} - --(BOOL)containsMouse -{ - // is this event actually inside that NSWindow ? - NSPoint aPt = [NSEvent mouseLocation]; - NSRect aFrameRect = [self frame]; - BOOL bInRect = NSPointInRect( aPt, aFrameRect ); - return bInRect; -} - --(BOOL)canBecomeKeyWindow -{ - if( (mpFrame->mnStyle & - ( SAL_FRAME_STYLE_FLOAT | - SAL_FRAME_STYLE_TOOLTIP | - SAL_FRAME_STYLE_INTRO - )) == 0 ) - return YES; - if( (mpFrame->mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) != 0 ) - return YES; - if( mpFrame->mbFullScreen ) - return YES; - if( (mpFrame->mnStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE) ) - return YES; - return [super canBecomeKeyWindow]; -} - --(void)windowDidBecomeKey: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - static const sal_uLong nGuessDocument = SAL_FRAME_STYLE_MOVEABLE| - SAL_FRAME_STYLE_SIZEABLE| - SAL_FRAME_STYLE_CLOSEABLE; - - if( mpFrame->mpMenu ) - mpFrame->mpMenu->setMainMenu(); - else if( ! mpFrame->mpParent && - ( (mpFrame->mnStyle & nGuessDocument) == nGuessDocument || // set default menu for e.g. help - mpFrame->mbFullScreen ) ) // ser default menu for e.g. presentation - { - AquaSalMenu::setDefaultMenu(); - } - #if 0 - // FIXME: we should disable menus while in modal mode - // however from down here there is currently no reliable way to - // find out when to do this - if( (mpFrame->mpParent && mpFrame->mpParent->GetWindow()->IsInModalMode()) ) - AquaSalMenu::enableMainMenu( false ); - #endif - mpFrame->CallCallback( SALEVENT_GETFOCUS, 0 ); - mpFrame->SendPaintEvent(); // repaint controls as active - } -} - --(void)windowDidResignKey: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->CallCallback(SALEVENT_LOSEFOCUS, 0); - mpFrame->SendPaintEvent(); // repaint controls as inactive - } -} - --(void)windowDidChangeScreen: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - mpFrame->screenParametersChanged(); -} - --(void)windowDidMove: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->UpdateFrameGeometry(); - mpFrame->CallCallback( SALEVENT_MOVE, 0 ); - } -} - --(void)windowDidResize: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->UpdateFrameGeometry(); - mpFrame->CallCallback( SALEVENT_RESIZE, 0 ); - mpFrame->SendPaintEvent(); - } -} - --(void)windowDidMiniaturize: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->mbShown = false; - mpFrame->UpdateFrameGeometry(); - mpFrame->CallCallback( SALEVENT_RESIZE, 0 ); - } -} - --(void)windowDidDeminiaturize: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->mbShown = true; - mpFrame->UpdateFrameGeometry(); - mpFrame->CallCallback( SALEVENT_RESIZE, 0 ); - } -} - --(BOOL)windowShouldClose: (NSNotification*)pNotification -{ - (void)pNotification; - YIELD_GUARD; - - BOOL bRet = YES; - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - // #i84461# end possible input - mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 ); - if( AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->CallCallback( SALEVENT_CLOSE, 0 ); - bRet = NO; // application will close the window or not, AppKit shouldn't - } - } - - return bRet; -} - --(void)dockMenuItemTriggered: (id)sender -{ - (void)sender; - YIELD_GUARD; - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - mpFrame->ToTop( SAL_FRAME_TOTOP_RESTOREWHENMIN | SAL_FRAME_TOTOP_GRABFOCUS ); -} - --(::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessibleContext >)accessibleContext -{ - return mpFrame -> GetWindow() -> GetAccessible() -> getAccessibleContext(); -} - --(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler draggingEntered: sender]; -} - --(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler draggingUpdated: sender]; -} - --(void)draggingExited:(id <NSDraggingInfo>)sender -{ - [mDraggingDestinationHandler draggingExited: sender]; -} - --(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler prepareForDragOperation: sender]; -} - --(BOOL)performDragOperation:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler performDragOperation: sender]; -} - --(void)concludeDragOperation:(id <NSDraggingInfo>)sender -{ - [mDraggingDestinationHandler concludeDragOperation: sender]; -} - --(void)registerDraggingDestinationHandler:(id)theHandler -{ - mDraggingDestinationHandler = theHandler; -} - --(void)unregisterDraggingDestinationHandler:(id)theHandler -{ - (void)theHandler; - mDraggingDestinationHandler = nil; -} - -@end - -@implementation SalFrameView -+(void)unsetMouseFrame: (AquaSalFrame*)pFrame -{ - if( pFrame == s_pMouseFrame ) - s_pMouseFrame = NULL; -} - --(id)initWithSalFrame: (AquaSalFrame*)pFrame -{ - if ((self = [super initWithFrame: [NSWindow contentRectForFrameRect: [pFrame->getWindow() frame] styleMask: pFrame->mnStyleMask]]) != nil) - { - mDraggingDestinationHandler = nil; - mpFrame = pFrame; - mMarkedRange = NSMakeRange(NSNotFound, 0); - mSelectedRange = NSMakeRange(NSNotFound, 0); - mpReferenceWrapper = nil; - mpMouseEventListener = nil; - mpLastSuperEvent = nil; - } - - mfLastMagnifyTime = 0.0; - return self; -} - --(AquaSalFrame*)getSalFrame -{ - return mpFrame; -} - --(void)resetCursorRects -{ - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - // FIXME: does this leak the returned NSCursor of getCurrentCursor ? - NSRect aRect = { { 0, 0 }, { mpFrame->maGeometry.nWidth, mpFrame->maGeometry.nHeight } }; - [self addCursorRect: aRect cursor: mpFrame->getCurrentCursor()]; - } -} - --(BOOL)acceptsFirstResponder -{ - return YES; -} - --(BOOL)acceptsFirstMouse: (NSEvent*)pEvent -{ - (void)pEvent; - return YES; -} - --(BOOL)isOpaque -{ - return mpFrame ? (mpFrame->getClipPath() != 0 ? NO : YES) : YES; -} - -// helper class similar to a osl::SolarGuard for the SalYieldMutex -// the difference is that it only does tryToAcquire instead of aquire -// so dreaded deadlocks like #i93512# are prevented -class TryGuard -{ -public: - TryGuard() { mbGuarded = ImplSalYieldMutexTryToAcquire(); } - ~TryGuard() { if( mbGuarded ) ImplSalYieldMutexRelease(); } - bool IsGuarded() { return mbGuarded; } -private: - bool mbGuarded; -}; - --(void)drawRect: (NSRect)aRect -{ - // HOTFIX: #i93512# prevent deadlocks if any other thread already has the SalYieldMutex - TryGuard aTryGuard; - if( !aTryGuard.IsGuarded() ) - { - // NOTE: the mpFrame access below is not guarded yet! - // TODO: mpFrame et al need to be guarded by an independent mutex - AquaSalGraphics* pGraphics = (mpFrame && AquaSalFrame::isAlive(mpFrame)) ? mpFrame->mpGraphics : NULL; - if( pGraphics ) - { - // we did not get the mutex so we cannot draw now => request to redraw later - // convert the NSRect to a CGRect for Refreshrect() - const CGRect aCGRect = {{aRect.origin.x,aRect.origin.y},{aRect.size.width,aRect.size.height}}; - pGraphics->RefreshRect( aCGRect ); - } - return; - } - - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) ) - { - if( mpFrame->mpGraphics ) - { - mpFrame->mpGraphics->UpdateWindow( aRect ); - if( mpFrame->getClipPath() ) - [mpFrame->getWindow() invalidateShadow]; - } - } -} - --(void)sendMouseEventToFrame: (NSEvent*)pEvent button:(sal_uInt16)nButton eventtype:(sal_uInt16)nEvent -{ - YIELD_GUARD; - - AquaSalFrame* pDispatchFrame = AquaSalFrame::GetCaptureFrame(); - bool bIsCaptured = false; - if( pDispatchFrame ) - { - bIsCaptured = true; - if( nEvent == SALEVENT_MOUSELEAVE ) // no leave events if mouse is captured - nEvent = SALEVENT_MOUSEMOVE; - } - else if( s_pMouseFrame ) - pDispatchFrame = s_pMouseFrame; - else - pDispatchFrame = mpFrame; - - /* #i81645# Cocoa reports mouse events while a button is pressed - to the window in which it was first pressed. This is reasonable and fine and - gets one around most cases where on other platforms one uses CaptureMouse or XGrabPointer, - however vcl expects mouse events to occur in the window the mouse is over, unless the - mouse is explicitly captured. So we need to find the window the mouse is actually - over for conformance with other platforms. - */ - if( ! bIsCaptured && nButton && pDispatchFrame && AquaSalFrame::isAlive( pDispatchFrame ) ) - { - // is this event actually inside that NSWindow ? - NSPoint aPt = [NSEvent mouseLocation]; - NSRect aFrameRect = [pDispatchFrame->getWindow() frame]; - - if ( ! NSPointInRect( aPt, aFrameRect ) ) - { - // no, it is not - // now we need to find the one it may be in - /* #i93756# we ant to get enumerate the application windows in z-order - to check if any contains the mouse. This could be elegantly done with this - code: - - // use NSApp to check windows in ZOrder whether they contain the mouse pointer - NSWindow* pWindow = [NSApp makeWindowsPerform: @selector(containsMouse) inOrder: YES]; - if( pWindow && [pWindow isMemberOfClass: [SalFrameWindow class]] ) - pDispatchFrame = [(SalFrameWindow*)pWindow getSalFrame]; - - However if a non SalFrameWindow is on screen (like e.g. the file dialog) - it can be hit with the containsMouse selector, which it doesn't support. - Sadly NSApplication:makeWindowsPerform does not check (for performance reasons - I assume) whether a window supports a selector before sending it. - */ - AquaSalFrame* pMouseFrame = getMouseContainerFrame(); - if( pMouseFrame ) - pDispatchFrame = pMouseFrame; - } - } - - if( pDispatchFrame && AquaSalFrame::isAlive( pDispatchFrame ) ) - { - pDispatchFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 ); - pDispatchFrame->mnLastModifierFlags = [pEvent modifierFlags]; - - NSPoint aPt = [NSEvent mouseLocation]; - pDispatchFrame->CocoaToVCL( aPt ); - - sal_uInt16 nModMask = ImplGetModifierMask( [pEvent modifierFlags] ); - // #i82284# emulate ctrl left - if( nModMask == KEY_MOD3 && nButton == MOUSE_LEFT ) - { - nModMask = 0; - nButton = MOUSE_RIGHT; - } - - SalMouseEvent aEvent; - aEvent.mnTime = pDispatchFrame->mnLastEventTime; - aEvent.mnX = static_cast<long>(aPt.x) - pDispatchFrame->maGeometry.nX; - aEvent.mnY = static_cast<long>(aPt.y) - pDispatchFrame->maGeometry.nY; - aEvent.mnButton = nButton; - aEvent.mnCode = aEvent.mnButton | nModMask; - - // --- RTL --- (mirror mouse pos) - if( Application::GetSettings().GetLayoutRTL() ) - aEvent.mnX = pDispatchFrame->maGeometry.nWidth-1-aEvent.mnX; - - pDispatchFrame->CallCallback( nEvent, &aEvent ); - } -} - --(void)mouseDown: (NSEvent*)pEvent -{ - if ( mpMouseEventListener != nil && - [mpMouseEventListener respondsToSelector: @selector(mouseDown:)]) - { - [mpMouseEventListener mouseDown: [pEvent copyWithZone: NULL]]; - } - - s_nLastButton = MOUSE_LEFT; - [self sendMouseEventToFrame:pEvent button:MOUSE_LEFT eventtype:SALEVENT_MOUSEBUTTONDOWN]; -} - --(void)mouseDragged: (NSEvent*)pEvent -{ - if ( mpMouseEventListener != nil && - [mpMouseEventListener respondsToSelector: @selector(mouseDragged:)]) - { - [mpMouseEventListener mouseDragged: [pEvent copyWithZone: NULL]]; - } - s_nLastButton = MOUSE_LEFT; - [self sendMouseEventToFrame:pEvent button:MOUSE_LEFT eventtype:SALEVENT_MOUSEMOVE]; -} - --(void)mouseUp: (NSEvent*)pEvent -{ - s_nLastButton = 0; - [self sendMouseEventToFrame:pEvent button:MOUSE_LEFT eventtype:SALEVENT_MOUSEBUTTONUP]; -} - --(void)mouseMoved: (NSEvent*)pEvent -{ - s_nLastButton = 0; - [self sendMouseEventToFrame:pEvent button:0 eventtype:SALEVENT_MOUSEMOVE]; -} - --(void)mouseEntered: (NSEvent*)pEvent -{ - s_pMouseFrame = mpFrame; - - // #i107215# the only mouse events we get when inactive are enter/exit - // actually we would like to have all of them, but better none than some - if( [NSApp isActive] ) - [self sendMouseEventToFrame:pEvent button:s_nLastButton eventtype:SALEVENT_MOUSEMOVE]; -} - --(void)mouseExited: (NSEvent*)pEvent -{ - if( s_pMouseFrame == mpFrame ) - s_pMouseFrame = NULL; - - // #i107215# the only mouse events we get when inactive are enter/exit - // actually we would like to have all of them, but better none than some - if( [NSApp isActive] ) - [self sendMouseEventToFrame:pEvent button:s_nLastButton eventtype:SALEVENT_MOUSELEAVE]; -} - --(void)rightMouseDown: (NSEvent*)pEvent -{ - s_nLastButton = MOUSE_RIGHT; - [self sendMouseEventToFrame:pEvent button:MOUSE_RIGHT eventtype:SALEVENT_MOUSEBUTTONDOWN]; -} - --(void)rightMouseDragged: (NSEvent*)pEvent -{ - s_nLastButton = MOUSE_RIGHT; - [self sendMouseEventToFrame:pEvent button:MOUSE_RIGHT eventtype:SALEVENT_MOUSEMOVE]; -} - --(void)rightMouseUp: (NSEvent*)pEvent -{ - s_nLastButton = 0; - [self sendMouseEventToFrame:pEvent button:MOUSE_RIGHT eventtype:SALEVENT_MOUSEBUTTONUP]; -} - --(void)otherMouseDown: (NSEvent*)pEvent -{ - if( [pEvent buttonNumber] == 2 ) - { - s_nLastButton = MOUSE_MIDDLE; - [self sendMouseEventToFrame:pEvent button:MOUSE_MIDDLE eventtype:SALEVENT_MOUSEBUTTONDOWN]; - } - else - s_nLastButton = 0; -} - --(void)otherMouseDragged: (NSEvent*)pEvent -{ - if( [pEvent buttonNumber] == 2 ) - { - s_nLastButton = MOUSE_MIDDLE; - [self sendMouseEventToFrame:pEvent button:MOUSE_MIDDLE eventtype:SALEVENT_MOUSEMOVE]; - } - else - s_nLastButton = 0; -} - --(void)otherMouseUp: (NSEvent*)pEvent -{ - s_nLastButton = 0; - if( [pEvent buttonNumber] == 2 ) - [self sendMouseEventToFrame:pEvent button:MOUSE_MIDDLE eventtype:SALEVENT_MOUSEBUTTONUP]; -} - -- (void)magnifyWithEvent: (NSEvent*)pEvent -{ - YIELD_GUARD; - - // TODO: ?? -(float)magnification; - if( AquaSalFrame::isAlive( mpFrame ) ) - { - const NSTimeInterval fMagnifyTime = [pEvent timestamp]; - mpFrame->mnLastEventTime = static_cast<sal_uLong>( fMagnifyTime * 1000.0 ); - mpFrame->mnLastModifierFlags = [pEvent modifierFlags]; - - // check if this is a new series of magnify events - static const NSTimeInterval fMaxDiffTime = 0.3; - const bool bNewSeries = (fMagnifyTime - mfLastMagnifyTime > fMaxDiffTime); - - if( bNewSeries ) - mfMagnifyDeltaSum = 0.0; - mfMagnifyDeltaSum += [pEvent deltaZ]; - - mfLastMagnifyTime = [pEvent timestamp]; - // TODO: change to 0.1 when COMMAND_WHEEL_ZOOM handlers allow finer zooming control - static const float fMagnifyFactor = 0.25; - static const float fMinMagnifyStep = 15.0 / fMagnifyFactor; - if( fabs(mfMagnifyDeltaSum) <= fMinMagnifyStep ) - return; - - // adapt NSEvent-sensitivity to application expectations - // TODO: rather make COMMAND_WHEEL_ZOOM handlers smarter - const float fDeltaZ = mfMagnifyDeltaSum * fMagnifyFactor; - int nDeltaZ = FRound( fDeltaZ ); - if( !nDeltaZ ) - { - // handle new series immediately - if( !bNewSeries ) - return; - nDeltaZ = (fDeltaZ >= 0.0) ? +1 : -1; - } - // eventually give credit for delta sum - mfMagnifyDeltaSum -= nDeltaZ / fMagnifyFactor; - - NSPoint aPt = [NSEvent mouseLocation]; - mpFrame->CocoaToVCL( aPt ); - - SalWheelMouseEvent aEvent; - aEvent.mnTime = mpFrame->mnLastEventTime; - aEvent.mnX = static_cast<long>(aPt.x) - mpFrame->maGeometry.nX; - aEvent.mnY = static_cast<long>(aPt.y) - mpFrame->maGeometry.nY; - aEvent.mnCode = ImplGetModifierMask( mpFrame->mnLastModifierFlags ); - aEvent.mnCode |= KEY_MOD1; // we want zooming, no scrolling - aEvent.mbDeltaIsPixel = TRUE; - - // --- RTL --- (mirror mouse pos) - if( Application::GetSettings().GetLayoutRTL() ) - aEvent.mnX = mpFrame->maGeometry.nWidth-1-aEvent.mnX; - - aEvent.mnDelta = nDeltaZ; - aEvent.mnNotchDelta = (nDeltaZ >= 0) ? +1 : -1; - if( aEvent.mnDelta == 0 ) - aEvent.mnDelta = aEvent.mnNotchDelta; - aEvent.mbHorz = FALSE; - aEvent.mnScrollLines = nDeltaZ; - if( aEvent.mnScrollLines == 0 ) - aEvent.mnScrollLines = 1; - mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent ); - } -} - -- (void)rotateWithEvent: (NSEvent*)pEvent -{ - //Rotation : -(float)rotation; - // TODO: create new CommandType so rotation is available to the applications - (void)pEvent; -} - -- (void)swipeWithEvent: (NSEvent*)pEvent -{ - YIELD_GUARD; - - if( AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 ); - mpFrame->mnLastModifierFlags = [pEvent modifierFlags]; - - // merge pending scroll wheel events - float dX = 0.0; - float dY = 0.0; - for(;;) - { - dX += [pEvent deltaX]; - dY += [pEvent deltaY]; - NSEvent* pNextEvent = [NSApp nextEventMatchingMask: NSScrollWheelMask - untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ]; - if( !pNextEvent ) - break; - pEvent = pNextEvent; - } - - NSPoint aPt = [NSEvent mouseLocation]; - mpFrame->CocoaToVCL( aPt ); - - SalWheelMouseEvent aEvent; - aEvent.mnTime = mpFrame->mnLastEventTime; - aEvent.mnX = static_cast<long>(aPt.x) - mpFrame->maGeometry.nX; - aEvent.mnY = static_cast<long>(aPt.y) - mpFrame->maGeometry.nY; - aEvent.mnCode = ImplGetModifierMask( mpFrame->mnLastModifierFlags ); - aEvent.mbDeltaIsPixel = TRUE; - - // --- RTL --- (mirror mouse pos) - if( Application::GetSettings().GetLayoutRTL() ) - aEvent.mnX = mpFrame->maGeometry.nWidth-1-aEvent.mnX; - - if( dX != 0.0 ) - { - aEvent.mnDelta = static_cast<long>(floor(dX)); - aEvent.mnNotchDelta = dX < 0 ? -1 : 1; - if( aEvent.mnDelta == 0 ) - aEvent.mnDelta = aEvent.mnNotchDelta; - aEvent.mbHorz = TRUE; - aEvent.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL; - mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent ); - } - if( dY != 0.0 && AquaSalFrame::isAlive( mpFrame )) - { - aEvent.mnDelta = static_cast<long>(floor(dY)); - aEvent.mnNotchDelta = dY < 0 ? -1 : 1; - if( aEvent.mnDelta == 0 ) - aEvent.mnDelta = aEvent.mnNotchDelta; - aEvent.mbHorz = FALSE; - aEvent.mnScrollLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL; - mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent ); - } - } -} - --(void)scrollWheel: (NSEvent*)pEvent -{ - YIELD_GUARD; - - if( AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 ); - mpFrame->mnLastModifierFlags = [pEvent modifierFlags]; - - // merge pending scroll wheel events - float dX = 0.0; - float dY = 0.0; - for(;;) - { - dX += [pEvent deltaX]; - dY += [pEvent deltaY]; - NSEvent* pNextEvent = [NSApp nextEventMatchingMask: NSScrollWheelMask - untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES ]; - if( !pNextEvent ) - break; - pEvent = pNextEvent; - } - - NSPoint aPt = [NSEvent mouseLocation]; - mpFrame->CocoaToVCL( aPt ); - - SalWheelMouseEvent aEvent; - aEvent.mnTime = mpFrame->mnLastEventTime; - aEvent.mnX = static_cast<long>(aPt.x) - mpFrame->maGeometry.nX; - aEvent.mnY = static_cast<long>(aPt.y) - mpFrame->maGeometry.nY; - aEvent.mnCode = ImplGetModifierMask( mpFrame->mnLastModifierFlags ); - aEvent.mbDeltaIsPixel = TRUE; - - // --- RTL --- (mirror mouse pos) - if( Application::GetSettings().GetLayoutRTL() ) - aEvent.mnX = mpFrame->maGeometry.nWidth-1-aEvent.mnX; - - if( dX != 0.0 ) - { - aEvent.mnDelta = static_cast<long>(floor(dX)); - aEvent.mnNotchDelta = dX < 0 ? -1 : 1; - if( aEvent.mnDelta == 0 ) - aEvent.mnDelta = aEvent.mnNotchDelta; - aEvent.mbHorz = TRUE; - aEvent.mnScrollLines = dY > 0 ? dX/WHEEL_EVENT_FACTOR : -dX/WHEEL_EVENT_FACTOR; - if( aEvent.mnScrollLines == 0 ) - aEvent.mnScrollLines = 1; - - mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent ); - } - if( dY != 0.0 && AquaSalFrame::isAlive( mpFrame ) ) - { - aEvent.mnDelta = static_cast<long>(floor(dY)); - aEvent.mnNotchDelta = dY < 0 ? -1 : 1; - if( aEvent.mnDelta == 0 ) - aEvent.mnDelta = aEvent.mnNotchDelta; - aEvent.mbHorz = FALSE; - aEvent.mnScrollLines = dY > 0 ? dY/WHEEL_EVENT_FACTOR : -dY/WHEEL_EVENT_FACTOR; - if( aEvent.mnScrollLines < 1 ) - aEvent.mnScrollLines = 1; - - mpFrame->CallCallback( SALEVENT_WHEELMOUSE, &aEvent ); - } - } -} - - --(void)keyDown: (NSEvent*)pEvent -{ - YIELD_GUARD; - - if( AquaSalFrame::isAlive( mpFrame ) ) - { - mpLastEvent = pEvent; - mbInKeyInput = true; - mbNeedSpecialKeyHandle = false; - mbKeyHandled = false; - - mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 ); - mpFrame->mnLastModifierFlags = [pEvent modifierFlags]; - - if( ! [self handleKeyDownException: pEvent] ) - { - NSArray* pArray = [NSArray arrayWithObject: pEvent]; - [self interpretKeyEvents: pArray]; - } - - mbInKeyInput = false; - } -} - --(BOOL)handleKeyDownException:(NSEvent*)pEvent -{ - // check for a very special set of modified characters - NSString* pUnmodifiedString = [pEvent charactersIgnoringModifiers]; - - if( pUnmodifiedString && [pUnmodifiedString length] == 1 ) - { - /* #i103102# key events with command and alternate don't make it through - interpretKeyEvents (why ?). Try to dispatch them here first, - if not successful continue normally - */ - if( (mpFrame->mnLastModifierFlags & (NSAlternateKeyMask | NSCommandKeyMask)) - == (NSAlternateKeyMask | NSCommandKeyMask) ) - { - if( [self sendSingleCharacter: mpLastEvent] ) - return YES; - } - unichar keyChar = [pUnmodifiedString characterAtIndex: 0]; - sal_uInt16 nKeyCode = ImplMapCharCode( keyChar ); - - // Caution: should the table grow to more than 5 or 6 entries, - // we must consider moving it to a kind of hash map - const unsigned int nExceptions = SAL_N_ELEMENTS( aExceptionalKeys ); - for( unsigned int i = 0; i < nExceptions; i++ ) - { - if( nKeyCode == aExceptionalKeys[i].nKeyCode && - (mpFrame->mnLastModifierFlags & aExceptionalKeys[i].nModifierMask) - == aExceptionalKeys[i].nModifierMask ) - { - [self sendKeyInputAndReleaseToFrame: nKeyCode character: 0]; - - return YES; - } - } - } - return NO; -} - --(void)flagsChanged: (NSEvent*)pEvent -{ - YIELD_GUARD; - - if( AquaSalFrame::isAlive( mpFrame ) ) - { - mpFrame->mnLastEventTime = static_cast<sal_uLong>( [pEvent timestamp] * 1000.0 ); - mpFrame->mnLastModifierFlags = [pEvent modifierFlags]; - } -} - --(void)insertText:(id)aString -{ - YIELD_GUARD; - - if( AquaSalFrame::isAlive( mpFrame ) ) - { - NSString* pInsert = nil; - if( [aString isMemberOfClass: [NSAttributedString class]] ) - pInsert = [aString string]; - else - pInsert = aString; - - int nLen = 0; - if( pInsert && ( nLen = [pInsert length] ) > 0 ) - { - OUString aInsertString( GetOUString( pInsert ) ); - // aCharCode initializer is safe since aInsertString will at least contain '\0' - sal_Unicode aCharCode = *aInsertString.getStr(); - - if( nLen == 1 && - aCharCode < 0x80 && - aCharCode > 0x1f && - ! [self hasMarkedText ] - ) - { - sal_uInt16 nKeyCode = ImplMapCharCode( aCharCode ); - unsigned int nLastModifiers = mpFrame->mnLastModifierFlags; - - // #i99567# - // find out the unmodified key code - - // sanity check - if( mpLastEvent && ( [mpLastEvent type] == NSKeyDown || [mpLastEvent type] == NSKeyUp ) ) - { - // get unmodified string - NSString* pUnmodifiedString = [mpLastEvent charactersIgnoringModifiers]; - if( pUnmodifiedString && [pUnmodifiedString length] == 1 ) - { - // map the unmodified key code - unichar keyChar = [pUnmodifiedString characterAtIndex: 0]; - nKeyCode = ImplMapCharCode( keyChar ); - } - nLastModifiers = [mpLastEvent modifierFlags]; - - } - // #i99567# - // applications and vcl's edit fields ignore key events with ALT - // however we're at a place where we know text should be inserted - // so it seems we need to strip the Alt modifier here - if( (nLastModifiers & (NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)) - == NSAlternateKeyMask ) - { - nLastModifiers = 0; - } - [self sendKeyInputAndReleaseToFrame: nKeyCode character: aCharCode modifiers: nLastModifiers]; - } - else - { - SalExtTextInputEvent aEvent; - aEvent.mnTime = mpFrame->mnLastEventTime; - aEvent.maText = aInsertString; - aEvent.mpTextAttr = NULL; - aEvent.mnCursorPos = aInsertString.getLength(); - aEvent.mnDeltaStart = 0; - aEvent.mnCursorFlags = 0; - aEvent.mbOnlyCursor = FALSE; - mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, &aEvent ); - if( AquaSalFrame::isAlive( mpFrame ) ) - mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 ); - } - } - else - { - SalExtTextInputEvent aEvent; - aEvent.mnTime = mpFrame->mnLastEventTime; - aEvent.maText = String(); - aEvent.mpTextAttr = NULL; - aEvent.mnCursorPos = 0; - aEvent.mnDeltaStart = 0; - aEvent.mnCursorFlags = 0; - aEvent.mbOnlyCursor = FALSE; - mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, &aEvent ); - if( AquaSalFrame::isAlive( mpFrame ) ) - mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 ); - - } - mbKeyHandled = true; - [self unmarkText]; - } -} - --(void)insertTab: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_TAB character: '\t' modifiers: 0]; -} - --(void)insertBacktab: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: (KEY_TAB | KEY_SHIFT) character: '\t' modifiers: 0]; -} - --(void)moveLeft: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_LEFT character: 0 modifiers: 0]; -} - --(void)moveLeftAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_LEFT character: 0 modifiers: NSShiftKeyMask]; -} - --(void)moveBackwardAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_BACKWARD character: 0 modifiers: 0]; -} - --(void)moveRight: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_RIGHT character: 0 modifiers: 0]; -} - --(void)moveRightAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_RIGHT character: 0 modifiers: NSShiftKeyMask]; -} - --(void)moveForwardAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_FORWARD character: 0 modifiers: 0]; -} - --(void)moveWordLeft: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_BACKWARD character: 0 modifiers: 0]; -} - --(void)moveWordBackward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_BACKWARD character: 0 modifiers: 0]; -} - --(void)moveWordBackwardAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_BACKWARD character: 0 modifiers: 0]; -} - --(void)moveWordLeftAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_BACKWARD character: 0 modifiers: 0]; -} - --(void)moveWordRight: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_FORWARD character: 0 modifiers: 0]; -} - --(void)moveWordForward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_WORD_FORWARD character: 0 modifiers: 0]; -} - --(void)moveWordForwardAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_FORWARD character: 0 modifiers: 0]; -} - --(void)moveWordRightAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD_FORWARD character: 0 modifiers: 0]; -} - --(void)moveToEndOfLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToRightEndOfLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToEndOfLineAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToRightEndOfLineAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToBeginningOfLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToLeftEndOfLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToBeginningOfLineAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToLeftEndOfLineAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE character: 0 modifiers: 0]; -} - --(void)moveToEndOfParagraph: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveToEndOfParagraphAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveParagraphForward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveParagraphForwardAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveToBeginningOfParagraph: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveParagraphBackward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveToBeginningOfParagraphAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveParagraphBackwardAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)moveToEndOfDocument: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT character: 0 modifiers: 0]; -} - --(void)scrollToEndOfDocument: (id)aSender -{ - (void)aSender; - // this is not exactly what we should do, but it makes "End" and "Shift-End" behave consistent - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT character: 0 modifiers: 0]; -} - --(void)moveToEndOfDocumentAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT character: 0 modifiers: 0]; -} - --(void)moveToBeginningOfDocument: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT character: 0 modifiers: 0]; -} - --(void)scrollToBeginningOfDocument: (id)aSender -{ - (void)aSender; - // this is not exactly what we should do, but it makes "Home" and "Shift-Home" behave consistent - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT character: 0 modifiers: 0]; -} - --(void)moveToBeginningOfDocumentAndModifySelection: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT character: 0 modifiers: 0]; -} - --(void)moveUp: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_UP character: 0 modifiers: 0]; -} - --(void)moveDown: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_DOWN character: 0 modifiers: 0]; -} - --(void)insertNewline: (id)aSender -{ - (void)aSender; - // #i91267# make enter and shift-enter work by evaluating the modifiers - [self sendKeyInputAndReleaseToFrame: KEY_RETURN character: '\n' modifiers: mpFrame->mnLastModifierFlags]; -} - --(void)deleteBackward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_BACKSPACE character: '\b' modifiers: 0]; -} - --(void)deleteForward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_DELETE character: 0x7f modifiers: 0]; -} - --(void)deleteBackwardByDecomposingPreviousCharacter: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_BACKSPACE character: '\b' modifiers: 0]; -} - --(void)deleteWordBackward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_WORD_BACKWARD character: 0 modifiers: 0]; -} - --(void)deleteWordForward: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_WORD_FORWARD character: 0 modifiers: 0]; -} - --(void)deleteToBeginningOfLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE character: 0 modifiers: 0]; -} - --(void)deleteToEndOfLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_END_OF_LINE character: 0 modifiers: 0]; -} - --(void)deleteToBeginningOfParagraph: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)deleteToEndOfParagraph: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::DELETE_TO_END_OF_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)insertLineBreak: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::INSERT_LINEBREAK character: 0 modifiers: 0]; -} - --(void)insertParagraphSeparator: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::INSERT_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)selectWord: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_WORD character: 0 modifiers: 0]; -} - --(void)selectLine: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_LINE character: 0 modifiers: 0]; -} - --(void)selectParagraph: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_PARAGRAPH character: 0 modifiers: 0]; -} - --(void)selectAll: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: com::sun::star::awt::Key::SELECT_ALL character: 0 modifiers: 0]; -} - --(void)cancelOperation: (id)aSender -{ - (void)aSender; - [self sendKeyInputAndReleaseToFrame: KEY_ESCAPE character: 0x1b modifiers: 0]; -} - --(void)noop: (id)aSender -{ - (void)aSender; - if( ! mbKeyHandled ) - { - if( ! [self sendSingleCharacter:mpLastEvent] ) - { - /* prevent recursion */ - if( mpLastEvent != mpLastSuperEvent && [NSApp respondsToSelector: @selector(sendSuperEvent:)] ) - { - id pLastSuperEvent = mpLastSuperEvent; - mpLastSuperEvent = mpLastEvent; - [NSApp performSelector:@selector(sendSuperEvent:) withObject: mpLastEvent]; - mpLastSuperEvent = pLastSuperEvent; - - std::map< NSEvent*, bool >::iterator it = GetSalData()->maKeyEventAnswer.find( mpLastEvent ); - if( it != GetSalData()->maKeyEventAnswer.end() ) - it->second = true; - } - } - } -} - --(BOOL)sendKeyInputAndReleaseToFrame: (sal_uInt16)nKeyCode character: (sal_Unicode)aChar -{ - return [self sendKeyInputAndReleaseToFrame: nKeyCode character: aChar modifiers: mpFrame->mnLastModifierFlags]; -} - --(BOOL)sendKeyInputAndReleaseToFrame: (sal_uInt16)nKeyCode character: (sal_Unicode)aChar modifiers: (unsigned int)nMod -{ - return [self sendKeyToFrameDirect: nKeyCode character: aChar modifiers: nMod] || - [self sendSingleCharacter: mpLastEvent]; -} - --(BOOL)sendKeyToFrameDirect: (sal_uInt16)nKeyCode character: (sal_Unicode)aChar modifiers: (unsigned int)nMod -{ - YIELD_GUARD; - - long nRet = 0; - if( AquaSalFrame::isAlive( mpFrame ) ) - { - SalKeyEvent aEvent; - aEvent.mnTime = mpFrame->mnLastEventTime; - aEvent.mnCode = nKeyCode | ImplGetModifierMask( nMod ); - aEvent.mnCharCode = aChar; - aEvent.mnRepeat = FALSE; - nRet = mpFrame->CallCallback( SALEVENT_KEYINPUT, &aEvent ); - std::map< NSEvent*, bool >::iterator it = GetSalData()->maKeyEventAnswer.find( mpLastEvent ); - if( it != GetSalData()->maKeyEventAnswer.end() ) - it->second = nRet ? true : false; - if( AquaSalFrame::isAlive( mpFrame ) ) - mpFrame->CallCallback( SALEVENT_KEYUP, &aEvent ); - } - return nRet ? YES : NO; -} - - --(BOOL)sendSingleCharacter: (NSEvent *)pEvent -{ - NSString* pUnmodifiedString = [pEvent charactersIgnoringModifiers]; - - if( pUnmodifiedString && [pUnmodifiedString length] == 1 ) - { - unichar keyChar = [pUnmodifiedString characterAtIndex: 0]; - sal_uInt16 nKeyCode = ImplMapCharCode( keyChar ); - if( nKeyCode != 0 ) - { - // don't send unicodes in the private use area - if( keyChar >= 0xf700 && keyChar < 0xf780 ) - keyChar = 0; - BOOL bRet = [self sendKeyToFrameDirect: nKeyCode character: keyChar modifiers: mpFrame->mnLastModifierFlags]; - mbInKeyInput = false; - - return bRet; - } - } - return NO; -} - - -// NSTextInput protocol -- (NSArray *)validAttributesForMarkedText -{ - return [NSArray arrayWithObjects:NSUnderlineStyleAttributeName, nil]; -} - -- (BOOL)hasMarkedText -{ - BOOL bHasMarkedText; - - bHasMarkedText = ( mMarkedRange.location != NSNotFound ) && - ( mMarkedRange.length != 0 ); - // hack to check keys like "Control-j" - if( mbInKeyInput ) - { - mbNeedSpecialKeyHandle = true; - } - - // FIXME: - // #i106901# - // if we come here outside of mbInKeyInput, this is likely to be because - // of the keyboard viewer. For unknown reasons having no marked range - // in this case causes a crash. So we say we have a marked range anyway - // This is a hack, since it is not understood what a) causes that crash - // and b) why we should have a marked range at this point. - if( ! mbInKeyInput ) - bHasMarkedText = YES; - - return bHasMarkedText; -} - -- (NSRange)markedRange -{ - // FIXME: - // #i106901# - // if we come here outside of mbInKeyInput, this is likely to be because - // of the keyboard viewer. For unknown reasons having no marked range - // in this case causes a crash. So we say we have a marked range anyway - // This is a hack, since it is not understood what a) causes that crash - // and b) why we should have a marked range at this point. - if( ! mbInKeyInput ) - return NSMakeRange( 0, 0 ); - - return [self hasMarkedText] ? mMarkedRange : NSMakeRange( NSNotFound, 0 ); -} - -- (NSRange)selectedRange -{ - return mSelectedRange; -} - -- (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange -{ - if( ![aString isKindOfClass:[NSAttributedString class]] ) - aString = [[[NSAttributedString alloc] initWithString:aString] autorelease]; - NSRange rangeToReplace = [self hasMarkedText] ? [self markedRange] : [self selectedRange]; - if( rangeToReplace.location == NSNotFound ) - { - mMarkedRange = NSMakeRange( selRange.location, [aString length] ); - mSelectedRange = NSMakeRange( selRange.location, selRange.length ); - } - else - { - mMarkedRange = NSMakeRange( rangeToReplace.location, [aString length] ); - mSelectedRange = NSMakeRange( rangeToReplace.location + selRange.location, selRange.length ); - } - - int len = [aString length]; - SalExtTextInputEvent aInputEvent; - aInputEvent.mnTime = mpFrame->mnLastEventTime; - aInputEvent.mnDeltaStart = 0; - aInputEvent.mbOnlyCursor = FALSE; - if( len > 0 ) { - NSString *pString = [aString string]; - OUString aInsertString( GetOUString( pString ) ); - std::vector<sal_uInt16> aInputFlags = std::vector<sal_uInt16>( std::max( 1, len ), 0 ); - for ( int i = 0; i < len; i++ ) - { - unsigned int nUnderlineValue; - NSRange effectiveRange; - - effectiveRange = NSMakeRange(i, 1); - nUnderlineValue = [[aString attribute:NSUnderlineStyleAttributeName atIndex:i effectiveRange:&effectiveRange] unsignedIntValue]; - - switch (nUnderlineValue & 0xff) { - case NSUnderlineStyleSingle: - aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_UNDERLINE; - break; - case NSUnderlineStyleThick: - aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_UNDERLINE | SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT; - break; - case NSUnderlineStyleDouble: - aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_BOLDUNDERLINE; - break; - default: - aInputFlags[i] = SAL_EXTTEXTINPUT_ATTR_HIGHLIGHT; - break; - } - } - - aInputEvent.maText = aInsertString; - aInputEvent.mnCursorPos = selRange.location; - aInputEvent.mpTextAttr = &aInputFlags[0]; - mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void *)&aInputEvent ); - } else { - aInputEvent.maText = String(); - aInputEvent.mnCursorPos = 0; - aInputEvent.mnCursorFlags = 0; - aInputEvent.mpTextAttr = 0; - mpFrame->CallCallback( SALEVENT_EXTTEXTINPUT, (void *)&aInputEvent ); - mpFrame->CallCallback( SALEVENT_ENDEXTTEXTINPUT, 0 ); - } - mbKeyHandled= true; -} - -- (void)unmarkText -{ - mSelectedRange = mMarkedRange = NSMakeRange(NSNotFound, 0); -} - -- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange -{ - (void)theRange; - // FIXME - return nil; -} - -- (unsigned int)characterIndexForPoint:(NSPoint)thePoint -{ - (void)thePoint; - // FIXME - return 0; -} - -#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) -/* build target 10.5 or greater */ -- (NSInteger)conversationIdentifier -#else -/* build target 10.4 */ -- (long)conversationIdentifier -#endif -{ - return (long)self; -} - -- (void)doCommandBySelector:(SEL)aSelector -{ - if( AquaSalFrame::isAlive( mpFrame ) ) - { - #if OSL_DEBUG_LEVEL > 1 - // fprintf( stderr, "SalFrameView: doCommandBySelector %s\n", (char*)aSelector ); - #endif - if( (mpFrame->mnICOptions & SAL_INPUTCONTEXT_TEXT) != 0 && - aSelector != NULL && [self respondsToSelector: aSelector] ) - { - [self performSelector: aSelector]; - } - else - { - [self sendSingleCharacter:mpLastEvent]; - } - } - - mbKeyHandled = true; -} - --(void)clearLastEvent -{ - mpLastEvent = nil; -} - -- (NSRect)firstRectForCharacterRange:(NSRange)theRange -{ - (void)theRange; - SalExtTextInputPosEvent aPosEvent; - mpFrame->CallCallback( SALEVENT_EXTTEXTINPUTPOS, (void *)&aPosEvent ); - - NSRect rect; - - rect.origin.x = aPosEvent.mnX + mpFrame->maGeometry.nX; - rect.origin.y = aPosEvent.mnY + mpFrame->maGeometry.nY + 4; // add some space for underlines - rect.size.width = aPosEvent.mnWidth; - rect.size.height = aPosEvent.mnHeight; - - mpFrame->VCLToCocoa( rect ); - return rect; -} - --(id)parentAttribute { - return (NSView *) mpFrame -> mpWindow; -} - --(::com::sun::star::accessibility::XAccessibleContext *)accessibleContext -{ - if ( mpReferenceWrapper == nil ) { - // some frames never become visible .. - Window *pWindow = mpFrame -> GetWindow(); - if ( ! pWindow ) - return nil; - - mpReferenceWrapper = new ReferenceWrapper; - mpReferenceWrapper -> rAccessibleContext = pWindow -> /*GetAccessibleChildWindow( 0 ) ->*/ GetAccessible() -> getAccessibleContext(); - [ AquaA11yFactory insertIntoWrapperRepository: self forAccessibleContext: mpReferenceWrapper -> rAccessibleContext ]; - } - return [ super accessibleContext ]; -} - --(NSView *)viewElementForParent -{ - return (NSView *) mpFrame -> mpWindow; -} - --(void)registerMouseEventListener: (id)theListener -{ - mpMouseEventListener = theListener; -} - --(void)unregisterMouseEventListener: (id)theListener -{ - (void)theListener; - mpMouseEventListener = nil; -} - --(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler draggingEntered: sender]; -} - --(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler draggingUpdated: sender]; -} - --(void)draggingExited:(id <NSDraggingInfo>)sender -{ - [mDraggingDestinationHandler draggingExited: sender]; -} - --(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler prepareForDragOperation: sender]; -} - --(BOOL)performDragOperation:(id <NSDraggingInfo>)sender -{ - return [mDraggingDestinationHandler performDragOperation: sender]; -} - --(void)concludeDragOperation:(id <NSDraggingInfo>)sender -{ - [mDraggingDestinationHandler concludeDragOperation: sender]; -} - --(void)registerDraggingDestinationHandler:(id)theHandler -{ - mDraggingDestinationHandler = theHandler; -} - --(void)unregisterDraggingDestinationHandler:(id)theHandler -{ - (void)theHandler; - mDraggingDestinationHandler = nil; -} - -@end - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/aqua/source/window/salmenu.cxx b/vcl/aqua/source/window/salmenu.cxx deleted file mode 100644 index f5810435f5..0000000000 --- a/vcl/aqua/source/window/salmenu.cxx +++ /dev/null @@ -1,969 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "rtl/ustrbuf.hxx" - -#include "vcl/cmdevt.hxx" -#include "vcl/floatwin.hxx" -#include "vcl/window.hxx" -#include "vcl/svapp.hxx" - -#include "aqua/saldata.hxx" -#include "aqua/salinst.h" -#include "aqua/salmenu.h" -#include "aqua/salnsmenu.h" -#include "aqua/salframe.h" -#include "aqua/salbmp.h" -#include "aqua/aqua11ywrapper.h" - -#include "svids.hrc" -#include "window.h" - -const AquaSalMenu* AquaSalMenu::pCurrentMenuBar = NULL; - -@interface MainMenuSelector : NSObject -{ -} --(void)showDialog: (int)nDialog; --(void)showPreferences: (id)sender; --(void)showAbout: (id)sender; -@end - -@implementation MainMenuSelector --(void)showDialog: (int)nDialog -{ - if( AquaSalMenu::pCurrentMenuBar ) - { - const AquaSalFrame* pFrame = AquaSalMenu::pCurrentMenuBar->mpFrame; - if( pFrame && AquaSalFrame::isAlive( pFrame ) ) - { - pFrame->CallCallback( SALEVENT_SHOWDIALOG, reinterpret_cast<void*>(nDialog) ); - } - } - else - { - String aDialog; - if( nDialog == SHOWDIALOG_ID_ABOUT ) - aDialog = String( RTL_CONSTASCII_USTRINGPARAM( "ABOUT" ) ); - else if( nDialog == SHOWDIALOG_ID_PREFERENCES ) - aDialog = String( RTL_CONSTASCII_USTRINGPARAM( "PREFERENCES" ) ); - const ApplicationEvent* pAppEvent = new ApplicationEvent( String(), - ApplicationAddress(), - ByteString( "SHOWDIALOG" ), - aDialog ); - AquaSalInstance::aAppEventList.push_back( pAppEvent ); - } -} - --(void)showPreferences: (id) sender -{ - (void)sender; - YIELD_GUARD; - - [self showDialog: SHOWDIALOG_ID_PREFERENCES]; -} --(void)showAbout: (id) sender -{ - (void)sender; - YIELD_GUARD; - - [self showDialog: SHOWDIALOG_ID_ABOUT]; -} -@end - - -// FIXME: currently this is leaked -static MainMenuSelector* pMainMenuSelector = nil; - -static void initAppMenu() -{ - static bool bOnce = true; - if( bOnce ) - { - bOnce = false; - - ResMgr* pMgr = ImplGetResMgr(); - if( pMgr ) - { - // get the main menu - NSMenu* pMainMenu = [NSApp mainMenu]; - if( pMainMenu != nil ) - { - // create the action selector - pMainMenuSelector = [[MainMenuSelector alloc] init]; - - // get the proper submenu - NSMenu* pAppMenu = [[pMainMenu itemAtIndex: 0] submenu]; - if( pAppMenu ) - { - // insert about entry - String aAbout( ResId( SV_STDTEXT_ABOUT, *pMgr ) ); - NSString* pString = CreateNSString( aAbout ); - NSMenuItem* pNewItem = [pAppMenu insertItemWithTitle: pString - action: @selector(showAbout:) - keyEquivalent: @"" - atIndex: 0]; - if (pString) - [pString release]; - if( pNewItem ) - { - [pNewItem setTarget: pMainMenuSelector]; - [pAppMenu insertItem: [NSMenuItem separatorItem] atIndex: 1]; - } - - // insert preferences entry - String aPref( ResId( SV_STDTEXT_PREFERENCES, *pMgr ) ); - pString = CreateNSString( aPref ); - pNewItem = [pAppMenu insertItemWithTitle: pString - action: @selector(showPreferences:) - keyEquivalent: @"," - atIndex: 2]; - if (pString) - [pString release]; - if( pNewItem ) - { - [pNewItem setKeyEquivalentModifierMask: NSCommandKeyMask]; - [pNewItem setTarget: pMainMenuSelector]; - [pAppMenu insertItem: [NSMenuItem separatorItem] atIndex: 3]; - } - - // WARNING: ultra ugly code ahead - - // rename standard entries - // rename "Services" - pNewItem = [pAppMenu itemAtIndex: 4]; - if( pNewItem ) - { - pString = CreateNSString( String( ResId( SV_MENU_MAC_SERVICES, *pMgr ) ) ); - [pNewItem setTitle: pString]; - if( pString ) - [pString release]; - } - - // rename "Hide NewApplication" - pNewItem = [pAppMenu itemAtIndex: 6]; - if( pNewItem ) - { - pString = CreateNSString( String( ResId( SV_MENU_MAC_HIDEAPP, *pMgr ) ) ); - [pNewItem setTitle: pString]; - if( pString ) - [pString release]; - } - - // rename "Hide Others" - pNewItem = [pAppMenu itemAtIndex: 7]; - if( pNewItem ) - { - pString = CreateNSString( String( ResId( SV_MENU_MAC_HIDEALL, *pMgr ) ) ); - [pNewItem setTitle: pString]; - if( pString ) - [pString release]; - } - - // rename "Show all" - pNewItem = [pAppMenu itemAtIndex: 8]; - if( pNewItem ) - { - pString = CreateNSString( String( ResId( SV_MENU_MAC_SHOWALL, *pMgr ) ) ); - [pNewItem setTitle: pString]; - if( pString ) - [pString release]; - } - - // rename "Quit NewApplication" - pNewItem = [pAppMenu itemAtIndex: 10]; - if( pNewItem ) - { - pString = CreateNSString( String( ResId( SV_MENU_MAC_QUITAPP, *pMgr ) ) ); - [pNewItem setTitle: pString]; - if( pString ) - [pString release]; - } - } - } - } - } -} - -// ======================================================================= - -SalMenu* AquaSalInstance::CreateMenu( sal_Bool bMenuBar, Menu* pVCLMenu ) -{ - initAppMenu(); - - AquaSalMenu *pAquaSalMenu = new AquaSalMenu( bMenuBar ); - pAquaSalMenu->mpVCLMenu = pVCLMenu; - - return pAquaSalMenu; -} - -void AquaSalInstance::DestroyMenu( SalMenu* pSalMenu ) -{ - delete pSalMenu; -} - -SalMenuItem* AquaSalInstance::CreateMenuItem( const SalItemParams* pItemData ) -{ - if( !pItemData ) - return NULL; - - AquaSalMenuItem *pSalMenuItem = new AquaSalMenuItem( pItemData ); - - return pSalMenuItem; -} - -void AquaSalInstance::DestroyMenuItem( SalMenuItem* pSalMenuItem ) -{ - delete pSalMenuItem; -} - - -// ======================================================================= - - -/* - * AquaSalMenu - */ - -AquaSalMenu::AquaSalMenu( bool bMenuBar ) : - mbMenuBar( bMenuBar ), - mpMenu( nil ), - mpVCLMenu( NULL ), - mpFrame( NULL ), - mpParentSalMenu( NULL ) -{ - if( ! mbMenuBar ) - { - mpMenu = [[SalNSMenu alloc] initWithMenu: this]; - [mpMenu setDelegate: mpMenu]; - } - else - { - mpMenu = [NSApp mainMenu]; - } - [mpMenu setAutoenablesItems: NO]; -} - -AquaSalMenu::~AquaSalMenu() -{ - // actually someone should have done AquaSalFrame::SetMenu( NULL ) - // on our frame, alas it is not so - if( mpFrame && AquaSalFrame::isAlive( mpFrame ) && mpFrame->mpMenu == this ) - const_cast<AquaSalFrame*>(mpFrame)->mpMenu = NULL; - - // this should normally be empty already, but be careful... - for( size_t i = 0; i < maButtons.size(); i++ ) - releaseButtonEntry( maButtons[i] ); - maButtons.clear(); - - // is this leaking in some cases ? the release often leads to a duplicate release - // it seems the parent item gets ownership of the menu - if( mpMenu ) - { - if( mbMenuBar ) - { - if( pCurrentMenuBar == this ) - { - // if the current menubar gets destroyed, set the default menubar - setDefaultMenu(); - } - } - else - // the system may still hold a reference on mpMenu - { - // so set the pointer to this AquaSalMenu to NULL - // to protect from calling a dead object - - // in ! mbMenuBar case our mpMenu is actually a SalNSMenu* - // so we can safely cast here - [static_cast<SalNSMenu*>(mpMenu) setSalMenu: NULL]; - /* #i89860# FIXME: - using [autorelease] here (and in AquaSalMenuItem::~AquaSalMenuItem) - instead of [release] fixes an occasional crash. That should - indicate that we release menus / menu items in the wrong order - somewhere, but I could not find that case. - */ - [mpMenu autorelease]; - } - } -} - -sal_Int32 removeUnusedItemsRunner(NSMenu * pMenu) -{ - NSArray * elements = [pMenu itemArray]; - NSEnumerator * it = [elements objectEnumerator]; - id elem; - NSMenuItem * lastDisplayedMenuItem = nil; - sal_Int32 drawnItems = 0; - bool firstEnabledItemIsNoSeparator = false; - while((elem=[it nextObject]) != nil) { - NSMenuItem * item = static_cast<NSMenuItem *>(elem); - if( (![item isEnabled] && ![item isSeparatorItem]) || ([item isSeparatorItem] && (lastDisplayedMenuItem != nil && [lastDisplayedMenuItem isSeparatorItem])) ) { - [[item menu]removeItem:item]; - } else { - if( ! firstEnabledItemIsNoSeparator && [item isSeparatorItem] ) { - [[item menu]removeItem:item]; - } else { - firstEnabledItemIsNoSeparator = true; - lastDisplayedMenuItem = item; - drawnItems++; - if( [item hasSubmenu] ) { - removeUnusedItemsRunner( [item submenu] ); - } - } - } - } - if( lastDisplayedMenuItem != nil && [lastDisplayedMenuItem isSeparatorItem]) { - [[lastDisplayedMenuItem menu]removeItem:lastDisplayedMenuItem]; - } - return drawnItems; -} - -bool AquaSalMenu::ShowNativePopupMenu(FloatingWindow * pWin, const Rectangle& rRect, sal_uLong nFlags) -{ - // do not use native popup menu when AQUA_NATIVE_MENUS is set to sal_False - if( ! VisibleMenuBar() ) { - return false; - } - - // set offsets for positioning - const float offset = 9.0; - - // get the pointers - AquaSalFrame * pParentAquaSalFrame = (AquaSalFrame *) pWin->ImplGetWindowImpl()->mpRealParent->ImplGetFrame(); - NSWindow * pParentNSWindow = pParentAquaSalFrame->mpWindow; - NSView * pParentNSView = [pParentNSWindow contentView]; - NSView * pPopupNSView = ((AquaSalFrame *) pWin->ImplGetWindow()->ImplGetFrame())->mpView; - NSRect popupFrame = [pPopupNSView frame]; - - // since we manipulate the menu below (removing entries) - // let's rather make a copy here and work with that - NSMenu* pCopyMenu = [mpMenu copy]; - - // filter disabled elements - removeUnusedItemsRunner( pCopyMenu ); - - // create frame rect - NSRect displayPopupFrame = NSMakeRect( rRect.nLeft+(offset-1), rRect.nTop+(offset+1), popupFrame.size.width, 0 ); - pParentAquaSalFrame->VCLToCocoa(displayPopupFrame, false); - - // do the same strange semantics as vcl popup windows to arrive at a frame geometry - // in mirrored UI case; best done by actually executing the same code - sal_uInt16 nArrangeIndex; - pWin->SetPosPixel( pWin->ImplCalcPos( pWin, rRect, nFlags, nArrangeIndex ) ); - displayPopupFrame.origin.x = pWin->ImplGetFrame()->maGeometry.nX - pParentAquaSalFrame->maGeometry.nX + offset; - displayPopupFrame.origin.y = pWin->ImplGetFrame()->maGeometry.nY - pParentAquaSalFrame->maGeometry.nY + offset; - pParentAquaSalFrame->VCLToCocoa(displayPopupFrame, false); - - // #i111992# if this menu was opened due to a key event, prevent dispatching that yet again - if( [pParentNSView respondsToSelector: @selector(clearLastEvent)] ) - [pParentNSView performSelector:@selector(clearLastEvent)]; - - // open popup menu - NSPopUpButtonCell * pPopUpButtonCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]; - [pPopUpButtonCell setMenu: pCopyMenu]; - [pPopUpButtonCell selectItem:nil]; - [AquaA11yWrapper setPopupMenuOpen: YES]; - [pPopUpButtonCell performClickWithFrame:displayPopupFrame inView:pParentNSView]; - [pPopUpButtonCell release]; - [AquaA11yWrapper setPopupMenuOpen: NO]; - - // clean up the copy - [pCopyMenu release]; - return true; -} - -int AquaSalMenu::getItemIndexByPos( sal_uInt16 nPos ) const -{ - int nIndex = 0; - if( nPos == MENU_APPEND ) - nIndex = [mpMenu numberOfItems]; - else - nIndex = sal::static_int_cast<int>( mbMenuBar ? nPos+1 : nPos ); - return nIndex; -} - -const AquaSalFrame* AquaSalMenu::getFrame() const -{ - const AquaSalMenu* pMenu = this; - while( pMenu && ! pMenu->mpFrame ) - pMenu = pMenu->mpParentSalMenu; - return pMenu ? pMenu->mpFrame : NULL; -} - -void AquaSalMenu::unsetMainMenu() -{ - pCurrentMenuBar = NULL; - - // remove items from main menu - NSMenu* pMenu = [NSApp mainMenu]; - for( int nItems = [pMenu numberOfItems]; nItems > 1; nItems-- ) - [pMenu removeItemAtIndex: 1]; -} - -void AquaSalMenu::setMainMenu() -{ - DBG_ASSERT( mbMenuBar, "setMainMenu on non menubar" ); - if( mbMenuBar ) - { - if( pCurrentMenuBar != this ) - { - unsetMainMenu(); - // insert our items - for( unsigned int i = 0; i < maItems.size(); i++ ) - { - NSMenuItem* pItem = maItems[i]->mpMenuItem; - [mpMenu insertItem: pItem atIndex: i+1]; - } - pCurrentMenuBar = this; - - // change status item - statusLayout(); - } - enableMainMenu( true ); - } -} - -void AquaSalMenu::setDefaultMenu() -{ - NSMenu* pMenu = [NSApp mainMenu]; - - unsetMainMenu(); - - // insert default items - std::vector< NSMenuItem* >& rFallbackMenu( GetSalData()->maFallbackMenu ); - for( unsigned int i = 0, nAddItems = rFallbackMenu.size(); i < nAddItems; i++ ) - { - NSMenuItem* pItem = rFallbackMenu[i]; - if( [pItem menu] == nil ) - [pMenu insertItem: pItem atIndex: i+1]; - } -} - -void AquaSalMenu::enableMainMenu( bool bEnable ) -{ - NSMenu* pMainMenu = [NSApp mainMenu]; - if( pMainMenu ) - { - // enable/disable items from main menu - int nItems = [pMainMenu numberOfItems]; - for( int n = 1; n < nItems; n++ ) - { - NSMenuItem* pItem = [pMainMenu itemAtIndex: n]; - [pItem setEnabled: bEnable ? YES : NO]; - } - } -} - -void AquaSalMenu::addFallbackMenuItem( NSMenuItem* pNewItem ) -{ - initAppMenu(); - - std::vector< NSMenuItem* >& rFallbackMenu( GetSalData()->maFallbackMenu ); - - // prevent duplicate insertion - int nItems = rFallbackMenu.size(); - for( int i = 0; i < nItems; i++ ) - { - if( rFallbackMenu[i] == pNewItem ) - return; - } - - // push the item to the back and retain it - [pNewItem retain]; - rFallbackMenu.push_back( pNewItem ); - - if( pCurrentMenuBar == NULL ) - setDefaultMenu(); -} - -void AquaSalMenu::removeFallbackMenuItem( NSMenuItem* pOldItem ) -{ - std::vector< NSMenuItem* >& rFallbackMenu( GetSalData()->maFallbackMenu ); - - // find item - unsigned int nItems = rFallbackMenu.size(); - for( unsigned int i = 0; i < nItems; i++ ) - { - if( rFallbackMenu[i] == pOldItem ) - { - // remove item and release - rFallbackMenu.erase( rFallbackMenu.begin() + i ); - [pOldItem release]; - - if( pCurrentMenuBar == NULL ) - setDefaultMenu(); - - return; - } - } -} - -sal_Bool AquaSalMenu::VisibleMenuBar() -{ - // Enable/disable experimental native menus code? - // - // To disable native menus, set the environment variable AQUA_NATIVE_MENUS to FALSE - - static const char *pExperimental = getenv ("AQUA_NATIVE_MENUS"); - - if ( ImplGetSVData()->mbIsTestTool || (pExperimental && !strcasecmp(pExperimental, "FALSE")) ) - return sal_False; - - // End of experimental code enable/disable part - - return sal_True; -} - -void AquaSalMenu::SetFrame( const SalFrame *pFrame ) -{ - mpFrame = static_cast<const AquaSalFrame*>(pFrame); -} - -void AquaSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) -{ - AquaSalMenuItem *pAquaSalMenuItem = static_cast<AquaSalMenuItem*>(pSalMenuItem); - - pAquaSalMenuItem->mpParentMenu = this; - DBG_ASSERT( pAquaSalMenuItem->mpVCLMenu == NULL || - pAquaSalMenuItem->mpVCLMenu == mpVCLMenu || - mpVCLMenu == NULL, - "resetting menu ?" ); - if( pAquaSalMenuItem->mpVCLMenu ) - mpVCLMenu = pAquaSalMenuItem->mpVCLMenu; - - if( nPos == MENU_APPEND || nPos == maItems.size() ) - maItems.push_back( pAquaSalMenuItem ); - else if( nPos < maItems.size() ) - maItems.insert( maItems.begin() + nPos, pAquaSalMenuItem ); - else - { - OSL_FAIL( "invalid item index in insert" ); - return; - } - - if( ! mbMenuBar || pCurrentMenuBar == this ) - [mpMenu insertItem: pAquaSalMenuItem->mpMenuItem atIndex: getItemIndexByPos(nPos)]; -} - -void AquaSalMenu::RemoveItem( unsigned nPos ) -{ - AquaSalMenuItem* pRemoveItem = NULL; - if( nPos == MENU_APPEND || nPos == (maItems.size()-1) ) - { - pRemoveItem = maItems.back(); - maItems.pop_back(); - } - else if( nPos < maItems.size() ) - { - pRemoveItem = maItems[ nPos ]; - maItems.erase( maItems.begin()+nPos ); - } - else - { - OSL_FAIL( "invalid item index in remove" ); - return; - } - - pRemoveItem->mpParentMenu = NULL; - - if( ! mbMenuBar || pCurrentMenuBar == this ) - [mpMenu removeItemAtIndex: getItemIndexByPos(nPos)]; -} - -void AquaSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned /*nPos*/ ) -{ - AquaSalMenuItem *pAquaSalMenuItem = static_cast<AquaSalMenuItem*>(pSalMenuItem); - AquaSalMenu *subAquaSalMenu = static_cast<AquaSalMenu*>(pSubMenu); - - if (subAquaSalMenu) - { - pAquaSalMenuItem->mpSubMenu = subAquaSalMenu; - if( subAquaSalMenu->mpParentSalMenu == NULL ) - { - subAquaSalMenu->mpParentSalMenu = this; - [pAquaSalMenuItem->mpMenuItem setSubmenu: subAquaSalMenu->mpMenu]; - - // set title of submenu - [subAquaSalMenu->mpMenu setTitle: [pAquaSalMenuItem->mpMenuItem title]]; - } - else if( subAquaSalMenu->mpParentSalMenu != this ) - { - // cocoa doesn't allow menus to be submenus of multiple - // menu items, so place a copy in the menu item instead ? - // let's hope that NSMenu copy does the right thing - NSMenu* pCopy = [subAquaSalMenu->mpMenu copy]; - [pAquaSalMenuItem->mpMenuItem setSubmenu: pCopy]; - - // set title of submenu - [pCopy setTitle: [pAquaSalMenuItem->mpMenuItem title]]; - } - } - else - { - if( pAquaSalMenuItem->mpSubMenu ) - { - if( pAquaSalMenuItem->mpSubMenu->mpParentSalMenu == this ) - pAquaSalMenuItem->mpSubMenu->mpParentSalMenu = NULL; - } - pAquaSalMenuItem->mpSubMenu = NULL; - [pAquaSalMenuItem->mpMenuItem setSubmenu: nil]; - } -} - -void AquaSalMenu::CheckItem( unsigned nPos, sal_Bool bCheck ) -{ - if( nPos < maItems.size() ) - { - NSMenuItem* pItem = maItems[nPos]->mpMenuItem; - [pItem setState: bCheck ? NSOnState : NSOffState]; - } -} - -void AquaSalMenu::EnableItem( unsigned nPos, sal_Bool bEnable ) -{ - if( nPos < maItems.size() ) - { - NSMenuItem* pItem = maItems[nPos]->mpMenuItem; - [pItem setEnabled: bEnable ? YES : NO]; - } -} - -void AquaSalMenu::SetItemImage( unsigned /*nPos*/, SalMenuItem* pSMI, const Image& rImage ) -{ - AquaSalMenuItem* pSalMenuItem = static_cast<AquaSalMenuItem*>( pSMI ); - if( ! pSalMenuItem || ! pSalMenuItem->mpMenuItem ) - return; - - NSImage* pImage = CreateNSImage( rImage ); - - [pSalMenuItem->mpMenuItem setImage: pImage]; - if( pImage ) - [pImage release]; -} - -void AquaSalMenu::SetItemText( unsigned /*i_nPos*/, SalMenuItem* i_pSalMenuItem, const XubString& i_rText ) -{ - if (!i_pSalMenuItem) - return; - - AquaSalMenuItem *pAquaSalMenuItem = (AquaSalMenuItem *) i_pSalMenuItem; - - String aText( i_rText ); - - // Delete mnemonics - aText.EraseAllChars( '~' ); - - /* #i90015# until there is a correct solution - strip out any appended (.*) in menubar entries - */ - if( mbMenuBar ) - { - xub_StrLen nPos = aText.SearchBackward( sal_Unicode( '(' ) ); - if( nPos != STRING_NOTFOUND ) - { - xub_StrLen nPos2 = aText.Search( sal_Unicode( ')' ) ); - if( nPos2 != STRING_NOTFOUND ) - aText.Erase( nPos, nPos2-nPos+1 ); - } - } - - NSString* pString = CreateNSString( aText ); - if (pString) - { - [pAquaSalMenuItem->mpMenuItem setTitle: pString]; - // if the menu item has a submenu, change its title as well - if (pAquaSalMenuItem->mpSubMenu) - [pAquaSalMenuItem->mpSubMenu->mpMenu setTitle: pString]; - [pString release]; - } -} - -void AquaSalMenu::SetAccelerator( unsigned /*nPos*/, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const XubString& /*rKeyName*/ ) -{ - sal_uInt16 nModifier; - sal_Unicode nCommandKey = 0; - - sal_uInt16 nKeyCode=rKeyCode.GetCode(); - if( nKeyCode ) - { - if ((nKeyCode>=KEY_A) && (nKeyCode<=KEY_Z)) // letter A..Z - nCommandKey = nKeyCode-KEY_A + 'a'; - else if ((nKeyCode>=KEY_0) && (nKeyCode<=KEY_9)) // numbers 0..9 - nCommandKey = nKeyCode-KEY_0 + '0'; - else if ((nKeyCode>=KEY_F1) && (nKeyCode<=KEY_F26)) // function keys F1..F26 - nCommandKey = nKeyCode-KEY_F1 + NSF1FunctionKey; - else if( nKeyCode == KEY_REPEAT ) - nCommandKey = NSRedoFunctionKey; - else if( nKeyCode == KEY_SPACE ) - nCommandKey = ' '; - else - { - switch (nKeyCode) - { - case KEY_ADD: - nCommandKey='+'; - break; - case KEY_SUBTRACT: - nCommandKey='-'; - break; - case KEY_MULTIPLY: - nCommandKey='*'; - break; - case KEY_DIVIDE: - nCommandKey='/'; - break; - case KEY_POINT: - nCommandKey='.'; - break; - case KEY_LESS: - nCommandKey='<'; - break; - case KEY_GREATER: - nCommandKey='>'; - break; - case KEY_EQUAL: - nCommandKey='='; - break; - } - } - } - else // not even a code ? nonsense -> ignore - return; - - DBG_ASSERT( nCommandKey, "unmapped accelerator key" ); - - nModifier=rKeyCode.GetAllModifier(); - - // should always use the command key - int nItemModifier = 0; - - if (nModifier & KEY_SHIFT) - { - nItemModifier |= NSShiftKeyMask; // actually useful only for function keys - if( nKeyCode >= KEY_A && nKeyCode <= KEY_Z ) - nCommandKey = nKeyCode - KEY_A + 'A'; - } - - if (nModifier & KEY_MOD1) - nItemModifier |= NSCommandKeyMask; - - if(nModifier & KEY_MOD2) - nItemModifier |= NSAlternateKeyMask; - - if(nModifier & KEY_MOD3) - nItemModifier |= NSControlKeyMask; - - AquaSalMenuItem *pAquaSalMenuItem = (AquaSalMenuItem *) pSalMenuItem; - NSString* pString = CreateNSString( rtl::OUString( &nCommandKey, 1 ) ); - [pAquaSalMenuItem->mpMenuItem setKeyEquivalent: pString]; - [pAquaSalMenuItem->mpMenuItem setKeyEquivalentModifierMask: nItemModifier]; - if (pString) - [pString release]; -} - -void AquaSalMenu::GetSystemMenuData( SystemMenuData* ) -{ -} - -AquaSalMenu::MenuBarButtonEntry* AquaSalMenu::findButtonItem( sal_uInt16 i_nItemId ) -{ - for( size_t i = 0; i < maButtons.size(); ++i ) - { - if( maButtons[i].maButton.mnId == i_nItemId ) - return &maButtons[i]; - } - return NULL; -} - -void AquaSalMenu::statusLayout() -{ - if( GetSalData()->mpStatusItem ) - { - NSView* pView = [GetSalData()->mpStatusItem view]; - if( [pView isMemberOfClass: [OOStatusItemView class]] ) // well of course it is - [(OOStatusItemView*)pView layout]; - else - OSL_FAIL( "someone stole our status view" ); - } -} - -void AquaSalMenu::releaseButtonEntry( MenuBarButtonEntry& i_rEntry ) -{ - if( i_rEntry.mpNSImage ) - { - [i_rEntry.mpNSImage release]; - i_rEntry.mpNSImage = nil; - } - if( i_rEntry.mpToolTipString ) - { - [i_rEntry.mpToolTipString release]; - i_rEntry.mpToolTipString = nil; - } -} - -bool AquaSalMenu::AddMenuBarButton( const SalMenuButtonItem& i_rNewItem ) -{ - if( ! mbMenuBar || ! VisibleMenuBar() ) - return false; - - MenuBarButtonEntry* pEntry = findButtonItem( i_rNewItem.mnId ); - if( pEntry ) - { - releaseButtonEntry( *pEntry ); - pEntry->maButton = i_rNewItem; - pEntry->mpNSImage = CreateNSImage( i_rNewItem.maImage ); - if( i_rNewItem.maToolTipText.getLength() ) - pEntry->mpToolTipString = CreateNSString( i_rNewItem.maToolTipText ); - } - else - { - maButtons.push_back( MenuBarButtonEntry( i_rNewItem ) ); - maButtons.back().mpNSImage = CreateNSImage( i_rNewItem.maImage ); - maButtons.back().mpToolTipString = CreateNSString( i_rNewItem.maToolTipText ); - } - - // lazy create status item - SalData::getStatusItem(); - - if( pCurrentMenuBar == this ) - statusLayout(); - - return true; -} - -void AquaSalMenu::RemoveMenuBarButton( sal_uInt16 i_nId ) -{ - MenuBarButtonEntry* pEntry = findButtonItem( i_nId ); - if( pEntry ) - { - releaseButtonEntry( *pEntry ); - // note: vector guarantees that its contents are in a plain array - maButtons.erase( maButtons.begin() + (pEntry - &maButtons[0]) ); - } - - if( pCurrentMenuBar == this ) - statusLayout(); -} - -Rectangle AquaSalMenu::GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame ) -{ - if( GetSalData()->mnSystemVersion < VER_LEOPARD ) - return Rectangle( Point( -1, -1 ), Size( 1, 1 ) ); - - if( ! i_pReferenceFrame || ! AquaSalFrame::isAlive( static_cast<AquaSalFrame*>(i_pReferenceFrame) ) ) - return Rectangle(); - - MenuBarButtonEntry* pEntry = findButtonItem( i_nItemId ); - - if( ! pEntry ) - return Rectangle(); - - NSStatusItem* pItem = SalData::getStatusItem(); - if( ! pItem ) - return Rectangle(); - - NSView* pView = [pItem view]; - if( ! pView ) - return Rectangle(); - NSWindow* pWin = [pView window]; - if( ! pWin ) - return Rectangle(); - - NSRect aRect = [pWin frame]; - aRect.origin = [pWin convertBaseToScreen: NSMakePoint( 0, 0 )]; - - // make coordinates relative to reference frame - static_cast<AquaSalFrame*>(i_pReferenceFrame)->CocoaToVCL( aRect.origin ); - aRect.origin.x -= i_pReferenceFrame->maGeometry.nX; - aRect.origin.y -= i_pReferenceFrame->maGeometry.nY + aRect.size.height; - - return Rectangle( Point(static_cast<long int>(aRect.origin.x), - static_cast<long int>(aRect.origin.y) - ), - Size( static_cast<long int>(aRect.size.width), - static_cast<long int>(aRect.size.height) - ) - ); -} - -// ======================================================================= - -/* - * SalMenuItem - */ - -AquaSalMenuItem::AquaSalMenuItem( const SalItemParams* pItemData ) : - mnId( pItemData->nId ), - mpVCLMenu( pItemData->pMenu ), - mpParentMenu( NULL ), - mpSubMenu( NULL ), - mpMenuItem( nil ) -{ - String aText( pItemData->aText ); - - // Delete mnemonics - aText.EraseAllChars( '~' ); - - if (pItemData->eType == MENUITEM_SEPARATOR) - { - mpMenuItem = [NSMenuItem separatorItem]; - // these can go occasionally go in and out of a menu, ensure their lifecycle - // also for the release in AquaSalMenuItem destructor - [mpMenuItem retain]; - } - else - { - mpMenuItem = [[SalNSMenuItem alloc] initWithMenuItem: this]; - [mpMenuItem setEnabled: YES]; - NSString* pString = CreateNSString( aText ); - if (pString) - { - [mpMenuItem setTitle: pString]; - [pString release]; - } - // anything but a separator should set a menu to dispatch to - DBG_ASSERT( mpVCLMenu, "no menu" ); - } -} - -AquaSalMenuItem::~AquaSalMenuItem() -{ - /* #i89860# FIXME: - using [autorelease] here (and in AquaSalMenu:::~AquaSalMenu) instead of - [release] fixes an occasional crash. That should indicate that we release - menus / menu items in the wrong order somewhere, but I - could not find that case. - */ - if( mpMenuItem ) - [mpMenuItem autorelease]; -} - -// ------------------------------------------------------------------- - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/aqua/source/window/salnsmenu.mm b/vcl/aqua/source/window/salnsmenu.mm deleted file mode 100644 index c2f182773c..0000000000 --- a/vcl/aqua/source/window/salnsmenu.mm +++ /dev/null @@ -1,217 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_vcl.hxx" - -#include "aqua/salinst.h" -#include "aqua/saldata.hxx" -#include "aqua/salframe.h" -#include "aqua/salmenu.h" -#include "aqua/salnsmenu.h" - -#include "vcl/window.hxx" - -@implementation SalNSMenu --(id)initWithMenu: (AquaSalMenu*)pMenu -{ - mpMenu = pMenu; - return [super initWithTitle: [NSString string]]; -} - --(void)menuNeedsUpdate: (NSMenu*)pMenu -{ - (void)pMenu; - YIELD_GUARD; - - if( mpMenu ) - { - const AquaSalFrame* pFrame = mpMenu->getFrame(); - if( pFrame && AquaSalFrame::isAlive( pFrame ) ) - { - SalMenuEvent aMenuEvt; - aMenuEvt.mnId = 0; - aMenuEvt.mpMenu = mpMenu->mpVCLMenu; - if( aMenuEvt.mpMenu ) - { - pFrame->CallCallback(SALEVENT_MENUACTIVATE, &aMenuEvt); - pFrame->CallCallback(SALEVENT_MENUDEACTIVATE, &aMenuEvt); - } - else - OSL_FAIL( "unconnected menu" ); - } - } -} - --(void)setSalMenu: (AquaSalMenu*)pMenu -{ - mpMenu = pMenu; -} -@end - -@implementation SalNSMenuItem --(id)initWithMenuItem: (AquaSalMenuItem*)pMenuItem -{ - mpMenuItem = pMenuItem; - id ret = [super initWithTitle: [NSString string] - action: @selector(menuItemTriggered:) - keyEquivalent: [NSString string]]; - [ret setTarget: self]; - return ret; -} --(void)menuItemTriggered: (id)aSender -{ - (void)aSender; - YIELD_GUARD; - - const AquaSalFrame* pFrame = mpMenuItem->mpParentMenu ? mpMenuItem->mpParentMenu->getFrame() : NULL; - if( pFrame && AquaSalFrame::isAlive( pFrame ) && ! pFrame->GetWindow()->IsInModalMode() ) - { - SalMenuEvent aMenuEvt( mpMenuItem->mnId, mpMenuItem->mpVCLMenu ); - pFrame->CallCallback(SALEVENT_MENUCOMMAND, &aMenuEvt); - } - else if( mpMenuItem->mpVCLMenu ) - { - // if an item from submenu was selected. the corresponding Window does not exist because - // we use native popup menus, so we have to set the selected menuitem directly - // incidentally this of course works for top level popup menus, too - PopupMenu * pPopupMenu = dynamic_cast<PopupMenu *>(mpMenuItem->mpVCLMenu); - if( pPopupMenu ) - { - // FIXME: revise this ugly code - - // select handlers in vcl are dispatch on the original menu - // if not consumed by the select handler of the current menu - // however since only the starting menu ever came into Execute - // the hierarchy is not build up. Workaround this by getting - // the menu it should have been - - // get started from hierarchy in vcl menus - AquaSalMenu* pParentMenu = mpMenuItem->mpParentMenu; - Menu* pCurMenu = mpMenuItem->mpVCLMenu; - while( pParentMenu && pParentMenu->mpVCLMenu ) - { - pCurMenu = pParentMenu->mpVCLMenu; - pParentMenu = pParentMenu->mpParentSalMenu; - } - - pPopupMenu->SetSelectedEntry( mpMenuItem->mnId ); - pPopupMenu->ImplSelectWithStart( pCurMenu ); - } - else - OSL_FAIL( "menubar item without frame !" ); - } -} -@end - -@implementation OOStatusItemView --(void)drawRect: (NSRect)aRect -{ - NSGraphicsContext* pContext = [NSGraphicsContext currentContext]; - [pContext saveGraphicsState]; - [SalData::getStatusItem() drawStatusBarBackgroundInRect: aRect withHighlight: NO]; - if( AquaSalMenu::pCurrentMenuBar ) - { - const std::vector< AquaSalMenu::MenuBarButtonEntry >& rButtons( AquaSalMenu::pCurrentMenuBar->getButtons() ); - NSRect aFrame = [self frame]; - NSRect aImgRect = { { 2, 0 }, { 0, 0 } }; - for( size_t i = 0; i < rButtons.size(); ++i ) - { - NSRect aFromRect = { { 0, 0 }, - { rButtons[i].maButton.maImage.GetSizePixel().Width(), - rButtons[i].maButton.maImage.GetSizePixel().Height() } }; - aImgRect.origin.y = floor((aFrame.size.height - aFromRect.size.height)/2); - aImgRect.size = aFromRect.size; - if( rButtons[i].mpNSImage ) - [rButtons[i].mpNSImage drawInRect: aImgRect fromRect: aFromRect operation: NSCompositeSourceOver fraction: 1.0]; - aImgRect.origin.x += aFromRect.size.width + 2; - } - } - [pContext restoreGraphicsState]; -} - --(void)mouseUp: (NSEvent *)pEvent -{ - /* check if button goes up inside one of our status buttons */ - if( AquaSalMenu::pCurrentMenuBar ) - { - const std::vector< AquaSalMenu::MenuBarButtonEntry >& rButtons( AquaSalMenu::pCurrentMenuBar->getButtons() ); - NSRect aFrame = [self frame]; - NSRect aImgRect = { { 2, 0 }, { 0, 0 } }; - NSPoint aMousePt = [pEvent locationInWindow]; - for( size_t i = 0; i < rButtons.size(); ++i ) - { - NSRect aFromRect = { { 0, 0 }, - { rButtons[i].maButton.maImage.GetSizePixel().Width(), - rButtons[i].maButton.maImage.GetSizePixel().Height() } }; - aImgRect.origin.y = (aFrame.size.height - aFromRect.size.height)/2; - aImgRect.size = aFromRect.size; - if( aMousePt.x >= aImgRect.origin.x && aMousePt.x <= (aImgRect.origin.x+aImgRect.size.width) && - aMousePt.y >= aImgRect.origin.y && aMousePt.y <= (aImgRect.origin.y+aImgRect.size.height) ) - { - if( AquaSalMenu::pCurrentMenuBar->mpFrame && AquaSalFrame::isAlive( AquaSalMenu::pCurrentMenuBar->mpFrame ) ) - { - SalMenuEvent aMenuEvt( rButtons[i].maButton.mnId, AquaSalMenu::pCurrentMenuBar->mpVCLMenu ); - AquaSalMenu::pCurrentMenuBar->mpFrame->CallCallback(SALEVENT_MENUBUTTONCOMMAND, &aMenuEvt); - } - return; - } - - aImgRect.origin.x += aFromRect.size.width + 2; - } - } -} - --(void)layout -{ - NSStatusBar* pStatBar = [NSStatusBar systemStatusBar]; - NSSize aSize = { 0, [pStatBar thickness] }; - [self removeAllToolTips]; - if( AquaSalMenu::pCurrentMenuBar ) - { - const std::vector< AquaSalMenu::MenuBarButtonEntry >& rButtons( AquaSalMenu::pCurrentMenuBar->getButtons() ); - if( ! rButtons.empty() ) - { - aSize.width = 2; - for( size_t i = 0; i < rButtons.size(); ++i ) - { - NSRect aImgRect = { { aSize.width, floor((aSize.height-rButtons[i].maButton.maImage.GetSizePixel().Height())/2) }, - { rButtons[i].maButton.maImage.GetSizePixel().Width(), - rButtons[i].maButton.maImage.GetSizePixel().Height() } }; - if( rButtons[i].mpToolTipString ) - [self addToolTipRect: aImgRect owner: rButtons[i].mpToolTipString userData: NULL]; - aSize.width += 2 + aImgRect.size.width; - } - } - } - [self setFrameSize: aSize]; -} -@end - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/aqua/source/window/salobj.cxx b/vcl/aqua/source/window/salobj.cxx deleted file mode 100644 index 3f2a9fcede..0000000000 --- a/vcl/aqua/source/window/salobj.cxx +++ /dev/null @@ -1,247 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_vcl.hxx" - -#include <string.h> - -#include "aqua/saldata.hxx" -#include "aqua/salobj.h" -#include "aqua/salframe.h" - -// ======================================================================= - -AquaSalObject::AquaSalObject( AquaSalFrame* pFrame ) : - mpFrame( pFrame ), - mnClipX( -1 ), - mnClipY( -1 ), - mnClipWidth( -1 ), - mnClipHeight( -1 ), - mbClip( false ), - mnX( 0 ), - mnY( 0 ), - mnWidth( 20 ), - mnHeight( 20 ) -{ - maSysData.nSize = sizeof( maSysData ); - maSysData.pView = NULL; - - NSRect aInitFrame = { { 0, 0 }, { 20, 20 } }; - mpClipView = [[NSClipView alloc] initWithFrame: aInitFrame ]; - if( mpClipView ) - { - [mpFrame->getView() addSubview: mpClipView]; - [mpClipView setHidden: YES]; - } - maSysData.pView = [[NSView alloc] initWithFrame: aInitFrame]; - if( maSysData.pView ) - { - if( mpClipView ) - [mpClipView setDocumentView: maSysData.pView]; - } -} - -// ----------------------------------------------------------------------- - -AquaSalObject::~AquaSalObject() -{ - if( maSysData.pView ) - { - NSView *pView = maSysData.pView; - [pView removeFromSuperview]; - [pView release]; - } - if( mpClipView ) - { - [mpClipView removeFromSuperview]; - [mpClipView release]; - } -} - -/* - sadly there seems to be no way to impose clipping on a child view, - especially a QTMovieView which seems to ignore the current context - completely. Also there is no real way to shape a window; on Aqua a - similar effect to non-rectangular windows is achieved by using a - non-opaque window and not painting where one wants the background - to shine through. - - With respect to SalObject this leaves us to having an NSClipView - containing the child view. Even a QTMovieView respects the boundaries of - that, which gives us a clip "region" consisting of one rectangle. - This is gives us an 80% solution only, though. -*/ - -// ----------------------------------------------------------------------- - -void AquaSalObject::ResetClipRegion() -{ - mbClip = false; - setClippedPosSize(); -} - -// ----------------------------------------------------------------------- - -sal_uInt16 AquaSalObject::GetClipRegionType() -{ - return SAL_OBJECT_CLIP_INCLUDERECTS; -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::BeginSetClipRegion( sal_uLong ) -{ - mbClip = false; -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight ) -{ - if( mbClip ) - { - if( nX < mnClipX ) - { - mnClipWidth += mnClipX - nX; - mnClipX = nX; - } - if( nX + nWidth > mnClipX + mnClipWidth ) - mnClipWidth = nX + nWidth - mnClipX; - if( nY < mnClipY ) - { - mnClipHeight += mnClipY - nY; - mnClipY = nY; - } - if( nY + nHeight > mnClipY + mnClipHeight ) - mnClipHeight = nY + nHeight - mnClipY; - } - else - { - mnClipX = nX; - mnClipY = nY; - mnClipWidth = nWidth; - mnClipHeight = nHeight; - mbClip = true; - } -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::EndSetClipRegion() -{ - setClippedPosSize(); -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight ) -{ - mnX = nX; - mnY = nY; - mnWidth = nWidth; - mnHeight = nHeight; - setClippedPosSize(); -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::setClippedPosSize() -{ - NSRect aViewRect = { { 0, 0 }, { mnWidth, mnHeight } }; - if( maSysData.pView ) - { - NSView *pView = maSysData.pView; - [pView setFrame: aViewRect]; - } - - NSRect aClipViewRect = { { mnX, mnY }, { mnWidth, mnHeight } }; - NSPoint aClipPt = { 0, 0 }; - if( mbClip ) - { - aClipViewRect.origin.x += mnClipX; - aClipViewRect.origin.y += mnClipY; - aClipViewRect.size.width = mnClipWidth; - aClipViewRect.size.height = mnClipHeight; - aClipPt.x = mnClipX; - if( mnClipY == 0 ) - aClipPt.y = mnHeight - mnClipHeight;; - } - - mpFrame->VCLToCocoa( aClipViewRect, false ); - [mpClipView setFrame: aClipViewRect]; - - [mpClipView scrollToPoint: aClipPt]; -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::Show( sal_Bool bVisible ) -{ - if( mpClipView ) - [mpClipView setHidden: (bVisible ? NO : YES)]; -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::Enable( sal_Bool ) -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::GrabFocus() -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::SetBackground() -{ -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::SetBackground( SalColor ) -{ -} - -// ----------------------------------------------------------------------- - -const SystemEnvData* AquaSalObject::GetSystemData() const -{ - return &maSysData; -} - -// ----------------------------------------------------------------------- - -void AquaSalObject::InterceptChildWindowKeyDown( sal_Bool /*bIntercept*/ ) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |