// RibbonResourceView.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "RibbonSample.h" #include "RibbonResourceView.h" #include "MainFrm.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRibbonResourceFrame IMPLEMENT_DYNAMIC(CRibbonResourceFrame, CXTPFrameWnd) CRibbonResourceFrame::CRibbonResourceFrame(CMainFrame* pOwnerView) { m_pOwnerView = pOwnerView; m_pCommandBars = NULL; m_pRibbonBar = NULL; } CRibbonResourceFrame::~CRibbonResourceFrame() { } BEGIN_MESSAGE_MAP(CRibbonResourceFrame, CXTPFrameWnd) //{{AFX_MSG_MAP(CRibbonResourceFrame) ON_WM_CREATE() ON_WM_DESTROY() ON_XTP_CREATECONTROL() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRibbonResourceFrame message handlers static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; int CRibbonResourceFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CXTPFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, _countof(indicators))) return -1; if (!InitCommandBars()) return -1; m_pCommandBars = GetCommandBars(); if (!m_pCommandBars) return -1; m_pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, m_pCommandBars->Add(_T("Resource Ribbon"), xtpBarTop, RUNTIME_CLASS(CXTPRibbonBar))); if (!m_pRibbonBar) return -1; CXTPRibbonBuilder builder; if (builder.LoadFromResource(IDR_RIBBON)) { builder.Build(m_pRibbonBar); } m_pRibbonBar->EnableDocking(0); m_pRibbonBar->EnableFrameTheme(); m_pCommandBars->GetCommandBarsOptions()->bShowKeyboardTips = TRUE; // Backstage CXTPRibbonControlSystemButton* pSysButton = m_pRibbonBar->GetSystemButton(); if (pSysButton) pSysButton->SetStyle(xtpButtonCaption); CreateBackstage(); return 0; } void CRibbonResourceFrame::OnDestroy() { CMainFrame* pFrame = DYNAMIC_DOWNCAST(CMainFrame, m_pOwnerView); _ASSERTE(pFrame); pFrame->m_pRibbonResourceFrame = NULL; CXTPFrameWnd::OnDestroy(); } void CRibbonResourceFrame::UpdateCommandBars(XTPPaintTheme paintTheme) { if (m_pCommandBars) { CXTPPaintManager::SetTheme(paintTheme); m_pCommandBars->GetPaintManager()->RefreshMetrics(); m_pCommandBars->RedrawCommandBars(); } } void CRibbonResourceFrame::CreateSystemMenuPopup() { if (m_pRibbonBar) { CXTPRibbonControlSystemButton* pControlFile = m_pRibbonBar->GetSystemButton(); if (pControlFile) { CMenu menu; menu.LoadMenu(IDR_MAINFRAME); CXTPPopupBar* pCommandBar = new CXTPRibbonSystemPopupBar(); if (pCommandBar) { pCommandBar->SetCommandBars(m_pCommandBars); pControlFile->SetCommandBar(pCommandBar); pCommandBar->InternalRelease(); pCommandBar->LoadMenu(menu.GetSubMenu(0)); pCommandBar->SetIconSize(CSize(36, 36)); } } } } void CRibbonResourceFrame::CreateBackstage() { CXTPRibbonBackstageView* pView = CXTPRibbonBackstageView::CreateBackstageView(m_pCommandBars); if (pView) { if (!m_pageInfo.GetSafeHwnd()) m_pageInfo.Create(CBackstagePageInfo::IDD, this); if (!m_pageHelp.GetSafeHwnd()) m_pageHelp.Create(CBackstagePageHelp::IDD, this); CXTPRibbonBackstageTab* pTabInfo = pView->AddTab(&m_pageInfo, ID_BACKSTAGE_INFO); if (pTabInfo) { pTabInfo->SetFlags(xtpFlagManualUpdate); // No Need update with Update handler pTabInfo->SetControlPaneMinSize(XTP_DPI(CSize(650, 400))); } CXTPRibbonBackstageTab* pTabHelp = pView->AddTab(&m_pageHelp, ID_BACKSTAGE_HELP); if (pTabHelp) { pTabHelp->SetFlags(xtpFlagManualUpdate); // No Need update with Update handler pTabHelp->SetIconId(ID_APP_ABOUT); } pView->AddCommand(ID_APP_OPTIONS); pView->AddCommand(ID_APP_EXIT); if (pTabInfo) pTabInfo->SetItemDefault(TRUE); if (m_pRibbonBar) { CXTPRibbonControlSystemButton* pButton = m_pRibbonBar->GetSystemButton(); if (pButton) { pButton->SetCommandBar(pView); } } pView->InternalRelease(); } SetBackstageTheme(); } void CRibbonResourceFrame::SetBackstageTheme() { XTPPaintTheme nPaintTheme = m_pCommandBars->GetPaintManager()->GetCurrentTheme(); XTPControlTheme nTheme = xtpControlThemeResource; switch (nPaintTheme) { case xtpThemeOffice2013: /*xtpThemeOffice2016*/ nTheme = xtpControlThemeOffice2013; /*xtpControlThemeOffice2016*/ break; case xtpThemeVisualStudio2015: nTheme = xtpControlThemeVisualStudio2015; break; case xtpThemeVisualStudio2017: nTheme = xtpControlThemeVisualStudio2017; break; case xtpThemeVisualStudio2019: nTheme = xtpControlThemeVisualStudio2019; break; case xtpThemeVisualStudio2022: nTheme = xtpControlThemeVisualStudio2022; break; default: nTheme = xtpControlThemeResource; } if (m_pRibbonBar) { CXTPRibbonBackstageView* pView = DYNAMIC_DOWNCAST( CXTPRibbonBackstageView, m_pRibbonBar->GetSystemButton()->GetCommandBar()); if (pView) { pView->SetTheme(nPaintTheme); if (nTheme == xtpControlThemeResource) { pView->SetBackstageStyle(xtpRibbonBackstageOffice2010Style); } else { pView->SetBackstageStyle(xtpRibbonBackstageOffice2016Style); } } if (m_pageInfo.GetSafeHwnd()) { m_pageInfo.SetTheme(nTheme); } if (m_pageHelp.GetSafeHwnd()) { m_pageHelp.SetTheme(nTheme); } } } void CRibbonResourceFrame::SetTheme(int nTheme, int nThemeColor) { if (m_pRibbonBar) { if (nTheme == xtpThemeDlgOffice2007) m_pRibbonBar->GetSystemButton()->SetStyle(xtpButtonAutomatic); else m_pRibbonBar->GetSystemButton()->SetStyle(xtpButtonCaption); if (nTheme == xtpThemeDlgNativeWindows || nTheme == xtpThemeDlgOffice2007) CreateSystemMenuPopup(); else CreateBackstage(); } } ///////////////////////////////////////////////////////////////////////////// // CRibbonResourceView IMPLEMENT_DYNCREATE(CRibbonResourceView, CView) CRibbonResourceView::CRibbonResourceView() { m_val = true; m_bOption[0] = TRUE; m_bOption[1] = FALSE; m_bOption[2] = FALSE; } CRibbonResourceView::~CRibbonResourceView() { } BEGIN_MESSAGE_MAP(CRibbonResourceView, CView) //{{AFX_MSG_MAP(CRibbonResourceView) ON_WM_CREATE() ON_COMMAND_RANGE(ID_RIBBON_BUTTON_1, ID_RIBBON_BUTTON_3, OnEmptyCommand) ON_COMMAND_RANGE(ID_RIBBON_BUTTON_MAIN, ID_RIBBON_BUTTON_MAIN_5, OnEmptyCommand) ON_COMMAND_RANGE(ID_RIBBON_BUTTON_OPTION1, ID_RIBBON_BUTTON_OPTION3, OnOption) ON_UPDATE_COMMAND_UI_RANGE(ID_RIBBON_BUTTON_OPTION1, ID_RIBBON_BUTTON_OPTION3, OnUpdateOption) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRibbonResourceView drawing void CRibbonResourceView::OnDraw(CDC* dc) { dc->SetTextColor(m_val ? RGB(255, 0, 0) : RGB(0, 0, 255)); dc->TextOut(10, 10, _T("Codejock Ribbon Sample")); } ///////////////////////////////////////////////////////////////////////////// // CRibbonResourceView diagnostics #ifdef _DEBUG void CRibbonResourceView::AssertValid() const { CView::AssertValid(); } void CRibbonResourceView::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CRibbonResourceView message handlers int CRibbonResourceView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; return 0; } int CRibbonResourceFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) { if (lpCreateControl->nID == ID_FILE_RECENTDOCUMENTS) { lpCreateControl->pControl = new CXTPRibbonControlSystemRecentFileList(); return TRUE; } if (lpCreateControl->nID == ID_APP_EXIT || lpCreateControl->nID == ID_APP_OPTIONS) { lpCreateControl->pControl = new CXTPRibbonControlSystemPopupBarButton(); return TRUE; } return FALSE; } void CRibbonResourceView::OnEmptyCommand(UINT) { m_val = !m_val; RedrawWindow(); } void CRibbonResourceView::OnEmptyCommand() { m_val = !m_val; RedrawWindow(); } void CRibbonResourceView::OnOption(UINT nID) { m_bOption[nID - ID_RIBBON_BUTTON_OPTION1] ^= 1; m_val = !m_val; RedrawWindow(); } void CRibbonResourceView::OnUpdateOption(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bOption[pCmdUI->m_nID - ID_RIBBON_BUTTON_OPTION1]); }