1/*
2 * $XConsortium: compfuncs.c,v 2.18 92/04/08 12:20:08 rws Exp $
3 *
4 *
5 * 		      COPYRIGHT 1987, 1989
6 *		   DIGITAL EQUIPMENT CORPORATION
7 *		       MAYNARD, MASSACHUSETTS
8 *			ALL RIGHTS RESERVED.
9 *
10 * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
11 * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
12 * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR
13 * ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
14 *
15 * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
16 * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
17 * ADDITION TO THAT SET FORTH ABOVE.
18 *
19 * Permission to use, copy, modify, and distribute this software and its
20 * documentation for any purpose and without fee is hereby granted, provided
21 * that the above copyright notice appear in all copies and that both that
22 * copyright notice and this permission notice appear in supporting
23 * documentation, and that the name of Digital Equipment Corporation not be
24 * used in advertising or publicity pertaining to distribution of the software
25 * without specific, written prior permission.
26 */
27/* $XFree86: xc/programs/xmh/compfuncs.c,v 1.2 2001/08/01 00:45:06 tsi Exp $ */
28
29/* comp.c -- action procedures to handle composition buttons. */
30
31#include "xmh.h"
32#include "actions.h"
33
34/* Reset this composition widget to be one with just a blank message
35   template. */
36
37/*ARGSUSED*/
38void DoResetCompose(
39    Widget	widget,		/* unused */
40    XtPointer	client_data,
41    XtPointer	call_data)	/* unused */
42{
43    Scrn	scrn = (Scrn) client_data;
44    Msg		msg;
45    XtCallbackRec	confirms[2];
46
47    confirms[0].callback = (XtCallbackProc) DoResetCompose;
48    confirms[0].closure = (XtPointer) scrn;
49    confirms[1].callback = (XtCallbackProc) NULL;
50    confirms[1].closure = (XtPointer) NULL;
51
52    if (MsgSetScrn((Msg) NULL, scrn, confirms, (XtCallbackList) NULL) ==
53	NEEDS_CONFIRMATION)
54	return;
55
56    msg = TocMakeNewMsg(DraftsFolder);
57    MsgLoadComposition(msg);
58    MsgSetTemporary(msg);
59    MsgSetReapable(msg);
60    (void) MsgSetScrn(msg, scrn, (XtCallbackList) NULL, (XtCallbackList) NULL);
61}
62
63/*ARGSUSED*/
64void XmhResetCompose(
65    Widget	w,
66    XEvent	*event,
67    String	*params,
68    Cardinal	*num_params)
69{
70    Scrn scrn = ScrnFromWidget(w);
71    DoResetCompose(w, (XtPointer) scrn, (XtPointer) NULL);
72}
73
74
75/* Send the message in this widget.  Avoid sending the same message twice.
76   (Code elsewhere actually makes sure this button is disabled to avoid
77   sending the same message twice, but it doesn't hurt to be safe here.) */
78
79/*ARGSUSED*/
80void XmhSend(
81    Widget	w,
82    XEvent	*event,
83    String	*params,
84    Cardinal	*num_params)
85{
86    Scrn scrn = ScrnFromWidget(w);
87    if (scrn->msg == NULL) return;
88    if (MsgChanged(scrn->msg) || ! MsgGetReapable(scrn->msg)) {
89	MsgSend(scrn->msg);
90	MsgSetReapable(scrn->msg);
91    }
92}
93
94
95/* Save any changes to the message.  This also makes this message permanent. */
96
97/*ARGSUSED*/
98void XmhSave(
99    Widget	w,
100    XEvent	*event,
101    String	*params,
102    Cardinal	*num_params)
103{
104    Scrn scrn = ScrnFromWidget(w);
105    DEBUG("XmhSave\n")
106    if (scrn->msg == NULL) return;
107    MsgSetPermanent(scrn->msg);
108    if (MsgSaveChanges(scrn->msg))
109	MsgClearReapable(scrn->msg);
110}
111
112
113/* Utility routine; creates a composition screen containing a forward message
114   of the messages in the given msglist. */
115
116void CreateForward(
117  MsgList mlist,
118  String *params,
119  Cardinal num_params)
120{
121    Scrn scrn;
122    Msg msg;
123    scrn = NewCompScrn();
124    msg = TocMakeNewMsg(DraftsFolder);
125    MsgLoadForward(scrn, msg, mlist, params, num_params);
126    MsgSetTemporary(msg);
127    MsgSetScrnForComp(msg, scrn);
128    MapScrn(scrn);
129}
130