home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / motifpg2.zip / ch05 / xuildemo.c < prev    next >
C/C++ Source or Header  |  1992-07-08  |  3KB  |  108 lines

  1. /*
  2.  * Copyright 1989, 1992 O'Reilly and Associates, Inc.
  3.  * See ../Copyright for complete rights and liability information.
  4.  */
  5.  
  6. /*
  7.  * xuildemo - simple uil example
  8.  */
  9.  
  10. #include <stdio.h>
  11. /*
  12.  
  13.  * Declare our callback functions.
  14.  */
  15. static void button_selected();
  16.  
  17. /* 
  18.  * Miscellaneous UIL boilerplate: next 8 lines 
  19.  */
  20. #include <Xm/Xm.h>                  /* Motif Toolkit */
  21. #include <Mrm/MrmPublic.h>          /* Motif Resource Manager */
  22.  
  23. static MrmHierarchy    s_MrmHierarchy; /* MRM database hierarchy id */
  24. static char    *vec[]={"xuildemo.uid"}; /* MRM database file list */
  25. static MrmCode        class ;
  26. static MrmCount        regnum = 1 ;
  27. static MrmRegisterArg  regvec[] = {
  28.     {"button_selected",(XtPointer) button_selected }
  29. };
  30.  
  31. /*
  32.  * Define our callback functions.
  33.  */
  34. static void button_selected(widget, call_data, client_data)
  35.     Widget    widget;
  36.     XtPointer client_data;
  37.     XtPointer call_data;
  38. {
  39.     XmAnyCallbackStruct *data = (XmAnyCallbackStruct *) call_data;
  40.     char *tag = (char *) client_data;
  41.  
  42.     printf("button selected\n");
  43. }
  44.  
  45. int main(argc, argv)
  46. int argc;
  47. char **argv;
  48. {
  49.     XtAppContext      app_context;
  50.     Widget topLevel, appMain;
  51.  
  52.     XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
  53.  
  54.     /*
  55.      *  Initialize the MRM
  56.      */
  57.     MrmInitialize ();
  58.  
  59.     topLevel = XtVaAppInitialize(
  60.            &app_context,       /* Application context */
  61.            "XUilDemo",         /* application class name */
  62.            NULL, 0,            /* command line option list */
  63.            &argc, argv,        /* command line args */
  64.            NULL,               /* for missing app-defaults file */
  65.            NULL);              /* terminate varargs list */
  66.  
  67.     /*
  68.      *  Define the Mrm.hierarchy (only 1 file)
  69.      */
  70.  
  71.     if (MrmOpenHierarchyPerDisplay(XtDisplay(topLevel),
  72.             1,             /* number of files */
  73.             vec,                                   /* files */
  74.             NULL,
  75.             &s_MrmHierarchy)          /* ptr to returned id */
  76.             != MrmSUCCESS) {
  77.         printf ("Mrm can't open hierarchy\n");
  78.     }
  79.  
  80.     /*
  81.      *     Register our callback routines so that the resource  
  82.      *     manager can resolve them at widget-creation time.
  83.      */
  84.  
  85.     if (MrmRegisterNames (regvec, regnum)
  86.             != MrmSUCCESS)
  87.          printf("Mrm can't register names\n");
  88.  
  89.     /*
  90.      *  Call MRM to fetch and create the pushbutton and its container
  91.      */
  92.  
  93.     if (MrmFetchWidget (s_MrmHierarchy,
  94.             "helloworld_main",
  95.             topLevel,
  96.             &appMain,
  97.             &class) != MrmSUCCESS)
  98.         printf("Mrm can't fetch interface\n");
  99.  
  100.     /*  Manage the main window of the hierarchy created by Mrm. */
  101.  
  102.     XtManageChild(appMain);
  103.     
  104.     XtRealizeWidget(topLevel);
  105.  
  106.     XtAppMainLoop(app_context);
  107. }
  108.