1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/datatransfer/XTransferable.hpp>
23 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
25 #include "DataFmtTransl.hxx"
27 #include "FetcList.hxx"
29 #if !defined WIN32_LEAN_AND_MEAN
30 # define WIN32_LEAN_AND_MEAN
36 /*--------------------------------------------------------------------------
37 - the function principle of the windows clipboard:
38 a data provider offers all formats he can deliver on the clipboard
39 a clipboard client ask for the available formats on the clipboard
40 and decides if there is a format he can use
41 if there is one, he requests the data in this format
43 - This class inherits from IDataObject and so can be placed on the
44 OleClipboard. The class wraps a transferable object which is the
46 - DataFlavors offered by this transferable will be translated into
47 appropriate clipboard formats
48 - if the transferable contains text data always text and unicodetext
49 will be offered or vice versa
50 - text data will be automatically converted between text and unicode text
51 - although the transferable may support text in different charsets
52 (codepages) only text in one codepage can be offered by the clipboard
54 ----------------------------------------------------------------------------*/
56 class CStgTransferHelper
;
58 class CXTDataObject
: public IDataObject
61 CXTDataObject( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
62 const css::uno::Reference
< css::datatransfer::XTransferable
>& aXTransferable
);
63 virtual ~CXTDataObject();
65 // ole interface implementation
67 //IUnknown interface methods
68 STDMETHODIMP
QueryInterface(REFIID iid
, void** ppvObject
) override
;
69 STDMETHODIMP_( ULONG
) AddRef( ) override
;
70 STDMETHODIMP_( ULONG
) Release( ) override
;
72 // IDataObject interface methods
73 STDMETHODIMP
GetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pmedium
) override
;
74 STDMETHODIMP
GetDataHere( FORMATETC
* pFormatetc
, STGMEDIUM
* pmedium
) override
;
75 STDMETHODIMP
QueryGetData( FORMATETC
* pFormatetc
) override
;
76 STDMETHODIMP
GetCanonicalFormatEtc( FORMATETC
* pFormatectIn
, FORMATETC
* pFormatetcOut
) override
;
77 STDMETHODIMP
SetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pmedium
, BOOL fRelease
) override
;
78 STDMETHODIMP
EnumFormatEtc( DWORD dwDirection
, IEnumFORMATETC
** ppenumFormatetc
) override
;
79 STDMETHODIMP
DAdvise( FORMATETC
* pFormatetc
, DWORD advf
, IAdviseSink
* pAdvSink
, DWORD
* pdwConnection
) override
;
80 STDMETHODIMP
DUnadvise( DWORD dwConnection
) override
;
81 STDMETHODIMP
EnumDAdvise( IEnumSTATDATA
** ppenumAdvise
) override
;
83 operator IDataObject
*( );
86 css::datatransfer::DataFlavor
formatEtcToDataFlavor( const FORMATETC
& aFormatEtc
) const;
88 void renderLocaleAndSetupStgMedium( FORMATETC
const & fetc
, STGMEDIUM
& stgmedium
);
89 void renderUnicodeAndSetupStgMedium( FORMATETC
const & fetc
, STGMEDIUM
& stgmedium
);
90 void renderAnyDataAndSetupStgMedium( FORMATETC
& fetc
, STGMEDIUM
& stgmedium
);
92 HRESULT
renderSynthesizedFormatAndSetupStgMedium( FORMATETC
& fetc
, STGMEDIUM
& stgmedium
);
93 void renderSynthesizedUnicodeAndSetupStgMedium( FORMATETC
const & fetc
, STGMEDIUM
& stgmedium
);
94 void renderSynthesizedTextAndSetupStgMedium( FORMATETC
& fetc
, STGMEDIUM
& stgmedium
);
95 void renderSynthesizedHtmlAndSetupStgMedium( FORMATETC
& fetc
, STGMEDIUM
& stgmedium
);
97 inline void InitializeFormatEtcContainer( );
101 css::uno::Reference
< css::datatransfer::XTransferable
> m_XTransferable
;
102 css::uno::Reference
< css::uno::XComponentContext
> m_XComponentContext
;
103 CFormatEtcContainer m_FormatEtcContainer
;
104 bool m_bFormatEtcContainerInitialized
;
105 CDataFormatTranslator m_DataFormatTranslator
;
106 CFormatRegistrar m_FormatRegistrar
;
109 class CEnumFormatEtc
: public IEnumFORMATETC
112 CEnumFormatEtc( LPUNKNOWN lpUnkOuter
, const CFormatEtcContainer
& aFormatEtcContainer
);
113 virtual ~CEnumFormatEtc() {}
116 STDMETHODIMP
QueryInterface( REFIID iid
, void** ppvObject
) override
;
117 STDMETHODIMP_( ULONG
) AddRef( ) override
;
118 STDMETHODIMP_( ULONG
) Release( ) override
;
121 STDMETHODIMP
Next( ULONG nRequested
, FORMATETC
* lpDest
, ULONG
* lpFetched
) override
;
122 STDMETHODIMP
Skip( ULONG celt
) override
;
123 STDMETHODIMP
Reset( ) override
;
124 STDMETHODIMP
Clone( IEnumFORMATETC
** ppenum
) override
;
128 LPUNKNOWN m_lpUnkOuter
;
129 CFormatEtcContainer m_FormatEtcContainer
;
132 typedef CEnumFormatEtc
*PCEnumFormatEtc
;
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */