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