shlwapi/tests: Link directly to Url*() functions.
[wine.git] / dlls / shell32 / clipboard.c
blob2f5c63bed9dd5b2267ee9b14685979821a0f1b0e
1 /*
2 * clipboard helper functions
4 * Copyright 2000 Juergen Schmied <juergen.schmied@debitel.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * 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
20 * NOTES:
22 * For copy & paste functions within contextmenus does the shell use
23 * the OLE clipboard functions in combination with dataobjects.
24 * The OLE32.DLL gets loaded with LoadLibrary
26 * - a right mousebutton-copy sets the following formats:
27 * classic:
28 * Shell IDList Array
29 * Preferred Drop Effect
30 * Shell Object Offsets
31 * HDROP
32 * FileName
33 * ole:
34 * OlePrivateData (ClipboardDataObjectInterface)
38 #include <stdarg.h>
39 #include <string.h>
41 #include "windef.h"
42 #include "winbase.h"
43 #include "winreg.h"
44 #include "wingdi.h"
45 #include "pidl.h"
46 #include "shell32_main.h"
47 #include "shlwapi.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(shell);
53 /**************************************************************************
54 * RenderHDROP
56 * creates a CF_HDROP structure
58 HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
60 UINT i;
61 int rootlen = 0,size = 0;
62 WCHAR wszRootPath[MAX_PATH];
63 WCHAR wszFileName[MAX_PATH];
64 HGLOBAL hGlobal;
65 DROPFILES *pDropFiles;
66 int offset;
68 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
70 /* get the size needed */
71 size = sizeof(DROPFILES);
73 SHGetPathFromIDListW(pidlRoot, wszRootPath);
74 PathAddBackslashW(wszRootPath);
75 rootlen = lstrlenW(wszRootPath);
77 for (i=0; i<cidl;i++)
79 _ILSimpleGetTextW(apidl[i], wszFileName, MAX_PATH);
80 size += (rootlen + lstrlenW(wszFileName) + 1) * sizeof(WCHAR);
83 size += sizeof(WCHAR);
85 /* Fill the structure */
86 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
87 if(!hGlobal) return hGlobal;
89 pDropFiles = GlobalLock(hGlobal);
90 offset = (sizeof(DROPFILES) + sizeof(WCHAR) - 1) / sizeof(WCHAR);
91 pDropFiles->pFiles = offset * sizeof(WCHAR);
92 pDropFiles->fWide = TRUE;
94 lstrcpyW(wszFileName, wszRootPath);
96 for (i=0; i<cidl;i++)
99 _ILSimpleGetTextW(apidl[i], wszFileName + rootlen, MAX_PATH - rootlen);
100 lstrcpyW(((WCHAR*)pDropFiles)+offset, wszFileName);
101 offset += lstrlenW(wszFileName) + 1;
104 ((WCHAR*)pDropFiles)[offset] = 0;
105 GlobalUnlock(hGlobal);
107 return hGlobal;
110 HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
112 UINT i;
113 int offset = 0, sizePidl, size;
114 HGLOBAL hGlobal;
115 LPIDA pcida;
117 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
119 /* get the size needed */
120 size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */
121 size += ILGetSize (pidlRoot); /* root pidl */
122 for(i=0; i<cidl; i++)
124 size += ILGetSize(apidl[i]); /* child pidls */
127 /* fill the structure */
128 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
129 if(!hGlobal) return hGlobal;
130 pcida = GlobalLock (hGlobal);
131 pcida->cidl = cidl;
133 /* root pidl */
134 offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
135 pcida->aoffset[0] = offset; /* first element */
136 sizePidl = ILGetSize (pidlRoot);
137 memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
138 offset += sizePidl;
140 for(i=0; i<cidl; i++) /* child pidls */
142 pcida->aoffset[i+1] = offset;
143 sizePidl = ILGetSize(apidl[i]);
144 memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
145 offset += sizePidl;
148 GlobalUnlock(hGlobal);
149 return hGlobal;
152 HGLOBAL RenderFILENAMEA (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
154 int size = 0;
155 char szTemp[MAX_PATH], *szFileName;
156 LPITEMIDLIST pidl;
157 HGLOBAL hGlobal;
158 BOOL bSuccess;
160 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
162 /* get path of combined pidl */
163 pidl = ILCombine(pidlRoot, apidl[0]);
164 if (!pidl)
165 return 0;
167 bSuccess = SHGetPathFromIDListA(pidl, szTemp);
168 SHFree(pidl);
169 if (!bSuccess)
170 return 0;
172 size = strlen(szTemp) + 1;
174 /* fill the structure */
175 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
176 if(!hGlobal) return hGlobal;
177 szFileName = GlobalLock(hGlobal);
178 memcpy(szFileName, szTemp, size);
179 GlobalUnlock(hGlobal);
181 return hGlobal;
184 HGLOBAL RenderFILENAMEW (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
186 int size = 0;
187 WCHAR szTemp[MAX_PATH], *szFileName;
188 LPITEMIDLIST pidl;
189 HGLOBAL hGlobal;
190 BOOL bSuccess;
192 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
194 /* get path of combined pidl */
195 pidl = ILCombine(pidlRoot, apidl[0]);
196 if (!pidl)
197 return 0;
199 bSuccess = SHGetPathFromIDListW(pidl, szTemp);
200 SHFree(pidl);
201 if (!bSuccess)
202 return 0;
204 size = (lstrlenW(szTemp)+1) * sizeof(WCHAR);
206 /* fill the structure */
207 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
208 if(!hGlobal) return hGlobal;
209 szFileName = GlobalLock(hGlobal);
210 memcpy(szFileName, szTemp, size);
211 GlobalUnlock(hGlobal);
213 return hGlobal;