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

对话框与窗口

开发平台:

Visual C++

  1. // PageMouse.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "styler.h"
  5. #include "pagemouse.h"
  6. #include "MouseManager.h"
  7. #include "StylerView.h"
  8. #include "MainFrm.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CPageMouse property page
  16. IMPLEMENT_DYNCREATE(CPageMouse, COptionsPage)
  17. CPageMouse::CPageMouse() 
  18. : COptionsPage(CPageMouse::IDD), m_wndAssign(GetMainFrame()->GetCommandBars()->GetShortcutManager())
  19. {
  20. m_wndAssign.m_bAllowDoubleKeyShortcuts = FALSE;
  21. //{{AFX_DATA_INIT(CPageMouse)
  22. //}}AFX_DATA_INIT
  23. }
  24. CPageMouse::~CPageMouse()
  25. {
  26. }
  27. void CPageMouse::DoDataExchange(CDataExchange* pDX)
  28. {
  29. COptionsPage::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CPageMouse)
  31. DDX_Control(pDX, IDC_EDIT_ASSIGN, m_wndAssign);
  32. DDX_Control(pDX, IDC_LIST_CURRENT, m_wndCurrent);
  33. DDX_Control(pDX, IDC_COMBO_MOUSE, m_cmbMouse);
  34. DDX_Control(pDX, IDC_COMBO_COMMAND, m_cmbCommands);
  35. DDX_Control(pDX, IDC_COMBO_AREA, m_cmbArea);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CPageMouse, COptionsPage)
  39. //{{AFX_MSG_MAP(CPageMouse)
  40. ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  41. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CPageMouse message handlers
  46. BOOL CPageMouse::OnInitDialog() 
  47. {
  48. COptionsPage::OnInitDialog();
  49. CXTPCommandBar* pMenuBar = GetMainFrame()->GetCommandBars()->GetMenuBar();
  50. ASSERT(pMenuBar);
  51. if (pMenuBar)
  52. {
  53. GetMenuStrings(pMenuBar, _T(""));
  54. m_mapCommands[ID_VIEW_LOCK] = "View.Lock";
  55. }
  56. UINT nID;
  57. CString strTitle;
  58. POSITION pos = m_mapCommands.GetStartPosition();
  59. while (pos != NULL)
  60. {
  61. m_mapCommands.GetNextAssoc( pos, nID, strTitle);
  62. m_cmbCommands.AddStringData(strTitle, nID);
  63. }
  64. m_cmbMouse.AddStringData(CMouseManager::GetMouseString(WM_LBUTTONDOWN), WM_LBUTTONDOWN);//"Left Button Click"
  65. m_cmbMouse.AddStringData(CMouseManager::GetMouseString(WM_RBUTTONDOWN), WM_RBUTTONDOWN);
  66. m_cmbMouse.AddStringData(CMouseManager::GetMouseString(WM_MBUTTONDOWN), WM_MBUTTONDOWN);
  67. m_cmbMouse.AddStringData(CMouseManager::GetMouseString(WM_LBUTTONDBLCLK), WM_LBUTTONDBLCLK);
  68. m_cmbMouse.AddStringData(CMouseManager::GetMouseString(WM_RBUTTONDBLCLK), WM_RBUTTONDBLCLK);
  69. m_cmbArea.AddStringData(_T("Tab"), MOUSE_AREA_TAB);
  70. m_cmbArea.AddStringData(_T("Tabbar"), MOUSE_AREA_TABBAR);
  71. m_cmbArea.AddStringData(_T("WebBrowser"), MOUSE_AREA_BROWSER);
  72. m_wndCurrent.ModifyStyle(0, LVS_SHOWSELALWAYS);
  73. m_wndCurrent.SetExtendedStyle(m_wndCurrent.GetExtendedStyle() | LVS_EX_FULLROWSELECT);
  74. m_wndCurrent.InsertColumn(0, _T("Mouse"), LVCFMT_LEFT, 100);
  75. m_wndCurrent.InsertColumn(1, _T("Key"), LVCFMT_LEFT, 60);
  76. m_wndCurrent.InsertColumn(2, _T("Area"), LVCFMT_LEFT, 50);
  77. m_wndCurrent.InsertColumn(3, _T("Command"), LVCFMT_LEFT, 123);
  78. m_wndAssign.m_bExtendedOnly = TRUE;
  79. RefreshList();
  80. return TRUE;  // return TRUE unless you set the focus to a control
  81.               // EXCEPTION: OCX Property Pages should return FALSE
  82. }
  83. void CPageMouse::GetMenuStrings(CXTPCommandBar* pBar, CString strPrefix)
  84. {
  85. int nCount = pBar->GetControls()->GetCount();
  86. for (int i = 0; i < nCount; i++)
  87. {
  88. CXTPControl* pControl = pBar->GetControls()->GetAt(i);
  89. CString strTitle = pControl->GetCaption();
  90. ConvertMenuItem(strTitle);
  91. if (!strTitle.IsEmpty())
  92. {
  93. if (IsPopupControlType(pControl->GetType()))
  94. {
  95. GetMenuStrings(((CXTPControlPopup*)pControl)->GetCommandBar(), strPrefix + strTitle + '.');
  96. else if (pControl->GetID())
  97. {
  98. int nId = pControl->GetID();
  99. if (! (nId >= AFX_IDM_FIRST_MDICHILD && nId < AFX_IDM_FIRST_MDICHILD + 10))
  100. if (! (
  101. nId == ID_FAVORITES_EX ||
  102. nId == ID_OPENALLFOLDERITEMS ||
  103. nId == ID_ADDPAGEHERE ||
  104. nId == ID_FAVORITE_LINK ||
  105. nId == ID_FAVORITE_FOLDER))
  106. {
  107. CString strCommand = strPrefix + strTitle;
  108. m_mapCommands.SetAt(nId, strCommand);
  109. }
  110. }
  111. }
  112. }  
  113. }
  114. void CPageMouse::RefreshList()
  115. {
  116. CString strKey;
  117. CString strArea;
  118. m_wndCurrent.DeleteAllItems();
  119. CMouseManager::CMouseClicksArray& mca = CMouseManager::GetArray();
  120. for (int i = 0; i < mca.GetSize(); i++)
  121. {
  122. MOUSECLICKS& mc = mca[i];
  123. CXTPShortcutManagerAccel accel(&mc.accel);
  124. CXTPShortcutManager::CKeyHelper kh(&accel, GetMainFrame()->GetCommandBars()->GetShortcutManager());
  125. kh.Format(strKey);
  126. int nIndex = m_wndCurrent.InsertItem(0, CMouseManager::GetMouseString(mc.dwMouse));
  127. m_wndCurrent.SetItemText(nIndex, 1, strKey);
  128. m_cmbArea.GetLBText(mc.nArea, strArea);
  129. m_wndCurrent.SetItemText(nIndex, 2, strArea);
  130. m_wndCurrent.SetItemText(nIndex, 3, m_mapCommands[mc.accel.cmd]);
  131. m_wndCurrent.SetItemData(nIndex, i);
  132. }
  133. }
  134. void CPageMouse::OnButtonRemove() 
  135. {
  136. UINT i, nSelectedCount = m_wndCurrent.GetSelectedCount();
  137. int  nItem = -1;
  138. CMouseManager::CMouseClicksArray& mca = CMouseManager::GetArray();
  139. if (nSelectedCount > 0)
  140. {
  141. BOOL bUpdate = FALSE;
  142. for (i = 0; i < nSelectedCount; i++)
  143. {
  144. nItem = m_wndCurrent.GetNextItem(nItem, LVNI_SELECTED);
  145. ASSERT(nItem != -1);
  146. if (nItem != -1)
  147. {
  148. int dwData = (int)m_wndCurrent.GetItemData(nItem);
  149. if (dwData >= 0 && dwData < mca.GetSize())
  150. {
  151. mca.RemoveAt(dwData);
  152. bUpdate = TRUE;
  153. }    
  154. }
  155. }
  156. if (bUpdate)
  157. RefreshList();
  158. }
  159. }
  160. void CPageMouse::OnButtonAdd() 
  161. {
  162. MOUSECLICKS mc;
  163. if (m_cmbMouse.GetCurSel() == CB_ERR)
  164. return;
  165. mc.dwMouse =  (DWORD)m_cmbMouse.GetItemData(m_cmbMouse.GetCurSel());
  166. CXTPShortcutManagerAccel* pAccel = m_wndAssign.GetAccel();
  167. mc.accel.fVirt = pAccel->key[0].fVirt;
  168. if (m_cmbCommands.GetCurSel() == CB_ERR)
  169. return;
  170. mc.accel.cmd = (WORD)m_cmbCommands.GetItemData(m_cmbCommands.GetCurSel());
  171. if (m_cmbArea.GetCurSel() == CB_ERR)
  172. return;
  173. mc.nArea =  (int)m_cmbArea.GetItemData(m_cmbArea.GetCurSel());
  174. CMouseManager::CMouseClicksArray& mca = CMouseManager::GetArray();
  175. mca.Add(mc);
  176. RefreshList();
  177. }