예제 #1
0
    void RemoveItemByIdx(int iItem)
    {
        int numRemoved = 0;

        if (iItem != -1) {
            // find the first matching item

            while (iItem > 1 && m_vItems[iItem-1] == m_vItems[iItem]) {
                iItem--;
            }

            // now remove all the matching items

            TRef<ListItem> pListItem = m_vItems[iItem];
            while (iItem < m_vItems.GetCount() && m_vItems[iItem] == pListItem) {
                m_vItems.Remove(iItem);
                numRemoved++;
            }
                
            if (iItem <= m_iSelItem) {
                SetSelItemByIdx(m_iSelItem - numRemoved);
            } else {
                SetSelItemByIdx(m_iSelItem);
            }

            if (m_pScrollPane) {
                // save the old top item, because shrinking the scroll pane could change it
                int iOldTopItem = m_iTopItem;

                m_pScrollPane->SetSize(m_vItems.GetCount());
                
                if (iItem < iOldTopItem) {
                    SetScrollPosition(max(iOldTopItem - numRemoved, 0));
                } else {
                    SetScrollPosition(min(iOldTopItem, 
                        max(m_vItems.GetCount() - m_cVisibleItems, 0)));
                }
            }
            NeedPaint();
        }
    }