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 / fonts.c < prev    next >
C/C++ Source or Header  |  1992-08-19  |  3KB  |  99 lines

  1. /**---------------------------------------------------------------------
  2. ***  
  3. ***  file:    fonts.c
  4. ***
  5. ***  project:  Motif Widgets example programs
  6. ***
  7. ***  description:  This program creates a PushButton widget and 
  8. ***                 shows how fonts can be set programmatically.
  9. ***
  10. ***-------------------------------------------------------------------*/
  11.  
  12.  
  13. /*  include files  */
  14.  
  15. #include <stdio.h>
  16. #include <Xm/PushB.h>
  17. #include <Xm/BulletinB.h>
  18.  
  19. /*  functions defined in this program  */
  20.  
  21. void main();
  22. void activateCB(); /* Callback for the PushButton */
  23.  
  24. /* global variables */
  25.  
  26.   XmString s1;  
  27.   XmFontList fontlist1;
  28.  
  29. /*-------------------------------------------------------------
  30. **  main - main logic for demo1 program
  31. */
  32. void main (argc,argv)
  33. unsigned int argc;
  34. char **argv;
  35. {
  36.   Widget        toplevel; /*  Shell widget          */
  37.   Widget        bboard;   /*  BulletinBoard widget  */
  38.   Widget        button;   /*  PushButton widget     */
  39.   Arg           args[10]; /*  arg list              */
  40.   register int  n;        /*  arg count             */
  41.   XFontStruct  *font1;
  42.   char         *word1="Push Me";
  43.   Display      *dpy;
  44.   XtAppContext  app_context;
  45.  
  46. /*  initialize toolkit  */
  47.   toplevel = XtAppInitialize (&app_context, "Fonts", NULL, 0, &argc, argv,
  48.   NULL, args, 0);
  49.  
  50. /*  Create a BulletinBoard widget to place the pushbutton in */
  51.   n = 0;
  52.   bboard = XmCreateBulletinBoard (toplevel, "bboard", args, n);
  53.  
  54. /*  Manage the BulletinBoard widget */
  55.   XtManageChild (bboard);
  56.  
  57. /*  Get the display ID and set up the font */
  58.   dpy=XtDisplay(toplevel);
  59.   font1 = XLoadQueryFont(dpy,"courB14");
  60.   fontlist1 = XmFontListCreate(font1,"chset1");
  61.  
  62. /*  Create a compound string for the label */
  63.   s1=XmStringCreateLtoR(word1,"chset1");
  64.  
  65. /*  Set up arglist  */
  66.   n = 0;
  67.   XtSetArg(args[n], XmNlabelString, s1); n++;
  68.   XtSetArg(args[n], XmNfontList, fontlist1); n++; 
  69.  
  70. /*  Create button  */
  71.   button = XtCreateManagedWidget ("button", xmPushButtonWidgetClass,
  72.     bboard, args, n);
  73.  
  74. /*  Add callback  */
  75.   XtAddCallback (button, XmNactivateCallback, activateCB, NULL);
  76.  
  77. /*  Realize widgets  */
  78.   XtRealizeWidget (toplevel);
  79.  
  80. /*  Process events  */
  81.   XtAppMainLoop (app_context);
  82. }
  83.  
  84.  
  85. /*-------------------------------------------------------------
  86. **  activateCB - callback for button
  87. */
  88. void activateCB (w, client_data, call_data) 
  89. Widget     w;            /*  widget id               */
  90. XtPointer  client_data;  /*  data from application   */
  91. XtPointer  call_data;    /*  data from widget class  */
  92. {
  93. /*  print message, free compound string memory, and terminate program  */
  94.   printf ("PushButton selected.\n");
  95.   XmFontListFree(fontlist1);
  96.   XmStringFree(s1);
  97.   exit (0);
  98. }
  99.