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