From 42b1cca8f2ff0c902fff8db9efc8b3487b654598 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 4 Jan 2019 19:50:44 +0100 Subject: [PATCH] Fix repositioning editors for horizontally scrolled grid New method of calculating of the new position/size of the editor (introduced in 95461c566d) doesn't work well in all cases so we have to go back to the (modified) old method. To get the correct position of the editor cell from the absolute position of the splitter 0 we have to shift it by the origin of the scrolled view area. See #18313. --- include/wx/propgrid/propgrid.h | 6 ------ src/propgrid/editors.cpp | 30 ++--------------------------- src/propgrid/propgrid.cpp | 35 ++++++---------------------------- 3 files changed, 8 insertions(+), 63 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index f7b444c21d..114a02f19b 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1687,10 +1687,8 @@ protected: // Which column's editor is selected (usually 1)? unsigned int m_selColumn; -#if WXWIN_COMPATIBILITY_3_0 // x relative to splitter (needed for resize). int m_ctrlXAdjust; -#endif // WXWIN_COMPATIBILITY_3_0 // lines between cells wxColour m_colLine; // property labels and values are written in this colour @@ -1803,11 +1801,7 @@ protected: wxRect GetEditorWidgetRect( wxPGProperty* p, int column ) const; -#if WXWIN_COMPATIBILITY_3_0 - wxDEPRECATED_MSG("Don't use this function. It works only if horizontal scrolling is not active") void CorrectEditorWidgetSizeX(); -#endif // WXWIN_COMPATIBILITY_3_0 - void CorrectEditorWidgetSizeX(int xPosChange, int widthChange); // Called in RecalculateVirtualSize() to reposition control // on virtual height changes. diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index b4dc593346..c2c3349096 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -1774,13 +1774,13 @@ wxWindow* wxPropertyGrid::GetEditorControl() const // ----------------------------------------------------------------------- -#if WXWIN_COMPATIBILITY_3_0 void wxPropertyGrid::CorrectEditorWidgetSizeX() { int secWid = 0; // Use fixed selColumn 1 for main editor widgets - int newSplitterx = m_pState->DoGetSplitterPosition(0); + int newSplitterx; + CalcScrolledPosition(m_pState->DoGetSplitterPosition(0), 0, &newSplitterx, NULL); int newWidth = newSplitterx + m_pState->GetColumnWidth(1); if ( m_wndEditor2 ) @@ -1816,32 +1816,6 @@ void wxPropertyGrid::CorrectEditorWidgetSizeX() if ( m_wndEditor2 ) m_wndEditor2->Refresh(); } -#endif // WXWIN_COMPATIBILITY_3_0 - -void wxPropertyGrid::CorrectEditorWidgetSizeX(int xPosChange, int widthChange) -{ - if ( m_wndEditor2 ) - { - // if width change occurred, move secondary wnd by that amount - wxPoint p = m_wndEditor2->GetPosition(); - p.x += xPosChange + widthChange; - m_wndEditor2->SetPosition(p); - } - - if ( m_wndEditor ) - { - wxRect r = m_wndEditor->GetRect(); - r.x += xPosChange; - - if ( !(m_iFlags & wxPG_FL_FIXED_WIDTH_EDITOR) ) - r.width += widthChange; - - m_wndEditor->SetSize(r); - } - - if ( m_wndEditor2 ) - m_wndEditor2->Refresh(); -} // ----------------------------------------------------------------------- diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 58edff27e2..760f7ffaa3 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -2791,19 +2791,13 @@ void wxPropertyGrid::DoSetSplitterPosition( int newxpos, if ( flags & wxPG_SPLITTER_FROM_EVENT ) m_pState->m_dontCenterSplitter = true; - // Save position and size of column 1 used for main editor widgets - int xPosEditorCol = m_pState->DoGetSplitterPosition(0); - int widthEditorCol = m_pState->GetColumnWidth(1); - m_pState->DoSetSplitterPosition(newxpos, splitterIndex, flags); if ( flags & wxPG_SPLITTER_REFRESH ) { if ( GetSelection() ) { - int xPosChange = m_pState->DoGetSplitterPosition(0) - xPosEditorCol; - int widthColChange = m_pState->GetColumnWidth(1) - widthEditorCol; - CorrectEditorWidgetSizeX(xPosChange, widthColChange); + CorrectEditorWidgetSizeX(); } Refresh(); @@ -2818,16 +2812,10 @@ void wxPropertyGrid::ResetColumnSizes( bool enableAutoResizing ) { if ( m_pState ) { - // Save position and size of column 1 used for main editor widgets - int xPosEditorCol = m_pState->DoGetSplitterPosition(0); - int widthEditorCol = m_pState->GetColumnWidth(1); - m_pState->ResetColumnSizes(0); if ( GetSelection() ) { - int xPosChange = m_pState->DoGetSplitterPosition(0) - xPosEditorCol; - int widthColChange = m_pState->GetColumnWidth(1) - widthEditorCol; - CorrectEditorWidgetSizeX(xPosChange, widthColChange); + CorrectEditorWidgetSizeX(); } Refresh(); @@ -4142,7 +4130,9 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) { int propY = p->GetY2(m_lineHeight); - int splitterX = GetSplitterPosition(); + int splitterX; + CalcScrolledPosition(GetSplitterPosition(), 0, &splitterX, NULL); + m_editorFocused = false; m_iFlags |= wxPG_FL_PRIMARY_FILLS_ENTIRE; @@ -4227,10 +4217,8 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) if ( p->HasFlag(wxPG_PROP_MODIFIED) && (m_windowStyle & wxPG_BOLD_MODIFIED) ) SetCurControlBoldFont(); -#if WXWIN_COMPATIBILITY_3_0 // Store x relative to splitter (we'll need it). m_ctrlXAdjust = m_wndEditor->GetPosition().x - splitterX; -#endif // WXWIN_COMPATIBILITY_3_0 // Check if background clear is not necessary wxPoint pos = m_wndEditor->GetPosition(); @@ -4563,13 +4551,6 @@ void wxPropertyGrid::RecalculateVirtualSize( int forceXPos ) m_iFlags |= wxPG_FL_RECALCULATING_VIRTUAL_SIZE; - // Save position and size of column 1 used for main editor widgets - int vx; - GetViewStart(&vx, NULL); - vx *= wxPG_PIXELS_PER_UNIT; - int xPosEditorCol = m_pState->DoGetSplitterPosition(0) - vx; - int widthEditorCol = m_pState->GetColumnWidth(1); - int x = m_pState->GetVirtualWidth(); int y = m_pState->m_virtualHeight; @@ -4622,11 +4603,7 @@ void wxPropertyGrid::RecalculateVirtualSize( int forceXPos ) if ( GetSelection() ) { - GetViewStart(&vx, NULL); - vx *= wxPG_PIXELS_PER_UNIT; - int xPosChange = m_pState->DoGetSplitterPosition(0) - vx - xPosEditorCol; - int widthColChange = m_pState->GetColumnWidth(1) - widthEditorCol; - CorrectEditorWidgetSizeX(xPosChange, widthColChange); + CorrectEditorWidgetSizeX(); } m_iFlags &= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE;