8c3cd914 |
1 | /* |
2 | * winstuff.h: Windows-specific inter-module stuff. |
3 | */ |
4 | |
f7f27309 |
5 | #ifndef PUTTY_WINSTUFF_H |
6 | #define PUTTY_WINSTUFF_H |
7 | |
7440fd44 |
8 | #ifndef AUTO_WINSOCK |
9 | #include <winsock2.h> |
10 | #endif |
11 | #include <windows.h> |
9a30e26b |
12 | #include <stdio.h> /* for FILENAME_MAX */ |
13 | |
fe8abbf4 |
14 | #include "tree234.h" |
15 | |
16 | #include "winhelp.h" |
17 | |
9a30e26b |
18 | struct Filename { |
19 | char path[FILENAME_MAX]; |
20 | }; |
c6940f12 |
21 | #define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) ) |
9a30e26b |
22 | |
23 | struct FontSpec { |
24 | char name[64]; |
25 | int isbold; |
26 | int height; |
27 | int charset; |
28 | }; |
29 | |
17c7fed1 |
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 | |
158cb9b1 |
39 | /* |
40 | * Where we can, we use GetWindowLongPtr and friends because they're |
41 | * more useful on 64-bit platforms, but they're a relatively recent |
42 | * innovation, missing from VC++ 6 and older MinGW. Degrade nicely. |
43 | * (NB that on some systems, some of these things are available but |
44 | * not others...) |
45 | */ |
17c7fed1 |
46 | |
158cb9b1 |
47 | #ifndef GCLP_HCURSOR |
48 | /* GetClassLongPtr and friends */ |
49 | #undef GetClassLongPtr |
50 | #define GetClassLongPtr GetClassLong |
51 | #undef SetClassLongPtr |
52 | #define SetClassLongPtr SetClassLong |
53 | #define GCLP_HCURSOR GCL_HCURSOR |
54 | /* GetWindowLongPtr and friends */ |
55 | #undef GetWindowLongPtr |
17c7fed1 |
56 | #define GetWindowLongPtr GetWindowLong |
158cb9b1 |
57 | #undef SetWindowLongPtr |
17c7fed1 |
58 | #define SetWindowLongPtr SetWindowLong |
158cb9b1 |
59 | #undef GWLP_USERDATA |
17c7fed1 |
60 | #define GWLP_USERDATA GWL_USERDATA |
158cb9b1 |
61 | #undef DWLP_MSGRESULT |
17c7fed1 |
62 | #define DWLP_MSGRESULT DWL_MSGRESULT |
158cb9b1 |
63 | /* Since we've clobbered the above functions, we should clobber the |
64 | * associated type regardless of whether it's defined. */ |
65 | #undef LONG_PTR |
66 | #define LONG_PTR LONG |
17c7fed1 |
67 | #endif |
68 | |
2979718a |
69 | #define BOXFLAGS DLGWINDOWEXTRA |
1e5eefb6 |
70 | #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR)) |
8ee3ff16 |
71 | #define DF_END 0x0001 |
72 | |
8c3cd914 |
73 | /* |
74 | * Global variables. Most modules declare these `extern', but |
75 | * window.c will do `#define PUTTY_DO_GLOBALS' before including this |
76 | * module, and so will get them properly defined. |
2979718a |
77 | */ |
f7f27309 |
78 | #ifndef GLOBAL |
8c3cd914 |
79 | #ifdef PUTTY_DO_GLOBALS |
80 | #define GLOBAL |
81 | #else |
82 | #define GLOBAL extern |
83 | #endif |
f7f27309 |
84 | #endif |
85 | |
a8327734 |
86 | #ifndef DONE_TYPEDEFS |
87 | #define DONE_TYPEDEFS |
88 | typedef struct config_tag Config; |
89 | typedef struct backend_tag Backend; |
90 | typedef struct terminal_tag Terminal; |
91 | #endif |
92 | |
f7f27309 |
93 | #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY" |
94 | #define PUTTY_REG_PARENT "Software\\SimonTatham" |
95 | #define PUTTY_REG_PARENT_CHILD "PuTTY" |
96 | #define PUTTY_REG_GPARENT "Software" |
97 | #define PUTTY_REG_GPARENT_CHILD "SimonTatham" |
98 | |
a9dc49af |
99 | #define PUTTY_HELP_FILE "putty.hlp" |
cb2708d3 |
100 | #define PUTTY_CHM_FILE "putty.chm" |
a9dc49af |
101 | #define PUTTY_HELP_CONTENTS "putty.cnt" |
102 | |
f7f27309 |
103 | #define GETTICKCOUNT GetTickCount |
104 | #define CURSORBLINK GetCaretBlinkTime() |
105 | #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */ |
106 | |
107 | #define DEFAULT_CODEPAGE CP_ACP |
108 | |
109 | typedef HDC Context; |
8c3cd914 |
110 | |
86557057 |
111 | #ifndef NO_GSSAPI |
112 | /* |
113 | * GSS-API stuff |
114 | */ |
115 | typedef struct Ssh_gss_buf { |
116 | int length; |
117 | char *value; |
118 | } Ssh_gss_buf; |
119 | |
120 | #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL} |
2c2bce14 |
121 | typedef void *Ssh_gss_name; |
86557057 |
122 | #endif |
123 | |
f7f27309 |
124 | /* |
5321c0c6 |
125 | * Window handles for the windows that can be running during a |
f7f27309 |
126 | * PuTTY session. |
127 | */ |
5321c0c6 |
128 | GLOBAL HWND hwnd; /* the main terminal window */ |
f7f27309 |
129 | GLOBAL HWND logbox; |
130 | |
131 | /* |
132 | * The all-important instance handle. |
133 | */ |
8c3cd914 |
134 | GLOBAL HINSTANCE hinst; |
135 | |
136 | /* |
cb2708d3 |
137 | * Help file stuff in winhelp.c. |
6b78788a |
138 | */ |
cb2708d3 |
139 | void init_help(void); |
140 | void shutdown_help(void); |
141 | int has_help(void); |
142 | void launch_help(HWND hwnd, const char *topic); |
143 | void quit_help(HWND hwnd); |
6b78788a |
144 | |
145 | /* |
a8327734 |
146 | * The terminal and logging context are notionally local to the |
147 | * Windows front end, but they must be shared between window.c and |
0b4f0bc0 |
148 | * windlg.c. Likewise the saved-sessions list. |
a8327734 |
149 | */ |
150 | GLOBAL Terminal *term; |
151 | GLOBAL void *logctx; |
152 | |
604fab0c |
153 | #define WM_NETEVENT (WM_APP + 5) |
f7f27309 |
154 | |
155 | /* |
e6346999 |
156 | * On Windows, we send MA_2CLK as the only event marking the second |
157 | * press of a mouse button. Compare unix.h. |
158 | */ |
159 | #define MULTICLICK_ONLY_EVENT 1 |
160 | |
161 | /* |
162 | * On Windows, data written to the clipboard must be NUL-terminated. |
163 | */ |
164 | #define SELECTION_NUL_TERMINATED 1 |
165 | |
166 | /* |
0f351587 |
167 | * On Windows, copying to the clipboard terminates lines with CRLF. |
168 | */ |
169 | #define SEL_NL { 13, 10 } |
170 | |
171 | /* |
2f92b717 |
172 | * sk_getxdmdata() does not exist under Windows (not that I |
173 | * couldn't write it if I wanted to, but I haven't bothered), so |
0a4022a1 |
174 | * it's a macro which always returns NULL. With any luck this will |
2f92b717 |
175 | * cause the compiler to notice it can optimise away the |
176 | * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-) |
177 | */ |
0a4022a1 |
178 | #define sk_getxdmdata(socket, lenp) (NULL) |
2f92b717 |
179 | |
180 | /* |
fe8abbf4 |
181 | * File-selector filter strings used in the config box. On Windows, |
182 | * these strings are of exactly the type needed to go in |
183 | * `lpstrFilter' in an OPENFILENAME structure. |
184 | */ |
185 | #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \ |
186 | "All Files (*.*)\0*\0\0\0") |
187 | #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \ |
188 | "All Files (*.*)\0*\0\0\0") |
189 | |
190 | /* |
2ac3322e |
191 | * On some versions of Windows, it has been known for WM_TIMER to |
192 | * occasionally get its callback time simply wrong, and call us |
193 | * back several minutes early. Defining these symbols enables |
194 | * compensation code in timing.c. |
195 | */ |
196 | #define TIMING_SYNC |
197 | #define TIMING_SYNC_TICKCOUNT |
198 | |
199 | /* |
7440fd44 |
200 | * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on |
201 | * what it can get, which means any WinSock routines used outside |
202 | * that module must be exported from it as function pointers. So |
203 | * here they are. |
204 | */ |
205 | extern int (WINAPI *p_WSAAsyncSelect) |
206 | (SOCKET s, HWND hWnd, u_int wMsg, long lEvent); |
207 | extern int (WINAPI *p_WSAEventSelect) |
208 | (SOCKET s, WSAEVENT hEventObject, long lNetworkEvents); |
209 | extern int (WINAPI *p_select) |
210 | (int nfds, fd_set FAR * readfds, fd_set FAR * writefds, |
211 | fd_set FAR *exceptfds, const struct timeval FAR * timeout); |
212 | extern int (WINAPI *p_WSAGetLastError)(void); |
213 | extern int (WINAPI *p_WSAEnumNetworkEvents) |
214 | (SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents); |
215 | |
39934deb |
216 | extern int socket_writable(SOCKET skt); |
217 | |
9f7ebadc |
218 | extern void socket_reselect_all(void); |
219 | |
7440fd44 |
220 | /* |
8c3cd914 |
221 | * Exports from winctrls.c. |
222 | */ |
223 | |
224 | struct ctlpos { |
225 | HWND hwnd; |
226 | WPARAM font; |
227 | int dlu4inpix; |
228 | int ypos, width; |
229 | int xoff; |
3ac9cd9f |
230 | int boxystart, boxid; |
8c3cd914 |
231 | char *boxtext; |
232 | }; |
233 | |
ca20bfcf |
234 | /* |
c0a81592 |
235 | * Exports from winutils.c. |
236 | */ |
9754e5ca |
237 | typedef struct filereq_tag filereq; /* cwd for file requester */ |
238 | BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save); |
239 | filereq *filereq_new(void); |
240 | void filereq_free(filereq *state); |
690695e0 |
241 | int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid); |
d3a1a808 |
242 | void split_into_argv(char *, int *, char ***, char ***); |
c0a81592 |
243 | |
244 | /* |
ca20bfcf |
245 | * Private structure for prefslist state. Only in the header file |
246 | * so that we can delegate allocation to callers. |
247 | */ |
248 | struct prefslist { |
249 | int listid, upbid, dnbid; |
250 | int srcitem; |
251 | int dummyitem; |
252 | int dragging; |
253 | }; |
254 | |
f7f27309 |
255 | /* |
fe8abbf4 |
256 | * This structure is passed to event handler functions as the `dlg' |
257 | * parameter, and hence is passed back to winctrls access functions. |
258 | */ |
259 | struct dlgparam { |
260 | HWND hwnd; /* the hwnd of the dialog box */ |
261 | struct winctrls *controltrees[8]; /* can have several of these */ |
262 | int nctrltrees; |
f6f450e2 |
263 | char *wintitle; /* title of actual window */ |
fe8abbf4 |
264 | char *errtitle; /* title of error sub-messageboxes */ |
265 | void *data; /* data to pass in refresh events */ |
266 | union control *focused, *lastfocused; /* which ctrl has focus now/before */ |
4e6d4091 |
267 | char shortcuts[128]; /* track which shortcuts in use */ |
fe8abbf4 |
268 | int coloursel_wanted; /* has an event handler asked for |
269 | * a colour selector? */ |
fe8abbf4 |
270 | struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */ |
4e6d4091 |
271 | tree234 *privdata; /* stores per-control private data */ |
fe8abbf4 |
272 | int ended, endresult; /* has the dialog been ended? */ |
273 | }; |
274 | |
275 | /* |
f7f27309 |
276 | * Exports from winctrls.c. |
277 | */ |
8c3cd914 |
278 | void ctlposinit(struct ctlpos *cp, HWND hwnd, |
32874aea |
279 | int leftborder, int rightborder, int topborder); |
ca20bfcf |
280 | HWND doctl(struct ctlpos *cp, RECT r, |
32874aea |
281 | char *wclass, int wstyle, int exstyle, char *wtext, int wid); |
8c3cd914 |
282 | void bartitle(struct ctlpos *cp, char *name, int id); |
3ac9cd9f |
283 | void beginbox(struct ctlpos *cp, char *name, int idbox); |
8c3cd914 |
284 | void endbox(struct ctlpos *cp); |
e73667f3 |
285 | void editboxfw(struct ctlpos *cp, int password, char *text, |
286 | int staticid, int editid); |
32874aea |
287 | void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...); |
d74d141c |
288 | void bareradioline(struct ctlpos *cp, int nacross, ...); |
8c3cd914 |
289 | void radiobig(struct ctlpos *cp, char *text, int id, ...); |
290 | void checkbox(struct ctlpos *cp, char *text, int id); |
66ee282a |
291 | void statictext(struct ctlpos *cp, char *text, int lines, int id); |
8c3cd914 |
292 | void staticbtn(struct ctlpos *cp, char *stext, int sid, |
32874aea |
293 | char *btext, int bid); |
af282e3b |
294 | void static2btn(struct ctlpos *cp, char *stext, int sid, |
295 | char *btext1, int bid1, char *btext2, int bid2); |
8c3cd914 |
296 | void staticedit(struct ctlpos *cp, char *stext, |
32874aea |
297 | int sid, int eid, int percentedit); |
2c9c6388 |
298 | void staticddl(struct ctlpos *cp, char *stext, |
299 | int sid, int lid, int percentlist); |
b8ae1f0f |
300 | void combobox(struct ctlpos *cp, char *text, int staticid, int listid); |
6e522441 |
301 | void staticpassedit(struct ctlpos *cp, char *stext, |
32874aea |
302 | int sid, int eid, int percentedit); |
6e522441 |
303 | void bigeditctrl(struct ctlpos *cp, char *stext, |
32874aea |
304 | int sid, int eid, int lines); |
305 | void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id); |
8c3cd914 |
306 | void editbutton(struct ctlpos *cp, char *stext, int sid, |
32874aea |
307 | int eid, char *btext, int bid); |
8c3cd914 |
308 | void sesssaver(struct ctlpos *cp, char *text, |
32874aea |
309 | int staticid, int editid, int listid, ...); |
8c3cd914 |
310 | void envsetter(struct ctlpos *cp, char *stext, int sid, |
32874aea |
311 | char *e1stext, int e1sid, int e1id, |
312 | char *e2stext, int e2sid, int e2id, |
313 | int listid, char *b1text, int b1id, char *b2text, int b2id); |
8c3cd914 |
314 | void charclass(struct ctlpos *cp, char *stext, int sid, int listid, |
32874aea |
315 | char *btext, int bid, int eid, char *s2text, int s2id); |
8c3cd914 |
316 | void colouredit(struct ctlpos *cp, char *stext, int sid, int listid, |
32874aea |
317 | char *btext, int bid, ...); |
fe8abbf4 |
318 | void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines, |
319 | char *stext, int sid, int listid, int upbid, int dnbid); |
ca20bfcf |
320 | int handle_prefslist(struct prefslist *hdl, |
321 | int *array, int maxmemb, |
322 | int is_dlmsg, HWND hwnd, |
323 | WPARAM wParam, LPARAM lParam); |
6e522441 |
324 | void progressbar(struct ctlpos *cp, int id); |
d74d141c |
325 | void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid, |
326 | char *e1stext, int e1sid, int e1id, |
327 | char *e2stext, int e2sid, int e2id, |
a4b92c62 |
328 | char *btext, int bid, |
329 | char *r1text, int r1id, char *r2text, int r2id); |
f7f27309 |
330 | |
fe8abbf4 |
331 | #define MAX_SHORTCUTS_PER_CTRL 16 |
332 | |
333 | /* |
334 | * This structure is what's stored for each `union control' in the |
335 | * portable-dialog interface. |
336 | */ |
337 | struct winctrl { |
338 | union control *ctrl; |
339 | /* |
340 | * The control may have several components at the Windows |
341 | * level, with different dialog IDs. To avoid needing N |
342 | * separate platformsidectrl structures (which could be stored |
343 | * separately in a tree234 so that lookup by ID worked), we |
344 | * impose the constraint that those IDs must be in a contiguous |
345 | * block. |
346 | */ |
347 | int base_id; |
348 | int num_ids; |
349 | /* |
350 | * Remember what keyboard shortcuts were used by this control, |
351 | * so that when we remove it again we can take them out of the |
352 | * list in the dlgparam. |
353 | */ |
354 | char shortcuts[MAX_SHORTCUTS_PER_CTRL]; |
355 | /* |
356 | * Some controls need a piece of allocated memory in which to |
357 | * store temporary data about the control. |
358 | */ |
359 | void *data; |
360 | }; |
361 | /* |
362 | * And this structure holds a set of the above, in two separate |
363 | * tree234s so that it can find an item by `union control' or by |
364 | * dialog ID. |
365 | */ |
366 | struct winctrls { |
367 | tree234 *byctrl, *byid; |
368 | }; |
d1582b2e |
369 | struct controlset; |
370 | struct controlbox; |
371 | |
fe8abbf4 |
372 | void winctrl_init(struct winctrls *); |
373 | void winctrl_cleanup(struct winctrls *); |
374 | void winctrl_add(struct winctrls *, struct winctrl *); |
375 | void winctrl_remove(struct winctrls *, struct winctrl *); |
376 | struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *); |
377 | struct winctrl *winctrl_findbyid(struct winctrls *, int); |
378 | struct winctrl *winctrl_findbyindex(struct winctrls *, int); |
379 | void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, |
380 | struct ctlpos *cp, struct controlset *s, int *id); |
381 | int winctrl_handle_command(struct dlgparam *dp, UINT msg, |
382 | WPARAM wParam, LPARAM lParam); |
d1582b2e |
383 | void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c); |
384 | int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id); |
385 | |
4e6d4091 |
386 | void dp_init(struct dlgparam *dp); |
387 | void dp_add_tree(struct dlgparam *dp, struct winctrls *tree); |
388 | void dp_cleanup(struct dlgparam *dp); |
389 | |
d1582b2e |
390 | /* |
391 | * Exports from wincfg.c. |
392 | */ |
393 | void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, |
8a7f1392 |
394 | int midsession, int protocol); |
fe8abbf4 |
395 | |
f7f27309 |
396 | /* |
397 | * Exports from windlg.c. |
398 | */ |
399 | void defuse_showwindow(void); |
400 | int do_config(void); |
f89c3294 |
401 | int do_reconfig(HWND, int); |
f7f27309 |
402 | void showeventlog(HWND); |
403 | void showabout(HWND); |
f7f27309 |
404 | void force_normal(HWND hwnd); |
d1582b2e |
405 | void modal_about_box(HWND hwnd); |
406 | void show_help(HWND hwnd); |
f7f27309 |
407 | |
f7f27309 |
408 | /* |
8ee3ff16 |
409 | * Exports from winmisc.c. |
410 | */ |
4c48c989 |
411 | extern OSVERSIONINFO osVersion; |
412 | BOOL init_winver(void); |
413 | |
8ee3ff16 |
414 | /* |
f7f27309 |
415 | * Exports from sizetip.c. |
416 | */ |
417 | void UpdateSizeTip(HWND src, int cx, int cy); |
418 | void EnableSizeTip(int bEnable); |
419 | |
facd762c |
420 | /* |
421 | * Exports from unicode.c. |
422 | */ |
07b2a9cd |
423 | struct unicode_data; |
21d2b241 |
424 | void init_ucs(Config *, struct unicode_data *); |
facd762c |
425 | |
c44bf5bd |
426 | /* |
34292b1d |
427 | * Exports from winhandl.c. |
428 | */ |
bdebd7e9 |
429 | #define HANDLE_FLAG_OVERLAPPED 1 |
430 | #define HANDLE_FLAG_IGNOREEOF 2 |
799e067e |
431 | #define HANDLE_FLAG_UNITBUFFER 4 |
34292b1d |
432 | struct handle; |
433 | typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len); |
434 | typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog); |
0e03ceff |
435 | struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata, |
bdebd7e9 |
436 | void *privdata, int flags); |
0e03ceff |
437 | struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata, |
bdebd7e9 |
438 | void *privdata, int flags); |
34292b1d |
439 | int handle_write(struct handle *h, const void *data, int len); |
440 | HANDLE *handle_get_events(int *nevents); |
441 | void handle_free(struct handle *h); |
442 | void handle_got_event(HANDLE event); |
443 | void handle_unthrottle(struct handle *h, int backlog); |
444 | int handle_backlog(struct handle *h); |
0e03ceff |
445 | void *handle_get_privdata(struct handle *h); |
34292b1d |
446 | |
447 | /* |
c44bf5bd |
448 | * pageantc.c needs to schedule callbacks for asynchronous agent |
449 | * requests. This has to be done differently in GUI and console, so |
450 | * there's an exported function used for the purpose. |
451 | * |
452 | * Also, we supply FLAG_SYNCAGENT to force agent requests to be |
453 | * synchronous in pscp and psftp. |
454 | */ |
455 | void agent_schedule_callback(void (*callback)(void *, void *, int), |
456 | void *callback_ctx, void *data, int len); |
457 | #define FLAG_SYNCAGENT 0x1000 |
458 | |
7374c779 |
459 | /* |
460 | * Exports from winser.c. |
461 | */ |
462 | extern Backend serial_backend; |
463 | |
f7f27309 |
464 | #endif |