fallback to string changes for number and float editors

Fixes for DrawGridSpace (it needed moved over/up by one pixel, at
least for MSW)

Editor left active when resizing rows/cols


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6248 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2000-02-23 19:27:08 +00:00
parent fc3398f8e0
commit a5777624e2

View File

@@ -635,9 +635,12 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
} }
else else
{ {
wxFAIL_MSG( _T("this cell doesn't have numeric value") ); wxString sValue = table->GetValue(row, col);
if (! sValue.ToLong(&m_valueOld))
return; {
wxFAIL_MSG( _T("this cell doesn't have numeric value") );
return;
}
} }
if ( HasRange() ) if ( HasRange() )
@@ -668,7 +671,10 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
if ( changed ) if ( changed )
{ {
grid->GetTable()->SetValueAsLong(row, col, value); if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER))
grid->GetTable()->SetValueAsLong(row, col, value);
else
grid->GetTable()->SetValue(row, col, wxString::Format("%ld", value));
} }
return changed; return changed;
@@ -728,9 +734,12 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
} }
else else
{ {
wxFAIL_MSG( _T("this cell doesn't have float value") ); wxString sValue = table->GetValue(row, col);
if (! sValue.ToDouble(&m_valueOld))
return; {
wxFAIL_MSG( _T("this cell doesn't have float value") );
return;
}
} }
DoBeginEdit(GetString()); DoBeginEdit(GetString());
@@ -742,7 +751,10 @@ bool wxGridCellFloatEditor::EndEdit(int row, int col,
double value; double value;
if ( Text()->GetValue().ToDouble(&value) && (value != m_valueOld) ) if ( Text()->GetValue().ToDouble(&value) && (value != m_valueOld) )
{ {
grid->GetTable()->SetValueAsDouble(row, col, value); if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT))
grid->GetTable()->SetValueAsDouble(row, col, value);
else
grid->GetTable()->SetValue(row, col, wxString::Format("%f", value));
return TRUE; return TRUE;
} }
@@ -898,11 +910,16 @@ void wxGridCellChoiceEditor::Create(wxWindow* parent,
wxGridCellEditor::Create(parent, id, evtHandler); wxGridCellEditor::Create(parent, id, evtHandler);
} }
void wxGridCellChoiceEditor::PaintBackground(const wxRect& WXUNUSED(rectCell), void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
wxGridCellAttr * WXUNUSED(attr)) wxGridCellAttr * attr)
{ {
// as we fill the entire client area, don't do anything here to minimize // as we fill the entire client area, don't do anything here to minimize
// flicker // flicker
// TODO: It doesn't actually fill the client area since the height of a
// combo always defaults to the standard... Until someone has time to
// figure out the right rectangle to paint, just do it the normal way...
wxGridCellEditor::PaintBackground(rectCell, attr);
} }
void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
@@ -2586,10 +2603,10 @@ void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
wxRegion reg = GetUpdateRegion(); wxRegion reg = GetUpdateRegion();
m_owner->CalcCellsExposed( reg ); m_owner->CalcCellsExposed( reg );
m_owner->DrawGridCellArea( dc ); m_owner->DrawGridCellArea( dc );
m_owner->DrawGridSpace( dc );
#if WXGRID_DRAW_LINES #if WXGRID_DRAW_LINES
m_owner->DrawAllGridLines( dc, reg ); m_owner->DrawAllGridLines( dc, reg );
#endif #endif
m_owner->DrawGridSpace( dc );
m_owner->DrawHighlight( dc ); m_owner->DrawHighlight( dc );
} }
@@ -3803,7 +3820,10 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
// Hide the edit control, so it // Hide the edit control, so it
// won't interfer with drag-shrinking. // won't interfer with drag-shrinking.
if ( IsCellEditControlEnabled() ) if ( IsCellEditControlEnabled() )
{
HideCellEditControl(); HideCellEditControl();
SaveEditControlValue();
}
// Have we captured the mouse yet? // Have we captured the mouse yet?
if (! m_winCapture) if (! m_winCapture)
@@ -3873,206 +3893,200 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
m_isDragging = FALSE; m_isDragging = FALSE;
m_startDragPos = wxDefaultPosition; m_startDragPos = wxDefaultPosition;
// if ( coords == wxGridNoCellCoords && m_cursorMode != WXGRID_CURSOR_SELECT_CELL ) // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
// { // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
// ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); // wxGTK
// }
// if ( coords != wxGridNoCellCoords )
// {
// VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
// immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
// wxGTK
#if 0 #if 0
if ( event.Entering() || event.Leaving() ) if ( event.Entering() || event.Leaving() )
{ {
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
m_gridWin->SetCursor( *wxSTANDARD_CURSOR ); m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
} }
else else
#endif // 0 #endif // 0
// ------------ Left button pressed // ------------ Left button pressed
// //
if ( event.LeftDown() && coords != wxGridNoCellCoords ) if ( event.LeftDown() && coords != wxGridNoCellCoords )
{
if ( event.ShiftDown() )
{ {
DisableCellEditControl(); SelectBlock( m_currentCellCoords, coords );
if ( event.ShiftDown() ) }
else if ( XToEdgeOfCol(x) < 0 &&
YToEdgeOfRow(y) < 0 )
{
if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
{ {
SelectBlock( m_currentCellCoords, coords ); DisableCellEditControl();
} MakeCellVisible( coords );
else if ( XToEdgeOfCol(x) < 0 &&
YToEdgeOfRow(y) < 0 ) // if this is the second click on this cell then start
{ // the edit control
if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK, if ( m_waitForSlowClick &&
coords.GetRow(), (coords == m_currentCellCoords) &&
coords.GetCol(), CanEnableCellControl())
event ) )
{ {
MakeCellVisible( coords ); EnableCellEditControl();
// if this is the second click on this cell then start wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
// the edit control attr->GetEditor(this, coords.GetRow(), coords.GetCol())->StartingClick();
if ( m_waitForSlowClick && attr->DecRef();
(coords == m_currentCellCoords) &&
CanEnableCellControl())
{
EnableCellEditControl();
wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords); m_waitForSlowClick = FALSE;
attr->GetEditor(this, coords.GetRow(), coords.GetCol())->StartingClick(); }
attr->DecRef(); else
{
m_waitForSlowClick = FALSE; SetCurrentCell( coords );
} m_waitForSlowClick = TRUE;
else
{
SetCurrentCell( coords );
m_waitForSlowClick = TRUE;
}
} }
} }
} }
}
// ------------ Left double click // ------------ Left double click
// //
else if ( event.LeftDClick() && coords != wxGridNoCellCoords ) else if ( event.LeftDClick() && coords != wxGridNoCellCoords )
{
DisableCellEditControl();
if ( XToEdgeOfCol(x) < 0 && YToEdgeOfRow(y) < 0 )
{ {
DisableCellEditControl(); SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK,
if ( XToEdgeOfCol(x) < 0 && YToEdgeOfRow(y) < 0 ) coords.GetRow(),
coords.GetCol(),
event );
}
}
// ------------ Left button released
//
else if ( event.LeftUp() )
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
if ( IsSelection() )
{ {
SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK, if (m_winCapture)
coords.GetRow(), {
coords.GetCol(), m_winCapture->ReleaseMouse();
event ); m_winCapture = NULL;
}
SendEvent( wxEVT_GRID_RANGE_SELECT, -1, -1, event );
} }
// Show the edit control, if it has been hidden for
// drag-shrinking.
ShowCellEditControl();
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
DoEndDragResizeRow();
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
DoEndDragResizeCol();
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
} }
m_dragLastPos = -1;
}
// ------------ Left button released
// // ------------ Right button down
else if ( event.LeftUp() ) //
else if ( event.RightDown() && coords != wxGridNoCellCoords )
{
DisableCellEditControl();
if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
{ {
// no default action at the moment
}
}
// ------------ Right double click
//
else if ( event.RightDClick() && coords != wxGridNoCellCoords )
{
DisableCellEditControl();
if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
{
// no default action at the moment
}
}
// ------------ Moving and no button action
//
else if ( event.Moving() && !event.IsButton() )
{
int dragRow = YToEdgeOfRow( y );
int dragCol = XToEdgeOfCol( x );
// Dragging on the corner of a cell to resize in both
// directions is not implemented yet...
//
if ( dragRow >= 0 && dragCol >= 0 )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
return;
}
if ( dragRow >= 0 )
{
m_dragRowOrCol = dragRow;
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{ {
if ( IsSelection() ) if ( CanDragRowSize() && CanDragGridSize() )
{ ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
if (m_winCapture)
{
m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
SendEvent( wxEVT_GRID_RANGE_SELECT, -1, -1, event );
}
// Show the edit control, if it has been hidden for
// drag-shrinking.
ShowCellEditControl();
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
DoEndDragResizeRow();
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
DoEndDragResizeCol();
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
} }
m_dragLastPos = -1; return;
} }
if ( dragCol >= 0 )
// ------------ Right button down
//
else if ( event.RightDown() && coords != wxGridNoCellCoords )
{ {
DisableCellEditControl(); m_dragRowOrCol = dragCol;
if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK,
coords.GetRow(), if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
coords.GetCol(),
event ) )
{ {
// no default action at the moment if ( CanDragColSize() && CanDragGridSize() )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
} }
return;
} }
// Neither on a row or col edge
// ------------ Right double click
// //
else if ( event.RightDClick() && coords != wxGridNoCellCoords ) if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
{ {
DisableCellEditControl(); ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK,
coords.GetRow(),
coords.GetCol(),
event ) )
{
// no default action at the moment
}
}
// ------------ Moving and no button action
//
else if ( event.Moving() && !event.IsButton() )
{
int dragRow = YToEdgeOfRow( y );
int dragCol = XToEdgeOfCol( x );
// Dragging on the corner of a cell to resize in both
// directions is not implemented yet...
//
if ( dragRow >= 0 && dragCol >= 0 )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
return;
}
if ( dragRow >= 0 )
{
m_dragRowOrCol = dragRow;
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
if ( CanDragRowSize() && CanDragGridSize() )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
}
return;
}
if ( dragCol >= 0 )
{
m_dragRowOrCol = dragCol;
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
if ( CanDragColSize() && CanDragGridSize() )
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
}
return;
}
// Neither on a row or col edge
//
if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
{
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
}
} }
}
} }
@@ -4091,6 +4105,7 @@ void wxGrid::DoEndDragResizeRow()
dc.SetLogicalFunction( wxINVERT ); dc.SetLogicalFunction( wxINVERT );
dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos ); dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos );
HideCellEditControl(); HideCellEditControl();
SaveEditControlValue();
int rowTop = GetRowTop(m_dragRowOrCol); int rowTop = GetRowTop(m_dragRowOrCol);
SetRowSize( m_dragRowOrCol, SetRowSize( m_dragRowOrCol,
@@ -4129,6 +4144,7 @@ void wxGrid::DoEndDragResizeCol()
dc.SetLogicalFunction( wxINVERT ); dc.SetLogicalFunction( wxINVERT );
dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top+ch ); dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top+ch );
HideCellEditControl(); HideCellEditControl();
SaveEditControlValue();
int colLeft = GetColLeft(m_dragRowOrCol); int colLeft = GetColLeft(m_dragRowOrCol);
SetColSize( m_dragRowOrCol, SetColSize( m_dragRowOrCol,
@@ -4826,11 +4842,11 @@ void wxGrid::DrawGridSpace( wxDC& dc )
dc.SetPen( *wxTRANSPARENT_PEN ); dc.SetPen( *wxTRANSPARENT_PEN );
if ( right > GetColRight(m_numCols-1) ) if ( right > GetColRight(m_numCols-1) )
dc.DrawRectangle( GetColRight(m_numCols-1)+1, top, dc.DrawRectangle( GetColRight(m_numCols-1), top,
right - GetColRight(m_numCols-1), ch ); right - GetColRight(m_numCols-1), ch );
if ( bottom > GetRowBottom(m_numRows-1) ) if ( bottom > GetRowBottom(m_numRows-1) )
dc.DrawRectangle( left, GetRowBottom(m_numRows-1)+1, dc.DrawRectangle( left, GetRowBottom(m_numRows-1),
cw, bottom - GetRowBottom(m_numRows-1) ); cw, bottom - GetRowBottom(m_numRows-1) );
} }
} }