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 » How to update command items in Ribbon Page? Collapse All
Subject Author Date
Stan Miasnikov Feb 18, 2007 - 3:08 PM

Function call:

CExtRibbonPage::RedrawCommandItems( nCmdID );

does not do anything in the RibbonPage example because the toolbar mapping is empty. How to update command items when needed?

Stan Miasnikov Feb 19, 2007 - 12:44 PM

Sorry, do you mean that these functions were just added and are not a part of the latest downloadable code (ZIP)?

Technical Support Feb 20, 2007 - 3:49 AM

No, these methods were added to the CExtRibbonPage class immediately before answering your message. They are not inside the latest downloadable source code yet. We are sorry for inconvenience. But they will be statically available in future of course. So, please add them manually or we can provide you with the newer download.

Stan Miasnikov Feb 19, 2007 - 12:41 PM

I check it in the sample applicaiton under the debugger. The different function is actually called for CExtRibbonPage::RedrawCommandItems( nCmdID )

INT CExtCustomizeSite::RedrawCommandItems(
    UINT nCmdID,
    bool bUpdateWindows // = true
    ) const
{
    ASSERT( CExtCmdManager::IsCommand(nCmdID) );
INT nUpdateBtnsCount = 0;
    for(    POSITION pos = m_mapToolBars.GetStartPosition();
            pos != NULL;
            )
    {
        CExtToolControlBar * pBar = NULL;
        CToolBarCustomizeInfo * pInfo = NULL;
        m_mapToolBars.GetNextAssoc( pos, (void * &)pBar, (void * &)pInfo );
        ASSERT( pBar != NULL );
        ASSERT( pInfo != NULL );
        if( !pBar->IsVisible() )
            continue;
        INT nBtnsCount = pBar->GetButtonsCount();
        if( nBtnsCount == 0 )
            continue;
        bool bUpdateBar = false;
        for( INT nBtnIdx = 0; nBtnIdx < nBtnsCount; nBtnIdx++ )
        {
            CExtBarButton * pTBB = pBar->GetButton( nBtnIdx );
            ASSERT_VALID( pTBB );
            UINT nTbbCmdID = pTBB->GetCmdID( false );
            if(        nTbbCmdID != nCmdID
                ||    (! pTBB->IsVisible() )
                ||    (pTBB->GetStyle()&TBBS_HIDDEN) != 0
                )
                continue;
            nUpdateBtnsCount ++;
            bUpdateBar = true;
            if( pTBB->IsKindOf(RUNTIME_CLASS(CExtBarColorButton)) )
                ((CExtBarColorButton*)pTBB)->OnSyncIcon();
            pTBB->RedrawButton( false );
        } // for( INT nBtnIdx = 0; nBtnIdx < nBtnsCount; nBtnIdx++ )
        if( bUpdateWindows && bUpdateBar )
            pBar->UpdateWindow();
    }
    return nUpdateBtnsCount;
}

and the m_mapToolBars is empty, so it does not do anything. Note that under the debugger the RedrawCommandItems() method is called from the CExtCustomizeSite class not from the CExtRibbonPage. This is in the standard sample code, I did not make any changes.

Technical Support Feb 19, 2007 - 10:48 AM

We confirm this issue. The following two public methods were added to the CExtRibbonPage class for re-painting and updating ribbon bar’s/ribbon page’s buttons:

      virtual INT RedrawCommandItems(
            UINT nCmdID,
            bool bUpdateWindows = true
            ) const;
      virtual INT UpdateAllCommandItems() const;


INT CExtRibbonPage::RedrawCommandItems(
      UINT nCmdID,
      bool bUpdateWindows // = true
      ) const
{
      ASSERT_VALID( this );
      ASSERT( CExtCmdManager::IsCommand(nCmdID) );
      if( ! IsVisible() )
            return 0;
INT nBtnsCount = GetButtonsCount();
      if( nBtnsCount == 0 )
            return 0;
INT nUpdateBtnsCount = 0;
bool bUpdateBar = false;
      for( INT nBtnIdx = 0; nBtnIdx < nBtnsCount; nBtnIdx++ )
      {
            CExtBarButton * pTBB = ( const_cast < CExtRibbonPage * > ( this ) ) -> GetButton( nBtnIdx );
            ASSERT_VALID( pTBB );
            UINT nTbbCmdID = pTBB->GetCmdID( false );
            if(         nTbbCmdID != nCmdID
                  ||    (! pTBB->IsVisible() )
                  ||    (pTBB->GetStyle()&TBBS_HIDDEN) != 0
                  )
                  continue;
            nUpdateBtnsCount ++;
            bUpdateBar = true;
            if( pTBB->IsKindOf(RUNTIME_CLASS(CExtBarColorButton)) )
                  ((CExtBarColorButton*)pTBB)->OnSyncIcon();
            pTBB->RedrawButton( false );
      } // for( INT nBtnIdx = 0; nBtnIdx < nBtnsCount; nBtnIdx++ )
      if( bUpdateWindows && bUpdateBar )
            ( const_cast < CExtRibbonPage * > ( this ) ) -> UpdateWindow();
      return nUpdateBtnsCount;
}

INT CExtRibbonPage::UpdateAllCommandItems() const
{
      ASSERT_VALID( this );
      if( ! IsVisible() )
            return 0;
      ( const_cast < CExtRibbonPage * > ( this ) ) -> DoCustomModeUpdateCmdUI();
      ( const_cast < CExtRibbonPage * > ( this ) ) -> UpdateWindow();
      return 1;
}