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.

435 lines
18 KiB

  1. /**INC+**********************************************************************/
  2. /* Header: sclipdata.h */
  3. /* */
  4. /* Purpose: Clipboard Monitor global data definition */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1998 */
  7. /* */
  8. /**INC-**********************************************************************/
  9. #ifndef _H_ACBMDATA
  10. #define _H_ACBMDATA
  11. #ifndef INITGUID
  12. #define INITGUID
  13. #include <initguid.h>
  14. #endif
  15. #include <oleguid.h>
  16. #ifndef PPVOID
  17. typedef LPVOID * PPVOID;
  18. #endif //PPVOID
  19. #ifndef TS_STRING_FUNCS
  20. #define TS_STRING_FUNCS
  21. #define TS_PREPEND_STRING "\\\\tsclient\\"
  22. #define LTS_PREPEND_STRING L"\\\\tsclient\\"
  23. // TS_PREPEND_LENGTH is the number of characters in TS_PREPEND_STRING,
  24. // not counting the terminating '\0'
  25. #define TS_PREPEND_LENGTH (sizeof(TS_PREPEND_STRING) - sizeof(TS_PREPEND_STRING[0]))
  26. #endif // ifndef TS_STRING_FUNCS
  27. // GetDataSync EVENTS
  28. #define TS_BLOCK_RECEIVED 0
  29. #define TS_RECEIVE_COMPLETED 1
  30. #define TS_RESET_EVENT 2
  31. #define TS_DISCONNECT_EVENT 3
  32. #define TS_NUM_EVENTS 4
  33. // String length for the paste information string.
  34. #define PASTE_PROGRESS_STRING_LENGTH 128
  35. HRESULT CBMConvertToServerPathW(PVOID pOldData, PVOID pData, size_t cbDest) ;
  36. HRESULT CBMConvertToServerPathA(PVOID pOldData, PVOID pData, size_t cbDest) ;
  37. HRESULT CBMConvertToServerPath(PVOID pOldData, PVOID pData, size_t cbDest,
  38. BOOL fWide) ;
  39. ULONG CBMGetNewDropfilesSizeForServerW(PVOID pData, ULONG oldSize) ;
  40. ULONG CBMGetNewDropfilesSizeForServerA(PVOID pData, ULONG oldSize) ;
  41. ULONG CBMGetNewDropfilesSizeForServer(PVOID pData, ULONG oldSize, BOOL fWide) ;
  42. HRESULT CBMConvertToClientPathW(PVOID pOldData, PVOID pData, size_t cbDest) ;
  43. HRESULT CBMConvertToClientPathA(PVOID pOldData, PVOID pData, size_t cbDest) ;
  44. HRESULT CBMConvertToClientPath(PVOID pOldData, PVOID pData, size_t cbDest,
  45. BOOL fWide) ;
  46. UINT CBMGetNewFilePathLengthForClient(PVOID pData, BOOL fWide) ;
  47. UINT CBMGetNewFilePathLengthForClientW(WCHAR* szOldFilepath) ;
  48. UINT CBMGetNewFilePathLengthForClientA(char* szOldFilepath) ;
  49. ULONG CBMGetNewDropfilesSizeForClientW(PVOID pData, ULONG oldSize) ;
  50. ULONG CBMGetNewDropfilesSizeForClientA(PVOID pData, ULONG oldSize) ;
  51. ULONG CBMGetNewDropfilesSizeForClient(PVOID pData, ULONG oldSize, BOOL fWide) ;
  52. int CBMCopyToTempDirectory(PVOID pSrcFiles, BOOL fWide) ;
  53. int CBMCopyToTempDirectoryW(PVOID pSrcFiles) ;
  54. int CBMCopyToTempDirectoryA(PVOID pSrcFiles) ;
  55. class CImpIDataObject ;
  56. typedef CImpIDataObject *PCImpIDataObject ;
  57. class CEnumFormatEtc ;
  58. class CClipData : public IUnknown
  59. {
  60. friend CImpIDataObject ;
  61. friend CEnumFormatEtc ;
  62. private:
  63. LONG _cRef ;
  64. TS_CLIP_PDU _ClipPDU ;
  65. PCImpIDataObject _pImpIDataObject ;
  66. public:
  67. CClipData();
  68. ~CClipData(void);
  69. HRESULT DCINTERNAL SetNumFormats(ULONG);
  70. DCVOID SetClipData(HGLOBAL, DCUINT) ;
  71. //IUnknown members that delegate to _pUnkOuter.
  72. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  73. STDMETHODIMP_(ULONG) AddRef(void);
  74. STDMETHODIMP_(ULONG) Release(void);
  75. } ;
  76. typedef CClipData *PCClipData ;
  77. class CImpIDataObject : public IDataObject
  78. {
  79. private:
  80. LONG _cRef;
  81. LPUNKNOWN _pUnkOuter;
  82. ULONG _maxNumFormats ;
  83. // Current number of formats in IDataObject
  84. ULONG _numFormats ;
  85. // Buffer of _maxNumFormats FORMATETC's
  86. LPFORMATETC _pFormats ;
  87. LPSTGMEDIUM _pSTGMEDIUM ; // Our fixed STGMEDIUM (always an HGLOBAL)
  88. DCUINT _uiSTGType;
  89. // _lastFormatRequested is used to see if we can avoid re-requesting the
  90. // same data twice over the wire.
  91. CLIPFORMAT _lastFormatRequested ;
  92. CLIPFORMAT _cfDropEffect ;
  93. BOOL _fAlreadyCopied ;
  94. DWORD _dropEffect ; // We currently only support FO_COPY and FO_MOVE
  95. LPVOID _fileName ;
  96. DCVOID FreeSTGMEDIUM( void );
  97. public:
  98. PTS_CLIP_PDU _pClipPDU ;
  99. CImpIDataObject(LPUNKNOWN);
  100. ~CImpIDataObject(void);
  101. HRESULT Init(ULONG) ;
  102. DCVOID SetClipData(HGLOBAL, DCUINT) ;
  103. public:
  104. //IUnknown members that delegate to _pUnkOuter.
  105. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  106. STDMETHODIMP_(ULONG) AddRef(void);
  107. STDMETHODIMP_(ULONG) Release(void);
  108. //IDataObject members
  109. STDMETHODIMP GetData(LPFORMATETC, LPSTGMEDIUM);
  110. STDMETHODIMP GetDataHere(LPFORMATETC, LPSTGMEDIUM);
  111. STDMETHODIMP QueryGetData(LPFORMATETC);
  112. STDMETHODIMP GetCanonicalFormatEtc(LPFORMATETC, LPFORMATETC);
  113. STDMETHODIMP SetData(LPFORMATETC, LPSTGMEDIUM, BOOL);
  114. STDMETHODIMP EnumFormatEtc(DWORD, LPENUMFORMATETC *);
  115. STDMETHODIMP DAdvise(LPFORMATETC, DWORD
  116. , LPADVISESINK, DWORD *);
  117. STDMETHODIMP DUnadvise(DWORD);
  118. STDMETHODIMP EnumDAdvise(LPENUMSTATDATA *);
  119. };
  120. class CEnumFormatEtc : public IEnumFORMATETC
  121. {
  122. private:
  123. LONG _cRef;
  124. LPUNKNOWN _pUnkRef;
  125. LPFORMATETC _pFormats;
  126. ULONG _iCur;
  127. ULONG _cItems;
  128. public:
  129. CEnumFormatEtc(LPUNKNOWN);
  130. ~CEnumFormatEtc(void);
  131. DCVOID Init(LPFORMATETC, ULONG) ;
  132. //IUnknown members that delegate to _pUnkOuter.
  133. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  134. STDMETHODIMP_(ULONG) AddRef(void);
  135. STDMETHODIMP_(ULONG) Release(void);
  136. //IEnumFORMATETC members
  137. STDMETHODIMP Next(ULONG, LPFORMATETC, ULONG *);
  138. STDMETHODIMP Skip(ULONG);
  139. STDMETHODIMP Reset(void);
  140. STDMETHODIMP Clone(IEnumFORMATETC **);
  141. };
  142. typedef CEnumFormatEtc *PCEnumFormatEtc;
  143. /**STRUCT+*******************************************************************/
  144. /* Structure: CBM_GLOBAL_DATA */
  145. /* */
  146. /* Description: Clipboard Monitor global data */
  147. /****************************************************************************/
  148. typedef struct tagCBM_GLOBAL_DATA
  149. {
  150. /************************************************************************/
  151. /* Clipboard viewer chain information */
  152. /************************************************************************/
  153. HWND viewerWindow;
  154. WNDCLASS viewerWindowClass;
  155. HWND nextViewer;
  156. DCBOOL notifyNextViewer;
  157. /************************************************************************/
  158. /* Our state information */
  159. /************************************************************************/
  160. DCUINT state;
  161. DCBOOL open;
  162. /************************************************************************/
  163. /* Client uses ascii for format names */
  164. /************************************************************************/
  165. DCBOOL fUseAsciiNames;
  166. /************************************************************************/
  167. /* Server/client format ID map */
  168. /************************************************************************/
  169. CB_FORMAT_MAP idMap[CB_MAX_FORMATS];
  170. /************************************************************************/
  171. /* The registered message used to communicate between the two threads */
  172. /* of the Clipboard Monitor */
  173. /************************************************************************/
  174. UINT regMsg;
  175. /************************************************************************/
  176. /* thread info */
  177. /************************************************************************/
  178. DCBOOL runThread;
  179. HANDLE hDataThread;
  180. /************************************************************************/
  181. /* other useful data */
  182. /************************************************************************/
  183. DCUINT pendingClientID;
  184. DCUINT pendingServerID;
  185. ULONG logonId;
  186. INT formatResponseCount;
  187. /************************************************************************/
  188. /* Virtual channel stuff */
  189. /************************************************************************/
  190. HANDLE vcHandle;
  191. OVERLAPPED writeOL;
  192. OVERLAPPED readOL;
  193. PDCUINT8 rxpBuffer;
  194. PDCUINT8 rxpNext;
  195. DCUINT rxSize;
  196. DCUINT rxLeft;
  197. /************************************************************************/
  198. /* Array of events */
  199. /************************************************************************/
  200. #define CLIP_EVENT_DISCONNECT 0
  201. #define CLIP_EVENT_RECONNECT 1
  202. #define CLIP_EVENT_READ 2
  203. #define CLIP_EVENT_COUNT 3
  204. HANDLE hEvent[CLIP_EVENT_COUNT];
  205. /************************************************************************/
  206. /* Already running mutex */
  207. /************************************************************************/
  208. HANDLE hMutex;
  209. // GetDataSync is an array of event handles used to synchronize the
  210. // transmission of data from the remote and local clipboard via the
  211. // IDataObject::GetData interface function
  212. // GetDataSync[TS_BLOCK_RECEIVED] is signaled if a datapacket arrives
  213. // GetDataSync[TS_RECEIVE_COMPLETED] is signaled when the data stream is done sending data
  214. // GetDataSync[TS_RESET_EVENT] is signaled when we need to reset/stop waiting
  215. // GetDataSync[TS_DISCONNECT_EVENT] is signaled when a disconnect event occurs
  216. HANDLE GetDataSync[TS_NUM_EVENTS] ;
  217. // CClipData is the data object that encapsulates the IDataObject
  218. PCClipData pClipData ;
  219. // locatation where temp files will go; the +1 is for an extra NULL char
  220. // that may be needed for the SHFileOperation
  221. char tempDirA[MAX_PATH+1] ;
  222. wchar_t tempDirW[MAX_PATH+1] ;
  223. char baseTempDirA[MAX_PATH+1] ;
  224. wchar_t baseTempDirW[MAX_PATH+1] ;
  225. DWORD dropEffect ;
  226. BOOL fFileCutCopyOn ;
  227. BOOL fAlreadyCopied ;
  228. BOOL fRegisteredForSessNotif;
  229. BOOL fInClipboardChain;
  230. WCHAR szPasteInfoStringW[PASTE_PROGRESS_STRING_LENGTH];
  231. CHAR szPasteInfoStringA[PASTE_PROGRESS_STRING_LENGTH];
  232. } CBM_GLOBAL_DATA;
  233. /**STRUCT-*******************************************************************/
  234. DC_GL_EXT CBM_GLOBAL_DATA CBM
  235. #ifdef DC_DEFINE_GLOBAL_DATA
  236. = { 0 }
  237. #endif
  238. ;
  239. /****************************************************************************/
  240. /* CBM State Table */
  241. /****************************************************************************/
  242. DC_GL_EXT DCUINT cbmStateTable[CBM_NUMEVENTS][CBM_NUMSTATES]
  243. #ifdef DC_DEFINE_GLOBAL_DATA
  244. = {
  245. /********************************************************************/
  246. /* This is not a state table in the strict sense. It simply shows */
  247. /* which events are valid in which states. It is not used to drive */
  248. /* CB. */
  249. /* */
  250. /* Values mean */
  251. /* - 0 event OK in this state. */
  252. /* - 1 warning - event should not occur in this state, but does in */
  253. /* some race conditions - ignore it. */
  254. /* - 2 error - event should not occur in ths state at all. */
  255. /* */
  256. /* These values are hard-coded here in order to make the table */
  257. /* readable. They correspond to the constants CBM_TABLE_OK, */
  258. /* CBM_TABLE_WARN & CBM_TABLE_ERROR. */
  259. /* */
  260. /* Uninitialized */
  261. /* | Initialized */
  262. /* | | Connected */
  263. /* | | | Local CB owner */
  264. /* | | | | Shared CB owner */
  265. /* | | | | | Pending format list rsp */
  266. /* | | | | | | Pending format data rsp */
  267. /* | | | | | | | */
  268. /********************************************************************/
  269. /* Start up */
  270. { 0, 2, 2, 2, 2, 2, 2}, /* CBM_MAIN */
  271. /* local Window messages */
  272. { 2, 0, 0, 0, 0, 0, 0}, /* WM_CLOSE */
  273. { 0, 2, 2, 2, 2, 2, 2}, /* WM_CREATE */
  274. { 2, 0, 2, 2, 2, 2, 2}, /* WM_DESTROY */
  275. { 2, 0, 0, 0, 0, 0, 0}, /* WM_CHANGECBCHAIN */
  276. { 1, 1, 0, 0, 0, 0, 2}, /* WM_DRAWCLIPBOARD */
  277. { 2, 2, 0, 0, 2, 2, 2}, /* WM_RENDERFORMAT */
  278. /* shared CB messages */
  279. { 2, 0, 1, 0, 2, 2, 2}, /* Connect */
  280. { 1, 1, 0, 0, 0, 0, 0}, /* Disconnect */
  281. { 2, 2, 0, 0, 0, 0, 0}, /* Format list */
  282. { 2, 2, 2, 2, 2, 0, 2}, /* Format list rsp */
  283. { 2, 2, 1, 1, 0, 1, 2}, /* Format data rq */
  284. { 2, 2, 2, 2, 2, 2, 0} /* Format data rsp */
  285. }
  286. #endif /* DC_DEFINE_GLOBAL_DATA */
  287. ;
  288. #ifdef DC_DEBUG
  289. /****************************************************************************/
  290. /* State and event descriptions (debug build only) */
  291. /****************************************************************************/
  292. DC_GL_EXT const DCTCHAR cbmState[CBM_NUMSTATES][35]
  293. #ifdef DC_DEFINE_GLOBAL_DATA
  294. = {
  295. _T("CBM_STATE_NOT_INIT"),
  296. _T("CBM_STATE_INITIALIZED"),
  297. _T("CBM_STATE_CONNECTED"),
  298. _T("CBM_STATE_LOCAL_CB_OWNER"),
  299. _T("CBM_STATE_SHARED_CB_OWNER"),
  300. _T("CBM_STATE_PENDING_FORMAT_LIST_RSP"),
  301. _T("CBM_STATE_PENDING_FORMAT_DATA_RSP")
  302. }
  303. #endif /* DC_DEFINE_GLOBAL_DATA */
  304. ;
  305. DC_GL_EXT const DCTCHAR cbmEvent[CBM_NUMEVENTS][35]
  306. #ifdef DC_DEFINE_GLOBAL_DATA
  307. = {
  308. _T("CBM_EVENT_CBM_MAIN"),
  309. _T("CBM_EVENT_WM_CLOSE"),
  310. _T("CBM_EVENT_WM_CREATE"),
  311. _T("CBM_EVENT_WM_DESTROY"),
  312. _T("CBM_EVENT_WM_CHANGECBCHAIN"),
  313. _T("CBM_EVENT_WM_DRAWCLIPBOARD"),
  314. _T("CBM_EVENT_WM_RENDERFORMAT"),
  315. _T("CBM_EVENT_CONNECT"),
  316. _T("CBM_EVENT_DISCONNECT"),
  317. _T("CBM_EVENT_FORMAT_LIST"),
  318. _T("CBM_EVENT_FORMAT_LIST_RSP"),
  319. _T("CBM_EVENT_FORMAT_DATA_RQ"),
  320. _T("CBM_EVENT_FORMAT_DATA_RSP")
  321. }
  322. #endif /* DC_DEFINE_GLOBAL_DATA */
  323. ;
  324. #endif /* DC_DEBUG */
  325. /****************************************************************************/
  326. /* Excluded formats */
  327. /****************************************************************************/
  328. const DCTCHAR cbmExcludedFormatList[CBM_EXCLUDED_FORMAT_COUNT]
  329. [TS_FORMAT_NAME_LEN]
  330. = {
  331. _T("Link" ),
  332. _T("OwnerLink" ),
  333. _T("ObjectLink" ),
  334. _T("Link Source" ),
  335. _T("Link Source Descriptor"),
  336. _T("Embed Source" ),
  337. _T("Embedded Object" )
  338. // _T("Ole Private Data" ),
  339. // _T("DataObject" ),
  340. // _T("Object Descriptor" ),
  341. // _T("Shell IDList Array" ),
  342. // _T("Shell Object Offsets" ),
  343. // _T("FileName" ),
  344. // _T("FileNameW" ),
  345. _T("FileContents" ),
  346. _T("FileGroupDescriptor" ),
  347. _T("FileGroupDescriptorW" ),
  348. } ;
  349. const DCTCHAR cbmExcludedFormatList_NO_RD[CBM_EXCLUDED_FORMAT_COUNT_NO_RD]
  350. [TS_FORMAT_NAME_LEN]
  351. = {
  352. _T("Link" ),
  353. _T("OwnerLink" ),
  354. _T("ObjectLink" ),
  355. _T("Link Source" ),
  356. _T("Link Source Descriptor"),
  357. _T("Embed Source" ),
  358. _T("Embedded Object" )
  359. _T("Ole Private Data" ),
  360. _T("DataObject" ),
  361. _T("Object Descriptor" ),
  362. _T("Shell IDList Array" ),
  363. _T("Shell Object Offsets" ),
  364. _T("FileName" ),
  365. _T("FileNameW" ),
  366. _T("FileContents" ),
  367. _T("FileGroupDescriptor" ),
  368. _T("FileGroupDescriptorW" ),
  369. } ;
  370. #endif /* _H_ACBMDATA */