2 * winstuff.h: Windows-specific inter-module stuff.
5 #ifndef PUTTY_WINSTUFF_H
6 #define PUTTY_WINSTUFF_H
12 #include <stdio.h> /* for FILENAME_MAX */
19 char path
[FILENAME_MAX
];
21 #define f_open(filename, mode) ( fopen((filename).path, (mode)) )
30 #define BOXFLAGS DLGWINDOWEXTRA
31 #define BOXRESULT DLGWINDOWEXTRA + 4
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.
40 #ifdef PUTTY_DO_GLOBALS
49 typedef struct config_tag Config
;
50 typedef struct backend_tag Backend
;
51 typedef struct terminal_tag Terminal
;
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"
60 #define PUTTY_HELP_FILE "putty.hlp"
61 #define PUTTY_HELP_CONTENTS "putty.cnt"
63 #define GETTICKCOUNT GetTickCount
64 #define CURSORBLINK GetCaretBlinkTime()
65 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
67 #define DEFAULT_CODEPAGE CP_ACP
72 * Window handles for the windows that can be running during a
75 GLOBAL HWND hwnd
; /* the main terminal window */
79 * The all-important instance handle.
81 GLOBAL HINSTANCE hinst
;
84 * Details of the help file.
86 GLOBAL
char *help_path
;
87 GLOBAL
int help_has_contents
;
88 GLOBAL
int requested_help
;
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.
95 GLOBAL Terminal
*term
;
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
103 #define WM_XUSER (WM_USER + 0x2000)
104 #define WM_NETEVENT (WM_XUSER + 5)
107 * On Windows, we send MA_2CLK as the only event marking the second
108 * press of a mouse button. Compare unix.h.
110 #define MULTICLICK_ONLY_EVENT 1
113 * On Windows, data written to the clipboard must be NUL-terminated.
115 #define SELECTION_NUL_TERMINATED 1
118 * On Windows, copying to the clipboard terminates lines with CRLF.
120 #define SEL_NL { 13, 10 }
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 :-)
129 #define sk_getxdmdata(socket, lenp) (NULL)
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.
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")
142 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
143 * what it can get, which means any WinSock routines used outside
144 * that module must be exported from it as function pointers. So
147 extern int (WINAPI
*p_WSAAsyncSelect
)
148 (SOCKET s
, HWND hWnd
, u_int wMsg
, long lEvent
);
149 extern int (WINAPI
*p_WSAEventSelect
)
150 (SOCKET s
, WSAEVENT hEventObject
, long lNetworkEvents
);
151 extern int (WINAPI
*p_select
)
152 (int nfds
, fd_set FAR
* readfds
, fd_set FAR
* writefds
,
153 fd_set FAR
*exceptfds
, const struct timeval FAR
* timeout
);
154 extern int (WINAPI
*p_WSAGetLastError
)(void);
155 extern int (WINAPI
*p_WSAEnumNetworkEvents
)
156 (SOCKET s
, WSAEVENT hEventObject
, LPWSANETWORKEVENTS lpNetworkEvents
);
158 extern int socket_writable(SOCKET skt
);
161 * Exports from winctrls.c.
170 int boxystart
, boxid
;
175 * Exports from winutils.c.
177 typedef struct filereq_tag filereq
; /* cwd for file requester */
178 BOOL
request_file(filereq
*state
, OPENFILENAME
*of
, int preserve
, int save
);
179 filereq
*filereq_new(void);
180 void filereq_free(filereq
*state
);
181 int message_box(LPCTSTR text
, LPCTSTR caption
, DWORD style
, DWORD helpctxid
);
182 void split_into_argv(char *, int *, char ***, char ***);
185 * Private structure for prefslist state. Only in the header file
186 * so that we can delegate allocation to callers.
189 int listid
, upbid
, dnbid
;
196 * This structure is passed to event handler functions as the `dlg'
197 * parameter, and hence is passed back to winctrls access functions.
200 HWND hwnd
; /* the hwnd of the dialog box */
201 struct winctrls
*controltrees
[8]; /* can have several of these */
203 char *wintitle
; /* title of actual window */
204 char *errtitle
; /* title of error sub-messageboxes */
205 void *data
; /* data to pass in refresh events */
206 union control
*focused
, *lastfocused
; /* which ctrl has focus now/before */
207 char shortcuts
[128]; /* track which shortcuts in use */
208 int coloursel_wanted
; /* has an event handler asked for
209 * a colour selector? */
210 struct { unsigned char r
, g
, b
, ok
; } coloursel_result
; /* 0-255 */
211 tree234
*privdata
; /* stores per-control private data */
212 int ended
, endresult
; /* has the dialog been ended? */
216 * Exports from winctrls.c.
218 void ctlposinit(struct ctlpos
*cp
, HWND hwnd
,
219 int leftborder
, int rightborder
, int topborder
);
220 HWND
doctl(struct ctlpos
*cp
, RECT r
,
221 char *wclass
, int wstyle
, int exstyle
, char *wtext
, int wid
);
222 void bartitle(struct ctlpos
*cp
, char *name
, int id
);
223 void beginbox(struct ctlpos
*cp
, char *name
, int idbox
);
224 void endbox(struct ctlpos
*cp
);
225 void multiedit(struct ctlpos
*cp
, int password
, ...);
226 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...);
227 void bareradioline(struct ctlpos
*cp
, int nacross
, ...);
228 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...);
229 void checkbox(struct ctlpos
*cp
, char *text
, int id
);
230 void statictext(struct ctlpos
*cp
, char *text
, int lines
, int id
);
231 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
232 char *btext
, int bid
);
233 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
234 char *btext1
, int bid1
, char *btext2
, int bid2
);
235 void staticedit(struct ctlpos
*cp
, char *stext
,
236 int sid
, int eid
, int percentedit
);
237 void staticddl(struct ctlpos
*cp
, char *stext
,
238 int sid
, int lid
, int percentlist
);
239 void combobox(struct ctlpos
*cp
, char *text
, int staticid
, int listid
);
240 void staticpassedit(struct ctlpos
*cp
, char *stext
,
241 int sid
, int eid
, int percentedit
);
242 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
243 int sid
, int eid
, int lines
);
244 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
);
245 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
246 int eid
, char *btext
, int bid
);
247 void sesssaver(struct ctlpos
*cp
, char *text
,
248 int staticid
, int editid
, int listid
, ...);
249 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
250 char *e1stext
, int e1sid
, int e1id
,
251 char *e2stext
, int e2sid
, int e2id
,
252 int listid
, char *b1text
, int b1id
, char *b2text
, int b2id
);
253 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
254 char *btext
, int bid
, int eid
, char *s2text
, int s2id
);
255 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
256 char *btext
, int bid
, ...);
257 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, int lines
,
258 char *stext
, int sid
, int listid
, int upbid
, int dnbid
);
259 int handle_prefslist(struct prefslist
*hdl
,
260 int *array
, int maxmemb
,
261 int is_dlmsg
, HWND hwnd
,
262 WPARAM wParam
, LPARAM lParam
);
263 void progressbar(struct ctlpos
*cp
, int id
);
264 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
265 char *e1stext
, int e1sid
, int e1id
,
266 char *e2stext
, int e2sid
, int e2id
,
267 char *btext
, int bid
,
268 char *r1text
, int r1id
, char *r2text
, int r2id
);
270 #define MAX_SHORTCUTS_PER_CTRL 16
273 * This structure is what's stored for each `union control' in the
274 * portable-dialog interface.
279 * The control may have several components at the Windows
280 * level, with different dialog IDs. To avoid needing N
281 * separate platformsidectrl structures (which could be stored
282 * separately in a tree234 so that lookup by ID worked), we
283 * impose the constraint that those IDs must be in a contiguous
289 * Remember what keyboard shortcuts were used by this control,
290 * so that when we remove it again we can take them out of the
291 * list in the dlgparam.
293 char shortcuts
[MAX_SHORTCUTS_PER_CTRL
];
295 * Some controls need a piece of allocated memory in which to
296 * store temporary data about the control.
301 * And this structure holds a set of the above, in two separate
302 * tree234s so that it can find an item by `union control' or by
306 tree234
*byctrl
, *byid
;
311 void winctrl_init(struct winctrls
*);
312 void winctrl_cleanup(struct winctrls
*);
313 void winctrl_add(struct winctrls
*, struct winctrl
*);
314 void winctrl_remove(struct winctrls
*, struct winctrl
*);
315 struct winctrl
*winctrl_findbyctrl(struct winctrls
*, union control
*);
316 struct winctrl
*winctrl_findbyid(struct winctrls
*, int);
317 struct winctrl
*winctrl_findbyindex(struct winctrls
*, int);
318 void winctrl_layout(struct dlgparam
*dp
, struct winctrls
*wc
,
319 struct ctlpos
*cp
, struct controlset
*s
, int *id
);
320 int winctrl_handle_command(struct dlgparam
*dp
, UINT msg
,
321 WPARAM wParam
, LPARAM lParam
);
322 void winctrl_rem_shortcuts(struct dlgparam
*dp
, struct winctrl
*c
);
323 int winctrl_context_help(struct dlgparam
*dp
, HWND hwnd
, int id
);
325 void dp_init(struct dlgparam
*dp
);
326 void dp_add_tree(struct dlgparam
*dp
, struct winctrls
*tree
);
327 void dp_cleanup(struct dlgparam
*dp
);
330 * Exports from wincfg.c.
332 void win_setup_config_box(struct controlbox
*b
, HWND
*hwndp
, int has_help
,
336 * Exports from windlg.c.
338 void defuse_showwindow(void);
340 int do_reconfig(HWND
, int);
341 void showeventlog(HWND
);
342 void showabout(HWND
);
343 void force_normal(HWND hwnd
);
344 void modal_about_box(HWND hwnd
);
345 void show_help(HWND hwnd
);
348 * Exports from winmisc.c.
350 extern OSVERSIONINFO osVersion
;
351 BOOL
init_winver(void);
354 * Exports from sizetip.c.
356 void UpdateSizeTip(HWND src
, int cx
, int cy
);
357 void EnableSizeTip(int bEnable
);
360 * Exports from unicode.c.
363 void init_ucs(Config
*, struct unicode_data
*);
366 * pageantc.c needs to schedule callbacks for asynchronous agent
367 * requests. This has to be done differently in GUI and console, so
368 * there's an exported function used for the purpose.
370 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
371 * synchronous in pscp and psftp.
373 void agent_schedule_callback(void (*callback
)(void *, void *, int),
374 void *callback_ctx
, void *data
, int len
);
375 #define FLAG_SYNCAGENT 0x1000