ReactOS 0.4.15-dev-7846-g8ba6c66
console.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/console/console.c
5 * PURPOSE: Initialization
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10#include "console.h"
11
12#define NDEBUG
13#include <debug.h>
14
19
21
22/* Local copy of the console information */
24/* What to do with the console information */
27
28static VOID
30 WORD idDlg,
32{
33 ZeroMemory(psp, sizeof(*psp));
34 psp->dwSize = sizeof(*psp);
35 psp->dwFlags = PSP_DEFAULT;
36 psp->hInstance = hApplet;
38 psp->pfnDlgProc = DlgProc;
39 psp->lParam = 0;
40}
41
42static VOID
44{
45 // FIXME: Also retrieve the value of REG_DWORD CurrentPage.
47}
48
49static INT_PTR
52 UINT uMsg,
55{
57
58 switch (uMsg)
59 {
60 case WM_INITDIALOG:
61 {
63 return TRUE;
64 }
65 case WM_COMMAND:
66 {
67 if (LOWORD(wParam) == IDOK)
68 {
71 else
73 }
74 else if (LOWORD(wParam) == IDCANCEL)
75 {
76 EndDialog(hwndDlg, IDCANCEL);
77 }
78 break;
79 }
80 default:
81 break;
82 }
83
84 return FALSE;
85}
86
87VOID
89{
90 static BOOL ConsoleInfoAlreadySaved = FALSE;
91
92 /*
93 * We already applied all the console properties (and saved if needed).
94 * Nothing more needs to be done.
95 */
96 if (ConsoleInfoAlreadySaved)
97 goto Done;
98
99 /*
100 * If we are setting the default parameters, just save them,
101 * otherwise display the confirmation & apply dialog.
102 */
103 if (ConInfo->hWnd == NULL)
104 {
107 }
108 else
109 {
111
114
115 if (!SetConsoleInfo)
116 {
117 /* Don't destroy when the user presses cancel */
119 return;
120 }
121 }
122
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;
129
130Done:
131 /* Options have been applied */
133 return;
134}
135
136static int CALLBACK
138{
139 // NOTE: This callback is needed to set large icon correctly.
140 HICON hIcon;
141 switch (uMsg)
142 {
143 case PSCB_INITIALIZED:
144 {
146 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
147 break;
148 }
149 }
150 return 0;
151}
152
153/* First Applet */
154static LONG
156InitApplet(HANDLE hSectionOrWnd)
157{
159 PCONSOLE_STATE_INFO pSharedInfo = NULL;
161 PROPSHEETPAGEW psp[4];
163 INT i = 0;
164
165 /*
166 * Because of Windows compatibility, we need to behave the same concerning
167 * information sharing with CONSRV. For some obscure reason the designers
168 * decided to use the CPlApplet hWnd parameter as being either a handle to
169 * the applet's parent caller's window (in case we ask for displaying
170 * the global console settings), or a handle to a shared section holding
171 * a CONSOLE_STATE_INFO structure (they don't use the extra l/wParams).
172 */
173
174 /*
175 * Try to open the shared section via the handle parameter. If we succeed,
176 * it means we were called by CONSRV for retrieving/setting parameters for
177 * a given console. If we fail, it means we are retrieving/setting default
178 * global parameters (and we were either called by CONSRV or directly by
179 * the user via the Control Panel, etc...)
180 */
181 pSharedInfo = MapViewOfFile(hSectionOrWnd, FILE_MAP_READ, 0, 0, 0);
182 if (pSharedInfo != NULL)
183 {
184 /*
185 * We succeeded. We were called by CONSRV and are retrieving
186 * parameters for a given console.
187 */
188
189 /* Copy the shared data into our allocated buffer */
190 DPRINT1("pSharedInfo->cbSize == %lu ; sizeof(CONSOLE_STATE_INFO) == %u\n",
191 pSharedInfo->cbSize, sizeof(CONSOLE_STATE_INFO));
192 ASSERT(pSharedInfo->cbSize >= sizeof(CONSOLE_STATE_INFO));
193
194 /* Allocate a local buffer to hold console information */
197 pSharedInfo->cbSize);
198 if (ConInfo)
199 RtlCopyMemory(ConInfo, pSharedInfo, pSharedInfo->cbSize);
200
201 /* Close the section */
202 UnmapViewOfFile(pSharedInfo);
203 CloseHandle(hSectionOrWnd);
204
205 if (!ConInfo) return 0;
206 }
207 else
208 {
209 /*
210 * We failed. We are retrieving the default global parameters.
211 */
212
213 /* Allocate a local buffer to hold console information */
216 sizeof(CONSOLE_STATE_INFO));
217 if (!ConInfo) return 0;
218
219 /*
220 * Setting the console window handle to NULL indicates we are
221 * retrieving/setting the default console parameters.
222 */
223 ConInfo->hWnd = NULL;
225
226 /* Use defaults */
228 }
229
230 /* Initialize the font support -- additional TrueType font cache and current preview font */
233
234 /* Initialize the property sheet structure */
235 ZeroMemory(&psh, sizeof(psh));
236 psh.dwSize = sizeof(psh);
238
240 {
242 psh.pszCaption = szTitle;
243 }
244 else
245 {
247 }
248
249 if (pSharedInfo != NULL)
250 {
251 /* We were started from a console window: this is our parent (or ConInfo->hWnd is NULL) */
252 psh.hwndParent = ConInfo->hWnd;
253 }
254 else
255 {
256 /* We were started in another way (--> default parameters). Caller's window is our parent. */
257 psh.hwndParent = (HWND)hSectionOrWnd;
258 }
259
260 psh.hInstance = hApplet;
261 // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCEW(IDC_CPLICON));
263 psh.nPages = ARRAYSIZE(psp);
264 psh.nStartPage = 0;
265 psh.ppsp = psp;
267
272
273 /* Display the property sheet */
275 Result = PropertySheetW(&psh);
277
278 /* Clear the font support */
281
282 /* Apply the console settings if necessary */
283 if (SetConsoleInfo)
284 {
286
287 /*
288 * Create a memory section to share with CONSRV, and map it.
289 */
291 NULL,
293 0,
295 NULL);
296 if (!hSection)
297 {
298 DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
299 goto Quit;
300 }
301
302 pSharedInfo = MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS, 0, 0, 0);
303 if (!pSharedInfo)
304 {
305 DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
307 goto Quit;
308 }
309
310 /* Copy the console information into the section and unmap it */
311 RtlCopyMemory(pSharedInfo, ConInfo, ConInfo->cbSize);
312 UnmapViewOfFile(pSharedInfo);
313
314 /*
315 * Signal to CONSRV that it can apply the new settings.
316 *
317 * NOTE: SetConsoleInfo set to TRUE by ApplyConsoleInfo()
318 * *only* when ConInfo->hWnd != NULL and the user did not
319 * press IDCANCEL in the confirmation dialog.
320 */
323
324 /* Close the section and return */
326 }
327
328 /* Save the console settings */
329 if (SaveConsoleInfo)
330 {
331 /* Default settings saved when ConInfo->hWnd == NULL */
333 }
334
335Quit:
336 /* Cleanup */
338 ConInfo = NULL;
339
340 return (Result != -1);
341}
342
343/* Control Panel Callback */
344LONG
347 UINT uMsg,
348 LPARAM lParam1,
349 LPARAM lParam2)
350{
351 switch (uMsg)
352 {
353 case CPL_INIT:
354 return TRUE;
355
356 case CPL_EXIT:
357 // TODO: Free allocated memory
358 break;
359
360 case CPL_GETCOUNT:
361 return 1;
362
363 case CPL_INQUIRE:
364 {
365 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
366 CPlInfo->idIcon = IDC_CPLICON;
367 CPlInfo->idName = IDS_CPLNAME;
368 CPlInfo->idInfo = IDS_CPLDESCRIPTION;
369 break;
370 }
371
372 case CPL_DBLCLK:
373 InitApplet((HANDLE)hwndCPl);
374 break;
375 }
376
377 return FALSE;
378}
379
380INT
381WINAPI
385{
387
388 switch (dwReason)
389 {
391 hApplet = hinstDLL;
393 break;
394 }
395
396 return TRUE;
397}
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:154
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define CPL_INQUIRE
Definition: cpl.h:14
#define CPL_DBLCLK
Definition: cpl.h:16
#define CPL_INIT
Definition: cpl.h:12
#define CPL_EXIT
Definition: cpl.h:18
#define CPL_GETCOUNT
Definition: cpl.h:13
#define DLGPROC
Definition: maze.c:62
WORD idDlg
Definition: desk.c:121
DLGPROC DlgProc
Definition: desk.c:122
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
PCONSOLE_STATE_INFO ConInfo
Definition: console.c:23
INT_PTR CALLBACK FontProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: font.c:725
static BOOL SaveConsoleInfo
Definition: console.c:26
static INT_PTR CALLBACK ApplyProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: console.c:51
static VOID InitPropSheetPage(PROPSHEETPAGEW *psp, WORD idDlg, DLGPROC DlgProc)
Definition: console.c:29
static VOID InitDefaultConsoleInfo(PCONSOLE_STATE_INFO pConInfo)
Definition: console.c:43
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: console.c:137
INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: colors.c:37
static LONG APIENTRY InitApplet(HANDLE hSectionOrWnd)
Definition: console.c:156
INT WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
Definition: console.c:382
INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: magnifier.c:860
INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: layout.c:525
VOID ApplyConsoleInfo(HWND hwndDlg)
Definition: console.c:88
static BOOL SetConsoleInfo
Definition: console.c:25
HINSTANCE hApplet
Definition: console.c:20
BOOL UnRegisterWinPrevClass(IN HINSTANCE hInstance)
Definition: layout.c:52
FONT_PREVIEW FontPreview
Definition: font.c:21
VOID RefreshFontPreview(IN FONT_PREVIEW *Preview, IN PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:52
BOOL RegisterWinPrevClass(IN HINSTANCE hInstance)
Definition: layout.c:32
#define ResetFontPreview(Preview)
Definition: console.h:65
#define IDC_RADIO_APPLY_CURRENT
Definition: resource.h:35
#define IDD_PROPPAGEFONT
Definition: resource.h:13
#define IDC_CPLICON
Definition: resource.h:7
#define IDS_CPLNAME
Definition: resource.h:8
#define IDD_APPLYOPTIONS
Definition: resource.h:16
#define IDS_CPLDESCRIPTION
Definition: resource.h:9
#define IDD_PROPPAGECOLORS
Definition: resource.h:15
#define IDD_PROPPAGEOPTIONS
Definition: resource.h:12
#define IDC_RADIO_APPLY_ALL
Definition: resource.h:34
#define IDD_PROPPAGELAYOUT
Definition: resource.h:14
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define APIENTRY
Definition: api.h:79
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2913
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define UnmapViewOfFile
Definition: compat.h:746
HANDLE HWND
Definition: compat.h:19
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define FILE_MAP_READ
Definition: compat.h:776
#define CALLBACK
Definition: compat.h:35
#define MapViewOfFile
Definition: compat.h:745
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint res
Definition: glext.h:9613
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static IN DWORD IN LPVOID lpvReserved
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
#define ASSERT(a)
Definition: mode.c:44
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define UNICODE_NULL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
long LONG
Definition: pedump.c:60
#define PSH_PROPTITLE
Definition: prsht.h:40
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
#define PSH_USECALLBACK
Definition: prsht.h:48
#define PSP_DEFAULT
Definition: prsht.h:22
#define PSNRET_NOERROR
Definition: prsht.h:129
#define PSH_PROPSHEETPAGE
Definition: prsht.h:43
#define PSH_USEICONID
Definition: prsht.h:42
#define PSCB_INITIALIZED
Definition: prsht.h:75
#define PSH_NOAPPLYNOW
Definition: prsht.h:47
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
WCHAR ConsoleTitle[ANYSIZE_ARRAY]
Definition: settings.h:58
LPCPROPSHEETPAGEW ppsp
Definition: prsht.h:308
HINSTANCE hInstance
Definition: prsht.h:296
DWORD dwSize
Definition: prsht.h:293
DWORD dwFlags
Definition: prsht.h:294
LPCWSTR pszIcon
Definition: prsht.h:299
HWND hwndParent
Definition: prsht.h:295
PFNPROPSHEETCALLBACK pfnCallback
Definition: prsht.h:311
UINT nStartPage
Definition: prsht.h:304
LPCWSTR pszCaption
Definition: prsht.h:301
DLGPROC pfnDlgProc
Definition: prsht.h:226
DWORD dwSize
Definition: prsht.h:214
DWORD dwFlags
Definition: prsht.h:215
LPARAM lParam
Definition: prsht.h:227
LPCWSTR pszTemplate
Definition: prsht.h:218
HINSTANCE hInstance
Definition: prsht.h:216
Definition: cpl.h:24
int idName
Definition: cpl.h:26
int idInfo
Definition: cpl.h:27
int idIcon
Definition: cpl.h:25
#define ICON_BIG
Definition: tnclass.cpp:51
#define SetWindowLongPtr
Definition: treelist.c:70
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID InitTTFontCache(VOID)
Initializes the console TrueType font cache.
Definition: font.c:1013
VOID ClearTTFontCache(VOID)
Clears the console TrueType font cache.
Definition: font.c:1131
VOID ConCfgGetDefaultSettings(IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
Definition: settings.c:491
BOOLEAN ConCfgWriteUserSettings(IN PCONSOLE_STATE_INFO ConsoleInfo, IN BOOLEAN DefaultSettings)
Definition: settings.c:344
#define WM_SETCONSOLEINFO
Definition: settings.h:21
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3239
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define IDCANCEL
Definition: winuser.h:831
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4399
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
#define IDOK
Definition: winuser.h:830
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define DWLP_MSGRESULT
Definition: winuser.h:870
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2075
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__wchar_t WCHAR
Definition: xmlstorage.h:180