clipboard.c 5.9 KB
Newer Older
1 2 3 4 5
/*
 *	clipboard helper functions
 *
 *	Copyright 2000	Juergen Schmied <juergen.schmied@debitel.de>
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21
 *
 * NOTES:
 *
22 23 24 25 26 27 28
 * For copy & paste functions within contextmenus does the shell use
 * the OLE clipboard functions in combination with dataobjects.
 * The OLE32.DLL gets loaded with LoadLibrary
 *
 * - a right mousebutton-copy sets the following formats:
 *  classic:
 *	Shell IDList Array
29
 *	Preferred Drop Effect
30 31 32 33 34 35 36 37
 *	Shell Object Offsets
 *	HDROP
 *	FileName
 *  ole:
 *	OlePrivateData (ClipboardDataObjectInterface)
 *
 */

38
#include <stdarg.h>
39 40
#include <string.h>

41 42
#include "windef.h"
#include "winbase.h"
43
#include "winreg.h"
44
#include "wingdi.h"
45
#include "pidl.h"
46
#include "undocshell.h"
47
#include "shell32_main.h"
48
#include "shlwapi.h"
49

50
#include "wine/unicode.h"
51
#include "wine/debug.h"
52

53
WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 55 56 57 58 59 60 61

/**************************************************************************
 * RenderHDROP
 *
 * creates a CF_HDROP structure
 */
HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
{
62
	UINT i;
63 64 65
	int rootlen = 0,size = 0;
	WCHAR wszRootPath[MAX_PATH];
	WCHAR wszFileName[MAX_PATH];
66
	HGLOBAL hGlobal;
67
	DROPFILES *pDropFiles;
68
	int offset;
69

70 71 72
	TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);

	/* get the size needed */
73
	size = sizeof(DROPFILES);
74

75 76 77
	SHGetPathFromIDListW(pidlRoot, wszRootPath);
	PathAddBackslashW(wszRootPath);
	rootlen = strlenW(wszRootPath);
78

79 80
	for (i=0; i<cidl;i++)
	{
81 82
	  _ILSimpleGetTextW(apidl[i], wszFileName, MAX_PATH);
	  size += (rootlen + strlenW(wszFileName) + 1) * sizeof(WCHAR);
83 84
	}

85
	size += sizeof(WCHAR);
86 87 88 89 90

	/* Fill the structure */
	hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
	if(!hGlobal) return hGlobal;

91
        pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
92 93 94
	offset = (sizeof(DROPFILES) + sizeof(WCHAR) - 1) / sizeof(WCHAR);
        pDropFiles->pFiles = offset * sizeof(WCHAR);
        pDropFiles->fWide = TRUE;
95

96
	strcpyW(wszFileName, wszRootPath);
97

98 99
	for (i=0; i<cidl;i++)
	{
100

101 102 103
	  _ILSimpleGetTextW(apidl[i], wszFileName + rootlen, MAX_PATH - rootlen);
	  strcpyW(((WCHAR*)pDropFiles)+offset, wszFileName);
	  offset += strlenW(wszFileName) + 1;
104 105
	}

106
	((WCHAR*)pDropFiles)[offset] = 0;
107 108 109 110 111 112 113
	GlobalUnlock(hGlobal);

	return hGlobal;
}

HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
{
114 115
	UINT i;
	int offset = 0, sizePidl, size;
116
	HGLOBAL hGlobal;
117
	LPIDA	pcida;
118 119 120 121 122 123 124 125 126 127 128 129

	TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);

	/* get the size needed */
	size = sizeof(CIDA) + sizeof (UINT)*(cidl);	/* header */
	size += ILGetSize (pidlRoot);			/* root pidl */
	for(i=0; i<cidl; i++)
	{
	  size += ILGetSize(apidl[i]);			/* child pidls */
	}

	/* fill the structure */
130
	hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
	if(!hGlobal) return hGlobal;
	pcida = GlobalLock (hGlobal);
	pcida->cidl = cidl;

	/* root pidl */
	offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
	pcida->aoffset[0] = offset;			/* first element */
	sizePidl = ILGetSize (pidlRoot);
	memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
	offset += sizePidl;

	for(i=0; i<cidl; i++)				/* child pidls */
	{
	  pcida->aoffset[i+1] = offset;
	  sizePidl = ILGetSize(apidl[i]);
	  memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
	  offset += sizePidl;
	}

	GlobalUnlock(hGlobal);
	return hGlobal;
}

HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
{
	FIXME("\n");
	return 0;
}

HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
{
	FIXME("\n");
	return 0;
}

HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
{
	FIXME("\n");
	return 0;
}

172
HGLOBAL RenderFILENAMEA (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
173
{
174
	int size = 0;
175
	char szTemp[MAX_PATH], *szFileName;
176
	LPITEMIDLIST pidl;
177
	HGLOBAL hGlobal;
178
	BOOL bSuccess;
179

180 181
	TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);

182 183 184 185 186
	/* get path of combined pidl */
	pidl = ILCombine(pidlRoot, apidl[0]);
	if (!pidl)
		return 0;

187
	bSuccess = SHGetPathFromIDListA(pidl, szTemp);
188
	SHFree(pidl);
189
	if (!bSuccess)
190 191
		return 0;

192 193 194 195 196
	size = strlen(szTemp) + 1;

	/* fill the structure */
	hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
	if(!hGlobal) return hGlobal;
197 198 199
	szFileName = (char *)GlobalLock(hGlobal);
	memcpy(szFileName, szTemp, size);
	GlobalUnlock(hGlobal);
200

201 202 203 204 205
	return hGlobal;
}

HGLOBAL RenderFILENAMEW (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
{
206
	int size = 0;
207
	WCHAR szTemp[MAX_PATH], *szFileName;
208
	LPITEMIDLIST pidl;
209
	HGLOBAL hGlobal;
210
	BOOL bSuccess;
211 212 213

	TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);

214 215 216 217 218
	/* get path of combined pidl */
	pidl = ILCombine(pidlRoot, apidl[0]);
	if (!pidl)
		return 0;

219
	bSuccess = SHGetPathFromIDListW(pidl, szTemp);
220
	SHFree(pidl);
221
	if (!bSuccess)
222 223 224
		return 0;

	size = (strlenW(szTemp)+1) * sizeof(WCHAR);
225 226 227 228 229 230

	/* fill the structure */
	hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
	if(!hGlobal) return hGlobal;
	szFileName = (WCHAR *)GlobalLock(hGlobal);
	memcpy(szFileName, szTemp, size);
231
	GlobalUnlock(hGlobal);
232

233 234 235 236 237 238 239
	return hGlobal;
}

HGLOBAL RenderPREFEREDDROPEFFECT (DWORD dwFlags)
{
	DWORD * pdwFlag;
	HGLOBAL hGlobal;
240

241
	TRACE("(0x%08x)\n", dwFlags);
242 243 244 245 246 247 248 249

	hGlobal = GlobalAlloc(GHND|GMEM_SHARE, sizeof(DWORD));
	if(!hGlobal) return hGlobal;
        pdwFlag = (DWORD*)GlobalLock(hGlobal);
	*pdwFlag = dwFlags;
	GlobalUnlock(hGlobal);
	return hGlobal;
}