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.

264 lines
8.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: listpad.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // ListPad.h : Declaration of the CListPad
  11. #ifndef __LISTPAD_H_
  12. #define __LISTPAD_H_
  13. #include "resource.h" // main symbols
  14. #include "amcmsgid.h"
  15. #include "commctrl.h"
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CListPad
  18. class ATL_NO_VTABLE CListPad :
  19. public CComObjectRootEx<CComSingleThreadModel>,
  20. public CComCoClass<CListPad, &CLSID_ListPad>,
  21. public CComControl<CListPad>,
  22. public IDispatchImpl<IListPad, &IID_IListPad, &LIBID_CICLib>,
  23. public IProvideClassInfo2Impl<&CLSID_ListPad, NULL, &LIBID_CICLib>,
  24. public IPersistStreamInitImpl<CListPad>,
  25. public IPersistStorageImpl<CListPad>,
  26. public IQuickActivateImpl<CListPad>,
  27. public IOleControlImpl<CListPad>,
  28. public IOleObjectImpl<CListPad>,
  29. public IOleInPlaceActiveObjectImpl<CListPad>,
  30. public IObjectSafetyImpl<CListPad, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  31. public IViewObjectExImpl<CListPad>,
  32. public IOleInPlaceObjectWindowlessImpl<CListPad>,
  33. public IDataObjectImpl<CListPad>,
  34. public ISpecifyPropertyPagesImpl<CListPad>
  35. {
  36. public:
  37. CListPad()
  38. {
  39. m_MMChWnd = m_ListViewHWND = NULL;
  40. m_bWindowOnly = TRUE;
  41. }
  42. ~CListPad()
  43. {
  44. if (m_MMChWnd)
  45. ::SendMessage (m_MMChWnd, MMC_MSG_CONNECT_TO_TPLV, (WPARAM)m_MMChWnd, (LPARAM)NULL);
  46. }
  47. /*+-------------------------------------------------------------------------*
  48. *
  49. * GetWndClassInfo
  50. *
  51. * PURPOSE: Need to override this to remove the CS_HREDRAW and CS_VREDRAW
  52. * styles, which were causing lots of flicker. See the SDK
  53. * docs under GetWndClassInfo for more details.
  54. *
  55. * RETURNS:
  56. * static CWndClassInfo&
  57. *
  58. *+-------------------------------------------------------------------------*/
  59. static CWndClassInfo& GetWndClassInfo()
  60. {
  61. static CWndClassInfo wc =
  62. {
  63. { sizeof(WNDCLASSEX), CS_DBLCLKS, StartWindowProc,
  64. 0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, NULL, NULL },
  65. NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
  66. };
  67. return wc;
  68. }
  69. DECLARE_MMC_CONTROL_REGISTRATION(
  70. g_szCicDll,
  71. CLSID_ListPad,
  72. _T("ListPad class"),
  73. _T("ListPad.ListPad.1"),
  74. _T("ListPad.ListPad"),
  75. LIBID_CICLib,
  76. _T("1"),
  77. _T("1.0"))
  78. BEGIN_COM_MAP(CListPad)
  79. COM_INTERFACE_ENTRY(IListPad)
  80. COM_INTERFACE_ENTRY(IDispatch)
  81. COM_INTERFACE_ENTRY(IObjectSafety)
  82. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  83. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  84. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  85. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  86. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  87. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  88. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  89. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  90. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  91. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  92. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  93. COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
  94. COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
  95. COM_INTERFACE_ENTRY_IMPL(IDataObject)
  96. COM_INTERFACE_ENTRY(IProvideClassInfo)
  97. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  98. END_COM_MAP()
  99. BEGIN_PROPERTY_MAP(CListPad)
  100. // Example entries
  101. // PROP_ENTRY("Property Description", dispid, clsid)
  102. // PROP_PAGE(CLSID_StockColorPage)
  103. END_PROPERTY_MAP()
  104. BEGIN_MSG_MAP(CListPad)
  105. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  106. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  107. MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
  108. MESSAGE_HANDLER(WM_NOTIFYFORMAT, OnNotifyFormat)
  109. MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
  110. MESSAGE_HANDLER(WM_SIZE, OnSize)
  111. END_MSG_MAP()
  112. // IViewObjectEx
  113. STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
  114. {
  115. ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
  116. *pdwStatus = VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE;
  117. return S_OK;
  118. }
  119. STDMETHOD(TranslateAccelerator)(MSG *pMsg)
  120. {
  121. // If the list view has the focus process the keys the list view can use
  122. // use because IE will take them before they become normal key events
  123. // to the focused window.
  124. if (::GetFocus() == m_ListViewHWND && pMsg->message == WM_KEYDOWN)
  125. {
  126. switch (pMsg->wParam)
  127. {
  128. case VK_UP:
  129. case VK_DOWN:
  130. case VK_LEFT:
  131. case VK_RIGHT:
  132. case VK_HOME:
  133. case VK_END:
  134. case VK_PRIOR:
  135. case VK_NEXT:
  136. ::TranslateMessage(pMsg);
  137. ::DispatchMessage(pMsg);
  138. return S_OK;
  139. }
  140. }
  141. CComQIPtr<IOleControlSite,&IID_IOleControlSite> spCtrlSite (m_spClientSite);
  142. if (spCtrlSite)
  143. return spCtrlSite->TranslateAccelerator (pMsg,0);
  144. return S_FALSE;
  145. }
  146. public:
  147. LRESULT OnSetFocus(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  148. {
  149. LRESULT lr = CComControlBase::OnSetFocus (nMsg, wParam, lParam, bHandled);
  150. if (m_ListViewHWND)
  151. {
  152. ::SetFocus (m_ListViewHWND);
  153. return TRUE;
  154. }
  155. return lr;
  156. }
  157. LRESULT OnNotify (UINT nMsg, WPARAM w, LPARAM l, BOOL& bHandled)
  158. {
  159. NMHDR* pnmhdr = reinterpret_cast<NMHDR*>(l);
  160. // Must handle focus changes here for active control tracking.
  161. // Don't forward it to the MMC window.
  162. if (pnmhdr->code == NM_SETFOCUS)
  163. {
  164. // if we're not UI active, request it now
  165. if (m_bInPlaceActive && !m_bUIActive)
  166. UIActivateWithNoGrab();
  167. return CComControlBase::OnSetFocus (WM_SETFOCUS, NULL, NULL, bHandled);
  168. }
  169. else if (pnmhdr->code == NM_KILLFOCUS)
  170. {
  171. return CComControlBase::OnKillFocus (WM_KILLFOCUS, NULL, NULL, bHandled);
  172. }
  173. if (m_MMChWnd != NULL)
  174. return(BOOL)::SendMessage (m_MMChWnd, nMsg, w, l);
  175. return bHandled = 0;
  176. }
  177. LRESULT OnNotifyFormat (UINT nMsg, WPARAM w, LPARAM l, BOOL& lResult)
  178. { return OnNotify (nMsg, w, l, lResult);}
  179. LRESULT OnDestroy (UINT nMsg, WPARAM w, LPARAM l, BOOL& lResult)
  180. {
  181. if (m_MMChWnd != NULL)
  182. { // detach
  183. ::SendMessage (m_MMChWnd, MMC_MSG_CONNECT_TO_TPLV, (WPARAM)m_hWnd, (LPARAM)NULL);
  184. m_MMChWnd = NULL;
  185. }
  186. return lResult = 1;
  187. }
  188. LRESULT OnSize (UINT nMsg, WPARAM w, LPARAM l, BOOL& lResult)
  189. {
  190. ::SetWindowPos (m_ListViewHWND, NULL, 0, 0, LOWORD(l), HIWORD(l), SWP_NOZORDER | SWP_NOACTIVATE);
  191. return 1;
  192. }
  193. HRESULT OnPostVerbInPlaceActivate();
  194. // UIActivation code taken from CComControlBase::InPlaceActivate.
  195. // Can't call InPlaceActivate because it always forces the focus to the
  196. // outer window and we don't want to steal focus from the list view control.
  197. void UIActivateWithNoGrab()
  198. {
  199. OLEINPLACEFRAMEINFO frameInfo;
  200. RECT rcPos, rcClip;
  201. CComPtr<IOleInPlaceFrame> spInPlaceFrame;
  202. CComPtr<IOleInPlaceUIWindow> spInPlaceUIWindow;
  203. frameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
  204. m_spInPlaceSite->GetWindowContext(&spInPlaceFrame,
  205. &spInPlaceUIWindow, &rcPos, &rcClip, &frameInfo);
  206. CComPtr<IOleInPlaceActiveObject> spActiveObject;
  207. ControlQueryInterface(IID_IOleInPlaceActiveObject, (void**)&spActiveObject);
  208. m_bUIActive = TRUE;
  209. HRESULT hr = m_spInPlaceSite->OnUIActivate();
  210. if (FAILED(hr))
  211. return;
  212. // set ourselves up in the host.
  213. //
  214. if (spActiveObject)
  215. {
  216. if (spInPlaceFrame)
  217. spInPlaceFrame->SetActiveObject(spActiveObject, NULL);
  218. if (spInPlaceUIWindow)
  219. spInPlaceUIWindow->SetActiveObject(spActiveObject, NULL);
  220. }
  221. if (spInPlaceFrame)
  222. spInPlaceFrame->SetBorderSpace(NULL);
  223. if (spInPlaceUIWindow)
  224. spInPlaceUIWindow->SetBorderSpace(NULL);
  225. }
  226. private:
  227. HWND m_MMChWnd;
  228. HWND m_ListViewHWND;
  229. };
  230. #endif //__LISTPAD_H_