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