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