home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume13
/
xmail
/
part08
/
actions.c
Wrap
C/C++ Source or Header
|
1991-06-15
|
29KB
|
1,023 lines
/*
* xmail - X window system interface to the mail program
*
* Copyright 1989 The University of Texas at Austin
*
* Author: Po Cheung
* Date: March 10, 1989
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation. The University of Texas at Austin makes no
* representations about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* Copyright 1990 by National Semiconductor Corporation
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of National Semiconductor Corporation not
* be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* NATIONAL SEMICONDUCTOR CORPORATION MAKES NO REPRESENTATIONS ABOUT THE
* SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS"
* WITHOUT EXPRESS OR IMPLIED WARRANTY. NATIONAL SEMICONDUCTOR CORPORATION
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
* EVENT SHALL NATIONAL SEMICONDUCTOR CORPORATION BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* The following software modules were created and are Copyrighted by
* National Semiconductor Corporation:
*
* 1. CheckInsert
* 2. DeleteChar
* 3. EraseIt:
* 4. DoCmd:
* 5. DoNothing:
* 6. DoReply:
* 7. DoSave:
* 8. DoSelected:
* 9. Folder:
* 10. Iconify:
* 11. MyNotify:
* 12. NextField:
* 13. PrintMsg:
* 14. SetAliases:
* 15. SetFolders:
* 16. SetMenu:
* 17. SetPopup:
* 18. SetSelect: and
* 19. ShowHelp.
*
* Author: Michael C. Wagnitz - National Semiconductor Corporation
*
*/
#include "global.h"
#include "xmailregex.h"
#include <ctype.h>
#ifdef USE_DIRENT
#include <dirent.h>
#else
#include <sys/dir.h>
#endif
/*
** @(#)CheckInsert() - prevents the user from munging up the File: prompt.
** If the current insertion point is less than the minimum StartPos, move
** the insertion point to the StartPos.
*/
/* ARGSUSED */
XtActionProc
CheckInsert(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
if (XawTextGetInsertionPoint(w) < StartPos)
XawTextSetInsertionPoint(w, StartPos);
} /* CheckInsert */
/*
** @(#)EraseIt() - Delete the specified portion of text.
*/
void
EraseIt(w, i, pos)
Widget w;
XawTextPosition i, pos;
{
XawTextBlock textblock;
textblock.firstPos = 0;
textblock.length = 0;
textblock.ptr = "";
XawTextReplace(w, i, pos, &textblock);
XawTextSetInsertionPoint(w, i);
} /* EraseIt */
/*
** @(#)DeleteChar() - prevents the user from deleting past the File: prompt.
** If the current insertion point is greater than the minimum StartPos, then
** delete the previous character.
*/
/* ARGSUSED */
XtActionProc
DeleteChar(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
XawTextPosition pos, i;
pos = XawTextGetInsertionPoint(w);
if (pos > StartPos) {
i = pos - 1;
EraseIt(w, i, pos);
}
} /* DeleteChar */
/*
** @(#)DeleteLine() - Deletes the entire current line from the file window.
** Simulates the action of the KILL character (ctrl-U).
*/
/* ARGSUSED */
XtActionProc
DeleteLine(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
XawTextPosition pos, i;
pos = XawTextGetInsertionPoint(w);
if (pos > StartPos) {
for (i = pos; i > StartPos && FileBuf[i - 1] != '\n'; i--);
EraseIt(w, i, pos);
}
} /* DeleteLine */
/*
** @(#)DeleteWord() - Erases the preceding word in the fileWindow buffer.
** Simulates the action of the WERASE character (ctrl-W).
*/
/* ARGSUSED */
XtActionProc
DeleteWord(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
XawTextPosition pos, i;
pos = XawTextGetInsertionPoint(w);
if (pos > StartPos) {
for (i = pos; i > StartPos && FileBuf[i - 1] == ' '; i--);
for (; i > StartPos && FileBuf[i - 1] != ' '; i--);
EraseIt(w, i, pos);
}
} /* DeleteWord */
/* ARGSUSED */
/*
** @(#)DoCmd() - send (multi-word) command to mail
*/
XtActionProc
DoCmd(w, event, params, num_params)
Widget w; /* unused */
XEvent *event; /* unused */
String *params;
Cardinal *num_params;
{
int i, n;
char buf[BUFSIZ];
Arg args[1];
LabelWidget lw = (LabelWidget) XtNameToWidget(toplevel, "topBox.titleBar.title");
SetCursor(1);
if (strcmp(params[0], "drop") == 0)
DropIt(w, *params, NULL);
else {
Command[0] = '\0';
for (i = 0; i < *num_params; i++) {
strcat(Command, params[i]);
strcat(Command, " ");
}
if (i)
Command[strlen(Command)-1] = '\0'; /* Drop the last trailing blank */
strcat(Command, "\n");
if (mailpid) { /* If connections are okay,... */
if ((n = match(&command_pattern, Command)) != C_FILE && n != C_NEWMAIL)
writeMail(Command);
else { /* check for commit of any changes */
XtSetArg(args[0], XtNlabel, (XtArgVal) NULL);
XtGetValues(lw, args, ONE);
strcpy(buf, (char *)args[0].value);
if (strcmp(&buf[strlen(buf)-7],"deleted") ||
strcmp(params[0], "inc") == 0 ||
Confirm("COMMIT all changes to this folder"))
writeMail(Command);
}
} else if (C_NEWMAIL != match(&command_pattern, Command))
Bell("No current mail connection\n"); /* If not 'Newmail' */
else {
if (strcmp(mailargv[mailargc - 2], "-f") == 0) {
mailargc -= 2; /* throw away any folder argument */
mailargv[mailargc] = NULL; /* and NULL end of argument list */
}
callMail(mailargc, mailargv); /* restart the mail connections */
strcpy(Command, "Start"); /* Let em know we've re-started */
UnsetNewmail(w, NULL, NULL);
}
}
} /* DoCmd */
/* ARGSUSED */
/*
** @(#)DoNothing() - dummy action for unwanted button(s)
*/
XtActionProc
DoNothing(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
return;
} /* DoNothing */
/*
** @(#)DoReply() - call Reply() CallbackProc from an ActionProc
*/
/* ARGSUSED */
XtActionProc
DoReply(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Reply(w, *params, NULL);
} /* DoReply */
/*
** @(#)DoSave() - call Save() CallbackProc from an ActionProc
*/
/* ARGSUSED */
XtActionProc
DoSave(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Save(w, *params, NULL);
} /* DoSave */
/* ARGSUSED */
/*
** @(#)DoSelected() - execute specified command using selected message number
*/
XtActionProc
DoSelected(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
int num = 0;
SetCursor(1);
if (! mailpid) Bell("No current mail connection\n");
else if (num_params) {
if (*params[0] != 'n' && *params[0] != '-')
num = SelectionNumber(*params[0] == 'u');
if (num) sprintf(Command, "%s %d\n", params[0], num);
else sprintf(Command, "%s\n", params[0]);
writeMail(Command);
if (strcmp(params[0], "preserve") == 0)
markIndex("P");
}
} /* DoSelected */
/*
** @(#)Folder() - change folders - must have specified folder name or error
*/
/* ARGSUSED */
XtActionProc
Folder(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
char buf[BUFSIZ];
Arg args[1];
LabelWidget lw = (LabelWidget) XtNameToWidget(toplevel, "topBox.titleBar.title");
XawTextPosition pos;
char *p;
Cardinal n;
SetCursor(1); /* restore normally by next msg read */
pos = TextGetLastPos(XtNameToWidget(toplevel, "topBox.commandPanel.fileWindow"));
if ((n = pos - StartPos) <= 0) {
Bell("Specify a folder name (in the [File: ] box) first\n");
} else {
FileBuf[StartPos + n] = '\0';
p = FileBuf + StartPos;
if (mailpid) { /* check for commit of any changes */
XtSetArg(args[0], XtNlabel, (XtArgVal) NULL);
XtGetValues(lw, args, ONE);
strcpy(buf, (char *)args[0].value);
if (strcmp(&buf[strlen(buf) - 7], "deleted") ||
Confirm("COMMIT all changes to this folder")) {
sprintf(Command, "file %s\n", p);
writeMail(Command);
}
} else {
/*
** We must first re-establish contact with the mail utility.
** This time, we indicate a specific mail folder to process.
*/
XMail.MFileName = XtNewString(p);
if (strcmp(mailargv[mailargc - 2], "-f") == 0) {
mailargv[mailargc - 1] = XMail.MFileName;
} else {
mailargv[mailargc++] = "-f";
mailargv[mailargc++] = XMail.MFileName;
mailargv[mailargc] = NULL; /* list MUST be NULL terminated */
}
callMail(mailargc, mailargv);
strcpy(Command, "Start"); /* Let em know we've re-started */
}
}
} /* Folder */
/* ARGSUSED */
/*
** @(#)Iconify() - request window iconification
*/
XtActionProc
Iconify(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Display *disp;
disp = XtDisplay(toplevel);
if (! XIconifyWindow(disp, XtWindow(toplevel), DefaultScreen(disp)))
XBell(XtDisplay(toplevel), 33);
}
/* ARGSUSED */
/*
** @(#)MyNotify() - call widget callbacks with passed parameter
*/
XtActionProc
MyNotify(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
XtCallCallbacks(w, XtNcallback, *params);
} /* MyNotify */
/*
** @(#)NextField() - warps pointer to next field in the Send command window.
** This allows carriage return to focus attention on the next data requirement.
*/
/* ARGSUSED */
XtActionProc
NextField(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
String name;
Widget shell;
if (strcmp(w->core.name, "Cc") == 0)
name = "Bcc"; else
if (strcmp(w->core.name, "Bcc") == 0)
name = "To"; else
if (strcmp(w->core.name, "To") == 0)
name = "Subject"; else
name = "Cc";
if ((shell = XtNameToWidget(XtParent(w), name)) != NULL)
XWarpPointer(XtDisplay(toplevel), None, XtWindow(shell), 0,0,0,0, 10, 5);
} /* NextField */
/*
** @(#)PrintMsg() - sends the selected mail message to the system printer
*/
/* ARGSUSED */
XtActionProc
PrintMsg(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
char *cp;
int num;
SetCursor(1);
if (! mailpid) Bell("No current mail connection\n");
else {
num = SelectionNumber(False); /* no current message returns zero */
if (! num) Bell("No messages to print.\n");
else {
cp = GetMailEnv("printmail");
if (! cp) {
sprintf(Command, "| %d \"lpr -p\"\n", num);
} else {
sprintf(Command, "| %d \"%s\"\n", num, cp);
XtFree(cp);
}
writeMail(Command);
}
}
} /* PrintMsg */
/*
** @(#)Quit() - call DoQuit() CallbackProc from the Quit ActionProc
*/
/* ARGSUSED */
XtActionProc
Quit(w, event, params, num_params)
Widget w; /* unused */
XEvent *event; /* unused */
String *params;
Cardinal *num_params;
{
if (event->type == ClientMessage &&
event->xclient.data.l[0] != wmDeleteWindow) {
XBell (XtDisplay(w), 0);
return;
}
DoQuit(w, *params, NULL);
} /* Quit */
/*
** @(#)SetAliases() - create a menu list of alias names
*/
/* ARGSUSED */
XtActionProc
SetAliases(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Arg args[7];
Cardinal i, j, k, n;
Widget bw, lw, popup, hold, left;
static String l_Trans = "<Btn3Up>: MenuPopdown(aliasList)";
static String fl_trans = "<EnterWindow>: set() \n\
<LeaveWindow>: unset() \n\
<Btn3Up>: notify()";
static XtCallbackRec fl_callbacks[] = {
{ (XtCallbackProc) GetAliasName, NULL },
{ NULL, NULL }
};
SetCursor(1);
popup = XtNameToWidget(w, "aliasList");
if (! popup || popup->core.being_destroyed) {
XtSetArg(args[0], XtNtranslations, XtParseTranslationTable(l_Trans));
popup = XtCreatePopupShell("aliasList",overrideShellWidgetClass,w,args,1);
(void) alias(NULL); /* ensure our aliases list is set */
/*
** determine proper label width by finding longest name length
*/
i = j = k = 0;
for (n = 0; aliases[n]; n++)
if ((k = strlen(aliases[n]->name)) > j) {
j = k;
i = n;
}
if (j == 0) { /* If no alias names exist */
XtSetArg(args[0], XtNwidth, 1); /* set these so MenuPopup */
XtSetArg(args[1], XtNheight, 1); /* won't complain about a */
XtSetValues(popup, (ArgList) args, 2); /* zero width or height */
XtDestroyWidget(popup); /* to bad MenuPopup() doesn't care */
} else {
/*
** Make equal width command buttons which contain the alias names
*/
XtSetArg(args[0], XtNdefaultDistance, (XtArgVal) 1);
lw = XtCreateManagedWidget("table", formWidgetClass, popup, args, ONE);
bw = left = NULL;
XtSetArg(args[0], XtNwidth, XTextWidth(XMail.buttonFont, aliases[i]->name, j) + 14);
XtSetArg(args[1], XtNfont, XMail.buttonFont);
XtSetArg(args[2], XtNtranslations, XtParseTranslationTable(fl_trans));
XtSetArg(args[3], XtNcallback, fl_callbacks);
i = j = 0;
if (n > 10) { /* if more than ten aliases, try to */
j = n / 4; /* make an approximately square list */
while (j * j < n) j++; /* (int. hack to avoid sqrt usage) */
i = n / --j;
while (i * j < n) i++;
while (j > 3 && i < 25) { /* try to keep box inside main shell */
i++;
j--;
}
}
for (n = 0; aliases[n]; n++) {
XtSetArg(args[4], XtNlabel, aliases[n]->name);
XtSetArg(args[5], XtNfromVert, bw); j = 6;
if (left) {
XtSetArg(args[j], XtNfromHoriz, left); j++;
}
bw = XtCreateManagedWidget("entry", commandWidgetClass, lw, args, j);
AddInfoHandler(bw, "Copy this alias to the current header field");
if (i) { /* post names in a rectangular list */
if (n % i == 0) hold = bw;
if ((n+1) % i == 0) {
left = hold;
bw = NULL;
}
}
}
} /* end - if some alias names exist */
} /* end - if popup does not exist or was being destroyed */
/*
** If the menu exists, set its x,y coordinates
*/
SetCursor(0);
if (popup->core.being_destroyed)
XBell(XtDisplay(toplevel), 33);
else {
SetXY(popup, w, XMail.menuX, XMail.buttonHeight / 2);
}
} /* SetAliases */
/*
** @(#)SetFolders() - create a menu list of folder names
*/
/* ARGSUSED */
XtActionProc
SetFolders(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Arg args[8];
Widget lw, above, this_one, to_left, popup;
int x, n;
char trans[BUFSIZ], tmp[BUFSIZ], *p, *List = NULL;
char foldir[BUFSIZ], *GetMailEnv(), *getenv();
int foldlen, List_size, newline = 0;
DIR *dirp = NULL;
#ifdef USE_DIRENT
struct dirent *dp;
#else
struct direct *dp;
#endif
static String dir_Trans = "\
<Btn1Down>: SetDirectory(%s,%s,%s)";
static String l_Trans = "<Btn3Up>: MenuPopdown(popupList)";
static String fl_trans = "<EnterWindow>: set() \n\
<LeaveWindow>: unset() \n\
<Btn3Up>: notify() MenuPopdown(popupList)";
static XtCallbackRec fl_callbacks[] = {
{ (XtCallbackProc) GetFolderName, NULL },
{ NULL, NULL }
};
SetCursor(1);
popup = XtNameToWidget(w, "popupList");
if (! popup || popup->core.being_destroyed) {
p = GetMailEnv("folder"); /* returns NULL if none */
if (p && strlen(p)) {
/*
* Don't prepend HOME if it starts with a slash or a .
*/
if (strchr("/.", *p))
strcpy(foldir, p);
else
sprintf(foldir, "%s/%s", getenv("HOME"), p);
XtFree((char *)p);
/*
* Make sure it ends with (only one) slash
*/
if (LASTCH(foldir) != '/')
strcat(foldir, "/");
} else
foldir[0] = '\0'; /* If no folder variable, then no folders */
foldlen = strlen(foldir);
XtSetArg(args[0], XtNtranslations, XtParseTranslationTable(l_Trans));
popup = XtCreatePopupShell("popupList",overrideShellWidgetClass,w,args,1);
if (*foldir) { /* if folder variable exists */
if (mailpid)
List = QueryMail("folders");
else {
if (dirp = opendir(foldir)) { /* and folder is readable... */
List_size = BUFSIZ;
List = XtMalloc(List_size); /* start with a BUFSIZ block */
List[0] = '\0';
x = 0;
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
if (strlen(List) + strlen(dp->d_name) + 2 > List_size) {
List_size += BUFSIZ;
List = XtRealloc(List, List_size);
}
strcat(List, " ");
strcat(List, dp->d_name);
if (++x % 4 == 0) {
x = 0;
strcat(List, "\n");
}
}
List = XtRealloc(List, strlen(List) + 1);
closedir(dirp);
} /* end - if folder directory is readable */
} /* end - if mail process is running */
} /* end - if a folder value exists */
if (List) /* could be null if no current mail */
if (O_BELL == match(&output_pattern, List)) {
strcat(List, "\n");
Bell(List);
XtFree((char *)List);
List = NULL;
}
/*
** determine proper label width by finding longest word length
*/
trans[0] = '\0';
x = 0;
if (List) /* if folders exist and are readable */
for (p = List; *p; p++) {
if (*p == ' ' || *p == '\n' || *p == '\t') {
if (x) {
tmp[x] = '\0';
x = 0;
if (strlen(trans) < strlen(tmp))
strcpy(trans, tmp);
}
} else tmp[x++] = *p;
}
if (x) {
tmp[x] = '\0';
if (strlen(trans) < strlen(tmp))
strcpy(trans, tmp);
}
if ((n = strlen(trans)) == 0) { /* if no folders set dummy width and */
XtSetArg(args[0], XtNwidth, 1); /* height so MenuPopup() */
XtSetArg(args[1], XtNheight, 1); /* won't complain about */
XtSetValues(popup, (ArgList) args, 2); /* zero width or height */
XtDestroyWidget(popup); /* it would be nice if MenuPopup() cared */
} else {
XtSetArg(args[0], XtNdefaultDistance, 1);
lw = XtCreateManagedWidget("list", formWidgetClass, popup, args, ONE);
/*
** Now, make equal width command buttons which contain the folder names
*/
XtSetArg(args[0], XtNwidth, XTextWidth(XMail.buttonFont, trans, n) + 20);
XtSetArg(args[1], XtNfont, XMail.buttonFont);
XtSetArg(args[2], XtNtranslations, XtParseTranslationTable(fl_trans));
XtSetArg(args[3], XtNcallback, fl_callbacks);
above = this_one = to_left = NULL;
for (x = 0, p = List; *p; p++) {
if (*p == '\n') {
newline = 1;
}
if (*p == ' ' || *p == '\n' || *p == '\t') {
if (x) {
tmp[x] = '\0';
/*
** If this 'folder' is really a directory, mark it with a trailing slash '/'
*/
foldir[foldlen] = '\0';
strcat(foldir, &tmp[1]);
if ((dirp = opendir(foldir)) != NULL) {
tmp[x++] = '/';
tmp[x] = '\0';
}
XtSetArg(args[4], XtNlabel, tmp);
XtSetArg(args[5], XtNfromHoriz, to_left); n = 6;
if (! to_left) XtSetArg(args[n], XtNfromVert, above); n++;
this_one = XtCreateManagedWidget("listbutton", commandWidgetClass,
lw, args, n);
if (to_left == NULL) above = this_one;
to_left = this_one;
if (newline) {
newline = 0;
to_left = NULL;
}
x = 0;
/*
** If this 'folder' is a directory, add a button to popup a menu of filenames.
*/
if (dirp) {
closedir(dirp);
sprintf(trans, dir_Trans, &tmp[1], foldir, "0");
XtOverrideTranslations(this_one, XtParseTranslationTable(trans));
AddInfoHandler(this_one, Folder_Info[2]);
} else
AddInfoHandler(this_one, Folder_Info[1]);
}
} else {
if (x == 0) tmp[x++] = '+'; /* start folder names with a 'plus' */
tmp[x++] = *p;
}
}
if (x) {
tmp[x] = '\0';
foldir[foldlen] = '\0';
strcat(foldir, &tmp[1]);
if ((dirp = opendir(foldir)) != NULL) {
tmp[x++] = '/';
tmp[x] = '\0';
}
XtSetArg(args[4], XtNlabel, tmp);
XtSetArg(args[5], XtNfromHoriz, to_left); n = 6;
if (! to_left) XtSetArg(args[n], XtNfromVert, above); n++;
this_one = XtCreateManagedWidget("listbutton", commandWidgetClass,
lw, args, n);
if (dirp) {
closedir(dirp);
sprintf(trans, dir_Trans, &tmp[1], foldir, "0");
XtOverrideTranslations(this_one, XtParseTranslationTable(trans));
AddInfoHandler(this_one, Folder_Info[2]);
} else
AddInfoHandler(this_one, Folder_Info[1]);
}
}
} /* end - if some trans strlen */
/*
** If folders menu exists, pop it up, after setting x,y coordinates
*/
if (popup->core.being_destroyed) {
if (! *foldir)
Bell("No value set for \"folder\"\n");
else {
if (dirp) {
if (! mailpid) {
Bell("No mail folders exist\n");
} else {
foldir[foldlen - 1] = '\0';
sprintf(tmp, "%s not found\n", foldir);
Bell(tmp);
}
}
}
} else {
if (! XtIsRealized(popup))
XtRealizeWidget(popup);
/*
** If folder list is small enough, anchor it to
** the folder button instead of the commandPanel
*/
if (popup->core.width + (3 * (XMail.buttonWidth + 12)) <= XMail.shellWidth)
SetXY(popup, w, XMail.menuX, XMail.buttonHeight / 2);
else
SetXY(popup, XtNameToWidget(toplevel, "topBox.commandPanel"),
XMail.menuX, XMail.commandHeight / 2);
}
if (List)
XtFree((char *)List);
SetCursor(0);
} /* SetFolders */
/*
** @(#)SetMenu() - create a menu for toggling selected mail options
*/
XtActionProc
SetMenu(parent, event, params, num_params)
Widget parent;
XEvent *event; /* unused */
String *params;
Cardinal *num_params;
{
Arg args[6];
Widget menu, layout, previous, next;
char *c, *info, label[BUFSIZ], name[BUFSIZ];
int indx;
static String b_Trans =
"<EnterWindow>: set() \n\
<LeaveWindow>: reset() \n\
<Btn3Up>: notify() unset()";
static String m_Trans =
"<Btn3Up>: MenuPopdown(set_menu)";
static String list[] = { "alwaysignore", "autoprint", "hold", "expert", NULL };
static String set_info[] = {
"Skip 'ignore'd header fields everywhere, not just during a print or read",
"Enable automatic printing of messages after delete and undelete commands",
"Preserve messages in the system mailbox after they have been read",
"Don't ask for confirmation when commiting changes or aborting a new letter",
NULL
};
static String unset_info[] = {
"Skip 'ignore'd header fields only when doing a print or read command",
"Disable automatic printing of messages after delete and undelete commands",
"Move system mailbox messages to the mbox save file after you read them",
"Ask for confirmation before commiting any changes or aborting a new letter",
NULL
};
SetCursor(1);
menu = XtNameToWidget(parent, "set_menu");
if (! menu || menu->core.being_destroyed) {
XtSetArg(args[0], XtNtranslations, XtParseTranslationTable(m_Trans));
menu = XtCreatePopupShell("set_menu",overrideShellWidgetClass,parent,args,1);
XtSetArg(args[0], XtNdefaultDistance, (XtArgVal) 1);
layout = XtCreateManagedWidget("menu", formWidgetClass, menu, args, ONE);
/*
** create the menu buttons
*/
previous = NULL;
XtSetArg(args[0], XtNwidth, figureWidth(XMail.buttonFont) * 18 + 12);
XtSetArg(args[1], XtNfont, XMail.buttonFont);
XtSetArg(args[2], XtNjustify, XtJustifyLeft);
XtSetArg(args[3], XtNtranslations, XtParseTranslationTable(b_Trans));
for (indx = 0; list[indx] != NULL; indx++) {
info = set_info[indx];
strcpy(label, "set ");
if (strcmp(list[indx], "expert") == 0) {
if (XMail.expert) {
info = unset_info[indx];
strcat(label, "no");
}
} else {
if ((c = GetMailEnv(list[indx])) != NULL) {
info = unset_info[indx];
strcat(label, "no");
XtFree(c);
}
}
strcat(label, list[indx]); /* set window name by label */
strcpy(name, &label[4]);
XtSetArg(args[4], XtNlabel, label);
XtSetArg(args[5], XtNfromVert, previous);
next = XtCreateManagedWidget(name, commandWidgetClass, layout, args, 6);
XtAddCallback(next, XtNcallback, (XtCallbackProc) DoSet, NULL);
AddInfoHandler(next, info);
previous = next;
}
} /* end - menu creation */
SetXY(menu, parent, XMail.menuX, XMail.buttonHeight / 2);
SetCursor(0);
} /* SetMenu */
/*
** @(#)SetPopup() - place named popup at menuX, menuY relative to Widget w.
*/
/* ARGSUSED */
XtActionProc
SetPopup(w, event, params, num_params)
Widget w;
XEvent *event; /* unused */
String *params;
Cardinal *num_params;
{
Widget shell;
String p;
SetCursor(1);
if (*num_params == 0)
XtError("xmail had no name parameter passed to SetPopup()");
p = params[0];
if ((shell = XtNameToWidget(w, p)) == NULL)
XtError("xmail shell name passed to SetPopup() not found in list");
SetXY(shell, w, XMail.menuX, XMail.menuY);
SetCursor(0);
} /* SetPopup */
/* ARGSUSED */
/*
** @(#)SetSelect() - flag the index number of the selected message
*/
XtActionProc
SetSelect(w, event, params, num_params)
Widget w; /* unused */
XEvent *event; /* unused */
String *params; /* unused */
Cardinal *num_params; /* unused */
{
markIndex(">");
} /* SetSelect */
/*
** @(#)ShowHelp() - set named string source as text for and popup help window.
*/
/* ARGSUSED */
XtActionProc
ShowHelp(w, event, params, num_params)
Widget w;
XEvent *event;
String *params; /* unused */
Cardinal *num_params; /* unused */
{
String name;
Widget tb;
int x;
SetCursor(1);
name = w->core.name;
if (strcmp(name, "text") == 0 && event->type == KeyPress)
name = "text2";
for (x = 0; x < HelpList.indx; x++)
if (strcmp(name, HelpList.name[x]) == 0) {
tb = XtNameToWidget(toplevel, "topBox");
XawTextSetSource(XtNameToWidget(tb, "help.helpWindow"),
HelpList.text[x], (XawTextPosition) 0);
SetXY(XtNameToWidget(tb, "help"),
XtNameToWidget(tb, "textWindow.text"),
XMail.helpX, XMail.helpY);
SetCursor(0);
XtPopup(XtNameToWidget(tb, "help"), XtGrabNone);
break;
}
} /* ShowHelp */