Enable intercepting ENTER in wxSpinCtrl under wxMac by using wxTE_PROCESS_ENTER

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56379 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2008-10-16 22:18:04 +00:00
parent 33a1719a95
commit 724852daae
3 changed files with 24 additions and 6 deletions

View File

@@ -367,6 +367,7 @@ public:
protected: protected:
void OnChar( wxKeyEvent &event ); void OnChar( wxKeyEvent &event );
void OnTextEnter( wxCommandEvent &event );
void OnKillFocus( wxFocusEvent &event ); void OnKillFocus( wxFocusEvent &event );
void OnIdle( wxIdleEvent &event ); void OnIdle( wxIdleEvent &event );

View File

@@ -765,6 +765,7 @@ BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar) EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus) EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle) EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter)
END_EVENT_TABLE() END_EVENT_TABLE()
wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
@@ -789,6 +790,12 @@ void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
event.Skip(); event.Skip();
} }
void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
{
m_finished = true;
m_owner->FinishEditing();
}
void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
{ {
switch ( event.m_keyCode ) switch ( event.m_keyCode )
@@ -799,10 +806,11 @@ void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
break; break;
case WXK_ESCAPE: case WXK_ESCAPE:
{
m_finished = true; m_finished = true;
m_owner->CancelEditing(); m_owner->CancelEditing();
break; break;
}
default: default:
event.Skip(); event.Skip();
} }
@@ -1265,7 +1273,7 @@ wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect la
wxString str; wxString str;
str.Printf( wxT("%d"), (int) l ); str.Printf( wxT("%d"), (int) l );
wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str, wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS, m_min, m_max, l ); labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l );
#ifdef __WXMAC__ #ifdef __WXMAC__
size = sc->GetSize(); size = sc->GetSize();
wxPoint pt = sc->GetPosition(); wxPoint pt = sc->GetPosition();

View File

@@ -41,8 +41,8 @@ static const wxCoord MARGIN = 3;
class wxSpinCtrlText : public wxTextCtrl class wxSpinCtrlText : public wxTextCtrl
{ {
public: public:
wxSpinCtrlText(wxSpinCtrl *spin, const wxString& value) wxSpinCtrlText(wxSpinCtrl *spin, const wxString& value, int style)
: wxTextCtrl(spin , wxID_ANY, value, wxDefaultPosition, wxSize(40, wxDefaultCoord)) : wxTextCtrl(spin , wxID_ANY, value, wxDefaultPosition, wxSize(40, wxDefaultCoord), style )
{ {
m_spin = spin; m_spin = spin;
@@ -60,6 +60,13 @@ public:
} }
protected: protected:
void OnSetFocus(wxFocusEvent& event)
{
// delegate to parent control
event.SetEventObject( GetParent() );
GetParent()->HandleWindowEvent(event);
}
void OnKillFocus(wxFocusEvent& event) void OnKillFocus(wxFocusEvent& event)
{ {
long l; long l;
@@ -96,6 +103,7 @@ protected:
m_spin->m_oldValue = l; m_spin->m_oldValue = l;
} }
// delegate to parent control
event.SetEventObject( GetParent() ); event.SetEventObject( GetParent() );
GetParent()->HandleWindowEvent(event); GetParent()->HandleWindowEvent(event);
} }
@@ -136,7 +144,8 @@ private:
BEGIN_EVENT_TABLE(wxSpinCtrlText, wxTextCtrl) BEGIN_EVENT_TABLE(wxSpinCtrlText, wxTextCtrl)
EVT_TEXT(wxID_ANY, wxSpinCtrlText::OnTextChange) EVT_TEXT(wxID_ANY, wxSpinCtrlText::OnTextChange)
EVT_KILL_FOCUS( wxSpinCtrlText::OnKillFocus) EVT_SET_FOCUS(wxSpinCtrlText::OnSetFocus)
EVT_KILL_FOCUS(wxSpinCtrlText::OnKillFocus)
END_EVENT_TABLE() END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -241,7 +250,7 @@ bool wxSpinCtrl::Create(wxWindow *parent,
} }
wxSize csize = size ; wxSize csize = size ;
m_text = new wxSpinCtrlText(this, value); m_text = new wxSpinCtrlText(this, value, style & wxTE_PROCESS_ENTER ? wxTE_PROCESS_ENTER : 0 );
m_btn = new wxSpinCtrlButton(this, style); m_btn = new wxSpinCtrlButton(this, style);
m_btn->SetRange(min, max); m_btn->SetRange(min, max);