Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Changing control types with designer bars
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Changing control types with designer bars

 Post Reply Post Reply
Author
Message
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post Topic: Changing control types with designer bars
    Posted: 14 November 2004 at 1:07pm
.. 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);
    }
}

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.027 seconds.