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 :
21 : #if OSL_DEBUG_LEVEL > 1
22 : #include <stdio.h>
23 : #endif
24 :
25 : #include <X11_transferable.hxx>
26 : #include <X11/Xatom.h>
27 : #include <com/sun/star/io/IOException.hpp>
28 :
29 : using namespace com::sun::star::datatransfer;
30 : using namespace com::sun::star::lang;
31 : using namespace com::sun::star::io;
32 : using namespace com::sun::star::uno;
33 : using namespace cppu;
34 : using namespace osl;
35 :
36 : using namespace x11;
37 :
38 :
39 :
40 0 : X11Transferable::X11Transferable(
41 : SelectionManager& rManager,
42 : Atom selection
43 : ) :
44 : m_rManager( rManager ),
45 0 : m_aSelection( selection )
46 : {
47 0 : }
48 :
49 : //==================================================================================================
50 :
51 0 : X11Transferable::~X11Transferable()
52 : {
53 0 : }
54 :
55 : //==================================================================================================
56 :
57 0 : Any SAL_CALL X11Transferable::getTransferData( const DataFlavor& rFlavor )
58 : throw(UnsupportedFlavorException, IOException, RuntimeException)
59 : {
60 0 : Any aRet;
61 0 : Sequence< sal_Int8 > aData;
62 0 : bool bSuccess = m_rManager.getPasteData( m_aSelection ? m_aSelection : XA_PRIMARY, rFlavor.MimeType, aData );
63 0 : if( ! bSuccess && m_aSelection == 0 )
64 0 : bSuccess = m_rManager.getPasteData( m_rManager.getAtom( OUString("CLIPBOARD") ), rFlavor.MimeType, aData );
65 :
66 0 : if( ! bSuccess )
67 : {
68 0 : throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) );
69 : }
70 0 : if( rFlavor.MimeType.equalsIgnoreAsciiCase( OUString("text/plain;charset=utf-16") ) )
71 : {
72 0 : int nLen = aData.getLength()/2;
73 0 : if( ((sal_Unicode*)aData.getConstArray())[nLen-1] == 0 )
74 0 : nLen--;
75 0 : OUString aString( (sal_Unicode*)aData.getConstArray(), nLen );
76 : #if OSL_DEBUG_LEVEL > 1
77 : fprintf( stderr, "X11Transferable::getTransferData( \"%s\" )\n -> \"%s\"\n",
78 : OUStringToOString( rFlavor.MimeType, RTL_TEXTENCODING_ISO_8859_1 ).getStr(),
79 : OUStringToOString( aString, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
80 : #endif
81 0 : aRet <<= aString;
82 : }
83 : else
84 0 : aRet <<= aData;
85 0 : return aRet;
86 : }
87 :
88 : //==================================================================================================
89 :
90 0 : Sequence< DataFlavor > SAL_CALL X11Transferable::getTransferDataFlavors()
91 : throw(RuntimeException)
92 : {
93 0 : Sequence< DataFlavor > aFlavorList;
94 0 : bool bSuccess = m_rManager.getPasteDataTypes( m_aSelection ? m_aSelection : XA_PRIMARY, aFlavorList );
95 0 : if( ! bSuccess && m_aSelection == 0 )
96 0 : bSuccess = m_rManager.getPasteDataTypes( m_rManager.getAtom( OUString("CLIPBOARD") ), aFlavorList );
97 :
98 0 : return aFlavorList;
99 : }
100 :
101 : //==================================================================================================
102 :
103 0 : sal_Bool SAL_CALL X11Transferable::isDataFlavorSupported( const DataFlavor& aFlavor )
104 : throw(RuntimeException)
105 : {
106 0 : if( aFlavor.DataType != getCppuType( (Sequence< sal_Int8 >*)0 ) )
107 : {
108 0 : if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( OUString("text/plain;charset=utf-16") ) &&
109 0 : aFlavor.DataType == getCppuType( (OUString*)0 ) )
110 0 : return false;
111 : }
112 :
113 0 : Sequence< DataFlavor > aFlavors( getTransferDataFlavors() );
114 0 : for( int i = 0; i < aFlavors.getLength(); i++ )
115 0 : if( aFlavor.MimeType.equalsIgnoreAsciiCase( aFlavors.getConstArray()[i].MimeType ) &&
116 0 : aFlavor.DataType == aFlavors.getConstArray()[i].DataType )
117 0 : return sal_True;
118 :
119 0 : return sal_False;
120 : }
121 :
122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|