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