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