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