BOOL CXTPRibbonBuilder::BuildTabElements(CXTPPropExchange* pPX, CXTPRibbonBar* pRibbonBar)
{

	CXTPPropExchangeSection pxElements(pPX->GetSection(_T("ELEMENTS")));

	CXTPPropExchangeEnumeratorPtr pEnumerator(pxElements->GetEnumerator(_T("ELEMENT")));

	BOOL bBeginGroup = FALSE;

	POSITION pos = pEnumerator->GetPosition(0);
	while (pos)
	{
		CXTPPropExchangeSection pxControl(pEnumerator->GetNext(pos));

		CString strElementName;
		PX_String(&pxControl, _T("ELEMENT_NAME"), strElementName);

		if (strElementName == _T("Separator"))
		{
			bBeginGroup = TRUE;
			continue;
		}


		CCmdTarget* pElement = CreateElement(strElementName);
		if (pElement == NULL)
			continue;

		CXTPControl* pControl = DYNAMIC_DOWNCAST(CXTPControl, pElement);

		if (!pControl)
		{
			delete pElement;
			continue;
		}

		CXTPPropExchangeSection pxElements(pxControl->GetSection(_T("ELEMENTS")));
		BuildControlPopupBar(&pxElements, pControl, RUNTIME_CLASS(CXTPPopupBar));

		BuildControl(&pxControl, pControl);

		pRibbonBar->GetControls()->Add(pControl);

		pControl->SetFlags(pControl->GetFlags() | xtpFlagRightAlign);

		pControl->SetBeginGroup(bBeginGroup);
		bBeginGroup = FALSE;

	}


	return TRUE;
}
示例#2
0
BOOL CXTPRibbonGroup::SetButtons(UINT* pButtons, int nCount)
{
    BOOL bSeparator = FALSE;

    CXTPRibbonBar* pRibbonBar = GetRibbonBar();
    CWnd* pSite = pRibbonBar->GetSite();

    for (int i = 0; i < nCount; i++)
    {
        if (pButtons[i] == 0)
            bSeparator = TRUE;
        else
        {
            XTPControlType controlType = xtpControlButton;
            XTPButtonStyle buttonStyle = xtpButtonAutomatic;
            CXTPControl* pControl = NULL;
            UINT nID = pButtons[i];

            XTP_COMMANDBARS_CREATECONTROL cs;

            if (pSite)
            {
                cs.nID = nID;
                cs.pControl = NULL;
                cs.bToolBar = TRUE;
                cs.pMenu = NULL;
                cs.nIndex = i;
                cs.strCaption = pRibbonBar->GetTitle();
                cs.controlType = controlType;
                cs.pCommandBar = pRibbonBar;
                cs.buttonStyle = buttonStyle;

                if (pSite->SendMessage(WM_XTP_BEFORECREATECONTROL, 0, (LPARAM)&cs) != 0)
                {
                    pControl = cs.pControl;
                    controlType = cs.controlType;
                    buttonStyle = cs.buttonStyle;
                    nID = cs.nID;
                }
            }

            int nControlPos = m_pControlGroupOption->GetIndex();

            if (pControl == NULL)
            {
                pControl = pRibbonBar->GetControls()->Add(controlType, nID, NULL, nControlPos);
                if (pControl)
                {
                    pControl->SetStyle(buttonStyle);
                    if (controlType == xtpControlPopup) pControl->SetIconId(nID);
                }
            }
            else pRibbonBar->GetControls()->Add(pControl, nID, NULL, nControlPos);

            if (!pControl)
                continue;

            if (bSeparator)
            {
                pControl->SetBeginGroup(TRUE);
                bSeparator = FALSE;
            }

            m_arrControls.InsertAt(GetCount(), pControl);
            pControl->InternalAddRef();

            pControl->m_pRibbonGroup = this;
            pControl->SetHideFlag(xtpHideRibbonTab, !IsVisible());

            if (pSite)
            {
                cs.pControl = pControl;
                pSite->SendMessage(WM_XTP_AFTERCREATECONTROL, 0, (LPARAM)&cs);
            }
        }
    }
    return TRUE;
}
BOOL CXTPRibbonBuilder::BuildMainButtonPopupBar(CXTPPropExchange* pPX, CXTPRibbonBar* pRibbonBar)
{
	if (!pRibbonBar->GetSystemButton())
		return FALSE;

	CXTPCommandBar* pPopupBar = pRibbonBar->GetSystemButton()->GetCommandBar();


	CString strElementName;
	PX_String(pPX, _T("ELEMENT_NAME"), strElementName);

	if (strElementName != _T("Category_Main"))
		return FALSE;

	CString strCaption;
	PX_String(pPX, _T("NAME"), strCaption);

	pRibbonBar->GetSystemButton()->SetCaption(strCaption);


	pPopupBar->SetIconSize(CSize(32, 32));

	m_arrImageLarge.RemoveAll();
	m_arrImageSmall.RemoveAll();

	CXTPPropExchangeSection pxElements(pPX->GetSection(_T("ELEMENTS")));

	CXTPPropExchangeEnumeratorPtr pEnumerator(pxElements->GetEnumerator(_T("ELEMENT")));

	BOOL bBeginGroup = FALSE;

	POSITION pos = pEnumerator->GetPosition(0);
	while (pos)
	{
		CXTPPropExchangeSection pxControl(pEnumerator->GetNext(pos));

		CString strElementName;
		PX_String(&pxControl, _T("ELEMENT_NAME"), strElementName);

		if (strElementName == _T("Separator"))
		{
			bBeginGroup = TRUE;
			continue;
		}


		CCmdTarget* pElement = CreateElement(strElementName);
		if (pElement == NULL)
			continue;

		CXTPControl* pControl = DYNAMIC_DOWNCAST(CXTPControl, pElement);

		if (!pControl)
		{
			delete pElement;
			continue;
		}

		CXTPPropExchangeSection pxElements(pxControl->GetSection(_T("ELEMENTS")));
		BuildControlPopupBar(&pxElements, pControl, RUNTIME_CLASS(CXTPRibbonSystemPopupBarPage));

		BuildControl(&pxControl, pControl);

		pPopupBar->GetControls()->Add(pControl, pControl->GetID());

		pControl->SetBeginGroup(bBeginGroup);
		bBeginGroup = FALSE;

	}

	CXTPPropExchangeSection pxRecentFileList(pPX->GetSection(_T("RECENT_FILE_LIST")));

	CString strEnabled;
	PX_String(&pxRecentFileList, _T("ENABLE"), strEnabled);
	if (strEnabled == _T("TRUE"))
	{
		CXTPControl* pControl = pPopupBar->GetControls()->Add(new CXTPRibbonControlSystemRecentFileList());

		CString strLabel;
		PX_String(&pxRecentFileList, _T("LABEL"), strLabel);
		pControl->SetCaption(strLabel);
	}


	LoadIcons(pPX);


	return TRUE;
}