home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume6 / wsxc2 / part03 / HelloWorld.c next >
C/C++ Source or Header  |  1990-04-26  |  4KB  |  100 lines

  1. /*
  2. *******************************************************************************
  3. *   HelloWorld.c 
  4. *******************************************************************************
  5.     This program demonstrates usage of the Xrm (X resource management) databse
  6.     for a widget tree definition and management.
  7.     There is very little code in this example, since the entire user interface
  8.     definition is stored in the Xrm database, preferably in the application
  9.     class resource file:  ~/HelloWorldClass
  10.  
  11.     ATTC NOTE: This example does NOT use Ws, since it's intended for use
  12.            outside Auto-trol.
  13. /*
  14. *******************************************************************************
  15. *   Include_files.
  16. *******************************************************************************
  17. */
  18.  
  19. #include <Xm/Xm.h>        /* Motif public header file    */
  20. #include <Xm/Label.h>        /* Motif label widget        */
  21. #include <Xm/PushB.h>        /* Motif pushbutton widget    */
  22. #include <Xm/RowColumn.h>    /* Motif row column widget    */
  23. #include "WsCreate.h"        /* Window System Creation routines */
  24.  
  25. /*
  26. *******************************************************************************
  27. *   Application callback declaration (callbacks should be in a separate file)
  28. *******************************************************************************
  29. */
  30. void pushCB();
  31.  
  32. /* 
  33. *******************************************************************************
  34. *   MAIN function
  35. *******************************************************************************
  36. */
  37.  
  38. main ( argc, argv )
  39. int    argc;
  40. char **argv;
  41. {   
  42.     Widget       app_shellW;          /* application shell widget       */
  43.     XtAppContext app;
  44.  
  45. /*  -- Intialize AWS creating the application shell */
  46.     app_shellW = XtInitialize ( "helloWorldClass","HelloWorldClass", NULL, 0, &argc, argv );
  47.     app        = XtWidgetToApplicationContext(app_shellW);
  48.  
  49. /*  -- Register used widget constructors */
  50.     WsRegisterConstructor     ( app, "XmCreateLabel",      XmCreateLabel     );
  51.     WsRegisterConstructor     ( app, "XmCreatePushButton", XmCreatePushButton);
  52.     WsRegisterConstructor     ( app, "XmCreateRowColumn",  XmCreateRowColumn );
  53.  
  54. /*  -- Register available callbacks */
  55.     WsRegisterCreateCallbacks ( app );
  56.     WsRegisterCallback        ( app, "push",  pushCB, NULL );
  57.  
  58.  
  59. /*  -- Create children of the toplevel shell defined by the Xrm database */
  60.     WsCreateKnownChildren     ( app_shellW );
  61.  
  62. /*  -- Realize the widget tree and enter the main application loop */
  63.     XtRealizeWidget           ( app_shellW );
  64.     XtMainLoop  ( );
  65. }
  66. /*
  67. *******************************************************************************
  68.     Application callbacks (should be in a separate file)
  69. *******************************************************************************
  70. */
  71. /*
  72.     -- Push callback
  73. *******************************************************************************
  74.     This callback is a state machine; the first invocation loads the text
  75.     specified as client data into XmNlabelString resource of invoking widget;
  76.     the next invocation exits the application.
  77. */
  78. void   pushCB ( w, client, call )
  79. Widget        w;
  80. caddr_t        client;
  81. caddr_t        call;
  82. {
  83.     static Boolean first = TRUE;
  84.     
  85.     if ( first )
  86.     {
  87.         static Arg setargs[] = { XmNlabelString, NULL };
  88.     String  text = ( client ) ? (String) client : "No text in Xrdb" ;
  89.  
  90.         setargs[0].value = (XtArgVal)XmStringCreateLtoR(text,XmSTRING_DEFAULT_CHARSET);
  91.     XtSetValues ( w, setargs, 1);
  92.     first = FALSE;
  93.         XmStringFree ( (XmString)setargs[0].value );
  94.     }
  95.     else
  96.     {
  97.     exit();
  98.     }    
  99. }
  100.