[KERNEL32-CONSRV]

- Implement GetLargestConsoleWindowSize (and add a DPRINT to see what happens when Far 1.65 is launched).
- Implement SetConsoleWindowInfo in kernel32 and pre-implement its CONSRV counterpart.

svn path=/branches/ros-csrss/; revision=58726
This commit is contained in:
Hermès Bélusca-Maïto 2013-04-09 15:21:14 +00:00
parent 2358a3210f
commit d070d323fb
8 changed files with 229 additions and 35 deletions

View file

@ -306,6 +306,12 @@ GetConsoleDisplayMode(LPDWORD lpModeFlags)
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest = &ApiMessage.Data.GetDisplayModeRequest;
if (lpModeFlags == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
// GetDisplayModeRequest->OutputHandle = hConsoleOutput;
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@ -357,7 +363,7 @@ GetConsoleFontSize(HANDLE hConsoleOutput,
/*
* @implemented (Undocumented)
*/
DWORD
BOOL
WINAPI
GetConsoleHardwareState(HANDLE hConsoleOutput,
DWORD Flags,
@ -369,6 +375,12 @@ GetConsoleHardwareState(HANDLE hConsoleOutput,
DPRINT1("GetConsoleHardwareState(%d, 0x%p) UNIMPLEMENTED!\n", Flags, State);
if (State == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
HardwareStateRequest->OutputHandle = hConsoleOutput;
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@ -523,7 +535,7 @@ SetConsoleDisplayMode(HANDLE hConsoleOutput,
SetDisplayModeRequest->OutputHandle = hConsoleOutput;
SetDisplayModeRequest->DisplayMode = dwFlags;
SetDisplayModeRequest->NewSBDim = (COORD){0,0};
SetDisplayModeRequest->NewSBDim = (COORD){0, 0};
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
NULL,
@ -535,7 +547,9 @@ SetConsoleDisplayMode(HANDLE hConsoleOutput,
return FALSE;
}
*lpNewScreenBufferDimensions = SetDisplayModeRequest->NewSBDim;
if (lpNewScreenBufferDimensions)
*lpNewScreenBufferDimensions = SetDisplayModeRequest->NewSBDim;
return TRUE;
}
@ -1022,6 +1036,12 @@ GetConsoleMode(HANDLE hConsoleHandle,
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
if (lpMode == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@ -1082,16 +1102,30 @@ GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
/*--------------------------------------------------------------
* GetLargestConsoleWindowSize
*
* @unimplemented
* @implemented
*/
COORD
WINAPI
GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
{
COORD Coord = {80,25};
DPRINT1("GetLargestConsoleWindowSize(0x%x) UNIMPLEMENTED!\n", hConsoleOutput);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return Coord;
NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &ApiMessage.Data.GetLargestWindowSizeRequest;
GetLargestWindowSizeRequest->OutputHandle = hConsoleOutput;
GetLargestWindowSizeRequest->Size = (COORD){0, 0};
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
NULL,
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetLargestWindowSize),
sizeof(CONSOLE_GETLARGESTWINDOWSIZE));
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
}
DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest->Size.X, GetLargestWindowSizeRequest->Size.Y);
return GetLargestWindowSizeRequest->Size;
}
@ -1390,7 +1424,7 @@ ScrollConsoleScreenBufferW(HANDLE hConsoleOutput,
/*--------------------------------------------------------------
* SetConsoleWindowInfo
*
* @unimplemented
* @implemented
*/
BOOL
WINAPI
@ -1398,9 +1432,31 @@ SetConsoleWindowInfo(HANDLE hConsoleOutput,
BOOL bAbsolute,
CONST SMALL_RECT *lpConsoleWindow)
{
DPRINT1("SetConsoleWindowInfo(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, bAbsolute, lpConsoleWindow);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_SETWINDOWINFO SetWindowInfoRequest = &ApiMessage.Data.SetWindowInfoRequest;
if (lpConsoleWindow == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
SetWindowInfoRequest->OutputHandle = hConsoleOutput;
SetWindowInfoRequest->Absolute = bAbsolute;
SetWindowInfoRequest->WindowRect = *lpConsoleWindow;
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
NULL,
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetWindowInfo),
sizeof(CONSOLE_SETWINDOWINFO));
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return FALSE;
}
return TRUE;
}

View file

@ -39,11 +39,11 @@ typedef enum _CONSRV_API_NUMBER
ConsolepSetMode,
ConsolepSetActiveScreenBuffer,
ConsolepFlushInputBuffer,
// ConsolepGetLargestWindowSize,
ConsolepGetLargestWindowSize,
ConsolepSetScreenBufferSize,
ConsolepSetCursorPosition,
ConsolepSetCursorInfo,
// ConsolepSetWindowInfo,
ConsolepSetWindowInfo,
ConsolepScrollScreenBuffer,
ConsolepSetTextAttribute,
// ConsolepSetFont,
@ -453,6 +453,20 @@ typedef struct
} CONSOLE_OPENCONSOLE, *PCONSOLE_OPENCONSOLE;
typedef struct
{
HANDLE OutputHandle;
COORD Size;
} CONSOLE_GETLARGESTWINDOWSIZE, *PCONSOLE_GETLARGESTWINDOWSIZE;
typedef struct
{
HANDLE OutputHandle;
BOOL Absolute;
SMALL_RECT WindowRect; // New console window position in the screen-buffer frame (Absolute == TRUE)
// or in the old window position frame (Absolute == FALSE).
} CONSOLE_SETWINDOWINFO, *PCONSOLE_SETWINDOWINFO;
typedef struct
{
HWND WindowHandle;
@ -575,10 +589,14 @@ typedef struct _CONSOLE_API_MESSAGE
ULONG Reserved;
union
{
/* Console initialization and uninitialization */
CONSOLE_ALLOCCONSOLE AllocConsoleRequest;
CONSOLE_ATTACHCONSOLE AttachConsoleRequest;
CONSOLE_FREECONSOLE FreeConsoleRequest;
/* Process list */
CONSOLE_GETPROCESSLIST GetProcessListRequest;
/* Handles */
CONSOLE_OPENCONSOLE OpenConsoleRequest;
CONSOLE_CLOSEHANDLE CloseHandleRequest;
@ -589,7 +607,7 @@ typedef struct _CONSOLE_API_MESSAGE
CONSOLE_GETSETCURSORINFO CursorInfoRequest;
CONSOLE_SETCURSORPOSITION SetCursorPositionRequest;
/* Screen buffer */
/* Screen-buffer */
CONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest;
CONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest;
CONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest;
@ -607,6 +625,8 @@ typedef struct _CONSOLE_API_MESSAGE
/* Console window */
CONSOLE_GETSETCONSOLETITLE TitleRequest;
CONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest;
CONSOLE_SETWINDOWINFO SetWindowInfoRequest;
CONSOLE_GETWINDOW GetWindowRequest;
CONSOLE_SETICON SetIconRequest;
@ -644,8 +664,6 @@ typedef struct _CONSOLE_API_MESSAGE
/* Input and Output Code Pages */
CONSOLE_GETSETINPUTOUTPUTCP ConsoleCPRequest;
CONSOLE_GETPROCESSLIST GetProcessListRequest;
} Data;
} CONSOLE_API_MESSAGE, *PCONSOLE_API_MESSAGE;

View file

@ -52,6 +52,8 @@ CSR_API(SrvGetConsoleHardwareState);
CSR_API(SrvSetConsoleHardwareState);
CSR_API(SrvGetConsoleDisplayMode);
CSR_API(SrvSetConsoleDisplayMode);
CSR_API(SrvGetLargestConsoleWindowSize);
CSR_API(SrvSetConsoleWindowInfo);
CSR_API(SrvGetConsoleWindow);
CSR_API(SrvSetConsoleIcon);
CSR_API(SrvGetConsoleCP);

View file

@ -25,6 +25,8 @@
#define ConioResizeTerminal(Console) (Console)->TermIFace.Vtbl->ResizeTerminal((Console))
#define ConioProcessKeyCallback(Console, Msg, KeyStateMenu, ShiftState, VirtualKeyCode, Down) \
(Console)->TermIFace.Vtbl->ProcessKeyCallback((Console), (Msg), (KeyStateMenu), (ShiftState), (VirtualKeyCode), (Down))
#define ConioGetLargestConsoleWindowSize(Console, pSize) \
(Console)->TermIFace.Vtbl->GetLargestConsoleWindowSize((Console), (pSize))
#define ConioGetConsoleWindowHandle(Console) \
(Console)->TermIFace.Vtbl->GetConsoleWindowHandle((Console))
#define ConioRefreshInternalInfo(Console) \

View file

@ -1261,10 +1261,10 @@ CSR_API(SrvGetConsoleHardwareState)
PCONSOLE Console;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get console handle in SrvGetConsoleHardwareState\n");
@ -1286,10 +1286,10 @@ CSR_API(SrvSetConsoleHardwareState)
PCONSOLE Console;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
HardwareStateRequest->OutputHandle,
&Buff,
GENERIC_WRITE,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get console handle in SrvSetConsoleHardwareState\n");
@ -1365,6 +1365,87 @@ CSR_API(SrvSetConsoleDisplayMode)
return Status;
}
CSR_API(SrvGetLargestConsoleWindowSize)
{
NTSTATUS Status;
PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetLargestWindowSizeRequest;
PCONSOLE_SCREEN_BUFFER Buff;
PCONSOLE Console;
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
GetLargestWindowSizeRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
ConioGetLargestConsoleWindowSize(Console, &GetLargestWindowSizeRequest->Size);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
}
CSR_API(SrvSetConsoleWindowInfo)
{
#if 0
NTSTATUS Status;
#endif
PCONSOLE_SETWINDOWINFO SetWindowInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetWindowInfoRequest;
#if 0
PCONSOLE_SCREEN_BUFFER Buff;
PCONSOLE Console;
#endif
SMALL_RECT WindowRect = SetWindowInfoRequest->WindowRect;
#if 0
Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
SetWindowInfoRequest->OutputHandle,
&Buff,
GENERIC_READ,
TRUE);
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
if (SetWindowInfoRequest->Absolute == FALSE)
{
/* Relative positions given. Transform them to absolute ones */
WindowRect.Left += Buff->ShowX;
WindowRect.Top += Buff->ShowY;
WindowRect.Right += Buff->ShowX + Console->ConsoleSize.X - 1;
WindowRect.Bottom += Buff->ShowY + Console->ConsoleSize.Y - 1;
}
if ( (WindowRect.Left < 0) || (WindowRect.Top < 0) ||
(WindowRect.Right > ScreenBufferSize.X) ||
(WindowRect.Bottom > ScreenBufferSize.Y) ||
(WindowRect.Right <= WindowRect.Left) ||
(WindowRect.Bottom <= WindowRect.Top) )
{
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_INVALID_PARAMETER;
}
Buff->ShowX = WindowRect.Left;
Buff->ShowY = WindowRect.Top;
// These two lines are frontend-specific.
Console->ConsoleSize.X = WindowRect.Right - WindowRect.Left + 1;
Console->ConsoleSize.Y = WindowRect.Bottom - WindowRect.Top + 1;
// ConioGetLargestConsoleWindowSize(Console, &GetLargestWindowSizeRequest->Size);
ConSrvReleaseScreenBuffer(Buff, TRUE);
return STATUS_SUCCESS;
#else
DPRINT1("SrvSetConsoleWindowInfo(0x%08x, %d, {L%d, T%d, R%d, B%d}) UNIMPLEMENTED\n",
SetWindowInfoRequest->OutputHandle, SetWindowInfoRequest->Absolute,
WindowRect.Left, WindowRect.Top, WindowRect.Right, WindowRect.Bottom);
return STATUS_NOT_IMPLEMENTED;
#endif
}
CSR_API(SrvGetConsoleWindow)
{
NTSTATUS Status;
@ -1375,8 +1456,8 @@ CSR_API(SrvGetConsoleWindow)
if (!NT_SUCCESS(Status)) return Status;
GetWindowRequest->WindowHandle = ConioGetConsoleWindowHandle(Console);
ConSrvReleaseConsole(Console, TRUE);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;
}
@ -1394,7 +1475,6 @@ CSR_API(SrvSetConsoleIcon)
: STATUS_UNSUCCESSFUL);
ConSrvReleaseConsole(Console, TRUE);
return Status;
}

View file

@ -1326,7 +1326,7 @@ GuiConsoleGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData, PMINMAXINFO minMaxInfo)
if (!ConSrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
windx = CONGUI_MIN_WIDTH * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
windx = CONGUI_MIN_WIDTH * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
windy = CONGUI_MIN_HEIGHT * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION);
minMaxInfo->ptMinTrackSize.x = windx;
@ -2321,6 +2321,39 @@ GuiGetConsoleWindowHandle(PCONSOLE Console)
return GuiData->hWindow;
}
static VOID WINAPI
GuiGetLargestConsoleWindowSize(PCONSOLE Console, PCOORD pSize)
{
PGUI_CONSOLE_DATA GuiData = Console->TermIFace.Data;
HWND hDesktop;
RECT desktop;
LONG width, height;
if (!pSize) return;
/*
* This is one solution. Surely better solutions exist :
* http://stackoverflow.com/questions/4631292/how-detect-current-screen-resolution
* http://www.clearevo.com/blog/programming/2011/08/30/windows_c_c++_-_get_monitor_display_screen_size_in_pixels.html
*/
hDesktop = GetDesktopWindow();
if (!hDesktop) return;
GetWindowRect(hDesktop, &desktop);
width = desktop.right;
height = desktop.bottom;
width -= (2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE)));
height -= (2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION));
if (width < 0) width = 0;
if (height < 0) height = 0;
pSize->X = (SHORT)(width / GuiData->CharWidth );
pSize->Y = (SHORT)(height / GuiData->CharHeight);
}
static FRONTEND_VTBL GuiVtbl =
{
GuiCleanupConsole,
@ -2335,7 +2368,8 @@ static FRONTEND_VTBL GuiVtbl =
GuiRefreshInternalInfo,
GuiChangeTitle,
GuiChangeIcon,
GuiGetConsoleWindowHandle
GuiGetConsoleWindowHandle,
GuiGetLargestConsoleWindowSize
};
NTSTATUS FASTCALL

View file

@ -125,6 +125,8 @@ typedef struct _FRONTEND_VTBL
BOOL (WINAPI *ChangeIcon)(struct _CONSOLE* Console,
HICON hWindowIcon);
HWND (WINAPI *GetConsoleWindowHandle)(struct _CONSOLE* Console);
VOID (WINAPI *GetLargestConsoleWindowSize)(struct _CONSOLE* Console,
PCOORD pSize);
} FRONTEND_VTBL, *PFRONTEND_VTBL;

View file

@ -47,11 +47,11 @@ PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber - CONSRV_FIR
SrvSetConsoleMode,
SrvSetConsoleActiveScreenBuffer,
SrvFlushConsoleInputBuffer,
// SrvGetLargestConsoleWindowSize,
SrvGetLargestConsoleWindowSize,
SrvSetConsoleScreenBufferSize,
SrvSetConsoleCursorPosition,
SrvSetConsoleCursorInfo,
// SrvSetConsoleWindowInfo,
SrvSetConsoleWindowInfo,
SrvScrollConsoleScreenBuffer,
SrvSetConsoleTextAttribute,
// SrvSetConsoleFont,
@ -138,11 +138,11 @@ BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber - CONSRV_FIRST_API
FALSE, // SrvSetConsoleMode,
FALSE, // SrvSetConsoleActiveScreenBuffer,
FALSE, // SrvFlushConsoleInputBuffer,
// FALSE, // SrvGetLargestConsoleWindowSize,
FALSE, // SrvGetLargestConsoleWindowSize,
FALSE, // SrvSetConsoleScreenBufferSize,
FALSE, // SrvSetConsoleCursorPosition,
FALSE, // SrvSetConsoleCursorInfo,
// FALSE, // SrvSetConsoleWindowInfo,
FALSE, // SrvSetConsoleWindowInfo,
FALSE, // SrvScrollConsoleScreenBuffer,
FALSE, // SrvSetConsoleTextAttribute,
// FALSE, // SrvSetConsoleFont,
@ -229,11 +229,11 @@ PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER]
"SetConsoleMode",
"SetConsoleActiveScreenBuffer",
"FlushConsoleInputBuffer",
// "GetLargestConsoleWindowSize",
"GetLargestConsoleWindowSize",
"SetConsoleScreenBufferSize",
"SetConsoleCursorPosition",
"SetConsoleCursorInfo",
// "SetConsoleWindowInfo",
"SetConsoleWindowInfo",
"ScrollConsoleScreenBuffer",
"SetConsoleTextAttribute",
// "SetConsoleFont",