[CONSOLE.DLL-CONSRV]

- Further separate properties of the GUI terminal front-end and those independent of the UI.
- Fix some console initialization steps.

svn path=/branches/ros-csrss/; revision=58605
This commit is contained in:
Hermès Bélusca-Maïto 2013-03-24 17:08:10 +00:00
parent fe98b9ea97
commit 53eba1ba5f
25 changed files with 911 additions and 553 deletions

View file

@ -21,7 +21,8 @@ add_importlibs(console
user32
gdi32
comctl32
kernel32)
kernel32
ntdll)
add_pch(console console.h)
add_cd_file(TARGET console DESTINATION reactos/system32 FOR all)

View file

@ -8,6 +8,9 @@
#include "console.h"
#define NDEBUG
#include <debug.h>
static BOOL
PaintStaticControls(HWND hwndDlg,
PCONSOLE_PROPS pConInfo,

View file

@ -8,6 +8,9 @@
#include "console.h"
#define NDEBUG
#include <debug.h>
#define NUM_APPLETS 1
LONG APIENTRY InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
@ -73,12 +76,17 @@ InitPropSheetPage(PROPSHEETPAGE *psp,
PCONSOLE_PROPS
AllocConsoleInfo()
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CONSOLE_PROPS));
/* Adapted for holding GUI terminal information */
return HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
sizeof(CONSOLE_PROPS) + sizeof(GUI_CONSOLE_INFO));
}
VOID
InitConsoleDefaults(PCONSOLE_PROPS pConInfo)
{
PGUI_CONSOLE_INFO GuiInfo = NULL;
/* Initialize the default properties */
pConInfo->ci.HistoryBufferSize = 50;
pConInfo->ci.NumberOfHistoryBuffers = 4;
@ -88,7 +96,7 @@ InitConsoleDefaults(PCONSOLE_PROPS pConInfo)
pConInfo->ci.InsertMode = TRUE;
// pConInfo->ci.InputBufferSize;
pConInfo->ci.ScreenBufferSize = (COORD){80, 300};
pConInfo->ci.ConsoleSize = (COORD){80, 25};
pConInfo->ci.ConsoleSize = (COORD){80, 25 };
pConInfo->ci.CursorBlinkOn = TRUE;
pConInfo->ci.ForceCursorOff = FALSE;
pConInfo->ci.CursorSize = CSR_DEFAULT_CURSOR_SIZE;
@ -97,14 +105,17 @@ InitConsoleDefaults(PCONSOLE_PROPS pConInfo)
pConInfo->ci.CodePage = 0;
pConInfo->ci.ConsoleTitle[0] = L'\0';
pConInfo->ci.u.GuiInfo.FaceName[0] = L'\0';
pConInfo->ci.u.GuiInfo.FontFamily = FF_DONTCARE;
pConInfo->ci.u.GuiInfo.FontSize = 0;
pConInfo->ci.u.GuiInfo.FontWeight = FW_DONTCARE;
pConInfo->ci.u.GuiInfo.UseRasterFonts = TRUE;
/* Adapted for holding GUI terminal information */
pConInfo->TerminalInfo.Size = sizeof(GUI_CONSOLE_INFO);
GuiInfo = pConInfo->TerminalInfo.TermInfo = (PGUI_CONSOLE_INFO)(pConInfo + 1);
GuiInfo->FaceName[0] = L'\0';
GuiInfo->FontFamily = FF_DONTCARE;
GuiInfo->FontSize = 0;
GuiInfo->FontWeight = FW_DONTCARE;
GuiInfo->UseRasterFonts = TRUE;
pConInfo->ci.u.GuiInfo.AutoPosition = TRUE;
pConInfo->ci.u.GuiInfo.WindowOrigin = (POINT){0, 0};
GuiInfo->AutoPosition = TRUE;
GuiInfo->WindowOrigin = (POINT){0, 0};
memcpy(pConInfo->ci.Colors, s_Colors, sizeof(s_Colors));
}
@ -169,23 +180,26 @@ ApplyConsoleInfo(HWND hwndDlg,
HANDLE hSection;
PCONSOLE_PROPS pSharedInfo;
/* Create a memory section to share with the server, and map it */
/*
* Create a memory section to share with the server, and map it.
*/
/* Holds data for console.dll + console info + terminal-specific info */
hSection = CreateFileMapping(INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
sizeof(CONSOLE_PROPS),
sizeof(CONSOLE_PROPS) + sizeof(GUI_CONSOLE_INFO),
NULL);
if (!hSection)
{
// DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
return FALSE;
}
pSharedInfo = MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (!pSharedInfo)
{
// DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
CloseHandle(hSection);
return FALSE;
}
@ -194,7 +208,9 @@ ApplyConsoleInfo(HWND hwndDlg,
pConInfo->AppliedConfig = TRUE;
/* Copy the console info into the section */
RtlCopyMemory(pSharedInfo, pConInfo, sizeof(CONSOLE_PROPS));
RtlCopyMemory(pSharedInfo, pConInfo, sizeof(CONSOLE_PROPS) + sizeof(GUI_CONSOLE_INFO));
/* Offsetize */
pSharedInfo->TerminalInfo.TermInfo = (PVOID)((ULONG_PTR)pSharedInfo->TerminalInfo.TermInfo - (ULONG_PTR)pSharedInfo);
/* Unmap it */
UnmapViewOfFile(pSharedInfo);
@ -219,6 +235,7 @@ LONG APIENTRY
InitApplet(HWND hWnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
{
HANDLE hSection = (HANDLE)wParam;
BOOL GuiTermInfo = FALSE;
PCONSOLE_PROPS pSharedInfo;
PCONSOLE_PROPS pConInfo;
WCHAR szTitle[MAX_PATH + 1];
@ -255,15 +272,23 @@ InitApplet(HWND hWnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
pConInfo->hConsoleWindow = pSharedInfo->hConsoleWindow;
pConInfo->ShowDefaultParams = pSharedInfo->ShowDefaultParams;
if (pConInfo->ShowDefaultParams)
/* Check that we are going to modify GUI terminal information */
GuiTermInfo = ( pSharedInfo->TerminalInfo.Size == sizeof(GUI_CONSOLE_INFO) &&
pSharedInfo->TerminalInfo.TermInfo != 0 );
if (pConInfo->ShowDefaultParams || !GuiTermInfo)
{
/* Use defaults */
InitConsoleDefaults(pConInfo);
}
else
{
/* Copy the shared data into our allocated buffer */
RtlCopyMemory(pConInfo, pSharedInfo, sizeof(CONSOLE_PROPS));
/*
* Copy the shared data into our allocated buffer, and
* de-offsetize the address of terminal-specific information.
*/
RtlCopyMemory(pConInfo, pSharedInfo, sizeof(CONSOLE_PROPS) + sizeof(GUI_CONSOLE_INFO));
pConInfo->TerminalInfo.TermInfo = (PVOID)((ULONG_PTR)pConInfo + (ULONG_PTR)pConInfo->TerminalInfo.TermInfo);
}
/* Close the section */
@ -315,6 +340,10 @@ CPlApplet(HWND hwndCPl,
case CPL_INIT:
return TRUE;
case CPL_EXIT:
// TODO: Free allocated memory
break;
case CPL_GETCOUNT:
return NUM_APPLETS;

View file

@ -16,7 +16,7 @@
#include "resource.h"
/* Shared header with consrv.dll */
#include "settings.h"
#include "consolecpl.h"
typedef struct
{

View file

@ -8,6 +8,9 @@
#include "console.h"
#define NDEBUG
#include <debug.h>
INT_PTR
CALLBACK
FontProc(HWND hwndDlg,

View file

@ -8,6 +8,9 @@
#include "console.h"
#define NDEBUG
#include <debug.h>
const TCHAR szPreviewText[] =
_T("C:\\ReactOS> dir \n") \
_T("SYSTEM <DIR> 03-03-13 5:00a\n") \
@ -23,6 +26,7 @@ VOID
PaintConsole(LPDRAWITEMSTRUCT drawItem,
PCONSOLE_PROPS pConInfo)
{
PGUI_CONSOLE_INFO GuiInfo = pConInfo->TerminalInfo.TermInfo;
HBRUSH hBrush;
RECT cRect, fRect;
DWORD startx, starty;
@ -34,8 +38,8 @@ PaintConsole(LPDRAWITEMSTRUCT drawItem,
sizex = drawItem->rcItem.right - drawItem->rcItem.left;
sizey = drawItem->rcItem.bottom - drawItem->rcItem.top;
if ( pConInfo->ci.u.GuiInfo.WindowOrigin.x == MAXDWORD &&
pConInfo->ci.u.GuiInfo.WindowOrigin.y == MAXDWORD )
if ( GuiInfo->WindowOrigin.x == MAXDWORD &&
GuiInfo->WindowOrigin.y == MAXDWORD )
{
startx = sizex / 3;
starty = sizey / 3;
@ -133,6 +137,7 @@ LayoutProc(HWND hwndDlg,
LPNMUPDOWN lpnmud;
LPPSHNOTIFY lppsn;
PCONSOLE_PROPS pConInfo = (PCONSOLE_PROPS)GetWindowLongPtr(hwndDlg, DWLP_USER);
PGUI_CONSOLE_INFO GuiInfo = (pConInfo ? pConInfo->TerminalInfo.TermInfo : NULL);
UNREFERENCED_PARAMETER(hwndDlg);
UNREFERENCED_PARAMETER(wParam);
@ -144,6 +149,7 @@ LayoutProc(HWND hwndDlg,
DWORD xres, yres;
HDC hDC;
pConInfo = (PCONSOLE_PROPS)((LPPROPSHEETPAGE)lParam)->lParam;
GuiInfo = pConInfo->TerminalInfo.TermInfo;
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
@ -162,11 +168,11 @@ LayoutProc(HWND hwndDlg,
SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(xres, 0));
SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP), UDM_SETRANGE, 0, (LPARAM)MAKELONG(yres, 0));
if ( pConInfo->ci.u.GuiInfo.WindowOrigin.x != MAXDWORD &&
pConInfo->ci.u.GuiInfo.WindowOrigin.y != MAXDWORD )
if ( GuiInfo->WindowOrigin.x != MAXDWORD &&
GuiInfo->WindowOrigin.y != MAXDWORD )
{
SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, pConInfo->ci.u.GuiInfo.WindowOrigin.x, FALSE);
SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, pConInfo->ci.u.GuiInfo.WindowOrigin.y, FALSE);
SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, GuiInfo->WindowOrigin.x, FALSE);
SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, GuiInfo->WindowOrigin.y, FALSE);
}
else
{
@ -288,7 +294,7 @@ LayoutProc(HWND hwndDlg,
pConInfo->ci.ScreenBufferSize = (COORD){swidth, sheight};
pConInfo->ci.ConsoleSize = (COORD){wwidth, wheight};
pConInfo->ci.u.GuiInfo.WindowOrigin = (POINT){left, top};
GuiInfo->WindowOrigin = (POINT){left, top};
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
@ -335,7 +341,7 @@ LayoutProc(HWND hwndDlg,
pConInfo->ci.ScreenBufferSize = (COORD){swidth, sheight};
pConInfo->ci.ConsoleSize = (COORD){wwidth, wheight};
pConInfo->ci.u.GuiInfo.WindowOrigin = (POINT){left, top};
GuiInfo->WindowOrigin = (POINT){left, top};
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
@ -350,7 +356,7 @@ LayoutProc(HWND hwndDlg,
left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, FALSE);
top = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, NULL, FALSE);
pConInfo->ci.u.GuiInfo.WindowOrigin = (POINT){left, top};
GuiInfo->WindowOrigin = (POINT){left, top};
SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP), TRUE);
@ -359,7 +365,7 @@ LayoutProc(HWND hwndDlg,
}
else if (res == BST_UNCHECKED)
{
pConInfo->ci.u.GuiInfo.WindowOrigin = (POINT){UINT_MAX, UINT_MAX};
GuiInfo->WindowOrigin = (POINT){UINT_MAX, UINT_MAX};
SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP), FALSE);

View file

@ -8,6 +8,9 @@
#include "console.h"
#define NDEBUG
#include <debug.h>
static
void
UpdateDialogElements(HWND hwndDlg, PCONSOLE_PROPS pConInfo);
@ -37,10 +40,8 @@ OptionsProc(HWND hwndDlg,
}
case WM_NOTIFY:
{
if (!pConInfo)
{
break;
}
if (!pConInfo) break;
lppsn = (LPPSHNOTIFY) lParam;
if (lppsn->hdr.code == UDN_DELTAPOS)
{
@ -68,10 +69,8 @@ OptionsProc(HWND hwndDlg,
}
case WM_COMMAND:
{
if (!pConInfo)
{
break;
}
if (!pConInfo) break;
switch (LOWORD(wParam))
{
case IDC_RADIO_SMALL_CURSOR:

View file

@ -823,6 +823,7 @@ AllocConsole(VOID)
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_ALLOCCONSOLE AllocConsoleRequest = &ApiMessage.Data.AllocConsoleRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
LPWSTR AppPath = NULL;
SIZE_T Length = 0;
if (Parameters->ConsoleHandle)
@ -832,8 +833,7 @@ AllocConsole(VOID)
return FALSE;
}
CaptureBuffer = CsrAllocateCaptureBuffer(2, sizeof(CONSOLE_START_INFO) +
(MAX_PATH + 1) * sizeof(WCHAR));
CaptureBuffer = CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO));
if (CaptureBuffer == NULL)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
@ -845,16 +845,13 @@ AllocConsole(VOID)
sizeof(CONSOLE_START_INFO),
(PVOID*)&AllocConsoleRequest->ConsoleStartInfo);
CsrAllocateMessagePointer(CaptureBuffer,
(MAX_PATH + 1) * sizeof(WCHAR),
(PVOID*)&AllocConsoleRequest->AppPath);
/** Copied from BasepInitConsole **********************************************/
InitConsoleInfo(AllocConsoleRequest->ConsoleStartInfo);
AppPath = AllocConsoleRequest->ConsoleStartInfo->AppPath;
Length = min(MAX_PATH, Parameters->ImagePathName.Length / sizeof(WCHAR));
wcsncpy(AllocConsoleRequest->AppPath, Parameters->ImagePathName.Buffer, Length);
AllocConsoleRequest->AppPath[Length] = L'\0';
wcsncpy(AppPath, Parameters->ImagePathName.Buffer, Length);
AppPath[Length] = L'\0';
/******************************************************************************/
AllocConsoleRequest->Console = NULL;

View file

@ -185,7 +185,7 @@ BasepInitConsole(VOID)
ConnectInfo.ConsoleNeeded = FALSE; // ConsoleNeeded is used for knowing whether or not this is a CUI app.
ConnectInfo.ConsoleStartInfo.ConsoleTitle[0] = L'\0';
ConnectInfo.AppPath[0] = L'\0';
ConnectInfo.ConsoleStartInfo.AppPath[0] = L'\0';
}
else
{
@ -194,10 +194,10 @@ BasepInitConsole(VOID)
InitConsoleInfo(&ConnectInfo.ConsoleStartInfo);
Length = min(sizeof(ConnectInfo.AppPath) / sizeof(ConnectInfo.AppPath[0]) - 1,
Length = min(sizeof(ConnectInfo.ConsoleStartInfo.AppPath) / sizeof(ConnectInfo.ConsoleStartInfo.AppPath[0]) - 1,
Parameters->ImagePathName.Length / sizeof(WCHAR));
wcsncpy(ConnectInfo.AppPath, Parameters->ImagePathName.Buffer, Length);
ConnectInfo.AppPath[Length] = L'\0';
wcsncpy(ConnectInfo.ConsoleStartInfo.AppPath, Parameters->ImagePathName.Buffer, Length);
ConnectInfo.ConsoleStartInfo.AppPath[Length] = L'\0';
/* Initialize Input EXE name */
ExeName = wcsrchr(Parameters->ImagePathName.Buffer, L'\\');

View file

@ -120,7 +120,8 @@ typedef struct _CONSOLE_START_INFO
POINT ConsoleWindowOrigin;
SIZE ConsoleWindowSize;
// UNICODE_STRING ConsoleTitle;
WCHAR ConsoleTitle[MAX_PATH + 1];
WCHAR ConsoleTitle[MAX_PATH + 1]; // Console title or full path to the startup shortcut
WCHAR AppPath[MAX_PATH + 1]; // Full path of the launched app
} CONSOLE_START_INFO, *PCONSOLE_START_INFO;
typedef struct _CONSOLE_CONNECTION_INFO
@ -129,7 +130,6 @@ typedef struct _CONSOLE_CONNECTION_INFO
/* Adapted from CONSOLE_ALLOCCONSOLE */
CONSOLE_START_INFO ConsoleStartInfo;
WCHAR AppPath[MAX_PATH + 1];
HANDLE Console; // ConsoleHandle // In fact, it is a PCSRSS_CONSOLE <-- correct that !!
HANDLE InputHandle;
@ -179,7 +179,6 @@ typedef struct
typedef struct
{
PCONSOLE_START_INFO ConsoleStartInfo;
LPWSTR AppPath; // Length: MAX_PATH + 1
HANDLE Console; // ConsoleHandle // In fact, it is a PCSRSS_CONSOLE <-- correct that !!
HANDLE InputHandle;

View file

@ -11,6 +11,7 @@ list(APPEND SOURCE
conoutput.c
console.c
guiconsole.c
guisettings.c
handle.c
init.c
lineinput.c

View file

@ -42,11 +42,8 @@ IntFindAliasHeader(PALIAS_HEADER RootHeader, LPCWSTR lpExeName)
while(RootHeader)
{
INT diff = _wcsicmp(RootHeader->lpExeName, lpExeName);
if (!diff)
return RootHeader;
if (diff > 0)
break;
if (!diff) return RootHeader;
if (diff > 0) break;
RootHeader = RootHeader->Next;
}
@ -60,8 +57,7 @@ IntCreateAliasHeader(LPCWSTR lpExeName)
UINT dwLength = wcslen(lpExeName) + 1;
Entry = RtlAllocateHeap(ConSrvHeap, 0, sizeof(ALIAS_HEADER) + sizeof(WCHAR) * dwLength);
if (!Entry)
return Entry;
if (!Entry) return Entry;
Entry->lpExeName = (LPCWSTR)(Entry + 1);
wcscpy((PWCHAR)Entry->lpExeName, lpExeName);
@ -79,10 +75,8 @@ IntInsertAliasHeader(PALIAS_HEADER * RootHeader, PALIAS_HEADER NewHeader)
while ((CurrentHeader = *LastLink) != NULL)
{
INT Diff = _wcsicmp(NewHeader->lpExeName, CurrentHeader->lpExeName);
if (Diff < 0)
{
break;
}
if (Diff < 0) break;
LastLink = &CurrentHeader->Next;
}
@ -95,8 +89,7 @@ IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName)
{
PALIAS_ENTRY RootHeader;
if (Header == NULL)
return NULL;
if (Header == NULL) return NULL;
RootHeader = Header->Data;
while(RootHeader)
@ -104,11 +97,8 @@ IntGetAliasEntry(PALIAS_HEADER Header, LPCWSTR lpSrcName)
INT diff;
DPRINT("IntGetAliasEntry->lpSource %S\n", RootHeader->lpSource);
diff = _wcsicmp(RootHeader->lpSource, lpSrcName);
if (!diff)
return RootHeader;
if (diff > 0)
break;
if (!diff) return RootHeader;
if (diff > 0) break;
RootHeader = RootHeader->Next;
}
@ -124,10 +114,8 @@ IntInsertAliasEntry(PALIAS_HEADER Header, PALIAS_ENTRY NewEntry)
while ((CurrentEntry = *LastLink) != NULL)
{
INT Diff = _wcsicmp(NewEntry->lpSource, CurrentEntry->lpSource);
if (Diff < 0)
{
break;
}
if (Diff < 0) break;
LastLink = &CurrentEntry->Next;
}
@ -146,8 +134,7 @@ IntCreateAliasEntry(LPCWSTR lpSource, LPCWSTR lpTarget)
dwTarget = wcslen(lpTarget) + 1;
Entry = RtlAllocateHeap(ConSrvHeap, 0, sizeof(ALIAS_ENTRY) + sizeof(WCHAR) * (dwSource + dwTarget));
if (!Entry)
return Entry;
if (!Entry) return Entry;
Entry->lpSource = (LPCWSTR)(Entry + 1);
wcscpy((LPWSTR)Entry->lpSource, lpSource);

View file

@ -13,7 +13,7 @@
/* Default attributes */
#define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
#define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
#define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
@ -74,7 +74,7 @@ typedef struct ConsoleInput_t
INPUT_RECORD InputEvent;
} ConsoleInput;
typedef struct _TERMINAL_VTBL
typedef struct _FRONTEND_VTBL
{
/*
* Internal interface (functions called by the console server only)
@ -100,6 +100,7 @@ typedef struct _TERMINAL_VTBL
NTSTATUS (WINAPI *ResizeBuffer)(struct _CONSOLE* Console,
PCONSOLE_SCREEN_BUFFER ScreenBuffer,
COORD Size);
VOID (WINAPI *ResizeTerminal)(struct _CONSOLE* Console);
BOOL (WINAPI *ProcessKeyCallback)(struct _CONSOLE* Console,
MSG* msg,
BYTE KeyStateMenu,
@ -116,7 +117,7 @@ typedef struct _TERMINAL_VTBL
HICON hWindowIcon);
HWND (WINAPI *GetConsoleWindowHandle)(struct _CONSOLE* Console);
} TERMINAL_VTBL, *PTERMINAL_VTBL;
} FRONTEND_VTBL, *PFRONTEND_VTBL;
#define ConioDrawRegion(Console, Region) (Console)->TermIFace.Vtbl->DrawRegion((Console), (Region))
#define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
@ -131,6 +132,7 @@ typedef struct _TERMINAL_VTBL
#define ConioCleanupConsole(Console) (Console)->TermIFace.Vtbl->CleanupConsole(Console)
#define ConioChangeIcon(Console, hWindowIcon) (Console)->TermIFace.Vtbl->ChangeIcon((Console), (hWindowIcon))
#define ConioResizeBuffer(Console, Buff, Size) (Console)->TermIFace.Vtbl->ResizeBuffer((Console), (Buff), (Size))
#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 ConioGetConsoleWindowHandle(Console) \
@ -138,12 +140,12 @@ typedef struct _TERMINAL_VTBL
#define ConioRefreshInternalInfo(Console) \
(Console)->TermIFace.Vtbl->RefreshInternalInfo((Console))
typedef struct _TERMINAL_IFACE
typedef struct _FRONTEND_IFACE
{
PTERMINAL_VTBL Vtbl; /* Virtual table */
PFRONTEND_VTBL Vtbl; /* Virtual table */
PVOID Data; /* Private data */
PVOID OldData; /* Reserved */
} TERMINAL_IFACE, *PTERMINAL_IFACE;
} FRONTEND_IFACE, *PFRONTEND_IFACE;
typedef struct _CONSOLE
{
@ -153,7 +155,7 @@ typedef struct _CONSOLE
struct _CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
TERMINAL_IFACE TermIFace; /* Terminal-specific interface */
FRONTEND_IFACE TermIFace; /* Frontend-specific interface */
/**************************** Input buffer and data ***************************/
CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
@ -195,7 +197,7 @@ typedef struct _CONSOLE
UNICODE_STRING OriginalTitle; /* Original title of console, the one when the console leader is launched. Always NULL-terminated */
UNICODE_STRING Title; /* Title of console. Always NULL-terminated */
COORD Size; /* Size of the console (different of the size of the screen buffer */
/* SIZE */ COORD ConsoleSize; /* The size of the console */
COLORREF Colors[16]; /* Colour palette */
} CONSOLE, *PCONSOLE;
@ -219,7 +221,6 @@ typedef struct _CONSOLE
VOID WINAPI ConSrvDeleteConsole(PCONSOLE Console);
VOID WINAPI ConSrvInitConsoleSupport(VOID);
NTSTATUS WINAPI ConSrvInitConsole(OUT PCONSOLE* NewConsole,
IN LPCWSTR AppPath,
IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
IN PCSR_PROCESS ConsoleLeaderProcess);
VOID FASTCALL ConioPause(PCONSOLE Console, UINT Flags);

View file

@ -229,14 +229,14 @@ ConioWriteConsole(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buff,
}
continue;
}
/* --- BEL ---*/
else if (Buffer[i] == '\a')
{
// FIXME: This MUST BE moved to the terminal emulator!!
DPRINT1("Bell\n");
// SendNotifyMessage(Console->hWindow, PM_CONSOLE_BEEP, 0, 0);
continue;
}
// /* --- BEL ---*/
// else if (Buffer[i] == '\a')
// {
// // FIXME: This MUST BE moved to the terminal emulator frontend!!
// DPRINT1("Bell\n");
// // SendNotifyMessage(Console->hWindow, PM_CONSOLE_BEEP, 0, 0);
// continue;
// }
}
UpdateRect.Left = min(UpdateRect.Left, (LONG)Buff->CursorPosition.X);
UpdateRect.Right = max(UpdateRect.Right, (LONG)Buff->CursorPosition.X);
@ -419,7 +419,7 @@ ConioDrawConsole(PCONSOLE Console)
{
SMALL_RECT Region;
ConioInitRect(&Region, 0, 0, Console->Size.Y - 1, Console->Size.X - 1);
ConioInitRect(&Region, 0, 0, Console->ConsoleSize.Y - 1, Console->ConsoleSize.X - 1);
ConioDrawRegion(Console, &Region);
}
@ -1343,9 +1343,9 @@ CSR_API(SrvGetConsoleScreenBufferInfo)
pInfo->dwCursorPosition = Buff->CursorPosition;
pInfo->wAttributes = Buff->ScreenDefaultAttrib;
pInfo->srWindow.Left = Buff->ShowX;
pInfo->srWindow.Right = Buff->ShowX + Console->Size.X - 1;
pInfo->srWindow.Right = Buff->ShowX + Console->ConsoleSize.X - 1;
pInfo->srWindow.Top = Buff->ShowY;
pInfo->srWindow.Bottom = Buff->ShowY + Console->Size.Y - 1;
pInfo->srWindow.Bottom = Buff->ShowY + Console->ConsoleSize.Y - 1;
pInfo->dwMaximumWindowSize = Buff->ScreenBufferSize;
ConSrvReleaseScreenBuffer(Buff, TRUE);

View file

@ -12,7 +12,9 @@
#define NONAMELESSUNION
#include "consrv.h"
#include "conio.h"
#include "settings.h"
#include "guiconsole.h"
#ifdef TUI_CONSOLE
@ -141,7 +143,7 @@ ConioUnpause(PCONSOLE Console, UINT Flags)
static BOOL
LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
OUT PCONSOLE_INFO ConsoleInfo,
IN OUT PCONSOLE_INFO ConsoleInfo,
OUT LPWSTR IconPath,
IN SIZE_T IconPathLength,
OUT PINT piIcon)
@ -207,14 +209,8 @@ LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
INT ShowCmd = 0;
// WORD HotKey = 0;
/* Get the name of the shortcut */
Length = min(Length - 4,
sizeof(ConsoleStartInfo->ConsoleTitle) / sizeof(ConsoleStartInfo->ConsoleTitle[0]) - 1);
wcsncpy(ConsoleStartInfo->ConsoleTitle, LinkName, Length);
ConsoleStartInfo->ConsoleTitle[Length] = L'\0';
// HACK: Copy also the name of the shortcut
Length = min(Length,
/* Reset the name of the console with the name of the shortcut */
Length = min(/*Length*/ Length - 4, // 4 == len(".lnk")
sizeof(ConsoleInfo->ConsoleTitle) / sizeof(ConsoleInfo->ConsoleTitle[0]) - 1);
wcsncpy(ConsoleInfo->ConsoleTitle, LinkName, Length);
ConsoleInfo->ConsoleTitle[Length] = L'\0';
@ -250,7 +246,6 @@ LoadShellLinkConsoleInfo(IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
NTSTATUS WINAPI
ConSrvInitConsole(OUT PCONSOLE* NewConsole,
IN LPCWSTR AppPath,
IN OUT PCONSOLE_START_INFO ConsoleStartInfo,
IN PCSR_PROCESS ConsoleLeaderProcess)
{
@ -293,9 +288,9 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
ConsoleInfo.ConsoleTitle[Length] = L'\0';
/*
* 3. Check whether the process creating the
* console was launched via a shell-link
* (ConsoleInfo.ConsoleTitle may be updated).
* 3. Check whether the process creating the console was launched
* via a shell-link. ConsoleInfo.ConsoleTitle may be updated by
* the name of the shortcut.
*/
if (ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME)
{
@ -325,6 +320,7 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
* Now, update them with the properties the user might gave to us
* via the STARTUPINFO structure before calling CreateProcess
* (and which was transmitted via the ConsoleStartInfo structure).
* We therefore overwrite the values read in the registry.
*/
if (ConsoleStartInfo->dwStartupFlags & STARTF_USEFILLATTRIBUTE)
{
@ -334,18 +330,9 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
{
ConsoleInfo.ScreenBufferSize = ConsoleStartInfo->ScreenBufferSize;
}
if (ConsoleStartInfo->dwStartupFlags & STARTF_USESHOWWINDOW)
{
ConsoleInfo.u.GuiInfo.ShowWindow = ConsoleStartInfo->ShowWindow;
}
if (ConsoleStartInfo->dwStartupFlags & STARTF_USEPOSITION)
{
ConsoleInfo.u.GuiInfo.AutoPosition = FALSE;
ConsoleInfo.u.GuiInfo.WindowOrigin = ConsoleStartInfo->ConsoleWindowOrigin;
}
if (ConsoleStartInfo->dwStartupFlags & STARTF_USESIZE)
{
// ConsoleInfo.ConsoleSize = ConsoleStartInfo->ConsoleWindowSize;
// ConsoleInfo->ConsoleSize = ConsoleStartInfo->ConsoleWindowSize;
ConsoleInfo.ConsoleSize.X = (SHORT)ConsoleStartInfo->ConsoleWindowSize.cx;
ConsoleInfo.ConsoleSize.Y = (SHORT)ConsoleStartInfo->ConsoleWindowSize.cy;
}
@ -363,7 +350,7 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
Console->ReferenceCount = 0;
InitializeListHead(&Console->ProcessList);
memcpy(Console->Colors, ConsoleInfo.Colors, sizeof(ConsoleInfo.Colors));
Console->Size = ConsoleInfo.ConsoleSize;
Console->ConsoleSize = ConsoleInfo.ConsoleSize;
/*
* Initialize the input buffer
@ -424,8 +411,8 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
Console->HistoryNoDup = ConsoleInfo.HistoryNoDup;
/* Initialize the console title */
RtlCreateUnicodeString(&Console->OriginalTitle, ConsoleStartInfo->ConsoleTitle);
if (ConsoleStartInfo->ConsoleTitle[0] == L'\0')
RtlCreateUnicodeString(&Console->OriginalTitle, ConsoleInfo.ConsoleTitle);
if (ConsoleInfo.ConsoleTitle[0] == L'\0')
{
if (LoadStringW(ConSrvDllInstance, IDS_CONSOLE_TITLE, Title, sizeof(Title) / sizeof(Title[0])))
{
@ -438,7 +425,7 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
}
else
{
RtlCreateUnicodeString(&Console->Title, ConsoleStartInfo->ConsoleTitle);
RtlCreateUnicodeString(&Console->Title, ConsoleInfo.ConsoleTitle);
}
/*
@ -455,7 +442,10 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
if (!GuiMode)
{
DPRINT1("CONSRV: Opening text-mode terminal emulator\n");
Status = TuiInitConsole(Console, &ConsoleInfo);
Status = TuiInitConsole(Console,
ConsoleStartInfo,
&ConsoleInfo,
ProcessId);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to open text-mode terminal emulator, switching to gui-mode, Status = 0x%08lx\n", Status);
@ -471,15 +461,16 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
* - We are in text-mode, therefore GuiMode == FALSE, the previous test-case
* succeeded BUT we failed at starting text-mode terminal emulator.
* Then GuiMode was switched to TRUE in order to try to open the GUI-mode
* terminal emulator (win32k will automatically switch to graphical mode,
* terminal emulator (Win32k will automatically switch to graphical mode,
* therefore no additional code is needed).
*/
if (GuiMode)
{
DPRINT1("CONSRV: Opening GUI-mode terminal emulator\n");
Status = GuiInitConsole(Console,
AppPath,
ConsoleStartInfo,
&ConsoleInfo,
ProcessId,
IconPath,
iIcon);
if (!NT_SUCCESS(Status))
@ -620,14 +611,10 @@ CSR_API(SrvAllocConsole)
return STATUS_ACCESS_DENIED;
}
if ( !CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&AllocConsoleRequest->ConsoleStartInfo,
1,
sizeof(CONSOLE_START_INFO)) ||
!CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&AllocConsoleRequest->AppPath,
MAX_PATH + 1,
sizeof(WCHAR)) )
if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&AllocConsoleRequest->ConsoleStartInfo,
1,
sizeof(CONSOLE_START_INFO)))
{
return STATUS_INVALID_PARAMETER;
}
@ -646,7 +633,6 @@ CSR_API(SrvAllocConsole)
/* Initialize a new Console owned by the Console Leader Process */
Status = ConSrvAllocateConsole(ProcessData,
AllocConsoleRequest->AppPath,
&AllocConsoleRequest->InputHandle,
&AllocConsoleRequest->OutputHandle,
&AllocConsoleRequest->ErrorHandle,

View file

@ -0,0 +1,14 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/consolecpl.h
* PURPOSE: GUI front-end settings management - Header for console.dll
* PROGRAMMERS: Hermes Belusca - Maito
*/
#pragma once
#include "settings.h"
#include "guisettings.h"
/* EOF */

View file

@ -167,7 +167,6 @@ NTSTATUS FASTCALL ConSrvGetObject(PCONSOLE_PROCESS_DATA ProcessData,
VOID FASTCALL ConSrvReleaseObject(Object_t *Object,
BOOL IsConsoleLocked);
NTSTATUS FASTCALL ConSrvAllocateConsole(PCONSOLE_PROCESS_DATA ProcessData,
LPCWSTR AppPath,
PHANDLE pInputHandle,
PHANDLE pOutputHandle,
PHANDLE pErrorHandle,

View file

@ -5,7 +5,7 @@
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#define REACTOS_VERSION_DLL
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Console Server DLL"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Console Server & Terminal Emulator DLL"
#define REACTOS_STR_INTERNAL_NAME "consrv"
#define REACTOS_STR_ORIGINAL_FILENAME "consrv.dll"
#include <reactos/version.rc>

View file

@ -2,15 +2,17 @@
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/guiconsole.c
* PURPOSE: GUI terminal emulator
* PURPOSE: GUI front-end
* PROGRAMMERS:
*/
/* INCLUDES *******************************************************************/
#include "consrv.h"
#include "conio.h"
#include "settings.h"
#include "guiconsole.h"
#include "guisettings.h"
#define NDEBUG
#include <debug.h>
@ -45,27 +47,6 @@ PrivateCsrssManualGuiCheck(LONG Check)
/* GLOBALS ********************************************************************/
typedef struct _GUI_CONSOLE_DATA
{
CRITICAL_SECTION Lock;
HANDLE hGuiInitEvent;
BOOL WindowSizeLock;
POINT OldCursor;
HWND hWindow; /* Handle to the console's window */
HICON hIcon; /* Handle to the console's icon (big) */
HICON hIconSm; /* Handle to the console's icon (small) */
// COLORREF Colors[16];
HFONT Font;
UINT CharWidth;
UINT CharHeight;
PCONSOLE Console; /* Pointer to the owned console */
GUI_CONSOLE_INFO GuiInfo; /* GUI terminal settings */
} GUI_CONSOLE_DATA, *PGUI_CONSOLE_DATA;
/**************************************************************\
\** Define the Console Leader Process for the console window **/
#define GWLP_CONSOLEWND_ALLOC (2 * sizeof(LONG_PTR))
@ -85,7 +66,6 @@ do { \
} while(0)
/**************************************************************/
static BOOL ConsInitialized = FALSE;
static HICON ghDefaultIcon = NULL;
static HICON ghDefaultIconSm = NULL;
@ -220,15 +200,11 @@ static VOID
GuiConsolePaste(PGUI_CONSOLE_DATA GuiData);
static VOID
GuiConsoleUpdateSelection(PCONSOLE Console, PCOORD coord);
static VOID
GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData, BOOL Defaults);
static VOID WINAPI
GuiDrawRegion(PCONSOLE Console, SMALL_RECT* Region);
static NTSTATUS WINAPI
GuiResizeBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Size);
static VOID
GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData);
static VOID
GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData);
@ -256,8 +232,8 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
PCONSOLE Console = GuiData->Console;
COORD bottomRight = { 0, 0 };
bottomRight.X = Console->Size.X - 1;
bottomRight.Y = Console->Size.Y - 1;
bottomRight.X = Console->ConsoleSize.X - 1;
bottomRight.Y = Console->ConsoleSize.Y - 1;
GuiConsoleUpdateSelection(Console, &bottomRight);
break;
}
@ -285,255 +261,6 @@ GuiConsoleHandleSysMenuCommand(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM
return Ret;
}
static VOID
GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData, BOOL Defaults)
{
NTSTATUS Status;
PCONSOLE Console = GuiData->Console;
PCONSOLE_PROCESS_DATA ProcessData;
HANDLE hSection = NULL, hClientSection = NULL;
LARGE_INTEGER SectionSize;
ULONG ViewSize = 0;
SIZE_T Length = 0;
PCONSOLE_PROPS pSharedInfo = NULL;
DPRINT("GuiConsoleShowConsoleProperties entered\n");
/* Create a memory section to share with the applet, and map it */
SectionSize.QuadPart = sizeof(CONSOLE_PROPS);
Status = NtCreateSection(&hSection,
SECTION_ALL_ACCESS,
NULL,
&SectionSize,
PAGE_READWRITE,
SEC_COMMIT,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to create a shared section ; Status = %lu\n", Status);
return;
}
Status = NtMapViewOfSection(hSection,
NtCurrentProcess(),
(PVOID*)&pSharedInfo,
0,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
NtClose(hSection);
return;
}
/*
* Setup the shared console properties structure.
*/
/* Header */
pSharedInfo->hConsoleWindow = GuiData->hWindow;
pSharedInfo->ShowDefaultParams = Defaults;
/* Console information */
pSharedInfo->ci.HistoryBufferSize = Console->HistoryBufferSize;
pSharedInfo->ci.NumberOfHistoryBuffers = Console->NumberOfHistoryBuffers;
pSharedInfo->ci.HistoryNoDup = Console->HistoryNoDup;
pSharedInfo->ci.FullScreen = Console->FullScreen;
pSharedInfo->ci.QuickEdit = Console->QuickEdit;
pSharedInfo->ci.InsertMode = Console->InsertMode;
pSharedInfo->ci.InputBufferSize = 0;
pSharedInfo->ci.ScreenBufferSize = Console->ActiveBuffer->ScreenBufferSize;
pSharedInfo->ci.ConsoleSize = Console->Size;
pSharedInfo->ci.CursorBlinkOn;
pSharedInfo->ci.ForceCursorOff;
pSharedInfo->ci.CursorSize = Console->ActiveBuffer->CursorInfo.dwSize;
pSharedInfo->ci.ScreenAttrib = Console->ActiveBuffer->ScreenDefaultAttrib;
pSharedInfo->ci.PopupAttrib = Console->ActiveBuffer->PopupDefaultAttrib;
pSharedInfo->ci.CodePage;
/* GUI Information */
wcsncpy(pSharedInfo->ci.u.GuiInfo.FaceName, GuiData->GuiInfo.FaceName, LF_FACESIZE);
pSharedInfo->ci.u.GuiInfo.FontSize = (DWORD)GuiData->GuiInfo.FontSize;
pSharedInfo->ci.u.GuiInfo.FontWeight = GuiData->GuiInfo.FontWeight;
pSharedInfo->ci.u.GuiInfo.UseRasterFonts = GuiData->GuiInfo.UseRasterFonts;
/// pSharedInfo->ci.u.GuiInfo.WindowPosition = GuiData->GuiInfo.WindowPosition;
pSharedInfo->ci.u.GuiInfo.AutoPosition = GuiData->GuiInfo.AutoPosition;
pSharedInfo->ci.u.GuiInfo.WindowOrigin = GuiData->GuiInfo.WindowOrigin;
/* Palette */
memcpy(pSharedInfo->ci.Colors, Console->Colors, sizeof(s_Colors)); // FIXME: Possible buffer overflow if s_colors is bigger than pSharedInfo->Colors.
/* Title of the console, original one corresponding to the one set by the console leader */
Length = min(sizeof(pSharedInfo->ci.ConsoleTitle) / sizeof(pSharedInfo->ci.ConsoleTitle[0]) - 1,
Console->OriginalTitle.Length / sizeof(WCHAR));
wcsncpy(pSharedInfo->ci.ConsoleTitle, Console->OriginalTitle.Buffer, Length);
pSharedInfo->ci.ConsoleTitle[Length] = L'\0';
/* Unmap the view */
NtUnmapViewOfSection(NtCurrentProcess(), pSharedInfo);
/* Get the console leader process, our client */
ProcessData = CONTAINING_RECORD(Console->ProcessList.Blink,
CONSOLE_PROCESS_DATA,
ConsoleLink);
/* Duplicate the section handle for the client */
Status = NtDuplicateObject(NtCurrentProcess(),
hSection,
ProcessData->Process->ProcessHandle,
&hClientSection,
0, 0, DUPLICATE_SAME_ACCESS);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to duplicate section handle for client ; Status = %lu\n", Status);
NtClose(hSection);
return;
}
/* Start the properties dialog */
if (ProcessData->PropDispatcher)
{
HANDLE Thread;
Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
ProcessData->PropDispatcher,
(PVOID)hClientSection, 0, NULL);
if (NULL == Thread)
{
DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
return;
}
DPRINT1("We succeeded at creating ProcessData->PropDispatcher remote thread, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
/// WaitForSingleObject(Thread, INFINITE);
CloseHandle(Thread);
}
/* We have finished, close the section handle */
NtClose(hSection);
return;
}
static VOID
GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
HANDLE hClientSection,
BOOL SaveSettings)
{
NTSTATUS Status;
PCONSOLE Console = GuiData->Console;
PCONSOLE_PROCESS_DATA ProcessData;
HANDLE hSection = NULL;
ULONG ViewSize = 0;
PCONSOLE_PROPS pConInfo = NULL;
PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
COORD BufSize;
BOOL SizeChanged = FALSE;
/// LOCK /// EnterCriticalSection(&Console->Lock);
/* Get the console leader process, our client */
ProcessData = CONTAINING_RECORD(Console->ProcessList.Blink,
CONSOLE_PROCESS_DATA,
ConsoleLink);
/* Duplicate the section handle for ourselves */
Status = NtDuplicateObject(ProcessData->Process->ProcessHandle,
hClientSection,
NtCurrentProcess(),
&hSection,
0, 0, DUPLICATE_SAME_ACCESS);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error when mapping client handle, Status = %lu\n", Status);
return;
}
/* Get a view of the shared section */
Status = NtMapViewOfSection(hSection,
NtCurrentProcess(),
(PVOID*)&pConInfo,
0,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READONLY);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error when mapping view of file, Status = %lu\n", Status);
NtClose(hSection);
return;
}
/* Check that the section is well-sized */
if (ViewSize < sizeof(CONSOLE_PROPS))
{
DPRINT1("Error: section bad-sized: sizeof(Section) < sizeof(CONSOLE_PROPS)\n");
NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
NtClose(hSection);
return;
}
// TODO: Check that GuiData->hWindow == pConInfo->hConsoleWindow
/*
* Apply foreground and background colors for both screen and popup.
* Copy the new palette.
* TODO: Really update the screen attributes as FillConsoleOutputAttribute does.
*/
ActiveBuffer->ScreenDefaultAttrib = pConInfo->ci.ScreenAttrib;
ActiveBuffer->PopupDefaultAttrib = pConInfo->ci.PopupAttrib;
memcpy(Console->Colors, pConInfo->ci.Colors, sizeof(s_Colors)); // FIXME: Possible buffer overflow if s_colors is bigger than pConInfo->Colors.
/* Apply cursor size */
ActiveBuffer->CursorInfo.bVisible = (pConInfo->ci.CursorSize != 0);
ActiveBuffer->CursorInfo.dwSize = min(max(pConInfo->ci.CursorSize, 0), 100);
if (pConInfo->ci.ConsoleSize.X != Console->Size.X ||
pConInfo->ci.ConsoleSize.Y != Console->Size.Y)
{
/* Resize window */
Console->Size = pConInfo->ci.ConsoleSize;
SizeChanged = TRUE;
}
BufSize = pConInfo->ci.ScreenBufferSize;
if (BufSize.X != ActiveBuffer->ScreenBufferSize.X || BufSize.Y != ActiveBuffer->ScreenBufferSize.Y)
{
if (NT_SUCCESS(GuiResizeBuffer(Console, ActiveBuffer, BufSize)))
SizeChanged = TRUE;
}
/* Move the window to the user's values */
GuiData->GuiInfo.AutoPosition = pConInfo->ci.u.GuiInfo.AutoPosition;
GuiData->GuiInfo.WindowOrigin = pConInfo->ci.u.GuiInfo.WindowOrigin;
GuiConsoleMoveWindow(GuiData);
if (SizeChanged)
{
/* Resize the window to the user's values */
GuiData->WindowSizeLock = TRUE;
GuiConsoleResizeWindow(GuiData);
GuiData->WindowSizeLock = FALSE;
}
/// LOCK /// LeaveCriticalSection(&Console->Lock);
InvalidateRect(pConInfo->hConsoleWindow, NULL, TRUE);
/* Save settings if needed */
// FIXME: Do it in the console properties applet ??
if (SaveSettings)
{
DWORD ProcessId = HandleToUlong(ProcessData->Process->ClientId.UniqueProcess);
ConSrvWriteUserSettings(&pConInfo->ci, ProcessId);
}
/* Finally, close the section */
NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
NtClose(hSection);
}
static PGUI_CONSOLE_DATA
GuiGetGuiData(HWND hWnd)
{
@ -541,7 +268,7 @@ GuiGetGuiData(HWND hWnd)
return ( ((GuiData == NULL) || (GuiData->hWindow == hWnd && GuiData->Console != NULL)) ? GuiData : NULL );
}
static VOID
VOID
GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData)
{
/* Move the window if needed (not positioned by the system) */
@ -563,19 +290,19 @@ GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData)
PCONSOLE Console = GuiData->Console;
SCROLLINFO sInfo;
DWORD Width = Console->Size.X * GuiData->CharWidth +
DWORD Width = Console->ConsoleSize.X * GuiData->CharWidth +
2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
DWORD Height = Console->Size.Y * GuiData->CharHeight +
DWORD Height = Console->ConsoleSize.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->ScreenBufferSize.Y > Console->Size.Y)
if (Console->ActiveBuffer->ScreenBufferSize.Y > Console->ConsoleSize.Y)
{
sInfo.nMax = Console->ActiveBuffer->ScreenBufferSize.Y - 1;
sInfo.nPage = Console->Size.Y;
sInfo.nPage = Console->ConsoleSize.Y;
sInfo.nPos = Console->ActiveBuffer->ShowY;
SetScrollInfo(GuiData->hWindow, SB_VERT, &sInfo, TRUE);
Width += GetSystemMetrics(SM_CXVSCROLL);
@ -586,10 +313,10 @@ GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData)
ShowScrollBar(GuiData->hWindow, SB_VERT, FALSE);
}
if (Console->ActiveBuffer->ScreenBufferSize.X > Console->Size.X)
if (Console->ActiveBuffer->ScreenBufferSize.X > Console->ConsoleSize.X)
{
sInfo.nMax = Console->ActiveBuffer->ScreenBufferSize.X - 1;
sInfo.nPage = Console->Size.X;
sInfo.nPage = Console->ConsoleSize.X;
sInfo.nPos = Console->ActiveBuffer->ShowX;
SetScrollInfo(GuiData->hWindow, SB_HORZ, &sInfo, TRUE);
Height += GetSystemMetrics(SM_CYHSCROLL);
@ -998,10 +725,10 @@ GuiConsoleHandleTimer(PGUI_CONSOLE_DATA GuiData)
// If we successfully got the info for the horizontal scrollbar
if(OldScrollX >= 0)
{
if((Buff->CursorPosition.X < Buff->ShowX)||(Buff->CursorPosition.X >= (Buff->ShowX + Console->Size.X)))
if((Buff->CursorPosition.X < Buff->ShowX)||(Buff->CursorPosition.X >= (Buff->ShowX + Console->ConsoleSize.X)))
{
// Handle the horizontal scroll bar
if(Buff->CursorPosition.X >= Console->Size.X) NewScrollX = Buff->CursorPosition.X - Console->Size.X + 1;
if(Buff->CursorPosition.X >= Console->ConsoleSize.X) NewScrollX = Buff->CursorPosition.X - Console->ConsoleSize.X + 1;
else NewScrollX = 0;
}
else
@ -1012,10 +739,10 @@ GuiConsoleHandleTimer(PGUI_CONSOLE_DATA GuiData)
// If we successfully got the info for the vertical scrollbar
if(OldScrollY >= 0)
{
if((Buff->CursorPosition.Y < Buff->ShowY) || (Buff->CursorPosition.Y >= (Buff->ShowY + Console->Size.Y)))
if((Buff->CursorPosition.Y < Buff->ShowY) || (Buff->CursorPosition.Y >= (Buff->ShowY + Console->ConsoleSize.Y)))
{
// Handle the vertical scroll bar
if(Buff->CursorPosition.Y >= Console->Size.Y) NewScrollY = Buff->CursorPosition.Y - Console->Size.Y + 1;
if(Buff->CursorPosition.Y >= Console->ConsoleSize.Y) NewScrollY = Buff->CursorPosition.Y - Console->ConsoleSize.Y + 1;
else NewScrollY = 0;
}
else
@ -1288,8 +1015,8 @@ GuiConsoleGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData, PMINMAXINFO minMaxInfo)
windx = (Console->ActiveBuffer->ScreenBufferSize.X) * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
windy = (Console->ActiveBuffer->ScreenBufferSize.Y) * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION);
if(Console->Size.X < Console->ActiveBuffer->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar
if(Console->Size.Y < Console->ActiveBuffer->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar
if(Console->ConsoleSize.X < Console->ActiveBuffer->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar
if(Console->ConsoleSize.Y < Console->ActiveBuffer->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar
minMaxInfo->ptMaxTrackSize.x = windx;
minMaxInfo->ptMaxTrackSize.y = windy;
@ -1312,8 +1039,8 @@ GuiConsoleResize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
windy = HIWORD(lParam);
// Compensate for existing scroll bars (because lParam values do not accommodate scroll bar)
if(Console->Size.X < Buff->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar
if(Console->Size.Y < Buff->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar
if(Console->ConsoleSize.X < Buff->ScreenBufferSize.X) windy += GetSystemMetrics(SM_CYHSCROLL); // window currently has a horizontal scrollbar
if(Console->ConsoleSize.Y < Buff->ScreenBufferSize.Y) windx += GetSystemMetrics(SM_CXVSCROLL); // window currently has a vertical scrollbar
charx = windx / GuiData->CharWidth;
chary = windy / GuiData->CharHeight;
@ -1334,17 +1061,17 @@ GuiConsoleResize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
if((windy % GuiData->CharHeight) >= (GuiData->CharHeight / 2)) ++chary;
// Resize window
if((charx != Console->Size.X) || (chary != Console->Size.Y))
if((charx != Console->ConsoleSize.X) || (chary != Console->ConsoleSize.Y))
{
Console->Size.X = (charx <= Buff->ScreenBufferSize.X) ? charx : Buff->ScreenBufferSize.X;
Console->Size.Y = (chary <= Buff->ScreenBufferSize.Y) ? chary : Buff->ScreenBufferSize.Y;
Console->ConsoleSize.X = (charx <= Buff->ScreenBufferSize.X) ? charx : Buff->ScreenBufferSize.X;
Console->ConsoleSize.Y = (chary <= Buff->ScreenBufferSize.Y) ? chary : Buff->ScreenBufferSize.Y;
}
GuiConsoleResizeWindow(GuiData);
// Adjust the start of the visible area if we are attempting to show nonexistent areas
if((Buff->ScreenBufferSize.X - Buff->ShowX) < Console->Size.X) Buff->ShowX = Buff->ScreenBufferSize.X - Console->Size.X;
if((Buff->ScreenBufferSize.Y - Buff->ShowY) < Console->Size.Y) Buff->ShowY = Buff->ScreenBufferSize.Y - Console->Size.Y;
if((Buff->ScreenBufferSize.X - Buff->ShowX) < Console->ConsoleSize.X) Buff->ShowX = Buff->ScreenBufferSize.X - Console->ConsoleSize.X;
if((Buff->ScreenBufferSize.Y - Buff->ShowY) < Console->ConsoleSize.Y) Buff->ShowY = Buff->ScreenBufferSize.Y - Console->ConsoleSize.Y;
InvalidateRect(GuiData->hWindow, NULL, TRUE);
GuiData->WindowSizeLock = FALSE;
@ -1398,13 +1125,13 @@ GuiConsoleHandleScroll(PGUI_CONSOLE_DATA GuiData, UINT uMsg, WPARAM wParam)
if (uMsg == WM_HSCROLL)
{
fnBar = SB_HORZ;
Maximum = Buff->ScreenBufferSize.X - Console->Size.X;
Maximum = Buff->ScreenBufferSize.X - Console->ConsoleSize.X;
pShowXY = &Buff->ShowX;
}
else
{
fnBar = SB_VERT;
Maximum = Buff->ScreenBufferSize.Y - Console->Size.Y;
Maximum = Buff->ScreenBufferSize.Y - Console->ConsoleSize.Y;
pShowXY = &Buff->ShowY;
}
@ -1900,7 +1627,7 @@ GuiWriteStream(PCONSOLE Console, SMALL_RECT* Region, LONG CursorStartX, LONG Cur
{
ScrollRect.left = 0;
ScrollRect.top = 0;
ScrollRect.right = Console->Size.X * GuiData->CharWidth;
ScrollRect.right = Console->ConsoleSize.X * GuiData->CharWidth;
ScrollRect.bottom = Region->Top * GuiData->CharHeight;
ScrollWindowEx(GuiData->hWindow,
@ -1993,7 +1720,7 @@ GuiResizeBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Siz
DWORD diff;
/* Buffer size is not allowed to be smaller than window size */
if (Size.X < Console->Size.X || Size.Y < Console->Size.Y)
if (Size.X < Console->ConsoleSize.X || Size.Y < Console->ConsoleSize.Y)
return STATUS_INVALID_PARAMETER;
if (Size.X == ScreenBuffer->ScreenBufferSize.X && Size.Y == ScreenBuffer->ScreenBufferSize.Y)
@ -2059,10 +1786,10 @@ GuiResizeBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Siz
ScreenBuffer->CursorPosition.X = Size.X - 1;
if (ScreenBuffer->CursorPosition.Y >= Size.Y)
ScreenBuffer->CursorPosition.Y = Size.Y - 1;
if (ScreenBuffer->ShowX > Size.X - Console->Size.X)
ScreenBuffer->ShowX = Size.X - Console->Size.X;
if (ScreenBuffer->ShowY > Size.Y - Console->Size.Y)
ScreenBuffer->ShowY = Size.Y - Console->Size.Y;
if (ScreenBuffer->ShowX > Size.X - Console->ConsoleSize.X)
ScreenBuffer->ShowX = Size.X - Console->ConsoleSize.X;
if (ScreenBuffer->ShowY > Size.Y - Console->ConsoleSize.Y)
ScreenBuffer->ShowY = Size.Y - Console->ConsoleSize.Y;
/* TODO: Should update scrollbar, but can't use anything that
* calls SendMessage or it could cause deadlock --> Use PostMessage */
@ -2071,6 +1798,17 @@ GuiResizeBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Siz
return STATUS_SUCCESS;
}
static VOID WINAPI
GuiResizeTerminal(PCONSOLE Console)
{
PGUI_CONSOLE_DATA GuiData = Console->TermIFace.Data;
/* Resize the window to the user's values */
GuiData->WindowSizeLock = TRUE;
GuiConsoleResizeWindow(GuiData);
GuiData->WindowSizeLock = FALSE;
}
static BOOL WINAPI
GuiProcessKeyCallback(PCONSOLE Console, MSG* msg, BYTE KeyStateMenu, DWORD ShiftState, UINT VirtualKeyCode, BOOL Down)
{
@ -2151,7 +1889,7 @@ GuiGetConsoleWindowHandle(PCONSOLE Console)
return GuiData->hWindow;
}
static TERMINAL_VTBL GuiVtbl =
static FRONTEND_VTBL GuiVtbl =
{
GuiCleanupConsole,
GuiWriteStream,
@ -2160,6 +1898,7 @@ static TERMINAL_VTBL GuiVtbl =
GuiSetScreenInfo,
GuiUpdateScreenInfo,
GuiResizeBuffer,
GuiResizeTerminal,
GuiProcessKeyCallback,
GuiRefreshInternalInfo,
GuiChangeTitle,
@ -2169,12 +1908,14 @@ static TERMINAL_VTBL GuiVtbl =
NTSTATUS FASTCALL
GuiInitConsole(PCONSOLE Console,
LPCWSTR AppPath,
/*IN*/ PCONSOLE_START_INFO ConsoleStartInfo,
PCONSOLE_INFO ConsoleInfo,
DWORD ProcessId,
LPCWSTR IconPath,
INT IconIndex)
{
PGUI_CONSOLE_DATA GuiData;
GUI_CONSOLE_INFO TermInfo;
if (Console == NULL || ConsoleInfo == NULL)
return STATUS_INVALID_PARAMETER;
@ -2198,15 +1939,59 @@ GuiInitConsole(PCONSOLE Console,
InitializeCriticalSection(&GuiData->Lock);
/* Set up the GUI data */
wcsncpy(GuiData->GuiInfo.FaceName, ConsoleInfo->u.GuiInfo.FaceName, LF_FACESIZE);
GuiData->GuiInfo.FontFamily = ConsoleInfo->u.GuiInfo.FontFamily;
GuiData->GuiInfo.FontSize = ConsoleInfo->u.GuiInfo.FontSize;
GuiData->GuiInfo.FontWeight = ConsoleInfo->u.GuiInfo.FontWeight;
GuiData->GuiInfo.UseRasterFonts = ConsoleInfo->u.GuiInfo.UseRasterFonts;
GuiData->GuiInfo.ShowWindow = ConsoleInfo->u.GuiInfo.ShowWindow;
GuiData->GuiInfo.AutoPosition = ConsoleInfo->u.GuiInfo.AutoPosition;
GuiData->GuiInfo.WindowOrigin = ConsoleInfo->u.GuiInfo.WindowOrigin;
/*
* Load the terminal settings
*/
/***********************************************
* Adapted from ConSrvInitConsole in console.c *
***********************************************/
/* 1. Load the default settings */
GuiConsoleGetDefaultSettings(&TermInfo, ProcessId);
/* 2. Load the remaining console settings via the registry. */
if ((ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) == 0)
{
/* Load the terminal infos from the registry. */
GuiConsoleReadUserSettings(&TermInfo, ConsoleInfo->ConsoleTitle, ProcessId);
/*
* Now, update them with the properties the user might gave to us
* via the STARTUPINFO structure before calling CreateProcess
* (and which was transmitted via the ConsoleStartInfo structure).
* We therefore overwrite the values read in the registry.
*/
if (ConsoleStartInfo->dwStartupFlags & STARTF_USESHOWWINDOW)
{
TermInfo.ShowWindow = ConsoleStartInfo->ShowWindow;
}
if (ConsoleStartInfo->dwStartupFlags & STARTF_USEPOSITION)
{
TermInfo.AutoPosition = FALSE;
TermInfo.WindowOrigin = ConsoleStartInfo->ConsoleWindowOrigin;
}
/*
if (ConsoleStartInfo->dwStartupFlags & STARTF_RUNFULLSCREEN)
{
}
*/
}
/*
* Set up the GUI data
*/
wcsncpy(GuiData->GuiInfo.FaceName, TermInfo.FaceName, LF_FACESIZE);
GuiData->GuiInfo.FontFamily = TermInfo.FontFamily;
GuiData->GuiInfo.FontSize = TermInfo.FontSize;
GuiData->GuiInfo.FontWeight = TermInfo.FontWeight;
GuiData->GuiInfo.UseRasterFonts = TermInfo.UseRasterFonts;
GuiData->GuiInfo.ShowWindow = TermInfo.ShowWindow;
GuiData->GuiInfo.AutoPosition = TermInfo.AutoPosition;
GuiData->GuiInfo.WindowOrigin = TermInfo.WindowOrigin;
/* Initialize the icon handles to their default values */
GuiData->hIcon = ghDefaultIcon;
@ -2215,7 +2000,7 @@ GuiInitConsole(PCONSOLE Console,
/* Get the associated icon, if any */
if (IconPath == NULL || *IconPath == L'\0')
{
IconPath = AppPath;
IconPath = ConsoleStartInfo->AppPath;
IconIndex = 0;
}
DPRINT1("IconPath = %S ; IconIndex = %lu\n", (IconPath ? IconPath : L"n/a"), IconIndex);

View file

@ -2,11 +2,13 @@
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/guiconsole.h
* PURPOSE: GUI terminal emulator
* PURPOSE: GUI front-end
* PROGRAMMERS:
*/
#include "conio.h"
#pragma once
// #include "guisettings.h"
#define CONGUI_MIN_WIDTH 10
#define CONGUI_MIN_HEIGHT 10
@ -14,10 +16,10 @@
#define CONGUI_UPDATE_TIMER 1
NTSTATUS FASTCALL GuiInitConsole(PCONSOLE Console,
LPCWSTR AppPath,
/*IN*/ PCONSOLE_START_INFO ConsoleStartInfo,
PCONSOLE_INFO ConsoleInfo,
DWORD ProcessId,
LPCWSTR IconPath,
INT IconIndex);
VOID FASTCALL GuiConsoleHandleScrollbarMenu(VOID);
/*EOF*/
/* EOF */

View file

@ -0,0 +1,462 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/guisettings.c
* PURPOSE: GUI terminal emulator settings management
* PROGRAMMERS: Hermes Belusca - Maito
*/
/* INCLUDES *******************************************************************/
#include "consrv.h"
#include "conio.h"
#include "settings.h"
#include "guiconsole.h"
#include "guisettings.h"
#define NDEBUG
#include <debug.h>
VOID GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData);
/* FUNCTIONS ******************************************************************/
BOOL
GuiConsoleReadUserSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
IN LPCWSTR ConsoleTitle,
IN DWORD ProcessId)
{
/*****************************************************
* Adapted from ConSrvReadUserSettings in settings.c *
*****************************************************/
BOOL RetVal = FALSE;
HKEY hKey;
DWORD dwNumSubKeys = 0;
DWORD dwIndex;
DWORD dwType;
WCHAR szValueName[MAX_PATH];
DWORD dwValueName;
WCHAR szValue[LF_FACESIZE] = L"\0";
DWORD Value;
DWORD dwValue;
if (!ConSrvOpenUserSettings(ProcessId,
ConsoleTitle,
&hKey, KEY_READ,
FALSE))
{
DPRINT("ConSrvOpenUserSettings failed\n");
return FALSE;
}
if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
&dwNumSubKeys, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
{
DPRINT("GuiConsoleReadUserSettings: RegQueryInfoKey failed\n");
RegCloseKey(hKey);
return FALSE;
}
DPRINT("GuiConsoleReadUserSettings entered dwNumSubKeys %d\n", dwNumSubKeys);
for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++)
{
dwValue = sizeof(Value);
dwValueName = MAX_PATH; // sizeof(szValueName)/sizeof(szValueName[0])
if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS)
{
if (dwType == REG_SZ)
{
/*
* Retry in case of string value
*/
dwValue = sizeof(szValue);
dwValueName = MAX_PATH; // sizeof(szValueName)/sizeof(szValueName[0])
if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS)
break;
}
else
{
break;
}
}
if (!wcscmp(szValueName, L"FaceName"))
{
wcsncpy(TermInfo->FaceName, szValue, LF_FACESIZE);
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"FontFamily"))
{
TermInfo->FontFamily = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"FontSize"))
{
TermInfo->FontSize = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"FontWeight"))
{
TermInfo->FontWeight = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"WindowPosition"))
{
TermInfo->AutoPosition = FALSE;
TermInfo->WindowOrigin.x = LOWORD(Value);
TermInfo->WindowOrigin.y = HIWORD(Value);
RetVal = TRUE;
}
}
RegCloseKey(hKey);
return RetVal;
}
BOOL
GuiConsoleWriteUserSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
IN LPCWSTR ConsoleTitle,
IN DWORD ProcessId)
{
/******************************************************
* Adapted from ConSrvWriteUserSettings in settings.c *
******************************************************/
BOOL GlobalSettings = (ConsoleTitle[0] == L'\0');
HKEY hKey;
DWORD Storage = 0;
#define SetConsoleSetting(SettingName, SettingType, SettingSize, Setting, DefaultValue) \
do { \
if (GlobalSettings || (!GlobalSettings && (*(Setting) != (DefaultValue)))) \
{ \
RegSetValueExW(hKey, (SettingName), 0, (SettingType), (PBYTE)(Setting), (SettingSize)); \
} \
else \
{ \
RegDeleteValue(hKey, (SettingName)); \
} \
} while (0)
if (!ConSrvOpenUserSettings(ProcessId,
ConsoleTitle,
&hKey, KEY_WRITE,
TRUE))
{
return FALSE;
}
SetConsoleSetting(L"FaceName", REG_SZ, (wcslen(TermInfo->FaceName) + 1) * sizeof(WCHAR), TermInfo->FaceName, L'\0');
SetConsoleSetting(L"FontFamily", REG_DWORD, sizeof(DWORD), &TermInfo->FontFamily, FF_DONTCARE);
SetConsoleSetting(L"FontSize", REG_DWORD, sizeof(DWORD), &TermInfo->FontSize, 0);
SetConsoleSetting(L"FontWeight", REG_DWORD, sizeof(DWORD), &TermInfo->FontWeight, FW_DONTCARE);
if (TermInfo->AutoPosition == FALSE)
{
Storage = MAKELONG(TermInfo->WindowOrigin.x, TermInfo->WindowOrigin.y);
RegSetValueExW(hKey, L"WindowPosition", 0, REG_DWORD, (PBYTE)&Storage, sizeof(DWORD));
}
else
{
RegDeleteValue(hKey, L"WindowPosition");
}
RegCloseKey(hKey);
return TRUE;
}
VOID
GuiConsoleGetDefaultSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
IN DWORD ProcessId)
{
/*******************************************************
* Adapted from ConSrvGetDefaultSettings in settings.c *
*******************************************************/
if (TermInfo == NULL) return;
/*
* 1. Load the default values
*/
// wcsncpy(TermInfo->FaceName, L"DejaVu Sans Mono", LF_FACESIZE);
// TermInfo->FontSize = MAKELONG(12, 8); // 0x0008000C; // font is 8x12
// TermInfo->FontSize = MAKELONG(16, 16); // font is 16x16
// TermInfo->FontWeight = FW_NORMAL;
wcsncpy(TermInfo->FaceName, L"Fixedsys", LF_FACESIZE); // HACK: !!
// TermInfo->FaceName[0] = L'\0';
TermInfo->FontFamily = FF_DONTCARE;
TermInfo->FontSize = 0;
TermInfo->FontWeight = FW_DONTCARE;
TermInfo->UseRasterFonts = TRUE;
TermInfo->ShowWindow = SW_SHOWNORMAL;
TermInfo->AutoPosition = TRUE;
TermInfo->WindowOrigin = (POINT){0, 0};
/*
* 2. Overwrite them with the ones stored in HKCU\Console.
* If the HKCU\Console key doesn't exist, create it
* and store the default values inside.
*/
if (!GuiConsoleReadUserSettings(TermInfo, L"", ProcessId))
{
GuiConsoleWriteUserSettings(TermInfo, L"", ProcessId);
}
}
VOID
GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
BOOL Defaults)
{
NTSTATUS Status;
PCONSOLE Console = GuiData->Console;
PCONSOLE_PROCESS_DATA ProcessData;
HANDLE hSection = NULL, hClientSection = NULL;
LARGE_INTEGER SectionSize;
ULONG ViewSize = 0;
SIZE_T Length = 0;
PCONSOLE_PROPS pSharedInfo = NULL;
PGUI_CONSOLE_INFO GuiInfo = NULL;
DPRINT("GuiConsoleShowConsoleProperties entered\n");
/*
* Create a memory section to share with the applet, and map it.
*/
/* Holds data for console.dll + console info + terminal-specific info */
SectionSize.QuadPart = sizeof(CONSOLE_PROPS) + sizeof(GUI_CONSOLE_INFO);
Status = NtCreateSection(&hSection,
SECTION_ALL_ACCESS,
NULL,
&SectionSize,
PAGE_READWRITE,
SEC_COMMIT,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to create a shared section ; Status = %lu\n", Status);
return;
}
Status = NtMapViewOfSection(hSection,
NtCurrentProcess(),
(PVOID*)&pSharedInfo,
0,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
NtClose(hSection);
return;
}
/*
* Setup the shared console properties structure.
*/
/* Header */
pSharedInfo->hConsoleWindow = GuiData->hWindow;
pSharedInfo->ShowDefaultParams = Defaults;
/* Console information */
pSharedInfo->ci.HistoryBufferSize = Console->HistoryBufferSize;
pSharedInfo->ci.NumberOfHistoryBuffers = Console->NumberOfHistoryBuffers;
pSharedInfo->ci.HistoryNoDup = Console->HistoryNoDup;
pSharedInfo->ci.FullScreen = Console->FullScreen;
pSharedInfo->ci.QuickEdit = Console->QuickEdit;
pSharedInfo->ci.InsertMode = Console->InsertMode;
pSharedInfo->ci.InputBufferSize = 0;
pSharedInfo->ci.ScreenBufferSize = Console->ActiveBuffer->ScreenBufferSize;
pSharedInfo->ci.ConsoleSize = Console->ConsoleSize;
pSharedInfo->ci.CursorBlinkOn;
pSharedInfo->ci.ForceCursorOff;
pSharedInfo->ci.CursorSize = Console->ActiveBuffer->CursorInfo.dwSize;
pSharedInfo->ci.ScreenAttrib = Console->ActiveBuffer->ScreenDefaultAttrib;
pSharedInfo->ci.PopupAttrib = Console->ActiveBuffer->PopupDefaultAttrib;
pSharedInfo->ci.CodePage;
/* GUI Information */
pSharedInfo->TerminalInfo.Size = sizeof(GUI_CONSOLE_INFO);
GuiInfo = pSharedInfo->TerminalInfo.TermInfo = (PGUI_CONSOLE_INFO)(pSharedInfo + 1);
wcsncpy(GuiInfo->FaceName, GuiData->GuiInfo.FaceName, LF_FACESIZE);
GuiInfo->FontSize = (DWORD)GuiData->GuiInfo.FontSize;
GuiInfo->FontWeight = GuiData->GuiInfo.FontWeight;
GuiInfo->UseRasterFonts = GuiData->GuiInfo.UseRasterFonts;
/// GuiInfo->WindowPosition = GuiData->GuiInfo.WindowPosition;
GuiInfo->AutoPosition = GuiData->GuiInfo.AutoPosition;
GuiInfo->WindowOrigin = GuiData->GuiInfo.WindowOrigin;
/* Offsetize */
pSharedInfo->TerminalInfo.TermInfo = (PVOID)((ULONG_PTR)GuiInfo - (ULONG_PTR)pSharedInfo);
/* Palette */
memcpy(pSharedInfo->ci.Colors, Console->Colors, sizeof(Console->Colors));
/* Title of the console, original one corresponding to the one set by the console leader */
Length = min(sizeof(pSharedInfo->ci.ConsoleTitle) / sizeof(pSharedInfo->ci.ConsoleTitle[0]) - 1,
Console->OriginalTitle.Length / sizeof(WCHAR));
wcsncpy(pSharedInfo->ci.ConsoleTitle, Console->OriginalTitle.Buffer, Length);
pSharedInfo->ci.ConsoleTitle[Length] = L'\0';
/* Unmap the view */
NtUnmapViewOfSection(NtCurrentProcess(), pSharedInfo);
/* Get the console leader process, our client */
ProcessData = CONTAINING_RECORD(Console->ProcessList.Blink,
CONSOLE_PROCESS_DATA,
ConsoleLink);
/* Duplicate the section handle for the client */
Status = NtDuplicateObject(NtCurrentProcess(),
hSection,
ProcessData->Process->ProcessHandle,
&hClientSection,
0, 0, DUPLICATE_SAME_ACCESS);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error: Impossible to duplicate section handle for client ; Status = %lu\n", Status);
NtClose(hSection);
return;
}
/* Start the properties dialog */
if (ProcessData->PropDispatcher)
{
HANDLE Thread;
Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
ProcessData->PropDispatcher,
(PVOID)hClientSection, 0, NULL);
if (NULL == Thread)
{
DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
return;
}
DPRINT1("We succeeded at creating ProcessData->PropDispatcher remote thread, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
/// WaitForSingleObject(Thread, INFINITE);
CloseHandle(Thread);
}
/* We have finished, close the section handle */
NtClose(hSection);
return;
}
NTSTATUS
GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
HANDLE hClientSection,
BOOL SaveSettings)
{
NTSTATUS Status = STATUS_SUCCESS;
PCONSOLE Console = GuiData->Console;
PCONSOLE_PROCESS_DATA ProcessData;
HANDLE hSection = NULL;
ULONG ViewSize = 0;
PCONSOLE_PROPS pConInfo = NULL;
PCONSOLE_INFO ConInfo = NULL;
PTERMINAL_INFO TermInfo = NULL;
PGUI_CONSOLE_INFO GuiInfo = NULL;
/// LOCK /// EnterCriticalSection(&Console->Lock);
/* Get the console leader process, our client */
ProcessData = CONTAINING_RECORD(Console->ProcessList.Blink,
CONSOLE_PROCESS_DATA,
ConsoleLink);
/* Duplicate the section handle for ourselves */
Status = NtDuplicateObject(ProcessData->Process->ProcessHandle,
hClientSection,
NtCurrentProcess(),
&hSection,
0, 0, DUPLICATE_SAME_ACCESS);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error when mapping client handle, Status = %lu\n", Status);
return Status;
}
/* Get a view of the shared section */
Status = NtMapViewOfSection(hSection,
NtCurrentProcess(),
(PVOID*)&pConInfo,
0,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READONLY);
if (!NT_SUCCESS(Status))
{
DPRINT1("Error when mapping view of file, Status = %lu\n", Status);
NtClose(hSection);
return Status;
}
/* Check that the section is well-sized */
if ( (ViewSize < sizeof(CONSOLE_PROPS)) ||
(pConInfo->TerminalInfo.Size != sizeof(GUI_CONSOLE_INFO)) ||
(ViewSize < sizeof(CONSOLE_PROPS) + pConInfo->TerminalInfo.Size) )
{
DPRINT1("Error: section bad-sized: sizeof(Section) < sizeof(CONSOLE_PROPS) + sizeof(Terminal_specific_info)\n");
Status = STATUS_INVALID_VIEW_SIZE;
goto Quit;
}
// TODO: Check that GuiData->hWindow == pConInfo->hConsoleWindow
/* Set the console informations */
ConInfo = &pConInfo->ci;
ConSrvApplyUserSettings(Console, ConInfo);
/* Set the terminal informations - De-offsetization of the pointer */
TermInfo = &pConInfo->TerminalInfo;
GuiInfo = TermInfo->TermInfo = (PVOID)((ULONG_PTR)pConInfo + (ULONG_PTR)TermInfo->TermInfo);
// memcpy(&GuiData->GuiInfo, GuiInfo, sizeof(GUI_CONSOLE_INFO));
/* Move the window to the user's values */
GuiData->GuiInfo.AutoPosition = GuiInfo->AutoPosition;
GuiData->GuiInfo.WindowOrigin = GuiInfo->WindowOrigin;
GuiConsoleMoveWindow(GuiData);
InvalidateRect(GuiData->hWindow, NULL, TRUE);
/*
* Save settings if needed
*/
// FIXME: Do it in the console properties applet ??
if (SaveSettings)
{
DWORD ProcessId = HandleToUlong(ProcessData->Process->ClientId.UniqueProcess);
ConSrvWriteUserSettings(ConInfo, ProcessId);
GuiConsoleWriteUserSettings(GuiInfo, ConInfo->ConsoleTitle, ProcessId);
}
Status = STATUS_SUCCESS;
/// LOCK /// LeaveCriticalSection(&Console->Lock);
Quit:
/* Finally, close the section and return */
NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
NtClose(hSection);
return Status;
}
/* EOF */

View file

@ -0,0 +1,83 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/guisettings.h
* PURPOSE: GUI front-end settings management
* PROGRAMMERS: Hermes Belusca - Maito
*
* NOTE: Also used by console.dll
*/
#pragma once
// #include "guiconsole.h"
#ifndef WM_APP
#define WM_APP 0x8000
#endif
#define PM_APPLY_CONSOLE_INFO (WM_APP + 100)
/* STRUCTURES *****************************************************************/
typedef struct _GUI_CONSOLE_INFO
{
// FONTSIGNATURE FontSignature;
WCHAR FaceName[LF_FACESIZE];
UINT FontFamily;
DWORD FontSize;
DWORD FontWeight;
BOOL UseRasterFonts;
WORD ShowWindow;
BOOL AutoPosition;
POINT WindowOrigin;
} GUI_CONSOLE_INFO, *PGUI_CONSOLE_INFO;
#ifndef CONSOLE_H__ // If we aren't included by console.dll
typedef struct _GUI_CONSOLE_DATA
{
CRITICAL_SECTION Lock;
HANDLE hGuiInitEvent;
BOOL WindowSizeLock;
POINT OldCursor;
HWND hWindow; /* Handle to the console's window */
HICON hIcon; /* Handle to the console's icon (big) */
HICON hIconSm; /* Handle to the console's icon (small) */
// COLORREF Colors[16];
// PVOID ScreenBuffer; /* Hardware screen buffer */
HFONT Font;
UINT CharWidth;
UINT CharHeight;
PCONSOLE Console; /* Pointer to the owned console */
GUI_CONSOLE_INFO GuiInfo; /* GUI terminal settings */
} GUI_CONSOLE_DATA, *PGUI_CONSOLE_DATA;
/* FUNCTIONS ******************************************************************/
BOOL
GuiConsoleReadUserSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
IN LPCWSTR ConsoleTitle,
IN DWORD ProcessId);
BOOL
GuiConsoleWriteUserSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
IN LPCWSTR ConsoleTitle,
IN DWORD ProcessId);
VOID
GuiConsoleGetDefaultSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
IN DWORD ProcessId);
VOID
GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
BOOL Defaults);
NTSTATUS
GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
HANDLE hClientSection,
BOOL SaveSettings);
#endif
/* EOF */

View file

@ -399,7 +399,6 @@ ConSrvReleaseObject(Object_t *Object,
NTSTATUS
FASTCALL
ConSrvAllocateConsole(PCONSOLE_PROCESS_DATA ProcessData,
LPCWSTR AppPath,
PHANDLE pInputHandle,
PHANDLE pOutputHandle,
PHANDLE pErrorHandle,
@ -408,7 +407,7 @@ ConSrvAllocateConsole(PCONSOLE_PROCESS_DATA ProcessData,
NTSTATUS Status = STATUS_SUCCESS;
/* Initialize a new Console owned by this process */
Status = ConSrvInitConsole(&ProcessData->Console, AppPath, ConsoleStartInfo, ProcessData->Process);
Status = ConSrvInitConsole(&ProcessData->Console, ConsoleStartInfo, ProcessData->Process);
if (!NT_SUCCESS(Status))
{
DPRINT1("Console initialization failed\n");
@ -693,7 +692,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
/* Initialize a new Console owned by the Console Leader Process */
Status = ConSrvAllocateConsole(ProcessData,
ConnectInfo->AppPath,
&ConnectInfo->InputHandle,
&ConnectInfo->OutputHandle,
&ConnectInfo->ErrorHandle,

View file

@ -116,7 +116,7 @@ OpenUserRegistryPathPerProcessId(DWORD ProcessId,
return bRet;
}
BOOL
/*static*/ BOOL
ConSrvOpenUserSettings(DWORD ProcessId,
LPCWSTR ConsoleTitle,
PHKEY hSubKey,
@ -191,16 +191,17 @@ BOOL
ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
IN DWORD ProcessId)
{
BOOL RetVal = FALSE;
HKEY hKey;
DWORD dwNumSubKeys = 0;
DWORD dwIndex;
DWORD dwValueName;
DWORD dwValue;
DWORD dwColorIndex = 0;
DWORD dwType;
WCHAR szValueName[MAX_PATH];
DWORD dwValueName;
WCHAR szValue[LF_FACESIZE] = L"\0";
DWORD Value;
DWORD dwValue;
if (!ConSrvOpenUserSettings(ProcessId,
ConsoleInfo->ConsoleTitle,
@ -224,7 +225,7 @@ ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++)
{
dwValue = sizeof(Value);
dwValueName = MAX_PATH;
dwValueName = MAX_PATH; // sizeof(szValueName)/sizeof(szValueName[0])
if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS)
{
@ -234,7 +235,7 @@ ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
* Retry in case of string value
*/
dwValue = sizeof(szValue);
dwValueName = LF_FACESIZE;
dwValueName = MAX_PATH; // sizeof(szValueName)/sizeof(szValueName[0])
if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS)
break;
}
@ -244,6 +245,7 @@ ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
}
}
/* Maybe it is UI-specific ?? */
if (!wcsncmp(szValueName, L"ColorTable", wcslen(L"ColorTable")))
{
dwColorIndex = 0;
@ -251,80 +253,70 @@ ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
if (dwColorIndex < sizeof(ConsoleInfo->Colors)/sizeof(ConsoleInfo->Colors[0]))
{
ConsoleInfo->Colors[dwColorIndex] = Value;
RetVal = TRUE;
}
}
else if (!wcscmp(szValueName, L"HistoryBufferSize"))
{
ConsoleInfo->HistoryBufferSize = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"NumberOfHistoryBuffers"))
{
ConsoleInfo->NumberOfHistoryBuffers = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"HistoryNoDup"))
{
ConsoleInfo->HistoryNoDup = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"FullScreen"))
{
ConsoleInfo->FullScreen = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"QuickEdit"))
{
ConsoleInfo->QuickEdit = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"InsertMode"))
{
ConsoleInfo->InsertMode = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"ScreenBufferSize"))
{
ConsoleInfo->ScreenBufferSize.X = LOWORD(Value);
ConsoleInfo->ScreenBufferSize.Y = HIWORD(Value);
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"WindowSize"))
{
ConsoleInfo->ConsoleSize.X = LOWORD(Value);
ConsoleInfo->ConsoleSize.Y = HIWORD(Value);
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"CursorSize"))
{
ConsoleInfo->CursorSize = min(max(Value, 0), 100);
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"ScreenColors"))
{
ConsoleInfo->ScreenAttrib = Value;
RetVal = TRUE;
}
else if (!wcscmp(szValueName, L"PopupColors"))
{
ConsoleInfo->PopupAttrib = Value;
}
else if (!wcscmp(szValueName, L"FaceName"))
{
wcsncpy(ConsoleInfo->u.GuiInfo.FaceName, szValue, LF_FACESIZE);
}
else if (!wcscmp(szValueName, L"FontFamily"))
{
ConsoleInfo->u.GuiInfo.FontFamily = Value;
}
else if (!wcscmp(szValueName, L"FontSize"))
{
ConsoleInfo->u.GuiInfo.FontSize = Value;
}
else if (!wcscmp(szValueName, L"FontWeight"))
{
ConsoleInfo->u.GuiInfo.FontWeight = Value;
}
else if (!wcscmp(szValueName, L"WindowPosition"))
{
ConsoleInfo->u.GuiInfo.AutoPosition = FALSE;
ConsoleInfo->u.GuiInfo.WindowOrigin.x = LOWORD(Value);
ConsoleInfo->u.GuiInfo.WindowOrigin.y = HIWORD(Value);
RetVal = TRUE;
}
}
RegCloseKey(hKey);
return TRUE;
return RetVal;
}
BOOL
@ -398,21 +390,6 @@ do {
Storage = ConsoleInfo->PopupAttrib;
SetConsoleSetting(L"PopupColors", REG_DWORD, sizeof(DWORD), &Storage, DEFAULT_POPUP_ATTRIB);
SetConsoleSetting(L"FaceName", REG_SZ, (wcslen(ConsoleInfo->u.GuiInfo.FaceName) + 1) * sizeof(WCHAR), ConsoleInfo->u.GuiInfo.FaceName, L'\0');
SetConsoleSetting(L"FontFamily", REG_DWORD, sizeof(DWORD), &ConsoleInfo->u.GuiInfo.FontFamily, FF_DONTCARE);
SetConsoleSetting(L"FontSize", REG_DWORD, sizeof(DWORD), &ConsoleInfo->u.GuiInfo.FontSize, 0);
SetConsoleSetting(L"FontWeight", REG_DWORD, sizeof(DWORD), &ConsoleInfo->u.GuiInfo.FontWeight, FW_DONTCARE);
if (ConsoleInfo->u.GuiInfo.AutoPosition == FALSE)
{
Storage = MAKELONG(ConsoleInfo->u.GuiInfo.WindowOrigin.x, ConsoleInfo->u.GuiInfo.WindowOrigin.y);
RegSetValueExW(hKey, L"WindowPosition", 0, REG_DWORD, (PBYTE)&ConsoleInfo->u.GuiInfo.WindowOrigin, sizeof(DWORD));
}
else
{
RegDeleteValue(hKey, L"WindowPosition");
}
RegCloseKey(hKey);
return TRUE;
}
@ -454,22 +431,6 @@ ConSrvGetDefaultSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
ConsoleInfo->ConsoleTitle[0] = L'\0';
// wcsncpy(ConsoleInfo->u.GuiInfo.FaceName, L"DejaVu Sans Mono", LF_FACESIZE);
// ConsoleInfo->u.GuiInfo.FontSize = MAKELONG(12, 8); // 0x0008000C; // font is 8x12
// ConsoleInfo->u.GuiInfo.FontSize = MAKELONG(16, 16); // font is 16x16
// ConsoleInfo->u.GuiInfo.FontWeight = FW_NORMAL;
wcsncpy(ConsoleInfo->u.GuiInfo.FaceName, L"Fixedsys", LF_FACESIZE); // HACK: !!
// ConsoleInfo->u.GuiInfo.FaceName[0] = L'\0';
ConsoleInfo->u.GuiInfo.FontFamily = FF_DONTCARE;
ConsoleInfo->u.GuiInfo.FontSize = 0;
ConsoleInfo->u.GuiInfo.FontWeight = FW_DONTCARE;
ConsoleInfo->u.GuiInfo.UseRasterFonts = TRUE;
ConsoleInfo->u.GuiInfo.ShowWindow = SW_SHOWNORMAL;
ConsoleInfo->u.GuiInfo.AutoPosition = TRUE;
ConsoleInfo->u.GuiInfo.WindowOrigin = (POINT){0, 0};
/*
* 2. Overwrite them with the ones stored in HKCU\Console.
* If the HKCU\Console key doesn't exist, create it
@ -481,4 +442,46 @@ ConSrvGetDefaultSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
}
}
VOID
ConSrvApplyUserSettings(IN PCONSOLE Console,
IN PCONSOLE_INFO ConsoleInfo)
{
PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
COORD BufSize;
BOOL SizeChanged = FALSE;
/*
* Apply foreground and background colors for both screen and popup
* and copy the new palette.
*/
ActiveBuffer->ScreenDefaultAttrib = ConsoleInfo->ScreenAttrib;
ActiveBuffer->PopupDefaultAttrib = ConsoleInfo->PopupAttrib;
memcpy(Console->Colors, ConsoleInfo->Colors, sizeof(s_Colors)); // FIXME: Possible buffer overflow if s_colors is bigger than pConInfo->Colors.
// TODO: Really update the screen attributes as FillConsoleOutputAttribute does.
/* Apply cursor size */
ActiveBuffer->CursorInfo.bVisible = (ConsoleInfo->CursorSize != 0);
ActiveBuffer->CursorInfo.dwSize = min(max(ConsoleInfo->CursorSize, 0), 100);
/* Resize the console */
if (ConsoleInfo->ConsoleSize.X != Console->ConsoleSize.X ||
ConsoleInfo->ConsoleSize.Y != Console->ConsoleSize.Y)
{
Console->ConsoleSize = ConsoleInfo->ConsoleSize;
SizeChanged = TRUE;
}
/* Resize its active screen-buffer */
BufSize = ConsoleInfo->ScreenBufferSize;
if (BufSize.X != ActiveBuffer->ScreenBufferSize.X ||
BufSize.Y != ActiveBuffer->ScreenBufferSize.Y)
{
if (NT_SUCCESS(ConioResizeBuffer(Console, ActiveBuffer, BufSize)))
SizeChanged = TRUE;
}
if (SizeChanged) ConioResizeTerminal(Console);
}
/* EOF */

View file

@ -8,40 +8,34 @@
* NOTE: Adapted from existing code.
*/
#ifndef WM_APP
#define WM_APP 0x8000
#endif
#define PM_APPLY_CONSOLE_INFO (WM_APP + 100)
#pragma once
/* STRUCTURES *****************************************************************/
typedef struct _GUI_CONSOLE_INFO
/*
* Structure used to hold terminal-specific information
*/
typedef struct _TERMINAL_INFO
{
// FONTSIGNATURE FontSignature;
WCHAR FaceName[LF_FACESIZE];
UINT FontFamily;
DWORD FontSize;
DWORD FontWeight;
BOOL UseRasterFonts;
WORD ShowWindow;
BOOL AutoPosition;
POINT WindowOrigin;
} GUI_CONSOLE_INFO, *PGUI_CONSOLE_INFO;
ULONG Size; /* Size of the memory buffer pointed by TermInfo */
PVOID TermInfo; /* Address (or offset when talking to console.dll) of the memory buffer holding terminal information */
} TERMINAL_INFO, *PTERMINAL_INFO;
/*
* Structure used to hold console information
*/
typedef struct _CONSOLE_INFO
{
ULONG HistoryBufferSize;
ULONG NumberOfHistoryBuffers;
BOOLEAN HistoryNoDup;
/* BOOLEAN */ ULONG FullScreen; // Give the type of console: GUI (windowed) or TUI (fullscreen)
/* BOOLEAN */ ULONG FullScreen; /* Give the type of console: GUI (windowed) or TUI (fullscreen) */
BOOLEAN QuickEdit;
BOOLEAN InsertMode;
ULONG InputBufferSize;
COORD ScreenBufferSize;
/* SIZE */ COORD ConsoleSize; // This is really the size of the console at screen.
/* SIZE */ COORD ConsoleSize; /* The size of the console */
BOOLEAN CursorBlinkOn;
BOOLEAN ForceCursorOff;
@ -50,19 +44,11 @@ typedef struct _CONSOLE_INFO
USHORT ScreenAttrib; // CHAR_INFO ScreenFillAttrib
USHORT PopupAttrib;
// Color palette
COLORREF Colors[16];
COLORREF Colors[16]; /* Color palette */
ULONG CodePage;
WCHAR ConsoleTitle[MAX_PATH + 1];
// PVOID TerminalInfo; /* Terminal-specific parameters */
union
{
GUI_CONSOLE_INFO GuiInfo;
// TUI_CONSOLE_INFO TuiInfo;
} u;
} CONSOLE_INFO, *PCONSOLE_INFO;
#define RGBFromAttrib(Console, Attribute) ((Console)->Colors[(Attribute) & 0xF])
@ -70,8 +56,9 @@ typedef struct _CONSOLE_INFO
#define BkgdAttribFromAttrib(Attribute) (((Attribute) >> 4) & 0xF)
#define MakeAttrib(TextAttrib, BkgdAttrib) (DWORD)((((BkgdAttrib) & 0xF) << 4) | ((TextAttrib) & 0xF))
/* Used to communicate with console.dll */
/*
* Structure used to communicate with console.dll
*/
typedef struct _CONSOLE_PROPS
{
HWND hConsoleWindow;
@ -80,16 +67,29 @@ typedef struct _CONSOLE_PROPS
BOOLEAN AppliedConfig;
DWORD ActiveStaticControl;
CONSOLE_INFO ci;
CONSOLE_INFO ci; /* Console-specific informations */
TERMINAL_INFO TerminalInfo; /* Frontend-specific parameters */
} CONSOLE_PROPS, *PCONSOLE_PROPS;
/* FUNCTIONS ******************************************************************/
#ifndef CONSOLE_H__ // If we aren't included by console.dll
BOOL ConSrvOpenUserSettings(DWORD ProcessId,
LPCWSTR ConsoleTitle,
PHKEY hSubKey,
REGSAM samDesired,
BOOL bCreate);
BOOL ConSrvReadUserSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
IN DWORD ProcessId);
BOOL ConSrvWriteUserSettings(IN PCONSOLE_INFO ConsoleInfo,
IN DWORD ProcessId);
VOID ConSrvGetDefaultSettings(IN OUT PCONSOLE_INFO ConsoleInfo,
IN DWORD ProcessId);
VOID ConSrvApplyUserSettings(IN PCONSOLE Console,
IN PCONSOLE_INFO ConsoleInfo);
#endif
/* EOF */