Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / dtmail / SendMsgDialog.h
1 /*
2  *+SNOTICE
3  *
4  * $TOG: SendMsgDialog.h /main/17 1999/03/25 13:43:01 mgreess $
5  *
6  * RESTRICTED CONFIDENTIAL INFORMATION:
7  * 
8  * The information in this document is subject to special
9  * restrictions in a confidential disclosure agreement between
10  * HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
11  * document outside HP, IBM, Sun, USL, SCO, or Univel without
12  * Sun's specific written approval.  This document and all copies
13  * and derivative works thereof must be returned or destroyed at
14  * Sun's request.
15  *
16  * Copyright 1993, 1994, 1995 Sun Microsystems, Inc.  All rights reserved.
17  *
18  *+ENOTICE
19  */
20
21 #ifndef SENDMSGDIALOG_H
22 #define SENDMSGDIALOG_H
23
24 //#include "Editor.hh"
25 //#include "CDEM_CoeEd.hh"
26 //#include "XmTextEditor.h"
27
28 #include "DtMailEditor.hh"
29 #include "MenuWindow.h"
30 #include "NoUndoCmd.h"
31 #include "RoamApp.h"
32 #include "RoamCmds.h"
33 #include "RoamMenuWindow.h"
34 #include "DtMailGenDialog.hh"
35 #include "DtVirtArray.hh"
36
37 class MailBox;
38 class Cmd;
39
40 // This is the Compose window.
41 class SendMsgDialog : public MenuWindow, public AbstractEditorParent {
42   public:
43     enum ShowState {
44         SMD_ALWAYS,
45         SMD_SHOWN,
46         SMD_HIDDEN,
47         SMD_NEVER
48         };
49     
50     struct HeaderList {
51         char            *label;
52         char            *header;
53         char            *value;
54         ShowState       show;
55         Widget          form_widget;
56         Widget          label_widget;
57         Widget          field_widget;
58         HeaderList(void);
59         HeaderList(const HeaderList &);
60         ~HeaderList(void);
61         };
62
63     Widget GetMainWin() { return _main_form; }
64     void   setTitle(char *title);
65     
66   private:
67     
68     Widget      _main_form;
69     DtMailEditor  *_my_editor;
70     DtMailGenDialog *_genDialog; 
71
72     Boolean _takeDown;
73     Boolean _first_time;
74     Boolean _already_sending;  // Flag to make sure we don't send more than once.
75     Boolean _show_attach_area;
76
77     int     _confirm_attachment_threshold;
78     int     confirm_add_attachment(char*, int);
79     int     get_confirm_attachment_threshold(void);
80     
81     Cmd *_send_button;
82     Cmd *_close_button;
83
84     Cmd *_separator;
85     
86     // File Menu items
87     
88     UnifiedSelectFileCmd *_file_include;
89     SaveAsTextCmd *_file_save_as;
90     Cmd *_file_log;
91     Cmd *_file_send;
92     Cmd *_file_sendAs[10];   // Assume 10 transports.
93     Cmd *_file_close;
94     
95     // Edit Menu items
96     
97     Cmd *_edit_undo;
98     Cmd *_edit_cut;
99     Cmd *_edit_copy;
100     Cmd *_edit_paste;
101     Cmd *_edit_paste_special[2];
102     Cmd *_edit_clear;
103     Cmd *_edit_delete;
104     Cmd *_edit_select_all;
105
106     // Alias Popup Menus
107     
108     DtVirtArray <PropStringPair *> *_aliasList;
109     CmdList *_bccPopupCmdlist;
110     Widget   _bccPopupMenu;
111     MenuBar *_bccPopupMenuBar;
112     CmdList *_ccPopupCmdlist;
113     Widget   _ccPopupMenu;
114     MenuBar *_ccPopupMenuBar;
115     CmdList *_toPopupCmdlist;
116     Widget   _toPopupMenu;
117     MenuBar *_toPopupMenuBar;
118     
119     // Text Popup Menu
120     //
121     // Found in Editor.hh
122     //
123     //MenuBar   *_menuPopupText;
124     //Widget    _textPopupMenu;
125     //
126     CmdList *_textPopupMenuList;
127     
128     // Attachment
129     Widget   _attachmentMenu;
130     CmdList *_attachmentMenuList;
131     CmdList *_attachmentPopupMenuList;
132     CmdList *_attachmentActionsList;
133
134     SaveAttachCmd  *_att_save;
135     UnifiedSelectFileCmd *_att_add;
136     Cmd *_att_delete;
137     Cmd *_att_undelete;
138     Cmd *_att_rename;
139     Cmd *_att_select_all;
140     Cmd *_att_show_pane;
141
142     void  construct_attachment_popup(void);
143     void  construct_text_popup(void);
144     
145     // Format
146     
147     Cmd *_format_word_wrap;
148     Cmd *_format_settings;
149     Cmd *_format_find_change;
150     Cmd *_format_spell;
151     Cmd *_format_bcc;    // Depends on Properties setting.
152     Cmd *_format_separator;
153     Widget      _format_menu;
154     CmdList     *_format_cmds;
155     CmdList     *_templates;
156     Widget      _format_cascade;
157     
158     Widget _status_form;
159     Widget _status_text;
160
161     int _num_sendAs;    // Number of Transports available through Back End.
162     int   _template_count; // Number of templates loaded.
163     char *_templateList; // names of templates
164     
165     
166     // The header list keeps track of the current headers on the Format
167     // menu, as well as their current state in the compose header region.
168     DtVirtArray<HeaderList *>   _header_list;
169     DtMailBoolean               _headers_changed;
170     Widget                      _header_form;
171     char                        *_additionalfields;
172     
173     // Help
174     Cmd *_overview;
175     Cmd *_tasks;
176     Cmd *_reference;
177     Cmd *_on_item;
178     Cmd *_using_help;
179     Cmd *_about_mailer;
180
181     // This is the internal data structure used for submission.
182     // As user adds/deletes attachment, this data structure is update immediately.
183     // This data structure is also updated at periodic checkpoints to store the
184     // latest Compose window data.
185     // Before sending, this is also updated.
186     DtMail::Message *_msgHandle;   
187     
188     // Pointer to the message that is being included as an attachment.
189     // When updateMsgHndAtt() is called, data in this handle is copied to _msgHandle.
190     DtMail::Message *_inclMsgHandle;
191     
192     // Pointer to the last Attachment BodyPart so that newBodyPart(error, _lastAttBP)
193     // returns a message body part after the last body part.  This is so that
194     // attachments will be ordered properly.
195     DtMail::BodyPart *_lastAttBP;
196     
197     // When makeMessage() is called, it creates a message handle with its
198     // first body part empty.  If set to TRUE, then this boolean variable
199     // indicates that the first body part of _msgHandle has already been used
200     // (probably for text).  Otherwise, the first body part can be used for attachment.
201     Boolean _firstBPHandled;
202     
203     // updateMsgHndAtt() uses this Boolean variable to determine whether the
204     // current message handle to be copied contains a text body part or not.
205     Boolean _inclMsgHasText;
206     
207     // The auto save interval id is used to stop the interval timer for auto
208     // saving.
209     //
210     XtIntervalId _auto_save_interval;
211     char * _auto_save_path;
212     char * _auto_save_file;
213     
214     char * _dead_letter_buf;
215     
216     DtMailBoolean _log_msg;
217     
218     void   mkAutoSavePath();
219     static void autoSaveCallback(XtPointer, XtIntervalId *id);
220     void   doAutoSave(void);
221     void   doAutoSave(char *);
222     int    getAutoSaveInterval(void);
223     
224     void   addTemplates(CmdList*); // Create the initial template menu.
225     Widget getHeaderWidget(const char *);
226     static void   aliasMenuButtonHandler(
227                         Widget,
228                         XtPointer client_data,
229                         XEvent *event,
230                         Boolean *);
231     void   createAliasList(DtVirtArray<PropStringPair*> *aliases);
232     void   destroyAliasList(DtVirtArray<PropStringPair*> *aliases);
233     Widget createAliasPopupMenu(
234                         Widget parent,
235                         MenuBar** menubar,
236                         CmdList** cmdlist,
237                         DtVirtArray<PropStringPair*> *aliases);
238     void   destroyAliasPopupMenu(
239                         Widget  parent,
240                         MenuBar *menubar,
241                         CmdList *cmdlist,
242                         Widget  menu);
243     void   createAliasPopupMenus();
244     void   destroyAliasPopupMenus();
245     void   createFormatMenu();
246     void   createMenuPanes();
247     Widget createWorkArea(Widget);
248     void   createHeaders(Widget header);
249     void   doDynamicHeaderMenus(void);
250     Boolean reservedHeader(const char *label);
251
252     void valueToAddrText(Widget, DtMailValueSeq &);
253     
254     // File selection Box callbacks 
255     static void include_file_cb( void *, char * );
256     static void add_att_cb( void *, char * );
257     static void save_att_cb( void *, char * );
258     
259     // Return a message handle -- internal data structure of a mail message.
260     DtMail::Message * makeMessage(void);
261     // Clear Compose window text fields to prepare for re-use.
262     void reset();
263
264     // Find a header in the list by name.
265     //
266     int lookupHeader(const char * name);
267     static void headerValueChanged(Widget, XtPointer, XtPointer);
268     void reattachHeaders(void);
269     void justifyHeaders(void);
270     void forceFormResize(Widget);
271
272     // Called when the sendmail child process completes
273     static void sendmailErrorProc (int pid, int status, void *data);
274     void popupMemoryError(DtMailEnv &error);
275
276   public:
277     SendMsgDialog();
278     virtual ~SendMsgDialog();
279     virtual const char *const className () { return "SendMsgDialog"; }
280     void initialize();
281     void send_message( const char *, int );
282
283     void include_file(char *);
284     void add_att(char *);
285     void add_att(char *, DtMailBuffer);
286     void add_att(DtMailBuffer);
287     void setMsgHnd();    // initialize _msgHandle.
288     void startAutoSave(void);
289     void stopAutoSave(void);
290     void setLogState(DtMailBoolean state) { _log_msg = state; }
291     void propsChanged(void);
292     Boolean isMsgValid(void);   // checks to see whether _msgHandle is NULL
293     
294     void setLastAttBP();
295     void setLastAttBP(DtMail::BodyPart *);
296     void setFirstBPHandled(Boolean);
297
298     void attachmentFeedback(Boolean);
299
300     // The set/get Header methods manage the dynamic header structures.
301     //
302     void setHeader(const char * name, const char * value);
303     void setHeader(const char * name, DtMailValueSeq & value);
304     void getHeader(const char * name, char ** value);
305     void resetHeaders(void);
306     void setInputFocus(const int mode);
307
308     // This method returns true if the user has edited the headers.
309     //
310     DtMailBoolean headersChanged(void) { return _headers_changed; }
311
312     // The load/store Headers methods will reload the pane from a message,
313     // or store the header pane values to the message. Specifying NULL will
314     // load the header pane from the current value for _msgHandle.
315     // If load_all is true, then all headers are loaded, and fields are
316     // added as necessary to the header pane. Otherwise, the list of shown
317     // headers are loaded and all others are ignored.
318     //
319     // storeHeaders transfers the currently stored headers to the specified
320     // message object, or the internal message if none is specified.
321     //
322     void loadHeaders(DtMail::Message * msg = NULL,
323                      DtMailBoolean load_all = DTM_FALSE);
324     void storeHeaders(DtMail::Message * msg = NULL);
325
326     // Check if a message has addressees.  If a message is Sent and
327     // it has no addressees, we need to barf.
328
329     Boolean hasAddressee();
330
331     // The changeHeaderState method toggles the dynamic headers between
332     // shown an hidden. It will also update the menu label accordingly.
333     //
334     void changeHeaderState(const char * name);
335
336     // unfilled_headers returns TRUE if no header has a value.
337     // FaLSE if any header has a value
338
339     Boolean unfilled_headers();
340
341     // The set/clear Status methods will set and clear the status line.
342     //
343     void setStatus(const char * str);
344     void clearStatus(void);
345
346     // XSMP support
347     static void         restoreSession(char*);
348     virtual int         smpSaveSessionGlobal();
349     virtual void        smpSaveSessionLocal();
350     
351     // These are public so that the check point routine can call
352     // updateMsgHnd, and include/forward routines can call updateMsgHndAtt.
353     void updateMsgHnd();
354     void updateMsgHndAtt();
355     
356     char *text();
357     
358     DtMailEditor* get_editor() {return _my_editor; }
359     
360     // Mutators
361     
362     void setInclMsgHnd(DtMail::Message *, Boolean);
363     void text( const char * );
364     void append( const char * );
365     void quit(Boolean delete_win = FALSE);
366     void panicQuit();
367
368     // Method to check if self has content in it.
369     Boolean checkDirty();
370     Boolean handleQuitDialog();
371     void    goAway(Boolean);
372
373     // Add the specified file (first parameter) as attachment.
374     void inclAsAttmt( char *, char *);
375     // Add the content of the buffer as attachment.
376     void inclAsAttmt( unsigned char *, int, char *);
377     // Parse the buffer and fill the Compose window with data.
378     void parseNplace( char *, int );
379     // Parse the file and fill the Compose window with data.
380     void parseNplace(const char * path);
381     
382     // Load the dead letter file.
383     void loadDeadLetter(const char * path);
384     
385     // SR - Text-selection callbacks.
386     
387     virtual void text_selected();
388     virtual void text_unselected();
389     void attachment_selected();
390     void all_attachments_deselected();
391     void all_attachments_selected();
392     void selectAllAttachments(); 
393     
394     
395     DtMailGenDialog *genDialog() { return _genDialog; }  
396     
397     void showAttachArea();
398     void hideAttachArea();
399     
400     void activate_default_attach_menu();
401     void deactivate_default_attach_menu();
402     
403     // Activate and deactivate paste stuff
404     void activate_edit_paste() { _edit_paste->activate(); }
405     void activate_edit_paste_indented() {_edit_paste_special[0]->activate();}
406     void activate_edit_paste_bracketed() {_edit_paste_special[1]->activate();}
407     
408     void delete_selected_attachments();
409     
410     void undelete_last_deleted_attachment();
411     
412     void save_selected_attachment(char *);
413     void save_selected_msg_text(char *);
414     
415     Boolean renameAttachmentOK();
416     
417     void addAttachmentActions(char **, int);
418     void removeAttachmentActions();
419     void invokeAttachmentAction(int);   
420
421     virtual void manage();
422     virtual void unmanage();
423
424 };
425
426
427 // Manager of all compose windows.
428 class Compose {
429     
430   public:
431     Compose();
432     virtual ~Compose();
433     virtual const char *const className () { return "Compose"; }
434
435     SendMsgDialog       *getWin();
436     SendMsgDialog       *getUnusedWin();
437     XtIntervalId         getTimeOutId() { return _timeout_id; }
438     int                  numCreatedWindows() { return _num_created; }
439     int                  numUnusedWindows() { return _not_in_use; }
440     void                 putWin(SendMsgDialog*, Boolean);
441     void                 putTimeOutId(XtIntervalId id) { _timeout_id = id; }
442     void                 Self_destruct(XtPointer, XtIntervalId*);
443   
444     
445   private:
446     struct Compose_Win
447     {
448         SendMsgDialog *win;
449         struct Compose_Win *next;
450         Boolean in_use;
451     };
452
453     Compose_Win *_compose_head; // List of compose windows.
454     int          _not_in_use;   // Number of unused compose windows.
455     int          _num_created;  // Total number of compose windows created.
456     XtIntervalId _timeout_id;   // Self destruct id.
457 };
458
459 extern Compose theCompose;
460
461 #ifdef DTMAIL_TOOLTALK
462 extern int started_by_tt;
463 #endif
464
465 #endif
466
467