From c3d0c01c0fc8b382de7d60c2caf6c6a8956debee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Thu, 14 Nov 2013 12:14:57 +0000 Subject: [PATCH] Cancel editing in generic wxDVC when clicking outside of the editor control. wxDataViewCtrl should behave as Explorer does on Windows: when an inline editor control is open, clicking outside of it should close the editor (preserving changes) in most cases - as a rule of thumb, when the subsequent action could interfere with the editor somehow. This was implemented by watching for focus change and so ignored clicks made on non-focusable controls outside of wxDVC's main window area. In particular, clicks on the list's header were ignored, even though they could result in modifications of the editor's position or size. Don't finish editing when the user right-clicks on the header, consistently with Explorer. Opening the menu likewise still doesn't finish editing, it is needed for access to editing operations. Fixes #15152. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75185 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/datavgen.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 6b4bf50e75..a20a7b75fb 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -229,6 +229,8 @@ protected: } private: + void FinishEditing(); + bool SendEvent(wxEventType type, unsigned int n) { wxDataViewCtrl * const owner = GetOwner(); @@ -246,6 +248,8 @@ private: void OnClick(wxHeaderCtrlEvent& event) { + FinishEditing(); + const unsigned idx = event.GetColumn(); if ( SendEvent(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, idx) ) @@ -290,6 +294,8 @@ private: void OnResize(wxHeaderCtrlEvent& event) { + FinishEditing(); + wxDataViewCtrl * const owner = GetOwner(); const unsigned col = event.GetColumn(); @@ -299,6 +305,8 @@ private: void OnEndReorder(wxHeaderCtrlEvent& event) { + FinishEditing(); + wxDataViewCtrl * const owner = GetOwner(); owner->ColumnMoved(owner->GetColumn(event.GetColumn()), event.GetNewOrder()); @@ -769,6 +777,7 @@ public: // Called by wxDataViewCtrl and our own OnRenameTimer() to start edit the // specified item in the given column. void StartEditing(const wxDataViewItem& item, const wxDataViewColumn* col); + void FinishEditing(); private: int RecalculateCount() const; @@ -2194,6 +2203,20 @@ wxDataViewMainWindow::StartEditing(const wxDataViewItem& item, } } +void wxDataViewMainWindow::FinishEditing() +{ + if ( m_editorCtrl ) + { + m_editorRenderer->FinishEditing(); + } +} + +void wxDataViewHeaderWindow::FinishEditing() +{ + wxDataViewMainWindow *win = static_cast(GetOwner()->GetMainWindow()); + win->FinishEditing(); +} + //----------------------------------------------------------------------------- // Helper class for do operation on the tree node //-----------------------------------------------------------------------------