///////////////////////////////////////////////////////////////////////////
-// Name: generic/grid.cpp
+// Name: src/generic/grid.cpp
// Purpose: wxGrid and related classes
// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
// Modified by: Robin Dunn, Vadim Zeitlin
void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
{
+ int row = m_grid->GetGridCursorRow();
+ int col = m_grid->GetGridCursorCol();
+ wxRect rect = m_grid->CellToRect( row, col );
+ int cw, ch;
+ m_grid->GetGridWindow()->GetClientSize( &cw, &ch );
+ // if cell width is smaller than grid client area, cell is wholly visible
+ bool wholeCellVisible = (rect.GetWidth() < cw);
+
switch ( event.GetKeyCode() )
{
case WXK_ESCAPE:
case WXK_NUMPAD_ENTER:
break;
+ case WXK_HOME:
+ {
+ if( wholeCellVisible )
+ {
+ // no special processing needed...
+ event.Skip();
+ break;
+ }
+
+ // do special processing for partly visible cell...
+
+ // get the widths of all cells previous to this one
+ int colXPos = 0;
+ for ( int i = 0; i < col; i++ )
+ {
+ colXPos += m_grid->GetColSize(i);
+ }
+
+ int xUnit = 1, yUnit = 1;
+ m_grid->GetScrollPixelsPerUnit(&xUnit, &yUnit);
+ if (col != 0)
+ {
+ m_grid->Scroll(colXPos/xUnit-1, m_grid->GetScrollPos(wxVERTICAL));
+ }
+ else
+ {
+ m_grid->Scroll(colXPos/xUnit, m_grid->GetScrollPos(wxVERTICAL));
+ }
+ event.Skip();
+ break;
+ }
+ case WXK_END:
+ {
+ if( wholeCellVisible )
+ {
+ // no special processing needed...
+ event.Skip();
+ break;
+ }
+
+ // do special processing for partly visible cell...
+
+ int textWidth = 0;
+ wxString value = m_grid->GetCellValue(row, col);
+ if ( wxEmptyString != value )
+ {
+ // get width of cell CONTENTS (text)
+ int y;
+ wxFont font = m_grid->GetCellFont(row, col);
+ m_grid->GetTextExtent(value, &textWidth, &y, NULL, NULL, &font);
+ // try to RIGHT align the text by scrolling
+ int client_right = m_grid->GetGridWindow()->GetClientSize().GetWidth();
+ // (m_grid->GetScrollLineX()*2) is a factor for not scrolling to far,
+ // otherwise the last part of the cell content might be hidden below the scroll bar
+ // FIXME: maybe there is a more suitable correction?
+ textWidth -= (client_right - (m_grid->GetScrollLineX()*2));
+ if ( textWidth < 0 )
+ {
+ textWidth = 0;
+ }
+ }
+
+ // get the widths of all cells previous to this one
+ int colXPos = 0;
+ for ( int i = 0; i < col; i++ )
+ {
+ colXPos += m_grid->GetColSize(i);
+ }
+ // and add the (modified) text width of the cell contents
+ // as we'd like to see the last part of the cell contents
+ colXPos += textWidth;
+
+ int xUnit = 1, yUnit = 1;
+ m_grid->GetScrollPixelsPerUnit(&xUnit, &yUnit);
+ m_grid->Scroll(colXPos/xUnit-1, m_grid->GetScrollPos(wxVERTICAL));
+ event.Skip();
+ break;
+ }
+
default:
event.Skip();
}
m_waitForSlowClick = true;
}
}
-
}
m_winCapture = NULL;
}
- if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl())
+ if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl() )
{
ClearSelection();
EnableCellEditControl();
}
break;
- case WXK_PRIOR:
+ case WXK_PAGEUP:
MovePageUp();
break;
- case WXK_NEXT:
+ case WXK_PAGEDOWN:
MovePageDown();
break;
return;
}
- wxClientDC dc(m_gridWin);
- PrepareDC(dc);
+ wxClientDC dc( m_gridWin );
+ PrepareDC( dc );
if ( m_currentCellCoords != wxGridNoCellCoords )
{
if ( IsVisible( m_currentCellCoords, false ) )
{
wxRect r;
- r = BlockToDeviceRect(m_currentCellCoords, m_currentCellCoords);
+ r = BlockToDeviceRect( m_currentCellCoords, m_currentCellCoords );
if ( !m_gridLinesEnabled )
{
r.x--;
// Otherwise refresh redraws the highlight!
m_currentCellCoords = coords;
- DrawGridCellArea(dc,cells);
+ DrawGridCellArea( dc, cells );
DrawAllGridLines( dc, r );
}
}
m_currentCellCoords = coords;
- wxGridCellAttr* attr = GetCellAttr(coords);
- DrawCellHighlight(dc, attr);
+ wxGridCellAttr *attr = GetCellAttr( coords );
+ DrawCellHighlight( dc, attr );
attr->DecRef();
}
wxString eol = wxTextFile::GetEOL( wxTextFileType_Unix );
wxString tVal = wxTextFile::Translate( value, wxTextFileType_Unix );
- while ( startPos < (int)tVal.Length() )
+ while ( startPos < (int)tVal.length() )
{
pos = tVal.Mid(startPos).Find( eol );
if ( pos < 0 )
startPos += pos + 1;
}
- if ( startPos < (int)value.Length() )
+ if ( startPos < (int)value.length() )
{
lines.Add( value.Mid( startPos ) );
}
if (! m_editable)
return;
- if ( m_currentCellCoords == wxGridNoCellCoords )
- SetCurrentCell( 0, 0 );
-
if ( enable != m_cellEditCtrlEnabled )
{
if ( enable )
{
if ( IsCellEditControlEnabled() )
{
- if ( !IsVisible( m_currentCellCoords ) )
+ if ( !IsVisible( m_currentCellCoords, false ) )
{
m_cellEditCtrlEnabled = false;
return;
//
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ int nXMove = 0;
+ if (rect.x < 0)
+ nXMove = rect.x;
+
// done in PaintBackground()
#if 0
// erase the highlight and the cell contents because the editor
int c_rows, c_cols;
GetCellSize( row, i, &c_rows, &c_cols );
// looks weird going over a multicell
- if (m_table->IsEmptyCell(row,i) &&
+ if (m_table->IsEmptyCell( row, i ) &&
(rect.width < maxWidth) && (c_rows == 1))
- rect.width += GetColWidth(i);
+ rect.width += GetColWidth( i );
else
break;
}
if (rect.GetRight() > client_right)
- rect.SetRight(client_right - 1);
+ rect.SetRight( client_right - 1 );
}
- editor->SetCellAttr(attr);
+ editor->SetCellAttr( attr );
editor->SetSize( rect );
+ editor->GetControl()->Move( editor->GetControl()->GetPosition().x + nXMove, editor->GetControl()->GetPosition().y );
editor->Show( true, attr );
+ int colXPos = 0;
+ for (int i = 0; i < m_currentCellCoords.GetCol(); i++)
+ {
+ colXPos += GetColSize( i );
+ }
+
+ int xUnit = 1, yUnit = 1;
+ GetScrollPixelsPerUnit( &xUnit, &yUnit );
+ if (m_currentCellCoords.GetCol() != 0)
+ Scroll( colXPos / xUnit - 1, GetScrollPos( wxVERTICAL ) );
+ else
+ Scroll( colXPos / xUnit, GetScrollPos( wxVERTICAL ) );
+
// recalc dimensions in case we need to
// expand the scrolled window to account for editor
CalcDimensions();
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
- wxGridCellAttr* attr = GetCellAttr(row, col);
+ wxGridCellAttr *attr = GetCellAttr(row, col);
wxGridCellEditor *editor = attr->GetEditor(this, row, col);
editor->Show( false );
editor->DecRef();
ypos += m_scrollLineY;
}
- if ( left < 0 )
+ // special handling for wide cells - show always left part of the cell!
+ // Otherwise, e.g. when stepping from row to row, it would jump between
+ // left and right part of the cell on every step!
+// if ( left < 0 )
+ if ( left < 0 || (right-left) >= cw )
{
xpos = r.GetLeft();
}
if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetRow() >= 0 )
{
- if ( expandSelection)
+ if ( expandSelection )
{
if ( m_selectingKeyboard == wxGridNoCellCoords )
m_selectingKeyboard = m_currentCellCoords;
int index = m_typeRegistry->FindOrCloneDataType(typeName);
if ( index == wxNOT_FOUND )
{
- wxString errStr;
+ wxString errStr;
errStr.Printf(wxT("Unknown data type name [%s]"), typeName.c_str());
wxFAIL_MSG(errStr.c_str());
}
#endif // wxUSE_GRID
-