Changeset 4274 for trunk/src/ole32/oleClip.cpp
- Timestamp:
- Sep 17, 2000, 12:31:07 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ole32/oleClip.cpp
r1606 r4274 1 /* $Id: oleClip.cpp,v 1. 3 1999-11-05 09:15:51 sandervlExp $ */1 /* $Id: oleClip.cpp,v 1.4 2000-09-17 10:31:05 davidr Exp $ */ 2 2 /* 3 3 * … … 13 13 * 14 14 * Ported from Wine Implementation (2/9/99) 15 * Copyright 2000 Abey George <abey@macadamian.com> 15 16 * Copyright 1999 Noel Borthwick <noel@macadamian.com> 16 17 * … … 55 56 56 57 #include "ole32.h" 58 #include "olestd.h" 57 59 #include "commctrl.h" 58 60 #include "oString.h" 61 #include "heapstring.h" 62 #include "storage.h" 59 63 #include <assert.h> 60 64 … … 136 140 137 141 } IEnumFORMATETCImpl; 142 143 typedef struct PresentationDataHeader 144 { 145 BYTE unknown1[28]; 146 DWORD dwObjectExtentX; 147 DWORD dwObjectExtentY; 148 DWORD dwSize; 149 } PresentationDataHeader; 138 150 139 151 /* … … 153 165 static void OLEClipbrd_DestroyWindow(HWND hwnd); 154 166 LRESULT CALLBACK OLEClipbrd_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 155 static HRESULT OLEClipbrd_RenderFormat( LPFORMATETC pFormatetc);167 static HRESULT OLEClipbrd_RenderFormat( IDataObject *pIDataObject, LPFORMATETC pFormatetc ); 156 168 static HGLOBAL OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc ); 157 169 … … 472 484 HRESULT hr = S_OK; 473 485 BOOL bClipboardOpen = FALSE; 486 IDataObject* pIDataObjectSrc = NULL; 474 487 475 488 … … 486 499 487 500 /* 501 * Addref and save the source data object we are holding on to temporarily, 502 * since it will be released when we empty the clipboard. 503 */ 504 pIDataObjectSrc = theOleClipboard->pIDataObjectSrc; 505 IDataObject_AddRef(pIDataObjectSrc); 506 507 /* 488 508 * Open the Windows clipboard 489 509 */ … … 501 521 * the windows clipboard. 502 522 */ 503 if ( FAILED( hr = IDataObject_EnumFormatEtc( (IDataObject*)&(theOleClipboard->lpvtbl1),523 if ( FAILED( hr = IDataObject_EnumFormatEtc( pIDataObjectSrc, 504 524 DATADIR_GET, 505 525 &penumFormatetc) )) … … 510 530 while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) ) 511 531 { 512 if ( rgelt.tymed == TYMED_HGLOBAL)532 if (( rgelt.tymed == TYMED_HGLOBAL ) || ( rgelt.tymed == TYMED_ISTORAGE )) 513 533 { 514 534 CHAR szFmtName[80]; … … 520 540 * Render the clipboard data 521 541 */ 522 if ( FAILED(OLEClipbrd_RenderFormat( &rgelt )) )542 if ( FAILED(OLEClipbrd_RenderFormat( pIDataObjectSrc, &rgelt )) ) 523 543 continue; 524 544 } 545 else 546 FIXME("(type of medium:%ld not supported yet !!)\n",rgelt.tymed); 525 547 } 526 548 … … 530 552 * Release the data object we are holding on to 531 553 */ 532 if ( theOleClipboard->pIDataObjectSrc ) 533 { 534 IDataObject_Release(theOleClipboard->pIDataObjectSrc); 535 theOleClipboard->pIDataObjectSrc = NULL; 536 } 554 IDataObject_Release(pIDataObjectSrc); 537 555 538 556 CLEANUP: … … 799 817 * (We must have a source data object or we wouldn't be in this WndProc) 800 818 */ 801 OLEClipbrd_RenderFormat( &rgelt );819 OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt ); 802 820 803 821 break; … … 834 852 while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) ) 835 853 { 836 if ( rgelt.tymed == TYMED_HGLOBAL)854 if (( rgelt.tymed == TYMED_HGLOBAL ) || ( rgelt.tymed == TYMED_ISTORAGE )) 837 855 { 838 856 /* 839 857 * Render the clipboard data. 840 858 */ 841 if ( FAILED(OLEClipbrd_RenderFormat( &rgelt )) )859 if ( FAILED(OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt )) ) 842 860 continue; 843 861 844 862 dprintf(("OLE32: OLEClipbrd_WndProc - WM_RENDERALLFORMATS(cfFormat=%d)\n", rgelt.cfFormat)); 845 863 } 864 else FIXME("(): WM_RENDERALLFORMATS(cfFormat=%d) not supported !!\n", rgelt.cfFormat); 846 865 } 847 866 … … 888 907 } 889 908 909 #define MAX_CLIPFORMAT_NAME 80 890 910 891 911 /*********************************************************************** … … 895 915 * Note: This function assumes it is passed an HGLOBAL format to render. 896 916 */ 897 static HRESULT OLEClipbrd_RenderFormat( LPFORMATETC pFormatetc)898 { 899 STGMEDIUM medium;917 static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pFormatetc) 918 { 919 STGMEDIUM std; 900 920 HGLOBAL hDup; 901 921 HRESULT hr = S_OK; 902 903 if ( FAILED(hr = IDataObject_GetData((IDataObject*)&(theOleClipboard->lpvtbl1), 904 pFormatetc, &medium)) ) 905 { 906 dprintf(("OLE32: Warning : IDataObject_GetData failed to render clipboard data! (%lx)\n", hr)); 922 char szFmtName[MAX_CLIPFORMAT_NAME]; 923 ILockBytes *ptrILockBytes = 0; 924 HGLOBAL hStorage = 0; 925 926 GetClipboardFormatNameA(pFormatetc->cfFormat, szFmtName, MAX_CLIPFORMAT_NAME); 927 928 /* If embed source */ 929 if (!strcmp(szFmtName, CF_EMBEDSOURCE)) 930 { 931 memset(&std, 0, sizeof(STGMEDIUM)); 932 std.tymed = pFormatetc->tymed = TYMED_ISTORAGE; 933 934 hStorage = GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, 0); 935 hr = CreateILockBytesOnHGlobal(hStorage, FALSE, &ptrILockBytes); 936 hr = StgCreateDocfileOnILockBytes(ptrILockBytes, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &std.u.pstg); 937 938 if (FAILED(hr = IDataObject_GetDataHere(pIDataObject, pFormatetc, &std))) 939 { 940 WARN("() : IDataObject_GetDataHere failed to render clipboard data! (%lx)\n", hr); 941 return hr; 942 } 943 944 //if (1) /* check whether the presentation data is already -not- present */ 945 { 946 FORMATETC fmt2; 947 STGMEDIUM std2; 948 METAFILEPICT *mfp = 0; 949 950 fmt2.cfFormat = CF_METAFILEPICT; 951 fmt2.ptd = 0; 952 fmt2.dwAspect = DVASPECT_CONTENT; 953 fmt2.lindex = -1; 954 fmt2.tymed = TYMED_MFPICT; 955 956 memset(&std2, 0, sizeof(STGMEDIUM)); 957 std2.tymed = TYMED_MFPICT; 958 959 /* Get the metafile picture out of it */ 960 961 if (!FAILED(hr = IDataObject_GetData(pIDataObject, &fmt2, &std2))) 962 { 963 mfp = (METAFILEPICT *)GlobalLock(std2.u.hMetaFilePict); 964 } 965 966 if (mfp) 967 { 968 OLECHAR name[]={ 2, 'O', 'l', 'e', 'P', 'r', 'e', 's', '0', '0', '0', 0}; 969 IStream *pStream = 0; 970 void *mfBits; 971 PresentationDataHeader pdh; 972 INT nSize; 973 CLSID clsID; 974 LPOLESTR strProgID; 975 CHAR strOleTypeName[51]; 976 BYTE OlePresStreamHeader [] = 977 { 978 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 979 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 980 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 981 0x00, 0x00, 0x00, 0x00 982 }; 983 984 nSize = GetMetaFileBitsEx(mfp->hMF, 0, NULL); 985 986 memset(&pdh, 0, sizeof(PresentationDataHeader)); 987 memcpy(&pdh, OlePresStreamHeader, sizeof(OlePresStreamHeader)); 988 989 pdh.dwObjectExtentX = mfp->xExt; 990 pdh.dwObjectExtentY = mfp->yExt; 991 pdh.dwSize = nSize; 992 993 hr = IStorage_CreateStream(std.u.pstg, name, STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, 0, &pStream); 994 995 hr = IStream_Write(pStream, &pdh, sizeof(PresentationDataHeader), NULL); 996 997 mfBits = HeapAlloc(GetProcessHeap(), 0, nSize); 998 nSize = GetMetaFileBitsEx(mfp->hMF, nSize, mfBits); 999 1000 hr = IStream_Write(pStream, mfBits, nSize, NULL); 1001 1002 IStream_Release(pStream); 1003 1004 HeapFree(GetProcessHeap(), 0, mfBits); 1005 1006 GlobalUnlock(std2.u.hMetaFilePict); 1007 1008 ReadClassStg(std.u.pstg, &clsID); 1009 ProgIDFromCLSID(&clsID, &strProgID); 1010 1011 lstrcpyWtoA(strOleTypeName, strProgID); 1012 OLECONVERT_CreateEmbeddedOleStream(std.u.pstg); 1013 OLECONVERT_CreateCompObjStream(std.u.pstg, strOleTypeName); 1014 } 1015 } 1016 } 1017 else 1018 { 1019 if (FAILED(hr = IDataObject_GetData(pIDataObject, pFormatetc, &std))) 1020 { 1021 WARN("() : IDataObject_GetData failed to render clipboard data! (%lx)\n", hr); 907 1022 return hr; 908 1023 } 1024 1025 /* To put a copy back on the clipboard */ 1026 switch (std.tymed) 1027 { 1028 case TYMED_HGLOBAL: 1029 hStorage = std.u.hGlobal; 1030 break; 1031 1032 case TYMED_ENHMF: 1033 case TYMED_FILE: 1034 case TYMED_ISTORAGE: 1035 case TYMED_ISTREAM: 1036 case TYMED_GDI: 1037 case TYMED_MFPICT: 1038 case TYMED_NULL: 1039 FIXME("Unsupported data format (tymed=%d)\n", (int) std.tymed); 1040 default: 1041 WARN("Unable to render clipboard data, unsupported data format (tymed=%d) \n", 1042 (int) std.tymed); 1043 } 1044 1045 } 909 1046 910 1047 /* … … 912 1049 */ 913 1050 914 if ( !(hDup = OLEClipbrd_GlobalDupMem( medium.u.hGlobal)) )1051 if ( !(hDup = OLEClipbrd_GlobalDupMem(hStorage)) ) 915 1052 HANDLE_ERROR( E_OUTOFMEMORY ); 916 1053 … … 918 1055 { 919 1056 GlobalFree(hDup); 920 dprintf(("OLE32: Warning : Failed to set rendered clipboard data into clipboard!\n"));1057 WARN("() : Failed to set rendered clipboard data into clipboard!\n"); 921 1058 } 922 1059 923 1060 CLEANUP: 924 1061 925 ReleaseStgMedium(& medium);1062 ReleaseStgMedium(&std); 926 1063 927 1064 return hr;
Note:
See TracChangeset
for help on using the changeset viewer.