Print Page | Close Window

CXTPControlComboBox and ListBox Tooltip

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=8268
Printed Date: 07 October 2024 at 12:25pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPControlComboBox and ListBox Tooltip
Posted By: jimmy
Subject: CXTPControlComboBox and ListBox Tooltip
Date Posted: 02 October 2007 at 12:37pm
Hello,

Is there a way to set a tooltip Text for the CXTPControlComboBox ListBox ?
Not a LabelTip.
Like this



  Jimmy



Replies:
Posted By: Simon HB9DRV
Date Posted: 02 October 2007 at 1:31pm
Originally posted by jimmy jimmy wrote:

Hello,

Is there a way to set a tooltip Text for the CXTPControlComboBox ListBox ?
Not a LabelTip.
Like this



  Jimmy
 
Now that would be magic! Come on Oleg, we know you can do it :-)


-------------
Simon HB9DRV


Posted By: jimmy
Date Posted: 04 October 2007 at 6:32am
Hallo,

Found solution

class CExControlComboBoxList : public CXTPControlComboBoxList
{
public:
    void CreateListBox() { __super::CreateListBox(); };

    virtual ~CExControlComboBoxList()
    {
        if (m_pToolTipContext)
            CMDTARGET_RELEASE(m_pToolTipContext);
    }

    void InitTooltip(LPCTSTR lpTitle)
    {
        m_ToolTipContext.ModifyToolTipStyle(TTS_NOPREFIX, 0);
        m_ToolTipContext.ShowImage(FALSE);
        SetTooltipTitle(lpTitle);

        m_pToolTipContext = &m_ToolTipContext;
        CMDTARGET_ADDREF(m_pToolTipContext);
    }
    void SetTooltipTitle(LPCTSTR lpTitle)
    {
        if (lpTitle && *lpTitle)
        {
            m_strTitle = lpTitle;
            m_ToolTipContext.ShowTitleAndDescription(TRUE);
        }
        else
            m_ToolTipContext.ShowTitleAndDescription(FALSE);
    }
    virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const
    {
        int iSel = GetCurSel();
        if (iSel >= 0)
        {
            CString strText;
            GetText(iSel, strText);
            TSSMap::const_iterator itr = m_mapTooltipText.find(strText);
            if (itr != m_mapTooltipText.end())
            {
                CXTPToolTipContext::FillInToolInfo(pTI, m_hWnd, CRect(0,0,200,50), iSel, itr->second, m_strTitle, itr->second, NULL);
                return iSel;
            }
        }
        return -1;
    }
    void AddTooltipText(const CString& strText, const CString& strTooltip)
    {
        m_mapTooltipText[strText] = strTooltip;
    }
    CXTPToolTipContext *GetToolTipContext() {
        return m_pToolTipContext;
    }
protected:
    typedef std::map<CString,CString> TSSMap;
    TSSMap m_mapTooltipText;
    CXTPToolTipContext m_ToolTipContext;
    CString m_strTitle;
};

class CExControlComboBox : public CXTPControlComboBox
{
public:
    CExControlComboBox()
    {
        if (m_pCommandBar)
            m_pCommandBar->InternalRelease();

        m_pCommandBar = new CExControlComboBoxList();
        GetExControlList()->CreateListBox();
    };

    CExControlComboBoxList *GetExControlList()    { return ((CExControlComboBoxList*)m_pCommandBar); }

    CXTPToolTipContext *GetToolTipContext() {
        GetExControlList()->GetToolTipContext();
    }
    void InitTooltip(LPCTSTR lpTitle = NULL) {
        GetExControlList()->InitTooltip(lpTitle);
    }
    void AddString(const CString& strText, const CString& strTooltip)
    {
        GetExControlList()->AddTooltipText(strText, strTooltip);
        __super::AddString(strText);
    }
    DECLARE_XTP_CONTROL(CExControlComboBox)
};

IMPLEMENT_XTP_CONTROL(CExControlComboBox, CXTPControlComboBox)

And in OnCreateControl

            CExControlComboBox* pComboUrl = (CExControlComboBox*)CExControlComboBox::CreateObject();
            pComboUrl->InitTooltip("Title");
            pComboUrl->AddString(_T("http://www.codejock.com"), "Mein Tooltip 1");
            pComboUrl->AddString(_T("ms-help://MS.VSCC/vsccCommon/html/vsccCommon_Start_Page.htm"), "Mein Tooltip 2" );


But some questions.

1) Better solution to store info Tooltiptext / Entry (i don't like use SetItemData)

2) Tooltip only show inside red border and wrong tooltip is show on green line position.



3) Can you add this function to new version ?

4) What can i make better inthis solution ?

    Jimmy



Posted By: Oleg
Date Posted: 05 October 2007 at 3:32am
Hi,
 
Nice solution.
 
May be only need add
DECLARE_XTP_COMMANDBAR/IMPLEMENT_XTP_COMMANDBAR for List
and instead predefined CRect(0,0,200,50), use
 
CRect rc;
GetListBoxCtrl()->GetItemRect(iSel, rc);
Think also need to add Save/Load tooltips for customization. See DOPropExchange method.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: jimmy
Date Posted: 05 October 2007 at 9:28am
1) better solution ?

2) red border ok, but Tooltip does not work correkt on 2 pixel width between
2 entrys (green line).

3) can add to next Codejock version ?

4) Ok

    Jimmy




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