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