Fix inplace editing of custom controls for

GTK+ variant of wxDataViewCtrl.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45536 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-04-19 12:47:47 +00:00
parent 8db4a5d27a
commit 30715fa195
3 changed files with 28 additions and 6 deletions

View File

@@ -24,7 +24,7 @@
#if defined(__WXGTK20__) #if defined(__WXGTK20__)
// for testing // for testing
#define wxUSE_GENERICDATAVIEWCTRL 1 // #define wxUSE_GENERICDATAVIEWCTRL 1
#elif defined(__WXMAC__) #elif defined(__WXMAC__)
#define wxUSE_GENERICDATAVIEWCTRL 1 #define wxUSE_GENERICDATAVIEWCTRL 1
#else #else
@@ -243,15 +243,18 @@ public:
wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner ); wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
void AcceptChangesAndFinish(); void AcceptChangesAndFinish();
void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
protected: protected:
void OnChar( wxKeyEvent &event ); void OnChar( wxKeyEvent &event );
void OnKillFocus( wxFocusEvent &event ); void OnKillFocus( wxFocusEvent &event );
void OnIdle( wxIdleEvent &event );
private: private:
wxDataViewRenderer *m_owner; wxDataViewRenderer *m_owner;
wxControl *m_editorCtrl; wxControl *m_editorCtrl;
bool m_finished; bool m_finished;
bool m_focusOnIdle;
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@@ -487,7 +490,7 @@ public:
private: private:
wxDataViewListModel *m_model; wxDataViewListModel *m_model;
wxList m_cols; wxList m_cols;
protected: protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
}; };

View File

@@ -728,11 +728,17 @@ bool wxDataViewRendererBase::StartEditing( unsigned int row, wxRect labelRect )
m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
m_editorCtrl->PushEventHandler( wxDataViewEditorCtrlEvtHandler *handler =
new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ) ); new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
m_editorCtrl->PushEventHandler( handler );
#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
handler->SetFocusOnIdle();
#else
m_editorCtrl->SetFocus(); m_editorCtrl->SetFocus();
#endif
return true; return true;
} }
@@ -773,6 +779,7 @@ bool wxDataViewRendererBase::FinishEditing()
BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler) 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)
END_EVENT_TABLE() END_EVENT_TABLE()
wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
@@ -785,6 +792,18 @@ wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
m_finished = false; m_finished = false;
} }
void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
{
if (m_focusOnIdle)
{
m_focusOnIdle = false;
if (wxWindow::FindFocus() != m_editorCtrl)
m_editorCtrl->SetFocus();
}
event.Skip();
}
void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
{ {
switch ( event.m_keyCode ) switch ( event.m_keyCode )

View File

@@ -595,7 +595,7 @@ static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
gtk_tree_path_free( treepath ); gtk_tree_path_free( treepath );
cell->StartEditing( model_row, renderrect ); cell->StartEditing( model_row, renderrect );
return NULL; return NULL;
} }