tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / basctl / source / dlged / dlgedclip.cxx
blobe10733af229b1bd9dc82998ef117e1345a32fc3f
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 .
20 #include <dlgedclip.hxx>
21 #include <vcl/svapp.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
24 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
25 #include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
27 namespace basctl
30 using namespace comphelper;
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::datatransfer;
34 using namespace ::com::sun::star::datatransfer::clipboard;
35 DlgEdTransferableImpl::DlgEdTransferableImpl( const Sequence< DataFlavor >& aSeqFlavors, const Sequence< Any >& aSeqData )
37 m_SeqFlavors = aSeqFlavors;
38 m_SeqData = aSeqData;
40 DlgEdTransferableImpl::~DlgEdTransferableImpl()
43 bool DlgEdTransferableImpl::compareDataFlavors( const DataFlavor& lFlavor, const DataFlavor& rFlavor )
45 // compare mime content types
46 const Reference< uno::XComponentContext >& xContext = getProcessComponentContext();
47 Reference< datatransfer::XMimeContentTypeFactory >
48 xMCntTypeFactory = MimeContentTypeFactory::create(xContext);
50 // compare full media types
51 Reference< datatransfer::XMimeContentType > xLType = xMCntTypeFactory->createMimeContentType( lFlavor.MimeType );
52 Reference< datatransfer::XMimeContentType > xRType = xMCntTypeFactory->createMimeContentType( rFlavor.MimeType );
54 OUString aLFullMediaType = xLType->getFullMediaType();
55 OUString aRFullMediaType = xRType->getFullMediaType();
57 bool bRet = aLFullMediaType.equalsIgnoreAsciiCase( aRFullMediaType );
59 return bRet;
62 // XTransferable
63 Any SAL_CALL DlgEdTransferableImpl::getTransferData( const DataFlavor& rFlavor )
65 const SolarMutexGuard aGuard;
67 if ( !isDataFlavorSupported( rFlavor ) )
68 throw UnsupportedFlavorException();
70 Any aData;
72 for ( sal_Int32 i = 0; i < m_SeqFlavors.getLength(); i++ )
74 if ( compareDataFlavors( m_SeqFlavors[i] , rFlavor ) )
76 aData = m_SeqData[i];
77 break;
81 return aData;
83 Sequence< DataFlavor > SAL_CALL DlgEdTransferableImpl::getTransferDataFlavors( )
85 const SolarMutexGuard aGuard;
87 return m_SeqFlavors;
89 sal_Bool SAL_CALL DlgEdTransferableImpl::isDataFlavorSupported( const DataFlavor& rFlavor )
91 const SolarMutexGuard aGuard;
93 for (auto const& i : m_SeqFlavors)
94 if ( compareDataFlavors( i, rFlavor ) )
95 return true;
96 return false;
99 // XClipboardOwner
100 void SAL_CALL DlgEdTransferableImpl::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& )
102 const SolarMutexGuard aGuard;
104 m_SeqFlavors = Sequence< DataFlavor >();
105 m_SeqData = Sequence< Any >();
107 } // namespace basctl
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */