- 3d buffers produce sounds
[wine/hacks.git] / dlls / shell32 / clipboard.c
blob8654c324c94b8411ee0396340f8c1216c5dee7a0
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 HRESULT (WINAPI *pOleInitialize)(LPVOID reserved);
51 void (WINAPI *pOleUninitialize)(void);
52 HRESULT (WINAPI *pRegisterDragDrop)(HWND hwnd, IDropTarget* pDropTarget);
53 HRESULT (WINAPI *pRevokeDragDrop)(HWND hwnd);
54 HRESULT (WINAPI *pDoDragDrop)(LPDATAOBJECT,LPDROPSOURCE,DWORD,DWORD*);
55 void (WINAPI *pReleaseStgMedium)(STGMEDIUM* pmedium);
56 HRESULT (WINAPI *pOleSetClipboard)(IDataObject* pDataObj);
57 HRESULT (WINAPI *pOleGetClipboard)(IDataObject** ppDataObj);
59 /**************************************************************************
60 * GetShellOle
62 * make sure OLE32.DLL is loaded
64 BOOL GetShellOle(void)
66 if(!hShellOle32)
68 hShellOle32 = LoadLibraryA("ole32.dll");
69 if(hShellOle32)
71 pOleInitialize=(void*)GetProcAddress(hShellOle32,"OleInitialize");
72 pOleUninitialize=(void*)GetProcAddress(hShellOle32,"OleUninitialize");
73 pRegisterDragDrop=(void*)GetProcAddress(hShellOle32,"RegisterDragDrop");
74 pRevokeDragDrop=(void*)GetProcAddress(hShellOle32,"RevokeDragDrop");
75 pDoDragDrop=(void*)GetProcAddress(hShellOle32,"DoDragDrop");
76 pReleaseStgMedium=(void*)GetProcAddress(hShellOle32,"ReleaseStgMedium");
77 pOleSetClipboard=(void*)GetProcAddress(hShellOle32,"OleSetClipboard");
78 pOleGetClipboard=(void*)GetProcAddress(hShellOle32,"OleGetClipboard");
80 pOleInitialize(NULL);
83 return TRUE;
86 /**************************************************************************
87 * RenderHDROP
89 * creates a CF_HDROP structure
91 HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
93 UINT i;
94 int rootsize = 0,size = 0;
95 char szRootPath[MAX_PATH];
96 char szFileName[MAX_PATH];
97 HGLOBAL hGlobal;
98 DROPFILES *pDropFiles;
99 int offset;
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;
116 size++;
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);
135 offset += size;
138 ((char*)pDropFiles)[offset] = 0;
139 GlobalUnlock(hGlobal);
141 return hGlobal;
144 HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
146 UINT i;
147 int offset = 0, sizePidl, size;
148 HGLOBAL hGlobal;
149 LPIDA pcida;
151 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
153 /* get the size needed */
154 size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */
155 size += ILGetSize (pidlRoot); /* root pidl */
156 for(i=0; i<cidl; i++)
158 size += ILGetSize(apidl[i]); /* child pidls */
161 /* fill the structure */
162 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
163 if(!hGlobal) return hGlobal;
164 pcida = GlobalLock (hGlobal);
165 pcida->cidl = cidl;
167 /* root pidl */
168 offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
169 pcida->aoffset[0] = offset; /* first element */
170 sizePidl = ILGetSize (pidlRoot);
171 memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
172 offset += sizePidl;
174 for(i=0; i<cidl; i++) /* child pidls */
176 pcida->aoffset[i+1] = offset;
177 sizePidl = ILGetSize(apidl[i]);
178 memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
179 offset += sizePidl;
182 GlobalUnlock(hGlobal);
183 return hGlobal;
186 HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
188 FIXME("\n");
189 return 0;
192 HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
194 FIXME("\n");
195 return 0;
198 HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
200 FIXME("\n");
201 return 0;
204 HGLOBAL RenderFILENAME (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
206 int len, size = 0;
207 char szTemp[MAX_PATH], *szFileName;
208 HGLOBAL hGlobal;
210 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
212 /* build name of first file */
213 SHGetPathFromIDListA(pidlRoot, szTemp);
214 PathAddBackslashA(szTemp);
215 len = strlen(szTemp);
216 _ILSimpleGetText(apidl[0], szTemp+len, MAX_PATH - len);
217 size = strlen(szTemp) + 1;
219 /* fill the structure */
220 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
221 if(!hGlobal) return hGlobal;
222 szFileName = (char *)GlobalLock(hGlobal);
223 GlobalUnlock(hGlobal);
224 return hGlobal;
227 HGLOBAL RenderPREFEREDDROPEFFECT (DWORD dwFlags)
229 DWORD * pdwFlag;
230 HGLOBAL hGlobal;
232 TRACE("(0x%08lx)\n", dwFlags);
234 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, sizeof(DWORD));
235 if(!hGlobal) return hGlobal;
236 pdwFlag = (DWORD*)GlobalLock(hGlobal);
237 *pdwFlag = dwFlags;
238 GlobalUnlock(hGlobal);
239 return hGlobal;
242 /**************************************************************************
243 * IsDataInClipboard
245 * checks if there is something in the clipboard we can use
247 BOOL IsDataInClipboard (HWND hwnd)
249 BOOL ret = FALSE;
251 if (OpenClipboard(hwnd))
253 if (GetOpenClipboardWindow())
255 ret = IsClipboardFormatAvailable(CF_TEXT);
257 CloseClipboard();
259 return ret;