static int caret_x = -1, caret_y = -1;
+static int kbd_codepage;
+
static void *ldisc;
static Backend *back;
static void *backhandle;
+static int session_closed;
+
+extern struct sesslist sesslist; /* imported from windlg.c */
+
#define FONT_NORMAL 0
#define FONT_BOLD 1
#define FONT_UNDERLINE 2
hwnd = NULL;
- term = term_init();
+ term = term_init(NULL);
+ logctx = log_init(NULL);
+ term_provide_logctx(term, logctx);
cfgtopalette();
error = back->init((void *)term, &backhandle,
cfg.host, cfg.port, &realhost, cfg.tcp_nodelay);
+ back->provide_logctx(backhandle, logctx);
if (error) {
sprintf(msg, "Unable to open connection to\n"
"%.800s\n" "%s", cfg.host, error);
title = msg;
}
sfree(realhost);
- set_title(title);
- set_icon(title);
+ set_title(NULL, title);
+ set_icon(NULL, title);
}
/*
AppendMenu(m, MF_ENABLED, IDM_NEWSESS, "Ne&w Session...");
AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session");
s = CreateMenu();
- get_sesslist(TRUE);
- for (i = 1; i < ((nsessions < 256) ? nsessions : 256); i++)
+ get_sesslist(&sesslist, TRUE);
+ for (i = 1;
+ i < ((sesslist.nsessions < 256) ? sesslist.nsessions : 256);
+ i++)
AppendMenu(s, MF_ENABLED, IDM_SAVED_MIN + (16 * i),
- sessions[i]);
+ sesslist.sessions[i]);
AppendMenu(m, MF_POPUP | MF_ENABLED, (UINT) s, "Sa&ved Sessions");
AppendMenu(m, MF_ENABLED, IDM_RECONF, "Chan&ge Settings...");
AppendMenu(m, MF_SEPARATOR, 0, 0);
/*
* Open the initial log file if there is one.
*/
- logfopen();
+ logfopen(logctx);
/*
* Finally show the window!
/*
* set or clear the "raw mouse message" mode
*/
-void set_raw_mouse_mode(int activate)
+void set_raw_mouse_mode(void *frontend, int activate)
{
activate = activate && !cfg.no_mouse_rep;
send_raw_mouse = activate;
/*
* Print a message box and close the connection.
*/
-void connection_fatal(char *fmt, ...)
+void connection_fatal(void *frontend, char *fmt, ...)
{
va_list ap;
char stuff[200];
}
fontflag[0] = fontflag[1] = fontflag[2] = 1;
- init_ucs_tables();
+ init_ucs();
}
static void another_font(int fontno)
}
}
-void request_resize(int w, int h)
+void request_resize(void *frontend, int w, int h)
{
int width, height;
* Translate a raw mouse button designation (LEFT, MIDDLE, RIGHT)
* into a cooked one (SELECT, EXTEND, PASTE).
*/
-Mouse_Button translate_button(Mouse_Button button)
+Mouse_Button translate_button(void *frontend, Mouse_Button button)
{
if (button == MBT_LEFT)
return MBT_SELECT;
sprintf(c, "putty &%p", filemap);
cl = c;
} else if (wParam == IDM_SAVEDSESS) {
- if ((lParam - IDM_SAVED_MIN) / 16 < nsessions) {
+ if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
char *session =
- sessions[(lParam - IDM_SAVED_MIN) / 16];
+ sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
cl = smalloc(16 + strlen(session));
/* 8, but play safe */
if (!cl)
if (strcmp(prev_cfg.logfilename, cfg.logfilename) ||
prev_cfg.logtype != cfg.logtype) {
- logfclose(); /* reset logging */
- logfopen();
+ logfclose(logctx); /* reset logging */
+ logfopen(logctx);
}
sfree(logpal);
init_lvl = 2;
}
- set_title(cfg.wintitle);
+ set_title(NULL, cfg.wintitle);
if (IsIconic(hwnd)) {
SetWindowText(hwnd,
cfg.win_name_always ? window_name :
(p.rcPaint.left-offset_width)/font_width,
(p.rcPaint.top-offset_height)/font_height,
(p.rcPaint.right-offset_width-1)/font_width,
- (p.rcPaint.bottom-offset_height-1)/font_height);
+ (p.rcPaint.bottom-offset_height-1)/font_height,
+ is_alt_pressed());
if (p.fErase ||
p.rcPaint.left < offset_width ||
* 1) Keep the sizetip uptodate
* 2) Make sure the window size is _stepped_ in units of the font size.
*/
- if (cfg.resize_action != RESIZE_FONT && !alt_pressed) {
+ if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) {
int width, height, w, h, ew, eh;
LPRECT r = (LPRECT) lParam;
* down the connection during an NT opaque drag.)
*/
if (resizing) {
- if (cfg.resize_action != RESIZE_FONT && !alt_pressed) {
+ if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) {
need_backend_resize = TRUE;
w = (width-cfg.window_border*2) / font_width;
if (w < 1) w = 1;
break;
case WM_PALETTECHANGED:
if ((HWND) wParam != hwnd && pal != NULL) {
- HDC hdc = get_ctx();
+ HDC hdc = get_ctx(NULL);
if (hdc) {
if (RealizePalette(hdc) > 0)
UpdateColors(hdc);
break;
case WM_QUERYNEWPALETTE:
if (pal != NULL) {
- HDC hdc = get_ctx();
+ HDC hdc = get_ctx(NULL);
if (hdc) {
if (RealizePalette(hdc) > 0)
UpdateColors(hdc);
}
default:
if (message == wm_mousewheel || message == WM_MOUSEWHEEL) {
- int shift_pressed=0, control_pressed=0, alt_pressed=0;
+ int shift_pressed=0, control_pressed=0;
if (message == WM_MOUSEWHEEL) {
wheel_accumulator += (short)HIWORD(wParam);
* helper software tracks the system caret, so we should arrange to
* have one.)
*/
-void sys_cursor(int x, int y)
+void sys_cursor(void *frontend, int x, int y)
{
int cx, cy;
}
}
- alt_pressed = (left_alt && key_down);
-
scan = (HIWORD(lParam) & (KF_UP | KF_EXTENDED | 0xFF));
shift_state = ((keystate[VK_SHIFT] & 0x80) != 0)
+ ((keystate[VK_CONTROL] & 0x80) != 0) * 2;
return -1;
}
-void request_paste(void)
+void request_paste(void *frontend)
{
/*
* In Windows, pasting is synchronous: we can read the
term_do_paste(term);
}
-void set_title(char *title)
+void set_title(void *frontend, char *title)
{
sfree(window_name);
window_name = smalloc(1 + strlen(title));
SetWindowText(hwnd, title);
}
-void set_icon(char *title)
+void set_icon(void *frontend, char *title)
{
sfree(icon_name);
icon_name = smalloc(1 + strlen(title));
SetWindowText(hwnd, title);
}
-void set_sbar(int total, int start, int page)
+void set_sbar(void *frontend, int total, int start, int page)
{
SCROLLINFO si;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
}
-Context get_ctx(void)
+Context get_ctx(void *frontend)
{
HDC hdc;
if (hwnd) {
colours[n] = RGB(r, g, b);
}
-void palette_set(int n, int r, int g, int b)
+void palette_set(void *frontend, int n, int r, int g, int b)
{
static const int first[21] = {
0, 2, 4, 6, 8, 10, 12, 14,
if (first[n] >= 18)
real_palette_set(first[n] + 1, r, g, b);
if (pal) {
- HDC hdc = get_ctx();
+ HDC hdc = get_ctx(frontend);
UnrealizeObject(pal);
RealizePalette(hdc);
free_ctx(hdc);
}
}
-void palette_reset(void)
+void palette_reset(void *frontend)
{
int i;
if (pal) {
HDC hdc;
SetPaletteEntries(pal, 0, NCOLOURS, logpal->palPalEntry);
- hdc = get_ctx();
+ hdc = get_ctx(frontend);
RealizePalette(hdc);
free_ctx(hdc);
}
}
-void write_aclip(char *data, int len, int must_deselect)
+void write_aclip(void *frontend, char *data, int len, int must_deselect)
{
HGLOBAL clipdata;
void *lock;
/*
* Note: unlike write_aclip() this will not append a nul.
*/
-void write_clip(wchar_t * data, int len, int must_deselect)
+void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
{
HGLOBAL clipdata, clipdata2, clipdata3;
int len2;
SendMessage(hwnd, WM_IGNORE_CLIP, FALSE, 0);
}
-void get_clip(wchar_t ** p, int *len)
+void get_clip(void *frontend, wchar_t ** p, int *len)
{
static HGLOBAL clipdata = NULL;
static wchar_t *converted = 0;
* Move `lines' lines from position `from' to position `to' in the
* window.
*/
-void optimised_move(int to, int from, int lines)
+void optimised_move(void *frontend, int to, int from, int lines)
{
RECT r;
int min, max;
/*
* Beep.
*/
-void beep(int mode)
+void beep(void *frontend, int mode)
{
if (mode == BELL_DEFAULT) {
/*
* Minimise or restore the window in response to a server-side
* request.
*/
-void set_iconic(int iconic)
+void set_iconic(void *frontend, int iconic)
{
if (IsIconic(hwnd)) {
if (!iconic)
/*
* Move the window in response to a server-side request.
*/
-void move_window(int x, int y)
+void move_window(void *frontend, int x, int y)
{
if (cfg.resize_action == RESIZE_DISABLED ||
cfg.resize_action == RESIZE_FONT ||
* Move the window to the top or bottom of the z-order in response
* to a server-side request.
*/
-void set_zorder(int top)
+void set_zorder(void *frontend, int top)
{
if (cfg.alwaysontop)
return; /* ignore */
/*
* Refresh the window in response to a server-side request.
*/
-void refresh_window(void)
+void refresh_window(void *frontend)
{
InvalidateRect(hwnd, NULL, TRUE);
}
* Maximise or restore the window in response to a server-side
* request.
*/
-void set_zoomed(int zoomed)
+void set_zoomed(void *frontend, int zoomed)
{
if (IsZoomed(hwnd)) {
if (!zoomed)
/*
* Report whether the window is iconic, for terminal reports.
*/
-int is_iconic(void)
+int is_iconic(void *frontend)
{
return IsIconic(hwnd);
}
/*
* Report the window's position, for terminal reports.
*/
-void get_window_pos(int *x, int *y)
+void get_window_pos(void *frontend, int *x, int *y)
{
RECT r;
GetWindowRect(hwnd, &r);
/*
* Report the window's pixel size, for terminal reports.
*/
-void get_window_pixels(int *x, int *y)
+void get_window_pixels(void *frontend, int *x, int *y)
{
RECT r;
GetWindowRect(hwnd, &r);
/*
* Return the window or icon title.
*/
-char *get_window_title(int icon)
+char *get_window_title(void *frontend, int icon)
{
return icon ? icon_name : window_name;
}