Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1559 lines
51 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. getset.c
  5. Abstract:
  6. This file implements the NT console server console state API
  7. Author:
  8. Therese Stowell (thereses) 5-Dec-1990
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #ifdef i386
  14. VOID
  15. ReverseMousePointer(
  16. IN PSCREEN_INFORMATION ScreenInfo,
  17. IN PSMALL_RECT Region
  18. );
  19. #endif
  20. ULONG
  21. SrvGetConsoleMode(
  22. IN OUT PCSR_API_MSG m,
  23. IN OUT PCSR_REPLY_STATUS ReplyStatus
  24. )
  25. {
  26. PCONSOLE_MODE_MSG a = (PCONSOLE_MODE_MSG)&m->u.ApiMessageData;
  27. NTSTATUS Status;
  28. PCONSOLE_INFORMATION Console;
  29. PHANDLE_DATA HandleData;
  30. Status = ApiPreamble(a->ConsoleHandle,
  31. &Console
  32. );
  33. if (!NT_SUCCESS(Status)) {
  34. return Status;
  35. }
  36. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  37. a->Handle,
  38. CONSOLE_ANY_HANDLE,
  39. GENERIC_READ,
  40. &HandleData
  41. );
  42. if (NT_SUCCESS(Status)) {
  43. //
  44. // check handle type and access
  45. //
  46. if (HandleData->HandleType & CONSOLE_INPUT_HANDLE) {
  47. a->Mode = HandleData->Buffer.InputBuffer->InputMode;
  48. if (Console->Flags & CONSOLE_USE_PRIVATE_FLAGS) {
  49. a->Mode |= ENABLE_PRIVATE_FLAGS;
  50. if (Console->InsertMode) {
  51. a->Mode |= ENABLE_INSERT_MODE;
  52. }
  53. if (Console->Flags & CONSOLE_QUICK_EDIT_MODE) {
  54. a->Mode |= ENABLE_QUICK_EDIT_MODE;
  55. }
  56. }
  57. } else {
  58. a->Mode = HandleData->Buffer.ScreenBuffer->OutputMode;
  59. }
  60. }
  61. UnlockConsole(Console);
  62. return Status;
  63. UNREFERENCED_PARAMETER(ReplyStatus);
  64. }
  65. ULONG
  66. SrvGetConsoleNumberOfFonts(
  67. IN OUT PCSR_API_MSG m,
  68. IN OUT PCSR_REPLY_STATUS ReplyStatus
  69. )
  70. {
  71. PCONSOLE_GETNUMBEROFFONTS_MSG a = (PCONSOLE_GETNUMBEROFFONTS_MSG)&m->u.ApiMessageData;
  72. NTSTATUS Status;
  73. PCONSOLE_INFORMATION Console;
  74. Status = ApiPreamble(a->ConsoleHandle,
  75. &Console
  76. );
  77. if (!NT_SUCCESS(Status)) {
  78. return Status;
  79. }
  80. if (Console->FullScreenFlags & CONSOLE_FULLSCREEN) {
  81. Status = STATUS_FULLSCREEN_MODE;
  82. } else {
  83. Status = GetNumFonts(&a->NumberOfFonts);
  84. }
  85. UnlockConsole(Console);
  86. return Status;
  87. UNREFERENCED_PARAMETER(ReplyStatus);
  88. }
  89. ULONG
  90. SrvGetConsoleNumberOfInputEvents(
  91. IN OUT PCSR_API_MSG m,
  92. IN OUT PCSR_REPLY_STATUS ReplyStatus
  93. )
  94. {
  95. PCONSOLE_GETNUMBEROFINPUTEVENTS_MSG a = (PCONSOLE_GETNUMBEROFINPUTEVENTS_MSG)&m->u.ApiMessageData;
  96. NTSTATUS Status;
  97. PCONSOLE_INFORMATION Console;
  98. PHANDLE_DATA HandleData;
  99. Status = ApiPreamble(a->ConsoleHandle,
  100. &Console
  101. );
  102. if (!NT_SUCCESS(Status)) {
  103. return Status;
  104. }
  105. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  106. a->InputHandle,
  107. CONSOLE_INPUT_HANDLE,
  108. GENERIC_READ,
  109. &HandleData
  110. );
  111. if (NT_SUCCESS(Status)) {
  112. Status = GetNumberOfReadyEvents(HandleData->Buffer.InputBuffer,
  113. &a->ReadyEvents
  114. );
  115. }
  116. UnlockConsole(Console);
  117. return Status;
  118. UNREFERENCED_PARAMETER(ReplyStatus);
  119. }
  120. ULONG
  121. SrvGetConsoleScreenBufferInfo(
  122. IN OUT PCSR_API_MSG m,
  123. IN OUT PCSR_REPLY_STATUS ReplyStatus
  124. )
  125. {
  126. PCONSOLE_GETSCREENBUFFERINFO_MSG a = (PCONSOLE_GETSCREENBUFFERINFO_MSG)&m->u.ApiMessageData;
  127. NTSTATUS Status;
  128. PCONSOLE_INFORMATION Console;
  129. PHANDLE_DATA HandleData;
  130. Status = ApiPreamble(a->ConsoleHandle,
  131. &Console
  132. );
  133. if (!NT_SUCCESS(Status)) {
  134. return Status;
  135. }
  136. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  137. a->OutputHandle,
  138. CONSOLE_OUTPUT_HANDLE,
  139. GENERIC_READ,
  140. &HandleData
  141. );
  142. if (NT_SUCCESS(Status)) {
  143. Status = GetScreenBufferInformation(HandleData->Buffer.ScreenBuffer,
  144. &a->Size,
  145. &a->CursorPosition,
  146. &a->ScrollPosition,
  147. &a->Attributes,
  148. &a->CurrentWindowSize,
  149. &a->MaximumWindowSize
  150. );
  151. }
  152. UnlockConsole(Console);
  153. return Status;
  154. UNREFERENCED_PARAMETER(ReplyStatus);
  155. }
  156. ULONG
  157. SrvGetConsoleCursorInfo(
  158. IN OUT PCSR_API_MSG m,
  159. IN OUT PCSR_REPLY_STATUS ReplyStatus
  160. )
  161. {
  162. PCONSOLE_GETCURSORINFO_MSG a = (PCONSOLE_GETCURSORINFO_MSG)&m->u.ApiMessageData;
  163. NTSTATUS Status;
  164. PCONSOLE_INFORMATION Console;
  165. PHANDLE_DATA HandleData;
  166. Status = ApiPreamble(a->ConsoleHandle,
  167. &Console
  168. );
  169. if (!NT_SUCCESS(Status)) {
  170. return Status;
  171. }
  172. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  173. a->OutputHandle,
  174. CONSOLE_OUTPUT_HANDLE,
  175. GENERIC_READ,
  176. &HandleData
  177. );
  178. if (NT_SUCCESS(Status)) {
  179. a->CursorSize = HandleData->Buffer.ScreenBuffer->BufferInfo.TextInfo.CursorSize;
  180. a->Visible = (BOOLEAN) HandleData->Buffer.ScreenBuffer->BufferInfo.TextInfo.CursorVisible;
  181. }
  182. UnlockConsole(Console);
  183. return Status;
  184. UNREFERENCED_PARAMETER(ReplyStatus);
  185. }
  186. ULONG
  187. SrvGetConsoleSelectionInfo(
  188. IN OUT PCSR_API_MSG m,
  189. IN OUT PCSR_REPLY_STATUS ReplyStatus
  190. )
  191. {
  192. PCONSOLE_GETSELECTIONINFO_MSG a = (PCONSOLE_GETSELECTIONINFO_MSG)&m->u.ApiMessageData;
  193. NTSTATUS Status;
  194. PCONSOLE_INFORMATION Console;
  195. Status = ApiPreamble(a->ConsoleHandle,
  196. &Console
  197. );
  198. if (NT_SUCCESS(Status)) {
  199. if (Console->Flags & CONSOLE_SELECTING) {
  200. a->SelectionInfo.dwFlags = (CONSOLE_SELECTION_IN_PROGRESS |
  201. (Console->SelectionFlags & CONSOLE_SELECTION_VALID));
  202. a->SelectionInfo.dwSelectionAnchor = Console->SelectionAnchor;
  203. a->SelectionInfo.srSelection = Console->SelectionRect;
  204. } else {
  205. RtlZeroMemory(&a->SelectionInfo, sizeof(a->SelectionInfo));
  206. }
  207. UnlockConsole(Console);
  208. }
  209. return Status;
  210. UNREFERENCED_PARAMETER(ReplyStatus);
  211. }
  212. ULONG
  213. SrvGetConsoleMouseInfo(
  214. IN OUT PCSR_API_MSG m,
  215. IN OUT PCSR_REPLY_STATUS ReplyStatus
  216. )
  217. {
  218. PCONSOLE_GETMOUSEINFO_MSG a = (PCONSOLE_GETMOUSEINFO_MSG)&m->u.ApiMessageData;
  219. NTSTATUS Status;
  220. PCONSOLE_INFORMATION Console;
  221. Status = ApiPreamble(a->ConsoleHandle,
  222. &Console
  223. );
  224. if (!NT_SUCCESS(Status)) {
  225. return Status;
  226. }
  227. Status = GetMouseButtons(&a->NumButtons);
  228. UnlockConsole(Console);
  229. return Status;
  230. UNREFERENCED_PARAMETER(ReplyStatus);
  231. }
  232. ULONG
  233. SrvGetConsoleFontInfo(
  234. IN OUT PCSR_API_MSG m,
  235. IN OUT PCSR_REPLY_STATUS ReplyStatus
  236. )
  237. {
  238. PCONSOLE_GETFONTINFO_MSG a = (PCONSOLE_GETFONTINFO_MSG)&m->u.ApiMessageData;
  239. NTSTATUS Status;
  240. PCONSOLE_INFORMATION Console;
  241. PHANDLE_DATA HandleData;
  242. Status = ApiPreamble(a->ConsoleHandle,
  243. &Console
  244. );
  245. if (!NT_SUCCESS(Status)) {
  246. return Status;
  247. }
  248. if (!CsrValidateMessageBuffer(m, &a->BufPtr, a->NumFonts, sizeof(*a->BufPtr))) {
  249. UnlockConsole(Console);
  250. return STATUS_INVALID_PARAMETER;
  251. }
  252. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  253. a->OutputHandle,
  254. CONSOLE_OUTPUT_HANDLE,
  255. GENERIC_READ,
  256. &HandleData
  257. );
  258. if (NT_SUCCESS(Status)) {
  259. if (HandleData->Buffer.ScreenBuffer->Console->FullScreenFlags & CONSOLE_FULLSCREEN) {
  260. Status = STATUS_FULLSCREEN_MODE;
  261. } else {
  262. Status = GetAvailableFonts(HandleData->Buffer.ScreenBuffer,
  263. a->MaximumWindow,
  264. a->BufPtr,
  265. &a->NumFonts
  266. );
  267. }
  268. }
  269. UnlockConsole(Console);
  270. return Status;
  271. UNREFERENCED_PARAMETER(ReplyStatus);
  272. }
  273. ULONG
  274. SrvGetConsoleFontSize(
  275. IN OUT PCSR_API_MSG m,
  276. IN OUT PCSR_REPLY_STATUS ReplyStatus
  277. )
  278. {
  279. PCONSOLE_GETFONTSIZE_MSG a = (PCONSOLE_GETFONTSIZE_MSG)&m->u.ApiMessageData;
  280. NTSTATUS Status;
  281. PCONSOLE_INFORMATION Console;
  282. PHANDLE_DATA HandleData;
  283. Status = ApiPreamble(a->ConsoleHandle,
  284. &Console
  285. );
  286. if (!NT_SUCCESS(Status)) {
  287. return Status;
  288. }
  289. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  290. a->OutputHandle,
  291. CONSOLE_OUTPUT_HANDLE,
  292. GENERIC_READ,
  293. &HandleData
  294. );
  295. if (NT_SUCCESS(Status)) {
  296. if (HandleData->Buffer.ScreenBuffer->Console->FullScreenFlags & CONSOLE_FULLSCREEN) {
  297. Status = STATUS_FULLSCREEN_MODE;
  298. } else {
  299. Status = GetFontSize(a->FontIndex,
  300. &a->FontSize
  301. );
  302. }
  303. }
  304. UnlockConsole(Console);
  305. return Status;
  306. UNREFERENCED_PARAMETER(ReplyStatus);
  307. }
  308. ULONG
  309. SrvGetConsoleCurrentFont(
  310. IN OUT PCSR_API_MSG m,
  311. IN OUT PCSR_REPLY_STATUS ReplyStatus
  312. )
  313. {
  314. PCONSOLE_GETCURRENTFONT_MSG a = (PCONSOLE_GETCURRENTFONT_MSG)&m->u.ApiMessageData;
  315. NTSTATUS Status;
  316. PCONSOLE_INFORMATION Console;
  317. PHANDLE_DATA HandleData;
  318. Status = ApiPreamble(a->ConsoleHandle,
  319. &Console
  320. );
  321. if (!NT_SUCCESS(Status)) {
  322. return Status;
  323. }
  324. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  325. a->OutputHandle,
  326. CONSOLE_OUTPUT_HANDLE,
  327. GENERIC_READ,
  328. &HandleData
  329. );
  330. if (NT_SUCCESS(Status)) {
  331. if (HandleData->Buffer.ScreenBuffer->Console->FullScreenFlags & CONSOLE_FULLSCREEN) {
  332. Status = STATUS_FULLSCREEN_MODE;
  333. } else {
  334. Status = GetCurrentFont(HandleData->Buffer.ScreenBuffer,
  335. a->MaximumWindow,
  336. &a->FontIndex,
  337. &a->FontSize
  338. );
  339. }
  340. }
  341. UnlockConsole(Console);
  342. return Status;
  343. UNREFERENCED_PARAMETER(ReplyStatus);
  344. }
  345. ULONG
  346. SrvSetConsoleMode(
  347. IN OUT PCSR_API_MSG m,
  348. IN OUT PCSR_REPLY_STATUS ReplyStatus
  349. )
  350. {
  351. PCONSOLE_MODE_MSG a = (PCONSOLE_MODE_MSG)&m->u.ApiMessageData;
  352. NTSTATUS Status;
  353. PCONSOLE_INFORMATION Console;
  354. PHANDLE_DATA HandleData;
  355. Status = ApiPreamble(a->ConsoleHandle,
  356. &Console
  357. );
  358. if (!NT_SUCCESS(Status)) {
  359. return Status;
  360. }
  361. try {
  362. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  363. a->Handle,
  364. CONSOLE_ANY_HANDLE,
  365. GENERIC_WRITE,
  366. &HandleData
  367. );
  368. if (!NT_SUCCESS(Status)) {
  369. leave;
  370. }
  371. if (HandleData->HandleType & CONSOLE_INPUT_HANDLE) {
  372. if (a->Mode & ~(INPUT_MODES | PRIVATE_MODES)) {
  373. Status = STATUS_INVALID_PARAMETER;
  374. leave;
  375. }
  376. if ((a->Mode & (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)) == ENABLE_ECHO_INPUT) {
  377. Status = STATUS_INVALID_PARAMETER;
  378. leave;
  379. }
  380. if (a->Mode & PRIVATE_MODES) {
  381. Console->Flags |= CONSOLE_USE_PRIVATE_FLAGS;
  382. if (a->Mode & ENABLE_QUICK_EDIT_MODE) {
  383. Console->Flags |= CONSOLE_QUICK_EDIT_MODE;
  384. } else {
  385. Console->Flags &= ~CONSOLE_QUICK_EDIT_MODE;
  386. }
  387. if (a->Mode & ENABLE_INSERT_MODE) {
  388. Console->InsertMode = TRUE;
  389. } else {
  390. Console->InsertMode = FALSE;
  391. }
  392. } else {
  393. Console->Flags &= ~CONSOLE_USE_PRIVATE_FLAGS;
  394. }
  395. #ifdef i386
  396. if (Console->FullScreenFlags & CONSOLE_FULLSCREEN_HARDWARE &&
  397. Console->CurrentScreenBuffer->Flags & CONSOLE_TEXTMODE_BUFFER &&
  398. (a->Mode & ENABLE_MOUSE_INPUT) != (HandleData->Buffer.InputBuffer->InputMode & ENABLE_MOUSE_INPUT)) {
  399. if (a->Mode & ENABLE_MOUSE_INPUT) {
  400. HandleData->Buffer.InputBuffer->InputMode |= ENABLE_MOUSE_INPUT;
  401. }
  402. #if defined(FE_SB)
  403. // Korean HBIOS doesn't like to reverse mouse pointer.
  404. // Because HBIOS will initialize full screen mode again.
  405. // 949 = Korea WanSung Code Page.
  406. if (Console->OutputCP != 949) {
  407. ReverseMousePointer(Console->CurrentScreenBuffer,
  408. &Console->CurrentScreenBuffer->Window);
  409. }
  410. #else
  411. ReverseMousePointer(Console->CurrentScreenBuffer,
  412. &Console->CurrentScreenBuffer->Window);
  413. #endif
  414. }
  415. #endif
  416. HandleData->Buffer.InputBuffer->InputMode = a->Mode & ~PRIVATE_MODES;
  417. }
  418. else {
  419. if (a->Mode & ~OUTPUT_MODES) {
  420. Status = STATUS_INVALID_PARAMETER;
  421. leave;
  422. }
  423. HandleData->Buffer.ScreenBuffer->OutputMode = a->Mode;
  424. }
  425. } finally {
  426. UnlockConsole(Console);
  427. }
  428. return Status;
  429. UNREFERENCED_PARAMETER(ReplyStatus);
  430. }
  431. ULONG
  432. SrvGenerateConsoleCtrlEvent(
  433. IN OUT PCSR_API_MSG m,
  434. IN OUT PCSR_REPLY_STATUS ReplyStatus
  435. )
  436. {
  437. PCONSOLE_CTRLEVENT_MSG a = (PCONSOLE_CTRLEVENT_MSG)&m->u.ApiMessageData;
  438. NTSTATUS Status;
  439. PCONSOLE_INFORMATION Console;
  440. Status = ApiPreamble(a->ConsoleHandle,
  441. &Console
  442. );
  443. if (!NT_SUCCESS(Status)) {
  444. return Status;
  445. }
  446. try {
  447. //
  448. // Make sure the process group id is valid
  449. //
  450. if (a->ProcessGroupId) {
  451. PCONSOLE_PROCESS_HANDLE ProcessHandleRecord;
  452. PLIST_ENTRY ListHead, ListNext;
  453. Status = STATUS_INVALID_PARAMETER;
  454. ListHead = &Console->ProcessHandleList;
  455. ListNext = ListHead->Flink;
  456. while (ListNext != ListHead) {
  457. ProcessHandleRecord = CONTAINING_RECORD( ListNext, CONSOLE_PROCESS_HANDLE, ListLink );
  458. ListNext = ListNext->Flink;
  459. if (ProcessHandleRecord->Process->ProcessGroupId == a->ProcessGroupId) {
  460. Status = STATUS_SUCCESS;
  461. break;
  462. }
  463. }
  464. }
  465. if (NT_SUCCESS(Status)) {
  466. Console->LimitingProcessId = a->ProcessGroupId;
  467. HandleCtrlEvent(Console, a->CtrlEvent);
  468. }
  469. } finally {
  470. UnlockConsole(Console);
  471. }
  472. return Status;
  473. UNREFERENCED_PARAMETER(ReplyStatus);
  474. }
  475. ULONG
  476. SrvSetConsoleActiveScreenBuffer(
  477. IN OUT PCSR_API_MSG m,
  478. IN OUT PCSR_REPLY_STATUS ReplyStatus
  479. )
  480. {
  481. PCONSOLE_SETACTIVESCREENBUFFER_MSG a = (PCONSOLE_SETACTIVESCREENBUFFER_MSG)&m->u.ApiMessageData;
  482. NTSTATUS Status;
  483. PCONSOLE_INFORMATION Console;
  484. PHANDLE_DATA HandleData;
  485. Status = ApiPreamble(a->ConsoleHandle,
  486. &Console
  487. );
  488. if (!NT_SUCCESS(Status)) {
  489. return Status;
  490. }
  491. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  492. a->OutputHandle,
  493. CONSOLE_GRAPHICS_OUTPUT_HANDLE | CONSOLE_OUTPUT_HANDLE,
  494. GENERIC_WRITE,
  495. &HandleData
  496. );
  497. if (NT_SUCCESS(Status)) {
  498. Status = SetActiveScreenBuffer(HandleData->Buffer.ScreenBuffer);
  499. }
  500. UnlockConsole(Console);
  501. return Status;
  502. UNREFERENCED_PARAMETER(ReplyStatus);
  503. }
  504. ULONG
  505. SrvFlushConsoleInputBuffer(
  506. IN OUT PCSR_API_MSG m,
  507. IN OUT PCSR_REPLY_STATUS ReplyStatus
  508. )
  509. {
  510. PCONSOLE_FLUSHINPUTBUFFER_MSG a = (PCONSOLE_FLUSHINPUTBUFFER_MSG)&m->u.ApiMessageData;
  511. NTSTATUS Status;
  512. PCONSOLE_INFORMATION Console;
  513. PHANDLE_DATA HandleData;
  514. Status = ApiPreamble(a->ConsoleHandle,
  515. &Console
  516. );
  517. if (!NT_SUCCESS(Status)) {
  518. return Status;
  519. }
  520. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  521. a->InputHandle,
  522. CONSOLE_INPUT_HANDLE,
  523. GENERIC_WRITE,
  524. &HandleData
  525. );
  526. if (NT_SUCCESS(Status)) {
  527. Status = FlushInputBuffer(HandleData->Buffer.InputBuffer);
  528. }
  529. UnlockConsole(Console);
  530. return Status;
  531. UNREFERENCED_PARAMETER(ReplyStatus);
  532. }
  533. ULONG
  534. SrvGetLargestConsoleWindowSize(
  535. IN OUT PCSR_API_MSG m,
  536. IN OUT PCSR_REPLY_STATUS ReplyStatus
  537. )
  538. {
  539. PCONSOLE_GETLARGESTWINDOWSIZE_MSG a = (PCONSOLE_GETLARGESTWINDOWSIZE_MSG)&m->u.ApiMessageData;
  540. NTSTATUS Status;
  541. PCONSOLE_INFORMATION Console;
  542. PHANDLE_DATA HandleData;
  543. PSCREEN_INFORMATION ScreenInfo;
  544. WINDOW_LIMITS WindowLimits;
  545. Status = ApiPreamble(a->ConsoleHandle,
  546. &Console
  547. );
  548. if (!NT_SUCCESS(Status)) {
  549. return Status;
  550. }
  551. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  552. a->OutputHandle,
  553. CONSOLE_OUTPUT_HANDLE,
  554. GENERIC_WRITE,
  555. &HandleData
  556. );
  557. if (NT_SUCCESS(Status)) {
  558. COORD FontSize;
  559. ScreenInfo = HandleData->Buffer.ScreenBuffer;
  560. if (ScreenInfo->Console->FullScreenFlags & CONSOLE_FULLSCREEN_HARDWARE) {
  561. a->Size.X = 80;
  562. #if defined(FE_SB)
  563. a->Size.Y = CONSOLE_IS_DBCS_OUTPUTCP(Console)?25:50;
  564. #else
  565. a->Size.Y = 50;
  566. #endif
  567. } else {
  568. if (ScreenInfo->Flags & CONSOLE_TEXTMODE_BUFFER) {
  569. FontSize = SCR_FONTSIZE(ScreenInfo);
  570. } else {
  571. FontSize.X = 1;
  572. FontSize.Y = 1;
  573. }
  574. GetWindowLimits(ScreenInfo, &WindowLimits);
  575. a->Size.X = (SHORT)(WindowLimits.FullScreenSize.X / FontSize.X);
  576. a->Size.Y = (SHORT)(WindowLimits.FullScreenSize.Y / FontSize.Y);
  577. }
  578. }
  579. UnlockConsole(Console);
  580. return Status;
  581. UNREFERENCED_PARAMETER(ReplyStatus);
  582. }
  583. ULONG
  584. SrvSetConsoleScreenBufferSize(
  585. IN OUT PCSR_API_MSG m,
  586. IN OUT PCSR_REPLY_STATUS ReplyStatus
  587. )
  588. {
  589. PCONSOLE_SETSCREENBUFFERSIZE_MSG a = (PCONSOLE_SETSCREENBUFFERSIZE_MSG)&m->u.ApiMessageData;
  590. NTSTATUS Status;
  591. PCONSOLE_INFORMATION Console;
  592. PHANDLE_DATA HandleData;
  593. PSCREEN_INFORMATION ScreenInfo;
  594. WINDOW_LIMITS WindowLimits;
  595. Status = ApiPreamble(a->ConsoleHandle,
  596. &Console
  597. );
  598. if (!NT_SUCCESS(Status)) {
  599. return Status;
  600. }
  601. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  602. a->OutputHandle,
  603. CONSOLE_OUTPUT_HANDLE,
  604. GENERIC_WRITE,
  605. &HandleData
  606. );
  607. if (NT_SUCCESS(Status)) {
  608. ScreenInfo = HandleData->Buffer.ScreenBuffer;
  609. //
  610. // make sure requested screen buffer size isn't smaller than the window
  611. //
  612. GetWindowLimits(ScreenInfo, &WindowLimits);
  613. if (a->Size.X < CONSOLE_WINDOW_SIZE_X(ScreenInfo) ||
  614. a->Size.Y < CONSOLE_WINDOW_SIZE_Y(ScreenInfo) ||
  615. a->Size.Y < WindowLimits.MinimumWindowSize.Y ||
  616. a->Size.X < WindowLimits.MinimumWindowSize.X) {
  617. Status = STATUS_INVALID_PARAMETER;
  618. }
  619. else if (a->Size.X == ScreenInfo->ScreenBufferSize.X &&
  620. a->Size.Y == ScreenInfo->ScreenBufferSize.Y) {
  621. Status = STATUS_SUCCESS;
  622. } else {
  623. Status = ResizeScreenBuffer(ScreenInfo,
  624. a->Size,
  625. TRUE);
  626. }
  627. }
  628. UnlockConsole(Console);
  629. return Status;
  630. UNREFERENCED_PARAMETER(ReplyStatus);
  631. }
  632. ULONG
  633. SrvSetConsoleCursorPosition(
  634. IN OUT PCSR_API_MSG m,
  635. IN OUT PCSR_REPLY_STATUS ReplyStatus
  636. )
  637. {
  638. PCONSOLE_SETCURSORPOSITION_MSG a = (PCONSOLE_SETCURSORPOSITION_MSG)&m->u.ApiMessageData;
  639. NTSTATUS Status;
  640. PCONSOLE_INFORMATION Console;
  641. PHANDLE_DATA HandleData;
  642. COORD WindowOrigin;
  643. PSCREEN_INFORMATION ScreenInfo;
  644. Status = ApiPreamble(a->ConsoleHandle,
  645. &Console
  646. );
  647. if (!NT_SUCCESS(Status)) {
  648. return Status;
  649. }
  650. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  651. a->OutputHandle,
  652. CONSOLE_OUTPUT_HANDLE,
  653. GENERIC_WRITE,
  654. &HandleData
  655. );
  656. if (NT_SUCCESS(Status)) {
  657. ScreenInfo = HandleData->Buffer.ScreenBuffer;
  658. if (a->CursorPosition.X >= ScreenInfo->ScreenBufferSize.X ||
  659. a->CursorPosition.Y >= ScreenInfo->ScreenBufferSize.Y ||
  660. a->CursorPosition.X < 0 ||
  661. a->CursorPosition.Y < 0) {
  662. Status = STATUS_INVALID_PARAMETER;
  663. } else {
  664. Status = SetCursorPosition(ScreenInfo,
  665. a->CursorPosition,
  666. TRUE
  667. );
  668. }
  669. if (NT_SUCCESS(Status)) {
  670. #if defined(FE_IME)
  671. if (ScreenInfo->Console->Flags & CONSOLE_JUST_VDM_UNREGISTERED){
  672. if( ScreenInfo->Console->InputBuffer.ImeMode.Open ){
  673. SHORT ScrollY = 0;
  674. AdjustCursorPosition(ScreenInfo,a->CursorPosition,TRUE,&ScrollY);
  675. a->CursorPosition.Y += ScrollY;
  676. }
  677. Console->Flags &= ~CONSOLE_JUST_VDM_UNREGISTERED;
  678. }
  679. // Bug fix: 442406
  680. // Telnet : KOR IME : WinSrv.dll : SetConsoleCursorPostion does not handle cursor positioning correctly.
  681. // 949 = Korea WanSung Code Page.
  682. else if (ScreenInfo->Console->OutputCP == 949)
  683. {
  684. if( ScreenInfo->Console->InputBuffer.ImeMode.Open ){
  685. ConsoleImeResizeCompStrView(Console,ScreenInfo->Window);
  686. }
  687. }
  688. #endif
  689. WindowOrigin.X = 0;
  690. WindowOrigin.Y = 0;
  691. if (ScreenInfo->Window.Left > a->CursorPosition.X) {
  692. WindowOrigin.X = a->CursorPosition.X - ScreenInfo->Window.Left;
  693. }
  694. else if (ScreenInfo->Window.Right < a->CursorPosition.X) {
  695. WindowOrigin.X = a->CursorPosition.X - ScreenInfo->Window.Right;
  696. }
  697. if (ScreenInfo->Window.Top > a->CursorPosition.Y) {
  698. WindowOrigin.Y = a->CursorPosition.Y - ScreenInfo->Window.Top;
  699. }
  700. else if (ScreenInfo->Window.Bottom < a->CursorPosition.Y) {
  701. WindowOrigin.Y = a->CursorPosition.Y - ScreenInfo->Window.Bottom;
  702. }
  703. Status = SetWindowOrigin(ScreenInfo,
  704. FALSE,
  705. WindowOrigin
  706. );
  707. }
  708. }
  709. UnlockConsole(Console);
  710. return Status;
  711. UNREFERENCED_PARAMETER(ReplyStatus);
  712. }
  713. ULONG
  714. SrvSetConsoleCursorInfo(
  715. IN OUT PCSR_API_MSG m,
  716. IN OUT PCSR_REPLY_STATUS ReplyStatus
  717. )
  718. {
  719. PCONSOLE_SETCURSORINFO_MSG a = (PCONSOLE_SETCURSORINFO_MSG)&m->u.ApiMessageData;
  720. NTSTATUS Status;
  721. PCONSOLE_INFORMATION Console;
  722. PHANDLE_DATA HandleData;
  723. Status = ApiPreamble(a->ConsoleHandle,
  724. &Console
  725. );
  726. if (!NT_SUCCESS(Status)) {
  727. return Status;
  728. }
  729. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  730. a->OutputHandle,
  731. CONSOLE_OUTPUT_HANDLE,
  732. GENERIC_WRITE,
  733. &HandleData
  734. );
  735. if (NT_SUCCESS(Status)) {
  736. if (a->CursorSize > 100 || a->CursorSize == 0) {
  737. Status = STATUS_INVALID_PARAMETER;
  738. } else {
  739. Status = SetCursorInformation(HandleData->Buffer.ScreenBuffer,a->CursorSize,a->Visible);
  740. }
  741. }
  742. UnlockConsole(Console);
  743. return Status;
  744. UNREFERENCED_PARAMETER(ReplyStatus);
  745. }
  746. ULONG
  747. SrvSetConsoleWindowInfo(
  748. IN OUT PCSR_API_MSG m,
  749. IN OUT PCSR_REPLY_STATUS ReplyStatus
  750. )
  751. {
  752. PCONSOLE_SETWINDOWINFO_MSG a = (PCONSOLE_SETWINDOWINFO_MSG)&m->u.ApiMessageData;
  753. NTSTATUS Status;
  754. PCONSOLE_INFORMATION Console;
  755. PHANDLE_DATA HandleData;
  756. PSCREEN_INFORMATION ScreenInfo;
  757. COORD NewWindowSize;
  758. WINDOW_LIMITS WindowLimits;
  759. Status = ApiPreamble(a->ConsoleHandle,
  760. &Console
  761. );
  762. if (!NT_SUCCESS(Status)) {
  763. return Status;
  764. }
  765. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  766. a->OutputHandle,
  767. CONSOLE_OUTPUT_HANDLE,
  768. GENERIC_WRITE,
  769. &HandleData
  770. );
  771. if (NT_SUCCESS(Status)) {
  772. ScreenInfo = HandleData->Buffer.ScreenBuffer;
  773. if (!a->Absolute) {
  774. a->Window.Left += ScreenInfo->Window.Left;
  775. a->Window.Right += ScreenInfo->Window.Right;
  776. a->Window.Top += ScreenInfo->Window.Top;
  777. a->Window.Bottom += ScreenInfo->Window.Bottom;
  778. }
  779. if (a->Window.Right < a->Window.Left ||
  780. a->Window.Bottom < a->Window.Top) {
  781. Status = STATUS_INVALID_PARAMETER;
  782. } else {
  783. NewWindowSize.X = (SHORT)(WINDOW_SIZE_X(&a->Window));
  784. NewWindowSize.Y = (SHORT)(WINDOW_SIZE_Y(&a->Window));
  785. GetWindowLimits(ScreenInfo, &WindowLimits);
  786. if ((NewWindowSize.X > WindowLimits.MaximumWindowSize.X ||
  787. NewWindowSize.Y > WindowLimits.MaximumWindowSize.Y) &&
  788. !(ScreenInfo->Console->FullScreenFlags & CONSOLE_FULLSCREEN)) {
  789. Status = STATUS_INVALID_PARAMETER;
  790. } else {
  791. #ifdef i386
  792. if (ScreenInfo->Console->FullScreenFlags & CONSOLE_FULLSCREEN) {
  793. COORD NewOrigin;
  794. if (NewWindowSize.X != (SHORT)(WINDOW_SIZE_X(&ScreenInfo->Window)) ||
  795. NewWindowSize.Y != (SHORT)(WINDOW_SIZE_Y(&ScreenInfo->Window))) {
  796. COORD WindowSize;
  797. ULONG ModeIndex;
  798. #if defined(FE_SB)
  799. ModeIndex = MatchWindowSize(ScreenInfo->Console->OutputCP,NewWindowSize,&WindowSize);
  800. #else
  801. ModeIndex = MatchWindowSize(NewWindowSize,&WindowSize);
  802. #endif
  803. if (NewWindowSize.X != WindowSize.X ||
  804. NewWindowSize.Y != WindowSize.Y ||
  805. WindowSize.X > ScreenInfo->ScreenBufferSize.X ||
  806. WindowSize.Y > ScreenInfo->ScreenBufferSize.Y) {
  807. UnlockConsole(Console);
  808. return (ULONG) STATUS_FULLSCREEN_MODE;
  809. }
  810. ScreenInfo->BufferInfo.TextInfo.ModeIndex = ModeIndex;
  811. ResizeWindow(ScreenInfo,
  812. &a->Window,
  813. FALSE
  814. );
  815. ScreenInfo->BufferInfo.TextInfo.WindowedWindowSize.X =
  816. CONSOLE_WINDOW_SIZE_X(ScreenInfo);
  817. ScreenInfo->BufferInfo.TextInfo.WindowedWindowSize.Y =
  818. CONSOLE_WINDOW_SIZE_Y(ScreenInfo);
  819. if (ScreenInfo->Console->FullScreenFlags & CONSOLE_FULLSCREEN_HARDWARE &&
  820. (!(ScreenInfo->Console->Flags & CONSOLE_VDM_REGISTERED)) ) {
  821. SetVideoMode(ScreenInfo);
  822. WriteToScreen(ScreenInfo,&ScreenInfo->Window);
  823. }
  824. } else {
  825. NewOrigin.X = a->Window.Left;
  826. NewOrigin.Y = a->Window.Top;
  827. SetWindowOrigin(ScreenInfo,
  828. TRUE,
  829. NewOrigin
  830. );
  831. }
  832. } else
  833. #endif
  834. {
  835. Status = ResizeWindow(ScreenInfo,
  836. &a->Window,
  837. TRUE
  838. );
  839. if (ACTIVE_SCREEN_BUFFER(ScreenInfo)) {
  840. SetWindowSize(ScreenInfo);
  841. WriteToScreen(ScreenInfo,&ScreenInfo->Window);
  842. }
  843. }
  844. }
  845. }
  846. }
  847. UnlockConsole(Console);
  848. return Status;
  849. UNREFERENCED_PARAMETER(ReplyStatus);
  850. }
  851. ULONG
  852. SrvScrollConsoleScreenBuffer(
  853. IN OUT PCSR_API_MSG m,
  854. IN OUT PCSR_REPLY_STATUS ReplyStatus
  855. )
  856. {
  857. PCONSOLE_SCROLLSCREENBUFFER_MSG a = (PCONSOLE_SCROLLSCREENBUFFER_MSG)&m->u.ApiMessageData;
  858. NTSTATUS Status;
  859. PCONSOLE_INFORMATION Console;
  860. PHANDLE_DATA HandleData;
  861. PSMALL_RECT ClipRect;
  862. Status = ApiPreamble(a->ConsoleHandle,
  863. &Console
  864. );
  865. if (!NT_SUCCESS(Status)) {
  866. return Status;
  867. }
  868. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  869. a->OutputHandle,
  870. CONSOLE_OUTPUT_HANDLE,
  871. GENERIC_WRITE,
  872. &HandleData
  873. );
  874. if (NT_SUCCESS(Status)) {
  875. if (a->Clip) {
  876. ClipRect = &a->ClipRectangle;
  877. }
  878. else {
  879. ClipRect = NULL;
  880. }
  881. if (!a->Unicode) {
  882. #if defined(FE_SB)
  883. a->Fill.Char.UnicodeChar = CharToWchar(Console,
  884. Console->OutputCP,
  885. &a->Fill.Char.AsciiChar);
  886. #else
  887. a->Fill.Char.UnicodeChar = CharToWchar(
  888. Console->OutputCP, a->Fill.Char.AsciiChar);
  889. #endif
  890. } else if ((Console->CurrentScreenBuffer->Flags & CONSOLE_OEMFONT_DISPLAY) &&
  891. !(Console->FullScreenFlags & CONSOLE_FULLSCREEN)) {
  892. RealUnicodeToFalseUnicode(&a->Fill.Char.UnicodeChar,
  893. 1,
  894. Console->OutputCP
  895. );
  896. }
  897. Status = ScrollRegion(HandleData->Buffer.ScreenBuffer,
  898. &a->ScrollRectangle,
  899. ClipRect,
  900. a->DestinationOrigin,
  901. a->Fill
  902. );
  903. }
  904. UnlockConsole(Console);
  905. return Status;
  906. UNREFERENCED_PARAMETER(ReplyStatus);
  907. }
  908. VOID
  909. UpdatePopups(
  910. IN PCONSOLE_INFORMATION Console,
  911. IN WORD NewAttributes,
  912. IN WORD NewPopupAttributes,
  913. IN WORD OldAttributes,
  914. IN WORD OldPopupAttributes
  915. )
  916. /*
  917. this routine is called when the user changes the screen/popup
  918. colors. it goes through the popup structures and changes
  919. the saved contents to reflect the new screen/popup colors.
  920. */
  921. {
  922. PLIST_ENTRY HistoryListHead, HistoryListNext;
  923. PLIST_ENTRY PopupListHead, PopupListNext;
  924. PCOMMAND_HISTORY History;
  925. PCLE_POPUP Popup;
  926. SHORT i,j;
  927. PCHAR_INFO OldContents;
  928. WORD InvertedOldPopupAttributes,InvertedNewPopupAttributes;
  929. InvertedOldPopupAttributes = (WORD)(((OldPopupAttributes << 4) & 0xf0) |
  930. ((OldPopupAttributes >> 4) & 0x0f));
  931. InvertedNewPopupAttributes = (WORD)(((NewPopupAttributes << 4) & 0xf0) |
  932. ((NewPopupAttributes >> 4) & 0x0f));
  933. HistoryListHead = &Console->CommandHistoryList;
  934. HistoryListNext = HistoryListHead->Blink;
  935. while (HistoryListNext != HistoryListHead) {
  936. History = CONTAINING_RECORD( HistoryListNext, COMMAND_HISTORY, ListLink );
  937. HistoryListNext = HistoryListNext->Blink;
  938. if (History->Flags & CLE_ALLOCATED && !CLE_NO_POPUPS(History)) {
  939. PopupListHead = &History->PopupList;
  940. PopupListNext = PopupListHead->Blink;
  941. while (PopupListNext != PopupListHead) {
  942. Popup = CONTAINING_RECORD( PopupListNext, CLE_POPUP, ListLink );
  943. PopupListNext = PopupListNext->Blink;
  944. OldContents = Popup->OldContents;
  945. for (i=Popup->Region.Left;i<=Popup->Region.Right;i++) {
  946. for (j=Popup->Region.Top;j<=Popup->Region.Bottom;j++) {
  947. if (OldContents->Attributes == OldAttributes) {
  948. OldContents->Attributes = NewAttributes;
  949. } else if (OldContents->Attributes == OldPopupAttributes) {
  950. OldContents->Attributes = NewPopupAttributes;
  951. } else if (OldContents->Attributes == InvertedOldPopupAttributes) {
  952. OldContents->Attributes = InvertedNewPopupAttributes;
  953. }
  954. OldContents++;
  955. }
  956. }
  957. }
  958. }
  959. }
  960. }
  961. NTSTATUS
  962. SetScreenColors(
  963. IN PSCREEN_INFORMATION ScreenInfo,
  964. IN WORD Attributes,
  965. IN WORD PopupAttributes,
  966. IN BOOL UpdateWholeScreen
  967. )
  968. {
  969. SHORT i,j;
  970. PROW Row;
  971. WORD DefaultAttributes,DefaultPopupAttributes;
  972. PCONSOLE_INFORMATION Console;
  973. COLORREF rgbBk;
  974. COLORREF rgbText;
  975. Console = ScreenInfo->Console;
  976. rgbBk = ConvertAttrToRGB(Console, LOBYTE(Attributes >> 4));
  977. rgbBk = GetNearestColor(Console->hDC, rgbBk);
  978. rgbText = ConvertAttrToRGB(Console, LOBYTE(Attributes));
  979. rgbText = GetNearestColor(Console->hDC, rgbText);
  980. if (ACTIVE_SCREEN_BUFFER(ScreenInfo)) {
  981. SetDCBrushColor(Console->hDC, rgbBk);
  982. SetTextColor(Console->hDC, rgbText);
  983. SetBkColor(Console->hDC, rgbBk);
  984. Console->LastAttributes = Attributes;
  985. SetConsoleBkColor(Console->hWnd, rgbBk);
  986. }
  987. DefaultAttributes = ScreenInfo->Attributes;
  988. DefaultPopupAttributes = ScreenInfo->PopupAttributes;
  989. ScreenInfo->Attributes = Attributes;
  990. ScreenInfo->PopupAttributes = PopupAttributes;
  991. #if defined(FE_IME)
  992. SetUndetermineAttribute( Console );
  993. #endif
  994. if (UpdateWholeScreen && ScreenInfo->Flags & CONSOLE_TEXTMODE_BUFFER) {
  995. WORD InvertedOldPopupAttributes,InvertedNewPopupAttributes;
  996. InvertedOldPopupAttributes = (WORD)(((DefaultPopupAttributes << 4) & 0xf0) |
  997. ((DefaultPopupAttributes >> 4) & 0x0f));
  998. InvertedNewPopupAttributes = (WORD)(((PopupAttributes << 4) & 0xf0) |
  999. ((PopupAttributes >> 4) & 0x0f));
  1000. //
  1001. // change all chars with default color
  1002. //
  1003. for (i=0;i<ScreenInfo->ScreenBufferSize.Y;i++) {
  1004. Row = &ScreenInfo->BufferInfo.TextInfo.Rows[i];
  1005. for (j=0;j<Row->AttrRow.Length;j++) {
  1006. if (Row->AttrRow.Attrs[j].Attr == DefaultAttributes) {
  1007. Row->AttrRow.Attrs[j].Attr = Attributes;
  1008. } else if (Row->AttrRow.Attrs[j].Attr == DefaultPopupAttributes) {
  1009. Row->AttrRow.Attrs[j].Attr = PopupAttributes;
  1010. } else if (Row->AttrRow.Attrs[j].Attr == InvertedOldPopupAttributes) {
  1011. Row->AttrRow.Attrs[j].Attr = InvertedNewPopupAttributes;
  1012. }
  1013. }
  1014. }
  1015. if (Console->PopupCount)
  1016. UpdatePopups(Console,
  1017. Attributes,
  1018. PopupAttributes,
  1019. DefaultAttributes,
  1020. DefaultPopupAttributes
  1021. );
  1022. // force repaint of entire line
  1023. ScreenInfo->BufferInfo.TextInfo.Flags &= ~TEXT_VALID_HINT;
  1024. WriteToScreen(ScreenInfo,&ScreenInfo->Window);
  1025. ScreenInfo->BufferInfo.TextInfo.Flags |= TEXT_VALID_HINT;
  1026. }
  1027. return STATUS_SUCCESS;
  1028. }
  1029. ULONG
  1030. SrvSetConsoleTextAttribute(
  1031. IN OUT PCSR_API_MSG m,
  1032. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1033. )
  1034. {
  1035. PCONSOLE_SETTEXTATTRIBUTE_MSG a = (PCONSOLE_SETTEXTATTRIBUTE_MSG)&m->u.ApiMessageData;
  1036. NTSTATUS Status;
  1037. PCONSOLE_INFORMATION Console;
  1038. PHANDLE_DATA HandleData;
  1039. Status = ApiPreamble(a->ConsoleHandle,
  1040. &Console
  1041. );
  1042. if (!NT_SUCCESS(Status)) {
  1043. return Status;
  1044. }
  1045. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  1046. a->OutputHandle,
  1047. CONSOLE_OUTPUT_HANDLE,
  1048. GENERIC_WRITE,
  1049. &HandleData
  1050. );
  1051. if (NT_SUCCESS(Status)) {
  1052. if (a->Attributes & ~VALID_TEXT_ATTRIBUTES) {
  1053. Status = STATUS_INVALID_PARAMETER;
  1054. } else {
  1055. Status = SetScreenColors(HandleData->Buffer.ScreenBuffer,
  1056. a->Attributes,
  1057. HandleData->Buffer.ScreenBuffer->PopupAttributes,
  1058. FALSE
  1059. );
  1060. }
  1061. }
  1062. UnlockConsole(Console);
  1063. return Status;
  1064. UNREFERENCED_PARAMETER(ReplyStatus);
  1065. }
  1066. ULONG
  1067. SrvSetConsoleFont(
  1068. IN OUT PCSR_API_MSG m,
  1069. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1070. )
  1071. {
  1072. PCONSOLE_SETFONT_MSG a = (PCONSOLE_SETFONT_MSG)&m->u.ApiMessageData;
  1073. NTSTATUS Status;
  1074. PCONSOLE_INFORMATION Console;
  1075. PHANDLE_DATA HandleData;
  1076. PSCREEN_INFORMATION ScreenInfo;
  1077. Status = ApiPreamble(a->ConsoleHandle,
  1078. &Console
  1079. );
  1080. if (!NT_SUCCESS(Status)) {
  1081. return Status;
  1082. }
  1083. try {
  1084. Status = DereferenceIoHandle(CONSOLE_PERPROCESSDATA(),
  1085. a->OutputHandle,
  1086. CONSOLE_OUTPUT_HANDLE,
  1087. GENERIC_WRITE,
  1088. &HandleData
  1089. );
  1090. if (!NT_SUCCESS(Status)) {
  1091. leave;
  1092. }
  1093. ScreenInfo = HandleData->Buffer.ScreenBuffer;
  1094. if (ScreenInfo->Console->FullScreenFlags & CONSOLE_FULLSCREEN) {
  1095. Status = STATUS_FULLSCREEN_MODE;
  1096. } else {
  1097. #if defined(FE_SB)
  1098. Status = SetScreenBufferFont(ScreenInfo,a->FontIndex,ScreenInfo->Console->OutputCP);
  1099. #else
  1100. Status = SetScreenBufferFont(ScreenInfo,a->FontIndex);
  1101. #endif
  1102. }
  1103. } finally {
  1104. UnlockConsole(Console);
  1105. }
  1106. return Status;
  1107. UNREFERENCED_PARAMETER(ReplyStatus);
  1108. }
  1109. ULONG
  1110. SrvSetConsoleIcon(
  1111. IN OUT PCSR_API_MSG m,
  1112. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1113. )
  1114. {
  1115. PCONSOLE_SETICON_MSG a = (PCONSOLE_SETICON_MSG)&m->u.ApiMessageData;
  1116. NTSTATUS Status;
  1117. PCONSOLE_INFORMATION Console;
  1118. HANDLE hIcon;
  1119. Status = ApiPreamble(a->ConsoleHandle,
  1120. &Console
  1121. );
  1122. if (!NT_SUCCESS(Status)) {
  1123. return Status;
  1124. }
  1125. if (a->hIcon == NULL) {
  1126. hIcon = ghDefaultIcon;
  1127. } else {
  1128. hIcon = CopyIcon(a->hIcon);
  1129. }
  1130. if (hIcon == NULL) {
  1131. Status = STATUS_INVALID_PARAMETER;
  1132. } else if (hIcon != Console->hIcon) {
  1133. PostMessage(Console->hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
  1134. if (Console->hIcon != ghDefaultIcon) {
  1135. DestroyIcon(Console->hIcon);
  1136. }
  1137. Console->hIcon = hIcon;
  1138. /*
  1139. * Small icon now
  1140. */
  1141. if (hIcon != ghDefaultIcon) {
  1142. /*
  1143. * The new one is not the default, clean-up
  1144. */
  1145. if (Console->hSmIcon != NULL && Console->hSmIcon != ghDefaultSmIcon) {
  1146. DestroyIcon(Console->hSmIcon);
  1147. }
  1148. Console->hSmIcon = NULL;
  1149. PostMessage(Console->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)NULL);
  1150. } else {
  1151. /*
  1152. * Change to default, so we can use the default small icon
  1153. */
  1154. if (Console->hSmIcon != ghDefaultSmIcon) {
  1155. if (Console->hSmIcon != NULL) {
  1156. DestroyIcon(Console->hSmIcon);
  1157. }
  1158. Console->hSmIcon = ghDefaultSmIcon;
  1159. PostMessage(Console->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)ghDefaultSmIcon);
  1160. }
  1161. }
  1162. }
  1163. UnlockConsole(Console);
  1164. return Status;
  1165. UNREFERENCED_PARAMETER(ReplyStatus);
  1166. }
  1167. ULONG
  1168. SrvSetConsoleCP(
  1169. IN OUT PCSR_API_MSG m,
  1170. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1171. )
  1172. {
  1173. PCONSOLE_SETCP_MSG a = (PCONSOLE_SETCP_MSG)&m->u.ApiMessageData;
  1174. NTSTATUS Status;
  1175. PCONSOLE_INFORMATION Console;
  1176. HANDLE hEvent = NULL;
  1177. Status = ApiPreamble(a->ConsoleHandle,
  1178. &Console
  1179. );
  1180. if (!NT_SUCCESS(Status)) {
  1181. return Status;
  1182. }
  1183. if (a->hEvent) {
  1184. Status = NtDuplicateObject(CONSOLE_CLIENTPROCESSHANDLE(),
  1185. a->hEvent,
  1186. NtCurrentProcess(),
  1187. &hEvent,
  1188. 0,
  1189. FALSE,
  1190. DUPLICATE_SAME_ACCESS
  1191. );
  1192. if (!NT_SUCCESS(Status)) {
  1193. goto SrvSetConsoleCPFailure;
  1194. }
  1195. }
  1196. if (!IsValidCodePage(a->wCodePageID)) {
  1197. Status = STATUS_INVALID_PARAMETER;
  1198. goto SrvSetConsoleCPFailure;
  1199. }
  1200. if ( IsAvailableFarEastCodePage( a->wCodePageID ) &&
  1201. OEMCP != a->wCodePageID )
  1202. {
  1203. Status = STATUS_INVALID_PARAMETER;
  1204. goto SrvSetConsoleCPFailure;
  1205. }
  1206. if ( (a->Output && Console->OutputCP != a->wCodePageID) ||
  1207. (!a->Output && Console->CP != a->wCodePageID) ) {
  1208. UINT CodePage;
  1209. if (a->Output) {
  1210. // Backup old code page
  1211. CodePage = Console->OutputCP;
  1212. // Set new code page
  1213. Console->OutputCP = a->wCodePageID;
  1214. Console->fIsDBCSOutputCP = CONSOLE_IS_DBCS_ENABLED() && IsAvailableFarEastCodePage(Console->OutputCP);
  1215. if (!ReCreateDbcsScreenBuffer(Console, CodePage) ) {
  1216. RIPMSG1(RIP_WARNING, "SrvSetConsoleCP: ReCreateDbcsScreenBuffer failed. Restoring to CP=%d",
  1217. CodePage);
  1218. Console->OutputCP = CodePage;
  1219. Console->fIsDBCSOutputCP = CONSOLE_IS_DBCS_ENABLED() && IsAvailableFarEastCodePage(CodePage);
  1220. Status = STATUS_NO_MEMORY;
  1221. goto SrvSetConsoleCPFailure;
  1222. }
  1223. SetConsoleCPInfo(Console,a->Output);
  1224. Status = QueueConsoleMessage(Console,
  1225. CM_SET_IME_CODEPAGE,
  1226. (WPARAM)hEvent,
  1227. MAKELPARAM(a->Output,CodePage)
  1228. );
  1229. if (!NT_SUCCESS(Status)) {
  1230. goto SrvSetConsoleCPFailure;
  1231. }
  1232. // load special ROM font, if necessary
  1233. #ifdef i386
  1234. if (Console->FullScreenFlags & CONSOLE_FULLSCREEN_HARDWARE) {
  1235. SetROMFontCodePage(Console->OutputCP,
  1236. Console->CurrentScreenBuffer->BufferInfo.TextInfo.ModeIndex);
  1237. WriteRegionToScreenHW(Console->CurrentScreenBuffer,
  1238. &Console->CurrentScreenBuffer->Window);
  1239. }
  1240. #endif
  1241. } else {
  1242. // Backup old code page
  1243. CodePage = Console->CP;
  1244. // Set new code page
  1245. Console->CP = a->wCodePageID;
  1246. Console->fIsDBCSCP = CONSOLE_IS_DBCS_ENABLED() && IsAvailableFarEastCodePage(Console->CP);
  1247. SetConsoleCPInfo(Console,a->Output);
  1248. Status = QueueConsoleMessage(Console,
  1249. CM_SET_IME_CODEPAGE,
  1250. (WPARAM)hEvent,
  1251. MAKELPARAM(a->Output,CodePage)
  1252. );
  1253. if (!NT_SUCCESS(Status)) {
  1254. goto SrvSetConsoleCPFailure;
  1255. }
  1256. }
  1257. }
  1258. else {
  1259. if (hEvent) {
  1260. NtSetEvent(hEvent, NULL);
  1261. NtClose(hEvent);
  1262. }
  1263. }
  1264. UnlockConsole(Console);
  1265. return STATUS_SUCCESS;
  1266. SrvSetConsoleCPFailure:
  1267. if (hEvent) {
  1268. NtSetEvent(hEvent, NULL);
  1269. NtClose(hEvent);
  1270. }
  1271. UnlockConsole(Console);
  1272. return Status;
  1273. UNREFERENCED_PARAMETER(ReplyStatus);
  1274. }
  1275. ULONG
  1276. SrvGetConsoleCP(
  1277. IN OUT PCSR_API_MSG m,
  1278. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1279. )
  1280. {
  1281. PCONSOLE_GETCP_MSG a = (PCONSOLE_GETCP_MSG)&m->u.ApiMessageData;
  1282. NTSTATUS Status;
  1283. PCONSOLE_INFORMATION Console;
  1284. Status = ApiPreamble(a->ConsoleHandle,
  1285. &Console
  1286. );
  1287. if (!NT_SUCCESS(Status)) {
  1288. return Status;
  1289. }
  1290. if (a->Output) {
  1291. a->wCodePageID = Console->OutputCP;
  1292. } else {
  1293. a->wCodePageID = Console->CP;
  1294. }
  1295. UnlockConsole(Console);
  1296. return STATUS_SUCCESS;
  1297. UNREFERENCED_PARAMETER(ReplyStatus);
  1298. }
  1299. ULONG
  1300. SrvGetConsoleKeyboardLayoutName(
  1301. IN OUT PCSR_API_MSG m,
  1302. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1303. )
  1304. {
  1305. PCONSOLE_GETKEYBOARDLAYOUTNAME_MSG a = (PCONSOLE_GETKEYBOARDLAYOUTNAME_MSG)&m->u.ApiMessageData;
  1306. NTSTATUS Status;
  1307. PCONSOLE_INFORMATION Console;
  1308. Status = ApiPreamble(a->ConsoleHandle,
  1309. &Console
  1310. );
  1311. if (!NT_SUCCESS(Status)) {
  1312. return Status;
  1313. }
  1314. if (Console->hklActive == NULL) {
  1315. //
  1316. // hklActive is not set yet. Let's initialize it here.
  1317. //
  1318. extern void GetNonBiDiKeyboardLayout(HKL * phklActive);
  1319. RIPMSG1(RIP_WARNING, "SrvGetConsoleKeyboardLayoutName: hklActive is not initialized. pCon=%p", Console);
  1320. SystemParametersInfo(SPI_GETDEFAULTINPUTLANG, 0, &Console->hklActive, FALSE);
  1321. GetNonBiDiKeyboardLayout(&Console->hklActive);
  1322. }
  1323. ActivateKeyboardLayout(Console->hklActive, 0);
  1324. if (a->bAnsi) {
  1325. GetKeyboardLayoutNameA(a->achLayout);
  1326. } else {
  1327. GetKeyboardLayoutNameW(a->awchLayout);
  1328. }
  1329. UnlockConsole(Console);
  1330. return STATUS_SUCCESS;
  1331. UNREFERENCED_PARAMETER(ReplyStatus);
  1332. }
  1333. ULONG
  1334. SrvGetConsoleWindow(
  1335. IN OUT PCSR_API_MSG m,
  1336. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1337. )
  1338. {
  1339. PCONSOLE_GETCONSOLEWINDOW_MSG a = (PCONSOLE_GETCONSOLEWINDOW_MSG)&m->u.ApiMessageData;
  1340. NTSTATUS Status;
  1341. PCONSOLE_INFORMATION Console;
  1342. Status = ApiPreamble(a->ConsoleHandle,
  1343. &Console
  1344. );
  1345. if (!NT_SUCCESS(Status)) {
  1346. return Status;
  1347. }
  1348. a->hwnd = Console->hWnd;
  1349. UnlockConsole(Console);
  1350. return STATUS_SUCCESS;
  1351. UNREFERENCED_PARAMETER(ReplyStatus);
  1352. }
  1353. ULONG
  1354. SrvGetConsoleProcessList(
  1355. IN OUT PCSR_API_MSG m,
  1356. IN OUT PCSR_REPLY_STATUS ReplyStatus
  1357. )
  1358. {
  1359. PCONSOLE_INFORMATION Console = NULL;
  1360. NTSTATUS Status;
  1361. PCONSOLE_PROCESS_HANDLE ProcessHandleRecord;
  1362. PLIST_ENTRY ListHead, ListNext;
  1363. PCONSOLE_GETCONSOLEPROCESSLIST_MSG a = (PCONSOLE_GETCONSOLEPROCESSLIST_MSG)&m->u.ApiMessageData;
  1364. DWORD dwProcessCount = 0;
  1365. LPDWORD lpdwProcessList;
  1366. Status = ApiPreamble(a->ConsoleHandle,
  1367. &Console
  1368. );
  1369. if (!NT_SUCCESS(Status)) {
  1370. goto Cleanup;
  1371. }
  1372. if (!CsrValidateMessageBuffer(m, &a->lpdwProcessList, a->dwProcessCount, sizeof(*a->lpdwProcessList))) {
  1373. Status = STATUS_INVALID_PARAMETER;
  1374. goto Cleanup;
  1375. }
  1376. lpdwProcessList = a->lpdwProcessList;
  1377. /*
  1378. * Run through the console's process list to determine if the user-supplied
  1379. * buffer is big enough to contain them all. This is requires that we make
  1380. * two passes over the data, but it allows this function to have the same
  1381. * semantics as GetProcessHeaps().
  1382. */
  1383. ListHead = &Console->ProcessHandleList;
  1384. ListNext = ListHead->Flink;
  1385. while (ListNext != ListHead) {
  1386. ++dwProcessCount;
  1387. ListNext = ListNext->Flink;
  1388. }
  1389. /*
  1390. * At this point we can't fail, so set the status accordingly.
  1391. */
  1392. Status = STATUS_SUCCESS;
  1393. /*
  1394. * There's not enough space in the array to hold all the pids, so we'll
  1395. * inform the user of that by returning a number > than a->dwProcessCount
  1396. * (but we still return STATUS_SUCCESS).
  1397. */
  1398. if (dwProcessCount > a->dwProcessCount) {
  1399. goto Cleanup;
  1400. }
  1401. /*
  1402. * Loop over the list of processes again and fill in the caller's buffer.
  1403. */
  1404. ListNext = ListHead->Flink;
  1405. while (ListNext != ListHead) {
  1406. ProcessHandleRecord = CONTAINING_RECORD( ListNext, CONSOLE_PROCESS_HANDLE, ListLink );
  1407. *lpdwProcessList++ = HandleToUlong(ProcessHandleRecord->Process->ClientId.UniqueProcess);
  1408. ListNext = ListNext->Flink;
  1409. }
  1410. Cleanup:
  1411. a->dwProcessCount = dwProcessCount;
  1412. if (Console != NULL) {
  1413. UnlockConsole(Console);
  1414. }
  1415. return Status;
  1416. UNREFERENCED_PARAMETER(ReplyStatus);
  1417. }