Auto-detect whether to create a GUI or a TUI console

svn path=/trunk/; revision=7571
This commit is contained in:
Gé van Geldorp 2004-01-11 17:31:16 +00:00
parent 0307fd628b
commit e98f4ce2f0
17 changed files with 2977 additions and 2628 deletions

View file

@ -1,4 +1,4 @@
/* $Id: blue.c,v 1.41 2003/11/17 02:12:48 hyperion Exp $
/* $Id: blue.c,v 1.42 2004/01/11 17:31:14 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -302,290 +302,327 @@ NTSTATUS STDCALL
ScrIoControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
PIO_STACK_LOCATION stk = IoGetCurrentIrpStackLocation (Irp);
PDEVICE_EXTENSION DeviceExtension;
NTSTATUS Status;
DeviceExtension = DeviceObject->DeviceExtension;
switch (stk->Parameters.DeviceIoControl.IoControlCode)
PIO_STACK_LOCATION stk = IoGetCurrentIrpStackLocation (Irp);
PDEVICE_EXTENSION DeviceExtension;
NTSTATUS Status;
DeviceExtension = DeviceObject->DeviceExtension;
switch (stk->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO:
case IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO:
{
PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
int rows = DeviceExtension->Rows;
int columns = DeviceExtension->Columns;
unsigned int offset;
/* read cursor position from crtc */
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSLO);
offset = READ_PORT_UCHAR (CRTC_DATA);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSHI);
offset += (READ_PORT_UCHAR (CRTC_DATA) << 8);
__asm__("sti\n\t");
pcsbi->dwSize.X = columns;
pcsbi->dwSize.Y = rows;
pcsbi->dwCursorPosition.X = (SHORT)(offset % columns);
pcsbi->dwCursorPosition.Y = (SHORT)(offset / columns);
pcsbi->wAttributes = DeviceExtension->CharAttribute;
pcsbi->srWindow.Left = 0;
pcsbi->srWindow.Right = columns - 1;
pcsbi->srWindow.Top = 0;
pcsbi->srWindow.Bottom = rows - 1;
pcsbi->dwMaximumWindowSize.X = columns;
pcsbi->dwMaximumWindowSize.Y = rows;
Irp->IoStatus.Information = sizeof (CONSOLE_SCREEN_BUFFER_INFO);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO:
{
PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
unsigned int offset;
DeviceExtension->CharAttribute = pcsbi->wAttributes;
offset = (pcsbi->dwCursorPosition.Y * DeviceExtension->Columns) +
pcsbi->dwCursorPosition.X;
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSLO);
WRITE_PORT_UCHAR (CRTC_DATA, offset);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSHI);
WRITE_PORT_UCHAR (CRTC_DATA, offset>>8);
__asm__("sti\n\t");
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_GET_CURSOR_INFO:
{
PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
pcci->dwSize = DeviceExtension->CursorSize;
pcci->bVisible = DeviceExtension->CursorVisible;
Irp->IoStatus.Information = sizeof (CONSOLE_CURSOR_INFO);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_CURSOR_INFO:
{
PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
BYTE data, value;
DWORD size, height;
DeviceExtension->CursorSize = pcci->dwSize;
DeviceExtension->CursorVisible = pcci->bVisible;
height = DeviceExtension->ScanLines;
data = (pcci->bVisible) ? 0x00 : 0x20;
size = (pcci->dwSize * height) / 100;
if (size < 1)
{
PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
int rows = DeviceExtension->Rows;
int columns = DeviceExtension->Columns;
unsigned int offset;
/* read cursor position from crtc */
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSLO);
offset = READ_PORT_UCHAR (CRTC_DATA);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSHI);
offset += (READ_PORT_UCHAR (CRTC_DATA) << 8);
__asm__("sti\n\t");
pcsbi->dwSize.X = columns;
pcsbi->dwSize.Y = rows;
pcsbi->dwCursorPosition.X = (SHORT)(offset % columns);
pcsbi->dwCursorPosition.Y = (SHORT)(offset / columns);
pcsbi->wAttributes = DeviceExtension->CharAttribute;
pcsbi->srWindow.Left = 0;
pcsbi->srWindow.Right = columns - 1;
pcsbi->srWindow.Top = 0;
pcsbi->srWindow.Bottom = rows - 1;
pcsbi->dwMaximumWindowSize.X = columns;
pcsbi->dwMaximumWindowSize.Y = rows;
Irp->IoStatus.Information = sizeof (CONSOLE_SCREEN_BUFFER_INFO);
Status = STATUS_SUCCESS;
size = 1;
}
break;
case IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO:
data |= (BYTE)(height - size);
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORSTART);
WRITE_PORT_UCHAR (CRTC_DATA, data);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSOREND);
value = READ_PORT_UCHAR (CRTC_DATA) & 0xE0;
WRITE_PORT_UCHAR (CRTC_DATA, value | (height - 1));
__asm__("sti\n\t");
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_GET_MODE:
{
PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
pcm->dwMode = DeviceExtension->Mode;
Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_MODE:
{
PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
DeviceExtension->Mode = pcm->dwMode;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE:
{
POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < Buf->nLength; dwCount++)
{
PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
unsigned int offset;
DeviceExtension->CharAttribute = pcsbi->wAttributes;
offset = (pcsbi->dwCursorPosition.Y * DeviceExtension->Columns) +
pcsbi->dwCursorPosition.X;
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSLO);
WRITE_PORT_UCHAR (CRTC_DATA, offset);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSHI);
WRITE_PORT_UCHAR (CRTC_DATA, offset>>8);
__asm__("sti\n\t");
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
vidmem[offset + (dwCount * 2)] = (char) Buf->wAttribute;
}
break;
case IOCTL_CONSOLE_GET_CURSOR_INFO:
{
PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
pcci->dwSize = DeviceExtension->CursorSize;
pcci->bVisible = DeviceExtension->CursorVisible;
Irp->IoStatus.Information = sizeof (CONSOLE_CURSOR_INFO);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_CURSOR_INFO:
{
PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
BYTE data, value;
DWORD size, height;
DeviceExtension->CursorSize = pcci->dwSize;
DeviceExtension->CursorVisible = pcci->bVisible;
height = DeviceExtension->ScanLines;
data = (pcci->bVisible) ? 0x40 : 0x20;
size = (pcci->dwSize * height) / 100;
if (size < 1)
size = 1;
data |= (BYTE)(height - size);
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORSTART);
WRITE_PORT_UCHAR (CRTC_DATA, data);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSOREND);
value = READ_PORT_UCHAR (CRTC_DATA) & 0xE0;
WRITE_PORT_UCHAR (CRTC_DATA, value | (height - 1));
__asm__("sti\n\t");
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_GET_MODE:
{
PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
pcm->dwMode = DeviceExtension->Mode;
Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_MODE:
{
PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
DeviceExtension->Mode = pcm->dwMode;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE:
{
POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < Buf->nLength; dwCount++)
{
vidmem[offset + (dwCount * 2)] = (char) Buf->wAttribute;
}
Buf->dwTransfered = Buf->nLength;
Buf->dwTransfered = Buf->nLength;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE:
case IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE:
{
POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
PWORD pAttr = (PWORD)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < stk->Parameters.DeviceIoControl.OutputBufferLength; dwCount++, pAttr++)
{
POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
PWORD pAttr = (PWORD)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < stk->Parameters.DeviceIoControl.OutputBufferLength; dwCount++, pAttr++)
{
(char) *pAttr = vidmem[offset + (dwCount * 2)];
}
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
(char) *pAttr = vidmem[offset + (dwCount * 2)];
}
break;
case IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE:
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE:
{
COORD *pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
CHAR *pAttr = (CHAR *)(pCoord + 1);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (pCoord->Y * DeviceExtension->Columns * 2) +
(pCoord->X * 2) + 1;
for (dwCount = 0; dwCount < (stk->Parameters.DeviceIoControl.InputBufferLength - sizeof( COORD )); dwCount++, pAttr++)
{
COORD *pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
CHAR *pAttr = (CHAR *)(pCoord + 1);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (pCoord->Y * DeviceExtension->Columns * 2) +
(pCoord->X * 2) + 1;
for (dwCount = 0; dwCount < (stk->Parameters.DeviceIoControl.InputBufferLength - sizeof( COORD )); dwCount++, pAttr++)
{
vidmem[offset + (dwCount * 2)] = *pAttr;
}
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
vidmem[offset + (dwCount * 2)] = *pAttr;
}
break;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE:
DeviceExtension->CharAttribute = (WORD)*(PWORD)Irp->AssociatedIrp.SystemBuffer;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
break;
case IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE:
DeviceExtension->CharAttribute = (WORD)*(PWORD)Irp->AssociatedIrp.SystemBuffer;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
break;
case IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER:
{
POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
char *vidmem;
int offset;
DWORD dwCount;
case IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER:
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2);
CHECKPOINT
for (dwCount = 0; dwCount < Buf->nLength; dwCount++)
{
POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2);
CHECKPOINT
for (dwCount = 0; dwCount < Buf->nLength; dwCount++)
{
vidmem[offset + (dwCount * 2)] = (char) Buf->cCharacter;
}
Buf->dwTransfered = Buf->nLength;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
vidmem[offset + (dwCount * 2)] = (char) Buf->cCharacter;
}
break;
case IOCTL_CONSOLE_READ_OUTPUT_CHARACTER:
Buf->dwTransfered = Buf->nLength;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_READ_OUTPUT_CHARACTER:
{
POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
LPSTR pChar = (LPSTR)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2);
for (dwCount = 0; dwCount < stk->Parameters.DeviceIoControl.OutputBufferLength; dwCount++, pChar++)
{
POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
LPSTR pChar = (LPSTR)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
(Buf->dwCoord.X * 2);
for (dwCount = 0; dwCount < stk->Parameters.DeviceIoControl.OutputBufferLength; dwCount++, pChar++)
{
*pChar = vidmem[offset + (dwCount * 2)];
}
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
*pChar = vidmem[offset + (dwCount * 2)];
}
break;
case IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER:
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER:
{
COORD *pCoord;
LPSTR pChar;
char *vidmem;
int offset;
DWORD dwCount;
pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
pChar = (CHAR *)(pCoord + 1);
vidmem = DeviceExtension->VideoMemory;
offset = (pCoord->Y * DeviceExtension->Columns * 2) +
(pCoord->X * 2);
for (dwCount = 0; dwCount < (stk->Parameters.DeviceIoControl.InputBufferLength - sizeof( COORD )); dwCount++, pChar++)
{
COORD *pCoord;
LPSTR pChar;
char *vidmem;
int offset;
DWORD dwCount;
pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
pChar = (CHAR *)(pCoord + 1);
vidmem = DeviceExtension->VideoMemory;
offset = (pCoord->Y * DeviceExtension->Columns * 2) +
(pCoord->X * 2);
for (dwCount = 0; dwCount < (stk->Parameters.DeviceIoControl.InputBufferLength - sizeof( COORD )); dwCount++, pChar++)
{
vidmem[offset + (dwCount * 2)] = *pChar;
}
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
vidmem[offset + (dwCount * 2)] = *pChar;
}
break;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
default:
Status = STATUS_NOT_IMPLEMENTED;
case IOCTL_CONSOLE_DRAW:
{
PCONSOLE_DRAW ConsoleDraw;
char *Src, *Dest;
UINT SrcDelta, DestDelta, i, Offset;
ConsoleDraw = (PCONSOLE_DRAW) MmGetSystemAddressForMdl(Irp->MdlAddress);
Src = (char *) (ConsoleDraw + 1);
SrcDelta = ConsoleDraw->SizeX * 2;
Dest = DeviceExtension->VideoMemory +
(ConsoleDraw->Y * DeviceExtension->Columns + ConsoleDraw->X) * 2;
DestDelta = DeviceExtension->Columns * 2;
for (i = 0; i < ConsoleDraw->SizeY; i++)
{
RtlCopyMemory(Dest, Src, SrcDelta);
Src += SrcDelta;
Dest += DestDelta;
}
Offset = (ConsoleDraw->CursorY * DeviceExtension->Columns) +
ConsoleDraw->CursorX;
__asm__("cli\n\t");
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSLO);
WRITE_PORT_UCHAR (CRTC_DATA, Offset);
WRITE_PORT_UCHAR (CRTC_COMMAND, CRTC_CURSORPOSHI);
WRITE_PORT_UCHAR (CRTC_DATA, Offset >> 8);
__asm__("sti\n\t");
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
default:
Status = STATUS_NOT_IMPLEMENTED;
}
Irp->IoStatus.Status = Status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
Irp->IoStatus.Status = Status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return (Status);
return Status;
}

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.21 2003/11/13 14:20:53 ekohl Exp $
# $Id: makefile,v 1.22 2004/01/11 17:31:14 gvg Exp $
PATH_TO_TOP = ../../..
@ -15,3 +15,6 @@ TARGET_CFLAGS = -Wall -Werror
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk
DEP_OBJECTS := $(TARGET_OBJECTS)
include $(PATH_TO_TOP)/tools/depend.mk

View file

@ -21,43 +21,45 @@
#define IOCTL_CONSOLE_READ_OUTPUT_CHARACTER CTL_CODE(FILE_DEVICE_SCREEN, 0x821, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER CTL_CODE(FILE_DEVICE_SCREEN, 0x822, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONSOLE_DRAW CTL_CODE(FILE_DEVICE_SCREEN, 0x830, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONSOLE_DRAW CTL_CODE(FILE_DEVICE_SCREEN, 0x830, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
/* TYPEDEFS **************************************************************/
typedef struct _CONSOLE_MODE
typedef struct tagCONSOLE_MODE
{
DWORD dwMode;
DWORD dwMode;
} CONSOLE_MODE, *PCONSOLE_MODE;
typedef struct _OUTPUT_ATTRIBUTE
typedef struct tagOUTPUT_ATTRIBUTE
{
WORD wAttribute;
DWORD nLength;
COORD dwCoord;
DWORD dwTransfered;
WORD wAttribute;
DWORD nLength;
COORD dwCoord;
DWORD dwTransfered;
} OUTPUT_ATTRIBUTE, *POUTPUT_ATTRIBUTE;
typedef struct _OUTPUT_CHARACTER
typedef struct tagOUTPUT_CHARACTER
{
CHAR cCharacter;
DWORD nLength;
COORD dwCoord;
DWORD dwTransfered;
CHAR cCharacter;
DWORD nLength;
COORD dwCoord;
DWORD dwTransfered;
} OUTPUT_CHARACTER, *POUTPUT_CHARACTER;
typedef struct _CONSOLE_DRAW
typedef struct tagCONSOLE_DRAW
{
SHORT X; /* Origin */
SHORT Y;
SHORT SizeX; /* Size of the screen buffer */
SHORT SizeY;
UINT X; /* Origin */
UINT Y;
UINT SizeX; /* Size of the screen buffer (chars) */
UINT SizeY;
UINT CursorX; /* New cursor position (screen-relative) */
UINT CursorY;
/* Followed by screen buffer in char/attrib format */
} CONSOLE_DRAW, *PCONSOLE_DRAW;

View file

@ -1,4 +1,4 @@
/* $Id: handle.c,v 1.15 2003/12/02 11:38:47 gvg Exp $
/* $Id: handle.c,v 1.16 2004/01/11 17:31:15 gvg Exp $
*
* reactos/subsys/csrss/api/handle.c
*
@ -60,21 +60,21 @@ CsrRegisterObjectDefinitions(PCSRSS_OBJECT_DEFINITION NewDefinitions)
NTSTATUS STDCALL CsrGetObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Handle, Object_t **Object )
{
ULONG h = (((ULONG)Handle) >> 2) - 1;
DPRINT("CsrGetObject, Object: %x, %x, %x\n", Object, Handle, ProcessData ? ProcessData->HandleTableSize : 0);
ULONG h = (((ULONG)Handle) >> 2) - 1;
DPRINT("CsrGetObject, Object: %x, %x, %x\n", Object, Handle, ProcessData ? ProcessData->HandleTableSize : 0);
if (ProcessData == NULL)
{
if (ProcessData == NULL)
{
return STATUS_INVALID_PARAMETER;
}
if( h >= ProcessData->HandleTableSize )
{
DPRINT("CsrGetObject returning invalid handle\n");
return STATUS_INVALID_HANDLE;
}
*Object = ProcessData->HandleTable[h];
// DbgPrint( "CsrGetObject returning\n" );
return *Object ? STATUS_SUCCESS : STATUS_INVALID_HANDLE;
}
if (ProcessData->HandleTableSize <= h)
{
DPRINT1("CsrGetObject returning invalid handle\n");
return STATUS_INVALID_HANDLE;
}
*Object = ProcessData->HandleTable[h];
// DbgPrint( "CsrGetObject returning\n" );
return *Object ? STATUS_SUCCESS : STATUS_INVALID_HANDLE;
}

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.31 2003/12/18 09:51:08 gvg Exp $
/* $Id: process.c,v 1.32 2004/01/11 17:31:15 gvg Exp $
*
* reactos/subsys/csrss/api/process.c
*
@ -14,6 +14,7 @@
#include <csrss/csrss.h>
#include <ntdll/rtl.h>
#include "api.h"
#include "conio.h"
#define NDEBUG
#include <debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: api.h,v 1.3 2003/12/02 11:38:46 gvg Exp $
/* $Id: api.h,v 1.4 2004/01/11 17:31:15 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -15,8 +15,9 @@
typedef struct Object_tt
{
LONG Type;
LONG ReferenceCount;
LONG Type;
LONG ReferenceCount;
CRITICAL_SECTION Lock;
} Object_t;
typedef struct ConsoleInput_t
@ -28,63 +29,7 @@ typedef struct ConsoleInput_t
BOOLEAN NotChar; // message should not be used to return a character
} ConsoleInput;
typedef struct CSRSS_CONSOLE_t *PCSRSS_CONSOLE;
/************************************************************************
* Screen buffer structure represents the win32 screen buffer object. *
* Internally, the portion of the buffer being shown CAN loop past the *
* bottom of the virtual buffer and wrap around to the top. Win32 does *
* not do this. I decided to do this because it eliminates the need to *
* do a massive memcpy() to scroll the contents of the buffer up to *
* scroll the screen on output, instead I just shift down the position *
* to be displayed, and let it wrap around to the top again. *
* The VirtualX member keeps track of the top X coord that win32 *
* clients THINK is currently being displayed, because they think that *
* when the display reaches the bottom of the buffer and another line *
* being printed causes another line to scroll down, that the buffer IS *
* memcpy()'s up, and the bottom of the buffer is still displayed, but *
* internally, I just wrap back to the top of the buffer. *
***********************************************************************/
typedef struct CSRSS_SCREEN_BUFFER_t
{
Object_t Header; /* Object header */
BYTE *Buffer; /* pointer to screen buffer */
USHORT MaxX, MaxY; /* size of the entire scrollback buffer */
USHORT ShowX, ShowY; /* beginning offset for the actual display area */
ULONG CurrentX; /* Current X cursor position */
ULONG CurrentY; /* Current Y cursor position */
BYTE DefaultAttrib; /* default char attribute */
USHORT VirtualX; /* top row of buffer being displayed, reported to callers */
CONSOLE_CURSOR_INFO CursorInfo;
USHORT Mode;
PCSRSS_CONSOLE Console; /* Console this buffer is currently attached to */
CRITICAL_SECTION Lock;
} CSRSS_SCREEN_BUFFER, *PCSRSS_SCREEN_BUFFER;
typedef struct CSRSS_CONSOLE_t
{
Object_t Header; /* Object header */
struct CSRSS_CONSOLE_t *Prev, *Next; /* Next and Prev consoles in console wheel */
HANDLE ActiveEvent;
LIST_ENTRY InputEvents; /* List head for input event queue */
WORD WaitingChars;
WORD WaitingLines; /* number of chars and lines in input queue */
PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
WORD Mode; /* Console mode flags */
WORD EchoCount; /* count of chars to echo, in line buffered mode */
UNICODE_STRING Title; /* Title of console */
struct { /* active code pages */
UINT Input;
UINT Output;
} CodePageId;
BOOL EarlyReturn; /* wake client and return data, even if we are in line buffered mode, and we don't have a complete line */
DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
HWND hWindow;
COORD Size;
PVOID GuiConsoleData;
LIST_ENTRY ProcessList;
} CSRSS_CONSOLE;
typedef struct tagCSRSS_CONSOLE *PCSRSS_CONSOLE;
typedef struct _CSRSS_PROCESS_DATA
{
@ -157,11 +102,6 @@ VOID Console_Api( DWORD Ignored );
extern HANDLE CsrssApiHeap;
/* api/conio.c */
NTSTATUS STDCALL CsrInitConsole(PCSRSS_CONSOLE Console);
NTSTATUS STDCALL CsrInitConsoleScreenBuffer(PCSRSS_SCREEN_BUFFER Buffer,
PCSRSS_CONSOLE Console,
unsigned Width,
unsigned Height);
VOID STDCALL CsrInitConsoleSupport(VOID);
/* api/process.c */
@ -177,10 +117,7 @@ BOOL STDCALL CsrServerInitialization (ULONG ArgumentCount, PWSTR *ArgumentArray)
NTSTATUS STDCALL CsrReleaseObjectByPointer(Object_t *Object);
NTSTATUS STDCALL CsrReleaseObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object );
NTSTATUS STDCALL CsrVerifyObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object );
VOID STDCALL CsrDrawConsole(PCSRSS_CONSOLE Console);
NTSTATUS CsrpEchoUnicodeChar( PCSRSS_SCREEN_BUFFER Console,
WCHAR UnicodeChar );
NTSTATUS STDCALL CsrpWriteConsole( PCSRSS_SCREEN_BUFFER Buff, CHAR *Buffer, DWORD Length, BOOL Attrib );
CSR_API(CsrGetInputHandle);
CSR_API(CsrGetOutputHandle);
CSR_API(CsrCloseHandle);

View file

@ -1,4 +1,4 @@
/* $Id: conio.h,v 1.1 2003/12/02 11:38:46 gvg Exp $
/* $Id: conio.h,v 1.2 2004/01/11 17:31:15 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -10,15 +10,91 @@
#define CONIO_H_INCLUDED
#include "api.h"
#include "win32csr.h"
/* Object type magic numbers */
#define CONIO_CONSOLE_MAGIC 0x00000001
#define CONIO_SCREEN_BUFFER_MAGIC 0x00000002
/************************************************************************
* Screen buffer structure represents the win32 screen buffer object. *
* Internally, the portion of the buffer being shown CAN loop past the *
* bottom of the virtual buffer and wrap around to the top. Win32 does *
* not do this. I decided to do this because it eliminates the need to *
* do a massive memcpy() to scroll the contents of the buffer up to *
* scroll the screen on output, instead I just shift down the position *
* to be displayed, and let it wrap around to the top again. *
* The VirtualX member keeps track of the top X coord that win32 *
* clients THINK is currently being displayed, because they think that *
* when the display reaches the bottom of the buffer and another line *
* being printed causes another line to scroll down, that the buffer IS *
* memcpy()'s up, and the bottom of the buffer is still displayed, but *
* internally, I just wrap back to the top of the buffer. *
***********************************************************************/
typedef struct tagCSRSS_SCREEN_BUFFER
{
Object_t Header; /* Object header */
BYTE *Buffer; /* pointer to screen buffer */
USHORT MaxX, MaxY; /* size of the entire scrollback buffer */
USHORT ShowX, ShowY; /* beginning offset for the actual display area */
ULONG CurrentX; /* Current X cursor position */
ULONG CurrentY; /* Current Y cursor position */
BYTE DefaultAttrib; /* default char attribute */
USHORT VirtualX; /* top row of buffer being displayed, reported to callers */
CONSOLE_CURSOR_INFO CursorInfo;
USHORT Mode;
} CSRSS_SCREEN_BUFFER, *PCSRSS_SCREEN_BUFFER;
typedef struct tagCSRSS_CONSOLE_VTBL
{
VOID (STDCALL *InitScreenBuffer)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
VOID (STDCALL *WriteStream)(PCSRSS_CONSOLE Console, RECT *Block, UINT CursorStartX, UINT CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length);
VOID (STDCALL *DrawRegion)(PCSRSS_CONSOLE Console, RECT *Region);
BOOL (STDCALL *SetCursorInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer);
BOOL (STDCALL *SetScreenInfo)(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER ScreenBuffer,
UINT OldCursorX, UINT OldCursorY);
BOOL (STDCALL *ChangeTitle)(PCSRSS_CONSOLE Console);
VOID (STDCALL *CleanupConsole)(PCSRSS_CONSOLE Console);
} CSRSS_CONSOLE_VTBL, *PCSRSS_CONSOLE_VTBL;
typedef struct tagCSRSS_CONSOLE
{
Object_t Header; /* Object header */
PCSRSS_CONSOLE Prev, Next; /* Next and Prev consoles in console wheel */
HANDLE ActiveEvent;
LIST_ENTRY InputEvents; /* List head for input event queue */
WORD WaitingChars;
WORD WaitingLines; /* number of chars and lines in input queue */
PCSRSS_SCREEN_BUFFER ActiveBuffer; /* Pointer to currently active screen buffer */
WORD Mode; /* Console mode flags */
WORD EchoCount; /* count of chars to echo, in line buffered mode */
UNICODE_STRING Title; /* Title of console */
struct /* active code pages */
{
UINT Input;
UINT Output;
} CodePageId;
BOOL EarlyReturn; /* wake client and return data, even if we are in line buffered mode, and we don't have a complete line */
DWORD HardwareState; /* _GDI_MANAGED, _DIRECT */
HWND hWindow;
COORD Size;
PVOID PrivateData;
PCSRSS_CONSOLE_VTBL Vtbl;
LIST_ENTRY ProcessList;
} CSRSS_CONSOLE;
VOID STDCALL ConioDeleteConsole(Object_t *Object);
VOID STDCALL ConioDeleteScreenBuffer(Object_t *Buffer);
void STDCALL CsrProcessKey(MSG *msg, PCSRSS_CONSOLE Console);
void STDCALL ConioProcessKey(MSG *msg, PCSRSS_CONSOLE Console, BOOL TextMode);
void FASTCALL ConioPhysicalToLogical(PCSRSS_SCREEN_BUFFER Buff,
ULONG PhysicalX,
ULONG PhysicalY,
LONG *LogicalX,
LONG *LogicalY);
VOID FASTCALL ConioDrawConsole(PCSRSS_CONSOLE Console);
/* api/conio.c */
CSR_API(CsrWriteConsole);
@ -54,6 +130,31 @@ CSR_API(CsrWriteConsoleInput);
CSR_API(CsrHardwareStateProperty);
CSR_API(CsrGetConsoleWindow);
#define ConioInitScreenBuffer(Console, Buff) (Console)->Vtbl->InitScreenBuffer((Console), (Buff))
#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 ConioChangeTitle(Console) (Console)->Vtbl->ChangeTitle(Console)
#define ConioCleanupConsole(Console) (Console)->Vtbl->CleanupConsole(Console)
#define ConioRectHeight(Rect) \
(((Rect)->top) > ((Rect)->bottom) ? 0 : ((Rect)->bottom) - ((Rect)->top) + 1)
#define ConioRectWidth(Rect) \
(((Rect)->left) > ((Rect)->right) ? 0 : ((Rect)->right) - ((Rect)->left) + 1)
#define ConioLockConsole(ProcessData, Handle, Ptr) \
Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), CONIO_CONSOLE_MAGIC)
#define ConioUnlockConsole(Console) \
Win32CsrUnlockObject((Object_t *) Console)
#define ConioLockScreenBuffer(ProcessData, Handle, Ptr) \
Win32CsrLockObject((ProcessData), (Handle), (Object_t **)(Ptr), CONIO_SCREEN_BUFFER_MAGIC)
#define ConioUnlockScreenBuffer(Buff) \
Win32CsrUnlockObject((Object_t *) Buff)
#endif /* CONIO_H_INCLUDED */
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: desktopbg.h,v 1.1 2003/12/07 23:02:57 gvg Exp $
/* $Id: desktopbg.h,v 1.2 2004/01/11 17:31:15 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -16,6 +16,8 @@ CSR_API(CsrCreateDesktop);
CSR_API(CsrShowDesktop);
CSR_API(CsrHideDesktop);
BOOL FASTCALL DtbgIsDesktopVisible(VOID);
#endif /* DESKTOPBG_H_INCLUDED */
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: win32csr.h,v 1.1 2003/12/02 11:38:46 gvg Exp $
/* $Id: win32csr.h,v 1.2 2004/01/11 17:31:15 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -6,6 +6,10 @@
* PURPOSE: Interface to win32csr.dll
*/
#ifndef WIN32CSR_H_INCLUDED
#define WIN32CSR_H_INCLUDED
#include <windows.h>
extern HANDLE Win32CsrApiHeap;
@ -13,8 +17,20 @@ extern HANDLE Win32CsrApiHeap;
NTSTATUS FASTCALL Win32CsrInsertObject(PCSRSS_PROCESS_DATA ProcessData,
PHANDLE Handle,
Object_t *Object);
NTSTATUS FASTCALL Win32CsrLockObject(PCSRSS_PROCESS_DATA ProcessData,
HANDLE Handle,
Object_t **Object,
long Type);
VOID FASTCALL Win32CsrUnlockObject(Object_t *Object);
#ifndef TODO
NTSTATUS FASTCALL Win32CsrGetObject(PCSRSS_PROCESS_DATA ProcessData,
HANDLE Handle,
Object_t **Object);
NTSTATUS FASTCALL Win32CsrReleaseObject(PCSRSS_PROCESS_DATA ProcessData,
HANDLE Object);
#endif
#endif /* WIN32CSR_H_INCLUDED */
/* EOF */

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.2 2003/12/07 23:02:57 gvg Exp $
# $Id: Makefile,v 1.3 2004/01/11 17:31:15 gvg Exp $
PATH_TO_TOP = ../../..
@ -15,7 +15,7 @@ TARGET_LFLAGS = -nostartfiles -nostdlib
TARGET_SDKLIBS = ntdll.a kernel32.a user32.a gdi32.a
TARGET_OBJECTS = dllmain.o conio.o guiconsole.o desktopbg.o
TARGET_OBJECTS = dllmain.o conio.o desktopbg.o guiconsole.o tuiconsole.o
TARGET_ENTRY = _DllMain@12

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* $Id: desktopbg.c,v 1.4 2003/12/27 15:09:51 navaraf Exp $
/* $Id: desktopbg.c,v 1.5 2004/01/11 17:31:16 gvg Exp $
*
* reactos/subsys/csrss/win32csr/desktopbg.c
*
@ -32,6 +32,7 @@ typedef struct tagDTBG_THREAD_DATA
} DTBG_THREAD_DATA, *PDTBG_THREAD_DATA;
static BOOL Initialized = FALSE;
static HWND VisibleDesktopWindow = NULL;
static LRESULT CALLBACK
DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
@ -68,6 +69,7 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
(int)(short) HIWORD(lParam),
SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOREDRAW);
UpdateWindow(Wnd);
VisibleDesktopWindow = Wnd;
break;
case PM_HIDE_DESKTOP:
Result = ! SetWindowPos(Wnd,
@ -75,6 +77,7 @@ DtbgWindowProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE |
SWP_HIDEWINDOW);
UpdateWindow(Wnd);
VisibleDesktopWindow = NULL;
break;
default:
Result = 0;
@ -95,12 +98,12 @@ DtbgInit()
WindowStation = OpenWindowStationW(L"WinSta0", FALSE, GENERIC_ALL);
if (NULL == WindowStation)
{
DPRINT1("Win32Csr: failed to open window station\n");
DPRINT1("Failed to open window station\n");
return FALSE;
}
if (! SetProcessWindowStation(WindowStation))
{
DPRINT1("Win32Csr: failed to set process window station\n");
DPRINT1("Failed to set process window station\n");
return FALSE;
}
@ -121,10 +124,11 @@ DtbgInit()
ClassAtom = RegisterClassExW(&Class);
if ((ATOM) 0 == ClassAtom)
{
DPRINT1("Win32Csr: Unable to register desktop background class (error %d)\n",
DPRINT1("Unable to register desktop background class (error %d)\n",
GetLastError());
return FALSE;
}
VisibleDesktopWindow = NULL;
return TRUE;
}
@ -138,7 +142,7 @@ DtbgDesktopThread(PVOID Data)
if (! SetThreadDesktop(ThreadData->Desktop))
{
DPRINT1("Win32Csr: failed to set thread desktop\n");
DPRINT1("Failed to set thread desktop\n");
ThreadData->Status = STATUS_UNSUCCESSFUL;
SetEvent(ThreadData->Event);
return 1;
@ -156,7 +160,7 @@ DtbgDesktopThread(PVOID Data)
NULL);
if (NULL == BackgroundWnd)
{
DPRINT1("Win32Csr: failed to create desktop background window\n");
DPRINT1("Failed to create desktop background window\n");
ThreadData->Status = STATUS_UNSUCCESSFUL;
SetEvent(ThreadData->Event);
return 1;
@ -198,7 +202,7 @@ CSR_API(CsrCreateDesktop)
0, FALSE, GENERIC_ALL);
if (NULL == Desktop)
{
DPRINT1("Win32Csr: failed to open desktop %S\n",
DPRINT1("Failed to open desktop %S\n",
Request->Data.CreateDesktopRequest.DesktopName);
return Reply->Status = STATUS_UNSUCCESSFUL;
}
@ -207,7 +211,7 @@ CSR_API(CsrCreateDesktop)
ThreadData.Event = CreateEventW(NULL, FALSE, FALSE, NULL);
if (NULL == ThreadData.Event)
{
DPRINT1("Win32Csr: Failed to create event (error %d)\n", GetLastError());
DPRINT1("Failed to create event (error %d)\n", GetLastError());
return Reply->Status = STATUS_UNSUCCESSFUL;
}
ThreadHandle = CreateThread(NULL,
@ -219,7 +223,7 @@ CSR_API(CsrCreateDesktop)
if (NULL == ThreadHandle)
{
CloseHandle(ThreadData.Event);
DPRINT1("Win32Csr: Failed to create desktop window thread.\n");
DPRINT1("Failed to create desktop window thread.\n");
return Reply->Status = STATUS_UNSUCCESSFUL;
}
CloseHandle(ThreadHandle);
@ -263,4 +267,15 @@ CSR_API(CsrHideDesktop)
return Reply->Status;
}
BOOL FASTCALL
DtbgIsDesktopVisible(VOID)
{
if (NULL != VisibleDesktopWindow && ! IsWindowVisible(VisibleDesktopWindow))
{
VisibleDesktopWindow = NULL;
}
return NULL != VisibleDesktopWindow;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: dllmain.c,v 1.2 2003/12/07 23:02:57 gvg Exp $
/* $Id: dllmain.c,v 1.3 2004/01/11 17:31:16 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -82,9 +82,11 @@ DllMain(HANDLE hDll,
NTSTATUS FASTCALL
Win32CsrInsertObject(PCSRSS_PROCESS_DATA ProcessData,
PHANDLE Handle,
Object_t *Object)
PHANDLE Handle,
Object_t *Object)
{
InitializeCriticalSection(&(Object->Lock));
return (CsrExports.CsrInsertObjectProc)(ProcessData, Handle, Object);
}
@ -96,6 +98,36 @@ Win32CsrGetObject(PCSRSS_PROCESS_DATA ProcessData,
return (CsrExports.CsrGetObjectProc)(ProcessData, Handle, Object);
}
NTSTATUS FASTCALL
Win32CsrLockObject(PCSRSS_PROCESS_DATA ProcessData,
HANDLE Handle,
Object_t **Object,
LONG Type)
{
NTSTATUS Status;
Status = (CsrExports.CsrGetObjectProc)(ProcessData, Handle, Object);
if (! NT_SUCCESS(Status))
{
return Status;
}
if ((*Object)->Type != Type)
{
return STATUS_INVALID_HANDLE;
}
EnterCriticalSection(&((*Object)->Lock));
return STATUS_SUCCESS;
}
VOID FASTCALL
Win32CsrUnlockObject(Object_t *Object)
{
LeaveCriticalSection(&(Object->Lock));
}
NTSTATUS FASTCALL
Win32CsrReleaseObject(PCSRSS_PROCESS_DATA ProcessData,
HANDLE Object)

View file

@ -1,9 +1,9 @@
/* $Id: guiconsole.c,v 1.6 2003/12/31 20:16:39 gvg Exp $
/* $Id: guiconsole.c,v 1.7 2004/01/11 17:31:16 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: subsys/csrss/win32csr/dllmain.c
* PURPOSE: Initialization
* FILE: subsys/csrss/win32csr/guiconsole.c
* PURPOSE: Implementation of gui-mode consoles
*/
/* INCLUDES ******************************************************************/
@ -13,6 +13,9 @@
#include "guiconsole.h"
#include "win32csr.h"
#define NDEBUG
#include <debug.h>
/* Not defined in any header file */
extern VOID STDCALL PrivateCsrssManualGuiCheck(LONG Check);
@ -38,6 +41,7 @@ typedef struct GUI_CONSOLE_DATA_TAG
#define CURSOR_BLINK_TIME 500
static BOOL Initialized = FALSE;
static HWND NotifyWnd;
/* FUNCTIONS *****************************************************************/
@ -46,7 +50,7 @@ static VOID FASTCALL
GuiConsoleGetDataPointers(HWND hWnd, PCSRSS_CONSOLE *Console, PGUI_CONSOLE_DATA *GuiData)
{
*Console = (PCSRSS_CONSOLE) GetWindowLongW(hWnd, GWL_USERDATA);
*GuiData = (NULL == *Console ? NULL : (*Console)->GuiConsoleData);
*GuiData = (NULL == *Console ? NULL : (*Console)->PrivateData);
}
static BOOL FASTCALL
@ -64,7 +68,7 @@ GuiConsoleHandleNcCreate(HWND hWnd, CREATESTRUCTW *Create)
(Console->Size.X + 1) * sizeof(WCHAR));
if (NULL == GuiData)
{
DbgPrint("GuiConsoleNcCreate: HeapAlloc failed\n");
DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n");
return FALSE;
}
GuiData->LineBuffer = (PWCHAR)(GuiData + 1);
@ -76,28 +80,28 @@ GuiConsoleHandleNcCreate(HWND hWnd, CREATESTRUCTW *Create)
L"Bitstream Vera Sans Mono");
if (NULL == GuiData->Font)
{
DbgPrint("GuiConsoleNcCreate: CreateFont failed\n");
DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
HeapFree(Win32CsrApiHeap, 0, GuiData);
return FALSE;
}
Dc = GetDC(hWnd);
if (NULL == Dc)
{
DbgPrint("GuiConsoleNcCreate: GetDC failed\n");
DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
HeapFree(Win32CsrApiHeap, 0, GuiData);
return FALSE;
}
OldFont = SelectObject(Dc, GuiData->Font);
if (NULL == OldFont)
{
DbgPrint("GuiConsoleNcCreate: SelectObject failed\n");
DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
ReleaseDC(hWnd, Dc);
HeapFree(Win32CsrApiHeap, 0, GuiData);
return FALSE;
}
if (! GetTextMetricsW(Dc, &Metrics))
{
DbgPrint("GuiConsoleNcCreate: GetTextMetrics failed\n");
DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
SelectObject(Dc, OldFont);
ReleaseDC(hWnd, Dc);
HeapFree(Win32CsrApiHeap, 0, GuiData);
@ -110,7 +114,7 @@ GuiConsoleHandleNcCreate(HWND hWnd, CREATESTRUCTW *Create)
GuiData->CursorBlinkOn = TRUE;
GuiData->ForceCursorOff = FALSE;
Console->GuiConsoleData = GuiData;
Console->PrivateData = GuiData;
SetWindowLongW(hWnd, GWL_USERDATA, (LONG) Console);
GetWindowRect(hWnd, &Rect);
@ -178,13 +182,13 @@ GuiConsoleHandlePaint(HWND hWnd)
if (NULL != Console && NULL != GuiData && NULL != Console->ActiveBuffer)
{
Buff = Console->ActiveBuffer;
EnterCriticalSection(&(Buff->Lock));
EnterCriticalSection(&(Buff->Header.Lock));
Dc = BeginPaint(hWnd, &Ps);
if (Ps.rcPaint.right <= Ps.rcPaint.left || Ps.rcPaint.bottom <= Ps.rcPaint.top)
{
EndPaint(hWnd, &Ps);
LeaveCriticalSection(&(Buff->Lock));
LeaveCriticalSection(&(Buff->Header.Lock));
return;
}
OldFont = SelectObject(Dc, GuiData->Font);
@ -220,7 +224,8 @@ GuiConsoleHandlePaint(HWND hWnd)
Attribute = *(From + 1);
if (Attribute != LastAttribute)
{
GuiConsoleSetTextColors(Dc, LastAttribute);
GuiConsoleSetTextColors(Dc, Attribute);
LastAttribute = Attribute;
}
}
*((PBYTE) To) = *From;
@ -258,7 +263,7 @@ GuiConsoleHandlePaint(HWND hWnd)
}
EndPaint(hWnd, &Ps);
LeaveCriticalSection(&(Buff->Lock));
LeaveCriticalSection(&(Buff->Header.Lock));
}
else
{
@ -280,7 +285,7 @@ GuiConsoleHandleKey(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Message.wParam = wParam;
Message.lParam = lParam;
CsrProcessKey(&Message, Console);
ConioProcessKey(&Message, Console, FALSE);
}
static VOID FASTCALL
@ -377,23 +382,149 @@ GuiConsoleHandleCopyRegion(HWND hWnd, PRECT Source, PRECT Dest)
}
}
static VOID FASTCALL
GuiIntDrawRegion(PGUI_CONSOLE_DATA GuiData, HWND Wnd, RECT *Region)
{
RECT RegionRect;
RegionRect.left = Region->left * GuiData->CharWidth;
RegionRect.top = Region->top * GuiData->CharHeight;
RegionRect.right = (Region->right + 1) * GuiData->CharWidth;
RegionRect.bottom = (Region->bottom + 1) * GuiData->CharHeight;
InvalidateRect(Wnd, &RegionRect, FALSE);
}
static VOID STDCALL
GuiDrawRegion(PCSRSS_CONSOLE Console, RECT *Region)
{
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->PrivateData;
if (NULL == Console->hWindow || NULL == GuiData)
{
return;
}
GuiIntDrawRegion(GuiData, Console->hWindow, Region);
}
static VOID FASTCALL
GuiInvalidateCell(PGUI_CONSOLE_DATA GuiData, HWND Wnd, UINT x, UINT y)
{
RECT CellRect;
CellRect.left = x;
CellRect.top = y;
CellRect.right = x;
CellRect.bottom = y;
GuiIntDrawRegion(GuiData, Wnd, &CellRect);
}
static VOID STDCALL
GuiWriteStream(PCSRSS_CONSOLE Console, RECT *Region, UINT CursorStartX, UINT CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length)
{
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->PrivateData;
PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer;
LONG CursorEndX, CursorEndY;
RECT Source, Dest;
if (NULL == Console->hWindow || NULL == GuiData)
{
return;
}
if (0 != ScrolledLines)
{
Source.left = 0;
Source.top = ScrolledLines;
Source.right = Console->Size.X - 1;
Source.bottom = ScrolledLines + Region->top - 1;
Dest.left = 0;
Dest.top = 0;
Dest.right = Console->Size.X - 1;
Dest.bottom = Region->top - 1;
GuiConsoleCopyRegion(Console, &Source, &Dest);
}
GuiIntDrawRegion(GuiData, Console->hWindow, Region);
if (CursorStartX < Region->left || Region->right < CursorStartX
|| CursorStartY < Region->top || Region->bottom < CursorStartY)
{
GuiInvalidateCell(GuiData, Console->hWindow, CursorStartX, CursorStartY);
}
ConioPhysicalToLogical(Buff, Buff->CurrentX, Buff->CurrentY,
&CursorEndX, &CursorEndY);
if ((CursorEndX < Region->left || Region->right < CursorEndX
|| CursorEndY < Region->top || Region->bottom < CursorEndY)
&& (CursorEndX != CursorStartX || CursorEndY != CursorStartY))
{
GuiInvalidateCell(GuiData, Console->hWindow, CursorEndX, CursorEndY);
}
}
static BOOL STDCALL
GuiSetCursorInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff)
{
RECT UpdateRect;
if (Console->ActiveBuffer == Buff)
{
ConioPhysicalToLogical(Buff, Buff->CurrentX, Buff->CurrentY,
&UpdateRect.left, &UpdateRect.top);
UpdateRect.right = UpdateRect.left;
UpdateRect.bottom = UpdateRect.top;
ConioDrawRegion(Console, &UpdateRect);
}
return TRUE;
}
static BOOL STDCALL
GuiSetScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, UINT OldCursorX, UINT OldCursorY)
{
RECT UpdateRect;
if (Console->ActiveBuffer == Buff)
{
/* Redraw char at old position (removes cursor) */
UpdateRect.left = OldCursorX;
UpdateRect.top = OldCursorY;
UpdateRect.right = OldCursorX;
UpdateRect.bottom = OldCursorY;
ConioDrawRegion(Console, &UpdateRect);
/* Redraw char at new position (shows cursor) */
ConioPhysicalToLogical(Buff, Buff->CurrentX, Buff->CurrentY,
&(UpdateRect.left), &(UpdateRect.top));
UpdateRect.right = UpdateRect.left;
UpdateRect.bottom = UpdateRect.top;
ConioDrawRegion(Console, &UpdateRect);
}
return TRUE;
}
static VOID FASTCALL
GuiConsoleHandleTimer(HWND hWnd)
{
PCSRSS_CONSOLE Console;
PGUI_CONSOLE_DATA GuiData;
SMALL_RECT CursorRect;
RECT CursorRect;
ULONG CursorX, CursorY;
GuiConsoleGetDataPointers(hWnd, &Console, &GuiData);
GuiData->CursorBlinkOn = ! GuiData->CursorBlinkOn;
GuiConsoleGetLogicalCursorPos(Console->ActiveBuffer, &CursorX, &CursorY);
CursorRect.Left = CursorX;
CursorRect.Top = CursorY;
CursorRect.Right = CursorX;
CursorRect.Bottom = CursorY;
GuiConsoleDrawRegion(Console, CursorRect);
CursorRect.left = CursorX;
CursorRect.top = CursorY;
CursorRect.right = CursorX;
CursorRect.bottom = CursorY;
GuiDrawRegion(Console, &CursorRect);
}
static VOID FASTCALL
@ -410,7 +541,7 @@ GuiConsoleHandleNcDestroy(HWND hWnd)
GuiConsoleGetDataPointers(hWnd, &Console, &GuiData);
KillTimer(hWnd, 1);
Console->GuiConsoleData = NULL;
Console->PrivateData = NULL;
HeapFree(Win32CsrApiHeap, 0, GuiData);
}
@ -546,8 +677,8 @@ GuiConsoleGuiThread(PVOID Data)
return 1;
}
VOID FASTCALL
GuiConsoleInitConsoleSupport(VOID)
static BOOL FASTCALL
GuiInit(VOID)
{
HDESK Desktop;
NTSTATUS Status;
@ -556,8 +687,8 @@ GuiConsoleInitConsoleSupport(VOID)
Desktop = OpenDesktopW(L"Default", 0, FALSE, GENERIC_ALL);
if (NULL == Desktop)
{
DbgPrint("Win32Csr: failed to open desktop\n");
return;
DPRINT1("Failed to open desktop\n");
return FALSE;
}
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessDesktop,
@ -565,13 +696,13 @@ GuiConsoleInitConsoleSupport(VOID)
sizeof(Desktop));
if (!NT_SUCCESS(Status))
{
DbgPrint("Win32Csr: cannot set default desktop.\n");
return;
DPRINT1("Cannot set default desktop.\n");
return FALSE;
}
if (! SetThreadDesktop(Desktop))
{
DbgPrint("Win32Csr: failed to set thread desktop\n");
return;
DPRINT1("Failed to set thread desktop\n");
return FALSE;
}
wc.lpszClassName = L"Win32CsrCreateNotify";
@ -586,7 +717,8 @@ GuiConsoleInitConsoleSupport(VOID)
wc.cbWndExtra = 0;
if (RegisterClassW(&wc) == 0)
{
return;
DPRINT1("Failed to register notify wndproc\n");
return FALSE;
}
wc.lpszClassName = L"Win32CsrConsole";
@ -601,16 +733,61 @@ GuiConsoleInitConsoleSupport(VOID)
wc.cbWndExtra = 0;
if (RegisterClassW(&wc) == 0)
{
return;
DPRINT1("Failed to register console wndproc\n");
return FALSE;
}
return TRUE;
}
BOOL STDCALL
GuiConsoleInitConsole(PCSRSS_CONSOLE Console)
static VOID STDCALL
GuiInitScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer)
{
Buffer->DefaultAttrib = 0x0f;
}
STATIC BOOL STDCALL
GuiChangeTitle(PCSRSS_CONSOLE Console)
{
SendMessageW(Console->hWindow, WM_SETTEXT, 0, (LPARAM) Console->Title.Buffer);
return TRUE;
}
static VOID STDCALL
GuiCleanupConsole(PCSRSS_CONSOLE Console)
{
SendMessageW(NotifyWnd, PM_DESTROY_CONSOLE, 0, (LPARAM) Console);
}
static CSRSS_CONSOLE_VTBL GuiVtbl =
{
GuiInitScreenBuffer,
GuiWriteStream,
GuiDrawRegion,
GuiSetCursorInfo,
GuiSetScreenInfo,
GuiChangeTitle,
GuiCleanupConsole
};
NTSTATUS FASTCALL
GuiInitConsole(PCSRSS_CONSOLE Console)
{
HANDLE GraphicsStartupEvent;
HANDLE ThreadHandle;
if (! Initialized)
{
Initialized = TRUE;
if (! GuiInit())
{
Initialized = FALSE;
return STATUS_UNSUCCESSFUL;
}
}
Console->Vtbl = &GuiVtbl;
Console->Size.X = 80;
Console->Size.Y = 25;
if (NULL == NotifyWnd)
@ -618,7 +795,7 @@ GuiConsoleInitConsole(PCSRSS_CONSOLE Console)
GraphicsStartupEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
if (NULL == GraphicsStartupEvent)
{
return FALSE;
return STATUS_UNSUCCESSFUL;
}
ThreadHandle = CreateThread(NULL,
@ -630,8 +807,8 @@ GuiConsoleInitConsole(PCSRSS_CONSOLE Console)
if (NULL == ThreadHandle)
{
NtClose(GraphicsStartupEvent);
DbgPrint("Win32Csr: Failed to create graphics console thread. Expect problems\n");
return FALSE;
DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n");
return STATUS_UNSUCCESSFUL;
}
CloseHandle(ThreadHandle);
@ -640,33 +817,14 @@ GuiConsoleInitConsole(PCSRSS_CONSOLE Console)
if (NULL == NotifyWnd)
{
DbgPrint("Win32Csr: Failed to create notification window.\n");
return FALSE;
DPRINT1("Win32Csr: Failed to create notification window.\n");
return STATUS_UNSUCCESSFUL;
}
}
PostMessageW(NotifyWnd, PM_CREATE_CONSOLE, 0, (LPARAM) Console);
return TRUE;
}
VOID STDCALL
GuiConsoleDrawRegion(PCSRSS_CONSOLE Console, SMALL_RECT Region)
{
PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA) Console->GuiConsoleData;
RECT RegionRect;
if (NULL == Console->hWindow || NULL == GuiData)
{
return;
}
RegionRect.left = Region.Left * GuiData->CharWidth;
RegionRect.top = Region.Top * GuiData->CharHeight;
RegionRect.right = (Region.Right + 1) * GuiData->CharWidth;
RegionRect.bottom = (Region.Bottom + 1) * GuiData->CharHeight;
InvalidateRect(Console->hWindow, &RegionRect, FALSE);
return STATUS_SUCCESS;
}
VOID STDCALL
@ -674,21 +832,9 @@ GuiConsoleCopyRegion(PCSRSS_CONSOLE Console,
RECT *Source,
RECT *Dest)
{
LeaveCriticalSection(&(Console->ActiveBuffer->Lock));
LeaveCriticalSection(&(Console->ActiveBuffer->Header.Lock));
SendMessageW(Console->hWindow, PM_COPY_REGION, (WPARAM) Source, (LPARAM) Dest);
EnterCriticalSection(&(Console->ActiveBuffer->Lock));
}
VOID STDCALL
GuiConsoleChangeTitle(PCSRSS_CONSOLE Console)
{
SendMessageW(Console->hWindow, WM_SETTEXT, 0, (LPARAM) Console->Title.Buffer);
}
VOID STDCALL
GuiConsoleDeleteConsole(PCSRSS_CONSOLE Console)
{
SendMessageW(NotifyWnd, PM_DESTROY_CONSOLE, 0, (LPARAM) Console);
EnterCriticalSection(&(Console->ActiveBuffer->Header.Lock));
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: guiconsole.h,v 1.1 2003/12/02 11:38:46 gvg Exp $
/* $Id: guiconsole.h,v 1.2 2004/01/11 17:31:16 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -8,7 +8,7 @@
#include "api.h"
extern BOOL STDCALL GuiConsoleInitConsole(PCSRSS_CONSOLE Console);
extern NTSTATUS FASTCALL GuiInitConsole(PCSRSS_CONSOLE Console);
extern VOID STDCALL GuiConsoleDrawRegion(PCSRSS_CONSOLE Console, SMALL_RECT Region);
extern VOID STDCALL GuiConsoleCopyRegion(PCSRSS_CONSOLE Console,
RECT *Source,
@ -16,6 +16,4 @@ extern VOID STDCALL GuiConsoleCopyRegion(PCSRSS_CONSOLE Console,
extern VOID STDCALL GuiConsoleChangeTitle(PCSRSS_CONSOLE Console);
extern VOID STDCALL GuiConsoleDeleteConsole(PCSRSS_CONSOLE Console);
extern VOID FASTCALL GuiConsoleInitConsoleSupport(VOID);
/*EOF*/

View file

@ -0,0 +1,346 @@
/* $Id: tuiconsole.c,v 1.1 2004/01/11 17:31:16 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: subsys/csrss/win32csr/tuiconsole.c
* PURPOSE: Implementation of text-mode consoles
*/
#include <windows.h>
#include <ddk/ntddblue.h>
#include <string.h>
#include "api.h"
#include "conio.h"
#include "tuiconsole.h"
#include "win32csr.h"
#define NDEBUG
#include <debug.h>
CRITICAL_SECTION ActiveConsoleLock;
static COORD PhysicalConsoleSize;
static HANDLE ConsoleDeviceHandle;
static PCSRSS_CONSOLE ActiveConsole;
static BOOL Initialized = FALSE;
static BOOL FASTCALL
TuiInit(VOID)
{
CONSOLE_SCREEN_BUFFER_INFO ScrInfo;
DWORD BytesReturned;
ConsoleDeviceHandle = CreateFileW(L"\\\\.\\BlueScreen", FILE_ALL_ACCESS, 0, NULL,
OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == ConsoleDeviceHandle)
{
DPRINT1("Failed to open BlueScreen.\n");
return FALSE;
}
ActiveConsole = NULL;
InitializeCriticalSection(&ActiveConsoleLock);
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO,
NULL, 0, &ScrInfo, sizeof(ScrInfo), &BytesReturned, NULL))
{
DPRINT1("Failed to get console info\n");
return FALSE;
}
PhysicalConsoleSize = ScrInfo.dwSize;
return TRUE;
}
static VOID STDCALL
TuiInitScreenBuffer(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buffer)
{
Buffer->DefaultAttrib = 0x17;
}
static void FASTCALL
TuiCopyRect(char *Dest, PCSRSS_SCREEN_BUFFER Buff, RECT *Region)
{
UINT SrcDelta, DestDelta, i;
char *Src, *SrcEnd;
Src = Buff->Buffer + (((Region->top + Buff->ShowY) % Buff->MaxY) * Buff->MaxX
+ Region->left + Buff->ShowX) * 2;
SrcDelta = Buff->MaxX * 2;
SrcEnd = Buff->Buffer + Buff->MaxY * Buff->MaxX * 2;
DestDelta = ConioRectWidth(Region) * 2;
for (i = Region->top; i <= Region->bottom; i++)
{
memcpy(Dest, Src, DestDelta);
Src += SrcDelta;
if (SrcEnd <= Src)
{
Src -= Buff->MaxY * Buff->MaxX * 2;
}
Dest += DestDelta;
}
}
static VOID STDCALL
TuiDrawRegion(PCSRSS_CONSOLE Console, RECT *Region)
{
DWORD BytesReturned;
PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer;
LONG CursorX, CursorY;
PCONSOLE_DRAW ConsoleDraw;
UINT ConsoleDrawSize;
if (ActiveConsole != Console)
{
return;
}
ConsoleDrawSize = sizeof(CONSOLE_DRAW) +
(ConioRectWidth(Region) * ConioRectHeight(Region)) * 2;
ConsoleDraw = HeapAlloc(Win32CsrApiHeap, 0, ConsoleDrawSize);
if (NULL == ConsoleDraw)
{
DPRINT1("HeapAlloc failed\n");
return;
}
ConioPhysicalToLogical(Buff, Buff->CurrentX, Buff->CurrentY, &CursorX, &CursorY);
ConsoleDraw->X = Region->left;
ConsoleDraw->Y = Region->top;
ConsoleDraw->SizeX = ConioRectWidth(Region);
ConsoleDraw->SizeY = ConioRectHeight(Region);
ConsoleDraw->CursorX = CursorX;
ConsoleDraw->CursorY = CursorY;
TuiCopyRect((char *) (ConsoleDraw + 1), Buff, Region);
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_DRAW,
ConsoleDraw, ConsoleDrawSize, NULL, 0, &BytesReturned, NULL))
{
DPRINT1("Failed to draw console\n");
HeapFree(Win32CsrApiHeap, 0, ConsoleDraw);
return;
}
HeapFree(Win32CsrApiHeap, 0, ConsoleDraw);
}
static VOID STDCALL
TuiWriteStream(PCSRSS_CONSOLE Console, RECT *Region, UINT CursorStartX, UINT CursorStartY,
UINT ScrolledLines, CHAR *Buffer, UINT Length)
{
DWORD BytesWritten;
PCSRSS_SCREEN_BUFFER Buff = Console->ActiveBuffer;
if (ActiveConsole->ActiveBuffer != Buff)
{
return;
}
if (! WriteFile(ConsoleDeviceHandle, Buffer, Length, &BytesWritten, NULL))
{
DPRINT1("Error writing to BlueScreen\n");
}
}
static BOOL STDCALL
TuiSetCursorInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff)
{
DWORD BytesReturned;
if (ActiveConsole->ActiveBuffer != Buff)
{
return TRUE;
}
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_CURSOR_INFO,
&Buff->CursorInfo, sizeof(Buff->CursorInfo), NULL, 0,
&BytesReturned, NULL))
{
DPRINT1( "Failed to set cursor info\n" );
return FALSE;
}
return TRUE;
}
static BOOL STDCALL
TuiSetScreenInfo(PCSRSS_CONSOLE Console, PCSRSS_SCREEN_BUFFER Buff, UINT OldCursorX, UINT OldCursorY)
{
CONSOLE_SCREEN_BUFFER_INFO Info;
LONG CursorX, CursorY;
DWORD BytesReturned;
if (ActiveConsole->ActiveBuffer != Buff)
{
return TRUE;
}
ConioPhysicalToLogical(Buff, Buff->CurrentX, Buff->CurrentY, &CursorX, &CursorY);
Info.dwCursorPosition.X = CursorX;
Info.dwCursorPosition.Y = CursorY;
Info.wAttributes = Buff->DefaultAttrib;
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO,
&Info, sizeof(CONSOLE_SCREEN_BUFFER_INFO), NULL, 0,
&BytesReturned, NULL))
{
DPRINT1( "Failed to set cursor position\n" );
return FALSE;
}
return TRUE;
}
STATIC BOOL STDCALL
TuiChangeTitle(PCSRSS_CONSOLE Console)
{
return TRUE;
}
STATIC VOID STDCALL
TuiCleanupConsole(PCSRSS_CONSOLE Console)
{
EnterCriticalSection(&ActiveConsoleLock);
/* Switch to next console */
if (ActiveConsole == Console)
{
ActiveConsole = Console->Next != Console ? Console->Next : NULL;
}
if (Console->Next != Console)
{
Console->Prev->Next = Console->Next;
Console->Next->Prev = Console->Prev;
}
LeaveCriticalSection(&ActiveConsoleLock);
if (NULL != ActiveConsole)
{
ConioDrawConsole(ActiveConsole);
}
}
static CSRSS_CONSOLE_VTBL TuiVtbl =
{
TuiInitScreenBuffer,
TuiWriteStream,
TuiDrawRegion,
TuiSetCursorInfo,
TuiSetScreenInfo,
TuiChangeTitle,
TuiCleanupConsole
};
NTSTATUS FASTCALL
TuiInitConsole(PCSRSS_CONSOLE Console)
{
if (! Initialized)
{
Initialized = TRUE;
if (! TuiInit())
{
Initialized = FALSE;
return STATUS_UNSUCCESSFUL;
}
}
Console->Vtbl = &TuiVtbl;
Console->hWindow = (HWND) NULL;
Console->Size = PhysicalConsoleSize;
EnterCriticalSection(&ActiveConsoleLock);
if (NULL != ActiveConsole)
{
Console->Prev = ActiveConsole;
Console->Next = ActiveConsole->Next;
ActiveConsole->Next->Prev = Console;
ActiveConsole->Next = Console;
}
else
{
Console->Prev = Console;
Console->Next = Console;
}
ActiveConsole = Console;
LeaveCriticalSection(&ActiveConsoleLock);
return STATUS_SUCCESS;
}
PCSRSS_CONSOLE FASTCALL
TuiGetFocusConsole(VOID)
{
return ActiveConsole;
}
BOOL FASTCALL
TuiSwapConsole(int Next)
{
static PCSRSS_CONSOLE SwapConsole = NULL; /* console we are thinking about swapping with */
DWORD BytesReturned;
ANSI_STRING Title;
void * Buffer;
COORD *pos;
if (0 != Next)
{
/* alt-tab, swap consoles */
/* move SwapConsole to next console, and print its title */
EnterCriticalSection(&ActiveConsoleLock);
if (! SwapConsole)
{
SwapConsole = ActiveConsole;
}
SwapConsole = (0 < Next ? SwapConsole->Next : SwapConsole->Prev);
Title.MaximumLength = RtlUnicodeStringToAnsiSize(&SwapConsole->Title);
Title.Length = 0;
Buffer = HeapAlloc(Win32CsrApiHeap,
0,
sizeof(COORD) + Title.MaximumLength);
pos = (COORD *)Buffer;
Title.Buffer = Buffer + sizeof( COORD );
RtlUnicodeStringToAnsiString(&Title, &SwapConsole->Title, FALSE);
pos->Y = PhysicalConsoleSize.Y / 2;
pos->X = (PhysicalConsoleSize.X - Title.Length) / 2;
/* redraw the console to clear off old title */
ConioDrawConsole(ActiveConsole);
if (! DeviceIoControl(ConsoleDeviceHandle, IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER,
Buffer, sizeof(COORD) + Title.Length, NULL, 0,
&BytesReturned, NULL))
{
DPRINT1( "Error writing to console\n" );
}
HeapFree(Win32CsrApiHeap, 0, Buffer);
LeaveCriticalSection(&ActiveConsoleLock);
return TRUE;
}
else if (NULL != SwapConsole)
{
EnterCriticalSection(&ActiveConsoleLock);
if (SwapConsole != ActiveConsole)
{
/* first remove swapconsole from the list */
SwapConsole->Prev->Next = SwapConsole->Next;
SwapConsole->Next->Prev = SwapConsole->Prev;
/* now insert before activeconsole */
SwapConsole->Next = ActiveConsole;
SwapConsole->Prev = ActiveConsole->Prev;
ActiveConsole->Prev->Next = SwapConsole;
ActiveConsole->Prev = SwapConsole;
}
ActiveConsole = SwapConsole;
SwapConsole = NULL;
ConioDrawConsole(ActiveConsole);
LeaveCriticalSection(&ActiveConsoleLock);
return TRUE;
}
else
{
return FALSE;
}
}
/* EOF */

View file

@ -0,0 +1,15 @@
/* $Id: tuiconsole.h,v 1.1 2004/01/11 17:31:16 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: subsys/csrss/win32csr/tuiconsole.h
* PURPOSE: Interface to text-mode consoles
*/
#include "api.h"
extern NTSTATUS FASTCALL TuiInitConsole(PCSRSS_CONSOLE Console);
extern PCSRSS_CONSOLE FASTCALL TuiGetFocusConsole(VOID);
extern BOOL FASTCALL TuiSwapConsole(int Next);
/* EOF */