/******************************************************************************* Function Name : OnHeaderEndDrag Input(s) : pNMHDR, pResult Output : BOOL Functionality : Event is fired after column Drag is ended. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ BOOL CRxMsgList::OnHeaderEndDrag(UINT, NMHDR* pNMHDR, LRESULT* /*pResult*/) { NMHEADER* pNMH = (NMHEADER*)pNMHDR; if (pNMH->pitem->mask & HDI_ORDER) { // Correct iOrder so it is just after the last hidden column int nColCount = GetHeaderCtrl()->GetItemCount(); int* pOrderArray = new int[nColCount]; VERIFY( GetColumnOrderArray(pOrderArray, nColCount) ); if(pNMH->iItem == 0 ) { pNMH->pitem->iOrder = 0; return FALSE; } for(int i = 0; i < nColCount ; ++i) { if (IsColumnVisible(pOrderArray[i])) { pNMH->pitem->iOrder = max(pNMH->pitem->iOrder,i); if(pNMH->pitem->iOrder == 0) pNMH->pitem->iOrder++; break; } } delete [] pOrderArray; } return FALSE; }
void CSortingListControl::LoadPersistentAttributes() { CArray<int, int> arr; arr.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(arr.GetData(), arr.GetSize()); CPersistence::GetColumnOrder(m_name, arr); SetColumnOrderArray(arr.GetSize(), arr.GetData()); for (int i=0; i < arr.GetSize(); i++) arr[i]= GetColumnWidth(i); CPersistence::GetColumnWidths(m_name, arr); for (i=0; i < arr.GetSize(); i++) { // To avoid "insane" settings we set the column width to // maximal twice the default width. int maxWidth= GetColumnWidth(i) * 2; int w= min(arr[i], maxWidth); SetColumnWidth(i, w); } // Not so good: CPersistence::GetSorting(m_name, GetHeaderCtrl()->GetItemCount(), m_sorting.column1, m_sorting.ascending1, m_sorting.column2, m_sorting.ascending2); // We refrain from saving the sorting because it is too likely, that // users start up with insane settings and don't get it. }
void CListCtrlEx::DeleteHdrItem(int iItem) { int aOrder [LISTEX_MAXCOLUMNS]; GetColumnOrderArray ((int*) aOrder, GetHeaderCtrl ()->GetItemCount ()); int iCol = aOrder [m_aIndex [iItem]]; DeleteColumn (iCol); RebuildAIndex (); OnForceUpdate (); }
void CSortingListControl::SavePersistentAttributes() { CArray<int, int> arr; arr.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(arr.GetData(), arr.GetSize()); CPersistence::SetColumnOrder(m_name, arr); for (int i=0; i < arr.GetSize(); i++) arr[i]= GetColumnWidth(i); CPersistence::SetColumnWidths(m_name, arr); // Not so good: CPersistence::SetSorting(m_name, m_sorting.column1, m_sorting.ascending1, m_sorting.column2, m_sorting.ascending2); }
bool CReportCtrl::StoreHeaderState(LPCTSTR Key, LPCTSTR SubKey) { DWORD hsz = CalcHeaderStateSize(m_Columns); HEADER_STATE *ph = (HEADER_STATE *)new BYTE[hsz]; ph->Columns = m_Columns; ph->SortCol = SortCol(); ph->SortDir = SortDir(); int cols = m_Columns; int *pColWidth = &ph->ColInfo[cols]; for (int i = 0; i < cols; i++) pColWidth[i] = GetColumnWidth(i); GetColumnOrderArray(ph->ColInfo, cols); bool retc = CPersist::WriteBinary(Key, SubKey, ph, hsz) != 0; delete ph; return(retc); }
void CListCtrlEx::SetColumnText(int iCol, LPCSTR pszText) { m_appszCols [iCol] = pszText; if (m_aIndex [iCol] == -1) return; int aOrder [LISTEX_MAXCOLUMNS]; GetColumnOrderArray ((int*) aOrder, GetHeaderCtrl ()->GetItemCount ()); iCol = aOrder [m_aIndex [iCol]]; HDITEM item; item.mask = HDI_TEXT; item.pszText = (LPSTR) pszText; GetHeaderCtrl ()->SetItem (iCol, &item); }
void CListCtrlEx::RebuildAIndex() { int cCols = GetHeaderCtrl ()->GetItemCount (); int i = 0; for (i = 0; i < m_cTotalCols; i++) m_aIndex [i] = -1; int aOrder [LISTEX_MAXCOLUMNS]; GetColumnOrderArray ((int*) aOrder, cCols); HDITEM item; item.mask = HDI_LPARAM; for (i = 0; i < cCols; i++) { GetHeaderCtrl ()->GetItem (aOrder [i], &item); m_aIndex [item.lParam] = i; } }
void CDownloadedListView::OnDestroy() { // 設定を保存する CString strIniFile = Misc::GetFullPath_ForExe(_T("Download.ini")); CIniFileO pr(strIniFile, _T("DownloadedListView")); int nColumnCount = GetColumnCount(); unique_ptr<int[]> pColumnOrder(new int[nColumnCount]); GetColumnOrderArray(nColumnCount, pColumnOrder.get()); for (int i = 0; i < nColumnCount; ++i) { CString strColumnOrder = _T("ColumnOrder"); strColumnOrder.Append(i); pr.SetValue(pColumnOrder[i], strColumnOrder); } for (int i = 0; i < nColumnCount; ++i) { int nWidth = GetColumnWidth(i); CString strWidth = _T("ColumnWidth"); strWidth.Append(i); pr.SetValue(nWidth, strWidth); } }
void CListCtrlEx::SaveState(LPCSTR pszName) { int *piWidthes; piWidthes = new int [m_cTotalCols]; int aOrder [LISTEX_MAXCOLUMNS]; GetColumnOrderArray ((int*) aOrder, GetHeaderCtrl ()->GetItemCount ()); for (int i = 0; i < m_cTotalCols; i++) if (m_aIndex [i] != -1) piWidthes [i] = GetColumnWidth (aOrder [m_aIndex [i]]); else piWidthes [i] = -1; CString strIndexes = pszName, strWidthes = pszName; strIndexes += 'I'; strWidthes += 'W'; _App.WriteProfileBinary (_T ("Settings\\View\\ListViews"), strIndexes, (LPBYTE)m_aIndex, m_cTotalCols * sizeof (int)); _App.WriteProfileBinary (_T ("Settings\\View\\ListViews"), strWidthes, (LPBYTE)piWidthes, m_cTotalCols * sizeof (int)); delete [] piWidthes; }
/******************************************************************************* Function Name : ShowColumn Input(s) : nCol, bShow Output : BOOL Functionality : Shows/Hides a Column nCol based on boolean bShow. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ BOOL CRxMsgList::ShowColumn(int nCol, bool bShow) { SetRedraw(FALSE); ColumnState& columnState = GetColumnState(nCol); int nColCount = GetHeaderCtrl()->GetItemCount(); int* pOrderArray = new int[nColCount]; VERIFY( GetColumnOrderArray(pOrderArray, nColCount) ); if (bShow) { // Restore the position of the column int nCurIndex = -1; for(int i = 0; i < nColCount ; ++i) { if (pOrderArray[i]==nCol) { nCurIndex = i; } else if (nCurIndex!=-1) { // We want to move it to the original position, // and after the last hidden column if ( (i <= columnState.m_OrgPosition) || !IsColumnVisible(pOrderArray[i]) ) { pOrderArray[nCurIndex] = pOrderArray[i]; pOrderArray[i] = nCol; nCurIndex = i; } } } } else { // Move the column to the front of the display order list int nCurIndex(-1); for(int i = nColCount-1; i >=0 ; --i) { if (pOrderArray[i]==nCol) { // Backup the current position of the column columnState.m_OrgPosition = i; nCurIndex = i; } else if (nCurIndex!=-1) { pOrderArray[nCurIndex] = pOrderArray[i]; pOrderArray[i] = nCol; nCurIndex = i; } } } VERIFY( SetColumnOrderArray(nColCount, pOrderArray) ); delete [] pOrderArray; if (bShow) { // Restore the column width columnState.m_Visible = true; VERIFY( SetColumnWidth(nCol, columnState.m_OrgWidth) ); } else { // Backup the column width if(GetColumnWidth(nCol) == 0) { columnState.m_Visible = false; } else { int orgWidth = GetColumnWidth(nCol); VERIFY( SetColumnWidth(nCol, 0) ); columnState.m_Visible = false; columnState.m_OrgWidth = orgWidth; } } SetRedraw(TRUE); Invalidate(FALSE); return TRUE; }
/* This function saves the columns widths of the listctrl to the registry. This is called in two places, OnDestroy, and OnEndTrack in the headerCtrl class. */ void CMultiColumnSortListCtrl::SaveColumnSettings() { //You must set a unique name for every listctrl ASSERT( m_strUniqueName.GetLength() ); int nIndex; //for the loops /* Save the widths */ CString strEntry( m_strUniqueName ); CString strValue; int iNumColumns = GetColumnCount(); for( nIndex = 0; nIndex < iNumColumns; nIndex++ ) { CString strTemp; strTemp.Format( "%d,", GetColumnWidth(nIndex) ); strValue += strTemp; } //write to the registry AfxGetApp()->WriteProfileString( m_strColumnWidthSection, strEntry, strValue ); /* Save the column's order */ LPINT pnOrder = (LPINT)malloc(iNumColumns*sizeof(int)); ASSERT(pnOrder != NULL); if( pnOrder ) { GetColumnOrderArray(pnOrder, iNumColumns); CString strColumnOrder; for( nIndex = 0; nIndex < iNumColumns; nIndex++ ) { CString strTemp; strTemp.Format( "%d,", pnOrder[nIndex] ); strColumnOrder += strTemp; } //write to the registry AfxGetApp()->WriteProfileString( m_strColumnOrderSection, strEntry, strColumnOrder ); free(pnOrder); } /* Save the sort order It saves the column numbers, it's negative if ASCENDING */ CString strColumnSort; int iNumCombinedSortedCols = GetNumCombinedSortedColumns(); //store the m_lColumnSortStates first { CString strTemp; strTemp.Format( "%d,", m_lColumnSortStates ); strColumnSort += strTemp; } //iterate the columns for( nIndex = 0; nIndex < iNumCombinedSortedCols; nIndex++ ) { SORT_STATE ssEachItem = GetItemSortState( m_aCombinedSortedColumns[nIndex] ); CString strTemp; strTemp.Format( "%d,", m_aCombinedSortedColumns[nIndex] ); strColumnSort += strTemp; } //write to the registry AfxGetApp()->WriteProfileString( m_strColumnSortSection, strEntry, strColumnSort ); }
BOOL COwnerDrawnListControl::OnEraseBkgnd(CDC* pDC) { int i = 0; ASSERT(GetHeaderCtrl()->GetItemCount() > 0); // We should recalculate m_yFirstItem here (could have changed e.g. when // the XP-Theme changed). if(GetItemCount() > 0) { CRect rc; GetItemRect(GetTopIndex(), rc, LVIR_BOUNDS); m_yFirstItem = rc.top; } // else: if we did the same thing as in OnColumnsCreated(), we get // repaint problems. const COLORREF gridColor = RGB(212,208,200); CRect rcClient; GetClientRect(rcClient); CRect rcHeader; GetHeaderCtrl()->GetWindowRect(rcHeader); ScreenToClient(rcHeader); CRect rcBetween = rcClient; // between header and first item rcBetween.top = rcHeader.bottom; rcBetween.bottom = m_yFirstItem; pDC->FillSolidRect(rcBetween, gridColor); CArray<int, int> columnOrder; columnOrder.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(columnOrder.GetData(), int(columnOrder.GetSize())); CArray<int, int> vertical; vertical.SetSize(GetHeaderCtrl()->GetItemCount()); int x = - GetScrollPos(SB_HORZ); HDITEM hdi; ZeroMemory(&hdi, sizeof(hdi)); hdi.mask = HDI_WIDTH; for(i = 0; i < GetHeaderCtrl()->GetItemCount(); i++) { GetHeaderCtrl()->GetItem(columnOrder[i], &hdi); x += hdi.cxy; vertical[i]= x; } if(m_showGrid) { CPen pen(PS_SOLID, 1, gridColor); CSelectObject sopen(pDC, &pen); for(int y = m_yFirstItem + GetRowHeight() - 1; y < rcClient.bottom; y += GetRowHeight()) { pDC->MoveTo(rcClient.left, y); pDC->LineTo(rcClient.right, y); } // BUGBUG: re-using i could be a potential bug! for(i = 0; i < vertical.GetSize(); i++) { pDC->MoveTo(vertical[i] - 1, rcClient.top); pDC->LineTo(vertical[i] - 1, rcClient.bottom); } } const int gridWidth = m_showGrid ? 1 : 0; const COLORREF bgcolor = ::GetSysColor(COLOR_WINDOW); const int lineCount = GetCountPerPage() + 1; const int firstItem = GetTopIndex(); const int lastItem = min(firstItem + lineCount, GetItemCount()) - 1; ASSERT(GetItemCount() == 0 || firstItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem >= firstItem); const int itemCount = lastItem - firstItem + 1; CRect fill; fill.left = vertical[vertical.GetSize() - 1]; fill.right = rcClient.right; fill.top = m_yFirstItem; fill.bottom = fill.top + GetRowHeight() - gridWidth; for(i = 0; i < itemCount; i++) { pDC->FillSolidRect(fill, bgcolor); fill.OffsetRect(0, GetRowHeight()); } int top = fill.top; while(top < rcClient.bottom) { fill.top = top; fill.bottom = top + GetRowHeight() - gridWidth; int left = 0; for(int i = 0; i < vertical.GetSize(); i++) { fill.left = left; fill.right = vertical[i] - gridWidth; pDC->FillSolidRect(fill, bgcolor); left = vertical[i]; } fill.left = left; fill.right = rcClient.right; pDC->FillSolidRect(fill, bgcolor); top += GetRowHeight(); } return true; }