Print Page | Close Window

Bug in office 2013 tooltips + solution

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=22213
Printed Date: 24 November 2024 at 7:49am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Bug in office 2013 tooltips + solution
Posted By: Michl
Subject: Bug in office 2013 tooltips + solution
Date 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




Replies:
Posted By: astoyan
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net