]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
c4cf8ce73646d4572d4e227d3fb034974153d6fc
[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 #ifndef __DARWIN__
342
343 void wxMicroSleep(unsigned long microseconds)
344 {
345 AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
346 MPDelayUntil( & wakeup);
347 }
348
349 void wxMilliSleep(unsigned long milliseconds)
350 {
351 AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
352 MPDelayUntil( & wakeup);
353 }
354
355 void wxSleep(int nSecs)
356 {
357 wxMilliSleep(1000*nSecs);
358 }
359
360 #endif
361
362 // Consume all events until no more left
363 void wxFlushEvents()
364 {
365 }
366
367 #endif // !__DARWIN__
368
369 // Emit a beeeeeep
370 void wxBell()
371 {
372 SysBeep(30);
373 }
374
375 wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
376 {
377 static wxToolkitInfo info;
378 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
379 info.name = _T("wxBase");
380 return info;
381 }
382
383 #endif // wxUSE_BASE
384
385 #if wxUSE_GUI
386
387 wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
388 {
389 static wxToolkitInfo info;
390 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
391 info.shortName = _T("mac");
392 info.name = _T("wxMac");
393 #ifdef __WXUNIVERSAL__
394 info.shortName << _T("univ");
395 info.name << _T("/wxUniversal");
396 #endif
397 return info;
398 }
399
400 // Reading and writing resources (eg WIN.INI, .Xdefaults)
401 #if wxUSE_RESOURCES
402 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
403 {
404 // TODO
405 return FALSE;
406 }
407
408 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
409 {
410 wxString buf;
411 buf.Printf(wxT("%.4f"), value);
412
413 return wxWriteResource(section, entry, buf, file);
414 }
415
416 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
417 {
418 wxString buf;
419 buf.Printf(wxT("%ld"), value);
420
421 return wxWriteResource(section, entry, buf, file);
422 }
423
424 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
425 {
426 wxString buf;
427 buf.Printf(wxT("%d"), value);
428
429 return wxWriteResource(section, entry, buf, file);
430 }
431
432 bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
433 {
434 // TODO
435 return FALSE;
436 }
437
438 bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
439 {
440 char *s = NULL;
441 bool succ = wxGetResource(section, entry, (char **)&s, file);
442 if (succ)
443 {
444 *value = (float)strtod(s, NULL);
445 delete[] s;
446 return TRUE;
447 }
448 else return FALSE;
449 }
450
451 bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
452 {
453 char *s = NULL;
454 bool succ = wxGetResource(section, entry, (char **)&s, file);
455 if (succ)
456 {
457 *value = strtol(s, NULL, 10);
458 delete[] s;
459 return TRUE;
460 }
461 else return FALSE;
462 }
463
464 bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
465 {
466 char *s = NULL;
467 bool succ = wxGetResource(section, entry, (char **)&s, file);
468 if (succ)
469 {
470 *value = (int)strtol(s, NULL, 10);
471 delete[] s;
472 return TRUE;
473 }
474 else return FALSE;
475 }
476 #endif // wxUSE_RESOURCES
477
478 int gs_wxBusyCursorCount = 0;
479 extern wxCursor gMacCurrentCursor ;
480 wxCursor gMacStoredActiveCursor ;
481
482 // Set the cursor to the busy cursor for all windows
483 void wxBeginBusyCursor(wxCursor *cursor)
484 {
485 if (gs_wxBusyCursorCount++ == 0)
486 {
487 gMacStoredActiveCursor = gMacCurrentCursor ;
488 cursor->MacInstall() ;
489 }
490 //else: nothing to do, already set
491 }
492
493 // Restore cursor to normal
494 void wxEndBusyCursor()
495 {
496 wxCHECK_RET( gs_wxBusyCursorCount > 0,
497 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
498
499 if (--gs_wxBusyCursorCount == 0)
500 {
501 gMacStoredActiveCursor.MacInstall() ;
502 gMacStoredActiveCursor = wxNullCursor ;
503 }
504 }
505
506 // TRUE if we're between the above two calls
507 bool wxIsBusy()
508 {
509 return (gs_wxBusyCursorCount > 0);
510 }
511
512 #endif // wxUSE_GUI
513
514 #if wxUSE_BASE
515
516 wxString wxMacFindFolder( short vol,
517 OSType folderType,
518 Boolean createFolder)
519 {
520 short vRefNum ;
521 long dirID ;
522 wxString strDir ;
523
524 if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
525 {
526 FSSpec file ;
527 if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
528 {
529 strDir = wxMacFSSpec2MacFilename( &file ) + wxFILE_SEP_PATH ;
530 }
531 }
532 return strDir ;
533 }
534
535 #endif // wxUSE_BASE
536
537 #if wxUSE_GUI
538
539 // Check whether this window wants to process messages, e.g. Stop button
540 // in long calculations.
541 bool wxCheckForInterrupt(wxWindow *wnd)
542 {
543 // TODO
544 return FALSE;
545 }
546
547 void wxGetMousePosition( int* x, int* y )
548 {
549 Point pt ;
550
551 GetMouse( &pt ) ;
552 LocalToGlobal( &pt ) ;
553 *x = pt.h ;
554 *y = pt.v ;
555 };
556
557 // Return TRUE if we have a colour display
558 bool wxColourDisplay()
559 {
560 return TRUE;
561 }
562
563 // Returns depth of screen
564 int wxDisplayDepth()
565 {
566 Rect globRect ;
567 SetRect(&globRect, -32760, -32760, 32760, 32760);
568 GDHandle theMaxDevice;
569
570 int theDepth = 8;
571 theMaxDevice = GetMaxDevice(&globRect);
572 if (theMaxDevice != nil)
573 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
574
575 return theDepth ;
576 }
577
578 // Get size of display
579 void wxDisplaySize(int *width, int *height)
580 {
581 BitMap screenBits;
582 GetQDGlobalsScreenBits( &screenBits );
583
584 if (width != NULL) {
585 *width = screenBits.bounds.right - screenBits.bounds.left ;
586 }
587 if (height != NULL) {
588 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
589 }
590 }
591
592 void wxDisplaySizeMM(int *width, int *height)
593 {
594 wxDisplaySize(width, height);
595 // on mac 72 is fixed (at least now ;-)
596 float cvPt2Mm = 25.4 / 72;
597
598 if (width != NULL) {
599 *width = int( *width * cvPt2Mm );
600 }
601 if (height != NULL) {
602 *height = int( *height * cvPt2Mm );
603 }
604 }
605
606 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
607 {
608 Rect r ;
609 GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ;
610 if ( x )
611 *x = r.left ;
612 if ( y )
613 *y = r.top ;
614 if ( width )
615 *width = r.right - r.left ;
616 if ( height )
617 *height = r.bottom - r.top ;
618 }
619
620 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
621 {
622 return wxGenericFindWindowAtPoint(pt);
623 }
624
625 #endif // wxUSE_GUI
626
627 #if wxUSE_BASE
628
629 wxString wxGetOsDescription()
630 {
631 #ifdef WXWIN_OS_DESCRIPTION
632 // use configure generated description if available
633 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
634 #else
635 return wxT("MacOS") ; //TODO:define further
636 #endif
637 }
638
639 #ifndef __DARWIN__
640 wxChar *wxGetUserHome (const wxString& user)
641 {
642 // TODO
643 return NULL;
644 }
645
646 bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
647 {
648 if ( path.empty() )
649 return FALSE;
650
651 wxString p = path ;
652 if (p[0u] == ':' ) {
653 p = wxGetCwd() + p ;
654 }
655
656 int pos = p.Find(':') ;
657 if ( pos != wxNOT_FOUND ) {
658 p = p.Mid(1,pos) ;
659 }
660
661 p = p + wxT(":") ;
662
663 Str255 volumeName ;
664 XVolumeParam pb ;
665
666 wxMacStringToPascal( p , volumeName ) ;
667 OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ;
668 if ( err == noErr ) {
669 if ( pTotal ) {
670 (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ;
671 }
672 if ( pFree ) {
673 (*pFree) = wxLongLong( pb.ioVFreeBytes ) ;
674 }
675 }
676
677 return err == noErr ;
678 }
679 #endif // !__DARWIN__
680
681 //---------------------------------------------------------------------------
682 // wxMac Specific utility functions
683 //---------------------------------------------------------------------------
684
685 void wxMacStringToPascal( const wxString&from , StringPtr to )
686 {
687 wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
688 int len = strlen(buf) ;
689
690 if ( len > 255 )
691 len = 255 ;
692 to[0] = len ;
693 memcpy( (char*) &to[1] , buf , len ) ;
694 }
695
696 wxString wxMacMakeStringFromPascal( ConstStringPtr from )
697 {
698 return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
699 }
700
701
702 wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
703 {
704 TextEncodingBase enc = 0 ;
705 if ( encoding == wxFONTENCODING_DEFAULT )
706 {
707 #if wxUSE_GUI
708 encoding = wxFont::GetDefaultEncoding() ;
709 #else
710 encoding = wxLocale::GetSystemEncoding() ;
711 #endif
712 }
713
714 switch( encoding)
715 {
716 case wxFONTENCODING_ISO8859_1 :
717 enc = kTextEncodingISOLatin1 ;
718 break ;
719 case wxFONTENCODING_ISO8859_2 :
720 enc = kTextEncodingISOLatin2;
721 break ;
722 case wxFONTENCODING_ISO8859_3 :
723 enc = kTextEncodingISOLatin3 ;
724 break ;
725 case wxFONTENCODING_ISO8859_4 :
726 enc = kTextEncodingISOLatin4;
727 break ;
728 case wxFONTENCODING_ISO8859_5 :
729 enc = kTextEncodingISOLatinCyrillic;
730 break ;
731 case wxFONTENCODING_ISO8859_6 :
732 enc = kTextEncodingISOLatinArabic;
733 break ;
734 case wxFONTENCODING_ISO8859_7 :
735 enc = kTextEncodingISOLatinGreek;
736 break ;
737 case wxFONTENCODING_ISO8859_8 :
738 enc = kTextEncodingISOLatinHebrew;
739 break ;
740 case wxFONTENCODING_ISO8859_9 :
741 enc = kTextEncodingISOLatin5;
742 break ;
743 case wxFONTENCODING_ISO8859_10 :
744 enc = kTextEncodingISOLatin6;
745 break ;
746 case wxFONTENCODING_ISO8859_13 :
747 enc = kTextEncodingISOLatin7;
748 break ;
749 case wxFONTENCODING_ISO8859_14 :
750 enc = kTextEncodingISOLatin8;
751 break ;
752 case wxFONTENCODING_ISO8859_15 :
753 enc = kTextEncodingISOLatin9;
754 break ;
755
756 case wxFONTENCODING_KOI8 :
757 enc = kTextEncodingKOI8_R;
758 break ;
759 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
760 enc = kTextEncodingDOSRussian;
761 break ;
762 /*
763 case wxFONTENCODING_BULGARIAN :
764 enc = ;
765 break ;
766 */
767 case wxFONTENCODING_CP437 :
768 enc =kTextEncodingDOSLatinUS ;
769 break ;
770 case wxFONTENCODING_CP850 :
771 enc = kTextEncodingDOSLatin1;
772 break ;
773 case wxFONTENCODING_CP852 :
774 enc = kTextEncodingDOSLatin2;
775 break ;
776 case wxFONTENCODING_CP855 :
777 enc = kTextEncodingDOSCyrillic;
778 break ;
779 case wxFONTENCODING_CP866 :
780 enc =kTextEncodingDOSRussian ;
781 break ;
782 case wxFONTENCODING_CP874 :
783 enc = kTextEncodingDOSThai;
784 break ;
785 case wxFONTENCODING_CP932 :
786 enc = kTextEncodingDOSJapanese;
787 break ;
788 case wxFONTENCODING_CP936 :
789 enc =kTextEncodingDOSChineseSimplif ;
790 break ;
791 case wxFONTENCODING_CP949 :
792 enc = kTextEncodingDOSKorean;
793 break ;
794 case wxFONTENCODING_CP950 :
795 enc = kTextEncodingDOSChineseTrad;
796 break ;
797
798 case wxFONTENCODING_CP1250 :
799 enc = kTextEncodingWindowsLatin2;
800 break ;
801 case wxFONTENCODING_CP1251 :
802 enc =kTextEncodingWindowsCyrillic ;
803 break ;
804 case wxFONTENCODING_CP1252 :
805 enc =kTextEncodingWindowsLatin1 ;
806 break ;
807 case wxFONTENCODING_CP1253 :
808 enc = kTextEncodingWindowsGreek;
809 break ;
810 case wxFONTENCODING_CP1254 :
811 enc = kTextEncodingWindowsLatin5;
812 break ;
813 case wxFONTENCODING_CP1255 :
814 enc =kTextEncodingWindowsHebrew ;
815 break ;
816 case wxFONTENCODING_CP1256 :
817 enc =kTextEncodingWindowsArabic ;
818 break ;
819 case wxFONTENCODING_CP1257 :
820 enc = kTextEncodingWindowsBalticRim;
821 break ;
822
823 case wxFONTENCODING_UTF7 :
824 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
825 break ;
826 case wxFONTENCODING_UTF8 :
827 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
828 break ;
829 case wxFONTENCODING_EUC_JP :
830 enc = kTextEncodingEUC_JP;
831 break ;
832 case wxFONTENCODING_UTF16BE :
833 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
834 break ;
835 case wxFONTENCODING_UTF16LE :
836 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
837 break ;
838 case wxFONTENCODING_UTF32BE :
839 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
840 break ;
841 case wxFONTENCODING_UTF32LE :
842 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
843 break ;
844
845 case wxFONTENCODING_MACROMAN :
846 enc = kTextEncodingMacRoman ;
847 break ;
848 case wxFONTENCODING_MACJAPANESE :
849 enc = kTextEncodingMacJapanese ;
850 break ;
851 case wxFONTENCODING_MACCHINESETRAD :
852 enc = kTextEncodingMacChineseTrad ;
853 break ;
854 case wxFONTENCODING_MACKOREAN :
855 enc = kTextEncodingMacKorean ;
856 break ;
857 case wxFONTENCODING_MACARABIC :
858 enc = kTextEncodingMacArabic ;
859 break ;
860 case wxFONTENCODING_MACHEBREW :
861 enc = kTextEncodingMacHebrew ;
862 break ;
863 case wxFONTENCODING_MACGREEK :
864 enc = kTextEncodingMacGreek ;
865 break ;
866 case wxFONTENCODING_MACCYRILLIC :
867 enc = kTextEncodingMacCyrillic ;
868 break ;
869 case wxFONTENCODING_MACDEVANAGARI :
870 enc = kTextEncodingMacDevanagari ;
871 break ;
872 case wxFONTENCODING_MACGURMUKHI :
873 enc = kTextEncodingMacGurmukhi ;
874 break ;
875 case wxFONTENCODING_MACGUJARATI :
876 enc = kTextEncodingMacGujarati ;
877 break ;
878 case wxFONTENCODING_MACORIYA :
879 enc = kTextEncodingMacOriya ;
880 break ;
881 case wxFONTENCODING_MACBENGALI :
882 enc = kTextEncodingMacBengali ;
883 break ;
884 case wxFONTENCODING_MACTAMIL :
885 enc = kTextEncodingMacTamil ;
886 break ;
887 case wxFONTENCODING_MACTELUGU :
888 enc = kTextEncodingMacTelugu ;
889 break ;
890 case wxFONTENCODING_MACKANNADA :
891 enc = kTextEncodingMacKannada ;
892 break ;
893 case wxFONTENCODING_MACMALAJALAM :
894 enc = kTextEncodingMacMalayalam ;
895 break ;
896 case wxFONTENCODING_MACSINHALESE :
897 enc = kTextEncodingMacSinhalese ;
898 break ;
899 case wxFONTENCODING_MACBURMESE :
900 enc = kTextEncodingMacBurmese ;
901 break ;
902 case wxFONTENCODING_MACKHMER :
903 enc = kTextEncodingMacKhmer ;
904 break ;
905 case wxFONTENCODING_MACTHAI :
906 enc = kTextEncodingMacThai ;
907 break ;
908 case wxFONTENCODING_MACLAOTIAN :
909 enc = kTextEncodingMacLaotian ;
910 break ;
911 case wxFONTENCODING_MACGEORGIAN :
912 enc = kTextEncodingMacGeorgian ;
913 break ;
914 case wxFONTENCODING_MACARMENIAN :
915 enc = kTextEncodingMacArmenian ;
916 break ;
917 case wxFONTENCODING_MACCHINESESIMP :
918 enc = kTextEncodingMacChineseSimp ;
919 break ;
920 case wxFONTENCODING_MACTIBETAN :
921 enc = kTextEncodingMacTibetan ;
922 break ;
923 case wxFONTENCODING_MACMONGOLIAN :
924 enc = kTextEncodingMacMongolian ;
925 break ;
926 case wxFONTENCODING_MACETHIOPIC :
927 enc = kTextEncodingMacEthiopic ;
928 break ;
929 case wxFONTENCODING_MACCENTRALEUR :
930 enc = kTextEncodingMacCentralEurRoman ;
931 break ;
932 case wxFONTENCODING_MACVIATNAMESE :
933 enc = kTextEncodingMacVietnamese ;
934 break ;
935 case wxFONTENCODING_MACARABICEXT :
936 enc = kTextEncodingMacExtArabic ;
937 break ;
938 case wxFONTENCODING_MACSYMBOL :
939 enc = kTextEncodingMacSymbol ;
940 break ;
941 case wxFONTENCODING_MACDINGBATS :
942 enc = kTextEncodingMacDingbats ;
943 break ;
944 case wxFONTENCODING_MACTURKISH :
945 enc = kTextEncodingMacTurkish ;
946 break ;
947 case wxFONTENCODING_MACCROATIAN :
948 enc = kTextEncodingMacCroatian ;
949 break ;
950 case wxFONTENCODING_MACICELANDIC :
951 enc = kTextEncodingMacIcelandic ;
952 break ;
953 case wxFONTENCODING_MACROMANIAN :
954 enc = kTextEncodingMacRomanian ;
955 break ;
956 case wxFONTENCODING_MACCELTIC :
957 enc = kTextEncodingMacCeltic ;
958 break ;
959 case wxFONTENCODING_MACGAELIC :
960 enc = kTextEncodingMacGaelic ;
961 break ;
962 case wxFONTENCODING_MACKEYBOARD :
963 enc = kTextEncodingMacKeyboardGlyphs ;
964 break ;
965 default :
966 // to make gcc happy
967 break ;
968 } ;
969 return enc ;
970 }
971
972 wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
973 {
974 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
975
976 switch( encoding)
977 {
978 case kTextEncodingISOLatin1 :
979 enc = wxFONTENCODING_ISO8859_1 ;
980 break ;
981 case kTextEncodingISOLatin2 :
982 enc = wxFONTENCODING_ISO8859_2;
983 break ;
984 case kTextEncodingISOLatin3 :
985 enc = wxFONTENCODING_ISO8859_3 ;
986 break ;
987 case kTextEncodingISOLatin4 :
988 enc = wxFONTENCODING_ISO8859_4;
989 break ;
990 case kTextEncodingISOLatinCyrillic :
991 enc = wxFONTENCODING_ISO8859_5;
992 break ;
993 case kTextEncodingISOLatinArabic :
994 enc = wxFONTENCODING_ISO8859_6;
995 break ;
996 case kTextEncodingISOLatinGreek :
997 enc = wxFONTENCODING_ISO8859_7;
998 break ;
999 case kTextEncodingISOLatinHebrew :
1000 enc = wxFONTENCODING_ISO8859_8;
1001 break ;
1002 case kTextEncodingISOLatin5 :
1003 enc = wxFONTENCODING_ISO8859_9;
1004 break ;
1005 case kTextEncodingISOLatin6 :
1006 enc = wxFONTENCODING_ISO8859_10;
1007 break ;
1008 case kTextEncodingISOLatin7 :
1009 enc = wxFONTENCODING_ISO8859_13;
1010 break ;
1011 case kTextEncodingISOLatin8 :
1012 enc = wxFONTENCODING_ISO8859_14;
1013 break ;
1014 case kTextEncodingISOLatin9 :
1015 enc =wxFONTENCODING_ISO8859_15 ;
1016 break ;
1017
1018 case kTextEncodingKOI8_R :
1019 enc = wxFONTENCODING_KOI8;
1020 break ;
1021 /*
1022 case :
1023 enc = wxFONTENCODING_BULGARIAN;
1024 break ;
1025 */
1026 case kTextEncodingDOSLatinUS :
1027 enc = wxFONTENCODING_CP437;
1028 break ;
1029 case kTextEncodingDOSLatin1 :
1030 enc = wxFONTENCODING_CP850;
1031 break ;
1032 case kTextEncodingDOSLatin2 :
1033 enc =wxFONTENCODING_CP852 ;
1034 break ;
1035 case kTextEncodingDOSCyrillic :
1036 enc = wxFONTENCODING_CP855;
1037 break ;
1038 case kTextEncodingDOSRussian :
1039 enc = wxFONTENCODING_CP866;
1040 break ;
1041 case kTextEncodingDOSThai :
1042 enc =wxFONTENCODING_CP874 ;
1043 break ;
1044 case kTextEncodingDOSJapanese :
1045 enc = wxFONTENCODING_CP932;
1046 break ;
1047 case kTextEncodingDOSChineseSimplif :
1048 enc = wxFONTENCODING_CP936;
1049 break ;
1050 case kTextEncodingDOSKorean :
1051 enc = wxFONTENCODING_CP949;
1052 break ;
1053 case kTextEncodingDOSChineseTrad :
1054 enc = wxFONTENCODING_CP950;
1055 break ;
1056
1057 case kTextEncodingWindowsLatin2 :
1058 enc = wxFONTENCODING_CP1250;
1059 break ;
1060 case kTextEncodingWindowsCyrillic :
1061 enc = wxFONTENCODING_CP1251;
1062 break ;
1063 case kTextEncodingWindowsLatin1 :
1064 enc = wxFONTENCODING_CP1252;
1065 break ;
1066 case kTextEncodingWindowsGreek :
1067 enc = wxFONTENCODING_CP1253;
1068 break ;
1069 case kTextEncodingWindowsLatin5 :
1070 enc = wxFONTENCODING_CP1254;
1071 break ;
1072 case kTextEncodingWindowsHebrew :
1073 enc = wxFONTENCODING_CP1255;
1074 break ;
1075 case kTextEncodingWindowsArabic :
1076 enc = wxFONTENCODING_CP1256;
1077 break ;
1078 case kTextEncodingWindowsBalticRim :
1079 enc =wxFONTENCODING_CP1257 ;
1080 break ;
1081 case kTextEncodingEUC_JP :
1082 enc = wxFONTENCODING_EUC_JP;
1083 break ;
1084 /*
1085 case wxFONTENCODING_UTF7 :
1086 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1087 break ;
1088 case wxFONTENCODING_UTF8 :
1089 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1090 break ;
1091 case wxFONTENCODING_UTF16BE :
1092 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1093 break ;
1094 case wxFONTENCODING_UTF16LE :
1095 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1096 break ;
1097 case wxFONTENCODING_UTF32BE :
1098 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1099 break ;
1100 case wxFONTENCODING_UTF32LE :
1101 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1102 break ;
1103 */
1104 case kTextEncodingMacRoman :
1105 enc = wxFONTENCODING_MACROMAN ;
1106 break ;
1107 case kTextEncodingMacJapanese :
1108 enc = wxFONTENCODING_MACJAPANESE ;
1109 break ;
1110 case kTextEncodingMacChineseTrad :
1111 enc = wxFONTENCODING_MACCHINESETRAD ;
1112 break ;
1113 case kTextEncodingMacKorean :
1114 enc = wxFONTENCODING_MACKOREAN ;
1115 break ;
1116 case kTextEncodingMacArabic :
1117 enc =wxFONTENCODING_MACARABIC ;
1118 break ;
1119 case kTextEncodingMacHebrew :
1120 enc = wxFONTENCODING_MACHEBREW ;
1121 break ;
1122 case kTextEncodingMacGreek :
1123 enc = wxFONTENCODING_MACGREEK ;
1124 break ;
1125 case kTextEncodingMacCyrillic :
1126 enc = wxFONTENCODING_MACCYRILLIC ;
1127 break ;
1128 case kTextEncodingMacDevanagari :
1129 enc = wxFONTENCODING_MACDEVANAGARI ;
1130 break ;
1131 case kTextEncodingMacGurmukhi :
1132 enc = wxFONTENCODING_MACGURMUKHI ;
1133 break ;
1134 case kTextEncodingMacGujarati :
1135 enc = wxFONTENCODING_MACGUJARATI ;
1136 break ;
1137 case kTextEncodingMacOriya :
1138 enc =wxFONTENCODING_MACORIYA ;
1139 break ;
1140 case kTextEncodingMacBengali :
1141 enc =wxFONTENCODING_MACBENGALI ;
1142 break ;
1143 case kTextEncodingMacTamil :
1144 enc = wxFONTENCODING_MACTAMIL ;
1145 break ;
1146 case kTextEncodingMacTelugu :
1147 enc = wxFONTENCODING_MACTELUGU ;
1148 break ;
1149 case kTextEncodingMacKannada :
1150 enc = wxFONTENCODING_MACKANNADA ;
1151 break ;
1152 case kTextEncodingMacMalayalam :
1153 enc = wxFONTENCODING_MACMALAJALAM ;
1154 break ;
1155 case kTextEncodingMacSinhalese :
1156 enc = wxFONTENCODING_MACSINHALESE ;
1157 break ;
1158 case kTextEncodingMacBurmese :
1159 enc = wxFONTENCODING_MACBURMESE ;
1160 break ;
1161 case kTextEncodingMacKhmer :
1162 enc = wxFONTENCODING_MACKHMER ;
1163 break ;
1164 case kTextEncodingMacThai :
1165 enc = wxFONTENCODING_MACTHAI ;
1166 break ;
1167 case kTextEncodingMacLaotian :
1168 enc = wxFONTENCODING_MACLAOTIAN ;
1169 break ;
1170 case kTextEncodingMacGeorgian :
1171 enc = wxFONTENCODING_MACGEORGIAN ;
1172 break ;
1173 case kTextEncodingMacArmenian :
1174 enc = wxFONTENCODING_MACARMENIAN ;
1175 break ;
1176 case kTextEncodingMacChineseSimp :
1177 enc = wxFONTENCODING_MACCHINESESIMP ;
1178 break ;
1179 case kTextEncodingMacTibetan :
1180 enc = wxFONTENCODING_MACTIBETAN ;
1181 break ;
1182 case kTextEncodingMacMongolian :
1183 enc = wxFONTENCODING_MACMONGOLIAN ;
1184 break ;
1185 case kTextEncodingMacEthiopic :
1186 enc = wxFONTENCODING_MACETHIOPIC ;
1187 break ;
1188 case kTextEncodingMacCentralEurRoman:
1189 enc = wxFONTENCODING_MACCENTRALEUR ;
1190 break ;
1191 case kTextEncodingMacVietnamese:
1192 enc = wxFONTENCODING_MACVIATNAMESE ;
1193 break ;
1194 case kTextEncodingMacExtArabic :
1195 enc = wxFONTENCODING_MACARABICEXT ;
1196 break ;
1197 case kTextEncodingMacSymbol :
1198 enc = wxFONTENCODING_MACSYMBOL ;
1199 break ;
1200 case kTextEncodingMacDingbats :
1201 enc = wxFONTENCODING_MACDINGBATS ;
1202 break ;
1203 case kTextEncodingMacTurkish :
1204 enc = wxFONTENCODING_MACTURKISH ;
1205 break ;
1206 case kTextEncodingMacCroatian :
1207 enc = wxFONTENCODING_MACCROATIAN ;
1208 break ;
1209 case kTextEncodingMacIcelandic :
1210 enc = wxFONTENCODING_MACICELANDIC ;
1211 break ;
1212 case kTextEncodingMacRomanian :
1213 enc = wxFONTENCODING_MACROMANIAN ;
1214 break ;
1215 case kTextEncodingMacCeltic :
1216 enc = wxFONTENCODING_MACCELTIC ;
1217 break ;
1218 case kTextEncodingMacGaelic :
1219 enc = wxFONTENCODING_MACGAELIC ;
1220 break ;
1221 case kTextEncodingMacKeyboardGlyphs :
1222 enc = wxFONTENCODING_MACKEYBOARD ;
1223 break ;
1224 } ;
1225 return enc ;
1226 }
1227
1228
1229 //
1230 // CFStringRefs (Carbon only)
1231 //
1232
1233 #if TARGET_CARBON
1234
1235 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1236 void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
1237 {
1238 Release() ;
1239
1240 wxString str = st ;
1241 wxMacConvertNewlines13To10( &str ) ;
1242 #if wxUSE_UNICODE
1243 #if SIZEOF_WCHAR_T == 2
1244 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
1245 (UniChar*)str.wc_str() , str.Len() );
1246 #else
1247 wxMBConvUTF16BE converter ;
1248 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1249 UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
1250 converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
1251 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
1252 unibuf , unicharlen / sizeof(UniChar) ) ;
1253 delete[] unibuf ;
1254 #endif
1255 #else // not wxUSE_UNICODE
1256 m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
1257 wxMacGetSystemEncFromFontEnc( encoding ) ) ;
1258 #endif
1259 m_release = true ;
1260 }
1261
1262 wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
1263 {
1264 Size cflen = CFStringGetLength( m_cfs ) ;
1265 size_t noChars ;
1266 wxChar* buf = NULL ;
1267
1268 #if wxUSE_UNICODE
1269 #if SIZEOF_WCHAR_T == 2
1270 buf = new wxChar[ cflen + 1 ] ;
1271 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
1272 noChars = cflen ;
1273 #else
1274 UniChar* unibuf = new UniChar[ cflen + 1 ] ;
1275 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
1276 unibuf[cflen] = 0 ;
1277 wxMBConvUTF16BE converter ;
1278 noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
1279 buf = new wxChar[ noChars + 1 ] ;
1280 converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
1281 delete[] unibuf ;
1282 #endif
1283 #else
1284 CFIndex cStrLen ;
1285 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1286 '?' , false , NULL , 0 , &cStrLen ) ;
1287 buf = new wxChar[ cStrLen + 1 ] ;
1288 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1289 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
1290 noChars = cStrLen ;
1291 #endif
1292
1293 buf[noChars] = 0 ;
1294 wxMacConvertNewlines10To13( buf ) ;
1295 wxString result(buf) ;
1296 delete[] buf ;
1297 return result ;
1298 }
1299
1300 #endif //TARGET_CARBON
1301
1302 void wxMacConvertNewlines13To10( char * data )
1303 {
1304 char * buf = data ;
1305 while( (buf=strchr(buf,0x0d)) != NULL )
1306 {
1307 *buf = 0x0a ;
1308 buf++ ;
1309 }
1310 }
1311
1312 void wxMacConvertNewlines10To13( char * data )
1313 {
1314 char * buf = data ;
1315 while( (buf=strchr(buf,0x0a)) != NULL )
1316 {
1317 *buf = 0x0d ;
1318 buf++ ;
1319 }
1320 }
1321
1322 void wxMacConvertNewlines13To10( wxString * data )
1323 {
1324 size_t len = data->Length() ;
1325
1326 if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
1327 return ;
1328
1329 wxString temp(*data) ;
1330 wxStringBuffer buf(*data,len ) ;
1331 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1332
1333 wxMacConvertNewlines13To10( buf ) ;
1334 }
1335
1336 void wxMacConvertNewlines10To13( wxString * data )
1337 {
1338 size_t len = data->Length() ;
1339
1340 if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL)
1341 return ;
1342
1343 wxString temp(*data) ;
1344 wxStringBuffer buf(*data,len ) ;
1345 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1346 wxMacConvertNewlines10To13( buf ) ;
1347 }
1348
1349
1350 #if wxUSE_UNICODE
1351 void wxMacConvertNewlines13To10( wxChar * data )
1352 {
1353 wxChar * buf = data ;
1354 while( (buf=wxStrchr(buf,0x0d)) != NULL )
1355 {
1356 *buf = 0x0a ;
1357 buf++ ;
1358 }
1359 }
1360
1361 void wxMacConvertNewlines10To13( wxChar * data )
1362 {
1363 wxChar * buf = data ;
1364 while( (buf=wxStrchr(buf,0x0a)) != NULL )
1365 {
1366 *buf = 0x0d ;
1367 buf++ ;
1368 }
1369 }
1370 #endif
1371
1372 // ----------------------------------------------------------------------------
1373 // Common Event Support
1374 // ----------------------------------------------------------------------------
1375
1376
1377 extern ProcessSerialNumber gAppProcess ;
1378
1379 void wxMacWakeUp()
1380 {
1381 ProcessSerialNumber psn ;
1382 Boolean isSame ;
1383 psn.highLongOfPSN = 0 ;
1384 psn.lowLongOfPSN = kCurrentProcess ;
1385 SameProcess( &gAppProcess , &psn , &isSame ) ;
1386 if ( isSame )
1387 {
1388 #if TARGET_CARBON
1389 EventRef dummyEvent ;
1390 OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(),
1391 kEventAttributeNone, &dummyEvent);
1392 if (err == noErr)
1393 {
1394 err = PostEventToQueue(GetMainEventQueue(), dummyEvent,
1395 kEventPriorityHigh);
1396 }
1397 #else
1398 PostEvent( nullEvent , 0 ) ;
1399 #endif
1400 }
1401 else
1402 {
1403 WakeUpProcess( &gAppProcess ) ;
1404 }
1405 }
1406
1407 #endif // wxUSE_BASE
1408
1409 #if wxUSE_GUI
1410
1411
1412 // ----------------------------------------------------------------------------
1413 // Carbon Event Support
1414 // ----------------------------------------------------------------------------
1415
1416
1417 OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
1418 {
1419 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ;
1420 }
1421
1422 OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
1423 {
1424 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ;
1425 }
1426
1427 // ----------------------------------------------------------------------------
1428 // Control Access Support
1429 // ----------------------------------------------------------------------------
1430
1431 OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize )
1432 {
1433 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;
1434 }
1435
1436 OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize )
1437 {
1438 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;
1439 }
1440
1441 OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
1442 {
1443 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ;
1444 }
1445
1446 OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
1447 {
1448 #if TARGET_API_MAC_OSX
1449 return SendEventToEventTargetWithOptions( event,
1450 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
1451 #else
1452 #pragma unused(inOptions)
1453 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ;
1454 #endif
1455 }
1456
1457 OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
1458 {
1459 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ;
1460 event.SetParameter<HICommand>(kEventParamDirectObject,command) ;
1461 return SendEvent( event , inOptions ) ;
1462 }
1463
1464 OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
1465 {
1466 HICommand command ;
1467 memset( &command, 0 , sizeof(command) ) ;
1468 command.commandID = commandID ;
1469 return SendHICommand( command , inOptions ) ;
1470 }
1471
1472 void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
1473 {
1474 HiliteControl( m_controlRef , part ) ;
1475 unsigned long finalTicks ;
1476 Delay( ticks , &finalTicks ) ;
1477 HiliteControl( m_controlRef , kControlNoPart ) ;
1478 }
1479
1480 SInt32 wxMacControl::GetValue() const
1481 {
1482 return ::GetControl32BitValue( m_controlRef ) ;
1483 }
1484
1485 SInt32 wxMacControl::GetMaximum() const
1486 {
1487 return ::GetControl32BitMaximum( m_controlRef ) ;
1488 }
1489
1490 SInt32 wxMacControl::GetMinimum() const
1491 {
1492 return ::GetControl32BitMinimum( m_controlRef ) ;
1493 }
1494
1495 void wxMacControl::SetValue( SInt32 v )
1496 {
1497 ::SetControl32BitValue( m_controlRef , v ) ;
1498 }
1499
1500 void wxMacControl::SetMinimum( SInt32 v )
1501 {
1502 ::SetControl32BitMinimum( m_controlRef , v ) ;
1503 }
1504
1505 void wxMacControl::SetMaximum( SInt32 v )
1506 {
1507 ::SetControl32BitMaximum( m_controlRef , v ) ;
1508 }
1509
1510 void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
1511 {
1512 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
1513 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
1514 ::SetControl32BitValue( m_controlRef , value ) ;
1515 }
1516
1517 void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
1518 {
1519 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
1520 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
1521 }
1522
1523 #endif // wxUSE_GUI
1524