2 * ========================================================================
3 * Copyright 2006-2008 University of Washington
4 * Copyright 2013-2021 Eduardo Chappa
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
18 #include "../../c-client/mail.h" /* for MAILSTREAM and friends */
19 #include "../../c-client/osdep.h"
20 #include "../../c-client/rfc822.h" /* for soutr_t and such */
21 #include "../../c-client/misc.h" /* for cpystr proto */
22 #include "../../c-client/utf8.h" /* for CHARSET and such*/
23 #include "../../c-client/imap4r1.h"
25 #include "../../pith/charconv/utf8.h"
26 #include "../../pith/charconv/filesys.h"
28 #include "../../pith/osdep/color.h"
30 #include "../../pith/debug.h"
31 #include "../../pith/state.h"
32 #include "../../pith/conf.h"
33 #include "../../pith/detach.h"
35 #include "../pico/estruct.h"
36 #include "../pico/pico.h"
38 #include "../../pico/osdep/raw.h"
39 #include "../../pico/osdep/signals.h"
40 #include "../../pico/osdep/mouse.h"
41 #include "../../pico/keydefs.h"
45 #include "../dispfilt.h"
46 #include "../signal.h"
47 #include "../status.h"
48 #include "../titlebar.h"
50 #include "../../pico/osdep/mswin.h"
52 #include "termin.gen.h"
53 #include "termin.wnt.h"
54 #include "termout.gen.h"
56 #define RETURN_CH(X) return(key_rec ? ((*key_rec)(X)) : (int)(X))
58 /* global to tell us if the window was resized. */
59 static int DidResize
= FALSE
;
61 int pine_window_resize_callback(void);
63 /*----------------------------------------------------------------------
64 Initialize the tty driver to do single char I/O and whatever else
68 Result: tty driver is put in raw mode
69 ----------------------------------------------------------------------*/
71 init_tty_driver(struct pine
*pine
)
74 mswin_setresizecallback (pine_window_resize_callback
);
75 init_mouse (); /* always a mouse under windows? */
80 /*----------------------------------------------------------------------
81 End use of the tty, put it back into it's normal mode
85 Result: tty driver mode change
86 ----------------------------------------------------------------------*/
88 end_tty_driver(struct pine
*pine
)
90 dprint((2, "about to end_tty_driver\n"));
91 mswin_clearresizecallback (pine_window_resize_callback
);
94 /*----------------------------------------------------------------------
95 Actually set up the tty driver
97 Args: state -- which state to put it in. 1 means go into raw, 0 out of
99 Result: returns 0 if successful and -1 if not.
105 ps_global
->low_speed
= 0;
109 /*----------------------------------------------------------------------
110 Read input characters with lots of processing for arrow keys and such
114 Result: returns the character read. Possible special chars defined h file
117 This deals with function and arrow keys as well.
118 It returns ^T for up , ^U for down, ^V for forward and ^W for back.
119 These are just sort of arbitrarily picked and might be changed.
120 They are defined in defs.h. Didn't want to use 8 bit chars because
121 the values are signed chars, though it ought to work with negative
124 The idea is that this routine handles all escape codes so it done in
125 only one place. Especially so the back arrow key can work when entering
126 things on a line. Also so all function keys can be broken and not
127 cause weird things to happen.
128 ----------------------------------------------------------------------*/
137 key_rec
= key_recorder
;
138 if(ps_global
->conceal_sensitive_debugging
&& debug
< 10)
141 if(process_config_input((int *) &ch
))
146 fix_windsize(ps_global
);
150 mswin_setcursor(MSWIN_CURSOR_ARROW
);
154 /* mswin_charavail() Yields control to other window apps. */
155 while (!mswin_charavail()) {
156 if(time(0L) >= timein
+ (time_t) tm
){
157 ch
= (tm
< IDLE_TIMEOUT
) ? NO_OP_COMMAND
: NO_OP_IDLE
;
162 fix_windsize(ps_global
);
165 if(checkmouse(&ch
,0,0,0))
170 while(!mswin_charavail())
171 if(checkmouse(&ch
,0,0,0))
174 ch
= mswin_getc_fast();
177 * mswin_getc_fast() returns UCS type codes (see keydefs.h). Map
178 * those values to what is expected from read_char(): Ctrl keys being
179 * in the 0..0x1f range, NO_OP_COMMAND, etc.
186 if(ch
>= '@' && ch
< '@' + 32) {
191 * This could be a ctrl key this part of Pine doesn't understand.
192 * For example, CTRL|KEY_LEFT. Map these to nops.
199 /* More obtuse key mapping. If it is a mouse event, the return
200 * may be KEY_MOUSE, which indicates to the upper layer that it
201 * is a mouse event. Return it here to avoid the code that
202 * follows which would do a (ch & 0xff).
208 * WARNING: Hack notice.
209 * the mouse interaction complicates this expression a bit as
210 * if function key mode is set, PFn values are setup for return
211 * by the mouse event catcher. For now, just special case them
212 * since they don't conflict with any of the DOS special keys.
214 if((ch
& 0xff) == ctrl('Z'))
215 RETURN_CH(do_suspend());
227 init_keyboard(int use_fkeys
)
232 end_keyboard(int use_fkeys
)
237 pre_screen_config_opt_enter(char *utf8string
, int utf8string_size
,
238 char *utf8prompt
, ESCKEY_S
*escape_list
,
239 HelpType help
, int *flags
)
241 mswin_setwindow(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
242 return(win_dialog_opt_enter(utf8string
, utf8string_size
, utf8prompt
, escape_list
,
247 win_dialog_opt_enter(char *utf8string
, int utf8string_size
, char *utf8prompt
,
248 ESCKEY_S
*escape_list
, HelpType help
, int *flags
)
250 MDlgButton button_list
[12];
251 LPTSTR free_names
[12];
252 LPTSTR free_labels
[12];
255 char *utf8
, *saved_string
= NULL
;
256 UCS
*string
, *s
, *prompt
;
259 memset(&free_names
, 0, sizeof(LPTSTR
) * 12);
260 memset(&free_labels
, 0, sizeof(LPTSTR
) * 12);
261 memset (&button_list
, 0, sizeof (MDlgButton
) * 12);
263 for (i
= 0; escape_list
&& escape_list
[i
].ch
!= -1 && i
< 11; ++i
) {
264 if (escape_list
[i
].name
!= NULL
265 && escape_list
[i
].ch
> 0 && escape_list
[i
].ch
< 256) {
266 button_list
[b
].ch
= escape_list
[i
].ch
;
267 button_list
[b
].rval
= escape_list
[i
].rval
;
268 free_names
[b
] = utf8_to_lptstr(escape_list
[i
].name
);
269 button_list
[b
].name
= free_names
[b
];
270 free_labels
[b
] = utf8_to_lptstr(escape_list
[i
].label
);
271 button_list
[b
].label
= free_labels
[b
];
276 button_list
[b
].ch
= -1;
279 saved_string
= cpystr(utf8string
);
281 /* assumption here is that HelpType is char ** */
285 string
= (UCS
*) fs_get(n
* sizeof(UCS
));
286 s
= utf8_to_ucs4_cpystr(utf8string
);
288 ucs4_strncpy(string
, s
, n
);
290 fs_give((void **) &s
);
293 prompt
= utf8_to_ucs4_cpystr(utf8prompt
? utf8prompt
: "");
295 return_v
= mswin_dialog(prompt
, string
, n
,
296 (flags
&& *flags
& OE_APPEND_CURRENT
),
297 (flags
&& *flags
& OE_PASSWD_NOAST
) ? 10 :
298 (flags
&& *flags
& OE_PASSWD
) ? 1 : 0,
300 help_text
, flags
? *flags
: OE_NONE
);
302 for(i
= 0; i
< 12; i
++){
304 fs_give((void **) &free_names
[i
]);
306 fs_give((void **) &free_labels
[i
]);
309 utf8
= ucs4_to_utf8_cpystr(string
);
311 strncpy(utf8string
, utf8
, utf8string_size
);
312 utf8string
[utf8string_size
-1] = '\0';
313 fs_give((void **) &utf8
);
317 fs_give((void **) &string
);
320 fs_give((void **) &prompt
);
322 if(flags
&& (saved_string
&& !utf8string
|| !saved_string
&& utf8string
||
323 (saved_string
&& string
&& strcmp(saved_string
, utf8string
))))
324 *flags
|= OE_USER_MODIFIED
;
327 fs_give((void **) &saved_string
);
333 /*----------------------------------------------------------------------
334 Flag the fact the window has resized.
337 pine_window_resize_callback (void)