1c2c66affSColin Finck /*
2c2c66affSColin Finck * Copyright 2000 Juergen Schmied
3c2c66affSColin Finck *
4c2c66affSColin Finck * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck * License as published by the Free Software Foundation; either
7c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck *
9c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c2c66affSColin Finck * Lesser General Public License for more details.
13c2c66affSColin Finck *
14c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck */
18c2c66affSColin Finck
19c2c66affSColin Finck #define WIN32_NO_STATUS
20c2c66affSColin Finck #define _INC_WINDOWS
21c2c66affSColin Finck #define NONAMELESSUNION
22c2c66affSColin Finck #define NONAMELESSSTRUCT
23c2c66affSColin Finck
24c2c66affSColin Finck #include <windef.h>
25c2c66affSColin Finck #include <winbase.h>
26c2c66affSColin Finck #include <shlobj.h>
27c2c66affSColin Finck #include <shlwapi.h>
28*52dd07feSHermès Bélusca-Maïto #include <undocshell.h>
29*52dd07feSHermès Bélusca-Maïto #include <shlwapi_undoc.h>
30c2c66affSColin Finck #include <wine/unicode.h>
31c2c66affSColin Finck #include <wine/debug.h>
32c2c66affSColin Finck
33c2c66affSColin Finck #include "shell32_main.h"
34c2c66affSColin Finck
35c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(shell);
36c2c66affSColin Finck
37c2c66affSColin Finck /************************* STRRET functions ****************************/
38c2c66affSColin Finck
debugstr_strret(STRRET * s)39c2c66affSColin Finck static const char *debugstr_strret(STRRET *s)
40c2c66affSColin Finck {
41c2c66affSColin Finck switch (s->uType)
42c2c66affSColin Finck {
43c2c66affSColin Finck case STRRET_WSTR:
44c2c66affSColin Finck return "STRRET_WSTR";
45c2c66affSColin Finck case STRRET_CSTR:
46c2c66affSColin Finck return "STRRET_CSTR";
47c2c66affSColin Finck case STRRET_OFFSET:
48c2c66affSColin Finck return "STRRET_OFFSET";
49c2c66affSColin Finck default:
50c2c66affSColin Finck return "STRRET_???";
51c2c66affSColin Finck }
52c2c66affSColin Finck }
53c2c66affSColin Finck
StrRetToStrNA(LPSTR dest,DWORD len,LPSTRRET src,const ITEMIDLIST * pidl)54c2c66affSColin Finck BOOL WINAPI StrRetToStrNA(LPSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
55c2c66affSColin Finck {
56c2c66affSColin Finck TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
57c2c66affSColin Finck
58c2c66affSColin Finck if (!dest)
59c2c66affSColin Finck return FALSE;
60c2c66affSColin Finck
61c2c66affSColin Finck switch (src->uType)
62c2c66affSColin Finck {
63c2c66affSColin Finck case STRRET_WSTR:
64c2c66affSColin Finck WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
65c2c66affSColin Finck CoTaskMemFree(src->u.pOleStr);
66c2c66affSColin Finck break;
67c2c66affSColin Finck case STRRET_CSTR:
68c2c66affSColin Finck lstrcpynA(dest, src->u.cStr, len);
69c2c66affSColin Finck break;
70c2c66affSColin Finck case STRRET_OFFSET:
71c2c66affSColin Finck lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
72c2c66affSColin Finck break;
73c2c66affSColin Finck default:
74c2c66affSColin Finck FIXME("unknown type %u!\n", src->uType);
75c2c66affSColin Finck if (len)
76c2c66affSColin Finck *dest = '\0';
77c2c66affSColin Finck return FALSE;
78c2c66affSColin Finck }
79c2c66affSColin Finck TRACE("-- %s\n", debugstr_a(dest) );
80c2c66affSColin Finck return TRUE;
81c2c66affSColin Finck }
82c2c66affSColin Finck
83c2c66affSColin Finck /************************************************************************/
84c2c66affSColin Finck
StrRetToStrNW(LPWSTR dest,DWORD len,LPSTRRET src,const ITEMIDLIST * pidl)85c2c66affSColin Finck BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
86c2c66affSColin Finck {
87c2c66affSColin Finck TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
88c2c66affSColin Finck
89c2c66affSColin Finck if (!dest)
90c2c66affSColin Finck return FALSE;
91c2c66affSColin Finck
92c2c66affSColin Finck switch (src->uType)
93c2c66affSColin Finck {
94c2c66affSColin Finck case STRRET_WSTR:
95c2c66affSColin Finck lstrcpynW(dest, src->u.pOleStr, len);
96c2c66affSColin Finck CoTaskMemFree(src->u.pOleStr);
97c2c66affSColin Finck break;
98c2c66affSColin Finck case STRRET_CSTR:
99c2c66affSColin Finck if (!MultiByteToWideChar(CP_ACP, 0, src->u.cStr, -1, dest, len) && len)
100c2c66affSColin Finck dest[len-1] = 0;
101c2c66affSColin Finck break;
102c2c66affSColin Finck case STRRET_OFFSET:
103c2c66affSColin Finck if (!MultiByteToWideChar(CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len)
104c2c66affSColin Finck && len)
105c2c66affSColin Finck dest[len-1] = 0;
106c2c66affSColin Finck break;
107c2c66affSColin Finck default:
108c2c66affSColin Finck FIXME("unknown type %u!\n", src->uType);
109c2c66affSColin Finck if (len)
110c2c66affSColin Finck *dest = '\0';
111c2c66affSColin Finck return FALSE;
112c2c66affSColin Finck }
113c2c66affSColin Finck return TRUE;
114c2c66affSColin Finck }
115c2c66affSColin Finck
116c2c66affSColin Finck
117c2c66affSColin Finck /*************************************************************************
118c2c66affSColin Finck * StrRetToStrN [SHELL32.96]
119c2c66affSColin Finck *
120c2c66affSColin Finck * converts a STRRET to a normal string
121c2c66affSColin Finck *
122c2c66affSColin Finck * NOTES
123c2c66affSColin Finck * the pidl is for STRRET OFFSET
124c2c66affSColin Finck */
StrRetToStrNAW(LPVOID dest,DWORD len,LPSTRRET src,const ITEMIDLIST * pidl)125c2c66affSColin Finck BOOL WINAPI StrRetToStrNAW(LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
126c2c66affSColin Finck {
127c2c66affSColin Finck if(SHELL_OsIsUnicode())
128c2c66affSColin Finck return StrRetToStrNW(dest, len, src, pidl);
129c2c66affSColin Finck else
130c2c66affSColin Finck return StrRetToStrNA(dest, len, src, pidl);
131c2c66affSColin Finck }
132c2c66affSColin Finck
133c2c66affSColin Finck /************************* OLESTR functions ****************************/
134c2c66affSColin Finck
135c2c66affSColin Finck /************************************************************************
136c2c66affSColin Finck * StrToOleStr [SHELL32.163]
137c2c66affSColin Finck *
138c2c66affSColin Finck */
StrToOleStrA(LPWSTR lpWideCharStr,LPCSTR lpMultiByteString)139c2c66affSColin Finck static int StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
140c2c66affSColin Finck {
141c2c66affSColin Finck TRACE("(%p, %p %s)\n",
142c2c66affSColin Finck lpWideCharStr, lpMultiByteString, debugstr_a(lpMultiByteString));
143c2c66affSColin Finck
144c2c66affSColin Finck return MultiByteToWideChar(CP_ACP, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
145c2c66affSColin Finck
146c2c66affSColin Finck }
StrToOleStrW(LPWSTR lpWideCharStr,LPCWSTR lpWString)147c2c66affSColin Finck static int StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
148c2c66affSColin Finck {
149c2c66affSColin Finck TRACE("(%p, %p %s)\n",
150c2c66affSColin Finck lpWideCharStr, lpWString, debugstr_w(lpWString));
151c2c66affSColin Finck
152c2c66affSColin Finck strcpyW (lpWideCharStr, lpWString );
153c2c66affSColin Finck return strlenW(lpWideCharStr);
154c2c66affSColin Finck }
155c2c66affSColin Finck
StrToOleStrAW(LPWSTR lpWideCharStr,LPCVOID lpString)156c2c66affSColin Finck BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
157c2c66affSColin Finck {
158c2c66affSColin Finck if (SHELL_OsIsUnicode())
159c2c66affSColin Finck return StrToOleStrW (lpWideCharStr, lpString);
160c2c66affSColin Finck return StrToOleStrA (lpWideCharStr, lpString);
161c2c66affSColin Finck }
162c2c66affSColin Finck
163c2c66affSColin Finck /*************************************************************************
164c2c66affSColin Finck * StrToOleStrN [SHELL32.79]
165c2c66affSColin Finck * lpMulti, nMulti, nWide [IN]
166c2c66affSColin Finck * lpWide [OUT]
167c2c66affSColin Finck */
StrToOleStrNA(LPWSTR lpWide,INT nWide,LPCSTR lpStrA,INT nStr)168c2c66affSColin Finck static BOOL StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
169c2c66affSColin Finck {
170c2c66affSColin Finck TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_an(lpStrA,nStr), nStr);
171c2c66affSColin Finck return MultiByteToWideChar (CP_ACP, 0, lpStrA, nStr, lpWide, nWide);
172c2c66affSColin Finck }
StrToOleStrNW(LPWSTR lpWide,INT nWide,LPCWSTR lpStrW,INT nStr)173c2c66affSColin Finck static BOOL StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
174c2c66affSColin Finck {
175c2c66affSColin Finck TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_wn(lpStrW, nStr), nStr);
176c2c66affSColin Finck
177c2c66affSColin Finck if (lstrcpynW (lpWide, lpStrW, nWide))
178c2c66affSColin Finck { return lstrlenW (lpWide);
179c2c66affSColin Finck }
180c2c66affSColin Finck return FALSE;
181c2c66affSColin Finck }
182c2c66affSColin Finck
StrToOleStrNAW(LPWSTR lpWide,INT nWide,LPCVOID lpStr,INT nStr)183c2c66affSColin Finck BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
184c2c66affSColin Finck {
185c2c66affSColin Finck if (SHELL_OsIsUnicode())
186c2c66affSColin Finck return StrToOleStrNW (lpWide, nWide, lpStr, nStr);
187c2c66affSColin Finck return StrToOleStrNA (lpWide, nWide, lpStr, nStr);
188c2c66affSColin Finck }
189c2c66affSColin Finck
190c2c66affSColin Finck /*************************************************************************
191c2c66affSColin Finck * OleStrToStrN [SHELL32.78]
192c2c66affSColin Finck */
OleStrToStrNA(LPSTR lpStr,INT nStr,LPCWSTR lpOle,INT nOle)193c2c66affSColin Finck static BOOL OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
194c2c66affSColin Finck {
195c2c66affSColin Finck TRACE("(%p, %x, %s, %x)\n", lpStr, nStr, debugstr_wn(lpOle,nOle), nOle);
196c2c66affSColin Finck return WideCharToMultiByte (CP_ACP, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
197c2c66affSColin Finck }
198c2c66affSColin Finck
OleStrToStrNW(LPWSTR lpwStr,INT nwStr,LPCWSTR lpOle,INT nOle)199c2c66affSColin Finck static BOOL OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
200c2c66affSColin Finck {
201c2c66affSColin Finck TRACE("(%p, %x, %s, %x)\n", lpwStr, nwStr, debugstr_wn(lpOle,nOle), nOle);
202c2c66affSColin Finck
203c2c66affSColin Finck if (lstrcpynW ( lpwStr, lpOle, nwStr))
204c2c66affSColin Finck { return lstrlenW (lpwStr);
205c2c66affSColin Finck }
206c2c66affSColin Finck return FALSE;
207c2c66affSColin Finck }
208c2c66affSColin Finck
OleStrToStrNAW(LPVOID lpOut,INT nOut,LPCVOID lpIn,INT nIn)209c2c66affSColin Finck BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
210c2c66affSColin Finck {
211c2c66affSColin Finck if (SHELL_OsIsUnicode())
212c2c66affSColin Finck return OleStrToStrNW (lpOut, nOut, lpIn, nIn);
213c2c66affSColin Finck return OleStrToStrNA (lpOut, nOut, lpIn, nIn);
214c2c66affSColin Finck }
215c2c66affSColin Finck
216c2c66affSColin Finck
217c2c66affSColin Finck /*************************************************************************
218c2c66affSColin Finck * CheckEscapesA [SHELL32.@]
219c2c66affSColin Finck *
220c2c66affSColin Finck * Checks a string for special characters which are not allowed in a path
221c2c66affSColin Finck * and encloses it in quotes if that is the case.
222c2c66affSColin Finck *
223c2c66affSColin Finck * PARAMS
224c2c66affSColin Finck * string [I/O] string to check and on return eventually quoted
225c2c66affSColin Finck * len [I] length of string
226c2c66affSColin Finck */
CheckEscapesA(LPSTR string,DWORD len)22799b52df0SKatayama Hirofumi MZ VOID WINAPI CheckEscapesA(
228c2c66affSColin Finck LPSTR string, /* [I/O] string to check ??*/
229c2c66affSColin Finck DWORD len) /* [I] is 0 */
230c2c66affSColin Finck {
231c2c66affSColin Finck LPWSTR wString;
232c2c66affSColin Finck TRACE("(%s %d)\n", debugstr_a(string), len);
23399b52df0SKatayama Hirofumi MZ
23499b52df0SKatayama Hirofumi MZ if (!string || !string[0])
23599b52df0SKatayama Hirofumi MZ return;
23699b52df0SKatayama Hirofumi MZ
237c2c66affSColin Finck wString = LocalAlloc(LPTR, len * sizeof(WCHAR));
23899b52df0SKatayama Hirofumi MZ if (!wString)
23999b52df0SKatayama Hirofumi MZ return;
24099b52df0SKatayama Hirofumi MZ
24199b52df0SKatayama Hirofumi MZ SHAnsiToUnicode(string, wString, len);
24299b52df0SKatayama Hirofumi MZ CheckEscapesW(wString, len);
24399b52df0SKatayama Hirofumi MZ SHUnicodeToAnsi(wString, string, len);
244c2c66affSColin Finck LocalFree(wString);
245c2c66affSColin Finck }
246c2c66affSColin Finck
247c2c66affSColin Finck /*************************************************************************
248c2c66affSColin Finck * CheckEscapesW [SHELL32.@]
249c2c66affSColin Finck *
250c2c66affSColin Finck * See CheckEscapesA.
251c2c66affSColin Finck */
CheckEscapesW(LPWSTR string,DWORD len)25299b52df0SKatayama Hirofumi MZ VOID WINAPI CheckEscapesW(
253c2c66affSColin Finck LPWSTR string,
254c2c66affSColin Finck DWORD len)
255c2c66affSColin Finck {
256c2c66affSColin Finck DWORD size = lstrlenW(string);
257c2c66affSColin Finck LPWSTR s, d;
258c2c66affSColin Finck
259c2c66affSColin Finck TRACE("(%s %d) stub\n", debugstr_w(string), len);
260c2c66affSColin Finck
26183be315aSHermès Bélusca-Maïto if (StrPBrkW(string, L" \",;^") && size + 2 <= len)
262c2c66affSColin Finck {
263c2c66affSColin Finck s = &string[size - 1];
264c2c66affSColin Finck d = &string[size + 2];
265c2c66affSColin Finck *d-- = 0;
266c2c66affSColin Finck *d-- = '"';
267c2c66affSColin Finck for (;d > string;)
268c2c66affSColin Finck *d-- = *s--;
269c2c66affSColin Finck *d = '"';
270c2c66affSColin Finck }
271c2c66affSColin Finck }
272