1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/app.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/window.h"
23 #include "wx/button.h"
27 #include "wx/palette.h"
29 #include "wx/cursor.h"
30 #include "wx/dialog.h"
31 #include "wx/msgdlg.h"
32 #include "wx/textctrl.h"
33 #include "wx/memory.h"
34 #include "wx/gdicmn.h"
35 #include "wx/module.h"
38 #include "wx/tooltip.h"
39 #include "wx/docview.h"
40 #include "wx/filename.h"
42 #include "wx/thread.h"
43 #include "wx/evtloop.h"
49 #include "wx/osx/uma.h"
51 #include "wx/osx/private.h"
54 #if defined(WXMAKINGDLL_CORE)
55 # include <mach-o/dyld.h>
58 // Keep linker from discarding wxStockGDIMac
59 wxFORCE_LINK_MODULE(gdiobj
)
61 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
62 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
63 EVT_IDLE(wxApp::OnIdle
)
64 EVT_END_SESSION(wxApp::OnEndSession
)
65 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
69 // platform specific static variables
70 static const short kwxMacAppleMenuId
= 1 ;
72 wxWindow
* wxApp::s_captureWindow
= NULL
;
73 long wxApp::s_lastModifiers
= 0 ;
75 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
76 long wxApp::s_macPreferencesMenuItemId
= wxID_PREFERENCES
;
77 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
78 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
80 bool wxApp::sm_isEmbedded
= false; // Normally we're not a plugin
84 //----------------------------------------------------------------------
85 // Core Apple Event Support
86 //----------------------------------------------------------------------
88 AEEventHandlerUPP sODocHandler
= NULL
;
89 AEEventHandlerUPP sGURLHandler
= NULL
;
90 AEEventHandlerUPP sOAppHandler
= NULL
;
91 AEEventHandlerUPP sPDocHandler
= NULL
;
92 AEEventHandlerUPP sRAppHandler
= NULL
;
93 AEEventHandlerUPP sQuitHandler
= NULL
;
95 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon refcon
) ;
96 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon refcon
) ;
97 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon refcon
) ;
98 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon refcon
) ;
99 pascal OSErr
AEHandleRApp( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon refcon
) ;
100 pascal OSErr
AEHandleGURL( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon refcon
) ;
102 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon
WXUNUSED(refcon
) )
104 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
107 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon
WXUNUSED(refcon
) )
109 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
112 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon
WXUNUSED(refcon
) )
114 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
117 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon
WXUNUSED(refcon
) )
119 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
122 pascal OSErr
AEHandleRApp( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon
WXUNUSED(refcon
) )
124 return wxTheApp
->MacHandleAERApp( (AppleEvent
*) event
, reply
) ;
127 pascal OSErr
AEHandleGURL( const AppleEvent
*event
, AppleEvent
*reply
, SRefCon
WXUNUSED(refcon
) )
129 return wxTheApp
->MacHandleAEGURL((WXEVENTREF
*)event
, reply
) ;
133 // AEODoc Calls MacOpenFiles with all of the files passed
135 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
139 DescType returnedType
;
145 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
149 err
= AECountItems(&docList
, &itemsInList
);
153 ProcessSerialNumber PSN
;
154 PSN
.highLongOfPSN
= 0 ;
155 PSN
.lowLongOfPSN
= kCurrentProcess
;
156 SetFrontProcess( &PSN
) ;
161 wxArrayString fileNames
;
162 for (i
= 1; i
<= itemsInList
; i
++)
165 &docList
, i
, typeFSRef
, &keywd
, &returnedType
,
166 (Ptr
)&theRef
, sizeof(theRef
), &actualSize
);
167 fName
= wxMacFSRefToPath( &theRef
) ;
169 fileNames
.Add(fName
);
172 MacOpenFiles(fileNames
);
177 // AEODoc Calls MacOpenURL on the url passed
179 short wxApp::MacHandleAEGURL(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
181 DescType returnedType
;
184 OSErr err
= AEGetParamPtr((AppleEvent
*)event
, keyDirectObject
, typeChar
,
185 &returnedType
, url
, sizeof(url
)-1,
190 url
[actualSize
] = '\0'; // Terminate the C string
192 ProcessSerialNumber PSN
;
193 PSN
.highLongOfPSN
= 0 ;
194 PSN
.lowLongOfPSN
= kCurrentProcess
;
195 SetFrontProcess( &PSN
) ;
197 MacOpenURL(wxString(url
, wxConvUTF8
));
202 // AEPDoc Calls MacPrintFile on each of the files passed
204 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
208 DescType returnedType
;
214 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
218 err
= AECountItems(&docList
, &itemsInList
);
222 ProcessSerialNumber PSN
;
223 PSN
.highLongOfPSN
= 0 ;
224 PSN
.lowLongOfPSN
= kCurrentProcess
;
225 SetFrontProcess( &PSN
) ;
230 for (i
= 1; i
<= itemsInList
; i
++)
233 &docList
, i
, typeFSRef
, &keywd
, &returnedType
,
234 (Ptr
)&theRef
, sizeof(theRef
), &actualSize
);
235 fName
= wxMacFSRefToPath( &theRef
) ;
243 // AEOApp calls MacNewFile
245 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
251 // AEQuit attempts to quit the application
253 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
256 wxTheApp
->OnQueryEndSession(event
);
257 if ( !event
.GetVeto() )
260 wxTheApp
->OnEndSession(event
);
265 // AEROApp calls MacReopenApp
267 short wxApp::MacHandleAERApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
276 //----------------------------------------------------------------------
277 // Support Routines linking the Mac...File Calls to the Document Manager
278 //----------------------------------------------------------------------
280 void wxApp::MacOpenFiles(const wxArrayString
& fileNames
)
283 const size_t fileCount
= fileNames
.GetCount();
284 for (i
= 0; i
< fileCount
; i
++)
286 MacOpenFile(fileNames
[i
]);
290 void wxApp::MacOpenFile(const wxString
& fileName
)
292 #if wxUSE_DOC_VIEW_ARCHITECTURE
293 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
295 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
299 void wxApp::MacOpenURL(const wxString
& WXUNUSED(url
) )
303 void wxApp::MacPrintFile(const wxString
& fileName
)
305 #if wxUSE_DOC_VIEW_ARCHITECTURE
307 #if wxUSE_PRINTING_ARCHITECTURE
308 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
311 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
314 wxView
* view
= doc
->GetFirstView() ;
317 wxPrintout
*printout
= view
->OnCreatePrintout();
321 printer
.Print(view
->GetFrame(), printout
, true);
328 doc
->DeleteAllViews();
329 dm
->RemoveDocument(doc
) ;
340 void wxApp::MacNewFile()
344 void wxApp::MacReopenApp()
347 // if there is no open window -> create a new one
348 // if all windows are hidden -> show the first
349 // if some windows are not hidden -> do nothing
351 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
358 wxTopLevelWindow
* firstIconized
= NULL
;
359 wxTopLevelWindow
* firstHidden
= NULL
;
362 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->GetData();
363 if ( !win
->IsShown() )
365 // make sure we don't show 'virtual toplevel windows' like wxTaskBarIconWindow
366 if ( firstHidden
== NULL
&& ( wxDynamicCast( win
, wxFrame
) || wxDynamicCast( win
, wxDialog
) ) )
369 else if ( win
->IsIconized() )
371 if ( firstIconized
== NULL
)
372 firstIconized
= win
;
376 // we do have a visible, non-iconized toplevelwindow -> do nothing
380 node
= node
->GetNext();
384 firstIconized
->Iconize( false ) ;
385 else if ( firstHidden
)
386 firstHidden
->Show( true );
390 //----------------------------------------------------------------------
391 // Macintosh CommandID support - converting between native and wx IDs
392 //----------------------------------------------------------------------
394 // if no native match they just return the passed-in id
404 IdPair gCommandIds
[] =
406 { kHICommandCut
, wxID_CUT
} ,
407 { kHICommandCopy
, wxID_COPY
} ,
408 { kHICommandPaste
, wxID_PASTE
} ,
409 { kHICommandSelectAll
, wxID_SELECTALL
} ,
410 { kHICommandClear
, wxID_CLEAR
} ,
411 { kHICommandUndo
, wxID_UNDO
} ,
412 { kHICommandRedo
, wxID_REDO
} ,
415 int wxMacCommandToId( UInt32 macCommandId
)
419 switch ( macCommandId
)
421 case kHICommandPreferences
:
422 wxid
= wxApp::s_macPreferencesMenuItemId
;
425 case kHICommandQuit
:
426 wxid
= wxApp::s_macExitMenuItemId
;
429 case kHICommandAbout
:
430 wxid
= wxApp::s_macAboutMenuItemId
;
435 for ( size_t i
= 0 ; i
< WXSIZEOF(gCommandIds
) ; ++i
)
437 if ( gCommandIds
[i
].macId
== macCommandId
)
439 wxid
= gCommandIds
[i
].wxId
;
448 wxid
= (int) macCommandId
;
453 UInt32
wxIdToMacCommand( int wxId
)
457 if ( wxId
== wxApp::s_macPreferencesMenuItemId
)
458 macId
= kHICommandPreferences
;
459 else if (wxId
== wxApp::s_macExitMenuItemId
)
460 macId
= kHICommandQuit
;
461 else if (wxId
== wxApp::s_macAboutMenuItemId
)
462 macId
= kHICommandAbout
;
465 for ( size_t i
= 0 ; i
< WXSIZEOF(gCommandIds
) ; ++i
)
467 if ( gCommandIds
[i
].wxId
== wxId
)
469 macId
= gCommandIds
[i
].macId
;
481 wxMenu
* wxFindMenuFromMacCommand( const HICommand
&command
, wxMenuItem
* &item
)
483 wxMenu
* itemMenu
= NULL
;
484 #ifndef __WXUNIVERSAL__
487 // for 'standard' commands which don't have a wx-menu
488 if ( command
.commandID
== kHICommandPreferences
|| command
.commandID
== kHICommandQuit
|| command
.commandID
== kHICommandAbout
)
490 id
= wxMacCommandToId( command
.commandID
) ;
492 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
494 item
= mbar
->FindItem( id
, &itemMenu
) ;
496 else if ( command
.commandID
!= 0 && command
.menu
.menuRef
!= 0 && command
.menu
.menuItemIndex
!= 0 )
498 id
= wxMacCommandToId( command
.commandID
) ;
499 // make sure it is one of our own menus, or of the 'synthetic' apple and help menus , otherwise don't touch
500 MenuItemIndex firstUserHelpMenuItem
;
501 static MenuHandle helpMenuHandle
= NULL
;
502 if ( helpMenuHandle
== NULL
)
504 if ( UMAGetHelpMenuDontCreate( &helpMenuHandle
, &firstUserHelpMenuItem
) != noErr
)
505 helpMenuHandle
= NULL
;
508 // is it part of the application or the Help menu, then look for the id directly
509 if ( ( GetMenuHandle( kwxMacAppleMenuId
) != NULL
&& command
.menu
.menuRef
== GetMenuHandle( kwxMacAppleMenuId
) ) ||
510 ( helpMenuHandle
!= NULL
&& command
.menu
.menuRef
== helpMenuHandle
) ||
511 wxMenuBar::MacGetWindowMenuHMenu() != NULL
&& command
.menu
.menuRef
== wxMenuBar::MacGetWindowMenuHMenu() )
513 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
515 item
= mbar
->FindItem( id
, &itemMenu
) ;
521 GetMenuItemRefCon( command
.menu
.menuRef
, command
.menu
.menuItemIndex
, &refCon
) ;
522 itemMenu
= wxFindMenuFromMacMenu( command
.menu
.menuRef
) ;
523 if ( itemMenu
!= NULL
&& refCon
!= 0)
524 item
= (wxMenuItem
*) refCon
;
533 //----------------------------------------------------------------------
534 // Carbon Event Handler
535 //----------------------------------------------------------------------
539 static const EventTypeSpec eventList
[] =
541 { kEventClassCommand
, kEventProcessCommand
} ,
542 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
544 { kEventClassMenu
, kEventMenuOpening
},
545 { kEventClassMenu
, kEventMenuClosed
},
546 { kEventClassMenu
, kEventMenuTargetItem
},
548 { kEventClassApplication
, kEventAppActivated
} ,
549 { kEventClassApplication
, kEventAppDeactivated
} ,
550 // handling the quit event is not recommended by apple
551 // rather using the quit apple event - which we do
553 { kEventClassAppleEvent
, kEventAppleEvent
} ,
555 { kEventClassMouse
, kEventMouseDown
} ,
556 { kEventClassMouse
, kEventMouseMoved
} ,
557 { kEventClassMouse
, kEventMouseUp
} ,
558 { kEventClassMouse
, kEventMouseDragged
} ,
562 static pascal OSStatus
563 wxMacAppMenuEventHandler( EventHandlerCallRef
WXUNUSED(handler
),
565 void *WXUNUSED(data
) )
567 wxMacCarbonEvent
cEvent( event
) ;
568 MenuRef menuRef
= cEvent
.GetParameter
<MenuRef
>(kEventParamDirectObject
) ;
569 #ifndef __WXUNIVERSAL__
570 wxMenu
* menu
= wxFindMenuFromMacMenu( menuRef
) ;
574 switch (GetEventKind(event
))
576 case kEventMenuOpening
:
577 menu
->HandleMenuOpened();
580 case kEventMenuClosed
:
581 menu
->HandleMenuClosed();
584 case kEventMenuTargetItem
:
588 command
.menu
.menuRef
= menuRef
;
589 command
.menu
.menuItemIndex
= cEvent
.GetParameter
<MenuItemIndex
>(kEventParamMenuItemIndex
,typeMenuItemIndex
) ;
590 command
.commandID
= cEvent
.GetParameter
<MenuCommand
>(kEventParamMenuCommand
,typeMenuCommand
) ;
591 if (command
.commandID
!= 0)
593 wxMenuItem
* item
= NULL
;
594 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
595 if ( itemMenu
&& item
)
596 itemMenu
->HandleMenuItemHighlighted( item
);
602 wxFAIL_MSG(wxT("Unexpected menu event kind"));
608 return eventNotHandledErr
;
611 static pascal OSStatus
612 wxMacAppCommandEventHandler( EventHandlerCallRef
WXUNUSED(handler
) ,
614 void *WXUNUSED(data
) )
616 OSStatus result
= eventNotHandledErr
;
620 wxMacCarbonEvent
cEvent( event
) ;
621 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
623 wxMenuItem
* item
= NULL
;
624 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
628 wxASSERT( itemMenu
!= NULL
) ;
630 switch ( cEvent
.GetKind() )
632 case kEventProcessCommand
:
633 if ( itemMenu
->HandleCommandProcess( item
) )
637 case kEventCommandUpdateStatus
:
638 if ( itemMenu
->HandleCommandUpdateStatus( item
) )
649 static pascal OSStatus
650 wxMacAppApplicationEventHandler( EventHandlerCallRef
WXUNUSED(handler
) ,
652 void *WXUNUSED(data
) )
654 OSStatus result
= eventNotHandledErr
;
655 switch ( GetEventKind( event
) )
657 case kEventAppActivated
:
659 wxTheApp
->SetActive( true , NULL
) ;
663 case kEventAppDeactivated
:
665 wxTheApp
->SetActive( false , NULL
) ;
676 pascal OSStatus
wxMacAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
678 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
679 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
680 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
682 OSStatus result
= eventNotHandledErr
;
683 switch ( GetEventClass( event
) )
686 case kEventClassCommand
:
687 result
= wxMacAppCommandEventHandler( handler
, event
, data
) ;
690 case kEventClassApplication
:
691 result
= wxMacAppApplicationEventHandler( handler
, event
, data
) ;
694 case kEventClassMenu
:
695 result
= wxMacAppMenuEventHandler( handler
, event
, data
) ;
698 case kEventClassMouse
:
700 wxMacCarbonEvent
cEvent( event
) ;
703 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
704 ::FindWindow(screenMouseLocation
, &window
);
705 // only send this event in case it had not already been sent to a tlw, as we get
706 // double events otherwise (in case event.skip) was called
707 if ( window
== NULL
)
708 result
= wxMacTopLevelMouseEventHandler( handler
, event
, NULL
) ;
712 case kEventClassAppleEvent
:
714 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
715 if ( AEProcessEvent
!= NULL
)
717 result
= AEProcessEvent(event
);
720 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
724 wxMacConvertEventToRecord( event
, &rec
) ;
725 result
= AEProcessAppleEvent( &rec
) ;
735 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
740 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler
)
743 #if wxDEBUG_LEVEL && wxOSX_USE_COCOA_OR_CARBON
746 wxMacAssertOutputHandler(OSType
WXUNUSED(componentSignature
),
747 UInt32
WXUNUSED(options
),
748 const char *assertionString
,
749 const char *exceptionLabelString
,
750 const char *errorString
,
751 const char *fileName
,
754 ConstStr255Param
WXUNUSED(outputMsg
))
756 // flow into assert handling
757 wxString fileNameStr
;
758 wxString assertionStr
;
759 wxString exceptionStr
;
763 fileNameStr
= wxString(fileName
, wxConvLocal
);
764 assertionStr
= wxString(assertionString
, wxConvLocal
);
765 exceptionStr
= wxString((exceptionLabelString
!=0) ? exceptionLabelString
: "", wxConvLocal
) ;
766 errorStr
= wxString((errorString
!=0) ? errorString
: "", wxConvLocal
) ;
768 fileNameStr
= fileName
;
769 assertionStr
= assertionString
;
770 exceptionStr
= (exceptionLabelString
!=0) ? exceptionLabelString
: "" ;
771 errorStr
= (errorString
!=0) ? errorString
: "" ;
776 wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %ld (value %p)\n"),
777 assertionStr
.c_str() ,
778 exceptionStr
.c_str() ,
780 fileNameStr
.c_str(), lineNumber
,
784 wxOnAssert(fileNameStr
, lineNumber
, assertionStr
,
785 wxString::Format( wxT("%s %s value (%p)") , exceptionStr
, errorStr
, value
) ) ;
789 #endif // wxDEBUG_LEVEL
791 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
795 #if wxDEBUG_LEVEL && wxOSX_USE_COCOA_OR_CARBON
796 InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler
) );
799 // Mac OS X passes a process serial number command line argument when
800 // the application is launched from the Finder. This argument must be
801 // removed from the command line arguments before being handled by the
802 // application (otherwise applications would need to handle it)
805 static const wxChar
*ARG_PSN
= wxT("-psn_");
806 if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 )
808 // remove this argument
810 memmove(argv
+ 1, argv
+ 2, argc
* sizeof(char *));
814 if ( !wxAppBase::Initialize(argc
, argv
) )
818 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
821 // these might be the startup dirs, set them to the 'usual' dir containing the app bundle
822 wxString startupCwd
= wxGetCwd() ;
823 if ( startupCwd
== wxT("/") || startupCwd
.Right(15) == wxT("/Contents/MacOS") )
825 CFURLRef url
= CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ;
826 CFURLRef urlParent
= CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault
, url
) ;
828 CFStringRef path
= CFURLCopyFileSystemPath ( urlParent
, kCFURLPOSIXPathStyle
) ;
829 CFRelease( urlParent
) ;
830 wxString cwd
= wxCFStringRef(path
).AsString(wxLocale::GetSystemEncoding());
831 wxSetWorkingDirectory( cwd
) ;
837 #if wxOSX_USE_COCOA_OR_CARBON
838 bool wxApp::CallOnInit()
840 wxMacAutoreleasePool autoreleasepool
;
845 bool wxApp::OnInitGui()
847 if ( !wxAppBase::OnInitGui() )
856 bool wxApp::ProcessIdle()
858 wxMacAutoreleasePool autoreleasepool
;
859 return wxAppBase::ProcessIdle();
864 wxMacAutoreleasePool pool
;
865 return wxAppBase::OnRun();
869 bool wxApp::DoInitGui()
871 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
874 InstallApplicationEventHandler(
875 GetwxMacAppEventHandlerUPP(),
876 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
881 sODocHandler
= NewAEEventHandlerUPP(AEHandleODoc
) ;
882 sGURLHandler
= NewAEEventHandlerUPP(AEHandleGURL
) ;
883 sOAppHandler
= NewAEEventHandlerUPP(AEHandleOApp
) ;
884 sPDocHandler
= NewAEEventHandlerUPP(AEHandlePDoc
) ;
885 sRAppHandler
= NewAEEventHandlerUPP(AEHandleRApp
) ;
886 sQuitHandler
= NewAEEventHandlerUPP(AEHandleQuit
) ;
888 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
889 sODocHandler
, 0 , FALSE
) ;
890 AEInstallEventHandler( kInternetEventClass
, kAEGetURL
,
891 sGURLHandler
, 0 , FALSE
) ;
892 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
893 sOAppHandler
, 0 , FALSE
) ;
894 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
895 sPDocHandler
, 0 , FALSE
) ;
896 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
897 sRAppHandler
, 0 , FALSE
) ;
898 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
899 sQuitHandler
, 0 , FALSE
) ;
902 if ( !wxMacInitCocoa() )
908 void wxApp::DoCleanUp()
911 RemoveEventHandler( (EventHandlerRef
)(wxTheApp
->m_macEventHandler
) );
915 AERemoveEventHandler( kCoreEventClass
, kAEOpenDocuments
,
916 sODocHandler
, FALSE
) ;
917 AERemoveEventHandler( kInternetEventClass
, kAEGetURL
,
918 sGURLHandler
, FALSE
) ;
919 AERemoveEventHandler( kCoreEventClass
, kAEOpenApplication
,
920 sOAppHandler
, FALSE
) ;
921 AERemoveEventHandler( kCoreEventClass
, kAEPrintDocuments
,
922 sPDocHandler
, FALSE
) ;
923 AERemoveEventHandler( kCoreEventClass
, kAEReopenApplication
,
924 sRAppHandler
, FALSE
) ;
925 AERemoveEventHandler( kCoreEventClass
, kAEQuitApplication
,
926 sQuitHandler
, FALSE
) ;
928 DisposeAEEventHandlerUPP( sODocHandler
) ;
929 DisposeAEEventHandlerUPP( sGURLHandler
) ;
930 DisposeAEEventHandlerUPP( sOAppHandler
) ;
931 DisposeAEEventHandlerUPP( sPDocHandler
) ;
932 DisposeAEEventHandlerUPP( sRAppHandler
) ;
933 DisposeAEEventHandlerUPP( sQuitHandler
) ;
939 void wxApp::CleanUp()
941 wxMacAutoreleasePool autoreleasepool
;
943 wxToolTip::RemoveToolTips() ;
948 wxAppBase::CleanUp();
951 //----------------------------------------------------------------------
952 // misc initialization stuff
953 //----------------------------------------------------------------------
955 #if wxOSX_USE_CARBON && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
956 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
958 OSStatus err
= noErr
;
959 bool converted
= ConvertEventRefToEventRecord( event
, rec
) ;
963 switch ( GetEventClass( event
) )
965 case kEventClassKeyboard
:
968 switch ( GetEventKind(event
) )
970 case kEventRawKeyDown
:
971 rec
->what
= keyDown
;
974 case kEventRawKeyRepeat
:
975 rec
->what
= autoKey
;
978 case kEventRawKeyUp
:
982 case kEventRawKeyModifiersChanged
:
983 rec
->what
= nullEvent
;
994 unsigned char charCode
;
996 GetMouse( &rec
->where
) ;
997 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
998 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
999 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1000 rec
->modifiers
= modifiers
;
1001 rec
->message
= (keyCode
<< 8 ) + charCode
;
1006 case kEventClassTextInput
:
1008 switch ( GetEventKind( event
) )
1010 case kEventTextInputUnicodeForKeyEvent
:
1013 err
= GetEventParameter(
1014 event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
,
1015 sizeof(rawEvent
), NULL
, &rawEvent
) ;
1019 UInt32 keyCode
, modifiers
;
1020 unsigned char charCode
;
1021 GetMouse( &rec
->where
) ;
1022 rec
->what
= keyDown
;
1023 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
1024 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
1025 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1026 rec
->modifiers
= modifiers
;
1027 rec
->message
= (keyCode
<< 8 ) + charCode
;
1049 m_printMode
= wxPRINT_WINDOWS
;
1051 m_macCurrentEvent
= NULL
;
1052 m_macCurrentEventHandlerCallRef
= NULL
;
1053 m_macPool
= new wxMacAutoreleasePool();
1062 CFMutableArrayRef
GetAutoReleaseArray()
1064 static CFMutableArrayRef array
= 0;
1066 array
= CFArrayCreateMutable(kCFAllocatorDefault
,0,&kCFTypeArrayCallBacks
);
1070 void wxApp::MacAddToAutorelease( void* cfrefobj
)
1072 CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj
);
1075 void wxApp::MacReleaseAutoreleasePool()
1079 m_macPool
= new wxMacAutoreleasePool();
1082 void wxApp::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1084 // If they are pending events, we must process them: pending events are
1085 // either events to the threads other than main or events posted with
1086 // wxPostEvent() functions
1087 #ifndef __WXUNIVERSAL__
1089 if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1090 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1093 CFArrayRemoveAllValues( GetAutoReleaseArray() );
1096 void wxApp::WakeUpIdle()
1098 wxEventLoopBase
* const loop
= wxEventLoopBase::GetActive();
1104 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1107 GetTopWindow()->Close(true);
1110 // Default behaviour: close the application with prompts. The
1111 // user can veto the close, and therefore the end session.
1112 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1114 if ( !wxDialog::OSXHasModalDialogsOpen() )
1118 if (!GetTopWindow()->Close(!event
.CanVeto()))
1128 extern "C" void wxCYield() ;
1135 void wxApp::MacHandleUnhandledEvent( WXEVENTREF
WXUNUSED(evr
) )
1137 // Override to process unhandled events as you please
1140 #if wxOSX_USE_COCOA_OR_CARBON
1142 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
1144 // adding forward compatible defines for keys that are different on different keyboard layouts
1145 // see Inside Mac Volume V
1171 kVK_ANSI_Equal
= 0x18,
1174 kVK_ANSI_Minus
= 0x1B,
1177 kVK_ANSI_RightBracket
= 0x1E,
1180 kVK_ANSI_LeftBracket
= 0x21,
1185 kVK_ANSI_Quote
= 0x27,
1187 kVK_ANSI_Semicolon
= 0x29,
1188 kVK_ANSI_Backslash
= 0x2A,
1189 kVK_ANSI_Comma
= 0x2B,
1190 kVK_ANSI_Slash
= 0x2C,
1193 kVK_ANSI_Period
= 0x2F,
1194 kVK_ANSI_Grave
= 0x32,
1195 kVK_ANSI_KeypadDecimal
= 0x41,
1196 kVK_ANSI_KeypadMultiply
= 0x43,
1197 kVK_ANSI_KeypadPlus
= 0x45,
1198 kVK_ANSI_KeypadClear
= 0x47,
1199 kVK_ANSI_KeypadDivide
= 0x4B,
1200 kVK_ANSI_KeypadEnter
= 0x4C,
1201 kVK_ANSI_KeypadMinus
= 0x4E,
1202 kVK_ANSI_KeypadEquals
= 0x51,
1203 kVK_ANSI_Keypad0
= 0x52,
1204 kVK_ANSI_Keypad1
= 0x53,
1205 kVK_ANSI_Keypad2
= 0x54,
1206 kVK_ANSI_Keypad3
= 0x55,
1207 kVK_ANSI_Keypad4
= 0x56,
1208 kVK_ANSI_Keypad5
= 0x57,
1209 kVK_ANSI_Keypad6
= 0x58,
1210 kVK_ANSI_Keypad7
= 0x59,
1211 kVK_ANSI_Keypad8
= 0x5B,
1212 kVK_ANSI_Keypad9
= 0x5C
1215 // defines for keys that are the same on all layouts
1225 kVK_CapsLock
= 0x39,
1228 kVK_RightShift
= 0x3C,
1229 kVK_RightOption
= 0x3D,
1230 kVK_RightControl
= 0x3E,
1231 kVK_Function
= 0x3F,
1233 kVK_VolumeUp
= 0x48,
1234 kVK_VolumeDown
= 0x49,
1255 kVK_ForwardDelete
= 0x75,
1259 kVK_PageDown
= 0x79,
1261 kVK_LeftArrow
= 0x7B,
1262 kVK_RightArrow
= 0x7C,
1263 kVK_DownArrow
= 0x7D,
1269 CGKeyCode
wxCharCodeWXToOSX(wxKeyCode code
)
1275 case 'a': case 'A': keycode
= kVK_ANSI_A
; break;
1276 case 'b': case 'B': keycode
= kVK_ANSI_B
; break;
1277 case 'c': case 'C': keycode
= kVK_ANSI_C
; break;
1278 case 'd': case 'D': keycode
= kVK_ANSI_D
; break;
1279 case 'e': case 'E': keycode
= kVK_ANSI_E
; break;
1280 case 'f': case 'F': keycode
= kVK_ANSI_F
; break;
1281 case 'g': case 'G': keycode
= kVK_ANSI_G
; break;
1282 case 'h': case 'H': keycode
= kVK_ANSI_H
; break;
1283 case 'i': case 'I': keycode
= kVK_ANSI_I
; break;
1284 case 'j': case 'J': keycode
= kVK_ANSI_J
; break;
1285 case 'k': case 'K': keycode
= kVK_ANSI_K
; break;
1286 case 'l': case 'L': keycode
= kVK_ANSI_L
; break;
1287 case 'm': case 'M': keycode
= kVK_ANSI_M
; break;
1288 case 'n': case 'N': keycode
= kVK_ANSI_N
; break;
1289 case 'o': case 'O': keycode
= kVK_ANSI_O
; break;
1290 case 'p': case 'P': keycode
= kVK_ANSI_P
; break;
1291 case 'q': case 'Q': keycode
= kVK_ANSI_Q
; break;
1292 case 'r': case 'R': keycode
= kVK_ANSI_R
; break;
1293 case 's': case 'S': keycode
= kVK_ANSI_S
; break;
1294 case 't': case 'T': keycode
= kVK_ANSI_T
; break;
1295 case 'u': case 'U': keycode
= kVK_ANSI_U
; break;
1296 case 'v': case 'V': keycode
= kVK_ANSI_V
; break;
1297 case 'w': case 'W': keycode
= kVK_ANSI_W
; break;
1298 case 'x': case 'X': keycode
= kVK_ANSI_X
; break;
1299 case 'y': case 'Y': keycode
= kVK_ANSI_Y
; break;
1300 case 'z': case 'Z': keycode
= kVK_ANSI_Z
; break;
1302 case '0': keycode
= kVK_ANSI_0
; break;
1303 case '1': keycode
= kVK_ANSI_1
; break;
1304 case '2': keycode
= kVK_ANSI_2
; break;
1305 case '3': keycode
= kVK_ANSI_3
; break;
1306 case '4': keycode
= kVK_ANSI_4
; break;
1307 case '5': keycode
= kVK_ANSI_5
; break;
1308 case '6': keycode
= kVK_ANSI_6
; break;
1309 case '7': keycode
= kVK_ANSI_7
; break;
1310 case '8': keycode
= kVK_ANSI_8
; break;
1311 case '9': keycode
= kVK_ANSI_9
; break;
1313 case WXK_BACK
: keycode
= kVK_Delete
; break;
1314 case WXK_TAB
: keycode
= kVK_Tab
; break;
1315 case WXK_RETURN
: keycode
= kVK_Return
; break;
1316 case WXK_ESCAPE
: keycode
= kVK_Escape
; break;
1317 case WXK_SPACE
: keycode
= kVK_Space
; break;
1318 case WXK_DELETE
: keycode
= kVK_Delete
; break;
1320 case WXK_SHIFT
: keycode
= kVK_Shift
; break;
1321 case WXK_ALT
: keycode
= kVK_Option
; break;
1322 case WXK_CONTROL
: keycode
= kVK_Control
; break;
1323 case WXK_COMMAND
: keycode
= kVK_Command
; break;
1325 case WXK_CAPITAL
: keycode
= kVK_CapsLock
; break;
1326 case WXK_END
: keycode
= kVK_End
; break;
1327 case WXK_HOME
: keycode
= kVK_Home
; break;
1328 case WXK_LEFT
: keycode
= kVK_LeftArrow
; break;
1329 case WXK_UP
: keycode
= kVK_UpArrow
; break;
1330 case WXK_RIGHT
: keycode
= kVK_RightArrow
; break;
1331 case WXK_DOWN
: keycode
= kVK_DownArrow
; break;
1333 case WXK_HELP
: keycode
= kVK_Help
; break;
1336 case WXK_NUMPAD0
: keycode
= kVK_ANSI_Keypad0
; break;
1337 case WXK_NUMPAD1
: keycode
= kVK_ANSI_Keypad1
; break;
1338 case WXK_NUMPAD2
: keycode
= kVK_ANSI_Keypad2
; break;
1339 case WXK_NUMPAD3
: keycode
= kVK_ANSI_Keypad3
; break;
1340 case WXK_NUMPAD4
: keycode
= kVK_ANSI_Keypad4
; break;
1341 case WXK_NUMPAD5
: keycode
= kVK_ANSI_Keypad5
; break;
1342 case WXK_NUMPAD6
: keycode
= kVK_ANSI_Keypad6
; break;
1343 case WXK_NUMPAD7
: keycode
= kVK_ANSI_Keypad7
; break;
1344 case WXK_NUMPAD8
: keycode
= kVK_ANSI_Keypad8
; break;
1345 case WXK_NUMPAD9
: keycode
= kVK_ANSI_Keypad9
; break;
1346 case WXK_F1
: keycode
= kVK_F1
; break;
1347 case WXK_F2
: keycode
= kVK_F2
; break;
1348 case WXK_F3
: keycode
= kVK_F3
; break;
1349 case WXK_F4
: keycode
= kVK_F4
; break;
1350 case WXK_F5
: keycode
= kVK_F5
; break;
1351 case WXK_F6
: keycode
= kVK_F6
; break;
1352 case WXK_F7
: keycode
= kVK_F7
; break;
1353 case WXK_F8
: keycode
= kVK_F8
; break;
1354 case WXK_F9
: keycode
= kVK_F9
; break;
1355 case WXK_F10
: keycode
= kVK_F10
; break;
1356 case WXK_F11
: keycode
= kVK_F11
; break;
1357 case WXK_F12
: keycode
= kVK_F12
; break;
1358 case WXK_F13
: keycode
= kVK_F13
; break;
1359 case WXK_F14
: keycode
= kVK_F14
; break;
1360 case WXK_F15
: keycode
= kVK_F15
; break;
1361 case WXK_F16
: keycode
= kVK_F16
; break;
1362 case WXK_F17
: keycode
= kVK_F17
; break;
1363 case WXK_F18
: keycode
= kVK_F18
; break;
1364 case WXK_F19
: keycode
= kVK_F19
; break;
1365 case WXK_F20
: keycode
= kVK_F20
; break;
1367 case WXK_PAGEUP
: keycode
= kVK_PageUp
; break;
1368 case WXK_PAGEDOWN
: keycode
= kVK_PageDown
; break;
1370 case WXK_NUMPAD_DELETE
: keycode
= kVK_ANSI_KeypadClear
; break;
1371 case WXK_NUMPAD_EQUAL
: keycode
= kVK_ANSI_KeypadEquals
; break;
1372 case WXK_NUMPAD_MULTIPLY
: keycode
= kVK_ANSI_KeypadMultiply
; break;
1373 case WXK_NUMPAD_ADD
: keycode
= kVK_ANSI_KeypadPlus
; break;
1374 case WXK_NUMPAD_SUBTRACT
: keycode
= kVK_ANSI_KeypadMinus
; break;
1375 case WXK_NUMPAD_DECIMAL
: keycode
= kVK_ANSI_KeypadDecimal
; break;
1376 case WXK_NUMPAD_DIVIDE
: keycode
= kVK_ANSI_KeypadDivide
; break;
1379 wxLogDebug( "Unrecognised keycode %d", code
);
1380 keycode
= static_cast<CGKeyCode
>(-1);
1386 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1391 case kHomeCharCode
:
1395 case kEnterCharCode
:
1396 retval
= WXK_RETURN
;
1402 case kHelpCharCode
:
1406 case kBackspaceCharCode
:
1414 case kPageUpCharCode
:
1415 retval
= WXK_PAGEUP
;
1418 case kPageDownCharCode
:
1419 retval
= WXK_PAGEDOWN
;
1422 case kReturnCharCode
:
1423 retval
= WXK_RETURN
;
1426 case kFunctionKeyCharCode
:
1496 case kEscapeCharCode
:
1497 retval
= WXK_ESCAPE
;
1500 case kLeftArrowCharCode
:
1504 case kRightArrowCharCode
:
1505 retval
= WXK_RIGHT
;
1508 case kUpArrowCharCode
:
1512 case kDownArrowCharCode
:
1516 case kDeleteCharCode
:
1517 retval
= WXK_DELETE
;
1527 int wxMacKeyCodeToModifier(wxKeyCode key
)
1553 #if wxOSX_USE_COCOA && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
1555 // defined in utils.mm
1557 #elif wxOSX_USE_COCOA_OR_CARBON
1559 wxMouseState
wxGetMouseState()
1563 wxPoint pt
= wxGetMousePosition();
1567 UInt32 buttons
= GetCurrentButtonState();
1568 ms
.SetLeftDown( (buttons
& 0x01) != 0 );
1569 ms
.SetMiddleDown( (buttons
& 0x04) != 0 );
1570 ms
.SetRightDown( (buttons
& 0x02) != 0 );
1572 UInt32 modifiers
= GetCurrentKeyModifiers();
1573 ms
.SetControlDown(modifiers
& controlKey
);
1574 ms
.SetShiftDown(modifiers
& shiftKey
);
1575 ms
.SetAltDown(modifiers
& optionKey
);
1576 ms
.SetMetaDown(modifiers
& cmdKey
);
1583 // TODO : once the new key/char handling is tested, move all the code to wxWindow
1585 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
, wxChar uniChar
)
1590 wxKeyEvent
event(wxEVT_KEY_DOWN
) ;
1591 MacCreateKeyEvent( event
, focus
, keymessage
, modifiers
, when
, wherex
, wherey
, uniChar
) ;
1593 return focus
->OSXHandleKeyEvent(event
);
1596 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
, wxChar uniChar
)
1601 wxKeyEvent
event( wxEVT_KEY_UP
) ;
1602 MacCreateKeyEvent( event
, focus
, keymessage
, modifiers
, when
, wherex
, wherey
, uniChar
) ;
1604 return focus
->OSXHandleKeyEvent(event
) ;
1607 bool wxApp::MacSendCharEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
, wxChar uniChar
)
1611 wxKeyEvent
event(wxEVT_CHAR
) ;
1612 MacCreateKeyEvent( event
, focus
, keymessage
, modifiers
, when
, wherex
, wherey
, uniChar
) ;
1614 bool handled
= false ;
1616 #if wxOSX_USE_CARBON
1617 long keyval
= event
.m_keyCode
;
1618 wxNonOwnedWindow
*tlw
= focus
->MacGetTopLevelWindow() ;
1622 event
.SetEventType( wxEVT_CHAR_HOOK
);
1623 handled
= tlw
->HandleWindowEvent( event
);
1624 if ( handled
&& event
.GetSkipped() )
1630 event
.SetEventType( wxEVT_CHAR
);
1631 event
.Skip( false ) ;
1632 handled
= focus
->HandleWindowEvent( event
) ;
1635 if ( !handled
&& (keyval
== WXK_TAB
) )
1637 wxWindow
* iter
= focus
->GetParent() ;
1638 while ( iter
&& !handled
)
1640 if ( iter
->HasFlag( wxTAB_TRAVERSAL
) )
1642 wxNavigationKeyEvent new_event
;
1643 new_event
.SetEventObject( focus
);
1644 new_event
.SetDirection( !event
.ShiftDown() );
1645 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1646 new_event
.SetWindowChange( event
.ControlDown() );
1647 new_event
.SetCurrentFocus( focus
);
1648 handled
= focus
->GetParent()->HandleWindowEvent( new_event
);
1649 if ( handled
&& new_event
.GetSkipped() )
1653 iter
= iter
->GetParent() ;
1657 // backdoor handler for default return and command escape
1658 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->AcceptsFocus() ) )
1660 // if window is not having a focus still testing for default enter or cancel
1661 // TODO: add the UMA version for ActiveNonFloatingWindow
1663 wxWindow
* focus
= wxNonOwnedWindow::GetFromWXWindow( (WXWindow
) FrontWindow() ) ;
1666 if ( keyval
== WXK_RETURN
|| keyval
== WXK_NUMPAD_ENTER
)
1668 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(focus
), wxTopLevelWindow
);
1669 if ( tlw
&& tlw
->GetDefaultItem() )
1671 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
1672 if ( def
&& def
->IsEnabled() )
1674 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1675 event
.SetEventObject(def
);
1676 def
->Command(event
);
1682 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1684 // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs)
1685 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1686 new_event
.SetEventObject( focus
);
1687 handled
= focus
->HandleWindowEvent( new_event
);
1696 // This method handles common code for SendKeyDown, SendKeyUp, and SendChar events.
1697 void wxApp::MacCreateKeyEvent( wxKeyEvent
& event
, wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
, wxChar uniChar
)
1699 #if wxOSX_USE_COCOA_OR_CARBON
1701 short keycode
, keychar
;
1703 keychar
= short(keymessage
& charCodeMask
);
1704 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1705 if ( !(event
.GetEventType() == wxEVT_CHAR
) && (modifiers
& (controlKey
| shiftKey
| optionKey
) ) )
1707 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1708 // and look at the character after
1710 // TODO new implementation using TextInputSources
1713 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
| shiftKey
| optionKey
))) | keycode
, &state
);
1714 keychar
= short(keyInfo
& charCodeMask
);
1718 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1719 if ( keyval
== keychar
&& ( event
.GetEventType() == wxEVT_KEY_UP
|| event
.GetEventType() == wxEVT_KEY_DOWN
) )
1720 keyval
= wxToupper( keyval
) ;
1722 // Check for NUMPAD keys. For KEY_UP/DOWN events we need to use the
1723 // WXK_NUMPAD constants, but for the CHAR event we want to use the
1724 // standard ascii values
1725 if ( event
.GetEventType() != wxEVT_CHAR
)
1727 if (keyval
>= '0' && keyval
<= '9' && keycode
>= 82 && keycode
<= 92)
1729 keyval
= (keyval
- '0') + WXK_NUMPAD0
;
1731 else if (keycode
>= 65 && keycode
<= 81)
1736 keyval
= WXK_NUMPAD_ENTER
;
1740 keyval
= WXK_NUMPAD_EQUAL
;
1744 keyval
= WXK_NUMPAD_MULTIPLY
;
1748 keyval
= WXK_NUMPAD_DIVIDE
;
1752 keyval
= WXK_NUMPAD_SUBTRACT
;
1756 keyval
= WXK_NUMPAD_ADD
;
1760 keyval
= WXK_NUMPAD_DECIMAL
;
1768 event
.m_shiftDown
= modifiers
& shiftKey
;
1769 event
.m_controlDown
= modifiers
& controlKey
;
1770 event
.m_altDown
= modifiers
& optionKey
;
1771 event
.m_metaDown
= modifiers
& cmdKey
;
1772 event
.m_keyCode
= keyval
;
1774 event
.m_uniChar
= uniChar
;
1777 event
.m_rawCode
= keymessage
;
1778 event
.m_rawFlags
= modifiers
;
1781 event
.SetTimestamp(when
);
1782 event
.SetEventObject(focus
);
1786 wxUnusedVar(keymessage
);
1787 wxUnusedVar(modifiers
);
1789 wxUnusedVar(wherex
);
1790 wxUnusedVar(wherey
);
1791 wxUnusedVar(uniChar
);
1796 void wxApp::MacHideApp()
1798 #if wxOSX_USE_CARBON
1799 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
1801 memset( &command
, 0 , sizeof(command
) );
1802 command
.commandID
= kHICommandHide
;
1803 event
.SetParameter
<HICommand
>(kEventParamDirectObject
, command
);
1804 SendEventToApplication( event
);