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 rootsize
= 0,size
= 0;
64 char szRootPath
[MAX_PATH
];
65 char szFileName
[MAX_PATH
];
67 DROPFILES
*pDropFiles
;
70 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
72 /* get the size needed */
73 size
= sizeof(DROPFILES
);
75 SHGetPathFromIDListA(pidlRoot
, szRootPath
);
76 PathAddBackslashA(szRootPath
);
77 rootsize
= strlen(szRootPath
);
81 _ILSimpleGetText(apidl
[i
], szFileName
, MAX_PATH
);
82 size
+= rootsize
+ strlen(szFileName
) + 1;
87 /* Fill the structure */
88 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
89 if(!hGlobal
) return hGlobal
;
91 pDropFiles
= (DROPFILES
*)GlobalLock(hGlobal
);
92 pDropFiles
->pFiles
= sizeof(DROPFILES
);
93 pDropFiles
->fWide
= FALSE
;
95 offset
= pDropFiles
->pFiles
;
96 strcpy(szFileName
, szRootPath
);
101 _ILSimpleGetText(apidl
[i
], szFileName
+ rootsize
, MAX_PATH
- rootsize
);
102 size
= strlen(szFileName
) + 1;
103 strcpy(((char*)pDropFiles
)+offset
, szFileName
);
107 ((char*)pDropFiles
)[offset
] = 0;
108 GlobalUnlock(hGlobal
);
113 HGLOBAL
RenderSHELLIDLIST (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
116 int offset
= 0, sizePidl
, size
;
120 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
122 /* get the size needed */
123 size
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
); /* header */
124 size
+= ILGetSize (pidlRoot
); /* root pidl */
125 for(i
=0; i
<cidl
; i
++)
127 size
+= ILGetSize(apidl
[i
]); /* child pidls */
130 /* fill the structure */
131 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
132 if(!hGlobal
) return hGlobal
;
133 pcida
= GlobalLock (hGlobal
);
137 offset
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
);
138 pcida
->aoffset
[0] = offset
; /* first element */
139 sizePidl
= ILGetSize (pidlRoot
);
140 memcpy(((LPBYTE
)pcida
)+offset
, pidlRoot
, sizePidl
);
143 for(i
=0; i
<cidl
; i
++) /* child pidls */
145 pcida
->aoffset
[i
+1] = offset
;
146 sizePidl
= ILGetSize(apidl
[i
]);
147 memcpy(((LPBYTE
)pcida
)+offset
, apidl
[i
], sizePidl
);
151 GlobalUnlock(hGlobal
);
155 HGLOBAL
RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
161 HGLOBAL
RenderFILECONTENTS (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
167 HGLOBAL
RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
173 HGLOBAL
RenderFILENAMEA (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
176 char szTemp
[MAX_PATH
], *szFileName
;
181 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
183 /* get path of combined pidl */
184 pidl
= ILCombine(pidlRoot
, apidl
[0]);
188 bSuccess
= SHGetPathFromIDListA(pidl
, szTemp
);
193 size
= strlen(szTemp
) + 1;
195 /* fill the structure */
196 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
197 if(!hGlobal
) return hGlobal
;
198 szFileName
= (char *)GlobalLock(hGlobal
);
199 memcpy(szFileName
, szTemp
, size
);
200 GlobalUnlock(hGlobal
);
205 HGLOBAL
RenderFILENAMEW (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
208 WCHAR szTemp
[MAX_PATH
], *szFileName
;
213 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
215 /* get path of combined pidl */
216 pidl
= ILCombine(pidlRoot
, apidl
[0]);
220 bSuccess
= SHGetPathFromIDListW(pidl
, szTemp
);
225 size
= (strlenW(szTemp
)+1) * sizeof(WCHAR
);
227 /* fill the structure */
228 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
229 if(!hGlobal
) return hGlobal
;
230 szFileName
= (WCHAR
*)GlobalLock(hGlobal
);
231 memcpy(szFileName
, szTemp
, size
);
232 GlobalUnlock(hGlobal
);
237 HGLOBAL
RenderPREFEREDDROPEFFECT (DWORD dwFlags
)
242 TRACE("(0x%08x)\n", dwFlags
);
244 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, sizeof(DWORD
));
245 if(!hGlobal
) return hGlobal
;
246 pdwFlag
= (DWORD
*)GlobalLock(hGlobal
);
248 GlobalUnlock(hGlobal
);
252 /**************************************************************************
255 * checks if there is something in the clipboard we can use
257 BOOL
IsDataInClipboard (HWND hwnd
)
261 if (OpenClipboard(hwnd
))
263 if (GetOpenClipboardWindow())
265 ret
= IsClipboardFormatAvailable(CF_TEXT
);