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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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:
29 * Preferred Drop Effect
30 * Shell Object Offsets
34 * OlePrivateData (ClipboardDataObjectInterface)
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 /**************************************************************************
45 * creates a CF_HDROP structure
47 HGLOBAL
RenderHDROP(LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
51 WCHAR wszFileName
[MAX_PATH
];
52 HGLOBAL hGlobal
= NULL
;
53 DROPFILES
*pDropFiles
;
57 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
59 pidls
= HeapAlloc(GetProcessHeap(), 0, cidl
* sizeof(*pidls
));
63 /* get the size needed */
64 size
= sizeof(DROPFILES
);
68 pidls
[i
] = ILCombine(pidlRoot
, apidl
[i
]);
69 SHGetPathFromIDListW(pidls
[i
], wszFileName
);
70 size
+= (wcslen(wszFileName
) + 1) * sizeof(WCHAR
);
73 size
+= sizeof(WCHAR
);
75 /* Fill the structure */
76 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
80 pDropFiles
= (DROPFILES
*)GlobalLock(hGlobal
);
81 offset
= (sizeof(DROPFILES
) + sizeof(WCHAR
) - 1) / sizeof(WCHAR
);
82 pDropFiles
->pFiles
= offset
* sizeof(WCHAR
);
83 pDropFiles
->fWide
= TRUE
;
87 SHGetPathFromIDListW(pidls
[i
], wszFileName
);
88 wcscpy(((WCHAR
*)pDropFiles
)+offset
, wszFileName
);
89 offset
+= wcslen(wszFileName
) + 1;
93 ((WCHAR
*)pDropFiles
)[offset
] = 0;
94 GlobalUnlock(hGlobal
);
98 HeapFree(GetProcessHeap(), 0, pidls
);
103 HGLOBAL
RenderSHELLIDLIST (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
106 int offset
= 0, sizePidl
, size
;
110 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
112 /* get the size needed */
113 size
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
); /* header */
114 size
+= ILGetSize (pidlRoot
); /* root pidl */
115 for(i
=0; i
<cidl
; i
++)
117 size
+= ILGetSize(apidl
[i
]); /* child pidls */
120 /* fill the structure */
121 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
122 if(!hGlobal
) return hGlobal
;
123 pcida
= GlobalLock (hGlobal
);
127 offset
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
);
128 pcida
->aoffset
[0] = offset
; /* first element */
129 sizePidl
= ILGetSize (pidlRoot
);
130 memcpy(((LPBYTE
)pcida
)+offset
, pidlRoot
, sizePidl
);
133 for(i
=0; i
<cidl
; i
++) /* child pidls */
135 pcida
->aoffset
[i
+1] = offset
;
136 sizePidl
= ILGetSize(apidl
[i
]);
137 memcpy(((LPBYTE
)pcida
)+offset
, apidl
[i
], sizePidl
);
141 GlobalUnlock(hGlobal
);
145 HGLOBAL
RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
151 HGLOBAL
RenderFILECONTENTS (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
157 HGLOBAL
RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
163 HGLOBAL
RenderFILENAMEA (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
166 char szTemp
[MAX_PATH
], *szFileName
;
171 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
173 /* get path of combined pidl */
174 pidl
= ILCombine(pidlRoot
, apidl
[0]);
178 bSuccess
= SHGetPathFromIDListA(pidl
, szTemp
);
183 size
= strlen(szTemp
) + 1;
185 /* fill the structure */
186 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
187 if(!hGlobal
) return hGlobal
;
188 szFileName
= (char *)GlobalLock(hGlobal
);
189 memcpy(szFileName
, szTemp
, size
);
190 GlobalUnlock(hGlobal
);
195 HGLOBAL
RenderFILENAMEW (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
198 WCHAR szTemp
[MAX_PATH
], *szFileName
;
203 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
205 /* get path of combined pidl */
206 pidl
= ILCombine(pidlRoot
, apidl
[0]);
210 bSuccess
= SHGetPathFromIDListW(pidl
, szTemp
);
215 size
= (wcslen(szTemp
)+1) * sizeof(WCHAR
);
217 /* fill the structure */
218 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
219 if(!hGlobal
) return hGlobal
;
220 szFileName
= (WCHAR
*)GlobalLock(hGlobal
);
221 memcpy(szFileName
, szTemp
, size
);
222 GlobalUnlock(hGlobal
);
227 HGLOBAL
RenderPREFEREDDROPEFFECT (DWORD dwFlags
)
232 TRACE("(0x%08x)\n", dwFlags
);
234 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, sizeof(DWORD
));
235 if(!hGlobal
) return hGlobal
;
236 pdwFlag
= (DWORD
*)GlobalLock(hGlobal
);
238 GlobalUnlock(hGlobal
);