1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: termout.unx.c 159 2006-10-02 22:00:13Z hubert@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006-2007 University of Washington
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
20
#include "../../c-client/mail.h" /* for MAILSTREAM and friends */
21
#include "../../c-client/osdep.h"
22
#include "../../c-client/rfc822.h" /* for soutr_t and such */
23
#include "../../c-client/misc.h" /* for cpystr proto */
24
#include "../../c-client/utf8.h" /* for CHARSET and such*/
25
#include "../../c-client/imap4r1.h"
27
#include "../../pith/osdep/color.h"
29
#include "../../pith/charconv/filesys.h"
31
#include "../../pith/debug.h"
32
#include "../../pith/conf.h"
33
#include "../../pith/newmail.h"
35
#include "../../pico/estruct.h"
36
#include "../../pico/pico.h"
37
#include "../../pico/keydefs.h"
39
#include "../../pico/osdep/mswin.h"
41
#include "../flagmaint.h"
43
#include "termout.wnt.h"
45
/*======================================================================
46
Routines for painting the screen
47
- figure out what the terminal type is
48
- deal with screen size changes
49
- save special output sequences
50
- the usual screen clearing, cursor addressing and scrolling
53
This library gives programs the ability to easily access the
54
termcap information and write screen oriented and raw input
55
programs. The routines can be called as needed, except that
56
to use the cursor / screen routines there must be a call to
57
InitScreen() first. The 'Raw' input routine can be used
58
independently, however. (Elm comment)
60
Not sure what the original source of this code was. It got to be
61
here as part of ELM. It has been changed significantly from the
62
ELM version to be more robust in the face of inconsistent terminal
63
autowrap behaviour. Also, the unused functions were removed, it was
64
made to pay attention to the window size, and some code was made nicer
65
(in my opinion anyways). It also outputs the terminal initialization
66
strings and provides for minimal scrolling and detects terminals
67
with out enough capabilities. (Pine comment, 1990)
71
#define PUTLINE_BUFLEN 256
73
static int _lines, _columns;
75
int config_screen(struct ttyo **);
77
BOOL CALLBACK __export
78
args_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
80
BOOL CALLBACK __export
81
login_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
83
BOOL CALLBACK __export
84
flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
86
BOOL CALLBACK __export
87
sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
89
BOOL CALLBACK __export
90
config_vars_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
92
BOOL CALLBACK __export
93
config_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
99
* If we want to show it, turn it on. If we don't care, put it back
100
* to the way it was originally.
102
mswin_showcaret(F_ON(F_SHOW_CURSOR, ps_global));
103
mswin_trayicon(F_ON(F_ENABLE_TRAYICON, ps_global));
108
end_screen(char *message, int exit_val)
110
int footer_rows_was_one = 0;
115
if(FOOTER_ROWS(ps_global) == 1){
116
footer_rows_was_one++;
117
FOOTER_ROWS(ps_global) = 3;
118
mark_status_unknown();
121
flush_status_messages(exit_val ? 0 : 1);
123
blank_keymenu(_lines - 2, 0);
127
PutLine0(_lines - 2, 0, message);
132
MoveCursor(_lines - 1, 0);
134
mswin_showcaret(F_ON(F_SHOW_CURSOR, ps_global));
136
if(footer_rows_was_one){
137
FOOTER_ROWS(ps_global) = 1;
138
mark_status_unknown();
142
/*----------------------------------------------------------------------
143
Initialize the screen for output, set terminal type, etc
145
Args: tt -- Pointer to variable to store the tty output structure.
147
Result: terminal size is discovered and set pine state
148
termcap entry is fetched and stored in local variables
149
make sure terminal has adequate capabilites
150
evaluate scrolling situation
151
returns status of indicating the state of the screen/termcap entry
154
-1 indicating no terminal name associated with this shell,
155
-2..-n No termcap for this terminal type known
156
-3 Can't open termcap file
157
-4 Terminal not powerful enough - missing clear to eoln or screen
162
config_screen(struct ttyo **tt)
166
_line = 0; /* where are we right now?? */
167
_col = 0; /* assume zero, zero... */
169
mswin_getscreensize(&_lines, &_columns);
170
if (_lines > MAX_SCREEN_ROWS)
171
_lines = MAX_SCREEN_ROWS;
172
if (_columns > MAX_SCREEN_COLS)
173
_columns = MAX_SCREEN_COLS;
175
ttyo = (struct ttyo *)fs_get(sizeof(struct ttyo));
176
ttyo->screen_cols = _columns;
177
ttyo->screen_rows = _lines ;
178
ttyo->header_rows = 2;
179
ttyo->footer_rows = 3;
186
/*----------------------------------------------------------------------
187
Get the current window size
189
Args: ttyo -- pointer to structure to store window size in
191
NOTE: we don't override the given values unless we know better
194
get_windsize(struct ttyo *ttyo)
196
char fontName[LF_FACESIZE+1];
199
char fontCharSet[256];
200
char windowPosition[32], windowPositionReg[32];
201
char foreColor[64], backColor[64];
202
int newRows, newCols;
203
char cursorStyle[32];
205
cursorStyle[0] = '\0';
207
/* Get the new window parameters and update the 'pinerc' variables. */
208
mswin_getwindow(fontName, sizeof(fontName), fontSize, sizeof(fontSize),
209
fontStyle, sizeof(fontStyle),
210
windowPosition, sizeof(windowPosition),
211
foreColor, sizeof(foreColor),
212
backColor, sizeof(backColor),
213
cursorStyle, sizeof(cursorStyle),
214
fontCharSet, sizeof(fontCharSet));
216
if(!ps_global->VAR_FONT_NAME
217
|| strucmp(ps_global->VAR_FONT_NAME, fontName))
218
set_variable(V_FONT_NAME, fontName, 1, 0,
219
ps_global->ew_for_except_vars);
221
if(!ps_global->VAR_FONT_SIZE
222
|| strucmp(ps_global->VAR_FONT_SIZE, fontSize))
223
set_variable(V_FONT_SIZE, fontSize, 1, 0,
224
ps_global->ew_for_except_vars);
226
if(!ps_global->VAR_FONT_STYLE
227
|| strucmp(ps_global->VAR_FONT_STYLE, fontStyle))
228
set_variable(V_FONT_STYLE, fontStyle, 1, 0,
229
ps_global->ew_for_except_vars);
231
if(!ps_global->VAR_FONT_CHAR_SET
232
|| strucmp(ps_global->VAR_FONT_CHAR_SET, fontCharSet))
233
set_variable(V_FONT_CHAR_SET, fontCharSet, 1, 0,
234
ps_global->ew_for_except_vars);
236
if(F_ON(F_STORE_WINPOS_IN_CONFIG, ps_global)){
237
if(!ps_global->VAR_WINDOW_POSITION
238
|| strucmp(ps_global->VAR_WINDOW_POSITION, windowPosition))
239
set_variable(V_WINDOW_POSITION, windowPosition, 1, 0,
240
ps_global->ew_for_except_vars);
244
* Get the window position stored in the registry.
246
* If current window position is not in the registry or is
247
* different from what is there, save it.
249
if(strnicmp(windowPosition, "MIN0", 4)
250
&& (!mswin_reg(MSWR_OP_GET, MSWR_PINE_POS, windowPositionReg,
251
sizeof(windowPositionReg)) ||
252
strucmp(windowPositionReg, windowPosition))
253
&& (ps_global->update_registry != UREG_NEVER_SET))
254
mswin_reg(MSWR_OP_SET | MSWR_OP_FORCE, MSWR_PINE_POS, windowPosition,
258
mswin_getprintfont(fontName, sizeof(fontName),
259
fontSize, sizeof(fontSize),
260
fontStyle, sizeof(fontStyle),
261
fontCharSet, sizeof(fontCharSet));
262
if(!ps_global->VAR_PRINT_FONT_NAME
263
|| strucmp(ps_global->VAR_PRINT_FONT_NAME, fontName))
264
set_variable(V_PRINT_FONT_NAME, fontName, 1, 0,
265
ps_global->ew_for_except_vars);
267
if(!ps_global->VAR_PRINT_FONT_SIZE
268
|| strucmp(ps_global->VAR_PRINT_FONT_SIZE, fontSize))
269
set_variable(V_PRINT_FONT_SIZE, fontSize, 1, 0,
270
ps_global->ew_for_except_vars);
272
if(!ps_global->VAR_PRINT_FONT_STYLE
273
|| strucmp(ps_global->VAR_PRINT_FONT_STYLE, fontStyle))
274
set_variable(V_PRINT_FONT_STYLE, fontStyle, 1, 0,
275
ps_global->ew_for_except_vars);
277
if(!ps_global->VAR_PRINT_FONT_CHAR_SET
278
|| strucmp(ps_global->VAR_PRINT_FONT_CHAR_SET, fontCharSet))
279
set_variable(V_PRINT_FONT_CHAR_SET, fontCharSet, 1, 0,
280
ps_global->ew_for_except_vars);
282
if(!ps_global->VAR_NORM_FORE_COLOR
283
|| strucmp(ps_global->VAR_NORM_FORE_COLOR, foreColor))
284
set_variable(V_NORM_FORE_COLOR, foreColor, 1, 0,
285
ps_global->ew_for_except_vars);
287
if(!ps_global->VAR_NORM_BACK_COLOR
288
|| strucmp(ps_global->VAR_NORM_BACK_COLOR, backColor))
289
set_variable(V_NORM_BACK_COLOR, backColor, 1, 0,
290
ps_global->ew_for_except_vars);
292
if(cursorStyle[0] && !ps_global->VAR_CURSOR_STYLE
293
|| strucmp(ps_global->VAR_CURSOR_STYLE, cursorStyle))
294
set_variable(V_CURSOR_STYLE, cursorStyle, 1, 0,
295
ps_global->ew_for_except_vars);
297
/* Get new window size. Compare to old. The window may have just
298
* moved, in which case we don't bother updating the size. */
299
mswin_getscreensize(&newRows, &newCols);
300
if (newRows == ttyo->screen_rows && newCols == ttyo->screen_cols)
301
return (NO_OP_COMMAND);
304
ttyo->screen_rows = newRows;
305
ttyo->screen_cols = newCols;
307
if (ttyo->screen_rows > MAX_SCREEN_ROWS)
308
ttyo->screen_rows = MAX_SCREEN_ROWS;
309
if (ttyo->screen_cols > MAX_SCREEN_COLS)
310
ttyo->screen_cols = MAX_SCREEN_COLS;
315
/*----------------------------------------------------------------------
316
Move the cursor to the row and column number
321
internal position updated
322
----------------------------------------------------------------------*/
324
MoveCursor(int row, int col)
326
/** move cursor to the specified row column on the screen.
327
0,0 is the top left! **/
329
if(ps_global->in_init_seq)
333
* This little hack is here for screen readers, for example, a screen
334
* reader associated with a braille display. If we flash the cursor off
335
* and on in the same position, the reader will be drawn to it. Since we
336
* are calling MoveCursor every time through the message viewing loops we
337
* need to suppress the calls if they aren't really doing anything.
338
* However, mswin_move actually does more than just move the cursor.
339
* It also call FlushAccum(), which is necessary in some cases. For
340
* example, in optionally_enter the user is typing characters in and
341
* the FlushAccum() allows them to show up on the screen. The putblock
342
* call is a quick hack to get the Flush_Accum() call, which is all
343
* the putblock does when the arg is NULL.
345
if(row == _line && col == _col){
346
mswin_putblock(NULL, 0);
350
mswin_move(row, col);
356
/*----------------------------------------------------------------------
357
Write a character to the screen, keeping track of cursor position
359
Input: charater to write
361
Result: character output
362
cursor position variables updated
363
----------------------------------------------------------------------*/
369
if(ps_global->in_init_seq)
374
_line = min(_line+1,ps_global->ttyo->screen_rows);
376
mswin_move(_line, _col);
379
case RETURN : /* move to column 0 */
381
mswin_move(_line, _col);
383
case BACKSPACE : /* move back a space if not in column 0 */
385
mswin_move(_line, --_col);
389
case BELL : /* ring the bell but don't advance _col */
390
mswin_beep(); /* libpico call */
393
case TAB: /* if a tab, output it */
396
while(((++_col)&0x07) != 0);
400
/* pass_ctrl_chars is always 1 for Windows */
401
width = wcellwidth(ucs);
405
if(_col + width > ps_global->ttyo->screen_cols){
407
if(_line + 1 < ps_global->ttyo->screen_rows)
409
mswin_move(_line, _col);
416
if(_col == ps_global->ttyo->screen_cols) {
418
if(_line + 1 < ps_global->ttyo->screen_rows)
421
mswin_move(_line, _col);
428
/*----------------------------------------------------------------------
429
Printf style write directly to the terminal at current position
431
Input: printf style control string
432
number of printf style arguments
433
up to three printf style arguments
435
Result: Line written to the screen
436
----------------------------------------------------------------------*/
438
Write_to_screen(char *string)
440
if(ps_global->in_init_seq)
446
* mswin_puts does not keep track of where we are. Simple fix is to
447
* reset _line and _col to unknown so that the next MoveCursor will
448
* do a real move. We could check for a simple string and actually
449
* keep track. Is that useful? I don't think so.
451
* There are other places where we lose track, but by comparing with
452
* the termout.unx code where we also lose track it would seem we don't
453
* really need to keep track in those other cases.
460
Write_to_screen_n(char *string, int n)
462
if(ps_global->in_init_seq)
465
mswin_puts_n (string, n);
471
/*----------------------------------------------------------------------
472
Clear the terminal screen
473
----------------------------------------------------------------------*/
477
_line = 0; /* clear leaves us at top... */
480
if(ps_global->in_init_seq)
483
mark_status_unknown();
484
mark_keymenu_dirty();
485
mark_titlebar_dirty();
491
/*----------------------------------------------------------------------
492
Clear screen to end of line on current line
493
----------------------------------------------------------------------*/
501
/*----------------------------------------------------------------------
502
function to output string such that it becomes icon text
504
Args: s -- string to write
506
Result: string indicated become our "icon" text
509
icon_text(char *s, int type)
511
if(type == IT_MCLOSED)
512
mswin_mclosedtext (s);
513
else /* IT_NEWMAIL */
514
mswin_newmailtext (s);
520
* Set the current position of the scroll bar.
523
scroll_setpos(long newpos)
525
mswin_setscrollpos (newpos);
529
* Set the range of the scroll bar.
530
* zero disables the scroll bar.
533
scroll_setrange (long pagelen, long rangeend)
535
if(rangeend < pagelen)
536
mswin_setscrollrange (0L, 0L);
538
mswin_setscrollrange (pagelen, rangeend + pagelen - 1L);
547
ScrollRegion(int lines)
553
BeginScroll(int top, int bottom)
564
#define WINDOW_USER_DATA GWL_USERDATA
566
/*===========================================================================
570
* The following structures hold the state data for dialogs.
572
typedef struct DLG_TYPEMAP {
577
typedef struct DLG_SORTDATA {
578
DLG_SORTPARAM *sortsel; /* parameter structure. */
579
int sortcount; /* Number of different sorts. */
580
DLG_TYPEMAP types[20]; /* Map pine sort types to ctrl ids. */
583
typedef struct DLG_LOGINDATA {
589
int pwc; /* set if we're using passfiles and we don't know user yet */
591
int prespass; /* if user wants to preserve the password */
595
typedef struct DLG_CONFIGDATA {
596
char *confpath; /* UTF-8 path */
603
typedef struct installvars {
609
unsigned defmailclient:1;
610
unsigned defnewsclient:1;
613
typedef struct DLG_CONGIGVARSDATA {
614
INSTALLVARS_S *ivars;
616
} DLG_CONFIGVARSDATA;
618
typedef struct DLG_FLAGDATA {
619
struct flag_table *ftbl;
625
int os_config_vars_dialog(INSTALLVARS_S *);
626
static void GetBtnPos (HWND, HWND, RECT *);
629
init_install_get_vars(void)
632
struct pine *ps = ps_global;
635
memset((void *)&ivars, 0, sizeof(INSTALLVARS_S));
636
if(ps->vars[V_PERSONAL_NAME].main_user_val.p)
637
ivars.pname = cpystr(ps->vars[V_PERSONAL_NAME].main_user_val.p);
638
if(ps->vars[V_USER_ID].main_user_val.p)
639
ivars.userid = cpystr(ps->vars[V_USER_ID].main_user_val.p);
640
if(ps->vars[V_USER_DOMAIN].main_user_val.p)
641
ivars.domain = cpystr(ps->vars[V_USER_DOMAIN].main_user_val.p);
642
if(ps->vars[V_INBOX_PATH].main_user_val.p)
643
ivars.inboxpath = cpystr(ps->vars[V_INBOX_PATH].main_user_val.p);
644
else if(ps->prc && ps->prc->name && (*ps->prc->name == '{')
645
&& (p = strindex(ps->prc->name, '}'))){
646
ivars.inboxpath = cpystr(ps->prc->name);
647
if(p = strindex(ivars.inboxpath, '}'))
650
if(ps->vars[V_SMTP_SERVER].main_user_val.l
651
&& *ps->vars[V_SMTP_SERVER].main_user_val.l)
652
ivars.smtpserver = cpystr(ps->vars[V_SMTP_SERVER].main_user_val.l[0]);
653
ivars.defmailclient = mswin_is_def_client(MSWR_SDC_MAIL);
654
ivars.defnewsclient = mswin_is_def_client(MSWR_SDC_NEWS);
656
if(os_config_vars_dialog(&ivars) == 0){
657
set_variable(V_PERSONAL_NAME, ivars.pname, 0, 0, Main);
658
set_variable(V_USER_ID, ivars.userid, 0, 0, Main);
659
set_variable(V_USER_DOMAIN, ivars.domain, 0, 0, Main);
660
set_variable(V_INBOX_PATH, ivars.inboxpath, 0, 0, Main);
661
if(ivars.smtpserver){
662
if(ps->vars[V_SMTP_SERVER].main_user_val.l){
663
fs_give((void **)&ps->vars[V_SMTP_SERVER].main_user_val.l[0]);
664
ps->vars[V_SMTP_SERVER].main_user_val.l[0]
665
= cpystr(ivars.smtpserver);
666
set_current_val(&ps->vars[V_SMTP_SERVER], TRUE, FALSE);
671
tstrlist[0] = ivars.smtpserver;
673
set_variable_list(V_SMTP_SERVER, tstrlist, 0, Main);
676
write_pinerc(ps_global, Main, WRP_NONE);
677
if(ivars.defmailclient)
678
mswin_set_def_client(MSWR_SDC_MAIL);
679
if(ivars.defnewsclient)
680
mswin_set_def_client(MSWR_SDC_NEWS);
682
/* Tell Windows that stuff has changed */
683
if(ivars.defmailclient || ivars.defnewsclient)
684
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
685
(WPARAM)NULL, (LPARAM)NULL,
686
SMTO_NORMAL, 1000, NULL);
690
fs_give((void **)&ivars.pname);
692
fs_give((void **)&ivars.userid);
694
fs_give((void **)&ivars.domain);
696
fs_give((void **)&ivars.inboxpath);
698
fs_give((void **)&ivars.smtpserver);
706
os_argsdialog (char **arg_text)
712
hInst = (HINSTANCE) mswin_gethinstance ();
713
hWnd = (HWND) mswin_gethwnd ();
717
dlgprc = args_dialog_proc;
719
DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_ARGLIST), hWnd,
720
dlgprc, (LPARAM) arg_text);
726
* Prompt for username and password
729
os_login_dialog (NETMBX *mb, char *user_utf8, int userlen,
730
char *pwd_utf8, int pwdlen, int pwc, int fixuser, int *prespass)
737
LPTSTR user_lptstr, pwd_lptstr;
738
char *tuser_utf8, *tpwd_utf8;
741
hInst = (HINSTANCE) mswin_gethinstance ();
742
hWnd = (HWND) mswin_gethwnd ();
746
dlgpw.user = (LPTSTR)fs_get(userlen*sizeof(TCHAR));
747
user_lptstr = utf8_to_lptstr(user_utf8);
748
_tcsncpy(dlgpw.user, user_lptstr, userlen - 1);
749
dlgpw.user[userlen - 1] = '\0';
750
fs_give((void **) &user_lptstr);
751
dlgpw.userlen = userlen;
753
dlgpw.pwd = (LPTSTR)fs_get(pwdlen*sizeof(TCHAR));
754
pwd_lptstr = utf8_to_lptstr(pwd_utf8);
755
_tcsncpy(dlgpw.pwd, pwd_lptstr, pwdlen - 1);
756
dlgpw.pwd[pwdlen - 1] = '\0';
757
fs_give((void **) &pwd_lptstr);
758
dlgpw.pwdlen = pwdlen;
760
dlgpw.fixuser = fixuser;
764
dlgprc = login_dialog_proc;
766
DialogBoxParam (hInst, MAKEINTRESOURCE (ps_global->install_flag
767
? IDD_LOGINDLG2 : IDD_LOGINDLG),
768
NULL, dlgprc, (LPARAM)&dlgpw);
771
tuser_utf8 = lptstr_to_utf8(dlgpw.user);
773
strncpy(user_utf8, tuser_utf8, userlen - 1);
774
user_utf8[userlen - 1] = '\0';
775
fs_give((void **) &tuser_utf8);
778
tpwd_utf8 = lptstr_to_utf8(dlgpw.pwd);
780
strncpy(pwd_utf8, tpwd_utf8, pwdlen - 1);
781
pwd_utf8[pwdlen - 1] = '\0';
782
fs_give((void **) &tpwd_utf8);
785
(*prespass) = dlgpw.prespass;
792
* Select message flags.
795
os_flagmsgdialog (struct flag_table *ftbl)
801
DLG_FLAGDATA dlgflag;
804
hInst = (HINSTANCE) mswin_gethinstance ();
805
hWnd = (HWND) mswin_gethwnd ();
808
dlgflag.hInstance = hInst;
809
dlgflag.hTextWnd = hWnd;
811
dlgprc = flag_dialog_proc;
813
rval = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTFLAG), hWnd,
814
dlgprc, (LPARAM)&dlgflag);
820
* Select a sort type.
824
os_sortdialog (DLG_SORTPARAM *sortsel)
830
DLG_SORTDATA dlgsort;
832
hInst = (HINSTANCE) mswin_gethinstance ();
833
hWnd = (HWND) mswin_gethwnd ();
836
/* Build a map of pine sort types to the resource types. */
838
dlgsort.types[i].pineid = SortArrival;
839
dlgsort.types[i++].rsrcid = IDC_SORTARRIVAL;
840
dlgsort.types[i].pineid = SortDate;
841
dlgsort.types[i++].rsrcid = IDC_SORTDATE;
842
dlgsort.types[i].pineid = SortFrom;
843
dlgsort.types[i++].rsrcid = IDC_SORTFROM;
844
dlgsort.types[i].pineid = SortSubject;
845
dlgsort.types[i++].rsrcid = IDC_SORTSUBJECT;
846
dlgsort.types[i].pineid = SortSubject2;
847
dlgsort.types[i++].rsrcid = IDC_SORTORDERSUB;
848
dlgsort.types[i].pineid = SortTo;
849
dlgsort.types[i++].rsrcid = IDC_SORTTO;
850
dlgsort.types[i].pineid = SortCc;
851
dlgsort.types[i++].rsrcid = IDC_SORTCC;
852
dlgsort.types[i].pineid = SortSize;
853
dlgsort.types[i++].rsrcid = IDC_SORTSIZE;
854
dlgsort.types[i].pineid = SortThread;
855
dlgsort.types[i++].rsrcid = IDC_SORTTHREAD;
856
dlgsort.types[i].pineid = SortScore;
857
dlgsort.types[i++].rsrcid = IDC_SORTSCORE;
858
dlgsort.sortcount = i;
859
dlgsort.sortsel = sortsel;
861
dlgprc = sort_dialog_proc;
863
DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_SELECTSORT), hWnd,
864
dlgprc, (LPARAM)&dlgsort);
871
* Dialog proc to handle index sort selection.
873
* Configures the dialog box on init and retrieves the settings on exit.
875
BOOL CALLBACK __export
876
args_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
879
long i, j, block_size;
881
LPTSTR args_text_lptstr, args_block_lptstr;
887
args_text = (char **)lParam;
890
* First convert char *'s over to one big block of
894
while(args_text && *args_text){
895
i += strlen(*args_text++);
900
args_block_lptstr = (LPTSTR)fs_get((block_size+1)*sizeof(TCHAR));
902
args_text = (char **)lParam;
905
while(args_text && *args_text){
906
args_text_lptstr = utf8_to_lptstr(*args_text++);
907
while(args_text_lptstr[i] && j < block_size){
908
args_block_lptstr[j++] = args_text_lptstr[i++];
910
args_block_lptstr[j++] = '\r';
911
args_block_lptstr[j++] = '\n';
912
fs_give((void **) &args_text_lptstr);
915
args_block_lptstr[j] = '\0';
917
/* and replace everything selected with args_text */
918
SendDlgItemMessage(hDlg, IDC_ARGTEXT, WM_SETTEXT, (WPARAM) 0,
919
(LPARAM) args_block_lptstr);
920
fs_give((void **)&args_block_lptstr);
926
EndDialog (hDlg, TRUE);
934
EndDialog (hDlg, TRUE);
945
* Dialog proc to handle login
947
* Configures the dialog box on init and retrieves the settings on exit.
949
BOOL CALLBACK __export
950
login_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
952
DLG_LOGINDATA *dlglogin;
962
dlglogin = (DLG_LOGINDATA *)lParam;
964
user = dlglogin->user;
966
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlglogin);
968
host_lptstr = utf8_to_lptstr(mb->host);
969
_sntprintf(tcbuf, sizeof(tcbuf), TEXT("Host: %.100s%s"), host_lptstr,
970
!mb->sslflag && !mb->tlsflag ? TEXT(" (INSECURE)") : TEXT(""));
971
fs_give((void **) &host_lptstr);
973
if(mb->sslflag || mb->tlsflag)
974
SetWindowText(hDlg, TEXT("Alpine Login +"));
976
SetWindowText(hDlg, TEXT("Alpine Insecure Login"));
979
EnableWindow(GetDlgItem(hDlg, IDC_RPASSWORD),0);
980
EnableWindow(GetDlgItem(hDlg, IDC_RPWTEXT),0);
981
EnableWindow(GetDlgItem(hDlg, IDC_PRESPASS),0);
983
if(mb->user && *mb->user){
986
user_lptstr = utf8_to_lptstr(mb->user);
987
SetDlgItemText(hDlg, IDC_RLOGINE, user_lptstr);
988
if((mb->user && *mb->user) || dlglogin->fixuser)
989
EnableWindow(GetDlgItem(hDlg, IDC_RLOGINE), 0);
990
fs_give((void **) &user_lptstr);
993
SetDlgItemText(hDlg, IDC_RLOGINE, user);
994
if(dlglogin->fixuser)
995
EnableWindow(GetDlgItem(hDlg, IDC_RLOGINE), 0);
997
SetDlgItemText(hDlg, IDC_PROMPT, tcbuf);
1002
dlglogin = (DLG_LOGINDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
1005
/* Retrieve the new username/passwd. */
1006
user = dlglogin->user;
1007
pwd = dlglogin->pwd;
1008
GetDlgItemText(hDlg, IDC_RLOGINE, user, dlglogin->userlen - 1);
1009
GetDlgItemText(hDlg, IDC_RPASSWORD, pwd, dlglogin->pwdlen - 1);
1010
user[dlglogin->userlen - 1] = '\0';
1011
pwd[dlglogin->pwdlen - 1] = '\0';
1012
dlglogin->prespass = (IsDlgButtonChecked(hDlg, IDC_PRESPASS) == BST_CHECKED);
1014
EndDialog (hDlg, LOWORD(wParam));
1022
EndDialog (hDlg, LOWORD(wParam));
1031
* Dialog proc to handle flag selection.
1033
* Configures the dialog box on init, adding buttons as needed for
1034
* an unknown number of flags.
1035
* Retrieves the settings on exit.
1037
BOOL CALLBACK __export
1038
flag_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1040
DLG_FLAGDATA *dlgflag;
1043
struct flag_table *fp;
1046
UINT bheight, bwidth, bvertSpace;
1057
dlgflag = (DLG_FLAGDATA *)lParam;
1058
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgflag);
1061
dlgflag->flagcount = 0;
1062
for (fp = dlgflag->ftbl; fp && fp->name; ++fp)
1063
++dlgflag->flagcount;
1065
/* Get the positions of the current buttons. */
1066
for (i = 0; i < 2; ++i) {
1067
hRB[i] = GetDlgItem (hDlg, IDC_FLAGCOL1 + i);
1068
GetBtnPos (hDlg, hRB[i], &rb[i]);
1070
bheight = rb[0].bottom - rb[0].top;
1071
bwidth = rb[0].right - rb[0].left;
1072
bvertSpace = bheight + 5;
1073
btnFont = (HFONT) SendMessage (hRB[0], WM_GETFONT, 0, 0);
1075
for (i = 0; i < dlgflag->flagcount; ++i) {
1076
LPTSTR fp_name_lptstr;
1078
fp = &dlgflag->ftbl[i];
1080
fp_name_lptstr = utf8_to_lptstr(fp->name);
1083
SetWindowText (hBtn, fp_name_lptstr);
1088
hBtn = CreateWindow (TEXT("BUTTON"), fp_name_lptstr,
1089
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
1090
rb[base].left, rb[base].top + bvertSpace * line,
1092
hDlg, (HMENU)NULL, dlgflag->hInstance, NULL);
1093
SetWindowLong (hBtn, GWL_ID, IDC_FLAGCOL1 + i);
1094
SendMessage (hBtn, WM_SETFONT, (WPARAM)btnFont,
1098
fs_give((void **) &fp_name_lptstr);
1100
SendMessage (hBtn, BM_SETSTYLE,
1101
(WPARAM)(BS_CHECKBOX | BS_AUTO3STATE), 0);
1102
SendMessage (hBtn, BM_SETCHECK,
1103
(WPARAM) fp->set == CMD_FLAG_UNKN ? 2 : fp->set ? 1 : 0,
1105
ShowWindow (hBtn, SW_SHOW);
1106
EnableWindow (hBtn, TRUE);
1109
/* Position the OK and Cancel buttons. */
1110
line = (dlgflag->flagcount + 1) / 2;
1111
for (i = 0; i < 2; ++i) {
1112
hRB[1] = GetDlgItem (hDlg, i == 0 ? IDOK : IDCANCEL);
1113
GetBtnPos (hDlg, hRB[1], &rb[1]);
1114
MoveWindow (hRB[1], rb[1].left, rb[0].top + bvertSpace * line,
1115
rb[1].right - rb[1].left, rb[1].bottom - rb[1].top,
1117
btnOKHeight = rb[1].bottom - rb[1].top;
1121
/* Resize whole dialog window. */
1122
GetWindowRect (hDlg, &rb[1]);
1123
rb[1].right -= rb[1].left;
1124
rb[1].bottom = rb[0].top + bvertSpace * line + btnOKHeight + 10 +
1125
GetSystemMetrics (SM_CYCAPTION);
1126
MoveWindow (hDlg, rb[1].left, rb[1].top, rb[1].right,
1127
rb[1].bottom, TRUE);
1132
dlgflag = (DLG_FLAGDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
1136
/* Retrieve the button states. */
1137
for (i = 0; i < dlgflag->flagcount; ++i) {
1138
fp = &dlgflag->ftbl[i];
1139
bstate = SendMessage (GetDlgItem (hDlg, IDC_FLAGCOL1 + i),
1142
case 2: fp->set = CMD_FLAG_UNKN; break;
1143
case 1: fp->set = CMD_FLAG_SET; break;
1144
case 0: fp->set = CMD_FLAG_CLEAR; break;
1147
EndDialog (hDlg, TRUE);
1152
EndDialog (hDlg, FALSE);
1164
* Dialog proc to handle index sort selection.
1166
* Configures the dialog box on init and retrieves the settings on exit.
1168
BOOL CALLBACK __export
1169
sort_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1171
DLG_SORTDATA *dlgsort;
1179
dlgsort = (DLG_SORTDATA *)lParam;
1180
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgsort);
1182
/* Set the reversed button state. */
1183
CheckDlgButton (hDlg, IDC_SORTREVERSE, dlgsort->sortsel->reverse);
1185
/* Set the current sort type radio button.*/
1186
cursort = IDC_SORTARRIVAL;
1187
for (i = 0; i < dlgsort->sortcount; ++i) {
1188
if (dlgsort->types[i].pineid == dlgsort->sortsel->cursort) {
1189
cursort = dlgsort->types[i].rsrcid;
1193
CheckRadioButton (hDlg, IDC_SORTFIRSTBUTTON, IDC_SORTLASTBUTTON,
1196
EnableWindow (GetDlgItem (hDlg, IDC_GETHELP),
1197
(dlgsort->sortsel->helptext != NULL));
1202
dlgsort = (DLG_SORTDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
1205
if (dlgsort->sortsel->helptext)
1206
mswin_showhelpmsg ((WINHAND)hDlg, dlgsort->sortsel->helptext);
1211
dlgsort->sortsel->rval = 1;
1213
/* Retrieve the reverse sort state. */
1214
dlgsort->sortsel->reverse = (IsDlgButtonChecked (hDlg, IDC_SORTREVERSE) == 1);
1216
/* Retrieve the new sort type. */
1217
for (i = 0; i < dlgsort->sortcount; ++i) {
1218
if (IsDlgButtonChecked (hDlg, dlgsort->types[i].rsrcid)) {
1219
dlgsort->sortsel->cursort = dlgsort->types[i].pineid;
1223
EndDialog (hDlg, dlgsort->sortsel->rval);
1228
dlgsort->sortsel->rval = 0;
1230
EndDialog (hDlg, dlgsort->sortsel->rval);
1241
os_config_vars_dialog (INSTALLVARS_S *ivars)
1247
DLG_CONFIGVARSDATA dlgcv;
1250
hInst = (HINSTANCE) mswin_gethinstance ();
1251
hWnd = (HWND) mswin_gethwnd ();
1253
dlgcv.ivars = ivars;
1256
dlgprc = config_vars_dialog_proc;
1258
DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_CFVARSDLG), NULL,
1259
dlgprc, (LPARAM)&dlgcv);
1265
* Dialog proc to handle login
1267
* Configures the dialog box on init and retrieves the settings on exit.
1269
BOOL CALLBACK __export
1270
config_vars_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1272
DLG_CONFIGVARSDATA *dlgcv;
1275
char buf[2*MAXPATH+1], *p;
1276
int buflen = 2*MAXPATH;
1277
#define TCBUFLEN (2*MAXPATH)
1278
TCHAR tcbuf[TCBUFLEN+1];
1284
dlgcv = (DLG_CONFIGVARSDATA *)lParam;
1285
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgcv);
1286
if(dlgcv->ivars->pname){
1287
tmp_lptstr = utf8_to_lptstr(dlgcv->ivars->pname);
1289
SetDlgItemText(hDlg, IDC_CFV_PNAME, tmp_lptstr);
1290
fs_give((void **) &tmp_lptstr);
1294
if(dlgcv->ivars->userid && dlgcv->ivars->domain){
1295
snprintf(buf, sizeof(buf), "%.*s@%.*s", MAXPATH, dlgcv->ivars->userid,
1296
MAXPATH, dlgcv->ivars->domain);
1297
buf[buflen-1] = '\0';
1298
tmp_lptstr = utf8_to_lptstr(buf);
1300
SetDlgItemText(hDlg, IDC_CFV_EMAILADR, tmp_lptstr);
1301
fs_give((void **) &tmp_lptstr);
1305
if(dlgcv->ivars->inboxpath){
1308
mbx = dlgcv->ivars->inboxpath;
1309
if(*mbx == '{' && (p = strindex(mbx, '}'))
1310
&& ((*(p+1) == '\0') || !strucmp(p+1, "inbox"))){
1311
char srvbuf[MAXPATH+1], tuser[MAXPATH+1];
1316
strncpy(buf, mbx+1, min(buflen, (int)(p - (mbx+1))));
1317
buf[min(buflen-1, (int)(p - (mbx+1)))] = '\0';
1318
for(i = 0, j = 0; buf[i] && j < MAXPATH; i++){
1320
if(!struncmp("/user=", buf+i, 6)){
1322
for(k = 0; k < MAXPATH && buf[i]
1323
&& buf[i] != '/'; i++)
1324
tuser[k++] = buf[i];
1328
else if(!struncmp("/pop3", buf+i, 5)
1329
&& (!*(buf+5) || (*(buf+5) == '/'))){
1334
srvbuf[j++] = buf[i];
1337
srvbuf[j++] = buf[i];
1341
tmp_lptstr = utf8_to_lptstr(srvbuf);
1343
SetDlgItemText(hDlg, IDC_CFV_MSERVER, tmp_lptstr);
1344
fs_give((void **) &tmp_lptstr);
1349
tmp_lptstr = utf8_to_lptstr(tuser);
1351
SetDlgItemText(hDlg, IDC_CFV_LOGIN, tmp_lptstr);
1352
fs_give((void **) &tmp_lptstr);
1357
tmp_lptstr = utf8_to_lptstr(mbx);
1359
SetDlgItemText(hDlg, IDC_CFV_MSERVER, tmp_lptstr);
1360
fs_give((void **) &tmp_lptstr);
1363
if(*mbx != '{' && *mbx != '#')
1364
EnableWindow(GetDlgItem(hDlg, IDC_CFV_MSERVER), 0);
1367
CheckRadioButton (hDlg, IDC_CFV_IMAP, IDC_CFV_POP3,
1368
usepop ? IDC_CFV_POP3 : IDC_CFV_IMAP);
1369
if(dlgcv->ivars->smtpserver){
1370
tmp_lptstr = utf8_to_lptstr(dlgcv->ivars->smtpserver);
1372
SetDlgItemText(hDlg, IDC_CFV_SMTPSERVER, tmp_lptstr);
1373
fs_give((void **) &tmp_lptstr);
1377
if(dlgcv->ivars->defmailclient)
1378
CheckDlgButton(hDlg, IDC_CFV_DEFMAILER, BST_CHECKED);
1379
if(dlgcv->ivars->defnewsclient)
1380
CheckDlgButton(hDlg, IDC_CFV_DEFNEWSRDR, BST_CHECKED);
1386
dlgcv = (DLG_CONFIGVARSDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
1390
GetDlgItemText(hDlg, IDC_CFV_PNAME, tcbuf, TCBUFLEN);
1391
tcbuf[TCBUFLEN] = '\0';
1392
u = lptstr_to_utf8(tcbuf);
1394
removing_leading_and_trailing_white_space(u);
1395
if(dlgcv->ivars->pname)
1396
fs_give((void **)&dlgcv->ivars->pname);
1399
dlgcv->ivars->pname = u;
1404
fs_give((void **) &u);
1407
/* user-id and domain */
1408
GetDlgItemText(hDlg, IDC_CFV_EMAILADR, tcbuf, TCBUFLEN);
1409
tcbuf[TCBUFLEN] = '\0';
1410
u = lptstr_to_utf8(tcbuf);
1412
removing_leading_and_trailing_white_space(u);
1413
if(p = strindex(u, '@')){
1415
if(dlgcv->ivars->userid)
1416
fs_give((void **)&dlgcv->ivars->userid);
1418
if(dlgcv->ivars->domain)
1419
fs_give((void **)&dlgcv->ivars->domain);
1422
dlgcv->ivars->userid = u;
1427
dlgcv->ivars->domain = cpystr(p);
1430
MessageBox(hDlg, TEXT("Invalid email address. Should be username@domain"),
1431
TEXT("Alpine"), MB_ICONWARNING | MB_OK);
1436
fs_give((void **) &u);
1440
GetDlgItemText(hDlg, IDC_CFV_MSERVER, tcbuf, TCBUFLEN);
1441
tcbuf[TCBUFLEN] = '\0';
1442
u = lptstr_to_utf8(tcbuf);
1444
removing_leading_and_trailing_white_space(u);
1445
if(*u == '{' || *u == '#'
1446
|| !IsWindowEnabled(GetDlgItem(hDlg, IDC_CFV_MSERVER))){
1447
if(dlgcv->ivars->inboxpath)
1448
fs_give((void **)&dlgcv->ivars->inboxpath);
1450
dlgcv->ivars->inboxpath = u;
1454
char tsrvr[4*MAXPATH+1];
1455
int tsrvrlen = 4*MAXPATH;
1457
if(dlgcv->ivars->inboxpath)
1458
fs_give((void **)&dlgcv->ivars->inboxpath);
1460
snprintf(tsrvr, sizeof(tsrvr), "{%s%s", u,
1461
IsDlgButtonChecked(hDlg, IDC_CFV_POP3)
1462
== BST_CHECKED ? "/pop3" : "");
1465
fs_give((void **) &u);
1467
GetDlgItemText(hDlg, IDC_CFV_LOGIN, tcbuf, TCBUFLEN);
1468
tcbuf[TCBUFLEN] = '\0';
1469
u = lptstr_to_utf8(tcbuf);
1471
removing_leading_and_trailing_white_space(u);
1473
strncat(tsrvr, "/user=", tsrvrlen);
1474
strncat(tsrvr, u, tsrvrlen);
1477
strncat(tsrvr, "}inbox", tsrvrlen);
1478
tsrvr[tsrvrlen-1] = '\0';
1479
dlgcv->ivars->inboxpath = cpystr(tsrvr);
1484
fs_give((void **) &u);
1488
GetDlgItemText(hDlg, IDC_CFV_SMTPSERVER, tcbuf, TCBUFLEN);
1489
tcbuf[TCBUFLEN] = '\0';
1490
u = lptstr_to_utf8(tcbuf);
1492
removing_leading_and_trailing_white_space(u);
1493
if(dlgcv->ivars->smtpserver)
1494
fs_give((void **)&dlgcv->ivars->smtpserver);
1497
dlgcv->ivars->smtpserver = u;
1502
fs_give((void **) &u);
1505
dlgcv->ivars->defmailclient =
1506
(IsDlgButtonChecked(hDlg, IDC_CFV_DEFMAILER)
1508
dlgcv->ivars->defnewsclient =
1509
(IsDlgButtonChecked(hDlg, IDC_CFV_DEFNEWSRDR)
1512
EndDialog (hDlg, LOWORD(wParam));
1520
EndDialog (hDlg, LOWORD(wParam));
1531
* Prompt for config location
1535
os_config_dialog (char *utf8_buf, int utf8_buflen,
1536
int *regset, int nopinerc)
1542
DLG_CONFIGDATA dlgcfg;
1545
hInst = (HINSTANCE) mswin_gethinstance ();
1546
hWnd = (HWND) mswin_gethwnd ();
1548
dlgcfg.confpath = utf8_buf;
1549
dlgcfg.confpathlen = utf8_buflen;
1551
dlgcfg.nopinerc = nopinerc;
1554
dlgprc = config_dialog_proc;
1556
DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_CONFIGDLG), NULL,
1557
dlgprc, (LPARAM)&dlgcfg);
1559
*regset = dlgcfg.setreg;
1565
* Dialog proc to handle login
1567
* Configures the dialog box on init and retrieves the settings on exit.
1569
BOOL CALLBACK __export
1570
config_dialog_proc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1572
DLG_CONFIGDATA *dlgcfg;
1574
int checked, def_rem_fldr = 1, def_diff_fldr = 0;
1579
dlgcfg = (DLG_CONFIGDATA *)lParam;
1580
SetWindowLong (hDlg, WINDOW_USER_DATA, (LONG) dlgcfg);
1581
if(ps_global->install_flag)
1582
SetDlgItemText(hDlg, IDC_CONFTEXT, TEXT("Please specify where Alpine should create (or look for) your personal configuration file."));
1583
SetDlgItemText(hDlg, IDC_CONFEFLDRNAME, TEXT("remote_pinerc"));
1584
if(*dlgcfg->confpath){
1585
if(dlgcfg->confpath[0] == '{'){
1586
LPTSTR tfldr, p, tfldr2, p2, user;
1588
tfldr = utf8_to_lptstr((LPSTR)(dlgcfg->confpath+1));
1589
if(p = _tcschr(tfldr, '}')){
1591
if(_tcscmp(TEXT("remote_pinerc"), p)){
1592
SetDlgItemText(hDlg, IDC_CONFEFLDRNAME, p);
1596
tfldr2 = _tcsdup(tfldr);
1597
for(p = tfldr, p2 = tfldr2; *p; p++)
1598
if(*p == '/' && !_tcsnicmp(p, TEXT("/user="), 6)){
1600
for(user = p; *p && *p != '/'; p++);
1607
SetDlgItemText(hDlg, IDC_CONFEUSERNAME, user);
1612
SetDlgItemText(hDlg, IDC_CONFESERVER, tfldr2);
1614
MemFree((void *)tfldr2);
1618
fs_give((void **) &tfldr);
1623
local_file = utf8_to_lptstr((LPSTR)dlgcfg->confpath);
1624
SetDlgItemText(hDlg, IDC_CONFEFN, local_file);
1625
if(!dlgcfg->nopinerc)
1628
fs_give((void **) &local_file);
1631
CheckRadioButton (hDlg, IDC_CONFRRADIO, IDC_CONFLRADIO,
1632
def_rem_fldr ? IDC_CONFRRADIO : IDC_CONFLRADIO);
1634
EnableWindow(GetDlgItem(hDlg, IDC_CONFFNTXT), 0);
1635
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFN), 0);
1636
EnableWindow(GetDlgItem(hDlg, IDC_CONFBROWSE), 0);
1638
CheckDlgButton(hDlg, IDC_CONFDFLTFLDR, BST_CHECKED);
1639
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 0);
1641
EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 0);
1644
EnableWindow(GetDlgItem(hDlg, IDC_CONFSRVRTXT), 0);
1645
EnableWindow(GetDlgItem(hDlg, IDC_CONFESERVER), 0);
1646
EnableWindow(GetDlgItem(hDlg, IDC_CONFUNTXT), 0);
1647
EnableWindow(GetDlgItem(hDlg, IDC_CONFEUSERNAME), 0);
1648
CheckDlgButton(hDlg, IDC_CONFDFLTFLDR, BST_CHECKED);
1649
EnableWindow(GetDlgItem(hDlg, IDC_CONFDFLTFLDR), 0);
1650
EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 0);
1651
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 0);
1653
if(ps_global->install_flag)
1654
CheckDlgButton(hDlg, IDC_CONFDFLTSET, BST_CHECKED);
1660
dlgcfg = (DLG_CONFIGDATA *) GetWindowLong (hDlg, WINDOW_USER_DATA);
1662
case IDC_CONFDFLTFLDR:
1663
checked = (IsDlgButtonChecked(hDlg, IDC_CONFDFLTFLDR) == BST_CHECKED);
1664
EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), checked ? 0 : 1);
1665
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), checked ? 0 : 1);
1667
SetDlgItemText(hDlg, IDC_CONFEFLDRNAME, TEXT("remote_pinerc"));
1669
case IDC_CONFRRADIO:
1670
case IDC_CONFLRADIO:
1671
CheckRadioButton (hDlg, IDC_CONFRRADIO, IDC_CONFLRADIO, wParam);
1672
EnableWindow(GetDlgItem(hDlg, IDC_CONFFNTXT), wParam == IDC_CONFRRADIO ? 0 : 1);
1673
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFN), wParam == IDC_CONFRRADIO ? 0 : 1);
1674
EnableWindow(GetDlgItem(hDlg, IDC_CONFBROWSE), wParam == IDC_CONFRRADIO ? 0 : 1);
1675
EnableWindow(GetDlgItem(hDlg, IDC_CONFSRVRTXT), wParam == IDC_CONFRRADIO ? 1 : 0);
1676
EnableWindow(GetDlgItem(hDlg, IDC_CONFESERVER), wParam == IDC_CONFRRADIO ? 1 : 0);
1677
EnableWindow(GetDlgItem(hDlg, IDC_CONFUNTXT), wParam == IDC_CONFRRADIO ? 1 : 0);
1678
EnableWindow(GetDlgItem(hDlg, IDC_CONFEUSERNAME), wParam == IDC_CONFRRADIO ? 1 : 0);
1679
EnableWindow(GetDlgItem(hDlg, IDC_CONFDFLTFLDR), wParam == IDC_CONFRRADIO ? 1 : 0);
1680
if(wParam == IDC_CONFRRADIO && IsDlgButtonChecked(hDlg, IDC_CONFDFLTFLDR) == BST_UNCHECKED){
1681
EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 1);
1682
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 1);
1684
else if(wParam == IDC_CONFLRADIO){
1685
EnableWindow(GetDlgItem(hDlg, IDC_CONFFLDRTXT), 0);
1686
EnableWindow(GetDlgItem(hDlg, IDC_CONFEFLDRNAME), 0);
1689
case IDC_CONFBROWSE:
1691
TCHAR fn[MAXPATH+1];
1696
/* Set up the BIG STRUCTURE. see mswin.c */
1697
memset (&ofn, 0, sizeof(ofn));
1698
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
1699
ofn.hwndOwner = hDlg;
1700
ofn.lpstrFilter = NULL;
1701
ofn.lpstrCustomFilter = NULL;
1702
ofn.nFilterIndex = 0;
1704
ofn.nMaxFile = MAXPATH;
1705
ofn.lpstrFileTitle = NULL;
1706
ofn.nMaxFileTitle = 0;
1707
ofn.lpstrInitialDir = NULL;
1708
ofn.lpstrTitle = TEXT("Select File");
1709
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
1710
ofn.lpstrDefExt = NULL;
1712
if (GetOpenFileName (&ofn)) {
1713
SetDlgItemText(hDlg, IDC_CONFEFN, fn);
1718
/* Retrieve the new username/passwd. */
1719
if(IsDlgButtonChecked(hDlg, IDC_CONFDFLTSET) == BST_CHECKED)
1723
if(IsDlgButtonChecked(hDlg, IDC_CONFRRADIO) == BST_CHECKED){
1724
TCHAR lptstr_buf[MAXPATH+1];
1725
char *utf8_srvr, *utf8_username, *utf8_fldrname;
1727
GetDlgItemText(hDlg, IDC_CONFESERVER, lptstr_buf, MAXPATH);
1728
lptstr_buf[MAXPATH] = '\0';
1729
utf8_srvr = lptstr_to_utf8(lptstr_buf);
1730
removing_leading_and_trailing_white_space(utf8_srvr);
1732
MessageBox(hDlg, TEXT("IMAP Server field empty"),
1733
TEXT("Alpine"), MB_ICONWARNING | MB_OK);
1735
fs_give((void **) &utf8_srvr);
1740
GetDlgItemText(hDlg, IDC_CONFEUSERNAME, lptstr_buf, MAXPATH);
1741
lptstr_buf[MAXPATH] = '\0';
1742
utf8_username = lptstr_to_utf8(lptstr_buf);
1743
removing_leading_and_trailing_white_space(utf8_username);
1744
if(IsDlgButtonChecked(hDlg, IDC_CONFDFLTFLDR) == BST_CHECKED){
1745
utf8_fldrname = cpystr("remote_pinerc");
1748
GetDlgItemText(hDlg, IDC_CONFEFLDRNAME, lptstr_buf, MAXPATH);
1749
lptstr_buf[MAXPATH] = '\0';
1750
utf8_fldrname = lptstr_to_utf8(lptstr_buf);
1751
removing_leading_and_trailing_white_space(utf8_fldrname);
1752
if(!*utf8_fldrname){
1753
MessageBox(hDlg, TEXT("Configuration Folder Name field empty"),
1754
TEXT("Alpine"), MB_ICONWARNING | MB_OK);
1756
fs_give((void **) &utf8_srvr);
1759
fs_give((void **) &utf8_username);
1762
fs_give((void **) &utf8_fldrname);
1767
if((strlen(utf8_srvr)
1768
+ strlen(utf8_username)
1769
+ strlen(utf8_fldrname)
1770
+ 11) > dlgcfg->confpathlen){
1771
MessageBox(hDlg, TEXT("Config path too long"),
1772
TEXT("Alpine"), MB_ICONWARNING | MB_OK);
1774
fs_give((void **) &utf8_srvr);
1777
fs_give((void **) &utf8_username);
1780
fs_give((void **) &utf8_fldrname);
1785
snprintf(dlgcfg->confpath, dlgcfg->confpathlen, "{%s%s%s}%s", utf8_srvr,
1786
*utf8_username ? "/user=" : "",
1787
utf8_username, utf8_fldrname);
1789
fs_give((void **) &utf8_srvr);
1792
fs_give((void **) &utf8_username);
1795
fs_give((void **) &utf8_fldrname);
1798
TCHAR lptstr_fn[MAXPATH+1];
1801
GetDlgItemText(hDlg, IDC_CONFEFN, lptstr_fn, MAXPATH);
1802
lptstr_fn[MAXPATH] = '\0';
1803
utf8_fn = lptstr_to_utf8(lptstr_fn);
1804
removing_leading_and_trailing_white_space(utf8_fn);
1806
MessageBox(hDlg, TEXT("Configuration File Name field empty"),
1807
TEXT("Alpine"), MB_ICONWARNING | MB_OK);
1809
fs_give((void **) &utf8_fn);
1814
if(strlen(utf8_fn) >= dlgcfg->confpathlen){
1815
MessageBox(hDlg, TEXT("Config path too long"),
1816
TEXT("Alpine"), MB_ICONWARNING | MB_OK);
1818
fs_give((void **) &utf8_fn);
1823
strncpy(dlgcfg->confpath, utf8_fn, dlgcfg->confpathlen);
1824
dlgcfg->confpath[dlgcfg->confpathlen-1] = '\0';
1826
fs_give((void **) &utf8_fn);
1829
EndDialog (hDlg, LOWORD(wParam));
1837
EndDialog (hDlg, LOWORD(wParam));
1848
* Get a button position in the parent's coordinate space.
1851
GetBtnPos (HWND hPrnt, HWND hWnd, RECT *r)
1853
GetWindowRect (hWnd, r);
1854
ScreenToClient (hPrnt, (POINT *) r);
1855
ScreenToClient (hPrnt, (POINT *) &r->right);