X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d82323930c8ce1b800f2213a598fbda79f868d1d..6ba636000f13b4bf7d3e7dcfad429713085f6700:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index e5ab724cad..5e8559b6c4 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -538,7 +538,15 @@ void wxGridCellTextEditor::SetSize(const wxRect& rectOrig) } #else // !GTK int extra_x = ( rect.x > 2 )? 2 : 1; + +// MB: treat MSW separately here otherwise the caret doesn't show +// when the editor is in the first row. +#if defined(__WXMSW__) + int extra_y = 2; +#else int extra_y = ( rect.y > 2 )? 2 : 1; +#endif // MSW + #if defined(__WXMOTIF__) extra_x *= 2; extra_y *= 2; @@ -1181,7 +1189,10 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) m_startValue = grid->GetTable()->GetValueAsBool(row, col); else - m_startValue = !!grid->GetTable()->GetValue(row, col); + { + wxString cellval( grid->GetTable()->GetValue(row, col) ); + m_startValue = !( !cellval || (cellval == "0") ); + } CBox()->SetValue(m_startValue); CBox()->SetFocus(); } @@ -1559,7 +1570,7 @@ void wxGridCellNumberRenderer::Draw(wxGrid& grid, // draw the text right aligned by default int hAlign, vAlign; attr.GetAlignment(&hAlign, &vAlign); - hAlign = wxRIGHT; + hAlign = wxALIGN_RIGHT; wxRect rect = rectCell; rect.Inflate(-1); @@ -1654,7 +1665,7 @@ void wxGridCellFloatRenderer::Draw(wxGrid& grid, // draw the text right aligned by default int hAlign, vAlign; attr.GetAlignment(&hAlign, &vAlign); - hAlign = wxRIGHT; + hAlign = wxALIGN_RIGHT; wxRect rect = rectCell; rect.Inflate(-1); @@ -1787,7 +1798,10 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) value = grid.GetTable()->GetValueAsBool(row, col); else - value = !!grid.GetTable()->GetValue(row, col); + { + wxString cellval( grid.GetTable()->GetValue(row, col) ); + value = !( !cellval || (cellval == "0") ); + } if ( value ) { @@ -3374,7 +3388,7 @@ void wxGrid::Create() // Set default cell attributes m_defaultCellAttr->SetFont(GetFont()); - m_defaultCellAttr->SetAlignment(wxLEFT, wxTOP); + m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP); m_defaultCellAttr->SetTextColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT)); m_defaultCellAttr->SetBackgroundColour( @@ -3506,11 +3520,11 @@ void wxGrid::Init() m_labelFont = this->GetFont(); m_labelFont.SetWeight( m_labelFont.GetWeight() + 2 ); - m_rowLabelHorizAlign = wxLEFT; - m_rowLabelVertAlign = wxCENTRE; + m_rowLabelHorizAlign = wxALIGN_LEFT; + m_rowLabelVertAlign = wxALIGN_CENTRE; - m_colLabelHorizAlign = wxCENTRE; - m_colLabelVertAlign = wxTOP; + m_colLabelHorizAlign = wxALIGN_CENTRE; + m_colLabelVertAlign = wxALIGN_TOP; m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH; m_defaultRowHeight = m_gridWin->GetCharHeight(); @@ -3817,6 +3831,8 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); 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 // removed _all_ rows, in this case, we remove // all column attributes. @@ -3824,6 +3840,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) // needed data is not available inside UpdateAttrRows. if ( !GetNumberRows() ) attrProvider->UpdateAttrCols( 0, -GetNumberCols() ); +#endif } if ( !GetBatchCount() ) { @@ -3950,6 +3967,8 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); if (attrProvider) { attrProvider->UpdateAttrCols( pos, -((int)numCols) ); +// ifdef'd out following patch from Paul Gammans +#if 0 // No need to touch row attributes, unless we // removed _all_ columns, in this case, we remove // all row attributes. @@ -3957,6 +3976,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) // needed data is not available inside UpdateAttrCols. if ( !GetNumberCols() ) attrProvider->UpdateAttrRows( 0, -GetNumberRows() ); +#endif } if ( !GetBatchCount() ) { @@ -4661,17 +4681,17 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) { if ( m_selectingKeyboard == wxGridNoCellCoords) m_selectingKeyboard = coords; - SelectBlock ( m_selectingKeyboard, coords ); + HighlightBlock ( m_selectingKeyboard, coords ); } else { if ( !IsSelection() ) { - SelectBlock( coords, coords ); + HighlightBlock( coords, coords ); } else { - SelectBlock( m_currentCellCoords, coords ); + HighlightBlock( m_currentCellCoords, coords ); } } @@ -4803,7 +4823,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event ) SetCurrentCell( coords ); if ( m_selection->GetSelectionMode() != wxGrid::wxGridSelectCells) - SelectBlock( coords, coords ); + HighlightBlock( coords, coords ); } m_waitForSlowClick = TRUE; } @@ -5582,7 +5602,7 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) HideCellEditControl(); DisableCellEditControl(); - if ( IsVisible( m_currentCellCoords ) ) + if ( IsVisible( m_currentCellCoords, FALSE ) ) { wxRect r; r = BlockToDeviceRect(m_currentCellCoords, m_currentCellCoords); @@ -5612,6 +5632,141 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) } +void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol ) +{ + int temp; + wxGridCellCoords updateTopLeft, updateBottomRight; + + if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows ) + { + leftCol = 0; + rightCol = GetNumberCols() - 1; + } + else if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns ) + { + topRow = 0; + bottomRow = GetNumberRows() - 1; + } + if ( topRow > bottomRow ) + { + temp = topRow; + topRow = bottomRow; + bottomRow = temp; + } + + if ( leftCol > rightCol ) + { + temp = leftCol; + leftCol = rightCol; + rightCol = temp; + } + + updateTopLeft = wxGridCellCoords( topRow, leftCol ); + updateBottomRight = wxGridCellCoords( bottomRow, rightCol ); + + if ( m_selectingTopLeft != updateTopLeft || + m_selectingBottomRight != updateBottomRight ) + { + // Compute two optimal update rectangles: + // Either one rectangle is a real subset of the + // other, or they are (almost) disjoint! + wxRect rect[4]; + bool need_refresh[4]; + need_refresh[0] = + need_refresh[1] = + need_refresh[2] = + need_refresh[3] = FALSE; + int i; + + // Store intermediate values + wxCoord oldLeft = m_selectingTopLeft.GetCol(); + wxCoord oldTop = m_selectingTopLeft.GetRow(); + wxCoord oldRight = m_selectingBottomRight.GetCol(); + wxCoord oldBottom = m_selectingBottomRight.GetRow(); + + // Determine the outer/inner coordinates. + if (oldLeft > leftCol) + { + temp = oldLeft; + oldLeft = leftCol; + leftCol = temp; + } + if (oldTop > topRow ) + { + temp = oldTop; + oldTop = topRow; + topRow = temp; + } + if (oldRight < rightCol ) + { + temp = oldRight; + oldRight = rightCol; + rightCol = temp; + } + if (oldBottom < bottomRow) + { + temp = oldBottom; + oldBottom = bottomRow; + bottomRow = temp; + } + + // Now, either the stuff marked old is the outer + // rectangle or we don't have a situation where one + // is contained in the other. + + if ( oldLeft < leftCol ) + { + need_refresh[0] = TRUE; + rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop, + oldLeft ), + wxGridCellCoords ( oldBottom, + leftCol - 1 ) ); + } + + if ( oldTop < topRow ) + { + need_refresh[1] = TRUE; + rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop, + leftCol ), + wxGridCellCoords ( topRow - 1, + rightCol ) ); + } + + if ( oldRight > rightCol ) + { + need_refresh[2] = TRUE; + rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop, + rightCol + 1 ), + wxGridCellCoords ( oldBottom, + oldRight ) ); + } + + if ( oldBottom > bottomRow ) + { + need_refresh[3] = TRUE; + rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1, + leftCol ), + wxGridCellCoords ( oldBottom, + rightCol ) ); + } + + + // Change Selection + m_selectingTopLeft = updateTopLeft; + m_selectingBottomRight = updateBottomRight; + + // various Refresh() calls + for (i = 0; i < 4; i++ ) + if ( need_refresh[i] && rect[i] != wxGridNoCellRect ) + m_gridWin->Refresh( FALSE, &(rect[i]) ); + } + + // never generate an event as it will be generated from + // wxGridSelection::SelectBlock! + // (old comment from when this was the body of SelectBlock) +} + + // // ------ functions to get/send data (see also public functions) // @@ -6038,15 +6193,15 @@ void wxGrid::DrawTextRectangle( wxDC& dc, float x, y; switch ( horizAlign ) { - case wxRIGHT: + case wxALIGN_RIGHT: x = rect.x + (rect.width - textWidth - 1); break; - case wxCENTRE: + case wxALIGN_CENTRE: x = rect.x + ((rect.width - textWidth)/2); break; - case wxLEFT: + case wxALIGN_LEFT: default: x = rect.x + 1; break; @@ -6054,15 +6209,15 @@ void wxGrid::DrawTextRectangle( wxDC& dc, switch ( vertAlign ) { - case wxBOTTOM: + case wxALIGN_BOTTOM: y = rect.y + (rect.height - textHeight - 1); break; - case wxCENTRE: + case wxALIGN_CENTRE: y = rect.y + ((rect.height - textHeight)/2); break; - case wxTOP: + case wxALIGN_TOP: default: y = rect.y + 1; break; @@ -6174,12 +6329,8 @@ void wxGrid::EnableEditing( bool edit ) // if ( edit != m_editable ) { + if(!edit) EnableCellEditControl(edit); m_editable = edit; - - // FIXME IMHO this won't disable the edit control if edit == FALSE - // because of the check in the beginning of - // EnableCellEditControl() just below (VZ) - EnableCellEditControl(m_editable); } } @@ -6273,6 +6424,7 @@ void wxGrid::ShowCellEditControl() { if ( !IsVisible( m_currentCellCoords ) ) { + m_cellEditCtrlEnabled = FALSE; return; } else @@ -6612,7 +6764,7 @@ bool wxGrid::MoveCursorUp( bool expandSelection ) m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() - 1 ); MakeCellVisible( m_selectingKeyboard.GetRow(), m_selectingKeyboard.GetCol() ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } } else if ( m_currentCellCoords.GetRow() > 0 ) @@ -6646,7 +6798,7 @@ bool wxGrid::MoveCursorDown( bool expandSelection ) m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() + 1 ); MakeCellVisible( m_selectingKeyboard.GetRow(), m_selectingKeyboard.GetCol() ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } } else if ( m_currentCellCoords.GetRow() < m_numRows - 1 ) @@ -6680,7 +6832,7 @@ bool wxGrid::MoveCursorLeft( bool expandSelection ) m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() - 1 ); MakeCellVisible( m_selectingKeyboard.GetRow(), m_selectingKeyboard.GetCol() ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } } else if ( m_currentCellCoords.GetCol() > 0 ) @@ -6714,7 +6866,7 @@ bool wxGrid::MoveCursorRight( bool expandSelection ) m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() + 1 ); MakeCellVisible( m_selectingKeyboard.GetRow(), m_selectingKeyboard.GetCol() ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } } else if ( m_currentCellCoords.GetCol() < m_numCols - 1 ) @@ -6844,7 +6996,7 @@ bool wxGrid::MoveCursorUpBlock( bool expandSelection ) if ( expandSelection ) { m_selectingKeyboard = wxGridCellCoords( row, col ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } else { @@ -6907,7 +7059,7 @@ bool wxGrid::MoveCursorDownBlock( bool expandSelection ) if ( expandSelection ) { m_selectingKeyboard = wxGridCellCoords( row, col ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } else { @@ -6971,7 +7123,7 @@ bool wxGrid::MoveCursorLeftBlock( bool expandSelection ) if ( expandSelection ) { m_selectingKeyboard = wxGridCellCoords( row, col ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } else { @@ -7035,7 +7187,7 @@ bool wxGrid::MoveCursorRightBlock( bool expandSelection ) if ( expandSelection ) { m_selectingKeyboard = wxGridCellCoords( row, col ); - SelectBlock( m_currentCellCoords, m_selectingKeyboard ); + HighlightBlock( m_currentCellCoords, m_selectingKeyboard ); } else { @@ -7185,12 +7337,27 @@ void wxGrid::SetLabelFont( const wxFont& font ) void wxGrid::SetRowLabelAlignment( int horiz, int vert ) { - if ( horiz == wxLEFT || horiz == wxCENTRE || horiz == wxRIGHT ) + // allow old (incorrect) defs to be used + switch ( horiz ) + { + case wxLEFT: horiz = wxALIGN_LEFT; break; + case wxRIGHT: horiz = wxALIGN_RIGHT; break; + case wxCENTRE: horiz = wxALIGN_CENTRE; break; + } + + switch ( vert ) + { + case wxTOP: vert = wxALIGN_TOP; break; + case wxBOTTOM: vert = wxALIGN_BOTTOM; break; + case wxCENTRE: vert = wxALIGN_CENTRE; break; + } + + if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) { m_rowLabelHorizAlign = horiz; } - if ( vert == wxTOP || vert == wxCENTRE || vert == wxBOTTOM ) + if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM ) { m_rowLabelVertAlign = vert; } @@ -7203,12 +7370,27 @@ void wxGrid::SetRowLabelAlignment( int horiz, int vert ) void wxGrid::SetColLabelAlignment( int horiz, int vert ) { - if ( horiz == wxLEFT || horiz == wxCENTRE || horiz == wxRIGHT ) + // allow old (incorrect) defs to be used + switch ( horiz ) + { + case wxLEFT: horiz = wxALIGN_LEFT; break; + case wxRIGHT: horiz = wxALIGN_RIGHT; break; + case wxCENTRE: horiz = wxALIGN_CENTRE; break; + } + + switch ( vert ) + { + case wxTOP: vert = wxALIGN_TOP; break; + case wxBOTTOM: vert = wxALIGN_BOTTOM; break; + case wxCENTRE: vert = wxALIGN_CENTRE; break; + } + + if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) { m_colLabelHorizAlign = horiz; } - if ( vert == wxTOP || vert == wxCENTRE || vert == wxBOTTOM ) + if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM ) { m_colLabelVertAlign = vert; } @@ -7230,7 +7412,7 @@ void wxGrid::SetRowLabelValue( int row, const wxString& s ) if ( rect.height > 0 ) { CalcScrolledPosition(0, rect.y, &rect.x, &rect.y); - rect.x = m_left; + rect.x = 0; rect.width = m_rowLabelWidth; m_rowLabelWin->Refresh( TRUE, &rect ); } @@ -7249,7 +7431,7 @@ void wxGrid::SetColLabelValue( int col, const wxString& s ) if ( rect.width > 0 ) { CalcScrolledPosition(rect.x, 0, &rect.x, &rect.y); - rect.y = m_top; + rect.y = 0; rect.height = m_colLabelHeight; m_colLabelWin->Refresh( TRUE, &rect ); } @@ -8071,139 +8253,17 @@ void wxGrid::SelectCol( int col, bool addToSelected ) } -void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ) +void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, + bool addToSelected ) { - int temp; - wxGridCellCoords updateTopLeft, updateBottomRight; - - if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows ) - { - leftCol = 0; - rightCol = GetNumberCols() - 1; - } - else if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns ) - { - topRow = 0; - bottomRow = GetNumberRows() - 1; - } - if ( topRow > bottomRow ) - { - temp = topRow; - topRow = bottomRow; - bottomRow = temp; - } - - if ( leftCol > rightCol ) - { - temp = leftCol; - leftCol = rightCol; - rightCol = temp; - } - - updateTopLeft = wxGridCellCoords( topRow, leftCol ); - updateBottomRight = wxGridCellCoords( bottomRow, rightCol ); - - if ( m_selectingTopLeft != updateTopLeft || - m_selectingBottomRight != updateBottomRight ) - { - // Compute two optimal update rectangles: - // Either one rectangle is a real subset of the - // other, or they are (almost) disjoint! - wxRect rect[4]; - bool need_refresh[4]; - need_refresh[0] = - need_refresh[1] = - need_refresh[2] = - need_refresh[3] = FALSE; - int i; - - // Store intermediate values - wxCoord oldLeft = m_selectingTopLeft.GetCol(); - wxCoord oldTop = m_selectingTopLeft.GetRow(); - wxCoord oldRight = m_selectingBottomRight.GetCol(); - wxCoord oldBottom = m_selectingBottomRight.GetRow(); - - // Determine the outer/inner coordinates. - if (oldLeft > leftCol) - { - temp = oldLeft; - oldLeft = leftCol; - leftCol = temp; - } - if (oldTop > topRow ) - { - temp = oldTop; - oldTop = topRow; - topRow = temp; - } - if (oldRight < rightCol ) - { - temp = oldRight; - oldRight = rightCol; - rightCol = temp; - } - if (oldBottom < bottomRow) - { - temp = oldBottom; - oldBottom = bottomRow; - bottomRow = temp; - } - - // Now, either the stuff marked old is the outer - // rectangle or we don't have a situation where one - // is contained in the other. - - if ( oldLeft < leftCol ) - { - need_refresh[0] = TRUE; - rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop, - oldLeft ), - wxGridCellCoords ( oldBottom, - leftCol - 1 ) ); - } - - if ( oldTop < topRow ) - { - need_refresh[1] = TRUE; - rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop, - leftCol ), - wxGridCellCoords ( topRow - 1, - rightCol ) ); - } - - if ( oldRight > rightCol ) - { - need_refresh[2] = TRUE; - rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop, - rightCol + 1 ), - wxGridCellCoords ( oldBottom, - oldRight ) ); - } - - if ( oldBottom > bottomRow ) - { - need_refresh[3] = TRUE; - rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1, - leftCol ), - wxGridCellCoords ( oldBottom, - rightCol ) ); - } - - - // Change Selection - m_selectingTopLeft = updateTopLeft; - m_selectingBottomRight = updateBottomRight; - - // various Refresh() calls - for (i = 0; i < 4; i++ ) - if ( need_refresh[i] && rect[i] != wxGridNoCellRect ) - m_gridWin->Refresh( FALSE, &(rect[i]) ); - } + if ( IsSelection() && !addToSelected ) + ClearSelection(); - // never generate an event as it will be generated from - // wxGridSelection::SelectBlock! + m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol, + FALSE, addToSelected ); } + void wxGrid::SelectAll() { m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 );