Update ooo320-m1
[ooovba.git] / dtrans / source / win32 / dnd / globals.cxx
blob15916fbec301897dae054ca11c12bf3d0fde80fe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: globals.cxx,v $
10 * $Revision: 1.10 $
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"
33 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
35 #include "globals.hxx"
37 //--> TRA
38 #include <com/sun/star/datatransfer/XTransferable.hpp>
40 // used as shortcut when drag-source and drop-target are the same
41 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > g_XTransferable;
43 //<-- TRA
45 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
47 sal_Int8 dndOleKeysToAction( DWORD grfKeyState, sal_Int8 nSourceActions)
49 sal_Int8 ret= 0;
51 // no MK_ALT, MK_CONTROL, MK_SHIFT
52 if( !(grfKeyState & MK_CONTROL) &&
53 !(grfKeyState & MK_ALT) &&
54 !(grfKeyState & MK_RBUTTON) &&
55 !(grfKeyState & MK_SHIFT))
57 if( nSourceActions & ACTION_MOVE )
59 ret= ACTION_DEFAULT | ACTION_MOVE;
62 else if( nSourceActions & ACTION_COPY )
64 ret= ACTION_COPY;
67 else if( nSourceActions & ACTION_LINK )
69 ret= ACTION_LINK;
72 else
73 ret = 0;
75 else if( grfKeyState & MK_SHIFT &&
76 !(grfKeyState & MK_CONTROL))
78 ret= ACTION_MOVE;
80 else if ( grfKeyState & MK_CONTROL &&
81 !(grfKeyState & MK_SHIFT) )
83 ret= ACTION_COPY;
85 else if ( grfKeyState & MK_CONTROL &&
86 grfKeyState & MK_SHIFT)
88 ret= ACTION_LINK;
90 else if ( grfKeyState & MK_RBUTTON |
91 grfKeyState & MK_ALT)
93 ret= ACTION_COPY_OR_MOVE | ACTION_LINK;
95 return ret;
99 sal_Int8 dndOleDropEffectsToActions( DWORD dwEffect)
101 sal_Int8 ret= ACTION_NONE;
102 if( dwEffect & DROPEFFECT_COPY)
103 ret |= ACTION_COPY;
104 if( dwEffect & DROPEFFECT_MOVE)
105 ret |= ACTION_MOVE;
106 if( dwEffect & DROPEFFECT_LINK)
107 ret |= ACTION_LINK;
109 return ret;
112 DWORD dndActionsToDropEffects( sal_Int8 actions)
114 DWORD ret= DROPEFFECT_NONE;
115 if( actions & ACTION_MOVE)
116 ret |= DROPEFFECT_MOVE;
117 if( actions & ACTION_COPY)
118 ret |= DROPEFFECT_COPY;
119 if( actions & ACTION_LINK)
120 ret |= DROPEFFECT_LINK;
121 if( actions & ACTION_DEFAULT)
122 ret |= DROPEFFECT_COPY;
123 return ret;
126 DWORD dndActionsToSingleDropEffect( sal_Int8 actions)
128 DWORD effects= dndActionsToDropEffects( actions);
130 sal_Int8 countEffect= 0;
132 if( effects & DROPEFFECT_MOVE)
133 countEffect++;
134 if( effects & DROPEFFECT_COPY)
135 countEffect++;
136 if( effects & DROPEFFECT_LINK)
137 countEffect++;
139 // DROPEFFECT_MOVE is the default effect
140 DWORD retVal= countEffect > 1 ? DROPEFFECT_MOVE : effects;
141 return retVal;