]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/app.cpp
moving constructors to .cpp
[wxWidgets.git] / src / mac / carbon / app.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
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#pragma implementation "app.h"
14#endif
15
16#include "wx/defs.h"
17
18#include "wx/window.h"
19#include "wx/frame.h"
20#include "wx/button.h"
21#include "wx/app.h"
22#include "wx/utils.h"
23#include "wx/gdicmn.h"
24#include "wx/pen.h"
25#include "wx/brush.h"
26#include "wx/cursor.h"
27#include "wx/intl.h"
28#include "wx/icon.h"
29#include "wx/palette.h"
30#include "wx/dc.h"
31#include "wx/dialog.h"
32#include "wx/msgdlg.h"
33#include "wx/log.h"
34#include "wx/module.h"
35#include "wx/memory.h"
36#include "wx/tooltip.h"
37#include "wx/textctrl.h"
38#include "wx/menu.h"
39#include "wx/docview.h"
40#include "wx/filename.h"
41
42#include <string.h>
43
44// mac
45
46#ifndef __DARWIN__
47 #if __option(profile)
48 #include <profiler.h>
49 #endif
50#endif
51
52// #include "apprsrc.h"
53
54#include "wx/mac/uma.h"
55#include "wx/mac/macnotfy.h"
56
57#ifdef __DARWIN__
58# include <CoreServices/CoreServices.h>
59# if defined(WXMAKINGDLL_CORE)
60# include <mach-o/dyld.h>
61# endif
62#else
63# include <Sound.h>
64# include <Threads.h>
65# include <ToolUtils.h>
66# include <DiskInit.h>
67# include <Devices.h>
68#endif
69
70extern wxList wxPendingDelete;
71
72// set wxMAC_USE_RAEL to 1 if RunApplicationEventLoop should be used
73// if 0 the lower level CarbonEventLoop will be used
74// on the long run RAEL should replace the low level event loop
75// we will have to clean up event handling to make sure we don't
76// miss handling of things like pending events etc
77// perhaps we will also have to pipe events through an ueber-event-handler
78// to make sure we have one place to do all these house-keeping functions
79
80#define wxMAC_USE_RAEL 0
81
82#if wxUSE_THREADS
83extern size_t g_numberOfThreads;
84#endif // wxUSE_THREADS
85
86// statics for implementation
87
88static bool s_inYield = FALSE;
89
90static bool s_inReceiveEvent = FALSE ;
91static EventTime sleepTime = kEventDurationNoWait ;
92
93#if !USE_SHARED_LIBRARY
94IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
95BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
96 EVT_IDLE(wxApp::OnIdle)
97 EVT_END_SESSION(wxApp::OnEndSession)
98 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
99END_EVENT_TABLE()
100#endif
101
102
103const short kMacMinHeap = (29 * 1024) ;
104// platform specific static variables
105
106const short kwxMacMenuBarResource = 1 ;
107const short kwxMacAppleMenuId = 1 ;
108
109WXHRGN wxApp::s_macCursorRgn = NULL;
110wxWindow* wxApp::s_captureWindow = NULL ;
111int wxApp::s_lastMouseDown = 0 ;
112long wxApp::sm_lastMessageTime = 0;
113long wxApp::s_lastModifiers = 0 ;
114
115
116bool wxApp::s_macSupportPCMenuShortcuts = true ;
117long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
118long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ;
119long wxApp::s_macExitMenuItemId = wxID_EXIT ;
120wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ;
121
122// Normally we're not a plugin
123bool wxApp::sm_isEmbedded = false;
124//----------------------------------------------------------------------
125// Core Apple Event Support
126//----------------------------------------------------------------------
127
128pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
129pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
130pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
131pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
132pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
133
134pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
135{
136 return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
137}
138
139pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
140{
141 return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
142}
143
144pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
145{
146 return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
147}
148
149pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
150{
151 return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
152}
153
154pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
155{
156 return wxTheApp->MacHandleAERApp( (AppleEvent*) event , reply) ;
157}
158
159// AEODoc Calls MacOpenFile on each of the files passed
160
161short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
162{
163 AEDescList docList;
164 AEKeyword keywd;
165 DescType returnedType;
166 Size actualSize;
167 long itemsInList;
168 FSSpec theSpec;
169 OSErr err;
170 short i;
171 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
172 if (err != noErr)
173 return err;
174
175 err = AECountItems(&docList, &itemsInList);
176 if (err != noErr)
177 return err;
178
179 ProcessSerialNumber PSN ;
180 PSN.highLongOfPSN = 0 ;
181 PSN.lowLongOfPSN = kCurrentProcess ;
182 SetFrontProcess( &PSN ) ;
183
184 for (i = 1; i <= itemsInList; i++) {
185 AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
186 (Ptr) & theSpec, sizeof(theSpec), &actualSize);
187 wxString fName = wxMacFSSpec2MacFilename(&theSpec);
188 MacOpenFile(fName);
189 }
190 return noErr;
191}
192
193// AEPDoc Calls MacPrintFile on each of the files passed
194
195short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply))
196{
197 AEDescList docList;
198 AEKeyword keywd;
199 DescType returnedType;
200 Size actualSize;
201 long itemsInList;
202 FSSpec theSpec;
203 OSErr err;
204 short i;
205 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
206 if (err != noErr)
207 return err;
208
209 err = AECountItems(&docList, &itemsInList);
210 if (err != noErr)
211 return err;
212
213 ProcessSerialNumber PSN ;
214 PSN.highLongOfPSN = 0 ;
215 PSN.lowLongOfPSN = kCurrentProcess ;
216 SetFrontProcess( &PSN ) ;
217
218 for (i = 1; i <= itemsInList; i++) {
219 AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
220 (Ptr) & theSpec, sizeof(theSpec), &actualSize);
221 wxString fName = wxMacFSSpec2MacFilename(&theSpec);
222 MacPrintFile(fName);
223 }
224 return noErr;
225}
226
227// AEOApp calls MacNewFile
228
229short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
230{
231 MacNewFile() ;
232 return noErr ;
233}
234
235// AEQuit attempts to quit the application
236
237short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
238{
239 wxWindow* win = GetTopWindow() ;
240 if ( win )
241 {
242 wxCommandEvent exitEvent(wxEVT_COMMAND_MENU_SELECTED, s_macExitMenuItemId);
243 if (!win->ProcessEvent(exitEvent))
244 win->Close(TRUE ) ;
245 }
246 else
247 {
248 ExitMainLoop() ;
249 }
250 return noErr ;
251}
252
253// AEROApp calls MacReopenApp
254
255short wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
256{
257 MacReopenApp() ;
258 return noErr ;
259}
260
261
262//----------------------------------------------------------------------
263// Support Routines linking the Mac...File Calls to the Document Manager
264//----------------------------------------------------------------------
265
266void wxApp::MacOpenFile(const wxString & fileName )
267{
268 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
269 if ( dm )
270 dm->CreateDocument(fileName , wxDOC_SILENT ) ;
271}
272
273void wxApp::MacPrintFile(const wxString & fileName )
274{
275 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
276 if ( dm )
277 {
278 wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ;
279 if ( doc )
280 {
281 wxView* view = doc->GetFirstView() ;
282 if( view )
283 {
284 wxPrintout *printout = view->OnCreatePrintout();
285 if (printout)
286 {
287 wxPrinter printer;
288 printer.Print(view->GetFrame(), printout, TRUE);
289 delete printout;
290 }
291 }
292 if (doc->Close())
293 {
294 doc->DeleteAllViews();
295 dm->RemoveDocument(doc) ;
296 }
297 }
298 }
299}
300
301void wxApp::MacNewFile()
302{
303}
304
305void wxApp::MacReopenApp()
306{
307 // eventually check for open docs, if none, call MacNewFile
308 wxTopLevelWindowMac* topLevelWindow = wxDynamicCast(GetTopWindow(), wxTopLevelWindowMac);
309
310 if (topLevelWindow && topLevelWindow->IsIconized())
311 topLevelWindow->Iconize(false);
312}
313
314//----------------------------------------------------------------------
315// Carbon Event Handler
316//----------------------------------------------------------------------
317
318static const EventTypeSpec eventList[] =
319{
320 { kEventClassCommand, kEventProcessCommand } ,
321 { kEventClassCommand, kEventCommandUpdateStatus } ,
322
323 { kEventClassMenu, kEventMenuOpening },
324 { kEventClassMenu, kEventMenuClosed },
325 { kEventClassMenu, kEventMenuTargetItem },
326
327 { kEventClassApplication , kEventAppActivated } ,
328 { kEventClassApplication , kEventAppDeactivated } ,
329 // handling the quit event is not recommended by apple
330 // rather using the quit apple event - which we do
331
332 { kEventClassAppleEvent , kEventAppleEvent } ,
333
334 { kEventClassMouse , kEventMouseDown } ,
335 { kEventClassMouse , kEventMouseMoved } ,
336 { kEventClassMouse , kEventMouseUp } ,
337 { kEventClassMouse , kEventMouseDragged } ,
338 { 'WXMC' , 'WXMC' }
339} ;
340
341static pascal OSStatus
342wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
343{
344 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
345 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
346 wxTheApp->MacSetCurrentEvent( event , handler ) ;
347
348 wxMacCarbonEvent cEvent( event ) ;
349 MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;
350 wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;
351
352 if ( menu )
353 {
354 wxEventType type=0;
355 MenuCommand cmd=0;
356 switch (GetEventKind(event))
357 {
358 case kEventMenuOpening:
359 type = wxEVT_MENU_OPEN;
360 break;
361 case kEventMenuClosed:
362 type = wxEVT_MENU_CLOSE;
363 break;
364 case kEventMenuTargetItem:
365 cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
366 if (cmd != 0)
367 type = wxEVT_MENU_HIGHLIGHT;
368 break;
369 default:
370 wxFAIL_MSG(wxT("Unexpected menu event kind"));
371 break;
372 }
373
374 if ( type )
375 {
376 wxMenuEvent wxevent(type, cmd);
377 wxevent.SetEventObject(menu);
378
379 wxEvtHandler* handler = menu->GetEventHandler();
380 if (handler && handler->ProcessEvent(wxevent))
381 {
382 // handled
383 }
384 else
385 {
386 wxWindow *win = menu->GetInvokingWindow();
387 if (win)
388 win->GetEventHandler()->ProcessEvent(wxevent);
389 }
390 }
391 }
392
393 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
394
395 return eventNotHandledErr;
396}
397
398static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
399{
400 OSStatus result = eventNotHandledErr ;
401
402 HICommand command ;
403
404 wxMacCarbonEvent cEvent( event ) ;
405 cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;
406
407 wxMenuItem* item = NULL ;
408 MenuCommand id = command.commandID ;
409 // for items we don't really control
410 if ( id == kHICommandPreferences )
411 {
412 id = wxApp::s_macPreferencesMenuItemId ;
413
414 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
415 if ( mbar )
416 {
417 wxMenu* menu = NULL ;
418 item = mbar->FindItem( id , &menu ) ;
419 }
420 }
421 else if ( id != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 )
422 {
423 GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , (UInt32*) &item ) ;
424 }
425
426 if ( item )
427 {
428 switch( cEvent.GetKind() )
429 {
430 case kEventProcessCommand :
431 {
432 if (item->IsCheckable())
433 {
434 item->Check( !item->IsChecked() ) ;
435 }
436
437 item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
438 result = noErr ;
439 }
440 break ;
441 case kEventCommandUpdateStatus:
442 // eventually trigger an updateui round
443 result = noErr ;
444 break ;
445 default :
446 break ;
447 }
448 }
449 return result ;
450}
451
452static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
453{
454 OSStatus result = eventNotHandledErr ;
455 switch ( GetEventKind( event ) )
456 {
457 case kEventAppActivated :
458 {
459 if ( wxTheApp )
460 wxTheApp->SetActive( true , NULL ) ;
461 result = noErr ;
462 }
463 break ;
464 case kEventAppDeactivated :
465 {
466 if ( wxTheApp )
467 wxTheApp->SetActive( false , NULL ) ;
468 result = noErr ;
469 }
470 break ;
471 default :
472 break ;
473 }
474 return result ;
475}
476
477pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
478{
479 OSStatus result = eventNotHandledErr ;
480 switch( GetEventClass( event ) )
481 {
482 case kEventClassCommand :
483 result = wxMacAppCommandEventHandler( handler , event , data ) ;
484 break ;
485 case kEventClassApplication :
486 result = wxMacAppApplicationEventHandler( handler , event , data ) ;
487 break ;
488 case kEventClassMenu :
489 result = wxMacAppMenuEventHandler( handler , event , data ) ;
490 break ;
491 case kEventClassMouse :
492 result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
493 break ;
494 case kEventClassAppleEvent :
495 {
496 EventRecord rec ;
497 wxMacConvertEventToRecord( event , &rec ) ;
498 result = AEProcessAppleEvent( &rec ) ;
499 }
500 break ;
501 default :
502 break ;
503 }
504
505 return result ;
506}
507
508DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler )
509
510#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
511// we know it's there ;-)
512WXIMPORT char std::__throws_bad_alloc ;
513#endif
514
515pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options,
516 const char *assertionString, const char *exceptionLabelString,
517 const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg)
518{
519 // flow into assert handling
520 wxString fileNameStr ;
521 wxString assertionStr ;
522 wxString exceptionStr ;
523 wxString errorStr ;
524#if wxUSE_UNICODE
525 fileNameStr = wxString(fileName, wxConvLocal);
526 assertionStr = wxString(assertionString, wxConvLocal);
527 exceptionStr = wxString((exceptionLabelString!=0) ? exceptionLabelString : "", wxConvLocal) ;
528 errorStr = wxString((errorString!=0) ? errorString : "", wxConvLocal) ;
529#else
530 fileNameStr = fileName;
531 assertionStr = assertionString;
532 exceptionStr = (exceptionLabelString!=0) ? exceptionLabelString : "" ;
533 errorStr = (errorString!=0) ? errorString : "" ;
534#endif
535
536#if 1
537 // flow into log
538 wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %ld (value %p)\n"),
539 assertionStr.c_str() ,
540 exceptionStr.c_str() ,
541 errorStr.c_str(),
542 fileNameStr.c_str(), lineNumber ,
543 value ) ;
544#else
545
546 wxOnAssert(fileNameStr, lineNumber , assertionStr ,
547 wxString::Format( wxT("%s %s value (%p)") ,exceptionStr, errorStr , value ) ) ;
548#endif
549}
550
551bool wxApp::Initialize(int& argc, wxChar **argv)
552{
553 // Mac-specific
554
555#if __WXDEBUG__
556 InstallDebugAssertOutputHandler ( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );
557#endif
558 UMAInitToolbox( 4, sm_isEmbedded ) ;
559 SetEventMask( everyEvent ) ;
560 UMAShowWatchCursor() ;
561
562#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
563 // open shared library resources from here since we don't have
564 // __wxinitialize in Mach-O shared libraries
565 wxStAppResource::OpenSharedLibraryResource(NULL);
566#endif
567
568#ifndef __DARWIN__
569# if __option(profile)
570 ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ;
571# endif
572#endif
573
574#ifndef __DARWIN__
575 // now avoid exceptions thrown for new (bad_alloc)
576 // FIXME CS for some changes outside wxMac does not compile anymore
577#if 0
578 std::__throws_bad_alloc = 0 ;
579#endif
580
581#endif
582
583 s_macCursorRgn = ::NewRgn() ;
584
585 // Mac OS X passes a process serial number command line argument when
586 // the application is launched from the Finder. This argument must be
587 // removed from the command line arguments before being handled by the
588 // application (otherwise applications would need to handle it)
589 if ( argc > 1 )
590 {
591 static const wxChar *ARG_PSN = _T("-psn_");
592 if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 )
593 {
594 // remove this argument
595 --argc;
596 memmove(argv + 1, argv + 2, argc * sizeof(char *));
597 }
598 }
599
600 if ( !wxAppBase::Initialize(argc, argv) )
601 return false;
602
603#if wxUSE_INTL
604 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
605#endif
606
607
608 wxMacCreateNotifierTable() ;
609
610 UMAShowArrowCursor() ;
611
612 return true;
613}
614
615bool wxApp::OnInitGui()
616{
617 if( !wxAppBase::OnInitGui() )
618 return false ;
619
620 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
621
622 if (!sm_isEmbedded)
623 {
624 InstallApplicationEventHandler(
625 GetwxMacAppEventHandlerUPP(),
626 GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler));
627 }
628
629 if (!sm_isEmbedded)
630 {
631 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
632 NewAEEventHandlerUPP(AEHandleODoc) ,
633 0 , FALSE ) ;
634 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
635 NewAEEventHandlerUPP(AEHandleOApp) ,
636 0 , FALSE ) ;
637 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
638 NewAEEventHandlerUPP(AEHandlePDoc) ,
639 0 , FALSE ) ;
640 AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,
641 NewAEEventHandlerUPP(AEHandleRApp) ,
642 0 , FALSE ) ;
643 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
644 NewAEEventHandlerUPP(AEHandleQuit) ,
645 0 , FALSE ) ;
646 }
647
648 return TRUE ;
649}
650
651void wxApp::CleanUp()
652{
653 wxToolTip::RemoveToolTips() ;
654
655 // One last chance for pending objects to be cleaned up
656 wxTheApp->DeletePendingObjects();
657
658 wxMacDestroyNotifierTable() ;
659
660#ifndef __DARWIN__
661# if __option(profile)
662 ProfilerDump( (StringPtr)"\papp.prof" ) ;
663 ProfilerTerm() ;
664# endif
665#endif
666
667#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
668 // close shared library resources from here since we don't have
669 // __wxterminate in Mach-O shared libraries
670 wxStAppResource::CloseSharedLibraryResource();
671#endif
672
673 UMACleanupToolbox() ;
674 if (s_macCursorRgn) {
675 ::DisposeRgn((RgnHandle)s_macCursorRgn);
676 }
677
678 #if 0
679 TerminateAE() ;
680 #endif
681
682 wxAppBase::CleanUp();
683}
684
685//----------------------------------------------------------------------
686// misc initialization stuff
687//----------------------------------------------------------------------
688
689// extern variable for shared library resource id
690// need to be able to find it with NSLookupAndBindSymbol
691short gSharedLibraryResource = kResFileNotOpened ;
692
693#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
694CFBundleRef gSharedLibraryBundle = NULL;
695#endif /* WXMAKINGDLL_CORE && __DARWIN__ */
696
697wxStAppResource::wxStAppResource()
698{
699 m_currentRefNum = CurResFile() ;
700 if ( gSharedLibraryResource != kResFileNotOpened )
701 {
702 UseResFile( gSharedLibraryResource ) ;
703 }
704}
705
706wxStAppResource::~wxStAppResource()
707{
708 if ( m_currentRefNum != kResFileNotOpened )
709 {
710 UseResFile( m_currentRefNum ) ;
711 }
712}
713
714void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
715{
716 gSharedLibraryResource = kResFileNotOpened;
717
718#ifdef WXMAKINGDLL_CORE
719 if ( initBlock != NULL ) {
720 const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
721 FSSpec *fileSpec = NULL;
722
723 if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
724 fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;
725 }
726 else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {
727 fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;
728 }
729
730 if (fileSpec != NULL) {
731 gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm);
732 }
733 }
734 else {
735#ifdef __DARWIN__
736 // Open the shared library resource file if it is not yet open
737 NSSymbol theSymbol;
738 NSModule theModule;
739 const char *theLibPath;
740
741 gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));
742 if (gSharedLibraryBundle != NULL) {
743 // wxWidgets has been bundled into a framework
744 // load the framework resources
745
746 gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
747 }
748 else {
749 // wxWidgets is a simple dynamic shared library
750 // load the resources from the data fork of a separate resource file
751 wxString theResPath;
752 wxString theName;
753 FSRef theResRef;
754 OSErr theErr = noErr;
755
756 // get the library path
757 theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
758 theModule = NSModuleForSymbol(theSymbol);
759 theLibPath = NSLibraryNameForModule(theModule);
760
761 // if we call wxLogDebug from here then, as wxTheApp hasn't been
762 // created yet when we're called from wxApp::Initialize(), wxLog
763 // is going to create a default stderr-based log target instead of
764 // the expected normal GUI one -- don't do it, if we really want
765 // to see this message just use fprintf() here
766#if 0
767 wxLogDebug( wxT("wxMac library installation name is '%s'"),
768 theLibPath );
769#endif
770
771 // allocate copy to replace .dylib.* extension with .rsrc
772 if (theLibPath != NULL) {
773#if wxUSE_UNICODE
774 theResPath = wxString(theLibPath, wxConvLocal);
775#else
776 theResPath = wxString(theLibPath);
777#endif
778 // replace '_core' with '' in case of multi-lib build
779 theResPath.Replace(wxT("_core"), wxEmptyString);
780 // replace ".dylib" shared library extension with ".rsrc"
781 theResPath.Replace(wxT(".dylib"), wxT(".rsrc"));
782 // Find the begining of the filename
783 theName = theResPath.AfterLast('/');
784
785#if 0
786 wxLogDebug( wxT("wxMac resources file name is '%s'"),
787 theResPath.mb_str() );
788#endif
789
790 theErr = FSPathMakeRef((UInt8 *) theResPath.mb_str(), &theResRef, false);
791 if (theErr != noErr) {
792 // try in current directory (using name only)
793 theErr = FSPathMakeRef((UInt8 *) theName.mb_str(), &theResRef, false);
794 }
795
796 // open the resource file
797 if (theErr == noErr) {
798 theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
799 &gSharedLibraryResource);
800 }
801 if (theErr != noErr) {
802#ifdef __WXDEBUG__
803 wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
804 theResPath.mb_str() );
805#endif // __WXDEBUG__
806 }
807
808 }
809 }
810#endif /* __DARWIN__ */
811 }
812#endif /* WXMAKINGDLL_CORE */
813}
814
815void wxStAppResource::CloseSharedLibraryResource()
816{
817#ifdef WXMAKINGDLL_CORE
818 // Close the shared library resource file
819 if (gSharedLibraryResource != kResFileNotOpened) {
820#ifdef __DARWIN__
821 if (gSharedLibraryBundle != NULL) {
822 CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
823 gSharedLibraryResource);
824 gSharedLibraryBundle = NULL;
825 }
826 else
827#endif /* __DARWIN__ */
828 {
829 CloseResFile(gSharedLibraryResource);
830 }
831 gSharedLibraryResource = kResFileNotOpened;
832 }
833#endif /* WXMAKINGDLL_CORE */
834}
835
836#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
837
838// for shared libraries we have to manually get the correct resource
839// ref num upon initializing and releasing when terminating, therefore
840// the __wxinitialize and __wxterminate must be used
841
842extern "C" {
843 void __sinit(void); /* (generated by linker) */
844 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
845 pascal void __terminate(void);
846}
847
848pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
849{
850 wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
851 return __initialize( theInitBlock ) ;
852}
853
854pascal void __wxterminate(void)
855{
856 wxStAppResource::CloseSharedLibraryResource() ;
857 __terminate() ;
858}
859
860#endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
861
862bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
863{
864 bool converted = ConvertEventRefToEventRecord( event,rec) ;
865 OSStatus err = noErr ;
866 if ( !converted )
867 {
868 switch( GetEventClass( event ) )
869 {
870 case kEventClassKeyboard :
871 {
872 converted = true ;
873 switch( GetEventKind(event) )
874 {
875 case kEventRawKeyDown :
876 rec->what = keyDown ;
877 break ;
878 case kEventRawKeyRepeat :
879 rec->what = autoKey ;
880 break ;
881 case kEventRawKeyUp :
882 rec->what = keyUp ;
883 break ;
884 case kEventRawKeyModifiersChanged :
885 rec->what = nullEvent ;
886 break ;
887 default :
888 converted = false ;
889 break ;
890 }
891 if ( converted )
892 {
893 UInt32 keyCode ;
894 unsigned char charCode ;
895 UInt32 modifiers ;
896 GetMouse( &rec->where) ;
897
898 err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
899 err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
900 err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
901 rec->modifiers = modifiers ;
902 rec->message = (keyCode << 8 ) + charCode ;
903 }
904 }
905 break ;
906 case kEventClassTextInput :
907 {
908 switch( GetEventKind( event ) )
909 {
910 case kEventTextInputUnicodeForKeyEvent :
911 {
912 EventRef rawEvent ;
913 err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
914 converted = true ;
915 {
916 UInt32 keyCode ;
917 unsigned char charCode ;
918 UInt32 modifiers ;
919 GetMouse( &rec->where) ;
920 rec->what = keyDown ;
921 err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
922 err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
923 err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
924 rec->modifiers = modifiers ;
925 rec->message = (keyCode << 8 ) + charCode ;
926 }
927 }
928 break ;
929 default :
930 break ;
931 }
932 }
933 break ;
934 }
935 }
936
937 return converted ;
938}
939
940wxApp::wxApp()
941{
942 m_printMode = wxPRINT_WINDOWS;
943
944 m_macCurrentEvent = NULL ;
945 m_macCurrentEventHandlerCallRef = NULL ;
946}
947
948int wxApp::MainLoop()
949{
950 m_keepGoing = TRUE;
951#if wxMAC_USE_RAEL
952 RunApplicationEventLoop() ;
953#else
954 while (m_keepGoing)
955 {
956 MacDoOneEvent() ;
957 }
958#endif
959 return 0;
960}
961
962void wxApp::ExitMainLoop()
963{
964 m_keepGoing = FALSE;
965#if wxMAC_USE_RAEL
966 QuitApplicationEventLoop() ;
967#endif
968}
969
970// Is a message/event pending?
971bool wxApp::Pending()
972{
973 // without the receive event (with pull param = false ) nothing is ever reported
974 EventRef theEvent;
975 ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &theEvent);
976 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
977}
978
979// Dispatch a message.
980bool wxApp::Dispatch()
981{
982 MacDoOneEvent() ;
983
984 return true;
985}
986
987void wxApp::OnIdle(wxIdleEvent& event)
988{
989 wxAppBase::OnIdle(event);
990
991 // If they are pending events, we must process them: pending events are
992 // either events to the threads other than main or events posted with
993 // wxPostEvent() functions
994 wxMacProcessNotifierAndPendingEvents();
995
996 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
997 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
998}
999
1000void wxApp::WakeUpIdle()
1001{
1002 wxMacWakeUp() ;
1003}
1004
1005void wxApp::Exit()
1006{
1007 wxApp::CleanUp();
1008 ::ExitToShell() ;
1009}
1010
1011void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1012{
1013 if (GetTopWindow())
1014 GetTopWindow()->Close(TRUE);
1015}
1016
1017// Default behaviour: close the application with prompts. The
1018// user can veto the close, and therefore the end session.
1019void wxApp::OnQueryEndSession(wxCloseEvent& event)
1020{
1021 if (GetTopWindow())
1022 {
1023 if (!GetTopWindow()->Close(!event.CanVeto()))
1024 event.Veto(TRUE);
1025 }
1026}
1027
1028extern "C" void wxCYield() ;
1029void wxCYield()
1030{
1031 wxYield() ;
1032}
1033
1034// Yield to other processes
1035
1036bool wxApp::Yield(bool onlyIfNeeded)
1037{
1038 if (s_inYield)
1039 {
1040 if ( !onlyIfNeeded )
1041 {
1042 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1043 }
1044
1045 return FALSE;
1046 }
1047
1048 s_inYield = TRUE;
1049
1050 // by definition yield should handle all non-processed events
1051
1052 EventRef theEvent;
1053
1054 OSStatus status = noErr ;
1055 do
1056 {
1057 s_inReceiveEvent = true ;
1058 status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
1059 s_inReceiveEvent = false ;
1060
1061 if ( status == eventLoopTimedOutErr )
1062 {
1063 // make sure next time the event loop will trigger idle events
1064 sleepTime = kEventDurationNoWait ;
1065 }
1066 else if ( status == eventLoopQuitErr )
1067 {
1068 // according to QA1061 this may also occur when a WakeUp Process
1069 // is executed
1070 }
1071 else
1072 {
1073 MacHandleOneEvent( theEvent ) ;
1074 ReleaseEvent(theEvent);
1075 }
1076 } while( status == noErr ) ;
1077
1078 wxMacProcessNotifierAndPendingEvents() ;
1079 s_inYield = FALSE;
1080
1081 return TRUE;
1082}
1083
1084void wxApp::MacDoOneEvent()
1085{
1086 EventRef theEvent;
1087
1088 s_inReceiveEvent = true ;
1089 OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
1090 s_inReceiveEvent = false ;
1091 if ( status == eventLoopTimedOutErr )
1092 {
1093 if ( wxTheApp->ProcessIdle() )
1094 sleepTime = kEventDurationNoWait ;
1095 else
1096 sleepTime = kEventDurationSecond;
1097 }
1098 else if ( status == eventLoopQuitErr )
1099 {
1100 // according to QA1061 this may also occur when a WakeUp Process
1101 // is executed
1102 }
1103 else
1104 {
1105 MacHandleOneEvent( theEvent ) ;
1106 ReleaseEvent(theEvent);
1107 sleepTime = kEventDurationNoWait ;
1108 }
1109 // repeaters
1110
1111 DeletePendingObjects() ;
1112 wxMacProcessNotifierAndPendingEvents() ;
1113}
1114
1115/*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr )
1116{
1117 // Override to process unhandled events as you please
1118}
1119
1120void wxApp::MacHandleOneEvent( WXEVENTREF evr )
1121{
1122 EventTargetRef theTarget;
1123 theTarget = GetEventDispatcherTarget();
1124 m_macCurrentEvent = evr ;
1125 OSStatus status = SendEventToEventTarget ((EventRef) evr , theTarget);
1126 if(status == eventNotHandledErr)
1127 {
1128 MacHandleUnhandledEvent(evr);
1129 }
1130 wxMacProcessNotifierAndPendingEvents() ;
1131#if wxUSE_THREADS
1132 wxMutexGuiLeaveOrEnter();
1133#endif // wxUSE_THREADS
1134}
1135
1136long wxMacTranslateKey(unsigned char key, unsigned char code) ;
1137long wxMacTranslateKey(unsigned char key, unsigned char code)
1138{
1139 long retval = key ;
1140 switch (key)
1141 {
1142 case kHomeCharCode :
1143 retval = WXK_HOME;
1144 break;
1145 case kEnterCharCode :
1146 retval = WXK_RETURN;
1147 break;
1148 case kEndCharCode :
1149 retval = WXK_END;
1150 break;
1151 case kHelpCharCode :
1152 retval = WXK_HELP;
1153 break;
1154 case kBackspaceCharCode :
1155 retval = WXK_BACK;
1156 break;
1157 case kTabCharCode :
1158 retval = WXK_TAB;
1159 break;
1160 case kPageUpCharCode :
1161 retval = WXK_PAGEUP;
1162 break;
1163 case kPageDownCharCode :
1164 retval = WXK_PAGEDOWN;
1165 break;
1166 case kReturnCharCode :
1167 retval = WXK_RETURN;
1168 break;
1169 case kFunctionKeyCharCode :
1170 {
1171 switch( code )
1172 {
1173 case 0x7a :
1174 retval = WXK_F1 ;
1175 break;
1176 case 0x78 :
1177 retval = WXK_F2 ;
1178 break;
1179 case 0x63 :
1180 retval = WXK_F3 ;
1181 break;
1182 case 0x76 :
1183 retval = WXK_F4 ;
1184 break;
1185 case 0x60 :
1186 retval = WXK_F5 ;
1187 break;
1188 case 0x61 :
1189 retval = WXK_F6 ;
1190 break;
1191 case 0x62:
1192 retval = WXK_F7 ;
1193 break;
1194 case 0x64 :
1195 retval = WXK_F8 ;
1196 break;
1197 case 0x65 :
1198 retval = WXK_F9 ;
1199 break;
1200 case 0x6D :
1201 retval = WXK_F10 ;
1202 break;
1203 case 0x67 :
1204 retval = WXK_F11 ;
1205 break;
1206 case 0x6F :
1207 retval = WXK_F12 ;
1208 break;
1209 case 0x69 :
1210 retval = WXK_F13 ;
1211 break;
1212 case 0x6B :
1213 retval = WXK_F14 ;
1214 break;
1215 case 0x71 :
1216 retval = WXK_F15 ;
1217 break;
1218 }
1219 }
1220 break ;
1221 case kEscapeCharCode :
1222 retval = WXK_ESCAPE ;
1223 break ;
1224 case kLeftArrowCharCode :
1225 retval = WXK_LEFT ;
1226 break ;
1227 case kRightArrowCharCode :
1228 retval = WXK_RIGHT ;
1229 break ;
1230 case kUpArrowCharCode :
1231 retval = WXK_UP ;
1232 break ;
1233 case kDownArrowCharCode :
1234 retval = WXK_DOWN ;
1235 break ;
1236 case kDeleteCharCode :
1237 retval = WXK_DELETE ;
1238 default:
1239 break ;
1240 } // end switch
1241
1242 return retval;
1243}
1244
1245int wxMacKeyCodeToModifier(wxKeyCode key)
1246{
1247 switch (key)
1248 {
1249 case WXK_START:
1250 case WXK_MENU:
1251 return cmdKey;
1252
1253 case WXK_SHIFT:
1254 return shiftKey;
1255
1256 case WXK_CAPITAL:
1257 return alphaLock;
1258
1259 case WXK_ALT:
1260 return optionKey;
1261
1262 case WXK_CONTROL:
1263 return controlKey;
1264
1265 default:
1266 return 0;
1267 }
1268}
1269
1270bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
1271{
1272//#ifdef __DARWIN__
1273// wxHIDKeyboard keyboard;
1274// return keyboard.IsActive(key);
1275//#else
1276// TODO: Have it use HID Manager on OSX...
1277//if OS X > 10.2 (i.e. 10.2.x)
1278//a known apple bug prevents the system from determining led
1279//states with GetKeys... can only determine caps lock led
1280 return !!(GetCurrentKeyModifiers() & wxMacKeyCodeToModifier(key));
1281//else
1282// KeyMapByteArray keymap;
1283// GetKeys((BigEndianLong*)keymap);
1284// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
1285//#endif
1286}
1287
1288
1289bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1290{
1291 if ( !focus )
1292 return false ;
1293
1294 short keycode ;
1295 short keychar ;
1296 keychar = short(keymessage & charCodeMask);
1297 keycode = short(keymessage & keyCodeMask) >> 8 ;
1298
1299 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1300 {
1301 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1302 // and look at the character after
1303 UInt32 state = 0;
1304 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1305 keychar = short(keyInfo & charCodeMask);
1306 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1307 }
1308 long keyval = wxMacTranslateKey(keychar, keycode) ;
1309 long realkeyval = keyval ;
1310 if ( keyval == keychar )
1311 {
1312 // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first)
1313 realkeyval = short(keymessage & charCodeMask) ;
1314 keyval = wxToupper( keyval ) ;
1315 }
1316
1317 wxKeyEvent event(wxEVT_KEY_DOWN);
1318 bool handled = false ;
1319 event.m_shiftDown = modifiers & shiftKey;
1320 event.m_controlDown = modifiers & controlKey;
1321 event.m_altDown = modifiers & optionKey;
1322 event.m_metaDown = modifiers & cmdKey;
1323 event.m_keyCode = keyval ;
1324
1325 event.m_x = wherex;
1326 event.m_y = wherey;
1327 event.m_timeStamp = when;
1328 event.SetEventObject(focus);
1329 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1330 if ( handled && event.GetSkipped() )
1331 handled = false ;
1332 if ( !handled )
1333 {
1334#if wxUSE_ACCEL
1335 if (!handled)
1336 {
1337 wxWindow *ancestor = focus;
1338 while (ancestor)
1339 {
1340 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1341 if (command != -1)
1342 {
1343 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1344 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1345 break;
1346 }
1347 if (ancestor->IsTopLevel())
1348 break;
1349 ancestor = ancestor->GetParent();
1350 }
1351 }
1352#endif // wxUSE_ACCEL
1353 }
1354 if (!handled)
1355 {
1356 event.Skip( FALSE ) ;
1357 event.SetEventType( wxEVT_CHAR ) ;
1358 // raw value again
1359 event.m_keyCode = realkeyval ;
1360
1361 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1362 if ( handled && event.GetSkipped() )
1363 handled = false ;
1364 }
1365 if ( !handled && (keyval == WXK_TAB) )
1366 {
1367 wxWindow* iter = focus->GetParent() ;
1368 while( iter && !handled )
1369 {
1370 if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
1371 {
1372 wxNavigationKeyEvent new_event;
1373 new_event.SetEventObject( focus );
1374 new_event.SetDirection( !event.ShiftDown() );
1375 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1376 new_event.SetWindowChange( event.ControlDown() );
1377 new_event.SetCurrentFocus( focus );
1378 handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
1379 if ( handled && new_event.GetSkipped() )
1380 handled = false ;
1381 }
1382 iter = iter->GetParent() ;
1383 }
1384 }
1385 // backdoor handler for default return and command escape
1386 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
1387 {
1388 // if window is not having a focus still testing for default enter or cancel
1389 // TODO add the UMA version for ActiveNonFloatingWindow
1390 wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1391 if ( focus )
1392 {
1393 if ( keyval == WXK_RETURN )
1394 {
1395 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
1396 wxButton);
1397 if ( def && def->IsEnabled() )
1398 {
1399 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1400 event.SetEventObject(def);
1401 def->Command(event);
1402 return true ;
1403 }
1404 }
1405 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1406 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
1407 {
1408 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1409 new_event.SetEventObject( focus );
1410 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1411 }
1412 }
1413 }
1414 return handled ;
1415}
1416
1417bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1418{
1419 if ( !focus )
1420 return false ;
1421
1422 short keycode ;
1423 short keychar ;
1424 keychar = short(keymessage & charCodeMask);
1425 keycode = short(keymessage & keyCodeMask) >> 8 ;
1426 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1427 {
1428 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1429 // and look at the character after
1430 UInt32 state = 0;
1431 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1432 keychar = short(keyInfo & charCodeMask);
1433 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1434 }
1435 long keyval = wxMacTranslateKey(keychar, keycode) ;
1436
1437 if ( keyval == keychar )
1438 {
1439 keyval = wxToupper( keyval ) ;
1440 }
1441 bool handled = false ;
1442
1443 wxKeyEvent event(wxEVT_KEY_UP);
1444 event.m_shiftDown = modifiers & shiftKey;
1445 event.m_controlDown = modifiers & controlKey;
1446 event.m_altDown = modifiers & optionKey;
1447 event.m_metaDown = modifiers & cmdKey;
1448 event.m_keyCode = keyval ;
1449
1450 event.m_x = wherex;
1451 event.m_y = wherey;
1452 event.m_timeStamp = when;
1453 event.SetEventObject(focus);
1454 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1455
1456 return handled ;
1457}