]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fb5246be | 2 | // Name: src/mac/carbon/utils.cpp |
e9576ca5 | 3 | // Purpose: Various utilities |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
88a7a4e1 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/utils.h" |
88a7a4e1 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
670f9935 | 18 | #include "wx/app.h" |
1832043f WS |
19 | #if wxUSE_GUI |
20 | #include "wx/toplevel.h" | |
48a1108e | 21 | #include "wx/font.h" |
1832043f | 22 | #endif |
88a7a4e1 WS |
23 | #endif |
24 | ||
2bf2d09e | 25 | #include "wx/apptrait.h" |
b6ed2b86 VZ |
26 | |
27 | #if wxUSE_GUI | |
28 | #include "wx/mac/uma.h" | |
29 | #endif | |
e9576ca5 SC |
30 | |
31 | #include <ctype.h> | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | #include <stdarg.h> | |
37 | ||
a2b77260 | 38 | #include "MoreFilesX.h" |
518af45b | 39 | |
66a09d47 | 40 | #ifndef __DARWIN__ |
8638e69b DS |
41 | #include <Threads.h> |
42 | #include <Sound.h> | |
66a09d47 SC |
43 | #endif |
44 | ||
7d9bf1f1 | 45 | #if wxUSE_GUI |
29d91661 | 46 | #if TARGET_API_MAC_OSX |
8638e69b | 47 | #include <CoreServices/CoreServices.h> |
29d91661 | 48 | #else |
8638e69b DS |
49 | #include <DriverServices.h> |
50 | #include <Multiprocessing.h> | |
29d91661 SC |
51 | #endif |
52 | ||
768c6e8b | 53 | #ifdef __DARWIN__ |
8638e69b | 54 | #include <Carbon/Carbon.h> |
768c6e8b | 55 | #else |
8638e69b DS |
56 | #include <ATSUnicode.h> |
57 | #include <TextCommon.h> | |
58 | #include <TextEncodingConverter.h> | |
768c6e8b | 59 | #endif |
7d9bf1f1 | 60 | #endif // wxUSE_GUI |
427ff662 | 61 | |
8638e69b | 62 | #include "wx/mac/private.h" |
a434b43f VZ |
63 | |
64 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
6cce68ea | 65 | #if __MWERKS__ < 0x4100 || !defined(__DARWIN__) |
a434b43f VZ |
66 | #include <wtime.h> |
67 | #endif | |
6cce68ea | 68 | #endif |
a434b43f | 69 | |
c655557f | 70 | #if wxUSE_BASE |
659b3e8b VZ |
71 | |
72 | // our OS version is the same in non GUI and GUI cases | |
c655557f | 73 | wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) |
659b3e8b | 74 | { |
6cce68ea | 75 | long theSystem; |
6cce68ea | 76 | Gestalt(gestaltSystemVersion, &theSystem); |
8638e69b | 77 | |
c655557f | 78 | if ( majorVsn != NULL ) |
6cce68ea | 79 | *majorVsn = (theSystem >> 8); |
8638e69b | 80 | |
c655557f VZ |
81 | if ( minorVsn != NULL ) |
82 | *minorVsn = (theSystem & 0xFF); | |
83 | ||
8bb6b2c0 VZ |
84 | #if defined( __DARWIN__ ) |
85 | return wxOS_MAC_OSX_DARWIN; | |
659b3e8b | 86 | #else |
8bb6b2c0 | 87 | return wxOS_MAC_OS; |
659b3e8b VZ |
88 | #endif |
89 | } | |
90 | ||
e5a9c663 SC |
91 | // ---------------------------------------------------------------------------- |
92 | // debugging support | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
e2fccedf | 95 | #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) |
e5a9c663 SC |
96 | |
97 | // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... | |
98 | ||
99 | #ifndef __MetroNubUtils__ | |
100 | #include "MetroNubUtils.h" | |
101 | #endif | |
102 | ||
103 | #ifndef __GESTALT__ | |
104 | #include <Gestalt.h> | |
105 | #endif | |
106 | ||
107 | #if TARGET_API_MAC_CARBON | |
108 | ||
8638e69b | 109 | #include <CodeFragments.h> |
e5a9c663 | 110 | |
8638e69b | 111 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); |
e5a9c663 | 112 | |
8638e69b | 113 | ProcPtr gCallUniversalProc_Proc = NULL; |
e5a9c663 SC |
114 | |
115 | #endif | |
116 | ||
117 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
118 | ||
119 | static long fRunOnce = false; | |
120 | ||
e5a9c663 SC |
121 | |
122 | Boolean IsMetroNubInstalled() | |
123 | { | |
124 | if (!fRunOnce) | |
125 | { | |
126 | long result, value; | |
127 | ||
128 | fRunOnce = true; | |
129 | gMetroNubEntry = NULL; | |
130 | ||
131 | if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) | |
132 | { | |
8638e69b | 133 | // look for MetroNub's Gestalt selector |
e5a9c663 SC |
134 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) |
135 | { | |
8638e69b | 136 | #if TARGET_API_MAC_CARBON |
e5a9c663 SC |
137 | if (gCallUniversalProc_Proc == NULL) |
138 | { | |
139 | CFragConnectionID connectionID; | |
140 | Ptr mainAddress; | |
141 | Str255 errorString; | |
142 | ProcPtr symbolAddress; | |
143 | OSErr err; | |
144 | CFragSymbolClass symbolClass; | |
145 | ||
146 | symbolAddress = NULL; | |
147 | err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, | |
148 | &connectionID, &mainAddress, errorString); | |
149 | ||
150 | if (err != noErr) | |
151 | { | |
152 | gCallUniversalProc_Proc = NULL; | |
153 | goto end; | |
154 | } | |
155 | ||
156 | err = FindSymbol(connectionID, "\pCallUniversalProc", | |
157 | (Ptr *) &gCallUniversalProc_Proc, &symbolClass); | |
158 | ||
159 | if (err != noErr) | |
160 | { | |
161 | gCallUniversalProc_Proc = NULL; | |
162 | goto end; | |
163 | } | |
164 | } | |
8638e69b | 165 | #endif |
e5a9c663 SC |
166 | |
167 | { | |
168 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
169 | ||
8638e69b | 170 | // make sure the version of the API is compatible |
e5a9c663 SC |
171 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && |
172 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
8638e69b DS |
173 | { |
174 | // success! | |
88a7a4e1 | 175 | gMetroNubEntry = block; |
8638e69b | 176 | } |
e5a9c663 | 177 | } |
e5a9c663 SC |
178 | } |
179 | } | |
180 | } | |
181 | ||
182 | end: | |
183 | ||
184 | #if TARGET_API_MAC_CARBON | |
185 | return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); | |
186 | #else | |
187 | return (gMetroNubEntry != NULL); | |
188 | #endif | |
189 | } | |
190 | ||
e5a9c663 SC |
191 | Boolean IsMWDebuggerRunning() |
192 | { | |
193 | if (IsMetroNubInstalled()) | |
194 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
e5a9c663 | 195 | |
8638e69b DS |
196 | return false; |
197 | } | |
e5a9c663 SC |
198 | |
199 | Boolean AmIBeingMWDebugged() | |
200 | { | |
201 | if (IsMetroNubInstalled()) | |
202 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
8638e69b DS |
203 | |
204 | return false; | |
e5a9c663 SC |
205 | } |
206 | ||
207 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
208 | { | |
209 | return IsMWDebuggerRunning() && AmIBeingMWDebugged(); | |
210 | } | |
211 | ||
212 | #else | |
213 | ||
214 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
215 | { | |
216 | return false; | |
217 | } | |
218 | ||
219 | #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) | |
220 | ||
a434b43f | 221 | |
f5c6eb5c | 222 | #ifndef __DARWIN__ |
03e11df5 GD |
223 | // defined in unix/utilsunx.cpp for Mac OS X |
224 | ||
2f1ae414 SC |
225 | // get full hostname (with domain name if possible) |
226 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
227 | { | |
228 | return wxGetHostName(buf, maxSize); | |
229 | } | |
230 | ||
8638e69b DS |
231 | // Get user ID e.g. jacs |
232 | bool wxGetUserId(wxChar *buf, int maxSize) | |
233 | { | |
6cce68ea | 234 | return wxGetUserName( buf , maxSize ); |
8638e69b DS |
235 | } |
236 | ||
237 | const wxChar* wxGetHomeDir(wxString *pstr) | |
238 | { | |
6cce68ea SC |
239 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ); |
240 | return pstr->c_str(); | |
8638e69b DS |
241 | } |
242 | ||
2f1ae414 | 243 | // Get hostname only (without domain name) |
427ff662 | 244 | bool wxGetHostName(wxChar *buf, int maxSize) |
e9576ca5 | 245 | { |
e40298d5 | 246 | // Gets Chooser name of user by examining a System resource. |
6cce68ea | 247 | buf[0] = 0; |
e40298d5 JS |
248 | |
249 | const short kComputerNameID = -16413; | |
5be55d56 | 250 | |
6cce68ea | 251 | short oldResFile = CurResFile(); |
e40298d5 JS |
252 | UseResFile(0); |
253 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
254 | UseResFile(oldResFile); | |
255 | ||
256 | if (chooserName && *chooserName) | |
257 | { | |
6cce68ea SC |
258 | HLock( (Handle) chooserName ); |
259 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
260 | HUnlock( (Handle) chooserName ); | |
261 | ReleaseResource( (Handle) chooserName ); | |
262 | wxStrncpy( buf , name , maxSize - 1 ); | |
e40298d5 | 263 | } |
0a67a93b | 264 | |
9d8aca48 | 265 | return true; |
e9576ca5 SC |
266 | } |
267 | ||
a31a5f85 | 268 | // Get user name e.g. Stefan Csomor |
427ff662 | 269 | bool wxGetUserName(wxChar *buf, int maxSize) |
e9576ca5 | 270 | { |
e40298d5 | 271 | // Gets Chooser name of user by examining a System resource. |
6cce68ea | 272 | buf[0] = 0; |
e40298d5 JS |
273 | |
274 | const short kChooserNameID = -16096; | |
5be55d56 | 275 | |
6cce68ea | 276 | short oldResFile = CurResFile(); |
e40298d5 JS |
277 | UseResFile(0); |
278 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
279 | UseResFile(oldResFile); | |
280 | ||
281 | if (chooserName && *chooserName) | |
282 | { | |
6cce68ea SC |
283 | HLock( (Handle) chooserName ); |
284 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
285 | HUnlock( (Handle) chooserName ); | |
286 | ReleaseResource( (Handle) chooserName ); | |
287 | wxStrncpy( buf , name , maxSize - 1 ); | |
e40298d5 | 288 | } |
0a67a93b | 289 | |
9d8aca48 | 290 | return true; |
e9576ca5 SC |
291 | } |
292 | ||
e0f6b731 | 293 | int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags) |
e9576ca5 SC |
294 | { |
295 | // TODO | |
296 | return 0; | |
297 | } | |
298 | ||
5dbb17e2 SC |
299 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) |
300 | { | |
e40298d5 | 301 | // TODO : under classic there is no environement support, under X yes |
6cce68ea | 302 | return false; |
5dbb17e2 SC |
303 | } |
304 | ||
9d8aca48 | 305 | // set the env var name to the given value, return true on success |
5dbb17e2 SC |
306 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value) |
307 | { | |
e40298d5 | 308 | // TODO : under classic there is no environement support, under X yes |
6cce68ea | 309 | return false; |
5dbb17e2 SC |
310 | } |
311 | ||
e9576ca5 | 312 | // Execute a program in an Interactive Shell |
e9576ca5 SC |
313 | bool wxShell(const wxString& command) |
314 | { | |
315 | // TODO | |
9d8aca48 | 316 | return false; |
e9576ca5 SC |
317 | } |
318 | ||
5be55d56 | 319 | // Shutdown or reboot the PC |
f6ba47d9 VZ |
320 | bool wxShutdown(wxShutdownFlags wFlags) |
321 | { | |
322 | // TODO | |
9d8aca48 | 323 | return false; |
f6ba47d9 VZ |
324 | } |
325 | ||
e9576ca5 | 326 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) |
9d8aca48 | 327 | wxMemorySize wxGetFreeMemory() |
e9576ca5 | 328 | { |
6cce68ea | 329 | return (wxMemorySize)FreeMem(); |
0a67a93b SC |
330 | } |
331 | ||
7f7b52b4 SC |
332 | #ifndef __DARWIN__ |
333 | ||
334 | void wxMicroSleep(unsigned long microseconds) | |
0a67a93b | 335 | { |
9d8aca48 WS |
336 | AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); |
337 | MPDelayUntil( & wakeup); | |
7f7b52b4 SC |
338 | } |
339 | ||
340 | void wxMilliSleep(unsigned long milliseconds) | |
341 | { | |
9d8aca48 WS |
342 | AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); |
343 | MPDelayUntil( & wakeup); | |
e9576ca5 SC |
344 | } |
345 | ||
346 | void wxSleep(int nSecs) | |
347 | { | |
7f7b52b4 | 348 | wxMilliSleep(1000*nSecs); |
e9576ca5 SC |
349 | } |
350 | ||
7f7b52b4 SC |
351 | #endif |
352 | ||
e9576ca5 SC |
353 | // Consume all events until no more left |
354 | void wxFlushEvents() | |
355 | { | |
356 | } | |
357 | ||
f5c6eb5c | 358 | #endif // !__DARWIN__ |
e9576ca5 SC |
359 | |
360 | // Emit a beeeeeep | |
361 | void wxBell() | |
362 | { | |
0a67a93b | 363 | SysBeep(30); |
e9576ca5 SC |
364 | } |
365 | ||
29c99ad3 | 366 | |
b6ed2b86 VZ |
367 | #endif // wxUSE_BASE |
368 | ||
369 | #if wxUSE_GUI | |
536732e4 | 370 | |
8bb6b2c0 | 371 | wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const |
29c99ad3 | 372 | { |
8bb6b2c0 VZ |
373 | // We suppose that toolkit version is the same as OS version under Mac |
374 | wxGetOsVersion(verMaj, verMin); | |
8638e69b | 375 | |
8bb6b2c0 | 376 | return wxPORT_MAC; |
29c99ad3 VZ |
377 | } |
378 | ||
e9576ca5 SC |
379 | // Reading and writing resources (eg WIN.INI, .Xdefaults) |
380 | #if wxUSE_RESOURCES | |
381 | bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) | |
382 | { | |
383 | // TODO | |
9d8aca48 | 384 | return false; |
e9576ca5 SC |
385 | } |
386 | ||
387 | bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) | |
388 | { | |
427ff662 SC |
389 | wxString buf; |
390 | buf.Printf(wxT("%.4f"), value); | |
391 | ||
e40298d5 | 392 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
393 | } |
394 | ||
395 | bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) | |
396 | { | |
427ff662 SC |
397 | wxString buf; |
398 | buf.Printf(wxT("%ld"), value); | |
399 | ||
e40298d5 | 400 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
401 | } |
402 | ||
403 | bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) | |
404 | { | |
427ff662 SC |
405 | wxString buf; |
406 | buf.Printf(wxT("%d"), value); | |
407 | ||
e40298d5 | 408 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
409 | } |
410 | ||
411 | bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) | |
412 | { | |
413 | // TODO | |
9d8aca48 | 414 | return false; |
e9576ca5 SC |
415 | } |
416 | ||
417 | bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) | |
418 | { | |
e40298d5 JS |
419 | char *s = NULL; |
420 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
421 | if (succ) | |
422 | { | |
423 | *value = (float)strtod(s, NULL); | |
424 | delete[] s; | |
e40298d5 | 425 | } |
8638e69b DS |
426 | |
427 | return succ; | |
e9576ca5 SC |
428 | } |
429 | ||
430 | bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) | |
431 | { | |
e40298d5 JS |
432 | char *s = NULL; |
433 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
434 | if (succ) | |
435 | { | |
436 | *value = strtol(s, NULL, 10); | |
437 | delete[] s; | |
e40298d5 | 438 | } |
8638e69b DS |
439 | |
440 | return succ; | |
e9576ca5 SC |
441 | } |
442 | ||
443 | bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) | |
444 | { | |
e40298d5 JS |
445 | char *s = NULL; |
446 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
447 | if (succ) | |
448 | { | |
449 | *value = (int)strtol(s, NULL, 10); | |
450 | delete[] s; | |
e40298d5 | 451 | } |
8638e69b DS |
452 | |
453 | return succ; | |
e9576ca5 SC |
454 | } |
455 | #endif // wxUSE_RESOURCES | |
456 | ||
6b57b49a | 457 | int gs_wxBusyCursorCount = 0; |
6cce68ea SC |
458 | extern wxCursor gMacCurrentCursor; |
459 | wxCursor gMacStoredActiveCursor; | |
e9576ca5 SC |
460 | |
461 | // Set the cursor to the busy cursor for all windows | |
f516d986 | 462 | void wxBeginBusyCursor(const wxCursor *cursor) |
e9576ca5 | 463 | { |
e40298d5 JS |
464 | if (gs_wxBusyCursorCount++ == 0) |
465 | { | |
6cce68ea SC |
466 | gMacStoredActiveCursor = gMacCurrentCursor; |
467 | cursor->MacInstall(); | |
e40298d5 JS |
468 | } |
469 | //else: nothing to do, already set | |
e9576ca5 SC |
470 | } |
471 | ||
472 | // Restore cursor to normal | |
473 | void wxEndBusyCursor() | |
474 | { | |
6b57b49a | 475 | wxCHECK_RET( gs_wxBusyCursorCount > 0, |
e40298d5 | 476 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); |
5be55d56 | 477 | |
e40298d5 JS |
478 | if (--gs_wxBusyCursorCount == 0) |
479 | { | |
6cce68ea SC |
480 | gMacStoredActiveCursor.MacInstall(); |
481 | gMacStoredActiveCursor = wxNullCursor; | |
e40298d5 | 482 | } |
e9576ca5 SC |
483 | } |
484 | ||
9d8aca48 | 485 | // true if we're between the above two calls |
e9576ca5 SC |
486 | bool wxIsBusy() |
487 | { | |
e40298d5 | 488 | return (gs_wxBusyCursorCount > 0); |
ec5d7799 | 489 | } |
e9576ca5 | 490 | |
2dbc444a RD |
491 | #endif // wxUSE_GUI |
492 | ||
493 | #if wxUSE_BASE | |
494 | ||
17af82fb | 495 | wxString wxMacFindFolderNoSeparator( short vol, |
e40298d5 JS |
496 | OSType folderType, |
497 | Boolean createFolder) | |
2f1ae414 | 498 | { |
6cce68ea SC |
499 | FSRef fsRef; |
500 | wxString strDir; | |
5be55d56 | 501 | |
a2b77260 | 502 | if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr) |
17af82fb VZ |
503 | { |
504 | strDir = wxMacFSRefToPath( &fsRef ); | |
505 | } | |
a2b77260 | 506 | |
6cce68ea | 507 | return strDir; |
2f1ae414 SC |
508 | } |
509 | ||
17af82fb VZ |
510 | wxString wxMacFindFolder( short vol, |
511 | OSType folderType, | |
512 | Boolean createFolder) | |
513 | { | |
514 | return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH; | |
515 | } | |
516 | ||
2dbc444a RD |
517 | #endif // wxUSE_BASE |
518 | ||
519 | #if wxUSE_GUI | |
520 | ||
e9576ca5 SC |
521 | // Check whether this window wants to process messages, e.g. Stop button |
522 | // in long calculations. | |
523 | bool wxCheckForInterrupt(wxWindow *wnd) | |
524 | { | |
525 | // TODO | |
9d8aca48 | 526 | return false; |
e9576ca5 SC |
527 | } |
528 | ||
529 | void wxGetMousePosition( int* x, int* y ) | |
530 | { | |
6cce68ea | 531 | Point pt; |
ec5d7799 | 532 | |
6cce68ea SC |
533 | GetMouse( &pt ); |
534 | LocalToGlobal( &pt ); | |
535 | *x = pt.h; | |
536 | *y = pt.v; | |
e9576ca5 SC |
537 | }; |
538 | ||
9d8aca48 | 539 | // Return true if we have a colour display |
e9576ca5 SC |
540 | bool wxColourDisplay() |
541 | { | |
9d8aca48 | 542 | return true; |
e9576ca5 SC |
543 | } |
544 | ||
545 | // Returns depth of screen | |
546 | int wxDisplayDepth() | |
547 | { | |
6cce68ea | 548 | Rect globRect; |
e40298d5 JS |
549 | SetRect(&globRect, -32760, -32760, 32760, 32760); |
550 | GDHandle theMaxDevice; | |
2f1ae414 | 551 | |
e40298d5 JS |
552 | int theDepth = 8; |
553 | theMaxDevice = GetMaxDevice(&globRect); | |
8638e69b | 554 | if (theMaxDevice != NULL) |
e40298d5 | 555 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; |
ec5d7799 | 556 | |
6cce68ea | 557 | return theDepth; |
e9576ca5 SC |
558 | } |
559 | ||
560 | // Get size of display | |
561 | void wxDisplaySize(int *width, int *height) | |
562 | { | |
e40298d5 JS |
563 | BitMap screenBits; |
564 | GetQDGlobalsScreenBits( &screenBits ); | |
5be55d56 | 565 | |
8638e69b | 566 | if (width != NULL) |
6cce68ea | 567 | *width = screenBits.bounds.right - screenBits.bounds.left; |
8638e69b DS |
568 | |
569 | if (height != NULL) | |
6cce68ea | 570 | *height = screenBits.bounds.bottom - screenBits.bounds.top; |
e9576ca5 SC |
571 | } |
572 | ||
5fde6fcc GD |
573 | void wxDisplaySizeMM(int *width, int *height) |
574 | { | |
5b028d57 | 575 | wxDisplaySize(width, height); |
6cce68ea | 576 | // on mac 72 is fixed (at least now;-) |
5b028d57 | 577 | float cvPt2Mm = 25.4 / 72; |
e8ca7105 | 578 | |
8638e69b | 579 | if (width != NULL) |
e8ca7105 | 580 | *width = int( *width * cvPt2Mm ); |
8638e69b DS |
581 | |
582 | if (height != NULL) | |
e8ca7105 | 583 | *height = int( *height * cvPt2Mm ); |
5fde6fcc GD |
584 | } |
585 | ||
ec5d7799 RD |
586 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) |
587 | { | |
6cce68ea | 588 | Rect r; |
8638e69b | 589 | |
6cce68ea | 590 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ); |
ee658398 | 591 | if ( x ) |
6cce68ea | 592 | *x = r.left; |
ee658398 | 593 | if ( y ) |
6cce68ea | 594 | *y = r.top; |
ee658398 | 595 | if ( width ) |
6cce68ea | 596 | *width = r.right - r.left; |
ee658398 | 597 | if ( height ) |
6cce68ea | 598 | *height = r.bottom - r.top; |
ec5d7799 RD |
599 | } |
600 | ||
57591e0e JS |
601 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
602 | { | |
603 | return wxGenericFindWindowAtPoint(pt); | |
604 | } | |
5dbb17e2 | 605 | |
b6ed2b86 VZ |
606 | #endif // wxUSE_GUI |
607 | ||
608 | #if wxUSE_BASE | |
609 | ||
5dbb17e2 SC |
610 | wxString wxGetOsDescription() |
611 | { | |
6e73695c GD |
612 | #ifdef WXWIN_OS_DESCRIPTION |
613 | // use configure generated description if available | |
5f3f0f17 | 614 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); |
6e73695c | 615 | #else |
6cce68ea | 616 | return wxT("MacOS"); //TODO:define further |
6e73695c GD |
617 | #endif |
618 | } | |
619 | ||
b6ed2b86 VZ |
620 | #ifndef __DARWIN__ |
621 | wxChar *wxGetUserHome (const wxString& user) | |
622 | { | |
623 | // TODO | |
624 | return NULL; | |
625 | } | |
626 | ||
7ba7c4e6 | 627 | bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) |
b6ed2b86 VZ |
628 | { |
629 | if ( path.empty() ) | |
9d8aca48 | 630 | return false; |
b6ed2b86 | 631 | |
6cce68ea | 632 | wxString p = path; |
8638e69b | 633 | if (p[0u] == ':' ) |
6cce68ea | 634 | p = wxGetCwd() + p; |
b6ed2b86 | 635 | |
6cce68ea | 636 | int pos = p.Find(':'); |
8638e69b | 637 | if ( pos != wxNOT_FOUND ) |
6cce68ea | 638 | p = p.Mid(1,pos); |
b6ed2b86 | 639 | |
6cce68ea | 640 | p = p + wxT(":"); |
b6ed2b86 | 641 | |
6cce68ea | 642 | OSErr err = noErr; |
9d8aca48 | 643 | |
6cce68ea SC |
644 | FSRef fsRef; |
645 | err = wxMacPathToFSRef( p , &fsRef ); | |
a2b77260 SC |
646 | if ( noErr == err ) |
647 | { | |
6cce68ea SC |
648 | FSVolumeRefNum vRefNum; |
649 | err = FSGetVRefNum( &fsRef , &vRefNum ); | |
a2b77260 SC |
650 | if ( noErr == err ) |
651 | { | |
6cce68ea SC |
652 | UInt64 freeBytes , totalBytes; |
653 | err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ); | |
a2b77260 SC |
654 | if ( noErr == err ) |
655 | { | |
9d8aca48 | 656 | if ( pTotal ) |
6cce68ea | 657 | *pTotal = wxDiskspaceSize_t( totalBytes ); |
a2b77260 | 658 | if ( pFree ) |
6cce68ea | 659 | *pFree = wxDiskspaceSize_t( freeBytes ); |
a2b77260 SC |
660 | } |
661 | } | |
b6ed2b86 | 662 | } |
9d8aca48 | 663 | |
6cce68ea | 664 | return err == noErr; |
b6ed2b86 VZ |
665 | } |
666 | #endif // !__DARWIN__ | |
667 | ||
3d963f81 SC |
668 | //--------------------------------------------------------------------------- |
669 | // wxMac Specific utility functions | |
670 | //--------------------------------------------------------------------------- | |
671 | ||
5be55d56 | 672 | void wxMacStringToPascal( const wxString&from , StringPtr to ) |
427ff662 | 673 | { |
6cce68ea SC |
674 | wxCharBuffer buf = from.mb_str( wxConvLocal ); |
675 | int len = strlen(buf); | |
427ff662 SC |
676 | |
677 | if ( len > 255 ) | |
6cce68ea SC |
678 | len = 255; |
679 | to[0] = len; | |
680 | memcpy( (char*) &to[1] , buf , len ); | |
427ff662 SC |
681 | } |
682 | ||
5be55d56 | 683 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) |
427ff662 | 684 | { |
6cce68ea | 685 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ); |
427ff662 SC |
686 | } |
687 | ||
73280e05 SC |
688 | // ---------------------------------------------------------------------------- |
689 | // Common Event Support | |
690 | // ---------------------------------------------------------------------------- | |
691 | ||
6cce68ea | 692 | extern ProcessSerialNumber gAppProcess; |
73280e05 SC |
693 | |
694 | void wxMacWakeUp() | |
695 | { | |
6cce68ea SC |
696 | ProcessSerialNumber psn; |
697 | Boolean isSame; | |
698 | psn.highLongOfPSN = 0; | |
699 | psn.lowLongOfPSN = kCurrentProcess; | |
700 | SameProcess( &gAppProcess , &psn , &isSame ); | |
73280e05 SC |
701 | if ( isSame ) |
702 | { | |
703 | #if TARGET_CARBON | |
6cce68ea | 704 | OSStatus err = noErr; |
8638e69b | 705 | |
41ab357e SC |
706 | #if 0 |
707 | // lead sometimes to race conditions, although all calls used should be thread safe ... | |
6cce68ea | 708 | static wxMacCarbonEvent s_wakeupEvent; |
8dfef0c2 | 709 | if ( !s_wakeupEvent.IsValid() ) |
d6c69b17 | 710 | { |
8dfef0c2 | 711 | err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
6cce68ea | 712 | kEventAttributeNone ); |
d6c69b17 | 713 | } |
8dfef0c2 | 714 | if ( err == noErr ) |
73280e05 | 715 | { |
88a7a4e1 | 716 | |
8dfef0c2 | 717 | if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) ) |
6cce68ea SC |
718 | return; |
719 | s_wakeupEvent.SetCurrentTime(); | |
d6c69b17 | 720 | err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent, |
41ab357e | 721 | kEventPriorityHigh ); |
8dfef0c2 | 722 | } |
41ab357e | 723 | #else |
6cce68ea | 724 | wxMacCarbonEvent wakeupEvent; |
41ab357e | 725 | wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
6cce68ea | 726 | kEventAttributeNone ); |
41ab357e SC |
727 | err = PostEventToQueue(GetMainEventQueue(), wakeupEvent, |
728 | kEventPriorityHigh ); | |
729 | #endif | |
73280e05 | 730 | #else |
6cce68ea | 731 | PostEvent( nullEvent , 0 ); |
73280e05 SC |
732 | #endif |
733 | } | |
734 | else | |
735 | { | |
6cce68ea | 736 | WakeUpProcess( &gAppProcess ); |
73280e05 SC |
737 | } |
738 | } | |
739 | ||
d13ea1bd RD |
740 | #endif // wxUSE_BASE |
741 | ||
742 | #if wxUSE_GUI | |
743 | ||
1f1c8bd4 SC |
744 | // ---------------------------------------------------------------------------- |
745 | // Native Struct Conversions | |
746 | // ---------------------------------------------------------------------------- | |
747 | ||
fb5246be | 748 | void wxMacRectToNative( const wxRect *wx , Rect *n ) |
1f1c8bd4 | 749 | { |
6cce68ea SC |
750 | n->left = wx->x; |
751 | n->top = wx->y; | |
752 | n->right = wx->x + wx->width; | |
753 | n->bottom = wx->y + wx->height; | |
1f1c8bd4 SC |
754 | } |
755 | ||
fb5246be | 756 | void wxMacNativeToRect( const Rect *n , wxRect* wx ) |
1f1c8bd4 | 757 | { |
6cce68ea SC |
758 | wx->x = n->left; |
759 | wx->y = n->top; | |
760 | wx->width = n->right - n->left; | |
761 | wx->height = n->bottom - n->top; | |
1f1c8bd4 SC |
762 | } |
763 | ||
fb5246be | 764 | void wxMacPointToNative( const wxPoint* wx , Point *n ) |
1f1c8bd4 | 765 | { |
6cce68ea SC |
766 | n->h = wx->x; |
767 | n->v = wx->y; | |
1f1c8bd4 SC |
768 | } |
769 | ||
fb5246be | 770 | void wxMacNativeToPoint( const Point *n , wxPoint* wx ) |
1f1c8bd4 | 771 | { |
6cce68ea SC |
772 | wx->x = n->h; |
773 | wx->y = n->v; | |
1f1c8bd4 | 774 | } |
d13ea1bd | 775 | |
facd6764 SC |
776 | // ---------------------------------------------------------------------------- |
777 | // Carbon Event Support | |
778 | // ---------------------------------------------------------------------------- | |
779 | ||
facd6764 SC |
780 | OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) |
781 | { | |
6cce68ea | 782 | return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ); |
facd6764 SC |
783 | } |
784 | ||
21fd5529 | 785 | OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) |
facd6764 | 786 | { |
6cce68ea | 787 | return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ); |
facd6764 SC |
788 | } |
789 | ||
86d8b744 SC |
790 | // ---------------------------------------------------------------------------- |
791 | // Control Access Support | |
792 | // ---------------------------------------------------------------------------- | |
793 | ||
1f1c8bd4 | 794 | wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl ) |
9b89f11a | 795 | { |
6cce68ea SC |
796 | Init(); |
797 | m_peer = peer; | |
798 | m_isRootControl = isRootControl; | |
9b89f11a SC |
799 | } |
800 | ||
fb5246be | 801 | wxMacControl::wxMacControl( wxWindow* peer , ControlRef control ) |
9b89f11a | 802 | { |
6cce68ea SC |
803 | Init(); |
804 | m_peer = peer; | |
6cce68ea | 805 | m_controlRef = control; |
9b89f11a SC |
806 | } |
807 | ||
808 | wxMacControl::wxMacControl( wxWindow* peer , WXWidget control ) | |
809 | { | |
6cce68ea SC |
810 | Init(); |
811 | m_peer = peer; | |
6cce68ea | 812 | m_controlRef = (ControlRef) control; |
9b89f11a SC |
813 | } |
814 | ||
815 | wxMacControl::~wxMacControl() | |
816 | { | |
817 | } | |
818 | ||
819 | void wxMacControl::Init() | |
820 | { | |
6cce68ea SC |
821 | m_peer = NULL; |
822 | m_controlRef = NULL; | |
823 | m_needsFocusRect = false; | |
6cce68ea | 824 | m_isRootControl = false; |
9b89f11a SC |
825 | } |
826 | ||
5ca0d812 SC |
827 | void wxMacControl::Dispose() |
828 | { | |
6cce68ea SC |
829 | ::DisposeControl( m_controlRef ); |
830 | m_controlRef = NULL; | |
5ca0d812 SC |
831 | } |
832 | ||
9d8aca48 | 833 | void wxMacControl::SetReference( SInt32 data ) |
5ca0d812 | 834 | { |
6cce68ea | 835 | SetControlReference( m_controlRef , data ); |
5ca0d812 SC |
836 | } |
837 | ||
29d91661 | 838 | OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const |
86d8b744 | 839 | { |
6cce68ea | 840 | return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ); |
86d8b744 SC |
841 | } |
842 | ||
29d91661 | 843 | OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const |
86d8b744 | 844 | { |
6cce68ea | 845 | return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ); |
86d8b744 SC |
846 | } |
847 | ||
848 | OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) | |
849 | { | |
6cce68ea | 850 | return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ); |
86d8b744 SC |
851 | } |
852 | ||
8638e69b | 853 | OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) |
21fd5529 | 854 | { |
e996f509 | 855 | #if TARGET_API_MAC_OSX |
9d8aca48 | 856 | return SendEventToEventTargetWithOptions( event, |
8638e69b | 857 | HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); |
e996f509 | 858 | #else |
9d8aca48 | 859 | #pragma unused(inOptions) |
6cce68ea | 860 | return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ); |
e996f509 | 861 | #endif |
21fd5529 SC |
862 | } |
863 | ||
9d8aca48 | 864 | OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) |
21fd5529 | 865 | { |
6cce68ea | 866 | wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ); |
8638e69b | 867 | |
6cce68ea | 868 | event.SetParameter<HICommand>(kEventParamDirectObject,command); |
8638e69b | 869 | |
6cce68ea | 870 | return SendEvent( event , inOptions ); |
21fd5529 SC |
871 | } |
872 | ||
9d8aca48 | 873 | OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) |
21fd5529 | 874 | { |
6cce68ea | 875 | HICommand command; |
8638e69b | 876 | |
6cce68ea SC |
877 | memset( &command, 0 , sizeof(command) ); |
878 | command.commandID = commandID; | |
879 | return SendHICommand( command , inOptions ); | |
21fd5529 SC |
880 | } |
881 | ||
9d8aca48 | 882 | void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) |
21fd5529 | 883 | { |
6cce68ea | 884 | unsigned long finalTicks; |
8638e69b | 885 | |
6cce68ea SC |
886 | HiliteControl( m_controlRef , part ); |
887 | Delay( ticks , &finalTicks ); | |
888 | HiliteControl( m_controlRef , kControlNoPart ); | |
21fd5529 SC |
889 | } |
890 | ||
7f7b52b4 | 891 | SInt32 wxMacControl::GetValue() const |
9d8aca48 | 892 | { |
6cce68ea | 893 | return ::GetControl32BitValue( m_controlRef ); |
7f7b52b4 SC |
894 | } |
895 | ||
896 | SInt32 wxMacControl::GetMaximum() const | |
9d8aca48 | 897 | { |
6cce68ea | 898 | return ::GetControl32BitMaximum( m_controlRef ); |
7f7b52b4 SC |
899 | } |
900 | ||
901 | SInt32 wxMacControl::GetMinimum() const | |
9d8aca48 | 902 | { |
6cce68ea | 903 | return ::GetControl32BitMinimum( m_controlRef ); |
7f7b52b4 SC |
904 | } |
905 | ||
9d8aca48 WS |
906 | void wxMacControl::SetValue( SInt32 v ) |
907 | { | |
6cce68ea | 908 | ::SetControl32BitValue( m_controlRef , v ); |
7f7b52b4 SC |
909 | } |
910 | ||
9d8aca48 WS |
911 | void wxMacControl::SetMinimum( SInt32 v ) |
912 | { | |
6cce68ea | 913 | ::SetControl32BitMinimum( m_controlRef , v ); |
7f7b52b4 SC |
914 | } |
915 | ||
9d8aca48 WS |
916 | void wxMacControl::SetMaximum( SInt32 v ) |
917 | { | |
6cce68ea | 918 | ::SetControl32BitMaximum( m_controlRef , v ); |
7f7b52b4 SC |
919 | } |
920 | ||
921 | void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) | |
922 | { | |
6cce68ea SC |
923 | ::SetControl32BitMinimum( m_controlRef , minimum ); |
924 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
925 | ::SetControl32BitValue( m_controlRef , value ); | |
7f7b52b4 SC |
926 | } |
927 | ||
9d8aca48 | 928 | OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) |
5ca0d812 | 929 | { |
6cce68ea | 930 | return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart ); |
5ca0d812 SC |
931 | } |
932 | ||
9d8aca48 | 933 | bool wxMacControl::HasFocus() const |
5ca0d812 | 934 | { |
6cce68ea SC |
935 | ControlRef control; |
936 | GetKeyboardFocus( GetUserFocusWindow() , &control ); | |
937 | return control == m_controlRef; | |
5ca0d812 SC |
938 | } |
939 | ||
fb5246be | 940 | void wxMacControl::SetNeedsFocusRect( bool needs ) |
9b89f11a | 941 | { |
6cce68ea | 942 | m_needsFocusRect = needs; |
9b89f11a SC |
943 | } |
944 | ||
9d8aca48 | 945 | bool wxMacControl::NeedsFocusRect() const |
5ca0d812 | 946 | { |
6cce68ea | 947 | return m_needsFocusRect; |
5ca0d812 SC |
948 | } |
949 | ||
9d8aca48 | 950 | void wxMacControl::VisibilityChanged(bool shown) |
29d91661 SC |
951 | { |
952 | } | |
953 | ||
89a66f11 SC |
954 | void wxMacControl::SuperChangedPosition() |
955 | { | |
956 | } | |
957 | ||
9d8aca48 | 958 | void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
29d91661 | 959 | { |
6cce68ea | 960 | m_font = font; |
9d8aca48 WS |
961 | ControlFontStyleRec fontStyle; |
962 | if ( font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
963 | { | |
8638e69b | 964 | switch ( font.MacGetThemeFontID() ) |
9d8aca48 | 965 | { |
8638e69b | 966 | case kThemeSmallSystemFont : |
6cce68ea SC |
967 | fontStyle.font = kControlFontSmallSystemFont; |
968 | break; | |
8638e69b DS |
969 | |
970 | case 109 : // mini font | |
6cce68ea SC |
971 | fontStyle.font = -5; |
972 | break; | |
8638e69b DS |
973 | |
974 | case kThemeSystemFont : | |
6cce68ea SC |
975 | fontStyle.font = kControlFontBigSystemFont; |
976 | break; | |
8638e69b DS |
977 | |
978 | default : | |
6cce68ea SC |
979 | fontStyle.font = kControlFontBigSystemFont; |
980 | break; | |
9d8aca48 | 981 | } |
8638e69b | 982 | |
6cce68ea | 983 | fontStyle.flags = kControlUseFontMask; |
9d8aca48 WS |
984 | } |
985 | else | |
986 | { | |
6cce68ea SC |
987 | fontStyle.font = font.MacGetFontNum(); |
988 | fontStyle.style = font.MacGetFontStyle(); | |
989 | fontStyle.size = font.MacGetFontSize(); | |
990 | fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask; | |
9d8aca48 | 991 | } |
29d91661 | 992 | |
6cce68ea SC |
993 | fontStyle.just = teJustLeft; |
994 | fontStyle.flags |= kControlUseJustMask; | |
29d91661 | 995 | if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) |
6cce68ea | 996 | fontStyle.just = teJustCenter; |
29d91661 | 997 | else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) |
6cce68ea | 998 | fontStyle.just = teJustRight; |
29d91661 | 999 | |
9d8aca48 | 1000 | |
29d91661 SC |
1001 | // we only should do this in case of a non-standard color, as otherwise 'disabled' controls |
1002 | // won't get grayed out by the system anymore | |
9d8aca48 | 1003 | |
29d91661 SC |
1004 | if ( foreground != *wxBLACK ) |
1005 | { | |
6cce68ea SC |
1006 | fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() ); |
1007 | fontStyle.flags |= kControlUseForeColorMask; | |
29d91661 | 1008 | } |
9d8aca48 WS |
1009 | |
1010 | ::SetControlFontStyle( m_controlRef , &fontStyle ); | |
29d91661 SC |
1011 | } |
1012 | ||
9d8aca48 | 1013 | void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) ) |
7ea087b7 | 1014 | { |
9d8aca48 | 1015 | // TODO |
7ea087b7 SC |
1016 | // setting up a color proc is not recommended anymore |
1017 | } | |
1018 | ||
7f7b52b4 SC |
1019 | void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) |
1020 | { | |
6cce68ea SC |
1021 | ::SetControl32BitMinimum( m_controlRef , minimum ); |
1022 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
7f7b52b4 SC |
1023 | } |
1024 | ||
8638e69b | 1025 | short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) |
5ca0d812 | 1026 | { |
6cce68ea | 1027 | return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ); |
5ca0d812 SC |
1028 | } |
1029 | ||
1030 | void wxMacControl::SetActionProc( ControlActionUPP actionProc ) | |
1031 | { | |
6cce68ea | 1032 | SetControlAction( m_controlRef , actionProc ); |
5ca0d812 SC |
1033 | } |
1034 | ||
1035 | void wxMacControl::SetViewSize( SInt32 viewSize ) | |
1036 | { | |
6cce68ea | 1037 | SetControlViewSize(m_controlRef , viewSize ); |
5ca0d812 SC |
1038 | } |
1039 | ||
1040 | SInt32 wxMacControl::GetViewSize() const | |
1041 | { | |
6cce68ea | 1042 | return GetControlViewSize( m_controlRef ); |
5ca0d812 SC |
1043 | } |
1044 | ||
9d8aca48 | 1045 | bool wxMacControl::IsVisible() const |
5ca0d812 | 1046 | { |
6cce68ea | 1047 | return IsControlVisible( m_controlRef ); |
5ca0d812 SC |
1048 | } |
1049 | ||
9d8aca48 | 1050 | void wxMacControl::SetVisibility( bool visible , bool redraw ) |
5ca0d812 | 1051 | { |
6cce68ea | 1052 | SetControlVisibility( m_controlRef , visible , redraw ); |
5ca0d812 SC |
1053 | } |
1054 | ||
9d8aca48 | 1055 | bool wxMacControl::IsEnabled() const |
5ca0d812 SC |
1056 | { |
1057 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1058 | return IsControlEnabled( m_controlRef ); |
5ca0d812 | 1059 | #else |
6cce68ea | 1060 | return IsControlActive( m_controlRef ); |
5ca0d812 SC |
1061 | #endif |
1062 | } | |
1063 | ||
9d8aca48 | 1064 | bool wxMacControl::IsActive() const |
5ca0d812 | 1065 | { |
6cce68ea | 1066 | return IsControlActive( m_controlRef ); |
5ca0d812 SC |
1067 | } |
1068 | ||
9d8aca48 | 1069 | void wxMacControl::Enable( bool enable ) |
5ca0d812 | 1070 | { |
5ca0d812 | 1071 | if ( enable ) |
6cce68ea | 1072 | EnableControl( m_controlRef ); |
5ca0d812 | 1073 | else |
6cce68ea | 1074 | DisableControl( m_controlRef ); |
5ca0d812 SC |
1075 | } |
1076 | ||
9d8aca48 | 1077 | void wxMacControl::SetDrawingEnabled( bool enable ) |
5ca0d812 | 1078 | { |
6cce68ea | 1079 | HIViewSetDrawingEnabled( m_controlRef , enable ); |
5ca0d812 SC |
1080 | } |
1081 | ||
9d8aca48 | 1082 | bool wxMacControl::GetNeedsDisplay() const |
5ca0d812 | 1083 | { |
e779b609 | 1084 | return HIViewGetNeedsDisplay( m_controlRef ); |
5ca0d812 SC |
1085 | } |
1086 | ||
1f1c8bd4 | 1087 | void wxMacControl::SetNeedsDisplay( RgnHandle where ) |
5ca0d812 | 1088 | { |
1f1c8bd4 | 1089 | if ( !IsVisible() ) |
6cce68ea | 1090 | return; |
fb5246be | 1091 | |
e779b609 | 1092 | HIViewSetNeedsDisplayInRegion( m_controlRef , where , true ); |
5ca0d812 | 1093 | } |
1f1c8bd4 SC |
1094 | |
1095 | void wxMacControl::SetNeedsDisplay( Rect* where ) | |
1096 | { | |
1097 | if ( !IsVisible() ) | |
6cce68ea | 1098 | return; |
1f1c8bd4 | 1099 | |
e779b609 | 1100 | if ( where != NULL ) |
1f1c8bd4 | 1101 | { |
e779b609 SC |
1102 | RgnHandle update = NewRgn(); |
1103 | RectRgn( update , where ); | |
1104 | HIViewSetNeedsDisplayInRegion( m_controlRef , update , true ); | |
1105 | DisposeRgn( update ); | |
1f1c8bd4 SC |
1106 | } |
1107 | else | |
e779b609 | 1108 | HIViewSetNeedsDisplay( m_controlRef , true ); |
1f1c8bd4 | 1109 | } |
5ca0d812 | 1110 | |
9d8aca48 | 1111 | void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) |
5ca0d812 | 1112 | { |
e779b609 | 1113 | HIPoint hiPoint; |
8638e69b | 1114 | |
e779b609 SC |
1115 | hiPoint.x = pt->x; |
1116 | hiPoint.y = pt->y; | |
1117 | HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ); | |
1118 | pt->x = (int)hiPoint.x; | |
1119 | pt->y = (int)hiPoint.y; | |
5ca0d812 SC |
1120 | } |
1121 | ||
9d8aca48 | 1122 | void wxMacControl::SetRect( Rect *r ) |
5ca0d812 | 1123 | { |
9b89f11a SC |
1124 | //A HIRect is actually a CGRect on OSX - which consists of two structures - |
1125 | //CGPoint and CGSize, which have two floats each | |
6cce68ea SC |
1126 | HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } }; |
1127 | HIViewSetFrame ( m_controlRef , &hir ); | |
1128 | // eventuall we might have to do a SetVisibility( false , true ); | |
1129 | // before and a SetVisibility( true , true ); after | |
8bb6b2c0 | 1130 | } |
5ca0d812 | 1131 | |
9d8aca48 | 1132 | void wxMacControl::GetRect( Rect *r ) |
5ca0d812 | 1133 | { |
6cce68ea | 1134 | GetControlBounds( m_controlRef , r ); |
5ca0d812 SC |
1135 | } |
1136 | ||
9d8aca48 | 1137 | void wxMacControl::GetRectInWindowCoords( Rect *r ) |
5ca0d812 | 1138 | { |
6cce68ea | 1139 | UMAGetControlBoundsInWindowCoords( m_controlRef , r ); |
5ca0d812 SC |
1140 | } |
1141 | ||
9d8aca48 | 1142 | void wxMacControl::GetBestRect( Rect *r ) |
5ca0d812 | 1143 | { |
6cce68ea | 1144 | short baselineoffset; |
8638e69b | 1145 | |
6cce68ea | 1146 | GetBestControlRect( m_controlRef , r , &baselineoffset ); |
5ca0d812 SC |
1147 | } |
1148 | ||
fb5246be | 1149 | void wxMacControl::SetLabel( const wxString &title ) |
5ca0d812 | 1150 | { |
10a59880 RD |
1151 | wxFontEncoding encoding; |
1152 | ||
1153 | if ( m_font.Ok() ) | |
1154 | encoding = m_font.GetEncoding(); | |
1155 | else | |
1156 | encoding = wxFont::GetDefaultEncoding(); | |
9d8aca48 | 1157 | |
6cce68ea | 1158 | UMASetControlTitle( m_controlRef , title , encoding ); |
5ca0d812 SC |
1159 | } |
1160 | ||
1161 | void wxMacControl::GetFeatures( UInt32 * features ) | |
1162 | { | |
6cce68ea | 1163 | GetControlFeatures( m_controlRef , features ); |
5ca0d812 SC |
1164 | } |
1165 | ||
9d8aca48 | 1166 | OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) |
5ca0d812 | 1167 | { |
6cce68ea | 1168 | OSStatus err = GetControlRegion( m_controlRef , partCode , region ); |
6cce68ea | 1169 | return err; |
5ca0d812 SC |
1170 | } |
1171 | ||
9d8aca48 | 1172 | OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) |
5ca0d812 SC |
1173 | { |
1174 | #if TARGET_API_MAC_OSX | |
9d8aca48 | 1175 | return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, |
6cce68ea | 1176 | (other != NULL) ? other->m_controlRef : NULL); |
5ca0d812 | 1177 | #else |
6cce68ea | 1178 | return 0; |
5ca0d812 SC |
1179 | #endif |
1180 | } | |
1181 | ||
5ca0d812 SC |
1182 | #if TARGET_API_MAC_OSX |
1183 | // SetNeedsDisplay would not invalidate the children | |
1184 | static void InvalidateControlAndChildren( HIViewRef control ) | |
1185 | { | |
6cce68ea SC |
1186 | HIViewSetNeedsDisplay( control , true ); |
1187 | UInt16 childrenCount = 0; | |
1188 | OSStatus err = CountSubControls( control , &childrenCount ); | |
5ca0d812 | 1189 | if ( err == errControlIsNotEmbedder ) |
6cce68ea | 1190 | return; |
8638e69b | 1191 | |
6cce68ea | 1192 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ); |
5ca0d812 | 1193 | |
6cce68ea | 1194 | for ( UInt16 i = childrenCount; i >=1; --i ) |
5ca0d812 | 1195 | { |
6cce68ea | 1196 | HIViewRef child; |
8638e69b | 1197 | |
6cce68ea | 1198 | err = GetIndexedSubControl( control , i , & child ); |
5ca0d812 | 1199 | if ( err == errControlIsNotEmbedder ) |
6cce68ea | 1200 | return; |
8638e69b | 1201 | |
6cce68ea | 1202 | InvalidateControlAndChildren( child ); |
5ca0d812 SC |
1203 | } |
1204 | } | |
1205 | #endif | |
1206 | ||
9d8aca48 | 1207 | void wxMacControl::InvalidateWithChildren() |
5ca0d812 SC |
1208 | { |
1209 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1210 | InvalidateControlAndChildren( m_controlRef ); |
5ca0d812 SC |
1211 | #endif |
1212 | } | |
1213 | ||
fb5246be | 1214 | void wxMacControl::ScrollRect( wxRect *r , int dx , int dy ) |
5ca0d812 | 1215 | { |
6cce68ea | 1216 | wxASSERT( r != NULL ); |
8638e69b | 1217 | |
e779b609 SC |
1218 | HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height); |
1219 | HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ); | |
5ca0d812 SC |
1220 | } |
1221 | ||
6cce68ea SC |
1222 | OSType wxMacCreator = 'WXMC'; |
1223 | OSType wxMacControlProperty = 'MCCT'; | |
1224 | ||
88a7a4e1 | 1225 | void wxMacControl::SetReferenceInNativeControl() |
6cce68ea SC |
1226 | { |
1227 | void * data = this; | |
1228 | verify_noerr( SetControlProperty ( m_controlRef , | |
1229 | wxMacCreator,wxMacControlProperty, sizeof(data), &data ) ); | |
1230 | } | |
1231 | ||
88a7a4e1 | 1232 | wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control) |
6cce68ea SC |
1233 | { |
1234 | wxMacControl* ctl = NULL; | |
1235 | UInt32 actualSize; | |
1236 | if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) , | |
1237 | &actualSize , &ctl ) == noErr ) | |
1238 | { | |
1239 | return ctl; | |
1240 | } | |
1241 | return NULL; | |
1242 | } | |
1243 | ||
1244 | // ============================================================================ | |
1245 | // DataBrowser Wrapper | |
1246 | // ============================================================================ | |
1247 | // | |
1248 | // basing on DataBrowserItemIDs | |
1249 | // | |
1250 | ||
1251 | pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc( | |
1252 | ControlRef browser, | |
1253 | DataBrowserItemID itemID, | |
1254 | DataBrowserItemNotification message, | |
1255 | DataBrowserItemDataRef itemData ) | |
1256 | { | |
1257 | wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) ); | |
1258 | if ( ctl != 0 ) | |
1259 | { | |
1260 | ctl->ItemNotification(itemID, message, itemData); | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc( | |
1265 | ControlRef browser, | |
1266 | DataBrowserItemID itemID, | |
1267 | DataBrowserPropertyID property, | |
1268 | DataBrowserItemDataRef itemData, | |
1269 | Boolean changeValue ) | |
1270 | { | |
1271 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1272 | ||
1273 | wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) ); | |
1274 | if ( ctl != 0 ) | |
1275 | { | |
1276 | err = ctl->GetSetItemData(itemID, property, itemData, changeValue); | |
1277 | } | |
1278 | return err; | |
1279 | } | |
1280 | ||
1281 | pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc( | |
88a7a4e1 WS |
1282 | ControlRef browser, |
1283 | DataBrowserItemID itemOneID, | |
1284 | DataBrowserItemID itemTwoID, | |
1285 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1286 | { |
1287 | wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) ); | |
1288 | if ( ctl != 0 ) | |
1289 | { | |
1290 | return ctl->CompareItems(itemOneID, itemTwoID, sortProperty); | |
1291 | } | |
1292 | return false; | |
1293 | } | |
1294 | ||
1295 | DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL; | |
1296 | DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL; | |
1297 | DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL; | |
1298 | ||
1299 | wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) : wxMacControl( peer ) | |
88a7a4e1 | 1300 | { |
6cce68ea SC |
1301 | Rect bounds = wxMacGetBoundsForControl( peer, pos, size ); |
1302 | OSStatus err = ::CreateDataBrowserControl( | |
1303 | MAC_WXHWND(peer->MacGetTopLevelWindowRef()), | |
1304 | &bounds, kDataBrowserListView, &m_controlRef ); | |
1305 | SetReferenceInNativeControl(); | |
1306 | verify_noerr( err ); | |
1307 | if ( gDataBrowserItemCompareUPP == NULL ) | |
1308 | gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc); | |
1309 | if ( gDataBrowserItemDataUPP == NULL ) | |
1310 | gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc); | |
1311 | if ( gDataBrowserItemNotificationUPP == NULL ) | |
1312 | { | |
1313 | gDataBrowserItemNotificationUPP = | |
1314 | #if TARGET_API_MAC_OSX | |
1315 | (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc); | |
1316 | #else | |
1317 | NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc); | |
1318 | #endif | |
1319 | } | |
1320 | ||
1321 | DataBrowserCallbacks callbacks; | |
1322 | InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks ); | |
1323 | ||
1324 | callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP; | |
1325 | callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP; | |
1326 | callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP; | |
1327 | SetCallbacks( &callbacks ); | |
1328 | ||
1329 | } | |
1330 | ||
1331 | OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container, | |
1332 | Boolean recurse, | |
1333 | DataBrowserItemState state, | |
88a7a4e1 | 1334 | UInt32 *numItems) const |
6cce68ea | 1335 | { |
88a7a4e1 | 1336 | return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems ); |
6cce68ea SC |
1337 | } |
1338 | ||
1339 | OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container, | |
1340 | Boolean recurse, | |
1341 | DataBrowserItemState state, | |
88a7a4e1 | 1342 | Handle items) const |
6cce68ea | 1343 | { |
88a7a4e1 | 1344 | return GetDataBrowserItems( m_controlRef, container, recurse, state, items ); |
6cce68ea SC |
1345 | } |
1346 | ||
1347 | OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options ) | |
1348 | { | |
1349 | return SetDataBrowserSelectionFlags( m_controlRef, options ); | |
1350 | } | |
1351 | ||
1352 | OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc, | |
1353 | DataBrowserTableViewColumnIndex position ) | |
1354 | { | |
1355 | return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position ); | |
1356 | } | |
1357 | ||
1358 | OSStatus wxMacDataBrowserControl::AutoSizeColumns() | |
1359 | { | |
1360 | return AutoSizeDataBrowserListViewColumns(m_controlRef); | |
1361 | } | |
1362 | ||
1363 | OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert ) | |
1364 | { | |
1365 | return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert ); | |
1366 | } | |
1367 | ||
1368 | OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) | |
1369 | { | |
1370 | return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle ); | |
1371 | } | |
1372 | ||
1373 | OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height) | |
1374 | { | |
1375 | return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1376 | } | |
1377 | ||
1378 | OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height) | |
1379 | { | |
1380 | return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1381 | } | |
1382 | ||
1383 | OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks) | |
1384 | { | |
1385 | return SetDataBrowserCallbacks( m_controlRef, callbacks ); | |
1386 | } | |
1387 | ||
88a7a4e1 | 1388 | OSStatus wxMacDataBrowserControl::UpdateItems( |
6cce68ea SC |
1389 | DataBrowserItemID container, |
1390 | UInt32 numItems, | |
1391 | const DataBrowserItemID *items, | |
1392 | DataBrowserPropertyID preSortProperty, | |
1393 | DataBrowserPropertyID propertyID ) const | |
1394 | { | |
1395 | return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID ); | |
1396 | } | |
1397 | ||
1398 | bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const | |
1399 | { | |
1400 | return IsDataBrowserItemSelected( m_controlRef, item ); | |
1401 | } | |
1402 | ||
1403 | OSStatus wxMacDataBrowserControl::AddItems( | |
1404 | DataBrowserItemID container, | |
1405 | UInt32 numItems, | |
1406 | const DataBrowserItemID *items, | |
1407 | DataBrowserPropertyID preSortProperty ) | |
1408 | { | |
1409 | return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1410 | } | |
1411 | ||
1412 | OSStatus wxMacDataBrowserControl::RemoveItems( | |
1413 | DataBrowserItemID container, | |
1414 | UInt32 numItems, | |
1415 | const DataBrowserItemID *items, | |
1416 | DataBrowserPropertyID preSortProperty ) | |
1417 | { | |
1418 | return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1419 | } | |
1420 | ||
1421 | OSStatus wxMacDataBrowserControl::RevealItem( | |
1422 | DataBrowserItemID item, | |
1423 | DataBrowserPropertyID propertyID, | |
1424 | DataBrowserRevealOptions options ) const | |
1425 | { | |
1426 | return RevealDataBrowserItem( m_controlRef, item, propertyID, options ); | |
1427 | } | |
1428 | ||
1429 | OSStatus wxMacDataBrowserControl::SetSelectedItems( | |
1430 | UInt32 numItems, | |
1431 | const DataBrowserItemID *items, | |
1432 | DataBrowserSetOption operation ) | |
1433 | { | |
1434 | return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation ); | |
1435 | } | |
1436 | ||
1437 | OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const | |
1438 | { | |
1439 | return GetDataBrowserSelectionAnchor( m_controlRef, first, last ); | |
1440 | } | |
1441 | ||
1442 | OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const | |
1443 | { | |
1444 | return GetDataBrowserTableViewItemID( m_controlRef, row, item ); | |
1445 | } | |
1446 | ||
1447 | OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const | |
1448 | { | |
1449 | return GetDataBrowserTableViewItemRow( m_controlRef, item, row ); | |
1450 | } | |
1451 | ||
88a7a4e1 | 1452 | OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height ) |
6cce68ea | 1453 | { |
88a7a4e1 | 1454 | return SetDataBrowserTableViewRowHeight( m_controlRef , height ); |
6cce68ea SC |
1455 | } |
1456 | ||
88a7a4e1 | 1457 | OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const |
6cce68ea | 1458 | { |
88a7a4e1 | 1459 | return GetDataBrowserTableViewRowHeight( m_controlRef, height ); |
6cce68ea | 1460 | } |
88a7a4e1 WS |
1461 | |
1462 | OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height) | |
6cce68ea SC |
1463 | { |
1464 | return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height ); | |
1465 | } | |
1466 | ||
88a7a4e1 | 1467 | OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const |
6cce68ea SC |
1468 | { |
1469 | return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height); | |
1470 | } | |
1471 | ||
88a7a4e1 | 1472 | OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const |
6cce68ea SC |
1473 | { |
1474 | return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1475 | } | |
1476 | ||
88a7a4e1 | 1477 | OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width ) |
6cce68ea SC |
1478 | { |
1479 | return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1480 | } | |
1481 | ||
88a7a4e1 | 1482 | OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const |
6cce68ea SC |
1483 | { |
1484 | return GetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1485 | } | |
1486 | ||
88a7a4e1 | 1487 | OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width ) |
6cce68ea SC |
1488 | { |
1489 | return SetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1490 | } | |
1491 | ||
88a7a4e1 | 1492 | OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const |
6cce68ea SC |
1493 | { |
1494 | return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns); | |
1495 | } | |
1496 | ||
88a7a4e1 | 1497 | OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column, |
6cce68ea SC |
1498 | UInt32 *position) const |
1499 | { | |
1500 | return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1501 | } | |
1502 | ||
88a7a4e1 | 1503 | OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, UInt32 position) |
6cce68ea SC |
1504 | { |
1505 | return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1506 | } | |
1507 | ||
88a7a4e1 | 1508 | OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const |
6cce68ea SC |
1509 | { |
1510 | return GetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1511 | } | |
1512 | ||
88a7a4e1 | 1513 | OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left ) |
6cce68ea SC |
1514 | { |
1515 | return SetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1516 | } | |
1517 | ||
88a7a4e1 | 1518 | OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const |
6cce68ea SC |
1519 | { |
1520 | return GetDataBrowserSortProperty( m_controlRef , column ); | |
1521 | } | |
1522 | ||
88a7a4e1 | 1523 | OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column ) |
6cce68ea SC |
1524 | { |
1525 | return SetDataBrowserSortProperty( m_controlRef , column ); | |
1526 | } | |
88a7a4e1 WS |
1527 | |
1528 | OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const | |
6cce68ea SC |
1529 | { |
1530 | return GetDataBrowserSortOrder( m_controlRef , order ); | |
1531 | } | |
1532 | ||
88a7a4e1 | 1533 | OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order ) |
6cce68ea SC |
1534 | { |
1535 | return SetDataBrowserSortOrder( m_controlRef , order ); | |
1536 | } | |
1537 | ||
88a7a4e1 WS |
1538 | OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property, |
1539 | DataBrowserPropertyFlags *flags ) const | |
6cce68ea SC |
1540 | { |
1541 | return GetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1542 | } | |
1543 | ||
88a7a4e1 WS |
1544 | OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property, |
1545 | DataBrowserPropertyFlags flags ) | |
6cce68ea SC |
1546 | { |
1547 | return SetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1548 | } | |
1549 | ||
88a7a4e1 WS |
1550 | OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property, |
1551 | DataBrowserListViewHeaderDesc *desc ) const | |
6cce68ea SC |
1552 | { |
1553 | return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); | |
1554 | } | |
1555 | ||
88a7a4e1 WS |
1556 | OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property, |
1557 | DataBrowserListViewHeaderDesc *desc ) | |
6cce68ea | 1558 | { |
88a7a4e1 | 1559 | return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); |
6cce68ea SC |
1560 | } |
1561 | ||
88a7a4e1 WS |
1562 | OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property , |
1563 | Boolean expandableRows ) | |
6cce68ea SC |
1564 | { |
1565 | return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows); | |
1566 | } | |
1567 | ||
1568 | // ============================================================================ | |
88a7a4e1 | 1569 | // Higher-level Databrowser |
6cce68ea SC |
1570 | // ============================================================================ |
1571 | // | |
1572 | // basing on data item objects | |
1573 | // | |
1574 | ||
1575 | wxMacDataItem::wxMacDataItem() | |
88a7a4e1 | 1576 | { |
6cce68ea SC |
1577 | } |
1578 | ||
88a7a4e1 WS |
1579 | wxMacDataItem::~wxMacDataItem() |
1580 | { | |
6cce68ea | 1581 | } |
88a7a4e1 WS |
1582 | |
1583 | bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *owner , | |
1584 | const wxMacDataItem*, | |
6cce68ea SC |
1585 | DataBrowserPropertyID property) const |
1586 | { | |
1587 | return false; | |
1588 | } | |
1589 | ||
88a7a4e1 | 1590 | OSStatus wxMacDataItem::GetSetData(wxMacDataItemBrowserControl *owner , |
6cce68ea SC |
1591 | DataBrowserPropertyID property, |
1592 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1593 | bool changeValue ) |
6cce68ea SC |
1594 | { |
1595 | return errDataBrowserPropertyNotSupported; | |
1596 | } | |
1597 | ||
88a7a4e1 | 1598 | void wxMacDataItem::Notification(wxMacDataItemBrowserControl *owner , |
6cce68ea SC |
1599 | DataBrowserItemNotification message, |
1600 | DataBrowserItemDataRef itemData ) const | |
1601 | { | |
1602 | } | |
1603 | ||
1604 | ||
88a7a4e1 | 1605 | wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) : |
6cce68ea | 1606 | wxMacDataBrowserControl( peer, pos, size, style ) |
88a7a4e1 | 1607 | { |
6cce68ea SC |
1608 | m_suppressSelection = false; |
1609 | } | |
88a7a4e1 WS |
1610 | |
1611 | wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser) | |
6cce68ea SC |
1612 | { |
1613 | m_former = browser->SuppressSelection(true); | |
1614 | m_browser = browser; | |
1615 | } | |
1616 | ||
1617 | wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor() | |
1618 | { | |
1619 | m_browser->SuppressSelection(m_former); | |
1620 | } | |
1621 | ||
1622 | bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress ) | |
1623 | { | |
1624 | bool former = m_suppressSelection; | |
1625 | m_suppressSelection = suppress; | |
1626 | ||
1627 | return former; | |
1628 | } | |
1629 | ||
88a7a4e1 WS |
1630 | Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID, |
1631 | DataBrowserItemID itemTwoID, | |
1632 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1633 | { |
1634 | wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID; | |
1635 | wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID; | |
1636 | return CompareItems( itemOne , itemTwo , sortProperty ); | |
1637 | } | |
1638 | ||
88a7a4e1 WS |
1639 | Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne, |
1640 | const wxMacDataItem* itemTwo, | |
1641 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1642 | { |
1643 | Boolean retval = false; | |
1644 | if ( itemOne != NULL ) | |
1645 | retval = itemOne->IsLessThan( this , itemTwo , sortProperty); | |
1646 | return retval; | |
1647 | } | |
1648 | ||
1649 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1650 | DataBrowserItemID itemID, | |
1651 | DataBrowserPropertyID property, | |
1652 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1653 | Boolean changeValue ) |
6cce68ea SC |
1654 | { |
1655 | wxMacDataItem* item = (wxMacDataItem*) itemID; | |
1656 | return GetSetItemData(item, property, itemData , changeValue ); | |
1657 | } | |
1658 | ||
1659 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1660 | wxMacDataItem* item, | |
1661 | DataBrowserPropertyID property, | |
1662 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1663 | Boolean changeValue ) |
6cce68ea SC |
1664 | { |
1665 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1666 | switch( property ) | |
1667 | { | |
1668 | case kDataBrowserContainerIsClosableProperty : | |
1669 | case kDataBrowserContainerIsSortableProperty : | |
1670 | case kDataBrowserContainerIsOpenableProperty : | |
1671 | // right now default behaviour on these | |
1672 | break; | |
1673 | default : | |
1674 | if ( item != NULL ) | |
1675 | err = item->GetSetData( this, property , itemData , changeValue ); | |
1676 | break; | |
88a7a4e1 | 1677 | |
6cce68ea SC |
1678 | } |
1679 | return err; | |
1680 | } | |
1681 | ||
1682 | void wxMacDataItemBrowserControl::ItemNotification( | |
1683 | DataBrowserItemID itemID, | |
1684 | DataBrowserItemNotification message, | |
88a7a4e1 | 1685 | DataBrowserItemDataRef itemData) |
6cce68ea | 1686 | { |
88a7a4e1 | 1687 | wxMacDataItem* item = (wxMacDataItem*) itemID; |
6cce68ea SC |
1688 | ItemNotification( item , message, itemData); |
1689 | } | |
1690 | ||
1691 | void wxMacDataItemBrowserControl::ItemNotification( | |
1692 | const wxMacDataItem* item, | |
1693 | DataBrowserItemNotification message, | |
88a7a4e1 | 1694 | DataBrowserItemDataRef itemData) |
6cce68ea SC |
1695 | { |
1696 | if (item != NULL) | |
1697 | item->Notification( this, message, itemData); | |
1698 | } | |
1699 | ||
88a7a4e1 WS |
1700 | unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container, |
1701 | bool recurse , DataBrowserItemState state) const | |
6cce68ea SC |
1702 | { |
1703 | UInt32 numItems = 0; | |
88a7a4e1 WS |
1704 | verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container, |
1705 | recurse, state, &numItems ) ); | |
6cce68ea SC |
1706 | return numItems; |
1707 | } | |
1708 | ||
88a7a4e1 WS |
1709 | void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container, |
1710 | bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const | |
6cce68ea SC |
1711 | { |
1712 | Handle handle = NewHandle(0); | |
88a7a4e1 WS |
1713 | verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container , |
1714 | recurse , state, handle) ); | |
6cce68ea SC |
1715 | |
1716 | int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID); | |
1717 | HLock( handle ); | |
1718 | wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle; | |
1719 | for ( int i = 0; i < itemCount; ++i) | |
1720 | { | |
1721 | items.Add(itemsArray[i]); | |
1722 | } | |
1723 | HUnlock( handle ); | |
1724 | DisposeHandle( handle ); | |
1725 | } | |
1726 | ||
1727 | unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const | |
1728 | { | |
1729 | DataBrowserTableViewRowIndex row; | |
1730 | OSStatus err = GetItemRow( (DataBrowserItemID) item , &row); | |
1731 | wxASSERT( err == noErr); | |
1732 | return row; | |
1733 | } | |
1734 | ||
1735 | wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const | |
1736 | { | |
1737 | DataBrowserItemID id; | |
1738 | OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id); | |
1739 | wxASSERT( err == noErr); | |
88a7a4e1 | 1740 | return (wxMacDataItem*) id; |
6cce68ea SC |
1741 | } |
1742 | ||
88a7a4e1 | 1743 | void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container, |
6cce68ea SC |
1744 | const wxMacDataItem *item , DataBrowserPropertyID property) const |
1745 | { | |
88a7a4e1 | 1746 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1, |
6cce68ea SC |
1747 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) ); |
1748 | } | |
1749 | ||
88a7a4e1 | 1750 | void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container, |
6cce68ea SC |
1751 | wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const |
1752 | { | |
1753 | unsigned int noItems = itemArray.GetCount(); | |
1754 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1755 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1756 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1757 | ||
88a7a4e1 | 1758 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems, |
6cce68ea SC |
1759 | items, kDataBrowserItemNoProperty /* notSorted */, property ) ); |
1760 | delete [] items; | |
1761 | } | |
1762 | ||
1763 | void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item) | |
1764 | { | |
88a7a4e1 | 1765 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1, |
6cce68ea SC |
1766 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) ); |
1767 | } | |
1768 | ||
88a7a4e1 | 1769 | void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray ) |
6cce68ea SC |
1770 | { |
1771 | unsigned int noItems = itemArray.GetCount(); | |
1772 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1773 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1774 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1775 | ||
88a7a4e1 | 1776 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems, |
6cce68ea SC |
1777 | (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) ); |
1778 | delete [] items; | |
1779 | } | |
1780 | ||
88a7a4e1 | 1781 | void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item) |
6cce68ea | 1782 | { |
88a7a4e1 | 1783 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1, |
6cce68ea SC |
1784 | (UInt32*) &item, kDataBrowserItemNoProperty ); |
1785 | verify_noerr( err ); | |
1786 | } | |
1787 | ||
88a7a4e1 | 1788 | void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray) |
6cce68ea SC |
1789 | { |
1790 | unsigned int noItems = itemArray.GetCount(); | |
1791 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1792 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1793 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1794 | ||
88a7a4e1 | 1795 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems, |
6cce68ea SC |
1796 | (UInt32*) items, kDataBrowserItemNoProperty ); |
1797 | verify_noerr( err ); | |
1798 | delete [] items; | |
1799 | } | |
1800 | ||
88a7a4e1 | 1801 | void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container) |
6cce68ea SC |
1802 | { |
1803 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty ); | |
1804 | verify_noerr( err ); | |
1805 | } | |
1806 | ||
88a7a4e1 | 1807 | void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option) |
6cce68ea SC |
1808 | { |
1809 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option )); | |
1810 | } | |
1811 | ||
88a7a4e1 | 1812 | void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option) |
6cce68ea SC |
1813 | { |
1814 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option )); | |
1815 | } | |
1816 | ||
88a7a4e1 | 1817 | void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option) |
6cce68ea SC |
1818 | { |
1819 | unsigned int noItems = itemArray.GetCount(); | |
1820 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1821 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1822 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1823 | ||
1824 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option )); | |
1825 | delete [] items; | |
1826 | } | |
1827 | ||
1828 | Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const | |
1829 | { | |
1830 | return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item); | |
1831 | } | |
1832 | ||
88a7a4e1 | 1833 | void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options) |
6cce68ea SC |
1834 | { |
1835 | verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) ); | |
1836 | } | |
1837 | ||
88a7a4e1 | 1838 | void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const |
6cce68ea | 1839 | { |
88a7a4e1 | 1840 | verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) ); |
6cce68ea SC |
1841 | } |
1842 | ||
88a7a4e1 | 1843 | |
6cce68ea | 1844 | |
5ca0d812 SC |
1845 | // |
1846 | // Tab Control | |
1847 | // | |
9d8aca48 WS |
1848 | |
1849 | OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) | |
5ca0d812 | 1850 | { |
6cce68ea | 1851 | return ::SetTabEnabled( m_controlRef , tabNo , enable ); |
5ca0d812 | 1852 | } |
9d8aca48 | 1853 | |
30e77b5c SC |
1854 | // |
1855 | // Quartz Support | |
1856 | // | |
1857 | ||
1858 | #ifdef __WXMAC_OSX__ | |
1859 | // snippets from Sketch Sample from Apple : | |
1860 | ||
8638e69b DS |
1861 | #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" |
1862 | ||
30e77b5c | 1863 | /* |
fb5246be | 1864 | This function locates, opens, and returns the profile reference for the calibrated |
30e77b5c SC |
1865 | Generic RGB color space. It is up to the caller to call CMCloseProfile when done |
1866 | with the profile reference this function returns. | |
1867 | */ | |
8638e69b | 1868 | CMProfileRef wxMacOpenGenericProfile() |
30e77b5c SC |
1869 | { |
1870 | static CMProfileRef cachedRGBProfileRef = NULL; | |
fb5246be | 1871 | |
30e77b5c SC |
1872 | // we only create the profile reference once |
1873 | if (cachedRGBProfileRef == NULL) | |
1874 | { | |
fb5246be WS |
1875 | CMProfileLocation loc; |
1876 | ||
1877 | loc.locType = cmPathBasedProfile; | |
1878 | strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr); | |
1879 | ||
1880 | verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) ); | |
30e77b5c SC |
1881 | } |
1882 | ||
8638e69b | 1883 | // clone the profile reference so that the caller has their own reference, not our cached one |
30e77b5c | 1884 | if (cachedRGBProfileRef) |
fb5246be | 1885 | CMCloneProfileRef(cachedRGBProfileRef); |
30e77b5c SC |
1886 | |
1887 | return cachedRGBProfileRef; | |
1888 | } | |
1889 | ||
1890 | /* | |
1891 | Return the generic RGB color space. This is a 'get' function and the caller should | |
1892 | not release the returned value unless the caller retains it first. Usually callers | |
1893 | of this routine will immediately use the returned colorspace with CoreGraphics | |
1894 | so they typically do not need to retain it themselves. | |
fb5246be | 1895 | |
30e77b5c SC |
1896 | This function creates the generic RGB color space once and hangs onto it so it can |
1897 | return it whenever this function is called. | |
1898 | */ | |
1899 | ||
1900 | CGColorSpaceRef wxMacGetGenericRGBColorSpace() | |
1901 | { | |
6cce68ea | 1902 | static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace; |
fb5246be | 1903 | |
8638e69b DS |
1904 | if (genericRGBColorSpace == NULL) |
1905 | { | |
26a2f914 | 1906 | if ( UMAGetSystemVersion() >= 0x1040 ) |
fb5246be | 1907 | { |
6cce68ea | 1908 | genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) ); |
fb5246be | 1909 | } |
26a2f914 SC |
1910 | else |
1911 | { | |
1912 | CMProfileRef genericRGBProfile = wxMacOpenGenericProfile(); | |
8638e69b | 1913 | |
26a2f914 SC |
1914 | if (genericRGBProfile) |
1915 | { | |
6cce68ea | 1916 | genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) ); |
8638e69b | 1917 | |
6cce68ea | 1918 | wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ); |
8638e69b | 1919 | |
26a2f914 | 1920 | // we opened the profile so it is up to us to close it |
88a7a4e1 | 1921 | CMCloseProfile(genericRGBProfile); |
26a2f914 SC |
1922 | } |
1923 | } | |
8638e69b DS |
1924 | } |
1925 | ||
30e77b5c SC |
1926 | return genericRGBColorSpace; |
1927 | } | |
1928 | #endif | |
1929 | ||
54ce9ebb JS |
1930 | wxMacPortSaver::wxMacPortSaver( GrafPtr port ) |
1931 | { | |
6cce68ea SC |
1932 | ::GetPort( &m_port ); |
1933 | ::SetPort( port ); | |
54ce9ebb JS |
1934 | } |
1935 | ||
1936 | wxMacPortSaver::~wxMacPortSaver() | |
1937 | { | |
6cce68ea | 1938 | ::SetPort( m_port ); |
54ce9ebb JS |
1939 | } |
1940 | ||
b6ed2b86 | 1941 | #endif // wxUSE_GUI |