summaryrefslogtreecommitdiff
path: root/dtrans
diff options
context:
space:
mode:
authorTino Rachui <tra@openoffice.org>2001-02-27 06:54:52 +0000
committerTino Rachui <tra@openoffice.org>2001-02-27 06:54:52 +0000
commit26dd65bf7ccda05ee0a0078567837c13064e863c (patch)
tree1694bd6fc6997fcdfca612f2e27b5f3d00102390 /dtrans
parent0755f9d4efdfd04f2ce414bb422dba33f27df296 (diff)
*** empty log message ***
Diffstat (limited to 'dtrans')
-rw-r--r--dtrans/source/win32/dtobj/APNDataObject.cxx521
-rw-r--r--dtrans/source/win32/dtobj/APNDataObject.hxx127
-rw-r--r--dtrans/source/win32/dtobj/DOTransferable.cxx380
-rw-r--r--dtrans/source/win32/dtobj/DOTransferable.hxx142
-rw-r--r--dtrans/source/win32/dtobj/DTransHelper.cxx241
-rw-r--r--dtrans/source/win32/dtobj/DTransHelper.hxx238
-rw-r--r--dtrans/source/win32/dtobj/DataFmtTransl.cxx375
-rw-r--r--dtrans/source/win32/dtobj/DataFmtTransl.hxx122
-rw-r--r--dtrans/source/win32/dtobj/DtObjFactory.cxx101
-rw-r--r--dtrans/source/win32/dtobj/FetcList.cxx708
-rw-r--r--dtrans/source/win32/dtobj/FetcList.hxx235
-rw-r--r--dtrans/source/win32/dtobj/FmtFilter.cxx217
-rw-r--r--dtrans/source/win32/dtobj/FmtFilter.hxx102
-rw-r--r--dtrans/source/win32/dtobj/MimeAttrib.hxx86
-rw-r--r--dtrans/source/win32/dtobj/TxtCnvtHlp.cxx222
-rw-r--r--dtrans/source/win32/dtobj/TxtCnvtHlp.hxx94
-rw-r--r--dtrans/source/win32/dtobj/XTDataObject.cxx705
-rw-r--r--dtrans/source/win32/dtobj/XTDataObject.hxx210
-rw-r--r--dtrans/source/win32/dtobj/makefile.mk95
19 files changed, 4921 insertions, 0 deletions
diff --git a/dtrans/source/win32/dtobj/APNDataObject.cxx b/dtrans/source/win32/dtobj/APNDataObject.cxx
new file mode 100644
index 000000000000..154339d581cd
--- /dev/null
+++ b/dtrans/source/win32/dtobj/APNDataObject.cxx
@@ -0,0 +1,521 @@
+/*************************************************************************
+ *
+ * $RCSfile: APNDataObject.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:50:05 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _APNDATAOBJECT_HXX_
+#include "APNDataObject.hxx"
+#endif
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+//------------------------------------------------------------------------
+// defines
+//------------------------------------------------------------------------
+
+#define FREE_HGLOB_ON_RELEASE TRUE
+#define KEEP_HGLOB_ON_RELEASE FALSE
+
+//------------------------------------------------------------------------
+// ctor
+//------------------------------------------------------------------------
+
+CAPNDataObject::CAPNDataObject( IDataObjectPtr rIDataObject ) :
+ m_rIDataObjectOrg( rIDataObject ),
+ m_hGlobal( NULL ),
+ m_nRefCnt( 0 )
+{
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ // we marshal the IDataObject interface pointer here so
+ // that it can be unmarshaled multiple times when this
+ // class will be used from another apartment
+ IStream* pStm = NULL;
+ HRESULT hr = CreateStreamOnHGlobal( 0,
+ KEEP_HGLOB_ON_RELEASE,
+ &pStm );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = CoMarshalInterface( pStm,
+ __uuidof( IDataObject ),
+ m_rIDataObjectOrg,
+ MSHCTX_LOCAL,
+ NULL,
+ MSHLFLAGS_TABLEWEAK );
+ if ( SUCCEEDED( hr ) )
+ hr = GetHGlobalFromStream( pStm, &m_hGlobal );
+
+ pStm->Release( );
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+// dtor
+//------------------------------------------------------------------------
+
+CAPNDataObject::~CAPNDataObject( )
+{
+ if ( NULL != m_hGlobal )
+ {
+ IStream* pStm = NULL;
+ HRESULT hr = CreateStreamOnHGlobal( m_hGlobal,
+ FREE_HGLOB_ON_RELEASE,
+ &pStm );
+ hr = CoReleaseMarshalData( pStm );
+ OSL_ASSERT( SUCCEEDED( hr ) );
+
+ pStm->Release( );
+ }
+}
+
+//------------------------------------------------------------------------
+// IUnknown->QueryInterface
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::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) CAPNDataObject::AddRef( )
+{
+ return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) );
+}
+
+//------------------------------------------------------------------------
+// IUnknown->Release
+//------------------------------------------------------------------------
+
+STDMETHODIMP_(ULONG) CAPNDataObject::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
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->GetData( pFormatetc, pmedium );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->GetData( pFormatetc, pmedium );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->EnumFormatEtc
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->EnumFormatEtc( dwDirection, ppenumFormatetc );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->EnumFormatEtc( dwDirection, ppenumFormatetc );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->QueryGetData
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::QueryGetData( LPFORMATETC pFormatetc )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->QueryGetData( pFormatetc );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->QueryGetData( pFormatetc );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->GetDataHere
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::GetDataHere( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->GetDataHere( pFormatetc, pmedium );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->GetDataHere( pFormatetc, pmedium );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->GetCanonicalFormatEtc
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::GetCanonicalFormatEtc( LPFORMATETC pFormatectIn, LPFORMATETC pFormatetcOut )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->GetCanonicalFormatEtc( pFormatectIn, pFormatetcOut );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->GetCanonicalFormatEtc( pFormatectIn, pFormatetcOut );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->SetData
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::SetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium, BOOL fRelease )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->SetData( pFormatetc, pmedium, fRelease );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->SetData( pFormatetc, pmedium, fRelease );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->DAdvise
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::DAdvise( LPFORMATETC pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD * pdwConnection )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->DAdvise( pFormatetc, advf, pAdvSink, pdwConnection );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->DAdvise( pFormatetc, advf, pAdvSink, pdwConnection );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->DUnadvise
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::DUnadvise( DWORD dwConnection )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->DUnadvise( dwConnection );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->DUnadvise( dwConnection );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->EnumDAdvise
+//------------------------------------------------------------------------
+
+STDMETHODIMP CAPNDataObject::EnumDAdvise( LPENUMSTATDATA * ppenumAdvise )
+{
+ HRESULT hr = E_FAIL;
+
+ try
+ {
+ if ( NULL != m_rIDataObjectOrg )
+ {
+ hr = m_rIDataObjectOrg->EnumDAdvise( ppenumAdvise );
+ if ( RPC_E_WRONG_THREAD == hr )
+ {
+ IDataObject* pIDOTmp;
+
+ hr = MarshalIDataObjectIntoCurrentApartment( &pIDOTmp );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = pIDOTmp->EnumDAdvise( ppenumAdvise );
+ pIDOTmp->Release( );
+ }
+ }
+ }
+ }
+ catch( _com_error& ex )
+ {
+ return ex.Error( );
+ }
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// for our convenience
+//------------------------------------------------------------------------
+
+CAPNDataObject::operator IDataObject*( )
+{
+ return static_cast< IDataObject* >( this );
+}
+
+//------------------------------------------------------------------------
+// helper function
+//------------------------------------------------------------------------
+
+HRESULT CAPNDataObject::MarshalIDataObjectIntoCurrentApartment( IDataObject** ppIDataObj )
+{
+ OSL_ASSERT( NULL != m_hGlobal );
+ OSL_ASSERT( NULL != ppIDataObj );
+
+ IStream* pStm;
+ HRESULT hr = CreateStreamOnHGlobal( m_hGlobal,
+ KEEP_HGLOB_ON_RELEASE,
+ &pStm );
+ if ( SUCCEEDED( hr ) )
+ {
+ hr = CoUnmarshalInterface( pStm, __uuidof( IDataObject ), (void**)ppIDataObj );
+ if ( FAILED( hr ) )
+ *ppIDataObj = NULL;
+
+ pStm->Release( );
+ }
+
+ return hr;
+}
diff --git a/dtrans/source/win32/dtobj/APNDataObject.hxx b/dtrans/source/win32/dtobj/APNDataObject.hxx
new file mode 100644
index 000000000000..c65e7cbddf93
--- /dev/null
+++ b/dtrans/source/win32/dtobj/APNDataObject.hxx
@@ -0,0 +1,127 @@
+/*************************************************************************
+ *
+ * $RCSfile: APNDataObject.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:49:58 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _APNDATAOBJECT_HXX_
+#define _APNDATAOBJECT_HXX_
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#include <comdef.h>
+
+//------------------------------------------------------------------------
+// deklarations
+//------------------------------------------------------------------------
+
+/*
+ an APartment Neutral dataobject wrapper; this wrapper of a IDataObject
+ pointer can be used from any apartment without RPC_E_WRONG_THREAD
+ which normally occurs if an apartment tries to use an interface
+ pointer of another apartment; we use containment to hold the original
+ DataObject
+*/
+class CAPNDataObject : public IDataObject
+{
+public:
+ CAPNDataObject( IDataObjectPtr rIDataObject );
+ ~CAPNDataObject( );
+
+ //-----------------------------------------------------------------
+ //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:
+ HRESULT MarshalIDataObjectIntoCurrentApartment( IDataObject** ppIDataObj );
+
+private:
+ IDataObjectPtr m_rIDataObjectOrg;
+ HGLOBAL m_hGlobal;
+ LONG m_nRefCnt;
+
+// prevent copy and assignment
+private:
+ CAPNDataObject( const CAPNDataObject& theOther );
+ CAPNDataObject& operator=( const CAPNDataObject& theOther );
+};
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/DOTransferable.cxx b/dtrans/source/win32/dtobj/DOTransferable.cxx
new file mode 100644
index 000000000000..82bac927821c
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DOTransferable.cxx
@@ -0,0 +1,380 @@
+/*************************************************************************
+ *
+ * $RCSfile: DOTransferable.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:54:17 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _SAL_TYPES_H_
+#include <sal/types.h>
+#endif
+
+#ifndef _DOWRAPPERTRANSFERABLE_HXX_
+#include "DOTransferable.hxx"
+#endif
+
+#ifndef _IMPLHELPER_HXX_
+#include "..\misc\ImplHelper.hxx"
+#endif
+
+#ifndef _WINCLIP_HXX_
+#include "..\misc\WinClip.hxx"
+#endif
+
+#ifndef _DTRANSHELPER_HXX_
+#include "DTransHelper.hxx"
+#endif
+
+#ifndef _RTL_TENCINFO_H
+#include <rtl/tencinfo.h>
+#endif
+
+#ifndef _MIMEATTRIB_HXX_
+#include "MimeAttrib.hxx"
+#endif
+
+#ifndef _FMTFILTER_HXX_
+#include "FmtFilter.hxx"
+#endif
+
+#include <olestd.h>
+
+#define STR2(x) #x
+#define STR(x) STR2(x)
+#define PRAGMA_MSG( msg ) message( __FILE__ "(" STR(__LINE__) "): " #msg )
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using namespace rtl;
+using namespace std;
+using namespace osl;
+using namespace cppu;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::datatransfer;
+using namespace com::sun::star::io;
+using namespace com::sun::star::lang;
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+const Type CPPUTYPE_OUSTRING = getCppuType( (OUString*)0 );
+
+//------------------------------------------------------------------------
+// ctor
+//------------------------------------------------------------------------
+
+CDOTransferable::CDOTransferable( const Reference< XMultiServiceFactory >& ServiceManager, IDataObjectPtr rDataObject ) :
+ m_rDataObject( rDataObject ),
+ m_bFlavorListInitialized( sal_False ),
+ m_SrvMgr( ServiceManager ),
+ m_DataFormatTranslator( m_SrvMgr )
+{
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+Any SAL_CALL CDOTransferable::getTransferData( const DataFlavor& aFlavor )
+ throw( UnsupportedFlavorException, IOException, RuntimeException )
+{
+ initFlavorList( );
+
+ FORMATETC fetc = dataFlavorToFormatEtc( aFlavor );
+ OSL_ASSERT( CF_INVALID != fetc.cfFormat );
+
+ ByteSequence_t clipDataStream = getClipboardData( fetc );
+
+ // format conversion if necessary
+ if ( CF_DIB == fetc.cfFormat )
+ clipDataStream = WinDIBToOOBMP( clipDataStream );
+ else if ( CF_METAFILEPICT == fetc.cfFormat )
+ clipDataStream = WinMFPictToOOMFPict( clipDataStream );
+
+ return byteStreamToAny( clipDataStream, aFlavor.DataType );
+}
+
+//------------------------------------------------------------------------
+// getTransferDataFlavors
+//------------------------------------------------------------------------
+
+Sequence< DataFlavor > SAL_CALL CDOTransferable::getTransferDataFlavors( )
+ throw( RuntimeException )
+{
+ initFlavorList( );
+ return m_FlavorList;
+}
+
+//------------------------------------------------------------------------
+// isDataFlavorSupported
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CDOTransferable::isDataFlavorSupported( const DataFlavor& aFlavor )
+ throw( RuntimeException )
+{
+ initFlavorList( );
+
+ for ( sal_Int32 i = 0; i < m_FlavorList.getLength( ); i++ )
+ if ( aFlavor == m_FlavorList[i] )
+ return sal_True;
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+// helper function
+// the list of datafalvors currently on the clipboard will be initialized
+// only once; if the client of this Transferable will hold a reference
+// to it und the underlying clipboard content changes, the client does
+// possible operate on a invalid list
+//------------------------------------------------------------------------
+
+void SAL_CALL CDOTransferable::initFlavorList( )
+{
+ // using double checked locking
+ if ( m_bFlavorListInitialized )
+ return;
+
+ MutexGuard aGuard( m_aMutex );
+
+ if ( !m_bFlavorListInitialized )
+ {
+ IEnumFORMATETCPtr pEnumFormatEtc;
+ HRESULT hr = m_rDataObject->EnumFormatEtc( DATADIR_GET, &pEnumFormatEtc );
+ if ( SUCCEEDED( hr ) )
+ {
+ pEnumFormatEtc->Reset( );
+
+ FORMATETC fetc;
+ while ( S_FALSE != pEnumFormatEtc->Next( 1, &fetc, NULL ) )
+ {
+ // we use locales only to determine the
+ // charset if there is text on the cliboard
+ // we don't offer this format
+ if ( CF_LOCALE == fetc.cfFormat )
+ continue;
+
+ DataFlavor aFlavor = formatEtcToDataFlavor( fetc );
+
+ addSupportedFlavor( aFlavor );
+
+ // see MSDN IEnumFORMATETC
+ if ( fetc.ptd )
+ CoTaskMemFree( fetc.ptd );
+ }
+
+ m_bFlavorListInitialized = sal_True;
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+void SAL_CALL CDOTransferable::addSupportedFlavor( const DataFlavor& aFlavor )
+{
+ // we irgnore all formats that can't be translated
+ if ( aFlavor.MimeType.getLength( ) )
+ {
+ m_FlavorList.realloc( m_FlavorList.getLength( ) + 1 );
+ m_FlavorList[m_FlavorList.getLength( ) - 1] = aFlavor;
+ }
+}
+
+//------------------------------------------------------------------------
+// helper function
+//------------------------------------------------------------------------
+
+inline
+FORMATETC SAL_CALL CDOTransferable::dataFlavorToFormatEtc( const DataFlavor& aFlavor ) const
+{
+ return m_DataFormatTranslator.getFormatEtcFromDataFlavor( aFlavor );
+}
+
+//------------------------------------------------------------------------
+// helper function
+//------------------------------------------------------------------------
+
+inline
+DataFlavor SAL_CALL CDOTransferable::formatEtcToDataFlavor( const FORMATETC& aFormatEtc )
+{
+ return m_DataFormatTranslator.getDataFlavorFromFormatEtc( this, aFormatEtc );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CDOTransferable::ByteSequence_t CDOTransferable::getClipboardData( const FORMATETC& aFormatEtc )
+{
+ STGMEDIUM stgmedium;
+ HRESULT hr = m_rDataObject->GetData( &const_cast< FORMATETC& >( aFormatEtc ), &stgmedium );
+
+ if ( FAILED( hr ) )
+ {
+ /*
+ i think it's not necessary to call ReleaseStgMedium
+ in case of failures because nothing should have been
+ allocated etc.
+ */
+ OSL_ASSERT( (hr != E_INVALIDARG) || (hr != DV_E_DVASPECT) );
+
+ if ( DV_E_FORMATETC == hr )
+ throw UnsupportedFlavorException( );
+ else
+ throw RuntimeException( );
+ }
+
+ ByteSequence_t byteStream;
+ sal_Bool bSuccess = clipDataToByteStream( stgmedium, byteStream );
+ if ( !bSuccess )
+ {
+ ReleaseStgMedium( &stgmedium );
+ throw RuntimeException( );
+ }
+
+ ReleaseStgMedium( &stgmedium );
+
+ return byteStream;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool CDOTransferable::clipDataToByteStream( STGMEDIUM stgmedium, ByteSequence_t& aByteSequence )
+{
+ CStgTransferHelper memTransferHelper;
+
+ switch( stgmedium.tymed )
+ {
+ case TYMED_HGLOBAL:
+ memTransferHelper.init( stgmedium.hGlobal );
+ break;
+
+ case TYMED_MFPICT:
+ memTransferHelper.init( stgmedium.hMetaFilePict );
+ break;
+
+ case TYMED_ENHMF:
+ memTransferHelper.init( stgmedium.hEnhMetaFile );
+ break;
+
+ case TYMED_ISTREAM:
+ #pragma PRAGMA_MSG( Has to be implemented )
+ break;
+
+ default:
+ OSL_ENSURE( sal_False, "Unsupported tymed" );
+ return sal_False;
+ }
+
+ int nMemSize = memTransferHelper.memSize( );
+ aByteSequence.realloc( nMemSize );
+
+ return memTransferHelper.read( aByteSequence.getArray( ), nMemSize );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+Any CDOTransferable::byteStreamToAny( ByteSequence_t& aByteStream, const Type& aRequestedDataType )
+{
+ Any aAny;
+
+ if ( aRequestedDataType == CPPUTYPE_OUSTRING )
+ {
+ OUString str = byteStreamToOUString( aByteStream );
+ aAny = makeAny( str );
+ }
+ else
+ aAny = makeAny( aByteStream );
+
+ return aAny;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+OUString CDOTransferable::byteStreamToOUString( ByteSequence_t& aByteStream )
+{
+ sal_Int32 nWChars;
+ sal_Int32 nMemSize = aByteStream.getLength( );
+
+ // if there is a trailing L"\0" substract 1 from length
+ if ( 0 == aByteStream[ aByteStream.getLength( ) - 2 ] &&
+ 0 == aByteStream[ aByteStream.getLength( ) - 1 ] )
+ nWChars = static_cast< sal_Int32 >( nMemSize / sizeof( sal_Unicode ) ) - 1;
+ else
+ nWChars = static_cast< sal_Int32 >( nMemSize / sizeof( sal_Unicode ) );
+
+ return OUString( reinterpret_cast< sal_Unicode* >( aByteStream.getArray( ) ), nWChars );
+}
+
diff --git a/dtrans/source/win32/dtobj/DOTransferable.hxx b/dtrans/source/win32/dtobj/DOTransferable.hxx
new file mode 100644
index 000000000000..d9e0135e3c3a
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DOTransferable.hxx
@@ -0,0 +1,142 @@
+/*************************************************************************
+ *
+ * $RCSfile: DOTransferable.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:54:25 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _DOTRANSFERABLE_HXX_
+#define _DOTRANSFERABLE_HXX_
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE1_HXX_
+#include <cppuhelper/implbase1.hxx>
+#endif
+
+#ifndef _DATAFMTTRANSL_HXX_
+#include "DataFmtTransl.hxx"
+#endif
+
+#include <comdef.h>
+
+//------------------------------------------------------------------------
+// deklarations
+//------------------------------------------------------------------------
+
+class CDOTransferable : public ::cppu::WeakImplHelper1< ::com::sun::star::datatransfer::XTransferable >
+{
+public:
+ typedef com::sun::star::uno::Sequence< sal_Int8 > ByteSequence_t;
+
+public:
+ // the DataObject should be the one returned by OleGetClipboard!!!
+ explicit CDOTransferable(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ServiceManager,
+ IDataObjectPtr rDataObject );
+
+ //------------------------------------------------------------------------
+ // XTransferable
+ //------------------------------------------------------------------------
+
+ virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
+ throw( ::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
+
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( )
+ throw( ::com::sun::star::uno::RuntimeException );
+
+ virtual sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
+ throw( ::com::sun::star::uno::RuntimeException );
+
+private:
+
+ //------------------------------------------------------------------------
+ // some helper functions
+ //------------------------------------------------------------------------
+
+ void SAL_CALL initFlavorList( );
+ void SAL_CALL addSupportedFlavor( const com::sun::star::datatransfer::DataFlavor& aFlavor );
+ FORMATETC SAL_CALL dataFlavorToFormatEtc( const com::sun::star::datatransfer::DataFlavor& aFlavor ) const;
+ com::sun::star::datatransfer::DataFlavor SAL_CALL formatEtcToDataFlavor( const FORMATETC& aFormatEtc );
+
+ ByteSequence_t SAL_CALL getClipboardData( const FORMATETC& aFormatEtc );
+ sal_Bool SAL_CALL clipDataToByteStream( STGMEDIUM stgmedium, ByteSequence_t& aByteSequence );
+ ::com::sun::star::uno::Any SAL_CALL byteStreamToAny( ByteSequence_t& aByteStream, const com::sun::star::uno::Type& aRequestedDataType );
+ rtl::OUString SAL_CALL byteStreamToOUString( ByteSequence_t& aByteStream );
+
+private:
+ IDataObjectPtr m_rDataObject;
+ com::sun::star::uno::Sequence< com::sun::star::datatransfer::DataFlavor > m_FlavorList;
+ sal_Bool m_bFlavorListInitialized;
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_SrvMgr;
+ CDataFormatTranslator m_DataFormatTranslator;
+ ::osl::Mutex m_aMutex;
+
+// non supported operations
+private:
+ CDOTransferable( const CDOTransferable& );
+ CDOTransferable& operator=( const CDOTransferable& );
+};
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/DTransHelper.cxx b/dtrans/source/win32/dtobj/DTransHelper.cxx
new file mode 100644
index 000000000000..851dbbc7ea82
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DTransHelper.cxx
@@ -0,0 +1,241 @@
+/*************************************************************************
+ *
+ * $RCSfile: DTransHelper.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:50:29 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#ifndef _DTRANSHELPER_HXX_
+#include "DTransHelper.hxx"
+#endif
+
+//------------------------------------------------------------------------
+// implementation
+//------------------------------------------------------------------------
+
+CStgTransferHelper::CStgTransferHelper( sal_Bool bAutoInit,
+ HGLOBAL hGlob,
+ sal_Bool bDeleteStorageOnRelease,
+ sal_Bool bReleaseStreamOnDestruction ) :
+ m_lpStream( NULL ),
+ m_bDelStgOnRelease( bDeleteStorageOnRelease ),
+ m_bReleaseStreamOnDestr( bReleaseStreamOnDestruction )
+{
+ OSL_ASSERT( !(bDeleteStorageOnRelease && !bReleaseStreamOnDestruction) );
+
+ if ( bAutoInit )
+ init( hGlob, bDeleteStorageOnRelease );
+}
+
+//------------------------------------------------------------------------
+// dtor
+//------------------------------------------------------------------------
+
+
+CStgTransferHelper::~CStgTransferHelper( )
+{
+ if ( m_bReleaseStreamOnDestr && m_lpStream )
+ m_lpStream->Release( );
+}
+
+//------------------------------------------------------------------------
+// TransferData into the
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CStgTransferHelper::write( const void* lpData, ULONG cb, ULONG* cbWritten )
+{
+ HRESULT hr = E_FAIL;
+
+ if ( m_lpStream )
+ hr = m_lpStream->Write( lpData, cb, cbWritten );
+
+ return SUCCEEDED( hr );
+}
+
+//------------------------------------------------------------------------
+// read
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CStgTransferHelper::read( LPVOID pv, ULONG cb, ULONG* pcbRead )
+{
+ HRESULT hr = E_FAIL;
+
+ if ( m_lpStream )
+ hr = m_lpStream->Read( pv, cb , pcbRead );
+
+ return SUCCEEDED( hr );
+}
+
+//------------------------------------------------------------------------
+// GetHGlobal
+//------------------------------------------------------------------------
+
+HGLOBAL SAL_CALL CStgTransferHelper::getHGlobal( ) const
+{
+ OSL_ASSERT( m_lpStream );
+
+ HGLOBAL hGlob = NULL;
+
+ if ( m_lpStream )
+ {
+ HRESULT hr = GetHGlobalFromStream( m_lpStream, &hGlob );
+ if ( FAILED( hr ) )
+ hGlob = NULL;
+ }
+
+ return hGlob;
+}
+
+//------------------------------------------------------------------------
+// getIStream
+//------------------------------------------------------------------------
+
+void SAL_CALL CStgTransferHelper::getIStream( LPSTREAM* ppStream )
+{
+ OSL_ASSERT( ppStream );
+ *ppStream = m_lpStream;
+}
+
+//------------------------------------------------------------------------
+// Init
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CStgTransferHelper::init( SIZE_T newSize,
+ UINT uiFlags,
+ sal_Bool bDeleteStorageOnRelease,
+ sal_Bool bReleaseStreamOnDestruction )
+{
+ OSL_ASSERT( !(bDeleteStorageOnRelease && !bReleaseStreamOnDestruction) );
+
+ cleanup( );
+ HGLOBAL hGlob = GlobalAlloc( uiFlags, newSize );
+ if ( NULL == hGlob )
+ throw COutOfMemoryException();
+
+ HRESULT hr = CreateStreamOnHGlobal( hGlob, bDeleteStorageOnRelease, &m_lpStream );
+
+ m_bDelStgOnRelease = bDeleteStorageOnRelease;
+ m_bReleaseStreamOnDestr = bReleaseStreamOnDestruction;
+
+ return SUCCEEDED( hr );
+}
+
+//------------------------------------------------------------------------
+// Init
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CStgTransferHelper::init( HGLOBAL hGlob,
+ sal_Bool bDeleteStorageOnRelease,
+ sal_Bool bReleaseStreamOnDestruction )
+{
+ OSL_ASSERT( !(bDeleteStorageOnRelease && !bReleaseStreamOnDestruction) );
+
+ cleanup( );
+ HRESULT hr = CreateStreamOnHGlobal( hGlob, bDeleteStorageOnRelease, &m_lpStream );
+ if ( hr == E_OUTOFMEMORY )
+ throw COutOfMemoryException();
+
+ m_bDelStgOnRelease = bDeleteStorageOnRelease;
+ m_bReleaseStreamOnDestr = bReleaseStreamOnDestruction;
+
+ return SUCCEEDED( hr );
+}
+
+//------------------------------------------------------------------------
+// free the global memory and invalidate the stream pointer
+//------------------------------------------------------------------------
+
+void SAL_CALL CStgTransferHelper::cleanup( )
+{
+ if ( m_lpStream && !m_bDelStgOnRelease )
+ {
+ HGLOBAL hGlob;
+ GetHGlobalFromStream( m_lpStream, &hGlob );
+ GlobalFree( hGlob );
+ }
+
+ m_lpStream->Release( );
+ m_lpStream = NULL;
+}
+
+//------------------------------------------------------------------------
+// return the size of memory we point to
+//------------------------------------------------------------------------
+
+sal_uInt32 SAL_CALL CStgTransferHelper::memSize( ) const
+{
+ DWORD dwSize = 0;
+
+ if ( NULL != m_lpStream )
+ {
+ HGLOBAL hGlob;
+
+ GetHGlobalFromStream( m_lpStream, &hGlob );
+ dwSize = GlobalSize( hGlob );
+ }
+
+ return dwSize;
+}
+
diff --git a/dtrans/source/win32/dtobj/DTransHelper.hxx b/dtrans/source/win32/dtobj/DTransHelper.hxx
new file mode 100644
index 000000000000..217f7d15718e
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DTransHelper.hxx
@@ -0,0 +1,238 @@
+/*************************************************************************
+ *
+ * $RCSfile: DTransHelper.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:50:37 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _DTRANSHELPER_HXX_
+#define _DTRANSHELPER_HXX_
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#include <windows.h>
+
+//------------------------------------------------------------------------
+// defines
+//------------------------------------------------------------------------
+
+#define AUTO_INIT TRUE
+#define NO_AUTO_INIT FALSE
+#define MEM_DESTROY_ON_RELEASE TRUE
+#define NO_MEM_DESTROY_ON_RELEASE FALSE
+
+//------------------------------------------------------------------------
+// deklarations
+//------------------------------------------------------------------------
+
+// will be thrown of allocation of
+// memory fails
+class COutOfMemoryException
+{
+};
+
+//-------------------------------------------------------------------------
+// a helper class to manage a global memory area, the clients can write
+// into the global memory area and extract the handle to the global mem
+// note: not thread-safe
+//-------------------------------------------------------------------------
+
+class CStgTransferHelper
+{
+public:
+ CStgTransferHelper( sal_Bool bAutoInit = sal_False,
+ HGLOBAL hGlob = NULL,
+ sal_Bool bDeleteStorageOnRelease = sal_False,
+ sal_Bool bReleaseStreamOnDestruction = sal_True );
+
+ ~CStgTransferHelper( );
+
+ sal_Bool SAL_CALL write( const void* lpData, ULONG cb, ULONG* cbWritten = NULL );
+ sal_Bool SAL_CALL read( LPVOID pv, ULONG cb, ULONG* pcbRead = NULL );
+
+ HGLOBAL SAL_CALL getHGlobal( ) const;
+ void SAL_CALL getIStream( LPSTREAM* ppStream );
+
+ sal_Bool SAL_CALL init( SIZE_T newSize,
+ UINT uiFlags = GMEM_MOVEABLE | GMEM_ZEROINIT,
+ sal_Bool bDeleteStorageOnRelease = sal_False,
+ sal_Bool bReleasStreamOnDestruction = sal_True );
+
+ sal_Bool SAL_CALL init( HGLOBAL hGlob,
+ sal_Bool bDeleteStorageOnRelease = sal_False,
+ sal_Bool bReleaseStreamOnDestruction = sal_True );
+
+ // returns the size of the managed memory
+ sal_uInt32 SAL_CALL memSize( ) const;
+
+ // free the global memory and necessary
+ // release the internal stream pointer
+ void SAL_CALL cleanup( );
+
+private:
+ LPSTREAM m_lpStream;
+ sal_Bool m_bDelStgOnRelease;
+ sal_Bool m_bReleaseStreamOnDestr;
+
+private:
+ CStgTransferHelper( const CStgTransferHelper& );
+ CStgTransferHelper& operator=( const CStgTransferHelper& );
+};
+
+//-------------------------------------------------------------------------
+// something like an auto-pointer - allows access to the memory belonging
+// to a HGLOBAL and automatically unlocks a global memory at destruction
+// time
+//-------------------------------------------------------------------------
+
+class CRawHGlobalPtr
+{
+public:
+
+ //---------------------------------------------
+ // ctor
+ //---------------------------------------------
+
+ CRawHGlobalPtr( HGLOBAL hGlob ) :
+ m_hGlob( hGlob ),
+ m_bIsLocked( FALSE ),
+ m_pGlobMem( NULL )
+ {
+ }
+
+
+ //---------------------------------------------
+ // ctor
+ //---------------------------------------------
+
+ CRawHGlobalPtr( const CStgTransferHelper& theHGlobalHelper ) :
+ m_hGlob( theHGlobalHelper.getHGlobal( ) ),
+ m_bIsLocked( FALSE ),
+ m_pGlobMem( NULL )
+ {
+ }
+
+ //---------------------------------------------
+ // dtor
+ //---------------------------------------------
+
+ ~CRawHGlobalPtr( )
+ {
+ if ( m_bIsLocked )
+ GlobalUnlock( m_hGlob );
+ }
+
+ //---------------------------------------------
+ // lock the global memory (initializes a
+ // pointer to this memory)
+ //---------------------------------------------
+
+ BOOL Lock( )
+ {
+ if ( !m_bIsLocked && ( NULL != m_hGlob ) )
+ {
+ m_pGlobMem = GlobalLock( m_hGlob );
+ m_bIsLocked = ( NULL != m_pGlobMem );
+ }
+
+ return m_bIsLocked;
+ }
+
+ //---------------------------------------------
+ // unlock the global memory (invalidates the
+ // pointer to this memory)
+ //---------------------------------------------
+
+ BOOL Unlock( )
+ {
+ GlobalUnlock( m_hGlob );
+ m_bIsLocked = FALSE;
+ m_pGlobMem = NULL;
+
+ return ( NO_ERROR == GetLastError( ) );
+ }
+
+ //---------------------------------------------
+ // locks the global memory and returns a
+ // pointer to this memory
+ //---------------------------------------------
+
+ LPVOID GetMemPtr( )
+ {
+ Lock( );
+ return m_pGlobMem;
+ }
+
+ //---------------------------------------------
+ // size of mem we point to
+ //---------------------------------------------
+
+ int MemSize( ) const
+ {
+ return GlobalSize( m_hGlob );
+ }
+
+private:
+ HGLOBAL m_hGlob;
+ BOOL m_bIsLocked;
+ LPVOID m_pGlobMem;
+};
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/DataFmtTransl.cxx b/dtrans/source/win32/dtobj/DataFmtTransl.cxx
new file mode 100644
index 000000000000..fc2b4da2db78
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DataFmtTransl.cxx
@@ -0,0 +1,375 @@
+/*************************************************************************
+ *
+ * $RCSfile: DataFmtTransl.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:52:05 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _DATAFMTTRANSL_HXX_
+#include "DataFmtTransl.hxx"
+#endif
+
+#ifndef _RTL_STRING_HXX_
+#include <rtl/string.hxx>
+#endif
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#ifndef _RTL_TENCINFO_H
+#include <rtl/tencinfo.h>
+#endif
+
+#ifndef _IMPLHELPER_HXX_
+#include "..\misc\ImplHelper.hxx"
+#endif
+
+#ifndef _WINCLIP_HXX_
+#include "..\misc\WinClip.hxx"
+#endif
+
+#ifndef _MIMEATTRIB_HXX_
+#include "MimeAttrib.hxx"
+#endif
+
+#ifndef _DTRANSHELPER_HXX_
+#include "DTransHelper.hxx"
+#endif
+
+#ifndef _RTL_STRING_H_
+#include <rtl/string.h>
+#endif
+
+#include <windows.h>
+#include <olestd.h>
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using namespace rtl;
+using namespace std;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::datatransfer;
+using namespace com::sun::star::lang;
+
+//------------------------------------------------------------------------
+// const
+//------------------------------------------------------------------------
+
+const Type CPPUTYPE_SALINT32 = getCppuType((sal_Int32*)0);
+const Type CPPUTYPE_SALINT8 = getCppuType((sal_Int8*)0);
+const Type CPPUTYPE_OUSTRING = getCppuType((OUString*)0);
+const Type CPPUTYPE_SEQSALINT8 = getCppuType((Sequence< sal_Int8>*)0);
+const sal_Int32 MAX_CLIPFORMAT_NAME = 256;
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CDataFormatTranslator::CDataFormatTranslator( const Reference< XMultiServiceFactory >& aServiceManager ) :
+ m_SrvMgr( aServiceManager )
+{
+ m_XDataFormatTranslator = Reference< XDataFormatTranslator >(
+ m_SrvMgr->createInstance( OUString::createFromAscii( "com.sun.star.datatransfer.DataFormatTranslator" ) ), UNO_QUERY );
+
+ OSL_ASSERT( !m_XDataFormatTranslator.is( ) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+FORMATETC CDataFormatTranslator::getFormatEtcFromDataFlavor( const DataFlavor& aDataFlavor ) const
+{
+ CLIPFORMAT cf = CF_INVALID;
+
+ try
+ {
+ Any aFormat = m_XDataFormatTranslator->getSystemDataTypeFromDataFlavor( aDataFlavor );
+
+ if ( aFormat.getValueType( ) == CPPUTYPE_SALINT32 )
+ {
+ aFormat >>= cf;
+ OSL_ENSURE( CF_INVALID != cf, "Invalid Clipboard format delivered" );
+ }
+ else if ( aFormat.getValueType( ) == CPPUTYPE_OUSTRING )
+ {
+ OUString aClipFmtName;
+ aFormat >>= aClipFmtName;
+
+ OSL_ASSERT( aClipFmtName.getLength( ) );
+ cf = RegisterClipboardFormatW( aClipFmtName.getStr( ) );
+
+ OSL_ENSURE( CF_INVALID != cf, "RegisterClipboardFormat failed" );
+ }
+ else
+ OSL_ENSURE( sal_False, "Wrong Any-Type detected" );
+ }
+ catch( ... )
+ {
+ OSL_ENSURE( sal_False, "Unexpected error" );
+ }
+
+ return getFormatEtcForClipformat( cf );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+DataFlavor CDataFormatTranslator::getDataFlavorFromFormatEtc( const Reference< XTransferable >& refXTransferable, const FORMATETC& aFormatEtc ) const
+{
+ DataFlavor aFlavor;
+
+ try
+ {
+ CLIPFORMAT aClipformat = aFormatEtc.cfFormat;
+
+ Any aAny;
+ aAny <<= static_cast< sal_Int32 >( aClipformat );
+
+ if ( isOemOrAnsiTextClipformat( aClipformat ) )
+ {
+ aFlavor.MimeType = OUString::createFromAscii( "text/plain;charset=" );
+ aFlavor.MimeType += getTextCharsetFromClipboard( refXTransferable, aClipformat );
+
+ aFlavor.HumanPresentableName = OUString::createFromAscii( "OEM/ANSI Text" );
+ aFlavor.DataType = CPPUTYPE_SALINT8;
+ }
+ else
+ {
+ aFlavor = m_XDataFormatTranslator->getDataFlavorFromSystemDataType( aAny );
+
+ if ( !aFlavor.MimeType.getLength( ) )
+ {
+ aAny <<= getClipboardFormatName( aClipformat );
+ aFlavor = m_XDataFormatTranslator->getDataFlavorFromSystemDataType( aAny );
+ }
+ }
+ }
+ catch( ... )
+ {
+ OSL_ENSURE( sal_False, "Unexpected error" );
+ }
+
+ return aFlavor;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+OUString CDataFormatTranslator::getClipboardFormatName( CLIPFORMAT aClipformat ) const
+{
+ OSL_PRECOND( CF_INVALID != aClipformat, "Invalid clipboard format" );
+
+ sal_Unicode wBuff[ MAX_CLIPFORMAT_NAME ];
+ sal_Int32 nLen = GetClipboardFormatNameW( aClipformat, wBuff, MAX_CLIPFORMAT_NAME );
+
+ return OUString( wBuff, nLen );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+FORMATETC SAL_CALL CDataFormatTranslator::getFormatEtcForClipformat( CLIPFORMAT cf ) const
+{
+ FORMATETC fetc;
+
+ fetc.cfFormat = cf;
+ fetc.ptd = NULL;
+ fetc.dwAspect = DVASPECT_CONTENT;
+ fetc.lindex = -1;
+
+ switch( cf )
+ {
+ case CF_METAFILEPICT:
+ fetc.tymed = TYMED_MFPICT;
+ break;
+
+ case CF_ENHMETAFILE:
+ fetc.tymed = TYMED_ENHMF;
+ break;
+
+ default:
+ fetc.tymed = TYMED_HGLOBAL | TYMED_ISTREAM;
+ }
+
+ return fetc;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CDataFormatTranslator::isOemOrAnsiTextClipformat( CLIPFORMAT aClipformat ) const
+{
+ return ( (aClipformat == CF_TEXT) ||
+ (aClipformat == CF_OEMTEXT) );
+}
+
+//------------------------------------------------------------------------
+// helper function
+//------------------------------------------------------------------------
+
+OUString SAL_CALL CDataFormatTranslator::getCodePageFromLocaleId( LCID locale, LCTYPE lcType ) const
+{
+ OSL_ASSERT( IsValidLocale( locale, LCID_SUPPORTED ) );
+
+ // we use the GetLocaleInfoA because don't want to provide
+ // a unicode wrapper function for Win9x in sal/systools
+ char buff[6];
+ GetLocaleInfoA( locale, lcType, buff, sizeof( buff ) );
+ rtl_TextEncoding tenc = rtl_getTextEncodingFromPCCodePage( CP_ACP );
+
+ return OUString( buff, rtl_str_getLength( buff ), tenc );
+}
+
+//------------------------------------------------------------------------
+// should be called only if there is realy text on the clipboard
+//------------------------------------------------------------------------
+
+LCID SAL_CALL CDataFormatTranslator::getCurrentLocaleFromClipboard(
+ const Reference< XTransferable >& refXTransferable ) const
+{
+ Any aAny;
+ FORMATETC fetc;
+
+ fetc.cfFormat = CF_LOCALE;
+ DataFlavor aFlavor = getDataFlavorFromFormatEtc( refXTransferable, fetc );
+
+ OSL_ASSERT( aFlavor.MimeType.getLength( ) );
+
+ LCID lcid;
+
+ try
+ {
+ if ( refXTransferable->isDataFlavorSupported( aFlavor ) )
+ {
+ aAny = refXTransferable->getTransferData( aFlavor );
+ if ( aAny.hasValue( ) )
+ {
+ OSL_ASSERT( aAny.getValueType( ) == CPPUTYPE_SEQSALINT8 );
+ Sequence< sal_Int8 > seqSalInt8;
+ aAny >>= seqSalInt8;
+
+ lcid = *reinterpret_cast< sal_Int32* >( seqSalInt8.getArray( ) );
+ }
+ }
+ }
+ catch( ... )
+ {
+ OSL_ENSURE( sal_False, "Unexpected error" );
+ }
+
+ if ( !IsValidLocale( lcid, LCID_SUPPORTED ) )
+ lcid = GetThreadLocale( );
+
+ return lcid;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+OUString SAL_CALL CDataFormatTranslator::makeMimeCharsetFromLocaleId(
+ LCID lcid, LCTYPE lcType, const OUString& aCharsetValuePrefix ) const
+{
+ OUString charset = getCodePageFromLocaleId( lcid, lcType );
+ return OUString::createFromAscii( "charset=" ) + charset;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+OUString SAL_CALL CDataFormatTranslator::getTextCharsetFromClipboard(
+ const Reference< XTransferable >& refXTransferable, CLIPFORMAT aClipformat ) const
+{
+ OSL_ASSERT( isOemOrAnsiTextClipformat( aClipformat ) );
+
+ OUString charset;
+ if ( CF_TEXT == aClipformat )
+ {
+ LCID lcid = getCurrentLocaleFromClipboard( refXTransferable );
+ charset = makeMimeCharsetFromLocaleId(
+ lcid,
+ LOCALE_IDEFAULTANSICODEPAGE,
+ PRE_WINDOWS_CODEPAGE );
+ }
+ else if ( CF_OEMTEXT == aClipformat )
+ {
+ LCID lcid = getCurrentLocaleFromClipboard( refXTransferable );
+ charset = makeMimeCharsetFromLocaleId(
+ lcid,
+ LOCALE_IDEFAULTCODEPAGE,
+ PRE_OEM_CODEPAGE );
+ }
+ else // CF_UNICODE
+ OSL_ASSERT( sal_False );
+
+ return charset;
+} \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/DataFmtTransl.hxx b/dtrans/source/win32/dtobj/DataFmtTransl.hxx
new file mode 100644
index 000000000000..f64492627781
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DataFmtTransl.hxx
@@ -0,0 +1,122 @@
+/*************************************************************************
+ *
+ * $RCSfile: DataFmtTransl.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:51:59 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _DATAFMTTRANSL_HXX_
+#define _DATAFMTTRANSL_HXX_
+
+//-----------------------------------------------
+// includes
+//-----------------------------------------------
+
+#ifndef _CPPUHELPER_SERVICEFACTORY_HXX_
+#include <cppuhelper/servicefactory.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XDATAFORMATTRANSLATOR_HPP_
+#include <com/sun/star/datatransfer/XDataFormatTranslator.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#endif
+
+#ifndef _SAL_TYPES_H_
+#include <sal/types.h>
+#endif
+
+#ifndef _RTL_USTRING_
+#include <rtl/ustring>
+#endif
+
+#include <windows.h>
+
+//-----------------------------------------------
+// declaration
+//-----------------------------------------------
+
+class CDataFormatTranslator
+{
+public:
+ CDataFormatTranslator( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager );
+
+ FORMATETC getFormatEtcFromDataFlavor( const com::sun::star::datatransfer::DataFlavor& aDataFlavor ) const;
+ com::sun::star::datatransfer::DataFlavor getDataFlavorFromFormatEtc(
+ const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& refXTransferable, const FORMATETC& aFormatEtc ) const;
+
+ FORMATETC SAL_CALL getFormatEtcForClipformat( CLIPFORMAT cf ) const;
+
+private:
+ rtl::OUString SAL_CALL getClipboardFormatName( CLIPFORMAT aClipformat ) const;
+ sal_Bool SAL_CALL isOemOrAnsiTextClipformat( CLIPFORMAT aClipformat ) const;
+
+ rtl::OUString SAL_CALL getCodePageFromLocaleId( LCID locale, LCTYPE lcType ) const;
+ LCID SAL_CALL getCurrentLocaleFromClipboard( const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& refXTransferable ) const;
+ rtl::OUString SAL_CALL makeMimeCharsetFromLocaleId( LCID lcid, LCTYPE lcType, const rtl::OUString& aCharsetValuePrefix ) const;
+ rtl::OUString SAL_CALL getTextCharsetFromClipboard(
+ const com::sun::star::uno::Reference< com::sun::star::datatransfer::XTransferable >& refXTransferable, CLIPFORMAT aClipformat ) const;
+
+private:
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_SrvMgr;
+ com::sun::star::uno::Reference< com::sun::star::datatransfer::XDataFormatTranslator > m_XDataFormatTranslator;
+};
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/DtObjFactory.cxx b/dtrans/source/win32/dtobj/DtObjFactory.cxx
new file mode 100644
index 000000000000..d90cbc1d593c
--- /dev/null
+++ b/dtrans/source/win32/dtobj/DtObjFactory.cxx
@@ -0,0 +1,101 @@
+/*************************************************************************
+ *
+ * $RCSfile: DtObjFactory.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:52:43 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _DTOBJFACTORY_HXX_
+#include "DtObjFactory.hxx"
+#endif
+
+#ifndef _TWRAPPERDATAOBJECT_HXX_
+#include "XTDataObject.hxx"
+#endif
+
+#ifndef _DOWRAPPERTRANSFERABLE_HXX_
+#include "DOTransferable.hxx"
+#endif
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::datatransfer;
+using namespace com::sun::star::lang;
+
+//------------------------------------------------------------------------
+// implementation
+//------------------------------------------------------------------------
+
+IDataObjectPtr SAL_CALL CDTransObjFactory::createDataObjFromTransferable( const Reference< XMultiServiceFactory >& aServiceManager,
+ const Reference< XTransferable >& refXTransferable )
+{
+ return ( IDataObjectPtr( new CXTDataObject( aServiceManager, refXTransferable ) ) );
+}
+
+Reference< XTransferable > SAL_CALL CDTransObjFactory::createTransferableFromDataObj( const Reference< XMultiServiceFactory >& aServiceManager,
+ IDataObject* pIDataObject )
+{
+ return Reference< XTransferable >( new CDOTransferable( aServiceManager, pIDataObject ) );
+}
+
diff --git a/dtrans/source/win32/dtobj/FetcList.cxx b/dtrans/source/win32/dtobj/FetcList.cxx
new file mode 100644
index 000000000000..836bafb87ecb
--- /dev/null
+++ b/dtrans/source/win32/dtobj/FetcList.cxx
@@ -0,0 +1,708 @@
+/*************************************************************************
+ *
+ * $RCSfile: FetcList.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:51:10 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#ifndef _FETCLIST_HXX_
+#include "FetcList.hxx"
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XMIMECONTENTTYPEFACTORY_HPP_
+#include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XMIMECONTENTTYPE_HPP_
+#include <com/sun/star/datatransfer/XMimeContentType.hpp>
+#endif
+
+#ifndef _DATAFORMATTRANSLATOR_HXX_
+#include "DataFmtTransl.hxx"
+#endif
+
+#ifndef _IMPLHELPER_HXX_
+#include "..\misc\ImplHelper.hxx"
+#endif
+
+#include "MimeAttrib.hxx"
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using namespace com::sun::star::uno;
+using namespace com::sun::star::datatransfer;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::container;
+using namespace rtl;
+using namespace std;
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+HANDLE CFormatRegistrar::m_hEvtEnumLocaleReady = NULL;
+LCID CFormatRegistrar::m_TxtLocale = 0;
+sal_uInt32 CFormatRegistrar::m_TxtCodePage = GetACP( );
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtc::CFormatEtc( const FORMATETC& aFormatEtc )
+{
+ CopyFormatEtc( &m_FormatEtc, &const_cast< FORMATETC& >( aFormatEtc ) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtc::CFormatEtc( CLIPFORMAT cf, DWORD tymed, DVTARGETDEVICE* ptd, DWORD dwAspect, LONG lindex )
+{
+ m_FormatEtc.cfFormat = cf;
+
+ if ( ptd )
+ m_FormatEtc.ptd = CopyTargetDevice( ptd );
+
+ m_FormatEtc.dwAspect = dwAspect;
+ m_FormatEtc.lindex = lindex;
+ m_FormatEtc.tymed = tymed;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtc::CFormatEtc( const CFormatEtc& theOther )
+{
+ m_FormatEtc.cfFormat = theOther.m_FormatEtc.cfFormat;
+
+ if ( theOther.m_FormatEtc.ptd )
+ m_FormatEtc.ptd = CopyTargetDevice( theOther.m_FormatEtc.ptd );
+
+ m_FormatEtc.dwAspect = theOther.m_FormatEtc.dwAspect;
+ m_FormatEtc.lindex = theOther.m_FormatEtc.lindex;
+ m_FormatEtc.tymed = theOther.m_FormatEtc.tymed;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtc::~CFormatEtc( )
+{
+ if ( m_FormatEtc.ptd )
+ DeleteTargetDevice( m_FormatEtc.ptd );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtc& CFormatEtc::operator=( const CFormatEtc& theOther )
+{
+ if ( this != &theOther )
+ {
+ if ( m_FormatEtc.ptd )
+ DeleteTargetDevice( m_FormatEtc.ptd );
+
+ m_FormatEtc.cfFormat = theOther.m_FormatEtc.cfFormat;
+
+ if ( theOther.m_FormatEtc.ptd )
+ m_FormatEtc.ptd = CopyTargetDevice( theOther.m_FormatEtc.ptd );
+
+ m_FormatEtc.dwAspect = theOther.m_FormatEtc.dwAspect;
+ m_FormatEtc.lindex = theOther.m_FormatEtc.lindex;
+ m_FormatEtc.tymed = theOther.m_FormatEtc.tymed;
+ }
+
+ return *this;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtc::operator FORMATETC*( )
+{
+ return &m_FormatEtc;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void CFormatEtc::getFORMATETC( LPFORMATETC lpFormatEtc )
+{
+ OSL_ASSERT( lpFormatEtc );
+ OSL_ASSERT( !IsBadWritePtr( lpFormatEtc, sizeof( FORMATETC ) ) );
+
+ CopyFormatEtc( lpFormatEtc, &m_FormatEtc );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CLIPFORMAT CFormatEtc::getClipformat( ) const
+{
+ return m_FormatEtc.cfFormat;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+DWORD CFormatEtc::getTymed( ) const
+{
+ return m_FormatEtc.tymed;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void CFormatEtc::getTargetDevice( DVTARGETDEVICE** lpDvTargetDevice ) const
+{
+ OSL_ASSERT( lpDvTargetDevice );
+ OSL_ASSERT( !IsBadWritePtr( lpDvTargetDevice, sizeof( DVTARGETDEVICE ) ) );
+
+ *lpDvTargetDevice = NULL;
+
+ if ( m_FormatEtc.ptd )
+ *lpDvTargetDevice = CopyTargetDevice( m_FormatEtc.ptd );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+DWORD CFormatEtc::getAspect( ) const
+{
+ return m_FormatEtc.dwAspect;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+LONG CFormatEtc::getLindex( ) const
+{
+ return m_FormatEtc.lindex;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool operator==( CFormatEtc& lhs, CFormatEtc& rhs )
+{
+ return CompareFormatEtc( &lhs.m_FormatEtc, &rhs.m_FormatEtc );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool operator!=( CFormatEtc& lhs, CFormatEtc& rhs )
+{
+ return ( !( lhs == rhs ) );
+}
+
+
+//#########################################################################
+
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatEtcContainer::CFormatEtcContainer( )
+{
+ m_EnumIterator = m_FormatMap.begin( );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool CFormatEtcContainer::addFormatEtc( const FORMATETC& fetc )
+{
+ return m_FormatMap.insert(
+ make_pair( fetc.cfFormat, CFormatEtc( fetc ) ) ).second;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void SAL_CALL CFormatEtcContainer::removeFormatEtc( const FORMATETC& fetc )
+{
+ FormatEtcMap_t::iterator iter = m_FormatMap.find( fetc.cfFormat );
+
+ if ( iter != m_FormatMap.end( ) )
+ m_FormatMap.erase( iter );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void SAL_CALL CFormatEtcContainer::removeAllFormatEtc( )
+{
+ m_FormatMap.clear( );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool CFormatEtcContainer::hasFormatEtc( const FORMATETC& fetc ) const
+{
+ FormatEtcMap_t::const_iterator iter = m_FormatMap.find( fetc.cfFormat );
+
+ if ( iter != m_FormatMap.end( ) )
+ {
+ return CFormatEtc( fetc ) == CFormatEtc( iter->second );
+ }
+
+ return sal_False;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool CFormatEtcContainer::hasElements( ) const
+{
+ return ( m_FormatMap.size( ) > 0 );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void CFormatEtcContainer::beginEnumFormatEtc( )
+{
+ m_EnumIterator = m_FormatMap.begin( );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_uInt32 SAL_CALL CFormatEtcContainer::nextFormatEtc( LPFORMATETC lpFetc,
+ sal_uInt32 aNum )
+{
+ OSL_ASSERT( lpFetc );
+ OSL_ASSERT( !IsBadWritePtr( lpFetc, sizeof( FORMATETC ) * aNum ) );
+
+ sal_uInt32 nFetched = 0;
+
+ if ( m_EnumIterator != m_FormatMap.end( ) )
+ {
+ for ( sal_uInt32 i = 0; i < aNum; i++, nFetched++, lpFetc++ )
+ {
+ CopyFormatEtc( lpFetc, m_EnumIterator->second );
+ }
+ }
+
+ return nFetched;
+}
+
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CFormatEtcContainer::skipFormatEtc( sal_uInt32 aNum )
+{
+ for ( sal_uInt32 i = 0; i < aNum; i++, ++m_EnumIterator )
+ /* intentionally left empty */;
+
+ return ( m_EnumIterator != m_FormatMap.end( ) );
+}
+
+
+//#########################################################################
+
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatRegistrar::CFormatRegistrar( const Reference< XMultiServiceFactory >& ServiceManager,
+ const CDataFormatTranslator& aDataFormatTranslator ) :
+ m_DataFormatTranslator( aDataFormatTranslator ),
+ m_bHasSynthesizedLocale( sal_False ),
+ m_SrvMgr( ServiceManager )
+{
+ CFormatRegistrar::m_hEvtEnumLocaleReady = CreateEvent( NULL,
+ sal_False,
+ sal_False,
+ NULL );
+
+ OSL_ASSERT( CFormatRegistrar::m_hEvtEnumLocaleReady );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+CFormatRegistrar::~CFormatRegistrar( )
+{
+ if ( CFormatRegistrar::m_hEvtEnumLocaleReady )
+ CloseHandle( CFormatRegistrar::m_hEvtEnumLocaleReady );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void SAL_CALL CFormatRegistrar::RegisterFormats( const Sequence< DataFlavor >& aFlavorList,
+ CFormatEtcContainer& aFormatEtcContainer )
+{
+ sal_Int32 nFlavors = aFlavorList.getLength( );
+ sal_Bool bSuccess = sal_False;
+ DataFlavor aFlavor;
+
+ for( sal_Int32 i = 0; i < nFlavors; i++ )
+ {
+ aFlavor = aFlavorList[i];
+ FORMATETC fetc = dataFlavorToFormatEtc( aFlavor );
+
+ if ( needsToSynthesizeAccompanyFormats( fetc ) )
+ {
+
+#ifdef _DEBUG
+ FORMATETC fetcdbg;
+
+ if ( fetc.cfFormat == CF_TEXT )
+ {
+ fetcdbg = getFormatEtcForClipformat( CF_OEMTEXT );
+ OSL_ASSERT( !aFormatEtcContainer.hasFormatEtc( fetcdbg ) );
+ }
+ else if ( fetc.cfFormat == CF_OEMTEXT )
+ {
+ fetcdbg = getFormatEtcForClipformat( CF_TEXT );
+ OSL_ASSERT( !aFormatEtcContainer.hasFormatEtc( fetcdbg ) );
+ }
+#endif
+
+ // we don't validate if the operation succeded
+ // because an accompany format might have be
+ // registered so that it's no problem if the
+ // operation fails because of a duplicate format
+ // e.g. text was already registered we have also
+ // registered unicode text, if we later try to
+ // register unicode text it will fail
+ aFormatEtcContainer.addFormatEtc( fetc );
+
+ synthesizeAndRegisterAccompanyFormats( fetc, aFlavor, aFormatEtcContainer );
+ }
+ else
+ {
+ bSuccess = aFormatEtcContainer.addFormatEtc( fetc );
+ OSL_ASSERT( bSuccess );
+ }
+ }
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CFormatRegistrar::hasSynthesizedLocale( ) const
+{
+ return m_bHasSynthesizedLocale;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+LCID SAL_CALL CFormatRegistrar::getSynthesizedLocale( ) const
+{
+ return m_TxtLocale;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CFormatRegistrar::isOemOrAnsiTextFormat( CLIPFORMAT cf ) const
+{
+ return ( (cf == CF_TEXT) || (cf == CF_OEMTEXT) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CFormatRegistrar::isUnicodeTextFormat( CLIPFORMAT cf ) const
+{
+ return ( cf == CF_UNICODETEXT );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CFormatRegistrar::isTextFormat( CLIPFORMAT cf ) const
+{
+ return ( isOemOrAnsiTextFormat( cf ) ||
+ isUnicodeTextFormat( cf ) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+FORMATETC SAL_CALL CFormatRegistrar::dataFlavorToFormatEtc( const DataFlavor& aFlavor ) const
+{
+ return m_DataFormatTranslator.getFormatEtcFromDataFlavor( aFlavor );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CFormatRegistrar::needsToSynthesizeAccompanyFormats( const FORMATETC& aFormatEtc ) const
+{
+ return ( isOemOrAnsiTextFormat( aFormatEtc.cfFormat ) ||
+ isUnicodeTextFormat( aFormatEtc.cfFormat ) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void SAL_CALL CFormatRegistrar::synthesizeAndRegisterAccompanyFormats(
+ FORMATETC& aFormatEtc, const DataFlavor& aFlavor, CFormatEtcContainer& aFormatEtcContainer )
+{
+ CLIPFORMAT cf = aFormatEtc.cfFormat;
+ OSL_ASSERT( isOemOrAnsiTextFormat(cf) || isUnicodeTextFormat(cf) );
+
+ FORMATETC fetc;
+
+ if ( isOemOrAnsiTextFormat( cf ) )
+ {
+ OUString charset = getCharsetFromDataFlavor( aFlavor );
+ if ( charset.getLength( ) )
+ m_TxtCodePage = getWinCodePageFromMimeCharset( charset );
+ else
+ m_TxtCodePage = GetACP( );
+
+ OSL_ASSERT( IsValidCodePage( m_TxtCodePage ) );
+
+ if ( !isEqualCurrentSystemCodePage( m_TxtCodePage ) )
+ {
+ FindLocaleForTextCodePage( );
+ fetc = getFormatEtcForClipformat( CF_LOCALE );
+ aFormatEtcContainer.addFormatEtc( fetc );
+ m_bHasSynthesizedLocale = sal_True;
+ }
+
+ // register may fail if we have already
+ // registered CF_UNICODETEXT but
+ // then it doesn't matter because in this
+ // case CF_TEXT is already registered
+ fetc = getFormatEtcForClipformat( CF_UNICODETEXT );
+ aFormatEtcContainer.addFormatEtc( fetc );
+ }
+ else // CF_UNICODETEXT
+ {
+ // register may fail if we have already
+ // registered CF_TEXT or CF_OEMTEXT but
+ // then it doesn't matter because in this
+ // case CF_UNICODETEXT is already registered
+ fetc = getFormatEtcForClipformat( CF_TEXT );
+ aFormatEtcContainer.addFormatEtc( fetc );
+ }
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+OUString SAL_CALL CFormatRegistrar::getCharsetFromDataFlavor( const DataFlavor& aFlavor )
+{
+ OUString charset;
+
+ try
+ {
+ Reference< XMimeContentTypeFactory > xMimeFac(
+ m_SrvMgr->createInstance( OUString::createFromAscii( \
+ "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), UNO_QUERY );
+
+ if( xMimeFac.is( ) )
+ {
+ Reference< XMimeContentType > xMimeType( xMimeFac->createMimeContentType( aFlavor.MimeType ) );
+ charset = xMimeType->getParameterValue( TEXTPLAIN_PARAM_CHARSET );
+ }
+ }
+ catch(NoSuchElementException&)
+ {
+ OSL_ENSURE( sal_False, "Text data flavor without charset not allowed" );
+ }
+ catch(...)
+ {
+ OSL_ENSURE( sal_False, "Invalid data flavor" );
+ }
+
+ return charset;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+FORMATETC SAL_CALL CFormatRegistrar::getFormatEtcForClipformat( CLIPFORMAT aClipformat ) const
+{
+ return m_DataFormatTranslator.getFormatEtcForClipformat( aClipformat );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool CFormatRegistrar::isEqualCurrentSystemCodePage( sal_uInt32 aCodePage ) const
+{
+ return ( (aCodePage == GetOEMCP()) || (aCodePage == GetACP()) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+void SAL_CALL CFormatRegistrar::FindLocaleForTextCodePage( )
+{
+ EnumSystemLocalesA( CFormatRegistrar::EnumLocalesProc, LCID_SUPPORTED );
+ WaitForSingleObject( CFormatRegistrar::m_hEvtEnumLocaleReady, INFINITE );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CFormatRegistrar::isLocaleCodePage( LCID lcid, LCTYPE lctype, sal_uInt32 codepage )
+{
+ char buff[6];
+ sal_uInt32 localeCodePage;
+
+ // get the ansi codepage of the current locale
+ GetLocaleInfoA( lcid, lctype, buff, sizeof( buff ) );
+ localeCodePage = atoi( buff );
+
+ return ( localeCodePage == codepage );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CFormatRegistrar::isLocaleOemCodePage( LCID lcid, sal_uInt32 codepage )
+{
+ return isLocaleCodePage( lcid, LOCALE_IDEFAULTCODEPAGE, codepage );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CFormatRegistrar::isLocaleAnsiCodePage( LCID lcid, sal_uInt32 codepage )
+{
+ return isLocaleCodePage( lcid, LOCALE_IDEFAULTANSICODEPAGE, codepage );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+BOOL CALLBACK CFormatRegistrar::EnumLocalesProc( LPSTR lpLocaleStr )
+{
+ LCID lcid = atoi( lpLocaleStr );
+
+ if ( isLocaleAnsiCodePage( lcid, CFormatRegistrar::m_TxtCodePage ) ||
+ isLocaleOemCodePage( lcid, CFormatRegistrar::m_TxtCodePage ) )
+ {
+ CFormatRegistrar::m_TxtLocale = lcid;
+ SetEvent( CFormatRegistrar::m_hEvtEnumLocaleReady );
+ return sal_False; // stop enumerating
+ }
+
+ return sal_True;
+}
+
diff --git a/dtrans/source/win32/dtobj/FetcList.hxx b/dtrans/source/win32/dtobj/FetcList.hxx
new file mode 100644
index 000000000000..ca27cdbc7242
--- /dev/null
+++ b/dtrans/source/win32/dtobj/FetcList.hxx
@@ -0,0 +1,235 @@
+/*************************************************************************
+ *
+ * $RCSfile: FetcList.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:51:04 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _FETCLIST_HXX_
+#define _FETCLIST_HXX_
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _SAL_TYPES_H_
+#include <sal/types.h>
+#endif
+
+#ifndef _CPPUHELPER_SERVICEFACTORY_HXX_
+#include <cppuhelper/servicefactory.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_DATAFLAVOR_HPP_
+#include <com/sun/star/datatransfer/DataFlavor.hpp>
+#endif
+
+#include <windows.h>
+#include <map>
+
+/**********************************************************************
+ stl container elements must fulfill the following requirements:
+ 1. they need a copy ctor and assignement operator(?)
+ 2. they must be compareable
+ because the FORMATETC structure has a pointer to a TARGETDEVICE
+ structure we need a simple wrapper class to fulfill these needs
+***********************************************************************/
+
+class CFormatEtc
+{
+public:
+ CFormatEtc( const FORMATETC& aFormatEtc );
+ CFormatEtc( CLIPFORMAT cf, DWORD tymed, DVTARGETDEVICE* ptd = NULL, DWORD dwAspect = DVASPECT_CONTENT, LONG lindex = -1 );
+ CFormatEtc( const CFormatEtc& theOther );
+
+ ~CFormatEtc( );
+
+ CFormatEtc& operator=( const CFormatEtc& theOther );
+ operator FORMATETC*( );
+
+ void getFORMATETC( LPFORMATETC lpFormatEtc );
+
+ CLIPFORMAT getClipformat( ) const;
+ DWORD getTymed( ) const;
+ void getTargetDevice( DVTARGETDEVICE** ptd ) const;
+ DWORD getAspect( ) const;
+ LONG getLindex( ) const;
+
+private:
+ FORMATETC m_FormatEtc;
+
+ friend sal_Bool operator==( CFormatEtc& lhs, CFormatEtc& rhs );
+ friend sal_Bool operator!=( CFormatEtc& lhs, CFormatEtc& rhs );
+};
+
+sal_Bool operator==( CFormatEtc& lhs, CFormatEtc& rhs );
+sal_Bool operator!=( CFormatEtc& lhs, CFormatEtc& rhs );
+
+/*****************************************************************
+ a simple container for FORMATECT structures
+ instances of this class are not thread-safe
+*****************************************************************/
+
+class CFormatEtcContainer
+{
+public:
+ CFormatEtcContainer( );
+
+ // duplicates not allowed
+ sal_Bool SAL_CALL addFormatEtc( const FORMATETC& fetc );
+
+ // removes the specified formatetc
+ void SAL_CALL removeFormatEtc( const FORMATETC& fetc );
+
+ // removes the formatetc at pos
+ void SAL_CALL removeAllFormatEtc( );
+
+ sal_Bool SAL_CALL hasFormatEtc( const FORMATETC& fetc ) const;
+
+ sal_Bool SAL_CALL hasElements( ) const;
+
+ // begin enumeration
+ void SAL_CALL beginEnumFormatEtc( );
+
+ // copies the specified number of formatetc structures starting
+ // at the current enum position
+ // the return value is the number of copied elements; if the
+ // current enum position is at the end the return value is 0
+ sal_uInt32 SAL_CALL nextFormatEtc( LPFORMATETC lpFetc, sal_uInt32 aNum = 1 );
+
+ // skips the specified number of elements in the container
+ sal_Bool SAL_CALL skipFormatEtc( sal_uInt32 aNum );
+
+protected:
+ typedef std::map< CLIPFORMAT, CFormatEtc > FormatEtcMap_t;
+
+private:
+ sal_uInt32 m_nCurrentEnumPos;
+ FormatEtcMap_t m_FormatMap;
+ FormatEtcMap_t::iterator m_EnumIterator;
+
+private:
+ //CFormatEtcContainer( const CFormatEtcContainer& );
+ //CFormatEtcContainer& operator=( const CFormatEtcContainer& );
+};
+
+/*****************************************************************
+ a helper class which converts data flavors to clipformats,
+ creates an appropriate formatetc structures and if possible
+ synthesizes clipboard formats if necessary, e.g. if text
+ is provided a locale will also be provided;
+ the class registers the formatetc within a CFormatEtcContainer
+
+ instances of this class are not thread-safe and multiple
+ instances of this class would use the same static variables
+ that's why this class should not be used by multiple threads,
+ only one thread of a process should use it
+*****************************************************************/
+
+// forward
+class CDataFormatTranslator;
+
+class CFormatRegistrar
+{
+public:
+ CFormatRegistrar( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ServiceManager,
+ const CDataFormatTranslator& aDataFormatTranslator );
+ ~CFormatRegistrar( );
+
+ void SAL_CALL RegisterFormats( const com::sun::star::uno::Sequence< com::sun::star::datatransfer::DataFlavor >& aFlavorList,
+ CFormatEtcContainer& aFormatEtcContainer );
+ sal_Bool SAL_CALL hasSynthesizedLocale( ) const;
+ LCID SAL_CALL getSynthesizedLocale( ) const;
+
+private:
+ sal_Bool SAL_CALL isOemOrAnsiTextFormat( CLIPFORMAT cf ) const;
+ sal_Bool SAL_CALL isUnicodeTextFormat( CLIPFORMAT cf ) const;
+ sal_Bool SAL_CALL isTextFormat( CLIPFORMAT cf ) const;
+ FORMATETC SAL_CALL dataFlavorToFormatEtc( const com::sun::star::datatransfer::DataFlavor& aFlavor ) const;
+ sal_Bool SAL_CALL needsToSynthesizeAccompanyFormats( const FORMATETC& aFormatEtc ) const;
+ void SAL_CALL synthesizeAndRegisterAccompanyFormats( FORMATETC& aFormatEtc,
+ const com::sun::star::datatransfer::DataFlavor& aFlavor,
+ CFormatEtcContainer& aFormatEtcContainer );
+ sal_Bool SAL_CALL isEqualCurrentSystemCodePage( sal_uInt32 aCodePage ) const;
+ rtl::OUString SAL_CALL getCharsetFromDataFlavor( const com::sun::star::datatransfer::DataFlavor& aFlavor );
+ FORMATETC SAL_CALL getFormatEtcForClipformat( CLIPFORMAT aClipformat ) const;
+
+ void SAL_CALL FindLocaleForTextCodePage( );
+
+ static sal_Bool SAL_CALL isLocaleOemCodePage( LCID lcid, sal_uInt32 codepage );
+ static sal_Bool SAL_CALL isLocaleAnsiCodePage( LCID lcid, sal_uInt32 codepage );
+ static sal_Bool SAL_CALL isLocaleCodePage( LCID lcid, LCTYPE lctype, sal_uInt32 codepage );
+
+ static BOOL CALLBACK EnumLocalesProc( LPSTR lpLocaleStr );
+
+private:
+ const CDataFormatTranslator& m_DataFormatTranslator;
+ sal_Bool m_bHasSynthesizedLocale;
+
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_SrvMgr;
+
+ static HANDLE m_hEvtEnumLocaleReady;
+ static LCID m_TxtLocale;
+ static sal_uInt32 m_TxtCodePage;
+
+private:
+ CFormatRegistrar( const CFormatRegistrar& );
+ CFormatRegistrar& operator=( const CFormatRegistrar& );
+};
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/FmtFilter.cxx b/dtrans/source/win32/dtobj/FmtFilter.cxx
new file mode 100644
index 000000000000..fe5be0891411
--- /dev/null
+++ b/dtrans/source/win32/dtobj/FmtFilter.cxx
@@ -0,0 +1,217 @@
+/*************************************************************************
+ *
+ * $RCSfile: FmtFilter.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:53:46 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _FMTFILTER_HXX_
+#include "FmtFilter.hxx"
+#endif
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using namespace com::sun::star::uno;
+
+//------------------------------------------------------------------------
+// implementation
+//------------------------------------------------------------------------
+
+#pragma pack(2)
+struct METAFILEHEADER
+{
+ DWORD key;
+ short hmf;
+ SMALL_RECT bbox;
+ WORD inch;
+ DWORD reserved;
+ WORD checksum;
+};
+#pragma pack()
+
+//------------------------------------------------------------------------
+// convert a windows metafile picture to a openoffice metafile picture
+//------------------------------------------------------------------------
+
+Sequence< sal_Int8 > SAL_CALL WinMFPictToOOMFPict( Sequence< sal_Int8 >& aMetaFilePict )
+{
+ OSL_ASSERT( aMetaFilePict.getLength( ) );
+
+ METAFILEPICT* pMFPict = reinterpret_cast< METAFILEPICT* >( aMetaFilePict.getArray( ) );
+
+ OSL_ASSERT( pMFPict );
+ OSL_ASSERT( !IsBadReadPtr( pMFPict, sizeof( METAFILEPICT ) ) );
+
+ sal_uInt32 nCount = GetMetaFileBitsEx( pMFPict->hMF, 0, NULL );
+ Sequence< sal_Int8 > mfpictStream( nCount + sizeof( METAFILEHEADER ) );
+
+ METAFILEHEADER* pMFHeader = (METAFILEHEADER*)mfpictStream.getArray( );
+ SMALL_RECT aRect = { 0,
+ 0,
+ static_cast< short >( pMFPict->xExt ),
+ static_cast< short >( pMFPict->yExt ) };
+ USHORT nInch;
+
+ switch( pMFPict->mm )
+ {
+ case MM_TEXT:
+ nInch = 72;
+ break;
+
+ case MM_LOMETRIC:
+ nInch = 100;
+ break;
+
+ case MM_HIMETRIC:
+ nInch = 1000;
+ break;
+
+ case MM_LOENGLISH:
+ nInch = 254;
+ break;
+
+ case MM_HIENGLISH:
+ case MM_ISOTROPIC:
+ case MM_ANISOTROPIC:
+ nInch = 2540;
+ break;
+
+ case MM_TWIPS:
+ nInch = 1440;
+ break;
+
+ default:
+ nInch = 576;
+ }
+
+ pMFHeader->key = 0x9AC6CDD7L;
+ pMFHeader->hmf = 0;
+ pMFHeader->bbox = aRect;
+ pMFHeader->inch = nInch;
+ pMFHeader->reserved = 0;
+ pMFHeader->checksum = 0;
+
+ char* pMFBuff = reinterpret_cast< char* >( mfpictStream.getArray( ) );
+
+ nCount = GetMetaFileBitsEx( pMFPict->hMF, nCount, pMFBuff + sizeof( METAFILEHEADER ) );
+ OSL_ASSERT( nCount );
+
+ return mfpictStream;
+}
+
+//------------------------------------------------------------------------
+// convert a openoffice metafile picture to a windows metafile picture
+//------------------------------------------------------------------------
+
+HMETAFILE SAL_CALL OOMFPictToWinMFPict( Sequence< sal_Int8 >& aOOMetaFilePict )
+{
+ OSL_ASSERT( aOOMetaFilePict.getLength( ) );
+
+ return SetMetaFileBitsEx( aOOMetaFilePict.getLength( ) - sizeof( METAFILEHEADER ),
+ reinterpret_cast< BYTE* >( aOOMetaFilePict.getArray( ) ) + sizeof( METAFILEHEADER ) );
+}
+
+//------------------------------------------------------------------------
+// convert a windows device independent bitmap into a openoffice bitmap
+//------------------------------------------------------------------------
+
+Sequence< sal_Int8 > SAL_CALL WinDIBToOOBMP( const Sequence< sal_Int8 >& aWinDIB )
+{
+ Sequence< sal_Int8 > ooBmpStream( aWinDIB.getLength( ) + sizeof(BITMAPFILEHEADER) );
+
+ const BITMAPINFOHEADER *pBmpInfoHdr = (const BITMAPINFOHEADER*)aWinDIB.getConstArray();
+ BITMAPFILEHEADER *pBmpFileHdr = (BITMAPFILEHEADER*)ooBmpStream.getArray();
+ DWORD nOffset = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER );
+
+ rtl_copyMemory( pBmpFileHdr + 1, pBmpInfoHdr, aWinDIB.getLength( ) );
+
+ if( pBmpInfoHdr->biBitCount <= 8 )
+ nOffset += ( pBmpInfoHdr->biClrUsed ? pBmpInfoHdr->biClrUsed : ( 1 << pBmpInfoHdr->biBitCount ) ) << 2;
+
+ pBmpFileHdr->bfType = 'MB';
+ pBmpFileHdr->bfSize = 0; // maybe: nMemSize + sizeof(BITMAPFILEHEADER)
+ pBmpFileHdr->bfReserved1 = 0;
+ pBmpFileHdr->bfReserved2 = 0;
+ pBmpFileHdr->bfOffBits = nOffset;
+
+ return ooBmpStream;
+}
+
+//------------------------------------------------------------------------
+// convert a openoffice bitmap into a windows device independent bitmap
+//------------------------------------------------------------------------
+
+Sequence< sal_Int8 > SAL_CALL OOBmpToWinDIB( Sequence< sal_Int8 >& aOOBmp )
+{
+ Sequence< sal_Int8 > winDIBStream( aOOBmp.getLength( ) - sizeof(BITMAPFILEHEADER) );
+
+ rtl_copyMemory( winDIBStream.getArray( ),
+ aOOBmp.getArray( ) + sizeof(BITMAPFILEHEADER),
+ aOOBmp.getLength( ) - sizeof(BITMAPFILEHEADER) );
+
+ return winDIBStream;
+} \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/FmtFilter.hxx b/dtrans/source/win32/dtobj/FmtFilter.hxx
new file mode 100644
index 000000000000..6b54f29586f2
--- /dev/null
+++ b/dtrans/source/win32/dtobj/FmtFilter.hxx
@@ -0,0 +1,102 @@
+/*************************************************************************
+ *
+ * $RCSfile: FmtFilter.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:53:57 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _FMTFILTER_HXX_
+#define _FMTFILTER_HXX_
+
+#ifndef _SAL_TYPES_H_
+#include <sal/types.h>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_
+#include <com/sun/star/uno/Sequence.hxx>
+#endif
+
+#include <windows.h>
+
+/*------------------------------------------------------------------------
+ input:
+ aMetaFilePict - a sequence of bytes containing a METAFILEPICT struct
+------------------------------------------------------------------------*/
+com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL WinMFPictToOOMFPict( com::sun::star::uno::Sequence< sal_Int8 >& aMetaFilePict );
+
+/*------------------------------------------------------------------------
+ input:
+ aByteStream - a sequence of bytes containing a openoffice metafile
+ picture with a leading METAFILEHEADER
+------------------------------------------------------------------------*/
+HMETAFILE SAL_CALL OOMFPictToWinMFPict( com::sun::star::uno::Sequence< sal_Int8 >& aOOMetaFilePict );
+
+/*------------------------------------------------------------------------
+ input:
+ aWinDIB - sequence of bytes containing a windows device independent
+ bitmap
+------------------------------------------------------------------------*/
+com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL WinDIBToOOBMP( const com::sun::star::uno::Sequence< sal_Int8 >& aWinDIB );
+
+/*------------------------------------------------------------------------
+ input:
+ aOOBmp - sequence of bytes containing a openoffice bitmap
+------------------------------------------------------------------------*/
+com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL OOBmpToWinDIB( com::sun::star::uno::Sequence< sal_Int8 >& aOOBmp );
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/MimeAttrib.hxx b/dtrans/source/win32/dtobj/MimeAttrib.hxx
new file mode 100644
index 000000000000..dc2e64501717
--- /dev/null
+++ b/dtrans/source/win32/dtobj/MimeAttrib.hxx
@@ -0,0 +1,86 @@
+/*************************************************************************
+ *
+ * $RCSfile: MimeAttrib.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:51:36 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _MIMEATTRIB_HXX_
+#define _MIMEATTRIB_HXX_
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _RTL_USTRING_
+#include <rtl/ustring>
+#endif
+
+//------------------------------------------------------------------------
+// deklarations
+//------------------------------------------------------------------------
+
+const rtl::OUString TEXTPLAIN_PARAM_CHARSET = rtl::OUString::createFromAscii( "charset" );
+
+const rtl::OUString PRE_WINDOWS_CODEPAGE = rtl::OUString::createFromAscii( "windows-" );
+const rtl::OUString PRE_OEM_CODEPAGE = rtl::OUString::createFromAscii( "cp" );
+const rtl::OUString CHARSET_UTF16 = rtl::OUString::createFromAscii( "utf-16" );
+const rtl::OUString CHARSET_UNICODE = rtl::OUString::createFromAscii( "unicode" );
+
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/TxtCnvtHlp.cxx b/dtrans/source/win32/dtobj/TxtCnvtHlp.cxx
new file mode 100644
index 000000000000..6e3137bab979
--- /dev/null
+++ b/dtrans/source/win32/dtobj/TxtCnvtHlp.cxx
@@ -0,0 +1,222 @@
+/*************************************************************************
+ *
+ * $RCSfile: TxtCnvtHlp.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:54:52 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#ifndef _TXTCNVTHLP_HXX_
+#include "TxtCnvtHlp.hxx"
+#endif
+
+#ifndef _DTRANSHELPER_HXX_
+#include "DTransHelper.hxx"
+#endif
+
+#ifndef _IMPLHELPER_HXX_
+#include "..\misc\ImplHelper.hxx"
+#endif
+
+using namespace ::com::sun::star::datatransfer;
+using namespace ::com::sun::star::uno;
+
+//------------------------------------------------------------------
+// assuming a '\0' terminated string if no length specified
+//------------------------------------------------------------------
+
+inline
+int CalcBuffSizeForTextConversion( LPCSTR lpMultiByteString, int nLen = -1 )
+{
+ return ( MultiByteToWideChar( CP_ACP,
+ 0,
+ lpMultiByteString,
+ nLen,
+ NULL,
+ 0 ) * sizeof( sal_Unicode ) );
+}
+
+//------------------------------------------------------------------
+// assuming a '\0' terminated string if no length specified
+//------------------------------------------------------------------
+
+inline
+int CalcBuffSizeForTextConversion( LPCWSTR lpWideCharString, int nLen = -1 )
+{
+ return WideCharToMultiByte( CP_ACP,
+ 0,
+ lpWideCharString,
+ nLen,
+ NULL,
+ 0,
+ NULL,
+ NULL );
+}
+
+//------------------------------------------------------------------
+// converts text in one code page into unicode text
+// automatically calculates the necessary buffer size and allocates
+// the buffer
+//------------------------------------------------------------------
+
+int MultiByteToWideCharEx( UINT cp_src, LPCSTR lpMultiByteString,
+ CStgTransferHelper& refDTransHelper,
+ BOOL bEnsureTrailingZero )
+{
+ OSL_ASSERT( IsValidCodePage( cp_src ) );
+ OSL_ASSERT( NULL != lpMultiByteString );
+
+ // calculate the required buff size
+ int reqSize = CalcBuffSizeForTextConversion( lpMultiByteString );
+
+ if ( bEnsureTrailingZero )
+ reqSize += sizeof( sal_Unicode );
+
+ // initialize the data-transfer helper
+ refDTransHelper.init( reqSize );
+
+ // setup a global memory pointer
+ CRawHGlobalPtr ptrHGlob( refDTransHelper );
+
+ // do the converssion an return
+ return MultiByteToWideChar( cp_src,
+ 0,
+ lpMultiByteString,
+ -1,
+ static_cast< LPWSTR >( ptrHGlob.GetMemPtr( ) ),
+ ptrHGlob.MemSize( ) );
+}
+
+//------------------------------------------------------------------
+// converts unicode text into text of the specified code page
+// automatically calculates the necessary buffer size and allocates
+// the buffer
+//------------------------------------------------------------------
+
+int WideCharToMultiByteEx( UINT cp_dest, LPCWSTR lpWideCharString,
+ CStgTransferHelper& refDTransHelper,
+ BOOL bEnsureTrailingZero )
+{
+ OSL_ASSERT( IsValidCodePage( cp_dest ) );
+ OSL_ASSERT( NULL != lpWideCharString );
+
+ // calculate the required buff size
+ int reqSize = CalcBuffSizeForTextConversion( lpWideCharString );
+
+ if ( bEnsureTrailingZero )
+ reqSize += sizeof( sal_Int8 );
+
+ // initialize the data-transfer helper
+ refDTransHelper.init( reqSize );
+
+ // setup a global memory pointer
+ CRawHGlobalPtr ptrHGlob( refDTransHelper );
+
+ // do the converssion an return
+ return WideCharToMultiByte( cp_dest,
+ 0,
+ lpWideCharString,
+ -1,
+ static_cast< LPSTR >( ptrHGlob.GetMemPtr( ) ),
+ ptrHGlob.MemSize( ),
+ NULL,
+ NULL );
+}
+
+//------------------------------------------------------------------
+// iterates through a sequence of dataflavors in order to find
+// the first non unicode character set
+//------------------------------------------------------------------
+/*
+BOOL FindFirstTextDataFlavor( const Sequence< DataFlavor >& dflvList, DataFlavor& aTxtDFlv )
+{
+ sal_Int32 nDFlv = dflvList.getLength( );
+ sal_Bool bRet = sal_False;
+
+ for ( sal_Int32 i = 0; i < nDFlv; ++i )
+ {
+ if ( MimeIsTextPlainAnyCharset( dflvList[i].MimeType ) )
+ {
+ aTxtDFlv = dflvList[i];
+ bRet = sal_True;
+ break;
+ }
+ }
+
+ return bRet;
+}
+
+//------------------------------------------------------------------
+// given a list of dataflavors this function searches for the
+// best dataflavor used to be converted into the destination
+// dataflavor
+//------------------------------------------------------------------
+
+BOOL FindBestDataFlavorForTextConversion( const DataFlavor& destDFlv,
+ const Sequence< DataFlavor >& suppDFlv,
+ DataFlavor& bestDFlv )
+{
+ return FindFirstTextDataFlavor( suppDFlv, bestDFlv );
+}
+*/ \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/TxtCnvtHlp.hxx b/dtrans/source/win32/dtobj/TxtCnvtHlp.hxx
new file mode 100644
index 000000000000..04bebc691420
--- /dev/null
+++ b/dtrans/source/win32/dtobj/TxtCnvtHlp.hxx
@@ -0,0 +1,94 @@
+/*************************************************************************
+ *
+ * $RCSfile: TxtCnvtHlp.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:54:44 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _TXTCNVTHLP_HXX_
+#define _TXTCNVTHLP_HXX_
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_DATAFLAVOR_HPP_
+#include <com/sun/star/datatransfer/DataFlavor.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HPP_
+#include <com/sun/star/uno/Sequence.h>
+#endif
+
+#ifndef _DTRANSHELPER_HXX_
+#include "DTransHelper.hxx"
+#endif
+
+#include <windows.h>
+
+//------------------------------------------------------------------------
+// deklarations
+//------------------------------------------------------------------------
+
+int MultiByteToWideCharEx( UINT cp_src, LPCSTR lpMultiByteString, CStgTransferHelper& refDTransHelper, BOOL bEnsureTrailingZero = TRUE );
+int WideCharToMultiByteEx( UINT cp_dest, LPCWSTR lpWideCharString, CStgTransferHelper& refDTransHelper, BOOL bEnsureTrailingZero = TRUE );
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+BOOL FindBestDataFlavorForTextConversion( const ::com::sun::star::datatransfer::DataFlavor& dfDest,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor >& seqSupportedDF,
+ ::com::sun::star::datatransfer::DataFlavor& bestDF );
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/XTDataObject.cxx b/dtrans/source/win32/dtobj/XTDataObject.cxx
new file mode 100644
index 000000000000..d012bd72d4e1
--- /dev/null
+++ b/dtrans/source/win32/dtobj/XTDataObject.cxx
@@ -0,0 +1,705 @@
+/*************************************************************************
+ *
+ * $RCSfile: XTDataObject.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:53:22 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#ifndef _TWRAPPERDATAOBJECT_HXX_
+#include "XTDataObject.hxx"
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_DATAFLAVOR_HPP_
+#include <com/sun/star/datatransfer/dataflavor.hpp>
+#endif
+
+#ifndef _IMPLHELPER_HXX_
+#include "..\misc\ImplHelper.hxx"
+#endif
+
+#ifndef _DTRANSHELPER_HXX_
+#include "DTransHelper.hxx"
+#endif
+
+#ifndef _TXTCNVTHLP_HXX_
+#include "TxtCnvtHlp.hxx"
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARDEX_HPP_
+#include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
+#endif
+
+#ifndef _FMTFILTER_HXX_
+#include "FmtFilter.hxx"
+#endif
+
+#include <windows.h>
+#include <shlobj.h>
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using namespace com::sun::star::datatransfer;
+using namespace com::sun::star::datatransfer::clipboard;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace rtl;
+
+//------------------------------------------------------------------------
+// ctor
+//------------------------------------------------------------------------
+
+CXTDataObject::CXTDataObject( const Reference< XMultiServiceFactory >& aServiceManager,
+ const Reference< XTransferable >& aXTransferable ) :
+ m_nRefCnt( 0 ),
+ m_SrvMgr( aServiceManager ),
+ m_XTransferable( aXTransferable ),
+ m_DataFormatTranslator( aServiceManager ),
+ m_FormatRegistrar( m_SrvMgr, m_DataFormatTranslator )
+{
+ m_FormatRegistrar.RegisterFormats( m_XTransferable->getTransferDataFlavors( ),
+ m_FormatEtcContainer );
+}
+
+//------------------------------------------------------------------------
+// IUnknown->QueryInterface
+//------------------------------------------------------------------------
+
+STDMETHODIMP CXTDataObject::QueryInterface( REFIID iid, LPVOID* 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( )
+{
+ ULONG nRefCnt =
+ static_cast< ULONG >( InterlockedDecrement( &m_nRefCnt ) );
+
+ if ( 0 == nRefCnt )
+ delete this;
+
+ return nRefCnt;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool CXTDataObject::isRequestForLocale( LPFORMATETC lpFormatEtc ) const
+{
+ return ( CF_LOCALE == lpFormatEtc->cfFormat );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+DataFlavor SAL_CALL CXTDataObject::formatEtcToDataFlavor( const FORMATETC& aFormatEtc ) const
+{
+ return m_DataFormatTranslator.getDataFlavorFromFormatEtc( m_XTransferable, aFormatEtc );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+sal_Bool SAL_CALL CXTDataObject::isSynthesizeableFormat( LPFORMATETC lpFormatEtc ) const
+{
+ return ( (lpFormatEtc->cfFormat == CF_TEXT) ||
+ (lpFormatEtc->cfFormat == CF_OEMTEXT) ||
+ (lpFormatEtc->cfFormat == CF_UNICODETEXT) );
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+STDMETHODIMP CXTDataObject::GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium )
+{
+ if ( !(pFormatetc && pmedium) )
+ return E_INVALIDARG;
+
+ HRESULT hr = validateFormatEtc( pFormatetc );
+ if ( FAILED( hr ) )
+ return hr;
+
+ DataFlavor aFlavor;
+
+ try
+ {
+ if ( isRequestForLocale( pFormatetc ) )
+ {
+ if ( m_FormatRegistrar.hasSynthesizedLocale( ) )
+ {
+ LCID lcid = m_FormatRegistrar.getSynthesizedLocale( );
+ TransferDataToStorageAndSetupStgMedium( reinterpret_cast< sal_Int8* >( &lcid ),
+ *pFormatetc,
+ 0,
+ sizeof( LCID ),
+ *pmedium );
+ return S_OK;
+ }
+ else
+ return DV_E_FORMATETC;
+ }
+
+ aFlavor = formatEtcToDataFlavor( *pFormatetc );
+
+ if ( CF_UNICODETEXT == pFormatetc->cfFormat )
+ {
+ OUString aText;
+ m_XTransferable->getTransferData( aFlavor ) >>= aText;
+
+ sal_uInt32 nRequiredMemSize = aText.getLength( ) * sizeof( sal_Unicode ) + 1;
+ sal_uInt32 nBytesToTransfer = aText.getLength( ) * sizeof( sal_Unicode );
+ hr = TransferDataToStorageAndSetupStgMedium( reinterpret_cast< const sal_Int8* >( aText.getStr( ) ),
+ *pFormatetc,
+ nRequiredMemSize,
+ nBytesToTransfer,
+ *pmedium );
+ }
+ else
+ {
+ Sequence< sal_Int8 > clipDataStream;
+ m_XTransferable->getTransferData( aFlavor ) >>= clipDataStream;
+
+ sal_uInt32 nRequiredMemSize = 0;
+ if ( (CF_TEXT == pFormatetc->cfFormat) || (CF_OEMTEXT == pFormatetc->cfFormat) )
+ nRequiredMemSize = sizeof( sal_Int8 ) * clipDataStream.getLength( ) + 1;
+
+ // prepare data for transmision
+ if ( CF_DIB == pFormatetc->cfFormat )
+ {
+ clipDataStream = OOBmpToWinDIB( clipDataStream );
+ }
+
+ if ( CF_METAFILEPICT == pFormatetc->cfFormat )
+ {
+ HMETAFILE hMfPict = OOMFPictToWinMFPict( clipDataStream );
+ TransferDataToStorageAndSetupStgMedium( reinterpret_cast< sal_Int8* >( &hMfPict ),
+ *pFormatetc,
+ 0,
+ sizeof( HMETAFILE ),
+ *pmedium );
+ }
+ else
+ TransferDataToStorageAndSetupStgMedium( clipDataStream.getArray( ),
+ *pFormatetc,
+ nRequiredMemSize,
+ clipDataStream.getLength( ),
+ *pmedium );
+ }
+ }
+ catch(UnsupportedFlavorException&)
+ {
+ if ( isSynthesizeableFormat( pFormatetc ) )
+ {
+ /*
+ FORMATETC fetc;
+
+ synthesize format
+ if ( requested format is unicodetext ) // implies the transferable has really only text
+ {
+ fetc = m_DataFormatTranslator.getFormatEtcForClipformat( CF_TEXT );
+ aFlavor = formatEtcToDataFlavor( fetc );
+
+ get transfer data
+ convert transfer data to unicode text
+ transfer result to storage
+ }
+ else // implies the transferable has really only unicodetext
+ {
+ fetc = m_DataFormatTranslator.getFormatEtcForClipformat( CF_UNICODETEXT );
+ aFlavor = formatEtcToDataFlavor( fetc );
+
+ get transfer data
+ if ( request is for ansi text )
+ convert transfer data to text using the CP_ACP
+ else
+ convert transfer data to oemtext using CP_OEMCP
+
+ transfer result to storage
+ }
+
+ transfer data to storage
+ */
+
+ return S_OK;
+ }
+
+ return DV_E_FORMATETC;
+ }
+ catch(COutOfMemoryException&)
+ {
+ return STG_E_MEDIUMFULL;
+ }
+ catch(...)
+ {
+ return E_UNEXPECTED;
+ }
+
+ return S_OK;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+HRESULT SAL_CALL CXTDataObject::TransferDataToStorageAndSetupStgMedium( const sal_Int8* lpStorage,
+ const FORMATETC& fetc,
+ sal_uInt32 nInitStgSize,
+ sal_uInt32 nBytesToTransfer,
+ STGMEDIUM& stgmedium )
+{
+ HRESULT hr = S_OK;
+
+ if ( isValidTymedForClipformat( fetc ) )
+ {
+ // if the client wants the data only via IStream we setup the storage transfer
+ // helper so that the stream will not be released on destruction
+ sal_Bool bShouldReleaseStream =
+ ( (fetc.tymed & TYMED_ISTREAM) && !(fetc.tymed & TYMED_HGLOBAL) );
+ CStgTransferHelper stgTransfHelper( AUTO_INIT,
+ NULL,
+ sal_False,
+ bShouldReleaseStream );
+
+ // setup storage size
+ if ( nInitStgSize > 0 )
+ stgTransfHelper.init( nInitStgSize,
+ GMEM_MOVEABLE | GMEM_ZEROINIT,
+ sal_False,
+ bShouldReleaseStream );
+
+ sal_Bool bResult = stgTransfHelper.write( lpStorage, nBytesToTransfer );
+
+ setupStgMedium( bResult, fetc, stgTransfHelper, stgmedium );
+ if ( !bResult )
+ hr = E_UNEXPECTED;
+ }
+ else
+ hr = DV_E_FORMATETC;
+
+ return hr;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->EnumFormatEtc
+//------------------------------------------------------------------------
+
+STDMETHODIMP CXTDataObject::EnumFormatEtc( DWORD dwDirection,
+ IEnumFORMATETC** ppenumFormatetc )
+{
+ if ( ( NULL == ppenumFormatetc ) || ( DATADIR_SET == dwDirection ) )
+ return E_INVALIDARG;
+
+ *ppenumFormatetc = NULL;
+
+ if ( DATADIR_GET == dwDirection )
+ {
+ *ppenumFormatetc = new CEnumFormatEtc( this, m_FormatEtcContainer );
+ if ( NULL != *ppenumFormatetc )
+ static_cast< LPUNKNOWN >( *ppenumFormatetc )->AddRef( );
+ }
+
+ return ( NULL != *ppenumFormatetc ) ? S_OK : E_OUTOFMEMORY;
+}
+
+//------------------------------------------------------------------------
+// IDataObject->QueryGetData
+//------------------------------------------------------------------------
+
+STDMETHODIMP CXTDataObject::QueryGetData( LPFORMATETC pFormatetc )
+{
+ if ( NULL == pFormatetc )
+ return E_INVALIDARG;
+
+ return m_FormatEtcContainer.hasFormatEtc( *pFormatetc ) ? S_OK : S_FALSE;
+}
+
+//------------------------------------------------------------------------
+// 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;
+}
+
+//------------------------------------------------------------------------
+// for our convenience
+//------------------------------------------------------------------------
+
+CXTDataObject::operator IDataObject*( )
+{
+ return static_cast< IDataObject* >( this );
+}
+
+//------------------------------------------------------------------------
+// aks for the total size of all available and renderable clipboard
+// formats
+//------------------------------------------------------------------------
+
+sal_Int64 SAL_CALL CXTDataObject::QueryDataSize( )
+{
+ return 0;
+}
+
+//------------------------------------------------------------------------
+// in preparation of clipboard flushing transfer all data from remote
+// to here
+//------------------------------------------------------------------------
+
+void SAL_CALL CXTDataObject::GetAllDataFromSource( )
+{
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+STDMETHODIMP CXTDataObject::validateFormatEtc( LPFORMATETC lpFormatEtc ) const
+{
+ OSL_ASSERT( lpFormatEtc );
+
+ if ( lpFormatEtc->lindex != -1 )
+ return DV_E_LINDEX;
+
+ if ( (lpFormatEtc->dwAspect != DVASPECT_CONTENT) ||
+ (lpFormatEtc->dwAspect != DVASPECT_COPY) ||
+ (lpFormatEtc->dwAspect != DVASPECT_LINK) ||
+ (lpFormatEtc->dwAspect != DVASPECT_SHORTNAME) )
+ return DV_E_DVASPECT;
+
+ if ( (lpFormatEtc->tymed != TYMED_HGLOBAL) ||
+ (lpFormatEtc->tymed != TYMED_ISTREAM) ||
+ (lpFormatEtc->tymed != TYMED_MFPICT) ||
+ (lpFormatEtc->tymed != TYMED_ENHMF) )
+ return DV_E_TYMED;
+
+ return S_OK;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+void SAL_CALL CXTDataObject::setupStgMedium( sal_Bool bTransferSuccessful,
+ const FORMATETC& fetc,
+ CStgTransferHelper& stgTransHlp,
+ STGMEDIUM& stgmedium )
+{
+ stgmedium.pUnkForRelease = NULL;
+
+ if ( bTransferSuccessful )
+ {
+ if ( fetc.tymed & TYMED_MFPICT )
+ {
+ stgmedium.tymed = TYMED_MFPICT;
+ stgmedium.hMetaFilePict = static_cast< HMETAFILEPICT >( stgTransHlp.getHGlobal( ) );
+ }
+ else if ( fetc.tymed & TYMED_ENHMF )
+ {
+ stgmedium.tymed = TYMED_ENHMF;
+ stgmedium.hEnhMetaFile = static_cast< HENHMETAFILE >( stgTransHlp.getHGlobal( ) );
+ }
+ else if ( fetc.tymed & TYMED_HGLOBAL )
+ {
+ stgmedium.tymed = TYMED_HGLOBAL;
+ stgmedium.hGlobal = stgTransHlp.getHGlobal( );
+ }
+ else if ( fetc.tymed & TYMED_ISTREAM )
+ {
+ stgmedium.tymed = TYMED_ISTREAM;
+ stgTransHlp.getIStream( &stgmedium.pstm );
+ }
+ else
+ OSL_ASSERT( sal_False );
+ }
+ else
+ stgmedium.tymed = TYMED_NULL;
+}
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+inline
+sal_Bool SAL_CALL CXTDataObject::isValidTymedForClipformat( const FORMATETC& fetc ) const
+{
+ if ( fetc.cfFormat == CF_METAFILEPICT && !(fetc.tymed & TYMED_MFPICT) )
+ return sal_False;
+
+ if ( fetc.cfFormat == CF_ENHMETAFILE && !(fetc.tymed & TYMED_ENHMF) )
+ return sal_False;
+
+ if ( !(fetc.tymed & TYMED_HGLOBAL) ||
+ !(fetc.tymed & TYMED_ISTREAM) )
+ return sal_False;
+
+ return sal_True;
+}
+
+//============================================================================
+// CEnumFormatEtc
+//============================================================================
+
+//----------------------------------------------------------------------------
+// ctor
+//----------------------------------------------------------------------------
+
+CEnumFormatEtc::CEnumFormatEtc( LPUNKNOWN lpUnkOuter, const CFormatEtcContainer& aFormatEtcContainer ) :
+ m_nRefCnt( 0 ),
+ m_lpUnkOuter( lpUnkOuter ),
+ m_FormatEtcContainer( aFormatEtcContainer )
+{
+}
+
+//----------------------------------------------------------------------------
+// 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_lpUnkOuter->AddRef( );
+ return InterlockedIncrement( &m_nRefCnt );
+}
+
+//----------------------------------------------------------------------------
+// IUnknown->Release
+//----------------------------------------------------------------------------
+
+STDMETHODIMP_(ULONG) CEnumFormatEtc::Release( )
+{
+ // release the outer dataobject
+ m_lpUnkOuter->Release( );
+
+ ULONG nRefCnt = InterlockedDecrement( &m_nRefCnt );
+ if ( 0 == nRefCnt )
+ delete this;
+
+ return nRefCnt;
+}
+
+//----------------------------------------------------------------------------
+// IEnumFORMATETC->Next
+//----------------------------------------------------------------------------
+
+STDMETHODIMP CEnumFormatEtc::Next( ULONG nRequested, LPFORMATETC lpDest, ULONG* lpFetched )
+{
+ if ( (( 0 != nRequested ) && ( NULL == lpDest )) ||
+ IsBadWritePtr( lpDest, sizeof( FORMATETC ) * nRequested ) )
+ return E_INVALIDARG;
+
+ sal_uInt32 nFetched = m_FormatEtcContainer.nextFormatEtc( lpDest, nRequested );
+
+ if ( lpFetched )
+ *lpFetched = nFetched;
+
+ return nFetched == nRequested ? S_OK : S_FALSE;
+}
+
+//----------------------------------------------------------------------------
+// IEnumFORMATETC->Skip
+//----------------------------------------------------------------------------
+
+STDMETHODIMP CEnumFormatEtc::Skip( ULONG celt )
+{
+ return m_FormatEtcContainer.skipFormatEtc( celt ) ? S_OK : S_FALSE;
+}
+
+//----------------------------------------------------------------------------
+// IEnumFORMATETC->Reset
+//----------------------------------------------------------------------------
+
+STDMETHODIMP CEnumFormatEtc::Reset( )
+{
+ m_FormatEtcContainer.beginEnumFormatEtc( );
+ return S_OK;
+}
+
+//----------------------------------------------------------------------------
+// IEnumFORMATETC->Clone
+//----------------------------------------------------------------------------
+
+STDMETHODIMP CEnumFormatEtc::Clone( IEnumFORMATETC** ppenum )
+{
+ if ( NULL == ppenum )
+ return E_INVALIDARG;
+
+ *ppenum = NULL;
+
+ CEnumFormatEtc* pCEnumFEtc =
+ new CEnumFormatEtc( m_lpUnkOuter, m_FormatEtcContainer );
+ if ( NULL != pCEnumFEtc )
+ {
+ *ppenum = static_cast< IEnumFORMATETC* >( pCEnumFEtc );
+ static_cast< LPUNKNOWN >( *ppenum )->AddRef( );
+ }
+
+ return ( NULL != *ppenum ) ? S_OK : E_OUTOFMEMORY;
+}
diff --git a/dtrans/source/win32/dtobj/XTDataObject.hxx b/dtrans/source/win32/dtobj/XTDataObject.hxx
new file mode 100644
index 000000000000..ad79d670717c
--- /dev/null
+++ b/dtrans/source/win32/dtobj/XTDataObject.hxx
@@ -0,0 +1,210 @@
+/*************************************************************************
+ *
+ * $RCSfile: XTDataObject.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: tra $ $Date: 2001-02-27 07:53:16 $
+ *
+ * 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES 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 _XTDATAOBJECT_HXX_
+#define _XTDATAOBJECT_HXX_
+
+
+//------------------------------------------------------------------------
+// includes
+//------------------------------------------------------------------------
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
+#include <com/sun/star/datatransfer/XTransferable.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARDOWNER_HPP_
+#include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
+#endif
+
+#ifndef _DATAFORMATTRANSLATOR_HXX_
+#include "DataFmtTransl.hxx"
+#endif
+
+#ifndef _FETCLIST_HXX_
+#include "FEtcList.hxx"
+#endif
+
+#include <windows.h>
+#include <ole2.h>
+#include <objidl.h>
+
+/*--------------------------------------------------------------------------
+ - 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 an so can be placed on the
+ OleClipboard. The class wrapps a transferable object which is the
+ original DataSource
+ - DataFlavors offerd 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 automaticaly converted between text und unicode text
+ - although the transferable may support text in different charsets
+ (codepages) only text in one codepage can be offered by the clipboard
+
+----------------------------------------------------------------------------*/
+
+class CStgTransferHelper;
+
+class CXTDataObject : public IDataObject
+{
+public:
+ CXTDataObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& aXTransferable );
+
+ //-----------------------------------------------------------------
+ // 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*( );
+
+ sal_Int64 SAL_CALL QueryDataSize( );
+
+ // retrieve the data from the source
+ // necessary so that we have all data
+ // when we flush the clipboard
+ void SAL_CALL GetAllDataFromSource( );
+
+ // sometimes we need to lock objects of this
+ // class for instance during clipboard shutdown
+ // it should not be possible to do specific
+ // things etc.
+ //Lock( );
+ //Unlock( );
+
+private:
+ STDMETHODIMP validateFormatEtc( LPFORMATETC lpFormatEtc ) const;
+ sal_Bool SAL_CALL isRequestForLocale( LPFORMATETC lpFormatEtc ) const;
+ com::sun::star::datatransfer::DataFlavor SAL_CALL formatEtcToDataFlavor( const FORMATETC& aFormatEtc ) const;
+ sal_Bool SAL_CALL isSynthesizeableFormat( LPFORMATETC lpFormatEtc ) const;
+ HRESULT SAL_CALL TransferDataToStorageAndSetupStgMedium( const sal_Int8* lpStorage,
+ const FORMATETC& fetc,
+ sal_uInt32 nInitStgSize,
+ sal_uInt32 nBytesToTransfer,
+ STGMEDIUM& stgmedium );
+
+ void SAL_CALL setupStgMedium( sal_Bool bTransferSuccessful,
+ const FORMATETC& fetc,
+ CStgTransferHelper& stgTransHlp,
+ STGMEDIUM& stgmedium );
+
+ sal_Bool SAL_CALL isValidTymedForClipformat( const FORMATETC& fetc ) const;
+
+private:
+ LONG m_nRefCnt;
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_SrvMgr;
+ ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > m_XTransferable;
+ CFormatEtcContainer m_FormatEtcContainer;
+ CDataFormatTranslator m_DataFormatTranslator;
+ CFormatRegistrar m_FormatRegistrar;
+};
+
+//------------------------------------------------------------------------
+//
+//------------------------------------------------------------------------
+
+class CEnumFormatEtc : public IEnumFORMATETC
+{
+public:
+ CEnumFormatEtc( LPUNKNOWN lpUnkOuter, const CFormatEtcContainer& aFormatEtcContainer );
+
+ // IUnknown
+ STDMETHODIMP QueryInterface( REFIID iid, LPVOID* ppvObject );
+ STDMETHODIMP_( ULONG ) AddRef( );
+ STDMETHODIMP_( ULONG ) Release( );
+
+ //IEnumFORMATETC
+ STDMETHODIMP Next( ULONG nRequested, LPFORMATETC lpDest, ULONG* lpFetched );
+ STDMETHODIMP Skip( ULONG celt );
+ STDMETHODIMP Reset( );
+ STDMETHODIMP Clone( IEnumFORMATETC** ppenum );
+
+private:
+ LONG m_nRefCnt;
+ LPUNKNOWN m_lpUnkOuter;
+ CFormatEtcContainer m_FormatEtcContainer;
+};
+
+typedef CEnumFormatEtc *PCEnumFormatEtc;
+
+#endif \ No newline at end of file
diff --git a/dtrans/source/win32/dtobj/makefile.mk b/dtrans/source/win32/dtobj/makefile.mk
new file mode 100644
index 000000000000..d070d2d77b85
--- /dev/null
+++ b/dtrans/source/win32/dtobj/makefile.mk
@@ -0,0 +1,95 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1 $
+#
+# last change: $Author: tra $ $Date: 2001-02-27 07:52:58 $
+#
+# 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 WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES 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=dtobjfact
+ENABLE_EXCEPTIONS=TRUE
+LIBTARGET=NO
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+# ------------------------------------------------------------------
+
+.INCLUDE : ..$/..$/cppumaker.mk
+
+#CFLAGS+=/GR -DUNICODE -D_UNICODE
+
+SLOFILES=$(SLO)$/DtObjFactory.obj\
+ $(SLO)$/APNDataObject.obj\
+ $(SLO)$/DOTransferable.obj\
+ $(SLO)$/DTransHelper.obj\
+ $(SLO)$/XTDataObject.obj\
+ $(SLO)$/TxtCnvtHlp.obj\
+ $(SLO)$/DataFmtTransl.obj\
+ $(SLO)$/FmtFilter.obj\
+ $(SLO)$/FetcList.obj
+
+LIB1TARGET=$(SLB)$/$(TARGET).lib
+LIB1OBJFILES=$(SLOFILES)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk