2 * winstuff.h: Windows-specific inter-module stuff.
5 #ifndef PUTTY_WINSTUFF_H
6 #define PUTTY_WINSTUFF_H
12 #include <stdio.h> /* for FILENAME_MAX */
21 #define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
29 struct FontSpec *fontspec_new(const char *name,
30 int bold, int height, int charset);
32 #ifndef CLEARTYPE_QUALITY
33 #define CLEARTYPE_QUALITY 5
35 #define FONT_QUALITY(fq) ( \
36 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
37 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
38 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
41 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
42 * wchar_t strings with environment */
45 * Where we can, we use GetWindowLongPtr and friends because they're
46 * more useful on 64-bit platforms, but they're a relatively recent
47 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
48 * (NB that on some systems, some of these things are available but
53 /* GetClassLongPtr and friends */
54 #undef GetClassLongPtr
55 #define GetClassLongPtr GetClassLong
56 #undef SetClassLongPtr
57 #define SetClassLongPtr SetClassLong
58 #define GCLP_HCURSOR GCL_HCURSOR
59 /* GetWindowLongPtr and friends */
60 #undef GetWindowLongPtr
61 #define GetWindowLongPtr GetWindowLong
62 #undef SetWindowLongPtr
63 #define SetWindowLongPtr SetWindowLong
65 #define GWLP_USERDATA GWL_USERDATA
67 #define DWLP_MSGRESULT DWL_MSGRESULT
68 /* Since we've clobbered the above functions, we should clobber the
69 * associated type regardless of whether it's defined. */
74 #define BOXFLAGS DLGWINDOWEXTRA
75 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
78 #ifndef NO_SECUREZEROMEMORY
79 #define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */
82 #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE /* used in sshshare.c */
85 * Dynamically linked functions. These come in two flavours:
87 * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
88 * so will always dynamically link against exactly what is specified
89 * in "name". If you're not sure, use this one.
91 * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
92 * preprocessor definitions like "#define foo bar"; this is principally
93 * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
94 * If your function has an argument of type "LPTSTR" or similar, this
95 * is the variant to use.
96 * (However, it can't always be used, as it trips over more complicated
97 * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
99 * (DECL_WINDOWS_FUNCTION works with both these variants.)
101 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
102 typedef rettype (WINAPI *t_##name) params; \
103 linkage t_##name p_##name
105 #define STR(x) STR1(x)
106 #define GET_WINDOWS_FUNCTION_PP(module, name) \
107 (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
108 #define GET_WINDOWS_FUNCTION(module, name) \
109 (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
112 * Global variables. Most modules declare these `extern', but
113 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
114 * module, and so will get them properly defined.
117 #ifdef PUTTY_DO_GLOBALS
120 #define GLOBAL extern
124 #ifndef DONE_TYPEDEFS
125 #define DONE_TYPEDEFS
126 typedef struct conf_tag Conf;
127 typedef struct backend_tag Backend;
128 typedef struct terminal_tag Terminal;
131 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
132 #define PUTTY_REG_PARENT "Software\\SimonTatham"
133 #define PUTTY_REG_PARENT_CHILD "PuTTY"
134 #define PUTTY_REG_GPARENT "Software"
135 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
137 /* Result values for the jumplist registry functions. */
138 #define JUMPLISTREG_OK 0
139 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
140 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
141 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
142 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
143 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
145 #define PUTTY_HELP_FILE "putty.hlp"
146 #define PUTTY_CHM_FILE "putty.chm"
147 #define PUTTY_HELP_CONTENTS "putty.cnt"
149 #define GETTICKCOUNT GetTickCount
150 #define CURSORBLINK GetCaretBlinkTime()
151 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
153 #define DEFAULT_CODEPAGE CP_ACP
154 #define USES_VTLINE_HACK
158 typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
159 #define PUTTY_UINT32_DEFINED
165 #define GSS_CC CALLBACK
167 typedef struct Ssh_gss_buf {
172 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
173 typedef void *Ssh_gss_name;
178 * Window handles for the windows that can be running during a
181 GLOBAL HWND hwnd; /* the main terminal window */
185 * The all-important instance handle.
187 GLOBAL HINSTANCE hinst;
190 * Help file stuff in winhelp.c.
192 void init_help(void);
193 void shutdown_help(void);
195 void launch_help(HWND hwnd, const char *topic);
196 void quit_help(HWND hwnd);
199 * The terminal and logging context are notionally local to the
200 * Windows front end, but they must be shared between window.c and
201 * windlg.c. Likewise the saved-sessions list.
203 GLOBAL Terminal *term;
206 #define WM_NETEVENT (WM_APP + 5)
209 * On Windows, we send MA_2CLK as the only event marking the second
210 * press of a mouse button. Compare unix.h.
212 #define MULTICLICK_ONLY_EVENT 1
215 * On Windows, data written to the clipboard must be NUL-terminated.
217 #define SELECTION_NUL_TERMINATED 1
220 * On Windows, copying to the clipboard terminates lines with CRLF.
222 #define SEL_NL { 13, 10 }
225 * sk_getxdmdata() does not exist under Windows (not that I
226 * couldn't write it if I wanted to, but I haven't bothered), so
227 * it's a macro which always returns NULL. With any luck this will
228 * cause the compiler to notice it can optimise away the
229 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
231 #define sk_getxdmdata(socket, lenp) (NULL)
234 * File-selector filter strings used in the config box. On Windows,
235 * these strings are of exactly the type needed to go in
236 * `lpstrFilter' in an OPENFILENAME structure.
238 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
239 "All Files (*.*)\0*\0\0\0")
240 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
241 "All Files (*.*)\0*\0\0\0")
242 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
243 "All Files (*.*)\0*\0\0\0")
246 * Exports from winnet.c.
248 extern int select_result(WPARAM, LPARAM);
251 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
252 * what it can get, which means any WinSock routines used outside
253 * that module must be exported from it as function pointers. So
256 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
257 (SOCKET, HWND, u_int, long));
258 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
259 (SOCKET, WSAEVENT, long));
260 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
261 (int, fd_set FAR *, fd_set FAR *,
262 fd_set FAR *, const struct timeval FAR *));
263 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
264 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
265 (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
267 extern int socket_writable(SOCKET skt);
269 extern void socket_reselect_all(void);
272 * Exports from winctrls.c.
281 int boxystart, boxid;
286 * Exports from winutils.c.
288 typedef struct filereq_tag filereq; /* cwd for file requester */
289 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
290 filereq *filereq_new(void);
291 void filereq_free(filereq *state);
292 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
293 char *GetDlgItemText_alloc(HWND hwnd, int id);
294 void split_into_argv(char *, int *, char ***, char ***);
297 * Private structure for prefslist state. Only in the header file
298 * so that we can delegate allocation to callers.
301 int listid, upbid, dnbid;
308 * This structure is passed to event handler functions as the `dlg'
309 * parameter, and hence is passed back to winctrls access functions.
312 HWND hwnd; /* the hwnd of the dialog box */
313 struct winctrls *controltrees[8]; /* can have several of these */
315 char *wintitle; /* title of actual window */
316 char *errtitle; /* title of error sub-messageboxes */
317 void *data; /* data to pass in refresh events */
318 union control *focused, *lastfocused; /* which ctrl has focus now/before */
319 char shortcuts[128]; /* track which shortcuts in use */
320 int coloursel_wanted; /* has an event handler asked for
321 * a colour selector? */
322 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
323 tree234 *privdata; /* stores per-control private data */
324 int ended, endresult; /* has the dialog been ended? */
325 int fixed_pitch_fonts; /* are we constrained to fixed fonts? */
329 * Exports from winctrls.c.
331 void ctlposinit(struct ctlpos *cp, HWND hwnd,
332 int leftborder, int rightborder, int topborder);
333 HWND doctl(struct ctlpos *cp, RECT r,
334 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
335 void bartitle(struct ctlpos *cp, char *name, int id);
336 void beginbox(struct ctlpos *cp, char *name, int idbox);
337 void endbox(struct ctlpos *cp);
338 void editboxfw(struct ctlpos *cp, int password, char *text,
339 int staticid, int editid);
340 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
341 void bareradioline(struct ctlpos *cp, int nacross, ...);
342 void radiobig(struct ctlpos *cp, char *text, int id, ...);
343 void checkbox(struct ctlpos *cp, char *text, int id);
344 void statictext(struct ctlpos *cp, char *text, int lines, int id);
345 void staticbtn(struct ctlpos *cp, char *stext, int sid,
346 char *btext, int bid);
347 void static2btn(struct ctlpos *cp, char *stext, int sid,
348 char *btext1, int bid1, char *btext2, int bid2);
349 void staticedit(struct ctlpos *cp, char *stext,
350 int sid, int eid, int percentedit);
351 void staticddl(struct ctlpos *cp, char *stext,
352 int sid, int lid, int percentlist);
353 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
354 void staticpassedit(struct ctlpos *cp, char *stext,
355 int sid, int eid, int percentedit);
356 void bigeditctrl(struct ctlpos *cp, char *stext,
357 int sid, int eid, int lines);
358 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
359 void editbutton(struct ctlpos *cp, char *stext, int sid,
360 int eid, char *btext, int bid);
361 void sesssaver(struct ctlpos *cp, char *text,
362 int staticid, int editid, int listid, ...);
363 void envsetter(struct ctlpos *cp, char *stext, int sid,
364 char *e1stext, int e1sid, int e1id,
365 char *e2stext, int e2sid, int e2id,
366 int listid, char *b1text, int b1id, char *b2text, int b2id);
367 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
368 char *btext, int bid, int eid, char *s2text, int s2id);
369 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
370 char *btext, int bid, ...);
371 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
372 char *stext, int sid, int listid, int upbid, int dnbid);
373 int handle_prefslist(struct prefslist *hdl,
374 int *array, int maxmemb,
375 int is_dlmsg, HWND hwnd,
376 WPARAM wParam, LPARAM lParam);
377 void progressbar(struct ctlpos *cp, int id);
378 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
379 char *e1stext, int e1sid, int e1id,
380 char *e2stext, int e2sid, int e2id,
381 char *btext, int bid,
382 char *r1text, int r1id, char *r2text, int r2id);
384 void dlg_auto_set_fixed_pitch_flag(void *dlg);
385 int dlg_get_fixed_pitch_flag(void *dlg);
386 void dlg_set_fixed_pitch_flag(void *dlg, int flag);
388 #define MAX_SHORTCUTS_PER_CTRL 16
391 * This structure is what's stored for each `union control' in the
392 * portable-dialog interface.
397 * The control may have several components at the Windows
398 * level, with different dialog IDs. To avoid needing N
399 * separate platformsidectrl structures (which could be stored
400 * separately in a tree234 so that lookup by ID worked), we
401 * impose the constraint that those IDs must be in a contiguous
407 * Remember what keyboard shortcuts were used by this control,
408 * so that when we remove it again we can take them out of the
409 * list in the dlgparam.
411 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
413 * Some controls need a piece of allocated memory in which to
414 * store temporary data about the control.
419 * And this structure holds a set of the above, in two separate
420 * tree234s so that it can find an item by `union control' or by
424 tree234 *byctrl, *byid;
429 void winctrl_init(struct winctrls *);
430 void winctrl_cleanup(struct winctrls *);
431 void winctrl_add(struct winctrls *, struct winctrl *);
432 void winctrl_remove(struct winctrls *, struct winctrl *);
433 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
434 struct winctrl *winctrl_findbyid(struct winctrls *, int);
435 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
436 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
437 struct ctlpos *cp, struct controlset *s, int *id);
438 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
439 WPARAM wParam, LPARAM lParam);
440 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
441 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
443 void dp_init(struct dlgparam *dp);
444 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
445 void dp_cleanup(struct dlgparam *dp);
448 * Exports from wincfg.c.
450 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
451 int midsession, int protocol);
454 * Exports from windlg.c.
456 void defuse_showwindow(void);
458 int do_reconfig(HWND, int);
459 void showeventlog(HWND);
460 void showabout(HWND);
461 void force_normal(HWND hwnd);
462 void modal_about_box(HWND hwnd);
463 void show_help(HWND hwnd);
466 * Exports from winmisc.c.
468 extern OSVERSIONINFO osVersion;
469 BOOL init_winver(void);
470 HMODULE load_system32_dll(const char *libname);
471 const char *win_strerror(int error);
474 * Exports from sizetip.c.
476 void UpdateSizeTip(HWND src, int cx, int cy);
477 void EnableSizeTip(int bEnable);
480 * Exports from unicode.c.
483 void init_ucs(Conf *, struct unicode_data *);
486 * Exports from winhandl.c.
488 #define HANDLE_FLAG_OVERLAPPED 1
489 #define HANDLE_FLAG_IGNOREEOF 2
490 #define HANDLE_FLAG_UNITBUFFER 4
492 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
493 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
494 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
495 void *privdata, int flags);
496 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
497 void *privdata, int flags);
498 int handle_write(struct handle *h, const void *data, int len);
499 void handle_write_eof(struct handle *h);
500 HANDLE *handle_get_events(int *nevents);
501 void handle_free(struct handle *h);
502 void handle_got_event(HANDLE event);
503 void handle_unthrottle(struct handle *h, int backlog);
504 int handle_backlog(struct handle *h);
505 void *handle_get_privdata(struct handle *h);
506 struct handle *handle_add_foreign_event(HANDLE event,
507 void (*callback)(void *), void *ctx);
510 * winpgntc.c needs to schedule callbacks for asynchronous agent
511 * requests. This has to be done differently in GUI and console, so
512 * there's an exported function used for the purpose.
514 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
515 * synchronous in pscp and psftp.
517 void agent_schedule_callback(void (*callback)(void *, void *, int),
518 void *callback_ctx, void *data, int len);
519 #define FLAG_SYNCAGENT 0x1000
522 * Exports from winser.c.
524 extern Backend serial_backend;
527 * Exports from winjump.c.
529 #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
530 void add_session_to_jumplist(const char * const sessionname);
531 void remove_session_from_jumplist(const char * const sessionname);
532 void clear_jumplist(void);
535 * Extra functions in winstore.c over and above the interface in
538 * These functions manipulate the Registry section which mirrors the
539 * current Windows 7 jump list. (Because the real jump list storage is
540 * write-only, we need to keep another copy of whatever we put in it,
541 * so that we can put in a slightly modified version the next time.)
544 /* Adds a saved session to the registry jump list mirror. 'item' is a
545 * string naming a saved session. */
546 int add_to_jumplist_registry(const char *item);
548 /* Removes an item from the registry jump list mirror. */
549 int remove_from_jumplist_registry(const char *item);
551 /* Returns the current jump list entries from the registry. Caller
552 * must free the returned pointer, which points to a contiguous
553 * sequence of NUL-terminated strings in memory, terminated with an
555 char *get_jumplist_registry_entries(void);