diff --git a/reactos/subsystems/win32/csrss/win32csr/alias.c b/reactos/subsystems/win32/csrss/win32csr/alias.c index 1432be1be53..569948a4f41 100644 --- a/reactos/subsystems/win32/csrss/win32csr/alias.c +++ b/reactos/subsystems/win32/csrss/win32csr/alias.c @@ -5,7 +5,7 @@ * PURPOSE: CSRSS alias support functions * COPYRIGHT: Christoph Wittich * Johannes Anderwald - * + * */ @@ -17,10 +17,10 @@ typedef struct tagALIAS_ENTRY { - LPCWSTR lpSource; - LPCWSTR lpTarget; - struct tagALIAS_ENTRY * Next; -}ALIAS_ENTRY, *PALIAS_ENTRY; + LPCWSTR lpSource; + LPCWSTR lpTarget; + struct tagALIAS_ENTRY * Next; +} ALIAS_ENTRY, *PALIAS_ENTRY; typedef struct tagALIAS_HEADER @@ -29,7 +29,7 @@ typedef struct tagALIAS_HEADER PALIAS_ENTRY Data; struct tagALIAS_HEADER * Next; -}ALIAS_HEADER, *PALIAS_HEADER; +} ALIAS_HEADER, *PALIAS_HEADER; /* Ensure that a buffer is contained within the process's shared memory section. */ static BOOL @@ -37,10 +37,10 @@ ValidateBuffer(PCSRSS_PROCESS_DATA ProcessData, PVOID Buffer, ULONG Size) { ULONG Offset = (BYTE *)Buffer - (BYTE *)ProcessData->CsrSectionViewBase; if (Offset >= ProcessData->CsrSectionViewSize - || Size > (ProcessData->CsrSectionViewSize - Offset)) + || Size > (ProcessData->CsrSectionViewSize - Offset)) { DPRINT1("Invalid buffer %p %d; not within %p %d\n", - Buffer, Size, ProcessData->CsrSectionViewBase, ProcessData->CsrSectionViewSize); + Buffer, Size, ProcessData->CsrSectionViewBase, ProcessData->CsrSectionViewSize); return FALSE; } return TRUE; @@ -67,38 +67,38 @@ IntFindAliasHeader(PALIAS_HEADER RootHeader, LPCWSTR lpExeName) PALIAS_HEADER IntCreateAliasHeader(LPCWSTR lpExeName) { - PALIAS_HEADER Entry; - UINT dwLength = wcslen(lpExeName) + 1; + PALIAS_HEADER Entry; + UINT dwLength = wcslen(lpExeName) + 1; - Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength); - if (!Entry) - return Entry; - - Entry->lpExeName = (LPCWSTR)(Entry + 1); - wcscpy((WCHAR*)Entry->lpExeName, lpExeName); - Entry->Data = NULL; - Entry->Next = NULL; - return Entry; + Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength); + if (!Entry) + return Entry; + + Entry->lpExeName = (LPCWSTR)(Entry + 1); + wcscpy((WCHAR*)Entry->lpExeName, lpExeName); + Entry->Data = NULL; + Entry->Next = NULL; + return Entry; } VOID IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader) { - PALIAS_HEADER CurrentHeader; - PALIAS_HEADER *LastLink = RootHeader; + PALIAS_HEADER CurrentHeader; + PALIAS_HEADER *LastLink = RootHeader; - while ((CurrentHeader = *LastLink) != NULL) - { - INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName); - if (Diff < 0) - { - break; - } - LastLink = &CurrentHeader->Next; - } + while ((CurrentHeader = *LastLink) != NULL) + { + INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName); + if (Diff < 0) + { + break; + } + LastLink = &CurrentHeader->Next; + } - *LastLink = NewHeader; - NewHeader->Next = CurrentHeader; + *LastLink = NewHeader; + NewHeader->Next = CurrentHeader; } PALIAS_ENTRY @@ -130,60 +130,60 @@ IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName) VOID IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry) { - PALIAS_ENTRY CurrentEntry; - PALIAS_ENTRY *LastLink = &Header->Data; + PALIAS_ENTRY CurrentEntry; + PALIAS_ENTRY *LastLink = &Header->Data; - while ((CurrentEntry = *LastLink) != NULL) - { - INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource); - if (Diff < 0) + while ((CurrentEntry = *LastLink) != NULL) { - break; + INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource); + if (Diff < 0) + { + break; + } + LastLink = &CurrentEntry->Next; } - LastLink = &CurrentEntry->Next; - } - *LastLink = NewEntry; - NewEntry->Next = CurrentEntry; + *LastLink = NewEntry; + NewEntry->Next = CurrentEntry; } PALIAS_ENTRY IntCreateAliasEntry(LPCWSTR lpSource, LPCWSTR lpTarget) { - UINT dwSource; - UINT dwTarget; - PALIAS_ENTRY Entry; + UINT dwSource; + UINT dwTarget; + PALIAS_ENTRY Entry; - dwSource = wcslen(lpSource) + 1; - dwTarget = wcslen(lpTarget) + 1; + dwSource = wcslen(lpSource) + 1; + dwTarget = wcslen(lpTarget) + 1; - Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource + dwTarget)); - if (!Entry) - return Entry; + Entry = RtlAllocateHeap(Win32CsrApiHeap, 0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource + dwTarget)); + if (!Entry) + return Entry; - Entry->lpSource = (LPCWSTR)(Entry + 1); - wcscpy((LPWSTR)Entry->lpSource, lpSource); - Entry->lpTarget = Entry->lpSource + dwSource; - wcscpy((LPWSTR)Entry->lpTarget, lpTarget); - Entry->Next = NULL; + Entry->lpSource = (LPCWSTR)(Entry + 1); + wcscpy((LPWSTR)Entry->lpSource, lpSource); + Entry->lpTarget = Entry->lpSource + dwSource; + wcscpy((LPWSTR)Entry->lpTarget, lpTarget); + Entry->Next = NULL; - return Entry; + return Entry; } UINT IntGetConsoleAliasesExesLength(PALIAS_HEADER RootHeader) { - UINT length = 0; + UINT length = 0; - while(RootHeader) - { - length += (wcslen(RootHeader->lpExeName) + 1) * sizeof(WCHAR); - RootHeader = RootHeader->Next; - } - if (length) - length += sizeof(WCHAR); // last entry entry is terminated with 2 zero bytes + while(RootHeader) + { + length += (wcslen(RootHeader->lpExeName) + 1) * sizeof(WCHAR); + RootHeader = RootHeader->Next; + } + if (length) + length += sizeof(WCHAR); // last entry entry is terminated with 2 zero bytes - return length; + return length; } UINT @@ -215,22 +215,22 @@ IntGetConsoleAliasesExes(PALIAS_HEADER RootHeader, LPWSTR TargetBuffer, UINT Tar UINT IntGetAllConsoleAliasesLength(PALIAS_HEADER Header) { - UINT Length = 0; - PALIAS_ENTRY CurEntry = Header->Data; + UINT Length = 0; + PALIAS_ENTRY CurEntry = Header->Data; - while(CurEntry) - { - Length += wcslen(CurEntry->lpSource); - Length += wcslen(CurEntry->lpTarget); - Length += 2; // zero byte and '=' - CurEntry = CurEntry->Next; - } + while(CurEntry) + { + Length += wcslen(CurEntry->lpSource); + Length += wcslen(CurEntry->lpTarget); + Length += 2; // zero byte and '=' + CurEntry = CurEntry->Next; + } - if (Length) - { - return (Length+1) * sizeof(WCHAR); - } - return 0; + if (Length) + { + return (Length+1) * sizeof(WCHAR); + } + return 0; } UINT IntGetAllConsoleAliases(PALIAS_HEADER Header, LPWSTR TargetBuffer, UINT TargetBufferLength) @@ -316,7 +316,7 @@ CSR_API(CsrAddConsoleAlias) { return STATUS_INVALID_PARAMETER; } - + Request->Status = ConioConsoleFromProcessData(ProcessData, &Console); if (!NT_SUCCESS(Request->Status)) { @@ -379,11 +379,11 @@ CSR_API(CsrGetConsoleAlias) lpTarget = Request->Data.GetConsoleAlias.TargetBuffer; - DPRINT("CsrGetConsoleAlias entered lpExeName %p lpSource %p TargetBuffer %p TargetBufferLength %u\n", - lpExeName, lpSource, lpTarget, Request->Data.GetConsoleAlias.TargetBufferLength); - - if (Request->Data.GetConsoleAlias.ExeLength == 0 || lpTarget == NULL || - Request->Data.GetConsoleAlias.TargetBufferLength == 0 || Request->Data.GetConsoleAlias.SourceLength == 0) + DPRINT("CsrGetConsoleAlias entered lpExeName %p lpSource %p TargetBuffer %p TargetBufferLength %u\n", + lpExeName, lpSource, lpTarget, Request->Data.GetConsoleAlias.TargetBufferLength); + + if (Request->Data.GetConsoleAlias.ExeLength == 0 || lpTarget == NULL || + Request->Data.GetConsoleAlias.TargetBufferLength == 0 || Request->Data.GetConsoleAlias.SourceLength == 0) { return STATUS_INVALID_PARAMETER; } @@ -465,7 +465,7 @@ CSR_API(CsrGetAllConsoleAliases) return STATUS_ACCESS_VIOLATION; } - BytesWritten = IntGetAllConsoleAliases(Header, + BytesWritten = IntGetAllConsoleAliases(Header, Request->Data.GetAllConsoleAlias.AliasBuffer, Request->Data.GetAllConsoleAlias.AliasBufferLength); @@ -509,7 +509,7 @@ CSR_API(CsrGetConsoleAliasesExes) PCSRSS_CONSOLE Console; UINT BytesWritten; UINT ExesLength; - + DPRINT("CsrGetConsoleAliasesExes entered\n"); Request->Status = ConioConsoleFromProcessData(ProcessData, &Console); @@ -519,7 +519,7 @@ CSR_API(CsrGetConsoleAliasesExes) } ExesLength = IntGetConsoleAliasesExesLength(Console->Aliases); - + if (ExesLength > Request->Data.GetConsoleAliasesExes.Length) { ConioUnlockConsole(Console); @@ -531,7 +531,7 @@ CSR_API(CsrGetConsoleAliasesExes) ConioUnlockConsole(Console); return STATUS_INVALID_PARAMETER; } - + if (!ValidateBuffer(ProcessData, Request->Data.GetConsoleAliasesExes.ExeNames, Request->Data.GetConsoleAliasesExes.Length)) @@ -540,7 +540,7 @@ CSR_API(CsrGetConsoleAliasesExes) return STATUS_ACCESS_VIOLATION; } - BytesWritten = IntGetConsoleAliasesExes(Console->Aliases, + BytesWritten = IntGetConsoleAliasesExes(Console->Aliases, Request->Data.GetConsoleAliasesExes.ExeNames, Request->Data.GetConsoleAliasesExes.Length); diff --git a/reactos/subsystems/win32/csrss/win32csr/appswitch.c b/reactos/subsystems/win32/csrss/win32csr/appswitch.c index 3d372a199f1..f816a8303ad 100644 --- a/reactos/subsystems/win32/csrss/win32csr/appswitch.c +++ b/reactos/subsystems/win32/csrss/win32csr/appswitch.c @@ -19,7 +19,7 @@ typedef struct APPSWITCH_ITEM BOOL bFocus; struct APPSWITCH_ITEM * Next; WCHAR szText[1]; -}APPSWITCH_ITEM, *PAPPSWITCH_ITEM; +} APPSWITCH_ITEM, *PAPPSWITCH_ITEM; static PAPPSWITCH_ITEM pRoot = NULL; static DWORD NumOfWindows = 0; @@ -30,7 +30,7 @@ UINT WINAPI PrivateExtractIconExW(LPCWSTR,int,HICON*,HICON*,UINT); BOOL -CALLBACK +CALLBACK EnumWindowEnumProc( HWND hwnd, LPARAM lParam @@ -51,21 +51,21 @@ EnumWindowEnumProc( hIcon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_BIG, 0); if (!hIcon) { - GetWindowThreadProcessId(hwnd, &dwPid); - hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, dwPid); - if (hProcess) - { - if (GetModuleFileNameExW(hProcess, NULL, szFileName, MAX_PATH)) - { - szFileName[MAX_PATH-1] = L'\0'; - PrivateExtractIconExW(szFileName, 0, &hIcon, NULL, 1); - } - } + GetWindowThreadProcessId(hwnd, &dwPid); + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, dwPid); + if (hProcess) + { + if (GetModuleFileNameExW(hProcess, NULL, szFileName, MAX_PATH)) + { + szFileName[MAX_PATH-1] = L'\0'; + PrivateExtractIconExW(szFileName, 0, &hIcon, NULL, 1); + } + } } else { - /* icons from WM_GETICON need to be copied */ - hIcon = CopyIcon(hIcon); + /* icons from WM_GETICON need to be copied */ + hIcon = CopyIcon(hIcon); } /* get the text length */ Length = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); @@ -88,9 +88,9 @@ EnumWindowEnumProc( if (!pRoot) { - /* first item */ - pRoot = pItem; - return TRUE; + /* first item */ + pRoot = pItem; + return TRUE; } /* enumerate the last item */ @@ -107,16 +107,16 @@ EnumWindowEnumProc( VOID EnumerateAppWindows(HDESK hDesk, HWND hwndDlg) { - /* initialize defaults */ - pRoot = NULL; - NumOfWindows = 0; - hAppWindowDlg = hwndDlg; - /* enumerate all windows */ - EnumDesktopWindows(hDesk, EnumWindowEnumProc, (LPARAM)NULL); - if (NumOfWindows > 7) - { - /* FIXME resize window */ - } + /* initialize defaults */ + pRoot = NULL; + NumOfWindows = 0; + hAppWindowDlg = hwndDlg; + /* enumerate all windows */ + EnumDesktopWindows(hDesk, EnumWindowEnumProc, (LPARAM)NULL); + if (NumOfWindows > 7) + { + /* FIXME resize window */ + } } VOID @@ -126,7 +126,7 @@ MarkNextEntryAsActive() pItem = pRoot; if (!pRoot) - return; + return; while(pItem) { @@ -153,82 +153,82 @@ KeyboardHookProc( LPARAM lParam ) { - PKBDLLHOOKSTRUCT hk = (PKBDLLHOOKSTRUCT) lParam; + PKBDLLHOOKSTRUCT hk = (PKBDLLHOOKSTRUCT) lParam; - if (wParam == WM_SYSKEYUP) - { - /* is tab key pressed */ - if (hk->vkCode == VK_TAB) - { - if (hAppWindowDlg == NULL) - { - /* FIXME - * launch window - */ - DPRINT1("launch alt-tab window\n"); - } - else - { - MarkNextEntryAsActive(); - } - } - } - return CallNextHookEx(hhk, nCode, wParam, lParam); + if (wParam == WM_SYSKEYUP) + { + /* is tab key pressed */ + if (hk->vkCode == VK_TAB) + { + if (hAppWindowDlg == NULL) + { + /* FIXME + * launch window + */ + DPRINT1("launch alt-tab window\n"); + } + else + { + MarkNextEntryAsActive(); + } + } + } + return CallNextHookEx(hhk, nCode, wParam, lParam); } VOID PaintAppWindows(HWND hwndDlg, HDC hDc) { - DWORD dwIndex, X, Y; - PAPPSWITCH_ITEM pCurItem; - RECT Rect; - DWORD XSize, YSize, XMax; - HBRUSH hBrush; + DWORD dwIndex, X, Y; + PAPPSWITCH_ITEM pCurItem; + RECT Rect; + DWORD XSize, YSize, XMax; + HBRUSH hBrush; - X = 10; - Y = 10; - XSize = GetSystemMetrics(SM_CXICON); - YSize = GetSystemMetrics(SM_CYICON); - XMax = (XSize+(XSize/2)) * 7 + X; - pCurItem = pRoot; + X = 10; + Y = 10; + XSize = GetSystemMetrics(SM_CXICON); + YSize = GetSystemMetrics(SM_CYICON); + XMax = (XSize+(XSize/2)) * 7 + X; + pCurItem = pRoot; - for (dwIndex = 0; dwIndex < NumOfWindows; dwIndex++) - { - if (X >= XMax) - { - X = 10; - Y += YSize + (YSize/2); - } - if (pCurItem->bFocus) - { + for (dwIndex = 0; dwIndex < NumOfWindows; dwIndex++) + { + if (X >= XMax) + { + X = 10; + Y += YSize + (YSize/2); + } + if (pCurItem->bFocus) + { hBrush = CreateSolidBrush(RGB(30, 30, 255)); SetRect(&Rect, X-5, Y-5, X + XSize + 5, Y + YSize + 5); FillRect(hDc, &Rect, hBrush); DeleteObject((HGDIOBJ)hBrush); SendDlgItemMessageW(hwndDlg, IDC_STATIC_CUR_APP, WM_SETTEXT, 0, (LPARAM)pCurItem->szText); - } + } - DrawIcon(hDc, X, Y, pCurItem->hIcon); - pCurItem = pCurItem->Next; - X += XSize +(XSize/2); - } + DrawIcon(hDc, X, Y, pCurItem->hIcon); + pCurItem = pCurItem->Next; + X += XSize +(XSize/2); + } } VOID DestroyAppWindows() { - PAPPSWITCH_ITEM pCurItem, pNextItem; + PAPPSWITCH_ITEM pCurItem, pNextItem; - pCurItem = pRoot; - while(pCurItem) - { - pNextItem = pCurItem->Next; - DestroyIcon(pCurItem->hIcon); - HeapFree(Win32CsrApiHeap, 0, pCurItem); - pCurItem = pNextItem; - } - pRoot = NULL; - hAppWindowDlg = NULL; - NumOfWindows = 0; + pCurItem = pRoot; + while(pCurItem) + { + pNextItem = pCurItem->Next; + DestroyIcon(pCurItem->hIcon); + HeapFree(Win32CsrApiHeap, 0, pCurItem); + pCurItem = pNextItem; + } + pRoot = NULL; + hAppWindowDlg = NULL; + NumOfWindows = 0; } INT_PTR diff --git a/reactos/subsystems/win32/csrss/win32csr/conio.c b/reactos/subsystems/win32/csrss/win32csr/conio.c index 51e320fdcef..f3a15157db0 100644 --- a/reactos/subsystems/win32/csrss/win32csr/conio.c +++ b/reactos/subsystems/win32/csrss/win32csr/conio.c @@ -15,25 +15,25 @@ /* GLOBALS *******************************************************************/ #define ConioInitRect(Rect, top, left, bottom, right) \ - ((Rect)->Top) = top; \ - ((Rect)->Left) = left; \ - ((Rect)->Bottom) = bottom; \ - ((Rect)->Right) = right + ((Rect)->Top) = top; \ + ((Rect)->Left) = left; \ + ((Rect)->Bottom) = bottom; \ + ((Rect)->Right) = right #define ConioIsRectEmpty(Rect) \ - (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom)) + (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom)) #define ConsoleInputUnicodeCharToAnsiChar(Console, dChar, sWChar) \ - WideCharToMultiByte((Console)->CodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL) + WideCharToMultiByte((Console)->CodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL) #define ConsoleInputAnsiCharToUnicodeChar(Console, dWChar, sChar) \ - MultiByteToWideChar((Console)->CodePage, 0, (sChar), 1, (dWChar), 1) + MultiByteToWideChar((Console)->CodePage, 0, (sChar), 1, (dWChar), 1) #define ConsoleUnicodeCharToAnsiChar(Console, dChar, sWChar) \ - WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL) + WideCharToMultiByte((Console)->OutputCodePage, 0, (sWChar), 1, (dChar), 1, NULL, NULL) #define ConsoleAnsiCharToUnicodeChar(Console, dWChar, sChar) \ - MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1) + MultiByteToWideChar((Console)->OutputCodePage, 0, (sChar), 1, (dWChar), 1) /* FUNCTIONS *****************************************************************/ @@ -41,72 +41,72 @@ NTSTATUS FASTCALL ConioConsoleFromProcessData(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CONSOLE *Console) { - PCSRSS_CONSOLE ProcessConsole; + PCSRSS_CONSOLE ProcessConsole; - RtlEnterCriticalSection(&ProcessData->HandleTableLock); - ProcessConsole = ProcessData->Console; + RtlEnterCriticalSection(&ProcessData->HandleTableLock); + ProcessConsole = ProcessData->Console; - if (!ProcessConsole) + if (!ProcessConsole) { - *Console = NULL; - RtlLeaveCriticalSection(&ProcessData->HandleTableLock); - return STATUS_INVALID_HANDLE; + *Console = NULL; + RtlLeaveCriticalSection(&ProcessData->HandleTableLock); + return STATUS_INVALID_HANDLE; } - InterlockedIncrement(&ProcessConsole->ReferenceCount); - RtlLeaveCriticalSection(&ProcessData->HandleTableLock); - EnterCriticalSection(&(ProcessConsole->Lock)); - *Console = ProcessConsole; + InterlockedIncrement(&ProcessConsole->ReferenceCount); + RtlLeaveCriticalSection(&ProcessData->HandleTableLock); + EnterCriticalSection(&(ProcessConsole->Lock)); + *Console = ProcessConsole; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } VOID FASTCALL ConioConsoleCtrlEventTimeout(DWORD Event, PCSRSS_PROCESS_DATA ProcessData, DWORD Timeout) { - HANDLE Thread; + HANDLE Thread; - DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n", ProcessData->ProcessId); + DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n", ProcessData->ProcessId); - if (ProcessData->CtrlDispatcher) + if (ProcessData->CtrlDispatcher) { - Thread = CreateRemoteThread(ProcessData->Process, NULL, 0, - (LPTHREAD_START_ROUTINE) ProcessData->CtrlDispatcher, - UlongToPtr(Event), 0, NULL); - if (NULL == Thread) + Thread = CreateRemoteThread(ProcessData->Process, NULL, 0, + (LPTHREAD_START_ROUTINE) ProcessData->CtrlDispatcher, + UlongToPtr(Event), 0, NULL); + if (NULL == Thread) { - DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError()); - return; + DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError()); + return; } - WaitForSingleObject(Thread, Timeout); - CloseHandle(Thread); + WaitForSingleObject(Thread, Timeout); + CloseHandle(Thread); } } VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData) { - ConioConsoleCtrlEventTimeout(Event, ProcessData, 0); + ConioConsoleCtrlEventTimeout(Event, ProcessData, 0); } PBYTE FASTCALL ConioCoordToPointer(PCSRSS_SCREEN_BUFFER Buff, ULONG X, ULONG Y) { - return &Buff->Buffer[2 * (((Y + Buff->VirtualY) % Buff->MaxY) * Buff->MaxX + X)]; + return &Buff->Buffer[2 * (((Y + Buff->VirtualY) % Buff->MaxY) * Buff->MaxX + X)]; } static VOID FASTCALL ClearLineBuffer(PCSRSS_SCREEN_BUFFER Buff) { - PBYTE Ptr = ConioCoordToPointer(Buff, 0, Buff->CurrentY); - UINT Pos; + PBYTE Ptr = ConioCoordToPointer(Buff, 0, Buff->CurrentY); + UINT Pos; - for (Pos = 0; Pos < Buff->MaxX; Pos++) + for (Pos = 0; Pos < Buff->MaxX; Pos++) { - /* Fill the cell */ - *Ptr++ = ' '; - *Ptr++ = Buff->DefaultAttrib; + /* Fill the cell */ + *Ptr++ = ' '; + *Ptr++ = Buff->DefaultAttrib; } } @@ -114,130 +114,130 @@ static NTSTATUS FASTCALL CsrInitConsoleScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer) { - DPRINT("CsrInitConsoleScreenBuffer Size X %d Size Y %d\n", Buffer->MaxX, Buffer->MaxY); + DPRINT("CsrInitConsoleScreenBuffer Size X %d Size Y %d\n", Buffer->MaxX, Buffer->MaxY); - Buffer->Header.Type = CONIO_SCREEN_BUFFER_MAGIC; - Buffer->Header.Console = Console; - Buffer->Header.HandleCount = 0; - Buffer->ShowX = 0; - Buffer->ShowY = 0; - Buffer->VirtualY = 0; - Buffer->Buffer = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, Buffer->MaxX * Buffer->MaxY * 2); - if (NULL == Buffer->Buffer) + Buffer->Header.Type = CONIO_SCREEN_BUFFER_MAGIC; + Buffer->Header.Console = Console; + Buffer->Header.HandleCount = 0; + Buffer->ShowX = 0; + Buffer->ShowY = 0; + Buffer->VirtualY = 0; + Buffer->Buffer = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, Buffer->MaxX * Buffer->MaxY * 2); + if (NULL == Buffer->Buffer) { - return STATUS_INSUFFICIENT_RESOURCES; + return STATUS_INSUFFICIENT_RESOURCES; } - ConioInitScreenBuffer(Console, Buffer); - /* initialize buffer to be empty with default attributes */ - for (Buffer->CurrentY = 0 ; Buffer->CurrentY < Buffer->MaxY; Buffer->CurrentY++) + ConioInitScreenBuffer(Console, Buffer); + /* initialize buffer to be empty with default attributes */ + for (Buffer->CurrentY = 0 ; Buffer->CurrentY < Buffer->MaxY; Buffer->CurrentY++) { - ClearLineBuffer(Buffer); + ClearLineBuffer(Buffer); } - Buffer->Mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT; - Buffer->CurrentX = 0; - Buffer->CurrentY = 0; + Buffer->Mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT; + Buffer->CurrentX = 0; + Buffer->CurrentY = 0; - InsertHeadList(&Console->BufferList, &Buffer->ListEntry); - return STATUS_SUCCESS; + InsertHeadList(&Console->BufferList, &Buffer->ListEntry); + return STATUS_SUCCESS; } static NTSTATUS WINAPI CsrInitConsole(PCSRSS_CONSOLE Console, BOOL Visible) { - NTSTATUS Status; - SECURITY_ATTRIBUTES SecurityAttributes; - PCSRSS_SCREEN_BUFFER NewBuffer; - BOOL GuiMode; + NTSTATUS Status; + SECURITY_ATTRIBUTES SecurityAttributes; + PCSRSS_SCREEN_BUFFER NewBuffer; + BOOL GuiMode; - Console->Title.MaximumLength = Console->Title.Length = 0; - Console->Title.Buffer = NULL; + Console->Title.MaximumLength = Console->Title.Length = 0; + Console->Title.Buffer = NULL; - //FIXME - RtlCreateUnicodeString(&Console->Title, L"Command Prompt"); + //FIXME + RtlCreateUnicodeString(&Console->Title, L"Command Prompt"); - Console->ReferenceCount = 0; - Console->WaitingChars = 0; - Console->WaitingLines = 0; - Console->EchoCount = 0; - Console->Header.Type = CONIO_CONSOLE_MAGIC; - Console->Header.Console = Console; - Console->Mode = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT; - Console->EarlyReturn = FALSE; - InitializeListHead(&Console->BufferList); - Console->ActiveBuffer = NULL; - InitializeListHead(&Console->InputEvents); - Console->CodePage = GetOEMCP(); - Console->OutputCodePage = GetOEMCP(); + Console->ReferenceCount = 0; + Console->WaitingChars = 0; + Console->WaitingLines = 0; + Console->EchoCount = 0; + Console->Header.Type = CONIO_CONSOLE_MAGIC; + Console->Header.Console = Console; + Console->Mode = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT; + Console->EarlyReturn = FALSE; + InitializeListHead(&Console->BufferList); + Console->ActiveBuffer = NULL; + InitializeListHead(&Console->InputEvents); + Console->CodePage = GetOEMCP(); + Console->OutputCodePage = GetOEMCP(); - SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); - SecurityAttributes.lpSecurityDescriptor = NULL; - SecurityAttributes.bInheritHandle = TRUE; + SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + SecurityAttributes.lpSecurityDescriptor = NULL; + SecurityAttributes.bInheritHandle = TRUE; - Console->ActiveEvent = CreateEventW(&SecurityAttributes, TRUE, FALSE, NULL); - if (NULL == Console->ActiveEvent) + Console->ActiveEvent = CreateEventW(&SecurityAttributes, TRUE, FALSE, NULL); + if (NULL == Console->ActiveEvent) { - RtlFreeUnicodeString(&Console->Title); - return STATUS_UNSUCCESSFUL; + RtlFreeUnicodeString(&Console->Title); + return STATUS_UNSUCCESSFUL; } - Console->PrivateData = NULL; - InitializeCriticalSection(&Console->Lock); + Console->PrivateData = NULL; + InitializeCriticalSection(&Console->Lock); - GuiMode = DtbgIsDesktopVisible(); + GuiMode = DtbgIsDesktopVisible(); - /* allocate console screen buffer */ - NewBuffer = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, sizeof(CSRSS_SCREEN_BUFFER)); - if (NULL == NewBuffer) + /* allocate console screen buffer */ + NewBuffer = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, sizeof(CSRSS_SCREEN_BUFFER)); + if (NULL == NewBuffer) { - RtlFreeUnicodeString(&Console->Title); - DeleteCriticalSection(&Console->Lock); - CloseHandle(Console->ActiveEvent); - return STATUS_INSUFFICIENT_RESOURCES; + RtlFreeUnicodeString(&Console->Title); + DeleteCriticalSection(&Console->Lock); + CloseHandle(Console->ActiveEvent); + return STATUS_INSUFFICIENT_RESOURCES; } - /* init screen buffer with defaults */ - NewBuffer->CursorInfo.bVisible = TRUE; - NewBuffer->CursorInfo.dwSize = CSR_DEFAULT_CURSOR_SIZE; - /* make console active, and insert into console list */ - Console->ActiveBuffer = (PCSRSS_SCREEN_BUFFER) NewBuffer; + /* init screen buffer with defaults */ + NewBuffer->CursorInfo.bVisible = TRUE; + NewBuffer->CursorInfo.dwSize = CSR_DEFAULT_CURSOR_SIZE; + /* make console active, and insert into console list */ + Console->ActiveBuffer = (PCSRSS_SCREEN_BUFFER) NewBuffer; - if (! GuiMode) + if (! GuiMode) { - Status = TuiInitConsole(Console); - if (! NT_SUCCESS(Status)) + Status = TuiInitConsole(Console); + if (! NT_SUCCESS(Status)) { - DPRINT1("Failed to open text-mode console, switching to gui-mode\n"); - GuiMode = TRUE; + DPRINT1("Failed to open text-mode console, switching to gui-mode\n"); + GuiMode = TRUE; } } - if (GuiMode) + if (GuiMode) { - Status = GuiInitConsole(Console, Visible); - if (! NT_SUCCESS(Status)) + Status = GuiInitConsole(Console, Visible); + if (! NT_SUCCESS(Status)) { - HeapFree(Win32CsrApiHeap,0, NewBuffer); - RtlFreeUnicodeString(&Console->Title); - DeleteCriticalSection(&Console->Lock); - CloseHandle(Console->ActiveEvent); - DPRINT1("GuiInitConsole: failed\n"); - return Status; + HeapFree(Win32CsrApiHeap,0, NewBuffer); + RtlFreeUnicodeString(&Console->Title); + DeleteCriticalSection(&Console->Lock); + CloseHandle(Console->ActiveEvent); + DPRINT1("GuiInitConsole: failed\n"); + return Status; } } - Status = CsrInitConsoleScreenBuffer(Console, NewBuffer); - if (! NT_SUCCESS(Status)) + Status = CsrInitConsoleScreenBuffer(Console, NewBuffer); + if (! NT_SUCCESS(Status)) { - ConioCleanupConsole(Console); - RtlFreeUnicodeString(&Console->Title); - DeleteCriticalSection(&Console->Lock); - CloseHandle(Console->ActiveEvent); - HeapFree(Win32CsrApiHeap, 0, NewBuffer); - DPRINT1("CsrInitConsoleScreenBuffer: failed\n"); - return Status; + ConioCleanupConsole(Console); + RtlFreeUnicodeString(&Console->Title); + DeleteCriticalSection(&Console->Lock); + CloseHandle(Console->ActiveEvent); + HeapFree(Win32CsrApiHeap, 0, NewBuffer); + DPRINT1("CsrInitConsoleScreenBuffer: failed\n"); + return Status; } - /* copy buffer contents to screen */ - ConioDrawConsole(Console); + /* copy buffer contents to screen */ + ConioDrawConsole(Console); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } @@ -270,7 +270,7 @@ CSR_API(CsrAllocConsole) /* If we already have one, then don't create a new one... */ if (!Request->Data.AllocConsoleRequest.Console || - Request->Data.AllocConsoleRequest.Console != ProcessData->ParentConsole) + Request->Data.AllocConsoleRequest.Console != ProcessData->ParentConsole) { /* Allocate a console structure */ NewConsole = TRUE; @@ -385,361 +385,362 @@ CSR_API(CsrAllocConsole) CSR_API(CsrFreeConsole) { - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - return Win32CsrReleaseConsole(ProcessData); + return Win32CsrReleaseConsole(ProcessData); } static VOID FASTCALL ConioNextLine(PCSRSS_SCREEN_BUFFER Buff, SMALL_RECT *UpdateRect, UINT *ScrolledLines) { - /* If we hit bottom, slide the viewable screen */ - if (++Buff->CurrentY == Buff->MaxY) + /* If we hit bottom, slide the viewable screen */ + if (++Buff->CurrentY == Buff->MaxY) { - Buff->CurrentY--; - if (++Buff->VirtualY == Buff->MaxY) + Buff->CurrentY--; + if (++Buff->VirtualY == Buff->MaxY) { - Buff->VirtualY = 0; + Buff->VirtualY = 0; } - (*ScrolledLines)++; - ClearLineBuffer(Buff); - if (UpdateRect->Top != 0) + (*ScrolledLines)++; + ClearLineBuffer(Buff); + if (UpdateRect->Top != 0) { - UpdateRect->Top--; + UpdateRect->Top--; } } - UpdateRect->Left = 0; - UpdateRect->Right = Buff->MaxX - 1; - UpdateRect->Bottom = Buff->CurrentY; + UpdateRect->Left = 0; + UpdateRect->Right = Buff->MaxX - 1; + UpdateRect->Bottom = Buff->CurrentY; } static NTSTATUS FASTCALL ConioWriteConsole(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, CHAR *Buffer, DWORD Length, BOOL Attrib) { - UINT i; - PBYTE Ptr; - SMALL_RECT UpdateRect; - LONG CursorStartX, CursorStartY; - UINT ScrolledLines; + UINT i; + PBYTE Ptr; + SMALL_RECT UpdateRect; + LONG CursorStartX, CursorStartY; + UINT ScrolledLines; - CursorStartX = Buff->CurrentX; - CursorStartY = Buff->CurrentY; - UpdateRect.Left = Buff->MaxX; - UpdateRect.Top = Buff->CurrentY; - UpdateRect.Right = -1; - UpdateRect.Bottom = Buff->CurrentY; - ScrolledLines = 0; + CursorStartX = Buff->CurrentX; + CursorStartY = Buff->CurrentY; + UpdateRect.Left = Buff->MaxX; + UpdateRect.Top = Buff->CurrentY; + UpdateRect.Right = -1; + UpdateRect.Bottom = Buff->CurrentY; + ScrolledLines = 0; - for (i = 0; i < Length; i++) + for (i = 0; i < Length; i++) { - if (Buff->Mode & ENABLE_PROCESSED_OUTPUT) + if (Buff->Mode & ENABLE_PROCESSED_OUTPUT) { - /* --- LF --- */ - if (Buffer[i] == '\n') + /* --- LF --- */ + if (Buffer[i] == '\n') { - Buff->CurrentX = 0; - ConioNextLine(Buff, &UpdateRect, &ScrolledLines); - continue; + Buff->CurrentX = 0; + ConioNextLine(Buff, &UpdateRect, &ScrolledLines); + continue; } - /* --- BS --- */ - else if (Buffer[i] == '\b') + /* --- BS --- */ + else if (Buffer[i] == '\b') { - /* Only handle BS if we're not on the first pos of the first line */ - if (0 != Buff->CurrentX || 0 != Buff->CurrentY) + /* Only handle BS if we're not on the first pos of the first line */ + if (0 != Buff->CurrentX || 0 != Buff->CurrentY) { - if (0 == Buff->CurrentX) + if (0 == Buff->CurrentX) { - /* slide virtual position up */ - Buff->CurrentX = Buff->MaxX - 1; - Buff->CurrentY--; - UpdateRect.Top = min(UpdateRect.Top, (LONG)Buff->CurrentY); + /* slide virtual position up */ + Buff->CurrentX = Buff->MaxX - 1; + Buff->CurrentY--; + UpdateRect.Top = min(UpdateRect.Top, (LONG)Buff->CurrentY); } - else + else { - Buff->CurrentX--; + Buff->CurrentX--; } - Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY); - Ptr[0] = ' '; - Ptr[1] = Buff->DefaultAttrib; - UpdateRect.Left = min(UpdateRect.Left, (LONG) Buff->CurrentX); - UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX); + Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY); + Ptr[0] = ' '; + Ptr[1] = Buff->DefaultAttrib; + UpdateRect.Left = min(UpdateRect.Left, (LONG) Buff->CurrentX); + UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX); } continue; } - /* --- CR --- */ - else if (Buffer[i] == '\r') + /* --- CR --- */ + else if (Buffer[i] == '\r') { - Buff->CurrentX = 0; - UpdateRect.Left = min(UpdateRect.Left, (LONG) Buff->CurrentX); - UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX); - continue; + Buff->CurrentX = 0; + UpdateRect.Left = min(UpdateRect.Left, (LONG) Buff->CurrentX); + UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX); + continue; } - /* --- TAB --- */ - else if (Buffer[i] == '\t') + /* --- TAB --- */ + else if (Buffer[i] == '\t') { - UINT EndX; + UINT EndX; - UpdateRect.Left = min(UpdateRect.Left, (LONG)Buff->CurrentX); - EndX = (Buff->CurrentX + 8) & ~7; - if (EndX > Buff->MaxX) + UpdateRect.Left = min(UpdateRect.Left, (LONG)Buff->CurrentX); + EndX = (Buff->CurrentX + 8) & ~7; + if (EndX > Buff->MaxX) { - EndX = Buff->MaxX; + EndX = Buff->MaxX; } - Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY); - while (Buff->CurrentX < EndX) + Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY); + while (Buff->CurrentX < EndX) { - *Ptr++ = ' '; - *Ptr++ = Buff->DefaultAttrib; - Buff->CurrentX++; + *Ptr++ = ' '; + *Ptr++ = Buff->DefaultAttrib; + Buff->CurrentX++; } - UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX - 1); - if (Buff->CurrentX == Buff->MaxX) + UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX - 1); + if (Buff->CurrentX == Buff->MaxX) { - if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT) + if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT) { - Buff->CurrentX = 0; - ConioNextLine(Buff, &UpdateRect, &ScrolledLines); + Buff->CurrentX = 0; + ConioNextLine(Buff, &UpdateRect, &ScrolledLines); } - else + else { - Buff->CurrentX--; + Buff->CurrentX--; } } - continue; + continue; } } - UpdateRect.Left = min(UpdateRect.Left, (LONG)Buff->CurrentX); - UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX); - Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY); - Ptr[0] = Buffer[i]; - if (Attrib) + UpdateRect.Left = min(UpdateRect.Left, (LONG)Buff->CurrentX); + UpdateRect.Right = max(UpdateRect.Right, (LONG) Buff->CurrentX); + Ptr = ConioCoordToPointer(Buff, Buff->CurrentX, Buff->CurrentY); + Ptr[0] = Buffer[i]; + if (Attrib) { - Ptr[1] = Buff->DefaultAttrib; + Ptr[1] = Buff->DefaultAttrib; } - Buff->CurrentX++; - if (Buff->CurrentX == Buff->MaxX) + Buff->CurrentX++; + if (Buff->CurrentX == Buff->MaxX) { - if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT) + if (Buff->Mode & ENABLE_WRAP_AT_EOL_OUTPUT) { - Buff->CurrentX = 0; - ConioNextLine(Buff, &UpdateRect, &ScrolledLines); + Buff->CurrentX = 0; + ConioNextLine(Buff, &UpdateRect, &ScrolledLines); } - else + else { - Buff->CurrentX = CursorStartX; + Buff->CurrentX = CursorStartX; } } } - if (! ConioIsRectEmpty(&UpdateRect) && Buff == Console->ActiveBuffer) + if (! ConioIsRectEmpty(&UpdateRect) && Buff == Console->ActiveBuffer) { - ConioWriteStream(Console, &UpdateRect, CursorStartX, CursorStartY, ScrolledLines, - Buffer, Length); + ConioWriteStream(Console, &UpdateRect, CursorStartX, CursorStartY, ScrolledLines, + Buffer, Length); } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrReadConsole) { - PLIST_ENTRY CurrentEntry; - ConsoleInput *Input; - PUCHAR Buffer; - PWCHAR UnicodeBuffer; - ULONG i; - ULONG nNumberOfCharsToRead, CharSize; - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PLIST_ENTRY CurrentEntry; + ConsoleInput *Input; + PUCHAR Buffer; + PWCHAR UnicodeBuffer; + ULONG i; + ULONG nNumberOfCharsToRead, CharSize; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrReadConsole\n"); + DPRINT("CsrReadConsole\n"); - CharSize = (Request->Data.ReadConsoleRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); + CharSize = (Request->Data.ReadConsoleRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); - /* truncate length to CSRSS_MAX_READ_CONSOLE_REQUEST */ - nNumberOfCharsToRead = min(Request->Data.ReadConsoleRequest.NrCharactersToRead, CSRSS_MAX_READ_CONSOLE / CharSize); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + /* truncate length to CSRSS_MAX_READ_CONSOLE_REQUEST */ + nNumberOfCharsToRead = min(Request->Data.ReadConsoleRequest.NrCharactersToRead, CSRSS_MAX_READ_CONSOLE / CharSize); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Buffer = Request->Data.ReadConsoleRequest.Buffer; - UnicodeBuffer = (PWCHAR)Buffer; - Status = ConioLockConsole(ProcessData, Request->Data.ReadConsoleRequest.ConsoleHandle, - &Console, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Buffer = Request->Data.ReadConsoleRequest.Buffer; + UnicodeBuffer = (PWCHAR)Buffer; + Status = ConioLockConsole(ProcessData, Request->Data.ReadConsoleRequest.ConsoleHandle, + &Console, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Data.ReadConsoleRequest.EventHandle = ProcessData->ConsoleEvent; - for (i = 0; i < nNumberOfCharsToRead && Console->InputEvents.Flink != &Console->InputEvents; i++) + Request->Data.ReadConsoleRequest.EventHandle = ProcessData->ConsoleEvent; + for (i = 0; i < nNumberOfCharsToRead && Console->InputEvents.Flink != &Console->InputEvents; i++) { - /* remove input event from queue */ - CurrentEntry = RemoveHeadList(&Console->InputEvents); - if (IsListEmpty(&Console->InputEvents)) - { - ResetEvent(Console->ActiveEvent); - } - Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry); - - /* only pay attention to valid ascii chars, on key down */ - if (KEY_EVENT == Input->InputEvent.EventType - && Input->InputEvent.Event.KeyEvent.bKeyDown - && Input->InputEvent.Event.KeyEvent.uChar.AsciiChar != '\0') + /* remove input event from queue */ + CurrentEntry = RemoveHeadList(&Console->InputEvents); + if (IsListEmpty(&Console->InputEvents)) { - /* - * backspace handling - if we are in charge of echoing it then we handle it here - * otherwise we treat it like a normal char. - */ - if ('\b' == Input->InputEvent.Event.KeyEvent.uChar.AsciiChar && 0 - != (Console->Mode & ENABLE_ECHO_INPUT)) + ResetEvent(Console->ActiveEvent); + } + Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry); + + /* only pay attention to valid ascii chars, on key down */ + if (KEY_EVENT == Input->InputEvent.EventType + && Input->InputEvent.Event.KeyEvent.bKeyDown + && Input->InputEvent.Event.KeyEvent.uChar.AsciiChar != '\0') + { + /* + * backspace handling - if we are in charge of echoing it then we handle it here + * otherwise we treat it like a normal char. + */ + if ('\b' == Input->InputEvent.Event.KeyEvent.uChar.AsciiChar && 0 + != (Console->Mode & ENABLE_ECHO_INPUT)) { - /* echo if it has not already been done, and either we or the client has chars to be deleted */ - if (! Input->Echoed - && (0 != i || Request->Data.ReadConsoleRequest.nCharsCanBeDeleted)) + /* echo if it has not already been done, and either we or the client has chars to be deleted */ + if (! Input->Echoed + && (0 != i || Request->Data.ReadConsoleRequest.nCharsCanBeDeleted)) { - ConioWriteConsole(Console, Console->ActiveBuffer, - &Input->InputEvent.Event.KeyEvent.uChar.AsciiChar, 1, TRUE); + ConioWriteConsole(Console, Console->ActiveBuffer, + &Input->InputEvent.Event.KeyEvent.uChar.AsciiChar, 1, TRUE); } - if (0 != i) + if (0 != i) { - i -= 2; /* if we already have something to return, just back it up by 2 */ + i -= 2; /* if we already have something to return, just back it up by 2 */ } - else - { /* otherwise, return STATUS_NOTIFY_CLEANUP to tell client to back up its buffer */ - Console->WaitingChars--; - ConioUnlockConsole(Console); - HeapFree(Win32CsrApiHeap, 0, Input); - Request->Data.ReadConsoleRequest.NrCharactersRead = 0; - return STATUS_NOTIFY_CLEANUP; + else + { + /* otherwise, return STATUS_NOTIFY_CLEANUP to tell client to back up its buffer */ + Console->WaitingChars--; + ConioUnlockConsole(Console); + HeapFree(Win32CsrApiHeap, 0, Input); + Request->Data.ReadConsoleRequest.NrCharactersRead = 0; + return STATUS_NOTIFY_CLEANUP; } - Request->Data.ReadConsoleRequest.nCharsCanBeDeleted--; - Input->Echoed = TRUE; /* mark as echoed so we don't echo it below */ + Request->Data.ReadConsoleRequest.nCharsCanBeDeleted--; + Input->Echoed = TRUE; /* mark as echoed so we don't echo it below */ } - /* do not copy backspace to buffer */ - else + /* do not copy backspace to buffer */ + else { - if(Request->Data.ReadConsoleRequest.Unicode) - ConsoleInputAnsiCharToUnicodeChar(Console, &UnicodeBuffer[i], &Input->InputEvent.Event.KeyEvent.uChar.AsciiChar); - else - Buffer[i] = Input->InputEvent.Event.KeyEvent.uChar.AsciiChar; + if(Request->Data.ReadConsoleRequest.Unicode) + ConsoleInputAnsiCharToUnicodeChar(Console, &UnicodeBuffer[i], &Input->InputEvent.Event.KeyEvent.uChar.AsciiChar); + else + Buffer[i] = Input->InputEvent.Event.KeyEvent.uChar.AsciiChar; } - /* echo to screen if enabled and we did not already echo the char */ - if (0 != (Console->Mode & ENABLE_ECHO_INPUT) - && ! Input->Echoed - && '\r' != Input->InputEvent.Event.KeyEvent.uChar.AsciiChar) + /* echo to screen if enabled and we did not already echo the char */ + if (0 != (Console->Mode & ENABLE_ECHO_INPUT) + && ! Input->Echoed + && '\r' != Input->InputEvent.Event.KeyEvent.uChar.AsciiChar) { - ConioWriteConsole(Console, Console->ActiveBuffer, - &Input->InputEvent.Event.KeyEvent.uChar.AsciiChar, 1, TRUE); + ConioWriteConsole(Console, Console->ActiveBuffer, + &Input->InputEvent.Event.KeyEvent.uChar.AsciiChar, 1, TRUE); } } - else + else { - i--; + i--; } - Console->WaitingChars--; - HeapFree(Win32CsrApiHeap, 0, Input); + Console->WaitingChars--; + HeapFree(Win32CsrApiHeap, 0, Input); } - Request->Data.ReadConsoleRequest.NrCharactersRead = i; - if (0 == i) + Request->Data.ReadConsoleRequest.NrCharactersRead = i; + if (0 == i) { - Status = STATUS_PENDING; /* we didn't read anything */ + Status = STATUS_PENDING; /* we didn't read anything */ } - else if (0 != (Console->Mode & ENABLE_LINE_INPUT)) + else if (0 != (Console->Mode & ENABLE_LINE_INPUT)) { - if (0 == Console->WaitingLines || - (Request->Data.ReadConsoleRequest.Unicode ? (L'\n' != UnicodeBuffer[i - 1]) : ('\n' != Buffer[i - 1]))) + if (0 == Console->WaitingLines || + (Request->Data.ReadConsoleRequest.Unicode ? (L'\n' != UnicodeBuffer[i - 1]) : ('\n' != Buffer[i - 1]))) { - Status = STATUS_PENDING; /* line buffered, didn't get a complete line */ + Status = STATUS_PENDING; /* line buffered, didn't get a complete line */ } - else + else { - Console->WaitingLines--; - Status = STATUS_SUCCESS; /* line buffered, did get a complete line */ + Console->WaitingLines--; + Status = STATUS_SUCCESS; /* line buffered, did get a complete line */ } } - else + else { - Status = STATUS_SUCCESS; /* not line buffered, did read something */ + Status = STATUS_SUCCESS; /* not line buffered, did read something */ } - if (Status == STATUS_PENDING) + if (Status == STATUS_PENDING) { - Console->EchoCount = nNumberOfCharsToRead - i; + Console->EchoCount = nNumberOfCharsToRead - i; } - else + else { - Console->EchoCount = 0; /* if the client is no longer waiting on input, do not echo */ + Console->EchoCount = 0; /* if the client is no longer waiting on input, do not echo */ } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - if (CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE) + i * CharSize > sizeof(CSR_API_MESSAGE)) + if (CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE) + i * CharSize > sizeof(CSR_API_MESSAGE)) { - Request->Header.u1.s1.TotalLength = CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE) + i * CharSize; - Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE) + i * CharSize; + Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); } - return Status; + return Status; } __inline BOOLEAN ConioGetIntersection( - SMALL_RECT *Intersection, - SMALL_RECT *Rect1, - SMALL_RECT *Rect2) + SMALL_RECT *Intersection, + SMALL_RECT *Rect1, + SMALL_RECT *Rect2) { - if (ConioIsRectEmpty(Rect1) || - (ConioIsRectEmpty(Rect2)) || - (Rect1->Top > Rect2->Bottom) || - (Rect1->Left > Rect2->Right) || - (Rect1->Bottom < Rect2->Top) || - (Rect1->Right < Rect2->Left)) - { - /* The rectangles do not intersect */ - ConioInitRect(Intersection, 0, -1, 0, -1); - return FALSE; - } + if (ConioIsRectEmpty(Rect1) || + (ConioIsRectEmpty(Rect2)) || + (Rect1->Top > Rect2->Bottom) || + (Rect1->Left > Rect2->Right) || + (Rect1->Bottom < Rect2->Top) || + (Rect1->Right < Rect2->Left)) + { + /* The rectangles do not intersect */ + ConioInitRect(Intersection, 0, -1, 0, -1); + return FALSE; + } - ConioInitRect(Intersection, - max(Rect1->Top, Rect2->Top), - max(Rect1->Left, Rect2->Left), - min(Rect1->Bottom, Rect2->Bottom), - min(Rect1->Right, Rect2->Right)); + ConioInitRect(Intersection, + max(Rect1->Top, Rect2->Top), + max(Rect1->Left, Rect2->Left), + min(Rect1->Bottom, Rect2->Bottom), + min(Rect1->Right, Rect2->Right)); - return TRUE; + return TRUE; } __inline BOOLEAN ConioGetUnion( - SMALL_RECT *Union, - SMALL_RECT *Rect1, - SMALL_RECT *Rect2) + SMALL_RECT *Union, + SMALL_RECT *Rect1, + SMALL_RECT *Rect2) { - if (ConioIsRectEmpty(Rect1)) + if (ConioIsRectEmpty(Rect1)) { - if (ConioIsRectEmpty(Rect2)) + if (ConioIsRectEmpty(Rect2)) { - ConioInitRect(Union, 0, -1, 0, -1); - return FALSE; + ConioInitRect(Union, 0, -1, 0, -1); + return FALSE; } - else + else { - *Union = *Rect2; + *Union = *Rect2; } } - else if (ConioIsRectEmpty(Rect2)) + else if (ConioIsRectEmpty(Rect2)) { - *Union = *Rect1; + *Union = *Rect1; } - else + else { - ConioInitRect(Union, - min(Rect1->Top, Rect2->Top), - min(Rect1->Left, Rect2->Left), - max(Rect1->Bottom, Rect2->Bottom), - max(Rect1->Right, Rect2->Right)); + ConioInitRect(Union, + min(Rect1->Top, Rect2->Top), + min(Rect1->Left, Rect2->Left), + max(Rect1->Bottom, Rect2->Bottom), + max(Rect1->Right, Rect2->Right)); } - return TRUE; + return TRUE; } /* Move from one rectangle to another. We must be careful about the order that @@ -751,158 +752,158 @@ ConioMoveRegion(PCSRSS_SCREEN_BUFFER ScreenBuffer, SMALL_RECT *ClipRegion, WORD Fill) { - int Width = ConioRectWidth(SrcRegion); - int Height = ConioRectHeight(SrcRegion); - int SX, SY; - int DX, DY; - int XDelta, YDelta; - int i, j; + int Width = ConioRectWidth(SrcRegion); + int Height = ConioRectHeight(SrcRegion); + int SX, SY; + int DX, DY; + int XDelta, YDelta; + int i, j; - SY = SrcRegion->Top; - DY = DstRegion->Top; - YDelta = 1; - if (SY < DY) + SY = SrcRegion->Top; + DY = DstRegion->Top; + YDelta = 1; + if (SY < DY) { - /* Moving down: work from bottom up */ - SY = SrcRegion->Bottom; - DY = DstRegion->Bottom; - YDelta = -1; + /* Moving down: work from bottom up */ + SY = SrcRegion->Bottom; + DY = DstRegion->Bottom; + YDelta = -1; } - for (i = 0; i < Height; i++) + for (i = 0; i < Height; i++) { - PWORD SRow = (PWORD)ConioCoordToPointer(ScreenBuffer, 0, SY); - PWORD DRow = (PWORD)ConioCoordToPointer(ScreenBuffer, 0, DY); + PWORD SRow = (PWORD)ConioCoordToPointer(ScreenBuffer, 0, SY); + PWORD DRow = (PWORD)ConioCoordToPointer(ScreenBuffer, 0, DY); - SX = SrcRegion->Left; - DX = DstRegion->Left; - XDelta = 1; - if (SX < DX) + SX = SrcRegion->Left; + DX = DstRegion->Left; + XDelta = 1; + if (SX < DX) { - /* Moving right: work from right to left */ - SX = SrcRegion->Right; - DX = DstRegion->Right; - XDelta = -1; + /* Moving right: work from right to left */ + SX = SrcRegion->Right; + DX = DstRegion->Right; + XDelta = -1; } - for (j = 0; j < Width; j++) + for (j = 0; j < Width; j++) { - WORD Cell = SRow[SX]; - if (SX >= ClipRegion->Left && SX <= ClipRegion->Right - && SY >= ClipRegion->Top && SY <= ClipRegion->Bottom) + WORD Cell = SRow[SX]; + if (SX >= ClipRegion->Left && SX <= ClipRegion->Right + && SY >= ClipRegion->Top && SY <= ClipRegion->Bottom) { - SRow[SX] = Fill; + SRow[SX] = Fill; } - if (DX >= ClipRegion->Left && DX <= ClipRegion->Right - && DY >= ClipRegion->Top && DY <= ClipRegion->Bottom) + if (DX >= ClipRegion->Left && DX <= ClipRegion->Right + && DY >= ClipRegion->Top && DY <= ClipRegion->Bottom) { - DRow[DX] = Cell; + DRow[DX] = Cell; } - SX += XDelta; - DX += XDelta; + SX += XDelta; + DX += XDelta; } - SY += YDelta; - DY += YDelta; + SY += YDelta; + DY += YDelta; } } static VOID FASTCALL ConioInputEventToAnsi(PCSRSS_CONSOLE Console, PINPUT_RECORD InputEvent) { - if (InputEvent->EventType == KEY_EVENT) + if (InputEvent->EventType == KEY_EVENT) { - WCHAR UnicodeChar = InputEvent->Event.KeyEvent.uChar.UnicodeChar; - InputEvent->Event.KeyEvent.uChar.UnicodeChar = 0; - ConsoleInputUnicodeCharToAnsiChar(Console, - &InputEvent->Event.KeyEvent.uChar.AsciiChar, - &UnicodeChar); + WCHAR UnicodeChar = InputEvent->Event.KeyEvent.uChar.UnicodeChar; + InputEvent->Event.KeyEvent.uChar.UnicodeChar = 0; + ConsoleInputUnicodeCharToAnsiChar(Console, + &InputEvent->Event.KeyEvent.uChar.AsciiChar, + &UnicodeChar); } } CSR_API(CsrWriteConsole) { - NTSTATUS Status; - PCHAR Buffer; - PCSRSS_SCREEN_BUFFER Buff; - PCSRSS_CONSOLE Console; - DWORD Written = 0; - ULONG Length; - ULONG CharSize = (Request->Data.WriteConsoleRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); + NTSTATUS Status; + PCHAR Buffer; + PCSRSS_SCREEN_BUFFER Buff; + PCSRSS_CONSOLE Console; + DWORD Written = 0; + ULONG Length; + ULONG CharSize = (Request->Data.WriteConsoleRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); - DPRINT("CsrWriteConsole\n"); + DPRINT("CsrWriteConsole\n"); - if (Request->Header.u1.s1.TotalLength - < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE) - + (Request->Data.WriteConsoleRequest.NrCharactersToWrite * CharSize)) + if (Request->Header.u1.s1.TotalLength + < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE) + + (Request->Data.WriteConsoleRequest.NrCharactersToWrite * CharSize)) { - DPRINT1("Invalid request size\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - return STATUS_INVALID_PARAMETER; + DPRINT1("Invalid request size\n"); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + return STATUS_INVALID_PARAMETER; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.WriteConsoleRequest.ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.WriteConsoleRequest.ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - if (Console->UnpauseEvent) + if (Console->UnpauseEvent) { - Status = NtDuplicateObject(GetCurrentProcess(), Console->UnpauseEvent, - ProcessData->Process, &Request->Data.WriteConsoleRequest.UnpauseEvent, - SYNCHRONIZE, 0, 0); - ConioUnlockScreenBuffer(Buff); - return NT_SUCCESS(Status) ? STATUS_PENDING : Status; + Status = NtDuplicateObject(GetCurrentProcess(), Console->UnpauseEvent, + ProcessData->Process, &Request->Data.WriteConsoleRequest.UnpauseEvent, + SYNCHRONIZE, 0, 0); + ConioUnlockScreenBuffer(Buff); + return NT_SUCCESS(Status) ? STATUS_PENDING : Status; } - if(Request->Data.WriteConsoleRequest.Unicode) + if(Request->Data.WriteConsoleRequest.Unicode) { - Length = WideCharToMultiByte(Console->OutputCodePage, 0, - (PWCHAR)Request->Data.WriteConsoleRequest.Buffer, - Request->Data.WriteConsoleRequest.NrCharactersToWrite, - NULL, 0, NULL, NULL); - Buffer = RtlAllocateHeap(GetProcessHeap(), 0, Length); - if (Buffer) + Length = WideCharToMultiByte(Console->OutputCodePage, 0, + (PWCHAR)Request->Data.WriteConsoleRequest.Buffer, + Request->Data.WriteConsoleRequest.NrCharactersToWrite, + NULL, 0, NULL, NULL); + Buffer = RtlAllocateHeap(GetProcessHeap(), 0, Length); + if (Buffer) { - WideCharToMultiByte(Console->OutputCodePage, 0, - (PWCHAR)Request->Data.WriteConsoleRequest.Buffer, - Request->Data.WriteConsoleRequest.NrCharactersToWrite, - Buffer, Length, NULL, NULL); + WideCharToMultiByte(Console->OutputCodePage, 0, + (PWCHAR)Request->Data.WriteConsoleRequest.Buffer, + Request->Data.WriteConsoleRequest.NrCharactersToWrite, + Buffer, Length, NULL, NULL); } - else + else { - Status = STATUS_NO_MEMORY; + Status = STATUS_NO_MEMORY; } } - else + else { - Buffer = (PCHAR)Request->Data.WriteConsoleRequest.Buffer; + Buffer = (PCHAR)Request->Data.WriteConsoleRequest.Buffer; } - if (Buffer) + if (Buffer) { - if (NT_SUCCESS(Status)) + if (NT_SUCCESS(Status)) { - Status = ConioWriteConsole(Console, Buff, Buffer, - Request->Data.WriteConsoleRequest.NrCharactersToWrite, TRUE); - if (NT_SUCCESS(Status)) + Status = ConioWriteConsole(Console, Buff, Buffer, + Request->Data.WriteConsoleRequest.NrCharactersToWrite, TRUE); + if (NT_SUCCESS(Status)) { - Written = Request->Data.WriteConsoleRequest.NrCharactersToWrite; + Written = Request->Data.WriteConsoleRequest.NrCharactersToWrite; } } - if (Request->Data.WriteConsoleRequest.Unicode) + if (Request->Data.WriteConsoleRequest.Unicode) { - RtlFreeHeap(GetProcessHeap(), 0, Buffer); + RtlFreeHeap(GetProcessHeap(), 0, Buffer); } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - Request->Data.WriteConsoleRequest.NrCharactersWritten = Written; + Request->Data.WriteConsoleRequest.NrCharactersWritten = Written; - return Status; + return Status; } VOID WINAPI @@ -929,52 +930,52 @@ ConioDeleteScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer) VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console) { - SMALL_RECT Region; + SMALL_RECT Region; - ConioInitRect(&Region, 0, 0, Console->Size.Y - 1, Console->Size.X - 1); + ConioInitRect(&Region, 0, 0, Console->Size.Y - 1, Console->Size.X - 1); - ConioDrawRegion(Console, &Region); + ConioDrawRegion(Console, &Region); } VOID WINAPI ConioDeleteConsole(Object_t *Object) { - PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Object; - ConsoleInput *Event; + PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Object; + ConsoleInput *Event; - DPRINT("ConioDeleteConsole\n"); + DPRINT("ConioDeleteConsole\n"); - /* Drain input event queue */ - while (Console->InputEvents.Flink != &Console->InputEvents) + /* Drain input event queue */ + while (Console->InputEvents.Flink != &Console->InputEvents) { - Event = (ConsoleInput *) Console->InputEvents.Flink; - Console->InputEvents.Flink = Console->InputEvents.Flink->Flink; - Console->InputEvents.Flink->Flink->Blink = &Console->InputEvents; - HeapFree(Win32CsrApiHeap, 0, Event); + Event = (ConsoleInput *) Console->InputEvents.Flink; + Console->InputEvents.Flink = Console->InputEvents.Flink->Flink; + Console->InputEvents.Flink->Flink->Blink = &Console->InputEvents; + HeapFree(Win32CsrApiHeap, 0, Event); } - ConioCleanupConsole(Console); - ConioDeleteScreenBuffer(Console->ActiveBuffer); - if (!IsListEmpty(&Console->BufferList)) + ConioCleanupConsole(Console); + ConioDeleteScreenBuffer(Console->ActiveBuffer); + if (!IsListEmpty(&Console->BufferList)) { - DPRINT1("BUG: screen buffer list not empty\n"); + DPRINT1("BUG: screen buffer list not empty\n"); } - CloseHandle(Console->ActiveEvent); - if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent); - DeleteCriticalSection(&Console->Lock); - RtlFreeUnicodeString(&Console->Title); - IntDeleteAllAliases(Console->Aliases); - HeapFree(Win32CsrApiHeap, 0, Console); + CloseHandle(Console->ActiveEvent); + if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent); + DeleteCriticalSection(&Console->Lock); + RtlFreeUnicodeString(&Console->Title); + IntDeleteAllAliases(Console->Aliases); + HeapFree(Win32CsrApiHeap, 0, Console); } VOID WINAPI CsrInitConsoleSupport(VOID) { - DPRINT("CSR: CsrInitConsoleSupport()\n"); + DPRINT("CSR: CsrInitConsoleSupport()\n"); - /* Should call LoadKeyboardLayout */ + /* Should call LoadKeyboardLayout */ } VOID FASTCALL @@ -1001,43 +1002,43 @@ static VOID FASTCALL ConioProcessChar(PCSRSS_CONSOLE Console, ConsoleInput *KeyEventRecord) { - BOOL updown; - ConsoleInput *TempInput; + BOOL updown; + ConsoleInput *TempInput; - if (KeyEventRecord->InputEvent.EventType == KEY_EVENT && - KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown) + if (KeyEventRecord->InputEvent.EventType == KEY_EVENT && + KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown) { - WORD vk = KeyEventRecord->InputEvent.Event.KeyEvent.wVirtualKeyCode; - if (!(Console->PauseFlags & PAUSED_FROM_KEYBOARD)) + WORD vk = KeyEventRecord->InputEvent.Event.KeyEvent.wVirtualKeyCode; + if (!(Console->PauseFlags & PAUSED_FROM_KEYBOARD)) { - DWORD cks = KeyEventRecord->InputEvent.Event.KeyEvent.dwControlKeyState; - if (Console->Mode & ENABLE_LINE_INPUT && - (vk == VK_PAUSE || (vk == 'S' && - (cks & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) && - !(cks & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))))) + DWORD cks = KeyEventRecord->InputEvent.Event.KeyEvent.dwControlKeyState; + if (Console->Mode & ENABLE_LINE_INPUT && + (vk == VK_PAUSE || (vk == 'S' && + (cks & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) && + !(cks & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))))) { - ConioPause(Console, PAUSED_FROM_KEYBOARD); - HeapFree(Win32CsrApiHeap, 0, KeyEventRecord); - return; + ConioPause(Console, PAUSED_FROM_KEYBOARD); + HeapFree(Win32CsrApiHeap, 0, KeyEventRecord); + return; } } - else + else { - if ((vk < VK_SHIFT || vk > VK_CAPITAL) && vk != VK_LWIN && - vk != VK_RWIN && vk != VK_NUMLOCK && vk != VK_SCROLL) + if ((vk < VK_SHIFT || vk > VK_CAPITAL) && vk != VK_LWIN && + vk != VK_RWIN && vk != VK_NUMLOCK && vk != VK_SCROLL) { - ConioUnpause(Console, PAUSED_FROM_KEYBOARD); - HeapFree(Win32CsrApiHeap, 0, KeyEventRecord); - return; + ConioUnpause(Console, PAUSED_FROM_KEYBOARD); + HeapFree(Win32CsrApiHeap, 0, KeyEventRecord); + return; } } } - if (0 != (Console->Mode & (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT))) + if (0 != (Console->Mode & (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT))) { - switch(KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar) + switch(KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar) { - case '\r': + case '\r': /* first add the \r */ KeyEventRecord->InputEvent.EventType = KEY_EVENT; updown = KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown; @@ -1048,10 +1049,10 @@ ConioProcessChar(PCSRSS_CONSOLE Console, Console->WaitingChars++; KeyEventRecord = HeapAlloc(Win32CsrApiHeap, 0, sizeof(ConsoleInput)); if (NULL == KeyEventRecord) - { + { DPRINT1("Failed to allocate KeyEventRecord\n"); return; - } + } KeyEventRecord->InputEvent.EventType = KEY_EVENT; KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown = updown; KeyEventRecord->InputEvent.Event.KeyEvent.wVirtualKeyCode = 0; @@ -1061,1733 +1062,1733 @@ ConioProcessChar(PCSRSS_CONSOLE Console, break; } } - /* add event to the queue */ - InsertTailList(&Console->InputEvents, &KeyEventRecord->ListEntry); - Console->WaitingChars++; - /* if line input mode is enabled, only wake the client on enter key down */ - if (0 == (Console->Mode & ENABLE_LINE_INPUT) - || Console->EarlyReturn - || ('\n' == KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar - && KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown)) + /* add event to the queue */ + InsertTailList(&Console->InputEvents, &KeyEventRecord->ListEntry); + Console->WaitingChars++; + /* if line input mode is enabled, only wake the client on enter key down */ + if (0 == (Console->Mode & ENABLE_LINE_INPUT) + || Console->EarlyReturn + || ('\n' == KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar + && KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown)) { - if ('\n' == KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar) + if ('\n' == KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar) { - Console->WaitingLines++; + Console->WaitingLines++; } } - KeyEventRecord->Echoed = FALSE; - if (0 != (Console->Mode & (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT)) - && '\b' == KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar - && KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown) + KeyEventRecord->Echoed = FALSE; + if (0 != (Console->Mode & (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT)) + && '\b' == KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar + && KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown) { - /* walk the input queue looking for a char to backspace */ - for (TempInput = (ConsoleInput *) Console->InputEvents.Blink; - TempInput != (ConsoleInput *) &Console->InputEvents - && (KEY_EVENT == TempInput->InputEvent.EventType - || ! TempInput->InputEvent.Event.KeyEvent.bKeyDown - || '\b' == TempInput->InputEvent.Event.KeyEvent.uChar.AsciiChar); - TempInput = (ConsoleInput *) TempInput->ListEntry.Blink) + /* walk the input queue looking for a char to backspace */ + for (TempInput = (ConsoleInput *) Console->InputEvents.Blink; + TempInput != (ConsoleInput *) &Console->InputEvents + && (KEY_EVENT == TempInput->InputEvent.EventType + || ! TempInput->InputEvent.Event.KeyEvent.bKeyDown + || '\b' == TempInput->InputEvent.Event.KeyEvent.uChar.AsciiChar); + TempInput = (ConsoleInput *) TempInput->ListEntry.Blink) { - /* NOP */; + /* NOP */; } - /* if we found one, delete it, otherwise, wake the client */ - if (TempInput != (ConsoleInput *) &Console->InputEvents) + /* if we found one, delete it, otherwise, wake the client */ + if (TempInput != (ConsoleInput *) &Console->InputEvents) { - /* delete previous key in queue, maybe echo backspace to screen, and do not place backspace on queue */ - RemoveEntryList(&TempInput->ListEntry); - if (TempInput->Echoed) + /* delete previous key in queue, maybe echo backspace to screen, and do not place backspace on queue */ + RemoveEntryList(&TempInput->ListEntry); + if (TempInput->Echoed) { - ConioWriteConsole(Console, Console->ActiveBuffer, - &KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar, - 1, TRUE); + ConioWriteConsole(Console, Console->ActiveBuffer, + &KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar, + 1, TRUE); } - HeapFree(Win32CsrApiHeap, 0, TempInput); - RemoveEntryList(&KeyEventRecord->ListEntry); - HeapFree(Win32CsrApiHeap, 0, KeyEventRecord); - Console->WaitingChars -= 2; - return; + HeapFree(Win32CsrApiHeap, 0, TempInput); + RemoveEntryList(&KeyEventRecord->ListEntry); + HeapFree(Win32CsrApiHeap, 0, KeyEventRecord); + Console->WaitingChars -= 2; + return; } } - else + else { - /* echo chars if we are supposed to and client is waiting for some */ - if (0 != (Console->Mode & ENABLE_ECHO_INPUT) && Console->EchoCount - && KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar - && KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown - && '\r' != KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar) + /* echo chars if we are supposed to and client is waiting for some */ + if (0 != (Console->Mode & ENABLE_ECHO_INPUT) && Console->EchoCount + && KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar + && KeyEventRecord->InputEvent.Event.KeyEvent.bKeyDown + && '\r' != KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar) { - /* mark the char as already echoed */ - ConioWriteConsole(Console, Console->ActiveBuffer, - &KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar, - 1, TRUE); - Console->EchoCount--; - KeyEventRecord->Echoed = TRUE; + /* mark the char as already echoed */ + ConioWriteConsole(Console, Console->ActiveBuffer, + &KeyEventRecord->InputEvent.Event.KeyEvent.uChar.AsciiChar, + 1, TRUE); + Console->EchoCount--; + KeyEventRecord->Echoed = TRUE; } } - /* Console->WaitingChars++; */ - SetEvent(Console->ActiveEvent); + /* Console->WaitingChars++; */ + SetEvent(Console->ActiveEvent); } static DWORD FASTCALL ConioGetShiftState(PBYTE KeyState) { - DWORD ssOut = 0; + DWORD ssOut = 0; - if (KeyState[VK_CAPITAL] & 1) - ssOut |= CAPSLOCK_ON; + if (KeyState[VK_CAPITAL] & 1) + ssOut |= CAPSLOCK_ON; - if (KeyState[VK_NUMLOCK] & 1) - ssOut |= NUMLOCK_ON; + if (KeyState[VK_NUMLOCK] & 1) + ssOut |= NUMLOCK_ON; - if (KeyState[VK_SCROLL] & 1) - ssOut |= SCROLLLOCK_ON; + if (KeyState[VK_SCROLL] & 1) + ssOut |= SCROLLLOCK_ON; - if (KeyState[VK_SHIFT] & 0x80) - ssOut |= SHIFT_PRESSED; + if (KeyState[VK_SHIFT] & 0x80) + ssOut |= SHIFT_PRESSED; - if (KeyState[VK_LCONTROL] & 0x80) - ssOut |= LEFT_CTRL_PRESSED; - if (KeyState[VK_RCONTROL] & 0x80) - ssOut |= RIGHT_CTRL_PRESSED; + if (KeyState[VK_LCONTROL] & 0x80) + ssOut |= LEFT_CTRL_PRESSED; + if (KeyState[VK_RCONTROL] & 0x80) + ssOut |= RIGHT_CTRL_PRESSED; - if (KeyState[VK_LMENU] & 0x80) - ssOut |= LEFT_ALT_PRESSED; - if (KeyState[VK_RMENU] & 0x80) - ssOut |= RIGHT_ALT_PRESSED; + if (KeyState[VK_LMENU] & 0x80) + ssOut |= LEFT_ALT_PRESSED; + if (KeyState[VK_RMENU] & 0x80) + ssOut |= RIGHT_ALT_PRESSED; - return ssOut; + return ssOut; } VOID WINAPI ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode) { - static BYTE KeyState[256] = { 0 }; - /* MSDN mentions that you should use the last virtual key code received - * when putting a virtual key identity to a WM_CHAR message since multiple - * or translated keys may be involved. */ - static UINT LastVirtualKey = 0; - DWORD ShiftState; - ConsoleInput *ConInRec; - UINT RepeatCount; - CHAR AsciiChar; - WCHAR UnicodeChar; - UINT VirtualKeyCode; - UINT VirtualScanCode; - BOOL Down = FALSE; - INPUT_RECORD er; - ULONG ResultSize = 0; + static BYTE KeyState[256] = { 0 }; + /* MSDN mentions that you should use the last virtual key code received + * when putting a virtual key identity to a WM_CHAR message since multiple + * or translated keys may be involved. */ + static UINT LastVirtualKey = 0; + DWORD ShiftState; + ConsoleInput *ConInRec; + UINT RepeatCount; + CHAR AsciiChar; + WCHAR UnicodeChar; + UINT VirtualKeyCode; + UINT VirtualScanCode; + BOOL Down = FALSE; + INPUT_RECORD er; + ULONG ResultSize = 0; - RepeatCount = 1; - VirtualScanCode = (msg->lParam >> 16) & 0xff; - Down = msg->message == WM_KEYDOWN || msg->message == WM_CHAR || - msg->message == WM_SYSKEYDOWN || msg->message == WM_SYSCHAR; + RepeatCount = 1; + VirtualScanCode = (msg->lParam >> 16) & 0xff; + Down = msg->message == WM_KEYDOWN || msg->message == WM_CHAR || + msg->message == WM_SYSKEYDOWN || msg->message == WM_SYSCHAR; - GetKeyboardState(KeyState); - ShiftState = ConioGetShiftState(KeyState); + GetKeyboardState(KeyState); + ShiftState = ConioGetShiftState(KeyState); - if (msg->message == WM_CHAR || msg->message == WM_SYSCHAR) + if (msg->message == WM_CHAR || msg->message == WM_SYSCHAR) { - VirtualKeyCode = LastVirtualKey; - UnicodeChar = msg->wParam; + VirtualKeyCode = LastVirtualKey; + UnicodeChar = msg->wParam; } - else + else { - WCHAR Chars[2]; - INT RetChars = 0; + WCHAR Chars[2]; + INT RetChars = 0; - VirtualKeyCode = msg->wParam; - RetChars = ToUnicodeEx(VirtualKeyCode, - VirtualScanCode, - KeyState, - Chars, - 2, - 0, - 0); - UnicodeChar = (1 == RetChars ? Chars[0] : 0); + VirtualKeyCode = msg->wParam; + RetChars = ToUnicodeEx(VirtualKeyCode, + VirtualScanCode, + KeyState, + Chars, + 2, + 0, + 0); + UnicodeChar = (1 == RetChars ? Chars[0] : 0); } - if (0 == ResultSize) + if (0 == ResultSize) { - AsciiChar = 0; + AsciiChar = 0; } - er.EventType = KEY_EVENT; - er.Event.KeyEvent.bKeyDown = Down; - er.Event.KeyEvent.wRepeatCount = RepeatCount; - er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar; - er.Event.KeyEvent.dwControlKeyState = ShiftState; - er.Event.KeyEvent.wVirtualKeyCode = VirtualKeyCode; - er.Event.KeyEvent.wVirtualScanCode = VirtualScanCode; + er.EventType = KEY_EVENT; + er.Event.KeyEvent.bKeyDown = Down; + er.Event.KeyEvent.wRepeatCount = RepeatCount; + er.Event.KeyEvent.uChar.UnicodeChar = UnicodeChar; + er.Event.KeyEvent.dwControlKeyState = ShiftState; + er.Event.KeyEvent.wVirtualKeyCode = VirtualKeyCode; + er.Event.KeyEvent.wVirtualScanCode = VirtualScanCode; - if (TextMode) + if (TextMode) { - if (0 != (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) - && VK_TAB == VirtualKeyCode) + if (0 != (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) + && VK_TAB == VirtualKeyCode) { - if (Down) + if (Down) { - TuiSwapConsole(ShiftState & SHIFT_PRESSED ? -1 : 1); + TuiSwapConsole(ShiftState & SHIFT_PRESSED ? -1 : 1); } - return; + return; } - else if (VK_MENU == VirtualKeyCode && ! Down) + else if (VK_MENU == VirtualKeyCode && ! Down) { - if (TuiSwapConsole(0)) + if (TuiSwapConsole(0)) { - return; + return; } } } - if (NULL == Console) + if (NULL == Console) { - DPRINT1("No Active Console!\n"); - return; + DPRINT1("No Active Console!\n"); + return; } - ConInRec = HeapAlloc(Win32CsrApiHeap, 0, sizeof(ConsoleInput)); + ConInRec = HeapAlloc(Win32CsrApiHeap, 0, sizeof(ConsoleInput)); - if (NULL == ConInRec) + if (NULL == ConInRec) { - return; + return; } - ConInRec->InputEvent = er; - ConInRec->Fake = UnicodeChar && - (msg->message != WM_CHAR && msg->message != WM_SYSCHAR && - msg->message != WM_KEYUP && msg->message != WM_SYSKEYUP); - ConInRec->NotChar = (msg->message != WM_CHAR && msg->message != WM_SYSCHAR); - ConInRec->Echoed = FALSE; - if (ConInRec->NotChar) - LastVirtualKey = msg->wParam; + ConInRec->InputEvent = er; + ConInRec->Fake = UnicodeChar && + (msg->message != WM_CHAR && msg->message != WM_SYSCHAR && + msg->message != WM_KEYUP && msg->message != WM_SYSKEYUP); + ConInRec->NotChar = (msg->message != WM_CHAR && msg->message != WM_SYSCHAR); + ConInRec->Echoed = FALSE; + if (ConInRec->NotChar) + LastVirtualKey = msg->wParam; - DPRINT ("csrss: %s %s %s %s %02x %02x '%c' %04x\n", - Down ? "down" : "up ", - (msg->message == WM_CHAR || msg->message == WM_SYSCHAR) ? - "char" : "key ", - ConInRec->Fake ? "fake" : "real", - ConInRec->NotChar ? "notc" : "char", - VirtualScanCode, - VirtualKeyCode, - (AsciiChar >= ' ') ? AsciiChar : '.', - ShiftState); + DPRINT ("csrss: %s %s %s %s %02x %02x '%c' %04x\n", + Down ? "down" : "up ", + (msg->message == WM_CHAR || msg->message == WM_SYSCHAR) ? + "char" : "key ", + ConInRec->Fake ? "fake" : "real", + ConInRec->NotChar ? "notc" : "char", + VirtualScanCode, + VirtualKeyCode, + (AsciiChar >= ' ') ? AsciiChar : '.', + ShiftState); - if (ConInRec->Fake && ConInRec->NotChar) + if (ConInRec->Fake && ConInRec->NotChar) { - HeapFree(Win32CsrApiHeap, 0, ConInRec); - return; + HeapFree(Win32CsrApiHeap, 0, ConInRec); + return; } - /* process Ctrl-C and Ctrl-Break */ - if (Console->Mode & ENABLE_PROCESSED_INPUT && - er.Event.KeyEvent.bKeyDown && - ((er.Event.KeyEvent.wVirtualKeyCode == VK_PAUSE) || - (er.Event.KeyEvent.wVirtualKeyCode == 'C')) && - (er.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))) + /* process Ctrl-C and Ctrl-Break */ + if (Console->Mode & ENABLE_PROCESSED_INPUT && + er.Event.KeyEvent.bKeyDown && + ((er.Event.KeyEvent.wVirtualKeyCode == VK_PAUSE) || + (er.Event.KeyEvent.wVirtualKeyCode == 'C')) && + (er.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))) { - PCSRSS_PROCESS_DATA current; - PLIST_ENTRY current_entry; - DPRINT1("Console_Api Ctrl-C\n"); - current_entry = Console->ProcessList.Flink; - while (current_entry != &Console->ProcessList) - { - current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); - current_entry = current_entry->Flink; - ConioConsoleCtrlEvent((DWORD)CTRL_C_EVENT, current); - } - HeapFree(Win32CsrApiHeap, 0, ConInRec); - return; - } - - if (0 != (er.Event.KeyEvent.dwControlKeyState - & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) - && (VK_UP == er.Event.KeyEvent.wVirtualKeyCode - || VK_DOWN == er.Event.KeyEvent.wVirtualKeyCode)) - { - if (er.Event.KeyEvent.bKeyDown) + PCSRSS_PROCESS_DATA current; + PLIST_ENTRY current_entry; + DPRINT1("Console_Api Ctrl-C\n"); + current_entry = Console->ProcessList.Flink; + while (current_entry != &Console->ProcessList) { - /* scroll up or down */ - if (VK_UP == er.Event.KeyEvent.wVirtualKeyCode) + current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); + current_entry = current_entry->Flink; + ConioConsoleCtrlEvent((DWORD)CTRL_C_EVENT, current); + } + HeapFree(Win32CsrApiHeap, 0, ConInRec); + return; + } + + if (0 != (er.Event.KeyEvent.dwControlKeyState + & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) + && (VK_UP == er.Event.KeyEvent.wVirtualKeyCode + || VK_DOWN == er.Event.KeyEvent.wVirtualKeyCode)) + { + if (er.Event.KeyEvent.bKeyDown) + { + /* scroll up or down */ + if (VK_UP == er.Event.KeyEvent.wVirtualKeyCode) { - /* only scroll up if there is room to scroll up into */ - if (Console->ActiveBuffer->CurrentY != Console->ActiveBuffer->MaxY - 1) + /* only scroll up if there is room to scroll up into */ + if (Console->ActiveBuffer->CurrentY != Console->ActiveBuffer->MaxY - 1) { - Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + - Console->ActiveBuffer->MaxY - 1) % - Console->ActiveBuffer->MaxY; - Console->ActiveBuffer->CurrentY++; + Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + + Console->ActiveBuffer->MaxY - 1) % + Console->ActiveBuffer->MaxY; + Console->ActiveBuffer->CurrentY++; } } - else + else { - /* only scroll down if there is room to scroll down into */ - if (Console->ActiveBuffer->CurrentY != 0) + /* only scroll down if there is room to scroll down into */ + if (Console->ActiveBuffer->CurrentY != 0) { - Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + 1) % - Console->ActiveBuffer->MaxY; - Console->ActiveBuffer->CurrentY--; + Console->ActiveBuffer->VirtualY = (Console->ActiveBuffer->VirtualY + 1) % + Console->ActiveBuffer->MaxY; + Console->ActiveBuffer->CurrentY--; } } - ConioDrawConsole(Console); + ConioDrawConsole(Console); } - HeapFree(Win32CsrApiHeap, 0, ConInRec); - return; + HeapFree(Win32CsrApiHeap, 0, ConInRec); + return; } - /* FIXME - convert to ascii */ - ConioProcessChar(Console, ConInRec); + /* FIXME - convert to ascii */ + ConioProcessChar(Console, ConInRec); } CSR_API(CsrGetScreenBufferInfo) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - PCONSOLE_SCREEN_BUFFER_INFO pInfo; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + PCONSOLE_SCREEN_BUFFER_INFO pInfo; - DPRINT("CsrGetScreenBufferInfo\n"); + DPRINT("CsrGetScreenBufferInfo\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.ScreenBufferInfoRequest.ConsoleHandle, &Buff, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.ScreenBufferInfoRequest.ConsoleHandle, &Buff, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; - pInfo = &Request->Data.ScreenBufferInfoRequest.Info; - pInfo->dwSize.X = Buff->MaxX; - pInfo->dwSize.Y = Buff->MaxY; - pInfo->dwCursorPosition.X = Buff->CurrentX; - pInfo->dwCursorPosition.Y = Buff->CurrentY; - pInfo->wAttributes = Buff->DefaultAttrib; - pInfo->srWindow.Left = Buff->ShowX; - pInfo->srWindow.Right = Buff->ShowX + Console->Size.X - 1; - pInfo->srWindow.Top = Buff->ShowY; - pInfo->srWindow.Bottom = Buff->ShowY + Console->Size.Y - 1; - pInfo->dwMaximumWindowSize.X = Buff->MaxX; - pInfo->dwMaximumWindowSize.Y = Buff->MaxY; - ConioUnlockScreenBuffer(Buff); + Console = Buff->Header.Console; + pInfo = &Request->Data.ScreenBufferInfoRequest.Info; + pInfo->dwSize.X = Buff->MaxX; + pInfo->dwSize.Y = Buff->MaxY; + pInfo->dwCursorPosition.X = Buff->CurrentX; + pInfo->dwCursorPosition.Y = Buff->CurrentY; + pInfo->wAttributes = Buff->DefaultAttrib; + pInfo->srWindow.Left = Buff->ShowX; + pInfo->srWindow.Right = Buff->ShowX + Console->Size.X - 1; + pInfo->srWindow.Top = Buff->ShowY; + pInfo->srWindow.Bottom = Buff->ShowY + Console->Size.Y - 1; + pInfo->dwMaximumWindowSize.X = Buff->MaxX; + pInfo->dwMaximumWindowSize.Y = Buff->MaxY; + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetCursor) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - LONG OldCursorX, OldCursorY; - LONG NewCursorX, NewCursorY; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + LONG OldCursorX, OldCursorY; + LONG NewCursorX, NewCursorY; - DPRINT("CsrSetCursor\n"); + DPRINT("CsrSetCursor\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetCursorRequest.ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetCursorRequest.ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } Console = Buff->Header.Console; - NewCursorX = Request->Data.SetCursorRequest.Position.X; - NewCursorY = Request->Data.SetCursorRequest.Position.Y; - if (NewCursorX < 0 || NewCursorX >= Buff->MaxX || - NewCursorY < 0 || NewCursorY >= Buff->MaxY) + NewCursorX = Request->Data.SetCursorRequest.Position.X; + NewCursorY = Request->Data.SetCursorRequest.Position.Y; + if (NewCursorX < 0 || NewCursorX >= Buff->MaxX || + NewCursorY < 0 || NewCursorY >= Buff->MaxY) { - ConioUnlockScreenBuffer(Buff); - return STATUS_INVALID_PARAMETER; + ConioUnlockScreenBuffer(Buff); + return STATUS_INVALID_PARAMETER; } - OldCursorX = Buff->CurrentX; - OldCursorY = Buff->CurrentY; - Buff->CurrentX = NewCursorX; - Buff->CurrentY = NewCursorY; - if (Buff == Console->ActiveBuffer) + OldCursorX = Buff->CurrentX; + OldCursorY = Buff->CurrentY; + Buff->CurrentX = NewCursorX; + Buff->CurrentY = NewCursorY; + if (Buff == Console->ActiveBuffer) { - if (! ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY)) + if (! ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY)) { - ConioUnlockScreenBuffer(Buff); - return STATUS_UNSUCCESSFUL; + ConioUnlockScreenBuffer(Buff); + return STATUS_UNSUCCESSFUL; } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static VOID FASTCALL ConioComputeUpdateRect(PCSRSS_SCREEN_BUFFER Buff, SMALL_RECT *UpdateRect, COORD *Start, UINT Length) { - if (Buff->MaxX <= Start->X + Length) + if (Buff->MaxX <= Start->X + Length) { - UpdateRect->Left = 0; + UpdateRect->Left = 0; } - else + else { - UpdateRect->Left = Start->X; + UpdateRect->Left = Start->X; } - if (Buff->MaxX <= Start->X + Length) + if (Buff->MaxX <= Start->X + Length) { - UpdateRect->Right = Buff->MaxX - 1; + UpdateRect->Right = Buff->MaxX - 1; } - else + else { - UpdateRect->Right = Start->X + Length - 1; + UpdateRect->Right = Start->X + Length - 1; } - UpdateRect->Top = Start->Y; - UpdateRect->Bottom = Start->Y+ (Start->X + Length - 1) / Buff->MaxX; - if (Buff->MaxY <= UpdateRect->Bottom) + UpdateRect->Top = Start->Y; + UpdateRect->Bottom = Start->Y+ (Start->X + Length - 1) / Buff->MaxX; + if (Buff->MaxY <= UpdateRect->Bottom) { - UpdateRect->Bottom = Buff->MaxY - 1; + UpdateRect->Bottom = Buff->MaxY - 1; } } CSR_API(CsrWriteConsoleOutputChar) { - NTSTATUS Status; - PCHAR String, tmpString = NULL; - PBYTE Buffer; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - DWORD X, Y, Length, CharSize, Written = 0; - SMALL_RECT UpdateRect; + NTSTATUS Status; + PCHAR String, tmpString = NULL; + PBYTE Buffer; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + DWORD X, Y, Length, CharSize, Written = 0; + SMALL_RECT UpdateRect; - DPRINT("CsrWriteConsoleOutputChar\n"); + DPRINT("CsrWriteConsoleOutputChar\n"); - CharSize = (Request->Data.WriteConsoleOutputCharRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); + CharSize = (Request->Data.WriteConsoleOutputCharRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); - if (Request->Header.u1.s1.TotalLength - < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR) - + (Request->Data.WriteConsoleOutputCharRequest.Length * CharSize)) + if (Request->Header.u1.s1.TotalLength + < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR) + + (Request->Data.WriteConsoleOutputCharRequest.Length * CharSize)) { - DPRINT1("Invalid request size\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - return STATUS_INVALID_PARAMETER; + DPRINT1("Invalid request size\n"); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + return STATUS_INVALID_PARAMETER; } - Status = ConioLockScreenBuffer(ProcessData, - Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle, - &Buff, - GENERIC_WRITE); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - if (NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, + Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle, + &Buff, + GENERIC_WRITE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + if (NT_SUCCESS(Status)) { - Console = Buff->Header.Console; - if(Request->Data.WriteConsoleOutputCharRequest.Unicode) + Console = Buff->Header.Console; + if(Request->Data.WriteConsoleOutputCharRequest.Unicode) { - Length = WideCharToMultiByte(Console->OutputCodePage, 0, - (PWCHAR)Request->Data.WriteConsoleOutputCharRequest.String, - Request->Data.WriteConsoleOutputCharRequest.Length, - NULL, 0, NULL, NULL); - tmpString = String = RtlAllocateHeap(GetProcessHeap(), 0, Length); - if (String) + Length = WideCharToMultiByte(Console->OutputCodePage, 0, + (PWCHAR)Request->Data.WriteConsoleOutputCharRequest.String, + Request->Data.WriteConsoleOutputCharRequest.Length, + NULL, 0, NULL, NULL); + tmpString = String = RtlAllocateHeap(GetProcessHeap(), 0, Length); + if (String) { - WideCharToMultiByte(Console->OutputCodePage, 0, - (PWCHAR)Request->Data.WriteConsoleOutputCharRequest.String, - Request->Data.WriteConsoleOutputCharRequest.Length, - String, Length, NULL, NULL); + WideCharToMultiByte(Console->OutputCodePage, 0, + (PWCHAR)Request->Data.WriteConsoleOutputCharRequest.String, + Request->Data.WriteConsoleOutputCharRequest.Length, + String, Length, NULL, NULL); } - else + else { - Status = STATUS_NO_MEMORY; + Status = STATUS_NO_MEMORY; } } - else + else { - String = (PCHAR)Request->Data.WriteConsoleOutputCharRequest.String; + String = (PCHAR)Request->Data.WriteConsoleOutputCharRequest.String; } - if (String) + if (String) { - if (NT_SUCCESS(Status)) + if (NT_SUCCESS(Status)) { - X = Request->Data.WriteConsoleOutputCharRequest.Coord.X; - Y = (Request->Data.WriteConsoleOutputCharRequest.Coord.Y + Buff->VirtualY) % Buff->MaxY; - Length = Request->Data.WriteConsoleOutputCharRequest.Length; - Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X)]; - while (Length--) + X = Request->Data.WriteConsoleOutputCharRequest.Coord.X; + Y = (Request->Data.WriteConsoleOutputCharRequest.Coord.Y + Buff->VirtualY) % Buff->MaxY; + Length = Request->Data.WriteConsoleOutputCharRequest.Length; + Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X)]; + while (Length--) { - *Buffer = *String++; - Written++; - Buffer += 2; - if (++X == Buff->MaxX) + *Buffer = *String++; + Written++; + Buffer += 2; + if (++X == Buff->MaxX) { - if (++Y == Buff->MaxY) + if (++Y == Buff->MaxY) { - Y = 0; - Buffer = Buff->Buffer; + Y = 0; + Buffer = Buff->Buffer; } - X = 0; + X = 0; } } - if (Buff == Console->ActiveBuffer) + if (Buff == Console->ActiveBuffer) { - ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.WriteConsoleOutputCharRequest.Coord, - Request->Data.WriteConsoleOutputCharRequest.Length); - ConioDrawRegion(Console, &UpdateRect); + ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.WriteConsoleOutputCharRequest.Coord, + Request->Data.WriteConsoleOutputCharRequest.Length); + ConioDrawRegion(Console, &UpdateRect); } Request->Data.WriteConsoleOutputCharRequest.EndCoord.X = X; Request->Data.WriteConsoleOutputCharRequest.EndCoord.Y = (Y + Buff->MaxY - Buff->VirtualY) % Buff->MaxY; } - if (Request->Data.WriteConsoleRequest.Unicode) + if (Request->Data.WriteConsoleRequest.Unicode) { - RtlFreeHeap(GetProcessHeap(), 0, tmpString); + RtlFreeHeap(GetProcessHeap(), 0, tmpString); } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); } - Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten = Written; - return Status; + Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten = Written; + return Status; } CSR_API(CsrFillOutputChar) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - DWORD X, Y, Length, Written = 0; - CHAR Char; - PBYTE Buffer; - SMALL_RECT UpdateRect; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + DWORD X, Y, Length, Written = 0; + CHAR Char; + PBYTE Buffer; + SMALL_RECT UpdateRect; - DPRINT("CsrFillOutputChar\n"); + DPRINT("CsrFillOutputChar\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.FillOutputRequest.ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.FillOutputRequest.ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - X = Request->Data.FillOutputRequest.Position.X; - Y = (Request->Data.FillOutputRequest.Position.Y + Buff->VirtualY) % Buff->MaxY; - Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X)]; - if(Request->Data.FillOutputRequest.Unicode) - ConsoleUnicodeCharToAnsiChar(Console, &Char, &Request->Data.FillOutputRequest.Char.UnicodeChar); - else - Char = Request->Data.FillOutputRequest.Char.AsciiChar; - Length = Request->Data.FillOutputRequest.Length; - while (Length--) + X = Request->Data.FillOutputRequest.Position.X; + Y = (Request->Data.FillOutputRequest.Position.Y + Buff->VirtualY) % Buff->MaxY; + Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X)]; + if(Request->Data.FillOutputRequest.Unicode) + ConsoleUnicodeCharToAnsiChar(Console, &Char, &Request->Data.FillOutputRequest.Char.UnicodeChar); + else + Char = Request->Data.FillOutputRequest.Char.AsciiChar; + Length = Request->Data.FillOutputRequest.Length; + while (Length--) { - *Buffer = Char; - Buffer += 2; - Written++; - if (++X == Buff->MaxX) + *Buffer = Char; + Buffer += 2; + Written++; + if (++X == Buff->MaxX) { - if (++Y == Buff->MaxY) + if (++Y == Buff->MaxY) { - Y = 0; - Buffer = Buff->Buffer; + Y = 0; + Buffer = Buff->Buffer; } - X = 0; + X = 0; } } - if (Buff == Console->ActiveBuffer) + if (Buff == Console->ActiveBuffer) { - ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.FillOutputRequest.Position, - Request->Data.FillOutputRequest.Length); - ConioDrawRegion(Console, &UpdateRect); + ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.FillOutputRequest.Position, + Request->Data.FillOutputRequest.Length); + ConioDrawRegion(Console, &UpdateRect); } - ConioUnlockScreenBuffer(Buff); - Length = Request->Data.FillOutputRequest.Length; - Request->Data.FillOutputRequest.NrCharactersWritten = Length; - return STATUS_SUCCESS; + ConioUnlockScreenBuffer(Buff); + Length = Request->Data.FillOutputRequest.Length; + Request->Data.FillOutputRequest.NrCharactersWritten = Length; + return STATUS_SUCCESS; } CSR_API(CsrReadInputEvent) { - PLIST_ENTRY CurrentEntry; - PCSRSS_CONSOLE Console; - NTSTATUS Status; - BOOLEAN Done = FALSE; - ConsoleInput *Input; + PLIST_ENTRY CurrentEntry; + PCSRSS_CONSOLE Console; + NTSTATUS Status; + BOOLEAN Done = FALSE; + ConsoleInput *Input; - DPRINT("CsrReadInputEvent\n"); + DPRINT("CsrReadInputEvent\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Request->Data.ReadInputRequest.Event = ProcessData->ConsoleEvent; + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Data.ReadInputRequest.Event = ProcessData->ConsoleEvent; - Status = ConioLockConsole(ProcessData, Request->Data.ReadInputRequest.ConsoleHandle, &Console, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockConsole(ProcessData, Request->Data.ReadInputRequest.ConsoleHandle, &Console, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - /* only get input if there is any */ - CurrentEntry = Console->InputEvents.Flink; - while (CurrentEntry != &Console->InputEvents) + /* only get input if there is any */ + CurrentEntry = Console->InputEvents.Flink; + while (CurrentEntry != &Console->InputEvents) { - Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry); - CurrentEntry = CurrentEntry->Flink; + Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry); + CurrentEntry = CurrentEntry->Flink; - if (Done && !Input->Fake) + if (Done && !Input->Fake) { - Request->Data.ReadInputRequest.MoreEvents = TRUE; - break; + Request->Data.ReadInputRequest.MoreEvents = TRUE; + break; } - RemoveEntryList(&Input->ListEntry); + RemoveEntryList(&Input->ListEntry); - if (!Done && !Input->Fake) + if (!Done && !Input->Fake) { - Request->Data.ReadInputRequest.Input = Input->InputEvent; - if (Request->Data.ReadInputRequest.Unicode == FALSE) + Request->Data.ReadInputRequest.Input = Input->InputEvent; + if (Request->Data.ReadInputRequest.Unicode == FALSE) { - ConioInputEventToAnsi(Console, &Request->Data.ReadInputRequest.Input); + ConioInputEventToAnsi(Console, &Request->Data.ReadInputRequest.Input); } - Done = TRUE; + Done = TRUE; } - if (Input->InputEvent.EventType == KEY_EVENT) + if (Input->InputEvent.EventType == KEY_EVENT) { - if (0 != (Console->Mode & ENABLE_LINE_INPUT) - && Input->InputEvent.Event.KeyEvent.bKeyDown - && '\r' == Input->InputEvent.Event.KeyEvent.uChar.AsciiChar) + if (0 != (Console->Mode & ENABLE_LINE_INPUT) + && Input->InputEvent.Event.KeyEvent.bKeyDown + && '\r' == Input->InputEvent.Event.KeyEvent.uChar.AsciiChar) { - Console->WaitingLines--; + Console->WaitingLines--; } - Console->WaitingChars--; + Console->WaitingChars--; } - HeapFree(Win32CsrApiHeap, 0, Input); + HeapFree(Win32CsrApiHeap, 0, Input); } - if (Done) + if (Done) { - Status = STATUS_SUCCESS; - Console->EarlyReturn = FALSE; + Status = STATUS_SUCCESS; + Console->EarlyReturn = FALSE; } - else + else { - Status = STATUS_PENDING; - Console->EarlyReturn = TRUE; /* mark for early return */ + Status = STATUS_PENDING; + Console->EarlyReturn = TRUE; /* mark for early return */ } - if (IsListEmpty(&Console->InputEvents)) + if (IsListEmpty(&Console->InputEvents)) { - ResetEvent(Console->ActiveEvent); + ResetEvent(Console->ActiveEvent); } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - return Status; + return Status; } CSR_API(CsrWriteConsoleOutputAttrib) { - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - PUCHAR Buffer; - PWORD Attribute; - int X, Y, Length; - NTSTATUS Status; - SMALL_RECT UpdateRect; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + PUCHAR Buffer; + PWORD Attribute; + int X, Y, Length; + NTSTATUS Status; + SMALL_RECT UpdateRect; - DPRINT("CsrWriteConsoleOutputAttrib\n"); + DPRINT("CsrWriteConsoleOutputAttrib\n"); - if (Request->Header.u1.s1.TotalLength - < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB) - + Request->Data.WriteConsoleOutputAttribRequest.Length * sizeof(WORD)) + if (Request->Header.u1.s1.TotalLength + < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB) + + Request->Data.WriteConsoleOutputAttribRequest.Length * sizeof(WORD)) { - DPRINT1("Invalid request size\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - return STATUS_INVALID_PARAMETER; + DPRINT1("Invalid request size\n"); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + return STATUS_INVALID_PARAMETER; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, - Request->Data.WriteConsoleOutputAttribRequest.ConsoleHandle, - &Buff, - GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, + Request->Data.WriteConsoleOutputAttribRequest.ConsoleHandle, + &Buff, + GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - X = Request->Data.WriteConsoleOutputAttribRequest.Coord.X; - Y = (Request->Data.WriteConsoleOutputAttribRequest.Coord.Y + Buff->VirtualY) % Buff->MaxY; - Length = Request->Data.WriteConsoleOutputAttribRequest.Length; - Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + 1]; - Attribute = Request->Data.WriteConsoleOutputAttribRequest.Attribute; - while (Length--) + X = Request->Data.WriteConsoleOutputAttribRequest.Coord.X; + Y = (Request->Data.WriteConsoleOutputAttribRequest.Coord.Y + Buff->VirtualY) % Buff->MaxY; + Length = Request->Data.WriteConsoleOutputAttribRequest.Length; + Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + 1]; + Attribute = Request->Data.WriteConsoleOutputAttribRequest.Attribute; + while (Length--) { - *Buffer = (UCHAR)(*Attribute++); - Buffer += 2; - if (++X == Buff->MaxX) + *Buffer = (UCHAR)(*Attribute++); + Buffer += 2; + if (++X == Buff->MaxX) { - if (++Y == Buff->MaxY) + if (++Y == Buff->MaxY) { - Y = 0; - Buffer = Buff->Buffer + 1; + Y = 0; + Buffer = Buff->Buffer + 1; } - X = 0; + X = 0; } } - if (Buff == Console->ActiveBuffer) + if (Buff == Console->ActiveBuffer) { - ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.WriteConsoleOutputAttribRequest.Coord, - Request->Data.WriteConsoleOutputAttribRequest.Length); - ConioDrawRegion(Console, &UpdateRect); + ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.WriteConsoleOutputAttribRequest.Coord, + Request->Data.WriteConsoleOutputAttribRequest.Length); + ConioDrawRegion(Console, &UpdateRect); } - Request->Data.WriteConsoleOutputAttribRequest.EndCoord.X = X; - Request->Data.WriteConsoleOutputAttribRequest.EndCoord.Y = (Y + Buff->MaxY - Buff->VirtualY) % Buff->MaxY; + Request->Data.WriteConsoleOutputAttribRequest.EndCoord.X = X; + Request->Data.WriteConsoleOutputAttribRequest.EndCoord.Y = (Y + Buff->MaxY - Buff->VirtualY) % Buff->MaxY; - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrFillOutputAttrib) { - PCSRSS_SCREEN_BUFFER Buff; - PUCHAR Buffer; - NTSTATUS Status; - int X, Y, Length; - UCHAR Attr; - SMALL_RECT UpdateRect; - PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + PUCHAR Buffer; + NTSTATUS Status; + int X, Y, Length; + UCHAR Attr; + SMALL_RECT UpdateRect; + PCSRSS_CONSOLE Console; - DPRINT("CsrFillOutputAttrib\n"); + DPRINT("CsrFillOutputAttrib\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.FillOutputAttribRequest.ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = ConioLockScreenBuffer(ProcessData, Request->Data.FillOutputAttribRequest.ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - X = Request->Data.FillOutputAttribRequest.Coord.X; - Y = (Request->Data.FillOutputAttribRequest.Coord.Y + Buff->VirtualY) % Buff->MaxY; - Length = Request->Data.FillOutputAttribRequest.Length; - Attr = Request->Data.FillOutputAttribRequest.Attribute; - Buffer = &Buff->Buffer[(Y * Buff->MaxX * 2) + (X * 2) + 1]; - while (Length--) + X = Request->Data.FillOutputAttribRequest.Coord.X; + Y = (Request->Data.FillOutputAttribRequest.Coord.Y + Buff->VirtualY) % Buff->MaxY; + Length = Request->Data.FillOutputAttribRequest.Length; + Attr = Request->Data.FillOutputAttribRequest.Attribute; + Buffer = &Buff->Buffer[(Y * Buff->MaxX * 2) + (X * 2) + 1]; + while (Length--) { - *Buffer = Attr; - Buffer += 2; - if (++X == Buff->MaxX) + *Buffer = Attr; + Buffer += 2; + if (++X == Buff->MaxX) { - if (++Y == Buff->MaxY) + if (++Y == Buff->MaxY) { - Y = 0; - Buffer = Buff->Buffer + 1; + Y = 0; + Buffer = Buff->Buffer + 1; } - X = 0; + X = 0; } } - if (Buff == Console->ActiveBuffer) + if (Buff == Console->ActiveBuffer) { - ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.FillOutputAttribRequest.Coord, - Request->Data.FillOutputAttribRequest.Length); - ConioDrawRegion(Console, &UpdateRect); + ConioComputeUpdateRect(Buff, &UpdateRect, &Request->Data.FillOutputAttribRequest.Coord, + Request->Data.FillOutputAttribRequest.Length); + ConioDrawRegion(Console, &UpdateRect); } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrGetCursorInfo) { - PCSRSS_SCREEN_BUFFER Buff; - NTSTATUS Status; + PCSRSS_SCREEN_BUFFER Buff; + NTSTATUS Status; - DPRINT("CsrGetCursorInfo\n"); + DPRINT("CsrGetCursorInfo\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.GetCursorInfoRequest.ConsoleHandle, &Buff, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.GetCursorInfoRequest.ConsoleHandle, &Buff, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Data.GetCursorInfoRequest.Info.bVisible = Buff->CursorInfo.bVisible; - Request->Data.GetCursorInfoRequest.Info.dwSize = Buff->CursorInfo.dwSize; - ConioUnlockScreenBuffer(Buff); + Request->Data.GetCursorInfoRequest.Info.bVisible = Buff->CursorInfo.bVisible; + Request->Data.GetCursorInfoRequest.Info.dwSize = Buff->CursorInfo.dwSize; + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetCursorInfo) { - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - DWORD Size; - BOOL Visible; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + DWORD Size; + BOOL Visible; + NTSTATUS Status; - DPRINT("CsrSetCursorInfo\n"); + DPRINT("CsrSetCursorInfo\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetCursorInfoRequest.ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetCursorInfoRequest.ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - Size = Request->Data.SetCursorInfoRequest.Info.dwSize; - Visible = Request->Data.SetCursorInfoRequest.Info.bVisible; - if (Size < 1) + Size = Request->Data.SetCursorInfoRequest.Info.dwSize; + Visible = Request->Data.SetCursorInfoRequest.Info.bVisible; + if (Size < 1) { - Size = 1; + Size = 1; } - if (100 < Size) + if (100 < Size) { - Size = 100; + Size = 100; } - if (Size != Buff->CursorInfo.dwSize - || (Visible && ! Buff->CursorInfo.bVisible) || (! Visible && Buff->CursorInfo.bVisible)) + if (Size != Buff->CursorInfo.dwSize + || (Visible && ! Buff->CursorInfo.bVisible) || (! Visible && Buff->CursorInfo.bVisible)) { - Buff->CursorInfo.dwSize = Size; - Buff->CursorInfo.bVisible = Visible; + Buff->CursorInfo.dwSize = Size; + Buff->CursorInfo.bVisible = Visible; - if (! ConioSetCursorInfo(Console, Buff)) + if (! ConioSetCursorInfo(Console, Buff)) { - ConioUnlockScreenBuffer(Buff); - return STATUS_UNSUCCESSFUL; + ConioUnlockScreenBuffer(Buff); + return STATUS_UNSUCCESSFUL; } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetTextAttrib) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; - DPRINT("CsrSetTextAttrib\n"); + DPRINT("CsrSetTextAttrib\n"); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetCursorRequest.ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetCursorRequest.ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } Console = Buff->Header.Console; - Buff->DefaultAttrib = Request->Data.SetAttribRequest.Attrib; - if (Buff == Console->ActiveBuffer) + Buff->DefaultAttrib = Request->Data.SetAttribRequest.Attrib; + if (Buff == Console->ActiveBuffer) { - if (! ConioUpdateScreenInfo(Console, Buff)) + if (! ConioUpdateScreenInfo(Console, Buff)) { - ConioUnlockScreenBuffer(Buff); - return STATUS_UNSUCCESSFUL; + ConioUnlockScreenBuffer(Buff); + return STATUS_UNSUCCESSFUL; } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetConsoleMode) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; - DPRINT("CsrSetConsoleMode\n"); + DPRINT("CsrSetConsoleMode\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = Win32CsrLockObject(ProcessData, - Request->Data.SetConsoleModeRequest.ConsoleHandle, - (Object_t **) &Console, GENERIC_WRITE, 0); - if (! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = Win32CsrLockObject(ProcessData, + Request->Data.SetConsoleModeRequest.ConsoleHandle, + (Object_t **) &Console, GENERIC_WRITE, 0); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Buff = (PCSRSS_SCREEN_BUFFER)Console; - if (CONIO_CONSOLE_MAGIC == Console->Header.Type) + Buff = (PCSRSS_SCREEN_BUFFER)Console; + if (CONIO_CONSOLE_MAGIC == Console->Header.Type) { - Console->Mode = Request->Data.SetConsoleModeRequest.Mode & CONSOLE_INPUT_MODE_VALID; + Console->Mode = Request->Data.SetConsoleModeRequest.Mode & CONSOLE_INPUT_MODE_VALID; } - else if (CONIO_SCREEN_BUFFER_MAGIC == Console->Header.Type) + else if (CONIO_SCREEN_BUFFER_MAGIC == Console->Header.Type) { - Buff->Mode = Request->Data.SetConsoleModeRequest.Mode & CONSOLE_OUTPUT_MODE_VALID; + Buff->Mode = Request->Data.SetConsoleModeRequest.Mode & CONSOLE_OUTPUT_MODE_VALID; } - else + else { - Status = STATUS_INVALID_HANDLE; + Status = STATUS_INVALID_HANDLE; } - Win32CsrUnlockObject((Object_t *)Console); + Win32CsrUnlockObject((Object_t *)Console); - return Status; + return Status; } CSR_API(CsrGetConsoleMode) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; /* gee, I really wish I could use an anonymous union here */ + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; /* gee, I really wish I could use an anonymous union here */ - DPRINT("CsrGetConsoleMode\n"); + DPRINT("CsrGetConsoleMode\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = Win32CsrLockObject(ProcessData, Request->Data.GetConsoleModeRequest.ConsoleHandle, - (Object_t **) &Console, GENERIC_READ, 0); - if (! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = Win32CsrLockObject(ProcessData, Request->Data.GetConsoleModeRequest.ConsoleHandle, + (Object_t **) &Console, GENERIC_READ, 0); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Status = STATUS_SUCCESS; - Buff = (PCSRSS_SCREEN_BUFFER) Console; - if (CONIO_CONSOLE_MAGIC == Console->Header.Type) + Status = STATUS_SUCCESS; + Buff = (PCSRSS_SCREEN_BUFFER) Console; + if (CONIO_CONSOLE_MAGIC == Console->Header.Type) { - Request->Data.GetConsoleModeRequest.ConsoleMode = Console->Mode; + Request->Data.GetConsoleModeRequest.ConsoleMode = Console->Mode; } - else if (CONIO_SCREEN_BUFFER_MAGIC == Buff->Header.Type) + else if (CONIO_SCREEN_BUFFER_MAGIC == Buff->Header.Type) { - Request->Data.GetConsoleModeRequest.ConsoleMode = Buff->Mode; + Request->Data.GetConsoleModeRequest.ConsoleMode = Buff->Mode; } - else + else { - Status = STATUS_INVALID_HANDLE; + Status = STATUS_INVALID_HANDLE; } - Win32CsrUnlockObject((Object_t *)Console); - return Status; + Win32CsrUnlockObject((Object_t *)Console); + return Status; } CSR_API(CsrCreateScreenBuffer) { - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + NTSTATUS Status; - DPRINT("CsrCreateScreenBuffer\n"); + DPRINT("CsrCreateScreenBuffer\n"); - RtlEnterCriticalSection(&ProcessData->HandleTableLock); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + RtlEnterCriticalSection(&ProcessData->HandleTableLock); + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Buff = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, sizeof(CSRSS_SCREEN_BUFFER)); + Buff = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, sizeof(CSRSS_SCREEN_BUFFER)); - if (Buff != NULL) + if (Buff != NULL) { - if (Console->ActiveBuffer) + if (Console->ActiveBuffer) { - Buff->MaxX = Console->ActiveBuffer->MaxX; - Buff->MaxY = Console->ActiveBuffer->MaxY; - Buff->CursorInfo.bVisible = Console->ActiveBuffer->CursorInfo.bVisible; - Buff->CursorInfo.dwSize = Console->ActiveBuffer->CursorInfo.dwSize; + Buff->MaxX = Console->ActiveBuffer->MaxX; + Buff->MaxY = Console->ActiveBuffer->MaxY; + Buff->CursorInfo.bVisible = Console->ActiveBuffer->CursorInfo.bVisible; + Buff->CursorInfo.dwSize = Console->ActiveBuffer->CursorInfo.dwSize; } - else + else { - Buff->CursorInfo.bVisible = TRUE; - Buff->CursorInfo.dwSize = CSR_DEFAULT_CURSOR_SIZE; + Buff->CursorInfo.bVisible = TRUE; + Buff->CursorInfo.dwSize = CSR_DEFAULT_CURSOR_SIZE; } - if (Buff->MaxX == 0) + if (Buff->MaxX == 0) { - Buff->MaxX = 80; + Buff->MaxX = 80; } - if (Buff->MaxY == 0) + if (Buff->MaxY == 0) { - Buff->MaxY = 25; + Buff->MaxY = 25; } - Status = CsrInitConsoleScreenBuffer(Console, Buff); - if(NT_SUCCESS(Status)) + Status = CsrInitConsoleScreenBuffer(Console, Buff); + if (NT_SUCCESS(Status)) { - Status = Win32CsrInsertObject(ProcessData, - &Request->Data.CreateScreenBufferRequest.OutputHandle, - &Buff->Header, - Request->Data.CreateScreenBufferRequest.Access, - Request->Data.CreateScreenBufferRequest.Inheritable, - Request->Data.CreateScreenBufferRequest.ShareMode); + Status = Win32CsrInsertObject(ProcessData, + &Request->Data.CreateScreenBufferRequest.OutputHandle, + &Buff->Header, + Request->Data.CreateScreenBufferRequest.Access, + Request->Data.CreateScreenBufferRequest.Inheritable, + Request->Data.CreateScreenBufferRequest.ShareMode); } } - else + else { - Status = STATUS_INSUFFICIENT_RESOURCES; + Status = STATUS_INSUFFICIENT_RESOURCES; } - ConioUnlockConsole(Console); - RtlLeaveCriticalSection(&ProcessData->HandleTableLock); - return Status; + ConioUnlockConsole(Console); + RtlLeaveCriticalSection(&ProcessData->HandleTableLock); + return Status; } CSR_API(CsrSetScreenBuffer) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; - DPRINT("CsrSetScreenBuffer\n"); + DPRINT("CsrSetScreenBuffer\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetScreenBufferRequest.OutputHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.SetScreenBufferRequest.OutputHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - if (Buff == Console->ActiveBuffer) + if (Buff == Console->ActiveBuffer) { - ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + ConioUnlockScreenBuffer(Buff); + return STATUS_SUCCESS; } - /* If old buffer has no handles, it's now unreferenced */ - if (Console->ActiveBuffer->Header.HandleCount == 0) + /* If old buffer has no handles, it's now unreferenced */ + if (Console->ActiveBuffer->Header.HandleCount == 0) { - ConioDeleteScreenBuffer(Console->ActiveBuffer); + ConioDeleteScreenBuffer(Console->ActiveBuffer); } - /* tie console to new buffer */ - Console->ActiveBuffer = Buff; - /* Redraw the console */ - ConioDrawConsole(Console); + /* tie console to new buffer */ + Console->ActiveBuffer = Buff; + /* Redraw the console */ + ConioDrawConsole(Console); - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetTitle) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PWCHAR Buffer; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PWCHAR Buffer; - DPRINT("CsrSetTitle\n"); + DPRINT("CsrSetTitle\n"); - if (Request->Header.u1.s1.TotalLength - < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE) - + Request->Data.SetTitleRequest.Length) + if (Request->Header.u1.s1.TotalLength + < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE) + + Request->Data.SetTitleRequest.Length) { - DPRINT1("Invalid request size\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - return STATUS_INVALID_PARAMETER; + DPRINT1("Invalid request size\n"); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + return STATUS_INVALID_PARAMETER; } - Status = ConioConsoleFromProcessData(ProcessData, &Console); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - if(NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + if(NT_SUCCESS(Status)) { - Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Request->Data.SetTitleRequest.Length); - if (Buffer) + Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Request->Data.SetTitleRequest.Length); + if (Buffer) { - /* copy title to console */ - RtlFreeUnicodeString(&Console->Title); - Console->Title.Buffer = Buffer; - Console->Title.Length = Console->Title.MaximumLength = Request->Data.SetTitleRequest.Length; - memcpy(Console->Title.Buffer, Request->Data.SetTitleRequest.Title, Console->Title.Length); - if (! ConioChangeTitle(Console)) + /* copy title to console */ + RtlFreeUnicodeString(&Console->Title); + Console->Title.Buffer = Buffer; + Console->Title.Length = Console->Title.MaximumLength = Request->Data.SetTitleRequest.Length; + memcpy(Console->Title.Buffer, Request->Data.SetTitleRequest.Title, Console->Title.Length); + if (! ConioChangeTitle(Console)) { - Status = STATUS_UNSUCCESSFUL; + Status = STATUS_UNSUCCESSFUL; } - else + else { - Status = STATUS_SUCCESS; + Status = STATUS_SUCCESS; } } - else + else { - Status = STATUS_NO_MEMORY; + Status = STATUS_NO_MEMORY; } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); } - return Status; + return Status; } CSR_API(CsrGetTitle) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - DWORD Length; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + DWORD Length; - DPRINT("CsrGetTitle\n"); + DPRINT("CsrGetTitle\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - DPRINT1("Can't get console\n"); - return Status; + DPRINT1("Can't get console\n"); + return Status; } - /* Copy title of the console to the user title buffer */ - RtlZeroMemory(&Request->Data.GetTitleRequest, sizeof(CSRSS_GET_TITLE)); - Request->Data.GetTitleRequest.Length = Console->Title.Length; - memcpy (Request->Data.GetTitleRequest.Title, Console->Title.Buffer, - Console->Title.Length); - Length = CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE) + Console->Title.Length; + /* Copy title of the console to the user title buffer */ + RtlZeroMemory(&Request->Data.GetTitleRequest, sizeof(CSRSS_GET_TITLE)); + Request->Data.GetTitleRequest.Length = Console->Title.Length; + memcpy (Request->Data.GetTitleRequest.Title, Console->Title.Buffer, + Console->Title.Length); + Length = CSR_API_MESSAGE_HEADER_SIZE(CSRSS_SET_TITLE) + Console->Title.Length; - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - if (Length > sizeof(CSR_API_MESSAGE)) + if (Length > sizeof(CSR_API_MESSAGE)) { - Request->Header.u1.s1.TotalLength = Length; - Request->Header.u1.s1.DataLength = Length - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = Length; + Request->Header.u1.s1.DataLength = Length - sizeof(PORT_MESSAGE); } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrWriteConsoleOutput) { - SHORT i, X, Y, SizeX, SizeY; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - SMALL_RECT ScreenBuffer; - CHAR_INFO* CurCharInfo; - SMALL_RECT WriteRegion; - CHAR_INFO* CharInfo; - COORD BufferCoord; - COORD BufferSize; - NTSTATUS Status; - PBYTE Ptr; - DWORD PSize; + SHORT i, X, Y, SizeX, SizeY; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + SMALL_RECT ScreenBuffer; + CHAR_INFO* CurCharInfo; + SMALL_RECT WriteRegion; + CHAR_INFO* CharInfo; + COORD BufferCoord; + COORD BufferSize; + NTSTATUS Status; + PBYTE Ptr; + DWORD PSize; - DPRINT("CsrWriteConsoleOutput\n"); + DPRINT("CsrWriteConsoleOutput\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, - Request->Data.WriteConsoleOutputRequest.ConsoleHandle, - &Buff, - GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = ConioLockScreenBuffer(ProcessData, + Request->Data.WriteConsoleOutputRequest.ConsoleHandle, + &Buff, + GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - BufferSize = Request->Data.WriteConsoleOutputRequest.BufferSize; - PSize = BufferSize.X * BufferSize.Y * sizeof(CHAR_INFO); - BufferCoord = Request->Data.WriteConsoleOutputRequest.BufferCoord; - CharInfo = Request->Data.WriteConsoleOutputRequest.CharInfo; - if (((PVOID)CharInfo < ProcessData->CsrSectionViewBase) || - (((ULONG_PTR)CharInfo + PSize) > - ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) + BufferSize = Request->Data.WriteConsoleOutputRequest.BufferSize; + PSize = BufferSize.X * BufferSize.Y * sizeof(CHAR_INFO); + BufferCoord = Request->Data.WriteConsoleOutputRequest.BufferCoord; + CharInfo = Request->Data.WriteConsoleOutputRequest.CharInfo; + if (((PVOID)CharInfo < ProcessData->CsrSectionViewBase) || + (((ULONG_PTR)CharInfo + PSize) > + ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) { - ConioUnlockScreenBuffer(Buff); - return STATUS_ACCESS_VIOLATION; + ConioUnlockScreenBuffer(Buff); + return STATUS_ACCESS_VIOLATION; } - WriteRegion = Request->Data.WriteConsoleOutputRequest.WriteRegion; + WriteRegion = Request->Data.WriteConsoleOutputRequest.WriteRegion; - SizeY = min(BufferSize.Y - BufferCoord.Y, ConioRectHeight(&WriteRegion)); - SizeX = min(BufferSize.X - BufferCoord.X, ConioRectWidth(&WriteRegion)); - WriteRegion.Bottom = WriteRegion.Top + SizeY - 1; - WriteRegion.Right = WriteRegion.Left + SizeX - 1; + SizeY = min(BufferSize.Y - BufferCoord.Y, ConioRectHeight(&WriteRegion)); + SizeX = min(BufferSize.X - BufferCoord.X, ConioRectWidth(&WriteRegion)); + WriteRegion.Bottom = WriteRegion.Top + SizeY - 1; + WriteRegion.Right = WriteRegion.Left + SizeX - 1; - /* Make sure WriteRegion is inside the screen buffer */ - ConioInitRect(&ScreenBuffer, 0, 0, Buff->MaxY - 1, Buff->MaxX - 1); - if (! ConioGetIntersection(&WriteRegion, &ScreenBuffer, &WriteRegion)) + /* Make sure WriteRegion is inside the screen buffer */ + ConioInitRect(&ScreenBuffer, 0, 0, Buff->MaxY - 1, Buff->MaxX - 1); + if (! ConioGetIntersection(&WriteRegion, &ScreenBuffer, &WriteRegion)) { - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - /* It is okay to have a WriteRegion completely outside the screen buffer. - No data is written then. */ - return STATUS_SUCCESS; + /* It is okay to have a WriteRegion completely outside the screen buffer. + No data is written then. */ + return STATUS_SUCCESS; } - for (i = 0, Y = WriteRegion.Top; Y <= WriteRegion.Bottom; i++, Y++) + for (i = 0, Y = WriteRegion.Top; Y <= WriteRegion.Bottom; i++, Y++) { - CurCharInfo = CharInfo + (i + BufferCoord.Y) * BufferSize.X + BufferCoord.X; - Ptr = ConioCoordToPointer(Buff, WriteRegion.Left, Y); - for (X = WriteRegion.Left; X <= WriteRegion.Right; X++) + CurCharInfo = CharInfo + (i + BufferCoord.Y) * BufferSize.X + BufferCoord.X; + Ptr = ConioCoordToPointer(Buff, WriteRegion.Left, Y); + for (X = WriteRegion.Left; X <= WriteRegion.Right; X++) { - CHAR AsciiChar; - if (Request->Data.WriteConsoleOutputRequest.Unicode) + CHAR AsciiChar; + if (Request->Data.WriteConsoleOutputRequest.Unicode) { - ConsoleUnicodeCharToAnsiChar(Console, &AsciiChar, &CurCharInfo->Char.UnicodeChar); + ConsoleUnicodeCharToAnsiChar(Console, &AsciiChar, &CurCharInfo->Char.UnicodeChar); } - else + else { - AsciiChar = CurCharInfo->Char.AsciiChar; + AsciiChar = CurCharInfo->Char.AsciiChar; } - *Ptr++ = AsciiChar; - *Ptr++ = CurCharInfo->Attributes; - CurCharInfo++; + *Ptr++ = AsciiChar; + *Ptr++ = CurCharInfo->Attributes; + CurCharInfo++; } } - ConioDrawRegion(Console, &WriteRegion); + ConioDrawRegion(Console, &WriteRegion); - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - Request->Data.WriteConsoleOutputRequest.WriteRegion.Right = WriteRegion.Left + SizeX - 1; - Request->Data.WriteConsoleOutputRequest.WriteRegion.Bottom = WriteRegion.Top + SizeY - 1; - Request->Data.WriteConsoleOutputRequest.WriteRegion.Left = WriteRegion.Left; - Request->Data.WriteConsoleOutputRequest.WriteRegion.Top = WriteRegion.Top; + Request->Data.WriteConsoleOutputRequest.WriteRegion.Right = WriteRegion.Left + SizeX - 1; + Request->Data.WriteConsoleOutputRequest.WriteRegion.Bottom = WriteRegion.Top + SizeY - 1; + Request->Data.WriteConsoleOutputRequest.WriteRegion.Left = WriteRegion.Left; + Request->Data.WriteConsoleOutputRequest.WriteRegion.Top = WriteRegion.Top; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrFlushInputBuffer) { - PLIST_ENTRY CurrentEntry; - PCSRSS_CONSOLE Console; - ConsoleInput* Input; - NTSTATUS Status; + PLIST_ENTRY CurrentEntry; + PCSRSS_CONSOLE Console; + ConsoleInput* Input; + NTSTATUS Status; - DPRINT("CsrFlushInputBuffer\n"); + DPRINT("CsrFlushInputBuffer\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockConsole(ProcessData, - Request->Data.FlushInputBufferRequest.ConsoleInput, - &Console, - GENERIC_WRITE); - if(! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = ConioLockConsole(ProcessData, + Request->Data.FlushInputBufferRequest.ConsoleInput, + &Console, + GENERIC_WRITE); + if(! NT_SUCCESS(Status)) { - return Status; + return Status; } - /* Discard all entries in the input event queue */ - while (!IsListEmpty(&Console->InputEvents)) + /* Discard all entries in the input event queue */ + while (!IsListEmpty(&Console->InputEvents)) { - CurrentEntry = RemoveHeadList(&Console->InputEvents); - Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry); - /* Destroy the event */ - HeapFree(Win32CsrApiHeap, 0, Input); + CurrentEntry = RemoveHeadList(&Console->InputEvents); + Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry); + /* Destroy the event */ + HeapFree(Win32CsrApiHeap, 0, Input); } - ResetEvent(Console->ActiveEvent); - Console->WaitingChars=0; + ResetEvent(Console->ActiveEvent); + Console->WaitingChars=0; - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrScrollConsoleScreenBuffer) { - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - SMALL_RECT ScreenBuffer; - SMALL_RECT SrcRegion; - SMALL_RECT DstRegion; - SMALL_RECT UpdateRegion; - SMALL_RECT ScrollRectangle; - SMALL_RECT ClipRectangle; - NTSTATUS Status; - HANDLE ConsoleHandle; - BOOLEAN UseClipRectangle; - COORD DestinationOrigin; - CHAR_INFO Fill; - CHAR FillChar; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + SMALL_RECT ScreenBuffer; + SMALL_RECT SrcRegion; + SMALL_RECT DstRegion; + SMALL_RECT UpdateRegion; + SMALL_RECT ScrollRectangle; + SMALL_RECT ClipRectangle; + NTSTATUS Status; + HANDLE ConsoleHandle; + BOOLEAN UseClipRectangle; + COORD DestinationOrigin; + CHAR_INFO Fill; + CHAR FillChar; - DPRINT("CsrScrollConsoleScreenBuffer\n"); + DPRINT("CsrScrollConsoleScreenBuffer\n"); - ConsoleHandle = Request->Data.ScrollConsoleScreenBufferRequest.ConsoleHandle; - UseClipRectangle = Request->Data.ScrollConsoleScreenBufferRequest.UseClipRectangle; - DestinationOrigin = Request->Data.ScrollConsoleScreenBufferRequest.DestinationOrigin; - Fill = Request->Data.ScrollConsoleScreenBufferRequest.Fill; + ConsoleHandle = Request->Data.ScrollConsoleScreenBufferRequest.ConsoleHandle; + UseClipRectangle = Request->Data.ScrollConsoleScreenBufferRequest.UseClipRectangle; + DestinationOrigin = Request->Data.ScrollConsoleScreenBufferRequest.DestinationOrigin; + Fill = Request->Data.ScrollConsoleScreenBufferRequest.Fill; - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, ConsoleHandle, &Buff, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Status = ConioLockScreenBuffer(ProcessData, ConsoleHandle, &Buff, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - ScrollRectangle = Request->Data.ScrollConsoleScreenBufferRequest.ScrollRectangle; + ScrollRectangle = Request->Data.ScrollConsoleScreenBufferRequest.ScrollRectangle; - /* Make sure source rectangle is inside the screen buffer */ - ConioInitRect(&ScreenBuffer, 0, 0, Buff->MaxY - 1, Buff->MaxX - 1); - if (! ConioGetIntersection(&SrcRegion, &ScreenBuffer, &ScrollRectangle)) + /* Make sure source rectangle is inside the screen buffer */ + ConioInitRect(&ScreenBuffer, 0, 0, Buff->MaxY - 1, Buff->MaxX - 1); + if (! ConioGetIntersection(&SrcRegion, &ScreenBuffer, &ScrollRectangle)) { - ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + ConioUnlockScreenBuffer(Buff); + return STATUS_SUCCESS; } - /* If the source was clipped on the left or top, adjust the destination accordingly */ - if (ScrollRectangle.Left < 0) + /* If the source was clipped on the left or top, adjust the destination accordingly */ + if (ScrollRectangle.Left < 0) { - DestinationOrigin.X -= ScrollRectangle.Left; + DestinationOrigin.X -= ScrollRectangle.Left; } - if (ScrollRectangle.Top < 0) + if (ScrollRectangle.Top < 0) { - DestinationOrigin.Y -= ScrollRectangle.Top; + DestinationOrigin.Y -= ScrollRectangle.Top; } - if (UseClipRectangle) + if (UseClipRectangle) { - ClipRectangle = Request->Data.ScrollConsoleScreenBufferRequest.ClipRectangle; - if (!ConioGetIntersection(&ClipRectangle, &ClipRectangle, &ScreenBuffer)) + ClipRectangle = Request->Data.ScrollConsoleScreenBufferRequest.ClipRectangle; + if (!ConioGetIntersection(&ClipRectangle, &ClipRectangle, &ScreenBuffer)) { - ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; - } + ConioUnlockScreenBuffer(Buff); + return STATUS_SUCCESS; + } } - else + else { - ClipRectangle = ScreenBuffer; + ClipRectangle = ScreenBuffer; } - ConioInitRect(&DstRegion, - DestinationOrigin.Y, - DestinationOrigin.X, - DestinationOrigin.Y + ConioRectHeight(&SrcRegion) - 1, - DestinationOrigin.X + ConioRectWidth(&SrcRegion) - 1); + ConioInitRect(&DstRegion, + DestinationOrigin.Y, + DestinationOrigin.X, + DestinationOrigin.Y + ConioRectHeight(&SrcRegion) - 1, + DestinationOrigin.X + ConioRectWidth(&SrcRegion) - 1); - if (Request->Data.ScrollConsoleScreenBufferRequest.Unicode) - ConsoleUnicodeCharToAnsiChar(Console, &FillChar, &Fill.Char.UnicodeChar); - else - FillChar = Fill.Char.AsciiChar; + if (Request->Data.ScrollConsoleScreenBufferRequest.Unicode) + ConsoleUnicodeCharToAnsiChar(Console, &FillChar, &Fill.Char.UnicodeChar); + else + FillChar = Fill.Char.AsciiChar; - ConioMoveRegion(Buff, &SrcRegion, &DstRegion, &ClipRectangle, Fill.Attributes << 8 | (BYTE)FillChar); + ConioMoveRegion(Buff, &SrcRegion, &DstRegion, &ClipRectangle, Fill.Attributes << 8 | (BYTE)FillChar); - if (Buff == Console->ActiveBuffer) + if (Buff == Console->ActiveBuffer) { - ConioGetUnion(&UpdateRegion, &SrcRegion, &DstRegion); - if (ConioGetIntersection(&UpdateRegion, &UpdateRegion, &ClipRectangle)) + ConioGetUnion(&UpdateRegion, &SrcRegion, &DstRegion); + if (ConioGetIntersection(&UpdateRegion, &UpdateRegion, &ClipRectangle)) { - /* Draw update region */ - ConioDrawRegion(Console, &UpdateRegion); + /* Draw update region */ + ConioDrawRegion(Console, &UpdateRegion); } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrReadConsoleOutputChar) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - DWORD Xpos, Ypos; - PCHAR ReadBuffer; - DWORD i; - ULONG CharSize; - CHAR Char; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + DWORD Xpos, Ypos; + PCHAR ReadBuffer; + DWORD i; + ULONG CharSize; + CHAR Char; - DPRINT("CsrReadConsoleOutputChar\n"); + DPRINT("CsrReadConsoleOutputChar\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); - ReadBuffer = Request->Data.ReadConsoleOutputCharRequest.String; + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); + ReadBuffer = Request->Data.ReadConsoleOutputCharRequest.String; - CharSize = (Request->Data.ReadConsoleOutputCharRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); + CharSize = (Request->Data.ReadConsoleOutputCharRequest.Unicode ? sizeof(WCHAR) : sizeof(CHAR)); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputCharRequest.ConsoleHandle, &Buff, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputCharRequest.ConsoleHandle, &Buff, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Console = Buff->Header.Console; + Console = Buff->Header.Console; - Xpos = Request->Data.ReadConsoleOutputCharRequest.ReadCoord.X; - Ypos = (Request->Data.ReadConsoleOutputCharRequest.ReadCoord.Y + Buff->VirtualY) % Buff->MaxY; + Xpos = Request->Data.ReadConsoleOutputCharRequest.ReadCoord.X; + Ypos = (Request->Data.ReadConsoleOutputCharRequest.ReadCoord.Y + Buff->VirtualY) % Buff->MaxY; - for (i = 0; i < Request->Data.ReadConsoleOutputCharRequest.NumCharsToRead; ++i) + for (i = 0; i < Request->Data.ReadConsoleOutputCharRequest.NumCharsToRead; ++i) { - Char = Buff->Buffer[(Xpos * 2) + (Ypos * 2 * Buff->MaxX)]; + Char = Buff->Buffer[(Xpos * 2) + (Ypos * 2 * Buff->MaxX)]; - if(Request->Data.ReadConsoleOutputCharRequest.Unicode) - { - ConsoleAnsiCharToUnicodeChar(Console, (WCHAR*)ReadBuffer, &Char); - ReadBuffer += sizeof(WCHAR); - } - else - *(ReadBuffer++) = Char; - - Xpos++; - - if (Xpos == Buff->MaxX) + if(Request->Data.ReadConsoleOutputCharRequest.Unicode) { - Xpos = 0; - Ypos++; + ConsoleAnsiCharToUnicodeChar(Console, (WCHAR*)ReadBuffer, &Char); + ReadBuffer += sizeof(WCHAR); + } + else + *(ReadBuffer++) = Char; - if (Ypos == Buff->MaxY) + Xpos++; + + if (Xpos == Buff->MaxX) + { + Xpos = 0; + Ypos++; + + if (Ypos == Buff->MaxY) { - Ypos = 0; + Ypos = 0; } } } - *ReadBuffer = 0; - Request->Data.ReadConsoleOutputCharRequest.EndCoord.X = Xpos; - Request->Data.ReadConsoleOutputCharRequest.EndCoord.Y = (Ypos - Buff->VirtualY + Buff->MaxY) % Buff->MaxY; + *ReadBuffer = 0; + Request->Data.ReadConsoleOutputCharRequest.EndCoord.X = Xpos; + Request->Data.ReadConsoleOutputCharRequest.EndCoord.Y = (Ypos - Buff->VirtualY + Buff->MaxY) % Buff->MaxY; - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - Request->Data.ReadConsoleOutputCharRequest.CharsRead = (DWORD)((ULONG_PTR)ReadBuffer - (ULONG_PTR)Request->Data.ReadConsoleOutputCharRequest.String) / CharSize; - if (Request->Data.ReadConsoleOutputCharRequest.CharsRead * CharSize + CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR) > sizeof(CSR_API_MESSAGE)) + Request->Data.ReadConsoleOutputCharRequest.CharsRead = (DWORD)((ULONG_PTR)ReadBuffer - (ULONG_PTR)Request->Data.ReadConsoleOutputCharRequest.String) / CharSize; + if (Request->Data.ReadConsoleOutputCharRequest.CharsRead * CharSize + CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR) > sizeof(CSR_API_MESSAGE)) { - Request->Header.u1.s1.TotalLength = Request->Data.ReadConsoleOutputCharRequest.CharsRead * CharSize + CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR); - Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = Request->Data.ReadConsoleOutputCharRequest.CharsRead * CharSize + CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR); + Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrReadConsoleOutputAttrib) { - NTSTATUS Status; - PCSRSS_SCREEN_BUFFER Buff; - DWORD Xpos, Ypos; - PWORD ReadBuffer; - DWORD i; - DWORD CurrentLength; + NTSTATUS Status; + PCSRSS_SCREEN_BUFFER Buff; + DWORD Xpos, Ypos; + PWORD ReadBuffer; + DWORD i; + DWORD CurrentLength; - DPRINT("CsrReadConsoleOutputAttrib\n"); + DPRINT("CsrReadConsoleOutputAttrib\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); - ReadBuffer = Request->Data.ReadConsoleOutputAttribRequest.Attribute; + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); + ReadBuffer = Request->Data.ReadConsoleOutputAttribRequest.Attribute; - Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputAttribRequest.ConsoleHandle, &Buff, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputAttribRequest.ConsoleHandle, &Buff, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Xpos = Request->Data.ReadConsoleOutputAttribRequest.ReadCoord.X; - Ypos = (Request->Data.ReadConsoleOutputAttribRequest.ReadCoord.Y + Buff->VirtualY) % Buff->MaxY; + Xpos = Request->Data.ReadConsoleOutputAttribRequest.ReadCoord.X; + Ypos = (Request->Data.ReadConsoleOutputAttribRequest.ReadCoord.Y + Buff->VirtualY) % Buff->MaxY; - for (i = 0; i < Request->Data.ReadConsoleOutputAttribRequest.NumAttrsToRead; ++i) + for (i = 0; i < Request->Data.ReadConsoleOutputAttribRequest.NumAttrsToRead; ++i) { - *ReadBuffer = Buff->Buffer[(Xpos * 2) + (Ypos * 2 * Buff->MaxX) + 1]; + *ReadBuffer = Buff->Buffer[(Xpos * 2) + (Ypos * 2 * Buff->MaxX) + 1]; - ReadBuffer++; - Xpos++; + ReadBuffer++; + Xpos++; - if (Xpos == Buff->MaxX) + if (Xpos == Buff->MaxX) { - Xpos = 0; - Ypos++; + Xpos = 0; + Ypos++; - if (Ypos == Buff->MaxY) + if (Ypos == Buff->MaxY) { - Ypos = 0; + Ypos = 0; } } } - *ReadBuffer = 0; + *ReadBuffer = 0; - Request->Data.ReadConsoleOutputAttribRequest.EndCoord.X = Xpos; - Request->Data.ReadConsoleOutputAttribRequest.EndCoord.Y = (Ypos - Buff->VirtualY + Buff->MaxY) % Buff->MaxY; + Request->Data.ReadConsoleOutputAttribRequest.EndCoord.X = Xpos; + Request->Data.ReadConsoleOutputAttribRequest.EndCoord.Y = (Ypos - Buff->VirtualY + Buff->MaxY) % Buff->MaxY; - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - CurrentLength = CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB) - + Request->Data.ReadConsoleOutputAttribRequest.NumAttrsToRead * sizeof(WORD); - if (CurrentLength > sizeof(CSR_API_MESSAGE)) + CurrentLength = CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB) + + Request->Data.ReadConsoleOutputAttribRequest.NumAttrsToRead * sizeof(WORD); + if (CurrentLength > sizeof(CSR_API_MESSAGE)) { - Request->Header.u1.s1.TotalLength = CurrentLength; - Request->Header.u1.s1.DataLength = CurrentLength - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = CurrentLength; + Request->Header.u1.s1.DataLength = CurrentLength - sizeof(PORT_MESSAGE); } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrGetNumberOfConsoleInputEvents) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - PLIST_ENTRY CurrentItem; - DWORD NumEvents; - ConsoleInput *Input; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + PLIST_ENTRY CurrentItem; + DWORD NumEvents; + ConsoleInput *Input; - DPRINT("CsrGetNumberOfConsoleInputEvents\n"); + DPRINT("CsrGetNumberOfConsoleInputEvents\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = Request->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE); - Status = ConioLockConsole(ProcessData, Request->Data.GetNumInputEventsRequest.ConsoleHandle, &Console, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockConsole(ProcessData, Request->Data.GetNumInputEventsRequest.ConsoleHandle, &Console, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - CurrentItem = Console->InputEvents.Flink; - NumEvents = 0; + CurrentItem = Console->InputEvents.Flink; + NumEvents = 0; - /* If there are any events ... */ - while (CurrentItem != &Console->InputEvents) + /* If there are any events ... */ + while (CurrentItem != &Console->InputEvents) { - Input = CONTAINING_RECORD(CurrentItem, ConsoleInput, ListEntry); - CurrentItem = CurrentItem->Flink; - if (!Input->Fake) + Input = CONTAINING_RECORD(CurrentItem, ConsoleInput, ListEntry); + CurrentItem = CurrentItem->Flink; + if (!Input->Fake) { - NumEvents++; + NumEvents++; } } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - Request->Data.GetNumInputEventsRequest.NumInputEvents = NumEvents; + Request->Data.GetNumInputEventsRequest.NumInputEvents = NumEvents; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrPeekConsoleInput) { - NTSTATUS Status; - PCSRSS_CONSOLE Console; - DWORD Size; - DWORD Length; - PLIST_ENTRY CurrentItem; - PINPUT_RECORD InputRecord; - ConsoleInput* Item; - UINT NumItems; + NTSTATUS Status; + PCSRSS_CONSOLE Console; + DWORD Size; + DWORD Length; + PLIST_ENTRY CurrentItem; + PINPUT_RECORD InputRecord; + ConsoleInput* Item; + UINT NumItems; - DPRINT("CsrPeekConsoleInput\n"); + DPRINT("CsrPeekConsoleInput\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockConsole(ProcessData, Request->Data.GetNumInputEventsRequest.ConsoleHandle, &Console, GENERIC_READ); - if(! NT_SUCCESS(Status)) + Status = ConioLockConsole(ProcessData, Request->Data.GetNumInputEventsRequest.ConsoleHandle, &Console, GENERIC_READ); + if(! NT_SUCCESS(Status)) { - return Status; + return Status; } - InputRecord = Request->Data.PeekConsoleInputRequest.InputRecord; - Length = Request->Data.PeekConsoleInputRequest.Length; - Size = Length * sizeof(INPUT_RECORD); + InputRecord = Request->Data.PeekConsoleInputRequest.InputRecord; + Length = Request->Data.PeekConsoleInputRequest.Length; + Size = Length * sizeof(INPUT_RECORD); - if (((PVOID)InputRecord < ProcessData->CsrSectionViewBase) - || (((ULONG_PTR)InputRecord + Size) > ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) + if (((PVOID)InputRecord < ProcessData->CsrSectionViewBase) + || (((ULONG_PTR)InputRecord + Size) > ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) { - ConioUnlockConsole(Console); - return STATUS_ACCESS_VIOLATION; + ConioUnlockConsole(Console); + return STATUS_ACCESS_VIOLATION; } - NumItems = 0; + NumItems = 0; - if (! IsListEmpty(&Console->InputEvents)) + if (! IsListEmpty(&Console->InputEvents)) { - CurrentItem = Console->InputEvents.Flink; + CurrentItem = Console->InputEvents.Flink; - while (CurrentItem != &Console->InputEvents && NumItems < Length) + while (CurrentItem != &Console->InputEvents && NumItems < Length) { - Item = CONTAINING_RECORD(CurrentItem, ConsoleInput, ListEntry); + Item = CONTAINING_RECORD(CurrentItem, ConsoleInput, ListEntry); - if (Item->Fake) + if (Item->Fake) { - CurrentItem = CurrentItem->Flink; - continue; + CurrentItem = CurrentItem->Flink; + continue; } - ++NumItems; - *InputRecord = Item->InputEvent; + ++NumItems; + *InputRecord = Item->InputEvent; - if (Request->Data.ReadInputRequest.Unicode == FALSE) + if (Request->Data.ReadInputRequest.Unicode == FALSE) { - ConioInputEventToAnsi(Console, InputRecord); + ConioInputEventToAnsi(Console, InputRecord); } - InputRecord++; - CurrentItem = CurrentItem->Flink; + InputRecord++; + CurrentItem = CurrentItem->Flink; } } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - Request->Data.PeekConsoleInputRequest.Length = NumItems; + Request->Data.PeekConsoleInputRequest.Length = NumItems; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrReadConsoleOutput) { - PCHAR_INFO CharInfo; - PCHAR_INFO CurCharInfo; - PCSRSS_SCREEN_BUFFER Buff; - DWORD Size; - DWORD Length; - DWORD SizeX, SizeY; - NTSTATUS Status; - COORD BufferSize; - COORD BufferCoord; - SMALL_RECT ReadRegion; - SMALL_RECT ScreenRect; - DWORD i; - PBYTE Ptr; - LONG X, Y; - UINT CodePage; + PCHAR_INFO CharInfo; + PCHAR_INFO CurCharInfo; + PCSRSS_SCREEN_BUFFER Buff; + DWORD Size; + DWORD Length; + DWORD SizeX, SizeY; + NTSTATUS Status; + COORD BufferSize; + COORD BufferCoord; + SMALL_RECT ReadRegion; + SMALL_RECT ScreenRect; + DWORD i; + PBYTE Ptr; + LONG X, Y; + UINT CodePage; - DPRINT("CsrReadConsoleOutput\n"); + DPRINT("CsrReadConsoleOutput\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputRequest.ConsoleHandle, &Buff, GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockScreenBuffer(ProcessData, Request->Data.ReadConsoleOutputRequest.ConsoleHandle, &Buff, GENERIC_READ); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - CharInfo = Request->Data.ReadConsoleOutputRequest.CharInfo; - ReadRegion = Request->Data.ReadConsoleOutputRequest.ReadRegion; - BufferSize = Request->Data.ReadConsoleOutputRequest.BufferSize; - BufferCoord = Request->Data.ReadConsoleOutputRequest.BufferCoord; - Length = BufferSize.X * BufferSize.Y; - Size = Length * sizeof(CHAR_INFO); + CharInfo = Request->Data.ReadConsoleOutputRequest.CharInfo; + ReadRegion = Request->Data.ReadConsoleOutputRequest.ReadRegion; + BufferSize = Request->Data.ReadConsoleOutputRequest.BufferSize; + BufferCoord = Request->Data.ReadConsoleOutputRequest.BufferCoord; + Length = BufferSize.X * BufferSize.Y; + Size = Length * sizeof(CHAR_INFO); - /* FIXME: Is this correct? */ - CodePage = ProcessData->Console->OutputCodePage; + /* FIXME: Is this correct? */ + CodePage = ProcessData->Console->OutputCodePage; - if (((PVOID)CharInfo < ProcessData->CsrSectionViewBase) - || (((ULONG_PTR)CharInfo + Size) > ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) + if (((PVOID)CharInfo < ProcessData->CsrSectionViewBase) + || (((ULONG_PTR)CharInfo + Size) > ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) { - ConioUnlockScreenBuffer(Buff); - return STATUS_ACCESS_VIOLATION; + ConioUnlockScreenBuffer(Buff); + return STATUS_ACCESS_VIOLATION; } - SizeY = min(BufferSize.Y - BufferCoord.Y, ConioRectHeight(&ReadRegion)); - SizeX = min(BufferSize.X - BufferCoord.X, ConioRectWidth(&ReadRegion)); - ReadRegion.Bottom = ReadRegion.Top + SizeY; - ReadRegion.Right = ReadRegion.Left + SizeX; + SizeY = min(BufferSize.Y - BufferCoord.Y, ConioRectHeight(&ReadRegion)); + SizeX = min(BufferSize.X - BufferCoord.X, ConioRectWidth(&ReadRegion)); + ReadRegion.Bottom = ReadRegion.Top + SizeY; + ReadRegion.Right = ReadRegion.Left + SizeX; - ConioInitRect(&ScreenRect, 0, 0, Buff->MaxY, Buff->MaxX); - if (! ConioGetIntersection(&ReadRegion, &ScreenRect, &ReadRegion)) + ConioInitRect(&ScreenRect, 0, 0, Buff->MaxY, Buff->MaxX); + if (! ConioGetIntersection(&ReadRegion, &ScreenRect, &ReadRegion)) { - ConioUnlockScreenBuffer(Buff); - return STATUS_SUCCESS; + ConioUnlockScreenBuffer(Buff); + return STATUS_SUCCESS; } - for (i = 0, Y = ReadRegion.Top; Y < ReadRegion.Bottom; ++i, ++Y) + for (i = 0, Y = ReadRegion.Top; Y < ReadRegion.Bottom; ++i, ++Y) { - CurCharInfo = CharInfo + (i * BufferSize.X); + CurCharInfo = CharInfo + (i * BufferSize.X); - Ptr = ConioCoordToPointer(Buff, ReadRegion.Left, Y); - for (X = ReadRegion.Left; X < ReadRegion.Right; ++X) + Ptr = ConioCoordToPointer(Buff, ReadRegion.Left, Y); + for (X = ReadRegion.Left; X < ReadRegion.Right; ++X) { - if (Request->Data.ReadConsoleOutputRequest.Unicode) + if (Request->Data.ReadConsoleOutputRequest.Unicode) { - MultiByteToWideChar(CodePage, 0, - (PCHAR)Ptr++, 1, - &CurCharInfo->Char.UnicodeChar, 1); + MultiByteToWideChar(CodePage, 0, + (PCHAR)Ptr++, 1, + &CurCharInfo->Char.UnicodeChar, 1); } - else + else { - CurCharInfo->Char.AsciiChar = *Ptr++; + CurCharInfo->Char.AsciiChar = *Ptr++; } - CurCharInfo->Attributes = *Ptr++; - ++CurCharInfo; + CurCharInfo->Attributes = *Ptr++; + ++CurCharInfo; } } - ConioUnlockScreenBuffer(Buff); + ConioUnlockScreenBuffer(Buff); - Request->Data.ReadConsoleOutputRequest.ReadRegion.Right = ReadRegion.Left + SizeX - 1; - Request->Data.ReadConsoleOutputRequest.ReadRegion.Bottom = ReadRegion.Top + SizeY - 1; - Request->Data.ReadConsoleOutputRequest.ReadRegion.Left = ReadRegion.Left; - Request->Data.ReadConsoleOutputRequest.ReadRegion.Top = ReadRegion.Top; + Request->Data.ReadConsoleOutputRequest.ReadRegion.Right = ReadRegion.Left + SizeX - 1; + Request->Data.ReadConsoleOutputRequest.ReadRegion.Bottom = ReadRegion.Top + SizeY - 1; + Request->Data.ReadConsoleOutputRequest.ReadRegion.Left = ReadRegion.Left; + Request->Data.ReadConsoleOutputRequest.ReadRegion.Top = ReadRegion.Top; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrWriteConsoleInput) { - PINPUT_RECORD InputRecord; - PCSRSS_CONSOLE Console; - NTSTATUS Status; - DWORD Length; - DWORD Size; - DWORD i; - ConsoleInput* Record; + PINPUT_RECORD InputRecord; + PCSRSS_CONSOLE Console; + NTSTATUS Status; + DWORD Length; + DWORD Size; + DWORD i; + ConsoleInput* Record; - DPRINT("CsrWriteConsoleInput\n"); + DPRINT("CsrWriteConsoleInput\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockConsole(ProcessData, Request->Data.WriteConsoleInputRequest.ConsoleHandle, &Console, GENERIC_WRITE); - if (! NT_SUCCESS(Status)) + Status = ConioLockConsole(ProcessData, Request->Data.WriteConsoleInputRequest.ConsoleHandle, &Console, GENERIC_WRITE); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - InputRecord = Request->Data.WriteConsoleInputRequest.InputRecord; - Length = Request->Data.WriteConsoleInputRequest.Length; - Size = Length * sizeof(INPUT_RECORD); + InputRecord = Request->Data.WriteConsoleInputRequest.InputRecord; + Length = Request->Data.WriteConsoleInputRequest.Length; + Size = Length * sizeof(INPUT_RECORD); - if (((PVOID)InputRecord < ProcessData->CsrSectionViewBase) - || (((ULONG_PTR)InputRecord + Size) > ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) + if (((PVOID)InputRecord < ProcessData->CsrSectionViewBase) + || (((ULONG_PTR)InputRecord + Size) > ((ULONG_PTR)ProcessData->CsrSectionViewBase + ProcessData->CsrSectionViewSize))) { - ConioUnlockConsole(Console); - return STATUS_ACCESS_VIOLATION; + ConioUnlockConsole(Console); + return STATUS_ACCESS_VIOLATION; } - for (i = 0; i < Length; i++) + for (i = 0; i < Length; i++) { - Record = HeapAlloc(Win32CsrApiHeap, 0, sizeof(ConsoleInput)); - if (NULL == Record) + Record = HeapAlloc(Win32CsrApiHeap, 0, sizeof(ConsoleInput)); + if (NULL == Record) { - ConioUnlockConsole(Console); - return STATUS_INSUFFICIENT_RESOURCES; + ConioUnlockConsole(Console); + return STATUS_INSUFFICIENT_RESOURCES; } - Record->Echoed = FALSE; - Record->Fake = FALSE; - //Record->InputEvent = *InputRecord++; - memcpy(&Record->InputEvent, &InputRecord[i], sizeof(INPUT_RECORD)); - if (KEY_EVENT == Record->InputEvent.EventType) + Record->Echoed = FALSE; + Record->Fake = FALSE; + //Record->InputEvent = *InputRecord++; + memcpy(&Record->InputEvent, &InputRecord[i], sizeof(INPUT_RECORD)); + if (KEY_EVENT == Record->InputEvent.EventType) { - /* FIXME - convert from unicode to ascii!! */ - ConioProcessChar(Console, Record); + /* FIXME - convert from unicode to ascii!! */ + ConioProcessChar(Console, Record); } } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - Request->Data.WriteConsoleInputRequest.Length = i; + Request->Data.WriteConsoleInputRequest.Length = i; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } /********************************************************************** @@ -2807,285 +2808,285 @@ CSR_API(CsrWriteConsoleInput) static NTSTATUS FASTCALL SetConsoleHardwareState (PCSRSS_CONSOLE Console, DWORD ConsoleHwState) { - DPRINT1("Console Hardware State: %d\n", ConsoleHwState); + DPRINT1("Console Hardware State: %d\n", ConsoleHwState); - if ((CONSOLE_HARDWARE_STATE_GDI_MANAGED == ConsoleHwState) - ||(CONSOLE_HARDWARE_STATE_DIRECT == ConsoleHwState)) + if ((CONSOLE_HARDWARE_STATE_GDI_MANAGED == ConsoleHwState) + ||(CONSOLE_HARDWARE_STATE_DIRECT == ConsoleHwState)) { - if (Console->HardwareState != ConsoleHwState) + if (Console->HardwareState != ConsoleHwState) { - /* TODO: implement switching from full screen to windowed mode */ - /* TODO: or back; now simply store the hardware state */ - Console->HardwareState = ConsoleHwState; + /* TODO: implement switching from full screen to windowed mode */ + /* TODO: or back; now simply store the hardware state */ + Console->HardwareState = ConsoleHwState; } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } - return STATUS_INVALID_PARAMETER_3; /* Client: (handle, set_get, [mode]) */ + return STATUS_INVALID_PARAMETER_3; /* Client: (handle, set_get, [mode]) */ } CSR_API(CsrHardwareStateProperty) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrHardwareStateProperty\n"); + DPRINT("CsrHardwareStateProperty\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioLockConsole(ProcessData, - Request->Data.ConsoleHardwareStateRequest.ConsoleHandle, - &Console, - GENERIC_READ); - if (! NT_SUCCESS(Status)) + Status = ConioLockConsole(ProcessData, + Request->Data.ConsoleHardwareStateRequest.ConsoleHandle, + &Console, + GENERIC_READ); + if (! NT_SUCCESS(Status)) { - DPRINT1("Failed to get console handle in SetConsoleHardwareState\n"); - return Status; + DPRINT1("Failed to get console handle in SetConsoleHardwareState\n"); + return Status; } - switch (Request->Data.ConsoleHardwareStateRequest.SetGet) + switch (Request->Data.ConsoleHardwareStateRequest.SetGet) { - case CONSOLE_HARDWARE_STATE_GET: + case CONSOLE_HARDWARE_STATE_GET: Request->Data.ConsoleHardwareStateRequest.State = Console->HardwareState; break; - case CONSOLE_HARDWARE_STATE_SET: + case CONSOLE_HARDWARE_STATE_SET: DPRINT("Setting console hardware state.\n"); Status = SetConsoleHardwareState(Console, Request->Data.ConsoleHardwareStateRequest.State); break; - default: + default: Status = STATUS_INVALID_PARAMETER_2; /* Client: (handle, [set_get], mode) */ break; } - ConioUnlockConsole(Console); + ConioUnlockConsole(Console); - return Status; + return Status; } CSR_API(CsrGetConsoleWindow) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrGetConsoleWindow\n"); + DPRINT("CsrGetConsoleWindow\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Data.GetConsoleWindowRequest.WindowHandle = Console->hWindow; - ConioUnlockConsole(Console); + Request->Data.GetConsoleWindowRequest.WindowHandle = Console->hWindow; + ConioUnlockConsole(Console); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetConsoleIcon) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrSetConsoleIcon\n"); + DPRINT("CsrSetConsoleIcon\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Status = (ConioChangeIcon(Console, Request->Data.SetConsoleIconRequest.WindowIcon) - ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL); - ConioUnlockConsole(Console); + Status = (ConioChangeIcon(Console, Request->Data.SetConsoleIconRequest.WindowIcon) + ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL); + ConioUnlockConsole(Console); - return Status; + return Status; } CSR_API(CsrGetConsoleCodePage) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrGetConsoleCodePage\n"); + DPRINT("CsrGetConsoleCodePage\n"); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Request->Data.GetConsoleCodePage.CodePage = Console->CodePage; - ConioUnlockConsole(Console); - return STATUS_SUCCESS; + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Data.GetConsoleCodePage.CodePage = Console->CodePage; + ConioUnlockConsole(Console); + return STATUS_SUCCESS; } CSR_API(CsrSetConsoleCodePage) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrSetConsoleCodePage\n"); + DPRINT("CsrSetConsoleCodePage\n"); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - if (IsValidCodePage(Request->Data.SetConsoleCodePage.CodePage)) + if (IsValidCodePage(Request->Data.SetConsoleCodePage.CodePage)) { - Console->CodePage = Request->Data.SetConsoleCodePage.CodePage; - ConioUnlockConsole(Console); - return STATUS_SUCCESS; + Console->CodePage = Request->Data.SetConsoleCodePage.CodePage; + ConioUnlockConsole(Console); + return STATUS_SUCCESS; } - ConioUnlockConsole(Console); - return STATUS_INVALID_PARAMETER; + ConioUnlockConsole(Console); + return STATUS_INVALID_PARAMETER; } CSR_API(CsrGetConsoleOutputCodePage) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrGetConsoleOutputCodePage\n"); + DPRINT("CsrGetConsoleOutputCodePage\n"); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Request->Data.GetConsoleOutputCodePage.CodePage = Console->OutputCodePage; - ConioUnlockConsole(Console); - return STATUS_SUCCESS; + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Data.GetConsoleOutputCodePage.CodePage = Console->OutputCodePage; + ConioUnlockConsole(Console); + return STATUS_SUCCESS; } CSR_API(CsrSetConsoleOutputCodePage) { - PCSRSS_CONSOLE Console; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + NTSTATUS Status; - DPRINT("CsrSetConsoleOutputCodePage\n"); + DPRINT("CsrSetConsoleOutputCodePage\n"); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - return Status; + return Status; } - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - if (IsValidCodePage(Request->Data.SetConsoleOutputCodePage.CodePage)) + if (IsValidCodePage(Request->Data.SetConsoleOutputCodePage.CodePage)) { - Console->OutputCodePage = Request->Data.SetConsoleOutputCodePage.CodePage; - ConioUnlockConsole(Console); - return STATUS_SUCCESS; + Console->OutputCodePage = Request->Data.SetConsoleOutputCodePage.CodePage; + ConioUnlockConsole(Console); + return STATUS_SUCCESS; } - ConioUnlockConsole(Console); - return STATUS_INVALID_PARAMETER; + ConioUnlockConsole(Console); + return STATUS_INVALID_PARAMETER; } CSR_API(CsrGetProcessList) { - PDWORD Buffer; - PCSRSS_CONSOLE Console; - PCSRSS_PROCESS_DATA current; - PLIST_ENTRY current_entry; - ULONG nItems = 0; - NTSTATUS Status; - ULONG_PTR Offset; + PDWORD Buffer; + PCSRSS_CONSOLE Console; + PCSRSS_PROCESS_DATA current; + PLIST_ENTRY current_entry; + ULONG nItems = 0; + NTSTATUS Status; + ULONG_PTR Offset; - DPRINT("CsrGetProcessList\n"); + DPRINT("CsrGetProcessList\n"); - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Buffer = Request->Data.GetProcessListRequest.ProcessId; - Offset = (PBYTE)Buffer - (PBYTE)ProcessData->CsrSectionViewBase; - if (Offset >= ProcessData->CsrSectionViewSize - || (Request->Data.GetProcessListRequest.nMaxIds * sizeof(DWORD)) > (ProcessData->CsrSectionViewSize - Offset) - || Offset & (sizeof(DWORD) - 1)) - { - return STATUS_ACCESS_VIOLATION; - } - - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) - { - return Status; - } - - for(current_entry = Console->ProcessList.Flink; - current_entry != &Console->ProcessList; - current_entry = current_entry->Flink) - { - current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); - if(++nItems <= Request->Data.GetProcessListRequest.nMaxIds) + Buffer = Request->Data.GetProcessListRequest.ProcessId; + Offset = (PBYTE)Buffer - (PBYTE)ProcessData->CsrSectionViewBase; + if (Offset >= ProcessData->CsrSectionViewSize + || (Request->Data.GetProcessListRequest.nMaxIds * sizeof(DWORD)) > (ProcessData->CsrSectionViewSize - Offset) + || Offset & (sizeof(DWORD) - 1)) { - *Buffer++ = (DWORD)current->ProcessId; + return STATUS_ACCESS_VIOLATION; } - } - ConioUnlockConsole(Console); + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) + { + return Status; + } - Request->Data.GetProcessListRequest.nProcessIdsTotal = nItems; - return STATUS_SUCCESS; + for (current_entry = Console->ProcessList.Flink; + current_entry != &Console->ProcessList; + current_entry = current_entry->Flink) + { + current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); + if (++nItems <= Request->Data.GetProcessListRequest.nMaxIds) + { + *Buffer++ = (DWORD)current->ProcessId; + } + } + + ConioUnlockConsole(Console); + + Request->Data.GetProcessListRequest.nProcessIdsTotal = nItems; + return STATUS_SUCCESS; } CSR_API(CsrGenerateCtrlEvent) { - PCSRSS_CONSOLE Console; - PCSRSS_PROCESS_DATA current; - PLIST_ENTRY current_entry; - DWORD Group; - NTSTATUS Status; + PCSRSS_CONSOLE Console; + PCSRSS_PROCESS_DATA current; + PLIST_ENTRY current_entry; + DWORD Group; + NTSTATUS Status; - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - Status = ConioConsoleFromProcessData(ProcessData, &Console); - if (! NT_SUCCESS(Status)) - { - return Status; - } - - Group = Request->Data.GenerateCtrlEvent.ProcessGroup; - Status = STATUS_INVALID_PARAMETER; - for (current_entry = Console->ProcessList.Flink; - current_entry != &Console->ProcessList; - current_entry = current_entry->Flink) - { - current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); - if (Group == 0 || current->ProcessGroup == Group) + Status = ConioConsoleFromProcessData(ProcessData, &Console); + if (! NT_SUCCESS(Status)) { - ConioConsoleCtrlEvent(Request->Data.GenerateCtrlEvent.Event, current); - Status = STATUS_SUCCESS; + return Status; } - } - ConioUnlockConsole(Console); + Group = Request->Data.GenerateCtrlEvent.ProcessGroup; + Status = STATUS_INVALID_PARAMETER; + for (current_entry = Console->ProcessList.Flink; + current_entry != &Console->ProcessList; + current_entry = current_entry->Flink) + { + current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); + if (Group == 0 || current->ProcessGroup == Group) + { + ConioConsoleCtrlEvent(Request->Data.GenerateCtrlEvent.Event, current); + Status = STATUS_SUCCESS; + } + } - return Status; + ConioUnlockConsole(Console); + + return Status; } CSR_API(CsrSetScreenBufferSize) diff --git a/reactos/subsystems/win32/csrss/win32csr/desktopbg.c b/reactos/subsystems/win32/csrss/win32csr/desktopbg.c index 7221f323df9..1853ab6cc21 100644 --- a/reactos/subsystems/win32/csrss/win32csr/desktopbg.c +++ b/reactos/subsystems/win32/csrss/win32csr/desktopbg.c @@ -49,71 +49,71 @@ DtbgWindowProc(HWND Wnd, switch (Msg) { - case WM_ERASEBKGND: - PaintDesktop((HDC)wParam); - return 1; + case WM_ERASEBKGND: + PaintDesktop((HDC)wParam); + return 1; - case WM_PAINT: - if (BeginPaint(Wnd, &PS)) - EndPaint(Wnd, &PS); - return 0; + case WM_PAINT: + if (BeginPaint(Wnd, &PS)) + EndPaint(Wnd, &PS); + return 0; - case WM_SETCURSOR: - return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW)); + case WM_SETCURSOR: + return (LRESULT)SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW)); - case WM_NCCREATE: - return (LRESULT)TRUE; + case WM_NCCREATE: + return (LRESULT)TRUE; - case WM_CREATE: - case WM_CLOSE: - return 0; + case WM_CREATE: + case WM_CLOSE: + return 0; - case WM_NOTIFY: + case WM_NOTIFY: + { + PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam; + + /* Use WM_NOTIFY for private messages since + * it can't be sent between processes! + */ + switch (nmh->hdr.code) { - PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam; + case PM_SHOW_DESKTOP: + { + LRESULT Result; - /* Use WM_NOTIFY for private messages since - * it can't be sent between processes! - */ - switch (nmh->hdr.code) - { - case PM_SHOW_DESKTOP: - { - LRESULT Result; + Result = !SetWindowPos(Wnd, NULL, 0, 0, + nmh->ShowDesktop.Width, + nmh->ShowDesktop.Height, + SWP_NOACTIVATE | SWP_NOZORDER | + SWP_SHOWWINDOW); - Result = !SetWindowPos(Wnd, NULL, 0, 0, - nmh->ShowDesktop.Width, - nmh->ShowDesktop.Height, - SWP_NOACTIVATE | SWP_NOZORDER | - SWP_SHOWWINDOW); + UpdateWindow(Wnd); + VisibleDesktopWindow = Wnd; + return Result; + } - UpdateWindow(Wnd); - VisibleDesktopWindow = Wnd; - return Result; - } + case PM_HIDE_DESKTOP: + { + LRESULT Result; - case PM_HIDE_DESKTOP: - { - LRESULT Result; + Result = !SetWindowPos(Wnd, NULL, 0, 0, 0, 0, + SWP_NOACTIVATE | SWP_NOZORDER | + SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); - Result = !SetWindowPos(Wnd, NULL, 0, 0, 0, 0, - SWP_NOACTIVATE | SWP_NOZORDER | - SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); - - UpdateWindow(Wnd); - VisibleDesktopWindow = NULL; - return Result; - } - - default: - DPRINT("Unknown notification code 0x%x sent to the desktop window!\n", - nmh->hdr.code); - return 0; - } + UpdateWindow(Wnd); + VisibleDesktopWindow = NULL; + return Result; } default: - return DefWindowProcW(Wnd, Msg, wParam, lParam); + DPRINT("Unknown notification code 0x%x sent to the desktop window!\n", + nmh->hdr.code); + return 0; + } + } + + default: + return DefWindowProcW(Wnd, Msg, wParam, lParam); } return 0; @@ -309,7 +309,7 @@ FASTCALL DtbgIsDesktopVisible(VOID) { if (VisibleDesktopWindow != NULL && - !IsWindowVisible(VisibleDesktopWindow)) + !IsWindowVisible(VisibleDesktopWindow)) { VisibleDesktopWindow = NULL; } diff --git a/reactos/subsystems/win32/csrss/win32csr/dllmain.c b/reactos/subsystems/win32/csrss/win32csr/dllmain.c index 2e8947f014a..7d8b7e2aaf8 100644 --- a/reactos/subsystems/win32/csrss/win32csr/dllmain.c +++ b/reactos/subsystems/win32/csrss/win32csr/dllmain.c @@ -23,7 +23,7 @@ HINSTANCE Win32CsrDllHandle = NULL; static CSRSS_EXPORTED_FUNCS CsrExports; static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] = - { +{ CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetHandle), CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetHandle), CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle), @@ -83,37 +83,37 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] = CSRSS_DEFINE_API(SET_SCREEN_BUFFER_SIZE, CsrSetScreenBufferSize), CSRSS_DEFINE_API(GET_CONSOLE_SELECTION_INFO, CsrGetConsoleSelectionInfo), { 0, 0, NULL } - }; +}; /* FUNCTIONS *****************************************************************/ BOOL WINAPI DllMain(HANDLE hDll, - DWORD dwReason, - LPVOID lpReserved) + DWORD dwReason, + LPVOID lpReserved) { - if (DLL_PROCESS_ATTACH == dwReason) + if (DLL_PROCESS_ATTACH == dwReason) { - Win32CsrDllHandle = hDll; - InitializeAppSwitchHook(); + Win32CsrDllHandle = hDll; + InitializeAppSwitchHook(); } - return TRUE; + return TRUE; } NTSTATUS FASTCALL Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc, PVOID Context) { - return (CsrExports.CsrEnumProcessesProc)(EnumProc, Context); + return (CsrExports.CsrEnumProcessesProc)(EnumProc, Context); } static BOOL WINAPI Win32CsrInitComplete(void) { - PrivateCsrssInitialized(); + PrivateCsrssInitialized(); - return TRUE; + return TRUE; } BOOL WINAPI @@ -122,22 +122,22 @@ Win32CsrInitialization(PCSRSS_API_DEFINITION *ApiDefinitions, PCSRSS_EXPORTED_FUNCS Exports, HANDLE CsrssApiHeap) { - NTSTATUS Status; - CsrExports = *Exports; - Win32CsrApiHeap = CsrssApiHeap; + NTSTATUS Status; + CsrExports = *Exports; + Win32CsrApiHeap = CsrssApiHeap; - Status = NtUserInitialize(0 ,NULL, NULL); + Status = NtUserInitialize(0, NULL, NULL); - PrivateCsrssManualGuiCheck(0); - CsrInitConsoleSupport(); + PrivateCsrssManualGuiCheck(0); + CsrInitConsoleSupport(); - *ApiDefinitions = Win32CsrApiDefinitions; - ServerProcs->InitCompleteProc = Win32CsrInitComplete; - ServerProcs->HardErrorProc = Win32CsrHardError; - ServerProcs->ProcessInheritProc = Win32CsrDuplicateHandleTable; - ServerProcs->ProcessDeletedProc = Win32CsrReleaseConsole; + *ApiDefinitions = Win32CsrApiDefinitions; + ServerProcs->InitCompleteProc = Win32CsrInitComplete; + ServerProcs->HardErrorProc = Win32CsrHardError; + ServerProcs->ProcessInheritProc = Win32CsrDuplicateHandleTable; + ServerProcs->ProcessDeletedProc = Win32CsrReleaseConsole; - return TRUE; + return TRUE; } /* EOF */ diff --git a/reactos/subsystems/win32/csrss/win32csr/exitros.c b/reactos/subsystems/win32/csrss/win32csr/exitros.c index ca9fecbc188..984b44a86a3 100644 --- a/reactos/subsystems/win32/csrss/win32csr/exitros.c +++ b/reactos/subsystems/win32/csrss/win32csr/exitros.c @@ -18,61 +18,61 @@ static HANDLE LogonProcess = NULL; CSR_API(CsrRegisterLogonProcess) { - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE); - if (Request->Data.RegisterLogonProcessRequest.Register) + if (Request->Data.RegisterLogonProcessRequest.Register) { - if (0 != LogonProcess) + if (0 != LogonProcess) { - return STATUS_LOGON_SESSION_EXISTS; + return STATUS_LOGON_SESSION_EXISTS; } - LogonProcess = Request->Data.RegisterLogonProcessRequest.ProcessId; + LogonProcess = Request->Data.RegisterLogonProcessRequest.ProcessId; } - else + else { - if (Request->Header.ClientId.UniqueProcess != LogonProcess) + if (Request->Header.ClientId.UniqueProcess != LogonProcess) { - DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n", - LogonProcess, Request->Header.ClientId.UniqueProcess); - return STATUS_NOT_LOGON_PROCESS; + DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n", + LogonProcess, Request->Header.ClientId.UniqueProcess); + return STATUS_NOT_LOGON_PROCESS; } - LogonProcess = 0; + LogonProcess = 0; } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } CSR_API(CsrSetLogonNotifyWindow) { - DWORD WindowCreator; + DWORD WindowCreator; - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - + sizeof(PORT_MESSAGE); - if (0 == GetWindowThreadProcessId(Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow, - &WindowCreator)) + if (0 == GetWindowThreadProcessId(Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow, + &WindowCreator)) { - DPRINT1("Can't get window creator\n"); - return STATUS_INVALID_HANDLE; + DPRINT1("Can't get window creator\n"); + return STATUS_INVALID_HANDLE; } - if (WindowCreator != (DWORD_PTR)LogonProcess) + if (WindowCreator != (DWORD_PTR)LogonProcess) { - DPRINT1("Trying to register window not created by winlogon as notify window\n"); - return STATUS_ACCESS_DENIED; + DPRINT1("Trying to register window not created by winlogon as notify window\n"); + return STATUS_ACCESS_DENIED; } - LogonNotifyWindow = Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow; + LogonNotifyWindow = Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } typedef struct tagSHUTDOWN_SETTINGS { - BOOL AutoEndTasks; - DWORD HungAppTimeout; - DWORD WaitToKillAppTimeout; + BOOL AutoEndTasks; + DWORD HungAppTimeout; + DWORD WaitToKillAppTimeout; } SHUTDOWN_SETTINGS, *PSHUTDOWN_SETTINGS; #define DEFAULT_AUTO_END_TASKS FALSE @@ -81,20 +81,20 @@ typedef struct tagSHUTDOWN_SETTINGS typedef struct tagNOTIFY_CONTEXT { - DWORD ProcessId; - UINT Msg; - WPARAM wParam; - LPARAM lParam; - HDESK Desktop; - DWORD StartTime; - DWORD QueryResult; - HWND Dlg; - DWORD EndNowResult; - BOOL ShowUI; - HANDLE UIThread; - HWND WndClient; - PSHUTDOWN_SETTINGS ShutdownSettings; - LPTHREAD_START_ROUTINE SendMessageProc; + DWORD ProcessId; + UINT Msg; + WPARAM wParam; + LPARAM lParam; + HDESK Desktop; + DWORD StartTime; + DWORD QueryResult; + HWND Dlg; + DWORD EndNowResult; + BOOL ShowUI; + HANDLE UIThread; + HWND WndClient; + PSHUTDOWN_SETTINGS ShutdownSettings; + LPTHREAD_START_ROUTINE SendMessageProc; } NOTIFY_CONTEXT, *PNOTIFY_CONTEXT; #define QUERY_RESULT_ABORT 0 @@ -106,30 +106,30 @@ typedef struct tagNOTIFY_CONTEXT static void FASTCALL UpdateProgressBar(HWND ProgressBar, PNOTIFY_CONTEXT NotifyContext) { - DWORD Passed; + DWORD Passed; - Passed = GetTickCount() - NotifyContext->StartTime; - Passed -= NotifyContext->ShutdownSettings->HungAppTimeout; - if (NotifyContext->ShutdownSettings->WaitToKillAppTimeout < Passed) + Passed = GetTickCount() - NotifyContext->StartTime; + Passed -= NotifyContext->ShutdownSettings->HungAppTimeout; + if (NotifyContext->ShutdownSettings->WaitToKillAppTimeout < Passed) { - Passed = NotifyContext->ShutdownSettings->WaitToKillAppTimeout; + Passed = NotifyContext->ShutdownSettings->WaitToKillAppTimeout; } - SendMessageW(ProgressBar, PBM_SETPOS, Passed / 2, 0); + SendMessageW(ProgressBar, PBM_SETPOS, Passed / 2, 0); } static INT_PTR CALLBACK EndNowDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam) { - INT_PTR Result; - PNOTIFY_CONTEXT NotifyContext; - HWND ProgressBar; - DWORD TitleLength; - int Len; - LPWSTR Title; + INT_PTR Result; + PNOTIFY_CONTEXT NotifyContext; + HWND ProgressBar; + DWORD TitleLength; + int Len; + LPWSTR Title; - switch(Msg) + switch(Msg) { - case WM_INITDIALOG: + case WM_INITDIALOG: NotifyContext = (PNOTIFY_CONTEXT) lParam; NotifyContext->EndNowResult = QUERY_RESULT_ABORT; SetWindowLongPtrW(Dlg, DWLP_USER, (LONG_PTR) lParam); @@ -138,13 +138,13 @@ EndNowDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam) GetWindowTextLengthW(Dlg); Title = HeapAlloc(Win32CsrApiHeap, 0, (TitleLength + 1) * sizeof(WCHAR)); if (NULL != Title) - { + { Len = GetWindowTextW(Dlg, Title, TitleLength + 1); SendMessageW(NotifyContext->WndClient, WM_GETTEXT, TitleLength + 1 - Len, (LPARAM) (Title + Len)); SetWindowTextW(Dlg, Title); HeapFree(Win32CsrApiHeap, 0, Title); - } + } ProgressBar = GetDlgItem(Dlg, IDC_PROGRESS); SendMessageW(ProgressBar, PBM_SETRANGE32, 0, NotifyContext->ShutdownSettings->WaitToKillAppTimeout / 2); @@ -153,33 +153,33 @@ EndNowDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam) Result = FALSE; break; - case WM_TIMER: + case WM_TIMER: NotifyContext = (PNOTIFY_CONTEXT) GetWindowLongPtrW(Dlg, DWLP_USER); ProgressBar = GetDlgItem(Dlg, IDC_PROGRESS); UpdateProgressBar(ProgressBar, NotifyContext); Result = TRUE; break; - case WM_COMMAND: + case WM_COMMAND: if (BN_CLICKED == HIWORD(wParam) && IDC_END_NOW == LOWORD(wParam)) - { + { NotifyContext = (PNOTIFY_CONTEXT) GetWindowLongPtrW(Dlg, DWLP_USER); NotifyContext->EndNowResult = QUERY_RESULT_FORCE; SendMessageW(Dlg, WM_CLOSE, 0, 0); Result = TRUE; - } + } else - { + { Result = FALSE; - } + } break; - case WM_CLOSE: + case WM_CLOSE: DestroyWindow(Dlg); Result = TRUE; break; - case WM_DESTROY: + case WM_DESTROY: NotifyContext = (PNOTIFY_CONTEXT) GetWindowLongPtrW(Dlg, DWLP_USER); NotifyContext->Dlg = NULL; KillTimer(Dlg, 0); @@ -187,12 +187,12 @@ EndNowDlgProc(HWND Dlg, UINT Msg, WPARAM wParam, LPARAM lParam) Result = TRUE; break; - default: + default: Result = FALSE; break; } - return Result; + return Result; } typedef void (WINAPI *INITCOMMONCONTROLS_PROC)(void); @@ -200,265 +200,265 @@ typedef void (WINAPI *INITCOMMONCONTROLS_PROC)(void); static void CallInitCommonControls() { - static BOOL Initialized = FALSE; - HMODULE Lib; - INITCOMMONCONTROLS_PROC InitProc; + static BOOL Initialized = FALSE; + HMODULE Lib; + INITCOMMONCONTROLS_PROC InitProc; - if (Initialized) + if (Initialized) { - return; + return; } - Lib = LoadLibraryW(L"COMCTL32.DLL"); - if (NULL == Lib) + Lib = LoadLibraryW(L"COMCTL32.DLL"); + if (NULL == Lib) { - return; + return; } - InitProc = (INITCOMMONCONTROLS_PROC) GetProcAddress(Lib, "InitCommonControls"); - if (NULL == InitProc) + InitProc = (INITCOMMONCONTROLS_PROC) GetProcAddress(Lib, "InitCommonControls"); + if (NULL == InitProc) { - return; + return; } - (*InitProc)(); + (*InitProc)(); - Initialized = TRUE; + Initialized = TRUE; } static DWORD WINAPI EndNowThreadProc(LPVOID Parameter) { - PNOTIFY_CONTEXT NotifyContext = (PNOTIFY_CONTEXT) Parameter; - MSG Msg; + PNOTIFY_CONTEXT NotifyContext = (PNOTIFY_CONTEXT) Parameter; + MSG Msg; - SetThreadDesktop(NotifyContext->Desktop); - SwitchDesktop(NotifyContext->Desktop); - CallInitCommonControls(); - NotifyContext->Dlg = CreateDialogParam(GetModuleHandleW(L"win32csr"), - MAKEINTRESOURCE(IDD_END_NOW), NULL, - EndNowDlgProc, (LPARAM) NotifyContext); - if (NULL == NotifyContext->Dlg) + SetThreadDesktop(NotifyContext->Desktop); + SwitchDesktop(NotifyContext->Desktop); + CallInitCommonControls(); + NotifyContext->Dlg = CreateDialogParam(GetModuleHandleW(L"win32csr"), + MAKEINTRESOURCE(IDD_END_NOW), NULL, + EndNowDlgProc, (LPARAM) NotifyContext); + if (NULL == NotifyContext->Dlg) { - return 0; + return 0; } - ShowWindow(NotifyContext->Dlg, SW_SHOWNORMAL); + ShowWindow(NotifyContext->Dlg, SW_SHOWNORMAL); - while (GetMessageW(&Msg, NULL, 0, 0)) + while (GetMessageW(&Msg, NULL, 0, 0)) { - if (! IsDialogMessage(NotifyContext->Dlg, &Msg)) + if (! IsDialogMessage(NotifyContext->Dlg, &Msg)) { - TranslateMessage(&Msg); - DispatchMessageW(&Msg); + TranslateMessage(&Msg); + DispatchMessageW(&Msg); } } - return Msg.wParam; + return Msg.wParam; } typedef struct tagMESSAGE_CONTEXT { - HWND Wnd; - UINT Msg; - WPARAM wParam; - LPARAM lParam; - DWORD Timeout; + HWND Wnd; + UINT Msg; + WPARAM wParam; + LPARAM lParam; + DWORD Timeout; } MESSAGE_CONTEXT, *PMESSAGE_CONTEXT; static DWORD WINAPI SendQueryEndSession(LPVOID Parameter) { - PMESSAGE_CONTEXT Context = (PMESSAGE_CONTEXT) Parameter; - DWORD_PTR Result; + PMESSAGE_CONTEXT Context = (PMESSAGE_CONTEXT) Parameter; + DWORD_PTR Result; - if (SendMessageTimeoutW(Context->Wnd, WM_QUERYENDSESSION, Context->wParam, - Context->lParam, SMTO_NORMAL, Context->Timeout, - &Result)) + if (SendMessageTimeoutW(Context->Wnd, WM_QUERYENDSESSION, Context->wParam, + Context->lParam, SMTO_NORMAL, Context->Timeout, + &Result)) { - return Result ? QUERY_RESULT_CONTINUE : QUERY_RESULT_ABORT; + return Result ? QUERY_RESULT_CONTINUE : QUERY_RESULT_ABORT; } - return 0 == GetLastError() ? QUERY_RESULT_TIMEOUT : QUERY_RESULT_ERROR; + return 0 == GetLastError() ? QUERY_RESULT_TIMEOUT : QUERY_RESULT_ERROR; } static DWORD WINAPI SendEndSession(LPVOID Parameter) { - PMESSAGE_CONTEXT Context = (PMESSAGE_CONTEXT) Parameter; - DWORD_PTR Result; + PMESSAGE_CONTEXT Context = (PMESSAGE_CONTEXT) Parameter; + DWORD_PTR Result; - if (Context->wParam) + if (Context->wParam) { - if (SendMessageTimeoutW(Context->Wnd, WM_ENDSESSION, Context->wParam, - Context->lParam, SMTO_NORMAL, Context->Timeout, - &Result)) + if (SendMessageTimeoutW(Context->Wnd, WM_ENDSESSION, Context->wParam, + Context->lParam, SMTO_NORMAL, Context->Timeout, + &Result)) { - return QUERY_RESULT_CONTINUE; + return QUERY_RESULT_CONTINUE; } - return 0 == GetLastError() ? QUERY_RESULT_TIMEOUT : QUERY_RESULT_ERROR; + return 0 == GetLastError() ? QUERY_RESULT_TIMEOUT : QUERY_RESULT_ERROR; } - else + else { - SendMessage(Context->Wnd, WM_ENDSESSION, Context->wParam, - Context->lParam); - return QUERY_RESULT_CONTINUE; + SendMessage(Context->Wnd, WM_ENDSESSION, Context->wParam, + Context->lParam); + return QUERY_RESULT_CONTINUE; } } static BOOL CALLBACK NotifyTopLevelEnum(HWND Wnd, LPARAM lParam) { - PNOTIFY_CONTEXT NotifyContext = (PNOTIFY_CONTEXT) lParam; - MESSAGE_CONTEXT MessageContext; - DWORD Now, Passed; - DWORD Timeout, WaitStatus; - DWORD ProcessId; - HANDLE MessageThread; - HANDLE Threads[2]; + PNOTIFY_CONTEXT NotifyContext = (PNOTIFY_CONTEXT) lParam; + MESSAGE_CONTEXT MessageContext; + DWORD Now, Passed; + DWORD Timeout, WaitStatus; + DWORD ProcessId; + HANDLE MessageThread; + HANDLE Threads[2]; - if (0 == GetWindowThreadProcessId(Wnd, &ProcessId)) + if (0 == GetWindowThreadProcessId(Wnd, &ProcessId)) { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; - return FALSE; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; + return FALSE; } - if (ProcessId == NotifyContext->ProcessId) + if (ProcessId == NotifyContext->ProcessId) { - Now = GetTickCount(); - if (0 == NotifyContext->StartTime) + Now = GetTickCount(); + if (0 == NotifyContext->StartTime) { - NotifyContext->StartTime = Now; + NotifyContext->StartTime = Now; } - /* Note: Passed is computed correctly even when GetTickCount() wraps due - to unsigned arithmetic */ - Passed = Now - NotifyContext->StartTime; - MessageContext.Wnd = Wnd; - MessageContext.Msg = NotifyContext->Msg; - MessageContext.wParam = NotifyContext->wParam; - MessageContext.lParam = NotifyContext->lParam; - MessageContext.Timeout = NotifyContext->ShutdownSettings->HungAppTimeout; - if (! NotifyContext->ShutdownSettings->AutoEndTasks) + /* Note: Passed is computed correctly even when GetTickCount() wraps due + to unsigned arithmetic */ + Passed = Now - NotifyContext->StartTime; + MessageContext.Wnd = Wnd; + MessageContext.Msg = NotifyContext->Msg; + MessageContext.wParam = NotifyContext->wParam; + MessageContext.lParam = NotifyContext->lParam; + MessageContext.Timeout = NotifyContext->ShutdownSettings->HungAppTimeout; + if (! NotifyContext->ShutdownSettings->AutoEndTasks) { - MessageContext.Timeout += NotifyContext->ShutdownSettings->WaitToKillAppTimeout; + MessageContext.Timeout += NotifyContext->ShutdownSettings->WaitToKillAppTimeout; } - if (Passed < MessageContext.Timeout) + if (Passed < MessageContext.Timeout) { - MessageContext.Timeout -= Passed; - MessageThread = CreateThread(NULL, 0, NotifyContext->SendMessageProc, - (LPVOID) &MessageContext, 0, NULL); - if (NULL == MessageThread) + MessageContext.Timeout -= Passed; + MessageThread = CreateThread(NULL, 0, NotifyContext->SendMessageProc, + (LPVOID) &MessageContext, 0, NULL); + if (NULL == MessageThread) { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; - return FALSE; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; + return FALSE; } - Timeout = NotifyContext->ShutdownSettings->HungAppTimeout; - if (Passed < Timeout) + Timeout = NotifyContext->ShutdownSettings->HungAppTimeout; + if (Passed < Timeout) { - Timeout -= Passed; - WaitStatus = WaitForSingleObjectEx(MessageThread, Timeout, FALSE); + Timeout -= Passed; + WaitStatus = WaitForSingleObjectEx(MessageThread, Timeout, FALSE); } - else + else { - WaitStatus = WAIT_TIMEOUT; + WaitStatus = WAIT_TIMEOUT; } - if (WAIT_TIMEOUT == WaitStatus) + if (WAIT_TIMEOUT == WaitStatus) { - NotifyContext->WndClient = Wnd; - if (NULL == NotifyContext->UIThread && NotifyContext->ShowUI) + NotifyContext->WndClient = Wnd; + if (NULL == NotifyContext->UIThread && NotifyContext->ShowUI) { - NotifyContext->UIThread = CreateThread(NULL, 0, - EndNowThreadProc, - (LPVOID) NotifyContext, - 0, NULL); + NotifyContext->UIThread = CreateThread(NULL, 0, + EndNowThreadProc, + (LPVOID) NotifyContext, + 0, NULL); } - Threads[0] = MessageThread; - Threads[1] = NotifyContext->UIThread; - WaitStatus = WaitForMultipleObjectsEx(NULL == NotifyContext->UIThread ? - 1 : 2, - Threads, FALSE, INFINITE, - FALSE); - if (WAIT_OBJECT_0 == WaitStatus) + Threads[0] = MessageThread; + Threads[1] = NotifyContext->UIThread; + WaitStatus = WaitForMultipleObjectsEx(NULL == NotifyContext->UIThread ? + 1 : 2, + Threads, FALSE, INFINITE, + FALSE); + if (WAIT_OBJECT_0 == WaitStatus) { - if (! GetExitCodeThread(MessageThread, &NotifyContext->QueryResult)) + if (! GetExitCodeThread(MessageThread, &NotifyContext->QueryResult)) { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; } } - else if (WAIT_OBJECT_0 + 1 == WaitStatus) + else if (WAIT_OBJECT_0 + 1 == WaitStatus) { - if (! GetExitCodeThread(NotifyContext->UIThread, - &NotifyContext->QueryResult)) + if (! GetExitCodeThread(NotifyContext->UIThread, + &NotifyContext->QueryResult)) { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; } } - else + else { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; } - if (WAIT_OBJECT_0 != WaitStatus) + if (WAIT_OBJECT_0 != WaitStatus) { - TerminateThread(MessageThread, QUERY_RESULT_TIMEOUT); + TerminateThread(MessageThread, QUERY_RESULT_TIMEOUT); } } - else if (WAIT_OBJECT_0 == WaitStatus) + else if (WAIT_OBJECT_0 == WaitStatus) { - if (! GetExitCodeThread(MessageThread, - &NotifyContext->QueryResult)) + if (! GetExitCodeThread(MessageThread, + &NotifyContext->QueryResult)) { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; } } - else + else { - NotifyContext->QueryResult = QUERY_RESULT_ERROR; + NotifyContext->QueryResult = QUERY_RESULT_ERROR; } - CloseHandle(MessageThread); + CloseHandle(MessageThread); } - else + else { - NotifyContext->QueryResult = QUERY_RESULT_TIMEOUT; + NotifyContext->QueryResult = QUERY_RESULT_TIMEOUT; } } - return QUERY_RESULT_CONTINUE == NotifyContext->QueryResult; + return QUERY_RESULT_CONTINUE == NotifyContext->QueryResult; } static BOOL CALLBACK NotifyDesktopEnum(LPWSTR DesktopName, LPARAM lParam) { - PNOTIFY_CONTEXT Context = (PNOTIFY_CONTEXT) lParam; + PNOTIFY_CONTEXT Context = (PNOTIFY_CONTEXT) lParam; - Context->Desktop = OpenDesktopW(DesktopName, 0, FALSE, - DESKTOP_ENUMERATE | DESKTOP_SWITCHDESKTOP); - if (NULL == Context->Desktop) + Context->Desktop = OpenDesktopW(DesktopName, 0, FALSE, + DESKTOP_ENUMERATE | DESKTOP_SWITCHDESKTOP); + if (NULL == Context->Desktop) { - DPRINT1("OpenDesktop failed with error %d\n", GetLastError()); - Context->QueryResult = QUERY_RESULT_ERROR; - return FALSE; + DPRINT1("OpenDesktop failed with error %d\n", GetLastError()); + Context->QueryResult = QUERY_RESULT_ERROR; + return FALSE; } - EnumDesktopWindows(Context->Desktop, NotifyTopLevelEnum, lParam); + EnumDesktopWindows(Context->Desktop, NotifyTopLevelEnum, lParam); - CloseDesktop(Context->Desktop); + CloseDesktop(Context->Desktop); - return QUERY_RESULT_CONTINUE == Context->QueryResult; + return QUERY_RESULT_CONTINUE == Context->QueryResult; } static BOOL FASTCALL NotifyTopLevelWindows(PNOTIFY_CONTEXT Context) { - HWINSTA WindowStation; + HWINSTA WindowStation; - WindowStation = GetProcessWindowStation(); - if (NULL == WindowStation) + WindowStation = GetProcessWindowStation(); + if (NULL == WindowStation) { - DPRINT1("GetProcessWindowStation failed with error %d\n", GetLastError()); - return TRUE; + DPRINT1("GetProcessWindowStation failed with error %d\n", GetLastError()); + return TRUE; } - EnumDesktopsW(WindowStation, NotifyDesktopEnum, (LPARAM) Context); + EnumDesktopsW(WindowStation, NotifyDesktopEnum, (LPARAM) Context); - return TRUE; + return TRUE; } static BOOL FASTCALL @@ -466,476 +466,476 @@ NotifyAndTerminateProcess(PCSRSS_PROCESS_DATA ProcessData, PSHUTDOWN_SETTINGS ShutdownSettings, UINT Flags) { - NOTIFY_CONTEXT Context; - HANDLE Process; - DWORD QueryResult = QUERY_RESULT_CONTINUE; + NOTIFY_CONTEXT Context; + HANDLE Process; + DWORD QueryResult = QUERY_RESULT_CONTINUE; - Context.QueryResult = QUERY_RESULT_CONTINUE; + Context.QueryResult = QUERY_RESULT_CONTINUE; - if (0 == (Flags & EWX_FORCE)) + if (0 == (Flags & EWX_FORCE)) { - if (NULL != ProcessData->Console) + if (NULL != ProcessData->Console) { - ConioConsoleCtrlEventTimeout(CTRL_LOGOFF_EVENT, ProcessData, - ShutdownSettings->WaitToKillAppTimeout); + ConioConsoleCtrlEventTimeout(CTRL_LOGOFF_EVENT, ProcessData, + ShutdownSettings->WaitToKillAppTimeout); } - else + else { - Context.ProcessId = (DWORD_PTR) ProcessData->ProcessId; - Context.wParam = 0; - Context.lParam = (0 != (Flags & EWX_INTERNAL_FLAG_LOGOFF) ? - ENDSESSION_LOGOFF : 0); - Context.StartTime = 0; - Context.UIThread = NULL; - Context.ShowUI = DtbgIsDesktopVisible(); - Context.Dlg = NULL; - Context.ShutdownSettings = ShutdownSettings; - Context.SendMessageProc = SendQueryEndSession; + Context.ProcessId = (DWORD_PTR) ProcessData->ProcessId; + Context.wParam = 0; + Context.lParam = (0 != (Flags & EWX_INTERNAL_FLAG_LOGOFF) ? + ENDSESSION_LOGOFF : 0); + Context.StartTime = 0; + Context.UIThread = NULL; + Context.ShowUI = DtbgIsDesktopVisible(); + Context.Dlg = NULL; + Context.ShutdownSettings = ShutdownSettings; + Context.SendMessageProc = SendQueryEndSession; - NotifyTopLevelWindows(&Context); + NotifyTopLevelWindows(&Context); - Context.wParam = (QUERY_RESULT_ABORT != Context.QueryResult); - Context.lParam = (0 != (Flags & EWX_INTERNAL_FLAG_LOGOFF) ? - ENDSESSION_LOGOFF : 0); - Context.SendMessageProc = SendEndSession; - Context.ShowUI = DtbgIsDesktopVisible() && - (QUERY_RESULT_ABORT != Context.QueryResult); - QueryResult = Context.QueryResult; - Context.QueryResult = QUERY_RESULT_CONTINUE; + Context.wParam = (QUERY_RESULT_ABORT != Context.QueryResult); + Context.lParam = (0 != (Flags & EWX_INTERNAL_FLAG_LOGOFF) ? + ENDSESSION_LOGOFF : 0); + Context.SendMessageProc = SendEndSession; + Context.ShowUI = DtbgIsDesktopVisible() && + (QUERY_RESULT_ABORT != Context.QueryResult); + QueryResult = Context.QueryResult; + Context.QueryResult = QUERY_RESULT_CONTINUE; - NotifyTopLevelWindows(&Context); + NotifyTopLevelWindows(&Context); - if (NULL != Context.UIThread) + if (NULL != Context.UIThread) { - if (NULL != Context.Dlg) + if (NULL != Context.Dlg) { - SendMessageW(Context.Dlg, WM_CLOSE, 0, 0); + SendMessageW(Context.Dlg, WM_CLOSE, 0, 0); } - else + else { - TerminateThread(Context.UIThread, QUERY_RESULT_ERROR); + TerminateThread(Context.UIThread, QUERY_RESULT_ERROR); } - CloseHandle(Context.UIThread); + CloseHandle(Context.UIThread); } } - if (QUERY_RESULT_ABORT == QueryResult) + if (QUERY_RESULT_ABORT == QueryResult) { - return FALSE; + return FALSE; } } - /* Terminate this process */ - Process = OpenProcess(PROCESS_TERMINATE, FALSE, - (DWORD_PTR) ProcessData->ProcessId); - if (NULL == Process) + /* Terminate this process */ + Process = OpenProcess(PROCESS_TERMINATE, FALSE, + (DWORD_PTR) ProcessData->ProcessId); + if (NULL == Process) { - DPRINT1("Unable to open process %d, error %d\n", ProcessData->ProcessId, - GetLastError()); - return TRUE; + DPRINT1("Unable to open process %d, error %d\n", ProcessData->ProcessId, + GetLastError()); + return TRUE; } - TerminateProcess(Process, 0); - CloseHandle(Process); + TerminateProcess(Process, 0); + CloseHandle(Process); - return TRUE; + return TRUE; } typedef struct tagPROCESS_ENUM_CONTEXT { - UINT ProcessCount; - PCSRSS_PROCESS_DATA *ProcessData; - TOKEN_ORIGIN TokenOrigin; - DWORD ShellProcess; - DWORD CsrssProcess; + UINT ProcessCount; + PCSRSS_PROCESS_DATA *ProcessData; + TOKEN_ORIGIN TokenOrigin; + DWORD ShellProcess; + DWORD CsrssProcess; } PROCESS_ENUM_CONTEXT, *PPROCESS_ENUM_CONTEXT; static NTSTATUS WINAPI ExitReactosProcessEnum(PCSRSS_PROCESS_DATA ProcessData, PVOID Data) { - HANDLE Process; - HANDLE Token; - TOKEN_ORIGIN Origin; - DWORD ReturnLength; - PPROCESS_ENUM_CONTEXT Context = (PPROCESS_ENUM_CONTEXT) Data; - PCSRSS_PROCESS_DATA *NewData; + HANDLE Process; + HANDLE Token; + TOKEN_ORIGIN Origin; + DWORD ReturnLength; + PPROCESS_ENUM_CONTEXT Context = (PPROCESS_ENUM_CONTEXT) Data; + PCSRSS_PROCESS_DATA *NewData; - /* Do not kill winlogon or csrss */ - if ((DWORD_PTR) ProcessData->ProcessId == Context->CsrssProcess || - ProcessData->ProcessId == LogonProcess) + /* Do not kill winlogon or csrss */ + if ((DWORD_PTR) ProcessData->ProcessId == Context->CsrssProcess || + ProcessData->ProcessId == LogonProcess) { - return STATUS_SUCCESS; + return STATUS_SUCCESS; } - /* Get the login session of this process */ - Process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, - (DWORD_PTR) ProcessData->ProcessId); - if (NULL == Process) + /* Get the login session of this process */ + Process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, + (DWORD_PTR) ProcessData->ProcessId); + if (NULL == Process) { - DPRINT1("Unable to open process %d, error %d\n", ProcessData->ProcessId, - GetLastError()); - return STATUS_UNSUCCESSFUL; + DPRINT1("Unable to open process %d, error %d\n", ProcessData->ProcessId, + GetLastError()); + return STATUS_UNSUCCESSFUL; } - if (! OpenProcessToken(Process, TOKEN_QUERY, &Token)) + if (! OpenProcessToken(Process, TOKEN_QUERY, &Token)) { - DPRINT1("Unable to open token for process %d, error %d\n", - ProcessData->ProcessId, GetLastError()); - CloseHandle(Process); - return STATUS_UNSUCCESSFUL; + DPRINT1("Unable to open token for process %d, error %d\n", + ProcessData->ProcessId, GetLastError()); + CloseHandle(Process); + return STATUS_UNSUCCESSFUL; } - CloseHandle(Process); + CloseHandle(Process); - if (! GetTokenInformation(Token, TokenOrigin, &Origin, - sizeof(TOKEN_ORIGIN), &ReturnLength)) + if (! GetTokenInformation(Token, TokenOrigin, &Origin, + sizeof(TOKEN_ORIGIN), &ReturnLength)) { - DPRINT1("GetTokenInformation failed for process %d with error %d\n", - ProcessData->ProcessId, GetLastError()); - CloseHandle(Token); - return STATUS_UNSUCCESSFUL; + DPRINT1("GetTokenInformation failed for process %d with error %d\n", + ProcessData->ProcessId, GetLastError()); + CloseHandle(Token); + return STATUS_UNSUCCESSFUL; } - CloseHandle(Token); + CloseHandle(Token); - /* This process will be killed if it's in the correct logon session */ - if (RtlEqualLuid(&(Context->TokenOrigin.OriginatingLogonSession), - &(Origin.OriginatingLogonSession))) + /* This process will be killed if it's in the correct logon session */ + if (RtlEqualLuid(&(Context->TokenOrigin.OriginatingLogonSession), + &(Origin.OriginatingLogonSession))) { - /* Kill the shell process last */ - if ((DWORD_PTR) ProcessData->ProcessId == Context->ShellProcess) + /* Kill the shell process last */ + if ((DWORD_PTR) ProcessData->ProcessId == Context->ShellProcess) { - ProcessData->ShutdownLevel = 0; + ProcessData->ShutdownLevel = 0; } - NewData = HeapAlloc(Win32CsrApiHeap, 0, (Context->ProcessCount + 1) - * sizeof(PCSRSS_PROCESS_DATA)); - if (NULL == NewData) + NewData = HeapAlloc(Win32CsrApiHeap, 0, (Context->ProcessCount + 1) + * sizeof(PCSRSS_PROCESS_DATA)); + if (NULL == NewData) { - return STATUS_NO_MEMORY; + return STATUS_NO_MEMORY; } - if (0 != Context->ProcessCount) + if (0 != Context->ProcessCount) { - memcpy(NewData, Context->ProcessData, - Context->ProcessCount * sizeof(PCSRSS_PROCESS_DATA)); - HeapFree(Win32CsrApiHeap, 0, Context->ProcessData); + memcpy(NewData, Context->ProcessData, + Context->ProcessCount * sizeof(PCSRSS_PROCESS_DATA)); + HeapFree(Win32CsrApiHeap, 0, Context->ProcessData); } - Context->ProcessData = NewData; - Context->ProcessData[Context->ProcessCount] = ProcessData; - Context->ProcessCount++; + Context->ProcessData = NewData; + Context->ProcessData[Context->ProcessCount] = ProcessData; + Context->ProcessCount++; } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static int ProcessDataCompare(const void *Elem1, const void *Elem2) { - const PCSRSS_PROCESS_DATA *ProcessData1 = (PCSRSS_PROCESS_DATA *) Elem1; - const PCSRSS_PROCESS_DATA *ProcessData2 = (PCSRSS_PROCESS_DATA *) Elem2; + const PCSRSS_PROCESS_DATA *ProcessData1 = (PCSRSS_PROCESS_DATA *) Elem1; + const PCSRSS_PROCESS_DATA *ProcessData2 = (PCSRSS_PROCESS_DATA *) Elem2; - if ((*ProcessData1)->ShutdownLevel < (*ProcessData2)->ShutdownLevel) + if ((*ProcessData1)->ShutdownLevel < (*ProcessData2)->ShutdownLevel) { - return +1; + return +1; } - else if ((*ProcessData2)->ShutdownLevel < (*ProcessData1)->ShutdownLevel) + else if ((*ProcessData2)->ShutdownLevel < (*ProcessData1)->ShutdownLevel) { - return -1; + return -1; } - else if ((*ProcessData1)->ProcessId < (*ProcessData2)->ProcessId) + else if ((*ProcessData1)->ProcessId < (*ProcessData2)->ProcessId) { - return +1; + return +1; } - else if ((*ProcessData2)->ProcessId < (*ProcessData1)->ProcessId) + else if ((*ProcessData2)->ProcessId < (*ProcessData1)->ProcessId) { - return -1; + return -1; } - return 0; + return 0; } static DWORD FASTCALL GetShutdownSetting(HKEY DesktopKey, LPCWSTR ValueName, DWORD DefaultValue) { - BYTE ValueBuffer[16]; - LONG ErrCode; - DWORD Type; - DWORD ValueSize; - UNICODE_STRING StringValue; - ULONG Value; + BYTE ValueBuffer[16]; + LONG ErrCode; + DWORD Type; + DWORD ValueSize; + UNICODE_STRING StringValue; + ULONG Value; - ValueSize = sizeof(ValueBuffer); - ErrCode = RegQueryValueExW(DesktopKey, ValueName, NULL, &Type, ValueBuffer, - &ValueSize); - if (ERROR_SUCCESS != ErrCode) + ValueSize = sizeof(ValueBuffer); + ErrCode = RegQueryValueExW(DesktopKey, ValueName, NULL, &Type, ValueBuffer, + &ValueSize); + if (ERROR_SUCCESS != ErrCode) { - DPRINT("GetShutdownSetting for %S failed with error code %ld\n", - ValueName, ErrCode); - return DefaultValue; + DPRINT("GetShutdownSetting for %S failed with error code %ld\n", + ValueName, ErrCode); + return DefaultValue; } - if (REG_SZ == Type) + if (REG_SZ == Type) { - RtlInitUnicodeString(&StringValue, (LPCWSTR) ValueBuffer); - if (! NT_SUCCESS(RtlUnicodeStringToInteger(&StringValue, 10, &Value))) + RtlInitUnicodeString(&StringValue, (LPCWSTR) ValueBuffer); + if (! NT_SUCCESS(RtlUnicodeStringToInteger(&StringValue, 10, &Value))) { - DPRINT1("Unable to convert value %S for setting %S\n", - StringValue.Buffer, ValueName); - return DefaultValue; + DPRINT1("Unable to convert value %S for setting %S\n", + StringValue.Buffer, ValueName); + return DefaultValue; } - return (DWORD) Value; + return (DWORD) Value; } - else if (REG_DWORD == Type) + else if (REG_DWORD == Type) { - return *((DWORD *) ValueBuffer); + return *((DWORD *) ValueBuffer); } - DPRINT1("Unexpected registry type %d for setting %S\n", Type, ValueName); - return DefaultValue; + DPRINT1("Unexpected registry type %d for setting %S\n", Type, ValueName); + return DefaultValue; } static void FASTCALL LoadShutdownSettings(PSID Sid, PSHUTDOWN_SETTINGS ShutdownSettings) { - static WCHAR Subkey[] = L"\\Control Panel\\Desktop"; - LPWSTR StringSid; - WCHAR InitialKeyName[128]; - LPWSTR KeyName; - HKEY DesktopKey; - LONG ErrCode; + static WCHAR Subkey[] = L"\\Control Panel\\Desktop"; + LPWSTR StringSid; + WCHAR InitialKeyName[128]; + LPWSTR KeyName; + HKEY DesktopKey; + LONG ErrCode; - ShutdownSettings->AutoEndTasks = DEFAULT_AUTO_END_TASKS; - ShutdownSettings->HungAppTimeout = DEFAULT_HUNG_APP_TIMEOUT; - ShutdownSettings->WaitToKillAppTimeout = DEFAULT_WAIT_TO_KILL_APP_TIMEOUT; + ShutdownSettings->AutoEndTasks = DEFAULT_AUTO_END_TASKS; + ShutdownSettings->HungAppTimeout = DEFAULT_HUNG_APP_TIMEOUT; + ShutdownSettings->WaitToKillAppTimeout = DEFAULT_WAIT_TO_KILL_APP_TIMEOUT; - if (! ConvertSidToStringSidW(Sid, &StringSid)) + if (! ConvertSidToStringSidW(Sid, &StringSid)) { - DPRINT1("ConvertSidToStringSid failed with error %d, using default shutdown settings\n", - GetLastError()); - return; + DPRINT1("ConvertSidToStringSid failed with error %d, using default shutdown settings\n", + GetLastError()); + return; } - if (wcslen(StringSid) + wcslen(Subkey) + 1 <= - sizeof(InitialKeyName) / sizeof(WCHAR)) + if (wcslen(StringSid) + wcslen(Subkey) + 1 <= + sizeof(InitialKeyName) / sizeof(WCHAR)) { - KeyName = InitialKeyName; + KeyName = InitialKeyName; } - else + else { - KeyName = HeapAlloc(Win32CsrApiHeap, 0, - (wcslen(StringSid) + wcslen(Subkey) + 1) * - sizeof(WCHAR)); - if (NULL == KeyName) + KeyName = HeapAlloc(Win32CsrApiHeap, 0, + (wcslen(StringSid) + wcslen(Subkey) + 1) * + sizeof(WCHAR)); + if (NULL == KeyName) { - DPRINT1("Failed to allocate memory, using default shutdown settings\n"); - LocalFree(StringSid); - return; + DPRINT1("Failed to allocate memory, using default shutdown settings\n"); + LocalFree(StringSid); + return; } } - wcscat(wcscpy(KeyName, StringSid), Subkey); - LocalFree(StringSid); + wcscat(wcscpy(KeyName, StringSid), Subkey); + LocalFree(StringSid); - ErrCode = RegOpenKeyExW(HKEY_USERS, KeyName, 0, KEY_QUERY_VALUE, &DesktopKey); - if (KeyName != InitialKeyName) + ErrCode = RegOpenKeyExW(HKEY_USERS, KeyName, 0, KEY_QUERY_VALUE, &DesktopKey); + if (KeyName != InitialKeyName) { - HeapFree(Win32CsrApiHeap, 0, KeyName); + HeapFree(Win32CsrApiHeap, 0, KeyName); } - if (ERROR_SUCCESS != ErrCode) + if (ERROR_SUCCESS != ErrCode) { - DPRINT1("RegOpenKeyEx failed with error %ld, using default shutdown settings\n", ErrCode); - return; + DPRINT1("RegOpenKeyEx failed with error %ld, using default shutdown settings\n", ErrCode); + return; } - ShutdownSettings->AutoEndTasks = (BOOL) GetShutdownSetting(DesktopKey, L"AutoEndTasks", - (DWORD) DEFAULT_AUTO_END_TASKS); - ShutdownSettings->HungAppTimeout = GetShutdownSetting(DesktopKey, - L"HungAppTimeout", - DEFAULT_HUNG_APP_TIMEOUT); - ShutdownSettings->WaitToKillAppTimeout = GetShutdownSetting(DesktopKey, - L"WaitToKillAppTimeout", - DEFAULT_WAIT_TO_KILL_APP_TIMEOUT); + ShutdownSettings->AutoEndTasks = (BOOL) GetShutdownSetting(DesktopKey, L"AutoEndTasks", + (DWORD) DEFAULT_AUTO_END_TASKS); + ShutdownSettings->HungAppTimeout = GetShutdownSetting(DesktopKey, + L"HungAppTimeout", + DEFAULT_HUNG_APP_TIMEOUT); + ShutdownSettings->WaitToKillAppTimeout = GetShutdownSetting(DesktopKey, + L"WaitToKillAppTimeout", + DEFAULT_WAIT_TO_KILL_APP_TIMEOUT); - RegCloseKey(DesktopKey); + RegCloseKey(DesktopKey); } static NTSTATUS FASTCALL InternalExitReactos(DWORD ProcessId, DWORD ThreadId, UINT Flags) { - HANDLE CallerThread; - HANDLE CallerToken; - NTSTATUS Status; - PROCESS_ENUM_CONTEXT Context; - DWORD ReturnLength; - HWND ShellWnd; - UINT ProcessIndex; - char FixedUserInfo[64]; - TOKEN_USER *UserInfo; - SHUTDOWN_SETTINGS ShutdownSettings; + HANDLE CallerThread; + HANDLE CallerToken; + NTSTATUS Status; + PROCESS_ENUM_CONTEXT Context; + DWORD ReturnLength; + HWND ShellWnd; + UINT ProcessIndex; + char FixedUserInfo[64]; + TOKEN_USER *UserInfo; + SHUTDOWN_SETTINGS ShutdownSettings; - if (ProcessId != (DWORD_PTR) LogonProcess) + if (ProcessId != (DWORD_PTR) LogonProcess) { - DPRINT1("Internal ExitWindowsEx call not from winlogon\n"); - return STATUS_ACCESS_DENIED; + DPRINT1("Internal ExitWindowsEx call not from winlogon\n"); + return STATUS_ACCESS_DENIED; } - DPRINT1("FIXME: Need to close all user processes!\n"); - return STATUS_SUCCESS; + DPRINT1("FIXME: Need to close all user processes!\n"); + return STATUS_SUCCESS; - CallerThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, ThreadId); - if (NULL == CallerThread) + CallerThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, ThreadId); + if (NULL == CallerThread) { - DPRINT1("OpenThread failed with error %d\n", GetLastError()); - return STATUS_UNSUCCESSFUL; + DPRINT1("OpenThread failed with error %d\n", GetLastError()); + return STATUS_UNSUCCESSFUL; } - if (! OpenThreadToken(CallerThread, TOKEN_QUERY, FALSE, &CallerToken)) + if (! OpenThreadToken(CallerThread, TOKEN_QUERY, FALSE, &CallerToken)) { - DPRINT1("OpenThreadToken failed with error %d\n", GetLastError()); - CloseHandle(CallerThread); - return STATUS_UNSUCCESSFUL; + DPRINT1("OpenThreadToken failed with error %d\n", GetLastError()); + CloseHandle(CallerThread); + return STATUS_UNSUCCESSFUL; } - CloseHandle(CallerThread); + CloseHandle(CallerThread); - Context.ProcessCount = 0; - Context.ProcessData = NULL; - if (! GetTokenInformation(CallerToken, TokenOrigin, &Context.TokenOrigin, - sizeof(TOKEN_ORIGIN), &ReturnLength)) + Context.ProcessCount = 0; + Context.ProcessData = NULL; + if (! GetTokenInformation(CallerToken, TokenOrigin, &Context.TokenOrigin, + sizeof(TOKEN_ORIGIN), &ReturnLength)) { - DPRINT1("GetTokenInformation failed with error %d\n", GetLastError()); - CloseHandle(CallerToken); - return STATUS_UNSUCCESSFUL; + DPRINT1("GetTokenInformation failed with error %d\n", GetLastError()); + CloseHandle(CallerToken); + return STATUS_UNSUCCESSFUL; } - if (! GetTokenInformation(CallerToken, TokenUser, FixedUserInfo, - sizeof(FixedUserInfo), &ReturnLength)) + if (! GetTokenInformation(CallerToken, TokenUser, FixedUserInfo, + sizeof(FixedUserInfo), &ReturnLength)) { - if (sizeof(FixedUserInfo) < ReturnLength) + if (sizeof(FixedUserInfo) < ReturnLength) { - UserInfo = HeapAlloc(Win32CsrApiHeap, 0, ReturnLength); - if (NULL == UserInfo) + UserInfo = HeapAlloc(Win32CsrApiHeap, 0, ReturnLength); + if (NULL == UserInfo) { - DPRINT1("Unable to allocate %u bytes for user info\n", - (unsigned) ReturnLength); - CloseHandle(CallerToken); - return STATUS_NO_MEMORY; + DPRINT1("Unable to allocate %u bytes for user info\n", + (unsigned) ReturnLength); + CloseHandle(CallerToken); + return STATUS_NO_MEMORY; } - if (! GetTokenInformation(CallerToken, TokenUser, UserInfo, - ReturnLength, &ReturnLength)) + if (! GetTokenInformation(CallerToken, TokenUser, UserInfo, + ReturnLength, &ReturnLength)) { - DPRINT1("GetTokenInformation failed with error %d\n", - GetLastError()); - HeapFree(Win32CsrApiHeap, 0, UserInfo); - CloseHandle(CallerToken); - return STATUS_UNSUCCESSFUL; + DPRINT1("GetTokenInformation failed with error %d\n", + GetLastError()); + HeapFree(Win32CsrApiHeap, 0, UserInfo); + CloseHandle(CallerToken); + return STATUS_UNSUCCESSFUL; } } - else + else { - DPRINT1("GetTokenInformation failed with error %d\n", GetLastError()); - CloseHandle(CallerToken); - return STATUS_UNSUCCESSFUL; + DPRINT1("GetTokenInformation failed with error %d\n", GetLastError()); + CloseHandle(CallerToken); + return STATUS_UNSUCCESSFUL; } } - else + else { - UserInfo = (TOKEN_USER *) FixedUserInfo; + UserInfo = (TOKEN_USER *) FixedUserInfo; } - CloseHandle(CallerToken); - LoadShutdownSettings(UserInfo->User.Sid, &ShutdownSettings); - if (UserInfo != (TOKEN_USER *) FixedUserInfo) + CloseHandle(CallerToken); + LoadShutdownSettings(UserInfo->User.Sid, &ShutdownSettings); + if (UserInfo != (TOKEN_USER *) FixedUserInfo) { - HeapFree(Win32CsrApiHeap, 0, UserInfo); + HeapFree(Win32CsrApiHeap, 0, UserInfo); } - Context.CsrssProcess = GetCurrentProcessId(); - ShellWnd = GetShellWindow(); - if (NULL == ShellWnd) + Context.CsrssProcess = GetCurrentProcessId(); + ShellWnd = GetShellWindow(); + if (NULL == ShellWnd) { - DPRINT("No shell present\n"); - Context.ShellProcess = 0; + DPRINT("No shell present\n"); + Context.ShellProcess = 0; } - else if (0 == GetWindowThreadProcessId(ShellWnd, &Context.ShellProcess)) + else if (0 == GetWindowThreadProcessId(ShellWnd, &Context.ShellProcess)) { - DPRINT1("Can't get process id of shell window\n"); - Context.ShellProcess = 0; + DPRINT1("Can't get process id of shell window\n"); + Context.ShellProcess = 0; } - Status = Win32CsrEnumProcesses(ExitReactosProcessEnum, &Context); - if (! NT_SUCCESS(Status)) + Status = Win32CsrEnumProcesses(ExitReactosProcessEnum, &Context); + if (! NT_SUCCESS(Status)) { - DPRINT1("Failed to enumerate registered processes, status 0x%x\n", - Status); - if (NULL != Context.ProcessData) + DPRINT1("Failed to enumerate registered processes, status 0x%x\n", + Status); + if (NULL != Context.ProcessData) { - HeapFree(Win32CsrApiHeap, 0, Context.ProcessData); + HeapFree(Win32CsrApiHeap, 0, Context.ProcessData); } - return Status; + return Status; } - qsort(Context.ProcessData, Context.ProcessCount, sizeof(PCSRSS_PROCESS_DATA), - ProcessDataCompare); + qsort(Context.ProcessData, Context.ProcessCount, sizeof(PCSRSS_PROCESS_DATA), + ProcessDataCompare); - /* Terminate processes, stop if we find one kicking and screaming it doesn't - want to die */ - Status = STATUS_SUCCESS; - for (ProcessIndex = 0; - ProcessIndex < Context.ProcessCount && NT_SUCCESS(Status); - ProcessIndex++) + /* Terminate processes, stop if we find one kicking and screaming it doesn't + want to die */ + Status = STATUS_SUCCESS; + for (ProcessIndex = 0; + ProcessIndex < Context.ProcessCount && NT_SUCCESS(Status); + ProcessIndex++) { - if (! NotifyAndTerminateProcess(Context.ProcessData[ProcessIndex], - &ShutdownSettings, Flags)) + if (! NotifyAndTerminateProcess(Context.ProcessData[ProcessIndex], + &ShutdownSettings, Flags)) { - Status = STATUS_REQUEST_ABORTED; + Status = STATUS_REQUEST_ABORTED; } } - /* Cleanup */ - if (NULL != Context.ProcessData) + /* Cleanup */ + if (NULL != Context.ProcessData) { - HeapFree(Win32CsrApiHeap, 0, Context.ProcessData); + HeapFree(Win32CsrApiHeap, 0, Context.ProcessData); } - return Status; + return Status; } static NTSTATUS FASTCALL UserExitReactos(DWORD UserProcessId, UINT Flags) { - NTSTATUS Status; + NTSTATUS Status; - if (NULL == LogonNotifyWindow) + if (NULL == LogonNotifyWindow) { - DPRINT1("No LogonNotifyWindow registered\n"); - return STATUS_NOT_FOUND; + DPRINT1("No LogonNotifyWindow registered\n"); + return STATUS_NOT_FOUND; } - /* FIXME Inside 2000 says we should impersonate the caller here */ - Status = SendMessageW(LogonNotifyWindow, PM_WINLOGON_EXITWINDOWS, - (WPARAM) UserProcessId, - (LPARAM) Flags); - /* If the message isn't handled, the return value is 0, so 0 doesn't indicate - success. Success is indicated by a 1 return value, if anything besides 0 - or 1 it's a NTSTATUS value */ - if (1 == Status) + /* FIXME Inside 2000 says we should impersonate the caller here */ + Status = SendMessageW(LogonNotifyWindow, PM_WINLOGON_EXITWINDOWS, + (WPARAM) UserProcessId, + (LPARAM) Flags); + /* If the message isn't handled, the return value is 0, so 0 doesn't indicate + success. Success is indicated by a 1 return value, if anything besides 0 + or 1 it's a NTSTATUS value */ + if (1 == Status) { - Status = STATUS_SUCCESS; + Status = STATUS_SUCCESS; } - else if (0 == Status) + else if (0 == Status) { - Status = STATUS_NOT_IMPLEMENTED; + Status = STATUS_NOT_IMPLEMENTED; } - return Status; + return Status; } CSR_API(CsrExitReactos) { - Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); - Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - - sizeof(PORT_MESSAGE); + Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE); + Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - + sizeof(PORT_MESSAGE); - if (0 == (Request->Data.ExitReactosRequest.Flags & EWX_INTERNAL_FLAG)) + if (0 == (Request->Data.ExitReactosRequest.Flags & EWX_INTERNAL_FLAG)) { - return UserExitReactos((DWORD_PTR) Request->Header.ClientId.UniqueProcess, - Request->Data.ExitReactosRequest.Flags); + return UserExitReactos((DWORD_PTR) Request->Header.ClientId.UniqueProcess, + Request->Data.ExitReactosRequest.Flags); } - else + else { - return InternalExitReactos((DWORD_PTR) Request->Header.ClientId.UniqueProcess, - (DWORD_PTR) Request->Header.ClientId.UniqueThread, - Request->Data.ExitReactosRequest.Flags); + return InternalExitReactos((DWORD_PTR) Request->Header.ClientId.UniqueProcess, + (DWORD_PTR) Request->Header.ClientId.UniqueThread, + Request->Data.ExitReactosRequest.Flags); } } diff --git a/reactos/subsystems/win32/csrss/win32csr/guiconsole.c b/reactos/subsystems/win32/csrss/win32csr/guiconsole.c index 5398fd40a4e..e274872a6eb 100644 --- a/reactos/subsystems/win32/csrss/win32csr/guiconsole.c +++ b/reactos/subsystems/win32/csrss/win32csr/guiconsole.c @@ -19,33 +19,33 @@ extern VOID WINAPI PrivateCsrssManualGuiCheck(LONG Check); typedef struct GUI_CONSOLE_DATA_TAG { - HFONT Font; - unsigned CharWidth; - unsigned CharHeight; - BOOL CursorBlinkOn; - BOOL ForceCursorOff; - CRITICAL_SECTION Lock; - HMODULE ConsoleLibrary; - HANDLE hGuiInitEvent; - WCHAR FontName[LF_FACESIZE]; - DWORD FontSize; - DWORD FontWeight; - DWORD HistoryNoDup; - DWORD FullScreen; - DWORD QuickEdit; - DWORD InsertMode; - DWORD NumberOfHistoryBuffers; - DWORD HistoryBufferSize; - DWORD WindowPosition; - DWORD UseRasterFonts; - COLORREF ScreenText; - COLORREF ScreenBackground; - COLORREF PopupBackground; - COLORREF PopupText; - COLORREF Colors[16]; - WCHAR szProcessName[MAX_PATH]; - BOOL WindowSizeLock; - POINT OldCursor; + HFONT Font; + unsigned CharWidth; + unsigned CharHeight; + BOOL CursorBlinkOn; + BOOL ForceCursorOff; + CRITICAL_SECTION Lock; + HMODULE ConsoleLibrary; + HANDLE hGuiInitEvent; + WCHAR FontName[LF_FACESIZE]; + DWORD FontSize; + DWORD FontWeight; + DWORD HistoryNoDup; + DWORD FullScreen; + DWORD QuickEdit; + DWORD InsertMode; + DWORD NumberOfHistoryBuffers; + DWORD HistoryBufferSize; + DWORD WindowPosition; + DWORD UseRasterFonts; + COLORREF ScreenText; + COLORREF ScreenBackground; + COLORREF PopupBackground; + COLORREF PopupText; + COLORREF Colors[16]; + WCHAR szProcessName[MAX_PATH]; + BOOL WindowSizeLock; + POINT OldCursor; } GUI_CONSOLE_DATA, *PGUI_CONSOLE_DATA; #ifndef WM_APP @@ -164,8 +164,8 @@ GuiConsoleAppendMenuItems(HMENU hMenu, 0, NULL); } - i++; - }while(!(Items[i].uID == 0 && Items[i].SubMenu == NULL && Items[i].wCmdID == 0)); + i++; + } while(!(Items[i].uID == 0 && Items[i].SubMenu == NULL && Items[i].wCmdID == 0)); } static VOID @@ -185,206 +185,206 @@ GuiConsoleCreateSysMenu(PCSRSS_CONSOLE Console) static VOID GuiConsoleGetDataPointers(HWND hWnd, PCSRSS_CONSOLE *Console, PGUI_CONSOLE_DATA *GuiData) { - *Console = (PCSRSS_CONSOLE) GetWindowLongPtrW(hWnd, GWL_USERDATA); - *GuiData = (NULL == *Console ? NULL : (*Console)->PrivateData); + *Console = (PCSRSS_CONSOLE) GetWindowLongPtrW(hWnd, GWL_USERDATA); + *GuiData = (NULL == *Console ? NULL : (*Console)->PrivateData); } static BOOL GuiConsoleOpenUserRegistryPathPerProcessId(DWORD ProcessId, PHANDLE hProcHandle, PHKEY hResult, REGSAM samDesired) { - HANDLE hProcessToken = NULL; - HANDLE hProcess; + HANDLE hProcessToken = NULL; + HANDLE hProcess; - BYTE Buffer[256]; - DWORD Length = 0; - UNICODE_STRING SidName; - LONG res; - PTOKEN_USER TokUser; + BYTE Buffer[256]; + DWORD Length = 0; + UNICODE_STRING SidName; + LONG res; + PTOKEN_USER TokUser; - hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | READ_CONTROL, FALSE, ProcessId); - if (!hProcess) + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | READ_CONTROL, FALSE, ProcessId); + if (!hProcess) { - DPRINT("Error: OpenProcess failed(0x%x)\n", GetLastError()); - return FALSE; + DPRINT("Error: OpenProcess failed(0x%x)\n", GetLastError()); + return FALSE; } - if (!OpenProcessToken(hProcess, TOKEN_QUERY, &hProcessToken)) + if (!OpenProcessToken(hProcess, TOKEN_QUERY, &hProcessToken)) { - DPRINT("Error: OpenProcessToken failed(0x%x)\n", GetLastError()); - CloseHandle(hProcess); - return FALSE; + DPRINT("Error: OpenProcessToken failed(0x%x)\n", GetLastError()); + CloseHandle(hProcess); + return FALSE; } - if (!GetTokenInformation(hProcessToken, TokenUser, (PVOID)Buffer, sizeof(Buffer), &Length)) + if (!GetTokenInformation(hProcessToken, TokenUser, (PVOID)Buffer, sizeof(Buffer), &Length)) { - DPRINT("Error: GetTokenInformation failed(0x%x)\n",GetLastError()); - CloseHandle(hProcess); - CloseHandle(hProcessToken); - return FALSE; + DPRINT("Error: GetTokenInformation failed(0x%x)\n",GetLastError()); + CloseHandle(hProcess); + CloseHandle(hProcessToken); + return FALSE; } - TokUser = ((PTOKEN_USER)Buffer)->User.Sid; - if (!NT_SUCCESS(RtlConvertSidToUnicodeString(&SidName, TokUser, TRUE))) + TokUser = ((PTOKEN_USER)Buffer)->User.Sid; + if (!NT_SUCCESS(RtlConvertSidToUnicodeString(&SidName, TokUser, TRUE))) { - DPRINT("Error: RtlConvertSidToUnicodeString failed(0x%x)\n", GetLastError()); - return FALSE; + DPRINT("Error: RtlConvertSidToUnicodeString failed(0x%x)\n", GetLastError()); + return FALSE; } - res = RegOpenKeyExW(HKEY_USERS, SidName.Buffer, 0, samDesired, hResult); - RtlFreeUnicodeString(&SidName); + res = RegOpenKeyExW(HKEY_USERS, SidName.Buffer, 0, samDesired, hResult); + RtlFreeUnicodeString(&SidName); - CloseHandle(hProcessToken); - if (hProcHandle) - *hProcHandle = hProcess; - else - CloseHandle(hProcess); + CloseHandle(hProcessToken); + if (hProcHandle) + *hProcHandle = hProcess; + else + CloseHandle(hProcess); - if (res != ERROR_SUCCESS) - return FALSE; - else - return TRUE; + if (res != ERROR_SUCCESS) + return FALSE; + else + return TRUE; } static BOOL GuiConsoleOpenUserSettings(PGUI_CONSOLE_DATA GuiData, DWORD ProcessId, PHKEY hSubKey, REGSAM samDesired, BOOL bCreate) { - WCHAR szProcessName[MAX_PATH]; - WCHAR szBuffer[MAX_PATH]; - UINT fLength, wLength; - DWORD dwBitmask, dwLength; - WCHAR CurDrive[] = { 'A',':', 0 }; - HANDLE hProcess; - HKEY hKey; - WCHAR * ptr; + WCHAR szProcessName[MAX_PATH]; + WCHAR szBuffer[MAX_PATH]; + UINT fLength, wLength; + DWORD dwBitmask, dwLength; + WCHAR CurDrive[] = { 'A',':', 0 }; + HANDLE hProcess; + HKEY hKey; + WCHAR * ptr; - /* - * console properties are stored under - * HKCU\Console\* - * - * There are 3 ways to store console properties - * - * 1. use console title as subkey name - * i.e. cmd.exe - * - * 2. use application name as subkey name - * - * 3. use unexpanded path to console application. - * i.e. %SystemRoot%_system32_cmd.exe - */ + /* + * console properties are stored under + * HKCU\Console\* + * + * There are 3 ways to store console properties + * + * 1. use console title as subkey name + * i.e. cmd.exe + * + * 2. use application name as subkey name + * + * 3. use unexpanded path to console application. + * i.e. %SystemRoot%_system32_cmd.exe + */ - DPRINT("GuiConsoleOpenUserSettings entered\n"); + DPRINT("GuiConsoleOpenUserSettings entered\n"); - if (!GuiConsoleOpenUserRegistryPathPerProcessId(ProcessId, &hProcess, &hKey, samDesired)) + if (!GuiConsoleOpenUserRegistryPathPerProcessId(ProcessId, &hProcess, &hKey, samDesired)) { - DPRINT("GuiConsoleOpenUserRegistryPathPerProcessId failed\n"); - return FALSE; + DPRINT("GuiConsoleOpenUserRegistryPathPerProcessId failed\n"); + return FALSE; } - /* FIXME we do not getting the process name so no menu will be loading, why ?*/ - fLength = GetProcessImageFileNameW(hProcess, szProcessName, sizeof(GuiData->szProcessName) / sizeof(WCHAR)); - CloseHandle(hProcess); + /* FIXME we do not getting the process name so no menu will be loading, why ?*/ + fLength = GetProcessImageFileNameW(hProcess, szProcessName, sizeof(GuiData->szProcessName) / sizeof(WCHAR)); + CloseHandle(hProcess); - //DPRINT1("szProcessName3 : %S\n",szProcessName); + //DPRINT1("szProcessName3 : %S\n",szProcessName); - if (!fLength) + if (!fLength) { - DPRINT("GetProcessImageFileNameW failed(0x%x)ProcessId %d\n", GetLastError(),hProcess); - return FALSE; + DPRINT("GetProcessImageFileNameW failed(0x%x)ProcessId %d\n", GetLastError(),hProcess); + return FALSE; } - /* - * try the process name as path - */ + /* + * try the process name as path + */ - ptr = wcsrchr(szProcessName, L'\\'); - wcscpy(GuiData->szProcessName, ptr); + ptr = wcsrchr(szProcessName, L'\\'); + wcscpy(GuiData->szProcessName, ptr); - swprintf(szBuffer, L"Console%s",ptr); - DPRINT("#1 Path : %S\n", szBuffer); + swprintf(szBuffer, L"Console%s",ptr); + DPRINT("#1 Path : %S\n", szBuffer); - if (bCreate) + if (bCreate) { - if (RegCreateKeyW(hKey, szBuffer, hSubKey) == ERROR_SUCCESS) + if (RegCreateKeyW(hKey, szBuffer, hSubKey) == ERROR_SUCCESS) { - RegCloseKey(hKey); - return TRUE; + RegCloseKey(hKey); + return TRUE; } - RegCloseKey(hKey); - return FALSE; - } - - if (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS) - { - RegCloseKey(hKey); - return TRUE; + RegCloseKey(hKey); + return FALSE; } - /* - * try the "Shortcut to processname" as path - * FIXME: detect wheter the process was started as a shortcut - */ - - swprintf(szBuffer, L"Console\\Shortcut to %S", ptr); - DPRINT("#2 Path : %S\n", szBuffer); - if (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS) + if (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS) { - swprintf(GuiData->szProcessName, L"Shortcut to %S", ptr); - RegCloseKey(hKey); - return TRUE; + RegCloseKey(hKey); + return TRUE; } - /* - * if the path contains \\Device\\HarddiskVolume1\... remove it - */ + /* + * try the "Shortcut to processname" as path + * FIXME: detect wheter the process was started as a shortcut + */ - if (szProcessName[0] == L'\\') + swprintf(szBuffer, L"Console\\Shortcut to %S", ptr); + DPRINT("#2 Path : %S\n", szBuffer); + if (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS) { - dwBitmask = GetLogicalDrives(); - while(dwBitmask) + swprintf(GuiData->szProcessName, L"Shortcut to %S", ptr); + RegCloseKey(hKey); + return TRUE; + } + + /* + * if the path contains \\Device\\HarddiskVolume1\... remove it + */ + + if (szProcessName[0] == L'\\') + { + dwBitmask = GetLogicalDrives(); + while(dwBitmask) { - if (dwBitmask & 0x1) + if (dwBitmask & 0x1) { - dwLength = QueryDosDeviceW(CurDrive, szBuffer, MAX_PATH); - if (dwLength) + dwLength = QueryDosDeviceW(CurDrive, szBuffer, MAX_PATH); + if (dwLength) { - if (!memcmp(szBuffer, szProcessName, (dwLength-2)*sizeof(WCHAR))) + if (!memcmp(szBuffer, szProcessName, (dwLength-2)*sizeof(WCHAR))) { - wcscpy(szProcessName, CurDrive); - RtlMoveMemory(&szProcessName[2], &szProcessName[dwLength-1], fLength - dwLength -1); - break; + wcscpy(szProcessName, CurDrive); + RtlMoveMemory(&szProcessName[2], &szProcessName[dwLength-1], fLength - dwLength -1); + break; } } } - dwBitmask = (dwBitmask >> 1); - CurDrive[0]++; + dwBitmask = (dwBitmask >> 1); + CurDrive[0]++; } } - /* - * last attempt: check whether the file is under %SystemRoot% - * and use path like Console\%SystemRoot%_dir_dir2_file.exe - */ + /* + * last attempt: check whether the file is under %SystemRoot% + * and use path like Console\%SystemRoot%_dir_dir2_file.exe + */ - wLength = GetWindowsDirectoryW(szBuffer, MAX_PATH); - if (wLength) + wLength = GetWindowsDirectoryW(szBuffer, MAX_PATH); + if (wLength) { - if (!wcsncmp(szProcessName, szBuffer, wLength)) + if (!wcsncmp(szProcessName, szBuffer, wLength)) { - /* replace slashes by underscores */ - while((ptr = wcschr(szProcessName, L'\\'))) - ptr[0] = L'_'; + /* replace slashes by underscores */ + while((ptr = wcschr(szProcessName, L'\\'))) + ptr[0] = L'_'; - swprintf(szBuffer, L"Console\\%%SystemRoot%%%S", &szProcessName[wLength]); - DPRINT("#3 Path : %S\n", szBuffer); - if (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS) + swprintf(szBuffer, L"Console\\%%SystemRoot%%%S", &szProcessName[wLength]); + DPRINT("#3 Path : %S\n", szBuffer); + if (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS) { - swprintf(GuiData->szProcessName, L"%%SystemRoot%%%S", &szProcessName[wLength]); - RegCloseKey(hKey); - return TRUE; + swprintf(GuiData->szProcessName, L"%%SystemRoot%%%S", &szProcessName[wLength]); + RegCloseKey(hKey); + return TRUE; } } } - RegCloseKey(hKey); - return FALSE; + RegCloseKey(hKey); + return FALSE; } static VOID @@ -394,238 +394,238 @@ GuiConsoleWriteUserSettings(PCSRSS_CONSOLE Console, PGUI_CONSOLE_DATA GuiData) PCSRSS_PROCESS_DATA ProcessData; if (Console->ProcessList.Flink == &Console->ProcessList) - { + { DPRINT("GuiConsoleWriteUserSettings: No Process!!!\n"); return; - } + } ProcessData = CONTAINING_RECORD(Console->ProcessList.Flink, CSRSS_PROCESS_DATA, ProcessEntry); if (!GuiConsoleOpenUserSettings(GuiData, PtrToUlong(ProcessData->ProcessId), &hKey, KEY_READ | KEY_WRITE, TRUE)) - { + { return; - } - - if (Console->ActiveBuffer->CursorInfo.dwSize <= 1) - { - RegDeleteKeyW(hKey, L"CursorSize"); - } - else - { - RegSetValueExW(hKey, L"CursorSize", 0, REG_DWORD, (const BYTE *)&Console->ActiveBuffer->CursorInfo.dwSize, sizeof(DWORD)); } - if (GuiData->NumberOfHistoryBuffers == 5) + if (Console->ActiveBuffer->CursorInfo.dwSize <= 1) { - RegDeleteKeyW(hKey, L"NumberOfHistoryBuffers"); - } - else - { - RegSetValueExW(hKey, L"NumberOfHistoryBuffers", 0, REG_DWORD, (const BYTE *)&GuiData->NumberOfHistoryBuffers, sizeof(DWORD)); - } - - if (GuiData->HistoryBufferSize == 50) - { - RegDeleteKeyW(hKey, L"HistoryBufferSize"); - } - else - { - RegSetValueExW(hKey, L"HistoryBufferSize", 0, REG_DWORD, (const BYTE *)&GuiData->HistoryBufferSize, sizeof(DWORD)); - } - - if (GuiData->FullScreen == FALSE) - { - RegDeleteKeyW(hKey, L"FullScreen"); - } - else - { - RegSetValueExW(hKey, L"FullScreen", 0, REG_DWORD, (const BYTE *)&GuiData->FullScreen, sizeof(DWORD)); - } - - if ( GuiData->QuickEdit == FALSE) - { - RegDeleteKeyW(hKey, L"QuickEdit"); + RegDeleteKeyW(hKey, L"CursorSize"); } else { - RegSetValueExW(hKey, L"QuickEdit", 0, REG_DWORD, (const BYTE *)&GuiData->QuickEdit, sizeof(DWORD)); + RegSetValueExW(hKey, L"CursorSize", 0, REG_DWORD, (const BYTE *)&Console->ActiveBuffer->CursorInfo.dwSize, sizeof(DWORD)); } - if (GuiData->InsertMode == TRUE) + if (GuiData->NumberOfHistoryBuffers == 5) { - RegDeleteKeyW(hKey, L"InsertMode"); + RegDeleteKeyW(hKey, L"NumberOfHistoryBuffers"); } - else + else { - RegSetValueExW(hKey, L"InsertMode", 0, REG_DWORD, (const BYTE *)&GuiData->InsertMode, sizeof(DWORD)); + RegSetValueExW(hKey, L"NumberOfHistoryBuffers", 0, REG_DWORD, (const BYTE *)&GuiData->NumberOfHistoryBuffers, sizeof(DWORD)); } - if (GuiData->HistoryNoDup == FALSE) + if (GuiData->HistoryBufferSize == 50) { - RegDeleteKeyW(hKey, L"HistoryNoDup"); + RegDeleteKeyW(hKey, L"HistoryBufferSize"); } - else + else { - RegSetValueExW(hKey, L"HistoryNoDup", 0, REG_DWORD, (const BYTE *)&GuiData->HistoryNoDup, sizeof(DWORD)); + RegSetValueExW(hKey, L"HistoryBufferSize", 0, REG_DWORD, (const BYTE *)&GuiData->HistoryBufferSize, sizeof(DWORD)); } - if (GuiData->ScreenText == RGB(192, 192, 192)) + if (GuiData->FullScreen == FALSE) { - /* - * MS uses console attributes instead of real color - */ - RegDeleteKeyW(hKey, L"ScreenText"); + RegDeleteKeyW(hKey, L"FullScreen"); } - else + else { - RegSetValueExW(hKey, L"ScreenText", 0, REG_DWORD, (const BYTE *)&GuiData->ScreenText, sizeof(COLORREF)); + RegSetValueExW(hKey, L"FullScreen", 0, REG_DWORD, (const BYTE *)&GuiData->FullScreen, sizeof(DWORD)); } - if (GuiData->ScreenBackground == RGB(0, 0, 0)) + if ( GuiData->QuickEdit == FALSE) { - RegDeleteKeyW(hKey, L"ScreenBackground"); + RegDeleteKeyW(hKey, L"QuickEdit"); } - else + else { - RegSetValueExW(hKey, L"ScreenBackground", 0, REG_DWORD, (const BYTE *)&GuiData->ScreenBackground, sizeof(COLORREF)); + RegSetValueExW(hKey, L"QuickEdit", 0, REG_DWORD, (const BYTE *)&GuiData->QuickEdit, sizeof(DWORD)); } - RegCloseKey(hKey); + if (GuiData->InsertMode == TRUE) + { + RegDeleteKeyW(hKey, L"InsertMode"); + } + else + { + RegSetValueExW(hKey, L"InsertMode", 0, REG_DWORD, (const BYTE *)&GuiData->InsertMode, sizeof(DWORD)); + } + + if (GuiData->HistoryNoDup == FALSE) + { + RegDeleteKeyW(hKey, L"HistoryNoDup"); + } + else + { + RegSetValueExW(hKey, L"HistoryNoDup", 0, REG_DWORD, (const BYTE *)&GuiData->HistoryNoDup, sizeof(DWORD)); + } + + if (GuiData->ScreenText == RGB(192, 192, 192)) + { + /* + * MS uses console attributes instead of real color + */ + RegDeleteKeyW(hKey, L"ScreenText"); + } + else + { + RegSetValueExW(hKey, L"ScreenText", 0, REG_DWORD, (const BYTE *)&GuiData->ScreenText, sizeof(COLORREF)); + } + + if (GuiData->ScreenBackground == RGB(0, 0, 0)) + { + RegDeleteKeyW(hKey, L"ScreenBackground"); + } + else + { + RegSetValueExW(hKey, L"ScreenBackground", 0, REG_DWORD, (const BYTE *)&GuiData->ScreenBackground, sizeof(COLORREF)); + } + + RegCloseKey(hKey); } static void GuiConsoleReadUserSettings(HKEY hKey, PCSRSS_CONSOLE Console, PGUI_CONSOLE_DATA GuiData, PCSRSS_SCREEN_BUFFER Buffer) { - DWORD dwNumSubKeys = 0; - DWORD dwIndex; - DWORD dwValueName; - DWORD dwValue; - DWORD dwType; - WCHAR szValueName[MAX_PATH]; - WCHAR szValue[LF_FACESIZE] = L"\0"; - DWORD Value; + DWORD dwNumSubKeys = 0; + DWORD dwIndex; + DWORD dwValueName; + DWORD dwValue; + DWORD dwType; + WCHAR szValueName[MAX_PATH]; + WCHAR szValue[LF_FACESIZE] = L"\0"; + DWORD Value; - if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &dwNumSubKeys, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) + if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &dwNumSubKeys, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) { - DPRINT("GuiConsoleReadUserSettings: RegQueryInfoKey failed\n"); - return; + DPRINT("GuiConsoleReadUserSettings: RegQueryInfoKey failed\n"); + return; } - DPRINT("GuiConsoleReadUserSettings entered dwNumSubKeys %d\n", dwNumSubKeys); + DPRINT("GuiConsoleReadUserSettings entered dwNumSubKeys %d\n", dwNumSubKeys); - for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++) + for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++) { - dwValue = sizeof(Value); - dwValueName = MAX_PATH; + dwValue = sizeof(Value); + dwValueName = MAX_PATH; - if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS) + if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS) { - if (dwType == REG_SZ) + if (dwType == REG_SZ) { - /* - * retry in case of string value - */ - dwValue = sizeof(szValue); - dwValueName = LF_FACESIZE; - if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS) + /* + * retry in case of string value + */ + dwValue = sizeof(szValue); + dwValueName = LF_FACESIZE; + if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS) + break; + } + else break; - } - else - break; } - if (!wcscmp(szValueName, L"CursorSize")) + if (!wcscmp(szValueName, L"CursorSize")) { - if (Value == 0x32) + if (Value == 0x32) { - Buffer->CursorInfo.dwSize = Value; + Buffer->CursorInfo.dwSize = Value; } - else if (Value == 0x64) + else if (Value == 0x64) { - Buffer->CursorInfo.dwSize = Value; + Buffer->CursorInfo.dwSize = Value; } } - else if (!wcscmp(szValueName, L"ScreenText")) + else if (!wcscmp(szValueName, L"ScreenText")) { - GuiData->ScreenText = Value; + GuiData->ScreenText = Value; } - else if (!wcscmp(szValueName, L"ScreenBackground")) + else if (!wcscmp(szValueName, L"ScreenBackground")) { - GuiData->ScreenBackground = Value; + GuiData->ScreenBackground = Value; } - else if (!wcscmp(szValueName, L"FaceName")) + else if (!wcscmp(szValueName, L"FaceName")) { - wcscpy(GuiData->FontName, szValue); + wcscpy(GuiData->FontName, szValue); } - else if (!wcscmp(szValueName, L"FontSize")) + else if (!wcscmp(szValueName, L"FontSize")) { - GuiData->FontSize = Value; + GuiData->FontSize = Value; } - else if (!wcscmp(szValueName, L"FontWeight")) + else if (!wcscmp(szValueName, L"FontWeight")) { - GuiData->FontWeight = Value; + GuiData->FontWeight = Value; } - else if (!wcscmp(szValueName, L"HistoryNoDup")) + else if (!wcscmp(szValueName, L"HistoryNoDup")) { - GuiData->HistoryNoDup = Value; + GuiData->HistoryNoDup = Value; } - else if (!wcscmp(szValueName, L"WindowSize")) + else if (!wcscmp(szValueName, L"WindowSize")) { - Console->Size.X = LOWORD(Value); - Console->Size.Y = HIWORD(Value); + Console->Size.X = LOWORD(Value); + Console->Size.Y = HIWORD(Value); } - else if (!wcscmp(szValueName, L"ScreenBufferSize")) + else if (!wcscmp(szValueName, L"ScreenBufferSize")) { if(Buffer) - { + { Buffer->MaxX = LOWORD(Value); Buffer->MaxY = HIWORD(Value); - } + } } - else if (!wcscmp(szValueName, L"FullScreen")) + else if (!wcscmp(szValueName, L"FullScreen")) { - GuiData->FullScreen = Value; + GuiData->FullScreen = Value; } - else if (!wcscmp(szValueName, L"QuickEdit")) + else if (!wcscmp(szValueName, L"QuickEdit")) { - GuiData->QuickEdit = Value; + GuiData->QuickEdit = Value; } - else if (!wcscmp(szValueName, L"InsertMode")) + else if (!wcscmp(szValueName, L"InsertMode")) { - GuiData->InsertMode = Value; + GuiData->InsertMode = Value; } - } + } } static VOID GuiConsoleUseDefaults(PCSRSS_CONSOLE Console, PGUI_CONSOLE_DATA GuiData, PCSRSS_SCREEN_BUFFER Buffer) { - /* - * init guidata with default properties - */ + /* + * init guidata with default properties + */ - wcscpy(GuiData->FontName, L"DejaVu Sans Mono"); - GuiData->FontSize = 0x0008000C; // font is 8x12 - GuiData->FontWeight = FW_NORMAL; - GuiData->HistoryNoDup = FALSE; - GuiData->FullScreen = FALSE; - GuiData->QuickEdit = FALSE; - GuiData->InsertMode = TRUE; - GuiData->HistoryBufferSize = 50; - GuiData->NumberOfHistoryBuffers = 5; - GuiData->ScreenText = RGB(192, 192, 192); - GuiData->ScreenBackground = RGB(0, 0, 0); - GuiData->PopupText = RGB(128, 0, 128); - GuiData->PopupBackground = RGB(255, 255, 255); - GuiData->WindowPosition = UINT_MAX; - GuiData->UseRasterFonts = TRUE; - memcpy(GuiData->Colors, s_Colors, sizeof(s_Colors)); + wcscpy(GuiData->FontName, L"DejaVu Sans Mono"); + GuiData->FontSize = 0x0008000C; // font is 8x12 + GuiData->FontWeight = FW_NORMAL; + GuiData->HistoryNoDup = FALSE; + GuiData->FullScreen = FALSE; + GuiData->QuickEdit = FALSE; + GuiData->InsertMode = TRUE; + GuiData->HistoryBufferSize = 50; + GuiData->NumberOfHistoryBuffers = 5; + GuiData->ScreenText = RGB(192, 192, 192); + GuiData->ScreenBackground = RGB(0, 0, 0); + GuiData->PopupText = RGB(128, 0, 128); + GuiData->PopupBackground = RGB(255, 255, 255); + GuiData->WindowPosition = UINT_MAX; + GuiData->UseRasterFonts = TRUE; + memcpy(GuiData->Colors, s_Colors, sizeof(s_Colors)); - Console->Size.X = 80; - Console->Size.Y = 25; + Console->Size.X = 80; + Console->Size.Y = 25; - if (Buffer) + if (Buffer) { - Buffer->MaxX = 80; - Buffer->MaxY = 300; - Buffer->CursorInfo.bVisible = TRUE; - Buffer->CursorInfo.dwSize = CSR_DEFAULT_CURSOR_SIZE; + Buffer->MaxX = 80; + Buffer->MaxY = 300; + Buffer->CursorInfo.bVisible = TRUE; + Buffer->CursorInfo.dwSize = CSR_DEFAULT_CURSOR_SIZE; } } @@ -633,157 +633,157 @@ VOID FASTCALL GuiConsoleInitScrollbar(PCSRSS_CONSOLE Console, HWND hwnd) { - SCROLLINFO sInfo; - PGUI_CONSOLE_DATA GuiData = Console->PrivateData; + SCROLLINFO sInfo; + PGUI_CONSOLE_DATA GuiData = Console->PrivateData; - DWORD Width = Console->Size.X * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)); - DWORD Height = Console->Size.Y * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION); + DWORD Width = Console->Size.X * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)); + DWORD Height = Console->Size.Y * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION); - /* set scrollbar sizes */ - sInfo.cbSize = sizeof(SCROLLINFO); - sInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - sInfo.nMin = 0; - if (Console->ActiveBuffer->MaxY > Console->Size.Y) - { - sInfo.nMax = Console->ActiveBuffer->MaxY - 1; - sInfo.nPage = Console->Size.Y; - sInfo.nPos = Console->ActiveBuffer->ShowY; - SetScrollInfo(hwnd, SB_VERT, &sInfo, TRUE); - Width += GetSystemMetrics(SM_CXVSCROLL); - ShowScrollBar(hwnd, SB_VERT, TRUE); - } - else - { - ShowScrollBar(hwnd, SB_VERT, FALSE); - } + /* set scrollbar sizes */ + sInfo.cbSize = sizeof(SCROLLINFO); + sInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; + sInfo.nMin = 0; + if (Console->ActiveBuffer->MaxY > Console->Size.Y) + { + sInfo.nMax = Console->ActiveBuffer->MaxY - 1; + sInfo.nPage = Console->Size.Y; + sInfo.nPos = Console->ActiveBuffer->ShowY; + SetScrollInfo(hwnd, SB_VERT, &sInfo, TRUE); + Width += GetSystemMetrics(SM_CXVSCROLL); + ShowScrollBar(hwnd, SB_VERT, TRUE); + } + else + { + ShowScrollBar(hwnd, SB_VERT, FALSE); + } - if (Console->ActiveBuffer->MaxX > Console->Size.X) - { - sInfo.nMax = Console->ActiveBuffer->MaxX - 1; - sInfo.nPage = Console->Size.X; - sInfo.nPos = Console->ActiveBuffer->ShowX; - SetScrollInfo(hwnd, SB_HORZ, &sInfo, TRUE); - Height += GetSystemMetrics(SM_CYHSCROLL); - ShowScrollBar(hwnd, SB_HORZ, TRUE); + if (Console->ActiveBuffer->MaxX > Console->Size.X) + { + sInfo.nMax = Console->ActiveBuffer->MaxX - 1; + sInfo.nPage = Console->Size.X; + sInfo.nPos = Console->ActiveBuffer->ShowX; + SetScrollInfo(hwnd, SB_HORZ, &sInfo, TRUE); + Height += GetSystemMetrics(SM_CYHSCROLL); + ShowScrollBar(hwnd, SB_HORZ, TRUE); - } - else - { - ShowScrollBar(hwnd, SB_HORZ, FALSE); - } + } + else + { + ShowScrollBar(hwnd, SB_HORZ, FALSE); + } - SetWindowPos(hwnd, NULL, 0, 0, Width, Height, - SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); + SetWindowPos(hwnd, NULL, 0, 0, Width, Height, + SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } static BOOL GuiConsoleHandleNcCreate(HWND hWnd, CREATESTRUCTW *Create) { - PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Create->lpCreateParams; - PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)Console->PrivateData; - HDC Dc; - HFONT OldFont; - TEXTMETRICW Metrics; - SIZE CharSize; - PCSRSS_PROCESS_DATA ProcessData; - HKEY hKey; + PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Create->lpCreateParams; + PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)Console->PrivateData; + HDC Dc; + HFONT OldFont; + TEXTMETRICW Metrics; + SIZE CharSize; + PCSRSS_PROCESS_DATA ProcessData; + HKEY hKey; - Console->hWindow = hWnd; + Console->hWindow = hWnd; - if (NULL == GuiData) + if (NULL == GuiData) { - DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n"); - return FALSE; + DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n"); + return FALSE; } - GuiConsoleUseDefaults(Console, GuiData, Console->ActiveBuffer); - if (Console->ProcessList.Flink != &Console->ProcessList) + GuiConsoleUseDefaults(Console, GuiData, Console->ActiveBuffer); + if (Console->ProcessList.Flink != &Console->ProcessList) { - ProcessData = CONTAINING_RECORD(Console->ProcessList.Flink, CSRSS_PROCESS_DATA, ProcessEntry); - if (GuiConsoleOpenUserSettings(GuiData, PtrToUlong(ProcessData->ProcessId), &hKey, KEY_READ, FALSE)) + ProcessData = CONTAINING_RECORD(Console->ProcessList.Flink, CSRSS_PROCESS_DATA, ProcessEntry); + if (GuiConsoleOpenUserSettings(GuiData, PtrToUlong(ProcessData->ProcessId), &hKey, KEY_READ, FALSE)) { - GuiConsoleReadUserSettings(hKey, Console, GuiData, Console->ActiveBuffer); - RegCloseKey(hKey); + GuiConsoleReadUserSettings(hKey, Console, GuiData, Console->ActiveBuffer); + RegCloseKey(hKey); } } - InitializeCriticalSection(&GuiData->Lock); + InitializeCriticalSection(&GuiData->Lock); - GuiData->Font = CreateFontW(LOWORD(GuiData->FontSize), - 0, //HIWORD(GuiData->FontSize), - 0, - TA_BASELINE, - GuiData->FontWeight, - FALSE, - FALSE, - FALSE, - OEM_CHARSET, - OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - NONANTIALIASED_QUALITY, FIXED_PITCH | FF_DONTCARE, - GuiData->FontName); - if (NULL == GuiData->Font) + GuiData->Font = CreateFontW(LOWORD(GuiData->FontSize), + 0, //HIWORD(GuiData->FontSize), + 0, + TA_BASELINE, + GuiData->FontWeight, + FALSE, + FALSE, + FALSE, + OEM_CHARSET, + OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + NONANTIALIASED_QUALITY, FIXED_PITCH | FF_DONTCARE, + GuiData->FontName); + if (NULL == GuiData->Font) { - DPRINT1("GuiConsoleNcCreate: CreateFont failed\n"); - DeleteCriticalSection(&GuiData->Lock); - HeapFree(Win32CsrApiHeap, 0, GuiData); - return FALSE; + DPRINT1("GuiConsoleNcCreate: CreateFont failed\n"); + DeleteCriticalSection(&GuiData->Lock); + HeapFree(Win32CsrApiHeap, 0, GuiData); + return FALSE; } - Dc = GetDC(hWnd); - if (NULL == Dc) + Dc = GetDC(hWnd); + if (NULL == Dc) { - DPRINT1("GuiConsoleNcCreate: GetDC failed\n"); - DeleteObject(GuiData->Font); - DeleteCriticalSection(&GuiData->Lock); - HeapFree(Win32CsrApiHeap, 0, GuiData); - return FALSE; + DPRINT1("GuiConsoleNcCreate: GetDC failed\n"); + DeleteObject(GuiData->Font); + DeleteCriticalSection(&GuiData->Lock); + HeapFree(Win32CsrApiHeap, 0, GuiData); + return FALSE; } - OldFont = SelectObject(Dc, GuiData->Font); - if (NULL == OldFont) + OldFont = SelectObject(Dc, GuiData->Font); + if (NULL == OldFont) { - DPRINT1("GuiConsoleNcCreate: SelectObject failed\n"); - ReleaseDC(hWnd, Dc); - DeleteObject(GuiData->Font); - DeleteCriticalSection(&GuiData->Lock); - HeapFree(Win32CsrApiHeap, 0, GuiData); - return FALSE; + DPRINT1("GuiConsoleNcCreate: SelectObject failed\n"); + ReleaseDC(hWnd, Dc); + DeleteObject(GuiData->Font); + DeleteCriticalSection(&GuiData->Lock); + HeapFree(Win32CsrApiHeap, 0, GuiData); + return FALSE; } - if (! GetTextMetricsW(Dc, &Metrics)) + if (! GetTextMetricsW(Dc, &Metrics)) { - DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n"); - SelectObject(Dc, OldFont); - ReleaseDC(hWnd, Dc); - DeleteObject(GuiData->Font); - DeleteCriticalSection(&GuiData->Lock); - HeapFree(Win32CsrApiHeap, 0, GuiData); - return FALSE; + DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n"); + SelectObject(Dc, OldFont); + ReleaseDC(hWnd, Dc); + DeleteObject(GuiData->Font); + DeleteCriticalSection(&GuiData->Lock); + HeapFree(Win32CsrApiHeap, 0, GuiData); + return FALSE; } - GuiData->CharWidth = Metrics.tmMaxCharWidth; - GuiData->CharHeight = Metrics.tmHeight + Metrics.tmExternalLeading; + GuiData->CharWidth = Metrics.tmMaxCharWidth; + GuiData->CharHeight = Metrics.tmHeight + Metrics.tmExternalLeading; - /* Measure real char width more precisely if possible. */ - if (GetTextExtentPoint32W(Dc, L"R", 1, &CharSize)) - GuiData->CharWidth = CharSize.cx; + /* Measure real char width more precisely if possible. */ + if (GetTextExtentPoint32W(Dc, L"R", 1, &CharSize)) + GuiData->CharWidth = CharSize.cx; - SelectObject(Dc, OldFont); + SelectObject(Dc, OldFont); - ReleaseDC(hWnd, Dc); - GuiData->CursorBlinkOn = TRUE; - GuiData->ForceCursorOff = FALSE; + ReleaseDC(hWnd, Dc); + GuiData->CursorBlinkOn = TRUE; + GuiData->ForceCursorOff = FALSE; - DPRINT("Console %p GuiData %p\n", Console, GuiData); - Console->PrivateData = GuiData; - SetWindowLongPtrW(hWnd, GWL_USERDATA, (DWORD_PTR) Console); + DPRINT("Console %p GuiData %p\n", Console, GuiData); + Console->PrivateData = GuiData; + SetWindowLongPtrW(hWnd, GWL_USERDATA, (DWORD_PTR) Console); - SetTimer(hWnd, CONGUI_UPDATE_TIMER, CONGUI_UPDATE_TIME, NULL); - GuiConsoleCreateSysMenu(Console); + SetTimer(hWnd, CONGUI_UPDATE_TIMER, CONGUI_UPDATE_TIME, NULL); + GuiConsoleCreateSysMenu(Console); - GuiData->WindowSizeLock = TRUE; - GuiConsoleInitScrollbar(Console, hWnd); - GuiData->WindowSizeLock = FALSE; + GuiData->WindowSizeLock = TRUE; + GuiConsoleInitScrollbar(Console, hWnd); + GuiData->WindowSizeLock = FALSE; - SetEvent(GuiData->hGuiInitEvent); + SetEvent(GuiData->hGuiInitEvent); - return (BOOL) DefWindowProcW(hWnd, WM_NCCREATE, 0, (LPARAM) Create); + return (BOOL) DefWindowProcW(hWnd, WM_NCCREATE, 0, (LPARAM) Create); } static VOID @@ -800,62 +800,62 @@ SmallRectToRect(PCSRSS_CONSOLE Console, PRECT Rect, PSMALL_RECT SmallRect) static VOID GuiConsoleUpdateSelection(PCSRSS_CONSOLE Console, PCOORD coord) { - RECT oldRect, newRect; - HWND hWnd = Console->hWindow; + RECT oldRect, newRect; + HWND hWnd = Console->hWindow; - SmallRectToRect(Console, &oldRect, &Console->Selection.srSelection); + SmallRectToRect(Console, &oldRect, &Console->Selection.srSelection); - if(coord != NULL) - { - SMALL_RECT rc; - /* exchange left/top with right/bottom if required */ - rc.Left = min(Console->Selection.dwSelectionAnchor.X, coord->X); - rc.Top = min(Console->Selection.dwSelectionAnchor.Y, coord->Y); - rc.Right = max(Console->Selection.dwSelectionAnchor.X, coord->X); - rc.Bottom = max(Console->Selection.dwSelectionAnchor.Y, coord->Y); - - SmallRectToRect(Console, &newRect, &rc); - - if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY) + if(coord != NULL) { - if (memcmp(&rc, &Console->Selection.srSelection, sizeof(SMALL_RECT)) != 0) - { - HRGN rgn1, rgn2; + SMALL_RECT rc; + /* exchange left/top with right/bottom if required */ + rc.Left = min(Console->Selection.dwSelectionAnchor.X, coord->X); + rc.Top = min(Console->Selection.dwSelectionAnchor.Y, coord->Y); + rc.Right = max(Console->Selection.dwSelectionAnchor.X, coord->X); + rc.Bottom = max(Console->Selection.dwSelectionAnchor.Y, coord->Y); - /* calculate the region that needs to be updated */ - if((rgn1 = CreateRectRgnIndirect(&oldRect))) + SmallRectToRect(Console, &newRect, &rc); + + if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY) { - if((rgn2 = CreateRectRgnIndirect(&newRect))) - { - if(CombineRgn(rgn1, rgn2, rgn1, RGN_XOR) != ERROR) + if (memcmp(&rc, &Console->Selection.srSelection, sizeof(SMALL_RECT)) != 0) { - InvalidateRgn(hWnd, rgn1, FALSE); - } + HRGN rgn1, rgn2; - DeleteObject(rgn2); - } - DeleteObject(rgn1); + /* calculate the region that needs to be updated */ + if((rgn1 = CreateRectRgnIndirect(&oldRect))) + { + if((rgn2 = CreateRectRgnIndirect(&newRect))) + { + if(CombineRgn(rgn1, rgn2, rgn1, RGN_XOR) != ERROR) + { + InvalidateRgn(hWnd, rgn1, FALSE); + } + + DeleteObject(rgn2); + } + DeleteObject(rgn1); + } + } } - } + else + { + InvalidateRect(hWnd, &newRect, FALSE); + } + Console->Selection.dwFlags |= CONSOLE_SELECTION_NOT_EMPTY; + Console->Selection.srSelection = rc; + ConioPause(Console, PAUSED_FROM_SELECTION); } else { - InvalidateRect(hWnd, &newRect, FALSE); + /* clear the selection */ + if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY) + { + InvalidateRect(hWnd, &oldRect, FALSE); + } + Console->Selection.dwFlags = CONSOLE_NO_SELECTION; + ConioUnpause(Console, PAUSED_FROM_SELECTION); } - Console->Selection.dwFlags |= CONSOLE_SELECTION_NOT_EMPTY; - Console->Selection.srSelection = rc; - ConioPause(Console, PAUSED_FROM_SELECTION); - } - else - { - /* clear the selection */ - if (Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY) - { - InvalidateRect(hWnd, &oldRect, FALSE); - } - Console->Selection.dwFlags = CONSOLE_NO_SELECTION; - ConioUnpause(Console, PAUSED_FROM_SELECTION); - } } @@ -939,12 +939,12 @@ GuiConsolePaint(PCSRSS_CONSOLE Console, } if (Buff->CursorInfo.bVisible && GuiData->CursorBlinkOn && - !GuiData->ForceCursorOff) + !GuiData->ForceCursorOff) { CursorX = Buff->CurrentX; CursorY = Buff->CurrentY; if (LeftChar <= CursorX && CursorX <= RightChar && - TopLine <= CursorY && CursorY <= BottomLine) + TopLine <= CursorY && CursorY <= BottomLine) { CursorHeight = (GuiData->CharHeight * Buff->CursorInfo.dwSize) / 100; if (CursorHeight < 1) @@ -992,14 +992,14 @@ GuiConsoleHandlePaint(HWND hWnd, HDC hDCPaint) hDC = BeginPaint(hWnd, &ps); if (hDC != NULL && - ps.rcPaint.left < ps.rcPaint.right && - ps.rcPaint.top < ps.rcPaint.bottom) + ps.rcPaint.left < ps.rcPaint.right && + ps.rcPaint.top < ps.rcPaint.bottom) { GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); if (Console != NULL && GuiData != NULL && - Console->ActiveBuffer != NULL) + Console->ActiveBuffer != NULL) { if (Console->ActiveBuffer->Buffer != NULL) { @@ -1040,23 +1040,23 @@ GuiConsoleHandlePaint(HWND hWnd, HDC hDCPaint) static VOID GuiConsoleHandleKey(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - MSG Message; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + MSG Message; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - Message.hwnd = hWnd; - Message.message = msg; - Message.wParam = wParam; - Message.lParam = lParam; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + Message.hwnd = hWnd; + Message.message = msg; + Message.wParam = wParam; + Message.lParam = lParam; - if(msg == WM_CHAR || msg == WM_SYSKEYDOWN) - { - /* clear the selection */ - GuiConsoleUpdateSelection(Console, NULL); - } + if(msg == WM_CHAR || msg == WM_SYSKEYDOWN) + { + /* clear the selection */ + GuiConsoleUpdateSelection(Console, NULL); + } - ConioProcessKey(&Message, Console, FALSE); + ConioProcessKey(&Message, Console, FALSE); } static VOID WINAPI @@ -1078,48 +1078,48 @@ static VOID WINAPI GuiWriteStream(PCSRSS_CONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LONG CursorStartY, UINT ScrolledLines, CHAR *Buffer, UINT Length) { - PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->PrivateData; - PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; - LONG CursorEndX, CursorEndY; - RECT ScrollRect; + PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->PrivateData; + PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; + LONG CursorEndX, CursorEndY; + RECT ScrollRect; - if (NULL == Console->hWindow || NULL == GuiData) + if (NULL == Console->hWindow || NULL == GuiData) { - return; + return; } - if (0 != ScrolledLines) + if (0 != ScrolledLines) { - ScrollRect.left = 0; - ScrollRect.top = 0; - ScrollRect.right = Console->Size.X * GuiData->CharWidth; - ScrollRect.bottom = Region->Top * GuiData->CharHeight; + ScrollRect.left = 0; + ScrollRect.top = 0; + ScrollRect.right = Console->Size.X * GuiData->CharWidth; + ScrollRect.bottom = Region->Top * GuiData->CharHeight; - ScrollWindowEx(Console->hWindow, - 0, - -(ScrolledLines * GuiData->CharHeight), - &ScrollRect, - NULL, - NULL, - NULL, - SW_INVALIDATE); + ScrollWindowEx(Console->hWindow, + 0, + -(ScrolledLines * GuiData->CharHeight), + &ScrollRect, + NULL, + NULL, + NULL, + SW_INVALIDATE); } - GuiDrawRegion(Console, Region); + GuiDrawRegion(Console, Region); - if (CursorStartX < Region->Left || Region->Right < CursorStartX - || CursorStartY < Region->Top || Region->Bottom < CursorStartY) + if (CursorStartX < Region->Left || Region->Right < CursorStartX + || CursorStartY < Region->Top || Region->Bottom < CursorStartY) { - GuiInvalidateCell(Console, CursorStartX, CursorStartY); + GuiInvalidateCell(Console, CursorStartX, CursorStartY); } - CursorEndX = Buff->CurrentX; - CursorEndY = Buff->CurrentY; - if ((CursorEndX < Region->Left || Region->Right < CursorEndX - || CursorEndY < Region->Top || Region->Bottom < CursorEndY) - && (CursorEndX != CursorStartX || CursorEndY != CursorStartY)) + CursorEndX = Buff->CurrentX; + CursorEndY = Buff->CurrentY; + if ((CursorEndX < Region->Left || Region->Right < CursorEndX + || CursorEndY < Region->Top || Region->Bottom < CursorEndY) + && (CursorEndX != CursorStartX || CursorEndY != CursorStartY)) { - GuiInvalidateCell(Console, CursorEndX, CursorEndY); + GuiInvalidateCell(Console, CursorEndX, CursorEndY); } // Set up the update timer (very short interval) - this is a "hack" for getting the OS to @@ -1131,26 +1131,26 @@ GuiWriteStream(PCSRSS_CONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LO static BOOL WINAPI GuiSetCursorInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff) { - if (Console->ActiveBuffer == Buff) + if (Console->ActiveBuffer == Buff) { - GuiInvalidateCell(Console, Buff->CurrentX, Buff->CurrentY); + GuiInvalidateCell(Console, Buff->CurrentX, Buff->CurrentY); } - return TRUE; + return TRUE; } static BOOL WINAPI GuiSetScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, UINT OldCursorX, UINT OldCursorY) { - if (Console->ActiveBuffer == Buff) + if (Console->ActiveBuffer == Buff) { - /* Redraw char at old position (removes cursor) */ - GuiInvalidateCell(Console, OldCursorX, OldCursorY); - /* Redraw char at new position (shows cursor) */ - GuiInvalidateCell(Console, Buff->CurrentX, Buff->CurrentY); + /* Redraw char at old position (removes cursor) */ + GuiInvalidateCell(Console, OldCursorX, OldCursorY); + /* Redraw char at new position (shows cursor) */ + GuiInvalidateCell(Console, Buff->CurrentX, Buff->CurrentY); } - return TRUE; + return TRUE; } static BOOL WINAPI @@ -1170,135 +1170,135 @@ GuiUpdateScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff) static VOID GuiConsoleHandleTimer(HWND hWnd) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - PCSRSS_SCREEN_BUFFER Buff; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + PCSRSS_SCREEN_BUFFER Buff; - SetTimer(hWnd, CONGUI_UPDATE_TIMER, CURSOR_BLINK_TIME, NULL); + SetTimer(hWnd, CONGUI_UPDATE_TIMER, CURSOR_BLINK_TIME, NULL); - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - Buff = Console->ActiveBuffer; - GuiInvalidateCell(Console, Buff->CurrentX, Buff->CurrentY); - GuiData->CursorBlinkOn = ! GuiData->CursorBlinkOn; + Buff = Console->ActiveBuffer; + GuiInvalidateCell(Console, Buff->CurrentX, Buff->CurrentY); + GuiData->CursorBlinkOn = ! GuiData->CursorBlinkOn; - if((GuiData->OldCursor.x != Buff->CurrentX) || (GuiData->OldCursor.y != Buff->CurrentY)) - { - SCROLLINFO xScroll; - int OldScrollX = -1, OldScrollY = -1; - int NewScrollX = -1, NewScrollY = -1; + if((GuiData->OldCursor.x != Buff->CurrentX) || (GuiData->OldCursor.y != Buff->CurrentY)) + { + SCROLLINFO xScroll; + int OldScrollX = -1, OldScrollY = -1; + int NewScrollX = -1, NewScrollY = -1; - xScroll.cbSize = sizeof(SCROLLINFO); - xScroll.fMask = SIF_POS; - // Capture the original position of the scroll bars and save them. - if(GetScrollInfo(hWnd, SB_HORZ, &xScroll))OldScrollX = xScroll.nPos; - if(GetScrollInfo(hWnd, SB_VERT, &xScroll))OldScrollY = xScroll.nPos; + xScroll.cbSize = sizeof(SCROLLINFO); + xScroll.fMask = SIF_POS; + // Capture the original position of the scroll bars and save them. + if(GetScrollInfo(hWnd, SB_HORZ, &xScroll))OldScrollX = xScroll.nPos; + if(GetScrollInfo(hWnd, SB_VERT, &xScroll))OldScrollY = xScroll.nPos; - // If we successfully got the info for the horizontal scrollbar - if(OldScrollX >= 0) - { - if((Buff->CurrentX < Buff->ShowX)||(Buff->CurrentX >= (Buff->ShowX + Console->Size.X))) - { - // Handle the horizontal scroll bar - if(Buff->CurrentX >= Console->Size.X) NewScrollX = Buff->CurrentX - Console->Size.X + 1; - else NewScrollX = 0; - } - else - { - NewScrollX = OldScrollX; - } - } - // If we successfully got the info for the vertical scrollbar - if(OldScrollY >= 0) - { - if((Buff->CurrentY < Buff->ShowY) || (Buff->CurrentY >= (Buff->ShowY + Console->Size.Y))) + // If we successfully got the info for the horizontal scrollbar + if(OldScrollX >= 0) { - // Handle the vertical scroll bar - if(Buff->CurrentY >= Console->Size.Y) NewScrollY = Buff->CurrentY - Console->Size.Y + 1; - else NewScrollY = 0; + if((Buff->CurrentX < Buff->ShowX)||(Buff->CurrentX >= (Buff->ShowX + Console->Size.X))) + { + // Handle the horizontal scroll bar + if(Buff->CurrentX >= Console->Size.X) NewScrollX = Buff->CurrentX - Console->Size.X + 1; + else NewScrollX = 0; + } + else + { + NewScrollX = OldScrollX; + } } - else + // If we successfully got the info for the vertical scrollbar + if(OldScrollY >= 0) { - NewScrollY = OldScrollY; + if((Buff->CurrentY < Buff->ShowY) || (Buff->CurrentY >= (Buff->ShowY + Console->Size.Y))) + { + // Handle the vertical scroll bar + if(Buff->CurrentY >= Console->Size.Y) NewScrollY = Buff->CurrentY - Console->Size.Y + 1; + else NewScrollY = 0; + } + else + { + NewScrollY = OldScrollY; + } } - } - // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area - // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar - // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling) - // and their associated scrollbar is left alone. - if((OldScrollX != NewScrollX) || (OldScrollY != NewScrollY)) - { - Buff->ShowX = NewScrollX; - Buff->ShowY = NewScrollY; - ScrollWindowEx(hWnd, - (OldScrollX - NewScrollX) * GuiData->CharWidth, - (OldScrollY - NewScrollY) * GuiData->CharHeight, - NULL, - NULL, - NULL, - NULL, - SW_INVALIDATE); - if(NewScrollX >= 0) + // Adjust scroll bars and refresh the window if the cursor has moved outside the visible area + // NOTE: OldScroll# and NewScroll# will both be -1 (initial value) if the info for the respective scrollbar + // was not obtained successfully in the previous steps. This means their difference is 0 (no scrolling) + // and their associated scrollbar is left alone. + if((OldScrollX != NewScrollX) || (OldScrollY != NewScrollY)) { - xScroll.nPos = NewScrollX; - SetScrollInfo(hWnd, SB_HORZ, &xScroll, TRUE); + Buff->ShowX = NewScrollX; + Buff->ShowY = NewScrollY; + ScrollWindowEx(hWnd, + (OldScrollX - NewScrollX) * GuiData->CharWidth, + (OldScrollY - NewScrollY) * GuiData->CharHeight, + NULL, + NULL, + NULL, + NULL, + SW_INVALIDATE); + if(NewScrollX >= 0) + { + xScroll.nPos = NewScrollX; + SetScrollInfo(hWnd, SB_HORZ, &xScroll, TRUE); + } + if(NewScrollY >= 0) + { + xScroll.nPos = NewScrollY; + SetScrollInfo(hWnd, SB_VERT, &xScroll, TRUE); + } + UpdateWindow(hWnd); + GuiData->OldCursor.x = Buff->CurrentX; + GuiData->OldCursor.y = Buff->CurrentY; } - if(NewScrollY >= 0) - { - xScroll.nPos = NewScrollY; - SetScrollInfo(hWnd, SB_VERT, &xScroll, TRUE); - } - UpdateWindow(hWnd); - GuiData->OldCursor.x = Buff->CurrentX; - GuiData->OldCursor.y = Buff->CurrentY; - } - } + } } static VOID GuiConsoleHandleClose(HWND hWnd) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - PLIST_ENTRY current_entry; - PCSRSS_PROCESS_DATA current; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + PLIST_ENTRY current_entry; + PCSRSS_PROCESS_DATA current; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - EnterCriticalSection(&Console->Lock); + EnterCriticalSection(&Console->Lock); - current_entry = Console->ProcessList.Flink; - while (current_entry != &Console->ProcessList) + current_entry = Console->ProcessList.Flink; + while (current_entry != &Console->ProcessList) { - current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); - current_entry = current_entry->Flink; + current = CONTAINING_RECORD(current_entry, CSRSS_PROCESS_DATA, ProcessEntry); + current_entry = current_entry->Flink; - /* FIXME: Windows will wait up to 5 seconds for the thread to exit. - * We shouldn't wait here, though, since the console lock is entered. - * A copy of the thread list probably needs to be made. */ - ConioConsoleCtrlEvent(CTRL_CLOSE_EVENT, current); + /* FIXME: Windows will wait up to 5 seconds for the thread to exit. + * We shouldn't wait here, though, since the console lock is entered. + * A copy of the thread list probably needs to be made. */ + ConioConsoleCtrlEvent(CTRL_CLOSE_EVENT, current); } - LeaveCriticalSection(&Console->Lock); + LeaveCriticalSection(&Console->Lock); } static VOID GuiConsoleHandleNcDestroy(HWND hWnd) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - KillTimer(hWnd, 1); - Console->PrivateData = NULL; - DeleteCriticalSection(&GuiData->Lock); - GetSystemMenu(hWnd, TRUE); - if (GuiData->ConsoleLibrary) - FreeLibrary(GuiData->ConsoleLibrary); + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + KillTimer(hWnd, 1); + Console->PrivateData = NULL; + DeleteCriticalSection(&GuiData->Lock); + GetSystemMenu(hWnd, TRUE); + if (GuiData->ConsoleLibrary) + FreeLibrary(GuiData->ConsoleLibrary); - HeapFree(Win32CsrApiHeap, 0, GuiData); + HeapFree(Win32CsrApiHeap, 0, GuiData); } static COORD @@ -1321,78 +1321,78 @@ PointToCoord(PCSRSS_CONSOLE Console, LPARAM lParam) static VOID GuiConsoleLeftMouseDown(HWND hWnd, LPARAM lParam) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if (Console == NULL || GuiData == NULL) return; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + if (Console == NULL || GuiData == NULL) return; - Console->Selection.dwSelectionAnchor = PointToCoord(Console, lParam); + Console->Selection.dwSelectionAnchor = PointToCoord(Console, lParam); - SetCapture(hWnd); + SetCapture(hWnd); - Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS | CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN; + Console->Selection.dwFlags |= CONSOLE_SELECTION_IN_PROGRESS | CONSOLE_MOUSE_SELECTION | CONSOLE_MOUSE_DOWN; - GuiConsoleUpdateSelection(Console, &Console->Selection.dwSelectionAnchor); + GuiConsoleUpdateSelection(Console, &Console->Selection.dwSelectionAnchor); } static VOID GuiConsoleLeftMouseUp(HWND hWnd, LPARAM lParam) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - COORD c; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + COORD c; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if (Console == NULL || GuiData == NULL) return; - if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) return; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + if (Console == NULL || GuiData == NULL) return; + if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) return; - c = PointToCoord(Console, lParam); + c = PointToCoord(Console, lParam); - Console->Selection.dwFlags &= ~CONSOLE_MOUSE_DOWN; + Console->Selection.dwFlags &= ~CONSOLE_MOUSE_DOWN; - GuiConsoleUpdateSelection(Console, &c); + GuiConsoleUpdateSelection(Console, &c); - ReleaseCapture(); + ReleaseCapture(); } static VOID GuiConsoleMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - COORD c; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + COORD c; - if (!(wParam & MK_LBUTTON)) return; + if (!(wParam & MK_LBUTTON)) return; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if (Console == NULL || GuiData == NULL) return; - if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) return; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + if (Console == NULL || GuiData == NULL) return; + if (!(Console->Selection.dwFlags & CONSOLE_MOUSE_DOWN)) return; - c = PointToCoord(Console, lParam); /* TODO: Scroll buffer to bring c into view */ + c = PointToCoord(Console, lParam); /* TODO: Scroll buffer to bring c into view */ - GuiConsoleUpdateSelection(Console, &c); + GuiConsoleUpdateSelection(Console, &c); } static VOID GuiConsoleRightMouseDown(HWND hWnd) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if (Console == NULL || GuiData == NULL) return; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + if (Console == NULL || GuiData == NULL) return; - if (!(Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)) - { - /* FIXME - paste text from clipboard */ - } - else - { - /* FIXME - copy selection to clipboard */ + if (!(Console->Selection.dwFlags & CONSOLE_SELECTION_NOT_EMPTY)) + { + /* FIXME - paste text from clipboard */ + } + else + { + /* FIXME - copy selection to clipboard */ - GuiConsoleUpdateSelection(Console, NULL); - } + GuiConsoleUpdateSelection(Console, NULL); + } } @@ -1400,74 +1400,74 @@ GuiConsoleRightMouseDown(HWND hWnd) static VOID GuiConsoleShowConsoleProperties(HWND hWnd, BOOL Defaults, PGUI_CONSOLE_DATA GuiData) { - PCSRSS_CONSOLE Console; - APPLET_PROC CPLFunc; - TCHAR szBuffer[MAX_PATH]; - ConsoleInfo SharedInfo; + PCSRSS_CONSOLE Console; + APPLET_PROC CPLFunc; + TCHAR szBuffer[MAX_PATH]; + ConsoleInfo SharedInfo; - DPRINT("GuiConsoleShowConsoleProperties entered\n"); + DPRINT("GuiConsoleShowConsoleProperties entered\n"); - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if (GuiData == NULL) + if (GuiData == NULL) { - DPRINT("GuiConsoleGetDataPointers failed\n"); - return; + DPRINT("GuiConsoleGetDataPointers failed\n"); + return; } - if (GuiData->ConsoleLibrary == NULL) + if (GuiData->ConsoleLibrary == NULL) { - GetWindowsDirectory(szBuffer,MAX_PATH); - _tcscat(szBuffer, _T("\\system32\\console.dll")); - GuiData->ConsoleLibrary = LoadLibrary(szBuffer); + GetWindowsDirectory(szBuffer,MAX_PATH); + _tcscat(szBuffer, _T("\\system32\\console.dll")); + GuiData->ConsoleLibrary = LoadLibrary(szBuffer); - if (GuiData->ConsoleLibrary == NULL) + if (GuiData->ConsoleLibrary == NULL) { - DPRINT1("failed to load console.dll"); - return; + DPRINT1("failed to load console.dll"); + return; } } - CPLFunc = (APPLET_PROC) GetProcAddress(GuiData->ConsoleLibrary, _T("CPlApplet")); - if (!CPLFunc) + CPLFunc = (APPLET_PROC) GetProcAddress(GuiData->ConsoleLibrary, _T("CPlApplet")); + if (!CPLFunc) { - DPRINT("Error: Console.dll misses CPlApplet export\n"); - return; + DPRINT("Error: Console.dll misses CPlApplet export\n"); + return; } - /* setup struct */ - SharedInfo.InsertMode = GuiData->InsertMode; - SharedInfo.HistoryBufferSize = GuiData->HistoryBufferSize; - SharedInfo.NumberOfHistoryBuffers = GuiData->NumberOfHistoryBuffers; - SharedInfo.ScreenText = GuiData->ScreenText; - SharedInfo.ScreenBackground = GuiData->ScreenBackground; - SharedInfo.PopupText = GuiData->PopupText; - SharedInfo.PopupBackground = GuiData->PopupBackground; - SharedInfo.WindowSize = (DWORD)MAKELONG(Console->Size.X, Console->Size.Y); - SharedInfo.WindowPosition = GuiData->WindowPosition; - SharedInfo.ScreenBuffer = (DWORD)MAKELONG(Console->ActiveBuffer->MaxX, Console->ActiveBuffer->MaxY); - SharedInfo.UseRasterFonts = GuiData->UseRasterFonts; - SharedInfo.FontSize = (DWORD)GuiData->FontSize; - SharedInfo.FontWeight = GuiData->FontWeight; - SharedInfo.CursorSize = Console->ActiveBuffer->CursorInfo.dwSize; - SharedInfo.HistoryNoDup = GuiData->HistoryNoDup; - SharedInfo.FullScreen = GuiData->FullScreen; - SharedInfo.QuickEdit = GuiData->QuickEdit; - memcpy(&SharedInfo.Colors[0], GuiData->Colors, sizeof(s_Colors)); + /* setup struct */ + SharedInfo.InsertMode = GuiData->InsertMode; + SharedInfo.HistoryBufferSize = GuiData->HistoryBufferSize; + SharedInfo.NumberOfHistoryBuffers = GuiData->NumberOfHistoryBuffers; + SharedInfo.ScreenText = GuiData->ScreenText; + SharedInfo.ScreenBackground = GuiData->ScreenBackground; + SharedInfo.PopupText = GuiData->PopupText; + SharedInfo.PopupBackground = GuiData->PopupBackground; + SharedInfo.WindowSize = (DWORD)MAKELONG(Console->Size.X, Console->Size.Y); + SharedInfo.WindowPosition = GuiData->WindowPosition; + SharedInfo.ScreenBuffer = (DWORD)MAKELONG(Console->ActiveBuffer->MaxX, Console->ActiveBuffer->MaxY); + SharedInfo.UseRasterFonts = GuiData->UseRasterFonts; + SharedInfo.FontSize = (DWORD)GuiData->FontSize; + SharedInfo.FontWeight = GuiData->FontWeight; + SharedInfo.CursorSize = Console->ActiveBuffer->CursorInfo.dwSize; + SharedInfo.HistoryNoDup = GuiData->HistoryNoDup; + SharedInfo.FullScreen = GuiData->FullScreen; + SharedInfo.QuickEdit = GuiData->QuickEdit; + memcpy(&SharedInfo.Colors[0], GuiData->Colors, sizeof(s_Colors)); - if (!CPLFunc(hWnd, CPL_INIT, 0, 0)) + if (!CPLFunc(hWnd, CPL_INIT, 0, 0)) { - DPRINT("Error: failed to initialize console.dll\n"); - return; + DPRINT("Error: failed to initialize console.dll\n"); + return; } - if (CPLFunc(hWnd, CPL_GETCOUNT, 0, 0) != 1) + if (CPLFunc(hWnd, CPL_GETCOUNT, 0, 0) != 1) { - DPRINT("Error: console.dll returned unexpected CPL count\n"); - return; + DPRINT("Error: console.dll returned unexpected CPL count\n"); + return; } - CPLFunc(hWnd, CPL_DBLCLK, (LPARAM)&SharedInfo, Defaults); + CPLFunc(hWnd, CPL_DBLCLK, (LPARAM)&SharedInfo, Defaults); } static LRESULT GuiConsoleHandleSysMenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, PGUI_CONSOLE_DATA GuiData) @@ -1476,25 +1476,25 @@ GuiConsoleHandleSysMenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, PGUI_CON switch(wParam) { - case ID_SYSTEM_EDIT_MARK: - case ID_SYSTEM_EDIT_COPY: - case ID_SYSTEM_EDIT_PASTE: - case ID_SYSTEM_EDIT_SELECTALL: - case ID_SYSTEM_EDIT_SCROLL: - case ID_SYSTEM_EDIT_FIND: - break; + case ID_SYSTEM_EDIT_MARK: + case ID_SYSTEM_EDIT_COPY: + case ID_SYSTEM_EDIT_PASTE: + case ID_SYSTEM_EDIT_SELECTALL: + case ID_SYSTEM_EDIT_SCROLL: + case ID_SYSTEM_EDIT_FIND: + break; - case ID_SYSTEM_DEFAULTS: - GuiConsoleShowConsoleProperties(hWnd, TRUE, GuiData); - break; + case ID_SYSTEM_DEFAULTS: + GuiConsoleShowConsoleProperties(hWnd, TRUE, GuiData); + break; - case ID_SYSTEM_PROPERTIES: - GuiConsoleShowConsoleProperties(hWnd, FALSE, GuiData); - break; + case ID_SYSTEM_PROPERTIES: + GuiConsoleShowConsoleProperties(hWnd, FALSE, GuiData); + break; - default: - Ret = DefWindowProcW(hWnd, WM_SYSCOMMAND, wParam, lParam); - break; + default: + Ret = DefWindowProcW(hWnd, WM_SYSCOMMAND, wParam, lParam); + break; } return Ret; } @@ -1502,105 +1502,105 @@ GuiConsoleHandleSysMenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam, PGUI_CON static VOID GuiConsoleGetMinMaxInfo(HWND hWnd, PMINMAXINFO minMaxInfo) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if((Console == NULL)|| (GuiData == NULL)) return; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + if((Console == NULL)|| (GuiData == NULL)) return; - DWORD windx = CONGUI_MIN_WIDTH * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)); - DWORD windy = CONGUI_MIN_HEIGHT * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION); + DWORD windx = CONGUI_MIN_WIDTH * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)); + DWORD windy = CONGUI_MIN_HEIGHT * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION); - minMaxInfo->ptMinTrackSize.x = windx; - minMaxInfo->ptMinTrackSize.y = windy; + minMaxInfo->ptMinTrackSize.x = windx; + minMaxInfo->ptMinTrackSize.y = windy; - windx = (Console->ActiveBuffer->MaxX) * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)); - windy = (Console->ActiveBuffer->MaxY) * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION); + windx = (Console->ActiveBuffer->MaxX) * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)); + windy = (Console->ActiveBuffer->MaxY) * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION); - if(Console->Size.X < Console->ActiveBuffer->MaxX) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar - if(Console->Size.Y < Console->ActiveBuffer->MaxY) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar + if(Console->Size.X < Console->ActiveBuffer->MaxX) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar + if(Console->Size.Y < Console->ActiveBuffer->MaxY) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar - minMaxInfo->ptMaxTrackSize.x = windx; - minMaxInfo->ptMaxTrackSize.y = windy; + minMaxInfo->ptMaxTrackSize.x = windx; + minMaxInfo->ptMaxTrackSize.y = windy; } static VOID GuiConsoleResize(HWND hWnd, WPARAM wParam, LPARAM lParam) { - PCSRSS_CONSOLE Console; - PGUI_CONSOLE_DATA GuiData; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - if((Console == NULL) || (GuiData == NULL)) return; + PCSRSS_CONSOLE Console; + PGUI_CONSOLE_DATA GuiData; + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + if((Console == NULL) || (GuiData == NULL)) return; - if ((GuiData->WindowSizeLock == FALSE) && (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED)) - { - PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; + if ((GuiData->WindowSizeLock == FALSE) && (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED)) + { + PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; - GuiData->WindowSizeLock = TRUE; + GuiData->WindowSizeLock = TRUE; - DWORD windx = LOWORD(lParam); - DWORD windy = HIWORD(lParam); + DWORD windx = LOWORD(lParam); + DWORD windy = HIWORD(lParam); - // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar) - if(Console->Size.X < Buff->MaxX) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar - if(Console->Size.Y < Buff->MaxY) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar + // Compensate for existing scroll bars (because lParam values do not accommodate scroll bar) + if(Console->Size.X < Buff->MaxX) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar + if(Console->Size.Y < Buff->MaxY) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar - DWORD charx = windx / GuiData->CharWidth; - DWORD chary = windy / GuiData->CharHeight; + DWORD charx = windx / GuiData->CharWidth; + DWORD chary = windy / GuiData->CharHeight; - // Character alignment (round size up or down) - if((windx % GuiData->CharWidth) >= (GuiData->CharWidth / 2)) ++charx; - if((windy % GuiData->CharHeight) >= (GuiData->CharHeight / 2)) ++chary; + // Character alignment (round size up or down) + if((windx % GuiData->CharWidth) >= (GuiData->CharWidth / 2)) ++charx; + if((windy % GuiData->CharHeight) >= (GuiData->CharHeight / 2)) ++chary; - // Compensate for added scroll bars in new window - if(charx < Buff->MaxX)windy -= GetSystemMetrics(SM_CYHSCROLL); // new window will have a horizontal scroll bar - if(chary < Buff->MaxY)windx -= GetSystemMetrics(SM_CXVSCROLL); // new window will have a vertical scroll bar + // Compensate for added scroll bars in new window + if(charx < Buff->MaxX)windy -= GetSystemMetrics(SM_CYHSCROLL); // new window will have a horizontal scroll bar + if(chary < Buff->MaxY)windx -= GetSystemMetrics(SM_CXVSCROLL); // new window will have a vertical scroll bar - charx = windx / GuiData->CharWidth; - chary = windy / GuiData->CharHeight; + charx = windx / GuiData->CharWidth; + chary = windy / GuiData->CharHeight; - // Character alignment (round size up or down) - if((windx % GuiData->CharWidth) >= (GuiData->CharWidth / 2)) ++charx; - if((windy % GuiData->CharHeight) >= (GuiData->CharHeight / 2)) ++chary; + // Character alignment (round size up or down) + if((windx % GuiData->CharWidth) >= (GuiData->CharWidth / 2)) ++charx; + if((windy % GuiData->CharHeight) >= (GuiData->CharHeight / 2)) ++chary; - // Resize window - if((charx != Console->Size.X) || (chary != Console->Size.Y)) - { - Console->Size.X = (charx <= Buff->MaxX) ? charx : Buff->MaxX; - Console->Size.Y = (chary <= Buff->MaxY) ? chary : Buff->MaxY; - } + // Resize window + if((charx != Console->Size.X) || (chary != Console->Size.Y)) + { + Console->Size.X = (charx <= Buff->MaxX) ? charx : Buff->MaxX; + Console->Size.Y = (chary <= Buff->MaxY) ? chary : Buff->MaxY; + } - GuiConsoleInitScrollbar(Console, hWnd); + GuiConsoleInitScrollbar(Console, hWnd); - // Adjust the start of the visible area if we are attempting to show nonexistent areas - if((Buff->MaxX - Buff->ShowX) < Console->Size.X) Buff->ShowX = Buff->MaxX - Console->Size.X; - if((Buff->MaxY - Buff->ShowY) < Console->Size.Y) Buff->ShowY = Buff->MaxY - Console->Size.Y; - InvalidateRect(hWnd, NULL, TRUE); + // Adjust the start of the visible area if we are attempting to show nonexistent areas + if((Buff->MaxX - Buff->ShowX) < Console->Size.X) Buff->ShowX = Buff->MaxX - Console->Size.X; + if((Buff->MaxY - Buff->ShowY) < Console->Size.Y) Buff->ShowY = Buff->MaxY - Console->Size.Y; + InvalidateRect(hWnd, NULL, TRUE); - GuiData->WindowSizeLock = FALSE; - } + GuiData->WindowSizeLock = FALSE; + } } VOID FASTCALL GuiConsoleHandleScrollbarMenu() { - HMENU hMenu; + HMENU hMenu; - hMenu = CreatePopupMenu(); - if (hMenu == NULL) + hMenu = CreatePopupMenu(); + if (hMenu == NULL) { - DPRINT("CreatePopupMenu failed\n"); - return; + DPRINT("CreatePopupMenu failed\n"); + return; } - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE); - //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1); - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP); - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM); - //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1); - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP); - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN); - //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1); - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP); - //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLHERE); + //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLTOP); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLBOTTOM); + //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_UP); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLPAGE_DOWN); + //InsertItem(hMenu, MFT_SEPARATOR, MIIM_FTYPE, 0, NULL, -1); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLUP); + //InsertItem(hMenu, MIIM_STRING, MIIM_ID | MIIM_FTYPE | MIIM_STRING, 0, NULL, IDS_SCROLLDOWN); } @@ -1700,258 +1700,258 @@ GuiResizeBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD static VOID GuiApplyUserSettings(PCSRSS_CONSOLE Console, PGUI_CONSOLE_DATA GuiData, PConsoleInfo pConInfo) { - DWORD windx, windy; - PCSRSS_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer; - COORD BufSize; - BOOL SizeChanged = FALSE; + DWORD windx, windy; + PCSRSS_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer; + COORD BufSize; + BOOL SizeChanged = FALSE; - EnterCriticalSection(&Console->Lock); + EnterCriticalSection(&Console->Lock); - /* apply text / background color */ - GuiData->ScreenText = pConInfo->ScreenText; - GuiData->ScreenBackground = pConInfo->ScreenBackground; + /* apply text / background color */ + GuiData->ScreenText = pConInfo->ScreenText; + GuiData->ScreenBackground = pConInfo->ScreenBackground; - /* apply cursor size */ - ActiveBuffer->CursorInfo.dwSize = min(max(pConInfo->CursorSize, 1), 100); + /* apply cursor size */ + ActiveBuffer->CursorInfo.dwSize = min(max(pConInfo->CursorSize, 1), 100); - windx = LOWORD(pConInfo->WindowSize); - windy = HIWORD(pConInfo->WindowSize); + windx = LOWORD(pConInfo->WindowSize); + windy = HIWORD(pConInfo->WindowSize); - if (windx != Console->Size.X || windy != Console->Size.Y) - { - /* resize window */ - Console->Size.X = windx; - Console->Size.Y = windy; - SizeChanged = TRUE; - } + if (windx != Console->Size.X || windy != Console->Size.Y) + { + /* resize window */ + Console->Size.X = windx; + Console->Size.Y = windy; + SizeChanged = TRUE; + } - BufSize.X = LOWORD(pConInfo->ScreenBuffer); - BufSize.Y = HIWORD(pConInfo->ScreenBuffer); - if (BufSize.X != ActiveBuffer->MaxX || BufSize.Y != ActiveBuffer->MaxY) - { - if (NT_SUCCESS(GuiResizeBuffer(Console, ActiveBuffer, BufSize))) - SizeChanged = TRUE; - } + BufSize.X = LOWORD(pConInfo->ScreenBuffer); + BufSize.Y = HIWORD(pConInfo->ScreenBuffer); + if (BufSize.X != ActiveBuffer->MaxX || BufSize.Y != ActiveBuffer->MaxY) + { + if (NT_SUCCESS(GuiResizeBuffer(Console, ActiveBuffer, BufSize))) + SizeChanged = TRUE; + } - if (SizeChanged) - { - GuiData->WindowSizeLock = TRUE; - GuiConsoleInitScrollbar(Console, pConInfo->hConsoleWindow); - GuiData->WindowSizeLock = FALSE; - } + if (SizeChanged) + { + GuiData->WindowSizeLock = TRUE; + GuiConsoleInitScrollbar(Console, pConInfo->hConsoleWindow); + GuiData->WindowSizeLock = FALSE; + } - LeaveCriticalSection(&Console->Lock); - InvalidateRect(pConInfo->hConsoleWindow, NULL, TRUE); + LeaveCriticalSection(&Console->Lock); + InvalidateRect(pConInfo->hConsoleWindow, NULL, TRUE); } static LRESULT GuiConsoleHandleScroll(HWND hwnd, UINT uMsg, WPARAM wParam) { - PCSRSS_CONSOLE Console; - PCSRSS_SCREEN_BUFFER Buff; - PGUI_CONSOLE_DATA GuiData; - SCROLLINFO sInfo; - int fnBar; - int old_pos, Maximum; - PUSHORT pShowXY; + PCSRSS_CONSOLE Console; + PCSRSS_SCREEN_BUFFER Buff; + PGUI_CONSOLE_DATA GuiData; + SCROLLINFO sInfo; + int fnBar; + int old_pos, Maximum; + PUSHORT pShowXY; - GuiConsoleGetDataPointers(hwnd, &Console, &GuiData); - if (Console == NULL || GuiData == NULL) - return FALSE; - Buff = Console->ActiveBuffer; + GuiConsoleGetDataPointers(hwnd, &Console, &GuiData); + if (Console == NULL || GuiData == NULL) + return FALSE; + Buff = Console->ActiveBuffer; - if (uMsg == WM_HSCROLL) - { - fnBar = SB_HORZ; - Maximum = Buff->MaxX - Console->Size.X; - pShowXY = &Buff->ShowX; - } - else - { - fnBar = SB_VERT; - Maximum = Buff->MaxY - Console->Size.Y; - pShowXY = &Buff->ShowY; - } + if (uMsg == WM_HSCROLL) + { + fnBar = SB_HORZ; + Maximum = Buff->MaxX - Console->Size.X; + pShowXY = &Buff->ShowX; + } + else + { + fnBar = SB_VERT; + Maximum = Buff->MaxY - Console->Size.Y; + pShowXY = &Buff->ShowY; + } - /* set scrollbar sizes */ - sInfo.cbSize = sizeof(SCROLLINFO); - sInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE | SIF_TRACKPOS; + /* set scrollbar sizes */ + sInfo.cbSize = sizeof(SCROLLINFO); + sInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE | SIF_TRACKPOS; - if (!GetScrollInfo(hwnd, fnBar, &sInfo)) - { - return FALSE; - } + if (!GetScrollInfo(hwnd, fnBar, &sInfo)) + { + return FALSE; + } - old_pos = sInfo.nPos; + old_pos = sInfo.nPos; - switch(LOWORD(wParam)) - { - case SB_LINELEFT: - sInfo.nPos -= 1; - break; + switch(LOWORD(wParam)) + { + case SB_LINELEFT: + sInfo.nPos -= 1; + break; - case SB_LINERIGHT: - sInfo.nPos += 1; - break; + case SB_LINERIGHT: + sInfo.nPos += 1; + break; - case SB_PAGELEFT: - sInfo.nPos -= sInfo.nPage; - break; + case SB_PAGELEFT: + sInfo.nPos -= sInfo.nPage; + break; - case SB_PAGERIGHT: - sInfo.nPos += sInfo.nPage; - break; + case SB_PAGERIGHT: + sInfo.nPos += sInfo.nPage; + break; - case SB_THUMBTRACK: - sInfo.nPos = sInfo.nTrackPos; - ConioPause(Console, PAUSED_FROM_SCROLLBAR); - break; + case SB_THUMBTRACK: + sInfo.nPos = sInfo.nTrackPos; + ConioPause(Console, PAUSED_FROM_SCROLLBAR); + break; - case SB_THUMBPOSITION: - ConioUnpause(Console, PAUSED_FROM_SCROLLBAR); - break; + case SB_THUMBPOSITION: + ConioUnpause(Console, PAUSED_FROM_SCROLLBAR); + break; - case SB_TOP: - sInfo.nPos = sInfo.nMin; - break; + case SB_TOP: + sInfo.nPos = sInfo.nMin; + break; - case SB_BOTTOM: - sInfo.nPos = sInfo.nMax; - break; + case SB_BOTTOM: + sInfo.nPos = sInfo.nMax; + break; - default: - break; - } + default: + break; + } - sInfo.nPos = max(sInfo.nPos, 0); - sInfo.nPos = min(sInfo.nPos, Maximum); + sInfo.nPos = max(sInfo.nPos, 0); + sInfo.nPos = min(sInfo.nPos, Maximum); - if (old_pos != sInfo.nPos) - { - USHORT OldX = Buff->ShowX; - USHORT OldY = Buff->ShowY; - *pShowXY = sInfo.nPos; + if (old_pos != sInfo.nPos) + { + USHORT OldX = Buff->ShowX; + USHORT OldY = Buff->ShowY; + *pShowXY = sInfo.nPos; - ScrollWindowEx(hwnd, - (OldX - Buff->ShowX) * GuiData->CharWidth, - (OldY - Buff->ShowY) * GuiData->CharHeight, - NULL, - NULL, - NULL, - NULL, - SW_INVALIDATE); + ScrollWindowEx(hwnd, + (OldX - Buff->ShowX) * GuiData->CharWidth, + (OldY - Buff->ShowY) * GuiData->CharHeight, + NULL, + NULL, + NULL, + NULL, + SW_INVALIDATE); - sInfo.fMask = SIF_POS; - SetScrollInfo(hwnd, fnBar, &sInfo, TRUE); + sInfo.fMask = SIF_POS; + SetScrollInfo(hwnd, fnBar, &sInfo, TRUE); - UpdateWindow(hwnd); - } - return 0; + UpdateWindow(hwnd); + } + return 0; } static LRESULT CALLBACK GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - LRESULT Result = 0; - PGUI_CONSOLE_DATA GuiData = NULL; - PCSRSS_CONSOLE Console = NULL; + LRESULT Result = 0; + PGUI_CONSOLE_DATA GuiData = NULL; + PCSRSS_CONSOLE Console = NULL; - GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); + GuiConsoleGetDataPointers(hWnd, &Console, &GuiData); - switch(msg) + switch(msg) { - case WM_NCCREATE: + case WM_NCCREATE: Result = (LRESULT) GuiConsoleHandleNcCreate(hWnd, (CREATESTRUCTW *) lParam); break; - case WM_PAINT: + case WM_PAINT: GuiConsoleHandlePaint(hWnd, (HDC)wParam); break; - case WM_KEYDOWN: - case WM_KEYUP: - case WM_SYSKEYDOWN: - case WM_SYSKEYUP: - case WM_CHAR: + case WM_KEYDOWN: + case WM_KEYUP: + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + case WM_CHAR: GuiConsoleHandleKey(hWnd, msg, wParam, lParam); break; - case WM_TIMER: + case WM_TIMER: GuiConsoleHandleTimer(hWnd); break; - case WM_CLOSE: + case WM_CLOSE: GuiConsoleHandleClose(hWnd); break; - case WM_NCDESTROY: + case WM_NCDESTROY: GuiConsoleHandleNcDestroy(hWnd); break; - case WM_LBUTTONDOWN: - GuiConsoleLeftMouseDown(hWnd, lParam); + case WM_LBUTTONDOWN: + GuiConsoleLeftMouseDown(hWnd, lParam); break; - case WM_LBUTTONUP: - GuiConsoleLeftMouseUp(hWnd, lParam); + case WM_LBUTTONUP: + GuiConsoleLeftMouseUp(hWnd, lParam); break; - case WM_RBUTTONDOWN: - GuiConsoleRightMouseDown(hWnd); + case WM_RBUTTONDOWN: + GuiConsoleRightMouseDown(hWnd); break; - case WM_MOUSEMOVE: - GuiConsoleMouseMove(hWnd, wParam, lParam); + case WM_MOUSEMOVE: + GuiConsoleMouseMove(hWnd, wParam, lParam); break; - case WM_SYSCOMMAND: - Result = GuiConsoleHandleSysMenuCommand(hWnd, wParam, lParam, GuiData); - break; - case WM_HSCROLL: - case WM_VSCROLL: - Result = GuiConsoleHandleScroll(hWnd, msg, wParam); - break; - case WM_GETMINMAXINFO: - GuiConsoleGetMinMaxInfo(hWnd, (PMINMAXINFO)lParam); - break; - case WM_SIZE: - GuiConsoleResize(hWnd, wParam, lParam); - break; - case PM_APPLY_CONSOLE_INFO: - GuiApplyUserSettings(Console, GuiData, (PConsoleInfo)wParam); - if (lParam) - { - GuiConsoleWriteUserSettings(Console, GuiData); - } - break; - default: + case WM_SYSCOMMAND: + Result = GuiConsoleHandleSysMenuCommand(hWnd, wParam, lParam, GuiData); + break; + case WM_HSCROLL: + case WM_VSCROLL: + Result = GuiConsoleHandleScroll(hWnd, msg, wParam); + break; + case WM_GETMINMAXINFO: + GuiConsoleGetMinMaxInfo(hWnd, (PMINMAXINFO)lParam); + break; + case WM_SIZE: + GuiConsoleResize(hWnd, wParam, lParam); + break; + case PM_APPLY_CONSOLE_INFO: + GuiApplyUserSettings(Console, GuiData, (PConsoleInfo)wParam); + if (lParam) + { + GuiConsoleWriteUserSettings(Console, GuiData); + } + break; + default: Result = DefWindowProcW(hWnd, msg, wParam, lParam); break; } - return Result; + return Result; } static LRESULT CALLBACK GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - HWND NewWindow; - LONG WindowCount; - MSG Msg; - PWCHAR Buffer, Title; - PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) lParam; + HWND NewWindow; + LONG WindowCount; + MSG Msg; + PWCHAR Buffer, Title; + PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) lParam; - switch(msg) + switch(msg) { - case WM_CREATE: + case WM_CREATE: SetWindowLongW(hWnd, GWL_USERDATA, 0); return 0; - case PM_CREATE_CONSOLE: + case PM_CREATE_CONSOLE: Buffer = HeapAlloc(Win32CsrApiHeap, 0, Console->Title.Length + sizeof(WCHAR)); if (NULL != Buffer) - { + { memcpy(Buffer, Console->Title.Buffer, Console->Title.Length); Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0'; Title = Buffer; - } + } else - { + { Title = L""; - } + } NewWindow = CreateWindowExW(WS_EX_CLIENTEDGE, L"ConsoleWindowClass", Title, @@ -1965,41 +1965,41 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) (HINSTANCE) GetModuleHandleW(NULL), (PVOID) Console); if (NULL != Buffer) - { + { HeapFree(Win32CsrApiHeap, 0, Buffer); - } + } if (NULL != NewWindow) - { + { SetWindowLongW(hWnd, GWL_USERDATA, GetWindowLongW(hWnd, GWL_USERDATA) + 1); if (wParam) { ShowWindow(NewWindow, SW_SHOW); } - } + } return (LRESULT) NewWindow; - case PM_DESTROY_CONSOLE: + case PM_DESTROY_CONSOLE: /* Window creation is done using a PostMessage(), so it's possible that the * window that we want to destroy doesn't exist yet. So first empty the message * queue */ while(PeekMessageW(&Msg, NULL, 0, 0, PM_REMOVE)) - { + { TranslateMessage(&Msg); DispatchMessageW(&Msg); - } + } DestroyWindow(Console->hWindow); Console->hWindow = NULL; WindowCount = GetWindowLongW(hWnd, GWL_USERDATA); WindowCount--; SetWindowLongW(hWnd, GWL_USERDATA, WindowCount); if (0 == WindowCount) - { + { NotifyWnd = NULL; DestroyWindow(hWnd); PrivateCsrssManualGuiCheck(-1); PostQuitMessage(0); - } + } return 0; - default: + default: return DefWindowProcW(hWnd, msg, wParam, lParam); } } @@ -2007,209 +2007,209 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) static DWORD WINAPI GuiConsoleGuiThread(PVOID Data) { - MSG msg; - PHANDLE GraphicsStartupEvent = (PHANDLE) Data; + MSG msg; + PHANDLE GraphicsStartupEvent = (PHANDLE) Data; - NotifyWnd = CreateWindowW(L"Win32CsrCreateNotify", - L"", - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - NULL, - NULL, - (HINSTANCE) GetModuleHandleW(NULL), - NULL); - if (NULL == NotifyWnd) + NotifyWnd = CreateWindowW(L"Win32CsrCreateNotify", + L"", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + (HINSTANCE) GetModuleHandleW(NULL), + NULL); + if (NULL == NotifyWnd) { - PrivateCsrssManualGuiCheck(-1); - SetEvent(*GraphicsStartupEvent); - return 1; + PrivateCsrssManualGuiCheck(-1); + SetEvent(*GraphicsStartupEvent); + return 1; } - SetEvent(*GraphicsStartupEvent); + SetEvent(*GraphicsStartupEvent); - while(GetMessageW(&msg, NULL, 0, 0)) + while(GetMessageW(&msg, NULL, 0, 0)) { - TranslateMessage(&msg); - DispatchMessageW(&msg); + TranslateMessage(&msg); + DispatchMessageW(&msg); } - return 1; + return 1; } static BOOL GuiInit(VOID) { - WNDCLASSEXW wc; + WNDCLASSEXW wc; - if (NULL == NotifyWnd) + if (NULL == NotifyWnd) { - PrivateCsrssManualGuiCheck(+1); + PrivateCsrssManualGuiCheck(+1); } - wc.cbSize = sizeof(WNDCLASSEXW); - wc.lpszClassName = L"Win32CsrCreateNotify"; - wc.lpfnWndProc = GuiConsoleNotifyWndProc; - wc.style = 0; - wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hIconSm = NULL; - if (RegisterClassExW(&wc) == 0) + wc.cbSize = sizeof(WNDCLASSEXW); + wc.lpszClassName = L"Win32CsrCreateNotify"; + wc.lpfnWndProc = GuiConsoleNotifyWndProc; + wc.style = 0; + wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hIconSm = NULL; + if (RegisterClassExW(&wc) == 0) { - DPRINT1("Failed to register notify wndproc\n"); - return FALSE; + DPRINT1("Failed to register notify wndproc\n"); + return FALSE; } - wc.cbSize = sizeof(WNDCLASSEXW); - wc.lpszClassName = L"ConsoleWindowClass"; - wc.lpfnWndProc = GuiConsoleWndProc; - wc.style = 0; - wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); - wc.hIcon = LoadIconW(GetModuleHandleW(L"win32csr"), MAKEINTRESOURCEW(1)); - wc.hCursor = LoadCursorW(NULL, (LPCWSTR) IDC_ARROW); - wc.hbrBackground = CreateSolidBrush(RGB(0,0,0)); - wc.lpszMenuName = NULL; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hIconSm = LoadImageW(GetModuleHandleW(L"win32csr"), MAKEINTRESOURCEW(1), IMAGE_ICON, - GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), - LR_SHARED); - if (RegisterClassExW(&wc) == 0) + wc.cbSize = sizeof(WNDCLASSEXW); + wc.lpszClassName = L"ConsoleWindowClass"; + wc.lpfnWndProc = GuiConsoleWndProc; + wc.style = 0; + wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); + wc.hIcon = LoadIconW(GetModuleHandleW(L"win32csr"), MAKEINTRESOURCEW(1)); + wc.hCursor = LoadCursorW(NULL, (LPCWSTR) IDC_ARROW); + wc.hbrBackground = CreateSolidBrush(RGB(0,0,0)); + wc.lpszMenuName = NULL; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hIconSm = LoadImageW(GetModuleHandleW(L"win32csr"), MAKEINTRESOURCEW(1), IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), + LR_SHARED); + if (RegisterClassExW(&wc) == 0) { - DPRINT1("Failed to register console wndproc\n"); - return FALSE; + DPRINT1("Failed to register console wndproc\n"); + return FALSE; } - return TRUE; + return TRUE; } static VOID WINAPI GuiInitScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer) { - Buffer->DefaultAttrib = DEFAULT_ATTRIB; + Buffer->DefaultAttrib = DEFAULT_ATTRIB; } static BOOL WINAPI GuiChangeTitle(PCSRSS_CONSOLE Console) { - PWCHAR Buffer, Title; + PWCHAR Buffer, Title; - Buffer = HeapAlloc(Win32CsrApiHeap, 0, - Console->Title.Length + sizeof(WCHAR)); - if (NULL != Buffer) + Buffer = HeapAlloc(Win32CsrApiHeap, 0, + Console->Title.Length + sizeof(WCHAR)); + if (NULL != Buffer) { - memcpy(Buffer, Console->Title.Buffer, Console->Title.Length); - Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0'; - Title = Buffer; + memcpy(Buffer, Console->Title.Buffer, Console->Title.Length); + Buffer[Console->Title.Length / sizeof(WCHAR)] = L'\0'; + Title = Buffer; } - else + else { - Title = L""; + Title = L""; } - SendMessageW(Console->hWindow, WM_SETTEXT, 0, (LPARAM) Title); + SendMessageW(Console->hWindow, WM_SETTEXT, 0, (LPARAM) Title); - if (NULL != Buffer) + if (NULL != Buffer) { - HeapFree(Win32CsrApiHeap, 0, Buffer); + HeapFree(Win32CsrApiHeap, 0, Buffer); } - return TRUE; + return TRUE; } static BOOL WINAPI GuiChangeIcon(PCSRSS_CONSOLE Console, HICON hWindowIcon) { - SendMessageW(Console->hWindow, WM_SETICON, ICON_BIG, (LPARAM)hWindowIcon); - SendMessageW(Console->hWindow, WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon); + SendMessageW(Console->hWindow, WM_SETICON, ICON_BIG, (LPARAM)hWindowIcon); + SendMessageW(Console->hWindow, WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon); - return TRUE; + return TRUE; } static VOID WINAPI GuiCleanupConsole(PCSRSS_CONSOLE Console) { - SendMessageW(NotifyWnd, PM_DESTROY_CONSOLE, 0, (LPARAM) Console); + SendMessageW(NotifyWnd, PM_DESTROY_CONSOLE, 0, (LPARAM) Console); } static CSRSS_CONSOLE_VTBL GuiVtbl = { - GuiInitScreenBuffer, - GuiWriteStream, - GuiDrawRegion, - GuiSetCursorInfo, - GuiSetScreenInfo, - GuiUpdateScreenInfo, - GuiChangeTitle, - GuiCleanupConsole, - GuiChangeIcon, - GuiResizeBuffer, + GuiInitScreenBuffer, + GuiWriteStream, + GuiDrawRegion, + GuiSetCursorInfo, + GuiSetScreenInfo, + GuiUpdateScreenInfo, + GuiChangeTitle, + GuiCleanupConsole, + GuiChangeIcon, + GuiResizeBuffer, }; NTSTATUS FASTCALL GuiInitConsole(PCSRSS_CONSOLE Console, BOOL Visible) { - HANDLE GraphicsStartupEvent; - HANDLE ThreadHandle; - PGUI_CONSOLE_DATA GuiData; + HANDLE GraphicsStartupEvent; + HANDLE ThreadHandle; + PGUI_CONSOLE_DATA GuiData; - if (! ConsInitialized) + if (! ConsInitialized) { - ConsInitialized = TRUE; - if (! GuiInit()) + ConsInitialized = TRUE; + if (! GuiInit()) { - ConsInitialized = FALSE; - return STATUS_UNSUCCESSFUL; + ConsInitialized = FALSE; + return STATUS_UNSUCCESSFUL; } } - Console->Vtbl = &GuiVtbl; - if (NULL == NotifyWnd) + Console->Vtbl = &GuiVtbl; + if (NULL == NotifyWnd) { - GraphicsStartupEvent = CreateEventW(NULL, FALSE, FALSE, NULL); - if (NULL == GraphicsStartupEvent) + GraphicsStartupEvent = CreateEventW(NULL, FALSE, FALSE, NULL); + if (NULL == GraphicsStartupEvent) { - return STATUS_UNSUCCESSFUL; + return STATUS_UNSUCCESSFUL; } - ThreadHandle = CreateThread(NULL, - 0, - GuiConsoleGuiThread, - (PVOID) &GraphicsStartupEvent, - 0, - NULL); - if (NULL == ThreadHandle) + ThreadHandle = CreateThread(NULL, + 0, + GuiConsoleGuiThread, + (PVOID) &GraphicsStartupEvent, + 0, + NULL); + if (NULL == ThreadHandle) { - NtClose(GraphicsStartupEvent); - DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n"); - return STATUS_UNSUCCESSFUL; + NtClose(GraphicsStartupEvent); + DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n"); + return STATUS_UNSUCCESSFUL; } - SetThreadPriority(ThreadHandle, THREAD_PRIORITY_HIGHEST); - CloseHandle(ThreadHandle); + SetThreadPriority(ThreadHandle, THREAD_PRIORITY_HIGHEST); + CloseHandle(ThreadHandle); - WaitForSingleObject(GraphicsStartupEvent, INFINITE); - CloseHandle(GraphicsStartupEvent); + WaitForSingleObject(GraphicsStartupEvent, INFINITE); + CloseHandle(GraphicsStartupEvent); - if (NULL == NotifyWnd) + if (NULL == NotifyWnd) { - DPRINT1("Win32Csr: Failed to create notification window.\n"); - return STATUS_UNSUCCESSFUL; + DPRINT1("Win32Csr: Failed to create notification window.\n"); + return STATUS_UNSUCCESSFUL; } } GuiData = HeapAlloc(Win32CsrApiHeap, HEAP_ZERO_MEMORY, sizeof(GUI_CONSOLE_DATA)); if (!GuiData) - { + { DPRINT1("Win32Csr: Failed to create GUI_CONSOLE_DATA\n"); return STATUS_UNSUCCESSFUL; - } + } Console->PrivateData = (PVOID) GuiData; /* @@ -2229,7 +2229,7 @@ GuiInitConsole(PCSRSS_CONSOLE Console, BOOL Visible) CloseHandle(GuiData->hGuiInitEvent); GuiData->hGuiInitEvent = NULL; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } /* EOF */ diff --git a/reactos/subsystems/win32/csrss/win32csr/handle.c b/reactos/subsystems/win32/csrss/win32csr/handle.c index 87f5c6348a4..ce8db451681 100644 --- a/reactos/subsystems/win32/csrss/win32csr/handle.c +++ b/reactos/subsystems/win32/csrss/win32csr/handle.c @@ -101,7 +101,7 @@ Win32CsrLockObject(PCSRSS_PROCESS_DATA ProcessData, { ULONG_PTR h = (ULONG_PTR)Handle >> 2; - DPRINT("CsrGetObject, Object: %x, %x, %x\n", + DPRINT("CsrGetObject, Object: %x, %x, %x\n", Object, Handle, ProcessData ? ProcessData->HandleTableSize : 0); RtlEnterCriticalSection(&ProcessData->HandleTableLock); @@ -271,7 +271,7 @@ CSR_API(CsrGetHandle) PCSRSS_CONSOLE Console = ProcessData->Console; Object_t *Object; - + EnterCriticalSection(&Console->Lock); if (Request->Type == GET_OUTPUT_HANDLE) Object = &Console->ActiveBuffer->Header; @@ -366,7 +366,7 @@ CSR_API(CsrDuplicateHandle) return STATUS_INVALID_PARAMETER; } } - + Request->Status = Win32CsrInsertObject(ProcessData, &Request->Data.DuplicateHandleRequest.Handle, Entry->Object, diff --git a/reactos/subsystems/win32/csrss/win32csr/harderror.c b/reactos/subsystems/win32/csrss/win32csr/harderror.c index 4b46e340842..0e10aad8a9d 100644 --- a/reactos/subsystems/win32/csrss/win32csr/harderror.c +++ b/reactos/subsystems/win32/csrss/win32csr/harderror.c @@ -84,8 +84,8 @@ CsrpGetClientFileName( ClientFileNameU->MaximumLength = ModuleData.BaseDllName.MaximumLength; ClientFileNameU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), - HEAP_ZERO_MEMORY, - ClientFileNameU->MaximumLength); + HEAP_ZERO_MEMORY, + ClientFileNameU->MaximumLength); Status = NtReadVirtualMemory(hProcess, ModuleData.BaseDllName.Buffer, @@ -123,9 +123,9 @@ CsrpCaptureStringParameters( UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; /* Read all strings from client space */ - for (nParam = 0; - nParam < HardErrorMessage->NumberOfParameters; - nParam++, UnicodeStringParameterMask >>= 1) + for (nParam = 0; + nParam < HardErrorMessage->NumberOfParameters; + nParam++, UnicodeStringParameterMask >>= 1) { Parameters[nParam] = 0; @@ -194,9 +194,9 @@ CsrpFreeStringParameters( UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask; /* Loop all parameters */ - for (nParam = 0; - nParam < HardErrorMessage->NumberOfParameters; - nParam++, UnicodeStringParameterMask >>= 1) + for (nParam = 0; + nParam < HardErrorMessage->NumberOfParameters; + nParam++, UnicodeStringParameterMask >>= 1) { /* Check if the current parameter is a string */ if (UnicodeStringParameterMask & 0x01) @@ -292,8 +292,8 @@ CsrpFormatMessages( /* Allocate a buffer for the caption */ CaptionStringU->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), - HEAP_ZERO_MEMORY, - CaptionStringU->MaximumLength); + HEAP_ZERO_MEMORY, + CaptionStringU->MaximumLength); /* Append the file name, seperator and the caption text */ CaptionStringU->Length = 0; @@ -383,13 +383,13 @@ CsrpFormatMessages( { /* Print the string into the buffer */ StringCbPrintfW(TextStringU->Buffer, - TextStringU->MaximumLength, - FormatString, - Parameters[0], - Parameters[1], - Parameters[2], - Parameters[3], - Parameters[4]); + TextStringU->MaximumLength, + FormatString, + Parameters[0], + Parameters[1], + Parameters[2], + Parameters[3], + Parameters[4]); Status = STATUS_SUCCESS; } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) @@ -424,30 +424,30 @@ CsrpMessageBox( /* Set the message box type */ switch (ValidResponseOptions) { - case OptionAbortRetryIgnore: - Type = MB_ABORTRETRYIGNORE; - break; - case OptionOk: - Type = MB_OK; - break; - case OptionOkCancel: - Type = MB_OKCANCEL; - break; - case OptionRetryCancel: - Type = MB_RETRYCANCEL; - break; - case OptionYesNo: - Type = MB_YESNO; - break; - case OptionYesNoCancel: - Type = MB_YESNOCANCEL; - break; - case OptionShutdownSystem: - Type = MB_RETRYCANCEL; // FIXME??? - break; + case OptionAbortRetryIgnore: + Type = MB_ABORTRETRYIGNORE; + break; + case OptionOk: + Type = MB_OK; + break; + case OptionOkCancel: + Type = MB_OKCANCEL; + break; + case OptionRetryCancel: + Type = MB_RETRYCANCEL; + break; + case OptionYesNo: + Type = MB_YESNO; + break; + case OptionYesNoCancel: + Type = MB_YESNOCANCEL; + break; + case OptionShutdownSystem: + Type = MB_RETRYCANCEL; // FIXME??? + break; /* Anything else is invalid */ - default: - return ResponseNotHandled; + default: + return ResponseNotHandled; } /* Set severity */ @@ -457,7 +457,7 @@ CsrpMessageBox( Type |= MB_SYSTEMMODAL | MB_SETFOREGROUND; - DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n", + DPRINT("Text = '%S', Caption = '%S', Severity = %d, Type = 0x%lx\n", Text, Caption, Severity, Type); /* Display a message box */ @@ -466,15 +466,15 @@ CsrpMessageBox( /* Return response value */ switch (MessageBoxResponse) { - case IDOK: return ResponseOk; - case IDCANCEL: return ResponseCancel; - case IDYES: return ResponseYes; - case IDNO: return ResponseNo; - case IDABORT: return ResponseAbort; - case IDIGNORE: return ResponseIgnore; - case IDRETRY: return ResponseRetry; - case IDTRYAGAIN: return ResponseTryAgain; - case IDCONTINUE: return ResponseContinue; + case IDOK: return ResponseOk; + case IDCANCEL: return ResponseCancel; + case IDYES: return ResponseYes; + case IDNO: return ResponseNo; + case IDABORT: return ResponseAbort; + case IDIGNORE: return ResponseIgnore; + case IDRETRY: return ResponseRetry; + case IDTRYAGAIN: return ResponseTryAgain; + case IDCONTINUE: return ResponseContinue; } return ResponseNotHandled; @@ -537,7 +537,7 @@ Win32CsrHardError( if (!NT_SUCCESS(Status)) { - return FALSE; + return FALSE; } /* Display the message box */ diff --git a/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c b/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c index c9071686e13..f078fe1e2a6 100644 --- a/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c +++ b/reactos/subsystems/win32/csrss/win32csr/tuiconsole.c @@ -20,15 +20,15 @@ static BOOL ConsInitialized = FALSE; static LRESULT CALLBACK TuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (msg == WM_ACTIVATE) + if (msg == WM_ACTIVATE) { - if (LOWORD(wParam) != WA_INACTIVE) + if (LOWORD(wParam) != WA_INACTIVE) { - SetFocus(hWnd); - ConioDrawConsole(ActiveConsole); + SetFocus(hWnd); + ConioDrawConsole(ActiveConsole); } } - return DefWindowProcW(hWnd, msg, wParam, lParam); + return DefWindowProcW(hWnd, msg, wParam, lParam); } static BOOL FASTCALL @@ -63,19 +63,19 @@ cleanup: static BOOL FASTCALL TuiInit(DWORD OemCP) { - CONSOLE_SCREEN_BUFFER_INFO ScrInfo; - DWORD BytesReturned; - WNDCLASSEXW wc; - USHORT TextAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; + CONSOLE_SCREEN_BUFFER_INFO ScrInfo; + DWORD BytesReturned; + WNDCLASSEXW wc; + USHORT TextAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; - TuiStartService(L"Blue"); + TuiStartService(L"Blue"); - ConsoleDeviceHandle = CreateFileW(L"\\\\.\\BlueScreen", FILE_ALL_ACCESS, 0, NULL, - OPEN_EXISTING, 0, NULL); - if (INVALID_HANDLE_VALUE == ConsoleDeviceHandle) + ConsoleDeviceHandle = CreateFileW(L"\\\\.\\BlueScreen", FILE_ALL_ACCESS, 0, NULL, + OPEN_EXISTING, 0, NULL); + if (INVALID_HANDLE_VALUE == ConsoleDeviceHandle) { - DPRINT1("Failed to open BlueScreen.\n"); - return FALSE; + DPRINT1("Failed to open BlueScreen.\n"); + return FALSE; } if (!DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_LOADFONT, @@ -93,163 +93,163 @@ TuiInit(DWORD OemCP) DPRINT1("Failed to set text attribute\n"); } - ActiveConsole = NULL; - InitializeCriticalSection(&ActiveConsoleLock); - if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO, - NULL, 0, &ScrInfo, sizeof(ScrInfo), &BytesReturned, NULL)) + ActiveConsole = NULL; + InitializeCriticalSection(&ActiveConsoleLock); + if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO, + NULL, 0, &ScrInfo, sizeof(ScrInfo), &BytesReturned, NULL)) { - DPRINT1("Failed to get console info\n"); - return FALSE; + DPRINT1("Failed to get console info\n"); + return FALSE; } - PhysicalConsoleSize = ScrInfo.dwSize; + PhysicalConsoleSize = ScrInfo.dwSize; - RtlZeroMemory(&wc, sizeof(WNDCLASSEXW)); - wc.cbSize = sizeof(WNDCLASSEXW); - wc.lpszClassName = L"TuiConsoleWindowClass"; - wc.lpfnWndProc = TuiConsoleWndProc; - wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); - if (RegisterClassExW(&wc) == 0) + RtlZeroMemory(&wc, sizeof(WNDCLASSEXW)); + wc.cbSize = sizeof(WNDCLASSEXW); + wc.lpszClassName = L"TuiConsoleWindowClass"; + wc.lpfnWndProc = TuiConsoleWndProc; + wc.hInstance = (HINSTANCE) GetModuleHandleW(NULL); + if (RegisterClassExW(&wc) == 0) { - DPRINT1("Failed to register console wndproc\n"); - return FALSE; + DPRINT1("Failed to register console wndproc\n"); + return FALSE; } - return TRUE; + return TRUE; } static VOID WINAPI TuiInitScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer) { - Buffer->DefaultAttrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; + Buffer->DefaultAttrib = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; } static void FASTCALL TuiCopyRect(char *Dest, PCSRSS_SCREEN_BUFFER Buff, SMALL_RECT *Region) { - UINT SrcDelta, DestDelta; - LONG i; - PBYTE Src, SrcEnd; + UINT SrcDelta, DestDelta; + LONG i; + PBYTE Src, SrcEnd; - Src = ConioCoordToPointer(Buff, Region->Left, Region->Top); - SrcDelta = Buff->MaxX * 2; - SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2; - DestDelta = ConioRectWidth(Region) * 2; - for (i = Region->Top; i <= Region->Bottom; i++) + Src = ConioCoordToPointer(Buff, Region->Left, Region->Top); + SrcDelta = Buff->MaxX * 2; + SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2; + DestDelta = ConioRectWidth(Region) * 2; + for (i = Region->Top; i <= Region->Bottom; i++) { - memcpy(Dest, Src, DestDelta); - Src += SrcDelta; - if (SrcEnd <= Src) + memcpy(Dest, Src, DestDelta); + Src += SrcDelta; + if (SrcEnd <= Src) { - Src -= Buff->MaxY * Buff->MaxX * 2; + Src -= Buff->MaxY * Buff->MaxX * 2; } - Dest += DestDelta; + Dest += DestDelta; } } static VOID WINAPI TuiDrawRegion(PCSRSS_CONSOLE Console, SMALL_RECT *Region) { - DWORD BytesReturned; - PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; - PCONSOLE_DRAW ConsoleDraw; - UINT ConsoleDrawSize; + DWORD BytesReturned; + PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; + PCONSOLE_DRAW ConsoleDraw; + UINT ConsoleDrawSize; - if (ActiveConsole != Console) + if (ActiveConsole != Console) { - return; + return; } - ConsoleDrawSize = sizeof(CONSOLE_DRAW) + - (ConioRectWidth(Region) * ConioRectHeight(Region)) * 2; - ConsoleDraw = HeapAlloc(Win32CsrApiHeap, 0, ConsoleDrawSize); - if (NULL == ConsoleDraw) + ConsoleDrawSize = sizeof(CONSOLE_DRAW) + + (ConioRectWidth(Region) * ConioRectHeight(Region)) * 2; + ConsoleDraw = HeapAlloc(Win32CsrApiHeap, 0, ConsoleDrawSize); + if (NULL == ConsoleDraw) { - DPRINT1("HeapAlloc failed\n"); - return; + DPRINT1("HeapAlloc failed\n"); + return; } - ConsoleDraw->X = Region->Left; - ConsoleDraw->Y = Region->Top; - ConsoleDraw->SizeX = ConioRectWidth(Region); - ConsoleDraw->SizeY = ConioRectHeight(Region); - ConsoleDraw->CursorX = Buff->CurrentX; - ConsoleDraw->CursorY = Buff->CurrentY; + ConsoleDraw->X = Region->Left; + ConsoleDraw->Y = Region->Top; + ConsoleDraw->SizeX = ConioRectWidth(Region); + ConsoleDraw->SizeY = ConioRectHeight(Region); + ConsoleDraw->CursorX = Buff->CurrentX; + ConsoleDraw->CursorY = Buff->CurrentY; - TuiCopyRect((char *) (ConsoleDraw + 1), Buff, Region); + TuiCopyRect((char *) (ConsoleDraw + 1), Buff, Region); - if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_DRAW, - NULL, 0, ConsoleDraw, ConsoleDrawSize, &BytesReturned, NULL)) + if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_DRAW, + NULL, 0, ConsoleDraw, ConsoleDrawSize, &BytesReturned, NULL)) { - DPRINT1("Failed to draw console\n"); - HeapFree(Win32CsrApiHeap, 0, ConsoleDraw); - return; + DPRINT1("Failed to draw console\n"); + HeapFree(Win32CsrApiHeap, 0, ConsoleDraw); + return; } - HeapFree(Win32CsrApiHeap, 0, ConsoleDraw); + HeapFree(Win32CsrApiHeap, 0, ConsoleDraw); } static VOID WINAPI TuiWriteStream(PCSRSS_CONSOLE Console, SMALL_RECT *Region, LONG CursorStartX, LONG CursorStartY, UINT ScrolledLines, CHAR *Buffer, UINT Length) { - DWORD BytesWritten; - PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; + DWORD BytesWritten; + PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer; - if (ActiveConsole->ActiveBuffer != Buff) + if (ActiveConsole->ActiveBuffer != Buff) { - return; + return; } - if (! WriteFile(ConsoleDeviceHandle, Buffer, Length, &BytesWritten, NULL)) + if (! WriteFile(ConsoleDeviceHandle, Buffer, Length, &BytesWritten, NULL)) { - DPRINT1("Error writing to BlueScreen\n"); + DPRINT1("Error writing to BlueScreen\n"); } } static BOOL WINAPI TuiSetCursorInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff) { - DWORD BytesReturned; + DWORD BytesReturned; - if (ActiveConsole->ActiveBuffer != Buff) + if (ActiveConsole->ActiveBuffer != Buff) { - return TRUE; + return TRUE; } - if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_CURSOR_INFO, - &Buff->CursorInfo, sizeof(Buff->CursorInfo), NULL, 0, - &BytesReturned, NULL)) + if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_CURSOR_INFO, + &Buff->CursorInfo, sizeof(Buff->CursorInfo), NULL, 0, + &BytesReturned, NULL)) { - DPRINT1( "Failed to set cursor info\n" ); - return FALSE; + DPRINT1( "Failed to set cursor info\n" ); + return FALSE; } - return TRUE; + return TRUE; } static BOOL WINAPI TuiSetScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, UINT OldCursorX, UINT OldCursorY) { - CONSOLE_SCREEN_BUFFER_INFO Info; - DWORD BytesReturned; + CONSOLE_SCREEN_BUFFER_INFO Info; + DWORD BytesReturned; - if (ActiveConsole->ActiveBuffer != Buff) + if (ActiveConsole->ActiveBuffer != Buff) { - return TRUE; + return TRUE; } - Info.dwCursorPosition.X = Buff->CurrentX; - Info.dwCursorPosition.Y = Buff->CurrentY; - Info.wAttributes = Buff->DefaultAttrib; + Info.dwCursorPosition.X = Buff->CurrentX; + Info.dwCursorPosition.Y = Buff->CurrentY; + Info.wAttributes = Buff->DefaultAttrib; - if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO, - &Info, sizeof(CONSOLE_SCREEN_BUFFER_INFO), NULL, 0, - &BytesReturned, NULL)) + if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO, + &Info, sizeof(CONSOLE_SCREEN_BUFFER_INFO), NULL, 0, + &BytesReturned, NULL)) { - DPRINT1( "Failed to set cursor position\n" ); - return FALSE; + DPRINT1( "Failed to set cursor position\n" ); + return FALSE; } - return TRUE; + return TRUE; } static BOOL WINAPI @@ -261,32 +261,32 @@ TuiUpdateScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff) static BOOL WINAPI TuiChangeTitle(PCSRSS_CONSOLE Console) { - return TRUE; + return TRUE; } static VOID WINAPI TuiCleanupConsole(PCSRSS_CONSOLE Console) { - DestroyWindow(Console->hWindow); + DestroyWindow(Console->hWindow); - EnterCriticalSection(&ActiveConsoleLock); + EnterCriticalSection(&ActiveConsoleLock); - /* Switch to next console */ - if (ActiveConsole == Console) + /* Switch to next console */ + if (ActiveConsole == Console) { - ActiveConsole = Console->Next != Console ? Console->Next : NULL; + ActiveConsole = Console->Next != Console ? Console->Next : NULL; } - if (Console->Next != Console) + if (Console->Next != Console) { - Console->Prev->Next = Console->Next; - Console->Next->Prev = Console->Prev; + Console->Prev->Next = Console->Next; + Console->Next->Prev = Console->Prev; } - LeaveCriticalSection(&ActiveConsoleLock); + LeaveCriticalSection(&ActiveConsoleLock); - if (NULL != ActiveConsole) + if (NULL != ActiveConsole) { - ConioDrawConsole(ActiveConsole); + ConioDrawConsole(ActiveConsole); } } @@ -306,179 +306,179 @@ TuiResizeBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer, COORD DWORD WINAPI TuiConsoleThread (PVOID Data) { - PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Data; - HWND NewWindow; - MSG msg; + PCSRSS_CONSOLE Console = (PCSRSS_CONSOLE) Data; + HWND NewWindow; + MSG msg; - NewWindow = CreateWindowW(L"TuiConsoleWindowClass", - Console->Title.Buffer, - 0, - -32000, -32000, 0, 0, - NULL, NULL, - (HINSTANCE) GetModuleHandleW(NULL), - (PVOID) Console); - Console->hWindow = NewWindow; - if (NULL == NewWindow) + NewWindow = CreateWindowW(L"TuiConsoleWindowClass", + Console->Title.Buffer, + 0, + -32000, -32000, 0, 0, + NULL, NULL, + (HINSTANCE) GetModuleHandleW(NULL), + (PVOID) Console); + Console->hWindow = NewWindow; + if (NULL == NewWindow) { - DPRINT1("CSR: Unable to create console window\n"); - return 1; + DPRINT1("CSR: Unable to create console window\n"); + return 1; } - SetForegroundWindow(Console->hWindow); + SetForegroundWindow(Console->hWindow); - while (TRUE) + while (TRUE) { - GetMessageW(&msg, 0, 0, 0); - DispatchMessage(&msg); - TranslateMessage(&msg); + GetMessageW(&msg, 0, 0, 0); + DispatchMessage(&msg); + TranslateMessage(&msg); - if (msg.message == WM_CHAR || msg.message == WM_SYSCHAR || - msg.message == WM_KEYDOWN || msg.message == WM_KEYUP || - msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP) + if (msg.message == WM_CHAR || msg.message == WM_SYSCHAR || + msg.message == WM_KEYDOWN || msg.message == WM_KEYUP || + msg.message == WM_SYSKEYDOWN || msg.message == WM_SYSKEYUP) { - ConioProcessKey(&msg, Console, TRUE); + ConioProcessKey(&msg, Console, TRUE); } } - return 0; + return 0; } static CSRSS_CONSOLE_VTBL TuiVtbl = { - TuiInitScreenBuffer, - TuiWriteStream, - TuiDrawRegion, - TuiSetCursorInfo, - TuiSetScreenInfo, - TuiUpdateScreenInfo, - TuiChangeTitle, - TuiCleanupConsole, - TuiChangeIcon, - TuiResizeBuffer, + TuiInitScreenBuffer, + TuiWriteStream, + TuiDrawRegion, + TuiSetCursorInfo, + TuiSetScreenInfo, + TuiUpdateScreenInfo, + TuiChangeTitle, + TuiCleanupConsole, + TuiChangeIcon, + TuiResizeBuffer, }; NTSTATUS FASTCALL TuiInitConsole(PCSRSS_CONSOLE Console) { - HANDLE ThreadHandle; + HANDLE ThreadHandle; - if (! ConsInitialized) + if (! ConsInitialized) { - ConsInitialized = TRUE; - if (! TuiInit(Console->CodePage)) + ConsInitialized = TRUE; + if (! TuiInit(Console->CodePage)) { - ConsInitialized = FALSE; - return STATUS_UNSUCCESSFUL; + ConsInitialized = FALSE; + return STATUS_UNSUCCESSFUL; } } - Console->Vtbl = &TuiVtbl; - Console->hWindow = NULL; - Console->Size = PhysicalConsoleSize; - Console->ActiveBuffer->MaxX = PhysicalConsoleSize.X; - Console->ActiveBuffer->MaxY = PhysicalConsoleSize.Y; + Console->Vtbl = &TuiVtbl; + Console->hWindow = NULL; + Console->Size = PhysicalConsoleSize; + Console->ActiveBuffer->MaxX = PhysicalConsoleSize.X; + Console->ActiveBuffer->MaxY = PhysicalConsoleSize.Y; - ThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TuiConsoleThread, - Console, 0, NULL); - if (NULL == ThreadHandle) + ThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TuiConsoleThread, + Console, 0, NULL); + if (NULL == ThreadHandle) { - DPRINT1("CSR: Unable to create console thread\n"); - return STATUS_UNSUCCESSFUL; + DPRINT1("CSR: Unable to create console thread\n"); + return STATUS_UNSUCCESSFUL; } - CloseHandle(ThreadHandle); + CloseHandle(ThreadHandle); - EnterCriticalSection(&ActiveConsoleLock); - if (NULL != ActiveConsole) + EnterCriticalSection(&ActiveConsoleLock); + if (NULL != ActiveConsole) { - Console->Prev = ActiveConsole; - Console->Next = ActiveConsole->Next; - ActiveConsole->Next->Prev = Console; - ActiveConsole->Next = Console; + Console->Prev = ActiveConsole; + Console->Next = ActiveConsole->Next; + ActiveConsole->Next->Prev = Console; + ActiveConsole->Next = Console; } - else + else { - Console->Prev = Console; - Console->Next = Console; + Console->Prev = Console; + Console->Next = Console; } - ActiveConsole = Console; - LeaveCriticalSection(&ActiveConsoleLock); + ActiveConsole = Console; + LeaveCriticalSection(&ActiveConsoleLock); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } PCSRSS_CONSOLE FASTCALL TuiGetFocusConsole(VOID) { - return ActiveConsole; + return ActiveConsole; } BOOL FASTCALL TuiSwapConsole(int Next) { - static PCSRSS_CONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */ - DWORD BytesReturned; - ANSI_STRING Title; - void * Buffer; - COORD *pos; + static PCSRSS_CONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */ + DWORD BytesReturned; + ANSI_STRING Title; + void * Buffer; + COORD *pos; - if (0 != Next) + if (0 != Next) { - /* alt-tab, swap consoles */ - /* move SwapConsole to next console, and print its title */ - EnterCriticalSection(&ActiveConsoleLock); - if (! SwapConsole) + /* alt-tab, swap consoles */ + /* move SwapConsole to next console, and print its title */ + EnterCriticalSection(&ActiveConsoleLock); + if (! SwapConsole) { - SwapConsole = ActiveConsole; + SwapConsole = ActiveConsole; } - SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev); - Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title); - Title.Length = 0; - Buffer = HeapAlloc(Win32CsrApiHeap, - 0, - sizeof(COORD) + Title.MaximumLength); - pos = (COORD *)Buffer; - Title.Buffer = (PVOID)((ULONG_PTR)Buffer + sizeof( COORD )); + SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev); + Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title); + Title.Length = 0; + Buffer = HeapAlloc(Win32CsrApiHeap, + 0, + sizeof(COORD) + Title.MaximumLength); + pos = (COORD *)Buffer; + Title.Buffer = (PVOID)((ULONG_PTR)Buffer + sizeof( COORD )); - RtlUnicodeStringToAnsiString(&Title, &SwapConsole->Title, FALSE); - pos->Y = PhysicalConsoleSize.Y / 2; - pos->X = (PhysicalConsoleSize.X - Title.Length) / 2; - /* redraw the console to clear off old title */ - ConioDrawConsole(ActiveConsole); - if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER, - NULL, 0, Buffer, sizeof(COORD) + Title.Length, - &BytesReturned, NULL)) + RtlUnicodeStringToAnsiString(&Title, &SwapConsole->Title, FALSE); + pos->Y = PhysicalConsoleSize.Y / 2; + pos->X = (PhysicalConsoleSize.X - Title.Length) / 2; + /* redraw the console to clear off old title */ + ConioDrawConsole(ActiveConsole); + if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER, + NULL, 0, Buffer, sizeof(COORD) + Title.Length, + &BytesReturned, NULL)) { - DPRINT1( "Error writing to console\n" ); + DPRINT1( "Error writing to console\n" ); } - HeapFree(Win32CsrApiHeap, 0, Buffer); - LeaveCriticalSection(&ActiveConsoleLock); + HeapFree(Win32CsrApiHeap, 0, Buffer); + LeaveCriticalSection(&ActiveConsoleLock); - return TRUE; + return TRUE; } - else if (NULL != SwapConsole) + else if (NULL != SwapConsole) { - EnterCriticalSection(&ActiveConsoleLock); - if (SwapConsole != ActiveConsole) + EnterCriticalSection(&ActiveConsoleLock); + if (SwapConsole != ActiveConsole) { - /* first remove swapconsole from the list */ - SwapConsole->Prev->Next = SwapConsole->Next; - SwapConsole->Next->Prev = SwapConsole->Prev; - /* now insert before activeconsole */ - SwapConsole->Next = ActiveConsole; - SwapConsole->Prev = ActiveConsole->Prev; - ActiveConsole->Prev->Next = SwapConsole; - ActiveConsole->Prev = SwapConsole; + /* first remove swapconsole from the list */ + SwapConsole->Prev->Next = SwapConsole->Next; + SwapConsole->Next->Prev = SwapConsole->Prev; + /* now insert before activeconsole */ + SwapConsole->Next = ActiveConsole; + SwapConsole->Prev = ActiveConsole->Prev; + ActiveConsole->Prev->Next = SwapConsole; + ActiveConsole->Prev = SwapConsole; } - ActiveConsole = SwapConsole; - SwapConsole = NULL; - ConioDrawConsole(ActiveConsole); - LeaveCriticalSection(&ActiveConsoleLock); - return TRUE; + ActiveConsole = SwapConsole; + SwapConsole = NULL; + ConioDrawConsole(ActiveConsole); + LeaveCriticalSection(&ActiveConsoleLock); + return TRUE; } - else + else { - return FALSE; + return FALSE; } }