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
))
59 char ch
= LOWORD(str
);
60 CharLowerBuffA( &ch
, 1 );
61 return (LPSTR
)(UINT_PTR
)(BYTE
)ch
;
66 CharLowerBuffA( str
, strlen(str
) );
70 SetLastError( ERROR_INVALID_PARAMETER
);
83 CharLowerBuffA(LPSTR str
, DWORD len
)
87 if (!str
) return 0; /* YES */
89 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
90 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
92 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
93 CharLowerBuffW(strW
, lenW
);
94 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
95 HeapFree(GetProcessHeap(), 0, strW
);
106 CharLowerBuffW(LPWSTR str
, DWORD len
)
109 if (!str
) return 0; /* YES */
110 for (; len
; len
--, str
++) *str
= towlower(*str
);
121 if (HIWORD(x
)) return strlwrW(x
);
122 else return (LPWSTR
)((UINT_PTR
)tolowerW(LOWORD(x
)));
130 CharPrevW(LPCWSTR start
, LPCWSTR x
)
132 if (x
> start
) return (LPWSTR
)(x
-1);
133 else return (LPWSTR
)x
;
141 CharNextA(LPCSTR ptr
)
143 if (!*ptr
) return (LPSTR
)ptr
;
144 if (IsDBCSLeadByte(ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
145 return (LPSTR
)(ptr
+ 1);
153 CharNextExA(WORD codepage
, LPCSTR ptr
, DWORD flags
)
155 if (!*ptr
) return (LPSTR
)ptr
;
156 if (IsDBCSLeadByteEx(codepage
, ptr
[0]) && ptr
[1]) return (LPSTR
)(ptr
+ 2);
157 return (LPSTR
)(ptr
+ 1);
176 CharPrevA(LPCSTR start
, LPCSTR ptr
)
178 while (*start
&& (start
< ptr
)) {
179 LPCSTR next
= CharNextA(start
);
180 if (next
>= ptr
) break;
189 LPSTR WINAPI
CharPrevExA( WORD codepage
, LPCSTR start
, LPCSTR ptr
, DWORD flags
)
191 while (*start
&& (start
< ptr
))
193 LPCSTR next
= CharNextExA( codepage
, start
, flags
);
194 if (next
> ptr
) break;
205 CharToOemA(LPCSTR s
, LPSTR d
)
207 if (!s
|| !d
) return TRUE
;
208 return CharToOemBuffA(s
, d
, strlen(s
) + 1);
216 CharToOemBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
220 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
222 MultiByteToWideChar(CP_ACP
, 0, s
, len
, bufW
, len
);
223 WideCharToMultiByte(CP_OEMCP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
224 HeapFree(GetProcessHeap(), 0, bufW
);
234 CharToOemBuffW(LPCWSTR s
, LPSTR d
, DWORD len
)
238 WideCharToMultiByte(CP_OEMCP
, 0, s
, len
, d
, len
, NULL
, NULL
);
247 CharToOemW(LPCWSTR s
, LPSTR d
)
249 return CharToOemBuffW(s
, d
, wcslen(s
) + 1);
255 LPSTR WINAPI
CharUpperA(LPSTR str
)
259 char ch
= LOWORD(str
);
260 CharUpperBuffA( &ch
, 1 );
261 return (LPSTR
)(UINT_PTR
)(BYTE
)ch
;
266 CharUpperBuffA( str
, strlen(str
) );
270 SetLastError( ERROR_INVALID_PARAMETER
);
283 CharUpperBuffA(LPSTR str
, DWORD len
)
287 if (!str
) return 0; /* YES */
289 lenW
= MultiByteToWideChar(CP_ACP
, 0, str
, len
, NULL
, 0);
290 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
* sizeof(WCHAR
));
292 MultiByteToWideChar(CP_ACP
, 0, str
, len
, strW
, lenW
);
293 CharUpperBuffW(strW
, lenW
);
294 len
= WideCharToMultiByte(CP_ACP
, 0, strW
, lenW
, str
, len
, NULL
, NULL
);
295 HeapFree(GetProcessHeap(), 0, strW
);
306 CharUpperBuffW(LPWSTR str
, DWORD len
)
309 if (!str
) return 0; /* YES */
310 for (; len
; len
--, str
++) *str
= towupper(*str
);
321 if (HIWORD(x
)) return struprW(x
);
322 else return (LPWSTR
)((UINT_PTR
)toupperW(LOWORD(x
)));
330 IsCharAlphaA(CHAR Ch
)
334 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
335 return IsCharAlphaW(WCh
);
343 IsCharAlphaNumericA(CHAR Ch
)
347 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
348 return IsCharAlphaNumericW(WCh
);
356 IsCharAlphaNumericW(WCHAR Ch
)
358 return (GetC1Type(Ch
) & (C1_ALPHA
|C1_DIGIT
)) != 0;
366 IsCharAlphaW(WCHAR Ch
)
368 return (GetC1Type(Ch
) & C1_ALPHA
) != 0;
376 IsCharLowerA(CHAR Ch
)
380 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
381 return IsCharLowerW(WCh
);
389 IsCharLowerW(WCHAR Ch
)
391 return (GetC1Type(Ch
) & C1_LOWER
) != 0;
399 IsCharUpperA(CHAR Ch
)
403 MultiByteToWideChar(CP_ACP
, 0, &Ch
, 1, &WCh
, 1);
404 return IsCharUpperW(WCh
);
412 IsCharUpperW(WCHAR Ch
)
414 return (GetC1Type(Ch
) & C1_UPPER
) != 0;
422 OemToCharA(LPCSTR s
, LPSTR d
)
424 return OemToCharBuffA(s
, d
, strlen(s
) + 1);
430 BOOL WINAPI
OemToCharBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
434 bufW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
436 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, bufW
, len
);
437 WideCharToMultiByte(CP_ACP
, 0, bufW
, len
, d
, len
, NULL
, NULL
);
438 HeapFree(GetProcessHeap(), 0, bufW
);
448 OemToCharBuffW(LPCSTR s
, LPWSTR d
, DWORD len
)
450 MultiByteToWideChar(CP_OEMCP
, 0, s
, len
, d
, len
);
457 BOOL WINAPI
OemToCharW(LPCSTR s
, LPWSTR d
)
459 return OemToCharBuffW(s
, d
, strlen(s
) + 1);