Source code of Windows XP (NT5)
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.

148 lines
4.1 KiB

  1. // LiteControl.h : Declaration of the CLiteControl
  2. #ifndef __LITECONTROL_H_
  3. #define __LITECONTROL_H_
  4. #include "resource.h" // main symbols
  5. #include <atlctl.h>
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CLiteControl
  8. class ATL_NO_VTABLE CLiteControl :
  9. public CComObjectRootEx<CComSingleThreadModel>,
  10. public IDispatchImpl<ILiteControl, &IID_ILiteControl, &LIBID_TaskAppLib>,
  11. public CComControl<CLiteControl>,
  12. public IPersistStreamInitImpl<CLiteControl>,
  13. public IOleControlImpl<CLiteControl>,
  14. public IOleObjectImpl<CLiteControl>,
  15. public IOleInPlaceActiveObjectImpl<CLiteControl>,
  16. public IViewObjectExImpl<CLiteControl>,
  17. public IOleInPlaceObjectWindowlessImpl<CLiteControl>,
  18. public CComCoClass<CLiteControl, &CLSID_LiteControl>
  19. {
  20. public:
  21. CLiteControl() : m_pTaskFrame(NULL), m_clsidDestPage(GUID_NULL), m_strText(L"<empty>")
  22. {
  23. m_sizePreferred = m_sizeExtent;
  24. }
  25. ~CLiteControl() { ATOMICRELEASE(m_pTaskFrame); }
  26. HRESULT SetFrame(ITaskFrame* pFrame)
  27. {
  28. ATOMICRELEASE(m_pTaskFrame);
  29. m_pTaskFrame = pFrame;
  30. if (m_pTaskFrame)
  31. m_pTaskFrame->AddRef();
  32. return S_OK;
  33. }
  34. HRESULT SetDestinationPage(REFCLSID rclsidPage)
  35. {
  36. m_clsidDestPage = rclsidPage;
  37. return S_OK;
  38. }
  39. HRESULT SetText(LPCWSTR pszText)
  40. {
  41. m_strText = pszText;
  42. return S_OK;
  43. }
  44. HRESULT SetMaxExtent(LONG cxWidth, LONG cxHeight)
  45. {
  46. if (0 == cxWidth)
  47. cxWidth = 2540; // 1 inch
  48. if (0 == cxHeight)
  49. cxHeight = 2540; // 1 inch
  50. m_sizePreferred.cx = cxWidth;
  51. m_sizePreferred.cy = cxHeight;
  52. return S_OK;
  53. }
  54. STDMETHOD(GetExtent)(DWORD /*dwDrawAspect*/, SIZEL *psizel)
  55. {
  56. if (psizel == NULL)
  57. return E_POINTER;
  58. *psizel = m_sizePreferred;
  59. return S_OK;
  60. }
  61. DECLARE_NOT_AGGREGATABLE(CLiteControl)
  62. //DECLARE_PROTECT_FINAL_CONSTRUCT()
  63. BEGIN_COM_MAP(CLiteControl)
  64. COM_INTERFACE_ENTRY(ILiteControl)
  65. COM_INTERFACE_ENTRY(IDispatch)
  66. COM_INTERFACE_ENTRY(IViewObjectEx)
  67. COM_INTERFACE_ENTRY(IViewObject2)
  68. COM_INTERFACE_ENTRY(IViewObject)
  69. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  70. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  71. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  72. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  73. COM_INTERFACE_ENTRY(IOleControl)
  74. COM_INTERFACE_ENTRY(IOleObject)
  75. COM_INTERFACE_ENTRY(IPersistStreamInit)
  76. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  77. END_COM_MAP()
  78. BEGIN_PROP_MAP(CLiteControl)
  79. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  80. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  81. // Example entries
  82. // PROP_ENTRY("Property Description", dispid, clsid)
  83. // PROP_PAGE(CLSID_StockColorPage)
  84. END_PROP_MAP()
  85. BEGIN_MSG_MAP(CLiteControl)
  86. CHAIN_MSG_MAP(CComControl<CLiteControl>)
  87. DEFAULT_REFLECTION_HANDLER()
  88. MESSAGE_HANDLER(WM_LBUTTONUP, OnButtonUP)
  89. MESSAGE_HANDLER(WM_RBUTTONUP, OnButtonUP)
  90. END_MSG_MAP()
  91. // Handler prototypes:
  92. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  93. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  94. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  95. // IViewObjectEx
  96. DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
  97. // ILiteControl
  98. public:
  99. HRESULT OnDraw(ATL_DRAWINFO& di)
  100. {
  101. RECT& rc = *(RECT*)di.prcBounds;
  102. Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  103. LPCWSTR pszText = m_strText ? m_strText : L"<empty>";
  104. SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
  105. TextOutW(di.hdcDraw,
  106. (rc.left + rc.right) / 2,
  107. (rc.top + rc.bottom) / 2,
  108. pszText,
  109. lstrlen(pszText));
  110. return S_OK;
  111. }
  112. private:
  113. ITaskFrame* m_pTaskFrame;
  114. CLSID m_clsidDestPage;
  115. CComBSTR m_strText;
  116. SIZEL m_sizePreferred;
  117. LRESULT OnButtonUP(UINT uMsg, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  118. {
  119. if (NULL != m_pTaskFrame)
  120. m_pTaskFrame->ShowPage(m_clsidDestPage, WM_RBUTTONUP == uMsg);
  121. return 0;
  122. }
  123. };
  124. #endif //__LITECONTROL_H_