Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Controls
  New Posts New Posts RSS Feed - Bug in office 2013 tooltips + solution
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Bug in office 2013 tooltips + solution

 Post Reply Post Reply
Author
Message
Michl View Drop Down
Senior Member
Senior Member


Joined: 14 September 2007
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Michl Quote  Post ReplyReply Direct Link To This Post Topic: Bug in office 2013 tooltips + solution
    Posted: 20 February 2014 at 6:09am
Hello

Titles are truncated if description is very short.
Your can reproduce it easy in calendar sample! Just switch to office 2013 style and change the description of a ribbon button to a short text.



Please move Tooltip-Classes from .cpp to .h! So it's not possible to derive class to fix it myself.

-------------------------------------------------------------------------------------------------------------------------

Because codejock don't unlock my solution for other users Angry, I will attach my solution to this thread.

.h

class CXTPBugfixedToolTipContext : public CXTPToolTipContext
{
    class CBugfixedOffice2013ToolTip;
    friend CBugfixedOffice2013ToolTip;

    public:
        virtual CWnd* CreateToolTip(CWnd* pOwner);
};



.cpp

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);
}


Enjoy! Wink

Back to Top
astoyan View Drop Down
Admin Group
Admin Group
Avatar

Joined: 24 August 2013
Status: Offline
Points: 304
Post Options Post Options   Thanks (0) Thanks(0)   Quote astoyan Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2014 at 10:00pm
Hello Michl,

Thank you for the proposed solution. We have applied your changes. The fix will be available in the next beta release.

Thank you.
Regards,
  Alexander Stoyan
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.143 seconds.