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
40 * Where we can, we use GetWindowLongPtr and friends because they're
\r
41 * more useful on 64-bit platforms, but they're a relatively recent
\r
42 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
\r
43 * (NB that on some systems, some of these things are available but
\r
47 #ifndef GCLP_HCURSOR
\r
48 /* GetClassLongPtr and friends */
\r
49 #undef GetClassLongPtr
\r
50 #define GetClassLongPtr GetClassLong
\r
51 #undef SetClassLongPtr
\r
52 #define SetClassLongPtr SetClassLong
\r
53 #define GCLP_HCURSOR GCL_HCURSOR
\r
54 /* GetWindowLongPtr and friends */
\r
55 #undef GetWindowLongPtr
\r
56 #define GetWindowLongPtr GetWindowLong
\r
57 #undef SetWindowLongPtr
\r
58 #define SetWindowLongPtr SetWindowLong
\r
59 #undef GWLP_USERDATA
\r
60 #define GWLP_USERDATA GWL_USERDATA
\r
61 #undef DWLP_MSGRESULT
\r
62 #define DWLP_MSGRESULT DWL_MSGRESULT
\r
63 /* Since we've clobbered the above functions, we should clobber the
\r
64 * associated type regardless of whether it's defined. */
\r
66 #define LONG_PTR LONG
\r
69 #define BOXFLAGS DLGWINDOWEXTRA
\r
70 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
\r
71 #define DF_END 0x0001
\r
74 * Global variables. Most modules declare these `extern', but
\r
75 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
\r
76 * module, and so will get them properly defined.
\r
79 #ifdef PUTTY_DO_GLOBALS
\r
82 #define GLOBAL extern
\r
86 #ifndef DONE_TYPEDEFS
\r
87 #define DONE_TYPEDEFS
\r
88 typedef struct config_tag Config;
\r
89 typedef struct backend_tag Backend;
\r
90 typedef struct terminal_tag Terminal;
\r
93 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
\r
94 #define PUTTY_REG_PARENT "Software\\SimonTatham"
\r
95 #define PUTTY_REG_PARENT_CHILD "PuTTY"
\r
96 #define PUTTY_REG_GPARENT "Software"
\r
97 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
\r
99 #define PUTTY_HELP_FILE "putty.hlp"
\r
100 #define PUTTY_CHM_FILE "putty.chm"
\r
101 #define PUTTY_HELP_CONTENTS "putty.cnt"
\r
103 #define GETTICKCOUNT GetTickCount
\r
104 #define CURSORBLINK GetCaretBlinkTime()
\r
105 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
\r
107 #define DEFAULT_CODEPAGE CP_ACP
\r
109 typedef HDC Context;
\r
112 * Window handles for the windows that can be running during a
\r
115 GLOBAL HWND hwnd; /* the main terminal window */
\r
116 GLOBAL HWND logbox;
\r
119 * The all-important instance handle.
\r
121 GLOBAL HINSTANCE hinst;
\r
124 * Help file stuff in winhelp.c.
\r
126 void init_help(void);
\r
127 void shutdown_help(void);
\r
128 int has_help(void);
\r
129 void launch_help(HWND hwnd, const char *topic);
\r
130 void quit_help(HWND hwnd);
\r
133 * The terminal and logging context are notionally local to the
\r
134 * Windows front end, but they must be shared between window.c and
\r
135 * windlg.c. Likewise the saved-sessions list.
\r
137 GLOBAL Terminal *term;
\r
138 GLOBAL void *logctx;
\r
140 #define WM_NETEVENT (WM_APP + 5)
\r
143 * On Windows, we send MA_2CLK as the only event marking the second
\r
144 * press of a mouse button. Compare unix.h.
\r
146 #define MULTICLICK_ONLY_EVENT 1
\r
149 * On Windows, data written to the clipboard must be NUL-terminated.
\r
151 #define SELECTION_NUL_TERMINATED 1
\r
154 * On Windows, copying to the clipboard terminates lines with CRLF.
\r
156 #define SEL_NL { 13, 10 }
\r
159 * sk_getxdmdata() does not exist under Windows (not that I
\r
160 * couldn't write it if I wanted to, but I haven't bothered), so
\r
161 * it's a macro which always returns NULL. With any luck this will
\r
162 * cause the compiler to notice it can optimise away the
\r
163 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
\r
165 #define sk_getxdmdata(socket, lenp) (NULL)
\r
168 * File-selector filter strings used in the config box. On Windows,
\r
169 * these strings are of exactly the type needed to go in
\r
170 * `lpstrFilter' in an OPENFILENAME structure.
\r
172 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
\r
173 "All Files (*.*)\0*\0\0\0")
\r
174 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
\r
175 "All Files (*.*)\0*\0\0\0")
\r
178 * On some versions of Windows, it has been known for WM_TIMER to
\r
179 * occasionally get its callback time simply wrong, and call us
\r
180 * back several minutes early. Defining these symbols enables
\r
181 * compensation code in timing.c.
\r
183 #define TIMING_SYNC
\r
184 #define TIMING_SYNC_TICKCOUNT
\r
187 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
\r
188 * what it can get, which means any WinSock routines used outside
\r
189 * that module must be exported from it as function pointers. So
\r
192 extern int (WINAPI *p_WSAAsyncSelect)
\r
193 (SOCKET s, HWND hWnd, u_int wMsg, long lEvent);
\r
194 extern int (WINAPI *p_WSAEventSelect)
\r
195 (SOCKET s, WSAEVENT hEventObject, long lNetworkEvents);
\r
196 extern int (WINAPI *p_select)
\r
197 (int nfds, fd_set FAR * readfds, fd_set FAR * writefds,
\r
198 fd_set FAR *exceptfds, const struct timeval FAR * timeout);
\r
199 extern int (WINAPI *p_WSAGetLastError)(void);
\r
200 extern int (WINAPI *p_WSAEnumNetworkEvents)
\r
201 (SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents);
\r
203 extern int socket_writable(SOCKET skt);
\r
205 extern void socket_reselect_all(void);
\r
208 * Exports from winctrls.c.
\r
217 int boxystart, boxid;
\r
222 * Exports from winutils.c.
\r
224 typedef struct filereq_tag filereq; /* cwd for file requester */
\r
225 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
\r
226 filereq *filereq_new(void);
\r
227 void filereq_free(filereq *state);
\r
228 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
\r
229 void split_into_argv(char *, int *, char ***, char ***);
\r
232 * Private structure for prefslist state. Only in the header file
\r
233 * so that we can delegate allocation to callers.
\r
236 int listid, upbid, dnbid;
\r
243 * This structure is passed to event handler functions as the `dlg'
\r
244 * parameter, and hence is passed back to winctrls access functions.
\r
247 HWND hwnd; /* the hwnd of the dialog box */
\r
248 struct winctrls *controltrees[8]; /* can have several of these */
\r
250 char *wintitle; /* title of actual window */
\r
251 char *errtitle; /* title of error sub-messageboxes */
\r
252 void *data; /* data to pass in refresh events */
\r
253 union control *focused, *lastfocused; /* which ctrl has focus now/before */
\r
254 char shortcuts[128]; /* track which shortcuts in use */
\r
255 int coloursel_wanted; /* has an event handler asked for
\r
256 * a colour selector? */
\r
257 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
\r
258 tree234 *privdata; /* stores per-control private data */
\r
259 int ended, endresult; /* has the dialog been ended? */
\r
263 * Exports from winctrls.c.
\r
265 void ctlposinit(struct ctlpos *cp, HWND hwnd,
\r
266 int leftborder, int rightborder, int topborder);
\r
267 HWND doctl(struct ctlpos *cp, RECT r,
\r
268 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
\r
269 void bartitle(struct ctlpos *cp, char *name, int id);
\r
270 void beginbox(struct ctlpos *cp, char *name, int idbox);
\r
271 void endbox(struct ctlpos *cp);
\r
272 void editboxfw(struct ctlpos *cp, int password, char *text,
\r
273 int staticid, int editid);
\r
274 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
\r
275 void bareradioline(struct ctlpos *cp, int nacross, ...);
\r
276 void radiobig(struct ctlpos *cp, char *text, int id, ...);
\r
277 void checkbox(struct ctlpos *cp, char *text, int id);
\r
278 void statictext(struct ctlpos *cp, char *text, int lines, int id);
\r
279 void staticbtn(struct ctlpos *cp, char *stext, int sid,
\r
280 char *btext, int bid);
\r
281 void static2btn(struct ctlpos *cp, char *stext, int sid,
\r
282 char *btext1, int bid1, char *btext2, int bid2);
\r
283 void staticedit(struct ctlpos *cp, char *stext,
\r
284 int sid, int eid, int percentedit);
\r
285 void staticddl(struct ctlpos *cp, char *stext,
\r
286 int sid, int lid, int percentlist);
\r
287 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
\r
288 void staticpassedit(struct ctlpos *cp, char *stext,
\r
289 int sid, int eid, int percentedit);
\r
290 void bigeditctrl(struct ctlpos *cp, char *stext,
\r
291 int sid, int eid, int lines);
\r
292 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
\r
293 void editbutton(struct ctlpos *cp, char *stext, int sid,
\r
294 int eid, char *btext, int bid);
\r
295 void sesssaver(struct ctlpos *cp, char *text,
\r
296 int staticid, int editid, int listid, ...);
\r
297 void envsetter(struct ctlpos *cp, char *stext, int sid,
\r
298 char *e1stext, int e1sid, int e1id,
\r
299 char *e2stext, int e2sid, int e2id,
\r
300 int listid, char *b1text, int b1id, char *b2text, int b2id);
\r
301 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
\r
302 char *btext, int bid, int eid, char *s2text, int s2id);
\r
303 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
\r
304 char *btext, int bid, ...);
\r
305 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
\r
306 char *stext, int sid, int listid, int upbid, int dnbid);
\r
307 int handle_prefslist(struct prefslist *hdl,
\r
308 int *array, int maxmemb,
\r
309 int is_dlmsg, HWND hwnd,
\r
310 WPARAM wParam, LPARAM lParam);
\r
311 void progressbar(struct ctlpos *cp, int id);
\r
312 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
\r
313 char *e1stext, int e1sid, int e1id,
\r
314 char *e2stext, int e2sid, int e2id,
\r
315 char *btext, int bid,
\r
316 char *r1text, int r1id, char *r2text, int r2id);
\r
318 #define MAX_SHORTCUTS_PER_CTRL 16
\r
321 * This structure is what's stored for each `union control' in the
\r
322 * portable-dialog interface.
\r
325 union control *ctrl;
\r
327 * The control may have several components at the Windows
\r
328 * level, with different dialog IDs. To avoid needing N
\r
329 * separate platformsidectrl structures (which could be stored
\r
330 * separately in a tree234 so that lookup by ID worked), we
\r
331 * impose the constraint that those IDs must be in a contiguous
\r
337 * Remember what keyboard shortcuts were used by this control,
\r
338 * so that when we remove it again we can take them out of the
\r
339 * list in the dlgparam.
\r
341 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
\r
343 * Some controls need a piece of allocated memory in which to
\r
344 * store temporary data about the control.
\r
349 * And this structure holds a set of the above, in two separate
\r
350 * tree234s so that it can find an item by `union control' or by
\r
354 tree234 *byctrl, *byid;
\r
359 void winctrl_init(struct winctrls *);
\r
360 void winctrl_cleanup(struct winctrls *);
\r
361 void winctrl_add(struct winctrls *, struct winctrl *);
\r
362 void winctrl_remove(struct winctrls *, struct winctrl *);
\r
363 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
\r
364 struct winctrl *winctrl_findbyid(struct winctrls *, int);
\r
365 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
\r
366 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
\r
367 struct ctlpos *cp, struct controlset *s, int *id);
\r
368 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
\r
369 WPARAM wParam, LPARAM lParam);
\r
370 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
\r
371 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
\r
373 void dp_init(struct dlgparam *dp);
\r
374 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
\r
375 void dp_cleanup(struct dlgparam *dp);
\r
378 * Exports from wincfg.c.
\r
380 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
\r
381 int midsession, int protocol);
\r
384 * Exports from windlg.c.
\r
386 void defuse_showwindow(void);
\r
387 int do_config(void);
\r
388 int do_reconfig(HWND, int);
\r
389 void showeventlog(HWND);
\r
390 void showabout(HWND);
\r
391 void force_normal(HWND hwnd);
\r
392 void modal_about_box(HWND hwnd);
\r
393 void show_help(HWND hwnd);
\r
396 * Exports from winmisc.c.
\r
398 extern OSVERSIONINFO osVersion;
\r
399 BOOL init_winver(void);
\r
402 * Exports from sizetip.c.
\r
404 void UpdateSizeTip(HWND src, int cx, int cy);
\r
405 void EnableSizeTip(int bEnable);
\r
408 * Exports from unicode.c.
\r
410 struct unicode_data;
\r
411 void init_ucs(Config *, struct unicode_data *);
\r
414 * Exports from winhandl.c.
\r
416 #define HANDLE_FLAG_OVERLAPPED 1
\r
417 #define HANDLE_FLAG_IGNOREEOF 2
\r
418 #define HANDLE_FLAG_UNITBUFFER 4
\r
420 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
\r
421 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
\r
422 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
\r
423 void *privdata, int flags);
\r
424 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
\r
425 void *privdata, int flags);
\r
426 int handle_write(struct handle *h, const void *data, int len);
\r
427 HANDLE *handle_get_events(int *nevents);
\r
428 void handle_free(struct handle *h);
\r
429 void handle_got_event(HANDLE event);
\r
430 void handle_unthrottle(struct handle *h, int backlog);
\r
431 int handle_backlog(struct handle *h);
\r
432 void *handle_get_privdata(struct handle *h);
\r
435 * pageantc.c needs to schedule callbacks for asynchronous agent
\r
436 * requests. This has to be done differently in GUI and console, so
\r
437 * there's an exported function used for the purpose.
\r
439 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
\r
440 * synchronous in pscp and psftp.
\r
442 void agent_schedule_callback(void (*callback)(void *, void *, int),
\r
443 void *callback_ctx, void *data, int len);
\r
444 #define FLAG_SYNCAGENT 0x1000
\r
447 * Exports from winser.c.
\r
449 extern Backend serial_backend;
\r