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