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))
79 * Dynamically linked functions. These come in two flavours:
81 * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
82 * so will always dynamically link against exactly what is specified
83 * in "name". If you're not sure, use this one.
85 * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
86 * preprocessor definitions like "#define foo bar"; this is principally
87 * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
88 * If your function has an argument of type "LPTSTR" or similar, this
89 * is the variant to use.
90 * (However, it can't always be used, as it trips over more complicated
91 * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
93 * (DECL_WINDOWS_FUNCTION works with both these variants.)
95 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
96 typedef rettype (WINAPI *t_##name) params; \
97 linkage t_##name p_##name
99 #define STR(x) STR1(x)
100 #define GET_WINDOWS_FUNCTION_PP(module, name) \
101 (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
102 #define GET_WINDOWS_FUNCTION(module, name) \
103 (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
106 * Global variables. Most modules declare these `extern', but
107 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
108 * module, and so will get them properly defined.
111 #ifdef PUTTY_DO_GLOBALS
114 #define GLOBAL extern
118 #ifndef DONE_TYPEDEFS
119 #define DONE_TYPEDEFS
120 typedef struct conf_tag Conf
;
121 typedef struct backend_tag Backend
;
122 typedef struct terminal_tag Terminal
;
125 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
126 #define PUTTY_REG_PARENT "Software\\SimonTatham"
127 #define PUTTY_REG_PARENT_CHILD "PuTTY"
128 #define PUTTY_REG_GPARENT "Software"
129 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
131 /* Result values for the jumplist registry functions. */
132 #define JUMPLISTREG_OK 0
133 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
134 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
135 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
136 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
137 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
139 #define PUTTY_HELP_FILE "putty.hlp"
140 #define PUTTY_CHM_FILE "putty.chm"
141 #define PUTTY_HELP_CONTENTS "putty.cnt"
143 #define GETTICKCOUNT GetTickCount
144 #define CURSORBLINK GetCaretBlinkTime()
145 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
147 #define DEFAULT_CODEPAGE CP_ACP
148 #define USES_VTLINE_HACK
152 typedef unsigned int uint32
; /* int is 32-bits on Win32 and Win64. */
153 #define PUTTY_UINT32_DEFINED
159 #define GSS_CC CALLBACK
161 typedef struct Ssh_gss_buf {
166 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
167 typedef void *Ssh_gss_name;
172 * Window handles for the windows that can be running during a
175 GLOBAL HWND hwnd
; /* the main terminal window */
179 * The all-important instance handle.
181 GLOBAL HINSTANCE hinst
;
184 * Help file stuff in winhelp.c.
186 void init_help(void);
187 void shutdown_help(void);
189 void launch_help(HWND hwnd
, const char *topic
);
190 void quit_help(HWND hwnd
);
193 * The terminal and logging context are notionally local to the
194 * Windows front end, but they must be shared between window.c and
195 * windlg.c. Likewise the saved-sessions list.
197 GLOBAL Terminal
*term
;
200 #define WM_NETEVENT (WM_APP + 5)
203 * On Windows, we send MA_2CLK as the only event marking the second
204 * press of a mouse button. Compare unix.h.
206 #define MULTICLICK_ONLY_EVENT 1
209 * On Windows, data written to the clipboard must be NUL-terminated.
211 #define SELECTION_NUL_TERMINATED 1
214 * On Windows, copying to the clipboard terminates lines with CRLF.
216 #define SEL_NL { 13, 10 }
219 * sk_getxdmdata() does not exist under Windows (not that I
220 * couldn't write it if I wanted to, but I haven't bothered), so
221 * it's a macro which always returns NULL. With any luck this will
222 * cause the compiler to notice it can optimise away the
223 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
225 #define sk_getxdmdata(socket, lenp) (NULL)
228 * File-selector filter strings used in the config box. On Windows,
229 * these strings are of exactly the type needed to go in
230 * `lpstrFilter' in an OPENFILENAME structure.
232 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
233 "All Files (*.*)\0*\0\0\0")
234 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
235 "All Files (*.*)\0*\0\0\0")
236 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
237 "All Files (*.*)\0*\0\0\0")
240 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
241 * what it can get, which means any WinSock routines used outside
242 * that module must be exported from it as function pointers. So
245 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAAsyncSelect
,
246 (SOCKET
, HWND
, u_int
, long));
247 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAEventSelect
,
248 (SOCKET
, WSAEVENT
, long));
249 DECL_WINDOWS_FUNCTION(GLOBAL
, int, select
,
250 (int, fd_set FAR
*, fd_set FAR
*,
251 fd_set FAR
*, const struct timeval FAR
*));
252 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAGetLastError
, (void));
253 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAEnumNetworkEvents
,
254 (SOCKET
, WSAEVENT
, LPWSANETWORKEVENTS
));
256 extern int socket_writable(SOCKET skt
);
258 extern void socket_reselect_all(void);
261 * Exports from winctrls.c.
270 int boxystart
, boxid
;
275 * Exports from winutils.c.
277 typedef struct filereq_tag filereq
; /* cwd for file requester */
278 BOOL
request_file(filereq
*state
, OPENFILENAME
*of
, int preserve
, int save
);
279 filereq
*filereq_new(void);
280 void filereq_free(filereq
*state
);
281 int message_box(LPCTSTR text
, LPCTSTR caption
, DWORD style
, DWORD helpctxid
);
282 char *GetDlgItemText_alloc(HWND hwnd
, int id
);
283 void split_into_argv(char *, int *, char ***, char ***);
286 * Private structure for prefslist state. Only in the header file
287 * so that we can delegate allocation to callers.
290 int listid
, upbid
, dnbid
;
297 * This structure is passed to event handler functions as the `dlg'
298 * parameter, and hence is passed back to winctrls access functions.
301 HWND hwnd
; /* the hwnd of the dialog box */
302 struct winctrls
*controltrees
[8]; /* can have several of these */
304 char *wintitle
; /* title of actual window */
305 char *errtitle
; /* title of error sub-messageboxes */
306 void *data
; /* data to pass in refresh events */
307 union control
*focused
, *lastfocused
; /* which ctrl has focus now/before */
308 char shortcuts
[128]; /* track which shortcuts in use */
309 int coloursel_wanted
; /* has an event handler asked for
310 * a colour selector? */
311 struct { unsigned char r
, g
, b
, ok
; } coloursel_result
; /* 0-255 */
312 tree234
*privdata
; /* stores per-control private data */
313 int ended
, endresult
; /* has the dialog been ended? */
314 int fixed_pitch_fonts
; /* are we constrained to fixed fonts? */
318 * Exports from winctrls.c.
320 void ctlposinit(struct ctlpos
*cp
, HWND hwnd
,
321 int leftborder
, int rightborder
, int topborder
);
322 HWND
doctl(struct ctlpos
*cp
, RECT r
,
323 char *wclass
, int wstyle
, int exstyle
, char *wtext
, int wid
);
324 void bartitle(struct ctlpos
*cp
, char *name
, int id
);
325 void beginbox(struct ctlpos
*cp
, char *name
, int idbox
);
326 void endbox(struct ctlpos
*cp
);
327 void editboxfw(struct ctlpos
*cp
, int password
, char *text
,
328 int staticid
, int editid
);
329 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...);
330 void bareradioline(struct ctlpos
*cp
, int nacross
, ...);
331 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...);
332 void checkbox(struct ctlpos
*cp
, char *text
, int id
);
333 void statictext(struct ctlpos
*cp
, char *text
, int lines
, int id
);
334 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
335 char *btext
, int bid
);
336 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
337 char *btext1
, int bid1
, char *btext2
, int bid2
);
338 void staticedit(struct ctlpos
*cp
, char *stext
,
339 int sid
, int eid
, int percentedit
);
340 void staticddl(struct ctlpos
*cp
, char *stext
,
341 int sid
, int lid
, int percentlist
);
342 void combobox(struct ctlpos
*cp
, char *text
, int staticid
, int listid
);
343 void staticpassedit(struct ctlpos
*cp
, char *stext
,
344 int sid
, int eid
, int percentedit
);
345 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
346 int sid
, int eid
, int lines
);
347 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
);
348 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
349 int eid
, char *btext
, int bid
);
350 void sesssaver(struct ctlpos
*cp
, char *text
,
351 int staticid
, int editid
, int listid
, ...);
352 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
353 char *e1stext
, int e1sid
, int e1id
,
354 char *e2stext
, int e2sid
, int e2id
,
355 int listid
, char *b1text
, int b1id
, char *b2text
, int b2id
);
356 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
357 char *btext
, int bid
, int eid
, char *s2text
, int s2id
);
358 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
359 char *btext
, int bid
, ...);
360 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, int lines
,
361 char *stext
, int sid
, int listid
, int upbid
, int dnbid
);
362 int handle_prefslist(struct prefslist
*hdl
,
363 int *array
, int maxmemb
,
364 int is_dlmsg
, HWND hwnd
,
365 WPARAM wParam
, LPARAM lParam
);
366 void progressbar(struct ctlpos
*cp
, int id
);
367 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
368 char *e1stext
, int e1sid
, int e1id
,
369 char *e2stext
, int e2sid
, int e2id
,
370 char *btext
, int bid
,
371 char *r1text
, int r1id
, char *r2text
, int r2id
);
373 void dlg_auto_set_fixed_pitch_flag(void *dlg
);
374 int dlg_get_fixed_pitch_flag(void *dlg
);
375 void dlg_set_fixed_pitch_flag(void *dlg
, int flag
);
377 #define MAX_SHORTCUTS_PER_CTRL 16
380 * This structure is what's stored for each `union control' in the
381 * portable-dialog interface.
386 * The control may have several components at the Windows
387 * level, with different dialog IDs. To avoid needing N
388 * separate platformsidectrl structures (which could be stored
389 * separately in a tree234 so that lookup by ID worked), we
390 * impose the constraint that those IDs must be in a contiguous
396 * Remember what keyboard shortcuts were used by this control,
397 * so that when we remove it again we can take them out of the
398 * list in the dlgparam.
400 char shortcuts
[MAX_SHORTCUTS_PER_CTRL
];
402 * Some controls need a piece of allocated memory in which to
403 * store temporary data about the control.
408 * And this structure holds a set of the above, in two separate
409 * tree234s so that it can find an item by `union control' or by
413 tree234
*byctrl
, *byid
;
418 void winctrl_init(struct winctrls
*);
419 void winctrl_cleanup(struct winctrls
*);
420 void winctrl_add(struct winctrls
*, struct winctrl
*);
421 void winctrl_remove(struct winctrls
*, struct winctrl
*);
422 struct winctrl
*winctrl_findbyctrl(struct winctrls
*, union control
*);
423 struct winctrl
*winctrl_findbyid(struct winctrls
*, int);
424 struct winctrl
*winctrl_findbyindex(struct winctrls
*, int);
425 void winctrl_layout(struct dlgparam
*dp
, struct winctrls
*wc
,
426 struct ctlpos
*cp
, struct controlset
*s
, int *id
);
427 int winctrl_handle_command(struct dlgparam
*dp
, UINT msg
,
428 WPARAM wParam
, LPARAM lParam
);
429 void winctrl_rem_shortcuts(struct dlgparam
*dp
, struct winctrl
*c
);
430 int winctrl_context_help(struct dlgparam
*dp
, HWND hwnd
, int id
);
432 void dp_init(struct dlgparam
*dp
);
433 void dp_add_tree(struct dlgparam
*dp
, struct winctrls
*tree
);
434 void dp_cleanup(struct dlgparam
*dp
);
437 * Exports from wincfg.c.
439 void win_setup_config_box(struct controlbox
*b
, HWND
*hwndp
, int has_help
,
440 int midsession
, int protocol
);
443 * Exports from windlg.c.
445 void defuse_showwindow(void);
447 int do_reconfig(HWND
, int);
448 void showeventlog(HWND
);
449 void showabout(HWND
);
450 void force_normal(HWND hwnd
);
451 void modal_about_box(HWND hwnd
);
452 void show_help(HWND hwnd
);
455 * Exports from winmisc.c.
457 extern OSVERSIONINFO osVersion
;
458 BOOL
init_winver(void);
459 HMODULE
load_system32_dll(const char *libname
);
462 * Exports from sizetip.c.
464 void UpdateSizeTip(HWND src
, int cx
, int cy
);
465 void EnableSizeTip(int bEnable
);
468 * Exports from unicode.c.
471 void init_ucs(Conf
*, struct unicode_data
*);
474 * Exports from winhandl.c.
476 #define HANDLE_FLAG_OVERLAPPED 1
477 #define HANDLE_FLAG_IGNOREEOF 2
478 #define HANDLE_FLAG_UNITBUFFER 4
480 typedef int (*handle_inputfn_t
)(struct handle
*h
, void *data
, int len
);
481 typedef void (*handle_outputfn_t
)(struct handle
*h
, int new_backlog
);
482 struct handle
*handle_input_new(HANDLE handle
, handle_inputfn_t gotdata
,
483 void *privdata
, int flags
);
484 struct handle
*handle_output_new(HANDLE handle
, handle_outputfn_t sentdata
,
485 void *privdata
, int flags
);
486 int handle_write(struct handle
*h
, const void *data
, int len
);
487 void handle_write_eof(struct handle
*h
);
488 HANDLE
*handle_get_events(int *nevents
);
489 void handle_free(struct handle
*h
);
490 void handle_got_event(HANDLE event
);
491 void handle_unthrottle(struct handle
*h
, int backlog
);
492 int handle_backlog(struct handle
*h
);
493 void *handle_get_privdata(struct handle
*h
);
496 * winpgntc.c needs to schedule callbacks for asynchronous agent
497 * requests. This has to be done differently in GUI and console, so
498 * there's an exported function used for the purpose.
500 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
501 * synchronous in pscp and psftp.
503 void agent_schedule_callback(void (*callback
)(void *, void *, int),
504 void *callback_ctx
, void *data
, int len
);
505 #define FLAG_SYNCAGENT 0x1000
508 * winpgntc.c also exports these two functions which are used by the
509 * server side of Pageant as well, to get the user SID for comparing
512 int init_advapi(void); /* initialises everything needed by get_user_sid */
513 PSID
get_user_sid(void);
516 * Exports from winser.c.
518 extern Backend serial_backend
;
521 * Exports from winjump.c.
523 #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
524 void add_session_to_jumplist(const char * const sessionname
);
525 void remove_session_from_jumplist(const char * const sessionname
);
526 void clear_jumplist(void);
529 * Extra functions in winstore.c over and above the interface in
532 * These functions manipulate the Registry section which mirrors the
533 * current Windows 7 jump list. (Because the real jump list storage is
534 * write-only, we need to keep another copy of whatever we put in it,
535 * so that we can put in a slightly modified version the next time.)
538 /* Adds a saved session to the registry jump list mirror. 'item' is a
539 * string naming a saved session. */
540 int add_to_jumplist_registry(const char *item
);
542 /* Removes an item from the registry jump list mirror. */
543 int remove_from_jumplist_registry(const char *item
);
545 /* Returns the current jump list entries from the registry. Caller
546 * must free the returned pointer, which points to a contiguous
547 * sequence of NUL-terminated strings in memory, terminated with an
549 char *get_jumplist_registry_entries(void);