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