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