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