374330e2 |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
1d470ad2 |
3 | #include <ctype.h> |
ec55b220 |
4 | #include <time.h> |
a7419ea4 |
5 | #include <assert.h> |
374330e2 |
6 | |
32874aea |
7 | #define PUTTY_DO_GLOBALS /* actually _define_ globals */ |
374330e2 |
8 | #include "putty.h" |
887035a5 |
9 | #include "terminal.h" |
d5859615 |
10 | #include "storage.h" |
374330e2 |
11 | #include "win_res.h" |
12 | |
7440fd44 |
13 | #ifndef NO_MULTIMON |
14 | #if WINVER < 0x0500 |
15 | #define COMPILE_MULTIMON_STUBS |
16 | #include <multimon.h> |
17 | #endif |
18 | #endif |
19 | |
20 | #include <imm.h> |
21 | #include <commctrl.h> |
22 | #include <richedit.h> |
23 | #include <mmsystem.h> |
24 | |
ce0b6f45 |
25 | /* From MSDN: In the WM_SYSCOMMAND message, the four low-order bits of |
26 | * wParam are used by Windows, and should be masked off, so we shouldn't |
27 | * attempt to store information in them. Hence all these identifiers have |
865e82ad |
28 | * the low 4 bits clear. Also, identifiers should < 0xF000. */ |
ce0b6f45 |
29 | |
6833a413 |
30 | #define IDM_SHOWLOG 0x0010 |
31 | #define IDM_NEWSESS 0x0020 |
32 | #define IDM_DUPSESS 0x0030 |
e3be8de5 |
33 | #define IDM_RESTART 0x0040 |
34 | #define IDM_RECONF 0x0050 |
35 | #define IDM_CLRSB 0x0060 |
36 | #define IDM_RESET 0x0070 |
70133c0e |
37 | #define IDM_HELP 0x0140 |
38 | #define IDM_ABOUT 0x0150 |
39 | #define IDM_SAVEDSESS 0x0160 |
40 | #define IDM_COPYALL 0x0170 |
41 | #define IDM_FULLSCREEN 0x0180 |
63be7767 |
42 | #define IDM_PASTE 0x0190 |
6833a413 |
43 | |
125105d1 |
44 | #define IDM_SPECIAL_MIN 0x0400 |
45 | #define IDM_SPECIAL_MAX 0x0800 |
46 | |
6833a413 |
47 | #define IDM_SAVED_MIN 0x1000 |
865e82ad |
48 | #define IDM_SAVED_MAX 0x5000 |
49 | #define MENU_SAVED_STEP 16 |
1f1e3232 |
50 | /* Maximum number of sessions on saved-session submenu */ |
865e82ad |
51 | #define MENU_SAVED_MAX ((IDM_SAVED_MAX-IDM_SAVED_MIN) / MENU_SAVED_STEP) |
374330e2 |
52 | |
604fab0c |
53 | #define WM_IGNORE_CLIP (WM_APP + 2) |
54 | #define WM_FULLSCR_ON_MAX (WM_APP + 3) |
55 | #define WM_AGENT_CALLBACK (WM_APP + 4) |
374330e2 |
56 | |
3cf144db |
57 | /* Needed for Chinese support and apparently not always defined. */ |
58 | #ifndef VK_PROCESSKEY |
59 | #define VK_PROCESSKEY 0xE5 |
60 | #endif |
61 | |
3f0f9388 |
62 | /* Mouse wheel support. */ |
5eaf1e06 |
63 | #ifndef WM_MOUSEWHEEL |
3f0f9388 |
64 | #define WM_MOUSEWHEEL 0x020A /* not defined in earlier SDKs */ |
65 | #endif |
66 | #ifndef WHEEL_DELTA |
67 | #define WHEEL_DELTA 120 |
5eaf1e06 |
68 | #endif |
69 | |
2c02ed02 |
70 | static Mouse_Button translate_button(Mouse_Button button); |
32874aea |
71 | static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); |
72 | static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, |
73 | unsigned char *output); |
374330e2 |
74 | static void cfgtopalette(void); |
26d1da7b |
75 | static void systopalette(void); |
374330e2 |
76 | static void init_palette(void); |
5a73255e |
77 | static void init_fonts(int, int); |
4eeb7d09 |
78 | static void another_font(int); |
79 | static void deinit_fonts(void); |
a5ce2e9f |
80 | static void set_input_locale(HKL); |
12745e35 |
81 | static void update_savedsess_menu(void); |
374330e2 |
82 | |
1ba99d2c |
83 | static int is_full_screen(void); |
84 | static void make_full_screen(void); |
85 | static void clear_full_screen(void); |
86 | static void flip_full_screen(void); |
87 | |
5a73255e |
88 | /* Window layout information */ |
89 | static void reset_window(int); |
a401e5f3 |
90 | static int extra_width, extra_height; |
5a73255e |
91 | static int font_width, font_height, font_dualwidth; |
92 | static int offset_width, offset_height; |
93 | static int was_zoomed = 0; |
94 | static int prev_rows, prev_cols; |
95 | |
39934deb |
96 | static void enact_netevent(WPARAM, LPARAM); |
f8a28d1f |
97 | static void flash_window(int mode); |
c1da5066 |
98 | static void sys_cursor_update(void); |
b9d7bcad |
99 | static int is_shift_pressed(void); |
d0f1bcb4 |
100 | static int get_fullscreen_rect(RECT * ss); |
59ad2c03 |
101 | |
c1da5066 |
102 | static int caret_x = -1, caret_y = -1; |
103 | |
0b4f0bc0 |
104 | static int kbd_codepage; |
105 | |
b9d7bcad |
106 | static void *ldisc; |
6b78788a |
107 | static Backend *back; |
108 | static void *backhandle; |
b9d7bcad |
109 | |
21d2b241 |
110 | static struct unicode_data ucsdata; |
0b4f0bc0 |
111 | static int session_closed; |
68a66cc3 |
112 | static int reconfiguring = FALSE; |
0b4f0bc0 |
113 | |
125105d1 |
114 | static const struct telnet_special *specials; |
6f2d0cde |
115 | static int n_specials; |
125105d1 |
116 | |
39934deb |
117 | #define TIMING_TIMER_ID 1234 |
118 | static long timing_next_time; |
119 | |
63be7767 |
120 | static struct { |
121 | HMENU menu; |
122 | int specials_submenu_pos; |
123 | } popup_menus[2]; |
124 | enum { SYSMENU, CTXMENU }; |
12745e35 |
125 | static HMENU savedsess_menu; |
63be7767 |
126 | |
3ea863a3 |
127 | Config cfg; /* exported to windlg.c */ |
128 | |
12745e35 |
129 | static struct sesslist sesslist; /* for saved-session menu */ |
0b4f0bc0 |
130 | |
c44bf5bd |
131 | struct agent_callback { |
132 | void (*callback)(void *, void *, int); |
133 | void *callback_ctx; |
134 | void *data; |
135 | int len; |
136 | }; |
137 | |
374330e2 |
138 | #define FONT_NORMAL 0 |
139 | #define FONT_BOLD 1 |
140 | #define FONT_UNDERLINE 2 |
141 | #define FONT_BOLDUND 3 |
4eeb7d09 |
142 | #define FONT_WIDE 0x04 |
143 | #define FONT_HIGH 0x08 |
144 | #define FONT_NARROW 0x10 |
5a73255e |
145 | |
4eeb7d09 |
146 | #define FONT_OEM 0x20 |
147 | #define FONT_OEMBOLD 0x21 |
148 | #define FONT_OEMUND 0x22 |
149 | #define FONT_OEMBOLDUND 0x23 |
5a73255e |
150 | |
151 | #define FONT_MAXNO 0x2F |
4eeb7d09 |
152 | #define FONT_SHIFT 5 |
153 | static HFONT fonts[FONT_MAXNO]; |
71f6951d |
154 | static LOGFONT lfont; |
4eeb7d09 |
155 | static int fontflag[FONT_MAXNO]; |
374330e2 |
156 | static enum { |
157 | BOLD_COLOURS, BOLD_SHADOW, BOLD_FONT |
158 | } bold_mode; |
159 | static enum { |
160 | UND_LINE, UND_FONT |
161 | } und_mode; |
162 | static int descent; |
163 | |
04a8208b |
164 | #define NCFGCOLOURS 22 |
cecb13f6 |
165 | #define NEXTCOLOURS 240 |
166 | #define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS) |
167 | static COLORREF colours[NALLCOLOURS]; |
374330e2 |
168 | static HPALETTE pal; |
169 | static LPLOGPALETTE logpal; |
cecb13f6 |
170 | static RGBTRIPLE defpal[NALLCOLOURS]; |
374330e2 |
171 | |
934c0b7a |
172 | static HBITMAP caretbm; |
173 | |
374330e2 |
174 | static int dbltime, lasttime, lastact; |
175 | static Mouse_Button lastbtn; |
176 | |
01c034ad |
177 | /* this allows xterm-style mouse handling. */ |
178 | static int send_raw_mouse = 0; |
179 | static int wheel_accumulator = 0; |
180 | |
755e0524 |
181 | static int busy_status = BUSY_NOT; |
182 | |
374330e2 |
183 | static char *window_name, *icon_name; |
184 | |
03f23ad6 |
185 | static int compose_state = 0; |
186 | |
011b0e33 |
187 | static UINT wm_mousewheel = WM_MOUSEWHEEL; |
188 | |
0965bee0 |
189 | /* Dummy routine, only required in plink. */ |
b9d7bcad |
190 | void ldisc_update(void *frontend, int echo, int edit) |
32874aea |
191 | { |
192 | } |
6f34e365 |
193 | |
c6ccd5c2 |
194 | char *get_ttymode(void *frontend, const char *mode) |
195 | { |
196 | return term_get_ttymode(term, mode); |
197 | } |
198 | |
e3be8de5 |
199 | static void start_backend(void) |
200 | { |
201 | const char *error; |
202 | char msg[1024], *title; |
203 | char *realhost; |
204 | int i; |
205 | |
206 | /* |
207 | * Select protocol. This is farmed out into a table in a |
208 | * separate file to enable an ssh-free variant. |
209 | */ |
210 | back = NULL; |
211 | for (i = 0; backends[i].backend != NULL; i++) |
212 | if (backends[i].protocol == cfg.protocol) { |
213 | back = backends[i].backend; |
214 | break; |
215 | } |
216 | if (back == NULL) { |
217 | char *str = dupprintf("%s Internal Error", appname); |
218 | MessageBox(NULL, "Unsupported protocol number found", |
219 | str, MB_OK | MB_ICONEXCLAMATION); |
220 | sfree(str); |
221 | cleanup_exit(1); |
222 | } |
223 | |
224 | error = back->init(NULL, &backhandle, &cfg, |
225 | cfg.host, cfg.port, &realhost, cfg.tcp_nodelay, |
226 | cfg.tcp_keepalives); |
227 | back->provide_logctx(backhandle, logctx); |
228 | if (error) { |
229 | char *str = dupprintf("%s Error", appname); |
230 | sprintf(msg, "Unable to open connection to\n" |
231 | "%.800s\n" "%s", cfg.host, error); |
232 | MessageBox(NULL, msg, str, MB_ICONERROR | MB_OK); |
233 | sfree(str); |
234 | exit(0); |
235 | } |
236 | window_name = icon_name = NULL; |
237 | if (*cfg.wintitle) { |
238 | title = cfg.wintitle; |
239 | } else { |
240 | sprintf(msg, "%s - %s", realhost, appname); |
241 | title = msg; |
242 | } |
243 | sfree(realhost); |
244 | set_title(NULL, title); |
245 | set_icon(NULL, title); |
246 | |
247 | /* |
248 | * Connect the terminal to the backend for resize purposes. |
249 | */ |
250 | term_provide_resize_fn(term, back->size, backhandle); |
251 | |
252 | /* |
253 | * Set up a line discipline. |
254 | */ |
255 | ldisc = ldisc_create(&cfg, term, back, backhandle, NULL); |
256 | |
257 | /* |
258 | * Destroy the Restart Session menu item. (This will return |
259 | * failure if it's already absent, as it will be the very first |
260 | * time we call this function. We ignore that, because as long |
261 | * as the menu item ends up not being there, we don't care |
262 | * whether it was us who removed it or not!) |
263 | */ |
264 | for (i = 0; i < lenof(popup_menus); i++) { |
265 | DeleteMenu(popup_menus[i].menu, IDM_RESTART, MF_BYCOMMAND); |
266 | } |
267 | |
268 | session_closed = FALSE; |
269 | } |
270 | |
271 | static void close_session(void) |
272 | { |
273 | char morestuff[100]; |
274 | int i; |
275 | |
276 | session_closed = TRUE; |
277 | sprintf(morestuff, "%.70s (inactive)", appname); |
278 | set_icon(NULL, morestuff); |
279 | set_title(NULL, morestuff); |
280 | |
281 | if (ldisc) { |
282 | ldisc_free(ldisc); |
283 | ldisc = NULL; |
284 | } |
285 | if (back) { |
286 | back->free(backhandle); |
287 | backhandle = NULL; |
288 | back = NULL; |
289 | update_specials_menu(NULL); |
290 | } |
291 | |
292 | /* |
293 | * Show the Restart Session menu item. Do a precautionary |
294 | * delete first to ensure we never end up with more than one. |
295 | */ |
296 | for (i = 0; i < lenof(popup_menus); i++) { |
297 | DeleteMenu(popup_menus[i].menu, IDM_RESTART, MF_BYCOMMAND); |
298 | InsertMenu(popup_menus[i].menu, IDM_DUPSESS, MF_BYCOMMAND | MF_ENABLED, |
299 | IDM_RESTART, "&Restart Session"); |
300 | } |
301 | } |
302 | |
32874aea |
303 | int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) |
304 | { |
374330e2 |
305 | WNDCLASS wndclass; |
306 | MSG msg; |
307 | int guess_width, guess_height; |
308 | |
8c3cd914 |
309 | hinst = inst; |
28339579 |
310 | hwnd = NULL; |
67779be7 |
311 | flags = FLAG_VERBOSE | FLAG_INTERACTIVE; |
73251d5d |
312 | |
8df7a775 |
313 | sk_init(); |
374330e2 |
314 | |
315 | InitCommonControls(); |
316 | |
301b66db |
317 | /* Ensure a Maximize setting in Explorer doesn't maximise the |
318 | * config box. */ |
319 | defuse_showwindow(); |
320 | |
4c48c989 |
321 | if (!init_winver()) |
88485e4d |
322 | { |
4c48c989 |
323 | char *str = dupprintf("%s Fatal Error", appname); |
324 | MessageBox(NULL, "Windows refuses to report a version", |
325 | str, MB_OK | MB_ICONEXCLAMATION); |
326 | sfree(str); |
327 | return 1; |
88485e4d |
328 | } |
329 | |
374330e2 |
330 | /* |
011b0e33 |
331 | * If we're running a version of Windows that doesn't support |
332 | * WM_MOUSEWHEEL, find out what message number we should be |
333 | * using instead. |
334 | */ |
335 | if (osVersion.dwMajorVersion < 4 || |
336 | (osVersion.dwMajorVersion == 4 && |
337 | osVersion.dwPlatformId != VER_PLATFORM_WIN32_NT)) |
338 | wm_mousewheel = RegisterWindowMessage("MSWHEEL_ROLLMSG"); |
339 | |
340 | /* |
70133c0e |
341 | * See if we can find our Help file. |
342 | */ |
343 | { |
344 | char b[2048], *p, *q, *r; |
345 | FILE *fp; |
346 | GetModuleFileName(NULL, b, sizeof(b) - 1); |
347 | r = b; |
348 | p = strrchr(b, '\\'); |
349 | if (p && p >= r) r = p+1; |
350 | q = strrchr(b, ':'); |
351 | if (q && q >= r) r = q+1; |
a9dc49af |
352 | strcpy(r, PUTTY_HELP_FILE); |
70133c0e |
353 | if ( (fp = fopen(b, "r")) != NULL) { |
354 | help_path = dupstr(b); |
355 | fclose(fp); |
356 | } else |
357 | help_path = NULL; |
a9dc49af |
358 | strcpy(r, PUTTY_HELP_CONTENTS); |
70133c0e |
359 | if ( (fp = fopen(b, "r")) != NULL) { |
360 | help_has_contents = TRUE; |
361 | fclose(fp); |
362 | } else |
363 | help_has_contents = FALSE; |
364 | } |
365 | |
366 | /* |
374330e2 |
367 | * Process the command line. |
368 | */ |
369 | { |
370 | char *p; |
c0a81592 |
371 | int got_host = 0; |
374330e2 |
372 | |
ffa79828 |
373 | default_protocol = be_default_protocol; |
374 | /* Find the appropriate default port. */ |
375 | { |
ffa79828 |
376 | int i; |
0d598aa7 |
377 | default_port = 0; /* illegal */ |
ffa79828 |
378 | for (i = 0; backends[i].backend != NULL; i++) |
379 | if (backends[i].protocol == default_protocol) { |
380 | default_port = backends[i].backend->default_port; |
381 | break; |
382 | } |
383 | } |
e1c8e0ed |
384 | cfg.logtype = LGTYP_NONE; |
e277c42d |
385 | |
a9422f39 |
386 | do_defaults(NULL, &cfg); |
374330e2 |
387 | |
388 | p = cmdline; |
374330e2 |
389 | |
390 | /* |
c0a81592 |
391 | * Process a couple of command-line options which are more |
392 | * easily dealt with before the line is broken up into |
393 | * words. These are the soon-to-be-defunct @sessionname and |
394 | * the internal-use-only &sharedmemoryhandle, neither of |
395 | * which are combined with anything else. |
e277c42d |
396 | */ |
c0a81592 |
397 | while (*p && isspace(*p)) |
e277c42d |
398 | p++; |
374330e2 |
399 | if (*p == '@') { |
f317611e |
400 | int i = strlen(p); |
32874aea |
401 | while (i > 1 && isspace(p[i - 1])) |
f317611e |
402 | i--; |
403 | p[i] = '\0'; |
32874aea |
404 | do_defaults(p + 1, &cfg); |
374330e2 |
405 | if (!*cfg.host && !do_config()) { |
7440fd44 |
406 | cleanup_exit(0); |
374330e2 |
407 | } |
408 | } else if (*p == '&') { |
409 | /* |
410 | * An initial & means we've been given a command line |
411 | * containing the hex value of a HANDLE for a file |
412 | * mapping object, which we must then extract as a |
413 | * config. |
414 | */ |
415 | HANDLE filemap; |
416 | Config *cp; |
32874aea |
417 | if (sscanf(p + 1, "%p", &filemap) == 1 && |
374330e2 |
418 | (cp = MapViewOfFile(filemap, FILE_MAP_READ, |
419 | 0, 0, sizeof(Config))) != NULL) { |
420 | cfg = *cp; |
421 | UnmapViewOfFile(cp); |
422 | CloseHandle(filemap); |
423 | } else if (!do_config()) { |
7440fd44 |
424 | cleanup_exit(0); |
374330e2 |
425 | } |
c0a81592 |
426 | } else { |
32874aea |
427 | /* |
c0a81592 |
428 | * Otherwise, break up the command line and deal with |
429 | * it sensibly. |
32874aea |
430 | */ |
c0a81592 |
431 | int argc, i; |
432 | char **argv; |
433 | |
d3a1a808 |
434 | split_into_argv(cmdline, &argc, &argv, NULL); |
c0a81592 |
435 | |
436 | for (i = 0; i < argc; i++) { |
437 | char *p = argv[i]; |
438 | int ret; |
439 | |
5555d393 |
440 | ret = cmdline_process_param(p, i+1<argc?argv[i+1]:NULL, |
441 | 1, &cfg); |
c0a81592 |
442 | if (ret == -2) { |
443 | cmdline_error("option \"%s\" requires an argument", p); |
444 | } else if (ret == 2) { |
445 | i++; /* skip next argument */ |
446 | } else if (ret == 1) { |
447 | continue; /* nothing further needs doing */ |
a6551274 |
448 | } else if (!strcmp(p, "-cleanup") || |
449 | !strcmp(p, "-cleanup-during-uninstall")) { |
c0a81592 |
450 | /* |
451 | * `putty -cleanup'. Remove all registry |
452 | * entries associated with PuTTY, and also find |
453 | * and delete the random seed file. |
454 | */ |
f6f450e2 |
455 | char *s1, *s2; |
a6551274 |
456 | /* Are we being invoked from an uninstaller? */ |
457 | if (!strcmp(p, "-cleanup-during-uninstall")) { |
458 | s1 = dupprintf("Remove saved sessions and random seed file?\n" |
459 | "\n" |
460 | "If you hit Yes, ALL Registry entries associated\n" |
461 | "with %s will be removed, as well as the\n" |
462 | "random seed file. THIS PROCESS WILL\n" |
463 | "DESTROY YOUR SAVED SESSIONS.\n" |
464 | "(This only affects the currently logged-in user.)\n" |
465 | "\n" |
466 | "If you hit No, uninstallation will proceed, but\n" |
467 | "saved sessions etc will be left on the machine.", |
468 | appname); |
469 | s2 = dupprintf("%s Uninstallation", appname); |
470 | } else { |
471 | s1 = dupprintf("This procedure will remove ALL Registry entries\n" |
472 | "associated with %s, and will also remove\n" |
473 | "the random seed file. (This only affects the\n" |
474 | "currently logged-in user.)\n" |
475 | "\n" |
476 | "THIS PROCESS WILL DESTROY YOUR SAVED SESSIONS.\n" |
477 | "Are you really sure you want to continue?", |
478 | appname); |
479 | s2 = dupprintf("%s Warning", appname); |
480 | } |
481 | if (message_box(s1, s2, |
482 | MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2, |
28339579 |
483 | HELPCTXID(option_cleanup)) == IDYES) { |
c0a81592 |
484 | cleanup_all(); |
485 | } |
f6f450e2 |
486 | sfree(s1); |
487 | sfree(s2); |
c0a81592 |
488 | exit(0); |
2285d016 |
489 | } else if (!strcmp(p, "-pgpfp")) { |
490 | pgp_fingerprints(); |
491 | exit(1); |
c0a81592 |
492 | } else if (*p != '-') { |
493 | char *q = p; |
494 | if (got_host) { |
495 | /* |
496 | * If we already have a host name, treat |
497 | * this argument as a port number. NB we |
498 | * have to treat this as a saved -P |
499 | * argument, so that it will be deferred |
500 | * until it's a good moment to run it. |
501 | */ |
5555d393 |
502 | int ret = cmdline_process_param("-P", p, 1, &cfg); |
c0a81592 |
503 | assert(ret == 2); |
504 | } else if (!strncmp(q, "telnet:", 7)) { |
505 | /* |
506 | * If the hostname starts with "telnet:", |
507 | * set the protocol to Telnet and process |
508 | * the string as a Telnet URL. |
509 | */ |
510 | char c; |
511 | |
512 | q += 7; |
513 | if (q[0] == '/' && q[1] == '/') |
514 | q += 2; |
515 | cfg.protocol = PROT_TELNET; |
516 | p = q; |
517 | while (*p && *p != ':' && *p != '/') |
518 | p++; |
519 | c = *p; |
520 | if (*p) |
521 | *p++ = '\0'; |
522 | if (c == ':') |
523 | cfg.port = atoi(p); |
524 | else |
525 | cfg.port = -1; |
526 | strncpy(cfg.host, q, sizeof(cfg.host) - 1); |
527 | cfg.host[sizeof(cfg.host) - 1] = '\0'; |
528 | got_host = 1; |
529 | } else { |
530 | /* |
531 | * Otherwise, treat this argument as a host |
532 | * name. |
533 | */ |
534 | while (*p && !isspace(*p)) |
535 | p++; |
536 | if (*p) |
537 | *p++ = '\0'; |
538 | strncpy(cfg.host, q, sizeof(cfg.host) - 1); |
539 | cfg.host[sizeof(cfg.host) - 1] = '\0'; |
540 | got_host = 1; |
541 | } |
86256dc6 |
542 | } else { |
543 | cmdline_error("unknown option \"%s\"", p); |
c0a81592 |
544 | } |
374330e2 |
545 | } |
546 | } |
13eafebf |
547 | |
5555d393 |
548 | cmdline_run_saved(&cfg); |
c0a81592 |
549 | |
550 | if (!*cfg.host && !do_config()) { |
7440fd44 |
551 | cleanup_exit(0); |
c0a81592 |
552 | } |
553 | |
381b1876 |
554 | /* |
555 | * Trim leading whitespace off the hostname if it's there. |
556 | */ |
557 | { |
558 | int space = strspn(cfg.host, " \t"); |
559 | memmove(cfg.host, cfg.host+space, 1+strlen(cfg.host)-space); |
560 | } |
561 | |
13eafebf |
562 | /* See if host is of the form user@host */ |
563 | if (cfg.host[0] != '\0') { |
5dd103a8 |
564 | char *atsign = strrchr(cfg.host, '@'); |
13eafebf |
565 | /* Make sure we're not overflowing the user field */ |
566 | if (atsign) { |
32874aea |
567 | if (atsign - cfg.host < sizeof cfg.username) { |
568 | strncpy(cfg.username, cfg.host, atsign - cfg.host); |
569 | cfg.username[atsign - cfg.host] = '\0'; |
13eafebf |
570 | } |
32874aea |
571 | memmove(cfg.host, atsign + 1, 1 + strlen(atsign + 1)); |
13eafebf |
572 | } |
573 | } |
503ddb97 |
574 | |
575 | /* |
05581745 |
576 | * Trim a colon suffix off the hostname if it's there. In |
577 | * order to protect IPv6 address literals against this |
578 | * treatment, we do not do this if there's _more_ than one |
579 | * colon. |
503ddb97 |
580 | */ |
05581745 |
581 | { |
582 | char *c = strchr(cfg.host, ':'); |
583 | |
584 | if (c) { |
585 | char *d = strchr(c+1, ':'); |
586 | if (!d) |
587 | *c = '\0'; |
588 | } |
589 | } |
cae0c023 |
590 | |
591 | /* |
592 | * Remove any remaining whitespace from the hostname. |
593 | */ |
594 | { |
595 | int p1 = 0, p2 = 0; |
596 | while (cfg.host[p2] != '\0') { |
597 | if (cfg.host[p2] != ' ' && cfg.host[p2] != '\t') { |
598 | cfg.host[p1] = cfg.host[p2]; |
599 | p1++; |
600 | } |
601 | p2++; |
602 | } |
603 | cfg.host[p1] = '\0'; |
604 | } |
374330e2 |
605 | } |
606 | |
b278b14a |
607 | /* Check for invalid Port number (i.e. zero) */ |
608 | if (cfg.port == 0) { |
f6f450e2 |
609 | char *str = dupprintf("%s Internal Error", appname); |
32874aea |
610 | MessageBox(NULL, "Invalid Port Number", |
f6f450e2 |
611 | str, MB_OK | MB_ICONEXCLAMATION); |
612 | sfree(str); |
7440fd44 |
613 | cleanup_exit(1); |
b278b14a |
614 | } |
615 | |
374330e2 |
616 | if (!prev) { |
32874aea |
617 | wndclass.style = 0; |
618 | wndclass.lpfnWndProc = WndProc; |
619 | wndclass.cbClsExtra = 0; |
620 | wndclass.cbWndExtra = 0; |
621 | wndclass.hInstance = inst; |
622 | wndclass.hIcon = LoadIcon(inst, MAKEINTRESOURCE(IDI_MAINICON)); |
623 | wndclass.hCursor = LoadCursor(NULL, IDC_IBEAM); |
5a73255e |
624 | wndclass.hbrBackground = NULL; |
32874aea |
625 | wndclass.lpszMenuName = NULL; |
374330e2 |
626 | wndclass.lpszClassName = appname; |
627 | |
32874aea |
628 | RegisterClass(&wndclass); |
374330e2 |
629 | } |
630 | |
21d2b241 |
631 | memset(&ucsdata, 0, sizeof(ucsdata)); |
632 | |
374330e2 |
633 | cfgtopalette(); |
634 | |
635 | /* |
636 | * Guess some defaults for the window size. This all gets |
637 | * updated later, so we don't really care too much. However, we |
638 | * do want the font width/height guesses to correspond to a |
639 | * large font rather than a small one... |
640 | */ |
32874aea |
641 | |
374330e2 |
642 | font_width = 10; |
643 | font_height = 20; |
644 | extra_width = 25; |
645 | extra_height = 28; |
c52dd4c9 |
646 | guess_width = extra_width + font_width * cfg.width; |
647 | guess_height = extra_height + font_height * cfg.height; |
374330e2 |
648 | { |
649 | RECT r; |
d0f1bcb4 |
650 | get_fullscreen_rect(&r); |
374330e2 |
651 | if (guess_width > r.right - r.left) |
652 | guess_width = r.right - r.left; |
653 | if (guess_height > r.bottom - r.top) |
654 | guess_height = r.bottom - r.top; |
655 | } |
656 | |
c9def1b8 |
657 | { |
32874aea |
658 | int winmode = WS_OVERLAPPEDWINDOW | WS_VSCROLL; |
659 | int exwinmode = 0; |
660 | if (!cfg.scrollbar) |
661 | winmode &= ~(WS_VSCROLL); |
ad5c93cc |
662 | if (cfg.resize_action == RESIZE_DISABLED) |
32874aea |
663 | winmode &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); |
664 | if (cfg.alwaysontop) |
665 | exwinmode |= WS_EX_TOPMOST; |
666 | if (cfg.sunken_edge) |
667 | exwinmode |= WS_EX_CLIENTEDGE; |
668 | hwnd = CreateWindowEx(exwinmode, appname, appname, |
669 | winmode, CW_USEDEFAULT, CW_USEDEFAULT, |
670 | guess_width, guess_height, |
671 | NULL, NULL, inst, NULL); |
672 | } |
374330e2 |
673 | |
674 | /* |
c52dd4c9 |
675 | * Initialise the terminal. (We have to do this _after_ |
676 | * creating the window, since the terminal is the first thing |
677 | * which will call schedule_timer(), which will in turn call |
5ba93094 |
678 | * timer_change_notify() which will expect hwnd to exist.) |
c52dd4c9 |
679 | */ |
680 | term = term_init(&cfg, &ucsdata, NULL); |
681 | logctx = log_init(NULL, &cfg); |
682 | term_provide_logctx(term, logctx); |
683 | term_size(term, cfg.height, cfg.width, cfg.savelines); |
684 | |
685 | /* |
374330e2 |
686 | * Initialise the fonts, simultaneously correcting the guesses |
687 | * for font_{width,height}. |
688 | */ |
5a73255e |
689 | init_fonts(0,0); |
374330e2 |
690 | |
691 | /* |
692 | * Correct the guesses for extra_{width,height}. |
693 | */ |
694 | { |
695 | RECT cr, wr; |
32874aea |
696 | GetWindowRect(hwnd, &wr); |
697 | GetClientRect(hwnd, &cr); |
5a73255e |
698 | offset_width = offset_height = cfg.window_border; |
699 | extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2; |
700 | extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2; |
374330e2 |
701 | } |
702 | |
703 | /* |
704 | * Resize the window, now we know what size we _really_ want it |
705 | * to be. |
706 | */ |
887035a5 |
707 | guess_width = extra_width + font_width * term->cols; |
708 | guess_height = extra_height + font_height * term->rows; |
32874aea |
709 | SetWindowPos(hwnd, NULL, 0, 0, guess_width, guess_height, |
710 | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER); |
374330e2 |
711 | |
712 | /* |
934c0b7a |
713 | * Set up a caret bitmap, with no content. |
714 | */ |
715 | { |
32874aea |
716 | char *bits; |
717 | int size = (font_width + 15) / 16 * 2 * font_height; |
3d88e64d |
718 | bits = snewn(size, char); |
32874aea |
719 | memset(bits, 0, size); |
720 | caretbm = CreateBitmap(font_width, font_height, 1, 1, bits); |
721 | sfree(bits); |
934c0b7a |
722 | } |
5b7ce734 |
723 | CreateCaret(hwnd, caretbm, font_width, font_height); |
934c0b7a |
724 | |
725 | /* |
374330e2 |
726 | * Initialise the scroll bar. |
727 | */ |
728 | { |
729 | SCROLLINFO si; |
730 | |
731 | si.cbSize = sizeof(si); |
c9def1b8 |
732 | si.fMask = SIF_ALL | SIF_DISABLENOSCROLL; |
374330e2 |
733 | si.nMin = 0; |
887035a5 |
734 | si.nMax = term->rows - 1; |
735 | si.nPage = term->rows; |
374330e2 |
736 | si.nPos = 0; |
32874aea |
737 | SetScrollInfo(hwnd, SB_VERT, &si, FALSE); |
374330e2 |
738 | } |
739 | |
374330e2 |
740 | /* |
374330e2 |
741 | * Prepare the mouse handler. |
742 | */ |
743 | lastact = MA_NOTHING; |
01c034ad |
744 | lastbtn = MBT_NOTHING; |
374330e2 |
745 | dbltime = GetDoubleClickTime(); |
746 | |
747 | /* |
748 | * Set up the session-control options on the system menu. |
749 | */ |
750 | { |
12745e35 |
751 | HMENU m; |
752 | int j; |
f6f450e2 |
753 | char *str; |
374330e2 |
754 | |
63be7767 |
755 | popup_menus[SYSMENU].menu = GetSystemMenu(hwnd, FALSE); |
756 | popup_menus[CTXMENU].menu = CreatePopupMenu(); |
757 | AppendMenu(popup_menus[CTXMENU].menu, MF_ENABLED, IDM_PASTE, "&Paste"); |
758 | |
12745e35 |
759 | savedsess_menu = CreateMenu(); |
0b4f0bc0 |
760 | get_sesslist(&sesslist, TRUE); |
12745e35 |
761 | update_savedsess_menu(); |
63be7767 |
762 | |
763 | for (j = 0; j < lenof(popup_menus); j++) { |
764 | m = popup_menus[j].menu; |
765 | |
766 | AppendMenu(m, MF_SEPARATOR, 0, 0); |
767 | popup_menus[j].specials_submenu_pos = GetMenuItemCount(m); |
768 | AppendMenu(m, MF_ENABLED, IDM_SHOWLOG, "&Event Log"); |
769 | AppendMenu(m, MF_SEPARATOR, 0, 0); |
770 | AppendMenu(m, MF_ENABLED, IDM_NEWSESS, "Ne&w Session..."); |
771 | AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session"); |
12745e35 |
772 | AppendMenu(m, MF_POPUP | MF_ENABLED, (UINT) savedsess_menu, |
773 | "Sa&ved Sessions"); |
63be7767 |
774 | AppendMenu(m, MF_ENABLED, IDM_RECONF, "Chan&ge Settings..."); |
775 | AppendMenu(m, MF_SEPARATOR, 0, 0); |
776 | AppendMenu(m, MF_ENABLED, IDM_COPYALL, "C&opy All to Clipboard"); |
777 | AppendMenu(m, MF_ENABLED, IDM_CLRSB, "C&lear Scrollback"); |
778 | AppendMenu(m, MF_ENABLED, IDM_RESET, "Rese&t Terminal"); |
779 | AppendMenu(m, MF_SEPARATOR, 0, 0); |
780 | AppendMenu(m, (cfg.resize_action == RESIZE_DISABLED) ? |
781 | MF_GRAYED : MF_ENABLED, IDM_FULLSCREEN, "&Full Screen"); |
782 | AppendMenu(m, MF_SEPARATOR, 0, 0); |
783 | if (help_path) |
784 | AppendMenu(m, MF_ENABLED, IDM_HELP, "&Help"); |
785 | str = dupprintf("&About %s", appname); |
786 | AppendMenu(m, MF_ENABLED, IDM_ABOUT, str); |
787 | sfree(str); |
788 | } |
374330e2 |
789 | } |
790 | |
533b1743 |
791 | start_backend(); |
125105d1 |
792 | |
374330e2 |
793 | /* |
a5ce2e9f |
794 | * Set up the initial input locale. |
795 | */ |
796 | set_input_locale(GetKeyboardLayout(0)); |
797 | |
798 | /* |
00db133f |
799 | * Open the initial log file if there is one. |
374330e2 |
800 | */ |
a8327734 |
801 | logfopen(logctx); |
374330e2 |
802 | |
803 | /* |
00db133f |
804 | * Finally show the window! |
e1c8e0ed |
805 | */ |
00db133f |
806 | ShowWindow(hwnd, show); |
807 | SetForegroundWindow(hwnd); |
e1c8e0ed |
808 | |
809 | /* |
374330e2 |
810 | * Set the palette up. |
811 | */ |
812 | pal = NULL; |
813 | logpal = NULL; |
814 | init_palette(); |
815 | |
1cff1320 |
816 | term_set_focus(term, GetForegroundWindow() == hwnd); |
32874aea |
817 | UpdateWindow(hwnd); |
374330e2 |
818 | |
32874aea |
819 | if (GetMessage(&msg, NULL, 0, 0) == 1) { |
ec55b220 |
820 | while (msg.message != WM_QUIT) { |
32874aea |
821 | if (!(IsWindow(logbox) && IsDialogMessage(logbox, &msg))) |
822 | DispatchMessage(&msg); |
c9def1b8 |
823 | /* Send the paste buffer if there's anything to send */ |
887035a5 |
824 | term_paste(term); |
59ad2c03 |
825 | /* If there's nothing new in the queue then we can do everything |
826 | * we've delayed, reading the socket, writing, and repainting |
827 | * the window. |
828 | */ |
32874aea |
829 | if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) |
ec55b220 |
830 | continue; |
59ad2c03 |
831 | |
0ed2f48e |
832 | /* The messages seem unreliable; especially if we're being tricky */ |
1cff1320 |
833 | term_set_focus(term, GetForegroundWindow() == hwnd); |
0ed2f48e |
834 | |
39934deb |
835 | net_pending_errors(); |
32874aea |
836 | |
ec55b220 |
837 | /* There's no point rescanning everything in the message queue |
156686ef |
838 | * so we do an apparently unnecessary wait here |
ec55b220 |
839 | */ |
840 | WaitMessage(); |
32874aea |
841 | if (GetMessage(&msg, NULL, 0, 0) != 1) |
ec55b220 |
842 | break; |
59ad2c03 |
843 | } |
374330e2 |
844 | } |
845 | |
c0d36a72 |
846 | cleanup_exit(msg.wParam); /* this doesn't return... */ |
847 | return msg.wParam; /* ... but optimiser doesn't know */ |
93b581bd |
848 | } |
849 | |
850 | /* |
851 | * Clean up and exit. |
852 | */ |
853 | void cleanup_exit(int code) |
854 | { |
374330e2 |
855 | /* |
856 | * Clean up. |
857 | */ |
4eeb7d09 |
858 | deinit_fonts(); |
374330e2 |
859 | sfree(logpal); |
860 | if (pal) |
861 | DeleteObject(pal); |
93b581bd |
862 | sk_cleanup(); |
374330e2 |
863 | |
8f203108 |
864 | if (cfg.protocol == PROT_SSH) { |
374330e2 |
865 | random_save_seed(); |
8f203108 |
866 | #ifdef MSCRYPTOAPI |
867 | crypto_wrapup(); |
868 | #endif |
869 | } |
374330e2 |
870 | |
93b581bd |
871 | exit(code); |
374330e2 |
872 | } |
873 | |
874 | /* |
8df7a775 |
875 | * Set up, or shut down, an AsyncSelect. Called from winnet.c. |
876 | */ |
32874aea |
877 | char *do_select(SOCKET skt, int startup) |
878 | { |
8df7a775 |
879 | int msg, events; |
880 | if (startup) { |
881 | msg = WM_NETEVENT; |
3ad9d396 |
882 | events = (FD_CONNECT | FD_READ | FD_WRITE | |
883 | FD_OOB | FD_CLOSE | FD_ACCEPT); |
8df7a775 |
884 | } else { |
885 | msg = events = 0; |
886 | } |
887 | if (!hwnd) |
888 | return "do_select(): internal error (hwnd==NULL)"; |
7440fd44 |
889 | if (p_WSAAsyncSelect(skt, hwnd, msg, events) == SOCKET_ERROR) { |
890 | switch (p_WSAGetLastError()) { |
32874aea |
891 | case WSAENETDOWN: |
892 | return "Network is down"; |
893 | default: |
894 | return "WSAAsyncSelect(): unknown error"; |
895 | } |
8df7a775 |
896 | } |
897 | return NULL; |
898 | } |
899 | |
900 | /* |
12745e35 |
901 | * Refresh the saved-session submenu from `sesslist'. |
902 | */ |
903 | static void update_savedsess_menu(void) |
904 | { |
905 | int i; |
906 | while (DeleteMenu(savedsess_menu, 0, MF_BYPOSITION)) ; |
907 | /* skip sesslist.sessions[0] == Default Settings */ |
908 | for (i = 1; |
909 | i < ((sesslist.nsessions <= MENU_SAVED_MAX+1) ? sesslist.nsessions |
910 | : MENU_SAVED_MAX+1); |
911 | i++) |
912 | AppendMenu(savedsess_menu, MF_ENABLED, |
913 | IDM_SAVED_MIN + (i-1)*MENU_SAVED_STEP, |
914 | sesslist.sessions[i]); |
915 | } |
916 | |
917 | /* |
125105d1 |
918 | * Update the Special Commands submenu. |
919 | */ |
920 | void update_specials_menu(void *frontend) |
921 | { |
e3be8de5 |
922 | HMENU p; |
125105d1 |
923 | int menu_already_exists = (specials != NULL); |
63be7767 |
924 | int i, j; |
125105d1 |
925 | |
e3be8de5 |
926 | if (back) |
927 | specials = back->get_specials(backhandle); |
928 | else |
929 | specials = NULL; |
930 | |
125105d1 |
931 | if (specials) { |
6f2d0cde |
932 | /* We can't use Windows to provide a stack for submenus, so |
933 | * here's a lame "stack" that will do for now. */ |
934 | HMENU saved_menu = NULL; |
935 | int nesting = 1; |
936 | p = CreatePopupMenu(); |
937 | for (i = 0; nesting > 0; i++) { |
125105d1 |
938 | assert(IDM_SPECIAL_MIN + 0x10 * i < IDM_SPECIAL_MAX); |
6f2d0cde |
939 | switch (specials[i].code) { |
940 | case TS_SEP: |
941 | AppendMenu(p, MF_SEPARATOR, 0, 0); |
942 | break; |
943 | case TS_SUBMENU: |
944 | assert(nesting < 2); |
945 | nesting++; |
946 | saved_menu = p; /* XXX lame stacking */ |
947 | p = CreatePopupMenu(); |
948 | AppendMenu(saved_menu, MF_POPUP | MF_ENABLED, |
949 | (UINT) p, specials[i].name); |
950 | break; |
951 | case TS_EXITMENU: |
952 | nesting--; |
953 | if (nesting) { |
954 | p = saved_menu; /* XXX lame stacking */ |
955 | saved_menu = NULL; |
956 | } |
957 | break; |
958 | default: |
125105d1 |
959 | AppendMenu(p, MF_ENABLED, IDM_SPECIAL_MIN + 0x10 * i, |
960 | specials[i].name); |
6f2d0cde |
961 | break; |
962 | } |
125105d1 |
963 | } |
6f2d0cde |
964 | /* Squirrel the highest special. */ |
965 | n_specials = i - 1; |
966 | } else { |
e3be8de5 |
967 | p = NULL; |
6f2d0cde |
968 | n_specials = 0; |
969 | } |
e3be8de5 |
970 | |
971 | for (j = 0; j < lenof(popup_menus); j++) { |
972 | if (menu_already_exists) { |
6f2d0cde |
973 | /* XXX does this free up all submenus? */ |
e3be8de5 |
974 | DeleteMenu(popup_menus[j].menu, |
975 | popup_menus[j].specials_submenu_pos, |
976 | MF_BYPOSITION); |
977 | DeleteMenu(popup_menus[j].menu, |
978 | popup_menus[j].specials_submenu_pos, |
979 | MF_BYPOSITION); |
980 | } |
981 | if (specials) { |
982 | InsertMenu(popup_menus[j].menu, |
983 | popup_menus[j].specials_submenu_pos, |
984 | MF_BYPOSITION | MF_SEPARATOR, 0, 0); |
63be7767 |
985 | InsertMenu(popup_menus[j].menu, |
986 | popup_menus[j].specials_submenu_pos, |
987 | MF_BYPOSITION | MF_POPUP | MF_ENABLED, |
0353864c |
988 | (UINT) p, "S&pecial Command"); |
63be7767 |
989 | } |
125105d1 |
990 | } |
991 | } |
992 | |
755e0524 |
993 | static void update_mouse_pointer(void) |
994 | { |
995 | LPTSTR curstype; |
996 | int force_visible = FALSE; |
997 | static int forced_visible = FALSE; |
998 | switch (busy_status) { |
999 | case BUSY_NOT: |
1000 | if (send_raw_mouse) |
1001 | curstype = IDC_ARROW; |
1002 | else |
1003 | curstype = IDC_IBEAM; |
1004 | break; |
1005 | case BUSY_WAITING: |
1006 | curstype = IDC_APPSTARTING; /* this may be an abuse */ |
1007 | force_visible = TRUE; |
1008 | break; |
1009 | case BUSY_CPU: |
1010 | curstype = IDC_WAIT; |
1011 | force_visible = TRUE; |
1012 | break; |
1013 | default: |
1014 | assert(0); |
1015 | } |
1016 | { |
1017 | HCURSOR cursor = LoadCursor(NULL, curstype); |
1018 | SetClassLong(hwnd, GCL_HCURSOR, (LONG)cursor); |
1019 | SetCursor(cursor); /* force redraw of cursor at current posn */ |
1020 | } |
1021 | if (force_visible != forced_visible) { |
1022 | /* We want some cursor shapes to be visible always. |
1023 | * Along with show_mouseptr(), this manages the ShowCursor() |
1024 | * counter such that if we switch back to a non-force_visible |
1025 | * cursor, the previous visibility state is restored. */ |
1026 | ShowCursor(force_visible); |
1027 | forced_visible = force_visible; |
1028 | } |
1029 | } |
1030 | |
1031 | void set_busy_status(void *frontend, int status) |
1032 | { |
1033 | busy_status = status; |
1034 | update_mouse_pointer(); |
1035 | } |
1036 | |
125105d1 |
1037 | /* |
01c034ad |
1038 | * set or clear the "raw mouse message" mode |
1039 | */ |
a8327734 |
1040 | void set_raw_mouse_mode(void *frontend, int activate) |
01c034ad |
1041 | { |
c0d36a72 |
1042 | activate = activate && !cfg.no_mouse_rep; |
01c034ad |
1043 | send_raw_mouse = activate; |
755e0524 |
1044 | update_mouse_pointer(); |
01c034ad |
1045 | } |
1046 | |
1047 | /* |
8d5de777 |
1048 | * Print a message box and close the connection. |
1049 | */ |
a8327734 |
1050 | void connection_fatal(void *frontend, char *fmt, ...) |
32874aea |
1051 | { |
8d5de777 |
1052 | va_list ap; |
971bcc0a |
1053 | char *stuff, morestuff[100]; |
8d5de777 |
1054 | |
1055 | va_start(ap, fmt); |
971bcc0a |
1056 | stuff = dupvprintf(fmt, ap); |
8d5de777 |
1057 | va_end(ap); |
f6f450e2 |
1058 | sprintf(morestuff, "%.70s Fatal Error", appname); |
1059 | MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK); |
971bcc0a |
1060 | sfree(stuff); |
1061 | |
5ecd7ad0 |
1062 | if (cfg.close_on_exit == FORCE_ON) |
32874aea |
1063 | PostQuitMessage(1); |
8d5de777 |
1064 | else { |
e3be8de5 |
1065 | close_session(); |
8d5de777 |
1066 | } |
1067 | } |
1068 | |
1069 | /* |
c0a81592 |
1070 | * Report an error at the command-line parsing stage. |
1071 | */ |
1072 | void cmdline_error(char *fmt, ...) |
1073 | { |
1074 | va_list ap; |
971bcc0a |
1075 | char *stuff, morestuff[100]; |
c0a81592 |
1076 | |
1077 | va_start(ap, fmt); |
971bcc0a |
1078 | stuff = dupvprintf(fmt, ap); |
c0a81592 |
1079 | va_end(ap); |
f6f450e2 |
1080 | sprintf(morestuff, "%.70s Command Line Error", appname); |
1081 | MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK); |
971bcc0a |
1082 | sfree(stuff); |
c0a81592 |
1083 | exit(1); |
1084 | } |
1085 | |
1086 | /* |
59ad2c03 |
1087 | * Actually do the job requested by a WM_NETEVENT |
1088 | */ |
39934deb |
1089 | static void enact_netevent(WPARAM wParam, LPARAM lParam) |
32874aea |
1090 | { |
9dde0b46 |
1091 | static int reentering = 0; |
8df7a775 |
1092 | extern int select_result(WPARAM, LPARAM); |
1093 | int ret; |
9dde0b46 |
1094 | |
1095 | if (reentering) |
32874aea |
1096 | return; /* don't unpend the pending */ |
9dde0b46 |
1097 | |
9dde0b46 |
1098 | reentering = 1; |
39934deb |
1099 | ret = select_result(wParam, lParam); |
9dde0b46 |
1100 | reentering = 0; |
59ad2c03 |
1101 | |
b41069ff |
1102 | if (ret == 0 && !session_closed) { |
32874aea |
1103 | /* Abnormal exits will already have set session_closed and taken |
1104 | * appropriate action. */ |
5ecd7ad0 |
1105 | if (cfg.close_on_exit == FORCE_ON || |
1106 | cfg.close_on_exit == AUTO) PostQuitMessage(0); |
59ad2c03 |
1107 | else { |
e3be8de5 |
1108 | close_session(); |
32874aea |
1109 | session_closed = TRUE; |
32874aea |
1110 | MessageBox(hwnd, "Connection closed by remote host", |
f6f450e2 |
1111 | appname, MB_OK | MB_ICONINFORMATION); |
59ad2c03 |
1112 | } |
1113 | } |
1114 | } |
1115 | |
1116 | /* |
374330e2 |
1117 | * Copy the colour palette from the configuration data into defpal. |
1118 | * This is non-trivial because the colour indices are different. |
1119 | */ |
32874aea |
1120 | static void cfgtopalette(void) |
1121 | { |
374330e2 |
1122 | int i; |
1123 | static const int ww[] = { |
cecb13f6 |
1124 | 256, 257, 258, 259, 260, 261, |
1125 | 0, 8, 1, 9, 2, 10, 3, 11, |
1126 | 4, 12, 5, 13, 6, 14, 7, 15 |
374330e2 |
1127 | }; |
1128 | |
cecb13f6 |
1129 | for (i = 0; i < 22; i++) { |
374330e2 |
1130 | int w = ww[i]; |
cecb13f6 |
1131 | defpal[w].rgbtRed = cfg.colours[i][0]; |
1132 | defpal[w].rgbtGreen = cfg.colours[i][1]; |
1133 | defpal[w].rgbtBlue = cfg.colours[i][2]; |
1134 | } |
1135 | for (i = 0; i < NEXTCOLOURS; i++) { |
1136 | if (i < 216) { |
1137 | int r = i / 36, g = (i / 6) % 6, b = i % 6; |
8098d585 |
1138 | defpal[i+16].rgbtRed = r ? r * 40 + 55 : 0; |
1139 | defpal[i+16].rgbtGreen = g ? g * 40 + 55 : 0; |
1140 | defpal[i+16].rgbtBlue = b ? b * 40 + 55 : 0; |
cecb13f6 |
1141 | } else { |
1142 | int shade = i - 216; |
8098d585 |
1143 | shade = shade * 10 + 8; |
cecb13f6 |
1144 | defpal[i+16].rgbtRed = defpal[i+16].rgbtGreen = |
1145 | defpal[i+16].rgbtBlue = shade; |
1146 | } |
374330e2 |
1147 | } |
26d1da7b |
1148 | |
1149 | /* Override with system colours if appropriate */ |
1150 | if (cfg.system_colour) |
1151 | systopalette(); |
1152 | } |
1153 | |
1154 | /* |
1155 | * Override bit of defpal with colours from the system. |
1156 | * (NB that this takes a copy the system colours at the time this is called, |
1157 | * so subsequent colour scheme changes don't take effect. To fix that we'd |
1158 | * probably want to be using GetSysColorBrush() and the like.) |
1159 | */ |
1160 | static void systopalette(void) |
1161 | { |
1162 | int i; |
1163 | static const struct { int nIndex; int norm; int bold; } or[] = |
1164 | { |
cecb13f6 |
1165 | { COLOR_WINDOWTEXT, 256, 257 }, /* Default Foreground */ |
1166 | { COLOR_WINDOW, 258, 259 }, /* Default Background */ |
1167 | { COLOR_HIGHLIGHTTEXT, 260, 260 }, /* Cursor Text */ |
1168 | { COLOR_HIGHLIGHT, 261, 261 }, /* Cursor Colour */ |
26d1da7b |
1169 | }; |
1170 | |
1171 | for (i = 0; i < (sizeof(or)/sizeof(or[0])); i++) { |
1172 | COLORREF colour = GetSysColor(or[i].nIndex); |
1173 | defpal[or[i].norm].rgbtRed = |
1174 | defpal[or[i].bold].rgbtRed = GetRValue(colour); |
1175 | defpal[or[i].norm].rgbtGreen = |
1176 | defpal[or[i].bold].rgbtGreen = GetGValue(colour); |
1177 | defpal[or[i].norm].rgbtBlue = |
1178 | defpal[or[i].bold].rgbtBlue = GetBValue(colour); |
1179 | } |
374330e2 |
1180 | } |
1181 | |
1182 | /* |
1183 | * Set up the colour palette. |
1184 | */ |
32874aea |
1185 | static void init_palette(void) |
1186 | { |
374330e2 |
1187 | int i; |
32874aea |
1188 | HDC hdc = GetDC(hwnd); |
374330e2 |
1189 | if (hdc) { |
32874aea |
1190 | if (cfg.try_palette && GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) { |
3d88e64d |
1191 | /* |
1192 | * This is a genuine case where we must use smalloc |
1193 | * because the snew macros can't cope. |
1194 | */ |
374330e2 |
1195 | logpal = smalloc(sizeof(*logpal) |
1196 | - sizeof(logpal->palPalEntry) |
cecb13f6 |
1197 | + NALLCOLOURS * sizeof(PALETTEENTRY)); |
374330e2 |
1198 | logpal->palVersion = 0x300; |
cecb13f6 |
1199 | logpal->palNumEntries = NALLCOLOURS; |
1200 | for (i = 0; i < NALLCOLOURS; i++) { |
374330e2 |
1201 | logpal->palPalEntry[i].peRed = defpal[i].rgbtRed; |
1202 | logpal->palPalEntry[i].peGreen = defpal[i].rgbtGreen; |
1203 | logpal->palPalEntry[i].peBlue = defpal[i].rgbtBlue; |
1204 | logpal->palPalEntry[i].peFlags = PC_NOCOLLAPSE; |
1205 | } |
32874aea |
1206 | pal = CreatePalette(logpal); |
374330e2 |
1207 | if (pal) { |
32874aea |
1208 | SelectPalette(hdc, pal, FALSE); |
1209 | RealizePalette(hdc); |
1210 | SelectPalette(hdc, GetStockObject(DEFAULT_PALETTE), FALSE); |
374330e2 |
1211 | } |
1212 | } |
32874aea |
1213 | ReleaseDC(hwnd, hdc); |
374330e2 |
1214 | } |
1215 | if (pal) |
cecb13f6 |
1216 | for (i = 0; i < NALLCOLOURS; i++) |
374330e2 |
1217 | colours[i] = PALETTERGB(defpal[i].rgbtRed, |
1218 | defpal[i].rgbtGreen, |
1219 | defpal[i].rgbtBlue); |
1220 | else |
cecb13f6 |
1221 | for (i = 0; i < NALLCOLOURS; i++) |
374330e2 |
1222 | colours[i] = RGB(defpal[i].rgbtRed, |
32874aea |
1223 | defpal[i].rgbtGreen, defpal[i].rgbtBlue); |
374330e2 |
1224 | } |
1225 | |
1226 | /* |
f0fccd51 |
1227 | * This is a wrapper to ExtTextOut() to force Windows to display |
1228 | * the precise glyphs we give it. Otherwise it would do its own |
1229 | * bidi and Arabic shaping, and we would end up uncertain which |
1230 | * characters it had put where. |
1231 | */ |
1232 | static void exact_textout(HDC hdc, int x, int y, CONST RECT *lprc, |
1233 | unsigned short *lpString, UINT cbCount, |
c6958dfe |
1234 | CONST INT *lpDx, int opaque) |
f0fccd51 |
1235 | { |
b7625258 |
1236 | #ifdef __LCC__ |
1237 | /* |
1238 | * The LCC include files apparently don't supply the |
1239 | * GCP_RESULTSW type, but we can make do with GCP_RESULTS |
1240 | * proper: the differences aren't important to us (the only |
1241 | * variable-width string parameter is one we don't use anyway). |
1242 | */ |
1243 | GCP_RESULTS gcpr; |
1244 | #else |
f0fccd51 |
1245 | GCP_RESULTSW gcpr; |
b7625258 |
1246 | #endif |
f0fccd51 |
1247 | char *buffer = snewn(cbCount*2+2, char); |
1248 | char *classbuffer = snewn(cbCount, char); |
1249 | memset(&gcpr, 0, sizeof(gcpr)); |
1250 | memset(buffer, 0, cbCount*2+2); |
1251 | memset(classbuffer, GCPCLASS_NEUTRAL, cbCount); |
1252 | |
1253 | gcpr.lStructSize = sizeof(gcpr); |
1254 | gcpr.lpGlyphs = (void *)buffer; |
1255 | gcpr.lpClass = classbuffer; |
1256 | gcpr.nGlyphs = cbCount; |
1257 | |
1258 | GetCharacterPlacementW(hdc, lpString, cbCount, 0, &gcpr, |
c6958dfe |
1259 | FLI_MASK | GCP_CLASSIN | GCP_DIACRITIC); |
f0fccd51 |
1260 | |
c6958dfe |
1261 | ExtTextOut(hdc, x, y, |
1262 | ETO_GLYPH_INDEX | ETO_CLIPPED | (opaque ? ETO_OPAQUE : 0), |
1263 | lprc, buffer, cbCount, lpDx); |
f0fccd51 |
1264 | } |
1265 | |
1266 | /* |
4eeb7d09 |
1267 | * Initialise all the fonts we will need initially. There may be as many as |
1268 | * three or as few as one. The other (poentially) twentyone fonts are done |
1269 | * if/when they are needed. |
1270 | * |
1271 | * We also: |
374330e2 |
1272 | * |
1273 | * - check the font width and height, correcting our guesses if |
1274 | * necessary. |
1275 | * |
1276 | * - verify that the bold font is the same width as the ordinary |
1277 | * one, and engage shadow bolding if not. |
1278 | * |
1279 | * - verify that the underlined font is the same width as the |
1280 | * ordinary one (manual underlining by means of line drawing can |
1281 | * be done in a pinch). |
374330e2 |
1282 | */ |
5a73255e |
1283 | static void init_fonts(int pick_width, int pick_height) |
32874aea |
1284 | { |
374330e2 |
1285 | TEXTMETRIC tm; |
4eeb7d09 |
1286 | CPINFO cpinfo; |
1287 | int fontsize[3]; |
97fc891e |
1288 | int i; |
374330e2 |
1289 | HDC hdc; |
1290 | int fw_dontcare, fw_bold; |
1291 | |
4eeb7d09 |
1292 | for (i = 0; i < FONT_MAXNO; i++) |
374330e2 |
1293 | fonts[i] = NULL; |
1294 | |
5a73255e |
1295 | bold_mode = cfg.bold_colour ? BOLD_COLOURS : BOLD_FONT; |
1296 | und_mode = UND_FONT; |
1297 | |
9a30e26b |
1298 | if (cfg.font.isbold) { |
374330e2 |
1299 | fw_dontcare = FW_BOLD; |
5b80d07f |
1300 | fw_bold = FW_HEAVY; |
32874aea |
1301 | } else { |
374330e2 |
1302 | fw_dontcare = FW_DONTCARE; |
1303 | fw_bold = FW_BOLD; |
1304 | } |
1305 | |
97fc891e |
1306 | hdc = GetDC(hwnd); |
1307 | |
5a73255e |
1308 | if (pick_height) |
1309 | font_height = pick_height; |
1310 | else { |
9a30e26b |
1311 | font_height = cfg.font.height; |
5a73255e |
1312 | if (font_height > 0) { |
1313 | font_height = |
1314 | -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72); |
1315 | } |
3b2c664e |
1316 | } |
59ad2c03 |
1317 | font_width = pick_width; |
97fc891e |
1318 | |
374330e2 |
1319 | #define f(i,c,w,u) \ |
97fc891e |
1320 | fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \ |
374330e2 |
1321 | c, OUT_DEFAULT_PRECIS, \ |
17c7fed1 |
1322 | CLIP_DEFAULT_PRECIS, FONT_QUALITY(cfg.font_quality), \ |
9a30e26b |
1323 | FIXED_PITCH | FF_DONTCARE, cfg.font.name) |
97fc891e |
1324 | |
9a30e26b |
1325 | f(FONT_NORMAL, cfg.font.charset, fw_dontcare, FALSE); |
97fc891e |
1326 | |
4eeb7d09 |
1327 | SelectObject(hdc, fonts[FONT_NORMAL]); |
1328 | GetTextMetrics(hdc, &tm); |
5a73255e |
1329 | |
fd64bb27 |
1330 | GetObject(fonts[FONT_NORMAL], sizeof(LOGFONT), &lfont); |
1331 | |
5a73255e |
1332 | if (pick_width == 0 || pick_height == 0) { |
1333 | font_height = tm.tmHeight; |
1334 | font_width = tm.tmAveCharWidth; |
1335 | } |
1336 | font_dualwidth = (tm.tmAveCharWidth != tm.tmMaxCharWidth); |
1337 | |
1338 | #ifdef RDB_DEBUG_PATCH |
1339 | debug(23, "Primary font H=%d, AW=%d, MW=%d", |
1340 | tm.tmHeight, tm.tmAveCharWidth, tm.tmMaxCharWidth); |
1341 | #endif |
97fc891e |
1342 | |
4eeb7d09 |
1343 | { |
1344 | CHARSETINFO info; |
1345 | DWORD cset = tm.tmCharSet; |
1346 | memset(&info, 0xFF, sizeof(info)); |
97fc891e |
1347 | |
4eeb7d09 |
1348 | /* !!! Yes the next line is right */ |
1349 | if (cset == OEM_CHARSET) |
21d2b241 |
1350 | ucsdata.font_codepage = GetOEMCP(); |
4eeb7d09 |
1351 | else |
21d2b241 |
1352 | if (TranslateCharsetInfo ((DWORD *) cset, &info, TCI_SRCCHARSET)) |
1353 | ucsdata.font_codepage = info.ciACP; |
4eeb7d09 |
1354 | else |
21d2b241 |
1355 | ucsdata.font_codepage = -1; |
32874aea |
1356 | |
21d2b241 |
1357 | GetCPInfo(ucsdata.font_codepage, &cpinfo); |
1358 | ucsdata.dbcs_screenfont = (cpinfo.MaxCharSize > 1); |
4eeb7d09 |
1359 | } |
97fc891e |
1360 | |
9a30e26b |
1361 | f(FONT_UNDERLINE, cfg.font.charset, fw_dontcare, TRUE); |
97fc891e |
1362 | |
4eeb7d09 |
1363 | /* |
1364 | * Some fonts, e.g. 9-pt Courier, draw their underlines |
1365 | * outside their character cell. We successfully prevent |
1366 | * screen corruption by clipping the text output, but then |
1367 | * we lose the underline completely. Here we try to work |
1368 | * out whether this is such a font, and if it is, we set a |
1369 | * flag that causes underlines to be drawn by hand. |
1370 | * |
1371 | * Having tried other more sophisticated approaches (such |
1372 | * as examining the TEXTMETRIC structure or requesting the |
1373 | * height of a string), I think we'll do this the brute |
1374 | * force way: we create a small bitmap, draw an underlined |
1375 | * space on it, and test to see whether any pixels are |
1376 | * foreground-coloured. (Since we expect the underline to |
1377 | * go all the way across the character cell, we only search |
1378 | * down a single column of the bitmap, half way across.) |
1379 | */ |
1380 | { |
1381 | HDC und_dc; |
1382 | HBITMAP und_bm, und_oldbm; |
1383 | int i, gotit; |
1384 | COLORREF c; |
1385 | |
1386 | und_dc = CreateCompatibleDC(hdc); |
1387 | und_bm = CreateCompatibleBitmap(hdc, font_width, font_height); |
1388 | und_oldbm = SelectObject(und_dc, und_bm); |
1389 | SelectObject(und_dc, fonts[FONT_UNDERLINE]); |
1390 | SetTextAlign(und_dc, TA_TOP | TA_LEFT | TA_NOUPDATECP); |
1391 | SetTextColor(und_dc, RGB(255, 255, 255)); |
1392 | SetBkColor(und_dc, RGB(0, 0, 0)); |
1393 | SetBkMode(und_dc, OPAQUE); |
1394 | ExtTextOut(und_dc, 0, 0, ETO_OPAQUE, NULL, " ", 1, NULL); |
1395 | gotit = FALSE; |
1396 | for (i = 0; i < font_height; i++) { |
1397 | c = GetPixel(und_dc, font_width / 2, i); |
1398 | if (c != RGB(0, 0, 0)) |
1399 | gotit = TRUE; |
1400 | } |
1401 | SelectObject(und_dc, und_oldbm); |
1402 | DeleteObject(und_bm); |
1403 | DeleteDC(und_dc); |
1404 | if (!gotit) { |
1405 | und_mode = UND_LINE; |
1406 | DeleteObject(fonts[FONT_UNDERLINE]); |
1407 | fonts[FONT_UNDERLINE] = 0; |
32874aea |
1408 | } |
4eeb7d09 |
1409 | } |
97fc891e |
1410 | |
4eeb7d09 |
1411 | if (bold_mode == BOLD_FONT) { |
9a30e26b |
1412 | f(FONT_BOLD, cfg.font.charset, fw_bold, FALSE); |
374330e2 |
1413 | } |
1414 | #undef f |
1415 | |
97fc891e |
1416 | descent = tm.tmAscent + 1; |
1417 | if (descent >= font_height) |
1418 | descent = font_height - 1; |
374330e2 |
1419 | |
4eeb7d09 |
1420 | for (i = 0; i < 3; i++) { |
97fc891e |
1421 | if (fonts[i]) { |
32874aea |
1422 | if (SelectObject(hdc, fonts[i]) && GetTextMetrics(hdc, &tm)) |
4eeb7d09 |
1423 | fontsize[i] = tm.tmAveCharWidth + 256 * tm.tmHeight; |
32874aea |
1424 | else |
4eeb7d09 |
1425 | fontsize[i] = -i; |
32874aea |
1426 | } else |
4eeb7d09 |
1427 | fontsize[i] = -i; |
374330e2 |
1428 | } |
1429 | |
32874aea |
1430 | ReleaseDC(hwnd, hdc); |
374330e2 |
1431 | |
4eeb7d09 |
1432 | if (fontsize[FONT_UNDERLINE] != fontsize[FONT_NORMAL]) { |
374330e2 |
1433 | und_mode = UND_LINE; |
32874aea |
1434 | DeleteObject(fonts[FONT_UNDERLINE]); |
4eeb7d09 |
1435 | fonts[FONT_UNDERLINE] = 0; |
374330e2 |
1436 | } |
1437 | |
4eeb7d09 |
1438 | if (bold_mode == BOLD_FONT && |
1439 | fontsize[FONT_BOLD] != fontsize[FONT_NORMAL]) { |
374330e2 |
1440 | bold_mode = BOLD_SHADOW; |
32874aea |
1441 | DeleteObject(fonts[FONT_BOLD]); |
4eeb7d09 |
1442 | fonts[FONT_BOLD] = 0; |
374330e2 |
1443 | } |
4eeb7d09 |
1444 | fontflag[0] = fontflag[1] = fontflag[2] = 1; |
1445 | |
21d2b241 |
1446 | init_ucs(&cfg, &ucsdata); |
4eeb7d09 |
1447 | } |
1448 | |
1449 | static void another_font(int fontno) |
1450 | { |
1451 | int basefont; |
1452 | int fw_dontcare, fw_bold; |
1453 | int c, u, w, x; |
1454 | char *s; |
1455 | |
1456 | if (fontno < 0 || fontno >= FONT_MAXNO || fontflag[fontno]) |
1457 | return; |
1458 | |
1459 | basefont = (fontno & ~(FONT_BOLDUND)); |
1460 | if (basefont != fontno && !fontflag[basefont]) |
1461 | another_font(basefont); |
97fc891e |
1462 | |
9a30e26b |
1463 | if (cfg.font.isbold) { |
4eeb7d09 |
1464 | fw_dontcare = FW_BOLD; |
1465 | fw_bold = FW_HEAVY; |
1466 | } else { |
1467 | fw_dontcare = FW_DONTCARE; |
1468 | fw_bold = FW_BOLD; |
1469 | } |
1470 | |
9a30e26b |
1471 | c = cfg.font.charset; |
4eeb7d09 |
1472 | w = fw_dontcare; |
1473 | u = FALSE; |
9a30e26b |
1474 | s = cfg.font.name; |
4eeb7d09 |
1475 | x = font_width; |
1476 | |
1477 | if (fontno & FONT_WIDE) |
1478 | x *= 2; |
1479 | if (fontno & FONT_NARROW) |
5a73255e |
1480 | x = (x+1)/2; |
4eeb7d09 |
1481 | if (fontno & FONT_OEM) |
1482 | c = OEM_CHARSET; |
1483 | if (fontno & FONT_BOLD) |
1484 | w = fw_bold; |
1485 | if (fontno & FONT_UNDERLINE) |
1486 | u = TRUE; |
1487 | |
1488 | fonts[fontno] = |
1489 | CreateFont(font_height * (1 + !!(fontno & FONT_HIGH)), x, 0, 0, w, |
1490 | FALSE, u, FALSE, c, OUT_DEFAULT_PRECIS, |
17c7fed1 |
1491 | CLIP_DEFAULT_PRECIS, FONT_QUALITY(cfg.font_quality), |
4eeb7d09 |
1492 | FIXED_PITCH | FF_DONTCARE, s); |
1493 | |
1494 | fontflag[fontno] = 1; |
1495 | } |
1496 | |
1497 | static void deinit_fonts(void) |
1498 | { |
1499 | int i; |
1500 | for (i = 0; i < FONT_MAXNO; i++) { |
1501 | if (fonts[i]) |
1502 | DeleteObject(fonts[i]); |
1503 | fonts[i] = 0; |
1504 | fontflag[i] = 0; |
374330e2 |
1505 | } |
1506 | } |
1507 | |
a8327734 |
1508 | void request_resize(void *frontend, int w, int h) |
32874aea |
1509 | { |
59ad2c03 |
1510 | int width, height; |
c9def1b8 |
1511 | |
1512 | /* If the window is maximized supress resizing attempts */ |
5a73255e |
1513 | if (IsZoomed(hwnd)) { |
0ed2f48e |
1514 | if (cfg.resize_action == RESIZE_TERM) |
5a73255e |
1515 | return; |
1516 | } |
32874aea |
1517 | |
ad5c93cc |
1518 | if (cfg.resize_action == RESIZE_DISABLED) return; |
887035a5 |
1519 | if (h == term->rows && w == term->cols) return; |
5a73255e |
1520 | |
1521 | /* Sanity checks ... */ |
1522 | { |
32874aea |
1523 | static int first_time = 1; |
1524 | static RECT ss; |
1525 | |
1526 | switch (first_time) { |
1527 | case 1: |
1528 | /* Get the size of the screen */ |
d0f1bcb4 |
1529 | if (get_fullscreen_rect(&ss)) |
32874aea |
1530 | /* first_time = 0 */ ; |
1531 | else { |
1532 | first_time = 2; |
1533 | break; |
1534 | } |
1535 | case 0: |
1536 | /* Make sure the values are sane */ |
5a73255e |
1537 | width = (ss.right - ss.left - extra_width) / 4; |
1538 | height = (ss.bottom - ss.top - extra_height) / 6; |
32874aea |
1539 | |
5a73255e |
1540 | if (w > width || h > height) |
1541 | return; |
32874aea |
1542 | if (w < 15) |
1543 | w = 15; |
1544 | if (h < 1) |
5a73255e |
1545 | h = 1; |
32874aea |
1546 | } |
c9def1b8 |
1547 | } |
59ad2c03 |
1548 | |
887035a5 |
1549 | term_size(term, h, w, cfg.savelines); |
5a73255e |
1550 | |
0ed2f48e |
1551 | if (cfg.resize_action != RESIZE_FONT && !IsZoomed(hwnd)) { |
5a73255e |
1552 | width = extra_width + font_width * w; |
1553 | height = extra_height + font_height * h; |
374330e2 |
1554 | |
5a73255e |
1555 | SetWindowPos(hwnd, NULL, 0, 0, width, height, |
1556 | SWP_NOACTIVATE | SWP_NOCOPYBITS | |
1557 | SWP_NOMOVE | SWP_NOZORDER); |
1558 | } else |
1559 | reset_window(0); |
1560 | |
1561 | InvalidateRect(hwnd, NULL, TRUE); |
1562 | } |
1563 | |
1564 | static void reset_window(int reinit) { |
1565 | /* |
1566 | * This function decides how to resize or redraw when the |
1567 | * user changes something. |
1568 | * |
1569 | * This function doesn't like to change the terminal size but if the |
1570 | * font size is locked that may be it's only soluion. |
1571 | */ |
1572 | int win_width, win_height; |
1573 | RECT cr, wr; |
1574 | |
1575 | #ifdef RDB_DEBUG_PATCH |
1576 | debug((27, "reset_window()")); |
1577 | #endif |
1578 | |
1579 | /* Current window sizes ... */ |
1580 | GetWindowRect(hwnd, &wr); |
1581 | GetClientRect(hwnd, &cr); |
1582 | |
1583 | win_width = cr.right - cr.left; |
1584 | win_height = cr.bottom - cr.top; |
1585 | |
0ed2f48e |
1586 | if (cfg.resize_action == RESIZE_DISABLED) reinit = 2; |
1587 | |
5a73255e |
1588 | /* Are we being forced to reload the fonts ? */ |
1589 | if (reinit>1) { |
1590 | #ifdef RDB_DEBUG_PATCH |
1591 | debug((27, "reset_window() -- Forced deinit")); |
1592 | #endif |
1593 | deinit_fonts(); |
1594 | init_fonts(0,0); |
1595 | } |
1596 | |
1597 | /* Oh, looks like we're minimised */ |
1598 | if (win_width == 0 || win_height == 0) |
1599 | return; |
1600 | |
1601 | /* Is the window out of position ? */ |
1602 | if ( !reinit && |
887035a5 |
1603 | (offset_width != (win_width-font_width*term->cols)/2 || |
1604 | offset_height != (win_height-font_height*term->rows)/2) ){ |
1605 | offset_width = (win_width-font_width*term->cols)/2; |
1606 | offset_height = (win_height-font_height*term->rows)/2; |
5a73255e |
1607 | InvalidateRect(hwnd, NULL, TRUE); |
1608 | #ifdef RDB_DEBUG_PATCH |
1609 | debug((27, "reset_window() -> Reposition terminal")); |
1610 | #endif |
1611 | } |
1612 | |
6003660f |
1613 | if (IsZoomed(hwnd)) { |
5a73255e |
1614 | /* We're fullscreen, this means we must not change the size of |
1615 | * the window so it's the font size or the terminal itself. |
1616 | */ |
1617 | |
1618 | extra_width = wr.right - wr.left - cr.right + cr.left; |
1619 | extra_height = wr.bottom - wr.top - cr.bottom + cr.top; |
1620 | |
0ed2f48e |
1621 | if (cfg.resize_action != RESIZE_TERM) { |
887035a5 |
1622 | if ( font_width != win_width/term->cols || |
1623 | font_height != win_height/term->rows) { |
5a73255e |
1624 | deinit_fonts(); |
887035a5 |
1625 | init_fonts(win_width/term->cols, win_height/term->rows); |
1626 | offset_width = (win_width-font_width*term->cols)/2; |
1627 | offset_height = (win_height-font_height*term->rows)/2; |
5a73255e |
1628 | InvalidateRect(hwnd, NULL, TRUE); |
1629 | #ifdef RDB_DEBUG_PATCH |
1630 | debug((25, "reset_window() -> Z font resize to (%d, %d)", |
1631 | font_width, font_height)); |
1632 | #endif |
1633 | } |
1634 | } else { |
887035a5 |
1635 | if ( font_width != win_width/term->cols || |
1636 | font_height != win_height/term->rows) { |
5a73255e |
1637 | /* Our only choice at this point is to change the |
1638 | * size of the terminal; Oh well. |
1639 | */ |
887035a5 |
1640 | term_size(term, win_height/font_height, win_width/font_width, |
1641 | cfg.savelines); |
1642 | offset_width = (win_width-font_width*term->cols)/2; |
1643 | offset_height = (win_height-font_height*term->rows)/2; |
5a73255e |
1644 | InvalidateRect(hwnd, NULL, TRUE); |
1645 | #ifdef RDB_DEBUG_PATCH |
1646 | debug((27, "reset_window() -> Zoomed term_size")); |
1647 | #endif |
1648 | } |
1649 | } |
1650 | return; |
1651 | } |
1652 | |
1653 | /* Hmm, a force re-init means we should ignore the current window |
1654 | * so we resize to the default font size. |
1655 | */ |
1656 | if (reinit>0) { |
1657 | #ifdef RDB_DEBUG_PATCH |
1658 | debug((27, "reset_window() -> Forced re-init")); |
1659 | #endif |
1660 | |
1661 | offset_width = offset_height = cfg.window_border; |
1662 | extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2; |
1663 | extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2; |
1664 | |
887035a5 |
1665 | if (win_width != font_width*term->cols + offset_width*2 || |
1666 | win_height != font_height*term->rows + offset_height*2) { |
5a73255e |
1667 | |
1668 | /* If this is too large windows will resize it to the maximum |
1669 | * allowed window size, we will then be back in here and resize |
1670 | * the font or terminal to fit. |
1671 | */ |
1672 | SetWindowPos(hwnd, NULL, 0, 0, |
887035a5 |
1673 | font_width*term->cols + extra_width, |
1674 | font_height*term->rows + extra_height, |
5a73255e |
1675 | SWP_NOMOVE | SWP_NOZORDER); |
1676 | } |
0ed2f48e |
1677 | |
1678 | InvalidateRect(hwnd, NULL, TRUE); |
5a73255e |
1679 | return; |
1680 | } |
1681 | |
1682 | /* Okay the user doesn't want us to change the font so we try the |
1683 | * window. But that may be too big for the screen which forces us |
1684 | * to change the terminal. |
1685 | */ |
0ed2f48e |
1686 | if ((cfg.resize_action == RESIZE_TERM && reinit<=0) || |
1687 | (cfg.resize_action == RESIZE_EITHER && reinit<0) || |
1688 | reinit>0) { |
5a73255e |
1689 | offset_width = offset_height = cfg.window_border; |
1690 | extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2; |
1691 | extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2; |
1692 | |
887035a5 |
1693 | if (win_width != font_width*term->cols + offset_width*2 || |
1694 | win_height != font_height*term->rows + offset_height*2) { |
5a73255e |
1695 | |
1696 | static RECT ss; |
1697 | int width, height; |
d0f1bcb4 |
1698 | |
1699 | get_fullscreen_rect(&ss); |
5a73255e |
1700 | |
5a73255e |
1701 | width = (ss.right - ss.left - extra_width) / font_width; |
1702 | height = (ss.bottom - ss.top - extra_height) / font_height; |
1703 | |
1704 | /* Grrr too big */ |
887035a5 |
1705 | if ( term->rows > height || term->cols > width ) { |
0ed2f48e |
1706 | if (cfg.resize_action == RESIZE_EITHER) { |
1707 | /* Make the font the biggest we can */ |
887035a5 |
1708 | if (term->cols > width) |
1709 | font_width = (ss.right - ss.left - extra_width) |
1710 | / term->cols; |
1711 | if (term->rows > height) |
1712 | font_height = (ss.bottom - ss.top - extra_height) |
1713 | / term->rows; |
0ed2f48e |
1714 | |
1715 | deinit_fonts(); |
1716 | init_fonts(font_width, font_height); |
1717 | |
1718 | width = (ss.right - ss.left - extra_width) / font_width; |
1719 | height = (ss.bottom - ss.top - extra_height) / font_height; |
1720 | } else { |
887035a5 |
1721 | if ( height > term->rows ) height = term->rows; |
1722 | if ( width > term->cols ) width = term->cols; |
1723 | term_size(term, height, width, cfg.savelines); |
5a73255e |
1724 | #ifdef RDB_DEBUG_PATCH |
0ed2f48e |
1725 | debug((27, "reset_window() -> term resize to (%d,%d)", |
1726 | height, width)); |
5a73255e |
1727 | #endif |
0ed2f48e |
1728 | } |
5a73255e |
1729 | } |
1730 | |
1731 | SetWindowPos(hwnd, NULL, 0, 0, |
887035a5 |
1732 | font_width*term->cols + extra_width, |
1733 | font_height*term->rows + extra_height, |
5a73255e |
1734 | SWP_NOMOVE | SWP_NOZORDER); |
1735 | |
1736 | InvalidateRect(hwnd, NULL, TRUE); |
1737 | #ifdef RDB_DEBUG_PATCH |
1738 | debug((27, "reset_window() -> window resize to (%d,%d)", |
887035a5 |
1739 | font_width*term->cols + extra_width, |
1740 | font_height*term->rows + extra_height)); |
5a73255e |
1741 | #endif |
1742 | } |
1743 | return; |
1744 | } |
1745 | |
1746 | /* We're allowed to or must change the font but do we want to ? */ |
1747 | |
887035a5 |
1748 | if (font_width != (win_width-cfg.window_border*2)/term->cols || |
1749 | font_height != (win_height-cfg.window_border*2)/term->rows) { |
5a73255e |
1750 | |
1751 | deinit_fonts(); |
887035a5 |
1752 | init_fonts((win_width-cfg.window_border*2)/term->cols, |
1753 | (win_height-cfg.window_border*2)/term->rows); |
1754 | offset_width = (win_width-font_width*term->cols)/2; |
1755 | offset_height = (win_height-font_height*term->rows)/2; |
5a73255e |
1756 | |
1757 | extra_width = wr.right - wr.left - cr.right + cr.left +offset_width*2; |
1758 | extra_height = wr.bottom - wr.top - cr.bottom + cr.top+offset_height*2; |
1759 | |
1760 | InvalidateRect(hwnd, NULL, TRUE); |
1761 | #ifdef RDB_DEBUG_PATCH |
1762 | debug((25, "reset_window() -> font resize to (%d,%d)", |
1763 | font_width, font_height)); |
1764 | #endif |
1765 | } |
374330e2 |
1766 | } |
1767 | |
a5ce2e9f |
1768 | static void set_input_locale(HKL kl) |
1769 | { |
1770 | char lbuf[20]; |
1771 | |
1772 | GetLocaleInfo(LOWORD(kl), LOCALE_IDEFAULTANSICODEPAGE, |
1773 | lbuf, sizeof(lbuf)); |
1774 | |
1775 | kbd_codepage = atoi(lbuf); |
1776 | } |
1777 | |
6908fed7 |
1778 | static void click(Mouse_Button b, int x, int y, int shift, int ctrl, int alt) |
32874aea |
1779 | { |
fdedf2c8 |
1780 | int thistime = GetMessageTime(); |
1781 | |
b90840c3 |
1782 | if (send_raw_mouse && !(cfg.mouse_override && shift)) { |
1783 | lastbtn = MBT_NOTHING; |
fc5b0934 |
1784 | term_mouse(term, b, translate_button(b), MA_CLICK, |
1785 | x, y, shift, ctrl, alt); |
01c034ad |
1786 | return; |
1787 | } |
1788 | |
fdedf2c8 |
1789 | if (lastbtn == b && thistime - lasttime < dbltime) { |
374330e2 |
1790 | lastact = (lastact == MA_CLICK ? MA_2CLK : |
1791 | lastact == MA_2CLK ? MA_3CLK : |
1792 | lastact == MA_3CLK ? MA_CLICK : MA_NOTHING); |
1793 | } else { |
1794 | lastbtn = b; |
1795 | lastact = MA_CLICK; |
1796 | } |
1797 | if (lastact != MA_NOTHING) |
fc5b0934 |
1798 | term_mouse(term, b, translate_button(b), lastact, |
1799 | x, y, shift, ctrl, alt); |
fdedf2c8 |
1800 | lasttime = thistime; |
374330e2 |
1801 | } |
1802 | |
01c034ad |
1803 | /* |
1804 | * Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT) |
1805 | * into a cooked one (SELECT, EXTEND, PASTE). |
1806 | */ |
2c02ed02 |
1807 | static Mouse_Button translate_button(Mouse_Button button) |
32874aea |
1808 | { |
01c034ad |
1809 | if (button == MBT_LEFT) |
1810 | return MBT_SELECT; |
1811 | if (button == MBT_MIDDLE) |
ebc0310d |
1812 | return cfg.mouse_is_xterm == 1 ? MBT_PASTE : MBT_EXTEND; |
01c034ad |
1813 | if (button == MBT_RIGHT) |
ebc0310d |
1814 | return cfg.mouse_is_xterm == 1 ? MBT_EXTEND : MBT_PASTE; |
2d466ffd |
1815 | return 0; /* shouldn't happen */ |
01c034ad |
1816 | } |
1817 | |
32874aea |
1818 | static void show_mouseptr(int show) |
1819 | { |
755e0524 |
1820 | /* NB that the counter in ShowCursor() is also frobbed by |
1821 | * update_mouse_pointer() */ |
554c540d |
1822 | static int cursor_visible = 1; |
32874aea |
1823 | if (!cfg.hide_mouseptr) /* override if this feature disabled */ |
1824 | show = 1; |
554c540d |
1825 | if (cursor_visible && !show) |
32874aea |
1826 | ShowCursor(FALSE); |
554c540d |
1827 | else if (!cursor_visible && show) |
32874aea |
1828 | ShowCursor(TRUE); |
554c540d |
1829 | cursor_visible = show; |
1830 | } |
1831 | |
6908fed7 |
1832 | static int is_alt_pressed(void) |
1833 | { |
1834 | BYTE keystate[256]; |
1835 | int r = GetKeyboardState(keystate); |
1836 | if (!r) |
1837 | return FALSE; |
1838 | if (keystate[VK_MENU] & 0x80) |
1839 | return TRUE; |
1840 | if (keystate[VK_RMENU] & 0x80) |
1841 | return TRUE; |
1842 | return FALSE; |
1843 | } |
1844 | |
25dba9e5 |
1845 | static int is_shift_pressed(void) |
1846 | { |
1847 | BYTE keystate[256]; |
1848 | int r = GetKeyboardState(keystate); |
1849 | if (!r) |
1850 | return FALSE; |
1851 | if (keystate[VK_SHIFT] & 0x80) |
1852 | return TRUE; |
1853 | return FALSE; |
1854 | } |
1855 | |
68f9b3d9 |
1856 | static int resizing; |
1857 | |
39934deb |
1858 | void notify_remote_exit(void *fe) { /* stub not needed in this frontend */ } |
1859 | |
1860 | void timer_change_notify(long next) |
1861 | { |
1862 | long ticks = next - GETTICKCOUNT(); |
1863 | if (ticks <= 0) ticks = 1; /* just in case */ |
1864 | KillTimer(hwnd, TIMING_TIMER_ID); |
1865 | SetTimer(hwnd, TIMING_TIMER_ID, ticks, NULL); |
1866 | timing_next_time = next; |
1867 | } |
1868 | |
32874aea |
1869 | static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
1870 | WPARAM wParam, LPARAM lParam) |
1871 | { |
374330e2 |
1872 | HDC hdc; |
374330e2 |
1873 | static int ignore_clip = FALSE; |
3ad8c6db |
1874 | static int need_backend_resize = FALSE; |
1ba99d2c |
1875 | static int fullscr_on_max = FALSE; |
d8a13f62 |
1876 | static UINT last_mousemove = 0; |
374330e2 |
1877 | |
1878 | switch (message) { |
59ad2c03 |
1879 | case WM_TIMER: |
39934deb |
1880 | if ((UINT_PTR)wParam == TIMING_TIMER_ID) { |
1881 | long next; |
1882 | |
1883 | KillTimer(hwnd, TIMING_TIMER_ID); |
1884 | if (run_timers(timing_next_time, &next)) { |
1885 | timer_change_notify(next); |
1886 | } else { |
32874aea |
1887 | } |
1888 | } |
59ad2c03 |
1889 | return 0; |
374330e2 |
1890 | case WM_CREATE: |
1891 | break; |
68130d34 |
1892 | case WM_CLOSE: |
f6f450e2 |
1893 | { |
1894 | char *str; |
1895 | show_mouseptr(1); |
1896 | str = dupprintf("%s Exit Confirmation", appname); |
1897 | if (!cfg.warn_on_close || session_closed || |
1898 | MessageBox(hwnd, |
1899 | "Are you sure you want to close this session?", |
84d264cd |
1900 | str, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1) |
76347f46 |
1901 | == IDOK) |
f6f450e2 |
1902 | DestroyWindow(hwnd); |
1903 | sfree(str); |
1904 | } |
68130d34 |
1905 | return 0; |
374330e2 |
1906 | case WM_DESTROY: |
32874aea |
1907 | show_mouseptr(1); |
1908 | PostQuitMessage(0); |
374330e2 |
1909 | return 0; |
12745e35 |
1910 | case WM_INITMENUPOPUP: |
1911 | if ((HMENU)wParam == savedsess_menu) { |
1912 | /* About to pop up Saved Sessions sub-menu. |
1913 | * Refresh the session list. */ |
1914 | get_sesslist(&sesslist, FALSE); /* free */ |
1915 | get_sesslist(&sesslist, TRUE); |
1916 | update_savedsess_menu(); |
1917 | return 0; |
1918 | } |
1919 | break; |
63be7767 |
1920 | case WM_COMMAND: |
6833a413 |
1921 | case WM_SYSCOMMAND: |
1922 | switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */ |
374330e2 |
1923 | case IDM_SHOWLOG: |
c5e9c988 |
1924 | showeventlog(hwnd); |
374330e2 |
1925 | break; |
1926 | case IDM_NEWSESS: |
1927 | case IDM_DUPSESS: |
6833a413 |
1928 | case IDM_SAVEDSESS: |
374330e2 |
1929 | { |
1930 | char b[2048]; |
1931 | char c[30], *cl; |
e4e4cc7e |
1932 | int freecl = FALSE; |
8e90e4c6 |
1933 | BOOL inherit_handles; |
374330e2 |
1934 | STARTUPINFO si; |
1935 | PROCESS_INFORMATION pi; |
1936 | HANDLE filemap = NULL; |
1937 | |
1938 | if (wParam == IDM_DUPSESS) { |
1939 | /* |
1940 | * Allocate a file-mapping memory chunk for the |
1941 | * config structure. |
1942 | */ |
1943 | SECURITY_ATTRIBUTES sa; |
1944 | Config *p; |
1945 | |
1946 | sa.nLength = sizeof(sa); |
1947 | sa.lpSecurityDescriptor = NULL; |
1948 | sa.bInheritHandle = TRUE; |
32874aea |
1949 | filemap = CreateFileMapping((HANDLE) 0xFFFFFFFF, |
374330e2 |
1950 | &sa, |
1951 | PAGE_READWRITE, |
32874aea |
1952 | 0, sizeof(Config), NULL); |
374330e2 |
1953 | if (filemap) { |
32874aea |
1954 | p = (Config *) MapViewOfFile(filemap, |
1955 | FILE_MAP_WRITE, |
1956 | 0, 0, sizeof(Config)); |
374330e2 |
1957 | if (p) { |
1958 | *p = cfg; /* structure copy */ |
1959 | UnmapViewOfFile(p); |
1960 | } |
1961 | } |
8e90e4c6 |
1962 | inherit_handles = TRUE; |
1d470ad2 |
1963 | sprintf(c, "putty &%p", filemap); |
374330e2 |
1964 | cl = c; |
0a4aa984 |
1965 | } else if (wParam == IDM_SAVEDSESS) { |
865e82ad |
1966 | unsigned int sessno = ((lParam - IDM_SAVED_MIN) |
1967 | / MENU_SAVED_STEP) + 1; |
1f1e3232 |
1968 | if (sessno < sesslist.nsessions) { |
1969 | char *session = sesslist.sessions[sessno]; |
1970 | /* XXX spaces? quotes? "-load"? */ |
1971 | cl = dupprintf("putty @%s", session); |
8e90e4c6 |
1972 | inherit_handles = FALSE; |
1f1e3232 |
1973 | freecl = TRUE; |
f8d7977b |
1974 | } else |
1975 | break; |
8e90e4c6 |
1976 | } else /* IDM_NEWSESS */ { |
6833a413 |
1977 | cl = NULL; |
8e90e4c6 |
1978 | inherit_handles = FALSE; |
1979 | } |
374330e2 |
1980 | |
32874aea |
1981 | GetModuleFileName(NULL, b, sizeof(b) - 1); |
374330e2 |
1982 | si.cb = sizeof(si); |
1983 | si.lpReserved = NULL; |
1984 | si.lpDesktop = NULL; |
1985 | si.lpTitle = NULL; |
1986 | si.dwFlags = 0; |
1987 | si.cbReserved2 = 0; |
1988 | si.lpReserved2 = NULL; |
8e90e4c6 |
1989 | CreateProcess(b, cl, NULL, NULL, inherit_handles, |
32874aea |
1990 | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); |
374330e2 |
1991 | |
1992 | if (filemap) |
1993 | CloseHandle(filemap); |
e4e4cc7e |
1994 | if (freecl) |
dcbde236 |
1995 | sfree(cl); |
374330e2 |
1996 | } |
1997 | break; |
e3be8de5 |
1998 | case IDM_RESTART: |
1999 | if (!back) { |
2000 | logevent(NULL, "----- Session restarted -----"); |
2001 | start_backend(); |
2002 | } |
2003 | |
2004 | break; |
32874aea |
2005 | case IDM_RECONF: |
2006 | { |
5a73255e |
2007 | Config prev_cfg; |
2008 | int init_lvl = 1; |
68a66cc3 |
2009 | int reconfig_result; |
5a73255e |
2010 | |
359fd192 |
2011 | if (reconfiguring) |
68a66cc3 |
2012 | break; |
359fd192 |
2013 | else |
68a66cc3 |
2014 | reconfiguring = TRUE; |
359fd192 |
2015 | |
32874aea |
2016 | GetWindowText(hwnd, cfg.wintitle, sizeof(cfg.wintitle)); |
5a73255e |
2017 | prev_cfg = cfg; |
e1c8e0ed |
2018 | |
68a66cc3 |
2019 | reconfig_result = |
b56ff5c3 |
2020 | do_reconfig(hwnd, back ? back->cfg_info(backhandle) : 0); |
68a66cc3 |
2021 | reconfiguring = FALSE; |
2022 | if (!reconfig_result) |
32874aea |
2023 | break; |
e1c8e0ed |
2024 | |
2cae8529 |
2025 | { |
2026 | /* Disable full-screen if resizing forbidden */ |
2027 | HMENU m = GetSystemMenu (hwnd, FALSE); |
2028 | EnableMenuItem(m, IDM_FULLSCREEN, MF_BYCOMMAND | |
2029 | (cfg.resize_action == RESIZE_DISABLED) |
2030 | ? MF_GRAYED : MF_ENABLED); |
2031 | /* Gracefully unzoom if necessary */ |
1ba99d2c |
2032 | if (IsZoomed(hwnd) && |
2cae8529 |
2033 | (cfg.resize_action == RESIZE_DISABLED)) { |
1ba99d2c |
2034 | ShowWindow(hwnd, SW_RESTORE); |
2cae8529 |
2035 | } |
a401e5f3 |
2036 | } |
2037 | |
c229ef97 |
2038 | /* Pass new config data to the logging module */ |
2039 | log_reconfig(logctx, &cfg); |
e1c8e0ed |
2040 | |
32874aea |
2041 | sfree(logpal); |
2042 | /* |
2043 | * Flush the line discipline's edit buffer in the |
2044 | * case where local editing has just been disabled. |
2045 | */ |
e3be8de5 |
2046 | if (ldisc) |
2047 | ldisc_send(ldisc, NULL, 0, 0); |
32874aea |
2048 | if (pal) |
2049 | DeleteObject(pal); |
2050 | logpal = NULL; |
2051 | pal = NULL; |
2052 | cfgtopalette(); |
2053 | init_palette(); |
2054 | |
64734920 |
2055 | /* Pass new config data to the terminal */ |
2056 | term_reconfig(term, &cfg); |
0d2086c5 |
2057 | |
86916870 |
2058 | /* Pass new config data to the back end */ |
e3be8de5 |
2059 | if (back) |
2060 | back->reconfig(backhandle, &cfg); |
86916870 |
2061 | |
5a73255e |
2062 | /* Screen size changed ? */ |
2063 | if (cfg.height != prev_cfg.height || |
2064 | cfg.width != prev_cfg.width || |
2065 | cfg.savelines != prev_cfg.savelines || |
0ed2f48e |
2066 | cfg.resize_action == RESIZE_FONT || |
811f10b3 |
2067 | (cfg.resize_action == RESIZE_EITHER && IsZoomed(hwnd)) || |
0ed2f48e |
2068 | cfg.resize_action == RESIZE_DISABLED) |
887035a5 |
2069 | term_size(term, cfg.height, cfg.width, cfg.savelines); |
5a73255e |
2070 | |
32874aea |
2071 | /* Enable or disable the scroll bar, etc */ |
2072 | { |
1e5eefb6 |
2073 | LONG nflg, flag = GetWindowLongPtr(hwnd, GWL_STYLE); |
32874aea |
2074 | LONG nexflag, exflag = |
1e5eefb6 |
2075 | GetWindowLongPtr(hwnd, GWL_EXSTYLE); |
32874aea |
2076 | |
2077 | nexflag = exflag; |
5a73255e |
2078 | if (cfg.alwaysontop != prev_cfg.alwaysontop) { |
32874aea |
2079 | if (cfg.alwaysontop) { |
2080 | nexflag |= WS_EX_TOPMOST; |
2081 | SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, |
2082 | SWP_NOMOVE | SWP_NOSIZE); |
2083 | } else { |
2084 | nexflag &= ~(WS_EX_TOPMOST); |
2085 | SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, |
2086 | SWP_NOMOVE | SWP_NOSIZE); |
2087 | } |
2088 | } |
2089 | if (cfg.sunken_edge) |
2090 | nexflag |= WS_EX_CLIENTEDGE; |
2091 | else |
2092 | nexflag &= ~(WS_EX_CLIENTEDGE); |
2093 | |
2094 | nflg = flag; |
1ba99d2c |
2095 | if (is_full_screen() ? |
2cae8529 |
2096 | cfg.scrollbar_in_fullscreen : cfg.scrollbar) |
32874aea |
2097 | nflg |= WS_VSCROLL; |
2098 | else |
2099 | nflg &= ~WS_VSCROLL; |
811f10b3 |
2100 | |
2101 | if (cfg.resize_action == RESIZE_DISABLED || |
2102 | is_full_screen()) |
2103 | nflg &= ~WS_THICKFRAME; |
2104 | else |
2105 | nflg |= WS_THICKFRAME; |
2106 | |
ad5c93cc |
2107 | if (cfg.resize_action == RESIZE_DISABLED) |
811f10b3 |
2108 | nflg &= ~WS_MAXIMIZEBOX; |
32874aea |
2109 | else |
811f10b3 |
2110 | nflg |= WS_MAXIMIZEBOX; |
32874aea |
2111 | |
2112 | if (nflg != flag || nexflag != exflag) { |
32874aea |
2113 | if (nflg != flag) |
1e5eefb6 |
2114 | SetWindowLongPtr(hwnd, GWL_STYLE, nflg); |
32874aea |
2115 | if (nexflag != exflag) |
1e5eefb6 |
2116 | SetWindowLongPtr(hwnd, GWL_EXSTYLE, nexflag); |
32874aea |
2117 | |
32874aea |
2118 | SetWindowPos(hwnd, NULL, 0, 0, 0, 0, |
2119 | SWP_NOACTIVATE | SWP_NOCOPYBITS | |
5a73255e |
2120 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | |
2121 | SWP_FRAMECHANGED); |
c9def1b8 |
2122 | |
5a73255e |
2123 | init_lvl = 2; |
e44d78b6 |
2124 | } |
32874aea |
2125 | } |
5a73255e |
2126 | |
e44d78b6 |
2127 | /* Oops */ |
ad5c93cc |
2128 | if (cfg.resize_action == RESIZE_DISABLED && IsZoomed(hwnd)) { |
e44d78b6 |
2129 | force_normal(hwnd); |
5a73255e |
2130 | init_lvl = 2; |
2131 | } |
2132 | |
a8327734 |
2133 | set_title(NULL, cfg.wintitle); |
32874aea |
2134 | if (IsIconic(hwnd)) { |
2135 | SetWindowText(hwnd, |
2136 | cfg.win_name_always ? window_name : |
2137 | icon_name); |
3da0b1d2 |
2138 | } |
5a73255e |
2139 | |
9a30e26b |
2140 | if (strcmp(cfg.font.name, prev_cfg.font.name) != 0 || |
5a73255e |
2141 | strcmp(cfg.line_codepage, prev_cfg.line_codepage) != 0 || |
9a30e26b |
2142 | cfg.font.isbold != prev_cfg.font.isbold || |
2143 | cfg.font.height != prev_cfg.font.height || |
2144 | cfg.font.charset != prev_cfg.font.charset || |
17c7fed1 |
2145 | cfg.font_quality != prev_cfg.font_quality || |
5a73255e |
2146 | cfg.vtmode != prev_cfg.vtmode || |
2147 | cfg.bold_colour != prev_cfg.bold_colour || |
0ed2f48e |
2148 | cfg.resize_action == RESIZE_DISABLED || |
2149 | cfg.resize_action == RESIZE_EITHER || |
2150 | (cfg.resize_action != prev_cfg.resize_action)) |
5a73255e |
2151 | init_lvl = 2; |
2152 | |
2153 | InvalidateRect(hwnd, NULL, TRUE); |
2154 | reset_window(init_lvl); |
7732d38a |
2155 | net_pending_errors(); |
32874aea |
2156 | } |
2157 | break; |
bc1235d4 |
2158 | case IDM_COPYALL: |
887035a5 |
2159 | term_copyall(term); |
bc1235d4 |
2160 | break; |
63be7767 |
2161 | case IDM_PASTE: |
2162 | term_do_paste(term); |
2163 | break; |
32874aea |
2164 | case IDM_CLRSB: |
887035a5 |
2165 | term_clrsb(term); |
32874aea |
2166 | break; |
2167 | case IDM_RESET: |
887035a5 |
2168 | term_pwron(term); |
e3be8de5 |
2169 | if (ldisc) |
2170 | ldisc_send(ldisc, NULL, 0, 0); |
32874aea |
2171 | break; |
374330e2 |
2172 | case IDM_ABOUT: |
32874aea |
2173 | showabout(hwnd); |
374330e2 |
2174 | break; |
70133c0e |
2175 | case IDM_HELP: |
2176 | WinHelp(hwnd, help_path, |
2177 | help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0); |
2178 | break; |
0d6dcf38 |
2179 | case SC_MOUSEMENU: |
2180 | /* |
2181 | * We get this if the System menu has been activated |
2182 | * using the mouse. |
2183 | */ |
2184 | show_mouseptr(1); |
2185 | break; |
dfca2656 |
2186 | case SC_KEYMENU: |
2187 | /* |
0d6dcf38 |
2188 | * We get this if the System menu has been activated |
2189 | * using the keyboard. This might happen from within |
2190 | * TranslateKey, in which case it really wants to be |
2191 | * followed by a `space' character to actually _bring |
2192 | * the menu up_ rather than just sitting there in |
2193 | * `ready to appear' state. |
dfca2656 |
2194 | */ |
0d6dcf38 |
2195 | show_mouseptr(1); /* make sure pointer is visible */ |
dfca2656 |
2196 | if( lParam == 0 ) |
2197 | PostMessage(hwnd, WM_CHAR, ' ', 0); |
2198 | break; |
a401e5f3 |
2199 | case IDM_FULLSCREEN: |
1ba99d2c |
2200 | flip_full_screen(); |
2201 | break; |
32874aea |
2202 | default: |
1f1e3232 |
2203 | if (wParam >= IDM_SAVED_MIN && wParam < IDM_SAVED_MAX) { |
32874aea |
2204 | SendMessage(hwnd, WM_SYSCOMMAND, IDM_SAVEDSESS, wParam); |
2205 | } |
125105d1 |
2206 | if (wParam >= IDM_SPECIAL_MIN && wParam <= IDM_SPECIAL_MAX) { |
2207 | int i = (wParam - IDM_SPECIAL_MIN) / 0x10; |
125105d1 |
2208 | /* |
2209 | * Ensure we haven't been sent a bogus SYSCOMMAND |
2210 | * which would cause us to reference invalid memory |
2211 | * and crash. Perhaps I'm just too paranoid here. |
2212 | */ |
6f2d0cde |
2213 | if (i >= n_specials) |
2214 | break; |
2215 | if (back) |
2216 | back->special(backhandle, specials[i].code); |
2217 | net_pending_errors(); |
125105d1 |
2218 | } |
374330e2 |
2219 | } |
2220 | break; |
37508af4 |
2221 | |
2222 | #define X_POS(l) ((int)(short)LOWORD(l)) |
2223 | #define Y_POS(l) ((int)(short)HIWORD(l)) |
2224 | |
5a73255e |
2225 | #define TO_CHR_X(x) ((((x)<0 ? (x)-font_width+1 : (x))-offset_width) / font_width) |
2226 | #define TO_CHR_Y(y) ((((y)<0 ? (y)-font_height+1: (y))-offset_height) / font_height) |
374330e2 |
2227 | case WM_LBUTTONDOWN: |
374330e2 |
2228 | case WM_MBUTTONDOWN: |
374330e2 |
2229 | case WM_RBUTTONDOWN: |
01c034ad |
2230 | case WM_LBUTTONUP: |
2231 | case WM_MBUTTONUP: |
374330e2 |
2232 | case WM_RBUTTONUP: |
ebc0310d |
2233 | if (message == WM_RBUTTONDOWN && |
2234 | ((wParam & MK_CONTROL) || (cfg.mouse_is_xterm == 2))) { |
63be7767 |
2235 | POINT cursorpos; |
2236 | |
ebc0310d |
2237 | show_mouseptr(1); /* make sure pointer is visible */ |
63be7767 |
2238 | GetCursorPos(&cursorpos); |
2239 | TrackPopupMenu(popup_menus[CTXMENU].menu, |
2240 | TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, |
2241 | cursorpos.x, cursorpos.y, |
2242 | 0, hwnd, NULL); |
2243 | break; |
2244 | } |
01c034ad |
2245 | { |
2246 | int button, press; |
6908fed7 |
2247 | |
01c034ad |
2248 | switch (message) { |
32874aea |
2249 | case WM_LBUTTONDOWN: |
2250 | button = MBT_LEFT; |
2251 | press = 1; |
2252 | break; |
2253 | case WM_MBUTTONDOWN: |
2254 | button = MBT_MIDDLE; |
2255 | press = 1; |
2256 | break; |
2257 | case WM_RBUTTONDOWN: |
2258 | button = MBT_RIGHT; |
2259 | press = 1; |
2260 | break; |
2261 | case WM_LBUTTONUP: |
2262 | button = MBT_LEFT; |
2263 | press = 0; |
2264 | break; |
2265 | case WM_MBUTTONUP: |
2266 | button = MBT_MIDDLE; |
2267 | press = 0; |
2268 | break; |
2269 | case WM_RBUTTONUP: |
2270 | button = MBT_RIGHT; |
2271 | press = 0; |
2272 | break; |
2d466ffd |
2273 | default: |
2274 | button = press = 0; /* shouldn't happen */ |
01c034ad |
2275 | } |
2276 | show_mouseptr(1); |
2cae8529 |
2277 | /* |
2278 | * Special case: in full-screen mode, if the left |
2279 | * button is clicked in the very top left corner of the |
2280 | * window, we put up the System menu instead of doing |
2281 | * selection. |
2282 | */ |
52a4d159 |
2283 | { |
2284 | char mouse_on_hotspot = 0; |
2285 | POINT pt; |
2286 | |
2287 | GetCursorPos(&pt); |
2288 | #ifndef NO_MULTIMON |
2289 | { |
2290 | HMONITOR mon; |
2291 | MONITORINFO mi; |
2292 | |
2293 | mon = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL); |
2294 | |
2295 | if (mon != NULL) { |
2296 | mi.cbSize = sizeof(MONITORINFO); |
2297 | GetMonitorInfo(mon, &mi); |
2298 | |
2299 | if (mi.rcMonitor.left == pt.x && |
2300 | mi.rcMonitor.top == pt.y) { |
2301 | mouse_on_hotspot = 1; |
2302 | } |
52a4d159 |
2303 | } |
2304 | } |
2305 | #else |
2306 | if (pt.x == 0 && pt.y == 0) { |
2307 | mouse_on_hotspot = 1; |
2308 | } |
2309 | #endif |
2310 | if (is_full_screen() && press && |
2311 | button == MBT_LEFT && mouse_on_hotspot) { |
2312 | SendMessage(hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, |
2313 | MAKELPARAM(pt.x, pt.y)); |
2314 | return 0; |
2315 | } |
2cae8529 |
2316 | } |
52a4d159 |
2317 | |
01c034ad |
2318 | if (press) { |
32874aea |
2319 | click(button, |
2320 | TO_CHR_X(X_POS(lParam)), TO_CHR_Y(Y_POS(lParam)), |
6908fed7 |
2321 | wParam & MK_SHIFT, wParam & MK_CONTROL, |
2322 | is_alt_pressed()); |
01c034ad |
2323 | SetCapture(hwnd); |
2324 | } else { |
fc5b0934 |
2325 | term_mouse(term, button, translate_button(button), MA_RELEASE, |
32874aea |
2326 | TO_CHR_X(X_POS(lParam)), |
2327 | TO_CHR_Y(Y_POS(lParam)), wParam & MK_SHIFT, |
6908fed7 |
2328 | wParam & MK_CONTROL, is_alt_pressed()); |
01c034ad |
2329 | ReleaseCapture(); |
2330 | } |
2331 | } |
374330e2 |
2332 | return 0; |
2333 | case WM_MOUSEMOVE: |
d8a13f62 |
2334 | { |
2335 | /* |
2336 | * Windows seems to like to occasionally send MOUSEMOVE |
2337 | * events even if the mouse hasn't moved. Don't unhide |
2338 | * the mouse pointer in this case. |
2339 | */ |
2340 | static WPARAM wp = 0; |
2341 | static LPARAM lp = 0; |
2342 | if (wParam != wp || lParam != lp || |
2343 | last_mousemove != WM_MOUSEMOVE) { |
2344 | show_mouseptr(1); |
2345 | wp = wParam; lp = lParam; |
2346 | last_mousemove = WM_MOUSEMOVE; |
2347 | } |
2348 | } |
374330e2 |
2349 | /* |
2350 | * Add the mouse position and message time to the random |
7d6ee6ff |
2351 | * number noise. |
374330e2 |
2352 | */ |
32874aea |
2353 | noise_ultralight(lParam); |
374330e2 |
2354 | |
319bfe5a |
2355 | if (wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON) && |
2356 | GetCapture() == hwnd) { |
374330e2 |
2357 | Mouse_Button b; |
2358 | if (wParam & MK_LBUTTON) |
6c6e7711 |
2359 | b = MBT_LEFT; |
374330e2 |
2360 | else if (wParam & MK_MBUTTON) |
6c6e7711 |
2361 | b = MBT_MIDDLE; |
374330e2 |
2362 | else |
6c6e7711 |
2363 | b = MBT_RIGHT; |
fc5b0934 |
2364 | term_mouse(term, b, translate_button(b), MA_DRAG, |
2365 | TO_CHR_X(X_POS(lParam)), |
32874aea |
2366 | TO_CHR_Y(Y_POS(lParam)), wParam & MK_SHIFT, |
6908fed7 |
2367 | wParam & MK_CONTROL, is_alt_pressed()); |
374330e2 |
2368 | } |
374330e2 |
2369 | return 0; |
d318ef8e |
2370 | case WM_NCMOUSEMOVE: |
d8a13f62 |
2371 | { |
2372 | static WPARAM wp = 0; |
2373 | static LPARAM lp = 0; |
2374 | if (wParam != wp || lParam != lp || |
2375 | last_mousemove != WM_NCMOUSEMOVE) { |
2376 | show_mouseptr(1); |
2377 | wp = wParam; lp = lParam; |
2378 | last_mousemove = WM_NCMOUSEMOVE; |
2379 | } |
2380 | } |
32874aea |
2381 | noise_ultralight(lParam); |
f9cbc48c |
2382 | break; |
374330e2 |
2383 | case WM_IGNORE_CLIP: |
2384 | ignore_clip = wParam; /* don't panic on DESTROYCLIPBOARD */ |
2385 | break; |
2386 | case WM_DESTROYCLIPBOARD: |
2387 | if (!ignore_clip) |
887035a5 |
2388 | term_deselect(term); |
374330e2 |
2389 | ignore_clip = FALSE; |
2390 | return 0; |
2391 | case WM_PAINT: |
2392 | { |
2393 | PAINTSTRUCT p; |
39934deb |
2394 | |
32874aea |
2395 | HideCaret(hwnd); |
2396 | hdc = BeginPaint(hwnd, &p); |
374330e2 |
2397 | if (pal) { |
32874aea |
2398 | SelectPalette(hdc, pal, TRUE); |
2399 | RealizePalette(hdc); |
374330e2 |
2400 | } |
39934deb |
2401 | |
8788a416 |
2402 | /* |
2403 | * We have to be careful about term_paint(). It will |
2404 | * set a bunch of character cells to INVALID and then |
2405 | * call do_paint(), which will redraw those cells and |
2406 | * _then mark them as done_. This may not be accurate: |
2407 | * when painting in WM_PAINT context we are restricted |
2408 | * to the rectangle which has just been exposed - so if |
2409 | * that only covers _part_ of a character cell and the |
2410 | * rest of it was already visible, that remainder will |
2411 | * not be redrawn at all. Accordingly, we must not |
2412 | * paint any character cell in a WM_PAINT context which |
2413 | * already has a pending update due to terminal output. |
2414 | * The simplest solution to this - and many, many |
2415 | * thanks to Hung-Te Lin for working all this out - is |
2416 | * not to do any actual painting at _all_ if there's a |
2417 | * pending terminal update: just mark the relevant |
2418 | * character cells as INVALID and wait for the |
2419 | * scheduled full update to sort it out. |
2420 | * |
2421 | * I have a suspicion this isn't the _right_ solution. |
2422 | * An alternative approach would be to have terminal.c |
2423 | * separately track what _should_ be on the terminal |
2424 | * screen and what _is_ on the terminal screen, and |
2425 | * have two completely different types of redraw (one |
2426 | * for full updates, which syncs the former with the |
2427 | * terminal itself, and one for WM_PAINT which syncs |
2428 | * the latter with the former); yet another possibility |
2429 | * would be to have the Windows front end do what the |
2430 | * GTK one already does, and maintain a bitmap of the |
2431 | * current terminal appearance so that WM_PAINT becomes |
2432 | * completely trivial. However, this should do for now. |
2433 | */ |
887035a5 |
2434 | term_paint(term, hdc, |
5a73255e |
2435 | (p.rcPaint.left-offset_width)/font_width, |
2436 | (p.rcPaint.top-offset_height)/font_height, |
2437 | (p.rcPaint.right-offset_width-1)/font_width, |
c1b55581 |
2438 | (p.rcPaint.bottom-offset_height-1)/font_height, |
8788a416 |
2439 | !term->window_update_pending); |
5a73255e |
2440 | |
2441 | if (p.fErase || |
2442 | p.rcPaint.left < offset_width || |
2443 | p.rcPaint.top < offset_height || |
887035a5 |
2444 | p.rcPaint.right >= offset_width + font_width*term->cols || |
2445 | p.rcPaint.bottom>= offset_height + font_height*term->rows) |
5a73255e |
2446 | { |
2447 | HBRUSH fillcolour, oldbrush; |
2448 | HPEN edge, oldpen; |
2449 | fillcolour = CreateSolidBrush ( |
c50f9fde |
2450 | colours[ATTR_DEFBG>>ATTR_BGSHIFT]); |
5a73255e |
2451 | oldbrush = SelectObject(hdc, fillcolour); |
2452 | edge = CreatePen(PS_SOLID, 0, |
c50f9fde |
2453 | colours[ATTR_DEFBG>>ATTR_BGSHIFT]); |
5a73255e |
2454 | oldpen = SelectObject(hdc, edge); |
2455 | |
bfa7a5db |
2456 | /* |
2457 | * Jordan Russell reports that this apparently |
2458 | * ineffectual IntersectClipRect() call masks a |
2459 | * Windows NT/2K bug causing strange display |
2460 | * problems when the PuTTY window is taller than |
2461 | * the primary monitor. It seems harmless enough... |
2462 | */ |
2463 | IntersectClipRect(hdc, |
2464 | p.rcPaint.left, p.rcPaint.top, |
2465 | p.rcPaint.right, p.rcPaint.bottom); |
2466 | |
5a73255e |
2467 | ExcludeClipRect(hdc, |
2468 | offset_width, offset_height, |
887035a5 |
2469 | offset_width+font_width*term->cols, |
2470 | offset_height+font_height*term->rows); |
5a73255e |
2471 | |
2472 | Rectangle(hdc, p.rcPaint.left, p.rcPaint.top, |
2473 | p.rcPaint.right, p.rcPaint.bottom); |
2474 | |
31fb1866 |
2475 | /* SelectClipRgn(hdc, NULL); */ |
5a73255e |
2476 | |
2477 | SelectObject(hdc, oldbrush); |
2478 | DeleteObject(fillcolour); |
2479 | SelectObject(hdc, oldpen); |
2480 | DeleteObject(edge); |
2481 | } |
32874aea |
2482 | SelectObject(hdc, GetStockObject(SYSTEM_FONT)); |
2483 | SelectObject(hdc, GetStockObject(WHITE_PEN)); |
2484 | EndPaint(hwnd, &p); |
2485 | ShowCaret(hwnd); |
374330e2 |
2486 | } |
2487 | return 0; |
2488 | case WM_NETEVENT: |
39934deb |
2489 | enact_netevent(wParam, lParam); |
2490 | net_pending_errors(); |
374330e2 |
2491 | return 0; |
2492 | case WM_SETFOCUS: |
1cff1320 |
2493 | term_set_focus(term, TRUE); |
32874aea |
2494 | CreateCaret(hwnd, caretbm, font_width, font_height); |
2495 | ShowCaret(hwnd); |
f8a28d1f |
2496 | flash_window(0); /* stop */ |
32874aea |
2497 | compose_state = 0; |
887035a5 |
2498 | term_update(term); |
374330e2 |
2499 | break; |
2500 | case WM_KILLFOCUS: |
32874aea |
2501 | show_mouseptr(1); |
1cff1320 |
2502 | term_set_focus(term, FALSE); |
32874aea |
2503 | DestroyCaret(); |
c1da5066 |
2504 | caret_x = caret_y = -1; /* ensure caret is replaced next time */ |
887035a5 |
2505 | term_update(term); |
374330e2 |
2506 | break; |
73251d5d |
2507 | case WM_ENTERSIZEMOVE: |
5a73255e |
2508 | #ifdef RDB_DEBUG_PATCH |
2509 | debug((27, "WM_ENTERSIZEMOVE")); |
2510 | #endif |
32874aea |
2511 | EnableSizeTip(1); |
2512 | resizing = TRUE; |
3ad8c6db |
2513 | need_backend_resize = FALSE; |
32874aea |
2514 | break; |
73251d5d |
2515 | case WM_EXITSIZEMOVE: |
32874aea |
2516 | EnableSizeTip(0); |
2517 | resizing = FALSE; |
5a73255e |
2518 | #ifdef RDB_DEBUG_PATCH |
2519 | debug((27, "WM_EXITSIZEMOVE")); |
2520 | #endif |
2521 | if (need_backend_resize) { |
887035a5 |
2522 | term_size(term, cfg.height, cfg.width, cfg.savelines); |
5a73255e |
2523 | InvalidateRect(hwnd, NULL, TRUE); |
2524 | } |
32874aea |
2525 | break; |
374330e2 |
2526 | case WM_SIZING: |
5a73255e |
2527 | /* |
2528 | * This does two jobs: |
2529 | * 1) Keep the sizetip uptodate |
2530 | * 2) Make sure the window size is _stepped_ in units of the font size. |
2531 | */ |
c1b55581 |
2532 | if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) { |
374330e2 |
2533 | int width, height, w, h, ew, eh; |
32874aea |
2534 | LPRECT r = (LPRECT) lParam; |
374330e2 |
2535 | |
0ed2f48e |
2536 | if ( !need_backend_resize && cfg.resize_action == RESIZE_EITHER && |
887035a5 |
2537 | (cfg.height != term->rows || cfg.width != term->cols )) { |
5a73255e |
2538 | /* |
0ed2f48e |
2539 | * Great! It seems that both the terminal size and the |
2540 | * font size have been changed and the user is now dragging. |
2541 | * |
2542 | * It will now be difficult to get back to the configured |
2543 | * font size! |
2544 | * |
2545 | * This would be easier but it seems to be too confusing. |
2546 | |
887035a5 |
2547 | term_size(term, cfg.height, cfg.width, cfg.savelines); |
5a73255e |
2548 | reset_window(2); |
0ed2f48e |
2549 | */ |
887035a5 |
2550 | cfg.height=term->rows; cfg.width=term->cols; |
0ed2f48e |
2551 | |
5a73255e |
2552 | InvalidateRect(hwnd, NULL, TRUE); |
2553 | need_backend_resize = TRUE; |
2554 | } |
2555 | |
374330e2 |
2556 | width = r->right - r->left - extra_width; |
2557 | height = r->bottom - r->top - extra_height; |
32874aea |
2558 | w = (width + font_width / 2) / font_width; |
2559 | if (w < 1) |
2560 | w = 1; |
2561 | h = (height + font_height / 2) / font_height; |
2562 | if (h < 1) |
2563 | h = 1; |
2564 | UpdateSizeTip(hwnd, w, h); |
374330e2 |
2565 | ew = width - w * font_width; |
2566 | eh = height - h * font_height; |
2567 | if (ew != 0) { |
2568 | if (wParam == WMSZ_LEFT || |
32874aea |
2569 | wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_TOPLEFT) |
374330e2 |
2570 | r->left += ew; |
2571 | else |
2572 | r->right -= ew; |
2573 | } |
2574 | if (eh != 0) { |
2575 | if (wParam == WMSZ_TOP || |
32874aea |
2576 | wParam == WMSZ_TOPRIGHT || wParam == WMSZ_TOPLEFT) |
374330e2 |
2577 | r->top += eh; |
2578 | else |
2579 | r->bottom -= eh; |
2580 | } |
2581 | if (ew || eh) |
2582 | return 1; |
2583 | else |
2584 | return 0; |
5a73255e |
2585 | } else { |
2586 | int width, height, w, h, rv = 0; |
2587 | int ex_width = extra_width + (cfg.window_border - offset_width) * 2; |
2588 | int ex_height = extra_height + (cfg.window_border - offset_height) * 2; |
2589 | LPRECT r = (LPRECT) lParam; |
2590 | |
2591 | width = r->right - r->left - ex_width; |
2592 | height = r->bottom - r->top - ex_height; |
2593 | |
887035a5 |
2594 | w = (width + term->cols/2)/term->cols; |
2595 | h = (height + term->rows/2)/term->rows; |
2596 | if ( r->right != r->left + w*term->cols + ex_width) |
5a73255e |
2597 | rv = 1; |
2598 | |
2599 | if (wParam == WMSZ_LEFT || |
2600 | wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_TOPLEFT) |
887035a5 |
2601 | r->left = r->right - w*term->cols - ex_width; |
5a73255e |
2602 | else |
887035a5 |
2603 | r->right = r->left + w*term->cols + ex_width; |
5a73255e |
2604 | |
887035a5 |
2605 | if (r->bottom != r->top + h*term->rows + ex_height) |
5a73255e |
2606 | rv = 1; |
2607 | |
2608 | if (wParam == WMSZ_TOP || |
2609 | wParam == WMSZ_TOPRIGHT || wParam == WMSZ_TOPLEFT) |
887035a5 |
2610 | r->top = r->bottom - h*term->rows - ex_height; |
5a73255e |
2611 | else |
887035a5 |
2612 | r->bottom = r->top + h*term->rows + ex_height; |
5a73255e |
2613 | |
2614 | return rv; |
374330e2 |
2615 | } |
32874aea |
2616 | /* break; (never reached) */ |
1ba99d2c |
2617 | case WM_FULLSCR_ON_MAX: |
2618 | fullscr_on_max = TRUE; |
2619 | break; |
c1da5066 |
2620 | case WM_MOVE: |
2621 | sys_cursor_update(); |
2622 | break; |
374330e2 |
2623 | case WM_SIZE: |
5a73255e |
2624 | #ifdef RDB_DEBUG_PATCH |
2625 | debug((27, "WM_SIZE %s (%d,%d)", |
2626 | (wParam == SIZE_MINIMIZED) ? "SIZE_MINIMIZED": |
2627 | (wParam == SIZE_MAXIMIZED) ? "SIZE_MAXIMIZED": |
2628 | (wParam == SIZE_RESTORED && resizing) ? "to": |
2629 | (wParam == SIZE_RESTORED) ? "SIZE_RESTORED": |
2630 | "...", |
2631 | LOWORD(lParam), HIWORD(lParam))); |
2632 | #endif |
0ed2f48e |
2633 | if (wParam == SIZE_MINIMIZED) |
32874aea |
2634 | SetWindowText(hwnd, |
2635 | cfg.win_name_always ? window_name : icon_name); |
374330e2 |
2636 | if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) |
32874aea |
2637 | SetWindowText(hwnd, window_name); |
811f10b3 |
2638 | if (wParam == SIZE_RESTORED) |
2639 | clear_full_screen(); |
2640 | if (wParam == SIZE_MAXIMIZED && fullscr_on_max) { |
811f10b3 |
2641 | fullscr_on_max = FALSE; |
d0f1bcb4 |
2642 | make_full_screen(); |
811f10b3 |
2643 | } |
5a73255e |
2644 | |
ad5c93cc |
2645 | if (cfg.resize_action == RESIZE_DISABLED) { |
5a73255e |
2646 | /* A resize, well it better be a minimize. */ |
2647 | reset_window(-1); |
2648 | } else { |
2649 | |
1a6f78fe |
2650 | int width, height, w, h; |
374330e2 |
2651 | |
2652 | width = LOWORD(lParam); |
2653 | height = HIWORD(lParam); |
5a73255e |
2654 | |
2655 | if (!resizing) { |
0ed2f48e |
2656 | if (wParam == SIZE_MAXIMIZED && !was_zoomed) { |
5a73255e |
2657 | was_zoomed = 1; |
887035a5 |
2658 | prev_rows = term->rows; |
2659 | prev_cols = term->cols; |
0ed2f48e |
2660 | if (cfg.resize_action == RESIZE_TERM) { |
5a73255e |
2661 | w = width / font_width; |
2662 | if (w < 1) w = 1; |
2663 | h = height / font_height; |
2664 | if (h < 1) h = 1; |
2665 | |
887035a5 |
2666 | term_size(term, h, w, cfg.savelines); |
5a73255e |
2667 | } |
2668 | reset_window(0); |
2669 | } else if (wParam == SIZE_RESTORED && was_zoomed) { |
2670 | was_zoomed = 0; |
0ed2f48e |
2671 | if (cfg.resize_action == RESIZE_TERM) |
887035a5 |
2672 | term_size(term, prev_rows, prev_cols, cfg.savelines); |
0ed2f48e |
2673 | if (cfg.resize_action != RESIZE_FONT) |
2674 | reset_window(2); |
2675 | else |
2676 | reset_window(0); |
5a73255e |
2677 | } |
2678 | /* This is an unexpected resize, these will normally happen |
2679 | * if the window is too large. Probably either the user |
2680 | * selected a huge font or the screen size has changed. |
2681 | * |
2682 | * This is also called with minimize. |
32874aea |
2683 | */ |
5a73255e |
2684 | else reset_window(-1); |
2685 | } |
2686 | |
2687 | /* |
2688 | * Don't call back->size in mid-resize. (To prevent |
2689 | * massive numbers of resize events getting sent |
2690 | * down the connection during an NT opaque drag.) |
2691 | */ |
2692 | if (resizing) { |
c1b55581 |
2693 | if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) { |
3ad8c6db |
2694 | need_backend_resize = TRUE; |
5a73255e |
2695 | w = (width-cfg.window_border*2) / font_width; |
2696 | if (w < 1) w = 1; |
2697 | h = (height-cfg.window_border*2) / font_height; |
2698 | if (h < 1) h = 1; |
2699 | |
e44d78b6 |
2700 | cfg.height = h; |
2701 | cfg.width = w; |
5a73255e |
2702 | } else |
2703 | reset_window(0); |
374330e2 |
2704 | } |
2705 | } |
c1da5066 |
2706 | sys_cursor_update(); |
374330e2 |
2707 | return 0; |
2708 | case WM_VSCROLL: |
2709 | switch (LOWORD(wParam)) { |
32874aea |
2710 | case SB_BOTTOM: |
887035a5 |
2711 | term_scroll(term, -1, 0); |
32874aea |
2712 | break; |
2713 | case SB_TOP: |
887035a5 |
2714 | term_scroll(term, +1, 0); |
32874aea |
2715 | break; |
2716 | case SB_LINEDOWN: |
887035a5 |
2717 | term_scroll(term, 0, +1); |
32874aea |
2718 | break; |
2719 | case SB_LINEUP: |
887035a5 |
2720 | term_scroll(term, 0, -1); |
32874aea |
2721 | break; |
2722 | case SB_PAGEDOWN: |
887035a5 |
2723 | term_scroll(term, 0, +term->rows / 2); |
32874aea |
2724 | break; |
2725 | case SB_PAGEUP: |
887035a5 |
2726 | term_scroll(term, 0, -term->rows / 2); |
32874aea |
2727 | break; |
2728 | case SB_THUMBPOSITION: |
2729 | case SB_THUMBTRACK: |
887035a5 |
2730 | term_scroll(term, 1, HIWORD(wParam)); |
32874aea |
2731 | break; |
2732 | } |
2733 | break; |
2734 | case WM_PALETTECHANGED: |
374330e2 |
2735 | if ((HWND) wParam != hwnd && pal != NULL) { |
a8327734 |
2736 | HDC hdc = get_ctx(NULL); |
374330e2 |
2737 | if (hdc) { |
32874aea |
2738 | if (RealizePalette(hdc) > 0) |
2739 | UpdateColors(hdc); |
2740 | free_ctx(hdc); |
374330e2 |
2741 | } |
2742 | } |
2743 | break; |
2744 | case WM_QUERYNEWPALETTE: |
2745 | if (pal != NULL) { |
a8327734 |
2746 | HDC hdc = get_ctx(NULL); |
374330e2 |
2747 | if (hdc) { |
32874aea |
2748 | if (RealizePalette(hdc) > 0) |
2749 | UpdateColors(hdc); |
2750 | free_ctx(hdc); |
374330e2 |
2751 | return TRUE; |
2752 | } |
2753 | } |
2754 | return FALSE; |
2755 | case WM_KEYDOWN: |
2756 | case WM_SYSKEYDOWN: |
c9def1b8 |
2757 | case WM_KEYUP: |
2758 | case WM_SYSKEYUP: |
374330e2 |
2759 | /* |
2760 | * Add the scan code and keypress timing to the random |
7d6ee6ff |
2761 | * number noise. |
374330e2 |
2762 | */ |
32874aea |
2763 | noise_ultralight(lParam); |
374330e2 |
2764 | |
2765 | /* |
2766 | * We don't do TranslateMessage since it disassociates the |
2767 | * resulting CHAR message from the KEYDOWN that sparked it, |
2768 | * which we occasionally don't want. Instead, we process |
2769 | * KEYDOWN, and call the Win32 translator functions so that |
2770 | * we get the translations under _our_ control. |
2771 | */ |
2772 | { |
2773 | unsigned char buf[20]; |
2774 | int len; |
2775 | |
43e95114 |
2776 | if (wParam == VK_PROCESSKEY) { /* IME PROCESS key */ |
2777 | if (message == WM_KEYDOWN) { |
2778 | MSG m; |
2779 | m.hwnd = hwnd; |
2780 | m.message = WM_KEYDOWN; |
2781 | m.wParam = wParam; |
2782 | m.lParam = lParam & 0xdfff; |
2783 | TranslateMessage(&m); |
2784 | } else break; /* pass to Windows for default processing */ |
32874aea |
2785 | } else { |
2786 | len = TranslateKey(message, wParam, lParam, buf); |
3cf144db |
2787 | if (len == -1) |
32874aea |
2788 | return DefWindowProc(hwnd, message, wParam, lParam); |
5471d09a |
2789 | |
b2a1eade |
2790 | if (len != 0) { |
bca9517a |
2791 | /* |
256cb87c |
2792 | * Interrupt an ongoing paste. I'm not sure |
2793 | * this is sensible, but for the moment it's |
2794 | * preferable to having to faff about buffering |
2795 | * things. |
2796 | */ |
887035a5 |
2797 | term_nopaste(term); |
256cb87c |
2798 | |
2799 | /* |
bca9517a |
2800 | * We need not bother about stdin backlogs |
2801 | * here, because in GUI PuTTY we can't do |
2802 | * anything about it anyway; there's no means |
2803 | * of asking Windows to hold off on KEYDOWN |
2804 | * messages. We _have_ to buffer everything |
2805 | * we're sent. |
2806 | */ |
887035a5 |
2807 | term_seen_key_event(term); |
e3be8de5 |
2808 | if (ldisc) |
2809 | ldisc_send(ldisc, buf, len, 1); |
32874aea |
2810 | show_mouseptr(0); |
bca9517a |
2811 | } |
3cf144db |
2812 | } |
374330e2 |
2813 | } |
7732d38a |
2814 | net_pending_errors(); |
374330e2 |
2815 | return 0; |
4eeb7d09 |
2816 | case WM_INPUTLANGCHANGE: |
a5ce2e9f |
2817 | /* wParam == Font number */ |
2818 | /* lParam == Locale */ |
2819 | set_input_locale((HKL)lParam); |
c1da5066 |
2820 | sys_cursor_update(); |
4eeb7d09 |
2821 | break; |
fd64bb27 |
2822 | case WM_IME_STARTCOMPOSITION: |
2823 | { |
71f6951d |
2824 | HIMC hImc = ImmGetContext(hwnd); |
2825 | ImmSetCompositionFont(hImc, &lfont); |
2826 | ImmReleaseContext(hwnd, hImc); |
71f6951d |
2827 | } |
2828 | break; |
88485e4d |
2829 | case WM_IME_COMPOSITION: |
2830 | { |
2831 | HIMC hIMC; |
2832 | int n; |
2833 | char *buff; |
a3cfd0c8 |
2834 | |
88485e4d |
2835 | if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS || |
2836 | osVersion.dwPlatformId == VER_PLATFORM_WIN32s) break; /* no Unicode */ |
2837 | |
2838 | if ((lParam & GCS_RESULTSTR) == 0) /* Composition unfinished. */ |
2839 | break; /* fall back to DefWindowProc */ |
2840 | |
2841 | hIMC = ImmGetContext(hwnd); |
2842 | n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0); |
2843 | |
2844 | if (n > 0) { |
a3cfd0c8 |
2845 | int i; |
3d88e64d |
2846 | buff = snewn(n, char); |
88485e4d |
2847 | ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n); |
a3cfd0c8 |
2848 | /* |
2849 | * Jaeyoun Chung reports that Korean character |
2850 | * input doesn't work correctly if we do a single |
2851 | * luni_send() covering the whole of buff. So |
2852 | * instead we luni_send the characters one by one. |
2853 | */ |
887035a5 |
2854 | term_seen_key_event(term); |
2cb50250 |
2855 | for (i = 0; i < n; i += 2) { |
e3be8de5 |
2856 | if (ldisc) |
2857 | luni_send(ldisc, (unsigned short *)(buff+i), 1, 1); |
2cb50250 |
2858 | } |
88485e4d |
2859 | free(buff); |
2860 | } |
2861 | ImmReleaseContext(hwnd, hIMC); |
2862 | return 1; |
2863 | } |
2864 | |
4eeb7d09 |
2865 | case WM_IME_CHAR: |
2866 | if (wParam & 0xFF00) { |
3cf144db |
2867 | unsigned char buf[2]; |
2868 | |
2869 | buf[1] = wParam; |
2870 | buf[0] = wParam >> 8; |
887035a5 |
2871 | term_seen_key_event(term); |
e3be8de5 |
2872 | if (ldisc) |
2873 | lpage_send(ldisc, kbd_codepage, buf, 2, 1); |
4eeb7d09 |
2874 | } else { |
2875 | char c = (unsigned char) wParam; |
887035a5 |
2876 | term_seen_key_event(term); |
e3be8de5 |
2877 | if (ldisc) |
2878 | lpage_send(ldisc, kbd_codepage, &c, 1, 1); |
3cf144db |
2879 | } |
4eeb7d09 |
2880 | return (0); |
374330e2 |
2881 | case WM_CHAR: |
2882 | case WM_SYSCHAR: |
2883 | /* |
2884 | * Nevertheless, we are prepared to deal with WM_CHAR |
2885 | * messages, should they crop up. So if someone wants to |
2886 | * post the things to us as part of a macro manoeuvre, |
2887 | * we're ready to cope. |
2888 | */ |
32874aea |
2889 | { |
4eeb7d09 |
2890 | char c = (unsigned char)wParam; |
887035a5 |
2891 | term_seen_key_event(term); |
e3be8de5 |
2892 | if (ldisc) |
2893 | lpage_send(ldisc, CP_ACP, &c, 1, 1); |
374330e2 |
2894 | } |
2895 | return 0; |
49a332ff |
2896 | case WM_SYSCOLORCHANGE: |
2897 | if (cfg.system_colour) { |
2898 | /* Refresh palette from system colours. */ |
2899 | /* XXX actually this zaps the entire palette. */ |
2900 | systopalette(); |
2901 | init_palette(); |
2902 | /* Force a repaint of the terminal window. */ |
2903 | term_invalidate(term); |
2904 | } |
2905 | break; |
c44bf5bd |
2906 | case WM_AGENT_CALLBACK: |
2907 | { |
2908 | struct agent_callback *c = (struct agent_callback *)lParam; |
2909 | c->callback(c->callback_ctx, c->data, c->len); |
2910 | sfree(c); |
2911 | } |
2912 | return 0; |
011b0e33 |
2913 | default: |
16837214 |
2914 | if (message == wm_mousewheel || message == WM_MOUSEWHEEL) { |
c1b55581 |
2915 | int shift_pressed=0, control_pressed=0; |
011b0e33 |
2916 | |
2917 | if (message == WM_MOUSEWHEEL) { |
2918 | wheel_accumulator += (short)HIWORD(wParam); |
2919 | shift_pressed=LOWORD(wParam) & MK_SHIFT; |
2920 | control_pressed=LOWORD(wParam) & MK_CONTROL; |
2921 | } else { |
2922 | BYTE keys[256]; |
2923 | wheel_accumulator += (int)wParam; |
2924 | if (GetKeyboardState(keys)!=0) { |
2925 | shift_pressed=keys[VK_SHIFT]&0x80; |
2926 | control_pressed=keys[VK_CONTROL]&0x80; |
2927 | } |
2928 | } |
2929 | |
2930 | /* process events when the threshold is reached */ |
2931 | while (abs(wheel_accumulator) >= WHEEL_DELTA) { |
2932 | int b; |
2933 | |
2934 | /* reduce amount for next time */ |
2935 | if (wheel_accumulator > 0) { |
2936 | b = MBT_WHEEL_UP; |
2937 | wheel_accumulator -= WHEEL_DELTA; |
2938 | } else if (wheel_accumulator < 0) { |
2939 | b = MBT_WHEEL_DOWN; |
2940 | wheel_accumulator += WHEEL_DELTA; |
2941 | } else |
2942 | break; |
2943 | |
2944 | if (send_raw_mouse && |
2945 | !(cfg.mouse_override && shift_pressed)) { |
2946 | /* send a mouse-down followed by a mouse up */ |
fc5b0934 |
2947 | term_mouse(term, b, translate_button(b), |
011b0e33 |
2948 | MA_CLICK, |
2949 | TO_CHR_X(X_POS(lParam)), |
2950 | TO_CHR_Y(Y_POS(lParam)), shift_pressed, |
2951 | control_pressed, is_alt_pressed()); |
fc5b0934 |
2952 | term_mouse(term, b, translate_button(b), |
2953 | MA_RELEASE, TO_CHR_X(X_POS(lParam)), |
011b0e33 |
2954 | TO_CHR_Y(Y_POS(lParam)), shift_pressed, |
2955 | control_pressed, is_alt_pressed()); |
2956 | } else { |
2957 | /* trigger a scroll */ |
887035a5 |
2958 | term_scroll(term, 0, |
2959 | b == MBT_WHEEL_UP ? |
2960 | -term->rows / 2 : term->rows / 2); |
011b0e33 |
2961 | } |
2962 | } |
2963 | return 0; |
2964 | } |
374330e2 |
2965 | } |
2966 | |
5c4dea05 |
2967 | /* |
2968 | * Any messages we don't process completely above are passed through to |
2969 | * DefWindowProc() for default processing. |
2970 | */ |
32874aea |
2971 | return DefWindowProc(hwnd, message, wParam, lParam); |
374330e2 |
2972 | } |
2973 | |
2974 | /* |
ec8679e9 |
2975 | * Move the system caret. (We maintain one, even though it's |
2976 | * invisible, for the benefit of blind people: apparently some |
2977 | * helper software tracks the system caret, so we should arrange to |
2978 | * have one.) |
2979 | */ |
a8327734 |
2980 | void sys_cursor(void *frontend, int x, int y) |
32874aea |
2981 | { |
c1da5066 |
2982 | int cx, cy; |
2983 | |
887035a5 |
2984 | if (!term->has_focus) return; |
c1da5066 |
2985 | |
2986 | /* |
2987 | * Avoid gratuitously re-updating the cursor position and IMM |
2988 | * window if there's no actual change required. |
2989 | */ |
2990 | cx = x * font_width + offset_width; |
2991 | cy = y * font_height + offset_height; |
2992 | if (cx == caret_x && cy == caret_y) |
2993 | return; |
2994 | caret_x = cx; |
2995 | caret_y = cy; |
2996 | |
2997 | sys_cursor_update(); |
2998 | } |
2999 | |
3000 | static void sys_cursor_update(void) |
3001 | { |
88485e4d |
3002 | COMPOSITIONFORM cf; |
3003 | HIMC hIMC; |
3004 | |
887035a5 |
3005 | if (!term->has_focus) return; |
c1da5066 |
3006 | |
3007 | if (caret_x < 0 || caret_y < 0) |
3008 | return; |
3009 | |
3010 | SetCaretPos(caret_x, caret_y); |
88485e4d |
3011 | |
3012 | /* IMM calls on Win98 and beyond only */ |
3013 | if(osVersion.dwPlatformId == VER_PLATFORM_WIN32s) return; /* 3.11 */ |
3014 | |
3015 | if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && |
3016 | osVersion.dwMinorVersion == 0) return; /* 95 */ |
3017 | |
3018 | /* we should have the IMM functions */ |
3019 | hIMC = ImmGetContext(hwnd); |
3020 | cf.dwStyle = CFS_POINT; |
c1da5066 |
3021 | cf.ptCurrentPos.x = caret_x; |
3022 | cf.ptCurrentPos.y = caret_y; |
88485e4d |
3023 | ImmSetCompositionWindow(hIMC, &cf); |
3024 | |
3025 | ImmReleaseContext(hwnd, hIMC); |
ec8679e9 |
3026 | } |
3027 | |
3028 | /* |
374330e2 |
3029 | * Draw a line of text in the window, at given character |
3030 | * coordinates, in given attributes. |
3031 | * |
3032 | * We are allowed to fiddle with the contents of `text'. |
3033 | */ |
c6958dfe |
3034 | void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len, |
3035 | unsigned long attr, int lattr) |
32874aea |
3036 | { |
374330e2 |
3037 | COLORREF fg, bg, t; |
3038 | int nfg, nbg, nfont; |
3039 | HDC hdc = ctx; |
59ad2c03 |
3040 | RECT line_box; |
3041 | int force_manual_underline = 0; |
36566009 |
3042 | int fnt_width, char_width; |
4eeb7d09 |
3043 | int text_adjust = 0; |
3044 | static int *IpDx = 0, IpDxLEN = 0; |
3045 | |
36566009 |
3046 | lattr &= LATTR_MODE; |
3047 | |
3048 | char_width = fnt_width = font_width * (1 + (lattr != LATTR_NORM)); |
3049 | |
4eeb7d09 |
3050 | if (attr & ATTR_WIDE) |
3051 | char_width *= 2; |
59ad2c03 |
3052 | |
4eeb7d09 |
3053 | if (len > IpDxLEN || IpDx[0] != char_width) { |
59ad2c03 |
3054 | int i; |
32874aea |
3055 | if (len > IpDxLEN) { |
59ad2c03 |
3056 | sfree(IpDx); |
3d88e64d |
3057 | IpDx = snewn(len + 16, int); |
32874aea |
3058 | IpDxLEN = (len + 16); |
59ad2c03 |
3059 | } |
32874aea |
3060 | for (i = 0; i < IpDxLEN; i++) |
4eeb7d09 |
3061 | IpDx[i] = char_width; |
59ad2c03 |
3062 | } |
374330e2 |
3063 | |
5a73255e |
3064 | /* Only want the left half of double width lines */ |
887035a5 |
3065 | if (lattr != LATTR_NORM && x*2 >= term->cols) |
5a73255e |
3066 | return; |
3067 | |
c9def1b8 |
3068 | x *= fnt_width; |
374330e2 |
3069 | y *= font_height; |
5a73255e |
3070 | x += offset_width; |
3071 | y += offset_height; |
374330e2 |
3072 | |
887035a5 |
3073 | if ((attr & TATTR_ACTCURS) && (cfg.cursor_type == 0 || term->big_cursor)) { |
cecb13f6 |
3074 | attr &= ~(ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS); |
3075 | if (bold_mode == BOLD_COLOURS) |
3076 | attr &= ~ATTR_BOLD; |
3077 | |
3078 | /* cursor fg and bg */ |
3079 | attr |= (260 << ATTR_FGSHIFT) | (261 << ATTR_BGSHIFT); |
374330e2 |
3080 | } |
3081 | |
3082 | nfont = 0; |
4eeb7d09 |
3083 | if (cfg.vtmode == VT_POORMAN && lattr != LATTR_NORM) { |
3084 | /* Assume a poorman font is borken in other ways too. */ |
3085 | lattr = LATTR_WIDE; |
3086 | } else |
3087 | switch (lattr) { |
3088 | case LATTR_NORM: |
3089 | break; |
3090 | case LATTR_WIDE: |
3091 | nfont |= FONT_WIDE; |
374330e2 |
3092 | break; |
4eeb7d09 |
3093 | default: |
3094 | nfont |= FONT_WIDE + FONT_HIGH; |
3095 | break; |
3096 | } |
5a73255e |
3097 | if (attr & ATTR_NARROW) |
3098 | nfont |= FONT_NARROW; |
4eeb7d09 |
3099 | |
3100 | /* Special hack for the VT100 linedraw glyphs. */ |
36566009 |
3101 | if (text[0] >= 0x23BA && text[0] <= 0x23BD) { |
3102 | switch ((unsigned char) (text[0])) { |
3103 | case 0xBA: |
3104 | text_adjust = -2 * font_height / 5; |
3105 | break; |
3106 | case 0xBB: |
3107 | text_adjust = -1 * font_height / 5; |
3108 | break; |
3109 | case 0xBC: |
3110 | text_adjust = font_height / 5; |
3111 | break; |
3112 | case 0xBD: |
3113 | text_adjust = 2 * font_height / 5; |
3114 | break; |
3115 | } |
3116 | if (lattr == LATTR_TOP || lattr == LATTR_BOT) |
3117 | text_adjust *= 2; |
3118 | text[0] = ucsdata.unitab_xterm['q']; |
3119 | if (attr & ATTR_UNDER) { |
3120 | attr &= ~ATTR_UNDER; |
3121 | force_manual_underline = 1; |
374330e2 |
3122 | } |
3123 | } |
3124 | |
4eeb7d09 |
3125 | /* Anything left as an original character set is unprintable. */ |
36566009 |
3126 | if (DIRECT_CHAR(text[0])) { |
3127 | int i; |
3128 | for (i = 0; i < len; i++) |
3129 | text[i] = 0xFFFD; |
4eeb7d09 |
3130 | } |
3131 | |
3132 | /* OEM CP */ |
36566009 |
3133 | if ((text[0] & CSET_MASK) == CSET_OEMCP) |
4eeb7d09 |
3134 | nfont |= FONT_OEM; |
3135 | |
37ca32ed |
3136 | nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT); |
37ca32ed |
3137 | nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT); |
374330e2 |
3138 | if (bold_mode == BOLD_FONT && (attr & ATTR_BOLD)) |
3139 | nfont |= FONT_BOLD; |
3140 | if (und_mode == UND_FONT && (attr & ATTR_UNDER)) |
3141 | nfont |= FONT_UNDERLINE; |
4eeb7d09 |
3142 | another_font(nfont); |
32874aea |
3143 | if (!fonts[nfont]) { |
3144 | if (nfont & FONT_UNDERLINE) |
59ad2c03 |
3145 | force_manual_underline = 1; |
3146 | /* Don't do the same for manual bold, it could be bad news. */ |
3147 | |
32874aea |
3148 | nfont &= ~(FONT_BOLD | FONT_UNDERLINE); |
59ad2c03 |
3149 | } |
4eeb7d09 |
3150 | another_font(nfont); |
3151 | if (!fonts[nfont]) |
3152 | nfont = FONT_NORMAL; |
374330e2 |
3153 | if (attr & ATTR_REVERSE) { |
32874aea |
3154 | t = nfg; |
3155 | nfg = nbg; |
3156 | nbg = t; |
374330e2 |
3157 | } |
cecb13f6 |
3158 | if (bold_mode == BOLD_COLOURS && (attr & ATTR_BOLD)) { |
3159 | if (nfg < 16) nfg |= 8; |
3160 | else if (nfg >= 256) nfg |= 1; |
3161 | } |
3162 | if (bold_mode == BOLD_COLOURS && (attr & ATTR_BLINK)) { |
3163 | if (nbg < 16) nbg |= 8; |
3164 | else if (nbg >= 256) nbg |= 1; |
3165 | } |
374330e2 |
3166 | fg = colours[nfg]; |
3167 | bg = colours[nbg]; |
32874aea |
3168 | SelectObject(hdc, fonts[nfont]); |
3169 | SetTextColor(hdc, fg); |
3170 | SetBkColor(hdc, bg); |
c6958dfe |
3171 | if (attr & TATTR_COMBINING) |
3172 | SetBkMode(hdc, TRANSPARENT); |
3173 | else |
3174 | SetBkMode(hdc, OPAQUE); |
32874aea |
3175 | line_box.left = x; |
3176 | line_box.top = y; |
4eeb7d09 |
3177 | line_box.right = x + char_width * len; |
32874aea |
3178 | line_box.bottom = y + font_height; |
4eeb7d09 |
3179 | |
5a73255e |
3180 | /* Only want the left half of double width lines */ |
887035a5 |
3181 | if (line_box.right > font_width*term->cols+offset_width) |
3182 | line_box.right = font_width*term->cols+offset_width; |
5a73255e |
3183 | |
4eeb7d09 |
3184 | /* We're using a private area for direct to font. (512 chars.) */ |
36566009 |
3185 | if (ucsdata.dbcs_screenfont && (text[0] & CSET_MASK) == CSET_ACP) { |
4eeb7d09 |
3186 | /* Ho Hum, dbcs fonts are a PITA! */ |
3187 | /* To display on W9x I have to convert to UCS */ |
3188 | static wchar_t *uni_buf = 0; |
3189 | static int uni_len = 0; |
5a73255e |
3190 | int nlen, mptr; |
4eeb7d09 |
3191 | if (len > uni_len) { |
3192 | sfree(uni_buf); |
3d88e64d |
3193 | uni_len = len; |
3194 | uni_buf = snewn(uni_len, wchar_t); |
4eeb7d09 |
3195 | } |
4eeb7d09 |
3196 | |
5a73255e |
3197 | for(nlen = mptr = 0; mptr<len; mptr++) { |
3198 | uni_buf[nlen] = 0xFFFD; |
21d2b241 |
3199 | if (IsDBCSLeadByteEx(ucsdata.font_codepage, (BYTE) text[mptr])) { |
36566009 |
3200 | char dbcstext[2]; |
3201 | dbcstext[0] = text[mptr] & 0xFF; |
3202 | dbcstext[1] = text[mptr+1] & 0xFF; |
5a73255e |
3203 | IpDx[nlen] += char_width; |
21d2b241 |
3204 | MultiByteToWideChar(ucsdata.font_codepage, MB_USEGLYPHCHARS, |
36566009 |
3205 | dbcstext, 2, uni_buf+nlen, 1); |
5a73255e |
3206 | mptr++; |
3207 | } |
3208 | else |
3209 | { |
36566009 |
3210 | char dbcstext[1]; |
3211 | dbcstext[0] = text[mptr] & 0xFF; |
21d2b241 |
3212 | MultiByteToWideChar(ucsdata.font_codepage, MB_USEGLYPHCHARS, |
36566009 |
3213 | dbcstext, 1, uni_buf+nlen, 1); |
5a73255e |
3214 | } |
3215 | nlen++; |
3216 | } |
4eeb7d09 |
3217 | if (nlen <= 0) |
3218 | return; /* Eeek! */ |
3219 | |
3220 | ExtTextOutW(hdc, x, |
3221 | y - font_height * (lattr == LATTR_BOT) + text_adjust, |
5a73255e |
3222 | ETO_CLIPPED | ETO_OPAQUE, &line_box, uni_buf, nlen, IpDx); |
4eeb7d09 |
3223 | if (bold_mode == BOLD_SHADOW && (attr & ATTR_BOLD)) { |
3224 | SetBkMode(hdc, TRANSPARENT); |
3225 | ExtTextOutW(hdc, x - 1, |
3226 | y - font_height * (lattr == |
3227 | LATTR_BOT) + text_adjust, |
5a73255e |
3228 | ETO_CLIPPED, &line_box, uni_buf, nlen, IpDx); |
4eeb7d09 |
3229 | } |
5a73255e |
3230 | |
3231 | IpDx[0] = -1; |
36566009 |
3232 | } else if (DIRECT_FONT(text[0])) { |
3233 | static char *directbuf = NULL; |
3234 | static int directlen = 0; |
3235 | int i; |
3236 | if (len > directlen) { |
3237 | directlen = len; |
3238 | directbuf = sresize(directbuf, directlen, char); |
3239 | } |
3240 | |
3241 | for (i = 0; i < len; i++) |
3242 | directbuf[i] = text[i] & 0xFF; |
3243 | |
4eeb7d09 |
3244 | ExtTextOut(hdc, x, |
3245 | y - font_height * (lattr == LATTR_BOT) + text_adjust, |
36566009 |
3246 | ETO_CLIPPED | ETO_OPAQUE, &line_box, directbuf, len, IpDx); |
4eeb7d09 |
3247 | if (bold_mode == BOLD_SHADOW && (attr & ATTR_BOLD)) { |
3248 | SetBkMode(hdc, TRANSPARENT); |
3249 | |
3250 | /* GRR: This draws the character outside it's box and can leave |
3251 | * 'droppings' even with the clip box! I suppose I could loop it |
3252 | * one character at a time ... yuk. |
3253 | * |
3254 | * Or ... I could do a test print with "W", and use +1 or -1 for this |
3255 | * shift depending on if the leftmost column is blank... |
3256 | */ |
3257 | ExtTextOut(hdc, x - 1, |
3258 | y - font_height * (lattr == |
3259 | LATTR_BOT) + text_adjust, |
36566009 |
3260 | ETO_CLIPPED, &line_box, directbuf, len, IpDx); |
4eeb7d09 |
3261 | } |
3262 | } else { |
3263 | /* And 'normal' unicode characters */ |
3264 | static WCHAR *wbuf = NULL; |
3265 | static int wlen = 0; |
3266 | int i; |
c6958dfe |
3267 | |
4eeb7d09 |
3268 | if (wlen < len) { |
3269 | sfree(wbuf); |
3270 | wlen = len; |
3d88e64d |
3271 | wbuf = snewn(wlen, WCHAR); |
4eeb7d09 |
3272 | } |
c6958dfe |
3273 | |
4eeb7d09 |
3274 | for (i = 0; i < len; i++) |
36566009 |
3275 | wbuf[i] = text[i]; |
4eeb7d09 |
3276 | |
f0fccd51 |
3277 | /* print Glyphs as they are, without Windows' Shaping*/ |
3278 | exact_textout(hdc, x, y - font_height * (lattr == LATTR_BOT) + text_adjust, |
c6958dfe |
3279 | &line_box, wbuf, len, IpDx, !(attr & TATTR_COMBINING)); |
f0fccd51 |
3280 | /* ExtTextOutW(hdc, x, |
4eeb7d09 |
3281 | y - font_height * (lattr == LATTR_BOT) + text_adjust, |
3282 | ETO_CLIPPED | ETO_OPAQUE, &line_box, wbuf, len, IpDx); |
f0fccd51 |
3283 | */ |
4eeb7d09 |
3284 | |
3285 | /* And the shadow bold hack. */ |
5a73255e |
3286 | if (bold_mode == BOLD_SHADOW && (attr & ATTR_BOLD)) { |
4eeb7d09 |
3287 | SetBkMode(hdc, TRANSPARENT); |
3288 | ExtTextOutW(hdc, x - 1, |
3289 | y - font_height * (lattr == |
3290 | LATTR_BOT) + text_adjust, |
3291 | ETO_CLIPPED, &line_box, wbuf, len, IpDx); |
3292 | } |
374330e2 |
3293 | } |
4eeb7d09 |
3294 | if (lattr != LATTR_TOP && (force_manual_underline || |
3295 | (und_mode == UND_LINE |
3296 | && (attr & ATTR_UNDER)))) { |
32874aea |
3297 | HPEN oldpen; |
4eeb7d09 |
3298 | int dec = descent; |
3299 | if (lattr == LATTR_BOT) |
3300 | dec = dec * 2 - font_height; |
3301 | |
32874aea |
3302 | oldpen = SelectObject(hdc, CreatePen(PS_SOLID, 0, fg)); |
4eeb7d09 |
3303 | MoveToEx(hdc, x, y + dec, NULL); |
3304 | LineTo(hdc, x + len * char_width, y + dec); |
32874aea |
3305 | oldpen = SelectObject(hdc, oldpen); |
3306 | DeleteObject(oldpen); |
374330e2 |
3307 | } |
4eeb7d09 |
3308 | } |
3309 | |
c6958dfe |
3310 | /* |
3311 | * Wrapper that handles combining characters. |
3312 | */ |
3313 | void do_text(Context ctx, int x, int y, wchar_t *text, int len, |
3314 | unsigned long attr, int lattr) |
3315 | { |
3316 | if (attr & TATTR_COMBINING) { |
3317 | unsigned long a = 0; |
3318 | attr &= ~TATTR_COMBINING; |
3319 | while (len--) { |
3320 | do_text_internal(ctx, x, y, text, 1, attr | a, lattr); |
3321 | text++; |
3322 | a = TATTR_COMBINING; |
3323 | } |
3324 | } else |
3325 | do_text_internal(ctx, x, y, text, len, attr, lattr); |
3326 | } |
3327 | |
36566009 |
3328 | void do_cursor(Context ctx, int x, int y, wchar_t *text, int len, |
4eeb7d09 |
3329 | unsigned long attr, int lattr) |
3330 | { |
3331 | |
3332 | int fnt_width; |
3333 | int char_width; |
3334 | HDC hdc = ctx; |
3335 | int ctype = cfg.cursor_type; |
3336 | |
8af95aa3 |
3337 | lattr &= LATTR_MODE; |
3338 | |
887035a5 |
3339 | if ((attr & TATTR_ACTCURS) && (ctype == 0 || term->big_cursor)) { |
36566009 |
3340 | if (*text != UCSWIDE) { |
4eeb7d09 |
3341 | do_text(ctx, x, y, text, len, attr, lattr); |
3342 | return; |
3343 | } |
3344 | ctype = 2; |
3345 | attr |= TATTR_RIGHTCURS; |
3346 | } |
3347 | |
3348 | fnt_width = char_width = font_width * (1 + (lattr != LATTR_NORM)); |
3349 | if (attr & ATTR_WIDE) |
3350 | char_width *= 2; |
3351 | x *= fnt_width; |
3352 | y *= font_height; |
5a73255e |
3353 | x += offset_width; |
3354 | y += offset_height; |
4eeb7d09 |
3355 | |
887035a5 |
3356 | if ((attr & TATTR_PASCURS) && (ctype == 0 || term->big_cursor)) { |
374330e2 |
3357 | POINT pts[5]; |
32874aea |
3358 | HPEN oldpen; |
374330e2 |
3359 | pts[0].x = pts[1].x = pts[4].x = x; |
4eeb7d09 |
3360 | pts[2].x = pts[3].x = x + char_width - 1; |
374330e2 |
3361 | pts[0].y = pts[3].y = pts[4].y = y; |
32874aea |
3362 | pts[1].y = pts[2].y = y + font_height - 1; |
cecb13f6 |
3363 | oldpen = SelectObject(hdc, CreatePen(PS_SOLID, 0, colours[261])); |
32874aea |
3364 | Polyline(hdc, pts, 5); |
3365 | oldpen = SelectObject(hdc, oldpen); |
3366 | DeleteObject(oldpen); |
4eeb7d09 |
3367 | } else if ((attr & (TATTR_ACTCURS | TATTR_PASCURS)) && ctype != 0) { |
32874aea |
3368 | int startx, starty, dx, dy, length, i; |
4eeb7d09 |
3369 | if (ctype == 1) { |
32874aea |
3370 | startx = x; |
3371 | starty = y + descent; |
3372 | dx = 1; |
3373 | dy = 0; |
4eeb7d09 |
3374 | length = char_width; |
32874aea |
3375 | } else { |
4e30ff69 |
3376 | int xadjust = 0; |
4eeb7d09 |
3377 | if (attr & TATTR_RIGHTCURS) |
3378 | xadjust = char_width - 1; |
32874aea |
3379 | startx = x + xadjust; |
3380 | starty = y; |
3381 | dx = 0; |
3382 | dy = 1; |
3383 | length = font_height; |
3384 | } |
4eeb7d09 |
3385 | if (attr & TATTR_ACTCURS) { |
32874aea |
3386 | HPEN oldpen; |
3387 | oldpen = |
fdc94dd1 |
3388 | SelectObject(hdc, CreatePen(PS_SOLID, 0, colours[261])); |
32874aea |
3389 | MoveToEx(hdc, startx, starty, NULL); |
3390 | LineTo(hdc, startx + dx * length, starty + dy * length); |
3391 | oldpen = SelectObject(hdc, oldpen); |
3392 | DeleteObject(oldpen); |
3393 | } else { |
3394 | for (i = 0; i < length; i++) { |
3395 | if (i % 2 == 0) { |
fdc94dd1 |
3396 | SetPixel(hdc, startx, starty, colours[261]); |
32874aea |
3397 | } |
3398 | startx += dx; |
3399 | starty += dy; |
3400 | } |
3401 | } |
4e30ff69 |
3402 | } |
374330e2 |
3403 | } |
3404 | |
5a73255e |
3405 | /* This function gets the actual width of a character in the normal font. |
3406 | */ |
2102eb8a |
3407 | int char_width(Context ctx, int uc) { |
5a73255e |
3408 | HDC hdc = ctx; |
3409 | int ibuf = 0; |
3410 | |
3411 | /* If the font max is the same as the font ave width then this |
3412 | * function is a no-op. |
3413 | */ |
3414 | if (!font_dualwidth) return 1; |
3415 | |
3416 | switch (uc & CSET_MASK) { |
36566009 |
3417 | case CSET_ASCII: |
21d2b241 |
3418 | uc = ucsdata.unitab_line[uc & 0xFF]; |
5a73255e |
3419 | break; |
36566009 |
3420 | case CSET_LINEDRW: |
21d2b241 |
3421 | uc = ucsdata.unitab_xterm[uc & 0xFF]; |
5a73255e |
3422 | break; |
36566009 |
3423 | case CSET_SCOACS: |
21d2b241 |
3424 | uc = ucsdata.unitab_scoacs[uc & 0xFF]; |
5a73255e |
3425 | break; |
3426 | } |
3427 | if (DIRECT_FONT(uc)) { |
21d2b241 |
3428 | if (ucsdata.dbcs_screenfont) return 1; |
5a73255e |
3429 | |
3430 | /* Speedup, I know of no font where ascii is the wrong width */ |
36566009 |
3431 | if ((uc&~CSET_MASK) >= ' ' && (uc&~CSET_MASK)<= '~') |
5a73255e |
3432 | return 1; |
3433 | |
36566009 |
3434 | if ( (uc & CSET_MASK) == CSET_ACP ) { |
5a73255e |
3435 | SelectObject(hdc, fonts[FONT_NORMAL]); |
36566009 |
3436 | } else if ( (uc & CSET_MASK) == CSET_OEMCP ) { |
5a73255e |
3437 | another_font(FONT_OEM); |
3438 | if (!fonts[FONT_OEM]) return 0; |
3439 | |
3440 | SelectObject(hdc, fonts[FONT_OEM]); |
3441 | } else |
3442 | return 0; |
3443 | |
36566009 |
3444 | if ( GetCharWidth32(hdc, uc&~CSET_MASK, uc&~CSET_MASK, &ibuf) != 1 && |
3445 | GetCharWidth(hdc, uc&~CSET_MASK, uc&~CSET_MASK, &ibuf) != 1) |
5a73255e |
3446 | return 0; |
3447 | } else { |
3448 | /* Speedup, I know of no font where ascii is the wrong width */ |
3449 | if (uc >= ' ' && uc <= '~') return 1; |
3450 | |
3451 | SelectObject(hdc, fonts[FONT_NORMAL]); |
3452 | if ( GetCharWidth32W(hdc, uc, uc, &ibuf) == 1 ) |
3453 | /* Okay that one worked */ ; |
3454 | else if ( GetCharWidthW(hdc, uc, uc, &ibuf) == 1 ) |
3455 | /* This should work on 9x too, but it's "less accurate" */ ; |
3456 | else |
3457 | return 0; |
3458 | } |
3459 | |
3460 | ibuf += font_width / 2 -1; |
3461 | ibuf /= font_width; |
3462 | |
3463 | return ibuf; |
3464 | } |
3465 | |
374330e2 |
3466 | /* |
c9def1b8 |
3467 | * Translate a WM_(SYS)?KEY(UP|DOWN) message into a string of ASCII |
3468 | * codes. Returns number of bytes used or zero to drop the message |
3469 | * or -1 to forward the message to windows. |
374330e2 |
3470 | */ |
3cf144db |
3471 | static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, |
32874aea |
3472 | unsigned char *output) |
3473 | { |
374330e2 |
3474 | BYTE keystate[256]; |
32874aea |
3475 | int scan, left_alt = 0, key_down, shift_state; |
3476 | int r, i, code; |
3477 | unsigned char *p = output; |
4eeb7d09 |
3478 | static int alt_sum = 0; |
374330e2 |
3479 | |
00e3ba0f |
3480 | HKL kbd_layout = GetKeyboardLayout(0); |
3481 | |
c264be08 |
3482 | /* keys is for ToAsciiEx. There's some ick here, see below. */ |
3483 | static WORD keys[3]; |
0c50ef57 |
3484 | static int compose_char = 0; |
3485 | static WPARAM compose_key = 0; |
32874aea |
3486 | |
c9def1b8 |
3487 | r = GetKeyboardState(keystate); |
32874aea |
3488 | if (!r) |
3489 | memset(keystate, 0, sizeof(keystate)); |
3490 | else { |
ec55b220 |
3491 | #if 0 |
4eeb7d09 |
3492 | #define SHOW_TOASCII_RESULT |
32874aea |
3493 | { /* Tell us all about key events */ |
3494 | static BYTE oldstate[256]; |
3495 | static int first = 1; |
3496 | static int scan; |
3497 | int ch; |
3498 | if (first) |
3499 | memcpy(oldstate, keystate, sizeof(oldstate)); |
3500 | first = 0; |
3501 | |
3502 | if ((HIWORD(lParam) & (KF_UP | KF_REPEAT)) == KF_REPEAT) { |
3503 | debug(("+")); |
3504 | } else if ((HIWORD(lParam) & KF_UP) |
3505 | && scan == (HIWORD(lParam) & 0xFF)) { |
3506 | debug((". U")); |
3507 | } else { |
3508 | debug((".\n")); |
3509 | if (wParam >= VK_F1 && wParam <= VK_F20) |
3510 | debug(("K_F%d", wParam + 1 - VK_F1)); |
3511 | else |
3512 | switch (wParam) { |
3513 | case VK_SHIFT: |
3514 | debug(("SHIFT")); |
3515 | break; |
3516 | case VK_CONTROL: |
3517 | debug(("CTRL")); |
3518 | break; |
3519 | case VK_MENU: |
3520 | debug(("ALT")); |
3521 | break; |
3522 | default: |
3523 | debug(("VK_%02x", wParam)); |
3524 | } |
3525 | if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP) |
3526 | debug(("*")); |
3527 | debug((", S%02x", scan = (HIWORD(lParam) & 0xFF))); |
3528 | |
3529 | ch = MapVirtualKeyEx(wParam, 2, kbd_layout); |
3530 | if (ch >= ' ' && ch <= '~') |
3531 | debug((", '%c'", ch)); |
3532 | else if (ch) |
3533 | debug((", $%02x", ch)); |
3534 | |
3535 | if (keys[0]) |
3536 | debug((", KB0=%02x", keys[0])); |
3537 | if (keys[1]) |
3538 | debug((", KB1=%02x", keys[1])); |
3539 | if (keys[2]) |
3540 | debug((", KB2=%02x", keys[2])); |
3541 | |
3542 | if ((keystate[VK_SHIFT] & 0x80) != 0) |
3543 | debug((", S")); |
3544 | if ((keystate[VK_CONTROL] & 0x80) != 0) |
3545 | debug((", C")); |
3546 | if ((HIWORD(lParam) & KF_EXTENDED)) |
3547 | debug((", E")); |
3548 | if ((HIWORD(lParam) & KF_UP)) |
3549 | debug((", U")); |
3550 | } |
3551 | |
3552 | if ((HIWORD(lParam) & (KF_UP | KF_REPEAT)) == KF_REPEAT); |
3553 | else if ((HIWORD(lParam) & KF_UP)) |
3554 | oldstate[wParam & 0xFF] ^= 0x80; |
3555 | else |
3556 | oldstate[wParam & 0xFF] ^= 0x81; |
3557 | |
3558 | for (ch = 0; ch < 256; ch++) |
3559 | if (oldstate[ch] != keystate[ch]) |
3560 | debug((", M%02x=%02x", ch, keystate[ch])); |
3561 | |
3562 | memcpy(oldstate, keystate, sizeof(oldstate)); |
3563 | } |
ec55b220 |
3564 | #endif |
3565 | |
32874aea |
3566 | if (wParam == VK_MENU && (HIWORD(lParam) & KF_EXTENDED)) { |
2cba1186 |
3567 | keystate[VK_RMENU] = keystate[VK_MENU]; |
3568 | } |
3569 | |
c9def1b8 |
3570 | |
3571 | /* Nastyness with NUMLock - Shift-NUMLock is left alone though */ |
5789bc94 |
3572 | if ((cfg.funky_type == FUNKY_VT400 || |
3573 | (cfg.funky_type <= FUNKY_LINUX && term->app_keypad_keys && |
887035a5 |
3574 | !cfg.no_applic_k)) |
32874aea |
3575 | && wParam == VK_NUMLOCK && !(keystate[VK_SHIFT] & 0x80)) { |
c9def1b8 |
3576 | |
3577 | wParam = VK_EXECUTE; |
3578 | |
3579 | /* UnToggle NUMLock */ |
32874aea |
3580 | if ((HIWORD(lParam) & (KF_UP | KF_REPEAT)) == 0) |
3581 | keystate[VK_NUMLOCK] ^= 1; |
c9def1b8 |
3582 | } |
3583 | |
3584 | /* And write back the 'adjusted' state */ |
32874aea |
3585 | SetKeyboardState(keystate); |
c9def1b8 |
3586 | } |
3587 | |
3588 | /* Disable Auto repeat if required */ |
887035a5 |
3589 | if (term->repeat_off && |
3590 | (HIWORD(lParam) & (KF_UP | KF_REPEAT)) == KF_REPEAT) |
32874aea |
3591 | return 0; |
c9def1b8 |
3592 | |
32874aea |
3593 | if ((HIWORD(lParam) & KF_ALTDOWN) && (keystate[VK_RMENU] & 0x80) == 0) |
c9def1b8 |
3594 | left_alt = 1; |
3595 | |
32874aea |
3596 | key_down = ((HIWORD(lParam) & KF_UP) == 0); |
c9def1b8 |
3597 | |
95bbe1ae |
3598 | /* Make sure Ctrl-ALT is not the same as AltGr for ToAscii unless told. */ |
32874aea |
3599 | if (left_alt && (keystate[VK_CONTROL] & 0x80)) { |
95bbe1ae |
3600 | if (cfg.ctrlaltkeys) |
3601 | keystate[VK_MENU] = 0; |
3602 | else { |
3603 | keystate[VK_RMENU] = 0x80; |
3604 | left_alt = 0; |
3605 | } |
3606 | } |
c9def1b8 |
3607 | |
3608 | scan = (HIWORD(lParam) & (KF_UP | KF_EXTENDED | 0xFF)); |
32874aea |
3609 | shift_state = ((keystate[VK_SHIFT] & 0x80) != 0) |
3610 | + ((keystate[VK_CONTROL] & 0x80) != 0) * 2; |
374330e2 |
3611 | |
95bbe1ae |
3612 | /* Note if AltGr was pressed and if it was used as a compose key */ |
3613 | if (!compose_state) { |
159eba53 |
3614 | compose_key = 0x100; |
95bbe1ae |
3615 | if (cfg.compose_key) { |
32874aea |
3616 | if (wParam == VK_MENU && (HIWORD(lParam) & KF_EXTENDED)) |
95bbe1ae |
3617 | compose_key = wParam; |
3618 | } |
3619 | if (wParam == VK_APPS) |
3620 | compose_key = wParam; |
3621 | } |
3622 | |
32874aea |
3623 | if (wParam == compose_key) { |
3624 | if (compose_state == 0 |
3625 | && (HIWORD(lParam) & (KF_UP | KF_REPEAT)) == 0) compose_state = |
3626 | 1; |
3627 | else if (compose_state == 1 && (HIWORD(lParam) & KF_UP)) |
95bbe1ae |
3628 | compose_state = 2; |
3629 | else |
3630 | compose_state = 0; |
32874aea |
3631 | } else if (compose_state == 1 && wParam != VK_CONTROL) |
95bbe1ae |
3632 | compose_state = 0; |
3633 | |
32874aea |
3634 | if (compose_state > 1 && left_alt) |
3635 | compose_state = 0; |
67c339f7 |
3636 | |
c9def1b8 |
3637 | /* Sanitize the number pad if not using a PC NumPad */ |
887035a5 |
3638 | if (left_alt || (term->app_keypad_keys && !cfg.no_applic_k |
5789bc94 |
3639 | && cfg.funky_type != FUNKY_XTERM) |
3640 | || cfg.funky_type == FUNKY_VT400 || cfg.nethack_keypad || compose_state) { |
32874aea |
3641 | if ((HIWORD(lParam) & KF_EXTENDED) == 0) { |
c9def1b8 |
3642 | int nParam = 0; |
32874aea |
3643 | switch (wParam) { |
3644 | case VK_INSERT: |
3645 | nParam = VK_NUMPAD0; |
3646 | break; |
3647 | case VK_END: |
3648 | nParam = VK_NUMPAD1; |
3649 | break; |
3650 | case VK_DOWN: |
3651 | nParam = VK_NUMPAD2; |
3652 | break; |
3653 | case VK_NEXT: |
3654 | nParam = VK_NUMPAD3; |
3655 | break; |
3656 | case VK_LEFT: |
3657 | nParam = VK_NUMPAD4; |
3658 | break; |
3659 | case VK_CLEAR: |
3660 | nParam = VK_NUMPAD5; |
3661 | break; |
3662 | case VK_RIGHT: |
3663 | nParam = VK_NUMPAD6; |
3664 | break; |
3665 | case VK_HOME: |
3666 | nParam = VK_NUMPAD7; |
3667 | break; |
3668 | case VK_UP: |
3669 | nParam = VK_NUMPAD8; |
3670 | break; |
3671 | case VK_PRIOR: |
3672 | nParam = VK_NUMPAD9; |
3673 | break; |
3674 | case VK_DELETE: |
3675 | nParam = VK_DECIMAL; |
3676 | break; |
c9def1b8 |
3677 | } |
32874aea |
3678 | if (nParam) { |
3679 | if (keystate[VK_NUMLOCK] & 1) |
3680 | shift_state |= 1; |
c9def1b8 |
3681 | wParam = nParam; |
3682 | } |
25d39ef6 |
3683 | } |
3684 | } |
3685 | |
c9def1b8 |
3686 | /* If a key is pressed and AltGr is not active */ |
32874aea |
3687 | if (key_down && (keystate[VK_RMENU] & 0x80) == 0 && !compose_state) { |
3688 | /* Okay, prepare for most alts then ... */ |
3689 | if (left_alt) |
3690 | *p++ = '\033'; |
374330e2 |
3691 | |
c9def1b8 |
3692 | /* Lets see if it's a pattern we know all about ... */ |
3693 | if (wParam == VK_PRIOR && shift_state == 1) { |
32874aea |
3694 | SendMessage(hwnd, WM_VSCROLL, SB_PAGEUP, 0); |
3695 | return 0; |
c9def1b8 |
3696 | } |
153580da |
3697 | if (wParam == VK_PRIOR && shift_state == 2) { |
3698 | SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0); |
3699 | return 0; |
3700 | } |
c9def1b8 |
3701 | if (wParam == VK_NEXT && shift_state == 1) { |
32874aea |
3702 | SendMessage(hwnd, WM_VSCROLL, SB_PAGEDOWN, 0); |
3703 | return 0; |
3704 | } |
153580da |
3705 | if (wParam == VK_NEXT && shift_state == 2) { |
3706 | SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0); |
3707 | return 0; |
3708 | } |
32874aea |
3709 | if (wParam == VK_INSERT && shift_state == 1) { |
887035a5 |
3710 | term_do_paste(term); |
32874aea |
3711 | return 0; |
3712 | } |
c9def1b8 |
3713 | if (left_alt && wParam == VK_F4 && cfg.alt_f4) { |
32874aea |
3714 | return -1; |
c9def1b8 |
3715 | } |
3716 | if (left_alt && wParam == VK_SPACE && cfg.alt_space) { |
32874aea |
3717 | SendMessage(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0); |
3718 | return -1; |
c9def1b8 |
3719 | } |
2cae8529 |
3720 | if (left_alt && wParam == VK_RETURN && cfg.fullscreenonaltenter && |
3721 | (cfg.resize_action != RESIZE_DISABLED)) { |
0ed2f48e |
3722 | if ((HIWORD(lParam) & (KF_UP | KF_REPEAT)) != KF_REPEAT) |
3723 | flip_full_screen(); |
8f57d753 |
3724 | return -1; |
3725 | } |
ec55b220 |
3726 | /* Control-Numlock for app-keypad mode switch */ |
3727 | if (wParam == VK_PAUSE && shift_state == 2) { |
887035a5 |
3728 | term->app_keypad_keys ^= 1; |
ec55b220 |
3729 | return 0; |
3730 | } |
374330e2 |
3731 | |
c9def1b8 |
3732 | /* Nethack keypad */ |
3733 | if (cfg.nethack_keypad && !left_alt) { |
32874aea |
3734 | switch (wParam) { |
3735 | case VK_NUMPAD1: |
3736 | *p++ = shift_state ? 'B' : 'b'; |
3737 | return p - output; |
3738 | case VK_NUMPAD2: |
3739 | *p++ = shift_state ? 'J' : 'j'; |
3740 | return p - output; |
3741 | case VK_NUMPAD3: |
3742 | *p++ = shift_state ? 'N' : 'n'; |
3743 | return p - output; |
3744 | case VK_NUMPAD4: |
3745 | *p++ = shift_state ? 'H' : 'h'; |
3746 | return p - output; |
3747 | case VK_NUMPAD5: |
3748 | *p++ = shift_state ? '.' : '.'; |
3749 | return p - output; |
3750 | case VK_NUMPAD6: |
3751 | *p++ = shift_state ? 'L' : 'l'; |
3752 | return p - output; |
3753 | case VK_NUMPAD7: |
3754 | *p++ = shift_state ? 'Y' : 'y'; |
3755 | return p - output; |
3756 | case VK_NUMPAD8: |
3757 | *p++ = shift_state ? 'K' : 'k'; |
3758 | return p - output; |
3759 | case VK_NUMPAD9: |
3760 | *p++ = shift_state ? 'U' : 'u'; |
3761 | return p - output; |
3762 | } |
c9def1b8 |
3763 | } |
3764 | |
3765 | /* Application Keypad */ |
3766 | if (!left_alt) { |
32874aea |
3767 | int xkey = 0; |
3768 | |
5789bc94 |
3769 | if (cfg.funky_type == FUNKY_VT400 || |
3770 | (cfg.funky_type <= FUNKY_LINUX && |
887035a5 |
3771 | term->app_keypad_keys && !cfg.no_applic_k)) switch (wParam) { |
32874aea |
3772 | case VK_EXECUTE: |
3773 | xkey = 'P'; |
3774 | break; |
3775 | case VK_DIVIDE: |
3776 | xkey = 'Q'; |
3777 | break; |
3778 | case VK_MULTIPLY: |
3779 | xkey = 'R'; |
3780 | break; |
3781 | case VK_SUBTRACT: |
3782 | xkey = 'S'; |
3783 | break; |
3784 | } |
887035a5 |
3785 | if (term->app_keypad_keys && !cfg.no_applic_k) |
32874aea |
3786 | switch (wParam) { |
3787 | case VK_NUMPAD0: |
3788 | xkey = 'p'; |
3789 | break; |
3790 | case VK_NUMPAD1: |
3791 | xkey = 'q'; |
3792 | break; |
3793 | case VK_NUMPAD2: |
3794 | xkey = 'r'; |
3795 | break; |
3796 | case VK_NUMPAD3: |
3797 | xkey = 's'; |
3798 | break; |
3799 | case VK_NUMPAD4: |
3800 | xkey = 't'; |
3801 | break; |
3802 | case VK_NUMPAD5: |
3803 | xkey = 'u'; |
3804 | break; |
3805 | case VK_NUMPAD6: |
3806 | xkey = 'v'; |
3807 | break; |
3808 | case VK_NUMPAD7: |
3809 | xkey = 'w'; |
3810 | break; |
3811 | case VK_NUMPAD8: |
3812 | xkey = 'x'; |
3813 | break; |
3814 | case VK_NUMPAD9: |
3815 | xkey = 'y'; |
3816 | break; |
3817 | |
3818 | case VK_DECIMAL: |
3819 | xkey = 'n'; |
3820 | break; |
3821 | case VK_ADD: |
5789bc94 |
3822 | if (cfg.funky_type == FUNKY_XTERM) { |
32874aea |
3823 | if (shift_state) |
3824 | xkey = 'l'; |
3825 | else |
3826 | xkey = 'k'; |
3827 | } else if (shift_state) |
3828 | xkey = 'm'; |
c9def1b8 |
3829 | else |
32874aea |
3830 | xkey = 'l'; |
3831 | break; |
3832 | |
3833 | case VK_DIVIDE: |
5789bc94 |
3834 | if (cfg.funky_type == FUNKY_XTERM) |
32874aea |
3835 | xkey = 'o'; |
3836 | break; |
3837 | case VK_MULTIPLY: |
5789bc94 |
3838 | if (cfg.funky_type == FUNKY_XTERM) |
32874aea |
3839 | xkey = 'j'; |
3840 | break; |
3841 | case VK_SUBTRACT: |
5789bc94 |
3842 | if (cfg.funky_type == FUNKY_XTERM) |
32874aea |
3843 | xkey = 'm'; |
3844 | break; |
3845 | |
3846 | case VK_RETURN: |
3847 | if (HIWORD(lParam) & KF_EXTENDED) |
3848 | xkey = 'M'; |
3849 | break; |
c9def1b8 |
3850 | } |
32874aea |
3851 | if (xkey) { |
887035a5 |
3852 | if (term->vt52_mode) { |
32874aea |
3853 | if (xkey >= 'P' && xkey <= 'S') |
3854 | p += sprintf((char *) p, "\x1B%c", xkey); |
3855 | else |
3856 | p += sprintf((char *) p, "\x1B?%c", xkey); |
3857 | } else |
3858 | p += sprintf((char *) p, "\x1BO%c", xkey); |
3859 | return p - output; |
c9def1b8 |
3860 | } |
3861 | } |
3862 | |
32874aea |
3863 | if (wParam == VK_BACK && shift_state == 0) { /* Backspace */ |
c9def1b8 |
3864 | *p++ = (cfg.bksp_is_delete ? 0x7F : 0x08); |
a5f3e637 |
3865 | *p++ = 0; |
3866 | return -2; |
c9def1b8 |
3867 | } |
e8e8d6e2 |
3868 | if (wParam == VK_BACK && shift_state == 1) { /* Shift Backspace */ |
3869 | /* We do the opposite of what is configured */ |
3870 | *p++ = (cfg.bksp_is_delete ? 0x08 : 0x7F); |
3871 | *p++ = 0; |
3872 | return -2; |
3873 | } |
32874aea |
3874 | if (wParam == VK_TAB && shift_state == 1) { /* Shift tab */ |
3875 | *p++ = 0x1B; |
3876 | *p++ = '['; |
3877 | *p++ = 'Z'; |
3878 | return p - output; |
c9def1b8 |
3879 | } |
32874aea |
3880 | if (wParam == VK_SPACE && shift_state == 2) { /* Ctrl-Space */ |
3881 | *p++ = 0; |
3882 | return p - output; |
c9def1b8 |
3883 | } |
32874aea |
3884 | if (wParam == VK_SPACE && shift_state == 3) { /* Ctrl-Shift-Space */ |
3885 | *p++ = 160; |
3886 | return p - output; |
c9def1b8 |
3887 | } |
32874aea |
3888 | if (wParam == VK_CANCEL && shift_state == 2) { /* Ctrl-Break */ |
3889 | *p++ = 3; |
a5f3e637 |
3890 | *p++ = 0; |
3891 | return -2; |
c9def1b8 |
3892 | } |
32874aea |
3893 | if (wParam == VK_PAUSE) { /* Break/Pause */ |
3894 | *p++ = 26; |
3895 | *p++ = 0; |
3896 | return -2; |
95bbe1ae |
3897 | } |
c9def1b8 |
3898 | /* Control-2 to Control-8 are special */ |
32874aea |
3899 | if (shift_state == 2 && wParam >= '2' && wParam <= '8') { |
3900 | *p++ = "\000\033\034\035\036\037\177"[wParam - '2']; |
c9def1b8 |
3901 | return p - output; |
3902 | } |
237f2b6e |
3903 | if (shift_state == 2 && (wParam == 0xBD || wParam == 0xBF)) { |
c9def1b8 |
3904 | *p++ = 0x1F; |
3905 | return p - output; |
3906 | } |
3907 | if (shift_state == 2 && wParam == 0xDF) { |
3908 | *p++ = 0x1C; |
3909 | return p - output; |
3910 | } |
9aa461e4 |
3911 | if (shift_state == 3 && wParam == 0xDE) { |
3912 | *p++ = 0x1E; /* Ctrl-~ == Ctrl-^ in xterm at least */ |
3913 | return p - output; |
3914 | } |
887035a5 |
3915 | if (shift_state == 0 && wParam == VK_RETURN && term->cr_lf_return) { |
32874aea |
3916 | *p++ = '\r'; |
3917 | *p++ = '\n'; |
c9def1b8 |
3918 | return p - output; |
3919 | } |
374330e2 |
3920 | |
c5e9c988 |
3921 | /* |
c9def1b8 |
3922 | * Next, all the keys that do tilde codes. (ESC '[' nn '~', |
3923 | * for integer decimal nn.) |
3924 | * |
3925 | * We also deal with the weird ones here. Linux VCs replace F1 |
3926 | * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but |
3927 | * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w |
3928 | * respectively. |
c5e9c988 |
3929 | */ |
c9def1b8 |
3930 | code = 0; |
3931 | switch (wParam) { |
32874aea |
3932 | case VK_F1: |
3933 | code = (keystate[VK_SHIFT] & 0x80 ? 23 : 11); |
3934 | break; |
3935 | case VK_F2: |
3936 | code = (keystate[VK_SHIFT] & 0x80 ? 24 : 12); |
3937 | break; |
3938 | case VK_F3: |
3939 | code = (keystate[VK_SHIFT] & 0x80 ? 25 : 13); |
3940 | break; |
3941 | case VK_F4: |
3942 | code = (keystate[VK_SHIFT] & 0x80 ? 26 : 14); |
3943 | break; |
3944 | case VK_F5: |
3945 | code = (keystate[VK_SHIFT] & 0x80 ? 28 : 15); |
3946 | break; |
3947 | case VK_F6: |
3948 | code = (keystate[VK_SHIFT] & 0x80 ? 29 : 17); |
3949 | break; |
3950 | case VK_F7: |
3951 | code = (keystate[VK_SHIFT] & 0x80 ? 31 : 18); |
3952 | break; |
3953 | case VK_F8: |
3954 | code = (keystate[VK_SHIFT] & 0x80 ? 32 : 19); |
3955 | break; |
3956 | case VK_F9: |
3957 | code = (keystate[VK_SHIFT] & 0x80 ? 33 : 20); |
3958 | break; |
3959 | case VK_F10: |
3960 | code = (keystate[VK_SHIFT] & 0x80 ? 34 : 21); |
3961 | break; |
3962 | case VK_F11: |
3963 | code = 23; |
3964 | break; |
3965 | case VK_F12: |
3966 | code = 24; |
3967 | break; |
3968 | case VK_F13: |
3969 | code = 25; |
3970 | break; |
3971 | case VK_F14: |
3972 | code = 26; |
3973 | break; |
3974 | case VK_F15: |
3975 | code = 28; |
3976 | break; |
3977 | case VK_F16: |
3978 | code = 29; |
3979 | break; |
3980 | case VK_F17: |
3981 | code = 31; |
3982 | break; |
3983 | case VK_F18: |
3984 | code = 32; |
3985 | break; |
3986 | case VK_F19: |
3987 | code = 33; |
3988 | break; |
3989 | case VK_F20: |
3990 | code = 34; |
3991 | break; |
dfca2656 |
3992 | } |
3993 | if ((shift_state&2) == 0) switch (wParam) { |
32874aea |
3994 | case VK_HOME: |
3995 | code = 1; |
3996 | break; |
3997 | case VK_INSERT: |
3998 | code = 2; |
3999 | break; |
4000 | case VK_DELETE: |
4001 | code = 3; |
4002 | break; |
4003 | case VK_END: |
4004 | code = 4; |
4005 | break; |
4006 | case VK_PRIOR: |
4007 | code = 5; |
4008 | break; |
4009 | case VK_NEXT: |
4010 | code = 6; |
4011 | break; |
374330e2 |
4012 | } |
ec55b220 |
4013 | /* Reorder edit keys to physical order */ |
5789bc94 |
4014 | if (cfg.funky_type == FUNKY_VT400 && code <= 6) |
32874aea |
4015 | code = "\0\2\1\4\5\3\6"[code]; |
ec55b220 |
4016 | |
887035a5 |
4017 | if (term->vt52_mode && code > 0 && code <= 6) { |
32874aea |
4018 | p += sprintf((char *) p, "\x1B%c", " HLMEIG"[code]); |
f37caa11 |
4019 | return p - output; |
4020 | } |
4021 | |
5789bc94 |
4022 | if (cfg.funky_type == FUNKY_SCO && /* SCO function keys */ |
9bc81a2c |
4023 | code >= 11 && code <= 34) { |
e24b1972 |
4024 | char codes[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{"; |
4025 | int index = 0; |
4026 | switch (wParam) { |
4027 | case VK_F1: index = 0; break; |
4028 | case VK_F2: index = 1; break; |
4029 | case VK_F3: index = 2; break; |
4030 | case VK_F4: index = 3; break; |
4031 | case VK_F5: index = 4; break; |
4032 | case VK_F6: index = 5; break; |
4033 | case VK_F7: index = 6; break; |
4034 | case VK_F8: index = 7; break; |
4035 | case VK_F9: index = 8; break; |
4036 | case VK_F10: index = 9; break; |
4037 | case VK_F11: index = 10; break; |
4038 | case VK_F12: index = 11; break; |
4039 | } |
4040 | if (keystate[VK_SHIFT] & 0x80) index += 12; |
4041 | if (keystate[VK_CONTROL] & 0x80) index += 24; |
4042 | p += sprintf((char *) p, "\x1B[%c", codes[index]); |
f37caa11 |
4043 | return p - output; |
4044 | } |
5789bc94 |
4045 | if (cfg.funky_type == FUNKY_SCO && /* SCO small keypad */ |
9bc81a2c |
4046 | code >= 1 && code <= 6) { |
4047 | char codes[] = "HL.FIG"; |
4048 | if (code == 3) { |
4049 | *p++ = '\x7F'; |
4050 | } else { |
4051 | p += sprintf((char *) p, "\x1B[%c", codes[code-1]); |
4052 | } |
4053 | return p - output; |
4054 | } |
5789bc94 |
4055 | if ((term->vt52_mode || cfg.funky_type == FUNKY_VT100P) && code >= 11 && code <= 24) { |
f37caa11 |
4056 | int offt = 0; |
32874aea |
4057 | if (code > 15) |
4058 | offt++; |
4059 | if (code > 21) |
4060 | offt++; |
887035a5 |
4061 | if (term->vt52_mode) |
32874aea |
4062 | p += sprintf((char *) p, "\x1B%c", code + 'P' - 11 - offt); |
f37caa11 |
4063 | else |
32874aea |
4064 | p += |
4065 | sprintf((char *) p, "\x1BO%c", code + 'P' - 11 - offt); |
f37caa11 |
4066 | return p - output; |
4067 | } |
5789bc94 |
4068 | if (cfg.funky_type == FUNKY_LINUX && code >= 11 && code <= 15) { |
32874aea |
4069 | p += sprintf((char *) p, "\x1B[[%c", code + 'A' - 11); |
c9def1b8 |
4070 | return p - output; |
4071 | } |
5789bc94 |
4072 | if (cfg.funky_type == FUNKY_XTERM && code >= 11 && code <= 14) { |
887035a5 |
4073 | if (term->vt52_mode) |
32874aea |
4074 | p += sprintf((char *) p, "\x1B%c", code + 'P' - 11); |
ec55b220 |
4075 | else |
32874aea |
4076 | p += sprintf((char *) p, "\x1BO%c", code + 'P' - 11); |
c9def1b8 |
4077 | return p - output; |
4078 | } |
4079 | if (cfg.rxvt_homeend && (code == 1 || code == 4)) { |
32874aea |
4080 | p += sprintf((char *) p, code == 1 ? "\x1B[H" : "\x1BOw"); |
c9def1b8 |
4081 | return p - output; |
4082 | } |
4083 | if (code) { |
32874aea |
4084 | p += sprintf((char *) p, "\x1B[%d~", code); |
374330e2 |
4085 | return p - output; |
374330e2 |
4086 | } |
45dabbc5 |
4087 | |
c9def1b8 |
4088 | /* |
4089 | * Now the remaining keys (arrows and Keypad 5. Keypad 5 for |
4090 | * some reason seems to send VK_CLEAR to Windows...). |
4091 | */ |
4092 | { |
4093 | char xkey = 0; |
4094 | switch (wParam) { |
32874aea |
4095 | case VK_UP: |
4096 | xkey = 'A'; |
4097 | break; |
4098 | case VK_DOWN: |
4099 | xkey = 'B'; |
4100 | break; |
4101 | case VK_RIGHT: |
4102 | xkey = 'C'; |
4103 | break; |
4104 | case VK_LEFT: |
4105 | xkey = 'D'; |
4106 | break; |
4107 | case VK_CLEAR: |
4108 | xkey = 'G'; |
4109 | break; |
c9def1b8 |
4110 | } |
32874aea |
4111 | if (xkey) { |
887035a5 |
4112 | if (term->vt52_mode) |
32874aea |
4113 | p += sprintf((char *) p, "\x1B%c", xkey); |
e864f84f |
4114 | else { |
887035a5 |
4115 | int app_flg = (term->app_cursor_keys && !cfg.no_applic_c); |
3a953121 |
4116 | #if 0 |
4117 | /* |
4118 | * RDB: VT100 & VT102 manuals both state the |
4119 | * app cursor keys only work if the app keypad |
4120 | * is on. |
4121 | * |
4122 | * SGT: That may well be true, but xterm |
4123 | * disagrees and so does at least one |
4124 | * application, so I've #if'ed this out and the |
4125 | * behaviour is back to PuTTY's original: app |
4126 | * cursor and app keypad are independently |
4127 | * switchable modes. If anyone complains about |
4128 | * _this_ I'll have to put in a configurable |
4129 | * option. |
e864f84f |
4130 | */ |
887035a5 |
4131 | if (!term->app_keypad_keys) |
e864f84f |
4132 | app_flg = 0; |
3a953121 |
4133 | #endif |
e864f84f |
4134 | /* Useful mapping of Ctrl-arrows */ |
4135 | if (shift_state == 2) |
4136 | app_flg = !app_flg; |
4137 | |
4138 | if (app_flg) |
4139 | p += sprintf((char *) p, "\x1BO%c", xkey); |
4140 | else |
4141 | p += sprintf((char *) p, "\x1B[%c", xkey); |
4142 | } |
c9def1b8 |
4143 | return p - output; |
4144 | } |
4145 | } |
0c50ef57 |
4146 | |
4147 | /* |
4148 | * Finally, deal with Return ourselves. (Win95 seems to |
4149 | * foul it up when Alt is pressed, for some reason.) |
4150 | */ |
32874aea |
4151 | if (wParam == VK_RETURN) { /* Return */ |
0c50ef57 |
4152 | *p++ = 0x0D; |
a5f3e637 |
4153 | *p++ = 0; |
4154 | return -2; |
0c50ef57 |
4155 | } |
4eeb7d09 |
4156 | |
4157 | if (left_alt && wParam >= VK_NUMPAD0 && wParam <= VK_NUMPAD9) |
4158 | alt_sum = alt_sum * 10 + wParam - VK_NUMPAD0; |
4159 | else |
4160 | alt_sum = 0; |
67c339f7 |
4161 | } |
374330e2 |
4162 | |
c9def1b8 |
4163 | /* Okay we've done everything interesting; let windows deal with |
4164 | * the boring stuff */ |
4165 | { |
a9c02454 |
4166 | BOOL capsOn=0; |
4167 | |
4168 | /* helg: clear CAPS LOCK state if caps lock switches to cyrillic */ |
4169 | if(cfg.xlat_capslockcyr && keystate[VK_CAPITAL] != 0) { |
4170 | capsOn= !left_alt; |
4171 | keystate[VK_CAPITAL] = 0; |
4172 | } |
4173 | |
c264be08 |
4174 | /* XXX how do we know what the max size of the keys array should |
4175 | * be is? There's indication on MS' website of an Inquire/InquireEx |
4176 | * functioning returning a KBINFO structure which tells us. */ |
4177 | if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) { |
4178 | /* XXX 'keys' parameter is declared in MSDN documentation as |
4179 | * 'LPWORD lpChar'. |
4180 | * The experience of a French user indicates that on |
4181 | * Win98, WORD[] should be passed in, but on Win2K, it should |
4182 | * be BYTE[]. German WinXP and my Win2K with "US International" |
4183 | * driver corroborate this. |
4184 | * Experimentally I've conditionalised the behaviour on the |
4185 | * Win9x/NT split, but I suspect it's worse than that. |
4186 | * See wishlist item `win-dead-keys' for more horrible detail |
4187 | * and speculations. */ |
4188 | BYTE keybs[3]; |
4189 | int i; |
4190 | r = ToAsciiEx(wParam, scan, keystate, (LPWORD)keybs, 0, kbd_layout); |
4191 | for (i=0; i<3; i++) keys[i] = keybs[i]; |
4192 | } else { |
4193 | r = ToAsciiEx(wParam, scan, keystate, keys, 0, kbd_layout); |
4194 | } |
4eeb7d09 |
4195 | #ifdef SHOW_TOASCII_RESULT |
4196 | if (r == 1 && !key_down) { |
4197 | if (alt_sum) { |
21d2b241 |
4198 | if (in_utf(term) || ucsdata.dbcs_screenfont) |
4eeb7d09 |
4199 | debug((", (U+%04x)", alt_sum)); |
4200 | else |
4201 | debug((", LCH(%d)", alt_sum)); |
4202 | } else { |
4203 | debug((", ACH(%d)", keys[0])); |
4204 | } |
4205 | } else if (r > 0) { |
4206 | int r1; |
4207 | debug((", ASC(")); |
4208 | for (r1 = 0; r1 < r; r1++) { |
4209 | debug(("%s%d", r1 ? "," : "", keys[r1])); |
4210 | } |
4211 | debug((")")); |
4212 | } |
4213 | #endif |
32874aea |
4214 | if (r > 0) { |
4eeb7d09 |
4215 | WCHAR keybuf; |
256cb87c |
4216 | |
4217 | /* |
4218 | * Interrupt an ongoing paste. I'm not sure this is |
4219 | * sensible, but for the moment it's preferable to |
4220 | * having to faff about buffering things. |
4221 | */ |
887035a5 |
4222 | term_nopaste(term); |
256cb87c |
4223 | |
c9def1b8 |
4224 | p = output; |
32874aea |
4225 | for (i = 0; i < r; i++) { |
4226 | unsigned char ch = (unsigned char) keys[i]; |
14963b8f |
4227 | |
32874aea |
4228 | if (compose_state == 2 && (ch & 0x80) == 0 && ch > ' ') { |
c9def1b8 |
4229 | compose_char = ch; |
32874aea |
4230 | compose_state++; |
c9def1b8 |
4231 | continue; |
4232 | } |
32874aea |
4233 | if (compose_state == 3 && (ch & 0x80) == 0 && ch > ' ') { |
c9def1b8 |
4234 | int nc; |
4235 | compose_state = 0; |
4236 | |
32874aea |
4237 | if ((nc = check_compose(compose_char, ch)) == -1) { |
fe50e814 |
4238 | MessageBeep(MB_ICONHAND); |
c9def1b8 |
4239 | return 0; |
4240 | } |
4eeb7d09 |
4241 | keybuf = nc; |
887035a5 |
4242 | term_seen_key_event(term); |
e3be8de5 |
4243 | if (ldisc) |
4244 | luni_send(ldisc, &keybuf, 1, 1); |
4eeb7d09 |
4245 | continue; |
c9def1b8 |
4246 | } |
374330e2 |
4247 | |
c9def1b8 |
4248 | compose_state = 0; |
374330e2 |
4249 | |
4eeb7d09 |
4250 | if (!key_down) { |
4251 | if (alt_sum) { |
21d2b241 |
4252 | if (in_utf(term) || ucsdata.dbcs_screenfont) { |
4eeb7d09 |
4253 | keybuf = alt_sum; |
887035a5 |
4254 | term_seen_key_event(term); |
e3be8de5 |
4255 | if (ldisc) |
4256 | luni_send(ldisc, &keybuf, 1, 1); |
4eeb7d09 |
4257 | } else { |
4258 | ch = (char) alt_sum; |
5471d09a |
4259 | /* |
4260 | * We need not bother about stdin |
4261 | * backlogs here, because in GUI PuTTY |
4262 | * we can't do anything about it |
4263 | * anyway; there's no means of asking |
4264 | * Windows to hold off on KEYDOWN |
4265 | * messages. We _have_ to buffer |
4266 | * everything we're sent. |
4267 | */ |
887035a5 |
4268 | term_seen_key_event(term); |
e3be8de5 |
4269 | if (ldisc) |
4270 | ldisc_send(ldisc, &ch, 1, 1); |
4eeb7d09 |
4271 | } |
4272 | alt_sum = 0; |
405a0c29 |
4273 | } else { |
887035a5 |
4274 | term_seen_key_event(term); |
e3be8de5 |
4275 | if (ldisc) |
4276 | lpage_send(ldisc, kbd_codepage, &ch, 1, 1); |
405a0c29 |
4277 | } |
4eeb7d09 |
4278 | } else { |
a9c02454 |
4279 | if(capsOn && ch < 0x80) { |
4280 | WCHAR cbuf[2]; |
4281 | cbuf[0] = 27; |
4282 | cbuf[1] = xlat_uskbd2cyrllic(ch); |
887035a5 |
4283 | term_seen_key_event(term); |
e3be8de5 |
4284 | if (ldisc) |
4285 | luni_send(ldisc, cbuf+!left_alt, 1+!!left_alt, 1); |
a9c02454 |
4286 | } else { |
4287 | char cbuf[2]; |
4288 | cbuf[0] = '\033'; |
4289 | cbuf[1] = ch; |
887035a5 |
4290 | term_seen_key_event(term); |
e3be8de5 |
4291 | if (ldisc) |
4292 | lpage_send(ldisc, kbd_codepage, |
4293 | cbuf+!left_alt, 1+!!left_alt, 1); |
a9c02454 |
4294 | } |
c9def1b8 |
4295 | } |
bca9517a |
4296 | show_mouseptr(0); |
c9def1b8 |
4297 | } |
374330e2 |
4298 | |
c9def1b8 |
4299 | /* This is so the ALT-Numpad and dead keys work correctly. */ |
4300 | keys[0] = 0; |
4301 | |
32874aea |
4302 | return p - output; |
c9def1b8 |
4303 | } |
159eba53 |
4304 | /* If we're definitly not building up an ALT-54321 then clear it */ |
32874aea |
4305 | if (!left_alt) |
4306 | keys[0] = 0; |
4eeb7d09 |
4307 | /* If we will be using alt_sum fix the 256s */ |
21d2b241 |
4308 | else if (keys[0] && (in_utf(term) || ucsdata.dbcs_screenfont)) |
4eeb7d09 |
4309 | keys[0] = 10; |
374330e2 |
4310 | } |
4311 | |
dfca2656 |
4312 | /* |
4313 | * ALT alone may or may not want to bring up the System menu. |
4314 | * If it's not meant to, we return 0 on presses or releases of |
4315 | * ALT, to show that we've swallowed the keystroke. Otherwise |
4316 | * we return -1, which means Windows will give the keystroke |
4317 | * its default handling (i.e. bring up the System menu). |
4318 | */ |
4319 | if (wParam == VK_MENU && !cfg.alt_only) |
4320 | return 0; |
374330e2 |
4321 | |
c9def1b8 |
4322 | return -1; |
374330e2 |
4323 | } |
4324 | |
a8327734 |
4325 | void request_paste(void *frontend) |
e6346999 |
4326 | { |
4327 | /* |
4328 | * In Windows, pasting is synchronous: we can read the |
4329 | * clipboard with no difficulty, so request_paste() can just go |
4330 | * ahead and paste. |
4331 | */ |
887035a5 |
4332 | term_do_paste(term); |
e6346999 |
4333 | } |
4334 | |
a8327734 |
4335 | void set_title(void *frontend, char *title) |
32874aea |
4336 | { |
4337 | sfree(window_name); |
3d88e64d |
4338 | window_name = snewn(1 + strlen(title), char); |
32874aea |
4339 | strcpy(window_name, title); |
37508af4 |
4340 | if (cfg.win_name_always || !IsIconic(hwnd)) |
32874aea |
4341 | SetWindowText(hwnd, title); |
374330e2 |
4342 | } |
4343 | |
a8327734 |
4344 | void set_icon(void *frontend, char *title) |
32874aea |
4345 | { |
4346 | sfree(icon_name); |
3d88e64d |
4347 | icon_name = snewn(1 + strlen(title), char); |
32874aea |
4348 | strcpy(icon_name, title); |
37508af4 |
4349 | if (!cfg.win_name_always && IsIconic(hwnd)) |
32874aea |
4350 | SetWindowText(hwnd, title); |
374330e2 |
4351 | } |
4352 | |
a8327734 |
4353 | void set_sbar(void *frontend, int total, int start, int page) |
32874aea |
4354 | { |
374330e2 |
4355 | SCROLLINFO si; |
c9def1b8 |
4356 | |
1ba99d2c |
4357 | if (is_full_screen() ? !cfg.scrollbar_in_fullscreen : !cfg.scrollbar) |
32874aea |
4358 | return; |
c9def1b8 |
4359 | |
374330e2 |
4360 | si.cbSize = sizeof(si); |
c9def1b8 |
4361 | si.fMask = SIF_ALL | SIF_DISABLENOSCROLL; |
374330e2 |
4362 | si.nMin = 0; |
4363 | si.nMax = total - 1; |
4364 | si.nPage = page; |
4365 | si.nPos = start; |
c1f5f956 |
4366 | if (hwnd) |
32874aea |
4367 | SetScrollInfo(hwnd, SB_VERT, &si, TRUE); |
374330e2 |
4368 | } |
4369 | |
a8327734 |
4370 | Context get_ctx(void *frontend) |
32874aea |
4371 | { |
374330e2 |
4372 | HDC hdc; |
4373 | if (hwnd) { |
32874aea |
4374 | hdc = GetDC(hwnd); |
374330e2 |
4375 | if (hdc && pal) |
32874aea |
4376 | SelectPalette(hdc, pal, FALSE); |
374330e2 |
4377 | return hdc; |
4378 | } else |
4379 | return NULL; |
4380 | } |
4381 | |
32874aea |
4382 | void free_ctx(Context ctx) |
4383 | { |
4384 | SelectPalette(ctx, GetStockObject(DEFAULT_PALETTE), FALSE); |
4385 | ReleaseDC(hwnd, ctx); |
374330e2 |
4386 | } |
4387 | |
32874aea |
4388 | static void real_palette_set(int n, int r, int g, int b) |
4389 | { |
374330e2 |
4390 | if (pal) { |
4391 | logpal->palPalEntry[n].peRed = r; |
4392 | logpal->palPalEntry[n].peGreen = g; |
4393 | logpal->palPalEntry[n].peBlue = b; |
4394 | logpal->palPalEntry[n].peFlags = PC_NOCOLLAPSE; |
4395 | colours[n] = PALETTERGB(r, g, b); |
cecb13f6 |
4396 | SetPaletteEntries(pal, 0, NALLCOLOURS, logpal->palPalEntry); |
374330e2 |
4397 | } else |
4398 | colours[n] = RGB(r, g, b); |
4399 | } |
4400 | |
a8327734 |
4401 | void palette_set(void *frontend, int n, int r, int g, int b) |
32874aea |
4402 | { |
cecb13f6 |
4403 | if (n >= 16) |
4404 | n += 256 - 16; |
4405 | if (n > NALLCOLOURS) |
4406 | return; |
4407 | real_palette_set(n, r, g, b); |
374330e2 |
4408 | if (pal) { |
a8327734 |
4409 | HDC hdc = get_ctx(frontend); |
32874aea |
4410 | UnrealizeObject(pal); |
4411 | RealizePalette(hdc); |
4412 | free_ctx(hdc); |
374330e2 |
4413 | } |
4414 | } |
4415 | |
a8327734 |
4416 | void palette_reset(void *frontend) |
32874aea |
4417 | { |
374330e2 |
4418 | int i; |
4419 | |
cecb13f6 |
4420 | /* And this */ |
4421 | for (i = 0; i < NALLCOLOURS; i++) { |
374330e2 |
4422 | if (pal) { |
4423 | logpal->palPalEntry[i].peRed = defpal[i].rgbtRed; |
4424 | logpal->palPalEntry[i].peGreen = defpal[i].rgbtGreen; |
4425 | logpal->palPalEntry[i].peBlue = defpal[i].rgbtBlue; |
4426 | logpal->palPalEntry[i].peFlags = 0; |
4427 | colours[i] = PALETTERGB(defpal[i].rgbtRed, |
4428 | defpal[i].rgbtGreen, |
4429 | defpal[i].rgbtBlue); |
4430 | } else |
4431 | colours[i] = RGB(defpal[i].rgbtRed, |
32874aea |
4432 | defpal[i].rgbtGreen, defpal[i].rgbtBlue); |
374330e2 |
4433 | } |
4434 | |
4435 | if (pal) { |
4436 | HDC hdc; |
cecb13f6 |
4437 | SetPaletteEntries(pal, 0, NALLCOLOURS, logpal->palPalEntry); |
a8327734 |
4438 | hdc = get_ctx(frontend); |
32874aea |
4439 | RealizePalette(hdc); |
4440 | free_ctx(hdc); |
374330e2 |
4441 | } |
4442 | } |
4443 | |
a8327734 |
4444 | void write_aclip(void *frontend, char *data, int len, int must_deselect) |
32874aea |
4445 | { |
374330e2 |
4446 | HGLOBAL clipdata; |
4447 | void *lock; |
4448 | |
32874aea |
4449 | clipdata = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, len + 1); |
374330e2 |
4450 | if (!clipdata) |
4451 | return; |
32874aea |
4452 | lock = GlobalLock(clipdata); |
374330e2 |
4453 | if (!lock) |
4454 | return; |
32874aea |
4455 | memcpy(lock, data, len); |
4456 | ((unsigned char *) lock)[len] = 0; |
4457 | GlobalUnlock(clipdata); |
374330e2 |
4458 | |
f0df44da |
4459 | if (!must_deselect) |
32874aea |
4460 | SendMessage(hwnd, WM_IGNORE_CLIP, TRUE, 0); |
f0df44da |
4461 | |
32874aea |
4462 | if (OpenClipboard(hwnd)) { |
374330e2 |
4463 | EmptyClipboard(); |
32874aea |
4464 | SetClipboardData(CF_TEXT, clipdata); |
374330e2 |
4465 | CloseClipboard(); |
4466 | } else |
32874aea |
4467 | GlobalFree(clipdata); |
f0df44da |
4468 | |
4469 | if (!must_deselect) |
32874aea |
4470 | SendMessage(hwnd, WM_IGNORE_CLIP, FALSE, 0); |
374330e2 |
4471 | } |
4472 | |
4eeb7d09 |
4473 | /* |
4474 | * Note: unlike write_aclip() this will not append a nul. |
4475 | */ |
a8327734 |
4476 | void write_clip(void *frontend, wchar_t * data, int len, int must_deselect) |
4eeb7d09 |
4477 | { |
a7419ea4 |
4478 | HGLOBAL clipdata, clipdata2, clipdata3; |
4eeb7d09 |
4479 | int len2; |
a7419ea4 |
4480 | void *lock, *lock2, *lock3; |
4eeb7d09 |
4481 | |
4482 | len2 = WideCharToMultiByte(CP_ACP, 0, data, len, 0, 0, NULL, NULL); |
4483 | |
4484 | clipdata = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, |
4485 | len * sizeof(wchar_t)); |
4486 | clipdata2 = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, len2); |
4487 | |
0e5e7f46 |
4488 | if (!clipdata || !clipdata2) { |
4eeb7d09 |
4489 | if (clipdata) |
4490 | GlobalFree(clipdata); |
4491 | if (clipdata2) |
4492 | GlobalFree(clipdata2); |
4493 | return; |
4494 | } |
4495 | if (!(lock = GlobalLock(clipdata))) |
4496 | return; |
4497 | if (!(lock2 = GlobalLock(clipdata2))) |
4498 | return; |
4499 | |
4500 | memcpy(lock, data, len * sizeof(wchar_t)); |
4501 | WideCharToMultiByte(CP_ACP, 0, data, len, lock2, len2, NULL, NULL); |
4502 | |
a7419ea4 |
4503 | if (cfg.rtf_paste) { |
4504 | wchar_t unitab[256]; |
4505 | char *rtf = NULL; |
4506 | unsigned char *tdata = (unsigned char *)lock2; |
4507 | wchar_t *udata = (wchar_t *)lock; |
4508 | int rtflen = 0, uindex = 0, tindex = 0; |
4509 | int rtfsize = 0; |
4510 | int multilen, blen, alen, totallen, i; |
4511 | char before[16], after[4]; |
4512 | |
4513 | get_unitab(CP_ACP, unitab, 0); |
4514 | |
9a30e26b |
4515 | rtfsize = 100 + strlen(cfg.font.name); |
3d88e64d |
4516 | rtf = snewn(rtfsize, char); |
fd64843f |
4517 | sprintf(rtf, "{\\rtf1\\ansi%d{\\fonttbl\\f0\\fmodern %s;}\\f0 ", |
9a30e26b |
4518 | GetACP(), cfg.font.name); |
a7419ea4 |
4519 | rtflen = strlen(rtf); |
4520 | |
4521 | /* |
4522 | * We want to construct a piece of RTF that specifies the |
4523 | * same Unicode text. To do this we will read back in |
4524 | * parallel from the Unicode data in `udata' and the |
4525 | * non-Unicode data in `tdata'. For each character in |
4526 | * `tdata' which becomes the right thing in `udata' when |
4527 | * looked up in `unitab', we just copy straight over from |
4528 | * tdata. For each one that doesn't, we must WCToMB it |
4529 | * individually and produce a \u escape sequence. |
4530 | * |
4531 | * It would probably be more robust to just bite the bullet |
4532 | * and WCToMB each individual Unicode character one by one, |
4533 | * then MBToWC each one back to see if it was an accurate |
4534 | * translation; but that strikes me as a horrifying number |
4535 | * of Windows API calls so I want to see if this faster way |
4536 | * will work. If it screws up badly we can always revert to |
4537 | * the simple and slow way. |
4538 | */ |
4539 | while (tindex < len2 && uindex < len && |
4540 | tdata[tindex] && udata[uindex]) { |
4541 | if (tindex + 1 < len2 && |
4542 | tdata[tindex] == '\r' && |
4543 | tdata[tindex+1] == '\n') { |
4544 | tindex++; |
4545 | uindex++; |
4546 | } |
4547 | if (unitab[tdata[tindex]] == udata[uindex]) { |
4548 | multilen = 1; |
4549 | before[0] = '\0'; |
4550 | after[0] = '\0'; |
4551 | blen = alen = 0; |
4552 | } else { |
4553 | multilen = WideCharToMultiByte(CP_ACP, 0, unitab+uindex, 1, |
4554 | NULL, 0, NULL, NULL); |
4555 | if (multilen != 1) { |
c3b032a6 |
4556 | blen = sprintf(before, "{\\uc%d\\u%d", multilen, |
4557 | udata[uindex]); |
a7419ea4 |
4558 | alen = 1; strcpy(after, "}"); |
4559 | } else { |
4560 | blen = sprintf(before, "\\u%d", udata[uindex]); |
4561 | alen = 0; after[0] = '\0'; |
4562 | } |
4563 | } |
4564 | assert(tindex + multilen <= len2); |
4565 | totallen = blen + alen; |
4566 | for (i = 0; i < multilen; i++) { |
4567 | if (tdata[tindex+i] == '\\' || |
4568 | tdata[tindex+i] == '{' || |
4569 | tdata[tindex+i] == '}') |
4570 | totallen += 2; |
4571 | else if (tdata[tindex+i] == 0x0D || tdata[tindex+i] == 0x0A) |
4572 | totallen += 6; /* \par\r\n */ |
4573 | else if (tdata[tindex+i] > 0x7E || tdata[tindex+i] < 0x20) |
4574 | totallen += 4; |
4575 | else |
4576 | totallen++; |
4577 | } |
4578 | |
4579 | if (rtfsize < rtflen + totallen + 3) { |
4580 | rtfsize = rtflen + totallen + 512; |
3d88e64d |
4581 | rtf = sresize(rtf, rtfsize, char); |
a7419ea4 |
4582 | } |
4583 | |
4584 | strcpy(rtf + rtflen, before); rtflen += blen; |
4585 | for (i = 0; i < multilen; i++) { |
4586 | if (tdata[tindex+i] == '\\' || |
4587 | tdata[tindex+i] == '{' || |
4588 | tdata[tindex+i] == '}') { |
4589 | rtf[rtflen++] = '\\'; |
4590 | rtf[rtflen++] = tdata[tindex+i]; |
4591 | } else if (tdata[tindex+i] == 0x0D || tdata[tindex+i] == 0x0A) { |
4592 | rtflen += sprintf(rtf+rtflen, "\\par\r\n"); |
4593 | } else if (tdata[tindex+i] > 0x7E || tdata[tindex+i] < 0x20) { |
4594 | rtflen += sprintf(rtf+rtflen, "\\'%02x", tdata[tindex+i]); |
4595 | } else { |
4596 | rtf[rtflen++] = tdata[tindex+i]; |
4597 | } |
4598 | } |
4599 | strcpy(rtf + rtflen, after); rtflen += alen; |
4600 | |
4601 | tindex += multilen; |
4602 | uindex++; |
4603 | } |
4604 | |
4605 | strcpy(rtf + rtflen, "}"); |
4606 | rtflen += 2; |
4607 | |
4608 | clipdata3 = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, rtflen); |
4609 | if (clipdata3 && (lock3 = GlobalLock(clipdata3)) != NULL) { |
4610 | strcpy(lock3, rtf); |
4611 | GlobalUnlock(clipdata3); |
4612 | } |
4613 | sfree(rtf); |
4614 | } else |
4615 | clipdata3 = NULL; |
4616 | |
4eeb7d09 |
4617 | GlobalUnlock(clipdata); |
4618 | GlobalUnlock(clipdata2); |
4619 | |
4620 | if (!must_deselect) |
4621 | SendMessage(hwnd, WM_IGNORE_CLIP, TRUE, 0); |
4622 | |
4623 | if (OpenClipboard(hwnd)) { |
4624 | EmptyClipboard(); |
4625 | SetClipboardData(CF_UNICODETEXT, clipdata); |
4626 | SetClipboardData(CF_TEXT, clipdata2); |
a7419ea4 |
4627 | if (clipdata3) |
4628 | SetClipboardData(RegisterClipboardFormat(CF_RTF), clipdata3); |
4eeb7d09 |
4629 | CloseClipboard(); |
4630 | } else { |
4631 | GlobalFree(clipdata); |
4632 | GlobalFree(clipdata2); |
4633 | } |
4634 | |
4635 | if (!must_deselect) |
4636 | SendMessage(hwnd, WM_IGNORE_CLIP, FALSE, 0); |
4637 | } |
4638 | |
a8327734 |
4639 | void get_clip(void *frontend, wchar_t ** p, int *len) |
32874aea |
4640 | { |
374330e2 |
4641 | static HGLOBAL clipdata = NULL; |
4eeb7d09 |
4642 | static wchar_t *converted = 0; |
4643 | wchar_t *p2; |
374330e2 |
4644 | |
4eeb7d09 |
4645 | if (converted) { |
4646 | sfree(converted); |
4647 | converted = 0; |
4648 | } |
374330e2 |
4649 | if (!p) { |
4650 | if (clipdata) |
32874aea |
4651 | GlobalUnlock(clipdata); |
374330e2 |
4652 | clipdata = NULL; |
4653 | return; |
4eeb7d09 |
4654 | } else if (OpenClipboard(NULL)) { |
2d466ffd |
4655 | if ((clipdata = GetClipboardData(CF_UNICODETEXT))) { |
374330e2 |
4656 | CloseClipboard(); |
4eeb7d09 |
4657 | *p = GlobalLock(clipdata); |
4658 | if (*p) { |
4659 | for (p2 = *p; *p2; p2++); |
4660 | *len = p2 - *p; |
4661 | return; |
374330e2 |
4662 | } |
2d466ffd |
4663 | } else if ( (clipdata = GetClipboardData(CF_TEXT)) ) { |
4eeb7d09 |
4664 | char *s; |
4665 | int i; |
4666 | CloseClipboard(); |
4667 | s = GlobalLock(clipdata); |
4668 | i = MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, 0, 0); |
3d88e64d |
4669 | *p = converted = snewn(i, wchar_t); |
4eeb7d09 |
4670 | MultiByteToWideChar(CP_ACP, 0, s, strlen(s) + 1, converted, i); |
4671 | *len = i - 1; |
4672 | return; |
4673 | } else |
4674 | CloseClipboard(); |
374330e2 |
4675 | } |
4676 | |
4677 | *p = NULL; |
4678 | *len = 0; |
4679 | } |
4680 | |
4eeb7d09 |
4681 | #if 0 |
374330e2 |
4682 | /* |
4683 | * Move `lines' lines from position `from' to position `to' in the |
4684 | * window. |
4685 | */ |
a8327734 |
4686 | void optimised_move(void *frontend, int to, int from, int lines) |
32874aea |
4687 | { |
374330e2 |
4688 | RECT r; |
f67b4e85 |
4689 | int min, max; |
374330e2 |
4690 | |
4691 | min = (to < from ? to : from); |
4692 | max = to + from - min; |
374330e2 |
4693 | |
5a73255e |
4694 | r.left = offset_width; |
887035a5 |
4695 | r.right = offset_width + term->cols * font_width; |
5a73255e |
4696 | r.top = offset_height + min * font_height; |
4697 | r.bottom = offset_height + (max + lines) * font_height; |
32874aea |
4698 | ScrollWindow(hwnd, 0, (to - from) * font_height, &r, &r); |
374330e2 |
4699 | } |
4eeb7d09 |
4700 | #endif |
374330e2 |
4701 | |
4702 | /* |
4703 | * Print a message box and perform a fatal exit. |
4704 | */ |
32874aea |
4705 | void fatalbox(char *fmt, ...) |
4706 | { |
374330e2 |
4707 | va_list ap; |
971bcc0a |
4708 | char *stuff, morestuff[100]; |
374330e2 |
4709 | |
4710 | va_start(ap, fmt); |
971bcc0a |
4711 | stuff = dupvprintf(fmt, ap); |
374330e2 |
4712 | va_end(ap); |
f6f450e2 |
4713 | sprintf(morestuff, "%.70s Fatal Error", appname); |
4714 | MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK); |
971bcc0a |
4715 | sfree(stuff); |
93b581bd |
4716 | cleanup_exit(1); |
374330e2 |
4717 | } |
4718 | |
4719 | /* |
1709795f |
4720 | * Print a modal (Really Bad) message box and perform a fatal exit. |
4721 | */ |
4722 | void modalfatalbox(char *fmt, ...) |
4723 | { |
4724 | va_list ap; |
971bcc0a |
4725 | char *stuff, morestuff[100]; |
1709795f |
4726 | |
4727 | va_start(ap, fmt); |
971bcc0a |
4728 | stuff = dupvprintf(fmt, ap); |
1709795f |
4729 | va_end(ap); |
f6f450e2 |
4730 | sprintf(morestuff, "%.70s Fatal Error", appname); |
4731 | MessageBox(hwnd, stuff, morestuff, |
1709795f |
4732 | MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); |
971bcc0a |
4733 | sfree(stuff); |
1709795f |
4734 | cleanup_exit(1); |
4735 | } |
4736 | |
39934deb |
4737 | static void flash_window(int mode); |
4738 | static long next_flash; |
4739 | static int flashing = 0; |
4740 | |
4741 | static void flash_window_timer(void *ctx, long now) |
4742 | { |
4743 | if (flashing && now - next_flash >= 0) { |
4744 | flash_window(1); |
4745 | } |
4746 | } |
4747 | |
1709795f |
4748 | /* |
f8a28d1f |
4749 | * Manage window caption / taskbar flashing, if enabled. |
4750 | * 0 = stop, 1 = maintain, 2 = start |
4751 | */ |
4752 | static void flash_window(int mode) |
4753 | { |
f8a28d1f |
4754 | if ((mode == 0) || (cfg.beep_ind == B_IND_DISABLED)) { |
4755 | /* stop */ |
4756 | if (flashing) { |
4757 | FlashWindow(hwnd, FALSE); |
4758 | flashing = 0; |
4759 | } |
4760 | |
4761 | } else if (mode == 2) { |
4762 | /* start */ |
4763 | if (!flashing) { |
f8a28d1f |
4764 | flashing = 1; |
4765 | FlashWindow(hwnd, TRUE); |
39934deb |
4766 | next_flash = schedule_timer(450, flash_window_timer, hwnd); |
f8a28d1f |
4767 | } |
4768 | |
4769 | } else if ((mode == 1) && (cfg.beep_ind == B_IND_FLASH)) { |
4770 | /* maintain */ |
4771 | if (flashing) { |
39934deb |
4772 | FlashWindow(hwnd, TRUE); /* toggle */ |
4773 | next_flash = schedule_timer(450, flash_window_timer, hwnd); |
f8a28d1f |
4774 | } |
4775 | } |
4776 | } |
4777 | |
4778 | /* |
374330e2 |
4779 | * Beep. |
4780 | */ |
860a34f8 |
4781 | void do_beep(void *frontend, int mode) |
32874aea |
4782 | { |
03169ad0 |
4783 | if (mode == BELL_DEFAULT) { |
eb04402e |
4784 | /* |
4785 | * For MessageBeep style bells, we want to be careful of |
4786 | * timing, because they don't have the nice property of |
4787 | * PlaySound bells that each one cancels the previous |
4788 | * active one. So we limit the rate to one per 50ms or so. |
4789 | */ |
4790 | static long lastbeep = 0; |
d51cdf1e |
4791 | long beepdiff; |
eb04402e |
4792 | |
d51cdf1e |
4793 | beepdiff = GetTickCount() - lastbeep; |
eb04402e |
4794 | if (beepdiff >= 0 && beepdiff < 50) |
4795 | return; |
156686ef |
4796 | MessageBeep(MB_OK); |
d51cdf1e |
4797 | /* |
4798 | * The above MessageBeep call takes time, so we record the |
4799 | * time _after_ it finishes rather than before it starts. |
4800 | */ |
4801 | lastbeep = GetTickCount(); |
03169ad0 |
4802 | } else if (mode == BELL_WAVEFILE) { |
9a30e26b |
4803 | if (!PlaySound(cfg.bell_wavefile.path, NULL, |
4804 | SND_ASYNC | SND_FILENAME)) { |
850323f9 |
4805 | char buf[sizeof(cfg.bell_wavefile.path) + 80]; |
f6f450e2 |
4806 | char otherbuf[100]; |
03169ad0 |
4807 | sprintf(buf, "Unable to play sound file\n%s\n" |
debe102c |
4808 | "Using default sound instead", cfg.bell_wavefile.path); |
f6f450e2 |
4809 | sprintf(otherbuf, "%.70s Sound Error", appname); |
4810 | MessageBox(hwnd, buf, otherbuf, |
32874aea |
4811 | MB_OK | MB_ICONEXCLAMATION); |
03169ad0 |
4812 | cfg.beep = BELL_DEFAULT; |
4813 | } |
85f6b361 |
4814 | } else if (mode == BELL_PCSPEAKER) { |
4815 | static long lastbeep = 0; |
4816 | long beepdiff; |
4817 | |
4818 | beepdiff = GetTickCount() - lastbeep; |
4819 | if (beepdiff >= 0 && beepdiff < 50) |
4820 | return; |
4821 | |
4822 | /* |
4823 | * We must beep in different ways depending on whether this |
4824 | * is a 95-series or NT-series OS. |
4825 | */ |
4826 | if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) |
4827 | Beep(800, 100); |
4828 | else |
4829 | MessageBeep(-1); |
4830 | lastbeep = GetTickCount(); |
03169ad0 |
4831 | } |
f8a28d1f |
4832 | /* Otherwise, either visual bell or disabled; do nothing here */ |
887035a5 |
4833 | if (!term->has_focus) { |
f8a28d1f |
4834 | flash_window(2); /* start */ |
4835 | } |
374330e2 |
4836 | } |
8f57d753 |
4837 | |
4838 | /* |
68f9b3d9 |
4839 | * Minimise or restore the window in response to a server-side |
4840 | * request. |
4841 | */ |
a8327734 |
4842 | void set_iconic(void *frontend, int iconic) |
68f9b3d9 |
4843 | { |
4844 | if (IsIconic(hwnd)) { |
4845 | if (!iconic) |
4846 | ShowWindow(hwnd, SW_RESTORE); |
4847 | } else { |
4848 | if (iconic) |
4849 | ShowWindow(hwnd, SW_MINIMIZE); |
4850 | } |
4851 | } |
4852 | |
4853 | /* |
4854 | * Move the window in response to a server-side request. |
4855 | */ |
a8327734 |
4856 | void move_window(void *frontend, int x, int y) |
68f9b3d9 |
4857 | { |
d1e0a352 |
4858 | if (cfg.resize_action == RESIZE_DISABLED || |
4859 | cfg.resize_action == RESIZE_FONT || |
4860 | IsZoomed(hwnd)) |
4861 | return; |
4862 | |
68f9b3d9 |
4863 | SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); |
4864 | } |
4865 | |
4866 | /* |
4867 | * Move the window to the top or bottom of the z-order in response |
4868 | * to a server-side request. |
4869 | */ |
a8327734 |
4870 | void set_zorder(void *frontend, int top) |
68f9b3d9 |
4871 | { |
1ba99d2c |
4872 | if (cfg.alwaysontop) |
68f9b3d9 |
4873 | return; /* ignore */ |
4874 | SetWindowPos(hwnd, top ? HWND_TOP : HWND_BOTTOM, 0, 0, 0, 0, |
4875 | SWP_NOMOVE | SWP_NOSIZE); |
4876 | } |
4877 | |
4878 | /* |
4879 | * Refresh the window in response to a server-side request. |
4880 | */ |
a8327734 |
4881 | void refresh_window(void *frontend) |
68f9b3d9 |
4882 | { |
4883 | InvalidateRect(hwnd, NULL, TRUE); |
4884 | } |
4885 | |
4886 | /* |
4887 | * Maximise or restore the window in response to a server-side |
4888 | * request. |
4889 | */ |
a8327734 |
4890 | void set_zoomed(void *frontend, int zoomed) |
68f9b3d9 |
4891 | { |
1ba99d2c |
4892 | if (IsZoomed(hwnd)) { |
4893 | if (!zoomed) |
4894 | ShowWindow(hwnd, SW_RESTORE); |
68f9b3d9 |
4895 | } else { |
4896 | if (zoomed) |
4897 | ShowWindow(hwnd, SW_MAXIMIZE); |
4898 | } |
4899 | } |
4900 | |
4901 | /* |
4902 | * Report whether the window is iconic, for terminal reports. |
4903 | */ |
a8327734 |
4904 | int is_iconic(void *frontend) |
68f9b3d9 |
4905 | { |
4906 | return IsIconic(hwnd); |
4907 | } |
4908 | |
4909 | /* |
4910 | * Report the window's position, for terminal reports. |
4911 | */ |
a8327734 |
4912 | void get_window_pos(void *frontend, int *x, int *y) |
68f9b3d9 |
4913 | { |
4914 | RECT r; |
4915 | GetWindowRect(hwnd, &r); |
4916 | *x = r.left; |
4917 | *y = r.top; |
4918 | } |
4919 | |
4920 | /* |
4921 | * Report the window's pixel size, for terminal reports. |
4922 | */ |
a8327734 |
4923 | void get_window_pixels(void *frontend, int *x, int *y) |
68f9b3d9 |
4924 | { |
4925 | RECT r; |
4926 | GetWindowRect(hwnd, &r); |
4927 | *x = r.right - r.left; |
4928 | *y = r.bottom - r.top; |
4929 | } |
4930 | |
4931 | /* |
4932 | * Return the window or icon title. |
4933 | */ |
a8327734 |
4934 | char *get_window_title(void *frontend, int icon) |
68f9b3d9 |
4935 | { |
4936 | return icon ? icon_name : window_name; |
4937 | } |
1ba99d2c |
4938 | |
4939 | /* |
4940 | * See if we're in full-screen mode. |
4941 | */ |
4e95095a |
4942 | static int is_full_screen() |
1ba99d2c |
4943 | { |
4944 | if (!IsZoomed(hwnd)) |
4945 | return FALSE; |
1e5eefb6 |
4946 | if (GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CAPTION) |
1ba99d2c |
4947 | return FALSE; |
4948 | return TRUE; |
4949 | } |
4950 | |
d0f1bcb4 |
4951 | /* Get the rect/size of a full screen window using the nearest available |
4952 | * monitor in multimon systems; default to something sensible if only |
4953 | * one monitor is present. */ |
4954 | static int get_fullscreen_rect(RECT * ss) |
4955 | { |
5d145a14 |
4956 | #if defined(MONITOR_DEFAULTTONEAREST) && !defined(NO_MULTIMON) |
d0f1bcb4 |
4957 | HMONITOR mon; |
4958 | MONITORINFO mi; |
4959 | mon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); |
4960 | mi.cbSize = sizeof(mi); |
4961 | GetMonitorInfo(mon, &mi); |
4962 | |
4963 | /* structure copy */ |
4964 | *ss = mi.rcMonitor; |
4965 | return TRUE; |
4966 | #else |
4967 | /* could also use code like this: |
4968 | ss->left = ss->top = 0; |
4969 | ss->right = GetSystemMetrics(SM_CXSCREEN); |
4970 | ss->bottom = GetSystemMetrics(SM_CYSCREEN); |
4971 | */ |
e6f8202f |
4972 | return GetClientRect(GetDesktopWindow(), ss); |
d0f1bcb4 |
4973 | #endif |
4974 | } |
4975 | |
4976 | |
1ba99d2c |
4977 | /* |
4978 | * Go full-screen. This should only be called when we are already |
4979 | * maximised. |
4980 | */ |
4e95095a |
4981 | static void make_full_screen() |
1ba99d2c |
4982 | { |
4983 | DWORD style; |
d0f1bcb4 |
4984 | RECT ss; |
1ba99d2c |
4985 | |
4986 | assert(IsZoomed(hwnd)); |
4987 | |
d0f1bcb4 |
4988 | if (is_full_screen()) |
4989 | return; |
4990 | |
1ba99d2c |
4991 | /* Remove the window furniture. */ |
1e5eefb6 |
4992 | style = GetWindowLongPtr(hwnd, GWL_STYLE); |
1ba99d2c |
4993 | style &= ~(WS_CAPTION | WS_BORDER | WS_THICKFRAME); |
4994 | if (cfg.scrollbar_in_fullscreen) |
4995 | style |= WS_VSCROLL; |
4996 | else |
4997 | style &= ~WS_VSCROLL; |
1e5eefb6 |
4998 | SetWindowLongPtr(hwnd, GWL_STYLE, style); |
1ba99d2c |
4999 | |
5000 | /* Resize ourselves to exactly cover the nearest monitor. */ |
d0f1bcb4 |
5001 | get_fullscreen_rect(&ss); |
5002 | SetWindowPos(hwnd, HWND_TOP, ss.left, ss.top, |
5003 | ss.right - ss.left, |
5004 | ss.bottom - ss.top, |
5005 | SWP_FRAMECHANGED); |
1ba99d2c |
5006 | |
5007 | /* Tick the menu item in the System menu. */ |
5008 | CheckMenuItem(GetSystemMenu(hwnd, FALSE), IDM_FULLSCREEN, |
5009 | MF_CHECKED); |
5010 | } |
5011 | |
5012 | /* |
5013 | * Clear the full-screen attributes. |
5014 | */ |
4e95095a |
5015 | static void clear_full_screen() |
1ba99d2c |
5016 | { |
5017 | DWORD oldstyle, style; |
5018 | |
5019 | /* Reinstate the window furniture. */ |
1e5eefb6 |
5020 | style = oldstyle = GetWindowLongPtr(hwnd, GWL_STYLE); |
811f10b3 |
5021 | style |= WS_CAPTION | WS_BORDER; |
5022 | if (cfg.resize_action == RESIZE_DISABLED) |
5023 | style &= ~WS_THICKFRAME; |
5024 | else |
5025 | style |= WS_THICKFRAME; |
1ba99d2c |
5026 | if (cfg.scrollbar) |
5027 | style |= WS_VSCROLL; |
5028 | else |
5029 | style &= ~WS_VSCROLL; |
5030 | if (style != oldstyle) { |
1e5eefb6 |
5031 | SetWindowLongPtr(hwnd, GWL_STYLE, style); |
1ba99d2c |
5032 | SetWindowPos(hwnd, NULL, 0, 0, 0, 0, |
5033 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | |
5034 | SWP_FRAMECHANGED); |
5035 | } |
5036 | |
5037 | /* Untick the menu item in the System menu. */ |
5038 | CheckMenuItem(GetSystemMenu(hwnd, FALSE), IDM_FULLSCREEN, |
5039 | MF_UNCHECKED); |
5040 | } |
5041 | |
5042 | /* |
5043 | * Toggle full-screen mode. |
5044 | */ |
4e95095a |
5045 | static void flip_full_screen() |
1ba99d2c |
5046 | { |
5047 | if (is_full_screen()) { |
5048 | ShowWindow(hwnd, SW_RESTORE); |
5049 | } else if (IsZoomed(hwnd)) { |
5050 | make_full_screen(); |
5051 | } else { |
5052 | SendMessage(hwnd, WM_FULLSCR_ON_MAX, 0, 0); |
5053 | ShowWindow(hwnd, SW_MAXIMIZE); |
5054 | } |
5055 | } |
ab2c86b9 |
5056 | |
b9d7bcad |
5057 | void frontend_keypress(void *handle) |
ab2c86b9 |
5058 | { |
5059 | /* |
5060 | * Keypress termination in non-Close-On-Exit mode is not |
5061 | * currently supported in PuTTY proper, because the window |
5062 | * always has a perfectly good Close button anyway. So we do |
5063 | * nothing here. |
5064 | */ |
5065 | return; |
5066 | } |
fbf6cb3b |
5067 | |
5068 | int from_backend(void *frontend, int is_stderr, const char *data, int len) |
5069 | { |
5070 | return term_data(term, is_stderr, data, len); |
5071 | } |
c44bf5bd |
5072 | |
edd0cb8a |
5073 | int from_backend_untrusted(void *frontend, const char *data, int len) |
5074 | { |
5075 | return term_data_untrusted(term, data, len); |
5076 | } |
5077 | |
5078 | int get_userpass_input(prompts_t *p, unsigned char *in, int inlen) |
5079 | { |
5080 | int ret; |
5081 | ret = cmdline_get_passwd_input(p, in, inlen); |
5082 | if (ret == -1) |
5083 | ret = term_get_userpass_input(term, p, in, inlen); |
5084 | return ret; |
5085 | } |
5086 | |
c44bf5bd |
5087 | void agent_schedule_callback(void (*callback)(void *, void *, int), |
5088 | void *callback_ctx, void *data, int len) |
5089 | { |
5090 | struct agent_callback *c = snew(struct agent_callback); |
5091 | c->callback = callback; |
5092 | c->callback_ctx = callback_ctx; |
5093 | c->data = data; |
5094 | c->len = len; |
5095 | PostMessage(hwnd, WM_AGENT_CALLBACK, 0, (LPARAM)c); |
5096 | } |