fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / win32 / workbench / test_wincb.cxx
bloba2d0ff9ae7a6c20fa34408d0a00377c7cd0879d2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "../misc/ImplHelper.hxx"
22 #include <cppuhelper/servicefactory.hxx>
23 #include <com/sun/star/datatransfer/XTransferable.hpp>
24 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
25 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
27 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <cppuhelper/implbase1.hxx>
30 #include <cppuhelper/implbase2.hxx>
31 #include <rtl/ustring.hxx>
32 #include <sal/types.h>
33 #include <osl/diagnose.h>
35 #include <stdio.h>
36 #if defined _MSC_VER
37 #pragma warning(push,1)
38 #endif
39 #include <windows.h>
40 #include <objbase.h>
41 #if defined _MSC_VER
42 #pragma warning(pop)
43 #endif
45 #include <memory>
47 #include <process.h>
49 // my defines
51 #define TEST_CLIPBOARD
52 #define RDB_SYSPATH "d:\\projects\\src623\\dtrans\\wntmsci7\\bin\\applicat.rdb"
53 #define WINCLIPBOARD_SERVICE_NAME L"com.sun.star.datatransfer.clipboard.SystemClipboard"
54 #define WRITE_CB
55 #define EVT_MANUAL_RESET TRUE
56 #define EVT_INIT_NONSIGNALED FALSE
57 #define EVT_NONAME ""
59 // namesapces
61 using namespace ::std;
62 using namespace ::cppu;
63 using namespace ::com::sun::star::datatransfer;
64 using namespace ::com::sun::star::datatransfer::clipboard;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::io;
67 using namespace ::com::sun::star::lang;
69 // globales
71 Reference< XTransferable > rXTransfRead;
72 HANDLE g_hEvtThreadWakeup;
74 class CClipboardListener : public WeakImplHelper1 < XClipboardListener >
76 public:
77 ~CClipboardListener( );
79 // XClipboardListener
81 virtual void SAL_CALL disposing( const EventObject& Source ) throw(RuntimeException);
82 virtual void SAL_CALL changedContents( const ClipboardEvent& event ) throw( RuntimeException );
85 CClipboardListener::~CClipboardListener( )
89 void SAL_CALL CClipboardListener::disposing( const EventObject& Source ) throw(RuntimeException)
94 void SAL_CALL CClipboardListener::changedContents( const ClipboardEvent& event ) throw( RuntimeException )
96 //MessageBox( NULL, TEXT("Clipboard content changed"), TEXT("Info"), MB_OK | MB_ICONINFORMATION );
99 class CTransferable : public WeakImplHelper2< XClipboardOwner, XTransferable >
101 public:
102 CTransferable( );
104 // XTransferable
106 virtual Any SAL_CALL getTransferData( const DataFlavor& aFlavor )
107 throw(UnsupportedFlavorException, IOException, RuntimeException);
109 virtual Sequence< DataFlavor > SAL_CALL getTransferDataFlavors( ) throw(RuntimeException);
111 virtual sal_Bool SAL_CALL isDataFlavorSupported( const DataFlavor& aFlavor ) throw(RuntimeException);
113 // XClipboardOwner
115 virtual void SAL_CALL lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans )
116 throw(RuntimeException);
118 private:
119 Sequence< DataFlavor > m_FlavorList;
120 OUString m_Data;
123 // ctor
125 CTransferable::CTransferable( ) :
126 m_FlavorList( 1 ),
127 m_Data( OUString("I bought a new bike!") )
129 DataFlavor df;
131 //df.MimeType = L"text/plain;charset=utf-16";
132 //df.DataType = cppu::UnoType<OUString>::get();
134 df.MimeType = L"text/plain;charset=Windows1252";
135 df.DataType = cppu::UnoType<Sequence< sal_Int8 >>::get();
137 m_FlavorList[0] = df;
140 // getTransferData
142 Any SAL_CALL CTransferable::getTransferData( const DataFlavor& aFlavor )
143 throw(UnsupportedFlavorException, IOException, RuntimeException)
145 Any anyData;
148 if ( aFlavor.MimeType == m_FlavorList[0].MimeType )
149 anyData = makeAny( m_Data );
151 if ( aFlavor.MimeType.equalsIgnoreCase( m_FlavorList[0].MimeType ) )
153 OString text(
154 m_Data.getStr( ),
155 m_Data.getLength( ),
156 RTL_TEXTENCODING_ASCII_US );
158 Sequence< sal_Int8 > textStream( text.getLength( ) + 1 );
160 memcpy( textStream.getArray( ), text.getStr( ), textStream.getLength( ) );
162 anyData = makeAny( textStream );
164 else
165 throw UnsupportedFlavorException( );
167 return anyData;
170 // getTransferDataFlavors
172 Sequence< DataFlavor > SAL_CALL CTransferable::getTransferDataFlavors( )
173 throw(RuntimeException)
175 return m_FlavorList;
178 // isDataFlavorSupported
180 sal_Bool SAL_CALL CTransferable::isDataFlavorSupported( const DataFlavor& aFlavor )
181 throw(RuntimeException)
183 sal_Int32 nLength = m_FlavorList.getLength( );
185 for ( sal_Int32 i = 0; i < nLength; ++i )
186 if ( m_FlavorList[i].MimeType == aFlavor.MimeType )
187 return sal_True;
189 return sal_False;
192 // lostOwnership
194 void SAL_CALL CTransferable::lostOwnership(
195 const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans )
196 throw(RuntimeException)
198 //MessageBox( NULL, TEXT("No longer clipboard owner"), TEXT("Info"), MB_OK | MB_ICONINFORMATION );
201 // main
203 int SAL_CALL main( int nArgc, char* Argv[] )
205 // create a multi-threaded apartment; we can test only
206 // with a multithreaded apartment because for a single
207 // threaded apartment we need a message loop to deliver
208 // messages to our XTDataObject
209 //HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
210 HRESULT hr = CoInitialize( NULL );
212 char buff[6];
214 LCID lcid = MAKELCID( MAKELANGID( LANG_GERMAN, SUBLANG_GERMAN ), SORT_DEFAULT );
216 BOOL bValid = IsValidLocale( lcid, LCID_SUPPORTED );
217 GetLocaleInfoA( lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof( buff ) );
219 // get the global service-manager
221 OUString rdbName = OUString( RDB_SYSPATH );
222 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
224 // Print a message if an error occurred.
225 if ( !g_xFactory.is( ) )
227 OSL_FAIL("Can't create RegistryServiceFactory");
228 return(-1);
231 // try to get an Interface to a XFilePicker Service
233 Reference< XTransferable > rXTransf( static_cast< XTransferable* >( new CTransferable ) );
235 Reference< XClipboard >
236 xClipboard( g_xFactory->createInstance( OUString( WINCLIPBOARD_SERVICE_NAME ) ), UNO_QUERY );
237 if ( !xClipboard.is( ) )
239 OSL_FAIL( "Error creating Clipboard Service" );
240 return(-1);
243 Reference< XClipboardNotifier > xClipNotifier( xClipboard, UNO_QUERY );
244 Reference< XClipboardListener > rXClipListener( static_cast< XClipboardListener* >( new CClipboardListener() ) );
245 xClipNotifier->addClipboardListener( rXClipListener );
247 MessageBox( NULL, TEXT("Go"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION);
249 // set new clipboard content
250 xClipboard->setContents( rXTransf, Reference< XClipboardOwner >( rXTransf, UNO_QUERY ) );
253 MessageBox( NULL, TEXT("Clear content"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION);
255 Reference< XClipboardOwner > rXClipOwner;
256 Reference< XTransferable > rXEmptyTransf;
257 xClipboard->setContents( rXEmptyTransf, rXClipOwner );
260 MessageBox( NULL, TEXT("Stop"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION);
262 // flush the clipboard content
263 Reference< XFlushableClipboard > rXFlushableClip( xClipboard, UNO_QUERY );
264 rXFlushableClip->flushClipboard( );
265 rXFlushableClip.clear();
267 xClipNotifier->removeClipboardListener( rXClipListener );
268 rXClipListener.clear();
269 xClipNotifier.clear();
271 // shutdown the service manager
273 // Cast factory to XComponent
274 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
276 if ( !xComponent.is() )
277 OSL_FAIL("Error shuting down");
279 // Dispose and clear factory
280 xComponent->dispose();
281 xComponent.clear();
283 g_xFactory.clear();
285 CoUninitialize( );
287 return 0;
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */