LibreOffice Module dtrans (master)  1
globals.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
21 
22 #include "globals.hxx"
23 
24 //--> TRA
25 #include <com/sun/star/datatransfer/XTransferable.hpp>
26 
27 // used as shortcut when drag-source and drop-target are the same
28 css::uno::Reference< css::datatransfer::XTransferable > g_XTransferable;
29 
30 //<-- TRA
31 
33 
34 sal_Int8 dndOleKeysToAction( DWORD grfKeyState, sal_Int8 nSourceActions)
35 {
36  sal_Int8 ret= 0;
37 
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))
43  {
44  if( nSourceActions & ACTION_MOVE )
45  {
46  ret= ACTION_DEFAULT | ACTION_MOVE;
47  }
48 
49  else if( nSourceActions & ACTION_COPY )
50  {
51  ret= ACTION_COPY;
52  }
53 
54  else if( nSourceActions & ACTION_LINK )
55  {
56  ret= ACTION_LINK;
57  }
58 
59  else
60  ret = 0;
61  }
62  else if( grfKeyState & MK_SHIFT &&
63  !(grfKeyState & MK_CONTROL))
64  {
65  ret= ACTION_MOVE;
66  }
67  else if ( grfKeyState & MK_CONTROL &&
68  !(grfKeyState & MK_SHIFT) )
69  {
70  ret= ACTION_COPY;
71  }
72  else if ( grfKeyState & MK_CONTROL &&
73  grfKeyState & MK_SHIFT)
74  {
75  ret= ACTION_LINK;
76  }
77  else if ( grfKeyState & MK_RBUTTON ||
78  grfKeyState & MK_ALT)
79  {
80  ret= ACTION_COPY_OR_MOVE | ACTION_LINK;
81  }
82  return ret;
83 }
84 
86 {
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;
94 
95  return ret;
96 }
97 
99 {
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;
110 }
111 
113 {
114  DWORD effects= dndActionsToDropEffects( actions);
115 
116  sal_Int8 countEffect= 0;
117 
118  if( effects & DROPEFFECT_MOVE)
119  countEffect++;
120  if( effects & DROPEFFECT_COPY)
121  countEffect++;
122  if( effects & DROPEFFECT_LINK)
123  countEffect++;
124 
125  // DROPEFFECT_MOVE is the default effect
126  DWORD retVal= countEffect > 1 ? DROPEFFECT_MOVE : effects;
127  return retVal;
128 }
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
signed char sal_Int8
sal_Int8 dndOleDropEffectsToActions(DWORD dwEffect)
Definition: globals.cxx:85
css::uno::Reference< css::datatransfer::XTransferable > g_XTransferable
Definition: globals.cxx:28
DWORD dndActionsToDropEffects(sal_Int8 actions)
Definition: globals.cxx:98
sal_Int8 dndOleKeysToAction(DWORD grfKeyState, sal_Int8 nSourceActions)
Definition: globals.cxx:34
DWORD dndActionsToSingleDropEffect(sal_Int8 actions)
Definition: globals.cxx:112