Make interface between wxGridHeaderCtrl and wxGrid more explicit

Rename the functions used from wxGridHeaderCtrl event handlers to start
with DoHeader prefix to make it clear that they're (only) used by it in
an attempt to make things more clear and more uniform.

No real changes.
This commit is contained in:
Vadim Zeitlin 2020-03-01 02:15:13 +01:00
parent 5986584fc0
commit 3d1de5c31b
3 changed files with 58 additions and 29 deletions

View File

@ -2534,18 +2534,26 @@ private:
void DoColHeaderClick(int col); void DoColHeaderClick(int col);
void DoStartResizeCol(int col);
void DoUpdateResizeColWidth(int w);
void DoStartMoveCol(int col); void DoStartMoveCol(int col);
void DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow *gridWindow); void DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow *gridWindow);
void DoEndDragResizeCol(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); 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 // process a TAB keypress
void DoGridProcessTab(wxKeyboardState& kbdState); void DoGridProcessTab(wxKeyboardState& kbdState);

View File

@ -252,24 +252,19 @@ private:
void OnBeginResize(wxHeaderCtrlEvent& event) void OnBeginResize(wxHeaderCtrlEvent& event)
{ {
GetOwner()->DoStartResizeCol(event.GetColumn()); GetOwner()->DoHeaderStartDragResizeCol(event.GetColumn());
event.Skip(); event.Skip();
} }
void OnResizing(wxHeaderCtrlEvent& event) void OnResizing(wxHeaderCtrlEvent& event)
{ {
GetOwner()->DoUpdateResizeColWidth(event.GetWidth()); GetOwner()->DoHeaderDragResizeCol(event.GetWidth());
} }
void OnEndResize(wxHeaderCtrlEvent& event) void OnEndResize(wxHeaderCtrlEvent& event)
{ {
// we again need to pass a mouse event to be used for the grid event GetOwner()->DoHeaderEndDragResizeCol(event.GetWidth());
// generation but we don't have it here so use a dummy one as in
// UpdateColumnVisibility()
wxMouseEvent e;
e.SetState(wxGetMouseState());
GetOwner()->DoEndDragResizeCol(e);
event.Skip(); event.Skip();
} }

View File

@ -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 ) void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindow* colLabelWin )
{ {
int x; int x;
@ -4746,6 +4731,19 @@ bool wxGrid::DoEndDragResizeLine(const wxGridOperations& oper, wxGridWindow *gri
return sizeChanged; 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) void wxGrid::DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow* gridWindow)
{ {
// TODO: generate RESIZING event, see #10754 // 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); 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) void wxGrid::DoStartMoveCol(int col)
{ {
m_dragMoveCol = col; m_dragMoveCol = col;