2 * Copyright 2000 Juergen Schmied
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
36 #include "shell32_main.h"
37 #include "undocshell.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(shell);
43 /************************* STRRET functions ****************************/
45 BOOL WINAPI StrRetToStrNA(LPSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
47 TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n",
49 (src->uType == STRRET_WSTR) ? "STRRET_WSTR" :
50 (src->uType == STRRET_CSTR) ? "STRRET_CSTR" :
51 (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
60 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
61 CoTaskMemFree(src->u.pOleStr);
65 lstrcpynA(dest, src->u.cStr, len);
69 lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
73 FIXME("unknown type!\n");
74 if (len) *dest = '\0';
77 TRACE("-- %s\n", debugstr_a(dest) );
81 /************************************************************************/
83 BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
85 TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n",
87 (src->uType == STRRET_WSTR) ? "STRRET_WSTR" :
88 (src->uType == STRRET_CSTR) ? "STRRET_CSTR" :
89 (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
98 lstrcpynW(dest, src->u.pOleStr, len);
99 CoTaskMemFree(src->u.pOleStr);
103 if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len)
108 if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len ) && len)
113 FIXME("unknown type!\n");
114 if (len) *dest = '\0';
121 /*************************************************************************
122 * StrRetToStrN [SHELL32.96]
124 * converts a STRRET to a normal string
127 * the pidl is for STRRET OFFSET
129 BOOL WINAPI StrRetToStrNAW(LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
131 if(SHELL_OsIsUnicode())
132 return StrRetToStrNW(dest, len, src, pidl);
134 return StrRetToStrNA(dest, len, src, pidl);
137 /************************* OLESTR functions ****************************/
139 /************************************************************************
140 * StrToOleStr [SHELL32.163]
143 static int StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
145 TRACE("(%p, %p %s)\n",
146 lpWideCharStr, lpMultiByteString, debugstr_a(lpMultiByteString));
148 return MultiByteToWideChar(0, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
151 static int StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
153 TRACE("(%p, %p %s)\n",
154 lpWideCharStr, lpWString, debugstr_w(lpWString));
156 strcpyW (lpWideCharStr, lpWString );
157 return strlenW(lpWideCharStr);
160 BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
162 if (SHELL_OsIsUnicode())
163 return StrToOleStrW (lpWideCharStr, lpString);
164 return StrToOleStrA (lpWideCharStr, lpString);
167 /*************************************************************************
168 * StrToOleStrN [SHELL32.79]
169 * lpMulti, nMulti, nWide [IN]
172 static BOOL StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
174 TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_an(lpStrA,nStr), nStr);
175 return MultiByteToWideChar (0, 0, lpStrA, nStr, lpWide, nWide);
177 static BOOL StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
179 TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_wn(lpStrW, nStr), nStr);
181 if (lstrcpynW (lpWide, lpStrW, nWide))
182 { return lstrlenW (lpWide);
187 BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
189 if (SHELL_OsIsUnicode())
190 return StrToOleStrNW (lpWide, nWide, lpStr, nStr);
191 return StrToOleStrNA (lpWide, nWide, lpStr, nStr);
194 /*************************************************************************
195 * OleStrToStrN [SHELL32.78]
197 static BOOL OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
199 TRACE("(%p, %x, %s, %x)\n", lpStr, nStr, debugstr_wn(lpOle,nOle), nOle);
200 return WideCharToMultiByte (0, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
203 static BOOL OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
205 TRACE("(%p, %x, %s, %x)\n", lpwStr, nwStr, debugstr_wn(lpOle,nOle), nOle);
207 if (lstrcpynW ( lpwStr, lpOle, nwStr))
208 { return lstrlenW (lpwStr);
213 BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
215 if (SHELL_OsIsUnicode())
216 return OleStrToStrNW (lpOut, nOut, lpIn, nIn);
217 return OleStrToStrNA (lpOut, nOut, lpIn, nIn);
221 /*************************************************************************
222 * CheckEscapesA [SHELL32.@]
224 * Checks a string for special characters which are not allowed in a path
225 * and encloses it in quotes if that is the case.
228 * string [I/O] string to check and on return eventually quoted
229 * len [I] length of string
232 * length of actual string
235 * Not really sure if this function returns actually a value at all.
237 DWORD WINAPI CheckEscapesA(
238 LPSTR string, /* [I/O] string to check ??*/
239 DWORD len) /* [I] is 0 */
244 TRACE("(%s %d)\n", debugstr_a(string), len);
245 wString = LocalAlloc(LPTR, len * sizeof(WCHAR));
248 MultiByteToWideChar(CP_ACP, 0, string, len, wString, len);
249 ret = CheckEscapesW(wString, len);
250 WideCharToMultiByte(CP_ACP, 0, wString, len, string, len, NULL, NULL);
256 static const WCHAR strEscapedChars[] = {' ','"',',',';','^',0};
258 /*************************************************************************
259 * CheckEscapesW [SHELL32.@]
263 DWORD WINAPI CheckEscapesW(
267 DWORD size = lstrlenW(string);
270 TRACE("(%s %d) stub\n", debugstr_w(string), len);
272 if (StrPBrkW(string, strEscapedChars) && size + 2 <= len)
274 s = &string[size - 1];
275 d = &string[size + 2];