Ignore:
Timestamp:
Sep 17, 2000, 12:31:07 PM (25 years ago)
Author:
davidr
Message:

Updates from wine

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 sandervl Exp $ */
     1/* $Id: oleClip.cpp,v 1.4 2000-09-17 10:31:05 davidr Exp $ */
    22/*
    33 *
     
    1313 *
    1414 * Ported from Wine Implementation (2/9/99)
     15 *   Copyright 2000  Abey George <abey@macadamian.com>
    1516 *   Copyright 1999  Noel Borthwick <noel@macadamian.com>
    1617 *
     
    5556
    5657#include "ole32.h"
     58#include "olestd.h"
    5759#include "commctrl.h"
    5860#include "oString.h"
     61#include "heapstring.h"
     62#include "storage.h"
    5963#include <assert.h>
    6064
     
    136140 
    137141} IEnumFORMATETCImpl;
     142
     143typedef struct PresentationDataHeader
     144{
     145  BYTE unknown1[28];
     146  DWORD dwObjectExtentX;
     147  DWORD dwObjectExtentY;
     148  DWORD dwSize;
     149} PresentationDataHeader;
    138150
    139151/*
     
    153165static void OLEClipbrd_DestroyWindow(HWND hwnd);
    154166LRESULT CALLBACK OLEClipbrd_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    155 static HRESULT OLEClipbrd_RenderFormat(LPFORMATETC pFormatetc);
     167static HRESULT OLEClipbrd_RenderFormat( IDataObject *pIDataObject, LPFORMATETC pFormatetc );
    156168static HGLOBAL OLEClipbrd_GlobalDupMem( HGLOBAL hGlobalSrc );
    157169
     
    472484  HRESULT hr = S_OK;
    473485  BOOL bClipboardOpen = FALSE;
     486  IDataObject* pIDataObjectSrc = NULL;
    474487 
    475488
     
    486499
    487500  /*
     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  /*
    488508   * Open the Windows clipboard
    489509   */
     
    501521   * the windows clipboard.
    502522   */
    503   if ( FAILED( hr = IDataObject_EnumFormatEtc( (IDataObject*)&(theOleClipboard->lpvtbl1),
     523  if ( FAILED( hr = IDataObject_EnumFormatEtc( pIDataObjectSrc,
    504524                                               DATADIR_GET,
    505525                                               &penumFormatetc) ))
     
    510530  while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) )
    511531  {
    512     if ( rgelt.tymed == TYMED_HGLOBAL )
     532    if (( rgelt.tymed == TYMED_HGLOBAL ) || ( rgelt.tymed == TYMED_ISTORAGE ))
    513533    {
    514534      CHAR szFmtName[80];
     
    520540       * Render the clipboard data
    521541       */
    522       if ( FAILED(OLEClipbrd_RenderFormat( &rgelt )) )
     542      if ( FAILED(OLEClipbrd_RenderFormat( pIDataObjectSrc, &rgelt )) )
    523543        continue;
    524544    }
     545    else
     546      FIXME("(type of medium:%ld not supported yet !!)\n",rgelt.tymed);
    525547  }
    526548 
     
    530552   * Release the data object we are holding on to
    531553   */
    532   if ( theOleClipboard->pIDataObjectSrc )
    533   {
    534     IDataObject_Release(theOleClipboard->pIDataObjectSrc);
    535     theOleClipboard->pIDataObjectSrc = NULL;
    536   }
     554  IDataObject_Release(pIDataObjectSrc);
    537555
    538556CLEANUP:
     
    799817       * (We must have a source data object or we wouldn't be in this WndProc)
    800818       */
    801       OLEClipbrd_RenderFormat( &rgelt );
     819      OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt );
    802820
    803821      break;
     
    834852      while ( S_OK == IEnumFORMATETC_Next(penumFormatetc, 1, &rgelt, NULL) )
    835853      {
    836         if ( rgelt.tymed == TYMED_HGLOBAL )
     854        if (( rgelt.tymed == TYMED_HGLOBAL ) || ( rgelt.tymed == TYMED_ISTORAGE ))
    837855        {
    838856          /*
    839857           * Render the clipboard data.
    840858           */
    841           if ( FAILED(OLEClipbrd_RenderFormat( &rgelt )) )
     859          if ( FAILED(OLEClipbrd_RenderFormat( (IDataObject*)&(theOleClipboard->lpvtbl1), &rgelt )) )
    842860            continue;
    843861       
    844862          dprintf(("OLE32: OLEClipbrd_WndProc - WM_RENDERALLFORMATS(cfFormat=%d)\n", rgelt.cfFormat));
    845863        }
     864        else FIXME("(): WM_RENDERALLFORMATS(cfFormat=%d) not supported !!\n", rgelt.cfFormat);
    846865      }
    847866     
     
    888907}
    889908
     909#define MAX_CLIPFORMAT_NAME   80
    890910
    891911/***********************************************************************
     
    895915 * Note: This function assumes it is passed an HGLOBAL format to render.
    896916 */
    897 static HRESULT OLEClipbrd_RenderFormat(LPFORMATETC pFormatetc)
    898 {
    899   STGMEDIUM medium;
     917static HRESULT OLEClipbrd_RenderFormat(IDataObject *pIDataObject, LPFORMATETC pFormatetc)
     918{
     919  STGMEDIUM std;
    900920  HGLOBAL hDup;
    901921  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);
    9071022    return hr;
    9081023  }
     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  }
    9091046
    9101047  /*
     
    9121049   */
    9131050 
    914   if ( !(hDup = OLEClipbrd_GlobalDupMem(medium.u.hGlobal)) )
     1051  if ( !(hDup = OLEClipbrd_GlobalDupMem(hStorage)) )
    9151052    HANDLE_ERROR( E_OUTOFMEMORY );
    9161053       
     
    9181055  {
    9191056    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");
    9211058  }
    9221059
    9231060CLEANUP:
    9241061 
    925   ReleaseStgMedium(&medium);
     1062  ReleaseStgMedium(&std);
    9261063 
    9271064  return hr;
Note: See TracChangeset for help on using the changeset viewer.