20 #define PUTTY_DO_GLOBALS /* actually _define_ globals */
26 #define IDM_SHOWLOG 0x0010
27 #define IDM_NEWSESS 0x0020
28 #define IDM_DUPSESS 0x0030
29 #define IDM_RECONF 0x0040
30 #define IDM_CLRSB 0x0050
31 #define IDM_RESET 0x0060
32 #define IDM_TEL_AYT 0x0070
33 #define IDM_TEL_BRK 0x0080
34 #define IDM_TEL_SYNCH 0x0090
35 #define IDM_TEL_EC 0x00a0
36 #define IDM_TEL_EL 0x00b0
37 #define IDM_TEL_GA 0x00c0
38 #define IDM_TEL_NOP 0x00d0
39 #define IDM_TEL_ABORT 0x00e0
40 #define IDM_TEL_AO 0x00f0
41 #define IDM_TEL_IP 0x0100
42 #define IDM_TEL_SUSP 0x0110
43 #define IDM_TEL_EOR 0x0120
44 #define IDM_TEL_EOF 0x0130
45 #define IDM_HELP 0x0140
46 #define IDM_ABOUT 0x0150
47 #define IDM_SAVEDSESS 0x0160
48 #define IDM_COPYALL 0x0170
49 #define IDM_FULLSCREEN 0x0180
51 #define IDM_SESSLGP 0x0250 /* log type printable */
52 #define IDM_SESSLGA 0x0260 /* log type all chars */
53 #define IDM_SESSLGE 0x0270 /* log end */
54 #define IDM_SAVED_MIN 0x1000
55 #define IDM_SAVED_MAX 0x2000
57 #define WM_IGNORE_CLIP (WM_XUSER + 2)
59 /* Needed for Chinese support and apparently not always defined. */
61 #define VK_PROCESSKEY 0xE5
64 /* Needed for mouse wheel support and not defined in earlier SDKs. */
66 #define WM_MOUSEWHEEL 0x020A
69 static LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
70 static int TranslateKey(UINT message
, WPARAM wParam
, LPARAM lParam
,
71 unsigned char *output
);
72 static void cfgtopalette(void);
73 static void init_palette(void);
74 static void init_fonts(int, int);
75 static void another_font(int);
76 static void deinit_fonts(void);
77 static void set_input_locale(HKL
);
79 /* Window layout information */
80 static void reset_window(int);
81 static int full_screen
= 0;
82 static int extra_width
, extra_height
;
83 static int font_width
, font_height
, font_dualwidth
;
84 static int offset_width
, offset_height
;
85 static int was_zoomed
= 0;
86 static int prev_rows
, prev_cols
;
88 static int pending_netevent
= 0;
89 static WPARAM pend_netevent_wParam
= 0;
90 static LPARAM pend_netevent_lParam
= 0;
91 static void enact_pending_netevent(void);
92 static void flash_window(int mode
);
93 static void flip_full_screen(void);
95 static time_t last_movement
= 0;
99 #define FONT_UNDERLINE 2
100 #define FONT_BOLDUND 3
101 #define FONT_WIDE 0x04
102 #define FONT_HIGH 0x08
103 #define FONT_NARROW 0x10
105 #define FONT_OEM 0x20
106 #define FONT_OEMBOLD 0x21
107 #define FONT_OEMUND 0x22
108 #define FONT_OEMBOLDUND 0x23
110 #define FONT_MAXNO 0x2F
112 static HFONT fonts
[FONT_MAXNO
];
113 static LOGFONT lfont
;
114 static int fontflag
[FONT_MAXNO
];
116 BOLD_COLOURS
, BOLD_SHADOW
, BOLD_FONT
124 static COLORREF colours
[NCOLOURS
];
126 static LPLOGPALETTE logpal
;
127 static RGBTRIPLE defpal
[NCOLOURS
];
131 static HBITMAP caretbm
;
133 static int dbltime
, lasttime
, lastact
;
134 static Mouse_Button lastbtn
;
136 /* this allows xterm-style mouse handling. */
137 static int send_raw_mouse
= 0;
138 static int wheel_accumulator
= 0;
140 static char *window_name
, *icon_name
;
142 static int compose_state
= 0;
144 static OSVERSIONINFO osVersion
;
146 /* Dummy routine, only required in plink. */
147 void ldisc_update(int echo
, int edit
)
151 int WINAPI
WinMain(HINSTANCE inst
, HINSTANCE prev
, LPSTR cmdline
, int show
)
153 static char appname
[] = "PuTTY";
158 int guess_width
, guess_height
;
161 flags
= FLAG_VERBOSE
| FLAG_INTERACTIVE
;
163 winsock_ver
= MAKEWORD(1, 1);
164 if (WSAStartup(winsock_ver
, &wsadata
)) {
165 MessageBox(NULL
, "Unable to initialise WinSock", "WinSock Error",
166 MB_OK
| MB_ICONEXCLAMATION
);
169 if (LOBYTE(wsadata
.wVersion
) != 1 || HIBYTE(wsadata
.wVersion
) != 1) {
170 MessageBox(NULL
, "WinSock version is incompatible with 1.1",
171 "WinSock Error", MB_OK
| MB_ICONEXCLAMATION
);
175 /* WISHLIST: maybe allow config tweaking even if winsock not present? */
178 InitCommonControls();
180 /* Ensure a Maximize setting in Explorer doesn't maximise the
185 ZeroMemory(&osVersion
, sizeof(osVersion
));
186 osVersion
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
187 if (!GetVersionEx ( (OSVERSIONINFO
*) &osVersion
)) {
188 MessageBox(NULL
, "Windows refuses to report a version",
189 "PuTTY Fatal Error", MB_OK
| MB_ICONEXCLAMATION
);
195 * See if we can find our Help file.
198 char b
[2048], *p
, *q
, *r
;
200 GetModuleFileName(NULL
, b
, sizeof(b
) - 1);
202 p
= strrchr(b
, '\\');
203 if (p
&& p
>= r
) r
= p
+1;
205 if (q
&& q
>= r
) r
= q
+1;
206 strcpy(r
, "putty.hlp");
207 if ( (fp
= fopen(b
, "r")) != NULL
) {
208 help_path
= dupstr(b
);
212 strcpy(r
, "putty.cnt");
213 if ( (fp
= fopen(b
, "r")) != NULL
) {
214 help_has_contents
= TRUE
;
217 help_has_contents
= FALSE
;
221 * Process the command line.
226 default_protocol
= DEFAULT_PROTOCOL
;
227 default_port
= DEFAULT_PORT
;
228 cfg
.logtype
= LGTYP_NONE
;
230 do_defaults(NULL
, &cfg
);
233 while (*p
&& isspace(*p
))
237 * Process command line options first. Yes, this can be
238 * done better, and it will be as soon as I have the
242 char *q
= p
+ strcspn(p
, " \t");
245 tolower(p
[0]) == 's' &&
246 tolower(p
[1]) == 's' && tolower(p
[2]) == 'h') {
247 default_protocol
= cfg
.protocol
= PROT_SSH
;
248 default_port
= cfg
.port
= 22;
249 } else if (q
== p
+ 7 &&
250 tolower(p
[0]) == 'c' &&
251 tolower(p
[1]) == 'l' &&
252 tolower(p
[2]) == 'e' &&
253 tolower(p
[3]) == 'a' &&
254 tolower(p
[4]) == 'n' &&
255 tolower(p
[5]) == 'u' && tolower(p
[6]) == 'p') {
257 * `putty -cleanup'. Remove all registry entries
258 * associated with PuTTY, and also find and delete
259 * the random seed file.
262 "This procedure will remove ALL Registry\n"
263 "entries associated with PuTTY, and will\n"
264 "also remove the PuTTY random seed file.\n"
266 "THIS PROCESS WILL DESTROY YOUR SAVED\n"
267 "SESSIONS. Are you really sure you want\n"
270 MB_YESNO
| MB_ICONWARNING
) == IDYES
) {
275 p
= q
+ strspn(q
, " \t");
279 * An initial @ means to activate a saved session.
283 while (i
> 1 && isspace(p
[i
- 1]))
286 do_defaults(p
+ 1, &cfg
);
287 if (!*cfg
.host
&& !do_config()) {
291 } else if (*p
== '&') {
293 * An initial & means we've been given a command line
294 * containing the hex value of a HANDLE for a file
295 * mapping object, which we must then extract as a
300 if (sscanf(p
+ 1, "%p", &filemap
) == 1 &&
301 (cp
= MapViewOfFile(filemap
, FILE_MAP_READ
,
302 0, 0, sizeof(Config
))) != NULL
) {
305 CloseHandle(filemap
);
306 } else if (!do_config()) {
313 * If the hostname starts with "telnet:", set the
314 * protocol to Telnet and process the string as a
317 if (!strncmp(q
, "telnet:", 7)) {
321 if (q
[0] == '/' && q
[1] == '/')
323 cfg
.protocol
= PROT_TELNET
;
325 while (*p
&& *p
!= ':' && *p
!= '/')
334 strncpy(cfg
.host
, q
, sizeof(cfg
.host
) - 1);
335 cfg
.host
[sizeof(cfg
.host
) - 1] = '\0';
337 while (*p
&& !isspace(*p
))
341 strncpy(cfg
.host
, q
, sizeof(cfg
.host
) - 1);
342 cfg
.host
[sizeof(cfg
.host
) - 1] = '\0';
343 while (*p
&& isspace(*p
))
358 * Trim leading whitespace off the hostname if it's there.
361 int space
= strspn(cfg
.host
, " \t");
362 memmove(cfg
.host
, cfg
.host
+space
, 1+strlen(cfg
.host
)-space
);
365 /* See if host is of the form user@host */
366 if (cfg
.host
[0] != '\0') {
367 char *atsign
= strchr(cfg
.host
, '@');
368 /* Make sure we're not overflowing the user field */
370 if (atsign
- cfg
.host
< sizeof cfg
.username
) {
371 strncpy(cfg
.username
, cfg
.host
, atsign
- cfg
.host
);
372 cfg
.username
[atsign
- cfg
.host
] = '\0';
374 memmove(cfg
.host
, atsign
+ 1, 1 + strlen(atsign
+ 1));
379 * Trim a colon suffix off the hostname if it's there.
381 cfg
.host
[strcspn(cfg
.host
, ":")] = '\0';
385 * Select protocol. This is farmed out into a table in a
386 * separate file to enable an ssh-free variant.
391 for (i
= 0; backends
[i
].backend
!= NULL
; i
++)
392 if (backends
[i
].protocol
== cfg
.protocol
) {
393 back
= backends
[i
].backend
;
397 MessageBox(NULL
, "Unsupported protocol number found",
398 "PuTTY Internal Error", MB_OK
| MB_ICONEXCLAMATION
);
404 /* Check for invalid Port number (i.e. zero) */
406 MessageBox(NULL
, "Invalid Port Number",
407 "PuTTY Internal Error", MB_OK
| MB_ICONEXCLAMATION
);
414 wndclass
.lpfnWndProc
= WndProc
;
415 wndclass
.cbClsExtra
= 0;
416 wndclass
.cbWndExtra
= 0;
417 wndclass
.hInstance
= inst
;
418 wndclass
.hIcon
= LoadIcon(inst
, MAKEINTRESOURCE(IDI_MAINICON
));
419 wndclass
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
420 wndclass
.hbrBackground
= NULL
;
421 wndclass
.lpszMenuName
= NULL
;
422 wndclass
.lpszClassName
= appname
;
424 RegisterClass(&wndclass
);
429 savelines
= cfg
.savelines
;
435 * Guess some defaults for the window size. This all gets
436 * updated later, so we don't really care too much. However, we
437 * do want the font width/height guesses to correspond to a
438 * large font rather than a small one...
445 term_size(cfg
.height
, cfg
.width
, cfg
.savelines
);
446 guess_width
= extra_width
+ font_width
* cols
;
447 guess_height
= extra_height
+ font_height
* rows
;
450 HWND w
= GetDesktopWindow();
451 GetWindowRect(w
, &r
);
452 if (guess_width
> r
.right
- r
.left
)
453 guess_width
= r
.right
- r
.left
;
454 if (guess_height
> r
.bottom
- r
.top
)
455 guess_height
= r
.bottom
- r
.top
;
459 int winmode
= WS_OVERLAPPEDWINDOW
| WS_VSCROLL
;
462 winmode
&= ~(WS_VSCROLL
);
463 if (cfg
.resize_action
== RESIZE_DISABLED
)
464 winmode
&= ~(WS_THICKFRAME
| WS_MAXIMIZEBOX
);
466 exwinmode
|= WS_EX_TOPMOST
;
468 exwinmode
|= WS_EX_CLIENTEDGE
;
469 hwnd
= CreateWindowEx(exwinmode
, appname
, appname
,
470 winmode
, CW_USEDEFAULT
, CW_USEDEFAULT
,
471 guess_width
, guess_height
,
472 NULL
, NULL
, inst
, NULL
);
476 * Initialise the fonts, simultaneously correcting the guesses
477 * for font_{width,height}.
482 * Correct the guesses for extra_{width,height}.
486 GetWindowRect(hwnd
, &wr
);
487 GetClientRect(hwnd
, &cr
);
488 offset_width
= offset_height
= cfg
.window_border
;
489 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+ offset_width
*2;
490 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
494 * Resize the window, now we know what size we _really_ want it
497 guess_width
= extra_width
+ font_width
* cols
;
498 guess_height
= extra_height
+ font_height
* rows
;
499 SetWindowPos(hwnd
, NULL
, 0, 0, guess_width
, guess_height
,
500 SWP_NOMOVE
| SWP_NOREDRAW
| SWP_NOZORDER
);
503 * Set up a caret bitmap, with no content.
507 int size
= (font_width
+ 15) / 16 * 2 * font_height
;
508 bits
= smalloc(size
);
509 memset(bits
, 0, size
);
510 caretbm
= CreateBitmap(font_width
, font_height
, 1, 1, bits
);
513 CreateCaret(hwnd
, caretbm
, font_width
, font_height
);
516 * Initialise the scroll bar.
521 si
.cbSize
= sizeof(si
);
522 si
.fMask
= SIF_ALL
| SIF_DISABLENOSCROLL
;
527 SetScrollInfo(hwnd
, SB_VERT
, &si
, FALSE
);
531 * Start up the telnet connection.
535 char msg
[1024], *title
;
538 error
= back
->init(cfg
.host
, cfg
.port
, &realhost
, cfg
.tcp_nodelay
);
540 sprintf(msg
, "Unable to open connection to\n"
541 "%.800s\n" "%s", cfg
.host
, error
);
542 MessageBox(NULL
, msg
, "PuTTY Error", MB_ICONERROR
| MB_OK
);
545 window_name
= icon_name
= NULL
;
547 title
= cfg
.wintitle
;
549 sprintf(msg
, "%s - PuTTY", realhost
);
557 session_closed
= FALSE
;
560 * Prepare the mouse handler.
562 lastact
= MA_NOTHING
;
563 lastbtn
= MBT_NOTHING
;
564 dbltime
= GetDoubleClickTime();
567 * Set up the session-control options on the system menu.
570 HMENU m
= GetSystemMenu(hwnd
, FALSE
);
574 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
575 if (cfg
.protocol
== PROT_TELNET
) {
577 AppendMenu(p
, MF_ENABLED
, IDM_TEL_AYT
, "Are You There");
578 AppendMenu(p
, MF_ENABLED
, IDM_TEL_BRK
, "Break");
579 AppendMenu(p
, MF_ENABLED
, IDM_TEL_SYNCH
, "Synch");
580 AppendMenu(p
, MF_SEPARATOR
, 0, 0);
581 AppendMenu(p
, MF_ENABLED
, IDM_TEL_EC
, "Erase Character");
582 AppendMenu(p
, MF_ENABLED
, IDM_TEL_EL
, "Erase Line");
583 AppendMenu(p
, MF_ENABLED
, IDM_TEL_GA
, "Go Ahead");
584 AppendMenu(p
, MF_ENABLED
, IDM_TEL_NOP
, "No Operation");
585 AppendMenu(p
, MF_SEPARATOR
, 0, 0);
586 AppendMenu(p
, MF_ENABLED
, IDM_TEL_ABORT
, "Abort Process");
587 AppendMenu(p
, MF_ENABLED
, IDM_TEL_AO
, "Abort Output");
588 AppendMenu(p
, MF_ENABLED
, IDM_TEL_IP
, "Interrupt Process");
589 AppendMenu(p
, MF_ENABLED
, IDM_TEL_SUSP
, "Suspend Process");
590 AppendMenu(p
, MF_SEPARATOR
, 0, 0);
591 AppendMenu(p
, MF_ENABLED
, IDM_TEL_EOR
, "End Of Record");
592 AppendMenu(p
, MF_ENABLED
, IDM_TEL_EOF
, "End Of File");
593 AppendMenu(m
, MF_POPUP
| MF_ENABLED
, (UINT
) p
,
595 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
597 AppendMenu(m
, MF_ENABLED
, IDM_SHOWLOG
, "&Event Log");
598 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
599 AppendMenu(m
, MF_ENABLED
, IDM_NEWSESS
, "Ne&w Session...");
600 AppendMenu(m
, MF_ENABLED
, IDM_DUPSESS
, "&Duplicate Session");
603 for (i
= 1; i
< ((nsessions
< 256) ? nsessions
: 256); i
++)
604 AppendMenu(s
, MF_ENABLED
, IDM_SAVED_MIN
+ (16 * i
),
606 AppendMenu(m
, MF_POPUP
| MF_ENABLED
, (UINT
) s
, "Sa&ved Sessions");
607 AppendMenu(m
, MF_ENABLED
, IDM_RECONF
, "Chan&ge Settings...");
608 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
609 AppendMenu(m
, MF_ENABLED
, IDM_COPYALL
, "C&opy All to Clipboard");
610 AppendMenu(m
, MF_ENABLED
, IDM_CLRSB
, "C&lear Scrollback");
611 AppendMenu(m
, MF_ENABLED
, IDM_RESET
, "Rese&t Terminal");
612 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
613 AppendMenu(m
, (cfg
.resize_action
== RESIZE_DISABLED
) ?
614 MF_GRAYED
: MF_ENABLED
, IDM_FULLSCREEN
, "&Full Screen");
615 AppendMenu(m
, MF_SEPARATOR
, 0, 0);
617 AppendMenu(m
, MF_ENABLED
, IDM_HELP
, "&Help");
618 AppendMenu(m
, MF_ENABLED
, IDM_ABOUT
, "&About PuTTY");
622 * Set up the initial input locale.
624 set_input_locale(GetKeyboardLayout(0));
627 * Finally show the window!
629 ShowWindow(hwnd
, show
);
630 SetForegroundWindow(hwnd
);
633 * Open the initial log file if there is one.
638 * Set the palette up.
644 has_focus
= (GetForegroundWindow() == hwnd
);
647 if (GetMessage(&msg
, NULL
, 0, 0) == 1) {
648 int timer_id
= 0, long_timer
= 0;
650 while (msg
.message
!= WM_QUIT
) {
651 /* Sometimes DispatchMessage calls routines that use their own
652 * GetMessage loop, setup this timer so we get some control back.
654 * Also call term_update() from the timer so that if the host
655 * is sending data flat out we still do redraws.
657 if (timer_id
&& long_timer
) {
658 KillTimer(hwnd
, timer_id
);
659 long_timer
= timer_id
= 0;
662 timer_id
= SetTimer(hwnd
, 1, 20, NULL
);
663 if (!(IsWindow(logbox
) && IsDialogMessage(logbox
, &msg
)))
664 DispatchMessage(&msg
);
666 /* Make sure we blink everything that needs it. */
669 /* Send the paste buffer if there's anything to send */
672 /* If there's nothing new in the queue then we can do everything
673 * we've delayed, reading the socket, writing, and repainting
676 if (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
679 if (pending_netevent
) {
680 enact_pending_netevent();
682 /* Force the cursor blink on */
685 if (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
))
689 /* Okay there is now nothing to do so we make sure the screen is
690 * completely up to date then tell windows to call us in a little
694 KillTimer(hwnd
, timer_id
);
702 flash_window(1); /* maintain */
704 /* The messages seem unreliable; especially if we're being tricky */
705 has_focus
= (GetForegroundWindow() == hwnd
);
708 /* Hmm, term_update didn't want to do an update too soon ... */
709 timer_id
= SetTimer(hwnd
, 1, 50, NULL
);
711 timer_id
= SetTimer(hwnd
, 1, 500, NULL
);
713 timer_id
= SetTimer(hwnd
, 1, 100, NULL
);
716 /* There's no point rescanning everything in the message queue
717 * so we do an apparently unnecessary wait here
720 if (GetMessage(&msg
, NULL
, 0, 0) != 1)
734 if (cfg
.protocol
== PROT_SSH
) {
745 * Set up, or shut down, an AsyncSelect. Called from winnet.c.
747 char *do_select(SOCKET skt
, int startup
)
752 events
= (FD_CONNECT
| FD_READ
| FD_WRITE
|
753 FD_OOB
| FD_CLOSE
| FD_ACCEPT
);
758 return "do_select(): internal error (hwnd==NULL)";
759 if (WSAAsyncSelect(skt
, hwnd
, msg
, events
) == SOCKET_ERROR
) {
760 switch (WSAGetLastError()) {
762 return "Network is down";
764 return "WSAAsyncSelect(): unknown error";
771 * set or clear the "raw mouse message" mode
773 void set_raw_mouse_mode(int activate
)
775 send_raw_mouse
= activate
;
776 SetCursor(LoadCursor(NULL
, activate ? IDC_ARROW
: IDC_IBEAM
));
780 * Print a message box and close the connection.
782 void connection_fatal(char *fmt
, ...)
788 vsprintf(stuff
, fmt
, ap
);
790 MessageBox(hwnd
, stuff
, "PuTTY Fatal Error", MB_ICONERROR
| MB_OK
);
791 if (cfg
.close_on_exit
== COE_ALWAYS
)
794 session_closed
= TRUE
;
795 SetWindowText(hwnd
, "PuTTY (inactive)");
800 * Actually do the job requested by a WM_NETEVENT
802 static void enact_pending_netevent(void)
804 static int reentering
= 0;
805 extern int select_result(WPARAM
, LPARAM
);
809 return; /* don't unpend the pending */
811 pending_netevent
= FALSE
;
814 ret
= select_result(pend_netevent_wParam
, pend_netevent_lParam
);
817 if (ret
== 0 && !session_closed
) {
818 /* Abnormal exits will already have set session_closed and taken
819 * appropriate action. */
820 if (cfg
.close_on_exit
== COE_ALWAYS
||
821 cfg
.close_on_exit
== COE_NORMAL
) PostQuitMessage(0);
823 session_closed
= TRUE
;
824 SetWindowText(hwnd
, "PuTTY (inactive)");
825 MessageBox(hwnd
, "Connection closed by remote host",
826 "PuTTY", MB_OK
| MB_ICONINFORMATION
);
832 * Copy the colour palette from the configuration data into defpal.
833 * This is non-trivial because the colour indices are different.
835 static void cfgtopalette(void)
838 static const int ww
[] = {
839 6, 7, 8, 9, 10, 11, 12, 13,
840 14, 15, 16, 17, 18, 19, 20, 21,
841 0, 1, 2, 3, 4, 4, 5, 5
844 for (i
= 0; i
< 24; i
++) {
846 defpal
[i
].rgbtRed
= cfg
.colours
[w
][0];
847 defpal
[i
].rgbtGreen
= cfg
.colours
[w
][1];
848 defpal
[i
].rgbtBlue
= cfg
.colours
[w
][2];
853 * Set up the colour palette.
855 static void init_palette(void)
858 HDC hdc
= GetDC(hwnd
);
860 if (cfg
.try_palette
&& GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
) {
861 logpal
= smalloc(sizeof(*logpal
)
862 - sizeof(logpal
->palPalEntry
)
863 + NCOLOURS
* sizeof(PALETTEENTRY
));
864 logpal
->palVersion
= 0x300;
865 logpal
->palNumEntries
= NCOLOURS
;
866 for (i
= 0; i
< NCOLOURS
; i
++) {
867 logpal
->palPalEntry
[i
].peRed
= defpal
[i
].rgbtRed
;
868 logpal
->palPalEntry
[i
].peGreen
= defpal
[i
].rgbtGreen
;
869 logpal
->palPalEntry
[i
].peBlue
= defpal
[i
].rgbtBlue
;
870 logpal
->palPalEntry
[i
].peFlags
= PC_NOCOLLAPSE
;
872 pal
= CreatePalette(logpal
);
874 SelectPalette(hdc
, pal
, FALSE
);
876 SelectPalette(hdc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
879 ReleaseDC(hwnd
, hdc
);
882 for (i
= 0; i
< NCOLOURS
; i
++)
883 colours
[i
] = PALETTERGB(defpal
[i
].rgbtRed
,
887 for (i
= 0; i
< NCOLOURS
; i
++)
888 colours
[i
] = RGB(defpal
[i
].rgbtRed
,
889 defpal
[i
].rgbtGreen
, defpal
[i
].rgbtBlue
);
893 * Initialise all the fonts we will need initially. There may be as many as
894 * three or as few as one. The other (poentially) twentyone fonts are done
895 * if/when they are needed.
899 * - check the font width and height, correcting our guesses if
902 * - verify that the bold font is the same width as the ordinary
903 * one, and engage shadow bolding if not.
905 * - verify that the underlined font is the same width as the
906 * ordinary one (manual underlining by means of line drawing can
907 * be done in a pinch).
909 static void init_fonts(int pick_width
, int pick_height
)
916 int fw_dontcare
, fw_bold
;
918 for (i
= 0; i
< FONT_MAXNO
; i
++)
921 bold_mode
= cfg
.bold_colour ? BOLD_COLOURS
: BOLD_FONT
;
924 if (cfg
.fontisbold
) {
925 fw_dontcare
= FW_BOLD
;
928 fw_dontcare
= FW_DONTCARE
;
935 font_height
= pick_height
;
937 font_height
= cfg
.fontheight
;
938 if (font_height
> 0) {
940 -MulDiv(font_height
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
943 font_width
= pick_width
;
946 fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \
947 c, OUT_DEFAULT_PRECIS, \
948 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, \
949 FIXED_PITCH | FF_DONTCARE, cfg.font)
951 f(FONT_NORMAL
, cfg
.fontcharset
, fw_dontcare
, FALSE
);
953 lfont
.lfHeight
= font_height
;
954 lfont
.lfWidth
= font_width
;
955 lfont
.lfEscapement
= 0;
956 lfont
.lfOrientation
= 0;
957 lfont
.lfWeight
= fw_dontcare
;
958 lfont
.lfItalic
= FALSE
;
959 lfont
.lfUnderline
= FALSE
;
960 lfont
.lfStrikeOut
= FALSE
;
961 lfont
.lfCharSet
= cfg
.fontcharset
;
962 lfont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
963 lfont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
964 lfont
.lfQuality
= DEFAULT_QUALITY
;
965 lfont
.lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
966 strncpy(lfont
.lfFaceName
, cfg
.font
, LF_FACESIZE
);
968 SelectObject(hdc
, fonts
[FONT_NORMAL
]);
969 GetTextMetrics(hdc
, &tm
);
971 if (pick_width
== 0 || pick_height
== 0) {
972 font_height
= tm
.tmHeight
;
973 font_width
= tm
.tmAveCharWidth
;
975 font_dualwidth
= (tm
.tmAveCharWidth
!= tm
.tmMaxCharWidth
);
977 #ifdef RDB_DEBUG_PATCH
978 debug(23, "Primary font H=%d, AW=%d, MW=%d",
979 tm
.tmHeight
, tm
.tmAveCharWidth
, tm
.tmMaxCharWidth
);
984 DWORD cset
= tm
.tmCharSet
;
985 memset(&info
, 0xFF, sizeof(info
));
987 /* !!! Yes the next line is right */
988 if (cset
== OEM_CHARSET
)
989 font_codepage
= GetOEMCP();
991 if (TranslateCharsetInfo
992 ((DWORD
*) cset
, &info
, TCI_SRCCHARSET
)) font_codepage
=
997 GetCPInfo(font_codepage
, &cpinfo
);
998 dbcs_screenfont
= (cpinfo
.MaxCharSize
> 1);
1001 f(FONT_UNDERLINE
, cfg
.fontcharset
, fw_dontcare
, TRUE
);
1004 * Some fonts, e.g. 9-pt Courier, draw their underlines
1005 * outside their character cell. We successfully prevent
1006 * screen corruption by clipping the text output, but then
1007 * we lose the underline completely. Here we try to work
1008 * out whether this is such a font, and if it is, we set a
1009 * flag that causes underlines to be drawn by hand.
1011 * Having tried other more sophisticated approaches (such
1012 * as examining the TEXTMETRIC structure or requesting the
1013 * height of a string), I think we'll do this the brute
1014 * force way: we create a small bitmap, draw an underlined
1015 * space on it, and test to see whether any pixels are
1016 * foreground-coloured. (Since we expect the underline to
1017 * go all the way across the character cell, we only search
1018 * down a single column of the bitmap, half way across.)
1022 HBITMAP und_bm
, und_oldbm
;
1026 und_dc
= CreateCompatibleDC(hdc
);
1027 und_bm
= CreateCompatibleBitmap(hdc
, font_width
, font_height
);
1028 und_oldbm
= SelectObject(und_dc
, und_bm
);
1029 SelectObject(und_dc
, fonts
[FONT_UNDERLINE
]);
1030 SetTextAlign(und_dc
, TA_TOP
| TA_LEFT
| TA_NOUPDATECP
);
1031 SetTextColor(und_dc
, RGB(255, 255, 255));
1032 SetBkColor(und_dc
, RGB(0, 0, 0));
1033 SetBkMode(und_dc
, OPAQUE
);
1034 ExtTextOut(und_dc
, 0, 0, ETO_OPAQUE
, NULL
, " ", 1, NULL
);
1036 for (i
= 0; i
< font_height
; i
++) {
1037 c
= GetPixel(und_dc
, font_width
/ 2, i
);
1038 if (c
!= RGB(0, 0, 0))
1041 SelectObject(und_dc
, und_oldbm
);
1042 DeleteObject(und_bm
);
1045 und_mode
= UND_LINE
;
1046 DeleteObject(fonts
[FONT_UNDERLINE
]);
1047 fonts
[FONT_UNDERLINE
] = 0;
1051 if (bold_mode
== BOLD_FONT
) {
1052 f(FONT_BOLD
, cfg
.fontcharset
, fw_bold
, FALSE
);
1056 descent
= tm
.tmAscent
+ 1;
1057 if (descent
>= font_height
)
1058 descent
= font_height
- 1;
1060 for (i
= 0; i
< 3; i
++) {
1062 if (SelectObject(hdc
, fonts
[i
]) && GetTextMetrics(hdc
, &tm
))
1063 fontsize
[i
] = tm
.tmAveCharWidth
+ 256 * tm
.tmHeight
;
1070 ReleaseDC(hwnd
, hdc
);
1072 if (fontsize
[FONT_UNDERLINE
] != fontsize
[FONT_NORMAL
]) {
1073 und_mode
= UND_LINE
;
1074 DeleteObject(fonts
[FONT_UNDERLINE
]);
1075 fonts
[FONT_UNDERLINE
] = 0;
1078 if (bold_mode
== BOLD_FONT
&&
1079 fontsize
[FONT_BOLD
] != fontsize
[FONT_NORMAL
]) {
1080 bold_mode
= BOLD_SHADOW
;
1081 DeleteObject(fonts
[FONT_BOLD
]);
1082 fonts
[FONT_BOLD
] = 0;
1084 fontflag
[0] = fontflag
[1] = fontflag
[2] = 1;
1089 static void another_font(int fontno
)
1092 int fw_dontcare
, fw_bold
;
1096 if (fontno
< 0 || fontno
>= FONT_MAXNO
|| fontflag
[fontno
])
1099 basefont
= (fontno
& ~(FONT_BOLDUND
));
1100 if (basefont
!= fontno
&& !fontflag
[basefont
])
1101 another_font(basefont
);
1103 if (cfg
.fontisbold
) {
1104 fw_dontcare
= FW_BOLD
;
1107 fw_dontcare
= FW_DONTCARE
;
1111 c
= cfg
.fontcharset
;
1117 if (fontno
& FONT_WIDE
)
1119 if (fontno
& FONT_NARROW
)
1121 if (fontno
& FONT_OEM
)
1123 if (fontno
& FONT_BOLD
)
1125 if (fontno
& FONT_UNDERLINE
)
1129 CreateFont(font_height
* (1 + !!(fontno
& FONT_HIGH
)), x
, 0, 0, w
,
1130 FALSE
, u
, FALSE
, c
, OUT_DEFAULT_PRECIS
,
1131 CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
,
1132 FIXED_PITCH
| FF_DONTCARE
, s
);
1134 fontflag
[fontno
] = 1;
1137 static void deinit_fonts(void)
1140 for (i
= 0; i
< FONT_MAXNO
; i
++) {
1142 DeleteObject(fonts
[i
]);
1148 void request_resize(int w
, int h
)
1152 /* If the window is maximized supress resizing attempts */
1153 if (IsZoomed(hwnd
)) {
1154 if (cfg
.resize_action
== RESIZE_TERM
)
1158 if (cfg
.resize_action
== RESIZE_DISABLED
) return;
1159 if (h
== rows
&& w
== cols
) return;
1161 /* Sanity checks ... */
1163 static int first_time
= 1;
1166 switch (first_time
) {
1168 /* Get the size of the screen */
1169 if (GetClientRect(GetDesktopWindow(), &ss
))
1170 /* first_time = 0 */ ;
1176 /* Make sure the values are sane */
1177 width
= (ss
.right
- ss
.left
- extra_width
) / 4;
1178 height
= (ss
.bottom
- ss
.top
- extra_height
) / 6;
1180 if (w
> width
|| h
> height
)
1189 term_size(h
, w
, cfg
.savelines
);
1191 if (cfg
.resize_action
!= RESIZE_FONT
&& !IsZoomed(hwnd
)) {
1192 width
= extra_width
+ font_width
* w
;
1193 height
= extra_height
+ font_height
* h
;
1195 SetWindowPos(hwnd
, NULL
, 0, 0, width
, height
,
1196 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1197 SWP_NOMOVE
| SWP_NOZORDER
);
1201 InvalidateRect(hwnd
, NULL
, TRUE
);
1204 static void reset_window(int reinit
) {
1206 * This function decides how to resize or redraw when the
1207 * user changes something.
1209 * This function doesn't like to change the terminal size but if the
1210 * font size is locked that may be it's only soluion.
1212 int win_width
, win_height
;
1215 #ifdef RDB_DEBUG_PATCH
1216 debug((27, "reset_window()"));
1219 /* Current window sizes ... */
1220 GetWindowRect(hwnd
, &wr
);
1221 GetClientRect(hwnd
, &cr
);
1223 win_width
= cr
.right
- cr
.left
;
1224 win_height
= cr
.bottom
- cr
.top
;
1226 if (cfg
.resize_action
== RESIZE_DISABLED
) reinit
= 2;
1228 /* Are we being forced to reload the fonts ? */
1230 #ifdef RDB_DEBUG_PATCH
1231 debug((27, "reset_window() -- Forced deinit"));
1237 /* Oh, looks like we're minimised */
1238 if (win_width
== 0 || win_height
== 0)
1241 /* Is the window out of position ? */
1243 (offset_width
!= (win_width
-font_width
*cols
)/2 ||
1244 offset_height
!= (win_height
-font_height
*rows
)/2) ){
1245 offset_width
= (win_width
-font_width
*cols
)/2;
1246 offset_height
= (win_height
-font_height
*rows
)/2;
1247 InvalidateRect(hwnd
, NULL
, TRUE
);
1248 #ifdef RDB_DEBUG_PATCH
1249 debug((27, "reset_window() -> Reposition terminal"));
1253 if (IsZoomed(hwnd
)) {
1254 /* We're fullscreen, this means we must not change the size of
1255 * the window so it's the font size or the terminal itself.
1258 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
;
1259 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
;
1261 if (cfg
.resize_action
!= RESIZE_TERM
) {
1262 if ( font_width
!= win_width
/cols
||
1263 font_height
!= win_height
/rows
) {
1265 init_fonts(win_width
/cols
, win_height
/rows
);
1266 offset_width
= (win_width
-font_width
*cols
)/2;
1267 offset_height
= (win_height
-font_height
*rows
)/2;
1268 InvalidateRect(hwnd
, NULL
, TRUE
);
1269 #ifdef RDB_DEBUG_PATCH
1270 debug((25, "reset_window() -> Z font resize to (%d, %d)",
1271 font_width
, font_height
));
1275 if ( font_width
!= win_width
/cols
||
1276 font_height
!= win_height
/rows
) {
1277 /* Our only choice at this point is to change the
1278 * size of the terminal; Oh well.
1280 term_size( win_height
/font_height
, win_width
/font_width
,
1282 offset_width
= (win_width
-font_width
*cols
)/2;
1283 offset_height
= (win_height
-font_height
*rows
)/2;
1284 InvalidateRect(hwnd
, NULL
, TRUE
);
1285 #ifdef RDB_DEBUG_PATCH
1286 debug((27, "reset_window() -> Zoomed term_size"));
1293 /* Hmm, a force re-init means we should ignore the current window
1294 * so we resize to the default font size.
1297 #ifdef RDB_DEBUG_PATCH
1298 debug((27, "reset_window() -> Forced re-init"));
1301 offset_width
= offset_height
= cfg
.window_border
;
1302 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+ offset_width
*2;
1303 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
1305 if (win_width
!= font_width
*cols
+ offset_width
*2 ||
1306 win_height
!= font_height
*rows
+ offset_height
*2) {
1308 /* If this is too large windows will resize it to the maximum
1309 * allowed window size, we will then be back in here and resize
1310 * the font or terminal to fit.
1312 SetWindowPos(hwnd
, NULL
, 0, 0,
1313 font_width
*cols
+ extra_width
,
1314 font_height
*rows
+ extra_height
,
1315 SWP_NOMOVE
| SWP_NOZORDER
);
1318 InvalidateRect(hwnd
, NULL
, TRUE
);
1322 /* Okay the user doesn't want us to change the font so we try the
1323 * window. But that may be too big for the screen which forces us
1324 * to change the terminal.
1326 if ((cfg
.resize_action
== RESIZE_TERM
&& reinit
<=0) ||
1327 (cfg
.resize_action
== RESIZE_EITHER
&& reinit
<0) ||
1329 offset_width
= offset_height
= cfg
.window_border
;
1330 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+ offset_width
*2;
1331 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
1333 if (win_width
!= font_width
*cols
+ offset_width
*2 ||
1334 win_height
!= font_height
*rows
+ offset_height
*2) {
1339 GetClientRect(GetDesktopWindow(), &ss
);
1340 width
= (ss
.right
- ss
.left
- extra_width
) / font_width
;
1341 height
= (ss
.bottom
- ss
.top
- extra_height
) / font_height
;
1344 if ( rows
> height
|| cols
> width
) {
1345 if (cfg
.resize_action
== RESIZE_EITHER
) {
1346 /* Make the font the biggest we can */
1348 font_width
= (ss
.right
- ss
.left
- extra_width
)/cols
;
1350 font_height
= (ss
.bottom
- ss
.top
- extra_height
)/rows
;
1353 init_fonts(font_width
, font_height
);
1355 width
= (ss
.right
- ss
.left
- extra_width
) / font_width
;
1356 height
= (ss
.bottom
- ss
.top
- extra_height
) / font_height
;
1358 if ( height
> rows
) height
= rows
;
1359 if ( width
> cols
) width
= cols
;
1360 term_size(height
, width
, cfg
.savelines
);
1361 #ifdef RDB_DEBUG_PATCH
1362 debug((27, "reset_window() -> term resize to (%d,%d)",
1368 SetWindowPos(hwnd
, NULL
, 0, 0,
1369 font_width
*cols
+ extra_width
,
1370 font_height
*rows
+ extra_height
,
1371 SWP_NOMOVE
| SWP_NOZORDER
);
1373 InvalidateRect(hwnd
, NULL
, TRUE
);
1374 #ifdef RDB_DEBUG_PATCH
1375 debug((27, "reset_window() -> window resize to (%d,%d)",
1376 font_width
*cols
+ extra_width
,
1377 font_height
*rows
+ extra_height
));
1383 /* We're allowed to or must change the font but do we want to ? */
1385 if (font_width
!= (win_width
-cfg
.window_border
*2)/cols
||
1386 font_height
!= (win_height
-cfg
.window_border
*2)/rows
) {
1389 init_fonts((win_width
-cfg
.window_border
*2)/cols
,
1390 (win_height
-cfg
.window_border
*2)/rows
);
1391 offset_width
= (win_width
-font_width
*cols
)/2;
1392 offset_height
= (win_height
-font_height
*rows
)/2;
1394 extra_width
= wr
.right
- wr
.left
- cr
.right
+ cr
.left
+offset_width
*2;
1395 extra_height
= wr
.bottom
- wr
.top
- cr
.bottom
+ cr
.top
+offset_height
*2;
1397 InvalidateRect(hwnd
, NULL
, TRUE
);
1398 #ifdef RDB_DEBUG_PATCH
1399 debug((25, "reset_window() -> font resize to (%d,%d)",
1400 font_width
, font_height
));
1405 static void set_input_locale(HKL kl
)
1409 GetLocaleInfo(LOWORD(kl
), LOCALE_IDEFAULTANSICODEPAGE
,
1410 lbuf
, sizeof(lbuf
));
1412 kbd_codepage
= atoi(lbuf
);
1415 static void click(Mouse_Button b
, int x
, int y
, int shift
, int ctrl
, int alt
)
1417 int thistime
= GetMessageTime();
1419 if (send_raw_mouse
&& !(cfg
.mouse_override
&& shift
)) {
1420 lastbtn
= MBT_NOTHING
;
1421 term_mouse(b
, MA_CLICK
, x
, y
, shift
, ctrl
, alt
);
1425 if (lastbtn
== b
&& thistime
- lasttime
< dbltime
) {
1426 lastact
= (lastact
== MA_CLICK ? MA_2CLK
:
1427 lastact
== MA_2CLK ? MA_3CLK
:
1428 lastact
== MA_3CLK ? MA_CLICK
: MA_NOTHING
);
1433 if (lastact
!= MA_NOTHING
)
1434 term_mouse(b
, lastact
, x
, y
, shift
, ctrl
, alt
);
1435 lasttime
= thistime
;
1439 * Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT)
1440 * into a cooked one (SELECT, EXTEND, PASTE).
1442 Mouse_Button
translate_button(Mouse_Button button
)
1444 if (button
== MBT_LEFT
)
1446 if (button
== MBT_MIDDLE
)
1447 return cfg
.mouse_is_xterm ? MBT_PASTE
: MBT_EXTEND
;
1448 if (button
== MBT_RIGHT
)
1449 return cfg
.mouse_is_xterm ? MBT_EXTEND
: MBT_PASTE
;
1450 return 0; /* shouldn't happen */
1453 static void show_mouseptr(int show
)
1455 static int cursor_visible
= 1;
1456 if (!cfg
.hide_mouseptr
) /* override if this feature disabled */
1458 if (cursor_visible
&& !show
)
1460 else if (!cursor_visible
&& show
)
1462 cursor_visible
= show
;
1465 static int is_alt_pressed(void)
1468 int r
= GetKeyboardState(keystate
);
1471 if (keystate
[VK_MENU
] & 0x80)
1473 if (keystate
[VK_RMENU
] & 0x80)
1478 static int resizing
;
1480 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
,
1481 WPARAM wParam
, LPARAM lParam
)
1484 static int ignore_clip
= FALSE
;
1485 static int need_backend_resize
= FALSE
;
1489 if (pending_netevent
)
1490 enact_pending_netevent();
1496 if (cfg
.ping_interval
> 0) {
1499 if (now
- last_movement
> cfg
.ping_interval
) {
1500 back
->special(TS_PING
);
1501 last_movement
= now
;
1504 net_pending_errors();
1510 if (!cfg
.warn_on_close
|| session_closed
||
1512 "Are you sure you want to close this session?",
1513 "PuTTY Exit Confirmation",
1514 MB_ICONWARNING
| MB_OKCANCEL
) == IDOK
)
1515 DestroyWindow(hwnd
);
1522 switch (wParam
& ~0xF) { /* low 4 bits reserved to Windows */
1534 PROCESS_INFORMATION pi
;
1535 HANDLE filemap
= NULL
;
1537 if (wParam
== IDM_DUPSESS
) {
1539 * Allocate a file-mapping memory chunk for the
1542 SECURITY_ATTRIBUTES sa
;
1545 sa
.nLength
= sizeof(sa
);
1546 sa
.lpSecurityDescriptor
= NULL
;
1547 sa
.bInheritHandle
= TRUE
;
1548 filemap
= CreateFileMapping((HANDLE
) 0xFFFFFFFF,
1551 0, sizeof(Config
), NULL
);
1553 p
= (Config
*) MapViewOfFile(filemap
,
1555 0, 0, sizeof(Config
));
1557 *p
= cfg
; /* structure copy */
1561 sprintf(c
, "putty &%p", filemap
);
1563 } else if (wParam
== IDM_SAVEDSESS
) {
1565 sessions
[(lParam
- IDM_SAVED_MIN
) / 16];
1566 cl
= smalloc(16 + strlen(session
)); /* 8, but play safe */
1568 cl
= NULL
; /* not a very important failure mode */
1570 sprintf(cl
, "putty @%s", session
);
1576 GetModuleFileName(NULL
, b
, sizeof(b
) - 1);
1578 si
.lpReserved
= NULL
;
1579 si
.lpDesktop
= NULL
;
1583 si
.lpReserved2
= NULL
;
1584 CreateProcess(b
, cl
, NULL
, NULL
, TRUE
,
1585 NORMAL_PRIORITY_CLASS
, NULL
, NULL
, &si
, &pi
);
1588 CloseHandle(filemap
);
1598 GetWindowText(hwnd
, cfg
.wintitle
, sizeof(cfg
.wintitle
));
1601 if (!do_reconfig(hwnd
))
1605 /* Disable full-screen if resizing forbidden */
1606 HMENU m
= GetSystemMenu (hwnd
, FALSE
);
1607 EnableMenuItem(m
, IDM_FULLSCREEN
, MF_BYCOMMAND
|
1608 (cfg
.resize_action
== RESIZE_DISABLED
)
1609 ? MF_GRAYED
: MF_ENABLED
);
1610 /* Gracefully unzoom if necessary */
1612 (cfg
.resize_action
== RESIZE_DISABLED
)) {
1617 if (strcmp(prev_cfg
.logfilename
, cfg
.logfilename
) ||
1618 prev_cfg
.logtype
!= cfg
.logtype
) {
1619 logfclose(); /* reset logging */
1625 * Flush the line discipline's edit buffer in the
1626 * case where local editing has just been disabled.
1628 ldisc_send(NULL
, 0, 0);
1636 /* Screen size changed ? */
1637 if (cfg
.height
!= prev_cfg
.height
||
1638 cfg
.width
!= prev_cfg
.width
||
1639 cfg
.savelines
!= prev_cfg
.savelines
||
1640 cfg
.resize_action
== RESIZE_FONT
||
1641 cfg
.resize_action
== RESIZE_DISABLED
)
1642 term_size(cfg
.height
, cfg
.width
, cfg
.savelines
);
1644 /* Enable or disable the scroll bar, etc */
1646 LONG nflg
, flag
= GetWindowLong(hwnd
, GWL_STYLE
);
1647 LONG nexflag
, exflag
=
1648 GetWindowLong(hwnd
, GWL_EXSTYLE
);
1651 if (cfg
.alwaysontop
!= prev_cfg
.alwaysontop
) {
1652 if (cfg
.alwaysontop
) {
1653 nexflag
|= WS_EX_TOPMOST
;
1654 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0,
1655 SWP_NOMOVE
| SWP_NOSIZE
);
1657 nexflag
&= ~(WS_EX_TOPMOST
);
1658 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0,
1659 SWP_NOMOVE
| SWP_NOSIZE
);
1662 if (cfg
.sunken_edge
)
1663 nexflag
|= WS_EX_CLIENTEDGE
;
1665 nexflag
&= ~(WS_EX_CLIENTEDGE
);
1669 cfg
.scrollbar_in_fullscreen
: cfg
.scrollbar
)
1672 nflg
&= ~WS_VSCROLL
;
1673 if (cfg
.resize_action
== RESIZE_DISABLED
)
1674 nflg
&= ~(WS_THICKFRAME
| WS_MAXIMIZEBOX
);
1676 nflg
|= (WS_THICKFRAME
| WS_MAXIMIZEBOX
);
1678 if (nflg
!= flag
|| nexflag
!= exflag
) {
1680 SetWindowLong(hwnd
, GWL_STYLE
, nflg
);
1681 if (nexflag
!= exflag
)
1682 SetWindowLong(hwnd
, GWL_EXSTYLE
, nexflag
);
1684 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1685 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1686 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1694 if (cfg
.resize_action
== RESIZE_DISABLED
&& IsZoomed(hwnd
)) {
1699 set_title(cfg
.wintitle
);
1700 if (IsIconic(hwnd
)) {
1702 cfg
.win_name_always ? window_name
:
1706 if (strcmp(cfg
.font
, prev_cfg
.font
) != 0 ||
1707 strcmp(cfg
.line_codepage
, prev_cfg
.line_codepage
) != 0 ||
1708 cfg
.fontisbold
!= prev_cfg
.fontisbold
||
1709 cfg
.fontheight
!= prev_cfg
.fontheight
||
1710 cfg
.fontcharset
!= prev_cfg
.fontcharset
||
1711 cfg
.vtmode
!= prev_cfg
.vtmode
||
1712 cfg
.bold_colour
!= prev_cfg
.bold_colour
||
1713 cfg
.resize_action
== RESIZE_DISABLED
||
1714 cfg
.resize_action
== RESIZE_EITHER
||
1715 (cfg
.resize_action
!= prev_cfg
.resize_action
))
1718 InvalidateRect(hwnd
, NULL
, TRUE
);
1719 reset_window(init_lvl
);
1720 net_pending_errors();
1733 back
->special(TS_AYT
);
1734 net_pending_errors();
1737 back
->special(TS_BRK
);
1738 net_pending_errors();
1741 back
->special(TS_SYNCH
);
1742 net_pending_errors();
1745 back
->special(TS_EC
);
1746 net_pending_errors();
1749 back
->special(TS_EL
);
1750 net_pending_errors();
1753 back
->special(TS_GA
);
1754 net_pending_errors();
1757 back
->special(TS_NOP
);
1758 net_pending_errors();
1761 back
->special(TS_ABORT
);
1762 net_pending_errors();
1765 back
->special(TS_AO
);
1766 net_pending_errors();
1769 back
->special(TS_IP
);
1770 net_pending_errors();
1773 back
->special(TS_SUSP
);
1774 net_pending_errors();
1777 back
->special(TS_EOR
);
1778 net_pending_errors();
1781 back
->special(TS_EOF
);
1782 net_pending_errors();
1788 WinHelp(hwnd
, help_path
,
1789 help_has_contents ? HELP_FINDER
: HELP_CONTENTS
, 0);
1793 * We get this if the System menu has been activated
1800 * We get this if the System menu has been activated
1801 * using the keyboard. This might happen from within
1802 * TranslateKey, in which case it really wants to be
1803 * followed by a `space' character to actually _bring
1804 * the menu up_ rather than just sitting there in
1805 * `ready to appear' state.
1807 show_mouseptr(1); /* make sure pointer is visible */
1809 PostMessage(hwnd
, WM_CHAR
, ' ', 0);
1811 case IDM_FULLSCREEN
:
1815 if (wParam
>= IDM_SAVED_MIN
&& wParam
<= IDM_SAVED_MAX
) {
1816 SendMessage(hwnd
, WM_SYSCOMMAND
, IDM_SAVEDSESS
, wParam
);
1821 #define X_POS(l) ((int)(short)LOWORD(l))
1822 #define Y_POS(l) ((int)(short)HIWORD(l))
1824 #define TO_CHR_X(x) ((((x)<0 ? (x)-font_width+1 : (x))-offset_width) / font_width)
1825 #define TO_CHR_Y(y) ((((y)<0 ? (y)-font_height+1: (y))-offset_height) / font_height)
1826 #define WHEEL_DELTA 120
1829 wheel_accumulator
+= (short) HIWORD(wParam
);
1830 wParam
= LOWORD(wParam
);
1832 /* process events when the threshold is reached */
1833 while (abs(wheel_accumulator
) >= WHEEL_DELTA
) {
1836 /* reduce amount for next time */
1837 if (wheel_accumulator
> 0) {
1839 wheel_accumulator
-= WHEEL_DELTA
;
1840 } else if (wheel_accumulator
< 0) {
1842 wheel_accumulator
+= WHEEL_DELTA
;
1846 if (send_raw_mouse
) {
1847 /* send a mouse-down followed by a mouse up */
1851 TO_CHR_X(X_POS(lParam
)),
1852 TO_CHR_Y(Y_POS(lParam
)), wParam
& MK_SHIFT
,
1853 wParam
& MK_CONTROL
, is_alt_pressed());
1854 term_mouse(b
, MA_RELEASE
, TO_CHR_X(X_POS(lParam
)),
1855 TO_CHR_Y(Y_POS(lParam
)), wParam
& MK_SHIFT
,
1856 wParam
& MK_CONTROL
, is_alt_pressed());
1858 /* trigger a scroll */
1860 b
== MBT_WHEEL_UP ?
-rows
/ 2 : rows
/ 2);
1865 case WM_LBUTTONDOWN
:
1866 case WM_MBUTTONDOWN
:
1867 case WM_RBUTTONDOWN
:
1875 case WM_LBUTTONDOWN
:
1879 case WM_MBUTTONDOWN
:
1880 button
= MBT_MIDDLE
;
1883 case WM_RBUTTONDOWN
:
1892 button
= MBT_MIDDLE
;
1900 button
= press
= 0; /* shouldn't happen */
1904 * Special case: in full-screen mode, if the left
1905 * button is clicked in the very top left corner of the
1906 * window, we put up the System menu instead of doing
1909 if (full_screen
&& press
&& button
== MBT_LEFT
&&
1910 X_POS(lParam
) == 0 && Y_POS(lParam
) == 0) {
1911 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
, 0);
1916 TO_CHR_X(X_POS(lParam
)), TO_CHR_Y(Y_POS(lParam
)),
1917 wParam
& MK_SHIFT
, wParam
& MK_CONTROL
,
1921 term_mouse(button
, MA_RELEASE
,
1922 TO_CHR_X(X_POS(lParam
)),
1923 TO_CHR_Y(Y_POS(lParam
)), wParam
& MK_SHIFT
,
1924 wParam
& MK_CONTROL
, is_alt_pressed());
1932 * Add the mouse position and message time to the random
1935 noise_ultralight(lParam
);
1937 if (wParam
& (MK_LBUTTON
| MK_MBUTTON
| MK_RBUTTON
)) {
1939 if (wParam
& MK_LBUTTON
)
1941 else if (wParam
& MK_MBUTTON
)
1945 term_mouse(b
, MA_DRAG
, TO_CHR_X(X_POS(lParam
)),
1946 TO_CHR_Y(Y_POS(lParam
)), wParam
& MK_SHIFT
,
1947 wParam
& MK_CONTROL
, is_alt_pressed());
1950 case WM_NCMOUSEMOVE
:
1952 noise_ultralight(lParam
);
1954 case WM_IGNORE_CLIP
:
1955 ignore_clip
= wParam
; /* don't panic on DESTROYCLIPBOARD */
1957 case WM_DESTROYCLIPBOARD
:
1960 ignore_clip
= FALSE
;
1966 hdc
= BeginPaint(hwnd
, &p
);
1968 SelectPalette(hdc
, pal
, TRUE
);
1969 RealizePalette(hdc
);
1972 (p
.rcPaint
.left
-offset_width
)/font_width
,
1973 (p
.rcPaint
.top
-offset_height
)/font_height
,
1974 (p
.rcPaint
.right
-offset_width
-1)/font_width
,
1975 (p
.rcPaint
.bottom
-offset_height
-1)/font_height
);
1978 p
.rcPaint
.left
< offset_width
||
1979 p
.rcPaint
.top
< offset_height
||
1980 p
.rcPaint
.right
>= offset_width
+ font_width
*cols
||
1981 p
.rcPaint
.bottom
>= offset_height
+ font_height
*rows
)
1983 HBRUSH fillcolour
, oldbrush
;
1985 fillcolour
= CreateSolidBrush (
1986 colours
[(ATTR_DEFBG
>>ATTR_BGSHIFT
)*2]);
1987 oldbrush
= SelectObject(hdc
, fillcolour
);
1988 edge
= CreatePen(PS_SOLID
, 0,
1989 colours
[(ATTR_DEFBG
>>ATTR_BGSHIFT
)*2]);
1990 oldpen
= SelectObject(hdc
, edge
);
1992 ExcludeClipRect(hdc
,
1993 offset_width
, offset_height
,
1994 offset_width
+font_width
*cols
,
1995 offset_height
+font_height
*rows
);
1997 Rectangle(hdc
, p
.rcPaint
.left
, p
.rcPaint
.top
,
1998 p
.rcPaint
.right
, p
.rcPaint
.bottom
);
2000 // SelectClipRgn(hdc, NULL);
2002 SelectObject(hdc
, oldbrush
);
2003 DeleteObject(fillcolour
);
2004 SelectObject(hdc
, oldpen
);
2007 SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
2008 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
2014 /* Notice we can get multiple netevents, FD_READ, FD_WRITE etc
2015 * but the only one that's likely to try to overload us is FD_READ.
2016 * This means buffering just one is fine.
2018 if (pending_netevent
)
2019 enact_pending_netevent();
2021 pending_netevent
= TRUE
;
2022 pend_netevent_wParam
= wParam
;
2023 pend_netevent_lParam
= lParam
;
2024 if (WSAGETSELECTEVENT(lParam
) != FD_READ
)
2025 enact_pending_netevent();
2027 time(&last_movement
);
2031 CreateCaret(hwnd
, caretbm
, font_width
, font_height
);
2033 flash_window(0); /* stop */
2039 if (full_screen
) flip_full_screen();
2046 case WM_ENTERSIZEMOVE
:
2047 #ifdef RDB_DEBUG_PATCH
2048 debug((27, "WM_ENTERSIZEMOVE"));
2052 need_backend_resize
= FALSE
;
2054 case WM_EXITSIZEMOVE
:
2057 #ifdef RDB_DEBUG_PATCH
2058 debug((27, "WM_EXITSIZEMOVE"));
2060 if (need_backend_resize
) {
2061 term_size(cfg
.height
, cfg
.width
, cfg
.savelines
);
2062 InvalidateRect(hwnd
, NULL
, TRUE
);
2067 * This does two jobs:
2068 * 1) Keep the sizetip uptodate
2069 * 2) Make sure the window size is _stepped_ in units of the font size.
2071 if (cfg
.resize_action
!= RESIZE_FONT
&& !alt_pressed
) {
2072 int width
, height
, w
, h
, ew
, eh
;
2073 LPRECT r
= (LPRECT
) lParam
;
2075 if ( !need_backend_resize
&& cfg
.resize_action
== RESIZE_EITHER
&&
2076 (cfg
.height
!= rows
|| cfg
.width
!= cols
)) {
2078 * Great! It seems that both the terminal size and the
2079 * font size have been changed and the user is now dragging.
2081 * It will now be difficult to get back to the configured
2084 * This would be easier but it seems to be too confusing.
2086 term_size(cfg.height, cfg.width, cfg.savelines);
2089 cfg
.height
=rows
; cfg
.width
=cols
;
2091 InvalidateRect(hwnd
, NULL
, TRUE
);
2092 need_backend_resize
= TRUE
;
2095 width
= r
->right
- r
->left
- extra_width
;
2096 height
= r
->bottom
- r
->top
- extra_height
;
2097 w
= (width
+ font_width
/ 2) / font_width
;
2100 h
= (height
+ font_height
/ 2) / font_height
;
2103 UpdateSizeTip(hwnd
, w
, h
);
2104 ew
= width
- w
* font_width
;
2105 eh
= height
- h
* font_height
;
2107 if (wParam
== WMSZ_LEFT
||
2108 wParam
== WMSZ_BOTTOMLEFT
|| wParam
== WMSZ_TOPLEFT
)
2114 if (wParam
== WMSZ_TOP
||
2115 wParam
== WMSZ_TOPRIGHT
|| wParam
== WMSZ_TOPLEFT
)
2125 int width
, height
, w
, h
, rv
= 0;
2126 int ex_width
= extra_width
+ (cfg
.window_border
- offset_width
) * 2;
2127 int ex_height
= extra_height
+ (cfg
.window_border
- offset_height
) * 2;
2128 LPRECT r
= (LPRECT
) lParam
;
2130 width
= r
->right
- r
->left
- ex_width
;
2131 height
= r
->bottom
- r
->top
- ex_height
;
2133 w
= (width
+ cols
/2)/cols
;
2134 h
= (height
+ rows
/2)/rows
;
2135 if ( r
->right
!= r
->left
+ w
*cols
+ ex_width
)
2138 if (wParam
== WMSZ_LEFT
||
2139 wParam
== WMSZ_BOTTOMLEFT
|| wParam
== WMSZ_TOPLEFT
)
2140 r
->left
= r
->right
- w
*cols
- ex_width
;
2142 r
->right
= r
->left
+ w
*cols
+ ex_width
;
2144 if (r
->bottom
!= r
->top
+ h
*rows
+ ex_height
)
2147 if (wParam
== WMSZ_TOP
||
2148 wParam
== WMSZ_TOPRIGHT
|| wParam
== WMSZ_TOPLEFT
)
2149 r
->top
= r
->bottom
- h
*rows
- ex_height
;
2151 r
->bottom
= r
->top
+ h
*rows
+ ex_height
;
2155 /* break; (never reached) */
2157 #ifdef RDB_DEBUG_PATCH
2158 debug((27, "WM_SIZE %s (%d,%d)",
2159 (wParam
== SIZE_MINIMIZED
) ?
"SIZE_MINIMIZED":
2160 (wParam
== SIZE_MAXIMIZED
) ?
"SIZE_MAXIMIZED":
2161 (wParam
== SIZE_RESTORED
&& resizing
) ?
"to":
2162 (wParam
== SIZE_RESTORED
) ?
"SIZE_RESTORED":
2164 LOWORD(lParam
), HIWORD(lParam
)));
2166 if (wParam
== SIZE_MINIMIZED
)
2168 cfg
.win_name_always ? window_name
: icon_name
);
2169 if (wParam
== SIZE_RESTORED
|| wParam
== SIZE_MAXIMIZED
)
2170 SetWindowText(hwnd
, window_name
);
2172 if (cfg
.resize_action
== RESIZE_DISABLED
) {
2173 /* A resize, well it better be a minimize. */
2177 int width
, height
, w
, h
;
2179 width
= LOWORD(lParam
);
2180 height
= HIWORD(lParam
);
2183 if (wParam
== SIZE_MAXIMIZED
&& !was_zoomed
) {
2187 if (cfg
.resize_action
== RESIZE_TERM
) {
2188 w
= width
/ font_width
;
2190 h
= height
/ font_height
;
2193 term_size(h
, w
, cfg
.savelines
);
2196 } else if (wParam
== SIZE_RESTORED
&& was_zoomed
) {
2198 if (cfg
.resize_action
== RESIZE_TERM
)
2199 term_size(prev_rows
, prev_cols
, cfg
.savelines
);
2200 if (cfg
.resize_action
!= RESIZE_FONT
)
2205 /* This is an unexpected resize, these will normally happen
2206 * if the window is too large. Probably either the user
2207 * selected a huge font or the screen size has changed.
2209 * This is also called with minimize.
2211 else reset_window(-1);
2215 * Don't call back->size in mid-resize. (To prevent
2216 * massive numbers of resize events getting sent
2217 * down the connection during an NT opaque drag.)
2220 if (cfg
.resize_action
!= RESIZE_FONT
&& !alt_pressed
) {
2221 need_backend_resize
= TRUE
;
2222 w
= (width
-cfg
.window_border
*2) / font_width
;
2224 h
= (height
-cfg
.window_border
*2) / font_height
;
2235 switch (LOWORD(wParam
)) {
2249 term_scroll(0, +rows
/ 2);
2252 term_scroll(0, -rows
/ 2);
2254 case SB_THUMBPOSITION
:
2256 term_scroll(1, HIWORD(wParam
));
2260 case WM_PALETTECHANGED
:
2261 if ((HWND
) wParam
!= hwnd
&& pal
!= NULL
) {
2262 HDC hdc
= get_ctx();
2264 if (RealizePalette(hdc
) > 0)
2270 case WM_QUERYNEWPALETTE
:
2272 HDC hdc
= get_ctx();
2274 if (RealizePalette(hdc
) > 0)
2286 * Add the scan code and keypress timing to the random
2289 noise_ultralight(lParam
);
2292 * We don't do TranslateMessage since it disassociates the
2293 * resulting CHAR message from the KEYDOWN that sparked it,
2294 * which we occasionally don't want. Instead, we process
2295 * KEYDOWN, and call the Win32 translator functions so that
2296 * we get the translations under _our_ control.
2299 unsigned char buf
[20];
2302 if (wParam
== VK_PROCESSKEY
) {
2305 m
.message
= WM_KEYDOWN
;
2307 m
.lParam
= lParam
& 0xdfff;
2308 TranslateMessage(&m
);
2310 len
= TranslateKey(message
, wParam
, lParam
, buf
);
2312 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
2316 * Interrupt an ongoing paste. I'm not sure
2317 * this is sensible, but for the moment it's
2318 * preferable to having to faff about buffering
2324 * We need not bother about stdin backlogs
2325 * here, because in GUI PuTTY we can't do
2326 * anything about it anyway; there's no means
2327 * of asking Windows to hold off on KEYDOWN
2328 * messages. We _have_ to buffer everything
2331 ldisc_send(buf
, len
, 1);
2336 net_pending_errors();
2338 case WM_INPUTLANGCHANGE
:
2339 /* wParam == Font number */
2340 /* lParam == Locale */
2341 set_input_locale((HKL
)lParam
);
2344 if(wParam
== IMN_SETOPENSTATUS
) {
2345 HIMC hImc
= ImmGetContext(hwnd
);
2346 ImmSetCompositionFont(hImc
, &lfont
);
2347 ImmReleaseContext(hwnd
, hImc
);
2351 case WM_IME_COMPOSITION
:
2357 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
||
2358 osVersion
.dwPlatformId
== VER_PLATFORM_WIN32s
) break; /* no Unicode */
2360 if ((lParam
& GCS_RESULTSTR
) == 0) /* Composition unfinished. */
2361 break; /* fall back to DefWindowProc */
2363 hIMC
= ImmGetContext(hwnd
);
2364 n
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
2367 buff
= (char*) smalloc(n
);
2368 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, buff
, n
);
2369 luni_send((unsigned short *)buff
, n
/ 2, 1);
2372 ImmReleaseContext(hwnd
, hIMC
);
2377 if (wParam
& 0xFF00) {
2378 unsigned char buf
[2];
2381 buf
[0] = wParam
>> 8;
2382 lpage_send(kbd_codepage
, buf
, 2, 1);
2384 char c
= (unsigned char) wParam
;
2385 lpage_send(kbd_codepage
, &c
, 1, 1);
2391 * Nevertheless, we are prepared to deal with WM_CHAR
2392 * messages, should they crop up. So if someone wants to
2393 * post the things to us as part of a macro manoeuvre,
2394 * we're ready to cope.
2397 char c
= (unsigned char)wParam
;
2398 lpage_send(CP_ACP
, &c
, 1, 1);
2402 if (send_raw_mouse
&& LOWORD(lParam
) == HTCLIENT
) {
2403 SetCursor(LoadCursor(NULL
, IDC_ARROW
));
2408 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
2412 * Move the system caret. (We maintain one, even though it's
2413 * invisible, for the benefit of blind people: apparently some
2414 * helper software tracks the system caret, so we should arrange to
2417 void sys_cursor(int x
, int y
)
2422 if (!has_focus
) return;
2424 SetCaretPos(x
* font_width
+ offset_width
,
2425 y
* font_height
+ offset_height
);
2427 /* IMM calls on Win98 and beyond only */
2428 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32s
) return; /* 3.11 */
2430 if(osVersion
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
&&
2431 osVersion
.dwMinorVersion
== 0) return; /* 95 */
2433 /* we should have the IMM functions */
2434 hIMC
= ImmGetContext(hwnd
);
2435 cf
.dwStyle
= CFS_POINT
;
2436 cf
.ptCurrentPos
.x
= x
* font_width
+ offset_width
;
2437 cf
.ptCurrentPos
.y
= y
* font_height
+ offset_height
;
2438 ImmSetCompositionWindow(hIMC
, &cf
);
2440 ImmReleaseContext(hwnd
, hIMC
);
2444 * Draw a line of text in the window, at given character
2445 * coordinates, in given attributes.
2447 * We are allowed to fiddle with the contents of `text'.
2449 void do_text(Context ctx
, int x
, int y
, char *text
, int len
,
2450 unsigned long attr
, int lattr
)
2453 int nfg
, nbg
, nfont
;
2456 int force_manual_underline
= 0;
2457 int fnt_width
= font_width
* (1 + (lattr
!= LATTR_NORM
));
2458 int char_width
= fnt_width
;
2459 int text_adjust
= 0;
2460 static int *IpDx
= 0, IpDxLEN
= 0;
2462 if (attr
& ATTR_WIDE
)
2465 if (len
> IpDxLEN
|| IpDx
[0] != char_width
) {
2467 if (len
> IpDxLEN
) {
2469 IpDx
= smalloc((len
+ 16) * sizeof(int));
2470 IpDxLEN
= (len
+ 16);
2472 for (i
= 0; i
< IpDxLEN
; i
++)
2473 IpDx
[i
] = char_width
;
2476 /* Only want the left half of double width lines */
2477 if (lattr
!= LATTR_NORM
&& x
*2 >= cols
)
2485 if ((attr
& TATTR_ACTCURS
) && (cfg
.cursor_type
== 0 || big_cursor
)) {
2486 attr
&= ATTR_CUR_AND
| (bold_mode
!= BOLD_COLOURS ? ATTR_BOLD
: 0);
2487 attr
^= ATTR_CUR_XOR
;
2491 if (cfg
.vtmode
== VT_POORMAN
&& lattr
!= LATTR_NORM
) {
2492 /* Assume a poorman font is borken in other ways too. */
2502 nfont
|= FONT_WIDE
+ FONT_HIGH
;
2505 if (attr
& ATTR_NARROW
)
2506 nfont
|= FONT_NARROW
;
2508 /* Special hack for the VT100 linedraw glyphs. */
2509 if ((attr
& CSET_MASK
) == 0x2300) {
2510 if (text
[0] >= (char) 0xBA && text
[0] <= (char) 0xBD) {
2511 switch ((unsigned char) (text
[0])) {
2513 text_adjust
= -2 * font_height
/ 5;
2516 text_adjust
= -1 * font_height
/ 5;
2519 text_adjust
= font_height
/ 5;
2522 text_adjust
= 2 * font_height
/ 5;
2525 if (lattr
== LATTR_TOP
|| lattr
== LATTR_BOT
)
2528 text
[0] = (char) (unitab_xterm
['q'] & CHAR_MASK
);
2529 attr
|= (unitab_xterm
['q'] & CSET_MASK
);
2530 if (attr
& ATTR_UNDER
) {
2531 attr
&= ~ATTR_UNDER
;
2532 force_manual_underline
= 1;
2537 /* Anything left as an original character set is unprintable. */
2538 if (DIRECT_CHAR(attr
)) {
2541 memset(text
, 0xFD, len
);
2545 if ((attr
& CSET_MASK
) == ATTR_OEMCP
)
2548 nfg
= 2 * ((attr
& ATTR_FGMASK
) >> ATTR_FGSHIFT
);
2549 nbg
= 2 * ((attr
& ATTR_BGMASK
) >> ATTR_BGSHIFT
);
2550 if (bold_mode
== BOLD_FONT
&& (attr
& ATTR_BOLD
))
2552 if (und_mode
== UND_FONT
&& (attr
& ATTR_UNDER
))
2553 nfont
|= FONT_UNDERLINE
;
2554 another_font(nfont
);
2555 if (!fonts
[nfont
]) {
2556 if (nfont
& FONT_UNDERLINE
)
2557 force_manual_underline
= 1;
2558 /* Don't do the same for manual bold, it could be bad news. */
2560 nfont
&= ~(FONT_BOLD
| FONT_UNDERLINE
);
2562 another_font(nfont
);
2564 nfont
= FONT_NORMAL
;
2565 if (attr
& ATTR_REVERSE
) {
2570 if (bold_mode
== BOLD_COLOURS
&& (attr
& ATTR_BOLD
))
2572 if (bold_mode
== BOLD_COLOURS
&& (attr
& ATTR_BLINK
))
2576 SelectObject(hdc
, fonts
[nfont
]);
2577 SetTextColor(hdc
, fg
);
2578 SetBkColor(hdc
, bg
);
2579 SetBkMode(hdc
, OPAQUE
);
2582 line_box
.right
= x
+ char_width
* len
;
2583 line_box
.bottom
= y
+ font_height
;
2585 /* Only want the left half of double width lines */
2586 if (line_box
.right
> font_width
*cols
+offset_width
)
2587 line_box
.right
= font_width
*cols
+offset_width
;
2589 /* We're using a private area for direct to font. (512 chars.) */
2590 if (dbcs_screenfont
&& (attr
& CSET_MASK
) == ATTR_ACP
) {
2591 /* Ho Hum, dbcs fonts are a PITA! */
2592 /* To display on W9x I have to convert to UCS */
2593 static wchar_t *uni_buf
= 0;
2594 static int uni_len
= 0;
2596 if (len
> uni_len
) {
2598 uni_buf
= smalloc((uni_len
= len
) * sizeof(wchar_t));
2601 for(nlen
= mptr
= 0; mptr
<len
; mptr
++) {
2602 uni_buf
[nlen
] = 0xFFFD;
2603 if (IsDBCSLeadByteEx(font_codepage
, (BYTE
) text
[mptr
])) {
2604 IpDx
[nlen
] += char_width
;
2605 MultiByteToWideChar(font_codepage
, MB_USEGLYPHCHARS
,
2606 text
+mptr
, 2, uni_buf
+nlen
, 1);
2611 MultiByteToWideChar(font_codepage
, MB_USEGLYPHCHARS
,
2612 text
+mptr
, 1, uni_buf
+nlen
, 1);
2620 y
- font_height
* (lattr
== LATTR_BOT
) + text_adjust
,
2621 ETO_CLIPPED
| ETO_OPAQUE
, &line_box
, uni_buf
, nlen
, IpDx
);
2622 if (bold_mode
== BOLD_SHADOW
&& (attr
& ATTR_BOLD
)) {
2623 SetBkMode(hdc
, TRANSPARENT
);
2624 ExtTextOutW(hdc
, x
- 1,
2625 y
- font_height
* (lattr
==
2626 LATTR_BOT
) + text_adjust
,
2627 ETO_CLIPPED
, &line_box
, uni_buf
, nlen
, IpDx
);
2631 } else if (DIRECT_FONT(attr
)) {
2633 y
- font_height
* (lattr
== LATTR_BOT
) + text_adjust
,
2634 ETO_CLIPPED
| ETO_OPAQUE
, &line_box
, text
, len
, IpDx
);
2635 if (bold_mode
== BOLD_SHADOW
&& (attr
& ATTR_BOLD
)) {
2636 SetBkMode(hdc
, TRANSPARENT
);
2638 /* GRR: This draws the character outside it's box and can leave
2639 * 'droppings' even with the clip box! I suppose I could loop it
2640 * one character at a time ... yuk.
2642 * Or ... I could do a test print with "W", and use +1 or -1 for this
2643 * shift depending on if the leftmost column is blank...
2645 ExtTextOut(hdc
, x
- 1,
2646 y
- font_height
* (lattr
==
2647 LATTR_BOT
) + text_adjust
,
2648 ETO_CLIPPED
, &line_box
, text
, len
, IpDx
);
2651 /* And 'normal' unicode characters */
2652 static WCHAR
*wbuf
= NULL
;
2653 static int wlen
= 0;
2658 wbuf
= smalloc(wlen
* sizeof(WCHAR
));
2660 for (i
= 0; i
< len
; i
++)
2661 wbuf
[i
] = (WCHAR
) ((attr
& CSET_MASK
) + (text
[i
] & CHAR_MASK
));
2664 y
- font_height
* (lattr
== LATTR_BOT
) + text_adjust
,
2665 ETO_CLIPPED
| ETO_OPAQUE
, &line_box
, wbuf
, len
, IpDx
);
2667 /* And the shadow bold hack. */
2668 if (bold_mode
== BOLD_SHADOW
&& (attr
& ATTR_BOLD
)) {
2669 SetBkMode(hdc
, TRANSPARENT
);
2670 ExtTextOutW(hdc
, x
- 1,
2671 y
- font_height
* (lattr
==
2672 LATTR_BOT
) + text_adjust
,
2673 ETO_CLIPPED
, &line_box
, wbuf
, len
, IpDx
);
2676 if (lattr
!= LATTR_TOP
&& (force_manual_underline
||
2677 (und_mode
== UND_LINE
2678 && (attr
& ATTR_UNDER
)))) {
2681 if (lattr
== LATTR_BOT
)
2682 dec
= dec
* 2 - font_height
;
2684 oldpen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, fg
));
2685 MoveToEx(hdc
, x
, y
+ dec
, NULL
);
2686 LineTo(hdc
, x
+ len
* char_width
, y
+ dec
);
2687 oldpen
= SelectObject(hdc
, oldpen
);
2688 DeleteObject(oldpen
);
2692 void do_cursor(Context ctx
, int x
, int y
, char *text
, int len
,
2693 unsigned long attr
, int lattr
)
2699 int ctype
= cfg
.cursor_type
;
2701 if ((attr
& TATTR_ACTCURS
) && (ctype
== 0 || big_cursor
)) {
2702 if (((attr
& CSET_MASK
) | (unsigned char) *text
) != UCSWIDE
) {
2703 do_text(ctx
, x
, y
, text
, len
, attr
, lattr
);
2707 attr
|= TATTR_RIGHTCURS
;
2710 fnt_width
= char_width
= font_width
* (1 + (lattr
!= LATTR_NORM
));
2711 if (attr
& ATTR_WIDE
)
2718 if ((attr
& TATTR_PASCURS
) && (ctype
== 0 || big_cursor
)) {
2721 pts
[0].x
= pts
[1].x
= pts
[4].x
= x
;
2722 pts
[2].x
= pts
[3].x
= x
+ char_width
- 1;
2723 pts
[0].y
= pts
[3].y
= pts
[4].y
= y
;
2724 pts
[1].y
= pts
[2].y
= y
+ font_height
- 1;
2725 oldpen
= SelectObject(hdc
, CreatePen(PS_SOLID
, 0, colours
[23]));
2726 Polyline(hdc
, pts
, 5);
2727 oldpen
= SelectObject(hdc
, oldpen
);
2728 DeleteObject(oldpen
);
2729 } else if ((attr
& (TATTR_ACTCURS
| TATTR_PASCURS
)) && ctype
!= 0) {
2730 int startx
, starty
, dx
, dy
, length
, i
;
2733 starty
= y
+ descent
;
2736 length
= char_width
;
2739 if (attr
& TATTR_RIGHTCURS
)
2740 xadjust
= char_width
- 1;
2741 startx
= x
+ xadjust
;
2745 length
= font_height
;
2747 if (attr
& TATTR_ACTCURS
) {
2750 SelectObject(hdc
, CreatePen(PS_SOLID
, 0, colours
[23]));
2751 MoveToEx(hdc
, startx
, starty
, NULL
);
2752 LineTo(hdc
, startx
+ dx
* length
, starty
+ dy
* length
);
2753 oldpen
= SelectObject(hdc
, oldpen
);
2754 DeleteObject(oldpen
);
2756 for (i
= 0; i
< length
; i
++) {
2758 SetPixel(hdc
, startx
, starty
, colours
[23]);
2767 /* This function gets the actual width of a character in the normal font.
2769 int CharWidth(Context ctx
, int uc
) {
2773 /* If the font max is the same as the font ave width then this
2774 * function is a no-op.
2776 if (!font_dualwidth
) return 1;
2778 switch (uc
& CSET_MASK
) {
2780 uc
= unitab_line
[uc
& 0xFF];
2783 uc
= unitab_xterm
[uc
& 0xFF];
2786 uc
= unitab_scoacs
[uc
& 0xFF];
2789 if (DIRECT_FONT(uc
)) {
2790 if (dbcs_screenfont
) return 1;
2792 /* Speedup, I know of no font where ascii is the wrong width */
2793 if ((uc
&CHAR_MASK
) >= ' ' && (uc
&CHAR_MASK
)<= '~')
2796 if ( (uc
& CSET_MASK
) == ATTR_ACP
) {
2797 SelectObject(hdc
, fonts
[FONT_NORMAL
]);
2798 } else if ( (uc
& CSET_MASK
) == ATTR_OEMCP
) {
2799 another_font(FONT_OEM
);
2800 if (!fonts
[FONT_OEM
]) return 0;
2802 SelectObject(hdc
, fonts
[FONT_OEM
]);
2806 if ( GetCharWidth32(hdc
, uc
&CHAR_MASK
, uc
&CHAR_MASK
, &ibuf
) != 1 &&
2807 GetCharWidth(hdc
, uc
&CHAR_MASK
, uc
&CHAR_MASK
, &ibuf
) != 1)
2810 /* Speedup, I know of no font where ascii is the wrong width */
2811 if (uc
>= ' ' && uc
<= '~') return 1;
2813 SelectObject(hdc
, fonts
[FONT_NORMAL
]);
2814 if ( GetCharWidth32W(hdc
, uc
, uc
, &ibuf
) == 1 )
2815 /* Okay that one worked */ ;
2816 else if ( GetCharWidthW(hdc
, uc
, uc
, &ibuf
) == 1 )
2817 /* This should work on 9x too, but it's "less accurate" */ ;
2822 ibuf
+= font_width
/ 2 -1;
2829 * Translate a WM_(SYS)?KEY(UP|DOWN) message into a string of ASCII
2830 * codes. Returns number of bytes used or zero to drop the message
2831 * or -1 to forward the message to windows.
2833 static int TranslateKey(UINT message
, WPARAM wParam
, LPARAM lParam
,
2834 unsigned char *output
)
2837 int scan
, left_alt
= 0, key_down
, shift_state
;
2839 unsigned char *p
= output
;
2840 static int alt_sum
= 0;
2842 HKL kbd_layout
= GetKeyboardLayout(0);
2844 static WORD keys
[3];
2845 static int compose_char
= 0;
2846 static WPARAM compose_key
= 0;
2848 r
= GetKeyboardState(keystate
);
2850 memset(keystate
, 0, sizeof(keystate
));
2853 #define SHOW_TOASCII_RESULT
2854 { /* Tell us all about key events */
2855 static BYTE oldstate
[256];
2856 static int first
= 1;
2860 memcpy(oldstate
, keystate
, sizeof(oldstate
));
2863 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == KF_REPEAT
) {
2865 } else if ((HIWORD(lParam
) & KF_UP
)
2866 && scan
== (HIWORD(lParam
) & 0xFF)) {
2870 if (wParam
>= VK_F1
&& wParam
<= VK_F20
)
2871 debug(("K_F%d", wParam
+ 1 - VK_F1
));
2884 debug(("VK_%02x", wParam
));
2886 if (message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
2888 debug((", S%02x", scan
= (HIWORD(lParam
) & 0xFF)));
2890 ch
= MapVirtualKeyEx(wParam
, 2, kbd_layout
);
2891 if (ch
>= ' ' && ch
<= '~')
2892 debug((", '%c'", ch
));
2894 debug((", $%02x", ch
));
2897 debug((", KB0=%02x", keys
[0]));
2899 debug((", KB1=%02x", keys
[1]));
2901 debug((", KB2=%02x", keys
[2]));
2903 if ((keystate
[VK_SHIFT
] & 0x80) != 0)
2905 if ((keystate
[VK_CONTROL
] & 0x80) != 0)
2907 if ((HIWORD(lParam
) & KF_EXTENDED
))
2909 if ((HIWORD(lParam
) & KF_UP
))
2913 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == KF_REPEAT
);
2914 else if ((HIWORD(lParam
) & KF_UP
))
2915 oldstate
[wParam
& 0xFF] ^= 0x80;
2917 oldstate
[wParam
& 0xFF] ^= 0x81;
2919 for (ch
= 0; ch
< 256; ch
++)
2920 if (oldstate
[ch
] != keystate
[ch
])
2921 debug((", M%02x=%02x", ch
, keystate
[ch
]));
2923 memcpy(oldstate
, keystate
, sizeof(oldstate
));
2927 if (wParam
== VK_MENU
&& (HIWORD(lParam
) & KF_EXTENDED
)) {
2928 keystate
[VK_RMENU
] = keystate
[VK_MENU
];
2932 /* Nastyness with NUMLock - Shift-NUMLock is left alone though */
2933 if ((cfg
.funky_type
== 3 ||
2934 (cfg
.funky_type
<= 1 && app_keypad_keys
&& !cfg
.no_applic_k
))
2935 && wParam
== VK_NUMLOCK
&& !(keystate
[VK_SHIFT
] & 0x80)) {
2937 wParam
= VK_EXECUTE
;
2939 /* UnToggle NUMLock */
2940 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == 0)
2941 keystate
[VK_NUMLOCK
] ^= 1;
2944 /* And write back the 'adjusted' state */
2945 SetKeyboardState(keystate
);
2948 /* Disable Auto repeat if required */
2949 if (repeat_off
&& (HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == KF_REPEAT
)
2952 if ((HIWORD(lParam
) & KF_ALTDOWN
) && (keystate
[VK_RMENU
] & 0x80) == 0)
2955 key_down
= ((HIWORD(lParam
) & KF_UP
) == 0);
2957 /* Make sure Ctrl-ALT is not the same as AltGr for ToAscii unless told. */
2958 if (left_alt
&& (keystate
[VK_CONTROL
] & 0x80)) {
2959 if (cfg
.ctrlaltkeys
)
2960 keystate
[VK_MENU
] = 0;
2962 keystate
[VK_RMENU
] = 0x80;
2967 alt_pressed
= (left_alt
&& key_down
);
2969 scan
= (HIWORD(lParam
) & (KF_UP
| KF_EXTENDED
| 0xFF));
2970 shift_state
= ((keystate
[VK_SHIFT
] & 0x80) != 0)
2971 + ((keystate
[VK_CONTROL
] & 0x80) != 0) * 2;
2973 /* Note if AltGr was pressed and if it was used as a compose key */
2974 if (!compose_state
) {
2975 compose_key
= 0x100;
2976 if (cfg
.compose_key
) {
2977 if (wParam
== VK_MENU
&& (HIWORD(lParam
) & KF_EXTENDED
))
2978 compose_key
= wParam
;
2980 if (wParam
== VK_APPS
)
2981 compose_key
= wParam
;
2984 if (wParam
== compose_key
) {
2985 if (compose_state
== 0
2986 && (HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) == 0) compose_state
=
2988 else if (compose_state
== 1 && (HIWORD(lParam
) & KF_UP
))
2992 } else if (compose_state
== 1 && wParam
!= VK_CONTROL
)
2996 * Record that we pressed key so the scroll window can be reset, but
2997 * be careful to avoid Shift-UP/Down
2999 if (wParam
!= VK_SHIFT
&& wParam
!= VK_PRIOR
&& wParam
!= VK_NEXT
&&
3000 wParam
!= VK_MENU
&& wParam
!= VK_CONTROL
) {
3004 if (compose_state
> 1 && left_alt
)
3007 /* Sanitize the number pad if not using a PC NumPad */
3008 if (left_alt
|| (app_keypad_keys
&& !cfg
.no_applic_k
3009 && cfg
.funky_type
!= 2)
3010 || cfg
.funky_type
== 3 || cfg
.nethack_keypad
|| compose_state
) {
3011 if ((HIWORD(lParam
) & KF_EXTENDED
) == 0) {
3015 nParam
= VK_NUMPAD0
;
3018 nParam
= VK_NUMPAD1
;
3021 nParam
= VK_NUMPAD2
;
3024 nParam
= VK_NUMPAD3
;
3027 nParam
= VK_NUMPAD4
;
3030 nParam
= VK_NUMPAD5
;
3033 nParam
= VK_NUMPAD6
;
3036 nParam
= VK_NUMPAD7
;
3039 nParam
= VK_NUMPAD8
;
3042 nParam
= VK_NUMPAD9
;
3045 nParam
= VK_DECIMAL
;
3049 if (keystate
[VK_NUMLOCK
] & 1)
3056 /* If a key is pressed and AltGr is not active */
3057 if (key_down
&& (keystate
[VK_RMENU
] & 0x80) == 0 && !compose_state
) {
3058 /* Okay, prepare for most alts then ... */
3062 /* Lets see if it's a pattern we know all about ... */
3063 if (wParam
== VK_PRIOR
&& shift_state
== 1) {
3064 SendMessage(hwnd
, WM_VSCROLL
, SB_PAGEUP
, 0);
3067 if (wParam
== VK_NEXT
&& shift_state
== 1) {
3068 SendMessage(hwnd
, WM_VSCROLL
, SB_PAGEDOWN
, 0);
3071 if (wParam
== VK_INSERT
&& shift_state
== 1) {
3075 if (left_alt
&& wParam
== VK_F4
&& cfg
.alt_f4
) {
3078 if (left_alt
&& wParam
== VK_SPACE
&& cfg
.alt_space
) {
3079 SendMessage(hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, 0);
3082 if (left_alt
&& wParam
== VK_RETURN
&& cfg
.fullscreenonaltenter
&&
3083 (cfg
.resize_action
!= RESIZE_DISABLED
)) {
3084 if ((HIWORD(lParam
) & (KF_UP
| KF_REPEAT
)) != KF_REPEAT
)
3088 /* Control-Numlock for app-keypad mode switch */
3089 if (wParam
== VK_PAUSE
&& shift_state
== 2) {
3090 app_keypad_keys
^= 1;
3094 /* Nethack keypad */
3095 if (cfg
.nethack_keypad
&& !left_alt
) {
3098 *p
++ = shift_state ?
'B' : 'b';
3101 *p
++ = shift_state ?
'J' : 'j';
3104 *p
++ = shift_state ?
'N' : 'n';
3107 *p
++ = shift_state ?
'H' : 'h';
3110 *p
++ = shift_state ?
'.' : '.';
3113 *p
++ = shift_state ?
'L' : 'l';
3116 *p
++ = shift_state ?
'Y' : 'y';
3119 *p
++ = shift_state ?
'K' : 'k';
3122 *p
++ = shift_state ?
'U' : 'u';
3127 /* Application Keypad */
3131 if (cfg
.funky_type
== 3 ||
3132 (cfg
.funky_type
<= 1 &&
3133 app_keypad_keys
&& !cfg
.no_applic_k
)) switch (wParam
) {
3147 if (app_keypad_keys
&& !cfg
.no_applic_k
)
3184 if (cfg
.funky_type
== 2) {
3189 } else if (shift_state
)
3196 if (cfg
.funky_type
== 2)
3200 if (cfg
.funky_type
== 2)
3204 if (cfg
.funky_type
== 2)
3209 if (HIWORD(lParam
) & KF_EXTENDED
)
3215 if (xkey
>= 'P' && xkey
<= 'S')
3216 p
+= sprintf((char *) p
, "\x1B%c", xkey
);
3218 p
+= sprintf((char *) p
, "\x1B?%c", xkey
);
3220 p
+= sprintf((char *) p
, "\x1BO%c", xkey
);
3225 if (wParam
== VK_BACK
&& shift_state
== 0) { /* Backspace */
3226 *p
++ = (cfg
.bksp_is_delete ?
0x7F : 0x08);
3230 if (wParam
== VK_TAB
&& shift_state
== 1) { /* Shift tab */
3236 if (wParam
== VK_SPACE
&& shift_state
== 2) { /* Ctrl-Space */
3240 if (wParam
== VK_SPACE
&& shift_state
== 3) { /* Ctrl-Shift-Space */
3244 if (wParam
== VK_CANCEL
&& shift_state
== 2) { /* Ctrl-Break */
3249 if (wParam
== VK_PAUSE
) { /* Break/Pause */
3254 /* Control-2 to Control-8 are special */
3255 if (shift_state
== 2 && wParam
>= '2' && wParam
<= '8') {
3256 *p
++ = "\000\033\034\035\036\037\177"[wParam
- '2'];
3259 if (shift_state
== 2 && wParam
== 0xBD) {
3263 if (shift_state
== 2 && wParam
== 0xDF) {
3267 if (shift_state
== 0 && wParam
== VK_RETURN
&& cr_lf_return
) {
3274 * Next, all the keys that do tilde codes. (ESC '[' nn '~',
3275 * for integer decimal nn.)
3277 * We also deal with the weird ones here. Linux VCs replace F1
3278 * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but
3279 * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w
3285 code
= (keystate
[VK_SHIFT
] & 0x80 ?
23 : 11);
3288 code
= (keystate
[VK_SHIFT
] & 0x80 ?
24 : 12);
3291 code
= (keystate
[VK_SHIFT
] & 0x80 ?
25 : 13);
3294 code
= (keystate
[VK_SHIFT
] & 0x80 ?
26 : 14);
3297 code
= (keystate
[VK_SHIFT
] & 0x80 ?
28 : 15);
3300 code
= (keystate
[VK_SHIFT
] & 0x80 ?
29 : 17);
3303 code
= (keystate
[VK_SHIFT
] & 0x80 ?
31 : 18);
3306 code
= (keystate
[VK_SHIFT
] & 0x80 ?
32 : 19);
3309 code
= (keystate
[VK_SHIFT
] & 0x80 ?
33 : 20);
3312 code
= (keystate
[VK_SHIFT
] & 0x80 ?
34 : 21);
3345 if ((shift_state
&2) == 0) switch (wParam
) {
3365 /* Reorder edit keys to physical order */
3366 if (cfg
.funky_type
== 3 && code
<= 6)
3367 code
= "\0\2\1\4\5\3\6"[code
];
3369 if (vt52_mode
&& code
> 0 && code
<= 6) {
3370 p
+= sprintf((char *) p
, "\x1B%c", " HLMEIG"[code
]);
3374 if (cfg
.funky_type
== 5 && /* SCO function keys */
3375 code
>= 11 && code
<= 34) {
3376 char codes
[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
3379 case VK_F1
: index
= 0; break;
3380 case VK_F2
: index
= 1; break;
3381 case VK_F3
: index
= 2; break;
3382 case VK_F4
: index
= 3; break;
3383 case VK_F5
: index
= 4; break;
3384 case VK_F6
: index
= 5; break;
3385 case VK_F7
: index
= 6; break;
3386 case VK_F8
: index
= 7; break;
3387 case VK_F9
: index
= 8; break;
3388 case VK_F10
: index
= 9; break;
3389 case VK_F11
: index
= 10; break;
3390 case VK_F12
: index
= 11; break;
3392 if (keystate
[VK_SHIFT
] & 0x80) index
+= 12;
3393 if (keystate
[VK_CONTROL
] & 0x80) index
+= 24;
3394 p
+= sprintf((char *) p
, "\x1B[%c", codes
[index
]);
3397 if (cfg
.funky_type
== 5 && /* SCO small keypad */
3398 code
>= 1 && code
<= 6) {
3399 char codes
[] = "HL.FIG";
3403 p
+= sprintf((char *) p
, "\x1B[%c", codes
[code
-1]);
3407 if ((vt52_mode
|| cfg
.funky_type
== 4) && code
>= 11 && code
<= 24) {
3414 p
+= sprintf((char *) p
, "\x1B%c", code
+ 'P' - 11 - offt
);
3417 sprintf((char *) p
, "\x1BO%c", code
+ 'P' - 11 - offt
);
3420 if (cfg
.funky_type
== 1 && code
>= 11 && code
<= 15) {
3421 p
+= sprintf((char *) p
, "\x1B[[%c", code
+ 'A' - 11);
3424 if (cfg
.funky_type
== 2 && code
>= 11 && code
<= 14) {
3426 p
+= sprintf((char *) p
, "\x1B%c", code
+ 'P' - 11);
3428 p
+= sprintf((char *) p
, "\x1BO%c", code
+ 'P' - 11);
3431 if (cfg
.rxvt_homeend
&& (code
== 1 || code
== 4)) {
3432 p
+= sprintf((char *) p
, code
== 1 ?
"\x1B[H" : "\x1BOw");
3436 p
+= sprintf((char *) p
, "\x1B[%d~", code
);
3441 * Now the remaining keys (arrows and Keypad 5. Keypad 5 for
3442 * some reason seems to send VK_CLEAR to Windows...).
3465 p
+= sprintf((char *) p
, "\x1B%c", xkey
);
3467 int app_flg
= (app_cursor_keys
&& !cfg
.no_applic_c
);
3468 /* VT100 & VT102 manuals both state the app cursor keys
3469 * only work if the app keypad is on.
3471 if (!app_keypad_keys
)
3473 /* Useful mapping of Ctrl-arrows */
3474 if (shift_state
== 2)
3478 p
+= sprintf((char *) p
, "\x1BO%c", xkey
);
3480 p
+= sprintf((char *) p
, "\x1B[%c", xkey
);
3487 * Finally, deal with Return ourselves. (Win95 seems to
3488 * foul it up when Alt is pressed, for some reason.)
3490 if (wParam
== VK_RETURN
) { /* Return */
3496 if (left_alt
&& wParam
>= VK_NUMPAD0
&& wParam
<= VK_NUMPAD9
)
3497 alt_sum
= alt_sum
* 10 + wParam
- VK_NUMPAD0
;
3502 /* Okay we've done everything interesting; let windows deal with
3503 * the boring stuff */
3507 /* helg: clear CAPS LOCK state if caps lock switches to cyrillic */
3508 if(cfg
.xlat_capslockcyr
&& keystate
[VK_CAPITAL
] != 0) {
3510 keystate
[VK_CAPITAL
] = 0;
3513 r
= ToAsciiEx(wParam
, scan
, keystate
, keys
, 0, kbd_layout
);
3514 #ifdef SHOW_TOASCII_RESULT
3515 if (r
== 1 && !key_down
) {
3517 if (in_utf
|| dbcs_screenfont
)
3518 debug((", (U+%04x)", alt_sum
));
3520 debug((", LCH(%d)", alt_sum
));
3522 debug((", ACH(%d)", keys
[0]));
3527 for (r1
= 0; r1
< r
; r1
++) {
3528 debug(("%s%d", r1 ?
"," : "", keys
[r1
]));
3537 * Interrupt an ongoing paste. I'm not sure this is
3538 * sensible, but for the moment it's preferable to
3539 * having to faff about buffering things.
3544 for (i
= 0; i
< r
; i
++) {
3545 unsigned char ch
= (unsigned char) keys
[i
];
3547 if (compose_state
== 2 && (ch
& 0x80) == 0 && ch
> ' ') {
3552 if (compose_state
== 3 && (ch
& 0x80) == 0 && ch
> ' ') {
3556 if ((nc
= check_compose(compose_char
, ch
)) == -1) {
3557 MessageBeep(MB_ICONHAND
);
3561 luni_send(&keybuf
, 1, 1);
3569 if (in_utf
|| dbcs_screenfont
) {
3571 luni_send(&keybuf
, 1, 1);
3573 ch
= (char) alt_sum
;
3575 * We need not bother about stdin
3576 * backlogs here, because in GUI PuTTY
3577 * we can't do anything about it
3578 * anyway; there's no means of asking
3579 * Windows to hold off on KEYDOWN
3580 * messages. We _have_ to buffer
3581 * everything we're sent.
3583 ldisc_send(&ch
, 1, 1);
3587 lpage_send(kbd_codepage
, &ch
, 1, 1);
3589 if(capsOn
&& ch
< 0x80) {
3592 cbuf
[1] = xlat_uskbd2cyrllic(ch
);
3593 luni_send(cbuf
+!left_alt
, 1+!!left_alt
, 1);
3598 lpage_send(kbd_codepage
, cbuf
+!left_alt
, 1+!!left_alt
, 1);
3604 /* This is so the ALT-Numpad and dead keys work correctly. */
3609 /* If we're definitly not building up an ALT-54321 then clear it */
3612 /* If we will be using alt_sum fix the 256s */
3613 else if (keys
[0] && (in_utf
|| dbcs_screenfont
))
3618 * ALT alone may or may not want to bring up the System menu.
3619 * If it's not meant to, we return 0 on presses or releases of
3620 * ALT, to show that we've swallowed the keystroke. Otherwise
3621 * we return -1, which means Windows will give the keystroke
3622 * its default handling (i.e. bring up the System menu).
3624 if (wParam
== VK_MENU
&& !cfg
.alt_only
)
3630 void set_title(char *title
)
3633 window_name
= smalloc(1 + strlen(title
));
3634 strcpy(window_name
, title
);
3635 if (cfg
.win_name_always
|| !IsIconic(hwnd
))
3636 SetWindowText(hwnd
, title
);
3639 void set_icon(char *title
)
3642 icon_name
= smalloc(1 + strlen(title
));
3643 strcpy(icon_name
, title
);
3644 if (!cfg
.win_name_always
&& IsIconic(hwnd
))
3645 SetWindowText(hwnd
, title
);
3648 void set_sbar(int total
, int start
, int page
)
3652 if ((full_screen
&& !cfg
.scrollbar_in_fullscreen
) ||
3653 (!full_screen
&& !cfg
.scrollbar
))
3656 si
.cbSize
= sizeof(si
);
3657 si
.fMask
= SIF_ALL
| SIF_DISABLENOSCROLL
;
3659 si
.nMax
= total
- 1;
3663 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
3666 Context
get_ctx(void)
3672 SelectPalette(hdc
, pal
, FALSE
);
3678 void free_ctx(Context ctx
)
3680 SelectPalette(ctx
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
3681 ReleaseDC(hwnd
, ctx
);
3684 static void real_palette_set(int n
, int r
, int g
, int b
)
3687 logpal
->palPalEntry
[n
].peRed
= r
;
3688 logpal
->palPalEntry
[n
].peGreen
= g
;
3689 logpal
->palPalEntry
[n
].peBlue
= b
;
3690 logpal
->palPalEntry
[n
].peFlags
= PC_NOCOLLAPSE
;
3691 colours
[n
] = PALETTERGB(r
, g
, b
);
3692 SetPaletteEntries(pal
, 0, NCOLOURS
, logpal
->palPalEntry
);
3694 colours
[n
] = RGB(r
, g
, b
);
3697 void palette_set(int n
, int r
, int g
, int b
)
3699 static const int first
[21] = {
3700 0, 2, 4, 6, 8, 10, 12, 14,
3701 1, 3, 5, 7, 9, 11, 13, 15,
3704 real_palette_set(first
[n
], r
, g
, b
);
3706 real_palette_set(first
[n
] + 1, r
, g
, b
);
3708 HDC hdc
= get_ctx();
3709 UnrealizeObject(pal
);
3710 RealizePalette(hdc
);
3715 void palette_reset(void)
3719 for (i
= 0; i
< NCOLOURS
; i
++) {
3721 logpal
->palPalEntry
[i
].peRed
= defpal
[i
].rgbtRed
;
3722 logpal
->palPalEntry
[i
].peGreen
= defpal
[i
].rgbtGreen
;
3723 logpal
->palPalEntry
[i
].peBlue
= defpal
[i
].rgbtBlue
;
3724 logpal
->palPalEntry
[i
].peFlags
= 0;
3725 colours
[i
] = PALETTERGB(defpal
[i
].rgbtRed
,
3726 defpal
[i
].rgbtGreen
,
3727 defpal
[i
].rgbtBlue
);
3729 colours
[i
] = RGB(defpal
[i
].rgbtRed
,
3730 defpal
[i
].rgbtGreen
, defpal
[i
].rgbtBlue
);
3735 SetPaletteEntries(pal
, 0, NCOLOURS
, logpal
->palPalEntry
);
3737 RealizePalette(hdc
);
3742 void write_aclip(char *data
, int len
, int must_deselect
)
3747 clipdata
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, len
+ 1);
3750 lock
= GlobalLock(clipdata
);
3753 memcpy(lock
, data
, len
);
3754 ((unsigned char *) lock
)[len
] = 0;
3755 GlobalUnlock(clipdata
);
3758 SendMessage(hwnd
, WM_IGNORE_CLIP
, TRUE
, 0);
3760 if (OpenClipboard(hwnd
)) {
3762 SetClipboardData(CF_TEXT
, clipdata
);
3765 GlobalFree(clipdata
);
3768 SendMessage(hwnd
, WM_IGNORE_CLIP
, FALSE
, 0);
3772 * Note: unlike write_aclip() this will not append a nul.
3774 void write_clip(wchar_t * data
, int len
, int must_deselect
)
3776 HGLOBAL clipdata
, clipdata2
, clipdata3
;
3778 void *lock
, *lock2
, *lock3
;
3780 len2
= WideCharToMultiByte(CP_ACP
, 0, data
, len
, 0, 0, NULL
, NULL
);
3782 clipdata
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
,
3783 len
* sizeof(wchar_t));
3784 clipdata2
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, len2
);
3786 if (!clipdata
|| !clipdata2
|| !clipdata3
) {
3788 GlobalFree(clipdata
);
3790 GlobalFree(clipdata2
);
3792 GlobalFree(clipdata3
);
3795 if (!(lock
= GlobalLock(clipdata
)))
3797 if (!(lock2
= GlobalLock(clipdata2
)))
3800 memcpy(lock
, data
, len
* sizeof(wchar_t));
3801 WideCharToMultiByte(CP_ACP
, 0, data
, len
, lock2
, len2
, NULL
, NULL
);
3803 if (cfg
.rtf_paste
) {
3804 wchar_t unitab
[256];
3806 unsigned char *tdata
= (unsigned char *)lock2
;
3807 wchar_t *udata
= (wchar_t *)lock
;
3808 int rtflen
= 0, uindex
= 0, tindex
= 0;
3810 int multilen
, blen
, alen
, totallen
, i
;
3811 char before
[16], after
[4];
3813 get_unitab(CP_ACP
, unitab
, 0);
3815 rtfsize
= 100 + strlen(cfg
.font
);
3816 rtf
= smalloc(rtfsize
);
3817 sprintf(rtf
, "{\\rtf1\\ansi%d{\\fonttbl\\f0\\fmodern %s;}\\f0",
3818 GetACP(), cfg
.font
);
3819 rtflen
= strlen(rtf
);
3822 * We want to construct a piece of RTF that specifies the
3823 * same Unicode text. To do this we will read back in
3824 * parallel from the Unicode data in `udata' and the
3825 * non-Unicode data in `tdata'. For each character in
3826 * `tdata' which becomes the right thing in `udata' when
3827 * looked up in `unitab', we just copy straight over from
3828 * tdata. For each one that doesn't, we must WCToMB it
3829 * individually and produce a \u escape sequence.
3831 * It would probably be more robust to just bite the bullet
3832 * and WCToMB each individual Unicode character one by one,
3833 * then MBToWC each one back to see if it was an accurate
3834 * translation; but that strikes me as a horrifying number
3835 * of Windows API calls so I want to see if this faster way
3836 * will work. If it screws up badly we can always revert to
3837 * the simple and slow way.
3839 while (tindex
< len2
&& uindex
< len
&&
3840 tdata
[tindex
] && udata
[uindex
]) {
3841 if (tindex
+ 1 < len2
&&
3842 tdata
[tindex
] == '\r' &&
3843 tdata
[tindex
+1] == '\n') {
3847 if (unitab
[tdata
[tindex
]] == udata
[uindex
]) {
3853 multilen
= WideCharToMultiByte(CP_ACP
, 0, unitab
+uindex
, 1,
3854 NULL
, 0, NULL
, NULL
);
3855 if (multilen
!= 1) {
3856 blen
= sprintf(before
, "{\\uc%d\\u%d", multilen
,
3858 alen
= 1; strcpy(after
, "}");
3860 blen
= sprintf(before
, "\\u%d", udata
[uindex
]);
3861 alen
= 0; after
[0] = '\0';
3864 assert(tindex
+ multilen
<= len2
);
3865 totallen
= blen
+ alen
;
3866 for (i
= 0; i
< multilen
; i
++) {
3867 if (tdata
[tindex
+i
] == '\\' ||
3868 tdata
[tindex
+i
] == '{' ||
3869 tdata
[tindex
+i
] == '}')
3871 else if (tdata
[tindex
+i
] == 0x0D || tdata
[tindex
+i
] == 0x0A)
3872 totallen
+= 6; /* \par\r\n */
3873 else if (tdata
[tindex
+i
] > 0x7E || tdata
[tindex
+i
] < 0x20)
3879 if (rtfsize
< rtflen
+ totallen
+ 3) {
3880 rtfsize
= rtflen
+ totallen
+ 512;
3881 rtf
= srealloc(rtf
, rtfsize
);
3884 strcpy(rtf
+ rtflen
, before
); rtflen
+= blen
;
3885 for (i
= 0; i
< multilen
; i
++) {
3886 if (tdata
[tindex
+i
] == '\\' ||
3887 tdata
[tindex
+i
] == '{' ||
3888 tdata
[tindex
+i
] == '}') {
3889 rtf
[rtflen
++] = '\\';
3890 rtf
[rtflen
++] = tdata
[tindex
+i
];
3891 } else if (tdata
[tindex
+i
] == 0x0D || tdata
[tindex
+i
] == 0x0A) {
3892 rtflen
+= sprintf(rtf
+rtflen
, "\\par\r\n");
3893 } else if (tdata
[tindex
+i
] > 0x7E || tdata
[tindex
+i
] < 0x20) {
3894 rtflen
+= sprintf(rtf
+rtflen
, "\\'%02x", tdata
[tindex
+i
]);
3896 rtf
[rtflen
++] = tdata
[tindex
+i
];
3899 strcpy(rtf
+ rtflen
, after
); rtflen
+= alen
;
3905 strcpy(rtf
+ rtflen
, "}");
3908 clipdata3
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, rtflen
);
3909 if (clipdata3
&& (lock3
= GlobalLock(clipdata3
)) != NULL
) {
3911 GlobalUnlock(clipdata3
);
3917 GlobalUnlock(clipdata
);
3918 GlobalUnlock(clipdata2
);
3921 SendMessage(hwnd
, WM_IGNORE_CLIP
, TRUE
, 0);
3923 if (OpenClipboard(hwnd
)) {
3925 SetClipboardData(CF_UNICODETEXT
, clipdata
);
3926 SetClipboardData(CF_TEXT
, clipdata2
);
3928 SetClipboardData(RegisterClipboardFormat(CF_RTF
), clipdata3
);
3931 GlobalFree(clipdata
);
3932 GlobalFree(clipdata2
);
3936 SendMessage(hwnd
, WM_IGNORE_CLIP
, FALSE
, 0);
3939 void get_clip(wchar_t ** p
, int *len
)
3941 static HGLOBAL clipdata
= NULL
;
3942 static wchar_t *converted
= 0;
3951 GlobalUnlock(clipdata
);
3954 } else if (OpenClipboard(NULL
)) {
3955 if ((clipdata
= GetClipboardData(CF_UNICODETEXT
))) {
3957 *p
= GlobalLock(clipdata
);
3959 for (p2
= *p
; *p2
; p2
++);
3963 } else if ( (clipdata
= GetClipboardData(CF_TEXT
)) ) {
3967 s
= GlobalLock(clipdata
);
3968 i
= MultiByteToWideChar(CP_ACP
, 0, s
, strlen(s
) + 1, 0, 0);
3969 *p
= converted
= smalloc(i
* sizeof(wchar_t));
3970 MultiByteToWideChar(CP_ACP
, 0, s
, strlen(s
) + 1, converted
, i
);
3983 * Move `lines' lines from position `from' to position `to' in the
3986 void optimised_move(int to
, int from
, int lines
)
3991 min
= (to
< from ? to
: from
);
3992 max
= to
+ from
- min
;
3994 r
.left
= offset_width
;
3995 r
.right
= offset_width
+ cols
* font_width
;
3996 r
.top
= offset_height
+ min
* font_height
;
3997 r
.bottom
= offset_height
+ (max
+ lines
) * font_height
;
3998 ScrollWindow(hwnd
, 0, (to
- from
) * font_height
, &r
, &r
);
4003 * Print a message box and perform a fatal exit.
4005 void fatalbox(char *fmt
, ...)
4011 vsprintf(stuff
, fmt
, ap
);
4013 MessageBox(hwnd
, stuff
, "PuTTY Fatal Error", MB_ICONERROR
| MB_OK
);
4018 * Manage window caption / taskbar flashing, if enabled.
4019 * 0 = stop, 1 = maintain, 2 = start
4021 static void flash_window(int mode
)
4023 static long last_flash
= 0;
4024 static int flashing
= 0;
4025 if ((mode
== 0) || (cfg
.beep_ind
== B_IND_DISABLED
)) {
4028 FlashWindow(hwnd
, FALSE
);
4032 } else if (mode
== 2) {
4035 last_flash
= GetTickCount();
4037 FlashWindow(hwnd
, TRUE
);
4040 } else if ((mode
== 1) && (cfg
.beep_ind
== B_IND_FLASH
)) {
4043 long now
= GetTickCount();
4044 long fdiff
= now
- last_flash
;
4045 if (fdiff
< 0 || fdiff
> 450) {
4047 FlashWindow(hwnd
, TRUE
); /* toggle */
4058 if (mode
== BELL_DEFAULT
) {
4060 * For MessageBeep style bells, we want to be careful of
4061 * timing, because they don't have the nice property of
4062 * PlaySound bells that each one cancels the previous
4063 * active one. So we limit the rate to one per 50ms or so.
4065 static long lastbeep
= 0;
4068 beepdiff
= GetTickCount() - lastbeep
;
4069 if (beepdiff
>= 0 && beepdiff
< 50)
4073 * The above MessageBeep call takes time, so we record the
4074 * time _after_ it finishes rather than before it starts.
4076 lastbeep
= GetTickCount();
4077 } else if (mode
== BELL_WAVEFILE
) {
4078 if (!PlaySound(cfg
.bell_wavefile
, NULL
, SND_ASYNC
| SND_FILENAME
)) {
4079 char buf
[sizeof(cfg
.bell_wavefile
) + 80];
4080 sprintf(buf
, "Unable to play sound file\n%s\n"
4081 "Using default sound instead", cfg
.bell_wavefile
);
4082 MessageBox(hwnd
, buf
, "PuTTY Sound Error",
4083 MB_OK
| MB_ICONEXCLAMATION
);
4084 cfg
.beep
= BELL_DEFAULT
;
4087 /* Otherwise, either visual bell or disabled; do nothing here */
4089 flash_window(2); /* start */
4094 * Toggle full screen mode. Thanks to cwis@nerim.fr for the
4096 * Revised by <wez@thebrainroom.com>
4098 static void flip_full_screen(void)
4103 wp
.length
= sizeof(wp
);
4104 GetWindowPlacement(hwnd
, &wp
);
4106 full_screen
= !full_screen
;
4109 if (wp
.showCmd
== SW_SHOWMAXIMIZED
) {
4110 /* Ooops it was already 'zoomed' we have to unzoom it before
4111 * everything will work right.
4113 wp
.showCmd
= SW_SHOWNORMAL
;
4114 SetWindowPlacement(hwnd
, &wp
);
4117 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~(WS_CAPTION
|WS_THICKFRAME
);
4118 style
&= ~WS_VSCROLL
;
4119 if (cfg
.scrollbar_in_fullscreen
)
4120 style
|= WS_VSCROLL
;
4121 SetWindowLong(hwnd
, GWL_STYLE
, style
);
4123 /* Some versions of explorer get confused and don't take
4124 * notice of us going fullscreen, so go topmost too.
4126 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0,
4127 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
4128 SWP_NOMOVE
| SWP_NOSIZE
|
4131 wp
.showCmd
= SW_SHOWMAXIMIZED
;
4132 SetWindowPlacement(hwnd
, &wp
);
4134 style
= GetWindowLong(hwnd
, GWL_STYLE
) | WS_CAPTION
;
4135 if (cfg
.resize_action
!= RESIZE_DISABLED
)
4136 style
|= WS_THICKFRAME
;
4137 style
&= ~WS_VSCROLL
;
4139 style
|= WS_VSCROLL
;
4140 SetWindowLong(hwnd
, GWL_STYLE
, style
);
4142 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0,
4143 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
4144 SWP_NOMOVE
| SWP_NOSIZE
|
4147 wp
.showCmd
= SW_SHOWNORMAL
;
4148 SetWindowPlacement(hwnd
, &wp
);
4151 CheckMenuItem(GetSystemMenu(hwnd
, FALSE
), IDM_FULLSCREEN
,
4152 MF_BYCOMMAND
| full_screen ? MF_CHECKED
: MF_UNCHECKED
);
4156 * Minimise or restore the window in response to a server-side
4159 void set_iconic(int iconic
)
4161 if (IsIconic(hwnd
)) {
4163 ShowWindow(hwnd
, SW_RESTORE
);
4166 ShowWindow(hwnd
, SW_MINIMIZE
);
4171 * Move the window in response to a server-side request.
4173 void move_window(int x
, int y
)
4175 SetWindowPos(hwnd
, NULL
, x
, y
, 0, 0, SWP_NOSIZE
| SWP_NOZORDER
);
4179 * Move the window to the top or bottom of the z-order in response
4180 * to a server-side request.
4182 void set_zorder(int top
)
4184 if (cfg
.alwaysontop
|| full_screen
)
4185 return; /* ignore */
4186 SetWindowPos(hwnd
, top ? HWND_TOP
: HWND_BOTTOM
, 0, 0, 0, 0,
4187 SWP_NOMOVE
| SWP_NOSIZE
);
4191 * Refresh the window in response to a server-side request.
4193 void refresh_window(void)
4195 InvalidateRect(hwnd
, NULL
, TRUE
);
4199 * Maximise or restore the window in response to a server-side
4202 void set_zoomed(int zoomed
)
4204 if (IsZoomed(hwnd
) || full_screen
) {
4209 ShowWindow(hwnd
, SW_RESTORE
);
4213 ShowWindow(hwnd
, SW_MAXIMIZE
);
4218 * Report whether the window is iconic, for terminal reports.
4222 return IsIconic(hwnd
);
4226 * Report the window's position, for terminal reports.
4228 void get_window_pos(int *x
, int *y
)
4231 GetWindowRect(hwnd
, &r
);
4237 * Report the window's pixel size, for terminal reports.
4239 void get_window_pixels(int *x
, int *y
)
4242 GetWindowRect(hwnd
, &r
);
4243 *x
= r
.right
- r
.left
;
4244 *y
= r
.bottom
- r
.top
;
4248 * Return the window or icon title.
4250 char *get_window_title(int icon
)
4252 return icon ? icon_name
: window_name
;