void CXTPCustomizeMenusPage::OnSelectionChangedContextmenus()
{
	CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars();
	CommitContextMenu();

	int nSel = m_cmbContextMenus.GetCurSel();

	if (nSel < 1)
	{
		GetDlgItem(XTP_IDC_BUTTON_RESETCONTEXT)->EnableWindow(FALSE);
		return;
	}

	GetDlgItem(XTP_IDC_BUTTON_RESETCONTEXT)->EnableWindow(TRUE);
	CXTPPopupBar* pPopupBar = (CXTPPopupBar*)m_cmbContextMenus.GetItemData(nSel);


	CXTPToolBar* pContextMenu = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop, RUNTIME_CLASS(CXTPFloatingPopupBar));
	if (!pContextMenu)
	{
		TRACE0("Failed to create toolbar\n");
		return;
	}

	CXTPControls* pControls = pPopupBar->GetControls()->Duplicate();
	pContextMenu->SetControls(pControls);


	pContextMenu->SetBarID(pPopupBar->GetBarID());
	pContextMenu->SetTitle(pPopupBar->GetTitle());
	pContextMenu->SetCustomizeDialogPresent(FALSE);

	pContextMenu->SetPosition(xtpBarFloating);
	pContextMenu->EnableDocking(xtpFlagFloating);

	pContextMenu->OnRecalcLayout();

	CXTPWindowRect rcContext(pContextMenu);
	CXTPWindowRect rcParent(GetParent());

	CPoint pt = m_ptContextMenu;
	if (pt == CPoint(0, 0))
		pt = CPoint(rcParent.left - rcContext.Width(), rcParent.top);

	pContextMenu->MoveWindow(pt.x, pt.y, rcContext.Width(), rcContext.Height());

	m_pContextMenu = pContextMenu;

	pContextMenu->SetCommandBarData((DWORD_PTR)pPopupBar);
	pContextMenu->OnUpdateCmdUI();
}
void CXTPCustomizeMenusPage::CommitContextMenu()
{
	CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars();
	if (m_pContextMenu)
	{
		CXTPPopupBar* pPopupBar = (CXTPPopupBar*)m_pContextMenu->GetCommandBarData();

		CXTPControls* pControls = m_pContextMenu->GetControls()->Duplicate();
		pPopupBar->SetControls(pControls);

		m_ptContextMenu = CXTPWindowRect(m_pContextMenu).TopLeft();

		pCommandBars->Remove(m_pContextMenu);
		m_pContextMenu = NULL;
	}
}
void CBackstagePageInfo::OnCheckForIssuesDropDown()
{
	CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
	
	CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(pMainFrame->GetCommandBars());
	pPopupBar->SetDefaultButtonStyle(xtpButtonCaptionAndDescription);
	pPopupBar->SetShowGripper(FALSE);
	
	pPopupBar->GetControls()->Add(xtpControlButton, IDS_CHECK_INSPECT_DOCUMENT);
	pPopupBar->GetControls()->Add(xtpControlButton, IDS_CHECK_ACCESSIBILITY);
	
	CXTPWindowRect rcButton(GetDlgItem(IDC_BUTTON_CHECKFORISSUE));	
	pMainFrame->GetCommandBars()->TrackPopupMenu(pPopupBar, TPM_RETURNCMD | TPM_NONOTIFY, rcButton.left, rcButton.bottom, this);
	
	
	pPopupBar->InternalRelease();
}
void CBackstagePageInfo::OnProtectDocumentDropDown()
{

	CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();

	CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(pMainFrame->GetCommandBars());
	pPopupBar->SetDefaultButtonStyle(xtpButtonCaptionAndDescription);
	pPopupBar->SetShowGripper(FALSE);
	pPopupBar->SetIconSize(CSize(32, 32));

	pPopupBar->GetControls()->Add(xtpControlButton, IDS_PROTECT_MARK_AS_FINAL);
	pPopupBar->GetControls()->Add(xtpControlButton, IDS_PROTECT_ENCRYPT);


	UINT nIDs[] = {IDS_PROTECT_ENCRYPT};
	XTPImageManager()->SetIcons(IDC_BUTTON_PROTECTDOCUMENT, nIDs, 1, CSize(0, 0), xtpImageNormal);


	CXTPWindowRect rcButton(GetDlgItem(IDC_BUTTON_PROTECTDOCUMENT));
	pMainFrame->GetCommandBars()->TrackPopupMenu(pPopupBar, TPM_RETURNCMD | TPM_NONOTIFY, rcButton.left, rcButton.bottom, this);


	pPopupBar->InternalRelease();
}
bool CMainFrame::_OnCreateRibbon()
{
	// Initialize the command bars
	if (!InitCommandBars())
		return false;

	// Get a pointer to the command bars object.
	CXTPCommandBars* pCommandBars = GetCommandBars();
	if(pCommandBars == NULL)
		return false;

	CXTPPaintManager::SetTheme(xtpThemeRibbon);

	//关闭默认菜单
	::SetMenu(m_hWnd, nullptr);
	m_hMenuDefault = nullptr;
	m_dwMenuBarState = AFX_MBS_HIDDEN;
	
	//初始化图标
	_LoadIcon();

	///Ribbon
	CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pCommandBars->Add(_T("Ribbon"), xtpBarTop, RUNTIME_CLASS(CXTPRibbonBar));
	if (!pRibbonBar)
		return false;
	pRibbonBar->EnableDocking(0);
	//pRibbonBar->GetTabPaintManager()->m_bSelectOnButtonDown = FALSE;

	///创建系统按钮
	CXTPControlPopup* pControlFile = (CXTPControlPopup*)pRibbonBar->AddSystemButton();
	pControlFile->SetIconId(IDB_GEAR);

	CMenu sysMenu;
	sysMenu.LoadMenu(IDR_MAINFRAME);
	CXTPPopupBar* pCommandBar = new CXTPRibbonSystemPopupBar();
	pCommandBar->SetCommandBars(pCommandBars);
	pControlFile->SetCommandBar(pCommandBar);
	pCommandBar->InternalRelease();
	pCommandBar->LoadMenu(sysMenu.GetSubMenu(0));
	pCommandBar->SetIconSize(CSize(32, 32));

	///RibbonHome
	CXTPRibbonTab* pTab = pRibbonBar->AddTab(L"Home");

	//RibbonHome - GroupObject
	CXTPRibbonGroup* pGroup = pTab->AddGroup(L"Object");
	//RibbonHome - GroupObject - Select
	pGroup->Add(xtpControlButton, IDC_Object_Select);
	//RibbonHome - GroupObject - Move
	pGroup->Add(xtpControlButton, IDC_Object_Move);
	//RibbonHome - GroupObject - Rotate
	pGroup->Add(xtpControlButton, IDC_Object_Rotate);
	//RibbonHome - GroupObject - Scale
	pGroup->Add(xtpControlButton, IDC_Object_Scale);
	//RibbonHome - GroupObject - Rmove
	pGroup->Add(xtpControlButton, IDC_Object_Remove);

	///RibbonEffect
	pTab = pRibbonBar->AddTab(L"Effect");

	//RibbonEffect - GroupSwitch
	pGroup = pTab->AddGroup(L"Switch");
	//RibbonEffect - GroupSwitch - Shadow
	pGroup->Add(xtpControlButton, IDC_Effect_Shadow);
	//RibbonEffect - GroupSwitch - SSAO
	pGroup->Add(xtpControlButton, IDC_Effect_SSAO);
	//RibbonEffect - GroupSwitch - Sharpen
	pGroup->Add(xtpControlButton, IDC_Effect_Sharpen);
	//RibbonEffect - GroupSwitch - FXAA
	pGroup->Add(xtpControlButton, IDC_Effect_FXAA);
	
	return true;
}
BOOL CXTPCustomizeMenusPage::OnInitDialog()
{
	CXTPPropertyPage::OnInitDialog();

	CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars();

	CString strDefaultMenu;
	GetDlgItemText(XTP_IDC_STATIC_DESCRIPTION, strDefaultMenu);

	if (_tcschr(strDefaultMenu, _T('\n')) != NULL)
	{
		AfxExtractSubString(m_strDefaultMenuDesc, strDefaultMenu, 1);
		AfxExtractSubString(m_strDefaultMenu, strDefaultMenu, 0);
	}
	else
	{
		m_strDefaultMenu = m_strDefaultMenuDesc = strDefaultMenu;
	}

	int nIndex = m_cmbAppMenus.AddString(m_strDefaultMenu);
	m_cmbAppMenus.SetItemData(nIndex, 0);
	int nCurSel = 0;

	if (pCommandBars->GetMenuBar() && ((pCommandBars->GetMenuBar()->GetFlags() & xtpFlagIgnoreSetMenuMessage) == 0))
	{
		CXTPMenuBar* pMenuBar = pCommandBars->GetMenuBar();
		CXTPMenuBarMDIMenus* pMDIControls = pMenuBar->GetMDIMenus();

		POSITION pos = pMDIControls->GetStartPosition();
		CXTPMenuBarMDIMenuInfo* pInfo;
		while (pos)
		{
			pMDIControls->GetNextMenu(pos, pInfo);
			if (pInfo->m_nIDResource == pMenuBar->GetDefaultMenuResource())
				continue;

			if (!pInfo->m_strTitle.IsEmpty())
			{
				nIndex = m_cmbAppMenus.AddString(pInfo->m_strTitle);
				m_cmbAppMenus.SetItemData(nIndex, (DWORD_PTR)pInfo);

				if (pInfo->m_nIDResource == pMenuBar->GetCurrentMenuResource())
				{
					nCurSel = nIndex;
				}
			}
		}
	}

	m_cmbAppMenus.SetCurSel(nCurSel);
	OnSelectionChangedAppmenus();

	nIndex = m_cmbContextMenus.AddString(_T(""));
	m_cmbContextMenus.SetItemData(nIndex, 0);

	for (int i = 0; i < pCommandBars->GetContextMenus()->GetCount(); i++)
	{
		CXTPPopupBar* pPopupBar = (CXTPPopupBar*)pCommandBars->GetContextMenus()->GetAt(i);

		nIndex = m_cmbContextMenus.AddString(pPopupBar->GetTitle());
		m_cmbContextMenus.SetItemData(nIndex, (DWORD_PTR)pPopupBar);
	}
	m_cmbContextMenus.SetCurSel(0);
	OnSelectionChangedContextmenus();


	SetResize(XTP_IDC_STATIC_APPLICATIONMENUS, XTP_ANCHOR_TOPLEFT, XTP_ANCHOR_TOPRIGHT);
	SetResize(XTP_IDC_STATIC_CONTEXTMENUS, XTP_ANCHOR_TOPLEFT, XTP_ANCHOR_TOPRIGHT);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Exemple #7
0
bool CMainFrame::_OnCreateRibbon()
{
	// Initialize the command bars
	if (!InitCommandBars())
		return false;

	// Get a pointer to the command bars object.
	CXTPCommandBars* pCommandBars = GetCommandBars();
	if(pCommandBars == NULL)
		return false;

	CXTPPaintManager::SetTheme(xtpThemeRibbon);

	//关闭默认菜单
	::SetMenu(m_hWnd, nullptr);
	m_hMenuDefault = nullptr;
	m_dwMenuBarState = AFX_MBS_HIDDEN;
	
	//初始化图标
	_LoadIcon();

	///Ribbon
	CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pCommandBars->Add(_T("Ribbon"), xtpBarTop, RUNTIME_CLASS(CXTPRibbonBar));
	if (!pRibbonBar)
		return false;
	pRibbonBar->EnableDocking(0);
	//pRibbonBar->GetTabPaintManager()->m_bSelectOnButtonDown = FALSE;

	///创建系统按钮
	CXTPControlPopup* pControlFile = (CXTPControlPopup*)pRibbonBar->AddSystemButton();
	pControlFile->SetIconId(IDB_GEAR);

	CMenu sysMenu;
	sysMenu.LoadMenu(IDR_MAINFRAME);
	CXTPPopupBar* pCommandBar = new CXTPRibbonSystemPopupBar();
	pCommandBar->SetCommandBars(pCommandBars);
	pControlFile->SetCommandBar(pCommandBar);
	pCommandBar->InternalRelease();
	pCommandBar->LoadMenu(sysMenu.GetSubMenu(0));
	pCommandBar->SetIconSize(CSize(32, 32));

	///RibbonHome
	CXTPRibbonTab* pTab = pRibbonBar->AddTab(L"Home");

	//RibbonHome - GroupObject
	CXTPRibbonGroup* pGroup = pTab->AddGroup(L"Object");
	//RibbonHome - GroupObject - Select
	pGroup->Add(xtpControlButton, IDC_Object_Select);
	//RibbonHome - GroupObject - Move
	pGroup->Add(xtpControlButton, IDC_Object_Move);
	//RibbonHome - GroupObject - Rotate
	pGroup->Add(xtpControlButton, IDC_Object_Rotate);
	//RibbonHome - GroupObject - Scale
	pGroup->Add(xtpControlButton, IDC_Object_Scale);
	//RibbonHome - GroupObject - Rmove
	pGroup->Add(xtpControlButton, IDC_Object_Remove);

	///RibbonHome - GroupTerrainModify
	pGroup = pTab->AddGroup(L"Terrain Modify");

	//RibbonHome - GroupTerrainModify - Deform
	pGroup->Add(xtpControlButton, IDC_Terrain_Deform);

	//RibbonHome - GroupTerrainModify - Splat
	CXTPControlPopup* pBtn = dynamic_cast<CXTPControlPopup*>(pGroup->Add(xtpControlSplitButtonPopup, IDC_Terrain_Splat));
	pBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Terrain_Splat_Layer0);
	pBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Terrain_Splat_Layer1);
	pBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Terrain_Splat_Layer2);
	pBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Terrain_Splat_Layer3);
	pBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Terrain_Splat_Layer4);
	
	//RibbonHome - GroupTerrainBrush
	pGroup = pTab->AddGroup(L"Terrain Brush");

	//RibbonHome - GroupTerrainBrush - EditBrushSize
	CXTPControlEdit* pControl = (CXTPControlEdit*)pGroup->Add(xtpControlEdit, ID_Terrain_BrushSize1);
	pControl->ShowSpinButtons(TRUE);

	pControl = (CXTPControlEdit*)pGroup->Add(xtpControlEdit, ID_Terrain_BrushSize2);
	pControl->ShowSpinButtons(TRUE);

	//RibbonHome - GroupTerrainTexture
	pGroup = pTab->AddGroup(L"Layer Texture");
	pGroup->SetControlsCentering(TRUE);

	m_terrainTexGallery = CXTPControlGalleryItems::CreateItems(pCommandBars, IDC_Terrain_LayerTexture);

	CXTPControlGallery* pControlGallery = (CXTPControlGallery*)pGroup->Add(new CXTPControlGallery(), IDC_Terrain_LayerTexture);	
	pControlGallery->SetControlSize(CSize(250, 60));
	//pControlGallery->SetResizable();
	pControlGallery->SetItemsMargin(0, 1, 0, 1);
	pControlGallery->ShowLabels(FALSE);
	pControlGallery->ShowBorders(TRUE);
	pControlGallery->SetItems(m_terrainTexGallery);
	
	_CreateLayerTexIcon();

	//RibbonHome - GroupVegetation
	pGroup = pTab->AddGroup(L"Vegetation");

	//RibbonHome - GroupVegetation - Grass
	pGroup->Add(xtpControlButton, IDC_Vegetation_Grass);

	///RibbonEffect
	pTab = pRibbonBar->AddTab(L"Effect");

	//RibbonEffect - GroupSwitch
	pGroup = pTab->AddGroup(L"Switch");
	//RibbonEffect - GroupSwitch - Shadow
	pGroup->Add(xtpControlButton, IDC_Effect_Shadow);
	//RibbonEffect - GroupSwitch - SSAO
	pGroup->Add(xtpControlButton, IDC_Effect_SSAO);
	//RibbonEffect - GroupSwitch - Sharpen
	pGroup->Add(xtpControlButton, IDC_Effect_Sharpen);
	//RibbonEffect - GroupSwitch - FXAA
	pGroup->Add(xtpControlButton, IDC_Effect_FXAA);

	///RibbonAnimation
	m_animTab = pRibbonBar->InsertTab(-1, L"Animation");
	m_animTab->SetContextTab(xtpRibbonTabContextColorRed, L"Animation");
	//选中了带动画物体才显示
	m_animTab->SetVisible(FALSE);

	//RibbonAnimation - GroupAnim
	pGroup = m_animTab->AddGroup(L"Anim");

	//RibbonAnimation - GroupAnim - AnimList
	m_animList = dynamic_cast<CXTPControlComboBox*>(pGroup->Add(xtpControlComboBox, IDC_Animation_Names));
	m_animList->SetDropDownListStyle();
	m_animList->SetWidth(150);

	//RibbonAnimation - GroupAnim - Play
	pGroup->Add(xtpControlButton, IDC_Animation_Play);

	//RibbonAnimation - GroupAnim - Stop
	pGroup->Add(xtpControlButton, IDC_Animation_Stop);

	//RibbonAnimation - GroupEffect
	pGroup = m_animTab->AddGroup(L"Effect");

	//RibbonAnimation - GroupEffect - EffectList
	m_effectList = dynamic_cast<CXTPControlComboBox*>(pGroup->Add(xtpControlComboBox, IDC_Animation_EffectList));
	m_effectList->SetDropDownListStyle();
	m_effectList->SetWidth(150);

	//RibbonAnimation - GroupEffect - AddEffect
	CXTPControlPopup* pAddBtn = dynamic_cast<CXTPControlPopup*>(pGroup->Add(xtpControlSplitButtonPopup, IDC_Effect_Add));
	pAddBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Effect_AddParticle);
	pAddBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Effect_AddEntityEffect);
	pAddBtn->GetCommandBar()->GetControls()->Add(xtpControlButton, IDC_Effect_AddDLight);

	//RibbonAnimation - GroupEffect - EffectRemove
	pGroup->Add(xtpControlButton, IDC_Animation_EffectRemove);
	
	return true;
}
void CXTPRibbonBuilder::BuildControlPopupBar(CXTPPropExchange* pPX, CXTPControl*& pParent, CRuntimeClass* pPopupBarClass)
{
	CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("ELEMENT")));

	BOOL bBeginGroup = FALSE;
	BOOL bEmpty = TRUE;

	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;
		}

		if (bEmpty)
		{
			CXTPControlPopup* pPopupButton = CXTPControlPopup::CreateControlPopup(xtpControlPopup);

			CXTPPopupBar* pPopupBar = (CXTPPopupBar*)pPopupBarClass->CreateObject();

			if (pPopupBar->IsKindOf(RUNTIME_CLASS(CXTPRibbonSystemPopupBarPage)))
			{
				pPopupBar->SetIconSize(CSize(32, 32));
				pPopupBar->SetWidth(300);
				pPopupBar->SetShowGripper(FALSE);
				pPopupBar->SetDefaultButtonStyle(xtpButtonCaptionAndDescription);
			}


			pPopupButton->SetCommandBar(pPopupBar);
			pPopupBar->InternalRelease();

			pParent->InternalRelease();
			pParent = pPopupButton;

			bEmpty = FALSE;
		}


		BuildControl(&pxControl, pControl);

		pParent->GetCommandBar()->GetControls()->Add(pControl, pControl->GetID());

		pParent->SetBeginGroup(bBeginGroup);
		bBeginGroup = FALSE;
	}
}