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