]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
10.2 fixes
[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 #if TARGET_API_MAC_OSX
49 #include <CoreServices/CoreServices.h>
50 #else
51 #include <DriverServices.h>
52 #include <Multiprocessing.h>
53 #endif
54
55 #include <ATSUnicode.h>
56 #include <TextCommon.h>
57 #include <TextEncodingConverter.h>
58
59 #include "wx/mac/private.h" // includes mac headers
60
61 #if defined(__MWERKS__) && wxUSE_UNICODE
62 #include <wtime.h>
63 #endif
64
65 // ---------------------------------------------------------------------------
66 // code used in both base and GUI compilation
67 // ---------------------------------------------------------------------------
68
69 // our OS version is the same in non GUI and GUI cases
70 static int DoGetOSVersion(int *majorVsn, int *minorVsn)
71 {
72 long theSystem ;
73
74 // are there x-platform conventions ?
75
76 Gestalt(gestaltSystemVersion, &theSystem) ;
77 if (minorVsn != NULL) {
78 *minorVsn = (theSystem & 0xFF ) ;
79 }
80 if (majorVsn != NULL) {
81 *majorVsn = (theSystem >> 8 ) ;
82 }
83 #ifdef __DARWIN__
84 return wxMAC_DARWIN;
85 #else
86 return wxMAC;
87 #endif
88 }
89
90
91 #if wxUSE_BASE
92
93 // ----------------------------------------------------------------------------
94 // debugging support
95 // ----------------------------------------------------------------------------
96
97 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
98
99 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
100
101 #ifndef __MetroNubUtils__
102 #include "MetroNubUtils.h"
103 #endif
104
105 #ifndef __GESTALT__
106 #include <Gestalt.h>
107 #endif
108
109 #if TARGET_API_MAC_CARBON
110
111 #include <CodeFragments.h>
112
113 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
114
115 ProcPtr gCallUniversalProc_Proc = NULL;
116
117 #endif
118
119 static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
120
121 static long fRunOnce = false;
122
123 /* ---------------------------------------------------------------------------
124 IsMetroNubInstalled
125 --------------------------------------------------------------------------- */
126
127 Boolean IsMetroNubInstalled()
128 {
129 if (!fRunOnce)
130 {
131 long result, value;
132
133 fRunOnce = true;
134 gMetroNubEntry = NULL;
135
136 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
137 {
138 /* look for MetroNub's Gestalt selector */
139 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
140 {
141
142 #if TARGET_API_MAC_CARBON
143 if (gCallUniversalProc_Proc == NULL)
144 {
145 CFragConnectionID connectionID;
146 Ptr mainAddress;
147 Str255 errorString;
148 ProcPtr symbolAddress;
149 OSErr err;
150 CFragSymbolClass symbolClass;
151
152 symbolAddress = NULL;
153 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
154 &connectionID, &mainAddress, errorString);
155
156 if (err != noErr)
157 {
158 gCallUniversalProc_Proc = NULL;
159 goto end;
160 }
161
162 err = FindSymbol(connectionID, "\pCallUniversalProc",
163 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
164
165 if (err != noErr)
166 {
167 gCallUniversalProc_Proc = NULL;
168 goto end;
169 }
170 }
171 #endif
172
173 {
174 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
175
176 /* make sure the version of the API is compatible */
177 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
178 kMetroNubUserAPIVersion <= block->apiHiVersion)
179 gMetroNubEntry = block; /* success! */
180 }
181
182 }
183 }
184 }
185
186 end:
187
188 #if TARGET_API_MAC_CARBON
189 return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
190 #else
191 return (gMetroNubEntry != NULL);
192 #endif
193 }
194
195 /* ---------------------------------------------------------------------------
196 IsMWDebuggerRunning [v1 API]
197 --------------------------------------------------------------------------- */
198
199 Boolean IsMWDebuggerRunning()
200 {
201 if (IsMetroNubInstalled())
202 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
203 else
204 return false;
205 }
206
207 /* ---------------------------------------------------------------------------
208 AmIBeingMWDebugged [v1 API]
209 --------------------------------------------------------------------------- */
210
211 Boolean AmIBeingMWDebugged()
212 {
213 if (IsMetroNubInstalled())
214 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
215 else
216 return false;
217 }
218
219 extern bool WXDLLEXPORT wxIsDebuggerRunning()
220 {
221 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
222 }
223
224 #else
225
226 extern bool WXDLLEXPORT wxIsDebuggerRunning()
227 {
228 return false;
229 }
230
231 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
232
233
234 #ifndef __DARWIN__
235 // defined in unix/utilsunx.cpp for Mac OS X
236
237 // get full hostname (with domain name if possible)
238 bool wxGetFullHostName(wxChar *buf, int maxSize)
239 {
240 return wxGetHostName(buf, maxSize);
241 }
242
243 // Get hostname only (without domain name)
244 bool wxGetHostName(wxChar *buf, int maxSize)
245 {
246 // Gets Chooser name of user by examining a System resource.
247
248 const short kComputerNameID = -16413;
249
250 short oldResFile = CurResFile() ;
251 UseResFile(0);
252 StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);
253 UseResFile(oldResFile);
254
255 if (chooserName && *chooserName)
256 {
257 HLock( (Handle) chooserName ) ;
258 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
259 HUnlock( (Handle) chooserName ) ;
260 ReleaseResource( (Handle) chooserName ) ;
261 wxStrncpy( buf , name , maxSize - 1 ) ;
262 }
263 else
264 buf[0] = 0 ;
265
266 return TRUE;
267 }
268
269 // Get user ID e.g. jacs
270 bool wxGetUserId(wxChar *buf, int maxSize)
271 {
272 return wxGetUserName( buf , maxSize ) ;
273 }
274
275 const wxChar* wxGetHomeDir(wxString *pstr)
276 {
277 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
278 return pstr->c_str() ;
279 }
280
281 // Get user name e.g. Stefan Csomor
282 bool wxGetUserName(wxChar *buf, int maxSize)
283 {
284 // Gets Chooser name of user by examining a System resource.
285
286 const short kChooserNameID = -16096;
287
288 short oldResFile = CurResFile() ;
289 UseResFile(0);
290 StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);
291 UseResFile(oldResFile);
292
293 if (chooserName && *chooserName)
294 {
295 HLock( (Handle) chooserName ) ;
296 wxString name = wxMacMakeStringFromPascal( *chooserName ) ;
297 HUnlock( (Handle) chooserName ) ;
298 ReleaseResource( (Handle) chooserName ) ;
299 wxStrncpy( buf , name , maxSize - 1 ) ;
300 }
301 else
302 buf[0] = 0 ;
303
304 return TRUE;
305 }
306
307 int wxKill(long pid, wxSignal sig , wxKillError *rc )
308 {
309 // TODO
310 return 0;
311 }
312
313 WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
314 {
315 // TODO : under classic there is no environement support, under X yes
316 return false ;
317 }
318
319 // set the env var name to the given value, return TRUE on success
320 WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
321 {
322 // TODO : under classic there is no environement support, under X yes
323 return false ;
324 }
325
326 //
327 // Execute a program in an Interactive Shell
328 //
329 bool wxShell(const wxString& command)
330 {
331 // TODO
332 return FALSE;
333 }
334
335 // Shutdown or reboot the PC
336 bool wxShutdown(wxShutdownFlags wFlags)
337 {
338 // TODO
339 return FALSE;
340 }
341
342 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
343 long wxGetFreeMemory()
344 {
345 return FreeMem() ;
346 }
347
348 #ifndef __DARWIN__
349
350 void wxMicroSleep(unsigned long microseconds)
351 {
352 AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
353 MPDelayUntil( & wakeup);
354 }
355
356 void wxMilliSleep(unsigned long milliseconds)
357 {
358 AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
359 MPDelayUntil( & wakeup);
360 }
361
362 void wxSleep(int nSecs)
363 {
364 wxMilliSleep(1000*nSecs);
365 }
366
367 #endif
368
369 // Consume all events until no more left
370 void wxFlushEvents()
371 {
372 }
373
374 #endif // !__DARWIN__
375
376 // Emit a beeeeeep
377 void wxBell()
378 {
379 SysBeep(30);
380 }
381
382 wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
383 {
384 static wxToolkitInfo info;
385 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
386 info.name = _T("wxBase");
387 return info;
388 }
389
390 #endif // wxUSE_BASE
391
392 #if wxUSE_GUI
393
394 wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
395 {
396 static wxToolkitInfo info;
397 info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor);
398 info.shortName = _T("mac");
399 info.name = _T("wxMac");
400 #ifdef __WXUNIVERSAL__
401 info.shortName << _T("univ");
402 info.name << _T("/wxUniversal");
403 #endif
404 return info;
405 }
406
407 // Reading and writing resources (eg WIN.INI, .Xdefaults)
408 #if wxUSE_RESOURCES
409 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
410 {
411 // TODO
412 return FALSE;
413 }
414
415 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
416 {
417 wxString buf;
418 buf.Printf(wxT("%.4f"), value);
419
420 return wxWriteResource(section, entry, buf, file);
421 }
422
423 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
424 {
425 wxString buf;
426 buf.Printf(wxT("%ld"), value);
427
428 return wxWriteResource(section, entry, buf, file);
429 }
430
431 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
432 {
433 wxString buf;
434 buf.Printf(wxT("%d"), value);
435
436 return wxWriteResource(section, entry, buf, file);
437 }
438
439 bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
440 {
441 // TODO
442 return FALSE;
443 }
444
445 bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
446 {
447 char *s = NULL;
448 bool succ = wxGetResource(section, entry, (char **)&s, file);
449 if (succ)
450 {
451 *value = (float)strtod(s, NULL);
452 delete[] s;
453 return TRUE;
454 }
455 else return FALSE;
456 }
457
458 bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
459 {
460 char *s = NULL;
461 bool succ = wxGetResource(section, entry, (char **)&s, file);
462 if (succ)
463 {
464 *value = strtol(s, NULL, 10);
465 delete[] s;
466 return TRUE;
467 }
468 else return FALSE;
469 }
470
471 bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
472 {
473 char *s = NULL;
474 bool succ = wxGetResource(section, entry, (char **)&s, file);
475 if (succ)
476 {
477 *value = (int)strtol(s, NULL, 10);
478 delete[] s;
479 return TRUE;
480 }
481 else return FALSE;
482 }
483 #endif // wxUSE_RESOURCES
484
485 int gs_wxBusyCursorCount = 0;
486 extern wxCursor gMacCurrentCursor ;
487 wxCursor gMacStoredActiveCursor ;
488
489 // Set the cursor to the busy cursor for all windows
490 void wxBeginBusyCursor(wxCursor *cursor)
491 {
492 if (gs_wxBusyCursorCount++ == 0)
493 {
494 gMacStoredActiveCursor = gMacCurrentCursor ;
495 cursor->MacInstall() ;
496 }
497 //else: nothing to do, already set
498 }
499
500 // Restore cursor to normal
501 void wxEndBusyCursor()
502 {
503 wxCHECK_RET( gs_wxBusyCursorCount > 0,
504 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
505
506 if (--gs_wxBusyCursorCount == 0)
507 {
508 gMacStoredActiveCursor.MacInstall() ;
509 gMacStoredActiveCursor = wxNullCursor ;
510 }
511 }
512
513 // TRUE if we're between the above two calls
514 bool wxIsBusy()
515 {
516 return (gs_wxBusyCursorCount > 0);
517 }
518
519 #endif // wxUSE_GUI
520
521 #if wxUSE_BASE
522
523 wxString wxMacFindFolder( short vol,
524 OSType folderType,
525 Boolean createFolder)
526 {
527 short vRefNum ;
528 long dirID ;
529 wxString strDir ;
530
531 if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
532 {
533 FSSpec file ;
534 if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
535 {
536 strDir = wxMacFSSpec2MacFilename( &file ) + wxFILE_SEP_PATH ;
537 }
538 }
539 return strDir ;
540 }
541
542 #endif // wxUSE_BASE
543
544 #if wxUSE_GUI
545
546 // Check whether this window wants to process messages, e.g. Stop button
547 // in long calculations.
548 bool wxCheckForInterrupt(wxWindow *wnd)
549 {
550 // TODO
551 return FALSE;
552 }
553
554 void wxGetMousePosition( int* x, int* y )
555 {
556 Point pt ;
557
558 GetMouse( &pt ) ;
559 LocalToGlobal( &pt ) ;
560 *x = pt.h ;
561 *y = pt.v ;
562 };
563
564 // Return TRUE if we have a colour display
565 bool wxColourDisplay()
566 {
567 return TRUE;
568 }
569
570 // Returns depth of screen
571 int wxDisplayDepth()
572 {
573 Rect globRect ;
574 SetRect(&globRect, -32760, -32760, 32760, 32760);
575 GDHandle theMaxDevice;
576
577 int theDepth = 8;
578 theMaxDevice = GetMaxDevice(&globRect);
579 if (theMaxDevice != nil)
580 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
581
582 return theDepth ;
583 }
584
585 // Get size of display
586 void wxDisplaySize(int *width, int *height)
587 {
588 BitMap screenBits;
589 GetQDGlobalsScreenBits( &screenBits );
590
591 if (width != NULL) {
592 *width = screenBits.bounds.right - screenBits.bounds.left ;
593 }
594 if (height != NULL) {
595 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
596 }
597 }
598
599 void wxDisplaySizeMM(int *width, int *height)
600 {
601 wxDisplaySize(width, height);
602 // on mac 72 is fixed (at least now ;-)
603 float cvPt2Mm = 25.4 / 72;
604
605 if (width != NULL) {
606 *width = int( *width * cvPt2Mm );
607 }
608 if (height != NULL) {
609 *height = int( *height * cvPt2Mm );
610 }
611 }
612
613 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
614 {
615 Rect r ;
616 GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ;
617 if ( x )
618 *x = r.left ;
619 if ( y )
620 *y = r.top ;
621 if ( width )
622 *width = r.right - r.left ;
623 if ( height )
624 *height = r.bottom - r.top ;
625 }
626
627 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
628 {
629 return wxGenericFindWindowAtPoint(pt);
630 }
631
632 #endif // wxUSE_GUI
633
634 #if wxUSE_BASE
635
636 wxString wxGetOsDescription()
637 {
638 #ifdef WXWIN_OS_DESCRIPTION
639 // use configure generated description if available
640 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
641 #else
642 return wxT("MacOS") ; //TODO:define further
643 #endif
644 }
645
646 #ifndef __DARWIN__
647 wxChar *wxGetUserHome (const wxString& user)
648 {
649 // TODO
650 return NULL;
651 }
652
653 bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
654 {
655 if ( path.empty() )
656 return FALSE;
657
658 wxString p = path ;
659 if (p[0u] == ':' ) {
660 p = wxGetCwd() + p ;
661 }
662
663 int pos = p.Find(':') ;
664 if ( pos != wxNOT_FOUND ) {
665 p = p.Mid(1,pos) ;
666 }
667
668 p = p + wxT(":") ;
669
670 Str255 volumeName ;
671 XVolumeParam pb ;
672
673 wxMacStringToPascal( p , volumeName ) ;
674 OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ;
675 if ( err == noErr ) {
676 if ( pTotal ) {
677 (*pTotal) = wxLongLong( pb.ioVTotalBytes ) ;
678 }
679 if ( pFree ) {
680 (*pFree) = wxLongLong( pb.ioVFreeBytes ) ;
681 }
682 }
683
684 return err == noErr ;
685 }
686 #endif // !__DARWIN__
687
688 //---------------------------------------------------------------------------
689 // wxMac Specific utility functions
690 //---------------------------------------------------------------------------
691
692 void wxMacStringToPascal( const wxString&from , StringPtr to )
693 {
694 wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
695 int len = strlen(buf) ;
696
697 if ( len > 255 )
698 len = 255 ;
699 to[0] = len ;
700 memcpy( (char*) &to[1] , buf , len ) ;
701 }
702
703 wxString wxMacMakeStringFromPascal( ConstStringPtr from )
704 {
705 return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
706 }
707
708
709 wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
710 {
711 TextEncodingBase enc = 0 ;
712 if ( encoding == wxFONTENCODING_DEFAULT )
713 {
714 #if wxUSE_GUI
715 encoding = wxFont::GetDefaultEncoding() ;
716 #else
717 encoding = wxLocale::GetSystemEncoding() ;
718 #endif
719 }
720
721 switch( encoding)
722 {
723 case wxFONTENCODING_ISO8859_1 :
724 enc = kTextEncodingISOLatin1 ;
725 break ;
726 case wxFONTENCODING_ISO8859_2 :
727 enc = kTextEncodingISOLatin2;
728 break ;
729 case wxFONTENCODING_ISO8859_3 :
730 enc = kTextEncodingISOLatin3 ;
731 break ;
732 case wxFONTENCODING_ISO8859_4 :
733 enc = kTextEncodingISOLatin4;
734 break ;
735 case wxFONTENCODING_ISO8859_5 :
736 enc = kTextEncodingISOLatinCyrillic;
737 break ;
738 case wxFONTENCODING_ISO8859_6 :
739 enc = kTextEncodingISOLatinArabic;
740 break ;
741 case wxFONTENCODING_ISO8859_7 :
742 enc = kTextEncodingISOLatinGreek;
743 break ;
744 case wxFONTENCODING_ISO8859_8 :
745 enc = kTextEncodingISOLatinHebrew;
746 break ;
747 case wxFONTENCODING_ISO8859_9 :
748 enc = kTextEncodingISOLatin5;
749 break ;
750 case wxFONTENCODING_ISO8859_10 :
751 enc = kTextEncodingISOLatin6;
752 break ;
753 case wxFONTENCODING_ISO8859_13 :
754 enc = kTextEncodingISOLatin7;
755 break ;
756 case wxFONTENCODING_ISO8859_14 :
757 enc = kTextEncodingISOLatin8;
758 break ;
759 case wxFONTENCODING_ISO8859_15 :
760 enc = kTextEncodingISOLatin9;
761 break ;
762
763 case wxFONTENCODING_KOI8 :
764 enc = kTextEncodingKOI8_R;
765 break ;
766 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
767 enc = kTextEncodingDOSRussian;
768 break ;
769 /*
770 case wxFONTENCODING_BULGARIAN :
771 enc = ;
772 break ;
773 */
774 case wxFONTENCODING_CP437 :
775 enc =kTextEncodingDOSLatinUS ;
776 break ;
777 case wxFONTENCODING_CP850 :
778 enc = kTextEncodingDOSLatin1;
779 break ;
780 case wxFONTENCODING_CP852 :
781 enc = kTextEncodingDOSLatin2;
782 break ;
783 case wxFONTENCODING_CP855 :
784 enc = kTextEncodingDOSCyrillic;
785 break ;
786 case wxFONTENCODING_CP866 :
787 enc =kTextEncodingDOSRussian ;
788 break ;
789 case wxFONTENCODING_CP874 :
790 enc = kTextEncodingDOSThai;
791 break ;
792 case wxFONTENCODING_CP932 :
793 enc = kTextEncodingDOSJapanese;
794 break ;
795 case wxFONTENCODING_CP936 :
796 enc =kTextEncodingDOSChineseSimplif ;
797 break ;
798 case wxFONTENCODING_CP949 :
799 enc = kTextEncodingDOSKorean;
800 break ;
801 case wxFONTENCODING_CP950 :
802 enc = kTextEncodingDOSChineseTrad;
803 break ;
804
805 case wxFONTENCODING_CP1250 :
806 enc = kTextEncodingWindowsLatin2;
807 break ;
808 case wxFONTENCODING_CP1251 :
809 enc =kTextEncodingWindowsCyrillic ;
810 break ;
811 case wxFONTENCODING_CP1252 :
812 enc =kTextEncodingWindowsLatin1 ;
813 break ;
814 case wxFONTENCODING_CP1253 :
815 enc = kTextEncodingWindowsGreek;
816 break ;
817 case wxFONTENCODING_CP1254 :
818 enc = kTextEncodingWindowsLatin5;
819 break ;
820 case wxFONTENCODING_CP1255 :
821 enc =kTextEncodingWindowsHebrew ;
822 break ;
823 case wxFONTENCODING_CP1256 :
824 enc =kTextEncodingWindowsArabic ;
825 break ;
826 case wxFONTENCODING_CP1257 :
827 enc = kTextEncodingWindowsBalticRim;
828 break ;
829
830 case wxFONTENCODING_UTF7 :
831 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
832 break ;
833 case wxFONTENCODING_UTF8 :
834 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
835 break ;
836 case wxFONTENCODING_EUC_JP :
837 enc = kTextEncodingEUC_JP;
838 break ;
839 case wxFONTENCODING_UTF16BE :
840 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
841 break ;
842 case wxFONTENCODING_UTF16LE :
843 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
844 break ;
845 case wxFONTENCODING_UTF32BE :
846 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
847 break ;
848 case wxFONTENCODING_UTF32LE :
849 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
850 break ;
851
852 case wxFONTENCODING_MACROMAN :
853 enc = kTextEncodingMacRoman ;
854 break ;
855 case wxFONTENCODING_MACJAPANESE :
856 enc = kTextEncodingMacJapanese ;
857 break ;
858 case wxFONTENCODING_MACCHINESETRAD :
859 enc = kTextEncodingMacChineseTrad ;
860 break ;
861 case wxFONTENCODING_MACKOREAN :
862 enc = kTextEncodingMacKorean ;
863 break ;
864 case wxFONTENCODING_MACARABIC :
865 enc = kTextEncodingMacArabic ;
866 break ;
867 case wxFONTENCODING_MACHEBREW :
868 enc = kTextEncodingMacHebrew ;
869 break ;
870 case wxFONTENCODING_MACGREEK :
871 enc = kTextEncodingMacGreek ;
872 break ;
873 case wxFONTENCODING_MACCYRILLIC :
874 enc = kTextEncodingMacCyrillic ;
875 break ;
876 case wxFONTENCODING_MACDEVANAGARI :
877 enc = kTextEncodingMacDevanagari ;
878 break ;
879 case wxFONTENCODING_MACGURMUKHI :
880 enc = kTextEncodingMacGurmukhi ;
881 break ;
882 case wxFONTENCODING_MACGUJARATI :
883 enc = kTextEncodingMacGujarati ;
884 break ;
885 case wxFONTENCODING_MACORIYA :
886 enc = kTextEncodingMacOriya ;
887 break ;
888 case wxFONTENCODING_MACBENGALI :
889 enc = kTextEncodingMacBengali ;
890 break ;
891 case wxFONTENCODING_MACTAMIL :
892 enc = kTextEncodingMacTamil ;
893 break ;
894 case wxFONTENCODING_MACTELUGU :
895 enc = kTextEncodingMacTelugu ;
896 break ;
897 case wxFONTENCODING_MACKANNADA :
898 enc = kTextEncodingMacKannada ;
899 break ;
900 case wxFONTENCODING_MACMALAJALAM :
901 enc = kTextEncodingMacMalayalam ;
902 break ;
903 case wxFONTENCODING_MACSINHALESE :
904 enc = kTextEncodingMacSinhalese ;
905 break ;
906 case wxFONTENCODING_MACBURMESE :
907 enc = kTextEncodingMacBurmese ;
908 break ;
909 case wxFONTENCODING_MACKHMER :
910 enc = kTextEncodingMacKhmer ;
911 break ;
912 case wxFONTENCODING_MACTHAI :
913 enc = kTextEncodingMacThai ;
914 break ;
915 case wxFONTENCODING_MACLAOTIAN :
916 enc = kTextEncodingMacLaotian ;
917 break ;
918 case wxFONTENCODING_MACGEORGIAN :
919 enc = kTextEncodingMacGeorgian ;
920 break ;
921 case wxFONTENCODING_MACARMENIAN :
922 enc = kTextEncodingMacArmenian ;
923 break ;
924 case wxFONTENCODING_MACCHINESESIMP :
925 enc = kTextEncodingMacChineseSimp ;
926 break ;
927 case wxFONTENCODING_MACTIBETAN :
928 enc = kTextEncodingMacTibetan ;
929 break ;
930 case wxFONTENCODING_MACMONGOLIAN :
931 enc = kTextEncodingMacMongolian ;
932 break ;
933 case wxFONTENCODING_MACETHIOPIC :
934 enc = kTextEncodingMacEthiopic ;
935 break ;
936 case wxFONTENCODING_MACCENTRALEUR :
937 enc = kTextEncodingMacCentralEurRoman ;
938 break ;
939 case wxFONTENCODING_MACVIATNAMESE :
940 enc = kTextEncodingMacVietnamese ;
941 break ;
942 case wxFONTENCODING_MACARABICEXT :
943 enc = kTextEncodingMacExtArabic ;
944 break ;
945 case wxFONTENCODING_MACSYMBOL :
946 enc = kTextEncodingMacSymbol ;
947 break ;
948 case wxFONTENCODING_MACDINGBATS :
949 enc = kTextEncodingMacDingbats ;
950 break ;
951 case wxFONTENCODING_MACTURKISH :
952 enc = kTextEncodingMacTurkish ;
953 break ;
954 case wxFONTENCODING_MACCROATIAN :
955 enc = kTextEncodingMacCroatian ;
956 break ;
957 case wxFONTENCODING_MACICELANDIC :
958 enc = kTextEncodingMacIcelandic ;
959 break ;
960 case wxFONTENCODING_MACROMANIAN :
961 enc = kTextEncodingMacRomanian ;
962 break ;
963 case wxFONTENCODING_MACCELTIC :
964 enc = kTextEncodingMacCeltic ;
965 break ;
966 case wxFONTENCODING_MACGAELIC :
967 enc = kTextEncodingMacGaelic ;
968 break ;
969 case wxFONTENCODING_MACKEYBOARD :
970 enc = kTextEncodingMacKeyboardGlyphs ;
971 break ;
972 default :
973 // to make gcc happy
974 break ;
975 } ;
976 return enc ;
977 }
978
979 wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
980 {
981 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
982
983 switch( encoding)
984 {
985 case kTextEncodingISOLatin1 :
986 enc = wxFONTENCODING_ISO8859_1 ;
987 break ;
988 case kTextEncodingISOLatin2 :
989 enc = wxFONTENCODING_ISO8859_2;
990 break ;
991 case kTextEncodingISOLatin3 :
992 enc = wxFONTENCODING_ISO8859_3 ;
993 break ;
994 case kTextEncodingISOLatin4 :
995 enc = wxFONTENCODING_ISO8859_4;
996 break ;
997 case kTextEncodingISOLatinCyrillic :
998 enc = wxFONTENCODING_ISO8859_5;
999 break ;
1000 case kTextEncodingISOLatinArabic :
1001 enc = wxFONTENCODING_ISO8859_6;
1002 break ;
1003 case kTextEncodingISOLatinGreek :
1004 enc = wxFONTENCODING_ISO8859_7;
1005 break ;
1006 case kTextEncodingISOLatinHebrew :
1007 enc = wxFONTENCODING_ISO8859_8;
1008 break ;
1009 case kTextEncodingISOLatin5 :
1010 enc = wxFONTENCODING_ISO8859_9;
1011 break ;
1012 case kTextEncodingISOLatin6 :
1013 enc = wxFONTENCODING_ISO8859_10;
1014 break ;
1015 case kTextEncodingISOLatin7 :
1016 enc = wxFONTENCODING_ISO8859_13;
1017 break ;
1018 case kTextEncodingISOLatin8 :
1019 enc = wxFONTENCODING_ISO8859_14;
1020 break ;
1021 case kTextEncodingISOLatin9 :
1022 enc =wxFONTENCODING_ISO8859_15 ;
1023 break ;
1024
1025 case kTextEncodingKOI8_R :
1026 enc = wxFONTENCODING_KOI8;
1027 break ;
1028 /*
1029 case :
1030 enc = wxFONTENCODING_BULGARIAN;
1031 break ;
1032 */
1033 case kTextEncodingDOSLatinUS :
1034 enc = wxFONTENCODING_CP437;
1035 break ;
1036 case kTextEncodingDOSLatin1 :
1037 enc = wxFONTENCODING_CP850;
1038 break ;
1039 case kTextEncodingDOSLatin2 :
1040 enc =wxFONTENCODING_CP852 ;
1041 break ;
1042 case kTextEncodingDOSCyrillic :
1043 enc = wxFONTENCODING_CP855;
1044 break ;
1045 case kTextEncodingDOSRussian :
1046 enc = wxFONTENCODING_CP866;
1047 break ;
1048 case kTextEncodingDOSThai :
1049 enc =wxFONTENCODING_CP874 ;
1050 break ;
1051 case kTextEncodingDOSJapanese :
1052 enc = wxFONTENCODING_CP932;
1053 break ;
1054 case kTextEncodingDOSChineseSimplif :
1055 enc = wxFONTENCODING_CP936;
1056 break ;
1057 case kTextEncodingDOSKorean :
1058 enc = wxFONTENCODING_CP949;
1059 break ;
1060 case kTextEncodingDOSChineseTrad :
1061 enc = wxFONTENCODING_CP950;
1062 break ;
1063
1064 case kTextEncodingWindowsLatin2 :
1065 enc = wxFONTENCODING_CP1250;
1066 break ;
1067 case kTextEncodingWindowsCyrillic :
1068 enc = wxFONTENCODING_CP1251;
1069 break ;
1070 case kTextEncodingWindowsLatin1 :
1071 enc = wxFONTENCODING_CP1252;
1072 break ;
1073 case kTextEncodingWindowsGreek :
1074 enc = wxFONTENCODING_CP1253;
1075 break ;
1076 case kTextEncodingWindowsLatin5 :
1077 enc = wxFONTENCODING_CP1254;
1078 break ;
1079 case kTextEncodingWindowsHebrew :
1080 enc = wxFONTENCODING_CP1255;
1081 break ;
1082 case kTextEncodingWindowsArabic :
1083 enc = wxFONTENCODING_CP1256;
1084 break ;
1085 case kTextEncodingWindowsBalticRim :
1086 enc =wxFONTENCODING_CP1257 ;
1087 break ;
1088 case kTextEncodingEUC_JP :
1089 enc = wxFONTENCODING_EUC_JP;
1090 break ;
1091 /*
1092 case wxFONTENCODING_UTF7 :
1093 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1094 break ;
1095 case wxFONTENCODING_UTF8 :
1096 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1097 break ;
1098 case wxFONTENCODING_UTF16BE :
1099 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1100 break ;
1101 case wxFONTENCODING_UTF16LE :
1102 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1103 break ;
1104 case wxFONTENCODING_UTF32BE :
1105 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1106 break ;
1107 case wxFONTENCODING_UTF32LE :
1108 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1109 break ;
1110 */
1111 case kTextEncodingMacRoman :
1112 enc = wxFONTENCODING_MACROMAN ;
1113 break ;
1114 case kTextEncodingMacJapanese :
1115 enc = wxFONTENCODING_MACJAPANESE ;
1116 break ;
1117 case kTextEncodingMacChineseTrad :
1118 enc = wxFONTENCODING_MACCHINESETRAD ;
1119 break ;
1120 case kTextEncodingMacKorean :
1121 enc = wxFONTENCODING_MACKOREAN ;
1122 break ;
1123 case kTextEncodingMacArabic :
1124 enc =wxFONTENCODING_MACARABIC ;
1125 break ;
1126 case kTextEncodingMacHebrew :
1127 enc = wxFONTENCODING_MACHEBREW ;
1128 break ;
1129 case kTextEncodingMacGreek :
1130 enc = wxFONTENCODING_MACGREEK ;
1131 break ;
1132 case kTextEncodingMacCyrillic :
1133 enc = wxFONTENCODING_MACCYRILLIC ;
1134 break ;
1135 case kTextEncodingMacDevanagari :
1136 enc = wxFONTENCODING_MACDEVANAGARI ;
1137 break ;
1138 case kTextEncodingMacGurmukhi :
1139 enc = wxFONTENCODING_MACGURMUKHI ;
1140 break ;
1141 case kTextEncodingMacGujarati :
1142 enc = wxFONTENCODING_MACGUJARATI ;
1143 break ;
1144 case kTextEncodingMacOriya :
1145 enc =wxFONTENCODING_MACORIYA ;
1146 break ;
1147 case kTextEncodingMacBengali :
1148 enc =wxFONTENCODING_MACBENGALI ;
1149 break ;
1150 case kTextEncodingMacTamil :
1151 enc = wxFONTENCODING_MACTAMIL ;
1152 break ;
1153 case kTextEncodingMacTelugu :
1154 enc = wxFONTENCODING_MACTELUGU ;
1155 break ;
1156 case kTextEncodingMacKannada :
1157 enc = wxFONTENCODING_MACKANNADA ;
1158 break ;
1159 case kTextEncodingMacMalayalam :
1160 enc = wxFONTENCODING_MACMALAJALAM ;
1161 break ;
1162 case kTextEncodingMacSinhalese :
1163 enc = wxFONTENCODING_MACSINHALESE ;
1164 break ;
1165 case kTextEncodingMacBurmese :
1166 enc = wxFONTENCODING_MACBURMESE ;
1167 break ;
1168 case kTextEncodingMacKhmer :
1169 enc = wxFONTENCODING_MACKHMER ;
1170 break ;
1171 case kTextEncodingMacThai :
1172 enc = wxFONTENCODING_MACTHAI ;
1173 break ;
1174 case kTextEncodingMacLaotian :
1175 enc = wxFONTENCODING_MACLAOTIAN ;
1176 break ;
1177 case kTextEncodingMacGeorgian :
1178 enc = wxFONTENCODING_MACGEORGIAN ;
1179 break ;
1180 case kTextEncodingMacArmenian :
1181 enc = wxFONTENCODING_MACARMENIAN ;
1182 break ;
1183 case kTextEncodingMacChineseSimp :
1184 enc = wxFONTENCODING_MACCHINESESIMP ;
1185 break ;
1186 case kTextEncodingMacTibetan :
1187 enc = wxFONTENCODING_MACTIBETAN ;
1188 break ;
1189 case kTextEncodingMacMongolian :
1190 enc = wxFONTENCODING_MACMONGOLIAN ;
1191 break ;
1192 case kTextEncodingMacEthiopic :
1193 enc = wxFONTENCODING_MACETHIOPIC ;
1194 break ;
1195 case kTextEncodingMacCentralEurRoman:
1196 enc = wxFONTENCODING_MACCENTRALEUR ;
1197 break ;
1198 case kTextEncodingMacVietnamese:
1199 enc = wxFONTENCODING_MACVIATNAMESE ;
1200 break ;
1201 case kTextEncodingMacExtArabic :
1202 enc = wxFONTENCODING_MACARABICEXT ;
1203 break ;
1204 case kTextEncodingMacSymbol :
1205 enc = wxFONTENCODING_MACSYMBOL ;
1206 break ;
1207 case kTextEncodingMacDingbats :
1208 enc = wxFONTENCODING_MACDINGBATS ;
1209 break ;
1210 case kTextEncodingMacTurkish :
1211 enc = wxFONTENCODING_MACTURKISH ;
1212 break ;
1213 case kTextEncodingMacCroatian :
1214 enc = wxFONTENCODING_MACCROATIAN ;
1215 break ;
1216 case kTextEncodingMacIcelandic :
1217 enc = wxFONTENCODING_MACICELANDIC ;
1218 break ;
1219 case kTextEncodingMacRomanian :
1220 enc = wxFONTENCODING_MACROMANIAN ;
1221 break ;
1222 case kTextEncodingMacCeltic :
1223 enc = wxFONTENCODING_MACCELTIC ;
1224 break ;
1225 case kTextEncodingMacGaelic :
1226 enc = wxFONTENCODING_MACGAELIC ;
1227 break ;
1228 case kTextEncodingMacKeyboardGlyphs :
1229 enc = wxFONTENCODING_MACKEYBOARD ;
1230 break ;
1231 } ;
1232 return enc ;
1233 }
1234
1235
1236 //
1237 // CFStringRefs (Carbon only)
1238 //
1239
1240 #if TARGET_CARBON
1241
1242 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1243 void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
1244 {
1245 Release() ;
1246
1247 wxString str = st ;
1248 wxMacConvertNewlines13To10( &str ) ;
1249 #if wxUSE_UNICODE
1250 #if SIZEOF_WCHAR_T == 2
1251 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
1252 (UniChar*)str.wc_str() , str.Len() );
1253 #else
1254 wxMBConvUTF16BE converter ;
1255 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1256 UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
1257 converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
1258 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
1259 unibuf , unicharlen / sizeof(UniChar) ) ;
1260 delete[] unibuf ;
1261 #endif
1262 #else // not wxUSE_UNICODE
1263 m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
1264 wxMacGetSystemEncFromFontEnc( encoding ) ) ;
1265 #endif
1266 m_release = true ;
1267 }
1268
1269 wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
1270 {
1271 Size cflen = CFStringGetLength( m_cfs ) ;
1272 size_t noChars ;
1273 wxChar* buf = NULL ;
1274
1275 #if wxUSE_UNICODE
1276 #if SIZEOF_WCHAR_T == 2
1277 buf = new wxChar[ cflen + 1 ] ;
1278 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
1279 noChars = cflen ;
1280 #else
1281 UniChar* unibuf = new UniChar[ cflen + 1 ] ;
1282 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
1283 unibuf[cflen] = 0 ;
1284 wxMBConvUTF16BE converter ;
1285 noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
1286 buf = new wxChar[ noChars + 1 ] ;
1287 converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
1288 delete[] unibuf ;
1289 #endif
1290 #else
1291 CFIndex cStrLen ;
1292 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1293 '?' , false , NULL , 0 , &cStrLen ) ;
1294 buf = new wxChar[ cStrLen + 1 ] ;
1295 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
1296 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
1297 noChars = cStrLen ;
1298 #endif
1299
1300 buf[noChars] = 0 ;
1301 wxMacConvertNewlines10To13( buf ) ;
1302 wxString result(buf) ;
1303 delete[] buf ;
1304 return result ;
1305 }
1306
1307 #endif //TARGET_CARBON
1308
1309 void wxMacConvertNewlines13To10( char * data )
1310 {
1311 char * buf = data ;
1312 while( (buf=strchr(buf,0x0d)) != NULL )
1313 {
1314 *buf = 0x0a ;
1315 buf++ ;
1316 }
1317 }
1318
1319 void wxMacConvertNewlines10To13( char * data )
1320 {
1321 char * buf = data ;
1322 while( (buf=strchr(buf,0x0a)) != NULL )
1323 {
1324 *buf = 0x0d ;
1325 buf++ ;
1326 }
1327 }
1328
1329 void wxMacConvertNewlines13To10( wxString * data )
1330 {
1331 size_t len = data->Length() ;
1332
1333 if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
1334 return ;
1335
1336 wxString temp(*data) ;
1337 wxStringBuffer buf(*data,len ) ;
1338 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1339
1340 wxMacConvertNewlines13To10( buf ) ;
1341 }
1342
1343 void wxMacConvertNewlines10To13( wxString * data )
1344 {
1345 size_t len = data->Length() ;
1346
1347 if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL)
1348 return ;
1349
1350 wxString temp(*data) ;
1351 wxStringBuffer buf(*data,len ) ;
1352 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
1353 wxMacConvertNewlines10To13( buf ) ;
1354 }
1355
1356
1357 #if wxUSE_UNICODE
1358 void wxMacConvertNewlines13To10( wxChar * data )
1359 {
1360 wxChar * buf = data ;
1361 while( (buf=wxStrchr(buf,0x0d)) != NULL )
1362 {
1363 *buf = 0x0a ;
1364 buf++ ;
1365 }
1366 }
1367
1368 void wxMacConvertNewlines10To13( wxChar * data )
1369 {
1370 wxChar * buf = data ;
1371 while( (buf=wxStrchr(buf,0x0a)) != NULL )
1372 {
1373 *buf = 0x0d ;
1374 buf++ ;
1375 }
1376 }
1377 #endif
1378
1379 // ----------------------------------------------------------------------------
1380 // Common Event Support
1381 // ----------------------------------------------------------------------------
1382
1383
1384 extern ProcessSerialNumber gAppProcess ;
1385
1386 void wxMacWakeUp()
1387 {
1388 ProcessSerialNumber psn ;
1389 Boolean isSame ;
1390 psn.highLongOfPSN = 0 ;
1391 psn.lowLongOfPSN = kCurrentProcess ;
1392 SameProcess( &gAppProcess , &psn , &isSame ) ;
1393 if ( isSame )
1394 {
1395 #if TARGET_CARBON
1396 EventRef dummyEvent ;
1397 OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(),
1398 kEventAttributeNone, &dummyEvent);
1399 if (err == noErr)
1400 {
1401 err = PostEventToQueue(GetMainEventQueue(), dummyEvent,
1402 kEventPriorityHigh);
1403 }
1404 #else
1405 PostEvent( nullEvent , 0 ) ;
1406 #endif
1407 }
1408 else
1409 {
1410 WakeUpProcess( &gAppProcess ) ;
1411 }
1412 }
1413
1414 #endif // wxUSE_BASE
1415
1416 #if wxUSE_GUI
1417
1418
1419 // ----------------------------------------------------------------------------
1420 // Carbon Event Support
1421 // ----------------------------------------------------------------------------
1422
1423
1424 OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
1425 {
1426 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ;
1427 }
1428
1429 OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
1430 {
1431 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ;
1432 }
1433
1434 // ----------------------------------------------------------------------------
1435 // Control Access Support
1436 // ----------------------------------------------------------------------------
1437
1438 void wxMacControl::Dispose()
1439 {
1440 ::DisposeControl( m_controlRef ) ;
1441 m_controlRef = NULL ;
1442 }
1443
1444 void wxMacControl::SetReference( SInt32 data )
1445 {
1446 SetControlReference( m_controlRef , data ) ;
1447 }
1448
1449 OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
1450 {
1451 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ;
1452 }
1453
1454 OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
1455 {
1456 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ;
1457 }
1458
1459 OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
1460 {
1461 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ;
1462 }
1463
1464 OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
1465 {
1466 #if TARGET_API_MAC_OSX
1467 return SendEventToEventTargetWithOptions( event,
1468 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
1469 #else
1470 #pragma unused(inOptions)
1471 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ;
1472 #endif
1473 }
1474
1475 OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
1476 {
1477 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ;
1478 event.SetParameter<HICommand>(kEventParamDirectObject,command) ;
1479 return SendEvent( event , inOptions ) ;
1480 }
1481
1482 OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
1483 {
1484 HICommand command ;
1485 memset( &command, 0 , sizeof(command) ) ;
1486 command.commandID = commandID ;
1487 return SendHICommand( command , inOptions ) ;
1488 }
1489
1490 void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
1491 {
1492 HiliteControl( m_controlRef , part ) ;
1493 unsigned long finalTicks ;
1494 Delay( ticks , &finalTicks ) ;
1495 HiliteControl( m_controlRef , kControlNoPart ) ;
1496 }
1497
1498 SInt32 wxMacControl::GetValue() const
1499 {
1500 return ::GetControl32BitValue( m_controlRef ) ;
1501 }
1502
1503 SInt32 wxMacControl::GetMaximum() const
1504 {
1505 return ::GetControl32BitMaximum( m_controlRef ) ;
1506 }
1507
1508 SInt32 wxMacControl::GetMinimum() const
1509 {
1510 return ::GetControl32BitMinimum( m_controlRef ) ;
1511 }
1512
1513 void wxMacControl::SetValue( SInt32 v )
1514 {
1515 ::SetControl32BitValue( m_controlRef , v ) ;
1516 }
1517
1518 void wxMacControl::SetMinimum( SInt32 v )
1519 {
1520 ::SetControl32BitMinimum( m_controlRef , v ) ;
1521 }
1522
1523 void wxMacControl::SetMaximum( SInt32 v )
1524 {
1525 ::SetControl32BitMaximum( m_controlRef , v ) ;
1526 }
1527
1528 void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
1529 {
1530 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
1531 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
1532 ::SetControl32BitValue( m_controlRef , value ) ;
1533 }
1534
1535 OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
1536 {
1537 return SetKeyboardFocus( GetControlOwner( m_controlRef ) ,
1538 m_controlRef , focusPart ) ;
1539 }
1540
1541 bool wxMacControl::HasFocus() const
1542 {
1543 ControlRef control ;
1544 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
1545 return control == m_controlRef ;
1546 }
1547
1548 bool wxMacControl::NeedsFocusRect() const
1549 {
1550 return false ;
1551 }
1552
1553 void wxMacControl::VisibilityChanged(bool shown)
1554 {
1555 }
1556
1557 void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
1558 {
1559 m_font = font ;
1560 ControlFontStyleRec fontStyle;
1561 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
1562 {
1563 switch( font.MacGetThemeFontID() )
1564 {
1565 case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ;
1566 case 109 /*mini font */ : fontStyle.font = -5 ; break ;
1567 case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ;
1568 default : fontStyle.font = kControlFontBigSystemFont ; break ;
1569 }
1570 fontStyle.flags = kControlUseFontMask ;
1571 }
1572 else
1573 {
1574 fontStyle.font = font.MacGetFontNum() ;
1575 fontStyle.style = font.MacGetFontStyle() ;
1576 fontStyle.size = font.MacGetFontSize() ;
1577 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ;
1578 }
1579
1580 fontStyle.just = teJustLeft ;
1581 fontStyle.flags |= kControlUseJustMask ;
1582 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
1583 fontStyle.just = teJustCenter ;
1584 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
1585 fontStyle.just = teJustRight ;
1586
1587
1588 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1589 // won't get grayed out by the system anymore
1590
1591 if ( foreground != *wxBLACK )
1592 {
1593 fontStyle.foreColor = MAC_WXCOLORREF(foreground.GetPixel() ) ;
1594 fontStyle.flags |= kControlUseForeColorMask ;
1595 }
1596
1597 ::SetControlFontStyle( m_controlRef , &fontStyle );
1598 }
1599
1600 void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
1601 {
1602 // TODO
1603 // setting up a color proc is not recommended anymore
1604 }
1605
1606 void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
1607 {
1608 ::SetControl32BitMinimum( m_controlRef , minimum ) ;
1609 ::SetControl32BitMaximum( m_controlRef , maximum ) ;
1610 }
1611
1612 short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
1613 {
1614 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ) ;
1615 }
1616
1617 void wxMacControl::SetActionProc( ControlActionUPP actionProc )
1618 {
1619 SetControlAction( m_controlRef , actionProc ) ;
1620 }
1621
1622 void wxMacControl::SetViewSize( SInt32 viewSize )
1623 {
1624 SetControlViewSize(m_controlRef , viewSize ) ;
1625 }
1626
1627 SInt32 wxMacControl::GetViewSize() const
1628 {
1629 return GetControlViewSize( m_controlRef ) ;
1630 }
1631
1632 bool wxMacControl::IsVisible() const
1633 {
1634 return IsControlVisible( m_controlRef ) ;
1635 }
1636
1637 void wxMacControl::SetVisibility( bool visible , bool redraw )
1638 {
1639 SetControlVisibility( m_controlRef , visible , redraw ) ;
1640 }
1641
1642 bool wxMacControl::IsEnabled() const
1643 {
1644 #if TARGET_API_MAC_OSX
1645 return IsControlEnabled( m_controlRef ) ;
1646 #else
1647 return IsControlActive( m_controlRef ) ;
1648 #endif
1649 }
1650
1651 bool wxMacControl::IsActive() const
1652 {
1653 return IsControlActive( m_controlRef ) ;
1654 }
1655
1656 void wxMacControl::Enable( bool enable )
1657 {
1658 #if TARGET_API_MAC_OSX
1659 if ( enable )
1660 EnableControl( m_controlRef ) ;
1661 else
1662 DisableControl( m_controlRef ) ;
1663 #else
1664 if ( enable )
1665 ActivateControl( m_controlRef ) ;
1666 else
1667 DeactivateControl( m_controlRef ) ;
1668 #endif
1669 }
1670
1671 void wxMacControl::SetDrawingEnabled( bool enable )
1672 {
1673 #if TARGET_API_MAC_OSX
1674 HIViewSetDrawingEnabled( m_controlRef , enable ) ;
1675 #endif
1676 }
1677
1678 bool wxMacControl::GetNeedsDisplay() const
1679 {
1680 #if TARGET_API_MAC_OSX
1681 return HIViewGetNeedsDisplay( m_controlRef ) ;
1682 #else
1683 return false ;
1684 #endif
1685 }
1686
1687 void wxMacControl::SetNeedsDisplay( bool needsDisplay , RgnHandle where )
1688 {
1689 #if TARGET_API_MAC_OSX
1690 if ( where != NULL )
1691 HIViewSetNeedsDisplayInRegion( m_controlRef , where , needsDisplay ) ;
1692 else
1693 HIViewSetNeedsDisplay( m_controlRef , needsDisplay ) ;
1694 #endif
1695 }
1696
1697 void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
1698 {
1699 #if TARGET_API_MAC_OSX
1700 HIPoint hiPoint ;
1701 hiPoint.x = pt->x ;
1702 hiPoint.y = pt->y ;
1703 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ) ;
1704 pt->x = (int)hiPoint.x ;
1705 pt->y = (int)hiPoint.y ;
1706 #endif
1707 }
1708
1709 void wxMacControl::SetRect( Rect *r )
1710 {
1711 #if TARGET_API_MAC_OSX
1712 HIRect hir = { r->left , r->top , r->right - r->left , r->bottom - r->top } ;
1713 HIViewSetFrame ( m_controlRef , &hir ) ;
1714 #else
1715 SetControlBounds( m_controlRef , r ) ;
1716 #endif
1717
1718 }
1719
1720 void wxMacControl::GetRect( Rect *r )
1721 {
1722 GetControlBounds( m_controlRef , r ) ;
1723 }
1724
1725 void wxMacControl::GetRectInWindowCoords( Rect *r )
1726 {
1727 UMAGetControlBoundsInWindowCoords( m_controlRef , r ) ;
1728 }
1729
1730 void wxMacControl::GetBestRect( Rect *r )
1731 {
1732 short baselineoffset ;
1733 GetBestControlRect( m_controlRef , r , &baselineoffset ) ;
1734 }
1735
1736 void wxMacControl::SetTitle( const wxString &title )
1737 {
1738 UMASetControlTitle( m_controlRef , title , m_font.GetEncoding() ) ;
1739 }
1740
1741 void wxMacControl::GetFeatures( UInt32 * features )
1742 {
1743 GetControlFeatures( m_controlRef , features ) ;
1744 }
1745
1746 OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
1747 {
1748 return GetControlRegion( m_controlRef , partCode , region ) ;
1749 }
1750
1751 OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
1752 {
1753 #if TARGET_API_MAC_OSX
1754 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
1755 (other != NULL) ? other->m_controlRef : NULL) ;
1756 #else
1757 return 0 ;
1758 #endif
1759 }
1760
1761
1762 #if TARGET_API_MAC_OSX
1763 // SetNeedsDisplay would not invalidate the children
1764 static void InvalidateControlAndChildren( HIViewRef control )
1765 {
1766 HIViewSetNeedsDisplay( control , true ) ;
1767 UInt16 childrenCount = 0 ;
1768 OSStatus err = CountSubControls( control , &childrenCount ) ;
1769 if ( err == errControlIsNotEmbedder )
1770 return ;
1771 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ;
1772
1773 for ( UInt16 i = childrenCount ; i >=1 ; --i )
1774 {
1775 HIViewRef child ;
1776 err = GetIndexedSubControl( control , i , & child ) ;
1777 if ( err == errControlIsNotEmbedder )
1778 return ;
1779 InvalidateControlAndChildren( child ) ;
1780 }
1781 }
1782 #endif
1783
1784 void wxMacControl::InvalidateWithChildren()
1785 {
1786 #if TARGET_API_MAC_OSX
1787 InvalidateControlAndChildren( m_controlRef ) ;
1788 #endif
1789 }
1790
1791 void wxMacControl::ScrollRect( const wxRect &r , int dx , int dy )
1792 {
1793 #if TARGET_API_MAC_OSX
1794 HIRect scrollarea = CGRectMake( r.x , r.y , r.width , r.height) ;
1795 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ;
1796 #endif
1797 }
1798
1799
1800 // SetNeedsDisplay would not invalidate the children
1801
1802 //
1803 // Databrowser
1804 //
1805
1806 OSStatus wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options )
1807 {
1808 return SetDataBrowserSelectionFlags( m_controlRef , options ) ;
1809 }
1810
1811 OSStatus wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc,
1812 DataBrowserTableViewColumnIndex position )
1813 {
1814 return AddDataBrowserListViewColumn( m_controlRef , columnDesc, position ) ;
1815 }
1816
1817 OSStatus wxMacControl::AutoSizeListViewColumns()
1818 {
1819 return AutoSizeDataBrowserListViewColumns(m_controlRef) ;
1820 }
1821
1822 OSStatus wxMacControl::SetHasScrollBars( bool horiz , bool vert )
1823 {
1824 return SetDataBrowserHasScrollBars( m_controlRef , horiz , vert ) ;
1825 }
1826
1827 OSStatus wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1828 {
1829 return SetDataBrowserTableViewHiliteStyle( m_controlRef , hiliteStyle ) ;
1830 }
1831
1832 OSStatus wxMacControl::SetListViewHeaderBtnHeight(UInt16 height)
1833 {
1834 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef ,height ) ;
1835 }
1836
1837 OSStatus wxMacControl::SetCallbacks(const DataBrowserCallbacks * callbacks)
1838 {
1839 return SetDataBrowserCallbacks( m_controlRef , callbacks ) ;
1840 }
1841
1842 OSStatus wxMacControl::UpdateItems( DataBrowserItemID container, UInt32 numItems,
1843 const DataBrowserItemID* items,
1844 DataBrowserPropertyID preSortProperty,
1845 DataBrowserPropertyID propertyID )
1846 {
1847 return UpdateDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty, propertyID ) ;
1848 }
1849
1850 bool wxMacControl::IsItemSelected( DataBrowserItemID item )
1851 {
1852 return IsDataBrowserItemSelected( m_controlRef , item ) ;
1853 }
1854
1855 OSStatus wxMacControl::AddItems( DataBrowserItemID container, UInt32 numItems,
1856 const DataBrowserItemID* items,
1857 DataBrowserPropertyID preSortProperty )
1858 {
1859 return AddDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ;
1860 }
1861
1862 OSStatus wxMacControl::RemoveItems( DataBrowserItemID container, UInt32 numItems,
1863 const DataBrowserItemID* items,
1864 DataBrowserPropertyID preSortProperty )
1865 {
1866 return RemoveDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ;
1867 }
1868
1869 OSStatus wxMacControl::RevealItem( DataBrowserItemID item,
1870 DataBrowserPropertyID propertyID,
1871 DataBrowserRevealOptions options )
1872 {
1873 return RevealDataBrowserItem( m_controlRef , item , propertyID , options ) ;
1874 }
1875
1876 OSStatus wxMacControl::SetSelectedItems(UInt32 numItems,
1877 const DataBrowserItemID * items,
1878 DataBrowserSetOption operation )
1879 {
1880 return SetDataBrowserSelectedItems( m_controlRef , numItems , items, operation ) ;
1881 }
1882
1883 //
1884 // Tab Control
1885 //
1886
1887 OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
1888 {
1889 return ::SetTabEnabled( m_controlRef , tabNo , enable ) ;
1890 }
1891
1892 #endif // wxUSE_GUI
1893