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