// ActionSampleView.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 "commandbarssample.h" #include "ActionSampleView.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // ActionSampleView IMPLEMENT_DYNCREATE(CActionSampleView, CFormView) CActionSampleView::CActionSampleView() : CFormView(CActionSampleView::IDD) { //{{AFX_DATA_INIT(CActionSampleView) // NOTE: the ClassWizard will add member initialization here m_bChecked = FALSE; m_bEnabled = FALSE; m_bVisible = FALSE; m_strCaption = _T(""); m_strDescription = _T(""); m_strTooltip = _T(""); //}}AFX_DATA_INIT } CActionSampleView::~CActionSampleView() { } void CActionSampleView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CActionSampleView) DDX_Control(pDX, IDC_COMBO_ACTIONS, m_lstActions); DDX_Check(pDX, IDC_CHECK_CHECKED, m_bChecked); DDX_Check(pDX, IDC_CHECK_ENABLED, m_bEnabled); DDX_Check(pDX, IDC_CHECK_VISIBLE, m_bVisible); DDX_Text(pDX, IDC_EDIT_CAPTION, m_strCaption); DDX_Text(pDX, IDC_EDIT_DESCRIPTION, m_strDescription); DDX_Text(pDX, IDC_EDIT_TOOLTIP, m_strTooltip); // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CActionSampleView, CFormView) //{{AFX_MSG_MAP(CActionSampleView) // NOTE - the ClassWizard will add and remove mapping macros here. ON_CBN_SELCHANGE(IDC_COMBO_ACTIONS, OnComboActionsSelChanged) ON_BN_CLICKED(IDC_CHECK_VISIBLE, OnCheckVisible) ON_BN_CLICKED(IDC_CHECK_ENABLED, OnCheckEnabled) ON_BN_CLICKED(IDC_CHECK_CHECKED, OnCheckChecked) ON_EN_CHANGE(IDC_EDIT_CAPTION, OnChangeEditCaption) ON_EN_CHANGE(IDC_EDIT_TOOLTIP, OnChangeEditTooltip) ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnChangeEditDescription) ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad) ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave) ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CActionSampleView diagnostics #ifdef _DEBUG void CActionSampleView::AssertValid() const { CFormView::AssertValid(); } void CActionSampleView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CActionSampleView message handlers void CActionSampleView::OnInitialUpdate() { CFormView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class CXTPFrameWnd* pFrame = (CXTPFrameWnd*)GetParentFrame(); CXTPCommandBars* pCommandBars = pFrame->GetCommandBars(); m_pActions = pCommandBars->GetActions(); FillActionsCombos(); OnComboActionsSelChanged(); } void CActionSampleView::OnComboActionsSelChanged() { int nSel = m_lstActions.GetCurSel(); GetDlgItem(IDC_CHECK_VISIBLE)->EnableWindow(nSel != CB_ERR); GetDlgItem(IDC_CHECK_ENABLED)->EnableWindow(nSel != CB_ERR); GetDlgItem(IDC_CHECK_CHECKED)->EnableWindow(nSel != CB_ERR); GetDlgItem(IDC_EDIT_CAPTION)->EnableWindow(nSel != CB_ERR); GetDlgItem(IDC_EDIT_TOOLTIP)->EnableWindow(nSel != CB_ERR); GetDlgItem(IDC_EDIT_DESCRIPTION)->EnableWindow(nSel != CB_ERR); if (nSel == CB_ERR) return; CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData(nSel); m_bVisible = pAction->IsVisible(); m_bEnabled = pAction->GetEnabled(); m_bChecked = pAction->GetChecked(); m_strCaption = pAction->GetCaption(); m_strTooltip = pAction->GetTooltip(); m_strDescription = pAction->GetDescription(); UpdateData(FALSE); } void CActionSampleView::OnCheckVisible() { UpdateData(); CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData( m_lstActions.GetCurSel()); pAction->SetVisible(m_bVisible); } void CActionSampleView::OnCheckEnabled() { UpdateData(); CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData( m_lstActions.GetCurSel()); pAction->SetEnabled(m_bEnabled); } void CActionSampleView::OnCheckChecked() { UpdateData(); CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData( m_lstActions.GetCurSel()); pAction->SetChecked(m_bChecked); } void CActionSampleView::OnChangeEditCaption() { UpdateData(); CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData( m_lstActions.GetCurSel()); pAction->SetCaption(m_strCaption); } void CActionSampleView::OnChangeEditTooltip() { UpdateData(); CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData( m_lstActions.GetCurSel()); pAction->SetTooltip(m_strTooltip); } void CActionSampleView::OnChangeEditDescription() { UpdateData(); CXTPControlAction* pAction = (CXTPControlAction*)m_lstActions.GetItemData( m_lstActions.GetCurSel()); pAction->SetDescription(m_strDescription); } void CActionSampleView::OnButtonLoad() { CString strFilter = _T("XML Document(*.xml)|*.xml|All files (*.*)|*.*||"); CFileDialog fd(TRUE, _T("xml"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter); if (fd.DoModal() == IDOK) { CXTPPropExchangeXMLNode px(TRUE, 0, _T("Settings")); if (!px.LoadFromFile(fd.GetPathName())) return; CXTPFrameWnd* pFrame = (CXTPFrameWnd*)GetParentFrame(); CXTPCommandBars* pCommandBars = pFrame->GetCommandBars(); XTP_COMMANDBARS_PROPEXCHANGE_PARAM param; param.bSaveOriginalControls = FALSE; param.bSerializeControls = FALSE; param.bSerializeOptions = FALSE; param.bSerializeLayout = FALSE; param.bSerializeActions = TRUE; pCommandBars->DoPropExchange(&px, ¶m); OnComboActionsSelChanged(); pCommandBars->RedrawCommandBars(); } } void CActionSampleView::OnButtonSave() { CString strFilter = _T("XML Document(*.xml)|*.xml|All files (*.*)|*.*||"); CFileDialog fd(FALSE, _T("xml"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFilter); if (fd.DoModal() == IDOK) { CXTPPropExchangeXMLNode px(FALSE, 0, _T("Settings")); CXTPFrameWnd* pFrame = (CXTPFrameWnd*)GetParentFrame(); CXTPCommandBars* pCommandBars = pFrame->GetCommandBars(); XTP_COMMANDBARS_PROPEXCHANGE_PARAM param; param.bSaveOriginalControls = FALSE; param.bSerializeControls = FALSE; param.bSerializeOptions = FALSE; param.bSerializeLayout = FALSE; param.bSerializeActions = TRUE; pCommandBars->DoPropExchange(&px, ¶m); px.SaveToFile(fd.GetPathName()); } } ////////////////////////////////////////////////////////////////// void CActionSampleView::FillActionsCombos() { for (int i = 0; i < m_pActions->GetCount(); i++) { CXTPControlAction* pAction = m_pActions->GetAt(i); CString strCaption; strCaption.Format(_T("%i - %s"), pAction->GetID(), (LPCTSTR)pAction->GetCaption()); int nIndex = m_lstActions.AddString(strCaption); m_lstActions.SetItemData(nIndex, (DWORD_PTR)pAction); _ASSERTE(m_pActions->FindAction(pAction->GetID())); } } HBRUSH CActionSampleView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { CFormView::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC) { pDC->SetTextColor(m_clrText); pDC->SetBkMode(TRANSPARENT); } return m_brush; } void CActionSampleView::RefreshMetrics(int m_Theme) { m_brush.DeleteObject(); COLORREF clrBrush = ::GetSysColor(COLOR_3DFACE); m_clrText = RGB(0, 0, 0); switch (m_Theme) { case xtpThemeDlgVisualStudio2008: case xtpThemeDlgVisualStudio2010: case xtpThemeDlgOffice2003: case xtpThemeDlgOffice2007: case xtpThemeDlgOffice2010: clrBrush = XTPIniColor(_T("Toolbar"), _T("DockBarFace"), RGB(255, 255, 255)); m_clrText = XTPIniColor(_T("Toolbar"), _T("MenuBarText"), RGB(255, 255, 255)); break; case xtpThemeDlgOffice2013: case xtpThemeDlgOffice2016: case xtpThemeDlgVisualStudio2012: case xtpThemeDlgVisualStudio2015: case xtpThemeDlgVisualStudio2017: case xtpThemeDlgVisualStudio2019: case xtpThemeDlgVisualStudio2022: case xtpThemeDlgNativeWindows10: case xtpThemeDlgNativeWindows11: clrBrush = XTPIniColor(_T("CommandBars"), _T("Back"), RGB(255, 255, 255)); m_clrText = XTPIniColor(_T("CommandBars.Menu"), _T("ButtonText"), RGB(255, 255, 255)); break; default: break; } m_brush.CreateSolidBrush(clrBrush); }