home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / n / newmarch.zip / HELP.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  3KB  |  145 lines

  1. /* Author:   $Author: jan $
  2.  * File:     $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/help.c,v $
  3.  * Date:     $Date: 1992/09/09 00:10:02 $
  4.  * Revision: $Revision: 1.1 $
  5.  */
  6.  
  7. #include "copyright.h"
  8.  
  9. #include <stdio.h>
  10. #include <Xm/PushB.h>   
  11. #include <Xm/MessageB.h> 
  12.         
  13.  
  14. char Class_name[] ="XmHelp";     
  15.  
  16.  
  17. #define MAX_ARGS 20
  18. #define BUFSIZ   1024
  19.  
  20. void CloseCB  ();  
  21.  
  22. /*------------------------------------------------------
  23. **      CreateHelp              - create help window 
  24. */ 
  25. Widget CreateHelp (parent)  
  26.     Widget    parent;        /* parent widget */ 
  27. {
  28.     Widget    button; 
  29.     Widget    message_box;   /* Information Dialog */
  30.     Arg       args[MAX_ARGS]; /* arg list   */ 
  31.     int  n;               /*  arg count */ 
  32.  
  33.     static char   message[BUFSIZ]; /* help text */ 
  34.     XmString      title_string; 
  35.     XmString      message_string; 
  36.     XmString      button_string; 
  37.  
  38.     /*      Generate message to display. 
  39.     */ 
  40.     sprintf (message, "\
  41. This is a general help message.  \n\
  42. See a human if you have problems. \n\
  43. This program doesn't know what is going on.");
  44.  
  45.     message_string = XmStringCreateLtoR (message,
  46.                       XmSTRING_DEFAULT_CHARSET); 
  47.     button_string = XmStringCreateLtoR ("Close",
  48.                      XmSTRING_DEFAULT_CHARSET); 
  49.     title_string = XmStringCreateLtoR (
  50.                      "Help dialog",
  51.                      XmSTRING_DEFAULT_CHARSET); 
  52.  
  53.     /*      Create Information Dialog
  54.     **      using a MessageBox
  55.     */ 
  56.     n = 0; 
  57.     XtSetArg (args[n], XmNdialogTitle,
  58.                    title_string);  n++; 
  59.     XtSetArg (args[n], XmNokLabelString,
  60.                    button_string);  n++; 
  61.     XtSetArg (args[n], XmNmessageString,
  62.                    message_string);  n++; 
  63.     message_box = XmCreateInformationDialog (parent,
  64.                    "helpbox", args, n); 
  65.     XtAddCallback (message_box, XmNokCallback,
  66.                 CloseCB, NULL);
  67.  
  68.     /* Get rid of unwanted buttons    */
  69.     button = XmMessageBoxGetChild (message_box,
  70.                    XmDIALOG_CANCEL_BUTTON); 
  71.     XtUnmanageChild (button); 
  72.     button = XmMessageBoxGetChild (message_box,
  73.                    XmDIALOG_HELP_BUTTON); 
  74.     XtUnmanageChild (button); 
  75.  
  76.     /* Free strings and return MessageBox. 
  77.     */ 
  78.     XmStringFree (title_string); 
  79.     XmStringFree (message_string); 
  80.     XmStringFree (button_string); 
  81.     return (message_box); 
  82.  
  83. /*------------------------------------------------------
  84. ** CloseCB   - callback for close button 
  85. */ 
  86. void CloseCB  (message_box, client_data, call_data)  
  87.     Widget  message_box;    /*  widget id */ 
  88.     caddr_t client_data;    /*  NULL */ 
  89.     caddr_t call_data;      /*  data from 
  90.                                widget class  */
  91.     Widget shell = XtParent (message_box); 
  92.  
  93.     /* Unmanage and destroy widgets. 
  94.     */ 
  95.     XtUnmanageChild (message_box); 
  96.     XtDestroyWidget (shell); 
  97.  
  98.  
  99. void
  100. PushCB(w, client_data, call_data)
  101. Widget w;
  102. caddr_t client_data;
  103. caddr_t call_data;
  104. {       Widget help;
  105.  
  106.     help = CreateHelp (w);
  107.         XtManageChild (help);
  108. }
  109.     
  110. main(argc, argv)    
  111. int argc;
  112. char **argv;
  113. {       
  114.     Widget toplevel;
  115.     Widget button;
  116.         
  117.     /* Initialize the intrinsics  
  118.        with a toplevel widget */ 
  119.     toplevel = XtInitialize(NULL,
  120.                      Class_name,     
  121.                      NULL,        
  122.                      0,        
  123.                      &argc, argv);    
  124.  
  125.   /* Create a widget, with the
  126.        toplevel as manager;
  127.     */      
  128.     button = XmCreatePushButton(toplevel, 
  129.                         "Press here for help",
  130.                         NULL,
  131.                         0);
  132.     XtAddCallback (button, XmNactivateCallback,
  133.                        PushCB);
  134.     XtManageChild (button);
  135.         
  136.     /* display all of the widgets */    
  137.     XtRealizeWidget(toplevel);      
  138.     
  139.     /* enter the main processing loop */    
  140.     XtMainLoop();
  141. }
  142.