summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dtrans/test/win32/dnd/atlwindow.cxx82
-rw-r--r--dtrans/test/win32/dnd/atlwindow.hxx31
-rw-r--r--dtrans/test/win32/dnd/dndTest.cxx98
-rw-r--r--dtrans/test/win32/dnd/makefile.mk13
-rw-r--r--dtrans/test/win32/dnd/targetlistener.cxx8
5 files changed, 157 insertions, 75 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
+
diff --git a/dtrans/test/win32/dnd/atlwindow.hxx b/dtrans/test/win32/dnd/atlwindow.hxx
index bfebf18e5add..2d664510b236 100644
--- a/dtrans/test/win32/dnd/atlwindow.hxx
+++ b/dtrans/test/win32/dnd/atlwindow.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: atlwindow.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * 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
@@ -64,6 +64,7 @@
extern CComModule _Module;
#include<atlcom.h>
#include<atlctl.h>
+#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
#include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp>
@@ -74,12 +75,21 @@ extern CComModule _Module;
using namespace com::sun::star::uno;
using namespace com::sun::star::datatransfer::dnd;
using namespace com::sun::star::datatransfer;
+using namespace com::sun::star::lang;
+#define WM_SOURCE_INIT WM_APP+100
+#define WM_SOURCE_STARTDRAG WM_APP+101
-struct ThreadData
+
+struct StartDragData
{
Reference<XDragSource> source;
Reference<XTransferable> transferable;
- HANDLE evtThreadReady;
+};
+
+struct InitializationData
+{
+ Reference<XInitialization> xInit;
+ HWND hWnd;
};
class AWindow: public CWindowImpl<AWindow, CWindow,
@@ -89,18 +99,21 @@ class AWindow: public CWindowImpl<AWindow, CWindow,
Reference<XDropTarget> m_xDropTarget;
Reference<XDragSource> m_xDragSource;
BOOL m_isMTA;
-
+ BOOL m_bInitInMTA;
HWND m_hwndEdit;
-
+ // Id of the MTA thread to which we post messages.
+ DWORD m_idMTAThread;
CDTransObjFactory m_aDataConverter;
public:
- AWindow(LPCTSTR strName)
+ AWindow(LPCTSTR strName, DWORD idMTAThread): m_idMTAThread( idMTAThread)
{
RECT rcPos= {0,0,200,200};
Create(0, rcPos, strName);
}
- AWindow(LPCTSTR strName, RECT pos, BOOL mta=FALSE): m_isMTA( mta)
+ AWindow(LPCTSTR strName, DWORD idMTAThread, RECT pos, BOOL mta=FALSE,
+ BOOL initInMTA=FALSE):
+ m_isMTA( mta), m_idMTAThread( idMTAThread), m_bInitInMTA( initInMTA)
{
Create(0, pos, strName);
}
@@ -131,4 +144,4 @@ public:
};
-#endif \ No newline at end of file
+#endif
diff --git a/dtrans/test/win32/dnd/dndTest.cxx b/dtrans/test/win32/dnd/dndTest.cxx
index 6dda3002f64b..505911a48793 100644
--- a/dtrans/test/win32/dnd/dndTest.cxx
+++ b/dtrans/test/win32/dnd/dndTest.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: dndTest.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
@@ -90,7 +90,13 @@ using namespace com::sun::star::datatransfer::dnd;
using namespace com::sun::star::datatransfer::dnd::DNDConstants;
using namespace rtl;
+// defined in atlwindow.hxx
+// #define WM_SOURCE_INIT WM_APP+100
+// #define WM_SOURCE_STARTDRAG WM_APP+101
+#define WM_CREATE_MTA_WND
+
HRESULT doTest();
+DWORD WINAPI MTAFunc( void* threadData);
Reference< XMultiServiceFactory > MultiServiceFactory;
//int APIENTRY WinMain(HINSTANCE hInstance,
@@ -123,19 +129,34 @@ int main( int argc, char *argv[ ], char *envp[ ] )
return 0;
}
-
-
HRESULT doTest()
{
MultiServiceFactory= createRegistryServiceFactory( OUString(L"applicat.rdb"));
+ // create the MTA thread that is used to realize MTA calls to the services
+ // We create the thread and wait until the thread has created its message queue
+ HANDLE evt= CreateEvent(NULL, FALSE, FALSE, NULL);
+ DWORD threadIdMTA=0;
+ HANDLE hMTAThread= CreateThread( NULL, 0, MTAFunc, &evt, 0, &threadIdMTA);
+ WaitForSingleObject( evt, INFINITE);
+ CloseHandle(evt);
+
+
HRESULT hr= S_OK;
RECT pos1={0,0,300,200};
- AWindow win(_T("Drag and Drop, OLE STA"), pos1);
+ AWindow win(_T("DnD starting in Ole STA"), threadIdMTA, pos1);
RECT pos2={ 0, 205, 300, 405};
- AWindow win2( _T("Drag and Drop, MTA"), pos2, true);
+ AWindow win2( _T("DnD starting in MTA"), threadIdMTA, pos2, true);
+
+ // win3 and win4 call initialize from an MTA but they are created in an STA
+ RECT pos3={300,0,600,200};
+ AWindow win3(_T("DnD starting in OLE STA"), threadIdMTA, pos3, false, true);
+
+ RECT pos4={ 300, 205, 600, 405};
+ AWindow win24( _T("DnD starting in Ole MTA"), threadIdMTA, pos4, true, true);
+
MSG msg;
while( GetMessage(&msg, (HWND)NULL, 0, 0) )
@@ -144,26 +165,69 @@ HRESULT doTest()
DispatchMessage( &msg);
}
+ // Shut down the MTA thread
+ PostThreadMessage( threadIdMTA, WM_QUIT, 0, 0);
+ WaitForSingleObject(hMTAThread, INFINITE);
+ CloseHandle(hMTAThread);
+
return S_OK;
}
extern Reference<XMultiServiceFactory> MultiServiceFactory;
-DWORD WINAPI MTAFunc(LPVOID pParams)
+DWORD WINAPI MTAFunc( void* threadData)
{
HRESULT hr= S_OK;
hr= CoInitializeEx( NULL, COINIT_MULTITHREADED);
ATLASSERT( FAILED(hr) );
+ MSG msg;
+ // force the creation of a message queue
+ PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+ SetEvent( *(HANDLE*)threadData );
+
+ RECT pos={0, 406, 300, 605};
+ AWindow win(_T("DnD, full MTA"), GetCurrentThreadId(), pos, false, true);
+// ThreadData data= *( ThreadData*)pParams;
+// SetEvent(data.evtThreadReady);
+ while( GetMessage(&msg, (HWND)NULL, 0, 0) )
+ {
+ switch( msg.message)
+ {
+ case WM_SOURCE_INIT:
+ {
+ InitializationData* pData= (InitializationData*)msg.wParam;
+ Any any;
+ any <<= (sal_uInt32) pData->hWnd;
+ pData->xInit->initialize( Sequence<Any>( &any, 1));
+
+ CoTaskMemFree( pData);
+ break;
+ }
+ case WM_SOURCE_STARTDRAG:
+ {
+ // wParam contains necessary data
+ StartDragData* pData= (StartDragData*)msg.wParam;
+ Sequence<DataFlavor> seq= pData->transferable->getTransferDataFlavors();
+ // have a look what flavours are supported
+ for( int i=0; i<seq.getLength(); i++)
+ {
+ DataFlavor d= seq[i];
+ }
+ pData->source->startDrag( DragGestureEvent(),
+ ACTION_LINK|ACTION_MOVE|ACTION_COPY,
+ 0,
+ 0,
+ pData->transferable,
+ Reference<XDragSourceListener>( static_cast<XDragSourceListener*>
+ ( new DragSourceListener())));
+ CoTaskMemFree( pData);
+ break;
+ }
+
+ } // end switch
- ThreadData data= *( ThreadData*)pParams;
- SetEvent(data.evtThreadReady);
-
- data.source->startDrag( DragGestureEvent(),
- ACTION_LINK|ACTION_MOVE|ACTION_COPY,
- 0,
- 0,
- data.transferable,
- Reference<XDragSourceListener>( static_cast<XDragSourceListener*>
- ( new DragSourceListener())));
+ TranslateMessage( &msg);
+ DispatchMessage( &msg);
+ }
CoUninitialize();
diff --git a/dtrans/test/win32/dnd/makefile.mk b/dtrans/test/win32/dnd/makefile.mk
index f1b2c18670fb..ba8193b158c9 100644
--- a/dtrans/test/win32/dnd/makefile.mk
+++ b/dtrans/test/win32/dnd/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.5 $
+# $Revision: 1.6 $
#
-# 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
@@ -111,9 +111,10 @@ APP1NOSAL=TRUE
APP1TARGET= $(TARGET)
APP1OBJS= $(OBJ)$/dndTest.obj \
- $(OBJ)$/atlwindow.obj \
- $(OBJ)$/targetlistener.obj \
- $(OBJ)$/sourcelistener.obj
+ $(OBJ)$/atlwindow.obj \
+ $(OBJ)$/targetlistener.obj \
+ $(OBJ)$/sourcelistener.obj \
+ $(OBJ)$/dataobject.obj
LIBCIMT=msvcrtd.lib
@@ -130,12 +131,12 @@ APP1STDLIBS= \
uuid.lib
APP1LIBS= \
- $(SOLARLIBDIR)$/imtaolecb.lib\
$(SOLARLIBDIR)$/user9x.lib\
$(SOLARLIBDIR)$/tools32.lib\
$(SLB)$/dtobjfact.lib \
$(SLB)$/dtutils.lib
+# $(SOLARLIBDIR)$/imtaolecb.lib\
diff --git a/dtrans/test/win32/dnd/targetlistener.cxx b/dtrans/test/win32/dnd/targetlistener.cxx
index 653c386d5592..8959653d8cb7 100644
--- a/dtrans/test/win32/dnd/targetlistener.cxx
+++ b/dtrans/test/win32/dnd/targetlistener.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: targetlistener.cxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: jl $ $Date: 2001-02-12 13:14:36 $
+ * 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
@@ -124,8 +124,8 @@ void SAL_CALL DropTargetListener::dragExit( const DropTargetEvent& dte )
void SAL_CALL DropTargetListener::dragOver( const DropTargetDragEvent& dtde )
throw(RuntimeException)
{
- if( !(dtde.SourceActions & dtde.DropAction) )
- dtde.Context->acceptDrag( ACTION_COPY);
+// if( (dtde.SourceActions & dtde.DropAction) )
+// dtde.Context->acceptDrag( ACTION_COPY);
}
void SAL_CALL DropTargetListener::dropActionChanged( const DropTargetDragEvent& dtde )