class CXTPBugfixedToolTipContext::CBugfixedOffice2013ToolTip : public CXTPToolTipContextToolTip { public: CBugfixedOffice2013ToolTip(CXTPToolTipContext* pContext) : CXTPToolTipContextToolTip(pContext) { }
protected: virtual CSize GetToolSize(TOOLITEM* lpToolInfo); virtual void DrawBackground(CDC* pDC, TOOLITEM* lpToolInfo, CRect rc); virtual void DrawEntry(CDC* pDC, TOOLITEM* lpToolInfo, CRect rc); };
CSize CXTPBugfixedToolTipContext::CBugfixedOffice2013ToolTip::GetToolSize(TOOLITEM* lpToolInfo) { CClientDC dc(this);
CXTPBugfixedToolTipContext* pFriendContext = static_cast<CXTPBugfixedToolTipContext*>(m_pContext);
CFont* pOldFont = dc.SelectObject(&pFriendContext->m_fnt);
CString str = GetToolText(lpToolInfo);
if (str.IsEmpty()) { dc.SelectObject(pOldFont); return CSize(0); }
int nMaxTipWidth = GetMaxTipWidth(); BOOL bDrawTitle = !m_strTitle.IsEmpty();
CRect rcMargin = m_pContext->GetMargin(); CSize szMargin; if (bDrawTitle) { szMargin.cx = 12 + rcMargin.left + rcMargin.right + 12; szMargin.cy = 7 + rcMargin.top + rcMargin.bottom + 7; } else { szMargin.cx = 5 + rcMargin.left + rcMargin.right + 5; szMargin.cy = 5 + rcMargin.top + rcMargin.bottom + 5; }
DWORD dwFlags = DT_NOPREFIX | DT_EXPANDTABS;
CSize szTitle(0, 0);
if (bDrawTitle) { CXTPFontDC fntTitle(&dc, &pFriendContext->m_fntTitle);
CRect rcTitle(0, 0, 0, 0); dc.DrawText(m_strTitle, rcTitle, dwFlags | DT_CALCRECT | DT_SINGLELINE);
szTitle = CSize(rcTitle.Width(), rcTitle.Height() + 6); }
CRect rcText(0, 0, nMaxTipWidth - szMargin.cx, 0);
if (bDrawTitle && szTitle.cx > nMaxTipWidth) szTitle.cx = nMaxTipWidth;
dc.DrawText(str, rcText, dwFlags | DT_CALCRECT | DT_WORDBREAK); dc.SelectObject(pOldFont);
CSize szText = rcText.Size();
CSize sz = szText; if (bDrawTitle) { sz.cx = max(sz.cx, szTitle.cx); sz.cy += szTitle.cy; }
sz.cx += szMargin.cx; sz.cy += szMargin.cy; return sz; }
void CXTPBugfixedToolTipContext::CBugfixedOffice2013ToolTip::DrawBackground(CDC* pDC, TOOLITEM* /*lpToolInfo*/, CRect rc) { pDC->FillSolidRect(&rc, RGB(0xff, 0xff, 0xff));
const COLORREF clrBorder = RGB(190, 190, 190); pDC->Draw3dRect(rc, clrBorder, clrBorder); }
void CXTPBugfixedToolTipContext::CBugfixedOffice2013ToolTip::DrawEntry(CDC* pDC, TOOLITEM* lpToolInfo, CRect rc) { CXTPBugfixedToolTipContext* pFriendContext = static_cast<CXTPBugfixedToolTipContext*>(m_pContext);
CString str = lpToolInfo->strCaption;
rc.DeflateRect(m_pContext->GetMargin());
DWORD dwFlags = DT_NOPREFIX | DT_EXPANDTABS; BOOL bLayoutRTL = lpToolInfo->hwnd && GetWindowLong(lpToolInfo->hwnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL;
if (bLayoutRTL) { dwFlags |= DT_RTLREADING | DT_RIGHT; }
int clrTextOld = pDC->SetTextColor(RGB(93, 93, 93));
BOOL bDrawTitle = !m_strTitle.IsEmpty(); if (bDrawTitle) { rc.DeflateRect(12, 7, 12, 7);
CXTPFontDC fnt(pDC, &pFriendContext->m_fntTitle); CRect rcTitle(rc.left, rc.top, rc.right, rc.bottom); pDC->DrawText(m_strTitle, rcTitle, dwFlags | DT_SINGLELINE);
rc.top += pDC->GetTextExtent(m_strTitle).cy + 6; } else rc.DeflateRect(5, 5, 5, 5);
pDC->DrawText(str, rc, dwFlags | DT_WORDBREAK); pDC->SetTextColor(clrTextOld); }
CWnd* CXTPBugfixedToolTipContext::CreateToolTip(CWnd* pOwner) { if (m_toolStyle == xtpToolTipOffice2013) return new EXTPBugfixedToolTipContext::CBugfixedOffice2013ToolTip(this); else return __super::CreateToolTip(pOwner); }
|