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