xref: /aoo4110/main/dtrans/source/win32/dnd/globals.cxx (revision b1cdbd2c)
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 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
27 
28 #include "globals.hxx"
29 
30 //--> TRA
31 #include <com/sun/star/datatransfer/XTransferable.hpp>
32 
33 // used as shortcut when drag-source and drop-target are the same
34 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > g_XTransferable;
35 
36 //<-- TRA
37 
38 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
39 
dndOleKeysToAction(DWORD grfKeyState,sal_Int8 nSourceActions)40 sal_Int8 dndOleKeysToAction( DWORD grfKeyState, sal_Int8 nSourceActions)
41 {
42 	sal_Int8 ret= 0;
43 
44 	// no MK_ALT, MK_CONTROL, MK_SHIFT
45 	if( !(grfKeyState & MK_CONTROL) &&
46 		!(grfKeyState & MK_ALT)	   &&
47 		!(grfKeyState & MK_RBUTTON) &&
48 		!(grfKeyState & MK_SHIFT))
49 	{
50         if( nSourceActions & ACTION_MOVE )
51         {
52 		    ret= ACTION_DEFAULT | ACTION_MOVE;
53         }
54 
55         else if( nSourceActions & ACTION_COPY )
56         {
57     		ret= ACTION_COPY;
58         }
59 
60         else if( nSourceActions & ACTION_LINK )
61         {
62     		ret= ACTION_LINK;
63         }
64 
65         else
66             ret = 0;
67 	}
68 	else if( grfKeyState & MK_SHIFT &&
69 			!(grfKeyState & MK_CONTROL))
70 	{
71 		ret= ACTION_MOVE;
72 	}
73 	else if ( grfKeyState & MK_CONTROL &&
74 			  !(grfKeyState & MK_SHIFT)	)
75 	{
76 		ret= ACTION_COPY;
77 	}
78 	else if ( grfKeyState & MK_CONTROL &&
79 			  grfKeyState & MK_SHIFT)
80 	{
81 		ret= ACTION_LINK;
82 	}
83 	else if ( grfKeyState & MK_RBUTTON |
84 			  grfKeyState & MK_ALT)
85 	{
86 		ret= ACTION_COPY_OR_MOVE | ACTION_LINK;
87 	}
88 	return ret;
89 }
90 
91 
dndOleDropEffectsToActions(DWORD dwEffect)92 sal_Int8 dndOleDropEffectsToActions( DWORD dwEffect)
93 {
94 	sal_Int8 ret= ACTION_NONE;
95 	if( dwEffect & DROPEFFECT_COPY)
96 		ret |= ACTION_COPY;
97 	if( dwEffect & DROPEFFECT_MOVE)
98 		ret |= ACTION_MOVE;
99 	if( dwEffect & DROPEFFECT_LINK)
100 		ret |= ACTION_LINK;
101 
102 	return ret;
103 }
104 
dndActionsToDropEffects(sal_Int8 actions)105 DWORD dndActionsToDropEffects( sal_Int8 actions)
106 {
107 	DWORD ret= DROPEFFECT_NONE;
108 	if( actions & ACTION_MOVE)
109 		ret |= DROPEFFECT_MOVE;
110 	if( actions & ACTION_COPY)
111 		ret |= DROPEFFECT_COPY;
112 	if( actions & ACTION_LINK)
113 		ret |= DROPEFFECT_LINK;
114 	if( actions & ACTION_DEFAULT)
115 		ret |= DROPEFFECT_COPY;
116 	return ret;
117 }
118 
dndActionsToSingleDropEffect(sal_Int8 actions)119 DWORD dndActionsToSingleDropEffect( sal_Int8 actions)
120 {
121 	DWORD effects= dndActionsToDropEffects( actions);
122 
123 	sal_Int8 countEffect= 0;
124 
125 	if( effects & DROPEFFECT_MOVE)
126 		countEffect++;
127 	if( effects & DROPEFFECT_COPY)
128 		countEffect++;
129 	if( effects & DROPEFFECT_LINK)
130 		countEffect++;
131 
132 	// DROPEFFECT_MOVE is the default effect
133 	DWORD retVal= countEffect > 1 ? DROPEFFECT_MOVE : effects;
134 	return retVal;
135 }
136