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