2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/console/console.c
5 * PURPOSE: Initialization
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
17 LONG APIENTRY
InitApplet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
);
18 INT_PTR CALLBACK
OptionsProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
19 INT_PTR CALLBACK
FontProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
20 INT_PTR CALLBACK
LayoutProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
21 INT_PTR CALLBACK
ColorsProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
23 HINSTANCE hApplet
= 0;
26 APPLET Applets
[NUM_APPLETS
] =
28 {IDC_CPLICON
, IDS_CPLNAME
, IDS_CPLDESCRIPTION
, InitApplet
}
32 * Default 16-color palette for foreground and background
33 * (corresponding flags in comments).
35 const COLORREF s_Colors
[16] =
37 RGB(0, 0, 0), // (Black)
38 RGB(0, 0, 128), // BLUE
39 RGB(0, 128, 0), // GREEN
40 RGB(0, 128, 128), // BLUE | GREEN
41 RGB(128, 0, 0), // RED
42 RGB(128, 0, 128), // BLUE | RED
43 RGB(128, 128, 0), // GREEN | RED
44 RGB(192, 192, 192), // BLUE | GREEN | RED
46 RGB(128, 128, 128), // (Grey) INTENSITY
47 RGB(0, 0, 255), // BLUE | INTENSITY
48 RGB(0, 255, 0), // GREEN | INTENSITY
49 RGB(0, 255, 255), // BLUE | GREEN | INTENSITY
50 RGB(255, 0, 0), // RED | INTENSITY
51 RGB(255, 0, 255), // BLUE | RED | INTENSITY
52 RGB(255, 255, 0), // GREEN | RED | INTENSITY
53 RGB(255, 255, 255) // BLUE | GREEN | RED | INTENSITY
55 /* Default attributes */
56 #define DEFAULT_SCREEN_ATTRIB (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
57 #define DEFAULT_POPUP_ATTRIB (FOREGROUND_BLUE | FOREGROUND_RED | \
58 BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
60 #define CSR_DEFAULT_CURSOR_SIZE 25
63 InitPropSheetPage(PROPSHEETPAGEW
*psp
,
68 ZeroMemory(psp
, sizeof(PROPSHEETPAGEW
));
69 psp
->dwSize
= sizeof(PROPSHEETPAGEW
);
70 psp
->dwFlags
= PSP_DEFAULT
;
71 psp
->hInstance
= hApplet
;
72 psp
->pszTemplate
= MAKEINTRESOURCEW(idDlg
);
73 psp
->pfnDlgProc
= DlgProc
;
80 /* Adapted for holding GUI terminal information */
81 return HeapAlloc(GetProcessHeap(),
83 sizeof(CONSOLE_PROPS
) + sizeof(GUI_CONSOLE_INFO
));
87 InitConsoleDefaults(PCONSOLE_PROPS pConInfo
)
89 PGUI_CONSOLE_INFO GuiInfo
= NULL
;
91 /* FIXME: Get also the defaults from the registry */
93 /* Initialize the default properties */
94 pConInfo
->ci
.HistoryBufferSize
= 50;
95 pConInfo
->ci
.NumberOfHistoryBuffers
= 4;
96 pConInfo
->ci
.HistoryNoDup
= FALSE
;
97 pConInfo
->ci
.QuickEdit
= FALSE
;
98 pConInfo
->ci
.InsertMode
= TRUE
;
99 // pConInfo->ci.InputBufferSize;
100 pConInfo
->ci
.ScreenBufferSize
.X
= 80;
101 pConInfo
->ci
.ScreenBufferSize
.Y
= 300;
102 pConInfo
->ci
.ConsoleSize
.X
= 80;
103 pConInfo
->ci
.ConsoleSize
.Y
= 25;
104 pConInfo
->ci
.CursorBlinkOn
= TRUE
;
105 pConInfo
->ci
.ForceCursorOff
= FALSE
;
106 pConInfo
->ci
.CursorSize
= CSR_DEFAULT_CURSOR_SIZE
;
107 pConInfo
->ci
.ScreenAttrib
= DEFAULT_SCREEN_ATTRIB
;
108 pConInfo
->ci
.PopupAttrib
= DEFAULT_POPUP_ATTRIB
;
109 pConInfo
->ci
.CodePage
= 0;
110 pConInfo
->ci
.ConsoleTitle
[0] = L
'\0';
112 /* Adapted for holding GUI terminal information */
113 pConInfo
->TerminalInfo
.Size
= sizeof(GUI_CONSOLE_INFO
);
114 GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
= (PGUI_CONSOLE_INFO
)(pConInfo
+ 1);
115 wcsncpy(GuiInfo
->FaceName
, L
"VGA", LF_FACESIZE
); // HACK: !!
116 // GuiInfo->FaceName[0] = L'\0';
117 GuiInfo
->FontFamily
= FF_DONTCARE
;
118 GuiInfo
->FontSize
= 0;
119 GuiInfo
->FontWeight
= FW_DONTCARE
;
120 GuiInfo
->UseRasterFonts
= TRUE
;
122 GuiInfo
->FullScreen
= FALSE
;
123 GuiInfo
->ShowWindow
= SW_SHOWNORMAL
;
124 GuiInfo
->AutoPosition
= TRUE
;
125 GuiInfo
->WindowOrigin
.x
= 0;
126 GuiInfo
->WindowOrigin
.y
= 0;
128 memcpy(pConInfo
->ci
.Colors
, s_Colors
, sizeof(s_Colors
));
133 ApplyProc(HWND hwndDlg
,
138 UNREFERENCED_PARAMETER(lParam
);
144 CheckDlgButton(hwndDlg
, IDC_RADIO_APPLY_CURRENT
, BST_CHECKED
);
149 if (LOWORD(wParam
) == IDOK
)
151 if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_APPLY_CURRENT
) == BST_CHECKED
)
152 EndDialog(hwndDlg
, IDC_RADIO_APPLY_CURRENT
);
154 EndDialog(hwndDlg
, IDC_RADIO_APPLY_ALL
);
156 else if (LOWORD(wParam
) == IDCANCEL
)
158 EndDialog(hwndDlg
, IDCANCEL
);
170 ApplyConsoleInfo(HWND hwndDlg
,
171 PCONSOLE_PROPS pConInfo
)
173 BOOL SetParams
= FALSE
;
174 BOOL SaveParams
= FALSE
;
177 * If we are setting the default parameters, just save them,
178 * otherwise display the save-confirmation dialog.
180 if (pConInfo
->ShowDefaultParams
)
187 INT_PTR res
= DialogBoxW(hApplet
, MAKEINTRESOURCEW(IDD_APPLYOPTIONS
), hwndDlg
, ApplyProc
);
189 SetParams
= (res
!= IDCANCEL
);
190 SaveParams
= (res
== IDC_RADIO_APPLY_ALL
);
192 if (SetParams
== FALSE
)
194 /* Don't destroy when user presses cancel */
195 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
203 PCONSOLE_PROPS pSharedInfo
;
206 * Create a memory section to share with the server, and map it.
208 /* Holds data for console.dll + console info + terminal-specific info */
209 hSection
= CreateFileMappingW(INVALID_HANDLE_VALUE
,
213 sizeof(CONSOLE_PROPS
) + sizeof(GUI_CONSOLE_INFO
),
217 DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
221 pSharedInfo
= MapViewOfFile(hSection
, FILE_MAP_ALL_ACCESS
, 0, 0, 0);
224 DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
225 CloseHandle(hSection
);
229 /* We are applying the chosen configuration */
230 pConInfo
->AppliedConfig
= TRUE
;
233 * Copy the console information into the section and
234 * offsetize the address of terminal-specific information.
235 * Do not perform the offsetization in pConInfo as it is
236 * likely to be reused later on. Instead, do it in pSharedInfo
237 * after having copied all the data.
239 RtlCopyMemory(pSharedInfo
, pConInfo
, sizeof(CONSOLE_PROPS
) + sizeof(GUI_CONSOLE_INFO
));
240 pSharedInfo
->TerminalInfo
.TermInfo
= (PVOID
)((ULONG_PTR
)pConInfo
->TerminalInfo
.TermInfo
- (ULONG_PTR
)pConInfo
);
243 UnmapViewOfFile(pSharedInfo
);
245 /* Signal to the console server that it can apply the new configuration */
246 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
247 SendMessage(pConInfo
->hConsoleWindow
,
248 PM_APPLY_CONSOLE_INFO
,
252 /* Close the section and return */
253 CloseHandle(hSection
);
261 InitApplet(HWND hWnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
)
263 HANDLE hSection
= (HANDLE
)wParam
;
264 PCONSOLE_PROPS pSharedInfo
= NULL
;
265 PCONSOLE_PROPS pConInfo
;
266 WCHAR szTitle
[MAX_PATH
+ 1];
267 PROPSHEETPAGEW psp
[4];
268 PROPSHEETHEADERW psh
;
271 UNREFERENCED_PARAMETER(uMsg
);
274 * CONSOLE.DLL shares information with CONSRV with wParam:
275 * wParam is a handle to a shared section holding a CONSOLE_PROPS struct.
277 * NOTE: lParam is not used.
280 /* Allocate a local buffer to hold console information */
281 pConInfo
= AllocConsoleInfo();
282 if (!pConInfo
) return 0;
284 /* Check whether we were launched from the terminal... */
285 if (hSection
!= NULL
)
287 /* ... yes, map the shared section */
288 pSharedInfo
= MapViewOfFile(hSection
, FILE_MAP_READ
, 0, 0, 0);
289 if (pSharedInfo
== NULL
)
292 HeapFree(GetProcessHeap(), 0, pConInfo
);
294 /* Close the section */
295 CloseHandle(hSection
);
300 /* Find the console window and whether we set the default parameters */
301 pConInfo
->hConsoleWindow
= pSharedInfo
->hConsoleWindow
;
302 pConInfo
->ShowDefaultParams
= pSharedInfo
->ShowDefaultParams
;
306 /* ... no, we were launched as a CPL. Display the default settings. */
307 pConInfo
->ShowDefaultParams
= TRUE
;
310 if (pConInfo
->ShowDefaultParams
)
313 InitConsoleDefaults(pConInfo
);
315 else if (hSection
&& pSharedInfo
)
318 * Copy the shared data into our allocated buffer, and
319 * de-offsetize the address of terminal-specific information.
322 /* Check that we are really going to modify GUI terminal information */
323 // FIXME: Do something clever, for example copy the UI-independent part
324 // and init the UI-dependent part to some default values...
325 ASSERT(pSharedInfo
->TerminalInfo
.Size
== sizeof(GUI_CONSOLE_INFO
));
326 ASSERT(pSharedInfo
->TerminalInfo
.TermInfo
);
328 RtlCopyMemory(pConInfo
, pSharedInfo
, sizeof(CONSOLE_PROPS
) + sizeof(GUI_CONSOLE_INFO
));
329 pConInfo
->TerminalInfo
.TermInfo
= (PVOID
)((ULONG_PTR
)pConInfo
+ (ULONG_PTR
)pConInfo
->TerminalInfo
.TermInfo
);
332 if (hSection
&& pSharedInfo
)
334 /* Close the section */
335 UnmapViewOfFile(pSharedInfo
);
336 CloseHandle(hSection
);
339 /* Initialize the property sheet structure */
340 ZeroMemory(&psh
, sizeof(PROPSHEETHEADERW
));
341 psh
.dwSize
= sizeof(PROPSHEETHEADERW
);
342 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_PROPTITLE
| /* PSH_USEHICON */ PSH_USEICONID
| PSH_NOAPPLYNOW
;
344 if (pConInfo
->ci
.ConsoleTitle
[0] != L
'\0')
346 wcsncpy(szTitle
, L
"\"", MAX_PATH
);
347 wcsncat(szTitle
, pConInfo
->ci
.ConsoleTitle
, MAX_PATH
- wcslen(szTitle
));
348 wcsncat(szTitle
, L
"\"", MAX_PATH
- wcslen(szTitle
));
352 wcscpy(szTitle
, L
"ReactOS Console");
354 psh
.pszCaption
= szTitle
;
356 psh
.hwndParent
= pConInfo
->hConsoleWindow
;
357 psh
.hInstance
= hApplet
;
358 // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCEW(IDC_CPLICON));
359 psh
.pszIcon
= MAKEINTRESOURCEW(IDC_CPLICON
);
364 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGEOPTIONS
, (DLGPROC
) OptionsProc
, (LPARAM
)pConInfo
);
365 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGEFONT
, (DLGPROC
) FontProc
, (LPARAM
)pConInfo
);
366 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGELAYOUT
, (DLGPROC
) LayoutProc
, (LPARAM
)pConInfo
);
367 InitPropSheetPage(&psp
[i
++], IDD_PROPPAGECOLORS
, (DLGPROC
) ColorsProc
, (LPARAM
)pConInfo
);
369 return (PropertySheetW(&psh
) != -1);
372 /* Control Panel Callback */
374 CPlApplet(HWND hwndCPl
,
385 // TODO: Free allocated memory
393 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
394 CPlInfo
->idIcon
= Applets
[0].idIcon
;
395 CPlInfo
->idName
= Applets
[0].idName
;
396 CPlInfo
->idInfo
= Applets
[0].idDescription
;
401 InitApplet(hwndCPl
, uMsg
, lParam1
, lParam2
);
411 DllMain(HINSTANCE hinstDLL
,
415 UNREFERENCED_PARAMETER(lpvReserved
);
419 case DLL_PROCESS_ATTACH
:
420 case DLL_THREAD_ATTACH
: