fe8abbf4 |
1 | /* |
2 | * wincfg.c - the Windows-specific parts of the PuTTY configuration |
3 | * box. |
4 | */ |
5 | |
6 | #include <windows.h> |
7 | |
8 | #include <assert.h> |
9 | #include <stdlib.h> |
10 | |
11 | #include "putty.h" |
12 | #include "dialog.h" |
13 | #include "storage.h" |
14 | |
15 | static void about_handler(union control *ctrl, void *dlg, |
16 | void *data, int event) |
17 | { |
18 | HWND *hwndp = (HWND *)ctrl->generic.context.p; |
19 | |
20 | if (event == EVENT_ACTION) { |
21 | modal_about_box(*hwndp); |
22 | } |
23 | } |
24 | |
25 | static void help_handler(union control *ctrl, void *dlg, |
26 | void *data, int event) |
27 | { |
28 | HWND *hwndp = (HWND *)ctrl->generic.context.p; |
29 | |
30 | if (event == EVENT_ACTION) { |
31 | show_help(*hwndp); |
32 | } |
33 | } |
34 | |
35 | void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, |
36 | int midsession) |
37 | { |
38 | struct controlset *s; |
39 | union control *c; |
40 | |
41 | if (!midsession) { |
42 | /* |
43 | * Add the About and Help buttons to the standard panel. |
44 | */ |
45 | s = ctrl_getset(b, "", "", ""); |
46 | c = ctrl_pushbutton(s, "About", 'a', HELPCTX(no_help), |
47 | about_handler, P(hwndp)); |
48 | c->generic.column = 0; |
49 | if (has_help) { |
50 | c = ctrl_pushbutton(s, "Help", 'h', HELPCTX(no_help), |
51 | help_handler, P(hwndp)); |
52 | c->generic.column = 1; |
53 | } |
54 | } |
55 | |
56 | /* |
1d0d4a3b |
57 | * Full-screen mode is a Windows peculiarity; hence |
58 | * scrollbar_in_fullscreen is as well. |
59 | */ |
60 | s = ctrl_getset(b, "Window", "scrollback", |
61 | "Control the scrollback in the window"); |
62 | ctrl_checkbox(s, "Display scrollbar in full screen mode", 'i', |
63 | HELPCTX(window_scrollback), |
64 | dlg_stdcheckbox_handler, |
65 | I(offsetof(Config,scrollbar_in_fullscreen))); |
66 | /* |
67 | * Really this wants to go just after `Display scrollbar'. See |
68 | * if we can find that control, and do some shuffling. |
69 | */ |
70 | { |
71 | int i; |
72 | for (i = 0; i < s->ncontrols; i++) { |
73 | c = s->ctrls[i]; |
74 | if (c->generic.type == CTRL_CHECKBOX && |
75 | c->generic.context.i == offsetof(Config,scrollbar)) { |
76 | /* |
77 | * Control i is the scrollbar checkbox. |
78 | * Control s->ncontrols-1 is the scrollbar-in-FS one. |
79 | */ |
80 | if (i < s->ncontrols-2) { |
81 | c = s->ctrls[s->ncontrols-1]; |
82 | memmove(s->ctrls+i+2, s->ctrls+i+1, |
83 | (s->ncontrols-i-2)*sizeof(union control *)); |
84 | s->ctrls[i+1] = c; |
85 | } |
86 | break; |
87 | } |
88 | } |
89 | } |
90 | |
91 | /* |
fe8abbf4 |
92 | * Windows has the AltGr key, which has various Windows- |
93 | * specific options. |
94 | */ |
95 | s = ctrl_getset(b, "Terminal/Keyboard", "features", |
96 | "Enable extra keyboard features:"); |
97 | ctrl_checkbox(s, "AltGr acts as Compose key", 't', |
98 | HELPCTX(keyboard_compose), |
99 | dlg_stdcheckbox_handler, I(offsetof(Config,compose_key))); |
100 | ctrl_checkbox(s, "Control-Alt is different from AltGr", 'd', |
101 | HELPCTX(keyboard_ctrlalt), |
102 | dlg_stdcheckbox_handler, I(offsetof(Config,ctrlaltkeys))); |
103 | |
104 | /* |
105 | * Windows allows an arbitrary .WAV to be played as a bell. For |
106 | * this we must search the existing controlset for the |
107 | * radio-button set controlling the `beep' option, and add an |
108 | * extra button to it. |
109 | * |
110 | * Note that although this _looks_ like a hideous hack, it's |
111 | * actually all above board. The well-defined interface to the |
112 | * per-platform dialog box code is the _data structures_ `union |
113 | * control', `struct controlset' and so on; so code like this |
114 | * that reaches into those data structures and changes bits of |
115 | * them is perfectly legitimate and crosses no boundaries. All |
116 | * the ctrl_* routines that create most of the controls are |
117 | * convenient shortcuts provided on the cross-platform side of |
118 | * the interface, and template creation code is under no actual |
119 | * obligation to use them. |
120 | */ |
121 | s = ctrl_getset(b, "Terminal/Bell", "style", "Set the style of bell"); |
122 | { |
123 | int i; |
124 | for (i = 0; i < s->ncontrols; i++) { |
125 | c = s->ctrls[i]; |
126 | if (c->generic.type == CTRL_RADIO && |
127 | c->generic.context.i == offsetof(Config, beep)) { |
128 | assert(c->generic.handler == dlg_stdradiobutton_handler); |
129 | c->radio.nbuttons++; |
130 | c->radio.buttons = |
3d88e64d |
131 | sresize(c->radio.buttons, c->radio.nbuttons, char *); |
fe8abbf4 |
132 | c->radio.buttons[c->radio.nbuttons-1] = |
133 | dupstr("Play a custom sound file"); |
134 | c->radio.buttondata = |
3d88e64d |
135 | sresize(c->radio.buttondata, c->radio.nbuttons, intorptr); |
fe8abbf4 |
136 | c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE); |
137 | if (c->radio.shortcuts) { |
138 | c->radio.shortcuts = |
3d88e64d |
139 | sresize(c->radio.shortcuts, c->radio.nbuttons, char); |
fe8abbf4 |
140 | c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT; |
141 | } |
142 | break; |
143 | } |
144 | } |
145 | } |
146 | ctrl_filesel(s, "Custom sound file to play as a bell:", NO_SHORTCUT, |
147 | FILTER_WAVE_FILES, FALSE, "Select bell sound file", |
148 | HELPCTX(bell_style), |
149 | dlg_stdfilesel_handler, I(offsetof(Config, bell_wavefile))); |
150 | |
151 | /* |
152 | * While we've got this box open, taskbar flashing on a bell is |
153 | * also Windows-specific. |
154 | */ |
155 | ctrl_radiobuttons(s, "Taskbar/caption indication on bell:", 'i', 3, |
156 | HELPCTX(bell_taskbar), |
157 | dlg_stdradiobutton_handler, |
158 | I(offsetof(Config, beep_ind)), |
159 | "Disabled", I(B_IND_DISABLED), |
160 | "Flashing", I(B_IND_FLASH), |
161 | "Steady", I(B_IND_STEADY), NULL); |
162 | |
163 | /* |
164 | * The sunken-edge border is a Windows GUI feature. |
165 | */ |
166 | s = ctrl_getset(b, "Window/Appearance", "border", |
167 | "Adjust the window border"); |
168 | ctrl_checkbox(s, "Sunken-edge border (slightly thicker)", 's', |
169 | HELPCTX(appearance_border), |
170 | dlg_stdcheckbox_handler, I(offsetof(Config,sunken_edge))); |
171 | |
172 | /* |
173 | * Cyrillic Lock is a horrid misfeature even on Windows, and |
174 | * the least we can do is ensure it never makes it to any other |
175 | * platform (at least unless someone fixes it!). |
176 | */ |
177 | s = ctrl_getset(b, "Window/Translation", "input", |
178 | "Enable character set translation on input data"); |
179 | ctrl_checkbox(s, "Caps Lock acts as Cyrillic switch", 's', |
180 | HELPCTX(translation_cyrillic), |
181 | dlg_stdcheckbox_handler, |
182 | I(offsetof(Config,xlat_capslockcyr))); |
183 | |
184 | /* |
185 | * Windows has the weird OEM font mode, which gives us some |
186 | * additional options when working with line-drawing |
187 | * characters. |
188 | */ |
189 | s = ctrl_getset(b, "Window/Translation", "linedraw", |
190 | "Adjust how PuTTY displays line drawing characters"); |
191 | { |
192 | int i; |
193 | for (i = 0; i < s->ncontrols; i++) { |
194 | c = s->ctrls[i]; |
195 | if (c->generic.type == CTRL_RADIO && |
196 | c->generic.context.i == offsetof(Config, vtmode)) { |
197 | assert(c->generic.handler == dlg_stdradiobutton_handler); |
198 | c->radio.nbuttons += 2; |
199 | c->radio.buttons = |
3d88e64d |
200 | sresize(c->radio.buttons, c->radio.nbuttons, char *); |
fe8abbf4 |
201 | c->radio.buttons[c->radio.nbuttons-2] = |
202 | dupstr("Use font in both ANSI and OEM modes"); |
203 | c->radio.buttons[c->radio.nbuttons-1] = |
204 | dupstr("Use font in OEM mode only"); |
205 | c->radio.buttondata = |
3d88e64d |
206 | sresize(c->radio.buttondata, c->radio.nbuttons, intorptr); |
fe8abbf4 |
207 | c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI); |
208 | c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY); |
209 | if (!c->radio.shortcuts) { |
210 | int j; |
3d88e64d |
211 | c->radio.shortcuts = snewn(c->radio.nbuttons, char); |
fe8abbf4 |
212 | for (j = 0; j < c->radio.nbuttons; j++) |
213 | c->radio.shortcuts[j] = NO_SHORTCUT; |
214 | } else { |
3d88e64d |
215 | c->radio.shortcuts = sresize(c->radio.shortcuts, |
216 | c->radio.nbuttons, char); |
fe8abbf4 |
217 | } |
218 | c->radio.shortcuts[c->radio.nbuttons-2] = 'b'; |
219 | c->radio.shortcuts[c->radio.nbuttons-1] = 'e'; |
220 | break; |
221 | } |
222 | } |
223 | } |
224 | |
225 | /* |
226 | * RTF paste is Windows-specific. |
227 | */ |
228 | s = ctrl_getset(b, "Window/Selection", "trans", |
229 | "Translation of pasted characters"); |
230 | ctrl_checkbox(s, "Paste to clipboard in RTF as well as plain text", 'f', |
231 | HELPCTX(selection_rtf), |
232 | dlg_stdcheckbox_handler, I(offsetof(Config,rtf_paste))); |
233 | |
234 | /* |
235 | * Windows often has no middle button, so we supply a selection |
236 | * mode in which the more critical Paste action is available on |
237 | * the right button instead. |
238 | */ |
239 | s = ctrl_getset(b, "Window/Selection", "mouse", |
240 | "Control use of mouse"); |
241 | ctrl_radiobuttons(s, "Action of mouse buttons:", NO_SHORTCUT, 1, |
242 | HELPCTX(selection_buttons), |
243 | dlg_stdradiobutton_handler, |
244 | I(offsetof(Config, mouse_is_xterm)), |
245 | "Windows (Right pastes, Middle extends)", 'w', I(0), |
246 | "xterm (Right extends, Middle pastes)", 'x', I(1), NULL); |
247 | /* |
248 | * This really ought to go at the _top_ of its box, not the |
249 | * bottom, so we'll just do some shuffling now we've set it |
250 | * up... |
251 | */ |
252 | c = s->ctrls[s->ncontrols-1]; /* this should be the new control */ |
253 | memmove(s->ctrls+1, s->ctrls, (s->ncontrols-1)*sizeof(union control *)); |
254 | s->ctrls[0] = c; |
255 | |
256 | /* |
257 | * Logical palettes don't even make sense anywhere except Windows. |
258 | */ |
259 | s = ctrl_getset(b, "Window/Colours", "general", |
260 | "General options for colour usage"); |
261 | ctrl_checkbox(s, "Attempt to use logical palettes", 'l', |
262 | HELPCTX(colours_logpal), |
263 | dlg_stdcheckbox_handler, I(offsetof(Config,try_palette))); |
264 | |
265 | /* |
266 | * Resize-by-changing-font is a Windows insanity. |
267 | */ |
268 | s = ctrl_getset(b, "Window", "size", "Set the size of the window"); |
269 | ctrl_radiobuttons(s, "When window is resized:", 'z', 1, |
270 | HELPCTX(window_resize), |
271 | dlg_stdradiobutton_handler, |
272 | I(offsetof(Config, resize_action)), |
273 | "Change the number of rows and columns", I(RESIZE_TERM), |
274 | "Change the size of the font", I(RESIZE_FONT), |
275 | "Change font size only when maximised", I(RESIZE_EITHER), |
276 | "Forbid resizing completely", I(RESIZE_DISABLED), NULL); |
277 | |
278 | /* |
279 | * Most of the Window/Behaviour stuff is there to mimic Windows |
280 | * conventions which PuTTY can optionally disregard. Hence, |
281 | * most of these options are Windows-specific. |
282 | */ |
283 | s = ctrl_getset(b, "Window/Behaviour", "main", NULL); |
284 | ctrl_checkbox(s, "Window closes on ALT-F4", '4', |
285 | HELPCTX(behaviour_altf4), |
286 | dlg_stdcheckbox_handler, I(offsetof(Config,alt_f4))); |
287 | ctrl_checkbox(s, "System menu appears on ALT-Space", 'y', |
288 | HELPCTX(behaviour_altspace), |
289 | dlg_stdcheckbox_handler, I(offsetof(Config,alt_space))); |
290 | ctrl_checkbox(s, "System menu appears on ALT alone", 'l', |
291 | HELPCTX(behaviour_altonly), |
292 | dlg_stdcheckbox_handler, I(offsetof(Config,alt_only))); |
293 | ctrl_checkbox(s, "Ensure window is always on top", 'e', |
294 | HELPCTX(behaviour_alwaysontop), |
295 | dlg_stdcheckbox_handler, I(offsetof(Config,alwaysontop))); |
296 | ctrl_checkbox(s, "Full screen on Alt-Enter", 'f', |
297 | HELPCTX(behaviour_altenter), |
298 | dlg_stdcheckbox_handler, |
299 | I(offsetof(Config,fullscreenonaltenter))); |
300 | } |