Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - CXTPControlBomboBox bug with Manual Updat
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPControlBomboBox bug with Manual Updat

 Post Reply Post Reply
Author
Message
vladsch View Drop Down
Newbie
Newbie


Joined: 04 February 2004
Location: Canada
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote vladsch Quote  Post ReplyReply Direct Link To This Post Topic: CXTPControlBomboBox bug with Manual Updat
    Posted: 28 March 2004 at 11:25am

Bug occurs if the CXTPControlComboBox control is set to manual update and SetDropDownListStyle(false).

To duplicate modify the CustomThemes sample to create a manual update combobox (make sure to delete the saved toolbars from the registry otherwise the old stored non-manual control will be used)

1. drop the list by clicking on the combobox
2. move the mouse so that an item is highlighted (other than the currently selected item)
3. click outside the list box so that the list box is closed without any selection being made. 

The combo box repaints with the new item even though it was not selected. Moving the mouse over the combobox causes it to repaint with the correct content.

The problem is caused during repaint while the list is dropped. The current selection for the list changes to follow the mouse movements so when GetText() method for the combobox is called from OnPaint while the list is dropped it uses the list's current selection to extract the string which will be the last hovered over item instead of the last selected item.

The solution that I used was to store the last selected item before poping up the list and restoring it when the popup is closed. This stored selection is modifed to the new selection in the OnSetSelected and OnExecute so that restoring the last selected value will not undo the new selection.

new or changed code is bold

CXTPControlComboBox.h add a new protected members to CXTPControlComboBox


    // Input:   bPopup - TRUE to set popup.
    // Returns: TRUE if successful; otherwise returns FALSE
    // Summary: This method is called to popup the control.
    virtual BOOL OnSetPopup(BOOL bPopup);

    // Summary: This method is called when the control is executed.
    virtual void OnExecute();

    int m_nLastSel;      // last user selected index, (used during display of list box)

in CXTPControlComboBox.cpp

in the Constructor Clear the new member to -1, not really needed but good practice


    m_nLastSel = -1;

Change/Add the following functions:


CString CXTPControlComboBox::GetText()
{
    int nSel = GetDroppedState() ? m_nLastSel : ((CListBox*)m_pCommandBar)->GetCurSel();
    CString str;
    if (nSel >= 0)
    ((CListBox*)m_pCommandBar)->GetText(nSel, str);
    return str;
}

void CXTPControlComboBox::OnSelChanged()
{
    m_nLastSel = GetCurSel();

    if (m_pEdit && m_pEdit->GetSafeHwnd()) m_pEdit->SetWindowText(GetText()); else m_strEditText = GetText();
    if (m_pParent && m_pParent->GetSafeHwnd()) m_pParent->Invalidate(FALSE);
}

BOOL CXTPControlComboBox::OnSetPopup(BOOL bPopup)
{
    if (bPopup)
    {
        m_nLastSel = GetCurSel();
    }
    else
    {
        SetCurSel(m_nLastSel);
    }

    return CXTPControlPopup::OnSetPopup(bPopup);
}

void CXTPControlComboBox::OnExecute()
{
    m_nLastSel = GetCurSel();
    CXTPControlPopup::OnExecute();
}

 



Edited by vladsch
Back to Top
vladsch View Drop Down
Newbie
Newbie


Joined: 04 February 2004
Location: Canada
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote vladsch Quote  Post ReplyReply Direct Link To This Post Posted: 28 March 2004 at 1:56pm
Edited original post to add a call to base class in OnExecute.
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.141 seconds.