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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
38 #include "shell32_main.h"
39 #include "undocshell.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
45 /************************* STRRET functions ****************************/
47 BOOL WINAPI
StrRetToStrNA(LPSTR dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
49 TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
51 (src
->uType
== STRRET_WSTR
) ? "STRRET_WSTR" :
52 (src
->uType
== STRRET_CSTR
) ? "STRRET_CSTR" :
53 (src
->uType
== STRRET_OFFSET
) ? "STRRET_OFFSET" : "STRRET_???",
62 WideCharToMultiByte(CP_ACP
, 0, src
->u
.pOleStr
, -1, dest
, len
, NULL
, NULL
);
63 CoTaskMemFree(src
->u
.pOleStr
);
67 lstrcpynA(dest
, src
->u
.cStr
, len
);
71 lstrcpynA(dest
, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, len
);
75 FIXME("unknown type!\n");
76 if (len
) *dest
= '\0';
79 TRACE("-- %s\n", debugstr_a(dest
) );
83 /************************************************************************/
85 BOOL WINAPI
StrRetToStrNW(LPWSTR dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
87 TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
89 (src
->uType
== STRRET_WSTR
) ? "STRRET_WSTR" :
90 (src
->uType
== STRRET_CSTR
) ? "STRRET_CSTR" :
91 (src
->uType
== STRRET_OFFSET
) ? "STRRET_OFFSET" : "STRRET_???",
100 lstrcpynW(dest
, src
->u
.pOleStr
, len
);
101 CoTaskMemFree(src
->u
.pOleStr
);
105 if (!MultiByteToWideChar( CP_ACP
, 0, src
->u
.cStr
, -1, dest
, len
) && len
)
110 if (!MultiByteToWideChar( CP_ACP
, 0, ((LPCSTR
)&pidl
->mkid
)+src
->u
.uOffset
, -1, dest
, len
) && len
)
115 FIXME("unknown type!\n");
116 if (len
) *dest
= '\0';
123 /*************************************************************************
124 * StrRetToStrN [SHELL32.96]
126 * converts a STRRET to a normal string
129 * the pidl is for STRRET OFFSET
131 BOOL WINAPI
StrRetToStrNAW(LPVOID dest
, DWORD len
, LPSTRRET src
, const ITEMIDLIST
*pidl
)
133 if(SHELL_OsIsUnicode())
134 return StrRetToStrNW(dest
, len
, src
, pidl
);
136 return StrRetToStrNA(dest
, len
, src
, pidl
);
139 /************************* OLESTR functions ****************************/
141 /************************************************************************
142 * StrToOleStr [SHELL32.163]
145 int WINAPI
StrToOleStrA (LPWSTR lpWideCharStr
, LPCSTR lpMultiByteString
)
147 TRACE("(%p, %p %s)\n",
148 lpWideCharStr
, lpMultiByteString
, debugstr_a(lpMultiByteString
));
150 return MultiByteToWideChar(0, 0, lpMultiByteString
, -1, lpWideCharStr
, MAX_PATH
);
153 int WINAPI
StrToOleStrW (LPWSTR lpWideCharStr
, LPCWSTR lpWString
)
155 TRACE("(%p, %p %s)\n",
156 lpWideCharStr
, lpWString
, debugstr_w(lpWString
));
158 strcpyW (lpWideCharStr
, lpWString
);
159 return strlenW(lpWideCharStr
);
162 BOOL WINAPI
StrToOleStrAW (LPWSTR lpWideCharStr
, LPCVOID lpString
)
164 if (SHELL_OsIsUnicode())
165 return StrToOleStrW (lpWideCharStr
, lpString
);
166 return StrToOleStrA (lpWideCharStr
, lpString
);
169 /*************************************************************************
170 * StrToOleStrN [SHELL32.79]
171 * lpMulti, nMulti, nWide [IN]
174 BOOL WINAPI
StrToOleStrNA (LPWSTR lpWide
, INT nWide
, LPCSTR lpStrA
, INT nStr
)
176 TRACE("(%p, %x, %s, %x)\n", lpWide
, nWide
, debugstr_an(lpStrA
,nStr
), nStr
);
177 return MultiByteToWideChar (0, 0, lpStrA
, nStr
, lpWide
, nWide
);
179 BOOL WINAPI
StrToOleStrNW (LPWSTR lpWide
, INT nWide
, LPCWSTR lpStrW
, INT nStr
)
181 TRACE("(%p, %x, %s, %x)\n", lpWide
, nWide
, debugstr_wn(lpStrW
, nStr
), nStr
);
183 if (lstrcpynW (lpWide
, lpStrW
, nWide
))
184 { return lstrlenW (lpWide
);
189 BOOL WINAPI
StrToOleStrNAW (LPWSTR lpWide
, INT nWide
, LPCVOID lpStr
, INT nStr
)
191 if (SHELL_OsIsUnicode())
192 return StrToOleStrNW (lpWide
, nWide
, lpStr
, nStr
);
193 return StrToOleStrNA (lpWide
, nWide
, lpStr
, nStr
);
196 /*************************************************************************
197 * OleStrToStrN [SHELL32.78]
199 BOOL WINAPI
OleStrToStrNA (LPSTR lpStr
, INT nStr
, LPCWSTR lpOle
, INT nOle
)
201 TRACE("(%p, %x, %s, %x)\n", lpStr
, nStr
, debugstr_wn(lpOle
,nOle
), nOle
);
202 return WideCharToMultiByte (0, 0, lpOle
, nOle
, lpStr
, nStr
, NULL
, NULL
);
205 BOOL WINAPI
OleStrToStrNW (LPWSTR lpwStr
, INT nwStr
, LPCWSTR lpOle
, INT nOle
)
207 TRACE("(%p, %x, %s, %x)\n", lpwStr
, nwStr
, debugstr_wn(lpOle
,nOle
), nOle
);
209 if (lstrcpynW ( lpwStr
, lpOle
, nwStr
))
210 { return lstrlenW (lpwStr
);
215 BOOL WINAPI
OleStrToStrNAW (LPVOID lpOut
, INT nOut
, LPCVOID lpIn
, INT nIn
)
217 if (SHELL_OsIsUnicode())
218 return OleStrToStrNW (lpOut
, nOut
, lpIn
, nIn
);
219 return OleStrToStrNA (lpOut
, nOut
, lpIn
, nIn
);
223 /*************************************************************************
224 * CheckEscapesA [SHELL32.@]
226 * Checks a string for special characters which are not allowed in a path
227 * and encloses it in quotes if that is the case.
230 * string [I/O] string to check and on return eventually quoted
231 * len [I] length of string
234 * length of actual string
237 * Not really sure if this function returns actually a value at all.
239 DWORD WINAPI
CheckEscapesA(
240 LPSTR string
, /* [I/O] string to check ??*/
241 DWORD len
) /* [I] is 0 */
246 TRACE("(%s %ld)\n", debugstr_a(string
), len
);
247 wString
= (LPWSTR
)LocalAlloc(LPTR
, len
* sizeof(WCHAR
));
250 MultiByteToWideChar(CP_ACP
, 0, string
, len
, wString
, len
);
251 ret
= CheckEscapesW(wString
, len
);
252 WideCharToMultiByte(CP_ACP
, 0, wString
, len
, string
, len
, NULL
, NULL
);
258 static const WCHAR strEscapedChars
[] = {' ','"',',',';','^',0};
260 /*************************************************************************
261 * CheckEscapesW [SHELL32.@]
265 DWORD WINAPI
CheckEscapesW(
269 DWORD size
= lstrlenW(string
);
272 TRACE("(%s %ld) stub\n", debugstr_w(string
), len
);
274 if (StrPBrkW(string
, strEscapedChars
) && size
+ 2 <= len
)
276 s
= &string
[size
- 1];
277 d
= &string
[size
+ 2];