1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dtrans.hxx"
30 
31 
32 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
33 
34 #include "sourcecontext.hxx"
35 #include <rtl/unload.h>
36 
37 using namespace com::sun::star::datatransfer::dnd;
38 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
39 extern rtl_StandardModuleCount g_moduleCount;
40 
41 SourceContext::SourceContext( DragSource* pSource,
42 							 const Reference<XDragSourceListener>& listener):
43 		WeakComponentImplHelper1<XDragSourceContext>(m_mutex),
44 		m_pDragSource( pSource),
45 		m_dragSource( static_cast<XDragSource*>( m_pDragSource) )
46 {
47 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
48 #if OSL_DEBUG_LEVEL > 1
49 	if( listener.is())
50 #endif
51 	rBHelper.addListener( ::getCppuType( &listener ), listener );
52 }
53 
54 SourceContext::~SourceContext()
55 {
56 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
57 }
58 
59 void SAL_CALL SourceContext::addDragSourceListener(
60 	const Reference<XDragSourceListener >& )
61 	throw( RuntimeException)
62 {
63 }
64 
65 void SAL_CALL SourceContext::removeDragSourceListener(
66 	 const Reference<XDragSourceListener >& )
67 	throw( RuntimeException)
68 {
69 }
70 
71 sal_Int32 SAL_CALL SourceContext::getCurrentCursor(  )
72 	throw( RuntimeException)
73 {
74 	return 0;
75 }
76 
77 void SAL_CALL SourceContext::setCursor( sal_Int32 /*cursorId*/ )
78 	throw( RuntimeException)
79 {
80 }
81 
82 void SAL_CALL SourceContext::setImage( sal_Int32 /*imageId*/ )
83 	throw( RuntimeException)
84 {
85 }
86 
87 void SAL_CALL SourceContext::transferablesFlavorsChanged(  )
88 	throw( RuntimeException)
89 {
90 }
91 
92 
93 // non -interface functions
94 // Fires XDragSourceListener::dragDropEnd events.
95 void SourceContext::fire_dragDropEnd( sal_Bool success, sal_Int8 effect)
96 {
97 
98 	DragSourceDropEvent e;
99 
100 	if( success == sal_True)
101 	{
102 		e.DropAction=  effect;
103 		e.DropSuccess= sal_True;
104 	}
105 	else
106 	{
107 		e.DropAction= ACTION_NONE;
108 		e.DropSuccess= sal_False;
109 	}
110 	e.DragSource= m_dragSource;
111 	e.DragSourceContext= static_cast<XDragSourceContext*>( this);
112 	e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);
113 
114 	OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
115 		getCppuType( (Reference<XDragSourceListener>* )0 ) );
116 
117 	if( pContainer)
118 	{
119 		OInterfaceIteratorHelper iter( *pContainer);
120 		while( iter.hasMoreElements())
121 		{
122 			Reference<XDragSourceListener> listener(
123 				static_cast<XDragSourceListener*>( iter.next()));
124 			listener->dragDropEnd( e);
125 		}
126 	}
127 }
128 
129 
130 void SourceContext::fire_dropActionChanged( sal_Int8 dropAction, sal_Int8 userAction)
131 {
132 	if( m_currentAction != dropAction)
133 	{
134 		m_currentAction= dropAction;
135 		DragSourceDragEvent e;
136 		e.DropAction= dropAction;
137 		e.UserAction= userAction;
138 		e.DragSource= m_dragSource;
139 		e.DragSourceContext= static_cast<XDragSourceContext*>( this);
140 		e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);
141 
142 		OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
143 			getCppuType( (Reference<XDragSourceListener>* )0 ) );
144 
145 		if( pContainer)
146 		{
147 			OInterfaceIteratorHelper iter( *pContainer);
148 			while( iter.hasMoreElements())
149 			{
150 				Reference<XDragSourceListener> listener(
151 					static_cast<XDragSourceListener*>( iter.next()));
152 				listener->dropActionChanged( e);
153 			}
154 		}
155 	}
156 }
157