[CONSRV] Minor code cleanup.

This commit is contained in:
Hermès Bélusca-Maïto 2019-05-26 00:00:39 +02:00
parent 8aeb6a920a
commit 5ca9c9c138
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
11 changed files with 107 additions and 86 deletions

View file

@ -17,7 +17,7 @@
/* PUBLIC SERVER APIS *********************************************************/ /* PUBLIC SERVER APIS *********************************************************/
/* /*
* FIXME: This function MUST be moved fro condrv/conoutput.c because only * FIXME: This function MUST be moved from condrv/conoutput.c because only
* consrv knows how to manipulate VDM screenbuffers. * consrv knows how to manipulate VDM screenbuffers.
*/ */
NTSTATUS NTAPI NTSTATUS NTAPI

View file

@ -1017,6 +1017,8 @@ OnPaint(PGUI_CONSOLE_DATA GuiData)
PaintSelectionRect(GuiData, &ps); PaintSelectionRect(GuiData, &ps);
} }
// TODO: Move cursor display here!
LeaveCriticalSection(&GuiData->Lock); LeaveCriticalSection(&GuiData->Lock);
} }
EndPaint(GuiData->hWindow, &ps); EndPaint(GuiData->hWindow, &ps);

View file

@ -129,16 +129,19 @@ GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
PCONSRV_CONSOLE Console = Buffer->Header.Console; PCONSRV_CONSOLE Console = Buffer->Header.Console;
// ASSERT(Console == GuiData->Console); // ASSERT(Console == GuiData->Console);
SetRectEmpty(rcFramebuffer); ConioInitLongRect(rcFramebuffer, 0, 0, 0, 0);
if (Buffer->BitMap == NULL) return; if (Buffer->BitMap == NULL)
return;
if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return; if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE))
return;
rcFramebuffer->left = Buffer->ViewOrigin.X * 1 + rcView->left; ConioInitLongRect(rcFramebuffer,
rcFramebuffer->top = Buffer->ViewOrigin.Y * 1 + rcView->top; Buffer->ViewOrigin.Y * 1 + rcView->top,
rcFramebuffer->right = Buffer->ViewOrigin.X * 1 + rcView->right; Buffer->ViewOrigin.X * 1 + rcView->left,
rcFramebuffer->bottom = Buffer->ViewOrigin.Y * 1 + rcView->bottom; Buffer->ViewOrigin.Y * 1 + rcView->bottom,
Buffer->ViewOrigin.X * 1 + rcView->right);
/* Grab the mutex */ /* Grab the mutex */
NtWaitForSingleObject(Buffer->Mutex, FALSE, NULL); NtWaitForSingleObject(Buffer->Mutex, FALSE, NULL);

View file

@ -151,7 +151,6 @@ GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
{ {
// PGRAPHICS_SCREEN_BUFFER Buffer = (PGRAPHICS_SCREEN_BUFFER)ActiveBuffer; // PGRAPHICS_SCREEN_BUFFER Buffer = (PGRAPHICS_SCREEN_BUFFER)ActiveBuffer;
DPRINT1("GuiConsoleShowConsoleProperties - Graphics buffer\n");
// FIXME: Gather defaults from the registry ? // FIXME: Gather defaults from the registry ?
pSharedInfo->ScreenAttributes = DEFAULT_SCREEN_ATTRIB; pSharedInfo->ScreenAttributes = DEFAULT_SCREEN_ATTRIB;

View file

@ -358,9 +358,7 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
PRECT rcFramebuffer) PRECT rcFramebuffer)
{ {
PCONSRV_CONSOLE Console = Buffer->Header.Console; PCONSRV_CONSOLE Console = Buffer->Header.Console;
// ASSERT(Console == GuiData->Console); ULONG TopLine, BottomLine, LeftColumn, RightColumn;
ULONG TopLine, BottomLine, LeftChar, RightChar;
ULONG Line, Char, Start; ULONG Line, Char, Start;
PCHAR_INFO From; PCHAR_INFO From;
PWCHAR To; PWCHAR To;
@ -370,26 +368,33 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
HFONT OldFont, NewFont; HFONT OldFont, NewFont;
BOOLEAN IsUnderline; BOOLEAN IsUnderline;
SetRectEmpty(rcFramebuffer); // ASSERT(Console == GuiData->Console);
if (Buffer->Buffer == NULL) return; ConioInitLongRect(rcFramebuffer, 0, 0, 0, 0);
if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return; if (Buffer->Buffer == NULL)
return;
rcFramebuffer->left = Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->left; if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE))
rcFramebuffer->top = Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->top; return;
rcFramebuffer->right = Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->right;
rcFramebuffer->bottom = Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->bottom; ConioInitLongRect(rcFramebuffer,
Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->top,
Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->left,
Buffer->ViewOrigin.Y * GuiData->CharHeight + rcView->bottom,
Buffer->ViewOrigin.X * GuiData->CharWidth + rcView->right);
LeftColumn = rcFramebuffer->left / GuiData->CharWidth;
RightColumn = rcFramebuffer->right / GuiData->CharWidth;
if (RightColumn >= (ULONG)Buffer->ScreenBufferSize.X)
RightColumn = Buffer->ScreenBufferSize.X - 1;
LeftChar = rcFramebuffer->left / GuiData->CharWidth;
TopLine = rcFramebuffer->top / GuiData->CharHeight; TopLine = rcFramebuffer->top / GuiData->CharHeight;
RightChar = rcFramebuffer->right / GuiData->CharWidth;
BottomLine = rcFramebuffer->bottom / GuiData->CharHeight; BottomLine = rcFramebuffer->bottom / GuiData->CharHeight;
if (BottomLine >= (ULONG)Buffer->ScreenBufferSize.Y)
BottomLine = Buffer->ScreenBufferSize.Y - 1;
if (RightChar >= (ULONG)Buffer->ScreenBufferSize.X) RightChar = Buffer->ScreenBufferSize.X - 1; LastAttribute = ConioCoordToPointer(Buffer, LeftColumn, TopLine)->Attributes;
if (BottomLine >= (ULONG)Buffer->ScreenBufferSize.Y) BottomLine = Buffer->ScreenBufferSize.Y - 1;
LastAttribute = ConioCoordToPointer(Buffer, LeftChar, TopLine)->Attributes;
SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute))); SetTextColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, TextAttribFromAttrib(LastAttribute)));
SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute))); SetBkColor(GuiData->hMemDC, PaletteRGBFromAttrib(Console, BkgdAttribFromAttrib(LastAttribute)));
@ -403,11 +408,11 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
for (Line = TopLine; Line <= BottomLine; Line++) for (Line = TopLine; Line <= BottomLine; Line++)
{ {
WCHAR LineBuffer[80]; // Buffer containing a part or all the line to be displayed WCHAR LineBuffer[80]; // Buffer containing a part or all the line to be displayed
From = ConioCoordToPointer(Buffer, LeftChar, Line); // Get the first code of the line From = ConioCoordToPointer(Buffer, LeftColumn, Line); // Get the first code of the line
Start = LeftChar; Start = LeftColumn;
To = LineBuffer; To = LineBuffer;
for (Char = LeftChar; Char <= RightChar; Char++) for (Char = LeftColumn; Char <= RightColumn; Char++)
{ {
/* /*
* We flush the buffer if the new attribute is different * We flush the buffer if the new attribute is different
@ -447,7 +452,7 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
Start * GuiData->CharWidth, Start * GuiData->CharWidth,
Line * GuiData->CharHeight, Line * GuiData->CharHeight,
LineBuffer, LineBuffer,
RightChar - Start + 1); RightColumn - Start + 1);
} }
/* Restore the old font */ /* Restore the old font */
@ -462,13 +467,14 @@ GuiPaintTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
{ {
CursorX = Buffer->CursorPosition.X; CursorX = Buffer->CursorPosition.X;
CursorY = Buffer->CursorPosition.Y; CursorY = Buffer->CursorPosition.Y;
if (LeftChar <= CursorX && CursorX <= RightChar && if (LeftColumn <= CursorX && CursorX <= RightColumn &&
TopLine <= CursorY && CursorY <= BottomLine) TopLine <= CursorY && CursorY <= BottomLine)
{ {
CursorHeight = ConioEffectiveCursorSize(Console, GuiData->CharHeight); CursorHeight = ConioEffectiveCursorSize(Console, GuiData->CharHeight);
Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes; Attribute = ConioCoordToPointer(Buffer, Buffer->CursorPosition.X, Buffer->CursorPosition.Y)->Attributes;
if (Attribute == DEFAULT_SCREEN_ATTRIB) Attribute = Buffer->ScreenDefaultAttrib; if (Attribute == DEFAULT_SCREEN_ATTRIB)
Attribute = Buffer->ScreenDefaultAttrib;
CursorBrush = CreateSolidBrush(PaletteRGBFromAttrib(Console, TextAttribFromAttrib(Attribute))); CursorBrush = CreateSolidBrush(PaletteRGBFromAttrib(Console, TextAttribFromAttrib(Attribute)));
OldBrush = SelectObject(GuiData->hMemDC, CursorBrush); OldBrush = SelectObject(GuiData->hMemDC, CursorBrush);

View file

@ -271,7 +271,7 @@ PPOPUP_WINDOW
HistoryDisplayCurrentHistory(PCONSRV_CONSOLE Console, HistoryDisplayCurrentHistory(PCONSRV_CONSOLE Console,
PUNICODE_STRING ExeName) PUNICODE_STRING ExeName)
{ {
PTEXTMODE_SCREEN_BUFFER ActiveBuffer; PCONSOLE_SCREEN_BUFFER ActiveBuffer;
PPOPUP_WINDOW Popup; PPOPUP_WINDOW Popup;
SHORT xLeft, yTop; SHORT xLeft, yTop;
@ -283,7 +283,7 @@ HistoryDisplayCurrentHistory(PCONSRV_CONSOLE Console,
if (Hist->NumEntries == 0) return NULL; if (Hist->NumEntries == 0) return NULL;
if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return NULL; if (GetType(Console->ActiveBuffer) != TEXTMODE_BUFFER) return NULL;
ActiveBuffer = (PTEXTMODE_SCREEN_BUFFER)Console->ActiveBuffer; ActiveBuffer = Console->ActiveBuffer;
Width = 40; Width = 40;
Height = 10; Height = 10;

View file

@ -9,13 +9,22 @@
#pragma once #pragma once
#define ConioInitLongRect(Rect, Top, Left, Bottom, Right) \
do { \
((Rect)->top) = Top; \
((Rect)->left) = Left; \
((Rect)->bottom) = Bottom; \
((Rect)->right) = Right; \
} while (0)
#define ConioInitRect(Rect, top, left, bottom, right) \ #define ConioInitRect(Rect, top, left, bottom, right) \
do { \ do { \
((Rect)->Top) = top; \ ((Rect)->Top) = top; \
((Rect)->Left) = left; \ ((Rect)->Left) = left; \
((Rect)->Bottom) = bottom; \ ((Rect)->Bottom) = bottom; \
((Rect)->Right) = right; \ ((Rect)->Right) = right; \
} while (0) } while (0)
#define ConioIsRectEmpty(Rect) \ #define ConioIsRectEmpty(Rect) \
(((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom)) (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))

View file

@ -121,12 +121,12 @@ LineInputEdit(PCONSRV_CONSOLE Console,
LineInputSetPos(Console, Pos + NumToInsert); LineInputSetPos(Console, Pos + NumToInsert);
} }
#if 0
static VOID static VOID
LineInputRecallHistory(PCONSRV_CONSOLE Console, LineInputRecallHistory(PCONSRV_CONSOLE Console,
PUNICODE_STRING ExeName, PUNICODE_STRING ExeName,
INT Offset) INT Offset)
{ {
#if 0
PHISTORY_BUFFER Hist = HistoryCurrentBuffer(Console, ExeName); PHISTORY_BUFFER Hist = HistoryCurrentBuffer(Console, ExeName);
UINT Position = 0; UINT Position = 0;
@ -140,13 +140,9 @@ LineInputRecallHistory(PCONSRV_CONSOLE Console,
LineInputEdit(Console, Console->LineSize, LineInputEdit(Console, Console->LineSize,
Hist->Entries[Hist->Position].Length / sizeof(WCHAR), Hist->Entries[Hist->Position].Length / sizeof(WCHAR),
Hist->Entries[Hist->Position].Buffer); Hist->Entries[Hist->Position].Buffer);
}
#else #else
static VOID
LineInputRecallHistory(PCONSRV_CONSOLE Console,
PUNICODE_STRING ExeName,
INT Offset)
{
UNICODE_STRING Entry; UNICODE_STRING Entry;
if (!HistoryRecallHistory(Console, ExeName, Offset, &Entry)) return; if (!HistoryRecallHistory(Console, ExeName, Offset, &Entry)) return;
@ -155,8 +151,8 @@ LineInputRecallHistory(PCONSRV_CONSOLE Console,
LineInputEdit(Console, Console->LineSize, LineInputEdit(Console, Console->LineSize,
Entry.Length / sizeof(WCHAR), Entry.Length / sizeof(WCHAR),
Entry.Buffer); Entry.Buffer);
}
#endif #endif
}
// TESTS!! // TESTS!!

View file

@ -181,17 +181,24 @@ DrawBox(PTEXTMODE_SCREEN_BUFFER Buffer,
/* PUBLIC FUNCTIONS ***********************************************************/ /* PUBLIC FUNCTIONS ***********************************************************/
PPOPUP_WINDOW PPOPUP_WINDOW
CreatePopupWindow(PCONSRV_CONSOLE Console, CreatePopupWindow(
PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSRV_CONSOLE Console,
SHORT xLeft, IN PCONSOLE_SCREEN_BUFFER ScreenBuffer,
SHORT yTop, IN SHORT xLeft,
SHORT Width, IN SHORT yTop,
SHORT Height) IN SHORT Width,
IN SHORT Height)
{ {
PTEXTMODE_SCREEN_BUFFER Buffer;
PPOPUP_WINDOW Popup; PPOPUP_WINDOW Popup;
SMALL_RECT Region; SMALL_RECT Region;
ASSERT((PCONSOLE)Console == Buffer->Header.Console); ASSERT((PCONSOLE)Console == ScreenBuffer->Header.Console);
if (GetType(ScreenBuffer) != TEXTMODE_BUFFER)
return NULL;
Buffer = (PTEXTMODE_SCREEN_BUFFER)ScreenBuffer;
/* Create the popup window */ /* Create the popup window */
Popup = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(*Popup)); Popup = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(*Popup));
@ -234,7 +241,8 @@ CreatePopupWindow(PCONSRV_CONSOLE Console,
} }
VOID VOID
DestroyPopupWindow(PPOPUP_WINDOW Popup) DestroyPopupWindow(
IN PPOPUP_WINDOW Popup)
{ {
SMALL_RECT Region; SMALL_RECT Region;

View file

@ -27,11 +27,14 @@ typedef struct _POPUP_WINDOW
PPOPUP_WINDOW PPOPUP_WINDOW
CreatePopupWindow(PCONSRV_CONSOLE Console, CreatePopupWindow(
PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSRV_CONSOLE Console,
SHORT xLeft, IN PCONSOLE_SCREEN_BUFFER ScreenBuffer,
SHORT yTop, IN SHORT xLeft,
SHORT Width, IN SHORT yTop,
SHORT Height); IN SHORT Width,
IN SHORT Height);
VOID VOID
DestroyPopupWindow(PPOPUP_WINDOW Popup); DestroyPopupWindow(
IN PPOPUP_WINDOW Popup);

View file

@ -66,11 +66,9 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
if (GetType(ActiveBuffer) == TEXTMODE_BUFFER) if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
{ {
PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
COORD BufSize;
/* Resize its active screen-buffer */ /* Resize its active screen-buffer */
BufSize = ConsoleInfo->ScreenBufferSize; PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
COORD BufSize = ConsoleInfo->ScreenBufferSize;
if (Console->FixedSize) if (Console->FixedSize)
{ {
@ -79,24 +77,24 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
* at the moment. However, keep those settings somewhere so that * at the moment. However, keep those settings somewhere so that
* we can try to set them up when we will be allowed to do so. * we can try to set them up when we will be allowed to do so.
*/ */
if (ConsoleInfo->WindowSize.X != Buffer->OldViewSize.X || if (ConsoleInfo->WindowSize.X != ActiveBuffer->OldViewSize.X ||
ConsoleInfo->WindowSize.Y != Buffer->OldViewSize.Y) ConsoleInfo->WindowSize.Y != ActiveBuffer->OldViewSize.Y)
{ {
Buffer->OldViewSize = ConsoleInfo->WindowSize; ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize;
} }
/* Buffer size is not allowed to be smaller than the view size */ /* The buffer size is not allowed to be smaller than the view size */
if (BufSize.X >= Buffer->OldViewSize.X && BufSize.Y >= Buffer->OldViewSize.Y) if (BufSize.X >= ActiveBuffer->OldViewSize.X && BufSize.Y >= ActiveBuffer->OldViewSize.Y)
{ {
if (BufSize.X != Buffer->OldScreenBufferSize.X || if (BufSize.X != ActiveBuffer->OldScreenBufferSize.X ||
BufSize.Y != Buffer->OldScreenBufferSize.Y) BufSize.Y != ActiveBuffer->OldScreenBufferSize.Y)
{ {
/* /*
* The console is in fixed-size mode, so we cannot resize anything * The console is in fixed-size mode, so we cannot resize anything
* at the moment. However, keep those settings somewhere so that * at the moment. However, keep those settings somewhere so that
* we can try to set them up when we will be allowed to do so. * we can try to set them up when we will be allowed to do so.
*/ */
Buffer->OldScreenBufferSize = BufSize; ActiveBuffer->OldScreenBufferSize = BufSize;
} }
} }
} }
@ -105,16 +103,16 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
BOOL SizeChanged = FALSE; BOOL SizeChanged = FALSE;
/* Resize the console */ /* Resize the console */
if (ConsoleInfo->WindowSize.X != Buffer->ViewSize.X || if (ConsoleInfo->WindowSize.X != ActiveBuffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y != Buffer->ViewSize.Y) ConsoleInfo->WindowSize.Y != ActiveBuffer->ViewSize.Y)
{ {
Buffer->ViewSize = ConsoleInfo->WindowSize; ActiveBuffer->ViewSize = ConsoleInfo->WindowSize;
SizeChanged = TRUE; SizeChanged = TRUE;
} }
/* Resize the screen-buffer */ /* Resize the screen-buffer */
if (BufSize.X != Buffer->ScreenBufferSize.X || if (BufSize.X != ActiveBuffer->ScreenBufferSize.X ||
BufSize.Y != Buffer->ScreenBufferSize.Y) BufSize.Y != ActiveBuffer->ScreenBufferSize.Y)
{ {
if (NT_SUCCESS(ConioResizeBuffer(Console, Buffer, BufSize))) if (NT_SUCCESS(ConioResizeBuffer(Console, Buffer, BufSize)))
SizeChanged = TRUE; SizeChanged = TRUE;
@ -131,14 +129,11 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
} }
else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
{ {
PGRAPHICS_SCREEN_BUFFER Buffer = (PGRAPHICS_SCREEN_BUFFER)ActiveBuffer;
/* /*
* In any case we do NOT modify the size of the graphics screen-buffer. * In any case we do NOT modify the size of the graphics screen-buffer.
* We just allow resizing the view only if the new size is smaller * We just allow resizing the view only if the new size is smaller
* than the older one. * than the older one.
*/ */
if (Console->FixedSize) if (Console->FixedSize)
{ {
/* /*
@ -146,19 +141,19 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
* at the moment. However, keep those settings somewhere so that * at the moment. However, keep those settings somewhere so that
* we can try to set them up when we will be allowed to do so. * we can try to set them up when we will be allowed to do so.
*/ */
if (ConsoleInfo->WindowSize.X <= Buffer->ViewSize.X || if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y <= Buffer->ViewSize.Y) ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y)
{ {
Buffer->OldViewSize = ConsoleInfo->WindowSize; ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize;
} }
} }
else else
{ {
/* Resize the view if its size is bigger than the specified size */ /* Resize the view if its size is bigger than the specified size */
if (ConsoleInfo->WindowSize.X <= Buffer->ViewSize.X || if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y <= Buffer->ViewSize.Y) ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y)
{ {
Buffer->ViewSize = ConsoleInfo->WindowSize; ActiveBuffer->ViewSize = ConsoleInfo->WindowSize;
// SizeChanged = TRUE; // SizeChanged = TRUE;
} }
} }