Line data Source code
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 : #include <vcl/wrkwin.hxx>
21 : #include <vcl/dialog.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <eeobj.hxx>
25 : #include <sot/exchange.hxx>
26 : #include <sot/formats.hxx>
27 : #include <editeng/editeng.hxx>
28 : #include <svl/itempool.hxx>
29 : #include <cppuhelper/queryinterface.hxx>
30 : #include <osl/mutex.hxx>
31 :
32 : using namespace ::com::sun::star;
33 :
34 :
35 0 : EditDataObject::EditDataObject()
36 : {
37 0 : }
38 :
39 0 : EditDataObject::~EditDataObject()
40 : {
41 0 : }
42 :
43 : // uno::XInterface
44 0 : uno::Any EditDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException, std::exception)
45 : {
46 0 : uno::Any aRet = ::cppu::queryInterface( rType, (static_cast< datatransfer::XTransferable* >(this)) );
47 0 : return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
48 : }
49 :
50 : // datatransfer::XTransferable
51 0 : uno::Any EditDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException, std::exception)
52 : {
53 0 : uno::Any aAny;
54 :
55 0 : SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
56 0 : if ( nT == SotClipboardFormatId::STRING )
57 : {
58 0 : aAny <<= GetString();
59 : }
60 0 : else if ( ( nT == SotClipboardFormatId::EDITENGINE ) || ( nT == SotClipboardFormatId::RTF ) )
61 : {
62 : // No RTF on demand any more:
63 : // 1) Was not working, because I had to flush() the clipboard immediately anyway
64 : // 2) Don't have the old pool defaults and the StyleSheetPool here.
65 :
66 0 : SvMemoryStream* pStream = ( nT == SotClipboardFormatId::EDITENGINE ) ? &GetStream() : &GetRTFStream();
67 0 : pStream->Seek( STREAM_SEEK_TO_END );
68 0 : sal_Size nLen = pStream->Tell();
69 0 : pStream->Seek(0);
70 :
71 0 : uno::Sequence< sal_Int8 > aSeq( nLen );
72 0 : memcpy( aSeq.getArray(), pStream->GetData(), nLen );
73 0 : aAny <<= aSeq;
74 : }
75 : else
76 : {
77 0 : datatransfer::UnsupportedFlavorException aException;
78 0 : throw( aException );
79 : }
80 :
81 0 : return aAny;
82 : }
83 :
84 0 : uno::Sequence< datatransfer::DataFlavor > EditDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException, std::exception)
85 : {
86 0 : uno::Sequence< datatransfer::DataFlavor > aDataFlavors(3);
87 0 : SotExchange::GetFormatDataFlavor( SotClipboardFormatId::EDITENGINE, aDataFlavors.getArray()[0] );
88 0 : SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aDataFlavors.getArray()[1] );
89 0 : SotExchange::GetFormatDataFlavor( SotClipboardFormatId::RTF, aDataFlavors.getArray()[2] );
90 :
91 0 : return aDataFlavors;
92 : }
93 :
94 0 : sal_Bool EditDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException, std::exception)
95 : {
96 0 : bool bSupported = false;
97 :
98 0 : SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
99 0 : if ( ( nT == SotClipboardFormatId::STRING ) || ( nT == SotClipboardFormatId::RTF ) || ( nT == SotClipboardFormatId::EDITENGINE ) )
100 0 : bSupported = true;
101 :
102 0 : return bSupported;
103 : }
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|