X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a9339fe22c1815cfbbf2ed9c300c897256644d18..593ac33e50ab0b01f6186773fa646104d410f365:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 9056462ed1..81140534de 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -188,9 +188,9 @@ class WXDLLIMPEXP_ADV wxGridWindow : public wxWindow public: wxGridWindow() { - m_owner = (wxGrid *)NULL; - m_rowLabelWin = (wxGridRowLabelWindow *)NULL; - m_colLabelWin = (wxGridColLabelWindow *)NULL; + m_owner = NULL; + m_rowLabelWin = NULL; + m_colLabelWin = NULL; } wxGridWindow( wxGrid *parent, @@ -800,13 +800,13 @@ void wxGridCellTextEditor::SetParameters(const wxString& params) else { long tmp; - if ( !params.ToLong(&tmp) ) + if ( params.ToLong(&tmp) ) { - wxLogDebug( _T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str() ); + m_maxChars = (size_t)tmp; } else { - m_maxChars = (size_t)tmp; + wxLogDebug( _T("Invalid wxGridCellTextEditor parameter string '%s' ignored"), params.c_str() ); } } } @@ -850,7 +850,7 @@ void wxGridCellNumberEditor::Create(wxWindow* parent, #if wxUSE_VALIDATORS Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); -#endif // wxUSE_VALIDATORS +#endif } } @@ -1043,7 +1043,7 @@ void wxGridCellFloatEditor::Create(wxWindow* parent, #if wxUSE_VALIDATORS Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); -#endif // wxUSE_VALIDATORS +#endif } void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid) @@ -1309,7 +1309,7 @@ void wxGridCellBoolEditor::Show(bool show, wxGridCellAttr *attr) void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) { wxASSERT_MSG(m_control, - wxT("The wxGridCellEditor must be Created first!")); + wxT("The wxGridCellEditor must be created first!")); if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) { @@ -1329,7 +1329,7 @@ bool wxGridCellBoolEditor::EndEdit(int row, int col, wxGrid* grid) { wxASSERT_MSG(m_control, - wxT("The wxGridCellEditor must be Created first!")); + wxT("The wxGridCellEditor must be created first!")); bool changed = false; bool value = CBox()->GetValue(); @@ -1350,7 +1350,7 @@ bool wxGridCellBoolEditor::EndEdit(int row, int col, void wxGridCellBoolEditor::Reset() { wxASSERT_MSG(m_control, - wxT("The wxGridCellEditor must be Created first!")); + wxT("The wxGridCellEditor must be created first!")); CBox()->SetValue(m_startValue); } @@ -1460,15 +1460,15 @@ void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell, // 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... + // 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) { wxASSERT_MSG(m_control, - wxT("The wxGridCellEditor must be Created first!")); + wxT("The wxGridCellEditor must be created first!")); wxGridCellEditorEvtHandler* evtHandler = NULL; if (m_control) @@ -1640,6 +1640,7 @@ void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) event.Skip(); break; } + case WXK_END: { if ( wholeCellVisible ) @@ -1693,6 +1694,7 @@ void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) default: event.Skip(); + break; } } @@ -1764,21 +1766,21 @@ void wxGridCellStringRenderer::SetTextColoursAndFont(const wxGrid& grid, // different coloured text when the grid is disabled if ( grid.IsEnabled() ) { - if ( isSelected ) - { - dc.SetTextBackground( grid.GetSelectionBackground() ); - dc.SetTextForeground( grid.GetSelectionForeground() ); - } - else - { - dc.SetTextBackground( attr.GetBackgroundColour() ); - dc.SetTextForeground( attr.GetTextColour() ); - } + if ( isSelected ) + { + dc.SetTextBackground( grid.GetSelectionBackground() ); + dc.SetTextForeground( grid.GetSelectionForeground() ); + } + else + { + dc.SetTextBackground( attr.GetBackgroundColour() ); + dc.SetTextForeground( attr.GetTextColour() ); + } } else { - dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); + dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); + dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); } dc.SetFont( attr.GetFont() ); @@ -1854,7 +1856,9 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid, } if (is_empty) + { rect.width += grid.GetColSize(i); + } else { i--; @@ -1876,10 +1880,10 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid, wxRect clip = rect; clip.x += rectCell.width; // draw each overflow cell individually - int col_end = col+cell_cols + overflowCols; + int col_end = col + cell_cols + overflowCols; if (col_end >= grid.GetNumberCols()) col_end = grid.GetNumberCols() - 1; - for (int i = col+cell_cols; i <= col_end; i++) + for (int i = col + cell_cols; i <= col_end; i++) { clip.width = grid.GetColSize(i) - 1; dc.DestroyClippingRegion(); @@ -2160,7 +2164,7 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, // draw a border around checkmark int vAlign, hAlign; - attr.GetAlignment(& hAlign, &vAlign); + attr.GetAlignment(&hAlign, &vAlign); wxRect rectBorder; if (hAlign == wxALIGN_CENTRE) @@ -2187,7 +2191,9 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, bool value; if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) + { value = grid.GetTable()->GetValueAsBool(row, col); + } else { wxString cellval( grid.GetTable()->GetValue(row, col) ); @@ -2393,7 +2399,9 @@ void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const *vAlign = m_vAlign; } else if (m_defGridAttr && m_defGridAttr != this) + { m_defGridAttr->GetAlignment(hAlign, vAlign); + } else { wxFAIL_MSG(wxT("Missing default cell attribute")); @@ -2413,11 +2421,11 @@ void wxGridCellAttr::GetSize( int *num_rows, int *num_cols ) const // used, otherwise the default editor or renderer is fetched from the grid and // used. It should be the default for the data type of the cell. If it is // NULL (because the table has a type that the grid does not have in its -// registry,) then the grid's default editor or renderer is used. +// registry), then the grid's default editor or renderer is used. wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) const { - wxGridCellRenderer *renderer; + wxGridCellRenderer *renderer = NULL; if ( m_renderer && this != m_defGridAttr ) { @@ -2433,14 +2441,10 @@ wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) // GetDefaultRendererForCell() will do IncRef() for us renderer = grid->GetDefaultRendererForCell(row, col); } - else - { - renderer = NULL; - } - if ( !renderer ) + if ( renderer == NULL ) { - if (m_defGridAttr && this != m_defGridAttr ) + if ( (m_defGridAttr != NULL) && (m_defGridAttr != this) ) { // if we still don't have one then use the grid default // (no need for IncRef() here neither) @@ -2465,7 +2469,7 @@ wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) // same as above, except for s/renderer/editor/g wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) const { - wxGridCellEditor *editor; + wxGridCellEditor *editor = NULL; if ( m_editor && this != m_defGridAttr ) { @@ -2481,14 +2485,10 @@ wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) cons // GetDefaultEditorForCell() will do IncRef() for us editor = grid->GetDefaultEditorForCell(row, col); } - else - { - editor = NULL; - } - if ( !editor ) + if ( editor == NULL ) { - if ( m_defGridAttr && this != m_defGridAttr ) + if ( (m_defGridAttr != NULL) && (m_defGridAttr != this) ) { // if we still don't have one then use the grid default // (no need for IncRef() here neither) @@ -3206,7 +3206,7 @@ wxString wxGridTableBase::GetColLabelValue( int col ) // reverse the string... wxString s2; - for ( i = 0; i < n; i++ ) + for ( i = 0; i < n; i++ ) { s2 += s[n - i - 1]; } @@ -3375,9 +3375,9 @@ void wxGridStringTable::Clear() { numCols = m_data[0].GetCount(); - for ( row = 0; row < numRows; row++ ) + for ( row = 0; row < numRows; row++ ) { - for ( col = 0; col < numCols; col++ ) + for ( col = 0; col < numCols; col++ ) { m_data[row][col] = wxEmptyString; } @@ -3500,9 +3500,9 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols ) return AppendCols( numCols ); } - for ( row = 0; row < curNumRows; row++ ) + for ( row = 0; row < curNumRows; row++ ) { - for ( col = pos; col < pos + numCols; col++ ) + for ( col = pos; col < pos + numCols; col++ ) { m_data[row].Insert( wxEmptyString, col ); } @@ -3537,7 +3537,7 @@ bool wxGridStringTable::AppendCols( size_t numCols ) } #endif - for ( row = 0; row < curNumRows; row++ ) + for ( row = 0; row < curNumRows; row++ ) { m_data[row].Add( wxEmptyString, numCols ); } @@ -3579,7 +3579,7 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols ) numCols = curNumCols - pos; } - for ( row = 0; row < curNumRows; row++ ) + for ( row = 0; row < curNumRows; row++ ) { if ( numCols >= curNumCols ) { @@ -3639,7 +3639,7 @@ void wxGridStringTable::SetRowLabelValue( int row, const wxString& value ) int n = m_rowLabels.GetCount(); int i; - for ( i = n; i <= row; i++ ) + for ( i = n; i <= row; i++ ) { m_rowLabels.Add( wxGridTableBase::GetRowLabelValue(i) ); } @@ -3655,7 +3655,7 @@ void wxGridStringTable::SetColLabelValue( int col, const wxString& value ) int n = m_colLabels.GetCount(); int i; - for ( i = n; i <= col; i++ ) + for ( i = n; i <= col; i++ ) { m_colLabels.Add( wxGridTableBase::GetColLabelValue(i) ); } @@ -3822,7 +3822,7 @@ END_EVENT_TABLE() wxGridCornerLabelWindow::wxGridCornerLabelWindow( wxGrid *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE|wxFULL_REPAINT_ON_RESIZE ) + : wxWindow( parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE | wxFULL_REPAINT_ON_RESIZE ) { m_owner = parent; } @@ -4099,7 +4099,7 @@ bool wxGrid::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { if (!wxScrolledWindow::Create(parent, id, pos, size, - style | wxWANTS_CHARS , name)) + style | wxWANTS_CHARS, name)) return false; m_colMinWidths = wxLongToLongHashMap(GRID_HASH_SIZE); @@ -4147,10 +4147,15 @@ wxGrid::~wxGrid() void wxGrid::Create() { - m_created = false; // set to true by CreateGrid + // set to true by CreateGrid + m_created = false; - m_table = (wxGridTableBase *) NULL; - m_ownTable = false; + // create the type registry + m_typeRegistry = new wxGridTypeRegistry; + m_selection = NULL; + + m_table = (wxGridTableBase *) NULL; + m_ownTable = false; m_cellEditCtrlEnabled = false; @@ -4185,16 +4190,7 @@ void wxGrid::Create() m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH; m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT; - // create the type registry - m_typeRegistry = new wxGridTypeRegistry; - m_selection = NULL; - // subwindow components that make up the wxGrid - m_cornerLabelWin = new wxGridCornerLabelWindow( this, - wxID_ANY, - wxDefaultPosition, - wxDefaultSize ); - m_rowLabelWin = new wxGridRowLabelWindow( this, wxID_ANY, wxDefaultPosition, @@ -4205,6 +4201,11 @@ void wxGrid::Create() wxDefaultPosition, wxDefaultSize ); + m_cornerLabelWin = new wxGridCornerLabelWindow( this, + wxID_ANY, + wxDefaultPosition, + wxDefaultSize ); + m_gridWin = new wxGridWindow( this, m_rowLabelWin, m_colLabelWin, @@ -4287,15 +4288,15 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, if (m_ownTable) { - wxGridTableBase *t=m_table; - m_table=0; + wxGridTableBase *t = m_table; + m_table = NULL; delete t; } delete m_selection; - m_table = 0; - m_selection = 0; + m_table = NULL; + m_selection = NULL; m_numRows = 0; m_numCols = 0; } @@ -4329,10 +4330,10 @@ void wxGrid::Init() } else { - m_labelBackgroundColour = wxColour( wxT("WHITE") ); + m_labelBackgroundColour = *wxWHITE; } - m_labelTextColour = wxColour( wxT("BLACK") ); + m_labelTextColour = *wxBLACK; // init attr cache m_attrCache.row = -1; @@ -4426,7 +4427,7 @@ void wxGrid::InitRowHeights() m_rowHeights.Add( m_defaultRowHeight, m_numRows ); - for ( int i = 0; i < m_numRows; i++ ) + for ( int i = 0; i < m_numRows; i++ ) { rowBottom += m_defaultRowHeight; m_rowBottoms.Add( rowBottom ); @@ -4444,7 +4445,7 @@ void wxGrid::InitColWidths() m_colWidths.Add( m_defaultColWidth, m_numCols ); - for ( int i = 0; i < m_numCols; i++ ) + for ( int i = 0; i < m_numCols; i++ ) { colRight += m_defaultColWidth; m_colRights.Add( colRight ); @@ -4502,24 +4503,24 @@ void wxGrid::CalcDimensions() // take into account editor if shown if ( IsCellEditControlShown() ) { - int w2, h2; - int r = m_currentCellCoords.GetRow(); - int c = m_currentCellCoords.GetCol(); - int x = GetColLeft(c); - int y = GetRowTop(r); - - // how big is the editor - wxGridCellAttr* attr = GetCellAttr(r, c); - wxGridCellEditor* editor = attr->GetEditor(this, r, c); - editor->GetControl()->GetSize(&w2, &h2); - w2 += x; - h2 += y; - if ( w2 > w ) - w = w2; - if ( h2 > h ) - h = h2; - editor->DecRef(); - attr->DecRef(); + int w2, h2; + int r = m_currentCellCoords.GetRow(); + int c = m_currentCellCoords.GetCol(); + int x = GetColLeft(c); + int y = GetRowTop(r); + + // how big is the editor + wxGridCellAttr* attr = GetCellAttr(r, c); + wxGridCellEditor* editor = attr->GetEditor(this, r, c); + editor->GetControl()->GetSize(&w2, &h2); + w2 += x; + h2 += y; + if ( w2 > w ) + w = w2; + if ( h2 > h ) + h = h2; + editor->DecRef(); + attr->DecRef(); } // preserve (more or less) the previous position @@ -4542,7 +4543,6 @@ void wxGrid::CalcDimensions() CalcWindowSizes(); } - void wxGrid::CalcWindowSizes() { // escape if the window is has not been fully created yet @@ -4556,19 +4556,18 @@ void wxGrid::CalcWindowSizes() if ( m_cornerLabelWin && m_cornerLabelWin->IsShown() ) m_cornerLabelWin->SetSize( 0, 0, m_rowLabelWidth, m_colLabelHeight ); - if ( m_colLabelWin && m_colLabelWin->IsShown() ) - m_colLabelWin->SetSize( m_rowLabelWidth, 0, cw - m_rowLabelWidth, m_colLabelHeight); + if ( m_colLabelWin && m_colLabelWin->IsShown() ) + m_colLabelWin->SetSize( m_rowLabelWidth, 0, cw - m_rowLabelWidth, m_colLabelHeight ); if ( m_rowLabelWin && m_rowLabelWin->IsShown() ) - m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, ch - m_colLabelHeight); + m_rowLabelWin->SetSize( 0, m_colLabelHeight, m_rowLabelWidth, ch - m_colLabelHeight ); if ( m_gridWin && m_gridWin->IsShown() ) - m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, cw - m_rowLabelWidth, ch - m_colLabelHeight); + m_gridWin->SetSize( m_rowLabelWidth, m_colLabelHeight, cw - m_rowLabelWidth, ch - m_colLabelHeight ); } - -// this is called when the grid table sends a message to say that it -// has been redimensioned +// this is called when the grid table sends a message +// to indicate that it has been redimensioned // bool wxGrid::Redimension( wxGridTableMessage& msg ) { @@ -4618,7 +4617,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) if ( pos > 0 ) bottom = m_rowBottoms[pos - 1]; - for ( i = pos; i < m_numRows; i++ ) + for ( i = pos; i < m_numRows; i++ ) { bottom += m_rowHeights[i]; m_rowBottoms[i] = bottom; @@ -4663,7 +4662,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) if ( oldNumRows > 0 ) bottom = m_rowBottoms[oldNumRows - 1]; - for ( i = oldNumRows; i < m_numRows; i++ ) + for ( i = oldNumRows; i < m_numRows; i++ ) { bottom += m_rowHeights[i]; m_rowBottoms[i] = bottom; @@ -4699,12 +4698,13 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) m_rowBottoms.RemoveAt( pos, numRows ); int h = 0; - for ( i = 0; i < m_numRows; i++ ) + for ( i = 0; i < m_numRows; i++ ) { h += m_rowHeights[i]; m_rowBottoms[i] = h; } } + if ( !m_numRows ) { m_currentCellCoords = wxGridNoCellCoords; @@ -4721,6 +4721,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) if (attrProvider) { attrProvider->UpdateAttrRows( pos, -((int)numRows) ); + // ifdef'd out following patch from Paul Gammans #if 0 // No need to touch column attributes, unless we @@ -4757,7 +4758,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) if ( pos > 0 ) right = m_colRights[pos - 1]; - for ( i = pos; i < m_numCols; i++ ) + for ( i = pos; i < m_numCols; i++ ) { right += m_colWidths[i]; m_colRights[i] = right; @@ -4782,7 +4783,6 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) CalcDimensions(); m_colLabelWin->Refresh(); } - } result = true; break; @@ -4801,7 +4801,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) if ( oldNumCols > 0 ) right = m_colRights[oldNumCols - 1]; - for ( i = oldNumCols; i < m_numCols; i++ ) + for ( i = oldNumCols; i < m_numCols; i++ ) { right += m_colWidths[i]; m_colRights[i] = right; @@ -4836,7 +4836,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) m_colRights.RemoveAt( pos, numCols ); int w = 0; - for ( i = 0; i < m_numCols; i++ ) + for ( i = 0; i < m_numCols; i++ ) { w += m_colWidths[i]; m_colRights[i] = w; @@ -4908,7 +4908,8 @@ wxArrayInt wxGrid::CalcRowLabelsExposed( const wxRegion& reg ) #if defined(__WXMOTIF__) int cw, ch; m_gridWin->GetClientSize( &cw, &ch ); - if ( r.GetTop() > ch ) r.SetTop( 0 ); + if ( r.GetTop() > ch ) + r.SetTop( 0 ); r.SetBottom( wxMin( r.GetBottom(), ch ) ); #endif @@ -4921,7 +4922,7 @@ wxArrayInt wxGrid::CalcRowLabelsExposed( const wxRegion& reg ) // find the row labels within these bounds // int row; - for ( row = internalYToRow(top); row < m_numRows; row++ ) + for ( row = internalYToRow(top); row < m_numRows; row++ ) { if ( GetRowBottom(row) < top ) continue; @@ -4958,7 +4959,8 @@ wxArrayInt wxGrid::CalcColLabelsExposed( const wxRegion& reg ) #if defined(__WXMOTIF__) int cw, ch; m_gridWin->GetClientSize( &cw, &ch ); - if ( r.GetLeft() > cw ) r.SetLeft( 0 ); + if ( r.GetLeft() > cw ) + r.SetLeft( 0 ); r.SetRight( wxMin( r.GetRight(), cw ) ); #endif @@ -4971,7 +4973,7 @@ wxArrayInt wxGrid::CalcColLabelsExposed( const wxRegion& reg ) // find the cells within these bounds // int col; - for ( col = internalXToCol(left); col < m_numCols; col++ ) + for ( col = internalXToCol(left); col < m_numCols; col++ ) { if ( GetColRight(col) < left ) continue; @@ -5022,7 +5024,7 @@ wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg ) // find the cells within these bounds // int row, col; - for ( row = internalYToRow(top); row < m_numRows; row++ ) + for ( row = internalYToRow(top); row < m_numRows; row++ ) { if ( GetRowBottom(row) <= top ) continue; @@ -5030,7 +5032,7 @@ wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg ) if ( GetRowTop(row) > bottom ) break; - for ( col = internalXToCol(left); col < m_numCols; col++ ) + for ( col = internalXToCol(left); col < m_numCols; col++ ) { if ( GetColRight(col) <= left ) continue; @@ -6118,7 +6120,7 @@ bool wxGrid::ProcessTableMessage( wxGridTableMessage& msg ) } // The behaviour of this function depends on the grid table class -// Clear() function. For the default wxGridStringTable class the +// Clear() function. For the default wxGridStringTable class the // behavious is to replace all cell contents with wxEmptyString but // not to change the number of rows or cols. // @@ -6130,7 +6132,7 @@ void wxGrid::ClearGrid() DisableCellEditControl(); m_table->Clear(); - if ( !GetBatchCount() + if (!GetBatchCount()) m_gridWin->Refresh(); } } @@ -6381,7 +6383,8 @@ int wxGrid::SendEvent( const wxEventType type, void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) ) { - wxPaintDC dc(this); // needed to prevent zillions of paint events on MSW + // needed to prevent zillions of paint events on MSW + wxPaintDC dc(this); } void wxGrid::Refresh(bool eraseb, const wxRect* rect) @@ -6943,9 +6946,9 @@ bool wxGrid::SetModelValues() if ( m_table ) { - for ( row = 0; row < m_numRows; row++ ) + for ( row = 0; row < m_numRows; row++ ) { - for ( col = 0; col < m_numCols; col++ ) + for ( col = 0; col < m_numCols; col++ ) { m_table->SetValue( row, col, GetCellValue(row, col) ); } @@ -6981,7 +6984,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells ) { wxGridCellCoords cell( row + cell_rows, col + cell_cols ); bool marked = false; - for ( int j = 0; j < numCells; j++ ) + for ( int j = 0; j < numCells; j++ ) { if ( cell == cells[j] ) { @@ -7015,7 +7018,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells ) { for ( int l = 0; l < cell_rows; l++ ) { - // find a cell in this row to left alreay marked for repaint + // find a cell in this row to leave already marked for repaint int left = col; for (int k = 0; k < int(redrawCells.GetCount()); k++) if ((redrawCells[k].GetCol() < left) && @@ -7071,7 +7074,7 @@ void wxGrid::DrawGridCellArea( wxDC& dc, const wxGridCellCoordsArray& cells ) numCells = redrawCells.GetCount(); - for ( i = numCells - 1; i >= 0; i-- ) + for ( i = numCells - 1; i >= 0; i-- ) { DrawCell( dc, redrawCells[i] ); } @@ -7171,10 +7174,10 @@ void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ) if (penWidth > 0) { - // The center of th drawn line is where the position/width/height of - // the rectangle is actually at, (on wxMSW at 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 + // The center of the drawn line is where the position/width/height of + // the rectangle is actually at (on wxMSW at least), so the + // size of the rectangle is reduced 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; @@ -7342,7 +7345,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) } } #else - wxRegion clippedcells( left , top, right - left, bottom - top); + wxRegion clippedcells( left, top, right - left, bottom - top ); int i, j, cell_rows, cell_cols; wxRect rect; @@ -7407,7 +7410,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) dc.DestroyClippingRegion(); } -void wxGrid::DrawRowLabels( wxDC& dc ,const wxArrayInt& rows) +void wxGrid::DrawRowLabels( wxDC& dc, const wxArrayInt& rows) { if ( !m_numRows ) return; @@ -7475,7 +7478,7 @@ void wxGrid::DrawColLabels( wxDC& dc,const wxArrayInt& cols ) size_t i; size_t numLabels = cols.GetCount(); - for ( i = 0; i < numLabels; i++ ) + for ( i = 0; i < numLabels; i++ ) { DrawColLabel( dc, cols[i] ); } @@ -7548,32 +7551,32 @@ void wxGrid::DrawTextRectangle( wxDC& dc, textOrientation ); } -void wxGrid::DrawTextRectangle( wxDC& dc, +// VZ: this should be replaced with wxDC::DrawLabel() to which we just have to +// add textOrientation support +void wxGrid::DrawTextRectangle(wxDC& dc, const wxArrayString& lines, const wxRect& rect, int horizAlign, int vertAlign, - int textOrientation ) + int textOrientation) { - long textWidth = 0, textHeight = 0; - long lineWidth = 0, lineHeight = 0; - int nLines; + if ( lines.empty() ) + return; - dc.SetClippingRegion( rect ); + wxDCClipper clip(dc, rect); - nLines = lines.GetCount(); - if ( nLines > 0 ) - { - int l; - float x = 0.0, y = 0.0; + long textWidth, + textHeight; - if ( textOrientation == wxHORIZONTAL ) - GetTextBoxSize( dc, lines, &textWidth, &textHeight ); - else - GetTextBoxSize( dc, lines, &textHeight, &textWidth ); + if ( textOrientation == wxHORIZONTAL ) + GetTextBoxSize( dc, lines, &textWidth, &textHeight ); + else + GetTextBoxSize( dc, lines, &textHeight, &textWidth ); - switch ( vertAlign ) - { + int x = 0, + y = 0; + switch ( vertAlign ) + { case wxALIGN_BOTTOM: if ( textOrientation == wxHORIZONTAL ) y = rect.y + (rect.height - textHeight - 1); @@ -7595,15 +7598,26 @@ void wxGrid::DrawTextRectangle( wxDC& dc, else x = rect.x + 1; break; - } + } + + // Align each line of a multi-line label + size_t nLines = lines.GetCount(); + for ( size_t l = 0; l < nLines; l++ ) + { + const wxString& line = lines[l]; - // Align each line of a multi-line label - for ( l = 0; l < nLines; l++ ) + if ( line.empty() ) { - dc.GetTextExtent(lines[l], &lineWidth, &lineHeight); + *(textOrientation == wxHORIZONTAL ? &y : &x) += dc.GetCharHeight(); + continue; + } - switch ( horizAlign ) - { + long lineWidth, + lineHeight; + dc.GetTextExtent(line, &lineWidth, &lineHeight); + + switch ( horizAlign ) + { case wxALIGN_RIGHT: if ( textOrientation == wxHORIZONTAL ) x = rect.x + (rect.width - lineWidth - 1); @@ -7625,22 +7639,19 @@ void wxGrid::DrawTextRectangle( wxDC& dc, else y = rect.y + rect.height - 1; break; - } + } - if ( textOrientation == wxHORIZONTAL ) - { - dc.DrawText( lines[l], (int)x, (int)y ); - y += lineHeight; - } - else - { - dc.DrawRotatedText( lines[l], (int)x, (int)y, 90.0 ); - x += lineHeight; - } + if ( textOrientation == wxHORIZONTAL ) + { + dc.DrawText( line, x, y ); + y += lineHeight; + } + else + { + dc.DrawRotatedText( line, x, y, 90.0 ); + x += lineHeight; } } - - dc.DestroyClippingRegion(); } // Split multi-line text up into an array of strings. @@ -7687,7 +7698,7 @@ void wxGrid::GetTextBoxSize( const wxDC& dc, long lineW = 0, lineH = 0; size_t i; - for ( i = 0; i < lines.GetCount(); i++ ) + for ( i = 0; i < lines.GetCount(); i++ ) { dc.GetTextExtent( lines[i], &lineW, &lineH ); w = wxMax( w, lineW ); @@ -8274,7 +8285,7 @@ void wxGrid::MakeCellVisible( int row, int col ) { int h = r.GetHeight(); ypos = r.GetTop(); - for ( i = row - 1; i >= 0; i-- ) + for ( i = row - 1; i >= 0; i-- ) { int rowHeight = GetRowHeight(i); if ( h + rowHeight > ch ) @@ -8285,11 +8296,11 @@ void wxGrid::MakeCellVisible( int row, int col ) } // we divide it later by GRID_SCROLL_LINE, make sure that we don't - // have rounding errors (this is important, because if we do, we - // might not scroll at all and some cells won't be redrawn) + // have rounding errors (this is important, because if we do, + // we might not scroll at all and some cells won't be redrawn) // - // Sometimes GRID_SCROLL_LINE/2 is not enough, so just add a full - // scroll unit... + // Sometimes GRID_SCROLL_LINE / 2 is not enough, + // so just add a full scroll unit... ypos += m_scrollLineY; } @@ -8480,7 +8491,7 @@ bool wxGrid::MovePageUp() if ( newRow == row ) { - //row > 0 , so newrow can never be less than 0 here. + // row > 0, so newRow can never be less than 0 here. newRow = row - 1; } @@ -8508,7 +8519,7 @@ bool wxGrid::MovePageDown() int newRow = internalYToRow( y + ch ); if ( newRow == row ) { - // row < m_numRows , so newrow can't overflow here. + // row < m_numRows, so newRow can't overflow here. newRow = row + 1; } @@ -9399,7 +9410,7 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const { if ( !LookupAttr(row, col, &attr) ) { - attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any) + attr = m_table ? m_table->GetAttr(row, col, wxGridCellAttr::Any) : (wxGridCellAttr *)NULL; CacheAttr(row, col, attr); } @@ -9774,7 +9785,7 @@ void wxGrid::SetRowSize( int row, int height ) m_rowHeights[row] = h; int i; - for ( i = row; i < m_numRows; i++ ) + for ( i = row; i < m_numRows; i++ ) { m_rowBottoms[i] += diff; } @@ -9821,16 +9832,16 @@ void wxGrid::SetColSize( int col, int width ) InitColWidths(); } - // if < 0 calc new width from label + // if < 0 then calculate new width from label if ( width < 0 ) { - long w, h; - wxArrayString lines; - wxClientDC dc(m_colLabelWin); - dc.SetFont(GetLabelFont()); - StringToLines(GetColLabelValue(col), lines); - GetTextBoxSize(dc, lines, &w, &h); - width = w + 6; + long w, h; + wxArrayString lines; + wxClientDC dc(m_colLabelWin); + dc.SetFont(GetLabelFont()); + StringToLines(GetColLabelValue(col), lines); + GetTextBoxSize(dc, lines, &w, &h); + width = w + 6; } int w = wxMax( 0, width ); @@ -9838,7 +9849,7 @@ void wxGrid::SetColSize( int col, int width ) m_colWidths[col] = w; int i; - for ( i = col; i < m_numCols; i++ ) + for ( i = col; i < m_numCols; i++ ) { m_colRights[i] += diff; } @@ -9943,9 +9954,7 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col); extent = column ? size.x : size.y; if ( extent > extentMax ) - { extentMax = extent; - } renderer->DecRef(); } @@ -9968,9 +9977,7 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) extent = column ? w : h; if ( extent > extentMax ) - { extentMax = extent; - } if ( !extentMax ) { @@ -10037,9 +10044,7 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin) for ( int col = 0; col < m_numCols; col++ ) { if ( !calcOnly ) - { AutoSizeColumn(col, setAsMin); - } width += GetColWidth(col); } @@ -10172,7 +10177,7 @@ void wxGrid::AutoSizeColLabelSize( int col ) long w, h; // Hide the edit control, so it - // won't interfer with drag-shrinking. + // won't interfere with drag-shrinking. if ( IsCellEditControlShown() ) { HideCellEditControl(); @@ -10207,7 +10212,7 @@ wxSize wxGrid::DoGetBestSize() const height = 80; // Round up to a multiple the scroll rate - // NOTE: this still doesn't get rid of the scrollbars; + // NOTE: this still doesn't get rid of the scrollbars; // is there any magic incantation for that? int xpu, ypu; GetScrollPixelsPerUnit(&xpu, &ypu);