1 | /* $Id: DnDUtils.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DnD - Common utility functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2022-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #include <VBox/GuestHost/DragAndDrop.h>
|
---|
33 | #include <VBox/HostServices/DragAndDropSvc.h>
|
---|
34 |
|
---|
35 | #include <iprt/assert.h>
|
---|
36 | #include <iprt/errcore.h>
|
---|
37 |
|
---|
38 | using namespace DragAndDropSvc;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Converts a host HGCM message to a string.
|
---|
42 | *
|
---|
43 | * @returns Stringified version of the host message.
|
---|
44 | */
|
---|
45 | const char *DnDHostMsgToStr(uint32_t uMsg)
|
---|
46 | {
|
---|
47 | switch (uMsg)
|
---|
48 | {
|
---|
49 | RT_CASE_RET_STR(HOST_DND_FN_SET_MODE);
|
---|
50 | RT_CASE_RET_STR(HOST_DND_FN_CANCEL);
|
---|
51 | RT_CASE_RET_STR(HOST_DND_FN_HG_EVT_ENTER);
|
---|
52 | RT_CASE_RET_STR(HOST_DND_FN_HG_EVT_MOVE);
|
---|
53 | RT_CASE_RET_STR(HOST_DND_FN_HG_EVT_LEAVE);
|
---|
54 | RT_CASE_RET_STR(HOST_DND_FN_HG_EVT_DROPPED);
|
---|
55 | RT_CASE_RET_STR(HOST_DND_FN_HG_SND_DATA_HDR);
|
---|
56 | RT_CASE_RET_STR(HOST_DND_FN_HG_SND_DATA);
|
---|
57 | RT_CASE_RET_STR(HOST_DND_FN_HG_SND_MORE_DATA);
|
---|
58 | RT_CASE_RET_STR(HOST_DND_FN_HG_SND_DIR);
|
---|
59 | RT_CASE_RET_STR(HOST_DND_FN_HG_SND_FILE_DATA);
|
---|
60 | RT_CASE_RET_STR(HOST_DND_FN_HG_SND_FILE_HDR);
|
---|
61 | RT_CASE_RET_STR(HOST_DND_FN_GH_REQ_PENDING);
|
---|
62 | RT_CASE_RET_STR(HOST_DND_FN_GH_EVT_DROPPED);
|
---|
63 | default:
|
---|
64 | break;
|
---|
65 | }
|
---|
66 | return "unknown";
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Converts a guest HGCM message to a string.
|
---|
71 | *
|
---|
72 | * @returns Stringified version of the guest message.
|
---|
73 | */
|
---|
74 | const char *DnDGuestMsgToStr(uint32_t uMsg)
|
---|
75 | {
|
---|
76 | switch (uMsg)
|
---|
77 | {
|
---|
78 | RT_CASE_RET_STR(GUEST_DND_FN_CONNECT);
|
---|
79 | RT_CASE_RET_STR(GUEST_DND_FN_DISCONNECT);
|
---|
80 | RT_CASE_RET_STR(GUEST_DND_FN_REPORT_FEATURES);
|
---|
81 | RT_CASE_RET_STR(GUEST_DND_FN_QUERY_FEATURES);
|
---|
82 | RT_CASE_RET_STR(GUEST_DND_FN_GET_NEXT_HOST_MSG);
|
---|
83 | RT_CASE_RET_STR(GUEST_DND_FN_EVT_ERROR);
|
---|
84 | RT_CASE_RET_STR(GUEST_DND_FN_HG_ACK_OP);
|
---|
85 | RT_CASE_RET_STR(GUEST_DND_FN_HG_REQ_DATA);
|
---|
86 | RT_CASE_RET_STR(GUEST_DND_FN_HG_EVT_PROGRESS);
|
---|
87 | RT_CASE_RET_STR(GUEST_DND_FN_GH_ACK_PENDING);
|
---|
88 | RT_CASE_RET_STR(GUEST_DND_FN_GH_SND_DATA_HDR);
|
---|
89 | RT_CASE_RET_STR(GUEST_DND_FN_GH_SND_DATA);
|
---|
90 | RT_CASE_RET_STR(GUEST_DND_FN_GH_SND_DIR);
|
---|
91 | RT_CASE_RET_STR(GUEST_DND_FN_GH_SND_FILE_DATA);
|
---|
92 | RT_CASE_RET_STR(GUEST_DND_FN_GH_SND_FILE_HDR);
|
---|
93 | default:
|
---|
94 | break;
|
---|
95 | }
|
---|
96 | return "unknown";
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Converts a VBOXDNDACTION to a string.
|
---|
101 | *
|
---|
102 | * @returns Stringified version of VBOXDNDACTION
|
---|
103 | * @param uAction DnD action to convert.
|
---|
104 | */
|
---|
105 | const char *DnDActionToStr(VBOXDNDACTION uAction)
|
---|
106 | {
|
---|
107 | switch (uAction)
|
---|
108 | {
|
---|
109 | case VBOX_DND_ACTION_IGNORE: return "ignore";
|
---|
110 | case VBOX_DND_ACTION_COPY: return "copy";
|
---|
111 | case VBOX_DND_ACTION_MOVE: return "move";
|
---|
112 | case VBOX_DND_ACTION_LINK: return "link";
|
---|
113 | default:
|
---|
114 | break;
|
---|
115 | }
|
---|
116 | AssertMsgFailedReturn(("Unknown uAction=%d\n", uAction), "bad");
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Converts a VBOXDNDACTIONLIST to a string.
|
---|
121 | *
|
---|
122 | * @returns Stringified version of VBOXDNDACTIONLIST. Must be free'd by the caller using RTStrFree().
|
---|
123 | * @retval NULL on allocation failure.
|
---|
124 | * @retval "<None>" if no (valid) actions found.
|
---|
125 | * @param fActionList DnD action list to convert.
|
---|
126 | */
|
---|
127 | char *DnDActionListToStrA(VBOXDNDACTIONLIST fActionList)
|
---|
128 | {
|
---|
129 | char *pszList = NULL;
|
---|
130 |
|
---|
131 | #define HANDLE_ACTION(a_Action) \
|
---|
132 | if (fActionList & a_Action) \
|
---|
133 | { \
|
---|
134 | if (pszList) \
|
---|
135 | AssertRCReturn(RTStrAAppend(&pszList, ", "), NULL); \
|
---|
136 | AssertRCReturn(RTStrAAppend(&pszList, DnDActionToStr(a_Action)), NULL); \
|
---|
137 | }
|
---|
138 |
|
---|
139 | HANDLE_ACTION(VBOX_DND_ACTION_IGNORE);
|
---|
140 | HANDLE_ACTION(VBOX_DND_ACTION_COPY);
|
---|
141 | HANDLE_ACTION(VBOX_DND_ACTION_MOVE);
|
---|
142 | HANDLE_ACTION(VBOX_DND_ACTION_LINK);
|
---|
143 |
|
---|
144 | #undef HANDLE_ACTION
|
---|
145 |
|
---|
146 | if (!pszList)
|
---|
147 | AssertRCReturn(RTStrAAppend(&pszList, "<None>"), NULL);
|
---|
148 |
|
---|
149 | return pszList;
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Converts a VBOXDNDSTATE to a string.
|
---|
154 | *
|
---|
155 | * @returns Stringified version of VBOXDNDSTATE.
|
---|
156 | * @param enmState DnD state to convert.
|
---|
157 | */
|
---|
158 | const char *DnDStateToStr(VBOXDNDSTATE enmState)
|
---|
159 | {
|
---|
160 | switch (enmState)
|
---|
161 | {
|
---|
162 | case VBOXDNDSTATE_UNKNOWN: return "unknown";
|
---|
163 | case VBOXDNDSTATE_ENTERED: return "entered VM window";
|
---|
164 | case VBOXDNDSTATE_LEFT: return "left VM window";
|
---|
165 | case VBOXDNDSTATE_QUERY_FORMATS: return "querying formats";
|
---|
166 | case VBOXDNDSTATE_QUERY_STATUS: return "querying status";
|
---|
167 | case VBOXDNDSTATE_DRAGGING: return "dragging";
|
---|
168 | case VBOXDNDSTATE_DROP_STARTED: return "drop started";
|
---|
169 | case VBOXDNDSTATE_DROP_ENDED: return "drop ended";
|
---|
170 | case VBOXDNDSTATE_CANCELLED: return "cancelled";
|
---|
171 | case VBOXDNDSTATE_ERROR: return "error";
|
---|
172 | default:
|
---|
173 | break;
|
---|
174 | }
|
---|
175 | AssertMsgFailedReturn(("Unknown enmState=%d\n", enmState), "bad");
|
---|
176 | }
|
---|
177 |
|
---|