home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / master12.zip / mastering / pathtest.c < prev    next >
C/C++ Source or Header  |  1992-08-21  |  4KB  |  125 lines

  1. /**---------------------------------------------------------------------
  2. ***    
  3. ***    file:        pathtest.c
  4. ***
  5. ***    project:    Motif Widgets example programs
  6. ***
  7. ***    description: This program creates a pushbutton widget and
  8. ***                 three label widgets, all contained within a
  9. ***                 bulletin board widget.  The labels that are
  10. ***                 displayed are dependent on the setting of certain
  11. ***                 environment variables, LANG, XAPPLRESDIR, 
  12. ***                 XFILESEARCHPATH, and XUSERFILESEARCHPATH.
  13. ***
  14. ***-------------------------------------------------------------------*/
  15.  
  16. /*  include files  */
  17.  
  18. #include <stdio.h>
  19. #include <Xm/PushB.h>
  20. #include <Xm/Label.h>
  21. #include <Xm/BulletinB.h>
  22.  
  23. /*  Functions defined in this program  */
  24.  
  25. void main();
  26. void activateCB(); /* Callback for the PushButton */
  27.  
  28. /*  Global variables  */
  29.  
  30. XmString btn_text;    /* button label pointer for compound string */
  31.  
  32. /*-------------------------------------------------------------
  33. **    main - Main logic for xmbutton
  34. */
  35. void main (argc,argv)
  36. unsigned int argc;
  37. char **argv;
  38. {
  39.     Widget       toplevel;                   /*  Shell widget          */
  40.     Widget       bboard;                     /*  Bulletin board widget */
  41.     Widget       button;                     /*  PushButton widget     */
  42.     Widget       label1, label2, label3;     /*  Label widgets         */
  43.     Arg          args[10];                   /*  arg list              */
  44.     register     int n;                      /*  arg count             */
  45.     XtAppContext app_context;                /*  application context   */
  46.  
  47. /*  Initialize the toolkit, create application context, open display, 
  48.     and create a toplevel shell.  Note that Pathtest is the application
  49.     class name that is used as the file name for app-defaults files for
  50.     this application.                                                 */
  51.  
  52.     toplevel = XtAppInitialize (&app_context, "Pathtest", NULL, 0, &argc,
  53.                                 argv, NULL, args, 0);
  54.    
  55.  
  56. /*  Create a bulletin board widget in which to place the pushbutton
  57.     and the three label widgets.                                   */
  58.     n = 0;
  59.     bboard = XmCreateBulletinBoard (toplevel, "bboard", args, n);
  60.  
  61. /*  Manage the bulletin board widget */
  62.     XtManageChild (bboard);
  63.  
  64. /*  Create a compound string for the pushbutton text  */
  65.     btn_text = XmStringCreateLtoR("Quit", XmFONTLIST_DEFAULT_TAG);
  66.  
  67. /*  Set up an arglist for the pushbutton  */
  68.     n = 0;
  69.     XtSetArg (args[n], XmNlabelString, btn_text);  n++;
  70.  
  71. /*  Create the pushbutton */
  72.     button = XmCreatePushButton (bboard, "button", args, n); 
  73.     
  74. /*  Manage the pushbutton */
  75.     XtManageChild (button);
  76.  
  77. /*  Add a callback for the pushbutton */
  78.     XtAddCallback (button, XmNactivateCallback, activateCB, NULL);
  79.  
  80. /*  Free the compound string memory */
  81.     XmStringFree (btn_text);
  82.  
  83. /*  Create label1 */
  84.     n = 0;
  85.     label1 =  XmCreateLabel (bboard, "label1", args, n); 
  86.     
  87. /*  Manage label1 */
  88.     XtManageChild (label1);
  89.  
  90. /*  Create label2 */
  91.     n = 0;
  92.     label2 =  XmCreateLabel (bboard, "label2", args, n); 
  93.     
  94. /*  Manage label2 */
  95.     XtManageChild (label2);
  96.  
  97. /*  Create label3 */
  98.     n = 0;
  99.     label3 =  XmCreateLabel (bboard, "label3", args, n); 
  100.     
  101. /*  Manage label3 */
  102.     XtManageChild (label3);
  103.  
  104. /*  Realize widgets  */
  105.     XtRealizeWidget (toplevel);
  106.  
  107. /*  Process events  */
  108.     XtAppMainLoop (app_context);
  109. }
  110.  
  111.  
  112. /*-------------------------------------------------------------
  113. **    activateCB - callback for button
  114. */
  115. void activateCB (w, client_data, call_data) 
  116.     Widget      w;            /*  widget id              */
  117.     XtPointer   client_data;  /*  data from application  */
  118.     XtPointer   call_data;    /*  data from widget class */
  119. {
  120. /*  Print message and terminate program  */
  121.     printf ("Pushbutton Activated.\n");
  122.     exit (0);
  123. }
  124.  
  125.