// 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();
}
wxVector<wxGridHeaderColumn> m_columns;
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGridHeaderCtrl)
+ wxDECLARE_NO_COPY_CLASS(wxGridHeaderCtrl);
};
// common base class for various grid subwindows
m_owner = owner;
}
+ virtual wxWindow *GetMainWindowOfCompositeControl() { return m_owner; }
+
virtual bool AcceptsFocus() const { return false; }
wxGrid *GetOwner() { return m_owner; }
wxGrid *m_owner;
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGridSubwindow)
+ wxDECLARE_NO_COPY_CLASS(wxGridSubwindow);
};
class WXDLLIMPEXP_ADV wxGridRowLabelWindow : public wxGridSubwindow
void OnMouseWheel( wxMouseEvent& event );
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGridRowLabelWindow)
+ wxDECLARE_NO_COPY_CLASS(wxGridRowLabelWindow);
};
void OnMouseWheel( wxMouseEvent& event );
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGridColLabelWindow)
+ wxDECLARE_NO_COPY_CLASS(wxGridColLabelWindow);
};
void OnPaint( wxPaintEvent& event );
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow)
+ wxDECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow);
};
class WXDLLIMPEXP_ADV wxGridWindow : public wxGridSubwindow
void OnFocus( wxFocusEvent& );
DECLARE_EVENT_TABLE()
- DECLARE_NO_COPY_CLASS(wxGridWindow)
+ wxDECLARE_NO_COPY_CLASS(wxGridWindow);
};
// ----------------------------------------------------------------------------
// 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 display position of the line with the given index.
+ //
+ // NB: As GetLineAt(), currently this is always identity for rows.
+ virtual int GetLinePos(const wxGrid *grid, int line) 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
+ virtual int GetLineAt(const wxGrid * WXUNUSED(grid), int pos) const
+ { return pos; } // TODO: implement row reordering
+ virtual int GetLinePos(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 GetLineAt(const wxGrid *grid, int pos) const
+ { return grid->GetColAt(pos); }
+ virtual int GetLinePos(const wxGrid *grid, int line) const
+ { return grid->GetColPos(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(); }
// This class abstracts the difference between operations going forward
// (down/right) and backward (up/left) and allows to use the same code for
-// functions which differ only in the direction of grid traversal
+// functions which differ only in the direction of grid traversal.
+//
+// Notice that all operations in this class work with display positions and not
+// internal indices which can be different if the columns were reordered.
//
// Like wxGridOperations it's an ABC with two concrete subclasses below. Unlike
// it, this is a normal object and not just a function dispatch table and has a
// Find the line at the given distance, in pixels, away from this one
// (this uses clipping, i.e. anything after the last line is counted as the
// last one and anything before the first one as 0)
+ //
+ // TODO: Implementation of this method currently doesn't support column
+ // reordering as it mixes up indices and positions. But this doesn't
+ // really matter as it's only called for rows (Page Up/Down only work
+ // vertically) and row reordering is not currently supported. We'd
+ // need to fix it if this ever changes however.
virtual int MoveByPixelDistance(int line, int distance) const = 0;
// This class is never used polymorphically but give it a virtual dtor
virtual ~wxGridDirectionOperations() { }
protected:
+ // Get the position of the row or column from the given coordinates pair.
+ //
+ // This is just a shortcut to avoid repeating m_oper and m_grid multiple
+ // times in the derived classes code.
+ int GetLinePos(const wxGridCellCoords& coords) const
+ {
+ return m_oper.GetLinePos(m_grid, m_oper.Select(coords));
+ }
+
+ // Get the index of the row or column from the position.
+ int GetLineAt(int pos) const
+ {
+ return m_oper.GetLineAt(m_grid, pos);
+ }
+
+ // Check if the given line is visible, i.e. has non 0 size.
+ bool IsLineVisible(int line) const
+ {
+ return m_oper.GetLineSize(m_grid, line) != 0;
+ }
+
+
wxGrid * const m_grid;
const wxGridOperations& m_oper;
};
{
wxASSERT_MSG( m_oper.Select(coords) >= 0, "invalid row/column" );
- return m_oper.Select(coords) == 0;
+ int pos = GetLinePos(coords);
+ while ( pos )
+ {
+ // Check the previous line.
+ int line = GetLineAt(--pos);
+ if ( IsLineVisible(line) )
+ {
+ // There is another visible line before this one, hence it's
+ // not at boundary.
+ return false;
+ }
+ }
+
+ // We reached the boundary without finding any visible lines.
+ return true;
}
virtual void Advance(wxGridCellCoords& coords) const
{
- wxASSERT( !IsAtBoundary(coords) );
-
- m_oper.Set(coords, m_oper.Select(coords) - 1);
+ int pos = GetLinePos(coords);
+ for ( ;; )
+ {
+ // This is not supposed to happen if IsAtBoundary() returned false.
+ wxCHECK_RET( pos, "can't advance when already at boundary" );
+
+ int line = GetLineAt(--pos);
+ if ( IsLineVisible(line) )
+ {
+ m_oper.Set(coords, line);
+ break;
+ }
+ }
}
virtual int MoveByPixelDistance(int line, int distance) const
}
};
+// Please refer to the comments above when reading this class code, it's
+// absolutely symmetrical to wxGridBackwardOperations.
class wxGridForwardOperations : public wxGridDirectionOperations
{
public:
{
wxASSERT_MSG( m_oper.Select(coords) < m_numLines, "invalid row/column" );
- return m_oper.Select(coords) == m_numLines - 1;
+ int pos = GetLinePos(coords);
+ while ( pos < m_numLines - 1 )
+ {
+ int line = GetLineAt(++pos);
+ if ( IsLineVisible(line) )
+ return false;
+ }
+
+ return true;
}
virtual void Advance(wxGridCellCoords& coords) const
{
- wxASSERT( !IsAtBoundary(coords) );
-
- m_oper.Set(coords, m_oper.Select(coords) + 1);
+ int pos = GetLinePos(coords);
+ for ( ;; )
+ {
+ wxCHECK_RET( pos < m_numLines - 1,
+ "can't advance when already at boundary" );
+
+ int line = GetLineAt(++pos);
+ if ( IsLineVisible(line) )
+ {
+ m_oper.Set(coords, line);
+ break;
+ }
+ }
}
virtual int MoveByPixelDistance(int line, int distance) 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
// ----------------------------------------------------------------------------
wxGridCellRenderer* m_renderer;
wxGridCellEditor* m_editor;
- DECLARE_NO_COPY_CLASS(wxGridDataTypeInfo)
+ wxDECLARE_NO_COPY_CLASS(wxGridDataTypeInfo);
};