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

📄 textctrl.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            if ( !(m_windowStyle & wxTE_MULTILINE) )            {                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 ;                    }                }                // this will make wxWidgets eat the ENTER key so that                // we actually prevent line wrapping in a single line text control                eat_key = true;            }            break;        case WXK_TAB:            if ( !(m_windowStyle & wxTE_PROCESS_TAB))            {                int flags = 0;                if (!event.ShiftDown())                    flags |= wxNavigationKeyEvent::IsForward ;                if (event.ControlDown())                    flags |= wxNavigationKeyEvent::WinChange ;                Navigate(flags);                return;            }            else            {                // This is necessary (don't know why);                // otherwise the tab will not be inserted.                WriteText(wxT("\t"));                eat_key = true;            }            break;        default:            break;    }    if (!eat_key)    {        // perform keystroke handling        event.Skip(true) ;    }    if ( ( key >= 0x20 && key < WXK_START ) ||         ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) ||         key == WXK_RETURN ||         key == WXK_DELETE ||         key == WXK_BACK)    {        wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);        event1.SetEventObject( this );        wxPostEvent( GetEventHandler(), event1 );    }}// ----------------------------------------------------------------------------// standard handlers for standard edit menu events// ----------------------------------------------------------------------------void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)){    Cut();}void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)){    Copy();}void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)){    Paste();}void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)){    Undo();}void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)){    Redo();}void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)){    long from, to;    GetSelection( &from, &to );    if (from != -1 && to != -1)        Remove( from, to );}void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)){    SetSelection(-1, -1);}void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event){    event.Enable( CanCut() );}void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event){    event.Enable( CanCopy() );}void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event){    event.Enable( CanPaste() );}void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event){    event.Enable( CanUndo() );}void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event){    event.Enable( CanRedo() );}void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event){    long from, to;    GetSelection( &from, &to );    event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ;}void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event){    event.Enable(GetLastPosition() > 0);}// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the momentvoid wxTextCtrl::OnContextMenu(wxContextMenuEvent& event){    if ( GetPeer()->HasOwnContextMenu() )    {        event.Skip() ;        return ;    }    if (m_privateContextMenu == NULL)    {        m_privateContextMenu = new wxMenu;        m_privateContextMenu->Append(wxID_UNDO, _("&Undo"));        m_privateContextMenu->Append(wxID_REDO, _("&Redo"));        m_privateContextMenu->AppendSeparator();        m_privateContextMenu->Append(wxID_CUT, _("Cu&t"));        m_privateContextMenu->Append(wxID_COPY, _("&Copy"));        m_privateContextMenu->Append(wxID_PASTE, _("&Paste"));        m_privateContextMenu->Append(wxID_CLEAR, _("&Delete"));        m_privateContextMenu->AppendSeparator();        m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All"));    }    if (m_privateContextMenu != NULL)        PopupMenu(m_privateContextMenu);}bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ){    if ( !GetPeer()->SetupCursor( pt ) )        return wxWindow::MacSetupCursor( pt ) ;    else        return true ;}#if !TARGET_API_MAC_OSX// user pane implementationvoid wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part){    GetPeer()->MacControlUserPaneDrawProc( part ) ;}wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y){    return GetPeer()->MacControlUserPaneHitTestProc( x , y ) ;}wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc){    return GetPeer()->MacControlUserPaneTrackingProc( x , y , actionProc ) ;}void wxTextCtrl::MacControlUserPaneIdleProc(){    GetPeer()->MacControlUserPaneIdleProc( ) ;}wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers){    return GetPeer()->MacControlUserPaneKeyDownProc( keyCode , charCode , modifiers ) ;}void wxTextCtrl::MacControlUserPaneActivateProc(bool activating){    GetPeer()->MacControlUserPaneActivateProc( activating ) ;}wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action){    return GetPeer()->MacControlUserPaneFocusProc( action ) ;}void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info){    GetPeer()->MacControlUserPaneBackgroundProc( info ) ;}#endif// ----------------------------------------------------------------------------// implementation base class// ----------------------------------------------------------------------------wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) :    wxMacControl( peer ){}wxMacTextControl::~wxMacTextControl(){}void wxMacTextControl::SetStyle(long start, long end, const wxTextAttr& style){}void wxMacTextControl::Copy(){}void wxMacTextControl::Cut(){}void wxMacTextControl::Paste(){}bool wxMacTextControl::CanPaste() const{    return false ;}void wxMacTextControl::SetEditable(bool editable){}wxTextPos wxMacTextControl::GetLastPosition() const{    return GetStringValue().length() ;}void wxMacTextControl::Replace( long from , long to , const wxString &val ){    SetSelection( from , to ) ;    WriteText( val ) ;}void wxMacTextControl::Remove( long from , long to ){    SetSelection( from , to ) ;    WriteText( wxEmptyString) ;}void wxMacTextControl::Clear(){    SetStringValue( wxEmptyString ) ;}bool wxMacTextControl::CanUndo() const{    return false ;}void wxMacTextControl::Undo(){}bool wxMacTextControl::CanRedo()  const{    return false ;}void wxMacTextControl::Redo(){}long wxMacTextControl::XYToPosition(long x, long y) const{    return 0 ;}bool wxMacTextControl::PositionToXY(long pos, long *x, long *y) const{    return false ;}void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ){}int wxMacTextControl::GetNumberOfLines() const{    ItemCount lines = 0 ;    wxString content = GetStringValue() ;    lines = 1;    for (size_t i = 0; i < content.length() ; i++)    {        if (content[i] == '\r')            lines++;    }    return lines ;}wxString wxMacTextControl::GetLineText(long lineNo) const{    // TODO: change this if possible to reflect real lines    wxString content = GetStringValue() ;    // Find line first    int count = 0;    for (size_t i = 0; i < content.length() ; i++)    {        if (count == lineNo)        {            // Add chars in line then            wxString tmp;            for (size_t j = i; j < content.length(); j++)            {                if (content[j] == '\n')                    return tmp;                tmp += content[j];            }            return tmp;        }        if (content[i] == '\n')            count++;    }    return wxEmptyString ;}int wxMacTextControl::GetLineLength(long lineNo) const{    // TODO: change this if possible to reflect real lines    wxString content = GetStringValue() ;    // Find line first    int count = 0;    for (size_t i = 0; i < content.length() ; i++)    {        if (count == lineNo)        {            // Count chars in line then            count = 0;            for (size_t j = i; j < content.length(); j++)            {                count++;                if (content[j] == '\n')                    return count;            }            return count;        }        if (content[i] == '\n')            count++;    }    return 0 ;}// ----------------------------------------------------------------------------// standard unicode control implementation// ----------------------------------------------------------------------------#if TARGET_API_MAC_OSX// the current unicode textcontrol implementation has a bug : only if the control// is currently having the focus, the selection can be retrieved by the corresponding// data tag. So we have a mirroring using a member variable// TODO : build event table using virtual member functions for wxMacControlstatic const EventTypeSpec unicodeTextControlEventList[] ={    { kEventClassControl , kEventControlSetFocusPart } ,} ;static pascal OSStatus wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    wxMacUnicodeTextControl* focus = (wxMacUnicodeTextControl*) data ;    wxMacCarbonEvent cEvent( event ) ;    switch ( GetEventKind( event ) )    {        case kEventControlSetFocusPart :        {            ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );            if ( controlPart == kControlFocusNoPart )            {                // about to loose focus -> store selection to field                focus->GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection );            }            result = CallNextEventHandler(handler,event) ;            if ( controlPart != kControlFocusNoPart )            {                // about to gain focus -> set selection from field                focus->SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection );            }            break;        }        default:            break ;    }    return result ;}static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){    OSStatus result = eventNotHandledErr ;    switch ( GetEventClass( event ) )    {        case kEventClassControl :            result = wxMacUnicodeTextControlControlEventHandler( handler , event , data ) ;            break ;        default :            break ;    }    return result ;}DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler )wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer,    const wxString& str,    const wxPoint& pos,    const wxSize& size, long style )    : wxMacTextControl( wxPeer ){    m_font = wxPeer->GetFont() ;    m_windowStyle = style ;    Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;    wxString st = str ;    wxMacConvertNewlines10To13( &st ) ;    wxMacCFStringHolder cf(st , m_font.GetEncoding()) ;    CFStringRef cfr = cf ;    Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ;    m_valueTag = isPassword ? kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ;    OSStatus err = CreateEditUnicodeTextControl(        MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr ,        isPassword , NULL , &m_controlRef ) ;    verify_noerr( err );    if ( !(m_windowStyle & wxTE_MULTILINE) )        SetData<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ;    InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(),

⌨️ 快捷键说明

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