Fixed bug that caused wrong block of cells to be selected if the

mouse was dragged out of the grid cell area.

Cell text values now echo changes in top edit control if in-place
editing is disabled.

Changed highlight scheme again so that a border is drawn around the
current cell whether in-place editing is on or off. Hopefully this is
less confusing.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4207 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Michael Bedward 1999-10-27 03:05:05 +00:00
parent ad9bb75ff2
commit 52068ea5ff
2 changed files with 105 additions and 28 deletions

View File

@ -287,7 +287,7 @@ class wxGrid : public wxPanel
{ {
DECLARE_DYNAMIC_CLASS( wxGrid ) DECLARE_DYNAMIC_CLASS( wxGrid )
private: protected:
bool m_created; bool m_created;
wxGridTableBase *m_table; wxGridTableBase *m_table;
@ -459,9 +459,16 @@ class wxGrid : public wxPanel
void DrawGridLines( wxDC& dc ); void DrawGridLines( wxDC& dc );
void DrawCells( wxDC& dc ); void DrawCells( wxDC& dc );
void DrawCellBackground( wxDC& dc, const wxRect&, int row, int col ); void DrawCellBackground( wxDC& dc, const wxRect&, int row, int col );
void DrawCellValue( wxDC& dc, const wxRect&, int row, int col ); void DrawCellValue( wxDC& dc, const wxRect&, int row, int col,
const wxString& value = wxEmptyString, bool useValueArg = FALSE );
// this one is useful when you just need to draw one or a few // this updates the displayed cell text value but not the underlying
// table cell value (it is used to echo text being entered into
// the top edit control when in-place editing is turned off)
//
void DrawCellValue( const wxGridCellCoords& coords, const wxString& value );
// these are useful when you just need to draw one or a few
// cells // cells
void DrawCell( int row, int col ); void DrawCell( int row, int col );
void DrawCell( const wxGridCellCoords& coords ) void DrawCell( const wxGridCellCoords& coords )
@ -896,7 +903,7 @@ class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
{ {
DECLARE_DYNAMIC_CLASS(wxGridEvent) DECLARE_DYNAMIC_CLASS(wxGridEvent)
private: protected:
int m_row; int m_row;
int m_col; int m_col;
int m_x; int m_x;
@ -931,7 +938,7 @@ class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
{ {
DECLARE_DYNAMIC_CLASS(wxGridSizeEvent) DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
private: protected:
int m_rowOrCol; int m_rowOrCol;
int m_x; int m_x;
int m_y; int m_y;
@ -964,7 +971,7 @@ class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
{ {
DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent) DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
private: protected:
wxGridCellCoords m_topLeft; wxGridCellCoords m_topLeft;
wxGridCellCoords m_bottomRight; wxGridCellCoords m_bottomRight;
bool m_control; bool m_control;

View File

@ -1294,8 +1294,28 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
{ {
SelectBlock( cellCoords, cellCoords ); SelectBlock( cellCoords, cellCoords );
} }
else if ( !IsInSelection( cellCoords ) ) else
{ {
// check for the mouse being outside the cell area
// (we still want to let the user grow the selected block)
//
if ( cellCoords.GetCol() == -1 )
{
if ( x >= m_right )
cellCoords.SetCol( m_numCols-1 );
else
cellCoords.SetCol( m_scrollPosX );
}
if ( cellCoords.GetRow() == -1 )
{
if ( y >= m_bottom )
cellCoords.SetRow( m_numRows-1 );
else
cellCoords.SetRow( m_scrollPosY );
}
if ( !IsInSelection( cellCoords ) )
SelectBlock( m_currentCellCoords, cellCoords ); SelectBlock( m_currentCellCoords, cellCoords );
} }
} }
@ -1913,8 +1933,9 @@ void wxGrid::OnText( wxKeyEvent& ev )
break; break;
} }
} }
else if ( ctrl == m_topEditCtrl && else if ( ctrl == m_topEditCtrl )
IsCellEditControlEnabled() ) {
if ( IsCellEditControlEnabled() )
{ {
switch ( m_editCtrlType ) switch ( m_editCtrlType )
{ {
@ -1929,6 +1950,23 @@ void wxGrid::OnText( wxKeyEvent& ev )
break; break;
} }
} }
else
{
// in the case when in-place editing is turned off we just want to
// echo the text changes in the cell but not yet update the grid table
//
switch ( m_editCtrlType )
{
case wxGRID_TEXTCTRL:
DrawCellValue( m_currentCellCoords, ((wxTextCtrl *)ctrl)->GetValue() );
break;
case wxGRID_COMBOBOX:
DrawCellValue( m_currentCellCoords, ((wxComboBox *)ctrl)->GetValue() );
break;
}
}
}
} }
m_inOnText = FALSE; m_inOnText = FALSE;
@ -2993,7 +3031,11 @@ void wxGrid::DrawCellBackground( wxDC& dc, const wxRect& rect, int row, int col
} }
void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col ) // This draws a text value in the given cell. If useValueArg is FALSE
// (the default) then the grid table value will be used
//
void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col,
const wxString& value, bool useValueArg )
{ {
wxRect rect2; wxRect rect2;
rect2 = rect; rect2 = rect;
@ -3020,7 +3062,37 @@ void wxGrid::DrawCellValue( wxDC& dc, const wxRect& rect, int row, int col )
int hAlign, vAlign; int hAlign, vAlign;
GetCellAlignment( row, col, &hAlign, &vAlign ); GetCellAlignment( row, col, &hAlign, &vAlign );
if ( useValueArg )
{
DrawTextRectangle( dc, value, rect2, hAlign, vAlign );
}
else
{
DrawTextRectangle( dc, GetCellValue( row, col ), rect2, hAlign, vAlign ); DrawTextRectangle( dc, GetCellValue( row, col ), rect2, hAlign, vAlign );
}
}
// this is used to echo text being entered into the top edit control when
// in-place editing is turned off
//
void wxGrid::DrawCellValue( const wxGridCellCoords& coords, const wxString& value )
{
if ( IsVisible( coords ) )
{
int row = coords.GetRow();
int col = coords.GetCol();
wxRect rect;
rect.x = m_colRights[ col ] - m_colWidths[ col ];
rect.y = m_rowBottoms[ row ] - m_rowHeights[ row ];
rect.width = m_colWidths[ col ];
rect.height = m_rowHeights[ row ];
wxClientDC dc( this );
DrawCellBackground( dc, rect, row, col );
DrawCellValue( dc, rect, row, col, value, TRUE );
}
} }
@ -3083,8 +3155,7 @@ void wxGrid::DrawCell( int row, int col )
// //
void wxGrid::HideCurrentCellHighlight( wxDC& dc ) void wxGrid::HideCurrentCellHighlight( wxDC& dc )
{ {
if ( !m_cellEditCtrlEnabled && if ( m_currentCellHighlighted &&
m_currentCellHighlighted &&
m_currentCellCoords != wxGridNoCellCoords ) m_currentCellCoords != wxGridNoCellCoords )
{ {
DrawCellHighlight( dc, m_currentCellCoords ); DrawCellHighlight( dc, m_currentCellCoords );
@ -3097,8 +3168,7 @@ void wxGrid::HideCurrentCellHighlight( wxDC& dc )
// //
void wxGrid::ShowCurrentCellHighlight( wxDC& dc ) void wxGrid::ShowCurrentCellHighlight( wxDC& dc )
{ {
if ( !m_cellEditCtrlEnabled && if ( !m_currentCellHighlighted &&
!m_currentCellHighlighted &&
m_currentCellCoords != wxGridNoCellCoords ) m_currentCellCoords != wxGridNoCellCoords )
{ {
DrawCellHighlight( dc, m_currentCellCoords ); DrawCellHighlight( dc, m_currentCellCoords );