⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        case kEventMouseUp :        {            if ( wxTheApp->s_captureWindow )                wxMacWindowEventHandler( handler , event , (void*) wxTheApp->s_captureWindow->MacGetTopLevelWindow() ) ;        }        break ;        case kEventMouseMoved :        {            wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;            result = noErr ;            break ;        }        break ;    }    return result ;}static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    HICommand command ;    GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL,        sizeof( HICommand ), NULL, &command );    MenuCommand id = command.commandID ;    if ( id == kHICommandPreferences )        id = wxApp::s_macPreferencesMenuItemId ;    wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;    wxMenu* menu = NULL ;    wxMenuItem* item = NULL ;    if ( mbar )    {        item = mbar->FindItem( id , &menu ) ;        // it is not 100 % sure that an menu of id 0 is really ours, safety check        if ( id == 0 && menu != NULL && menu->GetHMenu() != command.menu.menuRef )        {            item = NULL ;            menu = NULL ;        }    }    if ( item == NULL || menu == NULL || mbar == NULL )        return result ;       switch( GetEventKind( event ) )       {           case kEventProcessCommand :           {                if (item->IsCheckable())                {                    item->Check( !item->IsChecked() ) ;                }                menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;                result = noErr ;            }               break ;        case kEventCommandUpdateStatus:            // eventually trigger an updateui round            result = noErr ;            break ;           default :               break ;       }    return result ;}static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    switch ( GetEventKind( event ) )    {        case kEventAppActivated :            {                if ( wxTheApp )                    wxTheApp->MacResume( true ) ;                result = noErr ;            }            break ;        case kEventAppDeactivated :            {                if ( wxTheApp )                    wxTheApp->MacSuspend( true ) ;                result = noErr ;            }            break ;        default :            break ;    }    return result ;}pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    switch( GetEventClass( event ) )    {        case kEventClassCommand :            result = CommandEventHandler( handler , event , data ) ;            break ;        case kEventClassApplication :            result = ApplicationEventHandler( handler , event , data ) ;            break ;        case kEventClassMenu :            result = MenuEventHandler( handler , event , data ) ;            break ;        case kEventClassMouse :            result = MouseEventHandler( handler , event , data ) ;            break ;        case kEventClassAppleEvent :            {                EventRecord rec ;                wxMacConvertEventToRecord( event , &rec ) ;                result = AEProcessAppleEvent( &rec ) ;            }            break ;        default :            break ;    }    return result ;}DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )#endif#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)// we know it's there ;-)WXIMPORT char std::__throws_bad_alloc ;#endifbool wxApp::Initialize(int& argc, wxChar **argv){    int error = 0 ;    // Mac-specific    UMAInitToolbox( 4, sm_isEmbedded ) ;    SetEventMask( everyEvent ) ;    UMAShowWatchCursor() ;#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)    // open shared library resources from here since we don't have    //   __wxinitialize in Mach-O shared libraries    wxStAppResource::OpenSharedLibraryResource(NULL);#endif#ifndef __DARWIN__    // test the minimal configuration necessary#  if !TARGET_CARBON    long theSystem ;    long theMachine;    if (Gestalt(gestaltMachineType, &theMachine) != noErr)    {        error = kMacSTRWrongMachine;    }    else if (theMachine < gestaltMacPlus)    {        error = kMacSTRWrongMachine;    }    else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )    {        error = kMacSTROldSystem  ;    }    else if ( theSystem < 0x0860 )    {        error = kMacSTROldSystem  ;    }    else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)    {        error = kMacSTRSmallSize;    }#  endif    /*    else    {        if ( !UMAHasAppearance() )        {            error = kMacSTRNoPre8Yet ;        }    }    */#endif    // if we encountered any problems so far, give the error code and exit immediately  if ( error )  {        wxStAppResource resload ;        short itemHit;        Str255 message;        GetIndString(message, 128, error);        UMAShowArrowCursor() ;        ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");        itemHit = Alert(128, nil);        return false ;  }#ifndef __DARWIN__#  if __option(profile)    ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ;#  endif#endif#ifndef __DARWIN__    // now avoid exceptions thrown for new (bad_alloc)    // FIXME CS for some changes outside wxMac does not compile anymore#if 0    std::__throws_bad_alloc = 0 ;#endif#endif    s_macCursorRgn = ::NewRgn() ;    // Mac OS X passes a process serial number command line argument when    // the application is launched from the Finder. This argument must be    // removed from the command line arguments before being handled by the    // application (otherwise applications would need to handle it)    if ( argc > 1 )    {        static const wxChar *ARG_PSN = _T("-psn_");        if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 )        {            // remove this argument            --argc;            memmove(argv + 1, argv + 2, argc * sizeof(char *));        }    }    if ( !wxAppBase::Initialize(argc, argv) )        return false;#if wxUSE_INTL    wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());#endif    wxWinMacWindowList = new wxList(wxKEY_INTEGER);    wxWinMacControlList = new wxList(wxKEY_INTEGER);    wxMacCreateNotifierTable() ;    UMAShowArrowCursor() ;    return true;}bool wxApp::OnInitGui(){    if( !wxAppBase::OnInitGui() )        return false ;#if TARGET_CARBON    InstallStandardEventHandler( GetApplicationEventTarget() ) ;    if (!sm_isEmbedded)    {        InstallApplicationEventHandler(            GetwxAppEventHandlerUPP(),            GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler));    }#endif    if (!sm_isEmbedded)    {#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)        AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,                               NewAEEventHandlerUPP(AEHandleODoc) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,                               NewAEEventHandlerUPP(AEHandleOApp) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,                               NewAEEventHandlerUPP(AEHandlePDoc) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,                               NewAEEventHandlerUPP(AEHandleRApp) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,                               NewAEEventHandlerUPP(AEHandleQuit) ,                               0 , FALSE ) ;#else        AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,                               NewAEEventHandlerProc(AEHandleODoc) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,                               NewAEEventHandlerProc(AEHandleOApp) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,                               NewAEEventHandlerProc(AEHandlePDoc) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,                               NewAEEventHandlerProc(AEHandleRApp) ,                               0 , FALSE ) ;        AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,                               NewAEEventHandlerProc(AEHandleQuit) ,                               0 , FALSE ) ;#endif    }    return true ;}void wxApp::CleanUp(){    wxToolTip::RemoveToolTips() ;    // One last chance for pending objects to be cleaned up    wxTheApp->DeletePendingObjects();    wxMacDestroyNotifierTable() ;    delete wxWinMacWindowList ;    wxWinMacWindowList = NULL;    delete wxWinMacControlList ;    wxWinMacControlList = NULL;#ifndef __DARWIN__#  if __option(profile)    ProfilerDump( (StringPtr)"\papp.prof" ) ;    ProfilerTerm() ;#  endif#endif#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)    // close shared library resources from here since we don't have    //   __wxterminate in Mach-O shared libraries    wxStAppResource::CloseSharedLibraryResource();#endif    UMACleanupToolbox() ;    if (s_macCursorRgn) {        ::DisposeRgn((RgnHandle)s_macCursorRgn);    }    #if 0        TerminateAE() ;    #endif    wxAppBase::CleanUp();}//----------------------------------------------------------------------// misc initialization stuff//----------------------------------------------------------------------// extern variable for shared library resource id// need to be able to find it with NSLookupAndBindSymbolshort gSharedLibraryResource = kResFileNotOpened ;#if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)CFBundleRef gSharedLibraryBundle = NULL;#endif /* WXMAKINGDLL_CORE && __DARWIN__ */wxStAppResource::wxStAppResource(){    m_currentRefNum = CurResFile() ;    if ( gSharedLibraryResource != kResFileNotOpened )    {        UseResFile( gSharedLibraryResource ) ;    }}wxStAppResource::~wxStAppResource(){    if ( m_currentRefNum != kResFileNotOpened )    {        UseResFile( m_currentRefNum ) ;    }}void wxStAppResource::OpenSharedLibraryResource(const void *initBlock){    gSharedLibraryResource = kResFileNotOpened;#ifdef WXMAKINGDLL_CORE    if ( initBlock != NULL ) {        const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;        FSSpec *fileSpec = NULL;        if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {            fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;        }        else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {            fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;        }        if (fileSpec != NULL) {            gSharedLibraryResource =  FSpOpenResFile(fileSpec, fsRdPerm);        }    }    else {#ifdef __DARWIN__        // Open the shared library resource file if it is not yet open        NSSymbol    theSymbol;        NSModule    theModule;        const char *theLibPath;        gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));        if (gSharedLibraryBundle != NULL) {            // wxWidgets has been bundled into a framework            //   load the framework resources            gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);        }        else {            // wxWidgets is a simple dynamic shared library            //   load the resources from the data fork of a separate resource file            wxString theResPath;            wxString theName;            FSRef  theResRef;            OSErr  theErr = noErr;            // get the library path            theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");            theModule = NSModuleForSymbol(theSymbol);            theLibPath = NSLibraryNameForModule(theModule);            // if we call wxLogDebug from here then, as wxTheApp hasn't been            // created yet when we're called from wxApp::Initialize(), wxLog            // is going to create a default stderr-based log target instead of            // the expected normal GUI one -- don't do it, if we really want

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -