1 | /* $Id: clipboard-helper.h 62476 2016-07-22 18:23:50Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Some helper function for converting between the various EOLs.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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_GuestHost_clipboard_helper_h
|
---|
28 | #define ___VBox_GuestHost_clipboard_helper_h
|
---|
29 |
|
---|
30 | #include <iprt/string.h>
|
---|
31 |
|
---|
32 | /** Constants needed for string conversions done by the Linux/Mac clipboard code. */
|
---|
33 | enum {
|
---|
34 | /** In Linux, lines end with a linefeed character. */
|
---|
35 | LINEFEED = 0xa,
|
---|
36 | /** In Windows, lines end with a carriage return and a linefeed character. */
|
---|
37 | CARRIAGERETURN = 0xd,
|
---|
38 | /** Little endian "real" UTF-16 strings start with this marker. */
|
---|
39 | UTF16LEMARKER = 0xfeff,
|
---|
40 | /** Big endian "real" UTF-16 strings start with this marker. */
|
---|
41 | UTF16BEMARKER = 0xfffe
|
---|
42 | };
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Get the size of the buffer needed to hold a UTF-16-LE zero terminated string
|
---|
46 | * with Windows EOLs converted from a UTF-16 string with Linux EOLs.
|
---|
47 | *
|
---|
48 | * @returns VBox status code.
|
---|
49 | *
|
---|
50 | * @param pwszSrc The source UTF-16 string.
|
---|
51 | * @param cwcSrc The length of the source string in RTUTF16 units.
|
---|
52 | * @param pcwcDst The length of the destination string in RTUTF16 units.
|
---|
53 | */
|
---|
54 | int vboxClipboardUtf16GetWinSize(PRTUTF16 pwszSrc, size_t cwcSrc, size_t *pcwcDst);
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Convert a UTF-16 text with Linux EOLs to null-terminated UTF-16-LE with
|
---|
58 | * Windows EOLs.
|
---|
59 | *
|
---|
60 | * Does no checking for validity.
|
---|
61 | *
|
---|
62 | * @returns VBox status code
|
---|
63 | *
|
---|
64 | * @param pwszSrc Source UTF-16 text to convert.
|
---|
65 | * @param cwcSrc Size of the source text int RTUTF16 units
|
---|
66 | * @param pwszDst Buffer to store the converted text to.
|
---|
67 | * @param cwcDst Size of the buffer for the converted text in RTUTF16 units.
|
---|
68 | */
|
---|
69 | int vboxClipboardUtf16LinToWin(PRTUTF16 pwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Get the size of the buffer needed to hold a zero-terminated UTF-16 string
|
---|
73 | * with Linux EOLs converted from a UTF-16 string with Windows EOLs.
|
---|
74 | *
|
---|
75 | * @returns RT status code
|
---|
76 | *
|
---|
77 | * @param pwszSrc The source UTF-16 string
|
---|
78 | * @param cwcSrc The length of the source string in RTUTF16 units.
|
---|
79 | * @retval pcwcDst The length of the destination string in RTUTF16 units.
|
---|
80 | */
|
---|
81 | int vboxClipboardUtf16GetLinSize(PRTUTF16 pwszSrc, size_t cwcSrc, size_t *pcwcDst);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Convert UTF-16-LE text with Windows EOLs to zero-terminated UTF-16 with Linux
|
---|
85 | * EOLs. This function does not verify that the UTF-16 is valid.
|
---|
86 | *
|
---|
87 | * @returns VBox status code
|
---|
88 | *
|
---|
89 | * @param pwszSrc Text to convert
|
---|
90 | * @param cwcSrc Size of the source text in RTUTF16 units.
|
---|
91 | * @param pwszDst The buffer to store the converted text to
|
---|
92 | * @param cwcDst The size of the buffer for the destination text in RTUTF16
|
---|
93 | * chars.
|
---|
94 | */
|
---|
95 | int vboxClipboardUtf16WinToLin(PRTUTF16 pwszSrc, size_t cwcSrc, PRTUTF16 pwszDst, size_t cwcDst);
|
---|
96 |
|
---|
97 | #pragma pack(1)
|
---|
98 | /** @todo r=bird: Why duplicate these structures here, we've got them in
|
---|
99 | * DevVGA.cpp already! */
|
---|
100 | /**
|
---|
101 | * Bitmap File Header. Official win32 name is BITMAPFILEHEADER
|
---|
102 | * Always Little Endian.
|
---|
103 | */
|
---|
104 | typedef struct BMFILEHEADER
|
---|
105 | {
|
---|
106 | /** @todo r=bird: this type centric prefixing is what give hungarian notation a bad name... */
|
---|
107 | uint16_t u16Type;
|
---|
108 | uint32_t u32Size;
|
---|
109 | uint16_t u16Reserved1;
|
---|
110 | uint16_t u16Reserved2;
|
---|
111 | uint32_t u32OffBits;
|
---|
112 | } BMFILEHEADER;
|
---|
113 | /** Pointer to a BMFILEHEADER structure. */
|
---|
114 | typedef BMFILEHEADER *PBMFILEHEADER;
|
---|
115 | /** BMP file magic number */
|
---|
116 | #define BITMAPHEADERMAGIC (RT_H2LE_U16_C(0x4d42))
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Bitmap Info Header. Official win32 name is BITMAPINFOHEADER
|
---|
120 | * Always Little Endian.
|
---|
121 | */
|
---|
122 | typedef struct BMINFOHEADER
|
---|
123 | {
|
---|
124 | /** @todo r=bird: this type centric prefixing is what give hungarian notation a bad name... */
|
---|
125 | uint32_t u32Size;
|
---|
126 | uint32_t u32Width;
|
---|
127 | uint32_t u32Height;
|
---|
128 | uint16_t u16Planes;
|
---|
129 | uint16_t u16BitCount;
|
---|
130 | uint32_t u32Compression;
|
---|
131 | uint32_t u32SizeImage;
|
---|
132 | uint32_t u32XBitsPerMeter;
|
---|
133 | uint32_t u32YBitsPerMeter;
|
---|
134 | uint32_t u32ClrUsed;
|
---|
135 | uint32_t u32ClrImportant;
|
---|
136 | } BMINFOHEADER;
|
---|
137 | /** Pointer to a BMINFOHEADER structure. */
|
---|
138 | typedef BMINFOHEADER *PBMINFOHEADER;
|
---|
139 | #pragma pack() /** @todo r=bird: Only BMFILEHEADER needs packing. The BMINFOHEADER is perfectly aligned. */
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Convert CF_DIB data to full BMP data by prepending the BM header.
|
---|
143 | * Allocates with RTMemAlloc.
|
---|
144 | *
|
---|
145 | * @returns VBox status code
|
---|
146 | *
|
---|
147 | * @param pvSrc DIB data to convert
|
---|
148 | * @param cbSrc Size of the DIB data to convert in bytes
|
---|
149 | * @param ppvDst Where to store the pointer to the buffer for the
|
---|
150 | * destination data
|
---|
151 | * @param pcbDst Pointer to the size of the buffer for the destination
|
---|
152 | * data in bytes.
|
---|
153 | */
|
---|
154 | int vboxClipboardDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDst, size_t *pcbDst);
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Get the address and size of CF_DIB data in a full BMP data in the input buffer.
|
---|
158 | * Does not do any allocation.
|
---|
159 | *
|
---|
160 | * @returns VBox status code
|
---|
161 | *
|
---|
162 | * @param pvSrc BMP data to convert
|
---|
163 | * @param cbSrc Size of the BMP data to convert in bytes
|
---|
164 | * @param ppvDst Where to store the pointer to the destination data
|
---|
165 | * @param pcbDst Pointer to the size of the destination data in bytes
|
---|
166 | */
|
---|
167 | int vboxClipboardBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDst, size_t *pcbDst);
|
---|
168 |
|
---|
169 |
|
---|
170 | #endif
|
---|
171 |
|
---|