]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - windows/winstuff.h
I think r8738 broke IPv6 in MSVC Windows builds due to conflict with the
[PuTTY.git] / windows / winstuff.h
1 /*
2  * winstuff.h: Windows-specific inter-module stuff.
3  */
4
5 #ifndef PUTTY_WINSTUFF_H
6 #define PUTTY_WINSTUFF_H
7
8 #ifndef AUTO_WINSOCK
9 #include <winsock2.h>
10 #endif
11 #include <windows.h>
12 #include <stdio.h>                     /* for FILENAME_MAX */
13
14 #include "tree234.h"
15
16 #include "winhelp.h"
17
18 struct Filename {
19     char path[FILENAME_MAX];
20 };
21 #define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) )
22
23 struct FontSpec {
24     char name[64];
25     int isbold;
26     int height;
27     int charset;
28 };
29
30 #ifndef CLEARTYPE_QUALITY
31 #define CLEARTYPE_QUALITY 5
32 #endif
33 #define FONT_QUALITY(fq) ( \
34     (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
35     (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
36     (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
37     CLEARTYPE_QUALITY)
38
39 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
40                            * wchar_t strings with environment */
41
42 /*
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
47  * not others...)
48  */
49
50 #ifndef GCLP_HCURSOR
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
62 #undef  GWLP_USERDATA
63 #define GWLP_USERDATA GWL_USERDATA
64 #undef  DWLP_MSGRESULT
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. */
68 #undef LONG_PTR
69 #define LONG_PTR LONG
70 #endif
71
72 #define BOXFLAGS DLGWINDOWEXTRA
73 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
74 #define DF_END 0x0001
75
76 /*
77  * Dynamically linked functions. These come in two flavours:
78  *
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.
82  *
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.)
90  *
91  * (DECL_WINDOWS_FUNCTION works with both these variants.)
92  */
93 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
94     typedef rettype (WINAPI *t_##name) params; \
95     linkage t_##name p_##name
96 #define STR1(x) #x
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
102
103 /*
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.
107 */
108 #ifndef GLOBAL
109 #ifdef PUTTY_DO_GLOBALS
110 #define GLOBAL
111 #else
112 #define GLOBAL extern
113 #endif
114 #endif
115
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;
121 #endif
122
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"
128
129 #define PUTTY_HELP_FILE "putty.hlp"
130 #define PUTTY_CHM_FILE "putty.chm"
131 #define PUTTY_HELP_CONTENTS "putty.cnt"
132
133 #define GETTICKCOUNT GetTickCount
134 #define CURSORBLINK GetCaretBlinkTime()
135 #define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
136
137 #define DEFAULT_CODEPAGE CP_ACP
138
139 typedef HDC Context;
140
141 #ifndef NO_GSSAPI
142 /*
143  * GSS-API stuff
144  */
145 typedef struct Ssh_gss_buf {
146     int length;
147     char *value;
148 } Ssh_gss_buf;
149
150 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
151 typedef void *Ssh_gss_name;
152 #endif
153
154 /*
155  * Window handles for the windows that can be running during a
156  * PuTTY session.
157  */
158 GLOBAL HWND hwnd;       /* the main terminal window */
159 GLOBAL HWND logbox;
160
161 /*
162  * The all-important instance handle.
163  */
164 GLOBAL HINSTANCE hinst;
165
166 /*
167  * Help file stuff in winhelp.c.
168  */
169 void init_help(void);
170 void shutdown_help(void);
171 int has_help(void);
172 void launch_help(HWND hwnd, const char *topic);
173 void quit_help(HWND hwnd);
174
175 /*
176  * The terminal and logging context are notionally local to the
177  * Windows front end, but they must be shared between window.c and
178  * windlg.c. Likewise the saved-sessions list.
179  */
180 GLOBAL Terminal *term;
181 GLOBAL void *logctx;
182
183 #define WM_NETEVENT  (WM_APP + 5)
184
185 /*
186  * On Windows, we send MA_2CLK as the only event marking the second
187  * press of a mouse button. Compare unix.h.
188  */
189 #define MULTICLICK_ONLY_EVENT 1
190
191 /*
192  * On Windows, data written to the clipboard must be NUL-terminated.
193  */
194 #define SELECTION_NUL_TERMINATED 1
195
196 /*
197  * On Windows, copying to the clipboard terminates lines with CRLF.
198  */
199 #define SEL_NL { 13, 10 }
200
201 /*
202  * sk_getxdmdata() does not exist under Windows (not that I
203  * couldn't write it if I wanted to, but I haven't bothered), so
204  * it's a macro which always returns NULL. With any luck this will
205  * cause the compiler to notice it can optimise away the
206  * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
207  */
208 #define sk_getxdmdata(socket, lenp) (NULL)
209
210 /*
211  * File-selector filter strings used in the config box. On Windows,
212  * these strings are of exactly the type needed to go in
213  * `lpstrFilter' in an OPENFILENAME structure.
214  */
215 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
216                               "All Files (*.*)\0*\0\0\0")
217 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
218                                "All Files (*.*)\0*\0\0\0")
219
220 /*
221  * On some versions of Windows, it has been known for WM_TIMER to
222  * occasionally get its callback time simply wrong, and call us
223  * back several minutes early. Defining these symbols enables
224  * compensation code in timing.c.
225  */
226 #define TIMING_SYNC
227 #define TIMING_SYNC_TICKCOUNT
228
229 /*
230  * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
231  * what it can get, which means any WinSock routines used outside
232  * that module must be exported from it as function pointers. So
233  * here they are.
234  */
235 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
236                       (SOCKET, HWND, u_int, long));
237 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
238                       (SOCKET, WSAEVENT, long));
239 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
240                       (int, fd_set FAR *, fd_set FAR *,
241                        fd_set FAR *, const struct timeval FAR *));
242 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
243 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
244                       (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
245
246 extern int socket_writable(SOCKET skt);
247
248 extern void socket_reselect_all(void);
249
250 /*
251  * Exports from winctrls.c.
252  */
253
254 struct ctlpos {
255     HWND hwnd;
256     WPARAM font;
257     int dlu4inpix;
258     int ypos, width;
259     int xoff;
260     int boxystart, boxid;
261     char *boxtext;
262 };
263
264 /*
265  * Exports from winutils.c.
266  */
267 typedef struct filereq_tag filereq; /* cwd for file requester */
268 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
269 filereq *filereq_new(void);
270 void filereq_free(filereq *state);
271 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
272 void split_into_argv(char *, int *, char ***, char ***);
273
274 /*
275  * Private structure for prefslist state. Only in the header file
276  * so that we can delegate allocation to callers.
277  */
278 struct prefslist {
279     int listid, upbid, dnbid;
280     int srcitem;
281     int dummyitem;
282     int dragging;
283 };
284
285 /*
286  * This structure is passed to event handler functions as the `dlg'
287  * parameter, and hence is passed back to winctrls access functions.
288  */
289 struct dlgparam {
290     HWND hwnd;                         /* the hwnd of the dialog box */
291     struct winctrls *controltrees[8];  /* can have several of these */
292     int nctrltrees;
293     char *wintitle;                    /* title of actual window */
294     char *errtitle;                    /* title of error sub-messageboxes */
295     void *data;                        /* data to pass in refresh events */
296     union control *focused, *lastfocused; /* which ctrl has focus now/before */
297     char shortcuts[128];               /* track which shortcuts in use */
298     int coloursel_wanted;              /* has an event handler asked for
299                                         * a colour selector? */
300     struct { unsigned char r, g, b, ok; } coloursel_result;   /* 0-255 */
301     tree234 *privdata;                 /* stores per-control private data */
302     int ended, endresult;              /* has the dialog been ended? */
303 };
304
305 /*
306  * Exports from winctrls.c.
307  */
308 void ctlposinit(struct ctlpos *cp, HWND hwnd,
309                 int leftborder, int rightborder, int topborder);
310 HWND doctl(struct ctlpos *cp, RECT r,
311            char *wclass, int wstyle, int exstyle, char *wtext, int wid);
312 void bartitle(struct ctlpos *cp, char *name, int id);
313 void beginbox(struct ctlpos *cp, char *name, int idbox);
314 void endbox(struct ctlpos *cp);
315 void editboxfw(struct ctlpos *cp, int password, char *text,
316                int staticid, int editid);
317 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
318 void bareradioline(struct ctlpos *cp, int nacross, ...);
319 void radiobig(struct ctlpos *cp, char *text, int id, ...);
320 void checkbox(struct ctlpos *cp, char *text, int id);
321 void statictext(struct ctlpos *cp, char *text, int lines, int id);
322 void staticbtn(struct ctlpos *cp, char *stext, int sid,
323                char *btext, int bid);
324 void static2btn(struct ctlpos *cp, char *stext, int sid,
325                 char *btext1, int bid1, char *btext2, int bid2);
326 void staticedit(struct ctlpos *cp, char *stext,
327                 int sid, int eid, int percentedit);
328 void staticddl(struct ctlpos *cp, char *stext,
329                int sid, int lid, int percentlist);
330 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
331 void staticpassedit(struct ctlpos *cp, char *stext,
332                     int sid, int eid, int percentedit);
333 void bigeditctrl(struct ctlpos *cp, char *stext,
334                  int sid, int eid, int lines);
335 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
336 void editbutton(struct ctlpos *cp, char *stext, int sid,
337                 int eid, char *btext, int bid);
338 void sesssaver(struct ctlpos *cp, char *text,
339                int staticid, int editid, int listid, ...);
340 void envsetter(struct ctlpos *cp, char *stext, int sid,
341                char *e1stext, int e1sid, int e1id,
342                char *e2stext, int e2sid, int e2id,
343                int listid, char *b1text, int b1id, char *b2text, int b2id);
344 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
345                char *btext, int bid, int eid, char *s2text, int s2id);
346 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
347                 char *btext, int bid, ...);
348 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
349                char *stext, int sid, int listid, int upbid, int dnbid);
350 int handle_prefslist(struct prefslist *hdl,
351                      int *array, int maxmemb,
352                      int is_dlmsg, HWND hwnd,
353                      WPARAM wParam, LPARAM lParam);
354 void progressbar(struct ctlpos *cp, int id);
355 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
356                char *e1stext, int e1sid, int e1id,
357                char *e2stext, int e2sid, int e2id,
358                char *btext, int bid,
359                char *r1text, int r1id, char *r2text, int r2id);
360
361 #define MAX_SHORTCUTS_PER_CTRL 16
362
363 /*
364  * This structure is what's stored for each `union control' in the
365  * portable-dialog interface.
366  */
367 struct winctrl {
368     union control *ctrl;
369     /*
370      * The control may have several components at the Windows
371      * level, with different dialog IDs. To avoid needing N
372      * separate platformsidectrl structures (which could be stored
373      * separately in a tree234 so that lookup by ID worked), we
374      * impose the constraint that those IDs must be in a contiguous
375      * block.
376      */
377     int base_id;
378     int num_ids;
379     /*
380      * Remember what keyboard shortcuts were used by this control,
381      * so that when we remove it again we can take them out of the
382      * list in the dlgparam.
383      */
384     char shortcuts[MAX_SHORTCUTS_PER_CTRL];
385     /*
386      * Some controls need a piece of allocated memory in which to
387      * store temporary data about the control.
388      */
389     void *data;
390 };
391 /*
392  * And this structure holds a set of the above, in two separate
393  * tree234s so that it can find an item by `union control' or by
394  * dialog ID.
395  */
396 struct winctrls {
397     tree234 *byctrl, *byid;
398 };
399 struct controlset;
400 struct controlbox;
401
402 void winctrl_init(struct winctrls *);
403 void winctrl_cleanup(struct winctrls *);
404 void winctrl_add(struct winctrls *, struct winctrl *);
405 void winctrl_remove(struct winctrls *, struct winctrl *);
406 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
407 struct winctrl *winctrl_findbyid(struct winctrls *, int);
408 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
409 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
410                     struct ctlpos *cp, struct controlset *s, int *id);
411 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
412                            WPARAM wParam, LPARAM lParam);
413 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
414 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
415
416 void dp_init(struct dlgparam *dp);
417 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
418 void dp_cleanup(struct dlgparam *dp);
419
420 /*
421  * Exports from wincfg.c.
422  */
423 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
424                           int midsession, int protocol);
425
426 /*
427  * Exports from windlg.c.
428  */
429 void defuse_showwindow(void);
430 int do_config(void);
431 int do_reconfig(HWND, int);
432 void showeventlog(HWND);
433 void showabout(HWND);
434 void force_normal(HWND hwnd);
435 void modal_about_box(HWND hwnd);
436 void show_help(HWND hwnd);
437
438 /*
439  * Exports from winmisc.c.
440  */
441 extern OSVERSIONINFO osVersion;
442 BOOL init_winver(void);
443
444 /*
445  * Exports from sizetip.c.
446  */
447 void UpdateSizeTip(HWND src, int cx, int cy);
448 void EnableSizeTip(int bEnable);
449
450 /*
451  * Exports from unicode.c.
452  */
453 struct unicode_data;
454 void init_ucs(Config *, struct unicode_data *);
455
456 /*
457  * Exports from winhandl.c.
458  */
459 #define HANDLE_FLAG_OVERLAPPED 1
460 #define HANDLE_FLAG_IGNOREEOF 2
461 #define HANDLE_FLAG_UNITBUFFER 4
462 struct handle;
463 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
464 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
465 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
466                                 void *privdata, int flags);
467 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
468                                  void *privdata, int flags);
469 int handle_write(struct handle *h, const void *data, int len);
470 HANDLE *handle_get_events(int *nevents);
471 void handle_free(struct handle *h);
472 void handle_got_event(HANDLE event);
473 void handle_unthrottle(struct handle *h, int backlog);
474 int handle_backlog(struct handle *h);
475 void *handle_get_privdata(struct handle *h);
476
477 /*
478  * pageantc.c needs to schedule callbacks for asynchronous agent
479  * requests. This has to be done differently in GUI and console, so
480  * there's an exported function used for the purpose.
481  * 
482  * Also, we supply FLAG_SYNCAGENT to force agent requests to be
483  * synchronous in pscp and psftp.
484  */
485 void agent_schedule_callback(void (*callback)(void *, void *, int),
486                              void *callback_ctx, void *data, int len);
487 #define FLAG_SYNCAGENT 0x1000
488
489 /*
490  * Exports from winser.c.
491  */
492 extern Backend serial_backend;
493
494 #endif