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 in toolbar Collapse All
Subject Author Date
Borremans Pierre Nov 13, 2009 - 3:54 AM

We want to had the chevron in our application when button in the toolbar are hidden.


We follow the sample on the forum www.prof-uis.com/prof-uis/tech-support/support-forum/display-chevron-for-invisible-buttons-10850.aspx


but when the chevron is visible when we click on it nothing is visible.


Can some one help me ?


 


thanks

Technical Support Nov 13, 2009 - 2:00 PM

We just put the source code of the CMyBar class into the SDI sample application and it works OK. This class does what you need. What’s wrong with it?

Borremans Pierre Nov 17, 2009 - 8:04 AM

here my code :


 


 class CUI_ToolBar :     public CExtToolControlBar { public:     class CMyContentExpandButton : public CExtBarContentExpandButton     {     public:     CMyContentExpandButton( CExtToolControlBar * pBar = NULL )     : CExtBarContentExpandButton( pBar )     {     }     virtual bool IsVisible() const     {     bool bVisible = ( GetButtons().GetSize() > 0 ) ? true : false;     return bVisible;     }     };     CUI_ToolBar(void);     virtual CExtBarContentExpandButton * OnCreateBarRightBtn()

{

 return new CMyContentExpandButton( this );

}     virtual ~CUI_ToolBar(void);     virtual void _RecalcPositionsImpl()

{     CExtToolControlBar::_RecalcPositionsImpl();     if( m_pDockBar != NULL )     {         return;     }     CExtBarContentExpandButton * pRightTBB = GetRightButton();     if( pRightTBB == NULL )     {         return;     }     if( ! pRightTBB->IsVisible() )     {         return;     }     bool bHorz = ((GetBarStyle()&(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM))!=0) ? true : false;     CRect rcRightTBB = *pRightTBB, rcClient;     GetClientRect( &rcClient );     rcRightTBB.OffsetRect(         bHorz ? ( rcClient.right - rcRightTBB.right ) : 0,         bHorz ? 0 : ( rcClient.bottom - rcRightTBB.bottom )         );     pRightTBB->SetRect( rcRightTBB );     INT nIndex, nCount = GetButtonsCount();     for( nIndex = 0; nIndex < nCount; nIndex ++ )     {         CExtBarButton * pTBB = GetButton( nIndex );         if( ! pTBB->IsVisible() )         {             continue;         }         if( pTBB == pRightTBB )         {             continue;         }         CRect rcTBB = *pTBB;         if( bHorz )         {             if( rcTBB.right < rcRightTBB.left )             {                 continue;             }         }         else         {             if( rcTBB.bottom < rcRightTBB.top )             {                 continue;             }         }         pTBB->Show( false );         pRightTBB->GetButtons().InsertAt( 0, pTBB );     } }     //virtual CExtBarButton * OnCreateBarCommandBtn(UINT nCmdID, UINT nStyle = 0); };

 

in the mainframe :

int CUI_MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {

...

if( !this->m_ToolBar_File.Create( NULL, this, AFX_IDW_TOOLBAR ) || !this->m_ToolBar_File.LoadToolBar( IDR_TOOLBAR_FILE) ) { TRACE0("Failed to create toolbar file\n"); return -1; // fail to create }

...

m_ToolBar_File.EnableDocking( CBRS_ALIGN_ANY );

DockControlBar( &m_ToolBar_File);

..

}


When I debug this code, it stop and exist on the line :


    if( m_pDockBar != NULL )

    {

        return;

    }


If I comment the lines, and replace the for( nIndex = 0; nIndex < nCount; nIndex ++ ) with


 


    for( nIndex = 0; nIndex < nCount; nIndex ++ )     {         CExtBarButton * pTBB = GetButton( nIndex );         pRightTBB->GetButtons().InsertAt( 0, pTBB );

    }


When I click on the chevron no menu will be visible. Have you got an idea ?


 

Technical Support Nov 18, 2009 - 6:54 AM

Here is the updated version of your class:

 class CUI_ToolBar : public CExtToolControlBar
{
public:
      class CMyContentExpandButton : public CExtBarContentExpandButton
      {
      protected:
            mutable bool m_bComputingExtendedLayout:1;
      public:
            CMyContentExpandButton( CExtToolControlBar * pBar = NULL )
                  : CExtBarContentExpandButton( pBar )
                  , m_bComputingExtendedLayout( false )
            {
            }
            virtual bool IsVisible() const
            {
                  if( m_bComputingExtendedLayout )
                        return CExtBarContentExpandButton::IsVisible();
                 bool bVisible = ( GetButtons().GetSize() > 0 ) ? true : false;
                  return bVisible;
            }
            virtual CSize CalculateLayout(
                  CDC & dc,
                  CSize sizePreCalc,
                  BOOL bHorz
                  )
            {
                  if( m_bComputingExtendedLayout )
                        return CExtBarContentExpandButton::CalculateLayout( dc, sizePreCalc, bHorz );
                  if( IsVisible() )
                  {
                        SetStyle( GetStyle() & (~(TBBS_HIDDEN)) );
                        return CExtBarContentExpandButton::CalculateLayout( dc, sizePreCalc, bHorz );
                  }
                  m_ActiveSize.cx = m_ActiveSize.cy = 0;
                  SetStyle( GetStyle() | TBBS_HIDDEN );
                  return m_ActiveSize;
            }
            friend class CUI_ToolBar;
      };
      virtual CExtBarContentExpandButton * OnCreateBarRightBtn()
      {
            return new CMyContentExpandButton( this );
      }
      virtual void _RecalcPositionsImpl()
      {
            CMyContentExpandButton * pRightTBB = (CMyContentExpandButton*)GetRightButton();
            if( pRightTBB == NULL )
            {
                  CExtToolControlBar::_RecalcPositionsImpl();
                  return;
            }
            ASSERT_VALID( pRightTBB );
            bool bVisibleOld = pRightTBB->IsVisible();
            pRightTBB->SetStyle( pRightTBB->GetStyle() & (~(TBBS_HIDDEN)) );
            pRightTBB->Show( true );
            pRightTBB->m_bComputingExtendedLayout = true;
            CExtToolControlBar::_RecalcPositionsImpl();
            pRightTBB->m_bComputingExtendedLayout = false;
            bool bVisibleNew = pRightTBB->IsVisible();
            if( bVisibleOld != bVisibleNew )
                  CExtToolControlBar::_RecalcPositionsImpl();
      }
};