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 */
19 char path
[FILENAME_MAX
];
21 #define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) )
30 #ifndef CLEARTYPE_QUALITY
31 #define CLEARTYPE_QUALITY 5
33 #define FONT_QUALITY(fq) ( \
34 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
35 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
36 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
39 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
40 * wchar_t strings with environment */
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
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
59 #define GetWindowLongPtr GetWindowLong
60 #undef SetWindowLongPtr
61 #define SetWindowLongPtr SetWindowLong
63 #define GWLP_USERDATA GWL_USERDATA
65 #define DWLP_MSGRESULT DWL_MSGRESULT
66 /* Since we've clobbered the above functions, we should clobber the
67 * associated type regardless of whether it's defined. */
72 #define BOXFLAGS DLGWINDOWEXTRA
73 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
77 * Dynamically linked functions. These come in two flavours:
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.
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.)
91 * (DECL_WINDOWS_FUNCTION works with both these variants.)
93 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
94 typedef rettype (WINAPI *t_##name) params; \
95 linkage t_##name p_##name
97 #define STR(x) STR1(x)
98 #define GET_WINDOWS_FUNCTION_PP(module, name) \
99 p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL
100 #define GET_WINDOWS_FUNCTION(module, name) \
101 p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL
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.
109 #ifdef PUTTY_DO_GLOBALS
112 #define GLOBAL extern
116 #ifndef DONE_TYPEDEFS
117 #define DONE_TYPEDEFS
118 typedef struct config_tag Config
;
119 typedef struct backend_tag Backend
;
120 typedef struct terminal_tag Terminal
;
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"
129 #define PUTTY_HELP_FILE "putty.hlp"
130 #define PUTTY_CHM_FILE "putty.chm"
131 #define PUTTY_HELP_CONTENTS "putty.cnt"
133 #define GETTICKCOUNT GetTickCount
134 #define CURSORBLINK GetCaretBlinkTime()
135 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
137 #define DEFAULT_CODEPAGE CP_ACP
141 typedef unsigned int uint32
; /* int is 32-bits on Win32 and Win64. */
142 #define PUTTY_UINT32_DEFINED
148 #define GSS_CC CALLBACK
150 typedef struct Ssh_gss_buf {
155 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
156 typedef void *Ssh_gss_name;
161 * Window handles for the windows that can be running during a
164 GLOBAL HWND hwnd
; /* the main terminal window */
168 * The all-important instance handle.
170 GLOBAL HINSTANCE hinst
;
173 * Help file stuff in winhelp.c.
175 void init_help(void);
176 void shutdown_help(void);
178 void launch_help(HWND hwnd
, const char *topic
);
179 void quit_help(HWND hwnd
);
182 * The terminal and logging context are notionally local to the
183 * Windows front end, but they must be shared between window.c and
184 * windlg.c. Likewise the saved-sessions list.
186 GLOBAL Terminal
*term
;
189 #define WM_NETEVENT (WM_APP + 5)
192 * On Windows, we send MA_2CLK as the only event marking the second
193 * press of a mouse button. Compare unix.h.
195 #define MULTICLICK_ONLY_EVENT 1
198 * On Windows, data written to the clipboard must be NUL-terminated.
200 #define SELECTION_NUL_TERMINATED 1
203 * On Windows, copying to the clipboard terminates lines with CRLF.
205 #define SEL_NL { 13, 10 }
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
210 * it's a macro which always returns NULL. With any luck this will
211 * cause the compiler to notice it can optimise away the
212 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
214 #define sk_getxdmdata(socket, lenp) (NULL)
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.
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 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
226 "All Files (*.*)\0*\0\0\0")
229 * On some versions of Windows, it has been known for WM_TIMER to
230 * occasionally get its callback time simply wrong, and call us
231 * back several minutes early. Defining these symbols enables
232 * compensation code in timing.c.
235 #define TIMING_SYNC_TICKCOUNT
238 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
239 * what it can get, which means any WinSock routines used outside
240 * that module must be exported from it as function pointers. So
243 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAAsyncSelect
,
244 (SOCKET
, HWND
, u_int
, long));
245 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAEventSelect
,
246 (SOCKET
, WSAEVENT
, long));
247 DECL_WINDOWS_FUNCTION(GLOBAL
, int, select
,
248 (int, fd_set FAR
*, fd_set FAR
*,
249 fd_set FAR
*, const struct timeval FAR
*));
250 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAGetLastError
, (void));
251 DECL_WINDOWS_FUNCTION(GLOBAL
, int, WSAEnumNetworkEvents
,
252 (SOCKET
, WSAEVENT
, LPWSANETWORKEVENTS
));
254 extern int socket_writable(SOCKET skt
);
256 extern void socket_reselect_all(void);
259 * Exports from winctrls.c.
268 int boxystart
, boxid
;
273 * Exports from winutils.c.
275 typedef struct filereq_tag filereq
; /* cwd for file requester */
276 BOOL
request_file(filereq
*state
, OPENFILENAME
*of
, int preserve
, int save
);
277 filereq
*filereq_new(void);
278 void filereq_free(filereq
*state
);
279 int message_box(LPCTSTR text
, LPCTSTR caption
, DWORD style
, DWORD helpctxid
);
280 void split_into_argv(char *, int *, char ***, char ***);
283 * Private structure for prefslist state. Only in the header file
284 * so that we can delegate allocation to callers.
287 int listid
, upbid
, dnbid
;
294 * This structure is passed to event handler functions as the `dlg'
295 * parameter, and hence is passed back to winctrls access functions.
298 HWND hwnd
; /* the hwnd of the dialog box */
299 struct winctrls
*controltrees
[8]; /* can have several of these */
301 char *wintitle
; /* title of actual window */
302 char *errtitle
; /* title of error sub-messageboxes */
303 void *data
; /* data to pass in refresh events */
304 union control
*focused
, *lastfocused
; /* which ctrl has focus now/before */
305 char shortcuts
[128]; /* track which shortcuts in use */
306 int coloursel_wanted
; /* has an event handler asked for
307 * a colour selector? */
308 struct { unsigned char r
, g
, b
, ok
; } coloursel_result
; /* 0-255 */
309 tree234
*privdata
; /* stores per-control private data */
310 int ended
, endresult
; /* has the dialog been ended? */
314 * Exports from winctrls.c.
316 void ctlposinit(struct ctlpos
*cp
, HWND hwnd
,
317 int leftborder
, int rightborder
, int topborder
);
318 HWND
doctl(struct ctlpos
*cp
, RECT r
,
319 char *wclass
, int wstyle
, int exstyle
, char *wtext
, int wid
);
320 void bartitle(struct ctlpos
*cp
, char *name
, int id
);
321 void beginbox(struct ctlpos
*cp
, char *name
, int idbox
);
322 void endbox(struct ctlpos
*cp
);
323 void editboxfw(struct ctlpos
*cp
, int password
, char *text
,
324 int staticid
, int editid
);
325 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...);
326 void bareradioline(struct ctlpos
*cp
, int nacross
, ...);
327 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...);
328 void checkbox(struct ctlpos
*cp
, char *text
, int id
);
329 void statictext(struct ctlpos
*cp
, char *text
, int lines
, int id
);
330 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
331 char *btext
, int bid
);
332 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
333 char *btext1
, int bid1
, char *btext2
, int bid2
);
334 void staticedit(struct ctlpos
*cp
, char *stext
,
335 int sid
, int eid
, int percentedit
);
336 void staticddl(struct ctlpos
*cp
, char *stext
,
337 int sid
, int lid
, int percentlist
);
338 void combobox(struct ctlpos
*cp
, char *text
, int staticid
, int listid
);
339 void staticpassedit(struct ctlpos
*cp
, char *stext
,
340 int sid
, int eid
, int percentedit
);
341 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
342 int sid
, int eid
, int lines
);
343 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
);
344 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
345 int eid
, char *btext
, int bid
);
346 void sesssaver(struct ctlpos
*cp
, char *text
,
347 int staticid
, int editid
, int listid
, ...);
348 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
349 char *e1stext
, int e1sid
, int e1id
,
350 char *e2stext
, int e2sid
, int e2id
,
351 int listid
, char *b1text
, int b1id
, char *b2text
, int b2id
);
352 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
353 char *btext
, int bid
, int eid
, char *s2text
, int s2id
);
354 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
355 char *btext
, int bid
, ...);
356 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, int lines
,
357 char *stext
, int sid
, int listid
, int upbid
, int dnbid
);
358 int handle_prefslist(struct prefslist
*hdl
,
359 int *array
, int maxmemb
,
360 int is_dlmsg
, HWND hwnd
,
361 WPARAM wParam
, LPARAM lParam
);
362 void progressbar(struct ctlpos
*cp
, int id
);
363 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
364 char *e1stext
, int e1sid
, int e1id
,
365 char *e2stext
, int e2sid
, int e2id
,
366 char *btext
, int bid
,
367 char *r1text
, int r1id
, char *r2text
, int r2id
);
369 #define MAX_SHORTCUTS_PER_CTRL 16
372 * This structure is what's stored for each `union control' in the
373 * portable-dialog interface.
378 * The control may have several components at the Windows
379 * level, with different dialog IDs. To avoid needing N
380 * separate platformsidectrl structures (which could be stored
381 * separately in a tree234 so that lookup by ID worked), we
382 * impose the constraint that those IDs must be in a contiguous
388 * Remember what keyboard shortcuts were used by this control,
389 * so that when we remove it again we can take them out of the
390 * list in the dlgparam.
392 char shortcuts
[MAX_SHORTCUTS_PER_CTRL
];
394 * Some controls need a piece of allocated memory in which to
395 * store temporary data about the control.
400 * And this structure holds a set of the above, in two separate
401 * tree234s so that it can find an item by `union control' or by
405 tree234
*byctrl
, *byid
;
410 void winctrl_init(struct winctrls
*);
411 void winctrl_cleanup(struct winctrls
*);
412 void winctrl_add(struct winctrls
*, struct winctrl
*);
413 void winctrl_remove(struct winctrls
*, struct winctrl
*);
414 struct winctrl
*winctrl_findbyctrl(struct winctrls
*, union control
*);
415 struct winctrl
*winctrl_findbyid(struct winctrls
*, int);
416 struct winctrl
*winctrl_findbyindex(struct winctrls
*, int);
417 void winctrl_layout(struct dlgparam
*dp
, struct winctrls
*wc
,
418 struct ctlpos
*cp
, struct controlset
*s
, int *id
);
419 int winctrl_handle_command(struct dlgparam
*dp
, UINT msg
,
420 WPARAM wParam
, LPARAM lParam
);
421 void winctrl_rem_shortcuts(struct dlgparam
*dp
, struct winctrl
*c
);
422 int winctrl_context_help(struct dlgparam
*dp
, HWND hwnd
, int id
);
424 void dp_init(struct dlgparam
*dp
);
425 void dp_add_tree(struct dlgparam
*dp
, struct winctrls
*tree
);
426 void dp_cleanup(struct dlgparam
*dp
);
429 * Exports from wincfg.c.
431 void win_setup_config_box(struct controlbox
*b
, HWND
*hwndp
, int has_help
,
432 int midsession
, int protocol
);
435 * Exports from windlg.c.
437 void defuse_showwindow(void);
439 int do_reconfig(HWND
, int);
440 void showeventlog(HWND
);
441 void showabout(HWND
);
442 void force_normal(HWND hwnd
);
443 void modal_about_box(HWND hwnd
);
444 void show_help(HWND hwnd
);
447 * Exports from winmisc.c.
449 extern OSVERSIONINFO osVersion
;
450 BOOL
init_winver(void);
451 HMODULE
load_system32_dll(const char *libname
);
454 * Exports from sizetip.c.
456 void UpdateSizeTip(HWND src
, int cx
, int cy
);
457 void EnableSizeTip(int bEnable
);
460 * Exports from unicode.c.
463 void init_ucs(Config
*, struct unicode_data
*);
466 * Exports from winhandl.c.
468 #define HANDLE_FLAG_OVERLAPPED 1
469 #define HANDLE_FLAG_IGNOREEOF 2
470 #define HANDLE_FLAG_UNITBUFFER 4
472 typedef int (*handle_inputfn_t
)(struct handle
*h
, void *data
, int len
);
473 typedef void (*handle_outputfn_t
)(struct handle
*h
, int new_backlog
);
474 struct handle
*handle_input_new(HANDLE handle
, handle_inputfn_t gotdata
,
475 void *privdata
, int flags
);
476 struct handle
*handle_output_new(HANDLE handle
, handle_outputfn_t sentdata
,
477 void *privdata
, int flags
);
478 int handle_write(struct handle
*h
, const void *data
, int len
);
479 HANDLE
*handle_get_events(int *nevents
);
480 void handle_free(struct handle
*h
);
481 void handle_got_event(HANDLE event
);
482 void handle_unthrottle(struct handle
*h
, int backlog
);
483 int handle_backlog(struct handle
*h
);
484 void *handle_get_privdata(struct handle
*h
);
487 * pageantc.c needs to schedule callbacks for asynchronous agent
488 * requests. This has to be done differently in GUI and console, so
489 * there's an exported function used for the purpose.
491 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
492 * synchronous in pscp and psftp.
494 void agent_schedule_callback(void (*callback
)(void *, void *, int),
495 void *callback_ctx
, void *data
, int len
);
496 #define FLAG_SYNCAGENT 0x1000
499 * Exports from winser.c.
501 extern Backend serial_backend
;