gdiplus: Add TRACE(..) for font calls.
[wine/multimedia.git] / dlls / shell32 / shellstring.c
bloba35e15cd96c0b971e89585193fc3f943c2125867
1 /*
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
19 #include <string.h>
20 #include <stdarg.h>
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <stdlib.h>
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winreg.h"
34 #include "shlobj.h"
35 #include "shlwapi.h"
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",
48 dest,len,src,
49 (src->uType == STRRET_WSTR) ? "STRRET_WSTR" :
50 (src->uType == STRRET_CSTR) ? "STRRET_CSTR" :
51 (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
52 pidl);
54 if (!dest)
55 return FALSE;
57 switch (src->uType)
59 case STRRET_WSTR:
60 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
61 CoTaskMemFree(src->u.pOleStr);
62 break;
64 case STRRET_CSTR:
65 lstrcpynA(dest, src->u.cStr, len);
66 break;
68 case STRRET_OFFSET:
69 lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
70 break;
72 default:
73 FIXME("unknown type!\n");
74 if (len) *dest = '\0';
75 return FALSE;
77 TRACE("-- %s\n", debugstr_a(dest) );
78 return TRUE;
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",
86 dest,len,src,
87 (src->uType == STRRET_WSTR) ? "STRRET_WSTR" :
88 (src->uType == STRRET_CSTR) ? "STRRET_CSTR" :
89 (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
90 pidl);
92 if (!dest)
93 return FALSE;
95 switch (src->uType)
97 case STRRET_WSTR:
98 lstrcpynW(dest, src->u.pOleStr, len);
99 CoTaskMemFree(src->u.pOleStr);
100 break;
102 case STRRET_CSTR:
103 if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len)
104 dest[len-1] = 0;
105 break;
107 case STRRET_OFFSET:
108 if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len ) && len)
109 dest[len-1] = 0;
110 break;
112 default:
113 FIXME("unknown type!\n");
114 if (len) *dest = '\0';
115 return FALSE;
117 return TRUE;
121 /*************************************************************************
122 * StrRetToStrN [SHELL32.96]
124 * converts a STRRET to a normal string
126 * NOTES
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);
133 else
134 return StrRetToStrNA(dest, len, src, pidl);
137 /************************* OLESTR functions ****************************/
139 /************************************************************************
140 * StrToOleStr [SHELL32.163]
143 int WINAPI 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 int WINAPI 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]
170 * lpWide [OUT]
172 BOOL WINAPI 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 BOOL WINAPI 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);
184 return 0;
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 BOOL WINAPI 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 BOOL WINAPI 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);
210 return 0;
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.
227 * PARAMS
228 * string [I/O] string to check and on return eventually quoted
229 * len [I] length of string
231 * RETURNS
232 * length of actual string
234 * NOTES
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 */
241 LPWSTR wString;
242 DWORD ret = 0;
244 TRACE("(%s %d)\n", debugstr_a(string), len);
245 wString = (LPWSTR)LocalAlloc(LPTR, len * sizeof(WCHAR));
246 if (wString)
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);
251 LocalFree(wString);
253 return ret;
256 static const WCHAR strEscapedChars[] = {' ','"',',',';','^',0};
258 /*************************************************************************
259 * CheckEscapesW [SHELL32.@]
261 * See CheckEscapesA.
263 DWORD WINAPI CheckEscapesW(
264 LPWSTR string,
265 DWORD len)
267 DWORD size = lstrlenW(string);
268 LPWSTR s, d;
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];
276 *d-- = 0;
277 *d-- = '"';
278 for (;d > string;)
279 *d-- = *s--;
280 *d = '"';
281 return size + 2;
283 return size;