X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8fc856de1fc08a2667daf170f9b5e293f7b706ad..8b4457965a0c0d0ef828dbf7cca3d2f947083054:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index f40295f5f3..3a3ba4e0ba 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1159,20 +1159,25 @@ void wxGridCellFloatEditor::SetParameters(const wxString& params) wxString wxGridCellFloatEditor::GetString() const { wxString fmt; - if ( m_width == -1 ) - { - // default width/precision - fmt = _T("%f"); - } - else if ( m_precision == -1 ) + if ( m_precision == -1 && m_width != -1) { // default precision fmt.Printf(_T("%%%d.f"), m_width); } - else + else if ( m_precision != -1 && m_width == -1) + { + // default width + fmt.Printf(_T("%%.%df"), m_precision); + } + else if ( m_precision != -1 && m_width != -1 ) { fmt.Printf(_T("%%%d.%df"), m_width, m_precision); } + else + { + // default width/precision + fmt = _T("%f"); + } return wxString::Format(fmt, m_valueOld); } @@ -1582,6 +1587,14 @@ void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) 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: @@ -1590,6 +1603,85 @@ void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) 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(); } @@ -5816,7 +5908,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) // Dragging on the corner of a cell to resize in both // directions is not implemented yet... // - if ( dragRow >= 0 && dragCol >= 0 ) + if ( dragRow >= 0 && dragCol >= 0 ) { ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); return; @@ -5831,16 +5923,8 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) if ( CanDragRowSize() && CanDragGridSize() ) ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW); } - - if ( dragCol >= 0 ) - { - m_dragRowOrCol = dragCol; - } - - return; } - - if ( dragCol >= 0 ) + else if ( dragCol >= 0 ) { m_dragRowOrCol = dragCol; @@ -5849,15 +5933,13 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) if ( CanDragColSize() && CanDragGridSize() ) ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL); } - - return; } - - // Neither on a row or col edge - // - if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL ) + else // Neither on a row or col edge { - ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); + if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL ) + { + ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL); + } } } } @@ -7484,8 +7566,8 @@ void wxGrid::DrawTextRectangle( wxDC& dc, int vertAlign, int textOrientation ) { - long textWidth, textHeight; - long lineWidth, lineHeight; + long textWidth = 0, textHeight = 0; + long lineWidth = 0, lineHeight = 0; int nLines; dc.SetClippingRegion( rect ); @@ -7614,7 +7696,7 @@ void wxGrid::GetTextBoxSize( const wxDC& dc, { long w = 0; long h = 0; - long lineW, lineH; + long lineW = 0, lineH = 0; size_t i; for ( i = 0; i < lines.GetCount(); i++ ) @@ -7690,9 +7772,6 @@ void wxGrid::EnableCellEditControl( bool enable ) if (! m_editable) return; - if ( m_currentCellCoords == wxGridNoCellCoords ) - SetCurrentCell( 0, 0 ); - if ( enable != m_cellEditCtrlEnabled ) { if ( enable ) @@ -7777,7 +7856,7 @@ void wxGrid::ShowCellEditControl() { if ( IsCellEditControlEnabled() ) { - if ( !IsVisible( m_currentCellCoords ) ) + if ( !IsVisible( m_currentCellCoords, false ) ) { m_cellEditCtrlEnabled = false; return; @@ -7803,6 +7882,10 @@ void wxGrid::ShowCellEditControl() // 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 @@ -7877,8 +7960,21 @@ void wxGrid::ShowCellEditControl() 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(); @@ -8208,7 +8304,11 @@ void wxGrid::MakeCellVisible( int row, int col ) 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(); } @@ -9602,7 +9702,7 @@ wxGrid::GetDefaultEditorForType(const wxString& typeName) const 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());