HotKeys.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include "Shared/ArrayEx.h"
  3. class CHotKey
  4. {
  5. public:
  6. enum HotKeyType
  7. {
  8. PASTE_OPEN_CLIP,
  9. MOVE_TO_GROUP
  10. };
  11. CString m_Name;
  12. ATOM m_Atom;
  13. DWORD m_Key; //704 is ctrl-tilda
  14. bool m_bIsRegistered;
  15. bool m_bUnRegisterOnShowDitto;
  16. int m_clipId;
  17. int m_globalId;
  18. HotKeyType m_hkType;
  19. static int m_nextId;
  20. CHotKey( CString name, DWORD defKey = 0, bool bUnregOnShowDitto = false, HotKeyType hkType = PASTE_OPEN_CLIP );
  21. ~CHotKey();
  22. bool IsRegistered() { return m_bIsRegistered; }
  23. CString GetName() { return m_Name; }
  24. DWORD GetKey() { return m_Key; }
  25. CString GetHotKeyDisplay();
  26. void SetKey( DWORD key, bool bSave = false );
  27. // profile
  28. void LoadKey();
  29. bool SaveKey();
  30. void CopyFromCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID);
  31. void CopyToCtrl(CHotKeyCtrl& ctrl, HWND hParent, int nWindowsCBID);
  32. UINT GetModifier() { return GetModifier(HIBYTE(m_Key)); }
  33. bool Register();
  34. bool Unregister(bool bOnShowingDitto = false);
  35. static BOOL ValidateHotKey(DWORD dwHotKey);
  36. static UINT GetModifier(DWORD dwHotKey);
  37. static CString GetHotKeyDisplayStatic(DWORD dwHotKey);
  38. static CString GetVirKeyName(unsigned int virtualKey);
  39. };
  40. /*------------------------------------------------------------------*\
  41. CHotKeys - Manages system-wide hotkeys
  42. \*------------------------------------------------------------------*/
  43. class CHotKeys : public CArray<CHotKey*,CHotKey*>
  44. {
  45. public:
  46. HWND m_hWnd;
  47. CHotKeys();
  48. ~CHotKeys();
  49. void Init( HWND hWnd ) { m_hWnd = hWnd; }
  50. INT_PTR Find( CHotKey* pHotKey );
  51. bool Remove( CHotKey* pHotKey ); // pHotKey is NOT deleted.
  52. bool Remove(int clipId, CHotKey::HotKeyType hkType);
  53. BOOL ValidateClip(int clipId, DWORD key, CString desc, CHotKey::HotKeyType hkType);
  54. // profile load / save
  55. void LoadAllKeys();
  56. void SaveAllKeys();
  57. void RegisterAll(bool bMsgOnError = false);
  58. void UnregisterAll(bool bMsgOnError = false, bool bOnShowDitto = false);
  59. void GetKeys( ARRAY& keys );
  60. void SetKeys( ARRAY& keys, bool bSave = false ); // caution! this alters hotkeys based upon corresponding indexes
  61. static bool FindFirstConflict( ARRAY& keys, INT_PTR* pX = NULL, INT_PTR* pY = NULL );
  62. // if true, pX and pY (if valid) are set to the index of the conflicting hotkeys.
  63. bool FindFirstConflict( INT_PTR* pX = NULL, INT_PTR* pY = NULL );
  64. };
  65. extern CHotKeys g_HotKeys;