- Start to sort out things that depends only of the internals of a console, and things which are only related to "terminal emulators". Do it especially for (what I will call starting from now) the "GUI terminal emulator".
- Temporarily deactivate starting "TUI terminals".
- Temporarily break report that the terminal window is held by the current running console application in it (see r58107). This will be fixed later on.

svn path=/branches/ros-csrss/; revision=58447
This commit is contained in:
Hermès Bélusca-Maïto 2013-03-08 23:37:11 +00:00
parent beff3acbf2
commit 818ee21a07
9 changed files with 934 additions and 839 deletions

View file

@ -16,14 +16,6 @@
#define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
#ifndef WM_APP
#define WM_APP 0x8000
#endif
#define PM_CREATE_CONSOLE (WM_APP + 1)
#define PM_DESTROY_CONSOLE (WM_APP + 2)
#define PM_CONSOLE_BEEP (WM_APP + 3)
#define PM_CONSOLE_SET_TITLE (WM_APP + 4)
/************************************************************************
* Screen buffer structure represents the win32 screen buffer object. *
@ -82,16 +74,81 @@ typedef struct ConsoleInput_t
INPUT_RECORD InputEvent;
} ConsoleInput;
typedef struct _TERMINAL_VTBL
{
/*
* Internal interface (functions called by the console server only)
*/
VOID (WINAPI *CleanupConsole)(struct _CONSOLE* Console);
VOID (WINAPI *WriteStream)(struct _CONSOLE* Console,
SMALL_RECT* Block,
LONG CursorStartX,
LONG CursorStartY,
UINT ScrolledLines,
CHAR *Buffer,
UINT Length);
VOID (WINAPI *DrawRegion)(struct _CONSOLE* Console,
SMALL_RECT* Region);
BOOL (WINAPI *SetCursorInfo)(struct _CONSOLE* Console,
PCONSOLE_SCREEN_BUFFER ScreenBuffer);
BOOL (WINAPI *SetScreenInfo)(struct _CONSOLE* Console,
PCONSOLE_SCREEN_BUFFER ScreenBuffer,
UINT OldCursorX,
UINT OldCursorY);
BOOL (WINAPI *UpdateScreenInfo)(struct _CONSOLE* Console,
PCONSOLE_SCREEN_BUFFER ScreenBuffer);
NTSTATUS (WINAPI *ResizeBuffer)(struct _CONSOLE* Console,
PCONSOLE_SCREEN_BUFFER ScreenBuffer,
COORD Size);
BOOL (WINAPI *ProcessKeyCallback)(struct _CONSOLE* Console,
MSG* msg,
BYTE KeyStateMenu,
DWORD ShiftState,
UINT VirtualKeyCode,
BOOL Down);
/*
* External interface (functions corresponding to the Console API)
*/
VOID (WINAPI *ChangeTitle)(struct _CONSOLE* Console);
BOOL (WINAPI *ChangeIcon)(struct _CONSOLE* Console,
HICON hWindowIcon);
HWND (WINAPI *GetConsoleWindowHandle)(struct _CONSOLE* Console);
} TERMINAL_VTBL, *PTERMINAL_VTBL;
#define ConioDrawRegion(Console, Region) (Console)->TermIFace.Vtbl->DrawRegion((Console), (Region))
#define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
(Console)->TermIFace.Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
(ScrolledLines), (Buffer), (Length))
#define ConioSetCursorInfo(Console, Buff) (Console)->TermIFace.Vtbl->SetCursorInfo((Console), (Buff))
#define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
(Console)->TermIFace.Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
#define ConioUpdateScreenInfo(Console, Buff) \
(Console)->TermIFace.Vtbl->UpdateScreenInfo((Console), (Buff))
#define ConioChangeTitle(Console) (Console)->TermIFace.Vtbl->ChangeTitle(Console)
#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 ConioProcessKeyCallback(Console, Msg, KeyStateMenu, ShiftState, VirtualKeyCode, Down) \
(Console)->TermIFace.Vtbl->ProcessKeyCallback((Console), (Msg), (KeyStateMenu), (ShiftState), (VirtualKeyCode), (Down))
typedef struct _TERMINAL_IFACE
{
PTERMINAL_VTBL Vtbl; /* Virtual table */
PVOID Data; /* Private data */
PVOID OldData; /* Reserved */
} TERMINAL_IFACE, *PTERMINAL_IFACE;
typedef struct _CONSOLE
{
LONG ReferenceCount; /* Is incremented each time a handle to a screen-buffer or the input buffer of this console gets referenced, or the console gets locked */
CRITICAL_SECTION Lock;
struct _CONSOLE *Prev, *Next; /* Next and Prev consoles in console wheel */
struct _CONSOLE_VTBL *Vtbl; /* Using CUI or GUI consoles */
LIST_ENTRY ProcessList; /* List of processes owning the console. The first one is the so-called "Console Leader Process" */
CLIENT_ID ConsoleLeaderCID; /* Contains the Console Leader Process CID for this console. TODO: Is it possible to compute it via the contents of the ProcessList list ?? */
LIST_ENTRY ProcessList;
TERMINAL_IFACE TermIFace; /* Terminal-specific interface */
/**************************** Input buffer and data ***************************/
CONSOLE_INPUT_BUFFER InputBuffer; /* Input buffer of the console */
@ -129,19 +186,13 @@ typedef struct _CONSOLE
ULONG NumberOfHistoryBuffers; /* Maximum number of history buffers allowed */
BOOLEAN HistoryNoDup; /* Remove old duplicate history entries */
/******************************* Common UI data *******************************/
UNICODE_STRING OriginalTitle; /* Original title of console, the one when the console leader is launched. It is always NULL-terminated */
UNICODE_STRING Title; /* Title of console. It is always NULL-terminated */
/****************************** Other properties ******************************/
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 */
COLORREF Colors[16]; /* Colour palette */
/****************************** GUI-related data ******************************/
HWND hWindow; /* Handle to the console's window */
HICON hIcon; /* Handle to its icon (used when freeing) */
HICON hIconSm;
PVOID GuiData; /* PGUI_CONSOLE_DATA */
} CONSOLE, *PCONSOLE;
/**************************************************************\
@ -150,35 +201,26 @@ typedef struct _CONSOLE
#define GWLP_CONSOLE_LEADER_PID 0
#define GWLP_CONSOLE_LEADER_TID 4
#define SetConsoleWndConsoleLeaderCID(Console) \
do { \
SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_PID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueProcess)); \
SetWindowLongPtrW((Console)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)((Console)->ConsoleLeaderCID.UniqueThread )); \
#define SetConsoleWndConsoleLeaderCID(GuiData) \
do { \
PCONSOLE_PROCESS_DATA ProcessData; \
CLIENT_ID ConsoleLeaderCID; \
ProcessData = CONTAINING_RECORD((GuiData)->Console->ProcessList.Blink, \
CONSOLE_PROCESS_DATA, \
ConsoleLink); \
ConsoleLeaderCID = ProcessData->Process->ClientId; \
SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_PID, (LONG_PTR)(ConsoleLeaderCID.UniqueProcess)); \
SetWindowLongPtrW((GuiData)->hWindow, GWLP_CONSOLE_LEADER_TID, (LONG_PTR)(ConsoleLeaderCID.UniqueThread )); \
} while(0)
/**************************************************************/
typedef struct _CONSOLE_VTBL
{
VOID (WINAPI *WriteStream)(PCONSOLE Console, SMALL_RECT* Block, LONG CursorStartX, LONG CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length);
VOID (WINAPI *DrawRegion)(PCONSOLE Console, SMALL_RECT* Region);
BOOL (WINAPI *SetCursorInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
BOOL (WINAPI *SetScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer,
UINT OldCursorX, UINT OldCursorY);
BOOL (WINAPI *UpdateScreenInfo)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer);
VOID (WINAPI *ChangeTitle)(PCONSOLE Console);
VOID (WINAPI *CleanupConsole)(PCONSOLE Console);
BOOL (WINAPI *ChangeIcon)(PCONSOLE Console, HICON hWindowIcon);
NTSTATUS (WINAPI *ResizeBuffer)(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Size);
BOOL (WINAPI *ProcessKeyCallback)(PCONSOLE Console, MSG* msg, BYTE KeyStateMenu, DWORD ShiftState, UINT VirtualKeyCode, BOOL Down);
} CONSOLE_VTBL, *PCONSOLE_VTBL;
/* CONSOLE_SELECTION_INFO dwFlags values */
#define CONSOLE_NO_SELECTION 0x0
#define CONSOLE_SELECTION_IN_PROGRESS 0x1
#define CONSOLE_SELECTION_NOT_EMPTY 0x2
#define CONSOLE_MOUSE_SELECTION 0x4
#define CONSOLE_MOUSE_DOWN 0x8
/* HistoryFlags values */
#define HISTORY_NO_DUP_FLAG 0x1
@ -187,21 +229,6 @@ typedef struct _CONSOLE_VTBL
#define PAUSED_FROM_SCROLLBAR 0x2
#define PAUSED_FROM_SELECTION 0x4
#define ConioDrawRegion(Console, Region) (Console)->Vtbl->DrawRegion((Console), (Region))
#define ConioWriteStream(Console, Block, CurStartX, CurStartY, ScrolledLines, Buffer, Length) \
(Console)->Vtbl->WriteStream((Console), (Block), (CurStartX), (CurStartY), \
(ScrolledLines), (Buffer), (Length))
#define ConioSetCursorInfo(Console, Buff) (Console)->Vtbl->SetCursorInfo((Console), (Buff))
#define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY) \
(Console)->Vtbl->SetScreenInfo((Console), (Buff), (OldCursorX), (OldCursorY))
#define ConioUpdateScreenInfo(Console, Buff) \
(Console)->Vtbl->UpdateScreenInfo((Console), (Buff))
#define ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
#define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
#define ConioChangeIcon(Console, hWindowIcon) (Console)->Vtbl->ChangeIcon((Console), (hWindowIcon))
#define ConioResizeBuffer(Console, Buff, Size) (Console)->Vtbl->ResizeBuffer((Console), (Buff), (Size))
#define ConioProcessKeyCallback(Console, Msg, KeyStateMenu, ShiftState, VirtualKeyCode, Down) (Console)->Vtbl->ProcessKeyCallback((Console), (Msg), (KeyStateMenu), (ShiftState), (VirtualKeyCode), (Down))
/* console.c */
VOID WINAPI ConSrvDeleteConsole(PCONSOLE Console);
VOID WINAPI ConSrvInitConsoleSupport(VOID);

View file

@ -231,8 +231,9 @@ ConioWriteConsole(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER Buff,
/* --- 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);
// SendNotifyMessage(Console->hWindow, PM_CONSOLE_BEEP, 0, 0);
continue;
}
}

View file

@ -14,7 +14,10 @@
#include "consrv.h"
#include "settings.h"
#include "guiconsole.h"
#include "tuiconsole.h"
#ifdef TUI_CONSOLE
#include "tuiconsole.h"
#endif
#include <shlwapi.h>
#include <shlobj.h>
@ -324,7 +327,6 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
*/
InitializeCriticalSection(&Console->Lock);
Console->ReferenceCount = 0;
Console->ConsoleLeaderCID = ConsoleLeaderProcess->ClientId;
InitializeListHead(&Console->ProcessList);
memcpy(Console->Colors, ConsoleInfo.Colors, sizeof(ConsoleInfo.Colors));
Console->Size = ConsoleInfo.ConsoleSize;
@ -385,10 +387,6 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
Console->NumberOfHistoryBuffers = ConsoleInfo.NumberOfHistoryBuffers;
Console->HistoryNoDup = ConsoleInfo.HistoryNoDup;
/* Finish initialization */
Console->GuiData = NULL;
Console->hIcon = Console->hIconSm = NULL;
/* Initialize the console title */
RtlCreateUnicodeString(&Console->OriginalTitle, ConsoleStartInfo->ConsoleTitle);
if (ConsoleStartInfo->ConsoleTitle[0] == L'\0')
@ -408,35 +406,41 @@ ConSrvInitConsole(OUT PCONSOLE* NewConsole,
}
/*
* If we are not in GUI-mode, start the text-mode console.
* If we fail, try to start the GUI-mode console.
* If we are not in GUI-mode, start the text-mode terminal emulator.
* If we fail, try to start the GUI-mode terminal emulator.
*/
#ifdef TUI_CONSOLE
GuiMode = DtbgIsDesktopVisible();
#else
GuiMode = TRUE;
#endif
#ifdef TUI_CONSOLE
if (!GuiMode)
{
DPRINT1("CONSRV: Opening text-mode console\n");
DPRINT1("CONSRV: Opening text-mode terminal emulator\n");
Status = TuiInitConsole(Console, &ConsoleInfo);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to open text-mode console, switching to gui-mode, Status = 0x%08lx\n", Status);
DPRINT1("Failed to open text-mode terminal emulator, switching to gui-mode, Status = 0x%08lx\n", Status);
GuiMode = TRUE;
}
}
#endif
/*
* Try to open the GUI-mode console. Two cases are possible:
* Try to open the GUI-mode terminal emulator. Two cases are possible:
* - We are in GUI-mode, therefore GuiMode == TRUE, the previous test-case
* failed and we start GUI-mode console.
* failed and we start GUI-mode terminal emulator.
* - We are in text-mode, therefore GuiMode == FALSE, the previous test-case
* succeeded BUT we failed at starting text-mode console. Then GuiMode
* was switched to TRUE in order to try to open the console in GUI-mode
* (win32k will automatically switch to graphical mode, therefore
* no additional code is needed).
* 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,
* therefore no additional code is needed).
*/
if (GuiMode)
{
DPRINT1("CONSRV: Opening GUI-mode console\n");
DPRINT1("CONSRV: Opening GUI-mode terminal emulator\n");
Status = GuiInitConsole(Console,
AppPath,
&ConsoleInfo,
@ -1023,7 +1027,7 @@ CSR_API(SrvGetConsoleWindow)
Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
if (!NT_SUCCESS(Status)) return Status;
GetWindowRequest->WindowHandle = Console->hWindow;
GetWindowRequest->WindowHandle = Console->TermIFace.Vtbl->GetConsoleWindowHandle(Console);
ConSrvReleaseConsole(Console, TRUE);
return STATUS_SUCCESS;

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/guiconsole.h
* PURPOSE: Interface to GUI-mode consoles
* PURPOSE: GUI terminal emulator
* PROGRAMMERS:
*/

View file

@ -373,7 +373,7 @@ ConSrvGetObject(PCONSOLE_PROCESS_DATA ProcessData,
(HandleEntry->Access & Access) == 0 ||
(Type != 0 && ObjectEntry->Type != Type) )
{
DPRINT1("CsrGetObject returning invalid handle (%x) of type %lu with access %lu\n", Handle, Type, Access);
DPRINT1("ConSrvGetObject returning invalid handle (%x) of type %lu with access %lu\n", Handle, Type, Access);
RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
return STATUS_INVALID_HANDLE;
}
@ -511,7 +511,6 @@ FASTCALL
ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData)
{
PCONSOLE Console;
PCONSOLE_PROCESS_DATA NewProcessData;
DPRINT1("ConSrvRemoveConsole\n");
@ -532,11 +531,7 @@ ConSrvRemoveConsole(PCONSOLE_PROCESS_DATA ProcessData)
RemoveEntryList(&ProcessData->ConsoleLink);
/* Update the console leader process */
NewProcessData = CONTAINING_RECORD(Console->ProcessList.Blink,
CONSOLE_PROCESS_DATA,
ConsoleLink);
Console->ConsoleLeaderCID = NewProcessData->Process->ClientId;
SetConsoleWndConsoleLeaderCID(Console);
// SetConsoleWndConsoleLeaderCID(Console);
/* Release the console */
ConSrvReleaseConsole(Console, TRUE);
@ -799,7 +794,7 @@ CSR_API(SrvVerifyConsoleIoHandle)
Index >= ProcessData->HandleTableSize ||
ProcessData->HandleTable[Index].Object == NULL)
{
DPRINT("CsrVerifyObject failed\n");
DPRINT("SrvVerifyConsoleIoHandle failed\n");
Status = STATUS_INVALID_HANDLE;
}

View file

@ -8,6 +8,9 @@
* NOTE: Adapted from existing code.
*/
#ifndef WM_APP
#define WM_APP 0x8000
#endif
#define PM_APPLY_CONSOLE_INFO (WM_APP + 100)
/* STRUCTURES *****************************************************************/
@ -54,6 +57,7 @@ typedef struct _CONSOLE_INFO
WCHAR ConsoleTitle[MAX_PATH + 1];
// PVOID TerminalInfo; /* Terminal-specific parameters */
union
{
GUI_CONSOLE_INFO GuiInfo;

View file

@ -2,10 +2,12 @@
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/tuiconsole.c
* PURPOSE: Interface to text-mode consoles
* PURPOSE: TUI terminal emulator
* PROGRAMMERS:
*/
#ifdef TUI_CONSOLE
#include "consrv.h"
#include "settings.h"
#include "tuiconsole.h"
@ -15,9 +17,21 @@
#include <debug.h>
/* GLOBALS ********************************************************************/
/* TUI Console Window Class name */
#define TUI_CONSOLE_WINDOW_CLASS L"TuiConsoleWindowClass"
typedef struct _TUI_CONSOLE_DATA
{
CRITICAL_SECTION Lock;
// HANDLE hTuiInitEvent;
HWND hWindow;
PCONSOLE Console;
// TUI_CONSOLE_INFO TuiInfo;
} TUI_CONSOLE_DATA, *PTUI_CONSOLE_DATA;
CRITICAL_SECTION ActiveConsoleLock;
static COORD PhysicalConsoleSize;
@ -164,7 +178,7 @@ TuiSwapConsole(INT Next)
/* alt-tab, swap consoles */
/* move SwapConsole to next console, and print its title */
EnterCriticalSection(&ActiveConsoleLock);
if (! SwapConsole)
if (!SwapConsole)
{
SwapConsole = ActiveConsole;
}
@ -480,6 +494,12 @@ TuiChangeIcon(PCONSOLE Console, HICON hWindowIcon)
return TRUE;
}
static HWND WINAPI
TuiGetConsoleWindowHandle(PCONSOLE Console)
{
return Console->hWindow;
}
static NTSTATUS WINAPI
TuiResizeBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Size)
{
@ -507,7 +527,6 @@ TuiConsoleThread(PVOID Data)
return 1;
}
Console->hWindow = NewWindow;
SetConsoleWndConsoleLeaderCID(Console);
SetForegroundWindow(Console->hWindow);
@ -528,16 +547,17 @@ TuiConsoleThread(PVOID Data)
return 0;
}
static CONSOLE_VTBL TuiVtbl =
static TERMINAL_VTBL TuiVtbl =
{
TuiCleanupConsole,
TuiWriteStream,
TuiDrawRegion,
TuiSetCursorInfo,
TuiSetScreenInfo,
TuiUpdateScreenInfo,
TuiChangeTitle,
TuiCleanupConsole,
TuiChangeIcon,
TuiGetConsoleWindowHandle,
TuiResizeBuffer,
TuiProcessKeyCallback
};
@ -558,7 +578,7 @@ TuiInitConsole(PCONSOLE Console,
}
}
Console->Vtbl = &TuiVtbl;
Console->TermIFace.Vtbl = &TuiVtbl;
Console->hWindow = NULL;
Console->Size = PhysicalConsoleSize;
Console->ActiveBuffer->ScreenBufferSize = PhysicalConsoleSize;
@ -601,4 +621,6 @@ TuiGetFocusConsole(VOID)
return ActiveConsole;
}
#endif
/* EOF */

View file

@ -2,7 +2,7 @@
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Console Server DLL
* FILE: win32ss/user/consrv/tuiconsole.h
* PURPOSE: Interface to text-mode consoles
* PURPOSE: TUI terminal emulator
* PROGRAMMERS:
*/