VirtualBox

source: vbox/trunk/include/VBox/GuestHost/clipboard-helper.h@ 104429

Last change on this file since 104429 was 101878, checked in by vboxsync, 10 months ago

Additions: X11/Wayland: Add initial support for clipboard sharing with Gnome and Plasma Wayland guests (not yet enabled), bugref:10194.

  • Property eol-style set to native
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 10.1 KB
Line 
1/* $Id: clipboard-helper.h 101878 2023-11-06 15:36:24Z vboxsync $ */
2/** @file
3 * Shared Clipboard - Some helper function for converting between the various EOLs.
4 */
5
6/*
7 * Copyright (C) 2006-2023 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 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef VBOX_INCLUDED_GuestHost_clipboard_helper_h
38#define VBOX_INCLUDED_GuestHost_clipboard_helper_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/string.h>
44
45#include <VBox/GuestHost/SharedClipboard.h>
46
47/** Guest property which is set by GUI in order to notify guest about VM window focus change. */
48#define VBOX_GUI_FOCUS_CHANGE_GUEST_PROP_NAME "/VirtualBox/GuestAdd/GuiOnFocus"
49
50/** Constants needed for string conversions done by the Linux/Mac clipboard code. */
51enum
52{
53 /** In Linux, lines end with a linefeed character. */
54 VBOX_SHCL_LINEFEED = 0xa,
55 /** In Windows, lines end with a carriage return and a linefeed character. */
56 VBOX_SHCL_CARRIAGERETURN = 0xd,
57 /** Little endian "real" UTF-16 strings start with this marker. */
58 VBOX_SHCL_UTF16LEMARKER = 0xfeff,
59 /** Big endian "real" UTF-16 strings start with this marker. */
60 VBOX_SHCL_UTF16BEMARKER = 0xfffe
61};
62
63/**
64 * Returns the length (in UTF-8 characters) of an UTF-16 string with LF EOL.
65 *
66 * @returns VBox status code.
67 * @param pcwszSrc UTF-16 string to return size for.
68 * @param cwcSrc Length of the string in RTUTF16 units.
69 * @param pchLen Where to return the length (in UTF-8 characters).
70 * Does not include terminator.
71 */
72int ShClUtf16LFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
73
74/**
75 * Returns the length (in UTF-8 characters) of an UTF-16 string with CRLF EOL.
76 *
77 * @returns VBox status code.
78 * @param pcwszSrc UTF-16 string to return size for.
79 * @param cwcSrc Length of the source string in RTUTF16 units.
80 * @param pchLen Where to return the length (in UTF-8 characters).
81 * Does not include terminator.
82 */
83int ShClUtf16CRLFLenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
84
85/**
86 * Returns the length (in characters) of an UTF-16 string, including terminator.
87 *
88 * @returns VBox status code.
89 * @param pcwszSrc UTF-16 string to return size for.
90 * @param cwcSrc Length of the source string in RTUTF16 units.
91 * @param pchLen Where to return the length (in UTF-8 characters).
92 * Does not include terminator.
93 */
94int ShClUtf16LenUtf8(PCRTUTF16 pcwszSrc, size_t cwcSrc, size_t *pchLen);
95
96/**
97 * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
98 *
99 * @returns VBox status code.
100 * @param pcwszSrc UTF-16 string to convert.
101 * @param cwcSrc Size of the string int RTUTF16 units.
102 * @param pwszDst Buffer to store the converted string to.
103 * @param cwcDst The size of \a pwszDst in RTUTF16 units.
104 */
105int ShClConvUtf16LFToCRLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
106
107/**
108 * Converts an UTF-16 string with LF EOL to an UTF-16 string with CRLF EOL.
109 *
110 * Convenience function which returns the allocated + converted string on success.
111 *
112 * @returns VBox status code.
113 * @param pcwszSrc UTF-16 string to convert.
114 * @param cwcSrc Size of the string int RTUTF16 units.
115 * @param ppwszDst Where to return the allocated converted string. Must be free'd by the caller.
116 * @param pcwDst Where to return the size of the converted string in RTUTF16 units.
117 * Does not include the terminator.
118 */
119int ShClConvUtf16LFToCRLFA(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
120
121/**
122 * Converts an UTF-16 string with CRLF EOL to an UTF-16 string with LF EOL.
123 *
124 * @returns VBox status code.
125 * @param pcwszSrc UTF-16 string to convert.
126 * @param cwcSrc Size of the string in RTUTF16 units.
127 * @param pwszDst Where to store the converted string to.
128 * @param cwcDst The size of \a pwszDst in RTUTF16 units.
129 */
130int ShClConvUtf16CRLFToLF(PCRTUTF16 pcwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
131
132/**
133 * Converts an UTF-16 string with CRLF EOL to UTF-8 LF.
134 *
135 * @returns VBox status code. Will return VERR_NO_DATA if no data was converted.
136 * @param pcwszSrc UTF-16 string to convert.
137 * @param cbSrc Length of @a pwszSrc (in bytes).
138 * @param pszBuf Where to write the converted string.
139 * @param cbBuf The size of the buffer pointed to by @a pszBuf.
140 * @param pcbLen Where to store the size (in bytes) of the converted string.
141 * Does not include terminator.
142 */
143int ShClConvUtf16CRLFToUtf8LF(PCRTUTF16 pcwszSrc, size_t cbSrc, char *pszBuf, size_t cbBuf, size_t *pcbLen);
144
145/**
146* Converts an HTML string from UTF-16 into UTF-8.
147*
148* @returns VBox status code.
149* @param pcwszSrc UTF-16 string to convert.
150* @param cwcSrc Length (in RTUTF16 units) of the source text.
151* @param ppszDst Where to store the converted result on success.
152* @param pcbDst Where to store the number of bytes written.
153*/
154int ShClConvUtf16ToUtf8HTML(PCRTUTF16 pcwszSrc, size_t cwcSrc, char **ppszDst, size_t *pcbDst);
155
156/**
157 * Converts an UTF-8 string with LF EOL into UTF-16 CRLF.
158 *
159 * @returns VBox status code.
160 * @param pcszSrc UTF-8 string to convert.
161 * @param cbSrc Size of UTF-8 string to convert (in bytes), not counting the terminating zero.
162 * @param ppwszDst Where to return the allocated buffer on success.
163 * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
164 * Does not include terminator.
165 */
166int ShClConvUtf8LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
167
168/**
169 * Converts a Latin-1 string with LF EOL into UTF-16 CRLF.
170 *
171 * @returns VBox status code.
172 * @param pcszSrc UTF-8 string to convert.
173 * @param cbSrc Size of string (in bytes), not counting the terminating zero.
174 * @param ppwszDst Where to return the allocated buffer on success.
175 * @param pcwDst Where to return the size (in RTUTF16 units) of the allocated buffer on success.
176 * Does not include terminator.
177 */
178int ShClConvLatin1LFToUtf16CRLF(const char *pcszSrc, size_t cbSrc, PRTUTF16 *ppwszDst, size_t *pcwDst);
179
180/**
181 * Convert CF_DIB data to full BMP data by prepending the BM header.
182 * Allocates with RTMemAlloc.
183 *
184 * @returns VBox status code.
185 * @param pvSrc DIB data to convert
186 * @param cbSrc Size of the DIB data to convert in bytes
187 * @param ppvDst Where to store the pointer to the buffer for the
188 * destination data
189 * @param pcbDst Pointer to the size of the buffer for the destination
190 * data in bytes.
191 */
192int ShClDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
193
194/**
195 * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
196 * Does not do any allocation.
197 *
198 * @returns VBox status code.
199 * @param pvSrc BMP data to convert
200 * @param cbSrc Size of the BMP data to convert in bytes
201 * @param ppvDst Where to store the pointer to the destination data
202 * @param pcbDst Pointer to the size of the destination data in bytes
203 */
204int ShClBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
205
206#ifdef LOG_ENABLED
207/**
208 * Dumps HTML data to the debug log.
209 *
210 * @returns VBox status code.
211 * @param pszSrc HTML data to dump.
212 * @param cbSrc Size (in bytes) of HTML data to dump.
213 */
214int ShClDbgDumpHtml(const char *pszSrc, size_t cbSrc);
215
216/**
217 * Dumps data using a specified clipboard format.
218 *
219 * @param pv Pointer to data to dump.
220 * @param cb Size (in bytes) of data to dump.
221 * @param u32Format Clipboard format to use for dumping.
222 */
223void ShClDbgDumpData(const void *pv, size_t cb, SHCLFORMAT u32Format);
224#endif /* LOG_ENABLED */
225
226/**
227 * Translates a Shared Clipboard host function number to a string.
228 *
229 * @returns Function ID string name.
230 * @param uFn The function to translate.
231 */
232const char *ShClHostFunctionToStr(uint32_t uFn);
233
234/**
235 * Translates a Shared Clipboard host message enum to a string.
236 *
237 * @returns Message ID string name.
238 * @param uMsg The message to translate.
239 */
240const char *ShClHostMsgToStr(uint32_t uMsg);
241
242/**
243 * Translates a Shared Clipboard guest message enum to a string.
244 *
245 * @returns Message ID string name.
246 * @param uMsg The message to translate.
247 */
248const char *ShClGuestMsgToStr(uint32_t uMsg);
249
250char *ShClFormatsToStrA(SHCLFORMATS fFormats);
251
252#endif /* !VBOX_INCLUDED_GuestHost_clipboard_helper_h */
253
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette