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