diff options
Diffstat (limited to 'dtrans/test/win32/dnd/atlwindow.cxx')
-rw-r--r-- | dtrans/test/win32/dnd/atlwindow.cxx | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/dtrans/test/win32/dnd/atlwindow.cxx b/dtrans/test/win32/dnd/atlwindow.cxx index 5d5812f7b25c..c24c87d56019 100644 --- a/dtrans/test/win32/dnd/atlwindow.cxx +++ b/dtrans/test/win32/dnd/atlwindow.cxx @@ -2,9 +2,9 @@ * * $RCSfile: atlwindow.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: jl $ $Date: 2001-03-30 15:37:32 $ + * last change: $Author: jl $ $Date: 2001-07-19 11:14:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,6 +72,7 @@ #include "targetlistener.hxx" #include "sourcelistener.hxx" //#include "transferable.hxx" +#include "dataobject.hxx" #include <map> #include <winbase.h> @@ -146,7 +147,8 @@ LRESULT AWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle // create the DragSource - Reference< XInterface> xint= MultiServiceFactory->createInstance(OUString(L"com.sun.star.datatransfer.dnd.OleDragSource")); + OUString sServiceSource( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.datatransfer.dnd.OleDragSource")); + Reference< XInterface> xint= MultiServiceFactory->createInstance(sServiceSource); m_xDragSource= Reference<XDragSource>( xint, UNO_QUERY); Reference<XInitialization> xInit( xint, UNO_QUERY); @@ -155,18 +157,33 @@ LRESULT AWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle xInit->initialize( Sequence<Any>( ar, 2) ); //create the DropTarget + // the initialization func of the drop target can be called from an STA or + // MTA Reference< XInterface> xintTarget= MultiServiceFactory->createInstance(OUString(L"com.sun.star.datatransfer.dnd.OleDropTarget")); m_xDropTarget= Reference<XDropTarget>( xintTarget, UNO_QUERY); Reference<XInitialization> xInitTarget( xintTarget, UNO_QUERY); - Any any; - any <<= (sal_uInt32)m_hWnd; - xInitTarget->initialize( Sequence<Any>( &any, 1) ); + // call Initialize from the mta thread + if( m_bInitInMTA) + { + InitializationData* pData= (InitializationData*) CoTaskMemAlloc(sizeof( InitializationData)); + ZeroMemory( pData, sizeof( InitializationData)); + pData->xInit= xInitTarget; + pData->hWnd= m_hWnd; + PostThreadMessage( m_idMTAThread, WM_SOURCE_INIT,(WPARAM) pData, 0); + } + else + { + // call initialize from the current thread + Any any; + any <<= (sal_uInt32)m_hWnd; + xInitTarget->initialize( Sequence<Any>( &any, 1) ); + } m_xDropTarget->addDropTargetListener( static_cast<XDropTargetListener*> ( new DropTargetListener( m_hwndEdit)) ); -// // make this window tho a drop target +// // make this window a drop target m_xDropTarget->setActive(sal_True); return 0; @@ -193,51 +210,36 @@ LRESULT AWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled HRESULT hr; USES_CONVERSION; KillTimer( 1); - if(m_xDragSource.is()) + // only if the dragsource exists and it is our own timer + if(m_xDragSource.is() && (UINT) wParam == 1) { //Get the Text out of the Edit window int length= (int)::SendMessageA( m_hwndEdit, WM_GETTEXTLENGTH, 0, 0); char * pBuffer= new char[length + 1]; ZeroMemory( pBuffer, length + 1); - ::SendMessageA( m_hwndEdit, WM_GETTEXT, length, (LPARAM) pBuffer); + ::SendMessageA( m_hwndEdit, WM_GETTEXT, length+1, (LPARAM) pBuffer); + + IDataObject* pData= (IDataObject*)new DataObject(pBuffer); + pData->AddRef(); - IDataObject* pData= NULL; - HRESULT hr= CreateDataCache( NULL, CLSID_NULL, __uuidof(IDataObject),(void**) &pData); if( pData) { - FORMATETC format={ CF_TEXT, NULL, DVASPECT_CONTENT, -1, }; - - HGLOBAL mem= GlobalAlloc(GHND, length + 1 ); - void* pMem= GlobalLock( mem); - memcpy( pMem, pBuffer, length+1); - GlobalUnlock( mem); +// CDTransObjFactory fac; +// Reference<XTransferable> xTrans= fac.createTransferableFromDataObj( +// MultiServiceFactory, pData); - STGMEDIUM medium; - medium.tymed= TYMED_HGLOBAL; - medium.hGlobal= mem; - medium.pUnkForRelease= NULL; - - pData->SetData( &format, &medium, TRUE); // releases HGLOBAL eventually - - Reference<XTransferable> xTrans= m_aDataConverter.createTransferableFromDataObj( - MultiServiceFactory, pData); + Reference<XTransferable> xTrans= m_aDataConverter.createTransferableFromDataObj( + MultiServiceFactory, pData); // call XDragSource::executeDrag from an MTA if( m_isMTA ) { - DWORD mtaThreadId; - ThreadData data; - data.source= m_xDragSource; - data.transferable= xTrans; - - data.evtThreadReady= CreateEvent( NULL, FALSE, FALSE, NULL); - - HANDLE hThread= CreateThread( NULL, 0, MTAFunc, &data, 0, &mtaThreadId); - // We must wait until the thread copied the ThreadData structure - WaitForSingleObject( data.evtThreadReady, INFINITE); - CloseHandle( data.evtThreadReady); - + StartDragData* pData= (StartDragData*) CoTaskMemAlloc(sizeof( StartDragData)); + ZeroMemory( pData, sizeof( StartDragData)); + pData->source= m_xDragSource; + pData->transferable= xTrans; + PostThreadMessage( m_idMTAThread, WM_SOURCE_STARTDRAG,(WPARAM) pData, 0); } else @@ -250,6 +252,8 @@ LRESULT AWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled Reference<XDragSourceListener>( static_cast<XDragSourceListener*>(new DragSourceListener() ) ) ); } } + if( pData) + pData->Release(); delete[] pBuffer; } @@ -290,4 +294,4 @@ LRESULT APIENTRY EditSubclassProc( HWND hwnd, UINT uMsg,WPARAM wParam, LPARAM lP return CallWindowProc( wpOrigEditProc, hwnd, uMsg, wParam, lParam); } -
\ No newline at end of file + |