1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ed_idataobj.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #if defined(_MSC_VER) && (_MSC_VER > 1310)
31 #pragma warning(disable : 4917 4555)
34 // actually this workaround should be in presys.h!
35 //#define UINT64 USE_WIN_UINT64
36 //#define INT64 USE_WIN_INT64
37 //#define UINT32 USE_WIN_UINT32
38 //#define INT32 USE_WIN_INT32
40 //#include <tools/presys.h>
41 #include "embeddoc.hxx"
42 //#include <tools/postsys.h>
50 #include <com/sun/star/uno/Any.h>
51 #include <com/sun/star/uno/Exception.hpp>
52 #include <com/sun/star/datatransfer/XTransferable.hpp>
55 #include <osl/thread.h>
57 using namespace ::com::sun::star
;
59 //===============================================================================
61 //===============================================================================
63 sal_uInt64
EmbedDocument_Impl::getMetaFileHandle_Impl( sal_Bool isEnhMeta
)
65 sal_uInt64 pResult
= NULL
;
67 uno::Reference
< datatransfer::XTransferable
> xTransferable( m_pDocHolder
->GetDocument(), uno::UNO_QUERY
);
68 if ( xTransferable
.is() )
70 uno::Sequence
< sal_Int8
> aMetaBuffer
;
71 datatransfer::DataFlavor aFlavor
;
75 aFlavor
.MimeType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
76 "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ) );
77 aFlavor
.HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enhanced Windows MetaFile" ) );
81 aFlavor
.MimeType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
82 "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ) );
83 aFlavor
.HumanPresentableName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Windows GDIMetaFile" ) );
86 aFlavor
.DataType
= getCppuType( (const sal_uInt64
*) 0 );
88 uno::Any aAny
= xTransferable
->getTransferData( aFlavor
);
95 //-------------------------------------------------------------------------------
98 STDMETHODIMP
EmbedDocument_Impl::GetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
)
101 return DV_E_FORMATETC
;
104 return STG_E_MEDIUMFULL
;
106 if ( pFormatetc
->dwAspect
== DVASPECT_THUMBNAIL
107 || pFormatetc
->dwAspect
== DVASPECT_ICON
108 || pFormatetc
->dwAspect
== DVASPECT_DOCPRINT
)
109 return DV_E_DVASPECT
;
111 if ( pFormatetc
->cfFormat
== CF_ENHMETAFILE
)
113 if ( !( pFormatetc
->tymed
& TYMED_ENHMF
) )
116 HENHMETAFILE hMeta
= reinterpret_cast<HENHMETAFILE
>( getMetaFileHandle_Impl( sal_True
) );
120 pMedium
->tymed
= TYMED_ENHMF
;
121 pMedium
->hEnhMetaFile
= hMeta
;
122 pMedium
->pUnkForRelease
= NULL
;
127 return STG_E_MEDIUMFULL
;
129 else if ( pFormatetc
->cfFormat
== CF_METAFILEPICT
)
131 if ( !( pFormatetc
->tymed
& TYMED_MFPICT
) )
134 HGLOBAL hMeta
= reinterpret_cast<HGLOBAL
>( getMetaFileHandle_Impl( sal_False
) );
138 pMedium
->tymed
= TYMED_MFPICT
;
139 pMedium
->hMetaFilePict
= hMeta
;
140 pMedium
->pUnkForRelease
= NULL
;
145 return STG_E_MEDIUMFULL
;
149 CLIPFORMAT cf_embSource
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embed Source" );
150 CLIPFORMAT cf_embObj
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embedded Object" );
151 if ( pFormatetc
->cfFormat
== cf_embSource
|| pFormatetc
->cfFormat
== cf_embObj
)
153 if ( !( pFormatetc
->tymed
& TYMED_ISTORAGE
) )
156 CComPtr
< IStorage
> pNewStg
;
157 HRESULT hr
= StgCreateDocfile( NULL
, STGM_CREATE
| STGM_READWRITE
| STGM_DELETEONRELEASE
, 0, &pNewStg
);
158 if ( FAILED( hr
) || !pNewStg
) return STG_E_MEDIUMFULL
;
160 hr
= SaveTo_Impl( pNewStg
);
161 if ( FAILED( hr
) ) return STG_E_MEDIUMFULL
;
163 pMedium
->tymed
= TYMED_ISTORAGE
;
164 pMedium
->pstg
= pNewStg
;
165 pMedium
->pstg
->AddRef();
166 pMedium
->pUnkForRelease
= ( IUnknown
* )pNewStg
;
172 return DV_E_FORMATETC
;
175 STDMETHODIMP
EmbedDocument_Impl::GetDataHere( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
)
178 return DV_E_FORMATETC
;
181 return STG_E_MEDIUMFULL
;
183 if ( pFormatetc
->dwAspect
== DVASPECT_THUMBNAIL
184 || pFormatetc
->dwAspect
== DVASPECT_ICON
185 || pFormatetc
->dwAspect
== DVASPECT_DOCPRINT
)
186 return DV_E_DVASPECT
;
188 CLIPFORMAT cf_embSource
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embed Source" );
189 CLIPFORMAT cf_embObj
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embedded Object" );
191 if ( pFormatetc
->cfFormat
== cf_embSource
|| pFormatetc
->cfFormat
== cf_embObj
)
193 if ( !( pFormatetc
->tymed
& TYMED_ISTORAGE
) )
196 if ( !pMedium
->pstg
) return STG_E_MEDIUMFULL
;
198 HRESULT hr
= SaveTo_Impl( pMedium
->pstg
);
199 if ( FAILED( hr
) ) return STG_E_MEDIUMFULL
;
201 pMedium
->tymed
= TYMED_ISTORAGE
;
202 pMedium
->pUnkForRelease
= NULL
;
207 return DV_E_FORMATETC
;
210 STDMETHODIMP
EmbedDocument_Impl::QueryGetData( FORMATETC
* pFormatetc
)
214 if ( pFormatetc
->dwAspect
== DVASPECT_THUMBNAIL
215 || pFormatetc
->dwAspect
== DVASPECT_ICON
216 || pFormatetc
->dwAspect
== DVASPECT_DOCPRINT
)
217 return DV_E_DVASPECT
;
219 if ( pFormatetc
->cfFormat
== CF_ENHMETAFILE
)
221 if ( !( pFormatetc
->tymed
& TYMED_ENHMF
) )
226 else if ( pFormatetc
->cfFormat
== CF_METAFILEPICT
)
228 if ( !( pFormatetc
->tymed
& TYMED_MFPICT
) )
235 CLIPFORMAT cf_embSource
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embed Source" );
236 CLIPFORMAT cf_embObj
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embedded Object" );
237 if ( pFormatetc
->cfFormat
== cf_embSource
|| pFormatetc
->cfFormat
== cf_embObj
)
239 if ( !( pFormatetc
->tymed
& TYMED_ISTORAGE
) )
247 return DV_E_FORMATETC
;
251 STDMETHODIMP
EmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC
* pFormatetcIn
, FORMATETC
* pFormatetcOut
)
253 if ( !pFormatetcIn
|| !pFormatetcOut
)
254 return DV_E_FORMATETC
;
256 pFormatetcOut
->ptd
= NULL
;
257 pFormatetcOut
->cfFormat
= pFormatetcIn
->cfFormat
;
258 pFormatetcOut
->dwAspect
= DVASPECT_CONTENT
;
260 if ( pFormatetcIn
->cfFormat
== CF_ENHMETAFILE
)
262 pFormatetcOut
->tymed
= TYMED_ENHMF
;
265 else if ( pFormatetcIn
->cfFormat
== CF_METAFILEPICT
)
267 pFormatetcOut
->tymed
= TYMED_MFPICT
;
272 CLIPFORMAT cf_embSource
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embed Source" );
273 CLIPFORMAT cf_embObj
= (CLIPFORMAT
)RegisterClipboardFormatA( "Embedded Object" );
274 if ( pFormatetcIn
->cfFormat
== cf_embSource
|| pFormatetcIn
->cfFormat
== cf_embObj
)
276 pFormatetcOut
->tymed
= TYMED_ISTORAGE
;
281 return DV_E_FORMATETC
;
284 STDMETHODIMP
EmbedDocument_Impl::SetData( FORMATETC
* /*pFormatetc*/, STGMEDIUM
* /*pMedium*/, BOOL
/*fRelease*/ )
289 STDMETHODIMP
EmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection
, IEnumFORMATETC
** /*ppFormatetc*/ )
291 if ( dwDirection
== DATADIR_GET
)
297 STDMETHODIMP
EmbedDocument_Impl::DAdvise( FORMATETC
* pFormatetc
, DWORD advf
, IAdviseSink
* pAdvSink
, DWORD
* pdwConnection
)
299 if ( !m_pDAdviseHolder
)
300 if ( !SUCCEEDED( CreateDataAdviseHolder( &m_pDAdviseHolder
) ) || !m_pDAdviseHolder
)
301 return E_OUTOFMEMORY
;
303 return m_pDAdviseHolder
->Advise( (IDataObject
*)this, pFormatetc
, advf
, pAdvSink
, pdwConnection
);
306 STDMETHODIMP
EmbedDocument_Impl::DUnadvise( DWORD dwConnection
)
308 if ( !m_pDAdviseHolder
)
309 if ( !SUCCEEDED( CreateDataAdviseHolder( &m_pDAdviseHolder
) ) || !m_pDAdviseHolder
)
310 return E_OUTOFMEMORY
;
312 return m_pDAdviseHolder
->Unadvise( dwConnection
);
315 STDMETHODIMP
EmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA
** ppenumAdvise
)
317 if ( !m_pDAdviseHolder
)
318 if ( !SUCCEEDED( CreateDataAdviseHolder( &m_pDAdviseHolder
) ) || !m_pDAdviseHolder
)
319 return E_OUTOFMEMORY
;
321 return m_pDAdviseHolder
->EnumAdvise( ppenumAdvise
);
324 // Fix strange warnings about some
325 // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
326 // warning C4505: 'xxx' : unreferenced local function has been removed
327 #if defined(_MSC_VER)
328 #pragma warning(disable: 4505)