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

📄 app.cpp

📁 wxWidgets 是一个跨平台的 GUI 框架。它给开发人员提供了统一的接口
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                 retval = WXK_HELP;          break;        case kBackspaceCharCode :                 retval = WXK_BACK;          break;        case kTabCharCode :                 retval = WXK_TAB;          break;        case kPageUpCharCode :                 retval = WXK_PAGEUP;          break;        case kPageDownCharCode :                 retval = WXK_PAGEDOWN;          break;        case kReturnCharCode :                 retval = WXK_RETURN;          break;            case kFunctionKeyCharCode :            {                switch( code )                {                    case 0x7a :                        retval = WXK_F1 ;                        break;                    case 0x78 :                        retval = WXK_F2 ;                        break;                    case 0x63 :                        retval = WXK_F3 ;                        break;                    case 0x76 :                        retval = WXK_F4 ;                        break;                    case 0x60 :                        retval = WXK_F5 ;                        break;                    case 0x61 :                        retval = WXK_F6 ;                        break;                    case 0x62:                        retval = WXK_F7 ;                        break;                    case 0x64 :                        retval = WXK_F8 ;                        break;                    case 0x65 :                        retval = WXK_F9 ;                        break;                    case 0x6D :                        retval = WXK_F10 ;                        break;                    case 0x67 :                        retval = WXK_F11 ;                        break;                    case 0x6F :                        retval = WXK_F12 ;                        break;                    case 0x69 :                        retval = WXK_F13 ;                        break;                    case 0x6B :                        retval = WXK_F14 ;                        break;                    case 0x71 :                        retval = WXK_F15 ;                        break;                }            }            break ;            case kEscapeCharCode :                retval = WXK_ESCAPE ;            break ;            case kLeftArrowCharCode :                retval = WXK_LEFT ;            break ;            case kRightArrowCharCode :                retval = WXK_RIGHT ;            break ;            case kUpArrowCharCode :                retval = WXK_UP ;            break ;            case kDownArrowCharCode :                retval = WXK_DOWN ;            break ;            case kDeleteCharCode :                retval = WXK_DELETE ;             default:            break ;     } // end switch    return retval;}int wxKeyCodeToMacModifier(wxKeyCode key){    switch (key)    {    case WXK_START:    case WXK_MENU:        return cmdKey;    case WXK_SHIFT:        return shiftKey;    case WXK_CAPITAL:        return alphaLock;    case WXK_ALT:        return optionKey;    case WXK_CONTROL:        return controlKey;    default:        return 0;    }}bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below{    wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=        WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));    KeyMap keymap;    GetKeys(keymap);    return !!(BitTst(keymap, (sizeof(KeyMap)*8) - key));}#if !TARGET_CARBONvoid wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ){    EventRecord* ev = (EventRecord*) evr ;    wxToolTip::RemoveToolTips() ;    UInt32 menuresult = UMAMenuEvent(ev) ;    if ( HiWord( menuresult ) )    {        if ( !s_macIsInModalLoop )            MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;    }    else    {         wxWindow* focus = wxWindow::FindFocus() ;        if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )        {#if 0            // we must handle control keys the other way round, otherwise text content is updated too late            // has not been handled -> perform default            wxControl* control = wxDynamicCast( focus , wxControl ) ;            if ( control &&  control->GetMacControl() != NULL )            {                short keycode ;                short keychar ;                keychar = short(ev->message & charCodeMask);                keycode = short(ev->message & keyCodeMask) >> 8 ;                ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;            }#endif        }    }}void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ){    EventRecord* ev = (EventRecord*) evr ;    wxToolTip::RemoveToolTips() ;    UInt32 menuresult = UMAMenuEvent(ev) ;    if ( HiWord( menuresult ) )    {    }    else    {        MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;    }}#endifbool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ){    if ( !focus )        return false ;    short keycode ;    short keychar ;    keychar = short(keymessage & charCodeMask);    keycode = short(keymessage & keyCodeMask) >> 8 ;    if ( modifiers & ( controlKey|shiftKey|optionKey ) )    {        // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier        // and look at the character after        UInt32 state = 0;        UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);        keychar = short(keyInfo & charCodeMask);        keycode = short(keyInfo & keyCodeMask) >> 8 ;    }    long keyval = wxMacTranslateKey(keychar, keycode) ;    long realkeyval = keyval ;    if ( keyval == keychar )    {        // 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)        realkeyval = short(keymessage & charCodeMask) ;        keyval = wxToupper( keyval ) ;    }    wxKeyEvent event(wxEVT_KEY_DOWN);    bool handled = false ;    event.m_shiftDown = modifiers & shiftKey;    event.m_controlDown = modifiers & controlKey;    event.m_altDown = modifiers & optionKey;    event.m_metaDown = modifiers & cmdKey;    event.m_keyCode = keyval ;    event.m_x = wherex;    event.m_y = wherey;    event.SetTimestamp(when);    event.SetEventObject(focus);    handled = focus->GetEventHandler()->ProcessEvent( event ) ;    if ( handled && event.GetSkipped() )        handled = false ;    if ( !handled )    {#if wxUSE_ACCEL        if (!handled)        {            wxWindow *ancestor = focus;            while (ancestor)            {                int command = ancestor->GetAcceleratorTable()->GetCommand( event );                if (command != -1)                {                    wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );                    handled = ancestor->GetEventHandler()->ProcessEvent( command_event );                    break;                }                if (ancestor->IsTopLevel())                    break;                ancestor = ancestor->GetParent();            }        }#endif // wxUSE_ACCEL    }    if (!handled)    {        event.Skip( false ) ;        event.SetEventType( wxEVT_CHAR ) ;        // raw value again        event.m_keyCode = realkeyval ;        handled = focus->GetEventHandler()->ProcessEvent( event ) ;        if ( handled && event.GetSkipped() )            handled = false ;    }    if ( !handled &&         (keyval == WXK_TAB) &&// CS: copied the change below from wxGTK// VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may//     have this style, yet choose not to process this particular TAB in which//     case TAB must still work as a navigational character#if 0         (!focus->HasFlag(wxTE_PROCESS_TAB)) &&#endif         (focus->GetParent()) &&         (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )    {        wxNavigationKeyEvent new_event;        new_event.SetEventObject( focus );        new_event.SetDirection( !event.ShiftDown() );        /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */        new_event.SetWindowChange( event.ControlDown() );        new_event.SetCurrentFocus( focus );        handled = focus->GetEventHandler()->ProcessEvent( new_event );        if ( handled && new_event.GetSkipped() )            handled = false ;    }    // backdoor handler for default return and command escape    if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )    {        // if window is not having a focus still testing for default enter or cancel        // TODO add the UMA version for ActiveNonFloatingWindow        wxWindow* focus = wxFindWinFromMacWindow( (WXWindow) FrontWindow() ) ;        if ( focus )        {            if ( keyval == WXK_RETURN )            {                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);                if ( tlw && tlw->GetDefaultItem() )                {                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);                    if ( def && def->IsEnabled() )                    {                        wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );                        event.SetEventObject(def);                        def->Command(event);                        return true ;                    }                }            }            /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */            else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )            {                wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);                new_event.SetEventObject( focus );                handled = focus->GetEventHandler()->ProcessEvent( new_event );            }        }    }    return handled ;}bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ){    if ( !focus )        return false ;    short keycode ;    short keychar ;    keychar = short(keymessage & charCodeMask);    keycode = short(keymessage & keyCodeMask) >> 8 ;    if ( modifiers & ( controlKey|shiftKey|optionKey ) )    {        // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier        // and look at the character after        UInt32 state = 0;        UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);        keychar = short(keyInfo & charCodeMask);        keycode = short(keyInfo & keyCodeMask) >> 8 ;    }    long keyval = wxMacTranslateKey(keychar, keycode) ;    if ( keyval == keychar )    {        keyval = wxToupper( keyval ) ;    }    bool handled = false ;    wxKeyEvent event(wxEVT_KEY_UP);    event.m_shiftDown = modifiers & shiftKey;    event.m_controlDown = modifiers & controlKey;    event.m_altDown = modifiers & optionKey;    event.m_metaDown = modifiers & cmdKey;    event.m_keyCode = keyval ;    event.m_x = wherex;    event.m_y = wherey;    event.SetTimestamp(when);    event.SetEventObject(focus);    handled = focus->GetEventHandler()->ProcessEvent( event ) ;    return handled ;}#if !TARGET_CARBONvoid wxApp::MacHandleActivateEvent( WXEVENTREF evr ){    EventRecord* ev = (EventRecord*) evr ;    WindowRef window = (WindowRef) ev->message ;    if ( window )    {        bool activate = (ev->modifiers & activeFlag ) ;        WindowClass wclass ;        ::GetWindowClass ( window , &wclass ) ;        if ( wclass == kFloatingWindowClass )        {            // if it is a floater we activate/deactivate the front non-floating window instead            window = ::FrontNonFloatingWindow() ;        }        wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;        if ( win )            win->MacActivate( ev->when , activate ) ;    }}void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ){    EventRecord* ev = (EventRecord*) evr ;    WindowRef window = (WindowRef) ev->message ;    wxTopLevelWindowMac * win = wxFindWinFromMacWindow( (WXWindow) window ) ;    if ( win )    {        if ( !wxPendingDelete.Member(win) )            win->MacUpdate( ev->when ) ;    }    else    {        // since there is no way of telling this foreign window to update itself        // we have to invalidate the update region otherwise we keep getting the same        // event over and over again        BeginUpdate( window ) ;        EndUpdate( window ) ;    }}void wxApp::MacHandleDiskEvent( WXEVENTREF evr ){    EventRecord* ev = (EventRecord*) evr ;    if ( HiWord( ev->message ) != noErr )  {        OSErr err ;        Point point ;         SetPt( &point , 100 , 100 ) ;          err = DIBadMount( point , ev->message ) ;        wxASSERT( err == noErr ) ;    }}void wxApp::MacHandleOSEvent( WXEVENTREF evr ){    EventRecord* ev = (EventRecord*) evr ;    switch( ( ev->message & osEvtMessageMask ) >> 24 )    {        case suspendResumeMessage :            {                bool isResuming = ev->message & resumeFlag ;                bool convertClipboard = ev->message & convertClipboardFlag ;                bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;                if ( isResuming )                {                    WindowRef oldFrontWindow = NULL ;                    WindowRef newFrontWindow = NULL ;                    // in case we don't take care of activating ourselves, we have to synchronize                    // our idea of the active window with the process manager's - which it already activated                    if ( !doesActivate )                        oldFrontWindow = ::Fron

⌨️ 快捷键说明

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