From 6395e7805a0a57aa3df34675a82f8922bc635271 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 16 Jul 2017 19:15:07 +0200 Subject: [PATCH] Fix repositioning of active property editor in wxPG When there is open an editor for some property and in the same time wxPropertyGrid layout is changed (due to the adding or removing a property, sorting), it is necessary to recalculate the actual position of the active editor to display it in the cell dedicated for the edited property. Under some platforms the position of the edit control is shifted within the cell and we have to take this shift into account in repositioning process. Because actual value of the shift depends on the platform and on the particular control, it is convenient to determine actual shift when the editor is created and use this value whenever repositioning is done. Close #17912. --- include/wx/propgrid/propgrid.h | 6 +++++- src/propgrid/editors.cpp | 18 +++--------------- src/propgrid/propgrid.cpp | 13 +++++++++++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 455570d13d..7c8b22d1f5 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1465,6 +1465,9 @@ protected: // wxWindow pointers to editor control(s). wxWindow *m_wndEditor; wxWindow *m_wndEditor2; + // Actual positions of the editors within the cell. + wxPoint m_wndEditorPosRel; + wxPoint m_wndEditor2PosRel; wxBitmap *m_doubleBuffer; @@ -1644,8 +1647,9 @@ protected: // pointer to property that has mouse hovering wxPGProperty* m_propHover; - // Active label editor + // Active label editor and its actual position within the cell wxTextCtrl* m_labelEditor; + wxPoint m_labelEditorPosRel; // For which property the label editor is active wxPGProperty* m_labelEditorProperty; diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index 7288acd256..7124d86973 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -1835,12 +1835,7 @@ void wxPropertyGrid::CorrectEditorWidgetPosY() if ( m_labelEditor ) { wxRect r = GetEditorWidgetRect(selected, m_selColumn); - wxPoint pos = m_labelEditor->GetPosition(); - - // Calculate y offset - int offset = pos.y % m_lineHeight; - - m_labelEditor->Move(pos.x, r.y + offset); + m_labelEditor->Move(r.GetPosition() + m_labelEditorPosRel); } if ( m_wndEditor || m_wndEditor2 ) @@ -1849,19 +1844,12 @@ void wxPropertyGrid::CorrectEditorWidgetPosY() if ( m_wndEditor ) { - wxPoint pos = m_wndEditor->GetPosition(); - - // Calculate y offset - int offset = pos.y % m_lineHeight; - - m_wndEditor->Move(pos.x, r.y + offset); + m_wndEditor->Move(r.GetPosition() + m_wndEditorPosRel); } if ( m_wndEditor2 ) { - wxPoint pos = m_wndEditor2->GetPosition(); - - m_wndEditor2->Move(pos.x, r.y); + m_wndEditor2->Move(r.GetPosition() + m_wndEditor2PosRel); } } } diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index b1c878c6f1..0b207b79f7 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -1039,6 +1039,8 @@ void wxPropertyGrid::DoBeginLabelEdit( unsigned int colIndex, tc->SetFocus(); m_labelEditor = wxStaticCast(tc, wxTextCtrl); + // Get actual position within required rectangle + m_labelEditorPosRel = m_labelEditor->GetPosition() - r.GetPosition(); m_labelEditorProperty = selected; } @@ -4198,6 +4200,17 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) m_wndEditor = wndList.m_primary; m_wndEditor2 = wndList.m_secondary; + // Remember actual positions within required cell. + // These values can be used when there will be required + // to reposition the cell. + if ( m_wndEditor ) + { + m_wndEditorPosRel = m_wndEditor->GetPosition() - goodPos; + } + if ( m_wndEditor2 ) + { + m_wndEditor2PosRel = m_wndEditor2->GetPosition() - goodPos; + } primaryCtrl = GetEditorControl(); //