1 | /* $Id: clipboard-helper.h 80285 2019-08-15 09:11:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Some helper function for converting between the various EOLs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef VBOX_INCLUDED_GuestHost_clipboard_helper_h
|
---|
28 | #define VBOX_INCLUDED_GuestHost_clipboard_helper_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/string.h>
|
---|
34 |
|
---|
35 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
36 |
|
---|
37 | /** Constants needed for string conversions done by the Linux/Mac clipboard code. */
|
---|
38 | enum {
|
---|
39 | /** In Linux, lines end with a linefeed character. */
|
---|
40 | LINEFEED = 0xa,
|
---|
41 | /** In Windows, lines end with a carriage return and a linefeed character. */
|
---|
42 | CARRIAGERETURN = 0xd,
|
---|
43 | /** Little endian "real" UTF-16 strings start with this marker. */
|
---|
44 | UTF16LEMARKER = 0xfeff,
|
---|
45 | /** Big endian "real" UTF-16 strings start with this marker. */
|
---|
46 | UTF16BEMARKER = 0xfffe
|
---|
47 | };
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Get the size of the buffer needed to hold a UTF-16-LE zero terminated string
|
---|
51 | * with Windows EOLs converted from a UTF-16 string with Linux EOLs.
|
---|
52 | *
|
---|
53 | * @returns VBox status code.
|
---|
54 | *
|
---|
55 | * @param pwszSrc The source UTF-16 string.
|
---|
56 | * @param cwcSrc The length of the source string in RTUTF16 units.
|
---|
57 | * @param pcwcDst The length of the destination string in RTUTF16 units.
|
---|
58 | */
|
---|
59 | int vboxClipboardUtf16GetWinSize(PRTUTF16 pwszSrc, size_t cwcSrc, size_t *pcwcDst);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Convert a UTF-16 text with Linux EOLs to null-terminated UTF-16-LE with
|
---|
63 | * Windows EOLs.
|
---|
64 | *
|
---|
65 | * Does no checking for validity.
|
---|
66 | *
|
---|
67 | * @returns VBox status code
|
---|
68 | *
|
---|
69 | * @param pwszSrc Source UTF-16 text to convert.
|
---|
70 | * @param cwcSrc Size of the source text int RTUTF16 units
|
---|
71 | * @param pwszDst Buffer to store the converted text to.
|
---|
72 | * @param cwcDst Size of the buffer for the converted text in RTUTF16 units.
|
---|
73 | */
|
---|
74 | int vboxClipboardUtf16LinToWin(PRTUTF16 pwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Get the size of the buffer needed to hold a zero-terminated UTF-16 string
|
---|
78 | * with Linux EOLs converted from a UTF-16 string with Windows EOLs.
|
---|
79 | *
|
---|
80 | * @returns RT status code
|
---|
81 | *
|
---|
82 | * @param pwszSrc The source UTF-16 string
|
---|
83 | * @param cwcSrc The length of the source string in RTUTF16 units.
|
---|
84 | * @retval pcwcDst The length of the destination string in RTUTF16 units.
|
---|
85 | */
|
---|
86 | int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwcSrc, size_t *pcwcDst);
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Convert UTF-16-LE text with Windows EOLs to zero-terminated UTF-16 with Linux
|
---|
90 | * EOLs. This function does not verify that the UTF-16 is valid.
|
---|
91 | *
|
---|
92 | * @returns VBox status code
|
---|
93 | *
|
---|
94 | * @param pwszSrc Text to convert
|
---|
95 | * @param cwcSrc Size of the source text in RTUTF16 units.
|
---|
96 | * @param pwszDst The buffer to store the converted text to
|
---|
97 | * @param cwcDst The size of the buffer for the destination text in RTUTF16
|
---|
98 | * chars.
|
---|
99 | */
|
---|
100 | int vboxClipboardUtf16WinToLin(PRTUTF16 pwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
101 |
|
---|
102 | #pragma pack(1)
|
---|
103 | /** @todo r=bird: Why duplicate these structures here, we've got them in
|
---|
104 | * DevVGA.cpp already! */
|
---|
105 | /**
|
---|
106 | * Bitmap File Header. Official win32 name is BITMAPFILEHEADER
|
---|
107 | * Always Little Endian.
|
---|
108 | */
|
---|
109 | typedef struct BMFILEHEADER
|
---|
110 | {
|
---|
111 | /** @todo r=bird: this type centric prefixing is what give hungarian notation a bad name... */
|
---|
112 | uint16_t u16Type;
|
---|
113 | uint32_t u32Size;
|
---|
114 | uint16_t u16Reserved1;
|
---|
115 | uint16_t u16Reserved2;
|
---|
116 | uint32_t u32OffBits;
|
---|
117 | } BMFILEHEADER;
|
---|
118 | /** Pointer to a BMFILEHEADER structure. */
|
---|
119 | typedef BMFILEHEADER *PBMFILEHEADER;
|
---|
120 | /** BMP file magic number */
|
---|
121 | #define BITMAPHEADERMAGIC (RT_H2LE_U16_C(0x4d42))
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Bitmap Info Header. Official win32 name is BITMAPINFOHEADER
|
---|
125 | * Always Little Endian.
|
---|
126 | */
|
---|
127 | typedef struct BMINFOHEADER
|
---|
128 | {
|
---|
129 | /** @todo r=bird: this type centric prefixing is what give hungarian notation a bad name... */
|
---|
130 | uint32_t u32Size;
|
---|
131 | uint32_t u32Width;
|
---|
132 | uint32_t u32Height;
|
---|
133 | uint16_t u16Planes;
|
---|
134 | uint16_t u16BitCount;
|
---|
135 | uint32_t u32Compression;
|
---|
136 | uint32_t u32SizeImage;
|
---|
137 | uint32_t u32XBitsPerMeter;
|
---|
138 | uint32_t u32YBitsPerMeter;
|
---|
139 | uint32_t u32ClrUsed;
|
---|
140 | uint32_t u32ClrImportant;
|
---|
141 | } BMINFOHEADER;
|
---|
142 | /** Pointer to a BMINFOHEADER structure. */
|
---|
143 | typedef BMINFOHEADER *PBMINFOHEADER;
|
---|
144 | #pragma pack() /** @todo r=bird: Only BMFILEHEADER needs packing. The BMINFOHEADER is perfectly aligned. */
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Convert CF_DIB data to full BMP data by prepending the BM header.
|
---|
148 | * Allocates with RTMemAlloc.
|
---|
149 | *
|
---|
150 | * @returns VBox status code
|
---|
151 | *
|
---|
152 | * @param pvSrc DIB data to convert
|
---|
153 | * @param cbSrc Size of the DIB data to convert in bytes
|
---|
154 | * @param ppvDst Where to store the pointer to the buffer for the
|
---|
155 | * destination data
|
---|
156 | * @param pcbDst Pointer to the size of the buffer for the destination
|
---|
157 | * data in bytes.
|
---|
158 | */
|
---|
159 | int vboxClipboardDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
|
---|
163 | * Does not do any allocation.
|
---|
164 | *
|
---|
165 | * @returns VBox status code
|
---|
166 | *
|
---|
167 | * @param pvSrc BMP data to convert
|
---|
168 | * @param cbSrc Size of the BMP data to convert in bytes
|
---|
169 | * @param ppvDst Where to store the pointer to the destination data
|
---|
170 | * @param pcbDst Pointer to the size of the destination data in bytes
|
---|
171 | */
|
---|
172 | int vboxClipboardBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
|
---|
173 |
|
---|
174 | #ifdef LOG_ENABLED
|
---|
175 | /**
|
---|
176 | * Dumps HTML data to the debug log.
|
---|
177 | *
|
---|
178 | * @returns VBox status code.
|
---|
179 | * @param pszSrc HTML data to dump.
|
---|
180 | * @param cbSrc Size (in bytes) of HTML data to dump.
|
---|
181 | */
|
---|
182 | int VBoxClipboardDbgDumpHtml(const char *pszSrc, size_t cbSrc);
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Dumps data using a specified clipboard format.
|
---|
186 | *
|
---|
187 | * @param pv Pointer to data to dump.
|
---|
188 | * @param cb Size (in bytes) of data to dump.
|
---|
189 | * @param u32Format Clipboard format to use for dumping.
|
---|
190 | */
|
---|
191 | void VBoxClipboardDbgDumpData(const void *pv, size_t cb, VBOXCLIPBOARDFORMAT u32Format);
|
---|
192 | #endif /* LOG_ENABLED */
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Translates a Shared Clipboard host message enum to a string.
|
---|
196 | *
|
---|
197 | * @returns Message ID string name.
|
---|
198 | * @param uMsg The message to translate.
|
---|
199 | */
|
---|
200 | const char *VBoxClipboardHostMsgToStr(uint32_t uMsg);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Translates a Shared Clipboard guest message enum to a string.
|
---|
204 | *
|
---|
205 | * @returns Message ID string name.
|
---|
206 | * @param uMsg The message to translate.
|
---|
207 | */
|
---|
208 | const char *VBoxClipboardGuestMsgToStr(uint32_t uMsg);
|
---|
209 |
|
---|
210 | #endif /* !VBOX_INCLUDED_GuestHost_clipboard_helper_h */
|
---|
211 |
|
---|