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