xref: /trunk/main/dtrans/source/win32/dnd/globals.cxx (revision 48123e16)
1*48123e16SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*48123e16SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*48123e16SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*48123e16SAndrew Rist  * distributed with this work for additional information
6*48123e16SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*48123e16SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*48123e16SAndrew Rist  * "License"); you may not use this file except in compliance
9*48123e16SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*48123e16SAndrew Rist  *
11*48123e16SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*48123e16SAndrew Rist  *
13*48123e16SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*48123e16SAndrew Rist  * software distributed under the License is distributed on an
15*48123e16SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*48123e16SAndrew Rist  * KIND, either express or implied.  See the License for the
17*48123e16SAndrew Rist  * specific language governing permissions and limitations
18*48123e16SAndrew Rist  * under the License.
19*48123e16SAndrew Rist  *
20*48123e16SAndrew Rist  *************************************************************/
21*48123e16SAndrew Rist 
22*48123e16SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dtrans.hxx"
26cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "globals.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir //--> TRA
31cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // used as shortcut when drag-source and drop-target are the same
34cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > g_XTransferable;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //<-- TRA
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace com::sun::star::datatransfer::dnd::DNDConstants;
39cdf0e10cSrcweir 
dndOleKeysToAction(DWORD grfKeyState,sal_Int8 nSourceActions)40cdf0e10cSrcweir sal_Int8 dndOleKeysToAction( DWORD grfKeyState, sal_Int8 nSourceActions)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	sal_Int8 ret= 0;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	// no MK_ALT, MK_CONTROL, MK_SHIFT
45cdf0e10cSrcweir 	if( !(grfKeyState & MK_CONTROL) &&
46cdf0e10cSrcweir 		!(grfKeyState & MK_ALT)	   &&
47cdf0e10cSrcweir 		!(grfKeyState & MK_RBUTTON) &&
48cdf0e10cSrcweir 		!(grfKeyState & MK_SHIFT))
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir         if( nSourceActions & ACTION_MOVE )
51cdf0e10cSrcweir         {
52cdf0e10cSrcweir 		    ret= ACTION_DEFAULT | ACTION_MOVE;
53cdf0e10cSrcweir         }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         else if( nSourceActions & ACTION_COPY )
56cdf0e10cSrcweir         {
57cdf0e10cSrcweir     		ret= ACTION_COPY;
58cdf0e10cSrcweir         }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         else if( nSourceActions & ACTION_LINK )
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir     		ret= ACTION_LINK;
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         else
66cdf0e10cSrcweir             ret = 0;
67cdf0e10cSrcweir 	}
68cdf0e10cSrcweir 	else if( grfKeyState & MK_SHIFT &&
69cdf0e10cSrcweir 			!(grfKeyState & MK_CONTROL))
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		ret= ACTION_MOVE;
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 	else if ( grfKeyState & MK_CONTROL &&
74cdf0e10cSrcweir 			  !(grfKeyState & MK_SHIFT)	)
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		ret= ACTION_COPY;
77cdf0e10cSrcweir 	}
78cdf0e10cSrcweir 	else if ( grfKeyState & MK_CONTROL &&
79cdf0e10cSrcweir 			  grfKeyState & MK_SHIFT)
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		ret= ACTION_LINK;
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 	else if ( grfKeyState & MK_RBUTTON |
84cdf0e10cSrcweir 			  grfKeyState & MK_ALT)
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir 		ret= ACTION_COPY_OR_MOVE | ACTION_LINK;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 	return ret;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
dndOleDropEffectsToActions(DWORD dwEffect)92cdf0e10cSrcweir sal_Int8 dndOleDropEffectsToActions( DWORD dwEffect)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	sal_Int8 ret= ACTION_NONE;
95cdf0e10cSrcweir 	if( dwEffect & DROPEFFECT_COPY)
96cdf0e10cSrcweir 		ret |= ACTION_COPY;
97cdf0e10cSrcweir 	if( dwEffect & DROPEFFECT_MOVE)
98cdf0e10cSrcweir 		ret |= ACTION_MOVE;
99cdf0e10cSrcweir 	if( dwEffect & DROPEFFECT_LINK)
100cdf0e10cSrcweir 		ret |= ACTION_LINK;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	return ret;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
dndActionsToDropEffects(sal_Int8 actions)105cdf0e10cSrcweir DWORD dndActionsToDropEffects( sal_Int8 actions)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	DWORD ret= DROPEFFECT_NONE;
108cdf0e10cSrcweir 	if( actions & ACTION_MOVE)
109cdf0e10cSrcweir 		ret |= DROPEFFECT_MOVE;
110cdf0e10cSrcweir 	if( actions & ACTION_COPY)
111cdf0e10cSrcweir 		ret |= DROPEFFECT_COPY;
112cdf0e10cSrcweir 	if( actions & ACTION_LINK)
113cdf0e10cSrcweir 		ret |= DROPEFFECT_LINK;
114cdf0e10cSrcweir 	if( actions & ACTION_DEFAULT)
115cdf0e10cSrcweir 		ret |= DROPEFFECT_COPY;
116cdf0e10cSrcweir 	return ret;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
dndActionsToSingleDropEffect(sal_Int8 actions)119cdf0e10cSrcweir DWORD dndActionsToSingleDropEffect( sal_Int8 actions)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	DWORD effects= dndActionsToDropEffects( actions);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	sal_Int8 countEffect= 0;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	if( effects & DROPEFFECT_MOVE)
126cdf0e10cSrcweir 		countEffect++;
127cdf0e10cSrcweir 	if( effects & DROPEFFECT_COPY)
128cdf0e10cSrcweir 		countEffect++;
129cdf0e10cSrcweir 	if( effects & DROPEFFECT_LINK)
130cdf0e10cSrcweir 		countEffect++;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	// DROPEFFECT_MOVE is the default effect
133cdf0e10cSrcweir 	DWORD retVal= countEffect > 1 ? DROPEFFECT_MOVE : effects;
134cdf0e10cSrcweir 	return retVal;
135cdf0e10cSrcweir }
136