Unify wxGrid code for processing row and column mouse events
Reuse the same code for handling mouse events for both rows and columns instead of duplicating almost (but not quite) the same code for both of them. As part of resolving the inconsistencies between the two versions, add wxEVT_GRID_ROW_AUTO_SIZE corresponding to the existing event with the same name for the columns. Closes #22380.
This commit is contained in:
parent
1660584a45
commit
ec737396d8
@ -2802,8 +2802,7 @@ protected:
|
||||
|
||||
// Index of the row or column being drag-moved or -1 if there is no move
|
||||
// operation in progress.
|
||||
int m_dragMoveRow;
|
||||
int m_dragMoveCol;
|
||||
int m_dragMoveRowOrCol;
|
||||
|
||||
// Last horizontal mouse position while drag-moving a column.
|
||||
int m_dragLastPos;
|
||||
@ -2885,10 +2884,10 @@ protected:
|
||||
EventResult SendEvent(wxEventType evtType, const wxString& s = wxString())
|
||||
{ return SendEvent(evtType, m_currentCellCoords, s); }
|
||||
|
||||
// send wxEVT_GRID_{ROW,COL}_SIZE or wxEVT_GRID_COL_AUTO_SIZE, return true
|
||||
// send wxEVT_GRID_{ROW,COL}_SIZE or wxEVT_GRID_{ROW,COL}_AUTO_SIZE, return true
|
||||
// if the event was processed, false otherwise
|
||||
bool SendGridSizeEvent(wxEventType type,
|
||||
int row, int col,
|
||||
int rowOrCol,
|
||||
const wxMouseEvent& mouseEv);
|
||||
|
||||
void OnSize( wxSizeEvent& );
|
||||
@ -2906,6 +2905,7 @@ protected:
|
||||
{ return false; }
|
||||
|
||||
friend class WXDLLIMPEXP_FWD_CORE wxGridSelection;
|
||||
friend class wxGridOperations;
|
||||
friend class wxGridRowOperations;
|
||||
friend class wxGridColumnOperations;
|
||||
|
||||
@ -3047,19 +3047,18 @@ private:
|
||||
void ProcessGridCellMouseEvent(wxMouseEvent& event, wxGridWindow* gridWindow);
|
||||
|
||||
// process mouse events in the row/column labels/corner windows
|
||||
void ProcessRowLabelMouseEvent(wxMouseEvent& event,
|
||||
wxGridRowLabelWindow* rowLabelWin);
|
||||
void ProcessColLabelMouseEvent(wxMouseEvent& event,
|
||||
wxGridColLabelWindow* colLabelWin);
|
||||
void ProcessRowColLabelMouseEvent(const wxGridOperations &oper,
|
||||
wxMouseEvent& event,
|
||||
wxGridSubwindow* rowLabelWin);
|
||||
void ProcessCornerLabelMouseEvent(wxMouseEvent& event);
|
||||
|
||||
void HandleRowAutosize(int col, const wxMouseEvent& event);
|
||||
void HandleColumnAutosize(int col, const wxMouseEvent& event);
|
||||
|
||||
void DoColHeaderClick(int col);
|
||||
|
||||
void DoStartResizeRowOrCol(int col, int size);
|
||||
void DoStartMoveRow(int col);
|
||||
void DoStartMoveCol(int col);
|
||||
void DoStartMoveRowOrCol(int col);
|
||||
|
||||
// These functions should only be called when actually resizing/moving,
|
||||
// i.e. m_dragRowOrCol and m_dragMoveCol, respectively, are valid.
|
||||
@ -3486,6 +3485,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGrid
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent );
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent );
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent );
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_ROW_AUTO_SIZE, wxGridSizeEvent );
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_SIZE, wxGridSizeEvent );
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_COL_AUTO_SIZE, wxGridSizeEvent );
|
||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_GRID_RANGE_SELECTING, wxGridRangeSelectEvent );
|
||||
|
@ -17,6 +17,9 @@
|
||||
|
||||
#include "wx/headerctrl.h"
|
||||
|
||||
// for wxGridOperations
|
||||
#include "wx/generic/gridsel.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// array classes
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -167,7 +170,7 @@ private:
|
||||
|
||||
// as this is done by the user we should notify the main program about
|
||||
// it
|
||||
GetOwner()->SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, idx,
|
||||
GetOwner()->SendGridSizeEvent(wxEVT_GRID_COL_SIZE, idx,
|
||||
GetDummyMouseEvent());
|
||||
}
|
||||
|
||||
@ -243,7 +246,7 @@ private:
|
||||
|
||||
void OnBeginReorder(wxHeaderCtrlEvent& event)
|
||||
{
|
||||
GetOwner()->DoStartMoveCol(event.GetColumn());
|
||||
GetOwner()->DoStartMoveRowOrCol(event.GetColumn());
|
||||
}
|
||||
|
||||
void OnEndReorder(wxHeaderCtrlEvent& event)
|
||||
@ -479,6 +482,14 @@ public:
|
||||
// if this object is a wxGridColumnOperations and vice versa.
|
||||
virtual wxGridOperations& Dual() const = 0;
|
||||
|
||||
// returns wxHORIZONTAL or wxVERTICAL for row/col operations
|
||||
virtual int GetOrientation() const = 0;
|
||||
|
||||
// return row/col specific cursor modes
|
||||
virtual wxGrid::CursorMode GetCursorModeResize() const = 0;
|
||||
virtual wxGrid::CursorMode GetCursorModeSelect() const = 0;
|
||||
virtual wxGrid::CursorMode GetCursorModeMove() const = 0;
|
||||
|
||||
// Return the total number of rows or columns.
|
||||
virtual int GetTotalNumberOfLines(const wxGrid *grid) const = 0;
|
||||
|
||||
@ -568,6 +579,8 @@ public:
|
||||
// Set the row default height or column default width
|
||||
virtual void SetDefaultLineSize(wxGrid *grid, int size, bool resizeExisting) const = 0;
|
||||
|
||||
// auto size the row height or column width from the label content
|
||||
virtual void HandleLineAutosize(wxGrid *grid, int line, const wxMouseEvent& event) const = 0;
|
||||
|
||||
// Return the index of the line at the given position
|
||||
virtual int GetLineAt(const wxGrid *grid, int pos) const = 0;
|
||||
@ -587,6 +600,48 @@ public:
|
||||
// Get the row or column frozen grid window
|
||||
virtual wxGridWindow *GetFrozenGrid(wxGrid* grid) const = 0;
|
||||
|
||||
|
||||
// return the value of m_canDragRow/ColMove
|
||||
virtual bool CanDragMove(wxGrid *grid) const = 0;
|
||||
|
||||
// call DoEndMoveRow or DoEndMoveColumn
|
||||
virtual void DoEndMove(wxGrid* grid, int line) const = 0;
|
||||
|
||||
// return whether the given row/column can be interactively resized
|
||||
virtual bool CanDragLineSize(wxGrid *grid, int line) const = 0;
|
||||
|
||||
// call DoEndDragResizeRow or DoEndDragResizeCol
|
||||
virtual void DoEndLineResize(wxGrid *grid, const wxMouseEvent& event, wxGridWindow* gridWindow) const = 0;
|
||||
|
||||
|
||||
// extend current selection block up to given row or column
|
||||
virtual bool SelectionExtendCurrentBlock(wxGrid *grid, int line,
|
||||
const wxMouseEvent &event,
|
||||
wxEventType eventType = wxEVT_GRID_RANGE_SELECTED) const = 0;
|
||||
|
||||
// select or de-select a row or column
|
||||
virtual void SelectLine(wxGrid *grid, int line, wxMouseEvent &event) const = 0;
|
||||
virtual void DeselectLine(wxGrid * grid, int line) const = 0;
|
||||
|
||||
// check whether the row or columns first cell is in selected
|
||||
virtual bool IsLineInSelection(wxGrid *grid, int line) const = 0;
|
||||
|
||||
|
||||
// sent a result with row or column and the other value -1
|
||||
virtual wxGrid::EventResult SendEvent(wxGrid *grid, wxEventType eventType,
|
||||
int line, const wxMouseEvent& event) const = 0;
|
||||
|
||||
// call DrawRowLabel or DrawColumnLabel
|
||||
virtual void DrawLineLabel(wxGrid *grid, wxDC& dc, int line) const = 0;
|
||||
|
||||
|
||||
// make the specified line visible by doing a minimal amount of scrolling
|
||||
virtual void MakeLineVisible(wxGrid *grid, int line) const = 0;
|
||||
|
||||
// set cursor into the first visible cell of the given row or column
|
||||
virtual void MakeLineCurrent(wxGrid *grid, int line) const = 0;
|
||||
|
||||
|
||||
// This class is never used polymorphically but give it a virtual dtor
|
||||
// anyhow to suppress g++ complaints about it
|
||||
virtual ~wxGridOperations() { }
|
||||
@ -597,6 +652,16 @@ class wxGridRowOperations : public wxGridOperations
|
||||
public:
|
||||
virtual wxGridOperations& Dual() const wxOVERRIDE;
|
||||
|
||||
virtual int GetOrientation() const wxOVERRIDE
|
||||
{ return wxVERTICAL; }
|
||||
|
||||
virtual wxGrid::CursorMode GetCursorModeResize() const wxOVERRIDE
|
||||
{ return wxGrid::WXGRID_CURSOR_RESIZE_ROW; }
|
||||
virtual wxGrid::CursorMode GetCursorModeSelect() const wxOVERRIDE
|
||||
{ return wxGrid::WXGRID_CURSOR_SELECT_ROW; }
|
||||
virtual wxGrid::CursorMode GetCursorModeMove() const wxOVERRIDE
|
||||
{ return wxGrid::WXGRID_CURSOR_MOVE_ROW; }
|
||||
|
||||
virtual int GetTotalNumberOfLines(const wxGrid *grid) const wxOVERRIDE
|
||||
{ return grid->GetNumberRows(); }
|
||||
|
||||
@ -655,6 +720,8 @@ public:
|
||||
{ grid->SetRowSize(line, size); }
|
||||
virtual void SetDefaultLineSize(wxGrid *grid, int size, bool resizeExisting) const wxOVERRIDE
|
||||
{ grid->SetDefaultRowSize(size, resizeExisting); }
|
||||
virtual void HandleLineAutosize(wxGrid *grid, int line, const wxMouseEvent& event) const wxOVERRIDE
|
||||
{ grid->HandleRowAutosize(line, event); }
|
||||
|
||||
virtual int GetLineAt(const wxGrid *grid, int pos) const wxOVERRIDE
|
||||
{ return grid->GetRowAt(pos); }
|
||||
@ -674,13 +741,70 @@ public:
|
||||
|
||||
virtual wxGridWindow *GetFrozenGrid(wxGrid* grid) const wxOVERRIDE
|
||||
{ return (wxGridWindow*)grid->GetFrozenRowGridWindow(); }
|
||||
|
||||
virtual bool CanDragMove(wxGrid *grid) const wxOVERRIDE
|
||||
{ return grid->m_canDragRowMove; }
|
||||
virtual void DoEndMove(wxGrid* grid, int line) const wxOVERRIDE
|
||||
{ grid->DoEndMoveRow(line); }
|
||||
|
||||
virtual bool CanDragLineSize(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ return grid->CanDragRowSize(line); }
|
||||
virtual void DoEndLineResize(wxGrid *grid, const wxMouseEvent& event,
|
||||
wxGridWindow* gridWindow) const wxOVERRIDE
|
||||
{ grid->DoEndDragResizeRow(event, gridWindow); }
|
||||
|
||||
|
||||
virtual bool SelectionExtendCurrentBlock(wxGrid *grid, int line,
|
||||
const wxMouseEvent &event,
|
||||
wxEventType eventType = wxEVT_GRID_RANGE_SELECTED) const wxOVERRIDE
|
||||
{
|
||||
return grid->m_selection->ExtendCurrentBlock
|
||||
(
|
||||
wxGridCellCoords(grid->m_currentCellCoords.GetRow(), 0),
|
||||
wxGridCellCoords(line, grid->GetNumberCols() - 1),
|
||||
event,
|
||||
eventType
|
||||
);
|
||||
}
|
||||
|
||||
virtual void SelectLine(wxGrid *grid, int line, wxMouseEvent &event) const wxOVERRIDE
|
||||
{ grid->m_selection->SelectRow(line, event); };
|
||||
virtual void DeselectLine(wxGrid * grid, int line) const wxOVERRIDE
|
||||
{ grid->DeselectRow(line); }
|
||||
|
||||
virtual bool IsLineInSelection(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ return grid->m_selection->IsInSelection(line, 0); }
|
||||
|
||||
virtual wxGrid::EventResult SendEvent(wxGrid *grid, wxEventType eventType,
|
||||
int line, const wxMouseEvent& event) const wxOVERRIDE
|
||||
{ return grid->SendEvent(eventType, line, -1, event ); }
|
||||
|
||||
virtual void DrawLineLabel(wxGrid *grid, wxDC& dc, int line) const wxOVERRIDE
|
||||
{ grid->DrawRowLabel(dc, line); }
|
||||
|
||||
virtual void MakeLineVisible(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ grid->MakeCellVisible(line, -1); }
|
||||
virtual void MakeLineCurrent(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ grid->SetCurrentCell(line, grid->GetFirstFullyVisibleColumn()); }
|
||||
|
||||
};
|
||||
|
||||
class wxGridColumnOperations : public wxGridOperations
|
||||
{
|
||||
|
||||
public:
|
||||
virtual wxGridOperations& Dual() const wxOVERRIDE;
|
||||
|
||||
virtual int GetOrientation() const wxOVERRIDE
|
||||
{ return wxHORIZONTAL; }
|
||||
|
||||
virtual wxGrid::CursorMode GetCursorModeResize() const wxOVERRIDE
|
||||
{ return wxGrid::WXGRID_CURSOR_RESIZE_COL; }
|
||||
virtual wxGrid::CursorMode GetCursorModeSelect() const wxOVERRIDE
|
||||
{ return wxGrid::WXGRID_CURSOR_SELECT_COL; }
|
||||
virtual wxGrid::CursorMode GetCursorModeMove() const wxOVERRIDE
|
||||
{ return wxGrid::WXGRID_CURSOR_MOVE_COL; }
|
||||
|
||||
virtual int GetTotalNumberOfLines(const wxGrid *grid) const wxOVERRIDE
|
||||
{ return grid->GetNumberCols(); }
|
||||
|
||||
@ -739,6 +863,8 @@ public:
|
||||
{ grid->SetColSize(line, size); }
|
||||
virtual void SetDefaultLineSize(wxGrid *grid, int size, bool resizeExisting) const wxOVERRIDE
|
||||
{ grid->SetDefaultColSize(size, resizeExisting); }
|
||||
virtual void HandleLineAutosize(wxGrid *grid, int line, const wxMouseEvent& event) const wxOVERRIDE
|
||||
{ grid->HandleColumnAutosize(line, event); }
|
||||
|
||||
virtual int GetLineAt(const wxGrid *grid, int pos) const wxOVERRIDE
|
||||
{ return grid->GetColAt(pos); }
|
||||
@ -758,6 +884,51 @@ public:
|
||||
|
||||
virtual wxGridWindow *GetFrozenGrid(wxGrid* grid) const wxOVERRIDE
|
||||
{ return (wxGridWindow*)grid->GetFrozenColGridWindow(); }
|
||||
|
||||
virtual bool CanDragMove(wxGrid *grid) const wxOVERRIDE
|
||||
{ return grid->m_canDragColMove; }
|
||||
virtual void DoEndMove(wxGrid* grid, int line) const wxOVERRIDE
|
||||
{ grid->DoEndMoveCol(line); }
|
||||
|
||||
virtual bool CanDragLineSize(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ return grid->CanDragColSize(line); }
|
||||
virtual void DoEndLineResize(wxGrid *grid, const wxMouseEvent& event,
|
||||
wxGridWindow* gridWindow) const wxOVERRIDE
|
||||
{ grid->DoEndDragResizeCol(event, gridWindow); }
|
||||
|
||||
virtual bool SelectionExtendCurrentBlock(wxGrid *grid, int line,
|
||||
const wxMouseEvent &event,
|
||||
wxEventType eventType = wxEVT_GRID_RANGE_SELECTED) const wxOVERRIDE
|
||||
{
|
||||
return grid->m_selection->ExtendCurrentBlock
|
||||
(
|
||||
wxGridCellCoords(0, grid->m_currentCellCoords.GetCol()),
|
||||
wxGridCellCoords(grid->GetNumberRows() - 1, line),
|
||||
event,
|
||||
eventType
|
||||
);
|
||||
}
|
||||
|
||||
virtual void SelectLine(wxGrid *grid, int line, wxMouseEvent &event) const wxOVERRIDE
|
||||
{ grid->m_selection->SelectCol(line, event); };
|
||||
virtual void DeselectLine(wxGrid * grid, int line) const wxOVERRIDE
|
||||
{ grid->DeselectCol(line); }
|
||||
|
||||
virtual bool IsLineInSelection(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ return grid->m_selection->IsInSelection(line, 0); }
|
||||
|
||||
virtual wxGrid::EventResult SendEvent(wxGrid *grid, wxEventType eventType,
|
||||
int line, const wxMouseEvent& event) const wxOVERRIDE
|
||||
{ return grid->SendEvent(eventType, -1, line, event ); }
|
||||
|
||||
virtual void DrawLineLabel(wxGrid *grid, wxDC& dc, int line) const wxOVERRIDE
|
||||
{ grid->DrawColLabel(dc, line); }
|
||||
|
||||
virtual void MakeLineVisible(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ grid->MakeCellVisible(-1, line); }
|
||||
virtual void MakeLineCurrent(wxGrid *grid, int line) const wxOVERRIDE
|
||||
{ grid->SetCurrentCell(grid->GetFirstFullyVisibleRow(), line); }
|
||||
|
||||
};
|
||||
|
||||
// This class abstracts the difference between operations going forward
|
||||
|
@ -6381,6 +6381,13 @@ public:
|
||||
@event{EVT_GRID_CMD_ROW_SIZE(id, func)}
|
||||
The user resized a row, corresponds to @c wxEVT_GRID_ROW_SIZE event
|
||||
type.
|
||||
@event{EVT_GRID_ROW_AUTO_SIZE(func)}
|
||||
This event is sent when a row must be resized to its best size, e.g.
|
||||
when the user double clicks the row divider. The default
|
||||
implementation simply resizes the row to fit the row label (but
|
||||
not its contents as this could be too slow for big grids). This macro
|
||||
corresponds to @c wxEVT_GRID_ROW_AUTO_SIZE event type and is new since
|
||||
wxWidgets 3.1.7.
|
||||
@event{EVT_GRID_COL_SIZE(func)}
|
||||
Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id.
|
||||
@event{EVT_GRID_COL_AUTO_SIZE(func)}
|
||||
@ -6654,6 +6661,7 @@ wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
|
||||
wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
|
||||
wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
|
||||
wxEventType wxEVT_GRID_ROW_SIZE;
|
||||
wxEventType wxEVT_GRID_ROW_AUTO_SIZE;
|
||||
wxEventType wxEVT_GRID_COL_SIZE;
|
||||
wxEventType wxEVT_GRID_COL_AUTO_SIZE;
|
||||
wxEventType wxEVT_GRID_RANGE_SELECTING;
|
||||
|
@ -1564,6 +1564,7 @@ void GridFrame::FreezeOrThaw(wxCommandEvent& ev)
|
||||
}
|
||||
|
||||
GetMenuBar()->Enable( ID_TOGGLECOLMOVING, !grid->IsFrozen() );
|
||||
GetMenuBar()->Enable( ID_TOGGLEROWMOVING, !grid->IsFrozen() );
|
||||
}
|
||||
|
||||
void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) )
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user