]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/utils.cpp
removed USE_SHARED_LIBRARY mentions (and all variations in spelling) (patch 1231184)
[wxWidgets.git] / src / mac / carbon / utils.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
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
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5 13// Note: this is done in utilscmn.cpp now.
e9576ca5
SC
14// #pragma implementation "utils.h"
15#endif
16
3d1a4878
SC
17#include "wx/wxprec.h"
18
e9576ca5
SC
19#include "wx/utils.h"
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"
fe929141 27#else
9d8aca48 28 #include "wx/intl.h"
b6ed2b86 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
SC
40#ifndef __DARWIN__
41#include <Threads.h>
42#include <Sound.h>
43#endif
44
7d9bf1f1 45#if wxUSE_GUI
29d91661
SC
46#if TARGET_API_MAC_OSX
47#include <CoreServices/CoreServices.h>
48#else
49#include <DriverServices.h>
50#include <Multiprocessing.h>
51#endif
52
768c6e8b
SC
53#ifdef __DARWIN__
54#include <Carbon/Carbon.h>
55#else
7f0c3a63
SC
56#include <ATSUnicode.h>
57#include <TextCommon.h>
58#include <TextEncodingConverter.h>
768c6e8b 59#endif
7d9bf1f1 60#endif // wxUSE_GUI
427ff662 61
8aa701ed 62#include "wx/mac/private.h" // includes mac headers
a434b43f
VZ
63
64#if defined(__MWERKS__) && wxUSE_UNICODE
65 #include <wtime.h>
66#endif
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{
75 long theSystem ;
76
77 // are there x-platform conventions ?
78
79 Gestalt(gestaltSystemVersion, &theSystem) ;
80 if (minorVsn != NULL) {
81 *minorVsn = (theSystem & 0xFF ) ;
82 }
83 if (majorVsn != NULL) {
84 *majorVsn = (theSystem >> 8 ) ;
85 }
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
114 #include <CodeFragments.h>
115
116 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
117
118 ProcPtr gCallUniversalProc_Proc = NULL;
119
120#endif
121
122static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
123
124static long fRunOnce = false;
125
126/* ---------------------------------------------------------------------------
127 IsMetroNubInstalled
128 --------------------------------------------------------------------------- */
129
130Boolean IsMetroNubInstalled()
131{
132 if (!fRunOnce)
133 {
134 long result, value;
135
136 fRunOnce = true;
137 gMetroNubEntry = NULL;
138
139 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
140 {
141 /* look for MetroNub's Gestalt selector */
142 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
143 {
144
145 #if TARGET_API_MAC_CARBON
146 if (gCallUniversalProc_Proc == NULL)
147 {
148 CFragConnectionID connectionID;
149 Ptr mainAddress;
150 Str255 errorString;
151 ProcPtr symbolAddress;
152 OSErr err;
153 CFragSymbolClass symbolClass;
154
155 symbolAddress = NULL;
156 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
157 &connectionID, &mainAddress, errorString);
158
159 if (err != noErr)
160 {
161 gCallUniversalProc_Proc = NULL;
162 goto end;
163 }
164
165 err = FindSymbol(connectionID, "\pCallUniversalProc",
166 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
167
168 if (err != noErr)
169 {
170 gCallUniversalProc_Proc = NULL;
171 goto end;
172 }
173 }
174 #endif
175
176 {
177 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
178
179 /* make sure the version of the API is compatible */
180 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
181 kMetroNubUserAPIVersion <= block->apiHiVersion)
182 gMetroNubEntry = block; /* success! */
183 }
184
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
198/* ---------------------------------------------------------------------------
199 IsMWDebuggerRunning [v1 API]
200 --------------------------------------------------------------------------- */
201
202Boolean IsMWDebuggerRunning()
203{
204 if (IsMetroNubInstalled())
205 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
206 else
207 return false;
208}
209
210/* ---------------------------------------------------------------------------
211 AmIBeingMWDebugged [v1 API]
212 --------------------------------------------------------------------------- */
213
214Boolean AmIBeingMWDebugged()
215{
216 if (IsMetroNubInstalled())
217 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
218 else
219 return false;
220}
221
222extern bool WXDLLEXPORT wxIsDebuggerRunning()
223{
224 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
225}
226
227#else
228
229extern bool WXDLLEXPORT wxIsDebuggerRunning()
230{
231 return false;
232}
233
234#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
235
a434b43f 236
f5c6eb5c 237#ifndef __DARWIN__
03e11df5
GD
238// defined in unix/utilsunx.cpp for Mac OS X
239
2f1ae414
SC
240// get full hostname (with domain name if possible)
241bool wxGetFullHostName(wxChar *buf, int maxSize)
242{
243 return wxGetHostName(buf, maxSize);
244}
245
246// Get hostname only (without domain name)
427ff662 247bool wxGetHostName(wxChar *buf, int maxSize)
e9576ca5 248{
e40298d5
JS
249 // Gets Chooser name of user by examining a System resource.
250
251 const short kComputerNameID = -16413;
5be55d56 252
e40298d5
JS
253 short oldResFile = CurResFile() ;
254 UseResFile(0);
255 StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);
256 UseResFile(oldResFile);
257
258 if (chooserName && *chooserName)
259 {
427ff662
SC
260 HLock( (Handle) chooserName ) ;
261 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
262 HUnlock( (Handle) chooserName ) ;
263 ReleaseResource( (Handle) chooserName ) ;
264 wxStrncpy( buf , name , maxSize - 1 ) ;
e40298d5
JS
265 }
266 else
267 buf[0] = 0 ;
0a67a93b 268
9d8aca48 269 return true;
e9576ca5
SC
270}
271
272// Get user ID e.g. jacs
427ff662 273bool wxGetUserId(wxChar *buf, int maxSize)
e9576ca5 274{
0a67a93b 275 return wxGetUserName( buf , maxSize ) ;
e9576ca5
SC
276}
277
5b781a67
SC
278const wxChar* wxGetHomeDir(wxString *pstr)
279{
e40298d5
JS
280 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
281 return pstr->c_str() ;
5b781a67
SC
282}
283
a31a5f85 284// Get user name e.g. Stefan Csomor
427ff662 285bool wxGetUserName(wxChar *buf, int maxSize)
e9576ca5 286{
e40298d5
JS
287 // Gets Chooser name of user by examining a System resource.
288
289 const short kChooserNameID = -16096;
5be55d56 290
e40298d5
JS
291 short oldResFile = CurResFile() ;
292 UseResFile(0);
293 StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);
294 UseResFile(oldResFile);
295
296 if (chooserName && *chooserName)
297 {
427ff662
SC
298 HLock( (Handle) chooserName ) ;
299 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
300 HUnlock( (Handle) chooserName ) ;
301 ReleaseResource( (Handle) chooserName ) ;
302 wxStrncpy( buf , name , maxSize - 1 ) ;
e40298d5
JS
303 }
304 else
305 buf[0] = 0 ;
0a67a93b 306
9d8aca48 307 return true;
e9576ca5
SC
308}
309
e0f6b731 310int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags)
e9576ca5
SC
311{
312 // TODO
313 return 0;
314}
315
5dbb17e2
SC
316WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
317{
e40298d5
JS
318 // TODO : under classic there is no environement support, under X yes
319 return false ;
5dbb17e2
SC
320}
321
9d8aca48 322// set the env var name to the given value, return true on success
5dbb17e2
SC
323WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
324{
e40298d5
JS
325 // TODO : under classic there is no environement support, under X yes
326 return false ;
5dbb17e2
SC
327}
328
e9576ca5
SC
329//
330// Execute a program in an Interactive Shell
331//
332bool wxShell(const wxString& command)
333{
334 // TODO
9d8aca48 335 return false;
e9576ca5
SC
336}
337
5be55d56 338// Shutdown or reboot the PC
f6ba47d9
VZ
339bool wxShutdown(wxShutdownFlags wFlags)
340{
341 // TODO
9d8aca48 342 return false;
f6ba47d9
VZ
343}
344
8ea92b4d
WS
345wxPowerType wxGetPowerType()
346{
347 // TODO
348 return wxPOWER_UNKNOWN;
349}
350
351wxBatteryState wxGetBatteryState()
352{
353 // TODO
354 return wxBATTERY_UNKNOWN_STATE;
355}
356
e9576ca5 357// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
9d8aca48 358wxMemorySize wxGetFreeMemory()
e9576ca5 359{
9d8aca48 360 return (wxMemorySize)FreeMem() ;
0a67a93b
SC
361}
362
7f7b52b4
SC
363#ifndef __DARWIN__
364
365void wxMicroSleep(unsigned long microseconds)
0a67a93b 366{
9d8aca48
WS
367 AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
368 MPDelayUntil( & wakeup);
7f7b52b4
SC
369}
370
371void wxMilliSleep(unsigned long milliseconds)
372{
9d8aca48
WS
373 AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
374 MPDelayUntil( & wakeup);
e9576ca5
SC
375}
376
377void wxSleep(int nSecs)
378{
7f7b52b4 379 wxMilliSleep(1000*nSecs);
e9576ca5
SC
380}
381
7f7b52b4
SC
382#endif
383
e9576ca5
SC
384// Consume all events until no more left
385void wxFlushEvents()
386{
387}
388
f5c6eb5c 389#endif // !__DARWIN__
e9576ca5
SC
390
391// Emit a beeeeeep
392void wxBell()
393{
0a67a93b 394 SysBeep(30);
e9576ca5
SC
395}
396
324899f6 397wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
29c99ad3 398{
a8eaaeb2 399 static wxToolkitInfo info;
66b6b57c 400 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
a8eaaeb2 401 info.name = _T("wxBase");
324899f6 402 return info;
29c99ad3
VZ
403}
404
b6ed2b86
VZ
405#endif // wxUSE_BASE
406
407#if wxUSE_GUI
536732e4 408
324899f6 409wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
29c99ad3 410{
a8eaaeb2 411 static wxToolkitInfo info;
66b6b57c 412 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
a8eaaeb2
VS
413 info.shortName = _T("mac");
414 info.name = _T("wxMac");
415#ifdef __WXUNIVERSAL__
416 info.shortName << _T("univ");
417 info.name << _T("/wxUniversal");
418#endif
324899f6 419 return info;
29c99ad3
VZ
420}
421
e9576ca5
SC
422// Reading and writing resources (eg WIN.INI, .Xdefaults)
423#if wxUSE_RESOURCES
424bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
425{
426 // TODO
9d8aca48 427 return false;
e9576ca5
SC
428}
429
430bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
431{
427ff662
SC
432 wxString buf;
433 buf.Printf(wxT("%.4f"), value);
434
e40298d5 435 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
436}
437
438bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
439{
427ff662
SC
440 wxString buf;
441 buf.Printf(wxT("%ld"), value);
442
e40298d5 443 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
444}
445
446bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
447{
427ff662
SC
448 wxString buf;
449 buf.Printf(wxT("%d"), value);
450
e40298d5 451 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
452}
453
454bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
455{
456 // TODO
9d8aca48 457 return false;
e9576ca5
SC
458}
459
460bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
461{
e40298d5
JS
462 char *s = NULL;
463 bool succ = wxGetResource(section, entry, (char **)&s, file);
464 if (succ)
465 {
466 *value = (float)strtod(s, NULL);
467 delete[] s;
9d8aca48 468 return true;
e40298d5 469 }
9d8aca48 470 else return false;
e9576ca5
SC
471}
472
473bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
474{
e40298d5
JS
475 char *s = NULL;
476 bool succ = wxGetResource(section, entry, (char **)&s, file);
477 if (succ)
478 {
479 *value = strtol(s, NULL, 10);
480 delete[] s;
9d8aca48 481 return true;
e40298d5 482 }
9d8aca48 483 else return false;
e9576ca5
SC
484}
485
486bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
487{
e40298d5
JS
488 char *s = NULL;
489 bool succ = wxGetResource(section, entry, (char **)&s, file);
490 if (succ)
491 {
492 *value = (int)strtol(s, NULL, 10);
493 delete[] s;
9d8aca48 494 return true;
e40298d5 495 }
9d8aca48 496 else return false;
e9576ca5
SC
497}
498#endif // wxUSE_RESOURCES
499
6b57b49a 500int gs_wxBusyCursorCount = 0;
e40298d5
JS
501extern wxCursor gMacCurrentCursor ;
502wxCursor gMacStoredActiveCursor ;
e9576ca5
SC
503
504// Set the cursor to the busy cursor for all windows
505void wxBeginBusyCursor(wxCursor *cursor)
506{
e40298d5
JS
507 if (gs_wxBusyCursorCount++ == 0)
508 {
509 gMacStoredActiveCursor = gMacCurrentCursor ;
510 cursor->MacInstall() ;
511 }
512 //else: nothing to do, already set
e9576ca5
SC
513}
514
515// Restore cursor to normal
516void wxEndBusyCursor()
517{
6b57b49a 518 wxCHECK_RET( gs_wxBusyCursorCount > 0,
e40298d5 519 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
5be55d56 520
e40298d5
JS
521 if (--gs_wxBusyCursorCount == 0)
522 {
523 gMacStoredActiveCursor.MacInstall() ;
524 gMacStoredActiveCursor = wxNullCursor ;
525 }
e9576ca5
SC
526}
527
9d8aca48 528// true if we're between the above two calls
e9576ca5
SC
529bool wxIsBusy()
530{
e40298d5 531 return (gs_wxBusyCursorCount > 0);
ec5d7799 532}
e9576ca5 533
2dbc444a
RD
534#endif // wxUSE_GUI
535
536#if wxUSE_BASE
537
e7e1b01e 538wxString wxMacFindFolder( short vol,
e40298d5
JS
539 OSType folderType,
540 Boolean createFolder)
2f1ae414 541{
9d8aca48 542 FSRef fsRef ;
2d4e4f80 543 wxString strDir ;
5be55d56 544
a2b77260 545 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
814af667 546 strDir = wxMacFSRefToPath( &fsRef ) + wxFILE_SEP_PATH ;
a2b77260 547
2d4e4f80 548 return strDir ;
2f1ae414
SC
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{
519cb848 565 Point pt ;
ec5d7799 566
519cb848
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{
e40298d5
JS
582 Rect globRect ;
583 SetRect(&globRect, -32760, -32760, 32760, 32760);
584 GDHandle theMaxDevice;
2f1ae414 585
e40298d5
JS
586 int theDepth = 8;
587 theMaxDevice = GetMaxDevice(&globRect);
588 if (theMaxDevice != nil)
589 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
ec5d7799 590
e40298d5 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
VZ
599
600 if (width != NULL) {
e8ca7105
GD
601 *width = screenBits.bounds.right - screenBits.bounds.left ;
602 }
5be55d56 603 if (height != NULL) {
e8ca7105
GD
604 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
605 }
e9576ca5
SC
606}
607
5fde6fcc
GD
608void wxDisplaySizeMM(int *width, int *height)
609{
5b028d57
SC
610 wxDisplaySize(width, height);
611 // on mac 72 is fixed (at least now ;-)
612 float cvPt2Mm = 25.4 / 72;
e8ca7105 613
5be55d56 614 if (width != NULL) {
e8ca7105
GD
615 *width = int( *width * cvPt2Mm );
616 }
5be55d56 617 if (height != NULL) {
e8ca7105
GD
618 *height = int( *height * cvPt2Mm );
619 }
5fde6fcc
GD
620}
621
ec5d7799
RD
622void wxClientDisplayRect(int *x, int *y, int *width, int *height)
623{
ee658398
SC
624 Rect r ;
625 GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ;
626 if ( x )
627 *x = r.left ;
628 if ( y )
629 *y = r.top ;
630 if ( width )
631 *width = r.right - r.left ;
632 if ( height )
633 *height = r.bottom - r.top ;
ec5d7799
RD
634}
635
57591e0e
JS
636wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
637{
638 return wxGenericFindWindowAtPoint(pt);
639}
5dbb17e2 640
b6ed2b86
VZ
641#endif // wxUSE_GUI
642
643#if wxUSE_BASE
644
5dbb17e2
SC
645wxString wxGetOsDescription()
646{
6e73695c
GD
647#ifdef WXWIN_OS_DESCRIPTION
648 // use configure generated description if available
5f3f0f17 649 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
6e73695c 650#else
427ff662 651 return wxT("MacOS") ; //TODO:define further
6e73695c
GD
652#endif
653}
654
b6ed2b86
VZ
655#ifndef __DARWIN__
656wxChar *wxGetUserHome (const wxString& user)
657{
658 // TODO
659 return NULL;
660}
661
662bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
663{
664 if ( path.empty() )
9d8aca48 665 return false;
b6ed2b86
VZ
666
667 wxString p = path ;
71111c40 668 if (p[0u] == ':' ) {
b6ed2b86
VZ
669 p = wxGetCwd() + p ;
670 }
671
672 int pos = p.Find(':') ;
673 if ( pos != wxNOT_FOUND ) {
674 p = p.Mid(1,pos) ;
675 }
676
677 p = p + wxT(":") ;
678
a2b77260 679 OSErr err = noErr ;
9d8aca48 680
a2b77260
SC
681 FSRef fsRef ;
682 err = wxMacPathToFSRef( p , &fsRef ) ;
683 if ( noErr == err )
684 {
685 FSVolumeRefNum vRefNum ;
686 err = FSGetVRefNum( &fsRef , &vRefNum ) ;
687 if ( noErr == err )
688 {
689 UInt64 freeBytes , totalBytes ;
690 err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ) ;
691 if ( noErr == err )
692 {
9d8aca48 693 if ( pTotal )
a2b77260
SC
694 *pTotal = wxLongLong( totalBytes ) ;
695 if ( pFree )
696 *pFree = wxLongLong( freeBytes ) ;
697 }
698 }
b6ed2b86 699 }
9d8aca48 700
b6ed2b86
VZ
701 return err == noErr ;
702}
703#endif // !__DARWIN__
704
3d963f81
SC
705//---------------------------------------------------------------------------
706// wxMac Specific utility functions
707//---------------------------------------------------------------------------
708
5be55d56 709void wxMacStringToPascal( const wxString&from , StringPtr to )
427ff662 710{
939fba6c 711 wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
427ff662
SC
712 int len = strlen(buf) ;
713
714 if ( len > 255 )
715 len = 255 ;
716 to[0] = len ;
717 memcpy( (char*) &to[1] , buf , len ) ;
718}
719
5be55d56 720wxString wxMacMakeStringFromPascal( ConstStringPtr from )
427ff662 721{
939fba6c 722 return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
427ff662
SC
723}
724
e50d5284 725
73280e05
SC
726// ----------------------------------------------------------------------------
727// Common Event Support
728// ----------------------------------------------------------------------------
729
d13ea1bd 730
73280e05
SC
731extern ProcessSerialNumber gAppProcess ;
732
733void wxMacWakeUp()
734{
735 ProcessSerialNumber psn ;
736 Boolean isSame ;
737 psn.highLongOfPSN = 0 ;
738 psn.lowLongOfPSN = kCurrentProcess ;
739 SameProcess( &gAppProcess , &psn , &isSame ) ;
740 if ( isSame )
741 {
742#if TARGET_CARBON
8dfef0c2
SC
743 static wxMacCarbonEvent s_wakeupEvent ;
744 OSStatus err = noErr ;
745 if ( !s_wakeupEvent.IsValid() )
d6c69b17 746 {
8dfef0c2
SC
747 err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
748 kEventAttributeNone ) ;
d6c69b17 749 }
8dfef0c2 750 if ( err == noErr )
73280e05 751 {
8dfef0c2 752 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
9d8aca48 753 return ;
8dfef0c2 754 s_wakeupEvent.SetTime(0) ;
d6c69b17 755 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
73280e05 756 kEventPriorityHigh);
8dfef0c2 757 }
73280e05
SC
758#else
759 PostEvent( nullEvent , 0 ) ;
760#endif
761 }
762 else
763 {
764 WakeUpProcess( &gAppProcess ) ;
765 }
766}
767
d13ea1bd
RD
768#endif // wxUSE_BASE
769
770#if wxUSE_GUI
771
1f1c8bd4
SC
772// ----------------------------------------------------------------------------
773// Native Struct Conversions
774// ----------------------------------------------------------------------------
775
776
777void wxMacRectToNative( const wxRect *wx , Rect *n )
778{
779 n->left = wx->x ;
780 n->top = wx->y ;
781 n->right = wx->x + wx->width ;
782 n->bottom = wx->y + wx->height ;
783}
784
785void wxMacNativeToRect( const Rect *n , wxRect* wx )
786{
787 wx->x = n->left ;
788 wx->y = n->top ;
789 wx->width = n->right - n->left ;
790 wx->height = n->bottom - n->top ;
791}
792
793void wxMacPointToNative( const wxPoint* wx , Point *n )
794{
795 n->h = wx->x ;
796 n->v = wx->y ;
797}
798
799void wxMacNativeToPoint( const Point *n , wxPoint* wx )
800{
801 wx->x = n->h ;
802 wx->y = n->v ;
803}
d13ea1bd 804
facd6764
SC
805// ----------------------------------------------------------------------------
806// Carbon Event Support
807// ----------------------------------------------------------------------------
808
809
810OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
811{
9d8aca48 812 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ;
facd6764
SC
813}
814
21fd5529 815OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
facd6764 816{
9d8aca48 817 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ;
facd6764
SC
818}
819
86d8b744
SC
820// ----------------------------------------------------------------------------
821// Control Access Support
822// ----------------------------------------------------------------------------
823
1f1c8bd4 824wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl )
9b89f11a
SC
825{
826 Init() ;
827 m_peer = peer ;
1f1c8bd4 828 m_isRootControl = isRootControl ;
9b89f11a
SC
829 m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing() ;
830}
831
832wxMacControl::wxMacControl( wxWindow* peer , ControlRef control )
833{
834 Init() ;
835 m_peer = peer ;
836 m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing() ;
837 m_controlRef = control ;
838}
839
840wxMacControl::wxMacControl( wxWindow* peer , WXWidget control )
841{
842 Init() ;
843 m_peer = peer ;
844 m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing() ;
845 m_controlRef = (ControlRef) control ;
846}
847
848wxMacControl::~wxMacControl()
849{
850}
851
852void wxMacControl::Init()
853{
854 m_peer = NULL ;
855 m_controlRef = NULL ;
856 m_needsFocusRect = false ;
857 m_isCompositing = false ;
1f1c8bd4 858 m_isRootControl = false ;
9b89f11a
SC
859}
860
5ca0d812
SC
861void wxMacControl::Dispose()
862{
863 ::DisposeControl( m_controlRef ) ;
864 m_controlRef = NULL ;
865}
866
9d8aca48 867void wxMacControl::SetReference( SInt32 data )
5ca0d812
SC
868{
869 SetControlReference( m_controlRef , data ) ;
870}
871
29d91661 872OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
86d8b744 873{
9d8aca48 874 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;
86d8b744
SC
875}
876
29d91661 877OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
86d8b744 878{
9d8aca48 879 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;
86d8b744
SC
880}
881
882OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
883{
9d8aca48 884 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ;
86d8b744
SC
885}
886
9d8aca48 887OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
21fd5529 888{
e996f509 889#if TARGET_API_MAC_OSX
9d8aca48
WS
890 return SendEventToEventTargetWithOptions( event,
891 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
e996f509 892#else
9d8aca48 893 #pragma unused(inOptions)
e996f509
SC
894 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ;
895#endif
21fd5529
SC
896}
897
9d8aca48 898OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
21fd5529
SC
899{
900 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ;
901 event.SetParameter<HICommand>(kEventParamDirectObject,command) ;
9d8aca48 902 return SendEvent( event , inOptions ) ;
21fd5529
SC
903}
904
9d8aca48 905OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
21fd5529
SC
906{
907 HICommand command ;
908 memset( &command, 0 , sizeof(command) ) ;
909 command.commandID = commandID ;
910 return SendHICommand( command , inOptions ) ;
911}
912
9d8aca48 913void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
21fd5529
SC
914{
915 HiliteControl( m_controlRef , part ) ;
916 unsigned long finalTicks ;
917 Delay( ticks , &finalTicks ) ;
918 HiliteControl( m_controlRef , kControlNoPart ) ;
919}
920
7f7b52b4 921SInt32 wxMacControl::GetValue() const
9d8aca48
WS
922{
923 return ::GetControl32BitValue( m_controlRef ) ;
7f7b52b4
SC
924}
925
926SInt32 wxMacControl::GetMaximum() const
9d8aca48
WS
927{
928 return ::GetControl32BitMaximum( m_controlRef ) ;
7f7b52b4
SC
929}
930
931SInt32 wxMacControl::GetMinimum() const
9d8aca48
WS
932{
933 return ::GetControl32BitMinimum( m_controlRef ) ;
7f7b52b4
SC
934}
935
9d8aca48
WS
936void wxMacControl::SetValue( SInt32 v )
937{
938 ::SetControl32BitValue( m_controlRef , v ) ;
7f7b52b4
SC
939}
940
9d8aca48
WS
941void wxMacControl::SetMinimum( SInt32 v )
942{
943 ::SetControl32BitMinimum( m_controlRef , v ) ;
7f7b52b4
SC
944}
945
9d8aca48
WS
946void wxMacControl::SetMaximum( SInt32 v )
947{
7f7b52b4
SC
948 ::SetControl32BitMaximum( m_controlRef , v ) ;
949}
950
951void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
952{
953 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
9d8aca48 954 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
7f7b52b4
SC
955 ::SetControl32BitValue( m_controlRef , value ) ;
956}
957
9d8aca48 958OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
5ca0d812 959{
9d8aca48 960 return SetKeyboardFocus( GetControlOwner( m_controlRef ) ,
5ca0d812
SC
961 m_controlRef , focusPart ) ;
962}
963
9d8aca48 964bool wxMacControl::HasFocus() const
5ca0d812
SC
965{
966 ControlRef control ;
967 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
968 return control == m_controlRef ;
969}
970
9b89f11a
SC
971void wxMacControl::SetNeedsFocusRect( bool needs )
972{
973 m_needsFocusRect = needs ;
974}
975
9d8aca48 976bool wxMacControl::NeedsFocusRect() const
5ca0d812 977{
9b89f11a 978 return m_needsFocusRect ;
5ca0d812
SC
979}
980
9d8aca48 981void wxMacControl::VisibilityChanged(bool shown)
29d91661
SC
982{
983}
984
89a66f11
SC
985void wxMacControl::SuperChangedPosition()
986{
987}
988
9d8aca48 989void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
29d91661
SC
990{
991 m_font = font ;
9d8aca48
WS
992 ControlFontStyleRec fontStyle;
993 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
994 {
995 switch( font.MacGetThemeFontID() )
996 {
997 case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ;
998 case 109 /*mini font */ : fontStyle.font = -5 ; break ;
999 case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ;
1000 default : fontStyle.font = kControlFontBigSystemFont ; break ;
1001 }
1002 fontStyle.flags = kControlUseFontMask ;
1003 }
1004 else
1005 {
1006 fontStyle.font = font.MacGetFontNum() ;
1007 fontStyle.style = font.MacGetFontStyle() ;
1008 fontStyle.size = font.MacGetFontSize() ;
1009 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ;
1010 }
29d91661
SC
1011
1012 fontStyle.just = teJustLeft ;
1013 fontStyle.flags |= kControlUseJustMask ;
1014 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
1015 fontStyle.just = teJustCenter ;
1016 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
1017 fontStyle.just = teJustRight ;
1018
9d8aca48 1019
29d91661
SC
1020 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1021 // won't get grayed out by the system anymore
9d8aca48 1022
29d91661
SC
1023 if ( foreground != *wxBLACK )
1024 {
1025 fontStyle.foreColor = MAC_WXCOLORREF(foreground.GetPixel() ) ;
1026 fontStyle.flags |= kControlUseForeColorMask ;
1027 }
9d8aca48
WS
1028
1029 ::SetControlFontStyle( m_controlRef , &fontStyle );
29d91661
SC
1030}
1031
9d8aca48 1032void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
7ea087b7 1033{
9d8aca48 1034 // TODO
7ea087b7
SC
1035 // setting up a color proc is not recommended anymore
1036}
1037
7f7b52b4
SC
1038void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
1039{
1040 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
9d8aca48 1041 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
7f7b52b4
SC
1042}
1043
9d8aca48 1044short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
5ca0d812
SC
1045{
1046 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ) ;
1047}
1048
1049void wxMacControl::SetActionProc( ControlActionUPP actionProc )
1050{
1051 SetControlAction( m_controlRef , actionProc ) ;
1052}
1053
1054void wxMacControl::SetViewSize( SInt32 viewSize )
1055{
1056 SetControlViewSize(m_controlRef , viewSize ) ;
1057}
1058
1059SInt32 wxMacControl::GetViewSize() const
1060{
1061 return GetControlViewSize( m_controlRef ) ;
1062}
1063
9d8aca48 1064bool wxMacControl::IsVisible() const
5ca0d812
SC
1065{
1066 return IsControlVisible( m_controlRef ) ;
1067}
1068
9d8aca48 1069void wxMacControl::SetVisibility( bool visible , bool redraw )
5ca0d812
SC
1070{
1071 SetControlVisibility( m_controlRef , visible , redraw ) ;
1072}
1073
9d8aca48 1074bool wxMacControl::IsEnabled() const
5ca0d812
SC
1075{
1076#if TARGET_API_MAC_OSX
1077 return IsControlEnabled( m_controlRef ) ;
1078#else
1079 return IsControlActive( m_controlRef ) ;
1080#endif
1081}
1082
9d8aca48 1083bool wxMacControl::IsActive() const
5ca0d812
SC
1084{
1085 return IsControlActive( m_controlRef ) ;
1086}
1087
9d8aca48 1088void wxMacControl::Enable( bool enable )
5ca0d812
SC
1089{
1090#if TARGET_API_MAC_OSX
1091 if ( enable )
1092 EnableControl( m_controlRef ) ;
1093 else
1094 DisableControl( m_controlRef ) ;
1095#else
1096 if ( enable )
1097 ActivateControl( m_controlRef ) ;
1098 else
1099 DeactivateControl( m_controlRef ) ;
1100#endif
1101}
1102
9d8aca48 1103void wxMacControl::SetDrawingEnabled( bool enable )
5ca0d812
SC
1104{
1105#if TARGET_API_MAC_OSX
1106 HIViewSetDrawingEnabled( m_controlRef , enable ) ;
1107#endif
1108}
1109
23ad132c 1110#if TARGET_API_MAC_OSX
9d8aca48 1111bool wxMacControl::GetNeedsDisplay() const
5ca0d812
SC
1112{
1113#if TARGET_API_MAC_OSX
92346151
SC
1114 if ( m_isCompositing )
1115 {
1116 return HIViewGetNeedsDisplay( m_controlRef ) ;
1117 }
1118 else
5ca0d812 1119#endif
92346151
SC
1120 {
1121 if ( !IsVisible() )
1122 return false ;
1123
1124 Rect controlBounds ;
1125 GetControlBounds( m_controlRef, &controlBounds ) ;
1126 RgnHandle rgn = NewRgn() ;
1127 GetWindowRegion ( GetControlOwner( m_controlRef ) , kWindowUpdateRgn , rgn ) ;
1128 Boolean intersect = RectInRgn ( &controlBounds , rgn ) ;
1129 DisposeRgn( rgn ) ;
1130 return intersect ;
1131 }
1132
5ca0d812 1133}
1f1c8bd4 1134#endif
5ca0d812 1135
1f1c8bd4 1136void wxMacControl::SetNeedsDisplay( RgnHandle where )
5ca0d812 1137{
1f1c8bd4
SC
1138 if ( !IsVisible() )
1139 return ;
1140
5ca0d812 1141#if TARGET_API_MAC_OSX
1f1c8bd4
SC
1142 if ( m_isCompositing )
1143 {
1144 HIViewSetNeedsDisplayInRegion( m_controlRef , where , true ) ;
1145 }
5ca0d812 1146 else
5ca0d812 1147#endif
1f1c8bd4
SC
1148 {
1149 Rect controlBounds ;
1150 GetControlBounds( m_controlRef, &controlBounds ) ;
1151 RgnHandle update = NewRgn() ;
1152 CopyRgn( where , update ) ;
1153 OffsetRgn( update , controlBounds.left , controlBounds.top ) ;
1154 InvalWindowRgn( GetControlOwner( m_controlRef) , update ) ;
1155 }
5ca0d812 1156}
1f1c8bd4
SC
1157
1158void wxMacControl::SetNeedsDisplay( Rect* where )
1159{
1160 if ( !IsVisible() )
1161 return ;
1162
1163#if TARGET_API_MAC_OSX
1164 if ( m_isCompositing )
1165 {
1166 if ( where != NULL )
1167 {
1168 RgnHandle update = NewRgn() ;
1169 RectRgn( update , where ) ;
1170 HIViewSetNeedsDisplayInRegion( m_controlRef , update , true ) ;
1171 DisposeRgn( update ) ;
1172 }
1173 else
1174 HIViewSetNeedsDisplay( m_controlRef , true ) ;
1175 }
1176 else
23ad132c 1177#endif
1f1c8bd4
SC
1178 {
1179 Rect controlBounds ;
1180 GetControlBounds( m_controlRef, &controlBounds ) ;
1181 if ( where )
1182 {
1183 Rect whereLocal = *where ;
1184 OffsetRect( &whereLocal , controlBounds.left , controlBounds.top ) ;
1185 SectRect( &controlBounds , &whereLocal, &controlBounds ) ;
1186 }
1187 InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds ) ;
1188 }
1189}
5ca0d812 1190
9d8aca48 1191void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
5ca0d812
SC
1192{
1193#if TARGET_API_MAC_OSX
9b89f11a
SC
1194 if ( from->m_peer->MacGetTopLevelWindow()->MacUsesCompositing() )
1195 {
1196 HIPoint hiPoint ;
1197 hiPoint.x = pt->x ;
1198 hiPoint.y = pt->y ;
1199 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ) ;
1200 pt->x = (int)hiPoint.x ;
1201 pt->y = (int)hiPoint.y ;
1202 }
1203 else
5ca0d812 1204#endif
9b89f11a
SC
1205 {
1206 Rect fromRect ;
1207 Rect toRect ;
1f1c8bd4
SC
1208 GetControlBounds( from->m_controlRef , &fromRect ) ;
1209 GetControlBounds( to->m_controlRef , &toRect ) ;
1210 if ( from->m_isRootControl )
1211 fromRect.left = fromRect.top = 0 ;
1212 if ( to->m_isRootControl )
1213 toRect.left = toRect.top = 0 ;
9b89f11a
SC
1214
1215 pt->x = pt->x + fromRect.left - toRect.left ;
1216 pt->y = pt->y + fromRect.top - toRect.top ;
1217 }
5ca0d812
SC
1218}
1219
9d8aca48 1220void wxMacControl::SetRect( Rect *r )
5ca0d812
SC
1221{
1222#if TARGET_API_MAC_OSX
9b89f11a
SC
1223 if ( m_isCompositing )
1224 {
1225 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1226 //CGPoint and CGSize, which have two floats each
1227 HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } } ;
1228 HIViewSetFrame ( m_controlRef , &hir ) ;
1229 // eventuall we might have to do a SetVisibility( false , true ) ;
1230 // before and a SetVisibility( true , true ) ; after
1231 }
1232 else
5ca0d812 1233#endif
9b89f11a 1234 {
1f1c8bd4
SC
1235 bool vis = IsVisible() ;
1236 if ( vis )
1237 {
1238 Rect former ;
1239 GetControlBounds( m_controlRef , &former ) ;
1240 InvalWindowRect( GetControlOwner( m_controlRef ) , &former ) ;
1241 }
1242
1243 Rect controlBounds = *r ;
1244
92346151
SC
1245 // since the rect passed in is always (even in non-compositing) relative
1246 // to the (native) parent, we have to adjust to window relative here
1f1c8bd4
SC
1247 wxMacControl* parent = m_peer->GetParent()->GetPeer() ;
1248 if( parent->m_isRootControl == false )
1249 {
1250 Rect superRect ;
1251 GetControlBounds( parent->m_controlRef , &superRect ) ;
1252 OffsetRect( &controlBounds , superRect.left , superRect.top ) ;
1253 }
1254
1255 SetControlBounds( m_controlRef , &controlBounds ) ;
1256 if ( vis )
1257 {
1258 InvalWindowRect( GetControlOwner( m_controlRef ) , &controlBounds ) ;
1259 }
9b89f11a 1260 }
5ca0d812
SC
1261}
1262
9d8aca48 1263void wxMacControl::GetRect( Rect *r )
5ca0d812
SC
1264{
1265 GetControlBounds( m_controlRef , r ) ;
1f1c8bd4 1266 if ( m_isCompositing == false )
9b89f11a 1267 {
1f1c8bd4
SC
1268 // correct the case of the root control
1269 if ( m_isRootControl )
1270 {
1271 WindowRef wr = GetControlOwner( m_controlRef ) ;
1272 GetWindowBounds( wr , kWindowContentRgn , r ) ;
1273 r->right -= r->left ;
1274 r->bottom -= r->top ;
1275 r->left = 0 ;
1276 r->top = 0 ;
1277 }
1278 else
1279 {
1280 wxMacControl* parent = m_peer->GetParent()->GetPeer() ;
1281 if( parent->m_isRootControl == false )
1282 {
1283 Rect superRect ;
1284 GetControlBounds( parent->m_controlRef , &superRect ) ;
1285 OffsetRect( r , -superRect.left , -superRect.top ) ;
1286 }
1287 }
9b89f11a 1288 }
5ca0d812
SC
1289}
1290
9d8aca48 1291void wxMacControl::GetRectInWindowCoords( Rect *r )
5ca0d812
SC
1292{
1293 UMAGetControlBoundsInWindowCoords( m_controlRef , r ) ;
1294}
1295
9d8aca48 1296void wxMacControl::GetBestRect( Rect *r )
5ca0d812 1297{
5ca0d812
SC
1298 short baselineoffset ;
1299 GetBestControlRect( m_controlRef , r , &baselineoffset ) ;
1300}
1301
9d8aca48 1302void wxMacControl::SetTitle( const wxString &title )
5ca0d812 1303{
10a59880
RD
1304 wxFontEncoding encoding;
1305
1306 if ( m_font.Ok() )
1307 encoding = m_font.GetEncoding();
1308 else
1309 encoding = wxFont::GetDefaultEncoding();
9d8aca48 1310
10a59880 1311 UMASetControlTitle( m_controlRef , title , encoding ) ;
5ca0d812
SC
1312}
1313
1314void wxMacControl::GetFeatures( UInt32 * features )
1315{
1316 GetControlFeatures( m_controlRef , features ) ;
1317}
1318
9d8aca48 1319OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
5ca0d812 1320{
1f1c8bd4
SC
1321 OSStatus err = GetControlRegion( m_controlRef , partCode , region ) ;
1322 if ( m_isCompositing == false )
1323 {
1324 if ( !m_isRootControl )
1325 {
1326 Rect r ;
1327 GetControlBounds(m_controlRef, &r ) ;
1328 if ( !EmptyRgn( region ) )
1329 OffsetRgn( region , -r.left , -r.top ) ;
1330 }
1331 }
1332 return err ;
5ca0d812
SC
1333}
1334
9d8aca48 1335OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
5ca0d812
SC
1336{
1337#if TARGET_API_MAC_OSX
9d8aca48 1338 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
5ca0d812
SC
1339 (other != NULL) ? other->m_controlRef : NULL) ;
1340#else
1341 return 0 ;
1342#endif
1343}
1344
1345
1346#if TARGET_API_MAC_OSX
1347// SetNeedsDisplay would not invalidate the children
1348static void InvalidateControlAndChildren( HIViewRef control )
1349{
1350 HIViewSetNeedsDisplay( control , true ) ;
1351 UInt16 childrenCount = 0 ;
9d8aca48 1352 OSStatus err = CountSubControls( control , &childrenCount ) ;
5ca0d812
SC
1353 if ( err == errControlIsNotEmbedder )
1354 return ;
1355 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
1356
1357 for ( UInt16 i = childrenCount ; i >=1 ; --i )
1358 {
1359 HIViewRef child ;
1360 err = GetIndexedSubControl( control , i , & child ) ;
1361 if ( err == errControlIsNotEmbedder )
1362 return ;
1363 InvalidateControlAndChildren( child ) ;
1364 }
1365}
1366#endif
1367
9d8aca48 1368void wxMacControl::InvalidateWithChildren()
5ca0d812
SC
1369{
1370#if TARGET_API_MAC_OSX
1371 InvalidateControlAndChildren( m_controlRef ) ;
1372#endif
1373}
1374
92346151 1375void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
5ca0d812 1376{
92346151 1377 wxASSERT( r != NULL ) ;
5ca0d812 1378#if TARGET_API_MAC_OSX
92346151
SC
1379 if ( m_isCompositing )
1380 {
1381 HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height) ;
1382 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ;
1383 }
1384 else
5ca0d812 1385#endif
92346151
SC
1386 {
1387 Rect bounds ;
1388 GetControlBounds( m_controlRef , &bounds ) ;
92346151
SC
1389 bounds.left += r->x ;
1390 bounds.top += r->y ;
1391 bounds.bottom = bounds.top + r->height ;
1392 bounds.right = bounds.left + r->width ;
1393 wxMacWindowClipper clip( m_peer ) ;
1394 RgnHandle updateRgn = NewRgn() ;
1395 ::ScrollRect( &bounds , dx , dy , updateRgn ) ;
1396 InvalWindowRgn( GetControlOwner( m_controlRef ) , updateRgn ) ;
1397 }
5ca0d812
SC
1398}
1399
1400
1401// SetNeedsDisplay would not invalidate the children
1402
1403//
1404// Databrowser
1405//
1406
9d8aca48 1407OSStatus wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options )
5ca0d812
SC
1408{
1409 return SetDataBrowserSelectionFlags( m_controlRef , options ) ;
1410}
1411
1412OSStatus wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc,
9d8aca48 1413 DataBrowserTableViewColumnIndex position )
5ca0d812
SC
1414{
1415 return AddDataBrowserListViewColumn( m_controlRef , columnDesc, position ) ;
1416}
1417
1418OSStatus wxMacControl::AutoSizeListViewColumns()
1419{
1420 return AutoSizeDataBrowserListViewColumns(m_controlRef) ;
1421}
1422
9d8aca48 1423OSStatus wxMacControl::SetHasScrollBars( bool horiz , bool vert )
5ca0d812
SC
1424{
1425 return SetDataBrowserHasScrollBars( m_controlRef , horiz , vert ) ;
1426}
1427
1428OSStatus wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1429{
1430 return SetDataBrowserTableViewHiliteStyle( m_controlRef , hiliteStyle ) ;
1431}
1432
9d8aca48 1433OSStatus wxMacControl::SetListViewHeaderBtnHeight(UInt16 height)
5ca0d812
SC
1434{
1435 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef ,height ) ;
1436}
1437
9d8aca48 1438OSStatus wxMacControl::SetCallbacks(const DataBrowserCallbacks * callbacks)
5ca0d812
SC
1439{
1440 return SetDataBrowserCallbacks( m_controlRef , callbacks ) ;
1441}
1442
1443OSStatus wxMacControl::UpdateItems( DataBrowserItemID container, UInt32 numItems,
9d8aca48 1444 const DataBrowserItemID* items,
5ca0d812 1445 DataBrowserPropertyID preSortProperty,
9d8aca48 1446 DataBrowserPropertyID propertyID )
5ca0d812
SC
1447{
1448 return UpdateDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty, propertyID ) ;
1449}
1450
9d8aca48 1451bool wxMacControl::IsItemSelected( DataBrowserItemID item )
5ca0d812
SC
1452{
1453 return IsDataBrowserItemSelected( m_controlRef , item ) ;
1454}
1455
1456OSStatus wxMacControl::AddItems( DataBrowserItemID container, UInt32 numItems,
9d8aca48
WS
1457 const DataBrowserItemID* items,
1458 DataBrowserPropertyID preSortProperty )
5ca0d812
SC
1459{
1460 return AddDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ;
1461}
1462
1463OSStatus wxMacControl::RemoveItems( DataBrowserItemID container, UInt32 numItems,
9d8aca48
WS
1464 const DataBrowserItemID* items,
1465 DataBrowserPropertyID preSortProperty )
5ca0d812
SC
1466{
1467 return RemoveDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ;
1468}
1469
1470OSStatus wxMacControl::RevealItem( DataBrowserItemID item,
1471 DataBrowserPropertyID propertyID,
9d8aca48 1472 DataBrowserRevealOptions options )
5ca0d812
SC
1473{
1474 return RevealDataBrowserItem( m_controlRef , item , propertyID , options ) ;
1475}
1476
1477OSStatus wxMacControl::SetSelectedItems(UInt32 numItems,
1478 const DataBrowserItemID * items,
9d8aca48 1479 DataBrowserSetOption operation )
5ca0d812
SC
1480{
1481 return SetDataBrowserSelectedItems( m_controlRef , numItems , items, operation ) ;
1482}
1483
9d8aca48 1484OSStatus wxMacControl::GetSelectionAnchor( DataBrowserItemID * first, DataBrowserItemID * last )
c020f421
SC
1485{
1486 return GetDataBrowserSelectionAnchor( m_controlRef , first , last ) ;
1487}
1488
5ca0d812
SC
1489//
1490// Tab Control
1491//
9d8aca48
WS
1492
1493OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
5ca0d812
SC
1494{
1495 return ::SetTabEnabled( m_controlRef , tabNo , enable ) ;
1496}
9d8aca48 1497
30e77b5c
SC
1498//
1499// Quartz Support
1500//
1501
1502#ifdef __WXMAC_OSX__
1503// snippets from Sketch Sample from Apple :
1504
1505#define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
1506/*
1507 This function locates, opens, and returns the profile reference for the calibrated
1508 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
1509 with the profile reference this function returns.
1510*/
1511CMProfileRef wxMacOpenGenericProfile(void)
1512{
1513 static CMProfileRef cachedRGBProfileRef = NULL;
1514
1515 // we only create the profile reference once
1516 if (cachedRGBProfileRef == NULL)
1517 {
1518 CMProfileLocation loc;
1519
1520 loc.locType = cmPathBasedProfile;
1521 strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
1522
1523 verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
1524 }
1525
1526 if (cachedRGBProfileRef)
1527 {
1528 // clone the profile reference so that the caller has their own reference, not our cached one
1529 CMCloneProfileRef(cachedRGBProfileRef);
1530 }
1531
1532 return cachedRGBProfileRef;
1533}
1534
1535/*
1536 Return the generic RGB color space. This is a 'get' function and the caller should
1537 not release the returned value unless the caller retains it first. Usually callers
1538 of this routine will immediately use the returned colorspace with CoreGraphics
1539 so they typically do not need to retain it themselves.
1540
1541 This function creates the generic RGB color space once and hangs onto it so it can
1542 return it whenever this function is called.
1543*/
1544
1545CGColorSpaceRef wxMacGetGenericRGBColorSpace()
1546{
1547 static CGColorSpaceRef genericRGBColorSpace = NULL;
1548
1549 if (genericRGBColorSpace == NULL)
1550 {
1551 CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
1552
1553 if (genericRGBProfile)
1554 {
1555 genericRGBColorSpace = CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile);
1556 wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ) ;
1557
1558 // we opened the profile so it is up to us to close it
1559 CMCloseProfile(genericRGBProfile);
1560 }
1561 }
1562 return genericRGBColorSpace;
1563}
1564#endif
1565
b6ed2b86
VZ
1566#endif // wxUSE_GUI
1567