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.

148 lines
4.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: DataObj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "displ2.h"
  12. #include "DsplMgr2.h"
  13. #define MY_CF_SNAPIN_INTERNAL L"DISPLAY MANAGER SNAPIN"
  14. // global(s)
  15. extern long g_ref_DataObject; // in displ2.cpp
  16. const GUID GUID_RootNode = { /* d59cd090-44d9-11d1-9fd5-00600832db4a */
  17. 0xd59cd090,
  18. 0x44d9,
  19. 0x11d1,
  20. {0x9f, 0xd5, 0x00, 0x60, 0x08, 0x32, 0xdb, 0x4a}
  21. };
  22. const GUID GUID_WallpaperNode = { /* d59cd091-44d9-11d1-9fd5-00600832db4a */
  23. 0xd59cd091,
  24. 0x44d9,
  25. 0x11d1,
  26. {0x9f, 0xd5, 0x00, 0x60, 0x08, 0x32, 0xdb, 0x4a}
  27. };
  28. const GUID GUID_PatternNode = { /* d59cd092-44d9-11d1-9fd5-00600832db4a */
  29. 0xd59cd092,
  30. 0x44d9,
  31. 0x11d1,
  32. {0x9f, 0xd5, 0x00, 0x60, 0x08, 0x32, 0xdb, 0x4a}
  33. };
  34. // statics
  35. UINT CDataObject::s_cfInternal = 0;
  36. UINT CDataObject::s_cfDisplayName = 0;
  37. UINT CDataObject::s_cfNodeType = 0;
  38. UINT CDataObject::s_cfSnapinClsid = 0;
  39. UINT CDataObject::s_cfSnapinPreloads = 0;
  40. CDataObject::CDataObject(long cookie, DATA_OBJECT_TYPES type)
  41. {
  42. #ifdef DEBUG
  43. InterlockedIncrement (&g_ref_DataObject);
  44. #endif
  45. m_ref = 1;
  46. m_cookie = cookie;
  47. m_type = type;
  48. m_bPreload = FALSE;
  49. USES_CONVERSION;
  50. s_cfInternal = RegisterClipboardFormat (W2T(MY_CF_SNAPIN_INTERNAL));
  51. s_cfDisplayName = RegisterClipboardFormat (W2T(CCF_DISPLAY_NAME));
  52. s_cfNodeType = RegisterClipboardFormat (W2T(CCF_NODETYPE));
  53. s_cfSnapinClsid = RegisterClipboardFormat (W2T(CCF_SNAPIN_CLASSID));
  54. s_cfSnapinPreloads = RegisterClipboardFormat (W2T(CCF_SNAPIN_PRELOADS));
  55. }
  56. CDataObject::~CDataObject ()
  57. {
  58. #ifdef DEBUG
  59. InterlockedDecrement (&g_ref_DataObject);
  60. #endif
  61. }
  62. HRESULT CDataObject::QueryInterface (REFIID riid, LPVOID FAR* ppvObj)
  63. {
  64. if (ppvObj == NULL)
  65. return E_INVALIDARG;
  66. if ( (riid == IID_IUnknown) ||
  67. (riid == IID_IDataObject) ){
  68. // I know about these two interfaces, only.
  69. *ppvObj = (void *)this;
  70. } else {
  71. *ppvObj = NULL;
  72. return E_NOINTERFACE;
  73. }
  74. AddRef();
  75. return S_OK;
  76. }
  77. ULONG CDataObject::AddRef ()
  78. {
  79. return InterlockedIncrement ((LONG *) &m_ref);
  80. }
  81. ULONG CDataObject::Release ()
  82. {
  83. InterlockedDecrement ((LONG *)&m_ref);
  84. if (m_ref == 0) {
  85. delete this;
  86. return 0;
  87. }
  88. return m_ref;
  89. }
  90. HRESULT CDataObject::GetDataHere (FORMATETC *pformatetc, STGMEDIUM *pmedium)
  91. {
  92. IStream * pstm = NULL;
  93. HRESULT hresult = CreateStreamOnHGlobal (pmedium->hGlobal, FALSE, &pstm);
  94. if (pstm) {
  95. _ASSERT (hresult == S_OK);
  96. const CLIPFORMAT cf = pformatetc->cfFormat;
  97. if (cf == s_cfDisplayName) {
  98. LPWSTR pszName = L"Display Manager (Version 2)";
  99. hresult = pstm->Write (pszName, sizeof(WCHAR)*(1+wcslen (pszName)), NULL);
  100. } else
  101. if (cf == s_cfInternal) {
  102. CDataObject * pThis = this;
  103. hresult = pstm->Write (pThis, sizeof(CDataObject *), NULL);
  104. } else
  105. if (cf == s_cfNodeType) {
  106. const GUID * pguid;
  107. if (m_cookie == DISPLAY_MANAGER_WALLPAPER)
  108. pguid = &GUID_WallpaperNode;
  109. else if (m_cookie == DISPLAY_MANAGER_PATTERN)
  110. pguid = &GUID_PatternNode;
  111. else if (m_cookie == DISPLAY_MANAGER_PATTERN_CHILD)
  112. pguid = &GUID_RootNode;
  113. else if (m_cookie == 0)
  114. pguid = &GUID_RootNode;
  115. else {
  116. // anything else must be result-side stuff:
  117. pguid = &GUID_WallpaperNode;
  118. }
  119. hresult = pstm->Write ((PVOID)pguid, sizeof(GUID), NULL);
  120. } else
  121. if (cf == s_cfSnapinClsid) {
  122. hresult = pstm->Write (&CLSID_DsplMgr2, sizeof(CLSID_DsplMgr2), NULL);
  123. } else
  124. if (cf == s_cfSnapinPreloads) {
  125. hresult = pstm->Write ((PVOID)&m_bPreload, sizeof(BOOL), NULL);
  126. } else {
  127. hresult = DV_E_FORMATETC;
  128. // Might as well assert, since we should not have any other
  129. // clipboard formats at this time.
  130. _ASSERT(hresult == S_OK);
  131. }
  132. pstm->Release();
  133. }
  134. return hresult;
  135. }