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