ReactOS  0.4.14-dev-1115-gebeeb9d
frontendctl.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Console Server DLL
4  * FILE: win32ss/user/winsrv/consrv/frontendctl.c
5  * PURPOSE: Terminal Front-Ends Control
6  * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "consrv.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* PUBLIC SERVER APIS *********************************************************/
17 
18 /**********************************************************************
19  * HardwareStateProperty
20  *
21  * DESCRIPTION
22  * Set/Get the value of the HardwareState and switch
23  * between direct video buffer ouput and GDI windowed
24  * output.
25  * ARGUMENTS
26  * Client hands us a CONSOLE_GETSETHWSTATE object.
27  * We use the same object to Request.
28  * NOTE
29  * ConsoleHwState has the correct size to be compatible
30  * with NT's, but values are not.
31  */
32 #if 0
33 static NTSTATUS
35 {
36  DPRINT1("Console Hardware State: %d\n", ConsoleHwState);
37 
38  if ((CONSOLE_HARDWARE_STATE_GDI_MANAGED == ConsoleHwState)
39  ||(CONSOLE_HARDWARE_STATE_DIRECT == ConsoleHwState))
40  {
41  if (Console->HardwareState != ConsoleHwState)
42  {
43  /* TODO: implement switching from full screen to windowed mode */
44  /* TODO: or back; now simply store the hardware state */
45  Console->HardwareState = ConsoleHwState;
46  }
47 
48  return STATUS_SUCCESS;
49  }
50 
51  return STATUS_INVALID_PARAMETER_3; /* Client: (handle, set_get, [mode]) */
52 }
53 #endif
54 
55 /* API_NUMBER: ConsolepGetHardwareState */
56 CSR_API(SrvGetConsoleHardwareState)
57 {
58 #if 0
60  PCONSOLE_GETSETHWSTATE HardwareStateRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HardwareStateRequest;
63 
65  HardwareStateRequest->OutputHandle,
66  &Buff,
68  TRUE);
69  if (!NT_SUCCESS(Status))
70  {
71  DPRINT1("Failed to get console handle in SrvGetConsoleHardwareState\n");
72  return Status;
73  }
74 
75  Console = Buff->Header.Console;
76  HardwareStateRequest->State = Console->HardwareState;
77 
79  return Status;
80 #else
83 #endif
84 }
85 
86 /* API_NUMBER: ConsolepSetHardwareState */
87 CSR_API(SrvSetConsoleHardwareState)
88 {
89 #if 0
91  PCONSOLE_GETSETHWSTATE HardwareStateRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HardwareStateRequest;
94 
96  HardwareStateRequest->OutputHandle,
97  &Buff,
99  TRUE);
100  if (!NT_SUCCESS(Status))
101  {
102  DPRINT1("Failed to get console handle in SrvSetConsoleHardwareState\n");
103  return Status;
104  }
105 
106  DPRINT("Setting console hardware state.\n");
107  Console = Buff->Header.Console;
108  Status = SetConsoleHardwareState(Console, HardwareStateRequest->State);
109 
111  return Status;
112 #else
114  return STATUS_NOT_IMPLEMENTED;
115 #endif
116 }
117 
118 /* API_NUMBER: ConsolepGetDisplayMode */
119 CSR_API(SrvGetConsoleDisplayMode)
120 {
122  PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetDisplayModeRequest;
124 
126  &Console, TRUE);
127  if (!NT_SUCCESS(Status)) return Status;
128 
129  GetDisplayModeRequest->DisplayMode = TermGetDisplayMode(Console);
130 
132  return STATUS_SUCCESS;
133 }
134 
135 /* API_NUMBER: ConsolepSetDisplayMode */
136 CSR_API(SrvSetConsoleDisplayMode)
137 {
139  PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetDisplayModeRequest;
142 
144  SetDisplayModeRequest->OutputHandle,
145  &Buff,
147  TRUE);
148  if (!NT_SUCCESS(Status)) return Status;
149 
151 
152  if (TermSetDisplayMode(Console, SetDisplayModeRequest->DisplayMode))
153  {
154  SetDisplayModeRequest->NewSBDim = Buff->ScreenBufferSize;
156  }
157  else
158  {
160  }
161 
163  return Status;
164 }
165 
166 /* API_NUMBER: ConsolepGetLargestWindowSize */
167 CSR_API(SrvGetLargestConsoleWindowSize)
168 {
170  PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetLargestWindowSizeRequest;
171  PCONSOLE /*PCONSRV_CONSOLE*/ Console;
173 
175  GetLargestWindowSizeRequest->OutputHandle,
176  &Buff,
177  GENERIC_READ,
178  TRUE);
179  if (!NT_SUCCESS(Status)) return Status;
180 
181  Console = Buff->Header.Console;
182 
183  /*
184  * Retrieve the largest possible console window size, without
185  * taking into account the size of the console screen buffer
186  * (thus differs from ConDrvGetConsoleScreenBufferInfo).
187  */
188  TermGetLargestConsoleWindowSize(Console, &GetLargestWindowSizeRequest->Size);
189 
191  return STATUS_SUCCESS;
192 }
193 
194 /* API_NUMBER: ConsolepShowCursor */
195 CSR_API(SrvShowConsoleCursor)
196 {
198  PCONSOLE_SHOWCURSOR ShowCursorRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ShowCursorRequest;
199  PCONSOLE /*PCONSRV_CONSOLE*/ Console;
201 
203  ShowCursorRequest->OutputHandle,
204  &Buff,
206  TRUE);
207  if (!NT_SUCCESS(Status)) return Status;
208 
209  Console = Buff->Header.Console;
210 
211  ShowCursorRequest->RefCount = TermShowMouseCursor(Console, ShowCursorRequest->Show);
212 
214  return STATUS_SUCCESS;
215 }
216 
217 /* API_NUMBER: ConsolepSetCursor */
218 CSR_API(SrvSetConsoleCursor)
219 {
221  BOOL Success;
222  PCONSOLE_SETCURSOR SetCursorRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetCursorRequest;
225 
226  // NOTE: Tests show that this function is used only for graphics screen buffers
227  // and otherwise it returns FALSE and sets last error to ERROR_INVALID_HANDLE.
228  // I find that behaviour is ridiculous but ok, let's accept it at the moment...
230  SetCursorRequest->OutputHandle,
231  &Buff,
233  TRUE);
234  if (!NT_SUCCESS(Status)) return Status;
235 
237 
238  Success = TermSetMouseCursor(Console, SetCursorRequest->CursorHandle);
239 
242 }
243 
244 /* API_NUMBER: ConsolepMenuControl */
245 CSR_API(SrvConsoleMenuControl)
246 {
248  PCONSOLE_MENUCONTROL MenuControlRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.MenuControlRequest;
251 
253  MenuControlRequest->OutputHandle,
254  &Buff,
256  TRUE);
257  if (!NT_SUCCESS(Status)) return Status;
258 
260 
261  MenuControlRequest->MenuHandle = TermMenuControl(Console,
262  MenuControlRequest->CmdIdLow,
263  MenuControlRequest->CmdIdHigh);
264 
266  return STATUS_SUCCESS;
267 }
268 
269 /* API_NUMBER: ConsolepSetMenuClose */
270 CSR_API(SrvSetConsoleMenuClose)
271 {
273  BOOL Success;
274  PCONSOLE_SETMENUCLOSE SetMenuCloseRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetMenuCloseRequest;
276 
278  &Console, TRUE);
279  if (!NT_SUCCESS(Status)) return Status;
280 
281  Success = TermSetMenuClose(Console, SetMenuCloseRequest->Enable);
282 
285 }
286 
287 /* Used by USERSRV!SrvGetThreadConsoleDesktop() */
288 NTSTATUS
289 NTAPI
291  IN ULONG_PTR ThreadId,
292  OUT HDESK* ConsoleDesktop)
293 {
295  PCSR_THREAD CsrThread;
297 
298  /* No console desktop handle by default */
299  *ConsoleDesktop = NULL;
300 
301  /* Retrieve and lock the thread */
302  Status = CsrLockThreadByClientId(ULongToHandle(ThreadId), &CsrThread);
303  if (!NT_SUCCESS(Status))
304  return Status;
305 
306  ASSERT(CsrThread->Process);
307 
308  /* Retrieve the console to which the process is attached, and unlock the thread */
310  &Console, TRUE);
311  CsrUnlockThread(CsrThread);
312 
313  if (!NT_SUCCESS(Status))
314  return Status;
315 
316  /* Retrieve the console desktop handle, and release the console */
317  *ConsoleDesktop = TermGetThreadConsoleDesktop(Console);
319 
320  return STATUS_SUCCESS;
321 }
322 
323 /* API_NUMBER: ConsolepGetConsoleWindow */
324 CSR_API(SrvGetConsoleWindow)
325 {
327  PCONSOLE_GETWINDOW GetWindowRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetWindowRequest;
329 
331  &Console, TRUE);
332  if (!NT_SUCCESS(Status)) return Status;
333 
334  GetWindowRequest->WindowHandle = TermGetConsoleWindowHandle(Console);
335 
337  return STATUS_SUCCESS;
338 }
339 
340 /* API_NUMBER: ConsolepSetIcon */
341 CSR_API(SrvSetConsoleIcon)
342 {
344  PCONSOLE_SETICON SetIconRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetIconRequest;
346 
348  &Console, TRUE);
349  if (!NT_SUCCESS(Status)) return Status;
350 
351  Status = (TermChangeIcon(Console, SetIconRequest->IconHandle)
354 
356  return Status;
357 }
358 
359 /* API_NUMBER: ConsolepGetSelectionInfo */
360 CSR_API(SrvGetConsoleSelectionInfo)
361 {
363  PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetSelectionInfoRequest;
365 
367  &Console, TRUE);
368  if (!NT_SUCCESS(Status)) return Status;
369 
370  Status = (TermGetSelectionInfo(Console, &GetSelectionInfoRequest->Info)
373 
375  return Status;
376 }
377 
378 /* API_NUMBER: ConsolepGetNumberOfFonts */
379 CSR_API(SrvGetConsoleNumberOfFonts)
380 {
382  PCONSOLE_GETNUMFONTS GetNumFontsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetNumFontsRequest;
383  PCONSOLE /*PCONSRV_CONSOLE*/ Console;
384 
386  &Console, TRUE);
387  if (!NT_SUCCESS(Status)) return Status;
388 
389  // FIXME!
390  // TermGetNumberOfFonts(Console, ...);
391  DPRINT1("%s not yet implemented\n", __FUNCTION__);
392  GetNumFontsRequest->NumFonts = 0;
393 
395  return STATUS_SUCCESS;
396 }
397 
398 /* API_NUMBER: ConsolepGetFontInfo */
399 CSR_API(SrvGetConsoleFontInfo)
400 {
402  PCONSOLE_GETFONTINFO GetFontInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetFontInfoRequest;
403  // PCONSOLE /*PCONSRV_CONSOLE*/ Console;
405 
407  GetFontInfoRequest->OutputHandle,
408  &Buff,
409  GENERIC_READ,
410  TRUE);
411  if (!NT_SUCCESS(Status)) return Status;
412 
413  // FIXME!
414  // Console = Buff->Header.Console;
415  // TermGetFontInfo(Console, ...);
416  DPRINT1("%s not yet implemented\n", __FUNCTION__);
417  GetFontInfoRequest->NumFonts = 0;
418 
420  return STATUS_SUCCESS;
421 }
422 
423 /* API_NUMBER: ConsolepGetFontSize */
424 CSR_API(SrvGetConsoleFontSize)
425 {
427  PCONSOLE_GETFONTSIZE GetFontSizeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetFontSizeRequest;
428  // PCONSOLE /*PCONSRV_CONSOLE*/ Console;
430 
432  GetFontSizeRequest->OutputHandle,
433  &Buff,
434  GENERIC_READ,
435  TRUE);
436  if (!NT_SUCCESS(Status)) return Status;
437 
438  // FIXME!
439  // Console = Buff->Header.Console;
440  // TermGetFontSize(Console, ...);
441  DPRINT1("%s not yet implemented\n", __FUNCTION__);
442 
444  return STATUS_SUCCESS;
445 }
446 
447 /* API_NUMBER: ConsolepGetCurrentFont */
448 CSR_API(SrvGetConsoleCurrentFont)
449 {
451  PCONSOLE_GETCURRENTFONT GetCurrentFontRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCurrentFontRequest;
452  // PCONSOLE /*PCONSRV_CONSOLE*/ Console;
454 
456  GetCurrentFontRequest->OutputHandle,
457  &Buff,
458  GENERIC_READ,
459  TRUE);
460  if (!NT_SUCCESS(Status)) return Status;
461 
462  // FIXME!
463  // Console = Buff->Header.Console;
464  // TermGetCurrentFont(Console, ...);
465  DPRINT1("%s not yet implemented\n", __FUNCTION__);
466  GetCurrentFontRequest->FontIndex = 0;
467 
469  return STATUS_SUCCESS;
470 }
471 
472 /* API_NUMBER: ConsolepSetFont */
473 CSR_API(SrvSetConsoleFont)
474 {
476  PCONSOLE_SETFONT SetFontRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetFontRequest;
477  // PCONSOLE /*PCONSRV_CONSOLE*/ Console;
479 
481  SetFontRequest->OutputHandle,
482  &Buff,
484  TRUE);
485  if (!NT_SUCCESS(Status)) return Status;
486 
487  // FIXME!
488  // Console = Buff->Header.Console;
489  // TermSetFont(Console, ...);
490  DPRINT1("%s not yet implemented\n", __FUNCTION__);
491 
493  return STATUS_SUCCESS;
494 }
495 
496 /* EOF */
#define IN
Definition: typedefs.h:39
#define ULongToHandle(h)
Definition: basetsd.h:81
NTSTATUS ConSrvGetConsole(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
Definition: console.c:271
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
struct _CONSOLE * Console
Definition: conio.h:52
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
HANDLE OutputHandle
Definition: conmsg.h:438
#define TermSetDisplayMode(Console, NewMode)
Definition: term.h:58
struct _CONSOLE_API_MESSAGE * PCONSOLE_API_MESSAGE
LONG NTSTATUS
Definition: precomp.h:26
#define TermSetMenuClose(Console, Enable)
Definition: term.h:64
NTSTATUS NTAPI GetThreadConsoleDesktop(IN ULONG_PTR ThreadId, OUT HDESK *ConsoleDesktop)
Definition: frontendctl.c:290
HANDLE OutputHandle
Definition: conmsg.h:693
#define PCONSRV_CONSOLE
Definition: conio.h:27
HCURSOR CursorHandle
Definition: conmsg.h:339
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:296
CONSOLE_IO_OBJECT Header
Definition: conio.h:82
uint32_t ULONG_PTR
Definition: typedefs.h:64
PCSR_PROCESS Process
Definition: csrsrv.h:69
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:463
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
COORD ScreenBufferSize
Definition: conio.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SetConsoleHardwareState(HANDLE hConsoleOutput, DWORD Flags, DWORD State)
Definition: console.c:944
void DPRINT(...)
Definition: polytest.cpp:61
#define CONSOLE_HARDWARE_STATE_GDI_MANAGED
Definition: conmsg.h:391
#define CONSOLE_HARDWARE_STATE_DIRECT
Definition: conmsg.h:392
#define TermGetConsoleWindowHandle(Console)
Definition: term.h:52
NTSTATUS NTAPI CsrUnlockThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:1074
#define ConSrvGetTextModeBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
Definition: conoutput.h:12
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
#define TermGetSelectionInfo(Console, pSelectionInfo)
Definition: term.h:54
NTSTATUS NTAPI CsrLockThreadByClientId(IN HANDLE Tid, OUT PCSR_THREAD *CsrThread)
Definition: thredsup.c:964
#define TermGetLargestConsoleWindowSize(Console, pSize)
Definition: term.h:34
CONSOLE_SELECTION_INFO Info
Definition: conmsg.h:844
#define TermShowMouseCursor(Console, Show)
Definition: term.h:38
#define ConSrvReleaseScreenBuffer(Buff, IsConsoleLocked)
Definition: conoutput.h:33
#define ConSrvGetScreenBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
Definition: conoutput.h:26
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
HANDLE OutputHandle
Definition: conmsg.h:338
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
HANDLE OutputHandle
Definition: conmsg.h:330
HANDLE OutputHandle
Definition: conmsg.h:421
#define TermMenuControl(Console, CmdIdLow, CmdIdHigh)
Definition: term.h:62
CSR_API(SrvGetConsoleHardwareState)
Definition: frontendctl.c:56
#define TermGetThreadConsoleDesktop(Console)
Definition: term.h:50
#define ConSrvGetGraphicsBuffer(ProcessData, Handle, Ptr, Access, LockConsole)
Definition: conoutput.h:19
#define TermSetMouseCursor(Console, CursorHandle)
Definition: term.h:60
CConsole Console
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
#define TermGetDisplayMode(Console)
Definition: term.h:56
return STATUS_SUCCESS
Definition: btrfs.c:2938
HICON IconHandle
Definition: conmsg.h:723
#define __FUNCTION__
Definition: types.h:112
HANDLE OutputHandle
Definition: conmsg.h:412
#define TermChangeIcon(Console, IconHandle)
Definition: term.h:48