| 265 | |
| 266 | |
| 267 | void SListView::UpdateVisibleItems() |
| 268 | { |
| 269 | if(!m_adapter) return; |
| 270 | int iOldFirstVisible = m_iFirstVisible; |
| 271 | int iOldLastVisible = m_iFirstVisible + (int)m_lstItems.GetCount(); |
| 272 | int nOldTotalHeight = m_lvItemLocator->GetTotalHeight(); |
| 273 | |
| 274 | int iNewFirstVisible = m_lvItemLocator->Position2Item(m_siVer.nPos); |
| 275 | int iNewLastVisible = iNewFirstVisible; |
| 276 | int pos = m_lvItemLocator->Item2Position(iNewFirstVisible); |
| 277 | int iHoverItem = m_pHoverItem?(int)m_pHoverItem->GetItemIndex():-1; |
| 278 | m_pHoverItem = NULL; |
| 279 | |
| 280 | ItemInfo *pItemInfos = new ItemInfo[m_lstItems.GetCount()]; |
| 281 | SPOSITION spos = m_lstItems.GetHeadPosition(); |
| 282 | int i=0; |
| 283 | while(spos) |
| 284 | { |
| 285 | pItemInfos[i++]=m_lstItems.GetNext(spos); |
| 286 | } |
| 287 | |
| 288 | m_lstItems.RemoveAll(); |
| 289 | |
| 290 | if(iNewFirstVisible!=-1) |
| 291 | { |
| 292 | while(pos < m_siVer.nPos + (int)m_siVer.nPage && iNewLastVisible < m_adapter->getCount()) |
| 293 | { |
| 294 | DWORD dwState = WndState_Normal; |
| 295 | if(iHoverItem == iNewLastVisible) dwState |= WndState_Hover; |
| 296 | if(m_iSelItem == iNewLastVisible) dwState |= WndState_Check; |
| 297 | |
| 298 | ItemInfo ii={NULL,-1}; |
| 299 | ii.nType = m_adapter->getItemViewType(iNewLastVisible,dwState); |
| 300 | if(iNewLastVisible>=iOldFirstVisible && iNewLastVisible < iOldLastVisible) |
| 301 | {//use the old visible item |
| 302 | int iItem = iNewLastVisible-iOldFirstVisible;//(iNewLastVisible-iNewFirstVisible) + (iNewFirstVisible-iOldFirstVisible); |
| 303 | SASSERT(iItem>=0 && iItem <= (iOldLastVisible-iOldFirstVisible)); |
| 304 | if(ii.nType == pItemInfos[iItem].nType) |
| 305 | { |
| 306 | ii = pItemInfos[iItem]; |
| 307 | pItemInfos[iItem].pItem = NULL;//标记该行已经被重用 |
| 308 | } |
| 309 | } |
| 310 | if(!ii.pItem) |
| 311 | {//create new visible item |
| 312 | SList<SItemPanel *> *lstRecycle = m_itemRecycle.GetAt(ii.nType); |
| 313 | if(lstRecycle->IsEmpty()) |
| 314 | {//创建一个新的列表项 |
| 315 | ii.pItem = SItemPanel::Create(this,pugi::xml_node(),this); |
| 316 | ii.pItem->GetEventSet()->subscribeEvent(EventItemPanelClick::EventID,Subscriber(&SListView::OnItemClick,this)); |
| 317 | }else |
| 318 | { |
| 319 | ii.pItem = lstRecycle->RemoveHead(); |
| 320 | } |
| 321 | ii.pItem->SetItemIndex(iNewLastVisible); |
| 322 | } |
| 323 | ii.pItem->SetVisible(TRUE); |
| 324 | CRect rcItem = GetClientRect(); |
nothing calls this directly
no test coverage detected