1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
= nullptr;
31 static void SAL_CALL
releasePool( void* pPool
)
34 [static_cast<NSAutoreleasePool
*>(pPool
) release
];
39 mpTimerProc( nullptr ),
40 mpFirstInstance( nullptr ),
41 mpFirstObject( nullptr ),
43 mpFirstPrinter( nullptr ),
44 mpFontList( nullptr ),
46 mxRGBSpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB
) ),
47 mxGraySpace( CGColorSpaceCreateWithName(kCGColorSpaceGenericGray
) ),
49 mbIsScrollbarDoubleMax( false ),
50 #if !HAVE_FEATURE_MACOSX_SANDBOX
51 mpAppleRemoteMainController( nullptr ),
53 mpDockIconClickHandler( nil
),
57 maCursors
.fill( INVALID_CURSOR_PTR
);
58 if( s_aAutoReleaseKey
== nullptr )
59 s_aAutoReleaseKey
= osl_createThreadKey( releasePool
);
64 CGColorSpaceRelease( mxRGBSpace
);
65 CGColorSpaceRelease( mxGraySpace
);
66 for( NSCursor
* pCurs
: maCursors
)
68 if( pCurs
&& pCurs
!= INVALID_CURSOR_PTR
)
71 if( s_aAutoReleaseKey
)
73 // release the last pool
74 NSAutoreleasePool
* pPool
= reinterpret_cast<NSAutoreleasePool
*>( osl_getThreadKeyData( s_aAutoReleaseKey
) );
77 osl_setThreadKeyData( s_aAutoReleaseKey
, nullptr );
81 osl_destroyThreadKey( s_aAutoReleaseKey
);
82 s_aAutoReleaseKey
= nullptr;
84 #if !HAVE_FEATURE_MACOSX_SANDBOX
85 if ( mpAppleRemoteMainController
)
86 [mpAppleRemoteMainController release
];
90 void SalData::ensureThreadAutoreleasePool()
92 NSAutoreleasePool
* pPool
= nil
;
93 if( s_aAutoReleaseKey
)
95 pPool
= reinterpret_cast<NSAutoreleasePool
*>( osl_getThreadKeyData( s_aAutoReleaseKey
) );
98 pPool
= [[NSAutoreleasePool alloc
] init
];
99 osl_setThreadKeyData( s_aAutoReleaseKey
, pPool
);
104 OSL_FAIL( "no autorelease key" );
110 const char* pBaseName
;
111 const NSPoint aHotSpot
;
114 const o3tl::enumarray
<PointerStyle
, curs_ent
> aCursorTab
=
116 curs_ent
{ nullptr, { 0, 0 } }, //PointerStyle::Arrow
117 { "nullptr", { 16, 16 } }, //PointerStyle::Null
118 { "hourglass", { 15, 15 } }, //PointerStyle::Wait
119 { nullptr, { 0, 0 } }, //PointerStyle::Text
120 { "help", { 0, 0 } }, //PointerStyle::Help
121 { nullptr, { 0, 0 } }, //PointerStyle::Cross
122 { nullptr, { 0, 0 } }, //PointerStyle::Move
123 { nullptr, { 0, 0 } }, //PointerStyle::NSize
124 { nullptr, { 0, 0 } }, //PointerStyle::SSize
125 { nullptr, { 0, 0 } }, //PointerStyle::WSize
126 { nullptr, { 0, 0 } }, //PointerStyle::ESize
127 { "nwsesize", { 15, 15 } }, //PointerStyle::NWSize
128 { "neswsize", { 15, 15 } }, //PointerStyle::NESize
129 { "neswsize", { 15, 15 } }, //PointerStyle::SWSize
130 { "nwsesize", { 15, 15 } }, //PointerStyle::SESize
131 { nullptr, { 0, 0 } }, //PointerStyle::WindowNSize
132 { nullptr, { 0, 0 } }, //PointerStyle::WindowSSize
133 { nullptr, { 0, 0 } }, //PointerStyle::WindowWSize
134 { nullptr, { 0, 0 } }, //PointerStyle::WindowESize
135 { "nwsesize", { 15, 15 } }, //PointerStyle::WindowNWSize
136 { "neswsize", { 15, 15 } }, //PointerStyle::WindowNESize
137 { "neswsize", { 15, 15 } }, //PointerStyle::WindowSWSize
138 { "nwsesize", { 15, 15 } }, //PointerStyle::WindowSESize
139 { nullptr, { 0, 0 } }, //PointerStyle::HSplit
140 { nullptr, { 0, 0 } }, //PointerStyle::VSplit
141 { nullptr, { 0, 0 } }, //PointerStyle::HSizeBar
142 { nullptr, { 0, 0 } }, //PointerStyle::VSizeBar
143 { nullptr, { 0, 0 } }, //PointerStyle::Hand
144 { nullptr, { 0, 0 } }, //PointerStyle::RefHand
145 { "pen", { 3, 27 } }, //PointerStyle::Pen
146 { "magnify", { 12, 13 } }, //PointerStyle::Magnify
147 { "fill", { 10, 22 } }, //PointerStyle::Fill
148 { "rotate", { 15, 15 } }, //PointerStyle::Rotate
149 { "hshear", { 15, 15 } }, //PointerStyle::HShear
150 { "vshear", { 15, 15 } }, //PointerStyle::VShear
151 { "mirror", { 14, 12 } }, //PointerStyle::Mirror
152 { "crook", { 15, 14 } }, //PointerStyle::Crook
153 { "crop", { 9, 9 } }, //PointerStyle::Crop
154 { "movept", { 0, 0 } }, //PointerStyle::MovePoint
155 { "movebw", { 0, 0 } }, //PointerStyle::MoveBezierWeight
156 { "movedata", { 0, 0 } }, //PointerStyle::MoveData
157 { "copydata", { 0, 0 } }, //PointerStyle::CopyData
158 { "linkdata", { 0, 0 } }, //PointerStyle::LinkData
159 { "movedlnk", { 0, 0 } }, //PointerStyle::MoveDataLink
160 { "copydlnk", { 0, 0 } }, //PointerStyle::CopyDataLink
161 { "movef", { 8, 8 } }, //PointerStyle::MoveFile
162 { "copyf", { 8, 8 } }, //PointerStyle::CopyFile
163 { "linkf", { 8, 8 } }, //PointerStyle::LinkFile
164 { "moveflnk", { 8, 8 } }, //PointerStyle::MoveFileLink
165 { "copyflnk", { 8, 8 } }, //PointerStyle::CopyFileLink
166 { "movef2", { 7, 8 } }, //PointerStyle::MoveFiles
167 { "copyf2", { 7, 8 } }, //PointerStyle::CopyFiles
168 { "notallow", { 15, 15 } }, //PointerStyle::NotAllowed
169 { "dline", { 8, 8 } }, //PointerStyle::DrawLine
170 { "drect", { 8, 8 } }, //PointerStyle::DrawRect
171 { "dpolygon", { 8, 8 } }, //PointerStyle::DrawPolygon
172 { "dbezier", { 8, 8 } }, //PointerStyle::DrawBezier
173 { "darc", { 8, 8 } }, //PointerStyle::DrawArc
174 { "dpie", { 8, 8 } }, //PointerStyle::DrawPie
175 { "dcirccut", { 8, 8 } }, //PointerStyle::DrawCircleCut
176 { "dellipse", { 8, 8 } }, //PointerStyle::DrawEllipse
177 { "dfree", { 8, 8 } }, //PointerStyle::DrawFreehand
178 { "dconnect", { 8, 8 } }, //PointerStyle::DrawConnect
179 { "dtext", { 8, 8 } }, //PointerStyle::DrawText
180 { "dcapt", { 8, 8 } }, //PointerStyle::DrawCaption
181 { "chart", { 15, 16 } }, //PointerStyle::Chart
182 { "detectiv", { 12, 13 } }, //PointerStyle::Detective
183 { "pivotcol", { 7, 5 } }, //PointerStyle::PivotCol
184 { "pivotrow", { 8, 7 } }, //PointerStyle::PivotRow
185 { "pivotfld", { 8, 7 } }, //PointerStyle::PivotField
186 { "chain", { 0, 2 } }, //PointerStyle::Chain
187 { "chainnot", { 2, 2 } }, //PointerStyle::ChainNotAllowed
188 { "asn", { 16, 12 } }, //PointerStyle::AutoScrollN
189 { "ass", { 15, 19 } }, //PointerStyle::AutoScrollS
190 { "asw", { 12, 15 } }, //PointerStyle::AutoScrollW
191 { "ase", { 19, 16 } }, //PointerStyle::AutoScrollE
192 { "asnw", { 10, 10 } }, //PointerStyle::AutoScrollNW
193 { "asne", { 21, 10 } }, //PointerStyle::AutoScrollNE
194 { "assw", { 21, 21 } }, //PointerStyle::AutoScrollSW
195 { "asse", { 21, 21 } }, //PointerStyle::AutoScrollSE
196 { "asns", { 15, 15 } }, //PointerStyle::AutoScrollNS
197 { "aswe", { 15, 15 } }, //PointerStyle::AutoScrollWE
198 { "asnswe", { 15, 15 } }, //PointerStyle::AutoScrollNSWE
199 { "vtext", { 15, 15 } }, //PointerStyle::TextVertical
200 { "pivotdel", { 18, 15 } }, //PointerStyle::PivotDelete
201 { "tblsels", { 15, 30 } }, //PointerStyle::TabSelectS
202 { "tblsele", { 30, 16 } }, //PointerStyle::TabSelectE
203 { "tblselse", { 30, 30 } }, //PointerStyle::TabSelectSE
204 { "tblselw", { 1, 16 } }, //PointerStyle::TabSelectW
205 { "tblselsw", { 1, 30 } }, //PointerStyle::TabSelectSW
206 { "wshide", { 16, 16 } }, //PointerStyle::HideWhitespace
207 { "wsshow", { 16, 16 } } //PointerStyle::ShowWhitespace
210 NSCursor
* SalData::getCursor( PointerStyle i_eStyle
)
212 NSCursor
* pCurs
= maCursors
[ i_eStyle
];
213 if( pCurs
== INVALID_CURSOR_PTR
)
216 if( aCursorTab
[ i_eStyle
].pBaseName
)
218 NSPoint aHotSpot
= aCursorTab
[ i_eStyle
].aHotSpot
;
219 CFStringRef pCursorName
=
220 CFStringCreateWithCStringNoCopy(
222 aCursorTab
[ i_eStyle
].pBaseName
,
223 kCFStringEncodingASCII
,
225 CFBundleRef hMain
= CFBundleGetMainBundle();
226 CFURLRef hURL
= CFBundleCopyResourceURL( hMain
, pCursorName
, CFSTR("png"), CFSTR("cursors") );
229 pCurs
= [[NSCursor alloc
] initWithImage
: [[NSImage alloc
] initWithContentsOfURL
: const_cast<NSURL
*>(reinterpret_cast<NSURL
const *>(hURL
))] hotSpot
: aHotSpot
];
232 CFRelease( pCursorName
);
234 maCursors
[ i_eStyle
] = pCurs
;
239 NSStatusItem
* SalData::getStatusItem()
241 SalData
* pData
= GetSalData();
242 if( ! pData
->mpStatusItem
)
244 NSStatusBar
* pStatBar
=[NSStatusBar systemStatusBar
];
247 pData
->mpStatusItem
= [pStatBar statusItemWithLength
: NSVariableStatusItemLength
];
248 [pData
->mpStatusItem retain
];
249 OOStatusItemView
* pView
= [[OOStatusItemView alloc
] init
];
250 [pData
->mpStatusItem setView
: pView
];
254 return pData
->mpStatusItem
;
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */