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