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