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

  1. #include <stdio.h>
  2. #include <Xm/Xm.h>
  3. #include <Xm/PushB.h>
  4. #include <Xm/BulletinB.h>
  5.  
  6.  
  7. /*  Functions defined in this program  */
  8.  
  9. void main();
  10. void activateCB(); /* Callback for the PushButton */
  11.  
  12.  
  13. /*-------------------------------------------------------------
  14. **  main - Main logic for csbutton
  15. */
  16. void main (argc,argv)
  17. unsigned int argc;
  18. char **argv;
  19. {
  20.   Widget       toplevel;    /*  Shell widget          */
  21.   Widget       bboard;      /*  bulletin board widget */
  22.   Widget       button;      /*  PushButton widget     */
  23.   Arg          args[10];    /*  arg list              */
  24.   register     int n;       /*  arg count             */
  25.   XtAppContext app_context; /*  application context   */
  26.   XmString     dir1, text1, var1;
  27.   char        *text = "Push Here";
  28.  
  29. /*  Initialize the toolkit, create application context, open display, 
  30.     and create a toplevel shell */
  31.   toplevel = XtAppInitialize (&app_context, "Csbutton", NULL, 0, &argc,
  32.                               argv, NULL, args, 0);
  33.  
  34. /*  Create a bulletin board widget in which to place the pushbutton */
  35.   n = 0;
  36.   bboard = XmCreateBulletinBoard (toplevel, "bboard", args, n);
  37.  
  38. /*  Manage the bulletin board widget */
  39.   XtManageChild (bboard);
  40.  
  41. /*  Create a compound string for the button text  */
  42.   dir1 = XmStringDirectionCreate (XmSTRING_DIRECTION_R_TO_L);
  43.   text1 = XmStringCreate (text,"chset1");
  44.   var1 = XmStringConcat (dir1, text1);
  45.  
  46. /*  Set up an arglist for the push button */
  47.   n = 0;
  48.   XtSetArg (args[n], XmNlabelString, var1);  n++;
  49.  
  50. /*  Create the push button */
  51.   button = XtCreateManagedWidget ("button", xmPushButtonWidgetClass, bboard,
  52.                                   args, n); 
  53.  
  54. /*  Free the memory used by the compound strings */
  55.   XmStringFree(dir1);
  56.   XmStringFree(text1);
  57.   XmStringFree(var1);
  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 selected.\n");
  80.   exit (0);
  81. }
  82.  
  83.