[CONSOLE][CONSRV]
[reactos.git] / win32ss / user / winsrv / consrv / frontends / gui / guisettings.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/frontends/gui/guisettings.c
5 * PURPOSE: GUI Terminal Front-End Settings Management
6 * PROGRAMMERS: Johannes Anderwald
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include <consrv.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 #include "guiterm.h"
18 #include "guisettings.h"
19
20 VOID GuiConsoleMoveWindow(PGUI_CONSOLE_DATA GuiData);
21 VOID SwitchFullScreen(PGUI_CONSOLE_DATA GuiData, BOOL FullScreen);
22
23 /* FUNCTIONS ******************************************************************/
24
25 BOOL
26 GuiConsoleReadUserSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
27 IN LPCWSTR ConsoleTitle,
28 IN DWORD ProcessId)
29 {
30 /*****************************************************
31 * Adapted from ConSrvReadUserSettings in settings.c *
32 *****************************************************/
33
34 BOOL RetVal = FALSE;
35 HKEY hKey;
36 DWORD dwNumSubKeys = 0;
37 DWORD dwIndex;
38 DWORD dwType;
39 WCHAR szValueName[MAX_PATH];
40 DWORD dwValueName;
41 WCHAR szValue[LF_FACESIZE] = L"\0";
42 DWORD Value;
43 DWORD dwValue;
44
45 if (!ConSrvOpenUserSettings(ProcessId,
46 ConsoleTitle,
47 &hKey, KEY_READ,
48 FALSE))
49 {
50 DPRINT("ConSrvOpenUserSettings failed\n");
51 return FALSE;
52 }
53
54 if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
55 &dwNumSubKeys, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
56 {
57 DPRINT("GuiConsoleReadUserSettings: RegQueryInfoKey failed\n");
58 RegCloseKey(hKey);
59 return FALSE;
60 }
61
62 DPRINT("GuiConsoleReadUserSettings entered dwNumSubKeys %d\n", dwNumSubKeys);
63
64 for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++)
65 {
66 dwValue = sizeof(Value);
67 dwValueName = MAX_PATH; // sizeof(szValueName)/sizeof(szValueName[0])
68
69 if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS)
70 {
71 if (dwType == REG_SZ)
72 {
73 /*
74 * Retry in case of string value
75 */
76 dwValue = sizeof(szValue);
77 dwValueName = MAX_PATH; // sizeof(szValueName)/sizeof(szValueName[0])
78 if (RegEnumValueW(hKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS)
79 break;
80 }
81 else
82 {
83 break;
84 }
85 }
86
87 if (!wcscmp(szValueName, L"FaceName"))
88 {
89 SIZE_T Length = min(wcslen(szValue) + 1, LF_FACESIZE); // wcsnlen
90 wcsncpy(TermInfo->FaceName, szValue, LF_FACESIZE);
91 TermInfo->FaceName[Length] = L'\0';
92 RetVal = TRUE;
93 }
94 else if (!wcscmp(szValueName, L"FontFamily"))
95 {
96 TermInfo->FontFamily = Value;
97 RetVal = TRUE;
98 }
99 else if (!wcscmp(szValueName, L"FontSize"))
100 {
101 TermInfo->FontSize.X = LOWORD(Value);
102 TermInfo->FontSize.Y = HIWORD(Value);
103 RetVal = TRUE;
104 }
105 else if (!wcscmp(szValueName, L"FontWeight"))
106 {
107 TermInfo->FontWeight = Value;
108 RetVal = TRUE;
109 }
110 else if (!wcscmp(szValueName, L"FullScreen"))
111 {
112 TermInfo->FullScreen = Value;
113 RetVal = TRUE;
114 }
115 else if (!wcscmp(szValueName, L"WindowPosition"))
116 {
117 TermInfo->AutoPosition = FALSE;
118 TermInfo->WindowOrigin.x = LOWORD(Value);
119 TermInfo->WindowOrigin.y = HIWORD(Value);
120 RetVal = TRUE;
121 }
122 }
123
124 RegCloseKey(hKey);
125 return RetVal;
126 }
127
128 BOOL
129 GuiConsoleWriteUserSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
130 IN LPCWSTR ConsoleTitle,
131 IN DWORD ProcessId)
132 {
133 /******************************************************
134 * Adapted from ConSrvWriteUserSettings in settings.c *
135 ******************************************************/
136
137 BOOL GlobalSettings = (ConsoleTitle[0] == L'\0');
138 HKEY hKey;
139 DWORD Storage = 0;
140
141 #define SetConsoleSetting(SettingName, SettingType, SettingSize, Setting, DefaultValue) \
142 do { \
143 if (GlobalSettings || (!GlobalSettings && (*(Setting) != (DefaultValue)))) \
144 { \
145 RegSetValueExW(hKey, (SettingName), 0, (SettingType), (PBYTE)(Setting), (SettingSize)); \
146 } \
147 else \
148 { \
149 RegDeleteValue(hKey, (SettingName)); \
150 } \
151 } while (0)
152
153 if (!ConSrvOpenUserSettings(ProcessId,
154 ConsoleTitle,
155 &hKey, KEY_WRITE,
156 TRUE))
157 {
158 return FALSE;
159 }
160
161 SetConsoleSetting(L"FaceName", REG_SZ, (wcslen(TermInfo->FaceName) + 1) * sizeof(WCHAR), TermInfo->FaceName, L'\0'); // wcsnlen
162 SetConsoleSetting(L"FontFamily", REG_DWORD, sizeof(DWORD), &TermInfo->FontFamily, FF_DONTCARE);
163
164 Storage = MAKELONG(TermInfo->FontSize.X, TermInfo->FontSize.Y);
165 SetConsoleSetting(L"FontSize", REG_DWORD, sizeof(DWORD), &Storage, 0);
166
167 SetConsoleSetting(L"FontWeight", REG_DWORD, sizeof(DWORD), &TermInfo->FontWeight, FW_DONTCARE);
168
169 Storage = TermInfo->FullScreen;
170 SetConsoleSetting(L"FullScreen", REG_DWORD, sizeof(DWORD), &Storage, FALSE);
171
172 if (TermInfo->AutoPosition == FALSE)
173 {
174 Storage = MAKELONG(TermInfo->WindowOrigin.x, TermInfo->WindowOrigin.y);
175 RegSetValueExW(hKey, L"WindowPosition", 0, REG_DWORD, (PBYTE)&Storage, sizeof(DWORD));
176 }
177 else
178 {
179 RegDeleteValue(hKey, L"WindowPosition");
180 }
181
182 RegCloseKey(hKey);
183 return TRUE;
184 }
185
186 VOID
187 GuiConsoleGetDefaultSettings(IN OUT PGUI_CONSOLE_INFO TermInfo,
188 IN DWORD ProcessId)
189 {
190 /*******************************************************
191 * Adapted from ConSrvGetDefaultSettings in settings.c *
192 *******************************************************/
193
194 if (TermInfo == NULL) return;
195
196 /*
197 * 1. Load the default values
198 */
199 // wcsncpy(TermInfo->FaceName, L"DejaVu Sans Mono", LF_FACESIZE);
200 // TermInfo->FontSize = MAKELONG(12, 8); // 0x0008000C; // font is 8x12
201 // TermInfo->FontSize = MAKELONG(16, 16); // font is 16x16
202 // TermInfo->FontWeight = FW_NORMAL;
203
204 wcsncpy(TermInfo->FaceName, L"VGA", LF_FACESIZE); // HACK: !!
205 // TermInfo->FaceName[0] = L'\0';
206 TermInfo->FontFamily = FF_DONTCARE;
207 TermInfo->FontSize.X = 0;
208 TermInfo->FontSize.Y = 0;
209 TermInfo->FontWeight = FW_DONTCARE;
210 TermInfo->UseRasterFonts = TRUE;
211
212 TermInfo->FullScreen = FALSE;
213 TermInfo->ShowWindow = SW_SHOWNORMAL;
214 TermInfo->AutoPosition = TRUE;
215 TermInfo->WindowOrigin.x = 0;
216 TermInfo->WindowOrigin.y = 0;
217
218 /*
219 * 2. Overwrite them with the ones stored in HKCU\Console.
220 * If the HKCU\Console key doesn't exist, create it
221 * and store the default values inside.
222 */
223 if (!GuiConsoleReadUserSettings(TermInfo, L"", ProcessId))
224 {
225 GuiConsoleWriteUserSettings(TermInfo, L"", ProcessId);
226 }
227 }
228
229 VOID
230 GuiConsoleShowConsoleProperties(PGUI_CONSOLE_DATA GuiData,
231 BOOL Defaults)
232 {
233 NTSTATUS Status;
234 PCONSOLE Console = GuiData->Console;
235 PCONSOLE_SCREEN_BUFFER ActiveBuffer = GuiData->ActiveBuffer;
236 PCONSOLE_PROCESS_DATA ProcessData;
237 HANDLE hSection = NULL, hClientSection = NULL;
238 LARGE_INTEGER SectionSize;
239 ULONG ViewSize = 0;
240 SIZE_T Length = 0;
241 PCONSOLE_PROPS pSharedInfo = NULL;
242 PGUI_CONSOLE_INFO GuiInfo = NULL;
243
244 DPRINT("GuiConsoleShowConsoleProperties entered\n");
245
246 if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
247
248 /*
249 * Create a memory section to share with the applet, and map it.
250 */
251 /* Holds data for console.dll + console info + terminal-specific info */
252 SectionSize.QuadPart = sizeof(CONSOLE_PROPS) + sizeof(GUI_CONSOLE_INFO);
253 Status = NtCreateSection(&hSection,
254 SECTION_ALL_ACCESS,
255 NULL,
256 &SectionSize,
257 PAGE_READWRITE,
258 SEC_COMMIT,
259 NULL);
260 if (!NT_SUCCESS(Status))
261 {
262 DPRINT1("Error: Impossible to create a shared section ; Status = %lu\n", Status);
263 goto Quit;
264 }
265
266 Status = NtMapViewOfSection(hSection,
267 NtCurrentProcess(),
268 (PVOID*)&pSharedInfo,
269 0,
270 0,
271 NULL,
272 &ViewSize,
273 ViewUnmap,
274 0,
275 PAGE_READWRITE);
276 if (!NT_SUCCESS(Status))
277 {
278 DPRINT1("Error: Impossible to map the shared section ; Status = %lu\n", Status);
279 goto Quit;
280 }
281
282
283 /*
284 * Setup the shared console properties structure.
285 */
286
287 /* Header */
288 pSharedInfo->hConsoleWindow = GuiData->hWindow;
289 pSharedInfo->ShowDefaultParams = Defaults;
290
291 /*
292 * We fill-in the fields only if we display
293 * our properties, not the default ones.
294 */
295 if (!Defaults)
296 {
297 /* Console information */
298 pSharedInfo->ci.HistoryBufferSize = Console->HistoryBufferSize;
299 pSharedInfo->ci.NumberOfHistoryBuffers = Console->NumberOfHistoryBuffers;
300 pSharedInfo->ci.HistoryNoDup = Console->HistoryNoDup;
301 pSharedInfo->ci.QuickEdit = Console->QuickEdit;
302 pSharedInfo->ci.InsertMode = Console->InsertMode;
303 pSharedInfo->ci.InputBufferSize = 0;
304 pSharedInfo->ci.ScreenBufferSize = ActiveBuffer->ScreenBufferSize;
305 pSharedInfo->ci.ConsoleSize = ActiveBuffer->ViewSize;
306 pSharedInfo->ci.CursorBlinkOn;
307 pSharedInfo->ci.ForceCursorOff;
308 pSharedInfo->ci.CursorSize = ActiveBuffer->CursorInfo.dwSize;
309 if (GetType(ActiveBuffer) == TEXTMODE_BUFFER)
310 {
311 PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer;
312
313 pSharedInfo->ci.ScreenAttrib = Buffer->ScreenDefaultAttrib;
314 pSharedInfo->ci.PopupAttrib = Buffer->PopupDefaultAttrib;
315 }
316 else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER)
317 {
318 // PGRAPHICS_SCREEN_BUFFER Buffer = (PGRAPHICS_SCREEN_BUFFER)ActiveBuffer;
319 DPRINT1("GuiConsoleShowConsoleProperties - Graphics buffer\n");
320
321 // FIXME: Gather defaults from the registry ?
322 pSharedInfo->ci.ScreenAttrib = DEFAULT_SCREEN_ATTRIB;
323 pSharedInfo->ci.PopupAttrib = DEFAULT_POPUP_ATTRIB ;
324 }
325 pSharedInfo->ci.CodePage;
326
327 /* GUI Information */
328 pSharedInfo->TerminalInfo.Size = sizeof(GUI_CONSOLE_INFO);
329 GuiInfo = pSharedInfo->TerminalInfo.TermInfo = (PGUI_CONSOLE_INFO)(pSharedInfo + 1);
330 Length = min(wcslen(GuiData->GuiInfo.FaceName) + 1, LF_FACESIZE); // wcsnlen
331 wcsncpy(GuiInfo->FaceName, GuiData->GuiInfo.FaceName, LF_FACESIZE);
332 GuiInfo->FaceName[Length] = L'\0';
333 GuiInfo->FontFamily = GuiData->GuiInfo.FontFamily;
334 GuiInfo->FontSize = GuiData->GuiInfo.FontSize;
335 GuiInfo->FontWeight = GuiData->GuiInfo.FontWeight;
336 GuiInfo->UseRasterFonts = GuiData->GuiInfo.UseRasterFonts;
337 GuiInfo->FullScreen = GuiData->GuiInfo.FullScreen;
338 GuiInfo->AutoPosition = GuiData->GuiInfo.AutoPosition;
339 GuiInfo->WindowOrigin = GuiData->GuiInfo.WindowOrigin;
340 /* Offsetize */
341 pSharedInfo->TerminalInfo.TermInfo = (PVOID)((ULONG_PTR)GuiInfo - (ULONG_PTR)pSharedInfo);
342
343 /* Palette */
344 memcpy(pSharedInfo->ci.Colors, Console->Colors, sizeof(Console->Colors));
345
346 /* Title of the console, original one corresponding to the one set by the console leader */
347 Length = min(sizeof(pSharedInfo->ci.ConsoleTitle) / sizeof(pSharedInfo->ci.ConsoleTitle[0]) - 1,
348 Console->OriginalTitle.Length / sizeof(WCHAR));
349 wcsncpy(pSharedInfo->ci.ConsoleTitle, Console->OriginalTitle.Buffer, Length);
350 }
351 else
352 {
353 Length = 0;
354 // FIXME: Load the default parameters from the registry.
355 }
356
357 /* Null-terminate the title */
358 pSharedInfo->ci.ConsoleTitle[Length] = L'\0';
359
360
361 /* Unmap the view */
362 NtUnmapViewOfSection(NtCurrentProcess(), pSharedInfo);
363
364 /* Get the console leader process, our client */
365 ProcessData = ConSrvGetConsoleLeaderProcess(Console);
366
367 /* Duplicate the section handle for the client */
368 Status = NtDuplicateObject(NtCurrentProcess(),
369 hSection,
370 ProcessData->Process->ProcessHandle,
371 &hClientSection,
372 0, 0, DUPLICATE_SAME_ACCESS);
373 if (!NT_SUCCESS(Status))
374 {
375 DPRINT1("Error: Impossible to duplicate section handle for client ; Status = %lu\n", Status);
376 goto Quit;
377 }
378
379 /* Start the properties dialog */
380 if (ProcessData->PropDispatcher)
381 {
382 _SEH2_TRY
383 {
384 HANDLE Thread = NULL;
385
386 _SEH2_TRY
387 {
388 Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
389 ProcessData->PropDispatcher,
390 (PVOID)hClientSection, 0, NULL);
391 if (NULL == Thread)
392 {
393 DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
394 }
395 else
396 {
397 DPRINT("ProcessData->PropDispatcher remote thread creation succeeded, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
398 /// WaitForSingleObject(Thread, INFINITE);
399 }
400 }
401 _SEH2_FINALLY
402 {
403 CloseHandle(Thread);
404 }
405 _SEH2_END;
406 }
407 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
408 {
409 Status = _SEH2_GetExceptionCode();
410 DPRINT1("GuiConsoleShowConsoleProperties - Caught an exception, Status = %08X\n", Status);
411 }
412 _SEH2_END;
413 }
414
415 Quit:
416 /* We have finished, close the section handle */
417 if (hSection) NtClose(hSection);
418
419 LeaveCriticalSection(&Console->Lock);
420 return;
421 }
422
423 VOID
424 GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
425 HANDLE hClientSection,
426 BOOL SaveSettings)
427 {
428 NTSTATUS Status = STATUS_SUCCESS;
429 PCONSOLE Console = GuiData->Console;
430 PCONSOLE_PROCESS_DATA ProcessData;
431 HANDLE hSection = NULL;
432 ULONG ViewSize = 0;
433 PCONSOLE_PROPS pConInfo = NULL;
434 PCONSOLE_INFO ConInfo = NULL;
435 PTERMINAL_INFO TermInfo = NULL;
436 PGUI_CONSOLE_INFO GuiInfo = NULL;
437
438 if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
439
440 /* Get the console leader process, our client */
441 ProcessData = ConSrvGetConsoleLeaderProcess(Console);
442
443 /* Duplicate the section handle for ourselves */
444 Status = NtDuplicateObject(ProcessData->Process->ProcessHandle,
445 hClientSection,
446 NtCurrentProcess(),
447 &hSection,
448 0, 0, DUPLICATE_SAME_ACCESS);
449 if (!NT_SUCCESS(Status))
450 {
451 DPRINT1("Error when mapping client handle, Status = %lu\n", Status);
452 goto Quit;
453 }
454
455 /* Get a view of the shared section */
456 Status = NtMapViewOfSection(hSection,
457 NtCurrentProcess(),
458 (PVOID*)&pConInfo,
459 0,
460 0,
461 NULL,
462 &ViewSize,
463 ViewUnmap,
464 0,
465 PAGE_READWRITE);
466 if (!NT_SUCCESS(Status))
467 {
468 DPRINT1("Error when mapping view of file, Status = %lu\n", Status);
469 goto Quit;
470 }
471
472 _SEH2_TRY
473 {
474 /* Check that the section is well-sized */
475 if ( (ViewSize < sizeof(CONSOLE_PROPS)) ||
476 (pConInfo->TerminalInfo.Size != sizeof(GUI_CONSOLE_INFO)) ||
477 (ViewSize < sizeof(CONSOLE_PROPS) + pConInfo->TerminalInfo.Size) )
478 {
479 DPRINT1("Error: section bad-sized: sizeof(Section) < sizeof(CONSOLE_PROPS) + sizeof(Terminal_specific_info)\n");
480 Status = STATUS_INVALID_VIEW_SIZE;
481 _SEH2_YIELD(goto Quit);
482 }
483
484 // TODO: Check that GuiData->hWindow == pConInfo->hConsoleWindow
485
486 /* Retrieve terminal informations */
487 ConInfo = &pConInfo->ci;
488 TermInfo = &pConInfo->TerminalInfo;
489 GuiInfo = TermInfo->TermInfo = (PVOID)((ULONG_PTR)pConInfo + (ULONG_PTR)TermInfo->TermInfo);
490
491 /*
492 * If we don't set the default parameters,
493 * apply them, otherwise just save them.
494 */
495 if (pConInfo->ShowDefaultParams == FALSE)
496 {
497 /* Set the console informations */
498 ConSrvApplyUserSettings(Console, ConInfo);
499
500 /* Set the terminal informations */
501
502 // memcpy(&GuiData->GuiInfo, GuiInfo, sizeof(GUI_CONSOLE_INFO));
503
504 /* Move the window to the user's values */
505 GuiData->GuiInfo.AutoPosition = GuiInfo->AutoPosition;
506 GuiData->GuiInfo.WindowOrigin = GuiInfo->WindowOrigin;
507 GuiConsoleMoveWindow(GuiData);
508
509 InvalidateRect(GuiData->hWindow, NULL, TRUE);
510
511 /*
512 * Apply full-screen mode.
513 */
514 if (GuiInfo->FullScreen != GuiData->GuiInfo.FullScreen)
515 {
516 SwitchFullScreen(GuiData, GuiInfo->FullScreen);
517 }
518 }
519
520 /*
521 * Save settings if needed
522 */
523 // FIXME: Do it in the console properties applet ??
524 if (SaveSettings)
525 {
526 DWORD ProcessId = HandleToUlong(ProcessData->Process->ClientId.UniqueProcess);
527 ConSrvWriteUserSettings(ConInfo, ProcessId);
528 GuiConsoleWriteUserSettings(GuiInfo, ConInfo->ConsoleTitle, ProcessId);
529 }
530
531 Status = STATUS_SUCCESS;
532 }
533 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
534 {
535 Status = _SEH2_GetExceptionCode();
536 DPRINT1("GuiApplyUserSettings - Caught an exception, Status = %08X\n", Status);
537 }
538 _SEH2_END;
539
540 Quit:
541 /* Finally, close the section and return */
542 if (hSection)
543 {
544 NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
545 NtClose(hSection);
546 }
547
548 LeaveCriticalSection(&Console->Lock);
549 return;
550 }
551
552 /*
553 * Function for dealing with the undocumented message and structure used by
554 * Windows' console.dll for setting console info.
555 * See http://www.catch22.net/sites/default/source/files/setconsoleinfo.c
556 * and http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf
557 * for more information.
558 */
559 VOID
560 GuiApplyWindowsConsoleSettings(PGUI_CONSOLE_DATA GuiData,
561 HANDLE hClientSection)
562 {
563 NTSTATUS Status = STATUS_SUCCESS;
564 PCONSOLE Console = GuiData->Console;
565 PCONSOLE_PROCESS_DATA ProcessData;
566 HANDLE hSection = NULL;
567 ULONG ViewSize = 0;
568 PCONSOLE_STATE_INFO pConInfo = NULL;
569 CONSOLE_INFO ConInfo;
570 GUI_CONSOLE_INFO GuiInfo;
571 SIZE_T Length;
572
573 if (!ConDrvValidateConsoleUnsafe(Console, CONSOLE_RUNNING, TRUE)) return;
574
575 /* Get the console leader process, our client */
576 ProcessData = ConSrvGetConsoleLeaderProcess(Console);
577
578 /* Duplicate the section handle for ourselves */
579 Status = NtDuplicateObject(ProcessData->Process->ProcessHandle,
580 hClientSection,
581 NtCurrentProcess(),
582 &hSection,
583 0, 0, DUPLICATE_SAME_ACCESS);
584 if (!NT_SUCCESS(Status))
585 {
586 DPRINT1("Error when mapping client handle, Status = %lu\n", Status);
587 goto Quit;
588 }
589
590 /* Get a view of the shared section */
591 Status = NtMapViewOfSection(hSection,
592 NtCurrentProcess(),
593 (PVOID*)&pConInfo,
594 0,
595 0,
596 NULL,
597 &ViewSize,
598 ViewUnmap,
599 0,
600 PAGE_READWRITE);
601 if (!NT_SUCCESS(Status))
602 {
603 DPRINT1("Error when mapping view of file, Status = %lu\n", Status);
604 goto Quit;
605 }
606
607 _SEH2_TRY
608 {
609 /* Check that the section is well-sized */
610 if ( (ViewSize < sizeof(CONSOLE_STATE_INFO)) ||
611 (pConInfo->cbSize != sizeof(CONSOLE_STATE_INFO)) )
612 {
613 DPRINT1("Error: section bad-sized: sizeof(Section) < sizeof(CONSOLE_STATE_INFO)\n");
614 Status = STATUS_INVALID_VIEW_SIZE;
615 _SEH2_YIELD(goto Quit);
616 }
617
618 // TODO: Check that GuiData->hWindow == pConInfo->hConsoleWindow
619
620 /* Retrieve terminal informations */
621
622 // Console information
623 ConInfo.HistoryBufferSize = pConInfo->HistoryBufferSize;
624 ConInfo.NumberOfHistoryBuffers = pConInfo->NumberOfHistoryBuffers;
625 ConInfo.HistoryNoDup = !!pConInfo->HistoryNoDup;
626 ConInfo.QuickEdit = !!pConInfo->QuickEdit;
627 ConInfo.InsertMode = !!pConInfo->InsertMode;
628 ConInfo.ScreenBufferSize = pConInfo->ScreenBufferSize;
629 ConInfo.ConsoleSize = pConInfo->WindowSize;
630 ConInfo.CursorSize = pConInfo->CursorSize;
631 ConInfo.ScreenAttrib = pConInfo->ScreenColors;
632 ConInfo.PopupAttrib = pConInfo->PopupColors;
633 memcpy(&ConInfo.Colors, pConInfo->ColorTable, sizeof(ConInfo.Colors));
634 ConInfo.CodePage = pConInfo->CodePage;
635 /**ConInfo.ConsoleTitle[MAX_PATH + 1] = pConInfo->ConsoleTitle; // FIXME: memcpy**/
636 #if 0
637 /* Title of the console, original one corresponding to the one set by the console leader */
638 Length = min(sizeof(pConInfo->ConsoleTitle) / sizeof(pConInfo->ConsoleTitle[0]) - 1,
639 Console->OriginalTitle.Length / sizeof(WCHAR));
640 wcsncpy(pSharedInfo->ci.ConsoleTitle, Console->OriginalTitle.Buffer, Length);
641 #endif
642 // ULONG ConInfo.InputBufferSize = pConInfo->
643 // BOOLEAN ConInfo.CursorBlinkOn = pConInfo->
644 // BOOLEAN ConInfo.ForceCursorOff = pConInfo->
645
646
647 // Terminal information
648 Length = min(wcslen(pConInfo->FaceName) + 1, LF_FACESIZE); // wcsnlen
649 wcsncpy(GuiInfo.FaceName, pConInfo->FaceName, LF_FACESIZE);
650 GuiInfo.FaceName[Length] = L'\0';
651
652 GuiInfo.FontFamily = pConInfo->FontFamily;
653 GuiInfo.FontSize = pConInfo->FontSize;
654 GuiInfo.FontWeight = pConInfo->FontWeight;
655 GuiInfo.FullScreen = !!pConInfo->FullScreen;
656 GuiInfo.AutoPosition = !!pConInfo->AutoPosition;
657 GuiInfo.WindowOrigin = pConInfo->WindowPosition;
658 // BOOL GuiInfo.UseRasterFonts = pConInfo->
659 // WORD GuiInfo.ShowWindow = pConInfo->
660
661
662
663 /*
664 * If we don't set the default parameters,
665 * apply them, otherwise just save them.
666 */
667 #if 0
668 if (pConInfo->ShowDefaultParams == FALSE)
669 #endif
670 {
671 /* Set the console informations */
672 ConSrvApplyUserSettings(Console, &ConInfo);
673
674 /* Set the terminal informations */
675
676 // memcpy(&GuiData->GuiInfo, &GuiInfo, sizeof(GUI_CONSOLE_INFO));
677
678 /* Move the window to the user's values */
679 GuiData->GuiInfo.AutoPosition = GuiInfo.AutoPosition;
680 GuiData->GuiInfo.WindowOrigin = GuiInfo.WindowOrigin;
681 GuiConsoleMoveWindow(GuiData);
682
683 InvalidateRect(GuiData->hWindow, NULL, TRUE);
684
685 /*
686 * Apply full-screen mode.
687 */
688 if (GuiInfo.FullScreen != GuiData->GuiInfo.FullScreen)
689 {
690 SwitchFullScreen(GuiData, GuiInfo.FullScreen);
691 }
692 }
693
694 #if 0
695 /*
696 * Save settings if needed
697 */
698 // FIXME: Do it in the console properties applet ??
699 if (SaveSettings)
700 {
701 DWORD ProcessId = HandleToUlong(ProcessData->Process->ClientId.UniqueProcess);
702 ConSrvWriteUserSettings(&ConInfo, ProcessId);
703 GuiConsoleWriteUserSettings(&GuiInfo, ConInfo.ConsoleTitle, ProcessId);
704 }
705 #endif
706
707 Status = STATUS_SUCCESS;
708 }
709 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
710 {
711 Status = _SEH2_GetExceptionCode();
712 DPRINT1("GuiApplyUserSettings - Caught an exception, Status = %08X\n", Status);
713 }
714 _SEH2_END;
715
716 Quit:
717 /* Finally, close the section and return */
718 if (hSection)
719 {
720 NtUnmapViewOfSection(NtCurrentProcess(), pConInfo);
721 NtClose(hSection);
722 }
723
724 LeaveCriticalSection(&Console->Lock);
725 return;
726 }
727
728 /* EOF */