]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/utils.cpp
introduction of m_peer
[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
12#ifdef __GNUG__
13// Note: this is done in utilscmn.cpp now.
e9576ca5
SC
14// #pragma implementation "utils.h"
15#endif
16
17#include "wx/setup.h"
18#include "wx/utils.h"
19#include "wx/app.h"
2bf2d09e 20#include "wx/apptrait.h"
b6ed2b86
VZ
21
22#if wxUSE_GUI
23 #include "wx/mac/uma.h"
fe929141
SC
24 #include "wx/font.h"
25#else
26 #include "wx/intl.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
2d4e4f80
GD
36#ifdef __DARWIN__
37# include "MoreFilesX.h"
38#else
39# include "MoreFiles.h"
40# include "MoreFilesExtras.h"
41#endif
518af45b 42
66a09d47
SC
43#ifndef __DARWIN__
44#include <Threads.h>
45#include <Sound.h>
46#endif
47
7f0c3a63
SC
48#include <ATSUnicode.h>
49#include <TextCommon.h>
50#include <TextEncodingConverter.h>
427ff662 51
8aa701ed 52#include "wx/mac/private.h" // includes mac headers
a434b43f
VZ
53
54#if defined(__MWERKS__) && wxUSE_UNICODE
55 #include <wtime.h>
56#endif
57
659b3e8b
VZ
58// ---------------------------------------------------------------------------
59// code used in both base and GUI compilation
60// ---------------------------------------------------------------------------
61
62// our OS version is the same in non GUI and GUI cases
63static int DoGetOSVersion(int *majorVsn, int *minorVsn)
64{
65 long theSystem ;
66
67 // are there x-platform conventions ?
68
69 Gestalt(gestaltSystemVersion, &theSystem) ;
70 if (minorVsn != NULL) {
71 *minorVsn = (theSystem & 0xFF ) ;
72 }
73 if (majorVsn != NULL) {
74 *majorVsn = (theSystem >> 8 ) ;
75 }
76#ifdef __DARWIN__
77 return wxMAC_DARWIN;
78#else
79 return wxMAC;
80#endif
81}
82
b6ed2b86 83#if wxUSE_BASE
a434b43f 84
f5c6eb5c 85#ifndef __DARWIN__
03e11df5
GD
86// defined in unix/utilsunx.cpp for Mac OS X
87
2f1ae414
SC
88// get full hostname (with domain name if possible)
89bool wxGetFullHostName(wxChar *buf, int maxSize)
90{
91 return wxGetHostName(buf, maxSize);
92}
93
94// Get hostname only (without domain name)
427ff662 95bool wxGetHostName(wxChar *buf, int maxSize)
e9576ca5 96{
e40298d5
JS
97 // Gets Chooser name of user by examining a System resource.
98
99 const short kComputerNameID = -16413;
5be55d56 100
e40298d5
JS
101 short oldResFile = CurResFile() ;
102 UseResFile(0);
103 StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);
104 UseResFile(oldResFile);
105
106 if (chooserName && *chooserName)
107 {
427ff662
SC
108 HLock( (Handle) chooserName ) ;
109 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
110 HUnlock( (Handle) chooserName ) ;
111 ReleaseResource( (Handle) chooserName ) ;
112 wxStrncpy( buf , name , maxSize - 1 ) ;
e40298d5
JS
113 }
114 else
115 buf[0] = 0 ;
0a67a93b
SC
116
117 return TRUE;
e9576ca5
SC
118}
119
120// Get user ID e.g. jacs
427ff662 121bool wxGetUserId(wxChar *buf, int maxSize)
e9576ca5 122{
0a67a93b 123 return wxGetUserName( buf , maxSize ) ;
e9576ca5
SC
124}
125
5b781a67
SC
126const wxChar* wxGetHomeDir(wxString *pstr)
127{
e40298d5
JS
128 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
129 return pstr->c_str() ;
5b781a67
SC
130}
131
a31a5f85 132// Get user name e.g. Stefan Csomor
427ff662 133bool wxGetUserName(wxChar *buf, int maxSize)
e9576ca5 134{
e40298d5
JS
135 // Gets Chooser name of user by examining a System resource.
136
137 const short kChooserNameID = -16096;
5be55d56 138
e40298d5
JS
139 short oldResFile = CurResFile() ;
140 UseResFile(0);
141 StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);
142 UseResFile(oldResFile);
143
144 if (chooserName && *chooserName)
145 {
427ff662
SC
146 HLock( (Handle) chooserName ) ;
147 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
148 HUnlock( (Handle) chooserName ) ;
149 ReleaseResource( (Handle) chooserName ) ;
150 wxStrncpy( buf , name , maxSize - 1 ) ;
e40298d5
JS
151 }
152 else
153 buf[0] = 0 ;
0a67a93b
SC
154
155 return TRUE;
e9576ca5
SC
156}
157
5dbb17e2 158int wxKill(long pid, wxSignal sig , wxKillError *rc )
e9576ca5
SC
159{
160 // TODO
161 return 0;
162}
163
5dbb17e2
SC
164WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
165{
e40298d5
JS
166 // TODO : under classic there is no environement support, under X yes
167 return false ;
5dbb17e2
SC
168}
169
170// set the env var name to the given value, return TRUE on success
171WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
172{
e40298d5
JS
173 // TODO : under classic there is no environement support, under X yes
174 return false ;
5dbb17e2
SC
175}
176
e9576ca5
SC
177//
178// Execute a program in an Interactive Shell
179//
180bool wxShell(const wxString& command)
181{
182 // TODO
183 return FALSE;
184}
185
5be55d56 186// Shutdown or reboot the PC
f6ba47d9
VZ
187bool wxShutdown(wxShutdownFlags wFlags)
188{
189 // TODO
190 return FALSE;
191}
192
e9576ca5
SC
193// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
194long wxGetFreeMemory()
195{
0a67a93b
SC
196 return FreeMem() ;
197}
198
199void wxUsleep(unsigned long milliseconds)
200{
9cc64be1
SC
201 // TODO remove if we don't encounter any other problemsy
202 /*
e7e1b01e 203 clock_t start = clock() ;
5be55d56 204 do
e7e1b01e 205 {
e40298d5 206 YieldToAnyThread() ;
2a616188 207 } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ;
9cc64be1
SC
208 */
209 wxThread::Sleep( milliseconds ) ;
e9576ca5
SC
210}
211
212void wxSleep(int nSecs)
213{
0a67a93b 214 wxUsleep(1000*nSecs);
e9576ca5
SC
215}
216
217// Consume all events until no more left
218void wxFlushEvents()
219{
220}
221
f5c6eb5c 222#endif // !__DARWIN__
e9576ca5
SC
223
224// Emit a beeeeeep
225void wxBell()
226{
0a67a93b 227 SysBeep(30);
e9576ca5
SC
228}
229
324899f6 230wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
29c99ad3 231{
a8eaaeb2 232 static wxToolkitInfo info;
66b6b57c 233 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
a8eaaeb2 234 info.name = _T("wxBase");
324899f6 235 return info;
29c99ad3
VZ
236}
237
b6ed2b86
VZ
238#endif // wxUSE_BASE
239
240#if wxUSE_GUI
536732e4 241
324899f6 242wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
29c99ad3 243{
a8eaaeb2 244 static wxToolkitInfo info;
66b6b57c 245 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
a8eaaeb2
VS
246 info.shortName = _T("mac");
247 info.name = _T("wxMac");
248#ifdef __WXUNIVERSAL__
249 info.shortName << _T("univ");
250 info.name << _T("/wxUniversal");
251#endif
324899f6 252 return info;
29c99ad3
VZ
253}
254
e9576ca5
SC
255// Reading and writing resources (eg WIN.INI, .Xdefaults)
256#if wxUSE_RESOURCES
257bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
258{
259 // TODO
260 return FALSE;
261}
262
263bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
264{
427ff662
SC
265 wxString buf;
266 buf.Printf(wxT("%.4f"), value);
267
e40298d5 268 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
269}
270
271bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
272{
427ff662
SC
273 wxString buf;
274 buf.Printf(wxT("%ld"), value);
275
e40298d5 276 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
277}
278
279bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
280{
427ff662
SC
281 wxString buf;
282 buf.Printf(wxT("%d"), value);
283
e40298d5 284 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
285}
286
287bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
288{
289 // TODO
290 return FALSE;
291}
292
293bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
294{
e40298d5
JS
295 char *s = NULL;
296 bool succ = wxGetResource(section, entry, (char **)&s, file);
297 if (succ)
298 {
299 *value = (float)strtod(s, NULL);
300 delete[] s;
301 return TRUE;
302 }
303 else return FALSE;
e9576ca5
SC
304}
305
306bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
307{
e40298d5
JS
308 char *s = NULL;
309 bool succ = wxGetResource(section, entry, (char **)&s, file);
310 if (succ)
311 {
312 *value = strtol(s, NULL, 10);
313 delete[] s;
314 return TRUE;
315 }
316 else return FALSE;
e9576ca5
SC
317}
318
319bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
320{
e40298d5
JS
321 char *s = NULL;
322 bool succ = wxGetResource(section, entry, (char **)&s, file);
323 if (succ)
324 {
325 *value = (int)strtol(s, NULL, 10);
326 delete[] s;
327 return TRUE;
328 }
329 else return FALSE;
e9576ca5
SC
330}
331#endif // wxUSE_RESOURCES
332
6b57b49a 333int gs_wxBusyCursorCount = 0;
e40298d5
JS
334extern wxCursor gMacCurrentCursor ;
335wxCursor gMacStoredActiveCursor ;
e9576ca5
SC
336
337// Set the cursor to the busy cursor for all windows
338void wxBeginBusyCursor(wxCursor *cursor)
339{
e40298d5
JS
340 if (gs_wxBusyCursorCount++ == 0)
341 {
342 gMacStoredActiveCursor = gMacCurrentCursor ;
343 cursor->MacInstall() ;
344 }
345 //else: nothing to do, already set
e9576ca5
SC
346}
347
348// Restore cursor to normal
349void wxEndBusyCursor()
350{
6b57b49a 351 wxCHECK_RET( gs_wxBusyCursorCount > 0,
e40298d5 352 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
5be55d56 353
e40298d5
JS
354 if (--gs_wxBusyCursorCount == 0)
355 {
356 gMacStoredActiveCursor.MacInstall() ;
357 gMacStoredActiveCursor = wxNullCursor ;
358 }
e9576ca5
SC
359}
360
361// TRUE if we're between the above two calls
362bool wxIsBusy()
363{
e40298d5 364 return (gs_wxBusyCursorCount > 0);
ec5d7799 365}
e9576ca5 366
2dbc444a
RD
367#endif // wxUSE_GUI
368
369#if wxUSE_BASE
370
e7e1b01e 371wxString wxMacFindFolder( short vol,
e40298d5
JS
372 OSType folderType,
373 Boolean createFolder)
2f1ae414 374{
2d4e4f80
GD
375 short vRefNum ;
376 long dirID ;
377 wxString strDir ;
5be55d56 378
2d4e4f80
GD
379 if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
380 {
381 FSSpec file ;
382 if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
383 {
384 strDir = wxMacFSSpec2MacFilename( &file ) + wxFILE_SEP_PATH ;
385 }
386 }
387 return strDir ;
2f1ae414
SC
388}
389
2dbc444a
RD
390#endif // wxUSE_BASE
391
392#if wxUSE_GUI
393
e9576ca5
SC
394// Check whether this window wants to process messages, e.g. Stop button
395// in long calculations.
396bool wxCheckForInterrupt(wxWindow *wnd)
397{
398 // TODO
399 return FALSE;
400}
401
402void wxGetMousePosition( int* x, int* y )
403{
519cb848 404 Point pt ;
ec5d7799 405
519cb848
SC
406 GetMouse( &pt ) ;
407 LocalToGlobal( &pt ) ;
408 *x = pt.h ;
409 *y = pt.v ;
e9576ca5
SC
410};
411
412// Return TRUE if we have a colour display
413bool wxColourDisplay()
414{
e9576ca5
SC
415 return TRUE;
416}
417
418// Returns depth of screen
419int wxDisplayDepth()
420{
e40298d5
JS
421 Rect globRect ;
422 SetRect(&globRect, -32760, -32760, 32760, 32760);
423 GDHandle theMaxDevice;
2f1ae414 424
e40298d5
JS
425 int theDepth = 8;
426 theMaxDevice = GetMaxDevice(&globRect);
427 if (theMaxDevice != nil)
428 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
ec5d7799 429
e40298d5 430 return theDepth ;
e9576ca5
SC
431}
432
433// Get size of display
434void wxDisplaySize(int *width, int *height)
435{
e40298d5
JS
436 BitMap screenBits;
437 GetQDGlobalsScreenBits( &screenBits );
5be55d56
VZ
438
439 if (width != NULL) {
e8ca7105
GD
440 *width = screenBits.bounds.right - screenBits.bounds.left ;
441 }
5be55d56 442 if (height != NULL) {
e8ca7105
GD
443 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
444 }
e9576ca5
SC
445}
446
5fde6fcc
GD
447void wxDisplaySizeMM(int *width, int *height)
448{
5b028d57
SC
449 wxDisplaySize(width, height);
450 // on mac 72 is fixed (at least now ;-)
451 float cvPt2Mm = 25.4 / 72;
e8ca7105 452
5be55d56 453 if (width != NULL) {
e8ca7105
GD
454 *width = int( *width * cvPt2Mm );
455 }
5be55d56 456 if (height != NULL) {
e8ca7105
GD
457 *height = int( *height * cvPt2Mm );
458 }
5fde6fcc
GD
459}
460
ec5d7799
RD
461void wxClientDisplayRect(int *x, int *y, int *width, int *height)
462{
ee658398
SC
463 Rect r ;
464 GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ;
465 if ( x )
466 *x = r.left ;
467 if ( y )
468 *y = r.top ;
469 if ( width )
470 *width = r.right - r.left ;
471 if ( height )
472 *height = r.bottom - r.top ;
ec5d7799
RD
473}
474
57591e0e
JS
475wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
476{
477 return wxGenericFindWindowAtPoint(pt);
478}
5dbb17e2 479
b6ed2b86
VZ
480#endif // wxUSE_GUI
481
482#if wxUSE_BASE
483
5dbb17e2
SC
484wxString wxGetOsDescription()
485{
6e73695c
GD
486#ifdef WXWIN_OS_DESCRIPTION
487 // use configure generated description if available
5f3f0f17 488 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
6e73695c 489#else
427ff662 490 return wxT("MacOS") ; //TODO:define further
6e73695c
GD
491#endif
492}
493
b6ed2b86
VZ
494#ifndef __DARWIN__
495wxChar *wxGetUserHome (const wxString& user)
496{
497 // TODO
498 return NULL;
499}
500
501bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
502{
503 if ( path.empty() )
504 return FALSE;
505
506 wxString p = path ;
71111c40 507 if (p[0u] == ':' ) {
b6ed2b86
VZ
508 p = wxGetCwd() + p ;
509 }
510
511 int pos = p.Find(':') ;
512 if ( pos != wxNOT_FOUND ) {
513 p = p.Mid(1,pos) ;
514 }
515
516 p = p + wxT(":") ;
517
518 Str255 volumeName ;
519 XVolumeParam pb ;
520
521 wxMacStringToPascal( p , volumeName ) ;
522 OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ;
523 if ( err == noErr ) {
524 if ( pTotal ) {
525 (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ;
526 }
527 if ( pFree ) {
528 (*pFree) = wxLongLong( pb.ioVFreeBytes ) ;
529 }
530 }
531
532 return err == noErr ;
533}
534#endif // !__DARWIN__
535
3d963f81
SC
536//---------------------------------------------------------------------------
537// wxMac Specific utility functions
538//---------------------------------------------------------------------------
539
5be55d56 540void wxMacStringToPascal( const wxString&from , StringPtr to )
427ff662 541{
939fba6c 542 wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
427ff662
SC
543 int len = strlen(buf) ;
544
545 if ( len > 255 )
546 len = 255 ;
547 to[0] = len ;
548 memcpy( (char*) &to[1] , buf , len ) ;
549}
550
5be55d56 551wxString wxMacMakeStringFromPascal( ConstStringPtr from )
427ff662 552{
939fba6c 553 return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
427ff662
SC
554}
555
e50d5284
RD
556
557wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
558{
559 TextEncodingBase enc = 0 ;
fe929141
SC
560 if ( encoding == wxFONTENCODING_DEFAULT )
561 {
562#if wxUSE_GUI
563 encoding = wxFont::GetDefaultEncoding() ;
564#else
565 encoding = wxLocale::GetSystemEncoding() ;
566#endif
567 }
e50d5284
RD
568
569 switch( encoding)
570 {
571 case wxFONTENCODING_ISO8859_1 :
572 enc = kTextEncodingISOLatin1 ;
573 break ;
574 case wxFONTENCODING_ISO8859_2 :
575 enc = kTextEncodingISOLatin2;
576 break ;
577 case wxFONTENCODING_ISO8859_3 :
578 enc = kTextEncodingISOLatin3 ;
579 break ;
580 case wxFONTENCODING_ISO8859_4 :
581 enc = kTextEncodingISOLatin4;
582 break ;
583 case wxFONTENCODING_ISO8859_5 :
584 enc = kTextEncodingISOLatinCyrillic;
585 break ;
586 case wxFONTENCODING_ISO8859_6 :
587 enc = kTextEncodingISOLatinArabic;
588 break ;
589 case wxFONTENCODING_ISO8859_7 :
590 enc = kTextEncodingISOLatinGreek;
591 break ;
592 case wxFONTENCODING_ISO8859_8 :
593 enc = kTextEncodingISOLatinHebrew;
594 break ;
595 case wxFONTENCODING_ISO8859_9 :
596 enc = kTextEncodingISOLatin5;
597 break ;
598 case wxFONTENCODING_ISO8859_10 :
599 enc = kTextEncodingISOLatin6;
600 break ;
601 case wxFONTENCODING_ISO8859_13 :
602 enc = kTextEncodingISOLatin7;
603 break ;
604 case wxFONTENCODING_ISO8859_14 :
605 enc = kTextEncodingISOLatin8;
606 break ;
607 case wxFONTENCODING_ISO8859_15 :
608 enc = kTextEncodingISOLatin9;
609 break ;
610
611 case wxFONTENCODING_KOI8 :
612 enc = kTextEncodingKOI8_R;
613 break ;
614 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
615 enc = kTextEncodingDOSRussian;
616 break ;
617/*
618 case wxFONTENCODING_BULGARIAN :
619 enc = ;
620 break ;
621*/
622 case wxFONTENCODING_CP437 :
623 enc =kTextEncodingDOSLatinUS ;
624 break ;
625 case wxFONTENCODING_CP850 :
626 enc = kTextEncodingDOSLatin1;
627 break ;
628 case wxFONTENCODING_CP852 :
629 enc = kTextEncodingDOSLatin2;
630 break ;
631 case wxFONTENCODING_CP855 :
632 enc = kTextEncodingDOSCyrillic;
633 break ;
634 case wxFONTENCODING_CP866 :
635 enc =kTextEncodingDOSRussian ;
636 break ;
637 case wxFONTENCODING_CP874 :
638 enc = kTextEncodingDOSThai;
639 break ;
640 case wxFONTENCODING_CP932 :
641 enc = kTextEncodingDOSJapanese;
642 break ;
643 case wxFONTENCODING_CP936 :
644 enc =kTextEncodingDOSChineseSimplif ;
645 break ;
646 case wxFONTENCODING_CP949 :
647 enc = kTextEncodingDOSKorean;
648 break ;
649 case wxFONTENCODING_CP950 :
650 enc = kTextEncodingDOSChineseTrad;
651 break ;
652
653 case wxFONTENCODING_CP1250 :
654 enc = kTextEncodingWindowsLatin2;
655 break ;
656 case wxFONTENCODING_CP1251 :
657 enc =kTextEncodingWindowsCyrillic ;
658 break ;
659 case wxFONTENCODING_CP1252 :
660 enc =kTextEncodingWindowsLatin1 ;
661 break ;
662 case wxFONTENCODING_CP1253 :
663 enc = kTextEncodingWindowsGreek;
664 break ;
665 case wxFONTENCODING_CP1254 :
666 enc = kTextEncodingWindowsLatin5;
667 break ;
668 case wxFONTENCODING_CP1255 :
669 enc =kTextEncodingWindowsHebrew ;
670 break ;
671 case wxFONTENCODING_CP1256 :
672 enc =kTextEncodingWindowsArabic ;
673 break ;
674 case wxFONTENCODING_CP1257 :
675 enc = kTextEncodingWindowsBalticRim;
676 break ;
677
678 case wxFONTENCODING_UTF7 :
679 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
680 break ;
681 case wxFONTENCODING_UTF8 :
682 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
683 break ;
684 case wxFONTENCODING_EUC_JP :
685 enc = kTextEncodingEUC_JP;
686 break ;
687 case wxFONTENCODING_UTF16BE :
688 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
689 break ;
690 case wxFONTENCODING_UTF16LE :
691 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
692 break ;
693 case wxFONTENCODING_UTF32BE :
694 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
695 break ;
696 case wxFONTENCODING_UTF32LE :
697 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
698 break ;
699
700 case wxFONTENCODING_MACROMAN :
701 enc = kTextEncodingMacRoman ;
702 break ;
703 case wxFONTENCODING_MACJAPANESE :
704 enc = kTextEncodingMacJapanese ;
705 break ;
706 case wxFONTENCODING_MACCHINESETRAD :
707 enc = kTextEncodingMacChineseTrad ;
708 break ;
709 case wxFONTENCODING_MACKOREAN :
710 enc = kTextEncodingMacKorean ;
711 break ;
712 case wxFONTENCODING_MACARABIC :
713 enc = kTextEncodingMacArabic ;
714 break ;
715 case wxFONTENCODING_MACHEBREW :
716 enc = kTextEncodingMacHebrew ;
717 break ;
718 case wxFONTENCODING_MACGREEK :
719 enc = kTextEncodingMacGreek ;
720 break ;
721 case wxFONTENCODING_MACCYRILLIC :
722 enc = kTextEncodingMacCyrillic ;
723 break ;
724 case wxFONTENCODING_MACDEVANAGARI :
725 enc = kTextEncodingMacDevanagari ;
726 break ;
727 case wxFONTENCODING_MACGURMUKHI :
728 enc = kTextEncodingMacGurmukhi ;
729 break ;
730 case wxFONTENCODING_MACGUJARATI :
731 enc = kTextEncodingMacGujarati ;
732 break ;
733 case wxFONTENCODING_MACORIYA :
734 enc = kTextEncodingMacOriya ;
735 break ;
736 case wxFONTENCODING_MACBENGALI :
737 enc = kTextEncodingMacBengali ;
738 break ;
739 case wxFONTENCODING_MACTAMIL :
740 enc = kTextEncodingMacTamil ;
741 break ;
742 case wxFONTENCODING_MACTELUGU :
743 enc = kTextEncodingMacTelugu ;
744 break ;
745 case wxFONTENCODING_MACKANNADA :
746 enc = kTextEncodingMacKannada ;
747 break ;
748 case wxFONTENCODING_MACMALAJALAM :
749 enc = kTextEncodingMacMalayalam ;
750 break ;
751 case wxFONTENCODING_MACSINHALESE :
752 enc = kTextEncodingMacSinhalese ;
753 break ;
754 case wxFONTENCODING_MACBURMESE :
755 enc = kTextEncodingMacBurmese ;
756 break ;
757 case wxFONTENCODING_MACKHMER :
758 enc = kTextEncodingMacKhmer ;
759 break ;
760 case wxFONTENCODING_MACTHAI :
761 enc = kTextEncodingMacThai ;
762 break ;
763 case wxFONTENCODING_MACLAOTIAN :
764 enc = kTextEncodingMacLaotian ;
765 break ;
766 case wxFONTENCODING_MACGEORGIAN :
767 enc = kTextEncodingMacGeorgian ;
768 break ;
769 case wxFONTENCODING_MACARMENIAN :
770 enc = kTextEncodingMacArmenian ;
771 break ;
772 case wxFONTENCODING_MACCHINESESIMP :
773 enc = kTextEncodingMacChineseSimp ;
774 break ;
775 case wxFONTENCODING_MACTIBETAN :
776 enc = kTextEncodingMacTibetan ;
777 break ;
778 case wxFONTENCODING_MACMONGOLIAN :
779 enc = kTextEncodingMacMongolian ;
780 break ;
781 case wxFONTENCODING_MACETHIOPIC :
782 enc = kTextEncodingMacEthiopic ;
783 break ;
784 case wxFONTENCODING_MACCENTRALEUR :
785 enc = kTextEncodingMacCentralEurRoman ;
786 break ;
787 case wxFONTENCODING_MACVIATNAMESE :
788 enc = kTextEncodingMacVietnamese ;
789 break ;
790 case wxFONTENCODING_MACARABICEXT :
791 enc = kTextEncodingMacExtArabic ;
792 break ;
793 case wxFONTENCODING_MACSYMBOL :
794 enc = kTextEncodingMacSymbol ;
795 break ;
796 case wxFONTENCODING_MACDINGBATS :
797 enc = kTextEncodingMacDingbats ;
798 break ;
799 case wxFONTENCODING_MACTURKISH :
800 enc = kTextEncodingMacTurkish ;
801 break ;
802 case wxFONTENCODING_MACCROATIAN :
803 enc = kTextEncodingMacCroatian ;
804 break ;
805 case wxFONTENCODING_MACICELANDIC :
806 enc = kTextEncodingMacIcelandic ;
807 break ;
808 case wxFONTENCODING_MACROMANIAN :
809 enc = kTextEncodingMacRomanian ;
810 break ;
811 case wxFONTENCODING_MACCELTIC :
812 enc = kTextEncodingMacCeltic ;
813 break ;
814 case wxFONTENCODING_MACGAELIC :
815 enc = kTextEncodingMacGaelic ;
816 break ;
817 case wxFONTENCODING_MACKEYBOARD :
818 enc = kTextEncodingMacKeyboardGlyphs ;
79a73b4f
SC
819 break ;
820 default :
821 // to make gcc happy
822 break ;
e50d5284
RD
823 } ;
824 return enc ;
825}
826
827wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
828{
829 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
830
831 switch( encoding)
832 {
833 case kTextEncodingISOLatin1 :
834 enc = wxFONTENCODING_ISO8859_1 ;
835 break ;
836 case kTextEncodingISOLatin2 :
837 enc = wxFONTENCODING_ISO8859_2;
838 break ;
839 case kTextEncodingISOLatin3 :
840 enc = wxFONTENCODING_ISO8859_3 ;
841 break ;
842 case kTextEncodingISOLatin4 :
843 enc = wxFONTENCODING_ISO8859_4;
844 break ;
845 case kTextEncodingISOLatinCyrillic :
846 enc = wxFONTENCODING_ISO8859_5;
847 break ;
848 case kTextEncodingISOLatinArabic :
849 enc = wxFONTENCODING_ISO8859_6;
850 break ;
851 case kTextEncodingISOLatinGreek :
852 enc = wxFONTENCODING_ISO8859_7;
853 break ;
854 case kTextEncodingISOLatinHebrew :
855 enc = wxFONTENCODING_ISO8859_8;
856 break ;
857 case kTextEncodingISOLatin5 :
858 enc = wxFONTENCODING_ISO8859_9;
859 break ;
860 case kTextEncodingISOLatin6 :
861 enc = wxFONTENCODING_ISO8859_10;
862 break ;
863 case kTextEncodingISOLatin7 :
864 enc = wxFONTENCODING_ISO8859_13;
865 break ;
866 case kTextEncodingISOLatin8 :
867 enc = wxFONTENCODING_ISO8859_14;
868 break ;
869 case kTextEncodingISOLatin9 :
870 enc =wxFONTENCODING_ISO8859_15 ;
871 break ;
872
873 case kTextEncodingKOI8_R :
874 enc = wxFONTENCODING_KOI8;
875 break ;
876/*
877 case :
878 enc = wxFONTENCODING_BULGARIAN;
879 break ;
880*/
fe929141 881 case kTextEncodingDOSLatinUS :
e50d5284
RD
882 enc = wxFONTENCODING_CP437;
883 break ;
884 case kTextEncodingDOSLatin1 :
885 enc = wxFONTENCODING_CP850;
886 break ;
887 case kTextEncodingDOSLatin2 :
888 enc =wxFONTENCODING_CP852 ;
889 break ;
890 case kTextEncodingDOSCyrillic :
891 enc = wxFONTENCODING_CP855;
892 break ;
893 case kTextEncodingDOSRussian :
894 enc = wxFONTENCODING_CP866;
895 break ;
896 case kTextEncodingDOSThai :
897 enc =wxFONTENCODING_CP874 ;
898 break ;
899 case kTextEncodingDOSJapanese :
900 enc = wxFONTENCODING_CP932;
901 break ;
902 case kTextEncodingDOSChineseSimplif :
903 enc = wxFONTENCODING_CP936;
904 break ;
905 case kTextEncodingDOSKorean :
906 enc = wxFONTENCODING_CP949;
907 break ;
908 case kTextEncodingDOSChineseTrad :
909 enc = wxFONTENCODING_CP950;
910 break ;
911
912 case kTextEncodingWindowsLatin2 :
913 enc = wxFONTENCODING_CP1250;
914 break ;
915 case kTextEncodingWindowsCyrillic :
916 enc = wxFONTENCODING_CP1251;
917 break ;
918 case kTextEncodingWindowsLatin1 :
919 enc = wxFONTENCODING_CP1252;
920 break ;
921 case kTextEncodingWindowsGreek :
922 enc = wxFONTENCODING_CP1253;
923 break ;
924 case kTextEncodingWindowsLatin5 :
925 enc = wxFONTENCODING_CP1254;
926 break ;
927 case kTextEncodingWindowsHebrew :
928 enc = wxFONTENCODING_CP1255;
929 break ;
930 case kTextEncodingWindowsArabic :
931 enc = wxFONTENCODING_CP1256;
932 break ;
933 case kTextEncodingWindowsBalticRim :
934 enc =wxFONTENCODING_CP1257 ;
935 break ;
936 case kTextEncodingEUC_JP :
937 enc = wxFONTENCODING_EUC_JP;
938 break ;
939 /*
940 case wxFONTENCODING_UTF7 :
941 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
942 break ;
943 case wxFONTENCODING_UTF8 :
944 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
945 break ;
946 case wxFONTENCODING_UTF16BE :
947 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
948 break ;
949 case wxFONTENCODING_UTF16LE :
950 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
951 break ;
952 case wxFONTENCODING_UTF32BE :
953 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
954 break ;
955 case wxFONTENCODING_UTF32LE :
956 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
957 break ;
958 */
959 case kTextEncodingMacRoman :
960 enc = wxFONTENCODING_MACROMAN ;
961 break ;
962 case kTextEncodingMacJapanese :
963 enc = wxFONTENCODING_MACJAPANESE ;
964 break ;
965 case kTextEncodingMacChineseTrad :
966 enc = wxFONTENCODING_MACCHINESETRAD ;
967 break ;
968 case kTextEncodingMacKorean :
969 enc = wxFONTENCODING_MACKOREAN ;
970 break ;
971 case kTextEncodingMacArabic :
972 enc =wxFONTENCODING_MACARABIC ;
973 break ;
974 case kTextEncodingMacHebrew :
975 enc = wxFONTENCODING_MACHEBREW ;
976 break ;
977 case kTextEncodingMacGreek :
978 enc = wxFONTENCODING_MACGREEK ;
979 break ;
980 case kTextEncodingMacCyrillic :
981 enc = wxFONTENCODING_MACCYRILLIC ;
982 break ;
983 case kTextEncodingMacDevanagari :
984 enc = wxFONTENCODING_MACDEVANAGARI ;
985 break ;
986 case kTextEncodingMacGurmukhi :
987 enc = wxFONTENCODING_MACGURMUKHI ;
988 break ;
989 case kTextEncodingMacGujarati :
990 enc = wxFONTENCODING_MACGUJARATI ;
991 break ;
992 case kTextEncodingMacOriya :
993 enc =wxFONTENCODING_MACORIYA ;
994 break ;
995 case kTextEncodingMacBengali :
996 enc =wxFONTENCODING_MACBENGALI ;
997 break ;
998 case kTextEncodingMacTamil :
999 enc = wxFONTENCODING_MACTAMIL ;
1000 break ;
1001 case kTextEncodingMacTelugu :
1002 enc = wxFONTENCODING_MACTELUGU ;
1003 break ;
1004 case kTextEncodingMacKannada :
1005 enc = wxFONTENCODING_MACKANNADA ;
1006 break ;
1007 case kTextEncodingMacMalayalam :
1008 enc = wxFONTENCODING_MACMALAJALAM ;
1009 break ;
1010 case kTextEncodingMacSinhalese :
1011 enc = wxFONTENCODING_MACSINHALESE ;
1012 break ;
1013 case kTextEncodingMacBurmese :
1014 enc = wxFONTENCODING_MACBURMESE ;
1015 break ;
1016 case kTextEncodingMacKhmer :
1017 enc = wxFONTENCODING_MACKHMER ;
1018 break ;
1019 case kTextEncodingMacThai :
1020 enc = wxFONTENCODING_MACTHAI ;
1021 break ;
1022 case kTextEncodingMacLaotian :
1023 enc = wxFONTENCODING_MACLAOTIAN ;
1024 break ;
1025 case kTextEncodingMacGeorgian :
1026 enc = wxFONTENCODING_MACGEORGIAN ;
1027 break ;
1028 case kTextEncodingMacArmenian :
1029 enc = wxFONTENCODING_MACARMENIAN ;
1030 break ;
1031 case kTextEncodingMacChineseSimp :
1032 enc = wxFONTENCODING_MACCHINESESIMP ;
1033 break ;
1034 case kTextEncodingMacTibetan :
1035 enc = wxFONTENCODING_MACTIBETAN ;
1036 break ;
1037 case kTextEncodingMacMongolian :
1038 enc = wxFONTENCODING_MACMONGOLIAN ;
1039 break ;
1040 case kTextEncodingMacEthiopic :
1041 enc = wxFONTENCODING_MACETHIOPIC ;
1042 break ;
1043 case kTextEncodingMacCentralEurRoman:
1044 enc = wxFONTENCODING_MACCENTRALEUR ;
1045 break ;
1046 case kTextEncodingMacVietnamese:
1047 enc = wxFONTENCODING_MACVIATNAMESE ;
1048 break ;
1049 case kTextEncodingMacExtArabic :
1050 enc = wxFONTENCODING_MACARABICEXT ;
1051 break ;
1052 case kTextEncodingMacSymbol :
1053 enc = wxFONTENCODING_MACSYMBOL ;
1054 break ;
1055 case kTextEncodingMacDingbats :
1056 enc = wxFONTENCODING_MACDINGBATS ;
1057 break ;
1058 case kTextEncodingMacTurkish :
1059 enc = wxFONTENCODING_MACTURKISH ;
1060 break ;
1061 case kTextEncodingMacCroatian :
1062 enc = wxFONTENCODING_MACCROATIAN ;
1063 break ;
1064 case kTextEncodingMacIcelandic :
1065 enc = wxFONTENCODING_MACICELANDIC ;
1066 break ;
1067 case kTextEncodingMacRomanian :
1068 enc = wxFONTENCODING_MACROMANIAN ;
1069 break ;
1070 case kTextEncodingMacCeltic :
1071 enc = wxFONTENCODING_MACCELTIC ;
1072 break ;
1073 case kTextEncodingMacGaelic :
1074 enc = wxFONTENCODING_MACGAELIC ;
1075 break ;
1076 case kTextEncodingMacKeyboardGlyphs :
1077 enc = wxFONTENCODING_MACKEYBOARD ;
1078 break ;
1079 } ;
1080 return enc ;
1081}
1082
2dbc444a
RD
1083#endif // wxUSE_BASE
1084
1085#if wxUSE_GUI
1086
1087
5be55d56 1088//
427ff662
SC
1089// CFStringRefs (Carbon only)
1090//
1091
1092#if TARGET_CARBON
71111c40 1093
427ff662 1094// converts this string into a carbon foundation string with optional pc 2 mac encoding
fe929141 1095void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
427ff662 1096{
fe929141 1097 Release() ;
79a73b4f 1098
71111c40 1099 wxString str = st ;
8aa701ed 1100 wxMacConvertNewlines13To10( &str ) ;
427ff662 1101#if wxUSE_UNICODE
71111c40 1102#if SIZEOF_WCHAR_T == 2
5be55d56 1103 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
79a73b4f 1104 (UniChar*)str.wc_str() , str.Len() );
427ff662 1105#else
79a73b4f
SC
1106 wxMBConvUTF16BE converter ;
1107 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1108 UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
1109 converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
1110 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
1111 unibuf , unicharlen / sizeof(UniChar) ) ;
1112 delete[] unibuf ;
71111c40 1113#endif
71111c40 1114#else // not wxUSE_UNICODE
427ff662 1115 m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
fe929141 1116 wxMacGetSystemEncFromFontEnc( encoding ) ) ;
427ff662
SC
1117#endif
1118 m_release = true ;
1119}
1120
fe929141 1121wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
427ff662 1122{
79a73b4f
SC
1123 Size cflen = CFStringGetLength( m_cfs ) ;
1124 size_t noChars ;
1125 wxChar* buf = NULL ;
1126
427ff662 1127#if wxUSE_UNICODE
fe929141 1128#if SIZEOF_WCHAR_T == 2
79a73b4f
SC
1129 buf = new wxChar[ cflen + 1 ] ;
1130 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
1131 noChars = cflen ;
fe929141 1132#else
79a73b4f
SC
1133 UniChar* unibuf = new UniChar[ cflen + 1 ] ;
1134 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
1135 unibuf[cflen] = 0 ;
590e21b0 1136 wxMBConvUTF16BE converter ;
79a73b4f
SC
1137 noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
1138 buf = new wxChar[ noChars + 1 ] ;
1139 converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
1140 delete[] unibuf ;
1141#endif
427ff662 1142#else
79a73b4f
SC
1143 CFIndex cStrLen ;
1144 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
ac86379e 1145 '?' , false , NULL , 0 , &cStrLen ) ;
79a73b4f 1146 buf = new wxChar[ cStrLen + 1 ] ;
ac86379e
SC
1147 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1148 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
79a73b4f 1149 noChars = cStrLen ;
427ff662 1150#endif
79a73b4f
SC
1151
1152 buf[noChars] = 0 ;
8aa701ed 1153 wxMacConvertNewlines10To13( buf ) ;
79a73b4f
SC
1154 wxString result(buf) ;
1155 delete[] buf ;
427ff662
SC
1156 return result ;
1157}
1158
3d963f81
SC
1159#endif //TARGET_CARBON
1160
8aa701ed
SC
1161void wxMacConvertNewlines13To10( char * data )
1162{
1163 char * buf = data ;
1164 while( (buf=strchr(buf,0x0d)) != NULL )
1165 {
1166 *buf = 0x0a ;
1167 buf++ ;
1168 }
1169}
1170
1171void wxMacConvertNewlines10To13( char * data )
1172{
1173 char * buf = data ;
1174 while( (buf=strchr(buf,0x0a)) != NULL )
1175 {
1176 *buf = 0x0d ;
1177 buf++ ;
1178 }
1179}
1180
1181void wxMacConvertNewlines13To10( wxString * data )
1182{
be6628ce
SC
1183 size_t len = data->Length() ;
1184
1185 if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
8aa701ed
SC
1186 return ;
1187
be6628ce
SC
1188 wxString temp(*data) ;
1189 wxStringBuffer buf(*data,len ) ;
1190 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1191
1192 wxMacConvertNewlines13To10( buf ) ;
8aa701ed
SC
1193}
1194
1195void wxMacConvertNewlines10To13( wxString * data )
1196{
be6628ce
SC
1197 size_t len = data->Length() ;
1198
1199 if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL)
8aa701ed 1200 return ;
be6628ce
SC
1201
1202 wxString temp(*data) ;
1203 wxStringBuffer buf(*data,len ) ;
1204 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1205 wxMacConvertNewlines10To13( buf ) ;
8aa701ed
SC
1206}
1207
1208
1209#if wxUSE_UNICODE
1210void wxMacConvertNewlines13To10( wxChar * data )
1211{
1212 wxChar * buf = data ;
1213 while( (buf=wxStrchr(buf,0x0d)) != NULL )
1214 {
1215 *buf = 0x0a ;
1216 buf++ ;
1217 }
1218}
1219
1220void wxMacConvertNewlines10To13( wxChar * data )
1221{
1222 wxChar * buf = data ;
1223 while( (buf=wxStrchr(buf,0x0a)) != NULL )
1224 {
1225 *buf = 0x0d ;
1226 buf++ ;
1227 }
1228}
1229#endif
1230
73280e05
SC
1231// ----------------------------------------------------------------------------
1232// Common Event Support
1233// ----------------------------------------------------------------------------
1234
d13ea1bd
RD
1235#endif // wxUSE_GUI
1236
1237#if wxUSE_BASE
1238
73280e05
SC
1239extern ProcessSerialNumber gAppProcess ;
1240
1241void wxMacWakeUp()
1242{
1243 ProcessSerialNumber psn ;
1244 Boolean isSame ;
1245 psn.highLongOfPSN = 0 ;
1246 psn.lowLongOfPSN = kCurrentProcess ;
1247 SameProcess( &gAppProcess , &psn , &isSame ) ;
1248 if ( isSame )
1249 {
1250#if TARGET_CARBON
1251 EventRef dummyEvent ;
1252 OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(),
1253 kEventAttributeNone, &dummyEvent);
1254 if (err == noErr)
1255 {
1256 err = PostEventToQueue(GetMainEventQueue(), dummyEvent,
1257 kEventPriorityHigh);
1258 }
1259#else
1260 PostEvent( nullEvent , 0 ) ;
1261#endif
1262 }
1263 else
1264 {
1265 WakeUpProcess( &gAppProcess ) ;
1266 }
1267}
1268
d13ea1bd
RD
1269#endif // wxUSE_BASE
1270
1271#if wxUSE_GUI
1272
1273
facd6764
SC
1274// ----------------------------------------------------------------------------
1275// Carbon Event Support
1276// ----------------------------------------------------------------------------
1277
1278
1279OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
1280{
1281 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ;
1282}
1283
1284OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, void * inData)
1285{
1286 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ;
1287}
1288
86d8b744
SC
1289// ----------------------------------------------------------------------------
1290// Control Access Support
1291// ----------------------------------------------------------------------------
1292
1293OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize )
1294{
1295 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;
1296}
1297
1298OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize )
1299{
1300 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;
1301}
1302
1303OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
1304{
1305 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ;
1306}
1307
a434b43f
VZ
1308// ----------------------------------------------------------------------------
1309// debugging support
1310// ----------------------------------------------------------------------------
1311
1312#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1313
1314// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1315
1316#ifndef __MetroNubUtils__
1317#include "MetroNubUtils.h"
1318#endif
1319
1320#ifndef __GESTALT__
1321#include <Gestalt.h>
1322#endif
1323
1324#if TARGET_API_MAC_CARBON
1325
1326 #include <CodeFragments.h>
1327
536732e4 1328 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
a434b43f
VZ
1329
1330 ProcPtr gCallUniversalProc_Proc = NULL;
1331
1332#endif
1333
1334static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
1335
1336static long fRunOnce = false;
1337
1338/* ---------------------------------------------------------------------------
1339 IsMetroNubInstalled
1340 --------------------------------------------------------------------------- */
1341
1342Boolean IsMetroNubInstalled()
1343{
1344 if (!fRunOnce)
1345 {
1346 long result, value;
1347
1348 fRunOnce = true;
1349 gMetroNubEntry = NULL;
1350
1351 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
1352 {
1353 /* look for MetroNub's Gestalt selector */
1354 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
1355 {
1356
1357 #if TARGET_API_MAC_CARBON
1358 if (gCallUniversalProc_Proc == NULL)
1359 {
1360 CFragConnectionID connectionID;
1361 Ptr mainAddress;
1362 Str255 errorString;
1363 ProcPtr symbolAddress;
1364 OSErr err;
1365 CFragSymbolClass symbolClass;
1366
1367 symbolAddress = NULL;
1368 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
1369 &connectionID, &mainAddress, errorString);
1370
1371 if (err != noErr)
1372 {
1373 gCallUniversalProc_Proc = NULL;
1374 goto end;
1375 }
1376
1377 err = FindSymbol(connectionID, "\pCallUniversalProc",
1378 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
1379
1380 if (err != noErr)
1381 {
1382 gCallUniversalProc_Proc = NULL;
1383 goto end;
1384 }
1385 }
1386 #endif
1387
1388 {
1389 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
1390
1391 /* make sure the version of the API is compatible */
1392 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
1393 kMetroNubUserAPIVersion <= block->apiHiVersion)
1394 gMetroNubEntry = block; /* success! */
1395 }
1396
1397 }
1398 }
1399 }
1400
1401end:
1402
1403#if TARGET_API_MAC_CARBON
1404 return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
1405#else
1406 return (gMetroNubEntry != NULL);
1407#endif
1408}
1409
1410/* ---------------------------------------------------------------------------
1411 IsMWDebuggerRunning [v1 API]
1412 --------------------------------------------------------------------------- */
1413
1414Boolean IsMWDebuggerRunning()
1415{
1416 if (IsMetroNubInstalled())
1417 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
1418 else
1419 return false;
1420}
1421
1422/* ---------------------------------------------------------------------------
1423 AmIBeingMWDebugged [v1 API]
1424 --------------------------------------------------------------------------- */
1425
1426Boolean AmIBeingMWDebugged()
1427{
1428 if (IsMetroNubInstalled())
1429 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
1430 else
1431 return false;
1432}
1433
1434extern bool WXDLLEXPORT wxIsDebuggerRunning()
1435{
1436 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1437}
1438
1439#else
1440
1441extern bool WXDLLEXPORT wxIsDebuggerRunning()
1442{
1443 return false;
1444}
1445
1446#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
1447
b6ed2b86
VZ
1448#endif // wxUSE_GUI
1449