config.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * config.c - the Windows-specific parts of the PuTTY configuration
  3. * box.
  4. */
  5. #include <assert.h>
  6. #include <stdlib.h>
  7. #include "putty.h"
  8. #include "dialog.h"
  9. #include "storage.h"
  10. static void about_handler(dlgcontrol *ctrl, dlgparam *dlg,
  11. void *data, int event)
  12. {
  13. HWND *hwndp = (HWND *)ctrl->context.p;
  14. if (event == EVENT_ACTION) {
  15. modal_about_box(*hwndp);
  16. }
  17. }
  18. static void help_handler(dlgcontrol *ctrl, dlgparam *dlg,
  19. void *data, int event)
  20. {
  21. HWND *hwndp = (HWND *)ctrl->context.p;
  22. if (event == EVENT_ACTION) {
  23. show_help(*hwndp);
  24. }
  25. }
  26. static void variable_pitch_handler(dlgcontrol *ctrl, dlgparam *dlg,
  27. void *data, int event)
  28. {
  29. if (event == EVENT_REFRESH) {
  30. dlg_checkbox_set(ctrl, dlg, !dlg_get_fixed_pitch_flag(dlg));
  31. } else if (event == EVENT_VALCHANGE) {
  32. dlg_set_fixed_pitch_flag(dlg, !dlg_checkbox_get(ctrl, dlg));
  33. }
  34. }
  35. void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
  36. bool midsession, int protocol)
  37. {
  38. const struct BackendVtable *backvt;
  39. bool resize_forbidden = false;
  40. struct controlset *s;
  41. dlgcontrol *c;
  42. char *str;
  43. if (!midsession) {
  44. /*
  45. * Add the About and Help buttons to the standard panel.
  46. */
  47. s = ctrl_getset(b, "", "", "");
  48. c = ctrl_pushbutton(s, "About", 'a', HELPCTX(no_help),
  49. about_handler, P(hwndp));
  50. c->column = 0;
  51. if (has_help) {
  52. c = ctrl_pushbutton(s, "Help", 'h', HELPCTX(no_help),
  53. help_handler, P(hwndp));
  54. c->column = 1;
  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. conf_checkbox_handler,
  66. I(CONF_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->type == CTRL_CHECKBOX &&
  76. c->context.i == CONF_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(dlgcontrol *));
  85. s->ctrls[i+1] = c;
  86. }
  87. break;
  88. }
  89. }
  90. }
  91. /*
  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. conf_checkbox_handler, I(CONF_compose_key));
  100. ctrl_checkbox(s, "Control-Alt is different from AltGr", 'd',
  101. HELPCTX(keyboard_ctrlalt),
  102. conf_checkbox_handler, I(CONF_ctrlaltkeys));
  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->type == CTRL_RADIO &&
  126. c->context.i == CONF_beep) {
  127. assert(c->handler == conf_radiobutton_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. conf_filesel_handler, I(CONF_bell_wavefile));
  153. /*
  154. * While we've got this box open, taskbar flashing on a bell is
  155. * also Windows-specific.
  156. */
  157. ctrl_radiobuttons(s, "Taskbar/caption indication on bell:", 'i', 3,
  158. HELPCTX(bell_taskbar),
  159. conf_radiobutton_handler,
  160. I(CONF_beep_ind),
  161. "Disabled", I(B_IND_DISABLED),
  162. "Flashing", I(B_IND_FLASH),
  163. "Steady", I(B_IND_STEADY));
  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. conf_checkbox_handler, I(CONF_sunken_edge));
  172. /*
  173. * Configurable font quality settings for Windows.
  174. */
  175. s = ctrl_getset(b, "Window/Appearance", "font",
  176. "Font settings");
  177. ctrl_checkbox(s, "Allow selection of variable-pitch fonts", NO_SHORTCUT,
  178. HELPCTX(appearance_font), variable_pitch_handler, I(0));
  179. ctrl_radiobuttons(s, "Font quality:", 'q', 2,
  180. HELPCTX(appearance_font),
  181. conf_radiobutton_handler,
  182. I(CONF_font_quality),
  183. "Antialiased", I(FQ_ANTIALIASED),
  184. "Non-Antialiased", I(FQ_NONANTIALIASED),
  185. "ClearType", I(FQ_CLEARTYPE),
  186. "Default", I(FQ_DEFAULT));
  187. /*
  188. * Cyrillic Lock is a horrid misfeature even on Windows, and
  189. * the least we can do is ensure it never makes it to any other
  190. * platform (at least unless someone fixes it!).
  191. */
  192. s = ctrl_getset(b, "Window/Translation", "tweaks", NULL);
  193. ctrl_checkbox(s, "Caps Lock acts as Cyrillic switch", 's',
  194. HELPCTX(translation_cyrillic),
  195. conf_checkbox_handler,
  196. I(CONF_xlat_capslockcyr));
  197. /*
  198. * On Windows we can use but not enumerate translation tables
  199. * from the operating system. Briefly document this.
  200. */
  201. s = ctrl_getset(b, "Window/Translation", "trans",
  202. "Character set translation on received data");
  203. ctrl_text(s, "(Codepages supported by Windows but not listed here, "
  204. "such as CP866 on many systems, can be entered manually)",
  205. HELPCTX(translation_codepage));
  206. /*
  207. * Windows has the weird OEM font mode, which gives us some
  208. * additional options when working with line-drawing
  209. * characters.
  210. */
  211. str = dupprintf("Adjust how %s displays line drawing characters", appname);
  212. s = ctrl_getset(b, "Window/Translation", "linedraw", str);
  213. sfree(str);
  214. {
  215. int i;
  216. for (i = 0; i < s->ncontrols; i++) {
  217. c = s->ctrls[i];
  218. if (c->type == CTRL_RADIO &&
  219. c->context.i == CONF_vtmode) {
  220. assert(c->handler == conf_radiobutton_handler);
  221. c->radio.nbuttons += 3;
  222. c->radio.buttons =
  223. sresize(c->radio.buttons, c->radio.nbuttons, char *);
  224. c->radio.buttons[c->radio.nbuttons-3] =
  225. dupstr("Font has XWindows encoding");
  226. c->radio.buttons[c->radio.nbuttons-2] =
  227. dupstr("Use font in both ANSI and OEM modes");
  228. c->radio.buttons[c->radio.nbuttons-1] =
  229. dupstr("Use font in OEM mode only");
  230. c->radio.buttondata =
  231. sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
  232. c->radio.buttondata[c->radio.nbuttons-3] = I(VT_XWINDOWS);
  233. c->radio.buttondata[c->radio.nbuttons-2] = I(VT_OEMANSI);
  234. c->radio.buttondata[c->radio.nbuttons-1] = I(VT_OEMONLY);
  235. if (!c->radio.shortcuts) {
  236. int j;
  237. c->radio.shortcuts = snewn(c->radio.nbuttons, char);
  238. for (j = 0; j < c->radio.nbuttons; j++)
  239. c->radio.shortcuts[j] = NO_SHORTCUT;
  240. } else {
  241. c->radio.shortcuts = sresize(c->radio.shortcuts,
  242. c->radio.nbuttons, char);
  243. }
  244. c->radio.shortcuts[c->radio.nbuttons-3] = 'x';
  245. c->radio.shortcuts[c->radio.nbuttons-2] = 'b';
  246. c->radio.shortcuts[c->radio.nbuttons-1] = 'e';
  247. break;
  248. }
  249. }
  250. }
  251. /*
  252. * RTF paste is Windows-specific.
  253. */
  254. s = ctrl_getset(b, "Window/Selection/Copy", "format",
  255. "Formatting of copied characters");
  256. ctrl_checkbox(s, "Copy to clipboard in RTF as well as plain text", 'f',
  257. HELPCTX(copy_rtf),
  258. conf_checkbox_handler, I(CONF_rtf_paste));
  259. /*
  260. * Windows often has no middle button, so we supply a selection
  261. * mode in which the more critical Paste action is available on
  262. * the right button instead.
  263. */
  264. s = ctrl_getset(b, "Window/Selection", "mouse",
  265. "Control use of mouse");
  266. ctrl_radiobuttons(s, "Action of mouse buttons:", 'm', 1,
  267. HELPCTX(selection_buttons),
  268. conf_radiobutton_handler,
  269. I(CONF_mouse_is_xterm),
  270. "Windows (Middle extends, Right brings up menu)", I(2),
  271. "Compromise (Middle extends, Right pastes)", I(0),
  272. "xterm (Right extends, Middle pastes)", I(1));
  273. /*
  274. * This really ought to go at the _top_ of its box, not the
  275. * bottom, so we'll just do some shuffling now we've set it
  276. * up...
  277. */
  278. c = s->ctrls[s->ncontrols-1]; /* this should be the new control */
  279. memmove(s->ctrls+1, s->ctrls, (s->ncontrols-1)*sizeof(dlgcontrol *));
  280. s->ctrls[0] = c;
  281. /*
  282. * Logical palettes don't even make sense anywhere except Windows.
  283. */
  284. s = ctrl_getset(b, "Window/Colours", "general",
  285. "General options for colour usage");
  286. ctrl_checkbox(s, "Attempt to use logical palettes", 'l',
  287. HELPCTX(colours_logpal),
  288. conf_checkbox_handler, I(CONF_try_palette));
  289. ctrl_checkbox(s, "Use system colours", 's',
  290. HELPCTX(colours_system),
  291. conf_checkbox_handler, I(CONF_system_colour));
  292. /*
  293. * Resize-by-changing-font is a Windows insanity.
  294. */
  295. backvt = backend_vt_from_proto(protocol);
  296. if (backvt)
  297. resize_forbidden = (backvt->flags & BACKEND_RESIZE_FORBIDDEN);
  298. if (!midsession || !resize_forbidden) {
  299. s = ctrl_getset(b, "Window", "size", "Set the size of the window");
  300. ctrl_radiobuttons(s, "When window is resized:", 'z', 1,
  301. HELPCTX(window_resize),
  302. conf_radiobutton_handler,
  303. I(CONF_resize_action),
  304. "Change the number of rows and columns", I(RESIZE_TERM),
  305. "Change the size of the font", I(RESIZE_FONT),
  306. "Change font size only when maximised", I(RESIZE_EITHER),
  307. "Forbid resizing completely", I(RESIZE_DISABLED));
  308. }
  309. /*
  310. * Most of the Window/Behaviour stuff is there to mimic Windows
  311. * conventions which PuTTY can optionally disregard. Hence,
  312. * most of these options are Windows-specific.
  313. */
  314. s = ctrl_getset(b, "Window/Behaviour", "main", NULL);
  315. ctrl_checkbox(s, "Window closes on ALT-F4", '4',
  316. HELPCTX(behaviour_altf4),
  317. conf_checkbox_handler, I(CONF_alt_f4));
  318. ctrl_checkbox(s, "System menu appears on ALT-Space", 'y',
  319. HELPCTX(behaviour_altspace),
  320. conf_checkbox_handler, I(CONF_alt_space));
  321. ctrl_checkbox(s, "System menu appears on ALT alone", 'l',
  322. HELPCTX(behaviour_altonly),
  323. conf_checkbox_handler, I(CONF_alt_only));
  324. ctrl_checkbox(s, "Ensure window is always on top", 'e',
  325. HELPCTX(behaviour_alwaysontop),
  326. conf_checkbox_handler, I(CONF_alwaysontop));
  327. ctrl_checkbox(s, "Full screen on Alt-Enter", 'f',
  328. HELPCTX(behaviour_altenter),
  329. conf_checkbox_handler,
  330. I(CONF_fullscreenonaltenter));
  331. /*
  332. * Windows supports a local-command proxy.
  333. */
  334. if (!midsession) {
  335. int i;
  336. s = ctrl_getset(b, "Connection/Proxy", "basics", NULL);
  337. for (i = 0; i < s->ncontrols; i++) {
  338. c = s->ctrls[i];
  339. if (c->type == CTRL_LISTBOX &&
  340. c->handler == proxy_type_handler) {
  341. c->context.i |= PROXY_UI_FLAG_LOCAL;
  342. break;
  343. }
  344. }
  345. }
  346. /*
  347. * $XAUTHORITY is not reliable on Windows, so we provide a
  348. * means to override it.
  349. */
  350. if (!midsession && backend_vt_from_proto(PROT_SSH)) {
  351. s = ctrl_getset(b, "Connection/SSH/X11", "x11", "X11 forwarding");
  352. ctrl_filesel(s, "X authority file for local display", 't',
  353. NULL, false, "Select X authority file",
  354. HELPCTX(ssh_tunnels_xauthority),
  355. conf_filesel_handler, I(CONF_xauthfile));
  356. }
  357. }