XTPCustomizeMenusPage.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:8k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPCustomizeMenusPage.cpp : implementation of the CXTPCustomizeMenusPage class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Resource.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "XTPCustomizeMenusPage.h"
  24. #include "XTPToolBar.h"
  25. #include "XTPPopupBar.h"
  26. #include "XTPCommandBars.h"
  27. #include "XTPCustomizeSheet.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. class CXTPFloatingPopupBar : public CXTPToolBar
  34. {
  35. DECLARE_XTP_COMMANDBAR(CXTPFloatingPopupBar)
  36. public:
  37. CXTPFloatingPopupBar()
  38. {
  39. m_barType = xtpBarTypePopup;
  40. SetWidth(0);
  41. }
  42. };
  43. IMPLEMENT_XTP_COMMANDBAR(CXTPFloatingPopupBar, CXTPToolBar)
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CXTPCustomizeMenusPage property page
  46. CXTPCustomizeMenusPage::CXTPCustomizeMenusPage(CXTPCustomizeSheet* pSheet)
  47. : CPropertyPage(CXTPCustomizeMenusPage::IDD), m_pSheet(pSheet)
  48. {
  49. //{{AFX_DATA_INIT(CXTPCustomizeMenusPage)
  50. //}}AFX_DATA_INIT
  51. m_pContextMenu = NULL;
  52. m_ptContextMenu = CPoint(0, 0);
  53. }
  54. CXTPCustomizeMenusPage::~CXTPCustomizeMenusPage()
  55. {
  56. }
  57. void CXTPCustomizeMenusPage::DoDataExchange(CDataExchange* pDX)
  58. {
  59. CPropertyPage::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(CXTPCustomizeMenusPage)
  61. DDX_Control(pDX, XTP_IDC_STATIC_ICON, m_wndIcon);
  62. DDX_Control(pDX, XTP_IDC_COMBO_CONTEXTMENUS, m_cmbContextMenus);
  63. DDX_Control(pDX, XTP_IDC_COMBO_APPMENUS, m_cmbAppMenus);
  64. DDX_Control(pDX, XTP_IDC_STATIC_APPLICATIONMENUS, m_wndApplicationMenus);
  65. DDX_Control(pDX, XTP_IDC_STATIC_CONTEXTMENUS, m_wndContextMenus);
  66. //}}AFX_DATA_MAP
  67. }
  68. BEGIN_MESSAGE_MAP(CXTPCustomizeMenusPage, CPropertyPage)
  69. //{{AFX_MSG_MAP(CXTPCustomizeMenusPage)
  70. ON_CBN_SELCHANGE(XTP_IDC_COMBO_APPMENUS, OnSelectionChangedAppmenus)
  71. ON_CBN_SELCHANGE(XTP_IDC_COMBO_CONTEXTMENUS, OnSelectionChangedContextmenus)
  72. ON_WM_DESTROY()
  73. ON_BN_CLICKED(XTP_IDC_BUTTON_RESETCONTEXT, OnButtonResetContextMenu)
  74. ON_BN_CLICKED(XTP_IDC_BUTTON_RESETAPP, OnButtonResetAppMenu)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CXTPCustomizeMenusPage message handlers
  79. BOOL CXTPCustomizeMenusPage::OnInitDialog()
  80. {
  81. CPropertyPage::OnInitDialog();
  82. CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars();
  83. CString strDefaultMenu;
  84. GetDlgItemText(XTP_IDC_STATIC_DESCRIPTION, strDefaultMenu);
  85. if (_tcschr(strDefaultMenu, _T('n')) != NULL)
  86. {
  87. AfxExtractSubString(m_strDefaultMenuDesc, strDefaultMenu, 1);
  88. AfxExtractSubString(m_strDefaultMenu, strDefaultMenu, 0);
  89. }
  90. else
  91. {
  92. m_strDefaultMenu = m_strDefaultMenuDesc = strDefaultMenu;
  93. }
  94. int nIndex = m_cmbAppMenus.AddString(m_strDefaultMenu);
  95. m_cmbAppMenus.SetItemData(nIndex, 0);
  96. int nCurSel = 0;
  97. if (pCommandBars->GetMenuBar() && ((pCommandBars->GetMenuBar()->GetFlags() & xtpFlagIgnoreSetMenuMessage) == 0))
  98. {
  99. CXTPMenuBar* pMenuBar = pCommandBars->GetMenuBar();
  100. CXTPMenuBarMDIMenus* pMDIControls = pMenuBar->GetMDIMenus();
  101. POSITION pos = pMDIControls->GetStartPosition();
  102. CXTPMenuBarMDIMenuInfo* pInfo;
  103. while (pos)
  104. {
  105. pMDIControls->GetNextMenu(pos, pInfo);
  106. if (pInfo->m_nIDResource == pMenuBar->GetDefaultMenuResource())
  107. continue;
  108. if (!pInfo->m_strTitle.IsEmpty())
  109. {
  110. nIndex = m_cmbAppMenus.AddString(pInfo->m_strTitle);
  111. m_cmbAppMenus.SetItemData(nIndex, (DWORD_PTR)pInfo);
  112. if (pInfo->m_nIDResource == pMenuBar->GetCurrentMenuResource())
  113. {
  114. nCurSel = nIndex;
  115. }
  116. }
  117. }
  118. }
  119. m_cmbAppMenus.SetCurSel(nCurSel);
  120. OnSelectionChangedAppmenus();
  121. nIndex = m_cmbContextMenus.AddString(_T(""));
  122. m_cmbContextMenus.SetItemData(nIndex, 0);
  123. for (int i = 0; i < pCommandBars->GetContextMenus()->GetCount(); i++)
  124. {
  125. CXTPPopupBar* pPopupBar = (CXTPPopupBar*)pCommandBars->GetContextMenus()->GetAt(i);
  126. nIndex = m_cmbContextMenus.AddString(pPopupBar->GetTitle());
  127. m_cmbContextMenus.SetItemData(nIndex, (DWORD_PTR)pPopupBar);
  128. }
  129. m_cmbContextMenus.SetCurSel(0);
  130. OnSelectionChangedContextmenus();
  131. return TRUE;  // return TRUE unless you set the focus to a control
  132.               // EXCEPTION: OCX Property Pages should return FALSE
  133. }
  134. void CXTPCustomizeMenusPage::OnSelectionChangedAppmenus()
  135. {
  136. int nSel = m_cmbAppMenus.GetCurSel();
  137. if (nSel == CB_ERR)
  138. return;
  139. CXTPMenuBar* pMenuBar = m_pSheet->GetCommandBars()->GetMenuBar();
  140. UINT nIDResource = pMenuBar->GetDefaultMenuResource();
  141. CXTPMenuBarMDIMenuInfo* pInfo = (CXTPMenuBarMDIMenuInfo*)m_cmbAppMenus.GetItemData(nSel);
  142. if (pInfo)
  143. {
  144. SetDlgItemText(XTP_IDC_STATIC_DESCRIPTION, pInfo->m_strDescription);
  145. nIDResource = pInfo->m_nIDResource;
  146. }
  147. else
  148. {
  149. SetDlgItemText(XTP_IDC_STATIC_DESCRIPTION, m_strDefaultMenuDesc);
  150. }
  151. HICON hIcon = NULL;
  152. if (pInfo)
  153. {
  154. hIcon = pInfo->m_hIcon;
  155. }
  156. else
  157. {
  158. HWND hWnd = m_pSheet->GetCommandBars()->GetSite()->GetSafeHwnd();
  159. hIcon = (HICON)::SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
  160. if (!hIcon) hIcon = (HICON)(ULONG_PTR)::GetClassLongPtr(hWnd, GCLP_HICON);
  161. }
  162. if (hIcon)
  163. {
  164. m_wndIcon.SetIcon(hIcon);
  165. }
  166. if (m_cmbAppMenus.GetCount() > 1)
  167. {
  168. pMenuBar->SwitchMDIMenu(nIDResource);
  169. }
  170. }
  171. void CXTPCustomizeMenusPage::CommitContextMenu()
  172. {
  173. CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars();
  174. if (m_pContextMenu)
  175. {
  176. CXTPPopupBar* pPopupBar = (CXTPPopupBar*)m_pContextMenu->GetCommandBarData();
  177. CXTPControls* pControls = m_pContextMenu->GetControls()->Duplicate();
  178. pPopupBar->SetControls(pControls);
  179. m_ptContextMenu = CXTPWindowRect(m_pContextMenu).TopLeft();
  180. pCommandBars->Remove(m_pContextMenu);
  181. m_pContextMenu = NULL;
  182. }
  183. }
  184. void CXTPCustomizeMenusPage::OnSelectionChangedContextmenus()
  185. {
  186. CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars();
  187. CommitContextMenu();
  188. int nSel = m_cmbContextMenus.GetCurSel();
  189. if (nSel < 1)
  190. {
  191. GetDlgItem(XTP_IDC_BUTTON_RESETCONTEXT)->EnableWindow(FALSE);
  192. return;
  193. }
  194. GetDlgItem(XTP_IDC_BUTTON_RESETCONTEXT)->EnableWindow(TRUE);
  195. CXTPPopupBar* pPopupBar = (CXTPPopupBar*)m_cmbContextMenus.GetItemData(nSel);
  196. CXTPToolBar* pContextMenu = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop, RUNTIME_CLASS(CXTPFloatingPopupBar));
  197. if (!pContextMenu)
  198. {
  199. TRACE0("Failed to create toolbarn");
  200. return;
  201. }
  202. CXTPControls* pControls = pPopupBar->GetControls()->Duplicate();
  203. pContextMenu->SetControls(pControls);
  204. pContextMenu->SetBarID(pPopupBar->GetBarID());
  205. pContextMenu->SetTitle(pPopupBar->GetTitle());
  206. pContextMenu->SetCustomizeDialogPresent(FALSE);
  207. pContextMenu->SetPosition(xtpBarFloating);
  208. pContextMenu->EnableDocking(xtpFlagFloating);
  209. pContextMenu->OnRecalcLayout();
  210. CXTPWindowRect rcContext(pContextMenu);
  211. CXTPWindowRect rcParent(GetParent());
  212. CPoint pt = m_ptContextMenu;
  213. if (pt == CPoint(0, 0))
  214. pt = CPoint(rcParent.left - rcContext.Width(), rcParent.top);
  215. pContextMenu->MoveWindow(pt.x, pt.y, rcContext.Width(), rcContext.Height());
  216. m_pContextMenu = pContextMenu;
  217. pContextMenu->SetCommandBarData((DWORD_PTR)pPopupBar);
  218. pContextMenu->OnUpdateCmdUI();
  219. }
  220. void CXTPCustomizeMenusPage::OnDestroy()
  221. {
  222. CommitContextMenu();
  223. if (m_cmbAppMenus.GetCount() > 1)
  224. {
  225. CXTPMenuBar* pMenuBar = m_pSheet->GetCommandBars()->GetMenuBar();
  226. if (pMenuBar) pMenuBar->SwitchActiveMenu();
  227. }
  228. CPropertyPage::OnDestroy();
  229. }
  230. void CXTPCustomizeMenusPage::OnButtonResetContextMenu()
  231. {
  232. if (m_pContextMenu)
  233. {
  234. m_pContextMenu->Reset(TRUE);
  235. }
  236. }
  237. void CXTPCustomizeMenusPage::OnButtonResetAppMenu()
  238. {
  239. CXTPToolBar* pMenuBar = m_pSheet->GetCommandBars()->GetMenuBar();
  240. pMenuBar->Reset(TRUE);
  241. }