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