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: test_aquacb.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_vcl.hxx"
34 #include "aqua_clipboard.hxx"
35 #include <cppuhelper/servicefactory.hxx>
36 #include <com/sun/star/datatransfer/XTransferable.hpp>
37 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
38 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
39 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
42 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
43 #include <cppuhelper/implbase2.hxx>
45 #include <rtl/ustring.hxx>
46 #include <sal/types.h>
47 #include <osl/diagnose.h>
51 using namespace ::rtl
;
52 using namespace ::std
;
53 using namespace ::cppu
;
54 using namespace ::com::sun::star::datatransfer
;
55 using namespace ::com::sun::star::datatransfer::clipboard
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::io
;
58 using namespace ::com::sun::star::lang
;
60 Reference
< XTransferable
> rXTransfRead
;
62 class TestTransferable
: public WeakImplHelper2
< XClipboardOwner
, XTransferable
>
66 virtual Any SAL_CALL
getTransferData( const DataFlavor
& aFlavor
) throw(UnsupportedFlavorException
, IOException
, RuntimeException
);
67 virtual Sequence
< DataFlavor
> SAL_CALL
getTransferDataFlavors() throw(RuntimeException
);
68 virtual sal_Bool SAL_CALL
isDataFlavorSupported( const DataFlavor
& aFlavor
) throw(RuntimeException
);
69 virtual void SAL_CALL
lostOwnership( const Reference
< XClipboard
>& xClipboard
, const Reference
< XTransferable
>& xTrans
) throw(RuntimeException
);
72 Sequence
< DataFlavor
> m_seqDFlv
;
76 TestTransferable::TestTransferable() :
78 m_Data( RTL_CONSTASCII_USTRINGPARAM( "This is a test string" ) )
82 df
.MimeType
= OUString::createFromAscii( "text/html" );
83 df
.DataType
= getCppuType( ( Sequence
< sal_Int8
>* )0 );
88 Any SAL_CALL
TestTransferable::getTransferData( const DataFlavor
& aFlavor
)
89 throw(UnsupportedFlavorException
, IOException
, RuntimeException
)
93 if ( aFlavor
.MimeType
== m_seqDFlv
[0].MimeType
)
95 OString
aStr( m_Data
.getStr(), m_Data
.getLength(), 1252 );
96 Sequence
< sal_Int8
> sOfChars( aStr
.getLength() );
97 sal_Int32 lenStr
= aStr
.getLength();
99 for ( sal_Int32 i
= 0; i
< lenStr
; ++i
)
100 sOfChars
[i
] = aStr
[i
];
102 anyData
= makeAny( sOfChars
);
108 Sequence
< DataFlavor
> SAL_CALL
TestTransferable::getTransferDataFlavors()
109 throw(RuntimeException
)
114 sal_Bool SAL_CALL
TestTransferable::isDataFlavorSupported( const DataFlavor
& aFlavor
)
115 throw(RuntimeException
)
117 sal_Int32 nLength
= m_seqDFlv
.getLength();
118 sal_Bool bRet
= sal_False
;
120 for ( sal_Int32 i
= 0; i
< nLength
; ++i
)
122 if ( m_seqDFlv
[i
].MimeType
== aFlavor
.MimeType
)
132 void SAL_CALL
TestTransferable::lostOwnership( const Reference
< XClipboard
>& xClipboard
, const Reference
< XTransferable
>& xTrans
)
133 throw(RuntimeException
)
137 int SAL_CALL
main( int argc
, char** argv
)
141 fprintf( stderr
, "usage: %s <my rdb file>\n", argv
[0] );
145 //-------------------------------------------------
146 // get the global service-manager
147 //-------------------------------------------------
148 OUString rdbName
= OUString::createFromAscii( argv
[1] );
149 Reference
< XMultiServiceFactory
> g_xFactory( createRegistryServiceFactory( rdbName
) );
151 // Print a message if an error occured.
152 if ( !g_xFactory
.is() )
154 OSL_ENSURE(sal_False
, "Can't create RegistryServiceFactory");
158 //-------------------------------------------------
159 // try to get an Interface to a XFilePicker Service
160 //-------------------------------------------------
162 Reference
< XTransferable
> rXTransf( static_cast< XTransferable
* >( new TestTransferable
) );
164 Reference
< XClipboard
> xClipboard( g_xFactory
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( AQUA_CLIPBOARD_SERVICE_NAME
) ) ), UNO_QUERY
);
165 if ( !xClipboard
.is() )
167 OSL_ENSURE( sal_False
, "Error creating FolderPicker Service" );
171 Reference
< XTypeProvider
> rXTypProv( xClipboard
, UNO_QUERY
);
173 if ( rXTypProv
.is() )
175 Sequence
< Type
> seqType
= rXTypProv
->getTypes();
176 sal_Int32 nLen
= seqType
.getLength();
177 for ( sal_Int32 i
= 0; i
< nLen
; i
++ )
179 Type nxtType
= seqType
[i
];
182 Sequence
< sal_Int8
> seqInt8
= rXTypProv
->getImplementationId();
185 xClipboard
->setContents( rXTransf
, Reference
< XClipboardOwner
>( rXTransf
, UNO_QUERY
) );
187 rXTransfRead
= xClipboard
->getContents();
189 // destroy the transferable explicitly
190 rXTransfRead
= Reference
< XTransferable
>();
192 // destroy the clipboard
193 xClipboard
= Reference
< XClipboard
>();
195 //--------------------------------------------------
196 // shutdown the service manager
197 //--------------------------------------------------
199 // Cast factory to XComponent
200 Reference
< XComponent
> xComponent( g_xFactory
, UNO_QUERY
);
202 if ( !xComponent
.is() )
203 OSL_ENSURE(sal_False
, "Error shuting down");
205 // Dispose and clear factory
206 xComponent
->dispose();
208 g_xFactory
= Reference
< XMultiServiceFactory
>();