Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.1 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: subclass.h
  7. *
  8. * Contents: Interface file for the dynamic subclass manager
  9. *
  10. * History: 06-May-98 JeffRo Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef __SUBCLASS_H__
  14. #define __SUBCLASS_H__
  15. #pragma once
  16. // remove the definition from windowsx.h that conflicts with declarations here
  17. #ifdef SubclassWindow
  18. #undef SubclassWindow
  19. #endif
  20. /*--------------------------------------------------------------------------*
  21. * CSubclasser
  22. *
  23. * Derive a class from this to implement subclassing the subclass manager
  24. * way.
  25. *--------------------------------------------------------------------------*/
  26. class CSubclasser
  27. {
  28. public:
  29. virtual ~CSubclasser() {}
  30. virtual LRESULT Callback (HWND& hwnd, UINT& msg, WPARAM& wParam,
  31. LPARAM& lParam, bool& fPassMessageOn) = 0;
  32. };
  33. /*----------------*/
  34. /* SubclasserData */
  35. /*----------------*/
  36. class SubclasserData
  37. {
  38. public:
  39. SubclasserData (CSubclasser* pSubclasser_ = NULL, HWND hwnd = NULL)
  40. : pSubclasser (pSubclasser_),
  41. hwnd (hwnd),
  42. cRefs (0),
  43. fZombie (false)
  44. {}
  45. UINT AddRef ()
  46. { return (++cRefs); }
  47. UINT Release ()
  48. { ASSERT (cRefs > 0); return (--cRefs); }
  49. bool operator==(const SubclasserData& other) const
  50. { return (pSubclasser == other.pSubclasser); }
  51. bool operator<(const SubclasserData& other) const
  52. { return (pSubclasser < other.pSubclasser); }
  53. CSubclasser* pSubclasser;
  54. private:
  55. friend class WindowContext;
  56. HWND hwnd;
  57. UINT cRefs;
  58. bool fZombie;
  59. };
  60. typedef std::list<SubclasserData> SubclasserList;
  61. typedef std::set< SubclasserData> SubclasserSet;
  62. /*---------------*/
  63. /* WindowContext */
  64. /*---------------*/
  65. class WindowContext
  66. {
  67. public:
  68. WindowContext() : pfnOriginalWndProc(NULL)
  69. {}
  70. bool IsZombie(const SubclasserData& subclasser) const;
  71. void Insert(SubclasserData& subclasser);
  72. UINT Remove(SubclasserData& subclasser);
  73. void RemoveZombies();
  74. SubclasserList Subclassers;
  75. WNDPROC pfnOriginalWndProc;
  76. private:
  77. void Zombie(SubclasserData& subclasser, bool fZombie);
  78. SubclasserSet Zombies;
  79. };
  80. /*------------------*/
  81. /* CSubclassManager */
  82. /*------------------*/
  83. class CSubclassManager
  84. {
  85. public:
  86. bool SubclassWindow (HWND hwnd, CSubclasser* pSubclasser);
  87. bool UnsubclassWindow (HWND hwnd, CSubclasser* pSubclasser);
  88. private:
  89. typedef std::map<HWND, WindowContext> ContextMap;
  90. ContextMap m_ContextMap;
  91. bool PhysicallyUnsubclassWindow (HWND hwnd, bool fForce = false);
  92. LRESULT SubclassProcWorker (HWND, UINT, WPARAM, LPARAM);
  93. static LRESULT CALLBACK SubclassProc (HWND, UINT, WPARAM, LPARAM);
  94. };
  95. CSubclassManager& GetSubclassManager();
  96. #endif /* __SUBCLASS_H__ */