LibreOffice Module dtrans (master)  1
XTDataObject.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_XTDATAOBJECT_HXX
21 #define INCLUDED_DTRANS_SOURCE_WIN32_DTOBJ_XTDATAOBJECT_HXX
22 
23 #include <com/sun/star/datatransfer/XTransferable.hpp>
24 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
25 
26 #include "DataFmtTransl.hxx"
27 
28 #include "FetcList.hxx"
29 
30 #if !defined WIN32_LEAN_AND_MEAN
31 # define WIN32_LEAN_AND_MEAN
32 #endif
33 #include <windows.h>
34 #include <ole2.h>
35 #include <objidl.h>
36 
37 /*--------------------------------------------------------------------------
38  - the function principle of the windows clipboard:
39  a data provider offers all formats he can deliver on the clipboard
40  a clipboard client ask for the available formats on the clipboard
41  and decides if there is a format he can use
42  if there is one, he requests the data in this format
43 
44  - This class inherits from IDataObject and so can be placed on the
45  OleClipboard. The class wraps a transferable object which is the
46  original DataSource
47  - DataFlavors offered by this transferable will be translated into
48  appropriate clipboard formats
49  - if the transferable contains text data always text and unicodetext
50  will be offered or vice versa
51  - text data will be automatically converted between text and unicode text
52  - although the transferable may support text in different charsets
53  (codepages) only text in one codepage can be offered by the clipboard
54 
55 ----------------------------------------------------------------------------*/
56 
57 class CStgTransferHelper;
58 
59 class CXTDataObject : public IDataObject
60 {
61 public:
62  CXTDataObject( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
63  const css::uno::Reference< css::datatransfer::XTransferable >& aXTransferable );
64  virtual ~CXTDataObject();
65 
66  // ole interface implementation
67 
68  //IUnknown interface methods
69  STDMETHODIMP QueryInterface(REFIID iid, void** ppvObject) override;
70  STDMETHODIMP_( ULONG ) AddRef( ) override;
71  STDMETHODIMP_( ULONG ) Release( ) override;
72 
73  // IDataObject interface methods
74  STDMETHODIMP GetData( FORMATETC * pFormatetc, STGMEDIUM * pmedium ) override;
75  STDMETHODIMP GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pmedium ) override;
76  STDMETHODIMP QueryGetData( FORMATETC * pFormatetc ) override;
77  STDMETHODIMP GetCanonicalFormatEtc( FORMATETC * pFormatectIn, FORMATETC * pFormatetcOut ) override;
78  STDMETHODIMP SetData( FORMATETC * pFormatetc, STGMEDIUM * pmedium, BOOL fRelease ) override;
79  STDMETHODIMP EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc ) override;
80  STDMETHODIMP DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD* pdwConnection ) override;
81  STDMETHODIMP DUnadvise( DWORD dwConnection ) override;
82  STDMETHODIMP EnumDAdvise( IEnumSTATDATA** ppenumAdvise ) override;
83 
84  operator IDataObject*( );
85 
86 private:
87  css::datatransfer::DataFlavor formatEtcToDataFlavor( const FORMATETC& aFormatEtc ) const;
88 
89  void renderLocaleAndSetupStgMedium( FORMATETC const & fetc, STGMEDIUM& stgmedium );
90  void renderUnicodeAndSetupStgMedium( FORMATETC const & fetc, STGMEDIUM& stgmedium );
91  void renderAnyDataAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
92 
93  HRESULT renderSynthesizedFormatAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
94  void renderSynthesizedUnicodeAndSetupStgMedium( FORMATETC const & fetc, STGMEDIUM& stgmedium );
95  void renderSynthesizedTextAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
96  void renderSynthesizedHtmlAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
97 
98  inline void InitializeFormatEtcContainer( );
99 
100 private:
102  css::uno::Reference< css::datatransfer::XTransferable > m_XTransferable;
103  css::uno::Reference< css::uno::XComponentContext> m_XComponentContext;
108 };
109 
110 class CEnumFormatEtc : public IEnumFORMATETC
111 {
112 public:
113  CEnumFormatEtc( LPUNKNOWN lpUnkOuter, const CFormatEtcContainer& aFormatEtcContainer );
114  virtual ~CEnumFormatEtc() {}
115 
116  // IUnknown
117  STDMETHODIMP QueryInterface( REFIID iid, void** ppvObject ) override;
118  STDMETHODIMP_( ULONG ) AddRef( ) override;
119  STDMETHODIMP_( ULONG ) Release( ) override;
120 
121  //IEnumFORMATETC
122  STDMETHODIMP Next( ULONG nRequested, FORMATETC * lpDest, ULONG* lpFetched ) override;
123  STDMETHODIMP Skip( ULONG celt ) override;
124  STDMETHODIMP Reset( ) override;
125  STDMETHODIMP Clone( IEnumFORMATETC** ppenum ) override;
126 
127 private:
128  LONG m_nRefCnt;
129  LPUNKNOWN m_lpUnkOuter;
131 };
132 
134 
135 #endif
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHODIMP GetCanonicalFormatEtc(FORMATETC *pFormatectIn, FORMATETC *pFormatetcOut) override
STDMETHODIMP Reset() override
STDMETHODIMP DAdvise(FORMATETC *pFormatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection) override
css::datatransfer::DataFlavor formatEtcToDataFlavor(const FORMATETC &aFormatEtc) const
STDMETHODIMP Next(ULONG nRequested, FORMATETC *lpDest, ULONG *lpFetched) override
CFormatRegistrar m_FormatRegistrar
void renderUnicodeAndSetupStgMedium(FORMATETC const &fetc, STGMEDIUM &stgmedium)
LONG
css::uno::Reference< css::datatransfer::XTransferable > m_XTransferable
STDMETHODIMP Skip(ULONG celt) override
STDMETHODIMP GetDataHere(FORMATETC *pFormatetc, STGMEDIUM *pmedium) override
STDMETHODIMP Clone(IEnumFORMATETC **ppenum) override
STDMETHODIMP GetData(FORMATETC *pFormatetc, STGMEDIUM *pmedium) override
const wchar_t *typedef BOOL
STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject) override
void renderSynthesizedUnicodeAndSetupStgMedium(FORMATETC const &fetc, STGMEDIUM &stgmedium)
CFormatEtcContainer m_FormatEtcContainer
STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject) override
virtual ~CEnumFormatEtc()
STDMETHODIMP QueryGetData(FORMATETC *pFormatetc) override
void renderAnyDataAndSetupStgMedium(FORMATETC &fetc, STGMEDIUM &stgmedium)
void renderSynthesizedTextAndSetupStgMedium(FORMATETC &fetc, STGMEDIUM &stgmedium)
void InitializeFormatEtcContainer()
STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppenumFormatetc) override
LPUNKNOWN m_lpUnkOuter
css::uno::Reference< css::uno::XComponentContext > m_XComponentContext
HRESULT renderSynthesizedFormatAndSetupStgMedium(FORMATETC &fetc, STGMEDIUM &stgmedium)
STDMETHODIMP DUnadvise(DWORD dwConnection) override
CFormatEtcContainer m_FormatEtcContainer
STDMETHODIMP_(ULONG) AddRef() override
STDMETHODIMP SetData(FORMATETC *pFormatetc, STGMEDIUM *pmedium, BOOL fRelease) override
virtual ~CXTDataObject()
CEnumFormatEtc(LPUNKNOWN lpUnkOuter, const CFormatEtcContainer &aFormatEtcContainer)
void renderSynthesizedHtmlAndSetupStgMedium(FORMATETC &fetc, STGMEDIUM &stgmedium)
STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppenumAdvise) override
void renderLocaleAndSetupStgMedium(FORMATETC const &fetc, STGMEDIUM &stgmedium)
bool m_bFormatEtcContainerInitialized
CXTDataObject()
Definition: XTDo.cxx:51
STDMETHODIMP_(ULONG) AddRef() override
CDataFormatTranslator m_DataFormatTranslator