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 » how to insert a new tab in ribbon control at run time Collapse All
Subject Author Date
himanshu joshi Dec 7, 2006 - 11:21 PM

hi

i have created on ribbon control with 4 tabs each holding one tabpage and all are inside one tabpagecollection .
Now when i click on File (New)tab i want to generate a new tab containing a tabpage dynamically and to be shown at the end (after 4th tab)

Is it possible to generate and a new tab dynamically by clicking on existing tab .

What i have done is
CExtRibbonNodeTabPage * pRibbonNodeTabPage =new CExtRibbonNodeTabPage( 0L, m_pRibbonNode, _T("Test") );
pRibbonNodeTabPageCollection1->InsertNode( NULL,pRibbonNodeTabPage);

where pRibbonNodeTabPageCollection1 already contains 4 tabs and it present in my ribbonnode m_pRibbonNode.
m_pRibbonNode->InsertNode( NULL, pRibbonNodeTabPageCollection1 );

But still i could not see the newly added tab "Test" in my ribboncontrol.

What changs should i make on suggest a method to do such thing if possible


Thanks in advance.






Technical Support Dec 11, 2006 - 12:47 PM

Step 1: Add the following virtual method to the ribbon bar class to fix a small bug in it. This is required for updating the dynamic content correctly:

virtual void _RemoveAllButtonsImpl();
void CExtRibbonPage::_RemoveAllButtonsImpl()
{
    m_arrGroupButtons.RemoveAll();
    m_arrTabPageButtons.RemoveAll();
    m_arrRightButtons.RemoveAll();
    m_arrQuickAccessButtons.RemoveAll();
    m_pQACEB = NULL;
    CExtMenuControlBar::_RemoveAllButtonsImpl();
}
Step 2: The following code should be invoked to remove the content of the ribbon:
INT nSel = 0; // needs to restore selected tab
    if( m_pRibbonNode != NULL )
    {
        // remember selection index
        nSel = m_wndRibbonBar.Ribbon_GetTabPageRootNode()->PageSelectionGet();
        // delete content
        m_wndRibbonBar.SetButtons( NULL );
        delete m_pRibbonNode;
        m_pRibbonNode = NULL;
    }
Step 3: Create the new content in the same way as it is done in the CMainFrame::_InitRibbonBar() method in the RibbonBar sample. Use the nSel value when calling the pRibbonNodeTabPageCollection->PageSelectionSet() code when initializing the ribbon’s content.

Step 4: Make the changes visible on the screen.
    m_wndRibbonBar._RecalcPositionsImpl();
    m_wndRibbonBar.Invalidate();
    m_wndRibbonBar.UpdateWindow();


himanshu joshi Dec 28, 2006 - 6:25 AM

Hi

m_wndRibbonBar.SetButtons( NULL ); this statement gives call to _RemoveAllButtonsImpl() and removes everything created before.
Is there a way out that i could add any a new tab without removing previous content and just "append" the newly created tab at any position in between it.

Technical Support Dec 29, 2006 - 6:18 AM

You don’t need to remove all the content. Just use methods of the CExtCustomizeCmdTreeNode class and then just invoke the CExtRibbonBar::SetButtons() method to refresh the ribbon bar’s content.