*/
#include "consrv.h"
+#include "settings.h"
#include "tuiconsole.h"
#include <drivers/blue/ntddblue.h>
return DefWindowProcW(hWnd, msg, wParam, lParam);
}
+static BOOL FASTCALL
+TuiSwapConsole(INT Next)
+{
+ static PCONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */
+ DWORD BytesReturned;
+ ANSI_STRING Title;
+ PVOID Buffer;
+ PCOORD pos;
+
+ if (0 != Next)
+ {
+ /* alt-tab, swap consoles */
+ /* move SwapConsole to next console, and print its title */
+ EnterCriticalSection(&ActiveConsoleLock);
+ if (! SwapConsole)
+ {
+ SwapConsole = ActiveConsole;
+ }
+
+ SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev);
+ Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title);
+ Title.Length = 0;
+ Buffer = RtlAllocateHeap(ConSrvHeap,
+ 0,
+ sizeof(COORD) + Title.MaximumLength);
+ pos = (PCOORD )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))
+ {
+ DPRINT1( "Error writing to console\n" );
+ }
+ RtlFreeHeap(ConSrvHeap, 0, Buffer);
+ LeaveCriticalSection(&ActiveConsoleLock);
+
+ return TRUE;
+ }
+ else if (NULL != SwapConsole)
+ {
+ 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;
+ }
+ ActiveConsole = SwapConsole;
+ SwapConsole = NULL;
+ ConioDrawConsole(ActiveConsole);
+ LeaveCriticalSection(&ActiveConsoleLock);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+static BOOL WINAPI
+TuiProcessKeyCallback(PCONSOLE Console, MSG* msg, BYTE KeyStateMenu, DWORD ShiftState, UINT VirtualKeyCode, BOOL Down)
+{
+ if (0 != (ShiftState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) &&
+ VK_TAB == VirtualKeyCode)
+ {
+ if (Down)
+ {
+ TuiSwapConsole(ShiftState & SHIFT_PRESSED ? -1 : 1);
+ }
+
+ return TRUE;
+ }
+ else if (VK_MENU == VirtualKeyCode && !Down)
+ {
+ return TuiSwapConsole(0);
+ }
+
+ return FALSE;
+}
+
static BOOL FASTCALL
TuiInit(DWORD OemCP)
{
return TRUE;
}
-static void FASTCALL
+static VOID FASTCALL
TuiCopyRect(char *Dest, PCONSOLE_SCREEN_BUFFER Buff, SMALL_RECT* Region)
{
UINT SrcDelta, DestDelta;
PBYTE Src, SrcEnd;
Src = ConioCoordToPointer(Buff, Region->Left, Region->Top);
- SrcDelta = Buff->MaxX * 2;
- SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2;
+ SrcDelta = Buff->ScreenBufferSize.X * 2;
+ SrcEnd = Buff->Buffer + Buff->ScreenBufferSize.Y * Buff->ScreenBufferSize.X * 2;
DestDelta = ConioRectWidth(Region) * 2;
for (i = Region->Top; i <= Region->Bottom; i++)
{
Src += SrcDelta;
if (SrcEnd <= Src)
{
- Src -= Buff->MaxY * Buff->MaxX * 2;
+ Src -= Buff->ScreenBufferSize.Y * Buff->ScreenBufferSize.X * 2;
}
Dest += DestDelta;
}
ConsoleDraw->Y = Region->Top;
ConsoleDraw->SizeX = ConioRectWidth(Region);
ConsoleDraw->SizeY = ConioRectHeight(Region);
- ConsoleDraw->CursorX = Buff->CurrentX;
- ConsoleDraw->CursorY = Buff->CurrentY;
+ ConsoleDraw->CursorX = Buff->CursorPosition.X;
+ ConsoleDraw->CursorY = Buff->CursorPosition.Y;
TuiCopyRect((char *) (ConsoleDraw + 1), Buff, Region);
return TRUE;
}
- Info.dwCursorPosition.X = Buff->CurrentX;
- Info.dwCursorPosition.Y = Buff->CurrentY;
- Info.wAttributes = Buff->DefaultAttrib;
+ Info.dwCursorPosition = Buff->CursorPosition;
+ Info.wAttributes = Buff->ScreenDefaultAttrib;
if (!DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO,
&Info, sizeof(CONSOLE_SCREEN_BUFFER_INFO), NULL, 0,
return STATUS_NOT_IMPLEMENTED;
}
-DWORD WINAPI
+static DWORD WINAPI
TuiConsoleThread(PVOID Data)
{
PCONSOLE Console = (PCONSOLE) Data;
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_SYSKEYDOWN ||
+ msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP)
{
- ConioProcessKey(&msg, Console, TRUE);
+ ConioProcessKey(Console, &msg);
}
}
TuiCleanupConsole,
TuiChangeIcon,
TuiResizeBuffer,
+ TuiProcessKeyCallback
};
NTSTATUS FASTCALL
-TuiInitConsole(PCONSOLE Console)
+TuiInitConsole(PCONSOLE Console,
+ PCONSOLE_INFO ConsoleInfo)
{
HANDLE ThreadHandle;
Console->Vtbl = &TuiVtbl;
Console->hWindow = NULL;
Console->Size = PhysicalConsoleSize;
- Console->ActiveBuffer->MaxX = PhysicalConsoleSize.X;
- Console->ActiveBuffer->MaxY = PhysicalConsoleSize.Y;
+ Console->ActiveBuffer->ScreenBufferSize = PhysicalConsoleSize;
ThreadHandle = CreateThread(NULL,
0,
return ActiveConsole;
}
-BOOL FASTCALL
-TuiSwapConsole(INT Next)
-{
- static PCONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */
- DWORD BytesReturned;
- ANSI_STRING Title;
- PVOID Buffer;
- PCOORD pos;
-
- if (0 != Next)
- {
- /* alt-tab, swap consoles */
- /* move SwapConsole to next console, and print its title */
- EnterCriticalSection(&ActiveConsoleLock);
- if (! SwapConsole)
- {
- SwapConsole = ActiveConsole;
- }
-
- SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev);
- Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title);
- Title.Length = 0;
- Buffer = RtlAllocateHeap(ConSrvHeap,
- 0,
- sizeof(COORD) + Title.MaximumLength);
- pos = (PCOORD )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))
- {
- DPRINT1( "Error writing to console\n" );
- }
- RtlFreeHeap(ConSrvHeap, 0, Buffer);
- LeaveCriticalSection(&ActiveConsoleLock);
-
- return TRUE;
- }
- else if (NULL != SwapConsole)
- {
- 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;
- }
- ActiveConsole = SwapConsole;
- SwapConsole = NULL;
- ConioDrawConsole(ActiveConsole);
- LeaveCriticalSection(&ActiveConsoleLock);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
/* EOF */