Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / osx / saldata.cxx
blob7008011d4df8bb9a2ee62996c616bf654d56fcf6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include "osx/saldata.hxx"
23 #include "osx/salnsmenu.h"
24 #include "osx/salinst.h"
25 #include "o3tl/enumarray.hxx"
27 #import "apple_remote/RemoteMainController.h"
29 oslThreadKey SalData::s_aAutoReleaseKey = 0;
31 static void SAL_CALL releasePool( void* pPool )
33 if( pPool )
34 [static_cast<NSAutoreleasePool*>(pPool) release];
37 SalData::SalData()
39 mpTimerProc( NULL ),
40 mpFirstInstance( NULL ),
41 mpFirstObject( NULL ),
42 mpFirstVD( NULL ),
43 mpFirstPrinter( NULL ),
44 mpFontList( NULL ),
45 mpStatusItem( nil ),
46 mxRGBSpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB) ),
47 mxGraySpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) ),
48 maCursors(),
49 mbIsScrollbarDoubleMax( false ),
50 #if !HAVE_FEATURE_MACOSX_SANDBOX
51 mpAppleRemoteMainController( NULL ),
52 #endif
53 mpDockIconClickHandler( nil ),
54 mnDPIX( 0 ),
55 mnDPIY( 0 )
57 maCursors.fill( INVALID_CURSOR_PTR );
58 if( s_aAutoReleaseKey == 0 )
59 s_aAutoReleaseKey = osl_createThreadKey( releasePool );
62 SalData::~SalData()
64 CGColorSpaceRelease( mxRGBSpace );
65 CGColorSpaceRelease( mxGraySpace );
66 for( NSCursor* pCurs : maCursors )
68 if( pCurs && pCurs != INVALID_CURSOR_PTR )
69 [pCurs release];
71 if( s_aAutoReleaseKey )
73 // release the last pool
74 NSAutoreleasePool* pPool = nil;
75 pPool = reinterpret_cast<NSAutoreleasePool*>( osl_getThreadKeyData( s_aAutoReleaseKey ) );
76 if( pPool )
78 osl_setThreadKeyData( s_aAutoReleaseKey, NULL );
79 [pPool release];
82 osl_destroyThreadKey( s_aAutoReleaseKey );
83 s_aAutoReleaseKey = 0;
85 #if !HAVE_FEATURE_MACOSX_SANDBOX
86 if ( mpAppleRemoteMainController )
87 [mpAppleRemoteMainController release];
88 #endif
91 void SalData::ensureThreadAutoreleasePool()
93 NSAutoreleasePool* pPool = nil;
94 if( s_aAutoReleaseKey )
96 pPool = reinterpret_cast<NSAutoreleasePool*>( osl_getThreadKeyData( s_aAutoReleaseKey ) );
97 if( ! pPool )
99 pPool = [[NSAutoreleasePool alloc] init];
100 osl_setThreadKeyData( s_aAutoReleaseKey, pPool );
103 else
105 OSL_FAIL( "no autorelease key" );
109 typedef struct
111 const char* pBaseName;
112 const NSPoint aHotSpot;
113 } curs_ent;
115 const o3tl::enumarray<PointerStyle, curs_ent> aCursorTab =
117 curs_ent{ NULL, { 0, 0 } }, //PointerStyle::Arrow
118 { "nullptr", { 16, 16 } }, //PointerStyle::Null
119 { "hourglass", { 15, 15 } }, //PointerStyle::Wait
120 { NULL, { 0, 0 } }, //PointerStyle::Text
121 { "help", { 0, 0 } }, //PointerStyle::Help
122 { NULL, { 0, 0 } }, //PointerStyle::Cross
123 { NULL, { 0, 0 } }, //PointerStyle::Move
124 { NULL, { 0, 0 } }, //PointerStyle::NSize
125 { NULL, { 0, 0 } }, //PointerStyle::SSize
126 { NULL, { 0, 0 } }, //PointerStyle::WSize
127 { NULL, { 0, 0 } }, //PointerStyle::ESize
128 { "nwsesize", { 15, 15 } }, //PointerStyle::NWSize
129 { "neswsize", { 15, 15 } }, //PointerStyle::NESize
130 { "neswsize", { 15, 15 } }, //PointerStyle::SWSize
131 { "nwsesize", { 15, 15 } }, //PointerStyle::SESize
132 { NULL, { 0, 0 } }, //PointerStyle::WindowNSize
133 { NULL, { 0, 0 } }, //PointerStyle::WindowSSize
134 { NULL, { 0, 0 } }, //PointerStyle::WindowWSize
135 { NULL, { 0, 0 } }, //PointerStyle::WindowESize
136 { "nwsesize", { 15, 15 } }, //PointerStyle::WindowNWSize
137 { "neswsize", { 15, 15 } }, //PointerStyle::WindowNESize
138 { "neswsize", { 15, 15 } }, //PointerStyle::WindowSWSize
139 { "nwsesize", { 15, 15 } }, //PointerStyle::WindowSESize
140 { NULL, { 0, 0 } }, //PointerStyle::HSplit
141 { NULL, { 0, 0 } }, //PointerStyle::VSplit
142 { NULL, { 0, 0 } }, //PointerStyle::HSizeBar
143 { NULL, { 0, 0 } }, //PointerStyle::VSizeBar
144 { NULL, { 0, 0 } }, //PointerStyle::Hand
145 { NULL, { 0, 0 } }, //PointerStyle::RefHand
146 { "pen", { 3, 27 } }, //PointerStyle::Pen
147 { "magnify", { 12, 13 } }, //PointerStyle::Magnify
148 { "fill", { 10, 22 } }, //PointerStyle::Fill
149 { "rotate", { 15, 15 } }, //PointerStyle::Rotate
150 { "hshear", { 15, 15 } }, //PointerStyle::HShear
151 { "vshear", { 15, 15 } }, //PointerStyle::VShear
152 { "mirror", { 14, 12 } }, //PointerStyle::Mirror
153 { "crook", { 15, 14 } }, //PointerStyle::Crook
154 { "crop", { 9, 9 } }, //PointerStyle::Crop
155 { "movept", { 0, 0 } }, //PointerStyle::MovePoint
156 { "movebw", { 0, 0 } }, //PointerStyle::MoveBezierWeight
157 { "movedata", { 0, 0 } }, //PointerStyle::MoveData
158 { "copydata", { 0, 0 } }, //PointerStyle::CopyData
159 { "linkdata", { 0, 0 } }, //PointerStyle::LinkData
160 { "movedlnk", { 0, 0 } }, //PointerStyle::MoveDataLink
161 { "copydlnk", { 0, 0 } }, //PointerStyle::CopyDataLink
162 { "movef", { 8, 8 } }, //PointerStyle::MoveFile
163 { "copyf", { 8, 8 } }, //PointerStyle::CopyFile
164 { "linkf", { 8, 8 } }, //PointerStyle::LinkFile
165 { "moveflnk", { 8, 8 } }, //PointerStyle::MoveFileLink
166 { "copyflnk", { 8, 8 } }, //PointerStyle::CopyFileLink
167 { "movef2", { 7, 8 } }, //PointerStyle::MoveFiles
168 { "copyf2", { 7, 8 } }, //PointerStyle::CopyFiles
169 { "notallow", { 15, 15 } }, //PointerStyle::NotAllowed
170 { "dline", { 8, 8 } }, //PointerStyle::DrawLine
171 { "drect", { 8, 8 } }, //PointerStyle::DrawRect
172 { "dpolygon", { 8, 8 } }, //PointerStyle::DrawPolygon
173 { "dbezier", { 8, 8 } }, //PointerStyle::DrawBezier
174 { "darc", { 8, 8 } }, //PointerStyle::DrawArc
175 { "dpie", { 8, 8 } }, //PointerStyle::DrawPie
176 { "dcirccut", { 8, 8 } }, //PointerStyle::DrawCircleCut
177 { "dellipse", { 8, 8 } }, //PointerStyle::DrawEllipse
178 { "dfree", { 8, 8 } }, //PointerStyle::DrawFreehand
179 { "dconnect", { 8, 8 } }, //PointerStyle::DrawConnect
180 { "dtext", { 8, 8 } }, //PointerStyle::DrawText
181 { "dcapt", { 8, 8 } }, //PointerStyle::DrawCaption
182 { "chart", { 15, 16 } }, //PointerStyle::Chart
183 { "detectiv", { 12, 13 } }, //PointerStyle::Detective
184 { "pivotcol", { 7, 5 } }, //PointerStyle::PivotCol
185 { "pivotrow", { 8, 7 } }, //PointerStyle::PivotRow
186 { "pivotfld", { 8, 7 } }, //PointerStyle::PivotField
187 { "chain", { 0, 2 } }, //PointerStyle::Chain
188 { "chainnot", { 2, 2 } }, //PointerStyle::ChainNotAllowed
189 { "timemove", { 16, 16 } }, //PointerStyle::TimeEventMove
190 { "timesize", { 16, 17 } }, //PointerStyle::TimeEventSize
191 { "asn", { 16, 12 } }, //PointerStyle::AutoScrollN
192 { "ass", { 15, 19 } }, //PointerStyle::AutoScrollS
193 { "asw", { 12, 15 } }, //PointerStyle::AutoScrollW
194 { "ase", { 19, 16 } }, //PointerStyle::AutoScrollE
195 { "asnw", { 10, 10 } }, //PointerStyle::AutoScrollNW
196 { "asne", { 21, 10 } }, //PointerStyle::AutoScrollNE
197 { "assw", { 21, 21 } }, //PointerStyle::AutoScrollSW
198 { "asse", { 21, 21 } }, //PointerStyle::AutoScrollSE
199 { "asns", { 15, 15 } }, //PointerStyle::AutoScrollNS
200 { "aswe", { 15, 15 } }, //PointerStyle::AutoScrollWE
201 { "asnswe", { 15, 15 } }, //PointerStyle::AutoScrollNSWE
202 { "airbrush", { 5, 22 } }, //PointerStyle::Airbrush
203 { "vtext", { 15, 15 } }, //PointerStyle::TextVertical
204 { "pivotdel", { 18, 15 } }, //PointerStyle::PivotDelete
205 { "tblsels", { 15, 30 } }, //PointerStyle::TabSelectS
206 { "tblsele", { 30, 16 } }, //PointerStyle::TabSelectE
207 { "tblselse", { 30, 30 } }, //PointerStyle::TabSelectSE
208 { "tblselw", { 1, 16 } }, //PointerStyle::TabSelectW
209 { "tblselsw", { 1, 30 } }, //PointerStyle::TabSelectSW
210 { "pntbrsh", { 9, 16 } } //PointerStyle::Paintbrush
213 NSCursor* SalData::getCursor( PointerStyle i_eStyle )
215 NSCursor* pCurs = maCursors[ i_eStyle ];
216 if( pCurs == INVALID_CURSOR_PTR )
218 pCurs = nil;
219 if( aCursorTab[ i_eStyle ].pBaseName )
221 NSPoint aHotSpot = aCursorTab[ i_eStyle ].aHotSpot;
222 CFStringRef pCursorName =
223 CFStringCreateWithCStringNoCopy(
224 kCFAllocatorDefault,
225 aCursorTab[ i_eStyle ].pBaseName,
226 kCFStringEncodingASCII,
227 kCFAllocatorNull );
228 CFBundleRef hMain = CFBundleGetMainBundle();
229 CFURLRef hURL = CFBundleCopyResourceURL( hMain, pCursorName, CFSTR("png"), CFSTR("cursors") );
230 if( hURL )
232 pCurs = [[NSCursor alloc] initWithImage: [[NSImage alloc] initWithContentsOfURL: const_cast<NSURL*>(reinterpret_cast<NSURL const *>(hURL))] hotSpot: aHotSpot];
233 CFRelease( hURL );
235 CFRelease( pCursorName );
237 maCursors[ i_eStyle ] = pCurs;
239 return pCurs;
242 NSStatusItem* SalData::getStatusItem()
244 SalData* pData = GetSalData();
245 if( ! pData->mpStatusItem )
247 NSStatusBar* pStatBar =[NSStatusBar systemStatusBar];
248 if( pStatBar )
250 pData->mpStatusItem = [pStatBar statusItemWithLength: NSVariableStatusItemLength];
251 [pData->mpStatusItem retain];
252 OOStatusItemView* pView = [[OOStatusItemView alloc] init];
253 [pData->mpStatusItem setView: pView ];
254 [pView display];
257 return pData->mpStatusItem;
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */