ReactOS  0.4.13-dev-698-g77671f0
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 
28 static 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 
42 static VOID
44 {
45  // FIXME: Also retrieve the value of REG_DWORD CurrentPage.
46  ConCfgGetDefaultSettings(pConInfo);
47 }
48 
49 static INT_PTR
51 ApplyProc(HWND hwndDlg,
52  UINT uMsg,
53  WPARAM wParam,
54  LPARAM lParam)
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 
87 VOID
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 
112  SetConsoleInfo = (res != IDCANCEL);
114 
115  if (SetConsoleInfo == FALSE)
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 
130 Done:
131  /* Options have been applied */
133  return;
134 }
135 
136 static 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 */
154 static LONG
155 APIENTRY
156 InitApplet(HANDLE hSectionOrWnd)
157 {
158  INT_PTR Result;
159  PCONSOLE_STATE_INFO pSharedInfo = NULL;
160  WCHAR szTitle[MAX_PATH + 1];
161  PROPSHEETPAGEW psp[4];
162  PROPSHEETHEADERW psh;
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 fonts cache and current preview font */
231  InitTTFontCache();
233 
234  /* Initialize the property sheet structure */
235  ZeroMemory(&psh, sizeof(psh));
236  psh.dwSize = sizeof(psh);
238 
239  if (ConInfo->ConsoleTitle[0] != UNICODE_NULL)
241  else
242  StringCchCopyW(szTitle, ARRAYSIZE(szTitle), L"ReactOS Console");
243  psh.pszCaption = szTitle;
244 
245  if (pSharedInfo != NULL)
246  {
247  /* We were started from a console window: this is our parent (or ConInfo->hWnd is NULL) */
248  psh.hwndParent = ConInfo->hWnd;
249  }
250  else
251  {
252  /* We were started in another way (--> default parameters). Caller's window is our parent. */
253  psh.hwndParent = (HWND)hSectionOrWnd;
254  }
255 
256  psh.hInstance = hApplet;
257  // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCEW(IDC_CPLICON));
259  psh.nPages = ARRAYSIZE(psp);
260  psh.nStartPage = 0;
261  psh.ppsp = psp;
263 
268 
269  /* Display the property sheet */
271  Result = PropertySheetW(&psh);
273 
274  /* Clear the font support */
277 
278  /* Save the console settings */
279  if (SetConsoleInfo)
280  {
282 
283  /*
284  * Create a memory section to share with CONSRV, and map it.
285  */
287  NULL,
289  0,
290  ConInfo->cbSize,
291  NULL);
292  if (!hSection)
293  {
294  DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
295  goto Quit;
296  }
297 
298  pSharedInfo = MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS, 0, 0, 0);
299  if (!pSharedInfo)
300  {
301  DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
303  goto Quit;
304  }
305 
306  /* Copy the console information into the section */
307  RtlCopyMemory(pSharedInfo, ConInfo, ConInfo->cbSize);
308 
309  /* Unmap it */
310  UnmapViewOfFile(pSharedInfo);
311 
312  /* Signal to CONSRV that it can apply the new configuration */
314 
315  /* Close the section and return */
317  }
318 
319  if (SaveConsoleInfo)
320  {
321  /* Default settings saved when ConInfo->hWnd == NULL */
323  }
324 
325 Quit:
326  /* Cleanup */
328  ConInfo = NULL;
329 
330  return (Result != -1);
331 }
332 
333 /* Control Panel Callback */
334 LONG
335 CALLBACK
336 CPlApplet(HWND hwndCPl,
337  UINT uMsg,
338  LPARAM lParam1,
339  LPARAM lParam2)
340 {
341  switch (uMsg)
342  {
343  case CPL_INIT:
344  return TRUE;
345 
346  case CPL_EXIT:
347  // TODO: Free allocated memory
348  break;
349 
350  case CPL_GETCOUNT:
351  return 1;
352 
353  case CPL_INQUIRE:
354  {
355  CPLINFO *CPlInfo = (CPLINFO*)lParam2;
356  CPlInfo->idIcon = IDC_CPLICON;
357  CPlInfo->idName = IDS_CPLNAME;
358  CPlInfo->idInfo = IDS_CPLDESCRIPTION;
359  break;
360  }
361 
362  case CPL_DBLCLK:
363  InitApplet((HANDLE)hwndCPl);
364  break;
365  }
366 
367  return FALSE;
368 }
369 
370 INT
371 WINAPI
373  DWORD dwReason,
375 {
377 
378  switch (dwReason)
379  {
380  case DLL_PROCESS_ATTACH:
381  hApplet = hinstDLL;
382  DisableThreadLibraryCalls(hinstDLL);
383  break;
384  }
385 
386  return TRUE;
387 }
VOID ConCfgGetDefaultSettings(IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
Definition: settings.c:491
HWND hwndParent
Definition: prsht.h:277
WORD idDlg
Definition: desk.c:109
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define IDD_PROPPAGEOPTIONS
Definition: resource.h:12
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static INT_PTR CALLBACK ApplyProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: console.c:51
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:398
LPCPROPSHEETPAGEW ppsp
Definition: prsht.h:290
#define PSH_NOAPPLYNOW
Definition: prsht.h:47
Definition: cpl.h:24
LPCWSTR pszTemplate
Definition: prsht.h:209
#define MapViewOfFile
Definition: compat.h:402
static VOID InitDefaultConsoleInfo(PCONSOLE_STATE_INFO pConInfo)
Definition: console.c:43
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
static LONG APIENTRY InitApplet(HANDLE hSectionOrWnd)
Definition: console.c:156
#define CALLBACK
Definition: compat.h:27
int idInfo
Definition: cpl.h:27
HANDLE HWND
Definition: compat.h:13
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
UINT_PTR WPARAM
Definition: windef.h:207
static BOOL SetConsoleInfo
Definition: console.c:25
int32_t INT_PTR
Definition: typedefs.h:62
#define PSH_USECALLBACK
Definition: prsht.h:48
#define IDC_CPLICON
Definition: resource.h:7
INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: colors.c:39
int32_t INT
Definition: typedefs.h:56
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
static IN DWORD IN LPVOID lpvReserved
#define DWLP_MSGRESULT
Definition: winuser.h:864
VOID InitTTFontCache(VOID)
Definition: font.c:391
int idIcon
Definition: cpl.h:25
#define CPL_DBLCLK
Definition: cpl.h:16
VOID ClearTTFontCache(VOID)
Definition: font.c:500
DWORD dwReason
Definition: misc.cpp:154
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
#define IDS_CPLNAME
Definition: resource.h:8
DWORD dwSize
Definition: prsht.h:205
#define PSH_USEICONID
Definition: prsht.h:42
#define UNICODE_NULL
#define IDC_RADIO_APPLY_CURRENT
Definition: resource.h:35
LPCWSTR pszCaption
Definition: prsht.h:283
unsigned int BOOL
Definition: ntddk_ex.h:94
DLGPROC pfnDlgProc
Definition: prsht.h:217
long LONG
Definition: pedump.c:60
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
PFNPROPSHEETCALLBACK pfnCallback
Definition: prsht.h:293
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
smooth NULL
Definition: ftsmooth.c:416
_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:426
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
VOID ApplyConsoleInfo(HWND hwndDlg)
Definition: console.c:88
LONG_PTR LPARAM
Definition: windef.h:208
#define FILE_MAP_READ
Definition: compat.h:427
BOOL UnRegisterWinPrevClass(IN HINSTANCE hInstance)
Definition: layout.c:52
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2896
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4300
#define IDD_PROPPAGELAYOUT
Definition: resource.h:14
#define IDS_CPLDESCRIPTION
Definition: resource.h:9
INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: layout.c:525
#define PSP_DEFAULT
Definition: prsht.h:22
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CPL_EXIT
Definition: cpl.h:18
__wchar_t WCHAR
Definition: xmlstorage.h:180
HINSTANCE hApplet
Definition: console.c:20
BOOLEAN ConCfgWriteUserSettings(IN PCONSOLE_STATE_INFO ConsoleInfo, IN BOOLEAN DefaultSettings)
Definition: settings.c:344
#define PSH_PROPTITLE
Definition: prsht.h:40
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
HINSTANCE hInstance
Definition: prsht.h:278
LONG CALLBACK CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
Definition: console.c:336
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
LPCWSTR pszIcon
Definition: prsht.h:281
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwSize
Definition: prsht.h:275
DWORD dwFlags
Definition: prsht.h:276
#define CPL_INIT
Definition: cpl.h:12
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PSNRET_NOERROR
Definition: prsht.h:129
INT WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
Definition: console.c:372
#define CPL_INQUIRE
Definition: cpl.h:14
static const WCHAR L[]
Definition: oid.c:1250
static BOOL SaveConsoleInfo
Definition: console.c:26
LPARAM lParam
Definition: prsht.h:218
HINSTANCE hInstance
Definition: prsht.h:207
INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: magnifier.c:860
#define WM_COMMAND
Definition: winuser.h:1722
int idName
Definition: cpl.h:26
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2870
#define IDD_PROPPAGEFONT
Definition: resource.h:13
#define IDD_APPLYOPTIONS
Definition: resource.h:16
#define PSCB_INITIALIZED
Definition: prsht.h:75
HICON hIcon
Definition: msconfig.c:44
#define PSH_PROPSHEETPAGE
Definition: prsht.h:43
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
FONT_PREVIEW FontPreview
Definition: font.c:21
VOID RefreshFontPreview(IN FONT_PREVIEW *Preview, IN PCONSOLE_STATE_INFO pConInfo)
Definition: font.c:49
PCONSOLE_STATE_INFO ConInfo
Definition: console.c:23
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: console.c:137
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define ResetFontPreview(Preview)
Definition: console.h:65
WCHAR ConsoleTitle[ANYSIZE_ARRAY]
Definition: settings.h:58
#define BST_CHECKED
Definition: winuser.h:197
#define DPRINT1
Definition: precomp.h:8
GLuint res
Definition: glext.h:9613
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDCANCEL
Definition: winuser.h:825
#define UnmapViewOfFile
Definition: compat.h:403
BOOL RegisterWinPrevClass(IN HINSTANCE hInstance)
Definition: layout.c:32
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3217
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
DLGPROC DlgProc
Definition: desk.c:110
#define LOWORD(l)
Definition: pedump.c:82
static VOID InitPropSheetPage(PROPSHEETPAGEW *psp, WORD idDlg, DLGPROC DlgProc)
Definition: console.c:29
DWORD dwFlags
Definition: prsht.h:206
INT_PTR CALLBACK FontProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: font.c:699
#define IDC_RADIO_APPLY_ALL
Definition: resource.h:34
#define HeapFree(x, y, z)
Definition: compat.h:394
#define CPL_GETCOUNT
Definition: cpl.h:13
#define APIENTRY
Definition: api.h:79
#define ICON_BIG
Definition: tnclass.cpp:51
#define WM_SETCONSOLEINFO
Definition: settings.h:21
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define IDD_PROPPAGECOLORS
Definition: resource.h:15
UINT nStartPage
Definition: prsht.h:286