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: dlgedclip.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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
33 #include "dlgedclip.hxx"
34 #include <vos/mutex.hxx>
35 #include <vcl/svapp.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
38 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
41 using namespace comphelper
;
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::io
;
45 using namespace ::com::sun::star::datatransfer
;
46 using namespace ::com::sun::star::datatransfer::clipboard
;
49 //----------------------------------------------------------------------------
51 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence
< DataFlavor
>& aSeqFlavors
, const Sequence
< Any
>& aSeqData
)
53 m_SeqFlavors
= aSeqFlavors
;
57 //----------------------------------------------------------------------------
59 DlgEdTransferableImpl::~DlgEdTransferableImpl()
63 //----------------------------------------------------------------------------
65 sal_Bool
DlgEdTransferableImpl::compareDataFlavors( const DataFlavor
& lFlavor
, const DataFlavor
& rFlavor
)
67 sal_Bool bRet
= sal_False
;
69 // compare mime content types
70 Reference
< lang::XMultiServiceFactory
> xMSF
= getProcessServiceFactory();
71 Reference
< datatransfer::XMimeContentTypeFactory
>
72 xMCntTypeFactory( xMSF
->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.MimeContentTypeFactory" ) ) ), UNO_QUERY
);
74 if ( xMCntTypeFactory
.is( ) )
76 // compare full media types
77 Reference
< datatransfer::XMimeContentType
> xLType
= xMCntTypeFactory
->createMimeContentType( lFlavor
.MimeType
);
78 Reference
< datatransfer::XMimeContentType
> xRType
= xMCntTypeFactory
->createMimeContentType( rFlavor
.MimeType
);
80 ::rtl::OUString aLFullMediaType
= xLType
->getFullMediaType();
81 ::rtl::OUString aRFullMediaType
= xRType
->getFullMediaType();
83 bRet
= aLFullMediaType
.equalsIgnoreAsciiCase( aRFullMediaType
);
90 //----------------------------------------------------------------------------
92 Any SAL_CALL
DlgEdTransferableImpl::getTransferData( const DataFlavor
& rFlavor
) throw(UnsupportedFlavorException
, IOException
, RuntimeException
)
94 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
96 if ( !isDataFlavorSupported( rFlavor
) )
97 throw UnsupportedFlavorException();
101 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
103 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
105 aData
= m_SeqData
[i
];
113 //----------------------------------------------------------------------------
115 Sequence
< DataFlavor
> SAL_CALL
DlgEdTransferableImpl::getTransferDataFlavors( ) throw(RuntimeException
)
117 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
122 //----------------------------------------------------------------------------
124 sal_Bool SAL_CALL
DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor
& rFlavor
) throw(RuntimeException
)
126 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
128 sal_Bool bRet
= sal_False
;
130 for ( sal_Int32 i
= 0; i
< m_SeqFlavors
.getLength(); i
++ )
132 if ( compareDataFlavors( m_SeqFlavors
[i
] , rFlavor
) )
143 //----------------------------------------------------------------------------
145 void SAL_CALL
DlgEdTransferableImpl::lostOwnership( const Reference
< XClipboard
>&, const Reference
< XTransferable
>& ) throw(RuntimeException
)
147 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
149 m_SeqFlavors
= Sequence
< DataFlavor
>();
150 m_SeqData
= Sequence
< Any
>();