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