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 #ifndef CLEARTYPE_QUALITY
31 #define CLEARTYPE_QUALITY 5
33 #define FONT_QUALITY(fq) ( \
34 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
35 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
36 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
40 * Where we can, we use GetWindowLongPtr and friends because they're
41 * more useful on 64-bit platforms, but they're a relatively recent
42 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
43 * (NB that on some systems, some of these things are available but
48 /* GetClassLongPtr and friends */
49 #undef GetClassLongPtr
50 #define GetClassLongPtr GetClassLong
51 #undef SetClassLongPtr
52 #define SetClassLongPtr SetClassLong
53 #define GCLP_HCURSOR GCL_HCURSOR
54 /* GetWindowLongPtr and friends */
55 #undef GetWindowLongPtr
56 #define GetWindowLongPtr GetWindowLong
57 #undef SetWindowLongPtr
58 #define SetWindowLongPtr SetWindowLong
60 #define GWLP_USERDATA GWL_USERDATA
62 #define DWLP_MSGRESULT DWL_MSGRESULT
63 /* Since we've clobbered the above functions, we should clobber the
64 * associated type regardless of whether it's defined. */
69 #define BOXFLAGS DLGWINDOWEXTRA
70 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
74 * Global variables. Most modules declare these `extern', but
75 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
76 * module, and so will get them properly defined.
79 #ifdef PUTTY_DO_GLOBALS
88 typedef struct config_tag Config
;
89 typedef struct backend_tag Backend
;
90 typedef struct terminal_tag Terminal
;
93 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
94 #define PUTTY_REG_PARENT "Software\\SimonTatham"
95 #define PUTTY_REG_PARENT_CHILD "PuTTY"
96 #define PUTTY_REG_GPARENT "Software"
97 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
99 #define PUTTY_HELP_FILE "putty.hlp"
100 #define PUTTY_HELP_CONTENTS "putty.cnt"
102 #define GETTICKCOUNT GetTickCount
103 #define CURSORBLINK GetCaretBlinkTime()
104 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
106 #define DEFAULT_CODEPAGE CP_ACP
111 * Window handles for the windows that can be running during a
114 GLOBAL HWND hwnd
; /* the main terminal window */
118 * The all-important instance handle.
120 GLOBAL HINSTANCE hinst
;
123 * Details of the help file.
125 GLOBAL
char *help_path
;
126 GLOBAL
int help_has_contents
;
127 GLOBAL
int requested_help
;
130 * The terminal and logging context are notionally local to the
131 * Windows front end, but they must be shared between window.c and
132 * windlg.c. Likewise the saved-sessions list.
134 GLOBAL Terminal
*term
;
137 #define WM_NETEVENT (WM_APP + 5)
140 * On Windows, we send MA_2CLK as the only event marking the second
141 * press of a mouse button. Compare unix.h.
143 #define MULTICLICK_ONLY_EVENT 1
146 * On Windows, data written to the clipboard must be NUL-terminated.
148 #define SELECTION_NUL_TERMINATED 1
151 * On Windows, copying to the clipboard terminates lines with CRLF.
153 #define SEL_NL { 13, 10 }
156 * sk_getxdmdata() does not exist under Windows (not that I
157 * couldn't write it if I wanted to, but I haven't bothered), so
158 * it's a macro which always returns NULL. With any luck this will
159 * cause the compiler to notice it can optimise away the
160 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
162 #define sk_getxdmdata(socket, lenp) (NULL)
165 * File-selector filter strings used in the config box. On Windows,
166 * these strings are of exactly the type needed to go in
167 * `lpstrFilter' in an OPENFILENAME structure.
169 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
170 "All Files (*.*)\0*\0\0\0")
171 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
172 "All Files (*.*)\0*\0\0\0")
175 * On some versions of Windows, it has been known for WM_TIMER to
176 * occasionally get its callback time simply wrong, and call us
177 * back several minutes early. Defining these symbols enables
178 * compensation code in timing.c.
181 #define TIMING_SYNC_TICKCOUNT
184 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
185 * what it can get, which means any WinSock routines used outside
186 * that module must be exported from it as function pointers. So
189 extern int (WINAPI
*p_WSAAsyncSelect
)
190 (SOCKET s
, HWND hWnd
, u_int wMsg
, long lEvent
);
191 extern int (WINAPI
*p_WSAEventSelect
)
192 (SOCKET s
, WSAEVENT hEventObject
, long lNetworkEvents
);
193 extern int (WINAPI
*p_select
)
194 (int nfds
, fd_set FAR
* readfds
, fd_set FAR
* writefds
,
195 fd_set FAR
*exceptfds
, const struct timeval FAR
* timeout
);
196 extern int (WINAPI
*p_WSAGetLastError
)(void);
197 extern int (WINAPI
*p_WSAEnumNetworkEvents
)
198 (SOCKET s
, WSAEVENT hEventObject
, LPWSANETWORKEVENTS lpNetworkEvents
);
200 extern int socket_writable(SOCKET skt
);
203 * Exports from winctrls.c.
212 int boxystart
, boxid
;
217 * Exports from winutils.c.
219 typedef struct filereq_tag filereq
; /* cwd for file requester */
220 BOOL
request_file(filereq
*state
, OPENFILENAME
*of
, int preserve
, int save
);
221 filereq
*filereq_new(void);
222 void filereq_free(filereq
*state
);
223 int message_box(LPCTSTR text
, LPCTSTR caption
, DWORD style
, DWORD helpctxid
);
224 void split_into_argv(char *, int *, char ***, char ***);
227 * Private structure for prefslist state. Only in the header file
228 * so that we can delegate allocation to callers.
231 int listid
, upbid
, dnbid
;
238 * This structure is passed to event handler functions as the `dlg'
239 * parameter, and hence is passed back to winctrls access functions.
242 HWND hwnd
; /* the hwnd of the dialog box */
243 struct winctrls
*controltrees
[8]; /* can have several of these */
245 char *wintitle
; /* title of actual window */
246 char *errtitle
; /* title of error sub-messageboxes */
247 void *data
; /* data to pass in refresh events */
248 union control
*focused
, *lastfocused
; /* which ctrl has focus now/before */
249 char shortcuts
[128]; /* track which shortcuts in use */
250 int coloursel_wanted
; /* has an event handler asked for
251 * a colour selector? */
252 struct { unsigned char r
, g
, b
, ok
; } coloursel_result
; /* 0-255 */
253 tree234
*privdata
; /* stores per-control private data */
254 int ended
, endresult
; /* has the dialog been ended? */
258 * Exports from winctrls.c.
260 void ctlposinit(struct ctlpos
*cp
, HWND hwnd
,
261 int leftborder
, int rightborder
, int topborder
);
262 HWND
doctl(struct ctlpos
*cp
, RECT r
,
263 char *wclass
, int wstyle
, int exstyle
, char *wtext
, int wid
);
264 void bartitle(struct ctlpos
*cp
, char *name
, int id
);
265 void beginbox(struct ctlpos
*cp
, char *name
, int idbox
);
266 void endbox(struct ctlpos
*cp
);
267 void editboxfw(struct ctlpos
*cp
, int password
, char *text
,
268 int staticid
, int editid
);
269 void radioline(struct ctlpos
*cp
, char *text
, int id
, int nacross
, ...);
270 void bareradioline(struct ctlpos
*cp
, int nacross
, ...);
271 void radiobig(struct ctlpos
*cp
, char *text
, int id
, ...);
272 void checkbox(struct ctlpos
*cp
, char *text
, int id
);
273 void statictext(struct ctlpos
*cp
, char *text
, int lines
, int id
);
274 void staticbtn(struct ctlpos
*cp
, char *stext
, int sid
,
275 char *btext
, int bid
);
276 void static2btn(struct ctlpos
*cp
, char *stext
, int sid
,
277 char *btext1
, int bid1
, char *btext2
, int bid2
);
278 void staticedit(struct ctlpos
*cp
, char *stext
,
279 int sid
, int eid
, int percentedit
);
280 void staticddl(struct ctlpos
*cp
, char *stext
,
281 int sid
, int lid
, int percentlist
);
282 void combobox(struct ctlpos
*cp
, char *text
, int staticid
, int listid
);
283 void staticpassedit(struct ctlpos
*cp
, char *stext
,
284 int sid
, int eid
, int percentedit
);
285 void bigeditctrl(struct ctlpos
*cp
, char *stext
,
286 int sid
, int eid
, int lines
);
287 void ersatztab(struct ctlpos
*cp
, char *stext
, int sid
, int lid
, int s2id
);
288 void editbutton(struct ctlpos
*cp
, char *stext
, int sid
,
289 int eid
, char *btext
, int bid
);
290 void sesssaver(struct ctlpos
*cp
, char *text
,
291 int staticid
, int editid
, int listid
, ...);
292 void envsetter(struct ctlpos
*cp
, char *stext
, int sid
,
293 char *e1stext
, int e1sid
, int e1id
,
294 char *e2stext
, int e2sid
, int e2id
,
295 int listid
, char *b1text
, int b1id
, char *b2text
, int b2id
);
296 void charclass(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
297 char *btext
, int bid
, int eid
, char *s2text
, int s2id
);
298 void colouredit(struct ctlpos
*cp
, char *stext
, int sid
, int listid
,
299 char *btext
, int bid
, ...);
300 void prefslist(struct prefslist
*hdl
, struct ctlpos
*cp
, int lines
,
301 char *stext
, int sid
, int listid
, int upbid
, int dnbid
);
302 int handle_prefslist(struct prefslist
*hdl
,
303 int *array
, int maxmemb
,
304 int is_dlmsg
, HWND hwnd
,
305 WPARAM wParam
, LPARAM lParam
);
306 void progressbar(struct ctlpos
*cp
, int id
);
307 void fwdsetter(struct ctlpos
*cp
, int listid
, char *stext
, int sid
,
308 char *e1stext
, int e1sid
, int e1id
,
309 char *e2stext
, int e2sid
, int e2id
,
310 char *btext
, int bid
,
311 char *r1text
, int r1id
, char *r2text
, int r2id
);
313 #define MAX_SHORTCUTS_PER_CTRL 16
316 * This structure is what's stored for each `union control' in the
317 * portable-dialog interface.
322 * The control may have several components at the Windows
323 * level, with different dialog IDs. To avoid needing N
324 * separate platformsidectrl structures (which could be stored
325 * separately in a tree234 so that lookup by ID worked), we
326 * impose the constraint that those IDs must be in a contiguous
332 * Remember what keyboard shortcuts were used by this control,
333 * so that when we remove it again we can take them out of the
334 * list in the dlgparam.
336 char shortcuts
[MAX_SHORTCUTS_PER_CTRL
];
338 * Some controls need a piece of allocated memory in which to
339 * store temporary data about the control.
344 * And this structure holds a set of the above, in two separate
345 * tree234s so that it can find an item by `union control' or by
349 tree234
*byctrl
, *byid
;
354 void winctrl_init(struct winctrls
*);
355 void winctrl_cleanup(struct winctrls
*);
356 void winctrl_add(struct winctrls
*, struct winctrl
*);
357 void winctrl_remove(struct winctrls
*, struct winctrl
*);
358 struct winctrl
*winctrl_findbyctrl(struct winctrls
*, union control
*);
359 struct winctrl
*winctrl_findbyid(struct winctrls
*, int);
360 struct winctrl
*winctrl_findbyindex(struct winctrls
*, int);
361 void winctrl_layout(struct dlgparam
*dp
, struct winctrls
*wc
,
362 struct ctlpos
*cp
, struct controlset
*s
, int *id
);
363 int winctrl_handle_command(struct dlgparam
*dp
, UINT msg
,
364 WPARAM wParam
, LPARAM lParam
);
365 void winctrl_rem_shortcuts(struct dlgparam
*dp
, struct winctrl
*c
);
366 int winctrl_context_help(struct dlgparam
*dp
, HWND hwnd
, int id
);
368 void dp_init(struct dlgparam
*dp
);
369 void dp_add_tree(struct dlgparam
*dp
, struct winctrls
*tree
);
370 void dp_cleanup(struct dlgparam
*dp
);
373 * Exports from wincfg.c.
375 void win_setup_config_box(struct controlbox
*b
, HWND
*hwndp
, int has_help
,
376 int midsession
, int protocol
);
379 * Exports from windlg.c.
381 void defuse_showwindow(void);
383 int do_reconfig(HWND
, int);
384 void showeventlog(HWND
);
385 void showabout(HWND
);
386 void force_normal(HWND hwnd
);
387 void modal_about_box(HWND hwnd
);
388 void show_help(HWND hwnd
);
391 * Exports from winmisc.c.
393 extern OSVERSIONINFO osVersion
;
394 BOOL
init_winver(void);
397 * Exports from sizetip.c.
399 void UpdateSizeTip(HWND src
, int cx
, int cy
);
400 void EnableSizeTip(int bEnable
);
403 * Exports from unicode.c.
406 void init_ucs(Config
*, struct unicode_data
*);
409 * Exports from winhandl.c.
411 #define HANDLE_FLAG_OVERLAPPED 1
412 #define HANDLE_FLAG_IGNOREEOF 2
413 #define HANDLE_FLAG_UNITBUFFER 4
415 typedef int (*handle_inputfn_t
)(struct handle
*h
, void *data
, int len
);
416 typedef void (*handle_outputfn_t
)(struct handle
*h
, int new_backlog
);
417 struct handle
*handle_input_new(HANDLE handle
, handle_inputfn_t gotdata
,
418 void *privdata
, int flags
);
419 struct handle
*handle_output_new(HANDLE handle
, handle_outputfn_t sentdata
,
420 void *privdata
, int flags
);
421 int handle_write(struct handle
*h
, const void *data
, int len
);
422 HANDLE
*handle_get_events(int *nevents
);
423 void handle_free(struct handle
*h
);
424 void handle_got_event(HANDLE event
);
425 void handle_unthrottle(struct handle
*h
, int backlog
);
426 int handle_backlog(struct handle
*h
);
427 void *handle_get_privdata(struct handle
*h
);
430 * pageantc.c needs to schedule callbacks for asynchronous agent
431 * requests. This has to be done differently in GUI and console, so
432 * there's an exported function used for the purpose.
434 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
435 * synchronous in pscp and psftp.
437 void agent_schedule_callback(void (*callback
)(void *, void *, int),
438 void *callback_ctx
, void *data
, int len
);
439 #define FLAG_SYNCAGENT 0x1000
442 * Exports from winser.c.
444 extern Backend serial_backend
;