Пример #1
0
void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
    
    *pResult = 0;
	
    // Request item-specific notifications if this is the
    // beginning of the paint cycle.
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        *pResult = CDRF_NOTIFYITEMDRAW;
	}
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        LVITEM   rItem;
        int      nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
        CDC*     pDC   = CDC::FromHandle ( pLVCD->nmcd.hdc );
        COLORREF crBkgnd;
        BOOL     bListHasFocus;
        CRect    rcItem;
		
        bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
        
        // Get the image index and selected/focused state of the
        // item being drawn.
        ZeroMemory ( &rItem, sizeof(LVITEM) );
        rItem.mask  = LVIF_STATE;
        rItem.iItem = nItem;
        rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
        GetItem(&rItem);
		
        // Get the rect that bounds the text label.
        GetItemRect(nItem, rcItem, LVIR_LABEL);
		rcItem.left -= DUMMY_COL_WIDTH;
		
		COLORREF OldColor = -1;
		int nOldBKMode = -1;

		CString csText;
		LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
		GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
		csText.ReleaseBuffer();

		// extract symbols
		CString strSymbols;
		int nSymEnd = csText.Find('|');
		if (nSymEnd >= 0)
		{
			strSymbols = csText.Left(nSymEnd);
			csText = csText.Mid(nSymEnd + 1);
		}
		
		// Draw the background of the list item.  Colors are selected 
		// according to the item's state.
		if(rItem.state & LVIS_SELECTED)
		{
            if(bListHasFocus)
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
			}
            else
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
			}
		}
        else
		{
            //Shade alternating Rows
			if((nItem % 2) == 0)
			{
				crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
			}
			else
			{
				crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
			}
		}
		
        pDC->FillSolidRect(rcItem, crBkgnd);
        nOldBKMode = pDC->SetBkMode(TRANSPARENT);
		
        CRect rcText = rcItem;
        rcText.left += ROW_LEFT_BORDER;
		rcText.top++;
		
		if (m_showIfClipWasPasted &&
			strSymbols.GetLength() > 0 &&
			strSymbols.Find(_T("<pasted>")) >= 0) //clip was pasted from ditto 
		{
			CRect pastedRect(rcItem);
			pastedRect.left++;
			pastedRect.right = rcItem.left + theApp.m_metrics.ScaleX(3);
				
			pDC->FillSolidRect(pastedRect, g_Opt.m_Theme.ClipPastedColor());

			rcText.left += theApp.m_metrics.ScaleX(4);
		}
		        		
		// set firstTenNum to the first ten number (1-10) corresponding to
		//  the current nItem.
		// -1 means that nItem is not in the FirstTen block.
		int firstTenNum = GetFirstTenNum(nItem);
		
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			rcText.left += theApp.m_metrics.ScaleX(12);
		}
		
		bool drawInGroupIcon = true;
		// if we are inside a group, don't display the "in group" flag
		if( theApp.m_GroupID > 0 )
		{
			int nFlag = strSymbols.Find(_T("<ingroup>"));
			if (nFlag >= 0)
				drawInGroupIcon = false;
		}
		
		DrawBitMap(nItem, rcText, pDC, csText);			

		// draw the symbol box
		if( strSymbols.GetLength() > 0 )
		{
			if(strSymbols.Find(_T("<group>")) >= 0) //group 
			{
				m_groupFolder.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_groupFolder.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (strSymbols.Find(_T("<noautodelete>")) >= 0 &&
				strSymbols.Find(_T("<group>")) < 0 &&
				strSymbols.Find(_T("<sticky>")) < 0) //don't auto delete
			{
				m_dontDeleteImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_dontDeleteImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (strSymbols.Find(_T("<shortcut>")) >= 0) // has shortcut
			{
				m_shortCutImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_shortCutImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (drawInGroupIcon &&
				strSymbols.Find(_T("<ingroup>")) >= 0) // in group
			{
				m_inFolderImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_inFolderImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (strSymbols.Find(_T("<qpastetext>")) >= 0) // has quick paste text
			{
			}
			if (strSymbols.Find(_T("<sticky>")) >= 0) //sticky clip
			{
				m_stickyImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_stickyImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}			
		}
		
		if(DrawRtfText(nItem, rcText, pDC) == FALSE)
		{
			if (m_searchText.GetLength() > 0 &&
				FindNoCaseAndInsert(csText, m_searchText, _T("<font color='#ff0000'>"), _T("</font>")) > 0)
			{				
				DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
			}
			else
			{
				pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
			}
		}
		
        // Draw a focus rect around the item if necessary.
        if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
			pDC->DrawFocusRect(rcItem);
						
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			CString cs;
			if( firstTenNum == 10 )
				cs = "0";
			else
				cs.Format(_T("%d"), firstTenNum);
			
			CRect crClient;
			
			GetWindowRect(crClient);
			ScreenToClient(crClient);
			
			CRect crHotKey = rcItem;

			int extraFromClipWasPaste = 0;
			if (m_showIfClipWasPasted)
				extraFromClipWasPaste = 3;
			
			crHotKey.right = crHotKey.left + theApp.m_metrics.ScaleX(11);
			crHotKey.left += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
			crHotKey.top += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
			
			HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
			
			pDC->DrawText(cs, crHotKey, DT_BOTTOM);
			
			pDC->MoveTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.top));
			pDC->LineTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.bottom));
			
			pDC->SelectObject(hOldFont);
		}
		
		// restore the previous values		
		if(OldColor > -1)
			pDC->SetTextColor(OldColor);
		
		if(nOldBKMode > -1)
			pDC->SetBkMode(nOldBKMode);
		
        *pResult = CDRF_SKIPDEFAULT;    // We've painted everything.
	}
}
Пример #2
0
void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
    
    *pResult = 0;
	
    // Request item-specific notifications if this is the
    // beginning of the paint cycle.
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        *pResult = CDRF_NOTIFYITEMDRAW;
	}
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        LVITEM   rItem;
        int      nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
        CDC*     pDC   = CDC::FromHandle ( pLVCD->nmcd.hdc );
        COLORREF crBkgnd;
        BOOL     bListHasFocus;
        CRect    rcItem;
		
        bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
        
        // Get the image index and selected/focused state of the
        // item being drawn.
        ZeroMemory ( &rItem, sizeof(LVITEM) );
        rItem.mask  = LVIF_STATE;
        rItem.iItem = nItem;
        rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
        GetItem(&rItem);
		
        // Get the rect that bounds the text label.
        GetItemRect(nItem, rcItem, LVIR_LABEL);
		rcItem.left -= DUMMY_COL_WIDTH;
		
		COLORREF OldColor = -1;
		int nOldBKMode = -1;
		
		// Draw the background of the list item.  Colors are selected 
		// according to the item's state.
		if(rItem.state & LVIS_SELECTED)
		{
            if(bListHasFocus)
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
			}
            else
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
			}
		}
        else
		{
            //Shade alternating Rows
			if((nItem % 2) == 0)
			{
				crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
			}
			else
			{
				crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
			}
		}
		
        pDC->FillSolidRect(rcItem, crBkgnd);
        nOldBKMode = pDC->SetBkMode(TRANSPARENT);
		
        CRect rcText = rcItem;
        rcText.left += ROW_LEFT_BORDER;
		rcText.top++;
		
        // Draw the text.
        //CString csText = GetItemText(nItem, 0);
		
		CString csText;
		LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
		GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
		csText.ReleaseBuffer();
		
		// extract symbols
		CString strSymbols;
		int nSymEnd = csText.Find('|');
		if( nSymEnd >= 0 )
		{
			strSymbols = csText.Left(nSymEnd);  
			csText = csText.Mid(nSymEnd+1);
		}
		
		// set firstTenNum to the first ten number (1-10) corresponding to
		//  the current nItem.
		// -1 means that nItem is not in the FirstTen block.
		int firstTenNum = GetFirstTenNum(nItem);
		
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			rcText.left += 12;
		}
		
		// if we are inside a group, don't display the "in group" flag
		if( theApp.m_GroupID > 0 )
		{
			int nFlag = strSymbols.Find(_T("!"));
			if( nFlag >= 0 )
				strSymbols.Delete(nFlag);
		}
		
		DrawBitMap(nItem, rcText, pDC, csText);

		// draw the symbol box
		if( strSymbols.GetLength() > 0 )
		{
			strSymbols = " " + strSymbols + " "; // leave space for box
			// add spaces to leave room for the symbols
			CRect rectSym(rcText.left, rcText.top+1, rcText.left, rcText.top+1);
			CRect rectSpace(0,0,0,0);
			//Get text bounds
			pDC->DrawText(" ", &rectSpace, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
			pDC->DrawText(strSymbols, &rectSym, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
			VERIFY( rectSpace.Width() > 0 );
			
//			int numSpaces = rectSym.Width() / rectSpace.Width();
//			numSpaces++;
//			csText = CString(' ',numSpaces) + csText;
			
			// draw the symbols
			pDC->FillSolidRect( rectSym, GetSysColor(COLOR_ACTIVECAPTION) );
			//pDC->FillSolidRect( rectSym, RGB(0,255,255) );
			pDC->Draw3dRect(rectSym, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DDKSHADOW));
			//		COLORREF crOld = pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT));
			COLORREF crOld = pDC->SetTextColor(RGB(255, 255, 255));
			pDC->DrawText(strSymbols, rectSym, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
			pDC->SetTextColor(crOld);

			rcText.left += rectSym.Width() + 2;
		}
		
		if(DrawRtfText(nItem, rcText, pDC) == FALSE)
		{
			pDC->DrawText(csText, rcText, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
		}
		
        // Draw a focus rect around the item if necessary.
        if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
			pDC->DrawFocusRect(rcItem);
		
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			CString cs;
			if( firstTenNum == 10 )
				cs = "0";
			else
				cs.Format(_T("%d"), firstTenNum);
			
			CRect crClient;
			
			GetWindowRect(crClient);
			ScreenToClient(crClient);
			
			CRect crHotKey = rcItem;
			
			crHotKey.right = crHotKey.left + 11;
			crHotKey.left += 2;
			crHotKey.top += 2;
			
			HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
			
			pDC->DrawText(cs, crHotKey, DT_BOTTOM);
			
			pDC->MoveTo(CPoint(rcItem.left + 11, rcItem.top));
			pDC->LineTo(CPoint(rcItem.left + 11, rcItem.bottom));
			
			pDC->SelectObject(hOldFont);
		}
		
		// restore the previous values		
		if(OldColor > -1)
			pDC->SetTextColor(OldColor);
		
		if(nOldBKMode > -1)
			pDC->SetBkMode(nOldBKMode);
		
        *pResult = CDRF_SKIPDEFAULT;    // We've painted everything.
	}
}