X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ffdd3c9861e9fb1fc544435f2479b3e486194b33..c989314692827562d3d2147ae880886b5eaa530e:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 8768d2316e..4957e2a461 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -132,6 +132,7 @@ private: void OnPaint( wxPaintEvent& event ); void OnMouseEvent( wxMouseEvent& event ); + void OnMouseWheel( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& event ); void OnKeyUp( wxKeyEvent& ); @@ -152,6 +153,7 @@ private: void OnPaint( wxPaintEvent &event ); void OnMouseEvent( wxMouseEvent& event ); + void OnMouseWheel( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& event ); void OnKeyUp( wxKeyEvent& ); @@ -171,6 +173,7 @@ private: wxGrid *m_owner; void OnMouseEvent( wxMouseEvent& event ); + void OnMouseWheel( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& event ); void OnKeyUp( wxKeyEvent& ); void OnPaint( wxPaintEvent& event ); @@ -203,6 +206,7 @@ private: wxGridColLabelWindow *m_colLabelWin; void OnPaint( wxPaintEvent &event ); + void OnMouseWheel( wxMouseEvent& event ); void OnMouseEvent( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& ); void OnKeyUp( wxKeyEvent& ); @@ -374,8 +378,15 @@ wxGridCellCoords wxGridNoCellCoords( -1, -1 ); wxRect wxGridNoCellRect( -1, -1, -1, -1 ); // scroll line size -// TODO: fixed so far - make configurable later (and also different for x/y) -static const size_t GRID_SCROLL_LINE = 10; +// TODO: this doesn't work at all, grid cells have different sizes and approx +// calculations don't work as because of the size mismatch scrollbars +// sometimes fail to be shown when they should be or vice versa +// +// The scroll bars may be a little flakey once in a while, but that is +// surely much less horrible than having scroll lines of only 1!!! +// -- Robin +static const size_t GRID_SCROLL_LINE = 15; // 1; + // the size of hash tables used a bit everywhere (the max number of elements // in these hash tables is the number of rows/columns) @@ -1410,12 +1421,12 @@ void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) break; case WXK_TAB: - event.Skip( m_grid->GetEventHandler()->ProcessEvent( event ) ); + m_grid->GetEventHandler()->ProcessEvent( event ); break; - case WXK_NUMPAD_ENTER: case WXK_RETURN: - if ( !m_grid->GetEventHandler()->ProcessEvent(event) ) + case WXK_NUMPAD_ENTER: + if (!m_grid->GetEventHandler()->ProcessEvent(event)) m_editor->HandleReturn(event); break; @@ -1653,8 +1664,15 @@ wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) { if ( m_width == -1 ) { + if ( m_precision == -1 ) + { // default width/precision m_format = _T("%f"); + } + else + { + m_format.Printf(_T("%%.%df"), m_precision); + } } else if ( m_precision == -1 ) { @@ -1668,6 +1686,7 @@ wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) } text.Printf(m_format, val); + } //else: text already contains the string @@ -1706,8 +1725,6 @@ wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid, void wxGridCellFloatRenderer::SetParameters(const wxString& params) { - bool ok = TRUE; - if ( !params ) { // reset to defaults @@ -1720,37 +1737,34 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params) if ( !!tmp ) { long width; - if ( !tmp.ToLong(&width) ) + if ( tmp.ToLong(&width) ) { - ok = FALSE; + SetWidth((int)width); } else { - SetWidth((int)width); + wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str()); + } + } tmp = params.AfterFirst(_T(',')); if ( !!tmp ) { long precision; - if ( !tmp.ToLong(&precision) ) + if ( tmp.ToLong(&precision) ) { - ok = FALSE; + SetPrecision((int)precision); } else { - SetPrecision((int)precision); - } - } - } + wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str()); } - if ( !ok ) - { - wxLogDebug(_T("Invalid wxGridCellFloatRenderer parameter string '%s ignored"), params.c_str()); } } } + // ---------------------------------------------------------------------------- // wxGridCellBoolRenderer // ---------------------------------------------------------------------------- @@ -1877,11 +1891,47 @@ wxGridCellAttr *wxGridCellAttr::Clone() const if ( IsReadOnly() ) attr->SetReadOnly(); + attr->SetKind( m_attrkind ); + attr->SetDefAttr(m_defGridAttr); return attr; } +void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom) +{ + if ( !HasTextColour() && mergefrom->HasTextColour() ) + SetTextColour(mergefrom->GetTextColour()); + if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() ) + SetBackgroundColour(mergefrom->GetBackgroundColour()); + if ( !HasFont() && mergefrom->HasFont() ) + SetFont(mergefrom->GetFont()); + if ( !!HasAlignment() && mergefrom->HasAlignment() ){ + int hAlign, vAlign; + mergefrom->GetAlignment( &hAlign, &vAlign); + SetAlignment(hAlign, vAlign); + } + + // Directly access member functions as GetRender/Editor don't just return + // m_renderer/m_editor + // + // Maybe add support for merge of Render and Editor? + if (!HasRenderer() && mergefrom->HasRenderer() ) + { + m_renderer = mergefrom->m_renderer; + m_renderer->IncRef(); + } + if ( !HasEditor() && mergefrom->HasEditor() ) + { + m_editor = mergefrom->m_editor; + m_editor->IncRef(); + } + if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() ) + SetReadOnly(mergefrom->IsReadOnly()); + + SetDefAttr(mergefrom->m_defGridAttr); +} + const wxColour& wxGridCellAttr::GetTextColour() const { if (HasTextColour()) @@ -2234,28 +2284,77 @@ void wxGridCellAttrProvider::InitData() m_data = new wxGridCellAttrProviderData; } -wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col) const +wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, + wxGridCellAttr::wxAttrKind kind ) const { wxGridCellAttr *attr = (wxGridCellAttr *)NULL; if ( m_data ) { - // first look for the attribute of this specific cell - attr = m_data->m_cellAttrs.GetAttr(row, col); - - if ( !attr ) + switch(kind) { - // then look for the col attr (col attributes are more common than - // the row ones, hence they have priority) - attr = m_data->m_colAttrs.GetAttr(col); - } - - if ( !attr ) + case (wxGridCellAttr::Any): + //Get cached merge attributes. + // Currenlty not used as no cache implemented as not mutiable + // attr = m_data->m_mergeAttr.GetAttr(row, col); + if(!attr) + { + //Basicaly implement old version. + //Also check merge cache, so we don't have to re-merge every time.. + wxGridCellAttr *attrcell = (wxGridCellAttr *)NULL, + *attrrow = (wxGridCellAttr *)NULL, + *attrcol = (wxGridCellAttr *)NULL; + + attrcell = m_data->m_cellAttrs.GetAttr(row, col); + attrcol = m_data->m_colAttrs.GetAttr(col); + attrrow = m_data->m_rowAttrs.GetAttr(row); + + if((attrcell != attrrow) && (attrrow !=attrcol) && (attrcell != attrcol)){ + // Two or move are non NULL + attr = new wxGridCellAttr; + attr->SetKind(wxGridCellAttr::Merged); + + //Order important.. + if(attrcell){ + attr->MergeWith(attrcell); + attrcell->DecRef(); + } + if(attrcol){ + attr->MergeWith(attrcol); + attrcol->DecRef(); + } + if(attrrow){ + attr->MergeWith(attrrow); + attrrow->DecRef(); + } + //store merge attr if cache implemented + //attr->IncRef(); + //m_data->m_mergeAttr.SetAttr(attr, row, col); + } + else { - // finally try the row attributes + // one or none is non null return it or null. + if(attrrow) attr = attrrow; + if(attrcol) attr = attrcol; + if(attrcell) attr = attrcell; + } + } + break; + case (wxGridCellAttr::Cell): + attr = m_data->m_cellAttrs.GetAttr(row, col); + break; + case (wxGridCellAttr::Col): + attr = m_data->m_colAttrs.GetAttr(col); + break; + case (wxGridCellAttr::Row): attr = m_data->m_rowAttrs.GetAttr(row); + break; + default: + // unused as yet... + // (wxGridCellAttr::Default): + // (wxGridCellAttr::Merged): + break; } } - return attr; } @@ -2440,16 +2539,16 @@ int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName) wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index) { wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer; - if (renderer) - renderer->IncRef(); + if (renderer) + renderer->IncRef(); return renderer; } wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) { wxGridCellEditor* editor = m_typeinfo[index]->m_editor; - if (editor) - editor->IncRef(); + if (editor) + editor->IncRef(); return editor; } @@ -2487,10 +2586,10 @@ bool wxGridTableBase::CanHaveAttributes() return TRUE; } -wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col) +wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) { if ( m_attrProvider ) - return m_attrProvider->GetAttr(row, col); + return m_attrProvider->GetAttr(row, col, kind); else return (wxGridCellAttr *)NULL; } @@ -2499,6 +2598,7 @@ void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col) { if ( m_attrProvider ) { + attr->SetKind(wxGridCellAttr::Cell); m_attrProvider->SetAttr(attr, row, col); } else @@ -2513,6 +2613,7 @@ void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row) { if ( m_attrProvider ) { + attr->SetKind(wxGridCellAttr::Row); m_attrProvider->SetRowAttr(attr, row); } else @@ -2527,6 +2628,7 @@ void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col) { if ( m_attrProvider ) { + attr->SetKind(wxGridCellAttr::Col); m_attrProvider->SetColAttr(attr, col); } else @@ -3100,6 +3202,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow, wxWindow ) BEGIN_EVENT_TABLE( wxGridRowLabelWindow, wxWindow ) EVT_PAINT( wxGridRowLabelWindow::OnPaint ) + EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown ) EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp ) @@ -3138,6 +3241,12 @@ void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent& event ) } +void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} + + // This seems to be required for wxMotif otherwise the mouse // cursor must be in the cell edit control to get key events // @@ -3159,6 +3268,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow, wxWindow ) BEGIN_EVENT_TABLE( wxGridColLabelWindow, wxWindow ) EVT_PAINT( wxGridColLabelWindow::OnPaint ) + EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown ) EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp ) @@ -3196,6 +3306,11 @@ void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent& event ) m_owner->ProcessColLabelMouseEvent( event ); } +void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} + // This seems to be required for wxMotif otherwise the mouse // cursor must be in the cell edit control to get key events @@ -3217,6 +3332,7 @@ void wxGridColLabelWindow::OnKeyUp( wxKeyEvent& event ) IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow, wxWindow ) BEGIN_EVENT_TABLE( wxGridCornerLabelWindow, wxWindow ) + EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent ) EVT_PAINT( wxGridCornerLabelWindow::OnPaint) EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown ) @@ -3255,6 +3371,11 @@ void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent& event ) } +void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} + // This seems to be required for wxMotif otherwise the mouse // cursor must be in the cell edit control to get key events // @@ -3276,6 +3397,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridWindow, wxPanel ) BEGIN_EVENT_TABLE( wxGridWindow, wxPanel ) EVT_PAINT( wxGridWindow::OnPaint ) + EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridWindow::OnKeyDown ) EVT_KEY_UP( wxGridWindow::OnKeyUp ) @@ -3328,6 +3450,10 @@ void wxGridWindow::OnMouseEvent( wxMouseEvent& event ) m_owner->ProcessGridCellMouseEvent( event ); } +void wxGridWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} // This seems to be required for wxMotif/wxGTK otherwise the mouse // cursor must be in the cell edit control to get key events @@ -3412,6 +3538,7 @@ void wxGrid::Create() m_defaultCellAttr->SetDefAttr(m_defaultCellAttr); // Set default cell attributes + m_defaultCellAttr->SetKind(wxGridCellAttr::Default); m_defaultCellAttr->SetFont(GetFont()); m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP); m_defaultCellAttr->SetTextColour( @@ -3563,6 +3690,8 @@ void wxGrid::Init() m_gridLineColour = wxColour( 128, 128, 255 ); m_gridLinesEnabled = TRUE; m_cellHighlightColour = m_gridLineColour; + m_cellHighlightPenWidth = 3; + m_cellHighlightROPenWidth = 1; m_cursorMode = WXGRID_CURSOR_SELECT_CELL; m_winCapture = (wxWindow *)NULL; @@ -3679,19 +3808,44 @@ void wxGrid::CalcDimensions() int cw, ch; GetClientSize( &cw, &ch ); - if ( m_numRows > 0 || m_numCols > 0 ) - { - int right = m_numCols > 0 ? GetColRight( m_numCols-1 ) + m_extraWidth : 0; - int bottom = m_numRows > 0 ? GetRowBottom( m_numRows-1 ) + m_extraHeight : 0; + if ( m_colLabelWin->IsShown() ) + cw -= m_rowLabelWidth; + if ( m_rowLabelWin->IsShown() ) + ch -= m_colLabelHeight; - // TODO: restore the scroll position that we had before sizing - // - int x, y; - GetViewStart( &x, &y ); - SetScrollbars( GRID_SCROLL_LINE, GRID_SCROLL_LINE, - right/GRID_SCROLL_LINE, bottom/GRID_SCROLL_LINE, - x, y ); + // grid total size + int w = m_numCols > 0 ? GetColRight(m_numCols - 1) + m_extraWidth + 1 : 0; + int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) + m_extraHeight + 1 : 0; + + // preserve (more or less) the previous position + int x, y; + GetViewStart( &x, &y ); + // maybe we don't need scrollbars at all? and if we do, transform w and h + // from pixels into logical units + if ( w <= cw ) + { + w = 0; x= 0; } + else + { + w = (w + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE; + if ( x >= w ) + x = w - 1; + } + if ( h <= ch ) + { + h = 0; y = 0; + } + else + { + h = (h + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE; + if ( y >= h ) + y = h - 1; + } + + // do set scrollbar parameters + SetScrollbars( GRID_SCROLL_LINE, GRID_SCROLL_LINE, + w, h, x, y, (GetBatchCount() != 0)); } @@ -4008,13 +4162,9 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) CalcDimensions(); m_colLabelWin->Refresh(); } - return TRUE; } -#if 0 -// There is no path to this code !!!!!! - result = TRUE; + result = TRUE; break; -#endif } if (result && !GetBatchCount() ) @@ -4614,7 +4764,9 @@ void wxGrid::ChangeCursorMode(CursorMode mode, cursorModes[m_cursorMode], cursorModes[mode]); #endif // __WXDEBUG__ - if ( mode == m_cursorMode ) + if ( mode == m_cursorMode && + win == m_winCapture && + captureMouse == (m_winCapture != NULL)) return; if ( !win ) @@ -5285,13 +5437,12 @@ bool wxGrid::SendEvent( const wxEventType type, type, this, rowOrCol, - mouseEv.GetX() + GetColLabelSize(), - mouseEv.GetY() + GetRowLabelSize(), + mouseEv.GetX() + GetRowLabelSize(), + mouseEv.GetY() + GetColLabelSize(), mouseEv.ControlDown(), mouseEv.ShiftDown(), mouseEv.AltDown(), mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); } else if ( type == wxEVT_GRID_RANGE_SELECT ) @@ -5316,14 +5467,13 @@ bool wxGrid::SendEvent( const wxEventType type, type, this, row, col, - mouseEv.GetX() + GetColLabelSize(), - mouseEv.GetY() + GetRowLabelSize(), + mouseEv.GetX() + GetRowLabelSize(), + mouseEv.GetY() + GetColLabelSize(), FALSE, mouseEv.ControlDown(), mouseEv.ShiftDown(), mouseEv.AltDown(), mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); } } @@ -5792,7 +5942,6 @@ void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCo // (old comment from when this was the body of SelectBlock) } - // // ------ functions to get/send data (see also public functions) // @@ -5936,10 +6085,27 @@ void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ) // hmmm... what could we do here to show that the cell is disabled? // for now, I just draw a thinner border than for the other ones, but // it doesn't look really good - dc.SetPen(wxPen(m_cellHighlightColour, attr->IsReadOnly() ? 1 : 3, wxSOLID)); - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRectangle(rect); + int penWidth = attr->IsReadOnly() ? m_cellHighlightROPenWidth : m_cellHighlightPenWidth; + + if (penWidth > 0) { + + // The center of th drawn line is where the position/width/height of + // the rectangle is actually at, (on wxMSW atr least,) so we will + // reduce the size of the rectangle to compensate for the thickness of + // the line. If this is too strange on non wxMSW platforms then + // please #ifdef this appropriately. + rect.x += penWidth/2; + rect.y += penWidth/2; + rect.width -= penWidth-1; + rect.height -= penWidth-1; + + + // Now draw the rectangle + dc.SetPen(wxPen(m_cellHighlightColour, penWidth, wxSOLID)); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(rect); + } #if 0 // VZ: my experiments with 3d borders... @@ -6021,7 +6187,7 @@ void wxGrid::DrawHighlight(wxDC& dc) // This is used to redraw all grid lines e.g. when the grid line colour // has been changed // -void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED_GTK(reg) ) +void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) { if ( !m_gridLinesEnabled || !m_numRows || @@ -7492,6 +7658,38 @@ void wxGrid::SetCellHighlightColour( const wxColour& colour ) } } +void wxGrid::SetCellHighlightPenWidth(int width) +{ + if (m_cellHighlightPenWidth != width) { + m_cellHighlightPenWidth = width; + + // Just redrawing the cell highlight is not enough since that won't + // make any visible change if the the thickness is getting smaller. + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) + return; + wxRect rect = CellToRect(row, col); + m_gridWin->Refresh(TRUE, &rect); + } +} + +void wxGrid::SetCellHighlightROPenWidth(int width) +{ + if (m_cellHighlightROPenWidth != width) { + m_cellHighlightROPenWidth = width; + + // Just redrawing the cell highlight is not enough since that won't + // make any visible change if the the thickness is getting smaller. + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) + return; + wxRect rect = CellToRect(row, col); + m_gridWin->Refresh(TRUE, &rect); + } +} + void wxGrid::EnableGridLines( bool enable ) { if ( enable != m_gridLinesEnabled ) @@ -7695,6 +7893,7 @@ void wxGrid::ClearAttrCache() if ( m_attrCache.row != -1 ) { wxSafeDecRef(m_attrCache.attr); + m_attrCache.attr = NULL; m_attrCache.row = -1; } } @@ -7737,7 +7936,7 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const wxGridCellAttr *attr; if ( !LookupAttr(row, col, &attr) ) { - attr = m_table ? m_table->GetAttr(row, col) : (wxGridCellAttr *)NULL; + attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any) : (wxGridCellAttr *)NULL; CacheAttr(row, col, attr); } if (attr) @@ -7755,25 +7954,19 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const { - wxGridCellAttr *attr; - if ( !LookupAttr(row, col, &attr) || !attr ) - { + wxGridCellAttr *attr = (wxGridCellAttr *)NULL; wxASSERT_MSG( m_table, _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") ); - attr = m_table->GetAttr(row, col); + attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell ); if ( !attr ) { attr = new wxGridCellAttr; // artificially inc the ref count to match DecRef() in caller attr->IncRef(); - m_table->SetAttr(attr, row, col); } - - CacheAttr(row, col, attr); - } attr->SetDefAttr(m_defaultCellAttr); return attr; } @@ -7805,11 +7998,16 @@ void wxGrid::SetColFormatFloat(int col, int width, int precision) void wxGrid::SetColFormatCustom(int col, const wxString& typeName) { - wxGridCellAttr *attr = new wxGridCellAttr; + wxGridCellAttr *attr = (wxGridCellAttr *)NULL; + + attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col ); + if(!attr) + attr = new wxGridCellAttr; wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName); attr->SetRenderer(renderer); SetColAttr(col, attr); + } // ---------------------------------------------------------------------------- @@ -7821,6 +8019,7 @@ void wxGrid::SetRowAttr(int row, wxGridCellAttr *attr) if ( CanHaveAttributes() ) { m_table->SetRowAttr(attr, row); + ClearAttrCache(); } else { @@ -7833,6 +8032,7 @@ void wxGrid::SetColAttr(int col, wxGridCellAttr *attr) if ( CanHaveAttributes() ) { m_table->SetColAttr(attr, col); + ClearAttrCache(); } else { @@ -7991,8 +8191,8 @@ void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows ) if ( resizeExistingRows ) { InitRowHeights(); - - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } } @@ -8015,7 +8215,8 @@ void wxGrid::SetRowSize( int row, int height ) { m_rowBottoms[i] += diff; } - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) @@ -8025,8 +8226,8 @@ void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) if ( resizeExistingCols ) { InitColWidths(); - - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } } @@ -8051,7 +8252,8 @@ void wxGrid::SetColSize( int col, int width ) { m_colRights[i] += diff; } - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } @@ -8153,11 +8355,34 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) } } - if ( column ) + if ( column ){ SetColSize(col, extentMax); - else + if ( !GetBatchCount() ) + { + int cw, ch, dummy; + m_gridWin->GetClientSize( &cw, &ch ); + wxRect rect ( CellToRect( 0, col ) ); + rect.y = 0; + CalcScrolledPosition(rect.x, 0, &rect.x, &dummy); + rect.width = cw - rect.x; + rect.height = m_colLabelHeight; + m_colLabelWin->Refresh( TRUE, &rect ); + } + } + else{ SetRowSize(row, extentMax); - + if ( !GetBatchCount() ) + { + int cw, ch, dummy; + m_gridWin->GetClientSize( &cw, &ch ); + wxRect rect ( CellToRect( row, 0 ) ); + rect.x = 0; + CalcScrolledPosition(0, rect.y, &dummy, &rect.y); + rect.width = m_rowLabelWidth; + rect.height = ch - rect.y; + m_rowLabelWin->Refresh( TRUE, &rect ); + } + } if ( setAsMin ) { if ( column ) @@ -8171,6 +8396,8 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin) { int width = m_rowLabelWidth; + if ( !calcOnly ) + BeginBatch(); for ( int col = 0; col < m_numCols; col++ ) { if ( !calcOnly ) @@ -8180,7 +8407,8 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin) width += GetColWidth(col); } - + if ( !calcOnly ) + EndBatch(); return width; } @@ -8188,6 +8416,8 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin) { int height = m_colLabelHeight; + if ( !calcOnly ) + BeginBatch(); for ( int row = 0; row < m_numRows; row++ ) { if ( !calcOnly ) @@ -8197,14 +8427,15 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin) height += GetRowHeight(row); } - + if ( !calcOnly ) + EndBatch(); return height; } void wxGrid::AutoSize() { // set the size too - SetSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE)); + SetClientSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE)); } wxSize wxGrid::DoGetBestSize() const @@ -8292,7 +8523,8 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, void wxGrid::SelectAll() { - m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 ); + if ( m_numRows > 0 && m_numCols > 0 ) + m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 ); } //