Author: hbelusca
Date: Sat Feb 13 20:57:39 2016
New Revision: 70735
URL:
http://svn.reactos.org/svn/reactos?rev=70735&view=rev
Log:
[CLIPBRD]: Finish the implementation of clipboard write file support. There may be room
for improvements.
CORE-10852 #resolve
Modified:
trunk/reactos/base/applications/clipbrd/clipbrd.c
trunk/reactos/base/applications/clipbrd/cliputils.c
trunk/reactos/base/applications/clipbrd/cliputils.h
trunk/reactos/base/applications/clipbrd/fileutils.c
Modified: trunk/reactos/base/applications/clipbrd/clipbrd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/clipbrd/…
==============================================================================
--- trunk/reactos/base/applications/clipbrd/clipbrd.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/clipbrd/clipbrd.c [iso-8859-1] Sat Feb 13 20:57:39
2016
@@ -193,7 +193,7 @@
uFormat = EnumClipboardFormats(0);
while (uFormat)
{
- RetrieveClipboardFormatName(Globals.hInstance, uFormat, szFormatName,
ARRAYSIZE(szFormatName));
+ RetrieveClipboardFormatName(Globals.hInstance, uFormat, TRUE, szFormatName,
ARRAYSIZE(szFormatName));
if (!IsClipboardFormatSupported(uFormat))
{
Modified: trunk/reactos/base/applications/clipbrd/cliputils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/clipbrd/…
==============================================================================
--- trunk/reactos/base/applications/clipbrd/cliputils.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/clipbrd/cliputils.c [iso-8859-1] Sat Feb 13 20:57:39
2016
@@ -8,73 +8,61 @@
#include "precomp.h"
-int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR
lpszFormat, UINT cch)
+static int
+GetPredefinedClipboardFormatName(HINSTANCE hInstance,
+ UINT uFormat,
+ BOOL Unicode,
+ PVOID lpszFormat,
+ UINT cch)
{
+ static
+ struct FORMAT_NAME
+ {
+ UINT uFormat;
+ UINT uResID;
+ } uFormatList[] = {
+ /* Table sorted in increasing order of CF_xxx values, please keep it this way! */
+ {CF_TEXT , STRING_CF_TEXT }, // 1
+ {CF_BITMAP , STRING_CF_BITMAP }, // 2
+ {CF_METAFILEPICT, STRING_CF_METAFILEPICT}, // 3
+ {CF_SYLK , STRING_CF_SYLK }, // 4
+ {CF_DIF , STRING_CF_DIF }, // 5
+ {CF_TIFF , 0/*STRING_CF_TIFF*/ }, // 6
+ {CF_OEMTEXT , STRING_CF_OEMTEXT }, // 7
+ {CF_DIB , STRING_CF_DIB }, // 8
+ {CF_PALETTE , STRING_CF_PALETTE }, // 9
+ {CF_PENDATA , 0/*STRING_CF_PENDATA*/ }, // 10
+ {CF_RIFF , 0/*STRING_CF_RIFF*/ }, // 11
+ {CF_WAVE , 0/*STRING_CF_WAVE*/ }, // 12
+ {CF_UNICODETEXT , STRING_CF_UNICODETEXT }, // 13
+ {CF_ENHMETAFILE , STRING_CF_ENHMETAFILE }, // 14
+#if(WINVER >= 0x0400)
+ {CF_HDROP , STRING_CF_HDROP }, // 15
+ {CF_LOCALE , STRING_CF_LOCALE }, // 16
+#endif
+#if(WINVER >= 0x0500)
+ {CF_DIBV5 , STRING_CF_DIBV5 }, // 17
+#endif
+ };
+
switch (uFormat)
{
- case CF_TEXT:
+ case CF_TEXT: case CF_BITMAP: case CF_METAFILEPICT:
+ case CF_SYLK: case CF_DIF: // case CF_TIFF:
+ case CF_OEMTEXT: case CF_DIB: case CF_PALETTE:
+ // case CF_PENDATA: // case CF_RIFF: // case CF_WAVE:
+ case CF_UNICODETEXT: case CF_ENHMETAFILE:
+#if(WINVER >= 0x0400)
+ case CF_HDROP: case CF_LOCALE:
+#endif
+#if(WINVER >= 0x0500)
+ case CF_DIBV5:
+#endif
{
- return LoadStringW(hInstance, STRING_CF_TEXT, lpszFormat, cch);
- }
-
- case CF_BITMAP:
- {
- return LoadStringW(hInstance, STRING_CF_BITMAP, lpszFormat, cch);
- }
-
- case CF_OEMTEXT:
- {
- return LoadStringW(hInstance, STRING_CF_OEMTEXT, lpszFormat, cch);
- }
-
- case CF_UNICODETEXT:
- {
- return LoadStringW(hInstance, STRING_CF_UNICODETEXT, lpszFormat, cch);
- }
-
- case CF_DIB:
- {
- return LoadStringW(hInstance, STRING_CF_DIB, lpszFormat, cch);
- }
-
- case CF_LOCALE:
- {
- return LoadStringW(hInstance, STRING_CF_LOCALE, lpszFormat, cch);
- }
-
- case CF_ENHMETAFILE:
- {
- return LoadStringW(hInstance, STRING_CF_ENHMETAFILE, lpszFormat, cch);
- }
-
- case CF_METAFILEPICT:
- {
- return LoadStringW(hInstance, STRING_CF_METAFILEPICT, lpszFormat, cch);
- }
-
- case CF_PALETTE:
- {
- return LoadStringW(hInstance, STRING_CF_PALETTE, lpszFormat, cch);
- }
-
- case CF_DIBV5:
- {
- return LoadStringW(hInstance, STRING_CF_DIBV5, lpszFormat, cch);
- }
-
- case CF_SYLK:
- {
- return LoadStringW(hInstance, STRING_CF_SYLK, lpszFormat, cch);
- }
-
- case CF_DIF:
- {
- return LoadStringW(hInstance, STRING_CF_DIF, lpszFormat, cch);
- }
-
- case CF_HDROP:
- {
- return LoadStringW(hInstance, STRING_CF_HDROP, lpszFormat, cch);
+ if (Unicode)
+ return LoadStringW(hInstance, uFormatList[uFormat-1].uResID,
(LPWSTR)lpszFormat, cch);
+ else
+ return LoadStringA(hInstance, uFormatList[uFormat-1].uResID,
(LPSTR)lpszFormat, cch);
}
default:
@@ -84,13 +72,24 @@
}
}
-void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR lpszFormat,
UINT cch)
+void
+RetrieveClipboardFormatName(HINSTANCE hInstance,
+ UINT uFormat,
+ BOOL Unicode,
+ PVOID lpszFormat,
+ UINT cch)
{
- if (!GetPredefinedClipboardFormatName(hInstance, uFormat, lpszFormat, cch))
+ if (!GetPredefinedClipboardFormatName(hInstance, uFormat, Unicode, lpszFormat, cch))
{
- if (!GetClipboardFormatNameW(uFormat, lpszFormat, cch))
+ if (Unicode)
{
- LoadStringW(hInstance, STRING_CF_UNKNOWN, lpszFormat, cch);
+ if (!GetClipboardFormatNameW(uFormat, (LPWSTR)lpszFormat, cch))
+ LoadStringW(hInstance, STRING_CF_UNKNOWN, (LPWSTR)lpszFormat, cch);
+ }
+ else
+ {
+ if (!GetClipboardFormatNameA(uFormat, (LPSTR)lpszFormat, cch))
+ LoadStringA(hInstance, STRING_CF_UNKNOWN, (LPSTR)lpszFormat, cch);
}
}
}
Modified: trunk/reactos/base/applications/clipbrd/cliputils.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/clipbrd/…
==============================================================================
--- trunk/reactos/base/applications/clipbrd/cliputils.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/clipbrd/cliputils.h [iso-8859-1] Sat Feb 13 20:57:39
2016
@@ -6,8 +6,13 @@
* PROGRAMMERS: Ricardo Hanke
*/
-int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR
lpszFormat, UINT cch);
-void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPWSTR lpszFormat,
UINT cch);
+void
+RetrieveClipboardFormatName(HINSTANCE hInstance,
+ UINT uFormat,
+ BOOL Unicode,
+ PVOID lpszFormat,
+ UINT cch);
+
void DeleteClipboardContent(void);
UINT GetAutomaticClipboardFormat(void);
BOOL IsClipboardFormatSupported(UINT uFormat);
Modified: trunk/reactos/base/applications/clipbrd/fileutils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/clipbrd/…
==============================================================================
--- trunk/reactos/base/applications/clipbrd/fileutils.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/clipbrd/fileutils.c [iso-8859-1] Sat Feb 13 20:57:39
2016
@@ -81,6 +81,39 @@
return TRUE;
}
+static BOOL ClipboardWriteMemory(HANDLE hFile, DWORD dwFormat, DWORD dwOffset, PDWORD
pdwLength)
+{
+ HGLOBAL hData;
+ LPVOID lpData;
+ DWORD dwBytesWritten;
+
+ hData = GetClipboardData(dwFormat);
+ if (!hData)
+ return FALSE;
+
+ lpData = GlobalLock(hData);
+ if (!lpData)
+ return FALSE;
+
+ *pdwLength = GlobalSize(hData);
+
+ if (SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
+ {
+ GlobalUnlock(hData);
+ return FALSE;
+ }
+
+ if (!WriteFile(hFile, lpData, *pdwLength, &dwBytesWritten, NULL))
+ {
+ GlobalUnlock(hData);
+ return FALSE;
+ }
+
+ GlobalUnlock(hData);
+
+ return TRUE;
+}
+
static BOOL ClipboardReadPalette(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
{
LPLOGPALETTE lpPalette;
@@ -286,7 +319,6 @@
SizeOfFormatHeader = sizeof(CLIPFORMATHEADER);
pClipFileHeader = &ClipFileHeader;
pClipFormatArray = &ClipFormatArray;
- // MessageBox(Globals.hMainWnd, L"We have a Win3.11 clipboard
file!", L"File format", 0);
break;
case CLIP_FMT_NT:
@@ -295,7 +327,6 @@
SizeOfFormatHeader = sizeof(NTCLIPFORMATHEADER);
pClipFileHeader = &NtClipFileHeader;
pClipFormatArray = &NtClipFormatArray;
- // MessageBox(Globals.hMainWnd, L"We have a WinNT clipboard file!",
L"File format", 0);
break;
default:
@@ -436,8 +467,6 @@
DWORD dwBytesWritten;
int i;
- WCHAR szFormatName[MAX_FMT_NAME_LEN];
-
/* Create the file for write access */
hFile = CreateFileW(lpFileName, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -457,7 +486,6 @@
SizeOfFormatHeader = sizeof(CLIPFORMATHEADER);
pClipFileHeader = &ClipFileHeader;
pClipFormatArray = &ClipFormatArray;
- // MessageBox(Globals.hMainWnd, L"We write a Win3.11 clipboard
file!", L"File format", 0);
ClipFileHeader.wFileIdentifier = CLIP_FMT_31; // wFileIdentifier
ClipFileHeader.wFormatCount = wFormatCount;
@@ -469,7 +497,6 @@
SizeOfFormatHeader = sizeof(NTCLIPFORMATHEADER);
pClipFileHeader = &NtClipFileHeader;
pClipFormatArray = &NtClipFormatArray;
- // MessageBox(Globals.hMainWnd, L"We write a WinNT clipboard
file!", L"File format", 0);
NtClipFileHeader.wFileIdentifier = CLIP_FMT_NT; // wFileIdentifier
NtClipFileHeader.wFormatCount = wFormatCount;
@@ -497,35 +524,43 @@
dwFormatID = EnumClipboardFormats(0);
while (dwFormatID)
{
- if (i >= wFormatCount) assert(FALSE); // break;
-
- RetrieveClipboardFormatName(Globals.hInstance, dwFormatID, szFormatName,
ARRAYSIZE(szFormatName));
-
- // TODO: Copy the format name string into the format header,
- // possibly converting into ANSI for Win3.1 format, and render
- // in the file the different type of data. From the renderers
- // we retrieve the real size of the data into 'dwLenData'.
- /* TODO: Write the data stream at 'dwOffData' */
- dwLenData = 0;
-
- /* Write format data */
+ if (i >= wFormatCount)
+ {
+ /* Must never happen! */
+ assert(FALSE);
+ break;
+ }
+
+ /* Write the clipboard data at the specified offset, and retrieve its length */
+ if (!ClipboardWriteMemory(hFile, dwFormatID, dwOffData, &dwLenData))
+ goto Cont;
+
+ /* Write the format data header */
switch (wFileIdentifier)
{
case CLIP_FMT_31:
+ ZeroMemory(pClipFormatArray, sizeof(CLIPFORMATHEADER));
((CLIPFORMATHEADER*)pClipFormatArray)->dwFormatID = dwFormatID;
((CLIPFORMATHEADER*)pClipFormatArray)->dwLenData = dwLenData;
((CLIPFORMATHEADER*)pClipFormatArray)->dwOffData = dwOffData;
- // szName = ((CLIPFORMATHEADER*)pClipFormatArray)->szName;
- ZeroMemory( ((CLIPFORMATHEADER*)pClipFormatArray)->szName ,
sizeof(((CLIPFORMATHEADER*)pClipFormatArray)->szName) );
+ RetrieveClipboardFormatName(Globals.hInstance,
+ dwFormatID,
+ FALSE,
+
((CLIPFORMATHEADER*)pClipFormatArray)->szName,
+
ARRAYSIZE(((CLIPFORMATHEADER*)pClipFormatArray)->szName));
break;
case CLIP_FMT_NT:
case CLIP_FMT_BK:
+ ZeroMemory(pClipFormatArray, sizeof(NTCLIPFORMATHEADER));
((NTCLIPFORMATHEADER*)pClipFormatArray)->dwFormatID = dwFormatID;
((NTCLIPFORMATHEADER*)pClipFormatArray)->dwLenData = dwLenData;
((NTCLIPFORMATHEADER*)pClipFormatArray)->dwOffData = dwOffData;
- // szName = ((NTCLIPFORMATHEADER*)pClipFormatArray)->szName;
- ZeroMemory( ((NTCLIPFORMATHEADER*)pClipFormatArray)->szName ,
sizeof(((NTCLIPFORMATHEADER*)pClipFormatArray)->szName) );
+ RetrieveClipboardFormatName(Globals.hInstance,
+ dwFormatID,
+ TRUE,
+
((NTCLIPFORMATHEADER*)pClipFormatArray)->szName,
+
ARRAYSIZE(((NTCLIPFORMATHEADER*)pClipFormatArray)->szName));
break;
}
@@ -544,6 +579,7 @@
/* Adjust the offset for the next data stream */
dwOffData += dwLenData;
+Cont:
i++;
dwFormatID = EnumClipboardFormats(dwFormatID);
}