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 "undocshell.h"
47 #include "shell32_main.h"
50 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
55 /**************************************************************************
58 * creates a CF_HDROP structure
60 HGLOBAL
RenderHDROP(LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
63 int rootlen
= 0,size
= 0;
64 WCHAR wszRootPath
[MAX_PATH
];
65 WCHAR wszFileName
[MAX_PATH
];
67 DROPFILES
*pDropFiles
;
70 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
72 /* get the size needed */
73 size
= sizeof(DROPFILES
);
75 SHGetPathFromIDListW(pidlRoot
, wszRootPath
);
76 PathAddBackslashW(wszRootPath
);
77 rootlen
= strlenW(wszRootPath
);
81 _ILSimpleGetTextW(apidl
[i
], wszFileName
, MAX_PATH
);
82 size
+= (rootlen
+ strlenW(wszFileName
) + 1) * sizeof(WCHAR
);
85 size
+= sizeof(WCHAR
);
87 /* Fill the structure */
88 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
89 if(!hGlobal
) return hGlobal
;
91 pDropFiles
= GlobalLock(hGlobal
);
92 offset
= (sizeof(DROPFILES
) + sizeof(WCHAR
) - 1) / sizeof(WCHAR
);
93 pDropFiles
->pFiles
= offset
* sizeof(WCHAR
);
94 pDropFiles
->fWide
= TRUE
;
96 strcpyW(wszFileName
, wszRootPath
);
101 _ILSimpleGetTextW(apidl
[i
], wszFileName
+ rootlen
, MAX_PATH
- rootlen
);
102 strcpyW(((WCHAR
*)pDropFiles
)+offset
, wszFileName
);
103 offset
+= strlenW(wszFileName
) + 1;
106 ((WCHAR
*)pDropFiles
)[offset
] = 0;
107 GlobalUnlock(hGlobal
);
112 HGLOBAL
RenderSHELLIDLIST (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
115 int offset
= 0, sizePidl
, size
;
119 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
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
++)
126 size
+= ILGetSize(apidl
[i
]); /* child pidls */
129 /* fill the structure */
130 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
131 if(!hGlobal
) return hGlobal
;
132 pcida
= GlobalLock (hGlobal
);
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
);
142 for(i
=0; i
<cidl
; i
++) /* child pidls */
144 pcida
->aoffset
[i
+1] = offset
;
145 sizePidl
= ILGetSize(apidl
[i
]);
146 memcpy(((LPBYTE
)pcida
)+offset
, apidl
[i
], sizePidl
);
150 GlobalUnlock(hGlobal
);
154 HGLOBAL
RenderFILENAMEA (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
157 char szTemp
[MAX_PATH
], *szFileName
;
162 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
164 /* get path of combined pidl */
165 pidl
= ILCombine(pidlRoot
, apidl
[0]);
169 bSuccess
= SHGetPathFromIDListA(pidl
, szTemp
);
174 size
= strlen(szTemp
) + 1;
176 /* fill the structure */
177 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
178 if(!hGlobal
) return hGlobal
;
179 szFileName
= GlobalLock(hGlobal
);
180 memcpy(szFileName
, szTemp
, size
);
181 GlobalUnlock(hGlobal
);
186 HGLOBAL
RenderFILENAMEW (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
189 WCHAR szTemp
[MAX_PATH
], *szFileName
;
194 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
196 /* get path of combined pidl */
197 pidl
= ILCombine(pidlRoot
, apidl
[0]);
201 bSuccess
= SHGetPathFromIDListW(pidl
, szTemp
);
206 size
= (strlenW(szTemp
)+1) * sizeof(WCHAR
);
208 /* fill the structure */
209 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
210 if(!hGlobal
) return hGlobal
;
211 szFileName
= GlobalLock(hGlobal
);
212 memcpy(szFileName
, szTemp
, size
);
213 GlobalUnlock(hGlobal
);