📄 app.cpp
字号:
CFRunLoopSourceContext event_posted_context = {0}; event_posted_context.perform = macPostedEventCallback; m_macEventPosted = CFRunLoopSourceCreate(NULL,0,&event_posted_context); CFRunLoopAddSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); // run loop takes ownership CFRelease(m_macEventPosted);#endif UMAShowArrowCursor() ; return true;}AEEventHandlerUPP sODocHandler = NULL ;AEEventHandlerUPP sOAppHandler = NULL ;AEEventHandlerUPP sPDocHandler = NULL ;AEEventHandlerUPP sRAppHandler = NULL ;AEEventHandlerUPP sQuitHandler = NULL ;bool wxApp::OnInitGui(){ if ( !wxAppBase::OnInitGui() ) return false ; InstallStandardEventHandler( GetApplicationEventTarget() ) ; if (!sm_isEmbedded) { InstallApplicationEventHandler( GetwxMacAppEventHandlerUPP(), GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); } if (!sm_isEmbedded) { sODocHandler = NewAEEventHandlerUPP(AEHandleODoc) ; sOAppHandler = NewAEEventHandlerUPP(AEHandleOApp) ; sPDocHandler = NewAEEventHandlerUPP(AEHandlePDoc) ; sRAppHandler = NewAEEventHandlerUPP(AEHandleRApp) ; sQuitHandler = NewAEEventHandlerUPP(AEHandleQuit) ; AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , sODocHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , sOAppHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , sPDocHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEReopenApplication , sRAppHandler , 0 , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , sQuitHandler , 0 , FALSE ) ; } return true ;}void wxApp::CleanUp(){#if wxUSE_TOOLTIPS wxToolTip::RemoveToolTips() ;#endif#ifdef __WXMAC_OSX__ if (m_macEventPosted) { CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes); m_macEventPosted = NULL; }#endif // One last chance for pending objects to be cleaned up wxTheApp->DeletePendingObjects(); wxMacDestroyNotifierTable() ;#ifndef __DARWIN__# if __option(profile) ProfilerDump( (StringPtr)"\papp.prof" ) ; ProfilerTerm() ;# endif#endif UMACleanupToolbox() ; if (!sm_isEmbedded) RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) ); if (!sm_isEmbedded) { AERemoveEventHandler( kCoreEventClass , kAEOpenDocuments , sODocHandler , FALSE ) ; AERemoveEventHandler( kCoreEventClass , kAEOpenApplication , sOAppHandler , FALSE ) ; AERemoveEventHandler( kCoreEventClass , kAEPrintDocuments , sPDocHandler , FALSE ) ; AERemoveEventHandler( kCoreEventClass , kAEReopenApplication , sRAppHandler , FALSE ) ; AERemoveEventHandler( kCoreEventClass , kAEQuitApplication , sQuitHandler , FALSE ) ; DisposeAEEventHandlerUPP( sODocHandler ) ; DisposeAEEventHandlerUPP( sOAppHandler ) ; DisposeAEEventHandlerUPP( sPDocHandler ) ; DisposeAEEventHandlerUPP( sRAppHandler ) ; DisposeAEEventHandlerUPP( sQuitHandler ) ; } wxAppBase::CleanUp();}//----------------------------------------------------------------------// misc initialization stuff//----------------------------------------------------------------------#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)// for shared libraries we have to manually get the correct resource// ref num upon initializing and releasing when terminating, therefore// the __wxinitialize and __wxterminate must be usedextern "C"{ void __sinit(void); // (generated by linker) pascal OSErr __initialize(const CFragInitBlock *theInitBlock); pascal void __terminate(void);}pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock){ return __initialize( theInitBlock ) ;}pascal void __wxterminate(void){ __terminate() ;}#endif /* WXMAKINGDLL_CORE && !__DARWIN__ */bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec){ OSStatus err = noErr ; bool converted = ConvertEventRefToEventRecord( event, rec) ; if ( !converted ) { switch ( GetEventClass( event ) ) { case kEventClassKeyboard : { converted = true ; switch ( GetEventKind(event) ) { case kEventRawKeyDown : rec->what = keyDown ; break ; case kEventRawKeyRepeat : rec->what = autoKey ; break ; case kEventRawKeyUp : rec->what = keyUp ; break ; case kEventRawKeyModifiersChanged : rec->what = nullEvent ; break ; default : converted = false ; break ; } if ( converted ) { UInt32 keyCode ; unsigned char charCode ; UInt32 modifiers ;#ifndef __LP64__ GetMouse( &rec->where) ;#endif err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode); err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode); rec->modifiers = modifiers ; rec->message = (keyCode << 8 ) + charCode ; } } break ; case kEventClassTextInput : { switch ( GetEventKind( event ) ) { case kEventTextInputUnicodeForKeyEvent : { EventRef rawEvent ; err = GetEventParameter( event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawEvent), NULL, &rawEvent ) ; converted = true ; { UInt32 keyCode, modifiers; unsigned char charCode ;#ifndef __LP64__ GetMouse( &rec->where) ;#endif rec->what = keyDown ; err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode); err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode); rec->modifiers = modifiers ; rec->message = (keyCode << 8 ) + charCode ; } } break ; default : break ; } } break ; default : break ; } } return converted ;}wxApp::wxApp(){ m_printMode = wxPRINT_WINDOWS; m_macCurrentEvent = NULL ; m_macCurrentEventHandlerCallRef = NULL ;#ifdef __WXMAC_OSX__ m_macEventPosted = NULL ;#endif}void wxApp::OnIdle(wxIdleEvent& event){ wxAppBase::OnIdle(event); // If they are pending events, we must process them: pending events are // either events to the threads other than main or events posted with // wxPostEvent() functions wxMacProcessNotifierAndPendingEvents(); if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();}void wxApp::WakeUpIdle(){#ifdef __WXMAC_OSX__ if (m_macEventPosted) { CFRunLoopSourceSignal(m_macEventPosted); }#endif wxMacWakeUp() ;}void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)){ if (GetTopWindow()) GetTopWindow()->Close(true);}// Default behaviour: close the application with prompts. The// user can veto the close, and therefore the end session.void wxApp::OnQueryEndSession(wxCloseEvent& event){ if (GetTopWindow()) { if (!GetTopWindow()->Close(!event.CanVeto())) event.Veto(true); }}extern "C" void wxCYield() ;void wxCYield(){ wxYield() ;}// Yield to other processesbool wxApp::Yield(bool onlyIfNeeded){ if (s_inYield) { if ( !onlyIfNeeded ) { wxFAIL_MSG( wxT("wxYield called recursively" ) ); } return false; } s_inYield = true; // by definition yield should handle all non-processed events EventRef theEvent; OSStatus status = noErr ; while ( status == noErr ) { s_inReceiveEvent = true ; status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; s_inReceiveEvent = false ; if ( status == eventLoopTimedOutErr ) { // make sure next time the event loop will trigger idle events sleepTime = kEventDurationNoWait ; } else if ( status == eventLoopQuitErr ) { // according to QA1061 this may also occur when a WakeUp Process // is executed } else { MacHandleOneEvent( theEvent ) ; ReleaseEvent(theEvent); } } wxMacProcessNotifierAndPendingEvents() ; s_inYield = false; return true;}void wxApp::MacDoOneEvent(){ EventRef theEvent; s_inReceiveEvent = true ; OSStatus status = ReceiveNextEvent(0, NULL, sleepTime, true, &theEvent) ; s_inReceiveEvent = false ; switch (status) { case eventLoopTimedOutErr : if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait ; else sleepTime = kEventDurationSecond; break; case eventLoopQuitErr : // according to QA1061 this may also occur // when a WakeUp Process is executed break; default: MacHandleOneEvent( theEvent ) ; ReleaseEvent( theEvent ); sleepTime = kEventDurationNoWait ; break; } // repeaters DeletePendingObjects() ; wxMacProcessNotifierAndPendingEvents() ;}// virtualvoid wxApp::MacHandleUnhandledEvent( WXEVENTREF evr ){ // Override to process unhandled events as you please}CFMutableArrayRef GetAutoReleaseArray(){ static CFMutableArrayRef array = 0; if ( array == 0) array= CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks); return array;}void wxApp::MacHandleOneEvent( WXEVENTREF evr ){ EventTargetRef theTarget; theTarget = GetEventDispatcherTarget(); m_macCurrentEvent = evr ; OSStatus status = SendEventToEventTarget((EventRef) evr , theTarget); if (status == eventNotHandledErr) MacHandleUnhandledEvent(evr); wxMacProcessNotifierAndPendingEvents() ;#if wxUSE_THREADS wxMutexGuiLeaveOrEnter();#endif // wxUSE_THREADS CFArrayRemoveAllValues( GetAutoReleaseArray() );}void wxApp::MacAddToAutorelease( void* cfrefobj ){ CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj );}long wxMacTranslateKey(unsigned char key, unsigned char code){ long retval = key ; switch (key) { case kHomeCharCode : retval = WXK_HOME;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -