diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /dtrans/source/win32/workbench | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dtrans/source/win32/workbench')
-rw-r--r-- | dtrans/source/win32/workbench/XTDo.cxx | 358 | ||||
-rw-r--r-- | dtrans/source/win32/workbench/XTDo.hxx | 114 | ||||
-rw-r--r-- | dtrans/source/win32/workbench/makefile.mk | 81 | ||||
-rw-r--r-- | dtrans/source/win32/workbench/test_wincb.cxx | 287 | ||||
-rw-r--r-- | dtrans/source/win32/workbench/testmarshal.cxx | 213 |
5 files changed, 1053 insertions, 0 deletions
diff --git a/dtrans/source/win32/workbench/XTDo.cxx b/dtrans/source/win32/workbench/XTDo.cxx new file mode 100644 index 000000000..f8da707d9 --- /dev/null +++ b/dtrans/source/win32/workbench/XTDo.cxx @@ -0,0 +1,358 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <osl/diagnose.h> + +#include "../DTransHelper.hxx" + +#include "XTDo.hxx" + +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include <windows.h> +#include <ole2.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include <memory> + +using namespace ::std; + +// OTWrapperDataObject + +/* + in the constructor we enumerate all formats offered by the transferable + and convert the formats into formatetc structures + if the transferable supports text in different charsets we use either + the charset equal to the charset of the current thread or an arbitrary + charset supported by the transferable and the system + if the transferable supports only unicodetext we offer in addition to + this text in the charset of the current thread + in order to allow the consumer of the clipboard to query for the charset + of the text in the clipboard we offer a CF_LOCALE +*/ +CXTDataObject::CXTDataObject( ) : + m_nRefCnt( 0 ) +{ + +} + +// IUnknown->QueryInterface + +STDMETHODIMP CXTDataObject::QueryInterface( REFIID iid, LPVOID* ppvObject ) +{ + OSL_ASSERT( NULL != ppvObject ); + + if ( NULL == ppvObject ) + return E_INVALIDARG; + + HRESULT hr = E_NOINTERFACE; + + *ppvObject = NULL; + + if ( ( __uuidof( IUnknown ) == iid ) || ( __uuidof( IDataObject ) == iid ) ) + { + *ppvObject = static_cast< IUnknown* >( this ); + ( (LPUNKNOWN)*ppvObject )->AddRef( ); + hr = S_OK; + } + + return hr; +} + +// IUnknown->AddRef + +STDMETHODIMP_(ULONG) CXTDataObject::AddRef( ) +{ + return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) ); +} + +// IUnknown->Release + +STDMETHODIMP_(ULONG) CXTDataObject::Release( ) +{ + // we need a helper variable because it's + // not allowed to access a member variable + // after an object is destroyed + ULONG nRefCnt = static_cast< ULONG >( InterlockedDecrement( &m_nRefCnt ) ); + + if ( 0 == nRefCnt ) + { + delete this; + } + + return nRefCnt; +} + +/*------------------------------------------------------------------------ + + IDataObject->GetData + we deliver data only into global memory + + algo: + 1. convert the given formatect struct into a valid dataflavor + 2. if the transferable directly supports the requested format + 2.1. if text data requested add a trailing '\0' in order to prevent + problems (windows needs '\0' terminated strings + 2.2. we expect unicode data as Sequence< sal_Unicode > and all other + text and raw data as Sequence< sal_Int8 > + +------------------------------------------------------------------------*/ + +STDMETHODIMP CXTDataObject::GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium ) +{ + if ( ( NULL == pFormatetc ) || ( NULL == pmedium ) ) + return E_INVALIDARG; + + HRESULT hr = E_FAIL; + + if ( CF_TEXT == pFormatetc->cfFormat ) + { + CHGlobalHelper hGlobHlp( TRUE ); + + char pBuff[] = "Test OleClipboard"; + hGlobHlp.Write( pBuff, sizeof( pBuff ), NULL ); + + pmedium->tymed = TYMED_HGLOBAL; + pmedium->hGlobal = hGlobHlp.GetHGlobal( ); + pmedium->pUnkForRelease = NULL; + + hr = S_OK; + } + + return hr; +} + +// IDataObject->EnumFormatEtc + +STDMETHODIMP CXTDataObject::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc ) +{ + if ( ( NULL == ppenumFormatetc ) || ( DATADIR_SET == dwDirection ) ) + return E_INVALIDARG; + + *ppenumFormatetc = NULL; + + HRESULT hr = E_FAIL; + + if ( DATADIR_GET == dwDirection ) + { + *ppenumFormatetc = new CEnumFormatEtc( this ); + static_cast< LPUNKNOWN >( *ppenumFormatetc )->AddRef( ); + hr = S_OK; + } + + return hr; +} + +// IDataObject->QueryGetData + +STDMETHODIMP CXTDataObject::QueryGetData( LPFORMATETC pFormatetc ) +{ + return E_NOTIMPL; +} + +// IDataObject->GetDataHere + +STDMETHODIMP CXTDataObject::GetDataHere( LPFORMATETC, LPSTGMEDIUM ) +{ + return E_NOTIMPL; +} + +// IDataObject->GetCanonicalFormatEtc + +STDMETHODIMP CXTDataObject::GetCanonicalFormatEtc( LPFORMATETC, LPFORMATETC ) +{ + return E_NOTIMPL; +} + +// IDataObject->SetData + +STDMETHODIMP CXTDataObject::SetData( LPFORMATETC, LPSTGMEDIUM, BOOL ) +{ + return E_NOTIMPL; +} + +// IDataObject->DAdvise + +STDMETHODIMP CXTDataObject::DAdvise( LPFORMATETC, DWORD, LPADVISESINK, DWORD * ) +{ + return E_NOTIMPL; +} + +// IDataObject->DUnadvise + +STDMETHODIMP CXTDataObject::DUnadvise( DWORD ) +{ + return E_NOTIMPL; +} + +// IDataObject->EnumDAdvise + +STDMETHODIMP CXTDataObject::EnumDAdvise( LPENUMSTATDATA * ) +{ + return E_NOTIMPL; +} + +CXTDataObject::operator IDataObject*( ) +{ + return static_cast< IDataObject* >( this ); +} + +CEnumFormatEtc::CEnumFormatEtc( LPUNKNOWN pUnkDataObj ) : + m_nRefCnt( 0 ), + m_pUnkDataObj( pUnkDataObj ), + m_nCurrPos( 0 ) +{ +} + +// IUnknown->QueryInterface + +STDMETHODIMP CEnumFormatEtc::QueryInterface( REFIID iid, LPVOID* ppvObject ) +{ + if ( NULL == ppvObject ) + return E_INVALIDARG; + + HRESULT hr = E_NOINTERFACE; + + *ppvObject = NULL; + + if ( ( __uuidof( IUnknown ) == iid ) || ( __uuidof( IEnumFORMATETC ) == iid ) ) + { + *ppvObject = static_cast< IUnknown* >( this ); + static_cast< LPUNKNOWN >( *ppvObject )->AddRef( ); + hr = S_OK; + } + + return hr; +} + +// IUnknown->AddRef + +STDMETHODIMP_(ULONG) CEnumFormatEtc::AddRef( ) +{ + // keep the dataobject alive + m_pUnkDataObj->AddRef( ); + return InterlockedIncrement( &m_nRefCnt ); +} + +// IUnknown->Release + +STDMETHODIMP_(ULONG) CEnumFormatEtc::Release( ) +{ + // release the outer dataobject + m_pUnkDataObj->Release( ); + + // we need a helper variable because it's + // not allowed to access a member variable + // after an object is destroyed + ULONG nRefCnt = InterlockedDecrement( &m_nRefCnt ); + if ( 0 == nRefCnt ) + delete this; + + return nRefCnt; +} + +// IEnumFORMATETC->Next + +STDMETHODIMP CEnumFormatEtc::Next( ULONG celt, LPFORMATETC rgelt, ULONG* pceltFetched ) +{ + if ( ( 0 != celt ) && ( NULL == rgelt ) ) + return E_INVALIDARG; + + ULONG ulFetched = 0; + ULONG ulToFetch = celt; + HRESULT hr = S_FALSE; + + while( m_nCurrPos < 1 ) + { + rgelt->cfFormat = CF_TEXT; + rgelt->ptd = NULL; + rgelt->dwAspect = DVASPECT_CONTENT; + rgelt->lindex = -1; + rgelt->tymed = TYMED_HGLOBAL; + + ++m_nCurrPos; + ++rgelt; + --ulToFetch; + ++ulFetched; + } + + if ( ulFetched == celt ) + hr = S_OK; + + if ( NULL != pceltFetched ) + { + *pceltFetched = ulFetched; + } + + return hr; +} + +// IEnumFORMATETC->Skip + +STDMETHODIMP CEnumFormatEtc::Skip( ULONG celt ) +{ + HRESULT hr = S_FALSE; + + /* + if ( ( m_nCurrPos + celt ) < m_nClipFormats ) + { + m_nCurrPos += celt; + hr = S_OK; + } + */ + + return hr; +} + +// IEnumFORMATETC->Reset + +STDMETHODIMP CEnumFormatEtc::Reset( ) +{ + m_nCurrPos = 0; + return S_OK; +} + +// IEnumFORMATETC->Clone + +STDMETHODIMP CEnumFormatEtc::Clone( IEnumFORMATETC** ppenum ) +{ + OSL_ASSERT( NULL != ppenum ); + + if ( NULL == ppenum ) + return E_INVALIDARG; + + HRESULT hr = E_FAIL; + + *ppenum = NULL; + + CEnumFormatEtc* pCEnumFEtc = new CEnumFormatEtc( m_pUnkDataObj ); + if ( NULL != pCEnumFEtc ) + { + pCEnumFEtc->m_nCurrPos = m_nCurrPos; + *ppenum = static_cast< IEnumFORMATETC* >( pCEnumFEtc ); + static_cast< LPUNKNOWN >( *ppenum )->AddRef( ); + hr = NOERROR; + } + + return hr; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/win32/workbench/XTDo.hxx b/dtrans/source/win32/workbench/XTDo.hxx new file mode 100644 index 000000000..50f842559 --- /dev/null +++ b/dtrans/source/win32/workbench/XTDo.hxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_DTRANS_SOURCE_WIN32_WORKBENCH_XTDO_HXX +#define INCLUDED_DTRANS_SOURCE_WIN32_WORKBENCH_XTDO_HXX + +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include <windows.h> +#include <ole2.h> +#include <objidl.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif + +#include <vector> + +class EnumFormatEtc; + +/*-------------------------------------------------------------------------- + - the function principle of the windows clipboard: + a data provider offers all formats he can deliver on the clipboard + a clipboard client ask for the available formats on the clipboard + and decides if there is a format he can use + if there is one, he requests the data in this format + + - This class inherits from IDataObject and so can be placed on the + OleClipboard. The class wraps a transferable object which is the + original DataSource + - DataFlavors offered by this transferable will be translated into + appropriate clipboard formats + - if the transferable contains text data always text and unicodetext + will be offered or vice versa + - text data will be automatically converted between text and unicode text + - although the transferable may support text in different charsets + (codepages) only text in one codepage can be offered by the clipboard + +----------------------------------------------------------------------------*/ + +class CXTDataObject : public IDataObject +{ +public: + CXTDataObject( ); + + // ole interface implementation + + //IUnknown interface methods + STDMETHODIMP QueryInterface(REFIID iid, LPVOID* ppvObject); + STDMETHODIMP_( ULONG ) AddRef( ); + STDMETHODIMP_( ULONG ) Release( ); + + // IDataObject interface methods + STDMETHODIMP GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium ); + STDMETHODIMP GetDataHere( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium ); + STDMETHODIMP QueryGetData( LPFORMATETC pFormatetc ); + STDMETHODIMP GetCanonicalFormatEtc( LPFORMATETC pFormatectIn, LPFORMATETC pFormatetcOut ); + STDMETHODIMP SetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium, BOOL fRelease ); + STDMETHODIMP EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc ); + STDMETHODIMP DAdvise( LPFORMATETC pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD* pdwConnection ); + STDMETHODIMP DUnadvise( DWORD dwConnection ); + STDMETHODIMP EnumDAdvise( LPENUMSTATDATA* ppenumAdvise ); + + operator IDataObject*( ); + +private: + +private: + LONG m_nRefCnt; +}; + +class CEnumFormatEtc : public IEnumFORMATETC +{ +public: + explicit CEnumFormatEtc( LPUNKNOWN pUnkDataObj ); + + // IUnknown + STDMETHODIMP QueryInterface( REFIID iid, LPVOID* ppvObject ); + STDMETHODIMP_( ULONG ) AddRef( ); + STDMETHODIMP_( ULONG ) Release( ); + + //IEnumFORMATETC + STDMETHODIMP Next( ULONG celt, LPFORMATETC rgelt, ULONG* pceltFetched ); + STDMETHODIMP Skip( ULONG celt ); + STDMETHODIMP Reset( ); + STDMETHODIMP Clone( IEnumFORMATETC** ppenum ); + +private: + LONG m_nRefCnt; + LPUNKNOWN m_pUnkDataObj; + ULONG m_nCurrPos; +}; + +typedef CEnumFormatEtc *PCEnumFormatEtc; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/win32/workbench/makefile.mk b/dtrans/source/win32/workbench/makefile.mk new file mode 100644 index 000000000..3c82289f8 --- /dev/null +++ b/dtrans/source/win32/workbench/makefile.mk @@ -0,0 +1,81 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +PRJ=..$/..$/.. + +PRJNAME= dtrans +TARGET= testwincb +TARGET1= testmshl +LIBTARGET= NO +TARGETTYPE= CUI +USE_BOUNDCHK= +TESTCB=TRUE + +.IF "$(USE_BOUNDCHK)"=="TR" +bndchk=tr +stoponerror=tr +.ENDIF + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(TESTCB)"=="TRUE" + +CFLAGS+=-D_WIN32_DCOM -EHsc -Ob0 + +# --- Files -------------------------------------------------------- + +OBJFILES= $(OBJ)$/test_wincb.obj +APP1TARGET= $(TARGET) +APP1OBJS= $(OBJ)$/test_wincb.obj + +APP1STDLIBS= $(SALLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(USER32LIB) \ + $(OLE32LIB)\ + $(COMDLG32LIB) + +APP1LIBS= $(SLB)$/dtutils.lib + +APP1NOSAL= TRUE + +.ENDIF + +.IF "$(TESTCB)"=="" + +CFLAGS+=/D_WIN32_DCOM /EHsc /Ob0 + +OBJFILES= $(OBJ)$/testmarshal.obj +APP1TARGET= $(TARGET1) +APP1OBJS= $(OBJ)$/testmarshal.obj + +APP1STDLIBS= $(SALLIB)\ + $(USER32LIB)\ + $(OLE32LIB)\ + comsupp.lib\ + $(OLEAUT32LIB) + +APP1LIBS= +APP1NOSAL= TRUE + +.ENDIF + +# --- Targets ------------------------------------------------------ +.INCLUDE : target.mk diff --git a/dtrans/source/win32/workbench/test_wincb.cxx b/dtrans/source/win32/workbench/test_wincb.cxx new file mode 100644 index 000000000..96839e22a --- /dev/null +++ b/dtrans/source/win32/workbench/test_wincb.cxx @@ -0,0 +1,287 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "../misc/ImplHelper.hxx" + +#include <cppuhelper/servicefactory.hxx> +#include <com/sun/star/datatransfer/XTransferable.hpp> +#include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp> +#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp> +#include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp> +#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/implbase.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <osl/diagnose.h> + +#include <stdio.h> +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include <windows.h> +#include <objbase.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif + +#include <memory> + +#include <process.h> + +// my defines + +#define TEST_CLIPBOARD +#define RDB_SYSPATH "d:\\projects\\src623\\dtrans\\wntmsci7\\bin\\applicat.rdb" +#define WINCLIPBOARD_SERVICE_NAME L"com.sun.star.datatransfer.clipboard.SystemClipboard" +#define WRITE_CB +#define EVT_MANUAL_RESET TRUE +#define EVT_INIT_NONSIGNALED FALSE +#define EVT_NONAME "" + +// namespaces + +using namespace ::std; +using namespace ::cppu; +using namespace ::com::sun::star::datatransfer; +using namespace ::com::sun::star::datatransfer::clipboard; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; + +// globales + +Reference< XTransferable > rXTransfRead; +HANDLE g_hEvtThreadWakeup; + +class CClipboardListener : public WeakImplHelper < XClipboardListener > +{ +public: + ~CClipboardListener( ); + + // XClipboardListener + + virtual void SAL_CALL disposing( const EventObject& Source ) throw(RuntimeException); + virtual void SAL_CALL changedContents( const ClipboardEvent& event ) throw( RuntimeException ); +}; + +CClipboardListener::~CClipboardListener( ) +{ +} + +void SAL_CALL CClipboardListener::disposing( const EventObject& Source ) throw(RuntimeException) +{ + +} + +void SAL_CALL CClipboardListener::changedContents( const ClipboardEvent& event ) throw( RuntimeException ) +{ + //MessageBox( NULL, TEXT("Clipboard content changed"), TEXT("Info"), MB_OK | MB_ICONINFORMATION ); +} + +class CTransferable : public WeakImplHelper< XClipboardOwner, XTransferable > +{ +public: + CTransferable( ); + + // XTransferable + + virtual Any SAL_CALL getTransferData( const DataFlavor& aFlavor ) + throw(UnsupportedFlavorException, IOException, RuntimeException); + + virtual Sequence< DataFlavor > SAL_CALL getTransferDataFlavors( ) throw(RuntimeException); + + virtual sal_Bool SAL_CALL isDataFlavorSupported( const DataFlavor& aFlavor ) throw(RuntimeException); + + // XClipboardOwner + + virtual void SAL_CALL lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) + throw(RuntimeException); + +private: + Sequence< DataFlavor > m_FlavorList; + OUString m_Data; +}; + +// ctor + +CTransferable::CTransferable( ) : + m_FlavorList( 1 ), + m_Data( OUString("I bought a new bike!") ) +{ + DataFlavor df; + + //df.MimeType = L"text/plain;charset=utf-16"; + //df.DataType = cppu::UnoType<OUString>::get(); + + df.MimeType = L"text/plain;charset=Windows1252"; + df.DataType = cppu::UnoType<Sequence< sal_Int8 >>::get(); + + m_FlavorList[0] = df; +} + +// getTransferData + +Any SAL_CALL CTransferable::getTransferData( const DataFlavor& aFlavor ) + throw(UnsupportedFlavorException, IOException, RuntimeException) +{ + Any anyData; + + /* + if ( aFlavor.MimeType == m_FlavorList[0].MimeType ) + anyData = makeAny( m_Data ); + */ + if ( aFlavor.MimeType.equalsIgnoreCase( m_FlavorList[0].MimeType ) ) + { + OString text( + m_Data.getStr( ), + m_Data.getLength( ), + RTL_TEXTENCODING_ASCII_US ); + + Sequence< sal_Int8 > textStream( text.getLength( ) + 1 ); + + memcpy( textStream.getArray( ), text.getStr( ), textStream.getLength( ) ); + + anyData = makeAny( textStream ); + } + else + throw UnsupportedFlavorException( ); + + return anyData; +} + +// getTransferDataFlavors + +Sequence< DataFlavor > SAL_CALL CTransferable::getTransferDataFlavors( ) + throw(RuntimeException) +{ + return m_FlavorList; +} + +// isDataFlavorSupported + +sal_Bool SAL_CALL CTransferable::isDataFlavorSupported( const DataFlavor& aFlavor ) + throw(RuntimeException) +{ + sal_Int32 nLength = m_FlavorList.getLength( ); + + for ( sal_Int32 i = 0; i < nLength; ++i ) + if ( m_FlavorList[i].MimeType == aFlavor.MimeType ) + return sal_True; + + return sal_False; +} + +// lostOwnership + +void SAL_CALL CTransferable::lostOwnership( + const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) + throw(RuntimeException) +{ + //MessageBox( NULL, TEXT("No longer clipboard owner"), TEXT("Info"), MB_OK | MB_ICONINFORMATION ); +} + +// main + +int SAL_CALL main( int nArgc, char* Argv[] ) +{ + // create a multi-threaded apartment; we can test only + // with a multithreaded apartment because for a single + // threaded apartment we need a message loop to deliver + // messages to our XTDataObject + //HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED ); + (void)CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ); + + char buff[6]; + + LCID lcid = MAKELCID( MAKELANGID( LANG_GERMAN, SUBLANG_GERMAN ), SORT_DEFAULT ); + + BOOL bValid = IsValidLocale( lcid, LCID_SUPPORTED ); + GetLocaleInfoA( lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof( buff ) ); + + // get the global service-manager + + Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( RDB_SYSPATH ) ); + + // Print a message if an error occurred. + if ( !g_xFactory.is( ) ) + { + OSL_FAIL("Can't create RegistryServiceFactory"); + return(-1); + } + + // try to get an Interface to a XFilePicker Service + + Reference< XTransferable > rXTransf( static_cast< XTransferable* >( new CTransferable ) ); + + Reference< XClipboard >xClipboard( g_xFactory->createInstance( WINCLIPBOARD_SERVICE_NAME ), UNO_QUERY ); + if ( !xClipboard.is( ) ) + { + OSL_FAIL( "Error creating Clipboard Service" ); + return(-1); + } + + Reference< XClipboardNotifier > xClipNotifier( xClipboard, UNO_QUERY ); + Reference< XClipboardListener > rXClipListener( static_cast< XClipboardListener* >( new CClipboardListener() ) ); + xClipNotifier->addClipboardListener( rXClipListener ); + + MessageBox( NULL, TEXT("Go"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION); + + // set new clipboard content + xClipboard->setContents( rXTransf, Reference< XClipboardOwner >( rXTransf, UNO_QUERY ) ); + + /* + MessageBox( NULL, TEXT("Clear content"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION); + + Reference< XClipboardOwner > rXClipOwner; + Reference< XTransferable > rXEmptyTransf; + xClipboard->setContents( rXEmptyTransf, rXClipOwner ); + */ + + MessageBox( NULL, TEXT("Stop"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION); + + // flush the clipboard content + Reference< XFlushableClipboard > rXFlushableClip( xClipboard, UNO_QUERY ); + rXFlushableClip->flushClipboard( ); + rXFlushableClip.clear(); + + xClipNotifier->removeClipboardListener( rXClipListener ); + rXClipListener.clear(); + xClipNotifier.clear(); + + // shutdown the service manager + + // Cast factory to XComponent + Reference< XComponent > xComponent( g_xFactory, UNO_QUERY ); + + if ( !xComponent.is() ) + OSL_FAIL("Error shutting down"); + + // Dispose and clear factory + xComponent->dispose(); + xComponent.clear(); + + g_xFactory.clear(); + + CoUninitialize( ); + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/win32/workbench/testmarshal.cxx b/dtrans/source/win32/workbench/testmarshal.cxx new file mode 100644 index 000000000..d9edfe753 --- /dev/null +++ b/dtrans/source/win32/workbench/testmarshal.cxx @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <rtl/ustring.hxx> +#include <sal/types.h> + +#include <stdio.h> +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include <windows.h> +#include <objbase.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif + +#include <memory> + +#include <process.h> +#include "XTDo.hxx" + +// my defines + +#define WRITE_CB +#define EVT_MANUAL_RESET TRUE +#define EVT_INIT_NONSIGNALED FALSE +#define EVT_NONAME "" +#define WAIT_MSGLOOP +#define RAW_MARSHALING + +// namespaces + +using namespace ::std; + +// globales + +HANDLE g_hEvtThreadWakeup; + +#ifdef RAW_MARSHALING + HGLOBAL g_hGlob; +#else + IStream* g_pStm; +#endif + +// a thread in another apartment to test apartment transparency + +unsigned int _stdcall ThreadProc(LPVOID pParam) +{ + // setup another apartment + HRESULT hr = OleInitialize( NULL ); + + WaitForSingleObject( g_hEvtThreadWakeup, INFINITE ); + + IDataObject* pIDo = NULL; + +#ifdef RAW_MARSHALING + + IStream* pStm = NULL; + hr = CreateStreamOnHGlobal( g_hGlob, FALSE, &pStm ); + if ( SUCCEEDED( hr ) ) + { + hr = CoUnmarshalInterface( + pStm, + __uuidof( IDataObject ), + (void**)&pIDo ); + + hr = pStm->Release( ); + } + +#else + + hr = CoGetInterfaceAndReleaseStream( + g_pStm, + __uuidof( IDataObject ), + (void**)&pIDo + ); + +#endif + + IEnumFORMATETC* pIEEtc; + hr = pIDo->EnumFormatEtc( DATADIR_GET, &pIEEtc ); + + hr = OleIsCurrentClipboard( pIDo ); + + hr = OleFlushClipboard( ); + + OleUninitialize( ); + + return 0; +} + +// main + +int SAL_CALL main( int nArgc, char* Argv[] ) +{ + HRESULT hr = OleInitialize( NULL ); + + g_hEvtThreadWakeup = CreateEvent( 0, + EVT_MANUAL_RESET, + EVT_INIT_NONSIGNALED, + EVT_NONAME ); + + unsigned uThreadId; + HANDLE hThread; + + // create a thread in another apartment + hThread = (void*)_beginthreadex( NULL, 0, ThreadProc, NULL, 0, &uThreadId ); + + IDataObject* pIDo = new CXTDataObject( ); + + hr = OleSetClipboard( pIDo ); + hr = E_FAIL; + + hr = OleIsCurrentClipboard( pIDo ); + + //hr = OleGetClipboard( &pIDo ); + if ( SUCCEEDED( hr ) ) + { +#ifdef RAW_MARSHALING + + IStream* pStm = NULL; + + hr = CreateStreamOnHGlobal( 0, FALSE, &pStm ); + if ( SUCCEEDED( hr ) ) + { + hr = CoMarshalInterface( + pStm, + __uuidof( IDataObject ), + pIDo, + MSHCTX_INPROC, + 0, + MSHLFLAGS_NORMAL ); + if ( SUCCEEDED( hr ) ) + hr = GetHGlobalFromStream( pStm, &g_hGlob ); + + hr = pStm->Release( ); + } + +#else + + hr = CoMarshalInterThreadInterfaceInStream( + __uuidof( IDataObject ), + pIDo, + &g_pStm ); + +#endif + + if ( SUCCEEDED( hr ) ) + { + // wakeup the thread and waiting util it ends + SetEvent( g_hEvtThreadWakeup ); + +#ifdef WAIT_MSGLOOP + + BOOL bContinue = TRUE; + + while( bContinue ) + { + DWORD dwResult = WaitForMultipleObjects( + 1, + &hThread, + TRUE, + 0 ); + + if ( WAIT_OBJECT_0 == dwResult ) + { + bContinue = FALSE; + } + else + { + MSG msg; + while( PeekMessage( + &msg, + NULL, + 0, + 0, + PM_REMOVE ) ) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } // while + +#endif + + } // if + } // if + + OleFlushClipboard( ); + + OleUninitialize( ); + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |