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)
28 #include <atlimpl.cpp>
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
)
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
;
52 DWORD WINAPI
MTAFunc( void* threadData
);
54 Reference
< XMultiServiceFactory
> MultiServiceFactory
;
56 int main( int argc
, char *argv
[ ], char *envp
[ ] )
59 if( FAILED( hr
=CoInitialize(NULL
)))
61 printf("CoInitialize failed \n");
65 _Module
.Init( ObjectMap
, GetModuleHandleA( NULL
));
67 if( FAILED(hr
=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
);
86 HANDLE hMTAThread
= CreateThread( NULL
, 0, MTAFunc
, &evt
, 0, &threadIdMTA
);
87 WaitForSingleObject( evt
, INFINITE
);
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);
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
);
119 extern Reference
<XMultiServiceFactory
> MultiServiceFactory
;
120 DWORD WINAPI
MTAFunc( void* threadData
)
122 HRESULT hr
= CoInitializeEx( NULL
, COINIT_MULTITHREADED
);
123 ATLASSERT( FAILED(hr
) );
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) )
138 InitializationData
* pData
= (InitializationData
*)msg
.wParam
;
140 any
<<= (sal_uInt32
) pData
->hWnd
;
141 pData
->xInit
->initialize( Sequence
<Any
>( &any
, 1));
143 CoTaskMemFree( pData
);
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
,
161 Reference
<XDragSourceListener
>( static_cast<XDragSourceListener
*>
162 ( new DragSourceListener())));
163 CoTaskMemFree( pData
);
169 TranslateMessage( &msg
);
170 DispatchMessageA( &msg
);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */