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
24 * $TOG: MessageMgr.C /main/13 1998/07/27 14:20:49 mgreess $
26 * Copyright (c) 1991 HaL Computer Systems, Inc. All rights reserved.
27 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28 * States. Use of a copyright notice is precautionary only and does not
29 * imply publication or disclosure.
31 * This software contains confidential information and trade secrets of HaL
32 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
33 * without the prior express written permission of HaL Computer Systems, Inc.
35 * RESTRICTED RIGHTS LEGEND
36 * Use, duplication, or disclosure by the Government is subject to
37 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38 * Technical Data and Computer Software clause at DFARS 252.227-7013.
39 * HaL Computer Systems, Inc.
40 * 1315 Dell Avenue, Campbell, CA 95008
46 #define C_MessageAgent
47 #define C_VersionAgent
58 #include "Managers/CatMgr.hh"
59 #include "Registration.hh"
60 #include "Other/XmStringLocalized.hh"
65 LONG_LIVED_CC (MessageMgr,message_mgr);
67 #define CLASS MessageMgr
69 STATIC_SENDER_CC(UAS_CancelRetrievalMsg);
71 //static int progressDisplayed = 0;
73 class DisplayDocumentError : public UAS_Receiver<UAS_ErrorMsg>
76 DisplayDocumentError()
77 { UAS_Common::request (this); }
79 void receive (UAS_ErrorMsg &message, void *client_data);
83 DisplayDocumentError::receive (UAS_ErrorMsg &message, void *client_data)
85 const char *text = message.fErrorMsg;
88 text = (char*)UAS_String(CATGETS(Set_Messages, 35, "File a Bug"));
90 message_mgr().error_dialog ((char *) text);
93 static DisplayDocumentError error_displayer;
96 class ReportSearchMsg : public UAS_Receiver<UAS_SearchMsg>
99 ReportSearchMsg() { UAS_SearchEngine::request (this); }
101 void receive (UAS_SearchMsg &message, void *client_data);
105 ReportSearchMsg::receive (UAS_SearchMsg &message, void *client_data)
107 if (message.fSearchMsg) {
108 bool cont = message_mgr().question_dialog(message.fSearchMsg);
109 message.fContFlag = cont? 1 : 0;
112 message_mgr().error_dialog(
113 (char*)UAS_String(CATGETS(Set_Messages, 36, "File a Bug")));
117 static ReportSearchMsg g_search_msg_reporter;
119 class DisplayDocumentProgress: public UAS_Receiver<UAS_StatusMsg>,
120 public UAS_Receiver<UAS_DocumentRetrievedMsg> {
122 DisplayDocumentProgress () {
123 UAS_Common::request ((UAS_Receiver<UAS_StatusMsg> *) this);
124 UAS_Common::request ((UAS_Receiver<UAS_DocumentRetrievedMsg> *) this);
128 void receive (UAS_StatusMsg &msg, void *client_data);
129 void receive (UAS_DocumentRetrievedMsg &msg, void *client_data);
134 DisplayDocumentProgress::receive (UAS_StatusMsg &msg, void *client_data) {
135 message_mgr().progress_dialog (msg.fText);
139 DisplayDocumentProgress::receive (UAS_DocumentRetrievedMsg &, void *client_data) {
140 message_mgr().progress_dialog_done ();
144 static DisplayDocumentProgress progress_displayer;
147 // /////////////////////////////////////////////////////////////////
149 // /////////////////////////////////////////////////////////////////
151 MessageMgr::MessageMgr() :
152 f_booklist_message (*(new MessageAgent())),
153 f_nodeview_message (*(new MessageAgent())),
154 f_booklist_process(0),
155 f_nodeview_process(0),
159 f_dialog_active(False)
162 MessageAgent::request ((UAS_Receiver<CancelOperation> *) this);
166 // /////////////////////////////////////////////////////////////////
168 // /////////////////////////////////////////////////////////////////
170 MessageMgr::~MessageMgr()
172 g_message_mgr = NULL;
176 okCB(Widget, XtPointer client_data, XtPointer)
178 MessageMgr* mgr = (MessageMgr*)client_data;
183 cancelCB(Widget, XtPointer client_data, XtPointer)
185 MessageMgr* mgr = (MessageMgr*)client_data;
193 mark_mgr().finalize ();
194 UAS_Common::finalize ();
203 MessageMgr::cancel_cb()
205 f_pressed_ok = False;
210 MessageMgr::show_it(Widget dialog)
212 Widget parent, shell;
214 XtManageChild(dialog);
216 if (dialog) parent = XtParent(dialog);
217 if (parent) shell = XtParent(parent);
218 if (NULL == shell) shell = parent;
219 XtPopup(shell, XtGrabNone);
220 XMapRaised(XtDisplay(shell), XtWindow(shell));
223 f_pressed_ok = False;
228 XtAppNextEvent (window_system().app_context(), &event);
229 XtDispatchEvent (&event);
234 MessageMgr::destroy_it(Widget dialog)
236 Widget shell = XtParent(dialog);
238 XtUnmanageChild(dialog);
239 XtDestroyWidget(dialog);
243 MessageMgr::create_dialog (unsigned char dialog_type,
249 // determine the parent of the dialog shell
254 XGetInputFocus(window_system().display(), &window, &revert);
255 parent = XtWindowToWidget(window_system().display(), window);
257 parent = window_system().toplevel();
260 dialog = XmCreateMessageDialog(parent, "dialog", NULL, 0);
262 WXmString wxms = message_text;
263 XtVaSetValues(dialog,
264 XmNdialogType, dialog_type,
265 XmNmessageAlignment, XmALIGNMENT_CENTER,
266 XmNmessageString, (XmString)wxms,
270 XtAddCallback(dialog, XmNokCallback, okCB, this);
271 XtAddCallback(dialog, XmNcancelCallback, cancelCB, this);
276 // /////////////////////////////////////////////////////////////////
278 // /////////////////////////////////////////////////////////////////
281 MessageMgr::quit_dialog (char *message_text, Widget parent)
284 //parent = (Widget)window_system().toplevel();
285 //Widget dialog = XmCreateQuestionDialog(parent, "dialog", NULL, 0);
286 Widget dialog = create_dialog(XmDIALOG_QUESTION, message_text, parent);
288 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
289 XtVaSetValues(dialog,
290 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
291 XmNmessageAlignment, XmALIGNMENT_CENTER,
294 // Set labels on buttons
295 XmStringLocalized mtfstring;
296 mtfstring = CATGETS(Set_AgentLabel, 244, "Yes");
297 XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON),
298 XmNlabelString, (XmString)mtfstring,
300 mtfstring = CATGETS(Set_AgentLabel, 245, "No");
301 XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON),
302 XmNlabelString, (XmString)mtfstring,
305 // Set the window title
306 Widget shell = XtParent(dialog);
307 String string = CATGETS(Set_MessageAgent, 5, "Dtinfo: Confirm Quit");
310 XmNtitle, (XmString)string,
313 // Set the flag for the OK button
323 f_booklist_message.displayQuit(message_text, window_system().toplevel());
325 f_nodeview_message.displayQuit(message_text, parent);
326 //f_message_agent.displayQuit (message_text, parent);
331 // /////////////////////////////////////////////////////////////////
333 // /////////////////////////////////////////////////////////////////
335 MessageMgr::error_dialog (char *message_text, Widget parent)
337 Widget dialog = create_dialog(XmDIALOG_ERROR, message_text, parent);
338 //Widget dialog = XmCreateErrorDialog(parent, "dialog", NULL, 0);
340 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
341 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
342 XtVaSetValues(dialog,
343 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
344 XmNmessageAlignment, XmALIGNMENT_BEGINNING,
347 // Set the window title
348 Widget shell = XtParent(dialog);
349 String string = CATGETS(Set_MessageAgent, 1, "Dtinfo: Error");
350 XtVaSetValues(shell, XmNtitle, string, NULL);
358 f_booklist_message.displayError(message_text, window_system().toplevel());
360 f_nodeview_message.displayError(message_text, parent);
361 //f_message_agent.displayError (message_text, parent);
365 // /////////////////////////////////////////////////////////////////
367 // /////////////////////////////////////////////////////////////////
370 MessageMgr::warning_dialog (char *message_text, Widget parent)
372 Widget dialog = create_dialog(XmDIALOG_WARNING, message_text, parent);
373 //Widget dialog = XmCreateWarningDialog(parent, "dialog", NULL, 0);
375 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
376 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
377 XtVaSetValues(dialog,
378 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
379 XmNmessageAlignment, XmALIGNMENT_BEGINNING,
382 // Set the window title
383 Widget shell = XtParent(dialog);
384 String string = CATGETS(Set_MessageAgent, 2, "Dtinfo: Warning");
385 XtVaSetValues(shell, XmNtitle, string, NULL);
390 XtUnmanageChild(dialog);
391 XtDestroyWidget(dialog);
395 f_booklist_message.displayWarning(message_text, window_system().toplevel());
397 f_nodeview_message.displayWarning(message_text, parent);
398 //f_message_agent.displayWarning (message_text, parent);
402 // /////////////////////////////////////////////////////////////////
403 // information dialog
404 // /////////////////////////////////////////////////////////////////
407 MessageMgr::info_dialog (char *message_text, Widget parent)
409 Widget dialog = create_dialog(XmDIALOG_INFORMATION, message_text, parent);
410 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
411 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
413 // Set the window title
414 Widget shell = XtParent(dialog);
415 String string = CATGETS(Set_MessageAgent, 3, "Dtinfo: Information");
416 XtVaSetValues(shell, XmNtitle, string, NULL);
423 f_booklist_message.displayInformation(message_text, window_system().toplevel());
425 f_nodeview_message.displayInformation(message_text, parent);
426 //f_message_agent.displayInformation (message_text, parent);
430 // /////////////////////////////////////////////////////////////////
432 // /////////////////////////////////////////////////////////////////
435 MessageMgr::progress_dialog (char *message_text, Widget parent) {
436 // MessageAgent::request ((UAS_Receiver<CancelOperation> *) this);
437 //progressDisplayed = 1;
440 f_booklist_message.displayProgress (
441 message_text, window_system().toplevel());
442 f_booklist_process = 1;
446 f_nodeview_message.displayProgress (message_text, parent);
447 f_nodeview_process = 1;
451 // /////////////////////////////////////////////////////////////////
452 // progress dialog done
453 // /////////////////////////////////////////////////////////////////
456 MessageMgr::progress_dialog_done () {
457 // MessageAgent::unrequest ((UAS_Receiver<CancelOperation> *) this);
458 if (f_booklist_process)
459 f_booklist_message.undisplayProgress ();
460 if (f_nodeview_process)
461 f_nodeview_message.undisplayProgress ();
464 // /////////////////////////////////////////////////////////////////
466 // /////////////////////////////////////////////////////////////////
469 MessageMgr::question_dialog (char *message_text, Widget parent)
472 parent = (Widget)window_system().toplevel();
473 Widget dialog = XmCreateInformationDialog(parent, "dialog", NULL, 0);
474 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
475 WXmString wxms = message_text;
476 XtVaSetValues(dialog,
477 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
478 XmNmessageAlignment, XmALIGNMENT_CENTER,
479 XmNmessageString, (XmString)wxms,
482 // Set labels on buttons
483 XmStringLocalized mtfstring;
484 mtfstring = CATGETS(Set_AgentLabel, 244, "Yes");
485 XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON),
486 XmNlabelString, (XmString)mtfstring,
488 mtfstring = CATGETS(Set_AgentLabel, 245, "No");
489 XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON),
490 XmNlabelString, (XmString)mtfstring,
493 XtAddCallback(dialog, XmNokCallback, okCB, this);
494 XtAddCallback(dialog, XmNcancelCallback, cancelCB, this);
496 // Set the window title
497 Widget shell = XtParent(dialog);
498 String string = CATGETS(Set_MessageAgent, 3, "Dtinfo: Information");
499 XtVaSetValues(shell, XmNtitle, string, NULL);
504 XtUnmanageChild(dialog);
505 XtDestroyWidget(dialog);
507 return(f_pressed_ok);
511 return(f_booklist_message.displayQuestion(
512 message_text, window_system().toplevel()));
514 return(f_nodeview_message.displayQuestion(message_text, parent));
515 //return (f_message_agent.displayQuestion (message_text, parent));
520 MessageMgr::get_integer(const char *msg, const char* title,
521 int default_value, Widget parent)
524 return (f_booklist_message.get_integer (msg, title, default_value, window_system().toplevel()));
526 return (f_nodeview_message.get_integer (msg, title, default_value, parent));
530 MessageMgr::get_string (const char* msg, const char* title,
531 const char *default_value, Widget parent)
534 return (f_booklist_message.get_string (msg, title, default_value, window_system().toplevel()));
536 return (f_nodeview_message.get_string (msg, title, default_value, parent));
540 // /////////////////////////////////////////////////////////////////
542 // /////////////////////////////////////////////////////////////////
545 MessageMgr::assert_failed (char *statement, char *file,
546 int line, Widget parent)
551 "An internal error has occured.\n\
552 The current operation cannot be completed.\n\
553 Please file a bug report with this information:\n\
554 Assertion failed: %s\n\
555 File \"%s,\" line %d.",
556 statement, file, line);
559 f_booklist_message.displayError (buffer, window_system().toplevel());
561 f_nodeview_message.displayError (buffer, parent);
562 quit_dialog ("We strongly suggest you quit now, Ok?", parent);
565 // /////////////////////////////////////////////////////////////////////////
568 // put up error message. quit application when dialog returns
570 // /////////////////////////////////////////////////////////////////////////
573 MessageMgr::demo_failure(demoException &, Widget parent)
576 (char*)UAS_String(CATGETS(Set_Messages, 38, "File a Bug")),
581 MessageMgr::receive (CancelOperation &, void *client_data) {
582 // MessageAgent::unrequest ((UAS_Receiver<CancelOperation> *) this);
584 // SWM -- FOR NOW: Don't pass any document (just 0). We will need
585 // to change this in the future.
587 UAS_CancelRetrievalMsg cancelMsg(0);
588 send_message(cancelMsg, client_data);
591 MessageMgr::set_max_length(int length, Widget parent)
594 f_booklist_message.setMaxLength (length, window_system().toplevel());
596 f_nodeview_message.setMaxLength (length, parent);