diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 6175ef2580..8c07b1cc3d 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2534,18 +2534,26 @@ private: void DoColHeaderClick(int col); - void DoStartResizeCol(int col); - void DoUpdateResizeColWidth(int w); void DoStartMoveCol(int col); void DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow *gridWindow); void DoEndDragResizeCol(const wxMouseEvent& event, wxGridWindow *gridWindow); - void DoEndDragResizeCol(const wxMouseEvent& event) - { - DoEndDragResizeCol(event, m_gridWin); - } void DoEndMoveCol(int pos); + // Helper function returning the position (only the horizontal component + // really counts) corresponding to the given column drag-resize event. + // + // It's a bit ugly to create a phantom mouse position when we really only + // need the column width anyhow, but wxGrid code was originally written to + // expect the position and not the width and it's simpler to keep it happy + // by giving it the position than to change it. + wxPoint GetPositionForResizeEvent(int width) const; + + // functions called by wxGridHeaderCtrl while resizing m_dragRowOrCol + void DoHeaderStartDragResizeCol(int col); + void DoHeaderDragResizeCol(int width); + void DoHeaderEndDragResizeCol(int width); + // process a TAB keypress void DoGridProcessTab(wxKeyboardState& kbdState); diff --git a/include/wx/generic/private/grid.h b/include/wx/generic/private/grid.h index 96755a089c..216491fa89 100644 --- a/include/wx/generic/private/grid.h +++ b/include/wx/generic/private/grid.h @@ -252,24 +252,19 @@ private: void OnBeginResize(wxHeaderCtrlEvent& event) { - GetOwner()->DoStartResizeCol(event.GetColumn()); + GetOwner()->DoHeaderStartDragResizeCol(event.GetColumn()); event.Skip(); } void OnResizing(wxHeaderCtrlEvent& event) { - GetOwner()->DoUpdateResizeColWidth(event.GetWidth()); + GetOwner()->DoHeaderDragResizeCol(event.GetWidth()); } void OnEndResize(wxHeaderCtrlEvent& event) { - // we again need to pass a mouse event to be used for the grid event - // generation but we don't have it here so use a dummy one as in - // UpdateColumnVisibility() - wxMouseEvent e; - e.SetState(wxGetMouseState()); - GetOwner()->DoEndDragResizeCol(e); + GetOwner()->DoHeaderEndDragResizeCol(event.GetWidth()); event.Skip(); } diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 22674b4696..d4692fccec 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3745,21 +3745,6 @@ void wxGrid::DoColHeaderClick(int col) } } -void wxGrid::DoStartResizeCol(int col) -{ - m_dragRowOrCol = col; - m_dragLastPos = -1; - DoUpdateResizeColWidth(GetColWidth(m_dragRowOrCol)); -} - -void wxGrid::DoUpdateResizeColWidth(int w) -{ - wxPoint pt(GetColLeft(m_dragRowOrCol) + w, 0); - - pt = CalcGridWindowScrolledPosition(pt, m_gridWin); - DrawGridDragLine(pt, wxGridColumnOperations(), m_gridWin); -} - void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindow* colLabelWin ) { int x; @@ -4746,6 +4731,19 @@ bool wxGrid::DoEndDragResizeLine(const wxGridOperations& oper, wxGridWindow *gri return sizeChanged; } +wxPoint wxGrid::GetPositionForResizeEvent(int width) const +{ + // Note that we currently always use m_gridWin here as using + // wxGridHeaderCtrl is incompatible with using frozen rows/columns. + // This would need to be changed if they're allowed to be used together. + int x; + CalcGridWindowScrolledPosition(GetColLeft(m_dragRowOrCol) + width, 0, + &x, NULL, + m_gridWin); + + return wxPoint(x, 0); +} + void wxGrid::DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow* gridWindow) { // TODO: generate RESIZING event, see #10754 @@ -4762,6 +4760,34 @@ void wxGrid::DoEndDragResizeCol(const wxMouseEvent& event, wxGridWindow* gridWin SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event); } +void wxGrid::DoHeaderStartDragResizeCol(int col) +{ + m_dragRowOrCol = col; + m_dragLastPos = -1; + DoHeaderDragResizeCol(GetColWidth(m_dragRowOrCol)); +} + +void wxGrid::DoHeaderDragResizeCol(int width) +{ + DrawGridDragLine(GetPositionForResizeEvent(width), + wxGridColumnOperations(), + m_gridWin); +} + +void wxGrid::DoHeaderEndDragResizeCol(int width) +{ + // Unfortunately we need to create a dummy mouse event here to avoid + // modifying too much existing code. Note that only position and keyboard + // state parts of this event object are actually used, so the rest + // (even including some crucial parts, such as event type) can be left + // uninitialized. + wxMouseEvent e; + e.SetState(wxGetMouseState()); + e.SetPosition(GetPositionForResizeEvent(width)); + + DoEndDragResizeCol(e, m_gridWin); +} + void wxGrid::DoStartMoveCol(int col) { m_dragMoveCol = col;