Пример #1
0
void CFontComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
	CString strText;
	//判断当前索引的字体名称是否为空
	int nIndex = lpDrawItemStruct->itemID;
	if (GetLBTextLen(nIndex) < 0)
		return ;
	GetLBText(nIndex, strText);
	ASSERT(!strText.IsEmpty());
	int nImage = 0;
	//根据索引值从m_pFontVec得到字体图像类型
	if (!m_pFontVec.empty())
		nImage = m_pFontVec[nIndex]->GetImage();
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC);
	COLORREF crOldTextColor = dc.GetTextColor();
	COLORREF crOldBkColor = dc.GetBkColor();
	//如果Item处于选择焦点、状态下,用系统高亮色改变文本和背景色
	if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
		(lpDrawItemStruct->itemState & ODS_SELECTED))
	{
		dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
		dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
	}
	else
		dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
	CRect     rItem(lpDrawItemStruct->rcItem);
	CRect     rText(rItem);
	CRect     rBmp(&rItem);
	if(m_FontBmp)
	{
		//计算Item中字体预览图的贴图位置
		rBmp.top +=  (rBmp.Height() - FNTIMG_Y) / 2;
		rBmp.bottom = rBmp.top + FNTIMG_Y + 1;
		rText.left += FNTIMG_X;
		if (nImage != (int)0XFF)
		{
			int x,y;
			x = nImage * FNTIMG_X;   //根据预览图类型计算源图的矩形大小
			y = FNTIMG_Y;
			CDC mdc;
			mdc.CreateCompatibleDC(&dc);
			CBitmap* pOldBmp = mdc.SelectObject(CBitmap::FromHandle(m_FontBmp));
			COLORREF clrTransparent = mdc.GetPixel(0, y);
			//调用TransparentBlt进行透明贴图,此函数需要加入MsImg32.Lib文件
			::TransparentBlt (dc.GetSafeHdc(),rBmp.left, rBmp.top, FNTIMG_X, FNTIMG_Y,  
				mdc, x, y, FNTIMG_X, FNTIMG_Y, clrTransparent);
		}
	}
	else
		rText.left += 10;
	//rText所代表的字体名称填充位置需要右移图片的宽度
	dc.DrawText(strText, rText, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
	dc.SetTextColor(crOldTextColor);
	dc.SetBkColor(crOldBkColor);
	dc.Detach();
} 
Пример #2
0
// ------------------------------------------------------------------------------------------------
//	Opens a file, which is part of the archive.
IOStream *Q3BSPZipArchive::Open( const char* pFile, const char* pMode )
{
	ai_assert( NULL != pFile );

	std::string rItem( pFile );
	std::vector<std::string>::iterator it = std::find( m_FileList.begin(), m_FileList.end(), rItem );
	if ( m_FileList.end() == it )
		return NULL;

	ZipFile *pZipFile = new ZipFile( *it, m_ZipFileHandle );
	m_ArchiveMap[ rItem ] = pZipFile;

	return pZipFile;
}
LRESULT CPreferencesShortcutsPage::OnGutterDrawItem(WPARAM /*wParam*/, LPARAM lParam)
{
	NCGDRAWITEM* pNCGDI = (NCGDRAWITEM*)lParam;

	if (pNCGDI->nColID == PSP_SHORTCUTCOLUMNID)
	{
		CRect rItem(pNCGDI->rItem);
		HTREEITEM hti = (HTREEITEM)pNCGDI->dwItem;

		if (m_tcCommands.ItemHasChildren(hti))
		{
			pNCGDI->pDC->FillSolidRect(rItem, ::GetSysColor(COLOR_3DHIGHLIGHT));
			pNCGDI->pDC->FillSolidRect(rItem.right - 1, rItem.top, 1, rItem.Height(), OTC_GRIDCOLOR);
		}
		else
		{
			UINT nCmdID = m_tcCommands.GetItemData(hti);
			DWORD dwShortcut = 0;
		
			m_mapID2Shortcut.Lookup(nCmdID, dwShortcut);

			if (dwShortcut)
			{
				rItem.left += 3;

				// test for reserved shortcut and mark in red
				if (CToDoCtrl::IsReservedShortcut(dwShortcut) && !IsMiscCommandID(nCmdID))
					pNCGDI->pDC->SetTextColor(255);

				CString sText = m_pShortcutMgr->GetShortcutText(dwShortcut);

				if (!sText.IsEmpty())
					pNCGDI->pDC->DrawText(sText, rItem, DT_SINGLELINE | DT_VCENTER | DT_LEFT);

				rItem.left -= 3;
			}
			
			// vertical divider
			pNCGDI->pDC->FillSolidRect(rItem.right - 1, rItem.top, 1, rItem.Height(), OTC_GRIDCOLOR);
		}

		// horz divider
		rItem.top = rItem.bottom - 1;
		pNCGDI->pDC->FillSolidRect(rItem, OTC_GRIDCOLOR);
	
		return TRUE; // we handled it
	}

	return FALSE;
}
Пример #4
0
void CTabCtrlSSL::DrawItem(LPDRAWITEMSTRUCT lpdis)
{
	TC_ITEM     tci;
	CDC* pDC = CDC::FromHandle(lpdis->hDC);
	HIMAGELIST hilTabs = (HIMAGELIST)TabCtrl_GetImageList(GetSafeHwnd());

	BOOL bSelected = (lpdis->itemID == (UINT)GetCurSel());

	CRect rItem(lpdis->rcItem);
	UINT itemID = lpdis->itemID;

	if (bSelected)
		rItem.bottom -= 1;
	else
		rItem.bottom += 2;

	// tab
	// blend from back color to COLOR_3DFACE if 16 bit mode or better
	COLORREF crFrom;
	crFrom = ::GetSysColor(COLOR_3DFACE);

	if(itemID == (UINT)m_hColorTabID)
		pDC->FillSolidRect(rItem, crTabColor);
	else
		pDC->FillSolidRect(rItem, crFrom);

	// text & icon
	rItem.left += 3;
	rItem.top += 3 + (bSelected ? 1 : 0);

	pDC->SetBkMode(TRANSPARENT);

	CString sTemp;
	tci.mask        = TCIF_TEXT | TCIF_IMAGE;
	tci.pszText     = sTemp.GetBuffer(100);
	tci.cchTextMax  = 99;
	GetItem(lpdis->itemID, &tci);
	sTemp.ReleaseBuffer();

	// icon
	if (hilTabs)
	{
		ImageList_Draw(hilTabs, tci.iImage, *pDC, rItem.left, rItem.top, ILD_TRANSPARENT);
		rItem.left += 16 + 3;
	}

	// text
	rItem.right -= 3;
	pDC->DrawText(sTemp, rItem, DT_NOPREFIX | DT_CENTER);
}
Пример #5
0
bool TracksView::viewportEvent(QEvent *event)
      {
      if (event->type() == QEvent::ToolTip) {
            QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
            QModelIndex index = indexAt(helpEvent->pos());
            if (index.isValid()) {
                  QSize sizeHint = itemDelegate(index)->sizeHint(viewOptions(), index);
                  QRect rItem(0, 0, sizeHint.width(), sizeHint.height());
                  QRect rVisual = visualRect(index);
                  if (rItem.width() <= rVisual.width()) {
                        QToolTip::hideText();
                        return false;
                        }
                  }
            }

      return QTableView::viewportEvent(event);
}
Пример #6
0
void CMDITabsDialogBar::DrawItemBorder(LPDRAWITEMSTRUCT lpdis)
{
	BOOL bSelected = (lpdis->itemID == (UINT)GetCurSel());
    BOOL bBackTabs = FALSE;

	CRect rItem(lpdis->rcItem);
	CDC* pDC = CDC::FromHandle(lpdis->hDC); 

	if (bSelected || bBackTabs)
	{
		rItem.bottom += bSelected ? -1 : 1;
		// edges
        pDC->FillRect(CRect(rItem.left, rItem.top, rItem.left + 1, rItem.bottom), &g_PaintManager->m_brushLightestDefault);
		pDC->FillRect(CRect(rItem.left, rItem.top, rItem.right, rItem.top + 1), &g_PaintManager->m_brushLightestDefault);
		pDC->FillRect(CRect(rItem.right - 1, rItem.top, rItem.right, rItem.bottom), &g_PaintManager->m_brushDarkestDefault);
	}
	else // draw simple dividers
	{
		pDC->FillRect(CRect(rItem.left - 1, rItem.top, rItem.left, rItem.bottom), &g_PaintManager->m_brushDarkestDefault);
		pDC->FillRect(CRect(rItem.right - 1, rItem.top, rItem.right, rItem.bottom), &g_PaintManager->m_brushDarkestDefault);
	}
}
void CPreferencesShortcutsPage::OnTreeCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMCUSTOMDRAW* pNMCD = (NMCUSTOMDRAW*)pNMHDR;

	if (pNMCD->dwDrawStage == CDDS_PREPAINT)
		*pResult |= CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT;	
		
	else if (pNMCD->dwDrawStage == CDDS_ITEMPREPAINT)
	{
		NMTVCUSTOMDRAW* pTVCD = (NMTVCUSTOMDRAW*)pNMCD;

		// set colors
		HTREEITEM hti = (HTREEITEM)pTVCD->nmcd.dwItemSpec;

		if (m_tcCommands.ItemHasChildren(hti)) // popup menu
		{
			CRect rItem, rText;
			m_tcCommands.GetItemRect(hti, rItem, FALSE);
			m_tcCommands.GetItemRect(hti, rText, TRUE);
			rItem.left = rText.left - 2;

			CDC* pDC = CDC::FromHandle(pNMCD->hdc);
			pDC->FillSolidRect(rItem, GetSysColor(COLOR_3DSHADOW));
			pDC->SetBkMode(TRANSPARENT);

			pTVCD->clrTextBk = GetSysColor(COLOR_3DSHADOW);
			pTVCD->clrText = 0;

			*pResult |= CDRF_NEWFONT;
		}
		else if (pNMCD->uItemState & CDIS_SELECTED)
		{
			pTVCD->clrTextBk = GetSysColor(COLOR_HIGHLIGHT);
			pTVCD->clrText = GetSysColor(COLOR_HIGHLIGHTTEXT);

			*pResult |= CDRF_NEWFONT;
		}
		else // test for reserved shortcut
		{
			DWORD dwShortcut = 0;
			UINT nCmdID = pTVCD->nmcd.lItemlParam;
			m_mapID2Shortcut.Lookup(nCmdID, dwShortcut);

			if (CToDoCtrl::IsReservedShortcut(dwShortcut) && !IsMiscCommandID(nCmdID))
			{
				pTVCD->clrText = 255;
				*pResult |= CDRF_NEWFONT;
			}
		}
	}
	else if (pNMCD->dwDrawStage == CDDS_ITEMPOSTPAINT)
	{
		CDC* pDC = CDC::FromHandle(pNMCD->hdc);
		NMTVCUSTOMDRAW* pTVCD = (NMTVCUSTOMDRAW*)pNMCD;

		CRect rItem(pNMCD->rc);
		rItem.top = rItem.bottom - 1;

		// if the bottom of the text coincides with the bottom of the 
		// item and we have the then take care not to draw over the focus rect
		if (pNMCD->uItemState & CDIS_FOCUS)
		{
			HTREEITEM hti = (HTREEITEM)pTVCD->nmcd.dwItemSpec;

			CRect rText;
			m_tcCommands.GetItemRect(hti, rText, TRUE);

			if (rText.bottom == rItem.bottom)
			{
				pDC->FillSolidRect(rItem.left, rItem.bottom - 1, rText.left - rItem.left, 1, OTC_GRIDCOLOR);
				pDC->FillSolidRect(rText.right, rItem.bottom - 1, rItem.right - rText.right, 1, OTC_GRIDCOLOR);
			}
			else
				pDC->FillSolidRect(rItem, OTC_GRIDCOLOR);
		}
		else
			pDC->FillSolidRect(rItem, OTC_GRIDCOLOR);
	}
}
Пример #8
0
BOOL GraphicsMisc::FillItemRect(CDC* pDC, LPCRECT prcItem, COLORREF color, HWND hwnd)
{
	CRect rItem(prcItem);
	return FillItemRect(pDC, rItem, color, NULL);
}