1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basctl.hxx"
26 #include "dlgedclip.hxx"
27 #include <vos/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
31 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
32
33
34 using namespace comphelper;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::io;
38 using namespace ::com::sun::star::datatransfer;
39 using namespace ::com::sun::star::datatransfer::clipboard;
40
41
42 //----------------------------------------------------------------------------
43
DlgEdTransferableImpl(const Sequence<DataFlavor> & aSeqFlavors,const Sequence<Any> & aSeqData)44 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence< DataFlavor >& aSeqFlavors, const Sequence< Any >& aSeqData )
45 {
46 m_SeqFlavors = aSeqFlavors;
47 m_SeqData = aSeqData;
48 }
49
50 //----------------------------------------------------------------------------
51
~DlgEdTransferableImpl()52 DlgEdTransferableImpl::~DlgEdTransferableImpl()
53 {
54 }
55
56 //----------------------------------------------------------------------------
57
compareDataFlavors(const DataFlavor & lFlavor,const DataFlavor & rFlavor)58 sal_Bool DlgEdTransferableImpl::compareDataFlavors( const DataFlavor& lFlavor, const DataFlavor& rFlavor )
59 {
60 sal_Bool bRet = sal_False;
61
62 // compare mime content types
63 Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
64 Reference< datatransfer::XMimeContentTypeFactory >
65 xMCntTypeFactory( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.MimeContentTypeFactory" ) ) ), UNO_QUERY );
66
67 if ( xMCntTypeFactory.is( ) )
68 {
69 // compare full media types
70 Reference< datatransfer::XMimeContentType > xLType = xMCntTypeFactory->createMimeContentType( lFlavor.MimeType );
71 Reference< datatransfer::XMimeContentType > xRType = xMCntTypeFactory->createMimeContentType( rFlavor.MimeType );
72
73 ::rtl::OUString aLFullMediaType = xLType->getFullMediaType();
74 ::rtl::OUString aRFullMediaType = xRType->getFullMediaType();
75
76 bRet = aLFullMediaType.equalsIgnoreAsciiCase( aRFullMediaType );
77 }
78
79 return bRet;
80 }
81
82 // XTransferable
83 //----------------------------------------------------------------------------
84
getTransferData(const DataFlavor & rFlavor)85 Any SAL_CALL DlgEdTransferableImpl::getTransferData( const DataFlavor& rFlavor ) throw(UnsupportedFlavorException, IOException, RuntimeException)
86 {
87 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
88
89 if ( !isDataFlavorSupported( rFlavor ) )
90 throw UnsupportedFlavorException();
91
92 Any aData;
93
94 for ( sal_Int32 i = 0; i < m_SeqFlavors.getLength(); i++ )
95 {
96 if ( compareDataFlavors( m_SeqFlavors[i] , rFlavor ) )
97 {
98 aData = m_SeqData[i];
99 break;
100 }
101 }
102
103 return aData;
104 }
105
106 //----------------------------------------------------------------------------
107
getTransferDataFlavors()108 Sequence< DataFlavor > SAL_CALL DlgEdTransferableImpl::getTransferDataFlavors( ) throw(RuntimeException)
109 {
110 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
111
112 return m_SeqFlavors;
113 }
114
115 //----------------------------------------------------------------------------
116
isDataFlavorSupported(const DataFlavor & rFlavor)117 sal_Bool SAL_CALL DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor& rFlavor ) throw(RuntimeException)
118 {
119 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
120
121 sal_Bool bRet = sal_False;
122
123 for ( sal_Int32 i = 0; i < m_SeqFlavors.getLength(); i++ )
124 {
125 if ( compareDataFlavors( m_SeqFlavors[i] , rFlavor ) )
126 {
127 bRet = sal_True;
128 break;
129 }
130 }
131
132 return bRet;
133 }
134
135 // XClipboardOwner
136 //----------------------------------------------------------------------------
137
lostOwnership(const Reference<XClipboard> &,const Reference<XTransferable> &)138 void SAL_CALL DlgEdTransferableImpl::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) throw(RuntimeException)
139 {
140 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
141
142 m_SeqFlavors = Sequence< DataFlavor >();
143 m_SeqData = Sequence< Any >();
144 }
145
146