xref: /AOO41X/main/dtrans/source/win32/dnd/sourcecontext.cxx (revision 48123e16153c92857455f9e7a0d17cc19307983f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dtrans.hxx"
26 
27 
28 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
29 
30 #include "sourcecontext.hxx"
31 #include <rtl/unload.h>
32 
33 using namespace com::sun::star::datatransfer::dnd;
34 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
35 extern rtl_StandardModuleCount g_moduleCount;
36 
SourceContext(DragSource * pSource,const Reference<XDragSourceListener> & listener)37 SourceContext::SourceContext( DragSource* pSource,
38                              const Reference<XDragSourceListener>& listener):
39         WeakComponentImplHelper1<XDragSourceContext>(m_mutex),
40         m_pDragSource( pSource),
41         m_dragSource( static_cast<XDragSource*>( m_pDragSource) )
42 {
43     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
44 #if OSL_DEBUG_LEVEL > 1
45     if( listener.is())
46 #endif
47     rBHelper.addListener( ::getCppuType( &listener ), listener );
48 }
49 
~SourceContext()50 SourceContext::~SourceContext()
51 {
52     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
53 }
54 
addDragSourceListener(const Reference<XDragSourceListener> &)55 void SAL_CALL SourceContext::addDragSourceListener(
56     const Reference<XDragSourceListener >& )
57     throw( RuntimeException)
58 {
59 }
60 
removeDragSourceListener(const Reference<XDragSourceListener> &)61 void SAL_CALL SourceContext::removeDragSourceListener(
62      const Reference<XDragSourceListener >& )
63     throw( RuntimeException)
64 {
65 }
66 
getCurrentCursor()67 sal_Int32 SAL_CALL SourceContext::getCurrentCursor(  )
68     throw( RuntimeException)
69 {
70     return 0;
71 }
72 
setCursor(sal_Int32)73 void SAL_CALL SourceContext::setCursor( sal_Int32 /*cursorId*/ )
74     throw( RuntimeException)
75 {
76 }
77 
setImage(sal_Int32)78 void SAL_CALL SourceContext::setImage( sal_Int32 /*imageId*/ )
79     throw( RuntimeException)
80 {
81 }
82 
transferablesFlavorsChanged()83 void SAL_CALL SourceContext::transferablesFlavorsChanged(  )
84     throw( RuntimeException)
85 {
86 }
87 
88 
89 // non -interface functions
90 // Fires XDragSourceListener::dragDropEnd events.
fire_dragDropEnd(sal_Bool success,sal_Int8 effect)91 void SourceContext::fire_dragDropEnd( sal_Bool success, sal_Int8 effect)
92 {
93 
94     DragSourceDropEvent e;
95 
96     if( success == sal_True)
97     {
98         e.DropAction=  effect;
99         e.DropSuccess= sal_True;
100     }
101     else
102     {
103         e.DropAction= ACTION_NONE;
104         e.DropSuccess= sal_False;
105     }
106     e.DragSource= m_dragSource;
107     e.DragSourceContext= static_cast<XDragSourceContext*>( this);
108     e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);
109 
110     OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
111         getCppuType( (Reference<XDragSourceListener>* )0 ) );
112 
113     if( pContainer)
114     {
115         OInterfaceIteratorHelper iter( *pContainer);
116         while( iter.hasMoreElements())
117         {
118             Reference<XDragSourceListener> listener(
119                 static_cast<XDragSourceListener*>( iter.next()));
120             listener->dragDropEnd( e);
121         }
122     }
123 }
124 
125 
fire_dropActionChanged(sal_Int8 dropAction,sal_Int8 userAction)126 void SourceContext::fire_dropActionChanged( sal_Int8 dropAction, sal_Int8 userAction)
127 {
128     if( m_currentAction != dropAction)
129     {
130         m_currentAction= dropAction;
131         DragSourceDragEvent e;
132         e.DropAction= dropAction;
133         e.UserAction= userAction;
134         e.DragSource= m_dragSource;
135         e.DragSourceContext= static_cast<XDragSourceContext*>( this);
136         e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);
137 
138         OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
139             getCppuType( (Reference<XDragSourceListener>* )0 ) );
140 
141         if( pContainer)
142         {
143             OInterfaceIteratorHelper iter( *pContainer);
144             while( iter.hasMoreElements())
145             {
146                 Reference<XDragSourceListener> listener(
147                     static_cast<XDragSourceListener*>( iter.next()));
148                 listener->dropActionChanged( e);
149             }
150         }
151     }
152 }
153