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