Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dtrans / test / win32 / dnd / dndTest.cxx
blobb9f1d841e1c5eb715a584dd4e179aeac3f2b9dcd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #if defined _MSC_VER
21 #pragma warning(push,1)
22 #endif
23 #include <windows.h>
24 #include <comdef.h>
25 #include <atlbase.h>
26 CComModule _Module;
27 #include <atlcom.h>
28 #include <atlimpl.cpp>
29 #if defined _MSC_VER
30 #pragma warning(pop)
31 #endif
32 #include <com/sun/star/uno/Reference.h>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
35 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <rtl/process.h>
38 #include <cppuhelper/servicefactory.hxx>
39 #include "sourcelistener.hxx"
41 #include "atlwindow.hxx"
42 BEGIN_OBJECT_MAP(ObjectMap)
43 END_OBJECT_MAP()
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::datatransfer;
47 using namespace com::sun::star::uno;
48 using namespace com::sun::star::datatransfer::dnd;
49 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
51 HRESULT doTest();
52 DWORD WINAPI MTAFunc( void* threadData);
54 Reference< XMultiServiceFactory > MultiServiceFactory;
56 int main( int argc, char *argv[ ], char *envp[ ] )
58 HRESULT hr;
59 if( FAILED( hr=CoInitialize(NULL )))
61 printf("CoInitialize failed \n");
62 return -1;
65 _Module.Init( ObjectMap, GetModuleHandleA( NULL));
67 if( FAILED(hr=doTest()))
69 _com_error err( hr);
72 _Module.Term();
73 CoUninitialize();
74 return 0;
77 HRESULT doTest()
80 MultiServiceFactory= createRegistryServiceFactory( OUString(L"types.rdb"), OUString( L"services.rdb") , sal_True);
82 // create the MTA thread that is used to realize MTA calls to the services
83 // We create the thread and wait until the thread has created its message queue
84 HANDLE evt= CreateEventA(NULL, FALSE, FALSE, NULL);
85 DWORD threadIdMTA=0;
86 HANDLE hMTAThread= CreateThread( NULL, 0, MTAFunc, &evt, 0, &threadIdMTA);
87 WaitForSingleObject( evt, INFINITE);
88 CloseHandle(evt);
90 HRESULT hr= S_OK;
91 RECT pos1={0,0,300,200};
92 AWindow win("DnD starting in Ole STA", threadIdMTA, pos1);
94 RECT pos2={ 0, 205, 300, 405};
95 AWindow win2("DnD starting in MTA", threadIdMTA, pos2, true);
97 // win3 and win4 call initialize from an MTA but they are created in an STA
98 RECT pos3={300,0,600,200};
99 AWindow win3("DnD starting in OLE STA", threadIdMTA, pos3, false, true);
101 RECT pos4={ 300, 205, 600, 405};
102 AWindow win24("DnD starting in Ole MTA", threadIdMTA, pos4, true, true);
104 MSG msg;
105 while( GetMessageA(&msg, (HWND)NULL, 0, 0) )
107 TranslateMessage( &msg);
108 DispatchMessageA( &msg);
111 // Shut down the MTA thread
112 PostThreadMessageA( threadIdMTA, WM_QUIT, 0, 0);
113 WaitForSingleObject(hMTAThread, INFINITE);
114 CloseHandle(hMTAThread);
116 return S_OK;
119 extern Reference<XMultiServiceFactory> MultiServiceFactory;
120 DWORD WINAPI MTAFunc( void* threadData)
122 HRESULT hr= CoInitializeEx( NULL, COINIT_MULTITHREADED);
123 ATLASSERT( FAILED(hr) );
124 MSG msg;
125 // force the creation of a message queue
126 PeekMessageA(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
127 SetEvent( *(HANDLE*)threadData );
129 RECT pos={0, 406, 300, 605};
130 AWindow win("DnD, full MTA", GetCurrentThreadId(), pos, false, true);
132 while( GetMessageA(&msg, (HWND)NULL, 0, 0) )
134 switch( msg.message)
136 case WM_SOURCE_INIT:
138 InitializationData* pData= (InitializationData*)msg.wParam;
139 Any any;
140 any <<= (sal_uInt32) pData->hWnd;
141 pData->xInit->initialize( Sequence<Any>( &any, 1));
143 CoTaskMemFree( pData);
144 break;
146 case WM_SOURCE_STARTDRAG:
148 // wParam contains necessary data
149 StartDragData* pData= (StartDragData*)msg.wParam;
150 Sequence<DataFlavor> seq= pData->transferable->getTransferDataFlavors();
151 // have a look what flavours are supported
152 for( int i=0; i<seq.getLength(); i++)
154 DataFlavor d= seq[i];
156 pData->source->startDrag( DragGestureEvent(),
157 ACTION_LINK|ACTION_MOVE|ACTION_COPY,
160 pData->transferable,
161 Reference<XDragSourceListener>( static_cast<XDragSourceListener*>
162 ( new DragSourceListener())));
163 CoTaskMemFree( pData);
164 break;
167 } // end switch
169 TranslateMessage( &msg);
170 DispatchMessageA( &msg);
173 CoUninitialize();
174 return 0;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */