@@ -18,10 +18,12 @@ INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
18
18
INT_PTR CALLBACK ColorsProc (HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
19
19
20
20
HINSTANCE hApplet = NULL ;
21
- BOOLEAN AppliedConfig = FALSE;
22
21
23
- /* Local copy of the console informations */
22
+ /* Local copy of the console information */
24
23
PCONSOLE_STATE_INFO ConInfo = NULL ;
24
+ /* What to do with the console information */
25
+ static BOOL SetConsoleInfo = FALSE;
26
+ static BOOL SaveConsoleInfo = FALSE;
25
27
26
28
static VOID
27
29
InitPropSheetPage (PROPSHEETPAGEW * psp ,
@@ -40,8 +42,8 @@ InitPropSheetPage(PROPSHEETPAGEW *psp,
40
42
static VOID
41
43
InitDefaultConsoleInfo (PCONSOLE_STATE_INFO pConInfo )
42
44
{
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 );
45
47
}
46
48
47
49
static INT_PTR
@@ -82,90 +84,53 @@ ApplyProc(HWND hwndDlg,
82
84
return FALSE;
83
85
}
84
86
85
- BOOL
86
- ApplyConsoleInfo (HWND hwndDlg ,
87
- PCONSOLE_STATE_INFO pConInfo )
87
+ VOID
88
+ ApplyConsoleInfo (HWND hwndDlg )
88
89
{
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 ;
91
98
92
99
/*
93
100
* If we are setting the default parameters, just save them,
94
- * otherwise display the save- confirmation dialog.
101
+ * otherwise display the confirmation & apply dialog.
95
102
*/
96
- if (pConInfo -> hWnd == NULL )
103
+ if (ConInfo -> hWnd == NULL )
97
104
{
98
- SetParams = FALSE;
99
- SaveParams = TRUE; // FIXME: What happens if one clicks on CANCEL??
105
+ SetConsoleInfo = FALSE;
106
+ SaveConsoleInfo = TRUE;
100
107
}
101
108
else
102
109
{
103
110
INT_PTR res = DialogBoxW (hApplet , MAKEINTRESOURCEW (IDD_APPLYOPTIONS ), hwndDlg , ApplyProc );
104
111
105
- SetParams = (res != IDCANCEL );
106
- SaveParams = (res == IDC_RADIO_APPLY_ALL );
112
+ SetConsoleInfo = (res != IDCANCEL );
113
+ SaveConsoleInfo = (res == IDC_RADIO_APPLY_ALL );
107
114
108
- if (SetParams == FALSE)
115
+ if (SetConsoleInfo == FALSE)
109
116
{
110
- /* Don't destroy when user presses cancel */
117
+ /* Don't destroy when the user presses cancel */
111
118
SetWindowLongPtr (hwndDlg , DWLP_MSGRESULT , PSNRET_INVALID_NOCHANGEPAGE );
112
- // return TRUE ;
119
+ return ;
113
120
}
114
121
}
115
122
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;
167
129
168
- return TRUE;
130
+ Done :
131
+ /* Options have been applied */
132
+ SetWindowLongPtr (hwndDlg , DWLP_MSGRESULT , PSNRET_NOERROR );
133
+ return ;
169
134
}
170
135
171
136
/* First Applet */
@@ -286,7 +251,56 @@ InitApplet(HANDLE hSectionOrWnd)
286
251
InitPropSheetPage (& psp [i ++ ], IDD_PROPPAGECOLORS , ColorsProc );
287
252
288
253
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 );
289
287
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 :
290
304
/* Cleanup */
291
305
HeapFree (GetProcessHeap (), 0 , ConInfo );
292
306
ConInfo = NULL ;
0 commit comments