]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - windows/winstuff.h
Use {Get,Set}WindowLongPtr() instead of {Get,Set}WindowLong() for compatibility
[PuTTY.git] / 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 + sizeof(LONG_PTR))
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 GLOBAL int requested_help;
89
90 /*
91  * The terminal and logging context are notionally local to the
92  * Windows front end, but they must be shared between window.c and
93  * windlg.c. Likewise the saved-sessions list.
94  */
95 GLOBAL Terminal *term;
96 GLOBAL void *logctx;
97
98 /*
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 /*
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 /*
118  * On Windows, copying to the clipboard terminates lines with CRLF.
119  */
120 #define SEL_NL { 13, 10 }
121
122 /*
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
125  * it's a macro which always returns NULL. With any luck this will
126  * cause the compiler to notice it can optimise away the
127  * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
128  */
129 #define sk_getxdmdata(socket, lenp) (NULL)
130
131 /*
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 /*
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 /*
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  */
156 extern int (WINAPI *p_WSAAsyncSelect)
157     (SOCKET s, HWND hWnd, u_int wMsg, long lEvent);
158 extern int (WINAPI *p_WSAEventSelect)
159     (SOCKET s, WSAEVENT hEventObject, long lNetworkEvents);
160 extern 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);
163 extern int (WINAPI *p_WSAGetLastError)(void);
164 extern int (WINAPI *p_WSAEnumNetworkEvents)
165     (SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents);
166
167 extern int socket_writable(SOCKET skt);
168
169 /*
170  * Exports from winctrls.c.
171  */
172
173 struct ctlpos {
174     HWND hwnd;
175     WPARAM font;
176     int dlu4inpix;
177     int ypos, width;
178     int xoff;
179     int boxystart, boxid;
180     char *boxtext;
181 };
182
183 /*
184  * Exports from winutils.c.
185  */
186 typedef struct filereq_tag filereq; /* cwd for file requester */
187 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
188 filereq *filereq_new(void);
189 void filereq_free(filereq *state);
190 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
191 void split_into_argv(char *, int *, char ***, char ***);
192
193 /*
194  * Private structure for prefslist state. Only in the header file
195  * so that we can delegate allocation to callers.
196  */
197 struct prefslist {
198     int listid, upbid, dnbid;
199     int srcitem;
200     int dummyitem;
201     int dragging;
202 };
203
204 /*
205  * This structure is passed to event handler functions as the `dlg'
206  * parameter, and hence is passed back to winctrls access functions.
207  */
208 struct dlgparam {
209     HWND hwnd;                         /* the hwnd of the dialog box */
210     struct winctrls *controltrees[8];  /* can have several of these */
211     int nctrltrees;
212     char *wintitle;                    /* title of actual window */
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 */
216     char shortcuts[128];               /* track which shortcuts in use */
217     int coloursel_wanted;              /* has an event handler asked for
218                                         * a colour selector? */
219     struct { unsigned char r, g, b, ok; } coloursel_result;   /* 0-255 */
220     tree234 *privdata;                 /* stores per-control private data */
221     int ended, endresult;              /* has the dialog been ended? */
222 };
223
224 /*
225  * Exports from winctrls.c.
226  */
227 void ctlposinit(struct ctlpos *cp, HWND hwnd,
228                 int leftborder, int rightborder, int topborder);
229 HWND doctl(struct ctlpos *cp, RECT r,
230            char *wclass, int wstyle, int exstyle, char *wtext, int wid);
231 void bartitle(struct ctlpos *cp, char *name, int id);
232 void beginbox(struct ctlpos *cp, char *name, int idbox);
233 void endbox(struct ctlpos *cp);
234 void editboxfw(struct ctlpos *cp, int password, char *text,
235                int staticid, int editid);
236 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
237 void bareradioline(struct ctlpos *cp, int nacross, ...);
238 void radiobig(struct ctlpos *cp, char *text, int id, ...);
239 void checkbox(struct ctlpos *cp, char *text, int id);
240 void statictext(struct ctlpos *cp, char *text, int lines, int id);
241 void staticbtn(struct ctlpos *cp, char *stext, int sid,
242                char *btext, int bid);
243 void static2btn(struct ctlpos *cp, char *stext, int sid,
244                 char *btext1, int bid1, char *btext2, int bid2);
245 void staticedit(struct ctlpos *cp, char *stext,
246                 int sid, int eid, int percentedit);
247 void staticddl(struct ctlpos *cp, char *stext,
248                int sid, int lid, int percentlist);
249 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
250 void staticpassedit(struct ctlpos *cp, char *stext,
251                     int sid, int eid, int percentedit);
252 void bigeditctrl(struct ctlpos *cp, char *stext,
253                  int sid, int eid, int lines);
254 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
255 void editbutton(struct ctlpos *cp, char *stext, int sid,
256                 int eid, char *btext, int bid);
257 void sesssaver(struct ctlpos *cp, char *text,
258                int staticid, int editid, int listid, ...);
259 void envsetter(struct ctlpos *cp, char *stext, int sid,
260                char *e1stext, int e1sid, int e1id,
261                char *e2stext, int e2sid, int e2id,
262                int listid, char *b1text, int b1id, char *b2text, int b2id);
263 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
264                char *btext, int bid, int eid, char *s2text, int s2id);
265 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
266                 char *btext, int bid, ...);
267 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
268                char *stext, int sid, int listid, int upbid, int dnbid);
269 int handle_prefslist(struct prefslist *hdl,
270                      int *array, int maxmemb,
271                      int is_dlmsg, HWND hwnd,
272                      WPARAM wParam, LPARAM lParam);
273 void progressbar(struct ctlpos *cp, int id);
274 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
275                char *e1stext, int e1sid, int e1id,
276                char *e2stext, int e2sid, int e2id,
277                char *btext, int bid,
278                char *r1text, int r1id, char *r2text, int r2id);
279
280 #define MAX_SHORTCUTS_PER_CTRL 16
281
282 /*
283  * This structure is what's stored for each `union control' in the
284  * portable-dialog interface.
285  */
286 struct winctrl {
287     union control *ctrl;
288     /*
289      * The control may have several components at the Windows
290      * level, with different dialog IDs. To avoid needing N
291      * separate platformsidectrl structures (which could be stored
292      * separately in a tree234 so that lookup by ID worked), we
293      * impose the constraint that those IDs must be in a contiguous
294      * block.
295      */
296     int base_id;
297     int num_ids;
298     /*
299      * Remember what keyboard shortcuts were used by this control,
300      * so that when we remove it again we can take them out of the
301      * list in the dlgparam.
302      */
303     char shortcuts[MAX_SHORTCUTS_PER_CTRL];
304     /*
305      * Some controls need a piece of allocated memory in which to
306      * store temporary data about the control.
307      */
308     void *data;
309 };
310 /*
311  * And this structure holds a set of the above, in two separate
312  * tree234s so that it can find an item by `union control' or by
313  * dialog ID.
314  */
315 struct winctrls {
316     tree234 *byctrl, *byid;
317 };
318 struct controlset;
319 struct controlbox;
320
321 void winctrl_init(struct winctrls *);
322 void winctrl_cleanup(struct winctrls *);
323 void winctrl_add(struct winctrls *, struct winctrl *);
324 void winctrl_remove(struct winctrls *, struct winctrl *);
325 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
326 struct winctrl *winctrl_findbyid(struct winctrls *, int);
327 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
328 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
329                     struct ctlpos *cp, struct controlset *s, int *id);
330 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
331                            WPARAM wParam, LPARAM lParam);
332 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
333 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
334
335 void dp_init(struct dlgparam *dp);
336 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
337 void dp_cleanup(struct dlgparam *dp);
338
339 /*
340  * Exports from wincfg.c.
341  */
342 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
343                           int midsession);
344
345 /*
346  * Exports from windlg.c.
347  */
348 void defuse_showwindow(void);
349 int do_config(void);
350 int do_reconfig(HWND, int);
351 void showeventlog(HWND);
352 void showabout(HWND);
353 void force_normal(HWND hwnd);
354 void modal_about_box(HWND hwnd);
355 void show_help(HWND hwnd);
356
357 /*
358  * Exports from winmisc.c.
359  */
360 extern OSVERSIONINFO osVersion;
361 BOOL init_winver(void);
362
363 /*
364  * Exports from sizetip.c.
365  */
366 void UpdateSizeTip(HWND src, int cx, int cy);
367 void EnableSizeTip(int bEnable);
368
369 /*
370  * Exports from unicode.c.
371  */
372 struct unicode_data;
373 void init_ucs(Config *, struct unicode_data *);
374
375 /*
376  * pageantc.c needs to schedule callbacks for asynchronous agent
377  * requests. This has to be done differently in GUI and console, so
378  * there's an exported function used for the purpose.
379  * 
380  * Also, we supply FLAG_SYNCAGENT to force agent requests to be
381  * synchronous in pscp and psftp.
382  */
383 void agent_schedule_callback(void (*callback)(void *, void *, int),
384                              void *callback_ctx, void *data, int len);
385 #define FLAG_SYNCAGENT 0x1000
386
387 #endif