MessageMgr.C 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. * $TOG: MessageMgr.C /main/13 1998/07/27 14:20:49 mgreess $
  25. *
  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.
  30. *
  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.
  34. *
  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
  41. *
  42. */
  43. # include "UAS.hh"
  44. #define C_MessageAgent
  45. #define C_VersionAgent
  46. #define C_Agent
  47. #define L_Agents
  48. #define C_MessageMgr
  49. #define C_Manager
  50. #define C_MarkMgr
  51. #define L_Managers
  52. #include "Prelude.h"
  53. #include "Managers/CatMgr.hh"
  54. #include "Registration.hh"
  55. #include "Other/XmStringLocalized.hh"
  56. #include <stdio.h>
  57. #include <iostream>
  58. using namespace std;
  59. LONG_LIVED_CC (MessageMgr,message_mgr);
  60. #define CLASS MessageMgr
  61. STATIC_SENDER_CC(UAS_CancelRetrievalMsg);
  62. //static int progressDisplayed = 0;
  63. class DisplayDocumentError : public UAS_Receiver<UAS_ErrorMsg>
  64. {
  65. public:
  66. DisplayDocumentError()
  67. { UAS_Common::request (this); }
  68. private:
  69. void receive (UAS_ErrorMsg &message, void *client_data);
  70. };
  71. void
  72. DisplayDocumentError::receive (UAS_ErrorMsg &message, void *client_data)
  73. {
  74. const char *text = message.fErrorMsg;
  75. if (text == NULL)
  76. text = (char*)UAS_String(CATGETS(Set_Messages, 35, "File a Bug"));
  77. message_mgr().error_dialog ((char *) text);
  78. }
  79. static DisplayDocumentError error_displayer;
  80. class ReportSearchMsg : public UAS_Receiver<UAS_SearchMsg>
  81. {
  82. public:
  83. ReportSearchMsg() { UAS_SearchEngine::request (this); }
  84. private:
  85. void receive (UAS_SearchMsg &message, void *client_data);
  86. };
  87. void
  88. ReportSearchMsg::receive (UAS_SearchMsg &message, void *client_data)
  89. {
  90. if (message.fSearchMsg) {
  91. bool cont = message_mgr().question_dialog(message.fSearchMsg);
  92. message.fContFlag = cont? 1 : 0;
  93. }
  94. else {
  95. message_mgr().error_dialog(
  96. (char*)UAS_String(CATGETS(Set_Messages, 36, "File a Bug")));
  97. }
  98. }
  99. static ReportSearchMsg g_search_msg_reporter;
  100. class DisplayDocumentProgress: public UAS_Receiver<UAS_StatusMsg>,
  101. public UAS_Receiver<UAS_DocumentRetrievedMsg> {
  102. public:
  103. DisplayDocumentProgress () {
  104. UAS_Common::request ((UAS_Receiver<UAS_StatusMsg> *) this);
  105. UAS_Common::request ((UAS_Receiver<UAS_DocumentRetrievedMsg> *) this);
  106. }
  107. public:
  108. void receive (UAS_StatusMsg &msg, void *client_data);
  109. void receive (UAS_DocumentRetrievedMsg &msg, void *client_data);
  110. };
  111. void
  112. DisplayDocumentProgress::receive (UAS_StatusMsg &msg, void *client_data) {
  113. message_mgr().progress_dialog (msg.fText);
  114. }
  115. void
  116. DisplayDocumentProgress::receive (UAS_DocumentRetrievedMsg &, void *client_data) {
  117. message_mgr().progress_dialog_done ();
  118. }
  119. static DisplayDocumentProgress progress_displayer;
  120. // /////////////////////////////////////////////////////////////////
  121. // class constructor
  122. // /////////////////////////////////////////////////////////////////
  123. MessageMgr::MessageMgr() :
  124. f_booklist_message (*(new MessageAgent())),
  125. f_nodeview_message (*(new MessageAgent())),
  126. f_booklist_process(0),
  127. f_nodeview_process(0),
  128. f_popped_up(False),
  129. f_pressed_ok(False),
  130. f_exit_flag(False)
  131. {
  132. MessageAgent::request ((UAS_Receiver<CancelOperation> *) this);
  133. }
  134. // /////////////////////////////////////////////////////////////////
  135. // class destructor
  136. // /////////////////////////////////////////////////////////////////
  137. MessageMgr::~MessageMgr()
  138. {
  139. g_message_mgr = NULL;
  140. }
  141. void
  142. okCB(Widget, XtPointer client_data, XtPointer)
  143. {
  144. MessageMgr* mgr = (MessageMgr*)client_data;
  145. mgr->ok_cb();
  146. }
  147. void
  148. cancelCB(Widget, XtPointer client_data, XtPointer)
  149. {
  150. MessageMgr* mgr = (MessageMgr*)client_data;
  151. mgr->cancel_cb();
  152. }
  153. void
  154. MessageMgr::ok_cb()
  155. {
  156. if (f_exit_flag) {
  157. mark_mgr().finalize ();
  158. UAS_Common::finalize ();
  159. ::exit (0);
  160. }
  161. f_pressed_ok = True;
  162. f_popped_up = False;
  163. }
  164. void
  165. MessageMgr::cancel_cb()
  166. {
  167. f_pressed_ok = False;
  168. f_popped_up = False;
  169. }
  170. void
  171. MessageMgr::show_it(Widget dialog)
  172. {
  173. Widget parent = NULL;
  174. Widget shell = NULL;
  175. XtManageChild(dialog);
  176. if (dialog) parent = XtParent(dialog);
  177. if (parent) shell = XtParent(parent);
  178. if (NULL == shell) shell = parent;
  179. XtPopup(shell, XtGrabNone);
  180. XMapRaised(XtDisplay(shell), XtWindow(shell));
  181. f_popped_up = True;
  182. f_pressed_ok = False;
  183. XEvent event;
  184. while(f_popped_up)
  185. {
  186. XtAppNextEvent (window_system().app_context(), &event);
  187. XtDispatchEvent (&event);
  188. }
  189. }
  190. void
  191. MessageMgr::destroy_it(Widget dialog)
  192. {
  193. Widget shell = XtParent(dialog);
  194. XtPopdown(shell);
  195. XtUnmanageChild(dialog);
  196. XtDestroyWidget(dialog);
  197. }
  198. Widget
  199. MessageMgr::create_dialog (unsigned char dialog_type,
  200. char *message_text,
  201. Widget parent)
  202. {
  203. Widget dialog;
  204. // determine the parent of the dialog shell
  205. if(parent == NULL)
  206. {
  207. Window window;
  208. int revert;
  209. XGetInputFocus(window_system().display(), &window, &revert);
  210. parent = XtWindowToWidget(window_system().display(), window);
  211. if(parent == NULL)
  212. parent = window_system().toplevel();
  213. }
  214. dialog = XmCreateMessageDialog(parent, (char*)"dialog", NULL, 0);
  215. WXmString wxms = message_text;
  216. XtVaSetValues(dialog,
  217. XmNdialogType, dialog_type,
  218. XmNmessageAlignment, XmALIGNMENT_CENTER,
  219. XmNmessageString, (XmString)wxms,
  220. NULL);
  221. // add callbacks
  222. XtAddCallback(dialog, XmNokCallback, okCB, this);
  223. XtAddCallback(dialog, XmNcancelCallback, cancelCB, this);
  224. return dialog;
  225. }
  226. // /////////////////////////////////////////////////////////////////
  227. // quit dialog
  228. // /////////////////////////////////////////////////////////////////
  229. void
  230. MessageMgr::quit_dialog (char *message_text, Widget parent)
  231. {
  232. //if(parent == NULL)
  233. //parent = (Widget)window_system().toplevel();
  234. //Widget dialog = XmCreateQuestionDialog(parent, "dialog", NULL, 0);
  235. Widget dialog = create_dialog(XmDIALOG_QUESTION, message_text, parent);
  236. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  237. XtVaSetValues(dialog,
  238. XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  239. XmNmessageAlignment, XmALIGNMENT_CENTER,
  240. NULL);
  241. // Set labels on buttons
  242. XmStringLocalized mtfstring;
  243. mtfstring = CATGETS(Set_AgentLabel, 244, "Yes");
  244. XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON),
  245. XmNlabelString, (XmString)mtfstring,
  246. NULL);
  247. mtfstring = CATGETS(Set_AgentLabel, 245, "No");
  248. XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON),
  249. XmNlabelString, (XmString)mtfstring,
  250. NULL);
  251. // Set the window title
  252. Widget shell = XtParent(dialog);
  253. String string = CATGETS(Set_MessageAgent, 5, "Dtinfo: Confirm Quit");
  254. XtVaSetValues(shell,
  255. XmNminWidth, 200,
  256. XmNtitle, (XmString)string,
  257. NULL);
  258. // Set the flag for the OK button
  259. f_exit_flag = True;
  260. show_it(dialog);
  261. f_exit_flag = False;
  262. destroy_it(dialog);
  263. #if 0
  264. if(parent == NULL)
  265. f_booklist_message.displayQuit(message_text, window_system().toplevel());
  266. else
  267. f_nodeview_message.displayQuit(message_text, parent);
  268. //f_message_agent.displayQuit (message_text, parent);
  269. #endif
  270. }
  271. // /////////////////////////////////////////////////////////////////
  272. // error dialog
  273. // /////////////////////////////////////////////////////////////////
  274. void
  275. MessageMgr::error_dialog (char *message_text, Widget parent)
  276. {
  277. Widget dialog = create_dialog(XmDIALOG_ERROR, message_text, parent);
  278. //Widget dialog = XmCreateErrorDialog(parent, "dialog", NULL, 0);
  279. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  280. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  281. XtVaSetValues(dialog,
  282. XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  283. XmNmessageAlignment, XmALIGNMENT_BEGINNING,
  284. NULL);
  285. // Set the window title
  286. Widget shell = XtParent(dialog);
  287. String string = CATGETS(Set_MessageAgent, 1, "Dtinfo: Error");
  288. XtVaSetValues(shell, XmNtitle, string, NULL);
  289. show_it(dialog);
  290. destroy_it(dialog);
  291. #if 0
  292. if(parent == NULL)
  293. f_booklist_message.displayError(message_text, window_system().toplevel());
  294. else
  295. f_nodeview_message.displayError(message_text, parent);
  296. //f_message_agent.displayError (message_text, parent);
  297. #endif
  298. }
  299. // /////////////////////////////////////////////////////////////////
  300. // warning dialog
  301. // /////////////////////////////////////////////////////////////////
  302. void
  303. MessageMgr::warning_dialog (char *message_text, Widget parent)
  304. {
  305. Widget dialog = create_dialog(XmDIALOG_WARNING, message_text, parent);
  306. //Widget dialog = XmCreateWarningDialog(parent, "dialog", NULL, 0);
  307. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  308. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  309. XtVaSetValues(dialog,
  310. XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  311. XmNmessageAlignment, XmALIGNMENT_BEGINNING,
  312. NULL);
  313. // Set the window title
  314. Widget shell = XtParent(dialog);
  315. String string = CATGETS(Set_MessageAgent, 2, "Dtinfo: Warning");
  316. XtVaSetValues(shell, XmNtitle, string, NULL);
  317. show_it(dialog);
  318. XtPopdown(shell);
  319. XtUnmanageChild(dialog);
  320. XtDestroyWidget(dialog);
  321. #if 0
  322. if(parent == NULL)
  323. f_booklist_message.displayWarning(message_text, window_system().toplevel());
  324. else
  325. f_nodeview_message.displayWarning(message_text, parent);
  326. //f_message_agent.displayWarning (message_text, parent);
  327. #endif
  328. }
  329. // /////////////////////////////////////////////////////////////////
  330. // information dialog
  331. // /////////////////////////////////////////////////////////////////
  332. void
  333. MessageMgr::info_dialog (char *message_text, Widget parent)
  334. {
  335. Widget dialog = create_dialog(XmDIALOG_INFORMATION, message_text, parent);
  336. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  337. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  338. // Set the window title
  339. Widget shell = XtParent(dialog);
  340. String string = CATGETS(Set_MessageAgent, 3, "Dtinfo: Information");
  341. XtVaSetValues(shell, XmNtitle, string, NULL);
  342. show_it(dialog);
  343. destroy_it(dialog);
  344. #if 0
  345. if(parent == NULL)
  346. f_booklist_message.displayInformation(message_text, window_system().toplevel());
  347. else
  348. f_nodeview_message.displayInformation(message_text, parent);
  349. //f_message_agent.displayInformation (message_text, parent);
  350. #endif
  351. }
  352. // /////////////////////////////////////////////////////////////////
  353. // progress dialog
  354. // /////////////////////////////////////////////////////////////////
  355. void
  356. MessageMgr::progress_dialog (char *message_text, Widget parent) {
  357. // MessageAgent::request ((UAS_Receiver<CancelOperation> *) this);
  358. //progressDisplayed = 1;
  359. if(parent == NULL)
  360. {
  361. f_booklist_message.displayProgress (
  362. message_text, window_system().toplevel());
  363. f_booklist_process = 1;
  364. }
  365. else
  366. {
  367. f_nodeview_message.displayProgress (message_text, parent);
  368. f_nodeview_process = 1;
  369. }
  370. }
  371. // /////////////////////////////////////////////////////////////////
  372. // progress dialog done
  373. // /////////////////////////////////////////////////////////////////
  374. void
  375. MessageMgr::progress_dialog_done () {
  376. // MessageAgent::unrequest ((UAS_Receiver<CancelOperation> *) this);
  377. if (f_booklist_process)
  378. f_booklist_message.undisplayProgress ();
  379. if (f_nodeview_process)
  380. f_nodeview_message.undisplayProgress ();
  381. }
  382. // /////////////////////////////////////////////////////////////////
  383. // question dialog
  384. // /////////////////////////////////////////////////////////////////
  385. bool
  386. MessageMgr::question_dialog (char *message_text, Widget parent)
  387. {
  388. if(parent == NULL)
  389. parent = (Widget)window_system().toplevel();
  390. Widget dialog = XmCreateInformationDialog(parent, (char*)"dialog", NULL, 0);
  391. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  392. WXmString wxms = message_text;
  393. XtVaSetValues(dialog,
  394. XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  395. XmNmessageAlignment, XmALIGNMENT_CENTER,
  396. XmNmessageString, (XmString)wxms,
  397. NULL);
  398. // Set labels on buttons
  399. XmStringLocalized mtfstring;
  400. mtfstring = CATGETS(Set_AgentLabel, 244, "Yes");
  401. XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON),
  402. XmNlabelString, (XmString)mtfstring,
  403. NULL);
  404. mtfstring = CATGETS(Set_AgentLabel, 245, "No");
  405. XtVaSetValues(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON),
  406. XmNlabelString, (XmString)mtfstring,
  407. NULL);
  408. XtAddCallback(dialog, XmNokCallback, okCB, this);
  409. XtAddCallback(dialog, XmNcancelCallback, cancelCB, this);
  410. // Set the window title
  411. Widget shell = XtParent(dialog);
  412. String string = CATGETS(Set_MessageAgent, 3, "Dtinfo: Information");
  413. XtVaSetValues(shell, XmNtitle, string, NULL);
  414. show_it(dialog);
  415. XtPopdown(shell);
  416. XtUnmanageChild(dialog);
  417. XtDestroyWidget(dialog);
  418. return(f_pressed_ok);
  419. #if 0
  420. if(parent == NULL)
  421. return(f_booklist_message.displayQuestion(
  422. message_text, window_system().toplevel()));
  423. else
  424. return(f_nodeview_message.displayQuestion(message_text, parent));
  425. //return (f_message_agent.displayQuestion (message_text, parent));
  426. #endif
  427. }
  428. int
  429. MessageMgr::get_integer(const char *msg, const char* title,
  430. int default_value, Widget parent)
  431. {
  432. if(parent == NULL)
  433. return (f_booklist_message.get_integer (msg, title, default_value, window_system().toplevel()));
  434. else
  435. return (f_nodeview_message.get_integer (msg, title, default_value, parent));
  436. }
  437. const char *
  438. MessageMgr::get_string (const char* msg, const char* title,
  439. const char *default_value, Widget parent)
  440. {
  441. if(parent == NULL)
  442. return (f_booklist_message.get_string (msg, title, default_value, window_system().toplevel()));
  443. else
  444. return (f_nodeview_message.get_string (msg, title, default_value, parent));
  445. }
  446. // /////////////////////////////////////////////////////////////////
  447. // assert_failed
  448. // /////////////////////////////////////////////////////////////////
  449. void
  450. MessageMgr::assert_failed (char *statement, char *file,
  451. int line, Widget parent)
  452. {
  453. char buffer[512];
  454. snprintf (buffer, sizeof(buffer),
  455. "An internal error has occured.\n\
  456. The current operation cannot be completed.\n\
  457. Please file a bug report with this information:\n\
  458. Assertion failed: %s\n\
  459. File \"%s,\" line %d.",
  460. statement, file, line);
  461. if(parent == NULL)
  462. f_booklist_message.displayError (buffer, window_system().toplevel());
  463. else
  464. f_nodeview_message.displayError (buffer, parent);
  465. quit_dialog ((char*)"We strongly suggest you quit now, Ok?", parent);
  466. }
  467. // /////////////////////////////////////////////////////////////////////////
  468. // demo_failure
  469. //
  470. // put up error message. quit application when dialog returns
  471. //
  472. // /////////////////////////////////////////////////////////////////////////
  473. void
  474. MessageMgr::demo_failure(demoException &, Widget parent)
  475. {
  476. error_dialog(
  477. (char*)UAS_String(CATGETS(Set_Messages, 38, "File a Bug")),
  478. parent);
  479. ::exit(0);
  480. }
  481. void
  482. MessageMgr::receive (CancelOperation &, void *client_data) {
  483. // MessageAgent::unrequest ((UAS_Receiver<CancelOperation> *) this);
  484. //
  485. // SWM -- FOR NOW: Don't pass any document (just 0). We will need
  486. // to change this in the future.
  487. //
  488. UAS_CancelRetrievalMsg cancelMsg(0);
  489. send_message(cancelMsg, client_data);
  490. }
  491. void
  492. MessageMgr::set_max_length(int length, Widget parent)
  493. {
  494. if(parent == NULL)
  495. f_booklist_message.setMaxLength (length, window_system().toplevel());
  496. else
  497. f_nodeview_message.setMaxLength (length, parent);
  498. }