1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sourcecontext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dtrans.hxx"
35 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
37 #include "sourcecontext.hxx"
38 #include <rtl/unload.h>
40 using namespace com::sun::star::datatransfer::dnd
;
41 using namespace com::sun::star::datatransfer::dnd::DNDConstants
;
42 extern rtl_StandardModuleCount g_moduleCount
;
44 SourceContext::SourceContext( DragSource
* pSource
,
45 const Reference
<XDragSourceListener
>& listener
):
46 WeakComponentImplHelper1
<XDragSourceContext
>(m_mutex
),
47 m_pDragSource( pSource
),
48 m_dragSource( static_cast<XDragSource
*>( m_pDragSource
) )
50 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
51 #if OSL_DEBUG_LEVEL > 1
54 rBHelper
.addListener( ::getCppuType( &listener
), listener
);
57 SourceContext::~SourceContext()
59 g_moduleCount
.modCnt
.release( &g_moduleCount
.modCnt
);
62 void SAL_CALL
SourceContext::addDragSourceListener(
63 const Reference
<XDragSourceListener
>& )
64 throw( RuntimeException
)
68 void SAL_CALL
SourceContext::removeDragSourceListener(
69 const Reference
<XDragSourceListener
>& )
70 throw( RuntimeException
)
74 sal_Int32 SAL_CALL
SourceContext::getCurrentCursor( )
75 throw( RuntimeException
)
80 void SAL_CALL
SourceContext::setCursor( sal_Int32
/*cursorId*/ )
81 throw( RuntimeException
)
85 void SAL_CALL
SourceContext::setImage( sal_Int32
/*imageId*/ )
86 throw( RuntimeException
)
90 void SAL_CALL
SourceContext::transferablesFlavorsChanged( )
91 throw( RuntimeException
)
96 // non -interface functions
97 // Fires XDragSourceListener::dragDropEnd events.
98 void SourceContext::fire_dragDropEnd( sal_Bool success
, sal_Int8 effect
)
101 DragSourceDropEvent e
;
103 if( success
== sal_True
)
105 e
.DropAction
= effect
;
106 e
.DropSuccess
= sal_True
;
110 e
.DropAction
= ACTION_NONE
;
111 e
.DropSuccess
= sal_False
;
113 e
.DragSource
= m_dragSource
;
114 e
.DragSourceContext
= static_cast<XDragSourceContext
*>( this);
115 e
.Source
= Reference
<XInterface
>( static_cast<XDragSourceContext
*>( this), UNO_QUERY
);
117 OInterfaceContainerHelper
* pContainer
= rBHelper
.getContainer(
118 getCppuType( (Reference
<XDragSourceListener
>* )0 ) );
122 OInterfaceIteratorHelper
iter( *pContainer
);
123 while( iter
.hasMoreElements())
125 Reference
<XDragSourceListener
> listener(
126 static_cast<XDragSourceListener
*>( iter
.next()));
127 listener
->dragDropEnd( e
);
133 void SourceContext::fire_dropActionChanged( sal_Int8 dropAction
, sal_Int8 userAction
)
135 if( m_currentAction
!= dropAction
)
137 m_currentAction
= dropAction
;
138 DragSourceDragEvent e
;
139 e
.DropAction
= dropAction
;
140 e
.UserAction
= userAction
;
141 e
.DragSource
= m_dragSource
;
142 e
.DragSourceContext
= static_cast<XDragSourceContext
*>( this);
143 e
.Source
= Reference
<XInterface
>( static_cast<XDragSourceContext
*>( this), UNO_QUERY
);
145 OInterfaceContainerHelper
* pContainer
= rBHelper
.getContainer(
146 getCppuType( (Reference
<XDragSourceListener
>* )0 ) );
150 OInterfaceIteratorHelper
iter( *pContainer
);
151 while( iter
.hasMoreElements())
153 Reference
<XDragSourceListener
> listener(
154 static_cast<XDragSourceListener
*>( iter
.next()));
155 listener
->dropActionChanged( e
);