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 "aqua/saldata.hxx"
28cdf0e10cSrcweir #include "aqua/salnsmenu.h"
29cdf0e10cSrcweir #include "aqua/salinst.h"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #import "apple_remote/RemoteMainController.h"
32cdf0e10cSrcweir
33cdf0e10cSrcweir oslThreadKey SalData::s_aAutoReleaseKey = 0;
34cdf0e10cSrcweir
releasePool(void * pPool)35cdf0e10cSrcweir static void SAL_CALL releasePool( void* pPool )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir if( pPool )
38cdf0e10cSrcweir [(NSAutoreleasePool*)pPool release];
39cdf0e10cSrcweir }
40cdf0e10cSrcweir
SalData()41cdf0e10cSrcweir SalData::SalData()
42cdf0e10cSrcweir :
43cdf0e10cSrcweir mpTimerProc( NULL ),
44cdf0e10cSrcweir mpFirstInstance( NULL ),
45cdf0e10cSrcweir mpFirstObject( NULL ),
46cdf0e10cSrcweir mpFirstVD( NULL ),
47cdf0e10cSrcweir mpFirstPrinter( NULL ),
48cdf0e10cSrcweir mpFontList( NULL ),
49cdf0e10cSrcweir mpStatusItem( nil ),
50cdf0e10cSrcweir mxRGBSpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB) ),
51cdf0e10cSrcweir mxGraySpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) ),
52cdf0e10cSrcweir mxP50Space( NULL ),
53cdf0e10cSrcweir mxP50Pattern( NULL ),
54cdf0e10cSrcweir maCursors( POINTER_COUNT, INVALID_CURSOR_PTR ),
55cdf0e10cSrcweir mbIsScrollbarDoubleMax( false ),
56245318c3SHerbert Dürr mnSystemVersion( OSX_VER_LION ),
57*dbfe0a54SHerbert Dürr mpAppleRemoteMainController( NULL ),
58cdf0e10cSrcweir mpDockIconClickHandler( nil ),
59cdf0e10cSrcweir mnDPIX( 0 ),
60cdf0e10cSrcweir mnDPIY( 0 )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir if( s_aAutoReleaseKey == 0 )
63cdf0e10cSrcweir s_aAutoReleaseKey = osl_createThreadKey( releasePool );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
~SalData()66cdf0e10cSrcweir SalData::~SalData()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir CGPatternRelease( mxP50Pattern );
69cdf0e10cSrcweir CGColorSpaceRelease( mxP50Space );
70cdf0e10cSrcweir CGColorSpaceRelease( mxRGBSpace );
71cdf0e10cSrcweir CGColorSpaceRelease( mxGraySpace );
72cdf0e10cSrcweir for( unsigned int i = 0; i < maCursors.size(); i++ )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir NSCursor* pCurs = maCursors[i];
75cdf0e10cSrcweir if( pCurs && pCurs != INVALID_CURSOR_PTR )
76cdf0e10cSrcweir [pCurs release];
77cdf0e10cSrcweir }
78cdf0e10cSrcweir if( s_aAutoReleaseKey )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir // release the last pool
81cdf0e10cSrcweir NSAutoreleasePool* pPool = nil;
82cdf0e10cSrcweir pPool = reinterpret_cast<NSAutoreleasePool*>( osl_getThreadKeyData( s_aAutoReleaseKey ) );
83cdf0e10cSrcweir if( pPool )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir osl_setThreadKeyData( s_aAutoReleaseKey, NULL );
86cdf0e10cSrcweir [pPool release];
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir osl_destroyThreadKey( s_aAutoReleaseKey );
90cdf0e10cSrcweir s_aAutoReleaseKey = 0;
91cdf0e10cSrcweir }
92*dbfe0a54SHerbert Dürr if ( mpAppleRemoteMainController )
93*dbfe0a54SHerbert Dürr [mpAppleRemoteMainController release];
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
ensureThreadAutoreleasePool()96cdf0e10cSrcweir void SalData::ensureThreadAutoreleasePool()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir NSAutoreleasePool* pPool = nil;
99cdf0e10cSrcweir if( s_aAutoReleaseKey )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir pPool = reinterpret_cast<NSAutoreleasePool*>( osl_getThreadKeyData( s_aAutoReleaseKey ) );
102cdf0e10cSrcweir if( ! pPool )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir pPool = [[NSAutoreleasePool alloc] init];
105cdf0e10cSrcweir osl_setThreadKeyData( s_aAutoReleaseKey, pPool );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir else
109cdf0e10cSrcweir {
110cdf0e10cSrcweir DBG_ERROR( "no autorelease key" );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
drainThreadAutoreleasePool()114cdf0e10cSrcweir void SalData::drainThreadAutoreleasePool()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir NSAutoreleasePool* pPool = nil;
117cdf0e10cSrcweir if( s_aAutoReleaseKey )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir pPool = reinterpret_cast<NSAutoreleasePool*>( osl_getThreadKeyData( s_aAutoReleaseKey ) );
120cdf0e10cSrcweir if( pPool )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir // osl_setThreadKeyData( s_aAutoReleaseKey, NULL );
123cdf0e10cSrcweir // [pPool release];
124cdf0e10cSrcweir [pPool drain];
125cdf0e10cSrcweir }
126cdf0e10cSrcweir else
127cdf0e10cSrcweir {
128cdf0e10cSrcweir pPool = [[NSAutoreleasePool alloc] init];
129cdf0e10cSrcweir osl_setThreadKeyData( s_aAutoReleaseKey, pPool );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir else
133cdf0e10cSrcweir {
134cdf0e10cSrcweir DBG_ERROR( "no autorelease key" );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir }
137cdf0e10cSrcweir
138cdf0e10cSrcweir
139cdf0e10cSrcweir struct curs_ent
140cdf0e10cSrcweir {
141cdf0e10cSrcweir const char* pBaseName;
142cdf0e10cSrcweir const NSPoint aHotSpot;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir const aCursorTab[ POINTER_COUNT ] =
145cdf0e10cSrcweir {
146cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_ARROW
147cdf0e10cSrcweir { "nullptr", { 16, 16 } }, //POINTER_NULL
148cdf0e10cSrcweir { "hourglass", { 15, 15 } }, //POINTER_WAIT
149cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_TEXT
150cdf0e10cSrcweir { "help", { 0, 0 } }, //POINTER_HELP
151cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_CROSS
152cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_MOVE
153cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_NSIZE
154cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_SSIZE
155cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_WSIZE
156cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_ESIZE
157cdf0e10cSrcweir { "nwsesize", { 15, 15 } }, //POINTER_NWSIZE
158cdf0e10cSrcweir { "neswsize", { 15, 15 } }, //POINTER_NESIZE
159cdf0e10cSrcweir { "neswsize", { 15, 15 } }, //POINTER_SWSIZE
160cdf0e10cSrcweir { "nwsesize", { 15, 15 } }, //POINTER_SESIZE
161cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_WINDOW_NSIZE
162cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_WINDOW_SSIZE
163cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_WINDOW_WSIZE
164cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_WINDOW_ESIZE
165cdf0e10cSrcweir { "nwsesize", { 15, 15 } }, //POINTER_WINDOW_NWSIZE
166cdf0e10cSrcweir { "neswsize", { 15, 15 } }, //POINTER_WINDOW_NESIZE
167cdf0e10cSrcweir { "neswsize", { 15, 15 } }, //POINTER_WINDOW_SWSIZE
168cdf0e10cSrcweir { "nwsesize", { 15, 15 } }, //POINTER_WINDOW_SESIZE
169cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_HSPLIT
170cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_VSPLIT
171cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_HSIZEBAR
172cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_VSIZEBAR
173cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_HAND
174cdf0e10cSrcweir { NULL, { 0, 0 } }, //POINTER_REFHAND
175cdf0e10cSrcweir { "pen", { 3, 27 } }, //POINTER_PEN
176cdf0e10cSrcweir { "magnify", { 12, 13 } }, //POINTER_MAGNIFY
177cdf0e10cSrcweir { "fill", { 10, 22 } }, //POINTER_FILL
178cdf0e10cSrcweir { "rotate", { 15, 15 } }, //POINTER_ROTATE
179cdf0e10cSrcweir { "hshear", { 15, 15 } }, //POINTER_HSHEAR
180cdf0e10cSrcweir { "vshear", { 15, 15 } }, //POINTER_VSHEAR
181cdf0e10cSrcweir { "mirror", { 14, 12 } }, //POINTER_MIRROR
182cdf0e10cSrcweir { "crook", { 15, 14 } }, //POINTER_CROOK
183cdf0e10cSrcweir { "crop", { 9, 9 } }, //POINTER_CROP
184cdf0e10cSrcweir { "movept", { 0, 0 } }, //POINTER_MOVEPOINT
185cdf0e10cSrcweir { "movebw", { 0, 0 } }, //POINTER_MOVEBEZIERWEIGHT
186cdf0e10cSrcweir { "movedata", { 0, 0 } }, //POINTER_MOVEDATA
187cdf0e10cSrcweir { "copydata", { 0, 0 } }, //POINTER_COPYDATA
188cdf0e10cSrcweir { "linkdata", { 0, 0 } }, //POINTER_LINKDATA
189cdf0e10cSrcweir { "movedlnk", { 0, 0 } }, //POINTER_MOVEDATALINK
190cdf0e10cSrcweir { "copydlnk", { 0, 0 } }, //POINTER_COPYDATALINK
191cdf0e10cSrcweir { "movef", { 8, 8 } }, //POINTER_MOVEFILE
192cdf0e10cSrcweir { "copyf", { 8, 8 } }, //POINTER_COPYFILE
193cdf0e10cSrcweir { "linkf", { 8, 8 } }, //POINTER_LINKFILE
194cdf0e10cSrcweir { "moveflnk", { 8, 8 } }, //POINTER_MOVEFILELINK
195cdf0e10cSrcweir { "copyflnk", { 8, 8 } }, //POINTER_COPYFILELINK
196cdf0e10cSrcweir { "movef2", { 7, 8 } }, //POINTER_MOVEFILES
197cdf0e10cSrcweir { "copyf2", { 7, 8 } }, //POINTER_COPYFILES
198cdf0e10cSrcweir { "notallow", { 15, 15 } }, //POINTER_NOTALLOWED
199cdf0e10cSrcweir { "dline", { 8, 8 } }, //POINTER_DRAW_LINE
200cdf0e10cSrcweir { "drect", { 8, 8 } }, //POINTER_DRAW_RECT
201cdf0e10cSrcweir { "dpolygon", { 8, 8 } }, //POINTER_DRAW_POLYGON
202cdf0e10cSrcweir { "dbezier", { 8, 8 } }, //POINTER_DRAW_BEZIER
203cdf0e10cSrcweir { "darc", { 8, 8 } }, //POINTER_DRAW_ARC
204cdf0e10cSrcweir { "dpie", { 8, 8 } }, //POINTER_DRAW_PIE
205cdf0e10cSrcweir { "dcirccut", { 8, 8 } }, //POINTER_DRAW_CIRCLECUT
206cdf0e10cSrcweir { "dellipse", { 8, 8 } }, //POINTER_DRAW_ELLIPSE
207cdf0e10cSrcweir { "dfree", { 8, 8 } }, //POINTER_DRAW_FREEHAND
208cdf0e10cSrcweir { "dconnect", { 8, 8 } }, //POINTER_DRAW_CONNECT
209cdf0e10cSrcweir { "dtext", { 8, 8 } }, //POINTER_DRAW_TEXT
210cdf0e10cSrcweir { "dcapt", { 8, 8 } }, //POINTER_DRAW_CAPTION
211cdf0e10cSrcweir { "chart", { 15, 16 } }, //POINTER_CHART
212cdf0e10cSrcweir { "detectiv", { 12, 13 } }, //POINTER_DETECTIVE
213cdf0e10cSrcweir { "pivotcol", { 7, 5 } }, //POINTER_PIVOT_COL
214cdf0e10cSrcweir { "pivotrow", { 8, 7 } }, //POINTER_PIVOT_ROW
215cdf0e10cSrcweir { "pivotfld", { 8, 7 } }, //POINTER_PIVOT_FIELD
216cdf0e10cSrcweir { "chain", { 0, 2 } }, //POINTER_CHAIN
217cdf0e10cSrcweir { "chainnot", { 2, 2 } }, //POINTER_CHAIN_NOTALLOWED
218cdf0e10cSrcweir { "timemove", { 16, 16 } }, //POINTER_TIMEEVENT_MOVE
219cdf0e10cSrcweir { "timesize", { 16, 17 } }, //POINTER_TIMEEVENT_SIZE
220cdf0e10cSrcweir { "asn", { 16, 12 } }, //POINTER_AUTOSCROLL_N
221cdf0e10cSrcweir { "ass", { 15, 19 } }, //POINTER_AUTOSCROLL_S
222cdf0e10cSrcweir { "asw", { 12, 15 } }, //POINTER_AUTOSCROLL_W
223cdf0e10cSrcweir { "ase", { 19, 16 } }, //POINTER_AUTOSCROLL_E
224cdf0e10cSrcweir { "asnw", { 10, 10 } }, //POINTER_AUTOSCROLL_NW
225cdf0e10cSrcweir { "asne", { 21, 10 } }, //POINTER_AUTOSCROLL_NE
226cdf0e10cSrcweir { "assw", { 21, 21 } }, //POINTER_AUTOSCROLL_SW
227cdf0e10cSrcweir { "asse", { 21, 21 } }, //POINTER_AUTOSCROLL_SE
228cdf0e10cSrcweir { "asns", { 15, 15 } }, //POINTER_AUTOSCROLL_NS
229cdf0e10cSrcweir { "aswe", { 15, 15 } }, //POINTER_AUTOSCROLL_WE
230cdf0e10cSrcweir { "asnswe", { 15, 15 } }, //POINTER_AUTOSCROLL_NSWE
231cdf0e10cSrcweir { "airbrush", { 5, 22 } }, //POINTER_AIRBRUSH
232cdf0e10cSrcweir { "vtext", { 15, 15 } }, //POINTER_TEXT_VERTICAL
233cdf0e10cSrcweir { "pivotdel", { 18, 15 } }, //POINTER_PIVOT_DELETE
234cdf0e10cSrcweir { "tblsels", { 15, 30 } }, //POINTER_TAB_SELECT_S
235cdf0e10cSrcweir { "tblsele", { 30, 16 } }, //POINTER_TAB_SELECT_E
236cdf0e10cSrcweir { "tblselse", { 30, 30 } }, //POINTER_TAB_SELECT_SE
237cdf0e10cSrcweir { "tblselw", { 1, 16 } }, //POINTER_TAB_SELECT_W
238cdf0e10cSrcweir { "tblselsw", { 1, 30 } }, //POINTER_TAB_SELECT_SW
239cdf0e10cSrcweir { "pntbrsh", { 9, 16 } } //POINTER_PAINTBRUSH
240cdf0e10cSrcweir };
241cdf0e10cSrcweir
getCursor(PointerStyle i_eStyle)242cdf0e10cSrcweir NSCursor* SalData::getCursor( PointerStyle i_eStyle )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir if( i_eStyle >= POINTER_COUNT )
245cdf0e10cSrcweir return nil;
246cdf0e10cSrcweir
247cdf0e10cSrcweir NSCursor* pCurs = maCursors[ i_eStyle ];
248cdf0e10cSrcweir if( pCurs == INVALID_CURSOR_PTR )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir pCurs = nil;
251cdf0e10cSrcweir if( aCursorTab[ i_eStyle ].pBaseName )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir NSPoint aHotSpot = aCursorTab[ i_eStyle ].aHotSpot;
254cdf0e10cSrcweir CFStringRef pCursorName =
255cdf0e10cSrcweir CFStringCreateWithCStringNoCopy(
256cdf0e10cSrcweir kCFAllocatorDefault,
257cdf0e10cSrcweir aCursorTab[ i_eStyle ].pBaseName,
258cdf0e10cSrcweir kCFStringEncodingASCII,
259cdf0e10cSrcweir kCFAllocatorNull );
260cdf0e10cSrcweir CFBundleRef hMain = CFBundleGetMainBundle();
261cdf0e10cSrcweir CFURLRef hURL = CFBundleCopyResourceURL( hMain, pCursorName, CFSTR("png"), CFSTR("cursors") );
262cdf0e10cSrcweir if( hURL )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir pCurs = [[NSCursor alloc] initWithImage: [[NSImage alloc] initWithContentsOfURL: (NSURL*)hURL] hotSpot: aHotSpot];
265cdf0e10cSrcweir CFRelease( hURL );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir CFRelease( pCursorName );
268cdf0e10cSrcweir }
269cdf0e10cSrcweir maCursors[ i_eStyle ] = pCurs;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir return pCurs;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
getStatusItem()274cdf0e10cSrcweir NSStatusItem* SalData::getStatusItem()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir SalData* pData = GetSalData();
277cdf0e10cSrcweir if( ! pData->mpStatusItem )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir NSStatusBar* pStatBar =[NSStatusBar systemStatusBar];
280cdf0e10cSrcweir if( pStatBar )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir pData->mpStatusItem = [pStatBar statusItemWithLength: NSVariableStatusItemLength];
283cdf0e10cSrcweir [pData->mpStatusItem retain];
284cdf0e10cSrcweir OOStatusItemView* pView = [[OOStatusItemView alloc] init];
285cdf0e10cSrcweir [pData->mpStatusItem setView: pView ];
286cdf0e10cSrcweir [pView display];
287cdf0e10cSrcweir }
288cdf0e10cSrcweir }
289cdf0e10cSrcweir return pData->mpStatusItem;
290cdf0e10cSrcweir }
291