[8614] | 1 | /* $Id: clipboard.c,v 1.3 2002-06-09 12:41:20 sandervl Exp $ */
|
---|
[4121] | 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__
|
---|
[21494] | 23 | #define CINTERFACE
|
---|
[4121] | 24 | #include <odin.h>
|
---|
| 25 | #endif
|
---|
| 26 |
|
---|
| 27 | #include <string.h>
|
---|
| 28 |
|
---|
[8048] | 29 | #include "winreg.h"
|
---|
[4121] | 30 | #include "pidl.h"
|
---|
[8614] | 31 | #include "undocshell.h"
|
---|
[4121] | 32 | #include "shell32_main.h"
|
---|
[8048] | 33 | #include "shlwapi.h"
|
---|
[4121] | 34 |
|
---|
[8048] | 35 | #include "debugtools.h"
|
---|
[4121] | 36 |
|
---|
[8048] | 37 | DEFAULT_DEBUG_CHANNEL(shell);
|
---|
| 38 |
|
---|
[4121] | 39 | static int refClipCount = 0;
|
---|
| 40 | static HINSTANCE hShellOle32 = 0;
|
---|
| 41 |
|
---|
| 42 | /**************************************************************************
|
---|
| 43 | * InitShellOle
|
---|
| 44 | *
|
---|
| 45 | *
|
---|
| 46 | */
|
---|
| 47 | void InitShellOle(void)
|
---|
| 48 | {
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /**************************************************************************
|
---|
| 52 | * FreeShellOle
|
---|
| 53 | *
|
---|
| 54 | * unload OLE32.DLL
|
---|
| 55 | */
|
---|
| 56 | void 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 | */
|
---|
| 70 | BOOL 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 | */
|
---|
| 98 | HGLOBAL 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;
|
---|
[8048] | 105 | DROPFILES *pDropFiles;
|
---|
[4121] | 106 | int offset;
|
---|
| 107 |
|
---|
| 108 | TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl);
|
---|
| 109 |
|
---|
| 110 | /* get the size needed */
|
---|
[8048] | 111 | size = sizeof(DROPFILES);
|
---|
[4121] | 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 |
|
---|
[8048] | 129 | pDropFiles = (DROPFILES *)GlobalLock(hGlobal);
|
---|
| 130 | pDropFiles->pFiles = sizeof(DROPFILES);
|
---|
| 131 | pDropFiles->fWide = FALSE;
|
---|
[4121] | 132 |
|
---|
[8048] | 133 | offset = pDropFiles->pFiles;
|
---|
[4121] | 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 |
|
---|
| 151 | HGLOBAL 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 |
|
---|
| 192 | HGLOBAL RenderSHELLIDLISTOFFSET (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
|
---|
| 193 | {
|
---|
| 194 | FIXME("\n");
|
---|
| 195 | return 0;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | HGLOBAL RenderFILECONTENTS (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
|
---|
| 199 | {
|
---|
| 200 | FIXME("\n");
|
---|
| 201 | return 0;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | HGLOBAL RenderFILEDESCRIPTOR (LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl)
|
---|
| 205 | {
|
---|
| 206 | FIXME("\n");
|
---|
| 207 | return 0;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | HGLOBAL 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 |
|
---|
| 233 | HGLOBAL 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 | */
|
---|
| 253 | BOOL 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 | }
|
---|