Sync with trunk r62529.
[reactos.git] / dll / cpl / console / options.c
1 /*
2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/console/options.c
5 * PURPOSE: displays options dialog
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 */
8
9 #include "console.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 static
15 void
16 UpdateDialogElements(HWND hwndDlg, PCONSOLE_PROPS pConInfo);
17
18 INT_PTR
19 CALLBACK
20 OptionsProc(HWND hwndDlg,
21 UINT uMsg,
22 WPARAM wParam,
23 LPARAM lParam)
24 {
25 PCONSOLE_PROPS pConInfo;
26 PGUI_CONSOLE_INFO GuiInfo;
27 LRESULT lResult;
28 HWND hDlgCtrl;
29 LPPSHNOTIFY lppsn;
30
31 pConInfo = (PCONSOLE_PROPS)GetWindowLongPtr(hwndDlg, DWLP_USER);
32
33 switch (uMsg)
34 {
35 case WM_INITDIALOG:
36 {
37 pConInfo = (PCONSOLE_PROPS)((LPPROPSHEETPAGE)lParam)->lParam;
38 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
39 UpdateDialogElements(hwndDlg, pConInfo);
40 return TRUE;
41 }
42 case WM_NOTIFY:
43 {
44 if (!pConInfo) break;
45
46 lppsn = (LPPSHNOTIFY) lParam;
47 if (lppsn->hdr.code == UDN_DELTAPOS)
48 {
49 hDlgCtrl = GetDlgItem(hwndDlg, IDC_EDIT_BUFFER_SIZE);
50 pConInfo->ci.HistoryBufferSize = LOWORD(SendMessage(hDlgCtrl, UDM_GETPOS, 0, 0));
51
52 hDlgCtrl = GetDlgItem(hwndDlg, IDC_EDIT_NUM_BUFFER);
53 pConInfo->ci.NumberOfHistoryBuffers = LOWORD(SendMessage(hDlgCtrl, UDM_GETPOS, 0, 0));
54 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
55 }
56 else if (lppsn->hdr.code == PSN_APPLY)
57 {
58 if (!pConInfo->AppliedConfig)
59 {
60 return ApplyConsoleInfo(hwndDlg, pConInfo);
61 }
62 else
63 {
64 /* Options have already been applied */
65 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
66 return TRUE;
67 }
68 }
69 break;
70 }
71 case WM_COMMAND:
72 {
73 if (!pConInfo) break;
74 GuiInfo = pConInfo->TerminalInfo.TermInfo;
75
76 switch (LOWORD(wParam))
77 {
78 case IDC_RADIO_SMALL_CURSOR:
79 {
80 pConInfo->ci.CursorSize = 25;
81 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
82 break;
83 }
84 case IDC_RADIO_MEDIUM_CURSOR:
85 {
86 pConInfo->ci.CursorSize = 50;
87 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
88 break;
89 }
90 case IDC_RADIO_LARGE_CURSOR:
91 {
92 pConInfo->ci.CursorSize = 100;
93 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
94 break;
95 }
96 case IDC_RADIO_DISPLAY_WINDOW:
97 {
98 GuiInfo->FullScreen = FALSE;
99 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
100 break;
101 }
102 case IDC_RADIO_DISPLAY_FULL:
103 {
104 GuiInfo->FullScreen = TRUE;
105 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
106 break;
107 }
108 case IDC_CHECK_QUICK_EDIT:
109 {
110 lResult = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
111 if (lResult == BST_CHECKED)
112 {
113 pConInfo->ci.QuickEdit = FALSE;
114 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
115 }
116 else if (lResult == BST_UNCHECKED)
117 {
118 pConInfo->ci.QuickEdit = TRUE;
119 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
120 }
121 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
122 break;
123 }
124 case IDC_CHECK_INSERT_MODE:
125 {
126 lResult = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
127 if (lResult == BST_CHECKED)
128 {
129 pConInfo->ci.InsertMode = FALSE;
130 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
131 }
132 else if (lResult == BST_UNCHECKED)
133 {
134 pConInfo->ci.InsertMode = TRUE;
135 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
136 }
137 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
138 break;
139 }
140 case IDC_CHECK_DISCARD_DUPLICATES:
141 {
142 lResult = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
143 if (lResult == BST_CHECKED)
144 {
145 pConInfo->ci.HistoryNoDup = FALSE;
146 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
147 }
148 else if (lResult == BST_UNCHECKED)
149 {
150 pConInfo->ci.HistoryNoDup = TRUE;
151 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
152 }
153 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
154 break;
155 }
156 default:
157 break;
158 }
159 break;
160 }
161 default:
162 break;
163 }
164
165 return FALSE;
166 }
167
168 static
169 void
170 UpdateDialogElements(HWND hwndDlg, PCONSOLE_PROPS pConInfo)
171 {
172 PGUI_CONSOLE_INFO GuiInfo = pConInfo->TerminalInfo.TermInfo;
173 HWND hDlgCtrl;
174 TCHAR szBuffer[MAX_PATH];
175
176 /* Update cursor size */
177 if (pConInfo->ci.CursorSize <= 25)
178 {
179 /* Small cursor */
180 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_SMALL_CURSOR);
181 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
182
183 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_MEDIUM_CURSOR);
184 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
185 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_LARGE_CURSOR);
186 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
187 }
188 else if (pConInfo->ci.CursorSize <= 50)
189 {
190 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_MEDIUM_CURSOR);
191 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
192
193 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_SMALL_CURSOR);
194 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
195 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_LARGE_CURSOR);
196 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
197 }
198 else /* if (pConInfo->ci.CursorSize <= 100) */
199 {
200 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_LARGE_CURSOR);
201 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
202
203 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_SMALL_CURSOR);
204 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
205 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_MEDIUM_CURSOR);
206 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
207 }
208
209 /* Update num buffers */
210 hDlgCtrl = GetDlgItem(hwndDlg, IDC_UPDOWN_NUM_BUFFER);
211 SendMessage(hDlgCtrl, UDM_SETRANGE, 0, MAKELONG((short)999, (short)1));
212 hDlgCtrl = GetDlgItem(hwndDlg, IDC_EDIT_NUM_BUFFER);
213 _stprintf(szBuffer, _T("%d"), pConInfo->ci.NumberOfHistoryBuffers);
214 SendMessage(hDlgCtrl, WM_SETTEXT, 0, (LPARAM)szBuffer);
215
216 /* Update buffer size */
217 hDlgCtrl = GetDlgItem(hwndDlg, IDC_UPDOWN_BUFFER_SIZE);
218 SendMessage(hDlgCtrl, UDM_SETRANGE, 0, MAKELONG((short)999, (short)1));
219 hDlgCtrl = GetDlgItem(hwndDlg, IDC_EDIT_BUFFER_SIZE);
220 _stprintf(szBuffer, _T("%d"), pConInfo->ci.HistoryBufferSize);
221 SendMessage(hDlgCtrl, WM_SETTEXT, 0, (LPARAM)szBuffer);
222
223 /* Update discard duplicates */
224 hDlgCtrl = GetDlgItem(hwndDlg, IDC_CHECK_DISCARD_DUPLICATES);
225 if (pConInfo->ci.HistoryNoDup)
226 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
227 else
228 SendMessage(hDlgCtrl, BM_SETCHECK, (LPARAM)BST_UNCHECKED, 0);
229
230 /* Update full/window screen */
231 if (GuiInfo->FullScreen)
232 {
233 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_DISPLAY_FULL);
234 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
235
236 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_DISPLAY_WINDOW);
237 SendMessage(hDlgCtrl, BM_SETCHECK, (LPARAM)BST_UNCHECKED, 0);
238 }
239 else
240 {
241 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_DISPLAY_WINDOW);
242 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
243
244 hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_DISPLAY_FULL);
245 SendMessage(hDlgCtrl, BM_SETCHECK, (LPARAM)BST_UNCHECKED, 0);
246 }
247
248 /* Update quick edit */
249 hDlgCtrl = GetDlgItem(hwndDlg, IDC_CHECK_QUICK_EDIT);
250 if (pConInfo->ci.QuickEdit)
251 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
252 else
253 SendMessage(hDlgCtrl, BM_SETCHECK, (LPARAM)BST_UNCHECKED, 0);
254
255 /* Update insert mode */
256 hDlgCtrl = GetDlgItem(hwndDlg, IDC_CHECK_INSERT_MODE);
257 if (pConInfo->ci.InsertMode)
258 SendMessage(hDlgCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
259 else
260 SendMessage(hDlgCtrl, BM_SETCHECK, (LPARAM)BST_UNCHECKED, 0);
261 }