]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/carbon/utils.cpp | |
3 | // Purpose: Various utilities | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/utils.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
18 | #include "wx/app.h" | |
19 | #if wxUSE_GUI | |
20 | #include "wx/toplevel.h" | |
21 | #include "wx/font.h" | |
22 | #endif | |
23 | #endif | |
24 | ||
25 | #include "wx/apptrait.h" | |
26 | ||
27 | #if wxUSE_GUI | |
28 | #include "wx/mac/uma.h" | |
29 | #endif | |
30 | ||
31 | #include <ctype.h> | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | #include <stdarg.h> | |
37 | ||
38 | #include "MoreFilesX.h" | |
39 | ||
40 | #ifndef __DARWIN__ | |
41 | #include <Threads.h> | |
42 | #include <Sound.h> | |
43 | #endif | |
44 | ||
45 | #if wxUSE_GUI | |
46 | #if TARGET_API_MAC_OSX | |
47 | #include <CoreServices/CoreServices.h> | |
48 | #else | |
49 | #include <DriverServices.h> | |
50 | #include <Multiprocessing.h> | |
51 | #endif | |
52 | ||
53 | #ifdef __DARWIN__ | |
54 | #include <Carbon/Carbon.h> | |
55 | #else | |
56 | #include <ATSUnicode.h> | |
57 | #include <TextCommon.h> | |
58 | #include <TextEncodingConverter.h> | |
59 | #endif | |
60 | #endif // wxUSE_GUI | |
61 | ||
62 | #include "wx/mac/private.h" | |
63 | ||
64 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
65 | #if __MWERKS__ < 0x4100 || !defined(__DARWIN__) | |
66 | #include <wtime.h> | |
67 | #endif | |
68 | #endif | |
69 | ||
70 | #if wxUSE_BASE | |
71 | ||
72 | // our OS version is the same in non GUI and GUI cases | |
73 | wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) | |
74 | { | |
75 | SInt32 theSystem; | |
76 | Gestalt(gestaltSystemVersion, &theSystem); | |
77 | ||
78 | if ( majorVsn != NULL ) | |
79 | *majorVsn = (theSystem >> 8); | |
80 | ||
81 | if ( minorVsn != NULL ) | |
82 | *minorVsn = (theSystem & 0xFF); | |
83 | ||
84 | #if defined( __DARWIN__ ) | |
85 | return wxOS_MAC_OSX_DARWIN; | |
86 | #else | |
87 | return wxOS_MAC_OS; | |
88 | #endif | |
89 | } | |
90 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // debugging support | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
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 | ||
109 | #include <CodeFragments.h> | |
110 | ||
111 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); | |
112 | ||
113 | ProcPtr gCallUniversalProc_Proc = NULL; | |
114 | ||
115 | #endif | |
116 | ||
117 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
118 | ||
119 | static long fRunOnce = false; | |
120 | ||
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 | { | |
133 | // look for MetroNub's Gestalt selector | |
134 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) | |
135 | { | |
136 | #if TARGET_API_MAC_CARBON | |
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 | } | |
165 | #endif | |
166 | ||
167 | { | |
168 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
169 | ||
170 | // make sure the version of the API is compatible | |
171 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && | |
172 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
173 | { | |
174 | // success! | |
175 | gMetroNubEntry = block; | |
176 | } | |
177 | } | |
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 | ||
191 | Boolean IsMWDebuggerRunning() | |
192 | { | |
193 | if (IsMetroNubInstalled()) | |
194 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
195 | ||
196 | return false; | |
197 | } | |
198 | ||
199 | Boolean AmIBeingMWDebugged() | |
200 | { | |
201 | if (IsMetroNubInstalled()) | |
202 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
203 | ||
204 | return false; | |
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 | ||
221 | ||
222 | #ifndef __DARWIN__ | |
223 | // defined in unix/utilsunx.cpp for Mac OS X | |
224 | ||
225 | // get full hostname (with domain name if possible) | |
226 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
227 | { | |
228 | return wxGetHostName(buf, maxSize); | |
229 | } | |
230 | ||
231 | // Get user ID e.g. jacs | |
232 | bool wxGetUserId(wxChar *buf, int maxSize) | |
233 | { | |
234 | return wxGetUserName( buf , maxSize ); | |
235 | } | |
236 | ||
237 | const wxChar* wxGetHomeDir(wxString *pstr) | |
238 | { | |
239 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ); | |
240 | return pstr->c_str(); | |
241 | } | |
242 | ||
243 | // Get hostname only (without domain name) | |
244 | bool wxGetHostName(wxChar *buf, int maxSize) | |
245 | { | |
246 | // Gets Chooser name of user by examining a System resource. | |
247 | buf[0] = 0; | |
248 | ||
249 | const short kComputerNameID = -16413; | |
250 | ||
251 | short oldResFile = CurResFile(); | |
252 | UseResFile(0); | |
253 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
254 | UseResFile(oldResFile); | |
255 | ||
256 | if (chooserName && *chooserName) | |
257 | { | |
258 | HLock( (Handle) chooserName ); | |
259 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
260 | HUnlock( (Handle) chooserName ); | |
261 | ReleaseResource( (Handle) chooserName ); | |
262 | wxStrncpy( buf , name , maxSize - 1 ); | |
263 | } | |
264 | ||
265 | return true; | |
266 | } | |
267 | ||
268 | // Get user name e.g. Stefan Csomor | |
269 | bool wxGetUserName(wxChar *buf, int maxSize) | |
270 | { | |
271 | // Gets Chooser name of user by examining a System resource. | |
272 | buf[0] = 0; | |
273 | ||
274 | const short kChooserNameID = -16096; | |
275 | ||
276 | short oldResFile = CurResFile(); | |
277 | UseResFile(0); | |
278 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
279 | UseResFile(oldResFile); | |
280 | ||
281 | if (chooserName && *chooserName) | |
282 | { | |
283 | HLock( (Handle) chooserName ); | |
284 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
285 | HUnlock( (Handle) chooserName ); | |
286 | ReleaseResource( (Handle) chooserName ); | |
287 | wxStrncpy( buf , name , maxSize - 1 ); | |
288 | } | |
289 | ||
290 | return true; | |
291 | } | |
292 | ||
293 | int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags) | |
294 | { | |
295 | // TODO | |
296 | return 0; | |
297 | } | |
298 | ||
299 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) | |
300 | { | |
301 | // TODO : under classic there is no environement support, under X yes | |
302 | return false; | |
303 | } | |
304 | ||
305 | // set the env var name to the given value, return true on success | |
306 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value) | |
307 | { | |
308 | // TODO : under classic there is no environement support, under X yes | |
309 | return false; | |
310 | } | |
311 | ||
312 | // Execute a program in an Interactive Shell | |
313 | bool wxShell(const wxString& command) | |
314 | { | |
315 | // TODO | |
316 | return false; | |
317 | } | |
318 | ||
319 | // Shutdown or reboot the PC | |
320 | bool wxShutdown(wxShutdownFlags wFlags) | |
321 | { | |
322 | // TODO | |
323 | return false; | |
324 | } | |
325 | ||
326 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
327 | wxMemorySize wxGetFreeMemory() | |
328 | { | |
329 | return (wxMemorySize)FreeMem(); | |
330 | } | |
331 | ||
332 | #ifndef __DARWIN__ | |
333 | ||
334 | void wxMicroSleep(unsigned long microseconds) | |
335 | { | |
336 | AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); | |
337 | MPDelayUntil( & wakeup); | |
338 | } | |
339 | ||
340 | void wxMilliSleep(unsigned long milliseconds) | |
341 | { | |
342 | AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); | |
343 | MPDelayUntil( & wakeup); | |
344 | } | |
345 | ||
346 | void wxSleep(int nSecs) | |
347 | { | |
348 | wxMilliSleep(1000*nSecs); | |
349 | } | |
350 | ||
351 | #endif | |
352 | ||
353 | // Consume all events until no more left | |
354 | void wxFlushEvents() | |
355 | { | |
356 | } | |
357 | ||
358 | #endif // !__DARWIN__ | |
359 | ||
360 | // Emit a beeeeeep | |
361 | void wxBell() | |
362 | { | |
363 | #ifndef __LP64__ | |
364 | SysBeep(30); | |
365 | #endif | |
366 | } | |
367 | ||
368 | ||
369 | #endif // wxUSE_BASE | |
370 | ||
371 | #if wxUSE_GUI | |
372 | ||
373 | wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const | |
374 | { | |
375 | // We suppose that toolkit version is the same as OS version under Mac | |
376 | wxGetOsVersion(verMaj, verMin); | |
377 | ||
378 | return wxPORT_MAC; | |
379 | } | |
380 | ||
381 | int gs_wxBusyCursorCount = 0; | |
382 | extern wxCursor gMacCurrentCursor; | |
383 | wxCursor gMacStoredActiveCursor; | |
384 | ||
385 | // Set the cursor to the busy cursor for all windows | |
386 | void wxBeginBusyCursor(const wxCursor *cursor) | |
387 | { | |
388 | if (gs_wxBusyCursorCount++ == 0) | |
389 | { | |
390 | gMacStoredActiveCursor = gMacCurrentCursor; | |
391 | cursor->MacInstall(); | |
392 | } | |
393 | //else: nothing to do, already set | |
394 | } | |
395 | ||
396 | // Restore cursor to normal | |
397 | void wxEndBusyCursor() | |
398 | { | |
399 | wxCHECK_RET( gs_wxBusyCursorCount > 0, | |
400 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); | |
401 | ||
402 | if (--gs_wxBusyCursorCount == 0) | |
403 | { | |
404 | gMacStoredActiveCursor.MacInstall(); | |
405 | gMacStoredActiveCursor = wxNullCursor; | |
406 | } | |
407 | } | |
408 | ||
409 | // true if we're between the above two calls | |
410 | bool wxIsBusy() | |
411 | { | |
412 | return (gs_wxBusyCursorCount > 0); | |
413 | } | |
414 | ||
415 | #endif // wxUSE_GUI | |
416 | ||
417 | #if wxUSE_BASE | |
418 | ||
419 | wxString wxMacFindFolderNoSeparator( short vol, | |
420 | OSType folderType, | |
421 | Boolean createFolder) | |
422 | { | |
423 | FSRef fsRef; | |
424 | wxString strDir; | |
425 | ||
426 | if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr) | |
427 | { | |
428 | strDir = wxMacFSRefToPath( &fsRef ); | |
429 | } | |
430 | ||
431 | return strDir; | |
432 | } | |
433 | ||
434 | wxString wxMacFindFolder( short vol, | |
435 | OSType folderType, | |
436 | Boolean createFolder) | |
437 | { | |
438 | return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH; | |
439 | } | |
440 | ||
441 | #endif // wxUSE_BASE | |
442 | ||
443 | #if wxUSE_GUI | |
444 | ||
445 | // Check whether this window wants to process messages, e.g. Stop button | |
446 | // in long calculations. | |
447 | bool wxCheckForInterrupt(wxWindow *wnd) | |
448 | { | |
449 | // TODO | |
450 | return false; | |
451 | } | |
452 | ||
453 | void wxGetMousePosition( int* x, int* y ) | |
454 | { | |
455 | Point pt; | |
456 | #if wxMAC_USE_CORE_GRAPHICS | |
457 | GetGlobalMouse(&pt); | |
458 | #else | |
459 | GetMouse( &pt ); | |
460 | LocalToGlobal( &pt ); | |
461 | #endif | |
462 | *x = pt.h; | |
463 | *y = pt.v; | |
464 | }; | |
465 | ||
466 | // Return true if we have a colour display | |
467 | bool wxColourDisplay() | |
468 | { | |
469 | return true; | |
470 | } | |
471 | ||
472 | // Returns depth of screen | |
473 | int wxDisplayDepth() | |
474 | { | |
475 | int theDepth = 8; | |
476 | #if wxMAC_USE_CORE_GRAPHICS | |
477 | theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID()); | |
478 | #else | |
479 | Rect globRect; | |
480 | SetRect(&globRect, -32760, -32760, 32760, 32760); | |
481 | GDHandle theMaxDevice; | |
482 | ||
483 | theMaxDevice = GetMaxDevice(&globRect); | |
484 | if (theMaxDevice != NULL) | |
485 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; | |
486 | #endif | |
487 | return theDepth; | |
488 | } | |
489 | ||
490 | // Get size of display | |
491 | void wxDisplaySize(int *width, int *height) | |
492 | { | |
493 | #if wxMAC_USE_CORE_GRAPHICS | |
494 | // TODO adapt for multi-displays | |
495 | CGRect bounds = CGDisplayBounds(CGMainDisplayID()); | |
496 | if ( width ) | |
497 | *width = (int)bounds.size.width ; | |
498 | if ( height ) | |
499 | *height = (int)bounds.size.height; | |
500 | #else | |
501 | BitMap screenBits; | |
502 | GetQDGlobalsScreenBits( &screenBits ); | |
503 | ||
504 | if (width != NULL) | |
505 | *width = screenBits.bounds.right - screenBits.bounds.left; | |
506 | ||
507 | if (height != NULL) | |
508 | *height = screenBits.bounds.bottom - screenBits.bounds.top; | |
509 | #endif | |
510 | } | |
511 | ||
512 | void wxDisplaySizeMM(int *width, int *height) | |
513 | { | |
514 | wxDisplaySize(width, height); | |
515 | // on mac 72 is fixed (at least now;-) | |
516 | float cvPt2Mm = 25.4 / 72; | |
517 | ||
518 | if (width != NULL) | |
519 | *width = int( *width * cvPt2Mm ); | |
520 | ||
521 | if (height != NULL) | |
522 | *height = int( *height * cvPt2Mm ); | |
523 | } | |
524 | ||
525 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) | |
526 | { | |
527 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 | |
528 | HIRect bounds ; | |
529 | HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal, | |
530 | &bounds); | |
531 | if ( x ) | |
532 | *x = bounds.origin.x; | |
533 | if ( y ) | |
534 | *y = bounds.origin.y; | |
535 | if ( width ) | |
536 | *width = bounds.size.width; | |
537 | if ( height ) | |
538 | *height = bounds.size.height; | |
539 | #else | |
540 | Rect r; | |
541 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ); | |
542 | if ( x ) | |
543 | *x = r.left; | |
544 | if ( y ) | |
545 | *y = r.top; | |
546 | if ( width ) | |
547 | *width = r.right - r.left; | |
548 | if ( height ) | |
549 | *height = r.bottom - r.top; | |
550 | #endif | |
551 | } | |
552 | ||
553 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
554 | { | |
555 | return wxGenericFindWindowAtPoint(pt); | |
556 | } | |
557 | ||
558 | #endif // wxUSE_GUI | |
559 | ||
560 | #if wxUSE_BASE | |
561 | ||
562 | wxString wxGetOsDescription() | |
563 | { | |
564 | #ifdef WXWIN_OS_DESCRIPTION | |
565 | // use configure generated description if available | |
566 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); | |
567 | #else | |
568 | return wxT("MacOS"); //TODO:define further | |
569 | #endif | |
570 | } | |
571 | ||
572 | #ifndef __DARWIN__ | |
573 | wxChar *wxGetUserHome (const wxString& user) | |
574 | { | |
575 | // TODO | |
576 | return NULL; | |
577 | } | |
578 | ||
579 | bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) | |
580 | { | |
581 | if ( path.empty() ) | |
582 | return false; | |
583 | ||
584 | wxString p = path; | |
585 | if (p[0u] == ':' ) | |
586 | p = wxGetCwd() + p; | |
587 | ||
588 | int pos = p.Find(':'); | |
589 | if ( pos != wxNOT_FOUND ) | |
590 | p = p.Mid(1,pos); | |
591 | ||
592 | p = p + wxT(":"); | |
593 | ||
594 | OSErr err = noErr; | |
595 | ||
596 | FSRef fsRef; | |
597 | err = wxMacPathToFSRef( p , &fsRef ); | |
598 | if ( noErr == err ) | |
599 | { | |
600 | FSVolumeRefNum vRefNum; | |
601 | err = FSGetVRefNum( &fsRef , &vRefNum ); | |
602 | if ( noErr == err ) | |
603 | { | |
604 | UInt64 freeBytes , totalBytes; | |
605 | err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ); | |
606 | if ( noErr == err ) | |
607 | { | |
608 | if ( pTotal ) | |
609 | *pTotal = wxDiskspaceSize_t( totalBytes ); | |
610 | if ( pFree ) | |
611 | *pFree = wxDiskspaceSize_t( freeBytes ); | |
612 | } | |
613 | } | |
614 | } | |
615 | ||
616 | return err == noErr; | |
617 | } | |
618 | #endif // !__DARWIN__ | |
619 | ||
620 | //--------------------------------------------------------------------------- | |
621 | // wxMac Specific utility functions | |
622 | //--------------------------------------------------------------------------- | |
623 | ||
624 | void wxMacStringToPascal( const wxString&from , StringPtr to ) | |
625 | { | |
626 | wxCharBuffer buf = from.mb_str( wxConvLocal ); | |
627 | int len = strlen(buf); | |
628 | ||
629 | if ( len > 255 ) | |
630 | len = 255; | |
631 | to[0] = len; | |
632 | memcpy( (char*) &to[1] , buf , len ); | |
633 | } | |
634 | ||
635 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) | |
636 | { | |
637 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ); | |
638 | } | |
639 | ||
640 | // ---------------------------------------------------------------------------- | |
641 | // Common Event Support | |
642 | // ---------------------------------------------------------------------------- | |
643 | ||
644 | extern ProcessSerialNumber gAppProcess; | |
645 | ||
646 | void wxMacWakeUp() | |
647 | { | |
648 | ProcessSerialNumber psn; | |
649 | Boolean isSame; | |
650 | psn.highLongOfPSN = 0; | |
651 | psn.lowLongOfPSN = kCurrentProcess; | |
652 | SameProcess( &gAppProcess , &psn , &isSame ); | |
653 | if ( isSame ) | |
654 | { | |
655 | #if TARGET_CARBON | |
656 | OSStatus err = noErr; | |
657 | ||
658 | #if 0 | |
659 | // lead sometimes to race conditions, although all calls used should be thread safe ... | |
660 | static wxMacCarbonEvent s_wakeupEvent; | |
661 | if ( !s_wakeupEvent.IsValid() ) | |
662 | { | |
663 | err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), | |
664 | kEventAttributeNone ); | |
665 | } | |
666 | if ( err == noErr ) | |
667 | { | |
668 | ||
669 | if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) ) | |
670 | return; | |
671 | s_wakeupEvent.SetCurrentTime(); | |
672 | err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent, | |
673 | kEventPriorityHigh ); | |
674 | } | |
675 | #else | |
676 | wxMacCarbonEvent wakeupEvent; | |
677 | wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), | |
678 | kEventAttributeNone ); | |
679 | err = PostEventToQueue(GetMainEventQueue(), wakeupEvent, | |
680 | kEventPriorityHigh ); | |
681 | #endif | |
682 | #else | |
683 | PostEvent( nullEvent , 0 ); | |
684 | #endif | |
685 | } | |
686 | else | |
687 | { | |
688 | WakeUpProcess( &gAppProcess ); | |
689 | } | |
690 | } | |
691 | ||
692 | #endif // wxUSE_BASE | |
693 | ||
694 | #if wxUSE_GUI | |
695 | ||
696 | // ---------------------------------------------------------------------------- | |
697 | // Native Struct Conversions | |
698 | // ---------------------------------------------------------------------------- | |
699 | ||
700 | void wxMacRectToNative( const wxRect *wx , Rect *n ) | |
701 | { | |
702 | n->left = wx->x; | |
703 | n->top = wx->y; | |
704 | n->right = wx->x + wx->width; | |
705 | n->bottom = wx->y + wx->height; | |
706 | } | |
707 | ||
708 | void wxMacNativeToRect( const Rect *n , wxRect* wx ) | |
709 | { | |
710 | wx->x = n->left; | |
711 | wx->y = n->top; | |
712 | wx->width = n->right - n->left; | |
713 | wx->height = n->bottom - n->top; | |
714 | } | |
715 | ||
716 | void wxMacPointToNative( const wxPoint* wx , Point *n ) | |
717 | { | |
718 | n->h = wx->x; | |
719 | n->v = wx->y; | |
720 | } | |
721 | ||
722 | void wxMacNativeToPoint( const Point *n , wxPoint* wx ) | |
723 | { | |
724 | wx->x = n->h; | |
725 | wx->y = n->v; | |
726 | } | |
727 | ||
728 | // ---------------------------------------------------------------------------- | |
729 | // Carbon Event Support | |
730 | // ---------------------------------------------------------------------------- | |
731 | ||
732 | OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) | |
733 | { | |
734 | return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ); | |
735 | } | |
736 | ||
737 | OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) | |
738 | { | |
739 | return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ); | |
740 | } | |
741 | ||
742 | // ---------------------------------------------------------------------------- | |
743 | // Control Access Support | |
744 | // ---------------------------------------------------------------------------- | |
745 | ||
746 | IMPLEMENT_DYNAMIC_CLASS( wxMacControl , wxObject ) | |
747 | ||
748 | wxMacControl::wxMacControl() | |
749 | { | |
750 | Init(); | |
751 | } | |
752 | ||
753 | wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl ) | |
754 | { | |
755 | Init(); | |
756 | m_peer = peer; | |
757 | m_isRootControl = isRootControl; | |
758 | } | |
759 | ||
760 | wxMacControl::wxMacControl( wxWindow* peer , ControlRef control ) | |
761 | { | |
762 | Init(); | |
763 | m_peer = peer; | |
764 | m_controlRef = control; | |
765 | } | |
766 | ||
767 | wxMacControl::wxMacControl( wxWindow* peer , WXWidget control ) | |
768 | { | |
769 | Init(); | |
770 | m_peer = peer; | |
771 | m_controlRef = (ControlRef) control; | |
772 | } | |
773 | ||
774 | wxMacControl::~wxMacControl() | |
775 | { | |
776 | } | |
777 | ||
778 | void wxMacControl::Init() | |
779 | { | |
780 | m_peer = NULL; | |
781 | m_controlRef = NULL; | |
782 | m_needsFocusRect = false; | |
783 | m_isRootControl = false; | |
784 | } | |
785 | ||
786 | void wxMacControl::Dispose() | |
787 | { | |
788 | wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") ); | |
789 | wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") ); | |
790 | ||
791 | // we cannot check the ref count here anymore, as autorelease objects might delete their refs later | |
792 | CFRelease(m_controlRef); | |
793 | m_controlRef = NULL; | |
794 | } | |
795 | ||
796 | void wxMacControl::SetReference( URefCon data ) | |
797 | { | |
798 | SetControlReference( m_controlRef , data ); | |
799 | } | |
800 | ||
801 | OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const | |
802 | { | |
803 | return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ); | |
804 | } | |
805 | ||
806 | OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const | |
807 | { | |
808 | return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ); | |
809 | } | |
810 | ||
811 | OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) | |
812 | { | |
813 | return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ); | |
814 | } | |
815 | ||
816 | OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) | |
817 | { | |
818 | #if TARGET_API_MAC_OSX | |
819 | return SendEventToEventTargetWithOptions( event, | |
820 | HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); | |
821 | #else | |
822 | #pragma unused(inOptions) | |
823 | return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ); | |
824 | #endif | |
825 | } | |
826 | ||
827 | OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) | |
828 | { | |
829 | wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ); | |
830 | ||
831 | event.SetParameter<HICommand>(kEventParamDirectObject,command); | |
832 | ||
833 | return SendEvent( event , inOptions ); | |
834 | } | |
835 | ||
836 | OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) | |
837 | { | |
838 | HICommand command; | |
839 | ||
840 | memset( &command, 0 , sizeof(command) ); | |
841 | command.commandID = commandID; | |
842 | return SendHICommand( command , inOptions ); | |
843 | } | |
844 | ||
845 | void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) | |
846 | { | |
847 | unsigned long finalTicks; | |
848 | ||
849 | HiliteControl( m_controlRef , part ); | |
850 | Delay( ticks , &finalTicks ); | |
851 | HiliteControl( m_controlRef , kControlNoPart ); | |
852 | } | |
853 | ||
854 | SInt32 wxMacControl::GetValue() const | |
855 | { | |
856 | return ::GetControl32BitValue( m_controlRef ); | |
857 | } | |
858 | ||
859 | SInt32 wxMacControl::GetMaximum() const | |
860 | { | |
861 | return ::GetControl32BitMaximum( m_controlRef ); | |
862 | } | |
863 | ||
864 | SInt32 wxMacControl::GetMinimum() const | |
865 | { | |
866 | return ::GetControl32BitMinimum( m_controlRef ); | |
867 | } | |
868 | ||
869 | void wxMacControl::SetValue( SInt32 v ) | |
870 | { | |
871 | ::SetControl32BitValue( m_controlRef , v ); | |
872 | } | |
873 | ||
874 | void wxMacControl::SetMinimum( SInt32 v ) | |
875 | { | |
876 | ::SetControl32BitMinimum( m_controlRef , v ); | |
877 | } | |
878 | ||
879 | void wxMacControl::SetMaximum( SInt32 v ) | |
880 | { | |
881 | ::SetControl32BitMaximum( m_controlRef , v ); | |
882 | } | |
883 | ||
884 | void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) | |
885 | { | |
886 | ::SetControl32BitMinimum( m_controlRef , minimum ); | |
887 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
888 | ::SetControl32BitValue( m_controlRef , value ); | |
889 | } | |
890 | ||
891 | OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) | |
892 | { | |
893 | return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart ); | |
894 | } | |
895 | ||
896 | bool wxMacControl::HasFocus() const | |
897 | { | |
898 | ControlRef control; | |
899 | GetKeyboardFocus( GetUserFocusWindow() , &control ); | |
900 | return control == m_controlRef; | |
901 | } | |
902 | ||
903 | void wxMacControl::SetNeedsFocusRect( bool needs ) | |
904 | { | |
905 | m_needsFocusRect = needs; | |
906 | } | |
907 | ||
908 | bool wxMacControl::NeedsFocusRect() const | |
909 | { | |
910 | return m_needsFocusRect; | |
911 | } | |
912 | ||
913 | void wxMacControl::VisibilityChanged(bool shown) | |
914 | { | |
915 | } | |
916 | ||
917 | void wxMacControl::SuperChangedPosition() | |
918 | { | |
919 | } | |
920 | ||
921 | void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) | |
922 | { | |
923 | m_font = font; | |
924 | ControlFontStyleRec fontStyle; | |
925 | if ( font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
926 | { | |
927 | switch ( font.MacGetThemeFontID() ) | |
928 | { | |
929 | case kThemeSmallSystemFont : | |
930 | fontStyle.font = kControlFontSmallSystemFont; | |
931 | break; | |
932 | ||
933 | case 109 : // mini font | |
934 | fontStyle.font = -5; | |
935 | break; | |
936 | ||
937 | case kThemeSystemFont : | |
938 | fontStyle.font = kControlFontBigSystemFont; | |
939 | break; | |
940 | ||
941 | default : | |
942 | fontStyle.font = kControlFontBigSystemFont; | |
943 | break; | |
944 | } | |
945 | ||
946 | fontStyle.flags = kControlUseFontMask; | |
947 | } | |
948 | else | |
949 | { | |
950 | fontStyle.font = font.MacGetFontNum(); | |
951 | fontStyle.style = font.MacGetFontStyle(); | |
952 | fontStyle.size = font.MacGetFontSize(); | |
953 | fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask; | |
954 | } | |
955 | ||
956 | fontStyle.just = teJustLeft; | |
957 | fontStyle.flags |= kControlUseJustMask; | |
958 | if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) | |
959 | fontStyle.just = teJustCenter; | |
960 | else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) | |
961 | fontStyle.just = teJustRight; | |
962 | ||
963 | ||
964 | // we only should do this in case of a non-standard color, as otherwise 'disabled' controls | |
965 | // won't get grayed out by the system anymore | |
966 | ||
967 | if ( foreground != *wxBLACK ) | |
968 | { | |
969 | fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() ); | |
970 | fontStyle.flags |= kControlUseForeColorMask; | |
971 | } | |
972 | ||
973 | ::SetControlFontStyle( m_controlRef , &fontStyle ); | |
974 | } | |
975 | ||
976 | void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) ) | |
977 | { | |
978 | // TODO | |
979 | // setting up a color proc is not recommended anymore | |
980 | } | |
981 | ||
982 | void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) | |
983 | { | |
984 | ::SetControl32BitMinimum( m_controlRef , minimum ); | |
985 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
986 | } | |
987 | ||
988 | short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) | |
989 | { | |
990 | #ifndef __LP64__ | |
991 | return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ); | |
992 | #else | |
993 | return 0; | |
994 | #endif | |
995 | } | |
996 | ||
997 | void wxMacControl::SetActionProc( ControlActionUPP actionProc ) | |
998 | { | |
999 | SetControlAction( m_controlRef , actionProc ); | |
1000 | } | |
1001 | ||
1002 | void wxMacControl::SetViewSize( SInt32 viewSize ) | |
1003 | { | |
1004 | SetControlViewSize(m_controlRef , viewSize ); | |
1005 | } | |
1006 | ||
1007 | SInt32 wxMacControl::GetViewSize() const | |
1008 | { | |
1009 | return GetControlViewSize( m_controlRef ); | |
1010 | } | |
1011 | ||
1012 | bool wxMacControl::IsVisible() const | |
1013 | { | |
1014 | return IsControlVisible( m_controlRef ); | |
1015 | } | |
1016 | ||
1017 | void wxMacControl::SetVisibility( bool visible , bool redraw ) | |
1018 | { | |
1019 | SetControlVisibility( m_controlRef , visible , redraw ); | |
1020 | } | |
1021 | ||
1022 | bool wxMacControl::IsEnabled() const | |
1023 | { | |
1024 | #if TARGET_API_MAC_OSX | |
1025 | return IsControlEnabled( m_controlRef ); | |
1026 | #else | |
1027 | return IsControlActive( m_controlRef ); | |
1028 | #endif | |
1029 | } | |
1030 | ||
1031 | bool wxMacControl::IsActive() const | |
1032 | { | |
1033 | return IsControlActive( m_controlRef ); | |
1034 | } | |
1035 | ||
1036 | void wxMacControl::Enable( bool enable ) | |
1037 | { | |
1038 | if ( enable ) | |
1039 | EnableControl( m_controlRef ); | |
1040 | else | |
1041 | DisableControl( m_controlRef ); | |
1042 | } | |
1043 | ||
1044 | void wxMacControl::SetDrawingEnabled( bool enable ) | |
1045 | { | |
1046 | HIViewSetDrawingEnabled( m_controlRef , enable ); | |
1047 | } | |
1048 | ||
1049 | bool wxMacControl::GetNeedsDisplay() const | |
1050 | { | |
1051 | return HIViewGetNeedsDisplay( m_controlRef ); | |
1052 | } | |
1053 | ||
1054 | void wxMacControl::SetNeedsDisplay( RgnHandle where ) | |
1055 | { | |
1056 | if ( !IsVisible() ) | |
1057 | return; | |
1058 | ||
1059 | HIViewSetNeedsDisplayInRegion( m_controlRef , where , true ); | |
1060 | } | |
1061 | ||
1062 | void wxMacControl::SetNeedsDisplay( Rect* where ) | |
1063 | { | |
1064 | if ( !IsVisible() ) | |
1065 | return; | |
1066 | ||
1067 | if ( where != NULL ) | |
1068 | { | |
1069 | RgnHandle update = NewRgn(); | |
1070 | RectRgn( update , where ); | |
1071 | HIViewSetNeedsDisplayInRegion( m_controlRef , update , true ); | |
1072 | DisposeRgn( update ); | |
1073 | } | |
1074 | else | |
1075 | HIViewSetNeedsDisplay( m_controlRef , true ); | |
1076 | } | |
1077 | ||
1078 | void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) | |
1079 | { | |
1080 | HIPoint hiPoint; | |
1081 | ||
1082 | hiPoint.x = pt->x; | |
1083 | hiPoint.y = pt->y; | |
1084 | HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ); | |
1085 | pt->x = (int)hiPoint.x; | |
1086 | pt->y = (int)hiPoint.y; | |
1087 | } | |
1088 | ||
1089 | void wxMacControl::SetRect( Rect *r ) | |
1090 | { | |
1091 | //A HIRect is actually a CGRect on OSX - which consists of two structures - | |
1092 | //CGPoint and CGSize, which have two floats each | |
1093 | HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } }; | |
1094 | HIViewSetFrame ( m_controlRef , &hir ); | |
1095 | // eventuall we might have to do a SetVisibility( false , true ); | |
1096 | // before and a SetVisibility( true , true ); after | |
1097 | } | |
1098 | ||
1099 | void wxMacControl::GetRect( Rect *r ) | |
1100 | { | |
1101 | GetControlBounds( m_controlRef , r ); | |
1102 | } | |
1103 | ||
1104 | void wxMacControl::GetRectInWindowCoords( Rect *r ) | |
1105 | { | |
1106 | UMAGetControlBoundsInWindowCoords( m_controlRef , r ); | |
1107 | } | |
1108 | ||
1109 | void wxMacControl::GetBestRect( Rect *r ) | |
1110 | { | |
1111 | short baselineoffset; | |
1112 | ||
1113 | GetBestControlRect( m_controlRef , r , &baselineoffset ); | |
1114 | } | |
1115 | ||
1116 | void wxMacControl::SetLabel( const wxString &title ) | |
1117 | { | |
1118 | wxFontEncoding encoding; | |
1119 | ||
1120 | if ( m_font.Ok() ) | |
1121 | encoding = m_font.GetEncoding(); | |
1122 | else | |
1123 | encoding = wxFont::GetDefaultEncoding(); | |
1124 | ||
1125 | UMASetControlTitle( m_controlRef , title , encoding ); | |
1126 | } | |
1127 | ||
1128 | void wxMacControl::GetFeatures( UInt32 * features ) | |
1129 | { | |
1130 | GetControlFeatures( m_controlRef , features ); | |
1131 | } | |
1132 | ||
1133 | OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) | |
1134 | { | |
1135 | OSStatus err = GetControlRegion( m_controlRef , partCode , region ); | |
1136 | return err; | |
1137 | } | |
1138 | ||
1139 | OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) | |
1140 | { | |
1141 | #if TARGET_API_MAC_OSX | |
1142 | return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, | |
1143 | (other != NULL) ? other->m_controlRef : NULL); | |
1144 | #else | |
1145 | return 0; | |
1146 | #endif | |
1147 | } | |
1148 | ||
1149 | #if TARGET_API_MAC_OSX | |
1150 | // SetNeedsDisplay would not invalidate the children | |
1151 | static void InvalidateControlAndChildren( HIViewRef control ) | |
1152 | { | |
1153 | HIViewSetNeedsDisplay( control , true ); | |
1154 | UInt16 childrenCount = 0; | |
1155 | OSStatus err = CountSubControls( control , &childrenCount ); | |
1156 | if ( err == errControlIsNotEmbedder ) | |
1157 | return; | |
1158 | ||
1159 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ); | |
1160 | ||
1161 | for ( UInt16 i = childrenCount; i >=1; --i ) | |
1162 | { | |
1163 | HIViewRef child; | |
1164 | ||
1165 | err = GetIndexedSubControl( control , i , & child ); | |
1166 | if ( err == errControlIsNotEmbedder ) | |
1167 | return; | |
1168 | ||
1169 | InvalidateControlAndChildren( child ); | |
1170 | } | |
1171 | } | |
1172 | #endif | |
1173 | ||
1174 | void wxMacControl::InvalidateWithChildren() | |
1175 | { | |
1176 | #if TARGET_API_MAC_OSX | |
1177 | InvalidateControlAndChildren( m_controlRef ); | |
1178 | #endif | |
1179 | } | |
1180 | ||
1181 | void wxMacControl::ScrollRect( wxRect *r , int dx , int dy ) | |
1182 | { | |
1183 | wxASSERT( r != NULL ); | |
1184 | ||
1185 | HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height); | |
1186 | HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ); | |
1187 | } | |
1188 | ||
1189 | OSType wxMacCreator = 'WXMC'; | |
1190 | OSType wxMacControlProperty = 'MCCT'; | |
1191 | ||
1192 | void wxMacControl::SetReferenceInNativeControl() | |
1193 | { | |
1194 | void * data = this; | |
1195 | verify_noerr( SetControlProperty ( m_controlRef , | |
1196 | wxMacCreator,wxMacControlProperty, sizeof(data), &data ) ); | |
1197 | } | |
1198 | ||
1199 | wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control) | |
1200 | { | |
1201 | wxMacControl* ctl = NULL; | |
1202 | ByteCount actualSize; | |
1203 | if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) , | |
1204 | &actualSize , &ctl ) == noErr ) | |
1205 | { | |
1206 | return ctl; | |
1207 | } | |
1208 | return NULL; | |
1209 | } | |
1210 | ||
1211 | // ============================================================================ | |
1212 | // DataBrowser Wrapper | |
1213 | // ============================================================================ | |
1214 | // | |
1215 | // basing on DataBrowserItemIDs | |
1216 | // | |
1217 | ||
1218 | IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl ) | |
1219 | ||
1220 | pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc( | |
1221 | ControlRef browser, | |
1222 | DataBrowserItemID itemID, | |
1223 | DataBrowserItemNotification message, | |
1224 | DataBrowserItemDataRef itemData ) | |
1225 | { | |
1226 | wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl); | |
1227 | if ( ctl != 0 ) | |
1228 | { | |
1229 | ctl->ItemNotification(itemID, message, itemData); | |
1230 | } | |
1231 | } | |
1232 | ||
1233 | pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc( | |
1234 | ControlRef browser, | |
1235 | DataBrowserItemID itemID, | |
1236 | DataBrowserPropertyID property, | |
1237 | DataBrowserItemDataRef itemData, | |
1238 | Boolean changeValue ) | |
1239 | { | |
1240 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1241 | wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl); | |
1242 | if ( ctl != 0 ) | |
1243 | { | |
1244 | err = ctl->GetSetItemData(itemID, property, itemData, changeValue); | |
1245 | } | |
1246 | return err; | |
1247 | } | |
1248 | ||
1249 | pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc( | |
1250 | ControlRef browser, | |
1251 | DataBrowserItemID itemOneID, | |
1252 | DataBrowserItemID itemTwoID, | |
1253 | DataBrowserPropertyID sortProperty) | |
1254 | { | |
1255 | wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl); | |
1256 | if ( ctl != 0 ) | |
1257 | { | |
1258 | return ctl->CompareItems(itemOneID, itemTwoID, sortProperty); | |
1259 | } | |
1260 | return false; | |
1261 | } | |
1262 | ||
1263 | DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL; | |
1264 | DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL; | |
1265 | DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL; | |
1266 | ||
1267 | wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) : wxMacControl( peer ) | |
1268 | { | |
1269 | Rect bounds = wxMacGetBoundsForControl( peer, pos, size ); | |
1270 | OSStatus err = ::CreateDataBrowserControl( | |
1271 | MAC_WXHWND(peer->MacGetTopLevelWindowRef()), | |
1272 | &bounds, kDataBrowserListView, &m_controlRef ); | |
1273 | SetReferenceInNativeControl(); | |
1274 | verify_noerr( err ); | |
1275 | if ( gDataBrowserItemCompareUPP == NULL ) | |
1276 | gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc); | |
1277 | if ( gDataBrowserItemDataUPP == NULL ) | |
1278 | gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc); | |
1279 | if ( gDataBrowserItemNotificationUPP == NULL ) | |
1280 | { | |
1281 | gDataBrowserItemNotificationUPP = | |
1282 | #if TARGET_API_MAC_OSX | |
1283 | (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc); | |
1284 | #else | |
1285 | NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc); | |
1286 | #endif | |
1287 | } | |
1288 | ||
1289 | DataBrowserCallbacks callbacks; | |
1290 | InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks ); | |
1291 | ||
1292 | callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP; | |
1293 | callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP; | |
1294 | callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP; | |
1295 | SetCallbacks( &callbacks ); | |
1296 | ||
1297 | } | |
1298 | ||
1299 | OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container, | |
1300 | Boolean recurse, | |
1301 | DataBrowserItemState state, | |
1302 | ItemCount *numItems) const | |
1303 | { | |
1304 | return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems ); | |
1305 | } | |
1306 | ||
1307 | OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container, | |
1308 | Boolean recurse, | |
1309 | DataBrowserItemState state, | |
1310 | Handle items) const | |
1311 | { | |
1312 | return GetDataBrowserItems( m_controlRef, container, recurse, state, items ); | |
1313 | } | |
1314 | ||
1315 | OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options ) | |
1316 | { | |
1317 | return SetDataBrowserSelectionFlags( m_controlRef, options ); | |
1318 | } | |
1319 | ||
1320 | OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc, | |
1321 | DataBrowserTableViewColumnIndex position ) | |
1322 | { | |
1323 | return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position ); | |
1324 | } | |
1325 | ||
1326 | OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){ | |
1327 | return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id ); | |
1328 | } | |
1329 | ||
1330 | OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position ) | |
1331 | { | |
1332 | DataBrowserTableViewColumnID id; | |
1333 | GetColumnIDFromIndex( position, &id ); | |
1334 | return RemoveDataBrowserTableViewColumn( m_controlRef, id ); | |
1335 | } | |
1336 | ||
1337 | OSStatus wxMacDataBrowserControl::AutoSizeColumns() | |
1338 | { | |
1339 | return AutoSizeDataBrowserListViewColumns(m_controlRef); | |
1340 | } | |
1341 | ||
1342 | OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert ) | |
1343 | { | |
1344 | return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert ); | |
1345 | } | |
1346 | ||
1347 | OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) | |
1348 | { | |
1349 | return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle ); | |
1350 | } | |
1351 | ||
1352 | OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height) | |
1353 | { | |
1354 | return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1355 | } | |
1356 | ||
1357 | OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height) | |
1358 | { | |
1359 | return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1360 | } | |
1361 | ||
1362 | OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks) | |
1363 | { | |
1364 | return SetDataBrowserCallbacks( m_controlRef, callbacks ); | |
1365 | } | |
1366 | ||
1367 | OSStatus wxMacDataBrowserControl::UpdateItems( | |
1368 | DataBrowserItemID container, | |
1369 | UInt32 numItems, | |
1370 | const DataBrowserItemID *items, | |
1371 | DataBrowserPropertyID preSortProperty, | |
1372 | DataBrowserPropertyID propertyID ) const | |
1373 | { | |
1374 | return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID ); | |
1375 | } | |
1376 | ||
1377 | bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const | |
1378 | { | |
1379 | return IsDataBrowserItemSelected( m_controlRef, item ); | |
1380 | } | |
1381 | ||
1382 | OSStatus wxMacDataBrowserControl::AddItems( | |
1383 | DataBrowserItemID container, | |
1384 | UInt32 numItems, | |
1385 | const DataBrowserItemID *items, | |
1386 | DataBrowserPropertyID preSortProperty ) | |
1387 | { | |
1388 | return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1389 | } | |
1390 | ||
1391 | OSStatus wxMacDataBrowserControl::RemoveItems( | |
1392 | DataBrowserItemID container, | |
1393 | UInt32 numItems, | |
1394 | const DataBrowserItemID *items, | |
1395 | DataBrowserPropertyID preSortProperty ) | |
1396 | { | |
1397 | return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1398 | } | |
1399 | ||
1400 | OSStatus wxMacDataBrowserControl::RevealItem( | |
1401 | DataBrowserItemID item, | |
1402 | DataBrowserPropertyID propertyID, | |
1403 | DataBrowserRevealOptions options ) const | |
1404 | { | |
1405 | return RevealDataBrowserItem( m_controlRef, item, propertyID, options ); | |
1406 | } | |
1407 | ||
1408 | OSStatus wxMacDataBrowserControl::SetSelectedItems( | |
1409 | UInt32 numItems, | |
1410 | const DataBrowserItemID *items, | |
1411 | DataBrowserSetOption operation ) | |
1412 | { | |
1413 | return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation ); | |
1414 | } | |
1415 | ||
1416 | OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const | |
1417 | { | |
1418 | return GetDataBrowserSelectionAnchor( m_controlRef, first, last ); | |
1419 | } | |
1420 | ||
1421 | OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const | |
1422 | { | |
1423 | return GetDataBrowserTableViewItemID( m_controlRef, row, item ); | |
1424 | } | |
1425 | ||
1426 | OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const | |
1427 | { | |
1428 | return GetDataBrowserTableViewItemRow( m_controlRef, item, row ); | |
1429 | } | |
1430 | ||
1431 | OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height ) | |
1432 | { | |
1433 | return SetDataBrowserTableViewRowHeight( m_controlRef , height ); | |
1434 | } | |
1435 | ||
1436 | OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const | |
1437 | { | |
1438 | return GetDataBrowserTableViewRowHeight( m_controlRef, height ); | |
1439 | } | |
1440 | ||
1441 | OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height) | |
1442 | { | |
1443 | return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height ); | |
1444 | } | |
1445 | ||
1446 | OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const | |
1447 | { | |
1448 | return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height); | |
1449 | } | |
1450 | ||
1451 | OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const | |
1452 | { | |
1453 | return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1454 | } | |
1455 | ||
1456 | OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width ) | |
1457 | { | |
1458 | return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1459 | } | |
1460 | ||
1461 | OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const | |
1462 | { | |
1463 | return GetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1464 | } | |
1465 | ||
1466 | OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width ) | |
1467 | { | |
1468 | return SetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1469 | } | |
1470 | ||
1471 | OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const | |
1472 | { | |
1473 | return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns); | |
1474 | } | |
1475 | ||
1476 | OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column, | |
1477 | DataBrowserTableViewColumnIndex *position) const | |
1478 | { | |
1479 | return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1480 | } | |
1481 | ||
1482 | OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position) | |
1483 | { | |
1484 | return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1485 | } | |
1486 | ||
1487 | OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const | |
1488 | { | |
1489 | return GetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1490 | } | |
1491 | ||
1492 | OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left ) | |
1493 | { | |
1494 | return SetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1495 | } | |
1496 | ||
1497 | OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const | |
1498 | { | |
1499 | return GetDataBrowserSortProperty( m_controlRef , column ); | |
1500 | } | |
1501 | ||
1502 | OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column ) | |
1503 | { | |
1504 | return SetDataBrowserSortProperty( m_controlRef , column ); | |
1505 | } | |
1506 | ||
1507 | OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const | |
1508 | { | |
1509 | return GetDataBrowserSortOrder( m_controlRef , order ); | |
1510 | } | |
1511 | ||
1512 | OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order ) | |
1513 | { | |
1514 | return SetDataBrowserSortOrder( m_controlRef , order ); | |
1515 | } | |
1516 | ||
1517 | OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property, | |
1518 | DataBrowserPropertyFlags *flags ) const | |
1519 | { | |
1520 | return GetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1521 | } | |
1522 | ||
1523 | OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property, | |
1524 | DataBrowserPropertyFlags flags ) | |
1525 | { | |
1526 | return SetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1527 | } | |
1528 | ||
1529 | OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property, | |
1530 | DataBrowserListViewHeaderDesc *desc ) const | |
1531 | { | |
1532 | return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); | |
1533 | } | |
1534 | ||
1535 | OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property, | |
1536 | DataBrowserListViewHeaderDesc *desc ) | |
1537 | { | |
1538 | return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); | |
1539 | } | |
1540 | ||
1541 | OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property , | |
1542 | Boolean expandableRows ) | |
1543 | { | |
1544 | return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows); | |
1545 | } | |
1546 | ||
1547 | // ============================================================================ | |
1548 | // Higher-level Databrowser | |
1549 | // ============================================================================ | |
1550 | // | |
1551 | // basing on data item objects | |
1552 | // | |
1553 | ||
1554 | wxMacDataItem::wxMacDataItem() | |
1555 | { | |
1556 | m_data = NULL; | |
1557 | ||
1558 | m_order = 0; | |
1559 | m_colId = kTextColumnId; // for compat with existing wx*ListBox impls. | |
1560 | } | |
1561 | ||
1562 | wxMacDataItem::~wxMacDataItem() | |
1563 | { | |
1564 | } | |
1565 | ||
1566 | void wxMacDataItem::SetOrder( SInt32 order ) | |
1567 | { | |
1568 | m_order = order; | |
1569 | } | |
1570 | ||
1571 | SInt32 wxMacDataItem::GetOrder() const | |
1572 | { | |
1573 | return m_order; | |
1574 | } | |
1575 | ||
1576 | void wxMacDataItem::SetData( void* data) | |
1577 | { | |
1578 | m_data = data; | |
1579 | } | |
1580 | ||
1581 | void* wxMacDataItem::GetData() const | |
1582 | { | |
1583 | return m_data; | |
1584 | } | |
1585 | ||
1586 | short wxMacDataItem::GetColumn() | |
1587 | { | |
1588 | return m_colId; | |
1589 | } | |
1590 | ||
1591 | void wxMacDataItem::SetColumn( short col ) | |
1592 | { | |
1593 | m_colId = col; | |
1594 | } | |
1595 | ||
1596 | void wxMacDataItem::SetLabel( const wxString& str) | |
1597 | { | |
1598 | m_label = str; | |
1599 | m_cfLabel.Assign( str , wxLocale::GetSystemEncoding()); | |
1600 | } | |
1601 | ||
1602 | const wxString& wxMacDataItem::GetLabel() const | |
1603 | { | |
1604 | return m_label; | |
1605 | } | |
1606 | ||
1607 | bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *owner , | |
1608 | const wxMacDataItem* rhs, | |
1609 | DataBrowserPropertyID sortProperty) const | |
1610 | { | |
1611 | const wxMacDataItem* otherItem = wx_const_cast(wxMacDataItem*,rhs); | |
1612 | bool retval = false; | |
1613 | ||
1614 | if ( sortProperty == m_colId ){ | |
1615 | retval = m_label.CmpNoCase( otherItem->m_label) < 0; | |
1616 | } | |
1617 | ||
1618 | else if ( sortProperty == kNumericOrderColumnId ) | |
1619 | retval = m_order < otherItem->m_order; | |
1620 | ||
1621 | return retval; | |
1622 | } | |
1623 | ||
1624 | OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *owner , | |
1625 | DataBrowserPropertyID property, | |
1626 | DataBrowserItemDataRef itemData, | |
1627 | bool changeValue ) | |
1628 | { | |
1629 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1630 | if ( !changeValue ) | |
1631 | { | |
1632 | if ( property == m_colId ){ | |
1633 | err = ::SetDataBrowserItemDataText( itemData, m_cfLabel ); | |
1634 | err = noErr; | |
1635 | } | |
1636 | else if ( property == kNumericOrderColumnId ){ | |
1637 | err = ::SetDataBrowserItemDataValue( itemData, m_order ); | |
1638 | err = noErr; | |
1639 | } | |
1640 | else{ | |
1641 | } | |
1642 | } | |
1643 | else | |
1644 | { | |
1645 | switch (property) | |
1646 | { | |
1647 | // no editable props here | |
1648 | default: | |
1649 | break; | |
1650 | } | |
1651 | } | |
1652 | ||
1653 | return err; | |
1654 | } | |
1655 | ||
1656 | void wxMacDataItem::Notification(wxMacDataItemBrowserControl *owner , | |
1657 | DataBrowserItemNotification message, | |
1658 | DataBrowserItemDataRef itemData ) const | |
1659 | { | |
1660 | } | |
1661 | ||
1662 | IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl ) | |
1663 | ||
1664 | wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) : | |
1665 | wxMacDataBrowserControl( peer, pos, size, style ) | |
1666 | { | |
1667 | m_suppressSelection = false; | |
1668 | m_sortOrder = SortOrder_None; | |
1669 | m_clientDataItemsType = wxClientData_None; | |
1670 | } | |
1671 | ||
1672 | wxMacDataItem* wxMacDataItemBrowserControl::CreateItem() | |
1673 | { | |
1674 | return new wxMacDataItem(); | |
1675 | } | |
1676 | ||
1677 | wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser) | |
1678 | { | |
1679 | m_former = browser->SuppressSelection(true); | |
1680 | m_browser = browser; | |
1681 | } | |
1682 | ||
1683 | wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor() | |
1684 | { | |
1685 | m_browser->SuppressSelection(m_former); | |
1686 | } | |
1687 | ||
1688 | bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress ) | |
1689 | { | |
1690 | bool former = m_suppressSelection; | |
1691 | m_suppressSelection = suppress; | |
1692 | ||
1693 | return former; | |
1694 | } | |
1695 | ||
1696 | Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID, | |
1697 | DataBrowserItemID itemTwoID, | |
1698 | DataBrowserPropertyID sortProperty) | |
1699 | { | |
1700 | wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID; | |
1701 | wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID; | |
1702 | return CompareItems( itemOne , itemTwo , sortProperty ); | |
1703 | } | |
1704 | ||
1705 | Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne, | |
1706 | const wxMacDataItem* itemTwo, | |
1707 | DataBrowserPropertyID sortProperty) | |
1708 | { | |
1709 | Boolean retval = false; | |
1710 | if ( itemOne != NULL ) | |
1711 | retval = itemOne->IsLessThan( this , itemTwo , sortProperty); | |
1712 | return retval; | |
1713 | } | |
1714 | ||
1715 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1716 | DataBrowserItemID itemID, | |
1717 | DataBrowserPropertyID property, | |
1718 | DataBrowserItemDataRef itemData, | |
1719 | Boolean changeValue ) | |
1720 | { | |
1721 | wxMacDataItem* item = (wxMacDataItem*) itemID; | |
1722 | return GetSetItemData(item, property, itemData , changeValue ); | |
1723 | } | |
1724 | ||
1725 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1726 | wxMacDataItem* item, | |
1727 | DataBrowserPropertyID property, | |
1728 | DataBrowserItemDataRef itemData, | |
1729 | Boolean changeValue ) | |
1730 | { | |
1731 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1732 | switch( property ) | |
1733 | { | |
1734 | case kDataBrowserContainerIsClosableProperty : | |
1735 | case kDataBrowserContainerIsSortableProperty : | |
1736 | case kDataBrowserContainerIsOpenableProperty : | |
1737 | // right now default behaviour on these | |
1738 | break; | |
1739 | default : | |
1740 | ||
1741 | if ( item != NULL ){ | |
1742 | err = item->GetSetData( this, property , itemData , changeValue ); | |
1743 | } | |
1744 | break; | |
1745 | ||
1746 | } | |
1747 | return err; | |
1748 | } | |
1749 | ||
1750 | void wxMacDataItemBrowserControl::ItemNotification( | |
1751 | DataBrowserItemID itemID, | |
1752 | DataBrowserItemNotification message, | |
1753 | DataBrowserItemDataRef itemData) | |
1754 | { | |
1755 | wxMacDataItem* item = (wxMacDataItem*) itemID; | |
1756 | ItemNotification( item , message, itemData); | |
1757 | } | |
1758 | ||
1759 | void wxMacDataItemBrowserControl::ItemNotification( | |
1760 | const wxMacDataItem* item, | |
1761 | DataBrowserItemNotification message, | |
1762 | DataBrowserItemDataRef itemData) | |
1763 | { | |
1764 | if (item != NULL) | |
1765 | item->Notification( this, message, itemData); | |
1766 | } | |
1767 | ||
1768 | unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container, | |
1769 | bool recurse , DataBrowserItemState state) const | |
1770 | { | |
1771 | ItemCount numItems = 0; | |
1772 | verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container, | |
1773 | recurse, state, &numItems ) ); | |
1774 | return numItems; | |
1775 | } | |
1776 | ||
1777 | unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container, | |
1778 | bool recurse ) const | |
1779 | { | |
1780 | return GetItemCount( container, recurse, kDataBrowserItemIsSelected ); | |
1781 | ||
1782 | } | |
1783 | ||
1784 | void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container, | |
1785 | bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const | |
1786 | { | |
1787 | Handle handle = NewHandle(0); | |
1788 | verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container , | |
1789 | recurse , state, handle) ); | |
1790 | ||
1791 | int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID); | |
1792 | HLock( handle ); | |
1793 | wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle; | |
1794 | for ( int i = 0; i < itemCount; ++i) | |
1795 | { | |
1796 | items.Add(itemsArray[i]); | |
1797 | } | |
1798 | HUnlock( handle ); | |
1799 | DisposeHandle( handle ); | |
1800 | } | |
1801 | ||
1802 | unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const | |
1803 | { | |
1804 | DataBrowserTableViewRowIndex row; | |
1805 | OSStatus err = GetItemRow( (DataBrowserItemID) item , &row); | |
1806 | wxASSERT( err == noErr); | |
1807 | return row; | |
1808 | } | |
1809 | ||
1810 | wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const | |
1811 | { | |
1812 | DataBrowserItemID id; | |
1813 | OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id); | |
1814 | wxASSERT( err == noErr); | |
1815 | return (wxMacDataItem*) id; | |
1816 | } | |
1817 | ||
1818 | void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container, | |
1819 | const wxMacDataItem *item , DataBrowserPropertyID property) const | |
1820 | { | |
1821 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1, | |
1822 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) ); | |
1823 | } | |
1824 | ||
1825 | void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container, | |
1826 | wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const | |
1827 | { | |
1828 | unsigned int noItems = itemArray.GetCount(); | |
1829 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1830 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1831 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1832 | ||
1833 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems, | |
1834 | items, kDataBrowserItemNoProperty /* notSorted */, property ) ); | |
1835 | delete [] items; | |
1836 | } | |
1837 | ||
1838 | void wxMacDataItemBrowserControl::InsertColumn(int colId, DataBrowserPropertyType colType, | |
1839 | const wxString& title, SInt16 just, int defaultWidth) | |
1840 | { | |
1841 | DataBrowserListViewColumnDesc columnDesc; | |
1842 | columnDesc.headerBtnDesc.titleOffset = 0; | |
1843 | columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
1844 | ||
1845 | columnDesc.headerBtnDesc.btnFontStyle.flags = | |
1846 | kControlUseFontMask | kControlUseJustMask; | |
1847 | ||
1848 | columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly; | |
1849 | columnDesc.headerBtnDesc.btnFontStyle.just = just; | |
1850 | columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
1851 | columnDesc.headerBtnDesc.btnFontStyle.style = normal; | |
1852 | ||
1853 | // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is | |
1854 | // defined for other modes? | |
1855 | wxFontEncoding enc; | |
1856 | if ( m_font.Ok() ) | |
1857 | enc = m_font.GetEncoding(); | |
1858 | else | |
1859 | enc = wxLocale::GetSystemEncoding(); | |
1860 | wxMacCFStringHolder cfTitle; | |
1861 | cfTitle.Assign( title, enc ); | |
1862 | columnDesc.headerBtnDesc.titleString = cfTitle; | |
1863 | ||
1864 | columnDesc.headerBtnDesc.minimumWidth = 0; | |
1865 | columnDesc.headerBtnDesc.maximumWidth = 30000; | |
1866 | ||
1867 | columnDesc.propertyDesc.propertyID = (kMinColumnId + colId); | |
1868 | columnDesc.propertyDesc.propertyType = colType; | |
1869 | columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn; | |
1870 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
1871 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; | |
1872 | #endif | |
1873 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 | |
1874 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; | |
1875 | #endif | |
1876 | ||
1877 | verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); | |
1878 | ||
1879 | if (defaultWidth > 0){ | |
1880 | SetColumnWidth(colId, defaultWidth); | |
1881 | } | |
1882 | ||
1883 | } | |
1884 | ||
1885 | void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width) | |
1886 | { | |
1887 | DataBrowserPropertyID id; | |
1888 | GetColumnIDFromIndex(colId, &id); | |
1889 | verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width)); | |
1890 | } | |
1891 | ||
1892 | int wxMacDataItemBrowserControl::GetColumnWidth(int colId) | |
1893 | { | |
1894 | DataBrowserPropertyID id; | |
1895 | GetColumnIDFromIndex(colId, &id); | |
1896 | UInt16 result; | |
1897 | verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result)); | |
1898 | return result; | |
1899 | } | |
1900 | ||
1901 | void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item) | |
1902 | { | |
1903 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1, | |
1904 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) ); | |
1905 | } | |
1906 | ||
1907 | void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray ) | |
1908 | { | |
1909 | unsigned int noItems = itemArray.GetCount(); | |
1910 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1911 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1912 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1913 | ||
1914 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems, | |
1915 | (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) ); | |
1916 | delete [] items; | |
1917 | } | |
1918 | ||
1919 | void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item) | |
1920 | { | |
1921 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1, | |
1922 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ); | |
1923 | verify_noerr( err ); | |
1924 | } | |
1925 | ||
1926 | void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray) | |
1927 | { | |
1928 | unsigned int noItems = itemArray.GetCount(); | |
1929 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1930 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1931 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1932 | ||
1933 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems, | |
1934 | (DataBrowserItemID*) items, kDataBrowserItemNoProperty ); | |
1935 | verify_noerr( err ); | |
1936 | delete [] items; | |
1937 | } | |
1938 | ||
1939 | void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container) | |
1940 | { | |
1941 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty ); | |
1942 | verify_noerr( err ); | |
1943 | } | |
1944 | ||
1945 | void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option) | |
1946 | { | |
1947 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option )); | |
1948 | } | |
1949 | ||
1950 | void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option) | |
1951 | { | |
1952 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option )); | |
1953 | } | |
1954 | ||
1955 | void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option) | |
1956 | { | |
1957 | unsigned int noItems = itemArray.GetCount(); | |
1958 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1959 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1960 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1961 | ||
1962 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option )); | |
1963 | delete [] items; | |
1964 | } | |
1965 | ||
1966 | Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const | |
1967 | { | |
1968 | return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item); | |
1969 | } | |
1970 | ||
1971 | void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options) | |
1972 | { | |
1973 | verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) ); | |
1974 | } | |
1975 | ||
1976 | void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const | |
1977 | { | |
1978 | verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) ); | |
1979 | } | |
1980 | ||
1981 | wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const | |
1982 | { | |
1983 | return m_clientDataItemsType; | |
1984 | } | |
1985 | void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType) | |
1986 | { | |
1987 | m_clientDataItemsType = clientDataItemsType; | |
1988 | } | |
1989 | ||
1990 | unsigned int wxMacDataItemBrowserControl::MacGetCount() const | |
1991 | { | |
1992 | return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState); | |
1993 | } | |
1994 | ||
1995 | void wxMacDataItemBrowserControl::MacDelete( unsigned int n ) | |
1996 | { | |
1997 | wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n ); | |
1998 | RemoveItem( wxMacDataBrowserRootContainer, item ); | |
1999 | } | |
2000 | ||
2001 | void wxMacDataItemBrowserControl::MacInsert( unsigned int n, const wxString& text, int column ) | |
2002 | { | |
2003 | wxMacDataItem* newItem = CreateItem(); | |
2004 | newItem->SetLabel( text ); | |
2005 | if ( column != -1 ) | |
2006 | newItem->SetColumn( kMinColumnId + column ); | |
2007 | ||
2008 | if ( m_sortOrder == SortOrder_None ) | |
2009 | { | |
2010 | // increase the order of the lines to be shifted | |
2011 | unsigned int lines = MacGetCount(); | |
2012 | for ( unsigned int i = n; i < lines; ++i) | |
2013 | { | |
2014 | wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i); | |
2015 | iter->SetOrder( iter->GetOrder() + 1 ); | |
2016 | } | |
2017 | ||
2018 | SInt32 frontLineOrder = 0; | |
2019 | if ( n > 0 ) | |
2020 | { | |
2021 | wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1); | |
2022 | frontLineOrder = iter->GetOrder(); | |
2023 | } | |
2024 | newItem->SetOrder( frontLineOrder + 1 ); | |
2025 | } | |
2026 | ||
2027 | AddItem( wxMacDataBrowserRootContainer, newItem ); | |
2028 | } | |
2029 | ||
2030 | void wxMacDataItemBrowserControl::MacInsert( unsigned int n, const wxArrayString& items, int column ) | |
2031 | { | |
2032 | size_t itemsCount = items.GetCount(); | |
2033 | if ( itemsCount == 0 ) | |
2034 | return; | |
2035 | ||
2036 | SInt32 frontLineOrder = 0; | |
2037 | ||
2038 | if ( m_sortOrder == SortOrder_None ) | |
2039 | { | |
2040 | // increase the order of the lines to be shifted | |
2041 | unsigned int lines = MacGetCount(); | |
2042 | for ( unsigned int i = n; i < lines; ++i) | |
2043 | { | |
2044 | wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i); | |
2045 | iter->SetOrder( iter->GetOrder() + itemsCount ); | |
2046 | } | |
2047 | if ( n > 0 ) | |
2048 | { | |
2049 | wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1); | |
2050 | frontLineOrder = iter->GetOrder(); | |
2051 | } | |
2052 | } | |
2053 | ||
2054 | wxArrayMacDataItemPtr ids; | |
2055 | ids.SetCount( itemsCount ); | |
2056 | ||
2057 | for ( unsigned int i = 0; i < itemsCount; ++i ) | |
2058 | { | |
2059 | wxMacDataItem* item = CreateItem(); | |
2060 | item->SetLabel( items[i]); | |
2061 | if ( column != -1 ) | |
2062 | item->SetColumn( kMinColumnId + column ); | |
2063 | ||
2064 | if ( m_sortOrder == SortOrder_None ) | |
2065 | item->SetOrder( frontLineOrder + 1 + i ); | |
2066 | ||
2067 | ids[i] = item; | |
2068 | } | |
2069 | ||
2070 | AddItems( wxMacDataBrowserRootContainer, ids ); | |
2071 | } | |
2072 | ||
2073 | int wxMacDataItemBrowserControl::MacAppend( const wxString& text) | |
2074 | { | |
2075 | wxMacDataItem* item = CreateItem(); | |
2076 | item->SetLabel( text ); | |
2077 | if ( m_sortOrder == SortOrder_None ) | |
2078 | { | |
2079 | unsigned int lines = MacGetCount(); | |
2080 | if ( lines == 0 ) | |
2081 | item->SetOrder( 1 ); | |
2082 | else | |
2083 | { | |
2084 | wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1); | |
2085 | item->SetOrder( frontItem->GetOrder() + 1 ); | |
2086 | } | |
2087 | } | |
2088 | AddItem( wxMacDataBrowserRootContainer, item ); | |
2089 | ||
2090 | return GetLineFromItem(item); | |
2091 | } | |
2092 | ||
2093 | void wxMacDataItemBrowserControl::MacClear() | |
2094 | { | |
2095 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
2096 | RemoveAllItems(wxMacDataBrowserRootContainer); | |
2097 | } | |
2098 | ||
2099 | void wxMacDataItemBrowserControl::MacDeselectAll() | |
2100 | { | |
2101 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
2102 | SetSelectedAllItems( kDataBrowserItemsRemove ); | |
2103 | } | |
2104 | ||
2105 | void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi ) | |
2106 | { | |
2107 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); | |
2108 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
2109 | ||
2110 | if ( IsItemSelected( item ) != select ) | |
2111 | { | |
2112 | if ( select ) | |
2113 | SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign ); | |
2114 | else | |
2115 | SetSelectedItem( item, kDataBrowserItemsRemove ); | |
2116 | } | |
2117 | ||
2118 | MacScrollTo( n ); | |
2119 | } | |
2120 | ||
2121 | bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const | |
2122 | { | |
2123 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); | |
2124 | return IsItemSelected( item ); | |
2125 | } | |
2126 | ||
2127 | int wxMacDataItemBrowserControl::MacGetSelection() const | |
2128 | { | |
2129 | wxMacDataItemPtr first, last; | |
2130 | GetSelectionAnchor( &first, &last ); | |
2131 | ||
2132 | if ( first != NULL ) | |
2133 | { | |
2134 | return GetLineFromItem( first ); | |
2135 | } | |
2136 | ||
2137 | return -1; | |
2138 | } | |
2139 | ||
2140 | int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const | |
2141 | { | |
2142 | aSelections.Empty(); | |
2143 | wxArrayMacDataItemPtr selectedItems; | |
2144 | GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems); | |
2145 | ||
2146 | int count = selectedItems.GetCount(); | |
2147 | ||
2148 | for ( int i = 0; i < count; ++i) | |
2149 | { | |
2150 | aSelections.Add(GetLineFromItem(selectedItems[i])); | |
2151 | } | |
2152 | ||
2153 | return count; | |
2154 | } | |
2155 | ||
2156 | void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text ) | |
2157 | { | |
2158 | // as we don't store the strings we only have to issue a redraw | |
2159 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n); | |
2160 | item->SetLabel( text ); | |
2161 | UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId ); | |
2162 | } | |
2163 | ||
2164 | wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const | |
2165 | { | |
2166 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
2167 | return item->GetLabel(); | |
2168 | } | |
2169 | ||
2170 | void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data) | |
2171 | { | |
2172 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n); | |
2173 | item->SetData( data ); | |
2174 | // not displayed, therefore no Update infos to DataBrowser | |
2175 | } | |
2176 | ||
2177 | void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const | |
2178 | { | |
2179 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
2180 | return item->GetData(); | |
2181 | } | |
2182 | ||
2183 | void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n ) | |
2184 | { | |
2185 | RevealItem( GetItemFromLine( n) , kDataBrowserRevealWithoutSelecting ); | |
2186 | } | |
2187 | ||
2188 | ||
2189 | ||
2190 | // | |
2191 | // Tab Control | |
2192 | // | |
2193 | ||
2194 | OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) | |
2195 | { | |
2196 | return ::SetTabEnabled( m_controlRef , tabNo , enable ); | |
2197 | } | |
2198 | ||
2199 | // | |
2200 | // Quartz Support | |
2201 | // | |
2202 | ||
2203 | #ifdef __WXMAC_OSX__ | |
2204 | // snippets from Sketch Sample from Apple : | |
2205 | ||
2206 | #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" | |
2207 | ||
2208 | /* | |
2209 | This function locates, opens, and returns the profile reference for the calibrated | |
2210 | Generic RGB color space. It is up to the caller to call CMCloseProfile when done | |
2211 | with the profile reference this function returns. | |
2212 | */ | |
2213 | CMProfileRef wxMacOpenGenericProfile() | |
2214 | { | |
2215 | static CMProfileRef cachedRGBProfileRef = NULL; | |
2216 | ||
2217 | // we only create the profile reference once | |
2218 | if (cachedRGBProfileRef == NULL) | |
2219 | { | |
2220 | CMProfileLocation loc; | |
2221 | ||
2222 | loc.locType = cmPathBasedProfile; | |
2223 | strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr); | |
2224 | ||
2225 | verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) ); | |
2226 | } | |
2227 | ||
2228 | // clone the profile reference so that the caller has their own reference, not our cached one | |
2229 | if (cachedRGBProfileRef) | |
2230 | CMCloneProfileRef(cachedRGBProfileRef); | |
2231 | ||
2232 | return cachedRGBProfileRef; | |
2233 | } | |
2234 | ||
2235 | /* | |
2236 | Return the generic RGB color space. This is a 'get' function and the caller should | |
2237 | not release the returned value unless the caller retains it first. Usually callers | |
2238 | of this routine will immediately use the returned colorspace with CoreGraphics | |
2239 | so they typically do not need to retain it themselves. | |
2240 | ||
2241 | This function creates the generic RGB color space once and hangs onto it so it can | |
2242 | return it whenever this function is called. | |
2243 | */ | |
2244 | ||
2245 | CGColorSpaceRef wxMacGetGenericRGBColorSpace() | |
2246 | { | |
2247 | static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace; | |
2248 | ||
2249 | if (genericRGBColorSpace == NULL) | |
2250 | { | |
2251 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
2252 | { | |
2253 | genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) ); | |
2254 | } | |
2255 | else | |
2256 | { | |
2257 | CMProfileRef genericRGBProfile = wxMacOpenGenericProfile(); | |
2258 | ||
2259 | if (genericRGBProfile) | |
2260 | { | |
2261 | genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) ); | |
2262 | ||
2263 | wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ); | |
2264 | ||
2265 | // we opened the profile so it is up to us to close it | |
2266 | CMCloseProfile(genericRGBProfile); | |
2267 | } | |
2268 | } | |
2269 | } | |
2270 | ||
2271 | return genericRGBColorSpace; | |
2272 | } | |
2273 | #endif | |
2274 | ||
2275 | #ifndef __LP64__ | |
2276 | ||
2277 | wxMacPortSaver::wxMacPortSaver( GrafPtr port ) | |
2278 | { | |
2279 | ::GetPort( &m_port ); | |
2280 | ::SetPort( port ); | |
2281 | } | |
2282 | ||
2283 | wxMacPortSaver::~wxMacPortSaver() | |
2284 | { | |
2285 | ::SetPort( m_port ); | |
2286 | } | |
2287 | #endif | |
2288 | ||
2289 | void wxMacGlobalToLocal( WindowRef window , Point*pt ) | |
2290 | { | |
2291 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 | |
2292 | HIPoint p = CGPointMake( pt->h, pt->v ); | |
2293 | HIViewRef contentView ; | |
2294 | // TODO check toolbar offset | |
2295 | HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ; | |
2296 | HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView ); | |
2297 | pt->h = p.x; | |
2298 | pt->v = p.y; | |
2299 | #else | |
2300 | QDGlobalToLocalPoint( GetWindowPort(window), pt ) ; | |
2301 | #endif | |
2302 | } | |
2303 | ||
2304 | void wxMacLocalToGlobal( WindowRef window , Point*pt ) | |
2305 | { | |
2306 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 | |
2307 | HIPoint p = CGPointMake( pt->h, pt->v ); | |
2308 | HIViewRef contentView ; | |
2309 | // TODO check toolbar offset | |
2310 | HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ; | |
2311 | HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL ); | |
2312 | pt->h = p.x; | |
2313 | pt->v = p.y; | |
2314 | #else | |
2315 | QDLocalToGlobalPoint( GetWindowPort(window), pt ) ; | |
2316 | #endif | |
2317 | } | |
2318 | ||
2319 | #endif // wxUSE_GUI |