void wxTextCtrl::OnChar(wxKeyEvent& event) { switch ( event.GetKeyCode() ) { case WXK_RETURN: if ( !HasFlag(wxTE_MULTILINE) ) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); InitCommandEvent(event); event.SetString(GetValue()); if ( GetEventHandler()->ProcessEvent(event) ) return; } //else: multiline controls need Enter for themselves break; case WXK_TAB: // ok, so this is getting absolutely ridiculous but I don't see // any other way to fix this bug: when a multiline text control is // inside a wxFrame, we need to generate the navigation event as // otherwise nothing happens at all, but when the same control is // created inside a dialog, IsDialogMessage() *does* switch focus // all by itself and so if we do it here as well, it is advanced // twice and goes to the next control... to prevent this from // happening we're doing this ugly check, the logic being that if // we don't have focus then it had been already changed to the next // control // // the right thing to do would, of course, be to understand what // the hell is IsDialogMessage() doing but this is beyond my feeble // forces at the moment unfortunately if ( !(m_windowStyle & wxTE_PROCESS_TAB)) { if ( FindFocus() == this ) { int flags = 0; if (!event.ShiftDown()) flags |= wxNavigationKeyEvent::IsForward ; if (event.ControlDown()) flags |= wxNavigationKeyEvent::WinChange ; if (Navigate(flags)) return; } } else { // Insert tab since calling the default Windows handler // doesn't seem to do it WriteText(wxT("\t")); } break; } // no, we didn't process it event.Skip(); }
/***** Intercept the ENTER key and spit out a wxEVT_COMMAND_TEXT_ENTER event. *****/ void RFTextCtrl::OnChar(wxKeyEvent& event) { int key = event.GetKeyCode(); if (key == WXK_NUMPAD_ENTER) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId()); event.SetEventObject(this); event.SetString(GetValue()); if (GetEventHandler()->ProcessEvent(event)) return; } event.Skip(); }
void wxSpinCtrl::OnChar(wxKeyEvent& event) { switch ( event.GetKeyCode() ) { case WXK_RETURN: { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); InitCommandEvent(event); wxString val = wxGetWindowText(m_hwndBuddy); event.SetString(val); event.SetInt(GetValue()); if ( GetEventHandler()->ProcessEvent(event) ) return; break; } case WXK_TAB: // always produce navigation event - even if we process TAB // ourselves the fact that we got here means that the user code // decided to skip processing of this TAB - probably to let it // do its default job. { wxNavigationKeyEvent eventNav; eventNav.SetDirection(!event.ShiftDown()); eventNav.SetWindowChange(event.ControlDown()); eventNav.SetEventObject(this); if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) return; } break; } // no, we didn't process it event.Skip(); }
void wxTextCtrl::OnChar(wxKeyEvent& event) { int key = event.GetKeyCode() ; bool eat_key = false ; long from, to; if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) && !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END ) { // eat it return ; } if ( !GetTextPeer()->CanClipMaxLength() ) { // Check if we have reached the max # of chars (if it is set), but still // allow navigation and deletion GetSelection( &from, &to ); if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && from == to ) { // eat it, we don't want to add more than allowed # of characters // TODO: generate EVT_TEXT_MAXLEN() return; } } // assume that any key not processed yet is going to modify the control m_dirty = true; switch ( key ) { case WXK_RETURN: if (m_windowStyle & wxTE_PROCESS_ENTER) { wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId); event.SetEventObject( this ); event.SetString( GetValue() ); if ( HandleWindowEvent(event) ) return; } 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_BUTTON, 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) ; } // osx_cocoa sends its event upon insertText #if wxOSX_USE_CARBON if ( ( key >= 0x20 && key < WXK_START ) || ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || key == WXK_RETURN || key == WXK_DELETE || key == WXK_BACK) { wxCommandEvent event1(wxEVT_TEXT, m_windowId); event1.SetEventObject( this ); wxPostEvent( GetEventHandler(), event1 ); } #endif }
void wxListBox::OnChar(wxKeyEvent& event) { if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) { 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 ; } } event.Skip() ; } /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) ) { // FIXME: look in ancestors, not just parent. wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ; if (win) { wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); new_event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( new_event ); } } else if ( event.GetKeyCode() == WXK_TAB ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( this ); new_event.SetDirection( !event.ShiftDown() ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( event.ControlDown() ); new_event.SetCurrentFocus( this ); if ( !GetEventHandler()->ProcessEvent( new_event ) ) event.Skip() ; } else if ( event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_UP ) { // perform the default key handling first wxControl::OnKeyDown( event ) ; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); event.SetEventObject( this ); wxArrayInt aSelections; int n, count = GetSelections(aSelections); if ( count > 0 ) { n = aSelections[0]; if ( HasClientObjectData() ) event.SetClientObject( GetClientObject(n) ); else if ( HasClientUntypedData() ) event.SetClientData( GetClientData(n) ); event.SetString(GetString(n)); } else { n = -1; } event.SetInt(n); GetEventHandler()->ProcessEvent(event); } else { if ( event.GetTimestamp() > m_lastTypeIn + 60 ) { m_typeIn = wxEmptyString ; } m_lastTypeIn = event.GetTimestamp() ; m_typeIn += (char) event.GetKeyCode() ; int line = FindString(wxT("*")+m_typeIn+wxT("*")) ; if ( line >= 0 ) { if ( GetSelection() != line ) { SetSelection(line) ; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); event.SetEventObject( this ); if ( HasClientObjectData() ) event.SetClientObject( GetClientObject( line ) ); else if ( HasClientUntypedData() ) event.SetClientData( GetClientData(line) ); event.SetString(GetString(line)); event.SetInt(line); GetEventHandler()->ProcessEvent(event); } } } }