1c9e2be55Smrg/*
2c9e2be55Smrg * $XConsortium: viewfuncs.c,v 2.23 92/04/08 12:18:41 rws Exp $
3c9e2be55Smrg *
4c9e2be55Smrg *
5c9e2be55Smrg *		       COPYRIGHT 1987, 1989
6c9e2be55Smrg *		   DIGITAL EQUIPMENT CORPORATION
7c9e2be55Smrg *		       MAYNARD, MASSACHUSETTS
8c9e2be55Smrg *			ALL RIGHTS RESERVED.
9c9e2be55Smrg *
10c9e2be55Smrg * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
11c9e2be55Smrg * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
12c9e2be55Smrg * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR
13c9e2be55Smrg * ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
14c9e2be55Smrg *
15c9e2be55Smrg * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
16c9e2be55Smrg * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
17c9e2be55Smrg * ADDITION TO THAT SET FORTH ABOVE.
18c9e2be55Smrg *
19c9e2be55Smrg * Permission to use, copy, modify, and distribute this software and its
20c9e2be55Smrg * documentation for any purpose and without fee is hereby granted, provided
21c9e2be55Smrg * that the above copyright notice appear in all copies and that both that
22c9e2be55Smrg * copyright notice and this permission notice appear in supporting
23c9e2be55Smrg * documentation, and that the name of Digital Equipment Corporation not be
24c9e2be55Smrg * used in advertising or publicity pertaining to distribution of the software
25c9e2be55Smrg * without specific, written prior permission.
26c9e2be55Smrg */
27c9e2be55Smrg/* $XFree86$ */
28c9e2be55Smrg
29c9e2be55Smrg/* view.c -- action procedures to handle viewing of a message */
30c9e2be55Smrg
31c9e2be55Smrg#include "xmh.h"
32c9e2be55Smrg#include "actions.h"
33c9e2be55Smrg
34c9e2be55Smrg/*ARGSUSED*/
35c9e2be55Smrgvoid DoCloseView(
36c9e2be55Smrg    Widget	widget,		/* unused */
37c9e2be55Smrg    XtPointer	client_data,
38c9e2be55Smrg    XtPointer	call_data)	/* unused */
39c9e2be55Smrg{
40c9e2be55Smrg    Scrn scrn = (Scrn) client_data;
41c9e2be55Smrg    XtCallbackRec	confirms[2];
42c9e2be55Smrg
43c9e2be55Smrg    confirms[0].callback = DoCloseView;
44c9e2be55Smrg    confirms[0].closure = (XtPointer) scrn;
45c9e2be55Smrg    confirms[1].callback = (XtCallbackProc) NULL;
46c9e2be55Smrg    confirms[1].closure = (XtPointer) NULL;
47d859ff80Smrg
48c9e2be55Smrg    if (MsgSetScrn((Msg) NULL, scrn, confirms, (XtCallbackList) NULL) ==
49c9e2be55Smrg	NEEDS_CONFIRMATION)
50c9e2be55Smrg	return;
51c9e2be55Smrg    DestroyScrn(scrn);
52c9e2be55Smrg}
53d859ff80Smrg
54c9e2be55Smrg
55c9e2be55Smrg/*ARGSUSED*/
56c9e2be55Smrgvoid XmhCloseView(
57c9e2be55Smrg    Widget	w,
58c9e2be55Smrg    XEvent	*event,
59c9e2be55Smrg    String	*params,
60c9e2be55Smrg    Cardinal	*num_params)
61c9e2be55Smrg{
62c9e2be55Smrg    Scrn scrn = ScrnFromWidget(w);
63c9e2be55Smrg    DoCloseView(w, (XtPointer) scrn, (XtPointer) NULL);
64c9e2be55Smrg}
65c9e2be55Smrg
66c9e2be55Smrg
67c9e2be55Smrgstatic void DoViewReplyMsg(
68c9e2be55Smrg    Scrn	scrn,
69c9e2be55Smrg    String	*params,
70c9e2be55Smrg    Cardinal	num_params)
71c9e2be55Smrg{
72c9e2be55Smrg    Msg		msg;
73c9e2be55Smrg    Scrn	nscrn;
74c9e2be55Smrg
75c9e2be55Smrg    if (scrn->msg == NULL) return;
76c9e2be55Smrg    nscrn = NewCompScrn();
77c9e2be55Smrg    ScreenSetAssocMsg(nscrn, scrn->msg);
78c9e2be55Smrg    msg = TocMakeNewMsg(DraftsFolder);
79c9e2be55Smrg    MsgSetTemporary(msg);
80c9e2be55Smrg    MsgLoadReply(msg, scrn->msg, params, num_params);
81c9e2be55Smrg    MsgSetScrnForComp(msg, nscrn);
82c9e2be55Smrg    MapScrn(nscrn);
83c9e2be55Smrg}
84c9e2be55Smrg
85c9e2be55Smrg/*ARGSUSED*/
86c9e2be55Smrgvoid DoViewReply(
87c9e2be55Smrg    Widget	w,
88c9e2be55Smrg    XtPointer	client_data,
89c9e2be55Smrg    XtPointer	call_data)
90c9e2be55Smrg{
91c9e2be55Smrg    DoViewReplyMsg((Scrn) client_data, (String *)NULL, (Cardinal)0);
92c9e2be55Smrg}
93c9e2be55Smrg
94c9e2be55Smrg
95c9e2be55Smrg
96c9e2be55Smrg/*ARGSUSED*/
97c9e2be55Smrgvoid XmhViewReply(
98c9e2be55Smrg    Widget	w,
99c9e2be55Smrg    XEvent	*event,
100c9e2be55Smrg    String	*params,
101c9e2be55Smrg    Cardinal	*num_params)
102c9e2be55Smrg{
103c9e2be55Smrg    Scrn scrn = ScrnFromWidget(w);
104c9e2be55Smrg    DoViewReplyMsg(scrn, params, *num_params);
105c9e2be55Smrg}
106c9e2be55Smrg
107c9e2be55Smrg
108c9e2be55Smrg/*ARGSUSED*/
109c9e2be55Smrgstatic void DoViewForwardMsg(
110c9e2be55Smrg    Scrn	scrn,
111c9e2be55Smrg    String	*params,
112c9e2be55Smrg    Cardinal	num_params)
113c9e2be55Smrg{
114c9e2be55Smrg    MsgList	mlist;
115c9e2be55Smrg
116c9e2be55Smrg    if (scrn->msg == NULL) return;
117c9e2be55Smrg    mlist = MakeSingleMsgList(scrn->msg);
118c9e2be55Smrg    CreateForward(mlist, params, num_params);
119c9e2be55Smrg    FreeMsgList(mlist);
120c9e2be55Smrg}
121c9e2be55Smrg
122c9e2be55Smrg/*ARGSUSED*/
123c9e2be55Smrgvoid DoViewForward(
124c9e2be55Smrg    Widget	w,
125c9e2be55Smrg    XtPointer	client_data,
126c9e2be55Smrg    XtPointer	call_data)
127c9e2be55Smrg{
128c9e2be55Smrg    DoViewForwardMsg((Scrn) client_data, (String *)NULL, (Cardinal)0);
129c9e2be55Smrg}
130c9e2be55Smrg
131c9e2be55Smrg/*ARGSUSED*/
132c9e2be55Smrgvoid XmhViewForward(
133c9e2be55Smrg    Widget	w,
134c9e2be55Smrg    XEvent	*event,
135c9e2be55Smrg    String	*params,
136c9e2be55Smrg    Cardinal	*num_params)
137c9e2be55Smrg{
138c9e2be55Smrg    DoViewForwardMsg(ScrnFromWidget(w), params, *num_params);
139c9e2be55Smrg}
140c9e2be55Smrg
141c9e2be55Smrg
142c9e2be55Smrg/*ARGSUSED*/
143c9e2be55Smrgvoid DoViewUseAsComposition(
144c9e2be55Smrg    Widget	w,
145c9e2be55Smrg    XtPointer	client_data,
146c9e2be55Smrg    XtPointer	call_data)
147c9e2be55Smrg{
148c9e2be55Smrg    Scrn	scrn = (Scrn) client_data;
149c9e2be55Smrg    Msg		msg;
150c9e2be55Smrg    Scrn	nscrn;
151c9e2be55Smrg
152c9e2be55Smrg    if (scrn->msg == NULL) return;
153c9e2be55Smrg    nscrn = NewCompScrn();
154c9e2be55Smrg    if (MsgGetToc(scrn->msg) == DraftsFolder)
155c9e2be55Smrg	msg = scrn->msg;
156c9e2be55Smrg    else {
157c9e2be55Smrg	msg = TocMakeNewMsg(DraftsFolder);
158c9e2be55Smrg	MsgLoadCopy(msg, scrn->msg);
159c9e2be55Smrg	MsgSetTemporary(msg);
160c9e2be55Smrg    }
161c9e2be55Smrg    MsgSetScrnForComp(msg, nscrn);
162c9e2be55Smrg    MapScrn(nscrn);
163c9e2be55Smrg}
164d859ff80Smrg
165c9e2be55Smrg
166c9e2be55Smrg/*ARGSUSED*/
167c9e2be55Smrgvoid XmhViewUseAsComposition(
168c9e2be55Smrg    Widget	w,
169c9e2be55Smrg    XEvent	*event,
170c9e2be55Smrg    String	*params,
171c9e2be55Smrg    Cardinal	*num_params)
172c9e2be55Smrg{
173c9e2be55Smrg    Scrn	scrn = ScrnFromWidget(w);
174c9e2be55Smrg    DoViewUseAsComposition(w, (XtPointer) scrn, (XtPointer) NULL);
175c9e2be55Smrg}
176c9e2be55Smrg
177c9e2be55Smrg
178c9e2be55Smrg/*ARGSUSED*/
179c9e2be55Smrgvoid DoEditView(
180c9e2be55Smrg    Widget	w,
181c9e2be55Smrg    XtPointer	client_data,
182c9e2be55Smrg    XtPointer	call_data)
183c9e2be55Smrg{
184c9e2be55Smrg    Scrn	scrn = (Scrn) client_data;
185c9e2be55Smrg    Arg		args[1];
186c9e2be55Smrg    XtTranslations editTranslations = scrn->edit_translations;
187c9e2be55Smrg
188c9e2be55Smrg    if (scrn->msg == NULL) return;
189c9e2be55Smrg    XtSetArg(args[0], XtNtranslations, editTranslations);
190c9e2be55Smrg    XtSetValues(scrn->viewwidget, args, (Cardinal) 1);
191c9e2be55Smrg    MsgSetEditable(scrn->msg);
192c9e2be55Smrg}
193c9e2be55Smrg
194c9e2be55Smrg
195c9e2be55Smrg/*ARGSUSED*/
196c9e2be55Smrgvoid XmhEditView(
197c9e2be55Smrg    Widget	w,
198c9e2be55Smrg    XEvent	*event,
199c9e2be55Smrg    String	*params,
200c9e2be55Smrg    Cardinal	*num_params)
201c9e2be55Smrg{
202c9e2be55Smrg    Scrn	scrn = ScrnFromWidget(w);
203c9e2be55Smrg    if (scrn->msg != NULL && ! MsgGetEditable(scrn->msg))
204c9e2be55Smrg	DoEditView(w, (XtPointer) scrn, (XtPointer) NULL);
205c9e2be55Smrg}
206c9e2be55Smrg
207c9e2be55Smrg
208c9e2be55Smrg/*ARGSUSED*/
209c9e2be55Smrgvoid DoSaveView(
210c9e2be55Smrg    Widget	w,
211c9e2be55Smrg    XtPointer	client_data,
212c9e2be55Smrg    XtPointer	call_data)
213c9e2be55Smrg{
214c9e2be55Smrg    Scrn	scrn = (Scrn) client_data;
215c9e2be55Smrg    Arg		args[2];
216c9e2be55Smrg
217c9e2be55Smrg    if (scrn->msg == NULL) return;
218c9e2be55Smrg    if (MsgSaveChanges(scrn->msg)) {
219c9e2be55Smrg	XtSetArg(args[0], XtNtranslations, scrn->read_translations);
220c9e2be55Smrg	XtSetValues(scrn->viewwidget, args, (Cardinal) 1);
221c9e2be55Smrg	MsgClearEditable(scrn->msg);
222c9e2be55Smrg    }
223c9e2be55Smrg}
224c9e2be55Smrg
225c9e2be55Smrg
226c9e2be55Smrg/*ARGSUSED*/
227c9e2be55Smrgvoid XmhSaveView(
228c9e2be55Smrg    Widget	w,
229c9e2be55Smrg    XEvent	*event,
230c9e2be55Smrg    String	*params,
231c9e2be55Smrg    Cardinal	*num_params)
232c9e2be55Smrg{
233c9e2be55Smrg    Scrn	scrn = ScrnFromWidget(w);
234c9e2be55Smrg    if (MsgChanged(scrn->msg) || MsgGetReapable(scrn->msg))
235c9e2be55Smrg	DoSaveView(w, (XtPointer) scrn, (XtPointer) NULL);
236c9e2be55Smrg}
237c9e2be55Smrg
238c9e2be55Smrg
239c9e2be55Smrg/*ARGSUSED*/
240c9e2be55Smrgvoid DoPrintView(
241c9e2be55Smrg    Widget	w,
242c9e2be55Smrg    XtPointer	client_data,
243c9e2be55Smrg    XtPointer	call_data)
244c9e2be55Smrg{
245c9e2be55Smrg    Scrn	scrn = (Scrn) client_data;
246c9e2be55Smrg    char	**argv;
247c9e2be55Smrg    char	str[200];
248c9e2be55Smrg
249c9e2be55Smrg    if (! scrn->msg) return;
25066d665a3Smrg    snprintf(str, sizeof(str), "%s %s", app_resources.print_command,
251c9e2be55Smrg		   MsgFileName(scrn->msg));
252c9e2be55Smrg    argv = MakeArgv(3);
253c9e2be55Smrg    argv[0] = "/bin/sh";
254c9e2be55Smrg    argv[1] = "-c";	/* commands are read from the next argument */
255c9e2be55Smrg    argv[2] = str;
256c9e2be55Smrg    (void) DoCommand(argv, (char*)NULL, (char*)NULL);
257c9e2be55Smrg    /* a "notice" popup should appear with any stderr output */
258c9e2be55Smrg    XtFree((char*)argv);
259c9e2be55Smrg}
260c9e2be55Smrg
261c9e2be55Smrg
262c9e2be55Smrg/*ARGSUSED*/
263c9e2be55Smrgvoid XmhPrintView(
264c9e2be55Smrg    Widget	w,
265c9e2be55Smrg    XEvent	*event,
266c9e2be55Smrg    String	*params,
267c9e2be55Smrg    Cardinal	*num_params)
268c9e2be55Smrg{
269c9e2be55Smrg    Scrn scrn = ScrnFromWidget(w);
270c9e2be55Smrg    DoPrintView(w, (XtPointer) scrn, (XtPointer) NULL);
271c9e2be55Smrg}
272c9e2be55Smrg
273c9e2be55Smrg
274c9e2be55Smrg/*ARGSUSED*/
275c9e2be55Smrgvoid XmhViewMarkDelete(
276c9e2be55Smrg    Widget	w,
277c9e2be55Smrg    XEvent	*event,
278c9e2be55Smrg    String	*params,
279c9e2be55Smrg    Cardinal	*num_params)
280c9e2be55Smrg{
281c9e2be55Smrg    Scrn scrn = ScrnFromWidget(w);
282c9e2be55Smrg    if (scrn->msg == NULL) return;
283c9e2be55Smrg    MsgSetFate(scrn->msg, Fdelete, (Toc)NULL);
284c9e2be55Smrg}
285c9e2be55Smrg
286c9e2be55Smrg
287