Branch libreoffice-5-0-4
[LibreOffice.git] / dtrans / source / win32 / dnd / globals.cxx
blobf36297e349b11c34a1eb95c0e74747aafb2c7cc3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
22 #include "globals.hxx"
24 //--> TRA
25 #include <com/sun/star/datatransfer/XTransferable.hpp>
27 // used as shortcut when drag-source and drop-target are the same
28 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > g_XTransferable;
30 //<-- TRA
32 using namespace com::sun::star::datatransfer::dnd::DNDConstants;
34 sal_Int8 dndOleKeysToAction( DWORD grfKeyState, sal_Int8 nSourceActions)
36 sal_Int8 ret= 0;
38 // no MK_ALT, MK_CONTROL, MK_SHIFT
39 if( !(grfKeyState & MK_CONTROL) &&
40 !(grfKeyState & MK_ALT) &&
41 !(grfKeyState & MK_RBUTTON) &&
42 !(grfKeyState & MK_SHIFT))
44 if( nSourceActions & ACTION_MOVE )
46 ret= ACTION_DEFAULT | ACTION_MOVE;
49 else if( nSourceActions & ACTION_COPY )
51 ret= ACTION_COPY;
54 else if( nSourceActions & ACTION_LINK )
56 ret= ACTION_LINK;
59 else
60 ret = 0;
62 else if( grfKeyState & MK_SHIFT &&
63 !(grfKeyState & MK_CONTROL))
65 ret= ACTION_MOVE;
67 else if ( grfKeyState & MK_CONTROL &&
68 !(grfKeyState & MK_SHIFT) )
70 ret= ACTION_COPY;
72 else if ( grfKeyState & MK_CONTROL &&
73 grfKeyState & MK_SHIFT)
75 ret= ACTION_LINK;
77 else if ( grfKeyState & MK_RBUTTON ||
78 grfKeyState & MK_ALT)
80 ret= ACTION_COPY_OR_MOVE | ACTION_LINK;
82 return ret;
85 sal_Int8 dndOleDropEffectsToActions( DWORD dwEffect)
87 sal_Int8 ret= ACTION_NONE;
88 if( dwEffect & DROPEFFECT_COPY)
89 ret |= ACTION_COPY;
90 if( dwEffect & DROPEFFECT_MOVE)
91 ret |= ACTION_MOVE;
92 if( dwEffect & DROPEFFECT_LINK)
93 ret |= ACTION_LINK;
95 return ret;
98 DWORD dndActionsToDropEffects( sal_Int8 actions)
100 DWORD ret= DROPEFFECT_NONE;
101 if( actions & ACTION_MOVE)
102 ret |= DROPEFFECT_MOVE;
103 if( actions & ACTION_COPY)
104 ret |= DROPEFFECT_COPY;
105 if( actions & ACTION_LINK)
106 ret |= DROPEFFECT_LINK;
107 if( actions & ACTION_DEFAULT)
108 ret |= DROPEFFECT_COPY;
109 return ret;
112 DWORD dndActionsToSingleDropEffect( sal_Int8 actions)
114 DWORD effects= dndActionsToDropEffects( actions);
116 sal_Int8 countEffect= 0;
118 if( effects & DROPEFFECT_MOVE)
119 countEffect++;
120 if( effects & DROPEFFECT_COPY)
121 countEffect++;
122 if( effects & DROPEFFECT_LINK)
123 countEffect++;
125 // DROPEFFECT_MOVE is the default effect
126 DWORD retVal= countEffect > 1 ? DROPEFFECT_MOVE : effects;
127 return retVal;
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */