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