示例#1
0
int  CSHeaderCtrl::DrawSortImage(CDC* pDC, const CRect& rect, LPHDITEM lphdi)
{
	int iWidth = 0;
	
	if (rect.Width() > 0)
	{
		UINT nSortIndex = SHC_STATE_TO_INDEX_SORT(lphdi->iImage);
		CImageList* pImageList = GetImageList();
		if(nSortIndex != SHC_NONE_SORT && pImageList != NULL)
		{
			POINT point;
			point.y = rect.CenterPoint().y - ((m_sizeImage.cy+1) >> 1);
			point.x = rect.left;
			
			SIZE size;
			size.cx = rect.Width() < m_sizeImage.cx ? rect.Width() : m_sizeImage.cx;
			size.cy = m_sizeImage.cy;
			
			// save image list background color
			COLORREF rgb = pImageList->GetBkColor();
			
			// set image list background color to same as header control
			pImageList->DrawIndirect(pDC, GetIndexOfImageList(nSortIndex), point, size, CPoint(0, 0));
			
			iWidth = size.cx;
		}
示例#2
0
// @pymethod int|PyCImageList|GetBkColor|Retrieves the background color of an Image List.
PyObject *PyCImageList_GetBkColor( PyObject *self, PyObject *args )
{
	CImageList *pList;
	if (!(pList=PyCImageList::GetImageList(self)))
		return NULL;
	CHECK_NO_ARGS2(args, "GetBkColor");
	GUI_BGN_SAVE;
	int rc = pList->GetBkColor();
	GUI_END_SAVE;
	return Py_BuildValue("i", rc);
}
示例#3
0
///////////////////////////////////////////////////////////////////////////////
// DrawImage
int CXHeaderCtrl::DrawImage(CDC* pDC, CRect rect, LPHDITEM lphdi, BOOL bRight)
{
	CImageList* pImageList = GetImageList();
	int iWidth = 0;

	if (lphdi->iImage != XHEADERCTRL_NO_IMAGE)
	{
		if (pImageList)
		{
			if (rect.Width() > 0)
			{
				POINT point;

				point.y = rect.CenterPoint().y - (m_sizeImage.cy >> 1);

				if (bRight)
					point.x = rect.right - m_sizeImage.cx;
				else
					point.x = rect.left;

				SIZE size;
				size.cx = rect.Width()<m_sizeImage.cx ? rect.Width():m_sizeImage.cx;
				size.cy = m_sizeImage.cy;

				// save image list background color
				COLORREF rgb = pImageList->GetBkColor();

				// set image list background color to same as header control
				pImageList->SetBkColor(pDC->GetBkColor());
				pImageList->DrawIndirect(pDC, lphdi->iImage, point, size, CPoint(0, 0));
				pImageList->SetBkColor(rgb);

				iWidth = m_sizeImage.cx;
			}
		}
	}
//------------------------------------------------------------------------
//! Appends the checkbox state images to the list control image list
//!
//! @param owner The list control adding column
//! @param imagelist The image list assigned to the list control
//! @return Image index where the two state images (unchecked/checked) was inserted
//------------------------------------------------------------------------
int CGridColumnTraitImage::AppendStateImages(CGridListCtrlEx& owner, CImageList& imagelist)
{
	if (!(owner.GetExtendedStyle() & LVS_EX_SUBITEMIMAGES))
		owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_SUBITEMIMAGES);

	if (!imagelist)
		imagelist.Create(16, 16, ILC_COLOR16 | ILC_MASK, 1, 0);

	if (!owner.GetImageList(LVSIL_SMALL))
		owner.SetImageList(&imagelist, LVSIL_SMALL);

	VERIFY(owner.GetImageList(LVSIL_SMALL) == &imagelist);

	bool createdStateImages = false;
	CImageList* pStateList = owner.GetImageList(LVSIL_STATE);
	if (pStateList == NULL)
	{
		if (!(owner.GetExtendedStyle() & LVS_EX_CHECKBOXES))
		{
			createdStateImages = true;
			owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_CHECKBOXES);
			pStateList = owner.GetImageList(LVSIL_STATE);
		}
	}
	int imageCount = -1;
	ASSERT(pStateList != NULL);
	if (pStateList != NULL && pStateList->GetImageCount() >= 2)
	{
		imageCount = imagelist.GetImageCount();

		// Get the icon size of current imagelist
		CSize iconSize(16, 16);
		if (imageCount > 0)
		{
			IMAGEINFO iconSizeInfo = { 0 };
			VERIFY(imagelist.GetImageInfo(0, &iconSizeInfo));
			iconSize =
				CSize(iconSizeInfo.rcImage.right - iconSizeInfo.rcImage.left,
					iconSizeInfo.rcImage.bottom - iconSizeInfo.rcImage.top);
		}

		// Scale the icon-position if necessary
		CPoint iconPos(1, 0); // +1 pixel to avoid overlap with left-grid-line
		{
			IMAGEINFO stateSizeInfo = { 0 };
			VERIFY(pStateList->GetImageInfo(0, &stateSizeInfo));
			int stateIconHeight = stateSizeInfo.rcImage.bottom - stateSizeInfo.rcImage.top;
			if (iconSize.cy > stateIconHeight)
				iconPos.y = (iconSize.cy - stateIconHeight) / 2;
		}

		// Redraw the state-icon to match the icon size of the current imagelist (without scaling image)
		CClientDC clienDC(&owner);
		CDC memDC;
		VERIFY(memDC.CreateCompatibleDC(&clienDC));
		CBitmap dstBmp;
		VERIFY(dstBmp.CreateCompatibleBitmap(&clienDC, iconSize.cx, iconSize.cy));

		CBitmap* pBmpOld = memDC.SelectObject(&dstBmp);
		COLORREF oldBkColor = pStateList->SetBkColor(imagelist.GetBkColor());
		CBrush brush(imagelist.GetBkColor());
		memDC.FillRect(CRect(0, 0, iconSize.cx, iconSize.cy), &brush);
		VERIFY(pStateList->Draw(&memDC, 0, iconPos, ILD_NORMAL));
		memDC.SelectObject(pBmpOld);
		VERIFY(imagelist.Add(&dstBmp, oldBkColor) != -1);
		pBmpOld = memDC.SelectObject(&dstBmp);
		memDC.FillRect(CRect(0, 0, iconSize.cx, iconSize.cy), &brush);
		VERIFY(pStateList->Draw(&memDC, 1, iconPos, ILD_NORMAL));
		memDC.SelectObject(pBmpOld);
		VERIFY(imagelist.Add(&dstBmp, oldBkColor) != -1);
		pStateList->SetBkColor(oldBkColor);
	}
	if (createdStateImages)
		owner.SetExtendedStyle(owner.GetExtendedStyle() & ~LVS_EX_CHECKBOXES);

	return imageCount;
}