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 /* FUNCTIONS *****************************************************************/
40 if (! GetStringTypeW(CT_CTYPE1
, &Ch
, 1, &CharType
))
55 if (!HIWORD(x
)) return (LPSTR
)tolower((char)(int)x
);
68 SetLastError( ERROR_INVALID_PARAMETER );
81 CharLowerBuffA(LPSTR str
, DWORD len
)
85 if (!str
) return 0; /* YES */
87 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
88 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
90 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
91 CharLowerBuffW(strW
, lenW
);
92 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
93 HeapFree(GetProcessHeap(), 0, strW
);
104 CharLowerBuffW(LPWSTR str
, DWORD len
)
107 if (!str
) return 0; /* YES */
108 for (; len
; len
--, str
++) *str
= towlower(*str
);
122 return (LPWSTR
)(INT
)towlower((WORD
)(((DWORD
)(x
)) & 0xFFFF));
131 CharPrevW(LPCWSTR start
, LPCWSTR x
)
133 if (x
> start
) return (LPWSTR
)(x
-1);
134 else return (LPWSTR
)x
;
142 CharNextA(LPCSTR ptr
)
144 if (!*ptr
) return (LPSTR
)ptr
;
145 if (IsDBCSLeadByte(ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
146 return (LPSTR
)(ptr
+ 1);
154 CharNextExA(WORD codepage
, LPCSTR ptr
, DWORD flags
)
156 if (!*ptr
) return (LPSTR
)ptr
;
157 if (IsDBCSLeadByteEx(codepage
, ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
158 return (LPSTR
)(ptr
+ 1);
177 CharPrevA(LPCSTR start
, LPCSTR ptr
)
179 while (*start
&& (start
< ptr
)) {
180 LPCSTR next
= CharNextA(start
);
181 if (next
>= ptr
) break;
190 LPSTR WINAPI
CharPrevExA( WORD codepage
, LPCSTR start
, LPCSTR ptr
, DWORD flags
)
192 while (*start
&& (start
< ptr
))
194 LPCSTR next
= CharNextExA( codepage
, start
, flags
);
195 if (next
> ptr
) break;
206 CharToOemA(LPCSTR s
, LPSTR d
)
208 if (!s
|| !d
) return TRUE
;
209 return CharToOemBuffA(s
, d
, strlen(s
) + 1);
217 CharToOemBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
221 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
223 MultiByteToWideChar(CP_ACP
, 0, s
, len
, bufW
, len
);
224 WideCharToMultiByte(CP_OEMCP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
225 HeapFree(GetProcessHeap(), 0, bufW
);
235 CharToOemBuffW(LPCWSTR s
, LPSTR d
, DWORD len
)
239 WideCharToMultiByte(CP_OEMCP
, 0, s
, len
, d
, len
, NULL
, NULL
);
248 CharToOemW(LPCWSTR s
, LPSTR d
)
250 return CharToOemBuffW(s
, d
, wcslen(s
) + 1);
256 LPSTR WINAPI
CharUpperA(LPSTR x
)
258 if (!HIWORD(x
)) return (LPSTR
)toupper((char)(int)x
);
259 CharUpperBuffA(x
, strlen(x
));
268 CharUpperBuffA(LPSTR str
, DWORD len
)
272 if (!str
) return 0; /* YES */
274 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
275 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
277 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
278 CharUpperBuffW(strW
, lenW
);
279 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
280 HeapFree(GetProcessHeap(), 0, strW
);
291 CharUpperBuffW(LPWSTR str
, DWORD len
)
294 if (!str
) return 0; /* YES */
295 for (; len
; len
--, str
++) *str
= towupper(*str
);
306 if (HIWORD(x
)) return _wcsupr(x
);
307 else return (LPWSTR
)(UINT
)towlower((WORD
)(((DWORD
)(x
)) & 0xFFFF));
315 IsCharAlphaA(CHAR Ch
)
319 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
320 return IsCharAlphaW(WCh
);
328 IsCharAlphaNumericA(CHAR Ch
)
332 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
333 return IsCharAlphaNumericW(WCh
);
341 IsCharAlphaNumericW(WCHAR Ch
)
343 return (GetC1Type(Ch
) & (C1_ALPHA
|C1_DIGIT
)) != 0;
351 IsCharAlphaW(WCHAR Ch
)
353 return (GetC1Type(Ch
) & C1_ALPHA
) != 0;
361 IsCharLowerA(CHAR Ch
)
365 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
366 return IsCharLowerW(WCh
);
374 IsCharLowerW(WCHAR Ch
)
376 return (GetC1Type(Ch
) & C1_LOWER
) != 0;
384 IsCharUpperA(CHAR Ch
)
388 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
389 return IsCharUpperW(WCh
);
397 IsCharUpperW(WCHAR Ch
)
399 return (GetC1Type(Ch
) & C1_UPPER
) != 0;
407 OemToCharA(LPCSTR s
, LPSTR d
)
409 return OemToCharBuffA(s
, d
, strlen(s
) + 1);
415 BOOL WINAPI
OemToCharBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
419 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
421 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, bufW
, len
);
422 WideCharToMultiByte(CP_ACP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
423 HeapFree(GetProcessHeap(), 0, bufW
);
433 OemToCharBuffW(LPCSTR s
, LPWSTR d
, DWORD len
)
435 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, d
, len
);
442 BOOL WINAPI
OemToCharW(LPCSTR s
, LPWSTR d
)
444 return OemToCharBuffW(s
, d
, strlen(s
) + 1);