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

📄 app.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            }        }    }    if ( macId == 0 )        macId = (int) wxId ;    return macId ;}wxMenu* wxFindMenuFromMacCommand( const HICommand &command , wxMenuItem* &item ){    wxMenu* itemMenu = NULL ;    int id = 0 ;    // for 'standard' commands which don't have a wx-menu    if ( command.commandID == kHICommandPreferences || command.commandID == kHICommandQuit || command.commandID == kHICommandAbout )    {        id = wxMacCommandToId( command.commandID ) ;        wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;        if ( mbar )            item = mbar->FindItem( id , &itemMenu ) ;    }    else if ( command.commandID != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 )    {        id = wxMacCommandToId( command.commandID ) ;        // make sure it is one of our own menus, or of the 'synthetic' apple and help menus , otherwise don't touch        MenuItemIndex firstUserHelpMenuItem ;        static MenuHandle mh = NULL ;        if ( mh == NULL )        {            if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr )                mh = NULL ;        }        // is it part of the application or the Help menu, then look for the id directly        if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) ||             ( mh != NULL && command.menu.menuRef == mh ) )        {            wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;            if ( mbar )                item = mbar->FindItem( id , &itemMenu ) ;        }        else        {            URefCon refCon ;            GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ;            itemMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ;            if ( itemMenu != NULL )                item = (wxMenuItem*) refCon ;        }    }    return itemMenu ;}//----------------------------------------------------------------------// Carbon Event Handler//----------------------------------------------------------------------static const EventTypeSpec eventList[] ={    { kEventClassCommand, kEventProcessCommand } ,    { kEventClassCommand, kEventCommandUpdateStatus } ,    { kEventClassMenu, kEventMenuOpening },    { kEventClassMenu, kEventMenuClosed },    { kEventClassMenu, kEventMenuTargetItem },    { kEventClassApplication , kEventAppActivated } ,    { kEventClassApplication , kEventAppDeactivated } ,    // handling the quit event is not recommended by apple    // rather using the quit apple event - which we do    { kEventClassAppleEvent , kEventAppleEvent } ,    { kEventClassMouse , kEventMouseDown } ,    { kEventClassMouse , kEventMouseMoved } ,    { kEventClassMouse , kEventMouseUp } ,    { kEventClassMouse , kEventMouseDragged } ,    { 'WXMC' , 'WXMC' }} ;static pascal OSStatuswxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    wxMacCarbonEvent cEvent( event ) ;    MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;    wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;    if ( menu )    {        wxEventType type=0;        MenuCommand cmd=0;        switch (GetEventKind(event))        {            case kEventMenuOpening:                type = wxEVT_MENU_OPEN;                break;            case kEventMenuClosed:                type = wxEVT_MENU_CLOSE;                break;            case kEventMenuTargetItem:                cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;                if (cmd != 0)                    type = wxEVT_MENU_HIGHLIGHT;                break;            default:                wxFAIL_MSG(wxT("Unexpected menu event kind"));                break;        }        if ( type )        {            wxMenuEvent wxevent(type, cmd, menu);            wxevent.SetEventObject(menu);            wxEvtHandler* handler = menu->GetEventHandler();            if (handler && handler->ProcessEvent(wxevent))            {                // handled            }            else            {                wxWindow *win = menu->GetInvokingWindow();                if (win)                    win->GetEventHandler()->ProcessEvent(wxevent);                }            }    }    return eventNotHandledErr;}static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    HICommand command ;    wxMacCarbonEvent cEvent( event ) ;    cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;    wxMenuItem* item = NULL ;    wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ;    int id = wxMacCommandToId( command.commandID ) ;    if ( item )    {        wxASSERT( itemMenu != NULL ) ;        switch ( cEvent.GetKind() )        {            case kEventProcessCommand :            {                if (item->IsCheckable())                    item->Check( !item->IsChecked() ) ;                if ( itemMenu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) )                    result = noErr ;            }            break ;        case kEventCommandUpdateStatus:            {                wxUpdateUIEvent event(id);                event.SetEventObject( itemMenu );                bool processed = false;                // Try the menu's event handler                {                    wxEvtHandler *handler = itemMenu->GetEventHandler();                    if ( handler )                        processed = handler->ProcessEvent(event);                }                // Try the window the menu was popped up from                // (and up through the hierarchy)                if ( !processed )                {                    const wxMenuBase *menu = itemMenu;                    while ( menu )                    {                        wxWindow *win = menu->GetInvokingWindow();                        if ( win )                        {                            processed = win->GetEventHandler()->ProcessEvent(event);                            break;                        }                        menu = menu->GetParent();                    }                }                if ( processed )                {                    // if anything changed, update the changed attribute                    if (event.GetSetText())                        itemMenu->SetLabel(id, event.GetText());                    if (event.GetSetChecked())                        itemMenu->Check(id, event.GetChecked());                    if (event.GetSetEnabled())                        itemMenu->Enable(id, event.GetEnabled());                    result = noErr ;                }            }            break ;        default :            break ;        }    }    return result ;}static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    switch ( GetEventKind( event ) )    {        case kEventAppActivated :            if ( wxTheApp )                wxTheApp->SetActive( true , NULL ) ;            result = noErr ;            break ;        case kEventAppDeactivated :            if ( wxTheApp )                wxTheApp->SetActive( false , NULL ) ;            result = noErr ;            break ;        default :            break ;    }    return result ;}pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;    EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;    wxTheApp->MacSetCurrentEvent( event , handler ) ;    OSStatus result = eventNotHandledErr ;    switch ( GetEventClass( event ) )    {        case kEventClassCommand :            result = wxMacAppCommandEventHandler( handler , event , data ) ;            break ;        case kEventClassApplication :            result = wxMacAppApplicationEventHandler( handler , event , data ) ;            break ;        case kEventClassMenu :            result = wxMacAppMenuEventHandler( handler , event , data ) ;            break ;        case kEventClassMouse :            {                wxMacCarbonEvent cEvent( event ) ;                WindowRef window ;                Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;                ::FindWindow(screenMouseLocation, &window);                // only send this event in case it had not already been sent to a tlw, as we get                // double events otherwise (in case event.skip) was called                if ( window == NULL )                    result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;            }            break ;        case kEventClassAppleEvent :            {                EventRecord rec ;                wxMacConvertEventToRecord( event , &rec ) ;                result = AEProcessAppleEvent( &rec ) ;            }            break ;        default :            break ;    }    wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;    return result ;}DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler )#ifdef __WXDEBUG__pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options,    const char *assertionString, const char *exceptionLabelString,    const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg){    // flow into assert handling    wxString fileNameStr ;    wxString assertionStr ;    wxString exceptionStr ;    wxString errorStr ;#if wxUSE_UNICODE    fileNameStr = wxString(fileName, wxConvLocal);    assertionStr = wxString(assertionString, wxConvLocal);    exceptionStr = wxString((exceptionLabelString!=0) ? exceptionLabelString : "", wxConvLocal) ;    errorStr = wxString((errorString!=0) ? errorString : "", wxConvLocal) ;#else    fileNameStr = fileName;    assertionStr = assertionString;    exceptionStr = (exceptionLabelString!=0) ? exceptionLabelString : "" ;    errorStr = (errorString!=0) ? errorString : "" ;#endif#if 1    // flow into log    wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %ld (value %p)\n"),        assertionStr.c_str() ,        exceptionStr.c_str() ,        errorStr.c_str(),        fileNameStr.c_str(), lineNumber ,        value ) ;#else    wxOnAssert(fileNameStr, lineNumber , assertionStr ,        wxString::Format( wxT("%s %s value (%p)") , exceptionStr, errorStr , value ) ) ;#endif}#endif //__WXDEBUG__#ifdef __WXMAC_OSX__extern "C"{   // m_macEventPosted run loop source callback:   void macPostedEventCallback(void *unused);}void macPostedEventCallback(void *unused){    wxTheApp->ProcessPendingEvents();}#endifbool wxApp::Initialize(int& argc, wxChar **argv){    // Mac-specific#ifdef __WXDEBUG__    InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );#endif    UMAInitToolbox( 4, sm_isEmbedded ) ;    SetEventMask( everyEvent ) ;    UMAShowWatchCursor() ;#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    // 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#if TARGET_API_MAC_OSX    // these might be the startup dirs, set them to the 'usual' dir containing the app bundle    wxString startupCwd = wxGetCwd() ;    if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") )    {        CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ;        CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ;        CFRelease( url ) ;        CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ;        CFRelease( urlParent ) ;        wxString cwd = wxMacCFStringHolder(path).AsString(wxLocale::GetSystemEncoding());        wxSetWorkingDirectory( cwd ) ;    }#endif    wxMacCreateNotifierTable() ;#ifdef __WXMAC_OSX__    /* connect posted events to common-mode run loop so that wxPostEvent events       are handled even while we're in the menu or on a scrollbar */

⌨️ 快捷键说明

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