Merge documentation/status/lzexpand into the lzexpand source.
[wine/multimedia.git] / dlls / shell32 / clipboard.c
blob71948240144a6e2d774119fa76f9cf24a4f52a02
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * Prefered 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 "undocshell.h"
47 #include "shell32_main.h"
48 #include "shlwapi.h"
50 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 HRESULT (WINAPI *pOleInitialize)(LPVOID reserved);
56 void (WINAPI *pOleUninitialize)(void);
57 HRESULT (WINAPI *pRegisterDragDrop)(HWND hwnd, IDropTarget* pDropTarget);
58 HRESULT (WINAPI *pRevokeDragDrop)(HWND hwnd);
59 HRESULT (WINAPI *pDoDragDrop)(LPDATAOBJECT,LPDROPSOURCE,DWORD,DWORD*);
60 void (WINAPI *pReleaseStgMedium)(STGMEDIUM* pmedium);
61 HRESULT (WINAPI *pOleSetClipboard)(IDataObject* pDataObj);
62 HRESULT (WINAPI *pOleGetClipboard)(IDataObject** ppDataObj);
64 /**************************************************************************
65 * GetShellOle
67 * make sure OLE32.DLL is loaded
69 BOOL GetShellOle(void)
71 static HANDLE hOle32 = NULL;
72 if(!hOle32)
74 hOle32 = LoadLibraryA("ole32.dll");
75 if(hOle32)
77 pOleInitialize=(void*)GetProcAddress(hOle32,"OleInitialize");
78 pOleUninitialize=(void*)GetProcAddress(hOle32,"OleUninitialize");
79 pRegisterDragDrop=(void*)GetProcAddress(hOle32,"RegisterDragDrop");
80 pRevokeDragDrop=(void*)GetProcAddress(hOle32,"RevokeDragDrop");
81 pDoDragDrop=(void*)GetProcAddress(hOle32,"DoDragDrop");
82 pReleaseStgMedium=(void*)GetProcAddress(hOle32,"ReleaseStgMedium");
83 pOleSetClipboard=(void*)GetProcAddress(hOle32,"OleSetClipboard");
84 pOleGetClipboard=(void*)GetProcAddress(hOle32,"OleGetClipboard");
86 pOleInitialize(NULL);
89 return TRUE;
92 /**************************************************************************
93 * RenderHDROP
95 * creates a CF_HDROP structure
97 HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
99 UINT i;
100 int rootsize = 0,size = 0;
101 char szRootPath[MAX_PATH];
102 char szFileName[MAX_PATH];
103 HGLOBAL hGlobal;
104 DROPFILES *pDropFiles;
105 int offset;
107 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
109 /* get the size needed */
110 size = sizeof(DROPFILES);
112 SHGetPathFromIDListA(pidlRoot, szRootPath);
113 PathAddBackslashA(szRootPath);
114 rootsize = strlen(szRootPath);
116 for (i=0; i<cidl;i++)
118 _ILSimpleGetText(apidl[i], szFileName, MAX_PATH);
119 size += rootsize + strlen(szFileName) + 1;
122 size++;
124 /* Fill the structure */
125 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
126 if(!hGlobal) return hGlobal;
128 pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
129 pDropFiles->pFiles = sizeof(DROPFILES);
130 pDropFiles->fWide = FALSE;
132 offset = pDropFiles->pFiles;
133 strcpy(szFileName, szRootPath);
135 for (i=0; i<cidl;i++)
138 _ILSimpleGetText(apidl[i], szFileName + rootsize, MAX_PATH - rootsize);
139 size = strlen(szFileName) + 1;
140 strcpy(((char*)pDropFiles)+offset, szFileName);
141 offset += size;
144 ((char*)pDropFiles)[offset] = 0;
145 GlobalUnlock(hGlobal);
147 return hGlobal;
150 HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
152 UINT i;
153 int offset = 0, sizePidl, size;
154 HGLOBAL hGlobal;
155 LPIDA pcida;
157 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
159 /* get the size needed */
160 size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */
161 size += ILGetSize (pidlRoot); /* root pidl */
162 for(i=0; i<cidl; i++)
164 size += ILGetSize(apidl[i]); /* child pidls */
167 /* fill the structure */
168 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
169 if(!hGlobal) return hGlobal;
170 pcida = GlobalLock (hGlobal);
171 pcida->cidl = cidl;
173 /* root pidl */
174 offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
175 pcida->aoffset[0] = offset; /* first element */
176 sizePidl = ILGetSize (pidlRoot);
177 memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
178 offset += sizePidl;
180 for(i=0; i<cidl; i++) /* child pidls */
182 pcida->aoffset[i+1] = offset;
183 sizePidl = ILGetSize(apidl[i]);
184 memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
185 offset += sizePidl;
188 GlobalUnlock(hGlobal);
189 return hGlobal;
192 HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
194 FIXME("\n");
195 return 0;
198 HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
200 FIXME("\n");
201 return 0;
204 HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
206 FIXME("\n");
207 return 0;
210 HGLOBAL RenderFILENAMEA (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
212 int len, size = 0;
213 char szTemp[MAX_PATH], *szFileName;
214 HGLOBAL hGlobal;
216 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
218 /* build name of first file */
219 SHGetPathFromIDListA(pidlRoot, szTemp);
220 PathAddBackslashA(szTemp);
221 len = strlen(szTemp);
222 _ILSimpleGetText(apidl[0], szTemp+len, MAX_PATH - len);
223 size = strlen(szTemp) + 1;
225 /* fill the structure */
226 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
227 if(!hGlobal) return hGlobal;
228 szFileName = (char *)GlobalLock(hGlobal);
229 memcpy(szFileName, szTemp, size);
230 GlobalUnlock(hGlobal);
231 return hGlobal;
234 HGLOBAL RenderFILENAMEW (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
236 int len, size = 0;
237 WCHAR szTemp[MAX_PATH], *szFileName;
238 HGLOBAL hGlobal;
240 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
242 /* build name of first file */
243 SHGetPathFromIDListW(pidlRoot, szTemp);
244 PathAddBackslashW(szTemp);
245 len = strlenW(szTemp);
246 _ILSimpleGetTextW(apidl[0], szTemp+len, MAX_PATH - len);
247 size = sizeof(WCHAR) * (strlenW(szTemp)+1);
249 /* fill the structure */
250 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
251 if(!hGlobal) return hGlobal;
252 szFileName = (WCHAR *)GlobalLock(hGlobal);
253 memcpy(szFileName, szTemp, size);
254 GlobalUnlock(hGlobal);
255 return hGlobal;
258 HGLOBAL RenderPREFEREDDROPEFFECT (DWORD dwFlags)
260 DWORD * pdwFlag;
261 HGLOBAL hGlobal;
263 TRACE("(0x%08lx)\n", dwFlags);
265 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, sizeof(DWORD));
266 if(!hGlobal) return hGlobal;
267 pdwFlag = (DWORD*)GlobalLock(hGlobal);
268 *pdwFlag = dwFlags;
269 GlobalUnlock(hGlobal);
270 return hGlobal;
273 /**************************************************************************
274 * IsDataInClipboard
276 * checks if there is something in the clipboard we can use
278 BOOL IsDataInClipboard (HWND hwnd)
280 BOOL ret = FALSE;
282 if (OpenClipboard(hwnd))
284 if (GetOpenClipboardWindow())
286 ret = IsClipboardFormatAvailable(CF_TEXT);
288 CloseClipboard();
290 return ret;