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