3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
33 #include <wine/debug.h>
35 /* FUNCTIONS *****************************************************************/
42 if (! GetStringTypeW(CT_CTYPE1
, &Ch
, 1, &CharType
))
57 if (!HIWORD(x
)) return (LPSTR
)tolower((char)(int)x
);
58 CharLowerBuffA(x
, strlen(x
));
71 SetLastError( ERROR_INVALID_PARAMETER );
84 CharLowerBuffA(LPSTR str
, DWORD len
)
88 if (!str
) return 0; /* YES */
90 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
91 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
93 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
94 CharLowerBuffW(strW
, lenW
);
95 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
96 HeapFree(GetProcessHeap(), 0, strW
);
107 CharLowerBuffW(LPWSTR str
, DWORD len
)
110 if (!str
) return 0; /* YES */
111 for (; len
; len
--, str
++) *str
= towlower(*str
);
125 return (LPWSTR
)(INT
)towlower((WORD
)(((DWORD
)(x
)) & 0xFFFF));
134 CharPrevW(LPCWSTR start
, LPCWSTR x
)
136 if (x
> start
) return (LPWSTR
)(x
-1);
137 else return (LPWSTR
)x
;
145 CharNextA(LPCSTR ptr
)
147 if (!*ptr
) return (LPSTR
)ptr
;
148 if (IsDBCSLeadByte(ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
149 return (LPSTR
)(ptr
+ 1);
157 CharNextExA(WORD codepage
, LPCSTR ptr
, DWORD flags
)
159 if (!*ptr
) return (LPSTR
)ptr
;
160 if (IsDBCSLeadByteEx(codepage
, ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
161 return (LPSTR
)(ptr
+ 1);
180 CharPrevA(LPCSTR start
, LPCSTR ptr
)
182 while (*start
&& (start
< ptr
)) {
183 LPCSTR next
= CharNextA(start
);
184 if (next
>= ptr
) break;
193 LPSTR WINAPI
CharPrevExA( WORD codepage
, LPCSTR start
, LPCSTR ptr
, DWORD flags
)
195 while (*start
&& (start
< ptr
))
197 LPCSTR next
= CharNextExA( codepage
, start
, flags
);
198 if (next
> ptr
) break;
209 CharToOemA(LPCSTR s
, LPSTR d
)
211 if (!s
|| !d
) return TRUE
;
212 return CharToOemBuffA(s
, d
, strlen(s
) + 1);
220 CharToOemBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
224 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
226 MultiByteToWideChar(CP_ACP
, 0, s
, len
, bufW
, len
);
227 WideCharToMultiByte(CP_OEMCP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
228 HeapFree(GetProcessHeap(), 0, bufW
);
238 CharToOemBuffW(LPCWSTR s
, LPSTR d
, DWORD len
)
242 WideCharToMultiByte(CP_OEMCP
, 0, s
, len
, d
, len
, NULL
, NULL
);
251 CharToOemW(LPCWSTR s
, LPSTR d
)
253 return CharToOemBuffW(s
, d
, wcslen(s
) + 1);
259 LPSTR WINAPI
CharUpperA(LPSTR x
)
261 if (!HIWORD(x
)) return (LPSTR
)toupper((char)(int)x
);
262 CharUpperBuffA(x
, strlen(x
));
271 CharUpperBuffA(LPSTR str
, DWORD len
)
275 if (!str
) return 0; /* YES */
277 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
278 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
280 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
281 CharUpperBuffW(strW
, lenW
);
282 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
283 HeapFree(GetProcessHeap(), 0, strW
);
294 CharUpperBuffW(LPWSTR str
, DWORD len
)
297 if (!str
) return 0; /* YES */
298 for (; len
; len
--, str
++) *str
= towupper(*str
);
309 if (HIWORD(x
)) return _wcsupr(x
);
310 else return (LPWSTR
)(UINT
)towlower((WORD
)(((DWORD
)(x
)) & 0xFFFF));
318 IsCharAlphaA(CHAR Ch
)
322 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
323 return IsCharAlphaW(WCh
);
331 IsCharAlphaNumericA(CHAR Ch
)
335 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
336 return IsCharAlphaNumericW(WCh
);
344 IsCharAlphaNumericW(WCHAR Ch
)
346 return (GetC1Type(Ch
) & (C1_ALPHA
|C1_DIGIT
)) != 0;
354 IsCharAlphaW(WCHAR Ch
)
356 return (GetC1Type(Ch
) & C1_ALPHA
) != 0;
364 IsCharLowerA(CHAR Ch
)
368 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
369 return IsCharLowerW(WCh
);
377 IsCharLowerW(WCHAR Ch
)
379 return (GetC1Type(Ch
) & C1_LOWER
) != 0;
387 IsCharUpperA(CHAR Ch
)
391 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
392 return IsCharUpperW(WCh
);
400 IsCharUpperW(WCHAR Ch
)
402 return (GetC1Type(Ch
) & C1_UPPER
) != 0;
410 OemToCharA(LPCSTR s
, LPSTR d
)
412 return OemToCharBuffA(s
, d
, strlen(s
) + 1);
418 BOOL WINAPI
OemToCharBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
422 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
424 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, bufW
, len
);
425 WideCharToMultiByte(CP_ACP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
426 HeapFree(GetProcessHeap(), 0, bufW
);
436 OemToCharBuffW(LPCSTR s
, LPWSTR d
, DWORD len
)
438 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, d
, len
);
445 BOOL WINAPI
OemToCharW(LPCSTR s
, LPWSTR d
)
447 return OemToCharBuffW(s
, d
, strlen(s
) + 1);