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