1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS Console Server DLL 4 * FILE: win32ss/user/winsrv/consrv/settings.c 5 * PURPOSE: Console settings management 6 * PROGRAMMERS: Johannes Anderwald 7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr) 8 */ 9 10 /* INCLUDES *******************************************************************/ 11 12 #include "consrv.h" 13 #include "history.h" 14 #include "../concfg/font.h" 15 16 #define NDEBUG 17 #include <debug.h> 18 19 /* GLOBALS ********************************************************************/ 20 21 extern const COLORREF s_Colors[16]; 22 23 24 /* FUNCTIONS ******************************************************************/ 25 26 NTSTATUS NTAPI 27 ConDrvChangeScreenBufferAttributes(IN PCONSOLE Console, 28 IN PTEXTMODE_SCREEN_BUFFER Buffer, 29 IN USHORT NewScreenAttrib, 30 IN USHORT NewPopupAttrib); 31 /* 32 * NOTE: This function explicitly references Console->ActiveBuffer. 33 * It is possible that it should go into some frontend... 34 */ 35 VOID 36 ConSrvApplyUserSettings( 37 IN PCONSRV_CONSOLE Console, 38 IN PCONSOLE_STATE_INFO ConsoleInfo) 39 { 40 PCONSOLE_SCREEN_BUFFER ActiveBuffer = Console->ActiveBuffer; 41 42 /* 43 * Apply terminal-edition settings: 44 * - QuickEdit and Insert modes, 45 * - History settings. 46 */ 47 Console->QuickEdit = !!ConsoleInfo->QuickEdit; 48 Console->InsertMode = !!ConsoleInfo->InsertMode; 49 /// Console->InputBufferSize = 0; 50 HistoryReshapeAllBuffers(Console, 51 ConsoleInfo->HistoryBufferSize, 52 ConsoleInfo->NumberOfHistoryBuffers, 53 ConsoleInfo->HistoryNoDup); 54 55 /* Copy the new console palette */ 56 // FIXME: Possible buffer overflow if s_colors is bigger than ConsoleInfo->ColorTable. 57 RtlCopyMemory(Console->Colors, ConsoleInfo->ColorTable, sizeof(s_Colors)); 58 59 /* Apply cursor size */ 60 ActiveBuffer->CursorInfo.bVisible = (ConsoleInfo->CursorSize != 0); 61 ActiveBuffer->CursorInfo.dwSize = min(max(ConsoleInfo->CursorSize, 0), 100); 62 63 /* Update the code page */ 64 if ((Console->OutputCodePage != ConsoleInfo->CodePage) && 65 IsValidCodePage(ConsoleInfo->CodePage)) 66 { 67 Console->InputCodePage = Console->OutputCodePage = ConsoleInfo->CodePage; 68 // ConDrvSetConsoleCP(Console, ConsoleInfo->CodePage, TRUE); // Output 69 // ConDrvSetConsoleCP(Console, ConsoleInfo->CodePage, FALSE); // Input 70 71 Console->IsCJK = IsCJKCodePage(Console->OutputCodePage); 72 } 73 74 // FIXME: Check ConsoleInfo->WindowSize with respect to 75 // TermGetLargestConsoleWindowSize(...). 76 77 if (GetType(ActiveBuffer) == TEXTMODE_BUFFER) 78 { 79 /* Resize its active screen-buffer */ 80 PTEXTMODE_SCREEN_BUFFER Buffer = (PTEXTMODE_SCREEN_BUFFER)ActiveBuffer; 81 COORD BufSize = ConsoleInfo->ScreenBufferSize; 82 83 if (Console->FixedSize) 84 { 85 /* 86 * The console is in fixed-size mode, so we cannot resize anything 87 * at the moment. However, keep those settings somewhere so that 88 * we can try to set them up when we will be allowed to do so. 89 */ 90 if (ConsoleInfo->WindowSize.X != ActiveBuffer->OldViewSize.X || 91 ConsoleInfo->WindowSize.Y != ActiveBuffer->OldViewSize.Y) 92 { 93 ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize; 94 } 95 96 /* The buffer size is not allowed to be smaller than the view size */ 97 if (BufSize.X >= ActiveBuffer->OldViewSize.X && BufSize.Y >= ActiveBuffer->OldViewSize.Y) 98 { 99 if (BufSize.X != ActiveBuffer->OldScreenBufferSize.X || 100 BufSize.Y != ActiveBuffer->OldScreenBufferSize.Y) 101 { 102 /* 103 * The console is in fixed-size mode, so we cannot resize anything 104 * at the moment. However, keep those settings somewhere so that 105 * we can try to set them up when we will be allowed to do so. 106 */ 107 ActiveBuffer->OldScreenBufferSize = BufSize; 108 } 109 } 110 } 111 else 112 { 113 BOOL SizeChanged = FALSE; 114 115 /* Resize the console */ 116 if (ConsoleInfo->WindowSize.X != ActiveBuffer->ViewSize.X || 117 ConsoleInfo->WindowSize.Y != ActiveBuffer->ViewSize.Y) 118 { 119 ActiveBuffer->ViewSize = ConsoleInfo->WindowSize; 120 SizeChanged = TRUE; 121 } 122 123 /* Resize the screen-buffer */ 124 if (BufSize.X != ActiveBuffer->ScreenBufferSize.X || 125 BufSize.Y != ActiveBuffer->ScreenBufferSize.Y) 126 { 127 if (NT_SUCCESS(ConioResizeBuffer((PCONSOLE)Console, Buffer, BufSize))) 128 SizeChanged = TRUE; 129 } 130 131 if (SizeChanged) TermResizeTerminal(Console); 132 } 133 134 /* Apply foreground and background colors for both screen and popup */ 135 ConDrvChangeScreenBufferAttributes((PCONSOLE)Console, 136 Buffer, 137 ConsoleInfo->ScreenAttributes, 138 ConsoleInfo->PopupAttributes); 139 } 140 else // if (GetType(ActiveBuffer) == GRAPHICS_BUFFER) 141 { 142 /* 143 * In any case we do NOT modify the size of the graphics screen-buffer. 144 * We just allow resizing the view only if the new size is smaller 145 * than the older one. 146 */ 147 if (Console->FixedSize) 148 { 149 /* 150 * The console is in fixed-size mode, so we cannot resize anything 151 * at the moment. However, keep those settings somewhere so that 152 * we can try to set them up when we will be allowed to do so. 153 */ 154 if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X || 155 ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y) 156 { 157 ActiveBuffer->OldViewSize = ConsoleInfo->WindowSize; 158 } 159 } 160 else 161 { 162 /* Resize the view if its size is bigger than the specified size */ 163 if (ConsoleInfo->WindowSize.X <= ActiveBuffer->ViewSize.X || 164 ConsoleInfo->WindowSize.Y <= ActiveBuffer->ViewSize.Y) 165 { 166 ActiveBuffer->ViewSize = ConsoleInfo->WindowSize; 167 // SizeChanged = TRUE; 168 } 169 } 170 } 171 } 172 173 /* EOF */ 174