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