1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #pragma warning(push,1)
29 #include <atlimpl.cpp>
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
)
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
55 DWORD WINAPI
MTAFunc( void* threadData
);
57 Reference
< XMultiServiceFactory
> MultiServiceFactory
;
59 int main( int argc
, char *argv
[ ], char *envp
[ ] )
62 if( FAILED( hr
=CoInitialize(NULL
)))
64 _tprintf(_T("CoInitialize failed \n"));
68 _Module
.Init( ObjectMap
, GetModuleHandle( NULL
));
70 if( FAILED(hr
=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
);
89 HANDLE hMTAThread
= CreateThread( NULL
, 0, MTAFunc
, &evt
, 0, &threadIdMTA
);
90 WaitForSingleObject( evt
, INFINITE
);
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);
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
);
122 extern Reference
<XMultiServiceFactory
> MultiServiceFactory
;
123 DWORD WINAPI
MTAFunc( void* threadData
)
126 hr
= CoInitializeEx( NULL
, COINIT_MULTITHREADED
);
127 ATLASSERT( FAILED(hr
) );
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) )
142 InitializationData
* pData
= (InitializationData
*)msg
.wParam
;
144 any
<<= (sal_uInt32
) pData
->hWnd
;
145 pData
->xInit
->initialize( Sequence
<Any
>( &any
, 1));
147 CoTaskMemFree( pData
);
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
,
165 Reference
<XDragSourceListener
>( static_cast<XDragSourceListener
*>
166 ( new DragSourceListener())));
167 CoTaskMemFree( pData
);
173 TranslateMessage( &msg
);
174 DispatchMessage( &msg
);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */