/** * @file XTPMouseManager.h * * @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 * */ /** @cond */ #if !defined(__XTPMOUSEMANAGER_H__) # define __XTPMOUSEMANAGER_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPCommandBar; /** * @brief * CXTPMouseManager is standalone class. * It used in CommandBars to manage the mouse. */ class _XTP_EXT_CLASS CXTPMouseManager : public CNoTrackObject { friend class CXTPMouseManager* XTPMouseManager(); public: /** * @brief * Constructs a CXTPMouseManager object. */ CXTPMouseManager(); public: /** * @brief * Array of the tracking bars. */ class _XTP_EXT_CLASS CTrackArray : public CArray { public: /** * @brief * Call this method to find the position of a specified command bar. * @param pCommandBar CommandBar to find. * @return * The position of the command bar in the list if successful. * If unsuccessful, a value of -1. */ int Find(const CXTPCommandBar* pCommandBar) const; }; private: class CTrustedArray : public CArray { public: int Find(const HWND hWnd) const; void Remove(HWND hWnd); }; public: /** * @brief * Destroys a CXTPMouseManager object, handles cleanup and deallocation. */ ~CXTPMouseManager(); /** * @brief * Adds a tracking bar. * @param pTrack Pointer to a CXTPCommandBar object. * @param bCaptureMouse TRUE to capture the mouse. */ void SetTrack(CXTPCommandBar* pTrack, BOOL bCaptureMouse = TRUE); /** * @brief * Removes the tracking bar. * @param pTrack Pointer to a CXTPCommandBar object. */ void RemoveTrack(CXTPCommandBar* pTrack); /** * @brief * Removes all tracking bars. */ void SendTrackLost(); /** * @brief * Hooks window for the mouse leave event. * @param hwnd Window handle. */ void TrackMouseLeave(HWND hwnd); /** * @brief * Checks if the command bar is tracked. * @param pItem Pointer to a CXTPCommandBar object. * @return * TRUE if successful, otherwise FALSE. */ BOOL IsTrackedLock(const CXTPCommandBar* pItem = NULL); /** * @brief * Sets the selected command bar. * @param pSelected Pointer to a CXTPCommandBar object. */ void SetSelected(CXTPCommandBar* pSelected); /** * @brief * Removes the selected command bar. * @param pSelected Pointer to a CXTPCommandBar object. */ void RemoveSelected(CXTPCommandBar* pSelected); /** * @brief * Captures the mouse cursor. */ void LockMouseMove(); /** * @brief * Unlocks the mouse cursor. */ void UnlockMouseMove(); /** * @brief * Checks if the mouse cursor locked. * @return * TRUE if the mouse cursor is locked, otherwise FALSE. */ BOOL IsMouseLocked() const; /** * @brief * Check if the command bar needs to be expanded * @return * TRUE if successful; otherwise returns FALSE */ BOOL IsForceExpanded() const; /** * @brief * Sets expanded state. * @param bForceExpanded TRUE to expand bars. */ void SetForceExpanded(BOOL bForceExpanded); /** * @brief * Adds a window to the trusted window list. * @param hWnd Window handle. */ void AddTrustedWindow(HWND hWnd); /** * @brief * Removes a window from the trusted window list. * @param hWnd Window handle. */ void RemoveTrustedWindow(HWND hWnd); /** * @brief * Call this method to check if the top parent window is active. * @param hWnd Window handle. * @return * TRUE if the top parent window is active, otherwise FALSE. */ static BOOL AFX_CDECL IsTopParentActive(HWND hWnd); /** * @brief * This method is called to disable one WM_RBUTTONUP message. */ void IgnoreLButtonUp(); /** * @return * Refreshes the mouse cursor. */ static void AFX_CDECL RefreshCursor(); /** * @brief * This method determines where a point lies in a specified item. * @param point Specifies the point to be tested. * @return * A pointer to a CXTPCommandBar item that occupies the specified * point or NULL if no item occupies the point. */ CXTPCommandBar* HitTest(POINT point) const; /** @cond */ BOOL PreviewTackLost(CXTPCommandBar* pContextMenu, MSG* msg) const; void LockTrackRecurse(BOOL bLockTrack); void SendTrackLostRecurse(); BOOL IsTrackedLockRecurse() const; CTrackArray& GetTrackArray(); CXTPCommandBar* GetTopTracked() const; BOOL IsRelated(HWND hWndParent, HWND hWnd) const; void EnableSkipTrackedMouseMoveDuplicates(BOOL bEnable = TRUE); /** @endcond */ private: void DeliverMessage(CXTPCommandBar* pCapture, WPARAM wParam, POINT pt); BOOL PreTranslateMouseEvents(WPARAM wParam, POINT point); void SetupHook(BOOL); static void CALLBACK TrackMouseTimerProc(HWND hWnd, UINT /*uMsg*/, UINT_PTR idEvent, DWORD /*dwTime*/); static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam); private: int m_nLock; CTrackArray m_arrTracked; static CThreadLocal _xtpMouseThreadState; HHOOK m_hHookMouse; CXTPCommandBar* m_pSelected; HWND m_hwndLeave; BOOL m_bForceExpanded; CTrustedArray m_arrTrusted; BOOL m_bIgnoreLButtonUp; BOOL m_bSkipTrackedMouseMoveDuplicates; CPoint m_ptTrackedPos; # ifdef _AFXDLL AFX_MODULE_STATE* m_pModuleState; # endif friend class CXTPCustomizeSheet; friend class CXTPCommandBars; }; AFX_INLINE CXTPMouseManager* XTPMouseManager() { return CXTPMouseManager::_xtpMouseThreadState.GetData(); } /** @cond */ AFX_INLINE CXTPMouseManager::CTrackArray& CXTPMouseManager::GetTrackArray() { return m_arrTracked; } /** @endcond */ AFX_INLINE void CXTPMouseManager::SetSelected(CXTPCommandBar* pSelected) { m_pSelected = pSelected; } AFX_INLINE void CXTPMouseManager::RemoveSelected(CXTPCommandBar* pSelected) { if (m_pSelected == pSelected) m_pSelected = NULL; } AFX_INLINE void CXTPMouseManager::LockMouseMove() { m_nLock++; } AFX_INLINE void CXTPMouseManager::UnlockMouseMove() { m_nLock--; } AFX_INLINE BOOL CXTPMouseManager::IsMouseLocked() const { return m_nLock > 0; } AFX_INLINE BOOL CXTPMouseManager::IsForceExpanded() const { return m_bForceExpanded; } AFX_INLINE void CXTPMouseManager::SetForceExpanded(BOOL bForceExpanded) { m_bForceExpanded = bForceExpanded; } AFX_INLINE void CXTPMouseManager::IgnoreLButtonUp() { m_bIgnoreLButtonUp = TRUE; } /** @cond */ AFX_INLINE void CXTPMouseManager::EnableSkipTrackedMouseMoveDuplicates(BOOL bEnable /*= TRUE*/) { m_bSkipTrackedMouseMoveDuplicates = bEnable; } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPMOUSEMANAGER_H__) /** @endcond */