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 * Global variables. Most modules declare these `extern', but
78 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
79 * module, and so will get them properly defined.
82 #ifdef PUTTY_DO_GLOBALS
91 typedef struct config_tag Config;
92 typedef struct backend_tag Backend;
93 typedef struct terminal_tag Terminal;
96 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
97 #define PUTTY_REG_PARENT "Software\\SimonTatham"
98 #define PUTTY_REG_PARENT_CHILD "PuTTY"
99 #define PUTTY_REG_GPARENT "Software"
100 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
102 #define PUTTY_HELP_FILE "putty.hlp"
103 #define PUTTY_CHM_FILE "putty.chm"
104 #define PUTTY_HELP_CONTENTS "putty.cnt"
106 #define GETTICKCOUNT GetTickCount
107 #define CURSORBLINK GetCaretBlinkTime()
108 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
110 #define DEFAULT_CODEPAGE CP_ACP
118 typedef struct Ssh_gss_buf {
123 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
124 typedef void *Ssh_gss_name;
128 * Window handles for the windows that can be running during a
131 GLOBAL HWND hwnd; /* the main terminal window */
135 * The all-important instance handle.
137 GLOBAL HINSTANCE hinst;
140 * Help file stuff in winhelp.c.
142 void init_help(void);
143 void shutdown_help(void);
145 void launch_help(HWND hwnd, const char *topic);
146 void quit_help(HWND hwnd);
149 * The terminal and logging context are notionally local to the
150 * Windows front end, but they must be shared between window.c and
151 * windlg.c. Likewise the saved-sessions list.
153 GLOBAL Terminal *term;
156 #define WM_NETEVENT (WM_APP + 5)
159 * On Windows, we send MA_2CLK as the only event marking the second
160 * press of a mouse button. Compare unix.h.
162 #define MULTICLICK_ONLY_EVENT 1
165 * On Windows, data written to the clipboard must be NUL-terminated.
167 #define SELECTION_NUL_TERMINATED 1
170 * On Windows, copying to the clipboard terminates lines with CRLF.
172 #define SEL_NL { 13, 10 }
175 * sk_getxdmdata() does not exist under Windows (not that I
176 * couldn't write it if I wanted to, but I haven't bothered), so
177 * it's a macro which always returns NULL. With any luck this will
178 * cause the compiler to notice it can optimise away the
179 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
181 #define sk_getxdmdata(socket, lenp) (NULL)
184 * File-selector filter strings used in the config box. On Windows,
185 * these strings are of exactly the type needed to go in
186 * `lpstrFilter' in an OPENFILENAME structure.
188 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
189 "All Files (*.*)\0*\0\0\0")
190 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
191 "All Files (*.*)\0*\0\0\0")
194 * On some versions of Windows, it has been known for WM_TIMER to
195 * occasionally get its callback time simply wrong, and call us
196 * back several minutes early. Defining these symbols enables
197 * compensation code in timing.c.
200 #define TIMING_SYNC_TICKCOUNT
203 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
204 * what it can get, which means any WinSock routines used outside
205 * that module must be exported from it as function pointers. So
208 extern int (WINAPI *p_WSAAsyncSelect)
209 (SOCKET s, HWND hWnd, u_int wMsg, long lEvent);
210 extern int (WINAPI *p_WSAEventSelect)
211 (SOCKET s, WSAEVENT hEventObject, long lNetworkEvents);
212 extern int (WINAPI *p_select)
213 (int nfds, fd_set FAR * readfds, fd_set FAR * writefds,
214 fd_set FAR *exceptfds, const struct timeval FAR * timeout);
215 extern int (WINAPI *p_WSAGetLastError)(void);
216 extern int (WINAPI *p_WSAEnumNetworkEvents)
217 (SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents);
219 extern int socket_writable(SOCKET skt);
221 extern void socket_reselect_all(void);
224 * Exports from winctrls.c.
233 int boxystart, boxid;
238 * Exports from winutils.c.
240 typedef struct filereq_tag filereq; /* cwd for file requester */
241 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
242 filereq *filereq_new(void);
243 void filereq_free(filereq *state);
244 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
245 void split_into_argv(char *, int *, char ***, char ***);
248 * Private structure for prefslist state. Only in the header file
249 * so that we can delegate allocation to callers.
252 int listid, upbid, dnbid;
259 * This structure is passed to event handler functions as the `dlg'
260 * parameter, and hence is passed back to winctrls access functions.
263 HWND hwnd; /* the hwnd of the dialog box */
264 struct winctrls *controltrees[8]; /* can have several of these */
266 char *wintitle; /* title of actual window */
267 char *errtitle; /* title of error sub-messageboxes */
268 void *data; /* data to pass in refresh events */
269 union control *focused, *lastfocused; /* which ctrl has focus now/before */
270 char shortcuts[128]; /* track which shortcuts in use */
271 int coloursel_wanted; /* has an event handler asked for
272 * a colour selector? */
273 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
274 tree234 *privdata; /* stores per-control private data */
275 int ended, endresult; /* has the dialog been ended? */
279 * Exports from winctrls.c.
281 void ctlposinit(struct ctlpos *cp, HWND hwnd,
282 int leftborder, int rightborder, int topborder);
283 HWND doctl(struct ctlpos *cp, RECT r,
284 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
285 void bartitle(struct ctlpos *cp, char *name, int id);
286 void beginbox(struct ctlpos *cp, char *name, int idbox);
287 void endbox(struct ctlpos *cp);
288 void editboxfw(struct ctlpos *cp, int password, char *text,
289 int staticid, int editid);
290 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
291 void bareradioline(struct ctlpos *cp, int nacross, ...);
292 void radiobig(struct ctlpos *cp, char *text, int id, ...);
293 void checkbox(struct ctlpos *cp, char *text, int id);
294 void statictext(struct ctlpos *cp, char *text, int lines, int id);
295 void staticbtn(struct ctlpos *cp, char *stext, int sid,
296 char *btext, int bid);
297 void static2btn(struct ctlpos *cp, char *stext, int sid,
298 char *btext1, int bid1, char *btext2, int bid2);
299 void staticedit(struct ctlpos *cp, char *stext,
300 int sid, int eid, int percentedit);
301 void staticddl(struct ctlpos *cp, char *stext,
302 int sid, int lid, int percentlist);
303 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
304 void staticpassedit(struct ctlpos *cp, char *stext,
305 int sid, int eid, int percentedit);
306 void bigeditctrl(struct ctlpos *cp, char *stext,
307 int sid, int eid, int lines);
308 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
309 void editbutton(struct ctlpos *cp, char *stext, int sid,
310 int eid, char *btext, int bid);
311 void sesssaver(struct ctlpos *cp, char *text,
312 int staticid, int editid, int listid, ...);
313 void envsetter(struct ctlpos *cp, char *stext, int sid,
314 char *e1stext, int e1sid, int e1id,
315 char *e2stext, int e2sid, int e2id,
316 int listid, char *b1text, int b1id, char *b2text, int b2id);
317 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
318 char *btext, int bid, int eid, char *s2text, int s2id);
319 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
320 char *btext, int bid, ...);
321 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
322 char *stext, int sid, int listid, int upbid, int dnbid);
323 int handle_prefslist(struct prefslist *hdl,
324 int *array, int maxmemb,
325 int is_dlmsg, HWND hwnd,
326 WPARAM wParam, LPARAM lParam);
327 void progressbar(struct ctlpos *cp, int id);
328 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
329 char *e1stext, int e1sid, int e1id,
330 char *e2stext, int e2sid, int e2id,
331 char *btext, int bid,
332 char *r1text, int r1id, char *r2text, int r2id);
334 #define MAX_SHORTCUTS_PER_CTRL 16
337 * This structure is what's stored for each `union control' in the
338 * portable-dialog interface.
343 * The control may have several components at the Windows
344 * level, with different dialog IDs. To avoid needing N
345 * separate platformsidectrl structures (which could be stored
346 * separately in a tree234 so that lookup by ID worked), we
347 * impose the constraint that those IDs must be in a contiguous
353 * Remember what keyboard shortcuts were used by this control,
354 * so that when we remove it again we can take them out of the
355 * list in the dlgparam.
357 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
359 * Some controls need a piece of allocated memory in which to
360 * store temporary data about the control.
365 * And this structure holds a set of the above, in two separate
366 * tree234s so that it can find an item by `union control' or by
370 tree234 *byctrl, *byid;
375 void winctrl_init(struct winctrls *);
376 void winctrl_cleanup(struct winctrls *);
377 void winctrl_add(struct winctrls *, struct winctrl *);
378 void winctrl_remove(struct winctrls *, struct winctrl *);
379 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
380 struct winctrl *winctrl_findbyid(struct winctrls *, int);
381 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
382 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
383 struct ctlpos *cp, struct controlset *s, int *id);
384 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
385 WPARAM wParam, LPARAM lParam);
386 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
387 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
389 void dp_init(struct dlgparam *dp);
390 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
391 void dp_cleanup(struct dlgparam *dp);
394 * Exports from wincfg.c.
396 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
397 int midsession, int protocol);
400 * Exports from windlg.c.
402 void defuse_showwindow(void);
404 int do_reconfig(HWND, int);
405 void showeventlog(HWND);
406 void showabout(HWND);
407 void force_normal(HWND hwnd);
408 void modal_about_box(HWND hwnd);
409 void show_help(HWND hwnd);
412 * Exports from winmisc.c.
414 extern OSVERSIONINFO osVersion;
415 BOOL init_winver(void);
418 * Exports from sizetip.c.
420 void UpdateSizeTip(HWND src, int cx, int cy);
421 void EnableSizeTip(int bEnable);
424 * Exports from unicode.c.
427 void init_ucs(Config *, struct unicode_data *);
430 * Exports from winhandl.c.
432 #define HANDLE_FLAG_OVERLAPPED 1
433 #define HANDLE_FLAG_IGNOREEOF 2
434 #define HANDLE_FLAG_UNITBUFFER 4
436 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
437 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
438 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
439 void *privdata, int flags);
440 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
441 void *privdata, int flags);
442 int handle_write(struct handle *h, const void *data, int len);
443 HANDLE *handle_get_events(int *nevents);
444 void handle_free(struct handle *h);
445 void handle_got_event(HANDLE event);
446 void handle_unthrottle(struct handle *h, int backlog);
447 int handle_backlog(struct handle *h);
448 void *handle_get_privdata(struct handle *h);
451 * pageantc.c needs to schedule callbacks for asynchronous agent
452 * requests. This has to be done differently in GUI and console, so
453 * there's an exported function used for the purpose.
455 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
456 * synchronous in pscp and psftp.
458 void agent_schedule_callback(void (*callback)(void *, void *, int),
459 void *callback_ctx, void *data, int len);
460 #define FLAG_SYNCAGENT 0x1000
463 * Exports from winser.c.
465 extern Backend serial_backend;