/** * @file XTPNewToolbarDlg.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "Controls/Resource.h" #include "Common/XTPVC80Helpers.h" #include "Common/XTPCasting.h" #include "Common/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPDrawHelpers.h" #include "Common/XTPHookManager.h" #include "Common/XTPResourceManager.h" #include "Common/XTPColorManager.h" #include "Common/XTPResourceImage.h" #include "Common/XTPMaskEditT.h" #include "Common/ScrollBar/XTPScrollBase.h" #include "Common/ScrollBar/XTPScrollBarCtrl.h" #include "Common/ScrollBar/XTPScrollable.h" #include "Controls/Util/XTPControlTheme.h" #include "Controls/Resize/XTPResizeRect.h" #include "Controls/Resize/XTPResizePoint.h" #include "Controls/Resize/XTPResize.h" #include "Controls/Resize/XTPResizeDialog.h" #include "Controls/Button/XTPButton.h" #include "Controls/Edit/XTPEdit.h" #include "Controls/Dialog/XTPDialogBase.h" #include "Controls/Dialog/XTPNewToolbarDlg.h" #ifdef _XTP_INCLUDE_COMMANDBARS # include "CommandBars/Resource.h" # include "CommandBars/XTPCommandBarsDefines.h" # include "CommandBars/XTPPaintManager.h" # include "CommandBars/XTPShortcutManager.h" # include "CommandBars/XTPCommandBars.h" # include "CommandBars/XTPCommandBar.h" # include "CommandBars/XTPToolBar.h" # include "CommandBars/XTPMenuBar.h" # include "CommandBars/XTPMenuTitleBar.h" # include "CommandBars/XTPControl.h" # include "CommandBars/XTPControlEdit.h" #endif #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #ifdef _XTP_INCLUDE_COMMANDBARS ///////////////////////////////////////////////////////////////////////////// // CXTPNewToolbarDlg dialog CXTPNewToolbarDlg::CXTPNewToolbarDlg(CWnd* pParent, CXTPCommandBars* pCommandBars, CXTPCommandBar* pCommandBar) : m_pCommandBar(pCommandBar) , m_pCommandBars(pCommandBars) , m_theme(xtpControlThemeDefault) { InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(XTP_IDD_NEWTOOLBAR), pParent); m_strToolbar = _T(""); m_nNewID = 0; } void CXTPNewToolbarDlg::DoDataExchange(CDataExchange* pDX) { CXTPDialogEx::DoDataExchange(pDX); //{{AFX_DATA_MAP(CXTPNewToolbarDlg) DDX_Text(pDX, XTP_IDC_EDIT_TOOLBARNAME, m_strToolbar); DDX_Control(pDX, IDOK, m_btnOk); DDX_Control(pDX, IDCANCEL, m_btnCancel); DDX_Control(pDX, XTP_IDC_EDIT_TOOLBARNAME, m_edit); //}}AFX_DATA_MAP } # include "Common/Base/Diagnostic/XTPBeginAfxMap.h" BEGIN_MESSAGE_MAP(CXTPNewToolbarDlg, CXTPDialogEx) //{{AFX_MSG_MAP(CXTPNewToolbarDlg) ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() # include "Common/Base/Diagnostic/XTPEndAfxMap.h" ///////////////////////////////////////////////////////////////////////////// // CXTPNewToolbarDlg message handlers BOOL CXTPNewToolbarDlg::OnInitDialog() { CXTPDialogEx::OnInitDialog(); InitCommandBars(); GetCommandBars()->EnableFrameTheme(); # ifdef _XTP_ACTIVEX if (m_theme == xtpControlThemeOffice2013) GetCommandBars()->SetTheme(xtpThemeOffice2013); if (m_theme == xtpControlThemeOffice2016) GetCommandBars()->SetTheme(xtpThemeOffice2016); if (m_theme == xtpControlThemeVisualStudio2015) GetCommandBars()->SetTheme(xtpThemeVisualStudio2015); if (m_theme == xtpControlThemeVisualStudio2017) GetCommandBars()->SetTheme(xtpThemeVisualStudio2017); if (m_theme == xtpControlThemeVisualStudio2019) GetCommandBars()->SetTheme(xtpThemeVisualStudio2019); if (m_theme == xtpControlThemeVisualStudio2022) GetCommandBars()->SetTheme(xtpThemeVisualStudio2022); if (m_theme == xtpControlThemeNativeWindows10) GetCommandBars()->SetTheme(xtpThemeNativeWindows10); # endif if (m_pCommandBar) { m_strToolbar = m_pCommandBar->GetTitle(); UpdateData(FALSE); CString strWindowText; XTPResourceManager()->LoadString(&strWindowText, XTP_IDS_RENAMETOOLBAR); SetWindowText(strWindowText); } else { SetSuggestedName(); } ((CEdit*)GetDlgItem(XTP_IDC_EDIT_TOOLBARNAME))->SetLimitText(255); return TRUE; } void CXTPNewToolbarDlg::SetSuggestedName() { CString szMsg; XTPResourceManager()->LoadString(&szMsg, XTP_IDS_CUSTOM_BAR); int iNewID = 1; CString strCustom; strCustom.Format(szMsg, iNewID); int nCount = m_pCommandBars->GetCount(); int nIndex = 0; while (nIndex < nCount) { CXTPToolBar* pBar = m_pCommandBars->GetAt(nIndex); _ASSERTE(pBar != NULL); if (pBar && strCustom.Compare(pBar->GetTitle()) == 0) { strCustom.Format(szMsg, iNewID++); nIndex = 0; continue; } nIndex++; } m_strToolbar = strCustom; UpdateData(FALSE); } void CXTPNewToolbarDlg::OnOK() { UpdateData(); // If no text was entered, alert user. if (m_strToolbar.IsEmpty()) { XTPResourceManager()->ShowMessageBox(XTP_IDS_ERROR_BLANKNAME, MB_ICONSTOP); return; } m_nNewID = AFX_IDW_CONTROLBAR_FIRST; // Loop through all of the existing control bars to find // an available ID to use. int nCount = m_pCommandBars->GetCount(); int nIndex = 0; while (nIndex < nCount) { CXTPToolBar* pBar = m_pCommandBars->GetAt(nIndex); _ASSERTE(pBar != NULL); // We found a control bar with the same ID as m_nNewID, increment // m_nNewID and reset the position back to the head. if (pBar && m_pCommandBar == NULL && pBar->GetBarID() == m_nNewID) { m_nNewID++; // If m_nNewID is greater than the maximum number of allowed // custom commands, alert the user and abort. if ((int)m_nNewID >= AFX_IDW_CONTROLBAR_LAST) { XTPResourceManager()->ShowMessageBox(XTP_IDS_ERROR_LIMIT, MB_ICONSTOP); CXTPDialogEx::OnCancel(); return; } nIndex = 0; continue; } // Now check to see if the title for the toolbar has already // been used, if so, alert the user and return. if (pBar && m_pCommandBar != pBar && m_strToolbar.Compare(pBar->GetTitle()) == 0) { CString strName, strError; CXTPResourceManager::AssertValid( XTPResourceManager()->LoadString(&strError, XTP_IDS_ERROR_EXISTS)); strName.Format(strError, (LPCTSTR)m_strToolbar); XTPResourceManager()->ShowMessageBox(strName, MB_ICONSTOP); return; } nIndex++; } CXTPDialogEx::OnOK(); // success! } void CXTPNewToolbarDlg::SetTheme(XTPControlTheme theme) { m_theme = theme; m_btnOk.SetTheme(theme); m_btnCancel.SetTheme(theme); m_edit.SetTheme(theme); if (theme == xtpControlThemeResource) { m_brBack.CreateSolidBrush( XTPIniColor(_T("Ribbon"), _T("RibbonFace"), GetXtremeColor(COLOR_WINDOW))); m_clrText = XTPIniColor(_T("CommandBars.Toolbar"), _T("ButtonText"), GetXtremeColor(COLOR_WINDOWTEXT)); } if (theme >= xtpControlThemeOffice2013) { m_brBack.CreateSolidBrush( XTPIniColor(_T("CommandBars"), _T("Back"), GetXtremeColor(COLOR_WINDOW))); m_clrText = XTPIniColor(_T("CommandBars.Toolbar"), _T("ButtonText"), GetXtremeColor(COLOR_WINDOWTEXT)); } } BOOL CXTPNewToolbarDlg::OnEraseBkgnd(CDC* pDC) { if (m_brBack.GetSafeHandle()) { CXTPClientRect rc(this); ::FillRect(pDC->GetSafeHdc(), rc, m_brBack); return TRUE; } return CXTPDialogEx::OnEraseBkgnd(pDC); } HBRUSH CXTPNewToolbarDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hBrush = CXTPDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor == CTLCOLOR_STATIC) { if (m_theme != xtpControlThemeDefault) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(m_clrText); hBrush = m_brBack; } } return hBrush; } #endif