// SISListCtrlExt.cpp : implementation file // #include "stdafx.h" //#include " \ add additional includes here" #include "SISListCtrlExt.h" #include "SortClass.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSISListCtrlExt CSISListCtrlExt::CSISListCtrlExt() { 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; } void CSISListCtrlExt::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 CSISListCtrlExt::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 CSISListCtrlExt::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 CSISListCtrlExt::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 CSISListCtrlExt::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 CSISListCtrlExt::ResetBKColor() { POSITION pos = m_ListColorBk.GetHeadPosition(); pListRowColor pLRC; while (pos) { pLRC = m_ListColorBk.GetNext(pos); if (pLRC) delete pLRC; pLRC = NULL; } m_ListColorBk.RemoveAll(); } CSISListCtrlExt::~CSISListCtrlExt() { 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; } ResetTextColor(); ResetBKColor(); } BEGIN_MESSAGE_MAP(CSISListCtrlExt, CListCtrl) //{{AFX_MSG_MAP(CSISListCtrlExt) 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() ///////////////////////////////////////////////////////////////////////////// // CSISListCtrlExt message handlers void CSISListCtrlExt::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(strToken); strToken.Empty(); } else strToken += ch; } m_pComboBox->AddString(strToken); } m_pComboBox->ShowDropDown(); m_pComboBox->SetCurSel(0); m_pComboBox->ShowWindow(SW_SHOW); } } } } } } void CSISListCtrlExt::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 = (LPWSTR)(LPCTSTR)strValue; InsertItem(&item); item.iSubItem = nCol; item.pszText = (LPWSTR)(LPCTSTR)strValue; SetItem(&item); } void CSISListCtrlExt::EditDisableRows(int nRows) { SetEditDisableState(EDITDISABLE_NONE); m_nDisableRow = nRows; m_nEditDisableState = EDITDISABLE_ROWS; } void CSISListCtrlExt::EditDisableCols(int nCols) { SetEditDisableState(EDITDISABLE_NONE); m_nDisableCol = nCols; m_nEditDisableState = EDITDISABLE_COLS; } void CSISListCtrlExt::EditDisableRowCol(int nRow, int nCol) { SetEditDisableState(EDITDISABLE_NONE); m_nDisableRow = nRow; m_nDisableCol = nCol; m_nEditDisableState = EDITDISABLE_ROWCOL; } void CSISListCtrlExt::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;iiSubItem); *pResult = 0; } void CSISListCtrlExt::SortListCtrl(int nCol) { CSortClass csc(this, nCol , 0); if(m_bSortOrder) m_bSortOrder = FALSE; else m_bSortOrder = TRUE; csc.Sort(m_bSortOrder?1:0); } void CSISListCtrlExt::SetEnableSortList(BOOL nEnable) { m_bEnableSortList = nEnable; } BOOL CSISListCtrlExt::GetEnableSortList() { return m_bEnableSortList; } void CSISListCtrlExt::SetComboData(TCHAR *pData[], int nState , int nLength) { if(m_nInPlaceCtrl == INPLACECTRL_EDIT) return; if(m_pComboData) { m_pComboData->RemoveAll(); delete m_pComboData; m_pComboData = NULL; } m_pComboData = new CStringList; for(int i=0;iAddTail((LPSTR)(LPCSTR)pData[i]); } m_nComboDataState = nState; } void CSISListCtrlExt::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 CSISListCtrlExt::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; } }