I have a set of controls I put on a group. I then right-click the group and add the group to the QAT. Click the group on the QAT and it shows a popup with the controls that were on the group. So far so good.
I now proceed to unload the server that the controls were added for (it is an addin to my product). So I have to remove the controls I added to the ribbon.
So I call GetControls on the ribbon. For each command the add-in added, I call FindControl in a while loop (loop is to try and account for copied controls). Each control that is returned I call GetRibbonGroup on the control and then call the Remove method on the controls collection. I get the count of the ribbon group (if one was returned) and if the count is zero, I remove the group from the ribbon.
All of the above works. However, when I am done, the popup that got added to the QAT when I added the group still appears on the QAT. If I click the popup, I crash because
CXTPRibbonGroupControlPopup::OnSetPopup
is called and it does this:
m_pCommandBar = new CXTPRibbonGroupPopupToolBar(m_pPopupGroup);
However, m_pPopupGroup has been deleted (all instance data is 0xfeeefeee).
I have found that the group gets deleted when I do this:
Tab = Ribbon->FindTab ( id of the tab that contains the group )
Group = Tab->FindGroup( id of the group )
index = Group->GetIndex()
Groups = Tab->GetGroups()
Groups->Remove( index )
At that point, the group destructor is called. But the group appears to be copied in that group control popup. Hence the crash if the user clicks the popup.
Note that if I add a control from the group to the QAT and unload the add-in, when I call the controls remove method, the control is also automatically removed from the QAT too.
So Oleg,
What is the correct way to remove a control and the group that contained a control since the group could have been added to the QAT?
Oleg, A bit more info. I see the CXTPRibbonGroupControlPopup being checked to see if it is on the QAT. It is not but the QAT has another object of that class that contains the same group pointer. Not sure how or why there are two of those objects containing the same group pointer.
|