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

对话框与窗口

开发平台:

Visual C++

  1. // XTPRibbonCustomizeQuickAccessPage.cpp: implementation of the CXTPRibbonCustomizeQuickAccessPage class.
  2. //
  3. // This file is a part of the XTREME RIBBON 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/XTPResourceManager.h"
  23. #include "CommandBars/XTPControls.h"
  24. #include "CommandBars/XTPControl.h"
  25. #include "CommandBars/XTPControlPopup.h"
  26. #include "CommandBars/Resource.h"
  27. #include "CommandBars/XTPCommandBars.h"
  28. #include "CommandBars/XTPCustomizeSheet.h"
  29. #include "CommandBars/XTPPaintManager.h"
  30. #include "XTPRibbonCustomizeQuickAccessPage.h"
  31. #include "XTPRibbonQuickAccessControls.h"
  32. #include "XTPRibbonBar.h"
  33. #ifdef _DEBUG
  34. #define new DEBUG_NEW
  35. #undef THIS_FILE
  36. static char THIS_FILE[] = __FILE__;
  37. #endif
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CXTPRibbonCustomizeQuickAccessPage property page
  40. CXTPRibbonCustomizeQuickAccessPage::CXTPRibbonCustomizeQuickAccessPage(CXTPCustomizeSheet* pSheet)
  41. :   CPropertyPage(XTP_IDD_RIBBONCUSTOMIZE_QUICKACCESS)
  42. {
  43. m_pSheet = pSheet;
  44. m_pCommandBars = pSheet->GetCommandBars();
  45. m_bShowQuickAccessBelow = FALSE;
  46. }
  47. CXTPRibbonCustomizeQuickAccessPage::~CXTPRibbonCustomizeQuickAccessPage()
  48. {
  49. for (int i = 0; i < m_arrCategories.GetSize(); i++)
  50. {
  51. delete m_arrCategories[i];
  52. }
  53. }
  54. void CXTPRibbonCustomizeQuickAccessPage::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CPropertyPage::DoDataExchange(pDX);
  57. //{{AFX_DATA_MAP(CXTPRibbonCustomizeQuickAccessPage)
  58. DDX_Control(pDX, XTP_IDC_RIBBONCOMBO_CATEGORIES, m_lstCategories);
  59. DDX_Control(pDX, XTP_IDC_RIBBONLIST_QUICKACCESS, m_lstQuickAccess);
  60. DDX_Control(pDX, XTP_IDC_RIBBONLIST_COMMANDS, m_lstCommands);
  61. DDX_Check(pDX, XTP_IDC_RIBBONCHECK_SHOWQUICKACCESSBELOW, m_bShowQuickAccessBelow);
  62. //}}AFX_DATA_MAP
  63. }
  64. BEGIN_MESSAGE_MAP(CXTPRibbonCustomizeQuickAccessPage, CPropertyPage)
  65. //{{AFX_MSG_MAP(CXTPRibbonCustomizeQuickAccessPage)
  66. ON_BN_CLICKED(XTP_IDC_RIBBONCHECK_SHOWQUICKACCESSBELOW, OnCheckShowQuickAccessBelow)
  67. ON_LBN_SELCHANGE(XTP_IDC_RIBBONCOMBO_CATEGORIES, OnCategoriesSelectionChanged)
  68. ON_LBN_DBLCLK(XTP_IDC_RIBBONLIST_QUICKACCESS, OnDblclkListQuickAccess)
  69. ON_LBN_DBLCLK(XTP_IDC_RIBBONLIST_COMMANDS, OnDblclkListCommands)
  70. ON_BN_CLICKED(XTP_IDC_RIBBONBUTTON_ADD, OnButtonAdd)
  71. ON_BN_CLICKED(XTP_IDC_RIBBONBUTTON_REMOVE, OnButtonRemove)
  72. ON_BN_CLICKED(XTP_IDC_RIBBONBUTTON_RESET, OnButtonReset)
  73. ON_LBN_SELCHANGE(XTP_IDC_RIBBONLIST_COMMANDS, OnCommandsSelectionChanged)
  74. ON_LBN_SELCHANGE(XTP_IDC_RIBBONLIST_QUICKACCESS, OnQuickAccessSelectionChanged)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. CXTPRibbonBar* CXTPRibbonCustomizeQuickAccessPage::GetRibbonBar()
  78. {
  79. CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, m_pCommandBars->GetMenuBar());
  80. ASSERT(pRibbonBar);
  81. return pRibbonBar;
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CXTPRibbonCustomizeQuickAccessPage message handlers
  85. BOOL CXTPRibbonCustomizeQuickAccessPage::OnInitDialog()
  86. {
  87. CPropertyPage::OnInitDialog();
  88. for (int i = 0; i < m_arrCategories.GetSize(); i++)
  89. {
  90. int nIndex = m_lstCategories.AddString(m_arrCategories[i]->strCategory);
  91. m_lstCategories.SetItemData(nIndex, i);
  92. if (i == 0) m_lstCategories.SetCurSel(0);
  93. }
  94. CSize sz = m_pCommandBars->GetPaintManager()->DrawListBoxControl(NULL, NULL, CRect(0, 0, 0, 0), FALSE, FALSE, m_pCommandBars);
  95. m_lstCommands.SetItemHeight(-1, sz.cy);
  96. m_lstQuickAccess.SetItemHeight(-1, sz.cy);
  97. m_lstCommands.m_pCommandBars = m_pCommandBars;
  98. m_lstQuickAccess.m_pCommandBars = m_pCommandBars;
  99. OnCategoriesSelectionChanged();
  100. RefreshQuickAccessList();
  101. m_bShowQuickAccessBelow = GetRibbonBar()->IsQuickAccessBelowRibbon();
  102. UpdateData(FALSE);
  103. if (m_pCommandBars->IsLayoutRTL())
  104. {
  105. m_lstCommands.ModifyStyleEx(0, WS_EX_LAYOUTRTL);
  106. m_lstQuickAccess.ModifyStyleEx(0, WS_EX_LAYOUTRTL);
  107. m_lstCategories.ModifyStyleEx(0, WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR | WS_EX_RTLREADING);
  108. }
  109. return TRUE;  // return TRUE unless you set the focus to a control
  110.               // EXCEPTION: OCX Property Pages should return FALSE
  111. }
  112. void CXTPRibbonCustomizeQuickAccessPage::OnCheckShowQuickAccessBelow()
  113. {
  114. UpdateData();
  115. GetRibbonBar()->ShowQuickAccessBelowRibbon(m_bShowQuickAccessBelow);
  116. }
  117. void CXTPRibbonCustomizeQuickAccessPage::RefreshQuickAccessList()
  118. {
  119. m_lstQuickAccess.SetRedraw(FALSE);
  120. int nTopIndex = m_lstQuickAccess.GetTopIndex();
  121. m_lstQuickAccess.ResetContent();
  122. CXTPControls* pControls = GetRibbonBar()->GetQuickAccessControls();
  123. for (int i = 0; i < pControls->GetCount(); i++)
  124. {
  125. CXTPControl* pControl = pControls->GetAt(i);
  126. if (!pControl->IsVisible())
  127. continue;
  128. m_lstQuickAccess.SendMessage(LB_INSERTSTRING, m_lstQuickAccess.GetCount(), (LPARAM)pControl);
  129. }
  130. m_lstQuickAccess.SetTopIndex(nTopIndex);
  131. m_lstQuickAccess.SetRedraw(TRUE);
  132. OnQuickAccessSelectionChanged();
  133. OnCommandsSelectionChanged();
  134. }
  135. void CXTPRibbonCustomizeQuickAccessPage::OnCategoriesSelectionChanged()
  136. {
  137. m_lstCommands.ResetContent();
  138. int nIndex = m_lstCategories.GetCurSel();
  139. if (nIndex == LB_ERR)
  140. return;
  141. XTP_COMMANDBARS_CATEGORYINFO* pInfo = GetCategoryInfo((int)m_lstCategories.GetItemData(nIndex));
  142. if (pInfo == NULL)
  143. return;
  144. for (int i = 0; i < pInfo->pControls->GetCount(); i++)
  145. {
  146. CXTPControl* pControl = pInfo->pControls->GetAt(i);
  147. m_lstCommands.SendMessage(LB_INSERTSTRING, m_lstCommands.GetCount(), (LPARAM)pControl);
  148. }
  149. OnCommandsSelectionChanged();
  150. }
  151. XTP_COMMANDBARS_CATEGORYINFO* CXTPRibbonCustomizeQuickAccessPage::FindCategory(LPCTSTR strCategory) const
  152. {
  153. for (int i = 0; i < m_arrCategories.GetSize(); i++)
  154. {
  155. if (m_arrCategories[i]->strCategory.Compare(strCategory) == 0)
  156. return m_arrCategories[i];
  157. }
  158. return NULL;
  159. }
  160. XTP_COMMANDBARS_CATEGORYINFO* CXTPRibbonCustomizeQuickAccessPage::GetCategoryInfo(int nIndex)
  161. {
  162. if (nIndex >= 0 && nIndex < m_arrCategories.GetSize())
  163. return m_arrCategories[nIndex];
  164. return NULL;
  165. }
  166. BOOL CXTPRibbonCustomizeQuickAccessPage::AddCategory(LPCTSTR strCategory, CMenu* pMenu, BOOL bListSubItems)
  167. {
  168. CXTPControls* pCategoryControls = InsertCategory(strCategory);
  169. int nCount = pMenu->GetMenuItemCount();
  170. for (int i = 0; i < nCount; i++)
  171. {
  172. if (pMenu->GetMenuItemID(i) > 0)
  173. {
  174. CXTPControlPopup* pControl = DYNAMIC_DOWNCAST(CXTPControlPopup,
  175. pCategoryControls->AddMenuItem(pMenu, i));
  176. if (pControl && bListSubItems)
  177. {
  178. CXTPControls* pControls = pControl->GetCommandBar()->GetControls();
  179. for (int j = 0; j < pControls->GetCount(); j++)
  180. {
  181. pCategoryControls->AddClone(pControls->GetAt(j));
  182. }
  183. }
  184. }
  185. }
  186. return TRUE;
  187. }
  188. BOOL CXTPRibbonCustomizeQuickAccessPage::AddCategories(UINT nIDResource, BOOL bListSubItems)
  189. {
  190. CMenu menu;
  191. if (!XTPResourceManager()->LoadMenu(&menu, nIDResource))
  192. return FALSE;
  193. int nCount = menu.GetMenuItemCount();
  194. for (int i = 0; i < nCount; i++)
  195. {
  196. CString strCategory;
  197. if (menu.GetMenuString(i, strCategory, MF_BYPOSITION) > 0)
  198. {
  199. CMenu* pMenu = menu.GetSubMenu(i);
  200. if (pMenu)
  201. {
  202. CXTPPaintManager::StripMnemonics(strCategory);
  203. if (!AddCategory(strCategory, pMenu, bListSubItems))
  204. return FALSE;
  205. }
  206. }
  207. }
  208. return TRUE;
  209. }
  210. BOOL CXTPRibbonCustomizeQuickAccessPage::AddCategories(CXTPControls* pControls)
  211. {
  212. for (int i = 0; i < pControls->GetCount(); i++)
  213. {
  214. CXTPControl* pControl = pControls->GetAt(i);
  215. CString strCategory = pControl->GetCategory();
  216. if (!strCategory.IsEmpty())
  217. {
  218. CXTPControls* pCategoryControls = InsertCategory(strCategory);
  219. pCategoryControls->AddClone(pControl);
  220. }
  221. }
  222. return TRUE;
  223. }
  224. CXTPControls* CXTPRibbonCustomizeQuickAccessPage::InsertCategory(LPCTSTR strCategory, int nIndex)
  225. {
  226. XTP_COMMANDBARS_CATEGORYINFO* pInfo = FindCategory(strCategory);
  227. if (!pInfo)
  228. {
  229. pInfo = new XTP_COMMANDBARS_CATEGORYINFO(strCategory, m_pSheet->GetCommandBars());
  230. m_arrCategories.InsertAt(nIndex == -1 ? m_arrCategories.GetSize() : nIndex, pInfo);
  231. }
  232. return pInfo->pControls;
  233. }
  234. CXTPControls* CXTPRibbonCustomizeQuickAccessPage::GetControls(LPCTSTR strCategory)
  235. {
  236. XTP_COMMANDBARS_CATEGORYINFO* pInfo = FindCategory(strCategory);
  237. return pInfo ? pInfo->pControls : NULL;
  238. }
  239. void CXTPRibbonCustomizeQuickAccessPage::OnDblclkListQuickAccess()
  240. {
  241. OnButtonRemove();
  242. }
  243. void CXTPRibbonCustomizeQuickAccessPage::OnDblclkListCommands()
  244. {
  245. OnButtonAdd();
  246. }
  247. void CXTPRibbonCustomizeQuickAccessPage::OnButtonAdd()
  248. {
  249. if (!GetDlgItem(XTP_IDC_RIBBONBUTTON_ADD)->IsWindowEnabled())
  250. return;
  251. if (m_lstCommands.GetCurSel() == LB_ERR)
  252. return;
  253. CXTPControl* pControl = (CXTPControl*)m_lstCommands.GetItemDataPtr(m_lstCommands.GetCurSel());
  254. if (!pControl)
  255. return;
  256. GetRibbonBar()->GetQuickAccessControls()->AddClone(pControl);
  257. GetRibbonBar()->OnRecalcLayout();
  258. RefreshQuickAccessList();
  259. m_lstQuickAccess.SetCurSel(m_lstQuickAccess.GetCount() - 1);
  260. }
  261. void CXTPRibbonCustomizeQuickAccessPage::OnButtonRemove()
  262. {
  263. if (m_lstQuickAccess.GetCurSel() == LB_ERR)
  264. return;
  265. CXTPControl* pControl = (CXTPControl*)m_lstQuickAccess.GetItemDataPtr(m_lstQuickAccess.GetCurSel());
  266. if (!pControl)
  267. return;
  268. GetRibbonBar()->GetQuickAccessControls()->Remove(pControl);
  269. GetRibbonBar()->OnRecalcLayout();
  270. RefreshQuickAccessList();
  271. }
  272. void CXTPRibbonCustomizeQuickAccessPage::OnButtonReset()
  273. {
  274. CString strPrompt;
  275. VERIFY(XTPResourceManager()->LoadString(&strPrompt, XTP_IDS_RIBBONCUSTOMIZE_CONFIRMRESET));
  276. if (m_pSheet->MessageBox(strPrompt, MB_ICONWARNING | MB_YESNO) != IDYES)
  277. return;
  278. GetRibbonBar()->GetQuickAccessControls()->Reset();
  279. RefreshQuickAccessList();
  280. }
  281. void CXTPRibbonCustomizeQuickAccessPage::OnCommandsSelectionChanged()
  282. {
  283. BOOL bEnabled = m_lstCommands.GetCurSel() != LB_ERR;
  284. if (bEnabled)
  285. {
  286. CXTPControl* pControl = (CXTPControl*)m_lstCommands.GetItemDataPtr(m_lstCommands.GetCurSel());
  287. bEnabled = GetRibbonBar()->IsAllowQuickAccessControl(pControl);
  288. }
  289. GetDlgItem(XTP_IDC_RIBBONBUTTON_ADD)->EnableWindow(bEnabled);
  290. }
  291. void CXTPRibbonCustomizeQuickAccessPage::OnQuickAccessSelectionChanged()
  292. {
  293. GetDlgItem(XTP_IDC_RIBBONBUTTON_REMOVE)->EnableWindow(m_lstQuickAccess.GetCurSel() != LB_ERR);
  294. }