2 * winstuff.h: Windows-specific inter-module stuff.
\r
5 #ifndef PUTTY_WINSTUFF_H
\r
6 #define PUTTY_WINSTUFF_H
\r
9 #include <winsock2.h>
\r
11 #include <windows.h>
\r
12 #include <stdio.h> /* for FILENAME_MAX */
\r
14 #include "tree234.h"
\r
16 #include "winhelp.h"
\r
19 char path[FILENAME_MAX];
\r
21 #define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) )
\r
30 #ifndef CLEARTYPE_QUALITY
\r
31 #define CLEARTYPE_QUALITY 5
\r
33 #define FONT_QUALITY(fq) ( \
\r
34 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
\r
35 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
\r
36 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
\r
39 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
\r
40 * wchar_t strings with environment */
\r
43 * Where we can, we use GetWindowLongPtr and friends because they're
\r
44 * more useful on 64-bit platforms, but they're a relatively recent
\r
45 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
\r
46 * (NB that on some systems, some of these things are available but
\r
50 #ifndef GCLP_HCURSOR
\r
51 /* GetClassLongPtr and friends */
\r
52 #undef GetClassLongPtr
\r
53 #define GetClassLongPtr GetClassLong
\r
54 #undef SetClassLongPtr
\r
55 #define SetClassLongPtr SetClassLong
\r
56 #define GCLP_HCURSOR GCL_HCURSOR
\r
57 /* GetWindowLongPtr and friends */
\r
58 #undef GetWindowLongPtr
\r
59 #define GetWindowLongPtr GetWindowLong
\r
60 #undef SetWindowLongPtr
\r
61 #define SetWindowLongPtr SetWindowLong
\r
62 #undef GWLP_USERDATA
\r
63 #define GWLP_USERDATA GWL_USERDATA
\r
64 #undef DWLP_MSGRESULT
\r
65 #define DWLP_MSGRESULT DWL_MSGRESULT
\r
66 /* Since we've clobbered the above functions, we should clobber the
\r
67 * associated type regardless of whether it's defined. */
\r
69 #define LONG_PTR LONG
\r
72 #define BOXFLAGS DLGWINDOWEXTRA
\r
73 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
\r
74 #define DF_END 0x0001
\r
77 * Dynamically linked functions. These come in two flavours:
\r
79 * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
\r
80 * so will always dynamically link against exactly what is specified
\r
81 * in "name". If you're not sure, use this one.
\r
83 * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
\r
84 * preprocessor definitions like "#define foo bar"; this is principally
\r
85 * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
\r
86 * If your function has an argument of type "LPTSTR" or similar, this
\r
87 * is the variant to use.
\r
88 * (However, it can't always be used, as it trips over more complicated
\r
89 * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
\r
91 * (DECL_WINDOWS_FUNCTION works with both these variants.)
\r
93 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
\r
94 typedef rettype (WINAPI *t_##name) params; \
\r
95 linkage t_##name p_##name
\r
97 #define STR(x) STR1(x)
\r
98 #define GET_WINDOWS_FUNCTION_PP(module, name) \
\r
99 (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
\r
100 #define GET_WINDOWS_FUNCTION(module, name) \
\r
101 (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
\r
104 * Global variables. Most modules declare these `extern', but
\r
105 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
\r
106 * module, and so will get them properly defined.
\r
109 #ifdef PUTTY_DO_GLOBALS
\r
112 #define GLOBAL extern
\r
116 #ifndef DONE_TYPEDEFS
\r
117 #define DONE_TYPEDEFS
\r
118 typedef struct config_tag Config;
\r
119 typedef struct backend_tag Backend;
\r
120 typedef struct terminal_tag Terminal;
\r
123 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
\r
124 #define PUTTY_REG_PARENT "Software\\SimonTatham"
\r
125 #define PUTTY_REG_PARENT_CHILD "PuTTY"
\r
126 #define PUTTY_REG_GPARENT "Software"
\r
127 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
\r
129 /* Result values for the jumplist registry functions. */
\r
130 #define JUMPLISTREG_OK 0
\r
131 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
\r
132 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
\r
133 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
\r
134 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
\r
135 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
\r
137 #define PUTTY_HELP_FILE "putty.hlp"
\r
138 #define PUTTY_CHM_FILE "putty.chm"
\r
139 #define PUTTY_HELP_CONTENTS "putty.cnt"
\r
141 #define GETTICKCOUNT GetTickCount
\r
142 #define CURSORBLINK GetCaretBlinkTime()
\r
143 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
\r
145 #define DEFAULT_CODEPAGE CP_ACP
\r
147 typedef HDC Context;
\r
149 typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
\r
150 #define PUTTY_UINT32_DEFINED
\r
156 #define GSS_CC CALLBACK
\r
158 typedef struct Ssh_gss_buf {
\r
163 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
\r
164 typedef void *Ssh_gss_name;
\r
169 * Window handles for the windows that can be running during a
\r
172 GLOBAL HWND hwnd; /* the main terminal window */
\r
173 GLOBAL HWND logbox;
\r
176 * The all-important instance handle.
\r
178 GLOBAL HINSTANCE hinst;
\r
181 * Help file stuff in winhelp.c.
\r
183 void init_help(void);
\r
184 void shutdown_help(void);
\r
185 int has_help(void);
\r
186 void launch_help(HWND hwnd, const char *topic);
\r
187 void quit_help(HWND hwnd);
\r
190 * The terminal and logging context are notionally local to the
\r
191 * Windows front end, but they must be shared between window.c and
\r
192 * windlg.c. Likewise the saved-sessions list.
\r
194 GLOBAL Terminal *term;
\r
195 GLOBAL void *logctx;
\r
197 #define WM_NETEVENT (WM_APP + 5)
\r
200 * On Windows, we send MA_2CLK as the only event marking the second
\r
201 * press of a mouse button. Compare unix.h.
\r
203 #define MULTICLICK_ONLY_EVENT 1
\r
206 * On Windows, data written to the clipboard must be NUL-terminated.
\r
208 #define SELECTION_NUL_TERMINATED 1
\r
211 * On Windows, copying to the clipboard terminates lines with CRLF.
\r
213 #define SEL_NL { 13, 10 }
\r
216 * sk_getxdmdata() does not exist under Windows (not that I
\r
217 * couldn't write it if I wanted to, but I haven't bothered), so
\r
218 * it's a macro which always returns NULL. With any luck this will
\r
219 * cause the compiler to notice it can optimise away the
\r
220 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
\r
222 #define sk_getxdmdata(socket, lenp) (NULL)
\r
225 * File-selector filter strings used in the config box. On Windows,
\r
226 * these strings are of exactly the type needed to go in
\r
227 * `lpstrFilter' in an OPENFILENAME structure.
\r
229 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
\r
230 "All Files (*.*)\0*\0\0\0")
\r
231 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
\r
232 "All Files (*.*)\0*\0\0\0")
\r
233 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
\r
234 "All Files (*.*)\0*\0\0\0")
\r
237 * On some versions of Windows, it has been known for WM_TIMER to
\r
238 * occasionally get its callback time simply wrong, and call us
\r
239 * back several minutes early. Defining these symbols enables
\r
240 * compensation code in timing.c.
\r
242 #define TIMING_SYNC
\r
243 #define TIMING_SYNC_TICKCOUNT
\r
246 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
\r
247 * what it can get, which means any WinSock routines used outside
\r
248 * that module must be exported from it as function pointers. So
\r
251 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
\r
252 (SOCKET, HWND, u_int, long));
\r
253 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
\r
254 (SOCKET, WSAEVENT, long));
\r
255 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
\r
256 (int, fd_set FAR *, fd_set FAR *,
\r
257 fd_set FAR *, const struct timeval FAR *));
\r
258 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
\r
259 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
\r
260 (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
\r
262 extern int socket_writable(SOCKET skt);
\r
264 extern void socket_reselect_all(void);
\r
267 * Exports from winctrls.c.
\r
276 int boxystart, boxid;
\r
281 * Exports from winutils.c.
\r
283 typedef struct filereq_tag filereq; /* cwd for file requester */
\r
284 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
\r
285 filereq *filereq_new(void);
\r
286 void filereq_free(filereq *state);
\r
287 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
\r
288 void split_into_argv(char *, int *, char ***, char ***);
\r
291 * Private structure for prefslist state. Only in the header file
\r
292 * so that we can delegate allocation to callers.
\r
295 int listid, upbid, dnbid;
\r
302 * This structure is passed to event handler functions as the `dlg'
\r
303 * parameter, and hence is passed back to winctrls access functions.
\r
306 HWND hwnd; /* the hwnd of the dialog box */
\r
307 struct winctrls *controltrees[8]; /* can have several of these */
\r
309 char *wintitle; /* title of actual window */
\r
310 char *errtitle; /* title of error sub-messageboxes */
\r
311 void *data; /* data to pass in refresh events */
\r
312 union control *focused, *lastfocused; /* which ctrl has focus now/before */
\r
313 char shortcuts[128]; /* track which shortcuts in use */
\r
314 int coloursel_wanted; /* has an event handler asked for
\r
315 * a colour selector? */
\r
316 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
\r
317 tree234 *privdata; /* stores per-control private data */
\r
318 int ended, endresult; /* has the dialog been ended? */
\r
319 int fixed_pitch_fonts; /* are we constrained to fixed fonts? */
\r
323 * Exports from winctrls.c.
\r
325 void ctlposinit(struct ctlpos *cp, HWND hwnd,
\r
326 int leftborder, int rightborder, int topborder);
\r
327 HWND doctl(struct ctlpos *cp, RECT r,
\r
328 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
\r
329 void bartitle(struct ctlpos *cp, char *name, int id);
\r
330 void beginbox(struct ctlpos *cp, char *name, int idbox);
\r
331 void endbox(struct ctlpos *cp);
\r
332 void editboxfw(struct ctlpos *cp, int password, char *text,
\r
333 int staticid, int editid);
\r
334 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
\r
335 void bareradioline(struct ctlpos *cp, int nacross, ...);
\r
336 void radiobig(struct ctlpos *cp, char *text, int id, ...);
\r
337 void checkbox(struct ctlpos *cp, char *text, int id);
\r
338 void statictext(struct ctlpos *cp, char *text, int lines, int id);
\r
339 void staticbtn(struct ctlpos *cp, char *stext, int sid,
\r
340 char *btext, int bid);
\r
341 void static2btn(struct ctlpos *cp, char *stext, int sid,
\r
342 char *btext1, int bid1, char *btext2, int bid2);
\r
343 void staticedit(struct ctlpos *cp, char *stext,
\r
344 int sid, int eid, int percentedit);
\r
345 void staticddl(struct ctlpos *cp, char *stext,
\r
346 int sid, int lid, int percentlist);
\r
347 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
\r
348 void staticpassedit(struct ctlpos *cp, char *stext,
\r
349 int sid, int eid, int percentedit);
\r
350 void bigeditctrl(struct ctlpos *cp, char *stext,
\r
351 int sid, int eid, int lines);
\r
352 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
\r
353 void editbutton(struct ctlpos *cp, char *stext, int sid,
\r
354 int eid, char *btext, int bid);
\r
355 void sesssaver(struct ctlpos *cp, char *text,
\r
356 int staticid, int editid, int listid, ...);
\r
357 void envsetter(struct ctlpos *cp, char *stext, int sid,
\r
358 char *e1stext, int e1sid, int e1id,
\r
359 char *e2stext, int e2sid, int e2id,
\r
360 int listid, char *b1text, int b1id, char *b2text, int b2id);
\r
361 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
\r
362 char *btext, int bid, int eid, char *s2text, int s2id);
\r
363 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
\r
364 char *btext, int bid, ...);
\r
365 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
\r
366 char *stext, int sid, int listid, int upbid, int dnbid);
\r
367 int handle_prefslist(struct prefslist *hdl,
\r
368 int *array, int maxmemb,
\r
369 int is_dlmsg, HWND hwnd,
\r
370 WPARAM wParam, LPARAM lParam);
\r
371 void progressbar(struct ctlpos *cp, int id);
\r
372 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
\r
373 char *e1stext, int e1sid, int e1id,
\r
374 char *e2stext, int e2sid, int e2id,
\r
375 char *btext, int bid,
\r
376 char *r1text, int r1id, char *r2text, int r2id);
\r
378 void dlg_auto_set_fixed_pitch_flag(void *dlg);
\r
379 int dlg_get_fixed_pitch_flag(void *dlg);
\r
380 void dlg_set_fixed_pitch_flag(void *dlg, int flag);
\r
382 #define MAX_SHORTCUTS_PER_CTRL 16
\r
385 * This structure is what's stored for each `union control' in the
\r
386 * portable-dialog interface.
\r
389 union control *ctrl;
\r
391 * The control may have several components at the Windows
\r
392 * level, with different dialog IDs. To avoid needing N
\r
393 * separate platformsidectrl structures (which could be stored
\r
394 * separately in a tree234 so that lookup by ID worked), we
\r
395 * impose the constraint that those IDs must be in a contiguous
\r
401 * Remember what keyboard shortcuts were used by this control,
\r
402 * so that when we remove it again we can take them out of the
\r
403 * list in the dlgparam.
\r
405 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
\r
407 * Some controls need a piece of allocated memory in which to
\r
408 * store temporary data about the control.
\r
413 * And this structure holds a set of the above, in two separate
\r
414 * tree234s so that it can find an item by `union control' or by
\r
418 tree234 *byctrl, *byid;
\r
423 void winctrl_init(struct winctrls *);
\r
424 void winctrl_cleanup(struct winctrls *);
\r
425 void winctrl_add(struct winctrls *, struct winctrl *);
\r
426 void winctrl_remove(struct winctrls *, struct winctrl *);
\r
427 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
\r
428 struct winctrl *winctrl_findbyid(struct winctrls *, int);
\r
429 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
\r
430 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
\r
431 struct ctlpos *cp, struct controlset *s, int *id);
\r
432 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
\r
433 WPARAM wParam, LPARAM lParam);
\r
434 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
\r
435 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
\r
437 void dp_init(struct dlgparam *dp);
\r
438 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
\r
439 void dp_cleanup(struct dlgparam *dp);
\r
442 * Exports from wincfg.c.
\r
444 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
\r
445 int midsession, int protocol);
\r
448 * Exports from windlg.c.
\r
450 void defuse_showwindow(void);
\r
451 int do_config(void);
\r
452 int do_reconfig(HWND, int);
\r
453 void showeventlog(HWND);
\r
454 void showabout(HWND);
\r
455 void force_normal(HWND hwnd);
\r
456 void modal_about_box(HWND hwnd);
\r
457 void show_help(HWND hwnd);
\r
460 * Exports from winmisc.c.
\r
462 extern OSVERSIONINFO osVersion;
\r
463 BOOL init_winver(void);
\r
464 HMODULE load_system32_dll(const char *libname);
\r
467 * Exports from sizetip.c.
\r
469 void UpdateSizeTip(HWND src, int cx, int cy);
\r
470 void EnableSizeTip(int bEnable);
\r
473 * Exports from unicode.c.
\r
475 struct unicode_data;
\r
476 void init_ucs(Config *, struct unicode_data *);
\r
479 * Exports from winhandl.c.
\r
481 #define HANDLE_FLAG_OVERLAPPED 1
\r
482 #define HANDLE_FLAG_IGNOREEOF 2
\r
483 #define HANDLE_FLAG_UNITBUFFER 4
\r
485 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
\r
486 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
\r
487 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
\r
488 void *privdata, int flags);
\r
489 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
\r
490 void *privdata, int flags);
\r
491 int handle_write(struct handle *h, const void *data, int len);
\r
492 HANDLE *handle_get_events(int *nevents);
\r
493 void handle_free(struct handle *h);
\r
494 void handle_got_event(HANDLE event);
\r
495 void handle_unthrottle(struct handle *h, int backlog);
\r
496 int handle_backlog(struct handle *h);
\r
497 void *handle_get_privdata(struct handle *h);
\r
500 * winpgntc.c needs to schedule callbacks for asynchronous agent
\r
501 * requests. This has to be done differently in GUI and console, so
\r
502 * there's an exported function used for the purpose.
\r
504 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
\r
505 * synchronous in pscp and psftp.
\r
507 void agent_schedule_callback(void (*callback)(void *, void *, int),
\r
508 void *callback_ctx, void *data, int len);
\r
509 #define FLAG_SYNCAGENT 0x1000
\r
512 * winpgntc.c also exports these two functions which are used by the
\r
513 * server side of Pageant as well, to get the user SID for comparing
\r
516 int init_advapi(void); /* initialises everything needed by get_user_sid */
\r
517 PSID get_user_sid(void);
\r
520 * Exports from winser.c.
\r
522 extern Backend serial_backend;
\r
525 * Exports from winjump.c.
\r
527 #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
\r
528 void add_session_to_jumplist(const char * const sessionname);
\r
529 void remove_session_from_jumplist(const char * const sessionname);
\r
530 void clear_jumplist(void);
\r
533 * Extra functions in winstore.c over and above the interface in
\r
536 * These functions manipulate the Registry section which mirrors the
\r
537 * current Windows 7 jump list. (Because the real jump list storage is
\r
538 * write-only, we need to keep another copy of whatever we put in it,
\r
539 * so that we can put in a slightly modified version the next time.)
\r
542 /* Adds a saved session to the registry jump list mirror. 'item' is a
\r
543 * string naming a saved session. */
\r
544 int add_to_jumplist_registry(const char *item);
\r
546 /* Removes an item from the registry jump list mirror. */
\r
547 int remove_from_jumplist_registry(const char *item);
\r
549 /* Returns the current jump list entries from the registry. Caller
\r
550 * must free the returned pointer, which points to a contiguous
\r
551 * sequence of NUL-terminated strings in memory, terminated with an
\r
553 char *get_jumplist_registry_entries(void);
\r