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