123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /*
- * $TOG: MessageMgr.C /main/13 1998/07/27 14:20:49 mgreess $
- *
- * Copyright (c) 1991 HaL Computer Systems, Inc. All rights reserved.
- * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
- * States. Use of a copyright notice is precautionary only and does not
- * imply publication or disclosure.
- *
- * This software contains confidential information and trade secrets of HaL
- * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
- * without the prior express written permission of HaL Computer Systems, Inc.
- *
- * RESTRICTED RIGHTS LEGEND
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 252.227-7013.
- * HaL Computer Systems, Inc.
- * 1315 Dell Avenue, Campbell, CA 95008
- *
- */
- # include "UAS.hh"
- #define C_MessageAgent
- #define C_VersionAgent
- #define C_Agent
- #define L_Agents
- #define C_MessageMgr
- #define C_Manager
- #define C_MarkMgr
- #define L_Managers
- #include "Prelude.h"
- #include "Managers/CatMgr.hh"
- #include "Registration.hh"
- #include "Other/XmStringLocalized.hh"
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- LONG_LIVED_CC (MessageMgr,message_mgr);
- #define CLASS MessageMgr
- STATIC_SENDER_CC(UAS_CancelRetrievalMsg);
- //static int progressDisplayed = 0;
- class DisplayDocumentError : public UAS_Receiver<UAS_ErrorMsg>
- {
- public:
- DisplayDocumentError()
- { UAS_Common::request (this); }
- private:
- void receive (UAS_ErrorMsg &message, void *client_data);
- };
- void
- DisplayDocumentError::receive (UAS_ErrorMsg &message, void *client_data)
- {
- const char *text = message.fErrorMsg;
- if (text == NULL)
- text = (char*)UAS_String(CATGETS(Set_Messages, 35, "File a Bug"));
- message_mgr().error_dialog ((char *) text);
- }
- static DisplayDocumentError error_displayer;
- class ReportSearchMsg : public UAS_Receiver<UAS_SearchMsg>
- {
- public:
- ReportSearchMsg() { UAS_SearchEngine::request (this); }
- private:
- void receive (UAS_SearchMsg &message, void *client_data);
- };
- void
- ReportSearchMsg::receive (UAS_SearchMsg &message, void *client_data)
- {
- if (message.fSearchMsg) {
- bool cont = message_mgr().question_dialog(message.fSearchMsg);
- message.fContFlag = cont? 1 : 0;
- }
- else {
- message_mgr().error_dialog(
- (char*)UAS_String(CATGETS(Set_Messages, 36, "File a Bug")));
- }
- }
- static ReportSearchMsg g_search_msg_reporter;
- class DisplayDocumentProgress: public UAS_Receiver<UAS_StatusMsg>,
- public UAS_Receiver<UAS_DocumentRetrievedMsg> {
- public:
- DisplayDocumentProgress () {
- UAS_Common::request ((UAS_Receiver<UAS_StatusMsg> *) this);
- UAS_Common::request ((UAS_Receiver<UAS_DocumentRetrievedMsg> *) this);
- }
- public:
- void receive (UAS_StatusMsg &msg, void *client_data);
- void receive (UAS_DocumentRetrievedMsg &msg, void *client_data);
- };
- void
- DisplayDocumentProgress::receive (UAS_StatusMsg &msg, void *client_data) {
- message_mgr().progress_dialog (msg.fText);
- }
- void
- DisplayDocumentProgress::receive (UAS_DocumentRetrievedMsg &, void *client_data) {
- message_mgr().progress_dialog_done ();
- }
- static DisplayDocumentProgress progress_displayer;
- // /////////////////////////////////////////////////////////////////
- // class constructor
- // /////////////////////////////////////////////////////////////////
- MessageMgr::MessageMgr() :
- f_booklist_message (*(new MessageAgent())),
- f_nodeview_message (*(new MessageAgent())),
- f_booklist_process(0),
- f_nodeview_process(0),
- f_popped_up(False),
- f_pressed_ok(False),
- f_exit_flag(False)
- {
- MessageAgent::request ((UAS_Receiver<CancelOperation> *) this);
- }
- // /////////////////////////////////////////////////////////////////
- // class destructor
- // /////////////////////////////////////////////////////////////////
- MessageMgr::~MessageMgr()
- {
- g_message_mgr = NULL;
- }
- void
- okCB(Widget, XtPointer client_data, XtPointer)
- {
- MessageMgr* mgr = (MessageMgr*)client_data;
- mgr->ok_cb();
- }
- void
- cancelCB(Widget, XtPointer client_data, XtPointer)
- {
- MessageMgr* mgr = (MessageMgr*)client_data;
- mgr->cancel_cb();
- }
- void
- MessageMgr::ok_cb()
- {
- if (f_exit_flag) {
- mark_mgr().finalize ();
- UAS_Common::finalize ();
- ::exit (0);
- }
- f_pressed_ok = True;
- f_popped_up = False;
- }
- void
- MessageMgr::cancel_cb()
- {
- f_pressed_ok = False;
- f_popped_up = False;
- }
- void
- MessageMgr::show_it(Widget dialog)
- {
- Widget parent = NULL;
- Widget shell = NULL;
- XtManageChild(dialog);
- if (dialog) parent = XtParent(dialog);
- if (parent) shell = XtParent(parent);
- if (NULL == shell) shell = parent;
- XtPopup(shell, XtGrabNone);
- XMapRaised(XtDisplay(shell), XtWindow(shell));
- f_popped_up = True;
- f_pressed_ok = False;
-
- XEvent event;
- while(f_popped_up)
- {
- XtAppNextEvent (window_system().app_context(), &event);
- XtDispatchEvent (&event);
- }
- }
- void
- MessageMgr::destroy_it(Widget dialog)
- {
- Widget shell = XtParent(dialog);
- XtPopdown(shell);
- XtUnmanageChild(dialog);
- XtDestroyWidget(dialog);
- }
- Widget
- MessageMgr::create_dialog (unsigned char dialog_type,
- char *message_text,
- Widget parent)
- {
- Widget dialog;
- // determine the parent of the dialog shell
- if(parent == NULL)
- {
- Window window;
- int revert;
- XGetInputFocus(window_system().display(), &window, &revert);
- parent = XtWindowToWidget(window_system().display(), window);
- if(parent == NULL)
- parent = window_system().toplevel();
- }
- dialog = XmCreateMessageDialog(parent, (char*)"dialog", NULL, 0);
- WXmString wxms = message_text;
- XtVaSetValues(dialog,
- XmNdialogType, dialog_type,
- XmNmessageAlignment, XmALIGNMENT_CENTER,
- XmNmessageString, (XmString)wxms,
- NULL);
- // add callbacks
- XtAddCallback(dialog, XmNokCallback, okCB, this);
- XtAddCallback(dialog, XmNcancelCallback, cancelCB, this);
- return dialog;
- }
- // /////////////////////////////////////////////////////////////////
- // quit dialog
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::quit_dialog (char *message_text, Widget parent)
- {
- //if(parent == NULL)
- //parent = (Widget)window_system().toplevel();
- //Widget dialog = XmCreateQuestionDialog(parent, "dialog", NULL, 0);
- Widget dialog = create_dialog(XmDIALOG_QUESTION, message_text, parent);
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
- XtVaSetValues(dialog,
- XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
- XmNmessageAlignment, XmALIGNMENT_CENTER,
- NULL);
- // Set labels on buttons
- XmStringLocalized mtfstring;
- mtfstring = CATGETS(Set_AgentLabel, 244, "Yes");
- XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON),
- XmNlabelString, (XmString)mtfstring,
- NULL);
- mtfstring = CATGETS(Set_AgentLabel, 245, "No");
- XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON),
- XmNlabelString, (XmString)mtfstring,
- NULL);
- // Set the window title
- Widget shell = XtParent(dialog);
- String string = CATGETS(Set_MessageAgent, 5, "Dtinfo: Confirm Quit");
- XtVaSetValues(shell,
- XmNminWidth, 200,
- XmNtitle, (XmString)string,
- NULL);
- // Set the flag for the OK button
- f_exit_flag = True;
- show_it(dialog);
- f_exit_flag = False;
- destroy_it(dialog);
- #if 0
- if(parent == NULL)
- f_booklist_message.displayQuit(message_text, window_system().toplevel());
- else
- f_nodeview_message.displayQuit(message_text, parent);
- //f_message_agent.displayQuit (message_text, parent);
- #endif
- }
- // /////////////////////////////////////////////////////////////////
- // error dialog
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::error_dialog (char *message_text, Widget parent)
- {
- Widget dialog = create_dialog(XmDIALOG_ERROR, message_text, parent);
- //Widget dialog = XmCreateErrorDialog(parent, "dialog", NULL, 0);
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
- XtVaSetValues(dialog,
- XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
- XmNmessageAlignment, XmALIGNMENT_BEGINNING,
- NULL);
- // Set the window title
- Widget shell = XtParent(dialog);
- String string = CATGETS(Set_MessageAgent, 1, "Dtinfo: Error");
- XtVaSetValues(shell, XmNtitle, string, NULL);
- show_it(dialog);
- destroy_it(dialog);
- #if 0
- if(parent == NULL)
- f_booklist_message.displayError(message_text, window_system().toplevel());
- else
- f_nodeview_message.displayError(message_text, parent);
- //f_message_agent.displayError (message_text, parent);
- #endif
- }
- // /////////////////////////////////////////////////////////////////
- // warning dialog
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::warning_dialog (char *message_text, Widget parent)
- {
- Widget dialog = create_dialog(XmDIALOG_WARNING, message_text, parent);
- //Widget dialog = XmCreateWarningDialog(parent, "dialog", NULL, 0);
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
- XtVaSetValues(dialog,
- XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
- XmNmessageAlignment, XmALIGNMENT_BEGINNING,
- NULL);
- // Set the window title
- Widget shell = XtParent(dialog);
- String string = CATGETS(Set_MessageAgent, 2, "Dtinfo: Warning");
- XtVaSetValues(shell, XmNtitle, string, NULL);
- show_it(dialog);
- XtPopdown(shell);
- XtUnmanageChild(dialog);
- XtDestroyWidget(dialog);
- #if 0
- if(parent == NULL)
- f_booklist_message.displayWarning(message_text, window_system().toplevel());
- else
- f_nodeview_message.displayWarning(message_text, parent);
- //f_message_agent.displayWarning (message_text, parent);
- #endif
- }
- // /////////////////////////////////////////////////////////////////
- // information dialog
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::info_dialog (char *message_text, Widget parent)
- {
- Widget dialog = create_dialog(XmDIALOG_INFORMATION, message_text, parent);
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
- // Set the window title
- Widget shell = XtParent(dialog);
- String string = CATGETS(Set_MessageAgent, 3, "Dtinfo: Information");
- XtVaSetValues(shell, XmNtitle, string, NULL);
- show_it(dialog);
- destroy_it(dialog);
- #if 0
- if(parent == NULL)
- f_booklist_message.displayInformation(message_text, window_system().toplevel());
- else
- f_nodeview_message.displayInformation(message_text, parent);
- //f_message_agent.displayInformation (message_text, parent);
- #endif
- }
- // /////////////////////////////////////////////////////////////////
- // progress dialog
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::progress_dialog (char *message_text, Widget parent) {
- // MessageAgent::request ((UAS_Receiver<CancelOperation> *) this);
- //progressDisplayed = 1;
- if(parent == NULL)
- {
- f_booklist_message.displayProgress (
- message_text, window_system().toplevel());
- f_booklist_process = 1;
- }
- else
- {
- f_nodeview_message.displayProgress (message_text, parent);
- f_nodeview_process = 1;
- }
- }
- // /////////////////////////////////////////////////////////////////
- // progress dialog done
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::progress_dialog_done () {
- // MessageAgent::unrequest ((UAS_Receiver<CancelOperation> *) this);
- if (f_booklist_process)
- f_booklist_message.undisplayProgress ();
- if (f_nodeview_process)
- f_nodeview_message.undisplayProgress ();
- }
- // /////////////////////////////////////////////////////////////////
- // question dialog
- // /////////////////////////////////////////////////////////////////
- bool
- MessageMgr::question_dialog (char *message_text, Widget parent)
- {
- if(parent == NULL)
- parent = (Widget)window_system().toplevel();
- Widget dialog = XmCreateInformationDialog(parent, (char*)"dialog", NULL, 0);
- XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
- WXmString wxms = message_text;
- XtVaSetValues(dialog,
- XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
- XmNmessageAlignment, XmALIGNMENT_CENTER,
- XmNmessageString, (XmString)wxms,
- NULL);
- // Set labels on buttons
- XmStringLocalized mtfstring;
- mtfstring = CATGETS(Set_AgentLabel, 244, "Yes");
- XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON),
- XmNlabelString, (XmString)mtfstring,
- NULL);
- mtfstring = CATGETS(Set_AgentLabel, 245, "No");
- XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON),
- XmNlabelString, (XmString)mtfstring,
- NULL);
- XtAddCallback(dialog, XmNokCallback, okCB, this);
- XtAddCallback(dialog, XmNcancelCallback, cancelCB, this);
- // Set the window title
- Widget shell = XtParent(dialog);
- String string = CATGETS(Set_MessageAgent, 3, "Dtinfo: Information");
- XtVaSetValues(shell, XmNtitle, string, NULL);
- show_it(dialog);
- XtPopdown(shell);
- XtUnmanageChild(dialog);
- XtDestroyWidget(dialog);
- return(f_pressed_ok);
- #if 0
- if(parent == NULL)
- return(f_booklist_message.displayQuestion(
- message_text, window_system().toplevel()));
- else
- return(f_nodeview_message.displayQuestion(message_text, parent));
- //return (f_message_agent.displayQuestion (message_text, parent));
- #endif
- }
- int
- MessageMgr::get_integer(const char *msg, const char* title,
- int default_value, Widget parent)
- {
- if(parent == NULL)
- return (f_booklist_message.get_integer (msg, title, default_value, window_system().toplevel()));
- else
- return (f_nodeview_message.get_integer (msg, title, default_value, parent));
- }
- const char *
- MessageMgr::get_string (const char* msg, const char* title,
- const char *default_value, Widget parent)
- {
- if(parent == NULL)
- return (f_booklist_message.get_string (msg, title, default_value, window_system().toplevel()));
- else
- return (f_nodeview_message.get_string (msg, title, default_value, parent));
- }
- // /////////////////////////////////////////////////////////////////
- // assert_failed
- // /////////////////////////////////////////////////////////////////
- void
- MessageMgr::assert_failed (char *statement, char *file,
- int line, Widget parent)
- {
- char buffer[512];
- snprintf (buffer, sizeof(buffer),
- "An internal error has occured.\n\
- The current operation cannot be completed.\n\
- Please file a bug report with this information:\n\
- Assertion failed: %s\n\
- File \"%s,\" line %d.",
- statement, file, line);
-
- if(parent == NULL)
- f_booklist_message.displayError (buffer, window_system().toplevel());
- else
- f_nodeview_message.displayError (buffer, parent);
- quit_dialog ((char*)"We strongly suggest you quit now, Ok?", parent);
- }
- // /////////////////////////////////////////////////////////////////////////
- // demo_failure
- //
- // put up error message. quit application when dialog returns
- //
- // /////////////////////////////////////////////////////////////////////////
- void
- MessageMgr::demo_failure(demoException &, Widget parent)
- {
- error_dialog(
- (char*)UAS_String(CATGETS(Set_Messages, 38, "File a Bug")),
- parent);
- ::exit(0);
- }
- void
- MessageMgr::receive (CancelOperation &, void *client_data) {
- // MessageAgent::unrequest ((UAS_Receiver<CancelOperation> *) this);
- //
- // SWM -- FOR NOW: Don't pass any document (just 0). We will need
- // to change this in the future.
- //
- UAS_CancelRetrievalMsg cancelMsg(0);
- send_message(cancelMsg, client_data);
- }
- void
- MessageMgr::set_max_length(int length, Widget parent)
- {
- if(parent == NULL)
- f_booklist_message.setMaxLength (length, window_system().toplevel());
- else
- f_nodeview_message.setMaxLength (length, parent);
- }
|