// we can't know in advance whether we can sort by this column or not
// with wxGrid API so suppose we can by default
int flags = wxCOL_SORTABLE;
- if ( m_grid->CanDragColSize() )
+ if ( m_grid->CanDragColSize(m_col) )
flags |= wxCOL_RESIZABLE;
if ( m_grid->CanDragColMove() )
flags |= wxCOL_REORDERABLE;
private:
wxGrid *GetOwner() const { return static_cast<wxGrid *>(GetParent()); }
+ static wxMouseEvent GetDummyMouseEvent()
+ {
+ // make up a dummy event for the grid event to use -- unfortunately we
+ // can't do anything else here
+ wxMouseEvent e;
+ e.SetState(wxGetMouseState());
+ return e;
+ }
+
// override the base class method to update our m_columns array
virtual void OnColumnCountChanging(unsigned int count)
{
// as this is done by the user we should notify the main program about
// it
- GetOwner()->SendEvent(wxEVT_GRID_COL_SIZE, -1, idx);
+ GetOwner()->SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, idx,
+ GetDummyMouseEvent());
}
// overridden to react to the columns order changes in the customization
// event handlers forwarding wxHeaderCtrl events to wxGrid
void OnClick(wxHeaderCtrlEvent& event)
{
+ GetOwner()->SendEvent(wxEVT_GRID_LABEL_LEFT_CLICK,
+ -1, event.GetColumn(),
+ GetDummyMouseEvent());
+
GetOwner()->DoColHeaderClick(event.GetColumn());
}
+ void OnDoubleClick(wxHeaderCtrlEvent& event)
+ {
+ if ( !GetOwner()->SendEvent(wxEVT_GRID_LABEL_LEFT_DCLICK,
+ -1, event.GetColumn(),
+ GetDummyMouseEvent()) )
+ {
+ event.Skip();
+ }
+ }
+
+ void OnRightClick(wxHeaderCtrlEvent& event)
+ {
+ if ( !GetOwner()->SendEvent(wxEVT_GRID_LABEL_RIGHT_CLICK,
+ -1, event.GetColumn(),
+ GetDummyMouseEvent()) )
+ {
+ event.Skip();
+ }
+ }
+
void OnBeginResize(wxHeaderCtrlEvent& event)
{
GetOwner()->DoStartResizeCol(event.GetColumn());
void OnEndResize(wxHeaderCtrlEvent& event)
{
- GetOwner()->DoEndDragResizeCol();
+ // 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);
event.Skip();
}
// Set the row height or column width
virtual void SetLineSize(wxGrid *grid, int line, int size) const = 0;
- // True if rows/columns can be resized by user
- virtual bool CanResizeLines(const wxGrid *grid) const = 0;
+ // Set the row default height or column default width
+ virtual void SetDefaultLineSize(wxGrid *grid, int size, bool resizeExisting) const = 0;
// Return the index of the line at the given position
//
// NB: currently this is always identity for the rows as reordering is only
// implemented for the lines
- virtual int GetLineAt(const wxGrid *grid, int line) const = 0;
+ virtual int GetLineAt(const wxGrid *grid, int pos) const = 0;
+ // Return the index of the line just before the given one.
+ virtual int GetLineBefore(const wxGrid* grid, int line) const = 0;
// Get the row or column label window
virtual wxWindow *GetHeaderWindow(wxGrid *grid) const = 0;
{ return grid->GetRowMinimalHeight(line); }
virtual void SetLineSize(wxGrid *grid, int line, int size) const
{ grid->SetRowSize(line, size); }
- virtual bool CanResizeLines(const wxGrid *grid) const
- { return grid->CanDragRowSize(); }
+ virtual void SetDefaultLineSize(wxGrid *grid, int size, bool resizeExisting) const
+ { grid->SetDefaultRowSize(size, resizeExisting); }
virtual int GetLineAt(const wxGrid * WXUNUSED(grid), int line) const
{ return line; } // TODO: implement row reordering
+ virtual int GetLineBefore(const wxGrid* WXUNUSED(grid), int line) const
+ { return line ? line - 1 : line; }
+
virtual wxWindow *GetHeaderWindow(wxGrid *grid) const
{ return grid->GetGridRowLabelWindow(); }
virtual int GetHeaderWindowSize(wxGrid *grid) const
{ return grid->GetColMinimalWidth(line); }
virtual void SetLineSize(wxGrid *grid, int line, int size) const
{ grid->SetColSize(line, size); }
- virtual bool CanResizeLines(const wxGrid *grid) const
- { return grid->CanDragColSize(); }
+ virtual void SetDefaultLineSize(wxGrid *grid, int size, bool resizeExisting) const
+ { grid->SetDefaultColSize(size, resizeExisting); }
virtual int GetLineAt(const wxGrid *grid, int line) const
{ return grid->GetColAt(line); }
+ virtual int GetLineBefore(const wxGrid* grid, int line) const
+ { return grid->GetColAt(wxMax(0, grid->GetColPos(line) - 1)); }
+
virtual wxWindow *GetHeaderWindow(wxGrid *grid) const
{ return grid->GetGridColLabelWindow(); }
virtual int GetHeaderWindowSize(wxGrid *grid) const
const int m_numLines;
};
-// ----------------------------------------------------------------------------
-// private helpers
-// ----------------------------------------------------------------------------
-
-namespace
-{
-
-// ensure that first is less or equal to second, swapping the values if
-// necessary
-void EnsureFirstLessThanSecond(int& first, int& second)
-{
- if ( first > second )
- wxSwap(first, second);
-}
-
-} // anonymous namespace
-
// ----------------------------------------------------------------------------
// data structures used for the data type registry
// ----------------------------------------------------------------------------