]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - windows/winstuff.h
Introduce a new utility function smemclr(), which memsets things to
[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;
20 };
21 #define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
22
23 struct FontSpec {
24     char *name;
25     int isbold;
26     int height;
27     int charset;
28 };
29 struct FontSpec *fontspec_new(const char *name,
30                                int bold, int height, int charset);
31
32 #ifndef CLEARTYPE_QUALITY
33 #define CLEARTYPE_QUALITY 5
34 #endif
35 #define FONT_QUALITY(fq) ( \
36     (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
37     (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
38     (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
39     CLEARTYPE_QUALITY)
40
41 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
42                            * wchar_t strings with environment */
43
44 /*
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
49  * not others...)
50  */
51
52 #ifndef GCLP_HCURSOR
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
64 #undef  GWLP_USERDATA
65 #define GWLP_USERDATA GWL_USERDATA
66 #undef  DWLP_MSGRESULT
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. */
70 #undef LONG_PTR
71 #define LONG_PTR LONG
72 #endif
73
74 #define BOXFLAGS DLGWINDOWEXTRA
75 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
76 #define DF_END 0x0001
77
78 #define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */
79
80 /*
81  * Dynamically linked functions. These come in two flavours:
82  *
83  *  - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
84  *    so will always dynamically link against exactly what is specified
85  *    in "name". If you're not sure, use this one.
86  *
87  *  - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
88  *    preprocessor definitions like "#define foo bar"; this is principally
89  *    intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
90  *    If your function has an argument of type "LPTSTR" or similar, this
91  *    is the variant to use.
92  *    (However, it can't always be used, as it trips over more complicated
93  *    macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
94  *
95  * (DECL_WINDOWS_FUNCTION works with both these variants.)
96  */
97 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
98     typedef rettype (WINAPI *t_##name) params; \
99     linkage t_##name p_##name
100 #define STR1(x) #x
101 #define STR(x) STR1(x)
102 #define GET_WINDOWS_FUNCTION_PP(module, name) \
103     (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
104 #define GET_WINDOWS_FUNCTION(module, name) \
105     (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
106
107 /*
108  * Global variables. Most modules declare these `extern', but
109  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
110  * module, and so will get them properly defined.
111 */
112 #ifndef GLOBAL
113 #ifdef PUTTY_DO_GLOBALS
114 #define GLOBAL
115 #else
116 #define GLOBAL extern
117 #endif
118 #endif
119
120 #ifndef DONE_TYPEDEFS
121 #define DONE_TYPEDEFS
122 typedef struct conf_tag Conf;
123 typedef struct backend_tag Backend;
124 typedef struct terminal_tag Terminal;
125 #endif
126
127 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
128 #define PUTTY_REG_PARENT "Software\\SimonTatham"
129 #define PUTTY_REG_PARENT_CHILD "PuTTY"
130 #define PUTTY_REG_GPARENT "Software"
131 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
132
133 /* Result values for the jumplist registry functions. */
134 #define JUMPLISTREG_OK 0
135 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
136 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
137 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
138 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
139 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
140
141 #define PUTTY_HELP_FILE "putty.hlp"
142 #define PUTTY_CHM_FILE "putty.chm"
143 #define PUTTY_HELP_CONTENTS "putty.cnt"
144
145 #define GETTICKCOUNT GetTickCount
146 #define CURSORBLINK GetCaretBlinkTime()
147 #define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
148
149 #define DEFAULT_CODEPAGE CP_ACP
150 #define USES_VTLINE_HACK
151
152 typedef HDC Context;
153
154 typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
155 #define PUTTY_UINT32_DEFINED
156
157 #ifndef NO_GSSAPI
158 /*
159  * GSS-API stuff
160  */
161 #define GSS_CC CALLBACK
162 /*
163 typedef struct Ssh_gss_buf {
164     size_t length;
165     char *value;
166 } Ssh_gss_buf;
167
168 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
169 typedef void *Ssh_gss_name;
170 */
171 #endif
172
173 /*
174  * Window handles for the windows that can be running during a
175  * PuTTY session.
176  */
177 GLOBAL HWND hwnd;       /* the main terminal window */
178 GLOBAL HWND logbox;
179
180 /*
181  * The all-important instance handle.
182  */
183 GLOBAL HINSTANCE hinst;
184
185 /*
186  * Help file stuff in winhelp.c.
187  */
188 void init_help(void);
189 void shutdown_help(void);
190 int has_help(void);
191 void launch_help(HWND hwnd, const char *topic);
192 void quit_help(HWND hwnd);
193
194 /*
195  * The terminal and logging context are notionally local to the
196  * Windows front end, but they must be shared between window.c and
197  * windlg.c. Likewise the saved-sessions list.
198  */
199 GLOBAL Terminal *term;
200 GLOBAL void *logctx;
201
202 #define WM_NETEVENT  (WM_APP + 5)
203
204 /*
205  * On Windows, we send MA_2CLK as the only event marking the second
206  * press of a mouse button. Compare unix.h.
207  */
208 #define MULTICLICK_ONLY_EVENT 1
209
210 /*
211  * On Windows, data written to the clipboard must be NUL-terminated.
212  */
213 #define SELECTION_NUL_TERMINATED 1
214
215 /*
216  * On Windows, copying to the clipboard terminates lines with CRLF.
217  */
218 #define SEL_NL { 13, 10 }
219
220 /*
221  * sk_getxdmdata() does not exist under Windows (not that I
222  * couldn't write it if I wanted to, but I haven't bothered), so
223  * it's a macro which always returns NULL. With any luck this will
224  * cause the compiler to notice it can optimise away the
225  * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
226  */
227 #define sk_getxdmdata(socket, lenp) (NULL)
228
229 /*
230  * File-selector filter strings used in the config box. On Windows,
231  * these strings are of exactly the type needed to go in
232  * `lpstrFilter' in an OPENFILENAME structure.
233  */
234 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
235                               "All Files (*.*)\0*\0\0\0")
236 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
237                                "All Files (*.*)\0*\0\0\0")
238 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
239                                  "All Files (*.*)\0*\0\0\0")
240
241 /*
242  * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
243  * what it can get, which means any WinSock routines used outside
244  * that module must be exported from it as function pointers. So
245  * here they are.
246  */
247 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
248                       (SOCKET, HWND, u_int, long));
249 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
250                       (SOCKET, WSAEVENT, long));
251 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
252                       (int, fd_set FAR *, fd_set FAR *,
253                        fd_set FAR *, const struct timeval FAR *));
254 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
255 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
256                       (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
257
258 extern int socket_writable(SOCKET skt);
259
260 extern void socket_reselect_all(void);
261
262 /*
263  * Exports from winctrls.c.
264  */
265
266 struct ctlpos {
267     HWND hwnd;
268     WPARAM font;
269     int dlu4inpix;
270     int ypos, width;
271     int xoff;
272     int boxystart, boxid;
273     char *boxtext;
274 };
275
276 /*
277  * Exports from winutils.c.
278  */
279 typedef struct filereq_tag filereq; /* cwd for file requester */
280 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
281 filereq *filereq_new(void);
282 void filereq_free(filereq *state);
283 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
284 char *GetDlgItemText_alloc(HWND hwnd, int id);
285 void split_into_argv(char *, int *, char ***, char ***);
286
287 /*
288  * Private structure for prefslist state. Only in the header file
289  * so that we can delegate allocation to callers.
290  */
291 struct prefslist {
292     int listid, upbid, dnbid;
293     int srcitem;
294     int dummyitem;
295     int dragging;
296 };
297
298 /*
299  * This structure is passed to event handler functions as the `dlg'
300  * parameter, and hence is passed back to winctrls access functions.
301  */
302 struct dlgparam {
303     HWND hwnd;                         /* the hwnd of the dialog box */
304     struct winctrls *controltrees[8];  /* can have several of these */
305     int nctrltrees;
306     char *wintitle;                    /* title of actual window */
307     char *errtitle;                    /* title of error sub-messageboxes */
308     void *data;                        /* data to pass in refresh events */
309     union control *focused, *lastfocused; /* which ctrl has focus now/before */
310     char shortcuts[128];               /* track which shortcuts in use */
311     int coloursel_wanted;              /* has an event handler asked for
312                                         * a colour selector? */
313     struct { unsigned char r, g, b, ok; } coloursel_result;   /* 0-255 */
314     tree234 *privdata;                 /* stores per-control private data */
315     int ended, endresult;              /* has the dialog been ended? */
316     int fixed_pitch_fonts;             /* are we constrained to fixed fonts? */
317 };
318
319 /*
320  * Exports from winctrls.c.
321  */
322 void ctlposinit(struct ctlpos *cp, HWND hwnd,
323                 int leftborder, int rightborder, int topborder);
324 HWND doctl(struct ctlpos *cp, RECT r,
325            char *wclass, int wstyle, int exstyle, char *wtext, int wid);
326 void bartitle(struct ctlpos *cp, char *name, int id);
327 void beginbox(struct ctlpos *cp, char *name, int idbox);
328 void endbox(struct ctlpos *cp);
329 void editboxfw(struct ctlpos *cp, int password, char *text,
330                int staticid, int editid);
331 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
332 void bareradioline(struct ctlpos *cp, int nacross, ...);
333 void radiobig(struct ctlpos *cp, char *text, int id, ...);
334 void checkbox(struct ctlpos *cp, char *text, int id);
335 void statictext(struct ctlpos *cp, char *text, int lines, int id);
336 void staticbtn(struct ctlpos *cp, char *stext, int sid,
337                char *btext, int bid);
338 void static2btn(struct ctlpos *cp, char *stext, int sid,
339                 char *btext1, int bid1, char *btext2, int bid2);
340 void staticedit(struct ctlpos *cp, char *stext,
341                 int sid, int eid, int percentedit);
342 void staticddl(struct ctlpos *cp, char *stext,
343                int sid, int lid, int percentlist);
344 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
345 void staticpassedit(struct ctlpos *cp, char *stext,
346                     int sid, int eid, int percentedit);
347 void bigeditctrl(struct ctlpos *cp, char *stext,
348                  int sid, int eid, int lines);
349 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
350 void editbutton(struct ctlpos *cp, char *stext, int sid,
351                 int eid, char *btext, int bid);
352 void sesssaver(struct ctlpos *cp, char *text,
353                int staticid, int editid, int listid, ...);
354 void envsetter(struct ctlpos *cp, char *stext, int sid,
355                char *e1stext, int e1sid, int e1id,
356                char *e2stext, int e2sid, int e2id,
357                int listid, char *b1text, int b1id, char *b2text, int b2id);
358 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
359                char *btext, int bid, int eid, char *s2text, int s2id);
360 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
361                 char *btext, int bid, ...);
362 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
363                char *stext, int sid, int listid, int upbid, int dnbid);
364 int handle_prefslist(struct prefslist *hdl,
365                      int *array, int maxmemb,
366                      int is_dlmsg, HWND hwnd,
367                      WPARAM wParam, LPARAM lParam);
368 void progressbar(struct ctlpos *cp, int id);
369 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
370                char *e1stext, int e1sid, int e1id,
371                char *e2stext, int e2sid, int e2id,
372                char *btext, int bid,
373                char *r1text, int r1id, char *r2text, int r2id);
374
375 void dlg_auto_set_fixed_pitch_flag(void *dlg);
376 int dlg_get_fixed_pitch_flag(void *dlg);
377 void dlg_set_fixed_pitch_flag(void *dlg, int flag);
378
379 #define MAX_SHORTCUTS_PER_CTRL 16
380
381 /*
382  * This structure is what's stored for each `union control' in the
383  * portable-dialog interface.
384  */
385 struct winctrl {
386     union control *ctrl;
387     /*
388      * The control may have several components at the Windows
389      * level, with different dialog IDs. To avoid needing N
390      * separate platformsidectrl structures (which could be stored
391      * separately in a tree234 so that lookup by ID worked), we
392      * impose the constraint that those IDs must be in a contiguous
393      * block.
394      */
395     int base_id;
396     int num_ids;
397     /*
398      * Remember what keyboard shortcuts were used by this control,
399      * so that when we remove it again we can take them out of the
400      * list in the dlgparam.
401      */
402     char shortcuts[MAX_SHORTCUTS_PER_CTRL];
403     /*
404      * Some controls need a piece of allocated memory in which to
405      * store temporary data about the control.
406      */
407     void *data;
408 };
409 /*
410  * And this structure holds a set of the above, in two separate
411  * tree234s so that it can find an item by `union control' or by
412  * dialog ID.
413  */
414 struct winctrls {
415     tree234 *byctrl, *byid;
416 };
417 struct controlset;
418 struct controlbox;
419
420 void winctrl_init(struct winctrls *);
421 void winctrl_cleanup(struct winctrls *);
422 void winctrl_add(struct winctrls *, struct winctrl *);
423 void winctrl_remove(struct winctrls *, struct winctrl *);
424 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
425 struct winctrl *winctrl_findbyid(struct winctrls *, int);
426 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
427 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
428                     struct ctlpos *cp, struct controlset *s, int *id);
429 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
430                            WPARAM wParam, LPARAM lParam);
431 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
432 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
433
434 void dp_init(struct dlgparam *dp);
435 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
436 void dp_cleanup(struct dlgparam *dp);
437
438 /*
439  * Exports from wincfg.c.
440  */
441 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
442                           int midsession, int protocol);
443
444 /*
445  * Exports from windlg.c.
446  */
447 void defuse_showwindow(void);
448 int do_config(void);
449 int do_reconfig(HWND, int);
450 void showeventlog(HWND);
451 void showabout(HWND);
452 void force_normal(HWND hwnd);
453 void modal_about_box(HWND hwnd);
454 void show_help(HWND hwnd);
455
456 /*
457  * Exports from winmisc.c.
458  */
459 extern OSVERSIONINFO osVersion;
460 BOOL init_winver(void);
461 HMODULE load_system32_dll(const char *libname);
462
463 /*
464  * Exports from sizetip.c.
465  */
466 void UpdateSizeTip(HWND src, int cx, int cy);
467 void EnableSizeTip(int bEnable);
468
469 /*
470  * Exports from unicode.c.
471  */
472 struct unicode_data;
473 void init_ucs(Conf *, struct unicode_data *);
474
475 /*
476  * Exports from winhandl.c.
477  */
478 #define HANDLE_FLAG_OVERLAPPED 1
479 #define HANDLE_FLAG_IGNOREEOF 2
480 #define HANDLE_FLAG_UNITBUFFER 4
481 struct handle;
482 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
483 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
484 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
485                                 void *privdata, int flags);
486 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
487                                  void *privdata, int flags);
488 int handle_write(struct handle *h, const void *data, int len);
489 void handle_write_eof(struct handle *h);
490 HANDLE *handle_get_events(int *nevents);
491 void handle_free(struct handle *h);
492 void handle_got_event(HANDLE event);
493 void handle_unthrottle(struct handle *h, int backlog);
494 int handle_backlog(struct handle *h);
495 void *handle_get_privdata(struct handle *h);
496
497 /*
498  * winpgntc.c needs to schedule callbacks for asynchronous agent
499  * requests. This has to be done differently in GUI and console, so
500  * there's an exported function used for the purpose.
501  * 
502  * Also, we supply FLAG_SYNCAGENT to force agent requests to be
503  * synchronous in pscp and psftp.
504  */
505 void agent_schedule_callback(void (*callback)(void *, void *, int),
506                              void *callback_ctx, void *data, int len);
507 #define FLAG_SYNCAGENT 0x1000
508
509 /*
510  * winpgntc.c also exports these two functions which are used by the
511  * server side of Pageant as well, to get the user SID for comparing
512  * with clients'.
513  */
514 int init_advapi(void);  /* initialises everything needed by get_user_sid */
515 PSID get_user_sid(void);
516
517 /*
518  * Exports from winser.c.
519  */
520 extern Backend serial_backend;
521
522 /*
523  * Exports from winjump.c.
524  */
525 #define JUMPLIST_SUPPORTED             /* suppress #defines in putty.h */
526 void add_session_to_jumplist(const char * const sessionname);
527 void remove_session_from_jumplist(const char * const sessionname);
528 void clear_jumplist(void);
529
530 /*
531  * Extra functions in winstore.c over and above the interface in
532  * storage.h.
533  *
534  * These functions manipulate the Registry section which mirrors the
535  * current Windows 7 jump list. (Because the real jump list storage is
536  * write-only, we need to keep another copy of whatever we put in it,
537  * so that we can put in a slightly modified version the next time.)
538  */
539
540 /* Adds a saved session to the registry jump list mirror. 'item' is a
541  * string naming a saved session. */
542 int add_to_jumplist_registry(const char *item);
543
544 /* Removes an item from the registry jump list mirror. */
545 int remove_from_jumplist_registry(const char *item);
546
547 /* Returns the current jump list entries from the registry. Caller
548  * must free the returned pointer, which points to a contiguous
549  * sequence of NUL-terminated strings in memory, terminated with an
550  * empty one. */
551 char *get_jumplist_registry_entries(void);
552
553 #endif