diff options
-rw-r--r-- | dtrans/prj/build.lst | 1 | ||||
-rw-r--r-- | dtrans/source/inc/MtaOleClipb.hxx | 153 | ||||
-rw-r--r-- | dtrans/source/win32/clipb/WinClipbImpl.cxx | 52 | ||||
-rw-r--r-- | dtrans/source/win32/clipb/WinClipbImpl.hxx | 19 | ||||
-rw-r--r-- | dtrans/source/win32/clipb/WinClipboard.cxx | 7 | ||||
-rw-r--r-- | dtrans/source/win32/clipb/makefile.mk | 8 | ||||
-rw-r--r-- | dtrans/source/win32/dtobj/DtObjFactory.cxx | 16 | ||||
-rw-r--r-- | dtrans/source/win32/dtobj/makefile.mk | 6 | ||||
-rw-r--r-- | dtrans/source/win32/mtaole/MtaOleClipb.cxx | 703 | ||||
-rw-r--r-- | dtrans/source/win32/mtaole/makefile.mk | 85 | ||||
-rw-r--r-- | dtrans/source/win32/workbench/makefile.mk | 10 | ||||
-rw-r--r-- | dtrans/source/win32/workbench/test_wincb.cxx | 221 |
12 files changed, 1083 insertions, 198 deletions
diff --git a/dtrans/prj/build.lst b/dtrans/prj/build.lst index 71015f696309..ae94615d0705 100644 --- a/dtrans/prj/build.lst +++ b/dtrans/prj/build.lst @@ -2,6 +2,7 @@ dr dtrans : offapi rdbmaker NULL dr dtrans usr1 - all dr_mkout NULL dr dtrans\source\cnttype nmake - all dr_cnttype NULL dr dtrans\source\win32\misc nmake - w dr_win32_misc NULL +dr dtrans\source\win32\mtaole nmake - w dr_win32_mtaole NULL dr dtrans\source\win32\ftransl nmake - w dr_win32_ftransl dr_win32_misc NULL dr dtrans\source\win32\dtobj nmake - w dr_win32_dtobj dr_win32_misc dr_win32_ftransl NULL dr dtrans\source\win32\clipb nmake - w dr_win32_clipb dr_win32_dtobj NULL diff --git a/dtrans/source/inc/MtaOleClipb.hxx b/dtrans/source/inc/MtaOleClipb.hxx new file mode 100644 index 000000000000..e3323d2b9869 --- /dev/null +++ b/dtrans/source/inc/MtaOleClipb.hxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * $RCSfile: MtaOleClipb.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: tra $ $Date: 2001-03-14 14:48:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _MTAOLECLIPB_HXX_ +#define _MTAOLECLIPB_HXX_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +//#include <windows.h> +#include <objidl.h> + +//-------------------------------------------------------- +// the Mta-Ole clipboard class is for internal use only! +// only one instance of this class should be created, the +// user has to ensure this! +// the class is not thread-safe because it will be used +// only from within the clipboard service and the methods +// of the clipboard service are already synchronized +//-------------------------------------------------------- + +class CMtaOleClipboard +{ +public: + typedef void ( WINAPI *LPFNC_CLIPVIEWER_CALLBACK_t )( void ); + +public: + CMtaOleClipboard( ); + ~CMtaOleClipboard( ); + + // clipboard functions + HRESULT setClipboard( IDataObject* pIDataObject ); + HRESULT getClipboard( IDataObject** ppIDataObject ); + HRESULT flushClipboard( ); + + // register/unregister a clipboard viewer; there can only + // be one at a time; parameter NULL means unregister + // a clipboard viewer + // returns true on success else false; use GetLastError( ) in + // false case + sal_Bool registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback ); + +private: + unsigned int run( ); + + // create a hidden windows which serves as an request + // target; so we guarantee synchronization + void createMtaOleReqWnd( ); + + // message support + sal_Bool postMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 ); + LRESULT sendMessage( UINT msg, WPARAM wParam = 0, LPARAM lParam = 0 ); + + //--------------------------------------------------------------- + // message handler functions; remeber these functions are called + // from a different thread context! + //--------------------------------------------------------------- + + LRESULT onSetClipboard( IDataObject* pIDataObject ); + LRESULT onGetClipboard( LPSTREAM* ppStream ); + LRESULT onFlushClipboard( ); + sal_Bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback ); + + // win32 clipboard-viewer support + LRESULT onChangeCBChain( HWND hWndRemove, HWND hWndNext ); + LRESULT onDrawClipboard( ); + + static LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); + static unsigned int WINAPI oleThreadProc( LPVOID pParam ); + + sal_Bool WaitForThreadReady( ) const; + sal_Bool WaitOpComplete( ) const; + +private: + HANDLE m_hOleThread; + unsigned m_uOleThreadId; + HANDLE m_hEvtThrdReady; + HANDLE m_hEvtOpComplete; + HANDLE m_hEvtWmDrawClipboardReady; + HWND m_hwndMtaOleReqWnd; + HWND m_hwndNextClipViewer; + LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback; + sal_Bool m_bInRegisterClipViewer; + sal_Bool m_bInFlushClipboard; + + static CMtaOleClipboard* s_theMtaOleClipboardInst; + +// not allowed +private: + CMtaOleClipboard( const CMtaOleClipboard& ); + CMtaOleClipboard& operator=( const CMtaOleClipboard& ); +}; + +#endif
\ No newline at end of file diff --git a/dtrans/source/win32/clipb/WinClipbImpl.cxx b/dtrans/source/win32/clipb/WinClipbImpl.cxx index dd929602c624..9e3789d83bf9 100644 --- a/dtrans/source/win32/clipb/WinClipbImpl.cxx +++ b/dtrans/source/win32/clipb/WinClipbImpl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WinClipbImpl.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: tra $ $Date: 2001-03-07 11:23:10 $ + * last change: $Author: tra $ $Date: 2001-03-14 14:43:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,10 +75,6 @@ #include "..\..\inc\DtObjFactory.hxx" #endif -#ifndef _MTAOLECLIPB_H_ -#include <systools\win32\MtaOleClipb.h> -#endif - #ifndef _APNDATAOBJECT_HXX_ #include "APNDataObject.hxx" #endif @@ -152,15 +148,15 @@ Reference< XTransferable > SAL_CALL CWinClipbImpl::getContents( ) throw( Runtime { MutexGuard aGuard( m_aMutex ); + Reference< XTransferable > rClipContent; + if ( m_rCurrentClipbContent.is( ) ) - { - return m_rCurrentClipbContent; - } + rClipContent = m_rCurrentClipbContent; else { // get the current dataobject from clipboard IDataObjectPtr pIDataObject; - MTAGetClipboard( &pIDataObject ); + m_MtaOleClipboard.getClipboard( &pIDataObject ); // create an apartment neutral dataobject and initialize it with a // com smart pointer to the IDataObject from clipboard @@ -169,8 +165,10 @@ Reference< XTransferable > SAL_CALL CWinClipbImpl::getContents( ) throw( Runtime CDTransObjFactory objFactory; // remeber pIDo destroys itself due to the smart pointer - return objFactory.createTransferableFromDataObj( m_pWinClipboard->m_SrvMgr, pIDo ); + rClipContent = objFactory.createTransferableFromDataObj( m_pWinClipboard->m_SrvMgr, pIDo ); } + + return rClipContent; } //------------------------------------------------------------------------ @@ -203,7 +201,7 @@ void SAL_CALL CWinClipbImpl::setContents( const Reference< XTransferable >& xTra m_pWinClipboard->m_aCondition.reset( ); aGuard.clear( ); - MTASetClipboard( pIDataObj ); + m_MtaOleClipboard.setClipboard( pIDataObj ); } //------------------------------------------------------------------------ @@ -230,25 +228,26 @@ sal_Int8 SAL_CALL CWinClipbImpl::getRenderingCapabilities( ) throw( RuntimeExce void SAL_CALL CWinClipbImpl::flushClipboard( ) throw( RuntimeException ) { - MTAFlushClipboard( ); + if ( m_rCurrentClipbContent.is( ) ) + m_MtaOleClipboard.flushClipboard( ); } //------------------------------------------------------------------------ // //------------------------------------------------------------------------ -void SAL_CALL CWinClipbImpl::registerClipboardViewer( ) const +void SAL_CALL CWinClipbImpl::registerClipboardViewer( ) { - MTARegisterClipboardViewer( CWinClipbImpl::onClipboardContentChanged ); + m_MtaOleClipboard.registerClipViewer( CWinClipbImpl::onClipboardContentChanged ); } //------------------------------------------------------------------------ // //------------------------------------------------------------------------ -void SAL_CALL CWinClipbImpl::unregisterClipboardViewer( ) const +void SAL_CALL CWinClipbImpl::unregisterClipboardViewer( ) { - MTARegisterClipboardViewer( NULL ); + m_MtaOleClipboard.registerClipViewer( NULL ); } //------------------------------------------------------------------------ @@ -261,37 +260,37 @@ void SAL_CALL CWinClipbImpl::dispose() throw( RuntimeException ) !m_rOldClipbOwner.is( ) && !m_rCurrentClipbContent.is( ) && !m_rCurrentClipbOwner.is( ), - "Clipboard was not flushed before!" ); + "Clipboard was not flushed before shutdown!" ); } //------------------------------------------------------------------------ // //------------------------------------------------------------------------ -void CALLBACK CWinClipbImpl::onClipboardContentChanged( void ) +void WINAPI CWinClipbImpl::onClipboardContentChanged( void ) { ClearableMutexGuard aGuard( s_pCWinClipbImpl->m_aMutex ); Reference< XTransferable > xClipbContent; Reference< XClipboardOwner > xClipbOwner; - if ( s_pCWinClipbImpl->m_rOldClipbContent.is( ) && - s_pCWinClipbImpl->m_rOldClipbOwner.is( ) ) + if ( s_pCWinClipbImpl->m_rOldClipbContent.is( ) ) { // release the condition because of expected callbacks // to the clipboard service (remeber: the mutex is already // released) s_pCWinClipbImpl->m_pWinClipboard->m_aCondition.set( ); - s_pCWinClipbImpl->m_rOldClipbOwner->lostOwnership( - s_pCWinClipbImpl->m_pWinClipboard, s_pCWinClipbImpl->m_rOldClipbContent ); + // notify the old ClipboardOwner + if ( s_pCWinClipbImpl->m_rOldClipbOwner.is( ) ) + s_pCWinClipbImpl->m_rOldClipbOwner->lostOwnership( + s_pCWinClipbImpl->m_pWinClipboard, s_pCWinClipbImpl->m_rOldClipbContent ); s_pCWinClipbImpl->m_rOldClipbOwner = Reference< XClipboardOwner >( ); s_pCWinClipbImpl->m_rOldClipbContent = Reference< XTransferable >( ); } else if ( !s_pCWinClipbImpl->m_bSelfTriggered && - ( s_pCWinClipbImpl->m_rCurrentClipbContent.is( ) && - s_pCWinClipbImpl->m_rCurrentClipbOwner.is( ) ) ) + s_pCWinClipbImpl->m_rCurrentClipbContent.is( ) ) { // save the state variables locally xClipbContent = s_pCWinClipbImpl->m_rCurrentClipbContent; @@ -306,7 +305,8 @@ void CALLBACK CWinClipbImpl::onClipboardContentChanged( void ) s_pCWinClipbImpl->m_pWinClipboard->m_aCondition.set( ); // notify the old ClipboardOwner - xClipbOwner->lostOwnership( s_pCWinClipbImpl->m_pWinClipboard, xClipbContent ); + if ( xClipbOwner.is( ) ) + xClipbOwner->lostOwnership( s_pCWinClipbImpl->m_pWinClipboard, xClipbContent ); } s_pCWinClipbImpl->m_pWinClipboard->m_aCondition.set( ); diff --git a/dtrans/source/win32/clipb/WinClipbImpl.hxx b/dtrans/source/win32/clipb/WinClipbImpl.hxx index f29fcead6b9b..0a47183145e1 100644 --- a/dtrans/source/win32/clipb/WinClipbImpl.hxx +++ b/dtrans/source/win32/clipb/WinClipbImpl.hxx @@ -2,9 +2,9 @@ * * $RCSfile: WinClipbImpl.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: tra $ $Date: 2001-03-07 11:23:10 $ + * last change: $Author: tra $ $Date: 2001-03-14 14:43:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,6 +87,10 @@ #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp> #endif +#ifndef _MTAOLECLIPB_HXX_ +#include "..\..\inc\MtaOleClipb.hxx" +#endif + #include <windows.h> #include <comdef.h> @@ -137,14 +141,15 @@ protected: // member functions //------------------------------------------------ - void SAL_CALL registerClipboardViewer( ) const; - void SAL_CALL unregisterClipboardViewer( ) const; + void SAL_CALL registerClipboardViewer( ); + void SAL_CALL unregisterClipboardViewer( ); - static void CALLBACK onClipboardContentChanged( void ); + static void WINAPI onClipboardContentChanged( void ); sal_Bool SAL_CALL isInDispose( ) const; ::rtl::OUString m_itsName; + CMtaOleClipboard m_MtaOleClipboard; static CWinClipbImpl* s_pCWinClipbImpl; CWinClipboard* m_pWinClipboard; sal_Bool m_bInDispose; @@ -156,6 +161,10 @@ protected: osl::Mutex m_aMutex; friend class CWinClipboard; + +private: + CWinClipbImpl( const CWinClipbImpl& ); + CWinClipbImpl& operator=( const CWinClipbImpl& ); }; #endif
\ No newline at end of file diff --git a/dtrans/source/win32/clipb/WinClipboard.cxx b/dtrans/source/win32/clipb/WinClipboard.cxx index bdb6e772396e..5c56c5fc20d6 100644 --- a/dtrans/source/win32/clipb/WinClipboard.cxx +++ b/dtrans/source/win32/clipb/WinClipboard.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WinClipboard.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: tra $ $Date: 2001-03-09 08:45:20 $ + * last change: $Author: tra $ $Date: 2001-03-14 14:43:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -238,7 +238,8 @@ void SAL_CALL CWinClipboard::notifyAllClipboardListener( ) if ( pICHelper ) { OInterfaceIteratorHelper iter( *pICHelper ); - ClipboardEvent aClipbEvent( *this, m_pImpl->getContents( ) ); + Reference< XTransferable > rXTransf = m_pImpl->getContents( ); + ClipboardEvent aClipbEvent( static_cast< XClipboard* >( this ), rXTransf ); while( iter.hasMoreElements( ) ) { diff --git a/dtrans/source/win32/clipb/makefile.mk b/dtrans/source/win32/clipb/makefile.mk index bdb225d31df4..9c2aafeab954 100644 --- a/dtrans/source/win32/clipb/makefile.mk +++ b/dtrans/source/win32/clipb/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: tra $ $Date: 2001-03-02 15:38:15 $ +# last change: $Author: tra $ $Date: 2001-03-14 14:43:42 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -107,11 +107,11 @@ SHL1IMPLIB=i$(SHL1TARGET) #--- comment ----------------- SHL1LIBS= \ - $(SOLARLIBDIR)$/imtaolecb.lib\ $(SOLARLIBDIR)$/user9x.lib\ $(SOLARLIBDIR)$/tools32.lib\ $(SLB)$/dtutils.lib\ - $(SLB)$/dtobjfact.lib + $(SLB)$/dtobjfact.lib\ + $(SLB)$/mtaolecb.lib SHL1OBJS= $(SLOFILES) SHL1DEF= $(MISC)$/$(SHL1TARGET).def diff --git a/dtrans/source/win32/dtobj/DtObjFactory.cxx b/dtrans/source/win32/dtobj/DtObjFactory.cxx index f8e0cff12766..39c2d2d62d12 100644 --- a/dtrans/source/win32/dtobj/DtObjFactory.cxx +++ b/dtrans/source/win32/dtobj/DtObjFactory.cxx @@ -2,9 +2,9 @@ * * $RCSfile: DtObjFactory.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: tra $ $Date: 2001-03-02 17:20:33 $ + * last change: $Author: tra $ $Date: 2001-03-14 14:45:14 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,12 +75,6 @@ #include "DOTransferable.hxx" #endif -/* -#ifndef _WRPDOTRANSFERABLE_HXX_ -#include "WrpDOTransferable.hxx" -#endif -*/ - //------------------------------------------------------------------------ // namespace directives //------------------------------------------------------------------------ @@ -96,10 +90,6 @@ using namespace com::sun::star::lang; IDataObjectPtr SAL_CALL CDTransObjFactory::createDataObjFromTransferable( const Reference< XMultiServiceFactory >& aServiceManager, const Reference< XTransferable >& refXTransferable ) { - /* - Reference< XTransferable > wrpTransf( new CWrpDOTransferable( aServiceManager, refXTransferable, sal_False ) ); - return ( IDataObjectPtr( new CXTDataObject( aServiceManager, wrpTransf ) ) ); - */ return ( IDataObjectPtr( new CXTDataObject( aServiceManager, refXTransferable ) ) ); } @@ -113,8 +103,6 @@ Reference< XTransferable > SAL_CALL CDTransObjFactory::createTransferableFromDat pTransf->initFlavorList( ); pTransf->release( ); - //return Reference< XTransferable >( new CWrpDOTransferable( aServiceManager, refDOTransf ) ); - return refDOTransf; } diff --git a/dtrans/source/win32/dtobj/makefile.mk b/dtrans/source/win32/dtobj/makefile.mk index ecd368c8279b..a3646f0ae1d1 100644 --- a/dtrans/source/win32/dtobj/makefile.mk +++ b/dtrans/source/win32/dtobj/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.5 $ +# $Revision: 1.6 $ # -# last change: $Author: tra $ $Date: 2001-03-02 17:48:30 $ +# last change: $Author: tra $ $Date: 2001-03-14 14:45:41 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -88,8 +88,6 @@ SLOFILES=$(SLO)$/DtObjFactory.obj\ $(SLO)$/FetcList.obj\ $(SLO)$/Fetc.obj -#$(SLO)$/WrpDOTransferable.obj - LIB1TARGET=$(SLB)$/$(TARGET).lib LIB1OBJFILES=$(SLOFILES) diff --git a/dtrans/source/win32/mtaole/MtaOleClipb.cxx b/dtrans/source/win32/mtaole/MtaOleClipb.cxx new file mode 100644 index 000000000000..1d2b2b37494c --- /dev/null +++ b/dtrans/source/win32/mtaole/MtaOleClipb.cxx @@ -0,0 +1,703 @@ +/************************************************************************* + * + * $RCSfile: MtaOleClipb.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: tra $ $Date: 2001-03-14 14:47:01 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#pragma warning( disable : 4290 ) // c++ exception specification ignored +#pragma warning( disable : 4786 ) // identifier was truncated to 'number' + // characters in the debug information + +#define UNICODE + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#include <systools/win32/user9x.h> + +#include "..\..\inc\MtaOleClipb.hxx" + +#include <wchar.h> +#include <process.h> + +//---------------------------------------------------------------- +// defines +//---------------------------------------------------------------- + +#define HIDDEN_CB_WNDCLS_NAME L"MtaOleReqWnd_920896680C9449" +#define CLIPSERVICE_DLL_NAME "sysdtrans.dll" + +//-------------------------------------------------------- +// messages constants +//-------------------------------------------------------- + +const sal_uInt32 MSG_SETCLIPBOARD = WM_USER + 0x0001; +const sal_uInt32 MSG_GETCLIPBOARD = WM_USER + 0x0002; +const sal_uInt32 MSG_REGCLIPVIEWER = WM_USER + 0x0003; +const sal_uInt32 MSG_FLUSHCLIPBOARD = WM_USER + 0x0004; +const sal_uInt32 MSG_SHUTDOWN = WM_USER + 0x0006; + +const sal_uInt32 MAX_WAITTIME = 60000; +const sal_uInt32 MAX_OPCOMPLET_WAITTIME = 60000; +const sal_uInt32 MAX_WAIT_SHUTDOWN = 30000; +const sal_uInt32 MAX_CLIPEVENT_PROCESSING_TIME = 5000; + +const sal_Bool MANUAL_RESET = sal_True; +const sal_Bool AUTO_RESET = sal_False; +const sal_Bool INIT_NONSIGNALED = sal_False; + +//---------------------------------------------------------------- +// static member initialization +//---------------------------------------------------------------- + +CMtaOleClipboard* CMtaOleClipboard::s_theMtaOleClipboardInst = NULL; + +//-------------------------------------------------------------------- +// marshal an IDataObject +//-------------------------------------------------------------------- + +inline +HRESULT MarshalIDataObjectInStream( IDataObject* pIDataObject, LPSTREAM* ppStream ) +{ + OSL_ASSERT( NULL != pIDataObject ); + OSL_ASSERT( NULL != ppStream ); + + return CoMarshalInterThreadInterfaceInStream( + __uuidof(IDataObject), //The IID of inteface to be marshaled + pIDataObject, //The interface pointer + ppStream //IStream pointer + ); +} + +//-------------------------------------------------------------------- +// unmarshal an IDataObject +//-------------------------------------------------------------------- + +inline +HRESULT UnmarshalIDataObjectAndReleaseStream( LPSTREAM lpStream, IDataObject** ppIDataObject ) +{ + OSL_ASSERT( NULL != lpStream ); + OSL_ASSERT( NULL != ppIDataObject ); + + return CoGetInterfaceAndReleaseStream( + lpStream, + __uuidof(IDataObject), + reinterpret_cast<LPVOID*>(ppIDataObject)); +} + +//-------------------------------------------------------------------- +// helper class to ensure that the calling thread has com initialized +//-------------------------------------------------------------------- + +class CAutoComInit +{ +public: + CAutoComInit( ) + { + CoInitialize( NULL ); + } + + ~CAutoComInit( ) + { + CoUninitialize( ); + } +}; + +//-------------------------------------------------------------------- +// ctor +//-------------------------------------------------------------------- + +CMtaOleClipboard::CMtaOleClipboard( ) : + m_hOleThread( NULL ), + m_uOleThreadId( 0 ), + m_hEvtThrdReady( NULL ), + m_hEvtOpComplete( NULL ), + m_hEvtWmDrawClipboardReady( NULL ), + m_hwndMtaOleReqWnd( NULL ), + m_hwndNextClipViewer( NULL ), + m_pfncClipViewerCallback( NULL ), + m_bInFlushClipboard( sal_False ) +{ + // signals that the thread was successfully set up + m_hEvtThrdReady = CreateEvent( 0, MANUAL_RESET, INIT_NONSIGNALED, NULL ); + m_hEvtOpComplete = CreateEvent( 0, AUTO_RESET, INIT_NONSIGNALED, NULL ); + m_hEvtWmDrawClipboardReady = CreateEvent( 0, AUTO_RESET, INIT_NONSIGNALED, NULL ); + OSL_ASSERT( (NULL != m_hEvtThrdReady) && + (NULL != m_hEvtOpComplete) && + (NULL != m_hEvtWmDrawClipboardReady) ); + + s_theMtaOleClipboardInst = this; + + m_hOleThread = (HANDLE)_beginthreadex( + NULL, 0, CMtaOleClipboard::oleThreadProc, this, 0, &m_uOleThreadId ); + OSL_ASSERT( NULL != m_hOleThread ); +} + +//-------------------------------------------------------------------- +// dtor +//-------------------------------------------------------------------- + +CMtaOleClipboard::~CMtaOleClipboard( ) +{ + // block calling threads out + if ( NULL != m_hEvtThrdReady ) + ResetEvent( m_hEvtThrdReady ); + + // end the thread + // because DestroyWindow can only be called + // from within the thread that created the window + sendMessage( MSG_SHUTDOWN, + static_cast< WPARAM >( 0 ), + static_cast< LPARAM >( 0 ) ); + + // wait for thread shutdown + sal_uInt32 dwResult = + WaitForSingleObject( m_hOleThread, MAX_WAIT_SHUTDOWN ); + OSL_ENSURE( dwResult == WAIT_OBJECT_0, "OleThread could not terminate" ); + + if ( NULL != m_hOleThread ) + CloseHandle( m_hOleThread ); + + if ( NULL != m_hEvtThrdReady ) + CloseHandle( m_hEvtThrdReady ); + + if ( NULL != m_hEvtOpComplete ) + CloseHandle( m_hEvtOpComplete ); + + if ( NULL != m_hEvtWmDrawClipboardReady ) + CloseHandle( m_hEvtWmDrawClipboardReady ); + + OSL_ENSURE( ( NULL == m_pfncClipViewerCallback ) && + !IsWindow( m_hwndNextClipViewer ), \ + "Clipboard viewer not properly unregistered" ); +} + + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +HRESULT CMtaOleClipboard::flushClipboard( ) +{ + if ( !WaitForThreadReady( ) ) + return E_FAIL; + + CAutoComInit comAutoInit; + + HRESULT hr; + + m_bInFlushClipboard = sal_True; + + // we don't need to post the request if we are + // the ole thread self + if ( GetCurrentThreadId( ) == m_uOleThreadId ) + OSL_ENSURE( sal_False, "flushClipboard from within the OleThread called" ); + else + { + postMessage( MSG_FLUSHCLIPBOARD, + static_cast< WPARAM >( 0 ), + reinterpret_cast< LPARAM >( &hr ) ); + + // we have to wait a little bit different here + // because if we are not the first in the clipviewer + // chain OleFlushClipboard returns before the + // WM_DRAWCLIPBOARD message will be received, so we + // use another event which will be signaled be the + // WM_DRAWCLIPBOARD handler if we are in a flush + // clipboard operation so the call becomes synchronous + // for the caller + HANDLE hEvt[2]; + hEvt[0] = m_hEvtOpComplete; + hEvt[1] = m_hEvtWmDrawClipboardReady; + + DWORD dwResult = WaitForMultipleObjects( + 2, hEvt, TRUE, MAX_OPCOMPLET_WAITTIME ); + + if ( WAIT_OBJECT_0 != dwResult ) + hr = E_FAIL; + } + + m_bInFlushClipboard = sal_False; + + return hr; +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +HRESULT CMtaOleClipboard::getClipboard( IDataObject** ppIDataObject ) +{ + if ( !WaitForThreadReady( ) ) + return E_FAIL; + + if ( NULL == ppIDataObject ) + return E_INVALIDARG; + + CAutoComInit comAutoInit; + + LPSTREAM lpStream = NULL; + HRESULT hr; + + *ppIDataObject = NULL; + + // we don't need to post the request if we are + // the ole thread self + if ( GetCurrentThreadId( ) == m_uOleThreadId ) + hr = static_cast<HRESULT>( onGetClipboard( &lpStream ) ); + else + { + postMessage( MSG_GETCLIPBOARD, + reinterpret_cast< WPARAM >( &lpStream ), + reinterpret_cast< LPARAM >( &hr ) ); + + if ( !WaitOpComplete( ) ) + hr = E_FAIL; + } + + if ( SUCCEEDED( hr ) ) + hr = UnmarshalIDataObjectAndReleaseStream( lpStream, ppIDataObject ); + + return hr; +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +HRESULT CMtaOleClipboard::setClipboard( IDataObject* pIDataObject ) +{ + if ( !WaitForThreadReady( ) ) + return E_FAIL; + + CAutoComInit comAutoInit; + + HRESULT hr; + + // we don't need to post the request if we are + // the ole thread self + if ( GetCurrentThreadId( ) == m_uOleThreadId ) + OSL_ENSURE( sal_False, "setClipboard from within the OleThread called" ); + else + { + postMessage( MSG_SETCLIPBOARD, + reinterpret_cast< WPARAM >( pIDataObject ), + reinterpret_cast< LPARAM >( &hr ) ); + + if ( !WaitOpComplete( ) ) + hr = E_FAIL; + } + + return hr; +} + +//-------------------------------------------------------------------- +// register a clipboard viewer +//-------------------------------------------------------------------- + +sal_Bool CMtaOleClipboard::registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback ) +{ + if ( !WaitForThreadReady( ) ) + return sal_False; + + sal_Bool bRet = sal_False; + + if ( GetCurrentThreadId( ) == m_uOleThreadId ) + OSL_ENSURE( sal_False, "registerClipViewer from within the OleThread called" ); + else + { + postMessage( MSG_REGCLIPVIEWER, + reinterpret_cast<WPARAM>( pfncClipViewerCallback ), + reinterpret_cast<LPARAM>(&bRet) ); + + if ( !WaitOpComplete( ) ) + bRet = sal_False; + } + + return bRet; +} + +//-------------------------------------------------------------------- +// register a clipboard viewer +//-------------------------------------------------------------------- + +sal_Bool CMtaOleClipboard::onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback ) +{ + if ( !IsWindow( m_hwndMtaOleReqWnd ) ) + return sal_False; + + sal_Bool bRet = sal_True; + + // register if not yet done + if ( ( NULL != pfncClipViewerCallback ) && ( NULL == m_pfncClipViewerCallback ) ) + { + // SetClipboardViewer sends a WM_DRAWCLIPBOARD message we ignore + // this message if we register ourself as clip viewer + m_bInRegisterClipViewer = sal_True; + m_hwndNextClipViewer = SetClipboardViewer( m_hwndMtaOleReqWnd ); + m_bInRegisterClipViewer = sal_False; + + // if there is no other cb-viewer the + // return value is NULL!!! + bRet = IsWindow( m_hwndNextClipViewer ); + + // save the new callback function + m_pfncClipViewerCallback = pfncClipViewerCallback; + } + else if ( ( NULL == pfncClipViewerCallback ) && ( NULL != m_pfncClipViewerCallback ) ) + { + m_pfncClipViewerCallback = NULL; + + // unregister if input parameter is NULL and we previously registered + // as clipboard viewer + ChangeClipboardChain( m_hwndMtaOleReqWnd, m_hwndNextClipViewer ); + m_hwndNextClipViewer = NULL; + } + + return bRet; +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +LRESULT CMtaOleClipboard::onSetClipboard( IDataObject* pIDataObject ) +{ + HRESULT hr = OleSetClipboard( pIDataObject ); + return static_cast<LRESULT>(hr); +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +LRESULT CMtaOleClipboard::onGetClipboard( LPSTREAM* ppStream ) +{ + OSL_ASSERT( NULL != ppStream ); + + IDataObject* pIDataObject; + + // forward the request to the OleClipboard + HRESULT hr = OleGetClipboard( &pIDataObject ); + if ( SUCCEEDED( hr ) ) + hr = MarshalIDataObjectInStream( pIDataObject, ppStream ); + + return static_cast< LRESULT >( hr ); +} + +//-------------------------------------------------------------------- +// flush the ole-clipboard +//-------------------------------------------------------------------- + +LRESULT CMtaOleClipboard::onFlushClipboard( ) +{ + // the call will be block until the + // WM_DRAWCLIPBOARD message has been + // processed + ResetEvent( m_hEvtWmDrawClipboardReady ); + return static_cast<LRESULT>( OleFlushClipboard( ) ); +} + +//-------------------------------------------------------------------- +// handle clipboard chain change event +//-------------------------------------------------------------------- + +LRESULT CMtaOleClipboard::onChangeCBChain( HWND hWndRemove, HWND hWndNext ) +{ + if ( hWndRemove == m_hwndNextClipViewer ) + m_hwndNextClipViewer = hWndNext; + else if ( IsWindow( m_hwndNextClipViewer ) ) + { + // forward the message to the next one + DWORD dwResult; + SendMessageTimeoutA( + m_hwndNextClipViewer, + WM_CHANGECBCHAIN, + reinterpret_cast<WPARAM>(hWndRemove), + reinterpret_cast<LPARAM>(hWndNext), + SMTO_BLOCK, + MAX_CLIPEVENT_PROCESSING_TIME, + &dwResult ); + } + + return 0; +} + +//-------------------------------------------------------------------- +// handle draw clipboard event +//-------------------------------------------------------------------- + +LRESULT CMtaOleClipboard::onDrawClipboard( ) +{ + // we don't send a notification if we are + // registering ourself as clipboard + if ( !m_bInRegisterClipViewer ) + { + if ( NULL != m_pfncClipViewerCallback ) + m_pfncClipViewerCallback( ); + } + + // foward the message to the next viewer in the chain + if ( IsWindow( m_hwndNextClipViewer ) ) + { + DWORD dwResult; + SendMessageTimeoutA( + m_hwndNextClipViewer, + WM_DRAWCLIPBOARD, + static_cast< WPARAM >( 0 ), + static_cast< LPARAM >( 0 ), + SMTO_BLOCK, + MAX_CLIPEVENT_PROCESSING_TIME, + &dwResult ); + } + + if ( m_bInFlushClipboard ) + SetEvent( m_hEvtWmDrawClipboardReady ); + + return 0; +} + +//-------------------------------------------------------------------- +// SendMessage so we don't need to supply the HWND if we send +// something to our wrapped window +//-------------------------------------------------------------------- + +LRESULT CMtaOleClipboard::sendMessage( UINT msg, WPARAM wParam, LPARAM lParam ) +{ + return ::SendMessageA( m_hwndMtaOleReqWnd, msg, wParam, lParam ); +} + +//-------------------------------------------------------------------- +// PostMessage so we don't need to supply the HWND if we send +// something to our wrapped window +//-------------------------------------------------------------------- + +sal_Bool CMtaOleClipboard::postMessage( UINT msg, WPARAM wParam, LPARAM lParam ) +{ + return PostMessageA( m_hwndMtaOleReqWnd, msg, wParam, lParam ); +} + + +//-------------------------------------------------------------------- +// the window proc +//-------------------------------------------------------------------- + +LRESULT CALLBACK CMtaOleClipboard::mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) +{ + LRESULT lResult = 0; + + // get a connection to the class-instance via the static member + CMtaOleClipboard* pImpl = CMtaOleClipboard::s_theMtaOleClipboardInst; + OSL_ASSERT( NULL != pImpl ); + + switch( uMsg ) + { + case MSG_SETCLIPBOARD: + *(reinterpret_cast< HRESULT* >( lParam )) = + pImpl->onSetClipboard( reinterpret_cast< IDataObject* >(wParam) ); + SetEvent( pImpl->m_hEvtOpComplete ); + break; + + case MSG_GETCLIPBOARD: + *(reinterpret_cast< HRESULT* >( lParam )) = + pImpl->onGetClipboard( reinterpret_cast< LPSTREAM* >(wParam) ); + SetEvent( pImpl->m_hEvtOpComplete ); + break; + + case MSG_FLUSHCLIPBOARD: + *(reinterpret_cast< HRESULT* >( lParam )) = pImpl->onFlushClipboard( ); + SetEvent( pImpl->m_hEvtOpComplete ); + break; + + case MSG_REGCLIPVIEWER: + *(reinterpret_cast<sal_Bool*>(lParam)) = pImpl->onRegisterClipViewer( + reinterpret_cast<LPFNC_CLIPVIEWER_CALLBACK_t>(wParam) ); + SetEvent( pImpl->m_hEvtOpComplete ); + break; + + case WM_CHANGECBCHAIN: + lResult = pImpl->onChangeCBChain( + reinterpret_cast< HWND >( wParam ), reinterpret_cast< HWND >( lParam ) ); + break; + + case WM_DRAWCLIPBOARD: + lResult = pImpl->onDrawClipboard( ); + break; + + case MSG_SHUTDOWN: + DestroyWindow( pImpl->m_hwndMtaOleReqWnd ); + break; + + case WM_DESTROY: + PostQuitMessage( 0 ); + break; + + default: + return DefWindowProc( hWnd, uMsg, wParam, lParam ); + } + + return lResult; +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +void CMtaOleClipboard::createMtaOleReqWnd( ) +{ + WNDCLASSEXW wcex; + sal_Unicode szWndClsName[] = HIDDEN_CB_WNDCLS_NAME; + + HINSTANCE hInst = GetModuleHandleA( CLIPSERVICE_DLL_NAME ); + OSL_ENSURE( NULL != hInst, "The name of the clipboard service dll must have changed" ); + + ZeroMemory( &wcex, sizeof( WNDCLASSEX ) ); + + wcex.cbSize = sizeof( WNDCLASSEX ); + wcex.lpfnWndProc = static_cast< WNDPROC >( CMtaOleClipboard::mtaOleReqWndProc ); + wcex.hInstance = hInst; + wcex.lpszClassName = szWndClsName; + + ATOM atom = RegisterClassExW( &wcex ); + if ( 0 != atom ) + m_hwndMtaOleReqWnd = CreateWindowExW( + 0, szWndClsName, TEXT(""), 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL ); +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +unsigned int CMtaOleClipboard::run( ) +{ + HRESULT hr = OleInitialize( NULL ); + OSL_ASSERT( SUCCEEDED( hr ) ); + + createMtaOleReqWnd( ); + + unsigned int nRet; + + if ( IsWindow( m_hwndMtaOleReqWnd ) ) + { + if ( NULL != m_hEvtThrdReady ) + SetEvent( m_hEvtThrdReady ); + + // pumping messages + MSG msg; + while( GetMessage( &msg, NULL, 0, 0 ) ) + DispatchMessage( &msg ); + + nRet = 0; + } + else + nRet = -1; + + OleUninitialize( ); + + return nRet; +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +unsigned int WINAPI CMtaOleClipboard::oleThreadProc( LPVOID pParam ) +{ + CMtaOleClipboard* pInst = + reinterpret_cast<CMtaOleClipboard*>( pParam ); + OSL_ASSERT( NULL != pInst ); + + return pInst->run( ); +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +sal_Bool CMtaOleClipboard::WaitForThreadReady( ) const +{ + sal_Bool bRet = sal_False; + + if ( NULL != m_hEvtThrdReady ) + { + DWORD dwResult = WaitForSingleObject( + m_hEvtThrdReady, MAX_WAITTIME ); + bRet = ( dwResult == WAIT_OBJECT_0 ); + } + + return bRet; +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +sal_Bool CMtaOleClipboard::WaitOpComplete( ) const +{ + sal_Bool bRet = sal_False; + + if ( NULL != m_hEvtOpComplete ) + { + DWORD dwResult = WaitForSingleObject( + m_hEvtOpComplete, MAX_OPCOMPLET_WAITTIME ); + bRet = ( dwResult == WAIT_OBJECT_0 ); + } + + return bRet; +}
\ No newline at end of file diff --git a/dtrans/source/win32/mtaole/makefile.mk b/dtrans/source/win32/mtaole/makefile.mk new file mode 100644 index 000000000000..0c426414923c --- /dev/null +++ b/dtrans/source/win32/mtaole/makefile.mk @@ -0,0 +1,85 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: tra $ $Date: 2001-03-14 14:46:33 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc.. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJNAME=dtrans +TARGET=mtaolecb +LIBTARGET=NO + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Targets ---------------------------------- + +.IF "$(GUI)"=="WNT" + +# --- static lib -------------------------- + +SLOFILES=$(SLO)$/MtaOleClipb.obj + +LIB1TARGET=$(SLB)$/$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +.ENDIF + +.INCLUDE : target.mk diff --git a/dtrans/source/win32/workbench/makefile.mk b/dtrans/source/win32/workbench/makefile.mk index 93cb266c415f..b587c6bf7ae0 100644 --- a/dtrans/source/win32/workbench/makefile.mk +++ b/dtrans/source/win32/workbench/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: mh $ $Date: 2001-01-31 15:37:21 $ +# last change: $Author: tra $ $Date: 2001-03-14 14:54:51 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -90,8 +90,8 @@ CFLAGS+=/D_WIN32_DCOM /EHsc OBJFILES= $(OBJ)$/test_wincb.obj APP1TARGET= $(TARGET) -APP1OBJS= $(OBJ)$/test_wincb.obj\ - $(OBJ)$/ImplHelper.obj +APP1OBJS= $(OBJ)$/test_wincb.obj + APP1STDLIBS= $(SALLIB) \ $(CPPULIB) \ @@ -99,7 +99,7 @@ APP1STDLIBS= $(SALLIB) \ user32.lib \ ole32.lib -APP1LIBS= $(LB)$/dtutils.lib\ +APP1LIBS= $(SLB)$/dtutils.lib\ $(SOLARLIBDIR)$/user9x.lib\ $(SOLARLIBDIR)$/tools32.lib diff --git a/dtrans/source/win32/workbench/test_wincb.cxx b/dtrans/source/win32/workbench/test_wincb.cxx index c0bc094d997b..47e4be15617b 100644 --- a/dtrans/source/win32/workbench/test_wincb.cxx +++ b/dtrans/source/win32/workbench/test_wincb.cxx @@ -2,9 +2,9 @@ * * $RCSfile: test_wincb.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: armin $ $Date: 2001-03-08 12:11:56 $ + * last change: $Author: tra $ $Date: 2001-03-14 14:54:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,7 +65,7 @@ //_________________________________________________________________________________________________________________________ -#include "..\ImplHelper.hxx" +#include "..\misc\ImplHelper.hxx" //_________________________________________________________________________________________________________________________ // other includes @@ -91,11 +91,19 @@ #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp> #endif +#ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XFLUSHABLECLIPBOARD_HPP_ +#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> +#endif + #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ #include <com/sun/star/lang/XComponent.hpp> #endif #ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ #include <cppuhelper/implbase2.hxx> #endif @@ -115,7 +123,7 @@ #include <windows.h> #include <objbase.h> -#include <memory> +#include <stl/memory> #include <process.h> @@ -124,7 +132,7 @@ //------------------------------------------------------------- #define TEST_CLIPBOARD -#define RDB_SYSPATH "d:\\projects\\src616\\dtrans\\wntmsci7\\bin\\applicat.rdb" +#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 @@ -155,6 +163,37 @@ HANDLE g_hEvtThreadWakeup; // //------------------------------------------------------------ +class CClipboardListener : public WeakImplHelper1 < 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 WeakImplHelper2< XClipboardOwner, XTransferable > { public: @@ -164,18 +203,22 @@ public: // XTransferable //------------------------------------------------- - virtual Any SAL_CALL getTransferData( const DataFlavor& aFlavor ) throw(UnsupportedFlavorException, IOException, RuntimeException); + 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); + virtual void SAL_CALL lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) + throw(RuntimeException); private: - Sequence< DataFlavor > m_seqDFlv; + Sequence< DataFlavor > m_FlavorList; OUString m_Data; }; @@ -184,23 +227,15 @@ private: //---------------------------------------------------------------- CTransferable::CTransferable( ) : - m_seqDFlv( 1 ), - m_Data( L"Ich habe mir ein neues Fahrrad gekauft!" ) + m_FlavorList( 1 ), + m_Data( OUString::createFromAscii( "Ich habe mir ein neues Fahrrad gekauft!" ) ) { DataFlavor df; - /* - df.MimeType = L"text/plain; charset=unicode"; + df.MimeType = L"text/plain;charset=utf-16"; df.DataType = getCppuType( ( OUString* )0 ); - m_seqDFlv[0] = df; - */ - - //df.MimeType = L"text/plain; charset=windows1252"; - df.MimeType = L"text/html"; - df.DataType = getCppuType( ( Sequence< sal_Int8 >* )0 ); - - m_seqDFlv[0] = df; + m_FlavorList[0] = df; } //---------------------------------------------------------------- @@ -212,21 +247,8 @@ Any SAL_CALL CTransferable::getTransferData( const DataFlavor& aFlavor ) { Any anyData; - /*if ( aFlavor == m_seqDFlv[0] ) - { + if ( aFlavor.MimeType == m_FlavorList[0].MimeType ) anyData = makeAny( m_Data ); - } - else*/ if ( aFlavor == m_seqDFlv[0] ) - { - OString aStr( m_Data.getStr( ), m_Data.getLength( ), 1252 ); - Sequence< sal_Int8 > sOfChars( aStr.getLength( ) ); - sal_Int32 lenStr = aStr.getLength( ); - - for ( sal_Int32 i = 0; i < lenStr; ++i ) - sOfChars[i] = aStr[i]; - - anyData = makeAny( sOfChars ); - } return anyData; } @@ -238,7 +260,7 @@ Any SAL_CALL CTransferable::getTransferData( const DataFlavor& aFlavor ) Sequence< DataFlavor > SAL_CALL CTransferable::getTransferDataFlavors( ) throw(RuntimeException) { - return m_seqDFlv; + return m_FlavorList; } //---------------------------------------------------------------- @@ -248,73 +270,26 @@ Sequence< DataFlavor > SAL_CALL CTransferable::getTransferDataFlavors( ) sal_Bool SAL_CALL CTransferable::isDataFlavorSupported( const DataFlavor& aFlavor ) throw(RuntimeException) { - sal_Int32 nLength = m_seqDFlv.getLength( ); - sal_Bool bRet = sal_False; + sal_Int32 nLength = m_FlavorList.getLength( ); for ( sal_Int32 i = 0; i < nLength; ++i ) - { - if ( m_seqDFlv[i] == aFlavor ) - { - bRet = sal_True; - break; - } - } + if ( m_FlavorList[i].MimeType == aFlavor.MimeType ) + return sal_True; - return bRet; + return sal_False; } //---------------------------------------------------------------- // lostOwnership //---------------------------------------------------------------- -void SAL_CALL CTransferable::lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) +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 ); } -//################################################################ -// a thread in another apartment to test apartment transparency - -unsigned int _stdcall ThreadProc(LPVOID pParam) -{ - // setup another apartment - HRESULT hr = CoInitialize( NULL ); - //HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED ); - - WaitForSingleObject( g_hEvtThreadWakeup, INFINITE ); - - Sequence< DataFlavor > flavorList = rXTransfRead->getTransferDataFlavors( ); - sal_Int32 nFlavors = flavorList.getLength( ); - OUString mimeType; - OUString hpName; - for ( sal_Int32 i = 0; i < nFlavors; ++i ) - { - mimeType = flavorList[i].MimeType; - hpName = flavorList[i].HumanPresentableName; - } - - /* - try - { - DataFlavor flv; - flv.MimeType = L"text/html"; - flv.DataType = getCppuType( ( Sequence< sal_Int8 >* )0 ); - - rXTransfRead->getTransferData( flv ); - } - catch( UnsupportedFlavorException& ex ) - { - OSL_ENSURE( false, "### DataFlavor not supported" ); - } - */ - - CoUninitialize( ); - - return 0; -} - -//################################################################ - //---------------------------------------------------------------- // main //---------------------------------------------------------------- @@ -328,25 +303,10 @@ int SAL_CALL main( int nArgc, char* Argv[] ) //HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED ); HRESULT hr = CoInitialize( NULL ); - -#ifndef WRITE_CB - - 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 ); - -#endif - //------------------------------------------------- // get the global service-manager //------------------------------------------------- + OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) ); Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) ); @@ -363,50 +323,33 @@ int SAL_CALL main( int nArgc, char* Argv[] ) Reference< XTransferable > rXTransf( static_cast< XTransferable* >( new CTransferable ) ); - Reference< XClipboard > xClipboard( g_xFactory->createInstance( OUString( WINCLIPBOARD_SERVICE_NAME ) ), UNO_QUERY ); + Reference< XClipboard > + xClipboard( g_xFactory->createInstance( OUString( WINCLIPBOARD_SERVICE_NAME ) ), UNO_QUERY ); if ( !xClipboard.is( ) ) { - OSL_ENSURE( sal_False, "Error creating FolderPicker Service" ); + OSL_ENSURE( sal_False, "Error creating Clipboard Service" ); return(-1); } - Reference< XTypeProvider > rXTypProv( xClipboard, UNO_QUERY ); - - if ( rXTypProv.is( ) ) - { - Sequence< Type > seqType = rXTypProv->getTypes( ); - sal_Int32 nLen = seqType.getLength( ); - for ( sal_Int32 i = 0; i < nLen; ++nLen ) - { - Type nxtType = seqType[i]; - } - - Sequence< sal_Int8 > seqInt8 = rXTypProv->getImplementationId( ); - } + Reference< XClipboardNotifier > xClipNotifier( xClipboard, UNO_QUERY ); + Reference< XClipboardListener > rXClipListener( static_cast< XClipboardListener* >( new CClipboardListener() ) ); + xClipNotifier->addClipboardListener( rXClipListener ); -#ifdef WRITE_CB + // set new clipboard content xClipboard->setContents( rXTransf, Reference< XClipboardOwner >( rXTransf, UNO_QUERY ) ); -#else - rXTransfRead = xClipboard->getContents( ); + MessageBox( NULL, TEXT("Stop"), TEXT("INFO"), MB_OK|MB_ICONINFORMATION); - // wakeup the thread and waiting util it ends - SetEvent( g_hEvtThreadWakeup ); + // flush the clipboard content + Reference< XFlushableClipboard > rXFlushableClip( xClipboard, UNO_QUERY ); + rXFlushableClip->flushClipboard( ); + rXFlushableClip = Reference< XFlushableClipboard >( ); - // wait for thread end - WaitForSingleObject( hThread, INFINITE ); - - // destroy the transferable explicitly - rXTransfRead = Reference< XTransferable>( ); - -#endif - - // destroy the clipboard - xClipboard = Reference< XClipboard >( ); - - CoUninitialize( ); + xClipNotifier->removeClipboardListener( rXClipListener ); + rXClipListener = Reference< XClipboardListener >( ); + xClipNotifier = Reference< XClipboardNotifier >( ); //-------------------------------------------------- // shutdown the service manager @@ -420,8 +363,12 @@ int SAL_CALL main( int nArgc, char* Argv[] ) // Dispose and clear factory xComponent->dispose(); + xComponent = Reference< XComponent >( ); + g_xFactory.clear(); g_xFactory = Reference< XMultiServiceFactory >(); + CoUninitialize( ); + return 0; } |