lafe @ ウィキ
メニュー

作成したソフトウェア






プログラムtip



合計: -
今日: -
昨日: -


TabCtrlItem


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

class CTabCtrlItem {
public:
	// Data members
	BYTE		m_fsState;
	CString 	m_strItem;		// string on button
	CRect		m_rcItem;
	int 		m_nImgIndex;	// image list index
	DWORD_PTR	m_dwUser;		// user's data 
 
private:
	// Constants
	enum { s_kcxIconGap = 2 };
 
public:
	// Constructor/destructor
	CTabCtrlItem(const CString &strBtn = CString(), int nImgIndex = -1, DWORD_PTR dwUser = 0, BYTE fsState = TCISTATE_ENABLED)
		: m_fsState(fsState)
		, m_strItem(strBtn)
		, m_nImgIndex(nImgIndex)
		, m_dwUser(dwUser)
	{
		m_rcItem.SetRectEmpty();
	}
 
 
	// Attributes
	bool ModifyState(BYTE fsRemove, BYTE fsAdd)
	{
		BYTE fsStateOld = m_fsState;
 
		m_fsState = (m_fsState & ~fsRemove) | fsAdd;
 
		if ( (fsStateOld & TCISTATE_SELECTED || fsStateOld & TCISTATE_MSELECTED)
		   && (fsRemove == TCISTATE_HOT || fsAdd == TCISTATE_HOT) ) 	// selected, no need to update
			return false;
		else
			return m_fsState != fsStateOld;
	}
 
 
	// Methods
	void Update(CDCHandle dc, HIMAGELIST hImgList, bool bAnchorColor, CTabSkin *pTabSkin)
	{
		if (m_fsState & TCISTATE_HIDDEN)
			return;
 
		int    cxIcon		= 0, cyIcon = 0;
		int    cxIconOffset = 0;
 
		if (m_nImgIndex != -1) {
			::ImageList_GetIconSize(hImgList, &cxIcon, &cyIcon);
			cxIconOffset += cxIcon + s_kcxIconGap * 2;
		}
 
		bool   bHot 		= (m_fsState & TCISTATE_HOT) != 0;
		bool   bPressed 	= (m_fsState & TCISTATE_PRESSED) != 0;
 
		CPoint ptOffset(0, 0);
 
		if (m_fsState & TCISTATE_SELECTED) {							// now selected
			Update_Selected(dc, pTabSkin, bHot, bPressed);
			ptOffset += CPoint(2, 2);
		} else if (m_fsState & TCISTATE_MSELECTED) {					// multi-selected
			Update_MultiSel(dc, pTabSkin, bHot, bPressed);
			ptOffset += CPoint(2, 2);
		} else {														// not selected
			Update_NotSel(dc, pTabSkin, bHot, bPressed, ptOffset);
		}
 
		_DrawText(dc, ptOffset + CPoint(cxIconOffset, 0), bAnchorColor, pTabSkin);
 
		if (m_nImgIndex != -1) {
			::ImageList_Draw(hImgList, m_nImgIndex, dc, m_rcItem.left + ptOffset.x + s_kcxIconGap,
							 m_rcItem.top  + (m_rcItem.Height() - cyIcon) / 2 + ptOffset.y / 2, ILD_TRANSPARENT);
		}
	}
 
 
private:
	void Update_Selected(CDCHandle dc, CTabSkin *pTabSkin, BOOL bHot, BOOL bPressed)
	{
		if (bHot && bPressed) {
			//選択・スキンなし
			if (pTabSkin->IsVisible() == FALSE) {
				COLORREF crTxt = dc.SetTextColor(pTabSkin->m_colBtnFace);
				COLORREF crBk  = dc.SetBkColor(pTabSkin->m_colBtnHi);
				CBrush	 hbr( CDCHandle::GetHalftoneBrush() );
				dc.SetBrushOrg(m_rcItem.left, m_rcItem.top);
				dc.FillRect(m_rcItem, hbr);
				dc.SetTextColor(crTxt);
				dc.SetBkColor(crBk);
				dc.DrawEdge(m_rcItem, BDR_RAISEDINNER, BF_RECT);
			} else {
				pTabSkin->DrawSkinCur(dc.m_hDC, m_rcItem);
			}
		} else {														// ignored hot
			if (pTabSkin->IsVisible() == FALSE) {
				TCTRACE( _T(" draw selected(checked) button\n") );
				COLORREF crTxt = dc.SetTextColor(pTabSkin->m_colBtnFace);
				COLORREF crBk  = dc.SetBkColor(pTabSkin->m_colBtnHi);
				CBrush	 hbr( CDCHandle::GetHalftoneBrush() );
				dc.SetBrushOrg(m_rcItem.left, m_rcItem.top);
				dc.FillRect(m_rcItem, hbr);
				dc.SetTextColor(crTxt);
				dc.SetBkColor(crBk);
				dc.DrawEdge(m_rcItem, EDGE_SUNKEN, BF_RECT);
			} else {
				pTabSkin->DrawSkinCur(dc.m_hDC, m_rcItem);
			}
		}
	}
 
 
	void Update_MultiSel(CDCHandle dc, CTabSkin *pTabSkin, BOOL bHot, BOOL bPressed)
	{
		if (pTabSkin->IsVisible() == FALSE) {
			if (bHot && bPressed)
				dc.DrawEdge(m_rcItem, BDR_RAISEDINNER, BF_RECT);
			else
				dc.DrawEdge(m_rcItem, EDGE_SUNKEN, BF_RECT);
		} else {
			pTabSkin->DrawSkinSel(dc.m_hDC, m_rcItem);
		}
	}
 
 
	void Update_NotSel(CDCHandle dc, CTabSkin *pTabSkin, BOOL bHot, BOOL bPressed, CPoint &ptOffset)
	{
		if (pTabSkin->IsVisible() == FALSE) {
			if (bHot && bPressed) {
				dc.DrawEdge(m_rcItem, BDR_RAISEDINNER, BF_RECT);		// hot
				ptOffset += CPoint(2, 2);								// sunk a little
			} else if (bHot && !bPressed) {
				dc.DrawEdge(m_rcItem, BDR_RAISEDINNER, BF_RECT);		// hot
			}
		} else {
			if (bHot && !bPressed) {
				pTabSkin->DrawSkinSel(dc.m_hDC, m_rcItem);
				//				ptOffset += CPoint(2, 2);
			} else {
				pTabSkin->DrawSkinNone(dc.m_hDC, m_rcItem);
			}
		}
	}
 
 
	// Implementation
	void _DrawText(CDCHandle dc, CPoint ptOffset, bool bAnchorColor, CTabSkin *pTabSkin)
	{
		COLORREF clr;
 
		if ( !(m_fsState & TCISTATE_ENABLED) )
			clr = pTabSkin->m_colDisable;
		else if (m_fsState & TCISTATE_INACTIVE)
			clr = bAnchorColor ? pTabSkin->m_colInActive : pTabSkin->m_colText;
		else
			clr = bAnchorColor ? pTabSkin->m_colActive : pTabSkin->m_colText;
 
		COLORREF clrOld = dc.SetTextColor(clr);
 
		CRect	 rcBtn(m_rcItem.left + ptOffset.x, m_rcItem.top + ptOffset.y, m_rcItem.right, m_rcItem.bottom);
		rcBtn.DeflateRect(2, 0);
 
		UINT	 uFortmat;
		int 	 nWidth = MtlComputeWidthOfText( m_strItem, dc.GetCurrentFont() );
 
		if ( nWidth > rcBtn.Width() )
			uFortmat = DT_LEFT | DT_END_ELLIPSIS;
		else
			uFortmat = DT_CENTER | DT_NOCLIP;
 
		if ( !(m_fsState & TCISTATE_ENABLED) ) {
			// disabled - draw shadow text shifted down and right 1 pixel (unles selected)
			CRect	 rcDisabled = rcBtn + CPoint(1, 1);
			COLORREF clrOld2	= dc.SetTextColor(pTabSkin->m_colDisableHi);
			dc.DrawText(m_strItem, -1, rcDisabled, DT_SINGLELINE | uFortmat | DT_VCENTER | DT_NOPREFIX);
			dc.SetTextColor(clrOld2);
		}
 
		dc.DrawText(m_strItem, -1, rcBtn, DT_SINGLELINE | uFortmat | DT_VCENTER | DT_NOPREFIX);
		dc.SetTextColor(clrOld);
	}
 
 
	void DrawHot(CDCHandle dc)
	{
		dc.DrawEdge(m_rcItem, BDR_RAISEDINNER, BF_RECT);
	}
 
 
	void DrawPressed(CDCHandle dc)
	{
		dc.DrawEdge(m_rcItem, EDGE_SUNKEN, BF_MIDDLE);
	}
 
 
	void DrawSelected(CDCHandle dc)
	{
		dc.DrawEdge(m_rcItem, EDGE_SUNKEN, BF_RECT);
	}
};
 
 
何かあれば【 こちら 】まで問い合わせください

更新履歴

取得中です。