X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4db6714b166a733177740b06cd21f31f4bb27896..a5bb4f82930fc368188d56a4e11456abc93b272e:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index c52334ed7c..e27d34ae3e 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1488,7 +1488,13 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid) Combo()->SetFocus(); if (evtHandler) + { + // When dropping down the menu, a kill focus event + // happens after this point, so we can't reset the flag yet. +#if !defined(__WXGTK20__) evtHandler->SetInSetFocus(false); +#endif + } } bool wxGridCellChoiceEditor::EndEdit(int row, int col, @@ -2634,16 +2640,16 @@ wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, wxGridCellAttr *attr = (wxGridCellAttr *)NULL; if ( m_data ) { - switch(kind) + switch (kind) { case (wxGridCellAttr::Any): - //Get cached merge attributes. - // Currenlty not used as no cache implemented as not mutiable + // Get cached merge attributes. + // Currently not used as no cache implemented as not mutable // attr = m_data->m_mergeAttr.GetAttr(row, col); if (!attr) { - //Basically implement old version. - //Also check merge cache, so we don't have to re-merge every time.. + // Basically implement old version. + // Also check merge cache, so we don't have to re-merge every time.. wxGridCellAttr *attrcell = m_data->m_cellAttrs.GetAttr(row, col); wxGridCellAttr *attrrow = m_data->m_rowAttrs.GetAttr(row); wxGridCellAttr *attrcol = m_data->m_colAttrs.GetAttr(col); @@ -2654,7 +2660,7 @@ wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, attr = new wxGridCellAttr; attr->SetKind(wxGridCellAttr::Merged); - //Order important.. + // Order is important.. if (attrcell) { attr->MergeWith(attrcell); @@ -2670,7 +2676,8 @@ wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, attr->MergeWith(attrrow); attrrow->DecRef(); } - //store merge attr if cache implemented + + // store merge attr if cache implemented //attr->IncRef(); //m_data->m_mergeAttr.SetAttr(attr, row, col); } @@ -2681,7 +2688,7 @@ wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, attr = attrrow; if (attrcol) { - if(attr) + if (attr) attr->DecRef(); attr = attrcol; } @@ -4176,8 +4183,7 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, m_table = table; m_table->SetView( this ); - if (takeOwnership) - m_ownTable = true; + m_ownTable = takeOwnership; m_selection = new wxGridSelection( this, selmode ); CalcDimensions(); @@ -4922,7 +4928,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event ) if ( event.LeftIsDown() ) { - switch( m_cursorMode ) + switch ( m_cursorMode ) { case WXGRID_CURSOR_RESIZE_ROW: { @@ -5147,7 +5153,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event ) if ( event.LeftIsDown() ) { - switch( m_cursorMode ) + switch ( m_cursorMode ) { case WXGRID_CURSOR_RESIZE_COL: { @@ -5478,7 +5484,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) { //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol()); - // Don't start doing anything until the mouse has been drug at + // Don't start doing anything until the mouse has been dragged at // least 3 pixels in any direction... if (! m_isDragging) { @@ -7047,9 +7053,15 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords ) // Note: However, only if it is really _shown_, i.e. not hidden! if ( isCurrent && IsCellEditControlShown() ) { + // OSAF NB: this "#if..." is temporary and fixes a problem where the + // edit control is erased by this code after being rendered. + // On wxMac (QD build only), the cell editor is a wxTextCntl and is rendered + // implicitly, causing this out-of order render. +#if !defined(__WXMAC__) || wxMAC_USE_CORE_GRAPHICS wxGridCellEditor *editor = attr->GetEditor(this, row, col); editor->PaintBackground(rect, attr); editor->DecRef(); +#endif } else { @@ -7472,8 +7484,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 ); @@ -7489,7 +7501,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc, else GetTextBoxSize( dc, lines, &textHeight, &textWidth ); - switch( vertAlign ) + switch ( vertAlign ) { case wxALIGN_BOTTOM: if ( textOrientation == wxHORIZONTAL ) @@ -7519,7 +7531,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc, { dc.GetTextExtent(lines[l], &lineWidth, &lineHeight); - switch( horizAlign ) + switch ( horizAlign ) { case wxALIGN_RIGHT: if ( textOrientation == wxHORIZONTAL ) @@ -7602,7 +7614,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++ ) @@ -8247,11 +8259,11 @@ bool wxGrid::MoveCursorUp( bool expandSelection ) } else if ( m_currentCellCoords.GetRow() > 0 ) { + int row = m_currentCellCoords.GetRow() - 1; + int col = m_currentCellCoords.GetCol(); ClearSelection(); - MakeCellVisible( m_currentCellCoords.GetRow() - 1, - m_currentCellCoords.GetCol() ); - SetCurrentCell( m_currentCellCoords.GetRow() - 1, - m_currentCellCoords.GetCol() ); + MakeCellVisible( row, col ); + SetCurrentCell( row, col ); } else return false; @@ -8282,11 +8294,11 @@ bool wxGrid::MoveCursorDown( bool expandSelection ) } else if ( m_currentCellCoords.GetRow() < m_numRows - 1 ) { + int row = m_currentCellCoords.GetRow() + 1; + int col = m_currentCellCoords.GetCol(); ClearSelection(); - MakeCellVisible( m_currentCellCoords.GetRow() + 1, - m_currentCellCoords.GetCol() ); - SetCurrentCell( m_currentCellCoords.GetRow() + 1, - m_currentCellCoords.GetCol() ); + MakeCellVisible( row, col ); + SetCurrentCell( row, col ); } else return false; @@ -8316,11 +8328,11 @@ bool wxGrid::MoveCursorLeft( bool expandSelection ) } else if ( m_currentCellCoords.GetCol() > 0 ) { + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol() - 1; ClearSelection(); - MakeCellVisible( m_currentCellCoords.GetRow(), - m_currentCellCoords.GetCol() - 1 ); - SetCurrentCell( m_currentCellCoords.GetRow(), - m_currentCellCoords.GetCol() - 1 ); + MakeCellVisible( row, col ); + SetCurrentCell( row, col ); } else return false; @@ -8350,11 +8362,11 @@ bool wxGrid::MoveCursorRight( bool expandSelection ) } else if ( m_currentCellCoords.GetCol() < m_numCols - 1 ) { + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol() + 1; ClearSelection(); - MakeCellVisible( m_currentCellCoords.GetRow(), - m_currentCellCoords.GetCol() + 1 ); - SetCurrentCell( m_currentCellCoords.GetRow(), - m_currentCellCoords.GetCol() + 1 ); + MakeCellVisible( row, col ); + SetCurrentCell( row, col ); } else return false; @@ -9590,7 +9602,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()); @@ -9607,7 +9619,7 @@ wxGrid::GetDefaultRendererForType(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()); @@ -9618,7 +9630,6 @@ wxGrid::GetDefaultRendererForType(const wxString& typeName) const return m_typeRegistry->GetRenderer(index); } - // ---------------------------------------------------------------------------- // row/col size // ---------------------------------------------------------------------------- @@ -9716,7 +9727,7 @@ void wxGrid::SetColSize( int col, int width ) // // This test then fixes sf.net bug #645734 - if ( width < GetColMinimalAcceptableWidth()) + if ( width < GetColMinimalAcceptableWidth() ) return; if ( m_colWidths.IsEmpty() ) @@ -9736,6 +9747,7 @@ void wxGrid::SetColSize( int col, int width ) GetTextBoxSize(dc, lines, &w, &h); width = w + 6; } + int w = wxMax( 0, width ); int diff = w - m_colWidths[col]; m_colWidths[col] = w; @@ -9745,6 +9757,7 @@ void wxGrid::SetColSize( int col, int width ) { m_colRights[i] += diff; } + if ( !GetBatchCount() ) CalcDimensions(); } @@ -9771,6 +9784,7 @@ int wxGrid::GetColMinimalWidth(int col) const { wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)col; wxLongToLongHashMap::const_iterator it = m_colMinWidths.find(key); + return it != m_colMinWidths.end() ? (int)it->second : m_minAcceptableColWidth; } @@ -9778,25 +9792,24 @@ int wxGrid::GetRowMinimalHeight(int row) const { wxLongToLongHashMap::key_type key = (wxLongToLongHashMap::key_type)row; wxLongToLongHashMap::const_iterator it = m_rowMinHeights.find(key); + return it != m_rowMinHeights.end() ? (int)it->second : m_minAcceptableRowHeight; } void wxGrid::SetColMinimalAcceptableWidth( int width ) { // We do allow a width of 0 since this gives us - // an easy way to temporarily hidding columns. - if ( width < 0 ) - return; - m_minAcceptableColWidth = width; + // an easy way to temporarily hiding columns. + if ( width >= 0 ) + m_minAcceptableColWidth = width; } void wxGrid::SetRowMinimalAcceptableHeight( int height ) { // We do allow a height of 0 since this gives us - // an easy way to temporarily hidding rows. - if ( height < 0 ) - return; - m_minAcceptableRowHeight = height; + // an easy way to temporarily hiding rows. + if ( height >= 0 ) + m_minAcceptableRowHeight = height; } int wxGrid::GetColMinimalAcceptableWidth() const @@ -9817,11 +9830,11 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) { wxClientDC dc(m_gridWin); - //Cancel editting of cell + // cancel editing of cell HideCellEditControl(); SaveEditControlValue(); - // init both of them to avoid compiler warnings, even if weo nly need one + // init both of them to avoid compiler warnings, even if we only need one int row = -1, col = -1; if ( column ) @@ -9883,19 +9896,15 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) else { if ( column ) - { // leave some space around text extentMax += 10; - } else - { extentMax += 6; - } } if ( column ) { - SetColSize(col, extentMax); + SetColSize( col, extentMax ); if ( !GetBatchCount() ) { int cw, ch, dummy; @@ -9965,9 +9974,7 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin) for ( int row = 0; row < m_numRows; row++ ) { if ( !calcOnly ) - { AutoSizeRow(row, setAsMin); - } height += GetRowHeight(row); } @@ -10133,10 +10140,12 @@ wxSize wxGrid::DoGetBestSize() const height = maxheight; wxSize best(width, height); + // NOTE: This size should be cached, but first we need to add calls to // InvalidateBestSize everywhere that could change the results of this // calculation. // CacheBestSize(size); + return best; } @@ -10183,9 +10192,9 @@ void wxGrid::SetCellValue( int row, int col, const wxString& s ) } -// -// ------ Block, row and col selection -// +// ---------------------------------------------------------------------------- +// block, row and col selection +// ---------------------------------------------------------------------------- void wxGrid::SelectRow( int row, bool addToSelected ) { @@ -10225,9 +10234,9 @@ void wxGrid::SelectAll() } } -// -// ------ Cell, row and col deselection -// +// ---------------------------------------------------------------------------- +// cell, row and col deselection +// ---------------------------------------------------------------------------- void wxGrid::DeselectRow( int row ) { @@ -10373,7 +10382,7 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft, } else { - rect = wxRect(0,0,0,0); + rect = wxRect(0, 0, 0, 0); } cellRect = CellToRect( bottomRight ); @@ -10417,7 +10426,6 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft, bottomRow = i; } - for ( j = topRow; j <= bottomRow; j++ ) { for ( i = leftCol; i <= rightCol; i++ ) @@ -10461,9 +10469,9 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft, return rect; } -// -// ------ Grid event classes -// +// ---------------------------------------------------------------------------- +// grid event classes +// ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS( wxGridEvent, wxNotifyEvent )