fe8abbf4 |
1 | /* |
2 | * wincfg.c - the Windows-specific parts of the PuTTY configuration |
3 | * box. |
4 | */ |
5 | |
fe8abbf4 |
6 | #include <assert.h> |
7 | #include <stdlib.h> |
8 | |
9 | #include "putty.h" |
10 | #include "dialog.h" |
11 | #include "storage.h" |
12 | |
13 | static void about_handler(union control *ctrl, void *dlg, |
14 | void *data, int event) |
15 | { |
16 | HWND *hwndp = (HWND *)ctrl->generic.context.p; |
17 | |
18 | if (event == EVENT_ACTION) { |
19 | modal_about_box(*hwndp); |
20 | } |
21 | } |
22 | |
23 | static void help_handler(union control *ctrl, void *dlg, |
24 | void *data, int event) |
25 | { |
26 | HWND *hwndp = (HWND *)ctrl->generic.context.p; |
27 | |
28 | if (event == EVENT_ACTION) { |
29 | show_help(*hwndp); |
30 | } |
31 | } |
32 | |
14ce9887 |
33 | static void variable_pitch_handler(union control *ctrl, void *dlg, |
34 | void *data, int event) |
35 | { |
36 | if (event == EVENT_REFRESH) { |
37 | dlg_checkbox_set(ctrl, dlg, !dlg_get_fixed_pitch_flag(dlg)); |
38 | } else if (event == EVENT_VALCHANGE) { |
39 | dlg_set_fixed_pitch_flag(dlg, !dlg_checkbox_get(ctrl, dlg)); |
40 | } |
41 | } |
42 | |
fe8abbf4 |
43 | void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, |
8a7f1392 |
44 | int midsession, int protocol) |
fe8abbf4 |
45 | { |
46 | struct controlset *s; |
47 | union control *c; |
f6f450e2 |
48 | char *str; |
fe8abbf4 |
49 | |
50 | if (!midsession) { |
51 | /* |
52 | * Add the About and Help buttons to the standard panel. |
53 | */ |
54 | s = ctrl_getset(b, "", "", ""); |
55 | c = ctrl_pushbutton(s, "About", 'a', HELPCTX(no_help), |
56 | about_handler, P(hwndp)); |
57 | c->generic.column = 0; |
58 | if (has_help) { |
59 | c = ctrl_pushbutton(s, "Help", 'h', HELPCTX(no_help), |
60 | help_handler, P(hwndp)); |
61 | c->generic.column = 1; |
62 | } |
63 | } |
64 | |
65 | /* |
1d0d4a3b |
66 | * Full-screen mode is a Windows peculiarity; hence |
67 | * scrollbar_in_fullscreen is as well. |
68 | */ |
69 | s = ctrl_getset(b, "Window", "scrollback", |
70 | "Control the scrollback in the window"); |
71 | ctrl_checkbox(s, "Display scrollbar in full screen mode", 'i', |
72 | HELPCTX(window_scrollback), |
4a693cfc |
73 | conf_checkbox_handler, |
74 | I(CONF_scrollbar_in_fullscreen)); |
1d0d4a3b |
75 | /* |
76 | * Really this wants to go just after `Display scrollbar'. See |
77 | * if we can find that control, and do some shuffling. |
78 | */ |
79 | { |
80 | int i; |
81 | for (i = 0; i < s->ncontrols; i++) { |
82 | c = s->ctrls[i]; |
83 | if (c->generic.type == CTRL_CHECKBOX && |
4a693cfc |
84 | c->generic.context.i == CONF_scrollbar) { |
1d0d4a3b |
85 | /* |
86 | * Control i is the scrollbar checkbox. |
87 | * Control s->ncontrols-1 is the scrollbar-in-FS one. |
88 | */ |
89 | if (i < s->ncontrols-2) { |
90 | c = s->ctrls[s->ncontrols-1]; |
91 | memmove(s->ctrls+i+2, s->ctrls+i+1, |
92 | (s->ncontrols-i-2)*sizeof(union control *)); |
93 | s->ctrls[i+1] = c; |
94 | } |
95 | break; |
96 | } |
97 | } |
98 | } |
99 | |
100 | /* |
fe8abbf4 |
101 | * Windows has the AltGr key, which has various Windows- |
102 | * specific options. |
103 | */ |
104 | s = ctrl_getset(b, "Terminal/Keyboard", "features", |
105 | "Enable extra keyboard features:"); |
106 | ctrl_checkbox(s, "AltGr acts as Compose key", 't', |
107 | HELPCTX(keyboard_compose), |
4a693cfc |
108 | conf_checkbox_handler, I(CONF_compose_key)); |
fe8abbf4 |
109 | ctrl_checkbox(s, "Control-Alt is different from AltGr", 'd', |
110 | HELPCTX(keyboard_ctrlalt), |
4a693cfc |
111 | conf_checkbox_handler, I(CONF_ctrlaltkeys)); |
fe8abbf4 |
112 | |
113 | /* |
85f6b361 |
114 | * Windows allows an arbitrary .WAV to be played as a bell, and |
115 | * also the use of the PC speaker. For this we must search the |
116 | * existing controlset for the radio-button set controlling the |
117 | * `beep' option, and add extra buttons to it. |
fe8abbf4 |
118 | * |
119 | * Note that although this _looks_ like a hideous hack, it's |
120 | * actually all above board. The well-defined interface to the |
121 | * per-platform dialog box code is the _data structures_ `union |
122 | * control', `struct controlset' and so on; so code like this |
123 | * that reaches into those data structures and changes bits of |
124 | * them is perfectly legitimate and crosses no boundaries. All |
125 | * the ctrl_* routines that create most of the controls are |
126 | * convenient shortcuts provided on the cross-platform side of |
127 | * the interface, and template creation code is under no actual |
128 | * obligation to use them. |
129 | */ |
130 | s = ctrl_getset(b, "Terminal/Bell", "style", "Set the style of bell"); |
131 | { |
132 | int i; |
133 | for (i = 0; i < s->ncontrols; i++) { |
134 | c = s->ctrls[i]; |
135 | if (c->generic.type == CTRL_RADIO && |
4a693cfc |
136 | c->generic.context.i == CONF_beep) { |
137 | assert(c->generic.handler == conf_radiobutton_handler); |
85f6b361 |
138 | c->radio.nbuttons += 2; |
fe8abbf4 |
139 | c->radio.buttons = |
3d88e64d |
140 | sresize(c->radio.buttons, c->radio.nbuttons, char *); |
fe8abbf4 |
141 | c->radio.buttons[c->radio.nbuttons-1] = |
142 | dupstr("Play a custom sound file"); |
85f6b361 |
143 | c->radio.buttons[c->radio.nbuttons-2] = |
144 | dupstr("Beep using the PC speaker"); |
fe8abbf4 |
145 | c->radio.buttondata = |
3d88e64d |
146 | sresize(c->radio.buttondata, c->radio.nbuttons, intorptr); |
fe8abbf4 |
147 | c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE); |
85f6b361 |
148 | c->radio.buttondata[c->radio.nbuttons-2] = I(BELL_PCSPEAKER); |
fe8abbf4 |
149 | if (c->radio.shortcuts) { |
150 | c->radio.shortcuts = |
3d88e64d |
151 | sresize(c->radio.shortcuts, c->radio.nbuttons, char); |
fe8abbf4 |
152 | c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT; |
85f6b361 |
153 | c->radio.shortcuts[c->radio.nbuttons-2] = NO_SHORTCUT; |
fe8abbf4 |
154 | } |
155 | break; |
156 | } |
157 | } |
158 | } |
159 | ctrl_filesel(s, "Custom sound file to play as a bell:", NO_SHORTCUT, |
160 | FILTER_WAVE_FILES, FALSE, "Select bell sound file", |
161 | HELPCTX(bell_style), |
4a693cfc |
162 | conf_filesel_handler, I(CONF_bell_wavefile)); |
fe8abbf4 |
163 | |
164 | /* |
165 | * While we've got this box open, taskbar flashing on a bell is |
166 | * also Windows-specific. |
167 | */ |
168 | ctrl_radiobuttons(s, "Taskbar/caption indication on bell:", 'i', 3, |
169 | HELPCTX(bell_taskbar), |
4a693cfc |
170 | conf_radiobutton_handler, |
171 | I(CONF_beep_ind), |
fe8abbf4 |
172 | "Disabled", I(B_IND_DISABLED), |
173 | "Flashing", I(B_IND_FLASH), |
174 | "Steady", I(B_IND_STEADY), NULL); |
175 | |
176 | /* |
177 | * The sunken-edge border is a Windows GUI feature. |
178 | */ |
179 | s = ctrl_getset(b, "Window/Appearance", "border", |
180 | "Adjust the window border"); |
181 | ctrl_checkbox(s, "Sunken-edge border (slightly thicker)", 's', |
182 | HELPCTX(appearance_border), |
4a693cfc |
183 | conf_checkbox_handler, I(CONF_sunken_edge)); |
fe8abbf4 |
184 | |
185 | /* |
17c7fed1 |
186 | * Configurable font quality settings for Windows. |
187 | */ |
188 | s = ctrl_getset(b, "Window/Appearance", "font", |
189 | "Font settings"); |
14ce9887 |
190 | ctrl_checkbox(s, "Allow selection of variable-pitch fonts", NO_SHORTCUT, |
191 | HELPCTX(appearance_font), variable_pitch_handler, I(0)); |
17c7fed1 |
192 | ctrl_radiobuttons(s, "Font quality:", 'q', 2, |
193 | HELPCTX(appearance_font), |
4a693cfc |
194 | conf_radiobutton_handler, |
195 | I(CONF_font_quality), |
17c7fed1 |
196 | "Antialiased", I(FQ_ANTIALIASED), |
197 | "Non-Antialiased", I(FQ_NONANTIALIASED), |
198 | "ClearType", I(FQ_CLEARTYPE), |
199 | "Default", I(FQ_DEFAULT), NULL); |
200 | |
201 | /* |
fe8abbf4 |
202 | * Cyrillic Lock is a horrid misfeature even on Windows, and |
203 | * the least we can do is ensure it never makes it to any other |
204 | * platform (at least unless someone fixes it!). |
205 | */ |
74790953 |
206 | s = ctrl_getset(b, "Window/Translation", "tweaks", NULL); |
fe8abbf4 |
207 | ctrl_checkbox(s, "Caps Lock acts as Cyrillic switch", 's', |
208 | HELPCTX(translation_cyrillic), |
4a693cfc |
209 | conf_checkbox_handler, |
210 | I(CONF_xlat_capslockcyr)); |
fe8abbf4 |
211 | |
212 | /* |
894ba831 |
213 | * On Windows we can use but not enumerate translation tables |
214 | * from the operating system. Briefly document this. |
215 | */ |
216 | s = ctrl_getset(b, "Window/Translation", "trans", |
217 | "Character set translation on received data"); |
218 | ctrl_text(s, "(Codepages supported by Windows but not listed here, " |
219 | "such as CP866 on many systems, can be entered manually)", |
220 | HELPCTX(translation_codepage)); |
221 | |
222 | /* |
fe8abbf4 |
223 | * Windows has the weird OEM font mode, which gives us some |
224 | * additional options when working with line-drawing |
225 | * characters. |
226 | */ |
f6f450e2 |
227 | str = dupprintf("Adjust how %s displays line drawing characters", appname); |
228 | s = ctrl_getset(b, "Window/Translation", "linedraw", str); |
229 | sfree(str); |
fe8abbf4 |
230 | { |
231 | int i; |
232 | for (i = 0; i < s->ncontrols; i++) { |
233 | c = s->ctrls[i]; |
234 | if (c->generic.type == CTRL_RADIO && |
4a693cfc |
235 | c->generic.context.i == CONF_vtmode) { |
236 | assert(c->generic.handler == conf_radiobutton_handler); |
3900c2d6 |
237 | c->radio.nbuttons += 3; |
fe8abbf4 |
238 | c->radio.buttons = |
3d88e64d |
239 | sresize(c->radio.buttons, c->radio.nbuttons, char *); |
3900c2d6 |
240 | c->radio.buttons[c->radio.nbuttons-3] = |
241 | dupstr("Font has XWindows encoding"); |
fe8abbf4 |
242 | c->radio.buttons[c->radio.nbuttons-2] = |
243 | dupstr("Use font in both ANSI and OEM modes"); |
244 | c->radio.buttons[c->radio.nbuttons-1] = |
245 | dupstr("Use font in OEM mode only"); |
246 | c->radio.buttondata = |
3d88e64d |
247 | sresize(c->radio.buttondata, c->radio.nbuttons, intorptr); |
3900c2d6 |
248 | c->radio.buttondata[c->radio.nbuttons-3] = I(VT_XWINDOWS); |
fe8abbf4 |
249 | c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI); |
250 | c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY); |
251 | if (!c->radio.shortcuts) { |
252 | int j; |
3d88e64d |
253 | c->radio.shortcuts = snewn(c->radio.nbuttons, char); |
fe8abbf4 |
254 | for (j = 0; j < c->radio.nbuttons; j++) |
255 | c->radio.shortcuts[j] = NO_SHORTCUT; |
256 | } else { |
3d88e64d |
257 | c->radio.shortcuts = sresize(c->radio.shortcuts, |
258 | c->radio.nbuttons, char); |
fe8abbf4 |
259 | } |
3900c2d6 |
260 | c->radio.shortcuts[c->radio.nbuttons-3] = 'x'; |
fe8abbf4 |
261 | c->radio.shortcuts[c->radio.nbuttons-2] = 'b'; |
262 | c->radio.shortcuts[c->radio.nbuttons-1] = 'e'; |
263 | break; |
264 | } |
265 | } |
266 | } |
267 | |
268 | /* |
269 | * RTF paste is Windows-specific. |
270 | */ |
00381fc7 |
271 | s = ctrl_getset(b, "Window/Selection", "format", |
272 | "Formatting of pasted characters"); |
fe8abbf4 |
273 | ctrl_checkbox(s, "Paste to clipboard in RTF as well as plain text", 'f', |
274 | HELPCTX(selection_rtf), |
4a693cfc |
275 | conf_checkbox_handler, I(CONF_rtf_paste)); |
fe8abbf4 |
276 | |
277 | /* |
278 | * Windows often has no middle button, so we supply a selection |
279 | * mode in which the more critical Paste action is available on |
280 | * the right button instead. |
281 | */ |
282 | s = ctrl_getset(b, "Window/Selection", "mouse", |
283 | "Control use of mouse"); |
ebc0310d |
284 | ctrl_radiobuttons(s, "Action of mouse buttons:", 'm', 1, |
fe8abbf4 |
285 | HELPCTX(selection_buttons), |
4a693cfc |
286 | conf_radiobutton_handler, |
287 | I(CONF_mouse_is_xterm), |
ebc0310d |
288 | "Windows (Middle extends, Right brings up menu)", I(2), |
289 | "Compromise (Middle extends, Right pastes)", I(0), |
290 | "xterm (Right extends, Middle pastes)", I(1), NULL); |
fe8abbf4 |
291 | /* |
292 | * This really ought to go at the _top_ of its box, not the |
293 | * bottom, so we'll just do some shuffling now we've set it |
294 | * up... |
295 | */ |
296 | c = s->ctrls[s->ncontrols-1]; /* this should be the new control */ |
297 | memmove(s->ctrls+1, s->ctrls, (s->ncontrols-1)*sizeof(union control *)); |
298 | s->ctrls[0] = c; |
299 | |
300 | /* |
301 | * Logical palettes don't even make sense anywhere except Windows. |
302 | */ |
303 | s = ctrl_getset(b, "Window/Colours", "general", |
304 | "General options for colour usage"); |
305 | ctrl_checkbox(s, "Attempt to use logical palettes", 'l', |
306 | HELPCTX(colours_logpal), |
4a693cfc |
307 | conf_checkbox_handler, I(CONF_try_palette)); |
26d1da7b |
308 | ctrl_checkbox(s, "Use system colours", 's', |
309 | HELPCTX(colours_system), |
4a693cfc |
310 | conf_checkbox_handler, I(CONF_system_colour)); |
26d1da7b |
311 | |
fe8abbf4 |
312 | |
313 | /* |
314 | * Resize-by-changing-font is a Windows insanity. |
315 | */ |
316 | s = ctrl_getset(b, "Window", "size", "Set the size of the window"); |
317 | ctrl_radiobuttons(s, "When window is resized:", 'z', 1, |
318 | HELPCTX(window_resize), |
4a693cfc |
319 | conf_radiobutton_handler, |
320 | I(CONF_resize_action), |
fe8abbf4 |
321 | "Change the number of rows and columns", I(RESIZE_TERM), |
322 | "Change the size of the font", I(RESIZE_FONT), |
323 | "Change font size only when maximised", I(RESIZE_EITHER), |
324 | "Forbid resizing completely", I(RESIZE_DISABLED), NULL); |
325 | |
326 | /* |
327 | * Most of the Window/Behaviour stuff is there to mimic Windows |
328 | * conventions which PuTTY can optionally disregard. Hence, |
329 | * most of these options are Windows-specific. |
330 | */ |
331 | s = ctrl_getset(b, "Window/Behaviour", "main", NULL); |
332 | ctrl_checkbox(s, "Window closes on ALT-F4", '4', |
333 | HELPCTX(behaviour_altf4), |
4a693cfc |
334 | conf_checkbox_handler, I(CONF_alt_f4)); |
fe8abbf4 |
335 | ctrl_checkbox(s, "System menu appears on ALT-Space", 'y', |
336 | HELPCTX(behaviour_altspace), |
4a693cfc |
337 | conf_checkbox_handler, I(CONF_alt_space)); |
fe8abbf4 |
338 | ctrl_checkbox(s, "System menu appears on ALT alone", 'l', |
339 | HELPCTX(behaviour_altonly), |
4a693cfc |
340 | conf_checkbox_handler, I(CONF_alt_only)); |
fe8abbf4 |
341 | ctrl_checkbox(s, "Ensure window is always on top", 'e', |
342 | HELPCTX(behaviour_alwaysontop), |
4a693cfc |
343 | conf_checkbox_handler, I(CONF_alwaysontop)); |
fe8abbf4 |
344 | ctrl_checkbox(s, "Full screen on Alt-Enter", 'f', |
345 | HELPCTX(behaviour_altenter), |
4a693cfc |
346 | conf_checkbox_handler, |
347 | I(CONF_fullscreenonaltenter)); |
0edafb21 |
348 | |
349 | /* |
350 | * Windows supports a local-command proxy. This also means we |
351 | * must adjust the text on the `Telnet command' control. |
352 | */ |
353 | if (!midsession) { |
354 | int i; |
355 | s = ctrl_getset(b, "Connection/Proxy", "basics", NULL); |
356 | for (i = 0; i < s->ncontrols; i++) { |
357 | c = s->ctrls[i]; |
358 | if (c->generic.type == CTRL_RADIO && |
4a693cfc |
359 | c->generic.context.i == CONF_proxy_type) { |
360 | assert(c->generic.handler == conf_radiobutton_handler); |
0edafb21 |
361 | c->radio.nbuttons++; |
362 | c->radio.buttons = |
363 | sresize(c->radio.buttons, c->radio.nbuttons, char *); |
364 | c->radio.buttons[c->radio.nbuttons-1] = |
365 | dupstr("Local"); |
366 | c->radio.buttondata = |
367 | sresize(c->radio.buttondata, c->radio.nbuttons, intorptr); |
368 | c->radio.buttondata[c->radio.nbuttons-1] = I(PROXY_CMD); |
369 | break; |
370 | } |
371 | } |
372 | |
373 | for (i = 0; i < s->ncontrols; i++) { |
374 | c = s->ctrls[i]; |
375 | if (c->generic.type == CTRL_EDITBOX && |
4a693cfc |
376 | c->generic.context.i == CONF_proxy_telnet_command) { |
377 | assert(c->generic.handler == conf_editbox_handler); |
0edafb21 |
378 | sfree(c->generic.label); |
379 | c->generic.label = dupstr("Telnet command, or local" |
380 | " proxy command"); |
381 | break; |
382 | } |
383 | } |
384 | } |
7374c779 |
385 | |
386 | /* |
387 | * Serial back end is available on Windows. |
388 | */ |
8a7f1392 |
389 | if (!midsession || (protocol == PROT_SERIAL)) |
390 | ser_setup_config_box(b, midsession, 0x1F, 0x0F); |
8def70c3 |
391 | |
392 | /* |
393 | * $XAUTHORITY is not reliable on Windows, so we provide a |
394 | * means to override it. |
395 | */ |
5ea184d1 |
396 | if (!midsession && backend_from_proto(PROT_SSH)) { |
2875af11 |
397 | s = ctrl_getset(b, "Connection/SSH/X11", "x11", "X11 forwarding"); |
398 | ctrl_filesel(s, "X authority file for local display", 't', |
399 | NULL, FALSE, "Select X authority file", |
400 | HELPCTX(ssh_tunnels_xauthority), |
4a693cfc |
401 | conf_filesel_handler, I(CONF_xauthfile)); |
2875af11 |
402 | } |
fe8abbf4 |
403 | } |