]> git.saurik.com Git - wxWidgets.git/blame - src/mac/utils.cpp
Use extraFontFlag to specify if anti-aliased fonts should be used.
[wxWidgets.git] / src / mac / 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
427ff662
SC
48#include "ATSUnicode.h"
49#include "TextCommon.h"
50#include "TextEncodingConverter.h"
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{
2d4e4f80
GD
459 BitMap screenBits;
460 GetQDGlobalsScreenBits( &screenBits );
7cfebe05 461
ec5d7799
RD
462 if (x) *x = 0;
463 if (y) *y = 0;
7cfebe05 464
5be55d56 465 if (width != NULL) {
e8ca7105
GD
466 *width = screenBits.bounds.right - screenBits.bounds.left ;
467 }
5be55d56 468 if (height != NULL) {
e8ca7105
GD
469 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
470 }
7cfebe05 471
2d4e4f80
GD
472 SInt16 mheight ;
473#if TARGET_CARBON
474 GetThemeMenuBarHeight( &mheight ) ;
475#else
7cfebe05 476 mheight = LMGetMBarHeight() ;
2d4e4f80 477#endif
5be55d56 478 if (height != NULL) {
e8ca7105
GD
479 *height -= mheight ;
480 }
481 if (y)
2d4e4f80 482 *y = mheight ;
ec5d7799
RD
483}
484
57591e0e
JS
485wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
486{
487 return wxGenericFindWindowAtPoint(pt);
488}
5dbb17e2 489
b6ed2b86
VZ
490#endif // wxUSE_GUI
491
492#if wxUSE_BASE
493
5dbb17e2
SC
494wxString wxGetOsDescription()
495{
6e73695c
GD
496#ifdef WXWIN_OS_DESCRIPTION
497 // use configure generated description if available
5f3f0f17 498 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
6e73695c 499#else
427ff662 500 return wxT("MacOS") ; //TODO:define further
6e73695c
GD
501#endif
502}
503
b6ed2b86
VZ
504#ifndef __DARWIN__
505wxChar *wxGetUserHome (const wxString& user)
506{
507 // TODO
508 return NULL;
509}
510
511bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
512{
513 if ( path.empty() )
514 return FALSE;
515
516 wxString p = path ;
71111c40 517 if (p[0u] == ':' ) {
b6ed2b86
VZ
518 p = wxGetCwd() + p ;
519 }
520
521 int pos = p.Find(':') ;
522 if ( pos != wxNOT_FOUND ) {
523 p = p.Mid(1,pos) ;
524 }
525
526 p = p + wxT(":") ;
527
528 Str255 volumeName ;
529 XVolumeParam pb ;
530
531 wxMacStringToPascal( p , volumeName ) ;
532 OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ;
533 if ( err == noErr ) {
534 if ( pTotal ) {
535 (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ;
536 }
537 if ( pFree ) {
538 (*pFree) = wxLongLong( pb.ioVFreeBytes ) ;
539 }
540 }
541
542 return err == noErr ;
543}
544#endif // !__DARWIN__
545
3d963f81
SC
546//---------------------------------------------------------------------------
547// wxMac Specific utility functions
548//---------------------------------------------------------------------------
549
5be55d56 550void wxMacStringToPascal( const wxString&from , StringPtr to )
427ff662 551{
939fba6c 552 wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
427ff662
SC
553 int len = strlen(buf) ;
554
555 if ( len > 255 )
556 len = 255 ;
557 to[0] = len ;
558 memcpy( (char*) &to[1] , buf , len ) ;
559}
560
5be55d56 561wxString wxMacMakeStringFromPascal( ConstStringPtr from )
427ff662 562{
939fba6c 563 return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
427ff662
SC
564}
565
e50d5284
RD
566
567wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
568{
569 TextEncodingBase enc = 0 ;
fe929141
SC
570 if ( encoding == wxFONTENCODING_DEFAULT )
571 {
572#if wxUSE_GUI
573 encoding = wxFont::GetDefaultEncoding() ;
574#else
575 encoding = wxLocale::GetSystemEncoding() ;
576#endif
577 }
e50d5284
RD
578
579 switch( encoding)
580 {
581 case wxFONTENCODING_ISO8859_1 :
582 enc = kTextEncodingISOLatin1 ;
583 break ;
584 case wxFONTENCODING_ISO8859_2 :
585 enc = kTextEncodingISOLatin2;
586 break ;
587 case wxFONTENCODING_ISO8859_3 :
588 enc = kTextEncodingISOLatin3 ;
589 break ;
590 case wxFONTENCODING_ISO8859_4 :
591 enc = kTextEncodingISOLatin4;
592 break ;
593 case wxFONTENCODING_ISO8859_5 :
594 enc = kTextEncodingISOLatinCyrillic;
595 break ;
596 case wxFONTENCODING_ISO8859_6 :
597 enc = kTextEncodingISOLatinArabic;
598 break ;
599 case wxFONTENCODING_ISO8859_7 :
600 enc = kTextEncodingISOLatinGreek;
601 break ;
602 case wxFONTENCODING_ISO8859_8 :
603 enc = kTextEncodingISOLatinHebrew;
604 break ;
605 case wxFONTENCODING_ISO8859_9 :
606 enc = kTextEncodingISOLatin5;
607 break ;
608 case wxFONTENCODING_ISO8859_10 :
609 enc = kTextEncodingISOLatin6;
610 break ;
611 case wxFONTENCODING_ISO8859_13 :
612 enc = kTextEncodingISOLatin7;
613 break ;
614 case wxFONTENCODING_ISO8859_14 :
615 enc = kTextEncodingISOLatin8;
616 break ;
617 case wxFONTENCODING_ISO8859_15 :
618 enc = kTextEncodingISOLatin9;
619 break ;
620
621 case wxFONTENCODING_KOI8 :
622 enc = kTextEncodingKOI8_R;
623 break ;
624 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
625 enc = kTextEncodingDOSRussian;
626 break ;
627/*
628 case wxFONTENCODING_BULGARIAN :
629 enc = ;
630 break ;
631*/
632 case wxFONTENCODING_CP437 :
633 enc =kTextEncodingDOSLatinUS ;
634 break ;
635 case wxFONTENCODING_CP850 :
636 enc = kTextEncodingDOSLatin1;
637 break ;
638 case wxFONTENCODING_CP852 :
639 enc = kTextEncodingDOSLatin2;
640 break ;
641 case wxFONTENCODING_CP855 :
642 enc = kTextEncodingDOSCyrillic;
643 break ;
644 case wxFONTENCODING_CP866 :
645 enc =kTextEncodingDOSRussian ;
646 break ;
647 case wxFONTENCODING_CP874 :
648 enc = kTextEncodingDOSThai;
649 break ;
650 case wxFONTENCODING_CP932 :
651 enc = kTextEncodingDOSJapanese;
652 break ;
653 case wxFONTENCODING_CP936 :
654 enc =kTextEncodingDOSChineseSimplif ;
655 break ;
656 case wxFONTENCODING_CP949 :
657 enc = kTextEncodingDOSKorean;
658 break ;
659 case wxFONTENCODING_CP950 :
660 enc = kTextEncodingDOSChineseTrad;
661 break ;
662
663 case wxFONTENCODING_CP1250 :
664 enc = kTextEncodingWindowsLatin2;
665 break ;
666 case wxFONTENCODING_CP1251 :
667 enc =kTextEncodingWindowsCyrillic ;
668 break ;
669 case wxFONTENCODING_CP1252 :
670 enc =kTextEncodingWindowsLatin1 ;
671 break ;
672 case wxFONTENCODING_CP1253 :
673 enc = kTextEncodingWindowsGreek;
674 break ;
675 case wxFONTENCODING_CP1254 :
676 enc = kTextEncodingWindowsLatin5;
677 break ;
678 case wxFONTENCODING_CP1255 :
679 enc =kTextEncodingWindowsHebrew ;
680 break ;
681 case wxFONTENCODING_CP1256 :
682 enc =kTextEncodingWindowsArabic ;
683 break ;
684 case wxFONTENCODING_CP1257 :
685 enc = kTextEncodingWindowsBalticRim;
686 break ;
687
688 case wxFONTENCODING_UTF7 :
689 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
690 break ;
691 case wxFONTENCODING_UTF8 :
692 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
693 break ;
694 case wxFONTENCODING_EUC_JP :
695 enc = kTextEncodingEUC_JP;
696 break ;
697 case wxFONTENCODING_UTF16BE :
698 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
699 break ;
700 case wxFONTENCODING_UTF16LE :
701 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
702 break ;
703 case wxFONTENCODING_UTF32BE :
704 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
705 break ;
706 case wxFONTENCODING_UTF32LE :
707 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
708 break ;
709
710 case wxFONTENCODING_MACROMAN :
711 enc = kTextEncodingMacRoman ;
712 break ;
713 case wxFONTENCODING_MACJAPANESE :
714 enc = kTextEncodingMacJapanese ;
715 break ;
716 case wxFONTENCODING_MACCHINESETRAD :
717 enc = kTextEncodingMacChineseTrad ;
718 break ;
719 case wxFONTENCODING_MACKOREAN :
720 enc = kTextEncodingMacKorean ;
721 break ;
722 case wxFONTENCODING_MACARABIC :
723 enc = kTextEncodingMacArabic ;
724 break ;
725 case wxFONTENCODING_MACHEBREW :
726 enc = kTextEncodingMacHebrew ;
727 break ;
728 case wxFONTENCODING_MACGREEK :
729 enc = kTextEncodingMacGreek ;
730 break ;
731 case wxFONTENCODING_MACCYRILLIC :
732 enc = kTextEncodingMacCyrillic ;
733 break ;
734 case wxFONTENCODING_MACDEVANAGARI :
735 enc = kTextEncodingMacDevanagari ;
736 break ;
737 case wxFONTENCODING_MACGURMUKHI :
738 enc = kTextEncodingMacGurmukhi ;
739 break ;
740 case wxFONTENCODING_MACGUJARATI :
741 enc = kTextEncodingMacGujarati ;
742 break ;
743 case wxFONTENCODING_MACORIYA :
744 enc = kTextEncodingMacOriya ;
745 break ;
746 case wxFONTENCODING_MACBENGALI :
747 enc = kTextEncodingMacBengali ;
748 break ;
749 case wxFONTENCODING_MACTAMIL :
750 enc = kTextEncodingMacTamil ;
751 break ;
752 case wxFONTENCODING_MACTELUGU :
753 enc = kTextEncodingMacTelugu ;
754 break ;
755 case wxFONTENCODING_MACKANNADA :
756 enc = kTextEncodingMacKannada ;
757 break ;
758 case wxFONTENCODING_MACMALAJALAM :
759 enc = kTextEncodingMacMalayalam ;
760 break ;
761 case wxFONTENCODING_MACSINHALESE :
762 enc = kTextEncodingMacSinhalese ;
763 break ;
764 case wxFONTENCODING_MACBURMESE :
765 enc = kTextEncodingMacBurmese ;
766 break ;
767 case wxFONTENCODING_MACKHMER :
768 enc = kTextEncodingMacKhmer ;
769 break ;
770 case wxFONTENCODING_MACTHAI :
771 enc = kTextEncodingMacThai ;
772 break ;
773 case wxFONTENCODING_MACLAOTIAN :
774 enc = kTextEncodingMacLaotian ;
775 break ;
776 case wxFONTENCODING_MACGEORGIAN :
777 enc = kTextEncodingMacGeorgian ;
778 break ;
779 case wxFONTENCODING_MACARMENIAN :
780 enc = kTextEncodingMacArmenian ;
781 break ;
782 case wxFONTENCODING_MACCHINESESIMP :
783 enc = kTextEncodingMacChineseSimp ;
784 break ;
785 case wxFONTENCODING_MACTIBETAN :
786 enc = kTextEncodingMacTibetan ;
787 break ;
788 case wxFONTENCODING_MACMONGOLIAN :
789 enc = kTextEncodingMacMongolian ;
790 break ;
791 case wxFONTENCODING_MACETHIOPIC :
792 enc = kTextEncodingMacEthiopic ;
793 break ;
794 case wxFONTENCODING_MACCENTRALEUR :
795 enc = kTextEncodingMacCentralEurRoman ;
796 break ;
797 case wxFONTENCODING_MACVIATNAMESE :
798 enc = kTextEncodingMacVietnamese ;
799 break ;
800 case wxFONTENCODING_MACARABICEXT :
801 enc = kTextEncodingMacExtArabic ;
802 break ;
803 case wxFONTENCODING_MACSYMBOL :
804 enc = kTextEncodingMacSymbol ;
805 break ;
806 case wxFONTENCODING_MACDINGBATS :
807 enc = kTextEncodingMacDingbats ;
808 break ;
809 case wxFONTENCODING_MACTURKISH :
810 enc = kTextEncodingMacTurkish ;
811 break ;
812 case wxFONTENCODING_MACCROATIAN :
813 enc = kTextEncodingMacCroatian ;
814 break ;
815 case wxFONTENCODING_MACICELANDIC :
816 enc = kTextEncodingMacIcelandic ;
817 break ;
818 case wxFONTENCODING_MACROMANIAN :
819 enc = kTextEncodingMacRomanian ;
820 break ;
821 case wxFONTENCODING_MACCELTIC :
822 enc = kTextEncodingMacCeltic ;
823 break ;
824 case wxFONTENCODING_MACGAELIC :
825 enc = kTextEncodingMacGaelic ;
826 break ;
827 case wxFONTENCODING_MACKEYBOARD :
828 enc = kTextEncodingMacKeyboardGlyphs ;
79a73b4f
SC
829 break ;
830 default :
831 // to make gcc happy
832 break ;
e50d5284
RD
833 } ;
834 return enc ;
835}
836
837wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
838{
839 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
840
841 switch( encoding)
842 {
843 case kTextEncodingISOLatin1 :
844 enc = wxFONTENCODING_ISO8859_1 ;
845 break ;
846 case kTextEncodingISOLatin2 :
847 enc = wxFONTENCODING_ISO8859_2;
848 break ;
849 case kTextEncodingISOLatin3 :
850 enc = wxFONTENCODING_ISO8859_3 ;
851 break ;
852 case kTextEncodingISOLatin4 :
853 enc = wxFONTENCODING_ISO8859_4;
854 break ;
855 case kTextEncodingISOLatinCyrillic :
856 enc = wxFONTENCODING_ISO8859_5;
857 break ;
858 case kTextEncodingISOLatinArabic :
859 enc = wxFONTENCODING_ISO8859_6;
860 break ;
861 case kTextEncodingISOLatinGreek :
862 enc = wxFONTENCODING_ISO8859_7;
863 break ;
864 case kTextEncodingISOLatinHebrew :
865 enc = wxFONTENCODING_ISO8859_8;
866 break ;
867 case kTextEncodingISOLatin5 :
868 enc = wxFONTENCODING_ISO8859_9;
869 break ;
870 case kTextEncodingISOLatin6 :
871 enc = wxFONTENCODING_ISO8859_10;
872 break ;
873 case kTextEncodingISOLatin7 :
874 enc = wxFONTENCODING_ISO8859_13;
875 break ;
876 case kTextEncodingISOLatin8 :
877 enc = wxFONTENCODING_ISO8859_14;
878 break ;
879 case kTextEncodingISOLatin9 :
880 enc =wxFONTENCODING_ISO8859_15 ;
881 break ;
882
883 case kTextEncodingKOI8_R :
884 enc = wxFONTENCODING_KOI8;
885 break ;
886/*
887 case :
888 enc = wxFONTENCODING_BULGARIAN;
889 break ;
890*/
fe929141 891 case kTextEncodingDOSLatinUS :
e50d5284
RD
892 enc = wxFONTENCODING_CP437;
893 break ;
894 case kTextEncodingDOSLatin1 :
895 enc = wxFONTENCODING_CP850;
896 break ;
897 case kTextEncodingDOSLatin2 :
898 enc =wxFONTENCODING_CP852 ;
899 break ;
900 case kTextEncodingDOSCyrillic :
901 enc = wxFONTENCODING_CP855;
902 break ;
903 case kTextEncodingDOSRussian :
904 enc = wxFONTENCODING_CP866;
905 break ;
906 case kTextEncodingDOSThai :
907 enc =wxFONTENCODING_CP874 ;
908 break ;
909 case kTextEncodingDOSJapanese :
910 enc = wxFONTENCODING_CP932;
911 break ;
912 case kTextEncodingDOSChineseSimplif :
913 enc = wxFONTENCODING_CP936;
914 break ;
915 case kTextEncodingDOSKorean :
916 enc = wxFONTENCODING_CP949;
917 break ;
918 case kTextEncodingDOSChineseTrad :
919 enc = wxFONTENCODING_CP950;
920 break ;
921
922 case kTextEncodingWindowsLatin2 :
923 enc = wxFONTENCODING_CP1250;
924 break ;
925 case kTextEncodingWindowsCyrillic :
926 enc = wxFONTENCODING_CP1251;
927 break ;
928 case kTextEncodingWindowsLatin1 :
929 enc = wxFONTENCODING_CP1252;
930 break ;
931 case kTextEncodingWindowsGreek :
932 enc = wxFONTENCODING_CP1253;
933 break ;
934 case kTextEncodingWindowsLatin5 :
935 enc = wxFONTENCODING_CP1254;
936 break ;
937 case kTextEncodingWindowsHebrew :
938 enc = wxFONTENCODING_CP1255;
939 break ;
940 case kTextEncodingWindowsArabic :
941 enc = wxFONTENCODING_CP1256;
942 break ;
943 case kTextEncodingWindowsBalticRim :
944 enc =wxFONTENCODING_CP1257 ;
945 break ;
946 case kTextEncodingEUC_JP :
947 enc = wxFONTENCODING_EUC_JP;
948 break ;
949 /*
950 case wxFONTENCODING_UTF7 :
951 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
952 break ;
953 case wxFONTENCODING_UTF8 :
954 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
955 break ;
956 case wxFONTENCODING_UTF16BE :
957 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
958 break ;
959 case wxFONTENCODING_UTF16LE :
960 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
961 break ;
962 case wxFONTENCODING_UTF32BE :
963 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
964 break ;
965 case wxFONTENCODING_UTF32LE :
966 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
967 break ;
968 */
969 case kTextEncodingMacRoman :
970 enc = wxFONTENCODING_MACROMAN ;
971 break ;
972 case kTextEncodingMacJapanese :
973 enc = wxFONTENCODING_MACJAPANESE ;
974 break ;
975 case kTextEncodingMacChineseTrad :
976 enc = wxFONTENCODING_MACCHINESETRAD ;
977 break ;
978 case kTextEncodingMacKorean :
979 enc = wxFONTENCODING_MACKOREAN ;
980 break ;
981 case kTextEncodingMacArabic :
982 enc =wxFONTENCODING_MACARABIC ;
983 break ;
984 case kTextEncodingMacHebrew :
985 enc = wxFONTENCODING_MACHEBREW ;
986 break ;
987 case kTextEncodingMacGreek :
988 enc = wxFONTENCODING_MACGREEK ;
989 break ;
990 case kTextEncodingMacCyrillic :
991 enc = wxFONTENCODING_MACCYRILLIC ;
992 break ;
993 case kTextEncodingMacDevanagari :
994 enc = wxFONTENCODING_MACDEVANAGARI ;
995 break ;
996 case kTextEncodingMacGurmukhi :
997 enc = wxFONTENCODING_MACGURMUKHI ;
998 break ;
999 case kTextEncodingMacGujarati :
1000 enc = wxFONTENCODING_MACGUJARATI ;
1001 break ;
1002 case kTextEncodingMacOriya :
1003 enc =wxFONTENCODING_MACORIYA ;
1004 break ;
1005 case kTextEncodingMacBengali :
1006 enc =wxFONTENCODING_MACBENGALI ;
1007 break ;
1008 case kTextEncodingMacTamil :
1009 enc = wxFONTENCODING_MACTAMIL ;
1010 break ;
1011 case kTextEncodingMacTelugu :
1012 enc = wxFONTENCODING_MACTELUGU ;
1013 break ;
1014 case kTextEncodingMacKannada :
1015 enc = wxFONTENCODING_MACKANNADA ;
1016 break ;
1017 case kTextEncodingMacMalayalam :
1018 enc = wxFONTENCODING_MACMALAJALAM ;
1019 break ;
1020 case kTextEncodingMacSinhalese :
1021 enc = wxFONTENCODING_MACSINHALESE ;
1022 break ;
1023 case kTextEncodingMacBurmese :
1024 enc = wxFONTENCODING_MACBURMESE ;
1025 break ;
1026 case kTextEncodingMacKhmer :
1027 enc = wxFONTENCODING_MACKHMER ;
1028 break ;
1029 case kTextEncodingMacThai :
1030 enc = wxFONTENCODING_MACTHAI ;
1031 break ;
1032 case kTextEncodingMacLaotian :
1033 enc = wxFONTENCODING_MACLAOTIAN ;
1034 break ;
1035 case kTextEncodingMacGeorgian :
1036 enc = wxFONTENCODING_MACGEORGIAN ;
1037 break ;
1038 case kTextEncodingMacArmenian :
1039 enc = wxFONTENCODING_MACARMENIAN ;
1040 break ;
1041 case kTextEncodingMacChineseSimp :
1042 enc = wxFONTENCODING_MACCHINESESIMP ;
1043 break ;
1044 case kTextEncodingMacTibetan :
1045 enc = wxFONTENCODING_MACTIBETAN ;
1046 break ;
1047 case kTextEncodingMacMongolian :
1048 enc = wxFONTENCODING_MACMONGOLIAN ;
1049 break ;
1050 case kTextEncodingMacEthiopic :
1051 enc = wxFONTENCODING_MACETHIOPIC ;
1052 break ;
1053 case kTextEncodingMacCentralEurRoman:
1054 enc = wxFONTENCODING_MACCENTRALEUR ;
1055 break ;
1056 case kTextEncodingMacVietnamese:
1057 enc = wxFONTENCODING_MACVIATNAMESE ;
1058 break ;
1059 case kTextEncodingMacExtArabic :
1060 enc = wxFONTENCODING_MACARABICEXT ;
1061 break ;
1062 case kTextEncodingMacSymbol :
1063 enc = wxFONTENCODING_MACSYMBOL ;
1064 break ;
1065 case kTextEncodingMacDingbats :
1066 enc = wxFONTENCODING_MACDINGBATS ;
1067 break ;
1068 case kTextEncodingMacTurkish :
1069 enc = wxFONTENCODING_MACTURKISH ;
1070 break ;
1071 case kTextEncodingMacCroatian :
1072 enc = wxFONTENCODING_MACCROATIAN ;
1073 break ;
1074 case kTextEncodingMacIcelandic :
1075 enc = wxFONTENCODING_MACICELANDIC ;
1076 break ;
1077 case kTextEncodingMacRomanian :
1078 enc = wxFONTENCODING_MACROMANIAN ;
1079 break ;
1080 case kTextEncodingMacCeltic :
1081 enc = wxFONTENCODING_MACCELTIC ;
1082 break ;
1083 case kTextEncodingMacGaelic :
1084 enc = wxFONTENCODING_MACGAELIC ;
1085 break ;
1086 case kTextEncodingMacKeyboardGlyphs :
1087 enc = wxFONTENCODING_MACKEYBOARD ;
1088 break ;
1089 } ;
1090 return enc ;
1091}
1092
2dbc444a
RD
1093#endif // wxUSE_BASE
1094
1095#if wxUSE_GUI
1096
1097
5be55d56 1098//
427ff662
SC
1099// CFStringRefs (Carbon only)
1100//
1101
1102#if TARGET_CARBON
71111c40 1103
427ff662 1104// converts this string into a carbon foundation string with optional pc 2 mac encoding
fe929141 1105void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
427ff662 1106{
fe929141 1107 Release() ;
79a73b4f 1108
71111c40 1109 wxString str = st ;
8aa701ed 1110 wxMacConvertNewlines13To10( &str ) ;
427ff662 1111#if wxUSE_UNICODE
71111c40 1112#if SIZEOF_WCHAR_T == 2
5be55d56 1113 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
79a73b4f 1114 (UniChar*)str.wc_str() , str.Len() );
427ff662 1115#else
79a73b4f
SC
1116 wxMBConvUTF16BE converter ;
1117 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1118 UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
1119 converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
1120 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
1121 unibuf , unicharlen / sizeof(UniChar) ) ;
1122 delete[] unibuf ;
71111c40 1123#endif
71111c40 1124#else // not wxUSE_UNICODE
427ff662 1125 m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
fe929141 1126 wxMacGetSystemEncFromFontEnc( encoding ) ) ;
427ff662
SC
1127#endif
1128 m_release = true ;
1129}
1130
fe929141 1131wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
427ff662 1132{
79a73b4f
SC
1133 Size cflen = CFStringGetLength( m_cfs ) ;
1134 size_t noChars ;
1135 wxChar* buf = NULL ;
1136
427ff662 1137#if wxUSE_UNICODE
fe929141 1138#if SIZEOF_WCHAR_T == 2
79a73b4f
SC
1139 buf = new wxChar[ cflen + 1 ] ;
1140 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
1141 noChars = cflen ;
fe929141 1142#else
79a73b4f
SC
1143 UniChar* unibuf = new UniChar[ cflen + 1 ] ;
1144 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
1145 unibuf[cflen] = 0 ;
590e21b0 1146 wxMBConvUTF16BE converter ;
79a73b4f
SC
1147 noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
1148 buf = new wxChar[ noChars + 1 ] ;
1149 converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
1150 delete[] unibuf ;
1151#endif
427ff662 1152#else
79a73b4f
SC
1153 CFIndex cStrLen ;
1154 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
ac86379e 1155 '?' , false , NULL , 0 , &cStrLen ) ;
79a73b4f 1156 buf = new wxChar[ cStrLen + 1 ] ;
ac86379e
SC
1157 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1158 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
79a73b4f 1159 noChars = cStrLen ;
427ff662 1160#endif
79a73b4f
SC
1161
1162 buf[noChars] = 0 ;
8aa701ed 1163 wxMacConvertNewlines10To13( buf ) ;
79a73b4f
SC
1164 wxString result(buf) ;
1165 delete[] buf ;
427ff662
SC
1166 return result ;
1167}
1168
3d963f81
SC
1169#endif //TARGET_CARBON
1170
8aa701ed
SC
1171void wxMacConvertNewlines13To10( char * data )
1172{
1173 char * buf = data ;
1174 while( (buf=strchr(buf,0x0d)) != NULL )
1175 {
1176 *buf = 0x0a ;
1177 buf++ ;
1178 }
1179}
1180
1181void wxMacConvertNewlines10To13( char * data )
1182{
1183 char * buf = data ;
1184 while( (buf=strchr(buf,0x0a)) != NULL )
1185 {
1186 *buf = 0x0d ;
1187 buf++ ;
1188 }
1189}
1190
1191void wxMacConvertNewlines13To10( wxString * data )
1192{
be6628ce
SC
1193 size_t len = data->Length() ;
1194
1195 if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
8aa701ed
SC
1196 return ;
1197
be6628ce
SC
1198 wxString temp(*data) ;
1199 wxStringBuffer buf(*data,len ) ;
1200 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1201
1202 wxMacConvertNewlines13To10( buf ) ;
8aa701ed
SC
1203}
1204
1205void wxMacConvertNewlines10To13( wxString * data )
1206{
be6628ce
SC
1207 size_t len = data->Length() ;
1208
1209 if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL)
8aa701ed 1210 return ;
be6628ce
SC
1211
1212 wxString temp(*data) ;
1213 wxStringBuffer buf(*data,len ) ;
1214 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1215 wxMacConvertNewlines10To13( buf ) ;
8aa701ed
SC
1216}
1217
1218
1219#if wxUSE_UNICODE
1220void wxMacConvertNewlines13To10( wxChar * data )
1221{
1222 wxChar * buf = data ;
1223 while( (buf=wxStrchr(buf,0x0d)) != NULL )
1224 {
1225 *buf = 0x0a ;
1226 buf++ ;
1227 }
1228}
1229
1230void wxMacConvertNewlines10To13( wxChar * data )
1231{
1232 wxChar * buf = data ;
1233 while( (buf=wxStrchr(buf,0x0a)) != NULL )
1234 {
1235 *buf = 0x0d ;
1236 buf++ ;
1237 }
1238}
1239#endif
1240
a434b43f
VZ
1241// ----------------------------------------------------------------------------
1242// debugging support
1243// ----------------------------------------------------------------------------
1244
1245#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1246
1247// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1248
1249#ifndef __MetroNubUtils__
1250#include "MetroNubUtils.h"
1251#endif
1252
1253#ifndef __GESTALT__
1254#include <Gestalt.h>
1255#endif
1256
1257#if TARGET_API_MAC_CARBON
1258
1259 #include <CodeFragments.h>
1260
536732e4 1261 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
a434b43f
VZ
1262
1263 ProcPtr gCallUniversalProc_Proc = NULL;
1264
1265#endif
1266
1267static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
1268
1269static long fRunOnce = false;
1270
1271/* ---------------------------------------------------------------------------
1272 IsMetroNubInstalled
1273 --------------------------------------------------------------------------- */
1274
1275Boolean IsMetroNubInstalled()
1276{
1277 if (!fRunOnce)
1278 {
1279 long result, value;
1280
1281 fRunOnce = true;
1282 gMetroNubEntry = NULL;
1283
1284 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
1285 {
1286 /* look for MetroNub's Gestalt selector */
1287 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
1288 {
1289
1290 #if TARGET_API_MAC_CARBON
1291 if (gCallUniversalProc_Proc == NULL)
1292 {
1293 CFragConnectionID connectionID;
1294 Ptr mainAddress;
1295 Str255 errorString;
1296 ProcPtr symbolAddress;
1297 OSErr err;
1298 CFragSymbolClass symbolClass;
1299
1300 symbolAddress = NULL;
1301 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
1302 &connectionID, &mainAddress, errorString);
1303
1304 if (err != noErr)
1305 {
1306 gCallUniversalProc_Proc = NULL;
1307 goto end;
1308 }
1309
1310 err = FindSymbol(connectionID, "\pCallUniversalProc",
1311 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
1312
1313 if (err != noErr)
1314 {
1315 gCallUniversalProc_Proc = NULL;
1316 goto end;
1317 }
1318 }
1319 #endif
1320
1321 {
1322 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
1323
1324 /* make sure the version of the API is compatible */
1325 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
1326 kMetroNubUserAPIVersion <= block->apiHiVersion)
1327 gMetroNubEntry = block; /* success! */
1328 }
1329
1330 }
1331 }
1332 }
1333
1334end:
1335
1336#if TARGET_API_MAC_CARBON
1337 return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
1338#else
1339 return (gMetroNubEntry != NULL);
1340#endif
1341}
1342
1343/* ---------------------------------------------------------------------------
1344 IsMWDebuggerRunning [v1 API]
1345 --------------------------------------------------------------------------- */
1346
1347Boolean IsMWDebuggerRunning()
1348{
1349 if (IsMetroNubInstalled())
1350 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
1351 else
1352 return false;
1353}
1354
1355/* ---------------------------------------------------------------------------
1356 AmIBeingMWDebugged [v1 API]
1357 --------------------------------------------------------------------------- */
1358
1359Boolean AmIBeingMWDebugged()
1360{
1361 if (IsMetroNubInstalled())
1362 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
1363 else
1364 return false;
1365}
1366
1367extern bool WXDLLEXPORT wxIsDebuggerRunning()
1368{
1369 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1370}
1371
1372#else
1373
1374extern bool WXDLLEXPORT wxIsDebuggerRunning()
1375{
1376 return false;
1377}
1378
1379#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
1380
b6ed2b86
VZ
1381#endif // wxUSE_GUI
1382