Skip to content

Commit 5cdf75a

Browse files
committed
[CONSRV][CONSOLE.DLL]
- Correctly retrieve/set the default console properties. - (for console.dll only): split ApplyConsoleInfo so that it only deals with displaying the confirmation dialog (and set the correct return value for the PSN_APPLY notification message); the code that really sets console properties and save them in the registry is done in the main CPL function, after the property dialog is destroyed and before the CPL returns. svn path=/trunk/; revision=67068
1 parent e18a1e9 commit 5cdf75a

File tree

8 files changed

+147
-159
lines changed

8 files changed

+147
-159
lines changed

reactos/dll/cpl/console/colors.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,8 @@ ColorsProc(HWND hwndDlg,
8181
{
8282
case PSN_APPLY:
8383
{
84-
if (!AppliedConfig)
85-
{
86-
return ApplyConsoleInfo(hwndDlg, ConInfo);
87-
}
88-
else
89-
{
90-
/* Options have already been applied */
91-
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
92-
return TRUE;
93-
}
94-
break;
84+
ApplyConsoleInfo(hwndDlg);
85+
return TRUE;
9586
}
9687

9788
case UDN_DELTAPOS:

reactos/dll/cpl/console/console.c

Lines changed: 84 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
1818
INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
1919

2020
HINSTANCE hApplet = NULL;
21-
BOOLEAN AppliedConfig = FALSE;
2221

23-
/* Local copy of the console informations */
22+
/* Local copy of the console information */
2423
PCONSOLE_STATE_INFO ConInfo = NULL;
24+
/* What to do with the console information */
25+
static BOOL SetConsoleInfo = FALSE;
26+
static BOOL SaveConsoleInfo = FALSE;
2527

2628
static VOID
2729
InitPropSheetPage(PROPSHEETPAGEW *psp,
@@ -40,8 +42,8 @@ InitPropSheetPage(PROPSHEETPAGEW *psp,
4042
static VOID
4143
InitDefaultConsoleInfo(PCONSOLE_STATE_INFO pConInfo)
4244
{
43-
/* FIXME: Get also the defaults from the registry */
44-
ConCfgInitDefaultSettings(pConInfo);
45+
// FIXME: Also retrieve the value of REG_DWORD CurrentPage.
46+
ConCfgGetDefaultSettings(pConInfo);
4547
}
4648

4749
static INT_PTR
@@ -82,90 +84,53 @@ ApplyProc(HWND hwndDlg,
8284
return FALSE;
8385
}
8486

85-
BOOL
86-
ApplyConsoleInfo(HWND hwndDlg,
87-
PCONSOLE_STATE_INFO pConInfo)
87+
VOID
88+
ApplyConsoleInfo(HWND hwndDlg)
8889
{
89-
BOOL SetParams = FALSE;
90-
BOOL SaveParams = FALSE;
90+
static BOOL ConsoleInfoAlreadySaved = FALSE;
91+
92+
/*
93+
* We alread applied all the console properties (and saved if needed).
94+
* Nothing more needs to be done.
95+
*/
96+
if (ConsoleInfoAlreadySaved)
97+
goto Done;
9198

9299
/*
93100
* If we are setting the default parameters, just save them,
94-
* otherwise display the save-confirmation dialog.
101+
* otherwise display the confirmation & apply dialog.
95102
*/
96-
if (pConInfo->hWnd == NULL)
103+
if (ConInfo->hWnd == NULL)
97104
{
98-
SetParams = FALSE;
99-
SaveParams = TRUE; // FIXME: What happens if one clicks on CANCEL??
105+
SetConsoleInfo = FALSE;
106+
SaveConsoleInfo = TRUE;
100107
}
101108
else
102109
{
103110
INT_PTR res = DialogBoxW(hApplet, MAKEINTRESOURCEW(IDD_APPLYOPTIONS), hwndDlg, ApplyProc);
104111

105-
SetParams = (res != IDCANCEL);
106-
SaveParams = (res == IDC_RADIO_APPLY_ALL);
112+
SetConsoleInfo = (res != IDCANCEL);
113+
SaveConsoleInfo = (res == IDC_RADIO_APPLY_ALL);
107114

108-
if (SetParams == FALSE)
115+
if (SetConsoleInfo == FALSE)
109116
{
110-
/* Don't destroy when user presses cancel */
117+
/* Don't destroy when the user presses cancel */
111118
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
112-
// return TRUE;
119+
return;
113120
}
114121
}
115122

116-
if (SetParams)
117-
{
118-
HANDLE hSection;
119-
PCONSOLE_STATE_INFO pSharedInfo;
120-
121-
/*
122-
* Create a memory section to share with CONSRV, and map it.
123-
*/
124-
hSection = CreateFileMappingW(INVALID_HANDLE_VALUE,
125-
NULL,
126-
PAGE_READWRITE,
127-
0,
128-
pConInfo->cbSize,
129-
NULL);
130-
if (!hSection)
131-
{
132-
DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
133-
return FALSE;
134-
}
135-
136-
pSharedInfo = MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS, 0, 0, 0);
137-
if (!pSharedInfo)
138-
{
139-
DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
140-
CloseHandle(hSection);
141-
return FALSE;
142-
}
143-
144-
/* We are applying the chosen configuration */
145-
AppliedConfig = TRUE;
146-
147-
/* Copy the console information into the section */
148-
RtlCopyMemory(pSharedInfo, pConInfo, pConInfo->cbSize);
149-
150-
/* Unmap it */
151-
UnmapViewOfFile(pSharedInfo);
152-
153-
/* Signal to CONSRV that it can apply the new configuration */
154-
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
155-
SendMessage(pConInfo->hWnd,
156-
WM_SETCONSOLEINFO,
157-
(WPARAM)hSection, 0);
158-
159-
/* Close the section and return */
160-
CloseHandle(hSection);
161-
}
162-
163-
if (SaveParams)
164-
{
165-
ConCfgWriteUserSettings(pConInfo);
166-
}
123+
/*
124+
* We applied all the console properties (and saved if needed).
125+
* Set the flag so that if this function is called again, we won't
126+
* need to redo everything again.
127+
*/
128+
ConsoleInfoAlreadySaved = TRUE;
167129

168-
return TRUE;
130+
Done:
131+
/* Options have been applied */
132+
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
133+
return;
169134
}
170135

171136
/* First Applet */
@@ -286,7 +251,56 @@ InitApplet(HANDLE hSectionOrWnd)
286251
InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS , ColorsProc );
287252

288253
Result = PropertySheetW(&psh);
254+
255+
if (SetConsoleInfo)
256+
{
257+
HANDLE hSection;
258+
259+
/*
260+
* Create a memory section to share with CONSRV, and map it.
261+
*/
262+
hSection = CreateFileMappingW(INVALID_HANDLE_VALUE,
263+
NULL,
264+
PAGE_READWRITE,
265+
0,
266+
ConInfo->cbSize,
267+
NULL);
268+
if (!hSection)
269+
{
270+
DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
271+
goto Quit;
272+
}
273+
274+
pSharedInfo = MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS, 0, 0, 0);
275+
if (!pSharedInfo)
276+
{
277+
DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
278+
CloseHandle(hSection);
279+
goto Quit;
280+
}
281+
282+
/* Copy the console information into the section */
283+
RtlCopyMemory(pSharedInfo, ConInfo, ConInfo->cbSize);
284+
285+
/* Unmap it */
286+
UnmapViewOfFile(pSharedInfo);
289287

288+
/* Signal to CONSRV that it can apply the new configuration */
289+
SendMessage(ConInfo->hWnd,
290+
WM_SETCONSOLEINFO,
291+
(WPARAM)hSection, 0);
292+
293+
/* Close the section and return */
294+
CloseHandle(hSection);
295+
}
296+
297+
if (SaveConsoleInfo)
298+
{
299+
/* Default settings saved when ConInfo->hWnd == NULL */
300+
ConCfgWriteUserSettings(ConInfo, ConInfo->hWnd == NULL);
301+
}
302+
303+
Quit:
290304
/* Cleanup */
291305
HeapFree(GetProcessHeap(), 0, ConInfo);
292306
ConInfo = NULL;

reactos/dll/cpl/console/console.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ typedef enum _TEXT_TYPE
2929
} TEXT_TYPE;
3030

3131
/* Globals */
32-
extern BOOLEAN AppliedConfig;
3332
extern PCONSOLE_STATE_INFO ConInfo;
3433

35-
BOOL ApplyConsoleInfo(HWND hwndDlg, PCONSOLE_STATE_INFO pConInfo);
34+
VOID ApplyConsoleInfo(HWND hwndDlg);
3635
VOID PaintConsole(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo);
3736
BOOL PaintText(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo, TEXT_TYPE TextMode);
3837

reactos/dll/cpl/console/font.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -421,17 +421,8 @@ FontProc(HWND hwndDlg,
421421
{
422422
case PSN_APPLY:
423423
{
424-
if (!AppliedConfig)
425-
{
426-
return ApplyConsoleInfo(hwndDlg, ConInfo);
427-
}
428-
else
429-
{
430-
/* Options have already been applied */
431-
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
432-
return TRUE;
433-
}
434-
break;
424+
ApplyConsoleInfo(hwndDlg);
425+
return TRUE;
435426
}
436427
}
437428

reactos/dll/cpl/console/options.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,8 @@ OptionsProc(HWND hwndDlg,
127127
}
128128
else if (lppsn->hdr.code == PSN_APPLY)
129129
{
130-
if (!AppliedConfig)
131-
{
132-
return ApplyConsoleInfo(hwndDlg, ConInfo);
133-
}
134-
else
135-
{
136-
/* Options have already been applied */
137-
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
138-
return TRUE;
139-
}
130+
ApplyConsoleInfo(hwndDlg);
131+
return TRUE;
140132
}
141133
break;
142134
}

0 commit comments

Comments
 (0)