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