Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * clipboard helper functions |
| 3 | * |
| 4 | * Copyright 2000 Juergen Schmied <juergen.schmied@debitel.de> |
| 5 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 19 | * |
| 20 | * NOTES: |
| 21 | * |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 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 |
| 25 | * |
| 26 | * - a right mousebutton-copy sets the following formats: |
| 27 | * classic: |
| 28 | * Shell IDList Array |
Francois Gouget | fbb3343 | 2005-03-02 13:53:50 +0000 | [diff] [blame] | 29 | * Preferred Drop Effect |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 30 | * Shell Object Offsets |
| 31 | * HDROP |
| 32 | * FileName |
| 33 | * ole: |
| 34 | * OlePrivateData (ClipboardDataObjectInterface) |
| 35 | * |
| 36 | */ |
| 37 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 38 | #include <stdarg.h> |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 39 | #include <string.h> |
| 40 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 41 | #include "windef.h" |
| 42 | #include "winbase.h" |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 43 | #include "winreg.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 44 | #include "wingdi.h" |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 45 | #include "pidl.h" |
Alexandre Julliard | 3954117 | 2001-08-16 18:49:56 +0000 | [diff] [blame] | 46 | #include "undocshell.h" |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 47 | #include "shell32_main.h" |
Jon Griffiths | 603f20f | 2001-12-11 00:30:17 +0000 | [diff] [blame] | 48 | #include "shlwapi.h" |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 49 | |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 50 | #include "wine/unicode.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 51 | #include "wine/debug.h" |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 52 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 53 | WINE_DEFAULT_DEBUG_CHANNEL(shell); |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 54 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 55 | /************************************************************************** |
| 56 | * RenderHDROP |
| 57 | * |
| 58 | * creates a CF_HDROP structure |
| 59 | */ |
| 60 | HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) |
| 61 | { |
Rolf Kalbermatter | a964471 | 2002-12-13 00:36:52 +0000 | [diff] [blame] | 62 | UINT i; |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 63 | int rootlen = 0,size = 0; |
| 64 | WCHAR wszRootPath[MAX_PATH]; |
| 65 | WCHAR wszFileName[MAX_PATH]; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 66 | HGLOBAL hGlobal; |
Alexandre Julliard | 60e1752 | 2000-09-25 23:56:41 +0000 | [diff] [blame] | 67 | DROPFILES *pDropFiles; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 68 | int offset; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 69 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 70 | TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl); |
| 71 | |
| 72 | /* get the size needed */ |
Alexandre Julliard | 60e1752 | 2000-09-25 23:56:41 +0000 | [diff] [blame] | 73 | size = sizeof(DROPFILES); |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 74 | |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 75 | SHGetPathFromIDListW(pidlRoot, wszRootPath); |
| 76 | PathAddBackslashW(wszRootPath); |
| 77 | rootlen = strlenW(wszRootPath); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 78 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 79 | for (i=0; i<cidl;i++) |
| 80 | { |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 81 | _ILSimpleGetTextW(apidl[i], wszFileName, MAX_PATH); |
| 82 | size += (rootlen + strlenW(wszFileName) + 1) * sizeof(WCHAR); |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 85 | size += sizeof(WCHAR); |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 86 | |
| 87 | /* Fill the structure */ |
| 88 | hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size); |
| 89 | if(!hGlobal) return hGlobal; |
| 90 | |
Michael Stefaniuc | b7de266 | 2008-11-05 23:00:50 +0100 | [diff] [blame] | 91 | pDropFiles = GlobalLock(hGlobal); |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 92 | offset = (sizeof(DROPFILES) + sizeof(WCHAR) - 1) / sizeof(WCHAR); |
| 93 | pDropFiles->pFiles = offset * sizeof(WCHAR); |
| 94 | pDropFiles->fWide = TRUE; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 95 | |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 96 | strcpyW(wszFileName, wszRootPath); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 97 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 98 | for (i=0; i<cidl;i++) |
| 99 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 100 | |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 101 | _ILSimpleGetTextW(apidl[i], wszFileName + rootlen, MAX_PATH - rootlen); |
| 102 | strcpyW(((WCHAR*)pDropFiles)+offset, wszFileName); |
| 103 | offset += strlenW(wszFileName) + 1; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Ken Thomases | 8f5f3f5 | 2007-03-14 13:17:29 -0500 | [diff] [blame] | 106 | ((WCHAR*)pDropFiles)[offset] = 0; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 107 | GlobalUnlock(hGlobal); |
| 108 | |
| 109 | return hGlobal; |
| 110 | } |
| 111 | |
| 112 | HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) |
| 113 | { |
Rolf Kalbermatter | a964471 | 2002-12-13 00:36:52 +0000 | [diff] [blame] | 114 | UINT i; |
| 115 | int offset = 0, sizePidl, size; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 116 | HGLOBAL hGlobal; |
Patrik Stridvall | ced69a9 | 2002-11-12 01:05:00 +0000 | [diff] [blame] | 117 | LPIDA pcida; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 118 | |
| 119 | TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl); |
| 120 | |
| 121 | /* get the size needed */ |
| 122 | size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */ |
| 123 | size += ILGetSize (pidlRoot); /* root pidl */ |
| 124 | for(i=0; i<cidl; i++) |
| 125 | { |
| 126 | size += ILGetSize(apidl[i]); /* child pidls */ |
| 127 | } |
| 128 | |
| 129 | /* fill the structure */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 130 | hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size); |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 131 | if(!hGlobal) return hGlobal; |
| 132 | pcida = GlobalLock (hGlobal); |
| 133 | pcida->cidl = cidl; |
| 134 | |
| 135 | /* root pidl */ |
| 136 | offset = sizeof(CIDA) + sizeof (UINT)*(cidl); |
| 137 | pcida->aoffset[0] = offset; /* first element */ |
| 138 | sizePidl = ILGetSize (pidlRoot); |
| 139 | memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl); |
| 140 | offset += sizePidl; |
| 141 | |
| 142 | for(i=0; i<cidl; i++) /* child pidls */ |
| 143 | { |
| 144 | pcida->aoffset[i+1] = offset; |
| 145 | sizePidl = ILGetSize(apidl[i]); |
| 146 | memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl); |
| 147 | offset += sizePidl; |
| 148 | } |
| 149 | |
| 150 | GlobalUnlock(hGlobal); |
| 151 | return hGlobal; |
| 152 | } |
| 153 | |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 154 | HGLOBAL RenderFILENAMEA (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 155 | { |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 156 | int size = 0; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 157 | char szTemp[MAX_PATH], *szFileName; |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 158 | LPITEMIDLIST pidl; |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 159 | HGLOBAL hGlobal; |
Michael Jung | 81b7509 | 2005-06-14 19:17:41 +0000 | [diff] [blame] | 160 | BOOL bSuccess; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 161 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 162 | TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl); |
| 163 | |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 164 | /* get path of combined pidl */ |
| 165 | pidl = ILCombine(pidlRoot, apidl[0]); |
| 166 | if (!pidl) |
| 167 | return 0; |
| 168 | |
Michael Jung | 81b7509 | 2005-06-14 19:17:41 +0000 | [diff] [blame] | 169 | bSuccess = SHGetPathFromIDListA(pidl, szTemp); |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 170 | SHFree(pidl); |
Michael Jung | 81b7509 | 2005-06-14 19:17:41 +0000 | [diff] [blame] | 171 | if (!bSuccess) |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 172 | return 0; |
| 173 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 174 | size = strlen(szTemp) + 1; |
| 175 | |
| 176 | /* fill the structure */ |
| 177 | hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size); |
| 178 | if(!hGlobal) return hGlobal; |
Michael Stefaniuc | b7de266 | 2008-11-05 23:00:50 +0100 | [diff] [blame] | 179 | szFileName = GlobalLock(hGlobal); |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 180 | memcpy(szFileName, szTemp, size); |
| 181 | GlobalUnlock(hGlobal); |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 182 | |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 183 | return hGlobal; |
| 184 | } |
| 185 | |
| 186 | HGLOBAL RenderFILENAMEW (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) |
| 187 | { |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 188 | int size = 0; |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 189 | WCHAR szTemp[MAX_PATH], *szFileName; |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 190 | LPITEMIDLIST pidl; |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 191 | HGLOBAL hGlobal; |
Michael Jung | 81b7509 | 2005-06-14 19:17:41 +0000 | [diff] [blame] | 192 | BOOL bSuccess; |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 193 | |
| 194 | TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl); |
| 195 | |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 196 | /* get path of combined pidl */ |
| 197 | pidl = ILCombine(pidlRoot, apidl[0]); |
| 198 | if (!pidl) |
| 199 | return 0; |
| 200 | |
Michael Jung | 81b7509 | 2005-06-14 19:17:41 +0000 | [diff] [blame] | 201 | bSuccess = SHGetPathFromIDListW(pidl, szTemp); |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 202 | SHFree(pidl); |
Michael Jung | 81b7509 | 2005-06-14 19:17:41 +0000 | [diff] [blame] | 203 | if (!bSuccess) |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 204 | return 0; |
| 205 | |
| 206 | size = (strlenW(szTemp)+1) * sizeof(WCHAR); |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 207 | |
| 208 | /* fill the structure */ |
| 209 | hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size); |
| 210 | if(!hGlobal) return hGlobal; |
Michael Stefaniuc | b7de266 | 2008-11-05 23:00:50 +0100 | [diff] [blame] | 211 | szFileName = GlobalLock(hGlobal); |
Martin Fuchs | 65b4d2d | 2003-07-26 20:32:43 +0000 | [diff] [blame] | 212 | memcpy(szFileName, szTemp, size); |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 213 | GlobalUnlock(hGlobal); |
Martin Fuchs | 9d78f67 | 2004-01-21 23:50:46 +0000 | [diff] [blame] | 214 | |
Juergen Schmied | e2b8804 | 2000-02-20 18:46:28 +0000 | [diff] [blame] | 215 | return hGlobal; |
| 216 | } |