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