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 General Discussion » Chevron button when required. Collapse All
Subject Author Date
ahmad hassan Jun 4, 2004 - 12:42 AM

Hello,


I want to have the Show/Hide Panels button in the right button of a toolbar removed and have the right button (chevron) only appear when there are toolbar buttons which are not visible. I was not able to find such a feature in your library.


Regards,


Ahmad.

Technical Support Jun 4, 2004 - 10:09 AM


Dear Ahmad,

To implement the auto-hidden chevron button, you should use a CExtBarContentExpandButton-derived class like this:

class CMyChevronButton : public CExtBarContentExpandButton {
public:
CMyChevronButton(
            CExtToolControlBar * pBar = NULL
            ) :
            CExtBarContentExpandButton(pBar)
{
}
virtual bool IsVisible() const
{
            if( m_buttons.GetSize() == 0 )
                        return false;
            return true;
}
}; // class CMyChevronButton

To use this chevron button class in your toolbars, create your own CExtToolControlBar-derived class like this:
class CMyToolBar : public CExtToolControlBar {
public:
virtual CExtBarContentExpandButton * OnCreateBarRightBtn()
{
            CExtBarContentExpandButton * pRightBtn =
                        new CMyChevronButton( this );
            ASSERT_VALID( pRightBtn );
            return pRightBtn;
}
}; // class CMyToolBar

Prof-UIS allows you to change or completely re-create any built-in popup menu including the chevron menu, control bar’s caption-button menu, control bar caption’s context menu, dockbar’s context menu. The Prof-Studio sample available in the trial and commercial versions demonstrates how to solve this task. You should handle the CExtControlBar::g_nMsgConstructPopupMenu registered Windows message in the main frame window:
ON_REGISTERED_MESSAGE( 
CExtControlBar::g_nMsgConstructPopupMenu, 
OnConstructPopupMenuCB )
 
LRESULT CMainFrame::OnConstructPopupMenuCB( 
WPARAM wParam, LPARAM lParam ) {
            ASSERT_VALID( this );
            lParam;
 
CExtControlBar::POPUP_MENU_EVENT_DATA * p_pmed =
CExtControlBar::POPUP_MENU_EVENT_DATA::FromWParam( wParam );
ASSERT( p_pmed != NULL );
ASSERT_VALID( p_pmed->m_pPopupMenuWnd );
ASSERT_VALID( p_pmed->m_pWndEventSrc );
ASSERT( p_pmed->m_pWndEventSrc->GetSafeHwnd() != NULL );
ASSERT( ::IsWindow(p_pmed->m_pWndEventSrc->GetSafeHwnd()) ); ...
}

The CExtControlBar::POPUP_MENU_EVENT_DATA structure describes the built-in menu, which you can construct or change. This message is sent twice for each built-in menu. Initially p_pmed->m_pPopupMenuWnd has no menu items at all. You can completely construct it and return TRUE if you do not want to receive the second notification. The second time the p_pmed->m_pPopupMenuWnd contains default menu items and you can remove any of them or add new items.


The p_pmed->m_nHelperNotificationType variable describes which menu is to be constructed (see the __PMED_... enumerated constants in the CExtControlBar::POPUP_MENU_EVENT_DATAstructure in ExtControlBar.h file).

ahmad hassan Jun 5, 2004 - 8:22 AM

Hello,


This thing is fine as long as you want the button to be not visible but its space still remains. I actually want toolbar to shrink as well if no buttons are there for right button. It should appear as soon as some button added to right button.


I have actually seen a post on the other forum but those classes donot work fine alway especially for the case of windows restore button press.


Regards,


Ahmad.

Technical Support Jun 7, 2004 - 7:08 AM

Dear Ahmad,

Here is the source code for the toolbar that you need:

class CMyToolBar : public CExtToolControlBar
{
    class CMyChevronButton : public CExtBarContentExpandButton
    {
    public:
        CMyChevronButton(
            CExtToolControlBar * pBar = NULL
            )
            : CExtBarContentExpandButton(pBar)
        {
        }
        virtual CSize CalculateLayout(
            CDC & dc,
            CSize sizePreCalc,
            BOOL bHorz
            )
        {
            if( GetStyle() & TBBS_HIDDEN )
                return CSize( 0, 0 );
            return CExtBarContentExpandButton::
                CalculateLayout(
                    dc, sizePreCalc, bHorz );
        }
        void _AdjustVisibility()
        {
            if( m_buttons.GetSize() == 0 )
                ModifyStyle( TBBS_HIDDEN );
            else
                ModifyStyle( 0, TBBS_HIDDEN );
        }
    };
public:
    virtual CExtBarContentExpandButton * OnCreateBarRightBtn()
    {
        CExtBarContentExpandButton * pRightBtn =
            new CMyChevronButton( this );
        ASSERT_VALID( pRightBtn );
        return pRightBtn;
    }
protected:
    CSize _CalcLayout(
        DWORD dwMode, int nLength = -1 )
    {
        CExtBarContentExpandButton *
            pRightButton = GetRightButton();
        if( pRightButton == NULL )
        {
            VERIFY( InitContentExpandButton() );
            pRightButton = GetRightButton();
            ASSERT( pRightButton != NULL );
        } // if( pRightButton == NULL )
        _RecalcPositionsImpl();
        CSize _sizeLayout =
            CExtToolControlBar::_CalcLayout(
                dwMode, nLength );
        _RecalcPositionsImpl();
        ((CMyChevronButton *)pRightButton)->
            _AdjustVisibility();
        _sizeLayout =
            CExtToolControlBar::_CalcLayout(
                dwMode, nLength );
        return _sizeLayout;
    }
    CSize CalcDynamicLayout(
        int nLength, DWORD dwMode)
    {
        if(     (nLength == -1)
            && !(dwMode & (LM_MRUWIDTH|LM_COMMIT))
            &&  (dwMode & (LM_HORZDOCK|LM_VERTDOCK))
            )
            return
                CalcFixedLayout(
                    dwMode & LM_STRETCH,
                    dwMode & LM_HORZDOCK
                    );
        ASSERT(
            (dwMode&(LM_HORZ|LM_HORZDOCK))
            ||
            (!(dwMode&LM_HORZDOCK))
            );
        return _CalcLayout( dwMode, nLength );
    }
    CSize CalcFixedLayout(
        BOOL bStretch,
        BOOL bHorz
        )
    {
        DWORD dwMode = bStretch ? LM_STRETCH : 0;
        dwMode |= bHorz ? LM_HORZ : 0;
        ASSERT(
            (dwMode&(LM_HORZ|LM_HORZDOCK))
            ||
            (!(dwMode&LM_HORZDOCK))
            );
        return _CalcLayout( dwMode );
    }
};