Thank you for your question. It helped us find a small typo in the CExtRibbonBar::Ribbon_AutoHideModeDoExpanding()
method. There are the following lines of code near the beginning of this method:
INT nSelIdx = RibbonTabPageButton_GetIndexOf( pTBB );
if( nSelIdx <= 0 )
return false;
In fact they should be:
INT nSelIdx = RibbonTabPageButton_GetIndexOf( pTBB );
if( nSelIdx < 0 )
return false;
We implemented programmatic activation of text/combo field buttons. We didn’t add any new methods to the
CExtRibbonBar
and
CExtRibbonPage
classes yet. But we made the
RibbonBar sample application activating two different text fields when clicking on the Undo and Redo buttons inside the ribbon bar’s quick access toolbar area which is near the ribbon file button. We just inserted the following code into the beginning of the
CMainFrame::OnCmdMsg()
method in the
RibbonBar sample application:
if( ( nID == ID_QA_EDIT_UNDO || nID == ID_QA_EDIT_REDO ) && nCode == CN_COMMAND && pExtra == NULL )
{
// the index of the Home or Mailings ribbon tab page
INT nRibbonTabPageIndex = ( nID == ID_QA_EDIT_UNDO ) ? 0 : 4;
// id of font face name or go to text fields
UINT nTextFieldButtonCmdID = ( nID == ID_QA_EDIT_UNDO ) ? ID_SE_FONT_LIST : ID_MAILINGS_GOTO_RECORD;
SendMessage( WM_CANCELMODE ); // close any popup windows
CExtRibbonPage * pWndRibbonPageToSearch = &m_wndRibbonBar;
if( ! m_wndRibbonBar.RibbonPage_ExpandedModeGet() )
{
pWndRibbonPageToSearch = NULL;
CExtRibbonButtonTabPage * pRibbonTabPageTBB = m_wndRibbonBar.RibbonTabPageButton_GetAt( nRibbonTabPageIndex );
ASSERT_VALID( pRibbonTabPageTBB );
if( m_wndRibbonBar.Ribbon_AutoHideModeDoExpanding( pRibbonTabPageTBB, false )
&& m_wndRibbonBar.m_pPopupPageMenuAutoHide != NULL
)
{
ASSERT_VALID( m_wndRibbonBar.m_pPopupPageMenuAutoHide );
ASSERT( m_wndRibbonBar.m_pPopupPageMenuAutoHide->GetSafeHwnd() != NULL );
pWndRibbonPageToSearch = &m_wndRibbonBar.m_pPopupPageMenuAutoHide->m_wndRibbonPage;
}
}
else
m_wndRibbonBar.Ribbon_PageSelectionSet( nRibbonTabPageIndex );
if( pWndRibbonPageToSearch != NULL )
{
ASSERT_VALID( pWndRibbonPageToSearch );
ASSERT( pWndRibbonPageToSearch->GetSafeHwnd() != NULL );
int nTextFieldIndex = pWndRibbonPageToSearch->CommandToIndex( nTextFieldButtonCmdID );
if( nTextFieldIndex >= 0 )
{
CExtBarTextFieldButton * pTextFieldTBB =
DYNAMIC_DOWNCAST( CExtBarTextFieldButton, pWndRibbonPageToSearch->GetButton( nTextFieldIndex ) );
if( pTextFieldTBB != NULL )
{
ASSERT_VALID( pTextFieldTBB );
if( pTextFieldTBB->IsVisible() )
pTextFieldTBB->OnInplaceControlRun();
else
{
CExtRibbonButtonGroup * pGroupTBB = NULL;
CExtBarButton * pTBB = pTextFieldTBB->ParentButtonGet();
for( ; pTBB != NULL; pTBB = pTBB->ParentButtonGet() )
pGroupTBB = DYNAMIC_DOWNCAST( CExtRibbonButtonGroup, pTBB ); // find top group button
if( pGroupTBB != NULL )
{
ASSERT_VALID( pGroupTBB );
CPoint ptTrack = pGroupTBB->Rect().CenterPoint();
bool bSavedTCS = pGroupTBB->TopCollapsedStateGet();
pGroupTBB->TopCollapsedStateSet( true );
pGroupTBB->OnTrackPopup( ptTrack, false, false );
pGroupTBB->TopCollapsedStateSet( bSavedTCS );
if( pWndRibbonPageToSearch->m_pPopupPageMenuGroup->GetSafeHwnd() != NULL
&& pWndRibbonPageToSearch->m_pPopupPageMenuGroup->m_wndRibbonPage.GetSafeHwnd() != NULL
)
{
pWndRibbonPageToSearch = &pWndRibbonPageToSearch->m_pPopupPageMenuGroup->m_wndRibbonPage;
nTextFieldIndex = pWndRibbonPageToSearch->CommandToIndex( nTextFieldButtonCmdID );
if( nTextFieldIndex >= 0 )
{
pTextFieldTBB =
DYNAMIC_DOWNCAST( CExtBarTextFieldButton, pWndRibbonPageToSearch->GetButton( nTextFieldIndex ) );
if( pTextFieldTBB != NULL )
{
ASSERT_VALID( pTextFieldTBB );
if( pTextFieldTBB->IsVisible() )
pTextFieldTBB->OnInplaceControlRun();
}
}
}
}
}
}
}
}
m_wndRibbonBar.Invalidate();
return TRUE;
}
As we said, we didn’t insert a new method doing the same into Prof-UIS. We think we need to add some additional cases. For instance, the text/combo field ribbon items can be even deeper in the ribbon tree - they can be inside popup menus displayed by some ribbon buttons. They also can be inside ribbon file menu displayed from ribbon file button, inside quick access toolbar and part of right buttons group that is at right side of ribbon tabs. This task is even more interesting. There are several other ribbon elements which you may need to display programmatically and/or set focus to them: different types of galleries, popup color and date picker menus, check boxes etc. We are trying to design and test some more universal code which is able to solve your task as one of possible tasks. So, if you have any whishes or any similar tasks in your project, then we are ready to discuss them.
Please also note, if you will not apply the issue fix we meant at the beginning of this message, then only the Undo button will activate and focus ribbon text field after modifying the
RibbonBar sample application.