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