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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * Prefered Drop Effect
30 * Shell Object Offsets
34 * OlePrivateData (ClipboardDataObjectInterface)
42 #include "undocshell.h"
43 #include "shell32_main.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
50 static int refClipCount
= 0;
51 static HINSTANCE hShellOle32
= 0;
53 /**************************************************************************
58 void InitShellOle(void)
62 /**************************************************************************
67 void FreeShellOle(void)
72 FreeLibrary(hShellOle32
);
76 /**************************************************************************
79 * make sure OLE32.DLL is loaded
81 BOOL
GetShellOle(void)
85 hShellOle32
= LoadLibraryA("ole32.dll");
88 pOleInitialize
=(void*)GetProcAddress(hShellOle32
,"OleInitialize");
89 pOleUninitialize
=(void*)GetProcAddress(hShellOle32
,"OleUninitialize");
90 pRegisterDragDrop
=(void*)GetProcAddress(hShellOle32
,"RegisterDragDrop");
91 pRevokeDragDrop
=(void*)GetProcAddress(hShellOle32
,"RevokeDragDrop");
92 pDoDragDrop
=(void*)GetProcAddress(hShellOle32
,"DoDragDrop");
93 pReleaseStgMedium
=(void*)GetProcAddress(hShellOle32
,"ReleaseStgMedium");
94 pOleSetClipboard
=(void*)GetProcAddress(hShellOle32
,"OleSetClipboard");
95 pOleGetClipboard
=(void*)GetProcAddress(hShellOle32
,"OleGetClipboard");
104 /**************************************************************************
107 * creates a CF_HDROP structure
109 HGLOBAL
RenderHDROP(LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
112 int rootsize
= 0,size
= 0;
113 char szRootPath
[MAX_PATH
];
114 char szFileName
[MAX_PATH
];
116 DROPFILES
*pDropFiles
;
119 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
121 /* get the size needed */
122 size
= sizeof(DROPFILES
);
124 SHGetPathFromIDListA(pidlRoot
, szRootPath
);
125 PathAddBackslashA(szRootPath
);
126 rootsize
= strlen(szRootPath
);
128 for (i
=0; i
<cidl
;i
++)
130 _ILSimpleGetText(apidl
[i
], szFileName
, MAX_PATH
);
131 size
+= rootsize
+ strlen(szFileName
) + 1;
136 /* Fill the structure */
137 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
138 if(!hGlobal
) return hGlobal
;
140 pDropFiles
= (DROPFILES
*)GlobalLock(hGlobal
);
141 pDropFiles
->pFiles
= sizeof(DROPFILES
);
142 pDropFiles
->fWide
= FALSE
;
144 offset
= pDropFiles
->pFiles
;
145 strcpy(szFileName
, szRootPath
);
147 for (i
=0; i
<cidl
;i
++)
150 _ILSimpleGetText(apidl
[i
], szFileName
+ rootsize
, MAX_PATH
- rootsize
);
151 size
= strlen(szFileName
) + 1;
152 strcpy(((char*)pDropFiles
)+offset
, szFileName
);
156 ((char*)pDropFiles
)[offset
] = 0;
157 GlobalUnlock(hGlobal
);
162 HGLOBAL
RenderSHELLIDLIST (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
164 int i
,offset
= 0, sizePidl
, size
;
168 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
170 /* get the size needed */
171 size
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
); /* header */
172 size
+= ILGetSize (pidlRoot
); /* root pidl */
173 for(i
=0; i
<cidl
; i
++)
175 size
+= ILGetSize(apidl
[i
]); /* child pidls */
178 /* fill the structure */
179 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
180 if(!hGlobal
) return hGlobal
;
181 pcida
= GlobalLock (hGlobal
);
185 offset
= sizeof(CIDA
) + sizeof (UINT
)*(cidl
);
186 pcida
->aoffset
[0] = offset
; /* first element */
187 sizePidl
= ILGetSize (pidlRoot
);
188 memcpy(((LPBYTE
)pcida
)+offset
, pidlRoot
, sizePidl
);
191 for(i
=0; i
<cidl
; i
++) /* child pidls */
193 pcida
->aoffset
[i
+1] = offset
;
194 sizePidl
= ILGetSize(apidl
[i
]);
195 memcpy(((LPBYTE
)pcida
)+offset
, apidl
[i
], sizePidl
);
199 GlobalUnlock(hGlobal
);
203 HGLOBAL
RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
209 HGLOBAL
RenderFILECONTENTS (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
215 HGLOBAL
RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
221 HGLOBAL
RenderFILENAME (LPITEMIDLIST pidlRoot
, LPITEMIDLIST
* apidl
, UINT cidl
)
224 char szTemp
[MAX_PATH
], *szFileName
;
227 TRACE("(%p,%p,%u)\n", pidlRoot
, apidl
, cidl
);
229 /* build name of first file */
230 SHGetPathFromIDListA(pidlRoot
, szTemp
);
231 PathAddBackslashA(szTemp
);
232 len
= strlen(szTemp
);
233 _ILSimpleGetText(apidl
[0], szTemp
+len
, MAX_PATH
- len
);
234 size
= strlen(szTemp
) + 1;
236 /* fill the structure */
237 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, size
);
238 if(!hGlobal
) return hGlobal
;
239 szFileName
= (char *)GlobalLock(hGlobal
);
240 GlobalUnlock(hGlobal
);
244 HGLOBAL
RenderPREFEREDDROPEFFECT (DWORD dwFlags
)
249 TRACE("(0x%08lx)\n", dwFlags
);
251 hGlobal
= GlobalAlloc(GHND
|GMEM_SHARE
, sizeof(DWORD
));
252 if(!hGlobal
) return hGlobal
;
253 pdwFlag
= (DWORD
*)GlobalLock(hGlobal
);
255 GlobalUnlock(hGlobal
);
259 /**************************************************************************
262 * checks if there is something in the clipboard we can use
264 BOOL
IsDataInClipboard (HWND hwnd
)
268 if (OpenClipboard(hwnd
))
270 if (GetOpenClipboardWindow())
272 ret
= IsClipboardFormatAvailable(CF_TEXT
);