home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / windows / x / motif / 8257 < prev    next >
Encoding:
Text File  |  1992-12-30  |  5.6 KB  |  183 lines

  1. Xref: sparky comp.windows.x.motif:8257 comp.windows.x:20635
  2. Newsgroups: comp.windows.x.motif,comp.windows.x
  3. Path: sparky!uunet!stanford.edu!ames!pasteur!roma.berkeley.edu!raja
  4. From: raja@roma.berkeley.edu (Raja R. Kadiyala)
  5. Subject: Re: Catching window manager's kill (Solutions)
  6. Message-ID: <1992Dec30.183242.24141@pasteur.Berkeley.EDU>
  7. Sender: nntp@pasteur.Berkeley.EDU (NNTP Poster)
  8. Nntp-Posting-Host: roma.berkeley.edu
  9. Organization: U.C. Berkeley -- ERL
  10. References: <1992Dec29.224940.23390@pasteur.Berkeley.EDU>
  11. Date: Wed, 30 Dec 1992 18:32:42 GMT
  12. Lines: 169
  13.  
  14.  
  15.  
  16. My question:
  17. >    How do I catch/stop the window mngr. from quiting my application (i.e.
  18. >if I am running olwm the user may go up to the the title bar click to
  19. >get the 'window' menu and select 'quit' and my app is outa there.  Likewise
  20. >with mwm except it is 'close').
  21.  
  22. >    I want to prompt the user if he/she REALLY wants to quit.
  23.  
  24. Thanks for all the responses.  I got one to work (which is all I needed ...)
  25. raja
  26.  
  27.  
  28. Solutions:
  29.  
  30. John L. Cwikla <cwikla@wri.com>:
  31.     Look at handling WM_SAVE_YOURSELF and WM_DELETE_WINDOW
  32.     for regular Xt with XSetWMProtocols and
  33.     XmInternAtom and XmAddWMProtocolCallback for Motif.
  34.  
  35. Balwalli Krishnanan <SLLKZ@CC.USU.EDU>:
  36.     Your wm is using resources from .mwmrc (for mwm) etc. Simply 
  37.     edit that file to suit your requirements specifically as follows..
  38.     For .mwmrc (since i use it, i would do ..)
  39.     ...
  40.     Menu DefaultWindowMenu
  41.     {
  42.     ....
  43.     "Close"    _C  Alt<Key>F4     f.exec"yourprog"
  44.     }
  45.  
  46.   
  47. Scott Grosch <garath@engin.umich.edu>:
  48. Curtis Generous <generous@Sti.NASA.GOV>:
  49.     Here is example code taken from Dan Heller's book to handle MWM
  50.     protocols.  Hope it helps.
  51.     Here's an mwm specific example:
  52.  
  53. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  54.  * This program is freely distributable without licensing fees and
  55.  * is provided without guarantee or warrantee expressed or implied.
  56.  * This program is -not- in the public domain.
  57.  */
  58.  
  59. /* wm_delete.c -- demonstrate how to bind the Close button in the
  60.  * window manager's system menu to the "cancel" button in a dialog.
  61.  */
  62. #include <Xm/MessageB.h>
  63. #include <Xm/PushB.h>
  64. #include <Xm/Protocols.h>
  65.  
  66. #define YES 1
  67. #define NO  0
  68. int answer;
  69.  
  70. /* main() --create a pushbutton whose callback pops up a dialog box */
  71. main(argc, argv)
  72. char *argv[];
  73. {
  74.     Widget toplevel, button;
  75.     XtAppContext app;
  76.     void activate();
  77.  
  78.     toplevel = XtVaAppInitialize(&app, "Demos",
  79.         NULL, 0, &argc, argv, NULL, NULL);
  80.  
  81.     button = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
  82.         toplevel, NULL, 0);
  83.     XtAddCallback(button, XmNactivateCallback, activate, NULL);
  84.  
  85.     XtRealizeWidget(toplevel);
  86.     XtAppMainLoop(app);
  87. }
  88.  
  89. /* Create and popup an ErrorDialog indicating that the user may have
  90.  * done something wrong.  The dialog contains an Ok and Cancel button,
  91.  * but he can still choose the Close button in the titlebar.
  92.  */
  93. void
  94. activate(w)
  95. Widget w;
  96. {
  97.     Widget dialog, shell;
  98.     void handle_close(), response();
  99.     XmString t = XmStringCreateSimple("Warning: Delete All Files?");
  100.     Atom WM_DELETE_WINDOW;
  101.     Arg args[2];
  102.  
  103.     /* Make sure the VendorShell associated with the dialog does not
  104.      * react to the user's selection of the Close system menu item.
  105.      */
  106.     XtSetArg(args[0], XmNmessageString, t);
  107.     XtSetArg(args[1], XmNdeleteResponse, XmDO_NOTHING);
  108.     dialog = XmCreateWarningDialog(w, "notice", args, 2);
  109.     XmStringFree(t);
  110.  
  111.     /* add callback routines for ok and cancel -- desensitize help */
  112.     XtAddCallback(dialog, XmNokCallback, response, NULL);
  113.     XtAddCallback(dialog, XmNcancelCallback, response, NULL);
  114.     XtSetSensitive(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
  115.  
  116.     XtManageChild(dialog);
  117.  
  118.     /* Add a callback for the WM_DELETE_WINDOW protocol */
  119.     shell = XtParent(dialog);
  120.     WM_DELETE_WINDOW = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", False);
  121.     XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, response, dialog);
  122. }
  123.  
  124. /* callback for the Ok and Cancel buttons in the dialog -- may also be
  125.  * called from the WM_DELETE_WINDOW protocol message sent by the wm.
  126.  */
  127. void
  128. response(widget, client_data, cbs)
  129. Widget widget;
  130. XtPointer client_data;
  131. XmAnyCallbackStruct *cbs;
  132. {
  133.     Widget dialog;
  134.  
  135.     if (cbs->reason == XmCR_OK) {
  136.         answer = YES;
  137.         puts("Yes.");
  138.     } else {
  139.         answer = NO;
  140.         puts("No.");
  141.     }
  142.     /* test that "reason" is not the cancel button and not the ok button.
  143.      * It's value is XmCR_PROTOCOLS (6666), but we can't check for that
  144.      * because OSF didn't make that value public.
  145.      */
  146.     if (cbs->reason != XmCR_CANCEL && cbs->reason != XmCR_OK)
  147.         /* we passed the dialog as client data for the protocol callback */
  148.         dialog = (Widget)client_data;
  149.     else
  150.         dialog = widget;
  151.  
  152.     XtDestroyWidget(dialog);
  153. }
  154.  
  155.  
  156. Doug Clinton <dec@alex.com>:
  157.     You need to tell the window manager that you are interested in the
  158.     WM_PROTOCOL message WM_DELETE_WINDOW. You can do this in Motif using
  159.     the XmAddProtocolCallback function and related functions. See also the
  160.     VendorShell widget.
  161.  
  162.  
  163. Michael E. Dupree <zmed0b@trc.amoco.com>:
  164.     Atom wm_delete_window;
  165.     ...
  166.     ...
  167.     ...
  168.     
  169.     wm_delete_window=XmInternAtom(XtDisplay(toplevel),
  170.                         "WM_DELETE_WINDOW",False);
  171.     XmAddWMProtocols(toplevel,&wm_delete_window,1);
  172.     XmAddWMProtocolCallback(toplevel,wm_delete_window,
  173.                     exit_dialog, (XtPointer) app_context);
  174.  
  175.     This will trap for the Delete Window signal and call the exit_dialog
  176.     callback when this signal is received.
  177.  
  178. --
  179. Raja R. Kadiyala            UC Berkeley Robotics Lab
  180. Mail is forwarded to:            raja@robotics.berkeley.edu
  181. Office  333-5D Cory Hall        Phone: (510) 643-5798
  182. Lab     330    Cory Hall        Phone: (510) 642-3248 or 2-7824
  183.