Print Page | Close Window

Changing control types with designer bars

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=1409
Printed Date: 29 June 2025 at 1:43pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Changing control types with designer bars
Posted By: Ark42
Subject: Changing control types with designer bars
Date 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);
    }
}




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net