]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/utils.cpp
corrected GetPosition and extended erasing to include the entire update rgn passed
[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
29d91661
SC
48#if TARGET_API_MAC_OSX
49#include <CoreServices/CoreServices.h>
50#else
51#include <DriverServices.h>
52#include <Multiprocessing.h>
53#endif
54
7f0c3a63
SC
55#include <ATSUnicode.h>
56#include <TextCommon.h>
57#include <TextEncodingConverter.h>
427ff662 58
8aa701ed 59#include "wx/mac/private.h" // includes mac headers
a434b43f
VZ
60
61#if defined(__MWERKS__) && wxUSE_UNICODE
62 #include <wtime.h>
63#endif
64
659b3e8b
VZ
65// ---------------------------------------------------------------------------
66// code used in both base and GUI compilation
67// ---------------------------------------------------------------------------
68
69// our OS version is the same in non GUI and GUI cases
70static int DoGetOSVersion(int *majorVsn, int *minorVsn)
71{
72 long theSystem ;
73
74 // are there x-platform conventions ?
75
76 Gestalt(gestaltSystemVersion, &theSystem) ;
77 if (minorVsn != NULL) {
78 *minorVsn = (theSystem & 0xFF ) ;
79 }
80 if (majorVsn != NULL) {
81 *majorVsn = (theSystem >> 8 ) ;
82 }
83#ifdef __DARWIN__
84 return wxMAC_DARWIN;
85#else
86 return wxMAC;
87#endif
88}
89
ee8bf34f
RD
90
91#if wxUSE_BASE
92
e5a9c663
SC
93// ----------------------------------------------------------------------------
94// debugging support
95// ----------------------------------------------------------------------------
96
97#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
98
99// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
100
101#ifndef __MetroNubUtils__
102#include "MetroNubUtils.h"
103#endif
104
105#ifndef __GESTALT__
106#include <Gestalt.h>
107#endif
108
109#if TARGET_API_MAC_CARBON
110
111 #include <CodeFragments.h>
112
113 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
114
115 ProcPtr gCallUniversalProc_Proc = NULL;
116
117#endif
118
119static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
120
121static long fRunOnce = false;
122
123/* ---------------------------------------------------------------------------
124 IsMetroNubInstalled
125 --------------------------------------------------------------------------- */
126
127Boolean IsMetroNubInstalled()
128{
129 if (!fRunOnce)
130 {
131 long result, value;
132
133 fRunOnce = true;
134 gMetroNubEntry = NULL;
135
136 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
137 {
138 /* look for MetroNub's Gestalt selector */
139 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
140 {
141
142 #if TARGET_API_MAC_CARBON
143 if (gCallUniversalProc_Proc == NULL)
144 {
145 CFragConnectionID connectionID;
146 Ptr mainAddress;
147 Str255 errorString;
148 ProcPtr symbolAddress;
149 OSErr err;
150 CFragSymbolClass symbolClass;
151
152 symbolAddress = NULL;
153 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
154 &connectionID, &mainAddress, errorString);
155
156 if (err != noErr)
157 {
158 gCallUniversalProc_Proc = NULL;
159 goto end;
160 }
161
162 err = FindSymbol(connectionID, "\pCallUniversalProc",
163 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
164
165 if (err != noErr)
166 {
167 gCallUniversalProc_Proc = NULL;
168 goto end;
169 }
170 }
171 #endif
172
173 {
174 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
175
176 /* make sure the version of the API is compatible */
177 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
178 kMetroNubUserAPIVersion <= block->apiHiVersion)
179 gMetroNubEntry = block; /* success! */
180 }
181
182 }
183 }
184 }
185
186end:
187
188#if TARGET_API_MAC_CARBON
189 return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
190#else
191 return (gMetroNubEntry != NULL);
192#endif
193}
194
195/* ---------------------------------------------------------------------------
196 IsMWDebuggerRunning [v1 API]
197 --------------------------------------------------------------------------- */
198
199Boolean IsMWDebuggerRunning()
200{
201 if (IsMetroNubInstalled())
202 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
203 else
204 return false;
205}
206
207/* ---------------------------------------------------------------------------
208 AmIBeingMWDebugged [v1 API]
209 --------------------------------------------------------------------------- */
210
211Boolean AmIBeingMWDebugged()
212{
213 if (IsMetroNubInstalled())
214 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
215 else
216 return false;
217}
218
219extern bool WXDLLEXPORT wxIsDebuggerRunning()
220{
221 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
222}
223
224#else
225
226extern bool WXDLLEXPORT wxIsDebuggerRunning()
227{
228 return false;
229}
230
231#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
232
a434b43f 233
f5c6eb5c 234#ifndef __DARWIN__
03e11df5
GD
235// defined in unix/utilsunx.cpp for Mac OS X
236
2f1ae414
SC
237// get full hostname (with domain name if possible)
238bool wxGetFullHostName(wxChar *buf, int maxSize)
239{
240 return wxGetHostName(buf, maxSize);
241}
242
243// Get hostname only (without domain name)
427ff662 244bool wxGetHostName(wxChar *buf, int maxSize)
e9576ca5 245{
e40298d5
JS
246 // Gets Chooser name of user by examining a System resource.
247
248 const short kComputerNameID = -16413;
5be55d56 249
e40298d5
JS
250 short oldResFile = CurResFile() ;
251 UseResFile(0);
252 StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);
253 UseResFile(oldResFile);
254
255 if (chooserName && *chooserName)
256 {
427ff662
SC
257 HLock( (Handle) chooserName ) ;
258 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
259 HUnlock( (Handle) chooserName ) ;
260 ReleaseResource( (Handle) chooserName ) ;
261 wxStrncpy( buf , name , maxSize - 1 ) ;
e40298d5
JS
262 }
263 else
264 buf[0] = 0 ;
0a67a93b
SC
265
266 return TRUE;
e9576ca5
SC
267}
268
269// Get user ID e.g. jacs
427ff662 270bool wxGetUserId(wxChar *buf, int maxSize)
e9576ca5 271{
0a67a93b 272 return wxGetUserName( buf , maxSize ) ;
e9576ca5
SC
273}
274
5b781a67
SC
275const wxChar* wxGetHomeDir(wxString *pstr)
276{
e40298d5
JS
277 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
278 return pstr->c_str() ;
5b781a67
SC
279}
280
a31a5f85 281// Get user name e.g. Stefan Csomor
427ff662 282bool wxGetUserName(wxChar *buf, int maxSize)
e9576ca5 283{
e40298d5
JS
284 // Gets Chooser name of user by examining a System resource.
285
286 const short kChooserNameID = -16096;
5be55d56 287
e40298d5
JS
288 short oldResFile = CurResFile() ;
289 UseResFile(0);
290 StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);
291 UseResFile(oldResFile);
292
293 if (chooserName && *chooserName)
294 {
427ff662
SC
295 HLock( (Handle) chooserName ) ;
296 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
297 HUnlock( (Handle) chooserName ) ;
298 ReleaseResource( (Handle) chooserName ) ;
299 wxStrncpy( buf , name , maxSize - 1 ) ;
e40298d5
JS
300 }
301 else
302 buf[0] = 0 ;
0a67a93b
SC
303
304 return TRUE;
e9576ca5
SC
305}
306
5dbb17e2 307int wxKill(long pid, wxSignal sig , wxKillError *rc )
e9576ca5
SC
308{
309 // TODO
310 return 0;
311}
312
5dbb17e2
SC
313WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
314{
e40298d5
JS
315 // TODO : under classic there is no environement support, under X yes
316 return false ;
5dbb17e2
SC
317}
318
319// set the env var name to the given value, return TRUE on success
320WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
321{
e40298d5
JS
322 // TODO : under classic there is no environement support, under X yes
323 return false ;
5dbb17e2
SC
324}
325
e9576ca5
SC
326//
327// Execute a program in an Interactive Shell
328//
329bool wxShell(const wxString& command)
330{
331 // TODO
332 return FALSE;
333}
334
5be55d56 335// Shutdown or reboot the PC
f6ba47d9
VZ
336bool wxShutdown(wxShutdownFlags wFlags)
337{
338 // TODO
339 return FALSE;
340}
341
e9576ca5
SC
342// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
343long wxGetFreeMemory()
344{
0a67a93b
SC
345 return FreeMem() ;
346}
347
7f7b52b4
SC
348#ifndef __DARWIN__
349
350void wxMicroSleep(unsigned long microseconds)
0a67a93b 351{
7f7b52b4
SC
352 AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
353 MPDelayUntil( & wakeup);
354}
355
356void wxMilliSleep(unsigned long milliseconds)
357{
358 AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
359 MPDelayUntil( & wakeup);
e9576ca5
SC
360}
361
362void wxSleep(int nSecs)
363{
7f7b52b4 364 wxMilliSleep(1000*nSecs);
e9576ca5
SC
365}
366
7f7b52b4
SC
367#endif
368
e9576ca5
SC
369// Consume all events until no more left
370void wxFlushEvents()
371{
372}
373
f5c6eb5c 374#endif // !__DARWIN__
e9576ca5
SC
375
376// Emit a beeeeeep
377void wxBell()
378{
0a67a93b 379 SysBeep(30);
e9576ca5
SC
380}
381
324899f6 382wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
29c99ad3 383{
a8eaaeb2 384 static wxToolkitInfo info;
66b6b57c 385 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
a8eaaeb2 386 info.name = _T("wxBase");
324899f6 387 return info;
29c99ad3
VZ
388}
389
b6ed2b86
VZ
390#endif // wxUSE_BASE
391
392#if wxUSE_GUI
536732e4 393
324899f6 394wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
29c99ad3 395{
a8eaaeb2 396 static wxToolkitInfo info;
66b6b57c 397 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
a8eaaeb2
VS
398 info.shortName = _T("mac");
399 info.name = _T("wxMac");
400#ifdef __WXUNIVERSAL__
401 info.shortName << _T("univ");
402 info.name << _T("/wxUniversal");
403#endif
324899f6 404 return info;
29c99ad3
VZ
405}
406
e9576ca5
SC
407// Reading and writing resources (eg WIN.INI, .Xdefaults)
408#if wxUSE_RESOURCES
409bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
410{
411 // TODO
412 return FALSE;
413}
414
415bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
416{
427ff662
SC
417 wxString buf;
418 buf.Printf(wxT("%.4f"), value);
419
e40298d5 420 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
421}
422
423bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
424{
427ff662
SC
425 wxString buf;
426 buf.Printf(wxT("%ld"), value);
427
e40298d5 428 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
429}
430
431bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
432{
427ff662
SC
433 wxString buf;
434 buf.Printf(wxT("%d"), value);
435
e40298d5 436 return wxWriteResource(section, entry, buf, file);
e9576ca5
SC
437}
438
439bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
440{
441 // TODO
442 return FALSE;
443}
444
445bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
446{
e40298d5
JS
447 char *s = NULL;
448 bool succ = wxGetResource(section, entry, (char **)&s, file);
449 if (succ)
450 {
451 *value = (float)strtod(s, NULL);
452 delete[] s;
453 return TRUE;
454 }
455 else return FALSE;
e9576ca5
SC
456}
457
458bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
459{
e40298d5
JS
460 char *s = NULL;
461 bool succ = wxGetResource(section, entry, (char **)&s, file);
462 if (succ)
463 {
464 *value = strtol(s, NULL, 10);
465 delete[] s;
466 return TRUE;
467 }
468 else return FALSE;
e9576ca5
SC
469}
470
471bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
472{
e40298d5
JS
473 char *s = NULL;
474 bool succ = wxGetResource(section, entry, (char **)&s, file);
475 if (succ)
476 {
477 *value = (int)strtol(s, NULL, 10);
478 delete[] s;
479 return TRUE;
480 }
481 else return FALSE;
e9576ca5
SC
482}
483#endif // wxUSE_RESOURCES
484
6b57b49a 485int gs_wxBusyCursorCount = 0;
e40298d5
JS
486extern wxCursor gMacCurrentCursor ;
487wxCursor gMacStoredActiveCursor ;
e9576ca5
SC
488
489// Set the cursor to the busy cursor for all windows
490void wxBeginBusyCursor(wxCursor *cursor)
491{
e40298d5
JS
492 if (gs_wxBusyCursorCount++ == 0)
493 {
494 gMacStoredActiveCursor = gMacCurrentCursor ;
495 cursor->MacInstall() ;
496 }
497 //else: nothing to do, already set
e9576ca5
SC
498}
499
500// Restore cursor to normal
501void wxEndBusyCursor()
502{
6b57b49a 503 wxCHECK_RET( gs_wxBusyCursorCount > 0,
e40298d5 504 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
5be55d56 505
e40298d5
JS
506 if (--gs_wxBusyCursorCount == 0)
507 {
508 gMacStoredActiveCursor.MacInstall() ;
509 gMacStoredActiveCursor = wxNullCursor ;
510 }
e9576ca5
SC
511}
512
513// TRUE if we're between the above two calls
514bool wxIsBusy()
515{
e40298d5 516 return (gs_wxBusyCursorCount > 0);
ec5d7799 517}
e9576ca5 518
2dbc444a
RD
519#endif // wxUSE_GUI
520
521#if wxUSE_BASE
522
e7e1b01e 523wxString wxMacFindFolder( short vol,
e40298d5
JS
524 OSType folderType,
525 Boolean createFolder)
2f1ae414 526{
2d4e4f80
GD
527 short vRefNum ;
528 long dirID ;
529 wxString strDir ;
5be55d56 530
2d4e4f80
GD
531 if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
532 {
533 FSSpec file ;
534 if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
535 {
536 strDir = wxMacFSSpec2MacFilename( &file ) + wxFILE_SEP_PATH ;
537 }
538 }
539 return strDir ;
2f1ae414
SC
540}
541
2dbc444a
RD
542#endif // wxUSE_BASE
543
544#if wxUSE_GUI
545
e9576ca5
SC
546// Check whether this window wants to process messages, e.g. Stop button
547// in long calculations.
548bool wxCheckForInterrupt(wxWindow *wnd)
549{
550 // TODO
551 return FALSE;
552}
553
554void wxGetMousePosition( int* x, int* y )
555{
519cb848 556 Point pt ;
ec5d7799 557
519cb848
SC
558 GetMouse( &pt ) ;
559 LocalToGlobal( &pt ) ;
560 *x = pt.h ;
561 *y = pt.v ;
e9576ca5
SC
562};
563
564// Return TRUE if we have a colour display
565bool wxColourDisplay()
566{
e9576ca5
SC
567 return TRUE;
568}
569
570// Returns depth of screen
571int wxDisplayDepth()
572{
e40298d5
JS
573 Rect globRect ;
574 SetRect(&globRect, -32760, -32760, 32760, 32760);
575 GDHandle theMaxDevice;
2f1ae414 576
e40298d5
JS
577 int theDepth = 8;
578 theMaxDevice = GetMaxDevice(&globRect);
579 if (theMaxDevice != nil)
580 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
ec5d7799 581
e40298d5 582 return theDepth ;
e9576ca5
SC
583}
584
585// Get size of display
586void wxDisplaySize(int *width, int *height)
587{
e40298d5
JS
588 BitMap screenBits;
589 GetQDGlobalsScreenBits( &screenBits );
5be55d56
VZ
590
591 if (width != NULL) {
e8ca7105
GD
592 *width = screenBits.bounds.right - screenBits.bounds.left ;
593 }
5be55d56 594 if (height != NULL) {
e8ca7105
GD
595 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
596 }
e9576ca5
SC
597}
598
5fde6fcc
GD
599void wxDisplaySizeMM(int *width, int *height)
600{
5b028d57
SC
601 wxDisplaySize(width, height);
602 // on mac 72 is fixed (at least now ;-)
603 float cvPt2Mm = 25.4 / 72;
e8ca7105 604
5be55d56 605 if (width != NULL) {
e8ca7105
GD
606 *width = int( *width * cvPt2Mm );
607 }
5be55d56 608 if (height != NULL) {
e8ca7105
GD
609 *height = int( *height * cvPt2Mm );
610 }
5fde6fcc
GD
611}
612
ec5d7799
RD
613void wxClientDisplayRect(int *x, int *y, int *width, int *height)
614{
ee658398
SC
615 Rect r ;
616 GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ;
617 if ( x )
618 *x = r.left ;
619 if ( y )
620 *y = r.top ;
621 if ( width )
622 *width = r.right - r.left ;
623 if ( height )
624 *height = r.bottom - r.top ;
ec5d7799
RD
625}
626
57591e0e
JS
627wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
628{
629 return wxGenericFindWindowAtPoint(pt);
630}
5dbb17e2 631
b6ed2b86
VZ
632#endif // wxUSE_GUI
633
634#if wxUSE_BASE
635
5dbb17e2
SC
636wxString wxGetOsDescription()
637{
6e73695c
GD
638#ifdef WXWIN_OS_DESCRIPTION
639 // use configure generated description if available
5f3f0f17 640 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
6e73695c 641#else
427ff662 642 return wxT("MacOS") ; //TODO:define further
6e73695c
GD
643#endif
644}
645
b6ed2b86
VZ
646#ifndef __DARWIN__
647wxChar *wxGetUserHome (const wxString& user)
648{
649 // TODO
650 return NULL;
651}
652
653bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
654{
655 if ( path.empty() )
656 return FALSE;
657
658 wxString p = path ;
71111c40 659 if (p[0u] == ':' ) {
b6ed2b86
VZ
660 p = wxGetCwd() + p ;
661 }
662
663 int pos = p.Find(':') ;
664 if ( pos != wxNOT_FOUND ) {
665 p = p.Mid(1,pos) ;
666 }
667
668 p = p + wxT(":") ;
669
670 Str255 volumeName ;
671 XVolumeParam pb ;
672
673 wxMacStringToPascal( p , volumeName ) ;
674 OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ;
675 if ( err == noErr ) {
676 if ( pTotal ) {
677 (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ;
678 }
679 if ( pFree ) {
680 (*pFree) = wxLongLong( pb.ioVFreeBytes ) ;
681 }
682 }
683
684 return err == noErr ;
685}
686#endif // !__DARWIN__
687
3d963f81
SC
688//---------------------------------------------------------------------------
689// wxMac Specific utility functions
690//---------------------------------------------------------------------------
691
5be55d56 692void wxMacStringToPascal( const wxString&from , StringPtr to )
427ff662 693{
939fba6c 694 wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
427ff662
SC
695 int len = strlen(buf) ;
696
697 if ( len > 255 )
698 len = 255 ;
699 to[0] = len ;
700 memcpy( (char*) &to[1] , buf , len ) ;
701}
702
5be55d56 703wxString wxMacMakeStringFromPascal( ConstStringPtr from )
427ff662 704{
939fba6c 705 return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
427ff662
SC
706}
707
e50d5284
RD
708
709wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
710{
711 TextEncodingBase enc = 0 ;
fe929141
SC
712 if ( encoding == wxFONTENCODING_DEFAULT )
713 {
714#if wxUSE_GUI
715 encoding = wxFont::GetDefaultEncoding() ;
716#else
717 encoding = wxLocale::GetSystemEncoding() ;
718#endif
719 }
e50d5284
RD
720
721 switch( encoding)
722 {
723 case wxFONTENCODING_ISO8859_1 :
724 enc = kTextEncodingISOLatin1 ;
725 break ;
726 case wxFONTENCODING_ISO8859_2 :
727 enc = kTextEncodingISOLatin2;
728 break ;
729 case wxFONTENCODING_ISO8859_3 :
730 enc = kTextEncodingISOLatin3 ;
731 break ;
732 case wxFONTENCODING_ISO8859_4 :
733 enc = kTextEncodingISOLatin4;
734 break ;
735 case wxFONTENCODING_ISO8859_5 :
736 enc = kTextEncodingISOLatinCyrillic;
737 break ;
738 case wxFONTENCODING_ISO8859_6 :
739 enc = kTextEncodingISOLatinArabic;
740 break ;
741 case wxFONTENCODING_ISO8859_7 :
742 enc = kTextEncodingISOLatinGreek;
743 break ;
744 case wxFONTENCODING_ISO8859_8 :
745 enc = kTextEncodingISOLatinHebrew;
746 break ;
747 case wxFONTENCODING_ISO8859_9 :
748 enc = kTextEncodingISOLatin5;
749 break ;
750 case wxFONTENCODING_ISO8859_10 :
751 enc = kTextEncodingISOLatin6;
752 break ;
753 case wxFONTENCODING_ISO8859_13 :
754 enc = kTextEncodingISOLatin7;
755 break ;
756 case wxFONTENCODING_ISO8859_14 :
757 enc = kTextEncodingISOLatin8;
758 break ;
759 case wxFONTENCODING_ISO8859_15 :
760 enc = kTextEncodingISOLatin9;
761 break ;
762
763 case wxFONTENCODING_KOI8 :
764 enc = kTextEncodingKOI8_R;
765 break ;
766 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
767 enc = kTextEncodingDOSRussian;
768 break ;
769/*
770 case wxFONTENCODING_BULGARIAN :
771 enc = ;
772 break ;
773*/
774 case wxFONTENCODING_CP437 :
775 enc =kTextEncodingDOSLatinUS ;
776 break ;
777 case wxFONTENCODING_CP850 :
778 enc = kTextEncodingDOSLatin1;
779 break ;
780 case wxFONTENCODING_CP852 :
781 enc = kTextEncodingDOSLatin2;
782 break ;
783 case wxFONTENCODING_CP855 :
784 enc = kTextEncodingDOSCyrillic;
785 break ;
786 case wxFONTENCODING_CP866 :
787 enc =kTextEncodingDOSRussian ;
788 break ;
789 case wxFONTENCODING_CP874 :
790 enc = kTextEncodingDOSThai;
791 break ;
792 case wxFONTENCODING_CP932 :
793 enc = kTextEncodingDOSJapanese;
794 break ;
795 case wxFONTENCODING_CP936 :
796 enc =kTextEncodingDOSChineseSimplif ;
797 break ;
798 case wxFONTENCODING_CP949 :
799 enc = kTextEncodingDOSKorean;
800 break ;
801 case wxFONTENCODING_CP950 :
802 enc = kTextEncodingDOSChineseTrad;
803 break ;
804
805 case wxFONTENCODING_CP1250 :
806 enc = kTextEncodingWindowsLatin2;
807 break ;
808 case wxFONTENCODING_CP1251 :
809 enc =kTextEncodingWindowsCyrillic ;
810 break ;
811 case wxFONTENCODING_CP1252 :
812 enc =kTextEncodingWindowsLatin1 ;
813 break ;
814 case wxFONTENCODING_CP1253 :
815 enc = kTextEncodingWindowsGreek;
816 break ;
817 case wxFONTENCODING_CP1254 :
818 enc = kTextEncodingWindowsLatin5;
819 break ;
820 case wxFONTENCODING_CP1255 :
821 enc =kTextEncodingWindowsHebrew ;
822 break ;
823 case wxFONTENCODING_CP1256 :
824 enc =kTextEncodingWindowsArabic ;
825 break ;
826 case wxFONTENCODING_CP1257 :
827 enc = kTextEncodingWindowsBalticRim;
828 break ;
829
830 case wxFONTENCODING_UTF7 :
831 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
832 break ;
833 case wxFONTENCODING_UTF8 :
834 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
835 break ;
836 case wxFONTENCODING_EUC_JP :
837 enc = kTextEncodingEUC_JP;
838 break ;
839 case wxFONTENCODING_UTF16BE :
840 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
841 break ;
842 case wxFONTENCODING_UTF16LE :
843 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
844 break ;
845 case wxFONTENCODING_UTF32BE :
846 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
847 break ;
848 case wxFONTENCODING_UTF32LE :
849 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
850 break ;
851
852 case wxFONTENCODING_MACROMAN :
853 enc = kTextEncodingMacRoman ;
854 break ;
855 case wxFONTENCODING_MACJAPANESE :
856 enc = kTextEncodingMacJapanese ;
857 break ;
858 case wxFONTENCODING_MACCHINESETRAD :
859 enc = kTextEncodingMacChineseTrad ;
860 break ;
861 case wxFONTENCODING_MACKOREAN :
862 enc = kTextEncodingMacKorean ;
863 break ;
864 case wxFONTENCODING_MACARABIC :
865 enc = kTextEncodingMacArabic ;
866 break ;
867 case wxFONTENCODING_MACHEBREW :
868 enc = kTextEncodingMacHebrew ;
869 break ;
870 case wxFONTENCODING_MACGREEK :
871 enc = kTextEncodingMacGreek ;
872 break ;
873 case wxFONTENCODING_MACCYRILLIC :
874 enc = kTextEncodingMacCyrillic ;
875 break ;
876 case wxFONTENCODING_MACDEVANAGARI :
877 enc = kTextEncodingMacDevanagari ;
878 break ;
879 case wxFONTENCODING_MACGURMUKHI :
880 enc = kTextEncodingMacGurmukhi ;
881 break ;
882 case wxFONTENCODING_MACGUJARATI :
883 enc = kTextEncodingMacGujarati ;
884 break ;
885 case wxFONTENCODING_MACORIYA :
886 enc = kTextEncodingMacOriya ;
887 break ;
888 case wxFONTENCODING_MACBENGALI :
889 enc = kTextEncodingMacBengali ;
890 break ;
891 case wxFONTENCODING_MACTAMIL :
892 enc = kTextEncodingMacTamil ;
893 break ;
894 case wxFONTENCODING_MACTELUGU :
895 enc = kTextEncodingMacTelugu ;
896 break ;
897 case wxFONTENCODING_MACKANNADA :
898 enc = kTextEncodingMacKannada ;
899 break ;
900 case wxFONTENCODING_MACMALAJALAM :
901 enc = kTextEncodingMacMalayalam ;
902 break ;
903 case wxFONTENCODING_MACSINHALESE :
904 enc = kTextEncodingMacSinhalese ;
905 break ;
906 case wxFONTENCODING_MACBURMESE :
907 enc = kTextEncodingMacBurmese ;
908 break ;
909 case wxFONTENCODING_MACKHMER :
910 enc = kTextEncodingMacKhmer ;
911 break ;
912 case wxFONTENCODING_MACTHAI :
913 enc = kTextEncodingMacThai ;
914 break ;
915 case wxFONTENCODING_MACLAOTIAN :
916 enc = kTextEncodingMacLaotian ;
917 break ;
918 case wxFONTENCODING_MACGEORGIAN :
919 enc = kTextEncodingMacGeorgian ;
920 break ;
921 case wxFONTENCODING_MACARMENIAN :
922 enc = kTextEncodingMacArmenian ;
923 break ;
924 case wxFONTENCODING_MACCHINESESIMP :
925 enc = kTextEncodingMacChineseSimp ;
926 break ;
927 case wxFONTENCODING_MACTIBETAN :
928 enc = kTextEncodingMacTibetan ;
929 break ;
930 case wxFONTENCODING_MACMONGOLIAN :
931 enc = kTextEncodingMacMongolian ;
932 break ;
933 case wxFONTENCODING_MACETHIOPIC :
934 enc = kTextEncodingMacEthiopic ;
935 break ;
936 case wxFONTENCODING_MACCENTRALEUR :
937 enc = kTextEncodingMacCentralEurRoman ;
938 break ;
939 case wxFONTENCODING_MACVIATNAMESE :
940 enc = kTextEncodingMacVietnamese ;
941 break ;
942 case wxFONTENCODING_MACARABICEXT :
943 enc = kTextEncodingMacExtArabic ;
944 break ;
945 case wxFONTENCODING_MACSYMBOL :
946 enc = kTextEncodingMacSymbol ;
947 break ;
948 case wxFONTENCODING_MACDINGBATS :
949 enc = kTextEncodingMacDingbats ;
950 break ;
951 case wxFONTENCODING_MACTURKISH :
952 enc = kTextEncodingMacTurkish ;
953 break ;
954 case wxFONTENCODING_MACCROATIAN :
955 enc = kTextEncodingMacCroatian ;
956 break ;
957 case wxFONTENCODING_MACICELANDIC :
958 enc = kTextEncodingMacIcelandic ;
959 break ;
960 case wxFONTENCODING_MACROMANIAN :
961 enc = kTextEncodingMacRomanian ;
962 break ;
963 case wxFONTENCODING_MACCELTIC :
964 enc = kTextEncodingMacCeltic ;
965 break ;
966 case wxFONTENCODING_MACGAELIC :
967 enc = kTextEncodingMacGaelic ;
968 break ;
969 case wxFONTENCODING_MACKEYBOARD :
970 enc = kTextEncodingMacKeyboardGlyphs ;
79a73b4f
SC
971 break ;
972 default :
973 // to make gcc happy
974 break ;
e50d5284
RD
975 } ;
976 return enc ;
977}
978
979wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
980{
981 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
982
983 switch( encoding)
984 {
985 case kTextEncodingISOLatin1 :
986 enc = wxFONTENCODING_ISO8859_1 ;
987 break ;
988 case kTextEncodingISOLatin2 :
989 enc = wxFONTENCODING_ISO8859_2;
990 break ;
991 case kTextEncodingISOLatin3 :
992 enc = wxFONTENCODING_ISO8859_3 ;
993 break ;
994 case kTextEncodingISOLatin4 :
995 enc = wxFONTENCODING_ISO8859_4;
996 break ;
997 case kTextEncodingISOLatinCyrillic :
998 enc = wxFONTENCODING_ISO8859_5;
999 break ;
1000 case kTextEncodingISOLatinArabic :
1001 enc = wxFONTENCODING_ISO8859_6;
1002 break ;
1003 case kTextEncodingISOLatinGreek :
1004 enc = wxFONTENCODING_ISO8859_7;
1005 break ;
1006 case kTextEncodingISOLatinHebrew :
1007 enc = wxFONTENCODING_ISO8859_8;
1008 break ;
1009 case kTextEncodingISOLatin5 :
1010 enc = wxFONTENCODING_ISO8859_9;
1011 break ;
1012 case kTextEncodingISOLatin6 :
1013 enc = wxFONTENCODING_ISO8859_10;
1014 break ;
1015 case kTextEncodingISOLatin7 :
1016 enc = wxFONTENCODING_ISO8859_13;
1017 break ;
1018 case kTextEncodingISOLatin8 :
1019 enc = wxFONTENCODING_ISO8859_14;
1020 break ;
1021 case kTextEncodingISOLatin9 :
1022 enc =wxFONTENCODING_ISO8859_15 ;
1023 break ;
1024
1025 case kTextEncodingKOI8_R :
1026 enc = wxFONTENCODING_KOI8;
1027 break ;
1028/*
1029 case :
1030 enc = wxFONTENCODING_BULGARIAN;
1031 break ;
1032*/
fe929141 1033 case kTextEncodingDOSLatinUS :
e50d5284
RD
1034 enc = wxFONTENCODING_CP437;
1035 break ;
1036 case kTextEncodingDOSLatin1 :
1037 enc = wxFONTENCODING_CP850;
1038 break ;
1039 case kTextEncodingDOSLatin2 :
1040 enc =wxFONTENCODING_CP852 ;
1041 break ;
1042 case kTextEncodingDOSCyrillic :
1043 enc = wxFONTENCODING_CP855;
1044 break ;
1045 case kTextEncodingDOSRussian :
1046 enc = wxFONTENCODING_CP866;
1047 break ;
1048 case kTextEncodingDOSThai :
1049 enc =wxFONTENCODING_CP874 ;
1050 break ;
1051 case kTextEncodingDOSJapanese :
1052 enc = wxFONTENCODING_CP932;
1053 break ;
1054 case kTextEncodingDOSChineseSimplif :
1055 enc = wxFONTENCODING_CP936;
1056 break ;
1057 case kTextEncodingDOSKorean :
1058 enc = wxFONTENCODING_CP949;
1059 break ;
1060 case kTextEncodingDOSChineseTrad :
1061 enc = wxFONTENCODING_CP950;
1062 break ;
1063
1064 case kTextEncodingWindowsLatin2 :
1065 enc = wxFONTENCODING_CP1250;
1066 break ;
1067 case kTextEncodingWindowsCyrillic :
1068 enc = wxFONTENCODING_CP1251;
1069 break ;
1070 case kTextEncodingWindowsLatin1 :
1071 enc = wxFONTENCODING_CP1252;
1072 break ;
1073 case kTextEncodingWindowsGreek :
1074 enc = wxFONTENCODING_CP1253;
1075 break ;
1076 case kTextEncodingWindowsLatin5 :
1077 enc = wxFONTENCODING_CP1254;
1078 break ;
1079 case kTextEncodingWindowsHebrew :
1080 enc = wxFONTENCODING_CP1255;
1081 break ;
1082 case kTextEncodingWindowsArabic :
1083 enc = wxFONTENCODING_CP1256;
1084 break ;
1085 case kTextEncodingWindowsBalticRim :
1086 enc =wxFONTENCODING_CP1257 ;
1087 break ;
1088 case kTextEncodingEUC_JP :
1089 enc = wxFONTENCODING_EUC_JP;
1090 break ;
1091 /*
1092 case wxFONTENCODING_UTF7 :
1093 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1094 break ;
1095 case wxFONTENCODING_UTF8 :
1096 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1097 break ;
1098 case wxFONTENCODING_UTF16BE :
1099 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1100 break ;
1101 case wxFONTENCODING_UTF16LE :
1102 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1103 break ;
1104 case wxFONTENCODING_UTF32BE :
1105 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1106 break ;
1107 case wxFONTENCODING_UTF32LE :
1108 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1109 break ;
1110 */
1111 case kTextEncodingMacRoman :
1112 enc = wxFONTENCODING_MACROMAN ;
1113 break ;
1114 case kTextEncodingMacJapanese :
1115 enc = wxFONTENCODING_MACJAPANESE ;
1116 break ;
1117 case kTextEncodingMacChineseTrad :
1118 enc = wxFONTENCODING_MACCHINESETRAD ;
1119 break ;
1120 case kTextEncodingMacKorean :
1121 enc = wxFONTENCODING_MACKOREAN ;
1122 break ;
1123 case kTextEncodingMacArabic :
1124 enc =wxFONTENCODING_MACARABIC ;
1125 break ;
1126 case kTextEncodingMacHebrew :
1127 enc = wxFONTENCODING_MACHEBREW ;
1128 break ;
1129 case kTextEncodingMacGreek :
1130 enc = wxFONTENCODING_MACGREEK ;
1131 break ;
1132 case kTextEncodingMacCyrillic :
1133 enc = wxFONTENCODING_MACCYRILLIC ;
1134 break ;
1135 case kTextEncodingMacDevanagari :
1136 enc = wxFONTENCODING_MACDEVANAGARI ;
1137 break ;
1138 case kTextEncodingMacGurmukhi :
1139 enc = wxFONTENCODING_MACGURMUKHI ;
1140 break ;
1141 case kTextEncodingMacGujarati :
1142 enc = wxFONTENCODING_MACGUJARATI ;
1143 break ;
1144 case kTextEncodingMacOriya :
1145 enc =wxFONTENCODING_MACORIYA ;
1146 break ;
1147 case kTextEncodingMacBengali :
1148 enc =wxFONTENCODING_MACBENGALI ;
1149 break ;
1150 case kTextEncodingMacTamil :
1151 enc = wxFONTENCODING_MACTAMIL ;
1152 break ;
1153 case kTextEncodingMacTelugu :
1154 enc = wxFONTENCODING_MACTELUGU ;
1155 break ;
1156 case kTextEncodingMacKannada :
1157 enc = wxFONTENCODING_MACKANNADA ;
1158 break ;
1159 case kTextEncodingMacMalayalam :
1160 enc = wxFONTENCODING_MACMALAJALAM ;
1161 break ;
1162 case kTextEncodingMacSinhalese :
1163 enc = wxFONTENCODING_MACSINHALESE ;
1164 break ;
1165 case kTextEncodingMacBurmese :
1166 enc = wxFONTENCODING_MACBURMESE ;
1167 break ;
1168 case kTextEncodingMacKhmer :
1169 enc = wxFONTENCODING_MACKHMER ;
1170 break ;
1171 case kTextEncodingMacThai :
1172 enc = wxFONTENCODING_MACTHAI ;
1173 break ;
1174 case kTextEncodingMacLaotian :
1175 enc = wxFONTENCODING_MACLAOTIAN ;
1176 break ;
1177 case kTextEncodingMacGeorgian :
1178 enc = wxFONTENCODING_MACGEORGIAN ;
1179 break ;
1180 case kTextEncodingMacArmenian :
1181 enc = wxFONTENCODING_MACARMENIAN ;
1182 break ;
1183 case kTextEncodingMacChineseSimp :
1184 enc = wxFONTENCODING_MACCHINESESIMP ;
1185 break ;
1186 case kTextEncodingMacTibetan :
1187 enc = wxFONTENCODING_MACTIBETAN ;
1188 break ;
1189 case kTextEncodingMacMongolian :
1190 enc = wxFONTENCODING_MACMONGOLIAN ;
1191 break ;
1192 case kTextEncodingMacEthiopic :
1193 enc = wxFONTENCODING_MACETHIOPIC ;
1194 break ;
1195 case kTextEncodingMacCentralEurRoman:
1196 enc = wxFONTENCODING_MACCENTRALEUR ;
1197 break ;
1198 case kTextEncodingMacVietnamese:
1199 enc = wxFONTENCODING_MACVIATNAMESE ;
1200 break ;
1201 case kTextEncodingMacExtArabic :
1202 enc = wxFONTENCODING_MACARABICEXT ;
1203 break ;
1204 case kTextEncodingMacSymbol :
1205 enc = wxFONTENCODING_MACSYMBOL ;
1206 break ;
1207 case kTextEncodingMacDingbats :
1208 enc = wxFONTENCODING_MACDINGBATS ;
1209 break ;
1210 case kTextEncodingMacTurkish :
1211 enc = wxFONTENCODING_MACTURKISH ;
1212 break ;
1213 case kTextEncodingMacCroatian :
1214 enc = wxFONTENCODING_MACCROATIAN ;
1215 break ;
1216 case kTextEncodingMacIcelandic :
1217 enc = wxFONTENCODING_MACICELANDIC ;
1218 break ;
1219 case kTextEncodingMacRomanian :
1220 enc = wxFONTENCODING_MACROMANIAN ;
1221 break ;
1222 case kTextEncodingMacCeltic :
1223 enc = wxFONTENCODING_MACCELTIC ;
1224 break ;
1225 case kTextEncodingMacGaelic :
1226 enc = wxFONTENCODING_MACGAELIC ;
1227 break ;
1228 case kTextEncodingMacKeyboardGlyphs :
1229 enc = wxFONTENCODING_MACKEYBOARD ;
1230 break ;
1231 } ;
1232 return enc ;
1233}
1234
2dbc444a 1235
5be55d56 1236//
427ff662
SC
1237// CFStringRefs (Carbon only)
1238//
1239
1240#if TARGET_CARBON
71111c40 1241
427ff662 1242// converts this string into a carbon foundation string with optional pc 2 mac encoding
fe929141 1243void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
427ff662 1244{
fe929141 1245 Release() ;
79a73b4f 1246
71111c40 1247 wxString str = st ;
8aa701ed 1248 wxMacConvertNewlines13To10( &str ) ;
427ff662 1249#if wxUSE_UNICODE
71111c40 1250#if SIZEOF_WCHAR_T == 2
5be55d56 1251 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
79a73b4f 1252 (UniChar*)str.wc_str() , str.Len() );
427ff662 1253#else
79a73b4f
SC
1254 wxMBConvUTF16BE converter ;
1255 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1256 UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
1257 converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
1258 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
1259 unibuf , unicharlen / sizeof(UniChar) ) ;
1260 delete[] unibuf ;
71111c40 1261#endif
71111c40 1262#else // not wxUSE_UNICODE
427ff662 1263 m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
fe929141 1264 wxMacGetSystemEncFromFontEnc( encoding ) ) ;
427ff662
SC
1265#endif
1266 m_release = true ;
1267}
1268
fe929141 1269wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
427ff662 1270{
79a73b4f
SC
1271 Size cflen = CFStringGetLength( m_cfs ) ;
1272 size_t noChars ;
1273 wxChar* buf = NULL ;
1274
427ff662 1275#if wxUSE_UNICODE
fe929141 1276#if SIZEOF_WCHAR_T == 2
79a73b4f
SC
1277 buf = new wxChar[ cflen + 1 ] ;
1278 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
1279 noChars = cflen ;
fe929141 1280#else
79a73b4f
SC
1281 UniChar* unibuf = new UniChar[ cflen + 1 ] ;
1282 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
1283 unibuf[cflen] = 0 ;
590e21b0 1284 wxMBConvUTF16BE converter ;
79a73b4f
SC
1285 noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
1286 buf = new wxChar[ noChars + 1 ] ;
1287 converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
1288 delete[] unibuf ;
1289#endif
427ff662 1290#else
79a73b4f
SC
1291 CFIndex cStrLen ;
1292 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
ac86379e 1293 '?' , false , NULL , 0 , &cStrLen ) ;
79a73b4f 1294 buf = new wxChar[ cStrLen + 1 ] ;
ac86379e
SC
1295 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1296 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
79a73b4f 1297 noChars = cStrLen ;
427ff662 1298#endif
79a73b4f
SC
1299
1300 buf[noChars] = 0 ;
8aa701ed 1301 wxMacConvertNewlines10To13( buf ) ;
79a73b4f
SC
1302 wxString result(buf) ;
1303 delete[] buf ;
427ff662
SC
1304 return result ;
1305}
1306
3d963f81
SC
1307#endif //TARGET_CARBON
1308
8aa701ed
SC
1309void wxMacConvertNewlines13To10( char * data )
1310{
1311 char * buf = data ;
1312 while( (buf=strchr(buf,0x0d)) != NULL )
1313 {
1314 *buf = 0x0a ;
1315 buf++ ;
1316 }
1317}
1318
1319void wxMacConvertNewlines10To13( char * data )
1320{
1321 char * buf = data ;
1322 while( (buf=strchr(buf,0x0a)) != NULL )
1323 {
1324 *buf = 0x0d ;
1325 buf++ ;
1326 }
1327}
1328
1329void wxMacConvertNewlines13To10( wxString * data )
1330{
be6628ce
SC
1331 size_t len = data->Length() ;
1332
1333 if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
8aa701ed
SC
1334 return ;
1335
be6628ce
SC
1336 wxString temp(*data) ;
1337 wxStringBuffer buf(*data,len ) ;
1338 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1339
1340 wxMacConvertNewlines13To10( buf ) ;
8aa701ed
SC
1341}
1342
1343void wxMacConvertNewlines10To13( wxString * data )
1344{
be6628ce
SC
1345 size_t len = data->Length() ;
1346
1347 if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL)
8aa701ed 1348 return ;
be6628ce
SC
1349
1350 wxString temp(*data) ;
1351 wxStringBuffer buf(*data,len ) ;
1352 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1353 wxMacConvertNewlines10To13( buf ) ;
8aa701ed
SC
1354}
1355
1356
1357#if wxUSE_UNICODE
1358void wxMacConvertNewlines13To10( wxChar * data )
1359{
1360 wxChar * buf = data ;
1361 while( (buf=wxStrchr(buf,0x0d)) != NULL )
1362 {
1363 *buf = 0x0a ;
1364 buf++ ;
1365 }
1366}
1367
1368void wxMacConvertNewlines10To13( wxChar * data )
1369{
1370 wxChar * buf = data ;
1371 while( (buf=wxStrchr(buf,0x0a)) != NULL )
1372 {
1373 *buf = 0x0d ;
1374 buf++ ;
1375 }
1376}
1377#endif
1378
73280e05
SC
1379// ----------------------------------------------------------------------------
1380// Common Event Support
1381// ----------------------------------------------------------------------------
1382
d13ea1bd 1383
73280e05
SC
1384extern ProcessSerialNumber gAppProcess ;
1385
1386void wxMacWakeUp()
1387{
1388 ProcessSerialNumber psn ;
1389 Boolean isSame ;
1390 psn.highLongOfPSN = 0 ;
1391 psn.lowLongOfPSN = kCurrentProcess ;
1392 SameProcess( &gAppProcess , &psn , &isSame ) ;
1393 if ( isSame )
1394 {
1395#if TARGET_CARBON
1396 EventRef dummyEvent ;
1397 OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(),
1398 kEventAttributeNone, &dummyEvent);
1399 if (err == noErr)
1400 {
1401 err = PostEventToQueue(GetMainEventQueue(), dummyEvent,
1402 kEventPriorityHigh);
1403 }
1404#else
1405 PostEvent( nullEvent , 0 ) ;
1406#endif
1407 }
1408 else
1409 {
1410 WakeUpProcess( &gAppProcess ) ;
1411 }
1412}
1413
d13ea1bd
RD
1414#endif // wxUSE_BASE
1415
1416#if wxUSE_GUI
1417
1418
facd6764
SC
1419// ----------------------------------------------------------------------------
1420// Carbon Event Support
1421// ----------------------------------------------------------------------------
1422
1423
1424OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
1425{
1426 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ;
1427}
1428
21fd5529 1429OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
facd6764
SC
1430{
1431 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ;
1432}
1433
86d8b744
SC
1434// ----------------------------------------------------------------------------
1435// Control Access Support
1436// ----------------------------------------------------------------------------
1437
5ca0d812
SC
1438void wxMacControl::Dispose()
1439{
1440 ::DisposeControl( m_controlRef ) ;
1441 m_controlRef = NULL ;
1442}
1443
1444void wxMacControl::SetReference( SInt32 data )
1445{
1446 SetControlReference( m_controlRef , data ) ;
1447}
1448
29d91661 1449OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
86d8b744
SC
1450{
1451 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;
1452}
1453
29d91661 1454OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
86d8b744
SC
1455{
1456 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;
1457}
1458
1459OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
1460{
1461 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ;
1462}
1463
21fd5529
SC
1464OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
1465{
e996f509 1466#if TARGET_API_MAC_OSX
21fd5529 1467 return SendEventToEventTargetWithOptions( event,
e996f509
SC
1468 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
1469#else
1470 #pragma unused(inOptions)
1471 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ;
1472#endif
21fd5529
SC
1473}
1474
1475OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
1476{
1477 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ;
1478 event.SetParameter<HICommand>(kEventParamDirectObject,command) ;
1479 return SendEvent( event , inOptions ) ;
1480}
1481
1482OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
1483{
1484 HICommand command ;
1485 memset( &command, 0 , sizeof(command) ) ;
1486 command.commandID = commandID ;
1487 return SendHICommand( command , inOptions ) ;
1488}
1489
1490void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
1491{
1492 HiliteControl( m_controlRef , part ) ;
1493 unsigned long finalTicks ;
1494 Delay( ticks , &finalTicks ) ;
1495 HiliteControl( m_controlRef , kControlNoPart ) ;
1496}
1497
7f7b52b4
SC
1498SInt32 wxMacControl::GetValue() const
1499{
1500 return ::GetControl32BitValue( m_controlRef ) ;
1501}
1502
1503SInt32 wxMacControl::GetMaximum() const
1504{
1505 return ::GetControl32BitMaximum( m_controlRef ) ;
1506}
1507
1508SInt32 wxMacControl::GetMinimum() const
1509{
1510 return ::GetControl32BitMinimum( m_controlRef ) ;
1511}
1512
1513void wxMacControl::SetValue( SInt32 v )
1514{
1515 ::SetControl32BitValue( m_controlRef , v ) ;
1516}
1517
1518void wxMacControl::SetMinimum( SInt32 v )
1519{
1520 ::SetControl32BitMinimum( m_controlRef , v ) ;
1521}
1522
1523void wxMacControl::SetMaximum( SInt32 v )
1524{
1525 ::SetControl32BitMaximum( m_controlRef , v ) ;
1526}
1527
1528void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
1529{
1530 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
1531 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
1532 ::SetControl32BitValue( m_controlRef , value ) ;
1533}
1534
5ca0d812
SC
1535OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
1536{
1537 return SetKeyboardFocus( GetControlOwner( m_controlRef ) ,
1538 m_controlRef , focusPart ) ;
1539}
1540
1541bool wxMacControl::HasFocus() const
1542{
1543 ControlRef control ;
1544 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
1545 return control == m_controlRef ;
1546}
1547
1548bool wxMacControl::NeedsFocusRect() const
1549{
1550 return false ;
1551}
1552
29d91661
SC
1553void wxMacControl::VisibilityChanged(bool shown)
1554{
1555}
1556
1557void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
1558{
1559 m_font = font ;
1560 ControlFontStyleRec fontStyle;
1561 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
1562 {
1563 switch( font.MacGetThemeFontID() )
1564 {
1565 case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ;
1566 case 109 /*mini font */ : fontStyle.font = -5 ; break ;
1567 case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ;
1568 default : fontStyle.font = kControlFontBigSystemFont ; break ;
1569 }
1570 fontStyle.flags = kControlUseFontMask ;
1571 }
1572 else
1573 {
1574 fontStyle.font = font.MacGetFontNum() ;
1575 fontStyle.style = font.MacGetFontStyle() ;
1576 fontStyle.size = font.MacGetFontSize() ;
1577 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ;
1578 }
1579
1580 fontStyle.just = teJustLeft ;
1581 fontStyle.flags |= kControlUseJustMask ;
1582 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
1583 fontStyle.just = teJustCenter ;
1584 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
1585 fontStyle.just = teJustRight ;
1586
1587
1588 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1589 // won't get grayed out by the system anymore
1590
1591 if ( foreground != *wxBLACK )
1592 {
1593 fontStyle.foreColor = MAC_WXCOLORREF(foreground.GetPixel() ) ;
1594 fontStyle.flags |= kControlUseForeColorMask ;
1595 }
1596
1597 ::SetControlFontStyle( m_controlRef , &fontStyle );
1598}
1599
7ea087b7
SC
1600void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
1601{
1602 // TODO
1603 // setting up a color proc is not recommended anymore
1604}
1605
7f7b52b4
SC
1606void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
1607{
1608 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
1609 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
1610}
1611
5ca0d812
SC
1612short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
1613{
1614 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ) ;
1615}
1616
1617void wxMacControl::SetActionProc( ControlActionUPP actionProc )
1618{
1619 SetControlAction( m_controlRef , actionProc ) ;
1620}
1621
1622void wxMacControl::SetViewSize( SInt32 viewSize )
1623{
1624 SetControlViewSize(m_controlRef , viewSize ) ;
1625}
1626
1627SInt32 wxMacControl::GetViewSize() const
1628{
1629 return GetControlViewSize( m_controlRef ) ;
1630}
1631
1632bool wxMacControl::IsVisible() const
1633{
1634 return IsControlVisible( m_controlRef ) ;
1635}
1636
1637void wxMacControl::SetVisibility( bool visible , bool redraw )
1638{
1639 SetControlVisibility( m_controlRef , visible , redraw ) ;
1640}
1641
1642bool wxMacControl::IsEnabled() const
1643{
1644#if TARGET_API_MAC_OSX
1645 return IsControlEnabled( m_controlRef ) ;
1646#else
1647 return IsControlActive( m_controlRef ) ;
1648#endif
1649}
1650
1651bool wxMacControl::IsActive() const
1652{
1653 return IsControlActive( m_controlRef ) ;
1654}
1655
1656void wxMacControl::Enable( bool enable )
1657{
1658#if TARGET_API_MAC_OSX
1659 if ( enable )
1660 EnableControl( m_controlRef ) ;
1661 else
1662 DisableControl( m_controlRef ) ;
1663#else
1664 if ( enable )
1665 ActivateControl( m_controlRef ) ;
1666 else
1667 DeactivateControl( m_controlRef ) ;
1668#endif
1669}
1670
1671void wxMacControl::SetDrawingEnabled( bool enable )
1672{
1673#if TARGET_API_MAC_OSX
1674 HIViewSetDrawingEnabled( m_controlRef , enable ) ;
1675#endif
1676}
1677
1678bool wxMacControl::GetNeedsDisplay() const
1679{
1680#if TARGET_API_MAC_OSX
1681 return HIViewGetNeedsDisplay( m_controlRef ) ;
1682#else
1683 return false ;
1684#endif
1685}
1686
1687void wxMacControl::SetNeedsDisplay( bool needsDisplay , RgnHandle where )
1688{
1689#if TARGET_API_MAC_OSX
1690 if ( where != NULL )
1691 HIViewSetNeedsDisplayInRegion( m_controlRef , where , needsDisplay ) ;
1692 else
1693 HIViewSetNeedsDisplay( m_controlRef , needsDisplay ) ;
1694#endif
1695}
1696
1697void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
1698{
1699#if TARGET_API_MAC_OSX
1700 HIPoint hiPoint ;
1701 hiPoint.x = pt->x ;
1702 hiPoint.y = pt->y ;
1703 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ) ;
6ea4a266
VZ
1704 pt->x = (int)hiPoint.x ;
1705 pt->y = (int)hiPoint.y ;
5ca0d812
SC
1706#endif
1707}
1708
1709void wxMacControl::SetRect( Rect *r )
1710{
1711#if TARGET_API_MAC_OSX
1712 HIRect hir = { r->left , r->top , r->right - r->left , r->bottom - r->top } ;
1713 HIViewSetFrame ( m_controlRef , &hir ) ;
1714#else
1715 SetControlBounds( m_controlRef , r ) ;
1716#endif
1717
1718}
1719
1720void wxMacControl::GetRect( Rect *r )
1721{
1722 GetControlBounds( m_controlRef , r ) ;
1723}
1724
1725void wxMacControl::GetRectInWindowCoords( Rect *r )
1726{
1727 UMAGetControlBoundsInWindowCoords( m_controlRef , r ) ;
1728}
1729
1730void wxMacControl::GetBestRect( Rect *r )
1731{
5ca0d812
SC
1732 short baselineoffset ;
1733 GetBestControlRect( m_controlRef , r , &baselineoffset ) ;
1734}
1735
1736void wxMacControl::SetTitle( const wxString &title )
1737{
10a59880
RD
1738 wxFontEncoding encoding;
1739
1740 if ( m_font.Ok() )
1741 encoding = m_font.GetEncoding();
1742 else
1743 encoding = wxFont::GetDefaultEncoding();
1744
1745 UMASetControlTitle( m_controlRef , title , encoding ) ;
5ca0d812
SC
1746}
1747
1748void wxMacControl::GetFeatures( UInt32 * features )
1749{
1750 GetControlFeatures( m_controlRef , features ) ;
1751}
1752
1753OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
1754{
1755 return GetControlRegion( m_controlRef , partCode , region ) ;
1756}
1757
1758OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
1759{
1760#if TARGET_API_MAC_OSX
1761 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
1762 (other != NULL) ? other->m_controlRef : NULL) ;
1763#else
1764 return 0 ;
1765#endif
1766}
1767
1768
1769#if TARGET_API_MAC_OSX
1770// SetNeedsDisplay would not invalidate the children
1771static void InvalidateControlAndChildren( HIViewRef control )
1772{
1773 HIViewSetNeedsDisplay( control , true ) ;
1774 UInt16 childrenCount = 0 ;
1775 OSStatus err = CountSubControls( control , &childrenCount ) ;
1776 if ( err == errControlIsNotEmbedder )
1777 return ;
1778 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
1779
1780 for ( UInt16 i = childrenCount ; i >=1 ; --i )
1781 {
1782 HIViewRef child ;
1783 err = GetIndexedSubControl( control , i , & child ) ;
1784 if ( err == errControlIsNotEmbedder )
1785 return ;
1786 InvalidateControlAndChildren( child ) ;
1787 }
1788}
1789#endif
1790
1791void wxMacControl::InvalidateWithChildren()
1792{
1793#if TARGET_API_MAC_OSX
1794 InvalidateControlAndChildren( m_controlRef ) ;
1795#endif
1796}
1797
1798void wxMacControl::ScrollRect( const wxRect &r , int dx , int dy )
1799{
1800#if TARGET_API_MAC_OSX
1801 HIRect scrollarea = CGRectMake( r.x , r.y , r.width , r.height) ;
1802 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ;
1803#endif
1804}
1805
1806
1807// SetNeedsDisplay would not invalidate the children
1808
1809//
1810// Databrowser
1811//
1812
1813OSStatus wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options )
1814{
1815 return SetDataBrowserSelectionFlags( m_controlRef , options ) ;
1816}
1817
1818OSStatus wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc,
1819 DataBrowserTableViewColumnIndex position )
1820{
1821 return AddDataBrowserListViewColumn( m_controlRef , columnDesc, position ) ;
1822}
1823
1824OSStatus wxMacControl::AutoSizeListViewColumns()
1825{
1826 return AutoSizeDataBrowserListViewColumns(m_controlRef) ;
1827}
1828
1829OSStatus wxMacControl::SetHasScrollBars( bool horiz , bool vert )
1830{
1831 return SetDataBrowserHasScrollBars( m_controlRef , horiz , vert ) ;
1832}
1833
1834OSStatus wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1835{
1836 return SetDataBrowserTableViewHiliteStyle( m_controlRef , hiliteStyle ) ;
1837}
1838
1839OSStatus wxMacControl::SetListViewHeaderBtnHeight(UInt16 height)
1840{
1841 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef ,height ) ;
1842}
1843
1844OSStatus wxMacControl::SetCallbacks(const DataBrowserCallbacks * callbacks)
1845{
1846 return SetDataBrowserCallbacks( m_controlRef , callbacks ) ;
1847}
1848
1849OSStatus wxMacControl::UpdateItems( DataBrowserItemID container, UInt32 numItems,
1850 const DataBrowserItemID* items,
1851 DataBrowserPropertyID preSortProperty,
1852 DataBrowserPropertyID propertyID )
1853{
1854 return UpdateDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty, propertyID ) ;
1855}
1856
1857bool wxMacControl::IsItemSelected( DataBrowserItemID item )
1858{
1859 return IsDataBrowserItemSelected( m_controlRef , item ) ;
1860}
1861
1862OSStatus wxMacControl::AddItems( DataBrowserItemID container, UInt32 numItems,
1863 const DataBrowserItemID* items,
1864 DataBrowserPropertyID preSortProperty )
1865{
1866 return AddDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ;
1867}
1868
1869OSStatus wxMacControl::RemoveItems( DataBrowserItemID container, UInt32 numItems,
1870 const DataBrowserItemID* items,
1871 DataBrowserPropertyID preSortProperty )
1872{
1873 return RemoveDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ;
1874}
1875
1876OSStatus wxMacControl::RevealItem( DataBrowserItemID item,
1877 DataBrowserPropertyID propertyID,
1878 DataBrowserRevealOptions options )
1879{
1880 return RevealDataBrowserItem( m_controlRef , item , propertyID , options ) ;
1881}
1882
1883OSStatus wxMacControl::SetSelectedItems(UInt32 numItems,
1884 const DataBrowserItemID * items,
1885 DataBrowserSetOption operation )
1886{
1887 return SetDataBrowserSelectedItems( m_controlRef , numItems , items, operation ) ;
1888}
1889
1890//
1891// Tab Control
1892//
1893
1894OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
1895{
1896 return ::SetTabEnabled( m_controlRef , tabNo , enable ) ;
1897}
1898
b6ed2b86
VZ
1899#endif // wxUSE_GUI
1900