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)
46 #include "shell32_main.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
53 /**************************************************************************
56 * creates a CF_HDROP structure
58 HGLOBAL
RenderHDROP(LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
61 int rootlen
= 0,size
= 0;
62 WCHAR wszRootPath
[MAX_PATH
];
63 WCHAR wszFileName
[MAX_PATH
];
65 DROPFILES
*pDropFiles
;
68 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
70 /* get the size needed */
71 size
= sizeof(DROPFILES
);
73 SHGetPathFromIDListW(pidlRoot
, wszRootPath
);
74 PathAddBackslashW(wszRootPath
);
75 rootlen
= lstrlenW(wszRootPath
);
79 _ILSimpleGetTextW(apidl
[i
], wszFileName
, MAX_PATH
);
80 size
+= (rootlen
+ lstrlenW(wszFileName
) + 1) * sizeof(WCHAR
);
83 size
+= sizeof(WCHAR
);
85 /* Fill the structure */
86 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
87 if(!hGlobal
) return hGlobal
;
89 pDropFiles
= GlobalLock(hGlobal
);
90 offset
= (sizeof(DROPFILES
) + sizeof(WCHAR
) - 1) / sizeof(WCHAR
);
91 pDropFiles
->pFiles
= offset
* sizeof(WCHAR
);
92 pDropFiles
->fWide
= TRUE
;
94 lstrcpyW(wszFileName
, wszRootPath
);
99 _ILSimpleGetTextW(apidl
[i
], wszFileName
+ rootlen
, MAX_PATH
- rootlen
);
100 lstrcpyW(((WCHAR
*)pDropFiles
)+offset
, wszFileName
);
101 offset
+= lstrlenW(wszFileName
) + 1;
104 ((WCHAR
*)pDropFiles
)[offset
] = 0;
105 GlobalUnlock(hGlobal
);
110 HGLOBAL
RenderSHELLIDLIST (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
113 int offset
= 0, sizePidl
, size
;
117 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
119 /* get the size needed */
120 size
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
); /* header */
121 size
+= ILGetSize (pidlRoot
); /* root pidl */
122 for(i
=0; i
<cidl
; i
++)
124 size
+= ILGetSize(apidl
[i
]); /* child pidls */
127 /* fill the structure */
128 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
129 if(!hGlobal
) return hGlobal
;
130 pcida
= GlobalLock (hGlobal
);
134 offset
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
);
135 pcida
->aoffset
[0] = offset
; /* first element */
136 sizePidl
= ILGetSize (pidlRoot
);
137 memcpy(((LPBYTE
)pcida
)+offset
, pidlRoot
, sizePidl
);
140 for(i
=0; i
<cidl
; i
++) /* child pidls */
142 pcida
->aoffset
[i
+1] = offset
;
143 sizePidl
= ILGetSize(apidl
[i
]);
144 memcpy(((LPBYTE
)pcida
)+offset
, apidl
[i
], sizePidl
);
148 GlobalUnlock(hGlobal
);
152 HGLOBAL
RenderFILENAMEA (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
155 char szTemp
[MAX_PATH
], *szFileName
;
160 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
162 /* get path of combined pidl */
163 pidl
= ILCombine(pidlRoot
, apidl
[0]);
167 bSuccess
= SHGetPathFromIDListA(pidl
, szTemp
);
172 size
= strlen(szTemp
) + 1;
174 /* fill the structure */
175 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
176 if(!hGlobal
) return hGlobal
;
177 szFileName
= GlobalLock(hGlobal
);
178 memcpy(szFileName
, szTemp
, size
);
179 GlobalUnlock(hGlobal
);
184 HGLOBAL
RenderFILENAMEW (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
187 WCHAR szTemp
[MAX_PATH
], *szFileName
;
192 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
194 /* get path of combined pidl */
195 pidl
= ILCombine(pidlRoot
, apidl
[0]);
199 bSuccess
= SHGetPathFromIDListW(pidl
, szTemp
);
204 size
= (lstrlenW(szTemp
)+1) * sizeof(WCHAR
);
206 /* fill the structure */
207 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
208 if(!hGlobal
) return hGlobal
;
209 szFileName
= GlobalLock(hGlobal
);
210 memcpy(szFileName
, szTemp
, size
);
211 GlobalUnlock(hGlobal
);