// ListCtrlEx.cpp : implementation file // #include "stdafx.h" #include "ListCtrlEx.h" #include "SortClass.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__ ; #endif ///////////////////////////////////////////////////////////////////////////// // CListCtrlEx CListCtrlEx::CListCtrlEx() { m_nColNum = 0; m_nDisableRow = -1; m_nDisableCol = -1; m_nEditDisableState = EDITDISABLE_NONE; m_pEdit = NULL; m_pComboBox = NULL; m_pEditDisableCols = NULL; m_pEditDisableRows = NULL; m_strInitEditText = _T(""); m_nInPlaceCtrl = -1; m_bSortOrder = TRUE; m_bEnableSortList = TRUE; m_nLength = 0; m_pComboData = NULL; m_nComboDataState = COMBODATASTATE_SINGLE; m_pEditCtrlCols = NULL; m_pComboCtrlCols = NULL; m_nEditCtrlLength = 0; m_nComboCtrlLength = 0; m_bSetImageList = FALSE; m_pbNumericCol = NULL; } CListCtrlEx::~CListCtrlEx() { if(m_pEdit) { delete m_pEdit; m_pEdit = NULL; } if(m_pComboBox) { delete m_pComboBox; m_pComboBox = NULL; } if(m_pEditDisableCols) { delete m_pEditDisableCols; m_pEditDisableCols = NULL; } if(m_pEditDisableRows) { delete m_pEditDisableRows; m_pEditDisableRows = NULL; } if(m_pComboData) { m_pComboData->RemoveAll(); delete m_pComboData; m_pComboData = NULL; } if(m_pEditCtrlCols) { delete m_pEditCtrlCols; m_pEditCtrlCols = NULL; } if(m_pComboCtrlCols) { delete m_pComboCtrlCols; m_pComboCtrlCols = NULL; } if(m_pbNumericCol != NULL) { delete[] m_pbNumericCol; m_pbNumericCol = NULL; } ResetTextColor(); ResetBKColor(); } BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl) //{{AFX_MSG_MAP(CListCtrlEx) ON_WM_LBUTTONDOWN() ON_WM_VSCROLL() ON_WM_HSCROLL() ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick) ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CListCtrlEx message handlers void CListCtrlEx::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CListCtrl::OnLButtonDown(nFlags, point); // AddBlankItem(); LVHITTESTINFO pItem; pItem.pt = point; int test = SubItemHitTest(&pItem); int nCol,nRow; nRow = pItem.iItem; nCol = pItem.iSubItem; if(nRow != -1) { CRect rect; if(nCol == 0) { GetItemRect(nRow,rect,LVIR_BOUNDS); rect.right = GetColumnWidth(nCol); } else GetSubItemRect(nRow,nCol,LVIR_BOUNDS,rect); // Á¦¿ÜµÈ Çà,¿­ üũ ////////////////////////////////////////////////////// if(m_nEditDisableState == EDITDISABLE_ROWS || m_nEditDisableState == EDITDISABLE_COLS) { if(m_nDisableRow == nRow) return; if(m_nDisableCol == nCol) return; } if(m_nEditDisableState == EDITDISABLE_ROWCOL) { if(m_nDisableRow == nRow && m_nDisableCol == nCol) return; } if(m_nEditDisableState == EDITDISABLE_ROWS_ARRAY) { if(m_pEditDisableRows) { for(int i=0;iCreate(WS_BORDER | WS_CHILD | WS_VISIBLE,rect,this,10000); m_pEdit->ShowWindow(SW_SHOW); } if(m_nInPlaceCtrl == INPLACECTRL_COMBO) { if(m_pComboBox) { delete m_pComboBox; m_pComboBox = NULL; } m_pComboBox = new CInPlaceComboBox(nRow,nCol); rect.bottom = rect.bottom + 200; m_pComboBox->Create(WS_BORDER | WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL,rect,this,10001); // DWORD dwStyle = m_pComboBox->GetStyle(); // dwStyle &= ~CBS_SORT; // SetWindowLong(m_pComboBox->m_hWnd, GWL_STYLE, dwStyle); POSITION pos = m_pComboData->GetHeadPosition(); while(pos) { m_pComboBox->AddString(m_pComboData->GetNext(pos)); } m_pComboBox->ShowDropDown(); m_pComboBox->SetCurSel(0); m_pComboBox->ShowWindow(SW_SHOW); } if(m_nInPlaceCtrl == INPLACECTRL_EDIT_COMBO) { if(m_pEditCtrlCols) { for(int i=0;iCreate(WS_BORDER | WS_CHILD | WS_VISIBLE,rect,this,10000); m_pEdit->ShowWindow(SW_SHOW); } } } if(m_pComboCtrlCols) { for(int j=0;jCreate(WS_BORDER | WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL,rect,this,10001); // DWORD dwStyle = m_pComboBox->GetStyle(); // dwStyle &= ~CBS_SORT; // SetWindowLong(m_pComboBox->m_hWnd, GWL_STYLE, dwStyle); if(!m_pComboData) return; if(m_nComboDataState == COMBODATASTATE_SINGLE) { POSITION pos = m_pComboData->GetHeadPosition(); while(pos) { m_pComboBox->AddString(m_pComboData->GetNext(pos)); } } if(m_nComboDataState == COMBODATASTATE_MULTI) { POSITION pos = m_pComboData->FindIndex(j); if(!pos) return; CString strData = m_pComboData->GetAt(pos); CString strToken; for(int k=0;kAddString((LPTSTR)(LPCTSTR)strToken); strToken.Empty(); } else strToken += ch; } m_pComboBox->AddString((LPTSTR)(LPCTSTR)strToken); } m_pComboBox->ShowDropDown(); m_pComboBox->SetCurSel(0); m_pComboBox->ShowWindow(SW_SHOW); } } } } } } void CListCtrlEx::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default if (GetFocus() != this) SetFocus(); CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar); } void CListCtrlEx::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default if (GetFocus() != this) SetFocus(); CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar); } void CListCtrlEx::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // TODO: Add your control notification handler code here if(m_bEnableSortList) SortListCtrl(pNMListView->iSubItem); *pResult = 0; } void CListCtrlEx::SetTextColor(int nRow, COLORREF clrText) { POSITION pos = m_ListColorText.GetHeadPosition(); pListRowColor pLRC; BOOL bIs = FALSE; while (pos) { pLRC = m_ListColorText.GetNext(pos); if (pLRC) { if (pLRC->s_nRow == nRow) { pLRC->s_Color = clrText; bIs = TRUE; break; } } } if (!bIs) { pListRowColor pLRC = new ListRowColor; pLRC->s_nRow = nRow; pLRC->s_Color = clrText; m_ListColorText.AddTail(pLRC); } } void CListCtrlEx::SetBKColor(int nRow, COLORREF clrBK) { POSITION pos = m_ListColorBk.GetHeadPosition(); pListRowColor pLRC; BOOL bIs = FALSE; while (pos) { pLRC = m_ListColorBk.GetNext(pos); if (pLRC) { if (pLRC->s_nRow == nRow) { pLRC->s_Color = clrBK; bIs = TRUE; break; } } } if (!bIs) { pListRowColor pLRC = new ListRowColor; pLRC->s_nRow = nRow; pLRC->s_Color = clrBK; m_ListColorBk.AddTail(pLRC); } } void CListCtrlEx::ReleaseTextColor(int nRow) { POSITION posDel = NULL; POSITION pos = m_ListColorText.GetHeadPosition(); pListRowColor pLRC; BOOL bIs = FALSE; while (pos) { posDel = pos; pLRC = m_ListColorText.GetNext(pos); if (pLRC && pLRC->s_nRow == nRow) { bIs = TRUE; break; } } if (bIs && posDel && pLRC) { delete pLRC; pLRC = NULL; m_ListColorText.RemoveAt(posDel); } } void CListCtrlEx::ReleaseBKColor(int nRow) { POSITION posDel = NULL; POSITION pos = m_ListColorBk.GetHeadPosition(); pListRowColor pLRC; BOOL bIs = FALSE; while (pos) { posDel = pos; pLRC = m_ListColorBk.GetNext(pos); if (pLRC && pLRC->s_nRow == nRow) { bIs = TRUE; break; } } if (bIs && posDel && pLRC) { delete pLRC; pLRC = NULL; m_ListColorBk.RemoveAt(posDel); } } void CListCtrlEx::ResetTextColor() { POSITION pos = m_ListColorText.GetHeadPosition(); pListRowColor pLRC; while (pos) { pLRC = m_ListColorText.GetNext(pos); if (pLRC) delete pLRC; pLRC = NULL; } m_ListColorText.RemoveAll(); } void CListCtrlEx::ResetBKColor() { POSITION pos = m_ListColorBk.GetHeadPosition(); pListRowColor pLRC; while (pos) { pLRC = m_ListColorBk.GetNext(pos); if (pLRC) delete pLRC; pLRC = NULL; } m_ListColorBk.RemoveAll(); } void CListCtrlEx::AddBlankItem() { int nRow; nRow = GetCountPerPage(); if(GetItemCount() 0 && nPoint + 1 < strValue.GetLength() - nRight) strValue = strValue.Left(nPoint + 4); LV_ITEM item; item.mask = LVIF_TEXT | LVIF_IMAGE; item.iItem = nRow; item.iSubItem = nCol; item.pszText = (LPTSTR)(LPCTSTR)strValue; InsertItem(&item); item.iSubItem = nCol; item.pszText = (LPTSTR)(LPCTSTR)strValue; SetItem(&item); } void CListCtrlEx::InsertListItem(int nRow, int nCol, int nImageIdx) { if (m_bSetImageList) { LV_ITEM item; item.mask = LVIF_TEXT | LVIF_IMAGE; item.iItem = nRow; item.iImage = nImageIdx; item.iSubItem = nCol; item.pszText = _T(""); SetItem(&item); } else InsertListItem(nRow, nCol, _T("") ); } void CListCtrlEx::EditDisableRows(int nRows) { SetEditDisableState(EDITDISABLE_NONE); m_nDisableRow = nRows; m_nEditDisableState = EDITDISABLE_ROWS; } void CListCtrlEx::EditDisableCols(int nCols) { SetEditDisableState(EDITDISABLE_NONE); m_nDisableCol = nCols; m_nEditDisableState = EDITDISABLE_COLS; } void CListCtrlEx::EditDisableRowCol(int nRow, int nCol) { SetEditDisableState(EDITDISABLE_NONE); m_nDisableRow = nRow; m_nDisableCol = nCol; m_nEditDisableState = EDITDISABLE_ROWCOL; } void CListCtrlEx::EditDisableCols(CString strCols,int nLength) { if(m_pEditDisableCols) { delete m_pEditDisableCols; m_pEditDisableCols = NULL; } m_pEditDisableCols = new int[nLength]; m_nLength = nLength; int nCol = 0; CString strToken; for(int i=0;iRemoveAll(); delete m_pComboData; m_pComboData = NULL; } m_pComboData = new CStringList; for(int i=0;iAddTail( pData[i] ); } m_nComboDataState = nState; } void CListCtrlEx::SetComboData(CStringList* pList, int nState) { if(m_nInPlaceCtrl == INPLACECTRL_EDIT) return; if(m_pComboData) { m_pComboData->RemoveAll(); delete m_pComboData; m_pComboData = NULL; } m_pComboData = new CStringList; POSITION pos = pList->GetHeadPosition(); while(pos) { m_pComboData->AddTail(pList->GetNext(pos)); } m_nComboDataState = nState; } void CListCtrlEx::SetEditCtrlCols(CString strCols, int nLength) { if(m_pEditCtrlCols) { delete m_pEditCtrlCols; m_pEditCtrlCols = NULL; } m_pEditCtrlCols = new int[nLength]; m_nEditCtrlLength = nLength; int nCol = 0; CString strToken; for(int i=0;i(pNMHDR); *pResult = CDRF_DODEFAULT; if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) *pResult = CDRF_NOTIFYITEMDRAW; else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) { int nItem = static_cast(pLVCD->nmcd.dwItemSpec); // °¢ ¶óÀÎ ¼³Á¤ COLORREF crTextColor = RGB(0,0,0), crBkColor = RGB(255,255,255); pListRowColor pLRC = NULL; POSITION pos = NULL; // ±ÛÀÚ»ö ¹Ù²Ù±â pos = m_ListColorText.GetHeadPosition(); while (pos) { pLRC = m_ListColorText.GetNext(pos); if (pLRC && pLRC->s_nRow == nItem) break; } if (pLRC) pLVCD->clrText = pLRC->s_Color; // ¹è°æ»ö ¹Ù²Ù±â pos = m_ListColorBk.GetHeadPosition(); while (pos) { pLRC = m_ListColorBk.GetNext(pos); if (pLRC && pLRC->s_nRow == nItem) break; } if (pLRC) pLVCD->clrTextBk = pLRC->s_Color; // Tell Windows to paint the control itself; *pResult = CDRF_DODEFAULT; } } void CListCtrlEx::InitNumericCol( BOOL* pbCol,int nLength ) { for(int i=0; i < nLength; i++) { m_pbNumericCol[i] = pbCol[i]; } }