ReactOS 0.4.16-dev-2274-gc61d98f
utils.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL-2.1-or-later (https://spdx.org/licenses/GPL-2.1-or-later)
4 * PURPOSE: Utility functions
5 * COPYRIGHT: Copyright 2026 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include <win32k.h>
9
11
13
16{
17 SIZE_T ret = 0, cch;
18 const WCHAR *pch = pszz;
19 while (*pch)
20 {
21 cch = wcslen(pch) + 1;
22 ret += cch;
23 pch += cch;
24 }
25 ++ret;
26 return ret * sizeof(WCHAR);
27}
28
29VOID
31 _Inout_ PLIST_ENTRY pNewHead,
32 _Inout_ PLIST_ENTRY pOldHead)
33{
35
36 ASSERT(pNewHead != pOldHead);
37
38 InitializeListHead(pNewHead);
39 while (!IsListEmpty(pOldHead))
40 {
41 Entry = RemoveTailList(pOldHead);
42 InsertHeadList(pNewHead, Entry);
43 }
44}
45
47{
48 nTenthsOfDegrees %= 360 * 10;
49 if (nTenthsOfDegrees >= 0)
50 return nTenthsOfDegrees;
51 return nTenthsOfDegrees + 360 * 10;
52}
53
55{
56 switch (CharSet)
57 {
58 case ANSI_CHARSET: return L"ANSI";
59 case DEFAULT_CHARSET: return L"Default";
60 case SYMBOL_CHARSET: return L"Symbol";
61 case SHIFTJIS_CHARSET: return L"Shift_JIS";
62 case HANGUL_CHARSET: return L"Hangul";
63 case GB2312_CHARSET: return L"GB 2312";
64 case CHINESEBIG5_CHARSET: return L"Chinese Big5";
65 case OEM_CHARSET: return L"OEM";
66 case JOHAB_CHARSET: return L"Johab";
67 case HEBREW_CHARSET: return L"Hebrew";
68 case ARABIC_CHARSET: return L"Arabic";
69 case GREEK_CHARSET: return L"Greek";
70 case TURKISH_CHARSET: return L"Turkish";
71 case VIETNAMESE_CHARSET: return L"Vietnamese";
72 case THAI_CHARSET: return L"Thai";
73 case EASTEUROPE_CHARSET: return L"Eastern European";
74 case RUSSIAN_CHARSET: return L"Russian";
75 case MAC_CHARSET: return L"Mac";
76 case BALTIC_CHARSET: return L"Baltic";
77 default: return L"Unknown";
78 }
79}
80
81/* See https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/bb165625(v=vs.90) */
83{
84 /* FIXME: Add more and fix if wrong */
85 switch (PRIMARYLANGID(LangID))
86 {
87 case LANG_CHINESE:
88 switch (SUBLANGID(LangID))
89 {
93 default:
94 break;
95 }
96 return GB2312_CHARSET;
97
98 case LANG_CZECH: case LANG_HUNGARIAN: case LANG_POLISH:
100 return EASTEUROPE_CHARSET;
101
103 case LANG_SERBIAN: case LANG_UKRAINIAN:
104 return RUSSIAN_CHARSET;
105
106 case LANG_ARABIC: return ARABIC_CHARSET;
107 case LANG_GREEK: return GREEK_CHARSET;
108 case LANG_HEBREW: return HEBREW_CHARSET;
109 case LANG_JAPANESE: return SHIFTJIS_CHARSET;
110 case LANG_KOREAN: return JOHAB_CHARSET;
111 case LANG_TURKISH: return TURKISH_CHARSET;
112 case LANG_THAI: return THAI_CHARSET;
113 case LANG_LATVIAN: return BALTIC_CHARSET;
115
116 case LANG_ENGLISH: case LANG_BASQUE: case LANG_CATALAN:
117 case LANG_DANISH: case LANG_DUTCH: case LANG_FINNISH:
118 case LANG_FRENCH: case LANG_GERMAN: case LANG_ITALIAN:
120 case LANG_SWEDISH: default:
121 return ANSI_CHARSET;
122 }
123}
124
126{
127 BYTE b, *pb = pvData;
128 Size /= 2;
129 while (Size-- > 0)
130 {
131 b = pb[0];
132 pb[0] = pb[1];
133 pb[1] = b;
134 ++pb; ++pb;
135 }
136}
137
138/* Borrowed from shlwapi!PathFindFileNameW */
140{
141 PCWSTR lastSlash = pszPath;
142 while (*pszPath)
143 {
144 if ((*pszPath == L'\\' || *pszPath == L'/' || *pszPath == L':') &&
145 pszPath[1] && pszPath[1] != '\\' && pszPath[1] != L'/')
146 {
147 lastSlash = pszPath + 1;
148 }
149 pszPath++;
150 }
151 return (PWSTR)lastSlash;
152}
153
154/* Borrowed from shlwapi!PathIsRelativeW */
156{
157 if (!lpszPath || !*lpszPath)
158 return TRUE;
159 if (*lpszPath == L'\\' || (*lpszPath && lpszPath[1] == L':'))
160 return FALSE;
161 return TRUE;
162}
163
164VOID
166 _Out_ LPWSTR pszBuffer,
167 _In_ SIZE_T cbBuffer,
169{
170 SIZE_T cbLength = pString->Length;
171
172 if (cbBuffer < sizeof(UNICODE_NULL))
173 return;
174
175 if (cbLength > cbBuffer - sizeof(UNICODE_NULL))
176 cbLength = cbBuffer - sizeof(UNICODE_NULL);
177
178 RtlCopyMemory(pszBuffer, pString->Buffer, cbLength);
179 pszBuffer[cbLength / sizeof(WCHAR)] = UNICODE_NULL;
180}
181
186{
188 UNICODE_STRING Tmp;
189
190 Tmp.Buffer = ExAllocatePoolWithTag(PagedPool, Source->MaximumLength, TAG_USTR);
191 if (Tmp.Buffer)
192 {
193 Tmp.MaximumLength = Source->MaximumLength;
194 Tmp.Length = 0;
196
200
202 }
203
204 return Status;
205}
206
207VOID
210 IN OUT PDC dc,
211 IN INT X,
212 IN INT Y,
213 IN INT Width,
214 IN INT Height,
215 IN BRUSHOBJ *BrushObj)
216{
217 RECTL DestRect;
218 SURFACE *psurf = dc->dclevel.pSurface;
219
221 ASSERT(psurf != NULL);
222
223 if (Width < 0)
224 {
225 X += Width;
226 Width = -Width;
227 }
228
229 if (Height < 0)
230 {
231 Y += Height;
232 Height = -Height;
233 }
234
235 DestRect.left = X;
236 DestRect.right = X + Width;
237 DestRect.top = Y;
238 DestRect.bottom = Y + Height;
239
240 IntEngBitBlt(&psurf->SurfObj,
241 NULL,
242 NULL,
243 (CLIPOBJ *)&dc->co,
244 NULL,
245 &DestRect,
246 NULL,
247 NULL,
248 BrushObj,
251}
252
255 IN OUT PDC dc,
256 IN POINTL *pPoints,
257 IN UINT cPoints,
258 IN BRUSHOBJ *BrushObj)
259{
260 SURFACE *psurf = dc->dclevel.pSurface;
261 RECT Rect;
262 UINT i;
263 INT x, y;
264
266 ASSERT(psurf != NULL);
267
268 Rect.left = Rect.right = pPoints[0].x;
269 Rect.top = Rect.bottom = pPoints[0].y;
270 for (i = 1; i < cPoints; ++i)
271 {
272 x = pPoints[i].x;
273 if (x < Rect.left)
274 Rect.left = x;
275 else if (Rect.right < x)
276 Rect.right = x;
277
278 y = pPoints[i].y;
279 if (y < Rect.top)
280 Rect.top = y;
281 else if (Rect.bottom < y)
282 Rect.bottom = y;
283 }
284
285 IntFillPolygon(dc, dc->dclevel.pSurface, BrushObj, pPoints, cPoints, Rect, &g_PointZero);
286}
LONG NTSTATUS
Definition: precomp.h:26
__inline USHORT Length(VOID)
Definition: fxstring.hpp:85
__inline PWCHAR Buffer(VOID)
Definition: fxstring.hpp:144
HDC dc
Definition: cylfrac.c:34
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define ASSERT_DC_PREPARED(pdc)
Definition: dc.h:300
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define TAG_USTR
Definition: libsupp.c:997
#define APIENTRY
Definition: api.h:79
#define Y(I)
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
static void CharSet(RTF_Info *info)
Definition: reader.c:2400
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define InsertHeadList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveTailList(ListHead)
Definition: env_spec_w32.h:975
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxString * pString
Status
Definition: gdiplustypes.h:25
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define X(b, s)
#define ROP4_FROM_INDEX(index)
Definition: inteng.h:42
@ R3_OPINDEX_PATCOPY
Definition: inteng.h:35
#define b
Definition: ke_i.h:79
USHORT LANGID
Definition: mui.h:9
#define pch(ap)
Definition: match.c:418
#define ASSERT(a)
Definition: mode.c:44
unsigned int UINT
Definition: ndis.h:50
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3051
_In_ LPWSTR _In_ DWORD _In_ LPCVOID pvData
Definition: netsh.h:116
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FASTCALL
Definition: nt_native.h:50
#define UNICODE_NULL
_NullNull_terminated_ CONST WCHAR * PCZZWSTR
Definition: ntbasedef.h:433
BOOL FASTCALL IntFillPolygon(PDC dc, SURFACE *psurf, BRUSHOBJ *BrushObj, CONST PPOINT Points, int Count, RECTL DestRect, POINTL *BrushOrigin)
Definition: polyfill.c:590
long LONG
Definition: pedump.c:60
#define LANG_THAI
Definition: nls.h:132
#define LANG_NORWEGIAN
Definition: nls.h:102
#define SUBLANGID(l)
Definition: nls.h:17
#define LANG_TURKISH
Definition: nls.h:136
#define LANG_DANISH
Definition: nls.h:48
#define LANG_SPANISH
Definition: nls.h:123
#define LANG_POLISH
Definition: nls.h:107
#define LANG_GERMAN
Definition: nls.h:62
#define LANG_HEBREW
Definition: nls.h:67
#define LANG_UKRAINIAN
Definition: nls.h:139
#define LANG_BULGARIAN
Definition: nls.h:40
#define LANG_FINNISH
Definition: nls.h:57
#define LANG_GREEK
Definition: nls.h:63
#define LANG_BASQUE
Definition: nls.h:34
#define LANG_MACEDONIAN
Definition: nls.h:91
#define LANG_ENGLISH
Definition: nls.h:52
#define LANG_ROMANIAN
Definition: nls.h:111
#define SUBLANG_CHINESE_TRADITIONAL
Definition: nls.h:208
#define LANG_DUTCH
Definition: nls.h:51
#define SUBLANG_CHINESE_SIMPLIFIED
Definition: nls.h:209
#define LANG_RUSSIAN
Definition: nls.h:113
#define LANG_VIETNAMESE
Definition: nls.h:143
#define LANG_CZECH
Definition: nls.h:47
#define LANG_HUNGARIAN
Definition: nls.h:69
#define LANG_SWEDISH
Definition: nls.h:125
#define LANG_ARABIC
Definition: nls.h:29
#define LANG_CHINESE
Definition: nls.h:42
#define LANG_SERBIAN
Definition: nls.h:116
#define LANG_JAPANESE
Definition: nls.h:76
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define LANG_LATVIAN
Definition: nls.h:87
#define LANG_SLOVAK
Definition: nls.h:120
#define LANG_KOREAN
Definition: nls.h:84
#define LANG_SLOVENIAN
Definition: nls.h:121
#define LANG_FRENCH
Definition: nls.h:58
#define LANG_ITALIAN
Definition: nls.h:75
#define LANG_PORTUGUESE
Definition: nls.h:108
#define LANG_CATALAN
Definition: nls.h:41
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: polytest.cpp:41
base of all file and directory entries
Definition: entries.h:83
long bottom
Definition: polytest.cpp:53
long right
Definition: polytest.cpp:53
long top
Definition: polytest.cpp:53
long left
Definition: polytest.cpp:53
Definition: typedefs.h:120
SURFOBJ SurfObj
Definition: surface.h:8
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1083
BOOL APIENTRY IntEngBitBlt(SURFOBJ *psoTrg, SURFOBJ *psoSrc, SURFOBJ *psoMask, CLIPOBJ *pco, XLATEOBJ *pxlo, RECTL *prclTrg, POINTL *pptlSrc, POINTL *pptlMask, BRUSHOBJ *pbo, POINTL *pptlBrush, ROP4 Rop4)
Definition: bitblt.c:656
VOID APIENTRY IntEngFillPolygon(IN OUT PDC dc, IN POINTL *pPoints, IN UINT cPoints, IN BRUSHOBJ *BrushObj)
Definition: utils.c:254
BOOL PathIsRelativeW(_In_ LPCWSTR lpszPath)
Definition: utils.c:155
VOID IntSwapEndian(_Inout_ LPVOID pvData, _In_ DWORD Size)
Definition: utils.c:125
UNICODE_STRING g_FontRegPath
Definition: freetype.c:325
VOID IntRebaseList(_Inout_ PLIST_ENTRY pNewHead, _Inout_ PLIST_ENTRY pOldHead)
Definition: utils.c:30
NTSTATUS IntDuplicateUnicodeString(_In_ PCUNICODE_STRING Source, _Out_ PUNICODE_STRING Destination)
Definition: utils.c:183
VOID IntUnicodeStringToBuffer(_Out_ LPWSTR pszBuffer, _In_ SIZE_T cbBuffer, _In_ const UNICODE_STRING *pString)
Definition: utils.c:165
SIZE_T SZZ_GetSize(_In_ PCZZWSTR pszz)
Definition: utils.c:15
PWSTR PathFindFileNameW(_In_ PCWSTR pszPath)
Definition: utils.c:139
LPCWSTR FASTCALL IntNameFromCharSet(_In_ BYTE CharSet)
Definition: utils.c:54
BYTE IntCharSetFromLangID(_In_ LANGID LangID)
Definition: utils.c:82
LONG IntNormalizeAngle(_In_ LONG nTenthsOfDegrees)
Definition: utils.c:46
VOID FASTCALL IntEngFillBox(IN OUT PDC dc, IN INT X, IN INT Y, IN INT Width, IN INT Height, IN BRUSHOBJ *BrushObj)
Definition: utils.c:209
POINTL g_PointZero
Definition: utils.c:12
#define HANGUL_CHARSET
Definition: wingdi.h:388
#define RUSSIAN_CHARSET
Definition: wingdi.h:396
#define ARABIC_CHARSET
Definition: wingdi.h:394
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define THAI_CHARSET
Definition: wingdi.h:397
#define GREEK_CHARSET
Definition: wingdi.h:391
#define JOHAB_CHARSET
Definition: wingdi.h:401
#define CHINESEBIG5_CHARSET
Definition: wingdi.h:390
#define ANSI_CHARSET
Definition: wingdi.h:383
#define OEM_CHARSET
Definition: wingdi.h:400
#define VIETNAMESE_CHARSET
Definition: wingdi.h:402
#define MAC_CHARSET
Definition: wingdi.h:403
#define HEBREW_CHARSET
Definition: wingdi.h:393
#define SHIFTJIS_CHARSET
Definition: wingdi.h:386
#define SYMBOL_CHARSET
Definition: wingdi.h:385
#define EASTEUROPE_CHARSET
Definition: wingdi.h:399
#define GB2312_CHARSET
Definition: wingdi.h:389
#define BALTIC_CHARSET
Definition: wingdi.h:395
#define TURKISH_CHARSET
Definition: wingdi.h:392
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193