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