dataobject.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:8k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * viewobject.cpp: ActiveX control for VLC
  3.  *****************************************************************************
  4.  * Copyright (C) 2005 VideoLAN
  5.  *
  6.  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  21.  *****************************************************************************/
  22. #include "plugin.h"
  23. #include "dataobject.h"
  24. #include "utils.h"
  25. using namespace std;
  26. ////////////////////////////////////////////////////////////////////////////////////////////////
  27. static const FORMATETC _metaFileFormatEtc =
  28.     {
  29.         CF_METAFILEPICT,
  30.         NULL,
  31.         DVASPECT_CONTENT,
  32.         -1,
  33.         TYMED_MFPICT,
  34.     };
  35. static const FORMATETC _enhMetaFileFormatEtc =
  36.     {
  37.         CF_ENHMETAFILE,
  38.         NULL,
  39.         DVASPECT_CONTENT,
  40.         -1,
  41.         TYMED_ENHMF,
  42.     };
  43. class VLCEnumFORMATETC : public VLCEnumIterator<IID_IEnumFORMATETC,
  44.     IEnumFORMATETC,
  45.     FORMATETC,
  46.     vector<FORMATETC>::iterator>
  47. {
  48. public:
  49.     VLCEnumFORMATETC(vector<FORMATETC> v) :
  50.         VLCEnumIterator<IID_IEnumFORMATETC,
  51.         IEnumFORMATETC,
  52.         FORMATETC,
  53.         vector<FORMATETC>::iterator>(v.begin(), v.end())
  54.     {};
  55. };
  56. ////////////////////////////////////////////////////////////////////////////////////////////////
  57. VLCDataObject::VLCDataObject(VLCPlugin *p_instance) : _p_instance(p_instance)
  58. {
  59.     _v_formatEtc.push_back(_enhMetaFileFormatEtc);
  60.     _v_formatEtc.push_back(_metaFileFormatEtc);
  61.     CreateDataAdviseHolder(&_p_adviseHolder);
  62. };
  63. VLCDataObject::~VLCDataObject()
  64. {
  65.     _p_adviseHolder->Release();
  66. };
  67. ////////////////////////////////////////////////////////////////////////////////////////////////
  68. STDMETHODIMP VLCDataObject::DAdvise(LPFORMATETC pFormatEtc, DWORD padvf, LPADVISESINK pAdviseSink, LPDWORD pdwConnection)
  69. {
  70.     return _p_adviseHolder->Advise(this,
  71.             pFormatEtc, padvf,pAdviseSink, pdwConnection);
  72. };
  73. STDMETHODIMP VLCDataObject::DUnadvise(DWORD dwConnection)
  74. {
  75.     return _p_adviseHolder->Unadvise(dwConnection);
  76. };
  77. STDMETHODIMP VLCDataObject::EnumDAdvise(IEnumSTATDATA **ppenumAdvise)
  78. {
  79.     return _p_adviseHolder->EnumAdvise(ppenumAdvise);
  80. };
  81. STDMETHODIMP VLCDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppEnum)
  82. {
  83.     if( NULL == ppEnum )
  84.         return E_POINTER;
  85.     *ppEnum = dynamic_cast<IEnumFORMATETC *>(new VLCEnumFORMATETC(_v_formatEtc));
  86.     return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
  87. };
  88. STDMETHODIMP VLCDataObject::GetCanonicalFormatEtc(LPFORMATETC pFormatEtcIn, LPFORMATETC pFormatEtcOut)
  89. {
  90.     HRESULT result = QueryGetData(pFormatEtcIn);
  91.     if( FAILED(result) )
  92.         return result;
  93.     if( NULL == pFormatEtcOut )
  94.         return E_POINTER;
  95.     *pFormatEtcOut = *pFormatEtcIn;
  96.     pFormatEtcOut->ptd = NULL;
  97.     return DATA_S_SAMEFORMATETC;
  98. };
  99. STDMETHODIMP VLCDataObject::GetData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
  100. {
  101.     if( NULL == pMedium )
  102.         return E_POINTER;
  103.     HRESULT result = QueryGetData(pFormatEtc);
  104.     if( SUCCEEDED(result) )
  105.     {
  106.         switch( pFormatEtc->cfFormat )
  107.         {
  108.             case CF_METAFILEPICT:
  109.                 pMedium->tymed = TYMED_MFPICT;
  110.                 pMedium->hMetaFilePict = NULL;
  111.                 pMedium->pUnkForRelease = NULL;
  112.                 result = getMetaFileData(pFormatEtc, pMedium);
  113.                 break;
  114.             case CF_ENHMETAFILE:
  115.                 pMedium->tymed = TYMED_ENHMF;
  116.                 pMedium->hEnhMetaFile = NULL;
  117.                 pMedium->pUnkForRelease = NULL;
  118.                 result = getEnhMetaFileData(pFormatEtc, pMedium);
  119.                 break;
  120.             default:
  121.                 result = DV_E_FORMATETC;
  122.         }
  123.     }
  124.     return result;
  125. };
  126. STDMETHODIMP VLCDataObject::GetDataHere(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
  127. {
  128.     if( NULL == pMedium )
  129.         return E_POINTER;
  130.     return E_NOTIMPL;
  131. }
  132. ////////////////////////////////////////////////////////////////////////////////////////////////
  133. HRESULT VLCDataObject::getMetaFileData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
  134. {
  135.     HDC hicTargetDev = CreateDevDC(pFormatEtc->ptd);
  136.     if( NULL == hicTargetDev )
  137.         return E_FAIL;
  138.     HDC hdcMeta = CreateMetaFile(NULL);
  139.     if( NULL != hdcMeta )
  140.     {
  141.         LPMETAFILEPICT pMetaFilePict = (LPMETAFILEPICT)CoTaskMemAlloc(sizeof(METAFILEPICT));
  142.         if( NULL != pMetaFilePict )
  143.         {
  144.             SIZEL size = _p_instance->getExtent();
  145.             RECTL wBounds = { 0L, 0L, size.cx, size.cy };
  146.             pMetaFilePict->mm   = MM_ANISOTROPIC;
  147.             pMetaFilePict->xExt = size.cx;
  148.             pMetaFilePict->yExt = size.cy;
  149.             DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);
  150.             SetMapMode(hdcMeta, MM_ANISOTROPIC);
  151.             SetWindowExtEx(hdcMeta, size.cx, size.cy, NULL);
  152.             RECTL bounds = { 0L, 0L, size.cx, size.cy };
  153.             _p_instance->onDraw(pFormatEtc->ptd, hicTargetDev, hdcMeta, &bounds, &wBounds);
  154.             pMetaFilePict->hMF = CloseMetaFile(hdcMeta);
  155.             if( NULL != pMetaFilePict->hMF )
  156.                 pMedium->hMetaFilePict = pMetaFilePict;
  157.             else
  158.                 CoTaskMemFree(pMetaFilePict);
  159.         }
  160.     }
  161.     DeleteDC(hicTargetDev);
  162.     return (NULL != pMedium->hMetaFilePict) ? S_OK : E_FAIL;
  163. };
  164. HRESULT VLCDataObject::getEnhMetaFileData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
  165. {
  166.     HDC hicTargetDev = CreateDevDC(pFormatEtc->ptd);
  167.     if( NULL == hicTargetDev )
  168.         return E_FAIL;
  169.     SIZEL size = _p_instance->getExtent();
  170.     HDC hdcMeta = CreateEnhMetaFile(hicTargetDev, NULL, NULL, NULL);
  171.     if( NULL != hdcMeta )
  172.     {
  173.         RECTL wBounds = { 0L, 0L, size.cx, size.cy };
  174.         DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);
  175.         RECTL bounds = { 0L, 0L, size.cx, size.cy };
  176.         _p_instance->onDraw(pFormatEtc->ptd, hicTargetDev, hdcMeta, &bounds, &wBounds);
  177.         pMedium->hEnhMetaFile = CloseEnhMetaFile(hdcMeta);
  178.     }
  179.     DeleteDC(hicTargetDev);
  180.     return (NULL != pMedium->hEnhMetaFile) ? S_OK : E_FAIL;
  181. };
  182. STDMETHODIMP VLCDataObject::QueryGetData(LPFORMATETC pFormatEtc)
  183. {
  184.     if( NULL == pFormatEtc )
  185.         return E_POINTER;
  186.     const FORMATETC *formatEtc;
  187.     switch( pFormatEtc->cfFormat )
  188.     {
  189.         case CF_METAFILEPICT:
  190.             formatEtc = &_metaFileFormatEtc;
  191.             break;
  192.         case CF_ENHMETAFILE:
  193.             formatEtc = &_enhMetaFileFormatEtc;
  194.             break;
  195.         default:
  196.             return DV_E_FORMATETC;
  197.     }
  198.  
  199.     if( pFormatEtc->dwAspect != formatEtc->dwAspect )
  200.         return DV_E_DVASPECT;
  201.     if( pFormatEtc->lindex != formatEtc->lindex )
  202.         return DV_E_LINDEX;
  203.     if( pFormatEtc->tymed != formatEtc->tymed )
  204.         return DV_E_TYMED;
  205.     return S_OK;
  206. };
  207. STDMETHODIMP VLCDataObject::SetData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium, BOOL fRelease)
  208. {
  209.     return E_NOTIMPL;
  210. };
  211. /*void VLCDataObject::onDataChange(void)
  212. {
  213.     _p_adviseHolder->SendOnDataChange(this, 0, 0);
  214. };*/
  215. void VLCDataObject::onClose(void)
  216. {
  217.     _p_adviseHolder->SendOnDataChange(this, 0, ADVF_DATAONSTOP);
  218.     if( S_OK == OleIsCurrentClipboard(dynamic_cast<LPDATAOBJECT>(this)) )
  219.         OleFlushClipboard();
  220. };