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.

115 lines
4.3 KiB

  1. // HWNDHost.h
  2. //
  3. #ifndef DUI_CONTROL_HWNDHOST_H_INCLUDED
  4. #define DUI_CONTROL_HWNDHOST_H_INCLUDED
  5. namespace DirectUI
  6. {
  7. ////////////////////////////////////////////////////////
  8. // HWNDHost
  9. // Element to HWND bridge
  10. #define HHC_CacheFont 0x00000001
  11. // HWNDHost subclasses the HWND child and intercepts all input. This input is forward to DUser
  12. // as a normal message (as if the message never originated via the HWND child). After the input
  13. // message routes, it will be sent to the peer gadget and then on to Element (via OnInput).
  14. // A HWND message will be constructed and sent to the HWND child.
  15. //
  16. // The following flags disables the forwarding of the original HWND message into the DUser world.
  17. // Thus, while the underlying gadget may get mouse/key focus, the HWND will appear as a
  18. // "dead area" within the Element.
  19. //
  20. // These options are used if the HWND is used in an environment where it is not guaranteed that
  21. // all messages sent to it will be dispatched. If they aren't, DUser's state cannot by synchronized.
  22. #define HHC_NoMouseForward 0x00000002
  23. #define HHC_NoKeyboardForward 0x00000004
  24. #define HHC_SyncText 0x00000008
  25. #define HHC_SyncPaint 0x00000010
  26. // Class definition
  27. class HWNDHost : public Element
  28. {
  29. public:
  30. static HRESULT Create(OUT Element** ppElement) { return Create(HHC_CacheFont, AE_MouseAndKeyboard, ppElement); }
  31. static HRESULT Create(UINT nCreate, UINT nActive, OUT Element** ppElement);
  32. // System events
  33. virtual void OnPropertyChanged(PropertyInfo* ppi, int iIndex, Value* pvOld, Value* pvNew);
  34. virtual void OnInput(InputEvent* pInput);
  35. virtual void OnDestroy();
  36. // HWNDHost system events, control notification
  37. virtual bool OnNotify(UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT* plRet);
  38. // Sizing callback
  39. virtual BOOL OnAdjustWindowSize(int x, int y, UINT uFlags);
  40. // Message callback
  41. virtual UINT MessageCallback(GMSG* pGMsg);
  42. // Rendering
  43. virtual void Paint(HDC hDC, const RECT* prcBounds, const RECT* prcInvalid, RECT* prcSkipBorder, RECT* prcSkipContent);
  44. #ifdef GADGET_ENABLE_GDIPLUS
  45. virtual void Paint(Gdiplus::Graphics* pgpgr, const Gdiplus::RectF* prcBounds, const Gdiplus::RectF* prcInvalid, Gdiplus::RectF* prSkipBorder, Gdiplus::RectF* prSkipContent);
  46. #endif
  47. HWND GetHWND() { return _hwndCtrl; }
  48. HWND GetHWNDParent() { return _hwndSink; }
  49. void Detach();
  50. // ClassInfo accessors (static and virtual instance-based)
  51. static IClassInfo* Class;
  52. virtual IClassInfo* GetClassInfo() { return Class; }
  53. static HRESULT Register();
  54. ///////////////////////////////////////////////////////
  55. // Accessibility support
  56. virtual HRESULT GetAccessibleImpl(IAccessible ** ppAccessible);
  57. HWNDHost() { }
  58. HRESULT Initialize(UINT nCreate, UINT nActive);
  59. virtual ~HWNDHost() { }
  60. protected:
  61. virtual void OnHosted(Element* peNewHost);
  62. virtual void OnUnHosted(Element* peOldHost);
  63. virtual HWND CreateHWND(HWND hwndParent);
  64. // Synchronize control and sink to changes
  65. void SyncRect(UINT nChangeFlags, bool bForceSync = false);
  66. void SyncParent();
  67. void SyncStyle();
  68. void SyncVisible();
  69. void SyncFont();
  70. void SyncText();
  71. private:
  72. // Control and sink subclass procs
  73. static BOOL CALLBACK _SinkWndProc(void* pThis, HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT* plRet);
  74. static BOOL CALLBACK _CtrlWndProc(void* pThis, HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT* plRet);
  75. static const UINT g_rgMouseMap[7][3]; // Gadget input message to HWND input message mapping
  76. bool _fHwndCreate; // On first call, create HWNDs (sink and control)
  77. HWND _hwndCtrl; // Hosted control
  78. HWND _hwndSink; // HWND used to receive control notifications
  79. WNDPROC _pfnCtrlOrgProc; // The Controls original WNDPROC
  80. RECT _rcBounds; // Bounds of sink and control (in client coordinates)
  81. HFONT _hFont; // Cached font (optional)
  82. UINT _nCreate; // Creation flags
  83. };
  84. } // namespace DirectUI
  85. #endif // DUI_CONTROL_HWNDHOST_H_INCLUDED