ReactOS  0.4.14-dev-55-g2da92ac
conoutput.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Console Driver DLL
4  * FILE: win32ss/user/winsrv/consrv_new/condrv/conoutput.c
5  * PURPOSE: General Console Output Functions
6  * PROGRAMMERS: Jeffrey Morlan
7  * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8  */
9 
10 /* INCLUDES *******************************************************************/
11 
12 #include "consrv.h"
13 #include "console.h"
14 #include "include/conio.h"
15 #include "include/conio2.h"
16 #include "conoutput.h"
17 #include "handle.h"
18 
19 #define NDEBUG
20 #include <debug.h>
21 
22 
23 /* PRIVATE FUNCTIONS **********************************************************/
24 
28  IN PTEXTMODE_BUFFER_INFO TextModeInfo);
32  IN PGRAPHICS_BUFFER_INFO GraphicsInfo);
33 
34 VOID
36 VOID
38 
39 
43  IN SIZE_T Size)
44 {
45  if (Buffer == NULL || Console == NULL)
47 
50 
51  /* Initialize the header with the default type */
52  ConSrvInitObject(&(*Buffer)->Header, SCREEN_BUFFER, Console);
53  (*Buffer)->Vtbl = NULL;
54  return STATUS_SUCCESS;
55 }
56 
57 VOID
59 {
60  if (Buffer->Header.Type == TEXTMODE_BUFFER)
62  else if (Buffer->Header.Type == GRAPHICS_BUFFER)
64  else if (Buffer->Header.Type == SCREEN_BUFFER)
66  // else
67  // do_nothing;
68 }
69 
70 // ConDrvCreateConsoleScreenBuffer
74  IN ULONG BufferType,
76 {
78 
79  if ( Console == NULL || Buffer == NULL ||
80  (BufferType != CONSOLE_TEXTMODE_BUFFER && BufferType != CONSOLE_GRAPHICS_BUFFER) )
81  {
83  }
84 
85  if (BufferType == CONSOLE_TEXTMODE_BUFFER)
86  {
88  Console,
90  }
91  else if (BufferType == CONSOLE_GRAPHICS_BUFFER)
92  {
94  Console,
96  }
97  else
98  {
99  /* Never ever go there!! */
100  ASSERT(FALSE);
101  }
102 
103  /* Insert the newly created screen buffer into the list, if succeeded */
104  if (NT_SUCCESS(Status)) InsertHeadList(&Console->BufferList, &(*Buffer)->ListEntry);
105 
106  return Status;
107 }
108 
109 static VOID
111 
112 VOID WINAPI
114 {
115  PCONSOLE Console = Buffer->Header.Console;
116  PCONSOLE_SCREEN_BUFFER NewBuffer;
117 
118  RemoveEntryList(&Buffer->ListEntry);
119  if (Buffer == Console->ActiveBuffer)
120  {
121  /* Delete active buffer; switch to most recently created */
122  Console->ActiveBuffer = NULL;
123  if (!IsListEmpty(&Console->BufferList))
124  {
125  NewBuffer = CONTAINING_RECORD(Console->BufferList.Flink,
127  ListEntry);
128  ConioSetActiveScreenBuffer(NewBuffer);
129  }
130  }
131 
133 }
134 
137 {
139  PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer;
140 
141  if (ActiveBuffer)
142  {
143  ConioInitRect(&Region, 0, 0, ActiveBuffer->ViewSize.Y - 1, ActiveBuffer->ViewSize.X - 1);
145  }
146 }
147 
148 static VOID
150 {
151  PCONSOLE Console = Buffer->Header.Console;
152  Console->ActiveBuffer = Buffer;
154  // ConioDrawConsole(Console);
155 }
156 
160 {
161  if (Console == NULL || Buffer == NULL)
163 
164  /* Validity check */
165  ASSERT(Console == Buffer->Header.Console);
166 
167  if (Buffer == Console->ActiveBuffer) return STATUS_SUCCESS;
168 
169  /* If old buffer has no handles, it's now unreferenced */
170  if (Console->ActiveBuffer->Header.HandleCount == 0)
171  {
172  ConioDeleteScreenBuffer(Console->ActiveBuffer);
173  }
174 
175  /* Tie console to new buffer */
177 
178  return STATUS_SUCCESS;
179 }
180 
183 {
184  return (Console ? Console->ActiveBuffer : NULL);
185 }
186 
187 /* PUBLIC DRIVER APIS *********************************************************/
188 
193 {
194  if (Console == NULL || Buffer == NULL || Region == NULL)
196 
197  /* Validity check */
198  ASSERT(Console == Buffer->Header.Console);
199 
200  /* If the output buffer is the current one, redraw the correct portion of the screen */
201  if (Buffer == Console->ActiveBuffer) ConioDrawRegion(Console, Region);
202 
203  return STATUS_SUCCESS;
204 }
205 
209  OUT PCONSOLE_CURSOR_INFO CursorInfo)
210 {
211  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
213 
214  /* Validity check */
215  ASSERT(Console == Buffer->Header.Console);
216 
217  *CursorInfo = Buffer->CursorInfo;
218  // CursorInfo->bVisible = Buffer->CursorInfo.bVisible;
219  // CursorInfo->dwSize = Buffer->CursorInfo.dwSize;
220 
221  return STATUS_SUCCESS;
222 }
223 
227  IN PCONSOLE_CURSOR_INFO CursorInfo)
228 {
229  ULONG Size;
230  BOOLEAN Visible, Success = TRUE;
231 
232  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
234 
235  /* Validity check */
236  ASSERT(Console == Buffer->Header.Console);
237 
238  Size = min(max(CursorInfo->dwSize, 1), 100);
239  Visible = CursorInfo->bVisible;
240 
241  if ( (Size != Buffer->CursorInfo.dwSize) ||
242  (Visible && !Buffer->CursorInfo.bVisible) ||
243  (!Visible && Buffer->CursorInfo.bVisible) )
244  {
245  Buffer->CursorInfo.dwSize = Size;
246  Buffer->CursorInfo.bVisible = Visible;
247 
249  }
250 
252 }
253 
258 {
259  SHORT OldCursorX, OldCursorY;
260 
261  if (Console == NULL || Buffer == NULL || Position == NULL)
263 
264  /* Validity check */
265  ASSERT(Console == Buffer->Header.Console);
266 
267  if ( Position->X < 0 || Position->X >= Buffer->ScreenBufferSize.X ||
268  Position->Y < 0 || Position->Y >= Buffer->ScreenBufferSize.Y )
269  {
271  }
272 
273  OldCursorX = Buffer->CursorPosition.X;
274  OldCursorY = Buffer->CursorPosition.Y;
275  Buffer->CursorPosition = *Position;
276  // Buffer->CursorPosition.X = Position->X;
277  // Buffer->CursorPosition.Y = Position->Y;
278  if ( ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer) &&
279  (!ConioSetScreenInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer, OldCursorX, OldCursorY)) )
280  {
281  return STATUS_UNSUCCESSFUL;
282  }
283 
284  return STATUS_SUCCESS;
285 }
286 
287 /* EOF */
#define IN
Definition: typedefs.h:38
NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:170
#define max(a, b)
Definition: svc.c:63
#define ConioDrawRegion(Console, Region)
Definition: conio2.h:13
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID FASTCALL ConioDrawConsole(PCONSOLE Console)
Definition: conoutput.c:136
PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer(IN PCONSOLE Console)
Definition: conoutput.c:194
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
static COORD Position
Definition: mouse.c:34
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
NTSTATUS TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
Definition: text.c:62
NTSTATUS ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
Definition: conoutput.c:79
#define TEXTMODE_BUFFER
Definition: pccons.c:21
NTSTATUS NTAPI ConDrvGetConsoleCursorInfo(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PCONSOLE_CURSOR_INFO CursorInfo)
Definition: conoutput.c:263
#define FASTCALL
Definition: nt_native.h:50
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER_VTBL Vtbl, IN SIZE_T Size)
Definition: conoutput.c:37
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:123
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
short SHORT
Definition: pedump.c:59
#define ConioSetCursorInfo(Console, Buff)
Definition: conio2.h:18
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
ULONG X
Definition: bl.h:1340
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:149
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WINAPI
Definition: msvc.h:8
NTSTATUS GRAPHICS_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
Definition: graphics.c:44
NTSTATUS NTAPI ConDrvSetConsoleCursorPosition(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCOORD Position)
Definition: conoutput.c:311
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS NTAPI ConDrvSetConsoleCursorInfo(IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSOLE_CURSOR_INFO CursorInfo)
Definition: conoutput.c:281
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:294
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Definition: bl.h:1338
#define ConioInitRect(Rect, top, left, bottom, right)
Definition: rect.h:20
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
VOID WINAPI ConioDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:113
#define ConioSetScreenInfo(Console, Buff, OldCursorX, OldCursorY)
Definition: conio2.h:20
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:60
#define min(a, b)
Definition: monoChain.cc:55
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
NTSTATUS NTAPI ConDrvInvalidateBitMapRect(IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN PSMALL_RECT Region)
Definition: conoutput.c:202
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:249
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
ULONG Y
Definition: bl.h:1341
#define ConioResizeTerminal(Console)
Definition: conio2.h:22