source: trunk/src/shell32/clipboard.c@ 10367

Last change on this file since 10367 was 8614, checked in by sandervl, 23 years ago

compile fixes

File size: 6.0 KB
Line 
1/* $Id: clipboard.c,v 1.3 2002-06-09 12:41:20 sandervl Exp $ */
2/*
3 * clipboard helper functions
4 *
5 * Copyright 2000 Juergen Schmied <juergen.schmied@debitel.de>
6 *
7 * For copy & paste functions within contextmenus does the shell use
8 * the OLE clipboard functions in combination with dataobjects.
9 * The OLE32.DLL gets loaded with LoadLibrary
10 *
11 * - a right mousebutton-copy sets the following formats:
12 * classic:
13 * Shell IDList Array
14 * Prefered Drop Effect
15 * Shell Object Offsets
16 * HDROP
17 * FileName
18 * ole:
19 * OlePrivateData (ClipboardDataObjectInterface)
20 *
21 */
22#ifdef __WIN32OS2__
23#define ICOM_CINTERFACE 1
24#include <odin.h>
25#endif
26
27#include <string.h>
28
29#include "winreg.h"
30#include "pidl.h"
31#include "undocshell.h"
32#include "shell32_main.h"
33#include "shlwapi.h"
34
35#include "debugtools.h"
36
37DEFAULT_DEBUG_CHANNEL(shell);
38
39static int refClipCount = 0;
40static HINSTANCE hShellOle32 = 0;
41
42/**************************************************************************
43 * InitShellOle
44 *
45 *
46 */
47void InitShellOle(void)
48{
49}
50
51/**************************************************************************
52 * FreeShellOle
53 *
54 * unload OLE32.DLL
55 */
56void FreeShellOle(void)
57{
58 if (!--refClipCount)
59 {
60 pOleUninitialize();
61 FreeLibrary(hShellOle32);
62 }
63}
64
65/**************************************************************************
66 * LoadShellOle
67 *
68 * make sure OLE32.DLL is loaded
69 */
70BOOL GetShellOle(void)
71{
72 if(!refClipCount)
73 {
74 hShellOle32 = LoadLibraryA("ole32.dll");
75 if(hShellOle32)
76 {
77 pOleInitialize=(void*)GetProcAddress(hShellOle32,"OleInitialize");
78 pOleUninitialize=(void*)GetProcAddress(hShellOle32,"OleUninitialize");
79 pRegisterDragDrop=(void*)GetProcAddress(hShellOle32,"RegisterDragDrop");
80 pRevokeDragDrop=(void*)GetProcAddress(hShellOle32,"RevokeDragDrop");
81 pDoDragDrop=(void*)GetProcAddress(hShellOle32,"DoDragDrop");
82 pReleaseStgMedium=(void*)GetProcAddress(hShellOle32,"ReleaseStgMedium");
83 pOleSetClipboard=(void*)GetProcAddress(hShellOle32,"OleSetClipboard");
84 pOleGetClipboard=(void*)GetProcAddress(hShellOle32,"OleGetClipboard");
85
86 pOleInitialize(NULL);
87 refClipCount++;
88 }
89 }
90 return TRUE;
91}
92
93/**************************************************************************
94 * RenderHDROP
95 *
96 * creates a CF_HDROP structure
97 */
98HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
99{
100 int i;
101 int rootsize = 0,size = 0;
102 char szRootPath[MAX_PATH];
103 char szFileName[MAX_PATH];
104 HGLOBAL hGlobal;
105 DROPFILES *pDropFiles;
106 int offset;
107
108 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
109
110 /* get the size needed */
111 size = sizeof(DROPFILES);
112
113 SHGetPathFromIDListA(pidlRoot, szRootPath);
114 PathAddBackslashA(szRootPath);
115 rootsize = strlen(szRootPath);
116
117 for (i=0; i<cidl;i++)
118 {
119 _ILSimpleGetText(apidl[i], szFileName, MAX_PATH);
120 size += rootsize + strlen(szFileName) + 1;
121 }
122
123 size++;
124
125 /* Fill the structure */
126 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
127 if(!hGlobal) return hGlobal;
128
129 pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
130 pDropFiles->pFiles = sizeof(DROPFILES);
131 pDropFiles->fWide = FALSE;
132
133 offset = pDropFiles->pFiles;
134 strcpy(szFileName, szRootPath);
135
136 for (i=0; i<cidl;i++)
137 {
138
139 _ILSimpleGetText(apidl[i], szFileName + rootsize, MAX_PATH - rootsize);
140 size = strlen(szFileName) + 1;
141 strcpy(((char*)pDropFiles)+offset, szFileName);
142 offset += size;
143 }
144
145 ((char*)pDropFiles)[offset] = 0;
146 GlobalUnlock(hGlobal);
147
148 return hGlobal;
149}
150
151HGLOBAL RenderSHELLIDLIST (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
152{
153 int i,offset = 0, sizePidl, size;
154 HGLOBAL hGlobal;
155 LPCIDA pcida;
156
157 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
158
159 /* get the size needed */
160 size = sizeof(CIDA) + sizeof (UINT)*(cidl); /* header */
161 size += ILGetSize (pidlRoot); /* root pidl */
162 for(i=0; i<cidl; i++)
163 {
164 size += ILGetSize(apidl[i]); /* child pidls */
165 }
166
167 /* fill the structure */
168 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
169 if(!hGlobal) return hGlobal;
170 pcida = GlobalLock (hGlobal);
171 pcida->cidl = cidl;
172
173 /* root pidl */
174 offset = sizeof(CIDA) + sizeof (UINT)*(cidl);
175 pcida->aoffset[0] = offset; /* first element */
176 sizePidl = ILGetSize (pidlRoot);
177 memcpy(((LPBYTE)pcida)+offset, pidlRoot, sizePidl);
178 offset += sizePidl;
179
180 for(i=0; i<cidl; i++) /* child pidls */
181 {
182 pcida->aoffset[i+1] = offset;
183 sizePidl = ILGetSize(apidl[i]);
184 memcpy(((LPBYTE)pcida)+offset, apidl[i], sizePidl);
185 offset += sizePidl;
186 }
187
188 GlobalUnlock(hGlobal);
189 return hGlobal;
190}
191
192HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
193{
194 FIXME("\n");
195 return 0;
196}
197
198HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
199{
200 FIXME("\n");
201 return 0;
202}
203
204HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
205{
206 FIXME("\n");
207 return 0;
208}
209
210HGLOBAL RenderFILENAME (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
211{
212 int len, size = 0;
213 char szTemp[MAX_PATH], *szFileName;
214 HGLOBAL hGlobal;
215
216 TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
217
218 /* build name of first file */
219 SHGetPathFromIDListA(pidlRoot, szTemp);
220 PathAddBackslashA(szTemp);
221 len = strlen(szTemp);
222 _ILSimpleGetText(apidl[0], szTemp+len, MAX_PATH - len);
223 size = strlen(szTemp) + 1;
224
225 /* fill the structure */
226 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size);
227 if(!hGlobal) return hGlobal;
228 szFileName = (char *)GlobalLock(hGlobal);
229 GlobalUnlock(hGlobal);
230 return hGlobal;
231}
232
233HGLOBAL RenderPREFEREDDROPEFFECT (DWORD dwFlags)
234{
235 DWORD * pdwFlag;
236 HGLOBAL hGlobal;
237
238 TRACE("(0x%08lx)\n", dwFlags);
239
240 hGlobal = GlobalAlloc(GHND|GMEM_SHARE, sizeof(DWORD));
241 if(!hGlobal) return hGlobal;
242 pdwFlag = (DWORD*)GlobalLock(hGlobal);
243 *pdwFlag = dwFlags;
244 GlobalUnlock(hGlobal);
245 return hGlobal;
246}
247
248/**************************************************************************
249 * IsDataInClipboard
250 *
251 * checks if there is something in the clipboard we can use
252 */
253BOOL IsDataInClipboard (HWND hwnd)
254{
255 BOOL ret = FALSE;
256
257 if (OpenClipboard(hwnd))
258 {
259 if (GetOpenClipboardWindow())
260 {
261 ret = IsClipboardFormatAvailable(CF_TEXT);
262 }
263 CloseClipboard();
264 }
265 return ret;
266}
Note: See TracBrowser for help on using the repository browser.