XmListDeletePos (list_w, cbs−>item_position);
/* it's a long way, but traverse to To: text field */
XmProcessTraversal (list_w, XmTRAVERSE_NEXT_TAB_GROUP);
}
/* send_it() −− callback for when user clicked on Send. Build
* a command line, use popen() to open pipe to mail command, send
* text data to it and then exit. The message is sent to all
* of the addresses that have been specified and are shown in the
* list.
*/
void
send_it(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
Widget send_w;
XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
char *text, *subj, cmd[BUFSIZ], *p, *dummy, *getenv();
int n, i, status;
XmString *list;
FILE *pp, *popen();
if (w == text_w) {
send_w = (Widget) client_data;
XtCallActionProc (send_w, "ArmAndActivate", cbs−>event, NULL, 0);
return;
}
/* if something was left in the To: field, grab it */
text = XmTextGetString (to_w);
if (text != 0 && *text != 0) {
XmString str = XmStringCreateLocalized (text);
XmListAddItemUnselected (list_w, str, 0);
XmTextSetString (to_w, "");
XmStringFree (str);
XtFree (text);
}
/* Get the list of users entered */
XtVaGetValues (list_w,
XmNitems, &list,
XmNitemCount, &n,
NULL);
if (n == 0) {
static Widget dialog;
/* user goofed −− must provide at least one recipient */
if (!dialog) {
Arg args[5];
n = 0;
XtSetArg (args[n], XmNdialogStyle,
XmDIALOG_APPLICATION_MODAL); n++;
dialog = XmCreateErrorDialog (to_w, "error", args, n);
XtUnmanageChild (
XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
XtUnmanageChild (
XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON));
}
XtManageChild (dialog);
return;
28 Additional Example Programs 28 Additional Example Programs
747
}
/* get the subject (may be empty) */
subj = XmTextGetString (subj_w);
/* build command line */
if (!(p = getenv ("MAIL_CMD")))
p = MAIL_CMD;
p = strcpy (cmd, p);
p += strlen (cmd);
*p++ = ' ';
if (subj && *subj) {
/* if subject not empty, add to mail command */
sprintf (p, "−s
p += strlen (p);
}
/* Add each user in the List to the command line */
for (i = 0; i < n; i++) {
XmStringGetLtoR (list[i], XmFONTLIST_DEFAULT_TAG, &dummy);
p += strlen (strcpy (p, dummy));
if (i < n−1) /* more to come yet... */
*p++ = ',', *p++ = ' '; /* separate addresses w/commas */
}
/* open pipe to mail command */
if (!(pp = popen (cmd, "w"))) {
fprintf (stderr, "Can't execute");
perror (cmd);
return;
}
/* give it the text user typed (may be empty) */
text = XmTextGetString (text_w);
fputs (text, pp);
fputc ('0, pp); /* make sure there's a terminating newline */
status = pclose (pp); /* close mail program */
XtFree (text);
XtFree (subj);
if (status == 0) {
XmTextSetString (to_w, NULL);
XmTextSetString (text_w, NULL);
XmTextSetString (subj_w, NULL);
XmListDeleteAllItems (list_w);
}
/* send complete −− start back at beginning */
XmProcessTraversal (w, XmTRAVERSE_HOME);
}
/* move() −− callback for when the user hits return in the Text widget */
void
move(text_w, client_data, call_data)
Widget text_w;
XtPointer client_data;
XtPointer call_data;
{
XmProcessTraversal (text_w, XmTRAVERSE_NEXT_TAB_GROUP);
}
/* CreateLabeledTextForm() −− create a Form widget that has a label on
* the left and a Text widget to the right. Attach perimeter edges to
28 Additional Example Programs 28 Additional Example Programs
748
* form. We use it twice in the program, so make a function out of it.
*/
Widget
CreateLabeledTextForm(parent, label_name, text_name)
Widget parent;
char *label_name, *text_name;
{
Widget form, label, ret;
form = XtVaCreateWidget ("form",
xmFormWidgetClass, parent,
XmNorientation, XmHORIZONTAL,
NULL);
label = XtVaCreateManagedWidget (label_name,
xmLabelGadgetClass, form,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
ret = XtVaCreateManagedWidget (text_name,
xmTextWidgetClass, form,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, label,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
XtManageChild (form);
return ret;
}
the figure shows the output of the program.
Output of zcard.c
28 Additional Example Programs 28 Additional Example Programs
749

Get Volume 6A: Motif Programming Manual now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.