2 * window.c - the PuTTY(tel) main program, which runs a PuTTY terminal
3 * emulator and backend in a window.
14 #define COMPILE_MULTIMON_STUBS
17 #define PUTTY_DO_GLOBALS /* actually _define_ globals */
32 /* From MSDN: In the WM_SYSCOMMAND message, the four low-order bits of
33 * wParam are used by Windows, and should be masked off, so we shouldn't
34 * attempt to store information in them. Hence all these identifiers have
35 * the low 4 bits clear. Also, identifiers should < 0xF000. */
37 #define IDM_SHOWLOG 0x0010
38 #define IDM_NEWSESS 0x0020
39 #define IDM_DUPSESS 0x0030
40 #define IDM_RESTART 0x0040
41 #define IDM_RECONF 0x0050
42 #define IDM_CLRSB 0x0060
43 #define IDM_RESET 0x0070
44 #define IDM_HELP 0x0140
45 #define IDM_ABOUT 0x0150
46 #define IDM_SAVEDSESS 0x0160
47 #define IDM_COPYALL 0x0170
48 #define IDM_FULLSCREEN 0x0180
49 #define IDM_PASTE 0x0190
50 #define IDM_SPECIALSEP 0x0200
52 #define IDM_SPECIAL_MIN 0x0400
53 #define IDM_SPECIAL_MAX 0x0800
55 #define IDM_SAVED_MIN 0x1000
56 #define IDM_SAVED_MAX 0x5000
57 #define MENU_SAVED_STEP 16
58 /* Maximum number of sessions on saved-session submenu */
59 #define MENU_SAVED_MAX ((IDM_SAVED_MAX-IDM_SAVED_MIN) / MENU_SAVED_STEP)
61 #define WM_IGNORE_CLIP (WM_APP + 2)
62 #define WM_FULLSCR_ON_MAX (WM_APP + 3)
63 #define WM_AGENT_CALLBACK (WM_APP + 4)
64 #define WM_GOT_CLIPDATA (WM_APP + 6)
66 /* Needed for Chinese support and apparently not always defined. */
68 #define VK_PROCESSKEY 0xE5
71 /* Mouse wheel support. */
73 #define WM_MOUSEWHEEL 0x020A /* not defined in earlier SDKs */
76 #define WHEEL_DELTA 120
79 static Mouse_Button
translate_button(Mouse_Button button
);
80 static LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
81 static int TranslateKey(UINT message
, WPARAM wParam
, LPARAM lParam
,
82 unsigned char *output
);
83 static void conftopalette(void);
84 static void systopalette(void);
85 static void init_palette(void);
86 static void init_fonts(int, int);
87 static void another_font(int);
88 static void deinit_fonts(void);
89 static void set_input_locale(HKL
);
90 static void update_savedsess_menu(void);
91 static void init_flashwindow(void);
93 static int is_full_screen(void);
94 static void make_full_screen(void);
95 static void clear_full_screen(void);
96 static void flip_full_screen(void);
97 static int process_clipdata(HGLOBAL clipdata
, int unicode
);
99 /* Window layout information */
100 static void reset_window(int);
101 static int extra_width
, extra_height
;
102 static int font_width
, font_height
, font_dualwidth
, font_varpitch
;
103 static int offset_width
, offset_height
;
104 static int was_zoomed
= 0;
105 static int prev_rows
, prev_cols
;
107 static int pending_netevent
= 0;
108 static WPARAM pend_netevent_wParam
= 0;
109 static LPARAM pend_netevent_lParam
= 0;
110 static void enact_pending_netevent(void);
111 static void flash_window(int mode
);
112 static void sys_cursor_update(void);
113 static int get_fullscreen_rect(RECT
* ss
);
115 static int caret_x
= -1, caret_y
= -1;
117 static int kbd_codepage
;
120 static Backend
*back
;
121 static void *backhandle
;
123 static struct unicode_data ucsdata
;
124 static int must_close_session
, session_closed
;
125 static int reconfiguring
= FALSE
;
127 static const struct telnet_special
*specials
= NULL
;
128 static HMENU specials_menu
= NULL
;
129 static int n_specials
= 0;
131 static wchar_t *clipboard_contents
;
132 static size_t clipboard_length
;
134 #define TIMING_TIMER_ID 1234
135 static long timing_next_time
;
140 enum { SYSMENU
, CTXMENU
};
141 static HMENU savedsess_menu
;
143 Conf
*conf
; /* exported to windlg.c */
145 static void conf_cache_data(void);
149 static struct sesslist sesslist
; /* for saved-session menu */
151 struct agent_callback
{
152 void (*callback
)(void *, void *, int);
158 #define FONT_NORMAL 0
160 #define FONT_UNDERLINE 2
161 #define FONT_BOLDUND 3
162 #define FONT_WIDE 0x04
163 #define FONT_HIGH 0x08
164 #define FONT_NARROW 0x10
166 #define FONT_OEM 0x20
167 #define FONT_OEMBOLD 0x21
168 #define FONT_OEMUND 0x22
169 #define FONT_OEMBOLDUND 0x23
171 #define FONT_MAXNO 0x2F
173 static HFONT fonts
[FONT_MAXNO
];
174 static LOGFONT lfont
;
175 static int fontflag
[FONT_MAXNO
];
177 BOLD_NONE
, BOLD_SHADOW
, BOLD_FONT
179 static int bold_colours
;
185 #define NCFGCOLOURS 22
186 #define NEXTCOLOURS 240
187 #define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS)
188 static COLORREF colours
[NALLCOLOURS
];
190 static LPLOGPALETTE logpal
;
191 static RGBTRIPLE defpal
[NALLCOLOURS
];
193 static HBITMAP caretbm
;
195 static int dbltime
, lasttime
, lastact
;
196 static Mouse_Button lastbtn
;
198 /* this allows xterm-style mouse handling. */
199 static int send_raw_mouse
= 0;
200 static int wheel_accumulator
= 0;
202 static int busy_status
= BUSY_NOT
;
204 static char *window_name
, *icon_name
;
206 static int compose_state
= 0;
208 static UINT wm_mousewheel
= WM_MOUSEWHEEL
;
210 #define IS_HIGH_VARSEL(wch1, wch2) \
211 ((wch1) == 0xDB40 && ((wch2) >= 0xDD00 && (wch2) <= 0xDDEF))
212 #define IS_LOW_VARSEL(wch) \
213 (((wch) >= 0x180B && (wch) <= 0x180D) || /* MONGOLIAN FREE VARIATION SELECTOR */ \
214 ((wch) >= 0xFE00 && (wch) <= 0xFE0F)) /* VARIATION SELECTOR 1-16 */
216 /* Dummy routine, only required in plink. */
217 void ldisc_update(void *frontend
, int echo
, int edit
)
221 char *get_ttymode(void *frontend
, const char *mode
)
223 return term_get_ttymode(term
, mode
);
226 static void start_backend(void)
229 char msg
[1024], *title
;
234 * Select protocol. This is farmed out into a table in a
235 * separate file to enable an ssh-free variant.
237 back
= backend_from_proto(conf_get_int(conf
, CONF_protocol
));
239 char *str
= dupprintf("%s Internal Error", appname
);
240 MessageBox(NULL
, "Unsupported protocol number found",
241 str
, MB_OK
| MB_ICONEXCLAMATION
);
246 error
= back
->init(NULL
, &backhandle
, conf
,
247 conf_get_str(conf
, CONF_host
),
248 conf_get_int(conf
, CONF_port
),
250 conf_get_int(conf
, CONF_tcp_nodelay
),
251 conf_get_int(conf
, CONF_tcp_keepalives
));
252 back
->provide_logctx(backhandle
, logctx
);
254 char *str
= dupprintf("%s Error", appname
);
255 sprintf(msg
, "Unable to open connection to\n"
256 "%.800s\n" "%s", conf_dest(conf
), error
);
257 MessageBox(NULL
, msg
, str
, MB_ICONERROR
| MB_OK
);
261 window_name
= icon_name
= NULL
;
262 title
= conf_get_str(conf
, CONF_wintitle
);
264 sprintf(msg
, "%s - %s", realhost
, appname
);
268 set_title(NULL
, title
);
269 set_icon(NULL
, title
);
272 * Connect the terminal to the backend for resize purposes.
274 term_provide_resize_fn(term
, back
->size
, backhandle
);
277 * Set up a line discipline.
279 ldisc
= ldisc_create(conf
, term
, back
, backhandle
, NULL
);
282 * Destroy the Restart Session menu item. (This will return
283 * failure if it's already absent, as it will be the very first
284 * time we call this function. We ignore that, because as long
285 * as the menu item ends up not being there, we don't care
286 * whether it was us who removed it or not!)
288 for (i
= 0; i
< lenof(popup_menus
); i
++) {
289 DeleteMenu(popup_menus
[i
].menu
, IDM_RESTART
, MF_BYCOMMAND
);
292 must_close_session
= FALSE
;
293 session_closed
= FALSE
;
296 static void close_session(void)
301 session_closed
= TRUE
;
302 sprintf(morestuff
, "%.70s (inactive)", appname
);
303 set_icon(NULL
, morestuff
);
304 set_title(NULL
, morestuff
);
311 back
->free(backhandle
);
314 term_provide_resize_fn(term
, NULL
, NULL
);
315 update_specials_menu(NULL
);
319 * Show the Restart Session menu item. Do a precautionary
320 * delete first to ensure we never end up with more than one.
322 for (i
= 0; i
< lenof(popup_menus
); i
++) {
323 DeleteMenu(popup_menus
[i
].menu
, IDM_RESTART
, MF_BYCOMMAND
);
324 InsertMenu(popup_menus
[i
].menu
, IDM_DUPSESS
, MF_BYCOMMAND
| MF_ENABLED
,
325 IDM_RESTART
, "&Restart Session");
329 * Unset the 'must_close_session' flag, or else we'll come
330 * straight back here the next time we go round the main message
331 * loop - which, worse still, will be immediately (without
332 * blocking) because we've just triggered a WM_SETTEXT by the
333 * window title change above.
335 must_close_session
= FALSE
;
338 int WINAPI
WinMain(HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
)
343 int guess_width
, guess_height
;
347 flags
= FLAG_VERBOSE
| FLAG_INTERACTIVE
;
351 InitCommonControls();
353 /* Ensure a Maximize setting in Explorer doesn't maximise the
359 char *str
= dupprintf("%s Fatal Error", appname
);
360 MessageBox(NULL
, "Windows refuses to report a version",
361 str
, MB_OK
| MB_ICONEXCLAMATION
);
367 * If we're running a version of Windows that doesn't support
368 * WM_MOUSEWHEEL, find out what message number we should be
371 if (osVersion
.dwMajorVersion
< 4 ||
372 (osVersion
.dwMajorVersion
== 4 &&
373 osVersion
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
))
374 wm_mousewheel
= RegisterWindowMessage("MSWHEEL_ROLLMSG");
385 hr
= CoInitialize(NULL
);
386 if (hr
!= S_OK
&& hr
!= S_FALSE
) {
387 char *str
= dupprintf("%s Fatal Error", appname
);
388 MessageBox(NULL
, "Failed to initialize COM subsystem",
389 str
, MB_OK
| MB_ICONEXCLAMATION
);
395 * Process the command line.
400 /* By default, we bring up the config dialog, rather than launching
401 * a session. This gets set to TRUE if something happens to change
402 * that (e.g., a hostname is specified on the command-line). */
403 int allow_launch
= FALSE
;
405 default_protocol
= be_default_protocol
;
406 /* Find the appropriate default port. */
408 Backend
*b
= backend_from_proto(default_protocol
);
409 default_port
= 0; /* illegal */
411 default_port
= b
->default_port
;
413 conf_set_int(conf
, CONF_logtype
, LGTYP_NONE
);
415 do_defaults(NULL
, conf
);
420 * Process a couple of command-line options which are more
421 * easily dealt with before the line is broken up into words.
422 * These are the old-fashioned but convenient @sessionname and
423 * the internal-use-only &sharedmemoryhandle, neither of which
424 * are combined with anything else.
426 while (*p
&& isspace(*p
))
430 * An initial @ means that the whole of the rest of the
431 * command line should be treated as the name of a saved
432 * session, with _no quoting or escaping_. This makes it a
433 * very convenient means of automated saved-session
434 * launching, via IDM_SAVEDSESS or Windows 7 jump lists.
437 while (i
> 1 && isspace(p
[i
- 1]))
440 do_defaults(p
+ 1, conf
);
441 if (!conf_launchable(conf
) && !do_config()) {
444 allow_launch
= TRUE
; /* allow it to be launched directly */
445 } else if (*p
== '&') {
447 * An initial & means we've been given a command line
448 * containing the hex value of a HANDLE for a file
449 * mapping object, which we must then interpret as a
455 if (sscanf(p
+ 1, "%p:%u", &filemap
, &cpsize
) == 2 &&
456 (cp
= MapViewOfFile(filemap
, FILE_MAP_READ
,
457 0, 0, cpsize
)) != NULL
) {
458 conf_deserialise(conf
, cp
, cpsize
);
460 CloseHandle(filemap
);
461 } else if (!do_config()) {
467 * Otherwise, break up the command line and deal with
473 split_into_argv(cmdline
, &argc
, &argv
, NULL
);
475 for (i
= 0; i
< argc
; i
++) {
479 ret
= cmdline_process_param(p
, i
+1<argc?argv
[i
+1]:NULL
,
482 cmdline_error("option \"%s\" requires an argument", p
);
483 } else if (ret
== 2) {
484 i
++; /* skip next argument */
485 } else if (ret
== 1) {
486 continue; /* nothing further needs doing */
487 } else if (!strcmp(p
, "-cleanup") ||
488 !strcmp(p
, "-cleanup-during-uninstall")) {
490 * `putty -cleanup'. Remove all registry
491 * entries associated with PuTTY, and also find
492 * and delete the random seed file.
495 /* Are we being invoked from an uninstaller? */
496 if (!strcmp(p
, "-cleanup-during-uninstall")) {
497 s1
= dupprintf("Remove saved sessions and random seed file?\n"
499 "If you hit Yes, ALL Registry entries associated\n"
500 "with %s will be removed, as well as the\n"
501 "random seed file. THIS PROCESS WILL\n"
502 "DESTROY YOUR SAVED SESSIONS.\n"
503 "(This only affects the currently logged-in user.)\n"
505 "If you hit No, uninstallation will proceed, but\n"
506 "saved sessions etc will be left on the machine.",
508 s2
= dupprintf("%s Uninstallation", appname
);
510 s1
= dupprintf("This procedure will remove ALL Registry entries\n"
511 "associated with %s, and will also remove\n"
512 "the random seed file. (This only affects the\n"
513 "currently logged-in user.)\n"
515 "THIS PROCESS WILL DESTROY YOUR SAVED SESSIONS.\n"
516 "Are you really sure you want to continue?",
518 s2
= dupprintf("%s Warning", appname
);
520 if (message_box(s1
, s2
,
521 MB_YESNO
| MB_ICONWARNING
| MB_DEFBUTTON2
,
522 HELPCTXID(option_cleanup
)) == IDYES
) {
528 } else if (!strcmp(p
, "-pgpfp")) {
531 } else if (*p
!= '-') {
535 * If we already have a host name, treat
536 * this argument as a port number. NB we
537 * have to treat this as a saved -P
538 * argument, so that it will be deferred
539 * until it's a good moment to run it.
541 int ret
= cmdline_process_param("-P", p
, 1, conf
);
543 } else if (!strncmp(q
, "telnet:", 7)) {
545 * If the hostname starts with "telnet:",
546 * set the protocol to Telnet and process
547 * the string as a Telnet URL.
552 if (q
[0] == '/' && q
[1] == '/')
554 conf_set_int(conf
, CONF_protocol
, PROT_TELNET
);
556 while (*p
&& *p
!= ':' && *p
!= '/')
562 conf_set_int(conf
, CONF_port
, atoi(p
));
564 conf_set_int(conf
, CONF_port
, -1);
565 conf_set_str(conf
, CONF_host
, q
);
569 * Otherwise, treat this argument as a host
572 while (*p
&& !isspace(*p
))
576 conf_set_str(conf
, CONF_host
, q
);
580 cmdline_error("unknown option \"%s\"", p
);
585 cmdline_run_saved(conf
);
587 if (loaded_session
|| got_host
)
590 if ((!allow_launch
|| !conf_launchable(conf
)) && !do_config()) {
595 * Muck about with the hostname in various ways.
598 char *hostbuf
= dupstr(conf_get_str(conf
, CONF_host
));
599 char *host
= hostbuf
;
603 * Trim leading whitespace.
605 host
+= strspn(host
, " \t");
608 * See if host is of the form user@host, and separate
609 * out the username if so.
611 if (host
[0] != '\0') {
612 char *atsign
= strrchr(host
, '@');
615 conf_set_str(conf
, CONF_username
, host
);
621 * Trim off a colon suffix if it's there.
623 host
[strcspn(host
, ":")] = '\0';
626 * Remove any remaining whitespace.
631 if (*q
!= ' ' && *q
!= '\t')
637 conf_set_str(conf
, CONF_host
, hostbuf
);
644 wndclass
.lpfnWndProc
= WndProc
;
645 wndclass
.cbClsExtra
= 0;
646 wndclass
.cbWndExtra
= 0;
647 wndclass
.hInstance
= inst
;
648 wndclass
.hIcon
= LoadIcon(inst
, MAKEINTRESOURCE(IDI_MAINICON
));
649 wndclass
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
650 wndclass
.hbrBackground
= NULL
;
651 wndclass
.lpszMenuName
= NULL
;
652 wndclass
.lpszClassName
= appname
;
654 RegisterClass(&wndclass
);
657 memset(&ucsdata
, 0, sizeof(ucsdata
));
664 * Guess some defaults for the window size. This all gets
665 * updated later, so we don't really care too much. However, we
666 * do want the font width/height guesses to correspond to a
667 * large font rather than a small one...
674 guess_width
= extra_width
+ font_width
* conf_get_int(conf
, CONF_width
);
675 guess_height
= extra_height
+ font_height
*conf_get_int(conf
, CONF_height
);
678 get_fullscreen_rect(&r
);
679 if (guess_width
> r
.right
- r
.left
)
680 guess_width
= r
.right
- r
.left
;
681 if (guess_height
> r
.bottom
- r
.top
)
682 guess_height
= r
.bottom
- r
.top
;
686 int winmode
= WS_OVERLAPPEDWINDOW
| WS_VSCROLL
;
688 if (!conf_get_int(conf
, CONF_scrollbar
))
689 winmode
&= ~(WS_VSCROLL
);
690 if (conf_get_int(conf
, CONF_resize_action
) == RESIZE_DISABLED
)
691 winmode
&= ~(WS_THICKFRAME
| WS_MAXIMIZEBOX
);
692 if (conf_get_int(conf
, CONF_alwaysontop
))
693 exwinmode
|= WS_EX_TOPMOST
;
694 if (conf_get_int(conf
, CONF_sunken_edge
))
695 exwinmode
|= WS_EX_CLIENTEDGE
;
696 hwnd
= CreateWindowEx(exwinmode
, appname
, appname
,
697 winmode
, CW_USEDEFAULT
, CW_USEDEFAULT
,
698 guess_width
, guess_height
,
699 NULL
, NULL
, inst
, NULL
);
703 * Initialise the fonts, simultaneously correcting the guesses
704 * for font_{width,height}.
709 * Initialise the terminal. (We have to do this _after_
710 * creating the window, since the terminal is the first thing
711 * which will call schedule_timer(), which will in turn call
712 * timer_change_notify() which will expect hwnd to exist.)
714 term
= term_init(conf
, &ucsdata
, NULL
);
715 logctx
= log_init(NULL
, conf
);
716 term_provide_logctx(term
, logctx
);
717 term_size(term
, conf_get_int(conf
, CONF_height
),
718 conf_get_int(conf
, CONF_width
),
719 conf_get_int(conf
, CONF_savelines
));
722 * Correct the guesses for extra_{width,height}.
726 GetWindowRect(hwnd
, &wr
);
727 GetClientRect(hwnd
, &cr
);
728 offset_width
= offset_height
= conf_get_int(conf
, CONF_window_border
);
729 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+ offset_width
*2;
730 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
734 * Resize the window, now we know what size we _really_ want it
737 guess_width
= extra_width
+ font_width
* term
->cols
;
738 guess_height
= extra_height
+ font_height
* term
->rows
;
739 SetWindowPos(hwnd
, NULL
, 0, 0, guess_width
, guess_height
,
740 SWP_NOMOVE
| SWP_NOREDRAW
| SWP_NOZORDER
);
743 * Set up a caret bitmap, with no content.
747 int size
= (font_width
+ 15) / 16 * 2 * font_height
;
748 bits
= snewn(size
, char);
749 memset(bits
, 0, size
);
750 caretbm
= CreateBitmap(font_width
, font_height
, 1, 1, bits
);
753 CreateCaret(hwnd
, caretbm
, font_width
, font_height
);
756 * Initialise the scroll bar.
761 si
.cbSize
= sizeof(si
);
762 si
.fMask
= SIF_ALL
| SIF_DISABLENOSCROLL
;
764 si
.nMax
= term
->rows
- 1;
765 si
.nPage
= term
->rows
;
767 SetScrollInfo(hwnd
, SB_VERT
, &si
, FALSE
);
771 * Prepare the mouse handler.
773 lastact
= MA_NOTHING
;
774 lastbtn
= MBT_NOTHING
;
775 dbltime
= GetDoubleClickTime();
778 * Set up the session-control options on the system menu.
785 popup_menus
[SYSMENU
].menu
= GetSystemMenu(hwnd
, FALSE
);
786 popup_menus
[CTXMENU
].menu
= CreatePopupMenu();
787 AppendMenu(popup_menus
[CTXMENU
].menu
, MF_ENABLED
, IDM_PASTE
, "&Paste");
789 savedsess_menu
= CreateMenu();
790 get_sesslist(&sesslist
, TRUE
);
791 update_savedsess_menu();
793 for (j
= 0; j
< lenof(popup_menus
); j
++) {
794 m
= popup_menus
[j
].menu
;
796 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
797 AppendMenu(m
, MF_ENABLED
, IDM_SHOWLOG
, "&Event Log");
798 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
799 AppendMenu(m
, MF_ENABLED
, IDM_NEWSESS
, "Ne&w Session...");
800 AppendMenu(m
, MF_ENABLED
, IDM_DUPSESS
, "&Duplicate Session");
801 AppendMenu(m
, MF_POPUP
| MF_ENABLED
, (UINT
) savedsess_menu
,
803 AppendMenu(m
, MF_ENABLED
, IDM_RECONF
, "Chan&ge Settings...");
804 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
805 AppendMenu(m
, MF_ENABLED
, IDM_COPYALL
, "C&opy All to Clipboard");
806 AppendMenu(m
, MF_ENABLED
, IDM_CLRSB
, "C&lear Scrollback");
807 AppendMenu(m
, MF_ENABLED
, IDM_RESET
, "Rese&t Terminal");
808 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
809 AppendMenu(m
, (conf_get_int(conf
, CONF_resize_action
)
810 == RESIZE_DISABLED
) ? MF_GRAYED
: MF_ENABLED
,
811 IDM_FULLSCREEN
, "&Full Screen");
812 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
814 AppendMenu(m
, MF_ENABLED
, IDM_HELP
, "&Help");
815 str
= dupprintf("&About %s", appname
);
816 AppendMenu(m
, MF_ENABLED
, IDM_ABOUT
, str
);
824 * Set up the initial input locale.
826 set_input_locale(GetKeyboardLayout(0));
829 * Finally show the window!
831 ShowWindow(hwnd
, show
);
832 SetForegroundWindow(hwnd
);
835 * Set the palette up.
841 term_set_focus(term
, GetForegroundWindow() == hwnd
);
848 handles
= handle_get_events(&nhandles
);
850 n
= MsgWaitForMultipleObjects(nhandles
, handles
, FALSE
, INFINITE
,
853 if ((unsigned)(n
- WAIT_OBJECT_0
) < (unsigned)nhandles
) {
854 handle_got_event(handles
[n
- WAIT_OBJECT_0
]);
856 if (must_close_session
)
861 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
862 if (msg
.message
== WM_QUIT
)
863 goto finished
; /* two-level break */
865 if (!(IsWindow(logbox
) && IsDialogMessage(logbox
, &msg
)))
866 DispatchMessage(&msg
);
867 /* Send the paste buffer if there's anything to send */
869 /* If there's nothing new in the queue then we can do everything
870 * we've delayed, reading the socket, writing, and repainting
873 if (must_close_session
)
877 /* The messages seem unreliable; especially if we're being tricky */
878 term_set_focus(term
, GetForegroundWindow() == hwnd
);
880 if (pending_netevent
)
881 enact_pending_netevent();
883 net_pending_errors();
887 cleanup_exit(msg
.wParam
); /* this doesn't return... */
888 return msg
.wParam
; /* ... but optimiser doesn't know */
894 void cleanup_exit(int code
)
905 if (conf_get_int(conf
, CONF_protocol
) == PROT_SSH
) {
920 * Set up, or shut down, an AsyncSelect. Called from winnet.c.
922 char *do_select(SOCKET skt
, int startup
)
927 events
= (FD_CONNECT
| FD_READ
| FD_WRITE
|
928 FD_OOB
| FD_CLOSE
| FD_ACCEPT
);
933 return "do_select(): internal error (hwnd==NULL)";
934 if (p_WSAAsyncSelect(skt
, hwnd
, msg
, events
) == SOCKET_ERROR
) {
935 switch (p_WSAGetLastError()) {
937 return "Network is down";
939 return "WSAAsyncSelect(): unknown error";
946 * Refresh the saved-session submenu from `sesslist'.
948 static void update_savedsess_menu(void)
951 while (DeleteMenu(savedsess_menu
, 0, MF_BYPOSITION
)) ;
952 /* skip sesslist.sessions[0] == Default Settings */
954 i
< ((sesslist
.nsessions
<= MENU_SAVED_MAX
+1) ? sesslist
.nsessions
957 AppendMenu(savedsess_menu
, MF_ENABLED
,
958 IDM_SAVED_MIN
+ (i
-1)*MENU_SAVED_STEP
,
959 sesslist
.sessions
[i
]);
960 if (sesslist
.nsessions
<= 1)
961 AppendMenu(savedsess_menu
, MF_GRAYED
, IDM_SAVED_MIN
, "(No sessions)");
965 * Update the Special Commands submenu.
967 void update_specials_menu(void *frontend
)
973 specials
= back
->get_specials(backhandle
);
978 /* We can't use Windows to provide a stack for submenus, so
979 * here's a lame "stack" that will do for now. */
980 HMENU saved_menu
= NULL
;
982 new_menu
= CreatePopupMenu();
983 for (i
= 0; nesting
> 0; i
++) {
984 assert(IDM_SPECIAL_MIN
+ 0x10 * i
< IDM_SPECIAL_MAX
);
985 switch (specials
[i
].code
) {
987 AppendMenu(new_menu
, MF_SEPARATOR
, 0, 0);
992 saved_menu
= new_menu
; /* XXX lame stacking */
993 new_menu
= CreatePopupMenu();
994 AppendMenu(saved_menu
, MF_POPUP
| MF_ENABLED
,
995 (UINT
) new_menu
, specials
[i
].name
);
1000 new_menu
= saved_menu
; /* XXX lame stacking */
1005 AppendMenu(new_menu
, MF_ENABLED
, IDM_SPECIAL_MIN
+ 0x10 * i
,
1010 /* Squirrel the highest special. */
1017 for (j
= 0; j
< lenof(popup_menus
); j
++) {
1018 if (specials_menu
) {
1019 /* XXX does this free up all submenus? */
1020 DeleteMenu(popup_menus
[j
].menu
, (UINT
)specials_menu
, MF_BYCOMMAND
);
1021 DeleteMenu(popup_menus
[j
].menu
, IDM_SPECIALSEP
, MF_BYCOMMAND
);
1024 InsertMenu(popup_menus
[j
].menu
, IDM_SHOWLOG
,
1025 MF_BYCOMMAND
| MF_POPUP
| MF_ENABLED
,
1026 (UINT
) new_menu
, "S&pecial Command");
1027 InsertMenu(popup_menus
[j
].menu
, IDM_SHOWLOG
,
1028 MF_BYCOMMAND
| MF_SEPARATOR
, IDM_SPECIALSEP
, 0);
1031 specials_menu
= new_menu
;
1034 static void update_mouse_pointer(void)
1037 int force_visible
= FALSE
;
1038 static int forced_visible
= FALSE
;
1039 switch (busy_status
) {
1042 curstype
= IDC_ARROW
;
1044 curstype
= IDC_IBEAM
;
1047 curstype
= IDC_APPSTARTING
; /* this may be an abuse */
1048 force_visible
= TRUE
;
1051 curstype
= IDC_WAIT
;
1052 force_visible
= TRUE
;
1058 HCURSOR cursor
= LoadCursor(NULL
, curstype
);
1059 SetClassLongPtr(hwnd
, GCLP_HCURSOR
, (LONG_PTR
)cursor
);
1060 SetCursor(cursor
); /* force redraw of cursor at current posn */
1062 if (force_visible
!= forced_visible
) {
1063 /* We want some cursor shapes to be visible always.
1064 * Along with show_mouseptr(), this manages the ShowCursor()
1065 * counter such that if we switch back to a non-force_visible
1066 * cursor, the previous visibility state is restored. */
1067 ShowCursor(force_visible
);
1068 forced_visible
= force_visible
;
1072 void set_busy_status(void *frontend
, int status
)
1074 busy_status
= status
;
1075 update_mouse_pointer();
1079 * set or clear the "raw mouse message" mode
1081 void set_raw_mouse_mode(void *frontend
, int activate
)
1083 activate
= activate
&& !conf_get_int(conf
, CONF_no_mouse_rep
);
1084 send_raw_mouse
= activate
;
1085 update_mouse_pointer();
1089 * Print a message box and close the connection.
1091 void connection_fatal(void *frontend
, char *fmt
, ...)
1094 char *stuff
, morestuff
[100];
1097 stuff
= dupvprintf(fmt
, ap
);
1099 sprintf(morestuff
, "%.70s Fatal Error", appname
);
1100 MessageBox(hwnd
, stuff
, morestuff
, MB_ICONERROR
| MB_OK
);
1103 if (conf_get_int(conf
, CONF_close_on_exit
) == FORCE_ON
)
1106 must_close_session
= TRUE
;
1111 * Report an error at the command-line parsing stage.
1113 void cmdline_error(char *fmt
, ...)
1116 char *stuff
, morestuff
[100];
1119 stuff
= dupvprintf(fmt
, ap
);
1121 sprintf(morestuff
, "%.70s Command Line Error", appname
);
1122 MessageBox(hwnd
, stuff
, morestuff
, MB_ICONERROR
| MB_OK
);
1128 * Actually do the job requested by a WM_NETEVENT
1130 static void enact_pending_netevent(void)
1132 static int reentering
= 0;
1133 extern int select_result(WPARAM
, LPARAM
);
1136 return; /* don't unpend the pending */
1138 pending_netevent
= FALSE
;
1141 select_result(pend_netevent_wParam
, pend_netevent_lParam
);
1146 * Copy the colour palette from the configuration data into defpal.
1147 * This is non-trivial because the colour indices are different.
1149 static void conftopalette(void)
1152 static const int ww
[] = {
1153 256, 257, 258, 259, 260, 261,
1154 0, 8, 1, 9, 2, 10, 3, 11,
1155 4, 12, 5, 13, 6, 14, 7, 15
1158 for (i
= 0; i
< 22; i
++) {
1160 defpal
[w
].rgbtRed
= conf_get_int_int(conf
, CONF_colours
, i
*3+0);
1161 defpal
[w
].rgbtGreen
= conf_get_int_int(conf
, CONF_colours
, i
*3+1);
1162 defpal
[w
].rgbtBlue
= conf_get_int_int(conf
, CONF_colours
, i
*3+2);
1164 for (i
= 0; i
< NEXTCOLOURS
; i
++) {
1166 int r
= i
/ 36, g
= (i
/ 6) % 6, b
= i
% 6;
1167 defpal
[i
+16].rgbtRed
= r ? r
* 40 + 55 : 0;
1168 defpal
[i
+16].rgbtGreen
= g ? g
* 40 + 55 : 0;
1169 defpal
[i
+16].rgbtBlue
= b ? b
* 40 + 55 : 0;
1171 int shade
= i
- 216;
1172 shade
= shade
* 10 + 8;
1173 defpal
[i
+16].rgbtRed
= defpal
[i
+16].rgbtGreen
=
1174 defpal
[i
+16].rgbtBlue
= shade
;
1178 /* Override with system colours if appropriate */
1179 if (conf_get_int(conf
, CONF_system_colour
))
1184 * Override bit of defpal with colours from the system.
1185 * (NB that this takes a copy the system colours at the time this is called,
1186 * so subsequent colour scheme changes don't take effect. To fix that we'd
1187 * probably want to be using GetSysColorBrush() and the like.)
1189 static void systopalette(void)
1192 static const struct { int nIndex
; int norm
; int bold
; } or[] =
1194 { COLOR_WINDOWTEXT
, 256, 257 }, /* Default Foreground */
1195 { COLOR_WINDOW
, 258, 259 }, /* Default Background */
1196 { COLOR_HIGHLIGHTTEXT
, 260, 260 }, /* Cursor Text */
1197 { COLOR_HIGHLIGHT
, 261, 261 }, /* Cursor Colour */
1200 for (i
= 0; i
< (sizeof(or)/sizeof(or[0])); i
++) {
1201 COLORREF colour
= GetSysColor(or[i
].nIndex
);
1202 defpal
[or[i
].norm
].rgbtRed
=
1203 defpal
[or[i
].bold
].rgbtRed
= GetRValue(colour
);
1204 defpal
[or[i
].norm
].rgbtGreen
=
1205 defpal
[or[i
].bold
].rgbtGreen
= GetGValue(colour
);
1206 defpal
[or[i
].norm
].rgbtBlue
=
1207 defpal
[or[i
].bold
].rgbtBlue
= GetBValue(colour
);
1212 * Set up the colour palette.
1214 static void init_palette(void)
1217 HDC hdc
= GetDC(hwnd
);
1219 if (conf_get_int(conf
, CONF_try_palette
) &&
1220 GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
) {
1222 * This is a genuine case where we must use smalloc
1223 * because the snew macros can't cope.
1225 logpal
= smalloc(sizeof(*logpal
)
1226 - sizeof(logpal
->palPalEntry
)
1227 + NALLCOLOURS
* sizeof(PALETTEENTRY
));
1228 logpal
->palVersion
= 0x300;
1229 logpal
->palNumEntries
= NALLCOLOURS
;
1230 for (i
= 0; i
< NALLCOLOURS
; i
++) {
1231 logpal
->palPalEntry
[i
].peRed
= defpal
[i
].rgbtRed
;
1232 logpal
->palPalEntry
[i
].peGreen
= defpal
[i
].rgbtGreen
;
1233 logpal
->palPalEntry
[i
].peBlue
= defpal
[i
].rgbtBlue
;
1234 logpal
->palPalEntry
[i
].peFlags
= PC_NOCOLLAPSE
;
1236 pal
= CreatePalette(logpal
);
1238 SelectPalette(hdc
, pal
, FALSE
);
1239 RealizePalette(hdc
);
1240 SelectPalette(hdc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
1243 ReleaseDC(hwnd
, hdc
);
1246 for (i
= 0; i
< NALLCOLOURS
; i
++)
1247 colours
[i
] = PALETTERGB(defpal
[i
].rgbtRed
,
1248 defpal
[i
].rgbtGreen
,
1249 defpal
[i
].rgbtBlue
);
1251 for (i
= 0; i
< NALLCOLOURS
; i
++)
1252 colours
[i
] = RGB(defpal
[i
].rgbtRed
,
1253 defpal
[i
].rgbtGreen
, defpal
[i
].rgbtBlue
);
1257 * This is a wrapper to ExtTextOut() to force Windows to display
1258 * the precise glyphs we give it. Otherwise it would do its own
1259 * bidi and Arabic shaping, and we would end up uncertain which
1260 * characters it had put where.
1262 static void exact_textout(HDC hdc
, int x
, int y
, CONST RECT
*lprc
,
1263 unsigned short *lpString
, UINT cbCount
,
1264 CONST INT
*lpDx
, int opaque
)
1268 * The LCC include files apparently don't supply the
1269 * GCP_RESULTSW type, but we can make do with GCP_RESULTS
1270 * proper: the differences aren't important to us (the only
1271 * variable-width string parameter is one we don't use anyway).
1277 char *buffer
= snewn(cbCount
*2+2, char);
1278 char *classbuffer
= snewn(cbCount
, char);
1279 memset(&gcpr
, 0, sizeof(gcpr
));
1280 memset(buffer
, 0, cbCount
*2+2);
1281 memset(classbuffer
, GCPCLASS_NEUTRAL
, cbCount
);
1283 gcpr
.lStructSize
= sizeof(gcpr
);
1284 gcpr
.lpGlyphs
= (void *)buffer
;
1285 gcpr
.lpClass
= (void *)classbuffer
;
1286 gcpr
.nGlyphs
= cbCount
;
1287 GetCharacterPlacementW(hdc
, lpString
, cbCount
, 0, &gcpr
,
1288 FLI_MASK
| GCP_CLASSIN
| GCP_DIACRITIC
);
1290 ExtTextOut(hdc
, x
, y
,
1291 ETO_GLYPH_INDEX
| ETO_CLIPPED
| (opaque ? ETO_OPAQUE
: 0),
1292 lprc
, buffer
, cbCount
, lpDx
);
1296 * The exact_textout() wrapper, unfortunately, destroys the useful
1297 * Windows `font linking' behaviour: automatic handling of Unicode
1298 * code points not supported in this font by falling back to a font
1299 * which does contain them. Therefore, we adopt a multi-layered
1300 * approach: for any potentially-bidi text, we use exact_textout(),
1301 * and for everything else we use a simple ExtTextOut as we did
1302 * before exact_textout() was introduced.
1304 static void general_textout(HDC hdc
, int x
, int y
, CONST RECT
*lprc
,
1305 unsigned short *lpString
, UINT cbCount
,
1306 CONST INT
*lpDx
, int opaque
)
1309 int bkmode
= 0, got_bkmode
= FALSE
;
1313 for (i
= 0; i
< (int)cbCount
;) {
1314 int rtl
= is_rtl(lpString
[i
]);
1318 for (j
= i
+1; j
< (int)cbCount
; j
++) {
1319 if (rtl
!= is_rtl(lpString
[j
]))
1325 * Now [i,j) indicates a maximal substring of lpString
1326 * which should be displayed using the same textout
1330 exact_textout(hdc
, xp
, y
, lprc
, lpString
+i
, j
-i
,
1331 font_varpitch ? NULL
: lpDx
+i
, opaque
);
1333 ExtTextOutW(hdc
, xp
, y
, ETO_CLIPPED
| (opaque ? ETO_OPAQUE
: 0),
1334 lprc
, lpString
+i
, j
-i
,
1335 font_varpitch ? NULL
: lpDx
+i
);
1341 bkmode
= GetBkMode(hdc
);
1343 SetBkMode(hdc
, TRANSPARENT
);
1348 SetBkMode(hdc
, bkmode
);
1351 static int get_font_width(HDC hdc
, const TEXTMETRIC
*tm
)
1354 /* Note that the TMPF_FIXED_PITCH bit is defined upside down :-( */
1355 if (!(tm
->tmPitchAndFamily
& TMPF_FIXED_PITCH
)) {
1356 ret
= tm
->tmAveCharWidth
;
1360 ABCFLOAT widths
[LAST
-FIRST
+ 1];
1363 font_varpitch
= TRUE
;
1364 font_dualwidth
= TRUE
;
1365 if (GetCharABCWidthsFloat(hdc
, FIRST
, LAST
, widths
)) {
1367 for (j
= 0; j
< lenof(widths
); j
++) {
1368 int width
= (int)(0.5 + widths
[j
].abcfA
+
1369 widths
[j
].abcfB
+ widths
[j
].abcfC
);
1374 ret
= tm
->tmMaxCharWidth
;
1383 * Initialise all the fonts we will need initially. There may be as many as
1384 * three or as few as one. The other (potentially) twenty-one fonts are done
1385 * if/when they are needed.
1389 * - check the font width and height, correcting our guesses if
1392 * - verify that the bold font is the same width as the ordinary
1393 * one, and engage shadow bolding if not.
1395 * - verify that the underlined font is the same width as the
1396 * ordinary one (manual underlining by means of line drawing can
1397 * be done in a pinch).
1399 static void init_fonts(int pick_width
, int pick_height
)
1408 int fw_dontcare
, fw_bold
;
1410 for (i
= 0; i
< FONT_MAXNO
; i
++)
1413 bold_font_mode
= conf_get_int(conf
, CONF_bold_style
) & 1 ?
1414 BOLD_FONT
: BOLD_NONE
;
1415 bold_colours
= conf_get_int(conf
, CONF_bold_style
) & 2 ? TRUE
: FALSE
;
1416 und_mode
= UND_FONT
;
1418 font
= conf_get_fontspec(conf
, CONF_font
);
1420 fw_dontcare
= FW_BOLD
;
1423 fw_dontcare
= FW_DONTCARE
;
1430 font_height
= pick_height
;
1432 font_height
= font
->height
;
1433 if (font_height
> 0) {
1435 -MulDiv(font_height
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1438 font_width
= pick_width
;
1440 quality
= conf_get_int(conf
, CONF_font_quality
);
1441 #define f(i,c,w,u) \
1442 fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \
1443 c, OUT_DEFAULT_PRECIS, \
1444 CLIP_DEFAULT_PRECIS, FONT_QUALITY(quality), \
1445 FIXED_PITCH | FF_DONTCARE, font->name)
1447 f(FONT_NORMAL
, font
->charset
, fw_dontcare
, FALSE
);
1449 SelectObject(hdc
, fonts
[FONT_NORMAL
]);
1450 GetTextMetrics(hdc
, &tm
);
1452 GetObject(fonts
[FONT_NORMAL
], sizeof(LOGFONT
), &lfont
);
1454 /* Note that the TMPF_FIXED_PITCH bit is defined upside down :-( */
1455 if (!(tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)) {
1456 font_varpitch
= FALSE
;
1457 font_dualwidth
= (tm
.tmAveCharWidth
!= tm
.tmMaxCharWidth
);
1459 font_varpitch
= TRUE
;
1460 font_dualwidth
= TRUE
;
1462 if (pick_width
== 0 || pick_height
== 0) {
1463 font_height
= tm
.tmHeight
;
1464 font_width
= get_font_width(hdc
, &tm
);
1467 #ifdef RDB_DEBUG_PATCH
1468 debug(23, "Primary font H=%d, AW=%d, MW=%d",
1469 tm
.tmHeight
, tm
.tmAveCharWidth
, tm
.tmMaxCharWidth
);
1474 DWORD cset
= tm
.tmCharSet
;
1475 memset(&info
, 0xFF, sizeof(info
));
1477 /* !!! Yes the next line is right */
1478 if (cset
== OEM_CHARSET
)
1479 ucsdata
.font_codepage
= GetOEMCP();
1481 if (TranslateCharsetInfo ((DWORD
*) cset
, &info
, TCI_SRCCHARSET
))
1482 ucsdata
.font_codepage
= info
.ciACP
;
1484 ucsdata
.font_codepage
= -1;
1486 GetCPInfo(ucsdata
.font_codepage
, &cpinfo
);
1487 ucsdata
.dbcs_screenfont
= (cpinfo
.MaxCharSize
> 1);
1490 f(FONT_UNDERLINE
, font
->charset
, fw_dontcare
, TRUE
);
1493 * Some fonts, e.g. 9-pt Courier, draw their underlines
1494 * outside their character cell. We successfully prevent
1495 * screen corruption by clipping the text output, but then
1496 * we lose the underline completely. Here we try to work
1497 * out whether this is such a font, and if it is, we set a
1498 * flag that causes underlines to be drawn by hand.
1500 * Having tried other more sophisticated approaches (such
1501 * as examining the TEXTMETRIC structure or requesting the
1502 * height of a string), I think we'll do this the brute
1503 * force way: we create a small bitmap, draw an underlined
1504 * space on it, and test to see whether any pixels are
1505 * foreground-coloured. (Since we expect the underline to
1506 * go all the way across the character cell, we only search
1507 * down a single column of the bitmap, half way across.)
1511 HBITMAP und_bm
, und_oldbm
;
1515 und_dc
= CreateCompatibleDC(hdc
);
1516 und_bm
= CreateCompatibleBitmap(hdc
, font_width
, font_height
);
1517 und_oldbm
= SelectObject(und_dc
, und_bm
);
1518 SelectObject(und_dc
, fonts
[FONT_UNDERLINE
]);
1519 SetTextAlign(und_dc
, TA_TOP
| TA_LEFT
| TA_NOUPDATECP
);
1520 SetTextColor(und_dc
, RGB(255, 255, 255));
1521 SetBkColor(und_dc
, RGB(0, 0, 0));
1522 SetBkMode(und_dc
, OPAQUE
);
1523 ExtTextOut(und_dc
, 0, 0, ETO_OPAQUE
, NULL
, " ", 1, NULL
);
1525 for (i
= 0; i
< font_height
; i
++) {
1526 c
= GetPixel(und_dc
, font_width
/ 2, i
);
1527 if (c
!= RGB(0, 0, 0))
1530 SelectObject(und_dc
, und_oldbm
);
1531 DeleteObject(und_bm
);
1534 und_mode
= UND_LINE
;
1535 DeleteObject(fonts
[FONT_UNDERLINE
]);
1536 fonts
[FONT_UNDERLINE
] = 0;
1540 if (bold_font_mode
== BOLD_FONT
) {
1541 f(FONT_BOLD
, font
->charset
, fw_bold
, FALSE
);
1545 descent
= tm
.tmAscent
+ 1;
1546 if (descent
>= font_height
)
1547 descent
= font_height
- 1;
1549 for (i
= 0; i
< 3; i
++) {
1551 if (SelectObject(hdc
, fonts
[i
]) && GetTextMetrics(hdc
, &tm
))
1552 fontsize
[i
] = get_font_width(hdc
, &tm
) + 256 * tm
.tmHeight
;
1559 ReleaseDC(hwnd
, hdc
);
1561 if (fontsize
[FONT_UNDERLINE
] != fontsize
[FONT_NORMAL
]) {
1562 und_mode
= UND_LINE
;
1563 DeleteObject(fonts
[FONT_UNDERLINE
]);
1564 fonts
[FONT_UNDERLINE
] = 0;
1567 if (bold_font_mode
== BOLD_FONT
&&
1568 fontsize
[FONT_BOLD
] != fontsize
[FONT_NORMAL
]) {
1569 bold_font_mode
= BOLD_SHADOW
;
1570 DeleteObject(fonts
[FONT_BOLD
]);
1571 fonts
[FONT_BOLD
] = 0;
1573 fontflag
[0] = fontflag
[1] = fontflag
[2] = 1;
1575 init_ucs(conf
, &ucsdata
);
1578 static void another_font(int fontno
)
1581 int fw_dontcare
, fw_bold
, quality
;
1586 if (fontno
< 0 || fontno
>= FONT_MAXNO
|| fontflag
[fontno
])
1589 basefont
= (fontno
& ~(FONT_BOLDUND
));
1590 if (basefont
!= fontno
&& !fontflag
[basefont
])
1591 another_font(basefont
);
1593 font
= conf_get_fontspec(conf
, CONF_font
);
1596 fw_dontcare
= FW_BOLD
;
1599 fw_dontcare
= FW_DONTCARE
;
1609 if (fontno
& FONT_WIDE
)
1611 if (fontno
& FONT_NARROW
)
1613 if (fontno
& FONT_OEM
)
1615 if (fontno
& FONT_BOLD
)
1617 if (fontno
& FONT_UNDERLINE
)
1620 quality
= conf_get_int(conf
, CONF_font_quality
);
1623 CreateFont(font_height
* (1 + !!(fontno
& FONT_HIGH
)), x
, 0, 0, w
,
1624 FALSE
, u
, FALSE
, c
, OUT_DEFAULT_PRECIS
,
1625 CLIP_DEFAULT_PRECIS
, FONT_QUALITY(quality
),
1626 DEFAULT_PITCH
| FF_DONTCARE
, s
);
1628 fontflag
[fontno
] = 1;
1631 static void deinit_fonts(void)
1634 for (i
= 0; i
< FONT_MAXNO
; i
++) {
1636 DeleteObject(fonts
[i
]);
1642 void request_resize(void *frontend
, int w
, int h
)
1646 /* If the window is maximized supress resizing attempts */
1647 if (IsZoomed(hwnd
)) {
1648 if (conf_get_int(conf
, CONF_resize_action
) == RESIZE_TERM
)
1652 if (conf_get_int(conf
, CONF_resize_action
) == RESIZE_DISABLED
) return;
1653 if (h
== term
->rows
&& w
== term
->cols
) return;
1655 /* Sanity checks ... */
1657 static int first_time
= 1;
1660 switch (first_time
) {
1662 /* Get the size of the screen */
1663 if (get_fullscreen_rect(&ss
))
1664 /* first_time = 0 */ ;
1670 /* Make sure the values are sane */
1671 width
= (ss
.right
- ss
.left
- extra_width
) / 4;
1672 height
= (ss
.bottom
- ss
.top
- extra_height
) / 6;
1674 if (w
> width
|| h
> height
)
1683 term_size(term
, h
, w
, conf_get_int(conf
, CONF_savelines
));
1685 if (conf_get_int(conf
, CONF_resize_action
) != RESIZE_FONT
&&
1687 width
= extra_width
+ font_width
* w
;
1688 height
= extra_height
+ font_height
* h
;
1690 SetWindowPos(hwnd
, NULL
, 0, 0, width
, height
,
1691 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1692 SWP_NOMOVE
| SWP_NOZORDER
);
1696 InvalidateRect(hwnd
, NULL
, TRUE
);
1699 static void reset_window(int reinit
) {
1701 * This function decides how to resize or redraw when the
1702 * user changes something.
1704 * This function doesn't like to change the terminal size but if the
1705 * font size is locked that may be it's only soluion.
1707 int win_width
, win_height
, resize_action
, window_border
;
1710 #ifdef RDB_DEBUG_PATCH
1711 debug((27, "reset_window()"));
1714 /* Current window sizes ... */
1715 GetWindowRect(hwnd
, &wr
);
1716 GetClientRect(hwnd
, &cr
);
1718 win_width
= cr
.right
- cr
.left
;
1719 win_height
= cr
.bottom
- cr
.top
;
1721 resize_action
= conf_get_int(conf
, CONF_resize_action
);
1722 window_border
= conf_get_int(conf
, CONF_window_border
);
1724 if (resize_action
== RESIZE_DISABLED
)
1727 /* Are we being forced to reload the fonts ? */
1729 #ifdef RDB_DEBUG_PATCH
1730 debug((27, "reset_window() -- Forced deinit"));
1736 /* Oh, looks like we're minimised */
1737 if (win_width
== 0 || win_height
== 0)
1740 /* Is the window out of position ? */
1742 (offset_width
!= (win_width
-font_width
*term
->cols
)/2 ||
1743 offset_height
!= (win_height
-font_height
*term
->rows
)/2) ){
1744 offset_width
= (win_width
-font_width
*term
->cols
)/2;
1745 offset_height
= (win_height
-font_height
*term
->rows
)/2;
1746 InvalidateRect(hwnd
, NULL
, TRUE
);
1747 #ifdef RDB_DEBUG_PATCH
1748 debug((27, "reset_window() -> Reposition terminal"));
1752 if (IsZoomed(hwnd
)) {
1753 /* We're fullscreen, this means we must not change the size of
1754 * the window so it's the font size or the terminal itself.
1757 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
;
1758 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
;
1760 if (resize_action
!= RESIZE_TERM
) {
1761 if (font_width
!= win_width
/term
->cols
||
1762 font_height
!= win_height
/term
->rows
) {
1764 init_fonts(win_width
/term
->cols
, win_height
/term
->rows
);
1765 offset_width
= (win_width
-font_width
*term
->cols
)/2;
1766 offset_height
= (win_height
-font_height
*term
->rows
)/2;
1767 InvalidateRect(hwnd
, NULL
, TRUE
);
1768 #ifdef RDB_DEBUG_PATCH
1769 debug((25, "reset_window() -> Z font resize to (%d, %d)",
1770 font_width
, font_height
));
1774 if (font_width
* term
->cols
!= win_width
||
1775 font_height
* term
->rows
!= win_height
) {
1776 /* Our only choice at this point is to change the
1777 * size of the terminal; Oh well.
1779 term_size(term
, win_height
/font_height
, win_width
/font_width
,
1780 conf_get_int(conf
, CONF_savelines
));
1781 offset_width
= (win_width
-font_width
*term
->cols
)/2;
1782 offset_height
= (win_height
-font_height
*term
->rows
)/2;
1783 InvalidateRect(hwnd
, NULL
, TRUE
);
1784 #ifdef RDB_DEBUG_PATCH
1785 debug((27, "reset_window() -> Zoomed term_size"));
1792 /* Hmm, a force re-init means we should ignore the current window
1793 * so we resize to the default font size.
1796 #ifdef RDB_DEBUG_PATCH
1797 debug((27, "reset_window() -> Forced re-init"));
1800 offset_width
= offset_height
= window_border
;
1801 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+ offset_width
*2;
1802 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
1804 if (win_width
!= font_width
*term
->cols
+ offset_width
*2 ||
1805 win_height
!= font_height
*term
->rows
+ offset_height
*2) {
1807 /* If this is too large windows will resize it to the maximum
1808 * allowed window size, we will then be back in here and resize
1809 * the font or terminal to fit.
1811 SetWindowPos(hwnd
, NULL
, 0, 0,
1812 font_width
*term
->cols
+ extra_width
,
1813 font_height
*term
->rows
+ extra_height
,
1814 SWP_NOMOVE
| SWP_NOZORDER
);
1817 InvalidateRect(hwnd
, NULL
, TRUE
);
1821 /* Okay the user doesn't want us to change the font so we try the
1822 * window. But that may be too big for the screen which forces us
1823 * to change the terminal.
1825 if ((resize_action
== RESIZE_TERM
&& reinit
<=0) ||
1826 (resize_action
== RESIZE_EITHER
&& reinit
<0) ||
1828 offset_width
= offset_height
= window_border
;
1829 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+ offset_width
*2;
1830 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
1832 if (win_width
!= font_width
*term
->cols
+ offset_width
*2 ||
1833 win_height
!= font_height
*term
->rows
+ offset_height
*2) {
1838 get_fullscreen_rect(&ss
);
1840 width
= (ss
.right
- ss
.left
- extra_width
) / font_width
;
1841 height
= (ss
.bottom
- ss
.top
- extra_height
) / font_height
;
1844 if ( term
->rows
> height
|| term
->cols
> width
) {
1845 if (resize_action
== RESIZE_EITHER
) {
1846 /* Make the font the biggest we can */
1847 if (term
->cols
> width
)
1848 font_width
= (ss
.right
- ss
.left
- extra_width
)
1850 if (term
->rows
> height
)
1851 font_height
= (ss
.bottom
- ss
.top
- extra_height
)
1855 init_fonts(font_width
, font_height
);
1857 width
= (ss
.right
- ss
.left
- extra_width
) / font_width
;
1858 height
= (ss
.bottom
- ss
.top
- extra_height
) / font_height
;
1860 if ( height
> term
->rows
) height
= term
->rows
;
1861 if ( width
> term
->cols
) width
= term
->cols
;
1862 term_size(term
, height
, width
,
1863 conf_get_int(conf
, CONF_savelines
));
1864 #ifdef RDB_DEBUG_PATCH
1865 debug((27, "reset_window() -> term resize to (%d,%d)",
1871 SetWindowPos(hwnd
, NULL
, 0, 0,
1872 font_width
*term
->cols
+ extra_width
,
1873 font_height
*term
->rows
+ extra_height
,
1874 SWP_NOMOVE
| SWP_NOZORDER
);
1876 InvalidateRect(hwnd
, NULL
, TRUE
);
1877 #ifdef RDB_DEBUG_PATCH
1878 debug((27, "reset_window() -> window resize to (%d,%d)",
1879 font_width
*term
->cols
+ extra_width
,
1880 font_height
*term
->rows
+ extra_height
));
1886 /* We're allowed to or must change the font but do we want to ? */
1888 if (font_width
!= (win_width
-window_border
*2)/term
->cols
||
1889 font_height
!= (win_height
-window_border
*2)/term
->rows
) {
1892 init_fonts((win_width
-window_border
*2)/term
->cols
,
1893 (win_height
-window_border
*2)/term
->rows
);
1894 offset_width
= (win_width
-font_width
*term
->cols
)/2;
1895 offset_height
= (win_height
-font_height
*term
->rows
)/2;
1897 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+offset_width
*2;
1898 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
1900 InvalidateRect(hwnd
, NULL
, TRUE
);
1901 #ifdef RDB_DEBUG_PATCH
1902 debug((25, "reset_window() -> font resize to (%d,%d)",
1903 font_width
, font_height
));
1908 static void set_input_locale(HKL kl
)
1912 GetLocaleInfo(LOWORD(kl
), LOCALE_IDEFAULTANSICODEPAGE
,
1913 lbuf
, sizeof(lbuf
));
1915 kbd_codepage
= atoi(lbuf
);
1918 static void click(Mouse_Button b
, int x
, int y
, int shift
, int ctrl
, int alt
)
1920 int thistime
= GetMessageTime();
1922 if (send_raw_mouse
&&
1923 !(shift
&& conf_get_int(conf
, CONF_mouse_override
))) {
1924 lastbtn
= MBT_NOTHING
;
1925 term_mouse(term
, b
, translate_button(b
), MA_CLICK
,
1926 x
, y
, shift
, ctrl
, alt
);
1930 if (lastbtn
== b
&& thistime
- lasttime
< dbltime
) {
1931 lastact
= (lastact
== MA_CLICK ? MA_2CLK
:
1932 lastact
== MA_2CLK ? MA_3CLK
:
1933 lastact
== MA_3CLK ? MA_CLICK
: MA_NOTHING
);
1938 if (lastact
!= MA_NOTHING
)
1939 term_mouse(term
, b
, translate_button(b
), lastact
,
1940 x
, y
, shift
, ctrl
, alt
);
1941 lasttime
= thistime
;
1945 * Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT)
1946 * into a cooked one (SELECT, EXTEND, PASTE).
1948 static Mouse_Button
translate_button(Mouse_Button button
)
1950 if (button
== MBT_LEFT
)
1952 if (button
== MBT_MIDDLE
)
1953 return conf_get_int(conf
, CONF_mouse_is_xterm
) == 1 ?
1954 MBT_PASTE
: MBT_EXTEND
;
1955 if (button
== MBT_RIGHT
)
1956 return conf_get_int(conf
, CONF_mouse_is_xterm
) == 1 ?
1957 MBT_EXTEND
: MBT_PASTE
;
1958 return 0; /* shouldn't happen */
1961 static void show_mouseptr(int show
)
1963 /* NB that the counter in ShowCursor() is also frobbed by
1964 * update_mouse_pointer() */
1965 static int cursor_visible
= 1;
1966 if (!conf_get_int(conf
, CONF_hide_mouseptr
))
1967 show
= 1; /* override if this feature disabled */
1968 if (cursor_visible
&& !show
)
1970 else if (!cursor_visible
&& show
)
1972 cursor_visible
= show
;
1975 static int is_alt_pressed(void)
1978 int r
= GetKeyboardState(keystate
);
1981 if (keystate
[VK_MENU
] & 0x80)
1983 if (keystate
[VK_RMENU
] & 0x80)
1988 static int resizing
;
1990 void notify_remote_exit(void *fe
)
1992 int exitcode
, close_on_exit
;
1994 if (!session_closed
&&
1995 (exitcode
= back
->exitcode(backhandle
)) >= 0) {
1996 close_on_exit
= conf_get_int(conf
, CONF_close_on_exit
);
1997 /* Abnormal exits will already have set session_closed and taken
1998 * appropriate action. */
1999 if (close_on_exit
== FORCE_ON
||
2000 (close_on_exit
== AUTO
&& exitcode
!= INT_MAX
)) {
2003 must_close_session
= TRUE
;
2004 session_closed
= TRUE
;
2005 /* exitcode == INT_MAX indicates that the connection was closed
2006 * by a fatal error, so an error box will be coming our way and
2007 * we should not generate this informational one. */
2008 if (exitcode
!= INT_MAX
)
2009 MessageBox(hwnd
, "Connection closed by remote host",
2010 appname
, MB_OK
| MB_ICONINFORMATION
);
2015 void timer_change_notify(unsigned long next
)
2017 unsigned long now
= GETTICKCOUNT();
2019 if (now
- next
< INT_MAX
)
2023 KillTimer(hwnd
, TIMING_TIMER_ID
);
2024 SetTimer(hwnd
, TIMING_TIMER_ID
, ticks
, NULL
);
2025 timing_next_time
= next
;
2028 static void conf_cache_data(void)
2030 /* Cache some items from conf to speed lookups in very hot code */
2031 cursor_type
= conf_get_int(conf
, CONF_cursor_type
);
2032 vtmode
= conf_get_int(conf
, CONF_vtmode
);
2035 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
,
2036 WPARAM wParam
, LPARAM lParam
)
2039 static int ignore_clip
= FALSE
;
2040 static int need_backend_resize
= FALSE
;
2041 static int fullscr_on_max
= FALSE
;
2042 static int processed_resize
= FALSE
;
2043 static UINT last_mousemove
= 0;
2048 if ((UINT_PTR
)wParam
== TIMING_TIMER_ID
) {
2051 KillTimer(hwnd
, TIMING_TIMER_ID
);
2052 if (run_timers(timing_next_time
, &next
)) {
2053 timer_change_notify(next
);
2064 str
= dupprintf("%s Exit Confirmation", appname
);
2065 if (session_closed
|| !conf_get_int(conf
, CONF_warn_on_close
) ||
2067 "Are you sure you want to close this session?",
2068 str
, MB_ICONWARNING
| MB_OKCANCEL
| MB_DEFBUTTON1
)
2070 DestroyWindow(hwnd
);
2078 case WM_INITMENUPOPUP
:
2079 if ((HMENU
)wParam
== savedsess_menu
) {
2080 /* About to pop up Saved Sessions sub-menu.
2081 * Refresh the session list. */
2082 get_sesslist(&sesslist
, FALSE
); /* free */
2083 get_sesslist(&sesslist
, TRUE
);
2084 update_savedsess_menu();
2090 switch (wParam
& ~0xF) { /* low 4 bits reserved to Windows */
2101 BOOL inherit_handles
;
2103 PROCESS_INFORMATION pi
;
2104 HANDLE filemap
= NULL
;
2106 if (wParam
== IDM_DUPSESS
) {
2108 * Allocate a file-mapping memory chunk for the
2111 SECURITY_ATTRIBUTES sa
;
2115 size
= conf_serialised_size(conf
);
2117 sa
.nLength
= sizeof(sa
);
2118 sa
.lpSecurityDescriptor
= NULL
;
2119 sa
.bInheritHandle
= TRUE
;
2120 filemap
= CreateFileMapping(INVALID_HANDLE_VALUE
,
2124 if (filemap
&& filemap
!= INVALID_HANDLE_VALUE
) {
2125 p
= MapViewOfFile(filemap
, FILE_MAP_WRITE
, 0, 0, size
);
2127 conf_serialise(conf
, p
);
2131 inherit_handles
= TRUE
;
2132 sprintf(c
, "putty &%p:%u", filemap
, (unsigned)size
);
2134 } else if (wParam
== IDM_SAVEDSESS
) {
2135 unsigned int sessno
= ((lParam
- IDM_SAVED_MIN
)
2136 / MENU_SAVED_STEP
) + 1;
2137 if (sessno
< (unsigned)sesslist
.nsessions
) {
2138 char *session
= sesslist
.sessions
[sessno
];
2139 cl
= dupprintf("putty @%s", session
);
2140 inherit_handles
= FALSE
;
2144 } else /* IDM_NEWSESS */ {
2146 inherit_handles
= FALSE
;
2149 GetModuleFileName(NULL
, b
, sizeof(b
) - 1);
2151 si
.lpReserved
= NULL
;
2152 si
.lpDesktop
= NULL
;
2156 si
.lpReserved2
= NULL
;
2157 CreateProcess(b
, cl
, NULL
, NULL
, inherit_handles
,
2158 NORMAL_PRIORITY_CLASS
, NULL
, NULL
, &si
, &pi
);
2161 CloseHandle(filemap
);
2168 logevent(NULL
, "----- Session restarted -----");
2169 term_pwron(term
, FALSE
);
2178 int reconfig_result
;
2183 reconfiguring
= TRUE
;
2186 * Copy the current window title into the stored
2187 * previous configuration, so that doing nothing to
2188 * the window title field in the config box doesn't
2189 * reset the title to its startup state.
2191 conf_set_str(conf
, CONF_wintitle
, window_name
);
2193 prev_conf
= conf_copy(conf
);
2196 do_reconfig(hwnd
, back ? back
->cfg_info(backhandle
) : 0);
2197 reconfiguring
= FALSE
;
2198 if (!reconfig_result
)
2203 resize_action
= conf_get_int(conf
, CONF_resize_action
);
2205 /* Disable full-screen if resizing forbidden */
2207 for (i
= 0; i
< lenof(popup_menus
); i
++)
2208 EnableMenuItem(popup_menus
[i
].menu
, IDM_FULLSCREEN
,
2210 (resize_action
== RESIZE_DISABLED
)
2211 ? MF_GRAYED
: MF_ENABLED
);
2212 /* Gracefully unzoom if necessary */
2213 if (IsZoomed(hwnd
) && (resize_action
== RESIZE_DISABLED
))
2214 ShowWindow(hwnd
, SW_RESTORE
);
2217 /* Pass new config data to the logging module */
2218 log_reconfig(logctx
, conf
);
2222 * Flush the line discipline's edit buffer in the
2223 * case where local editing has just been disabled.
2225 ldisc_configure(ldisc
, conf
);
2227 ldisc_send(ldisc
, NULL
, 0, 0);
2235 /* Pass new config data to the terminal */
2236 term_reconfig(term
, conf
);
2238 /* Pass new config data to the back end */
2240 back
->reconfig(backhandle
, conf
);
2242 /* Screen size changed ? */
2243 if (conf_get_int(conf
, CONF_height
) !=
2244 conf_get_int(prev_conf
, CONF_height
) ||
2245 conf_get_int(conf
, CONF_width
) !=
2246 conf_get_int(prev_conf
, CONF_width
) ||
2247 conf_get_int(conf
, CONF_savelines
) !=
2248 conf_get_int(prev_conf
, CONF_savelines
) ||
2249 resize_action
== RESIZE_FONT
||
2250 (resize_action
== RESIZE_EITHER
&& IsZoomed(hwnd
)) ||
2251 resize_action
== RESIZE_DISABLED
)
2252 term_size(term
, conf_get_int(conf
, CONF_height
),
2253 conf_get_int(conf
, CONF_width
),
2254 conf_get_int(conf
, CONF_savelines
));
2256 /* Enable or disable the scroll bar, etc */
2258 LONG nflg
, flag
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2259 LONG nexflag
, exflag
=
2260 GetWindowLongPtr(hwnd
, GWL_EXSTYLE
);
2263 if (conf_get_int(conf
, CONF_alwaysontop
) !=
2264 conf_get_int(prev_conf
, CONF_alwaysontop
)) {
2265 if (conf_get_int(conf
, CONF_alwaysontop
)) {
2266 nexflag
|= WS_EX_TOPMOST
;
2267 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0,
2268 SWP_NOMOVE
| SWP_NOSIZE
);
2270 nexflag
&= ~(WS_EX_TOPMOST
);
2271 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0,
2272 SWP_NOMOVE
| SWP_NOSIZE
);
2275 if (conf_get_int(conf
, CONF_sunken_edge
))
2276 nexflag
|= WS_EX_CLIENTEDGE
;
2278 nexflag
&= ~(WS_EX_CLIENTEDGE
);
2281 if (conf_get_int(conf
, is_full_screen() ?
2282 CONF_scrollbar_in_fullscreen
:
2286 nflg
&= ~WS_VSCROLL
;
2288 if (resize_action
== RESIZE_DISABLED
||
2290 nflg
&= ~WS_THICKFRAME
;
2292 nflg
|= WS_THICKFRAME
;
2294 if (resize_action
== RESIZE_DISABLED
)
2295 nflg
&= ~WS_MAXIMIZEBOX
;
2297 nflg
|= WS_MAXIMIZEBOX
;
2299 if (nflg
!= flag
|| nexflag
!= exflag
) {
2301 SetWindowLongPtr(hwnd
, GWL_STYLE
, nflg
);
2302 if (nexflag
!= exflag
)
2303 SetWindowLongPtr(hwnd
, GWL_EXSTYLE
, nexflag
);
2305 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
2306 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2307 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
2315 if (resize_action
== RESIZE_DISABLED
&& IsZoomed(hwnd
)) {
2320 set_title(NULL
, conf_get_str(conf
, CONF_wintitle
));
2321 if (IsIconic(hwnd
)) {
2323 conf_get_int(conf
, CONF_win_name_always
) ?
2324 window_name
: icon_name
);
2328 FontSpec
*font
= conf_get_fontspec(conf
, CONF_font
);
2329 FontSpec
*prev_font
= conf_get_fontspec(prev_conf
,
2332 if (!strcmp(font
->name
, prev_font
->name
) ||
2333 !strcmp(conf_get_str(conf
, CONF_line_codepage
),
2334 conf_get_str(prev_conf
, CONF_line_codepage
)) ||
2335 font
->isbold
!= prev_font
->isbold
||
2336 font
->height
!= prev_font
->height
||
2337 font
->charset
!= prev_font
->charset
||
2338 conf_get_int(conf
, CONF_font_quality
) !=
2339 conf_get_int(prev_conf
, CONF_font_quality
) ||
2340 conf_get_int(conf
, CONF_vtmode
) !=
2341 conf_get_int(prev_conf
, CONF_vtmode
) ||
2342 conf_get_int(conf
, CONF_bold_style
) !=
2343 conf_get_int(prev_conf
, CONF_bold_style
) ||
2344 resize_action
== RESIZE_DISABLED
||
2345 resize_action
== RESIZE_EITHER
||
2346 resize_action
!= conf_get_int(prev_conf
,
2347 CONF_resize_action
))
2351 InvalidateRect(hwnd
, NULL
, TRUE
);
2352 reset_window(init_lvl
);
2353 net_pending_errors();
2355 conf_free(prev_conf
);
2362 request_paste(NULL
);
2368 term_pwron(term
, TRUE
);
2370 ldisc_send(ldisc
, NULL
, 0, 0);
2376 launch_help(hwnd
, NULL
);
2380 * We get this if the System menu has been activated
2387 * We get this if the System menu has been activated
2388 * using the keyboard. This might happen from within
2389 * TranslateKey, in which case it really wants to be
2390 * followed by a `space' character to actually _bring
2391 * the menu up_ rather than just sitting there in
2392 * `ready to appear' state.
2394 show_mouseptr(1); /* make sure pointer is visible */
2396 PostMessage(hwnd
, WM_CHAR
, ' ', 0);
2398 case IDM_FULLSCREEN
:
2402 if (wParam
>= IDM_SAVED_MIN
&& wParam
< IDM_SAVED_MAX
) {
2403 SendMessage(hwnd
, WM_SYSCOMMAND
, IDM_SAVEDSESS
, wParam
);
2405 if (wParam
>= IDM_SPECIAL_MIN
&& wParam
<= IDM_SPECIAL_MAX
) {
2406 int i
= (wParam
- IDM_SPECIAL_MIN
) / 0x10;
2408 * Ensure we haven't been sent a bogus SYSCOMMAND
2409 * which would cause us to reference invalid memory
2410 * and crash. Perhaps I'm just too paranoid here.
2412 if (i
>= n_specials
)
2415 back
->special(backhandle
, specials
[i
].code
);
2416 net_pending_errors();
2421 #define X_POS(l) ((int)(short)LOWORD(l))
2422 #define Y_POS(l) ((int)(short)HIWORD(l))
2424 #define TO_CHR_X(x) ((((x)<0 ? (x)-font_width+1 : (x))-offset_width) / font_width)
2425 #define TO_CHR_Y(y) ((((y)<0 ? (y)-font_height+1: (y))-offset_height) / font_height)
2426 case WM_LBUTTONDOWN
:
2427 case WM_MBUTTONDOWN
:
2428 case WM_RBUTTONDOWN
:
2432 if (message
== WM_RBUTTONDOWN
&&
2433 ((wParam
& MK_CONTROL
) ||
2434 (conf_get_int(conf
, CONF_mouse_is_xterm
) == 2))) {
2437 show_mouseptr(1); /* make sure pointer is visible */
2438 GetCursorPos(&cursorpos
);
2439 TrackPopupMenu(popup_menus
[CTXMENU
].menu
,
2440 TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
2441 cursorpos
.x
, cursorpos
.y
,
2449 case WM_LBUTTONDOWN
:
2451 wParam
|= MK_LBUTTON
;
2454 case WM_MBUTTONDOWN
:
2455 button
= MBT_MIDDLE
;
2456 wParam
|= MK_MBUTTON
;
2459 case WM_RBUTTONDOWN
:
2461 wParam
|= MK_RBUTTON
;
2466 wParam
&= ~MK_LBUTTON
;
2470 button
= MBT_MIDDLE
;
2471 wParam
&= ~MK_MBUTTON
;
2476 wParam
&= ~MK_RBUTTON
;
2480 button
= press
= 0; /* shouldn't happen */
2484 * Special case: in full-screen mode, if the left
2485 * button is clicked in the very top left corner of the
2486 * window, we put up the System menu instead of doing
2490 char mouse_on_hotspot
= 0;
2499 mon
= MonitorFromPoint(pt
, MONITOR_DEFAULTTONULL
);
2502 mi
.cbSize
= sizeof(MONITORINFO
);
2503 GetMonitorInfo(mon
, &mi
);
2505 if (mi
.rcMonitor
.left
== pt
.x
&&
2506 mi
.rcMonitor
.top
== pt
.y
) {
2507 mouse_on_hotspot
= 1;
2512 if (pt
.x
== 0 && pt
.y
== 0) {
2513 mouse_on_hotspot
= 1;
2516 if (is_full_screen() && press
&&
2517 button
== MBT_LEFT
&& mouse_on_hotspot
) {
2518 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
,
2519 MAKELPARAM(pt
.x
, pt
.y
));
2526 TO_CHR_X(X_POS(lParam
)), TO_CHR_Y(Y_POS(lParam
)),
2527 wParam
& MK_SHIFT
, wParam
& MK_CONTROL
,
2531 term_mouse(term
, button
, translate_button(button
), MA_RELEASE
,
2532 TO_CHR_X(X_POS(lParam
)),
2533 TO_CHR_Y(Y_POS(lParam
)), wParam
& MK_SHIFT
,
2534 wParam
& MK_CONTROL
, is_alt_pressed());
2535 if (!(wParam
& (MK_LBUTTON
| MK_MBUTTON
| MK_RBUTTON
)))
2543 * Windows seems to like to occasionally send MOUSEMOVE
2544 * events even if the mouse hasn't moved. Don't unhide
2545 * the mouse pointer in this case.
2547 static WPARAM wp
= 0;
2548 static LPARAM lp
= 0;
2549 if (wParam
!= wp
|| lParam
!= lp
||
2550 last_mousemove
!= WM_MOUSEMOVE
) {
2552 wp
= wParam
; lp
= lParam
;
2553 last_mousemove
= WM_MOUSEMOVE
;
2557 * Add the mouse position and message time to the random
2560 noise_ultralight(lParam
);
2562 if (wParam
& (MK_LBUTTON
| MK_MBUTTON
| MK_RBUTTON
) &&
2563 GetCapture() == hwnd
) {
2565 if (wParam
& MK_LBUTTON
)
2567 else if (wParam
& MK_MBUTTON
)
2571 term_mouse(term
, b
, translate_button(b
), MA_DRAG
,
2572 TO_CHR_X(X_POS(lParam
)),
2573 TO_CHR_Y(Y_POS(lParam
)), wParam
& MK_SHIFT
,
2574 wParam
& MK_CONTROL
, is_alt_pressed());
2577 case WM_NCMOUSEMOVE
:
2579 static WPARAM wp
= 0;
2580 static LPARAM lp
= 0;
2581 if (wParam
!= wp
|| lParam
!= lp
||
2582 last_mousemove
!= WM_NCMOUSEMOVE
) {
2584 wp
= wParam
; lp
= lParam
;
2585 last_mousemove
= WM_NCMOUSEMOVE
;
2588 noise_ultralight(lParam
);
2590 case WM_IGNORE_CLIP
:
2591 ignore_clip
= wParam
; /* don't panic on DESTROYCLIPBOARD */
2593 case WM_DESTROYCLIPBOARD
:
2595 term_deselect(term
);
2596 ignore_clip
= FALSE
;
2603 hdc
= BeginPaint(hwnd
, &p
);
2605 SelectPalette(hdc
, pal
, TRUE
);
2606 RealizePalette(hdc
);
2610 * We have to be careful about term_paint(). It will
2611 * set a bunch of character cells to INVALID and then
2612 * call do_paint(), which will redraw those cells and
2613 * _then mark them as done_. This may not be accurate:
2614 * when painting in WM_PAINT context we are restricted
2615 * to the rectangle which has just been exposed - so if
2616 * that only covers _part_ of a character cell and the
2617 * rest of it was already visible, that remainder will
2618 * not be redrawn at all. Accordingly, we must not
2619 * paint any character cell in a WM_PAINT context which
2620 * already has a pending update due to terminal output.
2621 * The simplest solution to this - and many, many
2622 * thanks to Hung-Te Lin for working all this out - is
2623 * not to do any actual painting at _all_ if there's a
2624 * pending terminal update: just mark the relevant
2625 * character cells as INVALID and wait for the
2626 * scheduled full update to sort it out.
2628 * I have a suspicion this isn't the _right_ solution.
2629 * An alternative approach would be to have terminal.c
2630 * separately track what _should_ be on the terminal
2631 * screen and what _is_ on the terminal screen, and
2632 * have two completely different types of redraw (one
2633 * for full updates, which syncs the former with the
2634 * terminal itself, and one for WM_PAINT which syncs
2635 * the latter with the former); yet another possibility
2636 * would be to have the Windows front end do what the
2637 * GTK one already does, and maintain a bitmap of the
2638 * current terminal appearance so that WM_PAINT becomes
2639 * completely trivial. However, this should do for now.
2641 term_paint(term
, hdc
,
2642 (p
.rcPaint
.left
-offset_width
)/font_width
,
2643 (p
.rcPaint
.top
-offset_height
)/font_height
,
2644 (p
.rcPaint
.right
-offset_width
-1)/font_width
,
2645 (p
.rcPaint
.bottom
-offset_height
-1)/font_height
,
2646 !term
->window_update_pending
);
2649 p
.rcPaint
.left
< offset_width
||
2650 p
.rcPaint
.top
< offset_height
||
2651 p
.rcPaint
.right
>= offset_width
+ font_width
*term
->cols
||
2652 p
.rcPaint
.bottom
>= offset_height
+ font_height
*term
->rows
)
2654 HBRUSH fillcolour
, oldbrush
;
2656 fillcolour
= CreateSolidBrush (
2657 colours
[ATTR_DEFBG
>>ATTR_BGSHIFT
]);
2658 oldbrush
= SelectObject(hdc
, fillcolour
);
2659 edge
= CreatePen(PS_SOLID
, 0,
2660 colours
[ATTR_DEFBG
>>ATTR_BGSHIFT
]);
2661 oldpen
= SelectObject(hdc
, edge
);
2664 * Jordan Russell reports that this apparently
2665 * ineffectual IntersectClipRect() call masks a
2666 * Windows NT/2K bug causing strange display
2667 * problems when the PuTTY window is taller than
2668 * the primary monitor. It seems harmless enough...
2670 IntersectClipRect(hdc
,
2671 p
.rcPaint
.left
, p
.rcPaint
.top
,
2672 p
.rcPaint
.right
, p
.rcPaint
.bottom
);
2674 ExcludeClipRect(hdc
,
2675 offset_width
, offset_height
,
2676 offset_width
+font_width
*term
->cols
,
2677 offset_height
+font_height
*term
->rows
);
2679 Rectangle(hdc
, p
.rcPaint
.left
, p
.rcPaint
.top
,
2680 p
.rcPaint
.right
, p
.rcPaint
.bottom
);
2682 /* SelectClipRgn(hdc, NULL); */
2684 SelectObject(hdc
, oldbrush
);
2685 DeleteObject(fillcolour
);
2686 SelectObject(hdc
, oldpen
);
2689 SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
2690 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
2696 /* Notice we can get multiple netevents, FD_READ, FD_WRITE etc
2697 * but the only one that's likely to try to overload us is FD_READ.
2698 * This means buffering just one is fine.
2700 if (pending_netevent
)
2701 enact_pending_netevent();
2703 pending_netevent
= TRUE
;
2704 pend_netevent_wParam
= wParam
;
2705 pend_netevent_lParam
= lParam
;
2706 if (WSAGETSELECTEVENT(lParam
) != FD_READ
)
2707 enact_pending_netevent();
2709 net_pending_errors();
2712 term_set_focus(term
, TRUE
);
2713 CreateCaret(hwnd
, caretbm
, font_width
, font_height
);
2715 flash_window(0); /* stop */
2721 term_set_focus(term
, FALSE
);
2723 caret_x
= caret_y
= -1; /* ensure caret is replaced next time */
2726 case WM_ENTERSIZEMOVE
:
2727 #ifdef RDB_DEBUG_PATCH
2728 debug((27, "WM_ENTERSIZEMOVE"));
2732 need_backend_resize
= FALSE
;
2734 case WM_EXITSIZEMOVE
:
2737 #ifdef RDB_DEBUG_PATCH
2738 debug((27, "WM_EXITSIZEMOVE"));
2740 if (need_backend_resize
) {
2741 term_size(term
, conf_get_int(conf
, CONF_height
),
2742 conf_get_int(conf
, CONF_width
),
2743 conf_get_int(conf
, CONF_savelines
));
2744 InvalidateRect(hwnd
, NULL
, TRUE
);
2749 * This does two jobs:
2750 * 1) Keep the sizetip uptodate
2751 * 2) Make sure the window size is _stepped_ in units of the font size.
2753 resize_action
= conf_get_int(conf
, CONF_resize_action
);
2754 if (resize_action
== RESIZE_TERM
||
2755 (resize_action
== RESIZE_EITHER
&& !is_alt_pressed())) {
2756 int width
, height
, w
, h
, ew
, eh
;
2757 LPRECT r
= (LPRECT
) lParam
;
2759 if (!need_backend_resize
&& resize_action
== RESIZE_EITHER
&&
2760 (conf_get_int(conf
, CONF_height
) != term
->rows
||
2761 conf_get_int(conf
, CONF_width
) != term
->cols
)) {
2763 * Great! It seems that both the terminal size and the
2764 * font size have been changed and the user is now dragging.
2766 * It will now be difficult to get back to the configured
2769 * This would be easier but it seems to be too confusing.
2771 conf_set_int(conf
, CONF_height
, term
->rows
);
2772 conf_set_int(conf
, CONF_width
, term
->cols
);
2774 InvalidateRect(hwnd
, NULL
, TRUE
);
2775 need_backend_resize
= TRUE
;
2778 width
= r
->right
- r
->left
- extra_width
;
2779 height
= r
->bottom
- r
->top
- extra_height
;
2780 w
= (width
+ font_width
/ 2) / font_width
;
2783 h
= (height
+ font_height
/ 2) / font_height
;
2786 UpdateSizeTip(hwnd
, w
, h
);
2787 ew
= width
- w
* font_width
;
2788 eh
= height
- h
* font_height
;
2790 if (wParam
== WMSZ_LEFT
||
2791 wParam
== WMSZ_BOTTOMLEFT
|| wParam
== WMSZ_TOPLEFT
)
2797 if (wParam
== WMSZ_TOP
||
2798 wParam
== WMSZ_TOPRIGHT
|| wParam
== WMSZ_TOPLEFT
)
2808 int width
, height
, w
, h
, rv
= 0;
2809 int window_border
= conf_get_int(conf
, CONF_window_border
);
2810 int ex_width
= extra_width
+ (window_border
- offset_width
) * 2;
2811 int ex_height
= extra_height
+ (window_border
- offset_height
) * 2;
2812 LPRECT r
= (LPRECT
) lParam
;
2814 width
= r
->right
- r
->left
- ex_width
;
2815 height
= r
->bottom
- r
->top
- ex_height
;
2817 w
= (width
+ term
->cols
/2)/term
->cols
;
2818 h
= (height
+ term
->rows
/2)/term
->rows
;
2819 if ( r
->right
!= r
->left
+ w
*term
->cols
+ ex_width
)
2822 if (wParam
== WMSZ_LEFT
||
2823 wParam
== WMSZ_BOTTOMLEFT
|| wParam
== WMSZ_TOPLEFT
)
2824 r
->left
= r
->right
- w
*term
->cols
- ex_width
;
2826 r
->right
= r
->left
+ w
*term
->cols
+ ex_width
;
2828 if (r
->bottom
!= r
->top
+ h
*term
->rows
+ ex_height
)
2831 if (wParam
== WMSZ_TOP
||
2832 wParam
== WMSZ_TOPRIGHT
|| wParam
== WMSZ_TOPLEFT
)
2833 r
->top
= r
->bottom
- h
*term
->rows
- ex_height
;
2835 r
->bottom
= r
->top
+ h
*term
->rows
+ ex_height
;
2839 /* break; (never reached) */
2840 case WM_FULLSCR_ON_MAX
:
2841 fullscr_on_max
= TRUE
;
2844 sys_cursor_update();
2847 resize_action
= conf_get_int(conf
, CONF_resize_action
);
2848 #ifdef RDB_DEBUG_PATCH
2849 debug((27, "WM_SIZE %s (%d,%d)",
2850 (wParam
== SIZE_MINIMIZED
) ?
"SIZE_MINIMIZED":
2851 (wParam
== SIZE_MAXIMIZED
) ?
"SIZE_MAXIMIZED":
2852 (wParam
== SIZE_RESTORED
&& resizing
) ?
"to":
2853 (wParam
== SIZE_RESTORED
) ?
"SIZE_RESTORED":
2855 LOWORD(lParam
), HIWORD(lParam
)));
2857 if (wParam
== SIZE_MINIMIZED
)
2859 conf_get_int(conf
, CONF_win_name_always
) ?
2860 window_name
: icon_name
);
2861 if (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
)
2862 SetWindowText(hwnd
, window_name
);
2863 if (wParam
== SIZE_RESTORED
) {
2864 processed_resize
= FALSE
;
2865 clear_full_screen();
2866 if (processed_resize
) {
2868 * Inhibit normal processing of this WM_SIZE; a
2869 * secondary one was triggered just now by
2870 * clear_full_screen which contained the correct
2876 if (wParam
== SIZE_MAXIMIZED
&& fullscr_on_max
) {
2877 fullscr_on_max
= FALSE
;
2878 processed_resize
= FALSE
;
2880 if (processed_resize
) {
2882 * Inhibit normal processing of this WM_SIZE; a
2883 * secondary one was triggered just now by
2884 * make_full_screen which contained the correct client
2891 processed_resize
= TRUE
;
2893 if (resize_action
== RESIZE_DISABLED
) {
2894 /* A resize, well it better be a minimize. */
2898 int width
, height
, w
, h
;
2899 int window_border
= conf_get_int(conf
, CONF_window_border
);
2901 width
= LOWORD(lParam
);
2902 height
= HIWORD(lParam
);
2904 if (wParam
== SIZE_MAXIMIZED
&& !was_zoomed
) {
2906 prev_rows
= term
->rows
;
2907 prev_cols
= term
->cols
;
2908 if (resize_action
== RESIZE_TERM
) {
2909 w
= width
/ font_width
;
2911 h
= height
/ font_height
;
2916 * As below, if we're in the middle of an
2917 * interactive resize we don't call
2918 * back->size. In Windows 7, this case can
2919 * arise in maximisation as well via the Aero
2922 need_backend_resize
= TRUE
;
2923 conf_set_int(conf
, CONF_height
, h
);
2924 conf_set_int(conf
, CONF_width
, w
);
2926 term_size(term
, h
, w
,
2927 conf_get_int(conf
, CONF_savelines
));
2931 } else if (wParam
== SIZE_RESTORED
&& was_zoomed
) {
2933 if (resize_action
== RESIZE_TERM
) {
2934 w
= (width
-window_border
*2) / font_width
;
2936 h
= (height
-window_border
*2) / font_height
;
2938 term_size(term
, h
, w
, conf_get_int(conf
, CONF_savelines
));
2940 } else if (resize_action
!= RESIZE_FONT
)
2944 } else if (wParam
== SIZE_MINIMIZED
) {
2946 } else if (resize_action
== RESIZE_TERM
||
2947 (resize_action
== RESIZE_EITHER
&&
2948 !is_alt_pressed())) {
2949 w
= (width
-window_border
*2) / font_width
;
2951 h
= (height
-window_border
*2) / font_height
;
2956 * Don't call back->size in mid-resize. (To
2957 * prevent massive numbers of resize events
2958 * getting sent down the connection during an NT
2961 need_backend_resize
= TRUE
;
2962 conf_set_int(conf
, CONF_height
, h
);
2963 conf_set_int(conf
, CONF_width
, w
);
2965 term_size(term
, h
, w
, conf_get_int(conf
, CONF_savelines
));
2971 sys_cursor_update();
2974 switch (LOWORD(wParam
)) {
2976 term_scroll(term
, -1, 0);
2979 term_scroll(term
, +1, 0);
2982 term_scroll(term
, 0, +1);
2985 term_scroll(term
, 0, -1);
2988 term_scroll(term
, 0, +term
->rows
/ 2);
2991 term_scroll(term
, 0, -term
->rows
/ 2);
2993 case SB_THUMBPOSITION
:
2995 term_scroll(term
, 1, HIWORD(wParam
));
2999 case WM_PALETTECHANGED
:
3000 if ((HWND
) wParam
!= hwnd
&& pal
!= NULL
) {
3001 HDC hdc
= get_ctx(NULL
);
3003 if (RealizePalette(hdc
) > 0)
3009 case WM_QUERYNEWPALETTE
:
3011 HDC hdc
= get_ctx(NULL
);
3013 if (RealizePalette(hdc
) > 0)
3025 * Add the scan code and keypress timing to the random
3028 noise_ultralight(lParam
);
3031 * We don't do TranslateMessage since it disassociates the
3032 * resulting CHAR message from the KEYDOWN that sparked it,
3033 * which we occasionally don't want. Instead, we process
3034 * KEYDOWN, and call the Win32 translator functions so that
3035 * we get the translations under _our_ control.
3038 unsigned char buf
[20];
3041 if (wParam
== VK_PROCESSKEY
) { /* IME PROCESS key */
3042 if (message
== WM_KEYDOWN
) {
3045 m
.message
= WM_KEYDOWN
;
3047 m
.lParam
= lParam
& 0xdfff;
3048 TranslateMessage(&m
);
3049 } else break; /* pass to Windows for default processing */
3051 len
= TranslateKey(message
, wParam
, lParam
, buf
);
3053 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
3057 * Interrupt an ongoing paste. I'm not sure
3058 * this is sensible, but for the moment it's
3059 * preferable to having to faff about buffering
3065 * We need not bother about stdin backlogs
3066 * here, because in GUI PuTTY we can't do
3067 * anything about it anyway; there's no means
3068 * of asking Windows to hold off on KEYDOWN
3069 * messages. We _have_ to buffer everything
3072 term_seen_key_event(term
);
3074 ldisc_send(ldisc
, buf
, len
, 1);
3079 net_pending_errors();
3081 case WM_INPUTLANGCHANGE
:
3082 /* wParam == Font number */
3083 /* lParam == Locale */
3084 set_input_locale((HKL
)lParam
);
3085 sys_cursor_update();
3087 case WM_IME_STARTCOMPOSITION
:
3089 HIMC hImc
= ImmGetContext(hwnd
);
3090 ImmSetCompositionFont(hImc
, &lfont
);
3091 ImmReleaseContext(hwnd
, hImc
);
3094 case WM_IME_COMPOSITION
:
3100 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
||
3101 osVersion
.dwPlatformId
== VER_PLATFORM_WIN32s
) break; /* no Unicode */
3103 if ((lParam
& GCS_RESULTSTR
) == 0) /* Composition unfinished. */
3104 break; /* fall back to DefWindowProc */
3106 hIMC
= ImmGetContext(hwnd
);
3107 n
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
3111 buff
= snewn(n
, char);
3112 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, buff
, n
);
3114 * Jaeyoun Chung reports that Korean character
3115 * input doesn't work correctly if we do a single
3116 * luni_send() covering the whole of buff. So
3117 * instead we luni_send the characters one by one.
3119 term_seen_key_event(term
);
3120 /* don't divide SURROGATE PAIR */
3122 for (i
= 0; i
< n
; i
+= 2) {
3123 WCHAR hs
= *(unsigned short *)(buff
+i
);
3124 if (IS_HIGH_SURROGATE(hs
) && i
+2 < n
) {
3125 WCHAR ls
= *(unsigned short *)(buff
+i
+2);
3126 if (IS_LOW_SURROGATE(ls
)) {
3127 luni_send(ldisc
, (unsigned short *)(buff
+i
), 2, 1);
3132 luni_send(ldisc
, (unsigned short *)(buff
+i
), 1, 1);
3137 ImmReleaseContext(hwnd
, hIMC
);
3142 if (wParam
& 0xFF00) {
3143 unsigned char buf
[2];
3146 buf
[0] = wParam
>> 8;
3147 term_seen_key_event(term
);
3149 lpage_send(ldisc
, kbd_codepage
, buf
, 2, 1);
3151 char c
= (unsigned char) wParam
;
3152 term_seen_key_event(term
);
3154 lpage_send(ldisc
, kbd_codepage
, &c
, 1, 1);
3160 * Nevertheless, we are prepared to deal with WM_CHAR
3161 * messages, should they crop up. So if someone wants to
3162 * post the things to us as part of a macro manoeuvre,
3163 * we're ready to cope.
3166 char c
= (unsigned char)wParam
;
3167 term_seen_key_event(term
);
3169 lpage_send(ldisc
, CP_ACP
, &c
, 1, 1);
3172 case WM_SYSCOLORCHANGE
:
3173 if (conf_get_int(conf
, CONF_system_colour
)) {
3174 /* Refresh palette from system colours. */
3175 /* XXX actually this zaps the entire palette. */
3178 /* Force a repaint of the terminal window. */
3179 term_invalidate(term
);
3182 case WM_AGENT_CALLBACK
:
3184 struct agent_callback
*c
= (struct agent_callback
*)lParam
;
3185 c
->callback(c
->callback_ctx
, c
->data
, c
->len
);
3189 case WM_GOT_CLIPDATA
:
3190 if (process_clipdata((HGLOBAL
)lParam
, wParam
))
3191 term_do_paste(term
);
3194 if (message
== wm_mousewheel
|| message
== WM_MOUSEWHEEL
) {
3195 int shift_pressed
=0, control_pressed
=0;
3197 if (message
== WM_MOUSEWHEEL
) {
3198 wheel_accumulator
+= (short)HIWORD(wParam
);
3199 shift_pressed
=LOWORD(wParam
) & MK_SHIFT
;
3200 control_pressed
=LOWORD(wParam
) & MK_CONTROL
;
3203 wheel_accumulator
+= (int)wParam
;
3204 if (GetKeyboardState(keys
)!=0) {
3205 shift_pressed
=keys
[VK_SHIFT
]&0x80;
3206 control_pressed
=keys
[VK_CONTROL
]&0x80;
3210 /* process events when the threshold is reached */
3211 while (abs(wheel_accumulator
) >= WHEEL_DELTA
) {
3214 /* reduce amount for next time */
3215 if (wheel_accumulator
> 0) {
3217 wheel_accumulator
-= WHEEL_DELTA
;
3218 } else if (wheel_accumulator
< 0) {
3220 wheel_accumulator
+= WHEEL_DELTA
;
3224 if (send_raw_mouse
&& shift_pressed
&&
3225 !(conf_get_int(conf
, CONF_mouse_override
))) {
3226 /* Mouse wheel position is in screen coordinates for
3229 p
.x
= X_POS(lParam
); p
.y
= Y_POS(lParam
);
3230 if (ScreenToClient(hwnd
, &p
)) {
3231 /* send a mouse-down followed by a mouse up */
3232 term_mouse(term
, b
, translate_button(b
),
3235 TO_CHR_Y(p
.y
), shift_pressed
,
3236 control_pressed
, is_alt_pressed());
3237 term_mouse(term
, b
, translate_button(b
),
3238 MA_RELEASE
, TO_CHR_X(p
.x
),
3239 TO_CHR_Y(p
.y
), shift_pressed
,
3240 control_pressed
, is_alt_pressed());
3241 } /* else: not sure when this can fail */
3243 /* trigger a scroll */
3244 term_scroll(term
, 0,
3246 -term
->rows
/ 2 : term
->rows
/ 2);
3254 * Any messages we don't process completely above are passed through to
3255 * DefWindowProc() for default processing.
3257 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
3261 * Move the system caret. (We maintain one, even though it's
3262 * invisible, for the benefit of blind people: apparently some
3263 * helper software tracks the system caret, so we should arrange to
3266 void sys_cursor(void *frontend
, int x
, int y
)
3270 if (!term
->has_focus
) return;
3273 * Avoid gratuitously re-updating the cursor position and IMM
3274 * window if there's no actual change required.
3276 cx
= x
* font_width
+ offset_width
;
3277 cy
= y
* font_height
+ offset_height
;
3278 if (cx
== caret_x
&& cy
== caret_y
)
3283 sys_cursor_update();
3286 static void sys_cursor_update(void)
3291 if (!term
->has_focus
) return;
3293 if (caret_x
< 0 || caret_y
< 0)
3296 SetCaretPos(caret_x
, caret_y
);
3298 /* IMM calls on Win98 and beyond only */
3299 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32s
) return; /* 3.11 */
3301 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
&&
3302 osVersion
.dwMinorVersion
== 0) return; /* 95 */
3304 /* we should have the IMM functions */
3305 hIMC
= ImmGetContext(hwnd
);
3306 cf
.dwStyle
= CFS_POINT
;
3307 cf
.ptCurrentPos
.x
= caret_x
;
3308 cf
.ptCurrentPos
.y
= caret_y
;
3309 ImmSetCompositionWindow(hIMC
, &cf
);
3311 ImmReleaseContext(hwnd
, hIMC
);
3315 * Draw a line of text in the window, at given character
3316 * coordinates, in given attributes.
3318 * We are allowed to fiddle with the contents of `text'.
3320 void do_text_internal(Context ctx
, int x
, int y
, wchar_t *text
, int len
,
3321 unsigned long attr
, int lattr
)
3324 int nfg
, nbg
, nfont
;
3327 int force_manual_underline
= 0;
3328 int fnt_width
, char_width
;
3329 int text_adjust
= 0;
3331 int maxlen
, remaining
, opaque
;
3332 int is_cursor
= FALSE
;
3333 static int *lpDx
= NULL
;
3334 static int lpDx_len
= 0;
3336 int len2
; /* for SURROGATE PAIR */
3338 lattr
&= LATTR_MODE
;
3340 char_width
= fnt_width
= font_width
* (1 + (lattr
!= LATTR_NORM
));
3342 if (attr
& ATTR_WIDE
)
3345 /* Only want the left half of double width lines */
3346 if (lattr
!= LATTR_NORM
&& x
*2 >= term
->cols
)
3354 if ((attr
& TATTR_ACTCURS
) && (cursor_type
== 0 || term
->big_cursor
)) {
3355 attr
&= ~(ATTR_REVERSE
|ATTR_BLINK
|ATTR_COLOURS
);
3356 /* cursor fg and bg */
3357 attr
|= (260 << ATTR_FGSHIFT
) | (261 << ATTR_BGSHIFT
);
3362 if (vtmode
== VT_POORMAN
&& lattr
!= LATTR_NORM
) {
3363 /* Assume a poorman font is borken in other ways too. */
3373 nfont
|= FONT_WIDE
+ FONT_HIGH
;
3376 if (attr
& ATTR_NARROW
)
3377 nfont
|= FONT_NARROW
;
3379 #ifdef USES_VTLINE_HACK
3380 /* Special hack for the VT100 linedraw glyphs. */
3381 if (text
[0] >= 0x23BA && text
[0] <= 0x23BD) {
3382 switch ((unsigned char) (text
[0])) {
3384 text_adjust
= -2 * font_height
/ 5;
3387 text_adjust
= -1 * font_height
/ 5;
3390 text_adjust
= font_height
/ 5;
3393 text_adjust
= 2 * font_height
/ 5;
3396 if (lattr
== LATTR_TOP
|| lattr
== LATTR_BOT
)
3398 text
[0] = ucsdata
.unitab_xterm
['q'];
3399 if (attr
& ATTR_UNDER
) {
3400 attr
&= ~ATTR_UNDER
;
3401 force_manual_underline
= 1;
3406 /* Anything left as an original character set is unprintable. */
3407 if (DIRECT_CHAR(text
[0]) &&
3408 (len
< 2 || !IS_SURROGATE_PAIR(text
[0], text
[1]))) {
3410 for (i
= 0; i
< len
; i
++)
3415 if ((text
[0] & CSET_MASK
) == CSET_OEMCP
)
3418 nfg
= ((attr
& ATTR_FGMASK
) >> ATTR_FGSHIFT
);
3419 nbg
= ((attr
& ATTR_BGMASK
) >> ATTR_BGSHIFT
);
3420 if (bold_font_mode
== BOLD_FONT
&& (attr
& ATTR_BOLD
))
3422 if (und_mode
== UND_FONT
&& (attr
& ATTR_UNDER
))
3423 nfont
|= FONT_UNDERLINE
;
3424 another_font(nfont
);
3425 if (!fonts
[nfont
]) {
3426 if (nfont
& FONT_UNDERLINE
)
3427 force_manual_underline
= 1;
3428 /* Don't do the same for manual bold, it could be bad news. */
3430 nfont
&= ~(FONT_BOLD
| FONT_UNDERLINE
);
3432 another_font(nfont
);
3434 nfont
= FONT_NORMAL
;
3435 if (attr
& ATTR_REVERSE
) {
3440 if (bold_colours
&& (attr
& ATTR_BOLD
) && !is_cursor
) {
3441 if (nfg
< 16) nfg
|= 8;
3442 else if (nfg
>= 256) nfg
|= 1;
3444 if (bold_colours
&& (attr
& ATTR_BLINK
)) {
3445 if (nbg
< 16) nbg
|= 8;
3446 else if (nbg
>= 256) nbg
|= 1;
3450 SelectObject(hdc
, fonts
[nfont
]);
3451 SetTextColor(hdc
, fg
);
3452 SetBkColor(hdc
, bg
);
3453 if (attr
& TATTR_COMBINING
)
3454 SetBkMode(hdc
, TRANSPARENT
);
3456 SetBkMode(hdc
, OPAQUE
);
3459 line_box
.right
= x
+ char_width
* len
;
3460 line_box
.bottom
= y
+ font_height
;
3461 /* adjust line_box.right for SURROGATE PAIR & VARIATION SELECTOR */
3465 for (i
= 0; i
< len
; i
++) {
3466 if (i
+1 < len
&& IS_HIGH_VARSEL(text
[i
], text
[i
+1])) {
3468 } else if (i
+1 < len
&& IS_SURROGATE_PAIR(text
[i
], text
[i
+1])) {
3469 rc_width
+= char_width
;
3471 } else if (IS_LOW_VARSEL(text
[i
])) {
3474 rc_width
+= char_width
;
3477 line_box
.right
= line_box
.left
+ rc_width
;
3480 /* Only want the left half of double width lines */
3481 if (line_box
.right
> font_width
*term
->cols
+offset_width
)
3482 line_box
.right
= font_width
*term
->cols
+offset_width
;
3484 if (font_varpitch
) {
3486 * If we're using a variable-pitch font, we unconditionally
3487 * draw the glyphs one at a time and centre them in their
3488 * character cells (which means in particular that we must
3489 * disable the lpDx mechanism). This gives slightly odd but
3490 * generally reasonable results.
3492 xoffset
= char_width
/ 2;
3493 SetTextAlign(hdc
, TA_TOP
| TA_CENTER
| TA_NOUPDATECP
);
3498 * In a fixed-pitch font, we draw the whole string in one go
3499 * in the normal way.
3502 SetTextAlign(hdc
, TA_TOP
| TA_LEFT
| TA_NOUPDATECP
);
3507 opaque
= TRUE
; /* start by erasing the rectangle */
3508 for (remaining
= len
; remaining
> 0;
3509 text
+= len
, remaining
-= len
, x
+= char_width
* len2
) {
3510 len
= (maxlen
< remaining ? maxlen
: remaining
);
3511 /* don't divide SURROGATE PAIR and VARIATION SELECTOR */
3514 if (remaining
>= 1 && IS_SURROGATE_PAIR(text
[0], text
[1]))
3516 if (remaining
-len
>= 1 && IS_LOW_VARSEL(text
[len
]))
3518 else if (remaining
-len
>= 2 &&
3519 IS_HIGH_VARSEL(text
[len
], text
[len
+1]))
3523 if (len
> lpDx_len
) {
3524 lpDx_len
= len
* 9 / 8 + 16;
3525 lpDx
= sresize(lpDx
, lpDx_len
, int);
3527 if (lpDx_maybe
) lpDx_maybe
= lpDx
;
3532 /* only last char has dx width in SURROGATE PAIR and
3533 * VARIATION sequence */
3534 for (i
= 0; i
< len
; i
++) {
3535 lpDx
[i
] = char_width
;
3536 if (i
+1 < len
&& IS_HIGH_VARSEL(text
[i
], text
[i
+1])) {
3537 if (i
> 0) lpDx
[i
-1] = 0;
3540 lpDx
[i
] = char_width
;
3541 } else if (i
+1 < len
&& IS_SURROGATE_PAIR(text
[i
],text
[i
+1])) {
3544 lpDx
[i
] = char_width
;
3545 } else if (IS_LOW_VARSEL(text
[i
])) {
3546 if (i
> 0) lpDx
[i
-1] = 0;
3547 lpDx
[i
] = char_width
;
3552 /* We're using a private area for direct to font. (512 chars.) */
3553 if (ucsdata
.dbcs_screenfont
&& (text
[0] & CSET_MASK
) == CSET_ACP
) {
3554 /* Ho Hum, dbcs fonts are a PITA! */
3555 /* To display on W9x I have to convert to UCS */
3556 static wchar_t *uni_buf
= 0;
3557 static int uni_len
= 0;
3559 if (len
> uni_len
) {
3562 uni_buf
= snewn(uni_len
, wchar_t);
3565 for(nlen
= mptr
= 0; mptr
<len
; mptr
++) {
3566 uni_buf
[nlen
] = 0xFFFD;
3567 if (IsDBCSLeadByteEx(ucsdata
.font_codepage
,
3568 (BYTE
) text
[mptr
])) {
3570 dbcstext
[0] = text
[mptr
] & 0xFF;
3571 dbcstext
[1] = text
[mptr
+1] & 0xFF;
3572 lpDx
[nlen
] += char_width
;
3573 MultiByteToWideChar(ucsdata
.font_codepage
, MB_USEGLYPHCHARS
,
3574 dbcstext
, 2, uni_buf
+nlen
, 1);
3580 dbcstext
[0] = text
[mptr
] & 0xFF;
3581 MultiByteToWideChar(ucsdata
.font_codepage
, MB_USEGLYPHCHARS
,
3582 dbcstext
, 1, uni_buf
+nlen
, 1);
3589 ExtTextOutW(hdc
, x
+ xoffset
,
3590 y
- font_height
* (lattr
== LATTR_BOT
) + text_adjust
,
3591 ETO_CLIPPED
| (opaque ? ETO_OPAQUE
: 0),
3592 &line_box
, uni_buf
, nlen
,
3594 if (bold_font_mode
== BOLD_SHADOW
&& (attr
& ATTR_BOLD
)) {
3595 SetBkMode(hdc
, TRANSPARENT
);
3596 ExtTextOutW(hdc
, x
+ xoffset
- 1,
3597 y
- font_height
* (lattr
==
3598 LATTR_BOT
) + text_adjust
,
3599 ETO_CLIPPED
, &line_box
, uni_buf
, nlen
, lpDx_maybe
);
3603 } else if (DIRECT_FONT(text
[0])) {
3604 static char *directbuf
= NULL
;
3605 static int directlen
= 0;
3607 if (len
> directlen
) {
3609 directbuf
= sresize(directbuf
, directlen
, char);
3612 for (i
= 0; i
< len
; i
++)
3613 directbuf
[i
] = text
[i
] & 0xFF;
3615 ExtTextOut(hdc
, x
+ xoffset
,
3616 y
- font_height
* (lattr
== LATTR_BOT
) + text_adjust
,
3617 ETO_CLIPPED
| (opaque ? ETO_OPAQUE
: 0),
3618 &line_box
, directbuf
, len
, lpDx_maybe
);
3619 if (bold_font_mode
== BOLD_SHADOW
&& (attr
& ATTR_BOLD
)) {
3620 SetBkMode(hdc
, TRANSPARENT
);
3622 /* GRR: This draws the character outside its box and
3623 * can leave 'droppings' even with the clip box! I
3624 * suppose I could loop it one character at a time ...
3627 * Or ... I could do a test print with "W", and use +1
3628 * or -1 for this shift depending on if the leftmost
3629 * column is blank...
3631 ExtTextOut(hdc
, x
+ xoffset
- 1,
3632 y
- font_height
* (lattr
==
3633 LATTR_BOT
) + text_adjust
,
3634 ETO_CLIPPED
, &line_box
, directbuf
, len
, lpDx_maybe
);
3637 /* And 'normal' unicode characters */
3638 static WCHAR
*wbuf
= NULL
;
3639 static int wlen
= 0;
3645 wbuf
= snewn(wlen
, WCHAR
);
3648 for (i
= 0; i
< len
; i
++)
3651 /* print Glyphs as they are, without Windows' Shaping*/
3652 general_textout(hdc
, x
+ xoffset
,
3653 y
- font_height
* (lattr
==LATTR_BOT
) + text_adjust
,
3654 &line_box
, wbuf
, len
, lpDx
,
3655 opaque
&& !(attr
& TATTR_COMBINING
));
3657 /* And the shadow bold hack. */
3658 if (bold_font_mode
== BOLD_SHADOW
&& (attr
& ATTR_BOLD
)) {
3659 SetBkMode(hdc
, TRANSPARENT
);
3660 ExtTextOutW(hdc
, x
+ xoffset
- 1,
3661 y
- font_height
* (lattr
==
3662 LATTR_BOT
) + text_adjust
,
3663 ETO_CLIPPED
, &line_box
, wbuf
, len
, lpDx_maybe
);
3668 * If we're looping round again, stop erasing the background
3671 SetBkMode(hdc
, TRANSPARENT
);
3674 if (lattr
!= LATTR_TOP
&& (force_manual_underline
||
3675 (und_mode
== UND_LINE
3676 && (attr
& ATTR_UNDER
)))) {
3679 if (lattr
== LATTR_BOT
)
3680 dec
= dec
* 2 - font_height
;
3682 oldpen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, fg
));
3683 MoveToEx(hdc
, line_box
.left
, line_box
.top
+ dec
, NULL
);
3684 LineTo(hdc
, line_box
.right
, line_box
.top
+ dec
);
3685 oldpen
= SelectObject(hdc
, oldpen
);
3686 DeleteObject(oldpen
);
3691 * Wrapper that handles combining characters.
3693 void do_text(Context ctx
, int x
, int y
, wchar_t *text
, int len
,
3694 unsigned long attr
, int lattr
)
3696 if (attr
& TATTR_COMBINING
) {
3697 unsigned long a
= 0;
3699 /* don't divide SURROGATE PAIR and VARIATION SELECTOR */
3700 if (len
>= 2 && IS_SURROGATE_PAIR(text
[0], text
[1]))
3702 if (len
-len0
>= 1 && IS_LOW_VARSEL(text
[len0
])) {
3703 attr
&= ~TATTR_COMBINING
;
3704 do_text_internal(ctx
, x
, y
, text
, len0
+1, attr
, lattr
);
3707 a
= TATTR_COMBINING
;
3708 } else if (len
-len0
>= 2 && IS_HIGH_VARSEL(text
[len0
], text
[len0
+1])) {
3709 attr
&= ~TATTR_COMBINING
;
3710 do_text_internal(ctx
, x
, y
, text
, len0
+2, attr
, lattr
);
3713 a
= TATTR_COMBINING
;
3715 attr
&= ~TATTR_COMBINING
;
3719 if (len
>= 1 && IS_SURROGATE_PAIR(text
[0], text
[1])) {
3720 do_text_internal(ctx
, x
, y
, text
, 2, attr
| a
, lattr
);
3724 do_text_internal(ctx
, x
, y
, text
, 1, attr
| a
, lattr
);
3728 a
= TATTR_COMBINING
;
3731 do_text_internal(ctx
, x
, y
, text
, len
, attr
, lattr
);
3734 void do_cursor(Context ctx
, int x
, int y
, wchar_t *text
, int len
,
3735 unsigned long attr
, int lattr
)
3741 int ctype
= cursor_type
;
3743 lattr
&= LATTR_MODE
;
3745 if ((attr
& TATTR_ACTCURS
) && (ctype
== 0 || term
->big_cursor
)) {
3746 if (*text
!= UCSWIDE
) {
3747 do_text(ctx
, x
, y
, text
, len
, attr
, lattr
);
3751 attr
|= TATTR_RIGHTCURS
;
3754 fnt_width
= char_width
= font_width
* (1 + (lattr
!= LATTR_NORM
));
3755 if (attr
& ATTR_WIDE
)
3762 if ((attr
& TATTR_PASCURS
) && (ctype
== 0 || term
->big_cursor
)) {
3765 pts
[0].x
= pts
[1].x
= pts
[4].x
= x
;
3766 pts
[2].x
= pts
[3].x
= x
+ char_width
- 1;
3767 pts
[0].y
= pts
[3].y
= pts
[4].y
= y
;
3768 pts
[1].y
= pts
[2].y
= y
+ font_height
- 1;
3769 oldpen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, colours
[261]));
3770 Polyline(hdc
, pts
, 5);
3771 oldpen
= SelectObject(hdc
, oldpen
);
3772 DeleteObject(oldpen
);
3773 } else if ((attr
& (TATTR_ACTCURS
| TATTR_PASCURS
)) && ctype
!= 0) {
3774 int startx
, starty
, dx
, dy
, length
, i
;
3777 starty
= y
+ descent
;
3780 length
= char_width
;
3783 if (attr
& TATTR_RIGHTCURS
)
3784 xadjust
= char_width
- 1;
3785 startx
= x
+ xadjust
;
3789 length
= font_height
;
3791 if (attr
& TATTR_ACTCURS
) {
3794 SelectObject(hdc
, CreatePen(PS_SOLID
, 0, colours
[261]));
3795 MoveToEx(hdc
, startx
, starty
, NULL
);
3796 LineTo(hdc
, startx
+ dx
* length
, starty
+ dy
* length
);
3797 oldpen
= SelectObject(hdc
, oldpen
);
3798 DeleteObject(oldpen
);
3800 for (i
= 0; i
< length
; i
++) {
3802 SetPixel(hdc
, startx
, starty
, colours
[261]);
3811 /* This function gets the actual width of a character in the normal font.
3813 int char_width(Context ctx
, int uc
) {
3817 /* If the font max is the same as the font ave width then this
3818 * function is a no-op.
3820 if (!font_dualwidth
) return 1;
3822 switch (uc
& CSET_MASK
) {
3824 uc
= ucsdata
.unitab_line
[uc
& 0xFF];
3827 uc
= ucsdata
.unitab_xterm
[uc
& 0xFF];
3830 uc
= ucsdata
.unitab_scoacs
[uc
& 0xFF];
3833 if (DIRECT_FONT(uc
)) {
3834 if (ucsdata
.dbcs_screenfont
) return 1;
3836 /* Speedup, I know of no font where ascii is the wrong width */
3837 if ((uc
&~CSET_MASK
) >= ' ' && (uc
&~CSET_MASK
)<= '~')
3840 if ( (uc
& CSET_MASK
) == CSET_ACP
) {
3841 SelectObject(hdc
, fonts
[FONT_NORMAL
]);
3842 } else if ( (uc
& CSET_MASK
) == CSET_OEMCP
) {
3843 another_font(FONT_OEM
);
3844 if (!fonts
[FONT_OEM
]) return 0;
3846 SelectObject(hdc
, fonts
[FONT_OEM
]);
3850 if ( GetCharWidth32(hdc
, uc
&~CSET_MASK
, uc
&~CSET_MASK
, &ibuf
) != 1 &&
3851 GetCharWidth(hdc
, uc
&~CSET_MASK
, uc
&~CSET_MASK
, &ibuf
) != 1)
3854 /* Speedup, I know of no font where ascii is the wrong width */
3855 if (uc
>= ' ' && uc
<= '~') return 1;
3857 SelectObject(hdc
, fonts
[FONT_NORMAL
]);
3858 if ( GetCharWidth32W(hdc
, uc
, uc
, &ibuf
) == 1 )
3859 /* Okay that one worked */ ;
3860 else if ( GetCharWidthW(hdc
, uc
, uc
, &ibuf
) == 1 )
3861 /* This should work on 9x too, but it's "less accurate" */ ;
3866 ibuf
+= font_width
/ 2 -1;
3873 * Translate a WM_(SYS)?KEY(UP|DOWN) message into a string of ASCII
3874 * codes. Returns number of bytes used, zero to drop the message,
3875 * -1 to forward the message to Windows, or another negative number
3876 * to indicate a NUL-terminated "special" string.
3878 static int TranslateKey(UINT message
, WPARAM wParam
, LPARAM lParam
,
3879 unsigned char *output
)
3882 int scan
, left_alt
= 0, key_down
, shift_state
;
3884 unsigned char *p
= output
;
3885 static int alt_sum
= 0;
3886 int funky_type
= conf_get_int(conf
, CONF_funky_type
);
3887 int no_applic_k
= conf_get_int(conf
, CONF_no_applic_k
);
3888 int ctrlaltkeys
= conf_get_int(conf
, CONF_ctrlaltkeys
);
3889 int nethack_keypad
= conf_get_int(conf
, CONF_nethack_keypad
);
3891 HKL kbd_layout
= GetKeyboardLayout(0);
3893 /* keys is for ToAsciiEx. There's some ick here, see below. */
3894 static WORD keys
[3];
3895 static int compose_char
= 0;
3896 static WPARAM compose_keycode
= 0;
3898 r
= GetKeyboardState(keystate
);
3900 memset(keystate
, 0, sizeof(keystate
));
3903 #define SHOW_TOASCII_RESULT
3904 { /* Tell us all about key events */
3905 static BYTE oldstate
[256];
3906 static int first
= 1;
3910 memcpy(oldstate
, keystate
, sizeof(oldstate
));
3913 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == KF_REPEAT
) {
3915 } else if ((HIWORD(lParam
) & KF_UP
)
3916 && scan
== (HIWORD(lParam
) & 0xFF)) {
3920 if (wParam
>= VK_F1
&& wParam
<= VK_F20
)
3921 debug(("K_F%d", wParam
+ 1 - VK_F1
));
3934 debug(("VK_%02x", wParam
));
3936 if (message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
3938 debug((", S%02x", scan
= (HIWORD(lParam
) & 0xFF)));
3940 ch
= MapVirtualKeyEx(wParam
, 2, kbd_layout
);
3941 if (ch
>= ' ' && ch
<= '~')
3942 debug((", '%c'", ch
));
3944 debug((", $%02x", ch
));
3947 debug((", KB0=%02x", keys
[0]));
3949 debug((", KB1=%02x", keys
[1]));
3951 debug((", KB2=%02x", keys
[2]));
3953 if ((keystate
[VK_SHIFT
] & 0x80) != 0)
3955 if ((keystate
[VK_CONTROL
] & 0x80) != 0)
3957 if ((HIWORD(lParam
) & KF_EXTENDED
))
3959 if ((HIWORD(lParam
) & KF_UP
))
3963 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == KF_REPEAT
);
3964 else if ((HIWORD(lParam
) & KF_UP
))
3965 oldstate
[wParam
& 0xFF] ^= 0x80;
3967 oldstate
[wParam
& 0xFF] ^= 0x81;
3969 for (ch
= 0; ch
< 256; ch
++)
3970 if (oldstate
[ch
] != keystate
[ch
])
3971 debug((", M%02x=%02x", ch
, keystate
[ch
]));
3973 memcpy(oldstate
, keystate
, sizeof(oldstate
));
3977 if (wParam
== VK_MENU
&& (HIWORD(lParam
) & KF_EXTENDED
)) {
3978 keystate
[VK_RMENU
] = keystate
[VK_MENU
];
3982 /* Nastyness with NUMLock - Shift-NUMLock is left alone though */
3983 if ((funky_type
== FUNKY_VT400
||
3984 (funky_type
<= FUNKY_LINUX
&& term
->app_keypad_keys
&&
3986 && wParam
== VK_NUMLOCK
&& !(keystate
[VK_SHIFT
] & 0x80)) {
3988 wParam
= VK_EXECUTE
;
3990 /* UnToggle NUMLock */
3991 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == 0)
3992 keystate
[VK_NUMLOCK
] ^= 1;
3995 /* And write back the 'adjusted' state */
3996 SetKeyboardState(keystate
);
3999 /* Disable Auto repeat if required */
4000 if (term
->repeat_off
&&
4001 (HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == KF_REPEAT
)
4004 if ((HIWORD(lParam
) & KF_ALTDOWN
) && (keystate
[VK_RMENU
] & 0x80) == 0)
4007 key_down
= ((HIWORD(lParam
) & KF_UP
) == 0);
4009 /* Make sure Ctrl-ALT is not the same as AltGr for ToAscii unless told. */
4010 if (left_alt
&& (keystate
[VK_CONTROL
] & 0x80)) {
4012 keystate
[VK_MENU
] = 0;
4014 keystate
[VK_RMENU
] = 0x80;
4019 scan
= (HIWORD(lParam
) & (KF_UP
| KF_EXTENDED
| 0xFF));
4020 shift_state
= ((keystate
[VK_SHIFT
] & 0x80) != 0)
4021 + ((keystate
[VK_CONTROL
] & 0x80) != 0) * 2;
4023 /* Note if AltGr was pressed and if it was used as a compose key */
4024 if (!compose_state
) {
4025 compose_keycode
= 0x100;
4026 if (conf_get_int(conf
, CONF_compose_key
)) {
4027 if (wParam
== VK_MENU
&& (HIWORD(lParam
) & KF_EXTENDED
))
4028 compose_keycode
= wParam
;
4030 if (wParam
== VK_APPS
)
4031 compose_keycode
= wParam
;
4034 if (wParam
== compose_keycode
) {
4035 if (compose_state
== 0
4036 && (HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == 0) compose_state
=
4038 else if (compose_state
== 1 && (HIWORD(lParam
) & KF_UP
))
4042 } else if (compose_state
== 1 && wParam
!= VK_CONTROL
)
4045 if (compose_state
> 1 && left_alt
)
4048 /* Sanitize the number pad if not using a PC NumPad */
4049 if (left_alt
|| (term
->app_keypad_keys
&& !no_applic_k
4050 && funky_type
!= FUNKY_XTERM
)
4051 || funky_type
== FUNKY_VT400
|| nethack_keypad
|| compose_state
) {
4052 if ((HIWORD(lParam
) & KF_EXTENDED
) == 0) {
4056 nParam
= VK_NUMPAD0
;
4059 nParam
= VK_NUMPAD1
;
4062 nParam
= VK_NUMPAD2
;
4065 nParam
= VK_NUMPAD3
;
4068 nParam
= VK_NUMPAD4
;
4071 nParam
= VK_NUMPAD5
;
4074 nParam
= VK_NUMPAD6
;
4077 nParam
= VK_NUMPAD7
;
4080 nParam
= VK_NUMPAD8
;
4083 nParam
= VK_NUMPAD9
;
4086 nParam
= VK_DECIMAL
;
4090 if (keystate
[VK_NUMLOCK
] & 1)
4097 /* If a key is pressed and AltGr is not active */
4098 if (key_down
&& (keystate
[VK_RMENU
] & 0x80) == 0 && !compose_state
) {
4099 /* Okay, prepare for most alts then ... */
4103 /* Lets see if it's a pattern we know all about ... */
4104 if (wParam
== VK_PRIOR
&& shift_state
== 1) {
4105 SendMessage(hwnd
, WM_VSCROLL
, SB_PAGEUP
, 0);
4108 if (wParam
== VK_PRIOR
&& shift_state
== 2) {
4109 SendMessage(hwnd
, WM_VSCROLL
, SB_LINEUP
, 0);
4112 if (wParam
== VK_NEXT
&& shift_state
== 1) {
4113 SendMessage(hwnd
, WM_VSCROLL
, SB_PAGEDOWN
, 0);
4116 if (wParam
== VK_NEXT
&& shift_state
== 2) {
4117 SendMessage(hwnd
, WM_VSCROLL
, SB_LINEDOWN
, 0);
4120 if ((wParam
== VK_PRIOR
|| wParam
== VK_NEXT
) && shift_state
== 3) {
4121 term_scroll_to_selection(term
, (wParam
== VK_PRIOR ?
0 : 1));
4124 if (wParam
== VK_INSERT
&& shift_state
== 1) {
4125 request_paste(NULL
);
4128 if (left_alt
&& wParam
== VK_F4
&& conf_get_int(conf
, CONF_alt_f4
)) {
4131 if (left_alt
&& wParam
== VK_SPACE
&& conf_get_int(conf
,
4133 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
4136 if (left_alt
&& wParam
== VK_RETURN
&&
4137 conf_get_int(conf
, CONF_fullscreenonaltenter
) &&
4138 (conf_get_int(conf
, CONF_resize_action
) != RESIZE_DISABLED
)) {
4139 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
4143 /* Control-Numlock for app-keypad mode switch */
4144 if (wParam
== VK_PAUSE
&& shift_state
== 2) {
4145 term
->app_keypad_keys
^= 1;
4149 /* Nethack keypad */
4150 if (nethack_keypad
&& !left_alt
) {
4153 *p
++ = "bB\002\002"[shift_state
& 3];
4156 *p
++ = "jJ\012\012"[shift_state
& 3];
4159 *p
++ = "nN\016\016"[shift_state
& 3];
4162 *p
++ = "hH\010\010"[shift_state
& 3];
4165 *p
++ = shift_state ?
'.' : '.';
4168 *p
++ = "lL\014\014"[shift_state
& 3];
4171 *p
++ = "yY\031\031"[shift_state
& 3];
4174 *p
++ = "kK\013\013"[shift_state
& 3];
4177 *p
++ = "uU\025\025"[shift_state
& 3];
4182 /* Application Keypad */
4186 if (funky_type
== FUNKY_VT400
||
4187 (funky_type
<= FUNKY_LINUX
&&
4188 term
->app_keypad_keys
&& !no_applic_k
)) switch (wParam
) {
4202 if (term
->app_keypad_keys
&& !no_applic_k
)
4239 if (funky_type
== FUNKY_XTERM
) {
4244 } else if (shift_state
)
4251 if (funky_type
== FUNKY_XTERM
)
4255 if (funky_type
== FUNKY_XTERM
)
4259 if (funky_type
== FUNKY_XTERM
)
4264 if (HIWORD(lParam
) & KF_EXTENDED
)
4269 if (term
->vt52_mode
) {
4270 if (xkey
>= 'P' && xkey
<= 'S')
4271 p
+= sprintf((char *) p
, "\x1B%c", xkey
);
4273 p
+= sprintf((char *) p
, "\x1B?%c", xkey
);
4275 p
+= sprintf((char *) p
, "\x1BO%c", xkey
);
4280 if (wParam
== VK_BACK
&& shift_state
== 0) { /* Backspace */
4281 *p
++ = (conf_get_int(conf
, CONF_bksp_is_delete
) ?
0x7F : 0x08);
4285 if (wParam
== VK_BACK
&& shift_state
== 1) { /* Shift Backspace */
4286 /* We do the opposite of what is configured */
4287 *p
++ = (conf_get_int(conf
, CONF_bksp_is_delete
) ?
0x08 : 0x7F);
4291 if (wParam
== VK_TAB
&& shift_state
== 1) { /* Shift tab */
4297 if (wParam
== VK_SPACE
&& shift_state
== 2) { /* Ctrl-Space */
4301 if (wParam
== VK_SPACE
&& shift_state
== 3) { /* Ctrl-Shift-Space */
4305 if (wParam
== VK_CANCEL
&& shift_state
== 2) { /* Ctrl-Break */
4307 back
->special(backhandle
, TS_BRK
);
4310 if (wParam
== VK_PAUSE
) { /* Break/Pause */
4315 /* Control-2 to Control-8 are special */
4316 if (shift_state
== 2 && wParam
>= '2' && wParam
<= '8') {
4317 *p
++ = "\000\033\034\035\036\037\177"[wParam
- '2'];
4320 if (shift_state
== 2 && (wParam
== 0xBD || wParam
== 0xBF)) {
4324 if (shift_state
== 2 && (wParam
== 0xDF || wParam
== 0xDC)) {
4328 if (shift_state
== 3 && wParam
== 0xDE) {
4329 *p
++ = 0x1E; /* Ctrl-~ == Ctrl-^ in xterm at least */
4332 if (shift_state
== 0 && wParam
== VK_RETURN
&& term
->cr_lf_return
) {
4339 * Next, all the keys that do tilde codes. (ESC '[' nn '~',
4340 * for integer decimal nn.)
4342 * We also deal with the weird ones here. Linux VCs replace F1
4343 * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but
4344 * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w
4350 code
= (keystate
[VK_SHIFT
] & 0x80 ?
23 : 11);
4353 code
= (keystate
[VK_SHIFT
] & 0x80 ?
24 : 12);
4356 code
= (keystate
[VK_SHIFT
] & 0x80 ?
25 : 13);
4359 code
= (keystate
[VK_SHIFT
] & 0x80 ?
26 : 14);
4362 code
= (keystate
[VK_SHIFT
] & 0x80 ?
28 : 15);
4365 code
= (keystate
[VK_SHIFT
] & 0x80 ?
29 : 17);
4368 code
= (keystate
[VK_SHIFT
] & 0x80 ?
31 : 18);
4371 code
= (keystate
[VK_SHIFT
] & 0x80 ?
32 : 19);
4374 code
= (keystate
[VK_SHIFT
] & 0x80 ?
33 : 20);
4377 code
= (keystate
[VK_SHIFT
] & 0x80 ?
34 : 21);
4410 if ((shift_state
&2) == 0) switch (wParam
) {
4430 /* Reorder edit keys to physical order */
4431 if (funky_type
== FUNKY_VT400
&& code
<= 6)
4432 code
= "\0\2\1\4\5\3\6"[code
];
4434 if (term
->vt52_mode
&& code
> 0 && code
<= 6) {
4435 p
+= sprintf((char *) p
, "\x1B%c", " HLMEIG"[code
]);
4439 if (funky_type
== FUNKY_SCO
&& code
>= 11 && code
<= 34) {
4440 /* SCO function keys */
4441 char codes
[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
4444 case VK_F1
: index
= 0; break;
4445 case VK_F2
: index
= 1; break;
4446 case VK_F3
: index
= 2; break;
4447 case VK_F4
: index
= 3; break;
4448 case VK_F5
: index
= 4; break;
4449 case VK_F6
: index
= 5; break;
4450 case VK_F7
: index
= 6; break;
4451 case VK_F8
: index
= 7; break;
4452 case VK_F9
: index
= 8; break;
4453 case VK_F10
: index
= 9; break;
4454 case VK_F11
: index
= 10; break;
4455 case VK_F12
: index
= 11; break;
4457 if (keystate
[VK_SHIFT
] & 0x80) index
+= 12;
4458 if (keystate
[VK_CONTROL
] & 0x80) index
+= 24;
4459 p
+= sprintf((char *) p
, "\x1B[%c", codes
[index
]);
4462 if (funky_type
== FUNKY_SCO
&& /* SCO small keypad */
4463 code
>= 1 && code
<= 6) {
4464 char codes
[] = "HL.FIG";
4468 p
+= sprintf((char *) p
, "\x1B[%c", codes
[code
-1]);
4472 if ((term
->vt52_mode
|| funky_type
== FUNKY_VT100P
) && code
>= 11 && code
<= 24) {
4478 if (term
->vt52_mode
)
4479 p
+= sprintf((char *) p
, "\x1B%c", code
+ 'P' - 11 - offt
);
4482 sprintf((char *) p
, "\x1BO%c", code
+ 'P' - 11 - offt
);
4485 if (funky_type
== FUNKY_LINUX
&& code
>= 11 && code
<= 15) {
4486 p
+= sprintf((char *) p
, "\x1B[[%c", code
+ 'A' - 11);
4489 if (funky_type
== FUNKY_XTERM
&& code
>= 11 && code
<= 14) {
4490 if (term
->vt52_mode
)
4491 p
+= sprintf((char *) p
, "\x1B%c", code
+ 'P' - 11);
4493 p
+= sprintf((char *) p
, "\x1BO%c", code
+ 'P' - 11);
4496 if ((code
== 1 || code
== 4) &&
4497 conf_get_int(conf
, CONF_rxvt_homeend
)) {
4498 p
+= sprintf((char *) p
, code
== 1 ?
"\x1B[H" : "\x1BOw");
4502 p
+= sprintf((char *) p
, "\x1B[%d~", code
);
4507 * Now the remaining keys (arrows and Keypad 5. Keypad 5 for
4508 * some reason seems to send VK_CLEAR to Windows...).
4530 p
+= format_arrow_key(p
, term
, xkey
, shift_state
);
4536 * Finally, deal with Return ourselves. (Win95 seems to
4537 * foul it up when Alt is pressed, for some reason.)
4539 if (wParam
== VK_RETURN
) { /* Return */
4545 if (left_alt
&& wParam
>= VK_NUMPAD0
&& wParam
<= VK_NUMPAD9
)
4546 alt_sum
= alt_sum
* 10 + wParam
- VK_NUMPAD0
;
4551 /* Okay we've done everything interesting; let windows deal with
4552 * the boring stuff */
4556 /* helg: clear CAPS LOCK state if caps lock switches to cyrillic */
4557 if(keystate
[VK_CAPITAL
] != 0 &&
4558 conf_get_int(conf
, CONF_xlat_capslockcyr
)) {
4560 keystate
[VK_CAPITAL
] = 0;
4563 /* XXX how do we know what the max size of the keys array should
4564 * be is? There's indication on MS' website of an Inquire/InquireEx
4565 * functioning returning a KBINFO structure which tells us. */
4566 if (osVersion
.dwPlatformId
== VER_PLATFORM_WIN32_NT
) {
4567 /* XXX 'keys' parameter is declared in MSDN documentation as
4569 * The experience of a French user indicates that on
4570 * Win98, WORD[] should be passed in, but on Win2K, it should
4571 * be BYTE[]. German WinXP and my Win2K with "US International"
4572 * driver corroborate this.
4573 * Experimentally I've conditionalised the behaviour on the
4574 * Win9x/NT split, but I suspect it's worse than that.
4575 * See wishlist item `win-dead-keys' for more horrible detail
4576 * and speculations. */
4579 r
= ToAsciiEx(wParam
, scan
, keystate
, (LPWORD
)keybs
, 0, kbd_layout
);
4580 for (i
=0; i
<3; i
++) keys
[i
] = keybs
[i
];
4582 r
= ToAsciiEx(wParam
, scan
, keystate
, keys
, 0, kbd_layout
);
4584 #ifdef SHOW_TOASCII_RESULT
4585 if (r
== 1 && !key_down
) {
4587 if (in_utf(term
) || ucsdata
.dbcs_screenfont
)
4588 debug((", (U+%04x)", alt_sum
));
4590 debug((", LCH(%d)", alt_sum
));
4592 debug((", ACH(%d)", keys
[0]));
4597 for (r1
= 0; r1
< r
; r1
++) {
4598 debug(("%s%d", r1 ?
"," : "", keys
[r1
]));
4607 * Interrupt an ongoing paste. I'm not sure this is
4608 * sensible, but for the moment it's preferable to
4609 * having to faff about buffering things.
4614 for (i
= 0; i
< r
; i
++) {
4615 unsigned char ch
= (unsigned char) keys
[i
];
4617 if (compose_state
== 2 && (ch
& 0x80) == 0 && ch
> ' ') {
4622 if (compose_state
== 3 && (ch
& 0x80) == 0 && ch
> ' ') {
4626 if ((nc
= check_compose(compose_char
, ch
)) == -1) {
4627 MessageBeep(MB_ICONHAND
);
4631 term_seen_key_event(term
);
4633 luni_send(ldisc
, &keybuf
, 1, 1);
4641 if (in_utf(term
) || ucsdata
.dbcs_screenfont
) {
4643 term_seen_key_event(term
);
4645 luni_send(ldisc
, &keybuf
, 1, 1);
4647 ch
= (char) alt_sum
;
4649 * We need not bother about stdin
4650 * backlogs here, because in GUI PuTTY
4651 * we can't do anything about it
4652 * anyway; there's no means of asking
4653 * Windows to hold off on KEYDOWN
4654 * messages. We _have_ to buffer
4655 * everything we're sent.
4657 term_seen_key_event(term
);
4659 ldisc_send(ldisc
, &ch
, 1, 1);
4663 term_seen_key_event(term
);
4665 lpage_send(ldisc
, kbd_codepage
, &ch
, 1, 1);
4668 if(capsOn
&& ch
< 0x80) {
4671 cbuf
[1] = xlat_uskbd2cyrllic(ch
);
4672 term_seen_key_event(term
);
4674 luni_send(ldisc
, cbuf
+!left_alt
, 1+!!left_alt
, 1);
4679 term_seen_key_event(term
);
4681 lpage_send(ldisc
, kbd_codepage
,
4682 cbuf
+!left_alt
, 1+!!left_alt
, 1);
4688 /* This is so the ALT-Numpad and dead keys work correctly. */
4693 /* If we're definitly not building up an ALT-54321 then clear it */
4696 /* If we will be using alt_sum fix the 256s */
4697 else if (keys
[0] && (in_utf(term
) || ucsdata
.dbcs_screenfont
))
4702 * ALT alone may or may not want to bring up the System menu.
4703 * If it's not meant to, we return 0 on presses or releases of
4704 * ALT, to show that we've swallowed the keystroke. Otherwise
4705 * we return -1, which means Windows will give the keystroke
4706 * its default handling (i.e. bring up the System menu).
4708 if (wParam
== VK_MENU
&& !conf_get_int(conf
, CONF_alt_only
))
4714 void set_title(void *frontend
, char *title
)
4717 window_name
= snewn(1 + strlen(title
), char);
4718 strcpy(window_name
, title
);
4719 if (conf_get_int(conf
, CONF_win_name_always
) || !IsIconic(hwnd
))
4720 SetWindowText(hwnd
, title
);
4723 void set_icon(void *frontend
, char *title
)
4726 icon_name
= snewn(1 + strlen(title
), char);
4727 strcpy(icon_name
, title
);
4728 if (!conf_get_int(conf
, CONF_win_name_always
) && IsIconic(hwnd
))
4729 SetWindowText(hwnd
, title
);
4732 void set_sbar(void *frontend
, int total
, int start
, int page
)
4736 if (!conf_get_int(conf
, is_full_screen() ?
4737 CONF_scrollbar_in_fullscreen
: CONF_scrollbar
))
4740 si
.cbSize
= sizeof(si
);
4741 si
.fMask
= SIF_ALL
| SIF_DISABLENOSCROLL
;
4743 si
.nMax
= total
- 1;
4747 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
4750 Context
get_ctx(void *frontend
)
4756 SelectPalette(hdc
, pal
, FALSE
);
4762 void free_ctx(Context ctx
)
4764 SelectPalette(ctx
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
4765 ReleaseDC(hwnd
, ctx
);
4768 static void real_palette_set(int n
, int r
, int g
, int b
)
4771 logpal
->palPalEntry
[n
].peRed
= r
;
4772 logpal
->palPalEntry
[n
].peGreen
= g
;
4773 logpal
->palPalEntry
[n
].peBlue
= b
;
4774 logpal
->palPalEntry
[n
].peFlags
= PC_NOCOLLAPSE
;
4775 colours
[n
] = PALETTERGB(r
, g
, b
);
4776 SetPaletteEntries(pal
, 0, NALLCOLOURS
, logpal
->palPalEntry
);
4778 colours
[n
] = RGB(r
, g
, b
);
4781 void palette_set(void *frontend
, int n
, int r
, int g
, int b
)
4785 if (n
> NALLCOLOURS
)
4787 real_palette_set(n
, r
, g
, b
);
4789 HDC hdc
= get_ctx(frontend
);
4790 UnrealizeObject(pal
);
4791 RealizePalette(hdc
);
4794 if (n
== (ATTR_DEFBG
>>ATTR_BGSHIFT
))
4795 /* If Default Background changes, we need to ensure any
4796 * space between the text area and the window border is
4798 InvalidateRect(hwnd
, NULL
, TRUE
);
4802 void palette_reset(void *frontend
)
4807 for (i
= 0; i
< NALLCOLOURS
; i
++) {
4809 logpal
->palPalEntry
[i
].peRed
= defpal
[i
].rgbtRed
;
4810 logpal
->palPalEntry
[i
].peGreen
= defpal
[i
].rgbtGreen
;
4811 logpal
->palPalEntry
[i
].peBlue
= defpal
[i
].rgbtBlue
;
4812 logpal
->palPalEntry
[i
].peFlags
= 0;
4813 colours
[i
] = PALETTERGB(defpal
[i
].rgbtRed
,
4814 defpal
[i
].rgbtGreen
,
4815 defpal
[i
].rgbtBlue
);
4817 colours
[i
] = RGB(defpal
[i
].rgbtRed
,
4818 defpal
[i
].rgbtGreen
, defpal
[i
].rgbtBlue
);
4823 SetPaletteEntries(pal
, 0, NALLCOLOURS
, logpal
->palPalEntry
);
4824 hdc
= get_ctx(frontend
);
4825 RealizePalette(hdc
);
4828 /* Default Background may have changed. Ensure any space between
4829 * text area and window border is redrawn. */
4830 InvalidateRect(hwnd
, NULL
, TRUE
);
4834 void write_aclip(void *frontend
, char *data
, int len
, int must_deselect
)
4839 clipdata
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, len
+ 1);
4842 lock
= GlobalLock(clipdata
);
4845 memcpy(lock
, data
, len
);
4846 ((unsigned char *) lock
)[len
] = 0;
4847 GlobalUnlock(clipdata
);
4850 SendMessage(hwnd
, WM_IGNORE_CLIP
, TRUE
, 0);
4852 if (OpenClipboard(hwnd
)) {
4854 SetClipboardData(CF_TEXT
, clipdata
);
4857 GlobalFree(clipdata
);
4860 SendMessage(hwnd
, WM_IGNORE_CLIP
, FALSE
, 0);
4864 * Note: unlike write_aclip() this will not append a nul.
4866 void write_clip(void *frontend
, wchar_t * data
, int *attr
, int len
, int must_deselect
)
4868 HGLOBAL clipdata
, clipdata2
, clipdata3
;
4870 void *lock
, *lock2
, *lock3
;
4872 len2
= WideCharToMultiByte(CP_ACP
, 0, data
, len
, 0, 0, NULL
, NULL
);
4874 clipdata
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
,
4875 len
* sizeof(wchar_t));
4876 clipdata2
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, len2
);
4878 if (!clipdata
|| !clipdata2
) {
4880 GlobalFree(clipdata
);
4882 GlobalFree(clipdata2
);
4885 if (!(lock
= GlobalLock(clipdata
)))
4887 if (!(lock2
= GlobalLock(clipdata2
)))
4890 memcpy(lock
, data
, len
* sizeof(wchar_t));
4891 WideCharToMultiByte(CP_ACP
, 0, data
, len
, lock2
, len2
, NULL
, NULL
);
4893 if (conf_get_int(conf
, CONF_rtf_paste
)) {
4894 wchar_t unitab
[256];
4896 unsigned char *tdata
= (unsigned char *)lock2
;
4897 wchar_t *udata
= (wchar_t *)lock
;
4898 int rtflen
= 0, uindex
= 0, tindex
= 0;
4900 int multilen
, blen
, alen
, totallen
, i
;
4901 char before
[16], after
[4];
4902 int fgcolour
, lastfgcolour
= 0;
4903 int bgcolour
, lastbgcolour
= 0;
4904 int attrBold
, lastAttrBold
= 0;
4905 int attrUnder
, lastAttrUnder
= 0;
4906 int palette
[NALLCOLOURS
];
4908 FontSpec
*font
= conf_get_fontspec(conf
, CONF_font
);
4910 get_unitab(CP_ACP
, unitab
, 0);
4912 rtfsize
= 100 + strlen(font
->name
);
4913 rtf
= snewn(rtfsize
, char);
4914 rtflen
= sprintf(rtf
, "{\\rtf1\\ansi\\deff0{\\fonttbl\\f0\\fmodern %s;}\\f0\\fs%d",
4915 font
->name
, font
->height
*2);
4918 * Add colour palette
4919 * {\colortbl ;\red255\green0\blue0;\red0\green0\blue128;}
4923 * First - Determine all colours in use
4924 * o Foregound and background colours share the same palette
4927 memset(palette
, 0, sizeof(palette
));
4928 for (i
= 0; i
< (len
-1); i
++) {
4929 fgcolour
= ((attr
[i
] & ATTR_FGMASK
) >> ATTR_FGSHIFT
);
4930 bgcolour
= ((attr
[i
] & ATTR_BGMASK
) >> ATTR_BGSHIFT
);
4932 if (attr
[i
] & ATTR_REVERSE
) {
4933 int tmpcolour
= fgcolour
; /* Swap foreground and background */
4934 fgcolour
= bgcolour
;
4935 bgcolour
= tmpcolour
;
4938 if (bold_colours
&& (attr
[i
] & ATTR_BOLD
)) {
4939 if (fgcolour
< 8) /* ANSI colours */
4941 else if (fgcolour
>= 256) /* Default colours */
4945 if (attr
[i
] & ATTR_BLINK
) {
4946 if (bgcolour
< 8) /* ANSI colours */
4948 else if (bgcolour
>= 256) /* Default colours */
4952 palette
[fgcolour
]++;
4953 palette
[bgcolour
]++;
4957 * Next - Create a reduced palette
4960 for (i
= 0; i
< NALLCOLOURS
; i
++) {
4961 if (palette
[i
] != 0)
4962 palette
[i
] = ++numcolours
;
4966 * Finally - Write the colour table
4968 rtf
= sresize(rtf
, rtfsize
+ (numcolours
* 25), char);
4969 strcat(rtf
, "{\\colortbl ;");
4970 rtflen
= strlen(rtf
);
4972 for (i
= 0; i
< NALLCOLOURS
; i
++) {
4973 if (palette
[i
] != 0) {
4974 rtflen
+= sprintf(&rtf
[rtflen
], "\\red%d\\green%d\\blue%d;", defpal
[i
].rgbtRed
, defpal
[i
].rgbtGreen
, defpal
[i
].rgbtBlue
);
4977 strcpy(&rtf
[rtflen
], "}");
4982 * We want to construct a piece of RTF that specifies the
4983 * same Unicode text. To do this we will read back in
4984 * parallel from the Unicode data in `udata' and the
4985 * non-Unicode data in `tdata'. For each character in
4986 * `tdata' which becomes the right thing in `udata' when
4987 * looked up in `unitab', we just copy straight over from
4988 * tdata. For each one that doesn't, we must WCToMB it
4989 * individually and produce a \u escape sequence.
4991 * It would probably be more robust to just bite the bullet
4992 * and WCToMB each individual Unicode character one by one,
4993 * then MBToWC each one back to see if it was an accurate
4994 * translation; but that strikes me as a horrifying number
4995 * of Windows API calls so I want to see if this faster way
4996 * will work. If it screws up badly we can always revert to
4997 * the simple and slow way.
4999 while (tindex
< len2
&& uindex
< len
&&
5000 tdata
[tindex
] && udata
[uindex
]) {
5001 if (tindex
+ 1 < len2
&&
5002 tdata
[tindex
] == '\r' &&
5003 tdata
[tindex
+1] == '\n') {
5009 * Set text attributes
5012 if (rtfsize
< rtflen
+ 64) {
5013 rtfsize
= rtflen
+ 512;
5014 rtf
= sresize(rtf
, rtfsize
, char);
5018 * Determine foreground and background colours
5020 fgcolour
= ((attr
[tindex
] & ATTR_FGMASK
) >> ATTR_FGSHIFT
);
5021 bgcolour
= ((attr
[tindex
] & ATTR_BGMASK
) >> ATTR_BGSHIFT
);
5023 if (attr
[tindex
] & ATTR_REVERSE
) {
5024 int tmpcolour
= fgcolour
; /* Swap foreground and background */
5025 fgcolour
= bgcolour
;
5026 bgcolour
= tmpcolour
;
5029 if (bold_colours
&& (attr
[tindex
] & ATTR_BOLD
)) {
5030 if (fgcolour
< 8) /* ANSI colours */
5032 else if (fgcolour
>= 256) /* Default colours */
5036 if (attr
[tindex
] & ATTR_BLINK
) {
5037 if (bgcolour
< 8) /* ANSI colours */
5039 else if (bgcolour
>= 256) /* Default colours */
5044 * Collect other attributes
5046 if (bold_font_mode
!= BOLD_NONE
)
5047 attrBold
= attr
[tindex
] & ATTR_BOLD
;
5051 attrUnder
= attr
[tindex
] & ATTR_UNDER
;
5055 * o If video isn't reversed, ignore colour attributes for default foregound
5057 * o Special case where bolded text is displayed using the default foregound
5058 * and background colours - force to bolded RTF.
5060 if (!(attr
[tindex
] & ATTR_REVERSE
)) {
5061 if (bgcolour
>= 256) /* Default color */
5062 bgcolour
= -1; /* No coloring */
5064 if (fgcolour
>= 256) { /* Default colour */
5065 if (bold_colours
&& (fgcolour
& 1) && bgcolour
== -1)
5066 attrBold
= ATTR_BOLD
; /* Emphasize text with bold attribute */
5068 fgcolour
= -1; /* No coloring */
5073 * Write RTF text attributes
5075 if (lastfgcolour
!= fgcolour
) {
5076 lastfgcolour
= fgcolour
;
5077 rtflen
+= sprintf(&rtf
[rtflen
], "\\cf%d ", (fgcolour
>= 0) ? palette
[fgcolour
] : 0);
5080 if (lastbgcolour
!= bgcolour
) {
5081 lastbgcolour
= bgcolour
;
5082 rtflen
+= sprintf(&rtf
[rtflen
], "\\highlight%d ", (bgcolour
>= 0) ? palette
[bgcolour
] : 0);
5085 if (lastAttrBold
!= attrBold
) {
5086 lastAttrBold
= attrBold
;
5087 rtflen
+= sprintf(&rtf
[rtflen
], "%s", attrBold ?
"\\b " : "\\b0 ");
5090 if (lastAttrUnder
!= attrUnder
) {
5091 lastAttrUnder
= attrUnder
;
5092 rtflen
+= sprintf(&rtf
[rtflen
], "%s", attrUnder ?
"\\ul " : "\\ulnone ");
5096 if (unitab
[tdata
[tindex
]] == udata
[uindex
]) {
5102 multilen
= WideCharToMultiByte(CP_ACP
, 0, unitab
+uindex
, 1,
5103 NULL
, 0, NULL
, NULL
);
5104 if (multilen
!= 1) {
5105 blen
= sprintf(before
, "{\\uc%d\\u%d", multilen
,
5107 alen
= 1; strcpy(after
, "}");
5109 blen
= sprintf(before
, "\\u%d", udata
[uindex
]);
5110 alen
= 0; after
[0] = '\0';
5113 assert(tindex
+ multilen
<= len2
);
5114 totallen
= blen
+ alen
;
5115 for (i
= 0; i
< multilen
; i
++) {
5116 if (tdata
[tindex
+i
] == '\\' ||
5117 tdata
[tindex
+i
] == '{' ||
5118 tdata
[tindex
+i
] == '}')
5120 else if (tdata
[tindex
+i
] == 0x0D || tdata
[tindex
+i
] == 0x0A)
5121 totallen
+= 6; /* \par\r\n */
5122 else if (tdata
[tindex
+i
] > 0x7E || tdata
[tindex
+i
] < 0x20)
5128 if (rtfsize
< rtflen
+ totallen
+ 3) {
5129 rtfsize
= rtflen
+ totallen
+ 512;
5130 rtf
= sresize(rtf
, rtfsize
, char);
5133 strcpy(rtf
+ rtflen
, before
); rtflen
+= blen
;
5134 for (i
= 0; i
< multilen
; i
++) {
5135 if (tdata
[tindex
+i
] == '\\' ||
5136 tdata
[tindex
+i
] == '{' ||
5137 tdata
[tindex
+i
] == '}') {
5138 rtf
[rtflen
++] = '\\';
5139 rtf
[rtflen
++] = tdata
[tindex
+i
];
5140 } else if (tdata
[tindex
+i
] == 0x0D || tdata
[tindex
+i
] == 0x0A) {
5141 rtflen
+= sprintf(rtf
+rtflen
, "\\par\r\n");
5142 } else if (tdata
[tindex
+i
] > 0x7E || tdata
[tindex
+i
] < 0x20) {
5143 rtflen
+= sprintf(rtf
+rtflen
, "\\'%02x", tdata
[tindex
+i
]);
5145 rtf
[rtflen
++] = tdata
[tindex
+i
];
5148 strcpy(rtf
+ rtflen
, after
); rtflen
+= alen
;
5154 rtf
[rtflen
++] = '}'; /* Terminate RTF stream */
5155 rtf
[rtflen
++] = '\0';
5156 rtf
[rtflen
++] = '\0';
5158 clipdata3
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, rtflen
);
5159 if (clipdata3
&& (lock3
= GlobalLock(clipdata3
)) != NULL
) {
5160 memcpy(lock3
, rtf
, rtflen
);
5161 GlobalUnlock(clipdata3
);
5167 GlobalUnlock(clipdata
);
5168 GlobalUnlock(clipdata2
);
5171 SendMessage(hwnd
, WM_IGNORE_CLIP
, TRUE
, 0);
5173 if (OpenClipboard(hwnd
)) {
5175 SetClipboardData(CF_UNICODETEXT
, clipdata
);
5176 SetClipboardData(CF_TEXT
, clipdata2
);
5178 SetClipboardData(RegisterClipboardFormat(CF_RTF
), clipdata3
);
5181 GlobalFree(clipdata
);
5182 GlobalFree(clipdata2
);
5186 SendMessage(hwnd
, WM_IGNORE_CLIP
, FALSE
, 0);
5189 static DWORD WINAPI
clipboard_read_threadfunc(void *param
)
5191 HWND hwnd
= (HWND
)param
;
5194 if (OpenClipboard(NULL
)) {
5195 if ((clipdata
= GetClipboardData(CF_UNICODETEXT
))) {
5196 SendMessage(hwnd
, WM_GOT_CLIPDATA
, (WPARAM
)1, (LPARAM
)clipdata
);
5197 } else if ((clipdata
= GetClipboardData(CF_TEXT
))) {
5198 SendMessage(hwnd
, WM_GOT_CLIPDATA
, (WPARAM
)0, (LPARAM
)clipdata
);
5206 static int process_clipdata(HGLOBAL clipdata
, int unicode
)
5208 sfree(clipboard_contents
);
5209 clipboard_contents
= NULL
;
5210 clipboard_length
= 0;
5213 wchar_t *p
= GlobalLock(clipdata
);
5217 /* Unwilling to rely on Windows having wcslen() */
5218 for (p2
= p
; *p2
; p2
++);
5219 clipboard_length
= p2
- p
;
5220 clipboard_contents
= snewn(clipboard_length
+ 1, wchar_t);
5221 memcpy(clipboard_contents
, p
, clipboard_length
* sizeof(wchar_t));
5222 clipboard_contents
[clipboard_length
] = L
'\0';
5226 char *s
= GlobalLock(clipdata
);
5230 i
= MultiByteToWideChar(CP_ACP
, 0, s
, strlen(s
) + 1, 0, 0);
5231 clipboard_contents
= snewn(i
, wchar_t);
5232 MultiByteToWideChar(CP_ACP
, 0, s
, strlen(s
) + 1,
5233 clipboard_contents
, i
);
5234 clipboard_length
= i
- 1;
5235 clipboard_contents
[clipboard_length
] = L
'\0';
5243 void request_paste(void *frontend
)
5246 * I always thought pasting was synchronous in Windows; the
5247 * clipboard access functions certainly _look_ synchronous,
5248 * unlike the X ones. But in fact it seems that in some
5249 * situations the contents of the clipboard might not be
5250 * immediately available, and the clipboard-reading functions
5251 * may block. This leads to trouble if the application
5252 * delivering the clipboard data has to get hold of it by -
5253 * for example - talking over a network connection which is
5254 * forwarded through this very PuTTY.
5256 * Hence, we spawn a subthread to read the clipboard, and do
5257 * our paste when it's finished. The thread will send a
5258 * message back to our main window when it terminates, and
5259 * that tells us it's OK to paste.
5261 DWORD in_threadid
; /* required for Win9x */
5262 CreateThread(NULL
, 0, clipboard_read_threadfunc
,
5263 hwnd
, 0, &in_threadid
);
5266 void get_clip(void *frontend
, wchar_t **p
, int *len
)
5269 *p
= clipboard_contents
;
5270 *len
= clipboard_length
;
5276 * Move `lines' lines from position `from' to position `to' in the
5279 void optimised_move(void *frontend
, int to
, int from
, int lines
)
5284 min
= (to
< from ? to
: from
);
5285 max
= to
+ from
- min
;
5287 r
.left
= offset_width
;
5288 r
.right
= offset_width
+ term
->cols
* font_width
;
5289 r
.top
= offset_height
+ min
* font_height
;
5290 r
.bottom
= offset_height
+ (max
+ lines
) * font_height
;
5291 ScrollWindow(hwnd
, 0, (to
- from
) * font_height
, &r
, &r
);
5296 * Print a message box and perform a fatal exit.
5298 void fatalbox(char *fmt
, ...)
5301 char *stuff
, morestuff
[100];
5304 stuff
= dupvprintf(fmt
, ap
);
5306 sprintf(morestuff
, "%.70s Fatal Error", appname
);
5307 MessageBox(hwnd
, stuff
, morestuff
, MB_ICONERROR
| MB_OK
);
5313 * Print a modal (Really Bad) message box and perform a fatal exit.
5315 void modalfatalbox(char *fmt
, ...)
5318 char *stuff
, morestuff
[100];
5321 stuff
= dupvprintf(fmt
, ap
);
5323 sprintf(morestuff
, "%.70s Fatal Error", appname
);
5324 MessageBox(hwnd
, stuff
, morestuff
,
5325 MB_SYSTEMMODAL
| MB_ICONERROR
| MB_OK
);
5330 DECL_WINDOWS_FUNCTION(static, BOOL
, FlashWindowEx
, (PFLASHWINFO
));
5332 static void init_flashwindow(void)
5334 HMODULE user32_module
= load_system32_dll("user32.dll");
5335 GET_WINDOWS_FUNCTION(user32_module
, FlashWindowEx
);
5338 static BOOL
flash_window_ex(DWORD dwFlags
, UINT uCount
, DWORD dwTimeout
)
5340 if (p_FlashWindowEx
) {
5342 fi
.cbSize
= sizeof(fi
);
5344 fi
.dwFlags
= dwFlags
;
5346 fi
.dwTimeout
= dwTimeout
;
5347 return (*p_FlashWindowEx
)(&fi
);
5350 return FALSE
; /* shrug */
5353 static void flash_window(int mode
);
5354 static long next_flash
;
5355 static int flashing
= 0;
5358 * Timer for platforms where we must maintain window flashing manually
5361 static void flash_window_timer(void *ctx
, unsigned long now
)
5363 if (flashing
&& now
== next_flash
) {
5369 * Manage window caption / taskbar flashing, if enabled.
5370 * 0 = stop, 1 = maintain, 2 = start
5372 static void flash_window(int mode
)
5374 int beep_ind
= conf_get_int(conf
, CONF_beep_ind
);
5375 if ((mode
== 0) || (beep_ind
== B_IND_DISABLED
)) {
5379 if (p_FlashWindowEx
)
5380 flash_window_ex(FLASHW_STOP
, 0, 0);
5382 FlashWindow(hwnd
, FALSE
);
5385 } else if (mode
== 2) {
5389 if (p_FlashWindowEx
) {
5390 /* For so-called "steady" mode, we use uCount=2, which
5391 * seems to be the traditional number of flashes used
5392 * by user notifications (e.g., by Explorer).
5393 * uCount=0 appears to enable continuous flashing, per
5394 * "flashing" mode, although I haven't seen this
5396 flash_window_ex(FLASHW_ALL
| FLASHW_TIMER
,
5397 (beep_ind
== B_IND_FLASH ?
0 : 2),
5398 0 /* system cursor blink rate */);
5399 /* No need to schedule timer */
5401 FlashWindow(hwnd
, TRUE
);
5402 next_flash
= schedule_timer(450, flash_window_timer
, hwnd
);
5406 } else if ((mode
== 1) && (beep_ind
== B_IND_FLASH
)) {
5408 if (flashing
&& !p_FlashWindowEx
) {
5409 FlashWindow(hwnd
, TRUE
); /* toggle */
5410 next_flash
= schedule_timer(450, flash_window_timer
, hwnd
);
5418 void do_beep(void *frontend
, int mode
)
5420 if (mode
== BELL_DEFAULT
) {
5422 * For MessageBeep style bells, we want to be careful of
5423 * timing, because they don't have the nice property of
5424 * PlaySound bells that each one cancels the previous
5425 * active one. So we limit the rate to one per 50ms or so.
5427 static long lastbeep
= 0;
5430 beepdiff
= GetTickCount() - lastbeep
;
5431 if (beepdiff
>= 0 && beepdiff
< 50)
5435 * The above MessageBeep call takes time, so we record the
5436 * time _after_ it finishes rather than before it starts.
5438 lastbeep
= GetTickCount();
5439 } else if (mode
== BELL_WAVEFILE
) {
5440 Filename
*bell_wavefile
= conf_get_filename(conf
, CONF_bell_wavefile
);
5441 if (!PlaySound(bell_wavefile
->path
, NULL
,
5442 SND_ASYNC
| SND_FILENAME
)) {
5443 char buf
[sizeof(bell_wavefile
->path
) + 80];
5445 sprintf(buf
, "Unable to play sound file\n%s\n"
5446 "Using default sound instead", bell_wavefile
->path
);
5447 sprintf(otherbuf
, "%.70s Sound Error", appname
);
5448 MessageBox(hwnd
, buf
, otherbuf
,
5449 MB_OK
| MB_ICONEXCLAMATION
);
5450 conf_set_int(conf
, CONF_beep
, BELL_DEFAULT
);
5452 } else if (mode
== BELL_PCSPEAKER
) {
5453 static long lastbeep
= 0;
5456 beepdiff
= GetTickCount() - lastbeep
;
5457 if (beepdiff
>= 0 && beepdiff
< 50)
5461 * We must beep in different ways depending on whether this
5462 * is a 95-series or NT-series OS.
5464 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
5468 lastbeep
= GetTickCount();
5470 /* Otherwise, either visual bell or disabled; do nothing here */
5471 if (!term
->has_focus
) {
5472 flash_window(2); /* start */
5477 * Minimise or restore the window in response to a server-side
5480 void set_iconic(void *frontend
, int iconic
)
5482 if (IsIconic(hwnd
)) {
5484 ShowWindow(hwnd
, SW_RESTORE
);
5487 ShowWindow(hwnd
, SW_MINIMIZE
);
5492 * Move the window in response to a server-side request.
5494 void move_window(void *frontend
, int x
, int y
)
5496 int resize_action
= conf_get_int(conf
, CONF_resize_action
);
5497 if (resize_action
== RESIZE_DISABLED
||
5498 resize_action
== RESIZE_FONT
||
5502 SetWindowPos(hwnd
, NULL
, x
, y
, 0, 0, SWP_NOSIZE
| SWP_NOZORDER
);
5506 * Move the window to the top or bottom of the z-order in response
5507 * to a server-side request.
5509 void set_zorder(void *frontend
, int top
)
5511 if (conf_get_int(conf
, CONF_alwaysontop
))
5512 return; /* ignore */
5513 SetWindowPos(hwnd
, top ? HWND_TOP
: HWND_BOTTOM
, 0, 0, 0, 0,
5514 SWP_NOMOVE
| SWP_NOSIZE
);
5518 * Refresh the window in response to a server-side request.
5520 void refresh_window(void *frontend
)
5522 InvalidateRect(hwnd
, NULL
, TRUE
);
5526 * Maximise or restore the window in response to a server-side
5529 void set_zoomed(void *frontend
, int zoomed
)
5531 if (IsZoomed(hwnd
)) {
5533 ShowWindow(hwnd
, SW_RESTORE
);
5536 ShowWindow(hwnd
, SW_MAXIMIZE
);
5541 * Report whether the window is iconic, for terminal reports.
5543 int is_iconic(void *frontend
)
5545 return IsIconic(hwnd
);
5549 * Report the window's position, for terminal reports.
5551 void get_window_pos(void *frontend
, int *x
, int *y
)
5554 GetWindowRect(hwnd
, &r
);
5560 * Report the window's pixel size, for terminal reports.
5562 void get_window_pixels(void *frontend
, int *x
, int *y
)
5565 GetWindowRect(hwnd
, &r
);
5566 *x
= r
.right
- r
.left
;
5567 *y
= r
.bottom
- r
.top
;
5571 * Return the window or icon title.
5573 char *get_window_title(void *frontend
, int icon
)
5575 return icon ? icon_name
: window_name
;
5579 * See if we're in full-screen mode.
5581 static int is_full_screen()
5583 if (!IsZoomed(hwnd
))
5585 if (GetWindowLongPtr(hwnd
, GWL_STYLE
) & WS_CAPTION
)
5590 /* Get the rect/size of a full screen window using the nearest available
5591 * monitor in multimon systems; default to something sensible if only
5592 * one monitor is present. */
5593 static int get_fullscreen_rect(RECT
* ss
)
5595 #if defined(MONITOR_DEFAULTTONEAREST) && !defined(NO_MULTIMON)
5598 mon
= MonitorFromWindow(hwnd
, MONITOR_DEFAULTTONEAREST
);
5599 mi
.cbSize
= sizeof(mi
);
5600 GetMonitorInfo(mon
, &mi
);
5602 /* structure copy */
5606 /* could also use code like this:
5607 ss->left = ss->top = 0;
5608 ss->right = GetSystemMetrics(SM_CXSCREEN);
5609 ss->bottom = GetSystemMetrics(SM_CYSCREEN);
5611 return GetClientRect(GetDesktopWindow(), ss
);
5617 * Go full-screen. This should only be called when we are already
5620 static void make_full_screen()
5625 assert(IsZoomed(hwnd
));
5627 if (is_full_screen())
5630 /* Remove the window furniture. */
5631 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
5632 style
&= ~(WS_CAPTION
| WS_BORDER
| WS_THICKFRAME
);
5633 if (conf_get_int(conf
, CONF_scrollbar_in_fullscreen
))
5634 style
|= WS_VSCROLL
;
5636 style
&= ~WS_VSCROLL
;
5637 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
);
5639 /* Resize ourselves to exactly cover the nearest monitor. */
5640 get_fullscreen_rect(&ss
);
5641 SetWindowPos(hwnd
, HWND_TOP
, ss
.left
, ss
.top
,
5646 /* We may have changed size as a result */
5650 /* Tick the menu item in the System and context menus. */
5653 for (i
= 0; i
< lenof(popup_menus
); i
++)
5654 CheckMenuItem(popup_menus
[i
].menu
, IDM_FULLSCREEN
, MF_CHECKED
);
5659 * Clear the full-screen attributes.
5661 static void clear_full_screen()
5663 DWORD oldstyle
, style
;
5665 /* Reinstate the window furniture. */
5666 style
= oldstyle
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
5667 style
|= WS_CAPTION
| WS_BORDER
;
5668 if (conf_get_int(conf
, CONF_resize_action
) == RESIZE_DISABLED
)
5669 style
&= ~WS_THICKFRAME
;
5671 style
|= WS_THICKFRAME
;
5672 if (conf_get_int(conf
, CONF_scrollbar
))
5673 style
|= WS_VSCROLL
;
5675 style
&= ~WS_VSCROLL
;
5676 if (style
!= oldstyle
) {
5677 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
);
5678 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
5679 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
5683 /* Untick the menu item in the System and context menus. */
5686 for (i
= 0; i
< lenof(popup_menus
); i
++)
5687 CheckMenuItem(popup_menus
[i
].menu
, IDM_FULLSCREEN
, MF_UNCHECKED
);
5692 * Toggle full-screen mode.
5694 static void flip_full_screen()
5696 if (is_full_screen()) {
5697 ShowWindow(hwnd
, SW_RESTORE
);
5698 } else if (IsZoomed(hwnd
)) {
5701 SendMessage(hwnd
, WM_FULLSCR_ON_MAX
, 0, 0);
5702 ShowWindow(hwnd
, SW_MAXIMIZE
);
5706 void frontend_keypress(void *handle
)
5709 * Keypress termination in non-Close-On-Exit mode is not
5710 * currently supported in PuTTY proper, because the window
5711 * always has a perfectly good Close button anyway. So we do
5717 int from_backend(void *frontend
, int is_stderr
, const char *data
, int len
)
5719 return term_data(term
, is_stderr
, data
, len
);
5722 int from_backend_untrusted(void *frontend
, const char *data
, int len
)
5724 return term_data_untrusted(term
, data
, len
);
5727 int from_backend_eof(void *frontend
)
5729 return TRUE
; /* do respond to incoming EOF with outgoing */
5732 int get_userpass_input(prompts_t
*p
, unsigned char *in
, int inlen
)
5735 ret
= cmdline_get_passwd_input(p
, in
, inlen
);
5737 ret
= term_get_userpass_input(term
, p
, in
, inlen
);
5741 void agent_schedule_callback(void (*callback
)(void *, void *, int),
5742 void *callback_ctx
, void *data
, int len
)
5744 struct agent_callback
*c
= snew(struct agent_callback
);
5745 c
->callback
= callback
;
5746 c
->callback_ctx
= callback_ctx
;
5749 PostMessage(hwnd
, WM_AGENT_CALLBACK
, 0, (LPARAM
)c
);