📄 window.c
字号:
return cfg.mouse_is_xterm == 1 ? MBT_PASTE : MBT_EXTEND;
if (button == MBT_RIGHT)
return cfg.mouse_is_xterm == 1 ? MBT_EXTEND : MBT_PASTE;
return 0; /* shouldn't happen */
}
static void show_mouseptr(int show)
{
/* NB that the counter in ShowCursor() is also frobbed by
* update_mouse_pointer() */
static int cursor_visible = 1;
if (!cfg.hide_mouseptr) /* override if this feature disabled */
show = 1;
if (cursor_visible && !show)
ShowCursor(FALSE);
else if (!cursor_visible && show)
ShowCursor(TRUE);
cursor_visible = show;
}
static int is_alt_pressed(void)
{
BYTE keystate[256];
int r = GetKeyboardState(keystate);
if (!r)
return FALSE;
if (keystate[VK_MENU] & 0x80)
return TRUE;
if (keystate[VK_RMENU] & 0x80)
return TRUE;
return FALSE;
}
static int is_shift_pressed(void)
{
BYTE keystate[256];
int r = GetKeyboardState(keystate);
if (!r)
return FALSE;
if (keystate[VK_SHIFT] & 0x80)
return TRUE;
return FALSE;
}
static int resizing;
void notify_remote_exit(void *fe)
{
int exitcode;
if (!session_closed &&
(exitcode = back->exitcode(backhandle)) >= 0) {
/* Abnormal exits will already have set session_closed and taken
* appropriate action. */
if (cfg.close_on_exit == FORCE_ON ||
(cfg.close_on_exit == AUTO && exitcode != INT_MAX)) {
PostQuitMessage(0);
} else {
must_close_session = TRUE;
session_closed = TRUE;
/* exitcode == INT_MAX indicates that the connection was closed
* by a fatal error, so an error box will be coming our way and
* we should not generate this informational one. */
if (exitcode != INT_MAX)
MessageBox(hwnd, "Connection closed by remote host",
appname, MB_OK | MB_ICONINFORMATION);
}
}
}
void timer_change_notify(long next)
{
long ticks = next - GETTICKCOUNT();
if (ticks <= 0) ticks = 1; /* just in case */
KillTimer(hwnd, TIMING_TIMER_ID);
SetTimer(hwnd, TIMING_TIMER_ID, ticks, NULL);
timing_next_time = next;
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
static int ignore_clip = FALSE;
static int need_backend_resize = FALSE;
static int fullscr_on_max = FALSE;
static UINT last_mousemove = 0;
switch (message) {
case WM_TIMER:
if ((UINT_PTR)wParam == TIMING_TIMER_ID) {
long next;
KillTimer(hwnd, TIMING_TIMER_ID);
if (run_timers(timing_next_time, &next)) {
timer_change_notify(next);
} else {
}
}
return 0;
case WM_CREATE:
break;
case WM_CLOSE:
{
char *str;
show_mouseptr(1);
str = dupprintf("%s Exit Confirmation", appname);
if (!cfg.warn_on_close || session_closed ||
MessageBox(hwnd,
"Are you sure you want to close this session?",
str, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1)
== IDOK)
DestroyWindow(hwnd);
sfree(str);
}
return 0;
case WM_DESTROY:
show_mouseptr(1);
PostQuitMessage(0);
return 0;
case WM_INITMENUPOPUP:
if ((HMENU)wParam == savedsess_menu) {
/* About to pop up Saved Sessions sub-menu.
* Refresh the session list. */
get_sesslist(&sesslist, FALSE); /* free */
get_sesslist(&sesslist, TRUE);
update_savedsess_menu();
return 0;
}
break;
case WM_COMMAND:
case WM_SYSCOMMAND:
switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
case IDM_SHOWLOG:
showeventlog(hwnd);
break;
case IDM_NEWSESS:
case IDM_DUPSESS:
case IDM_SAVEDSESS:
{
char b[2048];
char c[30], *cl;
int freecl = FALSE;
BOOL inherit_handles;
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE filemap = NULL;
if (wParam == IDM_DUPSESS) {
/*
* Allocate a file-mapping memory chunk for the
* config structure.
*/
SECURITY_ATTRIBUTES sa;
Config *p;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
filemap = CreateFileMapping(INVALID_HANDLE_VALUE,
&sa,
PAGE_READWRITE,
0, sizeof(Config), NULL);
if (filemap && filemap != INVALID_HANDLE_VALUE) {
p = (Config *) MapViewOfFile(filemap,
FILE_MAP_WRITE,
0, 0, sizeof(Config));
if (p) {
*p = cfg; /* structure copy */
UnmapViewOfFile(p);
}
}
inherit_handles = TRUE;
sprintf(c, "putty &%p", filemap);
cl = c;
} else if (wParam == IDM_SAVEDSESS) {
unsigned int sessno = ((lParam - IDM_SAVED_MIN)
/ MENU_SAVED_STEP) + 1;
if (sessno < (unsigned)sesslist.nsessions) {
char *session = sesslist.sessions[sessno];
/* XXX spaces? quotes? "-load"? */
cl = dupprintf("putty @%s", session);
inherit_handles = FALSE;
freecl = TRUE;
} else
break;
} else /* IDM_NEWSESS */ {
cl = NULL;
inherit_handles = FALSE;
}
GetModuleFileName(NULL, b, sizeof(b) - 1);
si.cb = sizeof(si);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
CreateProcess(b, cl, NULL, NULL, inherit_handles,
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
if (filemap)
CloseHandle(filemap);
if (freecl)
sfree(cl);
}
break;
case IDM_RESTART:
if (!back) {
logevent(NULL, "----- Session restarted -----");
term_pwron(term, FALSE);
start_backend();
}
break;
case IDM_RECONF:
{
Config prev_cfg;
int init_lvl = 1;
int reconfig_result;
if (reconfiguring)
break;
else
reconfiguring = TRUE;
GetWindowText(hwnd, cfg.wintitle, sizeof(cfg.wintitle));
prev_cfg = cfg;
reconfig_result =
do_reconfig(hwnd, back ? back->cfg_info(backhandle) : 0);
reconfiguring = FALSE;
if (!reconfig_result)
break;
{
/* Disable full-screen if resizing forbidden */
HMENU m = GetSystemMenu (hwnd, FALSE);
EnableMenuItem(m, IDM_FULLSCREEN, MF_BYCOMMAND |
(cfg.resize_action == RESIZE_DISABLED)
? MF_GRAYED : MF_ENABLED);
/* Gracefully unzoom if necessary */
if (IsZoomed(hwnd) &&
(cfg.resize_action == RESIZE_DISABLED)) {
ShowWindow(hwnd, SW_RESTORE);
}
}
/* Pass new config data to the logging module */
log_reconfig(logctx, &cfg);
sfree(logpal);
/*
* Flush the line discipline's edit buffer in the
* case where local editing has just been disabled.
*/
if (ldisc)
ldisc_send(ldisc, NULL, 0, 0);
if (pal)
DeleteObject(pal);
logpal = NULL;
pal = NULL;
cfgtopalette();
init_palette();
/* Pass new config data to the terminal */
term_reconfig(term, &cfg);
/* Pass new config data to the back end */
if (back)
back->reconfig(backhandle, &cfg);
/* Screen size changed ? */
if (cfg.height != prev_cfg.height ||
cfg.width != prev_cfg.width ||
cfg.savelines != prev_cfg.savelines ||
cfg.resize_action == RESIZE_FONT ||
(cfg.resize_action == RESIZE_EITHER && IsZoomed(hwnd)) ||
cfg.resize_action == RESIZE_DISABLED)
term_size(term, cfg.height, cfg.width, cfg.savelines);
/* Enable or disable the scroll bar, etc */
{
LONG nflg, flag = GetWindowLongPtr(hwnd, GWL_STYLE);
LONG nexflag, exflag =
GetWindowLongPtr(hwnd, GWL_EXSTYLE);
nexflag = exflag;
if (cfg.alwaysontop != prev_cfg.alwaysontop) {
if (cfg.alwaysontop) {
nexflag |= WS_EX_TOPMOST;
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
} else {
nexflag &= ~(WS_EX_TOPMOST);
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
}
}
if (cfg.sunken_edge)
nexflag |= WS_EX_CLIENTEDGE;
else
nexflag &= ~(WS_EX_CLIENTEDGE);
nflg = flag;
if (is_full_screen() ?
cfg.scrollbar_in_fullscreen : cfg.scrollbar)
nflg |= WS_VSCROLL;
else
nflg &= ~WS_VSCROLL;
if (cfg.resize_action == RESIZE_DISABLED ||
is_full_screen())
nflg &= ~WS_THICKFRAME;
else
nflg |= WS_THICKFRAME;
if (cfg.resize_action == RESIZE_DISABLED)
nflg &= ~WS_MAXIMIZEBOX;
else
nflg |= WS_MAXIMIZEBOX;
if (nflg != flag || nexflag != exflag) {
if (nflg != flag)
SetWindowLongPtr(hwnd, GWL_STYLE, nflg);
if (nexflag != exflag)
SetWindowLongPtr(hwnd, GWL_EXSTYLE, nexflag);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOCOPYBITS |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_FRAMECHANGED);
init_lvl = 2;
}
}
/* Oops */
if (cfg.resize_action == RESIZE_DISABLED && IsZoomed(hwnd)) {
force_normal(hwnd);
init_lvl = 2;
}
set_title(NULL, cfg.wintitle);
if (IsIconic(hwnd)) {
SetWindowText(hwnd,
cfg.win_name_always ? window_name :
icon_name);
}
if (strcmp(cfg.font.name, prev_cfg.font.name) != 0 ||
strcmp(cfg.line_codepage, prev_cfg.line_codepage) != 0 ||
cfg.font.isbold != prev_cfg.font.isbold ||
cfg.font.height != prev_cfg.font.height ||
cfg.font.charset != prev_cfg.font.charset ||
cfg.font_quality != prev_cfg.font_quality ||
cfg.vtmode != prev_cfg.vtmode ||
cfg.bold_colour != prev_cfg.bold_colour ||
cfg.resize_action == RESIZE_DISABLED ||
cfg.resize_action == RESIZE_EITHER ||
(cfg.resize_action != prev_cfg.resize_action))
init_lvl = 2;
InvalidateRect(hwnd, NULL, TRUE);
reset_window(init_lvl);
net_pending_errors();
}
break;
case IDM_COPYALL:
term_copyall(term);
break;
case IDM_PASTE:
term_do_paste(term);
break;
case IDM_CLRSB:
term_clrsb(term);
break;
case IDM_RESET:
term_pwron(term, TRUE);
if (ldisc)
ldisc_send(ldisc, NULL, 0, 0);
break;
case IDM_ABOUT:
showabout(hwnd);
break;
case IDM_HELP:
launch_help(hwnd, NULL);
break;
case SC_MOUSEMENU:
/*
* We get this if the System menu has been activated
* using the mouse.
*/
show_mouseptr(1);
break;
case SC_KEYMENU:
/*
* We get this if the System menu has been activated
* using the keyboard. This might happen from within
* TranslateKey, in which case it really wants to be
* followed by a `space' character to actually _bring
* the menu up_ rather than just sitting there in
* `ready to appear' state.
*/
show_mouseptr(1); /* make sure pointer is visible */
if( lParam == 0 )
PostMessage(hwnd, WM_CHAR, ' ', 0);
break;
case IDM_FULLSCREEN:
flip_full_screen();
break;
default:
if (wParam >= IDM_SAVED_MIN && wParam < IDM_SAVED_MAX) {
SendMessage(hwnd, WM_SYSCOMMAND, IDM_SAVEDSESS, wParam);
}
if (wParam >= IDM_SPECIAL_MIN && wParam <= IDM_SPECIAL_MAX) {
int i = (wParam - IDM_SPECIAL_MIN) / 0x10;
/*
* Ensure we haven't been sent a bogus SYSCOMMAND
* which would cause us to reference invalid memory
* and crash. Perhaps I'm just too paranoid here.
*/
if (i >= n_specials)
break;
if (back)
back->special(backhandle, specials[i].code);
net_pending_errors();
}
}
break;
#define X_POS(l) ((int)(short)LOWORD(l))
#define Y_POS(l) ((int)(short)HIWORD(l))
#define TO_CHR_X(x) ((((x)<0 ? (x)-font_width+1 : (x))-offset_width) / font_width)
#define TO_CHR_Y(y) ((((y)<0 ? (y)-font_height+1: (y))-offset_height) / font_height)
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
if (message == WM_RBUTTONDOWN &&
((wParam & MK_CONTROL) || (cfg.mouse_is_xterm == 2))) {
POINT cursorpos;
show_mouseptr(1); /* make sure pointer is visible */
GetCursorPos(&cursorpos);
TrackPopupMenu(popup_menus[CTXMENU].menu,
TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
cursorpos.x, cursorpos.y,
0, hwnd, NULL);
break;
}
{
int button, press;
switch (message) {
case WM_LBUTTONDOWN:
button = MBT_LEFT;
press = 1;
break;
case WM_MBUTTONDOWN:
button = MBT_MIDDLE;
press = 1;
break;
case WM_RBUTTONDOWN:
button = MBT_RIGHT;
press = 1;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -