Patch from Alejandro Sedeno, somewhat modified by me, which
[u/mdw/putty] / windows / winstuff.h
CommitLineData
8c3cd914 1/*
2 * winstuff.h: Windows-specific inter-module stuff.
3 */
4
f7f27309 5#ifndef PUTTY_WINSTUFF_H
6#define PUTTY_WINSTUFF_H
7
7440fd44 8#ifndef AUTO_WINSOCK
9#include <winsock2.h>
10#endif
11#include <windows.h>
9a30e26b 12#include <stdio.h> /* for FILENAME_MAX */
13
fe8abbf4 14#include "tree234.h"
15
16#include "winhelp.h"
17
9a30e26b 18struct Filename {
19 char path[FILENAME_MAX];
20};
c6940f12 21#define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) )
9a30e26b 22
23struct FontSpec {
24 char name[64];
25 int isbold;
26 int height;
27 int charset;
28};
29
17c7fed1 30#ifndef CLEARTYPE_QUALITY
31#define CLEARTYPE_QUALITY 5
32#endif
33#define FONT_QUALITY(fq) ( \
34 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
35 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
36 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
37 CLEARTYPE_QUALITY)
38
61ef0c16 39#define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
40 * wchar_t strings with environment */
41
158cb9b1 42/*
43 * Where we can, we use GetWindowLongPtr and friends because they're
44 * more useful on 64-bit platforms, but they're a relatively recent
45 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
46 * (NB that on some systems, some of these things are available but
47 * not others...)
48 */
17c7fed1 49
158cb9b1 50#ifndef GCLP_HCURSOR
51/* GetClassLongPtr and friends */
52#undef GetClassLongPtr
53#define GetClassLongPtr GetClassLong
54#undef SetClassLongPtr
55#define SetClassLongPtr SetClassLong
56#define GCLP_HCURSOR GCL_HCURSOR
57/* GetWindowLongPtr and friends */
58#undef GetWindowLongPtr
17c7fed1 59#define GetWindowLongPtr GetWindowLong
158cb9b1 60#undef SetWindowLongPtr
17c7fed1 61#define SetWindowLongPtr SetWindowLong
158cb9b1 62#undef GWLP_USERDATA
17c7fed1 63#define GWLP_USERDATA GWL_USERDATA
158cb9b1 64#undef DWLP_MSGRESULT
17c7fed1 65#define DWLP_MSGRESULT DWL_MSGRESULT
158cb9b1 66/* Since we've clobbered the above functions, we should clobber the
67 * associated type regardless of whether it's defined. */
68#undef LONG_PTR
69#define LONG_PTR LONG
17c7fed1 70#endif
71
2979718a 72#define BOXFLAGS DLGWINDOWEXTRA
1e5eefb6 73#define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
8ee3ff16 74#define DF_END 0x0001
75
8c3cd914 76/*
d0f67860 77 * Dynamically linked functions. These come in two flavours:
78 *
79 * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
80 * so will always dynamically link against exactly what is specified
81 * in "name". If you're not sure, use this one.
82 *
83 * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
84 * preprocessor definitions like "#define foo bar"; this is principally
85 * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
86 * If your function has an argument of type "LPTSTR" or similar, this
87 * is the variant to use.
88 * (However, it can't always be used, as it trips over more complicated
89 * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
90 *
91 * (DECL_WINDOWS_FUNCTION works with both these variants.)
65d1432e 92 */
93#define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
94 typedef rettype (WINAPI *t_##name) params; \
95 linkage t_##name p_##name
96#define STR1(x) #x
97#define STR(x) STR1(x)
d0f67860 98#define GET_WINDOWS_FUNCTION_PP(module, name) \
65d1432e 99 p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL
d0f67860 100#define GET_WINDOWS_FUNCTION(module, name) \
101 p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL
65d1432e 102
103/*
8c3cd914 104 * Global variables. Most modules declare these `extern', but
105 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
106 * module, and so will get them properly defined.
2979718a 107*/
f7f27309 108#ifndef GLOBAL
8c3cd914 109#ifdef PUTTY_DO_GLOBALS
110#define GLOBAL
111#else
112#define GLOBAL extern
113#endif
f7f27309 114#endif
115
a8327734 116#ifndef DONE_TYPEDEFS
117#define DONE_TYPEDEFS
118typedef struct config_tag Config;
119typedef struct backend_tag Backend;
120typedef struct terminal_tag Terminal;
121#endif
122
f7f27309 123#define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
124#define PUTTY_REG_PARENT "Software\\SimonTatham"
125#define PUTTY_REG_PARENT_CHILD "PuTTY"
126#define PUTTY_REG_GPARENT "Software"
127#define PUTTY_REG_GPARENT_CHILD "SimonTatham"
128
a9dc49af 129#define PUTTY_HELP_FILE "putty.hlp"
cb2708d3 130#define PUTTY_CHM_FILE "putty.chm"
a9dc49af 131#define PUTTY_HELP_CONTENTS "putty.cnt"
132
f7f27309 133#define GETTICKCOUNT GetTickCount
134#define CURSORBLINK GetCaretBlinkTime()
135#define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
136
137#define DEFAULT_CODEPAGE CP_ACP
138
139typedef HDC Context;
8c3cd914 140
b3d375b2 141typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
142#define PUTTY_UINT32_DEFINED
143
86557057 144#ifndef NO_GSSAPI
145/*
146 * GSS-API stuff
147 */
b3d375b2 148#define GSS_CC CALLBACK
149/*
86557057 150typedef struct Ssh_gss_buf {
b3d375b2 151 size_t length;
86557057 152 char *value;
153} Ssh_gss_buf;
154
155#define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
2c2bce14 156typedef void *Ssh_gss_name;
b3d375b2 157*/
86557057 158#endif
159
f7f27309 160/*
5321c0c6 161 * Window handles for the windows that can be running during a
f7f27309 162 * PuTTY session.
163 */
5321c0c6 164GLOBAL HWND hwnd; /* the main terminal window */
f7f27309 165GLOBAL HWND logbox;
166
167/*
168 * The all-important instance handle.
169 */
8c3cd914 170GLOBAL HINSTANCE hinst;
171
172/*
cb2708d3 173 * Help file stuff in winhelp.c.
6b78788a 174 */
cb2708d3 175void init_help(void);
176void shutdown_help(void);
177int has_help(void);
178void launch_help(HWND hwnd, const char *topic);
179void quit_help(HWND hwnd);
6b78788a 180
181/*
a8327734 182 * The terminal and logging context are notionally local to the
183 * Windows front end, but they must be shared between window.c and
0b4f0bc0 184 * windlg.c. Likewise the saved-sessions list.
a8327734 185 */
186GLOBAL Terminal *term;
187GLOBAL void *logctx;
188
604fab0c 189#define WM_NETEVENT (WM_APP + 5)
f7f27309 190
191/*
e6346999 192 * On Windows, we send MA_2CLK as the only event marking the second
193 * press of a mouse button. Compare unix.h.
194 */
195#define MULTICLICK_ONLY_EVENT 1
196
197/*
198 * On Windows, data written to the clipboard must be NUL-terminated.
199 */
200#define SELECTION_NUL_TERMINATED 1
201
202/*
0f351587 203 * On Windows, copying to the clipboard terminates lines with CRLF.
204 */
205#define SEL_NL { 13, 10 }
206
207/*
2f92b717 208 * sk_getxdmdata() does not exist under Windows (not that I
209 * couldn't write it if I wanted to, but I haven't bothered), so
0a4022a1 210 * it's a macro which always returns NULL. With any luck this will
2f92b717 211 * cause the compiler to notice it can optimise away the
212 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
213 */
0a4022a1 214#define sk_getxdmdata(socket, lenp) (NULL)
2f92b717 215
216/*
fe8abbf4 217 * File-selector filter strings used in the config box. On Windows,
218 * these strings are of exactly the type needed to go in
219 * `lpstrFilter' in an OPENFILENAME structure.
220 */
221#define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
222 "All Files (*.*)\0*\0\0\0")
223#define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
224 "All Files (*.*)\0*\0\0\0")
225
226/*
2ac3322e 227 * On some versions of Windows, it has been known for WM_TIMER to
228 * occasionally get its callback time simply wrong, and call us
229 * back several minutes early. Defining these symbols enables
230 * compensation code in timing.c.
231 */
232#define TIMING_SYNC
233#define TIMING_SYNC_TICKCOUNT
234
235/*
7440fd44 236 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
237 * what it can get, which means any WinSock routines used outside
238 * that module must be exported from it as function pointers. So
239 * here they are.
240 */
65d1432e 241DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
242 (SOCKET, HWND, u_int, long));
243DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
244 (SOCKET, WSAEVENT, long));
245DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
246 (int, fd_set FAR *, fd_set FAR *,
247 fd_set FAR *, const struct timeval FAR *));
248DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
249DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
250 (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
7440fd44 251
39934deb 252extern int socket_writable(SOCKET skt);
253
9f7ebadc 254extern void socket_reselect_all(void);
255
7440fd44 256/*
8c3cd914 257 * Exports from winctrls.c.
258 */
259
260struct ctlpos {
261 HWND hwnd;
262 WPARAM font;
263 int dlu4inpix;
264 int ypos, width;
265 int xoff;
3ac9cd9f 266 int boxystart, boxid;
8c3cd914 267 char *boxtext;
268};
269
ca20bfcf 270/*
c0a81592 271 * Exports from winutils.c.
272 */
9754e5ca 273typedef struct filereq_tag filereq; /* cwd for file requester */
274BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
275filereq *filereq_new(void);
276void filereq_free(filereq *state);
690695e0 277int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
d3a1a808 278void split_into_argv(char *, int *, char ***, char ***);
c0a81592 279
280/*
ca20bfcf 281 * Private structure for prefslist state. Only in the header file
282 * so that we can delegate allocation to callers.
283 */
284struct prefslist {
285 int listid, upbid, dnbid;
286 int srcitem;
287 int dummyitem;
288 int dragging;
289};
290
f7f27309 291/*
fe8abbf4 292 * This structure is passed to event handler functions as the `dlg'
293 * parameter, and hence is passed back to winctrls access functions.
294 */
295struct dlgparam {
296 HWND hwnd; /* the hwnd of the dialog box */
297 struct winctrls *controltrees[8]; /* can have several of these */
298 int nctrltrees;
f6f450e2 299 char *wintitle; /* title of actual window */
fe8abbf4 300 char *errtitle; /* title of error sub-messageboxes */
301 void *data; /* data to pass in refresh events */
302 union control *focused, *lastfocused; /* which ctrl has focus now/before */
4e6d4091 303 char shortcuts[128]; /* track which shortcuts in use */
fe8abbf4 304 int coloursel_wanted; /* has an event handler asked for
305 * a colour selector? */
fe8abbf4 306 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
4e6d4091 307 tree234 *privdata; /* stores per-control private data */
fe8abbf4 308 int ended, endresult; /* has the dialog been ended? */
309};
310
311/*
f7f27309 312 * Exports from winctrls.c.
313 */
8c3cd914 314void ctlposinit(struct ctlpos *cp, HWND hwnd,
32874aea 315 int leftborder, int rightborder, int topborder);
ca20bfcf 316HWND doctl(struct ctlpos *cp, RECT r,
32874aea 317 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
8c3cd914 318void bartitle(struct ctlpos *cp, char *name, int id);
3ac9cd9f 319void beginbox(struct ctlpos *cp, char *name, int idbox);
8c3cd914 320void endbox(struct ctlpos *cp);
e73667f3 321void editboxfw(struct ctlpos *cp, int password, char *text,
322 int staticid, int editid);
32874aea 323void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
d74d141c 324void bareradioline(struct ctlpos *cp, int nacross, ...);
8c3cd914 325void radiobig(struct ctlpos *cp, char *text, int id, ...);
326void checkbox(struct ctlpos *cp, char *text, int id);
66ee282a 327void statictext(struct ctlpos *cp, char *text, int lines, int id);
8c3cd914 328void staticbtn(struct ctlpos *cp, char *stext, int sid,
32874aea 329 char *btext, int bid);
af282e3b 330void static2btn(struct ctlpos *cp, char *stext, int sid,
331 char *btext1, int bid1, char *btext2, int bid2);
8c3cd914 332void staticedit(struct ctlpos *cp, char *stext,
32874aea 333 int sid, int eid, int percentedit);
2c9c6388 334void staticddl(struct ctlpos *cp, char *stext,
335 int sid, int lid, int percentlist);
b8ae1f0f 336void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
6e522441 337void staticpassedit(struct ctlpos *cp, char *stext,
32874aea 338 int sid, int eid, int percentedit);
6e522441 339void bigeditctrl(struct ctlpos *cp, char *stext,
32874aea 340 int sid, int eid, int lines);
341void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
8c3cd914 342void editbutton(struct ctlpos *cp, char *stext, int sid,
32874aea 343 int eid, char *btext, int bid);
8c3cd914 344void sesssaver(struct ctlpos *cp, char *text,
32874aea 345 int staticid, int editid, int listid, ...);
8c3cd914 346void envsetter(struct ctlpos *cp, char *stext, int sid,
32874aea 347 char *e1stext, int e1sid, int e1id,
348 char *e2stext, int e2sid, int e2id,
349 int listid, char *b1text, int b1id, char *b2text, int b2id);
8c3cd914 350void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
32874aea 351 char *btext, int bid, int eid, char *s2text, int s2id);
8c3cd914 352void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
32874aea 353 char *btext, int bid, ...);
fe8abbf4 354void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
355 char *stext, int sid, int listid, int upbid, int dnbid);
ca20bfcf 356int handle_prefslist(struct prefslist *hdl,
357 int *array, int maxmemb,
358 int is_dlmsg, HWND hwnd,
359 WPARAM wParam, LPARAM lParam);
6e522441 360void progressbar(struct ctlpos *cp, int id);
d74d141c 361void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
362 char *e1stext, int e1sid, int e1id,
363 char *e2stext, int e2sid, int e2id,
a4b92c62 364 char *btext, int bid,
365 char *r1text, int r1id, char *r2text, int r2id);
f7f27309 366
fe8abbf4 367#define MAX_SHORTCUTS_PER_CTRL 16
368
369/*
370 * This structure is what's stored for each `union control' in the
371 * portable-dialog interface.
372 */
373struct winctrl {
374 union control *ctrl;
375 /*
376 * The control may have several components at the Windows
377 * level, with different dialog IDs. To avoid needing N
378 * separate platformsidectrl structures (which could be stored
379 * separately in a tree234 so that lookup by ID worked), we
380 * impose the constraint that those IDs must be in a contiguous
381 * block.
382 */
383 int base_id;
384 int num_ids;
385 /*
386 * Remember what keyboard shortcuts were used by this control,
387 * so that when we remove it again we can take them out of the
388 * list in the dlgparam.
389 */
390 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
391 /*
392 * Some controls need a piece of allocated memory in which to
393 * store temporary data about the control.
394 */
395 void *data;
396};
397/*
398 * And this structure holds a set of the above, in two separate
399 * tree234s so that it can find an item by `union control' or by
400 * dialog ID.
401 */
402struct winctrls {
403 tree234 *byctrl, *byid;
404};
d1582b2e 405struct controlset;
406struct controlbox;
407
fe8abbf4 408void winctrl_init(struct winctrls *);
409void winctrl_cleanup(struct winctrls *);
410void winctrl_add(struct winctrls *, struct winctrl *);
411void winctrl_remove(struct winctrls *, struct winctrl *);
412struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
413struct winctrl *winctrl_findbyid(struct winctrls *, int);
414struct winctrl *winctrl_findbyindex(struct winctrls *, int);
415void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
416 struct ctlpos *cp, struct controlset *s, int *id);
417int winctrl_handle_command(struct dlgparam *dp, UINT msg,
418 WPARAM wParam, LPARAM lParam);
d1582b2e 419void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
420int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
421
4e6d4091 422void dp_init(struct dlgparam *dp);
423void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
424void dp_cleanup(struct dlgparam *dp);
425
d1582b2e 426/*
427 * Exports from wincfg.c.
428 */
429void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
8a7f1392 430 int midsession, int protocol);
fe8abbf4 431
f7f27309 432/*
433 * Exports from windlg.c.
434 */
435void defuse_showwindow(void);
436int do_config(void);
f89c3294 437int do_reconfig(HWND, int);
f7f27309 438void showeventlog(HWND);
439void showabout(HWND);
f7f27309 440void force_normal(HWND hwnd);
d1582b2e 441void modal_about_box(HWND hwnd);
442void show_help(HWND hwnd);
f7f27309 443
f7f27309 444/*
8ee3ff16 445 * Exports from winmisc.c.
446 */
4c48c989 447extern OSVERSIONINFO osVersion;
448BOOL init_winver(void);
449
8ee3ff16 450/*
f7f27309 451 * Exports from sizetip.c.
452 */
453void UpdateSizeTip(HWND src, int cx, int cy);
454void EnableSizeTip(int bEnable);
455
facd762c 456/*
457 * Exports from unicode.c.
458 */
07b2a9cd 459struct unicode_data;
21d2b241 460void init_ucs(Config *, struct unicode_data *);
facd762c 461
c44bf5bd 462/*
34292b1d 463 * Exports from winhandl.c.
464 */
bdebd7e9 465#define HANDLE_FLAG_OVERLAPPED 1
466#define HANDLE_FLAG_IGNOREEOF 2
799e067e 467#define HANDLE_FLAG_UNITBUFFER 4
34292b1d 468struct handle;
469typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
470typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
0e03ceff 471struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
bdebd7e9 472 void *privdata, int flags);
0e03ceff 473struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
bdebd7e9 474 void *privdata, int flags);
34292b1d 475int handle_write(struct handle *h, const void *data, int len);
476HANDLE *handle_get_events(int *nevents);
477void handle_free(struct handle *h);
478void handle_got_event(HANDLE event);
479void handle_unthrottle(struct handle *h, int backlog);
480int handle_backlog(struct handle *h);
0e03ceff 481void *handle_get_privdata(struct handle *h);
34292b1d 482
483/*
c44bf5bd 484 * pageantc.c needs to schedule callbacks for asynchronous agent
485 * requests. This has to be done differently in GUI and console, so
486 * there's an exported function used for the purpose.
487 *
488 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
489 * synchronous in pscp and psftp.
490 */
491void agent_schedule_callback(void (*callback)(void *, void *, int),
492 void *callback_ctx, void *data, int len);
493#define FLAG_SYNCAGENT 0x1000
494
7374c779 495/*
496 * Exports from winser.c.
497 */
498extern Backend serial_backend;
499
f7f27309 500#endif