X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ff3d11a0ab976879ff87c826f660786fee172ed9..3c85ada9dbd66f72f174c049744e8cdaa444d99f:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8ea0eada4e..23f67b2520 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -616,12 +616,17 @@ public: // return the hit code for the corresponding position (in this line) long HitTestLine(size_t line, int x, int y) const; + // bring the selected item into view, scrolling to it if necessary + void MoveToItem(size_t item); + + // bring the current item into view + void MoveToFocus() { MoveToItem(m_current); } + void EditLabel( long item ); void OnRenameTimer(); void OnRenameAccept(); void OnMouse( wxMouseEvent &event ); - void MoveToFocus(); // called to switch the selection from the current item to newCurrent, void OnArrowChar( size_t newCurrent, const wxKeyEvent& event ); @@ -662,7 +667,7 @@ public: int GetSelectedItemCount(); // set the scrollbars and update the positions of the items - void RecalculatePositions(); + void RecalculatePositions(bool noRefresh = FALSE); // refresh the window and the header void RefreshAll(); @@ -819,6 +824,9 @@ private: // initialize the current item if needed void UpdateCurrent(); + // delete all items but don't refresh: called from dtor + void DoDeleteAllItems(); + // called when an item is [un]focuded, i.e. becomes [not] current // // currently unused @@ -2159,7 +2167,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxListMainWindow::~wxListMainWindow() { - DeleteEverything(); + DoDeleteAllItems(); delete m_highlightBrush; @@ -2400,7 +2408,7 @@ void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo ) rect.x = 0; rect.y = GetLineY(lineFrom); rect.width = GetClientSize().x; - rect.height = GetLineY(lineTo) - rect.y; + rect.height = GetLineY(lineTo) - rect.y + GetLineHeight(); CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); RefreshRect( rect ); @@ -2483,11 +2491,15 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) CalcUnscrolledPosition(0, 0, &xOrig, &yOrig); // tell the caller cache to cache the data - wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, GetParent()->GetId()); - evCache.SetEventObject( GetParent() ); - evCache.m_oldItemIndex = visibleFrom; - evCache.m_itemIndex = visibleTo; - GetParent()->GetEventHandler()->ProcessEvent( evCache ); + if ( IsVirtual() ) + { + wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, + GetParent()->GetId()); + evCache.SetEventObject( GetParent() ); + evCache.m_oldItemIndex = visibleFrom; + evCache.m_itemIndex = visibleTo; + GetParent()->GetEventHandler()->ProcessEvent( evCache ); + } for ( size_t line = visibleFrom; line <= visibleTo; line++ ) { @@ -2605,7 +2617,12 @@ void wxListMainWindow::SendNotify( size_t line, if ( point != wxDefaultPosition ) le.m_pointDrag = point; - GetLine(line)->GetItem( 0, le.m_item ); + if ( command != wxEVT_COMMAND_LIST_DELETE_ITEM ) + { + GetLine(line)->GetItem( 0, le.m_item ); + } + //else: there may be no more such item + GetParent()->GetEventHandler()->ProcessEvent( le ); } @@ -2864,12 +2881,12 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) } } -void wxListMainWindow::MoveToFocus() +void wxListMainWindow::MoveToItem(size_t item) { - if ( !HasCurrent() ) + if ( item == (size_t)-1 ) return; - wxRect rect = GetLineRect(m_current); + wxRect rect = GetLineRect(item); int client_w, client_h; GetClientSize( &client_w, &client_h ); @@ -3549,7 +3566,8 @@ void wxListMainWindow::SetItemCount(long count) ResetVisibleLinesRange(); - Refresh(); + // scrollbars must be reset + m_dirty = TRUE; } int wxListMainWindow::GetSelectedItemCount() @@ -3606,11 +3624,8 @@ bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) // geometry calculation // ---------------------------------------------------------------------------- -void wxListMainWindow::RecalculatePositions() +void wxListMainWindow::RecalculatePositions(bool noRefresh) { - if ( IsEmpty() ) - return; - wxClientDC dc( this ); dc.SetFont( GetFont() ); @@ -3711,10 +3726,13 @@ void wxListMainWindow::RecalculatePositions() SetScrollbars( m_xScroll, m_yScroll, (entireWidth+SCROLL_UNIT_X) / m_xScroll, 0, scroll_pos, 0, TRUE ); } - // FIXME: why should we call it from here? - UpdateCurrent(); + if ( !noRefresh ) + { + // FIXME: why should we call it from here? + UpdateCurrent(); - RefreshAll(); + RefreshAll(); + } } void wxListMainWindow::RefreshAll() @@ -3795,20 +3813,12 @@ void wxListMainWindow::DeleteItem( long lindex ) size_t index = (size_t)lindex; - m_dirty = TRUE; - // select the next item when the selected one is deleted - if ( m_current == index ) + if ( m_current >= index ) { - // the last valid index after deleting the item will be count-2 - if ( m_current == count - 1 ) - { - m_current--; - } + m_current--; } - SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); - if ( InReportView() ) { ResetVisibleLinesRange(); @@ -3826,6 +3836,9 @@ void wxListMainWindow::DeleteItem( long lindex ) } m_dirty = TRUE; + + SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); + RefreshAfter(index); } @@ -3839,7 +3852,7 @@ void wxListMainWindow::DeleteColumn( int col ) m_columns.DeleteNode( node ); } -void wxListMainWindow::DeleteAllItems() +void wxListMainWindow::DoDeleteAllItems() { if ( IsEmpty() ) { @@ -3871,11 +3884,13 @@ void wxListMainWindow::DeleteAllItems() } m_lines.Clear(); +} - // NB: don't just set m_dirty to TRUE here as RecalculatePositions() - // doesn't do anything if the control is empty and so we won't be - // refreshed - Refresh(); +void wxListMainWindow::DeleteAllItems() +{ + DoDeleteAllItems(); + + RecalculatePositions(); } void wxListMainWindow::DeleteEverything() @@ -3895,14 +3910,15 @@ void wxListMainWindow::EnsureVisible( long index ) _T("invalid index in EnsureVisible") ); // We have to call this here because the label in question might just have - // been added and no screen update taken place. - if (m_dirty) - wxSafeYield(); + // been added and its position is not known yet + if ( m_dirty ) + { + m_dirty = FALSE; - size_t oldCurrent = m_current; - m_current = (size_t)index; - MoveToFocus(); - m_current = oldCurrent; + RecalculatePositions(TRUE /* no refresh */); + } + + MoveToItem((size_t)index); } long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(partial) )