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