update emoji autocorrect entries from po-files
[LibreOffice.git] / embedserv / source / embed / ed_idataobj.cxx
blobddb802aa318e9968dbad119426e73498a315817e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifdef _MSC_VER
20 #pragma warning(disable : 4917 4555)
21 #endif
23 #include "embeddoc.hxx"
25 #include <com/sun/star/uno/Any.h>
26 #include <com/sun/star/uno/Exception.hpp>
27 #include <com/sun/star/datatransfer/XTransferable.hpp>
30 #include <osl/thread.h>
32 using namespace ::com::sun::star;
35 // EmbedDocument_Impl
38 sal_uInt64 EmbedDocument_Impl::getMetaFileHandle_Impl( sal_Bool isEnhMeta )
40 sal_uInt64 pResult = NULL;
42 uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetDocument(), uno::UNO_QUERY );
43 if ( xTransferable.is() )
45 uno::Sequence< sal_Int8 > aMetaBuffer;
46 datatransfer::DataFlavor aFlavor;
48 if ( isEnhMeta )
50 aFlavor.MimeType = "application/x-openoffice-emf;windows_formatname=\"Image EMF\"";
51 aFlavor.HumanPresentableName = "Enhanced Windows MetaFile";
53 else
55 aFlavor.MimeType = "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"";
56 aFlavor.HumanPresentableName = "Windows GDIMetaFile";
59 aFlavor.DataType = cppu::UnoType<sal_uInt64>::get();
61 uno::Any aAny = xTransferable->getTransferData( aFlavor );
62 aAny >>= pResult;
65 return pResult;
69 // IDataObject
71 STDMETHODIMP EmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
73 if ( !pFormatetc )
74 return DV_E_FORMATETC;
76 if ( !pMedium )
77 return STG_E_MEDIUMFULL;
79 if ( pFormatetc->dwAspect == DVASPECT_THUMBNAIL
80 || pFormatetc->dwAspect == DVASPECT_ICON
81 || pFormatetc->dwAspect == DVASPECT_DOCPRINT )
82 return DV_E_DVASPECT;
84 if ( pFormatetc->cfFormat == CF_ENHMETAFILE )
86 if ( !( pFormatetc->tymed & TYMED_ENHMF ) )
87 return DV_E_TYMED;
89 HENHMETAFILE hMeta = reinterpret_cast<HENHMETAFILE>( getMetaFileHandle_Impl( sal_True ) );
91 if ( hMeta )
93 pMedium->tymed = TYMED_ENHMF;
94 pMedium->hEnhMetaFile = hMeta;
95 pMedium->pUnkForRelease = NULL;
97 return S_OK;
100 return STG_E_MEDIUMFULL;
102 else if ( pFormatetc->cfFormat == CF_METAFILEPICT )
104 if ( !( pFormatetc->tymed & TYMED_MFPICT ) )
105 return DV_E_TYMED;
107 HGLOBAL hMeta = reinterpret_cast<HGLOBAL>( getMetaFileHandle_Impl( sal_False ) );
109 if ( hMeta )
111 pMedium->tymed = TYMED_MFPICT;
112 pMedium->hMetaFilePict = hMeta;
113 pMedium->pUnkForRelease = NULL;
115 return S_OK;
118 return STG_E_MEDIUMFULL;
120 else
122 CLIPFORMAT cf_embSource = (CLIPFORMAT)RegisterClipboardFormatA( "Embed Source" );
123 CLIPFORMAT cf_embObj = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
124 if ( pFormatetc->cfFormat == cf_embSource || pFormatetc->cfFormat == cf_embObj )
126 if ( !( pFormatetc->tymed & TYMED_ISTORAGE ) )
127 return DV_E_TYMED;
129 CComPtr< IStorage > pNewStg;
130 HRESULT hr = StgCreateDocfile( NULL, STGM_CREATE | STGM_READWRITE | STGM_DELETEONRELEASE, 0, &pNewStg );
131 if ( FAILED( hr ) || !pNewStg ) return STG_E_MEDIUMFULL;
133 hr = SaveTo_Impl( pNewStg );
134 if ( FAILED( hr ) ) return STG_E_MEDIUMFULL;
136 pMedium->tymed = TYMED_ISTORAGE;
137 pMedium->pstg = pNewStg;
138 pMedium->pstg->AddRef();
139 pMedium->pUnkForRelease = ( IUnknown* )pNewStg;
141 return S_OK;
145 return DV_E_FORMATETC;
148 STDMETHODIMP EmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
150 if ( !pFormatetc )
151 return DV_E_FORMATETC;
153 if ( !pMedium )
154 return STG_E_MEDIUMFULL;
156 if ( pFormatetc->dwAspect == DVASPECT_THUMBNAIL
157 || pFormatetc->dwAspect == DVASPECT_ICON
158 || pFormatetc->dwAspect == DVASPECT_DOCPRINT )
159 return DV_E_DVASPECT;
161 CLIPFORMAT cf_embSource = (CLIPFORMAT)RegisterClipboardFormatA( "Embed Source" );
162 CLIPFORMAT cf_embObj = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
164 if ( pFormatetc->cfFormat == cf_embSource || pFormatetc->cfFormat == cf_embObj )
166 if ( !( pFormatetc->tymed & TYMED_ISTORAGE ) )
167 return DV_E_TYMED;
169 if ( !pMedium->pstg ) return STG_E_MEDIUMFULL;
171 HRESULT hr = SaveTo_Impl( pMedium->pstg );
172 if ( FAILED( hr ) ) return STG_E_MEDIUMFULL;
174 pMedium->tymed = TYMED_ISTORAGE;
175 pMedium->pUnkForRelease = NULL;
177 return S_OK;
180 return DV_E_FORMATETC;
183 STDMETHODIMP EmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
185 if ( pFormatetc )
187 if ( pFormatetc->dwAspect == DVASPECT_THUMBNAIL
188 || pFormatetc->dwAspect == DVASPECT_ICON
189 || pFormatetc->dwAspect == DVASPECT_DOCPRINT )
190 return DV_E_DVASPECT;
192 if ( pFormatetc->cfFormat == CF_ENHMETAFILE )
194 if ( !( pFormatetc->tymed & TYMED_ENHMF ) )
195 return DV_E_TYMED;
197 return S_OK;
199 else if ( pFormatetc->cfFormat == CF_METAFILEPICT )
201 if ( !( pFormatetc->tymed & TYMED_MFPICT ) )
202 return DV_E_TYMED;
204 return S_OK;
206 else
208 CLIPFORMAT cf_embSource = (CLIPFORMAT)RegisterClipboardFormatA( "Embed Source" );
209 CLIPFORMAT cf_embObj = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
210 if ( pFormatetc->cfFormat == cf_embSource || pFormatetc->cfFormat == cf_embObj )
212 if ( !( pFormatetc->tymed & TYMED_ISTORAGE ) )
213 return DV_E_TYMED;
215 return S_OK;
220 return DV_E_FORMATETC;
224 STDMETHODIMP EmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
226 if ( !pFormatetcIn || !pFormatetcOut )
227 return DV_E_FORMATETC;
229 pFormatetcOut->ptd = NULL;
230 pFormatetcOut->cfFormat = pFormatetcIn->cfFormat;
231 pFormatetcOut->dwAspect = DVASPECT_CONTENT;
233 if ( pFormatetcIn->cfFormat == CF_ENHMETAFILE )
235 pFormatetcOut->tymed = TYMED_ENHMF;
236 return S_OK;
238 else if ( pFormatetcIn->cfFormat == CF_METAFILEPICT )
240 pFormatetcOut->tymed = TYMED_MFPICT;
241 return S_OK;
243 else
245 CLIPFORMAT cf_embSource = (CLIPFORMAT)RegisterClipboardFormatA( "Embed Source" );
246 CLIPFORMAT cf_embObj = (CLIPFORMAT)RegisterClipboardFormatA( "Embedded Object" );
247 if ( pFormatetcIn->cfFormat == cf_embSource || pFormatetcIn->cfFormat == cf_embObj )
249 pFormatetcOut->tymed = TYMED_ISTORAGE;
250 return S_OK;
254 return DV_E_FORMATETC;
257 STDMETHODIMP EmbedDocument_Impl::SetData( FORMATETC * /*pFormatetc*/, STGMEDIUM * /*pMedium*/, BOOL /*fRelease*/ )
259 return E_NOTIMPL;
262 STDMETHODIMP EmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** /*ppFormatetc*/ )
264 if ( dwDirection == DATADIR_GET )
265 return OLE_S_USEREG;
267 return E_NOTIMPL;
270 STDMETHODIMP EmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
272 if ( !m_pDAdviseHolder )
273 if ( !SUCCEEDED( CreateDataAdviseHolder( &m_pDAdviseHolder ) ) || !m_pDAdviseHolder )
274 return E_OUTOFMEMORY;
276 return m_pDAdviseHolder->Advise( (IDataObject*)this, pFormatetc, advf, pAdvSink, pdwConnection );
279 STDMETHODIMP EmbedDocument_Impl::DUnadvise( DWORD dwConnection )
281 if ( !m_pDAdviseHolder )
282 if ( !SUCCEEDED( CreateDataAdviseHolder( &m_pDAdviseHolder ) ) || !m_pDAdviseHolder )
283 return E_OUTOFMEMORY;
285 return m_pDAdviseHolder->Unadvise( dwConnection );
288 STDMETHODIMP EmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
290 if ( !m_pDAdviseHolder )
291 if ( !SUCCEEDED( CreateDataAdviseHolder( &m_pDAdviseHolder ) ) || !m_pDAdviseHolder )
292 return E_OUTOFMEMORY;
294 return m_pDAdviseHolder->EnumAdvise( ppenumAdvise );
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */