Many bug fixes for display code:
- clicking outside cell area no longer causes crashes - clicking beyond labels is now ignored - better cell selection code - old grid sample now works with this grid - newlines can be entered in to cell edit control git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5832 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
da6af900f1
commit
58dd5b3b3e
@ -391,7 +391,14 @@ class WXDLLEXPORT wxGrid : public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
wxGrid()
|
||||
{ Create(); }
|
||||
{
|
||||
m_table = (wxGridTableBase *) NULL;
|
||||
m_gridWin = (wxGridWindow *) NULL;
|
||||
m_rowLabelWin = (wxGridRowLabelWindow *) NULL;
|
||||
m_colLabelWin = (wxGridColLabelWindow *) NULL;
|
||||
m_cornerLabelWin = (wxGridCornerLabelWindow *) NULL;
|
||||
m_cellEditCtrl = (wxWindow *) NULL;
|
||||
}
|
||||
|
||||
wxGrid( wxWindow *parent,
|
||||
wxWindowID id,
|
||||
@ -671,8 +678,8 @@ public:
|
||||
// limited by TopLeft and BottomRight cell in device coords and clipped
|
||||
// to the client size of the grid window.
|
||||
//
|
||||
wxRect BlockToDeviceRect( const wxGridCellCoords & TopLeft,
|
||||
const wxGridCellCoords & BottomRight );
|
||||
wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
|
||||
const wxGridCellCoords & bottomRight );
|
||||
|
||||
// This function returns the rectangle that encloses the selected cells
|
||||
// in device coords and clipped to the client size of the grid window.
|
||||
@ -962,9 +969,6 @@ protected:
|
||||
bool SetModelValues();
|
||||
|
||||
|
||||
////////////////////// Public section ////////////////////
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_CLASS( wxGrid )
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
@ -606,7 +606,6 @@ void wxGridTextCtrl::OnKeyDown( wxKeyEvent& event )
|
||||
case WXK_RIGHT:
|
||||
case WXK_PRIOR:
|
||||
case WXK_NEXT:
|
||||
case WXK_RETURN:
|
||||
if ( m_isCellControl )
|
||||
{
|
||||
// send the event to the parent grid, skipping the
|
||||
@ -623,6 +622,28 @@ void wxGridTextCtrl::OnKeyDown( wxKeyEvent& event )
|
||||
}
|
||||
break;
|
||||
|
||||
case WXK_RETURN:
|
||||
if ( m_isCellControl )
|
||||
{
|
||||
if ( !m_grid->ProcessEvent( event ) )
|
||||
{
|
||||
#ifdef __WXMOTIF__
|
||||
// wxMotif needs a little extra help...
|
||||
//
|
||||
int pos = GetInsertionPoint();
|
||||
wxString s( GetValue() );
|
||||
s = s.Left(pos) + "\n" + s.Mid(pos);
|
||||
SetValue(s);
|
||||
SetInsertionPoint( pos );
|
||||
#else
|
||||
// the other ports can handle a Return key press
|
||||
//
|
||||
event.Skip();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WXK_HOME:
|
||||
case WXK_END:
|
||||
if ( m_isCellControl )
|
||||
@ -877,7 +898,21 @@ wxGrid::wxGrid( wxWindow *parent,
|
||||
: wxScrolledWindow( parent, id, pos, size, style, name )
|
||||
{
|
||||
Create();
|
||||
}
|
||||
|
||||
|
||||
wxGrid::~wxGrid()
|
||||
{
|
||||
delete m_table;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ----- internal init and update functions
|
||||
//
|
||||
|
||||
void wxGrid::Create()
|
||||
{
|
||||
int colLblH = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
|
||||
int rowLblW = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
|
||||
|
||||
@ -923,26 +958,6 @@ wxGrid::wxGrid( wxWindow *parent,
|
||||
SetSizer( m_mainSizer );
|
||||
}
|
||||
|
||||
wxGrid::~wxGrid()
|
||||
{
|
||||
delete m_table;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ----- internal init and update functions
|
||||
//
|
||||
|
||||
void wxGrid::Create()
|
||||
{
|
||||
m_table = (wxGridTableBase *) NULL;
|
||||
m_gridWin = (wxGridWindow *) NULL;
|
||||
m_rowLabelWin = (wxGridRowLabelWindow *) NULL;
|
||||
m_colLabelWin = (wxGridColLabelWindow *) NULL;
|
||||
m_cornerLabelWin = (wxGridCornerLabelWindow *) NULL;
|
||||
m_cellEditCtrl = (wxWindow *) NULL;
|
||||
}
|
||||
|
||||
|
||||
bool wxGrid::CreateGrid( int numRows, int numCols )
|
||||
{
|
||||
@ -1037,7 +1052,7 @@ void wxGrid::Init()
|
||||
m_gridLineColour = wxColour( 128, 128, 255 );
|
||||
m_gridLinesEnabled = TRUE;
|
||||
|
||||
m_cursorMode = WXGRID_CURSOR_DEFAULT;
|
||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
||||
m_dragLastPos = -1;
|
||||
m_dragRowOrCol = -1;
|
||||
m_isDragging = FALSE;
|
||||
@ -1496,7 +1511,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
||||
if ( YToEdgeOfRow(y) < 0 )
|
||||
{
|
||||
row = YToRow(y);
|
||||
if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
|
||||
if ( row >= 0 &&
|
||||
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
|
||||
{
|
||||
SelectRow( row, event.ShiftDown() );
|
||||
m_cursorMode = WXGRID_CURSOR_SELECT_ROW;
|
||||
@ -1676,7 +1692,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
||||
if ( XToEdgeOfCol(x) < 0 )
|
||||
{
|
||||
col = XToCol(x);
|
||||
if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
|
||||
if ( col >= 0 &&
|
||||
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
|
||||
{
|
||||
SelectCol( col, event.ShiftDown() );
|
||||
m_cursorMode = WXGRID_CURSOR_SELECT_COL;
|
||||
@ -1869,7 +1886,15 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
||||
|
||||
m_isDragging = FALSE;
|
||||
|
||||
if ( coords != wxGridNoCellCoords )
|
||||
{
|
||||
if ( event.LeftDown() )
|
||||
{
|
||||
if ( event.ShiftDown() )
|
||||
{
|
||||
SelectBlock( m_currentCellCoords, coords );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK,
|
||||
coords.GetRow(),
|
||||
@ -1880,6 +1905,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
||||
SetCurrentCell( coords );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------ Left double click
|
||||
@ -1903,11 +1929,12 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
||||
{
|
||||
SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, event );
|
||||
}
|
||||
}
|
||||
|
||||
// Show the edit control, if it has
|
||||
// been hidden for drag-shrinking.
|
||||
if ( IsCellEditControlEnabled() )
|
||||
ShowCellEditControl();
|
||||
}
|
||||
|
||||
m_dragLastPos = -1;
|
||||
}
|
||||
@ -1940,6 +1967,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
@ -2391,7 +2419,14 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
|
||||
break;
|
||||
|
||||
case WXK_RETURN:
|
||||
if ( event.ControlDown() )
|
||||
{
|
||||
event.Skip(); // to let the edit control have the return
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveCursorDown();
|
||||
}
|
||||
break;
|
||||
|
||||
case WXK_HOME:
|
||||
@ -2978,17 +3013,33 @@ void wxGrid::ShowCellEditControl()
|
||||
// Make the edit control large enough to allow for internal margins
|
||||
// TODO: remove this if the text ctrl sizing is improved esp. for unix
|
||||
//
|
||||
int extra;
|
||||
#if defined (__WXMOTIF__)
|
||||
rect.SetLeft( wxMax(0, left-4) );
|
||||
rect.SetTop( wxMax(0, top-4) );
|
||||
rect.SetRight( rect.GetRight() + 8 );
|
||||
rect.SetBottom( rect.GetBottom() + 8 );
|
||||
if ( m_currentCellCoords.GetRow() == 0 ||
|
||||
m_currentCellCoords.GetCol() == 0 )
|
||||
{
|
||||
extra = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
extra = 4;
|
||||
}
|
||||
#else
|
||||
rect.SetLeft( wxMax(0, left-2) );
|
||||
rect.SetTop( wxMax(0, top-2) );
|
||||
rect.SetRight( rect.GetRight() + 4 );
|
||||
rect.SetBottom( rect.GetBottom() + 4 );
|
||||
if ( m_currentCellCoords.GetRow() == 0 ||
|
||||
m_currentCellCoords.GetCol() == 0 )
|
||||
{
|
||||
extra = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
extra = 2;
|
||||
}
|
||||
#endif
|
||||
rect.SetLeft( wxMax(0, left - extra) );
|
||||
rect.SetTop( wxMax(0, top - extra) );
|
||||
rect.SetRight( rect.GetRight() + 2*extra );
|
||||
rect.SetBottom( rect.GetBottom() + 2*extra );
|
||||
|
||||
|
||||
m_cellEditCtrl->SetSize( rect );
|
||||
m_cellEditCtrl->Show( TRUE );
|
||||
@ -3129,8 +3180,17 @@ void wxGrid::SaveEditControlValue()
|
||||
|
||||
void wxGrid::XYToCell( int x, int y, wxGridCellCoords& coords )
|
||||
{
|
||||
coords.SetRow( YToRow(y) );
|
||||
coords.SetCol( XToCol(x) );
|
||||
int row = YToRow(y);
|
||||
int col = XToCol(x);
|
||||
|
||||
if ( row == -1 || col == -1 )
|
||||
{
|
||||
coords = wxGridNoCellCoords;
|
||||
}
|
||||
else
|
||||
{
|
||||
coords.Set( row, col );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4322,15 +4382,13 @@ void wxGrid::ClearSelection()
|
||||
// This function returns the rectangle that encloses the given block
|
||||
// in device coords clipped to the client size of the grid window.
|
||||
//
|
||||
wxRect wxGrid::BlockToDeviceRect(const wxGridCellCoords & TopLeft,
|
||||
const wxGridCellCoords & BottomRight)
|
||||
wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft,
|
||||
const wxGridCellCoords &bottomRight )
|
||||
{
|
||||
wxRect rect;
|
||||
wxRect rect( wxGridNoCellRect );
|
||||
wxRect cellRect;
|
||||
|
||||
if ( IsSelection() )
|
||||
{
|
||||
cellRect = CellToRect( TopLeft );
|
||||
cellRect = CellToRect( topLeft );
|
||||
if ( cellRect != wxGridNoCellRect )
|
||||
{
|
||||
rect = cellRect;
|
||||
@ -4340,7 +4398,7 @@ wxRect wxGrid::BlockToDeviceRect(const wxGridCellCoords & TopLeft,
|
||||
rect = wxRect( 0, 0, 0, 0 );
|
||||
}
|
||||
|
||||
cellRect = CellToRect( BottomRight );
|
||||
cellRect = CellToRect( bottomRight );
|
||||
if ( cellRect != wxGridNoCellRect )
|
||||
{
|
||||
rect += cellRect;
|
||||
@ -4363,16 +4421,12 @@ wxRect wxGrid::BlockToDeviceRect(const wxGridCellCoords & TopLeft,
|
||||
rect.SetTop( wxMax(0, top) );
|
||||
rect.SetRight( wxMin(cw, right) );
|
||||
rect.SetBottom( wxMin(ch, bottom) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return wxGridNoCellRect;
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ------ Grid event classes
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user