Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtBarTextFieldButton m_nDropDownWidth automatic to max text size in listbox Collapse All
Subject Author Date
Stephan Finkler Nov 3, 2005 - 9:46 AM

Hi,

how can I set the drop down width of a combo field in a toolbar to the max. text width in the list box?
In CExtBarTextFieldButton::OnPopupListBoxMeasureTrackSize there is a call to CExtPaintManager::stat_CalcTextDimension
but it does not reach this..the function returns before because int nCount = m_arrLbItems.GetSize(); = 0

Any idea?


Technical Support Nov 4, 2005 - 2:06 AM

The CExtCmdItem::m_nDropDownWidth property specifies a width of the drop-down popup list box, in pixels, for the combo field command. If you set it to -1, then the width will always be calculated according to the list box content. By default, this value is -2 which means that the combo field area is used. So, get a pointer to the appropriate CExtCmdItem object by the command field identifier and set the drop-down list box width to -1:

CExtCmdItem * pCmdItem =
        g_CmdManager->CmdGetPtr( ..., ID_COMBO_FIELD_COMMAND );
    pCmdItem->m_nDropDownWidth = -1;
Please note that each CExtCustomizeCmdTreeNode stores a copy of this value. You need to clean your app state in the registry to see the result.

Stephan Finkler Nov 4, 2005 - 2:29 AM

I think CExtBarTextFieldButton::OnPopupListBoxMeasureTrackSize is responsible for that.
But this is not working in my app because

int nCount = m_arrLbItems.GetSize();

nCount is always 0.

So the function returns always with the default value     CSize sizeCalc( 150, 100 );

Do I have to fill the m_arrLbItems array?

What do I have to do to solve this problem?




Technical Support Nov 4, 2005 - 7:46 AM

Yes, you are right. The CExtBarTextFieldButton::OnPopupListBoxMeasureTrackSize() method doesn’t automatically detect the width of the drop-down menu if no items exist (m_arrLbItems.GetSize() == 0). And t is fully understandable: You cannot determine the maximum text width if there is no text at all.

Please note, the CExtBarTextFieldButton::OnPopupListBoxMeasureTrackSize() method is called every time just before the popup list is shown. So you need to add items. If your application is customizable (CMainFrame derived from CExtCustomizeSite) you need to override the CExtCustomizeSite::OnPopupListBoxInitContent() method and fill the list. You can also override CExtCustomizeSite::OnPopupListBoxMeasureTrackSize() to perform your own calculation of size of the popup list box. All these features are implemented in the StyleEditor sample (the Font, Size and Style combo fields).

Stephan Finkler Nov 4, 2005 - 7:56 AM

Yes, my app is customizable and the CExtCustomizeSite::OnPopupListBoxInitContent() is called to fill the list.

The problem is that CExtCustomizeSite::OnPopupListBoxInitContent() is called after CExtBarTextFieldButton::OnPopupListBoxMeasureTrackSize().

Is this rigth?

Technical Support Nov 4, 2005 - 9:19 AM

If your application is customizable, it does not matter when CExtCustomizeSite::OnPopupListBoxMeasureTrackSize() is called, because you always need to override this method to set the popup list box’s size if it is necessary. The m_arrLbItems array is only used in non-customizable applications. Please take a look at the CMainFrame::OnPopupListBoxMeasureTrackSize() and CMainFrame::OnPopupListBoxInitContent() methods in the StyleEditor sample.