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 #include "DragActionConversion.hxx"
25 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
26 
27 
28 using namespace com::sun::star::datatransfer::dnd;
29 
30 
31 /* Convert office drag actions as defined in
32    <type>com::sun::star::datatransfer::dnd::DNDConstants</type>
33    into system conform drag actions.
34  */
OfficeToSystemDragActions(sal_Int8 dragActions)35 unsigned int OfficeToSystemDragActions(sal_Int8 dragActions)
36 {
37   unsigned int actions = NSDragOperationNone;
38 
39   if (dragActions & DNDConstants::ACTION_COPY)
40 	{
41 	  actions |= NSDragOperationCopy;
42 	}
43 
44   if (dragActions & DNDConstants::ACTION_MOVE)
45 	{
46 	  actions |= NSDragOperationMove;
47 	}
48 
49   if (dragActions & DNDConstants::ACTION_LINK)
50 	{
51 	  actions |= NSDragOperationLink;
52 	}
53 
54   return actions;
55 }
56 
57 /* Convert system conform drag actions into office conform
58    drag actions as defined in
59    <type>com::sun::star::datatransfer::dnd::DNDConstants</type>.
60  */
SystemToOfficeDragActions(unsigned int dragActions)61 sal_Int8 SystemToOfficeDragActions(unsigned int dragActions)
62 {
63   sal_Int8 actions = DNDConstants::ACTION_NONE;
64 
65   if (dragActions & NSDragOperationCopy)
66 	{
67 	  actions |= DNDConstants::ACTION_COPY;
68 	}
69 
70   if (dragActions & NSDragOperationMove)
71 	{
72 	  actions |= DNDConstants::ACTION_MOVE;
73 	}
74 
75   if (dragActions & NSDragOperationLink)
76 	{
77 	  actions |= DNDConstants::ACTION_LINK;
78 	}
79 
80   // We map NSDragOperationGeneric to ACTION_DEFAULT to
81   // signal that we have to decide for a drag action
82   if (dragActions & NSDragOperationGeneric)
83 	{
84 	  actions |= DNDConstants::ACTION_DEFAULT;
85 	}
86 
87   return actions;
88 }
89