BOOL CReportCtrl::ExamItemStates(int nItem, DWORD dwStates) const { if (dwStates == RC_ITEM_NONE) return FALSE; if (dwStates & RC_ITEM_ALL) return TRUE; return (GetItemStates(nItem) & dwStates) == dwStates; }
BOOL CReportCtrl::SwapItems(int nItem1, int nItem2) { EndEdit(TRUE); if(!_IsValidIndex(nItem1) || !_IsValidIndex(nItem2)) { return(FALSE); } if(nItem1 == nItem2) { return(TRUE); } _UnsetSortedColumn(); // record previous states first const DWORD STATES1 = GetItemStates(nItem1); const DWORD STATES2 = GetItemStates(nItem2); const DWORD DATA1 = CListCtrl :: GetItemData(nItem1); const DWORD DATA2 = CListCtrl :: GetItemData(nItem2); // swap item texts and images for(int i = 0; i < GetColumnCount(); i++) { CString str = GetItemText(nItem1, i); CListCtrl :: SetItemText(nItem1, i, GetItemText(nItem2, i)); CListCtrl :: SetItemText(nItem2, i, str); UINT nImg = GetItemImage(nItem1, i); SetItemImage(nItem1, i, GetItemImage(nItem2, i)); SetItemImage(nItem2, i, nImg); } // swap item data CListCtrl :: SetItemData(nItem1, DATA2); CListCtrl :: SetItemData(nItem2, DATA1); // restore states SetItemStates(nItem1, STATES2); SetItemStates(nItem2, STATES1); return(TRUE); }
int CReportCtrl::MoveTo(int nItem, int nNewPosition) { if(!_IsValidIndex(nItem)) { return(-1); } EndEdit(TRUE); const int ITEMS = CListCtrl :: GetItemCount(); nNewPosition = max(0, nNewPosition); nNewPosition = min(ITEMS - 1, nNewPosition); if(nItem == nNewPosition) { return(nNewPosition); } _UnsetSortedColumn(); // Backup all states and attributes const int COLS = GetColumnCount(); const DWORD STATES = GetItemStates(nItem); const DWORD DATA = CListCtrl :: GetItemData(nItem); CArray<int, int> aImages; CStringArray aTexts; aImages.SetSize(COLS); aTexts.SetSize(COLS); for(int i = 0; i < COLS; i++) { aImages[i] = GetItemImage(nItem, i); aTexts[i] = GetItemText(nItem, i); } // Delete the item CListCtrl :: DeleteItem(nItem); // Insert a new item to the new position const int IDX = CListCtrl :: InsertItem(nNewPosition, _T("")); // Restore all states & attributes to the newly inserted item for(int j = 0; j < COLS; j++) { CListCtrl :: SetItemText(IDX, j, aTexts[j]); SetItemImage(IDX, j, aImages[j]); } CListCtrl :: SetItemData(IDX, DATA); SetItemStates(IDX, STATES); return(IDX); }
BOOL CReportCtrl::ExamItemStates(int nItem, DWORD dwStates) const { if(dwStates == RC_ITEM_NONE) { return(FALSE); } if(dwStates & RC_ITEM_ALL) { return(TRUE); } return(GetItemStates(nItem) & dwStates) == dwStates; }
BOOL CReportCtrl::_PartialSort(int nStart, int nEnd) { if(nStart >= nEnd || !_IsValidIndex(nStart) || !_IsValidIndex(nEnd)) { return(FALSE); } const int COUNT = nEnd - nStart + 1; int i = 0; int *aIndices = new int[COUNT]; for(i = 0; i < COUNT; i++) { aIndices[i] = nStart + i; } _QuickSortRecursive(aIndices, 0, COUNT - 1); // rearrange items const int COLS = GetColumnCount(); ROWINFO *aRows = new ROWINFO[COUNT]; for(i = 0; i < COUNT; i++) { //int n = aIndices[i]; aRows[i].dwStates = GetItemStates(aIndices[i]); aRows[i].dwData = CListCtrl :: GetItemData(aIndices[i]); aRows[i].aImages.SetSize(COLS); aRows[i].aTexts.SetSize(COLS); for(int j = 0; j < COLS; j++) { aRows[i].aImages[j] = GetItemImage(aIndices[i], j); aRows[i].aTexts[j] = GetItemText(aIndices[i], j); } } for(i = 0; i < COUNT; i++) { SetItemStates(nStart + i, aRows[i].dwStates); CListCtrl :: SetItemData(nStart + i, aRows[i].dwData); for(int j = 0; j < COLS; j++) { SetItemImage(nStart + i, j, aRows[i].aImages[j]); CListCtrl :: SetItemText(nStart + i, j, aRows[i].aTexts[j]); } } delete[] aRows; delete[] aIndices; return(TRUE); }