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

对话框与窗口

开发平台:

Visual C++

  1. // XTPMouseManager.h : interface for the CXTPMouseManager 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. //{{AFX_CODEJOCK_PRIVATE
  21. #if !defined(__XTPMOUSEMANAGER_H__)
  22. #define __XTPMOUSEMANAGER_H__
  23. //}}AFX_CODEJOCK_PRIVATE
  24. #if _MSC_VER >= 1000
  25. #pragma once
  26. #endif // _MSC_VER >= 1000
  27. class CXTPCommandBar;
  28. //===========================================================================
  29. // Summary:
  30. //     CXTPMouseManager is standalone class. It used in CommandBars to manage mouse.
  31. //===========================================================================
  32. class _XTP_EXT_CLASS CXTPMouseManager : public CNoTrackObject
  33. {
  34. friend class CXTPMouseManager* XTPMouseManager();
  35. public:
  36. //-----------------------------------------------------------------------
  37. // Summary:
  38. //     Constructs a CXTPMouseManager object
  39. //-----------------------------------------------------------------------
  40. CXTPMouseManager();
  41. public:
  42. //-----------------------------------------------------------------------
  43. // Summary:
  44. //     Array of the tracking bars.
  45. //-----------------------------------------------------------------------
  46. class _XTP_EXT_CLASS CTrackArray : public CArray<CXTPCommandBar*, CXTPCommandBar*>
  47. {
  48. public:
  49. //-----------------------------------------------------------------------
  50. // Summary:
  51. //     Find position of specified commandbar.
  52. // Parameters:
  53. //     pCommandBar - CommandBar to find
  54. // Returns:
  55. //     Position of command bar in list; -1 if not found.
  56. //-----------------------------------------------------------------------
  57. int Find(const CXTPCommandBar* pCommandBar) const
  58. {
  59. for (int i = 0; i < GetSize(); i++)
  60. {
  61. if (pCommandBar == GetAt(i))
  62. return  i;
  63. }
  64. return -1;
  65. }
  66. };
  67. private:
  68. class _XTP_EXT_CLASS CTrustedArray : public CArray<HWND, HWND>
  69. {
  70. public:
  71. int Find(const HWND hWnd) const
  72. {
  73. for (int i = 0; i < GetSize(); i++)
  74. {
  75. if (hWnd == GetAt(i))
  76. return  i;
  77. }
  78. return -1;
  79. }
  80. void Remove(HWND hWnd)
  81. {
  82. int i = Find(hWnd);
  83. if (i != -1) RemoveAt(i);
  84. }
  85. };
  86. public:
  87. //-----------------------------------------------------------------------
  88. // Summary:
  89. //     Destroys a CXTPMouseManager object, handles cleanup and deallocation.
  90. //-----------------------------------------------------------------------
  91. ~CXTPMouseManager();
  92. //-----------------------------------------------------------------------
  93. // Summary:
  94. //     Adds a tracking bar.
  95. // Parameters:
  96. //     pTrack        - Points to a CXTPCommandBar object
  97. //     bCaptureMouse - TRUE to capture the mouse.
  98. //-----------------------------------------------------------------------
  99. void SetTrack(CXTPCommandBar* pTrack, BOOL bCaptureMouse = TRUE);
  100. //-----------------------------------------------------------------------
  101. // Summary:
  102. //     Removes the tracking bar.
  103. // Parameters:
  104. //     pTrack - Points to a CXTPCommandBar object
  105. //-----------------------------------------------------------------------
  106. void RemoveTrack(CXTPCommandBar* pTrack);
  107. //-----------------------------------------------------------------------
  108. // Summary:
  109. //     Removes all tracking bars.
  110. //-----------------------------------------------------------------------
  111. void SendTrackLost();
  112. //-----------------------------------------------------------------------
  113. // Summary:
  114. //     Hooks window for the mouse leave event.
  115. // Parameters:
  116. //     hwnd - Window handle.
  117. //-----------------------------------------------------------------------
  118. void TrackMouseLeave(HWND hwnd);
  119. //-----------------------------------------------------------------------
  120. // Summary:
  121. //     Checks if the command bar is tracked.
  122. // Parameters:
  123. //     pItem - Points to a CXTPCommandBar object
  124. // Returns:
  125. //     TRUE if successful; otherwise returns FALSE
  126. //-----------------------------------------------------------------------
  127. BOOL IsTrackedLock(const CXTPCommandBar* pItem = NULL);
  128. //-----------------------------------------------------------------------
  129. // Summary:
  130. //     Sets the selected command bar.
  131. // Parameters:
  132. //     pSelected - Points to a CXTPCommandBar object
  133. //-----------------------------------------------------------------------
  134. void SetSelected(CXTPCommandBar* pSelected);
  135. //-----------------------------------------------------------------------
  136. // Summary:
  137. //     Removes the selected command bar.
  138. // Parameters:
  139. //     pSelected - Points to a CXTPCommandBar object
  140. //-----------------------------------------------------------------------
  141. void RemoveSelected(CXTPCommandBar* pSelected);
  142. //-----------------------------------------------------------------------
  143. // Summary:
  144. //     Captures the mouse cursor.
  145. //-----------------------------------------------------------------------
  146. void LockMouseMove();
  147. //-----------------------------------------------------------------------
  148. // Summary:
  149. //     Unlocks the mouse cursor.
  150. //-----------------------------------------------------------------------
  151. void UnlockMouseMove();
  152. //-----------------------------------------------------------------------
  153. // Summary:
  154. //     Checks if the mouse cursor locked.
  155. // Returns:
  156. //     TRUE if locked; otherwise returns FALSE
  157. //-----------------------------------------------------------------------
  158. BOOL IsMouseLocked() const;
  159. //-----------------------------------------------------------------------
  160. // Summary:
  161. //     Check if the command bar needs to be expanded
  162. // Returns:
  163. //     TRUE if successful; otherwise returns FALSE
  164. //-----------------------------------------------------------------------
  165. BOOL IsForceExpanded() const;
  166. //-----------------------------------------------------------------------
  167. // Summary:
  168. //     Sets expanded state.
  169. // Parameters:
  170. //     bForceExpanded - TRUE to expand bars.
  171. //-----------------------------------------------------------------------
  172. void SetForceExpanded(BOOL bForceExpanded);
  173. //-----------------------------------------------------------------------
  174. // Summary:
  175. //     Adds a window to the trusted window list.
  176. // Parameters:
  177. //     hWnd - Window handle.
  178. //-----------------------------------------------------------------------
  179. void AddTrustedWindow(HWND hWnd);
  180. //-----------------------------------------------------------------------
  181. // Summary:
  182. //     Removes a window from the trusted window list.
  183. // Parameters:
  184. //     hWnd - Window handle.
  185. //-----------------------------------------------------------------------
  186. void RemoveTrustedWindow(HWND hWnd);
  187. //-----------------------------------------------------------------------
  188. // Summary:
  189. //     This method called to determine if top parent window is active.
  190. // Parameters:
  191. //     hWnd - Window handle.
  192. // Returns:
  193. //     TRUE if parent window is active; FALSE otherwise.
  194. //-----------------------------------------------------------------------
  195. static BOOL AFX_CDECL IsTopParentActive(HWND hWnd);
  196. //-------------------------------------------------------------------------
  197. // Summary:
  198. //     This method is called to disable one WM_RBUTTONUP message.
  199. //-------------------------------------------------------------------------
  200. void IgnoreLButtonUp();
  201. static void AFX_CDECL RefreshCursor();
  202. CXTPCommandBar* HitTest(POINT point) const;
  203. BOOL PreviewTackLost(CXTPCommandBar* pContextMenu, MSG* msg) const;
  204. //{{AFX_CODEJOCK_PRIVATE
  205. void LockTrackRecurse(BOOL bLockTrack);
  206. void SendTrackLostRecurse();
  207. BOOL IsTrackedLockRecurse() const;
  208. CTrackArray& GetTrackArray();
  209. CXTPCommandBar* GetTopTracked() const;
  210. //}}AFX_CODEJOCK_PRIVATE
  211. private:
  212. void DeliverMessage(CXTPCommandBar* pCapture, WPARAM wParam, POINT pt);
  213. BOOL PreTranslateMouseEvents(WPARAM wParam, POINT point);
  214. void SetupHook(BOOL);
  215. static void CALLBACK TrackMouseTimerProc (HWND hWnd, UINT /*uMsg*/, UINT idEvent, DWORD /*dwTime*/);
  216. static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
  217. private:
  218. int m_nLock;
  219. CTrackArray m_arrTracked;
  220. static CThreadLocal<CXTPMouseManager> _xtpMouseThreadState;
  221. HHOOK m_hHookMouse;
  222. CXTPCommandBar* m_pSelected;
  223. HWND m_hwndLeave;
  224. BOOL m_bForceExpanded;
  225. CTrustedArray m_arrTrusted;
  226. BOOL m_bIgnoreLButtonUp;
  227. #ifdef _AFXDLL
  228. AFX_MODULE_STATE* m_pModuleState;
  229. #endif
  230. friend class CXTPCustomizeSheet;
  231. friend class CXTPCommandBars;
  232. };
  233. AFX_INLINE CXTPMouseManager* XTPMouseManager() {
  234. return CXTPMouseManager::_xtpMouseThreadState.GetData();
  235. }
  236. AFX_INLINE CXTPMouseManager::CTrackArray& CXTPMouseManager::GetTrackArray() {
  237. return m_arrTracked;
  238. }
  239. AFX_INLINE void CXTPMouseManager::SetSelected(CXTPCommandBar* pSelected) {
  240. m_pSelected = pSelected;
  241. }
  242. AFX_INLINE void CXTPMouseManager::RemoveSelected(CXTPCommandBar* pSelected){
  243. if (m_pSelected == pSelected)
  244. m_pSelected = NULL;
  245. }
  246. AFX_INLINE void CXTPMouseManager::LockMouseMove() {
  247. m_nLock++;
  248. }
  249. AFX_INLINE void CXTPMouseManager::UnlockMouseMove() {
  250. m_nLock--;
  251. }
  252. AFX_INLINE  BOOL CXTPMouseManager::IsMouseLocked() const{
  253. return m_nLock > 0;
  254. }
  255. AFX_INLINE  BOOL CXTPMouseManager::IsForceExpanded() const {
  256. return m_bForceExpanded;
  257. }
  258. AFX_INLINE void CXTPMouseManager::SetForceExpanded(BOOL bForceExpanded) {
  259. m_bForceExpanded = bForceExpanded;
  260. }
  261. AFX_INLINE void CXTPMouseManager::IgnoreLButtonUp() {
  262. m_bIgnoreLButtonUp = TRUE;
  263. }
  264. #endif //#if !defined(__XTPMOUSEMANAGER_H__)