.. and still allowing customization / resetting of toolbars and multiple copies of items.
I found OnCreateControl no so good for this, as resetting my toolbars
or trying to customize them wouldn't work well for certain custom items
like the color picker or other things you can't directly put in the
designer bar editor, so I wrote these little template functions that
make it really easy:
For example, in my CMainFrame::LoadFrame I just put:
ChangeControlType<CXTPControlPopupColorNoSplit>(pComma ndBars, ID_EDIT_ITEMCOLOR);
ChangeControlType<CXTPControlButtonColor>(pCommandBars , XTP_IDS_AUTOMATIC);
ChangeControlType<CXTPControlColorSelector>(pCommandBa rs, ID_EDIT_ITEMCOLOR_COLORS);
ChangeControlType<CXTPControlButtonColor>(pCommandBars , XTP_IDS_MORE_COLORS);
and my button popup becomes customizable, resettable, and works perfectly no matter how many duplicates I have.
The templates are here if anybody wants to use them:
template<class ControlType> void ChangeControlType(CXTPCommandBars *pCommandBars, long nControlId, ControlType *unused = 0)
{
//change menu items, submenu items, list of commands in customize
ChangeControlType<ControlType>(pCommandBars->m_pDes ignerControls, nControlId);
CXTPToolBar *pToolBar;
for(int i=0; i<pCommandBars->GetCount(); i++) {
pToolBar = pCommandBars->GetAt(i);
//change top menu list, toolbar items
ChangeControlType<ControlType>(pToolBar->GetControl s(), nControlId, FALSE);
}
}
template<class ControlType> void ChangeControlType(CXTPControls *pControls, long nControlId, BOOL recurse = TRUE, ControlType *unused = 0)
{
CXTPControl *pControl = pControls->GetFirst();
while( pControl ) {
if( pControl->GetID() == nControlId ) {
ControlType *pControlType = new ControlType();
CXTPControl
*pNewControl = pControls->Add(pControlType, nControlId, "",
pControl->GetIndex() + 1);
pNewControl->SetStyle(pControl->GetStyle());
pNewControl->SetCaption(pControl->GetCaption());
pNewControl->SetShortcutText(pControl->GetShortcutText ());
pNewControl->SetDescription(pControl->GetDescription() );
pNewControl->SetTooltip(pControl->GetTooltip());
pNewControl->SetCategory(pControl->GetCategory());
pNewControl->SetBeginGroup(pControl->GetBeginGroup());
if( pNewControl->IsKindOf(RUNTIME_CLASS(CXTPControlPopup)) ) {
static_cast<CXTPControlPopup *>(pNewControl)->SetCommandBar(static_cast<CXTPControlPopup *>(pControl)->GetCommandBar());
}
pControls->Remove(pControl);
pControl = pNewControl;
}
if( recurse ) {
if( pControl->IsKindOf(RUNTIME_CLASS(CXTPControlPopup)) ) {
CXTPPopupBar *pPopupBar = static_cast<CXTPPopupBar *>((static_cast<CXTPControlPopup *>(pControl))->GetCommandBar());
ChangeControlType< ;ControlType>(pPopupBar->GetControls(),
nControlId);
}
}
pControls->GetNext(pControl);
}
if( pControls->GetOriginalControls() ) {
ChangeControlType<ControlType>(pControls->GetOrigin alControls(), nControlId);
}
}
|