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