- Don't show applets on taskbar
[reactos.git] / reactos / dll / cpl / console / console.c
1 /* $Id$
2 *
3 * PROJECT: ReactOS Console Configuration DLL
4 * LICENSE: GPL - See COPYING in the top level directory
5 * FILE: dll/win32/console/console.c
6 * PURPOSE: initialization of DLL
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@student.tugraz.at)
8 */
9
10 #include "console.h"
11
12 #define NUM_APPLETS (1)
13 #define WM_SETCONSOLE (WM_USER+10)
14
15
16 LONG APIENTRY InitApplet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam);
17 INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
18 INT_PTR CALLBACK FontProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
19 INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
20 INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
21
22 HINSTANCE hApplet = 0;
23
24 /* Applets */
25 APPLET Applets[NUM_APPLETS] =
26 {
27 {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, InitApplet}
28 };
29
30 static COLORREF s_Colors[] =
31 {
32 RGB(0, 0, 0),
33 RGB(0, 0, 128),
34 RGB(0, 128, 0),
35 RGB(0, 128, 128),
36 RGB(128, 0, 0),
37 RGB(128, 0, 128),
38 RGB(128, 128, 0),
39 RGB(192, 192, 192),
40 RGB(128, 128, 128),
41 RGB(0, 0, 255),
42 RGB(0, 255, 0),
43 RGB(0, 255, 255),
44 RGB(255, 0, 0),
45 RGB(255, 0, 255),
46 RGB(255, 255, 0),
47 RGB(255, 255, 255)
48 };
49
50 static void
51 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam)
52 {
53 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
54 psp->dwSize = sizeof(PROPSHEETPAGE);
55 psp->dwFlags = PSP_DEFAULT;
56 psp->hInstance = hApplet;
57 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
58 psp->pfnDlgProc = DlgProc;
59 psp->lParam = lParam;
60 }
61
62 PConsoleInfo
63 AllocConsoleInfo()
64 {
65 PConsoleInfo pConInfo;
66
67 pConInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ConsoleInfo));
68
69 return pConInfo;
70 }
71
72 void
73 InitConsoleDefaults(PConsoleInfo pConInfo)
74 {
75 /* initialize struct */
76 pConInfo->InsertMode = TRUE;
77 pConInfo->HistoryBufferSize = 50;
78 pConInfo->NumberOfHistoryBuffers = 5;
79 pConInfo->ScreenText = RGB(192, 192, 192);
80 pConInfo->ScreenBackground = RGB(0, 0, 0);
81 pConInfo->PopupText = RGB(128, 0, 128);
82 pConInfo->PopupBackground = RGB(255, 255, 255);
83 pConInfo->WindowSize = (DWORD)MAKELONG(80, 25);
84 pConInfo->WindowPosition = UINT_MAX;
85 pConInfo->ScreenBuffer = MAKELONG(80, 300);
86 pConInfo->UseRasterFonts = TRUE;
87 pConInfo->FontSize = (DWORD)MAKELONG(8, 12);
88 pConInfo->FontWeight = FW_NORMAL;
89 memcpy(pConInfo->Colors, s_Colors, sizeof(s_Colors));
90 }
91
92
93 INT_PTR
94 CALLBACK
95 ApplyProc(
96 HWND hwndDlg,
97 UINT uMsg,
98 WPARAM wParam,
99 LPARAM lParam
100 )
101 {
102 HWND hDlgCtrl;
103
104 UNREFERENCED_PARAMETER(lParam);
105
106 switch(uMsg)
107 {
108 case WM_INITDIALOG:
109 {
110 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT);
111 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
112 return TRUE;
113 }
114 case WM_COMMAND:
115 {
116 if (LOWORD(wParam) == IDOK)
117 {
118 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT);
119 if ( SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED )
120 EndDialog(hwndDlg, IDC_RADIO_APPLY_CURRENT);
121 else
122 EndDialog(hwndDlg, IDC_RADIO_APPLY_ALL);
123 }
124 else if (LOWORD(wParam) == IDCANCEL)
125 {
126 EndDialog(hwndDlg, IDCANCEL);
127 }
128 break;
129 }
130 default:
131 break;
132 }
133 return FALSE;
134
135 }
136
137 void
138 ApplyConsoleInfo(HWND hwndDlg, PConsoleInfo pConInfo)
139 {
140 INT_PTR res = 0;
141
142 res = DialogBox(hApplet, MAKEINTRESOURCE(IDD_APPLYOPTIONS), hwndDlg, ApplyProc);
143
144 if (res == IDCANCEL)
145 {
146 /* dont destroy when user presses cancel */
147 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
148 }
149 else if ( res == IDC_RADIO_APPLY_ALL )
150 {
151 pConInfo->AppliedConfig = TRUE;
152 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
153 SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE);
154 }
155 else if ( res == IDC_RADIO_APPLY_CURRENT )
156 {
157 pConInfo->AppliedConfig = TRUE;
158 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
159 SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE);
160 }
161 }
162
163 /* First Applet */
164 LONG APIENTRY
165 InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
166 {
167 PROPSHEETPAGE psp[4];
168 PROPSHEETHEADER psh;
169 INT i=0;
170 PConsoleInfo pConInfo;
171 PConsoleInfo pSharedInfo = (PConsoleInfo)wParam;
172
173 UNREFERENCED_PARAMETER(uMsg);
174
175 /*
176 * console.dll shares information with win32csr with wParam, lParam
177 *
178 * wParam is a pointer to an ConsoleInfo struct
179 * lParam is a boolean parameter which specifies wheter defaults should be shown
180 */
181
182 pConInfo = AllocConsoleInfo();
183 if (!pConInfo)
184 {
185 return 0;
186 }
187
188 if (lParam)
189 {
190 /* use defaults */
191 InitConsoleDefaults(pConInfo);
192 }
193 else
194 {
195 if (IsBadReadPtr((const void *)pSharedInfo, sizeof(ConsoleInfo)))
196 {
197 /* use defaults */
198 InitConsoleDefaults(pConInfo);
199 }
200 else
201 {
202 pConInfo->InsertMode = pSharedInfo->InsertMode;
203 pConInfo->HistoryBufferSize = pSharedInfo->HistoryBufferSize;
204 pConInfo->NumberOfHistoryBuffers = pSharedInfo->NumberOfHistoryBuffers;
205 pConInfo->ScreenText = pSharedInfo->ScreenText;
206 pConInfo->ScreenBackground = pSharedInfo->ScreenBackground;
207 pConInfo->PopupText = pSharedInfo->PopupText;
208 pConInfo->PopupBackground = pSharedInfo->PopupBackground;
209 pConInfo->WindowSize = pSharedInfo->WindowSize;
210 pConInfo->WindowPosition = pSharedInfo->WindowPosition;
211 pConInfo->ScreenBuffer = pSharedInfo->ScreenBuffer;
212 pConInfo->UseRasterFonts = pSharedInfo->UseRasterFonts;
213 pConInfo->FontSize = pSharedInfo->FontSize;
214 pConInfo->FontWeight = pSharedInfo->FontWeight;
215 memcpy(pConInfo->Colors, pSharedInfo->Colors, sizeof(s_Colors));
216 }
217 }
218
219 /* console window -> is notified on a property change event */
220 pConInfo->hConsoleWindow = hwnd;
221
222 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
223 psh.dwSize = sizeof(PROPSHEETHEADER);
224 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
225
226 if(_tcslen(pConInfo->szProcessName))
227 {
228 psh.dwFlags |= PSH_PROPTITLE;
229 psh.pszCaption = pConInfo->szProcessName;
230 }
231
232 psh.hwndParent = hwnd;
233 psh.hInstance = hApplet;
234 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
235 psh.pszCaption = 0;
236 psh.nPages = 4;
237 psh.nStartPage = 0;
238 psh.ppsp = psp;
239
240 InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, (DLGPROC) OptionsProc, (LPARAM)pConInfo);
241 InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT, (DLGPROC) FontProc, (LPARAM)pConInfo);
242 InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT, (DLGPROC) LayoutProc, (LPARAM)pConInfo);
243 InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS, (DLGPROC) ColorsProc, (LPARAM)pConInfo);
244
245 return (PropertySheet(&psh) != -1);
246 }
247
248 /* Control Panel Callback */
249 LONG CALLBACK
250 CPlApplet(
251 HWND hwndCPl,
252 UINT uMsg,
253 LPARAM lParam1,
254 LPARAM lParam2)
255 {
256 switch(uMsg)
257 {
258 case CPL_INIT:
259 {
260 return TRUE;
261 }
262 case CPL_GETCOUNT:
263 {
264 return NUM_APPLETS;
265 }
266 case CPL_INQUIRE:
267 {
268 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
269 CPlInfo->idIcon = Applets[0].idIcon;
270 CPlInfo->idName = Applets[0].idName;
271 CPlInfo->idInfo = Applets[0].idDescription;
272 break;
273 }
274 case CPL_DBLCLK:
275 {
276 InitApplet(hwndCPl, uMsg, lParam1, lParam2);
277 break;
278 }
279 }
280 return FALSE;
281 }
282
283
284 INT
285 WINAPI
286 DllMain(
287 HINSTANCE hinstDLL,
288 DWORD dwReason,
289 LPVOID lpvReserved)
290 {
291 UNREFERENCED_PARAMETER(lpvReserved);
292
293 switch(dwReason)
294 {
295 case DLL_PROCESS_ATTACH:
296 case DLL_THREAD_ATTACH:
297 hApplet = hinstDLL;
298 break;
299 }
300 return TRUE;
301 }
302