-fpermissive to allow GCC to compile old C++
[oweals/cde.git] / cde / programs / dtmail / dtmail / ViewMsgDialog.C
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 librararies 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: ViewMsgDialog.C /main/6 1998/01/28 18:35:43 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 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42
43 #include <assert.h>
44 #include <Xm/Label.h>
45 #include <Xm/ScrolledW.h>
46 #include <Xm/DialogS.h>
47 #include <Xm/Form.h>
48 #include <Xm/Text.h>
49 #include <Xm/Protocols.h>
50 #include <Xm/AtomMgr.h>
51 #include <Xm/PushB.h>
52 #include <Xm/MainW.h>
53
54 #include "MainWindow.h"
55 #include "ViewMsgDialog.h"
56 #include "RoamMenuWindow.h"
57 #include "MenuBar.h"
58 #include "RoamApp.h"
59 #include "MailMsg.h"
60 #include "Attachment.h"
61 #include "Help.hh"
62 #include "Help.hh"
63 #include "DtMailHelp.hh"
64
65 // Need the XmTextEditor.  Will eventually need the HP-Editor here!
66 //#include "XmTextEditor.h"
67
68 #include "DtMailEditor.hh"
69
70 extern nl_catd  DtMailMsgCat;
71
72 //#include "CDEM_CoeEd.hh"
73
74
75 // The WM_CLASS_NAME of a VMD is DtMail_SecWin.
76 // SQE's  test suites depend on the WM_CLASS_NAME being a 
77 // constant.  If you are going to change the name, talk to SQE
78 // and get their consent for whatever change you are making.
79
80 ViewMsgDialog::ViewMsgDialog (RoamMenuWindow *parent, WidgetClass wc) :
81 DialogShell ("DtMail_SecWin", parent, wc)
82 {
83     _parent = parent;
84     _workArea = NULL;
85     _menuBar = NULL;
86     my_editor = NULL;
87     _genDialog  = NULL;
88
89     _edit_copy = NULL;
90     _edit_select_all = NULL;
91     
92     _attach_save_as = NULL;
93     _attach_select_all = NULL;
94
95     _attachmentActionsList = NULL;
96     _attachmentMenu = NULL;
97     _attachmentMenuList = NULL;
98     _attachmentPopupMenuList = NULL;
99     _textPopupMenuList = NULL;
100
101     assert( theApplication != NULL );
102
103 }
104
105
106 ViewMsgDialog::~ViewMsgDialog()
107 {
108
109     delete _menuBar;
110     delete      _genDialog;
111
112     delete _edit_copy;
113     delete _edit_select_all;
114
115     delete _attach_save_as;
116     delete _attach_select_all;
117     
118     delete _attachmentActionsList;
119     delete _attachmentMenuList;
120     delete _attachmentPopupMenuList;
121     delete _textPopupMenuList;
122
123     delete my_editor;
124
125 }
126
127
128 Widget 
129 ViewMsgDialog::createWorkArea ( Widget shell )
130 {
131
132     Widget form = XtCreateWidget(
133                         "Work_Area", xmFormWidgetClass,
134                         shell, NULL, 0);
135
136     _main = XtVaCreateManagedWidget ("separateViewWindow", 
137                 xmMainWindowWidgetClass,
138                 form, 
139                 XmNleftAttachment, XmATTACH_FORM,
140                 XmNtopAttachment, XmATTACH_FORM,
141                 XmNbottomAttachment, XmATTACH_FORM,
142                 XmNrightAttachment, XmATTACH_FORM,
143                 NULL);
144
145     Widget form1 = XtCreateWidget("Work_Area", xmFormWidgetClass,
146                                   _main, NULL, 0);
147     printHelpId("form", form1);
148     /* add help callback */
149     // XtAddCallback(form1, XmNhelpCallback, HelpCB, helpId);
150
151
152     my_editor = new DtMailEditor(form1, this);
153     my_editor->initialize();
154
155     my_editor->attachArea()->setOwnerShell(this);
156
157     Widget wid = my_editor->container();
158
159     XtVaSetValues( wid,
160         XmNrightAttachment,XmATTACH_FORM, 
161         XmNleftAttachment,XmATTACH_FORM, 
162         XmNtopAttachment,XmATTACH_FORM, 
163         XmNbottomAttachment, XmATTACH_FORM,
164         NULL );
165
166     XtManageChild(form1);
167
168     return form;
169 }                                
170
171 void
172 ViewMsgDialog::propsChanged(void)
173 {
174 }
175
176 void
177 ViewMsgDialog::text(const char *text, const unsigned long len)
178 {
179
180     my_editor->textEditor()->set_contents(text, len);
181
182 }
183
184 void
185 ViewMsgDialog::append( const char *text, const unsigned long len ){
186   
187     my_editor->textEditor()->append_to_contents(text, len);
188 }
189
190 void 
191 ViewMsgDialog::popped_down()
192 {
193     delete this;
194 }
195
196
197 void
198 ViewMsgDialog::popped_up()
199 {
200     Widget text;
201     Dimension width, height;
202
203     text = _parent->get_editor()->container();
204     
205     XtVaGetValues(text,
206         XmNwidth, &width,
207         XmNheight, &height,
208         NULL);
209
210     XtVaSetValues(_w,
211         XmNx, _parent->x() + (_parent->width() / 2),
212         XmNy, _parent->y() + (_parent->height() /2),
213         NULL );
214
215 }
216
217
218 // SR - added the messages below
219
220 void
221 ViewMsgDialog::initialize()
222 {
223
224     DialogShell::initialize();
225
226     _menuBar = new MenuBar ( _main, "menubar" );
227
228     XtVaSetValues ( _main, 
229                    XmNmenuBar, _menuBar->baseWidget(),
230                    NULL);
231
232     this->construct_edit_menu();
233     this->construct_text_popup();
234     this->construct_attachment_menu();
235     this->construct_attachment_popup();
236     this->construct_help_menu();
237
238     _menuBar->manage();
239
240     _genDialog = new DtMailGenDialog("Dialog", _main);
241
242     XtManageChild(_main);
243 }
244
245
246 void 
247 ViewMsgDialog::quit()
248 {
249     _parent->unregisterDialog(this);
250     delete this;
251 }
252
253 void 
254 ViewMsgDialog::raise()
255 {
256     XRaiseWindow(XtDisplay(_w), XtWindow(_w));
257 }
258
259 DtMailEditor* 
260 ViewMsgDialog::get_editor()
261 {
262
263     return(my_editor);
264
265 }
266
267 void
268 ViewMsgDialog::auto_show_cursor_off()
269 {
270     
271     my_editor->textEditor()->auto_show_cursor_off();
272
273 }
274
275 void
276 ViewMsgDialog::auto_show_cursor_restore()
277 {
278
279     my_editor->textEditor()->auto_show_cursor_restore();
280
281 }
282
283 void
284 ViewMsgDialog::set_to_top()
285 {
286
287     my_editor->textEditor()->set_to_top();
288
289 }
290
291 void
292 ViewMsgDialog::text_selected()
293 {
294
295     // turn on sensitivity for Cut/Clear/Copy/Paste/Delete
296
297 }
298
299 void
300 ViewMsgDialog::text_unselected()
301 {
302
303     // turn off sensitivity for those items
304
305 }
306
307
308 void
309 ViewMsgDialog::attachment_selected()
310 {
311     _attach_save_as->activate();
312 }
313
314
315 void
316 ViewMsgDialog::all_attachments_selected()
317 {
318     _attach_save_as->deactivate();
319     if (_attachmentActionsList != NULL) {
320         _menuBar->removeCommands(_attachmentMenu, _attachmentActionsList);
321         _menuPopupAtt->removeCommands(_attachmentPopupMenu, 
322                                 _attachmentActionsList);
323         delete _attachmentActionsList;
324         _attachmentActionsList = NULL;
325     }
326 }
327
328 void
329 ViewMsgDialog::all_attachments_deselected()
330 {
331     _attach_save_as->deactivate();
332     if (_attachmentActionsList != NULL) {
333         _menuBar->removeCommands(_attachmentMenu, _attachmentActionsList);
334         _menuPopupAtt->removeCommands(_attachmentPopupMenu, 
335                         _attachmentActionsList);
336         delete _attachmentActionsList;
337         _attachmentActionsList = NULL;
338     }
339 }
340
341 void
342 ViewMsgDialog::construct_edit_menu()
343 {
344
345     CmdList *cmdList;
346     
347     _edit_copy = new EditCopyCmd(
348                         "Copy",
349                         GETMSG(DT_catd, 1, 161, "Copy"), 
350                         TRUE, 
351                         this
352                      );
353
354     _edit_select_all = new EditSelectAllCmd(
355                         "Select All",
356                         GETMSG(DT_catd, 1, 162, "Select All"), 
357                         TRUE,
358                         this
359                     );
360
361     cmdList = new CmdList("Edit", GETMSG(DT_catd, 1, 163, "Edit"));
362     cmdList->add(_edit_copy);
363     cmdList->add(_edit_select_all);
364     
365     _menuBar->addCommands(cmdList);
366
367 }
368
369 void
370 ViewMsgDialog::construct_attachment_menu()
371 {
372
373     // Separator for menu items
374     SeparatorCmd *separator = new SeparatorCmd("Separator", "Separator", TRUE );
375
376     _attach_save_as     = new SaveAttachCmd (
377                                 "Save As...",
378                                 GETMSG(DT_catd, 1, 164, "Save As..."),
379                                 GETMSG(DT_catd, 1, 165, "Mailer - Attachments - Save As"),
380                                 FALSE, 
381                                 ViewMsgDialog::save_attachment_callback,
382                                 this,
383                                 this->baseWidget());
384
385     _attach_select_all = new SelectAllAttachsCmd(
386                                 "Select All",
387                                 GETMSG(DT_catd, 1, 166, "Select All"), 
388                                 this);
389
390     _attachmentMenuList = new CmdList( 
391                                 "Attachments",
392                                 GETMSG(DT_catd, 1, 167, "Attachments") );
393
394     _attachmentMenuList->add(_attach_save_as);
395     _attachmentMenuList->add(_attach_select_all);
396
397     _attachmentMenu = _menuBar->addCommands(_attachmentMenuList);
398
399 }
400
401 void
402 ViewMsgDialog::construct_attachment_popup(void)
403 {
404    _attachmentPopupMenuList = new CmdList( "AttachmentsPopup", "AttachmentsPopup");
405
406     LabelCmd *title     = new LabelCmd (
407                         "Mailer - Attachments",
408                         GETMSG(DT_catd, 1, 168, "Mailer - Attachments"), TRUE);
409     SeparatorCmd *separator = new SeparatorCmd("Separator","Separator", TRUE );
410
411     _attachmentPopupMenuList->add(title);
412     _attachmentPopupMenuList->add(separator);
413     _attachmentPopupMenuList->add(_attach_save_as);
414     _attachmentPopupMenuList->add(_attach_select_all);
415     _menuPopupAtt = new MenuBar(my_editor->attachArea()->getClipWindow(), 
416                                         "ViewMsgAttachmentPopup", XmMENU_POPUP);
417     _attachmentPopupMenu = _menuPopupAtt->addCommands(_attachmentPopupMenuList, 
418                                 FALSE, XmMENU_POPUP);
419 }
420
421 void
422 ViewMsgDialog::construct_text_popup(void)
423 {
424    if (theApplication->bMenuButton() != Button3)
425         return;
426
427    _textPopupMenuList = new CmdList("TextPopup", "TextPopup");
428
429     LabelCmd *title     = new LabelCmd (
430                         "Mailer - Text",
431                         GETMSG(DT_catd, 1, 169, "Mailer - Text"), TRUE);
432     SeparatorCmd *separator = new SeparatorCmd("Separator", "Separator", TRUE );
433
434     _textPopupMenuList->add(title);
435     _textPopupMenuList->add(separator);
436     _textPopupMenuList->add(_edit_copy);
437     _textPopupMenuList->add(_edit_select_all);
438
439     Widget parent = my_editor->textEditor()->get_editor();
440     _menuPopupText = new MenuBar(parent, "ViewMsgTextPopup", XmMENU_POPUP);
441     _textPopupMenu = _menuPopupText->addCommands(_textPopupMenuList, 
442                                 FALSE, XmMENU_POPUP);
443 }
444
445
446
447 void
448 ViewMsgDialog::construct_help_menu()
449 {
450     CmdList * cmdList;
451
452     // Separator for menu items
453     
454     SeparatorCmd *separator= new SeparatorCmd("Separator", "Separator", TRUE );
455     _overview = new OnAppCmd("Overview", GETMSG(DT_catd, 1, 170, "Overview"), 
456                                 TRUE, this);
457     _tasks = new TasksCmd("Tasks", GETMSG(DT_catd, 1, 171, "Tasks"), 
458                                 TRUE, this);
459     _reference = new ReferenceCmd("Reference",
460                                 GETMSG(DT_catd, 1, 172, "Reference"), 
461                                 TRUE, this);
462     _on_item = new OnItemCmd("On Item",
463                                 GETMSG(DT_catd, 1, 173, "On Item"), 
464                                 TRUE, this);
465     _using_help = new UsingHelpCmd("Using Help",
466                                 GETMSG(DT_catd, 1, 174, "Using Help"), 
467                                 TRUE, this);
468     cmdList = new CmdList( "Help", GETMSG(DT_catd, 1, 175, "Help") );
469     cmdList->add ( _overview );
470     cmdList->add ( separator );
471     cmdList->add ( _tasks );
472     cmdList->add ( _reference );
473     cmdList->add ( separator );
474     cmdList->add ( _on_item );
475     cmdList->add ( separator );
476     cmdList->add ( _using_help );
477     cmdList->add ( separator );
478
479     _about_mailer = new RelNoteCmd("About Mailer",
480                                     GETMSG(DT_catd, 1, 176, "About Mailer..."),
481                                     TRUE, this);
482     cmdList->add ( _about_mailer );
483
484     // Make help menu show up on right side of menubar.
485     _menuBar->addCommands ( cmdList, TRUE );
486     
487 }
488
489 void
490 ViewMsgDialog::save_attachment_callback(
491     void *client_data,
492     char *selection
493 )
494 {
495     DtMailEnv mail_error;
496
497     // Initialize the mail_error.
498
499     mail_error.clear();
500
501     ViewMsgDialog *obj = (ViewMsgDialog *) client_data;
502
503     obj->save_selected_attachment(selection);
504
505 }
506
507 void
508 ViewMsgDialog::save_selected_attachment(
509     char *selection
510 )
511 {
512    
513     DtMailEnv mail_error;
514     
515     mail_error.clear();
516     DtMailEditor *editor = this->get_editor();
517     AttachArea *attacharea = editor->attachArea();
518     Attachment *attachment = attacharea->getSelectedAttachment();
519
520    // Get selected attachment, if none selected, then return.
521    if ( attachment == NULL ) {
522           // Let User know that no attachment has been selected???
523           int answer = 0;
524           char *helpId = NULL;
525
526
527           _genDialog->setToErrorDialog(
528                     GETMSG(DT_catd, 1, 177, "Mailer"),            
529                     GETMSG(DT_catd, 2, 20, "An attachment needs to be selected before issuing the\n\"Save As\" command to save to a file.") );
530           helpId = DTMAILHELPSELECTATTACH;
531           answer = _genDialog->post_and_return(
532                         GETMSG(DT_catd, 3, 75, "OK"), helpId );
533           return;
534       }
535
536     attachment->saveToFile(mail_error, selection);
537
538     if (mail_error.isSet()) {
539         // do something
540     }
541
542 }
543
544 void
545 ViewMsgDialog::manage()
546 {
547
548     Widget text;
549     Dimension width, height;
550
551     text = _parent->get_editor()->container();
552     
553     XtVaGetValues(text,
554         XmNwidth, &width,
555         XmNheight, &height,
556         NULL);
557
558     XtVaSetValues(_w,
559         XmNx, _parent->x() + (_parent->width() / 2),
560         XmNy, _parent->y() + (_parent->height() /2),
561         NULL );
562
563     DialogShell::manage();
564
565 }
566
567 void
568 ViewMsgDialog::addAttachmentActions(
569     char **actions,
570     int indx
571 )
572 {
573     int i;
574     char *anAction;
575     AttachmentActionCmd *attachActionCmd;
576     
577     if (_attachmentActionsList == NULL) { 
578         _attachmentActionsList = new CmdList("AttachmentActions",
579                                              "AttachmentActions");
580     }
581     else {
582         _menuBar->removeCommands(_attachmentMenu, _attachmentActionsList);
583         _menuPopupAtt->removeCommands(_attachmentPopupMenu, 
584                                         _attachmentActionsList);
585         delete _attachmentActionsList;
586         _attachmentActionsList = new CmdList("AttachmentActions",
587                                              "AttachmentActions");
588     }
589
590     char *actionLabel;
591     for (i = 0; i < indx; i++) {
592         anAction = actions[i];
593         actionLabel = DtActionLabel(anAction);  // get the localized action label
594         attachActionCmd = new AttachmentActionCmd(
595                                         anAction,
596                                         actionLabel,
597                                         this,
598                                         i);
599         _attachmentActionsList->add(attachActionCmd);
600         
601     }
602     _attachmentMenu = _menuBar->addCommands(
603                                 _attachmentMenu, 
604                                 _attachmentActionsList
605                         );
606
607     _attachmentPopupMenu = _menuPopupAtt->addCommands(
608                                 _attachmentPopupMenu, 
609                                 _attachmentActionsList);
610
611 }
612
613
614 void
615 ViewMsgDialog::removeAttachmentActions()
616 {
617
618     // Stubbed out for now
619 }
620
621 void
622 ViewMsgDialog::invokeAttachmentAction(
623     int index
624 )
625 {
626     DtMailEditor *editor = this->get_editor();
627     AttachArea *attacharea = editor->attachArea();
628     Attachment *attachment = attacharea->getSelectedAttachment();
629
630     attachment->invokeAction(index);
631
632 }
633
634 void
635 ViewMsgDialog::selectAllAttachments()
636 {
637     
638     DtMailEditor *editor = this->get_editor();
639     AttachArea *attachArea = editor->attachArea();
640     
641     attachArea->selectAllAttachments();
642
643 }
644
645 void
646 ViewMsgDialog::activate_default_attach_menu()
647 {
648     _attach_select_all->activate();
649 }
650
651 void
652 ViewMsgDialog::deactivate_default_attach_menu()
653 {
654     _attach_select_all->deactivate();
655 }
656
657
658 void
659 ViewMsgDialog::showAttachArea()
660 {
661     DtMailEditor *editor = this->get_editor();
662     editor->showAttachArea();
663 }
664
665 void
666 ViewMsgDialog::hideAttachArea()
667 {
668     DtMailEditor *editor = this->get_editor();
669     editor->hideAttachArea();
670 }
671
672
673 void
674 ViewMsgDialog::attachmentFeedback(
675     Boolean bval
676 )
677 {
678     if (bval) {
679         this->busyCursor();
680     }
681     else {
682         this->normalCursor();
683     }
684 }