[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 *********************************************************/
/*
* 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.
*/
NTSTATUS NTAPI

View file

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

View file

@ -129,16 +129,19 @@ GuiPaintGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
PCONSRV_CONSOLE Console = Buffer->Header.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;
rcFramebuffer->top = Buffer->ViewOrigin.Y * 1 + rcView->top;
rcFramebuffer->right = Buffer->ViewOrigin.X * 1 + rcView->right;
rcFramebuffer->bottom = Buffer->ViewOrigin.Y * 1 + rcView->bottom;
ConioInitLongRect(rcFramebuffer,
Buffer->ViewOrigin.Y * 1 + rcView->top,
Buffer->ViewOrigin.X * 1 + rcView->left,
Buffer->ViewOrigin.Y * 1 + rcView->bottom,
Buffer->ViewOrigin.X * 1 + rcView->right);
/* Grab the mutex */
NtWaitForSingleObject(Buffer->Mutex, FALSE, NULL);

View file

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

View file

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

View file

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

View file

@ -9,13 +9,22 @@
#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) \
do { \
((Rect)->Top) = top; \
((Rect)->Left) = left; \
((Rect)->Top) = top; \
((Rect)->Left) = left; \
((Rect)->Bottom) = bottom; \
((Rect)->Right) = right; \
((Rect)->Right) = right; \
} while (0)
#define ConioIsRectEmpty(Rect) \
(((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))

View file

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

View file

@ -181,17 +181,24 @@ DrawBox(PTEXTMODE_SCREEN_BUFFER Buffer,
/* PUBLIC FUNCTIONS ***********************************************************/
PPOPUP_WINDOW
CreatePopupWindow(PCONSRV_CONSOLE Console,
PTEXTMODE_SCREEN_BUFFER Buffer,
SHORT xLeft,
SHORT yTop,
SHORT Width,
SHORT Height)
CreatePopupWindow(
IN PCONSRV_CONSOLE Console,
IN PCONSOLE_SCREEN_BUFFER ScreenBuffer,
IN SHORT xLeft,
IN SHORT yTop,
IN SHORT Width,
IN SHORT Height)
{
PTEXTMODE_SCREEN_BUFFER Buffer;
PPOPUP_WINDOW Popup;
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 */
Popup = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(*Popup));
@ -234,7 +241,8 @@ CreatePopupWindow(PCONSRV_CONSOLE Console,
}
VOID
DestroyPopupWindow(PPOPUP_WINDOW Popup)
DestroyPopupWindow(
IN PPOPUP_WINDOW Popup)
{
SMALL_RECT Region;

View file

@ -27,11 +27,14 @@ typedef struct _POPUP_WINDOW
PPOPUP_WINDOW
CreatePopupWindow(PCONSRV_CONSOLE Console,
PTEXTMODE_SCREEN_BUFFER Buffer,
SHORT xLeft,
SHORT yTop,
SHORT Width,
SHORT Height);
CreatePopupWindow(
IN PCONSRV_CONSOLE Console,
IN PCONSOLE_SCREEN_BUFFER ScreenBuffer,
IN SHORT xLeft,
IN SHORT yTop,
IN SHORT Width,
IN SHORT Height);
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)
{
PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
COORD BufSize;
/* Resize its active screen-buffer */
BufSize = ConsoleInfo->ScreenBufferSize;
PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
COORD BufSize = ConsoleInfo->ScreenBufferSize;
if (Console->FixedSize)
{
@ -79,24 +77,24 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
* 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.
*/
if (ConsoleInfo->WindowSize.X != Buffer->OldViewSize.X ||
ConsoleInfo->WindowSize.Y != Buffer->OldViewSize.Y)
if (ConsoleInfo->WindowSize.X != ActiveBuffer->OldViewSize.X ||
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 */
if (BufSize.X >= Buffer->OldViewSize.X && BufSize.Y >= Buffer->OldViewSize.Y)
/* The buffer size is not allowed to be smaller than the view size */
if (BufSize.X >= ActiveBuffer->OldViewSize.X && BufSize.Y >= ActiveBuffer->OldViewSize.Y)
{
if (BufSize.X != Buffer->OldScreenBufferSize.X ||
BufSize.Y != Buffer->OldScreenBufferSize.Y)
if (BufSize.X != ActiveBuffer->OldScreenBufferSize.X ||
BufSize.Y != ActiveBuffer->OldScreenBufferSize.Y)
{
/*
* The console is in fixed-size mode, so we cannot resize anything
* 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.
*/
Buffer->OldScreenBufferSize = BufSize;
ActiveBuffer->OldScreenBufferSize = BufSize;
}
}
}
@ -105,16 +103,16 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
BOOL SizeChanged = FALSE;
/* Resize the console */
if (ConsoleInfo->WindowSize.X != Buffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y != Buffer->ViewSize.Y)
if (ConsoleInfo->WindowSize.X != ActiveBuffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y != ActiveBuffer->ViewSize.Y)
{
Buffer->ViewSize = ConsoleInfo->WindowSize;
ActiveBuffer->ViewSize = ConsoleInfo->WindowSize;
SizeChanged = TRUE;
}
/* Resize the screen-buffer */
if (BufSize.X != Buffer->ScreenBufferSize.X ||
BufSize.Y != Buffer->ScreenBufferSize.Y)
if (BufSize.X != ActiveBuffer->ScreenBufferSize.X ||
BufSize.Y != ActiveBuffer->ScreenBufferSize.Y)
{
if (NT_SUCCESS(ConioResizeBuffer(Console, Buffer, BufSize)))
SizeChanged = TRUE;
@ -131,14 +129,11 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
}
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.
* We just allow resizing the view only if the new size is smaller
* than the older one.
*/
if (Console->FixedSize)
{
/*
@ -146,19 +141,19 @@ ConSrvApplyUserSettings(IN PCONSOLE Console,
* 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.
*/
if (ConsoleInfo->WindowSize.X <= Buffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y <= Buffer->ViewSize.Y)
if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y)
{
Buffer->OldViewSize = ConsoleInfo->WindowSize;
ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize;
}
}
else
{
/* Resize the view if its size is bigger than the specified size */
if (ConsoleInfo->WindowSize.X <= Buffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y <= Buffer->ViewSize.Y)
if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X ||
ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y)
{
Buffer->ViewSize = ConsoleInfo->WindowSize;
ActiveBuffer->ViewSize = ConsoleInfo->WindowSize;
// SizeChanged = TRUE;
}
}