1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: X11_transferable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dtrans.hxx"
34 #if OSL_DEBUG_LEVEL > 1
38 #include <X11_transferable.hxx>
39 #include <X11/Xatom.h>
40 #include <com/sun/star/io/IOException.hpp>
42 using namespace com::sun::star::datatransfer
;
43 using namespace com::sun::star::lang
;
44 using namespace com::sun::star::io
;
45 using namespace com::sun::star::uno
;
54 X11Transferable::X11Transferable(
55 SelectionManager
& rManager
,
56 const Reference
< XInterface
>& xCreator
,
59 m_rManager( rManager
),
60 m_xCreator( xCreator
),
61 m_aSelection( selection
)
65 //==================================================================================================
67 X11Transferable::~X11Transferable()
71 //==================================================================================================
73 Any SAL_CALL
X11Transferable::getTransferData( const DataFlavor
& rFlavor
)
74 throw(UnsupportedFlavorException
, IOException
, RuntimeException
)
77 Sequence
< sal_Int8
> aData
;
78 bool bSuccess
= m_rManager
.getPasteData( m_aSelection
? m_aSelection
: XA_PRIMARY
, rFlavor
.MimeType
, aData
);
79 if( ! bSuccess
&& m_aSelection
== 0 )
80 bSuccess
= m_rManager
.getPasteData( m_rManager
.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ), rFlavor
.MimeType
, aData
);
84 throw UnsupportedFlavorException( rFlavor
.MimeType
, static_cast < XTransferable
* > ( this ) );
86 if( rFlavor
.MimeType
.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) )
88 int nLen
= aData
.getLength()/2;
89 if( ((sal_Unicode
*)aData
.getConstArray())[nLen
-1] == 0 )
91 OUString
aString( (sal_Unicode
*)aData
.getConstArray(), nLen
);
92 #if OSL_DEBUG_LEVEL > 1
93 fprintf( stderr
, "X11Transferable::getTransferData( \"%s\" )\n -> \"%s\"\n",
94 OUStringToOString( rFlavor
.MimeType
, RTL_TEXTENCODING_ISO_8859_1
).getStr(),
95 OUStringToOString( aString
, RTL_TEXTENCODING_ISO_8859_1
).getStr() );
104 //==================================================================================================
106 Sequence
< DataFlavor
> SAL_CALL
X11Transferable::getTransferDataFlavors()
107 throw(RuntimeException
)
109 Sequence
< DataFlavor
> aFlavorList
;
110 bool bSuccess
= m_rManager
.getPasteDataTypes( m_aSelection
? m_aSelection
: XA_PRIMARY
, aFlavorList
);
111 if( ! bSuccess
&& m_aSelection
== 0 )
112 bSuccess
= m_rManager
.getPasteDataTypes( m_rManager
.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ), aFlavorList
);
117 //==================================================================================================
119 sal_Bool SAL_CALL
X11Transferable::isDataFlavorSupported( const DataFlavor
& aFlavor
)
120 throw(RuntimeException
)
122 if( aFlavor
.DataType
!= getCppuType( (Sequence
< sal_Int8
>*)0 ) )
124 if( ! aFlavor
.MimeType
.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) &&
125 aFlavor
.DataType
== getCppuType( (OUString
*)0 ) )
129 Sequence
< DataFlavor
> aFlavors( getTransferDataFlavors() );
130 for( int i
= 0; i
< aFlavors
.getLength(); i
++ )
131 if( aFlavor
.MimeType
.equalsIgnoreAsciiCase( aFlavors
.getConstArray()[i
].MimeType
) &&
132 aFlavor
.DataType
== aFlavors
.getConstArray()[i
].DataType
)