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
)
50 int rootlen
= 0,size
= 0;
51 WCHAR wszRootPath
[MAX_PATH
];
52 WCHAR wszFileName
[MAX_PATH
];
54 DROPFILES
*pDropFiles
;
57 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
59 /* get the size needed */
60 size
= sizeof(DROPFILES
);
62 SHGetPathFromIDListW(pidlRoot
, wszRootPath
);
63 PathAddBackslashW(wszRootPath
);
64 rootlen
= wcslen(wszRootPath
);
68 _ILSimpleGetTextW(apidl
[i
], wszFileName
, MAX_PATH
);
69 size
+= (rootlen
+ wcslen(wszFileName
) + 1) * sizeof(WCHAR
);
72 size
+= sizeof(WCHAR
);
74 /* Fill the structure */
75 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
76 if(!hGlobal
) return hGlobal
;
78 pDropFiles
= (DROPFILES
*)GlobalLock(hGlobal
);
79 offset
= (sizeof(DROPFILES
) + sizeof(WCHAR
) - 1) / sizeof(WCHAR
);
80 pDropFiles
->pFiles
= offset
* sizeof(WCHAR
);
81 pDropFiles
->fWide
= TRUE
;
83 wcscpy(wszFileName
, wszRootPath
);
88 _ILSimpleGetTextW(apidl
[i
], wszFileName
+ rootlen
, MAX_PATH
- rootlen
);
89 wcscpy(((WCHAR
*)pDropFiles
)+offset
, wszFileName
);
90 offset
+= wcslen(wszFileName
) + 1;
93 ((WCHAR
*)pDropFiles
)[offset
] = 0;
94 GlobalUnlock(hGlobal
);
99 HGLOBAL
RenderSHELLIDLIST (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
102 int offset
= 0, sizePidl
, size
;
106 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
108 /* get the size needed */
109 size
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
); /* header */
110 size
+= ILGetSize (pidlRoot
); /* root pidl */
111 for(i
=0; i
<cidl
; i
++)
113 size
+= ILGetSize(apidl
[i
]); /* child pidls */
116 /* fill the structure */
117 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
118 if(!hGlobal
) return hGlobal
;
119 pcida
= GlobalLock (hGlobal
);
123 offset
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
);
124 pcida
->aoffset
[0] = offset
; /* first element */
125 sizePidl
= ILGetSize (pidlRoot
);
126 memcpy(((LPBYTE
)pcida
)+offset
, pidlRoot
, sizePidl
);
129 for(i
=0; i
<cidl
; i
++) /* child pidls */
131 pcida
->aoffset
[i
+1] = offset
;
132 sizePidl
= ILGetSize(apidl
[i
]);
133 memcpy(((LPBYTE
)pcida
)+offset
, apidl
[i
], sizePidl
);
137 GlobalUnlock(hGlobal
);
141 HGLOBAL
RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
147 HGLOBAL
RenderFILECONTENTS (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
153 HGLOBAL
RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
159 HGLOBAL
RenderFILENAMEA (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
162 char szTemp
[MAX_PATH
], *szFileName
;
167 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
169 /* get path of combined pidl */
170 pidl
= ILCombine(pidlRoot
, apidl
[0]);
174 bSuccess
= SHGetPathFromIDListA(pidl
, szTemp
);
179 size
= strlen(szTemp
) + 1;
181 /* fill the structure */
182 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
183 if(!hGlobal
) return hGlobal
;
184 szFileName
= (char *)GlobalLock(hGlobal
);
185 memcpy(szFileName
, szTemp
, size
);
186 GlobalUnlock(hGlobal
);
191 HGLOBAL
RenderFILENAMEW (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
194 WCHAR szTemp
[MAX_PATH
], *szFileName
;
199 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
201 /* get path of combined pidl */
202 pidl
= ILCombine(pidlRoot
, apidl
[0]);
206 bSuccess
= SHGetPathFromIDListW(pidl
, szTemp
);
211 size
= (wcslen(szTemp
)+1) * sizeof(WCHAR
);
213 /* fill the structure */
214 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
215 if(!hGlobal
) return hGlobal
;
216 szFileName
= (WCHAR
*)GlobalLock(hGlobal
);
217 memcpy(szFileName
, szTemp
, size
);
218 GlobalUnlock(hGlobal
);
223 HGLOBAL
RenderPREFEREDDROPEFFECT (DWORD dwFlags
)
228 TRACE("(0x%08x)\n", dwFlags
);
230 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, sizeof(DWORD
));
231 if(!hGlobal
) return hGlobal
;
232 pdwFlag
= (DWORD
*)GlobalLock(hGlobal
);
234 GlobalUnlock(hGlobal
);