fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / test / win32 / dnd / dndTest.cxx
blobd0261324a89bc063e4f64764aad38a111f5fdba7
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 <tchar.h>
26 #include <atlbase.h>
27 CComModule _Module;
28 #include <atlcom.h>
29 #include <atlimpl.cpp>
30 #if defined _MSC_VER
31 #pragma warning(pop)
32 #endif
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
36 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <rtl/process.h>
39 #include <cppuhelper/servicefactory.hxx>
40 #include "sourcelistener.hxx"
42 #include "atlwindow.hxx"
43 BEGIN_OBJECT_MAP(ObjectMap)
44 END_OBJECT_MAP()
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::datatransfer;
48 using namespace com::sun::star::uno;
49 using namespace com::sun::star::datatransfer::dnd;
50 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
52 #define WM_CREATE_MTA_WND
54 HRESULT doTest();
55 DWORD WINAPI MTAFunc( void* threadData);
57 Reference< XMultiServiceFactory > MultiServiceFactory;
59 int main( int argc, char *argv[ ], char *envp[ ] )
61 HRESULT hr;
62 if( FAILED( hr=CoInitialize(NULL )))
64 _tprintf(_T("CoInitialize failed \n"));
65 return -1;
68 _Module.Init( ObjectMap, GetModuleHandle( NULL));
70 if( FAILED(hr=doTest()))
72 _com_error err( hr);
75 _Module.Term();
76 CoUninitialize();
77 return 0;
80 HRESULT doTest()
83 MultiServiceFactory= createRegistryServiceFactory( OUString(L"types.rdb"), OUString( L"services.rdb") , sal_True);
85 // create the MTA thread that is used to realize MTA calls to the services
86 // We create the thread and wait until the thread has created its message queue
87 HANDLE evt= CreateEvent(NULL, FALSE, FALSE, NULL);
88 DWORD threadIdMTA=0;
89 HANDLE hMTAThread= CreateThread( NULL, 0, MTAFunc, &evt, 0, &threadIdMTA);
90 WaitForSingleObject( evt, INFINITE);
91 CloseHandle(evt);
93 HRESULT hr= S_OK;
94 RECT pos1={0,0,300,200};
95 AWindow win(_T("DnD starting in Ole STA"), threadIdMTA, pos1);
97 RECT pos2={ 0, 205, 300, 405};
98 AWindow win2( _T("DnD starting in MTA"), threadIdMTA, pos2, true);
100 // win3 and win4 call initialize from an MTA but they are created in an STA
101 RECT pos3={300,0,600,200};
102 AWindow win3(_T("DnD starting in OLE STA"), threadIdMTA, pos3, false, true);
104 RECT pos4={ 300, 205, 600, 405};
105 AWindow win24( _T("DnD starting in Ole MTA"), threadIdMTA, pos4, true, true);
107 MSG msg;
108 while( GetMessage(&msg, (HWND)NULL, 0, 0) )
110 TranslateMessage( &msg);
111 DispatchMessage( &msg);
114 // Shut down the MTA thread
115 PostThreadMessage( threadIdMTA, WM_QUIT, 0, 0);
116 WaitForSingleObject(hMTAThread, INFINITE);
117 CloseHandle(hMTAThread);
119 return S_OK;
122 extern Reference<XMultiServiceFactory> MultiServiceFactory;
123 DWORD WINAPI MTAFunc( void* threadData)
125 HRESULT hr= S_OK;
126 hr= CoInitializeEx( NULL, COINIT_MULTITHREADED);
127 ATLASSERT( FAILED(hr) );
128 MSG msg;
129 // force the creation of a message queue
130 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
131 SetEvent( *(HANDLE*)threadData );
133 RECT pos={0, 406, 300, 605};
134 AWindow win(_T("DnD, full MTA"), GetCurrentThreadId(), pos, false, true);
136 while( GetMessage(&msg, (HWND)NULL, 0, 0) )
138 switch( msg.message)
140 case WM_SOURCE_INIT:
142 InitializationData* pData= (InitializationData*)msg.wParam;
143 Any any;
144 any <<= (sal_uInt32) pData->hWnd;
145 pData->xInit->initialize( Sequence<Any>( &any, 1));
147 CoTaskMemFree( pData);
148 break;
150 case WM_SOURCE_STARTDRAG:
152 // wParam contains necessary data
153 StartDragData* pData= (StartDragData*)msg.wParam;
154 Sequence<DataFlavor> seq= pData->transferable->getTransferDataFlavors();
155 // have a look what flavours are supported
156 for( int i=0; i<seq.getLength(); i++)
158 DataFlavor d= seq[i];
160 pData->source->startDrag( DragGestureEvent(),
161 ACTION_LINK|ACTION_MOVE|ACTION_COPY,
164 pData->transferable,
165 Reference<XDragSourceListener>( static_cast<XDragSourceListener*>
166 ( new DragSourceListener())));
167 CoTaskMemFree( pData);
168 break;
171 } // end switch
173 TranslateMessage( &msg);
174 DispatchMessage( &msg);
177 CoUninitialize();
178 return 0;
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */