2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
26 * $TOG: ViewMsgDialog.C /main/6 1998/01/28 18:35:43 mgreess $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
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
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
45 #include <Xm/ScrolledW.h>
46 #include <Xm/DialogS.h>
49 #include <Xm/Protocols.h>
50 #include <Xm/AtomMgr.h>
54 #include "MainWindow.h"
55 #include "ViewMsgDialog.h"
56 #include "RoamMenuWindow.h"
60 #include "Attachment.h"
63 #include "DtMailHelp.hh"
65 // Need the XmTextEditor. Will eventually need the HP-Editor here!
66 //#include "XmTextEditor.h"
68 #include "DtMailEditor.hh"
70 extern nl_catd DtMailMsgCat;
72 //#include "CDEM_CoeEd.hh"
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.
80 ViewMsgDialog::ViewMsgDialog (RoamMenuWindow *parent, WidgetClass wc) :
81 DialogShell ("DtMail_SecWin", parent, wc)
90 _edit_select_all = NULL;
92 _attach_save_as = NULL;
93 _attach_select_all = NULL;
95 _attachmentActionsList = NULL;
96 _attachmentMenu = NULL;
97 _attachmentMenuList = NULL;
98 _attachmentPopupMenuList = NULL;
99 _textPopupMenuList = NULL;
101 assert( theApplication != NULL );
106 ViewMsgDialog::~ViewMsgDialog()
113 delete _edit_select_all;
115 delete _attach_save_as;
116 delete _attach_select_all;
118 delete _attachmentActionsList;
119 delete _attachmentMenuList;
120 delete _attachmentPopupMenuList;
121 delete _textPopupMenuList;
129 ViewMsgDialog::createWorkArea ( Widget shell )
132 Widget form = XtCreateWidget(
133 "Work_Area", xmFormWidgetClass,
136 _main = XtVaCreateManagedWidget ("separateViewWindow",
137 xmMainWindowWidgetClass,
139 XmNleftAttachment, XmATTACH_FORM,
140 XmNtopAttachment, XmATTACH_FORM,
141 XmNbottomAttachment, XmATTACH_FORM,
142 XmNrightAttachment, XmATTACH_FORM,
145 Widget form1 = XtCreateWidget("Work_Area", xmFormWidgetClass,
147 printHelpId("form", form1);
148 /* add help callback */
149 // XtAddCallback(form1, XmNhelpCallback, HelpCB, helpId);
152 my_editor = new DtMailEditor(form1, this);
153 my_editor->initialize();
155 my_editor->attachArea()->setOwnerShell(this);
157 Widget wid = my_editor->container();
160 XmNrightAttachment,XmATTACH_FORM,
161 XmNleftAttachment,XmATTACH_FORM,
162 XmNtopAttachment,XmATTACH_FORM,
163 XmNbottomAttachment, XmATTACH_FORM,
166 XtManageChild(form1);
172 ViewMsgDialog::propsChanged(void)
177 ViewMsgDialog::text(const char *text, const unsigned long len)
180 my_editor->textEditor()->set_contents(text, len);
185 ViewMsgDialog::append( const char *text, const unsigned long len ){
187 my_editor->textEditor()->append_to_contents(text, len);
191 ViewMsgDialog::popped_down()
198 ViewMsgDialog::popped_up()
201 Dimension width, height;
203 text = _parent->get_editor()->container();
211 XmNx, _parent->x() + (_parent->width() / 2),
212 XmNy, _parent->y() + (_parent->height() /2),
218 // SR - added the messages below
221 ViewMsgDialog::initialize()
224 DialogShell::initialize();
226 _menuBar = new MenuBar ( _main, "menubar" );
228 XtVaSetValues ( _main,
229 XmNmenuBar, _menuBar->baseWidget(),
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();
240 _genDialog = new DtMailGenDialog("Dialog", _main);
242 XtManageChild(_main);
247 ViewMsgDialog::quit()
249 _parent->unregisterDialog(this);
254 ViewMsgDialog::raise()
256 XRaiseWindow(XtDisplay(_w), XtWindow(_w));
260 ViewMsgDialog::get_editor()
268 ViewMsgDialog::auto_show_cursor_off()
271 my_editor->textEditor()->auto_show_cursor_off();
276 ViewMsgDialog::auto_show_cursor_restore()
279 my_editor->textEditor()->auto_show_cursor_restore();
284 ViewMsgDialog::set_to_top()
287 my_editor->textEditor()->set_to_top();
292 ViewMsgDialog::text_selected()
295 // turn on sensitivity for Cut/Clear/Copy/Paste/Delete
300 ViewMsgDialog::text_unselected()
303 // turn off sensitivity for those items
309 ViewMsgDialog::attachment_selected()
311 _attach_save_as->activate();
316 ViewMsgDialog::all_attachments_selected()
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;
329 ViewMsgDialog::all_attachments_deselected()
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;
342 ViewMsgDialog::construct_edit_menu()
347 _edit_copy = new EditCopyCmd(
349 GETMSG(DT_catd, 1, 161, "Copy"),
354 _edit_select_all = new EditSelectAllCmd(
356 GETMSG(DT_catd, 1, 162, "Select All"),
361 cmdList = new CmdList("Edit", GETMSG(DT_catd, 1, 163, "Edit"));
362 cmdList->add(_edit_copy);
363 cmdList->add(_edit_select_all);
365 _menuBar->addCommands(cmdList);
370 ViewMsgDialog::construct_attachment_menu()
373 // Separator for menu items
374 SeparatorCmd *separator = new SeparatorCmd("Separator", "Separator", TRUE );
376 _attach_save_as = new SaveAttachCmd (
378 GETMSG(DT_catd, 1, 164, "Save As..."),
379 GETMSG(DT_catd, 1, 165, "Mailer - Attachments - Save As"),
381 ViewMsgDialog::save_attachment_callback,
385 _attach_select_all = new SelectAllAttachsCmd(
387 GETMSG(DT_catd, 1, 166, "Select All"),
390 _attachmentMenuList = new CmdList(
392 GETMSG(DT_catd, 1, 167, "Attachments") );
394 _attachmentMenuList->add(_attach_save_as);
395 _attachmentMenuList->add(_attach_select_all);
397 _attachmentMenu = _menuBar->addCommands(_attachmentMenuList);
402 ViewMsgDialog::construct_attachment_popup(void)
404 _attachmentPopupMenuList = new CmdList( "AttachmentsPopup", "AttachmentsPopup");
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 );
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);
422 ViewMsgDialog::construct_text_popup(void)
424 if (theApplication->bMenuButton() != Button3)
427 _textPopupMenuList = new CmdList("TextPopup", "TextPopup");
429 LabelCmd *title = new LabelCmd (
431 GETMSG(DT_catd, 1, 169, "Mailer - Text"), TRUE);
432 SeparatorCmd *separator = new SeparatorCmd("Separator", "Separator", TRUE );
434 _textPopupMenuList->add(title);
435 _textPopupMenuList->add(separator);
436 _textPopupMenuList->add(_edit_copy);
437 _textPopupMenuList->add(_edit_select_all);
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);
448 ViewMsgDialog::construct_help_menu()
452 // Separator for menu items
454 SeparatorCmd *separator= new SeparatorCmd("Separator", "Separator", TRUE );
455 _overview = new OnAppCmd("Overview", GETMSG(DT_catd, 1, 170, "Overview"),
457 _tasks = new TasksCmd("Tasks", GETMSG(DT_catd, 1, 171, "Tasks"),
459 _reference = new ReferenceCmd("Reference",
460 GETMSG(DT_catd, 1, 172, "Reference"),
462 _on_item = new OnItemCmd("On Item",
463 GETMSG(DT_catd, 1, 173, "On Item"),
465 _using_help = new UsingHelpCmd("Using Help",
466 GETMSG(DT_catd, 1, 174, "Using Help"),
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 );
479 _about_mailer = new RelNoteCmd("About Mailer",
480 GETMSG(DT_catd, 1, 176, "About Mailer..."),
482 cmdList->add ( _about_mailer );
484 // Make help menu show up on right side of menubar.
485 _menuBar->addCommands ( cmdList, TRUE );
490 ViewMsgDialog::save_attachment_callback(
495 DtMailEnv mail_error;
497 // Initialize the mail_error.
501 ViewMsgDialog *obj = (ViewMsgDialog *) client_data;
503 obj->save_selected_attachment(selection);
508 ViewMsgDialog::save_selected_attachment(
513 DtMailEnv mail_error;
516 DtMailEditor *editor = this->get_editor();
517 AttachArea *attacharea = editor->attachArea();
518 Attachment *attachment = attacharea->getSelectedAttachment();
520 // Get selected attachment, if none selected, then return.
521 if ( attachment == NULL ) {
522 // Let User know that no attachment has been selected???
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 );
536 attachment->saveToFile(mail_error, selection);
538 if (mail_error.isSet()) {
545 ViewMsgDialog::manage()
549 Dimension width, height;
551 text = _parent->get_editor()->container();
559 XmNx, _parent->x() + (_parent->width() / 2),
560 XmNy, _parent->y() + (_parent->height() /2),
563 DialogShell::manage();
568 ViewMsgDialog::addAttachmentActions(
575 AttachmentActionCmd *attachActionCmd;
577 if (_attachmentActionsList == NULL) {
578 _attachmentActionsList = new CmdList("AttachmentActions",
579 "AttachmentActions");
582 _menuBar->removeCommands(_attachmentMenu, _attachmentActionsList);
583 _menuPopupAtt->removeCommands(_attachmentPopupMenu,
584 _attachmentActionsList);
585 delete _attachmentActionsList;
586 _attachmentActionsList = new CmdList("AttachmentActions",
587 "AttachmentActions");
591 for (i = 0; i < indx; i++) {
592 anAction = actions[i];
593 actionLabel = DtActionLabel(anAction); // get the localized action label
594 attachActionCmd = new AttachmentActionCmd(
599 _attachmentActionsList->add(attachActionCmd);
602 _attachmentMenu = _menuBar->addCommands(
604 _attachmentActionsList
607 _attachmentPopupMenu = _menuPopupAtt->addCommands(
608 _attachmentPopupMenu,
609 _attachmentActionsList);
615 ViewMsgDialog::removeAttachmentActions()
618 // Stubbed out for now
622 ViewMsgDialog::invokeAttachmentAction(
626 DtMailEditor *editor = this->get_editor();
627 AttachArea *attacharea = editor->attachArea();
628 Attachment *attachment = attacharea->getSelectedAttachment();
630 attachment->invokeAction(index);
635 ViewMsgDialog::selectAllAttachments()
638 DtMailEditor *editor = this->get_editor();
639 AttachArea *attachArea = editor->attachArea();
641 attachArea->selectAllAttachments();
646 ViewMsgDialog::activate_default_attach_menu()
648 _attach_select_all->activate();
652 ViewMsgDialog::deactivate_default_attach_menu()
654 _attach_select_all->deactivate();
659 ViewMsgDialog::showAttachArea()
661 DtMailEditor *editor = this->get_editor();
662 editor->showAttachArea();
666 ViewMsgDialog::hideAttachArea()
668 DtMailEditor *editor = this->get_editor();
669 editor->hideAttachArea();
674 ViewMsgDialog::attachmentFeedback(
682 this->normalCursor();