xref: /aoo42x/main/vcl/aqua/source/window/salframe.cxx (revision 01367266)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "osl/file.h"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "vcl/svapp.hxx"
34cdf0e10cSrcweir #include "vcl/window.hxx"
35cdf0e10cSrcweir #include "vcl/timer.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "aqua/saldata.hxx"
38cdf0e10cSrcweir #include "aqua/salgdi.h"
39cdf0e10cSrcweir #include "aqua/salframe.h"
40cdf0e10cSrcweir #include "aqua/salmenu.h"
41cdf0e10cSrcweir #include "aqua/saltimer.h"
42cdf0e10cSrcweir #include "aqua/salinst.h"
43cdf0e10cSrcweir #include "aqua/salframeview.h"
44cdf0e10cSrcweir #include "aqua/aqua11yfactory.h"
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "salwtype.hxx"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include "premac.h"
49cdf0e10cSrcweir // needed for theming
50cdf0e10cSrcweir // FIXME: move theming code to salnativewidgets.cxx
51cdf0e10cSrcweir #include <Carbon/Carbon.h>
52cdf0e10cSrcweir #include "postmac.h"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace std;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // =======================================================================
58cdf0e10cSrcweir 
59cdf0e10cSrcweir AquaSalFrame* AquaSalFrame::s_pCaptureFrame = NULL;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // =======================================================================
62cdf0e10cSrcweir 
AquaSalFrame(SalFrame * pParent,sal_uLong salFrameStyle)63cdf0e10cSrcweir AquaSalFrame::AquaSalFrame( SalFrame* pParent, sal_uLong salFrameStyle ) :
64bde8a4bdSHerbert Dürr     mpNSWindow(nil),
65bde8a4bdSHerbert Dürr     mpNSView(nil),
66cdf0e10cSrcweir     mpDockMenuEntry(nil),
67cdf0e10cSrcweir     mpGraphics(NULL),
68cdf0e10cSrcweir     mpParent(NULL),
69cdf0e10cSrcweir     mnMinWidth(0),
70cdf0e10cSrcweir     mnMinHeight(0),
71cdf0e10cSrcweir     mnMaxWidth(0),
72cdf0e10cSrcweir     mnMaxHeight(0),
73cdf0e10cSrcweir     mbGraphics(false),
74cdf0e10cSrcweir     mbFullScreen( false ),
75cdf0e10cSrcweir     mbShown(false),
76cdf0e10cSrcweir     mbInitShow(true),
77cdf0e10cSrcweir     mbPositioned(false),
78cdf0e10cSrcweir     mbSized(false),
79cdf0e10cSrcweir     mbPresentation( false ),
80cdf0e10cSrcweir     mnStyle( salFrameStyle ),
81cdf0e10cSrcweir     mnStyleMask( 0 ),
82cdf0e10cSrcweir     mnLastEventTime( 0 ),
83cdf0e10cSrcweir     mnLastModifierFlags( 0 ),
84cdf0e10cSrcweir     mpMenu( NULL ),
85cdf0e10cSrcweir     mnExtStyle( 0 ),
86cdf0e10cSrcweir     mePointerStyle( POINTER_ARROW ),
87cdf0e10cSrcweir     mnTrackingRectTag( 0 ),
88cdf0e10cSrcweir     mrClippingPath( 0 ),
89cdf0e10cSrcweir     mnICOptions( 0 )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     maSysData.nSize     = sizeof( SystemEnvData );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     mpParent = dynamic_cast<AquaSalFrame*>(pParent);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     initWindowAndView();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     SalData* pSalData = GetSalData();
98cdf0e10cSrcweir     pSalData->maFrames.push_front( this );
99cdf0e10cSrcweir     pSalData->maFrameCheck.insert( this );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir // -----------------------------------------------------------------------
103cdf0e10cSrcweir 
~AquaSalFrame()104cdf0e10cSrcweir AquaSalFrame::~AquaSalFrame()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     // if the frame is destroyed and has the current menubar
107cdf0e10cSrcweir     // set the default menubar
108cdf0e10cSrcweir     if( mpMenu && mpMenu->mbMenuBar && AquaSalMenu::pCurrentMenuBar == mpMenu )
109cdf0e10cSrcweir         AquaSalMenu::setDefaultMenu();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     // cleanup clipping stuff
112cdf0e10cSrcweir     ResetClipRegion();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     [SalFrameView unsetMouseFrame: this];
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     SalData* pSalData = GetSalData();
117cdf0e10cSrcweir     pSalData->maFrames.remove( this );
118cdf0e10cSrcweir     pSalData->maFrameCheck.erase( this );
119ff005604SEike Rathke     pSalData->maPresentationFrames.remove( this );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     DBG_ASSERT( this != s_pCaptureFrame, "capture frame destroyed" );
122cdf0e10cSrcweir     if( this == s_pCaptureFrame )
123cdf0e10cSrcweir         s_pCaptureFrame = NULL;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	if ( mpGraphics )
126cdf0e10cSrcweir 		delete mpGraphics;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     if( mpDockMenuEntry )
129cdf0e10cSrcweir         // life cycle comment: the menu has ownership of the item, so no release
130cdf0e10cSrcweir         [AquaSalInstance::GetDynamicDockMenu() removeItem: mpDockMenuEntry];
131bde8a4bdSHerbert Dürr     if ( mpNSView ) {
132bde8a4bdSHerbert Dürr         [AquaA11yFactory revokeView: mpNSView];
133bde8a4bdSHerbert Dürr         [mpNSView release];
134cdf0e10cSrcweir     }
135bde8a4bdSHerbert Dürr     if ( mpNSWindow )
136bde8a4bdSHerbert Dürr         [mpNSWindow release];
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir // -----------------------------------------------------------------------
140cdf0e10cSrcweir 
initWindowAndView()141cdf0e10cSrcweir void AquaSalFrame::initWindowAndView()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     // initialize mirroring parameters
144cdf0e10cSrcweir     // FIXME: screens changing
145bde8a4bdSHerbert Dürr     NSScreen* pNSScreen = [mpNSWindow screen];
146bde8a4bdSHerbert Dürr     if( pNSScreen == nil )
147bde8a4bdSHerbert Dürr         pNSScreen = [NSScreen mainScreen];
148bde8a4bdSHerbert Dürr     maScreenRect = [pNSScreen frame];
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     // calculate some default geometry
151bde8a4bdSHerbert Dürr     NSRect aVisibleRect = [pNSScreen visibleFrame];
152cdf0e10cSrcweir     CocoaToVCL( aVisibleRect );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     maGeometry.nX = static_cast<int>(aVisibleRect.origin.x + aVisibleRect.size.width / 10);
155cdf0e10cSrcweir     maGeometry.nY = static_cast<int>(aVisibleRect.origin.y + aVisibleRect.size.height / 10);
156cdf0e10cSrcweir     maGeometry.nWidth = static_cast<unsigned int>(aVisibleRect.size.width * 0.8);
157cdf0e10cSrcweir     maGeometry.nHeight = static_cast<unsigned int>(aVisibleRect.size.height * 0.8);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     // calculate style mask
160cdf0e10cSrcweir     if( (mnStyle & SAL_FRAME_STYLE_FLOAT) ||
161cdf0e10cSrcweir         (mnStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
162cdf0e10cSrcweir         mnStyleMask = NSBorderlessWindowMask;
163cdf0e10cSrcweir     else if( mnStyle & SAL_FRAME_STYLE_DEFAULT )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         mnStyleMask = NSTitledWindowMask            |
166cdf0e10cSrcweir                       NSMiniaturizableWindowMask    |
167cdf0e10cSrcweir                       NSResizableWindowMask         |
168cdf0e10cSrcweir                       NSClosableWindowMask;
169cdf0e10cSrcweir         // make default window "maximized"
170cdf0e10cSrcweir         maGeometry.nX = static_cast<int>(aVisibleRect.origin.x);
171cdf0e10cSrcweir         maGeometry.nY = static_cast<int>(aVisibleRect.origin.y);
172cdf0e10cSrcweir         maGeometry.nWidth = static_cast<int>(aVisibleRect.size.width);
173cdf0e10cSrcweir         maGeometry.nHeight = static_cast<int>(aVisibleRect.size.height);
174cdf0e10cSrcweir         mbPositioned = mbSized = true;
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir     else
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir         if( (mnStyle & SAL_FRAME_STYLE_MOVEABLE) )
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             mnStyleMask |= NSTitledWindowMask;
181cdf0e10cSrcweir             if( mpParent == NULL )
182cdf0e10cSrcweir                 mnStyleMask |= NSMiniaturizableWindowMask;
183cdf0e10cSrcweir         }
184cdf0e10cSrcweir         if( (mnStyle & SAL_FRAME_STYLE_SIZEABLE) )
185cdf0e10cSrcweir             mnStyleMask |= NSResizableWindowMask;
186cdf0e10cSrcweir         if( (mnStyle & SAL_FRAME_STYLE_CLOSEABLE) )
187cdf0e10cSrcweir             mnStyleMask |= NSClosableWindowMask;
188cdf0e10cSrcweir         // documentation says anything other than NSBorderlessWindowMask (=0)
189cdf0e10cSrcweir         // should also include NSTitledWindowMask;
190cdf0e10cSrcweir         if( mnStyleMask != 0 )
191cdf0e10cSrcweir             mnStyleMask |= NSTitledWindowMask;
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     // #i91990# support GUI-less (daemon) execution
195cdf0e10cSrcweir     @try
196cdf0e10cSrcweir     {
197bde8a4bdSHerbert Dürr         mpNSWindow = [[SalFrameWindow alloc] initWithSalFrame: this];
198bde8a4bdSHerbert Dürr         mpNSView = [[SalFrameView alloc] initWithSalFrame: this];
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir     @catch ( id exception )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         return;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     if( (mnStyle & SAL_FRAME_STYLE_TOOLTIP) )
206bde8a4bdSHerbert Dürr         [mpNSWindow setIgnoresMouseEvents: YES];
207cdf0e10cSrcweir     else
208bde8a4bdSHerbert Dürr         [mpNSWindow setAcceptsMouseMovedEvents: YES];
209bde8a4bdSHerbert Dürr     [mpNSWindow setHasShadow: YES];
2102dae3561SHerbert Dürr     [mpNSWindow setDelegate: static_cast<id<NSWindowDelegate> >(mpNSWindow)];
211cdf0e10cSrcweir 
212*01367266SHerbert Dürr     const NSRect aRect = { NSZeroPoint, NSMakeSize( maGeometry.nWidth, maGeometry.nHeight )};
213bde8a4bdSHerbert Dürr     mnTrackingRectTag = [mpNSView addTrackingRect: aRect owner: mpNSView userData: nil assumeInside: NO];
214cdf0e10cSrcweir 
215bde8a4bdSHerbert Dürr     maSysData.mpNSView = mpNSView;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     UpdateFrameGeometry();
218cdf0e10cSrcweir 
219bde8a4bdSHerbert Dürr     [mpNSWindow setContentView: mpNSView];
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir // -----------------------------------------------------------------------
223cdf0e10cSrcweir 
CocoaToVCL(NSRect & io_rRect,bool bRelativeToScreen)224cdf0e10cSrcweir void AquaSalFrame::CocoaToVCL( NSRect& io_rRect, bool bRelativeToScreen )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     if( bRelativeToScreen )
227cdf0e10cSrcweir         io_rRect.origin.y = maScreenRect.size.height - (io_rRect.origin.y+io_rRect.size.height);
228cdf0e10cSrcweir     else
229cdf0e10cSrcweir         io_rRect.origin.y = maGeometry.nHeight - (io_rRect.origin.y+io_rRect.size.height);
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
VCLToCocoa(NSRect & io_rRect,bool bRelativeToScreen)232cdf0e10cSrcweir void AquaSalFrame::VCLToCocoa( NSRect& io_rRect, bool bRelativeToScreen )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     if( bRelativeToScreen )
235cdf0e10cSrcweir         io_rRect.origin.y = maScreenRect.size.height - (io_rRect.origin.y+io_rRect.size.height);
236cdf0e10cSrcweir     else
237cdf0e10cSrcweir         io_rRect.origin.y = maGeometry.nHeight - (io_rRect.origin.y+io_rRect.size.height);
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
CocoaToVCL(NSPoint & io_rPoint,bool bRelativeToScreen)240cdf0e10cSrcweir void AquaSalFrame::CocoaToVCL( NSPoint& io_rPoint, bool bRelativeToScreen )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir     if( bRelativeToScreen )
243cdf0e10cSrcweir         io_rPoint.y = maScreenRect.size.height - io_rPoint.y;
244cdf0e10cSrcweir     else
245cdf0e10cSrcweir         io_rPoint.y = maGeometry.nHeight - io_rPoint.y;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
VCLToCocoa(NSPoint & io_rPoint,bool bRelativeToScreen)248cdf0e10cSrcweir void AquaSalFrame::VCLToCocoa( NSPoint& io_rPoint, bool bRelativeToScreen )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     if( bRelativeToScreen )
251cdf0e10cSrcweir         io_rPoint.y = maScreenRect.size.height - io_rPoint.y;
252cdf0e10cSrcweir     else
253cdf0e10cSrcweir         io_rPoint.y = maGeometry.nHeight - io_rPoint.y;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir // -----------------------------------------------------------------------
257cdf0e10cSrcweir 
screenParametersChanged()258cdf0e10cSrcweir void AquaSalFrame::screenParametersChanged()
259cdf0e10cSrcweir {
260cdf0e10cSrcweir     UpdateFrameGeometry();
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     if( mpGraphics )
263cdf0e10cSrcweir         mpGraphics->updateResolution();
264cdf0e10cSrcweir     CallCallback( SALEVENT_DISPLAYCHANGED, 0 );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir // -----------------------------------------------------------------------
268cdf0e10cSrcweir 
GetGraphics()269cdf0e10cSrcweir SalGraphics* AquaSalFrame::GetGraphics()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	if ( mbGraphics )
272cdf0e10cSrcweir 		return NULL;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	if ( !mpGraphics )
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir         mpGraphics = new AquaSalGraphics;
277cdf0e10cSrcweir         mpGraphics->SetWindowGraphics( this );
278cdf0e10cSrcweir 	}
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     mbGraphics = TRUE;
281cdf0e10cSrcweir 	return mpGraphics;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir // -----------------------------------------------------------------------
285cdf0e10cSrcweir 
ReleaseGraphics(SalGraphics * pGraphics)286cdf0e10cSrcweir void AquaSalFrame::ReleaseGraphics( SalGraphics *pGraphics )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir     (void)pGraphics;
289cdf0e10cSrcweir     DBG_ASSERT( pGraphics == mpGraphics, "graphics released on wrong frame" );
290cdf0e10cSrcweir 	mbGraphics = FALSE;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir // -----------------------------------------------------------------------
294cdf0e10cSrcweir 
PostEvent(void * pData)295cdf0e10cSrcweir sal_Bool AquaSalFrame::PostEvent( void *pData )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir     GetSalData()->mpFirstInstance->PostUserEvent( this, SALEVENT_USEREVENT, pData );
298cdf0e10cSrcweir     return TRUE;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir // -----------------------------------------------------------------------
SetTitle(const XubString & rTitle)302cdf0e10cSrcweir void AquaSalFrame::SetTitle(const XubString& rTitle)
303cdf0e10cSrcweir {
304bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
305cdf0e10cSrcweir         return;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
308cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     NSString* pTitle = CreateNSString( rTitle );
311bde8a4bdSHerbert Dürr     [mpNSWindow setTitle: pTitle];
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     // create an entry in the dock menu
314cdf0e10cSrcweir     const sal_uLong nAppWindowStyle = (SAL_FRAME_STYLE_CLOSEABLE | SAL_FRAME_STYLE_MOVEABLE);
315cdf0e10cSrcweir     if( mpParent == NULL &&
316cdf0e10cSrcweir         (mnStyle & nAppWindowStyle) == nAppWindowStyle )
317cdf0e10cSrcweir     {
318cdf0e10cSrcweir         if( mpDockMenuEntry == NULL )
319cdf0e10cSrcweir         {
320cdf0e10cSrcweir             NSMenu* pDock = AquaSalInstance::GetDynamicDockMenu();
321cdf0e10cSrcweir             mpDockMenuEntry = [pDock insertItemWithTitle: pTitle
322cdf0e10cSrcweir                                      action: @selector(dockMenuItemTriggered:)
323cdf0e10cSrcweir                                      keyEquivalent: @""
324cdf0e10cSrcweir                                      atIndex: 0];
325bde8a4bdSHerbert Dürr             [mpDockMenuEntry setTarget: mpNSWindow];
326cdf0e10cSrcweir 
327cdf0e10cSrcweir             // TODO: image (either the generic window image or an icon
328cdf0e10cSrcweir             // check mark (for "main" window ?)
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir         else
331cdf0e10cSrcweir             [mpDockMenuEntry setTitle: pTitle];
332cdf0e10cSrcweir     }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     if (pTitle)
335cdf0e10cSrcweir         [pTitle release];
336cdf0e10cSrcweir }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir // -----------------------------------------------------------------------
339cdf0e10cSrcweir 
SetIcon(sal_uInt16)340cdf0e10cSrcweir void AquaSalFrame::SetIcon( sal_uInt16 )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir // -----------------------------------------------------------------------
345cdf0e10cSrcweir 
SetRepresentedURL(const rtl::OUString & i_rDocURL)346cdf0e10cSrcweir void AquaSalFrame::SetRepresentedURL( const rtl::OUString& i_rDocURL )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
349cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     if( i_rDocURL.indexOfAsciiL( "file:", 5 ) == 0 )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         rtl::OUString aSysPath;
354cdf0e10cSrcweir         osl_getSystemPathFromFileURL( i_rDocURL.pData, &aSysPath.pData );
355cdf0e10cSrcweir         NSString* pStr = CreateNSString( aSysPath );
356cdf0e10cSrcweir         if( pStr )
357cdf0e10cSrcweir         {
358cdf0e10cSrcweir             [pStr autorelease];
359bde8a4bdSHerbert Dürr             [mpNSWindow setRepresentedFilename: pStr];
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir // -----------------------------------------------------------------------
365cdf0e10cSrcweir 
initShow()366cdf0e10cSrcweir void AquaSalFrame::initShow()
367cdf0e10cSrcweir {
368cdf0e10cSrcweir     mbInitShow = false;
369cdf0e10cSrcweir     if( ! mbPositioned && ! mbFullScreen )
370cdf0e10cSrcweir     {
371cdf0e10cSrcweir         Rectangle aScreenRect;
372cdf0e10cSrcweir         GetWorkArea( aScreenRect );
373cdf0e10cSrcweir         if( mpParent ) // center relative to parent
374cdf0e10cSrcweir         {
375cdf0e10cSrcweir             // center on parent
376cdf0e10cSrcweir             long nNewX = mpParent->maGeometry.nX + ((long)mpParent->maGeometry.nWidth - (long)maGeometry.nWidth)/2;
377cdf0e10cSrcweir             if( nNewX < aScreenRect.Left() )
378cdf0e10cSrcweir                 nNewX = aScreenRect.Left();
379cdf0e10cSrcweir             if( long(nNewX + maGeometry.nWidth) > aScreenRect.Right() )
380cdf0e10cSrcweir                 nNewX = aScreenRect.Right() - maGeometry.nWidth-1;
381cdf0e10cSrcweir             long nNewY = mpParent->maGeometry.nY + ((long)mpParent->maGeometry.nHeight - (long)maGeometry.nHeight)/2;
382cdf0e10cSrcweir             if( nNewY < aScreenRect.Top() )
383cdf0e10cSrcweir                 nNewY = aScreenRect.Top();
384cdf0e10cSrcweir             if( nNewY > aScreenRect.Bottom() )
385cdf0e10cSrcweir                 nNewY = aScreenRect.Bottom() - maGeometry.nHeight-1;
386cdf0e10cSrcweir             SetPosSize( nNewX - mpParent->maGeometry.nX,
387cdf0e10cSrcweir                         nNewY - mpParent->maGeometry.nY,
388cdf0e10cSrcweir                         0, 0,  SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
389cdf0e10cSrcweir         }
390cdf0e10cSrcweir         else if( ! (mnStyle & SAL_FRAME_STYLE_SIZEABLE) )
391cdf0e10cSrcweir         {
392cdf0e10cSrcweir             // center on screen
393cdf0e10cSrcweir             long nNewX = (aScreenRect.GetWidth() - maGeometry.nWidth)/2;
394cdf0e10cSrcweir             long nNewY = (aScreenRect.GetHeight() - maGeometry.nHeight)/2;
395cdf0e10cSrcweir             SetPosSize( nNewX, nNewY, 0, 0,  SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y );
396cdf0e10cSrcweir         }
397cdf0e10cSrcweir     }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     // make sure the view is present in the wrapper list before any children receive focus
400bde8a4bdSHerbert Dürr     [AquaA11yFactory registerView: mpNSView];
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
SendPaintEvent(const Rectangle * pRect)403cdf0e10cSrcweir void AquaSalFrame::SendPaintEvent( const Rectangle* pRect )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     SalPaintEvent aPaintEvt( 0, 0, maGeometry.nWidth, maGeometry.nHeight, true );
406cdf0e10cSrcweir     if( pRect )
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         aPaintEvt.mnBoundX      = pRect->Left();
409cdf0e10cSrcweir         aPaintEvt.mnBoundY      = pRect->Top();
410cdf0e10cSrcweir         aPaintEvt.mnBoundWidth  = pRect->GetWidth();
411cdf0e10cSrcweir         aPaintEvt.mnBoundHeight = pRect->GetHeight();
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     CallCallback(SALEVENT_PAINT, &aPaintEvt);
415cdf0e10cSrcweir }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir // -----------------------------------------------------------------------
418cdf0e10cSrcweir 
Show(sal_Bool bVisible,sal_Bool bNoActivate)419cdf0e10cSrcweir void AquaSalFrame::Show(sal_Bool bVisible, sal_Bool bNoActivate)
420cdf0e10cSrcweir {
421bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
422cdf0e10cSrcweir         return;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
425cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     mbShown = bVisible;
428cdf0e10cSrcweir     if(bVisible)
429cdf0e10cSrcweir     {
430cdf0e10cSrcweir         if( mbInitShow )
431cdf0e10cSrcweir             initShow();
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         CallCallback(SALEVENT_RESIZE, 0);
434cdf0e10cSrcweir         // trigger filling our backbuffer
435cdf0e10cSrcweir         SendPaintEvent();
436cdf0e10cSrcweir 
437bde8a4bdSHerbert Dürr         if( bNoActivate || [mpNSWindow canBecomeKeyWindow] == NO )
438bde8a4bdSHerbert Dürr             [mpNSWindow orderFront: NSApp];
439cdf0e10cSrcweir         else
440bde8a4bdSHerbert Dürr             [mpNSWindow makeKeyAndOrderFront: NSApp];
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         if( mpParent )
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir             /* #i92674# #i96433# we do not want an invisible parent to show up (which adding a visible
445cdf0e10cSrcweir                child implicitly does). However we also do not want a parentless toolbar.
446cdf0e10cSrcweir 
447cdf0e10cSrcweir                HACK: try to decide when we should not insert a child to its parent
448cdf0e10cSrcweir                floaters and ownerdraw windows have not yet shown up in cases where
449cdf0e10cSrcweir                we don't want the parent to become visible
450cdf0e10cSrcweir             */
451cdf0e10cSrcweir             if( mpParent->mbShown || (mnStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT) ) )
452cdf0e10cSrcweir             {
453bde8a4bdSHerbert Dürr                 [mpParent->mpNSWindow addChildWindow: mpNSWindow ordered: NSWindowAbove];
454cdf0e10cSrcweir             }
455cdf0e10cSrcweir         }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir         if( mbPresentation )
458bde8a4bdSHerbert Dürr             [mpNSWindow makeMainWindow];
459cdf0e10cSrcweir     }
460cdf0e10cSrcweir     else
461cdf0e10cSrcweir     {
462cdf0e10cSrcweir         // if the frame holding the current menubar gets hidden
463cdf0e10cSrcweir         // show the default menubar
464cdf0e10cSrcweir         if( mpMenu && mpMenu->mbMenuBar && AquaSalMenu::pCurrentMenuBar == mpMenu )
465cdf0e10cSrcweir             AquaSalMenu::setDefaultMenu();
466cdf0e10cSrcweir 
467cdf0e10cSrcweir         // #i90440# #i94443# work around the focus going back to some other window
468cdf0e10cSrcweir         // if a child gets hidden for a parent window
469bde8a4bdSHerbert Dürr         if( mpParent && mpParent->mbShown && [mpNSWindow isKeyWindow] )
470bde8a4bdSHerbert Dürr             [mpParent->mpNSWindow makeKeyAndOrderFront: NSApp];
471cdf0e10cSrcweir 
472cdf0e10cSrcweir         [SalFrameView unsetMouseFrame: this];
473bde8a4bdSHerbert Dürr         if( mpParent && [mpNSWindow parentWindow] == mpParent->mpNSWindow )
474bde8a4bdSHerbert Dürr             [mpParent->mpNSWindow removeChildWindow: mpNSWindow];
475cdf0e10cSrcweir 
476bde8a4bdSHerbert Dürr         [mpNSWindow orderOut: NSApp];
477cdf0e10cSrcweir     }
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir // -----------------------------------------------------------------------
481cdf0e10cSrcweir 
Enable(sal_Bool)482cdf0e10cSrcweir void AquaSalFrame::Enable( sal_Bool )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir // -----------------------------------------------------------------------
487cdf0e10cSrcweir 
SetMinClientSize(long nWidth,long nHeight)488cdf0e10cSrcweir void AquaSalFrame::SetMinClientSize( long nWidth, long nHeight )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
491cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     mnMinWidth = nWidth;
494cdf0e10cSrcweir     mnMinHeight = nHeight;
495cdf0e10cSrcweir 
496bde8a4bdSHerbert Dürr     if( mpNSWindow )
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         // Always add the decoration as the dimension concerns only
499cdf0e10cSrcweir         // the content rectangle
500cdf0e10cSrcweir         nWidth += maGeometry.nLeftDecoration + maGeometry.nRightDecoration;
501cdf0e10cSrcweir         nHeight += maGeometry.nTopDecoration + maGeometry.nBottomDecoration;
502cdf0e10cSrcweir 
503cd426cceSHerbert Dürr         const NSSize aSize = NSMakeSize( nWidth, nHeight);
504cdf0e10cSrcweir 
505cdf0e10cSrcweir         // Size of full window (content+structure) although we only
506cdf0e10cSrcweir         // have the client size in arguments
507bde8a4bdSHerbert Dürr         [mpNSWindow setMinSize: aSize];
508cdf0e10cSrcweir     }
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir // -----------------------------------------------------------------------
512cdf0e10cSrcweir 
SetMaxClientSize(long nWidth,long nHeight)513cdf0e10cSrcweir void AquaSalFrame::SetMaxClientSize( long nWidth, long nHeight )
514cdf0e10cSrcweir {
515cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
516cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
517cdf0e10cSrcweir 
518cdf0e10cSrcweir     mnMaxWidth = nWidth;
519cdf0e10cSrcweir     mnMaxHeight = nHeight;
520cdf0e10cSrcweir 
521bde8a4bdSHerbert Dürr     if( mpNSWindow )
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         // Always add the decoration as the dimension concerns only
524cdf0e10cSrcweir         // the content rectangle
525cdf0e10cSrcweir         nWidth += maGeometry.nLeftDecoration + maGeometry.nRightDecoration;
526cdf0e10cSrcweir         nHeight += maGeometry.nTopDecoration + maGeometry.nBottomDecoration;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         // Carbon windows can't have a size greater than 32767x32767
529cdf0e10cSrcweir         if (nWidth>32767) nWidth=32767;
530cdf0e10cSrcweir         if (nHeight>32767) nHeight=32767;
531cdf0e10cSrcweir 
532cd426cceSHerbert Dürr         const NSSize aSize = NSMakeSize( nWidth, nHeight);
533cdf0e10cSrcweir 
534cdf0e10cSrcweir         // Size of full window (content+structure) although we only
535cdf0e10cSrcweir         // have the client size in arguments
536bde8a4bdSHerbert Dürr         [mpNSWindow setMaxSize: aSize];
537cdf0e10cSrcweir     }
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir // -----------------------------------------------------------------------
541cdf0e10cSrcweir 
SetClientSize(long nWidth,long nHeight)542cdf0e10cSrcweir void AquaSalFrame::SetClientSize( long nWidth, long nHeight )
543cdf0e10cSrcweir {
544cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
545cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
546cdf0e10cSrcweir 
547bde8a4bdSHerbert Dürr     if( mpNSWindow )
548cdf0e10cSrcweir     {
549cd426cceSHerbert Dürr         const NSSize aSize = NSMakeSize( nWidth, nHeight);
550cdf0e10cSrcweir 
551bde8a4bdSHerbert Dürr         [mpNSWindow setContentSize: aSize];
552cdf0e10cSrcweir         UpdateFrameGeometry();
553cdf0e10cSrcweir         if( mbShown )
554cdf0e10cSrcweir             // trigger filling our backbuffer
555cdf0e10cSrcweir             SendPaintEvent();
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir // -----------------------------------------------------------------------
560cdf0e10cSrcweir 
GetClientSize(long & rWidth,long & rHeight)561cdf0e10cSrcweir void AquaSalFrame::GetClientSize( long& rWidth, long& rHeight )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     if( mbShown || mbInitShow )
564cdf0e10cSrcweir     {
565cdf0e10cSrcweir         rWidth  = maGeometry.nWidth;
566cdf0e10cSrcweir         rHeight = maGeometry.nHeight;
567cdf0e10cSrcweir     }
568cdf0e10cSrcweir     else
569cdf0e10cSrcweir     {
570cdf0e10cSrcweir         rWidth  = 0;
571cdf0e10cSrcweir         rHeight = 0;
572cdf0e10cSrcweir     }
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir // -----------------------------------------------------------------------
576cdf0e10cSrcweir 
SetWindowState(const SalFrameState * pState)577cdf0e10cSrcweir void AquaSalFrame::SetWindowState( const SalFrameState* pState )
578cdf0e10cSrcweir {
579cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
580cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
581cdf0e10cSrcweir 
582bde8a4bdSHerbert Dürr     if ( mpNSWindow )
583cdf0e10cSrcweir     {
584cdf0e10cSrcweir     // set normal state
585bde8a4bdSHerbert Dürr     NSRect aStateRect = [mpNSWindow frame];
586cdf0e10cSrcweir     aStateRect = [NSWindow contentRectForFrameRect: aStateRect styleMask: mnStyleMask];
587cdf0e10cSrcweir     CocoaToVCL( aStateRect );
588cdf0e10cSrcweir     if( pState->mnMask & SAL_FRAMESTATE_MASK_X )
589cdf0e10cSrcweir         aStateRect.origin.x = float(pState->mnX);
590cdf0e10cSrcweir     if( pState->mnMask & SAL_FRAMESTATE_MASK_Y )
591cdf0e10cSrcweir         aStateRect.origin.y = float(pState->mnY);
592cdf0e10cSrcweir     if( pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH )
593cdf0e10cSrcweir         aStateRect.size.width = float(pState->mnWidth);
594cdf0e10cSrcweir     if( pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT )
595cdf0e10cSrcweir         aStateRect.size.height = float(pState->mnHeight);
596cdf0e10cSrcweir     VCLToCocoa( aStateRect );
597cdf0e10cSrcweir     aStateRect = [NSWindow frameRectForContentRect: aStateRect styleMask: mnStyleMask];
598cdf0e10cSrcweir 
599bde8a4bdSHerbert Dürr     [mpNSWindow setFrame: aStateRect display: NO];
600cdf0e10cSrcweir     if( pState->mnState == SAL_FRAMESTATE_MINIMIZED )
601bde8a4bdSHerbert Dürr         [mpNSWindow miniaturize: NSApp];
602bde8a4bdSHerbert Dürr     else if( [mpNSWindow isMiniaturized] )
603bde8a4bdSHerbert Dürr         [mpNSWindow deminiaturize: NSApp];
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 
606cdf0e10cSrcweir     /* ZOOMED is not really maximized (actually it toggles between a user set size and
607cdf0e10cSrcweir        the program specified one), but comes closest since the default behavior is
608cdf0e10cSrcweir        "maximized" if the user did not intervene
609cdf0e10cSrcweir     */
610cdf0e10cSrcweir     if( pState->mnState == SAL_FRAMESTATE_MAXIMIZED )
611cdf0e10cSrcweir     {
612bde8a4bdSHerbert Dürr         if(! [mpNSWindow isZoomed])
613bde8a4bdSHerbert Dürr             [mpNSWindow zoom: NSApp];
614cdf0e10cSrcweir     }
615cdf0e10cSrcweir     else
616cdf0e10cSrcweir     {
617bde8a4bdSHerbert Dürr         if( [mpNSWindow isZoomed] )
618bde8a4bdSHerbert Dürr             [mpNSWindow zoom: NSApp];
619cdf0e10cSrcweir     }
620cdf0e10cSrcweir     }
621cdf0e10cSrcweir 
622cdf0e10cSrcweir     // get new geometry
623cdf0e10cSrcweir     UpdateFrameGeometry();
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     sal_uInt16 nEvent = 0;
626cdf0e10cSrcweir     if( pState->mnMask & (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_X) )
627cdf0e10cSrcweir     {
628cdf0e10cSrcweir         mbPositioned = true;
629cdf0e10cSrcweir         nEvent = SALEVENT_MOVE;
630cdf0e10cSrcweir     }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir     if( pState->mnMask & (SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT) )
633cdf0e10cSrcweir     {
634cdf0e10cSrcweir         mbSized = true;
635cdf0e10cSrcweir         nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE;
636cdf0e10cSrcweir     }
637cdf0e10cSrcweir     // send event that we were moved/sized
638cdf0e10cSrcweir     if( nEvent )
639cdf0e10cSrcweir         CallCallback( nEvent, NULL );
640cdf0e10cSrcweir 
641bde8a4bdSHerbert Dürr     if( mbShown && mpNSWindow )
642cdf0e10cSrcweir     {
643cdf0e10cSrcweir         // trigger filling our backbuffer
644cdf0e10cSrcweir         SendPaintEvent();
645cdf0e10cSrcweir 
646cdf0e10cSrcweir         // tell the system the views need to be updated
647bde8a4bdSHerbert Dürr         [mpNSWindow display];
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // -----------------------------------------------------------------------
652cdf0e10cSrcweir 
GetWindowState(SalFrameState * pState)653cdf0e10cSrcweir sal_Bool AquaSalFrame::GetWindowState( SalFrameState* pState )
654cdf0e10cSrcweir {
655bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
656cdf0e10cSrcweir         return FALSE;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
659cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
660cdf0e10cSrcweir 
661cdf0e10cSrcweir     pState->mnMask = SAL_FRAMESTATE_MASK_X                 |
662cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_Y                 |
663cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_WIDTH             |
664cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_HEIGHT            |
665cdf0e10cSrcweir                      #if 0
666cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_MAXIMIZED_X       |
667cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_MAXIMIZED_Y       |
668cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_MAXIMIZED_WIDTH   |
669cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_MAXIMIZED_HEIGHT  |
670cdf0e10cSrcweir                      #endif
671cdf0e10cSrcweir                      SAL_FRAMESTATE_MASK_STATE;
672cdf0e10cSrcweir 
673bde8a4bdSHerbert Dürr     NSRect aStateRect = [mpNSWindow frame];
674cdf0e10cSrcweir     aStateRect = [NSWindow contentRectForFrameRect: aStateRect styleMask: mnStyleMask];
675cdf0e10cSrcweir     CocoaToVCL( aStateRect );
676cdf0e10cSrcweir     pState->mnX         = long(aStateRect.origin.x);
677cdf0e10cSrcweir     pState->mnY         = long(aStateRect.origin.y);
678cdf0e10cSrcweir     pState->mnWidth     = long(aStateRect.size.width);
679cdf0e10cSrcweir     pState->mnHeight    = long(aStateRect.size.height);
680cdf0e10cSrcweir 
681bde8a4bdSHerbert Dürr     if( [mpNSWindow isMiniaturized] )
682cdf0e10cSrcweir         pState->mnState = SAL_FRAMESTATE_MINIMIZED;
683bde8a4bdSHerbert Dürr     else if( ! [mpNSWindow isZoomed] )
684cdf0e10cSrcweir         pState->mnState = SAL_FRAMESTATE_NORMAL;
685cdf0e10cSrcweir     else
686cdf0e10cSrcweir         pState->mnState = SAL_FRAMESTATE_MAXIMIZED;
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 	return TRUE;
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir // -----------------------------------------------------------------------
692cdf0e10cSrcweir 
SetScreenNumber(unsigned int nScreen)693cdf0e10cSrcweir void AquaSalFrame::SetScreenNumber(unsigned int nScreen)
694cdf0e10cSrcweir {
695bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
696cdf0e10cSrcweir         return;
697cdf0e10cSrcweir 
698cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
699cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
700cdf0e10cSrcweir 
701cdf0e10cSrcweir     NSArray* pScreens = [NSScreen screens];
702cdf0e10cSrcweir     Rectangle aRet;
703cdf0e10cSrcweir     NSScreen* pScreen = nil;
704cdf0e10cSrcweir     if( pScreens && nScreen < [pScreens count] )
705cdf0e10cSrcweir     {
706cdf0e10cSrcweir         // get new screen frame
707cdf0e10cSrcweir         pScreen = [pScreens objectAtIndex: nScreen];
708cdf0e10cSrcweir         NSRect aNewScreen = [pScreen frame];
709cdf0e10cSrcweir 
710cdf0e10cSrcweir         // get current screen frame
711bde8a4bdSHerbert Dürr         pScreen = [mpNSWindow screen];
712cdf0e10cSrcweir         if( pScreen )
713cdf0e10cSrcweir         {
714cdf0e10cSrcweir             NSRect aCurScreen = [pScreen frame];
715cdf0e10cSrcweir             if( aCurScreen.origin.x != aNewScreen.origin.x ||
716cdf0e10cSrcweir                 aCurScreen.origin.y != aNewScreen.origin.y )
717cdf0e10cSrcweir             {
718bde8a4bdSHerbert Dürr                 NSRect aFrameRect = [mpNSWindow frame];
719cdf0e10cSrcweir                 aFrameRect.origin.x += aNewScreen.origin.x - aCurScreen.origin.x;
720cdf0e10cSrcweir                 aFrameRect.origin.y += aNewScreen.origin.y - aCurScreen.origin.y;
721bde8a4bdSHerbert Dürr                 [mpNSWindow setFrame: aFrameRect display: NO];
722cdf0e10cSrcweir                 UpdateFrameGeometry();
723cdf0e10cSrcweir             }
724cdf0e10cSrcweir         }
725cdf0e10cSrcweir     }
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir // -----------------------------------------------------------------------
729cdf0e10cSrcweir 
ShowFullScreen(sal_Bool bFullScreen,sal_Int32 nDisplay)730cdf0e10cSrcweir void AquaSalFrame::ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nDisplay )
731cdf0e10cSrcweir {
732bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
733cdf0e10cSrcweir         return;
734cdf0e10cSrcweir 
735cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
736cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 	if( mbFullScreen == bFullScreen )
739cdf0e10cSrcweir 		return;
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 	mbFullScreen = bFullScreen;
742cdf0e10cSrcweir 	if( bFullScreen )
743cdf0e10cSrcweir 	{
744cdf0e10cSrcweir 	    // hide the dock and the menubar if we are on the menu screen
745cdf0e10cSrcweir         // which is always on index 0 according to documentation
746cdf0e10cSrcweir         bool bHideMenu = (nDisplay == 0);
747cdf0e10cSrcweir 
748*01367266SHerbert Dürr         NSRect aNewContentRect = NSZeroRect;
749cdf0e10cSrcweir         // get correct screen
750cdf0e10cSrcweir         NSScreen* pScreen = nil;
751cdf0e10cSrcweir         NSArray* pScreens = [NSScreen screens];
752cdf0e10cSrcweir         if( pScreens )
753cdf0e10cSrcweir         {
754cdf0e10cSrcweir             if( nDisplay >= 0 && (unsigned int)nDisplay < [pScreens count] )
755cdf0e10cSrcweir                 pScreen = [pScreens objectAtIndex: nDisplay];
756cdf0e10cSrcweir             else
757cdf0e10cSrcweir             {
758cdf0e10cSrcweir                 // this means span all screens
759cdf0e10cSrcweir                 bHideMenu = true;
760cdf0e10cSrcweir                 NSEnumerator* pEnum = [pScreens objectEnumerator];
761cdf0e10cSrcweir                 while( (pScreen = [pEnum nextObject]) != nil )
762cdf0e10cSrcweir                 {
763cdf0e10cSrcweir                     NSRect aScreenRect = [pScreen frame];
764cdf0e10cSrcweir                     if( aScreenRect.origin.x < aNewContentRect.origin.x )
765cdf0e10cSrcweir                     {
766cdf0e10cSrcweir                         aNewContentRect.size.width += aNewContentRect.origin.x - aScreenRect.origin.x;
767cdf0e10cSrcweir                         aNewContentRect.origin.x = aScreenRect.origin.x;
768cdf0e10cSrcweir                     }
769cdf0e10cSrcweir                     if( aScreenRect.origin.y < aNewContentRect.origin.y )
770cdf0e10cSrcweir                     {
771cdf0e10cSrcweir                         aNewContentRect.size.height += aNewContentRect.origin.y - aScreenRect.origin.y;
772cdf0e10cSrcweir                         aNewContentRect.origin.y = aScreenRect.origin.y;
773cdf0e10cSrcweir                     }
774cdf0e10cSrcweir                     if( aScreenRect.origin.x + aScreenRect.size.width > aNewContentRect.origin.x + aNewContentRect.size.width )
775cdf0e10cSrcweir                         aNewContentRect.size.width = aScreenRect.origin.x + aScreenRect.size.width - aNewContentRect.origin.x;
776cdf0e10cSrcweir                     if( aScreenRect.origin.y + aScreenRect.size.height > aNewContentRect.origin.y + aNewContentRect.size.height )
777cdf0e10cSrcweir                         aNewContentRect.size.height = aScreenRect.origin.y + aScreenRect.size.height - aNewContentRect.origin.y;
778cdf0e10cSrcweir                 }
779cdf0e10cSrcweir             }
780cdf0e10cSrcweir         }
781cdf0e10cSrcweir         if( aNewContentRect.size.width == 0 && aNewContentRect.size.height == 0 )
782cdf0e10cSrcweir         {
783cdf0e10cSrcweir             if( pScreen == nil )
784bde8a4bdSHerbert Dürr                 pScreen = [mpNSWindow screen];
785cdf0e10cSrcweir             if( pScreen == nil )
786cdf0e10cSrcweir                 pScreen = [NSScreen mainScreen];
787cdf0e10cSrcweir 
788cdf0e10cSrcweir             aNewContentRect = [pScreen frame];
789cdf0e10cSrcweir         }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir         if( bHideMenu )
792cdf0e10cSrcweir             [NSMenu setMenuBarVisible:NO];
793cdf0e10cSrcweir 
794bde8a4bdSHerbert Dürr 	    maFullScreenRect = [mpNSWindow frame];
795cdf0e10cSrcweir         {
796bde8a4bdSHerbert Dürr             [mpNSWindow setFrame: [NSWindow frameRectForContentRect: aNewContentRect styleMask: mnStyleMask] display: mbShown ? YES : NO];
797cdf0e10cSrcweir         }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 	    UpdateFrameGeometry();
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 	    if( mbShown )
802cdf0e10cSrcweir             CallCallback( SALEVENT_MOVERESIZE, NULL );
803cdf0e10cSrcweir 	}
804cdf0e10cSrcweir 	else
805cdf0e10cSrcweir 	{
806cdf0e10cSrcweir         {
807bde8a4bdSHerbert Dürr             [mpNSWindow setFrame: maFullScreenRect display: mbShown ? YES : NO];
808cdf0e10cSrcweir         }
809cdf0e10cSrcweir 	    UpdateFrameGeometry();
810cdf0e10cSrcweir 
811cdf0e10cSrcweir 	    if( mbShown )
812cdf0e10cSrcweir             CallCallback( SALEVENT_MOVERESIZE, NULL );
813cdf0e10cSrcweir 
814cdf0e10cSrcweir 	    // show the dock and the menubar
815cdf0e10cSrcweir 	    [NSMenu setMenuBarVisible:YES];
816cdf0e10cSrcweir 	}
817cdf0e10cSrcweir     if( mbShown )
818cdf0e10cSrcweir         // trigger filling our backbuffer
819cdf0e10cSrcweir         SendPaintEvent();
820cdf0e10cSrcweir }
821cdf0e10cSrcweir 
822cdf0e10cSrcweir // -----------------------------------------------------------------------
823cdf0e10cSrcweir 
824cdf0e10cSrcweir class PreventSleepTimer : public AutoTimer
825cdf0e10cSrcweir {
826cdf0e10cSrcweir public:
PreventSleepTimer()827cdf0e10cSrcweir     PreventSleepTimer()
828cdf0e10cSrcweir     {
829cdf0e10cSrcweir         SetTimeout( 30000 );
830cdf0e10cSrcweir         Start();
831cdf0e10cSrcweir     }
832cdf0e10cSrcweir 
~PreventSleepTimer()833cdf0e10cSrcweir     virtual ~PreventSleepTimer()
834cdf0e10cSrcweir     {
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir 
Timeout()837cdf0e10cSrcweir     virtual void Timeout()
838cdf0e10cSrcweir     {
839cdf0e10cSrcweir         UpdateSystemActivity(OverallAct);
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir };
842cdf0e10cSrcweir 
StartPresentation(sal_Bool bStart)843cdf0e10cSrcweir void AquaSalFrame::StartPresentation( sal_Bool bStart )
844cdf0e10cSrcweir {
845bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
846cdf0e10cSrcweir         return;
847cdf0e10cSrcweir 
848cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
849cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
850cdf0e10cSrcweir 
851cdf0e10cSrcweir     if( bStart )
852cdf0e10cSrcweir     {
853ff005604SEike Rathke         GetSalData()->maPresentationFrames.push_back( this );
854cdf0e10cSrcweir         mpActivityTimer.reset( new PreventSleepTimer() );
855bde8a4bdSHerbert Dürr         [mpNSWindow setLevel: NSPopUpMenuWindowLevel];
856cdf0e10cSrcweir         if( mbShown )
857bde8a4bdSHerbert Dürr             [mpNSWindow makeMainWindow];
858cdf0e10cSrcweir     }
859cdf0e10cSrcweir     else
860cdf0e10cSrcweir     {
861ff005604SEike Rathke         GetSalData()->maPresentationFrames.remove( this );
862cdf0e10cSrcweir         mpActivityTimer.reset();
863bde8a4bdSHerbert Dürr         [mpNSWindow setLevel: NSNormalWindowLevel];
864cdf0e10cSrcweir     }
865cdf0e10cSrcweir }
866cdf0e10cSrcweir 
867cdf0e10cSrcweir // -----------------------------------------------------------------------
868cdf0e10cSrcweir 
SetAlwaysOnTop(sal_Bool)869cdf0e10cSrcweir void AquaSalFrame::SetAlwaysOnTop( sal_Bool )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
873cdf0e10cSrcweir // -----------------------------------------------------------------------
874cdf0e10cSrcweir 
ToTop(sal_uInt16 nFlags)875cdf0e10cSrcweir void AquaSalFrame::ToTop(sal_uInt16 nFlags)
876cdf0e10cSrcweir {
877bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
878cdf0e10cSrcweir         return;
879cdf0e10cSrcweir 
880cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
881cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
882cdf0e10cSrcweir 
883cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
884cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
885cdf0e10cSrcweir 
886cdf0e10cSrcweir     if( ! (nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN) )
887cdf0e10cSrcweir     {
888bde8a4bdSHerbert Dürr         if( ! [mpNSWindow isVisible] || [mpNSWindow isMiniaturized] )
889cdf0e10cSrcweir             return;
890cdf0e10cSrcweir     }
891cdf0e10cSrcweir     if( nFlags & SAL_FRAME_TOTOP_GRABFOCUS )
892bde8a4bdSHerbert Dürr         [mpNSWindow makeKeyAndOrderFront: NSApp];
893cdf0e10cSrcweir     else
894bde8a4bdSHerbert Dürr         [mpNSWindow orderFront: NSApp];
895cdf0e10cSrcweir }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir // -----------------------------------------------------------------------
898cdf0e10cSrcweir 
getCurrentCursor() const899cdf0e10cSrcweir NSCursor* AquaSalFrame::getCurrentCursor() const
900cdf0e10cSrcweir {
901cdf0e10cSrcweir     NSCursor* pCursor = nil;
902cdf0e10cSrcweir     switch( mePointerStyle )
903cdf0e10cSrcweir     {
904cdf0e10cSrcweir     case POINTER_TEXT:      pCursor = [NSCursor IBeamCursor];           break;
905cdf0e10cSrcweir     case POINTER_CROSS:     pCursor = [NSCursor crosshairCursor];       break;
906cdf0e10cSrcweir     case POINTER_HAND:
907cdf0e10cSrcweir     case POINTER_MOVE:      pCursor = [NSCursor openHandCursor];        break;
908cdf0e10cSrcweir     case POINTER_NSIZE:     pCursor = [NSCursor resizeUpCursor];        break;
909cdf0e10cSrcweir     case POINTER_SSIZE:     pCursor = [NSCursor resizeDownCursor];      break;
910cdf0e10cSrcweir     case POINTER_ESIZE:     pCursor = [NSCursor resizeRightCursor];      break;
911cdf0e10cSrcweir     case POINTER_WSIZE:     pCursor = [NSCursor resizeLeftCursor];     break;
912cdf0e10cSrcweir     case POINTER_ARROW:     pCursor = [NSCursor arrowCursor];           break;
913cdf0e10cSrcweir     case POINTER_VSPLIT:
914cdf0e10cSrcweir     case POINTER_VSIZEBAR:
915cdf0e10cSrcweir     case POINTER_WINDOW_NSIZE:
916cdf0e10cSrcweir     case POINTER_WINDOW_SSIZE:
917cdf0e10cSrcweir                             pCursor = [NSCursor resizeUpDownCursor];    break;
918cdf0e10cSrcweir     case POINTER_HSPLIT:
919cdf0e10cSrcweir     case POINTER_HSIZEBAR:
920cdf0e10cSrcweir     case POINTER_WINDOW_ESIZE:
921cdf0e10cSrcweir     case POINTER_WINDOW_WSIZE:
922cdf0e10cSrcweir                             pCursor = [NSCursor resizeLeftRightCursor]; break;
923cdf0e10cSrcweir     case POINTER_REFHAND:   pCursor = [NSCursor pointingHandCursor];    break;
924cdf0e10cSrcweir 
925cdf0e10cSrcweir     default:
926cdf0e10cSrcweir         pCursor = GetSalData()->getCursor( mePointerStyle );
927cdf0e10cSrcweir         if( pCursor == nil )
928cdf0e10cSrcweir         {
929cdf0e10cSrcweir             DBG_ERROR( "unmapped cursor" );
930cdf0e10cSrcweir             pCursor = [NSCursor arrowCursor];
931cdf0e10cSrcweir         }
932cdf0e10cSrcweir         break;
933cdf0e10cSrcweir     }
934cdf0e10cSrcweir     return pCursor;
935cdf0e10cSrcweir }
936cdf0e10cSrcweir 
SetPointer(PointerStyle ePointerStyle)937cdf0e10cSrcweir void AquaSalFrame::SetPointer( PointerStyle ePointerStyle )
938cdf0e10cSrcweir {
939bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
940cdf0e10cSrcweir         return;
941cdf0e10cSrcweir 
942cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
943cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
944cdf0e10cSrcweir 
945cdf0e10cSrcweir     if( ePointerStyle >= POINTER_COUNT || ePointerStyle == mePointerStyle )
946cdf0e10cSrcweir         return;
947cdf0e10cSrcweir     mePointerStyle = ePointerStyle;
948cdf0e10cSrcweir 
949bde8a4bdSHerbert Dürr     [mpNSWindow invalidateCursorRectsForView: mpNSView];
950cdf0e10cSrcweir }
951cdf0e10cSrcweir 
952cdf0e10cSrcweir // -----------------------------------------------------------------------
953cdf0e10cSrcweir 
SetPointerPos(long nX,long nY)954cdf0e10cSrcweir void AquaSalFrame::SetPointerPos( long nX, long nY )
955cdf0e10cSrcweir {
956cdf0e10cSrcweir     // FIXME: use Cocoa functions
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     // FIXME: multiscreen support
959cd426cceSHerbert Dürr     const CGPoint aPoint = CGPointMake( nX + maGeometry.nX, nY + maGeometry.nY);
960cdf0e10cSrcweir     CGDirectDisplayID mainDisplayID = CGMainDisplayID();
961cdf0e10cSrcweir     CGDisplayMoveCursorToPoint( mainDisplayID, aPoint );
962cdf0e10cSrcweir }
963cdf0e10cSrcweir 
964cdf0e10cSrcweir // -----------------------------------------------------------------------
965cdf0e10cSrcweir 
Flush(void)966cdf0e10cSrcweir void AquaSalFrame::Flush( void )
967cdf0e10cSrcweir {
968bde8a4bdSHerbert Dürr     if( !(mbGraphics && mpGraphics && mpNSView && mbShown) )
969cdf0e10cSrcweir         return;
970cdf0e10cSrcweir 
971cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
972cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 
975bde8a4bdSHerbert Dürr     [mpNSView setNeedsDisplay: YES];
976cdf0e10cSrcweir 
977cdf0e10cSrcweir     // outside of the application's event loop (e.g. IntroWindow)
978cdf0e10cSrcweir     // nothing would trigger paint event handling
979cdf0e10cSrcweir     // => fall back to synchronous painting
980cdf0e10cSrcweir     if( ImplGetSVData()->maAppData.mnDispatchLevel <= 0 )
981cdf0e10cSrcweir     {
982bde8a4bdSHerbert Dürr         [mpNSView display];
983cdf0e10cSrcweir     }
984cdf0e10cSrcweir }
985cdf0e10cSrcweir 
986cdf0e10cSrcweir // -----------------------------------------------------------------------
987cdf0e10cSrcweir 
Flush(const Rectangle & rRect)988cdf0e10cSrcweir void AquaSalFrame::Flush( const Rectangle& rRect )
989cdf0e10cSrcweir {
990bde8a4bdSHerbert Dürr     if( !(mbGraphics && mpGraphics && mpNSView && mbShown) )
991cdf0e10cSrcweir         return;
992cdf0e10cSrcweir 
993cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
994cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
995cdf0e10cSrcweir 
996cd426cceSHerbert Dürr     NSRect aNSRect = NSMakeRect( rRect.Left(), rRect.Top(), rRect.GetWidth(), rRect.GetHeight());
997cdf0e10cSrcweir     VCLToCocoa( aNSRect, false );
998bde8a4bdSHerbert Dürr     [mpNSView setNeedsDisplayInRect: aNSRect];
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir     // outside of the application's event loop (e.g. IntroWindow)
1001cdf0e10cSrcweir     // nothing would trigger paint event handling
1002cdf0e10cSrcweir     // => fall back to synchronous painting
1003cdf0e10cSrcweir     if( ImplGetSVData()->maAppData.mnDispatchLevel <= 0 )
1004cdf0e10cSrcweir     {
1005bde8a4bdSHerbert Dürr         [mpNSView display];
1006cdf0e10cSrcweir     }
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir // -----------------------------------------------------------------------
1010cdf0e10cSrcweir 
Sync()1011cdf0e10cSrcweir void AquaSalFrame::Sync()
1012cdf0e10cSrcweir {
1013bde8a4bdSHerbert Dürr     if( mbGraphics && mpGraphics && mpNSView && mbShown )
1014cdf0e10cSrcweir     {
1015cdf0e10cSrcweir         // #i113170# may not be the main thread if called from UNO API
1016cdf0e10cSrcweir         SalData::ensureThreadAutoreleasePool();
1017cdf0e10cSrcweir 
1018bde8a4bdSHerbert Dürr         [mpNSView setNeedsDisplay: YES];
1019bde8a4bdSHerbert Dürr         [mpNSView display];
1020cdf0e10cSrcweir     }
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir // -----------------------------------------------------------------------
1024cdf0e10cSrcweir 
SetInputContext(SalInputContext * pContext)1025cdf0e10cSrcweir void AquaSalFrame::SetInputContext( SalInputContext* pContext )
1026cdf0e10cSrcweir {
1027cdf0e10cSrcweir     if (!pContext)
1028cdf0e10cSrcweir     {
1029cdf0e10cSrcweir         mnICOptions = 0;
1030cdf0e10cSrcweir         return;
1031cdf0e10cSrcweir     }
1032cdf0e10cSrcweir 
1033cdf0e10cSrcweir     mnICOptions = pContext->mnOptions;
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir     if(!(pContext->mnOptions & SAL_INPUTCONTEXT_TEXT))
1036cdf0e10cSrcweir         return;
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir // -----------------------------------------------------------------------
1040cdf0e10cSrcweir 
EndExtTextInput(sal_uInt16)1041cdf0e10cSrcweir void AquaSalFrame::EndExtTextInput( sal_uInt16 )
1042cdf0e10cSrcweir {
1043cdf0e10cSrcweir }
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir // -----------------------------------------------------------------------
1046cdf0e10cSrcweir 
GetKeyName(sal_uInt16 nKeyCode)1047cdf0e10cSrcweir XubString AquaSalFrame::GetKeyName( sal_uInt16 nKeyCode )
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir     static std::map< sal_uInt16, rtl::OUString > aKeyMap;
1050cdf0e10cSrcweir     if( aKeyMap.empty() )
1051cdf0e10cSrcweir     {
1052cdf0e10cSrcweir         sal_uInt16 i;
1053cdf0e10cSrcweir         for( i = KEY_A; i <= KEY_Z; i++ )
1054cdf0e10cSrcweir             aKeyMap[ i ] = rtl::OUString( sal_Unicode( 'A' + (i - KEY_A) ) );
1055cdf0e10cSrcweir         for( i = KEY_0; i <= KEY_9; i++ )
1056cdf0e10cSrcweir             aKeyMap[ i ] = rtl::OUString( sal_Unicode( '0' + (i - KEY_0) ) );
1057cdf0e10cSrcweir         for( i = KEY_F1; i <= KEY_F26; i++ )
1058cdf0e10cSrcweir         {
1059cdf0e10cSrcweir             rtl::OUStringBuffer aKey( 3 );
1060cdf0e10cSrcweir             aKey.append( sal_Unicode( 'F' ) );
1061cdf0e10cSrcweir             aKey.append( sal_Int32( i - KEY_F1 + 1 ) );
1062cdf0e10cSrcweir             aKeyMap[ i ] = aKey.makeStringAndClear();
1063cdf0e10cSrcweir         }
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir         aKeyMap[ KEY_DOWN ]     = rtl::OUString( sal_Unicode( 0x21e3 ) );
1066cdf0e10cSrcweir         aKeyMap[ KEY_UP ]       = rtl::OUString( sal_Unicode( 0x21e1 ) );
1067cdf0e10cSrcweir         aKeyMap[ KEY_LEFT ]     = rtl::OUString( sal_Unicode( 0x21e0 ) );
1068cdf0e10cSrcweir         aKeyMap[ KEY_RIGHT ]    = rtl::OUString( sal_Unicode( 0x21e2 ) );
1069cdf0e10cSrcweir         aKeyMap[ KEY_HOME ]     = rtl::OUString( sal_Unicode( 0x2196 ) );
1070cdf0e10cSrcweir         aKeyMap[ KEY_END ]      = rtl::OUString( sal_Unicode( 0x2198 ) );
1071cdf0e10cSrcweir         aKeyMap[ KEY_PAGEUP ]   = rtl::OUString( sal_Unicode( 0x21de ) );
1072cdf0e10cSrcweir         aKeyMap[ KEY_PAGEDOWN ] = rtl::OUString( sal_Unicode( 0x21df ) );
1073cdf0e10cSrcweir         aKeyMap[ KEY_RETURN ]   = rtl::OUString( sal_Unicode( 0x21a9 ) );
1074cdf0e10cSrcweir         aKeyMap[ KEY_ESCAPE ]   = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "esc" ) );
1075cdf0e10cSrcweir         aKeyMap[ KEY_TAB ]      = rtl::OUString( sal_Unicode( 0x21e5 ) );
1076cdf0e10cSrcweir         aKeyMap[ KEY_BACKSPACE ]= rtl::OUString( sal_Unicode( 0x232b ) );
1077cdf0e10cSrcweir         aKeyMap[ KEY_SPACE ]    = rtl::OUString( sal_Unicode( 0x2423 ) );
1078cdf0e10cSrcweir         aKeyMap[ KEY_DELETE ]   = rtl::OUString( sal_Unicode( 0x2326 ) );
1079cdf0e10cSrcweir         aKeyMap[ KEY_ADD ]      = rtl::OUString( sal_Unicode( '+' ) );
1080cdf0e10cSrcweir         aKeyMap[ KEY_SUBTRACT ] = rtl::OUString( sal_Unicode( '-' ) );
1081cdf0e10cSrcweir         aKeyMap[ KEY_DIVIDE ]   = rtl::OUString( sal_Unicode( '/' ) );
1082cdf0e10cSrcweir         aKeyMap[ KEY_MULTIPLY ] = rtl::OUString( sal_Unicode( '*' ) );
1083cdf0e10cSrcweir         aKeyMap[ KEY_POINT ]    = rtl::OUString( sal_Unicode( '.' ) );
1084cdf0e10cSrcweir         aKeyMap[ KEY_COMMA ]    = rtl::OUString( sal_Unicode( ',' ) );
1085cdf0e10cSrcweir         aKeyMap[ KEY_LESS ]     = rtl::OUString( sal_Unicode( '<' ) );
1086cdf0e10cSrcweir         aKeyMap[ KEY_GREATER ]  = rtl::OUString( sal_Unicode( '>' ) );
1087cdf0e10cSrcweir         aKeyMap[ KEY_EQUAL ]    = rtl::OUString( sal_Unicode( '=' ) );
1088cdf0e10cSrcweir         aKeyMap[ KEY_OPEN ]     = rtl::OUString( sal_Unicode( 0x23cf ) );
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir         /* yet unmapped KEYCODES:
1091cdf0e10cSrcweir         aKeyMap[ KEY_INSERT ]   = rtl::OUString( sal_Unicode( ) );
1092cdf0e10cSrcweir         aKeyMap[ KEY_CUT ]      = rtl::OUString( sal_Unicode( ) );
1093cdf0e10cSrcweir         aKeyMap[ KEY_COPY ]     = rtl::OUString( sal_Unicode( ) );
1094cdf0e10cSrcweir         aKeyMap[ KEY_PASTE ]    = rtl::OUString( sal_Unicode( ) );
1095cdf0e10cSrcweir         aKeyMap[ KEY_UNDO ]     = rtl::OUString( sal_Unicode( ) );
1096cdf0e10cSrcweir         aKeyMap[ KEY_REPEAT ]   = rtl::OUString( sal_Unicode( ) );
1097cdf0e10cSrcweir         aKeyMap[ KEY_FIND ]     = rtl::OUString( sal_Unicode( ) );
1098cdf0e10cSrcweir         aKeyMap[ KEY_PROPERTIES ]     = rtl::OUString( sal_Unicode( ) );
1099cdf0e10cSrcweir         aKeyMap[ KEY_FRONT ]    = rtl::OUString( sal_Unicode( ) );
1100cdf0e10cSrcweir         aKeyMap[ KEY_CONTEXTMENU ]    = rtl::OUString( sal_Unicode( ) );
1101cdf0e10cSrcweir         aKeyMap[ KEY_MENU ]     = rtl::OUString( sal_Unicode( ) );
1102cdf0e10cSrcweir         aKeyMap[ KEY_HELP ]     = rtl::OUString( sal_Unicode( ) );
1103cdf0e10cSrcweir         aKeyMap[ KEY_HANGUL_HANJA ]   = rtl::OUString( sal_Unicode( ) );
1104cdf0e10cSrcweir         aKeyMap[ KEY_DECIMAL ]  = rtl::OUString( sal_Unicode( ) );
1105cdf0e10cSrcweir         aKeyMap[ KEY_TILDE ]    = rtl::OUString( sal_Unicode( ) );
1106cdf0e10cSrcweir         aKeyMap[ KEY_QUOTELEFT ]= rtl::OUString( sal_Unicode( ) );
1107cdf0e10cSrcweir         */
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir     }
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir     rtl::OUStringBuffer aResult( 16 );
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir     sal_uInt16 nUnmodifiedCode = (nKeyCode & KEY_CODE);
1114cdf0e10cSrcweir     std::map< sal_uInt16, rtl::OUString >::const_iterator it = aKeyMap.find( nUnmodifiedCode );
1115cdf0e10cSrcweir     if( it != aKeyMap.end() )
1116cdf0e10cSrcweir     {
1117cdf0e10cSrcweir         if( (nKeyCode & KEY_SHIFT) != 0 )
1118cdf0e10cSrcweir             aResult.append( sal_Unicode( 0x21e7 ) );
1119cdf0e10cSrcweir         if( (nKeyCode & KEY_MOD1) != 0 )
1120cdf0e10cSrcweir             aResult.append( sal_Unicode( 0x2318 ) );
1121cdf0e10cSrcweir         // we do not really handle Alt (see below)
1122cdf0e10cSrcweir         // we map it to MOD3, whichis actually Command
1123cdf0e10cSrcweir         if( (nKeyCode & (KEY_MOD2|KEY_MOD3)) != 0 )
1124cdf0e10cSrcweir             aResult.append( sal_Unicode( 0x2303 ) );
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir         aResult.append( it->second );
1127cdf0e10cSrcweir     }
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir 	return aResult.makeStringAndClear();
1130cdf0e10cSrcweir }
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir // -----------------------------------------------------------------------
1133cdf0e10cSrcweir 
GetSymbolKeyName(const XubString &,sal_uInt16 nKeyCode)1134cdf0e10cSrcweir XubString AquaSalFrame::GetSymbolKeyName( const XubString&, sal_uInt16 nKeyCode )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir 	return GetKeyName( nKeyCode );
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir // -----------------------------------------------------------------------
1140cdf0e10cSrcweir 
getAppleScrollBarVariant(void)1141cdf0e10cSrcweir static void getAppleScrollBarVariant(void)
1142cdf0e10cSrcweir {
1143cdf0e10cSrcweir     bool bIsScrollbarDoubleMax = true; // default is DoubleMax
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir     CFStringRef AppleScrollBarType = CFSTR("AppleScrollBarVariant");
1146cdf0e10cSrcweir     if( AppleScrollBarType )
1147cdf0e10cSrcweir     {
1148cdf0e10cSrcweir         CFStringRef ScrollBarVariant = ((CFStringRef)CFPreferencesCopyAppValue( AppleScrollBarType, kCFPreferencesCurrentApplication ));
1149cdf0e10cSrcweir         if( ScrollBarVariant )
1150cdf0e10cSrcweir         {
1151cdf0e10cSrcweir             if( CFGetTypeID( ScrollBarVariant ) == CFStringGetTypeID() )
1152cdf0e10cSrcweir             {
1153cdf0e10cSrcweir                 // TODO: check for the less important variants "DoubleMin" and "DoubleBoth" too
1154cdf0e10cSrcweir                 CFStringRef DoubleMax = CFSTR("DoubleMax");
1155cdf0e10cSrcweir                 if (DoubleMax)
1156cdf0e10cSrcweir                 {
1157cdf0e10cSrcweir                     if ( !CFStringCompare(ScrollBarVariant, DoubleMax, kCFCompareCaseInsensitive) )
1158cdf0e10cSrcweir                         bIsScrollbarDoubleMax = true;
1159cdf0e10cSrcweir                     else
1160cdf0e10cSrcweir                         bIsScrollbarDoubleMax = false;
1161cdf0e10cSrcweir                     CFRelease(DoubleMax);
1162cdf0e10cSrcweir                 }
1163cdf0e10cSrcweir             }
1164cdf0e10cSrcweir             CFRelease( ScrollBarVariant );
1165cdf0e10cSrcweir         }
1166cdf0e10cSrcweir 		CFRelease(AppleScrollBarType);
1167cdf0e10cSrcweir     }
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 	GetSalData()->mbIsScrollbarDoubleMax = bIsScrollbarDoubleMax;
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir     CFStringRef jumpScroll = CFSTR("AppleScrollerPagingBehavior");
1172cdf0e10cSrcweir     if( jumpScroll )
1173cdf0e10cSrcweir     {
1174cdf0e10cSrcweir         CFBooleanRef jumpStr = ((CFBooleanRef)CFPreferencesCopyAppValue( jumpScroll, kCFPreferencesCurrentApplication ));
1175cdf0e10cSrcweir         if( jumpStr )
1176cdf0e10cSrcweir         {
1177cdf0e10cSrcweir             if( CFGetTypeID( jumpStr ) == CFBooleanGetTypeID() )
1178cdf0e10cSrcweir                 ImplGetSVData()->maNWFData.mbScrollbarJumpPage = (jumpStr == kCFBooleanTrue);
1179cdf0e10cSrcweir             CFRelease( jumpStr );
1180cdf0e10cSrcweir         }
1181cdf0e10cSrcweir 		CFRelease( jumpScroll );
1182cdf0e10cSrcweir     }
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir 
getColor(NSColor * pSysColor,const Color & rDefault,NSWindow * pWin)1185cdf0e10cSrcweir static Color getColor( NSColor* pSysColor, const Color& rDefault, NSWindow* pWin )
1186cdf0e10cSrcweir {
1187cdf0e10cSrcweir     Color aRet( rDefault );
1188cdf0e10cSrcweir     if( pSysColor )
1189cdf0e10cSrcweir     {
1190cdf0e10cSrcweir         // transform to RGB
1191cdf0e10cSrcweir         NSColor* pRBGColor = [pSysColor colorUsingColorSpaceName: NSDeviceRGBColorSpace device: [pWin deviceDescription]];
1192cdf0e10cSrcweir         if( pRBGColor )
1193cdf0e10cSrcweir         {
119424a22e85SHerbert Dürr             CGFloat r = 0, g = 0, b = 0, a = 0;
1195cdf0e10cSrcweir             [pRBGColor getRed: &r green: &g blue: &b alpha: &a];
1196cdf0e10cSrcweir             aRet = Color( int(r*255.999), int(g*255.999), int(b*255.999) );
1197cdf0e10cSrcweir             /*
1198cdf0e10cSrcweir             do not release here; leads to duplicate free in yield
1199cdf0e10cSrcweir             it seems the converted color comes out autoreleased, although this
1200cdf0e10cSrcweir             is not documented
1201cdf0e10cSrcweir             [pRBGColor release];
1202cdf0e10cSrcweir             */
1203cdf0e10cSrcweir         }
1204cdf0e10cSrcweir     }
1205cdf0e10cSrcweir     return aRet;
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir 
getFont(NSFont * pFont,long nDPIY,const Font & rDefault)1208cdf0e10cSrcweir static Font getFont( NSFont* pFont, long nDPIY, const Font& rDefault )
1209cdf0e10cSrcweir {
1210cdf0e10cSrcweir     Font aResult( rDefault );
1211cdf0e10cSrcweir     if( pFont )
1212cdf0e10cSrcweir     {
1213cdf0e10cSrcweir         aResult.SetName( GetOUString( [pFont familyName] ) );
1214cdf0e10cSrcweir         aResult.SetHeight( static_cast<int>(([pFont pointSize] * 72.0 / (float)nDPIY)+0.5) );
1215cdf0e10cSrcweir         aResult.SetItalic( ([pFont italicAngle] != 0.0) ? ITALIC_NORMAL : ITALIC_NONE );
1216cdf0e10cSrcweir         // FIMXE: bold ?
1217cdf0e10cSrcweir     }
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir     return aResult;
1220cdf0e10cSrcweir }
1221cdf0e10cSrcweir 
getResolution(sal_Int32 & o_rDPIX,sal_Int32 & o_rDPIY)12228a718ffcSHerbert Dürr void AquaSalFrame::getResolution( sal_Int32& o_rDPIX, sal_Int32& o_rDPIY )
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir     if( ! mpGraphics )
1225cdf0e10cSrcweir     {
1226cdf0e10cSrcweir         GetGraphics();
1227cdf0e10cSrcweir         ReleaseGraphics( mpGraphics );
1228cdf0e10cSrcweir     }
1229cdf0e10cSrcweir 	mpGraphics->GetResolution( o_rDPIX, o_rDPIY );
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir // on OSX-Aqua the style settings are independent of the frame, so it does
1233cdf0e10cSrcweir // not really belong here. Since the connection to the Appearance_Manager
1234cdf0e10cSrcweir // is currently done in salnativewidgets.cxx this would be a good place.
1235cdf0e10cSrcweir // On the other hand VCL's platform independent code currently only asks
1236cdf0e10cSrcweir // SalFrames for system settings anyway, so moving the code somewhere else
1237cdf0e10cSrcweir // doesn't make the anything cleaner for now
UpdateSettings(AllSettings & rSettings)1238cdf0e10cSrcweir void AquaSalFrame::UpdateSettings( AllSettings& rSettings )
1239cdf0e10cSrcweir {
1240bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1241cdf0e10cSrcweir         return;
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1244cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1245cdf0e10cSrcweir 
1246bde8a4bdSHerbert Dürr     [mpNSView lockFocus];
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir     StyleSettings aStyleSettings = rSettings.GetStyleSettings();
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir     // Background Color
1251cdf0e10cSrcweir     Color aBackgroundColor = Color( 0xEC, 0xEC, 0xEC );
1252cdf0e10cSrcweir     aStyleSettings.Set3DColors( aBackgroundColor );
1253cdf0e10cSrcweir     aStyleSettings.SetFaceColor( aBackgroundColor );
1254cdf0e10cSrcweir     Color aInactiveTabColor( aBackgroundColor );
1255cdf0e10cSrcweir     aInactiveTabColor.DecreaseLuminance( 32 );
1256cdf0e10cSrcweir     aStyleSettings.SetInactiveTabColor( aInactiveTabColor );
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir     aStyleSettings.SetDialogColor( aBackgroundColor );
1259cdf0e10cSrcweir     aStyleSettings.SetLightBorderColor( aBackgroundColor );
1260cdf0e10cSrcweir     Color aShadowColor( aStyleSettings.GetShadowColor() );
1261cdf0e10cSrcweir     aStyleSettings.SetDarkShadowColor( aShadowColor );
1262cdf0e10cSrcweir     aShadowColor.IncreaseLuminance( 32 );
1263cdf0e10cSrcweir     aStyleSettings.SetShadowColor( aShadowColor );
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir     // get the system font settings
1266cdf0e10cSrcweir     Font aAppFont = aStyleSettings.GetAppFont();
12678a718ffcSHerbert Dürr 	sal_Int32 nDPIX = 72, nDPIY = 72;
1268cdf0e10cSrcweir 	getResolution( nDPIX, nDPIY );
1269cdf0e10cSrcweir     aAppFont = getFont( [NSFont systemFontOfSize: 0], nDPIY, aAppFont );
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir     // TODO: better mapping of aqua<->ooo font settings
1272cdf0e10cSrcweir 	aStyleSettings.SetAppFont( aAppFont );
1273cdf0e10cSrcweir 	aStyleSettings.SetHelpFont( aAppFont );
1274cdf0e10cSrcweir 	aStyleSettings.SetPushButtonFont( aAppFont );
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir     Font aTitleFont( getFont( [NSFont titleBarFontOfSize: 0], nDPIY, aAppFont ) );
1277cdf0e10cSrcweir 	aStyleSettings.SetTitleFont( aTitleFont );
1278cdf0e10cSrcweir 	aStyleSettings.SetFloatTitleFont( aTitleFont );
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir     Font aMenuFont( getFont( [NSFont menuFontOfSize: 0], nDPIY, aAppFont ) );
1281cdf0e10cSrcweir 	aStyleSettings.SetMenuFont( aMenuFont );
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir 	aStyleSettings.SetToolFont( aAppFont );
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir     Font aLabelFont( getFont( [NSFont labelFontOfSize: 0], nDPIY, aAppFont ) );
1286cdf0e10cSrcweir 	aStyleSettings.SetLabelFont( aLabelFont );
1287cdf0e10cSrcweir 	aStyleSettings.SetInfoFont( aLabelFont );
1288cdf0e10cSrcweir 	aStyleSettings.SetRadioCheckFont( aLabelFont );
1289cdf0e10cSrcweir 	aStyleSettings.SetFieldFont( aLabelFont );
1290cdf0e10cSrcweir 	aStyleSettings.SetGroupFont( aLabelFont );
1291cdf0e10cSrcweir 	aStyleSettings.SetIconFont( aLabelFont );
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir     Color aHighlightColor( getColor( [NSColor selectedTextBackgroundColor],
1294bde8a4bdSHerbert Dürr                                       aStyleSettings.GetHighlightColor(), mpNSWindow ) );
1295cdf0e10cSrcweir     aStyleSettings.SetHighlightColor( aHighlightColor );
1296cdf0e10cSrcweir     Color aHighlightTextColor( getColor( [NSColor selectedTextColor],
1297bde8a4bdSHerbert Dürr                                          aStyleSettings.GetHighlightTextColor(), mpNSWindow ) );
1298cdf0e10cSrcweir     aStyleSettings.SetHighlightTextColor( aHighlightTextColor );
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir     Color aMenuHighlightColor( getColor( [NSColor selectedMenuItemColor],
1301bde8a4bdSHerbert Dürr                                          aStyleSettings.GetMenuHighlightColor(), mpNSWindow ) );
1302cdf0e10cSrcweir     aStyleSettings.SetMenuHighlightColor( aMenuHighlightColor );
1303cdf0e10cSrcweir     Color aMenuHighlightTextColor( getColor( [NSColor selectedMenuItemTextColor],
1304bde8a4bdSHerbert Dürr                                              aStyleSettings.GetMenuHighlightTextColor(), mpNSWindow ) );
1305cdf0e10cSrcweir     aStyleSettings.SetMenuHighlightTextColor( aMenuHighlightTextColor );
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir     aStyleSettings.SetMenuColor( aBackgroundColor );
1308cdf0e10cSrcweir     Color aMenuTextColor( getColor( [NSColor textColor],
1309bde8a4bdSHerbert Dürr                                     aStyleSettings.GetMenuTextColor(), mpNSWindow ) );
1310cdf0e10cSrcweir     aStyleSettings.SetMenuTextColor( aMenuTextColor );
1311cdf0e10cSrcweir     aStyleSettings.SetMenuBarTextColor( aMenuTextColor );
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir     aStyleSettings.SetCursorBlinkTime( 500 );
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir     // no mnemonics on aqua
1316cdf0e10cSrcweir     aStyleSettings.SetOptions( aStyleSettings.GetOptions() | STYLE_OPTION_NOMNEMONICS );
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir     getAppleScrollBarVariant();
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir     // set scrollbar size
1321cdf0e10cSrcweir     aStyleSettings.SetScrollBarSize( static_cast<long int>([NSScroller scrollerWidth]) );
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir     // images in menus false for MacOSX
1324cdf0e10cSrcweir     aStyleSettings.SetUseImagesInMenus( false );
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir     rSettings.SetStyleSettings( aStyleSettings );
1327cdf0e10cSrcweir 
1328bde8a4bdSHerbert Dürr     [mpNSView unlockFocus];
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir // -----------------------------------------------------------------------
1332cdf0e10cSrcweir 
GetSystemData() const1333cdf0e10cSrcweir const SystemEnvData* AquaSalFrame::GetSystemData() const
1334cdf0e10cSrcweir {
1335cdf0e10cSrcweir     return &maSysData;
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir // -----------------------------------------------------------------------
1339cdf0e10cSrcweir 
Beep(SoundType eSoundType)1340cdf0e10cSrcweir void AquaSalFrame::Beep( SoundType eSoundType )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir     switch( eSoundType )
1343cdf0e10cSrcweir     {
1344cdf0e10cSrcweir     case SOUND_DISABLE:
1345cdf0e10cSrcweir         // don't beep
1346cdf0e10cSrcweir         break;
1347cdf0e10cSrcweir     default:
1348cdf0e10cSrcweir         NSBeep();
1349cdf0e10cSrcweir         break;
1350cdf0e10cSrcweir     }
1351cdf0e10cSrcweir }
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir // -----------------------------------------------------------------------
1354cdf0e10cSrcweir 
SetPosSize(long nX,long nY,long nWidth,long nHeight,sal_uInt16 nFlags)1355cdf0e10cSrcweir void AquaSalFrame::SetPosSize(long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags)
1356cdf0e10cSrcweir {
1357bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1358cdf0e10cSrcweir         return;
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1361cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir     sal_uInt16 nEvent = 0;
1364cdf0e10cSrcweir 
1365bde8a4bdSHerbert Dürr     if( [mpNSWindow isMiniaturized] )
1366bde8a4bdSHerbert Dürr         [mpNSWindow deminiaturize: NSApp]; // expand the window
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir     if (nFlags & (SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y))
1369cdf0e10cSrcweir     {
1370cdf0e10cSrcweir         mbPositioned = true;
1371cdf0e10cSrcweir         nEvent = SALEVENT_MOVE;
1372cdf0e10cSrcweir     }
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir     if (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT))
1375cdf0e10cSrcweir     {
1376cdf0e10cSrcweir         mbSized = true;
1377cdf0e10cSrcweir         nEvent = (nEvent == SALEVENT_MOVE) ? SALEVENT_MOVERESIZE : SALEVENT_RESIZE;
1378cdf0e10cSrcweir     }
1379cdf0e10cSrcweir 
1380bde8a4bdSHerbert Dürr     NSRect aFrameRect = [mpNSWindow frame];
1381cdf0e10cSrcweir     NSRect aContentRect = [NSWindow contentRectForFrameRect: aFrameRect styleMask: mnStyleMask];
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir     // position is always relative to parent frame
1384cdf0e10cSrcweir     NSRect aParentContentRect;
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir     if( mpParent )
1387cdf0e10cSrcweir     {
1388cdf0e10cSrcweir         if( Application::GetSettings().GetLayoutRTL() )
1389cdf0e10cSrcweir         {
1390cdf0e10cSrcweir             if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
1391cdf0e10cSrcweir                 nX = mpParent->maGeometry.nWidth - nWidth-1 - nX;
1392cdf0e10cSrcweir             else
1393cdf0e10cSrcweir                 nX = mpParent->maGeometry.nWidth - static_cast<long int>( aContentRect.size.width-1) - nX;
1394cdf0e10cSrcweir         }
1395bde8a4bdSHerbert Dürr         NSRect aParentFrameRect = [mpParent->mpNSWindow frame];
1396cdf0e10cSrcweir         aParentContentRect = [NSWindow contentRectForFrameRect: aParentFrameRect styleMask: mpParent->mnStyleMask];
1397cdf0e10cSrcweir     }
1398cdf0e10cSrcweir     else
1399cdf0e10cSrcweir         aParentContentRect = maScreenRect; // use screen if no parent
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir     CocoaToVCL( aContentRect );
1402cdf0e10cSrcweir     CocoaToVCL( aParentContentRect );
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir     bool bPaint = false;
1405cdf0e10cSrcweir     if( (nFlags & (SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT)) != 0 )
1406cdf0e10cSrcweir     {
1407cdf0e10cSrcweir         if( nWidth != aContentRect.size.width || nHeight != aContentRect.size.height )
1408cdf0e10cSrcweir             bPaint = true;
1409cdf0e10cSrcweir     }
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir     // use old window pos if no new pos requested
1412cdf0e10cSrcweir     if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 )
1413cdf0e10cSrcweir         aContentRect.origin.x = nX + aParentContentRect.origin.x;
1414cdf0e10cSrcweir     if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0)
1415cdf0e10cSrcweir         aContentRect.origin.y = nY + aParentContentRect.origin.y;
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir     // use old size if no new size requested
1418cdf0e10cSrcweir     if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
1419cdf0e10cSrcweir         aContentRect.size.width = nWidth;
1420cdf0e10cSrcweir     if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0)
1421cdf0e10cSrcweir         aContentRect.size.height = nHeight;
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir     VCLToCocoa( aContentRect );
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir     // do not display yet, we need to update our backbuffer
1426cdf0e10cSrcweir     {
1427bde8a4bdSHerbert Dürr         [mpNSWindow setFrame: [NSWindow frameRectForContentRect: aContentRect styleMask: mnStyleMask] display: NO];
1428cdf0e10cSrcweir     }
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir     UpdateFrameGeometry();
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir     if (nEvent)
1433cdf0e10cSrcweir         CallCallback(nEvent, NULL);
1434cdf0e10cSrcweir 
1435cdf0e10cSrcweir     if( mbShown && bPaint )
1436cdf0e10cSrcweir     {
1437cdf0e10cSrcweir         // trigger filling our backbuffer
1438cdf0e10cSrcweir         SendPaintEvent();
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir         // now inform the system that the views need to be drawn
1441bde8a4bdSHerbert Dürr         [mpNSWindow display];
1442cdf0e10cSrcweir     }
1443cdf0e10cSrcweir }
1444cdf0e10cSrcweir 
GetWorkArea(Rectangle & rRect)1445cdf0e10cSrcweir void AquaSalFrame::GetWorkArea( Rectangle& rRect )
1446cdf0e10cSrcweir {
1447bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1448cdf0e10cSrcweir         return;
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1451cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1452cdf0e10cSrcweir 
1453bde8a4bdSHerbert Dürr     NSScreen* pScreen = [mpNSWindow screen];
1454cdf0e10cSrcweir     if( pScreen ==  nil )
1455cdf0e10cSrcweir         pScreen = [NSScreen mainScreen];
1456cdf0e10cSrcweir     NSRect aRect = [pScreen visibleFrame];
1457cdf0e10cSrcweir     CocoaToVCL( aRect );
1458cdf0e10cSrcweir     rRect.nLeft     = static_cast<long>(aRect.origin.x);
1459cdf0e10cSrcweir     rRect.nTop      = static_cast<long>(aRect.origin.y);
1460cdf0e10cSrcweir     rRect.nRight    = static_cast<long>(aRect.origin.x + aRect.size.width - 1);
1461cdf0e10cSrcweir     rRect.nBottom   = static_cast<long>(aRect.origin.y + aRect.size.height - 1);
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir 
GetPointerState()1464cdf0e10cSrcweir SalPointerState	AquaSalFrame::GetPointerState()
1465cdf0e10cSrcweir {
1466cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1467cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir     SalPointerState state;
1470cdf0e10cSrcweir     state.mnState = 0;
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir     // get position
1473bde8a4bdSHerbert Dürr     NSPoint aPt = [mpNSWindow mouseLocationOutsideOfEventStream];
1474cdf0e10cSrcweir     CocoaToVCL( aPt, false );
1475cdf0e10cSrcweir     state.maPos = Point(static_cast<long>(aPt.x), static_cast<long>(aPt.y));
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir     NSEvent* pCur = [NSApp currentEvent];
1478cdf0e10cSrcweir     bool bMouseEvent = false;
1479cdf0e10cSrcweir     if( pCur )
1480cdf0e10cSrcweir     {
1481cdf0e10cSrcweir         bMouseEvent = true;
1482cdf0e10cSrcweir         switch( [pCur type] )
1483cdf0e10cSrcweir         {
1484cdf0e10cSrcweir         case NSLeftMouseDown:       state.mnState |= MOUSE_LEFT; break;
1485cdf0e10cSrcweir         case NSLeftMouseUp:         break;
1486cdf0e10cSrcweir         case NSRightMouseDown:      state.mnState |= MOUSE_RIGHT; break;
1487cdf0e10cSrcweir         case NSRightMouseUp:        break;
1488cdf0e10cSrcweir         case NSOtherMouseDown:      state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; break;
1489cdf0e10cSrcweir         case NSOtherMouseUp:        break;
1490cdf0e10cSrcweir         case NSMouseMoved:          break;
1491cdf0e10cSrcweir         case NSLeftMouseDragged:    state.mnState |= MOUSE_LEFT; break;
1492cdf0e10cSrcweir         case NSRightMouseDragged:   state.mnState |= MOUSE_RIGHT; break;
1493cdf0e10cSrcweir         case NSOtherMouseDragged:   state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; break;
1494cdf0e10cSrcweir             break;
1495cdf0e10cSrcweir         default:
1496cdf0e10cSrcweir             bMouseEvent = false;
1497cdf0e10cSrcweir             break;
1498cdf0e10cSrcweir         }
1499cdf0e10cSrcweir     }
1500cdf0e10cSrcweir     if( bMouseEvent )
1501cdf0e10cSrcweir     {
1502cdf0e10cSrcweir         unsigned int nMask = (unsigned int)[pCur modifierFlags];
1503cdf0e10cSrcweir         if( (nMask & NSShiftKeyMask) != 0 )
1504cdf0e10cSrcweir             state.mnState |= KEY_SHIFT;
1505cdf0e10cSrcweir         if( (nMask & NSControlKeyMask) != 0 )
1506cdf0e10cSrcweir             state.mnState |= KEY_MOD3;
1507cdf0e10cSrcweir         if( (nMask & NSAlternateKeyMask) != 0 )
1508cdf0e10cSrcweir             state.mnState |= KEY_MOD2;
1509cdf0e10cSrcweir         if( (nMask & NSCommandKeyMask) != 0 )
1510cdf0e10cSrcweir             state.mnState |= KEY_MOD1;
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir     }
1513cdf0e10cSrcweir     else
1514cdf0e10cSrcweir     {
1515cdf0e10cSrcweir         // FIXME: replace Carbon by Cocoa
1516cdf0e10cSrcweir         // Cocoa does not have an equivalent for GetCurrentEventButtonState
1517cdf0e10cSrcweir         // and GetCurrentEventKeyModifiers.
1518cdf0e10cSrcweir         // we could try to get away with tracking all events for modifierKeys
1519cdf0e10cSrcweir         // and all mouse events for button state in VCL_NSApllication::sendEvent,
1520cdf0e10cSrcweir         // but it is unclear whether this will get us the same result.
1521cdf0e10cSrcweir         // leave in GetCurrentEventButtonState and GetCurrentEventKeyModifiers for now
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir         // fill in button state
1524cdf0e10cSrcweir         UInt32 nState = GetCurrentEventButtonState();
1525cdf0e10cSrcweir         state.mnState = 0;
1526cdf0e10cSrcweir         if( nState & 1 )
1527cdf0e10cSrcweir             state.mnState |= MOUSE_LEFT;    // primary button
1528cdf0e10cSrcweir         if( nState & 2 )
1529cdf0e10cSrcweir             state.mnState |= MOUSE_RIGHT;   // secondary button
1530cdf0e10cSrcweir         if( nState & 4 )
1531cdf0e10cSrcweir             state.mnState |= MOUSE_MIDDLE;  // tertiary button
1532cdf0e10cSrcweir 
1533cdf0e10cSrcweir         // fill in modifier state
1534cdf0e10cSrcweir         nState = GetCurrentEventKeyModifiers();
1535cdf0e10cSrcweir         if( nState & shiftKey )
1536cdf0e10cSrcweir             state.mnState |= KEY_SHIFT;
1537cdf0e10cSrcweir         if( nState & controlKey )
1538cdf0e10cSrcweir             state.mnState |= KEY_MOD3;
1539cdf0e10cSrcweir         if( nState & optionKey )
1540cdf0e10cSrcweir             state.mnState |= KEY_MOD2;
1541cdf0e10cSrcweir         if( nState & cmdKey )
1542cdf0e10cSrcweir             state.mnState |= KEY_MOD1;
1543cdf0e10cSrcweir     }
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir     return state;
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir 
SetPluginParent(SystemParentData *)1549cdf0e10cSrcweir bool AquaSalFrame::SetPluginParent( SystemParentData* )
1550cdf0e10cSrcweir {
1551cdf0e10cSrcweir     // plugin parent may be killed unexpectedly by
1552cdf0e10cSrcweir     // plugging process;
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir     //TODO: implement
1555cdf0e10cSrcweir     return sal_False;
1556cdf0e10cSrcweir }
1557cdf0e10cSrcweir 
MapUnicodeToKeyCode(sal_Unicode,LanguageType,KeyCode &)1558cdf0e10cSrcweir sal_Bool AquaSalFrame::MapUnicodeToKeyCode( sal_Unicode , LanguageType , KeyCode& )
1559cdf0e10cSrcweir {
1560cdf0e10cSrcweir     // not supported yet
1561cdf0e10cSrcweir     return FALSE;
1562cdf0e10cSrcweir }
1563cdf0e10cSrcweir 
GetInputLanguage()1564cdf0e10cSrcweir LanguageType AquaSalFrame::GetInputLanguage()
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir     //TODO: implement
1567cdf0e10cSrcweir     return LANGUAGE_DONTKNOW;
1568cdf0e10cSrcweir }
1569cdf0e10cSrcweir 
DrawMenuBar()1570cdf0e10cSrcweir void AquaSalFrame::DrawMenuBar()
1571cdf0e10cSrcweir {
1572cdf0e10cSrcweir }
1573cdf0e10cSrcweir 
SetMenu(SalMenu * pSalMenu)1574cdf0e10cSrcweir void AquaSalFrame::SetMenu( SalMenu* pSalMenu )
1575cdf0e10cSrcweir {
1576cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1577cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir     AquaSalMenu* pMenu = static_cast<AquaSalMenu*>(pSalMenu);
1580cdf0e10cSrcweir     DBG_ASSERT( ! pMenu || pMenu->mbMenuBar, "setting non menubar on frame" );
1581cdf0e10cSrcweir     mpMenu = pMenu;
1582cdf0e10cSrcweir     if( mpMenu  )
1583cdf0e10cSrcweir         mpMenu->setMainMenu();
1584cdf0e10cSrcweir }
1585cdf0e10cSrcweir 
SetExtendedFrameStyle(SalExtStyle nStyle)1586cdf0e10cSrcweir void AquaSalFrame::SetExtendedFrameStyle( SalExtStyle nStyle )
1587cdf0e10cSrcweir {
1588bde8a4bdSHerbert Dürr     if ( mpNSWindow )
1589cdf0e10cSrcweir     {
1590cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1591cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir     if( (mnExtStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) != (nStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) )
1594bde8a4bdSHerbert Dürr         [mpNSWindow setDocumentEdited: (nStyle & SAL_FRAME_EXT_STYLE_DOCMODIFIED) ? YES : NO];
1595cdf0e10cSrcweir     }
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir     mnExtStyle = nStyle;
1598cdf0e10cSrcweir }
1599cdf0e10cSrcweir 
SetBackgroundBitmap(SalBitmap *)1600cdf0e10cSrcweir void AquaSalFrame::SetBackgroundBitmap( SalBitmap* )
1601cdf0e10cSrcweir {
1602cdf0e10cSrcweir     //TODO: implement
1603cdf0e10cSrcweir }
1604cdf0e10cSrcweir 
SnapShot()1605cdf0e10cSrcweir SalBitmap* AquaSalFrame::SnapShot()
1606cdf0e10cSrcweir {
1607cdf0e10cSrcweir     return mpGraphics ? mpGraphics->getBitmap( 0, 0, maGeometry.nWidth, maGeometry.nHeight ) : NULL;
1608cdf0e10cSrcweir }
1609cdf0e10cSrcweir 
GetParent() const1610cdf0e10cSrcweir SalFrame* AquaSalFrame::GetParent() const
1611cdf0e10cSrcweir {
1612cdf0e10cSrcweir     return mpParent;
1613cdf0e10cSrcweir }
1614cdf0e10cSrcweir 
SetParent(SalFrame * pNewParent)1615cdf0e10cSrcweir void AquaSalFrame::SetParent( SalFrame* pNewParent )
1616cdf0e10cSrcweir {
1617cdf0e10cSrcweir     bool bShown = mbShown;
1618cdf0e10cSrcweir     // remove from child list
1619cdf0e10cSrcweir     Show( FALSE );
1620cdf0e10cSrcweir     mpParent = (AquaSalFrame*)pNewParent;
1621cdf0e10cSrcweir     // insert to correct parent and paint
1622cdf0e10cSrcweir     Show( bShown );
1623cdf0e10cSrcweir }
1624cdf0e10cSrcweir 
UpdateFrameGeometry()1625cdf0e10cSrcweir void AquaSalFrame::UpdateFrameGeometry()
1626cdf0e10cSrcweir {
1627bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1628cdf0e10cSrcweir     {
1629cdf0e10cSrcweir         return;
1630cdf0e10cSrcweir     }
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir     // keep in mind that view and window coordinates are lower left
1633cdf0e10cSrcweir     // whereas vcl's are upper left
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir     // update screen rect
1636bde8a4bdSHerbert Dürr     NSScreen * pScreen = [mpNSWindow screen];
1637cdf0e10cSrcweir     if( pScreen )
1638cdf0e10cSrcweir     {
1639cdf0e10cSrcweir         maScreenRect = [pScreen frame];
1640cdf0e10cSrcweir         NSArray* pScreens = [NSScreen screens];
1641cdf0e10cSrcweir         if( pScreens )
1642cdf0e10cSrcweir             maGeometry.nScreenNumber = [pScreens indexOfObject: pScreen];
1643cdf0e10cSrcweir     }
1644cdf0e10cSrcweir 
1645bde8a4bdSHerbert Dürr     NSRect aFrameRect = [mpNSWindow frame];
1646cdf0e10cSrcweir     NSRect aContentRect = [NSWindow contentRectForFrameRect: aFrameRect styleMask: mnStyleMask];
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir     // release old track rect
1649bde8a4bdSHerbert Dürr     [mpNSView removeTrackingRect: mnTrackingRectTag];
1650cdf0e10cSrcweir     // install the new track rect
1651*01367266SHerbert Dürr     NSRect aTrackRect = { NSZeroPoint, aContentRect.size };
1652bde8a4bdSHerbert Dürr     mnTrackingRectTag = [mpNSView addTrackingRect: aTrackRect owner: mpNSView userData: nil assumeInside: NO];
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir     // convert to vcl convention
1655cdf0e10cSrcweir     CocoaToVCL( aFrameRect );
1656cdf0e10cSrcweir     CocoaToVCL( aContentRect );
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir     maGeometry.nX = static_cast<int>(aContentRect.origin.x);
1659cdf0e10cSrcweir     maGeometry.nY = static_cast<int>(aContentRect.origin.y);
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir     maGeometry.nLeftDecoration = static_cast<unsigned int>(aContentRect.origin.x - aFrameRect.origin.x);
1662cdf0e10cSrcweir     maGeometry.nRightDecoration = static_cast<unsigned int>((aFrameRect.origin.x + aFrameRect.size.width) -
1663cdf0e10cSrcweir                                   (aContentRect.origin.x + aContentRect.size.width));
1664cdf0e10cSrcweir 
1665cdf0e10cSrcweir     maGeometry.nTopDecoration = static_cast<unsigned int>(aContentRect.origin.y - aFrameRect.origin.y);
1666cdf0e10cSrcweir     maGeometry.nBottomDecoration = static_cast<unsigned int>((aFrameRect.origin.y + aFrameRect.size.height) -
1667cdf0e10cSrcweir                                    (aContentRect.origin.y + aContentRect.size.height));
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir     maGeometry.nWidth = static_cast<unsigned int>(aContentRect.size.width);
1670cdf0e10cSrcweir     maGeometry.nHeight = static_cast<unsigned int>(aContentRect.size.height);
1671cdf0e10cSrcweir }
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir // -----------------------------------------------------------------------
1674cdf0e10cSrcweir 
CaptureMouse(sal_Bool bCapture)1675cdf0e10cSrcweir void AquaSalFrame::CaptureMouse( sal_Bool bCapture )
1676cdf0e10cSrcweir {
1677cdf0e10cSrcweir     /* Remark:
1678cdf0e10cSrcweir        we'll try to use a pidgin version of capture mouse
1679cdf0e10cSrcweir        on MacOSX (neither carbon nor cocoa) there is a
1680cdf0e10cSrcweir        CaptureMouse equivalent (in Carbon there is TrackMouseLocation
1681cdf0e10cSrcweir        but this is useless to use since it is blocking)
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir        However on cocoa the active frame seems to get mouse events
1684cdf0e10cSrcweir        also outside the window, so we'll try to forward mouse events
1685cdf0e10cSrcweir        to the capture frame in the hope that one of our frames
1686cdf0e10cSrcweir        gets a mouse event.
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir        This will break as soon as the user activates another app, but
1689cdf0e10cSrcweir        a mouse click will normally lead to a release of the mouse anyway.
1690cdf0e10cSrcweir 
1691cdf0e10cSrcweir        Let's see how far we get this way. Alternatively we could use one
1692cdf0e10cSrcweir        large overlay window like we did for the carbon implementation,
1693cdf0e10cSrcweir        however that is resource intensive.
1694cdf0e10cSrcweir     */
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir     if( bCapture )
1697cdf0e10cSrcweir         s_pCaptureFrame = this;
1698cdf0e10cSrcweir     else if( ! bCapture && s_pCaptureFrame == this )
1699cdf0e10cSrcweir         s_pCaptureFrame = NULL;
1700cdf0e10cSrcweir }
1701cdf0e10cSrcweir 
ResetClipRegion()1702cdf0e10cSrcweir void AquaSalFrame::ResetClipRegion()
1703cdf0e10cSrcweir {
1704bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1705cdf0e10cSrcweir     {
1706cdf0e10cSrcweir         return;
1707cdf0e10cSrcweir     }
1708cdf0e10cSrcweir 
1709cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1710cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir     // release old path and indicate no clipping
1713cdf0e10cSrcweir     CGPathRelease( mrClippingPath );
1714cdf0e10cSrcweir     mrClippingPath = NULL;
1715cdf0e10cSrcweir 
1716bde8a4bdSHerbert Dürr     if( mpNSView && mbShown )
1717bde8a4bdSHerbert Dürr         [mpNSView setNeedsDisplay: YES];
1718bde8a4bdSHerbert Dürr     if( mpNSWindow )
1719cdf0e10cSrcweir     {
1720bde8a4bdSHerbert Dürr         [mpNSWindow setOpaque: YES];
1721bde8a4bdSHerbert Dürr         [mpNSWindow invalidateShadow];
1722cdf0e10cSrcweir     }
1723cdf0e10cSrcweir }
1724cdf0e10cSrcweir 
BeginSetClipRegion(sal_uLong nRects)1725cdf0e10cSrcweir void AquaSalFrame::BeginSetClipRegion( sal_uLong nRects )
1726cdf0e10cSrcweir {
1727bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1728cdf0e10cSrcweir     {
1729cdf0e10cSrcweir         return;
1730cdf0e10cSrcweir     }
1731cdf0e10cSrcweir 
1732cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1733cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir     // release old path
1736cdf0e10cSrcweir     if( mrClippingPath )
1737cdf0e10cSrcweir     {
1738cdf0e10cSrcweir         CGPathRelease( mrClippingPath );
1739cdf0e10cSrcweir         mrClippingPath = NULL;
1740cdf0e10cSrcweir     }
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir     if( maClippingRects.size() > SAL_CLIPRECT_COUNT && nRects < maClippingRects.size() )
1743cdf0e10cSrcweir     {
1744cdf0e10cSrcweir         std::vector<CGRect> aEmptyVec;
1745cdf0e10cSrcweir         maClippingRects.swap( aEmptyVec );
1746cdf0e10cSrcweir     }
1747cdf0e10cSrcweir     maClippingRects.clear();
1748cdf0e10cSrcweir     maClippingRects.reserve( nRects );
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir 
UnionClipRegion(long nX,long nY,long nWidth,long nHeight)1751cdf0e10cSrcweir void AquaSalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
1752cdf0e10cSrcweir {
1753cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1754cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir     if( nWidth && nHeight )
1757cdf0e10cSrcweir     {
1758cd426cceSHerbert Dürr         NSRect aRect = NSMakeRect( nX, nY, nWidth, nHeight);
1759cdf0e10cSrcweir         VCLToCocoa( aRect, false );
1760cdf0e10cSrcweir         maClippingRects.push_back( CGRectMake(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height) );
1761cdf0e10cSrcweir     }
1762cdf0e10cSrcweir }
1763cdf0e10cSrcweir 
EndSetClipRegion()1764cdf0e10cSrcweir void AquaSalFrame::EndSetClipRegion()
1765cdf0e10cSrcweir {
1766bde8a4bdSHerbert Dürr     if ( !mpNSWindow )
1767cdf0e10cSrcweir     {
1768cdf0e10cSrcweir         return;
1769cdf0e10cSrcweir     }
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir     // #i113170# may not be the main thread if called from UNO API
1772cdf0e10cSrcweir     SalData::ensureThreadAutoreleasePool();
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir     if( ! maClippingRects.empty() )
1775cdf0e10cSrcweir     {
1776cdf0e10cSrcweir         mrClippingPath = CGPathCreateMutable();
1777cdf0e10cSrcweir         CGPathAddRects( mrClippingPath, NULL, &maClippingRects[0], maClippingRects.size() );
1778cdf0e10cSrcweir     }
1779bde8a4bdSHerbert Dürr     if( mpNSView && mbShown )
1780bde8a4bdSHerbert Dürr         [mpNSView setNeedsDisplay: YES];
1781bde8a4bdSHerbert Dürr     if( mpNSWindow )
1782cdf0e10cSrcweir     {
1783bde8a4bdSHerbert Dürr         [mpNSWindow setOpaque: (mrClippingPath != NULL) ? NO : YES];
1784bde8a4bdSHerbert Dürr         [mpNSWindow setBackgroundColor: [NSColor clearColor]];
1785cdf0e10cSrcweir         // shadow is invalidated when view gets drawn again
1786cdf0e10cSrcweir     }
1787cdf0e10cSrcweir }
1788cdf0e10cSrcweir 
1789