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