2 * clipboard helper functions
4 * Copyright 2000 Juergen Schmied <juergen.schmied@debitel.de>
6 * For copy & paste functions within contextmenus does the shell use
7 * the OLE clipboard functions in combination with dataobjects.
8 * The OLE32.DLL gets loaded with LoadLibrary
10 * - a right mousebutton-copy sets the following formats:
13 * Prefered Drop Effect
14 * Shell Object Offsets
18 * OlePrivateData (ClipboardDataObjectInterface)
24 #include "debugtools.h"
27 #include "wine/undocshell.h"
28 #include "shell32_main.h"
30 DEFAULT_DEBUG_CHANNEL(shell)
32 static int refClipCount = 0;
33 static HINSTANCE hShellOle32 = 0;
35 /**************************************************************************
40 void InitShellOle(void)
44 /**************************************************************************
49 void FreeShellOle(void)
54 FreeLibrary(hShellOle32);
58 /**************************************************************************
61 * make sure OLE32.DLL is loaded
63 BOOL GetShellOle(void)
67 hShellOle32 = LoadLibraryA("ole32.dll");
70 pOleInitialize=(void*)GetProcAddress(hShellOle32,"OleInitialize");
71 pOleUninitialize=(void*)GetProcAddress(hShellOle32,"OleUninitialize");
72 pRegisterDragDrop=(void*)GetProcAddress(hShellOle32,"RegisterDragDrop");
73 pRevokeDragDrop=(void*)GetProcAddress(hShellOle32,"RevokeDragDrop");
74 pDoDragDrop=(void*)GetProcAddress(hShellOle32,"DoDragDrop");
75 pReleaseStgMedium=(void*)GetProcAddress(hShellOle32,"ReleaseStgMedium");
76 pOleSetClipboard=(void*)GetProcAddress(hShellOle32,"OleSetClipboard");
77 pOleGetClipboard=(void*)GetProcAddress(hShellOle32,"OleGetClipboard");
86 /**************************************************************************
89 * creates a CF_HDROP structure
91 HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
94 int rootsize = 0,size = 0;
95 char szRootPath[MAX_PATH];
96 char szFileName[MAX_PATH];
98 DROPFILES *pDropFiles;
101 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
103 /* get the size needed */
104 size = sizeof(DROPFILES);
106 SHGetPathFromIDListA(pidlRoot, szRootPath);
107 PathAddBackslashA(szRootPath);
108 rootsize = strlen(szRootPath);
110 for (i=0; i<cidl;i++)
112 _ILSimpleGetText(apidl[i], szFileName, MAX_PATH);
113 size += rootsize + strlen(szFileName) + 1;
118 /* Fill the structure */
119 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
120 if(!hGlobal) return hGlobal;
122 pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
123 pDropFiles->pFiles = sizeof(DROPFILES);
124 pDropFiles->fWide = FALSE;
126 offset = pDropFiles->pFiles;
127 strcpy(szFileName, szRootPath);
129 for (i=0; i<cidl;i++)
132 _ILSimpleGetText(apidl[i], szFileName + rootsize, MAX_PATH - rootsize);
133 size = strlen(szFileName) + 1;
134 strcpy(((char*)pDropFiles)+offset, szFileName);
138 ((char*)pDropFiles)[offset] = 0;
139 GlobalUnlock(hGlobal);
144 HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
146 int i,offset = 0, sizePidl, size;
150 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
152 /* get the size needed */
153 size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */
154 size += ILGetSize (pidlRoot); /* root pidl */
155 for(i=0; i<cidl; i++)
157 size += ILGetSize(apidl[i]); /* child pidls */
160 /* fill the structure */
161 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
162 if(!hGlobal) return hGlobal;
163 pcida = GlobalLock (hGlobal);
167 offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
168 pcida->aoffset[0] = offset; /* first element */
169 sizePidl = ILGetSize (pidlRoot);
170 memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
173 for(i=0; i<cidl; i++) /* child pidls */
175 pcida->aoffset[i+1] = offset;
176 sizePidl = ILGetSize(apidl[i]);
177 memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
181 GlobalUnlock(hGlobal);
185 HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
191 HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
197 HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
203 HGLOBAL RenderFILENAME (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
206 char szTemp[MAX_PATH], *szFileName;
209 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
211 /* build name of first file */
212 SHGetPathFromIDListA(pidlRoot, szTemp);
213 PathAddBackslashA(szTemp);
214 len = strlen(szTemp);
215 _ILSimpleGetText(apidl[0], szTemp+len, MAX_PATH - len);
216 size = strlen(szTemp) + 1;
218 /* fill the structure */
219 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
220 if(!hGlobal) return hGlobal;
221 szFileName = (char *)GlobalLock(hGlobal);
222 GlobalUnlock(hGlobal);
226 HGLOBAL RenderPREFEREDDROPEFFECT (DWORD dwFlags)
231 TRACE("(0x%08lx)\n", dwFlags);
233 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, sizeof(DWORD));
234 if(!hGlobal) return hGlobal;
235 pdwFlag = (DWORD*)GlobalLock(hGlobal);
237 GlobalUnlock(hGlobal);
241 /**************************************************************************
244 * checks if there is something in the clipboard we can use
246 BOOL IsDataInClipboard (HWND hwnd)
250 if (OpenClipboard(hwnd))
252 if (GetOpenClipboardWindow())
254 ret = IsClipboardFormatAvailable(CF_TEXT);