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