Handle ascii & unicode drag and drop structures in DragQueryFileA &
[wine/dcerpc.git] / dlls / shell32 / clipboard.c
blobad741789fe6f6d3069cf8bd43d173ce86ceb179d
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 <string.h>
40 #include "winreg.h"
41 #include "pidl.h"
42 #include "undocshell.h"
43 #include "shell32_main.h"
44 #include "shlwapi.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 static int refClipCount = 0;
51 static HINSTANCE hShellOle32 = 0;
53 /**************************************************************************
54 * InitShellOle
58 void InitShellOle(void)
62 /**************************************************************************
63 * FreeShellOle
65 * unload OLE32.DLL
67 void FreeShellOle(void)
69 if (!--refClipCount)
71 pOleUninitialize();
72 FreeLibrary(hShellOle32);
76 /**************************************************************************
77 * LoadShellOle
79 * make sure OLE32.DLL is loaded
81 BOOL GetShellOle(void)
83 if(!refClipCount)
85 hShellOle32 = LoadLibraryA("ole32.dll");
86 if(hShellOle32)
88 pOleInitialize=(void*)GetProcAddress(hShellOle32,"OleInitialize");
89 pOleUninitialize=(void*)GetProcAddress(hShellOle32,"OleUninitialize");
90 pRegisterDragDrop=(void*)GetProcAddress(hShellOle32,"RegisterDragDrop");
91 pRevokeDragDrop=(void*)GetProcAddress(hShellOle32,"RevokeDragDrop");
92 pDoDragDrop=(void*)GetProcAddress(hShellOle32,"DoDragDrop");
93 pReleaseStgMedium=(void*)GetProcAddress(hShellOle32,"ReleaseStgMedium");
94 pOleSetClipboard=(void*)GetProcAddress(hShellOle32,"OleSetClipboard");
95 pOleGetClipboard=(void*)GetProcAddress(hShellOle32,"OleGetClipboard");
97 pOleInitialize(NULL);
98 refClipCount++;
101 return TRUE;
104 /**************************************************************************
105 * RenderHDROP
107 * creates a CF_HDROP structure
109 HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
111 int i;
112 int rootsize = 0,size = 0;
113 char szRootPath[MAX_PATH];
114 char szFileName[MAX_PATH];
115 HGLOBAL hGlobal;
116 DROPFILES *pDropFiles;
117 int offset;
119 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
121 /* get the size needed */
122 size = sizeof(DROPFILES);
124 SHGetPathFromIDListA(pidlRoot, szRootPath);
125 PathAddBackslashA(szRootPath);
126 rootsize = strlen(szRootPath);
128 for (i=0; i<cidl;i++)
130 _ILSimpleGetText(apidl[i], szFileName, MAX_PATH);
131 size += rootsize + strlen(szFileName) + 1;
134 size++;
136 /* Fill the structure */
137 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
138 if(!hGlobal) return hGlobal;
140 pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
141 pDropFiles->pFiles = sizeof(DROPFILES);
142 pDropFiles->fWide = FALSE;
144 offset = pDropFiles->pFiles;
145 strcpy(szFileName, szRootPath);
147 for (i=0; i<cidl;i++)
150 _ILSimpleGetText(apidl[i], szFileName + rootsize, MAX_PATH - rootsize);
151 size = strlen(szFileName) + 1;
152 strcpy(((char*)pDropFiles)+offset, szFileName);
153 offset += size;
156 ((char*)pDropFiles)[offset] = 0;
157 GlobalUnlock(hGlobal);
159 return hGlobal;
162 HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
164 int i,offset = 0, sizePidl, size;
165 HGLOBAL hGlobal;
166 LPCIDA pcida;
168 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
170 /* get the size needed */
171 size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */
172 size += ILGetSize (pidlRoot); /* root pidl */
173 for(i=0; i<cidl; i++)
175 size += ILGetSize(apidl[i]); /* child pidls */
178 /* fill the structure */
179 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
180 if(!hGlobal) return hGlobal;
181 pcida = GlobalLock (hGlobal);
182 pcida->cidl = cidl;
184 /* root pidl */
185 offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
186 pcida->aoffset[0] = offset; /* first element */
187 sizePidl = ILGetSize (pidlRoot);
188 memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
189 offset += sizePidl;
191 for(i=0; i<cidl; i++) /* child pidls */
193 pcida->aoffset[i+1] = offset;
194 sizePidl = ILGetSize(apidl[i]);
195 memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
196 offset += sizePidl;
199 GlobalUnlock(hGlobal);
200 return hGlobal;
203 HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
205 FIXME("\n");
206 return 0;
209 HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
211 FIXME("\n");
212 return 0;
215 HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
217 FIXME("\n");
218 return 0;
221 HGLOBAL RenderFILENAME (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
223 int len, size = 0;
224 char szTemp[MAX_PATH], *szFileName;
225 HGLOBAL hGlobal;
227 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
229 /* build name of first file */
230 SHGetPathFromIDListA(pidlRoot, szTemp);
231 PathAddBackslashA(szTemp);
232 len = strlen(szTemp);
233 _ILSimpleGetText(apidl[0], szTemp+len, MAX_PATH - len);
234 size = strlen(szTemp) + 1;
236 /* fill the structure */
237 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
238 if(!hGlobal) return hGlobal;
239 szFileName = (char *)GlobalLock(hGlobal);
240 GlobalUnlock(hGlobal);
241 return hGlobal;
244 HGLOBAL RenderPREFEREDDROPEFFECT (DWORD dwFlags)
246 DWORD * pdwFlag;
247 HGLOBAL hGlobal;
249 TRACE("(0x%08lx)\n", dwFlags);
251 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, sizeof(DWORD));
252 if(!hGlobal) return hGlobal;
253 pdwFlag = (DWORD*)GlobalLock(hGlobal);
254 *pdwFlag = dwFlags;
255 GlobalUnlock(hGlobal);
256 return hGlobal;
259 /**************************************************************************
260 * IsDataInClipboard
262 * checks if there is something in the clipboard we can use
264 BOOL IsDataInClipboard (HWND hwnd)
266 BOOL ret = FALSE;
268 if (OpenClipboard(hwnd))
270 if (GetOpenClipboardWindow())
272 ret = IsClipboardFormatAvailable(CF_TEXT);
274 CloseClipboard();
276 return ret;