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 / xmbutton.c < prev    next >
C/C++ Source or Header  |  1992-08-27  |  2KB  |  83 lines

  1. /*  include files  */
  2.  
  3. #include <stdio.h>
  4. #include <Xm/PushB.h>
  5. #include <Xm/BulletinB.h>
  6.  
  7.  
  8. /*  Functions defined in this program  */
  9.  
  10. void main();
  11. void activateCB(); /* Callback for the pushbutton */
  12.  
  13.  
  14. /*  Global variables  */
  15.  
  16. XmString btn_text;  /* button label pointer for compound string */
  17.  
  18.  
  19. /*-------------------------------------------------------------
  20. **  main - Main logic for xmbutton
  21. */
  22. void main (argc,argv)
  23. unsigned int argc;
  24. char **argv;
  25. {
  26.   Widget       toplevel;    /*  Shell widget         */
  27.   Widget       bboard;      /*  Bulletin board widget */
  28.   Widget       button;      /*  Pushbutton widget    */
  29.   Arg          args[10];    /*  arg list             */
  30.   register     int n;       /*  arg count            */
  31.   XtAppContext app_context; /*  application context  */
  32.  
  33. /*  Initialize the toolkit, create application context, open display, 
  34.     and create a toplevel shell */
  35.   toplevel = XtAppInitialize (&app_context, "XMbutton", NULL, 0, &argc,
  36.                               argv, NULL, args, 0);
  37.  
  38. /*  Create a bulletin board widget in which to place the pushbutton */
  39.   n = 0;
  40.   bboard = XmCreateBulletinBoard (toplevel, "bboard", args, n);
  41.  
  42. /*  Manage the bulletin board widget */
  43.   XtManageChild (bboard);
  44.  
  45. /*  Create a compound string for the button text  */
  46.   btn_text = XmStringCreateLtoR("Push Here", XmFONTLIST_DEFAULT_TAG);
  47.  
  48. /*  Set up an arglist for the pushbutton */
  49.   n = 0;
  50.   XtSetArg (args[n], XmNlabelString, btn_text);  n++;
  51.  
  52. /*  Create the pushbutton */
  53.   button = XtCreateManagedWidget ("button", xmPushButtonWidgetClass, bboard,
  54.   args, n); 
  55.  
  56. /*  Free the compound string memory */
  57.   XmStringFree (btn_text);
  58.  
  59. /*  Add a callback  */
  60.   XtAddCallback (button, XmNactivateCallback, activateCB, NULL);
  61.  
  62. /*  Realize widgets  */
  63.   XtRealizeWidget (toplevel);
  64.  
  65. /*  Process events  */
  66.   XtAppMainLoop (app_context);
  67. }
  68.  
  69.  
  70. /*-------------------------------------------------------------
  71. **  activateCB - callback for button
  72. */
  73. void activateCB (w, client_data, call_data) 
  74.   Widget   w;            /*  widget id              */
  75.   XtPointer   client_data;  /*  data from application  */
  76.   XtPointer   call_data;    /*  data from widget class */
  77. {
  78. /*  Print message and terminate program  */
  79.   printf ("Pushbutton Activated.\n");
  80.   exit (0);
  81. }
  82.  
  83.